1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtGui module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QPALETTE_H |
41 | #define QPALETTE_H |
42 | |
43 | #include <QtGui/qtguiglobal.h> |
44 | #include <QtGui/qwindowdefs.h> |
45 | #include <QtGui/qcolor.h> |
46 | #include <QtGui/qbrush.h> |
47 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | |
51 | class QPalettePrivate; |
52 | class QVariant; |
53 | |
54 | class Q_GUI_EXPORT QPalette |
55 | { |
56 | Q_GADGET |
57 | public: |
58 | QPalette(); |
59 | QPalette(const QColor &button); |
60 | QPalette(Qt::GlobalColor button); |
61 | QPalette(const QColor &button, const QColor &window); |
62 | QPalette(const QBrush &windowText, const QBrush &button, const QBrush &light, |
63 | const QBrush &dark, const QBrush &mid, const QBrush &text, |
64 | const QBrush &bright_text, const QBrush &base, const QBrush &window); |
65 | QPalette(const QColor &windowText, const QColor &window, const QColor &light, |
66 | const QColor &dark, const QColor &mid, const QColor &text, const QColor &base); |
67 | QPalette(const QPalette &palette); |
68 | ~QPalette(); |
69 | QPalette &operator=(const QPalette &palette); |
70 | QPalette(QPalette &&other) noexcept |
71 | : d(other.d), data(other.data) |
72 | { other.d = nullptr; } |
73 | inline QPalette &operator=(QPalette &&other) noexcept |
74 | { |
75 | for_faster_swapping_dont_use = other.for_faster_swapping_dont_use; |
76 | qSwap(d, other.d); return *this; |
77 | } |
78 | |
79 | void swap(QPalette &other) noexcept |
80 | { |
81 | qSwap(d, other.d); |
82 | qSwap(for_faster_swapping_dont_use, other.for_faster_swapping_dont_use); |
83 | } |
84 | |
85 | operator QVariant() const; |
86 | |
87 | // Do not change the order, the serialization format depends on it |
88 | enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active }; |
89 | Q_ENUM(ColorGroup) |
90 | enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid, |
91 | Text, BrightText, ButtonText, Base, Window, Shadow, |
92 | Highlight, HighlightedText, |
93 | Link, LinkVisited, |
94 | AlternateBase, |
95 | NoRole, |
96 | ToolTipBase, ToolTipText, |
97 | PlaceholderText, |
98 | NColorRoles = PlaceholderText + 1, |
99 | #if QT_DEPRECATED_SINCE(5, 13) |
100 | Foreground Q_DECL_ENUMERATOR_DEPRECATED_X("Use QPalette::WindowText instead" ) = WindowText, |
101 | Background Q_DECL_ENUMERATOR_DEPRECATED_X("Use QPalette::Window instead" ) = Window |
102 | #endif |
103 | }; |
104 | Q_ENUM(ColorRole) |
105 | |
106 | inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(data.current_group); } |
107 | inline void setCurrentColorGroup(ColorGroup cg) { data.current_group = cg; } |
108 | |
109 | inline const QColor &color(ColorGroup cg, ColorRole cr) const |
110 | { return brush(cg, cr).color(); } |
111 | const QBrush &brush(ColorGroup cg, ColorRole cr) const; |
112 | inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color); |
113 | inline void setColor(ColorRole cr, const QColor &color); |
114 | inline void setBrush(ColorRole cr, const QBrush &brush); |
115 | bool isBrushSet(ColorGroup cg, ColorRole cr) const; |
116 | void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush); |
117 | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
118 | const QBrush &light, const QBrush &dark, const QBrush &mid, |
119 | const QBrush &text, const QBrush &bright_text, const QBrush &base, |
120 | const QBrush &window); |
121 | bool isEqual(ColorGroup cr1, ColorGroup cr2) const; |
122 | |
123 | inline const QColor &color(ColorRole cr) const { return color(Current, cr); } |
124 | inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); } |
125 | inline const QBrush &windowText() const { return brush(WindowText); } |
126 | inline const QBrush &button() const { return brush(Button); } |
127 | inline const QBrush &light() const { return brush(Light); } |
128 | inline const QBrush &dark() const { return brush(Dark); } |
129 | inline const QBrush &mid() const { return brush(Mid); } |
130 | inline const QBrush &text() const { return brush(Text); } |
131 | inline const QBrush &base() const { return brush(Base); } |
132 | inline const QBrush &alternateBase() const { return brush(AlternateBase); } |
133 | inline const QBrush &toolTipBase() const { return brush(ToolTipBase); } |
134 | inline const QBrush &toolTipText() const { return brush(ToolTipText); } |
135 | inline const QBrush &window() const { return brush(Window); } |
136 | inline const QBrush &midlight() const { return brush(Midlight); } |
137 | inline const QBrush &brightText() const { return brush(BrightText); } |
138 | inline const QBrush &buttonText() const { return brush(ButtonText); } |
139 | inline const QBrush &shadow() const { return brush(Shadow); } |
140 | inline const QBrush &highlight() const { return brush(Highlight); } |
141 | inline const QBrush &highlightedText() const { return brush(HighlightedText); } |
142 | inline const QBrush &link() const { return brush(Link); } |
143 | inline const QBrush &linkVisited() const { return brush(LinkVisited); } |
144 | inline const QBrush &placeholderText() const { return brush(PlaceholderText); } |
145 | #if QT_DEPRECATED_SINCE(5, 13) |
146 | QT_DEPRECATED_X("Use QPalette::windowText() instead" ) |
147 | inline const QBrush &foreground() const { return windowText(); } |
148 | QT_DEPRECATED_X("Use QPalette::window() instead" ) |
149 | inline const QBrush &background() const { return window(); } |
150 | #endif |
151 | |
152 | bool operator==(const QPalette &p) const; |
153 | inline bool operator!=(const QPalette &p) const { return !(operator==(p)); } |
154 | bool isCopyOf(const QPalette &p) const; |
155 | |
156 | #if QT_DEPRECATED_SINCE(5, 0) |
157 | QT_DEPRECATED inline int serialNumber() const { return cacheKey() >> 32; } |
158 | #endif |
159 | qint64 cacheKey() const; |
160 | |
161 | QPalette resolve(const QPalette &) const; |
162 | inline uint resolve() const { return data.resolve_mask; } |
163 | inline void resolve(uint mask) { data.resolve_mask = mask; } |
164 | |
165 | private: |
166 | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
167 | const QBrush &light, const QBrush &dark, const QBrush &mid, |
168 | const QBrush &text, const QBrush &bright_text, |
169 | const QBrush &base, const QBrush &alternate_base, |
170 | const QBrush &window, const QBrush &midlight, |
171 | const QBrush &button_text, const QBrush &shadow, |
172 | const QBrush &highlight, const QBrush &highlighted_text, |
173 | const QBrush &link, const QBrush &link_visited); |
174 | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
175 | const QBrush &light, const QBrush &dark, const QBrush &mid, |
176 | const QBrush &text, const QBrush &bright_text, |
177 | const QBrush &base, const QBrush &alternate_base, |
178 | const QBrush &window, const QBrush &midlight, |
179 | const QBrush &button_text, const QBrush &shadow, |
180 | const QBrush &highlight, const QBrush &highlighted_text, |
181 | const QBrush &link, const QBrush &link_visited, |
182 | const QBrush &toolTipBase, const QBrush &toolTipText); |
183 | void init(); |
184 | void detach(); |
185 | |
186 | QPalettePrivate *d; |
187 | struct Data { |
188 | uint current_group : 4; |
189 | uint resolve_mask : 28; |
190 | }; |
191 | union { |
192 | Data data; |
193 | quint32 for_faster_swapping_dont_use; |
194 | }; |
195 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p); |
196 | }; |
197 | |
198 | Q_DECLARE_SHARED(QPalette) |
199 | |
200 | inline void QPalette::setColor(ColorGroup acg, ColorRole acr, |
201 | const QColor &acolor) |
202 | { setBrush(acg, acr, QBrush(acolor)); } |
203 | inline void QPalette::setColor(ColorRole acr, const QColor &acolor) |
204 | { setColor(All, acr, acolor); } |
205 | inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush) |
206 | { setBrush(All, acr, abrush); } |
207 | |
208 | /***************************************************************************** |
209 | QPalette stream functions |
210 | *****************************************************************************/ |
211 | #ifndef QT_NO_DATASTREAM |
212 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p); |
213 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p); |
214 | #endif // QT_NO_DATASTREAM |
215 | |
216 | #ifndef QT_NO_DEBUG_STREAM |
217 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &); |
218 | #endif |
219 | |
220 | QT_END_NAMESPACE |
221 | |
222 | #endif // QPALETTE_H |
223 | |