diff options
Diffstat (limited to 'src/ui/main_window/GeneralMainWindow.cpp')
-rw-r--r-- | src/ui/main_window/GeneralMainWindow.cpp | 88 |
1 files changed, 32 insertions, 56 deletions
diff --git a/src/ui/main_window/GeneralMainWindow.cpp b/src/ui/main_window/GeneralMainWindow.cpp index ad2f061a..2eb9f2a4 100644 --- a/src/ui/main_window/GeneralMainWindow.cpp +++ b/src/ui/main_window/GeneralMainWindow.cpp @@ -28,9 +28,13 @@ #include "GeneralMainWindow.h" -#include <utility> - #include "ui/struct/SettingsObject.h" +#include "ui/struct/settings/AppearanceSO.h" +#include "ui/struct/settings/WindowStateSO.h" + +namespace GpgFrontend::UI { + +class GeneralWindowState {}; GpgFrontend::UI::GeneralMainWindow::GeneralMainWindow(QString name, QWidget *parent) @@ -50,30 +54,19 @@ void GpgFrontend::UI::GeneralMainWindow::closeEvent(QCloseEvent *event) { void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { try { - SettingsObject general_windows_state(name_ + "_state"); + WindowStateSO window_state(SettingsObject(name_ + "_state")); - QString window_state = QString::fromStdString(general_windows_state.Check( - "window_state", saveState().toBase64().toStdString())); - GF_UI_LOG_DEBUG("restore main window state: {}", window_state); + GF_UI_LOG_DEBUG("restore main window state: {}", + window_state.window_state_data); // state sets pos & size of dock-widgets - this->restoreState(QByteArray::fromBase64(window_state.toUtf8())); - - bool window_save = general_windows_state.Check("window_save", true); - - // Restore window size & location - if (window_save) { - int x = general_windows_state.Check("window_pos").Check("x", 100); - int y = general_windows_state.Check("window_pos").Check("y", 100); - - pos_ = {x, y}; - - int width = - general_windows_state.Check("window_size").Check("width", 800); - int height = - general_windows_state.Check("window_size").Check("height", 450); + this->restoreState( + QByteArray::fromBase64(window_state.window_state_data.toUtf8())); - size_ = {width, height}; + // restore window size & location + if (window_state.window_save) { + pos_ = {window_state.x, window_state.y}; + size_ = {window_state.width, window_state.height}; if (this->parent() != nullptr) { GF_UI_LOG_DEBUG("parent address: {}", @@ -114,21 +107,14 @@ void GpgFrontend::UI::GeneralMainWindow::slot_restore_settings() noexcept { } // appearance - SettingsObject general_settings_state("general_settings_state"); + AppearanceSO appearance(SettingsObject("general_settings_state")); - int width = general_settings_state.Check("icon_size").Check("width", 24); - int height = general_settings_state.Check("icon_size").Check("height", 24); - GF_UI_LOG_DEBUG("icon size: {} {}", width, height); - - icon_size_ = {width, height}; - font_size_ = general_settings_state.Check("font_size", 10); + icon_size_ = {appearance.tool_bar_icon_width, + appearance.tool_bar_icon_height}; + font_size_ = appearance.info_board_font_size; this->setIconSize(icon_size_); - - // icon_style - int s_icon_style = - general_settings_state.Check("icon_style", Qt::ToolButtonTextUnderIcon); - this->setToolButtonStyle(static_cast<Qt::ToolButtonStyle>(s_icon_style)); + this->setToolButtonStyle(appearance.tool_bar_button_style); icon_style_ = toolButtonStyle(); } catch (...) { @@ -141,32 +127,22 @@ void GpgFrontend::UI::GeneralMainWindow::slot_save_settings() noexcept { GF_UI_LOG_DEBUG("save main window state, name: {}", name_); SettingsObject general_windows_state(name_ + "_state"); - // window position and size - general_windows_state["window_state"] = - saveState().toBase64().toStdString(); - general_windows_state["window_pos"]["x"] = pos().x(); - general_windows_state["window_pos"]["y"] = pos().y(); - - // update size of current dialog + // update geo of current dialog size_ = this->size(); + pos_ = this->pos(); - general_windows_state["window_size"]["width"] = size_.width(); - general_windows_state["window_size"]["height"] = size_.height(); - general_windows_state["window_save"] = true; - - SettingsObject general_settings_state("general_settings_state"); - - // icon size - general_settings_state["icon_size"]["width"] = icon_size_.width(); - general_settings_state["icon_size"]["height"] = icon_size_.height(); - - // font size - general_settings_state["font_size"] = font_size_; - - // tool button style - general_settings_state["icon_style"] = this->toolButtonStyle(); + WindowStateSO window_state; + window_state.x = pos_.x(); + window_state.y = pos_.y(); + window_state.width = size_.width(); + window_state.height = size_.height(); + window_state.window_save = true; + window_state.window_state_data = this->saveState().toBase64(); + general_windows_state.Store(window_state.Json()); } catch (...) { GF_UI_LOG_ERROR("gernal main window: {}, caught exception", name_); } } + +} // namespace GpgFrontend::UI
\ No newline at end of file |