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
202 anchors.top: whiteSmall.bottom
203 anchors.left: whiteTurnsPerAddition.left
205 property int hours: 0
206 property int minutes: 30
207 property int seconds: 0
209 text: {hours + " h " + minutes + " min " + seconds + " s"}
217 timePicker.timeType = "initial"
218 timePicker.player = "white"
219 timePicker.hour = parent.hours
220 timePicker.minute = parent.minutes
221 timePicker.second = parent.seconds
232 visible: !equalTimesSwitch.checked
236 anchors.top: whiteSmall.bottom
237 anchors.left: blackTurnsPerAddition.left
239 property int hours: 0
240 property int minutes: 30
241 property int seconds: 0
243 text: hours + " h " + minutes + " min " + seconds + " s"
251 timePicker.timeType = "initial"
252 timePicker.player = "black"
253 timePicker.hour = parent.hours
254 timePicker.minute = parent.minutes
255 timePicker.second = parent.seconds
265 id: additionalTimeText
267 anchors.verticalCenter: whiteAdditionalTime.verticalCenter
269 text: "Additional time"
272 visible: newGameDialogPage.askAddition
273 // anchors.top: initialTimeText.bottom
274 // anchors.horizontalCenter: parent.horizontalCenter
281 id: whiteAdditionalTime
282 visible: newGameDialogPage.askAddition
285 anchors.top: whiteInitialTime.bottom
286 anchors.topMargin: 15
287 // anchors.left: additionalTimeText.right
288 anchors.left: whiteTurnsPerAddition.left
289 property int hours: 0
290 property int minutes: 0
291 property int seconds: 30
293 text: hours + " h " + minutes + " min " + seconds + " s"
301 timePicker.timeType = "additional"
302 timePicker.player = "white"
303 timePicker.hour = parent.hours
304 timePicker.minute = parent.minutes
305 timePicker.second = parent.seconds
313 id: blackAdditionalTime
314 visible: newGameDialogPage.askAddition && !equalTimesSwitch.checked
317 anchors.top: whiteAdditionalTime.top
318 anchors.left: blackTurnsPerAddition.left
320 property int hours: 0
321 property int minutes: 0
322 property int seconds: 30
324 text: hours + " h " + minutes + " min " + seconds + " s"
331 timePicker.timeType = "additional"
332 timePicker.player = "black"
333 timePicker.hour = parent.hours
334 timePicker.minute = parent.minutes
335 timePicker.second = parent.seconds
345 id: turnsPerAdditionText
346 text: "Turns per addition"
349 visible: newGameDialogPage.askTurnsPerAddition
350 anchors.verticalCenter: whiteTurnsPerAddition.verticalCenter
355 id: whiteTurnsPerAddition
356 visible: newGameDialogPage.askTurnsPerAddition
359 anchors.top: whiteAdditionalTime.bottom
360 anchors.topMargin: 15
361 anchors.left: turnsPerAdditionText.right
362 anchors.leftMargin: 25
369 turnsDialog.player = "white"
371 turnsColumn.selectedIndex = parent.text-1 //Needs to be after open(), or gets overridden by the previous chosen value
381 id: blackTurnsPerAddition
382 visible: newGameDialogPage.askTurnsPerAddition && !equalTimesSwitch.checked
385 anchors.top: whiteTurnsPerAddition.top
386 anchors.left: whiteTurnsPerAddition.right
387 anchors.leftMargin: 25
394 turnsDialog.player = "black"
396 turnsColumn.selectedIndex = parent.text-1 //Needs to be after open(), or gets overridden by the previous chosen value
408 anchors.top: whiteTurnsPerAddition.bottom
409 anchors.topMargin: 15
410 anchors.right: parent.right
416 clocksPage.timeControl = timeControl
419 clocksPage.whiteInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
420 clocksPage.whiteAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
421 clocksPage.whiteTurnsPerAddition = whiteTurnsPerAddition.text
425 //Save settings for white
426 settings.setInitialTime(timeControl,true,whiteInitialTime.hours,whiteInitialTime.minutes,whiteInitialTime.seconds)
427 settings.setAdditionalTime(timeControl,true,whiteAdditionalTime.hours,whiteAdditionalTime.minutes,whiteAdditionalTime.seconds)
428 settings.setTurnsPerAddition(timeControl,true,whiteTurnsPerAddition.text)
430 settings.setEqualTimes(timeControl,equalTimesSwitch.checked) //save equal times setting
432 if (equalTimesSwitch.checked)
434 //use same values for white and black
435 clocksPage.blackInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
436 clocksPage.blackAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
437 clocksPage.blackTurnsPerAddition = whiteTurnsPerAddition.text
439 //If black values in dialog are not used they are not saved to settings
443 clocksPage.blackInitialTime = 60*60*1000*blackInitialTime.hours+60*1000*blackInitialTime.minutes+1000*blackInitialTime.seconds
444 clocksPage.blackAdditionalTime = 60*60*1000*blackAdditionalTime.hours+60*1000*blackAdditionalTime.minutes+1000*blackAdditionalTime.seconds
445 clocksPage.blackTurnsPerAddition = blackTurnsPerAddition.text
447 //Save settings for black
448 settings.setInitialTime(timeControl,false,blackInitialTime.hours,blackInitialTime.minutes,blackInitialTime.seconds)
449 settings.setAdditionalTime(timeControl,false,blackAdditionalTime.hours,blackAdditionalTime.minutes,blackAdditionalTime.seconds)
450 settings.setTurnsPerAddition(timeControl,false,blackTurnsPerAddition.text)
456 pageStack.push(clocksPage)
469 property string timeType
470 property string player
472 titleText: "Choose " + timeType + " time for " + player
473 rejectButtonText: "Cancel"
474 acceptButtonText: "Ok"
475 hourMode: DateTime.TwentyFourHours
478 if (timeType == "initial")
480 if (player == "white")
482 whiteInitialTime.hours = hour
483 whiteInitialTime.minutes = minute
484 whiteInitialTime.seconds = second
488 blackInitialTime.hours = hour
489 blackInitialTime.minutes = minute
490 blackInitialTime.seconds = second
493 else if (player == "white")
495 whiteAdditionalTime.hours = hour
496 whiteAdditionalTime.minutes = minute
497 whiteAdditionalTime.seconds = second
501 blackAdditionalTime.hours = hour
502 blackAdditionalTime.minutes = minute
503 blackAdditionalTime.seconds = second
523 Component.onCompleted:
525 for (var turn = 1; turn <= 99; turn++)
527 turnsList.append({"value" : turn});
539 property string player
541 titleText: "Choose turns per addition for " + player
542 acceptButtonText: "Ok"
543 rejectButtonText: "Cancel"
545 columns: [turnsColumn]
549 if (player == "white")
550 whiteTurnsPerAddition.text = turnsColumn.selectedIndex+1
551 else if (player == "black")
552 blackTurnsPerAddition.text = turnsColumn.selectedIndex+1