Sat, 01 Feb 2020 17:20:10 +0200
added configurable background color
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( |
8 | QSettings* settings, | |
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 | { | |
40 | this->settings->setValue("locale", this->ui.language->currentData().toString()); | |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
16
diff
changeset
|
41 | this->settings->setValue("Render/MainColor", this->ui.mainColorButton->selectedColor().name()); |
40
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
42 | this->settings->setValue("Render/BackgroundColor", this->ui.backgroundColorButton->selectedColor().name()); |
7 | 43 | this->librariesEditor.saveSettings(this->settings); |
44 | } | |
45 | ||
46 | void SettingsEditor::loadLocales() | |
47 | { | |
48 | this->ui.language->clear(); | |
49 | QDir dir{":/locale"}; | |
50 | // Collect translation files in built-in resources | |
51 | QVector<QString> localeCodes = {"en"}; // English is the default locale | |
52 | for (const QFileInfo& file : dir.entryInfoList(QDir::Files)) | |
53 | { | |
54 | localeCodes.append(file.baseName()); | |
55 | } | |
56 | std::sort(localeCodes.begin(), localeCodes.end()); | |
57 | this->ui.language->addItem(tr("System language"), "system"); | |
58 | for (const QString& localeCode : localeCodes) | |
59 | { | |
60 | const QLocale locale{localeCode}; | |
61 | const QString languageName = QLocale::languageToString(locale.language()); | |
62 | const QIcon flag{":/flags/" + localeCode + ".png"}; | |
63 | this->ui.language->addItem(languageName, localeCode); | |
64 | this->ui.language->setItemIcon(this->ui.language->count() - 1, flag); | |
65 | } | |
66 | } | |
67 | ||
68 | void SettingsEditor::setDefaults() | |
69 | { | |
70 | this->setCurrentLanguage(this->settings->value("locale", QLocale::system().name()).toString()); | |
40
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
71 | this->ui.mainColorButton->setSelectedColor(this->settings->value( |
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
72 | "Render/MainColor", |
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
73 | gl::RenderPreferences{}.mainColor).toString()); |
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
74 | this->ui.backgroundColorButton->setSelectedColor(this->settings->value( |
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
75 | "Render/BackgroundColor", |
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
76 | gl::RenderPreferences{}.backgroundColor).toString()); |
7 | 77 | } |
78 | ||
79 | void SettingsEditor::setCurrentLanguage(const QString& localeCode) | |
80 | { | |
81 | for (int i = 0; i < this->ui.language->count(); i += 1) | |
82 | { | |
83 | if (this->ui.language->itemData(i) == localeCode) | |
84 | { | |
85 | this->ui.language->setCurrentIndex(i); | |
86 | break; | |
87 | } | |
88 | } | |
89 | } |