-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
174 lines (148 loc) · 4.65 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
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.1
import QmlFileIO 1.0
import "Logic.js" as Logic
ApplicationWindow {
title: qsTr("QChess")
width: 600
height: 600
visible: true
QmlFileIO {
id: fio
}
toolBar: ToolBar {
RowLayout {
anchors.centerIn: parent
ToolButton {
id: bStart
text: qsTr("Start")
visible: true
onClicked: {
body.state = "PLAY"
Logic.game.initialPosition()
}
}
ToolButton {
id: bLoad
text: qsTr("Load")
visible: true
onClicked: {
fileDialog.load = true
fileDialog.title = "Load saved game."
fileDialog.selectExisting = true
fileDialog.open()
body.state = "LOAD"
}
}
ToolButton {
id: bStop
text: qsTr("Stop")
visible: false
onClicked: {
body.state = "INITIAL"
}
}
ToolButton {
id: bSave
text: qsTr("Save")
visible: false
onClicked: {
fileDialog.load = false
fileDialog.title = "Save game as."
fileDialog.selectExisting = false
fileDialog.open()
}
}
ToolButton {
id: bPrev
text: qsTr("Prev")
visible: false
onClicked: {
Logic.game.histPrev()
}
}
ToolButton {
id: bNext
text: qsTr("Next")
visible: false
onClicked: {
Logic.game.histNext()
}
}
}
}
Item {
id: body
visible: true
anchors.fill: parent
state: "INITIAL"
property int blockSizeX: { return Math.floor(body.width/8.0) }
property int blockSizeY: { return Math.floor(body.height/8.0) }
Image{
source: "images/board/simple.svg"
anchors.fill: parent
visible: true
}
states: [
State {
name: "INITIAL"
PropertyChanges { target: bStart; visible: true }
PropertyChanges { target: bLoad; visible: true }
PropertyChanges { target: bStop; visible: false }
PropertyChanges { target: bSave; visible: false }
PropertyChanges { target: bPrev; visible: false }
PropertyChanges { target: bNext; visible: false }
},
State {
name: "PLAY"
PropertyChanges { target: bStart; visible: false }
PropertyChanges { target: bLoad; visible: false }
PropertyChanges { target: bStop; visible: true }
PropertyChanges { target: bSave; visible: true }
PropertyChanges { target: bPrev; visible: false }
PropertyChanges { target: bNext; visible: false }
},
State {
name: "LOAD"
PropertyChanges { target: bStart; visible: true }
PropertyChanges { target: bLoad; visible: true }
PropertyChanges { target: bStop; visible: false }
PropertyChanges { target: bSave; visible: false }
PropertyChanges { target: bPrev; visible: true }
PropertyChanges { target: bNext; visible: true }
}
]
MouseArea {
anchors.fill: parent
onClicked: {
if (body.state == "PLAY") {
Logic.game.clicked(mouse)
}
}
}
}
FileDialog {
id: fileDialog
visible: false
modality: Qt.WindowModal
title: "Save game as!"
selectExisting: true
selectMultiple: false
selectFolder: false
sidebarVisible: true
nameFilters: [ "*.qchess *.*" ]
selectedNameFilter: ""
property bool load: false
onAccepted: {
var path = fileUrl.toString().split("://")
if (load == true) {
Logic.game.loadGame(path[1])
} else {
Logic.game.saveGame(path[1])
}
}
}
}