src/settingseditor/settingseditor.cpp

Thu, 06 Feb 2020 20:33:05 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 06 Feb 2020 20:33:05 +0200
changeset 46
98645c8e7704
parent 45
272c84c7c87e
child 48
3c10f0e2fbe0
permissions
-rw-r--r--

added the pick scene

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

mercurial