7import QtQuick.Controls as QQC2
10import org.kde.kirigami as Kirigami
11import org.kde.kirigamiaddons.delegates as Delegates
12import org.kde.kirigamiaddons.components as Components
48 signal activated(int index)
67 property string description: ""
72 property alias currentValue: combobox.currentValue
79 property alias currentText: combobox.currentText
96 property alias count: combobox.count
103 property alias textRole: combobox.textRole
110 property alias valueRole: combobox.valueRole
119 property alias currentIndex: combobox.currentIndex
126 property alias highlightedIndex: combobox.highlightedIndex
135 property alias displayText: combobox.displayText
148 property alias editable: combobox.editable
155 property alias editText: combobox.editText
186 property int displayMode: Kirigami.Settings.isMobile ? FormComboBoxDelegate.Dialog : FormComboBoxDelegate.ComboBox
191 property Component comboBoxDelegate: Delegates.RoundedItemDelegate {
192 implicitWidth: ListView.view ? ListView.view.width : Kirigami.Units.gridUnit * 16
193 text: controlRoot.textRole ? (Array.isArray(controlRoot.model) ? modelData[controlRoot.textRole] : model[controlRoot.textRole]) : modelData
194 highlighted: controlRoot.highlightedIndex === index
200 property Component dialogDelegate: Delegates.RoundedItemDelegate {
201 implicitWidth: ListView.view ? ListView.view.width : Kirigami.Units.gridUnit * 16
202 text: controlRoot.textRole ? (Array.isArray(controlRoot.model) ? modelData[controlRoot.textRole] : model[controlRoot.textRole]) : modelData
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;
257 if (_selectionDialogItem) {
258 _selectionDialogItem.close();
262 property var _selectionPageItem: null
263 property var _selectionDialogItem: null
264 property real __indicatorMargin: controlRoot.indicator && controlRoot.indicator.visible && controlRoot.indicator.width > 0 ? controlRoot.spacing + indicator.width + controlRoot.spacing : 0
266 leftPadding: horizontalPadding + (!controlRoot.mirrored ? 0 : __indicatorMargin)
267 rightPadding: horizontalPadding + (controlRoot.mirrored ? 0 : __indicatorMargin)
270 // use connections instead of onClicked on root, so that users can supply
271 // their own behaviour.
274 function onClicked() {
275 if (controlRoot.displayMode === FormComboBoxDelegate.Dialog) {
276 controlRoot._selectionDialogItem = controlRoot.dialog.createObject();
277 controlRoot._selectionDialogItem.open();
278 } else if (controlRoot.displayMode === FormComboBoxDelegate.Page) {
279 controlRoot._selectionPageItem = controlRoot.QQC2.ApplicationWindow.window.pageStack.pushDialogLayer(page)
281 combobox.popup.open();
282 combobox.forceActiveFocus(Qt.PopupFocusReason);
293 property Component dialog: QQC2.Dialog {
296 x: Math.round((parent.width - width) / 2)
297 y: Math.round((parent.height - height) / 2)
298 z: Kirigami.OverlayZStacking.z
300 title: controlRoot.text
301 implicitWidth: Math.min(parent.width - Kirigami.Units.gridUnit * 2, Kirigami.Units.gridUnit * 22)
302 parent: controlRoot.QQC2.Overlay.overlay
303 background: Components.DialogRoundedBackground {}
305 implicitHeight: Math.min(
306 Math.max(implicitBackgroundHeight + topInset + bottomInset,
307 contentHeight + topPadding + bottomPadding
308 + (implicitHeaderHeight > 0 ? implicitHeaderHeight + spacing : 0)
309 + (implicitFooterHeight > 0 ? implicitFooterHeight + spacing : 0)),
310 parent.height - Kirigami.Units.gridUnit * 2)
318 header: Kirigami.Heading {
320 elide: QQC2.Label.ElideRight
321 leftPadding: Kirigami.Units.largeSpacing
322 rightPadding: Kirigami.Units.largeSpacing
323 topPadding: Kirigami.Units.largeSpacing
324 bottomPadding: Kirigami.Units.largeSpacing
327 contentItem: ColumnLayout {
331 visible: !listView.atYBeginning
332 Layout.fillWidth: true
336 Layout.fillWidth: true
337 Layout.fillHeight: true
341 Component.onCompleted: if (background) {
342 background.visible = false;
349 model: controlRoot.model
350 delegate: controlRoot.dialogDelegate
351 currentIndex: controlRoot.currentIndex
352 onCurrentIndexChanged: controlRoot.currentIndex = currentIndex
357 visible: controlRoot.editable
358 Layout.fillWidth: true
362 visible: controlRoot.editable
363 onTextChanged: controlRoot.editText = text;
364 Layout.fillWidth: true
375 property Component page: Kirigami.ScrollablePage {
376 title: controlRoot.text
380 model: controlRoot.model
381 delegate: controlRoot.dialogDelegate
383 footer: QQC2.TextField {
384 visible: controlRoot.editable
385 onTextChanged: controlRoot.editText = text;
386 Layout.fillWidth: true
391 function indexOfValue(value) {
392 return combobox.indexOfValue(value);
395 focusPolicy: Qt.StrongFocus
396 Accessible.description: description
397 Accessible.onPressAction: controlRoot.clicked()
399 // Only have the mouse hover feedback if the combobox is the whole delegate itself
400 background: displayMode === FormComboBoxDelegate.ComboBox ? null : selectableBackground
401 FormDelegateBackground { id: selectableBackground; control: controlRoot }
403 contentItem: ColumnLayout {
404 spacing: Kirigami.Units.smallSpacing
407 Layout.fillWidth: true
408 spacing: Kirigami.Units.smallSpacing
411 Layout.fillWidth: true
412 text: controlRoot.text
413 elide: Text.ElideRight
414 color: controlRoot.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
417 Accessible.ignored: true
421 Layout.alignment: Qt.AlignRight
422 Layout.rightMargin: Kirigami.Units.smallSpacing
423 color: Kirigami.Theme.disabledTextColor
424 text: controlRoot.displayText
425 visible: controlRoot.displayMode === FormComboBoxDelegate.Dialog || controlRoot.displayMode === FormComboBoxDelegate.Page
429 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
430 direction: Qt.DownArrow
431 visible: controlRoot.displayMode === FormComboBoxDelegate.Dialog || controlRoot.displayMode === FormComboBoxDelegate.Page
437 focusPolicy: Qt.NoFocus // provided by parent
438 model: controlRoot.model
439 visible: controlRoot.displayMode == FormComboBoxDelegate.ComboBox
440 delegate: controlRoot.comboBoxDelegate
441 currentIndex: controlRoot.currentIndex
442 onActivated: index => controlRoot.activated(index)
443 onAccepted: controlRoot.accepted()
444 popup.contentItem.clip: true
445 Layout.fillWidth: true
449 visible: controlRoot.description !== "
"
450 Layout.fillWidth: true
451 text: controlRoot.description
452 color: Kirigami.Theme.disabledTextColor
454 Accessible.ignored: true
457 Kirigami.InlineMessage {
458 visible: controlRoot.statusMessage.length > 0
459 Layout.topMargin: visible ? Kirigami.Units.smallSpacing : 0
460 Layout.fillWidth: true
461 text: controlRoot.statusMessage
462 type: controlRoot.status