8#include <QtCore/qsettings.h>
10#include <QtQuickControls2/private/qquickstyle_p.h>
14Q_GLOBAL_STATIC_WITH_ARGS(QString, GlobalPath, (QLatin1String(
"qrc:/qt-project.org/imports/QtQuick/Controls/Imagine/images/")))
16static QString ensureSlash(
const QString &path)
18 const QChar slash = QLatin1Char(
'/');
19 return path.endsWith(slash) ? path : path + slash;
22QQuickImagineStyle::QQuickImagineStyle(QObject *parent)
23 : QQuickAttachedPropertyPropagator(parent),
29QQuickImagineStyle *QQuickImagineStyle::qmlAttachedProperties(QObject *object)
31 return new QQuickImagineStyle(object);
34QString QQuickImagineStyle::path()
const
39void QQuickImagineStyle::setPath(
const QString &path)
41 m_explicitPath =
true;
51void QQuickImagineStyle::inheritPath(
const QString &path)
53 if (m_explicitPath || m_path == path)
61void QQuickImagineStyle::propagatePath()
63 const auto styles = attachedChildren();
64 for (QQuickAttachedPropertyPropagator *child : styles) {
65 QQuickImagineStyle *imagine = qobject_cast<QQuickImagineStyle *>(child);
67 imagine->inheritPath(m_path);
71void QQuickImagineStyle::resetPath()
76 m_explicitPath =
false;
77 QQuickImagineStyle *imagine = qobject_cast<QQuickImagineStyle *>(attachedParent());
78 inheritPath(imagine ? imagine->path() : *GlobalPath());
81QUrl QQuickImagineStyle::url()
const
94 const QString path = ensureSlash(m_path);
95 if (path.startsWith(QLatin1String(
"qrc")))
98 if (path.startsWith(QLatin1String(
":/")))
99 return QUrl(QLatin1String(
"qrc") + path);
101 return QUrl::fromLocalFile(path);
104void QQuickImagineStyle::attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent)
107 QQuickImagineStyle *imagine = qobject_cast<QQuickImagineStyle *>(newParent);
109 inheritPath(imagine->path());
114 QByteArray value = qgetenv(env);
115#if QT_CONFIG(settings)
116 if (value.isNull() && !settings.isNull())
117 value = settings->value(name).toByteArray();
122void QQuickImagineStyle::init()
124 static bool globalsInitialized =
false;
125 if (!globalsInitialized) {
126 QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(QStringLiteral(
"Imagine"));
128 QString path = QString::fromUtf8(resolveSetting(
"QT_QUICK_CONTROLS_IMAGINE_PATH", settings, QStringLiteral(
"Path")));
130 *GlobalPath() = m_path = ensureSlash(path);
132 globalsInitialized =
true;
135 QQuickAttachedPropertyPropagator::initialize();
140#include "moc_qquickimaginestyle_p.cpp"
static QByteArray resolveSetting(const QByteArray &env, const QSharedPointer< QSettings > &settings, const QString &name)