1 #include <QSettings> |
1 #include <QSettings> |
2 #include <QMdiArea> |
2 #include <QMdiArea> |
|
3 #include "settings.h" |
3 #include "gl/common.h" |
4 #include "gl/common.h" |
4 #include "keyboardshortcutseditor.h" |
5 #include "keyboardshortcutseditor.h" |
5 #include "settingseditor.h" |
6 #include "settingseditor.h" |
6 #include "ui_settingseditor.h" |
7 #include "ui_settingseditor.h" |
7 |
8 |
8 SettingsEditor::SettingsEditor( |
9 SettingsEditor::SettingsEditor( |
9 Configuration* settings, |
|
10 const uiutilities::KeySequenceMap& defaultKeyboardShortcuts, |
10 const uiutilities::KeySequenceMap& defaultKeyboardShortcuts, |
11 QWidget* parent |
11 QWidget* parent |
12 ) : |
12 ) : |
13 QDialog{parent}, |
13 QDialog{parent}, |
14 ui{*new Ui_SettingsEditor}, |
14 ui{*new Ui_SettingsEditor}, |
15 settings{settings}, |
15 libraries{this}, |
16 libraries{settings, this}, |
16 librariesEditor{this}, |
17 librariesEditor{settings, this}, |
|
18 defaultKeyboardShortcuts{defaultKeyboardShortcuts} |
17 defaultKeyboardShortcuts{defaultKeyboardShortcuts} |
19 { |
18 { |
20 this->ui.setupUi(this); |
19 this->ui.setupUi(this); |
21 this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this}); |
20 this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this}); |
22 this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView}); |
21 this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView}); |
38 delete &this->ui; |
37 delete &this->ui; |
39 } |
38 } |
40 |
39 |
41 void SettingsEditor::handleAccepted() |
40 void SettingsEditor::handleAccepted() |
42 { |
41 { |
43 this->settings->setLocale(this->ui.language->currentData().toString()); |
42 setSetting<Setting::Locale>(this->ui.language->currentData().toString()); |
44 this->settings->setMainColor(this->ui.mainColorButton->selectedColor()); |
43 setSetting<Setting::MainColor>(this->ui.mainColorButton->selectedColor()); |
45 this->settings->setBackgroundColor(this->ui.backgroundColorButton->selectedColor()); |
44 setSetting<Setting::BackgroundColor>(this->ui.backgroundColorButton->selectedColor()); |
46 this->settings->setSelectedColor(this->ui.selectedColorButton->selectedColor()); |
45 setSetting<Setting::SelectedColor>(this->ui.selectedColorButton->selectedColor()); |
47 this->settings->setLineThickness(static_cast<GLfloat>(this->ui.lineThickness->value())); |
46 setSetting<Setting::LineThickness>(static_cast<GLfloat>(this->ui.lineThickness->value())); |
48 this->settings->setLineAntiAliasing(this->ui.lineAntiAliasing->isChecked()); |
47 setSetting<Setting::LineAntiAliasing>(this->ui.lineAntiAliasing->isChecked()); |
49 const int viewMode = this->ui.viewModeButtonGroup->checkedId(); |
48 const int viewMode = this->ui.viewModeButtonGroup->checkedId(); |
50 if (viewMode != -1) { |
49 if (viewMode != -1) { |
51 this->settings->setViewMode(viewMode); |
50 setSetting<Setting::ViewMode>(static_cast<QMdiArea::ViewMode>(viewMode)); |
52 } |
51 } |
53 this->librariesEditor.saveSettings(this->settings); |
52 this->librariesEditor.saveSettings(); |
54 } |
53 } |
55 |
54 |
56 void SettingsEditor::loadLocales() |
55 void SettingsEditor::loadLocales() |
57 { |
56 { |
58 this->ui.language->clear(); |
57 this->ui.language->clear(); |
75 } |
74 } |
76 } |
75 } |
77 |
76 |
78 void SettingsEditor::setDefaults() |
77 void SettingsEditor::setDefaults() |
79 { |
78 { |
80 this->setCurrentLanguage(this->settings->locale()); |
79 this->setCurrentLanguage(setting<Setting::Locale>()); |
81 this->ui.mainColorButton->setSelectedColor(this->settings->mainColor()); |
80 this->ui.mainColorButton->setSelectedColor(setting<Setting::MainColor>()); |
82 this->ui.backgroundColorButton->setSelectedColor(this->settings->backgroundColor()); |
81 this->ui.backgroundColorButton->setSelectedColor(setting<Setting::BackgroundColor>()); |
83 this->ui.selectedColorButton->setSelectedColor(this->settings->selectedColor()); |
82 this->ui.selectedColorButton->setSelectedColor(setting<Setting::SelectedColor>()); |
84 this->ui.lineThickness->setValue(static_cast<double>(this->settings->lineThickness())); |
83 this->ui.lineThickness->setValue(double_cast(setting<Setting::LineThickness>())); |
85 this->ui.lineAntiAliasing->setChecked(this->settings->lineAntiAliasing()); |
84 this->ui.lineAntiAliasing->setChecked(setting<Setting::LineAntiAliasing>()); |
86 auto* const viewModeButton = this->ui.viewModeButtonGroup->button(this->settings->viewMode()); |
85 auto* const viewModeButton = this->ui.viewModeButtonGroup->button(setting<Setting::ViewMode>()); |
87 if (viewModeButton != nullptr) { |
86 if (viewModeButton != nullptr) { |
88 viewModeButton->setChecked(true); |
87 viewModeButton->setChecked(true); |
89 } |
88 } |
90 } |
89 } |
91 |
90 |