1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the gui module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
32
#include "QtGui/qwindowdefs.h"
33
#include "QtGui/qcolor.h"
34
#include "QtGui/qbrush.h" // QColor->QBrush conversion
41
class QPalettePrivate;
44
class Q_GUI_EXPORT QPalette
47
Q_ENUMS(ColorGroup ColorRole)
50
QPalette(const QColor &button);
51
QPalette(Qt::GlobalColor button);
52
QPalette(const QColor &button, const QColor &background);
53
QPalette(const QBrush &foreground, const QBrush &button, const QBrush &light,
54
const QBrush &dark, const QBrush &mid, const QBrush &text,
55
const QBrush &bright_text, const QBrush &base, const QBrush &background);
56
QPalette(const QColor &foreground, const QColor &background, const QColor &light,
57
const QColor &dark, const QColor &mid, const QColor &text, const QColor &base);
59
QT3_SUPPORT_CONSTRUCTOR QPalette(const QColorGroup &active, const QColorGroup &disabled, const QColorGroup &inactive);
61
QPalette(const QPalette &palette);
63
QPalette &operator=(const QPalette &palette);
64
operator QVariant() const;
66
// Do not change the order, the serialization format depends on it
67
enum ColorGroup { Active, Disabled, Inactive, NColorGroups, Current, All, Normal = Active };
68
enum ColorRole { Foreground, Button, Light, Midlight, Dark, Mid,
69
Text, BrightText, ButtonText, Base, Background, Shadow,
70
Highlight, HighlightedText, Link, LinkVisited, AlternateBase,
71
NColorRoles, NoRole = NColorRoles };
73
inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(current_group); }
74
inline void setCurrentColorGroup(ColorGroup cg) { current_group = cg; }
76
inline const QColor &color(ColorGroup cg, ColorRole cr) const
77
{ return brush(cg, cr).color(); }
78
const QBrush &brush(ColorGroup cg, ColorRole cr) const;
79
inline void setColor(ColorGroup cg, ColorRole cr, const QColor &color);
80
inline void setColor(ColorRole cr, const QColor &color);
81
inline void setBrush(ColorRole cr, const QBrush &brush);
82
void setBrush(ColorGroup cg, ColorRole cr, const QBrush &brush);
83
void setColorGroup(ColorGroup cr, const QBrush &foreground, const QBrush &button,
84
const QBrush &light, const QBrush &dark, const QBrush &mid,
85
const QBrush &text, const QBrush &bright_text, const QBrush &base,
86
const QBrush &background);
87
bool isEqual(ColorGroup cr1, ColorGroup cr2) const;
89
inline const QColor &color(ColorRole cr) const { return color(Current, cr); }
90
inline const QBrush &brush(ColorRole cr) const { return brush(Current, cr); }
91
inline const QBrush &foreground() const { return brush(Foreground); }
92
inline const QBrush &button() const { return brush(Button); }
93
inline const QBrush &light() const { return brush(Light); }
94
inline const QBrush &dark() const { return brush(Dark); }
95
inline const QBrush &mid() const { return brush(Mid); }
96
inline const QBrush &text() const { return brush(Text); }
97
inline const QBrush &base() const { return brush(Base); }
98
inline const QBrush &alternateBase() const { return brush(AlternateBase); }
99
inline const QBrush &background() const { return brush(Background); }
100
inline const QBrush &midlight() const { return brush(Midlight); }
101
inline const QBrush &brightText() const { return brush(BrightText); }
102
inline const QBrush &buttonText() const { return brush(ButtonText); }
103
inline const QBrush &shadow() const { return brush(Shadow); }
104
inline const QBrush &highlight() const { return brush(Highlight); }
105
inline const QBrush &highlightedText() const { return brush(HighlightedText); }
106
inline const QBrush &link() const { return brush(Link); }
107
inline const QBrush &linkVisited() const { return brush(LinkVisited); }
110
inline QT3_SUPPORT QPalette copy() const { QPalette p = *this; p.detach(); return p; }
111
QT3_SUPPORT QColorGroup normal() const;
112
inline QT3_SUPPORT void setNormal(const QColorGroup &cg) { setColorGroup(Active, cg); }
114
QT3_SUPPORT QColorGroup active() const;
115
QT3_SUPPORT QColorGroup disabled() const;
116
QT3_SUPPORT QColorGroup inactive() const;
117
inline QT3_SUPPORT void setActive(const QColorGroup &cg) { setColorGroup(Active, cg); }
118
inline QT3_SUPPORT void setDisabled(const QColorGroup &cg) { setColorGroup(Disabled, cg); }
119
inline QT3_SUPPORT void setInactive(const QColorGroup &cg) { setColorGroup(Inactive, cg); }
122
bool operator==(const QPalette &p) const;
123
inline bool operator!=(const QPalette &p) const { return !(operator==(p)); }
124
bool isCopyOf(const QPalette &p) const;
126
int serialNumber() const;
128
QPalette resolve(const QPalette &) const;
129
inline uint resolve() const { return resolve_mask; }
130
inline void resolve(uint mask) { resolve_mask = mask; }
133
void setColorGroup(ColorGroup cr, const QBrush &foreground, const QBrush &button,
134
const QBrush &light, const QBrush &dark, const QBrush &mid,
135
const QBrush &text, const QBrush &bright_text,
136
const QBrush &base, const QBrush &alternate_base,
137
const QBrush &background, const QBrush &midlight,
138
const QBrush &button_text, const QBrush &shadow,
139
const QBrush &highlight, const QBrush &highlighted_text,
140
const QBrush &link, const QBrush &link_visited);
142
friend class QColorGroup;
143
void setColorGroup(ColorGroup, const QColorGroup &);
144
QColorGroup createColorGroup(ColorGroup) const;
150
uint current_group : 4;
151
uint resolve_mask : 28;
152
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
155
inline void QPalette::setColor(ColorGroup acg, ColorRole acr,
156
const QColor &acolor)
157
{ setBrush(acg, acr, QBrush(acolor)); }
158
inline void QPalette::setColor(ColorRole acr, const QColor &acolor)
159
{ setColor(All, acr, acolor); }
160
inline void QPalette::setBrush(ColorRole acr, const QBrush &abrush)
161
{ setBrush(All, acr, abrush); }
164
class Q_GUI_EXPORT QColorGroup : public QPalette
167
inline QColorGroup() : QPalette() {}
168
inline QColorGroup(const QBrush &foreground, const QBrush &button, const QBrush &light,
169
const QBrush &dark, const QBrush &mid, const QBrush &text,
170
const QBrush &bright_text, const QBrush &base, const QBrush &background)
171
: QPalette(foreground, button, light, dark, mid, text, bright_text, base, background)
173
inline QColorGroup(const QColor &foreground, const QColor &background, const QColor &light,
174
const QColor &dark, const QColor &mid, const QColor &text, const QColor &base)
175
: QPalette(foreground, background, light, dark, mid, text, base) {}
176
inline QColorGroup(const QColorGroup &cg) : QPalette(cg) {}
177
inline QColorGroup(const QPalette &pal) : QPalette(pal) {}
178
bool operator==(const QColorGroup &other) const;
179
inline bool operator!=(const QColorGroup &other) const { return !(operator==(other)); }
180
operator QVariant() const;
182
inline QT3_SUPPORT const QColor &foreground() const { return color(Foreground); }
183
inline QT3_SUPPORT const QColor &button() const { return color(Button); }
184
inline QT3_SUPPORT const QColor &light() const { return color(Light); }
185
inline QT3_SUPPORT const QColor &dark() const { return color(Dark); }
186
inline QT3_SUPPORT const QColor &mid() const { return color(Mid); }
187
inline QT3_SUPPORT const QColor &text() const { return color(Text); }
188
inline QT3_SUPPORT const QColor &base() const { return color(Base); }
189
inline QT3_SUPPORT const QColor &background() const { return color(Background); }
190
inline QT3_SUPPORT const QColor &midlight() const { return color(Midlight); }
191
inline QT3_SUPPORT const QColor &brightText() const { return color(BrightText); }
192
inline QT3_SUPPORT const QColor &buttonText() const { return color(ButtonText); }
193
inline QT3_SUPPORT const QColor &shadow() const { return color(Shadow); }
194
inline QT3_SUPPORT const QColor &highlight() const { return color(Highlight); }
195
inline QT3_SUPPORT const QColor &highlightedText() const { return color(HighlightedText); }
196
inline QT3_SUPPORT const QColor &link() const { return color(Link); }
197
inline QT3_SUPPORT const QColor &linkVisited() const { return color(LinkVisited); }
200
#ifndef QT_NO_DATASTREAM
201
Q_GUI_EXPORT QT3_SUPPORT QDataStream &operator<<(QDataStream &ds, const QColorGroup &cg);
202
Q_GUI_EXPORT QT3_SUPPORT QDataStream &operator>>(QDataStream &ds, QColorGroup &cg);
205
inline QColorGroup QPalette::inactive() const { return createColorGroup(Inactive); }
206
inline QColorGroup QPalette::disabled() const { return createColorGroup(Disabled); }
207
inline QColorGroup QPalette::active() const { return createColorGroup(Active); }
208
inline QColorGroup QPalette::normal() const { return createColorGroup(Active); }
212
/*****************************************************************************
213
QPalette stream functions
214
*****************************************************************************/
215
#ifndef QT_NO_DATASTREAM
216
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &ds, const QPalette &p);
217
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &ds, QPalette &p);
218
#endif // QT_NO_DATASTREAM
220
#endif // QT_NO_PALETTE