|
| 1 | +import QtQuick 2.9 |
| 2 | +import QtQuick.Controls 2.0 |
| 3 | +import QtQuick.Layouts 1.3 |
| 4 | +ComboBox { |
| 5 | + id: root |
| 6 | + property color checkedColor: "#1ABC9C" |
| 7 | + |
| 8 | + delegate:ItemDelegate { |
| 9 | + id:itemDelegate |
| 10 | + property string iconRectColor: iconColor |
| 11 | + property string iconRectIcon: iconName |
| 12 | + |
| 13 | + width: root.width * 1.4 |
| 14 | + height: 40 |
| 15 | + hoverEnabled: true |
| 16 | + focus: true |
| 17 | + |
| 18 | + background: Rectangle{ |
| 19 | + color: itemDelegate.hovered ? "blue" : "transparent" |
| 20 | + anchors.fill: parent |
| 21 | + radius: 8 |
| 22 | + } |
| 23 | + |
| 24 | + RowLayout { |
| 25 | + Layout.alignment: Qt.AlignVCenter |
| 26 | + width: parent.width |
| 27 | + height: parent.height |
| 28 | + anchors.fill: parent |
| 29 | + spacing: 10 |
| 30 | + Layout.leftMargin: 10 |
| 31 | + Layout.rightMargin: 10 |
| 32 | + |
| 33 | + Rectangle{ |
| 34 | + id:iconImageRect |
| 35 | + visible:iconRectIcon |
| 36 | + width: parent.height * 0.6 |
| 37 | + height: parent.height * 0.6 |
| 38 | + color: iconRectColor |
| 39 | + Layout.alignment: Qt.AlignVCenter |
| 40 | + Layout.leftMargin: 10 |
| 41 | + radius: 6 |
| 42 | + |
| 43 | + Label{ |
| 44 | + text: iconRectIcon |
| 45 | + font.pointSize: 8 |
| 46 | + anchors.centerIn: parent |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + Label { |
| 51 | + opacity: 0.87 |
| 52 | + font.pointSize: 12 |
| 53 | + text: name |
| 54 | + Layout.fillWidth: true |
| 55 | + font.weight: Font.Medium |
| 56 | + verticalAlignment: Image.AlignVCenter |
| 57 | + Layout.alignment: Qt.AlignVCenter |
| 58 | + color: itemDelegate.hovered ? "white" : Qt.darkGray |
| 59 | + Layout.leftMargin: iconImageRect.visible ? 0 : 10 |
| 60 | + } |
| 61 | + |
| 62 | + Label { |
| 63 | + opacity: 0.87 |
| 64 | + font.pointSize: 12 |
| 65 | + text: "✅" |
| 66 | + visible: root.currentIndex == index |
| 67 | + Layout.fillWidth: true |
| 68 | + font.weight: Font.Medium |
| 69 | + verticalAlignment: Image.AlignVCenter |
| 70 | + horizontalAlignment: Image.AlignRight |
| 71 | + Layout.alignment: Qt.AlignVCenter |
| 72 | + Layout.rightMargin: 10 |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + } |
| 77 | + |
| 78 | + indicator: Canvas { |
| 79 | + id: canvas |
| 80 | + x: root.width - width - 10 |
| 81 | + y: (root.availableHeight - height) / 2 |
| 82 | + width: 12 |
| 83 | + height: 8 |
| 84 | + contextType: "2d" |
| 85 | + |
| 86 | + Connections { |
| 87 | + target: root |
| 88 | + function onPressedChanged(){ |
| 89 | + canvas.requestPaint() |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + onPaint: { |
| 94 | + context.reset(); |
| 95 | + context.moveTo(0, 0); |
| 96 | + context.lineTo(width, 0); |
| 97 | + context.lineTo(width / 2, height); |
| 98 | + context.closePath(); |
| 99 | + context.fillStyle = "white" |
| 100 | + context.fill(); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + contentItem: Item { |
| 105 | + width: root.background.width - root.indicator.width - 10 |
| 106 | + height: root.background.height |
| 107 | + |
| 108 | + RowLayout { |
| 109 | + anchors.fill: parent |
| 110 | + spacing: 10 |
| 111 | + Rectangle{ |
| 112 | + id:iconRect |
| 113 | + visible: model.get(currentIndex).iconName ? true : false |
| 114 | + width: parent.height * 0.6 |
| 115 | + height: parent.height * 0.6 |
| 116 | + color: model.get(currentIndex).iconColor |
| 117 | + Layout.alignment: Qt.AlignVCenter |
| 118 | + Layout.leftMargin: 5 |
| 119 | + radius: 6 |
| 120 | + |
| 121 | + Label{ |
| 122 | + text: model.get(currentIndex).iconName |
| 123 | + font.pointSize: 8 |
| 124 | + anchors.centerIn: parent |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + Label { |
| 129 | + opacity: 0.87 |
| 130 | + font.pointSize: 12 |
| 131 | + text: model.get(currentIndex).name |
| 132 | + Layout.fillWidth: true |
| 133 | + font.weight: Font.Medium |
| 134 | + verticalAlignment: Image.AlignVCenter |
| 135 | + Layout.alignment: Qt.AlignVCenter |
| 136 | + color: "white" |
| 137 | + elide: Text.ElideRight |
| 138 | + Layout.leftMargin:iconRect.visible ? 0 : 10 |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + } |
| 143 | + |
| 144 | + background: Rectangle { |
| 145 | + implicitWidth: 200 |
| 146 | + implicitHeight: 41 |
| 147 | + color: root.down ? Qt.darker(root.checkedColor, 1.2) : root.checkedColor |
| 148 | + radius: 5 |
| 149 | + } |
| 150 | + |
| 151 | + popup: Popup { |
| 152 | + y: root.height - 1 |
| 153 | + width: root.width * 1.5 |
| 154 | + implicitHeight: contentItem.implicitHeight > 250 ? 250 : contentItem.implicitHeight |
| 155 | + padding: 4 |
| 156 | + contentItem: ListView { |
| 157 | + leftMargin: 5 |
| 158 | + implicitHeight: contentHeight |
| 159 | + keyNavigationEnabled: true |
| 160 | + model: root.popup.visible ? root.delegateModel : null |
| 161 | + clip: true |
| 162 | + focus: true |
| 163 | + currentIndex: root.highlightedIndex |
| 164 | + } |
| 165 | + |
| 166 | + background: Rectangle { |
| 167 | + anchors.fill: parent |
| 168 | + color: "#dde4de" |
| 169 | + radius: 4 |
| 170 | + clip: true |
| 171 | + } |
| 172 | + } |
| 173 | +} |
0 commit comments