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

« back to all changes in this revision

Viewing changes to tests/auto/quick/qquicklistview/data/delegateCreationRange.qml

  • Committer: Package Import Robot
  • Author(s): Michał Sawicz
  • Date: 2013-09-11 14:03:31 UTC
  • Revision ID: package-import@ubuntu.com-20130911140331-wv7btehlz356piyi
Tags: 5.0.2-6ubuntu2
Add qtquick_delegate_creation_range_itemviews.patch to patchset.
(LP: #1217924)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
import QtQuick 2.0
 
3
 
 
4
ListView {
 
5
    id: list
 
6
    width: 400
 
7
    height: 600
 
8
    model: ListModel {
 
9
        ListElement { kind: "Bought" }
 
10
        ListElement { kind: "Available To Buy" }
 
11
    }
 
12
 
 
13
    delegate: ListView {
 
14
        id: innerList
 
15
        objectName: "list" + index
 
16
        height: count * itemHeight
 
17
        width: parent.width
 
18
        interactive: false
 
19
        property int count: {
 
20
            if (innerList.foo == 0) return 50;
 
21
            else return 100;
 
22
        }
 
23
        property int itemHeight: innerList.foo == 0 ? 200 : 50;
 
24
        model: count
 
25
        property int foo: index
 
26
        property bool enableRange: true
 
27
        onEnableRangeChanged: updatedDelegateCreationRange();
 
28
 
 
29
        delegate: Item {
 
30
            width: parent.width
 
31
            height: innerList.itemHeight
 
32
            Rectangle {
 
33
                width: parent.width - 20
 
34
                height: parent.height - 20
 
35
                anchors.centerIn: parent
 
36
                color: {
 
37
                    if (innerList.foo == 0) return Math.random() * 2 > 1 ? "green" : "yellow";
 
38
                    else return Math.random() * 2 > 1 ? "red" : "blue";
 
39
                }
 
40
                Text {
 
41
                    text: index
 
42
                }
 
43
            }
 
44
        }
 
45
 
 
46
        delegateCreationBegin: enableRange ? 0 : undefined
 
47
        delegateCreationEnd: enableRange ? 0 : undefined
 
48
 
 
49
        function updatedDelegateCreationRange() {
 
50
            if (!enableRange) {
 
51
              delegateCreationBegin = undefined
 
52
              delegateCreationEnd = undefined
 
53
              return;
 
54
            }
 
55
 
 
56
            if (list.contentY + list.height <= y) {
 
57
                // Not visible
 
58
                delegateCreationBegin = 0
 
59
                delegateCreationEnd = 0
 
60
            } else if (y + height <= list.contentY) {
 
61
                // Not visible
 
62
                delegateCreationBegin = height
 
63
                delegateCreationEnd = height
 
64
            } else {
 
65
                delegateCreationBegin = Math.max(list.contentY - y, 0)
 
66
                delegateCreationEnd = Math.min(list.contentY + list.height - y, height)
 
67
            }
 
68
        }
 
69
 
 
70
        Component.onCompleted: updatedDelegateCreationRange();
 
71
        Connections {
 
72
            target: list
 
73
            onContentYChanged: updatedDelegateCreationRange();
 
74
            onHeightChanged: updatedDelegateCreationRange();
 
75
        }
 
76
    }
 
77
 
 
78
    section.property: "kind"
 
79
    section.delegate: Text {
 
80
        height: 40
 
81
        font.pixelSize: 30
 
82
        text: section
 
83
    }
 
84
}
 
 
b'\\ No newline at end of file'