From f5d95f56c45cf84f8155f9ec90946093b41d6bd1 Mon Sep 17 00:00:00 2001 From: iCancely Date: Fri, 13 Nov 2026 14:23:04 +0800 Subject: [PATCH] fix(spinbox): redesign indicator background with combined container - Remove individual background from up/down indicator buttons - Each indicator renders its own half of the combined background (up: rounded top corners, down: rounded bottom corners) - Background width 20px, height = spinbox height - 4px, 4px corner radius - Spacing between input field and indicator area: 2px - Background color: light mode rgba(0,0,0,0.15), dark mode rgba(0,0,0,0.2) - Dark mode only: 1px inner shadow at bottom edge (down indicator only), color rgba(0,0,0,0.4) - Simplify SpinBoxIndicator: remove Loader-based inactive/active switching and ItemViewport, use ToolButton (background: null) instead - Disabled state only dims the icon, background stays unchanged - Indicator width: 24 -> 20 --- qt6/src/qml/FlowStyle.qml | 15 +++- qt6/src/qml/SpinBoxIndicator.qml | 120 ++++++++++++------------------- 2 files changed, 59 insertions(+), 76 deletions(-) diff --git a/qt6/src/qml/FlowStyle.qml b/qt6/src/qml/FlowStyle.qml index f7932d7a3..32b21c55d 100644 --- a/qt6/src/qml/FlowStyle.qml +++ b/qt6/src/qml/FlowStyle.qml @@ -726,9 +726,10 @@ QtObject { property int width : 300 property int height: 36 property int spacing: 10 + property int indicatorSpacing: 2 property QtObject indicator: QtObject { - property int width: 24 + property int width: 20 property int height: 14 property int iconSize: 24 property int focusIconSize: 10 @@ -739,6 +740,18 @@ QtObject { pressed: Qt.rgba(0, 0, 0, 0.8) } } + + // Combined background for both up/down indicators + property int indicatorContainerVMargin: 2 + property int indicatorContainerRadius: 4 + property D.Palette indicatorBackground: D.Palette { + normal: Qt.rgba(0, 0, 0, 0.15) + normalDark: Qt.rgba(0, 0, 0, 0.2) + } + // 1px inner shadow, dark mode only + property D.Palette indicatorInnerShadow: D.Palette { + normalDark: Qt.rgba(0, 0, 0, 0.4) + } } property QtObject plusMinusSpinBox: QtObject { diff --git a/qt6/src/qml/SpinBoxIndicator.qml b/qt6/src/qml/SpinBoxIndicator.qml index eacea3f79..f91357bea 100644 --- a/qt6/src/qml/SpinBoxIndicator.qml +++ b/qt6/src/qml/SpinBoxIndicator.qml @@ -5,7 +5,6 @@ import QtQuick import org.deepin.dtk 1.0 as D import org.deepin.dtk.style 1.0 as DS -import org.deepin.dtk.private as P Control { id: control @@ -19,90 +18,61 @@ Control { property bool singleIndicator: false property int direction property D.Palette inactiveBackgroundColor: DS.Style.spinBox.indicator.background + property D.Palette indicatorBackground: DS.Style.spinBox.indicatorBackground + property D.Palette indicatorInnerShadow: DS.Style.spinBox.indicatorInnerShadow palette.windowText: control.D.ColorSelector.inactiveBackgroundColor + // Background stays full opacity; only the icon dims when disabled. hoverEnabled: true implicitWidth: DS.Style.spinBox.indicator.width - implicitHeight: spinBox.activeFocus ? spinBox.implicitHeight / 2 : DS.Style.spinBox.indicator.height - opacity: D.ColorSelector.controlState === D.DTK.DisabledState ? 0.4 : 1 + implicitHeight: (spinBox.implicitHeight - 2 * DS.Style.spinBox.indicatorContainerVMargin) / 2 - Component { - id: inactiveComponent - D.DciIcon { - id: icon - smooth: control.smooth - sourceSize.width: DS.Style.spinBox.indicator.iconSize - palette: D.DTK.makeIconPalette(control.palette) - name: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? "entry_spinbox_up" : "entry_spinbox_down" - mode: control.D.ColorSelector.controlState - theme: control.D.ColorSelector.controlTheme - fallbackToQIcon: false - } - } - - Component { - id: activeComponent - Item { - Item { - id: btnBackground - width: parent.width + DS.Style.control.radius - height: parent.height + DS.Style.control.radius - anchors { - right: parent.right - top: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? parent.top : undefined - bottom: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? undefined : parent.bottom - } - - Button { - id: btn - anchors { - right: parent.right - top: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? parent.top : undefined - bottom: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? undefined : parent.bottom - } - width: DS.Style.spinBox.indicatorWidth - height: spinBox.implicitHeight / 2 - icon { - name: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? "arrow_ordinary_up" : "arrow_ordinary_down" - width: DS.Style.spinBox.indicator.focusIconSize - height: DS.Style.spinBox.indicator.focusIconSize - } - activeFocusOnTab: false - opacity: 1 - background: P.ButtonPanel { - button: btn - radius: 0 - } - onClicked: { - if (direction === SpinBoxIndicator.IndicatorDirection.UpIndicator) { - spinBox.increase() - } else { - spinBox.decrease() - } - } - } - } + // Each indicator draws its own half of the combined background. + // The up indicator has rounded top corners; the down indicator has + // rounded bottom corners. Together they form a seamless whole with + // no overlap and no gap. + background: Rectangle { + radius: DS.Style.spinBox.indicatorContainerRadius + color: control.D.ColorSelector.indicatorBackground + topLeftRadius: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? DS.Style.spinBox.indicatorContainerRadius : 0 + topRightRadius: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? DS.Style.spinBox.indicatorContainerRadius : 0 + bottomLeftRadius: direction === SpinBoxIndicator.IndicatorDirection.DownIndicator ? DS.Style.spinBox.indicatorContainerRadius : 0 + bottomRightRadius: direction === SpinBoxIndicator.IndicatorDirection.DownIndicator ? DS.Style.spinBox.indicatorContainerRadius : 0 - D.ItemViewport { - id: viewport - sourceItem: btnBackground - radius: DS.Style.control.radius - fixed: true - width: btnBackground.width - height: btnBackground.height - anchors { - right: parent.right - top: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? parent.top : undefined - bottom: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? undefined : parent.bottom - } - hideSource: true + Loader { + active: D.DTK.themeType === D.ApplicationHelper.DarkType && direction === SpinBoxIndicator.IndicatorDirection.DownIndicator + anchors.fill: parent + sourceComponent: BoxInsetShadow { + shadowBlur: 1 + shadowOffsetY: -1 + spread: 0 + shadowColor: control.D.ColorSelector.indicatorInnerShadow + cornerRadius: DS.Style.spinBox.indicatorContainerRadius } } - } - Loader { + ToolButton { + opacity: D.ColorSelector.controlState === D.DTK.DisabledState ? 0.4 : 1 anchors.fill: parent - sourceComponent: spinBox.activeFocus ? activeComponent : inactiveComponent + topPadding: 0 + bottomPadding: 0 + leftPadding: 0 + rightPadding: 0 + focusPolicy: Qt.NoFocus + background: null + icon { + name: direction === SpinBoxIndicator.IndicatorDirection.UpIndicator ? "arrow_ordinary_up" : "arrow_ordinary_down" + width: DS.Style.spinBox.indicator.focusIconSize + height: DS.Style.spinBox.indicator.focusIconSize + } + activeFocusOnTab: false + onClicked: { + if (direction === SpinBoxIndicator.IndicatorDirection.UpIndicator) { + spinBox.increase() + } else { + spinBox.decrease() + } + } } }