Sat, 01 Feb 2020 17:10:11 +0200
Main color is now configurable
7 | 1 | #include <QSettings> |
16 | 2 | #include "keyboardshortcutseditor.h" |
7 | 3 | #include "settingseditor.h" |
4 | #include "ui_settingseditor.h" | |
5 | ||
16 | 6 | SettingsEditor::SettingsEditor( |
7 | QSettings* settings, | |
8 | const uiutilities::KeySequenceMap& defaultKeyboardShortcuts, | |
9 | QWidget* parent | |
10 | ) : | |
7 | 11 | QDialog{parent}, |
12 | ui{*new Ui_SettingsEditor}, | |
13 | settings{settings}, | |
14 | libraries{settings, this}, | |
16 | 15 | librariesEditor{settings, this}, |
16 | defaultKeyboardShortcuts{defaultKeyboardShortcuts} | |
7 | 17 | { |
18 | this->ui.setupUi(this); | |
19 | this->loadLocales(); | |
20 | this->setDefaults(); | |
21 | QVBoxLayout* layout = new QVBoxLayout{this}; | |
22 | layout->addWidget(&librariesEditor); | |
23 | this->ui.tabLdrawLibraries->setLayout(layout); | |
24 | connect( | |
25 | this, | |
26 | &SettingsEditor::accepted, | |
27 | this, | |
28 | &SettingsEditor::handleAccepted); | |
16 | 29 | this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this}); |
7 | 30 | } |
31 | ||
32 | SettingsEditor::~SettingsEditor() | |
33 | { | |
34 | delete &this->ui; | |
35 | } | |
36 | ||
37 | void SettingsEditor::handleAccepted() | |
38 | { | |
39 | 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
|
40 | this->settings->setValue("Render/MainColor", this->ui.mainColorButton->selectedColor().name()); |
7 | 41 | this->librariesEditor.saveSettings(this->settings); |
42 | } | |
43 | ||
44 | void SettingsEditor::loadLocales() | |
45 | { | |
46 | this->ui.language->clear(); | |
47 | QDir dir{":/locale"}; | |
48 | // Collect translation files in built-in resources | |
49 | QVector<QString> localeCodes = {"en"}; // English is the default locale | |
50 | for (const QFileInfo& file : dir.entryInfoList(QDir::Files)) | |
51 | { | |
52 | localeCodes.append(file.baseName()); | |
53 | } | |
54 | std::sort(localeCodes.begin(), localeCodes.end()); | |
55 | this->ui.language->addItem(tr("System language"), "system"); | |
56 | for (const QString& localeCode : localeCodes) | |
57 | { | |
58 | const QLocale locale{localeCode}; | |
59 | const QString languageName = QLocale::languageToString(locale.language()); | |
60 | const QIcon flag{":/flags/" + localeCode + ".png"}; | |
61 | this->ui.language->addItem(languageName, localeCode); | |
62 | this->ui.language->setItemIcon(this->ui.language->count() - 1, flag); | |
63 | } | |
64 | } | |
65 | ||
66 | void SettingsEditor::setDefaults() | |
67 | { | |
68 | this->setCurrentLanguage(this->settings->value("locale", QLocale::system().name()).toString()); | |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
16
diff
changeset
|
69 | this->ui.mainColorButton->setSelectedColor(this->settings->value("Render/MainColor").toString()); |
7 | 70 | } |
71 | ||
72 | void SettingsEditor::setCurrentLanguage(const QString& localeCode) | |
73 | { | |
74 | for (int i = 0; i < this->ui.language->count(); i += 1) | |
75 | { | |
76 | if (this->ui.language->itemData(i) == localeCode) | |
77 | { | |
78 | this->ui.language->setCurrentIndex(i); | |
79 | break; | |
80 | } | |
81 | } | |
82 | } |