Author: mir3x
Date: Thu Sep  1 18:37:53 2016
New Revision: 33738

URL: http://svn.gna.org/viewcvs/freeciv?rev=33738&view=rev
Log:
Qt client - Use new font system in self-drawing classes
Patch by Louis Moureaux <louis94>

See patch #7662


Modified:
    branches/S2_6/client/gui-qt/dialogs.cpp
    branches/S2_6/client/gui-qt/dialogs.h
    branches/S2_6/client/gui-qt/fc_client.cpp
    branches/S2_6/client/gui-qt/fc_client.h
    branches/S2_6/client/gui-qt/gui_main.cpp
    branches/S2_6/client/gui-qt/mapview.cpp
    branches/S2_6/client/gui-qt/mapview.h

Modified: branches/S2_6/client/gui-qt/dialogs.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/dialogs.cpp?rev=33738&r1=33737&r2=33738&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/dialogs.cpp     (original)
+++ branches/S2_6/client/gui-qt/dialogs.cpp     Thu Sep  1 18:37:53 2016
@@ -605,7 +605,7 @@
   qheadline = QString(headline);
   qlines = QString(lines);
   qlist = qlines.split("\n");
-  small_font =::gui()->fc_fonts.get_font("gui_qt_font_notify_label");
+  small_font = get_font(fonts::notify_label);
   x = 0;
   y = 0;
   calc_size(x, y);
@@ -614,6 +614,8 @@
                                  x, y, x, y, 0);
   move(x, y);
   was_destroyed = false;
+
+  font_options_listener::listen();
 }
 
 /***************************************************************************
@@ -621,7 +623,7 @@
 ***************************************************************************/
 void notify_dialog::calc_size(int &x, int &y)
 {
-  QFontMetrics fm(*small_font);
+  QFontMetrics fm(small_font);
   int i;
   QStringList str_list;
 
@@ -636,6 +638,15 @@
 }
 
 /***************************************************************************
+  Change the fonts when needed
+***************************************************************************/
+void notify_dialog::update_font(const QString &name, const QFont &font)
+{
+  // FIXME Updating fonts isn't practical because the size of the widget
+  // will change -> its position too.
+}
+
+/***************************************************************************
   Paint Event for notify dialog
 ***************************************************************************/
 void notify_dialog::paintEvent(QPaintEvent * paint_event)
@@ -643,14 +654,14 @@
   QPainter painter(this);
   QPainterPath path;
   QPen pen;
-  QFontMetrics fm(*small_font);
+  QFontMetrics fm(small_font);
   int i;
 
   pen.setWidth(1);
   pen.setColor(QColor(232, 255, 0));
   painter.setBrush(QColor(0, 0, 0, 175));
   painter.drawRect(0, 0, width(), height());
-  painter.setFont(*small_font);
+  painter.setFont(small_font);
   painter.setPen(pen);
   painter.drawText(10, fm.height() + 3, qcaption);
   painter.drawText(10, 2 * fm.height() + 6, qheadline);
@@ -2385,9 +2396,8 @@
   pix = NULL;
   show_line = 0;
   highligh_num = -1;
-  ufont = new QFont;
-  ufont->setItalic(true);
-  info_font = gui()->fc_fonts.get_font("gui_qt_font_notify_label");
+  ufont.setItalic(true);
+  info_font = get_font(fonts::notify_label);
   update_units();
   h_pix = NULL;
   create_pixmap();
@@ -2404,6 +2414,8 @@
   }
   move(final_p.x(), final_p.y() - height());
   setFocus();
+
+  font_options_listener::listen();
 }
 /****************************************************************
   Destructor for unit select
@@ -2412,7 +2424,6 @@
 {
     delete h_pix;
     delete pix;
-    delete ufont;
     delete cw;
 }
 
@@ -2431,7 +2442,7 @@
   int rate, f;
   int a;
   QPen pen;
-  QFontMetrics fm(*info_font);
+  QFontMetrics fm(info_font);
 
   if (pix != NULL) {
     delete pix;
@@ -2473,8 +2484,8 @@
   a = qMin(item_size.width() / 4, 12);
   x = 0, y = -item_size.height(), i = -1;
   p.begin(pix);
-  ufont->setPixelSize(a);
-  p.setFont(*ufont);
+  ufont.setPixelSize(a);
+  p.setFont(ufont);
   pen.setColor(QColor(232, 255, 0));
   p.setPen(pen);
 
@@ -2522,7 +2533,7 @@
 {
   int a, b;
   int old_h;
-  QFontMetrics fm(*info_font);
+  QFontMetrics fm(info_font);
 
   old_h = highligh_num;
   highligh_num = -1;
@@ -2572,14 +2583,14 @@
 *****************************************************************/
 void unit_select::paint(QPainter *painter, QPaintEvent *event)
 {
-  QFontMetrics fm(*info_font);
+  QFontMetrics fm(info_font);
   int h, i;
   int *f_size;
   QPen pen;
   QString str, str2;
   struct unit *punit;
-  int point_size = info_font->pointSize();
-  int pixel_size = info_font->pixelSize();
+  int point_size = info_font.pointSize();
+  int pixel_size = info_font.pixelSize();
 
   if (point_size < 0) {
     f_size = &pixel_size;
@@ -2598,11 +2609,11 @@
                 .arg(unit_list_size(utile->units));
   for (i = *f_size; i > 4; i--) {
     if (point_size < 0) {
-      info_font->setPixelSize(i);
+      info_font.setPixelSize(i);
     } else  {
-      info_font->setPointSize(i);
-    }
-    QFontMetrics qfm(*info_font);
+      info_font.setPointSize(i);
+    }
+    QFontMetrics qfm(info_font);
     if (10 + qfm.width(str2) < width()) {
       break;
     }
@@ -2614,16 +2625,16 @@
     painter->drawPixmap(10, h + 3, *pix);
     pen.setColor(QColor(232, 255, 0));
     painter->setPen(pen);
-    painter->setFont(*info_font);
+    painter->setFont(info_font);
     painter->drawText(10, h, str);
     if (highligh_num != -1 && highligh_num < unit_list.count()) {
       painter->drawText(10, height() - 5, str2);
     }
   }
   if (point_size < 0) {
-    info_font->setPixelSize(*f_size);
+    info_font.setPixelSize(*f_size);
   } else {
-    info_font->setPointSize(*f_size);
+    info_font.setPointSize(*f_size);
   }
   cw->put_to_corner();
 }
@@ -2727,6 +2738,15 @@
 }
 
 /***************************************************************************
+  Change the fonts when needed
+***************************************************************************/
+void unit_select::update_font(const QString& name, const QFont& font)
+{
+  // FIXME Updating fonts isn't practical because the size of the widget
+  // will change -> its position too.
+}
+
+/***************************************************************************
   Set current diplo dialog
 ***************************************************************************/
 void fc_client::set_diplo_dialog(choice_dialog *widget)

Modified: branches/S2_6/client/gui-qt/dialogs.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/dialogs.h?rev=33738&r1=33737&r2=33738&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/dialogs.h       (original)
+++ branches/S2_6/client/gui-qt/dialogs.h       Thu Sep  1 18:37:53 2016
@@ -28,6 +28,7 @@
 #include <QVariant>
 
 // gui-qt
+#include "fonts.h"
 #include "mapview.h"
 
 class QComboBox;
@@ -127,7 +128,7 @@
  Widget around map view to display informations like demographics report,
  top 5 cities, traveler's report.
 ***************************************************************************/
-class notify_dialog:public fcwidget
+class notify_dialog:public fcwidget, private font_options_listener
 {
   Q_OBJECT
 public:
@@ -140,6 +141,7 @@
   void mouseMoveEvent(QMouseEvent *event);
   void mouseReleaseEvent(QMouseEvent *event);
 private:
+  void update_font(const QString &name, const QFont &font);
   void paintEvent(QPaintEvent *paint_event);
   void calc_size(int &x, int&y);
   close_widget *cw;
@@ -148,7 +150,7 @@
   QString qcaption;
   QString qheadline;
   QStringList qlist;
-  QFont *small_font;
+  QFont small_font;
   QPoint cursor;
 };
 
@@ -157,7 +159,7 @@
  TODO Add some simple scrollbars (just paint it during paint event,
  if 'more' is true->scroll visible and would depend on show_line
 ***************************************************************************/
-class unit_select: public fcwidget
+class unit_select: public fcwidget, private font_options_listener
 {
   Q_OBJECT
   QPixmap *pix;
@@ -165,8 +167,8 @@
   QSize item_size; /** size of each pixmap of unit */
   QList<unit*> unit_list; /** storing units only for drawing, for rest units
                             * iterate utile->units */
-  QFont *ufont;
-  QFont *info_font;
+  QFont ufont;
+  QFont info_font;
   int row_count;
   close_widget *cw;
 public:
@@ -185,6 +187,8 @@
   void wheelEvent(QWheelEvent *event);
   void closeEvent(QCloseEvent *event);
 private:
+  void update_font(const QString &name, const QFont &font);
+
   bool more;
   int show_line;
   int highligh_num;

Modified: branches/S2_6/client/gui-qt/fc_client.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/fc_client.cpp?rev=33738&r1=33737&r2=33738&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/fc_client.cpp   (original)
+++ branches/S2_6/client/gui-qt/fc_client.cpp   Thu Sep  1 18:37:53 2016
@@ -112,6 +112,8 @@
 ****************************************************************************/
 void fc_client::init()
 {
+  QApplication::setFont(get_font(fonts::default_font));
+
   QString path;
   central_wdg = new QWidget;
   central_layout = new QStackedLayout;
@@ -189,6 +191,7 @@
 
   game_tab_widget->init();
   chat_listener::listen();
+  font_options_listener::listen();
 }
 
 /****************************************************************************
@@ -259,6 +262,16 @@
     output_window->append(str);
     output_window->verticalScrollBar()->setSliderPosition(
                               output_window->verticalScrollBar()->maximum());
+  }
+}
+
+/****************************************************************************
+  Updates the application's default font when it changes
+****************************************************************************/
+void fc_client::update_font(const QString &name, const QFont &font)
+{
+  if (name == fonts::default_font) {
+    QApplication::setFont(font);
   }
 }
 

Modified: branches/S2_6/client/gui-qt/fc_client.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/fc_client.h?rev=33738&r1=33737&r2=33738&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/fc_client.h     (original)
+++ branches/S2_6/client/gui-qt/fc_client.h     Thu Sep  1 18:37:53 2016
@@ -45,6 +45,7 @@
 #include "canvas.h"
 #include "chatline.h"
 #include "dialogs.h"
+#include "fonts.h"
 #include "gotodlg.h"
 #include "mapview.h"
 #include "messagewin.h"
@@ -157,7 +158,9 @@
 };
 
 
-class fc_client : public QMainWindow, private chat_listener
+class fc_client : public QMainWindow,
+                  private chat_listener,
+                  private font_options_listener
 {
   Q_OBJECT
   QWidget *main_wdg;
@@ -307,6 +310,7 @@
 private:
   void chat_message_received(const QString &message,
                              const struct text_tag_list *tags);
+  void update_font(const QString &name, const QFont &font);
 
   void create_main_page();
   void create_network_page();

Modified: branches/S2_6/client/gui-qt/gui_main.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/gui_main.cpp?rev=33738&r1=33737&r2=33738&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/gui_main.cpp    (original)
+++ branches/S2_6/client/gui-qt/gui_main.cpp    Thu Sep  1 18:37:53 2016
@@ -211,6 +211,8 @@
                           apply_font);
   option_var_set_callback(gui_qt_font_default,
                           apply_font);
+  option_var_set_callback(gui_qt_font_notify_label,
+                          apply_font);
   option_var_set_callback(gui_qt_font_city_productions,
                           apply_font);
   option_var_set_callback(gui_qt_font_reqtree_text,

Modified: branches/S2_6/client/gui-qt/mapview.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/mapview.cpp?rev=33738&r1=33737&r2=33738&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/mapview.cpp     (original)
+++ branches/S2_6/client/gui-qt/mapview.cpp     Thu Sep  1 18:37:53 2016
@@ -1305,7 +1305,7 @@
 info_tile::info_tile(struct tile *ptile, QWidget *parent): QLabel(parent)
 {
   setParent(parent);
-  info_font = gui()->fc_fonts.get_font("gui_qt_font_comment_label");
+  info_font = get_font(fonts::comment_label);
   itile = ptile;
   calc_size();
 }
@@ -1315,7 +1315,7 @@
 **************************************************************************/
 void info_tile::calc_size()
 {
-  QFontMetrics fm(*info_font);
+  QFontMetrics fm(info_font);
   QString str;
   int hh = tileset_tile_height(tileset);
   int fin_x;
@@ -1352,7 +1352,7 @@
 void info_tile::paint(QPainter *painter, QPaintEvent *event)
 {
   QPen pen;
-  QFontMetrics fm(*info_font);
+  QFontMetrics fm(info_font);
   int pos, h;
 
   h = fm.height();
@@ -1362,7 +1362,7 @@
   painter->setBrush(QColor(0, 0, 0, 205));
   painter->drawRect(0, 0, width(), height());
   painter->setPen(pen);
-  painter->setFont(*info_font);
+  painter->setFont(info_font);
   for (int i = 0; i < str_list.count(); i++) {
     painter->drawText(5, pos, str_list.at(i));
     pos = pos + 5 + h;
@@ -1380,3 +1380,15 @@
   paint(&painter, event);
   painter.end();
 }
+
+/**************************************************************************
+  Updates fonts
+**************************************************************************/
+void info_tile::update_font(const QString &name, const QFont &font)
+{
+  if (name == fonts::comment_label) {
+    info_font = font;
+    calc_size();
+    update();
+  }
+}

Modified: branches/S2_6/client/gui-qt/mapview.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/mapview.h?rev=33738&r1=33737&r2=33738&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/mapview.h       (original)
+++ branches/S2_6/client/gui-qt/mapview.h       Thu Sep  1 18:37:53 2016
@@ -148,10 +148,10 @@
 /**************************************************************************
   Information label about clicked tile
 **************************************************************************/
-class info_tile: public QLabel
-{
-  Q_OBJECT
-  QFont *info_font;
+class info_tile: public QLabel, private font_options_listener
+{
+  Q_OBJECT
+  QFont info_font;
 public:
   info_tile(struct tile *ptile, QWidget *parent = 0);
   struct tile *itile;
@@ -161,6 +161,7 @@
 private:
   QStringList str_list;
   void calc_size();
+  void update_font(const QString &name, const QFont &font);
 };
 
 /**************************************************************************


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

Reply via email to