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