Author: mir3x
Date: Wed Jul 20 21:42:34 2016
New Revision: 33284

URL: http://svn.gna.org/viewcvs/freeciv?rev=33284&view=rev
Log:
Qt client - added option to change themes (only system ones).

See patch #7471


Modified:
    branches/S2_5/client/gui-qt/gui_main.cpp
    branches/S2_5/client/gui-qt/themes.cpp
    branches/S2_5/client/options.c

Modified: branches/S2_5/client/gui-qt/gui_main.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/gui_main.cpp?rev=33284&r1=33283&r2=33284&view=diff
==============================================================================
--- branches/S2_5/client/gui-qt/gui_main.cpp    (original)
+++ branches/S2_5/client/gui-qt/gui_main.cpp    Wed Jul 20 21:42:34 2016
@@ -35,6 +35,7 @@
 #include <QApplication>
 #include <QMessageBox>
 #include <QScrollBar>
+#include <QStyleFactory>
 
 // utility
 #include "fciconv.h"
@@ -63,6 +64,7 @@
 const bool gui_use_transliteration = false;
 
 static QPixmap *unit_pixmap;
+extern char gui_qt_default_theme_name[512];
 
 void reset_unit_table(void);
 static void populate_unit_pixmap_table(void);
@@ -156,6 +158,7 @@
     qpm = get_icon_sprite(tileset, ICON_FREECIV)->pm;
     app_icon = ::QIcon(*qpm);
     qapp->setWindowIcon(app_icon);
+    qapp->setStyle(QStyleFactory::create(gui_qt_default_theme_name));
     freeciv_qt = new fc_client();
     freeciv_qt->main(qapp);
   }

Modified: branches/S2_5/client/gui-qt/themes.cpp
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/gui-qt/themes.cpp?rev=33284&r1=33283&r2=33284&view=diff
==============================================================================
--- branches/S2_5/client/gui-qt/themes.cpp      (original)
+++ branches/S2_5/client/gui-qt/themes.cpp      Wed Jul 20 21:42:34 2016
@@ -14,6 +14,10 @@
 #include <fc_config.h>
 #endif
 
+// Qt
+#include <QApplication>
+#include <QStyleFactory>
+
 /* utility */
 #include "mem.h"
 
@@ -26,12 +30,14 @@
 /* client/include */
 #include "themes_g.h"
 
+extern QApplication *qapp;
+
 /*****************************************************************************
-  Loads a gtk theme directory/theme_name
+  Loads a qt theme directory/theme_name
 *****************************************************************************/
 void qtg_gui_load_theme(const char *directory, const char *theme_name)
 {
-  /* Nothing */
+  qapp->setStyle(QStyleFactory::create(theme_name));
 }
 
 /*****************************************************************************
@@ -39,7 +45,7 @@
 *****************************************************************************/
 void qtg_gui_clear_theme()
 {
-  /* Nothing */
+  qapp->setStyle(QStyleFactory::create("Fusion"));
 }
 
 /*****************************************************************************
@@ -50,9 +56,10 @@
 *****************************************************************************/
 char **qtg_get_gui_specific_themes_directories(int *count)
 {
-  *count = 0;
-  
-  return (char **) fc_malloc(sizeof(char*) * 0);
+  const char **array = new const char *[1];
+  *count = 1;
+  array[0] = "qt";
+  return const_cast<char**>(array);
 }
 
 /*****************************************************************************
@@ -62,6 +69,22 @@
 *****************************************************************************/
 char **qtg_get_useable_themes_in_directory(const char *directory, int *count)
 {
-  *count = 0;
-  return (char **) fc_malloc(sizeof(char*) * 0);
+  QStringList sl;
+  char **array;
+  char *data;
+  QByteArray qba;;
+  QString str;
+
+  sl = QStyleFactory::keys();
+  array = new char *[sl.count()];
+  *count = sl.count();
+
+  for (int i = 0; i < *count; i++) {
+    qba = sl[i].toLocal8Bit();
+    data = new char[sl[i].toLocal8Bit().count() + 1];
+    strcpy(data, sl[i].toLocal8Bit().data());
+    array[i] = data;
+  }
+
+  return array;
 }

Modified: branches/S2_5/client/options.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_5/client/options.c?rev=33284&r1=33283&r2=33284&view=diff
==============================================================================
--- branches/S2_5/client/options.c      (original)
+++ branches/S2_5/client/options.c      Wed Jul 20 21:42:34 2016
@@ -235,6 +235,8 @@
 bool gui_sdl_use_color_cursors = TRUE;
 
 /* gui-qt client specific options. */
+
+char gui_qt_default_theme_name[512] = "Fusion";
 char gui_qt_font_city_label[512] = "Monospace,8,-1,5,50,0,0,0,0,0";
 char gui_qt_font_notify_label[512] = "Monospace,8,-1,5,75,0,0,0,0,0";
 char gui_qt_font_spaceship_label[512] = "Monospace,8,-1,5,50,0,0,0,0,0";
@@ -1776,6 +1778,11 @@
                       N_("By changing this option you change the "
                          "active theme."),
                       COC_GRAPHICS, GUI_SDL, FC_SDL_DEFAULT_THEME_NAME,
+                      get_themes_list, theme_reread_callback),
+  GEN_STR_LIST_OPTION(gui_qt_default_theme_name, N_("Theme"),
+                      N_("By changing this option you change the "
+                         "active theme."),
+                      COC_GRAPHICS, GUI_QT, NULL,
                       get_themes_list, theme_reread_callback),
 
   /* It's important to give empty string instead of NULL as as default


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

Reply via email to