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