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
43 Settings {id: settings}
44 Component.onCompleted:
46 equalTimesSwitch = settings.isEqualTimes(timeControl)
47 whiteInitialTime = settings.getInitialTime(timeControl,true)
48 blackInitialTime = settings.getInitialTime(timeControl,false)
49 whiteAdditionalTime = settings.getAdditionalTime(timeControl,true)
50 blackAdditionalTime = settings.getAdditionalTime(timeControl,false)
51 whiteTurnsPerAddition = settings.getTurnsPerAddition(timeControl,true)
52 blackTurnsPerAddition = settings.getTurnsPerAddition(timeControl,false)
57 ToolIcon { iconId: "toolbar-back"; onClicked: pageStack.pop() }
66 anchors.horizontalCenter: parent.horizontalCenter
70 text: newGameDialogPage.name
78 anchors.top: title.bottom
82 // width: rowRow.width - rowRow.spacing - switchComponent.width - whiteSmall.width - blackSmall.width
83 // height: switchComponent.height
84 verticalAlignment: Text.AlignVCenter
97 whiteSmall.anchors.horizontalCenter = undefined
98 whiteSmall.anchors.right = whiteInitialTime.horizontalCenter
100 blackSmall.anchors.horizontalCenter = undefined
101 blackSmall.anchors.left = whiteInitialTime.horizontalCenter
109 whiteSmall.anchors.right = undefined
110 whiteSmall.anchors.horizontalCenter = whiteInitialTime.horizontalCenter
112 blackSmall.anchors.left = undefined
113 blackSmall.anchors.horizontalCenter = blackInitialTime.horizontalCenter
128 anchors.top: rowRow.bottom
130 source: ":/rc/pic/white_small.png"
132 Component.onCompleted:
134 if (equalTimesSwitch.checked)
135 anchors.right = whiteInitialTime.horizontalCenter
137 anchors.horizontalCenter = whiteInitialTime.horizontalCenter
146 anchors.top: rowRow.bottom
149 source: ":/rc/pic/black_small.png"
151 Component.onCompleted:
153 if (equalTimesSwitch.checked)
154 anchors.left = whiteInitialTime.horizontalCenter
156 anchors.horizontalCenter = blackInitialTime.horizontalCenter
166 anchors.verticalCenter: whiteInitialTime.verticalCenter
175 anchors.top: whiteSmall.bottom
176 anchors.left: whiteTurnsPerAddition.left
182 text: {hours + " h " + minutes + " min " + seconds + " s"}
188 onClicked: {timePicker.timeType = "initial"; timePicker.player = "white"; timePicker.open()}
197 visible: !equalTimesSwitch.checked
201 anchors.top: whiteSmall.bottom
202 anchors.left: blackTurnsPerAddition.left
208 text: hours + " h " + minutes + " min " + seconds + " s"
214 onClicked: {timePicker.timeType = "initial"; timePicker.player = "black"; timePicker.open()}
222 id: additionalTimeText
224 anchors.verticalCenter: whiteAdditionalTime.verticalCenter
226 text: "Additional time"
229 visible: newGameDialogPage.askAddition
230 // anchors.top: initialTimeText.bottom
231 // anchors.horizontalCenter: parent.horizontalCenter
238 id: whiteAdditionalTime
239 visible: newGameDialogPage.askAddition
242 anchors.top: whiteInitialTime.bottom
243 anchors.topMargin: 15
244 // anchors.left: additionalTimeText.right
245 anchors.left: whiteTurnsPerAddition.left
250 text: hours + " h " + minutes + " min " + seconds + " s"
256 onClicked: {timePicker.timeType = "additional"; timePicker.player = "white"; timePicker.open()}
262 id: blackAdditionalTime
263 visible: newGameDialogPage.askAddition && !equalTimesSwitch.checked
266 anchors.top: whiteAdditionalTime.top
267 anchors.left: blackTurnsPerAddition.left
273 text: hours + " h " + minutes + " min " + seconds + " s"
278 onClicked: {timePicker.timeType = "additional"; timePicker.player = "black"; timePicker.open()}
286 id: turnsPerAdditionText
287 text: "Turns per addition"
290 visible: newGameDialogPage.askTurnsPerAddition
291 anchors.verticalCenter: whiteTurnsPerAddition.verticalCenter
296 id: whiteTurnsPerAddition
297 visible: newGameDialogPage.askTurnsPerAddition
300 anchors.top: whiteAdditionalTime.bottom
301 anchors.topMargin: 15
302 anchors.left: turnsPerAdditionText.right
303 anchors.leftMargin: 25
310 onClicked: {turnsDialog.player = "white"; turnsDialog.open()}
317 id: blackTurnsPerAddition
318 visible: newGameDialogPage.askTurnsPerAddition && !equalTimesSwitch.checked
321 anchors.top: whiteTurnsPerAddition.top
322 anchors.left: whiteTurnsPerAddition.right
323 anchors.leftMargin: 25
330 onClicked: {turnsDialog.player = "black"; turnsDialog.open()}
341 anchors.top: whiteTurnsPerAddition.bottom
342 anchors.topMargin: 15
343 anchors.right: parent.right
349 clocksPage.timeControl = timeControl
352 clocksPage.whiteInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
353 clocksPage.whiteAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
354 clocksPage.whiteTurnsPerAddition = whiteTurnsPerAddition.text
357 //Save settings for white
358 settings.setInitialTime(timeControl,true,clocksPage.whiteInitialTime)
359 settings.setAdditionalTime(timeControl,true,clocksPage.whiteAdditionalTime)
360 settings.setTurnsPerAddition(timeControl,true,clocksPage.whiteTurnsPerAddition)
362 if (equalTimesSwitch.checked)
364 //use same values for white and black
365 clocksPage.blackInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
366 clocksPage.blackAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
367 clocksPage.blackTurnsPerAddition = whiteTurnsPerAddition.text
369 //If black values in dialog are not used they are not saved to settings
373 clocksPage.blackInitialTime = 60*60*1000*blackInitialTime.hours+60*1000*blackInitialTime.minutes+1000*blackInitialTime.seconds
374 clocksPage.blackAdditionalTime = 60*60*1000*blackAdditionalTime.hours+60*1000*blackAdditionalTime.minutes+1000*blackAdditionalTime.seconds
375 clocksPage.blackTurnsPerAddition = blackTurnsPerAddition.text
377 //Save settings for black
378 settings.setInitialTime(timeControl,false,clocksPage.blackInitialTime)
379 settings.setAdditionalTime(timeControl,false,clocksPage.blackAdditionalTime)
380 settings.setTurnsPerAddition(timeControl,false,clocksPage.blackTurnsPerAddition)
386 pageStack.push(clocksPage)
399 property string timeType
400 property string player
402 titleText: "Choose " + timeType + " time for " + player
403 rejectButtonText: "Cancel"
404 acceptButtonText: "Ok"
405 hourMode: DateTime.TwentyFourHours
408 if (timeType == "initial")
410 if (player == "white")
412 whiteInitialTime.hours = hour
413 whiteInitialTime.minutes = minute
414 whiteInitialTime.seconds = second
418 blackInitialTime.hours = hour
419 blackInitialTime.minutes = minute
420 blackInitialTime.seconds = second
423 else if (player == "white")
425 whiteAdditionalTime.hours = hour
426 whiteAdditionalTime.minutes = minute
427 whiteAdditionalTime.seconds = second
431 blackAdditionalTime.hours = hour
432 blackAdditionalTime.minutes = minute
433 blackAdditionalTime.seconds = second
454 Component.onCompleted:
456 for (var turn = 1; turn <= 99; turn++)
458 turnsList.append({"value" : turn});
470 property string player
472 titleText: "Choose turns per addition for " + player
473 acceptButtonText: "Ok"
474 rejectButtonText: "Cancel"
476 columns: [turnsColumn]
480 if (player == "white")
481 whiteTurnsPerAddition.text = turnsColumn.selectedIndex+1
482 else if (player == "black")
483 blackTurnsPerAddition.text = turnsColumn.selectedIndex+1