Sun, 09 Apr 2023 16:27:22 +0300
Also connect up "Select all"
7 | 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> |
357
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
3 | #include <QFileDialog> |
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
|
4 | #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
|
5 | #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
|
6 | #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
|
7 | #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
|
8 | #include "src/settingseditor/settingseditor.h" |
7 | 9 | |
341
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
10 | static QVariantMap storeSettings() |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
11 | { |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
12 | QVariantMap result; |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
13 | QSettings settingsObject; |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
14 | for (const QString& key : settingsObject.allKeys()) { |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
15 | result[key] = settingsObject.value(key); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
16 | } |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
17 | return result; |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
18 | } |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
19 | |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
20 | static void restoreSettings(const QVariantMap& storedValues) |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
21 | { |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
22 | QSettings settingsObject; |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
23 | settingsObject.clear(); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
24 | for (const QString& key : storedValues.keys()) { |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
25 | settingsObject.setValue(key, storedValues[key]); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
26 | } |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
27 | } |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
28 | |
16 | 29 | SettingsEditor::SettingsEditor( |
30 | const uiutilities::KeySequenceMap& defaultKeyboardShortcuts, | |
31 | QWidget* parent | |
32 | ) : | |
285
99af8bf63d10
Don't create more than one settings editor
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
282
diff
changeset
|
33 | QMdiSubWindow{parent}, |
7 | 34 | ui{*new Ui_SettingsEditor}, |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
35 | libraries{this}, |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
36 | librariesEditor{this}, |
16 | 37 | defaultKeyboardShortcuts{defaultKeyboardShortcuts} |
7 | 38 | { |
341
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
39 | QWidget* centralWidget = new QWidget{this}; |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
40 | this->ui.setupUi(centralWidget); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
41 | this->setWidget(centralWidget); |
202
b05af0bab735
Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
42 | 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
|
43 | 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
|
44 | this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView}); |
335 | 45 | this->ui.toolButtonStyle->addItem(tr("Icons only"), Qt::ToolButtonIconOnly); |
46 | this->ui.toolButtonStyle->addItem(tr("Text only"), Qt::ToolButtonTextOnly); | |
47 | this->ui.toolButtonStyle->addItem(tr("Text beside icon"), Qt::ToolButtonTextBesideIcon); | |
48 | this->ui.toolButtonStyle->addItem(tr("Text under icon"), Qt::ToolButtonTextUnderIcon); | |
49 | this->ui.toolButtonStyle->addItem(tr("Style default"), Qt::ToolButtonFollowStyle); | |
356
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
50 | connect( |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
51 | this->ui.codeEditorSystemFont, |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
52 | &QCheckBox::stateChanged, |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
53 | [this](int state){ |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
54 | const bool checked = (state == Qt::Checked); |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
55 | this->ui.codeEditorFontFamily->setEnabled(not checked); |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
56 | this->ui.codeEditorFontSize->setEnabled(not checked); |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
57 | } |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
58 | ); |
282
f2dc3bbecbfa
Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
264
diff
changeset
|
59 | this->loadSettings(); |
f2dc3bbecbfa
Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
264
diff
changeset
|
60 | 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
|
61 | 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
|
62 | this->librariesEditor.setModel(&libraries); |
7 | 63 | QVBoxLayout* layout = new QVBoxLayout{this}; |
64 | layout->addWidget(&librariesEditor); | |
65 | this->ui.tabLdrawLibraries->setLayout(layout); | |
341
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
66 | QSettings settingsObject; |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
67 | connect( |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
68 | this->ui.buttonBox, &QDialogButtonBox::clicked, |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
69 | [this, previousSettings = storeSettings()](QAbstractButton* button) |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
70 | { |
282
f2dc3bbecbfa
Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
264
diff
changeset
|
71 | const auto role = this->ui.buttonBox->buttonRole(button); |
341
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
72 | switch (role) |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
73 | { |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
74 | case QDialogButtonBox::AcceptRole: |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
75 | this->close(); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
76 | break; |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
77 | case QDialogButtonBox::RejectRole: |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
78 | restoreSettings(previousSettings); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
79 | Q_EMIT this->settingsChanged(); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
80 | this->close(); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
81 | break; |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
82 | case QDialogButtonBox::ResetRole: |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
83 | restoreSettings(previousSettings); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
84 | Q_EMIT this->settingsChanged(); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
85 | break; |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
86 | default: |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
87 | break; |
282
f2dc3bbecbfa
Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
264
diff
changeset
|
88 | } |
341
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
89 | } |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
90 | ); |
357
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
91 | connect( |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
92 | this->ui.exportSettingsButton, |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
93 | &QAbstractButton::clicked, |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
94 | [&] |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
95 | { |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
96 | const QString defaultName = QStringLiteral(CMAKE_PROJECT_NAME ".conf"); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
97 | QString filename = QFileDialog::getSaveFileName(this, "", defaultName, "*.conf"); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
98 | if (not filename.isEmpty()) |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
99 | { |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
100 | QSettings settings; |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
101 | QSettings exportSettings{filename, QSettings::IniFormat}; |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
102 | for (const QString& key : settings.allKeys()) |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
103 | { |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
104 | exportSettings.setValue(key, settings.value(key)); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
105 | } |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
106 | exportSettings.sync(); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
107 | } |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
108 | } |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
109 | ); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
110 | connect( |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
111 | this->ui.importSettingsButton, |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
112 | &QAbstractButton::clicked, |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
113 | [&] |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
114 | { |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
115 | QString filename = QFileDialog::getOpenFileName(this, "", "", "*.ini"); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
116 | if (not filename.isEmpty()) |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
117 | { |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
118 | QSettings settings; |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
119 | const QSettings importSettings{filename}; |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
120 | settings.clear(); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
121 | for (const QString& key : importSettings.allKeys()) |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
122 | { |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
123 | settings.setValue(key, importSettings.value(key)); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
124 | } |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
125 | settings.sync(); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
126 | this->loadSettings(); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
127 | } |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
128 | } |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
129 | ); |
341
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
130 | for (auto* widget : this->findChildren<QAbstractButton*>()) { |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
131 | connect(widget, &QAbstractButton::clicked, this, &SettingsEditor::saveSettings); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
132 | } |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
133 | for (auto* widget : this->findChildren<QSpinBox*>()) { |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
134 | connect(widget, qOverload<int>(&QSpinBox::valueChanged), this, &SettingsEditor::saveSettings); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
135 | } |
347
5c655cc006de
Rename ColorButton -> ColorEdit
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
341
diff
changeset
|
136 | for (auto* widget : this->findChildren<ColorEdit*>()) { |
5c655cc006de
Rename ColorButton -> ColorEdit
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
341
diff
changeset
|
137 | connect(widget, &ColorEdit::colorChanged, this, &SettingsEditor::saveSettings); |
341
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
138 | } |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
139 | for (auto* widget : this->findChildren<QComboBox*>()) { |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
140 | connect(widget, qOverload<int>(&QComboBox::currentIndexChanged), this, &SettingsEditor::saveSettings); |
71c8cea3c205
Save settings as soon as they are changed, Cancel and Reset buttons revert changes
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
335
diff
changeset
|
141 | } |
7 | 142 | } |
143 | ||
144 | SettingsEditor::~SettingsEditor() | |
145 | { | |
146 | delete &this->ui; | |
147 | } | |
148 | ||
282
f2dc3bbecbfa
Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
264
diff
changeset
|
149 | void SettingsEditor::saveSettings() |
7 | 150 | { |
357
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
151 | if (not disableSettingsAutoSave) |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
152 | { |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
153 | setSetting<Setting::MainColor>(this->ui.mainColorButton->color()); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
154 | setSetting<Setting::BackgroundColor>(this->ui.backgroundColorButton->color()); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
155 | setSetting<Setting::SelectedColor>(this->ui.selectedColorButton->color()); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
156 | setSetting<Setting::LineThickness>(static_cast<GLfloat>(this->ui.lineThickness->value())); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
157 | setSetting<Setting::LineAntiAliasing>(this->ui.lineAntiAliasing->isChecked()); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
158 | setSetting<Setting::LogOpenGLDebugMessages>(this->ui.logOpenGLDebugMessages->isChecked()); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
159 | setSetting<Setting::CodeEditorUseSystemFont>(this->ui.codeEditorSystemFont->isChecked()); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
160 | setSetting<Setting::CodeEditorFontFamily>(this->ui.codeEditorFontFamily->currentText()); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
161 | setSetting<Setting::CodeEditorFontSize>(this->ui.codeEditorFontSize->value()); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
162 | const int viewMode = this->ui.viewModeButtonGroup->checkedId(); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
163 | if (viewMode != -1) { |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
164 | setSetting<Setting::ViewMode>(static_cast<QMdiArea::ViewMode>(viewMode)); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
165 | } |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
166 | const QVariant toolButtonStyle = this->ui.toolButtonStyle->currentData(); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
167 | if (toolButtonStyle.isValid()) { |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
168 | setSetting<Setting::ToolButtonStyle>( |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
169 | static_cast<Qt::ToolButtonStyle>(toolButtonStyle.toInt())); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
170 | } |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
171 | this->librariesEditor.saveSettings(); |
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
172 | Q_EMIT this->settingsChanged(); |
202
b05af0bab735
Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
173 | } |
7 | 174 | } |
175 | ||
282
f2dc3bbecbfa
Make settings editor a sub window instead of a dialog
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
264
diff
changeset
|
176 | void SettingsEditor::loadSettings() |
7 | 177 | { |
357
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
178 | this->disableSettingsAutoSave = true; |
259
c27612f0eac0
- Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
256
diff
changeset
|
179 | this->libraries.restoreFromSettings(); |
256
c6f5de03dc0f
Move color button into widgets lib
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
237
diff
changeset
|
180 | 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
|
181 | 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
|
182 | 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
|
183 | 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
|
184 | 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
|
185 | this->ui.logOpenGLDebugMessages->setChecked(setting<Setting::LogOpenGLDebugMessages>()); |
356
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
186 | this->ui.codeEditorSystemFont->setChecked(setting<Setting::CodeEditorUseSystemFont>()); |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
187 | this->ui.codeEditorFontFamily->setCurrentText(setting<Setting::CodeEditorFontFamily>()); |
65b4741b302d
Made editor font configurable
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
347
diff
changeset
|
188 | this->ui.codeEditorFontSize->setValue(setting<Setting::CodeEditorFontSize>()); |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
189 | 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
|
190 | if (viewModeButton != nullptr) { |
b05af0bab735
Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
191 | viewModeButton->setChecked(true); |
b05af0bab735
Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
192 | } |
335 | 193 | int toolButtonStyleIndex = this->ui.toolButtonStyle->findData( |
194 | setting<Setting::ToolButtonStyle>()); | |
195 | if (toolButtonStyleIndex != -1) { | |
196 | this->ui.toolButtonStyle->setCurrentIndex(toolButtonStyleIndex); | |
197 | } | |
357
66c75604f5b8
Add settings import and export
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
356
diff
changeset
|
198 | this->disableSettingsAutoSave = false; |
7 | 199 | } |