1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquicksystempalette_p.h"
5
6#include <QGuiApplication>
7
8#include <private/qobject_p.h>
9
10QT_BEGIN_NAMESPACE
11
12class QQuickSystemPalettePrivate : public QObjectPrivate
13{
14public:
15 QPalette::ColorGroup group;
16};
17
18
19
20/*!
21 \qmltype SystemPalette
22 \instantiates QQuickSystemPalette
23 \inqmlmodule QtQuick
24 \ingroup qtquick-visual-utility
25 \brief Provides access to the Qt palettes.
26
27 The SystemPalette type provides access to the Qt application
28 palettes. This provides information about the standard colors used
29 for application windows, buttons and other features. These colors
30 are grouped into three \e {color groups}: \c active, \c inactive,
31 and \c disabled. See the QPalette documentation for details about
32 color groups and the properties provided by SystemPalette.
33
34 This can be used to color items in a way that provides a more
35 native look and feel.
36
37 The following example creates a palette from the \c Active color
38 group and uses this to color the window and text items
39 appropriately:
40
41 \snippet qml/systempalette.qml 0
42
43 \sa QPalette
44*/
45QQuickSystemPalette::QQuickSystemPalette(QObject *parent)
46 : QObject(*(new QQuickSystemPalettePrivate), parent)
47{
48 Q_D(QQuickSystemPalette);
49 d->group = QPalette::Active;
50 connect(qApp, SIGNAL(paletteChanged(QPalette)), receiver: this, SIGNAL(paletteChanged()));
51}
52
53/*!
54 \qmlproperty color QtQuick::SystemPalette::window
55 The window (general background) color of the current color group.
56
57 \sa QPalette::ColorRole
58*/
59QColor QQuickSystemPalette::window() const
60{
61 Q_D(const QQuickSystemPalette);
62 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Window);
63}
64
65/*!
66 \qmlproperty color QtQuick::SystemPalette::windowText
67 The window text (general foreground) color of the current color group.
68
69 \sa QPalette::ColorRole
70*/
71QColor QQuickSystemPalette::windowText() const
72{
73 Q_D(const QQuickSystemPalette);
74 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::WindowText);
75}
76
77/*!
78 \qmlproperty color QtQuick::SystemPalette::base
79 The base color of the current color group.
80
81 \sa QPalette::ColorRole
82*/
83QColor QQuickSystemPalette::base() const
84{
85 Q_D(const QQuickSystemPalette);
86 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Base);
87}
88
89/*!
90 \qmlproperty color QtQuick::SystemPalette::text
91 The text color of the current color group.
92
93 \sa QPalette::ColorRole
94*/
95QColor QQuickSystemPalette::text() const
96{
97 Q_D(const QQuickSystemPalette);
98 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Text);
99}
100
101/*!
102 \qmlproperty color QtQuick::SystemPalette::alternateBase
103 The alternate base color of the current color group.
104
105 \sa QPalette::ColorRole
106*/
107QColor QQuickSystemPalette::alternateBase() const
108{
109 Q_D(const QQuickSystemPalette);
110 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::AlternateBase);
111}
112
113/*!
114 \qmlproperty color QtQuick::SystemPalette::button
115 The button color of the current color group.
116
117 \sa QPalette::ColorRole
118*/
119QColor QQuickSystemPalette::button() const
120{
121 Q_D(const QQuickSystemPalette);
122 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Button);
123}
124
125/*!
126 \qmlproperty color QtQuick::SystemPalette::buttonText
127 The button text foreground color of the current color group.
128
129 \sa QPalette::ColorRole
130*/
131QColor QQuickSystemPalette::buttonText() const
132{
133 Q_D(const QQuickSystemPalette);
134 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::ButtonText);
135}
136
137/*!
138 \qmlproperty color QtQuick::SystemPalette::light
139 The light color of the current color group.
140
141 \sa QPalette::ColorRole
142*/
143QColor QQuickSystemPalette::light() const
144{
145 Q_D(const QQuickSystemPalette);
146 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Light);
147}
148
149/*!
150 \qmlproperty color QtQuick::SystemPalette::midlight
151 The midlight color of the current color group.
152
153 \sa QPalette::ColorRole
154*/
155QColor QQuickSystemPalette::midlight() const
156{
157 Q_D(const QQuickSystemPalette);
158 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Midlight);
159}
160
161/*!
162 \qmlproperty color QtQuick::SystemPalette::dark
163 The dark color of the current color group.
164
165 \sa QPalette::ColorRole
166*/
167QColor QQuickSystemPalette::dark() const
168{
169 Q_D(const QQuickSystemPalette);
170 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Dark);
171}
172
173/*!
174 \qmlproperty color QtQuick::SystemPalette::mid
175 The mid color of the current color group.
176
177 \sa QPalette::ColorRole
178*/
179QColor QQuickSystemPalette::mid() const
180{
181 Q_D(const QQuickSystemPalette);
182 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Mid);
183}
184
185/*!
186 \qmlproperty color QtQuick::SystemPalette::shadow
187 The shadow color of the current color group.
188
189 \sa QPalette::ColorRole
190*/
191QColor QQuickSystemPalette::shadow() const
192{
193 Q_D(const QQuickSystemPalette);
194 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Shadow);
195}
196
197/*!
198 \qmlproperty color QtQuick::SystemPalette::highlight
199 The highlight color of the current color group.
200
201 \sa QPalette::ColorRole
202*/
203QColor QQuickSystemPalette::highlight() const
204{
205 Q_D(const QQuickSystemPalette);
206 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::Highlight);
207}
208
209/*!
210 \qmlproperty color QtQuick::SystemPalette::highlightedText
211 The highlighted text color of the current color group.
212
213 \sa QPalette::ColorRole
214*/
215QColor QQuickSystemPalette::highlightedText() const
216{
217 Q_D(const QQuickSystemPalette);
218 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::HighlightedText);
219}
220
221/*!
222 \qmlproperty color QtQuick::SystemPalette::placeholderText
223 The placeholder text color of the current color group.
224
225 \since 6.2
226 \sa QPalette::ColorRole
227*/
228QColor QQuickSystemPalette::placeholderText() const
229{
230 Q_D(const QQuickSystemPalette);
231 return QGuiApplication::palette().color(cg: d->group, cr: QPalette::PlaceholderText);
232}
233/*!
234 \qmlproperty enumeration QtQuick::SystemPalette::colorGroup
235
236 The color group of the palette. This can be one of:
237
238 \value SystemPalette.Active (default) QPalette::Active
239 \value SystemPalette.Inactive QPalette::Inactive
240 \value SystemPalette.Disabled QPalette::Disabled
241
242 \sa QPalette::ColorGroup
243*/
244QQuickSystemPalette::ColorGroup QQuickSystemPalette::colorGroup() const
245{
246 Q_D(const QQuickSystemPalette);
247 return (QQuickSystemPalette::ColorGroup)d->group;
248}
249
250void QQuickSystemPalette::setColorGroup(QQuickSystemPalette::ColorGroup colorGroup)
251{
252 Q_D(QQuickSystemPalette);
253 d->group = (QPalette::ColorGroup)colorGroup;
254 emit paletteChanged();
255}
256
257QT_END_NAMESPACE
258
259#include "moc_qquicksystempalette_p.cpp"
260

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