1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qquicksystempalette_p.h"
41
42#include <QGuiApplication>
43
44#include <private/qobject_p.h>
45
46QT_BEGIN_NAMESPACE
47
48class QQuickSystemPalettePrivate : public QObjectPrivate
49{
50public:
51 QPalette::ColorGroup group;
52};
53
54
55
56/*!
57 \qmltype SystemPalette
58 \instantiates QQuickSystemPalette
59 \inqmlmodule QtQuick
60 \ingroup qtquick-visual-utility
61 \brief Provides access to the Qt palettes.
62
63 The SystemPalette type provides access to the Qt application
64 palettes. This provides information about the standard colors used
65 for application windows, buttons and other features. These colors
66 are grouped into three \e {color groups}: \c Active, \c Inactive,
67 and \c Disabled. See the QPalette documentation for details about
68 color groups and the properties provided by SystemPalette.
69
70 This can be used to color items in a way that provides a more
71 native look and feel.
72
73 The following example creates a palette from the \c Active color
74 group and uses this to color the window and text items
75 appropriately:
76
77 \snippet qml/systempalette.qml 0
78
79 \sa QPalette
80*/
81QQuickSystemPalette::QQuickSystemPalette(QObject *parent)
82 : QObject(*(new QQuickSystemPalettePrivate), parent)
83{
84 Q_D(QQuickSystemPalette);
85 d->group = QPalette::Active;
86 connect(qApp, SIGNAL(paletteChanged(QPalette)), receiver: this, SIGNAL(paletteChanged()));
87}
88
89QQuickSystemPalette::~QQuickSystemPalette()
90{
91}
92
93/*!
94 \qmlproperty color QtQuick::SystemPalette::window
95 The window (general background) color of the current color group.
96
97 \sa QPalette::ColorRole
98*/
99QColor QQuickSystemPalette::window() const
100{
101 Q_D(const QQuickSystemPalette);
102 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Window);
103}
104
105/*!
106 \qmlproperty color QtQuick::SystemPalette::windowText
107 The window text (general foreground) color of the current color group.
108
109 \sa QPalette::ColorRole
110*/
111QColor QQuickSystemPalette::windowText() const
112{
113 Q_D(const QQuickSystemPalette);
114 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::WindowText);
115}
116
117/*!
118 \qmlproperty color QtQuick::SystemPalette::base
119 The base color of the current color group.
120
121 \sa QPalette::ColorRole
122*/
123QColor QQuickSystemPalette::base() const
124{
125 Q_D(const QQuickSystemPalette);
126 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Base);
127}
128
129/*!
130 \qmlproperty color QtQuick::SystemPalette::text
131 The text color of the current color group.
132
133 \sa QPalette::ColorRole
134*/
135QColor QQuickSystemPalette::text() const
136{
137 Q_D(const QQuickSystemPalette);
138 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Text);
139}
140
141/*!
142 \qmlproperty color QtQuick::SystemPalette::alternateBase
143 The alternate base color of the current color group.
144
145 \sa QPalette::ColorRole
146*/
147QColor QQuickSystemPalette::alternateBase() const
148{
149 Q_D(const QQuickSystemPalette);
150 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::AlternateBase);
151}
152
153/*!
154 \qmlproperty color QtQuick::SystemPalette::button
155 The button color of the current color group.
156
157 \sa QPalette::ColorRole
158*/
159QColor QQuickSystemPalette::button() const
160{
161 Q_D(const QQuickSystemPalette);
162 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Button);
163}
164
165/*!
166 \qmlproperty color QtQuick::SystemPalette::buttonText
167 The button text foreground color of the current color group.
168
169 \sa QPalette::ColorRole
170*/
171QColor QQuickSystemPalette::buttonText() const
172{
173 Q_D(const QQuickSystemPalette);
174 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::ButtonText);
175}
176
177/*!
178 \qmlproperty color QtQuick::SystemPalette::light
179 The light color of the current color group.
180
181 \sa QPalette::ColorRole
182*/
183QColor QQuickSystemPalette::light() const
184{
185 Q_D(const QQuickSystemPalette);
186 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Light);
187}
188
189/*!
190 \qmlproperty color QtQuick::SystemPalette::midlight
191 The midlight color of the current color group.
192
193 \sa QPalette::ColorRole
194*/
195QColor QQuickSystemPalette::midlight() const
196{
197 Q_D(const QQuickSystemPalette);
198 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Midlight);
199}
200
201/*!
202 \qmlproperty color QtQuick::SystemPalette::dark
203 The dark color of the current color group.
204
205 \sa QPalette::ColorRole
206*/
207QColor QQuickSystemPalette::dark() const
208{
209 Q_D(const QQuickSystemPalette);
210 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Dark);
211}
212
213/*!
214 \qmlproperty color QtQuick::SystemPalette::mid
215 The mid color of the current color group.
216
217 \sa QPalette::ColorRole
218*/
219QColor QQuickSystemPalette::mid() const
220{
221 Q_D(const QQuickSystemPalette);
222 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Mid);
223}
224
225/*!
226 \qmlproperty color QtQuick::SystemPalette::shadow
227 The shadow color of the current color group.
228
229 \sa QPalette::ColorRole
230*/
231QColor QQuickSystemPalette::shadow() const
232{
233 Q_D(const QQuickSystemPalette);
234 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Shadow);
235}
236
237/*!
238 \qmlproperty color QtQuick::SystemPalette::highlight
239 The highlight color of the current color group.
240
241 \sa QPalette::ColorRole
242*/
243QColor QQuickSystemPalette::highlight() const
244{
245 Q_D(const QQuickSystemPalette);
246 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Highlight);
247}
248
249/*!
250 \qmlproperty color QtQuick::SystemPalette::highlightedText
251 The highlighted text color of the current color group.
252
253 \sa QPalette::ColorRole
254*/
255QColor QQuickSystemPalette::highlightedText() const
256{
257 Q_D(const QQuickSystemPalette);
258 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::HighlightedText);
259}
260
261/*!
262 \qmlproperty enumeration QtQuick::SystemPalette::colorGroup
263
264 The color group of the palette. This can be one of:
265
266 \list
267 \li SystemPalette.Active (default)
268 \li SystemPalette.Inactive
269 \li SystemPalette.Disabled
270 \endlist
271
272 \sa QPalette::ColorGroup
273*/
274QQuickSystemPalette::ColorGroup QQuickSystemPalette::colorGroup() const
275{
276 Q_D(const QQuickSystemPalette);
277 return (QQuickSystemPalette::ColorGroup)d->group;
278}
279
280void QQuickSystemPalette::setColorGroup(QQuickSystemPalette::ColorGroup colorGroup)
281{
282 Q_D(QQuickSystemPalette);
283 d->group = (QPalette::ColorGroup)colorGroup;
284 emit paletteChanged();
285}
286
287QT_END_NAMESPACE
288
289#include "moc_qquicksystempalette_p.cpp"
290

source code of qtdeclarative/src/quick/util/qquicksystempalette.cpp