summaryrefslogtreecommitdiff
path: root/share/qtcreator/qmldesigner/propertyEditorQmlSources/imports/StudioControls/FilterComboBox.qml
blob: c41fe060e500a493458e1ce2c2b124d9eb2f6724 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Quick 3D.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick
import QtQuick.Templates as T
import StudioTheme 1.0 as StudioTheme

Item {
    id: root

    enum Interaction { None, TextEdit, Key }

    property int currentInteraction: FilterComboBox.Interaction.None

    property alias model: sortFilterModel.model
    property alias items: sortFilterModel.items
    property alias delegate: sortFilterModel.delegate

    property alias font: textInput.font

    // This indicates if the value was committed or the user is still editing
    property bool editing: false

    // This is the actual filter that is applied on the model
    property string filter: ""
    property bool filterActive: root.filter !== ""

    // Accept arbitrary input or only items from the model
    property bool allowUserInput: false

    property alias editText: textInput.text
    property int highlightedIndex: -1 // items index
    property int currentIndex: -1 // items index

    property string autocompleteString: ""

    property bool __isCompleted: false

    property alias actionIndicator: actionIndicator

    // This property is used to indicate the global hover state
    property bool hover: actionIndicator.hover || textInput.hover || checkIndicator.hover
    property alias edit: textInput.edit
    property alias open: popup.visible

    property alias actionIndicatorVisible: actionIndicator.visible
    property real __actionIndicatorWidth: StudioTheme.Values.actionIndicatorWidth
    property real __actionIndicatorHeight: StudioTheme.Values.actionIndicatorHeight

    property bool dirty: false // user modification flag

    property bool escapePressed: false

    signal accepted()
    signal activated(int index)
    signal compressedActivated(int index, int reason)

    enum ActivatedReason { EditingFinished, Other }

    property alias popup: popup
    property alias popupScrollBar: popupScrollBar
    property alias popupMouseArea: popupMouseArea

    property bool hasActiveDrag: false // an item that can be dropped here is being dragged
    property bool hasActiveHoverDrag: false // an item that can be dropped her is being hovered on top

    width: StudioTheme.Values.defaultControlWidth
    height: StudioTheme.Values.defaultControlHeight
    implicitHeight: StudioTheme.Values.defaultControlHeight

    function selectItem(itemsIndex) {
        textInput.text = sortFilterModel.items.get(itemsIndex).model.name
        root.currentIndex = itemsIndex
        root.finishEditing()
        root.activated(itemsIndex)
    }

    function submitValue() {
        if (!root.allowUserInput) {
            // If input isn't according to any item in the model, don't finish editing
            if (root.highlightedIndex === -1)
                return

            root.selectItem(root.highlightedIndex)
        } else {
            root.currentIndex = -1

            // Only trigger the signal, if the value was modified
            if (root.dirty) {
                myTimer.stop()
                root.dirty = false
                root.editText = root.editText.trim()
            }

            root.finishEditing()
            root.accepted()
        }
    }

    function finishEditing() {
        root.editing = false
        root.filter = ""
        root.autocompleteString = ""
        textInput.focus = false // Remove focus from text field
        popup.close()
    }

    function increaseVisibleIndex() {
        let numItems = sortFilterModel.visibleGroup.count
        if (!numItems)
            return

        if (root.highlightedIndex === -1) // Nothing is selected
            root.setHighlightedIndexVisible(0)
        else {
            let currentVisibleIndex = sortFilterModel.items.get(root.highlightedIndex).visibleIndex
            ++currentVisibleIndex

            if (currentVisibleIndex > numItems - 1)
                currentVisibleIndex = 0

            root.setHighlightedIndexVisible(currentVisibleIndex)
        }
    }

    function decreaseVisibleIndex() {
        let numItems = sortFilterModel.visibleGroup.count
        if (!numItems)
            return

        if (root.highlightedIndex === -1) // Nothing is selected
            root.setHighlightedIndexVisible(numItems - 1)
        else {
            let currentVisibleIndex = sortFilterModel.items.get(root.highlightedIndex).visibleIndex
            --currentVisibleIndex

            if (currentVisibleIndex < 0)
                currentVisibleIndex = numItems - 1

            root.setHighlightedIndexVisible(currentVisibleIndex)
        }
    }

    function updateHighlightedIndex() {
        // Check if current index is still part of the filtered list, if not set it to 0
        if (root.highlightedIndex !== -1 && !sortFilterModel.items.get(root.highlightedIndex).inVisible) {
            root.setHighlightedIndexVisible(0)
        } else {
            // Needs to be set in order for ListView to keep its currenIndex up to date, so
            // scroll position gets updated according to the higlighted item
            root.setHighlightedIndexItems(root.highlightedIndex)
        }
    }

    function setHighlightedIndexItems(itemsIndex) { // items group index
        root.highlightedIndex = itemsIndex

        if (itemsIndex === -1)
            listView.currentIndex = -1
        else
            listView.currentIndex = sortFilterModel.items.get(itemsIndex).visibleIndex
    }

    function setHighlightedIndexVisible(visibleIndex) { // visible group index
        if (visibleIndex === -1)
            root.highlightedIndex = -1
        else
            root.highlightedIndex = sortFilterModel.visibleGroup.get(visibleIndex).itemsIndex

        listView.currentIndex = visibleIndex
    }

    function updateAutocomplete() {
        if (root.highlightedIndex === -1)
            root.autocompleteString = ""
        else {
            let suggestion = sortFilterModel.items.get(root.highlightedIndex).model.name
            root.autocompleteString = suggestion.substring(textInput.text.length)
        }
    }

    // TODO is this already case insensitiv?!
    function find(text) {
        for (let i = 0; i < sortFilterModel.items.count; ++i)
            if (sortFilterModel.items.get(i).model.name === text)
                return i

        return -1
    }

    Timer {
        id: myTimer
        property int activatedIndex
        repeat: false
        running: false
        interval: 100
        onTriggered: root.compressedActivated(myTimer.activatedIndex,
                                              ComboBox.ActivatedReason.Other)
    }

    onActivated: function(index) {
        myTimer.activatedIndex = index
        myTimer.restart()
    }

    onHighlightedIndexChanged: {
        if (root.editing || (root.editText === "" && root.allowUserInput))
            root.updateAutocomplete()
    }

    DelegateModel {
        id: noMatchesModel

        model: ListModel {
            ListElement { name: "No matches" }
        }

        delegate: ItemDelegate {
            id: noMatchesDelegate
            width: popup.width - popup.leftPadding - popup.rightPadding
                   - (popupScrollBar.visible ? popupScrollBar.contentItem.implicitWidth + 2
                                             : 0) // TODO Magic number
            height: StudioTheme.Values.height - 2 * StudioTheme.Values.border
            padding: 0

            contentItem: Text {
                leftPadding: StudioTheme.Values.inputHorizontalPadding
                text: name
                font.italic: true
                color: StudioTheme.Values.themeTextColor
                elide: Text.ElideRight
                verticalAlignment: Text.AlignVCenter
            }

            background: Rectangle {
                x: 0
                y: 0
                width: noMatchesDelegate.width
                height: noMatchesDelegate.height
                color: "transparent"
            }
        }
    }

    SortFilterModel {
        id: sortFilterModel

        filterAcceptsItem: function(item) {
            return item.name.toLowerCase().startsWith(root.filter.toLowerCase())
        }

        lessThan: function(left, right) {
            if (left.group === right.group) {
              return left.name.toLowerCase().localeCompare(right.name.toLowerCase())
            }

            return left.group - right.group
        }

        delegate: ItemDelegate {
            id: delegateRoot
            width: popup.width - popup.leftPadding - popup.rightPadding
                   - (popupScrollBar.visible ? popupScrollBar.contentItem.implicitWidth + 2
                                             : 0) // TODO Magic number
            height: StudioTheme.Values.height - 2 * StudioTheme.Values.border
            padding: 0
            hoverEnabled: true
            highlighted: root.highlightedIndex === delegateRoot.DelegateModel.itemsIndex

            onHoveredChanged: {
                if (delegateRoot.hovered && !popupMouseArea.active)
                    root.setHighlightedIndexItems(delegateRoot.DelegateModel.itemsIndex)
            }

            onClicked: root.selectItem(delegateRoot.DelegateModel.itemsIndex)

            indicator: Item {
                id: itemDelegateIconArea
                width: delegateRoot.height
                height: delegateRoot.height

                T.Label {
                    id: itemDelegateIcon
                    text: StudioTheme.Constants.tickIcon
                    color: delegateRoot.highlighted ? StudioTheme.Values.themeTextSelectedTextColor
                                                    : StudioTheme.Values.themeTextColor
                    font.family: StudioTheme.Constants.iconFont.family
                    font.pixelSize: StudioTheme.Values.spinControlIconSizeMulti
                    visible: root.currentIndex === delegateRoot.DelegateModel.itemsIndex ? true
                                                                                         : false
                    anchors.fill: parent
                    renderType: Text.NativeRendering
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }
            }

            contentItem: Text {
                leftPadding: itemDelegateIconArea.width
                text: name
                color: delegateRoot.highlighted ? StudioTheme.Values.themeTextSelectedTextColor
                                                : StudioTheme.Values.themeTextColor
                font: textInput.font
                elide: Text.ElideRight
                verticalAlignment: Text.AlignVCenter
            }

            background: Rectangle {
                x: 0
                y: 0
                width: delegateRoot.width
                height: delegateRoot.height
                color: delegateRoot.highlighted ? StudioTheme.Values.themeInteraction
                                                : "transparent"
            }
        }

        onUpdated: {
            if (!root.__isCompleted)
                return

            if (sortFilterModel.count === 0)
                root.setHighlightedIndexVisible(-1)
            else {
                if (root.highlightedIndex === -1 && !root.allowUserInput)
                    root.setHighlightedIndexVisible(0)
            }
        }
    }

    Row {
        ActionIndicator {
            id: actionIndicator
            myControl: root
            x: 0
            y: 0
            width: actionIndicator.visible ? root.__actionIndicatorWidth : 0
            height: actionIndicator.visible ? root.__actionIndicatorHeight : 0
        }

        TextInput {
            id: textInput

            property bool hover: textInputMouseArea.containsMouse && textInput.enabled
            property bool edit: textInput.activeFocus
            property string preFocusText: ""

            x: 0
            y: 0
            z: 2
            width: root.width - actionIndicator.width
            height: root.height
            leftPadding: StudioTheme.Values.inputHorizontalPadding
            rightPadding: StudioTheme.Values.inputHorizontalPadding + checkIndicator.width
                          + StudioTheme.Values.border
            horizontalAlignment: Qt.AlignLeft
            verticalAlignment: Qt.AlignVCenter
            color: StudioTheme.Values.themeTextColor
            selectionColor: StudioTheme.Values.themeTextSelectionColor
            selectedTextColor: StudioTheme.Values.themeTextSelectedTextColor
            selectByMouse: true
            clip: true

            Rectangle {
                id: textInputBackground
                z: -1
                width: textInput.width
                height: textInput.height
                color: StudioTheme.Values.themeControlBackground
                border.color: StudioTheme.Values.themeControlOutline
                border.width: StudioTheme.Values.border
            }

            MouseArea {
                id: textInputMouseArea
                anchors.fill: parent
                enabled: true
                hoverEnabled: true
                propagateComposedEvents: true
                acceptedButtons: Qt.LeftButton
                cursorShape: Qt.PointingHandCursor
                onPressed: function(mouse) {
                    textInput.forceActiveFocus()
                    mouse.accepted = false
                }

                // Stop scrollable views from scrolling while ComboBox is in edit mode and the mouse
                // pointer is on top of it. We might add wheel selection in the future.
                onWheel: function(wheel) {
                    wheel.accepted = root.edit
                }
            }

            onEditingFinished: {
                if (root.escapePressed) {
                    root.escapePressed = false
                    root.editText = textInput.preFocusText
                } else {
                    if (root.currentInteraction === FilterComboBox.Interaction.TextEdit) {
                        if (root.dirty)
                            root.submitValue()
                    } else if (root.currentInteraction === FilterComboBox.Interaction.Key) {
                        root.selectItem(root.highlightedIndex)
                    }
                }

                sortFilterModel.update()
            }

            onTextEdited: {
                root.currentInteraction = FilterComboBox.Interaction.TextEdit
                root.editing = true
                popupMouseArea.active = true
                root.dirty = true

                if (textInput.text !== "")
                    root.filter = textInput.text
                else {
                    root.filter = ""
                    root.autocompleteString = ""
                }

                if (!popup.visible)
                    popup.open()

                sortFilterModel.update()

                if (!root.allowUserInput)
                    root.updateHighlightedIndex()
                else
                    root.setHighlightedIndexVisible(-1)

                root.updateAutocomplete()
            }

            onActiveFocusChanged: {
                if (textInput.activeFocus) {
                    popup.open()
                    textInput.preFocusText = textInput.text
                } else
                    popup.close()
            }

            states: [
                State {
                    name: "default"
                    when: root.enabled && !textInput.edit && !root.hover && !root.open
                          && !root.hasActiveDrag
                    PropertyChanges {
                        target: textInputBackground
                        color: StudioTheme.Values.themeControlBackground
                        border.color: StudioTheme.Values.themeControlOutline
                    }
                    PropertyChanges {
                        target: textInputMouseArea
                        cursorShape: Qt.PointingHandCursor
                        acceptedButtons: Qt.LeftButton
                    }
                },
                State {
                    name: "acceptsDrag"
                    when: root.enabled && root.hasActiveDrag && !root.hasActiveHoverDrag
                    PropertyChanges {
                        target: textInputBackground
                        border.color: StudioTheme.Values.themeInteraction
                    }
                },
                State {
                    name: "dragHover"
                    when: root.enabled && root.hasActiveHoverDrag
                    PropertyChanges {
                        target: textInputBackground
                        color: StudioTheme.Values.themeControlBackgroundInteraction
                        border.color: StudioTheme.Values.themeInteraction
                    }
                },
                State {
                    name: "globalHover"
                    when: root.hover && !textInput.hover && !textInput.edit && !root.open
                    PropertyChanges {
                        target: textInputBackground
                        color: StudioTheme.Values.themeControlBackgroundGlobalHover
                    }
                },
                State {
                    name: "hover"
                    when: textInput.hover && root.hover && !textInput.edit
                    PropertyChanges {
                        target: textInputBackground
                        color: StudioTheme.Values.themeControlBackgroundHover
                    }
                },
                State {
                    name: "edit"
                    when: root.edit
                    PropertyChanges {
                        target: textInputBackground
                        color: StudioTheme.Values.themeControlBackgroundInteraction
                        border.color: StudioTheme.Values.themeControlOutlineInteraction
                    }
                    PropertyChanges {
                        target: textInputMouseArea
                        cursorShape: Qt.IBeamCursor
                        acceptedButtons: Qt.NoButton
                    }
                },
                State {
                    name: "disable"
                    when: !root.enabled
                    PropertyChanges {
                        target: textInputBackground
                        color: StudioTheme.Values.themeControlBackgroundDisabled
                    }
                    PropertyChanges {
                        target: textInput
                        color: StudioTheme.Values.themeTextColorDisabled
                    }
                }
            ]

            Text {
                visible: root.autocompleteString !== ""
                text: root.autocompleteString
                x: textInput.leftPadding + textMetrics.advanceWidth
                y: (textInput.height - Math.ceil(textMetrics.height)) / 2
                color: "gray" // TODO proper color value
                font: textInput.font
                renderType: textInput.renderType
            }

            TextMetrics {
                id: textMetrics
                font: textInput.font
                text: textInput.text
            }

            Rectangle {
                id: checkIndicator

                property bool hover: checkIndicatorMouseArea.containsMouse && checkIndicator.enabled
                property bool pressed: checkIndicatorMouseArea.containsPress
                property bool checked: popup.visible

                x: textInput.width - checkIndicator.width - StudioTheme.Values.border
                y: StudioTheme.Values.border
                width: StudioTheme.Values.height - StudioTheme.Values.border
                height: textInput.height  - (StudioTheme.Values.border * 2)
                color: StudioTheme.Values.themeControlBackground
                border.width: 0

                MouseArea {
                    id: checkIndicatorMouseArea
                    anchors.fill: parent
                    hoverEnabled: true
                    onClicked: {
                        if (popup.visible)
                            popup.close()
                        else
                            popup.open()

                        if (!textInput.activeFocus) {
                            textInput.forceActiveFocus()
                            textInput.selectAll()
                        }
                    }
                }

                T.Label {
                    id: checkIndicatorIcon
                    anchors.fill: parent
                    color: StudioTheme.Values.themeTextColor
                    text: StudioTheme.Constants.upDownSquare2
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                    font.pixelSize: StudioTheme.Values.sliderControlSizeMulti
                    font.family: StudioTheme.Constants.iconFont.family
                }

                states: [
                    State {
                        name: "default"
                        when: root.enabled && checkIndicator.enabled && !root.edit
                              && !checkIndicator.hover && !root.hover
                              && !checkIndicator.checked && !root.hasActiveHoverDrag
                        PropertyChanges {
                            target: checkIndicator
                            color: StudioTheme.Values.themeControlBackground
                        }
                    },
                    State {
                        name: "dragHover"
                        when: root.enabled && root.hasActiveHoverDrag
                        PropertyChanges {
                            target: checkIndicator
                            color: StudioTheme.Values.themeControlBackgroundInteraction
                        }
                    },
                    State {
                        name: "globalHover"
                        when: root.enabled && checkIndicator.enabled
                              && !checkIndicator.hover && root.hover && !root.edit
                              && !checkIndicator.checked
                        PropertyChanges {
                            target: checkIndicator
                            color: StudioTheme.Values.themeControlBackgroundGlobalHover
                        }
                    },
                    State {
                        name: "hover"
                        when: root.enabled && checkIndicator.enabled
                              && checkIndicator.hover && root.hover && !checkIndicator.pressed
                              && !checkIndicator.checked
                        PropertyChanges {
                            target: checkIndicator
                            color: StudioTheme.Values.themeControlBackgroundHover
                        }
                    },
                    State {
                        name: "check"
                        when: checkIndicator.checked
                        PropertyChanges {
                            target: checkIndicatorIcon
                            color: StudioTheme.Values.themeIconColor
                        }
                        PropertyChanges {
                            target: checkIndicator
                            color: StudioTheme.Values.themeInteraction
                        }
                    },
                    State {
                        name: "press"
                        when: root.enabled && checkIndicator.enabled
                              && checkIndicator.pressed
                        PropertyChanges {
                            target: checkIndicatorIcon
                            color: StudioTheme.Values.themeIconColor
                        }
                        PropertyChanges {
                            target: checkIndicator
                            color: StudioTheme.Values.themeInteraction
                        }
                    },
                    State {
                        name: "disable"
                        when: !root.enabled
                        PropertyChanges {
                            target: checkIndicator
                            color: StudioTheme.Values.themeControlBackgroundDisabled
                        }
                        PropertyChanges {
                            target: checkIndicatorIcon
                            color: StudioTheme.Values.themeTextColorDisabled
                        }
                    }
                ]
            }
        }
    }

    T.Popup {
        id: popup
        x: textInput.x + StudioTheme.Values.border
        y: textInput.height
        width: textInput.width - (StudioTheme.Values.border * 2)
        height: Math.min(popup.contentItem.implicitHeight + popup.topPadding + popup.bottomPadding,
                         root.Window.height - popup.topMargin - popup.bottomMargin,
                         StudioTheme.Values.maxComboBoxPopupHeight)
        padding: StudioTheme.Values.border
        margins: 0 // If not defined margin will be -1
        closePolicy: T.Popup.NoAutoClose

        contentItem: ListView {
            id: listView
            clip: true
            implicitHeight: listView.contentHeight
            highlightMoveVelocity: -1
            boundsBehavior: Flickable.StopAtBounds
            flickDeceleration: 10000

            model: {
                if (popup.visible)
                    return sortFilterModel.count ? sortFilterModel : noMatchesModel

                return null
            }

            ScrollBar.vertical: ScrollBar {
                id: popupScrollBar
                visible: listView.height < listView.contentHeight
            }
        }

        background: Rectangle {
            color: StudioTheme.Values.themePopupBackground
            border.width: 0
        }

        onOpened: {
            // Reset the highlightedIndex of ListView as binding with condition didn't work
            if (root.highlightedIndex !== -1)
                root.setHighlightedIndexItems(root.highlightedIndex)
        }

        onAboutToShow: {
            // Select first item in list
            if (root.highlightedIndex === -1 && sortFilterModel.count && !root.allowUserInput)
                root.setHighlightedIndexVisible(0)
        }

        MouseArea {
            // This is MouseArea is intended to block the hovered property of an ItemDelegate
            // when the ListView changes due to Key interaction.

            id: popupMouseArea
            property bool active: true

            anchors.fill: parent
            enabled: popup.visible && popupMouseArea.active
            hoverEnabled: true
            onPositionChanged: { popupMouseArea.active = false }
        }
    }

    Keys.onDownPressed: {
        if (!sortFilterModel.visibleGroup.count)
            return

        root.currentInteraction = FilterComboBox.Interaction.Key
        root.increaseVisibleIndex()

        popupMouseArea.active = true
    }

    Keys.onUpPressed: {
        if (!sortFilterModel.visibleGroup.count)
            return

        root.currentInteraction = FilterComboBox.Interaction.Key
        root.decreaseVisibleIndex()

        popupMouseArea.active = true
    }

    Keys.onEscapePressed: {
        root.escapePressed = true
        root.finishEditing()
    }

    Component.onCompleted: {
        let index = root.find(root.editText)
        root.currentIndex = index
        root.highlightedIndex = index // TODO might not be intended

        root.__isCompleted = true
    }
}