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