src/settingseditor/settingseditor.cpp

Mon, 04 Jul 2022 15:37:22 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 04 Jul 2022 15:37:22 +0300
changeset 332
ae7f7fbb9cda
parent 296
38f6fad61bad
child 335
c5830bce1c23
permissions
-rw-r--r--

Only enable the text editor when having a model open

7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include <QSettings>
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
2 #include <QMdiArea>
264
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
3 #include <ui_settingseditor.h>
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
4 #include "src/settings.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
5 #include "src/gl/common.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
6 #include "src/settingseditor/keyboardshortcutseditor.h"
76a025db4948 Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 259
diff changeset
7 #include "src/settingseditor/settingseditor.h"
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8
16
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
9 SettingsEditor::SettingsEditor(
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
10 const uiutilities::KeySequenceMap& defaultKeyboardShortcuts,
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
11 QWidget* parent
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
12 ) :
285
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 282
diff changeset
13 QMdiSubWindow{parent},
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 ui{*new Ui_SettingsEditor},
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
15 libraries{this},
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
16 librariesEditor{this},
16
Teemu Piippo <teemu@hecknology.net>
parents: 7
diff changeset
17 defaultKeyboardShortcuts{defaultKeyboardShortcuts}
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18 {
285
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 282
diff changeset
19 QWidget* widget = new QWidget{this};
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 282
diff changeset
20 this->ui.setupUi(widget);
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 282
diff changeset
21 this->setWidget(widget);
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
22 this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this});
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
23 this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView});
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
24 this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView});
282
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
25 this->loadSettings();
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
26 this->setWindowTitle(tr("Settings"));
285
99af8bf63d10 Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 282
diff changeset
27 this->setWindowIcon(QIcon{":/icons/settings-outline.png"});
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 256
diff changeset
28 this->librariesEditor.setModel(&libraries);
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 QVBoxLayout* layout = new QVBoxLayout{this};
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 layout->addWidget(&librariesEditor);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 this->ui.tabLdrawLibraries->setLayout(layout);
282
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
32 connect(this->ui.buttonBox, &QDialogButtonBox::clicked,
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
33 [&](QAbstractButton* button) {
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
34 const auto role = this->ui.buttonBox->buttonRole(button);
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
35 if (role == QDialogButtonBox::ApplyRole) {
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
36 this->saveSettings();
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
37 }
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
38 });
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 SettingsEditor::~SettingsEditor()
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 delete &this->ui;
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45
282
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
46 void SettingsEditor::saveSettings()
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 {
256
c6f5de03dc0f Move color button into widgets lib
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
48 setSetting<Setting::MainColor>(this->ui.mainColorButton->color());
c6f5de03dc0f Move color button into widgets lib
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
49 setSetting<Setting::BackgroundColor>(this->ui.backgroundColorButton->color());
c6f5de03dc0f Move color button into widgets lib
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
50 setSetting<Setting::SelectedColor>(this->ui.selectedColorButton->color());
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
51 setSetting<Setting::LineThickness>(static_cast<GLfloat>(this->ui.lineThickness->value()));
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
52 setSetting<Setting::LineAntiAliasing>(this->ui.lineAntiAliasing->isChecked());
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
53 setSetting<Setting::LogOpenGLDebugMessages>(this->ui.logOpenGLDebugMessages->isChecked());
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
54 const int viewMode = this->ui.viewModeButtonGroup->checkedId();
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
55 if (viewMode != -1) {
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
56 setSetting<Setting::ViewMode>(static_cast<QMdiArea::ViewMode>(viewMode));
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
57 }
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
58 this->librariesEditor.saveSettings();
282
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
59 Q_EMIT this->settingsChanged();
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61
282
f2dc3bbecbfa Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 264
diff changeset
62 void SettingsEditor::loadSettings()
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 256
diff changeset
64 this->libraries.restoreFromSettings();
256
c6f5de03dc0f Move color button into widgets lib
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
65 this->ui.mainColorButton->setColor(setting<Setting::MainColor>());
c6f5de03dc0f Move color button into widgets lib
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
66 this->ui.backgroundColorButton->setColor(setting<Setting::BackgroundColor>());
c6f5de03dc0f Move color button into widgets lib
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
67 this->ui.selectedColorButton->setColor(setting<Setting::SelectedColor>());
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
68 this->ui.lineThickness->setValue(double_cast(setting<Setting::LineThickness>()));
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
69 this->ui.lineAntiAliasing->setChecked(setting<Setting::LineAntiAliasing>());
237
10a6298f636f Add an option to log opengl messages
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 218
diff changeset
70 this->ui.logOpenGLDebugMessages->setChecked(setting<Setting::LogOpenGLDebugMessages>());
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
71 auto* const viewModeButton = this->ui.viewModeButtonGroup->button(setting<Setting::ViewMode>());
202
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
72 if (viewModeButton != nullptr) {
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
73 viewModeButton->setChecked(true);
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
74 }
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 }

mercurial