490b136d36b3f3dd701e50192e884a10adbd0bbf
[chessclock] / qml / NewGameDialogPage.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 {
32     id: newGameDialogPage
33
34     orientationLock: PageOrientation.LockLandscape
35
36     property string name
37     property int timeControl //QML does not allow properties to be declared as enums...
38     property bool askAddition
39     property bool askTurnsPerAddition
40
41     tools: ToolBarLayout
42     {
43         ToolButton { iconSource: "toolbar-back"; onClicked: pageStack.pop() }
44     }
45
46
47
48            Label
49             {
50                 id: title
51
52                 color:"white"
53                 font.pointSize: 64
54                 text: newGameDialogPage.name
55             }
56
57             Row
58             {
59                 id: rowRow
60                 spacing: 10
61
62                 anchors.top: title.bottom
63
64                 Text
65                 {
66 //                     width: rowRow.width - rowRow.spacing - switchComponent.width - whiteSmall.width - blackSmall.width
67 //                     height: switchComponent.height
68                     verticalAlignment: Text.AlignVCenter
69                     text: "Equal times"
70                     color: "white"
71                     font.pointSize: 26
72                 }
73
74                 Switch
75                 {
76                     id: equalTimesSwitch
77                     onCheckedChanged:
78                     {
79                         if (checked)
80                         {
81                             whiteSmall.anchors.horizontalCenter = undefined
82                             whiteSmall.anchors.right = whiteInitialTime.horizontalCenter
83
84                             blackSmall.anchors.horizontalCenter = undefined
85                             blackSmall.anchors.left = whiteInitialTime.horizontalCenter
86
87
88                         }
89
90                         else
91                         {
92
93                             whiteSmall.anchors.right = undefined
94                             whiteSmall.anchors.horizontalCenter = whiteInitialTime.horizontalCenter
95
96                             blackSmall.anchors.left = undefined
97                             blackSmall.anchors.horizontalCenter = blackInitialTime.horizontalCenter
98
99                         }
100
101                     }
102                 }
103             }
104
105
106
107
108             Image
109             {
110                 id: whiteSmall
111
112                 anchors.top: rowRow.bottom
113
114                 source: ":/rc/pic/white_small.png"
115
116                 Component.onCompleted:
117                 {
118                     if (equalTimesSwitch.checked)
119                         anchors.right = whiteInitialTime.horizontalCenter
120                     else
121                         anchors.horizontalCenter = whiteInitialTime.horizontalCenter
122                 }
123             }
124
125             Image
126             {
127
128                 id: blackSmall
129
130                 anchors.top: rowRow.bottom
131
132
133                 source: ":/rc/pic/black_small.png"
134
135                 Component.onCompleted:
136                 {
137                     if (equalTimesSwitch.checked)
138                         anchors.left = whiteInitialTime.horizontalCenter
139                     else
140                         anchors.horizontalCenter = blackInitialTime.horizontalCenter
141                 }
142             }
143
144             Text
145             {
146                 id: initialTimeText
147                 text: "Initial time"
148                 color: "white"
149                 font.pointSize: 26
150                 anchors.top: whiteSmall.bottom
151               }
152
153
154             TextField
155             {
156                 id: whiteInitialTime
157                 readOnly: true
158
159                 anchors.top: whiteSmall.bottom
160                 anchors.left: initialTimeText.right
161
162                 property int hours
163                 property int minutes
164                 property int seconds
165
166                 text: {hours + " h " + minutes + " min " + seconds + " s"}
167
168
169                 MouseArea
170                 {
171                     anchors.fill: parent
172                     onClicked: {timePicker.timeType = "initial";  timePicker.player = "white"; timePicker.open()}
173                 }
174             }
175
176
177
178             TextField
179             {
180                 id: blackInitialTime
181                 visible: !equalTimesSwitch.checked
182
183                 readOnly: true
184
185                 anchors.top: whiteSmall.bottom
186                 anchors.left:  whiteInitialTime.right
187
188                 property int hours
189                 property int minutes
190                 property int seconds
191
192                 text: hours + " h " + minutes + " min " + seconds + " s"
193
194
195
196                 MouseArea
197                 {
198                 anchors.fill: parent
199                 onClicked: {timePicker.timeType = "initial";  timePicker.player = "black"; timePicker.open()}
200                 }
201             }
202
203
204
205             Text
206             {
207                 id: additionalTimeText
208
209                 anchors.top: whiteInitialTime.bottom
210
211                 text: "Additional time"
212                 color: "white"
213                 font.pointSize: 26
214                 visible: newGameDialogPage.askAddition
215 //                    anchors.top: initialTimeText.bottom
216 //                    anchors.horizontalCenter: parent.horizontalCenter
217             }
218
219
220
221             TextField
222             {
223                 id: whiteAdditionalTime
224                 visible:  newGameDialogPage.askAddition
225                 readOnly: true
226
227                 anchors.top: whiteInitialTime.bottom
228                 anchors.left: additionalTimeText.right
229
230                 property int hours
231                 property int minutes
232                 property int seconds
233
234                 text: hours + " h " + minutes + " min " + seconds + " s"
235
236
237                 MouseArea
238                 {
239                     anchors.fill: parent
240                     onClicked: {timePicker.timeType = "additional";  timePicker.player = "white"; timePicker.open()}
241                 }
242             }
243
244             TextField
245             {
246                 id: blackAdditionalTime
247                 visible: newGameDialogPage.askAddition && !equalTimesSwitch.checked
248                 readOnly: true
249
250                 anchors.top: whiteInitialTime.bottom
251                 anchors.left: whiteAdditionalTime.right
252
253                 property int hours
254                 property int minutes
255                 property int seconds
256
257                 text: hours + " h " + minutes + " min " + seconds + " s"
258
259                 MouseArea
260                 {
261                     anchors.fill: parent
262                     onClicked: {timePicker.timeType = "additional";  timePicker.player = "black"; timePicker.open()}
263                 }
264
265
266             }
267
268             Text
269             {
270                 id: turnsPerAdditionText
271                 text:  "Turns per addition"
272                 color: "white"
273                 font.pointSize: 26
274                 visible: newGameDialogPage.askTurnsPerAddition
275                 anchors.top: whiteAdditionalTime.bottom
276             }
277
278             TextField
279             {
280                 id: whiteTurnsPerAddition
281                 visible: newGameDialogPage.askTurnsPerAddition
282                 readOnly: true;
283
284                 anchors.top: whiteAdditionalTime.bottom
285                 anchors.left: turnsPerAdditionText.right
286
287                 text: "1"
288
289                 MouseArea
290                 {
291                     anchors.fill: parent
292                     onClicked: {turnsDialog.player = "white";  turnsDialog.open()}
293                 }
294
295             }
296
297             TextField
298             {
299                 id: blackTurnsPerAddition
300                 visible: newGameDialogPage.askTurnsPerAddition && !equalTimesSwitch.checked
301                 readOnly: true;
302
303                 anchors.top: whiteAdditionalTime.bottom
304                 anchors.left: whiteTurnsPerAddition.right
305
306                 text: "1"
307
308                 MouseArea
309                 {
310                     anchors.fill: parent
311                     onClicked: {turnsDialog.player = "black";  turnsDialog.open()}
312                 }
313
314             }
315
316
317             Button
318             {
319                 id: okButton
320                 text:  "Start game"
321
322                 anchors.top: whiteTurnsPerAddition.bottom
323                 anchors.right: parent.right
324
325                 onClicked:
326                 {
327                 clocksPage.timeControl = timeControl
328
329                 clocksPage.whiteInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
330                 clocksPage.whiteAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
331                 clocksPage.whiteTurnsPerAddition = whiteTurnsPerAddition.text
332
333                 if (equalTimesSwitch.checked)
334                 {
335                     clocksPage.blackInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
336                     clocksPage.blackAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
337                     clocksPage.blackTurnsPerAddition = whiteTurnsPerAddition.text
338
339                 }
340                 else
341                 {
342                     clocksPage.blackInitialTime = 60*60*1000*blackInitialTime.hours+60*1000*blackInitialTime.minutes+1000*blackInitialTime.seconds
343                     clocksPage.blackAdditionalTime = 60*60*1000*blackAdditionalTime.hours+60*1000*blackAdditionalTime.minutes+1000*blackAdditionalTime.seconds
344                     clocksPage.blackTurnsPerAddition = blackTurnsPerAddition.text
345                 }
346
347                 pageStack.push(clocksPage)
348
349             }
350
351             }
352
353
354
355
356 TimePickerDialog
357 {
358     id: timePicker
359
360     property string timeType
361     property string player
362
363     titleText: "Choose " + timeType + " time for " + player
364     rejectButtonText: "Cancel"
365     acceptButtonText: "Ok"
366     hourMode: DateTime.TwentyFourHours
367     onAccepted:
368     {
369         if (timeType == "initial")
370         {
371             if (player == "white")
372             {
373                 whiteInitialTime.hours = hour
374                 whiteInitialTime.minutes = minute
375                 whiteInitialTime.seconds = second
376             }
377             else
378             {
379                 blackInitialTime.hours = hour
380                 blackInitialTime.minutes = minute
381                 blackInitialTime.seconds = second
382             }
383         }
384         else if (player == "white")
385             {
386                 whiteAdditionalTime.hours = hour
387                 whiteAdditionalTime.minutes = minute
388                 whiteAdditionalTime.seconds = second
389             }
390             else
391             {
392                 blackAdditionalTime.hours = hour
393                 blackAdditionalTime.minutes = minute
394                 blackAdditionalTime.seconds = second
395             }
396
397     }
398 }
399
400
401
402 TumblerColumn
403 {
404     id: turnsColumn
405     selectedIndex: 1
406     items: turnsList
407
408
409 }
410
411 ListModel
412 {
413     id: turnsList
414
415     Component.onCompleted:
416     {
417         for (var turn = 1; turn <= 99; turn++)
418               {
419                  turnsList.append({"value" : turn});
420               }
421
422     }
423
424 }
425
426
427 TumblerDialog
428 {
429     id: turnsDialog
430
431     property string player
432
433     titleText: "Choose turns per addition for " + player
434     acceptButtonText: "Ok"
435     rejectButtonText: "Cancel"
436
437     columns: [turnsColumn]
438
439     onAccepted:
440     {
441         if (player == "white")
442             whiteTurnsPerAddition.text = turnsColumn.selectedIndex+1
443         else if (player == "black")
444             blackTurnsPerAddition.text = turnsColumn.selectedIndex+1
445
446
447     }
448 }
449
450 }