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