1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
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 Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QPALETTE_H |
43 | #define QPALETTE_H |
44 | |
45 | #include <QtGui/qwindowdefs.h> |
46 | #include <QtGui/qcolor.h> |
47 | #include <QtGui/qbrush.h> |
48 | |
49 | QT_BEGIN_HEADER |
50 | |
51 | QT_BEGIN_NAMESPACE |
52 | |
53 | QT_MODULE(Gui) |
54 | |
55 | #ifdef QT3_SUPPORT |
56 | class QColorGroup; |
57 | #endif |
58 | class QPalettePrivate; |
59 | class QVariant; |
60 | |
61 | class Q_GUI_EXPORT QPalette |
62 | { |
63 | Q_GADGET |
64 | Q_ENUMS(ColorGroup ColorRole) |
65 | public: |
66 | QPalette(); |
67 | QPalette(const QColor &button); |
68 | QPalette(Qt::GlobalColor button); |
69 | QPalette(const QColor &button, const QColor &window); |
70 | QPalette(const QBrush &windowText, const QBrush &button, const QBrush &light, |
71 | const QBrush &dark, const QBrush &mid, const QBrush &text, |
72 | const QBrush &bright_text, const QBrush &base, const QBrush &window); |
73 | QPalette(const QColor &windowText, const QColor &window, const QColor &light, |
74 | const QColor &dark, const QColor &mid, const QColor &text, const QColor &base); |
75 | #ifdef QT3_SUPPORT |
76 | QT3_SUPPORT_CONSTRUCTOR QPalette(const QColorGroup &active, const QColorGroup &disabled, const QColorGroup &inactive); |
77 | #endif |
78 | QPalette(const QPalette &palette); |
79 | ~QPalette(); |
80 | QPalette &operator=(const QPalette &palette); |
81 | #ifdef Q_COMPILER_RVALUE_REFS |
82 | inline QPalette &operator=(QPalette &&other) |
83 | { |
84 | resolve_mask = other.resolve_mask; |
85 | current_group = other.current_group; |
86 | qSwap(d, other.d); return *this; |
87 | } |
88 | #endif |
89 | operator QVariant() const; |
90 | |
91 | // Do not change the order, the serialization format depends on it |
92 | enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active }; |
93 | enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid, |
94 | Text, BrightText, ButtonText, Base, Window, Shadow, |
95 | Highlight, HighlightedText, |
96 | Link, LinkVisited, // ### Qt 5: remove |
97 | AlternateBase, |
98 | NoRole, // ### Qt 5: value should be 0 or -1 |
99 | ToolTipBase, ToolTipText, |
100 | NColorRoles = ToolTipText + 1, |
101 | Foreground = WindowText, Background = Window // ### Qt 5: remove |
102 | }; |
103 | |
104 | inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(current_group); } |
105 | inline void setCurrentColorGroup(ColorGroup cg) { current_group = cg; } |
106 | |
107 | inline const QColor &color(ColorGroup cg, ColorRole cr) const |
108 | { return brush(cg, cr).color(); } |
109 | const QBrush &brush(ColorGroup cg, ColorRole cr) const; |
110 | inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color); |
111 | inline void setColor(ColorRole cr, const QColor &color); |
112 | inline void setBrush(ColorRole cr, const QBrush &brush); |
113 | bool isBrushSet(ColorGroup cg, ColorRole cr) const; |
114 | void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush); |
115 | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
116 | const QBrush &light, const QBrush &dark, const QBrush &mid, |
117 | const QBrush &text, const QBrush &bright_text, const QBrush &base, |
118 | const QBrush &window); |
119 | bool isEqual(ColorGroup cr1, ColorGroup cr2) const; |
120 | |
121 | inline const QColor &color(ColorRole cr) const { return color(Current, cr); } |
122 | inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); } |
123 | inline const QBrush &foreground() const { return brush(WindowText); } |
124 | inline const QBrush &windowText() const { return brush(WindowText); } |
125 | inline const QBrush &button() const { return brush(Button); } |
126 | inline const QBrush &light() const { return brush(Light); } |
127 | inline const QBrush &dark() const { return brush(Dark); } |
128 | inline const QBrush &mid() const { return brush(Mid); } |
129 | inline const QBrush &text() const { return brush(Text); } |
130 | inline const QBrush &base() const { return brush(Base); } |
131 | inline const QBrush &alternateBase() const { return brush(AlternateBase); } |
132 | inline const QBrush &toolTipBase() const { return brush(ToolTipBase); } |
133 | inline const QBrush &toolTipText() const { return brush(ToolTipText); } |
134 | inline const QBrush &background() const { return brush(Window); } |
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 | |
145 | #ifdef QT3_SUPPORT |
146 | inline QT3_SUPPORT QPalette copy() const { QPalette p = *this; p.detach(); return p; } |
147 | QT3_SUPPORT QColorGroup normal() const; |
148 | inline QT3_SUPPORT void setNormal(const QColorGroup &cg) { setColorGroup(Active, cg); } |
149 | |
150 | QT3_SUPPORT QColorGroup active() const; |
151 | QT3_SUPPORT QColorGroup disabled() const; |
152 | QT3_SUPPORT QColorGroup inactive() const; |
153 | inline QT3_SUPPORT void setActive(const QColorGroup &cg) { setColorGroup(Active, cg); } |
154 | inline QT3_SUPPORT void setDisabled(const QColorGroup &cg) { setColorGroup(Disabled, cg); } |
155 | inline QT3_SUPPORT void setInactive(const QColorGroup &cg) { setColorGroup(Inactive, cg); } |
156 | #endif |
157 | |
158 | bool operator==(const QPalette &p) const; |
159 | inline bool operator!=(const QPalette &p) const { return !(operator==(p)); } |
160 | bool isCopyOf(const QPalette &p) const; |
161 | |
162 | int serialNumber() const; |
163 | qint64 cacheKey() const; |
164 | |
165 | QPalette resolve(const QPalette &) const; |
166 | inline uint resolve() const { return resolve_mask; } |
167 | inline void resolve(uint mask) { resolve_mask = mask; } |
168 | |
169 | private: |
170 | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
171 | const QBrush &light, const QBrush &dark, const QBrush &mid, |
172 | const QBrush &text, const QBrush &bright_text, |
173 | const QBrush &base, const QBrush &alternate_base, |
174 | const QBrush &window, const QBrush &midlight, |
175 | const QBrush &button_text, const QBrush &shadow, |
176 | const QBrush &highlight, const QBrush &highlighted_text, |
177 | const QBrush &link, const QBrush &link_visited); |
178 | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
179 | const QBrush &light, const QBrush &dark, const QBrush &mid, |
180 | const QBrush &text, const QBrush &bright_text, |
181 | const QBrush &base, const QBrush &alternate_base, |
182 | const QBrush &window, const QBrush &midlight, |
183 | const QBrush &button_text, const QBrush &shadow, |
184 | const QBrush &highlight, const QBrush &highlighted_text, |
185 | const QBrush &link, const QBrush &link_visited, |
186 | const QBrush &toolTipBase, const QBrush &toolTipText); |
187 | #ifdef QT3_SUPPORT |
188 | friend class QColorGroup; |
189 | void setColorGroup(ColorGroup, const QColorGroup &); |
190 | QColorGroup createColorGroup(ColorGroup) const; |
191 | #endif |
192 | void init(); |
193 | void detach(); |
194 | |
195 | QPalettePrivate *d; |
196 | uint current_group : 4; |
197 | uint resolve_mask : 28; |
198 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p); |
199 | }; |
200 | |
201 | inline void QPalette::setColor(ColorGroup acg, ColorRole acr, |
202 | const QColor &acolor) |
203 | { setBrush(acg, acr, QBrush(acolor)); } |
204 | inline void QPalette::setColor(ColorRole acr, const QColor &acolor) |
205 | { setColor(All, acr, acolor); } |
206 | inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush) |
207 | { setBrush(All, acr, abrush); } |
208 | |
209 | #ifdef QT3_SUPPORT |
210 | class Q_GUI_EXPORT QColorGroup : public QPalette |
211 | { |
212 | public: |
213 | inline QColorGroup() : QPalette() {} |
214 | inline QColorGroup(const QBrush &foreground, const QBrush &button, const QBrush &light, |
215 | const QBrush &dark, const QBrush &mid, const QBrush &text, |
216 | const QBrush &bright_text, const QBrush &base, const QBrush &background) |
217 | : QPalette(foreground, button, light, dark, mid, text, bright_text, base, background) |
218 | {} |
219 | inline QColorGroup(const QColor &foreground, const QColor &background, const QColor &light, |
220 | const QColor &dark, const QColor &mid, const QColor &text, const QColor &base) |
221 | : QPalette(foreground, background, light, dark, mid, text, base) {} |
222 | inline QColorGroup(const QColorGroup &cg) : QPalette(cg) {} |
223 | inline QColorGroup(const QPalette &pal) : QPalette(pal) {} |
224 | bool operator==(const QColorGroup &other) const; |
225 | inline bool operator!=(const QColorGroup &other) const { return !(operator==(other)); } |
226 | operator QVariant() const; |
227 | |
228 | inline QT3_SUPPORT const QColor &foreground() const { return color(WindowText); } |
229 | inline QT3_SUPPORT const QColor &button() const { return color(Button); } |
230 | inline QT3_SUPPORT const QColor &light() const { return color(Light); } |
231 | inline QT3_SUPPORT const QColor &dark() const { return color(Dark); } |
232 | inline QT3_SUPPORT const QColor &mid() const { return color(Mid); } |
233 | inline QT3_SUPPORT const QColor &text() const { return color(Text); } |
234 | inline QT3_SUPPORT const QColor &base() const { return color(Base); } |
235 | inline QT3_SUPPORT const QColor &background() const { return color(Window); } |
236 | inline QT3_SUPPORT const QColor &midlight() const { return color(Midlight); } |
237 | inline QT3_SUPPORT const QColor &brightText() const { return color(BrightText); } |
238 | inline QT3_SUPPORT const QColor &buttonText() const { return color(ButtonText); } |
239 | inline QT3_SUPPORT const QColor &shadow() const { return color(Shadow); } |
240 | inline QT3_SUPPORT const QColor &highlight() const { return color(Highlight); } |
241 | inline QT3_SUPPORT const QColor &highlightedText() const { return color(HighlightedText); } |
242 | inline QT3_SUPPORT const QColor &link() const { return color(Link); } |
243 | inline QT3_SUPPORT const QColor &linkVisited() const { return color(LinkVisited); } |
244 | }; |
245 | |
246 | #ifndef QT_NO_DATASTREAM |
247 | Q_GUI_EXPORT QT3_SUPPORT QDataStream &operator<<(QDataStream &ds, const QColorGroup &cg); |
248 | Q_GUI_EXPORT QT3_SUPPORT QDataStream &operator>>(QDataStream &ds, QColorGroup &cg); |
249 | #endif |
250 | |
251 | inline QColorGroup QPalette::inactive() const { return createColorGroup(Inactive); } |
252 | inline QColorGroup QPalette::disabled() const { return createColorGroup(Disabled); } |
253 | inline QColorGroup QPalette::active() const { return createColorGroup(Active); } |
254 | inline QColorGroup QPalette::normal() const { return createColorGroup(Active); } |
255 | |
256 | #endif |
257 | |
258 | /***************************************************************************** |
259 | QPalette stream functions |
260 | *****************************************************************************/ |
261 | #ifndef QT_NO_DATASTREAM |
262 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p); |
263 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p); |
264 | #endif // QT_NO_DATASTREAM |
265 | |
266 | QT_END_NAMESPACE |
267 | |
268 | QT_END_HEADER |
269 | |
270 | #endif // QPALETTE_H |
271 | |