diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2023-08-14 15:38:59 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-08-14 13:30:57 +0000 |
commit | ee6a616e48d526408962ab915e0fd144d8dd7495 (patch) | |
tree | b648605f651d8c255e295a85218330435e78b757 | |
parent | d82d45f2f504624e48c7c8ae362eae0fca4bcca3 (diff) |
Material: make Switch respect Dense variant
This patch makes the Material 3 Switch more compact when the Dense
variant is in use, bringing it in line with other controls like Button.
Fixes: QTBUG-116028
Change-Id: I8df7a5d00688965066ea40eee8d6a9a918d2265f
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
(cherry picked from commit a3c577d07d5064eb811e9121284193fe4819ae32)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quickcontrols/material/Switch.qml | 3 | ||||
-rw-r--r-- | src/quickcontrols/material/impl/SwitchIndicator.qml | 10 | ||||
-rw-r--r-- | src/quickcontrols/material/qquickmaterialstyle.cpp | 25 | ||||
-rw-r--r-- | src/quickcontrols/material/qquickmaterialstyle_p.h | 10 |
4 files changed, 42 insertions, 6 deletions
diff --git a/src/quickcontrols/material/Switch.qml b/src/quickcontrols/material/Switch.qml index d27621a74f..29a1297684 100644 --- a/src/quickcontrols/material/Switch.qml +++ b/src/quickcontrols/material/Switch.qml @@ -34,7 +34,8 @@ T.Switch { Ripple { x: parent.handle.x + parent.handle.width / 2 - width / 2 y: parent.handle.y + parent.handle.height / 2 - height / 2 - width: 28; height: 28 + width: 28 + height: 28 pressed: control.pressed active: enabled && (control.down || control.visualFocus || control.hovered) color: control.checked ? control.Material.highlightedRippleColor : control.Material.rippleColor diff --git a/src/quickcontrols/material/impl/SwitchIndicator.qml b/src/quickcontrols/material/impl/SwitchIndicator.qml index 2d48302e01..d864f3887a 100644 --- a/src/quickcontrols/material/impl/SwitchIndicator.qml +++ b/src/quickcontrols/material/impl/SwitchIndicator.qml @@ -9,8 +9,8 @@ import QtQuick.Controls.Material.impl Rectangle { id: indicator - width: 52 - height: 32 + width: control.Material.switchIndicatorWidth + height: control.Material.switchIndicatorHeight radius: height / 2 y: parent.height / 2 - height / 2 color: control.enabled @@ -62,9 +62,9 @@ Rectangle { scale: indicator.control.down ? 1 : (indicator.control.checked ? checkedSize / largestSize : normalSize / largestSize) readonly property int offset: 2 - readonly property real normalSize: !hasIcon ? 16 : checkedSize - readonly property real checkedSize: 24 - readonly property real largestSize: 28 + readonly property real normalSize: !hasIcon ? indicator.control.Material.switchNormalHandleHeight : checkedSize + readonly property real checkedSize: indicator.control.Material.switchCheckedHandleHeight + readonly property real largestSize: indicator.control.Material.switchLargestHandleHeight readonly property real largestScale: largestSize / normalSize readonly property bool hasIcon: indicator.control.icon.name.length > 0 || indicator.control.icon.source.toString().length > 0 diff --git a/src/quickcontrols/material/qquickmaterialstyle.cpp b/src/quickcontrols/material/qquickmaterialstyle.cpp index cd191cd77b..7338dde84e 100644 --- a/src/quickcontrols/material/qquickmaterialstyle.cpp +++ b/src/quickcontrols/material/qquickmaterialstyle.cpp @@ -1302,6 +1302,31 @@ int QQuickMaterialStyle::menuItemVerticalPadding() const return globalVariant == Dense ? 8 : 12; } +int QQuickMaterialStyle::switchIndicatorWidth() const +{ + return globalVariant == Dense ? 40 : 52; +} + +int QQuickMaterialStyle::switchIndicatorHeight() const +{ + return globalVariant == Dense ? 22 : 32; +} + +int QQuickMaterialStyle::switchNormalHandleHeight() const +{ + return globalVariant == Dense ? 10 : 16; +} + +int QQuickMaterialStyle::switchCheckedHandleHeight() const +{ + return globalVariant == Dense ? 16 : 24; +} + +int QQuickMaterialStyle::switchLargestHandleHeight() const +{ + return globalVariant == Dense ? 18 : 28; +} + int QQuickMaterialStyle::switchDelegateVerticalPadding() const { // SwitchDelegate's indicator is much larger than the others due to the shadow, diff --git a/src/quickcontrols/material/qquickmaterialstyle_p.h b/src/quickcontrols/material/qquickmaterialstyle_p.h index 83b9e3ede3..96d07179f7 100644 --- a/src/quickcontrols/material/qquickmaterialstyle_p.h +++ b/src/quickcontrols/material/qquickmaterialstyle_p.h @@ -82,6 +82,11 @@ class QQuickMaterialStyle : public QQuickAttachedPropertyPropagator Q_PROPERTY(int frameVerticalPadding READ frameVerticalPadding CONSTANT FINAL) Q_PROPERTY(int menuItemHeight READ menuItemHeight CONSTANT FINAL) Q_PROPERTY(int menuItemVerticalPadding READ menuItemVerticalPadding CONSTANT FINAL) + Q_PROPERTY(int switchIndicatorWidth READ switchIndicatorWidth CONSTANT FINAL) + Q_PROPERTY(int switchIndicatorHeight READ switchIndicatorHeight CONSTANT FINAL) + Q_PROPERTY(int switchNormalHandleHeight READ switchNormalHandleHeight CONSTANT FINAL) + Q_PROPERTY(int switchCheckedHandleHeight READ switchCheckedHandleHeight CONSTANT FINAL) + Q_PROPERTY(int switchLargestHandleHeight READ switchLargestHandleHeight CONSTANT FINAL) Q_PROPERTY(int switchDelegateVerticalPadding READ switchDelegateVerticalPadding CONSTANT FINAL) Q_PROPERTY(int textFieldHeight READ textFieldHeight CONSTANT FINAL) Q_PROPERTY(int textFieldHorizontalPadding READ textFieldHorizontalPadding CONSTANT FINAL) @@ -270,6 +275,11 @@ public: int frameVerticalPadding() const; int menuItemHeight() const; int menuItemVerticalPadding() const; + int switchIndicatorWidth() const; + int switchIndicatorHeight() const; + int switchNormalHandleHeight() const; + int switchCheckedHandleHeight() const; + int switchLargestHandleHeight() const; int switchDelegateVerticalPadding() const; int textFieldHeight() const; int textFieldHorizontalPadding() const; |