From 1b16b903a0d90703c291468baf61b8ef1d3e30b6 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Tue, 17 Sep 2024 10:48:59 -0400 Subject: [PATCH] added saving geometry --- scwx-qt/source/scwx/qt/main/main_window.cpp | 17 ++++++++++++++--- scwx-qt/source/scwx/qt/settings/ui_settings.cpp | 14 ++++++++++++-- scwx-qt/source/scwx/qt/settings/ui_settings.hpp | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index e8217290..d511241a 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -443,10 +443,15 @@ void MainWindow::keyReleaseEvent(QKeyEvent* ev) void MainWindow::showEvent(QShowEvent* event) { QMainWindow::showEvent(event); + auto& uiSettings = settings::UiSettings::Instance(); + + // restore the geometry state + std::string uiGeometry = uiSettings.main_ui_geometry().GetValue(); + restoreGeometry( + QByteArray::fromBase64(QByteArray::fromStdString(uiGeometry))); // restore the UI state - std::string uiState = - settings::UiSettings::Instance().main_ui_state().GetValue(); + std::string uiState = uiSettings.main_ui_state().GetValue(); bool restored = restoreState(QByteArray::fromBase64(QByteArray::fromStdString(uiState))); @@ -458,9 +463,15 @@ void MainWindow::showEvent(QShowEvent* event) void MainWindow::closeEvent(QCloseEvent* event) { + auto& uiSettings = settings::UiSettings::Instance(); + + // save the UI geometry + QByteArray uiGeometry = saveGeometry().toBase64(); + uiSettings.main_ui_geometry().StageValue(uiGeometry.data()); + // save the UI state QByteArray uiState = saveState().toBase64(); - settings::UiSettings::Instance().main_ui_state().StageValue(uiState.data()); + uiSettings.main_ui_state().StageValue(uiState.data()); QMainWindow::closeEvent(event); } diff --git a/scwx-qt/source/scwx/qt/settings/ui_settings.cpp b/scwx-qt/source/scwx/qt/settings/ui_settings.cpp index 3ef1a23d..eca2c8e1 100644 --- a/scwx-qt/source/scwx/qt/settings/ui_settings.cpp +++ b/scwx-qt/source/scwx/qt/settings/ui_settings.cpp @@ -20,6 +20,7 @@ public: mapSettingsExpanded_.SetDefault(true); timelineExpanded_.SetDefault(true); mainUIState_.SetDefault(""); + mainUIGeometry_.SetDefault(""); } ~UiSettingsImpl() {} @@ -30,6 +31,7 @@ public: SettingsVariable mapSettingsExpanded_ {"map_settings_expanded"}; SettingsVariable timelineExpanded_ {"timeline_expanded"}; SettingsVariable mainUIState_ {"main_ui_state"}; + SettingsVariable mainUIGeometry_ {"main_ui_geometry"}; }; UiSettings::UiSettings() : @@ -40,7 +42,8 @@ UiSettings::UiSettings() : &p->level3ProductsExpanded_, &p->mapSettingsExpanded_, &p->timelineExpanded_, - &p->mainUIState_}); + &p->mainUIState_, + &p->mainUIGeometry_}); SetDefaults(); } UiSettings::~UiSettings() = default; @@ -78,6 +81,11 @@ SettingsVariable& UiSettings::main_ui_state() const return p->mainUIState_; } +SettingsVariable& UiSettings::main_ui_geometry() const +{ + return p->mainUIGeometry_; +} + bool UiSettings::Shutdown() { bool dataChanged = false; @@ -89,6 +97,7 @@ bool UiSettings::Shutdown() dataChanged |= p->mapSettingsExpanded_.Commit(); dataChanged |= p->timelineExpanded_.Commit(); dataChanged |= p->mainUIState_.Commit(); + dataChanged |= p->mainUIGeometry_.Commit(); return dataChanged; } @@ -106,7 +115,8 @@ bool operator==(const UiSettings& lhs, const UiSettings& rhs) lhs.p->level3ProductsExpanded_ == rhs.p->level3ProductsExpanded_ && lhs.p->mapSettingsExpanded_ == rhs.p->mapSettingsExpanded_ && lhs.p->timelineExpanded_ == rhs.p->timelineExpanded_ && - lhs.p->mainUIState_ == rhs.p->mainUIState_); + lhs.p->mainUIState_ == rhs.p->mainUIState_ && + lhs.p->mainUIGeometry_ == rhs.p->mainUIGeometry_); } } // namespace settings diff --git a/scwx-qt/source/scwx/qt/settings/ui_settings.hpp b/scwx-qt/source/scwx/qt/settings/ui_settings.hpp index 6227a93a..0a9f95ef 100644 --- a/scwx-qt/source/scwx/qt/settings/ui_settings.hpp +++ b/scwx-qt/source/scwx/qt/settings/ui_settings.hpp @@ -33,6 +33,7 @@ public: SettingsVariable& map_settings_expanded() const; SettingsVariable& timeline_expanded() const; SettingsVariable& main_ui_state() const; + SettingsVariable& main_ui_geometry() const; bool Shutdown();