ca619a89b4f05cf6f172b2f2a6d9ed62d7c5b996
[profile/ivi/qtbase.git] / src / gui / kernel / qpalette.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
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
49 QT_BEGIN_HEADER
50
51 QT_BEGIN_NAMESPACE
52
53
54 class QPalettePrivate;
55 class QVariant;
56
57 class Q_GUI_EXPORT QPalette
58 {
59     Q_GADGET
60     Q_ENUMS(ColorGroup ColorRole)
61 public:
62     QPalette();
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);
72     ~QPalette();
73     QPalette &operator=(const QPalette &palette);
74 #ifdef Q_COMPILER_RVALUE_REFS
75     inline QPalette &operator=(QPalette &&other)
76     {
77         resolve_mask = other.resolve_mask;
78         current_group = other.current_group;
79         qSwap(d, other.d); return *this;
80     }
81 #endif
82     operator QVariant() const;
83
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
90                      AlternateBase,
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
95                    };
96
97     inline ColorGroup currentColorGroup() const { return static_cast<ColorGroup>(current_group); }
98     inline void setCurrentColorGroup(ColorGroup cg) { current_group = cg; }
99
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;
113
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); }
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 #if QT_DEPRECATED_SINCE(5, 0)
143     QT_DEPRECATED inline int serialNumber() const { return cacheKey() >> 32; }
144 #endif
145     qint64 cacheKey() const;
146
147     QPalette resolve(const QPalette &) const;
148     inline uint resolve() const { return resolve_mask; }
149     inline void resolve(uint mask) { resolve_mask = mask; }
150
151 private:
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);
169     void init();
170     void detach();
171
172     QPalettePrivate *d;
173     uint current_group : 4;
174     uint resolve_mask : 28;
175     friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPalette &p);
176 };
177
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); }
185
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
193
194 #ifndef QT_NO_DEBUG_STREAM
195 Q_GUI_EXPORT QDebug operator<<(QDebug, const QPalette &);
196 #endif
197
198 QT_END_NAMESPACE
199
200 QT_END_HEADER
201
202 #endif // QPALETTE_H