/src/qtbase/src/gui/kernel/qpalette.h
Line | Count | Source |
1 | | // Copyright (C) 2016 The Qt Company Ltd. |
2 | | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | | // Qt-Security score:significant reason:default |
4 | | |
5 | | #ifndef QPALETTE_H |
6 | | #define QPALETTE_H |
7 | | |
8 | | #include <QtGui/qtguiglobal.h> |
9 | | #include <QtGui/qwindowdefs.h> |
10 | | #include <QtGui/qcolor.h> |
11 | | #include <QtGui/qbrush.h> |
12 | | |
13 | | QT_BEGIN_NAMESPACE |
14 | | |
15 | | |
16 | | class QPalettePrivate; |
17 | | class QVariant; |
18 | | |
19 | | class Q_GUI_EXPORT QPalette |
20 | | { |
21 | | Q_GADGET |
22 | | public: |
23 | | QPalette(); |
24 | | QPalette(const QColor &button); |
25 | | QPalette(Qt::GlobalColor button); |
26 | | QPalette(const QColor &button, const QColor &window); |
27 | | QPalette(const QBrush &windowText, const QBrush &button, const QBrush &light, |
28 | | const QBrush &dark, const QBrush &mid, const QBrush &text, |
29 | | const QBrush &bright_text, const QBrush &base, const QBrush &window); |
30 | | QPalette(const QColor &windowText, const QColor &window, const QColor &light, |
31 | | const QColor &dark, const QColor &mid, const QColor &text, const QColor &base); |
32 | | QPalette(const QPalette &palette); |
33 | | ~QPalette(); |
34 | | QPalette &operator=(const QPalette &palette); |
35 | | QPalette(QPalette &&other) noexcept |
36 | 0 | : d(std::exchange(other.d, nullptr)), currentGroup(other.currentGroup) |
37 | 0 | {} |
38 | 0 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPalette) |
39 | 0 |
|
40 | 0 | void swap(QPalette &other) noexcept |
41 | 0 | { |
42 | 0 | std::swap(currentGroup, other.currentGroup); |
43 | 0 | qt_ptr_swap(d, other.d); |
44 | 0 | } |
45 | | |
46 | | operator QVariant() const; |
47 | | |
48 | | // Do not change the order, the serialization format depends on it |
49 | | // Ensure these values are kept in sync with QQuickColorGroup's properties |
50 | | // and QCss::KnownValue! |
51 | | enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active }; |
52 | 0 | Q_ENUM(ColorGroup) Unexecuted instantiation: qt_getEnumMetaObject(QPalette::ColorGroup) Unexecuted instantiation: qt_getEnumName(QPalette::ColorGroup) |
53 | 0 | enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid, |
54 | 0 | Text, BrightText, ButtonText, Base, Window, Shadow, |
55 | 0 | Highlight, HighlightedText, |
56 | 0 | Link, LinkVisited, |
57 | 0 | AlternateBase, |
58 | 0 | NoRole, |
59 | 0 | ToolTipBase, ToolTipText, |
60 | 0 | PlaceholderText, |
61 | 0 | Accent, |
62 | 0 | NColorRoles = Accent + 1, |
63 | 0 | }; |
64 | 0 | Q_ENUM(ColorRole) Unexecuted instantiation: qt_getEnumMetaObject(QPalette::ColorRole) Unexecuted instantiation: qt_getEnumName(QPalette::ColorRole) |
65 | 0 |
|
66 | 0 | inline ColorGroup currentColorGroup() const { return currentGroup; } |
67 | 0 | inline void setCurrentColorGroup(ColorGroup cg) { currentGroup = cg; } |
68 | | |
69 | | inline const QColor &color(ColorGroup cg, ColorRole cr) const |
70 | 282k | { return brush(cg, cr).color(); } |
71 | | const QBrush &brush(ColorGroup cg, ColorRole cr) const; |
72 | | inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color); |
73 | | inline void setColor(ColorRole cr, const QColor &color); |
74 | | inline void setBrush(ColorRole cr, const QBrush &brush); |
75 | | bool isBrushSet(ColorGroup cg, ColorRole cr) const; |
76 | | void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush); |
77 | | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
78 | | const QBrush &light, const QBrush &dark, const QBrush &mid, |
79 | | const QBrush &text, const QBrush &bright_text, const QBrush &base, |
80 | | const QBrush &window); |
81 | | bool isEqual(ColorGroup cr1, ColorGroup cr2) const; |
82 | | |
83 | 0 | inline const QColor &color(ColorRole cr) const { return color(Current, cr); } |
84 | 188k | inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); } |
85 | 0 | inline const QBrush &windowText() const { return brush(WindowText); } |
86 | 0 | inline const QBrush &button() const { return brush(Button); } |
87 | 0 | inline const QBrush &light() const { return brush(Light); } |
88 | 0 | inline const QBrush &dark() const { return brush(Dark); } |
89 | 0 | inline const QBrush &mid() const { return brush(Mid); } |
90 | 94.1k | inline const QBrush &text() const { return brush(Text); } |
91 | 94.1k | inline const QBrush &base() const { return brush(Base); } |
92 | 0 | inline const QBrush &alternateBase() const { return brush(AlternateBase); } |
93 | 0 | inline const QBrush &toolTipBase() const { return brush(ToolTipBase); } |
94 | 0 | inline const QBrush &toolTipText() const { return brush(ToolTipText); } |
95 | 0 | inline const QBrush &window() const { return brush(Window); } |
96 | 0 | inline const QBrush &midlight() const { return brush(Midlight); } |
97 | 0 | inline const QBrush &brightText() const { return brush(BrightText); } |
98 | 0 | inline const QBrush &buttonText() const { return brush(ButtonText); } |
99 | 0 | inline const QBrush &shadow() const { return brush(Shadow); } |
100 | 0 | inline const QBrush &highlight() const { return brush(Highlight); } |
101 | 0 | inline const QBrush &highlightedText() const { return brush(HighlightedText); } |
102 | 0 | inline const QBrush &link() const { return brush(Link); } |
103 | 0 | inline const QBrush &linkVisited() const { return brush(LinkVisited); } |
104 | 0 | inline const QBrush &placeholderText() const { return brush(PlaceholderText); } |
105 | 0 | inline const QBrush &accent() const { return brush(Accent); } |
106 | | |
107 | | bool operator==(const QPalette &p) const; |
108 | 0 | inline bool operator!=(const QPalette &p) const { return !(operator==(p)); } |
109 | | bool isCopyOf(const QPalette &p) const; |
110 | | |
111 | | qint64 cacheKey() const; |
112 | | |
113 | | QPalette resolve(const QPalette &other) const; |
114 | | |
115 | | using ResolveMask = quint64; |
116 | | ResolveMask resolveMask() const; |
117 | | void setResolveMask(ResolveMask mask); |
118 | | |
119 | | private: |
120 | | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
121 | | const QBrush &light, const QBrush &dark, const QBrush &mid, |
122 | | const QBrush &text, const QBrush &bright_text, |
123 | | const QBrush &base, const QBrush &alternate_base, |
124 | | const QBrush &window, const QBrush &midlight, |
125 | | const QBrush &button_text, const QBrush &shadow, |
126 | | const QBrush &highlight, const QBrush &highlighted_text, |
127 | | const QBrush &link, const QBrush &link_visited); |
128 | | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
129 | | const QBrush &light, const QBrush &dark, const QBrush &mid, |
130 | | const QBrush &text, const QBrush &bright_text, |
131 | | const QBrush &base, const QBrush &alternate_base, |
132 | | const QBrush &window, const QBrush &midlight, |
133 | | const QBrush &button_text, const QBrush &shadow, |
134 | | const QBrush &highlight, const QBrush &highlighted_text, |
135 | | const QBrush &link, const QBrush &link_visited, |
136 | | const QBrush &toolTipBase, const QBrush &toolTipText); |
137 | | void init(); |
138 | | void detach(); |
139 | | |
140 | | QPalettePrivate *d; |
141 | | ColorGroup currentGroup{Active}; |
142 | | |
143 | | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p); |
144 | | }; |
145 | | |
146 | 0 | Q_DECLARE_SHARED(QPalette) |
147 | 0 |
|
148 | 0 | inline void QPalette::setColor(ColorGroup acg, ColorRole acr, |
149 | 0 | const QColor &acolor) |
150 | 282k | { setBrush(acg, acr, QBrush(acolor)); } |
151 | | inline void QPalette::setColor(ColorRole acr, const QColor &acolor) |
152 | 0 | { setColor(All, acr, acolor); } |
153 | | inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush) |
154 | 470k | { setBrush(All, acr, abrush); } |
155 | | |
156 | | /***************************************************************************** |
157 | | QPalette stream functions |
158 | | *****************************************************************************/ |
159 | | #ifndef QT_NO_DATASTREAM |
160 | | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p); |
161 | | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p); |
162 | | #endif // QT_NO_DATASTREAM |
163 | | |
164 | | #ifndef QT_NO_DEBUG_STREAM |
165 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &); |
166 | | #endif |
167 | | |
168 | | QT_END_NAMESPACE |
169 | | |
170 | | #endif // QPALETTE_H |