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
37 property int timeControl //QML does not allow properties to be declared as enums...
38 property bool askAddition
39 property bool askTurnsPerAddition
47 Component.onCompleted:
49 equalTimesSwitch = settings.isEqualTimes(timeControl)
51 var whiteInitial = settings.getInitialTime(timeControl,true)
52 whiteInitialTime.hours = whiteInitial/360
53 whiteInitialTime.minutes = (whiteIntial%360)/60
54 whiteInitialTime.seconds = whiteInitial%60
56 var blackInitial = settings.getInitialTime(timeControl,false)
57 blackInitialTime.hours = blackInitial/360
58 blackInitialTime.minutes = (blackInitial%360)/60
59 blackInitialTime.seconds = blackInitial%60
61 var whiteAdditional = settings.getAdditionalTime(timeControl,true)
62 whiteAdditionalTime.hours = whiteAdditional/360
63 whiteAdditionalTime.minutes = (whiteAdditional%360)/60
64 whiteAdditionalTime.seconds = whiteAdditional%60
66 var blackAdditional = settings.getAdditionalTime(timeControl,false)
67 blackAdditionalTime.hours = blackAdditional/360
68 blackAdditionalTime.minutes = (blackAdditional%360)/60
69 blackAdditionalTime.seconds = blackAdditional%60
71 whiteTurnsPerAddition.text = settings.getTurnsPerAddition(timeControl,true)
72 blackTurnsPerAddition.text = settings.getTurnsPerAddition(timeControl,false)
77 ToolIcon { iconId: "toolbar-back"; onClicked: pageStack.pop() }
86 anchors.horizontalCenter: parent.horizontalCenter
90 text: newGameDialogPage.name
98 anchors.top: title.bottom
102 // width: rowRow.width - rowRow.spacing - switchComponent.width - whiteSmall.width - blackSmall.width
103 // height: switchComponent.height
104 verticalAlignment: Text.AlignVCenter
117 whiteSmall.anchors.horizontalCenter = undefined
118 whiteSmall.anchors.right = whiteInitialTime.horizontalCenter
120 blackSmall.anchors.horizontalCenter = undefined
121 blackSmall.anchors.left = whiteInitialTime.horizontalCenter
129 whiteSmall.anchors.right = undefined
130 whiteSmall.anchors.horizontalCenter = whiteInitialTime.horizontalCenter
132 blackSmall.anchors.left = undefined
133 blackSmall.anchors.horizontalCenter = blackInitialTime.horizontalCenter
148 anchors.top: rowRow.bottom
150 source: ":/rc/pic/white_small.png"
152 Component.onCompleted:
154 if (equalTimesSwitch.checked)
155 anchors.right = whiteInitialTime.horizontalCenter
157 anchors.horizontalCenter = whiteInitialTime.horizontalCenter
166 anchors.top: rowRow.bottom
169 source: ":/rc/pic/black_small.png"
171 Component.onCompleted:
173 if (equalTimesSwitch.checked)
174 anchors.left = whiteInitialTime.horizontalCenter
176 anchors.horizontalCenter = blackInitialTime.horizontalCenter
186 anchors.verticalCenter: whiteInitialTime.verticalCenter
195 anchors.top: whiteSmall.bottom
196 anchors.left: whiteTurnsPerAddition.left
202 text: {hours + " h " + minutes + " min " + seconds + " s"}
208 onClicked: {timePicker.timeType = "initial"; timePicker.player = "white"; timePicker.open()}
217 visible: !equalTimesSwitch.checked
221 anchors.top: whiteSmall.bottom
222 anchors.left: blackTurnsPerAddition.left
228 text: hours + " h " + minutes + " min " + seconds + " s"
234 onClicked: {timePicker.timeType = "initial"; timePicker.player = "black"; timePicker.open()}
242 id: additionalTimeText
244 anchors.verticalCenter: whiteAdditionalTime.verticalCenter
246 text: "Additional time"
249 visible: newGameDialogPage.askAddition
250 // anchors.top: initialTimeText.bottom
251 // anchors.horizontalCenter: parent.horizontalCenter
258 id: whiteAdditionalTime
259 visible: newGameDialogPage.askAddition
262 anchors.top: whiteInitialTime.bottom
263 anchors.topMargin: 15
264 // anchors.left: additionalTimeText.right
265 anchors.left: whiteTurnsPerAddition.left
270 text: hours + " h " + minutes + " min " + seconds + " s"
276 onClicked: {timePicker.timeType = "additional"; timePicker.player = "white"; timePicker.open()}
282 id: blackAdditionalTime
283 visible: newGameDialogPage.askAddition && !equalTimesSwitch.checked
286 anchors.top: whiteAdditionalTime.top
287 anchors.left: blackTurnsPerAddition.left
293 text: hours + " h " + minutes + " min " + seconds + " s"
298 onClicked: {timePicker.timeType = "additional"; timePicker.player = "black"; timePicker.open()}
306 id: turnsPerAdditionText
307 text: "Turns per addition"
310 visible: newGameDialogPage.askTurnsPerAddition
311 anchors.verticalCenter: whiteTurnsPerAddition.verticalCenter
316 id: whiteTurnsPerAddition
317 visible: newGameDialogPage.askTurnsPerAddition
320 anchors.top: whiteAdditionalTime.bottom
321 anchors.topMargin: 15
322 anchors.left: turnsPerAdditionText.right
323 anchors.leftMargin: 25
330 onClicked: {turnsDialog.player = "white"; turnsDialog.open()}
337 id: blackTurnsPerAddition
338 visible: newGameDialogPage.askTurnsPerAddition && !equalTimesSwitch.checked
341 anchors.top: whiteTurnsPerAddition.top
342 anchors.left: whiteTurnsPerAddition.right
343 anchors.leftMargin: 25
350 onClicked: {turnsDialog.player = "black"; turnsDialog.open()}
361 anchors.top: whiteTurnsPerAddition.bottom
362 anchors.topMargin: 15
363 anchors.right: parent.right
369 clocksPage.timeControl = timeControl
372 clocksPage.whiteInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
373 clocksPage.whiteAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
374 clocksPage.whiteTurnsPerAddition = whiteTurnsPerAddition.text
377 //Save settings for white
378 settings.setInitialTime(timeControl,true,clocksPage.whiteInitialTime)
379 settings.setAdditionalTime(timeControl,true,clocksPage.whiteAdditionalTime)
380 settings.setTurnsPerAddition(timeControl,true,clocksPage.whiteTurnsPerAddition)
382 if (equalTimesSwitch.checked)
384 //use same values for white and black
385 clocksPage.blackInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
386 clocksPage.blackAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
387 clocksPage.blackTurnsPerAddition = whiteTurnsPerAddition.text
389 //If black values in dialog are not used they are not saved to settings
393 clocksPage.blackInitialTime = 60*60*1000*blackInitialTime.hours+60*1000*blackInitialTime.minutes+1000*blackInitialTime.seconds
394 clocksPage.blackAdditionalTime = 60*60*1000*blackAdditionalTime.hours+60*1000*blackAdditionalTime.minutes+1000*blackAdditionalTime.seconds
395 clocksPage.blackTurnsPerAddition = blackTurnsPerAddition.text
397 //Save settings for black
398 settings.setInitialTime(timeControl,false,clocksPage.blackInitialTime)
399 settings.setAdditionalTime(timeControl,false,clocksPage.blackAdditionalTime)
400 settings.setTurnsPerAddition(timeControl,false,clocksPage.blackTurnsPerAddition)
406 pageStack.push(clocksPage)
419 property string timeType
420 property string player
422 titleText: "Choose " + timeType + " time for " + player
423 rejectButtonText: "Cancel"
424 acceptButtonText: "Ok"
425 hourMode: DateTime.TwentyFourHours
428 if (timeType == "initial")
430 if (player == "white")
432 whiteInitialTime.hours = hour
433 whiteInitialTime.minutes = minute
434 whiteInitialTime.seconds = second
438 blackInitialTime.hours = hour
439 blackInitialTime.minutes = minute
440 blackInitialTime.seconds = second
443 else if (player == "white")
445 whiteAdditionalTime.hours = hour
446 whiteAdditionalTime.minutes = minute
447 whiteAdditionalTime.seconds = second
451 blackAdditionalTime.hours = hour
452 blackAdditionalTime.minutes = minute
453 blackAdditionalTime.seconds = second
474 Component.onCompleted:
476 for (var turn = 1; turn <= 99; turn++)
478 turnsList.append({"value" : turn});
490 property string player
492 titleText: "Choose turns per addition for " + player
493 acceptButtonText: "Ok"
494 rejectButtonText: "Cancel"
496 columns: [turnsColumn]
500 if (player == "white")
501 whiteTurnsPerAddition.text = turnsColumn.selectedIndex+1
502 else if (player == "black")
503 blackTurnsPerAddition.text = turnsColumn.selectedIndex+1