From 6899b673c4829f6a51a939318d940f2d4fbc7789 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 23 Jun 2022 18:24:40 +0300 Subject: [PATCH 53/53] Qt: Make options dialogs to remember their geometry Requested by ddeanbrown See osdn #44391 Signed-off-by: Marko Lindqvist --- client/gui-qt/fc_client.cpp | 12 +++++++-- client/gui-qt/fc_client.h | 2 ++ client/gui-qt/optiondlg.cpp | 51 ++++++++++++++++++++++++++++++++++--- client/gui-qt/optiondlg.h | 17 ++++++++++--- 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/client/gui-qt/fc_client.cpp b/client/gui-qt/fc_client.cpp index 247cb1cff3..d1365df51b 100644 --- a/client/gui-qt/fc_client.cpp +++ b/client/gui-qt/fc_client.cpp @@ -692,6 +692,12 @@ void fc_client::read_settings() if (s.contains("help_splitter1")) { qt_settings.help_splitter1 = s.value("help_splitter1").toByteArray(); } + if (s.contains("opt-client-dialog")) { + qt_settings.options_client_geometry = s.value("opt-client-dialog").toByteArray(); + } + if (s.contains("opt-server-dialog")) { + qt_settings.options_server_geometry = s.value("opt-server-dialog").toByteArray(); + } if (s.contains("new_turn_text")) { qt_settings.show_new_turn_text = s.value("new_turn_text").toBool(); } else { @@ -765,6 +771,8 @@ void fc_client::write_settings() s.setValue("splitter3", qt_settings.city_splitter3); s.setValue("help-dialog", qt_settings.help_geometry); s.setValue("help_splitter1", qt_settings.help_splitter1); + s.setValue("opt-client-dialog", qt_settings.options_client_geometry); + s.setValue("opt-server-dialog", qt_settings.options_server_geometry); s.setValue("unit_fx", qt_settings.unit_info_pos_fx); s.setValue("unit_fy", qt_settings.unit_info_pos_fy); s.setValue("minimap_x", qt_settings.minimap_x); @@ -835,7 +843,7 @@ void fc_client::remove_repo_dlg(QString str) ****************************************************************************/ void fc_client::popup_client_options() { - option_dialog_popup(_("Set local options"), client_optset); + option_dialog_popup(_("Set local options"), client_optset, true); } /************************************************************************//** @@ -1304,5 +1312,5 @@ void pregame_options::pick_nation() ****************************************************************************/ void pregame_options::popup_server_options() { - option_dialog_popup(_("Set server options"), server_optset); + option_dialog_popup(_("Set server options"), server_optset, false); } diff --git a/client/gui-qt/fc_client.h b/client/gui-qt/fc_client.h index 2ed4ae80d3..f7afb4f69f 100644 --- a/client/gui-qt/fc_client.h +++ b/client/gui-qt/fc_client.h @@ -136,6 +136,8 @@ struct fc_settings QByteArray city_splitter3; QByteArray help_geometry; QByteArray help_splitter1; + QByteArray options_client_geometry; + QByteArray options_server_geometry; float unit_info_pos_fx; float unit_info_pos_fy; float minimap_x; diff --git a/client/gui-qt/optiondlg.cpp b/client/gui-qt/optiondlg.cpp index b29467c9a4..0d1b272152 100644 --- a/client/gui-qt/optiondlg.cpp +++ b/client/gui-qt/optiondlg.cpp @@ -123,8 +123,9 @@ QString cut_helptext(QString text) Constructor for options dialog. ****************************************************************************/ option_dialog::option_dialog(const QString &name, - const option_set *options, QWidget *parent) - : qfc_dialog(parent) + const option_set *options, bool client_set, + QWidget *parent) + : qfc_dialog(parent), client_settings(client_set) { QPushButton *but; @@ -767,7 +768,8 @@ void option_dialog::add_option(struct option *poption) /************************************************************************//** Popup the option dialog for the option set. ****************************************************************************/ -void option_dialog_popup(QString name, const struct option_set *poptset) +void option_dialog_popup(QString name, const struct option_set *poptset, + bool client_set) { option_dialog *opt_dialog; @@ -775,7 +777,8 @@ void option_dialog_popup(QString name, const struct option_set *poptset) opt_dialog = dialog_list[poptset]; opt_dialog->show(); } else { - opt_dialog = new option_dialog(name, poptset, gui()->central_wdg); + opt_dialog = new option_dialog(name, poptset, client_set, + gui()->central_wdg); ::dialog_list.insert(poptset, opt_dialog); opt_dialog->show(); } @@ -857,6 +860,46 @@ void option_dialog::set_color() } } +/************************************************************************//** + Show event for options dialog +****************************************************************************/ +void option_dialog::showEvent(QShowEvent *event) +{ + if (client_settings) { + if (!gui()->qt_settings.options_client_geometry.isNull()) { + restoreGeometry(gui()->qt_settings.options_client_geometry); + } + } else { + if (!gui()->qt_settings.options_server_geometry.isNull()) { + restoreGeometry(gui()->qt_settings.options_server_geometry); + } + } +} + +/************************************************************************//** + Hide event for options dialog +****************************************************************************/ +void option_dialog::hideEvent(QHideEvent *event) +{ + if (client_settings) { + gui()->qt_settings.options_client_geometry = saveGeometry(); + } else { + gui()->qt_settings.options_server_geometry = saveGeometry(); + } +} + +/************************************************************************//** + Close event for options dialog +****************************************************************************/ +void option_dialog::closeEvent(QCloseEvent *event) +{ + if (client_settings) { + gui()->qt_settings.options_client_geometry = saveGeometry(); + } else { + gui()->qt_settings.options_server_geometry = saveGeometry(); + } +} + /************************************************************************//** Popdown the option dialog for the option set. ****************************************************************************/ diff --git a/client/gui-qt/optiondlg.h b/client/gui-qt/optiondlg.h index 15dac85129..8deae7a27e 100644 --- a/client/gui-qt/optiondlg.h +++ b/client/gui-qt/optiondlg.h @@ -35,7 +35,8 @@ class QString; QString split_text(QString text, bool cut); QString cut_helptext(QString text); -void option_dialog_popup(QString name, const struct option_set *poptset); +void option_dialog_popup(QString name, const struct option_set *poptset, + bool client); /**************************************************************************** Dialog for client/server options @@ -43,15 +44,15 @@ void option_dialog_popup(QString name, const struct option_set *poptset); class option_dialog : public qfc_dialog { Q_OBJECT - QVBoxLayout * main_layout; + QVBoxLayout *main_layout; QTabWidget *tab_widget; QDialogButtonBox *button_box; QList categories; QMap widget_map; public: - option_dialog(const QString &name, const option_set *options, - QWidget *parent = 0); + option_dialog(const QString &name, const option_set *options, bool client_set, + QWidget *parent = nullptr); ~option_dialog(); void fill(const struct option_set *poptset); void add_option(struct option *poption); @@ -59,7 +60,9 @@ public: void option_dialog_reset(struct option *poption); void full_refresh(); void apply_options(); + private: + bool client_settings; // As opposed to server ones const option_set *curr_options; void set_bool(struct option *poption, bool value); void set_int(struct option *poption, int value); @@ -78,6 +81,12 @@ private: struct option* get_color_option(); unsigned get_bitwise(struct option *poption); void full_reset(); + +protected: + void showEvent(QShowEvent *event); + void hideEvent(QHideEvent *event); + void closeEvent(QCloseEvent *event); + private slots: void apply_option(int response); void set_color(); -- 2.35.1