aboutsummaryrefslogtreecommitdiffstats
path: root/examples/declarative/dragtarget/tiles/DragTile.qml
blob: 213373a392d12902e7c26ef1912a1874931f3feb (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
import QtQuick 2.0

Rectangle {
    id: dragRectangle

    property Item dropTarget

    property string colorKey

    color: colorKey

    width: 100; height: 100

    Text {
        anchors.fill: parent
        color: "white"
        font.pixelSize: 90
        text: modelData + 1
        horizontalAlignment:Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
    }

    MouseArea {
        id: draggable

        anchors.fill: parent

        drag.target: parent
        drag.keys: [ colorKey ]

        drag.onDropped: dropTarget = dropItem

        states: [
            State {
                when: dragRectangle.dropTarget != undefined && !draggable.drag.active
                ParentChange {
                    target: dragRectangle
                    parent: dropTarget
                    x: 0
                    y: 0
                }
            },
            State {
                when: dragRectangle.dropTarget != undefined && draggable.drag.active
                ParentChange {
                    target: dragRectangle
                    parent: dropTarget
                }
            },
            State {
                when:  !draggable.drag.active
                AnchorChanges {
                    target: dragRectangle
                    anchors.horizontalCenter: parent.horizontalCenter
                }
            }
        ]
    }
}