From d8bcf2ed5984c8d2e1e0e0edec2d72c55744e8e2 Mon Sep 17 00:00:00 2001 From: Pico Date: Sun, 9 Nov 2025 01:41:00 +0300 Subject: [PATCH] added symbol (icon) support to items --- .../modules/common/widgets/StyledComboBox.qml | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/dots/.config/quickshell/ii/modules/common/widgets/StyledComboBox.qml b/dots/.config/quickshell/ii/modules/common/widgets/StyledComboBox.qml index 4910c0d49..75bb76f28 100644 --- a/dots/.config/quickshell/ii/modules/common/widgets/StyledComboBox.qml +++ b/dots/.config/quickshell/ii/modules/common/widgets/StyledComboBox.qml @@ -42,10 +42,15 @@ ComboBox { Loader { Layout.alignment: Qt.AlignVCenter - active: root.buttonIcon.length > 0 + active: root.buttonIcon.length > 0 || (root.currentIndex >= 0 && root.model[root.currentIndex]?.icon) visible: active sourceComponent: MaterialSymbol { - text: root.buttonIcon + text: { + if (root.currentIndex >= 0 && root.model[root.currentIndex]?.icon) { + return root.model[root.currentIndex].icon; + } + return root.buttonIcon; + } iconSize: Appearance.font.pixelSize.larger color: Appearance.colors.colOnSecondaryContainer } @@ -88,13 +93,36 @@ ComboBox { anchors.leftMargin: 12 anchors.rightMargin: 12 - StyledText { - Layout.fillWidth: true + Loader { Layout.alignment: Qt.AlignVCenter - color: root.currentIndex === itemDelegate.index ? Appearance.colors.colOnPrimary : Appearance.colors.colOnSecondaryContainer - text: itemDelegate.model[root.textRole] - elide: Text.ElideRight - verticalAlignment: Text.AlignVCenter + Layout.preferredHeight: Appearance.font.pixelSize.larger + active: itemDelegate.model.icon && itemDelegate.model.icon.length > 0 + visible: active + sourceComponent: Item { + implicitWidth: icon.implicitWidth + implicitHeight: Appearance.font.pixelSize.larger + MaterialSymbol { + id: icon + anchors.centerIn: parent + text: itemDelegate.model.icon + iconSize: Appearance.font.pixelSize.larger + color: root.currentIndex === itemDelegate.index ? Appearance.colors.colOnPrimary : Appearance.colors.colOnSecondaryContainer + } + } + } + + Item { + Layout.fillWidth: true + Layout.preferredHeight: Appearance.font.pixelSize.larger + + StyledText { + anchors.centerIn: parent + width: parent.width + color: root.currentIndex === itemDelegate.index ? Appearance.colors.colOnPrimary : Appearance.colors.colOnSecondaryContainer + text: itemDelegate.model[root.textRole] + elide: Text.ElideRight + verticalAlignment: Text.AlignVCenter + } } } } @@ -134,6 +162,7 @@ ComboBox { id: listView clip: true implicitHeight: contentHeight + spacing: 2 model: root.popup.visible ? root.delegateModel : null currentIndex: root.highlightedIndex