1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qdeclarativesystempalette_p.h"
44 #include <QGuiApplication>
46 #include <private/qobject_p.h>
50 class QDeclarativeSystemPalettePrivate : public QObjectPrivate
54 QPalette::ColorGroup group;
60 \qmlclass SystemPalette QDeclarativeSystemPalette
61 \inqmlmodule QtQuick 2
62 \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 = QGuiApplication::palette();
88 d->group = QPalette::Active;
89 qApp->installEventFilter(this);
92 QDeclarativeSystemPalette::~QDeclarativeSystemPalette()
97 \qmlproperty color QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QtQuick2::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 QGuiApplication::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 = QGuiApplication::palette();
306 emit paletteChanged();
309 return QObject::event(event);