7import QtQuick.Controls as QQC2
10import org.kde.kirigami as Kirigami
11import org.kde.kirigamiaddons.delegates as Delegates
47 signal activated(int index)
66 property string description: ""
71 property alias currentValue: combobox.currentValue
78 property alias currentText: combobox.currentText
95 property alias count: combobox.count
102 property alias textRole: combobox.textRole
109 property alias valueRole: combobox.valueRole
118 property alias currentIndex: combobox.currentIndex
125 property alias highlightedIndex: combobox.highlightedIndex
134 property alias displayText: combobox.displayText
147 property alias editable: combobox.editable
154 property alias editText: combobox.editText
185 property int displayMode: Kirigami.Settings.isMobile ? FormComboBoxDelegate.Dialog : FormComboBoxDelegate.ComboBox
190 property Component comboBoxDelegate: Delegates.RoundedItemDelegate {
191 implicitWidth: ListView.view ? ListView.view.width : Kirigami.Units.gridUnit * 16
192 text: controlRoot.textRole ? (Array.isArray(controlRoot.model) ? modelData[controlRoot.textRole] : model[controlRoot.textRole]) : modelData
193 highlighted: controlRoot.highlightedIndex === index
199 property Component dialogDelegate: Delegates.RoundedItemDelegate {
200 implicitWidth: ListView.view ? ListView.view.width : Kirigami.Units.gridUnit * 16
201 text: controlRoot.textRole ? (Array.isArray(controlRoot.model) ? modelData[controlRoot.textRole] : model[controlRoot.textRole]) : modelData
202 checked: controlRoot.currentIndex === index
204 Layout.topMargin: index == 0 ? Math.round(Kirigami.Units.smallSpacing / 2) : 0
207 controlRoot.currentIndex = index;
208 controlRoot.activated(index);
209 controlRoot.closeDialog();
234 property var status: Kirigami.MessageType.Information
244 property string statusMessage: "
"
251 function closeDialog() {
252 if (_selectionPageItem) {
253 _selectionPageItem.closeDialog();
254 _selectionPageItem = null;
262 property var _selectionPageItem: null
263 property real __indicatorMargin: controlRoot.indicator && controlRoot.indicator.visible && controlRoot.indicator.width > 0 ? controlRoot.spacing + indicator.width + controlRoot.spacing : 0
265 leftPadding: horizontalPadding + (!controlRoot.mirrored ? 0 : __indicatorMargin)
266 rightPadding: horizontalPadding + (controlRoot.mirrored ? 0 : __indicatorMargin)
269 // use connections instead of onClicked on root, so that users can supply
270 // their own behaviour.
273 function onClicked() {
274 if (controlRoot.displayMode === FormComboBoxDelegate.Dialog) {
275 controlRoot.dialog.open();
276 } else if (controlRoot.displayMode === FormComboBoxDelegate.Page) {
277 controlRoot._selectionPageItem = controlRoot.QQC2.ApplicationWindow.window.pageStack.pushDialogLayer(page)
279 combobox.popup.open();
280 combobox.forceActiveFocus(Qt.PopupFocusReason);
291 property var dialog: Kirigami.Dialog {
293 showCloseButton: false
294 title: controlRoot.text
295 preferredWidth: Kirigami.Units.gridUnit * 16
296 parent: QQC2.Overlay.overlay
302 model: controlRoot.model
303 delegate: controlRoot.dialogDelegate
307 visible: controlRoot.editable
308 onTextChanged: controlRoot.editText = text;
309 Layout.fillWidth: true
320 property Component page: Kirigami.ScrollablePage {
321 title: controlRoot.text
325 model: controlRoot.model
326 delegate: controlRoot.dialogDelegate
328 footer: QQC2.TextField {
329 visible: controlRoot.editable
330 onTextChanged: controlRoot.editText = text;
331 Layout.fillWidth: true
336 function indexOfValue(value) {
337 return combobox.indexOfValue(value);
340 focusPolicy: Qt.StrongFocus
341 Accessible.description: description
342 Accessible.onPressAction: controlRoot.clicked()
344 // Only have the mouse hover feedback if the combobox is the whole delegate itself
345 background: displayMode === FormComboBoxDelegate.ComboBox ? null : selectableBackground
346 FormDelegateBackground { id: selectableBackground; control: controlRoot }
348 contentItem: ColumnLayout {
349 spacing: Kirigami.Units.smallSpacing
352 Layout.fillWidth: true
353 spacing: Kirigami.Units.smallSpacing
356 Layout.fillWidth: true
357 text: controlRoot.text
358 elide: Text.ElideRight
359 color: controlRoot.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
362 Accessible.ignored: true
366 Layout.alignment: Qt.AlignRight
367 Layout.rightMargin: Kirigami.Units.smallSpacing
368 color: Kirigami.Theme.disabledTextColor
369 text: controlRoot.displayText
370 visible: controlRoot.displayMode === FormComboBoxDelegate.Dialog || controlRoot.displayMode === FormComboBoxDelegate.Page
374 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
375 direction: Qt.DownArrow
376 visible: controlRoot.displayMode === FormComboBoxDelegate.Dialog || controlRoot.displayMode === FormComboBoxDelegate.Page
382 focusPolicy: Qt.NoFocus // provided by parent
383 model: controlRoot.model
384 visible: controlRoot.displayMode == FormComboBoxDelegate.ComboBox
385 delegate: controlRoot.comboBoxDelegate
386 currentIndex: controlRoot.currentIndex
387 onActivated: index => controlRoot.activated(index)
388 onAccepted: controlRoot.accepted()
389 popup.contentItem.clip: true
390 Layout.fillWidth: true
394 visible: controlRoot.description !== "
"
395 Layout.fillWidth: true
396 text: controlRoot.description
397 color: Kirigami.Theme.disabledTextColor
399 Accessible.ignored: true
402 Kirigami.InlineMessage {
403 visible: controlRoot.statusMessage.length > 0
404 Layout.topMargin: visible ? Kirigami.Units.smallSpacing : 0
405 Layout.fillWidth: true
406 text: controlRoot.statusMessage
407 type: controlRoot.status