~timo-jyrinki/ubuntu/trusty/qtdeclarative-opensource-src/sru_backport_two_requested_patches

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
import QtQuick 2.0

ListView {
    id: list
    width: 400
    height: 600
    model: ListModel {
        ListElement { kind: "Bought" }
        ListElement { kind: "Available To Buy" }
    }

    delegate: ListView {
        id: innerList
        objectName: "list" + index
        height: count * itemHeight
        width: parent.width
        interactive: false
        property int count: {
            if (innerList.foo == 0) return 50;
            else return 100;
        }
        property int itemHeight: innerList.foo == 0 ? 200 : 50;
        model: count
        property int foo: index
        property bool enableRange: true
        onEnableRangeChanged: updatedDelegateCreationRange();

        delegate: Item {
            width: parent.width
            height: innerList.itemHeight
            Rectangle {
                width: parent.width - 20
                height: parent.height - 20
                anchors.centerIn: parent
                color: {
                    if (innerList.foo == 0) return Math.random() * 2 > 1 ? "green" : "yellow";
                    else return Math.random() * 2 > 1 ? "red" : "blue";
                }
                Text {
                    text: index
                }
            }
        }

        delegateCreationBegin: enableRange ? 0 : undefined
        delegateCreationEnd: enableRange ? 0 : undefined

        function updatedDelegateCreationRange() {
            if (!enableRange) {
              delegateCreationBegin = undefined
              delegateCreationEnd = undefined
              return;
            }

            if (list.contentY + list.height <= y) {
                // Not visible
                delegateCreationBegin = 0
                delegateCreationEnd = 0
            } else if (y + height <= list.contentY) {
                // Not visible
                delegateCreationBegin = height
                delegateCreationEnd = height
            } else {
                delegateCreationBegin = Math.max(list.contentY - y, 0)
                delegateCreationEnd = Math.min(list.contentY + list.height - y, height)
            }
        }

        Component.onCompleted: updatedDelegateCreationRange();
        Connections {
            target: list
            onContentYChanged: updatedDelegateCreationRange();
            onHeightChanged: updatedDelegateCreationRange();
        }
    }

    section.property: "kind"
    section.delegate: Text {
        height: 40
        font.pixelSize: 30
        text: section
    }
}