From 5624de750b3fc0838107972b5b44543c65343b0f Mon Sep 17 00:00:00 2001 From: BigBahss Date: Tue, 15 Sep 2020 14:57:46 -0400 Subject: [PATCH] Save & restore tileset editor geometry & state from config --- include/config.h | 12 +++++++---- src/config.cpp | 45 +++++++++++++++++++++++++++++----------- src/mainwindow.cpp | 15 ++++++++------ src/ui/tileseteditor.cpp | 5 +++++ 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/include/config.h b/include/config.h index 4bd21cfe..e9aa6943 100644 --- a/include/config.h +++ b/include/config.h @@ -50,7 +50,8 @@ public: void setRecentMap(QString map); void setMapSortOrder(MapSortOrder order); void setPrettyCursors(bool enabled); - void setGeometry(QByteArray, QByteArray, QByteArray, QByteArray); + void setMainGeometry(QByteArray, QByteArray, QByteArray, QByteArray); + void setTilesetEditorGeometry(QByteArray, QByteArray); void setCollisionOpacity(int opacity); void setMetatilesZoom(int zoom); void setShowPlayerView(bool enabled); @@ -62,7 +63,8 @@ public: QString getRecentMap(); MapSortOrder getMapSortOrder(); bool getPrettyCursors(); - QMap getGeometry(); + QMap getMainGeometry(); + QMap getTilesetEditorGeometry(); int getCollisionOpacity(); int getMetatilesZoom(); bool getShowPlayerView(); @@ -83,11 +85,13 @@ private: QByteArray bytesFromString(QString); MapSortOrder mapSortOrder; bool prettyCursors; - QByteArray windowGeometry; - QByteArray windowState; + QByteArray mainWindowGeometry; + QByteArray mainWindowState; QByteArray mapSplitterState; QByteArray eventsSlpitterState; QByteArray mainSplitterState; + QByteArray tilesetEditorGeometry; + QByteArray tilesetEditorState; int collisionOpacity; int metatilesZoom; bool showPlayerView; diff --git a/src/config.cpp b/src/config.cpp index 8934f707..f12c3789 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -122,10 +122,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { this->mapSortOrder = MapSortOrder::Group; logWarn(QString("Invalid config value for map_sort_order: '%1'. Must be 'group', 'area', or 'layout'.").arg(value)); } - } else if (key == "window_geometry") { - this->windowGeometry = bytesFromString(value); - } else if (key == "window_state") { - this->windowState = bytesFromString(value); + } else if (key == "main_window_geometry") { + this->mainWindowGeometry = bytesFromString(value); + } else if (key == "main_window_state") { + this->mainWindowState = bytesFromString(value); } else if (key == "map_splitter_state") { this->mapSplitterState = bytesFromString(value); } else if (key == "main_splitter_state") { @@ -137,6 +137,10 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { logWarn(QString("Invalid config value for collision_opacity: '%1'. Must be an integer.").arg(value)); this->collisionOpacity = 50; } + } else if (key == "tileset_editor_geometry") { + this->tilesetEditorGeometry = bytesFromString(value); + } else if (key == "tileset_editor_state") { + this->tilesetEditorState = bytesFromString(value); } else if (key == "metatiles_zoom") { bool ok; this->metatilesZoom = qMax(10, qMin(100, value.toInt(&ok))); @@ -186,10 +190,12 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("recent_map", this->recentMap); map.insert("pretty_cursors", this->prettyCursors ? "1" : "0"); map.insert("map_sort_order", mapSortOrderMap.value(this->mapSortOrder)); - map.insert("window_geometry", stringFromByteArray(this->windowGeometry)); - map.insert("window_state", stringFromByteArray(this->windowState)); + map.insert("main_window_geometry", stringFromByteArray(this->mainWindowGeometry)); + map.insert("main_window_state", stringFromByteArray(this->mainWindowState)); map.insert("map_splitter_state", stringFromByteArray(this->mapSplitterState)); map.insert("main_splitter_state", stringFromByteArray(this->mainSplitterState)); + map.insert("tileset_editor_geometry", stringFromByteArray(this->tilesetEditorGeometry)); + map.insert("tileset_editor_state", stringFromByteArray(this->tilesetEditorState)); map.insert("collision_opacity", QString("%1").arg(this->collisionOpacity)); map.insert("metatiles_zoom", QString("%1").arg(this->metatilesZoom)); map.insert("show_player_view", this->showPlayerView ? "1" : "0"); @@ -243,15 +249,21 @@ void PorymapConfig::setMonitorFiles(bool monitor) { this->save(); } -void PorymapConfig::setGeometry(QByteArray windowGeometry_, QByteArray windowState_, +void PorymapConfig::setMainGeometry(QByteArray mainWindowGeometry_, QByteArray mainWindowState_, QByteArray mapSplitterState_, QByteArray mainSplitterState_) { - this->windowGeometry = windowGeometry_; - this->windowState = windowState_; + this->mainWindowGeometry = mainWindowGeometry_; + this->mainWindowState = mainWindowState_; this->mapSplitterState = mapSplitterState_; this->mainSplitterState = mainSplitterState_; this->save(); } +void PorymapConfig::setTilesetEditorGeometry(QByteArray tilesetEditorGeometry_, QByteArray tilesetEditorState_) { + this->tilesetEditorGeometry = tilesetEditorGeometry_; + this->tilesetEditorState = tilesetEditorState_; + this->save(); +} + void PorymapConfig::setCollisionOpacity(int opacity) { this->collisionOpacity = opacity; // don't auto-save here because this can be called very frequently. @@ -296,17 +308,26 @@ bool PorymapConfig::getPrettyCursors() { return this->prettyCursors; } -QMap PorymapConfig::getGeometry() { +QMap PorymapConfig::getMainGeometry() { QMap geometry; - geometry.insert("window_geometry", this->windowGeometry); - geometry.insert("window_state", this->windowState); + geometry.insert("main_window_geometry", this->mainWindowGeometry); + geometry.insert("main_window_state", this->mainWindowState); geometry.insert("map_splitter_state", this->mapSplitterState); geometry.insert("main_splitter_state", this->mainSplitterState); return geometry; } +QMap PorymapConfig::getTilesetEditorGeometry() { + QMap geometry; + + geometry.insert("tileset_editor_geometry", this->tilesetEditorGeometry); + geometry.insert("tileset_editor_state", this->tilesetEditorState); + + return geometry; +} + int PorymapConfig::getCollisionOpacity() { return this->collisionOpacity; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e2ae8bdb..4738d004 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -350,10 +350,10 @@ void MainWindow::loadUserSettings() { } void MainWindow::restoreWindowState() { - logInfo("Restoring window geometry from previous session."); - QMap geometry = porymapConfig.getGeometry(); - this->restoreGeometry(geometry.value("window_geometry")); - this->restoreState(geometry.value("window_state")); + logInfo("Restoring main window geometry from previous session."); + QMap geometry = porymapConfig.getMainGeometry(); + this->restoreGeometry(geometry.value("main_window_geometry")); + this->restoreState(geometry.value("main_window_state")); this->ui->splitter_map->restoreState(geometry.value("map_splitter_state")); this->ui->splitter_main->restoreState(geometry.value("main_splitter_state")); } @@ -2518,7 +2518,10 @@ void MainWindow::on_actionTileset_Editor_triggered() this->tilesetEditor = new TilesetEditor(this->editor->project, this->editor->map, this); connect(this->tilesetEditor, SIGNAL(tilesetsSaved(QString, QString)), this, SLOT(onTilesetsSaved(QString, QString))); connect(this->tilesetEditor, &QObject::destroyed, [=](QObject *) { this->tilesetEditor = nullptr; }); - this->tilesetEditor->setAttribute(Qt::WA_DeleteOnClose); + logInfo("Restoring tileset editor geometry from previous session."); + QMap geometry = porymapConfig.getTilesetEditorGeometry(); + this->tilesetEditor->restoreGeometry(geometry.value("tileset_editor_geometry")); + this->tilesetEditor->restoreState(geometry.value("tileset_editor_state")); } if (!this->tilesetEditor->isVisible()) { @@ -2697,7 +2700,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { } } - porymapConfig.setGeometry( + porymapConfig.setMainGeometry( this->saveGeometry(), this->saveState(), this->ui->splitter_map->saveState(), diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 75a60b9a..de095a80 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -606,6 +606,11 @@ void TilesetEditor::closeEvent(QCloseEvent *event) } else { event->accept(); } + + porymapConfig.setTilesetEditorGeometry( + this->saveGeometry(), + this->saveState() + ); } void TilesetEditor::on_actionChange_Metatiles_Count_triggered()