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
qquicktheme.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 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
5
#
include
"qquicktheme_p.h"
6
#
include
"qquicktheme_p_p.h"
7
8
#
include
<
QtGui
/
qpa
/
qplatformtheme
.
h
>
9
#
include
<
QtGui
/
private
/
qguiapplication_p
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
std::unique_ptr<QQuickTheme> QQuickThemePrivate::instance;
14
15
static
void
cleanup_instance
()
16
{
17
QQuickThemePrivate::instance.reset();
18
}
19
20
static
void
install_instance_cleanuper
()
21
{
22
qAddPostRoutine(
cleanup_instance
);
23
}
24
25
Q_COREAPP_STARTUP_FUNCTION(install_instance_cleanuper)
26
27
static
QPlatformTheme
::
Font
platformFont
(QQuickTheme::Scope scope)
28
{
29
switch
(scope) {
30
case
QQuickTheme::Button:
return
QPlatformTheme::PushButtonFont;
31
case
QQuickTheme::CheckBox:
return
QPlatformTheme::CheckBoxFont;
32
case
QQuickTheme::ComboBox:
return
QPlatformTheme::ComboMenuItemFont;
33
case
QQuickTheme::GroupBox:
return
QPlatformTheme::GroupBoxTitleFont;
34
case
QQuickTheme::ItemView:
return
QPlatformTheme::ItemViewFont;
35
case
QQuickTheme::Label:
return
QPlatformTheme::LabelFont;
36
case
QQuickTheme::ListView:
return
QPlatformTheme::ListViewFont;
37
case
QQuickTheme::Menu:
return
QPlatformTheme::MenuFont;
38
case
QQuickTheme::MenuBar:
return
QPlatformTheme::MenuBarFont;
39
case
QQuickTheme::RadioButton:
return
QPlatformTheme::RadioButtonFont;
40
case
QQuickTheme::SpinBox:
return
QPlatformTheme::EditorFont;
41
case
QQuickTheme::Switch:
return
QPlatformTheme::CheckBoxFont;
42
case
QQuickTheme::TabBar:
return
QPlatformTheme::TabButtonFont;
43
case
QQuickTheme::TextArea:
return
QPlatformTheme::EditorFont;
44
case
QQuickTheme::TextField:
return
QPlatformTheme::EditorFont;
45
case
QQuickTheme::ToolBar:
return
QPlatformTheme::ToolButtonFont;
46
case
QQuickTheme::ToolTip:
return
QPlatformTheme::TipLabelFont;
47
case
QQuickTheme::Tumbler:
return
QPlatformTheme::ItemViewFont;
48
default
:
return
QPlatformTheme::SystemFont;
49
}
50
}
51
52
static
QPlatformTheme
::
Palette
platformPalette
(QQuickTheme::Scope scope)
53
{
54
switch
(scope) {
55
case
QQuickTheme::Button:
return
QPlatformTheme::ButtonPalette;
56
case
QQuickTheme::CheckBox:
return
QPlatformTheme::CheckBoxPalette;
57
case
QQuickTheme::ComboBox:
return
QPlatformTheme::ComboBoxPalette;
58
case
QQuickTheme::GroupBox:
return
QPlatformTheme::GroupBoxPalette;
59
case
QQuickTheme::ItemView:
return
QPlatformTheme::ItemViewPalette;
60
case
QQuickTheme::Label:
return
QPlatformTheme::LabelPalette;
61
case
QQuickTheme::ListView:
return
QPlatformTheme::ItemViewPalette;
62
case
QQuickTheme::Menu:
return
QPlatformTheme::MenuPalette;
63
case
QQuickTheme::MenuBar:
return
QPlatformTheme::MenuBarPalette;
64
case
QQuickTheme::RadioButton:
return
QPlatformTheme::RadioButtonPalette;
65
case
QQuickTheme::SpinBox:
return
QPlatformTheme::TextLineEditPalette;
66
case
QQuickTheme::Switch:
return
QPlatformTheme::CheckBoxPalette;
67
case
QQuickTheme::TabBar:
return
QPlatformTheme::TabBarPalette;
68
case
QQuickTheme::TextArea:
return
QPlatformTheme::TextEditPalette;
69
case
QQuickTheme::TextField:
return
QPlatformTheme::TextLineEditPalette;
70
case
QQuickTheme::ToolBar:
return
QPlatformTheme::ToolButtonPalette;
71
case
QQuickTheme::ToolTip:
return
QPlatformTheme::ToolTipPalette;
72
case
QQuickTheme::Tumbler:
return
QPlatformTheme::ItemViewPalette;
73
default
:
return
QPlatformTheme::SystemPalette;
74
}
75
}
76
77
QQuickTheme::QQuickTheme()
78
: d_ptr(
new
QQuickThemePrivate)
79
{
80
}
81
82
QQuickTheme::~QQuickTheme()
83
{
84
}
85
86
QQuickTheme *QQuickTheme::instance()
87
{
88
return
QQuickThemePrivate::instance.get();
89
}
90
91
QFont QQuickTheme::font(Scope scope)
92
{
93
const
QFont *font =
nullptr
;
94
if
(QQuickTheme *theme = instance())
95
font = QQuickThemePrivate::get(theme)->fonts[scope].data();
96
else
if
(QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
97
font = theme->font(platformFont(scope));
98
99
if
(font) {
100
QFont f = *font;
101
if
(scope == System)
102
f.setResolveMask(0);
103
return
f;
104
}
105
106
if
(scope != System)
107
return
QQuickTheme::font(System);
108
109
return
QFont();
110
}
111
112
QPalette QQuickTheme::palette(Scope scope)
113
{
114
const
QPalette *palette =
nullptr
;
115
116
if
(
auto
theme = instance()) {
117
if
(theme->usePlatformPalette()) {
118
if
(
auto
platformTheme = QGuiApplicationPrivate::platformTheme()) {
119
palette = platformTheme->palette(platformPalette(scope));
120
// In case, if palettes are provided through configuration file
121
// (qtquickcontrols2.conf), then respect configuration palette
122
// and resolve it with platform palette
123
if
(palette) {
124
QQuickThemePrivate *p = QQuickThemePrivate::get(theme);
125
if
(p->defaultPalette && p->defaultPalette->resolveMask() != 0) {
126
QPalette defPalette = *p->defaultPalette;
127
defPalette.resolve(*palette);
128
if
(scope == System)
129
defPalette.setResolveMask(0);
130
return
defPalette;
131
}
132
}
133
}
134
}
else
{
135
palette = QQuickThemePrivate::get(theme)->palettes[scope].data();
136
}
137
}
138
139
if
(palette) {
140
QPalette f = *palette;
141
if
(scope == System)
142
f.setResolveMask(0);
143
return
f;
144
}
145
146
if
(scope != System)
147
return
QQuickTheme::palette(System);
148
149
return
QPalette();
150
}
151
152
void
QQuickTheme::setFont(Scope scope,
const
QFont &font)
153
{
154
Q_D(QQuickTheme);
155
d->fonts[scope] = QSharedPointer<QFont>::create(d->defaultFont ? d->defaultFont->resolve(font) : font);
156
}
157
158
void
QQuickTheme::setPalette(Scope scope,
const
QPalette &palette)
159
{
160
Q_D(QQuickTheme);
161
d->palettes[scope] = QSharedPointer<QPalette>::create(d->defaultPalette ? d->defaultPalette->resolve(palette) : palette);
162
}
163
164
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
install_instance_cleanuper
static void install_instance_cleanuper()
Definition
qquicktheme.cpp:20
platformPalette
static QPlatformTheme::Palette platformPalette(QQuickTheme::Scope scope)
Definition
qquicktheme.cpp:52
platformFont
static QPlatformTheme::Font platformFont(QQuickTheme::Scope scope)
Definition
qquicktheme.cpp:27
cleanup_instance
static void cleanup_instance()
Definition
qquicktheme.cpp:15
qtdeclarative
src
quicktemplates
qquicktheme.cpp
Generated on
for Qt by
1.18.0