Qt 4.8
qpalette.h
Go to the documentation of this file.
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 
50 
52 
53 QT_MODULE(Gui)
54 
55 #ifdef QT3_SUPPORT
56 class QColorGroup;
57 #endif
58 class QPalettePrivate;
59 class QVariant;
60 
62 {
63  Q_GADGET
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
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 
198  friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
199 };
200 
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
264 #endif // QT_NO_DATASTREAM
265 
267 
269 
270 #endif // QPALETTE_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool operator!=(const QPalette &p) const
Returns true (slowly) if this palette is different from p; otherwise returns false (usually quickly)...
Definition: qpalette.h:159
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
const QBrush & highlight() const
Returns the highlight brush of the current color group.
Definition: qpalette.h:140
const QBrush & base() const
Returns the base brush of the current color group.
Definition: qpalette.h:130
const QBrush & brightText() const
Returns the bright text foreground brush of the current color group.
Definition: qpalette.h:137
#define disabled
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
ColorRole
The ColorRole enum defines the different symbolic color roles used in current GUIs.
Definition: qpalette.h:93
void detach()
Definition: qpalette.cpp:953
const QBrush & dark() const
Returns the dark brush of the current color group.
Definition: qpalette.h:127
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
Q_GUI_EXPORT QDataStream & operator<<(QDataStream &ds, const QPalette &p)
QPalettePrivate * d
Definition: qpalette.h:195
const QBrush & background() const
Use window() instead.
Definition: qpalette.h:134
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
friend Q_GUI_EXPORT QDataStream & operator<<(QDataStream &s, const QPalette &p)
Writes the palette, p to the stream s and returns a reference to the stream.
Definition: qpalette.cpp:1154
const QBrush & foreground() const
Use windowText() instead.
Definition: qpalette.h:123
const QColor & color(ColorRole cr) const
Returns the color that has been set for the given color role in the current ColorGroup.
Definition: qpalette.h:121
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
static const uint base
Definition: qurl.cpp:268
void resolve(uint mask)
Definition: qpalette.h:167
GlobalColor
Definition: qnamespace.h:104
ColorGroup currentColorGroup() const
Returns the palette&#39;s current color group.
Definition: qpalette.h:104
ColorGroup
Definition: qpalette.h:92
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
NSWindow * window
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
const QBrush & light() const
Returns the light brush of the current color group.
Definition: qpalette.h:126
static bool init
const QBrush & midlight() const
Returns the midlight brush of the current color group.
Definition: qpalette.h:136
const QBrush & mid() const
Returns the mid brush of the current color group.
Definition: qpalette.h:128
uint current_group
Definition: qpalette.h:196
unsigned int uint
Definition: qglobal.h:996
const QBrush & brush(ColorRole cr) const
Returns the brush that has been set for the given color role in the current ColorGroup.
Definition: qpalette.h:122
__int64 qint64
Definition: qglobal.h:942
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
#define Q_GADGET
Definition: qobjectdefs.h:173
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
const QBrush & shadow() const
Returns the shadow brush of the current color group.
Definition: qpalette.h:139
const QBrush & windowText() const
Returns the window text (general foreground) brush of the current color group.
Definition: qpalette.h:124
const QBrush & highlightedText() const
Returns the highlighted text brush of the current color group.
Definition: qpalette.h:141
const QBrush & linkVisited() const
Returns the visited link text brush of the current color group.
Definition: qpalette.h:143
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201
const QBrush & toolTipBase() const
Returns the tool tip base brush of the current color group.
Definition: qpalette.h:132
The QColorGroup class contains color groups for each widget state.
uint resolve() const
Definition: qpalette.h:166
const QBrush & toolTipText() const
Returns the tool tip text brush of the current color group.
Definition: qpalette.h:133
const QBrush & alternateBase() const
Returns the alternate base brush of the current color group.
Definition: qpalette.h:131
const QBrush & link() const
Returns the unvisited link text brush of the current color group.
Definition: qpalette.h:142
bool operator==(const QPalette &p) const
Returns true (usually quickly) if this palette is equal to p; otherwise returns false (slowly)...
Definition: qpalette.cpp:992
const QBrush & buttonText() const
Returns the button text foreground brush of the current color group.
Definition: qpalette.h:138
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
QPalette()
Constructs a palette object that uses the application&#39;s default palette.
Definition: qpalette.cpp:673
QDataStream & operator>>(QDataStream &s, QPalette &p)
Reads a palette from the stream, s into the palette p, and returns a reference to the stream...
Definition: qpalette.cpp:1195
const QBrush & button() const
Returns the button brush of the current color group.
Definition: qpalette.h:125
#define QT_END_HEADER
Definition: qglobal.h:137
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023
const QBrush & window() const
Returns the window (general background) brush of the current color group.
Definition: qpalette.h:135
uint resolve_mask
Definition: qpalette.h:197
#define text
Definition: qobjectdefs.h:80
const QBrush & text() const
Returns the text foreground brush of the current color group.
Definition: qpalette.h:129
The Text item allows you to add formatted text to a scene.
Button
Definition: qmessagebox.cpp:82
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61