Author: mir3x
Date: Sun Oct 23 20:00:41 2016
New Revision: 34224

URL: http://svn.gna.org/viewcvs/freeciv?rev=34224&view=rev
Log:
Qt client - try to set better fonts on first run

See patch #7854

Modified:
    branches/S2_6/client/gui-qt/chatline.cpp
    branches/S2_6/client/gui-qt/fc_client.cpp
    branches/S2_6/client/gui-qt/fonts.cpp
    branches/S2_6/client/gui-qt/fonts.h

Modified: branches/S2_6/client/gui-qt/chatline.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/chatline.cpp?rev=34224&r1=34223&r2=34224&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/chatline.cpp    (original)
+++ branches/S2_6/client/gui-qt/chatline.cpp    Sun Oct 23 20:00:41 2016
@@ -273,6 +273,7 @@
   gl = new QGridLayout;
   chat_line = new chat_input;
   chat_output = new QTextBrowser;
+  chat_output->setFont(*fc_font::instance()->get_font(fonts::chatline));
   remove_links = new QPushButton("");
   
remove_links->setIcon(style()->standardPixmap(QStyle::SP_DialogCancelButton));
   remove_links->setToolTip(_("Clear links"));

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=34224&r1=34223&r2=34224&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/fc_client.cpp   (original)
+++ branches/S2_6/client/gui-qt/fc_client.cpp   Sun Oct 23 20:00:41 2016
@@ -121,6 +121,7 @@
 void fc_client::init()
 {
   fc_font::instance()->init_fonts();
+  read_settings();
   QApplication::setFont(*fc_font::instance()->get_font(fonts::default_font));
   QString path;
   central_wdg = new QWidget;
@@ -168,7 +169,6 @@
   if (path.isEmpty() == false) {
     QSettings::setPath(QSettings::NativeFormat, QSettings::UserScope, path);
   }
-  read_settings();
   pages[PAGE_GAME] = new QWidget(central_wdg);
   init_mapcanvas_and_overview();
   create_game_page();
@@ -204,6 +204,7 @@
 
   game_tab_widget->init();
   chat_listener::listen();
+
 }
 
 /****************************************************************************
@@ -580,6 +581,9 @@
 {
   QSettings s(QSettings::IniFormat, QSettings::UserScope,
               "freeciv-qt-client");
+  if (s.contains("Fonts-set") == false) {
+    configure_fonts();
+  }
   if (s.contains("Chat-xsize")) {
     qt_settings.chat_width = s.value("Chat-xsize").toInt();
   } else {
@@ -624,6 +628,7 @@
 {
   QSettings s(QSettings::IniFormat, QSettings::UserScope,
               "freeciv-qt-client");
+  s.setValue("Fonts-set", true);
   s.setValue("Chat-xsize", qt_settings.chat_width);
   s.setValue("Chat-ysize", qt_settings.chat_height);
   s.setValue("City-dialog", qt_settings.city_geometry);

Modified: branches/S2_6/client/gui-qt/fonts.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/fonts.cpp?rev=34224&r1=34223&r2=34224&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/fonts.cpp       (original)
+++ branches/S2_6/client/gui-qt/fonts.cpp       Sun Oct 23 20:00:41 2016
@@ -21,7 +21,11 @@
 #include "fonts.h"
 
 // Qt
+#include <QApplication>
+#include <QFontDatabase>
+#include <QGuiApplication>
 #include <QWidget>
+#include <QScreen>
 
 /****************************************************************************
   Font provider constructor
@@ -114,3 +118,118 @@
   font_map.insert(name,qf);
 }
 
+/****************************************************************************
+  Tries to choose good fonts for freeciv-qt 
+****************************************************************************/
+void configure_fonts()
+{
+  int max, smaller, default_size;
+  QStringList sl;
+  QString font_name;
+  const QList<QScreen *> screens = QGuiApplication::screens();
+  const QScreen *screen = screens.at(0);
+  qreal logical_dpi = screen->logicalDotsPerInchX();
+  qreal physical_dpi = screen->physicalDotsPerInchX();
+  qreal scale = (physical_dpi / logical_dpi)
+                / screen->devicePixelRatio();
+
+  max = qRound(physical_dpi * scale / 6);
+  smaller = qRound(physical_dpi * scale / 8);
+  default_size = qRound(physical_dpi * scale / 7);
+
+  /* default and help label*/
+  sl << "Segoe UI" << "Cousine" << "Liberation Sans" << "Droid Sans" 
+     << "Ubuntu" << "Noto Sans" << "DejaVu Sans" << "Luxi Sans"
+     << "Lucida Sans" << "Trebuchet MS" << "Times New Roman";
+  font_name = configure_font(fonts::default_font, sl, max);
+  if (font_name.isEmpty() == false) {
+    fc_strlcpy(gui_options.gui_qt_font_default,
+               font_name.toLocal8Bit().data(), 512);
+  }
+  font_name = configure_font(fonts::help_label, sl, max);
+  if (font_name.isEmpty() == false) {
+    fc_strlcpy(gui_options.gui_qt_font_help_label,
+               font_name.toLocal8Bit().data(), 512);
+  }
+  font_name = configure_font(fonts::city_names, sl, smaller, true);
+  if (font_name.isEmpty() == false) {
+    fc_strlcpy(gui_options.gui_qt_font_city_names,
+               font_name.toLocal8Bit().data(), 512);
+  }
+  sl.clear();
+
+  /* notify */
+  sl  <<  "Cousine" << "Liberation Mono" << "Source Code Pro"
+      << "Source Code Pro [ADBO]"
+      << "Noto Mono" << "Ubuntu Mono" << "Courier New";
+  font_name = configure_font(fonts::notify_label, sl, default_size);
+  if (font_name.isEmpty() == false) {
+    fc_strlcpy(gui_options.gui_qt_font_notify_label,
+               font_name.toLocal8Bit().data(), 512);
+  }
+
+  /* the same font for city label but smaller */
+  font_name = configure_font(fonts::city_label, sl, smaller);
+  if (font_name.isEmpty() == false) {
+    fc_strlcpy(gui_options.gui_qt_font_city_label,
+               font_name.toLocal8Bit().data(), 512);
+  }
+  /* standard for chat */
+  font_name = configure_font(fonts::chatline, sl, default_size);
+  if (font_name.isEmpty() == false) {
+    fc_strlcpy(gui_options.gui_qt_font_chatline,
+               font_name.toLocal8Bit().data(), 512);
+  }
+
+  /* help title */
+  sl.clear();
+  sl  <<  "Segoe Print" << "Papyrus" << "Vladimir Script"
+      << "Comic Sans MS" << "Droid Sans" << "Noto Sans";
+  font_name = configure_font(fonts::help_title, sl, max, true);
+  if (font_name.isEmpty() == false) {
+    fc_strlcpy(gui_options.gui_qt_font_help_title,
+               font_name.toLocal8Bit().data(), 512);
+  }
+  /* City production */
+  sl.clear();
+  sl  << "Arimo" << "Play" <<  "Tinos" << "Ubuntu" << "Times New Roman"
+      << "Droid Sans" << "Noto Sans";
+  font_name = configure_font(fonts::city_productions, sl, default_size,
+                             true);
+  if (font_name.isEmpty() == false) {
+    fc_strlcpy(gui_options.gui_qt_font_city_productions,
+               font_name.toLocal8Bit().data(), 512);
+  }
+  /* Reqtree */
+  sl.clear();
+  sl  << "Papyrus" << "Segoe Script" << "Comic Sans MS"
+      << "Droid Sans" << "Noto Sans" << "Ubuntu";
+  font_name = configure_font(fonts::reqtree_text, sl, max, true);
+  if (font_name.isEmpty() == false) {
+    fc_strlcpy(gui_options.gui_qt_font_reqtree_text,
+               font_name.toLocal8Bit().data(), 512);
+  }
+}
+
+/****************************************************************************
+  Returns long font name, sets given for for use
+****************************************************************************/
+QString configure_font(QString font_name, QStringList sl, int size,
+                       bool bold)
+{
+  QFontDatabase database;
+  QString str;
+  QFont *f;
+
+  foreach (str, sl)  {
+    if (database.families().contains(str)) {
+      f = new QFont(str, size);
+      if (bold) {
+        f->setBold(true);
+      }
+      fc_font::instance()->set_font(font_name, f);
+      return f->toString().toLocal8Bit().data();
+    }
+  }
+  return QString();
+}

Modified: branches/S2_6/client/gui-qt/fonts.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/fonts.h?rev=34224&r1=34223&r2=34224&view=diff
==============================================================================
--- branches/S2_6/client/gui-qt/fonts.h (original)
+++ branches/S2_6/client/gui-qt/fonts.h Sun Oct 23 20:00:41 2016
@@ -60,4 +60,7 @@
   void release_fonts();
 };
 
+void configure_fonts();
+QString configure_font(QString font_name, QStringList sl, int size, bool bold 
= false);
+
 #endif // FC__FONTS_H


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

Reply via email to