KColorScheme

kcolorscheme.cpp
1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "kcolorscheme.h"
9#include "kcolorschemehelpers_p.h"
10
11#include "kcolorscheme_debug.h"
12
13#include <KColorUtils>
14#include <KConfig>
15#include <KConfigGroup>
16
17#include <QBrush>
18#include <QColor>
19
20// BEGIN StateEffects
21StateEffects::StateEffects(QPalette::ColorGroup state, const KSharedConfigPtr &config)
22 : _color(0, 0, 0, 0) //, _chain(0) not needed yet
23{
24 QString group;
25 if (state == QPalette::Disabled) {
26 group = QStringLiteral("ColorEffects:Disabled");
27 } else if (state == QPalette::Inactive) {
28 group = QStringLiteral("ColorEffects:Inactive");
29 }
30
31 for (auto &effect : _effects) {
32 effect = 0;
33 }
34
35 // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp
36 if (!group.isEmpty()) {
37 KConfigGroup cfg(config, group);
38 const bool enabledByDefault = (state == QPalette::Disabled);
39 if (cfg.readEntry("Enable", enabledByDefault)) {
40 _effects[Intensity] = cfg.readEntry("IntensityEffect", (int)(state == QPalette::Disabled ? IntensityDarken : IntensityNoEffect));
41 _effects[Color] = cfg.readEntry("ColorEffect", (int)(state == QPalette::Disabled ? ColorNoEffect : ColorDesaturate));
42 _effects[Contrast] = cfg.readEntry("ContrastEffect", (int)(state == QPalette::Disabled ? ContrastFade : ContrastTint));
43 _amount[Intensity] = cfg.readEntry("IntensityAmount", state == QPalette::Disabled ? 0.10 : 0.0);
44 _amount[Color] = cfg.readEntry("ColorAmount", state == QPalette::Disabled ? 0.0 : -0.9);
45 _amount[Contrast] = cfg.readEntry("ContrastAmount", state == QPalette::Disabled ? 0.65 : 0.25);
46 if (_effects[Color] > ColorNoEffect) {
47 _color = cfg.readEntry("Color", state == QPalette::Disabled ? QColor(56, 56, 56) : QColor(112, 111, 110));
48 }
49 }
50 }
51}
52
53QBrush StateEffects::brush(const QBrush &background) const
54{
55 QColor color = background.color(); // TODO - actually work on brushes
56 switch (_effects[Intensity]) {
57 case IntensityShade:
58 color = KColorUtils::shade(color, _amount[Intensity]);
59 break;
60 case IntensityDarken:
61 color = KColorUtils::darken(color, _amount[Intensity]);
62 break;
63 case IntensityLighten:
64 color = KColorUtils::lighten(color, _amount[Intensity]);
65 break;
66 }
67 switch (_effects[Color]) {
68 case ColorDesaturate:
69 color = KColorUtils::darken(color, 0.0, 1.0 - _amount[Color]);
70 break;
71 case ColorFade:
72 color = KColorUtils::mix(color, _color, _amount[Color]);
73 break;
74 case ColorTint:
75 color = KColorUtils::tint(color, _color, _amount[Color]);
76 break;
77 }
78 return QBrush(color);
79}
80
81QBrush StateEffects::brush(const QBrush &foreground, const QBrush &background) const
82{
83 QColor color = foreground.color(); // TODO - actually work on brushes
84 QColor bg = background.color();
85 // Apply the foreground effects
86 switch (_effects[Contrast]) {
87 case ContrastFade:
88 color = KColorUtils::mix(color, bg, _amount[Contrast]);
89 break;
90 case ContrastTint:
91 color = KColorUtils::tint(color, bg, _amount[Contrast]);
92 break;
93 }
94 // Now apply global effects
95 return brush(color);
96}
97// END StateEffects
98
99// BEGIN default colors
100struct SerializedColors {
101 QColor NormalBackground;
102 QColor AlternateBackground;
103 QColor NormalText;
104 QColor InactiveText;
105 QColor ActiveText;
106 QColor LinkText;
107 QColor VisitedText;
108 QColor NegativeText;
109 QColor NeutralText;
110 QColor PositiveText;
111};
112
113struct DecorationColors {
114 QColor Focus;
115 QColor Hover;
116};
117
118// clang-format off
119// These numbers come from the default color scheme which is currently
120// Breeze Light ([breeze repo]/colors/BreezeLight.colors)
121static const SerializedColors defaultViewColors = {
122 { 255, 255, 255 }, // Background
123 { 247, 247, 247 }, // Alternate
124 { 35, 38, 41 }, // Normal
125 { 112, 125, 138 }, // Inactive
126 { 61, 174, 233 }, // Active
127 { 41, 128, 185 }, // Link
128 { 155, 89, 182 }, // Visited
129 { 218, 68, 83 }, // Negative
130 { 246, 116, 0 }, // Neutral
131 { 39, 174, 96 } // Positive
132};
133
134static const SerializedColors defaultWindowColors = {
135 { 239, 240, 241 }, // Background
136 { 227, 229, 231 }, // Alternate
137 { 35, 38, 41 }, // Normal
138 { 112, 125, 138 }, // Inactive
139 { 61, 174, 233 }, // Active
140 { 41, 128, 185 }, // Link
141 { 155, 89, 182 }, // Visited
142 { 218, 68, 83 }, // Negative
143 { 246, 116, 0 }, // Neutral
144 { 39, 174, 96 } // Positive
145};
146
147static const SerializedColors defaultButtonColors = {
148 { 252, 252, 252 }, // Background
149 { 163, 212, 250 }, // Alternate
150 { 35, 38, 41 }, // Normal
151 { 112, 125, 138 }, // Inactive
152 { 61, 174, 233 }, // Active
153 { 41, 128, 185 }, // Link
154 { 155, 89, 182 }, // Visited
155 { 218, 68, 83 }, // Negative
156 { 246, 116, 0 }, // Neutral
157 { 39, 174, 96 } // Positive
158};
159
160static const SerializedColors defaultSelectionColors = {
161 { 61, 174, 233 }, // Background
162 { 163, 212, 250 }, // Alternate
163 { 255, 255, 255 }, // Normal
164 { 112, 125, 138 }, // Inactive
165 { 255, 255, 255 }, // Active
166 { 253, 188, 75 }, // Link
167 { 155, 89, 182 }, // Visited
168 { 176, 55, 69 }, // Negative
169 { 198, 92, 0 }, // Neutral
170 { 23, 104, 57 } // Positive
171};
172
173static const SerializedColors defaultTooltipColors = {
174 { 247, 247, 247 }, // Background
175 { 239, 240, 241 }, // Alternate
176 { 35, 38, 41 }, // Normal
177 { 112, 125, 138 }, // Inactive
178 { 61, 174, 233 }, // Active
179 { 41, 128, 185 }, // Link
180 { 155, 89, 182 }, // Visited
181 { 218, 68, 83 }, // Negative
182 { 246, 116, 0 }, // Neutral
183 { 39, 174, 96 } // Positive
184};
185
186static const SerializedColors defaultComplementaryColors = {
187 { 42, 46, 50 }, // Background
188 { 27, 30, 32 }, // Alternate
189 { 252, 252, 252 }, // Normal
190 { 161, 169, 177 }, // Inactive
191 { 61, 174, 233 }, // Active
192 { 29, 153, 243 }, // Link
193 { 155, 89, 182 }, // Visited
194 { 218, 68, 83 }, // Negative
195 { 246, 116, 0 }, // Neutral
196 { 39, 174, 96 } // Positive
197};
198
199static const SerializedColors defaultHeaderColors = {
200 { 222, 224, 226 }, // Background
201 { 239, 240, 241 }, // Alternate
202 { 35, 38, 41 }, // Normal
203 { 112, 125, 138 }, // Inactive
204 { 61, 174, 233 }, // Active
205 { 41, 128, 185 }, // Link
206 { 155, 89, 182 }, // Visited
207 { 218, 68, 83 }, // Negative
208 { 246, 116, 0 }, // Neutral
209 { 39, 174, 96 } // Positive
210};
211
212static const DecorationColors defaultDecorationColors = {
213 { 61, 174, 233 }, // Focus
214 { 147, 206, 233 }, // Hover
215};
216// END default colors
217// clang-format off
218
219//BEGIN KColorSchemePrivate
220class KColorSchemePrivate : public QSharedData
221{
222public:
223 explicit KColorSchemePrivate(const KSharedConfigPtr &, QPalette::ColorGroup state, KColorScheme::ColorSet set);
224 ~KColorSchemePrivate()
225 {
226 }
227
228 QBrush background(KColorScheme::BackgroundRole) const;
229 QBrush foreground(KColorScheme::ForegroundRole) const;
230 QBrush decoration(KColorScheme::DecorationRole) const;
231 qreal contrast() const;
232
233 struct Brushes {
234 std::array<QBrush, KColorScheme::NForegroundRoles> fg;
235 std::array<QBrush, KColorScheme::NBackgroundRoles> bg;
236 std::array<QBrush, KColorScheme::NDecorationRoles> deco;
237
238 bool operator==(const Brushes &b) const
239 {
240 return this == &b || (fg == b.fg && bg == b.bg && deco == b.deco);
241 }
242 } _brushes;
243
244 qreal _contrast;
245};
246
247static SerializedColors loadSerializedColors(const KConfigGroup &group, const SerializedColors &defaults)
248{
249 constexpr std::array configMap = {
250 std::pair{"ForegroundNormal", &SerializedColors::NormalText},
251 std::pair{"ForegroundInactive", &SerializedColors::InactiveText},
252 std::pair{"ForegroundActive", &SerializedColors::ActiveText},
253 std::pair{"ForegroundLink", &SerializedColors::LinkText},
254 std::pair{"ForegroundVisited", &SerializedColors::VisitedText},
255 std::pair{"ForegroundNegative", &SerializedColors::NegativeText},
256 std::pair{"ForegroundNeutral", &SerializedColors::NeutralText},
257 std::pair{"ForegroundPositive", &SerializedColors::PositiveText},
258 std::pair{"BackgroundNormal", &SerializedColors::NormalBackground},
259 std::pair{"BackgroundAlternate", &SerializedColors::AlternateBackground},
260 };
261 SerializedColors loadedColors;
262 for (const auto &entry : configMap) {
263 loadedColors.*(entry.second) = group.readEntry(entry.first, defaults.*(entry.second));
264 }
265 return loadedColors;
266}
267
268static DecorationColors loadDecorationColors(const KConfigGroup &group, const DecorationColors &defaults)
269{
270 DecorationColors colors;
271 colors.Focus = group.readEntry("DecorationFocus", defaults.Focus);
272 colors.Hover = group.readEntry("DecorationHover", defaults.Hover);
273 return colors;
274}
275
276KColorSchemePrivate::KColorSchemePrivate(const KSharedConfigPtr &config, QPalette::ColorGroup state, KColorScheme::ColorSet set)
277{
278 QString groupName;
279 SerializedColors defaultColors;
280 DecorationColors defaultDecoColors = defaultDecorationColors;
281 QColor tint;
282 switch (set) {
284 groupName = QStringLiteral("Colors:Window");
285 defaultColors = defaultWindowColors;
286 break;
288 groupName = QStringLiteral("Colors:Button");
289 defaultColors = defaultButtonColors;
290 break;
292 const KConfigGroup inactiveEffectGroup(config, QStringLiteral("ColorEffects:Inactive"));
293 // NOTE: keep this in sync with kdebase/workspace/kcontrol/colors/colorscm.cpp
294 const bool inactiveSelectionEffect = inactiveEffectGroup.readEntry("ChangeSelectionColor", inactiveEffectGroup.readEntry("Enable", true));
295 // if enabled, inactive/disabled uses Window colors instead, ala gtk
296 // ...except tinted with the Selection:NormalBackground color so it looks more like selection
297 if (state == QPalette::Active || (state == QPalette::Inactive && !inactiveSelectionEffect)) {
298 groupName = QStringLiteral("Colors:Selection");
299 defaultColors = defaultSelectionColors;
300 } else if (state == QPalette::Inactive) {
301 groupName = QStringLiteral("Colors:Window");
302 defaultColors = defaultWindowColors;
303 tint = config->group(QStringLiteral("Colors:Selection")).readEntry("BackgroundNormal", defaultSelectionColors.NormalBackground);
304 } else { // disabled (...and still want this branch when inactive+disabled exists)
305 groupName = QStringLiteral("Colors:Window");
306 defaultColors = defaultWindowColors;
307 }
308 } break;
310 groupName = QStringLiteral("Colors:Tooltip");
311 defaultColors = defaultTooltipColors;
312 break;
314 groupName = QStringLiteral("Colors:Complementary");
315 defaultColors = defaultComplementaryColors;
316 break;
318 groupName = QStringLiteral("Colors:Header");
319 defaultColors = loadSerializedColors(config->group(QStringLiteral("Colors:Window")), defaultHeaderColors);
320 defaultDecoColors = loadDecorationColors(config->group(QStringLiteral("Colors:Window")), defaultDecorationColors);
321 break;
323 qCWarning(KCOLORSCHEME) << "ColorSet::NColorSets is not a valid color set value to pass to KColorScheme::KColorScheme";
324 [[fallthrough]];
326 groupName = QStringLiteral("Colors:View");
327 defaultColors = defaultViewColors;
328 break;
329 }
330
331 KConfigGroup cfg(config, groupName);
332 bool hasInactivePalette = false;
333 if (state == QPalette::Inactive) {
334 KConfigGroup inactiveGroup = KConfigGroup(&cfg, QStringLiteral("Inactive"));
335 if (inactiveGroup.exists()) {
336 cfg = inactiveGroup;
337 hasInactivePalette = true;
338 }
339 }
340
341 _contrast = KColorScheme::contrastF(config);
342
343 const SerializedColors loadedColors = loadSerializedColors(cfg, defaultColors);
344 const DecorationColors loadedDecoColors = loadDecorationColors(cfg, defaultDecoColors);
345
346 _brushes.fg[KColorScheme::NormalText] = loadedColors.NormalText;
347 _brushes.fg[KColorScheme::InactiveText] = loadedColors.InactiveText;
348 _brushes.fg[KColorScheme::ActiveText] = loadedColors.ActiveText;
349 _brushes.fg[KColorScheme::LinkText] = loadedColors.LinkText;
350 _brushes.fg[KColorScheme::VisitedText] = loadedColors.VisitedText;
351 _brushes.fg[KColorScheme::NegativeText] = loadedColors.NegativeText;
352 _brushes.fg[KColorScheme::NeutralText] = loadedColors.NeutralText;
353 _brushes.fg[KColorScheme::PositiveText] = loadedColors.PositiveText;
354
355 _brushes.bg[KColorScheme::NormalBackground] = loadedColors.NormalBackground;
356 _brushes.bg[KColorScheme::AlternateBackground] = loadedColors.AlternateBackground;
357
358 _brushes.deco[KColorScheme::FocusColor] = loadedDecoColors.Focus;
359 _brushes.deco[KColorScheme::HoverColor] = loadedDecoColors.Hover;
360
361 if (tint.isValid()) {
362 // adjustment
363 _brushes.bg[KColorScheme::NormalBackground] =
364 KColorUtils::tint(_brushes.bg[KColorScheme::NormalBackground].color(), tint, 0.4);
366 KColorUtils::tint(_brushes.bg[KColorScheme::AlternateBackground].color(), tint, 0.4);
367 }
368
369 // apply state adjustments
370 if (state != QPalette::Active || (state == QPalette::Inactive && !hasInactivePalette)) {
371 StateEffects effects(state, config);
372 for (auto &fg : _brushes.fg) {
373 fg = effects.brush(fg, _brushes.bg[KColorScheme::NormalBackground]);
374 }
375 for (auto &deco : _brushes.deco) {
376 deco = effects.brush(deco, _brushes.bg[KColorScheme::NormalBackground]);
377 }
378 _brushes.bg[KColorScheme::NormalBackground] = effects.brush(_brushes.bg[KColorScheme::NormalBackground]);
379 _brushes.bg[KColorScheme::AlternateBackground] = effects.brush(_brushes.bg[KColorScheme::AlternateBackground]);
380 }
381
382 // calculated backgrounds
383 _brushes.bg[KColorScheme::ActiveBackground] =
385 _brushes.fg[KColorScheme::ActiveText].color());
386 _brushes.bg[KColorScheme::LinkBackground] =
388 _brushes.fg[KColorScheme::LinkText].color());
391 _brushes.fg[KColorScheme::VisitedText].color());
394 _brushes.fg[KColorScheme::NegativeText].color());
397 _brushes.fg[KColorScheme::NeutralText].color());
400 _brushes.fg[KColorScheme::PositiveText].color());
401}
402
403QBrush KColorSchemePrivate::background(KColorScheme::BackgroundRole role) const
404{
406 return _brushes.bg[role];
407 } else {
408 return _brushes.bg[KColorScheme::NormalBackground];
409 }
410}
411
412QBrush KColorSchemePrivate::foreground(KColorScheme::ForegroundRole role) const
413{
415 return _brushes.fg[role];
416 } else {
417 return _brushes.fg[KColorScheme::NormalText];
418 }
419}
420
421QBrush KColorSchemePrivate::decoration(KColorScheme::DecorationRole role) const
422{
424 return _brushes.deco[role];
425 } else {
426 return _brushes.deco[KColorScheme::FocusColor];
427 }
428}
429
430qreal KColorSchemePrivate::contrast() const
431{
432 return _contrast;
433}
434//END KColorSchemePrivate
435
436//BEGIN KColorScheme
437KColorScheme::KColorScheme(const KColorScheme &) = default;
438KColorScheme &KColorScheme::operator=(const KColorScheme &) = default;
439KColorScheme::KColorScheme(KColorScheme &&) = default;
440KColorScheme &KColorScheme::operator=(KColorScheme &&) = default;
442
443KColorScheme::KColorScheme(QPalette::ColorGroup state, ColorSet set, KSharedConfigPtr config)
444 : d(new KColorSchemePrivate(config ? config : defaultConfig(), state, set))
445{
446}
447
449{
450 return d == other.d
451 || (d->_contrast == other.d->_contrast
452 && d->_brushes == other.d->_brushes)
453 ;
454}
455
456// static
457qreal KColorScheme::contrastF(const KSharedConfigPtr &config)
458{
459 KConfigGroup g(config ? config : defaultConfig(), QStringLiteral("KDE"));
460 return 0.1 * g.readEntry("contrast", 7);
461}
462
464{
465 return d->background(role);
466}
467
469{
470 return d->foreground(role);
471}
472
474{
475 return d->decoration(role);
476}
477
479{
480 return shade(background().color(), role, d->contrast());
481}
482
484{
485 return shade(color, role, KColorScheme::contrastF());
486}
487
488QColor KColorScheme::shade(const QColor &color, ShadeRole role, qreal contrast, qreal chromaAdjust)
489{
490 // nan -> 1.0
491 contrast = (1.0 > contrast ? (-1.0 < contrast ? contrast : -1.0) : 1.0);
492 qreal y = KColorUtils::luma(color);
493 qreal yi = 1.0 - y;
494
495 // handle very dark colors (base, mid, dark, shadow == midlight, light)
496 if (y < 0.006) {
497 switch (role) {
499 return KColorUtils::shade(color, 0.05 + 0.95 * contrast, chromaAdjust);
501 return KColorUtils::shade(color, 0.01 + 0.20 * contrast, chromaAdjust);
503 return KColorUtils::shade(color, 0.02 + 0.40 * contrast, chromaAdjust);
504 default:
505 return KColorUtils::shade(color, 0.03 + 0.60 * contrast, chromaAdjust);
506 }
507 }
508
509 // handle very light colors (base, midlight, light == mid, dark, shadow)
510 if (y > 0.93) {
511 switch (role) {
513 return KColorUtils::shade(color, -0.02 - 0.20 * contrast, chromaAdjust);
515 return KColorUtils::shade(color, -0.06 - 0.60 * contrast, chromaAdjust);
517 return KColorUtils::shade(color, -0.10 - 0.90 * contrast, chromaAdjust);
518 default:
519 return KColorUtils::shade(color, -0.04 - 0.40 * contrast, chromaAdjust);
520 }
521 }
522
523 // handle everything else
524 qreal lightAmount = (0.05 + y * 0.55) * (0.25 + contrast * 0.75);
525 qreal darkAmount = (- y) * (0.55 + contrast * 0.35);
526 switch (role) {
528 return KColorUtils::shade(color, lightAmount, chromaAdjust);
530 return KColorUtils::shade(color, (0.15 + 0.35 * yi) * lightAmount, chromaAdjust);
532 return KColorUtils::shade(color, (0.35 + 0.15 * y) * darkAmount, chromaAdjust);
534 return KColorUtils::shade(color, darkAmount, chromaAdjust);
535 default:
536 return KColorUtils::darken(KColorUtils::shade(color, darkAmount, chromaAdjust), 0.5 + 0.3 * y);
537 }
538}
539
541 ColorSet set, KSharedConfigPtr config)
542{
543 palette.setBrush(QPalette::Active, color, KColorScheme(QPalette::Active, set, config).background(newRole));
544 palette.setBrush(QPalette::Inactive, color, KColorScheme(QPalette::Inactive, set, config).background(newRole));
545 palette.setBrush(QPalette::Disabled, color, KColorScheme(QPalette::Disabled, set, config).background(newRole));
546}
547
549 ColorSet set, KSharedConfigPtr config)
550{
551 palette.setBrush(QPalette::Active, color, KColorScheme(QPalette::Active, set, config).foreground(newRole));
552 palette.setBrush(QPalette::Inactive, color, KColorScheme(QPalette::Inactive, set, config).foreground(newRole));
553 palette.setBrush(QPalette::Disabled, color, KColorScheme(QPalette::Disabled, set, config).foreground(newRole));
554}
555
556bool KColorScheme::isColorSetSupported(const KSharedConfigPtr &config, KColorScheme::ColorSet set)
557{
558 switch (set) {
559 case View:
560 return config->hasGroup(QStringLiteral("Colors:View"));
561 case Window:
562 return config->hasGroup(QStringLiteral("Colors:Window"));
563 case Button:
564 return config->hasGroup(QStringLiteral("Colors:Button"));
565 case Selection:
566 return config->hasGroup(QStringLiteral("Colors:Selection"));
567 case Tooltip:
568 return config->hasGroup(QStringLiteral("Colors:Tooltip"));
569 case Complementary:
570 return config->hasGroup(QStringLiteral("Colors:Complementary"));
571 case Header:
572 return config->hasGroup(QStringLiteral("Colors:Header"));
573 case NColorSets:
574 break;
575 }
576
577 return false;
578}
579
581{
582 QPalette palette;
583
584 static const QPalette::ColorGroup states[QPalette::NColorGroups] = {
586 };
587
588 // TT thinks tooltips shouldn't use active, so we use our active colors for all states
590
591 for (auto state : states) {
592 KColorScheme schemeView(state, KColorScheme::View, config);
593 KColorScheme schemeWindow(state, KColorScheme::Window, config);
594 KColorScheme schemeButton(state, KColorScheme::Button, config);
595 KColorScheme schemeSelection(state, KColorScheme::Selection, config);
596
597 palette.setBrush(state, QPalette::WindowText, schemeWindow.foreground());
598 palette.setBrush(state, QPalette::Window, schemeWindow.background());
599 palette.setBrush(state, QPalette::Base, schemeView.background());
600 palette.setBrush(state, QPalette::Text, schemeView.foreground());
601 palette.setBrush(state, QPalette::Button, schemeButton.background());
602 palette.setBrush(state, QPalette::ButtonText, schemeButton.foreground());
603 palette.setBrush(state, QPalette::Highlight, schemeSelection.background());
604 palette.setBrush(state, QPalette::HighlightedText, schemeSelection.foreground());
605 palette.setBrush(state, QPalette::ToolTipBase, schemeTooltip.background());
606 palette.setBrush(state, QPalette::ToolTipText, schemeTooltip.foreground());
608#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
609 palette.setBrush(state, QPalette::Accent, schemeSelection.background());
610#endif
611
612 palette.setColor(state, QPalette::Light, schemeWindow.shade(KColorScheme::LightShade));
613 palette.setColor(state, QPalette::Midlight, schemeWindow.shade(KColorScheme::MidlightShade));
614 palette.setColor(state, QPalette::Mid, schemeWindow.shade(KColorScheme::MidShade));
615 palette.setColor(state, QPalette::Dark, schemeWindow.shade(KColorScheme::DarkShade));
616 palette.setColor(state, QPalette::Shadow, schemeWindow.shade(KColorScheme::ShadowShade));
617
619 palette.setBrush(state, QPalette::Link, schemeView.foreground(KColorScheme::LinkText));
621 }
622
623 return palette;
624}
625
626//END KColorScheme
A set of methods used to work with colors.
static void adjustForeground(QPalette &, ForegroundRole newRole=NormalText, QPalette::ColorRole color=QPalette::Text, ColorSet set=View, KSharedConfigPtr=KSharedConfigPtr())
Adjust a QPalette by replacing the specified QPalette::ColorRole with the requested foreground color ...
ForegroundRole
This enumeration describes the foreground color being selected from the given set.
@ NForegroundRoles
Number of foreground roles.
@ ActiveText
Third color; for example items which are new, active, requesting attention, etc.
@ VisitedText
Fifth color; used for (visited) links.
@ LinkText
Fourth color; use for (unvisited) links.
@ NeutralText
Seventh color; for example, warnings, secure/encrypted content.
@ NormalText
Normal foreground.
@ InactiveText
Second color; for example, comments, items which are old, inactive or disabled.
@ NegativeText
Sixth color; for example, errors, untrusted content, deletions, etc.
@ PositiveText
Eighth color; for example, additions, success messages, trusted content.
static QPalette createApplicationPalette(const KSharedConfigPtr &config)
Used to obtain the QPalette that will be used to set the application palette from KDE Platform theme.
bool operator==(const KColorScheme &other) const
ShadeRole
This enumeration describes the color shade being selected from the given set.
@ MidlightShade
The midlight color is in between base() and light().
@ DarkShade
The dark color is in between mid() and shadow().
@ LightShade
The light color is lighter than dark() or shadow() and contrasts with the base color.
@ ShadowShade
The shadow color is darker than light() or midlight() and contrasts the base color.
@ MidShade
The mid color is in between base() and dark().
BackgroundRole
This enumeration describes the background color being selected from the given set.
@ PositiveBackground
Eighth color; for example, success messages, trusted content.
@ NeutralBackground
Seventh color; for example, warnings, secure/encrypted content.
@ AlternateBackground
Alternate background; for example, for use in lists.
@ NormalBackground
Normal background.
@ VisitedBackground
Fifth color; corresponds to visited links.
@ NBackgroundRoles
Number of background roles.
@ ActiveBackground
Third color; for example, items which are new, active, requesting attention, etc.
@ NegativeBackground
Sixth color; for example, errors, untrusted content, etc.
@ LinkBackground
Fourth color; corresponds to (unvisited) links.
ColorSet
This enumeration describes the color set for which a color is being selected.
@ Header
Colors for header areas that should be used both by the top toolbar and the titlebar.
@ Complementary
Complementary areas.
@ Tooltip
Tooltips.
@ NColorSets
Number of color sets.
@ View
Views; for example, frames, input fields, etc.
@ Window
Non-editable window elements; for example, menus.
@ Selection
Selected items in views.
@ Button
Buttons and button-like controls.
static qreal contrastF(const KSharedConfigPtr &config=KSharedConfigPtr())
Returns the contrast for borders as a floating point value.
static bool isColorSetSupported(const KSharedConfigPtr &config, KColorScheme::ColorSet set)
Used to check if the color scheme has a given set.
QBrush background(BackgroundRole=NormalBackground) const
Retrieve the requested background brush.
DecorationRole
This enumeration describes the decoration color being selected from the given set.
@ HoverColor
Color used to draw decorations for items which will be activated by clicking.
@ NDecorationRoles
Number of decoration roles.
@ FocusColor
Color used to draw decorations for items which have input focus.
static void adjustBackground(QPalette &, BackgroundRole newRole=NormalBackground, QPalette::ColorRole color=QPalette::Base, ColorSet set=View, KSharedConfigPtr=KSharedConfigPtr())
Adjust a QPalette by replacing the specified QPalette::ColorRole with the requested background color ...
QBrush decoration(DecorationRole) const
Retrieve the requested decoration brush.
virtual ~KColorScheme()
Destructor.
QColor shade(ShadeRole) const
Retrieve the requested shade color, using KColorScheme::background(KColorScheme::NormalBackground) as...
QBrush foreground(ForegroundRole=NormalText) const
Retrieve the requested foreground brush.
QString readEntry(const char *key, const char *aDefault=nullptr) const
bool exists() const
KGUIADDONS_EXPORT QColor darken(const QColor &, qreal amount=0.5, qreal chromaGain=1.0)
KGUIADDONS_EXPORT qreal luma(const QColor &)
KGUIADDONS_EXPORT QColor shade(const QColor &, qreal lumaAmount, qreal chromaAmount=0.0)
KGUIADDONS_EXPORT QColor mix(const QColor &c1, const QColor &c2, qreal bias=0.5)
KGUIADDONS_EXPORT QColor tint(const QColor &base, const QColor &color, qreal amount=0.3)
KGUIADDONS_EXPORT QColor lighten(const QColor &, qreal amount=0.5, qreal chromaInverseGain=1.0)
KGuiItem defaults()
const QColor & color() const const
bool isValid() const const
void setBrush(ColorGroup group, ColorRole role, const QBrush &brush)
void setColor(ColorGroup group, ColorRole role, const QColor &color)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 10 2024 11:51:55 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.