19 this->ui.setupUi(this); |
19 this->ui.setupUi(this); |
20 this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this}); |
20 this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this}); |
21 this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView}); |
21 this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView}); |
22 this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView}); |
22 this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView}); |
23 this->loadLocales(); |
23 this->loadLocales(); |
24 this->setDefaults(); |
24 this->loadSettings(); |
|
25 this->setWindowTitle(tr("Settings")); |
25 this->librariesEditor.setModel(&libraries); |
26 this->librariesEditor.setModel(&libraries); |
26 QVBoxLayout* layout = new QVBoxLayout{this}; |
27 QVBoxLayout* layout = new QVBoxLayout{this}; |
27 layout->addWidget(&librariesEditor); |
28 layout->addWidget(&librariesEditor); |
28 this->ui.tabLdrawLibraries->setLayout(layout); |
29 this->ui.tabLdrawLibraries->setLayout(layout); |
29 connect( |
30 connect(this->ui.buttonBox, &QDialogButtonBox::clicked, |
30 this, |
31 [&](QAbstractButton* button) { |
31 &SettingsEditor::accepted, |
32 const auto role = this->ui.buttonBox->buttonRole(button); |
32 this, |
33 if (role == QDialogButtonBox::ApplyRole) { |
33 &SettingsEditor::handleAccepted); |
34 this->saveSettings(); |
|
35 } |
|
36 }); |
34 } |
37 } |
35 |
38 |
36 SettingsEditor::~SettingsEditor() |
39 SettingsEditor::~SettingsEditor() |
37 { |
40 { |
38 delete &this->ui; |
41 delete &this->ui; |
39 } |
42 } |
40 |
43 |
41 void SettingsEditor::handleAccepted() |
44 void SettingsEditor::saveSettings() |
42 { |
45 { |
43 setSetting<Setting::Locale>(this->ui.language->currentData().toString()); |
46 setSetting<Setting::Locale>(this->ui.language->currentData().toString()); |
44 setSetting<Setting::MainColor>(this->ui.mainColorButton->color()); |
47 setSetting<Setting::MainColor>(this->ui.mainColorButton->color()); |
45 setSetting<Setting::BackgroundColor>(this->ui.backgroundColorButton->color()); |
48 setSetting<Setting::BackgroundColor>(this->ui.backgroundColorButton->color()); |
46 setSetting<Setting::SelectedColor>(this->ui.selectedColorButton->color()); |
49 setSetting<Setting::SelectedColor>(this->ui.selectedColorButton->color()); |
50 const int viewMode = this->ui.viewModeButtonGroup->checkedId(); |
53 const int viewMode = this->ui.viewModeButtonGroup->checkedId(); |
51 if (viewMode != -1) { |
54 if (viewMode != -1) { |
52 setSetting<Setting::ViewMode>(static_cast<QMdiArea::ViewMode>(viewMode)); |
55 setSetting<Setting::ViewMode>(static_cast<QMdiArea::ViewMode>(viewMode)); |
53 } |
56 } |
54 this->librariesEditor.saveSettings(); |
57 this->librariesEditor.saveSettings(); |
|
58 Q_EMIT this->settingsChanged(); |
55 } |
59 } |
56 |
60 |
57 void SettingsEditor::loadLocales() |
61 void SettingsEditor::loadLocales() |
58 { |
62 { |
59 this->ui.language->clear(); |
63 this->ui.language->clear(); |
74 this->ui.language->addItem(languageName, localeCode); |
78 this->ui.language->addItem(languageName, localeCode); |
75 this->ui.language->setItemIcon(this->ui.language->count() - 1, flag); |
79 this->ui.language->setItemIcon(this->ui.language->count() - 1, flag); |
76 } |
80 } |
77 } |
81 } |
78 |
82 |
79 void SettingsEditor::setDefaults() |
83 void SettingsEditor::loadSettings() |
80 { |
84 { |
81 this->libraries.restoreFromSettings(); |
85 this->libraries.restoreFromSettings(); |
82 this->setCurrentLanguage(setting<Setting::Locale>()); |
86 this->setCurrentLanguage(setting<Setting::Locale>()); |
83 this->ui.mainColorButton->setColor(setting<Setting::MainColor>()); |
87 this->ui.mainColorButton->setColor(setting<Setting::MainColor>()); |
84 this->ui.backgroundColorButton->setColor(setting<Setting::BackgroundColor>()); |
88 this->ui.backgroundColorButton->setColor(setting<Setting::BackgroundColor>()); |