1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtGui/qwindowdefs.h>
46 #include <QtGui/qcolor.h>
47 #include <QtGui/qbrush.h>
54 class QPalettePrivate;
57 class Q_GUI_EXPORT QPalette
60 Q_ENUMS(ColorGroup ColorRole)
63 QPalette(const QColor &button);
64 QPalette(Qt::GlobalColor button);
65 QPalette(const QColor &button, const QColor &window);
66 QPalette(const QBrush &windowText, const QBrush &button, const QBrush &light,
67 const QBrush &dark, const QBrush &mid, const QBrush &text,
68 const QBrush &bright_text, const QBrush &base, const QBrush &window);
69 QPalette(const QColor &windowText, const QColor &window, const QColor &light,
70 const QColor &dark, const QColor &mid, const QColor &text, const QColor &base);
71 QPalette(const QPalette &palette);
73 QPalette &operator=(const QPalette &palette);
74 #ifdef Q_COMPILER_RVALUE_REFS
75 inline QPalette &operator=(QPalette &&other)
77 resolve_mask = other.resolve_mask;
78 current_group = other.current_group;
79 qSwap(d, other.d); return *this;
82 operator QVariant() const;
84 // Do not change the order, the serialization format depends on it
85 enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active };
86 enum ColorRole { WindowText, Button, Light, Midlight, Dark, Mid,
87 Text, BrightText, ButtonText, Base, Window, Shadow,
88 Highlight, HighlightedText,
89 Link, LinkVisited, // ### Qt 5: remove
91 NoRole, // ### Qt 5: value should be 0 or -1
92 ToolTipBase, ToolTipText,
93 NColorRoles = ToolTipText + 1,
94 Foreground = WindowText, Background = Window // ### Qt 5: remove
97 inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(current_group); }
98 inline void setCurrentColorGroup(ColorGroup cg) { current_group = cg; }
100 inline const QColor &color(ColorGroup cg, ColorRole cr) const
101 { return brush(cg, cr).color(); }
102 const QBrush &brush(ColorGroup cg, ColorRole cr) const;
103 inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color);
104 inline void setColor(ColorRole cr, const QColor &color);
105 inline void setBrush(ColorRole cr, const QBrush &brush);
106 bool isBrushSet(ColorGroup cg, ColorRole cr) const;
107 void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush);
108 void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
109 const QBrush &light, const QBrush &dark, const QBrush &mid,
110 const QBrush &text, const QBrush &bright_text, const QBrush &base,
111 const QBrush &window);
112 bool isEqual(ColorGroup cr1, ColorGroup cr2) const;
114 inline const QColor &color(ColorRole cr) const { return color(Current, cr); }
115 inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); }
116 inline const QBrush &foreground() const { return brush(WindowText); }
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 &background() const { return brush(Window); }
128 inline const QBrush &window() const { return brush(Window); }
129 inline const QBrush &midlight() const { return brush(Midlight); }
130 inline const QBrush &brightText() const { return brush(BrightText); }
131 inline const QBrush &buttonText() const { return brush(ButtonText); }
132 inline const QBrush &shadow() const { return brush(Shadow); }
133 inline const QBrush &highlight() const { return brush(Highlight); }
134 inline const QBrush &highlightedText() const { return brush(HighlightedText); }
135 inline const QBrush &link() const { return brush(Link); }
136 inline const QBrush &linkVisited() const { return brush(LinkVisited); }
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;
142 #if QT_DEPRECATED_SINCE(5, 0)
143 QT_DEPRECATED inline int serialNumber() const { return cacheKey() >> 32; }
145 qint64 cacheKey() const;
147 QPalette resolve(const QPalette &) const;
148 inline uint resolve() const { return resolve_mask; }
149 inline void resolve(uint mask) { resolve_mask = mask; }
152 void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
153 const QBrush &light, const QBrush &dark, const QBrush &mid,
154 const QBrush &text, const QBrush &bright_text,
155 const QBrush &base, const QBrush &alternate_base,
156 const QBrush &window, const QBrush &midlight,
157 const QBrush &button_text, const QBrush &shadow,
158 const QBrush &highlight, const QBrush &highlighted_text,
159 const QBrush &link, const QBrush &link_visited);
160 void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button,
161 const QBrush &light, const QBrush &dark, const QBrush &mid,
162 const QBrush &text, const QBrush &bright_text,
163 const QBrush &base, const QBrush &alternate_base,
164 const QBrush &window, const QBrush &midlight,
165 const QBrush &button_text, const QBrush &shadow,
166 const QBrush &highlight, const QBrush &highlighted_text,
167 const QBrush &link, const QBrush &link_visited,
168 const QBrush &toolTipBase, const QBrush &toolTipText);
173 uint current_group : 4;
174 uint resolve_mask : 28;
175 friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
178 inline void QPalette::setColor(ColorGroup acg, ColorRole acr,
179 const QColor &acolor)
180 { setBrush(acg, acr, QBrush(acolor)); }
181 inline void QPalette::setColor(ColorRole acr, const QColor &acolor)
182 { setColor(All, acr, acolor); }
183 inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush)
184 { setBrush(All, acr, abrush); }
186 /*****************************************************************************
187 QPalette stream functions
188 *****************************************************************************/
189 #ifndef QT_NO_DATASTREAM
190 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p);
191 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p);
192 #endif // QT_NO_DATASTREAM
194 #ifndef QT_NO_DEBUG_STREAM
195 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &);