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
48QT_BEGIN_NAMESPACE
49
50
51class QPalettePrivate;
52class QVariant;
53
54class Q_GUI_EXPORT QPalette
55{
56 Q_GADGET
57public:
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#if QT_DEPRECATED_SINCE(5, 13)
102 Foreground Q_DECL_ENUMERATOR_DEPRECATED_X("Use QPalette::WindowText instead") = WindowText,
103 Background Q_DECL_ENUMERATOR_DEPRECATED_X("Use QPalette::Window instead") = Window
104#endif
105 };
106 Q_ENUM(ColorRole)
107
108 inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(data.current_group); }
109 inline void setCurrentColorGroup(ColorGroup cg) { data.current_group = cg; }
110
111 inline const QColor &color(ColorGroup cg, ColorRole cr) const
112 { return brush(cg, cr).color(); }
113 const QBrush &brush(ColorGroup cg, ColorRole cr) const;
114 inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color);
115 inline void setColor(ColorRole cr, const QColor &color);
116 inline void setBrush(ColorRole cr, const QBrush &brush);
117 bool isBrushSet(ColorGroup cg, ColorRole cr) const;
118 void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush);
119 void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
120 const QBrush &light, const QBrush &dark, const QBrush &mid,
121 const QBrush &text, const QBrush &bright_text, const QBrush &base,
122 const QBrush &window);
123 bool isEqual(ColorGroup cr1, ColorGroup cr2) const;
124
125 inline const QColor &color(ColorRole cr) const { return color(Current, cr); }
126 inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); }
127 inline const QBrush &windowText() const { return brush(WindowText); }
128 inline const QBrush &button() const { return brush(Button); }
129 inline const QBrush &light() const { return brush(Light); }
130 inline const QBrush &dark() const { return brush(Dark); }
131 inline const QBrush &mid() const { return brush(Mid); }
132 inline const QBrush &text() const { return brush(Text); }
133 inline const QBrush &base() const { return brush(Base); }
134 inline const QBrush &alternateBase() const { return brush(AlternateBase); }
135 inline const QBrush &toolTipBase() const { return brush(ToolTipBase); }
136 inline const QBrush &toolTipText() const { return brush(ToolTipText); }
137 inline const QBrush &window() const { return brush(Window); }
138 inline const QBrush &midlight() const { return brush(Midlight); }
139 inline const QBrush &brightText() const { return brush(BrightText); }
140 inline const QBrush &buttonText() const { return brush(ButtonText); }
141 inline const QBrush &shadow() const { return brush(Shadow); }
142 inline const QBrush &highlight() const { return brush(Highlight); }
143 inline const QBrush &highlightedText() const { return brush(HighlightedText); }
144 inline const QBrush &link() const { return brush(Link); }
145 inline const QBrush &linkVisited() const { return brush(LinkVisited); }
146 inline const QBrush &placeholderText() const { return brush(PlaceholderText); }
147#if QT_DEPRECATED_SINCE(5, 13)
148 QT_DEPRECATED_X("Use QPalette::windowText() instead")
149 inline const QBrush &foreground() const { return windowText(); }
150 QT_DEPRECATED_X("Use QPalette::window() instead")
151 inline const QBrush &background() const { return window(); }
152#endif
153
154 bool operator==(const QPalette &p) const;
155 inline bool operator!=(const QPalette &p) const { return !(operator==(p)); }
156 bool isCopyOf(const QPalette &p) const;
157
158#if QT_DEPRECATED_SINCE(5, 0)
159 QT_DEPRECATED inline int serialNumber() const { return cacheKey() >> 32; }
160#endif
161 qint64 cacheKey() const;
162
163 QPalette resolve(const QPalette &) const;
164 inline uint resolve() const { return data.resolve_mask; }
165 inline void resolve(uint mask) { data.resolve_mask = mask; }
166
167private:
168 void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
169 const QBrush &light, const QBrush &dark, const QBrush &mid,
170 const QBrush &text, const QBrush &bright_text,
171 const QBrush &base, const QBrush &alternate_base,
172 const QBrush &window, const QBrush &midlight,
173 const QBrush &button_text, const QBrush &shadow,
174 const QBrush &highlight, const QBrush &highlighted_text,
175 const QBrush &link, const QBrush &link_visited);
176 void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
177 const QBrush &light, const QBrush &dark, const QBrush &mid,
178 const QBrush &text, const QBrush &bright_text,
179 const QBrush &base, const QBrush &alternate_base,
180 const QBrush &window, const QBrush &midlight,
181 const QBrush &button_text, const QBrush &shadow,
182 const QBrush &highlight, const QBrush &highlighted_text,
183 const QBrush &link, const QBrush &link_visited,
184 const QBrush &toolTipBase, const QBrush &toolTipText);
185 void init();
186 void detach();
187
188 QPalettePrivate *d;
189 struct Data {
190 uint current_group : 4;
191 uint resolve_mask : 28;
192 };
193 union {
194 Data data;
195 quint32 for_faster_swapping_dont_use;
196 };
197 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
198};
199
200Q_DECLARE_SHARED(QPalette)
201
202inline void QPalette::setColor(ColorGroup acg, ColorRole acr,
203 const QColor &acolor)
204{ setBrush(acg, acr, QBrush(acolor)); }
205inline void QPalette::setColor(ColorRole acr, const QColor &acolor)
206{ setColor(All, acr, acolor); }
207inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush)
208{ setBrush(All, acr, abrush); }
209
210/*****************************************************************************
211 QPalette stream functions
212 *****************************************************************************/
213#ifndef QT_NO_DATASTREAM
214Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p);
215Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p);
216#endif // QT_NO_DATASTREAM
217
218#ifndef QT_NO_DEBUG_STREAM
219Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &);
220#endif
221
222QT_END_NAMESPACE
223
224#endif // QPALETTE_H
225