Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include "qquicktheme_p.h"
5#include "qquicktheme_p_p.h"
6
7#include <QtGui/qpa/qplatformtheme.h>
8#include <QtGui/private/qguiapplication_p.h>
9
11
12std::unique_ptr<QQuickTheme> QQuickThemePrivate::instance;
13
14static void cleanup_instance()
15{
17}
18
23
25
50
75
80
84
89
91{
92 const QFont *font = nullptr;
93 if (QQuickTheme *theme = instance())
94 font = QQuickThemePrivate::get(theme)->fonts[scope].data();
96 font = theme->font(platformFont(scope));
97
98 if (font) {
99 QFont f = *font;
100 if (scope == System)
101 f.setResolveMask(0);
102 return f;
103 }
104
105 if (scope != System)
107
108 return QFont();
109}
110
112{
113 const QPalette *palette = nullptr;
114
115 if (auto theme = instance()) {
116 if (theme->usePlatformPalette()) {
117 if (auto platformTheme = QGuiApplicationPrivate::platformTheme()) {
118 palette = platformTheme->palette(platformPalette(scope));
119 // In case, if palettes are provided through configuration file
120 // (qtquickcontrols2.conf), then respect configuration palette
121 // and resolve it with platform palette
122 if (palette) {
124 if (p->defaultPalette && p->defaultPalette->resolveMask() != 0) {
125 QPalette defPalette = *p->defaultPalette;
126 defPalette.resolve(*palette);
127 if (scope == System)
128 defPalette.setResolveMask(0);
129 return defPalette;
130 }
131 }
132 }
133 } else {
134 palette = QQuickThemePrivate::get(theme)->palettes[scope].data();
135 }
136 }
137
138 if (palette) {
139 QPalette f = *palette;
140 if (scope == System)
141 f.setResolveMask(0);
142 return f;
143 }
144
145 if (scope != System)
147
148 return QPalette();
149}
150
152{
153 Q_D(QQuickTheme);
154 d->fonts[scope] = QSharedPointer<QFont>::create(d->defaultFont ? d->defaultFont->resolve(font) : font);
155}
156
158{
159 Q_D(QQuickTheme);
160 d->palettes[scope] = QSharedPointer<QPalette>::create(d->defaultPalette ? d->defaultPalette->resolve(palette) : palette);
161}
162
\reentrant
Definition qfont.h:22
void setResolveMask(uint mask)
Definition qfont.h:313
static QPlatformTheme * platformTheme()
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
void setResolveMask(ResolveMask mask)
QPalette resolve(const QPalette &other) const
Returns a new QPalette that is a union of this instance and other.
Definition qpalette.cpp:963
The QPlatformTheme class allows customizing the UI based on themes.
static QQuickThemePrivate * get(QQuickTheme *theme)
static std::unique_ptr< QQuickTheme > instance
static QQuickTheme * instance()
void setFont(Scope scope, const QFont &font)
void setPalette(Scope scope, const QPalette &palette)
static QPalette palette(Scope scope)
static QFont font(Scope scope)
static QSharedPointer create(Args &&...arguments)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Combined button and popup list for selecting options.
void qAddPostRoutine(QtCleanUpFunction p)
#define Q_COREAPP_STARTUP_FUNCTION(AFUNC)
GLfloat GLfloat f
GLfloat GLfloat p
[1]
static void install_instance_cleanuper()
static QPlatformTheme::Palette platformPalette(QQuickTheme::Scope scope)
static QPlatformTheme::Font platformFont(QQuickTheme::Scope scope)
static void cleanup_instance()