diff --git a/include/config.h b/include/config.h index 1fa0be3f..fb94c4be 100644 --- a/include/config.h +++ b/include/config.h @@ -38,6 +38,7 @@ public: this->showPlayerView = false; this->showCursorTile = true; this->regionMapDimensions = QSize(32, 20); + this->theme = "default"; } void setRecentProject(QString project); void setRecentMap(QString map); @@ -49,6 +50,7 @@ public: void setShowPlayerView(bool enabled); void setShowCursorTile(bool enabled); void setRegionMapDimensions(int width, int height); + void setTheme(QString theme); QString getRecentProject(); QString getRecentMap(); MapSortOrder getMapSortOrder(); @@ -59,6 +61,7 @@ public: bool getShowPlayerView(); bool getShowCursorTile(); QSize getRegionMapDimensions(); + QString getTheme(); protected: QString getConfigFilepath(); void parseConfigKeyValue(QString key, QString value); @@ -81,6 +84,7 @@ private: bool showPlayerView; bool showCursorTile; QSize regionMapDimensions; + QString theme; }; extern PorymapConfig porymapConfig; diff --git a/include/mainwindow.h b/include/mainwindow.h index 1aae4d32..b9e5a703 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -211,6 +211,7 @@ private: void setProjectSpecificUIVisibility(); void loadUserSettings(); void restoreWindowState(); + void setTheme(QString); bool openRecentProject(); void updateTilesetEditor(); QString getEventGroupFromTabWidget(QWidget *tab); diff --git a/src/config.cpp b/src/config.cpp index 9ca25a9b..5b974255 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -167,6 +167,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { } else { this->regionMapDimensions = QSize(w, h); } + } else if (key == "theme") { + this->theme = value; } else { logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key)); } @@ -189,6 +191,7 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("show_cursor_tile", this->showCursorTile ? "1" : "0"); map.insert("region_map_dimensions", QString("%1x%2").arg(this->regionMapDimensions.width()) .arg(this->regionMapDimensions.height())); + map.insert("theme", this->theme); return map; } @@ -263,6 +266,10 @@ void PorymapConfig::setRegionMapDimensions(int width, int height) { this->regionMapDimensions = QSize(width, height); } +void PorymapConfig::setTheme(QString theme) { + this->theme = theme; +} + QString PorymapConfig::getRecentProject() { return this->recentProject; } @@ -311,6 +318,10 @@ QSize PorymapConfig::getRegionMapDimensions() { return this->regionMapDimensions; } +QString PorymapConfig::getTheme() { + return this->theme; +} + const QMap baseGameVersionMap = { {BaseGameVersion::pokeruby, "pokeruby"}, {BaseGameVersion::pokeemerald, "pokeemerald"}, diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6d3ebb7d..3593075e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -227,6 +227,7 @@ void MainWindow::loadUserSettings() { ui->horizontalSlider_MetatileZoom->blockSignals(true); ui->horizontalSlider_MetatileZoom->setValue(porymapConfig.getMetatilesZoom()); ui->horizontalSlider_MetatileZoom->blockSignals(false); + setTheme(porymapConfig.getTheme()); } void MainWindow::restoreWindowState() { @@ -239,6 +240,17 @@ void MainWindow::restoreWindowState() { this->ui->splitter_main->restoreState(geometry.value("main_splitter_state")); } +void MainWindow::setTheme(QString theme) { + if (theme == "default") { + setStyleSheet(""); + } else { + QFile File(QString(":/themes/%1.qss").arg(theme)); + File.open(QFile::ReadOnly); + QString stylesheet = QLatin1String(File.readAll()); + setStyleSheet(stylesheet); + } +} + bool MainWindow::openRecentProject() { QString default_dir = porymapConfig.getRecentProject(); if (!default_dir.isNull() && default_dir.length() > 0) { @@ -2136,6 +2148,7 @@ void MainWindow::on_actionThemes_triggered() NoScrollComboBox *themeSelector = new NoScrollComboBox(); themeSelector->addItems(themes); + themeSelector->setCurrentText(porymapConfig.getTheme()); form.addRow(new QLabel("Themes"), themeSelector); QDialogButtonBox buttonBox(QDialogButtonBox::Apply | QDialogButtonBox::Close, Qt::Horizontal, &themeSelectorWindow); @@ -2143,15 +2156,8 @@ void MainWindow::on_actionThemes_triggered() connect(&buttonBox, &QDialogButtonBox::clicked, [&themeSelectorWindow, &buttonBox, themeSelector, this](QAbstractButton *button){ if (button == buttonBox.button(QDialogButtonBox::Apply)) { QString theme = themeSelector->currentText(); - if (theme == "default") { - setStyleSheet(""); - return; - } - - QFile File(QString(":/themes/%1.qss").arg(theme)); - File.open(QFile::ReadOnly); - QString stylesheet = QLatin1String(File.readAll()); - setStyleSheet(stylesheet); + porymapConfig.setTheme(theme); + this->setTheme(theme); } }); connect(&buttonBox, SIGNAL(rejected()), &themeSelectorWindow, SLOT(reject()));