1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "private/qdeclarativesystempalette_p.h"
44 #include <QApplication>
46 #include <private/qobject_p.h>
50 class QDeclarativeSystemPalettePrivate : public QObjectPrivate
54 QPalette::ColorGroup group;
60 \qmlclass SystemPalette QDeclarativeSystemPalette
61 \ingroup qml-utility-elements
63 \brief The SystemPalette element provides access to the Qt palettes.
65 The SystemPalette element provides access to the Qt application
66 palettes. This provides information about the standard colors used
67 for application windows, buttons and other features. These colors
68 are grouped into three \e {color groups}: \c Active, \c Inactive,
69 and \c Disabled. See the QPalette documentation for details about
70 color groups and the properties provided by SystemPalette.
72 This can be used to color items in a way that provides a more
75 The following example creates a palette from the \c Active color
76 group and uses this to color the window and text items
79 \snippet doc/src/snippets/declarative/systempalette.qml 0
83 QDeclarativeSystemPalette::QDeclarativeSystemPalette(QObject *parent)
84 : QObject(*(new QDeclarativeSystemPalettePrivate), parent)
86 Q_D(QDeclarativeSystemPalette);
87 d->palette = QApplication::palette();
88 d->group = QPalette::Active;
89 qApp->installEventFilter(this);
92 QDeclarativeSystemPalette::~QDeclarativeSystemPalette()
97 \qmlproperty color SystemPalette::window
98 The window (general background) color of the current color group.
100 \sa QPalette::ColorRole
102 QColor QDeclarativeSystemPalette::window() const
104 Q_D(const QDeclarativeSystemPalette);
105 return d->palette.color(d->group, QPalette::Window);
109 \qmlproperty color SystemPalette::windowText
110 The window text (general foreground) color of the current color group.
112 \sa QPalette::ColorRole
114 QColor QDeclarativeSystemPalette::windowText() const
116 Q_D(const QDeclarativeSystemPalette);
117 return d->palette.color(d->group, QPalette::WindowText);
121 \qmlproperty color SystemPalette::base
122 The base color of the current color group.
124 \sa QPalette::ColorRole
126 QColor QDeclarativeSystemPalette::base() const
128 Q_D(const QDeclarativeSystemPalette);
129 return d->palette.color(d->group, QPalette::Base);
133 \qmlproperty color SystemPalette::text
134 The text color of the current color group.
136 \sa QPalette::ColorRole
138 QColor QDeclarativeSystemPalette::text() const
140 Q_D(const QDeclarativeSystemPalette);
141 return d->palette.color(d->group, QPalette::Text);
145 \qmlproperty color SystemPalette::alternateBase
146 The alternate base color of the current color group.
148 \sa QPalette::ColorRole
150 QColor QDeclarativeSystemPalette::alternateBase() const
152 Q_D(const QDeclarativeSystemPalette);
153 return d->palette.color(d->group, QPalette::AlternateBase);
157 \qmlproperty color SystemPalette::button
158 The button color of the current color group.
160 \sa QPalette::ColorRole
162 QColor QDeclarativeSystemPalette::button() const
164 Q_D(const QDeclarativeSystemPalette);
165 return d->palette.color(d->group, QPalette::Button);
169 \qmlproperty color SystemPalette::buttonText
170 The button text foreground color of the current color group.
172 \sa QPalette::ColorRole
174 QColor QDeclarativeSystemPalette::buttonText() const
176 Q_D(const QDeclarativeSystemPalette);
177 return d->palette.color(d->group, QPalette::ButtonText);
181 \qmlproperty color SystemPalette::light
182 The light color of the current color group.
184 \sa QPalette::ColorRole
186 QColor QDeclarativeSystemPalette::light() const
188 Q_D(const QDeclarativeSystemPalette);
189 return d->palette.color(d->group, QPalette::Light);
193 \qmlproperty color SystemPalette::midlight
194 The midlight color of the current color group.
196 \sa QPalette::ColorRole
198 QColor QDeclarativeSystemPalette::midlight() const
200 Q_D(const QDeclarativeSystemPalette);
201 return d->palette.color(d->group, QPalette::Midlight);
205 \qmlproperty color SystemPalette::dark
206 The dark color of the current color group.
208 \sa QPalette::ColorRole
210 QColor QDeclarativeSystemPalette::dark() const
212 Q_D(const QDeclarativeSystemPalette);
213 return d->palette.color(d->group, QPalette::Dark);
217 \qmlproperty color SystemPalette::mid
218 The mid color of the current color group.
220 \sa QPalette::ColorRole
222 QColor QDeclarativeSystemPalette::mid() const
224 Q_D(const QDeclarativeSystemPalette);
225 return d->palette.color(d->group, QPalette::Mid);
229 \qmlproperty color SystemPalette::shadow
230 The shadow color of the current color group.
232 \sa QPalette::ColorRole
234 QColor QDeclarativeSystemPalette::shadow() const
236 Q_D(const QDeclarativeSystemPalette);
237 return d->palette.color(d->group, QPalette::Shadow);
241 \qmlproperty color SystemPalette::highlight
242 The highlight color of the current color group.
244 \sa QPalette::ColorRole
246 QColor QDeclarativeSystemPalette::highlight() const
248 Q_D(const QDeclarativeSystemPalette);
249 return d->palette.color(d->group, QPalette::Highlight);
253 \qmlproperty color SystemPalette::highlightedText
254 The highlighted text color of the current color group.
256 \sa QPalette::ColorRole
258 QColor QDeclarativeSystemPalette::highlightedText() const
260 Q_D(const QDeclarativeSystemPalette);
261 return d->palette.color(d->group, QPalette::HighlightedText);
265 \qmlproperty enumeration SystemPalette::colorGroup
267 The color group of the palette. This can be one of:
270 \o SystemPalette.Active (default)
271 \o SystemPalette.Inactive
272 \o SystemPalette.Disabled
275 \sa QPalette::ColorGroup
277 QDeclarativeSystemPalette::ColorGroup QDeclarativeSystemPalette::colorGroup() const
279 Q_D(const QDeclarativeSystemPalette);
280 return (QDeclarativeSystemPalette::ColorGroup)d->group;
283 void QDeclarativeSystemPalette::setColorGroup(QDeclarativeSystemPalette::ColorGroup colorGroup)
285 Q_D(QDeclarativeSystemPalette);
286 d->group = (QPalette::ColorGroup)colorGroup;
287 emit paletteChanged();
290 bool QDeclarativeSystemPalette::eventFilter(QObject *watched, QEvent *event)
292 if (watched == qApp) {
293 if (event->type() == QEvent::ApplicationPaletteChange) {
294 QApplication::postEvent(this, new QEvent(QEvent::ApplicationPaletteChange));
298 return QObject::eventFilter(watched, event);
301 bool QDeclarativeSystemPalette::event(QEvent *event)
303 Q_D(QDeclarativeSystemPalette);
304 if (event->type() == QEvent::ApplicationPaletteChange) {
305 d->palette = QApplication::palette();
306 emit paletteChanged();
309 return QObject::event(event);