-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChessPiece.qml
129 lines (114 loc) · 2.98 KB
/
ChessPiece.qml
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import QtQuick 2.4
import QmlChess 1.0
import QtGraphicalEffects 1.0
Item {
id: root
property int index: boardIndex
Behavior on x {
NumberAnimation {
easing.type: Easing.InOutCubic
duration: 300
}
}
Behavior on y {
NumberAnimation {
easing.type: Easing.InOutCubic
duration: 300
}
}
Image {
id: img
anchors.fill: parent
sourceSize: Qt.size(parent.width, parent.height)
source: "qrc:/Pieces/" + iconSrc + ".svg"
opacity: marea.enabled ? 1.0 : 0.5
}
DropShadow {
anchors.fill: img
source: img
samples: 16
color: "#c0000000"
radius: 3
verticalOffset: 2
}
MouseArea {
id: marea
anchors.fill: parent
drag.threshold: 0
enabled: false
drag.onActiveChanged: {
piece.active = drag.active
if (drag.active) {
root.Drag.start(Qt.MoveAction)
} else {
if (root.Drag.target)
root.Drag.drop()
root.x = column * width
root.y = row * height
}
}
}
Drag.active: marea.drag.active
Drag.dragType: Drag.Internal
Drag.keys: [ "piece" ]
Drag.hotSpot: Qt.point(marea.mouseX, marea.mouseY)
states: [
State {
name: "readyToMove"
extend: 'onboard'
when: boardModel.turn == color && inGame
PropertyChanges {
target: marea
drag.target: root
enabled: true
}
},
State {
name: "onboard"
when: inGame
ParentChange {
target: root
parent: checkerboard.topmost
}
PropertyChanges {
target: root
width: checkerboard.cellsize
height: width
rotation: -checkerboard.__boardContainer.rotation
x: column * width
y: row * height
}
},
State {
name: "capturedByWhite"
when: color == Piece.Black && !inGame
ParentChange {
target: root
parent: whitePanel.prison
rotation: 360
width: 40
height: 40
x: 0
y: 0
}
},
State {
name: "capturedByBlack"
when: color == Piece.White && !inGame
ParentChange {
target: root
parent: blackPanel.prison
rotation: 360
width: 40
height: 40
x: 0
y: 0
}
}
]
transitions: Transition {
ParentAnimation {
NumberAnimation { properties: "x,y,rotation,width,heigth"; duration: 300; easing.type: Easing.OutCubic }
}
}
}