File size: 2,679 Bytes
a4cf109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import QtQuick 2.5
import QtQuick.Controls 2.4

Item {
    id: root
    signal activated(int index);
    property alias model: combo.model
    property alias text: name.text
    property alias curIndex: combo.currentIndex

    function setDefault(value) {
        const id = combo.find(value, Qt.MatchExactly);
        if (id !== -1) combo.currentIndex = id;
        else combo.currentIndex = 0;
    }

    function reset() {
        combo.currentIndex = 0;
    }

    function value() {
        return combo.currentText;
    }

    height: 100

    Text {
        id: name
        font.pixelSize: 35
        font.family: "Maison Neue"
        font.styleName: "Bold"
    }
    ComboBox {
        id: combo
        anchors {
            top: name.bottom
            topMargin: 20
        }
        width: parent.width
        height: 60

        font.family: "Maison Neue"
        font.styleName: "light"

        background: Rectangle {
            border.width: 2
            border.color: "black"
            color: "white"
            radius: 2
        }
        contentItem: Label {
            text: parent.currentText
            anchors {
                left: parent.left
                leftMargin: 15
                verticalCenter: parent.verticalCenter
                verticalCenterOffset: 2
            }
            verticalAlignment: Text.AlignVCenter
            color: "black"
        }

        delegate: ItemDelegate {
            width: root.width - 25
            contentItem: Text {
                text: modelData
                color: "black"
                font.family: "Maison Neue"
                font.styleName: "light"
                font.bold: combo.highlightedIndex === index
                verticalAlignment: Text.AlignVCenter
            }
        }

        popup: Popup {
            readonly property int columns: combo.model.length > 12 ? 2 : 1
            y: combo.height + 20
            width: root.width * columns
            implicitHeight: Math.min(contentItem.contentHeight + 20, 800)
            clip: true

            contentItem: GridView {
                id: grid
                flow: GridView.FlowLeftToRight
                model: combo.popup.visible ? combo.delegateModel : null
                currentIndex: combo.highlightedIndex
                cellWidth: root.width - 15
                cellHeight: combo.height

                ScrollBar.vertical: ScrollBar { policy: ScrollBar.AsNeeded }
            }

            background: Rectangle {
                border.color: "black"
                border.width: 2
                radius: 3
            }
        }

        onActivated: parent.activated(index);
    }
}