-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
133 lines (122 loc) · 3.58 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
import QtQuick 2.11
import QtQuick.Layouts 1.11
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.1
import Qt.labs.platform 1.0 as QLP
import Map 1.0
ApplicationWindow {
id: window
height: 480
width: 480
visible: true
Material.theme: Material.Dark
Material.accent: Material.Blue
menuBar: MenuBar {
Menu {
title: "File"
MenuItem {
text: "Open..."
onTriggered: loadMap.visible = true
}
MenuItem {
text: "Save..."
onTriggered: saveMap.visible = true
}
}
Menu {
title: "Map size"
MenuItem {
text: "10"
onTriggered: map.start(10)
}
MenuItem {
text: "20"
onTriggered: map.start(20)
}
MenuItem {
text: "50"
onTriggered: map.start(50)
}
MenuItem {
text: "100"
onTriggered: map.start(100)
}
}
}
ColumnLayout {
anchors.fill: parent
GridLayout {
id: tableView
Layout.fillHeight: true
Layout.fillWidth: true
columns: map.size
rowSpacing: 1
columnSpacing: 1
Repeater {
model: Map {
id: map
}
Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true
color: {
if(map.countNeighborsFromIndex(index) < 2 && modelData && colorCB.checked) {
return "#440000"
} else if(map.countNeighborsFromIndex(index) > 3 && modelData && colorCB.checked) {
return "#440000"
} else if(map.countNeighborsFromIndex(index) == 3 && !modelData && colorCB.checked) {
return "#004400"
} else if(modelData) {
return "#f3f3f4"
} else {
return "#505050"
}
}
MouseArea {
anchors.fill: parent
onClicked: cell = !cell
}
Text {
text: map.countNeighborsFromIndex(index)
}
}
}
}
RowLayout {
Button {
text: "Clear"
Layout.fillWidth: true
onClicked: {print(window.loadMap);map.start(map.size);}
}
Button {
text: map.running ? "Stop" : "Start"
Layout.fillWidth: true
onClicked: map.running = !map.running
}
CheckBox {
id: colorCB
text: "Enable colors"
}
}
}
NewFileDialog {
id: loadMap
title: "Please choose a Map file"
nameFilters: ["Map files (*.map)"]
fileMode: QLP.FileDialog.OpenFile
onOutputChanged: {
print('Load from >', output)
map.loadMap(output)
}
}
NewFileDialog {
id: saveMap
title: "Please select a folder"
nameFilters: ["Map files (*.map)"]
fileMode: QLP.FileDialog.SaveFile
onOutputChanged: {
print('Save in >', output)
map.saveMap(output)
}
}
}