12 #include <QApplication>
18 #include <QStyleFactory>
19 #include <QTextStream>
42 void load_chat_colors(QSettings &
settings)
44 settings.beginGroup(
"color_mapping");
45 QHash<QString, QString>
colors;
47 for (
auto k :
settings.childKeys()) {
49 if (!QColor::isValidColor(val)) {
50 qWarning() <<
"color invalid: " << val;
53 colors[QStringLiteral(
"#") + k] = val;
60 static std::array<QColor, COLOR_LAST> diag_colors = {};
65 void load_diag_colors(QSettings &
settings)
67 settings.beginGroup(
"diagram_colors");
69 for (
int i = 0; i < COLOR_LAST; ++i) {
70 const auto name = color_std_name(
static_cast<color_std
>(i));
74 diag_colors[i] = QColor();
84 QPalette load_palette(QSettings &
settings)
86 settings.beginGroup(
"general_colors");
89 auto meta = QMetaEnum::fromType<QPalette::ColorRole>();
90 for (
int i = 0; i < meta.keyCount(); ++i) {
91 const auto name = meta.key(i);
92 const auto role =
static_cast<QPalette::ColorRole
>(meta.value(i));
93 if (role == QPalette::NColorRoles || role == QPalette::NoRole) {
98 qWarning() <<
"missing color" <<
name;
103 if (!QColor::isValidColor(val)) {
104 qWarning() <<
"color invalid:" << val;
108 pal.setBrush(role, QColor(val));
125 QString lnb = QStringLiteral(
"LittleFinger");
127 if (def_app_style->isEmpty()) {
128 *def_app_style = QApplication::style()->objectName();
131 data_dir = QString(directory);
133 f.setFileName(data_dir +
"/" + theme_name +
"/resource.qss");
135 if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
144 *stylestring = in.readAll();
145 stylestring->replace(lnb, fake_dir +
"/" + theme_name +
"/");
147 if (theme_name == QStringLiteral(
"System")) {
148 QApplication::setStyle(QStyleFactory::create(*def_app_style));
150 QStyle *fstyle = QStyleFactory::create(QStringLiteral(
"Fusion"));
152 if (fstyle !=
nullptr) {
153 QApplication::setStyle(fstyle);
155 QApplication::setStyle(QStyleFactory::create(*def_app_style));
159 QSettings
settings(data_dir +
"/" + theme_name +
"/theme.conf",
160 QSettings::IniFormat);
165 QPixmapCache::clear();
166 if (theme_name != QStringLiteral(
"System")) {
169 QApplication::setPalette(load_palette(
settings));
171 qApp->setStyleSheet(*stylestring);
184 qFatal(
_(
"No Qt-client theme was found. For instructions on how to "
185 "get one, please visit %s"),
202 *count = data_dirs.size();
203 for (
const auto &data_dir : data_dirs) {
204 directories.append(QStringLiteral(
"%1/themes").arg(data_dir));
217 QStringList sl, theme_list, array;
224 dir.setPath(directory);
225 sl << dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
226 name = QString(directory);
228 for (
auto const &str : qAsConst(sl)) {
231 if (str == QStringLiteral(
"System")) {
235 f.setFileName(
name +
"/" + str +
"/resource.qss");
244 if (theme_list.contains(qtheme_name)) {
245 theme_list.removeAll(qtheme_name);
246 theme_list.prepend(qtheme_name);
void set_chat_colors(const QHash< QString, QString > &colors)
Sets color substitution map.
void reloadSidebarIcons()
Reloads top bar icons (useful on theme change)
QColor get_color(const struct tileset *t, enum color_std stdcolor)
Return a pointer to the given "standard" color.
class fc_client * king()
Return fc_client instance.
client_options * gui_options
#define FC_QT_DEFAULT_THEME_NAME
pageGame * queen()
Return game instandce.
Q_GLOBAL_STATIC(QVector< QString >, future_name_translation)
static struct setting settings[]
const QStringList & get_data_dirs()
Returns a list of data directory paths, in the order in which they should be searched.
char gui_qt_default_theme_name[512]
QStringList get_gui_specific_themes_directories(int *count)
Each gui has its own themes directories.
QStringList get_useable_themes_in_directory(QString &directory)
Return an array of names of usable themes in the given directory.
QColor get_diag_color(color_std c)
Gets a diagram color.
void gui_clear_theme()
Clears a theme (sets default system theme)
void gui_load_theme(const QString &directory, const QString &theme_name)
Loads a qt theme directory/theme_name.
struct theme_directory * directories
bool load_theme(const QString &theme_name)
Loads a theme with the given name.