Freeciv-3.2
Loading...
Searching...
No Matches
themes.cpp
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifdef HAVE_CONFIG_H
14#include <fc_config.h>
15#endif
16
17// Qt
18#include <QApplication>
19#include <QDir>
20#include <QPalette>
21#include <QStyleFactory>
22#include <QTextStream>
23
24// utility
25#include "mem.h"
26
27// client
28#include "themes_common.h"
29
30// client/include
31#include "themes_g.h"
32
33// gui-qt
34#include "fc_client.h"
35#include "gui_main.h"
36
40
41/*************************************************************************/
44void qtg_gui_load_theme(const char *directory, const char *theme_name)
45{
47 QString path;
50 QDir dir;
51 QFile f;
52 QString lnb = "LittleFinger";
54
55 if (def_app_style.isEmpty()) {
56 def_app_style = QApplication::style()->objectName();
57 }
58
60
62 name = path + "resource.qss";
63 f.setFileName(name);
64
65 if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
68 }
69 return;
70 }
71 // Stylesheet uses UNIX separators
73 fake_dir.replace(QString(DIR_SEPARATOR), "/");
75 stylestring = in.readAll();
76 stylestring.replace(lnb, fake_dir + "/" + theme_name + "/");
77
78 if (QString(theme_name) == QString("System")) {
79 QApplication::setStyle(QStyleFactory::create(def_app_style));
80 } else {
81 QStyle *fstyle = QStyleFactory::create("Fusion");
82
83 if (fstyle != nullptr) {
84 QApplication::setStyle(fstyle);
85 } else {
86 QApplication::setStyle(QStyleFactory::create(def_app_style));
87 }
88 }
89
91 QPixmapCache::clear();
92 current_app()->setStyleSheet(stylestring);
93 if (gui()) {
94 gui()->reload_sidebar_icons();
95 }
96 pal.setBrush(QPalette::Link, QColor(92,170,229));
97 pal.setBrush(QPalette::LinkVisited, QColor(54,150,229));
98 QApplication::setPalette(pal);
99}
100
101/*************************************************************************/
105{
107 // TRANS: No full stop after the URL, could cause confusion.
108 log_fatal(_("No Qt-client theme was found. For instructions on how to "
109 "get one, please visit %s"), HOMEPAGE_URL);
111 }
112}
113
114/*************************************************************************/
121{
122 const struct strvec *data_dirs = get_data_dirs();
123 char **directories = (char **)fc_malloc(strvec_size(data_dirs)
124 * sizeof(char *));
125 int i = 0;
126
127 *count = strvec_size(data_dirs);
129 int len = strlen(data_dir) + strlen("/themes/gui-qt") + 1;
130 char *buf = (char *)fc_malloc(len);
131
132 fc_snprintf(buf, len, "%s/themes/gui-qt", data_dir);
133
134 directories[i++] = buf;
136
137 return directories;
138}
139
140/*************************************************************************/
145char **qtg_get_usable_themes_in_directory(const char *directory, int *count)
146{
148 char **array;
149 char *data;
151 QString str;
154 QDir dir;
155 QFile f;
156
157 dir.setPath(directory);
158 sl << dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
160
161 foreach(str, sl) {
162 f.setFileName(name + DIR_SEPARATOR + str
163 + DIR_SEPARATOR + "resource.qss");
164 if (!f.exists()) {
165 continue;
166 }
167 theme_list << str;
168 }
169
171 // Move current theme on first position
172 if (theme_list.contains(qtheme_name)) {
173 theme_list.removeAll(qtheme_name);
174 theme_list.prepend(qtheme_name);
175 }
176 array = new char *[theme_list.count()];
177 *count = theme_list.count();
178
179 for (int i = 0; i < *count; i++) {
181
182 qba = theme_list[i].toUtf8();
183 data = new char[theme_list[i].toUtf8().length() + 1];
184 tn_bytes = theme_list[i].toUtf8();
185 strcpy(data, tn_bytes.data());
186 array[i] = data;
187 }
188
189 return array;
190}
#define str
Definition astring.c:76
char * incite_cost
Definition comments.c:75
#define _(String)
Definition fcintl.h:67
static bool load_theme
Definition theme_dlg.c:30
QApplication * current_app()
Definition gui_main.cpp:229
const char * name
Definition inputfile.c:127
#define log_fatal(message,...)
Definition log.h:100
#define fc_malloc(sz)
Definition mem.h:34
static mpgui * gui
Definition mpgui_qt.cpp:52
struct client_options gui_options
Definition options.c:71
#define FC_QT_DEFAULT_THEME_NAME
Definition options.h:404
int len
Definition packhand.c:127
const struct strvec * get_data_dirs(void)
Definition shared.c:893
#define DIR_SEPARATOR
Definition shared.h:127
size_t strvec_size(const struct strvec *psv)
#define strvec_iterate(psv, str)
#define strvec_iterate_end
char gui_qt_default_theme_name[512]
Definition options.h:409
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
static QString def_app_style
Definition themes.cpp:38
char ** qtg_get_usable_themes_in_directory(const char *directory, int *count)
Definition themes.cpp:145
QString current_theme
Definition fc_client.cpp:65
void qtg_gui_clear_theme()
Definition themes.cpp:104
static QString stylestring
Definition themes.cpp:39
void qtg_gui_load_theme(const char *directory, const char *theme_name)
Definition themes.cpp:44
char ** qtg_get_gui_specific_themes_directories(int *count)
Definition themes.cpp:120
struct theme_directory * directories
const char * directory
Definition themes_g.h:23