aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicklistview/data/roundingErrors.qml
blob: 2c1a1e665d94b7ea254c32cc20e17eee08505ab6 (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
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick 2.0
import QtQml.Models 2.1

ListView {
    id: listview

    width: 600
    height: 200

    spacing: 8
    orientation: ListView.Horizontal

    Component.onCompleted: {
        var colors = ["blue", "green", "red", "yellow", "orange", "purple", "cyan",
                      "magenta", "chartreuse", "aquamarine", "indigo", "lightsteelblue",
                      "violet", "grey", "springgreen", "salmon", "blanchedalmond",
                      "forestgreen", "pink", "navy", "goldenrod", "crimson", "teal" ]
        for (var i = 0; i < 100; ++i)
            colorModel.append( { nid: i,  color: colors[i%colors.length] } )
    }

    model: DelegateModel {
        id: visualModel

        model: ListModel {
            id: colorModel
        }

        delegate: MouseArea {
            id: delegateRoot
            objectName: model.nid

            width: 107.35
            height: 63.35

            drag.target: icon

            Rectangle{
                id: icon
                width: delegateRoot.width
                height: delegateRoot.height
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.verticalCenter: parent.verticalCenter
                color: model.color

                Drag.active: delegateRoot.drag.active
                Drag.source: delegateRoot
                Drag.hotSpot.x: 36
                Drag.hotSpot.y: 36

                Text {
                    id: text
                    anchors.fill: parent
                    font.pointSize: 40
                    text: model.nid
                    horizontalAlignment: Qt.AlignHCenter
                    verticalAlignment: Qt.AlignVCenter
                }

                states: [
                    State {
                        when: icon.Drag.active
                        ParentChange {
                            target: icon
                            parent: delegateRoot.ListView.view
                        }

                        AnchorChanges {
                            target: icon
                            anchors.horizontalCenter: undefined
                            anchors.verticalCenter: undefined
                        }
                    }
                ]
            }
        }
    }

    DropArea {
        anchors.fill: parent
        onPositionChanged: (drag) => {
            var to = listview.indexAt(drag.x + listview.contentX, 0)
            if (to !== -1) {
                var from = drag.source.DelegateModel.itemsIndex
                if (from !== to)
                    visualModel.items.move(from, to)
                drag.accept()
            }
        }
    }
}