From 0d5a43fa84ffe298d028aded4478d5e388d58298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 6 Mar 2020 19:25:42 +0100 Subject: Material: Change slider's color to grey when not enabled When Slider was not enabled it would look exactly the same as when enabled. [ChangeLog][Controls][Material] Add visual distinction between an enabled and not enabled slider. Task-number: QTBUG-70768 Change-Id: If0d7e5adc19d8bc22a810cb2ba4e57b657ab48d4 Reviewed-by: Mitch Curtis --- src/imports/controls/material/Slider.qml | 4 ++-- src/imports/controls/material/SliderHandle.qml | 4 ++-- src/imports/controls/material/qquickmaterialstyle.cpp | 7 +++++++ src/imports/controls/material/qquickmaterialstyle_p.h | 2 ++ 4 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src/imports/controls/material') diff --git a/src/imports/controls/material/Slider.qml b/src/imports/controls/material/Slider.qml index cc6a1413..8c1ef12e 100644 --- a/src/imports/controls/material/Slider.qml +++ b/src/imports/controls/material/Slider.qml @@ -65,8 +65,8 @@ T.Slider { implicitHeight: control.horizontal ? 48 : 200 width: control.horizontal ? control.availableWidth : 1 height: control.horizontal ? 1 : control.availableHeight - color: control.Material.foreground scale: control.horizontal && control.mirrored ? -1 : 1 + color: control.enabled ? control.Material.foreground : control.Material.sliderDisabledColor Rectangle { x: control.horizontal ? 0 : (parent.width - width) / 2 @@ -74,7 +74,7 @@ T.Slider { width: control.horizontal ? control.position * parent.width : 3 height: control.horizontal ? 3 : control.position * parent.height - color: control.Material.accentColor + color: control.enabled ? control.Material.accentColor : control.Material.sliderDisabledColor } } } diff --git a/src/imports/controls/material/SliderHandle.qml b/src/imports/controls/material/SliderHandle.qml index 2e3120e4..c9078bc8 100644 --- a/src/imports/controls/material/SliderHandle.qml +++ b/src/imports/controls/material/SliderHandle.qml @@ -55,8 +55,8 @@ Item { width: parent.width height: parent.height radius: width / 2 - color: root.control.Material.accentColor scale: root.handlePressed ? 1.5 : 1 + color: control.enabled ? root.control.Material.accentColor : root.control.Material.sliderDisabledColor Behavior on scale { NumberAnimation { @@ -71,6 +71,6 @@ Item { width: 22; height: 22 pressed: root.handlePressed active: root.handlePressed || root.handleHasFocus || root.handleHovered - color: root.control.Material.rippleColor + color: root.control.Material.highlightedRippleColor } } diff --git a/src/imports/controls/material/qquickmaterialstyle.cpp b/src/imports/controls/material/qquickmaterialstyle.cpp index 77a65927..35afeb00 100644 --- a/src/imports/controls/material/qquickmaterialstyle.cpp +++ b/src/imports/controls/material/qquickmaterialstyle.cpp @@ -422,6 +422,8 @@ static const QRgb rippleColorLight = 0x10000000; static const QRgb rippleColorDark = 0x20FFFFFF; static const QRgb spinBoxDisabledIconColorLight = 0xFFCCCCCC; static const QRgb spinBoxDisabledIconColorDark = 0xFF666666; +static const QRgb sliderDisabledColorLight = 0xFF9E9E9E; +static const QRgb sliderDisabledColorDark = 0xFF616161; static QQuickMaterialStyle::Theme effectiveTheme(QQuickMaterialStyle::Theme theme) { @@ -1037,6 +1039,11 @@ QColor QQuickMaterialStyle::spinBoxDisabledIconColor() const return QColor::fromRgba(m_theme == Light ? spinBoxDisabledIconColorLight : spinBoxDisabledIconColorDark); } +QColor QQuickMaterialStyle::sliderDisabledColor() const +{ + return QColor::fromRgba(m_theme == Light ? sliderDisabledColorLight : sliderDisabledColorDark); +} + QColor QQuickMaterialStyle::color(QQuickMaterialStyle::Color color, QQuickMaterialStyle::Shade shade) const { int count = sizeof(colors) / sizeof(colors[0]); diff --git a/src/imports/controls/material/qquickmaterialstyle_p.h b/src/imports/controls/material/qquickmaterialstyle_p.h index 4b0f7b31..d2a89761 100644 --- a/src/imports/controls/material/qquickmaterialstyle_p.h +++ b/src/imports/controls/material/qquickmaterialstyle_p.h @@ -97,6 +97,7 @@ class QQuickMaterialStyle : public QQuickAttachedObject 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) Q_PROPERTY(int touchTarget READ touchTarget CONSTANT FINAL) Q_PROPERTY(int buttonHeight READ buttonHeight CONSTANT FINAL) @@ -237,6 +238,7 @@ public: QColor toolBarColor() const; QColor toolTextColor() const; QColor spinBoxDisabledIconColor() const; + QColor sliderDisabledColor() const; Q_INVOKABLE QColor color(Color color, Shade shade = Shade500) const; Q_INVOKABLE QColor shade(const QColor &color, Shade shade) const; -- cgit v1.2.3