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.1
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"}
213 timePicker.timeType = "initial"
214 timePicker.player = "white"
215 timePicker.hour = hours
216 timePicker.minute = minutes
217 timePicker.second = seconds
228 visible: !equalTimesSwitch.checked
230 anchors.top: whiteSmall.bottom
231 anchors.left: blackTurnsPerAddition.left
232 anchors.right: blackTurnsPerAddition.right
234 property int hours: 0
235 property int minutes: 30
236 property int seconds: 0
238 text: hours + " h " + minutes + " min " + seconds + " s"
242 timePicker.timeType = "initial"
243 timePicker.player = "black"
244 timePicker.hour = hours
245 timePicker.minute = minutes
246 timePicker.second = seconds
256 id: additionalTimeText
258 anchors.verticalCenter: whiteAdditionalTime.verticalCenter
260 text: "Additional time"
263 visible: newGameDialogPage.askAddition
264 // anchors.top: initialTimeText.bottom
265 // anchors.horizontalCenter: parent.horizontalCenter
272 id: whiteAdditionalTime
273 visible: newGameDialogPage.askAddition
275 anchors.top: whiteInitialTime.bottom
276 anchors.topMargin: 15
277 // anchors.left: additionalTimeText.right
278 anchors.left: whiteTurnsPerAddition.left
279 anchors.right: whiteTurnsPerAddition.right
280 property int hours: 0
281 property int minutes: 0
282 property int seconds: 30
284 text: hours + " h " + minutes + " min " + seconds + " s"
288 timePicker.timeType = "additional"
289 timePicker.player = "white"
290 timePicker.hour = hours
291 timePicker.minute = minutes
292 timePicker.second = seconds
300 id: blackAdditionalTime
301 visible: newGameDialogPage.askAddition && !equalTimesSwitch.checked
303 anchors.top: whiteAdditionalTime.top
304 anchors.left: blackTurnsPerAddition.left
305 anchors.right: blackTurnsPerAddition.right
307 property int hours: 0
308 property int minutes: 0
309 property int seconds: 30
311 text: hours + " h " + minutes + " min " + seconds + " s"
316 timePicker.timeType = "additional"
317 timePicker.player = "black"
318 timePicker.hour = hours
319 timePicker.minute = minutes
320 timePicker.second = seconds
330 id: turnsPerAdditionText
331 text: "Turns per addition"
334 visible: newGameDialogPage.askTurnsPerAddition
335 anchors.verticalCenter: whiteTurnsPerAddition.verticalCenter
340 id: whiteTurnsPerAddition
341 visible: newGameDialogPage.askTurnsPerAddition
343 anchors.top: whiteAdditionalTime.bottom
344 anchors.topMargin: 15
345 anchors.left: turnsPerAdditionText.right
346 anchors.leftMargin: 25
347 // anchors.rightMargin: 25
348 width: 250 //The width of all white buttons are indirectly defined by this value, and the width of black buttons is defined by the space available.
353 turnsDialog.player = "white"
355 turnsColumn.selectedIndex = text-1 //Needs to be after open(), or gets overridden by the previous chosen value
364 id: blackTurnsPerAddition
365 visible: newGameDialogPage.askTurnsPerAddition && !equalTimesSwitch.checked
368 anchors.top: whiteTurnsPerAddition.top
369 anchors.left: whiteTurnsPerAddition.right
370 anchors.leftMargin: 25
371 anchors.right: parent.right
372 anchors.rightMargin: 25
376 turnsDialog.player = "black"
378 turnsColumn.selectedIndex = parent.text-1 //Needs to be after open(), or gets overridden by the previous chosen value
388 anchors.top: whiteTurnsPerAddition.bottom
389 anchors.topMargin: 15
390 anchors.right: parent.right
391 anchors.rightMargin: 5
397 clocksPage.timeControl = timeControl
400 clocksPage.whiteInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
401 clocksPage.whiteAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
402 clocksPage.whiteTurnsPerAddition = whiteTurnsPerAddition.text
406 //Save settings for white
407 settings.setInitialTime(timeControl,true,whiteInitialTime.hours,whiteInitialTime.minutes,whiteInitialTime.seconds)
408 settings.setAdditionalTime(timeControl,true,whiteAdditionalTime.hours,whiteAdditionalTime.minutes,whiteAdditionalTime.seconds)
409 settings.setTurnsPerAddition(timeControl,true,whiteTurnsPerAddition.text)
411 settings.setEqualTimes(timeControl,equalTimesSwitch.checked) //save equal times setting
413 if (equalTimesSwitch.checked)
415 //use same values for white and black
416 clocksPage.blackInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
417 clocksPage.blackAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
418 clocksPage.blackTurnsPerAddition = whiteTurnsPerAddition.text
420 //If black values in dialog are not used they are not saved to settings
424 clocksPage.blackInitialTime = 60*60*1000*blackInitialTime.hours+60*1000*blackInitialTime.minutes+1000*blackInitialTime.seconds
425 clocksPage.blackAdditionalTime = 60*60*1000*blackAdditionalTime.hours+60*1000*blackAdditionalTime.minutes+1000*blackAdditionalTime.seconds
426 clocksPage.blackTurnsPerAddition = blackTurnsPerAddition.text
428 //Save settings for black
429 settings.setInitialTime(timeControl,false,blackInitialTime.hours,blackInitialTime.minutes,blackInitialTime.seconds)
430 settings.setAdditionalTime(timeControl,false,blackAdditionalTime.hours,blackAdditionalTime.minutes,blackAdditionalTime.seconds)
431 settings.setTurnsPerAddition(timeControl,false,blackTurnsPerAddition.text)
437 pageStack.push(clocksPage)
450 property string timeType
451 property string player
453 titleText: "Choose " + timeType + " time for " + player
454 rejectButtonText: "Cancel"
455 acceptButtonText: "Ok"
456 hourMode: DateTime.TwentyFourHours
459 if (timeType == "initial")
461 if (player == "white")
463 whiteInitialTime.hours = hour
464 whiteInitialTime.minutes = minute
465 whiteInitialTime.seconds = second
469 blackInitialTime.hours = hour
470 blackInitialTime.minutes = minute
471 blackInitialTime.seconds = second
474 else if (player == "white")
476 whiteAdditionalTime.hours = hour
477 whiteAdditionalTime.minutes = minute
478 whiteAdditionalTime.seconds = second
482 blackAdditionalTime.hours = hour
483 blackAdditionalTime.minutes = minute
484 blackAdditionalTime.seconds = second
504 Component.onCompleted:
506 for (var turn = 1; turn <= 99; turn++)
508 turnsList.append({"value" : turn});
520 property string player
522 titleText: "Choose turns per addition for " + player
523 acceptButtonText: "Ok"
524 rejectButtonText: "Cancel"
526 columns: [turnsColumn]
530 if (player == "white")
531 whiteTurnsPerAddition.text = turnsColumn.selectedIndex+1
532 else if (player == "black")
533 blackTurnsPerAddition.text = turnsColumn.selectedIndex+1