Sat, 05 Mar 2022 12:42:14 +0200
Add icons from ionicons
7 | 1 | #include <QSettings> |
40
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
2 | #include "gl/common.h" |
16 | 3 | #include "keyboardshortcutseditor.h" |
7 | 4 | #include "settingseditor.h" |
5 | #include "ui_settingseditor.h" | |
6 | ||
16 | 7 | SettingsEditor::SettingsEditor( |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
8 | Configuration* settings, |
16 | 9 | const uiutilities::KeySequenceMap& defaultKeyboardShortcuts, |
10 | QWidget* parent | |
11 | ) : | |
7 | 12 | QDialog{parent}, |
13 | ui{*new Ui_SettingsEditor}, | |
14 | settings{settings}, | |
15 | libraries{settings, this}, | |
16 | 16 | librariesEditor{settings, this}, |
17 | defaultKeyboardShortcuts{defaultKeyboardShortcuts} | |
7 | 18 | { |
19 | this->ui.setupUi(this); | |
20 | this->loadLocales(); | |
21 | this->setDefaults(); | |
22 | QVBoxLayout* layout = new QVBoxLayout{this}; | |
23 | layout->addWidget(&librariesEditor); | |
24 | this->ui.tabLdrawLibraries->setLayout(layout); | |
25 | connect( | |
26 | this, | |
27 | &SettingsEditor::accepted, | |
28 | this, | |
29 | &SettingsEditor::handleAccepted); | |
16 | 30 | this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this}); |
7 | 31 | } |
32 | ||
33 | SettingsEditor::~SettingsEditor() | |
34 | { | |
35 | delete &this->ui; | |
36 | } | |
37 | ||
38 | void SettingsEditor::handleAccepted() | |
39 | { | |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
40 | this->settings->setLocale(this->ui.language->currentData().toString()); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
41 | this->settings->setMainColor(this->ui.mainColorButton->selectedColor()); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
42 | this->settings->setBackgroundColor(this->ui.backgroundColorButton->selectedColor()); |
48
3c10f0e2fbe0
added selection highlighting
Teemu Piippo <teemu@hecknology.net>
parents:
45
diff
changeset
|
43 | this->settings->setSelectedColor(this->ui.selectedColorButton->selectedColor()); |
44
c6114b3af3a6
added configurable line thickness
Teemu Piippo <teemu@hecknology.net>
parents:
41
diff
changeset
|
44 | this->settings->setLineThickness(static_cast<GLfloat>(this->ui.lineThickness->value())); |
45
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
45 | this->settings->setLineAntiAliasing(this->ui.lineAntiAliasing->isChecked()); |
7 | 46 | this->librariesEditor.saveSettings(this->settings); |
47 | } | |
48 | ||
49 | void SettingsEditor::loadLocales() | |
50 | { | |
51 | this->ui.language->clear(); | |
52 | QDir dir{":/locale"}; | |
53 | // Collect translation files in built-in resources | |
54 | QVector<QString> localeCodes = {"en"}; // English is the default locale | |
55 | for (const QFileInfo& file : dir.entryInfoList(QDir::Files)) | |
56 | { | |
57 | localeCodes.append(file.baseName()); | |
58 | } | |
59 | std::sort(localeCodes.begin(), localeCodes.end()); | |
60 | this->ui.language->addItem(tr("System language"), "system"); | |
61 | for (const QString& localeCode : localeCodes) | |
62 | { | |
63 | const QLocale locale{localeCode}; | |
64 | const QString languageName = QLocale::languageToString(locale.language()); | |
65 | const QIcon flag{":/flags/" + localeCode + ".png"}; | |
66 | this->ui.language->addItem(languageName, localeCode); | |
67 | this->ui.language->setItemIcon(this->ui.language->count() - 1, flag); | |
68 | } | |
69 | } | |
70 | ||
71 | void SettingsEditor::setDefaults() | |
72 | { | |
41
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
73 | this->setCurrentLanguage(this->settings->locale()); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
74 | this->ui.mainColorButton->setSelectedColor(this->settings->mainColor()); |
0abada2a9802
added automated configuration collection
Teemu Piippo <teemu@hecknology.net>
parents:
40
diff
changeset
|
75 | this->ui.backgroundColorButton->setSelectedColor(this->settings->backgroundColor()); |
48
3c10f0e2fbe0
added selection highlighting
Teemu Piippo <teemu@hecknology.net>
parents:
45
diff
changeset
|
76 | this->ui.selectedColorButton->setSelectedColor(this->settings->selectedColor()); |
44
c6114b3af3a6
added configurable line thickness
Teemu Piippo <teemu@hecknology.net>
parents:
41
diff
changeset
|
77 | this->ui.lineThickness->setValue(static_cast<double>(this->settings->lineThickness())); |
45
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
78 | this->ui.lineAntiAliasing->setChecked(this->settings->lineAntiAliasing()); |
7 | 79 | } |
80 | ||
81 | void SettingsEditor::setCurrentLanguage(const QString& localeCode) | |
82 | { | |
83 | for (int i = 0; i < this->ui.language->count(); i += 1) | |
84 | { | |
85 | if (this->ui.language->itemData(i) == localeCode) | |
86 | { | |
87 | this->ui.language->setCurrentIndex(i); | |
88 | break; | |
89 | } | |
90 | } | |
91 | } |