From 947cbe438a072473d2c6a033158fcc426e2ff38c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Fri, 24 May 2024 17:42:10 +0200 Subject: [PATCH] =?UTF-8?q?!OSDN:#117692:S=C5=82awomir=20Lach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User can switch from/onto counters tab in city dialog (Qt5) diff --git a/client/gui-qt/citydlg.cpp b/client/gui-qt/citydlg.cpp index 8eb04d2b89..0e5deeb491 100644 --- a/client/gui-qt/citydlg.cpp +++ b/client/gui-qt/citydlg.cpp @@ -1503,10 +1503,10 @@ city_dialog::city_dialog(QWidget *parent): qfc_dialog(parent) int list_size; int h = 2 * fm.height() + 2; + current_tab = common; small_font = fc_font::instance()->get_font(fonts::notify_label); zoom = 1.0; - happiness_shown = false; central_splitter = new QSplitter; central_splitter->setOpaqueResize(false); central_left_splitter = new QSplitter; @@ -1701,7 +1701,6 @@ city_dialog::city_dialog(QWidget *parent): qfc_dialog(parent) happiness_button->setIcon(fc_icons::instance()->get_icon("city-switch")); happiness_button->setIconSize(QSize(56, 28)); connect(happiness_button, &QAbstractButton::clicked, this, &city_dialog::show_happiness); - update_happiness_button(); button->setFixedSize(64, 64); prev_city_but->setFixedSize(64, 64); @@ -1712,6 +1711,12 @@ city_dialog::city_dialog(QWidget *parent): qfc_dialog(parent) vbox_layout->addWidget(next_city_but); vbox_layout->addWidget(button); vbox_layout->addWidget(happiness_button, Qt::AlignHCenter); + + counterss_button = new QPushButton(); + connect(counterss_button, &QAbstractButton::clicked, this, &city_dialog::show_counters); + vbox_layout->addWidget(counterss_button, Qt::AlignHCenter); + + update_tabs(); hbox_layout = new QHBoxLayout; hbox_layout->addLayout(vbox_layout, Qt::AlignLeft); @@ -1868,6 +1873,10 @@ city_dialog::city_dialog(QWidget *parent): qfc_dialog(parent) gridl = new QGridLayout; slider_grid = new QGridLayout; + counterss_layout = new QHBoxLayout(); + counterss_widget = new QWidget(); + counterss_widget->setLayout(counterss_layout); + qpush2 = new QPushButton(style()->standardIcon(QStyle::SP_DialogSaveButton), _("Save")); @@ -2077,12 +2086,19 @@ void city_dialog::change_production(bool next) /************************************************************************//** Sets tooltip for happiness/pruction button switcher ****************************************************************************/ -void city_dialog::update_happiness_button() +void city_dialog::update_tabs() { - if (happiness_shown) { + if (current_tab == happiness) { happiness_button->setToolTip(_("Show city production")); } else { happiness_button->setToolTip(_("Show happiness information")); + + if (current_tab == counters) { + counterss_button->setToolTip(_("Show city production")); + } + else { + counterss_button->setToolTip(_("Show counters information")); + } } } @@ -2091,28 +2107,69 @@ void city_dialog::update_happiness_button() ****************************************************************************/ void city_dialog::show_happiness() { + QWidget *active_tab = current_tab == counters ? counterss_widget : prod_unit_splitter; setUpdatesEnabled(false); - if (!happiness_shown) { - leftbot_layout->replaceWidget(prod_unit_splitter, + + if (current_tab != happiness) { + leftbot_layout->replaceWidget(active_tab, happiness_widget, Qt::FindDirectChildrenOnly); - prod_unit_splitter->hide(); + active_tab->hide(); happiness_widget->show(); happiness_widget->updateGeometry(); + current_tab = happiness; } else { + /* We do not change prod_unit_splitter to current_tab, + * because happiness is active tab and clicked - + * switching to default */ leftbot_layout->replaceWidget(happiness_widget, prod_unit_splitter, Qt::FindDirectChildrenOnly); prod_unit_splitter->show(); prod_unit_splitter->updateGeometry(); happiness_widget->hide(); + current_tab = common; } setUpdatesEnabled(true); update(); - happiness_shown = !happiness_shown; - update_happiness_button(); + update_tabs(); +} + +/************************************************************************//** + Shows counters tab +****************************************************************************/ +void city_dialog::show_counters() +{ + QWidget *active_tab = current_tab == happiness ? happiness_widget : prod_unit_splitter; + setUpdatesEnabled(false); + + + if (current_tab != counters) { + leftbot_layout->replaceWidget(active_tab, + counterss_widget, + Qt::FindDirectChildrenOnly); + active_tab->hide(); + counterss_widget->show(); + counterss_widget->updateGeometry(); + current_tab = counters; + } else { + /* We do not change prod_unit_splitter to current_tab, + * because counters is active tab and clicked - + * switching to default */ + leftbot_layout->replaceWidget(counterss_widget, + prod_unit_splitter, + Qt::FindDirectChildrenOnly); + prod_unit_splitter->show(); + prod_unit_splitter->updateGeometry(); + counterss_widget->hide(); + current_tab = common; + } + + setUpdatesEnabled(true); + update(); + update_tabs(); } /************************************************************************//** @@ -2201,10 +2258,16 @@ city_dialog::~city_dialog() ::city_dlg_created = false; // Delete the one widget that currently does NOT have a parent - if (happiness_shown) { - delete prod_unit_splitter; - } else { + if (current_tab == common) { delete happiness_widget; + delete counterss_widget; + } + else if (current_tab == counters) { + delete happiness_widget; + delete prod_unit_splitter; + }else { + delete counterss_widget; + delete prod_unit_splitter; } } diff --git a/client/gui-qt/citydlg.h b/client/gui-qt/citydlg.h index 158e996392..137ce78289 100644 --- a/client/gui-qt/citydlg.h +++ b/client/gui-qt/citydlg.h @@ -437,9 +437,13 @@ class city_dialog: public qfc_dialog { Q_OBJECT - bool happiness_shown; + enum city_dialog_tab { common, + happiness, counters } + current_tab; + QHBoxLayout *single_page_layout; QHBoxLayout *happiness_layout; + QHBoxLayout *counterss_layout; QSplitter *prod_unit_splitter; QSplitter *central_left_splitter; QSplitter *central_splitter; @@ -454,6 +458,7 @@ class city_dialog: public qfc_dialog QGroupBox *info_labels_group; QGroupBox *happiness_group; QWidget *happiness_widget; + QWidget *counterss_widget; QWidget *info_widget; QLabel *qlt[NUM_INFO_FIELDS]; QLabel *cma_info_text; @@ -483,6 +488,7 @@ class city_dialog: public qfc_dialog QPushButton *work_add_but; QPushButton *work_rem_but; QPushButton *happiness_button; + QPushButton *counterss_button; QPushButton *zoom_in_button; QPushButton *zoom_out_button; QPixmap *citizen_pixmap; @@ -516,7 +522,7 @@ private: void update_disabled(); void update_sliders(); void update_prod_buttons(); - void update_happiness_button(); + void update_tabs(); void change_production(bool next); private slots: @@ -526,6 +532,7 @@ private slots: void show_targets(); void show_targets_worklist(); void show_happiness(); + void show_counters(); void buy(); void dbl_click_p(QTableWidgetItem *item); void item_selected(const QItemSelection &sl, const QItemSelection &ds); -- 2.45.1