-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cell.qml
227 lines (136 loc) · 3.87 KB
/
Cell.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import QtQuick 2.5
Item {
property string cellSymbol: qsTr(" ")
property color textColor: "#FFF"
property color borderColor: "#353535"
property color backgroundColor: "#050505"
property color hoverColor: "#404040"
property color clickedColor: "#252525"
property int hoverAnimationDuration: 150
property int clickAnimationDuration: 250
// Cell clicked
signal clicked
// Clear cell color and mark
function setClear() {
cell.cellSymbol = qsTr(" ")
cell.backgroundColor = "#050505"
cell.textColor = "#FFF"
cell.borderColor = "#353535"
cell.hoverColor = "#404040"
cell.clickedColor = "#252525"
}
// Set cell color to green and mark to Nought
function setNought() {
cell.cellSymbol = qsTr("O")
cell.backgroundColor = "#001500"
cell.textColor = "#00FF00"
cell.borderColor = "#005500"
cell.hoverColor = "#003500"
cell.clickedColor = "#002500"
}
// Set cell color to red and mark to Cross
function setCross() {
cell.cellSymbol = qsTr("✘")
cell.backgroundColor = "#150000"
cell.textColor = "#FF0000"
cell.borderColor = "#550000"
cell.hoverColor = "#350000"
cell.clickedColor = "#250000"
}
// Highlight cell
function highlight() {
cell.borderColor = cell.textColor
}
// Disable cell
function disable() {
cell.textColor = "#353535"
cell.borderColor = "#353535"
cell.hoverColor = "#404040"
cell.clickedColor = "#252525"
cell.backgroundColor = "#050505"
}
id: cell
x: 0
y: 0
height: 120
width: 120
smooth: true
Rectangle {
id: cellBackground
anchors.fill: cell
height: cell.height
width: cell.width
color: backgroundColor
radius: 10
border {
width: 5
color: borderColor
}
smooth: true
}
Text {
id: cellText
anchors.centerIn: cell
text: cellSymbol
color: textColor
style: Text.Raised
styleColor: "#FFF"
font {
family: "Arial"
pixelSize: 100
bold: true
}
antialiasing: true
smooth: true
}
PropertyAnimation {
id: hoverAnimation
target: cellBackground
properties: "color"
to: hoverColor
duration: hoverAnimationDuration
}
PropertyAnimation {
id: leaveAnimation
target: cellBackground
properties: "color"
to: backgroundColor
duration: hoverAnimationDuration
}
PropertyAnimation {
id: clickAnimation
target: cellBackground
properties: "color"
to: clickedColor
duration: clickAnimationDuration
}
PropertyAnimation {
id: releaseAnimation
target: cellBackground
properties: "color"
to: hoverColor
duration: clickAnimationDuration
}
MouseArea {
id: cellArea
anchors.fill: cell
hoverEnabled: true
// Visual effects (animation on hover)
onEntered: {
hoverAnimation.start()
}
// Visual effects (animation on hover out)
onExited: {
leaveAnimation.start()
}
// Visual effects (animation on cell released)
onReleased: {
releaseAnimation.start()
}
// Visual effects (animation on cell clicked)
onClicked: {
clickAnimation.start()
cell.clicked()
}
}
}