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 | #ifdef Q_COMPILER_RVALUE_REFS |
71 | QPalette(QPalette &&other) Q_DECL_NOTHROW |
72 | : d(other.d), data(other.data) |
73 | { other.d = nullptr; } |
74 | inline QPalette &operator=(QPalette &&other) Q_DECL_NOEXCEPT |
75 | { |
76 | for_faster_swapping_dont_use = other.for_faster_swapping_dont_use; |
77 | qSwap(d, other.d); return *this; |
78 | } |
79 | #endif |
80 | |
81 | void swap(QPalette &other) Q_DECL_NOEXCEPT |
82 | { |
83 | qSwap(d, other.d); |
84 | qSwap(for_faster_swapping_dont_use, other.for_faster_swapping_dont_use); |
85 | } |
86 | |
87 | operator QVariant() const; |
88 | |
89 | // Do not change the order, the serialization format depends on it |
90 | enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active }; |
91 | Q_ENUM(ColorGroup) |
92 | enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid, |
93 | Text, BrightText, ButtonText, Base, Window, Shadow, |
94 | Highlight, HighlightedText, |
95 | Link, LinkVisited, |
96 | AlternateBase, |
97 | NoRole, |
98 | ToolTipBase, ToolTipText, |
99 | PlaceholderText, |
100 | NColorRoles = PlaceholderText + 1, |
101 | Foreground = WindowText, Background = Window |
102 | }; |
103 | Q_ENUM(ColorRole) |
104 | |
105 | inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(data.current_group); } |
106 | inline void setCurrentColorGroup(ColorGroup cg) { data.current_group = cg; } |
107 | |
108 | inline const QColor &color(ColorGroup cg, ColorRole cr) const |
109 | { return brush(cg, cr).color(); } |
110 | const QBrush &brush(ColorGroup cg, ColorRole cr) const; |
111 | inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color); |
112 | inline void setColor(ColorRole cr, const QColor &color); |
113 | inline void setBrush(ColorRole cr, const QBrush &brush); |
114 | bool isBrushSet(ColorGroup cg, ColorRole cr) const; |
115 | void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush); |
116 | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
117 | const QBrush &light, const QBrush &dark, const QBrush &mid, |
118 | const QBrush &text, const QBrush &bright_text, const QBrush &base, |
119 | const QBrush &window); |
120 | bool isEqual(ColorGroup cr1, ColorGroup cr2) const; |
121 | |
122 | inline const QColor &color(ColorRole cr) const { return color(Current, cr); } |
123 | inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); } |
124 | inline const QBrush &foreground() const { return brush(WindowText); } |
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 &background() const { return brush(Window); } |
136 | inline const QBrush &window() const { return brush(Window); } |
137 | inline const QBrush &midlight() const { return brush(Midlight); } |
138 | inline const QBrush &brightText() const { return brush(BrightText); } |
139 | inline const QBrush &buttonText() const { return brush(ButtonText); } |
140 | inline const QBrush &shadow() const { return brush(Shadow); } |
141 | inline const QBrush &highlight() const { return brush(Highlight); } |
142 | inline const QBrush &highlightedText() const { return brush(HighlightedText); } |
143 | inline const QBrush &link() const { return brush(Link); } |
144 | inline const QBrush &linkVisited() const { return brush(LinkVisited); } |
145 | inline const QBrush &placeholderText() const { return brush(PlaceholderText); } |
146 | |
147 | bool operator==(const QPalette &p) const; |
148 | inline bool operator!=(const QPalette &p) const { return !(operator==(p)); } |
149 | bool isCopyOf(const QPalette &p) const; |
150 | |
151 | #if QT_DEPRECATED_SINCE(5, 0) |
152 | QT_DEPRECATED inline int serialNumber() const { return cacheKey() >> 32; } |
153 | #endif |
154 | qint64 cacheKey() const; |
155 | |
156 | QPalette resolve(const QPalette &) const; |
157 | inline uint resolve() const { return data.resolve_mask; } |
158 | inline void resolve(uint mask) { data.resolve_mask = mask; } |
159 | |
160 | private: |
161 | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
162 | const QBrush &light, const QBrush &dark, const QBrush &mid, |
163 | const QBrush &text, const QBrush &bright_text, |
164 | const QBrush &base, const QBrush &alternate_base, |
165 | const QBrush &window, const QBrush &midlight, |
166 | const QBrush &button_text, const QBrush &shadow, |
167 | const QBrush &highlight, const QBrush &highlighted_text, |
168 | const QBrush &link, const QBrush &link_visited); |
169 | void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, |
170 | const QBrush &light, const QBrush &dark, const QBrush &mid, |
171 | const QBrush &text, const QBrush &bright_text, |
172 | const QBrush &base, const QBrush &alternate_base, |
173 | const QBrush &window, const QBrush &midlight, |
174 | const QBrush &button_text, const QBrush &shadow, |
175 | const QBrush &highlight, const QBrush &highlighted_text, |
176 | const QBrush &link, const QBrush &link_visited, |
177 | const QBrush &toolTipBase, const QBrush &toolTipText); |
178 | void init(); |
179 | void detach(); |
180 | |
181 | QPalettePrivate *d; |
182 | struct Data { |
183 | uint current_group : 4; |
184 | uint resolve_mask : 28; |
185 | }; |
186 | union { |
187 | Data data; |
188 | quint32 for_faster_swapping_dont_use; |
189 | }; |
190 | friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p); |
191 | }; |
192 | |
193 | Q_DECLARE_SHARED(QPalette) |
194 | |
195 | inline void QPalette::setColor(ColorGroup acg, ColorRole acr, |
196 | const QColor &acolor) |
197 | { setBrush(acg, acr, QBrush(acolor)); } |
198 | inline void QPalette::setColor(ColorRole acr, const QColor &acolor) |
199 | { setColor(All, acr, acolor); } |
200 | inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush) |
201 | { setBrush(All, acr, abrush); } |
202 | |
203 | /***************************************************************************** |
204 | QPalette stream functions |
205 | *****************************************************************************/ |
206 | #ifndef QT_NO_DATASTREAM |
207 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p); |
208 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p); |
209 | #endif // QT_NO_DATASTREAM |
210 | |
211 | #ifndef QT_NO_DEBUG_STREAM |
212 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &); |
213 | #endif |
214 | |
215 | QT_END_NAMESPACE |
216 | |
217 | #endif // QPALETTE_H |
218 | |