1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #include "QtQuick1/private/qdeclarativesystempalette_p.h"
44 #include <QApplication>
46 #include <private/qobject_p.h>
52 class QDeclarative1SystemPalettePrivate : public QObjectPrivate
56 QPalette::ColorGroup group;
62 \qmlclass SystemPalette QDeclarative1SystemPalette
63 \inqmlmodule QtQuick 1
64 \ingroup qml-utility-elements
66 \brief The SystemPalette element provides access to the Qt palettes.
68 The SystemPalette element provides access to the Qt application
69 palettes. This provides information about the standard colors used
70 for application windows, buttons and other features. These colors
71 are grouped into three \e {color groups}: \c Active, \c Inactive,
72 and \c Disabled. See the QPalette documentation for details about
73 color groups and the properties provided by SystemPalette.
75 This can be used to color items in a way that provides a more
78 The following example creates a palette from the \c Active color
79 group and uses this to color the window and text items
82 \snippet doc/src/snippets/qtquick1/systempalette.qml 0
86 QDeclarative1SystemPalette::QDeclarative1SystemPalette(QObject *parent)
87 : QObject(*(new QDeclarative1SystemPalettePrivate), parent)
89 Q_D(QDeclarative1SystemPalette);
90 d->palette = QApplication::palette();
91 d->group = QPalette::Active;
92 qApp->installEventFilter(this);
95 QDeclarative1SystemPalette::~QDeclarative1SystemPalette()
100 \qmlproperty color QtQuick1::SystemPalette::window
101 The window (general background) color of the current color group.
103 \sa QPalette::ColorRole
105 QColor QDeclarative1SystemPalette::window() const
107 Q_D(const QDeclarative1SystemPalette);
108 return d->palette.color(d->group, QPalette::Window);
112 \qmlproperty color QtQuick1::SystemPalette::windowText
113 The window text (general foreground) color of the current color group.
115 \sa QPalette::ColorRole
117 QColor QDeclarative1SystemPalette::windowText() const
119 Q_D(const QDeclarative1SystemPalette);
120 return d->palette.color(d->group, QPalette::WindowText);
124 \qmlproperty color QtQuick1::SystemPalette::base
125 The base color of the current color group.
127 \sa QPalette::ColorRole
129 QColor QDeclarative1SystemPalette::base() const
131 Q_D(const QDeclarative1SystemPalette);
132 return d->palette.color(d->group, QPalette::Base);
136 \qmlproperty color QtQuick1::SystemPalette::text
137 The text color of the current color group.
139 \sa QPalette::ColorRole
141 QColor QDeclarative1SystemPalette::text() const
143 Q_D(const QDeclarative1SystemPalette);
144 return d->palette.color(d->group, QPalette::Text);
148 \qmlproperty color QtQuick1::SystemPalette::alternateBase
149 The alternate base color of the current color group.
151 \sa QPalette::ColorRole
153 QColor QDeclarative1SystemPalette::alternateBase() const
155 Q_D(const QDeclarative1SystemPalette);
156 return d->palette.color(d->group, QPalette::AlternateBase);
160 \qmlproperty color QtQuick1::SystemPalette::button
161 The button color of the current color group.
163 \sa QPalette::ColorRole
165 QColor QDeclarative1SystemPalette::button() const
167 Q_D(const QDeclarative1SystemPalette);
168 return d->palette.color(d->group, QPalette::Button);
172 \qmlproperty color QtQuick1::SystemPalette::buttonText
173 The button text foreground color of the current color group.
175 \sa QPalette::ColorRole
177 QColor QDeclarative1SystemPalette::buttonText() const
179 Q_D(const QDeclarative1SystemPalette);
180 return d->palette.color(d->group, QPalette::ButtonText);
184 \qmlproperty color QtQuick1::SystemPalette::light
185 The light color of the current color group.
187 \sa QPalette::ColorRole
189 QColor QDeclarative1SystemPalette::light() const
191 Q_D(const QDeclarative1SystemPalette);
192 return d->palette.color(d->group, QPalette::Light);
196 \qmlproperty color QtQuick1::SystemPalette::midlight
197 The midlight color of the current color group.
199 \sa QPalette::ColorRole
201 QColor QDeclarative1SystemPalette::midlight() const
203 Q_D(const QDeclarative1SystemPalette);
204 return d->palette.color(d->group, QPalette::Midlight);
208 \qmlproperty color QtQuick1::SystemPalette::dark
209 The dark color of the current color group.
211 \sa QPalette::ColorRole
213 QColor QDeclarative1SystemPalette::dark() const
215 Q_D(const QDeclarative1SystemPalette);
216 return d->palette.color(d->group, QPalette::Dark);
220 \qmlproperty color QtQuick1::SystemPalette::mid
221 The mid color of the current color group.
223 \sa QPalette::ColorRole
225 QColor QDeclarative1SystemPalette::mid() const
227 Q_D(const QDeclarative1SystemPalette);
228 return d->palette.color(d->group, QPalette::Mid);
232 \qmlproperty color QtQuick1::SystemPalette::shadow
233 The shadow color of the current color group.
235 \sa QPalette::ColorRole
237 QColor QDeclarative1SystemPalette::shadow() const
239 Q_D(const QDeclarative1SystemPalette);
240 return d->palette.color(d->group, QPalette::Shadow);
244 \qmlproperty color QtQuick1::SystemPalette::highlight
245 The highlight color of the current color group.
247 \sa QPalette::ColorRole
249 QColor QDeclarative1SystemPalette::highlight() const
251 Q_D(const QDeclarative1SystemPalette);
252 return d->palette.color(d->group, QPalette::Highlight);
256 \qmlproperty color QtQuick1::SystemPalette::highlightedText
257 The highlighted text color of the current color group.
259 \sa QPalette::ColorRole
261 QColor QDeclarative1SystemPalette::highlightedText() const
263 Q_D(const QDeclarative1SystemPalette);
264 return d->palette.color(d->group, QPalette::HighlightedText);
268 \qmlproperty enumeration QtQuick1::SystemPalette::colorGroup
270 The color group of the palette. This can be one of:
273 \o SystemPalette.Active (default)
274 \o SystemPalette.Inactive
275 \o SystemPalette.Disabled
278 \sa QPalette::ColorGroup
280 QDeclarative1SystemPalette::ColorGroup QDeclarative1SystemPalette::colorGroup() const
282 Q_D(const QDeclarative1SystemPalette);
283 return (QDeclarative1SystemPalette::ColorGroup)d->group;
286 void QDeclarative1SystemPalette::setColorGroup(QDeclarative1SystemPalette::ColorGroup colorGroup)
288 Q_D(QDeclarative1SystemPalette);
289 d->group = (QPalette::ColorGroup)colorGroup;
290 emit paletteChanged();
293 bool QDeclarative1SystemPalette::eventFilter(QObject *watched, QEvent *event)
295 if (watched == qApp) {
296 if (event->type() == QEvent::ApplicationPaletteChange) {
297 QApplication::postEvent(this, new QEvent(QEvent::ApplicationPaletteChange));
301 return QObject::eventFilter(watched, event);
304 bool QDeclarative1SystemPalette::event(QEvent *event)
306 Q_D(QDeclarative1SystemPalette);
307 if (event->type() == QEvent::ApplicationPaletteChange) {
308 d->palette = QApplication::palette();
309 emit paletteChanged();
312 return QObject::event(event);