233void QQStyleKitStyle::setFallbackStyle(QQStyleKitStyle *fallbackStyle)
235 if (m_fallbackStyle == fallbackStyle)
238 m_fallbackStyle = fallbackStyle;
239 emit fallbackStyleChanged();
242 palettes()->setFallbackPalette(m_fallbackStyle ? m_fallbackStyle->palettes() :
nullptr);
245 fonts()->setFallbackFont(m_fallbackStyle ? m_fallbackStyle->fonts() :
nullptr);
345void QQStyleKitStyle::recreateTheme()
347 QString effectiveThemeName;
348 QQmlComponent *effectiveThemeComponent =
nullptr;
350 if (QString::compare(m_themeName, kSystem, Qt::CaseInsensitive) == 0) {
351 switch (QGuiApplication::styleHints()->colorScheme()) {
352 case Qt::ColorScheme::Dark:
353 effectiveThemeName = kDark;
354 effectiveThemeComponent = m_dark;
356 case Qt::ColorScheme::Light:
357 case Qt::ColorScheme::Unknown:
358 effectiveThemeName = kLight;
359 effectiveThemeComponent = m_light;
365 }
else if (QString::compare(m_themeName, kLight, Qt::CaseInsensitive) == 0) {
366 effectiveThemeName = kLight;
367 effectiveThemeComponent = m_light;
368 }
else if (QString::compare(m_themeName,kDark, Qt::CaseInsensitive) == 0) {
369 effectiveThemeName =kDark;
370 effectiveThemeComponent = m_dark;
371 }
else if (!m_themeName.isEmpty()){
372 for (
auto *customTheme : customThemes()) {
373 if (QString::compare(m_themeName, customTheme->name(), Qt::CaseInsensitive) == 0) {
374 effectiveThemeName = customTheme->name();
375 effectiveThemeComponent = customTheme->theme();
379 if (effectiveThemeName.isEmpty())
380 qmlWarning(
this) <<
"No theme found with themeName '" << m_themeName <<
"'";
381 else if (!effectiveThemeComponent)
382 qmlWarning(
this) <<
"Custom theme '" << effectiveThemeName <<
"' has no theme component set";
386 if (m_effectiveThemeName == effectiveThemeName)
389 m_theme->deleteLater();
393 m_effectiveThemeName = effectiveThemeName;
394 m_currentThemeComponent = effectiveThemeComponent;
396 if (effectiveThemeComponent) {
397 if (effectiveThemeComponent->status() != QQmlComponent::Ready) {
398 qmlWarning(
this) <<
"failed to create theme '" << effectiveThemeName <<
"': " << effectiveThemeComponent->errorString();
401
402
403
404
405 QVariant themeAsVariant;
406 QMetaObject::invokeMethod(
this,
"createThemeInsideStyle", Qt::DirectConnection,
407 qReturnArg(themeAsVariant), QVariant::fromValue(effectiveThemeComponent));
408 m_theme = qvariant_cast<QQStyleKitTheme *>(themeAsVariant);
410 if (!m_theme || !effectiveThemeComponent->errorString().isEmpty()) {
411 qmlWarning(
this) <<
"failed to create theme '" << effectiveThemeName <<
"': " << effectiveThemeComponent->errorString();
413 m_theme->setParent(
this);
420 m_theme =
new QQStyleKitTheme(
this);
421 m_theme->setObjectName(
"<empty theme>"_L1);
422 m_theme->m_completed =
true;
424 m_theme->setParent(
this);
427 if (m_theme->fonts())
428 m_theme->fonts()->setFallbackFont(fonts());
429 if (m_theme->palettes())
430 m_theme->palettes()->setFallbackPalette(palettes());