From 28d2c824f1727527975b5d4b05f72447ecc11498 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 15 Jul 2022 02:36:34 +0300 Subject: [PATCH 43/43] 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 | 51 ++++++++++++++++++++++++++++++------- client/gui-qt/sidebar.h | 2 ++ 5 files changed, 58 insertions(+), 11 deletions(-) diff --git a/client/gui-qt/fc_client.cpp b/client/gui-qt/fc_client.cpp index d1365df51b..851e7b0698 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 f7afb4f69f..6798d1e82c 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 4aa5e01d00..55a98e38fe 100644 --- a/client/gui-qt/gui_main.cpp +++ b/client/gui-qt/gui_main.cpp @@ -412,6 +412,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); @@ -424,7 +425,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 5596df09d9..26ea82d6a3 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; @@ -562,7 +584,7 @@ void fc_sidebar::resize_me(int hght, bool force) non_std_count = 0; // Resize all non standard sidewidgets first - foreach (fc_sidewidget * sw, objects) { + foreach (fc_sidewidget *sw, objects) { if (sw->standard != SW_STD) { sw->resize_pixmap(w, 0); sw->setFixedSize(w, sw->get_pixmap()->height()); @@ -575,7 +597,7 @@ 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) { + foreach (fc_sidewidget *sw, objects) { if (sw->standard == SW_STD) { sw->resize_pixmap(w, h); sw->setFixedSize(w, h); @@ -584,6 +606,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 a2c9ee4562..a23be40a9c 100644 --- a/client/gui-qt/sidebar.h +++ b/client/gui-qt/sidebar.h @@ -65,6 +65,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; @@ -115,6 +116,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