From a8f6fa30498b7185d0c4f9a406f31b76c6b67b9a Mon Sep 17 00:00:00 2001 From: YeShanShan Date: Mon, 30 Dec 2024 11:05:23 +0800 Subject: [PATCH] fix: adjust UI for MenuItem It's consistent with QMenu. Fallback padding from 0 to 6. Fallback subMenu's background. pms: BUG-297003 --- qt6/src/qml/FlowStyle.qml | 7 +++++-- qt6/src/qml/HighlightPanel.qml | 5 ++++- qt6/src/qml/Menu.qml | 33 ++++++++------------------------- qt6/src/qml/MenuItem.qml | 9 +++++---- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/qt6/src/qml/FlowStyle.qml b/qt6/src/qml/FlowStyle.qml index 4047be98..16602029 100644 --- a/qt6/src/qml/FlowStyle.qml +++ b/qt6/src/qml/FlowStyle.qml @@ -633,18 +633,20 @@ QtObject { } property QtObject menu: QtObject { - property int padding: 0 + property int padding: 6 + property int topPadding: 8 property int radius: D.DTK.platformTheme.windowRadius < 0 ? 12 : D.DTK.platformTheme.windowRadius property int margins: 10 property int overlap: 1 property QtObject item: QtObject { property int width: 180 - property int height: 34 + property int height: 30 property size iconSize: Qt.size(14, 14) property int count: 0 property int contentPadding: 30 property int indicatorMargin: 10 + property int radius: 6 } property QtObject separator: QtObject { @@ -699,6 +701,7 @@ QtObject { property QtObject highlightPanel: QtObject { property int width: 180 property int height: 30 + property int radius: 6 property D.Palette background: D.Palette { normal: D.DTK.makeColor(D.Color.Highlight) diff --git a/qt6/src/qml/HighlightPanel.qml b/qt6/src/qml/HighlightPanel.qml index ea78ee77..01286cef 100644 --- a/qt6/src/qml/HighlightPanel.qml +++ b/qt6/src/qml/HighlightPanel.qml @@ -12,11 +12,13 @@ Item { property D.Palette backgroundColor: DS.Style.highlightPanel.background property D.Palette outerShadowColor: DS.Style.highlightPanel.dropShadow property D.Palette innerShadowColor: DS.Style.highlightPanel.innerShadow + property int radius: DS.Style.highlightPanel.radius implicitWidth: DS.Style.highlightPanel.width implicitHeight: DS.Style.highlightPanel.height BoxShadow { anchors.fill: backgroundRect + visible: panel.outerShadowColor shadowColor: panel.D.ColorSelector.outerShadowColor shadowOffsetY: 4 shadowBlur: 6 @@ -27,11 +29,12 @@ Item { id: backgroundRect anchors.fill: parent color: panel.D.ColorSelector.backgroundColor - radius: DS.Style.control.radius + radius: panel.radius } BoxInsetShadow { anchors.fill: backgroundRect + visible: panel.innerShadowColor shadowColor: panel.D.ColorSelector.innerShadowColor shadowOffsetY: -1 shadowBlur: 2 diff --git a/qt6/src/qml/Menu.qml b/qt6/src/qml/Menu.qml index d24ec490..c0cc616f 100644 --- a/qt6/src/qml/Menu.qml +++ b/qt6/src/qml/Menu.qml @@ -34,6 +34,8 @@ T.Menu { margins: DS.Style.menu.margins overlap: DS.Style.menu.overlap padding: DS.Style.menu.padding + topPadding: DS.Style.menu.topPadding + bottomPadding: topPadding delegate: MenuItem { } @@ -42,7 +44,7 @@ T.Menu { } contentItem: Control { - topPadding: 15 // TODO how to clip radius + topPadding: 0 bottomPadding: topPadding leftPadding: 0 rightPadding: leftPadding @@ -83,42 +85,23 @@ T.Menu { view.highlightMoveDuration: 50 view.highlightMoveVelocity: -1 - view.highlight: Rectangle { + view.highlight: HighlightPanel { id: highlightRect anchors.left: parent ? parent.left : undefined anchors.right: parent ? parent.right : undefined anchors.leftMargin: 0 anchors.rightMargin: 0 scale: D.DTK.hasAnimation ? 0.9 : 1.0 - property D.Palette backgroundColor: DS.Style.highlightPanel.background - property D.Palette submenuOpenedItemHighlightColor: DS.Style.menu.submenuOpenedItemHighlight - property D.Palette itemHighlightShadowColor: DS.Style.menu.itemHighlightShadow - color: { - let item = control.itemAt(control.currentIndex) - if (item && item.subMenu) { - return D.ColorSelector.submenuOpenedItemHighlightColor - } else { - return D.ColorSelector.backgroundColor - } - } - radius: 1 + + radius: DS.Style.menu.item.radius + outerShadowColor: null + innerShadowColor: null Component.onCompleted: { scale = 1.0 } Behavior on scale { NumberAnimation { duration: 100 } } - BoxInsetShadow { - visible: highlightRect.color === highlightRect.D.ColorSelector.backgroundColor - anchors.fill: parent - z: DTK.AboveOrder - cornerRadius: parent.radius - shadowOffsetX: 0 - shadowOffsetY: -1 - shadowBlur: 1 - spread: 1 - shadowColor: highlightRect.D.ColorSelector.itemHighlightShadowColor - } } } Loader { diff --git a/qt6/src/qml/MenuItem.qml b/qt6/src/qml/MenuItem.qml index 38cf54c7..592f2dce 100644 --- a/qt6/src/qml/MenuItem.qml +++ b/qt6/src/qml/MenuItem.qml @@ -99,10 +99,11 @@ T.MenuItem { implicitHeight: DS.Style.menu.item.height Loader { anchors.fill: parent - active: !control.hovered && control.subMenu && control.subMenu.opened - sourceComponent: Rectangle { - color: control.D.ColorSelector.subMenuBackgroundColor - radius: DS.Style.control.radius + active: control.highlighted + sourceComponent: HighlightPanel { + outerShadowColor: null + innerShadowColor: null + radius: DS.Style.menu.item.radius } } }