RabbitCommon v2.3.3
Loading...
Searching...
No Matches
FrmStyle.cpp
1// Copyright Copyright (c) Kang Lin studio, All Rights Reserved
2// Author Kang Lin <kl222@126.com>
3
4// See: https://github.com/KangLin/Documents/blob/master/qt/theme.md
5// - Icon Theme Specification: https://specifications.freedesktop.org/icon-theme-spec/latest/
6// - Icon Naming Specification: https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
7// - Icon Theme Specification: https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
8
9#include <QSettings>
10#include <QLoggingCategory>
11
12#include "FrmStyle.h"
13#include "ui_FrmStyle.h"
14#include "Style.h"
15#include "RabbitCommonDir.h"
16
17static Q_LOGGING_CATEGORY(log, "RabbitCommon.Style")
18
19CFrmStyle::CFrmStyle(QWidget *parent, Qt::WindowFlags f) :
20 QWidget(parent, f),
21 ui(new Ui::CFrmStyle)
22{
23 qDebug(log) << Q_FUNC_INFO;
24 setAttribute(Qt::WA_DeleteOnClose, true);
25 ui->setupUi(this);
26
27 ui->leStyleName->setText(RabbitCommon::CStyle::Instance()->GetStyleFile());
28
29 ui->lbIconThemeChanged->setVisible(false);
30 // Icon theme
31 QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure(),
32 QSettings::IniFormat);
33 bool bIconTheme = set.value("Style/Icon/Theme/Enable", true).toBool();
34 ui->gpIconTheme->setChecked(bIconTheme);
35
36 qDebug(log)
37 << "Icon theme name:" << QIcon::themeName() << "\n"
38 << "Icon theme search paths:" << QIcon::themeSearchPaths() << "\n"
39 #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
40 << "Fallback theme name:" << QIcon::fallbackThemeName() << "\n"
41 #endif //QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
42 #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
43 << "Fallback search paths:" << QIcon::fallbackSearchPaths() << "\n"
44 #endif // QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
45 ;
46 foreach(auto d, QIcon::themeSearchPaths())
47 {
48 QDir dir(d);
49 if(!dir.exists())
50 {
51 qDebug(log)
52 << "Theme folder isn't exists:" << d;
53 continue;
54 }
55
56 qInfo(log) << "Theme folder:" << dir.absolutePath();
57// #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) && !defined(Q_OS_WINDOWS)
58// if(RabbitCommon::CDir::Instance()->GetDirIcons() == d) continue;
59// #endif
60 foreach(auto themeName, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
61 {
62 qDebug(log) << "Theme path:" << dir.absolutePath()
63 << "Theme:" << themeName;
64 QFileInfo fi(dir.absolutePath() + QDir::separator()
65 + themeName + QDir::separator() + "index.theme");
66 if(fi.exists())
67 {
68 qDebug(log) << "Theme:" << themeName;
69 ui->cbIconTheme->addItem(themeName);
70 } else {
71 qCritical(log) << "index.theme is not exists:" << fi.fileName()
72 << "Theme:" << themeName;
73 }
74 }
75 }
76 if(!QIcon::themeName().isEmpty())
77 ui->cbIconTheme->setCurrentText(QIcon::themeName());
78
79#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) && !defined(Q_OS_WINDOWS)
80 QDir fallbackDir(RabbitCommon::CDir::Instance()->GetDirIcons());
81 QStringList lstFallback;
82 if(fallbackDir.exists())
83 {
84 foreach(auto themeName, fallbackDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
85 {
86 qDebug(log) << "fallback path:" << fallbackDir.absolutePath()
87 << "Theme:" << themeName;
88 QFileInfo fi(fallbackDir.absolutePath() + QDir::separator()
89 + themeName + QDir::separator() + "index.theme");
90 if(!fi.exists())
91 continue;
92 qDebug(log) << "fallback Theme:" << themeName;
93 ui->cbFallbackTheme->addItem(themeName);
94 }
95 }
96
97 if(!QIcon::fallbackThemeName().isEmpty())
98 {
99 ui->cbFallbackTheme->setCurrentText(QIcon::fallbackThemeName());
100 }
101 ui->gbFallbackTheme->setVisible(true);
102#else
103 ui->gbFallbackTheme->setVisible(false);
104#endif
105
106}
107
108CFrmStyle::~CFrmStyle()
109{
110 qDebug(log) << "CFrmStyle::~CFrmStyle()";
111 delete ui;
112}
113
114void CFrmStyle::on_pbOK_clicked()
115{
116 QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure(),
117 QSettings::IniFormat);
118
119 bool bIconTheme = ui->gpIconTheme->isChecked();
120 set.setValue("Style/Icon/Theme/Enable", bIconTheme);
121 if(bIconTheme) {
122 if(!ui->cbIconTheme->currentText().isEmpty())
123 QIcon::setThemeName(ui->cbIconTheme->currentText());
124 set.setValue("Style/Icon/Theme", QIcon::themeName());
125
126#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
127 if(!ui->cbFallbackTheme->currentText().isEmpty())
128 QIcon::setFallbackThemeName(ui->cbFallbackTheme->currentText());
129 set.setValue("Style/Icon/Theme/Fallback", QIcon::fallbackThemeName());
130#endif
131 }
132
133 RabbitCommon::CStyle::Instance()->SetFile(ui->leStyleName->text());
134 close();
135}
136
137void CFrmStyle::on_pbCancel_clicked()
138{
139 close();
140}
141
142void CFrmStyle::on_pbBrowse_clicked()
143{
144 ui->leStyleName->setText(RabbitCommon::CStyle::Instance()->GetStyle());
145}
146
147void CFrmStyle::on_pbDefault_clicked()
148{
149 ui->leStyleName->setText(RabbitCommon::CStyle::Instance()->GetDefaultStyle());
150
151 if(ui->gpIconTheme->isChecked()) {
152 ui->cbIconTheme->setCurrentText(
153 RabbitCommon::CStyle::Instance()->m_szDefaultIconTheme);
154 ui->cbFallbackTheme->setCurrentText(
155 RabbitCommon::CStyle::Instance()->m_szDefaultFallbackIconTheme);
156 }
157}
158
159void CFrmStyle::on_gpIconTheme_clicked()
160{
161 ui->lbIconThemeChanged->setVisible(true);
162}
Set style and icon theme form.
Definition FrmStyle.h:89