aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/controls/material
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2020-07-23 14:55:18 +0200
committerMitch Curtis <mitch.curtis@qt.io>2020-08-27 16:46:03 +0200
commit7f29e89c26ae2babc358b1c4e6f965af6ec759f4 (patch)
treeb8d1b68f53a4d39c9f389d8c68a77d60d4cc4888 /src/imports/controls/material
parentbda2925304525be1dacc16fe9779199f29a08f45 (diff)
Material: fix binding loops when binding between attached properties
The paletteChanged signal was used as the change signal for a lot of properties. The problem with this was this binding, for example: Material.foreground: Material.toolTextColor results in foreground being set, which emits paletteChanged. toolTextColor has paletteChanged as its change signal, so that is triggered and then the foreground binding is re-evaluated in the middle of already being evaluated. I haven't found a way to fix this for toolTextColor yet, so we temporarily skip emission of toolTextColorChanged when foreground changes. This means that some text will be the wrong color when foreground is changed after startup. For other properties, using more specific change handlers is enough to solve any binding loops. Task-number: QTBUG-85699 Pick-to: 5.15 Change-Id: Ied52d4c38914765ed5c75e234954f4baabaaa9af Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/imports/controls/material')
-rw-r--r--src/imports/controls/material/qquickmaterialstyle.cpp93
-rw-r--r--src/imports/controls/material/qquickmaterialstyle_p.h80
2 files changed, 114 insertions, 59 deletions
diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp
index 08f47990..d343f2f5 100644
--- a/src/imports/controls/material/qquickmaterialstyle.cpp
+++ b/src/imports/controls/material/qquickmaterialstyle.cpp
@@ -469,14 +469,13 @@ void QQuickMaterialStyle::setTheme(Theme theme)
m_theme = theme;
propagateTheme();
- emit themeChanged();
- emit paletteChanged();
+ themeChange();
if (!m_customAccent)
- emit accentChanged();
+ accentChange();
if (!m_hasBackground)
- emit backgroundChanged();
+ backgroundChange();
if (!m_hasForeground)
- emit foregroundChanged();
+ foregroundChange();
}
void QQuickMaterialStyle::inheritTheme(Theme theme)
@@ -486,14 +485,13 @@ void QQuickMaterialStyle::inheritTheme(Theme theme)
m_theme = theme;
propagateTheme();
- emit themeChanged();
- emit paletteChanged();
+ themeChange();
if (!m_customAccent)
- emit accentChanged();
+ accentChange();
if (!m_hasBackground)
- emit backgroundChanged();
+ backgroundChange();
if (!m_hasForeground)
- emit foregroundChanged();
+ foregroundChange();
}
void QQuickMaterialStyle::propagateTheme()
@@ -516,6 +514,19 @@ void QQuickMaterialStyle::resetTheme()
inheritTheme(material ? material->theme() : globalTheme);
}
+void QQuickMaterialStyle::themeChange()
+{
+ emit themeChanged();
+ emit themeOrAccentChanged();
+ emit primaryHighlightedTextColor();
+ emit buttonColorChanged();
+ emit buttonDisabledColorChanged();
+ emit dialogColorChanged();
+ emit tooltipColorChanged();
+ emit toolBarColorChanged();
+ emit toolTextColorChanged();
+}
+
QVariant QQuickMaterialStyle::primary() const
{
return primaryColor();
@@ -535,8 +546,7 @@ void QQuickMaterialStyle::setPrimary(const QVariant &var)
m_customPrimary = custom;
m_primary = primary;
propagatePrimary();
- emit primaryChanged();
- emit paletteChanged();
+ primaryChange();
}
void QQuickMaterialStyle::inheritPrimary(uint primary, bool custom)
@@ -547,8 +557,7 @@ void QQuickMaterialStyle::inheritPrimary(uint primary, bool custom)
m_customPrimary = custom;
m_primary = primary;
propagatePrimary();
- emit primaryChanged();
- emit paletteChanged();
+ primaryChange();
}
void QQuickMaterialStyle::propagatePrimary()
@@ -575,6 +584,13 @@ void QQuickMaterialStyle::resetPrimary()
inheritPrimary(globalPrimary, false);
}
+void QQuickMaterialStyle::primaryChange()
+{
+ emit primaryChanged();
+ emit toolBarColorChanged();
+ emit toolTextColorChanged();
+}
+
QVariant QQuickMaterialStyle::accent() const
{
return accentColor();
@@ -594,8 +610,7 @@ void QQuickMaterialStyle::setAccent(const QVariant &var)
m_customAccent = custom;
m_accent = accent;
propagateAccent();
- emit accentChanged();
- emit paletteChanged();
+ accentChange();
}
void QQuickMaterialStyle::inheritAccent(uint accent, bool custom)
@@ -606,8 +621,7 @@ void QQuickMaterialStyle::inheritAccent(uint accent, bool custom)
m_customAccent = custom;
m_accent = accent;
propagateAccent();
- emit accentChanged();
- emit paletteChanged();
+ accentChange();
}
void QQuickMaterialStyle::propagateAccent()
@@ -634,6 +648,13 @@ void QQuickMaterialStyle::resetAccent()
inheritAccent(globalAccent, false);
}
+void QQuickMaterialStyle::accentChange()
+{
+ emit accentChanged();
+ emit themeOrAccentChanged();
+ emit buttonColorChanged();
+}
+
QVariant QQuickMaterialStyle::foreground() const
{
if (!m_hasForeground)
@@ -660,8 +681,7 @@ void QQuickMaterialStyle::setForeground(const QVariant &var)
m_customForeground = custom;
m_foreground = foreground;
propagateForeground();
- emit foregroundChanged();
- emit paletteChanged();
+ foregroundChange();
}
void QQuickMaterialStyle::inheritForeground(uint foreground, bool custom, bool has)
@@ -673,7 +693,7 @@ void QQuickMaterialStyle::inheritForeground(uint foreground, bool custom, bool h
m_customForeground = custom;
m_foreground = foreground;
propagateForeground();
- emit foregroundChanged();
+ foregroundChange();
}
void QQuickMaterialStyle::propagateForeground()
@@ -698,6 +718,14 @@ void QQuickMaterialStyle::resetForeground()
inheritForeground(material ? material->m_foreground : globalForeground, true, material ? material->m_hasForeground : false);
}
+void QQuickMaterialStyle::foregroundChange()
+{
+ emit foregroundChanged();
+ emit primaryHighlightedTextColorChanged();
+ // TODO: This causes a binding loop: see QTBUG-85699 and the comments on its fix
+// emit toolTextColorChanged();
+}
+
QVariant QQuickMaterialStyle::background() const
{
return backgroundColor();
@@ -718,8 +746,7 @@ void QQuickMaterialStyle::setBackground(const QVariant &var)
m_customBackground = custom;
m_background = background;
propagateBackground();
- emit backgroundChanged();
- emit paletteChanged();
+ backgroundChange();
}
void QQuickMaterialStyle::inheritBackground(uint background, bool custom, bool has)
@@ -731,8 +758,7 @@ void QQuickMaterialStyle::inheritBackground(uint background, bool custom, bool h
m_customBackground = custom;
m_background = background;
propagateBackground();
- emit backgroundChanged();
- emit paletteChanged();
+ backgroundChange();
}
void QQuickMaterialStyle::propagateBackground()
@@ -757,6 +783,15 @@ void QQuickMaterialStyle::resetBackground()
inheritBackground(material ? material->m_background : globalBackground, true, material ? material->m_hasBackground : false);
}
+void QQuickMaterialStyle::backgroundChange()
+{
+ emit backgroundChanged();
+ emit buttonColorChanged();
+ emit dialogColorChanged();
+ emit tooltipColorChanged();
+ emit toolBarColorChanged();
+}
+
int QQuickMaterialStyle::elevation() const
{
return m_elevation;
@@ -768,7 +803,7 @@ void QQuickMaterialStyle::setElevation(int elevation)
return;
m_elevation = elevation;
- emit elevationChanged();
+ elevationChange();
}
void QQuickMaterialStyle::resetElevation()
@@ -776,6 +811,12 @@ void QQuickMaterialStyle::resetElevation()
setElevation(0);
}
+void QQuickMaterialStyle::elevationChange()
+{
+ emit elevationChanged();
+ emit buttonDisabledColorChanged();
+}
+
QColor QQuickMaterialStyle::primaryColor() const
{
if (m_customPrimary)
diff --git a/src/imports/controls/material/qquickmaterialstyle_p.h b/src/imports/controls/material/qquickmaterialstyle_p.h
index 557a4434..56cf141c 100644
--- a/src/imports/controls/material/qquickmaterialstyle_p.h
+++ b/src/imports/controls/material/qquickmaterialstyle_p.h
@@ -66,38 +66,38 @@ class QQuickMaterialStyle : public QQuickAttachedObject
Q_PROPERTY(QColor primaryColor READ primaryColor NOTIFY primaryChanged FINAL) // TODO: remove?
Q_PROPERTY(QColor accentColor READ accentColor NOTIFY accentChanged FINAL) // TODO: remove?
Q_PROPERTY(QColor backgroundColor READ backgroundColor NOTIFY backgroundChanged FINAL)
- Q_PROPERTY(QColor primaryTextColor READ primaryTextColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor primaryHighlightedTextColor READ primaryHighlightedTextColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor secondaryTextColor READ secondaryTextColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor hintTextColor READ hintTextColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor textSelectionColor READ textSelectionColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor dropShadowColor READ dropShadowColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor dividerColor READ dividerColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor iconColor READ iconColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor iconDisabledColor READ iconDisabledColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor buttonColor READ buttonColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor buttonDisabledColor READ buttonDisabledColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor highlightedButtonColor READ highlightedButtonColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor frameColor READ frameColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor rippleColor READ rippleColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor highlightedRippleColor READ highlightedRippleColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor switchUncheckedTrackColor READ switchUncheckedTrackColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor switchCheckedTrackColor READ switchCheckedTrackColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor switchUncheckedHandleColor READ switchUncheckedHandleColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor switchCheckedHandleColor READ switchCheckedHandleColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor switchDisabledTrackColor READ switchDisabledTrackColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor switchDisabledHandleColor READ switchDisabledHandleColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor scrollBarColor READ scrollBarColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor scrollBarHoveredColor READ scrollBarHoveredColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor scrollBarPressedColor READ scrollBarPressedColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor dialogColor READ dialogColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor backgroundDimColor READ backgroundDimColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor listHighlightColor READ listHighlightColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor tooltipColor READ tooltipColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor toolBarColor READ toolBarColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor toolTextColor READ toolTextColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor spinBoxDisabledIconColor READ spinBoxDisabledIconColor NOTIFY paletteChanged FINAL)
- Q_PROPERTY(QColor sliderDisabledColor READ sliderDisabledColor NOTIFY paletteChanged FINAL REVISION 15)
+ Q_PROPERTY(QColor primaryTextColor READ primaryTextColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor primaryHighlightedTextColor READ primaryHighlightedTextColor NOTIFY primaryHighlightedTextColorChanged FINAL)
+ Q_PROPERTY(QColor secondaryTextColor READ secondaryTextColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor hintTextColor READ hintTextColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor textSelectionColor READ textSelectionColor NOTIFY themeOrAccentChanged FINAL)
+ Q_PROPERTY(QColor dropShadowColor READ dropShadowColor CONSTANT FINAL)
+ Q_PROPERTY(QColor dividerColor READ dividerColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor iconColor READ iconColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor iconDisabledColor READ iconDisabledColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor buttonColor READ buttonColor NOTIFY buttonColorChanged FINAL)
+ Q_PROPERTY(QColor buttonDisabledColor READ buttonDisabledColor NOTIFY buttonDisabledColorChanged FINAL)
+ Q_PROPERTY(QColor highlightedButtonColor READ highlightedButtonColor NOTIFY buttonColorChanged FINAL)
+ Q_PROPERTY(QColor frameColor READ frameColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor rippleColor READ rippleColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor highlightedRippleColor READ highlightedRippleColor NOTIFY themeOrAccentChanged FINAL)
+ Q_PROPERTY(QColor switchUncheckedTrackColor READ switchUncheckedTrackColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor switchCheckedTrackColor READ switchCheckedTrackColor NOTIFY themeOrAccentChanged FINAL)
+ Q_PROPERTY(QColor switchUncheckedHandleColor READ switchUncheckedHandleColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor switchCheckedHandleColor READ switchCheckedHandleColor NOTIFY themeOrAccentChanged FINAL)
+ Q_PROPERTY(QColor switchDisabledTrackColor READ switchDisabledTrackColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor switchDisabledHandleColor READ switchDisabledHandleColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor scrollBarColor READ scrollBarColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor scrollBarHoveredColor READ scrollBarHoveredColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor scrollBarPressedColor READ scrollBarPressedColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor dialogColor READ dialogColor NOTIFY dialogColorChanged FINAL)
+ Q_PROPERTY(QColor backgroundDimColor READ backgroundDimColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor listHighlightColor READ listHighlightColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor tooltipColor READ tooltipColor NOTIFY tooltipColorChanged FINAL)
+ Q_PROPERTY(QColor toolBarColor READ toolBarColor NOTIFY toolBarColorChanged FINAL)
+ Q_PROPERTY(QColor toolTextColor READ toolTextColor NOTIFY toolTextColorChanged FINAL)
+ Q_PROPERTY(QColor spinBoxDisabledIconColor READ spinBoxDisabledIconColor NOTIFY themeChanged FINAL)
+ Q_PROPERTY(QColor sliderDisabledColor READ sliderDisabledColor NOTIFY themeChanged FINAL REVISION 15)
Q_PROPERTY(int touchTarget READ touchTarget CONSTANT FINAL)
Q_PROPERTY(int buttonHeight READ buttonHeight CONSTANT FINAL)
@@ -179,34 +179,40 @@ public:
void inheritTheme(Theme theme);
void propagateTheme();
void resetTheme();
+ void themeChange();
QVariant primary() const;
void setPrimary(const QVariant &accent);
void inheritPrimary(uint primary, bool custom);
void propagatePrimary();
void resetPrimary();
+ void primaryChange();
QVariant accent() const;
void setAccent(const QVariant &accent);
void inheritAccent(uint accent, bool custom);
void propagateAccent();
void resetAccent();
+ void accentChange();
QVariant foreground() const;
void setForeground(const QVariant &foreground);
void inheritForeground(uint foreground, bool custom, bool has);
void propagateForeground();
void resetForeground();
+ void foregroundChange();
QVariant background() const;
void setBackground(const QVariant &background);
void inheritBackground(uint background, bool custom, bool has);
void propagateBackground();
void resetBackground();
+ void backgroundChange();
int elevation() const;
void setElevation(int elevation);
void resetElevation();
+ void elevationChange();
QColor primaryColor() const;
QColor accentColor() const;
@@ -270,7 +276,15 @@ Q_SIGNALS:
void backgroundChanged();
void elevationChanged();
- void paletteChanged();
+ void themeOrAccentChanged();
+
+ void primaryHighlightedTextColorChanged();
+ void buttonColorChanged();
+ void buttonDisabledColorChanged();
+ void dialogColorChanged();
+ void tooltipColorChanged();
+ void toolBarColorChanged();
+ void toolTextColorChanged();
protected:
void attachedParentChange(QQuickAttachedObject *newParent, QQuickAttachedObject *oldParent) override;