1 /**************************************************************************
5 This file is part of Chess Clock software.
7 (This file) Copyright (c) Heli Hyvättinen 2011
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.
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.
20 **************************************************************************/
26 import com.nokia.extras 1.0
27 import ChessClocks 1.0
34 orientationLock: PageOrientation.LockLandscape
38 //QML does not allow properties to be declared as enums...
39 //Initializing to invalid value to make sure picking *any* time control will trigger OnTimeControlChanged
40 property int timeControl: 1000
43 property bool askAddition
44 property bool askTurnsPerAddition
55 equalTimesSwitch.checked = settings.isEqualTimes(timeControl)
57 var whiteInitial = settings.getInitialTime(timeControl,true)
58 whiteInitialTime.hours = Qt.formatTime(whiteInitial,"h")
59 whiteInitialTime.minutes = Qt.formatTime(whiteInitial,"m")
60 whiteInitialTime.seconds = Qt.formatTime(whiteInitial,"s")
62 var blackInitial = settings.getInitialTime(timeControl,false)
63 blackInitialTime.hours = Qt.formatTime(blackInitial,"h")
64 blackInitialTime.minutes = Qt.formatTime(blackInitial,"m")
65 blackInitialTime.seconds = Qt.formatTime(blackInitial,"s")
67 var whiteAdditional = settings.getAdditionalTime(timeControl,true)
68 whiteAdditionalTime.hours = Qt.formatTime(whiteAdditional,"h")
69 whiteAdditionalTime.minutes = Qt.formatTime(whiteAdditional,"m")
70 whiteAdditionalTime.seconds = Qt.formatTime(whiteAdditional,"s")
72 var blackAdditional = settings.getAdditionalTime(timeControl,false)
73 blackAdditionalTime.hours = Qt.formatTime(blackAdditional,"h")
74 blackAdditionalTime.minutes = Qt.formatTime(blackAdditional,"m")
75 blackAdditionalTime.seconds = Qt.formatTime(blackAdditional,"s")
78 whiteTurnsPerAddition.text = settings.getTurnsPerAddition(timeControl,true)
79 blackTurnsPerAddition.text = settings.getTurnsPerAddition(timeControl,false)
84 ToolIcon { iconId: "toolbar-back"; onClicked: pageStack.pop() }
93 anchors.horizontalCenter: parent.horizontalCenter
97 text: newGameDialogPage.name
105 anchors.top: title.bottom
109 // width: rowRow.width - rowRow.spacing - switchComponent.width - whiteSmall.width - blackSmall.width
110 // height: switchComponent.height
111 verticalAlignment: Text.AlignVCenter
124 whiteSmall.anchors.horizontalCenter = undefined
125 whiteSmall.anchors.right = whiteInitialTime.horizontalCenter
127 blackSmall.anchors.horizontalCenter = undefined
128 blackSmall.anchors.left = whiteInitialTime.horizontalCenter
136 whiteSmall.anchors.right = undefined
137 whiteSmall.anchors.horizontalCenter = whiteInitialTime.horizontalCenter
139 blackSmall.anchors.left = undefined
140 blackSmall.anchors.horizontalCenter = blackInitialTime.horizontalCenter
155 anchors.top: rowRow.bottom
157 source: ":/rc/pic/white_small.png"
159 Component.onCompleted:
161 if (equalTimesSwitch.checked)
162 anchors.right = whiteInitialTime.horizontalCenter
164 anchors.horizontalCenter = whiteInitialTime.horizontalCenter
173 anchors.top: rowRow.bottom
176 source: ":/rc/pic/black_small.png"
178 Component.onCompleted:
180 if (equalTimesSwitch.checked)
181 anchors.left = whiteInitialTime.horizontalCenter
183 anchors.horizontalCenter = blackInitialTime.horizontalCenter
193 anchors.verticalCenter: whiteInitialTime.verticalCenter
201 anchors.top: whiteSmall.bottom
202 anchors.left: whiteTurnsPerAddition.left
203 anchors.right: whiteTurnsPerAddition.right
205 property int hours: 0
206 property int minutes: 30
207 property int seconds: 0
209 text: {hours + " h " + minutes + " min " + seconds + " s"}
215 timePicker.timeType = "initial"
216 timePicker.player = "white"
217 timePicker.hour = hours
218 timePicker.minute = minutes
219 timePicker.second = seconds
230 visible: !equalTimesSwitch.checked
232 anchors.top: whiteSmall.bottom
233 anchors.left: blackTurnsPerAddition.left
234 anchors.right: blackTurnsPerAddition.right
236 property int hours: 0
237 property int minutes: 30
238 property int seconds: 0
240 text: hours + " h " + minutes + " min " + seconds + " s"
246 timePicker.timeType = "initial"
247 timePicker.player = "black"
248 timePicker.hour = hours
249 timePicker.minute = minutes
250 timePicker.second = seconds
260 id: additionalTimeText
262 anchors.verticalCenter: whiteAdditionalTime.verticalCenter
264 text: "Additional time"
267 visible: newGameDialogPage.askAddition
268 // anchors.top: initialTimeText.bottom
269 // anchors.horizontalCenter: parent.horizontalCenter
276 id: whiteAdditionalTime
277 visible: newGameDialogPage.askAddition
280 anchors.top: whiteInitialTime.bottom
281 anchors.topMargin: 15
282 // anchors.left: additionalTimeText.right
283 anchors.left: whiteTurnsPerAddition.left
284 property int hours: 0
285 property int minutes: 0
286 property int seconds: 30
288 text: hours + " h " + minutes + " min " + seconds + " s"
296 timePicker.timeType = "additional"
297 timePicker.player = "white"
298 timePicker.hour = parent.hours
299 timePicker.minute = parent.minutes
300 timePicker.second = parent.seconds
308 id: blackAdditionalTime
309 visible: newGameDialogPage.askAddition && !equalTimesSwitch.checked
312 anchors.top: whiteAdditionalTime.top
313 anchors.left: blackTurnsPerAddition.left
315 property int hours: 0
316 property int minutes: 0
317 property int seconds: 30
319 text: hours + " h " + minutes + " min " + seconds + " s"
326 timePicker.timeType = "additional"
327 timePicker.player = "black"
328 timePicker.hour = parent.hours
329 timePicker.minute = parent.minutes
330 timePicker.second = parent.seconds
340 id: turnsPerAdditionText
341 text: "Turns per addition"
344 visible: newGameDialogPage.askTurnsPerAddition
345 anchors.verticalCenter: whiteTurnsPerAddition.verticalCenter
350 id: whiteTurnsPerAddition
351 visible: newGameDialogPage.askTurnsPerAddition
354 anchors.top: whiteAdditionalTime.bottom
355 anchors.topMargin: 15
356 anchors.left: turnsPerAdditionText.right
357 anchors.leftMargin: 25
364 turnsDialog.player = "white"
366 turnsColumn.selectedIndex = parent.text-1 //Needs to be after open(), or gets overridden by the previous chosen value
376 id: blackTurnsPerAddition
377 visible: newGameDialogPage.askTurnsPerAddition && !equalTimesSwitch.checked
380 anchors.top: whiteTurnsPerAddition.top
381 anchors.left: whiteTurnsPerAddition.right
382 anchors.leftMargin: 25
389 turnsDialog.player = "black"
391 turnsColumn.selectedIndex = parent.text-1 //Needs to be after open(), or gets overridden by the previous chosen value
403 anchors.top: whiteTurnsPerAddition.bottom
404 anchors.topMargin: 15
405 anchors.right: parent.right
411 clocksPage.timeControl = timeControl
414 clocksPage.whiteInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
415 clocksPage.whiteAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
416 clocksPage.whiteTurnsPerAddition = whiteTurnsPerAddition.text
420 //Save settings for white
421 settings.setInitialTime(timeControl,true,whiteInitialTime.hours,whiteInitialTime.minutes,whiteInitialTime.seconds)
422 settings.setAdditionalTime(timeControl,true,whiteAdditionalTime.hours,whiteAdditionalTime.minutes,whiteAdditionalTime.seconds)
423 settings.setTurnsPerAddition(timeControl,true,whiteTurnsPerAddition.text)
425 settings.setEqualTimes(timeControl,equalTimesSwitch.checked) //save equal times setting
427 if (equalTimesSwitch.checked)
429 //use same values for white and black
430 clocksPage.blackInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
431 clocksPage.blackAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
432 clocksPage.blackTurnsPerAddition = whiteTurnsPerAddition.text
434 //If black values in dialog are not used they are not saved to settings
438 clocksPage.blackInitialTime = 60*60*1000*blackInitialTime.hours+60*1000*blackInitialTime.minutes+1000*blackInitialTime.seconds
439 clocksPage.blackAdditionalTime = 60*60*1000*blackAdditionalTime.hours+60*1000*blackAdditionalTime.minutes+1000*blackAdditionalTime.seconds
440 clocksPage.blackTurnsPerAddition = blackTurnsPerAddition.text
442 //Save settings for black
443 settings.setInitialTime(timeControl,false,blackInitialTime.hours,blackInitialTime.minutes,blackInitialTime.seconds)
444 settings.setAdditionalTime(timeControl,false,blackAdditionalTime.hours,blackAdditionalTime.minutes,blackAdditionalTime.seconds)
445 settings.setTurnsPerAddition(timeControl,false,blackTurnsPerAddition.text)
451 pageStack.push(clocksPage)
464 property string timeType
465 property string player
467 titleText: "Choose " + timeType + " time for " + player
468 rejectButtonText: "Cancel"
469 acceptButtonText: "Ok"
470 hourMode: DateTime.TwentyFourHours
473 if (timeType == "initial")
475 if (player == "white")
477 whiteInitialTime.hours = hour
478 whiteInitialTime.minutes = minute
479 whiteInitialTime.seconds = second
483 blackInitialTime.hours = hour
484 blackInitialTime.minutes = minute
485 blackInitialTime.seconds = second
488 else if (player == "white")
490 whiteAdditionalTime.hours = hour
491 whiteAdditionalTime.minutes = minute
492 whiteAdditionalTime.seconds = second
496 blackAdditionalTime.hours = hour
497 blackAdditionalTime.minutes = minute
498 blackAdditionalTime.seconds = second
518 Component.onCompleted:
520 for (var turn = 1; turn <= 99; turn++)
522 turnsList.append({"value" : turn});
534 property string player
536 titleText: "Choose turns per addition for " + player
537 acceptButtonText: "Ok"
538 rejectButtonText: "Cancel"
540 columns: [turnsColumn]
544 if (player == "white")
545 whiteTurnsPerAddition.text = turnsColumn.selectedIndex+1
546 else if (player == "black")
547 blackTurnsPerAddition.text = turnsColumn.selectedIndex+1