232void QQStyleKitStyle::setFallbackStyle(QQStyleKitStyle *fallbackStyle)
234 if (m_fallbackStyle == fallbackStyle)
237 m_fallbackStyle = fallbackStyle;
238 emit fallbackStyleChanged();
241 palettes()->setFallbackPalette(m_fallbackStyle ? m_fallbackStyle->palettes() :
nullptr);
244 fonts()->setFallbackFont(m_fallbackStyle ? m_fallbackStyle->fonts() :
nullptr);
344void QQStyleKitStyle::recreateTheme()
346 QString effectiveThemeName;
347 QQmlComponent *effectiveThemeComponent =
nullptr;
349 if (QString::compare(m_themeName, kSystem, Qt::CaseInsensitive) == 0) {
350 const auto scheme = QGuiApplication::styleHints()->colorScheme();
351 if (scheme == Qt::ColorScheme::Light) {
352 effectiveThemeName = kLight;
353 effectiveThemeComponent = m_light;
355 else if (scheme == Qt::ColorScheme::Dark) {
356 effectiveThemeName = kDark;
357 effectiveThemeComponent = m_dark;
359 }
else if (QString::compare(m_themeName, kLight, Qt::CaseInsensitive) == 0) {
360 effectiveThemeName = kLight;
361 effectiveThemeComponent = m_light;
362 }
else if (QString::compare(m_themeName,kDark, Qt::CaseInsensitive) == 0) {
363 effectiveThemeName =kDark;
364 effectiveThemeComponent = m_dark;
365 }
else if (!m_themeName.isEmpty()){
366 for (
auto *customTheme : customThemes()) {
367 if (QString::compare(m_themeName, customTheme->name(), Qt::CaseInsensitive) == 0) {
368 effectiveThemeName = customTheme->name();
369 effectiveThemeComponent = customTheme->theme();
373 if (effectiveThemeName.isEmpty())
374 qmlWarning(
this) <<
"No theme found with name:" << m_themeName;
375 else if (!effectiveThemeComponent)
376 qmlWarning(
this) <<
"Custom theme '" << effectiveThemeName <<
"' has no theme component set";
379 if (m_effectiveThemeName == effectiveThemeName)
383 m_theme->deleteLater();
387 m_effectiveThemeName = effectiveThemeName;
388 m_currentThemeComponent = effectiveThemeComponent;
390 if (effectiveThemeComponent) {
391 if (effectiveThemeComponent->status() != QQmlComponent::Ready) {
392 qmlWarning(
this) <<
"failed to create theme '" << effectiveThemeName <<
"': " << effectiveThemeComponent->errorString();
395
396
397
398
399 QVariant themeAsVariant;
400 QMetaObject::invokeMethod(
this,
"createThemeInsideStyle", Qt::DirectConnection,
401 qReturnArg(themeAsVariant), QVariant::fromValue(effectiveThemeComponent));
402 m_theme = qvariant_cast<QQStyleKitTheme *>(themeAsVariant);
404 if (!m_theme || !effectiveThemeComponent->errorString().isEmpty()) {
405 qmlWarning(
this) <<
"failed to create theme '" << effectiveThemeName <<
"': " << effectiveThemeComponent->errorString();
407 m_theme->setParent(
this);
414 m_theme =
new QQStyleKitTheme(
this);
415 m_theme->setObjectName(
"<empty theme>"_L1);
416 m_theme->m_completed =
true;
418 m_theme->setParent(
this);
421 if (m_theme->fonts())
422 m_theme->fonts()->setFallbackFont(fonts());
423 if (m_theme->palettes())
424 m_theme->palettes()->setFallbackPalette(palettes());
426 m_theme->updateThemePalettes();
427 m_theme->updateThemeFonts();
429 QQStyleKitReader::resetReadersForStyle(
this);