KConfigWidgets

kcolorscheme.cpp
1 /*
2  This file is part of the KDE project
3  SPDX-FileCopyrightText: 2007 Matthew Woehlke <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "kcolorscheme.h"
9 #include "kcolorschemehelpers_p.h"
10 
11 #include "kconfigwidgets_debug.h"
12 
13 #include <KColorUtils>
14 #include <KConfig>
15 #include <KConfigGroup>
16 
17 #include <QBrush>
18 #include <QColor>
19 
20 // BEGIN StateEffects
21 StateEffects::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 
53 QBrush 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 
81 QBrush 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
100 struct 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 
113 struct 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)
121 static 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 
134 static 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 
147 static 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 
160 static 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 
173 static 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 
186 static 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 
199 static 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 
212 static 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
220 class KColorSchemePrivate : public QSharedData
221 {
222 public:
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 
247 static 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 
268 static 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 
276 KColorSchemePrivate::KColorSchemePrivate(const KSharedConfigPtr &config, QPalette::ColorGroup state, KColorScheme::ColorSet set)
277 {
278  const char *groupName = nullptr;
279  SerializedColors defaultColors;
280  DecorationColors defaultDecoColors = defaultDecorationColors;
281  QBrush tint;
282  switch (set) {
284  groupName = "Colors:Window";
285  defaultColors = defaultWindowColors;
286  break;
288  groupName = "Colors:Button";
289  defaultColors = defaultButtonColors;
290  break;
292  const KConfigGroup inactiveEffectGroup(config, "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 = "Colors:Selection";
299  defaultColors = defaultSelectionColors;
300  } else if (state == QPalette::Inactive) {
301  groupName = "Colors:Window";
302  defaultColors = defaultWindowColors;
303  tint = KColorSchemePrivate(config, QPalette::Active, KColorScheme::Selection)._brushes.bg[KColorScheme::NormalBackground];
304  } else { // disabled (...and still want this branch when inactive+disabled exists)
305  groupName = "Colors:Window";
306  defaultColors = defaultWindowColors;
307  }
308  } break;
310  groupName = "Colors:Tooltip";
311  defaultColors = defaultTooltipColors;
312  break;
314  groupName = "Colors:Complementary";
315  defaultColors = defaultComplementaryColors;
316  break;
318  groupName = "Colors:Header";
319  defaultColors = loadSerializedColors(config->group("Colors:Window"), defaultHeaderColors);
320  defaultDecoColors = loadDecorationColors(config->group("Colors:Window"), defaultDecorationColors);
321  break;
323  qCWarning(KCONFIG_WIDGETS_LOG) << "ColorSet::NColorSets is not a valid color set value to pass to KColorScheme::KColorScheme";
324  [[fallthrough]];
325  case KColorScheme::View:
326  groupName = "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, "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 != Qt::NoBrush) {
362  // adjustment
363  _brushes.bg[KColorScheme::NormalBackground] =
364  KColorUtils::tint(_brushes.bg[KColorScheme::NormalBackground].color(), tint.color(), 0.4);
365  _brushes.bg[KColorScheme::AlternateBackground] =
366  KColorUtils::tint(_brushes.bg[KColorScheme::AlternateBackground].color(), tint.color(), 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());
389  _brushes.bg[KColorScheme::VisitedBackground] =
391  _brushes.fg[KColorScheme::VisitedText].color());
392  _brushes.bg[KColorScheme::NegativeBackground] =
394  _brushes.fg[KColorScheme::NegativeText].color());
395  _brushes.bg[KColorScheme::NeutralBackground] =
397  _brushes.fg[KColorScheme::NeutralText].color());
398  _brushes.bg[KColorScheme::PositiveBackground] =
400  _brushes.fg[KColorScheme::PositiveText].color());
401 }
402 
403 QBrush KColorSchemePrivate::background(KColorScheme::BackgroundRole role) const
404 {
406  return _brushes.bg[role];
407  } else {
408  return _brushes.bg[KColorScheme::NormalBackground];
409  }
410 }
411 
412 QBrush KColorSchemePrivate::foreground(KColorScheme::ForegroundRole role) const
413 {
415  return _brushes.fg[role];
416  } else {
417  return _brushes.fg[KColorScheme::NormalText];
418  }
419 }
420 
421 QBrush KColorSchemePrivate::decoration(KColorScheme::DecorationRole role) const
422 {
424  return _brushes.deco[role];
425  } else {
426  return _brushes.deco[KColorScheme::FocusColor];
427  }
428 }
429 
430 qreal KColorSchemePrivate::contrast() const
431 {
432  return _contrast;
433 }
434 //END KColorSchemePrivate
435 
436 //BEGIN KColorScheme
437 KColorScheme::KColorScheme(const KColorScheme &) = default;
438 KColorScheme &KColorScheme::operator=(const KColorScheme &) = default;
439 KColorScheme::KColorScheme(KColorScheme &&) = default;
440 KColorScheme &KColorScheme::operator=(KColorScheme &&) = default;
441 KColorScheme::~KColorScheme() = default;
442 
443 KColorScheme::KColorScheme(QPalette::ColorGroup state, ColorSet set, KSharedConfigPtr config)
444  : d(new KColorSchemePrivate(config ? config : defaultConfig(), state, set))
445 {
446 }
447 
448 bool KColorScheme::operator==(const KColorScheme &other) const
449 {
450  return d == other.d
451  || (d->_contrast == other.d->_contrast
452  && d->_brushes == other.d->_brushes)
453  ;
454 }
455 
456 // static
457 #if KCONFIGWIDGETS_BUILD_DEPRECATED_SINCE(5, 93)
459 {
460  KConfigGroup g(defaultConfig(), "KDE");
461  return g.readEntry("contrast", 7);
462 }
463 #endif
464 
465 // static
466 qreal KColorScheme::contrastF(const KSharedConfigPtr &config)
467 {
468  KConfigGroup g(config ? config : defaultConfig(), "KDE");
469  return 0.1 * g.readEntry("contrast", 7);
470 }
471 
473 {
474  return d->background(role);
475 }
476 
478 {
479  return d->foreground(role);
480 }
481 
483 {
484  return d->decoration(role);
485 }
486 
488 {
489  return shade(background().color(), role, d->contrast());
490 }
491 
493 {
494  return shade(color, role, KColorScheme::contrastF());
495 }
496 
497 QColor KColorScheme::shade(const QColor &color, ShadeRole role, qreal contrast, qreal chromaAdjust)
498 {
499  // nan -> 1.0
500  contrast = (1.0 > contrast ? (-1.0 < contrast ? contrast : -1.0) : 1.0);
501  qreal y = KColorUtils::luma(color);
502  qreal yi = 1.0 - y;
503 
504  // handle very dark colors (base, mid, dark, shadow == midlight, light)
505  if (y < 0.006) {
506  switch (role) {
508  return KColorUtils::shade(color, 0.05 + 0.95 * contrast, chromaAdjust);
510  return KColorUtils::shade(color, 0.01 + 0.20 * contrast, chromaAdjust);
512  return KColorUtils::shade(color, 0.02 + 0.40 * contrast, chromaAdjust);
513  default:
514  return KColorUtils::shade(color, 0.03 + 0.60 * contrast, chromaAdjust);
515  }
516  }
517 
518  // handle very light colors (base, midlight, light == mid, dark, shadow)
519  if (y > 0.93) {
520  switch (role) {
522  return KColorUtils::shade(color, -0.02 - 0.20 * contrast, chromaAdjust);
524  return KColorUtils::shade(color, -0.06 - 0.60 * contrast, chromaAdjust);
526  return KColorUtils::shade(color, -0.10 - 0.90 * contrast, chromaAdjust);
527  default:
528  return KColorUtils::shade(color, -0.04 - 0.40 * contrast, chromaAdjust);
529  }
530  }
531 
532  // handle everything else
533  qreal lightAmount = (0.05 + y * 0.55) * (0.25 + contrast * 0.75);
534  qreal darkAmount = (- y) * (0.55 + contrast * 0.35);
535  switch (role) {
537  return KColorUtils::shade(color, lightAmount, chromaAdjust);
539  return KColorUtils::shade(color, (0.15 + 0.35 * yi) * lightAmount, chromaAdjust);
541  return KColorUtils::shade(color, (0.35 + 0.15 * y) * darkAmount, chromaAdjust);
543  return KColorUtils::shade(color, darkAmount, chromaAdjust);
544  default:
545  return KColorUtils::darken(KColorUtils::shade(color, darkAmount, chromaAdjust), 0.5 + 0.3 * y);
546  }
547 }
548 
550  ColorSet set, KSharedConfigPtr config)
551 {
552  palette.setBrush(QPalette::Active, color, KColorScheme(QPalette::Active, set, config).background(newRole));
555 }
556 
558  ColorSet set, KSharedConfigPtr config)
559 {
560  palette.setBrush(QPalette::Active, color, KColorScheme(QPalette::Active, set, config).foreground(newRole));
563 }
564 
565 bool KColorScheme::isColorSetSupported(const KSharedConfigPtr &config, KColorScheme::ColorSet set)
566 {
567  switch (set) {
568  case View:
569  return config->hasGroup("Colors:View");
570  case Window:
571  return config->hasGroup("Colors:Window");
572  case Button:
573  return config->hasGroup("Colors:Button");
574  case Selection:
575  return config->hasGroup("Colors:Selection");
576  case Tooltip:
577  return config->hasGroup("Colors:Tooltip");
578  case Complementary:
579  return config->hasGroup("Colors:Complementary");
580  case Header:
581  return config->hasGroup("Colors:Header");
582  case NColorSets:
583  break;
584  }
585 
586  return false;
587 }
588 
589 QPalette KColorScheme::createApplicationPalette(const KSharedConfigPtr &config)
590 {
591  QPalette palette;
592 
593  static const QPalette::ColorGroup states[QPalette::NColorGroups] = {
595  };
596 
597  // TT thinks tooltips shouldn't use active, so we use our active colors for all states
599 
600  for (auto state : states) {
601  KColorScheme schemeView(state, KColorScheme::View, config);
602  KColorScheme schemeWindow(state, KColorScheme::Window, config);
603  KColorScheme schemeButton(state, KColorScheme::Button, config);
604  KColorScheme schemeSelection(state, KColorScheme::Selection, config);
605 
606  palette.setBrush(state, QPalette::WindowText, schemeWindow.foreground());
607  palette.setBrush(state, QPalette::Window, schemeWindow.background());
608  palette.setBrush(state, QPalette::Base, schemeView.background());
609  palette.setBrush(state, QPalette::Text, schemeView.foreground());
610  palette.setBrush(state, QPalette::Button, schemeButton.background());
611  palette.setBrush(state, QPalette::ButtonText, schemeButton.foreground());
612  palette.setBrush(state, QPalette::Highlight, schemeSelection.background());
613  palette.setBrush(state, QPalette::HighlightedText, schemeSelection.foreground());
614  palette.setBrush(state, QPalette::ToolTipBase, schemeTooltip.background());
615  palette.setBrush(state, QPalette::ToolTipText, schemeTooltip.foreground());
616 
617  palette.setColor(state, QPalette::Light, schemeWindow.shade(KColorScheme::LightShade));
618  palette.setColor(state, QPalette::Midlight, schemeWindow.shade(KColorScheme::MidlightShade));
619  palette.setColor(state, QPalette::Mid, schemeWindow.shade(KColorScheme::MidShade));
620  palette.setColor(state, QPalette::Dark, schemeWindow.shade(KColorScheme::DarkShade));
621  palette.setColor(state, QPalette::Shadow, schemeWindow.shade(KColorScheme::ShadowShade));
622 
624  palette.setBrush(state, QPalette::Link, schemeView.foreground(KColorScheme::LinkText));
626  }
627 
628  return palette;
629 }
630 
631 //END KColorScheme
const QColor & color() const const
@ VisitedText
Fifth color; used for (visited) links.
Definition: kcolorscheme.h:239
QString readEntry(const char *key, const char *aDefault=nullptr) const
@ MidShade
The mid color is in between base() and dark().
Definition: kcolorscheme.h:308
@ MidlightShade
The midlight color is in between base() and light().
Definition: kcolorscheme.h:304
KGUIADDONS_EXPORT qreal luma(const QColor &)
@ NeutralBackground
Seventh color; for example, warnings, secure/encrypted content.
Definition: kcolorscheme.h:181
@ Selection
Selected items in views.
Definition: kcolorscheme.h:93
KGUIADDONS_EXPORT QColor mix(const QColor &c1, const QColor &c2, qreal bias=0.5)
@ NormalText
Normal foreground.
Definition: kcolorscheme.h:213
@ NegativeBackground
Sixth color; for example, errors, untrusted content, etc.
Definition: kcolorscheme.h:177
KGUIADDONS_EXPORT QColor darken(const QColor &, qreal amount=0.5, qreal chromaGain=1.0)
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.
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 ...
@ Header
Colors for header areas that should be used both by the top toolbar and the titlebar.
Definition: kcolorscheme.h:117
@ Window
Non-editable window elements; for example, menus.
Definition: kcolorscheme.h:77
@ DarkShade
The dark color is in between mid() and shadow().
Definition: kcolorscheme.h:312
@ ActiveText
Third color; for example items which are new, active, requesting attention, etc.
Definition: kcolorscheme.h:225
KGUIADDONS_EXPORT QColor tint(const QColor &base, const QColor &color, qreal amount=0.3)
@ PositiveBackground
Eighth color; for example, success messages, trusted content.
Definition: kcolorscheme.h:185
@ LinkText
Fourth color; use for (unvisited) links.
Definition: kcolorscheme.h:231
bool exists() const
bool operator==(const KColorScheme &other) const
@ NBackgroundRoles
Number of background roles.
Definition: kcolorscheme.h:190
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
@ NeutralText
Seventh color; for example, warnings, secure/encrypted content.
Definition: kcolorscheme.h:248
KGUIADDONS_EXPORT QColor lighten(const QColor &, qreal amount=0.5, qreal chromaInverseGain=1.0)
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 ...
@ NColorSets
Number of color sets.
Definition: kcolorscheme.h:123
@ ShadowShade
The shadow color is darker than light() or midlight() and contrasts the base color.
Definition: kcolorscheme.h:317
@ FocusColor
Color used to draw decorations for items which have input focus.
Definition: kcolorscheme.h:274
bool isEmpty() const const
ForegroundRole
This enumeration describes the foreground color being selected from the given set.
Definition: kcolorscheme.h:209
@ PositiveText
Eighth color; for example, additions, success messages, trusted content.
Definition: kcolorscheme.h:253
void setBrush(QPalette::ColorRole role, const QBrush &brush)
virtual ~KColorScheme()
Destructor.
@ NormalBackground
Normal background.
Definition: kcolorscheme.h:139
ShadeRole
This enumeration describes the color shade being selected from the given set.
Definition: kcolorscheme.h:295
KSharedConfigPtr config()
ColorSet
This enumeration describes the color set for which a color is being selected.
Definition: kcolorscheme.h:65
@ NForegroundRoles
Number of foreground roles.
Definition: kcolorscheme.h:258
@ AlternateBackground
Alternate background; for example, for use in lists.
Definition: kcolorscheme.h:146
QBrush foreground(ForegroundRole=NormalText) const
Retrieve the requested foreground brush.
void setColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QColor &color)
@ Button
Buttons and button-like controls.
Definition: kcolorscheme.h:85
@ Tooltip
Tooltips.
Definition: kcolorscheme.h:102
@ InactiveText
Second color; for example, comments, items which are old, inactive or disabled.
Definition: kcolorscheme.h:220
@ LightShade
The light color is lighter than dark() or shadow() and contrasts with the base color.
Definition: kcolorscheme.h:300
KGuiItem defaults()
QColor shade(ShadeRole) const
Retrieve the requested shade color, using KColorScheme::background(KColorScheme::NormalBackground) as...
@ VisitedBackground
Fifth color; corresponds to visited links.
Definition: kcolorscheme.h:173
@ LinkBackground
Fourth color; corresponds to (unvisited) links.
Definition: kcolorscheme.h:165
static QPalette createApplicationPalette(const KSharedConfigPtr &config)
Used to obtain the QPalette that will be used to set the application palette from KDE Platform theme.
DecorationRole
This enumeration describes the decoration color being selected from the given set.
Definition: kcolorscheme.h:270
QBrush decoration(DecorationRole) const
Retrieve the requested decoration brush.
@ View
Views; for example, frames, input fields, etc.
Definition: kcolorscheme.h:71
KGUIADDONS_EXPORT QColor shade(const QColor &, qreal lumaAmount, qreal chromaAmount=0.0)
static int contrast()
Returns the contrast for borders.
@ NDecorationRoles
Number of decoration roles.
Definition: kcolorscheme.h:284
static qreal contrastF(const KSharedConfigPtr &config=KSharedConfigPtr())
Returns the contrast for borders as a floating point value.
@ Complementary
Complementary areas.
Definition: kcolorscheme.h:112
BackgroundRole
This enumeration describes the background color being selected from the given set.
Definition: kcolorscheme.h:135
@ NegativeText
Sixth color; for example, errors, untrusted content, deletions, etc.
Definition: kcolorscheme.h:244
@ HoverColor
Color used to draw decorations for items which will be activated by clicking.
Definition: kcolorscheme.h:279
@ ActiveBackground
Third color; for example, items which are new, active, requesting attention, etc.
Definition: kcolorscheme.h:156
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Sep 30 2023 04:11:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.