-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
413 lines (390 loc) · 12.2 KB
/
main.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtQuick.Shapes 1.12
import ModelWorld 1.0
Window {
id:mainWindow
visible: true
width: 400
height: 600
title: qsTr("LG")
property bool autoChecked: false
ModelWorld{
id:myModel
}
//size
PullDownMenu{
slideX:sizeMenu.x
slideStartY:sizeMenu.y-sizeMenu.height*4
slideEndY:sizeMenu.y
x: sizeMenu.x
y: sizeMenu.y-sizeMenu.height*4
height: sizeMenu.height*5
z:10
width: sizeMenu.width
secondButton.onClicked: myModel.setSize(10)
thirdButton.onClicked: myModel.setSize(15)
fourthButton.onClicked: myModel.setSize(20)
fifthButton.onClicked: myModel.setSize(25)
textFifth: "25X25"
textFourth: "20X20"
textThird: "15X15"
textSecond: "10X10"
textFirst: "Size"
}
//shape
PullDownMenu{
slideX:shapeMenu.x
slideStartY:shapeMenu.y-shapeMenu.height*4
slideEndY:shapeMenu.y
x: shapeMenu.x
y: shapeMenu.y-shapeMenu.height*4
height: shapeMenu.height*5
z:10
width: shapeMenu.width
secondButton.onClicked: root.delegate=squar
thirdButton.onClicked: root.delegate=circle
fourthButton.onClicked: root.delegate=triangle
fifthButton.onClicked: root.delegate=star
textFifth: "Star"
textFourth: "Triangle"
textThird: "Circle"
textSecond: "Square"
textFirst: "Shape"
}
//color
PullDownMenu{
slideX:colorButtonMenu.x
slideStartY:colorButtonMenu.y-colorButtonMenu.height*4
slideEndY:colorButtonMenu.y
x: colorButtonMenu.x
y: colorButtonMenu.y-colorButtonMenu.height*4
height: colorButtonMenu.height*5
antialiasing: true
width: colorButtonMenu.width
z:10
secondButton.onClicked: myModel.secondColor="black"
thirdButton.onClicked: myModel.secondColor="red"
fourthButton.onClicked: myModel.secondColor="green"
fifthButton.onClicked: myModel.secondColor="blue"
textFifth: "Blue"
textFourth: "Green"
textThird: "Red"
textSecond: "Black"
textFirst: "Color"
}
//top menu
Rectangle{
id:topMenu
anchors.top: parent.top
width: parent.width
height: parent.height/12
Row{
anchors.fill: parent
Row{
height: topMenu.height
width: topMenu.width/3
Rectangle{
height: parent.height
width: parent.width-areaGlider.width
color: "black"
TextComponent{
anchors.fill: parent
textComponent:"Game"
}
}
Rectangle{
id:areaGlider
height: parent.height
width: areaGlider.height
border.color: "black"
border.width: 3
Image {
id: glaider
anchors.centerIn: parent
height: parent.height-6
width: parent.height-6
source: "/Glider.svg.png"
}
}
}
Rectangle{
id:sizeMenu
height: topMenu.height
width: topMenu.width/6
Text {
anchors.fill: parent
text: qsTr("Size")
color: "white"
fontSizeMode: Text.Fit
font.pixelSize: 20
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.family: "Microsoft New Tai Lue"
font.bold: true
}
}
Rectangle{
id:shapeMenu
height: topMenu.height
width: topMenu.width/6
color:"black"
border.color: shapeButton.pressed?"white":"black"
border.width: 2
TextComponent{
anchors.fill: parent
textComponent:"Shape"
}
MouseArea{
anchors.fill: parent
id: shapeButton
}
}
Rectangle{
id:colorButtonMenu
height: topMenu.height
width: topMenu.width/6
}
Rectangle{
height: topMenu.height
width: topMenu.width/6
color:"black"
border.color: exitButton.pressed?"white":"black"
border.width: 2
TextComponent{
anchors.fill: parent
textComponent:"Exit"
}
MouseArea{
id:exitButton
anchors.fill: parent
onClicked:Qt.quit()
}
}
}
}
//world
Rectangle{
width: mainWindow.width
height: mainWindow.width
border.color: "black"
border.width: 1
anchors.centerIn: parent
GridView{
id:root
anchors.fill: parent
width: parent.width-2
height: parent.height-2
interactive: false
antialiasing: true
model: myModel
cellHeight:height/myModel.size
cellWidth:width/myModel.size
delegate: squar
}
}
//cell in the form of a triangle
Component{
id: triangle
Rectangle {
id:triangleRect
width: root.cellWidth
height: root.cellHeight
border.color: "black"
border.width: 1
MouseArea{
anchors.fill:parent
onClicked: {
root.currentIndex = model.index
myModel.changeCellByClick(root.currentIndex)
}
}
Shape {
antialiasing: true
anchors.fill: parent
ShapePath {
fillColor: model.color
startX: triangleRect.width/2; startY: 1
PathLine { x: triangleRect.width-2; y: triangleRect.width-2; }
PathLine { x: 2; y: triangleRect.width-2 }
PathLine { x: triangleRect.width/2; y: 1 }
}
}
}
}
//cell in the form of a star
Component{
id: star
Rectangle {
id:starRect
width: root.cellWidth
height: root.cellHeight
border.color: "black"
border.width: 1
color: "transparent"
MouseArea{
anchors.fill:parent
onClicked: {
root.currentIndex = model.index
myModel.changeCellByClick(root.currentIndex)
}
}
Shape {
antialiasing: true
anchors.fill: parent
ShapePath {
strokeWidth: -1
fillRule: ShapePath.WindingFill
fillColor: model.color
startX: starRect.width/2;
startY: 2
PathLine {
x:starRect.width/2*0.59+starRect.width/2
y:starRect.width/2*0.81+starRect.width/2
}
PathLine {
x:starRect.width/2*0.05
y:starRect.width/2-starRect.width/2*0.3
}
PathLine {
x:starRect.width/2+starRect.width/2*0.95
y:starRect.width/2-starRect.width/2*0.3
}
PathLine {
x:starRect.width/2-starRect.width/2*0.59
y:starRect.width/2+starRect.width/2*0.81
}
}
}
}
}
//cell in the form of a square
Component {
id: squar
Rectangle{
width: root.cellWidth
height: root.cellHeight
border.color: "black"
border.width: 1
color: model.color
MouseArea{
anchors.fill:parent
onClicked: {
root.currentIndex = model.index
myModel.changeCellByClick(root.currentIndex)
}
}
}
}
//cell in the form of a circle
Component {
id: circle
Rectangle {
id:cellRectangle
width: root.cellWidth
height: root.cellHeight
border.color: "black"
border.width: 1
color: "transparent"
Rectangle{
anchors.centerIn: cellRectangle
width: cellRectangle.width-5
height: cellRectangle.height-5
radius: height
color: model.color
}
MouseArea{
anchors.fill:parent
onClicked: {
root.currentIndex = model.index
myModel.changeCellByClick(root.currentIndex)
}
}
}
}
//bottom menu
Rectangle{
id:bottomMenu
width: parent.width
height: parent.height/12
anchors.bottom: parent.bottom
Row{
anchors.fill: parent
Rectangle{
height: bottomMenu.height
width: bottomMenu.width/4
color:"black"
border.color: stepButton.pressed?"white":"black"
border.width: 2
TextComponent{
anchors.fill: parent
textComponent:"Step"
}
MouseArea{
id: stepButton
anchors.fill: parent
onClicked: myModel.nextStep()
}
}
Rectangle{
height: bottomMenu.height
width: bottomMenu.width/4
color:"black"
border.color: randomButton.pressed?"white":"black"
border.width: 2
TextComponent{
anchors.fill: parent
textComponent:"Random"
}
MouseArea{
id: randomButton
anchors.fill: parent
onClicked: myModel.randomStart()
}
}
Rectangle{
height: bottomMenu.height
width: bottomMenu.width/4
color:"black"
border.color: autoButton.pressed?"white":"black"
border.width: 2
Timer {
id: timer
interval: 500
running: false
repeat: true
onTriggered: myModel.nextStep()
}
TextComponent{
anchors.fill: parent
textComponent:autoChecked ? "Stop": "Auto"
}
MouseArea{
id: autoButton
anchors.fill: parent
onClicked:{
timer.running = !timer.running
autoChecked=!autoChecked
}
}
}
Rectangle{
height: bottomMenu.height
width: bottomMenu.width/4
color:"black"
border.color: clearButton.pressed?"white":"black"
border.width: 2
TextComponent{
anchors.fill: parent
textComponent:"Clear"
}
MouseArea{
id:clearButton
anchors.fill: parent
onClicked:myModel.clear()
}
}
}
}
}