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
203 checked: controlRoot.currentIndex === index
205 Layout.topMargin: index == 0 ? Math.round(Kirigami.Units.smallSpacing / 2) : 0
208 controlRoot.currentIndex = index;
209 controlRoot.activated(index);
210 controlRoot.closeDialog();
235 property var status: Kirigami.MessageType.Information
245 property string statusMessage: "
"
252 function closeDialog() {
253 if (_selectionPageItem) {
254 _selectionPageItem.closeDialog();
255 _selectionPageItem = null;
263 property var _selectionPageItem: 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 const dialogObject = controlRoot.dialog.createObject();
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: applicationWindow().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
355 visible: controlRoot.editable
356 Layout.fillWidth: true
360 visible: controlRoot.editable
361 onTextChanged: controlRoot.editText = text;
362 Layout.fillWidth: true
373 property Component page: Kirigami.ScrollablePage {
374 title: controlRoot.text
378 model: controlRoot.model
379 delegate: controlRoot.dialogDelegate
381 footer: QQC2.TextField {
382 visible: controlRoot.editable
383 onTextChanged: controlRoot.editText = text;
384 Layout.fillWidth: true
389 function indexOfValue(value) {
390 return combobox.indexOfValue(value);
393 focusPolicy: Qt.StrongFocus
394 Accessible.description: description
395 Accessible.onPressAction: controlRoot.clicked()
397 // Only have the mouse hover feedback if the combobox is the whole delegate itself
398 background: displayMode === FormComboBoxDelegate.ComboBox ? null : selectableBackground
399 FormDelegateBackground { id: selectableBackground; control: controlRoot }
401 contentItem: ColumnLayout {
402 spacing: Kirigami.Units.smallSpacing
405 Layout.fillWidth: true
406 spacing: Kirigami.Units.smallSpacing
409 Layout.fillWidth: true
410 text: controlRoot.text
411 elide: Text.ElideRight
412 color: controlRoot.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
415 Accessible.ignored: true
419 Layout.alignment: Qt.AlignRight
420 Layout.rightMargin: Kirigami.Units.smallSpacing
421 color: Kirigami.Theme.disabledTextColor
422 text: controlRoot.displayText
423 visible: controlRoot.displayMode === FormComboBoxDelegate.Dialog || controlRoot.displayMode === FormComboBoxDelegate.Page
427 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
428 direction: Qt.DownArrow
429 visible: controlRoot.displayMode === FormComboBoxDelegate.Dialog || controlRoot.displayMode === FormComboBoxDelegate.Page
435 focusPolicy: Qt.NoFocus // provided by parent
436 model: controlRoot.model
437 visible: controlRoot.displayMode == FormComboBoxDelegate.ComboBox
438 delegate: controlRoot.comboBoxDelegate
439 currentIndex: controlRoot.currentIndex
440 onActivated: index => controlRoot.activated(index)
441 onAccepted: controlRoot.accepted()
442 popup.contentItem.clip: true
443 Layout.fillWidth: true
447 visible: controlRoot.description !== "
"
448 Layout.fillWidth: true
449 text: controlRoot.description
450 color: Kirigami.Theme.disabledTextColor
452 Accessible.ignored: true
455 Kirigami.InlineMessage {
456 visible: controlRoot.statusMessage.length > 0
457 Layout.topMargin: visible ? Kirigami.Units.smallSpacing : 0
458 Layout.fillWidth: true
459 text: controlRoot.statusMessage
460 type: controlRoot.status