Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickcolorgroup.cpp
Go to the documentation of this file.
1
// Copyright (C) 2020 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
#
include
"qquickcolorgroup_p.h"
5
6
#
include
<
QScopeGuard
>
7
8
#
include
<
QtQuick
/
private
/
qquickabstractpaletteprovider_p
.
h
>
9
#
include
<
QtQuick
/
private
/
qquickpalette_p
.
h
>
10
#
include
<
QtQuick
/
private
/
qquickpalettecolorprovider_p
.
h
>
11
12
QT_BEGIN_NAMESPACE
13
14
/*!
15
\internal
16
17
\class QQuickColorGroup
18
\brief The QQuickColorGroup class represents a set of colors.
19
\inmodule QtQuick
20
\since 6.0
21
22
Used by QQuickPalette to provide different groups of colors by roles.
23
24
\sa QPalette::ColorRole
25
//! internal \sa QQuickPalette, QQuickAbstractPaletteProvider
26
*/
27
28
/*!
29
\qmltype ColorGroup
30
\nativetype QQuickColorGroup
31
\inherits QtObject
32
\inqmlmodule QtQuick
33
\ingroup qtquick-visual
34
\brief The set of colors by roles.
35
36
The ColorGroup type is used to define a set of colors with certain roles. Although a ColorGroup
37
has no visual appearance, it defines colors used to customize rendered items.
38
39
Default values of colors are equal to active group colors of default-constructed \c QPalette.
40
41
The following code can be used to create a color group with some colors specified:
42
43
\code
44
ColorGroup {
45
alternateBase: "red"
46
base: "green"
47
}
48
\endcode
49
50
The \l Palette type exposes color groups for each QML item state.
51
*/
52
53
/*!
54
\qmlproperty color QtQuick::ColorGroup::accent
55
\since 6.6
56
57
A color that typically contrasts or compliments \l base, \l window, and \l
58
button colors. It usually represents the users' choice of desktop
59
personalisation. Styling of interactive components is a typical use case.
60
Unless explicitly set, it defaults to \l highlight.
61
*/
62
63
/*!
64
\qmlproperty color QtQuick::ColorGroup::alternateBase
65
66
Used as the alternate background color in item views with alternating row colors.
67
*/
68
69
/*!
70
\qmlproperty color QtQuick::ColorGroup::base
71
72
Used mostly as the background color for text editor controls and item views.
73
It is usually white or another light color.
74
*/
75
76
/*!
77
\qmlproperty color QtQuick::ColorGroup::brightText
78
79
A text color that is very different from \c windowText, and contrasts
80
well with e.g. \c dark. Typically used for text that needs to be drawn
81
where \c text, \c windowText or \c buttonText would
82
give poor contrast, such as on highlighted buttons.
83
*/
84
85
/*!
86
\qmlproperty color QtQuick::ColorGroup::button
87
88
The general button background color. This background can be different from
89
\c window as some styles require a different background color for buttons.
90
*/
91
92
/*!
93
\qmlproperty color QtQuick::ColorGroup::buttonText
94
95
A foreground color used with the \c palette color.
96
*/
97
98
/*!
99
\qmlproperty color QtQuick::ColorGroup::dark
100
101
A foreground color used with the \c palette color.
102
*/
103
104
/*!
105
\qmlproperty color QtQuick::ColorGroup::highlight
106
107
A color to indicate a selected item or the current item.
108
*/
109
110
/*!
111
\qmlproperty color QtQuick::ColorGroup::highlightedText
112
113
A text color that contrasts with \c highlight.
114
*/
115
116
/*!
117
\qmlproperty color QtQuick::ColorGroup::light
118
119
Lighter than \c button.
120
*/
121
122
/*!
123
\qmlproperty color QtQuick::ColorGroup::link
124
125
A text color used for hyperlinks.
126
*/
127
128
/*!
129
\qmlproperty color QtQuick::ColorGroup::linkVisited
130
131
A text color used for already visited hyperlinks.
132
*/
133
134
/*!
135
\qmlproperty color QtQuick::ColorGroup::mid
136
137
Between \c palette.button and \c dark.
138
*/
139
140
/*!
141
\qmlproperty color QtQuick::ColorGroup::midlight
142
143
Between \c button and \c light.
144
*/
145
146
/*!
147
\qmlproperty color QtQuick::ColorGroup::shadow
148
149
A very dark color.
150
*/
151
152
/*!
153
\qmlproperty color QtQuick::ColorGroup::text
154
155
The foreground color used with \c base. This is usually the same as
156
the \c windowText, in which case it must provide good contrast with
157
\c window and \c base.
158
*/
159
160
/*!
161
\qmlproperty color QtQuick::ColorGroup::toolTipBase
162
163
Used as the background color for tooltips.
164
*/
165
166
/*!
167
\qmlproperty color QtQuick::ColorGroup::toolTipText
168
169
Used as the foreground color for tooltips.
170
*/
171
172
/*!
173
\qmlproperty color QtQuick::ColorGroup::window
174
175
A general background color.
176
*/
177
178
/*!
179
\qmlproperty color QtQuick::ColorGroup::windowText
180
181
A general foreground color.
182
*/
183
184
/*!
185
\qmlproperty color QtQuick::ColorGroup::placeholderText
186
\since 6.2
187
188
Used as the place holder color for editable single line fields.
189
*/
190
191
/*!
192
\qmlsignal QtQuick::ColorGroup::changed
193
194
Additional signal indicates that the current state of this color group
195
has been changed. Usually it means that one of the colors is changed.
196
*/
197
198
/*!
199
Construct object in default state.
200
*/
201
QQuickColorGroup::QQuickColorGroup(QQuickPalette &parent)
202
: QObject(&parent)
203
, m_groupTag(defaultGroupTag())
204
, m_colorProvider(parent.colorProvider().shared_from_this())
205
{
206
}
207
208
QPalette::ColorGroup QQuickColorGroup::currentColorGroup()
const
209
{
210
return
groupTag();
211
}
212
213
QColor QQuickColorGroup::alternateBase()
const
214
{
215
return
color(QPalette::AlternateBase);
216
}
217
218
void
QQuickColorGroup::setAlternateBase(
const
QColor &color)
219
{
220
setColor(QPalette::AlternateBase, color, &QQuickColorGroup::alternateBaseChanged);
221
}
222
223
void
QQuickColorGroup::resetAlternateBase()
224
{
225
resetColor(QPalette::AlternateBase, &QQuickColorGroup::alternateBaseChanged);
226
}
227
228
QColor QQuickColorGroup::base()
const
229
{
230
return
color(QPalette::Base);
231
}
232
233
void
QQuickColorGroup::setBase(
const
QColor &color)
234
{
235
setColor(QPalette::Base, color, &QQuickColorGroup::baseChanged);
236
}
237
238
void
QQuickColorGroup::resetBase()
239
{
240
resetColor(QPalette::Base, &QQuickColorGroup::baseChanged);
241
}
242
243
QColor QQuickColorGroup::brightText()
const
244
{
245
return
color(QPalette::BrightText);
246
}
247
248
void
QQuickColorGroup::setBrightText(
const
QColor &color)
249
{
250
setColor(QPalette::BrightText, color, &QQuickColorGroup::brightTextChanged);
251
}
252
253
void
QQuickColorGroup::resetBrightText()
254
{
255
resetColor(QPalette::BrightText, &QQuickColorGroup::brightTextChanged);
256
}
257
258
QColor QQuickColorGroup::button()
const
259
{
260
return
color(QPalette::Button);
261
}
262
263
void
QQuickColorGroup::setButton(
const
QColor &color)
264
{
265
setColor(QPalette::Button, color, &QQuickColorGroup::buttonChanged);
266
}
267
268
void
QQuickColorGroup::resetButton()
269
{
270
resetColor(QPalette::Button, &QQuickColorGroup::buttonChanged);
271
}
272
273
QColor QQuickColorGroup::buttonText()
const
274
{
275
return
color(QPalette::ButtonText);
276
}
277
278
void
QQuickColorGroup::setButtonText(
const
QColor &color)
279
{
280
setColor(QPalette::ButtonText, color, &QQuickColorGroup::buttonTextChanged);
281
}
282
283
void
QQuickColorGroup::resetButtonText()
284
{
285
resetColor(QPalette::ButtonText, &QQuickColorGroup::buttonTextChanged);
286
}
287
288
QColor QQuickColorGroup::dark()
const
289
{
290
return
color(QPalette::Dark);
291
}
292
293
void
QQuickColorGroup::setDark(
const
QColor &color)
294
{
295
setColor(QPalette::Dark, color, &QQuickColorGroup::darkChanged);
296
}
297
298
void
QQuickColorGroup::resetDark()
299
{
300
resetColor(QPalette::Dark, &QQuickColorGroup::darkChanged);
301
}
302
303
QColor QQuickColorGroup::highlight()
const
304
{
305
return
color(QPalette::Highlight);
306
}
307
308
void
QQuickColorGroup::setHighlight(
const
QColor &color)
309
{
310
setColor(QPalette::Highlight, color, &QQuickColorGroup::highlightChanged);
311
}
312
313
void
QQuickColorGroup::resetHighlight()
314
{
315
resetColor(QPalette::Highlight, &QQuickColorGroup::highlightChanged);
316
}
317
318
QColor QQuickColorGroup::highlightedText()
const
319
{
320
return
color(QPalette::HighlightedText);
321
}
322
323
void
QQuickColorGroup::setHighlightedText(
const
QColor &color)
324
{
325
setColor(QPalette::HighlightedText, color, &QQuickColorGroup::highlightedTextChanged);
326
}
327
328
void
QQuickColorGroup::resetHighlightedText()
329
{
330
resetColor(QPalette::HighlightedText, &QQuickColorGroup::highlightedTextChanged);
331
}
332
333
QColor QQuickColorGroup::light()
const
334
{
335
return
color(QPalette::Light);
336
}
337
338
void
QQuickColorGroup::setLight(
const
QColor &color)
339
{
340
setColor(QPalette::Light, color, &QQuickColorGroup::lightChanged);
341
}
342
343
void
QQuickColorGroup::resetLight()
344
{
345
resetColor(QPalette::Light, &QQuickColorGroup::lightChanged);
346
}
347
348
QColor QQuickColorGroup::link()
const
349
{
350
return
color(QPalette::Link);
351
}
352
353
void
QQuickColorGroup::setLink(
const
QColor &color)
354
{
355
setColor(QPalette::Link, color, &QQuickColorGroup::linkChanged);
356
}
357
358
void
QQuickColorGroup::resetLink()
359
{
360
resetColor(QPalette::Link, &QQuickColorGroup::linkChanged);
361
}
362
363
QColor QQuickColorGroup::linkVisited()
const
364
{
365
return
color(QPalette::LinkVisited);
366
}
367
368
void
QQuickColorGroup::setLinkVisited(
const
QColor &color)
369
{
370
setColor(QPalette::LinkVisited, color, &QQuickColorGroup::linkVisitedChanged);
371
}
372
373
void
QQuickColorGroup::resetLinkVisited()
374
{
375
resetColor(QPalette::LinkVisited, &QQuickColorGroup::linkVisitedChanged);
376
}
377
378
QColor QQuickColorGroup::mid()
const
379
{
380
return
color(QPalette::Mid);
381
}
382
383
void
QQuickColorGroup::setMid(
const
QColor &color)
384
{
385
setColor(QPalette::Mid, color, &QQuickColorGroup::midChanged);
386
}
387
388
void
QQuickColorGroup::resetMid()
389
{
390
resetColor(QPalette::Mid, &QQuickColorGroup::midChanged);
391
}
392
393
QColor QQuickColorGroup::midlight()
const
394
{
395
return
color(QPalette::Midlight);
396
}
397
398
void
QQuickColorGroup::setMidlight(
const
QColor &color)
399
{
400
setColor(QPalette::Midlight, color, &QQuickColorGroup::midlightChanged);
401
}
402
403
void
QQuickColorGroup::resetMidlight()
404
{
405
resetColor(QPalette::Midlight, &QQuickColorGroup::midlightChanged);
406
}
407
408
QColor QQuickColorGroup::shadow()
const
409
{
410
return
color(QPalette::Shadow);
411
}
412
413
void
QQuickColorGroup::setShadow(
const
QColor &color)
414
{
415
setColor(QPalette::Shadow, color, &QQuickColorGroup::shadowChanged);
416
}
417
418
void
QQuickColorGroup::resetShadow()
419
{
420
resetColor(QPalette::Shadow, &QQuickColorGroup::shadowChanged);
421
}
422
423
QColor QQuickColorGroup::text()
const
424
{
425
return
color(QPalette::Text);
426
}
427
428
void
QQuickColorGroup::setText(
const
QColor &color)
429
{
430
setColor(QPalette::Text, color, &QQuickColorGroup::textChanged);
431
}
432
433
void
QQuickColorGroup::resetText()
434
{
435
resetColor(QPalette::Text, &QQuickColorGroup::textChanged);
436
}
437
438
QColor QQuickColorGroup::toolTipBase()
const
439
{
440
return
color(QPalette::ToolTipBase);
441
}
442
443
void
QQuickColorGroup::setToolTipBase(
const
QColor &color)
444
{
445
setColor(QPalette::ToolTipBase, color, &QQuickColorGroup::toolTipBaseChanged);
446
}
447
448
void
QQuickColorGroup::resetToolTipBase()
449
{
450
resetColor(QPalette::ToolTipBase, &QQuickColorGroup::toolTipBaseChanged);
451
}
452
453
QColor QQuickColorGroup::toolTipText()
const
454
{
455
return
color(QPalette::ToolTipText);
456
}
457
458
void
QQuickColorGroup::setToolTipText(
const
QColor &color)
459
{
460
setColor(QPalette::ToolTipText, color, &QQuickColorGroup::toolTipTextChanged);
461
}
462
463
void
QQuickColorGroup::resetToolTipText()
464
{
465
resetColor(QPalette::ToolTipText, &QQuickColorGroup::toolTipTextChanged);
466
}
467
468
QColor QQuickColorGroup::window()
const
469
{
470
return
color(QPalette::Window);
471
}
472
473
void
QQuickColorGroup::setWindow(
const
QColor &color)
474
{
475
setColor(QPalette::Window, color, &QQuickColorGroup::windowChanged);
476
}
477
478
void
QQuickColorGroup::resetWindow()
479
{
480
resetColor(QPalette::Window, &QQuickColorGroup::windowChanged);
481
}
482
483
QColor QQuickColorGroup::windowText()
const
484
{
485
return
color(QPalette::WindowText);
486
}
487
488
void
QQuickColorGroup::setWindowText(
const
QColor &color)
489
{
490
setColor(QPalette::WindowText, color, &QQuickColorGroup::windowTextChanged);
491
}
492
493
void
QQuickColorGroup::resetWindowText()
494
{
495
resetColor(QPalette::WindowText, &QQuickColorGroup::windowTextChanged);
496
}
497
498
QColor QQuickColorGroup::placeholderText()
const
499
{
500
return
color(QPalette::PlaceholderText);
501
}
502
503
void
QQuickColorGroup::setPlaceholderText(
const
QColor &color)
504
{
505
setColor(QPalette::PlaceholderText, color, &QQuickColorGroup::placeholderTextChanged);
506
}
507
508
void
QQuickColorGroup::resetPlaceholderText()
509
{
510
resetColor(QPalette::PlaceholderText, &QQuickColorGroup::placeholderTextChanged);
511
}
512
513
QColor QQuickColorGroup::accent()
const
514
{
515
return
color(QPalette::Accent);
516
}
517
518
void
QQuickColorGroup::setAccent(
const
QColor &color)
519
{
520
setColor(QPalette::Accent, color, &QQuickColorGroup::accentChanged);
521
}
522
523
void
QQuickColorGroup::resetAccent()
524
{
525
resetColor(QPalette::Accent, &QQuickColorGroup::accentChanged);
526
}
527
528
QPalette::ColorGroup QQuickColorGroup::groupTag()
const
529
{
530
return
m_groupTag;
531
}
532
533
QQuickColorGroup::QQuickColorGroup(QObject *parent)
534
: QObject(parent)
535
, m_groupTag(defaultGroupTag())
536
, m_colorProvider(std::make_shared<QQuickPaletteColorProvider>())
537
{
538
}
539
540
void
QQuickColorGroup::setGroupTag(QPalette::ColorGroup tag)
541
{
542
if
(m_groupTag != tag) {
543
m_groupTag = tag;
544
Q_EMIT changed();
545
}
546
}
547
548
const
QQuickPaletteColorProvider &QQuickColorGroup::colorProvider()
const
549
{
550
Q_ASSERT(m_colorProvider);
551
return
*m_colorProvider;
552
}
553
554
QQuickPaletteColorProvider &QQuickColorGroup::colorProvider()
555
{
556
return
const_cast
<QQuickPaletteColorProvider &>(
557
const_cast
<
const
QQuickColorGroup*>(
this
)->colorProvider());
558
}
559
560
QQuickColorGroup *QQuickColorGroup::createWithParent(QQuickPalette &parent)
561
{
562
return
new
QQuickColorGroup(parent);
563
}
564
565
QColor QQuickColorGroup::color(QPalette::ColorRole role)
const
566
{
567
return
colorProvider().color(currentColorGroup(), role);
568
}
569
570
void
QQuickColorGroup::setColor(QPalette::ColorRole role, QColor color, Notifier notifier)
571
{
572
if
(colorProvider().setColor(groupTag(), role, color)) {
573
Q_EMIT (
this
->*notifier)();
574
Q_EMIT changed();
575
}
576
}
577
578
void
QQuickColorGroup::resetColor(QPalette::ColorRole role, Notifier notifier)
579
{
580
if
(colorProvider().resetColor(groupTag(), role)) {
581
Q_EMIT (
this
->*notifier)();
582
Q_EMIT changed();
583
}
584
}
585
586
QT_END_NAMESPACE
587
588
#
include
"moc_qquickcolorgroup_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quick
items
qquickcolorgroup.cpp
Generated on
for Qt by
1.18.0