Skip to content

Commit 21b366a

Browse files
authored
Merge pull request #32554 from grliszas14/dropdown_icon
Add ability to have an icon for dropdown
2 parents 5a8c838 + 20c9244 commit 21b366a

File tree

2 files changed

+76
-28
lines changed

2 files changed

+76
-28
lines changed

src/framework/uicomponents/qml/Muse/UiComponents/StyledDropdown.qml

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
import QtQuick
2323
import QtQuick.Controls
24+
import QtQuick.Layouts
2425

2526
import Muse.Ui
2627
import Muse.UiComponents
@@ -35,6 +36,7 @@ Item {
3536
property int count: Boolean(model) ? model.length : 0
3637
property string textRole: "text"
3738
property string valueRole: "value"
39+
property Component contentItem: null
3840

3941
property int currentIndex: -1
4042

@@ -51,9 +53,6 @@ Item {
5153

5254
property int popupItemsCount: 18
5355

54-
property alias dropIcon: mainItem.dropIcon
55-
property alias label: mainItem.label
56-
5756
property alias navigation: mainItem.navigation
5857

5958
property alias isOpened: dropdownLoader.isOpened
@@ -123,9 +122,6 @@ Item {
123122
property bool selected: false
124123
property bool insideDropdownList: false
125124

126-
property alias label: labelItem
127-
property alias dropIcon: dropIconItem
128-
129125
property color hoveredColor: backgroundItem.color
130126

131127
property alias navigation: navCtrl
@@ -136,7 +132,7 @@ Item {
136132
name: mainItem.objectName != "" ? mainItem.objectName : "Dropdown"
137133
enabled: mainItem.enabled && mainItem.visible
138134
accessible.role: MUAccessible.ComboBox
139-
accessible.name: labelItem.text
135+
accessible.name: root.displayText
140136

141137
onActiveChanged: {
142138
if (!mainItem.activeFocus) {
@@ -159,25 +155,50 @@ Item {
159155
NavigationFocusBorder { navigationCtrl: navCtrl }
160156
}
161157

162-
StyledTextLabel {
163-
id: labelItem
164-
anchors.top: parent.top
165-
anchors.bottom: parent.bottom
166-
anchors.left: parent.left
167-
anchors.right: dropIconItem.left
168-
anchors.leftMargin: 12
169-
anchors.rightMargin: 6
170-
horizontalAlignment: Text.AlignLeft
171-
text: root.displayText
172-
}
158+
Loader {
159+
id: contentLoader
160+
161+
anchors.fill: parent
162+
163+
sourceComponent: root.contentItem ?? defaultContentComponent
164+
165+
onLoaded: {
166+
const item = contentLoader.item
167+
if (!item) {
168+
return
169+
}
173170

174-
StyledIconLabel {
175-
id: dropIconItem
176-
anchors.verticalCenter: parent.verticalCenter
177-
anchors.right: parent.right
178-
anchors.rightMargin: 8
171+
if (item.text !== undefined) {
172+
item.text = Qt.binding(function() { return root.displayText })
173+
}
174+
}
175+
176+
Component {
177+
id: defaultContentComponent
178+
179+
RowLayout {
180+
property alias labelItem: labelItem
181+
182+
anchors.fill: parent
183+
anchors.leftMargin: 12
184+
anchors.rightMargin: 8
185+
spacing: 6
179186

180-
iconCode: IconCode.SMALL_ARROW_DOWN
187+
StyledTextLabel {
188+
id: labelItem
189+
190+
Layout.fillWidth: true
191+
Layout.alignment: Qt.AlignVCenter
192+
horizontalAlignment: Text.AlignLeft
193+
text: root.displayText
194+
}
195+
196+
StyledIconLabel {
197+
Layout.alignment: Qt.AlignVCenter
198+
iconCode: IconCode.SMALL_ARROW_DOWN
199+
}
200+
}
201+
}
181202
}
182203

183204
MouseArea {
@@ -190,12 +211,13 @@ Item {
190211
onClicked: mainItem.clicked()
191212

192213
onContainsMouseChanged: {
193-
if (!labelItem.truncated) {
214+
const defaultLabel = contentLoader.item ? contentLoader.item.labelItem : null
215+
if (!defaultLabel || !defaultLabel.truncated) {
194216
return
195217
}
196218

197219
if (mouseAreaItem.containsMouse) {
198-
ui.tooltip.show(mainItem, labelItem.text)
220+
ui.tooltip.show(mainItem, root.displayText)
199221
} else {
200222
ui.tooltip.hide(mainItem)
201223
}

src/instrumentsscene/qml/MuseScore/InstrumentsScene/internal/InstrumentsView.qml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,34 @@ Item {
149149
width: 86
150150
height: 24
151151

152-
label.anchors.leftMargin: 8
153-
dropIcon.anchors.rightMargin: 4
152+
contentItem: Item {
153+
property string text: ""
154+
property alias labelItem: labelItem
155+
156+
StyledTextLabel {
157+
id: labelItem
158+
159+
anchors.top: parent.top
160+
anchors.bottom: parent.bottom
161+
anchors.left: parent.left
162+
anchors.right: dropIconItem.left
163+
anchors.leftMargin: 8
164+
anchors.rightMargin: 6
165+
166+
horizontalAlignment: Text.AlignLeft
167+
text: parent.text
168+
}
169+
170+
StyledIconLabel {
171+
id: dropIconItem
172+
173+
anchors.verticalCenter: parent.verticalCenter
174+
anchors.right: parent.right
175+
anchors.rightMargin: 4
176+
177+
iconCode: IconCode.SMALL_ARROW_DOWN
178+
}
179+
}
154180

155181
visible: traitsBox.count > 1
156182

0 commit comments

Comments
 (0)