src/settingseditor/settingseditor.cpp

Mon, 27 Jun 2022 01:57:06 +0300

author
Teemu Piippo <teemu.s.piippo@gmail.com>
date
Mon, 27 Jun 2022 01:57:06 +0300
changeset 269
593545977c5e
parent 264
76a025db4948
child 282
f2dc3bbecbfa
permissions
-rw-r--r--

Further use APPNAME macro

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 ) :
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 QDialog{parent},
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 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
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
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23 this->loadLocales();
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 this->setDefaults();
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 256
diff changeset
25 this->librariesEditor.setModel(&libraries);
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 QVBoxLayout* layout = new QVBoxLayout{this};
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 layout->addWidget(&librariesEditor);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 this->ui.tabLdrawLibraries->setLayout(layout);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 connect(
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 this,
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31 &SettingsEditor::accepted,
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 this,
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 &SettingsEditor::handleAccepted);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 SettingsEditor::~SettingsEditor()
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 delete &this->ui;
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 void SettingsEditor::handleAccepted()
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 {
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
43 setSetting<Setting::Locale>(this->ui.language->currentData().toString());
256
c6f5de03dc0f Move color button into widgets lib
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 if (viewMode != -1) {
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
52 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
53 }
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
54 this->librariesEditor.saveSettings();
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
55 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
56
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
57 void SettingsEditor::loadLocales()
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
58 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
59 this->ui.language->clear();
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
60 QDir dir{":/locale"};
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
61 // Collect translation files in built-in resources
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
62 QVector<QString> localeCodes = {"en"}; // English is the default locale
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
63 for (const QFileInfo& file : dir.entryInfoList(QDir::Files))
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
64 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
65 localeCodes.append(file.baseName());
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
66 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
67 std::sort(localeCodes.begin(), localeCodes.end());
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
68 this->ui.language->addItem(tr("System language"), "system");
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
69 for (const QString& localeCode : localeCodes)
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
70 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
71 const QLocale locale{localeCode};
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
72 const QString languageName = QLocale::languageToString(locale.language());
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
73 const QIcon flag{":/flags/" + localeCode + ".png"};
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
74 this->ui.language->addItem(languageName, localeCode);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
75 this->ui.language->setItemIcon(this->ui.language->count() - 1, flag);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
76 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
77 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
78
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
79 void SettingsEditor::setDefaults()
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
80 {
259
c27612f0eac0 - Made it build under Qt6
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 256
diff changeset
81 this->libraries.restoreFromSettings();
218
63125c36de73 Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 202
diff changeset
82 this->setCurrentLanguage(setting<Setting::Locale>());
256
c6f5de03dc0f Move color button into widgets lib
Teemu Piippo <teemu.s.piippo@gmail.com>
parents: 237
diff changeset
83 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
84 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
85 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
86 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
87 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
88 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
89 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
90 if (viewModeButton != nullptr) {
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
91 viewModeButton->setChecked(true);
b05af0bab735 Replaced the tab widget with an MDI area
Teemu Piippo <teemu@hecknology.net>
parents: 48
diff changeset
92 }
7
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
93 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
94
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
95 void SettingsEditor::setCurrentLanguage(const QString& localeCode)
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
96 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
97 for (int i = 0; i < this->ui.language->count(); i += 1)
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
98 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
99 if (this->ui.language->itemData(i) == localeCode)
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
100 {
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
101 this->ui.language->setCurrentIndex(i);
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
102 break;
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
103 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
104 }
68443f5be176 added the settings editor
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
105 }

mercurial