Author: mir3x
Date: Thu Sep  1 18:36:29 2016
New Revision: 33737

URL: http://svn.gna.org/viewcvs/freeciv?rev=33737&view=rev
Log:
Qt client - Use font_updater wherever possible.
Patch by Louis Moureaux <louis94>

See patch #7661


Modified:
    trunk/client/gui-qt/chatline.cpp
    trunk/client/gui-qt/chatline.h
    trunk/client/gui-qt/citydlg.cpp
    trunk/client/gui-qt/citydlg.h
    trunk/client/gui-qt/fc_client.cpp
    trunk/client/gui-qt/gui_main.cpp
    trunk/client/gui-qt/helpdlg.cpp
    trunk/client/gui-qt/helpdlg.h
    trunk/client/gui-qt/pages.cpp

Modified: trunk/client/gui-qt/chatline.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/chatline.cpp?rev=33737&r1=33736&r2=33737&view=diff
==============================================================================
--- trunk/client/gui-qt/chatline.cpp    (original)
+++ trunk/client/gui-qt/chatline.cpp    Thu Sep  1 18:36:29 2016
@@ -303,6 +303,7 @@
   chat_line->installEventFilter(this);
   chat_output->setVisible(true);
   chat_output->setAcceptRichText(true);
+  new font_updater(chat_output, fonts::chatline);
   chat_output->setOpenLinks(false);
   chat_output->setReadOnly(true);
   connect(chat_output, SIGNAL(anchorClicked(const QUrl)),
@@ -461,17 +462,6 @@
   return QObject::eventFilter(obj, event);
 }
 
-
-/***************************************************************************
-  Updates font for chatwdg
-***************************************************************************/
-void chatwdg::update_font()
-{
-  QFont *qf;
-  qf = gui()->fc_fonts.get_font("gui_qt_font_chatline");
-  chat_output->setFont(*qf);
-}
-
 /***************************************************************************
   Hides allies and links button for local game
 ***************************************************************************/
@@ -492,7 +482,7 @@
 int chatwdg::default_size(int lines)
 {
   int size;
-  QFontMetrics fm(*gui()->fc_fonts.get_font("gui_qt_font_chatline"));
+  QFontMetrics fm(chat_output->font());
   size = 2 * chat_output->frameWidth() + lines * fm.lineSpacing()
          + chat_line->size().height() + 4;
 

Modified: trunk/client/gui-qt/chatline.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/chatline.h?rev=33737&r1=33736&r2=33737&view=diff
==============================================================================
--- trunk/client/gui-qt/chatline.h      (original)
+++ trunk/client/gui-qt/chatline.h      Thu Sep  1 18:36:29 2016
@@ -22,6 +22,8 @@
 #include "chatline_g.h"
 }
 
+// gui-qt
+#include "fonts.h"
 #include "listener.h"
 
 //Qt
@@ -100,7 +102,6 @@
   void append(const QString &str);
   chat_input *chat_line;
   void make_link(struct tile *ptile);
-  void update_font();
   void update_widgets();
   int default_size(int lines);
   void scroll_to_bottom();

Modified: trunk/client/gui-qt/citydlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/citydlg.cpp?rev=33737&r1=33736&r2=33737&view=diff
==============================================================================
--- trunk/client/gui-qt/citydlg.cpp     (original)
+++ trunk/client/gui-qt/citydlg.cpp     Thu Sep  1 18:36:29 2016
@@ -741,7 +741,6 @@
                                     QSizePolicy::Expanding);
   QSizePolicy size_fixed_policy(QSizePolicy::Fixed, QSizePolicy::Fixed);
   QStringList info_list;
-  QFont *small_font;
   QFont f = QApplication::font();
   QFontMetrics fm(f);
   int info_nr;
@@ -750,7 +749,6 @@
   QLabel *ql;
   QLabel *lab2;
   int h = 2 * fm.height() + 2;
-  small_font = gui()->fc_fonts.get_font("gui_qt_font_city_label");
   QString city_stl = "QPushButton{font-weight: bold italic; border: "
                      "0px;text-align: right;}"
                      "QPushButton:hover "
@@ -799,16 +797,16 @@
     QHBoxLayout *v_layout = new QHBoxLayout;
     QGroupBox *prod_box = new QGroupBox(this);
     QGridLayout *prod_layout = new QGridLayout;
-
-    info_widget = new QWidget(overview_tab); /** City information widget
-                                        * texts about surpluses and so on */
+    // City information widget texts about surpluses and so on
+    QWidget *info_widget = new QWidget(overview_tab);
+
     info_grid_layout = new QGridLayout(parent);
     info_list << _("Food:") << _("Prod:") << _("Trade:") << _("Gold:")
               << _("Luxury:") << _("Science:") << _("Granary:")
               << _("Change in:") << _("Corruption:") << _("Waste:")
               << _("Culture:") << _("Pollution:") << _("Plague Risk:");
     info_nr = info_list.count();
-    info_widget->setFont(*small_font);
+    new font_updater(info_widget, fonts::city_label);
     info_grid_layout->setSpacing(0);
     for (iter = 0; iter < info_nr; iter++) {
       ql = new QLabel(info_list[iter], info_widget);
@@ -1067,7 +1065,7 @@
       lab_table[i] = new city_label(1 + i, this);
       gridl->addWidget(lab_table[i], i, 1, 1, 1);
       lab2 = new QLabel(this);
-      lab2->setFont(*small_font);
+      new font_updater(lab2, fonts::city_label);
       lab2->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
       lab2->setText(info_list.at(i));
       gridl->addWidget(lab2, i, 0, 1, 1);
@@ -1103,7 +1101,7 @@
     connect(qpush2, SIGNAL(pressed()), SLOT(save_cma()));
 
     cma_info_text = new QLabel;
-    cma_info_text->setFont(*small_font);
+    new font_updater(cma_info_text, fonts::city_label);
     cma_info_text->setAlignment(Qt::AlignCenter);
     cma_table = new QTableWidget;
     cma_table->setColumnCount(1);

Modified: trunk/client/gui-qt/citydlg.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/citydlg.h?rev=33737&r1=33736&r2=33737&view=diff
==============================================================================
--- trunk/client/gui-qt/citydlg.h       (original)
+++ trunk/client/gui-qt/citydlg.h       Thu Sep  1 18:36:29 2016
@@ -41,6 +41,9 @@
 
 // client
 #include "canvas.h"
+
+// gui-qt
+#include "fonts.h"
 
 // Qt
 #include <QProgressBar>
@@ -380,7 +383,6 @@
   ~city_dialog();
   void setup_ui(struct city *qcity);
   void refresh();
-  void update_font();
   struct city *pcity;
 
 private:

Modified: trunk/client/gui-qt/fc_client.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/fc_client.cpp?rev=33737&r1=33736&r2=33737&view=diff
==============================================================================
--- trunk/client/gui-qt/fc_client.cpp   (original)
+++ trunk/client/gui-qt/fc_client.cpp   Thu Sep  1 18:36:29 2016
@@ -321,7 +321,6 @@
     showMaximized();
     gui()->infotab->chtwdg->update_widgets();
     status_bar->setVisible(false);
-    gui()->infotab->chtwdg->update_font();
     if (gui_options.gui_qt_fullscreen){
       gui()->showFullScreen();
       gui()->mapview_wdg->showFullScreen();

Modified: trunk/client/gui-qt/gui_main.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/gui_main.cpp?rev=33737&r1=33736&r2=33737&view=diff
==============================================================================
--- trunk/client/gui-qt/gui_main.cpp    (original)
+++ trunk/client/gui-qt/gui_main.cpp    Thu Sep  1 18:36:29 2016
@@ -73,8 +73,6 @@
 static void populate_unit_pixmap_table(void);
 static void apply_font(struct option *poption);
 static void apply_titlebar(struct option *poption);
-static void apply_city_font(struct option *poption);
-static void apply_help_font(struct option *poption);
 static void apply_sidebar(struct option *poption);
 
 /****************************************************************************
@@ -209,7 +207,6 @@
   } else {                                                                  \
     log_error("Didn't find option %s!", #var);                              \
   }
-
   option_var_set_callback(gui_qt_font_city_names,
                           apply_font);
   option_var_set_callback(gui_qt_font_default,
@@ -219,13 +216,13 @@
   option_var_set_callback(gui_qt_font_reqtree_text,
                           apply_font);
   option_var_set_callback(gui_qt_font_city_label,
-                          apply_city_font);
+                          apply_font);
   option_var_set_callback(gui_qt_font_help_label,
-                          apply_help_font);
+                          apply_font);
   option_var_set_callback(gui_qt_font_help_text,
-                          apply_help_font);
+                          apply_font);
   option_var_set_callback(gui_qt_font_help_title,
-                          apply_help_font);
+                          apply_font);
   option_var_set_callback(gui_qt_font_chatline,
                           apply_font);
   option_var_set_callback(gui_qt_show_titlebar,
@@ -360,8 +357,6 @@
     remove_old = gui()->fc_fonts.get_font(s);
     delete remove_old;
     gui()->fc_fonts.set_font(s, f);
-    update_city_descriptions();
-    gui()->infotab->chtwdg->update_font();
   }
 }
 
@@ -395,34 +390,12 @@
 }
 
 /****************************************************************************
-  Change the manual font
-****************************************************************************/
-static void apply_help_font(struct option *poption)
-{
-  QFont *f;
-  QFont *remove_old;
-  QString s;
-
-  if (gui()) {
-    f = new QFont;
-    s = option_font_get(poption);
-    f->fromString(s);
-    s = option_name(poption);
-    remove_old = gui()->fc_fonts.get_font(s);
-    delete remove_old;
-    gui()->fc_fonts.set_font(s, f);
-    update_help_fonts();
-  }
-}
-
-/****************************************************************************
   Change sidebar position
 ****************************************************************************/
 void apply_sidebar(struct option *poption)
 {
   gui()->update_sidebar_position();
 }
-
 
 /****************************************************************************
   Stub for editor function
@@ -514,27 +487,6 @@
   }
 }
 
-/****************************************************************************
-  Changes city label font
-****************************************************************************/
-void apply_city_font(option *poption)
-{
-  QFont *f;
-  QFont *remove_old;
-  QString s;
-
-  if (gui() && qtg_get_current_client_page() == PAGE_GAME) {
-    f = new QFont;
-    s = option_font_get(poption);
-    f->fromString(s);
-    s = option_name(poption);
-    remove_old = gui()->fc_fonts.get_font(s);
-    delete remove_old;
-    gui()->fc_fonts.set_font(s, f);
-    qtg_popdown_all_city_dialogs();
-  }
-}
-
 /**************************************************************************
   Called to build the unit_below pixmap table.  This is the table on the
   left of the screen that shows all of the inactive units in the current

Modified: trunk/client/gui-qt/helpdlg.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/helpdlg.cpp?rev=33737&r1=33736&r2=33737&view=diff
==============================================================================
--- trunk/client/gui-qt/helpdlg.cpp     (original)
+++ trunk/client/gui-qt/helpdlg.cpp     Thu Sep  1 18:36:29 2016
@@ -40,6 +40,7 @@
 
 // gui-qt
 #include "qtg_cxxside.h"
+#include "fonts.h"
 #include "helpdlg.h"
 #include "sprite.h"
 
@@ -104,16 +105,6 @@
     help_dlg->setVisible(false);
     help_dlg->deleteLater();
     help_dlg = NULL;
-  }
-}
-
-/**************************************************************************
-  Updates fonts
-**************************************************************************/
-void update_help_fonts()
-{
-  if (help_dlg) {
-    help_dlg->update_fonts();
   }
 }
 
@@ -301,18 +292,6 @@
 }
 
 /**************************************************************************
-  Update fonts for help_wdg
-**************************************************************************/
-void help_dialog::update_fonts()
-{
-  QFont *def_font;
-
-  def_font = gui()->fc_fonts.get_font("gui_qt_font_default");
-  tree_wdg->setFont(*def_font);
-  help_wdg->update_fonts();
-}
-
-/**************************************************************************
   Creates a new, empty help widget.
 **************************************************************************/
 help_widget::help_widget(QWidget *parent) :
@@ -364,34 +343,11 @@
   group_layout->addWidget(title_label);
 
   text_browser = new QTextBrowser(this);
-  text_browser->setFont(QFont(QLatin1String("mono")));
+  new font_updater(text_browser, fonts::help_text);
   layout->addWidget(text_browser);
   main_widget = text_browser;
 
   splitter_sizes << 200 << 400;
-
-  update_fonts();
-}
-
-/**************************************************************************
-  Updates fonts for manual
-**************************************************************************/
-void help_widget::update_fonts()
-{
-  QFont *help_font, *label_font, *title_font;
-  QLabel *label;
-
-  label_font = gui()->fc_fonts.get_font("gui_qt_font_help_label");
-  help_font = gui()->fc_fonts.get_font("gui_qt_font_help_text");
-  title_font = gui()->fc_fonts.get_font("gui_qt_font_help_title");
-  text_browser->setFont(*help_font);
-  title_label->setFont(*title_font);
-  foreach (label, label_list) {
-    label->setFont(*label_font);
-  }
-  foreach (label, title_list) {
-    label->setFont(*title_font);
-  }
 }
 
 /****************************************************************************
@@ -472,9 +428,6 @@
   info_panel = NULL;
   splitter = NULL;
   info_layout = NULL;
-  // Don't keep pointers to deleted labels
-  label_list.clear();
-  title_list.clear();
 }
 
 /****************************************************************************
@@ -513,9 +466,9 @@
 void help_widget::add_info_label(const QString &text)
 {
   QLabel *label = new QLabel(text);
+  new font_updater(label, fonts::help_label);
   label->setWordWrap(true);
 
-  label_list << label;
   info_layout->addWidget(label);
 }
 
@@ -541,11 +494,11 @@
   layout->setVerticalSpacing(0);
 
   label = new QLabel(text, wdg);
-  label_list << label;
+  new font_updater(label, fonts::help_label);
   layout->addWidget(label, 0, 0);
 
   label = new QLabel(wdg);
-  label_list << label;
+  new font_updater(label, fonts::help_label);
   if (value.isEmpty()) {
     label->setNum(progress);
   } else {
@@ -588,6 +541,7 @@
       QLabel *tb;
       QString str;
       tb = new QLabel(this);
+      new font_updater(tb, fonts::help_label);
       tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
       tb->setTextFormat(Qt::RichText);
 
@@ -598,7 +552,6 @@
             + link_me(extra_name_translation(pextra), HELP_EXTRA)
             + QString(buffer) + "\n";
             tb->setText(str.trimmed());
-            tb->setFont(*gui()->fc_fonts.get_font("gui_qt_font_help_label"));
             connect(tb, SIGNAL(linkActivated(const QString)),
                     this, SLOT(anchor_clicked(const QString)));
             info_layout->addWidget(tb);
@@ -711,7 +664,6 @@
   }
 
   do_layout();
-  update_fonts();
 }
 
 /****************************************************************************
@@ -932,7 +884,7 @@
             str = "<b>" + str + "</b> "
                + link_me(government_name_translation(pgov), HELP_GOVERNMENT);
             tb->setText(str.trimmed());
-            tb->setFont(*gui()->fc_fonts.get_font("gui_qt_font_help_label"));
+            new font_updater(tb, fonts::help_label);
             connect(tb, SIGNAL(linkActivated(const QString)),
                     this, SLOT(anchor_clicked(const QString)));
             info_layout->addWidget(tb);
@@ -953,7 +905,7 @@
             tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
             tb->setTextFormat(Qt::RichText);
             tb->setText(str.trimmed());
-            tb->setFont(*gui()->fc_fonts.get_font("gui_qt_font_help_label"));
+            new font_updater(tb, fonts::help_label);
             connect(tb, SIGNAL(linkActivated(const QString)),
                     this, SLOT(anchor_clicked(const QString)));
             info_layout->addWidget(tb);
@@ -972,7 +924,7 @@
             tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
             tb->setTextFormat(Qt::RichText);
             tb->setText(str.trimmed());
-            tb->setFont(*gui()->fc_fonts.get_font("gui_qt_font_help_label"));
+            new font_updater(tb, fonts::help_label);
             connect(tb, SIGNAL(linkActivated(const QString)),
                     this, SLOT(anchor_clicked(const QString)));
             info_layout->addWidget(tb);
@@ -991,7 +943,7 @@
         tb->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
         tb->setTextFormat(Qt::RichText);
         tb->setText(str.trimmed());
-        tb->setFont(*gui()->fc_fonts.get_font("gui_qt_font_help_label"));
+            new font_updater(tb, fonts::help_label);
         connect(tb, SIGNAL(linkActivated(const QString)),
                 this, SLOT(anchor_clicked(const QString)));
         info_layout->addWidget(tb);
@@ -1074,11 +1026,11 @@
   layout->addWidget(label, 0, 0, 2, 1);
 
   label = new QLabel(title);
-  title_list << label;
+  new font_updater(label, fonts::help_title);
   layout->addWidget(label, 0, 1, Qt::AlignBottom);
 
   label = new QLabel(legend);
-  label_list << label;
+  new font_updater(label, fonts::help_label);
   layout->addWidget(label, 1, 1, Qt::AlignTop);
 
   if (!tooltip.isEmpty()) {

Modified: trunk/client/gui-qt/helpdlg.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/helpdlg.h?rev=33737&r1=33736&r2=33737&view=diff
==============================================================================
--- trunk/client/gui-qt/helpdlg.h       (original)
+++ trunk/client/gui-qt/helpdlg.h       Thu Sep  1 18:36:29 2016
@@ -50,7 +50,6 @@
   void make_tree();
 public:
   help_dialog(QWidget *parent = 0);
-  void update_fonts();
 
 public slots:
   void set_topic(const help_item *item);
@@ -64,8 +63,6 @@
   Q_OBJECT
   QFrame *box_wdg;
   QLabel *title_label;
-  QList<QLabel *> label_list;
-  QList<QLabel *> title_list;
 
   QWidget *main_widget;
   QTextBrowser *text_browser;
@@ -117,9 +114,9 @@
   help_widget(QWidget *parent = 0);
   help_widget(const help_item *item, QWidget *parent = 0);
   ~help_widget();
-  void update_fonts();
 private:
   QString link_me(const char *str, help_page_type hpt);
+
 public slots:
   void set_topic(const help_item *item);
 private slots:
@@ -130,5 +127,4 @@
   struct unit_type *uclass_max_values(struct unit_class *uclass);
 };
 
-void update_help_fonts();
 #endif /* FC__HELPDLG_H */

Modified: trunk/client/gui-qt/pages.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/pages.cpp?rev=33737&r1=33736&r2=33737&view=diff
==============================================================================
--- trunk/client/gui-qt/pages.cpp       (original)
+++ trunk/client/gui-qt/pages.cpp       Thu Sep  1 18:36:29 2016
@@ -133,10 +133,9 @@
   QFontMetrics fm(f);
   int row = 0;
 #if IS_BETA_VERSION
-  QFont *fe = fc_fonts.get_font("gui_qt_font_beta_label");
   QPalette warn_color;
   QLabel *beta_label = new QLabel(beta_message());
-  beta_label->setFont(*fe);
+  new font_updater(beta_label, fonts::beta_label);
 #endif /* IS_BETA_VERSION */
 
   pages_layout[PAGE_MAIN] = new QGridLayout;


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to