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->showPlayerView = false;
this->showCursorTile = true; this->showCursorTile = true;
this->regionMapDimensions = QSize(32, 20); this->regionMapDimensions = QSize(32, 20);
this->theme = "default";
} }
void setRecentProject(QString project); void setRecentProject(QString project);
void setRecentMap(QString map); void setRecentMap(QString map);
@ -49,6 +50,7 @@ public:
void setShowPlayerView(bool enabled); void setShowPlayerView(bool enabled);
void setShowCursorTile(bool enabled); void setShowCursorTile(bool enabled);
void setRegionMapDimensions(int width, int height); void setRegionMapDimensions(int width, int height);
void setTheme(QString theme);
QString getRecentProject(); QString getRecentProject();
QString getRecentMap(); QString getRecentMap();
MapSortOrder getMapSortOrder(); MapSortOrder getMapSortOrder();
@ -59,6 +61,7 @@ public:
bool getShowPlayerView(); bool getShowPlayerView();
bool getShowCursorTile(); bool getShowCursorTile();
QSize getRegionMapDimensions(); QSize getRegionMapDimensions();
QString getTheme();
protected: protected:
QString getConfigFilepath(); QString getConfigFilepath();
void parseConfigKeyValue(QString key, QString value); void parseConfigKeyValue(QString key, QString value);
@ -81,6 +84,7 @@ private:
bool showPlayerView; bool showPlayerView;
bool showCursorTile; bool showCursorTile;
QSize regionMapDimensions; QSize regionMapDimensions;
QString theme;
}; };
extern PorymapConfig porymapConfig; extern PorymapConfig porymapConfig;

View file

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

View file

@ -167,6 +167,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
} else { } else {
this->regionMapDimensions = QSize(w, h); this->regionMapDimensions = QSize(w, h);
} }
} else if (key == "theme") {
this->theme = value;
} else { } else {
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key)); 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("show_cursor_tile", this->showCursorTile ? "1" : "0");
map.insert("region_map_dimensions", QString("%1x%2").arg(this->regionMapDimensions.width()) map.insert("region_map_dimensions", QString("%1x%2").arg(this->regionMapDimensions.width())
.arg(this->regionMapDimensions.height())); .arg(this->regionMapDimensions.height()));
map.insert("theme", this->theme);
return map; return map;
} }
@ -263,6 +266,10 @@ void PorymapConfig::setRegionMapDimensions(int width, int height) {
this->regionMapDimensions = QSize(width, height); this->regionMapDimensions = QSize(width, height);
} }
void PorymapConfig::setTheme(QString theme) {
this->theme = theme;
}
QString PorymapConfig::getRecentProject() { QString PorymapConfig::getRecentProject() {
return this->recentProject; return this->recentProject;
} }
@ -311,6 +318,10 @@ QSize PorymapConfig::getRegionMapDimensions() {
return this->regionMapDimensions; return this->regionMapDimensions;
} }
QString PorymapConfig::getTheme() {
return this->theme;
}
const QMap<BaseGameVersion, QString> baseGameVersionMap = { const QMap<BaseGameVersion, QString> baseGameVersionMap = {
{BaseGameVersion::pokeruby, "pokeruby"}, {BaseGameVersion::pokeruby, "pokeruby"},
{BaseGameVersion::pokeemerald, "pokeemerald"}, {BaseGameVersion::pokeemerald, "pokeemerald"},

View file

@ -227,6 +227,7 @@ void MainWindow::loadUserSettings() {
ui->horizontalSlider_MetatileZoom->blockSignals(true); ui->horizontalSlider_MetatileZoom->blockSignals(true);
ui->horizontalSlider_MetatileZoom->setValue(porymapConfig.getMetatilesZoom()); ui->horizontalSlider_MetatileZoom->setValue(porymapConfig.getMetatilesZoom());
ui->horizontalSlider_MetatileZoom->blockSignals(false); ui->horizontalSlider_MetatileZoom->blockSignals(false);
setTheme(porymapConfig.getTheme());
} }
void MainWindow::restoreWindowState() { void MainWindow::restoreWindowState() {
@ -239,6 +240,17 @@ void MainWindow::restoreWindowState() {
this->ui->splitter_main->restoreState(geometry.value("main_splitter_state")); 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() { bool MainWindow::openRecentProject() {
QString default_dir = porymapConfig.getRecentProject(); QString default_dir = porymapConfig.getRecentProject();
if (!default_dir.isNull() && default_dir.length() > 0) { if (!default_dir.isNull() && default_dir.length() > 0) {
@ -2136,6 +2148,7 @@ void MainWindow::on_actionThemes_triggered()
NoScrollComboBox *themeSelector = new NoScrollComboBox(); NoScrollComboBox *themeSelector = new NoScrollComboBox();
themeSelector->addItems(themes); themeSelector->addItems(themes);
themeSelector->setCurrentText(porymapConfig.getTheme());
form.addRow(new QLabel("Themes"), themeSelector); form.addRow(new QLabel("Themes"), themeSelector);
QDialogButtonBox buttonBox(QDialogButtonBox::Apply | QDialogButtonBox::Close, Qt::Horizontal, &themeSelectorWindow); 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){ connect(&buttonBox, &QDialogButtonBox::clicked, [&themeSelectorWindow, &buttonBox, themeSelector, this](QAbstractButton *button){
if (button == buttonBox.button(QDialogButtonBox::Apply)) { if (button == buttonBox.button(QDialogButtonBox::Apply)) {
QString theme = themeSelector->currentText(); QString theme = themeSelector->currentText();
if (theme == "default") { porymapConfig.setTheme(theme);
setStyleSheet(""); this->setTheme(theme);
return;
}
QFile File(QString(":/themes/%1.qss").arg(theme));
File.open(QFile::ReadOnly);
QString stylesheet = QLatin1String(File.readAll());
setStyleSheet(stylesheet);
} }
}); });
connect(&buttonBox, SIGNAL(rejected()), &themeSelectorWindow, SLOT(reject())); connect(&buttonBox, SIGNAL(rejected()), &themeSelectorWindow, SLOT(reject()));