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