diff --git a/qt6/src/qml/Button.qml b/qt6/src/qml/Button.qml index 076f950a..de0c7e31 100644 --- a/qt6/src/qml/Button.qml +++ b/qt6/src/qml/Button.qml @@ -23,8 +23,7 @@ T.Button { opacity: D.ColorSelector.controlState === D.DTK.DisabledState ? 0.4 : 1 D.DciIcon.mode: D.ColorSelector.controlState D.DciIcon.theme: D.ColorSelector.controlTheme - D.DciIcon.palette: D.DTK.makeIconPalette(palette) - palette.windowText: D.ColorSelector.textColor + D.DciIcon.palette: D.DTK.makeIconPaletteWithForeground(palette, D.ColorSelector.textColor) icon { width: DS.Style.button.iconSize height: DS.Style.button.iconSize diff --git a/qt6/src/qml/ButtonIndicator.qml b/qt6/src/qml/ButtonIndicator.qml index f021bf1c..54e96539 100644 --- a/qt6/src/qml/ButtonIndicator.qml +++ b/qt6/src/qml/ButtonIndicator.qml @@ -22,7 +22,7 @@ Rectangle { width: DS.Style.buttonIndicator.iconSize } name: "arrow_ordinary_down" - palette: control.D.DTK.makeIconPalette(control.palette) + palette: control.D.DTK.makeIconPaletteWithForeground(control.palette, control.D.ColorSelector.textColor) mode: control.D.ColorSelector.controlState theme: control.D.ColorSelector.controlTheme fallbackToQIcon: false diff --git a/qt6/src/qml/IconButton.qml b/qt6/src/qml/IconButton.qml index c7492d2c..717a0fb1 100644 --- a/qt6/src/qml/IconButton.qml +++ b/qt6/src/qml/IconButton.qml @@ -26,7 +26,7 @@ Button { contentItem: D.DciIcon { smooth: control.smooth name: control.icon.name - palette: D.DTK.makeIconPalette(control.palette) + palette: D.DTK.makeIconPaletteWithForeground(control.palette, control.D.ColorSelector.textColor) mode: control.D.ColorSelector.controlState theme: control.D.ColorSelector.controlTheme sourceSize: Qt.size(control.icon.width, control.icon.height) diff --git a/qt6/src/qml/ItemDelegate.qml b/qt6/src/qml/ItemDelegate.qml index ef530a6d..6517cc57 100644 --- a/qt6/src/qml/ItemDelegate.qml +++ b/qt6/src/qml/ItemDelegate.qml @@ -18,6 +18,10 @@ T.ItemDelegate { property bool contentFlow property Component content property D.Palette checkedTextColor: DS.Style.checkedButton.text + readonly property color resolvedTextColor: { + let undraged = D.DTK.hasAnimation ? control.backgroundVisible && !dragActive : true + return checked && !control.cascadeSelected && undraged ? D.ColorSelector.checkedTextColor : control.palette.windowText + } property int corners: D.RoundRectangle.TopLeftCorner | D.RoundRectangle.TopRightCorner | D.RoundRectangle.BottomLeftCorner | D.RoundRectangle.BottomRightCorner property bool dragActive: false // drag @@ -43,14 +47,10 @@ T.ItemDelegate { spacing: DS.Style.control.spacing checkable: true autoExclusive: true - palette.windowText: { - let undraged = D.DTK.hasAnimation ? control.backgroundVisible && !dragActive : true - return checked && !control.cascadeSelected && undraged ? D.ColorSelector.checkedTextColor : undefined - } D.DciIcon.mode: D.ColorSelector.controlState D.DciIcon.theme: D.ColorSelector.controlTheme - D.DciIcon.palette: D.DTK.makeIconPalette(palette) + D.DciIcon.palette: D.DTK.makeIconPaletteWithForeground(palette, control.resolvedTextColor) icon { width: DS.Style.itemDelegate.iconSize height: DS.Style.itemDelegate.iconSize @@ -65,7 +65,7 @@ T.ItemDelegate { sourceComponent: D.DciIcon { smooth: control.smooth - palette: D.DTK.makeIconPalette(control.palette) + palette: D.DTK.makeIconPaletteWithForeground(control.palette, control.resolvedTextColor) mode: control.D.ColorSelector.controlState theme: control.D.ColorSelector.controlTheme fallbackToQIcon: false @@ -84,7 +84,7 @@ T.ItemDelegate { ? Qt.AlignCenter : Qt.AlignLeft | Qt.AlignVCenter text: control.text font: control.font - color: control.palette.windowText + color: control.resolvedTextColor icon: D.DTK.makeIcon(control.icon, control.D.DciIcon) Layout.fillWidth: !control.contentFlow } diff --git a/qt6/src/qml/MenuItem.qml b/qt6/src/qml/MenuItem.qml index ed61474a..3f78c320 100644 --- a/qt6/src/qml/MenuItem.qml +++ b/qt6/src/qml/MenuItem.qml @@ -27,10 +27,9 @@ T.MenuItem { : DS.Style.menu.itemText property D.Palette subMenuBackgroundColor: DS.Style.menu.subMenuOpenedBackground - palette.windowText: D.ColorSelector.textColor D.DciIcon.mode: D.ColorSelector.controlState D.DciIcon.theme: D.ColorSelector.controlTheme - D.DciIcon.palette: D.DTK.makeIconPalette(palette) + D.DciIcon.palette: D.DTK.makeIconPaletteWithForeground(palette, D.ColorSelector.textColor) contentItem: D.IconLabel { readonly property real arrowPadding: control.subMenu && control.arrow ? control.arrow.width + control.spacing : 0 readonly property real indicatorPadding: control.useIndicatorPadding && control.indicator ? control.indicator.width + control.spacing : 0 @@ -44,7 +43,7 @@ T.MenuItem { alignment: Qt.AlignLeft text: control.text font: control.font - color: control.palette.windowText + color: control.D.ColorSelector.textColor Behavior on color { enabled: D.DTK.hasAnimation ColorAnimation { duration: control.hovered ? 100 : 0; } diff --git a/qt6/src/qml/WindowButton.qml b/qt6/src/qml/WindowButton.qml index 81e0d82a..cc050b3b 100644 --- a/qt6/src/qml/WindowButton.qml +++ b/qt6/src/qml/WindowButton.qml @@ -33,7 +33,7 @@ D.IconButton { smooth: control.smooth name: control.icon.name asynchronous: false - palette: D.DTK.makeIconPalette(control.palette) + palette: D.DTK.makeIconPaletteWithForeground(control.palette, control.D.ColorSelector.textColor) mode: control.D.ColorSelector.controlState theme: control.D.ColorSelector.controlTheme sourceSize: Qt.size(control.icon.width, control.icon.height) diff --git a/src/private/dqmlglobalobject.cpp b/src/private/dqmlglobalobject.cpp index a63d5bd2..80053166 100644 --- a/src/private/dqmlglobalobject.cpp +++ b/src/private/dqmlglobalobject.cpp @@ -444,6 +444,15 @@ DDciIconPalette DQMLGlobalObject::makeIconPalette(const QQuickPalette *palette) iconPalette.setHighlightForeground(palette->highlightedText()); return iconPalette; } + +// 在 makeIconPalette 基础上,显式设置前景色(用于状态相关图标的颜色渲染) +DDciIconPalette DQMLGlobalObject::makeIconPaletteWithForeground(const QQuickPalette *palette, const QColor &foreground) +{ + DDciIconPalette iconPalette = makeIconPalette(palette); + if (foreground.isValid()) + iconPalette.setForeground(foreground); + return iconPalette; +} #endif bool DQMLGlobalObject::sendMessage(QObject *target, const QString &content, const QString &iconName, int duration, const QString &msgId) diff --git a/src/private/dqmlglobalobject_p.h b/src/private/dqmlglobalobject_p.h index e2d24d55..11d7ce5a 100644 --- a/src/private/dqmlglobalobject_p.h +++ b/src/private/dqmlglobalobject_p.h @@ -228,6 +228,7 @@ class DQMLGlobalObject : public QObject, public DTK_CORE_NAMESPACE::DObject Q_INVOKABLE DTK_GUI_NAMESPACE::DDciIconPalette makeIconPalette(const QPalette &palette); #else Q_INVOKABLE DTK_GUI_NAMESPACE::DDciIconPalette makeIconPalette(const QQuickPalette *palette); + Q_INVOKABLE DTK_GUI_NAMESPACE::DDciIconPalette makeIconPaletteWithForeground(const QQuickPalette *palette, const QColor &foreground); #endif Q_INVOKABLE bool sendMessage(QObject *target, const QString &content, const QString &iconName = QString(), int duration = 4000, const QString &msgId = QString());