KConfigWidgets

kstatefulbrush.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Matthew Woehlke <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "kstatefulbrush.h"
8 
9 #include "kcolorschemehelpers_p.h"
10 
11 #if KCONFIGWIDGETS_BUILD_DEPRECATED_SINCE(5, 84)
12 #include <QWidget>
13 #endif
14 
15 #include <array>
16 
17 class KStatefulBrushPrivate
18 {
19 public:
20  std::array<QBrush, QPalette::NColorGroups> brushes;
21 };
22 
24  : d(std::make_unique<KStatefulBrushPrivate>())
25 {
26 }
27 
29 
31  : KStatefulBrush()
32 {
33  d->brushes[QPalette::Active] = KColorScheme(QPalette::Active, set, config).foreground(role);
34  d->brushes[QPalette::Disabled] = KColorScheme(QPalette::Disabled, set, config).foreground(role);
35  d->brushes[QPalette::Inactive] = KColorScheme(QPalette::Inactive, set, config).foreground(role);
36 }
37 
39  : KStatefulBrush()
40 
41 {
42  d->brushes[QPalette::Active] = KColorScheme(QPalette::Active, set, config).background(role);
43  d->brushes[QPalette::Disabled] = KColorScheme(QPalette::Disabled, set, config).background(role);
44  d->brushes[QPalette::Inactive] = KColorScheme(QPalette::Inactive, set, config).background(role);
45 }
46 
48  : KStatefulBrush()
49 {
50  d->brushes[QPalette::Active] = KColorScheme(QPalette::Active, set, config).decoration(role);
51  d->brushes[QPalette::Disabled] = KColorScheme(QPalette::Disabled, set, config).decoration(role);
52  d->brushes[QPalette::Inactive] = KColorScheme(QPalette::Inactive, set, config).decoration(role);
53 }
54 
55 KStatefulBrush::KStatefulBrush(const QBrush &brush, KSharedConfigPtr config)
56  : KStatefulBrush()
57 {
58  if (!config) {
59  config = defaultConfig();
60  }
61  d->brushes[QPalette::Active] = brush;
62  d->brushes[QPalette::Disabled] = StateEffects(QPalette::Disabled, config).brush(brush);
63  d->brushes[QPalette::Inactive] = StateEffects(QPalette::Inactive, config).brush(brush);
64 }
65 
66 KStatefulBrush::KStatefulBrush(const QBrush &brush, const QBrush &background, KSharedConfigPtr config)
67  : KStatefulBrush()
68 {
69  if (!config) {
70  config = defaultConfig();
71  }
72  d->brushes[QPalette::Active] = brush;
73  d->brushes[QPalette::Disabled] = StateEffects(QPalette::Disabled, config).brush(brush, background);
74  d->brushes[QPalette::Inactive] = StateEffects(QPalette::Inactive, config).brush(brush, background);
75 }
76 
78  : KStatefulBrush()
79 {
80  d->brushes[QPalette::Active] = other.d->brushes[QPalette::Active];
81  d->brushes[QPalette::Disabled] = other.d->brushes[QPalette::Disabled];
82  d->brushes[QPalette::Inactive] = other.d->brushes[QPalette::Inactive];
83 }
84 
86 {
87  d->brushes[QPalette::Active] = other.d->brushes[QPalette::Active];
88  d->brushes[QPalette::Disabled] = other.d->brushes[QPalette::Disabled];
89  d->brushes[QPalette::Inactive] = other.d->brushes[QPalette::Inactive];
90  return *this;
91 }
92 
94 {
95  if (state >= QPalette::Active && state < QPalette::NColorGroups) {
96  return d->brushes[state];
97  } else {
98  return d->brushes[QPalette::Active];
99  }
100 }
101 
103 {
104  return brush(pal.currentColorGroup());
105 }
106 
107 #if KCONFIGWIDGETS_BUILD_DEPRECATED_SINCE(5, 84)
109 {
110  if (widget) {
111  return brush(widget->palette());
112  } else {
113  return QBrush();
114  }
115 }
116 #endif
KStatefulBrush & operator=(const KStatefulBrush &)
Standard assignment operator.
KStatefulBrush()
Construct a "default" stateful brush.
QBrush background(BackgroundRole=NormalBackground) const
Retrieve the requested background brush.
ForegroundRole
This enumeration describes the foreground color being selected from the given set.
Definition: kcolorscheme.h:209
~KStatefulBrush()
Destructor.
QPalette::ColorGroup currentColorGroup() const const
ColorSet
This enumeration describes the color set for which a color is being selected.
Definition: kcolorscheme.h:65
QBrush foreground(ForegroundRole=NormalText) const
Retrieve the requested foreground brush.
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.
BackgroundRole
This enumeration describes the background color being selected from the given set.
Definition: kcolorscheme.h:135
QBrush brush(QPalette::ColorGroup) const
Retrieve the brush for the specified widget state.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:54:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.