From 32498275bab9b9ebc2c317e2cce898d5abfac656 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 15 Jul 2022 02:40:29 +0300 Subject: [PATCH 27/27] Qt: Refresh sidebar fonts when the settings change Reported by ddeanbrown See osdn #44907 Signed-off-by: Marko Lindqvist --- client/gui-qt/fc_client.cpp | 10 ++++++- client/gui-qt/fc_client.h | 3 +- client/gui-qt/gui_main.cpp | 3 ++ client/gui-qt/sidebar.cpp | 55 +++++++++++++++++++++++++++++-------- client/gui-qt/sidebar.h | 2 ++ 5 files changed, 60 insertions(+), 13 deletions(-) diff --git a/client/gui-qt/fc_client.cpp b/client/gui-qt/fc_client.cpp index 6864e0fdbf..ad823e463b 100644 --- a/client/gui-qt/fc_client.cpp +++ b/client/gui-qt/fc_client.cpp @@ -424,6 +424,14 @@ void fc_client::add_server_source(int sock) &fc_client::server_input); } +/************************************************************************//** + Refresh fonts +****************************************************************************/ +void fc_client::update_fonts() +{ + sidebar_wdg->update_fonts(); +} + /************************************************************************//** Event handler ****************************************************************************/ @@ -1110,7 +1118,7 @@ void fc_game_tab_widget::current_changed(int index) /* Set focus to map instead sidebar */ if (gui()->mapview_wdg && gui()->current_page() == PAGE_GAME - && index == 0) { + && index == 0) { gui()->mapview_wdg->setFocus(); } diff --git a/client/gui-qt/fc_client.h b/client/gui-qt/fc_client.h index 52269da730..a6bb08fe92 100644 --- a/client/gui-qt/fc_client.h +++ b/client/gui-qt/fc_client.h @@ -226,7 +226,7 @@ public: fc_client(); ~fc_client(); - void fc_main(QApplication *); + void fc_main(QApplication *qapp); map_view *mapview_wdg; fc_sidebar *sidebar_wdg; minimap_view *minimapview_wdg; @@ -285,6 +285,7 @@ public: bool is_closing(); void update_sidebar_tooltips(); void reload_sidebar_icons(); + void update_fonts(); private slots: void send_fake_chat_message(const QString &message); diff --git a/client/gui-qt/gui_main.cpp b/client/gui-qt/gui_main.cpp index 38ea68f233..02291289b8 100644 --- a/client/gui-qt/gui_main.cpp +++ b/client/gui-qt/gui_main.cpp @@ -403,6 +403,7 @@ static void apply_font(struct option *poption) QString s; if (gui()) { + // FIXME: All this should be within gui()->update_fonts() f = new QFont; s = option_font_get(poption); f->fromString(s); @@ -415,7 +416,9 @@ static void apply_font(struct option *poption) QApplication::setFont(*fc_font::instance()->get_font(fonts::default_font)); real_science_report_dialog_update(nullptr); fc_font::instance()->get_mapfont_size(); + gui()->update_fonts(); } + apply_help_font(poption); } diff --git a/client/gui-qt/sidebar.cpp b/client/gui-qt/sidebar.cpp index 0148d4ed27..a751a61c55 100644 --- a/client/gui-qt/sidebar.cpp +++ b/client/gui-qt/sidebar.cpp @@ -66,12 +66,17 @@ fc_sidewidget::fc_sidewidget(QPixmap *pix, QString label, QString pg, pix = new QPixmap(12,12); pix->fill(Qt::black); } + blink = false; disabled = false; def_pixmap = pix; scaled_pixmap = new QPixmap; final_pixmap = new QPixmap; - sfont = new QFont(*fc_font::instance()->get_font(fonts::notify_label)); + + sfont = nullptr; + info_font = nullptr; + update_fonts(); + left_click = func; desc = label; standard = type; @@ -84,11 +89,7 @@ fc_sidewidget::fc_sidewidget(QPixmap *pix, QString label, QString pg, timer = new QTimer; timer->setSingleShot(false); timer->setInterval(700); - sfont->setCapitalization(QFont::SmallCaps); - sfont->setItalic(true); - info_font = new QFont(*sfont); - info_font->setBold(true); - info_font->setItalic(false); + connect(timer, &QTimer::timeout, this, &fc_sidewidget::sblink); } @@ -125,6 +126,26 @@ void fc_sidewidget::set_pixmap(QPixmap *pm) def_pixmap = pm; } +/***********************************************************************//** + Update sidebar fonts +***************************************************************************/ +void fc_sidewidget::update_fonts() +{ + if (sfont != nullptr) { + delete sfont; + } + sfont = new QFont(*fc_font::instance()->get_font(fonts::notify_label)); + sfont->setCapitalization(QFont::SmallCaps); + sfont->setItalic(true); + + if (info_font != nullptr) { + delete info_font; + } + info_font = new QFont(*sfont); + info_font->setBold(true); + info_font->setItalic(false); +} + /***********************************************************************//** Sets custom text visible on top of sidewidget ***************************************************************************/ @@ -398,8 +419,9 @@ void fc_sidewidget::update_final_pixmap() p.setPen(pen); if (standard == SW_TAX && !client_is_global_observer()) { - pos = 0; int d, modulo; + + pos = 0; sprite = get_tax_sprite(tileset, O_GOLD); if (sprite == nullptr) { return; @@ -561,8 +583,8 @@ void fc_sidebar::resize_me(int hght, bool force) non_std = 0; non_std_count = 0; - /* resize all non standard sidewidgets first*/ - foreach (fc_sidewidget * sw, objects) { + // Resize all non standard sidewidgets first + foreach (fc_sidewidget *sw, objects) { if (sw->standard != SW_STD) { sw->resize_pixmap(w, 0); sw->setFixedSize(w, sw->get_pixmap()->height()); @@ -574,8 +596,8 @@ void fc_sidebar::resize_me(int hght, bool force) h = h - non_std; h = h / (objects.count() - non_std_count) - 2; - /* resize all standard sidewidgets */ - foreach (fc_sidewidget * sw, objects) { + // Resize all standard sidewidgets + foreach (fc_sidewidget *sw, objects) { if (sw->standard == SW_STD) { sw->resize_pixmap(w, h); sw->setFixedSize(w, h); @@ -585,6 +607,17 @@ void fc_sidebar::resize_me(int hght, bool force) } +/***********************************************************************//** + Refresh fonts for all the sidebar widgets. +***************************************************************************/ +void fc_sidebar::update_fonts() +{ + foreach (fc_sidewidget *sw, objects) { + sw->update_fonts(); + sw->update_final_pixmap(); + } +} + /***********************************************************************//** Callback to show map ***************************************************************************/ diff --git a/client/gui-qt/sidebar.h b/client/gui-qt/sidebar.h index acb275bc3f..0c30893223 100644 --- a/client/gui-qt/sidebar.h +++ b/client/gui-qt/sidebar.h @@ -64,6 +64,7 @@ public: void set_wheel_down(pfcn func); void set_wheel_up(pfcn func); void update_final_pixmap(); + void update_fonts(); bool blink; bool keep_blinking; @@ -114,6 +115,7 @@ public: void add_widget(fc_sidewidget *fsw); void paint(QPainter *painter, QPaintEvent *event); void resize_me(int height, bool force = false); + void update_fonts(); QList objects; protected: void paintEvent(QPaintEvent *event); -- 2.35.1