Fixed dialog button sizes
[chessclock] / qml / NewGameDialogPage.qml
index 57979a3..eb3f633 100644 (file)
@@ -30,23 +30,71 @@ import ChessClocks 1.0
 Page
 {
     id: newGameDialogPage
-    tools: commonTools
+
     orientationLock: PageOrientation.LockLandscape
 
     property string name
-    property int timeControl //QML does not allow properties to be declared as enums...
+
+    //QML does not allow properties to be declared as enums...
+    //Initializing to invalid value to make sure picking *any* time control will trigger OnTimeControlChanged
+    property int timeControl: 1000
+
+
     property bool askAddition
     property bool askTurnsPerAddition
 
+    property int test
+
+    Settings
+    {
+        id: settings
+
+    }
+    onTimeControlChanged:
+    {
+        equalTimesSwitch.checked = settings.isEqualTimes(timeControl)
+
+        var whiteInitial = settings.getInitialTime(timeControl,true)
+        whiteInitialTime.hours = Qt.formatTime(whiteInitial,"h")
+        whiteInitialTime.minutes = Qt.formatTime(whiteInitial,"m")
+        whiteInitialTime.seconds = Qt.formatTime(whiteInitial,"s")
+
+        var blackInitial = settings.getInitialTime(timeControl,false)
+        blackInitialTime.hours = Qt.formatTime(blackInitial,"h")
+        blackInitialTime.minutes = Qt.formatTime(blackInitial,"m")
+        blackInitialTime.seconds = Qt.formatTime(blackInitial,"s")
 
+        var whiteAdditional = settings.getAdditionalTime(timeControl,true)
+        whiteAdditionalTime.hours = Qt.formatTime(whiteAdditional,"h")
+        whiteAdditionalTime.minutes = Qt.formatTime(whiteAdditional,"m")
+        whiteAdditionalTime.seconds = Qt.formatTime(whiteAdditional,"s")
 
-           Label
+        var blackAdditional = settings.getAdditionalTime(timeControl,false)
+        blackAdditionalTime.hours = Qt.formatTime(blackAdditional,"h")
+        blackAdditionalTime.minutes = Qt.formatTime(blackAdditional,"m")
+        blackAdditionalTime.seconds = Qt.formatTime(blackAdditional,"s")
+
+
+        whiteTurnsPerAddition.text = settings.getTurnsPerAddition(timeControl,true)
+        blackTurnsPerAddition.text = settings.getTurnsPerAddition(timeControl,false)
+    }
+
+    tools: ToolBarLayout
+    {
+        ToolIcon { iconId: "toolbar-back"; onClicked: pageStack.pop() }
+    }
+
+
+
+           Text
             {
                 id: title
 
+                anchors.horizontalCenter: parent.horizontalCenter
+
                 color:"white"
-                font.pointSize: 64
-                text: newGameDialog.name
+                font.pointSize: 26
+                text: newGameDialogPage.name
             }
 
             Row
@@ -73,6 +121,24 @@ Page
                     {
                         if (checked)
                         {
+                            whiteSmall.anchors.horizontalCenter = undefined
+                            whiteSmall.anchors.right = whiteInitialTime.horizontalCenter
+
+                            blackSmall.anchors.horizontalCenter = undefined
+                            blackSmall.anchors.left = whiteInitialTime.horizontalCenter
+
+
+                        }
+
+                        else
+                        {
+
+                            whiteSmall.anchors.right = undefined
+                            whiteSmall.anchors.horizontalCenter = whiteInitialTime.horizontalCenter
+
+                            blackSmall.anchors.left = undefined
+                            blackSmall.anchors.horizontalCenter = blackInitialTime.horizontalCenter
+
                         }
 
                     }
@@ -87,7 +153,16 @@ Page
                 id: whiteSmall
 
                 anchors.top: rowRow.bottom
+
                 source: ":/rc/pic/white_small.png"
+
+                Component.onCompleted:
+                {
+                    if (equalTimesSwitch.checked)
+                        anchors.right = whiteInitialTime.horizontalCenter
+                    else
+                        anchors.horizontalCenter = whiteInitialTime.horizontalCenter
+                }
             }
 
             Image
@@ -96,9 +171,17 @@ Page
                 id: blackSmall
 
                 anchors.top: rowRow.bottom
-                anchors.left: whiteSmall.right
+
 
                 source: ":/rc/pic/black_small.png"
+
+                Component.onCompleted:
+                {
+                    if (equalTimesSwitch.checked)
+                        anchors.left = whiteInitialTime.horizontalCenter
+                    else
+                        anchors.horizontalCenter = blackInitialTime.horizontalCenter
+                }
             }
 
             Text
@@ -107,57 +190,63 @@ Page
                 text: "Initial time"
                 color: "white"
                 font.pointSize: 26
-                anchors.top: whiteSmall.bottom
+                anchors.verticalCenter: whiteInitialTime.verticalCenter
               }
 
 
-            TextField
+            Button
             {
                 id: whiteInitialTime
-                readOnly: true
 
                 anchors.top: whiteSmall.bottom
-                anchors.left: initialTimeText.right
+                anchors.left: whiteTurnsPerAddition.left
+                anchors.right: whiteTurnsPerAddition.right
 
-                property int hours
-                property int minutes
-                property int seconds
+                property int hours: 0
+                property int minutes: 30
+                property int seconds: 0
 
                 text: {hours + " h " + minutes + " min " + seconds + " s"}
 
-
-                MouseArea
+                onClicked:
                 {
-                    anchors.fill: parent
-                    onClicked: {timePicker.timeType = "initial";  timePicker.player = "white"; timePicker.open()}
+                    timePicker.timeType = "initial"
+                    timePicker.player = "white"
+                    timePicker.hour = hours
+                    timePicker.minute = minutes
+                    timePicker.second = seconds
+                    timePicker.open()
                 }
+
             }
 
 
 
-            TextField
+            Button
             {
                 id: blackInitialTime
-                enabled: !equalTimesSwitch.checked
-
-                readOnly: true
+                visible: !equalTimesSwitch.checked
 
                 anchors.top: whiteSmall.bottom
-                anchors.left:  whiteInitialTime.right
+                anchors.left:  blackTurnsPerAddition.left
+                anchors.right: blackTurnsPerAddition.right
 
-                property int hours
-                property int minutes
-                property int seconds
+                property int hours: 0
+                property int minutes: 30
+                property int seconds: 0
 
                 text: hours + " h " + minutes + " min " + seconds + " s"
 
-
-
-                MouseArea
+                onClicked:
                 {
-                anchors.fill: parent
-                onClicked: {timePicker.timeType = "initial";  timePicker.player = "black"; timePicker.open()}
+                    timePicker.timeType = "initial"
+                    timePicker.player = "black"
+                    timePicker.hour = hours
+                    timePicker.minute = minutes
+                    timePicker.second = seconds
+                    timePicker.open()
                 }
+
             }
 
 
@@ -166,7 +255,7 @@ Page
             {
                 id: additionalTimeText
 
-                anchors.top: whiteInitialTime.bottom
+                anchors.verticalCenter: whiteAdditionalTime.verticalCenter
 
                 text: "Additional time"
                 color: "white"
@@ -178,52 +267,62 @@ Page
 
 
 
-            TextField
+            Button
             {
                 id: whiteAdditionalTime
                 visible:  newGameDialogPage.askAddition
-                readOnly: true
 
                 anchors.top: whiteInitialTime.bottom
-                anchors.left: additionalTimeText.right
-
-                property int hours
-                property int minutes
-                property int seconds
+                anchors.topMargin: 15
+  //              anchors.left: additionalTimeText.right
+                anchors.left: whiteTurnsPerAddition.left
+                anchors.right: whiteTurnsPerAddition.right
+                property int hours: 0
+                property int minutes: 0
+                property int seconds: 30
 
                 text: hours + " h " + minutes + " min " + seconds + " s"
 
-
-                MouseArea
+                onClicked:
                 {
-                    anchors.fill: parent
-                    onClicked: {timePicker.timeType = "additional";  timePicker.player = "white"; timePicker.open()}
+                    timePicker.timeType = "additional"
+                    timePicker.player = "white"
+                    timePicker.hour = hours
+                    timePicker.minute = minutes
+                    timePicker.second = seconds
+                    timePicker.open()
                 }
+
             }
 
-            TextField
+            Button
             {
                 id: blackAdditionalTime
-                visible: newGameDialogPage.askAddition
-                enabled: !equalTimesSwitch.checked
-                readOnly: true
+                visible: newGameDialogPage.askAddition && !equalTimesSwitch.checked
 
-                anchors.top: whiteInitialTime.bottom
-                anchors.left: whiteAdditionalTime.right
+                anchors.top: whiteAdditionalTime.top
+                anchors.left: blackTurnsPerAddition.left
+                anchors.right: blackTurnsPerAddition.right
 
-                property int hours
-                property int minutes
-                property int seconds
+                property int hours: 0
+                property int minutes: 0
+                property int seconds: 30
 
                 text: hours + " h " + minutes + " min " + seconds + " s"
 
-                MouseArea
+
+                onClicked:
                 {
-                    anchors.fill: parent
-                    onClicked: {timePicker.timeType = "additional";  timePicker.player = "black"; timePicker.open()}
+                    timePicker.timeType = "additional"
+                    timePicker.player = "black"
+                    timePicker.hour = hours
+                    timePicker.minute = minutes
+                    timePicker.second = seconds
+                    timePicker.open()
                 }
 
 
+
             }
 
             Text
@@ -233,45 +332,51 @@ Page
                 color: "white"
                 font.pointSize: 26
                 visible: newGameDialogPage.askTurnsPerAddition
-                anchors.top: whiteAdditionalTime.bottom
+                anchors.verticalCenter: whiteTurnsPerAddition.verticalCenter
             }
 
-            TextField
+            Button
             {
                 id: whiteTurnsPerAddition
                 visible: newGameDialogPage.askTurnsPerAddition
-                readOnly: true;
 
                 anchors.top: whiteAdditionalTime.bottom
+                anchors.topMargin: 15
                 anchors.left: turnsPerAdditionText.right
+                anchors.leftMargin: 25
+//                anchors.rightMargin: 25
+                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.
 
-                text: "1"
 
-                MouseArea
+                onClicked:
                 {
-                    anchors.fill: parent
-                    onClicked: {turnsDialog.player = "white";  turnsDialog.open()}
+                    turnsDialog.player = "white"
+                    turnsDialog.open()
+                    turnsColumn.selectedIndex = text-1 //Needs to be after open(),  or gets overridden by the previous chosen value
+
                 }
 
+
             }
 
-            TextField
+            Button
             {
                 id: blackTurnsPerAddition
-                visible: newGameDialogPage.askTurnsPerAddition
-                readOnly: true;
+                visible: newGameDialogPage.askTurnsPerAddition && !equalTimesSwitch.checked
 
-                anchors.top: whiteAdditionalTime.bottom
-                anchors.left: whiteTurnsPerAddition.right
 
-                text: "1"
+                anchors.top: whiteTurnsPerAddition.top
+                anchors.left: whiteTurnsPerAddition.right
+                anchors.leftMargin: 25
+                anchors.right: parent.right
+                anchors.rightMargin: 25
 
-                MouseArea
+                onClicked:
                 {
-                    anchors.fill: parent
-                    onClicked: {turnsDialog.player = "black";  turnsDialog.open()}
+                    turnsDialog.player = "black"
+                    turnsDialog.open()
+                    turnsColumn.selectedIndex = parent.text-1 //Needs to be after open(),  or gets overridden by the previous chosen value
                 }
-
             }
 
 
@@ -281,29 +386,54 @@ Page
                 text:  "Start game"
 
                 anchors.top: whiteTurnsPerAddition.bottom
+                anchors.topMargin: 15
+                anchors.right: parent.right
+                anchors.rightMargin: 5
 
                 onClicked:
                 {
+
+
                 clocksPage.timeControl = timeControl
 
+
                 clocksPage.whiteInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
                 clocksPage.whiteAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
                 clocksPage.whiteTurnsPerAddition = whiteTurnsPerAddition.text
 
+
+
+                //Save settings for white
+                settings.setInitialTime(timeControl,true,whiteInitialTime.hours,whiteInitialTime.minutes,whiteInitialTime.seconds)
+                settings.setAdditionalTime(timeControl,true,whiteAdditionalTime.hours,whiteAdditionalTime.minutes,whiteAdditionalTime.seconds)
+                settings.setTurnsPerAddition(timeControl,true,whiteTurnsPerAddition.text)
+
+                settings.setEqualTimes(timeControl,equalTimesSwitch.checked) //save equal times setting
+
                 if (equalTimesSwitch.checked)
                 {
+                    //use same values for white and black
                     clocksPage.blackInitialTime = 60*60*1000*whiteInitialTime.hours+60*1000*whiteInitialTime.minutes+1000*whiteInitialTime.seconds
                     clocksPage.blackAdditionalTime = 60*60*1000*whiteAdditionalTime.hours+60*1000*whiteAdditionalTime.minutes+1000*whiteAdditionalTime.seconds
                     clocksPage.blackTurnsPerAddition = whiteTurnsPerAddition.text
 
+                    //If black values in dialog are not used they are not saved to settings
                 }
                 else
                 {
                     clocksPage.blackInitialTime = 60*60*1000*blackInitialTime.hours+60*1000*blackInitialTime.minutes+1000*blackInitialTime.seconds
                     clocksPage.blackAdditionalTime = 60*60*1000*blackAdditionalTime.hours+60*1000*blackAdditionalTime.minutes+1000*blackAdditionalTime.seconds
                     clocksPage.blackTurnsPerAddition = blackTurnsPerAddition.text
+
+                    //Save settings for black
+                    settings.setInitialTime(timeControl,false,blackInitialTime.hours,blackInitialTime.minutes,blackInitialTime.seconds)
+                    settings.setAdditionalTime(timeControl,false,blackAdditionalTime.hours,blackAdditionalTime.minutes,blackAdditionalTime.seconds)
+                    settings.setTurnsPerAddition(timeControl,false,blackTurnsPerAddition.text)
                 }
 
+
+
+
                 pageStack.push(clocksPage)
 
             }
@@ -362,7 +492,6 @@ TimePickerDialog
 TumblerColumn
 {
     id: turnsColumn
-    selectedIndex: 1
     items: turnsList