-
Notifications
You must be signed in to change notification settings - Fork 0
/
Field.qml
333 lines (197 loc) · 5.22 KB
/
Field.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
import QtQuick 2.5
Item {
id: field
x: 0
y: 0
width: 400
height: 400
property bool done: false
property bool hintVisibility: false
property string noughtSign: qsTr("◯")
property string crossSign: qsTr("✘")
property string hintText: qsTr("CLICK<br>ME!")
property color backgroundColor: "#050505"
property color noughtColor: "#00FF00"
property color noughtHoverColor: "#002500"
property color crossColor: "#FF0000"
property color crossHoverColor: "#250000"
property color hintColor: "#FF0"
// Cell(x, y) clicked
signal clicked(int x, int y)
// Hint clicked
signal hintClicked
// Get cell(x, y)
function getCell(x, y) {
switch(x + y * 3) {
case 0:
return cell00
case 1:
return cell10
case 2:
return cell20
case 3:
return cell01
case 4:
return cell11
case 5:
return cell21
case 6:
return cell02
case 7:
return cell12
case 8:
return cell22
default:
return undefined
}
}
// Clear cells
function clear() {
cell00.setClear()
cell10.setClear()
cell20.setClear()
cell01.setClear()
cell11.setClear()
cell21.setClear()
cell02.setClear()
cell12.setClear()
cell22.setClear()
}
// Highlight cell(i) where i = x + y * 3
function highlightCell(i) {
field.getCell(i % 3, Math.floor(i / 3)).highlight()
}
// Disable cell(i) where i = x + y * 3
function disableCell(i) {
field.getCell(i % 3, Math.floor(i / 3)).disable()
}
Rectangle {
id: background
anchors.fill: parent
color: backgroundColor
smooth: true
}
Grid {
id: grid
anchors.centerIn: parent
columns: 3
spacing: 10
Cell {
id: cell00
onClicked: {
hintAnimation.start()
field.clicked(0, 0)
}
}
Cell {
id: cell10
onClicked: {
hintAnimation.start()
field.clicked(1, 0)
}
}
Cell {
id: cell20
onClicked: {
hintAnimation.start()
field.clicked(2, 0)
}
}
Cell {
id: cell01
onClicked: {
hintAnimation.start()
field.clicked(0, 1)
}
}
Cell {
id: cell11
onClicked: {
hintAnimation.start()
field.clicked(1, 1)
}
}
Cell {
id: cell21
onClicked: {
hintAnimation.start()
field.clicked(2, 1)
}
}
Cell {
id: cell02
onClicked: {
hintAnimation.start()
field.clicked(0, 2)
}
}
Cell {
id: cell12
onClicked: {
hintAnimation.start()
field.clicked(1, 2)
}
}
Cell {
id: cell22
onClicked: {
hintAnimation.start()
field.clicked(2, 2)
}
}
}
PropertyAnimation {
id: hintAnimation
target: hint
properties: "opacity"
from: 1.0
to: 0.75
duration: 1000
}
Rectangle {
id: hint
visible: hintVisibility
anchors.centerIn: parent
width: parent.width
height: parent.height
color: background.color
Rectangle {
id: hintBorder
anchors.centerIn: parent
width: parent.width - 80
height: parent.height - 200
color: background.color
opacity: 1.0
radius: 10
border {
width: 10
color: hintColor
}
}
Text {
id: hintTextData
anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter
color: hintColor
style: Text.Raised
styleColor: "#FFF"
textFormat: Text.RichText
text: hintText
font {
family: "Arial"
bold: true
pixelSize: 36
}
antialiasing: true
smooth: true
}
MouseArea {
id: hintArea
anchors.fill: hint
hoverEnabled: true
onClicked: {
field.hintClicked()
}
}
}
}