Author: mir3x Date: Thu Sep 1 18:34:44 2016 New Revision: 33735 URL: http://svn.gna.org/viewcvs/freeciv?rev=33735&view=rev Log: Qt client - Use new font system in canvas-related classes. Patch by Louis Moureaux <louis94>
See patch #7660 Modified: trunk/client/gui-qt/canvas.cpp trunk/client/gui-qt/mapview.cpp trunk/client/gui-qt/mapview.h trunk/client/gui-qt/repodlgs.cpp trunk/client/gui-qt/repodlgs.h Modified: trunk/client/gui-qt/canvas.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/canvas.cpp?rev=33735&r1=33734&r2=33735&view=diff ============================================================================== --- trunk/client/gui-qt/canvas.cpp (original) +++ trunk/client/gui-qt/canvas.cpp Thu Sep 1 18:34:44 2016 @@ -20,10 +20,9 @@ // qt-client #include "canvas.h" +#include "fonts.h" #include "sprite.h" #include "colors.h" - -QFont *get_font(enum client_font font); /**************************************************************************** Create a canvas of the given size. @@ -274,33 +273,6 @@ } /**************************************************************************** - Returns given font -****************************************************************************/ -QFont *get_font(client_font font) -{ - QFont *qf; - switch (font) { - case FONT_CITY_NAME: - qf = gui()->fc_fonts.get_font("gui_qt_font_city_names"); - break; - case FONT_CITY_PROD: - qf = gui()->fc_fonts.get_font("gui_qt_font_city_productions"); - break; - case FONT_REQTREE_TEXT: - qf = gui()->fc_fonts.get_font("gui_qt_font_reqtree_text"); - break; - case FONT_COUNT: - qf = NULL; - break; - default: - qf = NULL; - break; - } - return qf; -} - - -/**************************************************************************** Return the size of the given text in the given font. This size should include the ascent and descent of the text. Either of width or height may be NULL in which case those values simply shouldn't be filled out. @@ -308,11 +280,11 @@ void qtg_get_text_size (int *width, int *height, enum client_font font, const char *text) { - QFont *afont; + QFont afont; QFontMetrics *fm; - afont = get_font(font); - fm = new QFontMetrics(*afont); + afont = font_options_listener::get_font(font); + fm = new QFontMetrics(afont); if (width) { *width = fm->width(QString::fromUtf8(text)); } @@ -334,17 +306,17 @@ { QPainter p; QPen pen; - QFont *afont; + QFont afont; QColor color(pcolor->qcolor); QFontMetrics *fm; - afont = get_font(font); + afont = font_options_listener::get_font(font); pen.setColor(color); - fm = new QFontMetrics(*afont); + fm = new QFontMetrics(afont); p.begin(&pcanvas->map_pixmap); p.setPen(pen); - p.setFont(*afont); + p.setFont(afont); p.drawText(canvas_x, canvas_y + fm->ascent(), QString::fromUtf8(text)); p.end(); delete fm; Modified: trunk/client/gui-qt/mapview.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/mapview.cpp?rev=33735&r1=33734&r2=33735&view=diff ============================================================================== --- trunk/client/gui-qt/mapview.cpp (original) +++ trunk/client/gui-qt/mapview.cpp Thu Sep 1 18:34:44 2016 @@ -226,6 +226,8 @@ timer->start(200); resize(0, 0); setMouseTracking(true); + + font_options_listener::listen(); } /************************************************************************** @@ -265,6 +267,17 @@ cursor_frame = 0; } setCursor(*(gui()->fc_cursors[cursor][cursor_frame])); +} + +/************************************************************************** + Updates fonts +**************************************************************************/ +void map_view::update_font(const QString &name, const QFont &font) +{ + if (name == fonts::city_names || + name == fonts::city_productions) { + update_map_canvas_visible(); + } } /************************************************************************** Modified: trunk/client/gui-qt/mapview.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/mapview.h?rev=33735&r1=33734&r2=33735&view=diff ============================================================================== --- trunk/client/gui-qt/mapview.h (original) +++ trunk/client/gui-qt/mapview.h Thu Sep 1 18:34:44 2016 @@ -25,6 +25,9 @@ extern "C" { #include "mapview_g.h" } + +// gui-qt +#include "fonts.h" // Qt #include <QHBoxLayout> @@ -112,7 +115,7 @@ /************************************************************************** QWidget used for displaying map **************************************************************************/ -class map_view : public QWidget +class map_view : public QWidget, private font_options_listener { Q_OBJECT public: @@ -135,6 +138,8 @@ private slots: void timer_event(); private: + void update_font(const QString &name, const QFont &font); + int cursor_frame; int cursor; Modified: trunk/client/gui-qt/repodlgs.cpp URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/repodlgs.cpp?rev=33735&r1=33734&r2=33735&view=diff ============================================================================== --- trunk/client/gui-qt/repodlgs.cpp (original) +++ trunk/client/gui-qt/repodlgs.cpp Thu Sep 1 18:34:44 2016 @@ -93,6 +93,8 @@ req = NULL; reset(); setMouseTracking(true); + + font_options_listener::listen(); } /**************************************************************************** @@ -244,6 +246,15 @@ pcanvas->map_pixmap.fill(Qt::transparent); } +/**************************************************************************** + Updates the canvas when the font changes +****************************************************************************/ +void research_diagram::font_changed(const QString &name, const QFont &) +{ + if (name == fonts::reqtree_text) { + update_reqtree(); + } +} /**************************************************************************** Mouse handler for research_diagram Modified: trunk/client/gui-qt/repodlgs.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-qt/repodlgs.h?rev=33735&r1=33734&r2=33735&view=diff ============================================================================== --- trunk/client/gui-qt/repodlgs.h (original) +++ trunk/client/gui-qt/repodlgs.h Thu Sep 1 18:34:44 2016 @@ -24,6 +24,9 @@ // client #include "climisc.h" + +// gui-qt +#include "fonts.h" // Qt #include <QObject> @@ -66,7 +69,8 @@ /**************************************************************************** Custom widget representing research diagram in science_report ****************************************************************************/ -class research_diagram: public QWidget +class research_diagram: public QWidget, + private font_options_listener { Q_OBJECT @@ -78,6 +82,7 @@ QSize size(); private: + void font_changed(const QString &name, const QFont &font); void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); void paintEvent(QPaintEvent *event); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits