add themes to config so they persist between sessions

This commit is contained in:
garak 2019-08-14 18:02:00 -04:00 committed by huderlem
parent 376cfbf9c3
commit 230b018834
4 changed files with 31 additions and 9 deletions

View file

@ -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;

View file

@ -211,6 +211,7 @@ private:
void setProjectSpecificUIVisibility();
void loadUserSettings();
void restoreWindowState();
void setTheme(QString);
bool openRecentProject();
void updateTilesetEditor();
QString getEventGroupFromTabWidget(QWidget *tab);

View file

@ -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<QString, QString> 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<BaseGameVersion, QString> baseGameVersionMap = {
{BaseGameVersion::pokeruby, "pokeruby"},
{BaseGameVersion::pokeemerald, "pokeemerald"},

View file

@ -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()));