2121 */
2222import QtQuick
2323import QtQuick.Controls
24+ import QtQuick.Layouts
2425
2526import Muse.Ui
2627import Muse.UiComponents
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
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 }
0 commit comments