1 | /* |
2 | SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef KCOLORSCHEME_P_H |
8 | #define KCOLORSCHEME_P_H |
9 | |
10 | #include <KSharedConfig> |
11 | |
12 | #include <QCoreApplication> |
13 | #include <QPalette> |
14 | |
15 | #include <array> |
16 | |
17 | #ifdef Q_OS_WIN |
18 | #include "windows.h" |
19 | #endif |
20 | |
21 | #ifdef Q_OS_WIN |
22 | static bool isHighContrastModeActive() |
23 | { |
24 | HIGHCONTRAST result; |
25 | result.cbSize = sizeof(HIGHCONTRAST); |
26 | if (SystemParametersInfo(SPI_GETHIGHCONTRAST, result.cbSize, &result, 0)) { |
27 | return (result.dwFlags & HCF_HIGHCONTRASTON); |
28 | } |
29 | return false; |
30 | } |
31 | #endif |
32 | |
33 | static KSharedConfigPtr defaultConfig() |
34 | { |
35 | // cache the value we'll return, since usually it's going to be the same value |
36 | static thread_local KSharedConfigPtr config; |
37 | // Read from the application's color scheme file (as set by KColorSchemeManager). |
38 | // If unset, this is equivalent to openConfig() and the system scheme is used. |
39 | const auto colorSchemePath = qApp->property(name: "KDE_COLOR_SCHEME_PATH" ).toString(); |
40 | #ifdef Q_OS_WIN |
41 | // If no color scheme is set and high-contrast is active then use the system colors |
42 | if (colorSchemePath.isEmpty() && isHighContrastModeActive()) { |
43 | return {}; |
44 | } |
45 | #endif |
46 | if (!config || config->name() != colorSchemePath) { |
47 | config = KSharedConfig::openConfig(fileName: colorSchemePath); |
48 | } |
49 | return config; |
50 | } |
51 | |
52 | class StateEffects |
53 | { |
54 | public: |
55 | explicit StateEffects(QPalette::ColorGroup state, const KSharedConfigPtr &); |
56 | ~StateEffects() |
57 | { |
58 | } |
59 | |
60 | QBrush brush(const QBrush &background) const; |
61 | QBrush brush(const QBrush &foreground, const QBrush &background) const; |
62 | |
63 | private: |
64 | enum EffectTypes { |
65 | Intensity, |
66 | Color, |
67 | Contrast, |
68 | NEffectTypes, |
69 | }; |
70 | |
71 | enum IntensityEffects { |
72 | IntensityNoEffect, |
73 | IntensityShade, |
74 | IntensityDarken, |
75 | IntensityLighten, |
76 | NIntensityEffects, |
77 | }; |
78 | |
79 | enum ColorEffects { |
80 | ColorNoEffect, |
81 | ColorDesaturate, |
82 | ColorFade, |
83 | ColorTint, |
84 | NColorEffects, |
85 | }; |
86 | |
87 | enum ContrastEffects { |
88 | ContrastNoEffect, |
89 | ContrastFade, |
90 | ContrastTint, |
91 | NContrastEffects, |
92 | }; |
93 | |
94 | int _effects[NEffectTypes]; |
95 | double _amount[NEffectTypes]; |
96 | QColor _color; |
97 | }; |
98 | |
99 | #endif |
100 | |