Sun, 26 Jun 2022 19:44:45 +0300
- Made it build under Qt6
- Fix strangeness involving library path settings
#include <QSettings> #include <QMdiArea> #include "settings.h" #include "gl/common.h" #include "keyboardshortcutseditor.h" #include "settingseditor.h" #include "ui_settingseditor.h" SettingsEditor::SettingsEditor( const uiutilities::KeySequenceMap& defaultKeyboardShortcuts, QWidget* parent ) : QDialog{parent}, ui{*new Ui_SettingsEditor}, libraries{this}, librariesEditor{this}, defaultKeyboardShortcuts{defaultKeyboardShortcuts} { this->ui.setupUi(this); this->ui.keyboardShortcutsView->setModel(new KeyboardShortcutsEditor{parent, this}); this->ui.viewModeButtonGroup->setId(this->ui.viewModeTabs, int{QMdiArea::TabbedView}); this->ui.viewModeButtonGroup->setId(this->ui.viewModeSubWindows, int{QMdiArea::SubWindowView}); this->loadLocales(); this->setDefaults(); this->librariesEditor.setModel(&libraries); QVBoxLayout* layout = new QVBoxLayout{this}; layout->addWidget(&librariesEditor); this->ui.tabLdrawLibraries->setLayout(layout); connect( this, &SettingsEditor::accepted, this, &SettingsEditor::handleAccepted); } SettingsEditor::~SettingsEditor() { delete &this->ui; } void SettingsEditor::handleAccepted() { setSetting<Setting::Locale>(this->ui.language->currentData().toString()); setSetting<Setting::MainColor>(this->ui.mainColorButton->color()); setSetting<Setting::BackgroundColor>(this->ui.backgroundColorButton->color()); setSetting<Setting::SelectedColor>(this->ui.selectedColorButton->color()); setSetting<Setting::LineThickness>(static_cast<GLfloat>(this->ui.lineThickness->value())); setSetting<Setting::LineAntiAliasing>(this->ui.lineAntiAliasing->isChecked()); setSetting<Setting::LogOpenGLDebugMessages>(this->ui.logOpenGLDebugMessages->isChecked()); const int viewMode = this->ui.viewModeButtonGroup->checkedId(); if (viewMode != -1) { setSetting<Setting::ViewMode>(static_cast<QMdiArea::ViewMode>(viewMode)); } this->librariesEditor.saveSettings(); } void SettingsEditor::loadLocales() { this->ui.language->clear(); QDir dir{":/locale"}; // Collect translation files in built-in resources QVector<QString> localeCodes = {"en"}; // English is the default locale for (const QFileInfo& file : dir.entryInfoList(QDir::Files)) { localeCodes.append(file.baseName()); } std::sort(localeCodes.begin(), localeCodes.end()); this->ui.language->addItem(tr("System language"), "system"); for (const QString& localeCode : localeCodes) { const QLocale locale{localeCode}; const QString languageName = QLocale::languageToString(locale.language()); const QIcon flag{":/flags/" + localeCode + ".png"}; this->ui.language->addItem(languageName, localeCode); this->ui.language->setItemIcon(this->ui.language->count() - 1, flag); } } void SettingsEditor::setDefaults() { this->libraries.restoreFromSettings(); this->setCurrentLanguage(setting<Setting::Locale>()); this->ui.mainColorButton->setColor(setting<Setting::MainColor>()); this->ui.backgroundColorButton->setColor(setting<Setting::BackgroundColor>()); this->ui.selectedColorButton->setColor(setting<Setting::SelectedColor>()); this->ui.lineThickness->setValue(double_cast(setting<Setting::LineThickness>())); this->ui.lineAntiAliasing->setChecked(setting<Setting::LineAntiAliasing>()); this->ui.logOpenGLDebugMessages->setChecked(setting<Setting::LogOpenGLDebugMessages>()); auto* const viewModeButton = this->ui.viewModeButtonGroup->button(setting<Setting::ViewMode>()); if (viewModeButton != nullptr) { viewModeButton->setChecked(true); } } void SettingsEditor::setCurrentLanguage(const QString& localeCode) { for (int i = 0; i < this->ui.language->count(); i += 1) { if (this->ui.language->itemData(i) == localeCode) { this->ui.language->setCurrentIndex(i); break; } } }