Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickstyleplugin.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
4#include "qquickstyle.h"
5#include "qquickstyle_p.h"
7
8#include <QtCore/private/qfileselector_p.h>
9#include <QtCore/qloggingcategory.h>
10#include <QtGui/qstylehints.h>
11#include <QtGui/qguiapplication.h>
12#include <QtQml/qqmlengine.h>
13#include <QtQml/qqmlfile.h>
14#include <QtQml/private/qqmlmetatype_p.h>
15#include <QtQuickTemplates2/private/qquicktheme_p_p.h>
16
18
19Q_LOGGING_CATEGORY(lcStylePlugin, "qt.quick.controls.styleplugin")
20
23{
24}
25
27{
28}
29
31{
32 qCDebug(lcStylePlugin).nospace() << "registerTypes called with uri " << uri << "; plugin name is " << name();
33
34 const QTypeRevision latestControlsRevision = QQmlMetaType::latestModuleVersion(QLatin1String("QtQuick.Controls"));
35 // Use the private function because we don't want to cause resolve() to be called,
36 // as the logic that assigns a default style if one wasn't set would interfere with compile-time style selection.
38 if (!latestControlsRevision.isValid() && styleName.isEmpty()) {
39 // The user hasn't imported QtQuick.Controls, nor set a style via the runtime methods.
40 qCDebug(lcStylePlugin).nospace() << uri << " imported before QtQuick.Controls; using compile-time style selection";
42 styleName = name();
43 }
44
45 // Even if this style plugin isn't for the style set by the user,
46 // we still want to create the theme object, because that function
47 // is also responsible for reading values from qtquickcontrols2.conf.
48 // So, even if a style doesn't have a QQuickTheme, it can still have
49 // values set for (e.g. fonts and palettes) in qtquickcontrols2.conf.
50 const QString effectiveCurrentStyleName = QQuickStylePrivate::effectiveStyleName(styleName);
51 auto theme = QQuickTheme::instance();
52 if (!theme) {
53 qCDebug(lcStylePlugin) << "creating theme";
54 theme = createTheme(effectiveCurrentStyleName);
55 }
56
57 if (name() != effectiveCurrentStyleName) {
58 qCDebug(lcStylePlugin).nospace() << "theme does not belong to current style ("
59 << effectiveCurrentStyleName << "); not calling initializeTheme()";
60 return;
61 }
62
63 qCDebug(lcStylePlugin) << "theme has not yet been initialized; calling initializeTheme()";
64 initializeTheme(theme);
67
68 if (!styleName.isEmpty())
70}
71
73{
74 qCDebug(lcStylePlugin) << "unregisterTypes called; plugin name is" << name();
76 return;
77
80
81 // Not every style has a plugin - some styles are QML-only. So, we clean this
82 // stuff up when the first style plugin is unregistered rather than when the
83 // plugin for the current style is unregistered.
86}
87
100QQuickTheme *QQuickStylePlugin::createTheme(const QString &name)
101{
102 qCDebug(lcStylePlugin) << "creating QQuickTheme instance to be initialized by style-specific theme of" << name;
103
104 QQuickTheme *theme = new QQuickTheme;
105#if QT_CONFIG(settings)
108 if (settings) {
109 p->defaultFont.reset(QQuickStylePrivate::readFont(settings));
110 // Set the default font as the System scope, because that's what
111 // QQuickControlPrivate::parentFont() uses as its fallback if no
112 // parent item has a font explicitly set. QQuickControlPrivate::parentFont()
113 // is used as the starting point for font inheritance/resolution.
114 // The same goes for palettes below.
115 theme->setFont(QQuickTheme::System, *p->defaultFont);
116
117 p->defaultPalette.reset(QQuickStylePrivate::readPalette(settings));
118 theme->setPalette(QQuickTheme::System, *p->defaultPalette);
119 }
120#endif
121 QQuickThemePrivate::instance.reset(theme);
122 return theme;
123}
124
126
127#include "moc_qquickstyleplugin_p.cpp"
static void addStatics(const QStringList &)
static QStyleHints * styleHints()
Returns the application's style hints.
\inmodule QtCore
Definition qobject.h:90
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
The QQmlExtensionPlugin class provides an abstract base for custom QML extension plugins with custom ...
static QTypeRevision latestModuleVersion(const QString &uri)
void registerTypes(const char *uri) override
Registers the QML types in the given uri.
virtual void updateTheme()
void unregisterTypes() override
virtual QString name() const =0
virtual void initializeTheme(QQuickTheme *theme)=0
static QString effectiveStyleName(const QString &styleName)
static void reset()
static const QFont * readFont(const QSharedPointer< QSettings > &settings)
static QSharedPointer< QSettings > settings(const QString &group=QString())
static QString style()
static const QPalette * readPalette(const QSharedPointer< QSettings > &settings)
static void setStyle(const QString &style)
Sets the application style to style.
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)
\inmodule QtCore
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
void colorSchemeChanged(Qt::ColorScheme colorScheme)
\inmodule QtCore
constexpr bool isValid() const
Returns true if the major version or the minor version is known, otherwise false.
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLuint name
GLfloat GLfloat p
[1]
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
QSettings settings("MySoft", "Star Runner")
[0]
myObject disconnect()
[26]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent