import QtQuick 2.0
-Rectangle {
- id: dragRectangle
+Item {
+ id: root
+ property string colorKey
- property Item dropTarget
+ width: 100; height: 100
- property string colorKey
+ MouseArea {
+ id: mouseArea
- color: colorKey
+ width: 100; height: 100
+ anchors.centerIn: parent
- width: 100; height: 100
+ drag.target: tile
- Text {
- anchors.fill: parent
- color: "white"
- font.pixelSize: 90
- text: modelData + 1
- horizontalAlignment:Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- }
+ onReleased: parent = tile.Drag.target !== null ? tile.Drag.target : root
- MouseArea {
- id: draggable
+ Rectangle {
+ id: tile
- anchors.fill: parent
+ width: 100; height: 100
- drag.target: parent
- drag.keys: [ colorKey ]
+ anchors.horizontalCenter: parent.horizontalCenter; anchors.verticalCenter: parent.verticalCenter
+ color: colorKey
- drag.onDropped: dropTarget = dropItem
+ Drag.keys: [ colorKey ]
+ Drag.active: mouseArea.drag.active
+ Drag.hotSpot.x: 50
+ Drag.hotSpot.y: 50
- 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
- }
+ Text {
+ anchors.fill: parent
+ color: "white"
+ font.pixelSize: 90
+ text: modelData + 1
+ horizontalAlignment:Text.AlignHCenter
+ verticalAlignment: Text.AlignVCenter
}
- ]
+
+ states: State {
+ when: mouseArea.drag.active
+ ParentChange { target: tile; parent: root }
+ AnchorChanges { target: tile; anchors.verticalCenter: undefined; anchors.horizontalCenter: undefined }
+ }
+ }
}
}
+