Krita Source Code Documentation
Loading...
Searching...
No Matches
KisTheme.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#include "KisTheme.h"
7#include <QApplication>
9
11{
12 static const KisThemeConfig *kts;
13 if (!kts) {
14 kts = new KisThemeConfig;
15 }
16 return kts;
17}
18
19void KisThemeConfig::slotSetFilename(const QString &filename)
20{
21 if (filename != m_filename) {
22 m_filename = filename;
24 }
25}
26
28 : QObject(parent)
29 , m_filename(qApp->property("KDE_COLOR_SCHEME_PATH").toString())
30{
33 this,
36}
37
39{
40 KSharedConfigPtr config = KSharedConfig::openConfig(m_filename);
41 m_viewActive = KColorScheme(QPalette::Active, KColorScheme::View, config);
42 m_viewInactive = KColorScheme(QPalette::Inactive, KColorScheme::View, config);
43 m_viewDisabled = KColorScheme(QPalette::Disabled, KColorScheme::View, config);
44 m_windowActive = KColorScheme(QPalette::Active, KColorScheme::Window, config);
45 m_windowInactive = KColorScheme(QPalette::Inactive, KColorScheme::Window, config);
46 m_windowDisabled = KColorScheme(QPalette::Disabled, KColorScheme::Window, config);
47 m_buttonActive = KColorScheme(QPalette::Active, KColorScheme::Button, config);
48 m_buttonInactive = KColorScheme(QPalette::Inactive, KColorScheme::Button, config);
49 m_buttonDisabled = KColorScheme(QPalette::Disabled, KColorScheme::Button, config);
50 m_selectionActive = KColorScheme(QPalette::Active, KColorScheme::Selection, config);
51 m_selectionInactive = KColorScheme(QPalette::Inactive, KColorScheme::Selection, config);
52 m_selectionDisabled = KColorScheme(QPalette::Disabled, KColorScheme::Selection, config);
53 m_tooltipActive = KColorScheme(QPalette::Active, KColorScheme::Tooltip, config);
54 m_tooltipInactive = KColorScheme(QPalette::Inactive, KColorScheme::Tooltip, config);
55 m_tooltipDisabled = KColorScheme(QPalette::Disabled, KColorScheme::Tooltip, config);
56 Q_EMIT sigThemeChanged();
57}
58
60 : QObject(parent)
61 , m_set(set)
62{
63}
64
66{
67 return int(m_state);
68}
69
71{
72 if (m_state != QPalette::ColorGroup(state)) {
73 QColor oldTextColor = textColor();
74 QColor oldDisabledTextColor = disabledTextColor();
75 QColor oldActiveTextColor = activeTextColor();
76 QColor oldLinkColor = linkColor();
77 QColor oldVisitedLinkColor = visitedLinkColor();
78 QColor oldNegativeTextColor = negativeTextColor();
79 QColor oldNeutralTextColor = neutralTextColor();
80 QColor oldPositiveTextColor = positiveTextColor();
81 QColor oldBackgroundColor = backgroundColor();
82 QColor oldActiveBackgroundColor = activeBackgroundColor();
83 QColor oldLinkBackgroundColor = linkBackgroundColor();
84 QColor oldVisitedLinkBackgroundColor = visitedLinkBackgroundColor();
85 QColor oldNegativeBackgroundColor = negativeBackgroundColor();
86 QColor oldNeutralBackgroundColor = neutralBackgroundColor();
87 QColor oldPositiveBackgroundColor = positiveBackgroundColor();
88 QColor oldAlternateBackgroundColor = alternateBackgroundColor();
89 QColor oldFocusColor = focusColor();
90 QColor oldHoverColor = hoverColor();
91 QColor oldLightShadeColor = lightShadeColor();
92 QColor oldMidLightShadeColor = midLightShadeColor();
93 QColor oldMidShadeColor = midShadeColor();
94 QColor oldDarkShadeColor = darkShadeColor();
95 QColor oldShadowShadeColor = shadowShadeColor();
96
97 m_state = QPalette::ColorGroup(state);
98 Q_EMIT stateChanged();
99
100 if (QColor newTextColor = textColor(); newTextColor != oldTextColor) {
101 Q_EMIT textColorChanged();
102 }
103 if (QColor newDisabledTextColor = disabledTextColor(); newDisabledTextColor != oldDisabledTextColor) {
105 }
106 if (QColor newActiveTextColor = activeTextColor(); newActiveTextColor != oldActiveTextColor) {
107 Q_EMIT activeTextColorChanged();
108 }
109 if (QColor newLinkColor = linkColor(); newLinkColor != oldLinkColor) {
110 Q_EMIT linkColorChanged();
111 }
112 if (QColor newVisitedLinkColor = visitedLinkColor(); newVisitedLinkColor != oldVisitedLinkColor) {
114 }
115 if (QColor newNegativeTextColor = negativeTextColor(); newNegativeTextColor != oldNegativeTextColor) {
117 }
118 if (QColor newNeutralTextColor = neutralTextColor(); newNeutralTextColor != oldNeutralTextColor) {
120 }
121 if (QColor newPositiveTextColor = positiveTextColor(); newPositiveTextColor != oldPositiveTextColor) {
123 }
124 if (QColor newBackgroundColor = backgroundColor(); newBackgroundColor != oldBackgroundColor) {
125 Q_EMIT backgroundColorChanged();
126 }
127 if (QColor newActiveBackgroundColor = activeBackgroundColor();
128 newActiveBackgroundColor != oldActiveBackgroundColor) {
130 }
131 if (QColor newLinkBackgroundColor = linkBackgroundColor(); newLinkBackgroundColor != oldLinkBackgroundColor) {
133 }
134 if (QColor newVisitedLinkBackgroundColor = visitedLinkBackgroundColor();
135 newVisitedLinkBackgroundColor != oldVisitedLinkBackgroundColor) {
137 }
138 if (QColor newNegativeBackgroundColor = negativeBackgroundColor();
139 newNegativeBackgroundColor != oldNegativeBackgroundColor) {
141 }
142 if (QColor newNeutralBackgroundColor = neutralBackgroundColor();
143 newNeutralBackgroundColor != oldNeutralBackgroundColor) {
145 }
146 if (QColor newPositiveBackgroundColor = positiveBackgroundColor();
147 newPositiveBackgroundColor != oldPositiveBackgroundColor) {
149 }
150 if (QColor newAlternateBackgroundColor = alternateBackgroundColor();
151 newAlternateBackgroundColor != oldAlternateBackgroundColor) {
153 }
154 if (QColor newFocusColor = focusColor(); newFocusColor != oldFocusColor) {
155 Q_EMIT focusColorChanged();
156 }
157 if (QColor newHoverColor = hoverColor(); newHoverColor != oldHoverColor) {
158 Q_EMIT hoverColorChanged();
159 }
160 if (QColor newLightShadeColor = lightShadeColor(); newLightShadeColor != oldLightShadeColor) {
161 Q_EMIT lightShadeColorChanged();
162 }
163 if (QColor newMidLightShadeColor = midLightShadeColor(); newMidLightShadeColor != oldMidLightShadeColor) {
165 }
166 if (QColor newMidShadeColor = midShadeColor(); newMidShadeColor != oldMidShadeColor) {
167 Q_EMIT midShadeColorChanged();
168 }
169 if (QColor newDarkShadeColor = darkShadeColor(); newDarkShadeColor != oldDarkShadeColor) {
170 Q_EMIT darkShadeColorChanged();
171 }
172 if (QColor newShadowShadeColor = shadowShadeColor(); newShadowShadeColor != oldShadowShadeColor) {
174 }
175 }
176}
177
182
187
192
194{
196}
197
202
207
212
217
222
227
232
237
242
247
252
257
262
267
272
277
282
287
292
319
321{
322 switch (set) {
324 switch (state) {
325 case QPalette::Inactive:
327 case QPalette::Disabled:
329 default:
331 }
333 switch (state) {
334 case QPalette::Inactive:
336 case QPalette::Disabled:
338 default:
340 }
342 switch (state) {
343 case QPalette::Inactive:
345 case QPalette::Disabled:
347 default:
349 }
351 switch (state) {
352 case QPalette::Inactive:
354 case QPalette::Disabled:
356 default:
358 }
359 default:
360 switch (state) {
361 case QPalette::Inactive:
363 case QPalette::Disabled:
365 default:
367 }
368 }
369}
370
371KisTheme::KisTheme(QObject *parent)
372 : QObject(parent)
373 , m_view(KisThemeColorGroup(KColorScheme::View, this))
374 , m_window(KisThemeColorGroup(KColorScheme::Window, this))
375 , m_button(KisThemeColorGroup(KColorScheme::Button, this))
376 , m_selection(KisThemeColorGroup(KColorScheme::Selection, this))
377 , m_tooltip(KisThemeColorGroup(KColorScheme::Tooltip, this))
378{
380}
381
383{
384 return &this->m_view;
385}
386
388{
389 return &this->m_window;
390}
391
393{
394 return &this->m_button;
395}
396
398{
399 return &this->m_selection;
400}
401
403{
404 return &this->m_tooltip;
405}
406
QBrush background(BackgroundRole=NormalBackground) const
QBrush decoration(DecorationRole) const
QColor shade(ShadeRole) const
QBrush foreground(ForegroundRole=NormalText) const
void signalColorThemeChanged(const QString &filename)
static KisConfigNotifier * instance()
QColor visitedLinkColor
Definition KisTheme.h:142
void neutralTextColorChanged()
QColor activeBackgroundColor
Definition KisTheme.h:150
QColor backgroundColor
Definition KisTheme.h:149
QColor negativeTextColor
Definition KisTheme.h:144
void setState(int state)
Definition KisTheme.cpp:70
void activeBackgroundColorChanged()
void backgroundColorChanged()
void visitedLinkColorChanged()
void shadowShadeColorChanged()
void linkBackgroundColorChanged()
KisThemeColorGroup(KColorScheme::ColorSet set=KColorScheme::View, QObject *parent=nullptr)
Definition KisTheme.cpp:59
QColor linkBackgroundColor
Definition KisTheme.h:152
QPalette::ColorGroup m_state
Definition KisTheme.h:243
void midShadeColorChanged()
QColor positiveTextColor
Definition KisTheme.h:146
void lightShadeColorChanged()
const KColorScheme & currentScheme() const
Definition KisTheme.h:235
void positiveTextColorChanged()
void disabledTextColorChanged()
QColor neutralBackgroundColor
Definition KisTheme.h:157
void negativeBackgroundColorChanged()
QColor shadowShadeColor
Definition KisTheme.h:173
QColor positiveBackgroundColor
Definition KisTheme.h:158
void visitedLinkBackgroundColorChanged()
void neutralBackgroundColorChanged()
void positiveBackgroundColorChanged()
QColor visitedLinkBackgroundColor
Definition KisTheme.h:154
QColor negativeBackgroundColor
Definition KisTheme.h:156
void midLightShadeColorChanged()
void darkShadeColorChanged()
QColor darkShadeColor
Definition KisTheme.h:172
QColor alternateBackgroundColor
Definition KisTheme.h:161
void activeTextColorChanged()
void alternateBackgroundColorChanged()
void negativeTextColorChanged()
QColor lightShadeColor
Definition KisTheme.h:169
QColor activeTextColor
Definition KisTheme.h:139
QColor disabledTextColor
Definition KisTheme.h:138
static const KColorScheme & scheme(KColorScheme::ColorSet set, QPalette::ColorGroup state)
Definition KisTheme.cpp:320
QColor neutralTextColor
Definition KisTheme.h:145
QColor midLightShadeColor
Definition KisTheme.h:170
KColorScheme m_viewInactive
Definition KisTheme.h:114
const KColorScheme & selectionDisabled() const
Definition KisTheme.h:81
const KColorScheme & windowActive() const
Definition KisTheme.h:41
KColorScheme m_tooltipInactive
Definition KisTheme.h:126
const KColorScheme & buttonInactive() const
Definition KisTheme.h:61
KColorScheme m_windowInactive
Definition KisTheme.h:117
const KColorScheme & selectionActive() const
Definition KisTheme.h:71
KColorScheme m_selectionInactive
Definition KisTheme.h:123
const KColorScheme & windowDisabled() const
Definition KisTheme.h:51
void sigThemeChanged()
void updateSchemes()
Definition KisTheme.cpp:38
const KColorScheme & buttonActive() const
Definition KisTheme.h:56
const KColorScheme & selectionInactive() const
Definition KisTheme.h:76
KColorScheme m_selectionActive
Definition KisTheme.h:122
KColorScheme m_viewDisabled
Definition KisTheme.h:115
const KColorScheme & windowInactive() const
Definition KisTheme.h:46
KColorScheme m_buttonInactive
Definition KisTheme.h:120
void slotSetFilename(const QString &filename)
Definition KisTheme.cpp:19
KColorScheme m_viewActive
Definition KisTheme.h:113
KColorScheme m_selectionDisabled
Definition KisTheme.h:124
const KColorScheme & viewDisabled() const
Definition KisTheme.h:36
KColorScheme m_windowDisabled
Definition KisTheme.h:118
QString m_filename
Definition KisTheme.h:112
static const KisThemeConfig * instance()
Definition KisTheme.cpp:10
KColorScheme m_buttonDisabled
Definition KisTheme.h:121
const KColorScheme & buttonDisabled() const
Definition KisTheme.h:66
KColorScheme m_buttonActive
Definition KisTheme.h:119
const KColorScheme & viewInactive() const
Definition KisTheme.h:31
KColorScheme m_tooltipActive
Definition KisTheme.h:125
const KColorScheme & tooltipInactive() const
Definition KisTheme.h:91
const KColorScheme & tooltipDisabled() const
Definition KisTheme.h:96
const KColorScheme & viewActive() const
Definition KisTheme.h:26
const KColorScheme & tooltipActive() const
Definition KisTheme.h:86
KisThemeConfig(QObject *parent=nullptr)
Definition KisTheme.cpp:27
KColorScheme m_tooltipDisabled
Definition KisTheme.h:127
KColorScheme m_windowActive
Definition KisTheme.h:116
KisThemeColorGroup m_button
Definition KisTheme.h:279
KisTheme(QObject *parent=nullptr)
Definition KisTheme.cpp:371
FINALKisThemeColorGroup * selection
Definition KisTheme.h:260
KisThemeColorGroup m_view
Definition KisTheme.h:277
KisThemeColorGroup m_selection
Definition KisTheme.h:280
FINALKisThemeColorGroup * window
Definition KisTheme.h:258
FINALKisThemeColorGroup * button
Definition KisTheme.h:259
FINALKisThemeColorGroup * tooltip
Definition KisTheme.h:261
KisThemeColorGroup * view
Definition KisTheme.h:257
KisThemeColorGroup m_window
Definition KisTheme.h:278
KisThemeColorGroup m_tooltip
Definition KisTheme.h:281
void slotUpdateThemes()
Definition KisTheme.cpp:407
Definition View.h:25