| 70 | namespace OpenOrienteering { |
| 71 | |
| 72 | SettingsDialog::SettingsDialog(QWidget* parent) |
| 73 | : QDialog { parent } |
| 74 | , tab_widget { nullptr } |
| 75 | , stack_widget { nullptr } |
| 76 | , scrollbar_extent { QScrollBar(Qt::Vertical).sizeHint().width() } |
| 77 | { |
| 78 | setWindowTitle(tr("Settings")); |
| 79 | |
| 80 | auto layout = new QVBoxLayout(this); |
| 81 | |
| 82 | auto buttons = QDialogButtonBox::StandardButtons{ QDialogButtonBox::Ok }; |
| 83 | if (Settings::mobileModeEnforced()) |
| 84 | { |
| 85 | if (parent) |
| 86 | setGeometry(parent->geometry()); |
| 87 | |
| 88 | stack_widget = new QStackedWidget(); |
| 89 | layout->addWidget(stack_widget, 1); |
| 90 | |
| 91 | auto menu_widget = new QToolBar(); |
| 92 | menu_widget->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); |
| 93 | menu_widget->setOrientation(Qt::Vertical); |
| 94 | stack_widget->addWidget(menu_widget); |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | buttons |= QDialogButtonBox::Reset | QDialogButtonBox::Cancel | QDialogButtonBox::Help; |
| 99 | |
| 100 | tab_widget = new QTabWidget(); |
| 101 | #ifndef Q_OS_MACOS |
| 102 | tab_widget->setDocumentMode(true); |
| 103 | #endif |
| 104 | layout->addWidget(tab_widget, 1); |
| 105 | } |
| 106 | |
| 107 | button_box = new QDialogButtonBox(buttons, Qt::Horizontal); |
| 108 | connect(button_box, &QDialogButtonBox::clicked, this, &SettingsDialog::buttonPressed); |
| 109 | if (stack_widget) |
| 110 | { |
| 111 | int left, top, right, bottom; |
| 112 | layout->getContentsMargins(&left, &top, &right, &bottom); |
| 113 | layout->setContentsMargins(0, 0, 0, 0); |
| 114 | layout->setSpacing(0); |
| 115 | |
| 116 | auto l = new QVBoxLayout(); |
| 117 | l->setContentsMargins(left, top, right, bottom); |
| 118 | l->addWidget(button_box); |
| 119 | layout->addLayout(l); |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | layout->addWidget(button_box); |
| 124 | } |
| 125 | |
| 126 | addPages(); |
| 127 | } |
| 128 | |
| 129 | SettingsDialog::~SettingsDialog() = default; |