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