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