125QQuickUniversalStyle::QQuickUniversalStyle(QObject *parent)
126 : QQuickAttachedPropertyPropagator(parent)
127 , m_hasForeground(HasGlobalForeground)
128 , m_hasBackground(HasGlobalBackground)
129 , m_usingSystemTheme(GlobalTheme == System)
130 , m_theme(qquickuniversal_effective_theme(GlobalTheme))
131 , m_accent(GlobalAccent)
132 , m_foreground(GlobalForeground)
133 , m_background(GlobalBackground)
148void QQuickUniversalStyle::setTheme(Theme theme)
150 m_explicitTheme =
true;
156 const bool systemThemeChanged = (m_usingSystemTheme != (theme == System));
157 const Theme effectiveTheme = qquickuniversal_effective_theme(theme);
159 if ((m_theme == effectiveTheme) && !systemThemeChanged)
162 m_theme = effectiveTheme;
163 m_usingSystemTheme = (theme == System);
164 if (systemThemeChanged) {
165 if (m_usingSystemTheme)
166 QQuickUniversalTheme::registerSystemStyle(
this);
168 QQuickUniversalTheme::unregisterSystemStyle(
this);
173 emit paletteChanged();
174 emit foregroundChanged();
175 emit backgroundChanged();
178void QQuickUniversalStyle::inheritTheme(Theme theme)
180 const bool systemThemeChanged = (m_usingSystemTheme != (theme == System));
181 const Theme effectiveTheme = qquickuniversal_effective_theme(theme);
182 const bool hasThemeChanged = systemThemeChanged || (m_theme != effectiveTheme);
183 if (m_explicitTheme || !hasThemeChanged)
186 m_theme = effectiveTheme;
187 m_usingSystemTheme = (theme == System);
191 emit paletteChanged();
192 emit foregroundChanged();
193 emit backgroundChanged();
196void QQuickUniversalStyle::propagateTheme()
198 const auto styles = attachedChildren();
199 for (QQuickAttachedPropertyPropagator *child : styles) {
200 QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(child);
205 universal->inheritTheme(m_theme);
250void QQuickUniversalStyle::propagateAccent()
252 const auto styles = attachedChildren();
253 for (QQuickAttachedPropertyPropagator *child : styles) {
254 QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(child);
256 universal->inheritAccent(m_accent);
293void QQuickUniversalStyle::inheritForeground(QRgb foreground,
bool has)
295 if (m_explicitForeground || m_foreground == foreground)
298 m_hasForeground = has;
299 m_foreground = foreground;
300 propagateForeground();
301 emit foregroundChanged();
304void QQuickUniversalStyle::propagateForeground()
306 const auto styles = attachedChildren();
307 for (QQuickAttachedPropertyPropagator *child : styles) {
308 QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(child);
310 universal->inheritForeground(m_foreground, m_hasForeground);
348void QQuickUniversalStyle::inheritBackground(QRgb background,
bool has)
350 if (m_explicitBackground || m_background == background)
353 m_hasBackground = has;
354 m_background = background;
355 propagateBackground();
356 emit backgroundChanged();
359void QQuickUniversalStyle::propagateBackground()
361 const auto styles = attachedChildren();
362 for (QQuickAttachedPropertyPropagator *child : styles) {
363 QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(child);
365 universal->inheritBackground(m_background, m_hasBackground);
510void QQuickUniversalStyle::attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent)
513 QQuickUniversalStyle *universal = qobject_cast<QQuickUniversalStyle *>(newParent);
515 inheritTheme(universal->theme());
516 inheritAccent(universal->m_accent);
517 inheritForeground(universal->m_foreground, universal->m_hasForeground);
518 inheritBackground(universal->m_background, universal->m_hasBackground);
539void QQuickUniversalStyle::initGlobals()
541 QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(QStringLiteral(
"Universal"));
544 QByteArray themeValue = resolveSetting(
"QT_QUICK_CONTROLS_UNIVERSAL_THEME", settings, QStringLiteral(
"Theme"));
545 Theme themeEnum = toEnumValue<Theme>(themeValue, &ok);
547 GlobalTheme = themeEnum;
548 else if (!themeValue.isEmpty())
549 qWarning().nospace().noquote() <<
"Universal: unknown theme value: " << themeValue;
551 QByteArray accentValue = resolveSetting(
"QT_QUICK_CONTROLS_UNIVERSAL_ACCENT", settings, QStringLiteral(
"Accent"));
552 Color accentEnum = toEnumValue<Color>(accentValue, &ok);
554 GlobalAccent = qquickuniversal_accent_color(accentEnum);
555 }
else if (!accentValue.isEmpty()) {
556 QColor color = QColor::fromString(accentValue);
558 GlobalAccent = color.rgba();
560 qWarning().nospace().noquote() <<
"Universal: unknown accent value: " << accentValue;
563 QByteArray foregroundValue = resolveSetting(
"QT_QUICK_CONTROLS_UNIVERSAL_FOREGROUND", settings, QStringLiteral(
"Foreground"));
564 Color foregroundEnum = toEnumValue<Color>(foregroundValue, &ok);
566 GlobalForeground = qquickuniversal_accent_color(foregroundEnum);
567 HasGlobalForeground =
true;
568 }
else if (!foregroundValue.isEmpty()) {
569 QColor color = QColor::fromString(foregroundValue);
570 if (color.isValid()) {
571 GlobalForeground = color.rgba();
572 HasGlobalForeground =
true;
574 qWarning().nospace().noquote() <<
"Universal: unknown foreground value: " << foregroundValue;
578 QByteArray backgroundValue = resolveSetting(
"QT_QUICK_CONTROLS_UNIVERSAL_BACKGROUND", settings, QStringLiteral(
"Background"));
579 Color backgroundEnum = toEnumValue<Color>(backgroundValue, &ok);
581 GlobalBackground = qquickuniversal_accent_color(backgroundEnum);
582 HasGlobalBackground =
true;
583 }
else if (!backgroundValue.isEmpty()) {
584 QColor color = QColor::fromString(backgroundValue);
585 if (color.isValid()) {
586 GlobalBackground = color.rgba();
587 HasGlobalBackground =
true;
589 qWarning().nospace().noquote() <<
"Universal: unknown background value: " << backgroundValue;