aboutsummaryrefslogtreecommitdiffstats
path: root/DemoApplication/controls/CNListView.qml
blob: 74582310b94f17ac926f28d11d9b090a7871fae8 (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
import QtQuick 2.11
import QtQuick.Controls 2.4
import CursorNavigation 1.0

ListView {
    id: listView
    spacing: 4
    focus: true
    /* when list view scopes the cursor, the cursor is passed further to its
     * currently focused child. this means, moving from outside to the list,
     * will return the cursor to the item that was previously selected
     * comment this out to make transition directly between individual list items and the rest of the ui
     */
    CursorNavigation.acceptsCursor: true

    Rectangle {
        anchors.fill: parent
        border.width: 1
        border.color: listView.activeFocus ? "red" : "black"
        color: "transparent"
    }

    highlight: Rectangle {
        width: listView.width
        height: 40
        color: "lightgrey"
        opacity: 0.3
    }

    delegate: ItemDelegate {
        id: deleg
        width: listView.width
        height: 40
        CursorNavigation.acceptsCursor: true

        //make sure the list's current index follows the cursor!
        CursorNavigation.onHasCursorChanged: {
            if (CursorNavigation.hasCursor)
                listView.currentIndex = index
        }

        contentItem: Rectangle {
            width: listView.width
            height: 40
            border.color: deleg.CursorNavigation.hasCursor ? "red" : "transparent"

            Row {
                width: (parent.width - x)
                height: 35
                x: 5
                anchors.verticalCenter: parent.verticalCenter
                spacing: 10
                Rectangle {
                    width: parent.height
                    height: parent.height
                    radius: width/2
                    color: colorCode
                }
                Text {
                    height: parent.height
                    font.bold: true
                    verticalAlignment: Text.AlignVCenter
                    text: name
                }
            }
        }
        onClicked: {
            listView.currentIndex = index;
        }
    }

}