b7f7516b6001fcae52dbf2fad9464d8f17d37a6b
[chessclock] / qml / MainPage.qml
1 import QtQuick 1.1
2 import com.meego 1.0
3 import QtQuick 1.0
4 import com.nokia.extras 1.0
5
6
7 Page {
8     id: mainPage
9     tools: commonTools
10
11
12
13
14
15
16 //    Label {
17 //        id: label
18 //        anchors.centerIn: parent
19 //        text: qsTr("Hello world!")
20 //        visible: false
21 //    }
22
23
24     Image
25     {
26         id: bigLogo
27 //        anchors.fill: parent
28 //        anchors.left: menuList.right
29
30         source: ":/rc/pic/logo.png"
31     }
32
33     ListModel
34     {
35         id: menuModel
36
37         ListElement
38         {
39             name: "Normal clock"
40             askAddition: false
41             logoFile: ":/rc/pic/oldclock.png"
42
43
44         }
45
46         ListElement
47         {
48             name: "Addition before"
49             askAddition: true
50             logoFile: ":/rc/pic/addbefore.png"
51         }
52
53         ListElement
54         {
55             name: "Addition after"
56             askAddition: true
57             logoFile: ":/rc/pic/addafter.png"
58         }
59
60         ListElement
61         {
62             name: "Delay"
63             askAddition: true
64             logoFile: ":/rc/pic/pausebefore.png"
65         }
66
67         ListElement
68         {
69             name: "Delay after"
70             askAddition: true
71             logoFile: ":/rc/pic/pauseafter.png"
72         }
73
74         ListElement
75         {
76             name:"Hour Glass"
77             askAddition: false
78             logoFile:":/rc/pic/hourglass.png"
79         }
80
81     }
82
83
84     ListView
85     {
86         id: menuList
87
88         anchors.left: bigLogo.right
89         anchors.right: parent.right
90         anchors.top: parent.top
91         anchors.bottom: parent.bottom
92
93
94          model: menuModel
95
96          delegate: Row
97          {
98             Image
99             {
100                 source: logoFile
101
102                 MouseArea
103                 {
104                     anchors.fill: parent
105                     onClicked: {newGameDialog.name = name; newGameDialog.askAddition = askAddition; newGameDialog.open()}
106                 }
107             }
108
109             Text
110             {
111                 text: name
112                 font.pointSize: 40
113                 anchors.topMargin: 12
114                 color: "white"
115
116                 MouseArea
117                 {
118                     anchors.fill: parent
119                     onClicked: {newGameDialog.name = name; newGameDialog.askAddition = askAddition; newGameDialog.open()}
120                 }
121             }
122
123         }
124     }
125
126
127
128
129
130     Dialog
131     {
132         id:newGameDialog
133
134         property string name
135         property bool askAddition
136
137
138
139         title:Label
140         {
141             color:"white"
142             font.pointSize: 64
143             text: newGameDialog.name
144         }
145
146
147         content:
148             Grid
149             {
150                 columns: 3
151
152                 Row
153                 {
154                     id: rowRow
155                     spacing: 10
156 //                    anchors.top: parent.top
157 //                    anchors.horizontalCenter: parent.horizontalCenter
158
159                     Text
160                     {
161  //                     width: rowRow.width - rowRow.spacing - switchComponent.width - whiteSmall.width - blackSmall.width
162  //                     height: switchComponent.height
163                         verticalAlignment: Text.AlignVCenter
164                         text: "Equal times"
165                         color: "white"
166                         font.pointSize: 26
167                     }
168
169                     Switch
170                     {
171                         id: equalTimesSwitch
172                         onCheckedChanged:
173                         {
174                             if (checked)
175                             {
176                                 blackInitialTime.text = whiteInitialTime.text
177                                 blackAdditionalTime.text = whiteAdditionalTime.text
178                                 blackTurnsPerAddition.text = whiteTurnsPerAddition.text
179
180                             }
181                         }
182                     }
183                 }
184                 Image
185                 {
186                     id: whiteSmall
187                     source: ":/rc/pic/white_small.png"
188                 }
189
190                 Image
191                 {
192                     id: blackSmall
193                     source: ":/rc/pic/black_small.png"
194                 }
195
196                 Text
197                 {
198                     id: initialTimeText
199                     text: "Initial time"
200                     color: "white"
201                     font.pointSize: 26
202 //                    anchors.top: rowRow.bottom
203 //                    anchors.horizontalCenter: parent.horizontalCenter
204 //                    visible: true
205                 }
206
207
208                 TextField
209                 {
210                     id: whiteInitialTime
211                     readOnly: true
212
213                     onTextChanged: {if (equalTimesSwitch.checked) blackInitialTime.text = text}
214
215                     MouseArea
216                     {
217                         anchors.fill: parent
218                         onClicked: {timePicker.timeType = "initial";  timePicker.player = "white"; timePicker.open()}
219                     }
220                 }
221
222
223
224                 TextField
225                 {
226                     id: blackInitialTime
227                     enabled: !equalTimesSwitch.checked
228
229                     readOnly: true
230
231
232
233                     MouseArea
234                     {
235                     anchors.fill: parent
236                     onClicked: {timePicker.timeType = "initial";  timePicker.player = "black"; timePicker.open()}
237                     }
238                 }
239
240
241
242                 Text
243                 {
244                     id: additionalTimeText
245                     text: "Additional time"
246                     color: "white"
247                     font.pointSize: 26
248                     visible: newGameDialog.askAddition
249 //                    anchors.top: initialTimeText.bottom
250 //                    anchors.horizontalCenter: parent.horizontalCenter
251                 }
252
253
254
255                 TextField
256                 {
257                     id: whiteAdditionalTime
258                     visible:  newGameDialog.askAddition
259                     readOnly: true
260
261                     onTextChanged: {if (equalTimesSwitch.checked) blackAdditionalTime.text = text}
262
263                     MouseArea
264                     {
265                         anchors.fill: parent
266                         onClicked: {timePicker.timeType = "additional";  timePicker.player = "white"; timePicker.open()}
267                     }
268                 }
269
270                 TextField
271                 {
272                     id: blackAdditionalTime
273                     visible: newGameDialog.askAddition
274                     enabled: !equalTimesSwitch.checked
275                     readOnly: true
276
277                     MouseArea
278                     {
279                         anchors.fill: parent
280                         onClicked: {timePicker.timeType = "additional";  timePicker.player = "black"; timePicker.open()}
281                     }
282         }
283
284
285
286                 Text
287                 {
288                     text:  "Turns per addition"
289                     color: "white"
290                     font.pointSize: 26
291                     visible: newGameDialog.askAddition
292 //                    anchors.top: additionalTimeText.bottom
293 //                    anchors.horizontalCenter: parent.horizontalCenter
294                 }
295                 TextField
296                 {
297                     id: whiteTurnsPerAddition
298                     visible: newGameDialog.askAddition
299
300                     inputMask: "D00"
301                     text: "1"
302
303                     onTextChanged: {if (equalTimesSwitch.checked) blackTurnsPerAddition.text = text}
304                 }
305
306                 TextField
307                 {
308                     id: blackTurnsPerAddition
309                     visible: newGameDialog.askAddition
310                     enabled: !equalTimesSwitch.checked
311                     inputMask: "D00"
312                     text: "1"
313                 }
314
315
316
317          }
318
319
320         buttons:
321
322             Button
323             {
324                 id: bOk
325                 text: "Start game"
326                 y: 45
327
328                 onClicked: newGameDialog.accept()
329             }
330     }
331
332     TimePickerDialog
333     {
334         id: timePicker
335
336         property string timeType
337         property string player
338         property string result
339
340
341         titleText: "Choose " + timeType + " time for " + player
342         rejectButtonText: "Cancel"
343         acceptButtonText: "Ok"
344         hourMode: DateTime.TwentyFourHours
345         onAccepted:
346         {
347             result = hour + " h " + minute + " min " + second + " s"
348             if (timeType == "initial")
349                 if (player == "white")
350                     whiteInitialTime.text = result
351                 else
352                     blackInitialTime.text = result
353
354             else if (player == "white")
355                     whiteAdditionalTime.text = result
356                 else
357                     blackAdditionalTime.text = result
358
359         }
360     }
361 }
362
363
364
365