Freeciv-3.3
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
41static QStyle *current_style = nullptr;
42
43/*************************************************************************/
46void qtg_gui_load_theme(const char *directory, const char *theme_name)
47{
49 QString path;
52 QDir dir;
53 QFile f;
54 QString lnb = "LittleFinger";
56
57 if (def_app_style.isEmpty()) {
58 def_app_style = QApplication::style()->objectName();
59 }
60
62
64 name = path + "resource.qss";
65 f.setFileName(name);
66
67 if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
70 }
71 return;
72 }
73 // Stylesheet uses UNIX separators
75 fake_dir.replace(QString(DIR_SEPARATOR), "/");
77 stylestring = in.readAll();
78 stylestring.replace(lnb, fake_dir + "/" + theme_name + "/");
79
80 if (QString(theme_name) == QString("System")) {
81 current_style = QStyleFactory::create(def_app_style);
82 } else {
83 QStyle *fstyle = QStyleFactory::create("Fusion");
84
85 if (fstyle != nullptr) {
87 } else {
88 current_style = QStyleFactory::create(def_app_style);
89 }
90 }
91 QApplication::setStyle(current_style);
92
94 QPixmapCache::clear();
95 current_app()->setStyleSheet(stylestring);
96 if (gui()) {
97 gui()->reload_sidebar_icons();
98 }
99 pal.setBrush(QPalette::Link, QColor(92,170,229));
100 pal.setBrush(QPalette::LinkVisited, QColor(54,150,229));
101 QApplication::setPalette(pal);
102}
103
104/*************************************************************************/
108{
109 QApplication::setStyle(current_style);
110}
111
112/*************************************************************************/
116{
118 // TRANS: No full stop after the URL, could cause confusion.
119 log_fatal(_("No Qt-client theme was found. For instructions on how to "
120 "get one, please visit %s"), HOMEPAGE_URL);
122 }
123}
124
125/*************************************************************************/
132{
133 const struct strvec *data_dirs = get_data_dirs();
134 char **directories = (char **)fc_malloc(strvec_size(data_dirs)
135 * sizeof(char *));
136 int i = 0;
137
138 *count = strvec_size(data_dirs);
140 int len = strlen(data_dir) + strlen("/themes/gui-qt") + 1;
141 char *buf = (char *)fc_malloc(len);
142
143 fc_snprintf(buf, len, "%s/themes/gui-qt", data_dir);
144
145 directories[i++] = buf;
147
148 return directories;
149}
150
151/*************************************************************************/
156char **qtg_get_usable_themes_in_directory(const char *directory, int *count)
157{
159 char **array;
160 char *data;
162 QString str;
165 QDir dir;
166 QFile f;
167
168 dir.setPath(directory);
169 sl << dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
171
172 foreach(str, sl) {
173 f.setFileName(name + DIR_SEPARATOR + str
174 + DIR_SEPARATOR + "resource.qss");
175 if (!f.exists()) {
176 continue;
177 }
178 theme_list << str;
179 }
180
182 // Move current theme on first position
183 if (theme_list.contains(qtheme_name)) {
184 theme_list.removeAll(qtheme_name);
185 theme_list.prepend(qtheme_name);
186 }
187 array = new char *[theme_list.count()];
188 *count = theme_list.count();
189
190 for (int i = 0; i < *count; i++) {
192
193 qba = theme_list[i].toUtf8();
194 data = new char[theme_list[i].toUtf8().length() + 1];
195 tn_bytes = theme_list[i].toUtf8();
196 strcpy(data, tn_bytes.data());
197 array[i] = data;
198 }
199
200 return array;
201}
#define str
Definition astring.c:76
char * incite_cost
Definition comments.c:76
#define _(String)
Definition fcintl.h:67
static bool load_theme
Definition theme_dlg.c:30
QApplication * current_app()
Definition gui_main.cpp:227
const char * name
Definition inputfile.c:127
#define log_fatal(message,...)
Definition log.h:101
#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:412
int len
Definition packhand.c:127
const struct strvec * get_data_dirs(void)
Definition shared.c:886
#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:417
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
static QString def_app_style
Definition themes.cpp:38
char ** qtg_get_usable_themes_in_directory(const char *directory, int *count)
Definition themes.cpp:156
QString current_theme
Definition fc_client.cpp:64
void qtg_gui_clear_theme()
Definition themes.cpp:115
static QString stylestring
Definition themes.cpp:39
void qtg_gui_load_theme(const char *directory, const char *theme_name)
Definition themes.cpp:46
void set_theme_style()
Definition themes.cpp:107
char ** qtg_get_gui_specific_themes_directories(int *count)
Definition themes.cpp:131
static QStyle * current_style
Definition themes.cpp:41
struct theme_directory * directories
const char * directory
Definition themes_g.h:23