src/settingseditor/settingseditor.cpp

changeset 296
38f6fad61bad
parent 286
04478da357d0
child 335
c5830bce1c23
equal deleted inserted replaced
295:4241d948af28 296:38f6fad61bad
20 this->ui.setupUi(widget); 20 this->ui.setupUi(widget);
21 this->setWidget(widget); 21 this->setWidget(widget);
22 this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this}); 22 this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this});
23 this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView}); 23 this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView});
24 this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView}); 24 this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView});
25 this->loadLocales();
26 this->loadSettings(); 25 this->loadSettings();
27 this->setWindowTitle(tr("Settings")); 26 this->setWindowTitle(tr("Settings"));
28 this->setWindowIcon(QIcon{":/icons/settings-outline.png"}); 27 this->setWindowIcon(QIcon{":/icons/settings-outline.png"});
29 this->librariesEditor.setModel(&libraries); 28 this->librariesEditor.setModel(&libraries);
30 QVBoxLayout* layout = new QVBoxLayout{this}; 29 QVBoxLayout* layout = new QVBoxLayout{this};
44 delete &this->ui; 43 delete &this->ui;
45 } 44 }
46 45
47 void SettingsEditor::saveSettings() 46 void SettingsEditor::saveSettings()
48 { 47 {
49 //setSetting<Setting::Locale>(this->ui.language->currentData().toString());
50 setSetting<Setting::MainColor>(this->ui.mainColorButton->color()); 48 setSetting<Setting::MainColor>(this->ui.mainColorButton->color());
51 setSetting<Setting::BackgroundColor>(this->ui.backgroundColorButton->color()); 49 setSetting<Setting::BackgroundColor>(this->ui.backgroundColorButton->color());
52 setSetting<Setting::SelectedColor>(this->ui.selectedColorButton->color()); 50 setSetting<Setting::SelectedColor>(this->ui.selectedColorButton->color());
53 setSetting<Setting::LineThickness>(static_cast<GLfloat>(this->ui.lineThickness->value())); 51 setSetting<Setting::LineThickness>(static_cast<GLfloat>(this->ui.lineThickness->value()));
54 setSetting<Setting::LineAntiAliasing>(this->ui.lineAntiAliasing->isChecked()); 52 setSetting<Setting::LineAntiAliasing>(this->ui.lineAntiAliasing->isChecked());
59 } 57 }
60 this->librariesEditor.saveSettings(); 58 this->librariesEditor.saveSettings();
61 Q_EMIT this->settingsChanged(); 59 Q_EMIT this->settingsChanged();
62 } 60 }
63 61
64 void SettingsEditor::loadLocales()
65 {
66 /*
67 this->ui.language->clear();
68 QDir dir{":/locale"};
69 // Collect translation files in built-in resources
70 QVector<QString> localeCodes = {"en"}; // English is the default locale
71 for (const QFileInfo& file : dir.entryInfoList(QDir::Files))
72 {
73 localeCodes.append(file.baseName());
74 }
75 std::sort(localeCodes.begin(), localeCodes.end());
76 this->ui.language->addItem(tr("System language"), "system");
77 for (const QString& localeCode : localeCodes)
78 {
79 const QLocale locale{localeCode};
80 const QString languageName = QLocale::languageToString(locale.language());
81 const QIcon flag{":/flags/" + localeCode + ".png"};
82 this->ui.language->addItem(languageName, localeCode);
83 this->ui.language->setItemIcon(this->ui.language->count() - 1, flag);
84 }
85 */
86 }
87
88 void SettingsEditor::loadSettings() 62 void SettingsEditor::loadSettings()
89 { 63 {
90 this->libraries.restoreFromSettings(); 64 this->libraries.restoreFromSettings();
91 //this->setCurrentLanguage(setting<Setting::Locale>());
92 this->ui.mainColorButton->setColor(setting<Setting::MainColor>()); 65 this->ui.mainColorButton->setColor(setting<Setting::MainColor>());
93 this->ui.backgroundColorButton->setColor(setting<Setting::BackgroundColor>()); 66 this->ui.backgroundColorButton->setColor(setting<Setting::BackgroundColor>());
94 this->ui.selectedColorButton->setColor(setting<Setting::SelectedColor>()); 67 this->ui.selectedColorButton->setColor(setting<Setting::SelectedColor>());
95 this->ui.lineThickness->setValue(double_cast(setting<Setting::LineThickness>())); 68 this->ui.lineThickness->setValue(double_cast(setting<Setting::LineThickness>()));
96 this->ui.lineAntiAliasing->setChecked(setting<Setting::LineAntiAliasing>()); 69 this->ui.lineAntiAliasing->setChecked(setting<Setting::LineAntiAliasing>());
98 auto* const viewModeButton = this->ui.viewModeButtonGroup->button(setting<Setting::ViewMode>()); 71 auto* const viewModeButton = this->ui.viewModeButtonGroup->button(setting<Setting::ViewMode>());
99 if (viewModeButton != nullptr) { 72 if (viewModeButton != nullptr) {
100 viewModeButton->setChecked(true); 73 viewModeButton->setChecked(true);
101 } 74 }
102 } 75 }
103
104 void SettingsEditor::setCurrentLanguage(const QString& localeCode)
105 {
106 /*
107 for (int i = 0; i < this->ui.language->count(); i += 1)
108 {
109 if (this->ui.language->itemData(i) == localeCode)
110 {
111 this->ui.language->setCurrentIndex(i);
112 break;
113 }
114 }
115 */
116 }

mercurial