94
95
96 if (!QQStyleKitAttached::s_instance)
97 QQStyleKitAttached::s_instance =
new QQStyleKitAttached(QGuiApplication::instance());
98 if (!QQStyleKitAttached::s_instance->m_engine && obj)
99 QQStyleKitAttached::s_instance->m_engine = qmlEngine(obj);
100 return QQStyleKitAttached::s_instance.get();
106 connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged,
this, [
this](){
107 if (m_style && QString::compare(m_style->themeName(),
"System"_L1, Qt::CaseInsensitive) == 0)
108 m_style->recreateTheme();
147 if (m_styleUrl == styleUrl)
150 m_styleUrl = styleUrl;
153 QQmlComponent component(m_engine, styleUrl,
this);
154 if (!component.errors().isEmpty()) {
155 qmlWarning(
this) <<
"Could not create a Style from url '" << styleUrl <<
"': " << component.errorString();
160
161
162 QQmlComponentPrivate *componentPrivate = QQmlComponentPrivate::get(&component);
163 const auto compilationUnit = componentPrivate->compilationUnit();
164 const auto propertyCache = compilationUnit ? compilationUnit->rootPropertyCache() :
nullptr;
165 const auto firstMetaObject = propertyCache ? propertyCache->firstCppMetaObject() :
nullptr;
166 if (!firstMetaObject || !firstMetaObject->inherits(&QQStyleKitStyle::staticMetaObject)) {
167 qmlWarning(
this) <<
"Could not create a Style from url '" << styleUrl <<
"': the root item is not a Style.";
171 auto *style = qobject_cast<QQStyleKitStyle *>(component.create());
173 qmlWarning(
this) <<
"Could not create a Style from url '" << styleUrl <<
"': failed to create an instance of the resolved Component.";
177 style->componentComplete();
180 emit styleUrlChanged();