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
qquickimaginestyle.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
5
6#if QT_CONFIG(settings)
7#include <QtCore/qsettings.h>
8#endif
9#include <QtQuickControls2/private/qquickstyle_p.h>
10
12
13Q_GLOBAL_STATIC_WITH_ARGS(QString, GlobalPath, (QLatin1String("qrc:/qt-project.org/imports/QtQuick/Controls/Imagine/images/")))
14
15static QString ensureSlash(const QString &path)
16{
17 const QChar slash = QLatin1Char('/');
18 return path.endsWith(slash) ? path : path + slash;
19}
20
23 m_path(*GlobalPath())
24{
25 init();
26}
27
32
34{
35 return m_path;
36}
37
39{
40 m_explicitPath = true;
41 if (m_path == path)
42 return;
43
44 m_path = path;
46
48}
49
51{
52 if (m_explicitPath || m_path == path)
53 return;
54
55 m_path = path;
58}
59
61{
62 const auto styles = attachedChildren();
64 QQuickImagineStyle *imagine = qobject_cast<QQuickImagineStyle *>(child);
65 if (imagine)
66 imagine->inheritPath(m_path);
67 }
68}
69
71{
72 if (!m_explicitPath)
73 return;
74
75 m_explicitPath = false;
76 QQuickImagineStyle *imagine = qobject_cast<QQuickImagineStyle *>(attachedParent());
77 inheritPath(imagine ? imagine->path() : *GlobalPath());
78}
79
81{
82 // Using ApplicationWindow as an example, its NinePatchImage url
83 // was previously assigned like this:
84 //
85 // soruce: Imagine.path + "applicationwindow-background"
86 //
87 // If Imagine.path is set to ":/images" by the user, then the final URL would be:
88 //
89 // QUrl("file:///home/user/qt/qtbase/qml/QtQuick/Controls/Imagine/:/images/applicationwindow-background")
90 //
91 // To ensure that the correct URL is constructed, we do it ourselves here,
92 // and then the control QML files use the "url" property instead.
93 const QString path = ensureSlash(m_path);
94 if (path.startsWith(QLatin1String("qrc")))
95 return QUrl(path);
96
97 if (path.startsWith(QLatin1String(":/")))
98 return QUrl(QLatin1String("qrc") + path);
99
101}
102
104{
105 Q_UNUSED(oldParent);
106 QQuickImagineStyle *imagine = qobject_cast<QQuickImagineStyle *>(newParent);
107 if (imagine)
108 inheritPath(imagine->path());
109}
110
111static QByteArray resolveSetting(const QByteArray &env, const QSharedPointer<QSettings> &settings, const QString &name)
112{
113 QByteArray value = qgetenv(env);
114#if QT_CONFIG(settings)
115 if (value.isNull() && !settings.isNull())
117#endif
118 return value;
119}
120
121void QQuickImagineStyle::init()
122{
123 static bool globalsInitialized = false;
124 if (!globalsInitialized) {
125 QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(QStringLiteral("Imagine"));
126
127 QString path = QString::fromUtf8(resolveSetting("QT_QUICK_CONTROLS_IMAGINE_PATH", settings, QStringLiteral("Path")));
128 if (!path.isEmpty())
129 *GlobalPath() = m_path = ensureSlash(path);
130
131 globalsInitialized = true;
132 }
133
135}
136
138
139#include "moc_qquickimaginestyle_p.cpp"
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
The QQuickAttachedPropertyPropagator class provides a way to propagate attached properties.
QQuickAttachedPropertyPropagator * attachedParent() const
This function returns the attached parent of this attached object.
QList< QQuickAttachedPropertyPropagator * > attachedChildren() const
This function returns the attached children of this attached object.
void initialize()
Finds and sets the attached parent for this attached object, and then does the same for its children.
static QQuickImagineStyle * qmlAttachedProperties(QObject *object)
void inheritPath(const QString &path)
void setPath(const QString &path)
void attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent) override
This function is called whenever the attached parent of this QQuickAttachedPropertyPropagator changes...
QQuickImagineStyle(QObject *parent=nullptr)
static QSharedPointer< QSettings > settings(const QString &group=QString())
QVariant value(QAnyStringView key, const QVariant &defaultValue) const
Returns the value for setting key.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
\inmodule QtCore
Definition qurl.h:94
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3368
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has userType() \l QMetaType::QByteArray or \l QMet...
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
GLuint name
GLsizei const GLchar *const * path
static QByteArray resolveSetting(const QByteArray &env, const QSharedPointer< QSettings > &settings, const QString &name)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
#define emit
#define Q_UNUSED(x)
QSettings settings("MySoft", "Star Runner")
[0]
QLayoutItem * child
[0]
\inmodule QtCore \reentrant
Definition qchar.h:18