Now starts the requested time control
[chessclock] / qml / MainPage.qml
1 /**************************************************************************
2
3    Chess Clock
4
5    This file is part of Chess Clock software.
6
7    (This file) Copyright (c) Heli Hyvättinen 2011
8
9    Chess Clock is free software: you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation, either version 3 of the License, or
12    (at your option) any later version.
13
14    Chess Clock is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19
20 **************************************************************************/
21
22
23 import QtQuick 1.1
24 import com.meego 1.0
25 import QtQuick 1.0
26 import com.nokia.extras 1.0
27 import ChessClocks 1.0
28
29
30 Page {
31     id: mainPage
32     tools: commonTools
33     orientationLock: PageOrientation.LockLandscape
34
35
36
37
38
39
40 //    Label {
41 //        id: label
42 //        anchors.centerIn: parent
43 //        text: qsTr("Hello world!")
44 //        visible: false
45 //    }
46
47
48     Image
49     {
50         id: bigLogo
51 //        anchors.fill: parent
52 //        anchors.left: menuList.right
53
54         source: ":/rc/pic/logo.png"
55     }
56
57     ListModel
58     {
59         id: menuModel
60
61         ListElement
62         {
63             name: "Normal clock"
64             timeControl: WrappedClocksWidget.NormalClock
65             askAddition: false
66             askTurnsPerAddition: false
67             logoFile: ":/rc/pic/oldclock.png"
68
69
70         }
71
72         ListElement
73         {
74             name: "Addition before"
75             timeControl: WrappedClocksWidget.AdditionBefore
76             askAddition: true
77             askTurnsPerAddition: true
78             logoFile: ":/rc/pic/addbefore.png"
79         }
80
81         ListElement
82         {
83             name: "Addition after"
84             timeControl: WrappedClocksWidget.AdditionAfter
85             askAddition: true
86             askTurnsPerAddition: true
87             logoFile: ":/rc/pic/addafter.png"
88         }
89
90         ListElement
91         {
92             name: "Delay"
93             timeControl: WrappedClocksWidget.Delay
94             askAddition: true
95             askTurnsPerAddition: false
96             logoFile: ":/rc/pic/pausebefore.png"
97         }
98
99         ListElement
100         {
101             name: "Delay after"
102             timeControl: WrappedClocksWidget.DelayAfter
103             askAddition: true
104             askTurnsPerAddition: false
105             logoFile: ":/rc/pic/pauseafter.png"
106         }
107
108         ListElement
109         {
110             name:"Hour Glass"
111             timeControl: WrappedClocksWidget.HourGlass
112             askAddition: false
113             askTurnsPerAddition: false
114             logoFile:":/rc/pic/hourglass.png"
115         }
116
117     }
118
119
120     ListView
121     {
122         id: menuList
123
124         anchors.left: bigLogo.right
125         anchors.right: parent.right
126         anchors.top: parent.top
127         anchors.bottom: parent.bottom
128
129
130          model: menuModel
131
132          delegate: Row
133          {
134             Image
135             {
136                 source: logoFile
137
138                 MouseArea
139                 {
140                     anchors.fill: parent
141                     onClicked:
142                     {
143                         newGameDialog.name = name
144                         newGameDialog.timeControl = timeControl
145                         newGameDialog.askAddition = askAddition
146                         newGameDialog.askTurnsPerAddition = askTurnsPerAddition
147                         newGameDialog.open()
148                     }
149                 }
150             }
151
152             Text
153             {
154                 text: name
155                 font.pointSize: 40
156                 anchors.topMargin: 12
157                 color: "white"
158
159                 MouseArea
160                 {
161                     anchors.fill: parent
162                     onClicked:
163                     {
164                         newGameDialog.name = name
165                         newGameDialog.timeControl = timeControl
166                         newGameDialog.askAddition = askAddition
167                         newGameDialog.askTurnsPerAddition = askTurnsPerAddition
168                         newGameDialog.open()
169                     }
170                 }
171             }
172
173         }
174     }
175
176
177
178
179
180     Dialog
181     {
182         id:newGameDialog
183
184         property string name
185         property int timeControl //QML does not allow properties to be declared as enums...
186         property bool askAddition
187         property bool askTurnsPerAddition
188
189         onAccepted:
190         {
191             clocksPage.timeControl = timeControl
192             clocksPage.whiteInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
193             clocksPage.blackInitialTime = 60*60*1000*blackInitialTime.hours+60*1000*blackInitialTime.minutes+1000*blackInitialTime.seconds
194             clocksPage.whiteAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
195             clocksPage.blackAdditionalTime = 60*60*1000*blackAdditionalTime.hours+60*1000*blackAdditionalTime.minutes+1000*blackAdditionalTime.seconds
196             clocksPage.whiteTurnsPerAddition = whiteTurnsPerAddition.text
197             clocksPage.blackTurnsPerAddition = blackTurnsPerAddition.text
198             pageStack.push(clocksPage)
199
200         }
201
202         title:Label
203         {
204             color:"white"
205             font.pointSize: 64
206             text: newGameDialog.name
207         }
208
209
210         content:
211             Grid
212             {
213                 columns: 3
214
215                 Row
216                 {
217                     id: rowRow
218                     spacing: 10
219 //                    anchors.top: parent.top
220 //                    anchors.horizontalCenter: parent.horizontalCenter
221
222                     Text
223                     {
224  //                     width: rowRow.width - rowRow.spacing - switchComponent.width - whiteSmall.width - blackSmall.width
225  //                     height: switchComponent.height
226                         verticalAlignment: Text.AlignVCenter
227                         text: "Equal times"
228                         color: "white"
229                         font.pointSize: 26
230                     }
231
232                     Switch
233                     {
234                         id: equalTimesSwitch
235                         onCheckedChanged:
236                         {
237                             if (checked)
238                             {
239                                 blackInitialTime.text = whiteInitialTime.text
240                                 blackAdditionalTime.text = whiteAdditionalTime.text
241                                 blackTurnsPerAddition.text = whiteTurnsPerAddition.text
242
243                             }
244                         }
245                     }
246                 }
247                 Image
248                 {
249                     id: whiteSmall
250                     source: ":/rc/pic/white_small.png"
251                 }
252
253                 Image
254                 {
255                     id: blackSmall
256                     source: ":/rc/pic/black_small.png"
257                 }
258
259                 Text
260                 {
261                     id: initialTimeText
262                     text: "Initial time"
263                     color: "white"
264                     font.pointSize: 26
265 //                    anchors.top: rowRow.bottom
266 //                    anchors.horizontalCenter: parent.horizontalCenter
267 //                    visible: true
268                 }
269
270
271                 TextField
272                 {
273                     id: whiteInitialTime
274                     readOnly: true
275
276                     property int hours
277                     property int minutes
278                     property int seconds
279
280                     text: {hours + " h " + minutes + " min " + seconds + " s"}
281
282                     onTextChanged: {if (equalTimesSwitch.checked) blackInitialTime.text = text}
283
284                     MouseArea
285                     {
286                         anchors.fill: parent
287                         onClicked: {timePicker.timeType = "initial";  timePicker.player = "white"; timePicker.open()}
288                     }
289                 }
290
291
292
293                 TextField
294                 {
295                     id: blackInitialTime
296                     enabled: !equalTimesSwitch.checked
297
298                     readOnly: true
299
300                     property int hours
301                     property int minutes
302                     property int seconds
303
304                     text: hours + " h " + minutes + " min " + seconds + " s"
305
306
307
308                     MouseArea
309                     {
310                     anchors.fill: parent
311                     onClicked: {timePicker.timeType = "initial";  timePicker.player = "black"; timePicker.open()}
312                     }
313                 }
314
315
316
317                 Text
318                 {
319                     id: additionalTimeText
320                     text: "Additional time"
321                     color: "white"
322                     font.pointSize: 26
323                     visible: newGameDialog.askAddition
324 //                    anchors.top: initialTimeText.bottom
325 //                    anchors.horizontalCenter: parent.horizontalCenter
326                 }
327
328
329
330                 TextField
331                 {
332                     id: whiteAdditionalTime
333                     visible:  newGameDialog.askAddition
334                     readOnly: true
335
336                     property int hours
337                     property int minutes
338                     property int seconds
339
340                     text: hours + " h " + minutes + " min " + seconds + " s"
341
342                     onTextChanged: {if (equalTimesSwitch.checked) blackAdditionalTime.text = text}
343
344                     MouseArea
345                     {
346                         anchors.fill: parent
347                         onClicked: {timePicker.timeType = "additional";  timePicker.player = "white"; timePicker.open()}
348                     }
349                 }
350
351                 TextField
352                 {
353                     id: blackAdditionalTime
354                     visible: newGameDialog.askAddition
355                     enabled: !equalTimesSwitch.checked
356                     readOnly: true
357
358                     property int hours
359                     property int minutes
360                     property int seconds
361
362                     text: hours + " h " + minutes + " min " + seconds + " s"
363
364                     MouseArea
365                     {
366                         anchors.fill: parent
367                         onClicked: {timePicker.timeType = "additional";  timePicker.player = "black"; timePicker.open()}
368                     }
369         }
370
371
372
373                 Text
374                 {
375                     text:  "Turns per addition"
376                     color: "white"
377                     font.pointSize: 26
378                     visible: newGameDialog.askTurnsPerAddition
379 //                    anchors.top: additionalTimeText.bottom
380 //                    anchors.horizontalCenter: parent.horizontalCenter
381                 }
382                 TextField
383                 {
384                     id: whiteTurnsPerAddition
385                     visible: newGameDialog.askTurnsPerAddition
386
387                     inputMask: "D00"
388                     text: "1"
389
390                     onTextChanged: {if (equalTimesSwitch.checked) blackTurnsPerAddition.text = text}
391                 }
392
393                 TextField
394                 {
395                     id: blackTurnsPerAddition
396                     visible: newGameDialog.askTurnsPerAddition
397                     enabled: !equalTimesSwitch.checked
398                     inputMask: "D00"
399                     text: "1"
400                 }
401
402
403
404          }
405
406
407         buttons:
408
409             Button
410             {
411                 id: bOk
412                 text: "Start game"
413                 y: 45
414
415                 onClicked: newGameDialog.accept()
416             }
417     }
418
419     TimePickerDialog
420     {
421         id: timePicker
422
423         property string timeType
424         property string player
425
426         titleText: "Choose " + timeType + " time for " + player
427         rejectButtonText: "Cancel"
428         acceptButtonText: "Ok"
429         hourMode: DateTime.TwentyFourHours
430         onAccepted:
431         {
432             if (timeType == "initial")
433                 if (player == "white")
434                 {
435                     whiteInitialTime.hours = hour
436                     whiteInitialTime.minutes = minute
437                     whiteInitialTime.seconds = second
438                 }
439                 else
440                 {
441                     blackInitialTime.hours = hour
442                     blackInitialTime.minutes = minute
443                     blackInitialTime.seconds = second
444                 }
445             else if (player == "white")
446                 {
447                     whiteAdditionalTime.hours = hour
448                     whiteAdditionalTime.minutes = minute
449                     whiteAdditionalTime.seconds = second
450                 }
451                 else
452                 {
453                     blackAdditionalTime.hours = hour
454                     blackAdditionalTime.minutes = minute
455                     blackAdditionalTime.seconds = second
456                 }
457
458         }
459     }
460
461
462
463 }
464
465
466
467