239void QQStyleKitStyle::setFallbackStyle(QQStyleKitStyle *fallbackStyle)
241 if (m_fallbackStyle == fallbackStyle)
244 if (fallbackStyle && fallbackStyle->dependsOn(
this)) {
245 qmlWarning(
this) <<
"Cannot set fallbackStyle to style with objectName '"
246 << fallbackStyle->objectName()
247 <<
"', since that would create a loop in the fallback chain!";
251 m_fallbackStyle = fallbackStyle;
254 palettes()->setFallbackPalette(m_fallbackStyle ? m_fallbackStyle->palettes() :
nullptr);
257 fonts()->setFallbackFont(m_fallbackStyle ? m_fallbackStyle->fonts() :
nullptr);
259 reapplyStylesDependingOnThis();
260 emit fallbackStyleChanged();
354void QQStyleKitStyle::recreateTheme()
356 QString effectiveThemeName;
357 QQmlComponent *effectiveThemeComponent =
nullptr;
359 if (QString::compare(m_themeName, kSystem, Qt::CaseInsensitive) == 0) {
360 switch (QGuiApplication::styleHints()->colorScheme()) {
361 case Qt::ColorScheme::Dark:
362 effectiveThemeName = kDark;
363 effectiveThemeComponent = m_dark;
365 case Qt::ColorScheme::Light:
366 case Qt::ColorScheme::Unknown:
367 effectiveThemeName = kLight;
368 effectiveThemeComponent = m_light;
374 }
else if (QString::compare(m_themeName, kLight, Qt::CaseInsensitive) == 0) {
375 effectiveThemeName = kLight;
376 effectiveThemeComponent = m_light;
377 }
else if (QString::compare(m_themeName,kDark, Qt::CaseInsensitive) == 0) {
378 effectiveThemeName =kDark;
379 effectiveThemeComponent = m_dark;
380 }
else if (!m_themeName.isEmpty()){
381 for (
auto *customTheme : customThemes()) {
382 if (QString::compare(m_themeName, customTheme->name(), Qt::CaseInsensitive) == 0) {
383 effectiveThemeName = customTheme->name();
384 effectiveThemeComponent = customTheme->theme();
388 if (effectiveThemeName.isEmpty())
389 qmlWarning(
this) <<
"No theme found with themeName '" << m_themeName <<
"'";
390 else if (!effectiveThemeComponent)
391 qmlWarning(
this) <<
"Custom theme '" << effectiveThemeName <<
"' has no theme component set";
395 if (m_effectiveThemeName == effectiveThemeName)
398 m_theme->deleteLater();
402 m_effectiveThemeName = effectiveThemeName;
403 m_currentThemeComponent = effectiveThemeComponent;
405 if (effectiveThemeComponent) {
406 if (effectiveThemeComponent->status() != QQmlComponent::Ready) {
407 qmlWarning(
this) <<
"failed to create theme '" << effectiveThemeName <<
"': " << effectiveThemeComponent->errorString();
410
411
412
413
414 QVariant themeAsVariant;
415 QMetaObject::invokeMethod(
this,
"createThemeInsideStyle", Qt::DirectConnection,
416 qReturnArg(themeAsVariant), QVariant::fromValue(effectiveThemeComponent));
417 m_theme = qvariant_cast<QQStyleKitTheme *>(themeAsVariant);
419 if (!m_theme || !effectiveThemeComponent->errorString().isEmpty()) {
420 qmlWarning(
this) <<
"failed to create theme '" << effectiveThemeName <<
"': " << effectiveThemeComponent->errorString();
422 m_theme->setParent(
this);
429 m_theme =
new QQStyleKitTheme(
this);
430 m_theme->setObjectName(
"<empty theme>"_L1);
431 m_theme->m_completed =
true;
433 m_theme->setParent(
this);
436 if (m_theme->fonts())
437 m_theme->fonts()->setFallbackFont(fonts());
438 if (m_theme->palettes())
439 m_theme->palettes()->setFallbackPalette(palettes());