Mon, 20 Jun 2022 22:22:15 +0300
Substitute circular primitives in during file parsing
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> |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
3 | #include "settings.h" |
40
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
4 | #include "gl/common.h" |
16 | 5 | #include "keyboardshortcutseditor.h" |
7 | 6 | #include "settingseditor.h" |
7 | #include "ui_settingseditor.h" | |
8 | ||
16 | 9 | SettingsEditor::SettingsEditor( |
10 | const uiutilities::KeySequenceMap& defaultKeyboardShortcuts, | |
11 | QWidget* parent | |
12 | ) : | |
7 | 13 | QDialog{parent}, |
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 | 17 | defaultKeyboardShortcuts{defaultKeyboardShortcuts} |
7 | 18 | { |
19 | this->ui.setupUi(this); | |
202
b05af0bab735
Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
20 | 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
|
21 | 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
|
22 | this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView}); |
7 | 23 | this->loadLocales(); |
24 | this->setDefaults(); | |
25 | QVBoxLayout* layout = new QVBoxLayout{this}; | |
26 | layout->addWidget(&librariesEditor); | |
27 | this->ui.tabLdrawLibraries->setLayout(layout); | |
28 | connect( | |
29 | this, | |
30 | &SettingsEditor::accepted, | |
31 | this, | |
32 | &SettingsEditor::handleAccepted); | |
33 | } | |
34 | ||
35 | SettingsEditor::~SettingsEditor() | |
36 | { | |
37 | delete &this->ui; | |
38 | } | |
39 | ||
40 | void SettingsEditor::handleAccepted() | |
41 | { | |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
42 | setSetting<Setting::Locale>(this->ui.language->currentData().toString()); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
43 | setSetting<Setting::MainColor>(this->ui.mainColorButton->selectedColor()); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
44 | setSetting<Setting::BackgroundColor>(this->ui.backgroundColorButton->selectedColor()); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
45 | setSetting<Setting::SelectedColor>(this->ui.selectedColorButton->selectedColor()); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
46 | 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
|
47 | 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
|
48 | 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
|
49 | 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
|
50 | if (viewMode != -1) { |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
51 | 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
|
52 | } |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
53 | this->librariesEditor.saveSettings(); |
7 | 54 | } |
55 | ||
56 | void SettingsEditor::loadLocales() | |
57 | { | |
58 | this->ui.language->clear(); | |
59 | QDir dir{":/locale"}; | |
60 | // Collect translation files in built-in resources | |
61 | QVector<QString> localeCodes = {"en"}; // English is the default locale | |
62 | for (const QFileInfo& file : dir.entryInfoList(QDir::Files)) | |
63 | { | |
64 | localeCodes.append(file.baseName()); | |
65 | } | |
66 | std::sort(localeCodes.begin(), localeCodes.end()); | |
67 | this->ui.language->addItem(tr("System language"), "system"); | |
68 | for (const QString& localeCode : localeCodes) | |
69 | { | |
70 | const QLocale locale{localeCode}; | |
71 | const QString languageName = QLocale::languageToString(locale.language()); | |
72 | const QIcon flag{":/flags/" + localeCode + ".png"}; | |
73 | this->ui.language->addItem(languageName, localeCode); | |
74 | this->ui.language->setItemIcon(this->ui.language->count() - 1, flag); | |
75 | } | |
76 | } | |
77 | ||
78 | void SettingsEditor::setDefaults() | |
79 | { | |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
80 | this->setCurrentLanguage(setting<Setting::Locale>()); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
81 | this->ui.mainColorButton->setSelectedColor(setting<Setting::MainColor>()); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
82 | this->ui.backgroundColorButton->setSelectedColor(setting<Setting::BackgroundColor>()); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
83 | this->ui.selectedColorButton->setSelectedColor(setting<Setting::SelectedColor>()); |
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
202
diff
changeset
|
84 | 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
|
85 | 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
|
86 | 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
|
87 | 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
|
88 | if (viewModeButton != nullptr) { |
b05af0bab735
Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
89 | viewModeButton->setChecked(true); |
b05af0bab735
Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents:
48
diff
changeset
|
90 | } |
7 | 91 | } |
92 | ||
93 | void SettingsEditor::setCurrentLanguage(const QString& localeCode) | |
94 | { | |
95 | for (int i = 0; i < this->ui.language->count(); i += 1) | |
96 | { | |
97 | if (this->ui.language->itemData(i) == localeCode) | |
98 | { | |
99 | this->ui.language->setCurrentIndex(i); | |
100 | break; | |
101 | } | |
102 | } | |
103 | } |