Import first revisions of new project SchachUhr.

Fri, 08 Jul 2011 22:41:48 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 08 Jul 2011 22:41:48 +0200
changeset 3
c5c9ba04c01a
parent 2
57bc4d78e5cd
child 4
fe1cd8fc5b83

Import first revisions of new project SchachUhr.

qml/Wecker.qml file | annotate | diff | comparison | revisions
qml/main.qml file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/qml/Wecker.qml	Fri Jul 08 22:41:48 2011 +0200
     1.3 @@ -0,0 +1,163 @@
     1.4 +//
     1.5 +//  Schachuhr - Chess clock graphical user interface client
     1.6 +//  Copyright © 2011 Michael Schloh von Bennewitz <michael@schloh.com>
     1.7 +//
     1.8 +//  Schachuhr is free software: you can redistribute it and/or modify
     1.9 +//  it under the terms of the GNU General Public License as published
    1.10 +//  by the Free Software Foundation, either version 3 of the License,
    1.11 +//  or (at your option) any later version.
    1.12 +//
    1.13 +//  Schachuhr is distributed in the hope that it will be useful,
    1.14 +//  but WITHOUT ANY WARRANTY; without even the implied warranty
    1.15 +//  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
    1.16 +//  the GNU General Public License for more details.
    1.17 +//
    1.18 +//  You should have received a copy of the GNU General Public License
    1.19 +//  along with Schachuhr. If not, see <http://www.gnu.org/licenses/>.
    1.20 +//
    1.21 +//  This file is part of project Schachuhr, a chess clock graphical
    1.22 +//  user interface client and is found at http://schachuhr.europalab.com/
    1.23 +//
    1.24 +//  Wecker.qml: QML implementation
    1.25 +//
    1.26 +
    1.27 +import QtQuick 1.0
    1.28 +
    1.29 +Item {          // unsure if this should be a generic item
    1.30 +    id: wecker  // or be rewritten as a QML component
    1.31 +    width: 365; height: 360  // roughly the size of a single clockface
    1.32 +
    1.33 +    property alias opponent: playName.text  // opponent name
    1.34 +    property int hours                    // displayed hour hand
    1.35 +    property int minutes                  // displayed minute hand
    1.36 +    property int seconds                  // displayed second hand
    1.37 +    property real zeitfrist               // opponent time allowance
    1.38 +    property bool altercolor: false       // opponent clock colour choice
    1.39 +    property bool running: true           // indicates wecker state
    1.40 +
    1.41 +    // called once when hands are initialized
    1.42 +    function timeInit() {
    1.43 +        seconds = 0
    1.44 +        minutes = 60 - zeitfrist % 60
    1.45 +        hours = 11 - zeitfrist / 60
    1.46 +    }
    1.47 +
    1.48 +    // called constantly as match progresses
    1.49 +    function timeChanged() {
    1.50 +        seconds = seconds + 1
    1.51 +        if (seconds % 60 == 0) {
    1.52 +            if (minutes == 59)
    1.53 +                hours++
    1.54 +            minutes++
    1.55 +        }
    1.56 +    }
    1.57 +
    1.58 +    // starts the timer of the next opponent,
    1.59 +    // and stops the timer of the current one
    1.60 +    // as well as indicating the running clock
    1.61 +    // using text color and clockface size
    1.62 +    function toggle() {
    1.63 +        if (wecker.state == "playing") {
    1.64 +            wecker.state = "waiting"
    1.65 +            timeLeft.running = false
    1.66 +            playName.color = "#A08050"
    1.67 +            playName.style = Text.Sunken
    1.68 +        }
    1.69 +        else {
    1.70 +            wecker.state = "playing"
    1.71 +            timeLeft.running = true
    1.72 +            playName.color = "white"
    1.73 +            playName.style = Text.Raised
    1.74 +        }
    1.75 +    }
    1.76 +
    1.77 +    // the match timer
    1.78 +    Timer {
    1.79 +        id: timeLeft
    1.80 +        interval: 1000; running: false; repeat: true; triggeredOnStart: true
    1.81 +        onTriggered: wecker.timeChanged()
    1.82 +    }
    1.83 +
    1.84 +    // a series of mutually exclusive clockface colours and sizes,
    1.85 +    // in which only one is used for each opponent at a given time
    1.86 +    Image { id: bgbraunlit; x: 50; y: 50; width: 320; height: 320; source: "clock-braun.png"; visible: wecker.altercolor == false && wecker.running == false }
    1.87 +    Image { id: bgbraunbig; width: 420; height: 420; source: "clock-brexp.png"; visible: wecker.altercolor == false && wecker.running == true }
    1.88 +    Image { id: bgbleuelit; x: 50; y: 50; width: 320; height: 320; source: "clock-bleu.png"; visible: wecker.altercolor == true && wecker.running == false }
    1.89 +    Image { id: bgbleuebig; width: 420; height: 420; source: "clock-blexp.png"; visible: wecker.altercolor == true && wecker.running == true }
    1.90 +
    1.91 +    // animated second hand is placed under the center graphic
    1.92 +    Image {
    1.93 +        x: 202; y: 80
    1.94 +        width: 15; height: 130
    1.95 +        source: "seconds.svg"
    1.96 +        smooth: true
    1.97 +        transform: Rotation {
    1.98 +            id: secondRotation
    1.99 +            origin.x: 7.5; origin.y: 130;
   1.100 +            angle: wecker.seconds * 6
   1.101 +            Behavior on angle {
   1.102 +                SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
   1.103 +            }
   1.104 +        }
   1.105 +    }
   1.106 +
   1.107 +    // the center graphic which covers or connects to various hands
   1.108 +    Image {
   1.109 +        width: 34; height: 34; anchors.centerIn: bgbraunbig; source: "centre.png"
   1.110 +    }
   1.111 +
   1.112 +    // animated hour hand is placed over the center graphic
   1.113 +    Image {
   1.114 +        x: 200; y: 130
   1.115 +        width: 20; height: 70
   1.116 +        source: "hourmin.svg"
   1.117 +        smooth: true
   1.118 +        transform: Rotation {
   1.119 +            id: hourRotation
   1.120 +            origin.x: 10; origin.y: 80;
   1.121 +            angle: (wecker.hours * 30) + (wecker.minutes * 0.5)
   1.122 +            Behavior on angle {
   1.123 +                SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
   1.124 +            }
   1.125 +        }
   1.126 +    }
   1.127 +
   1.128 +    // animated minute hand is placed over the center graphic
   1.129 +    Image {
   1.130 +        x: 202; y: 90
   1.131 +        width: 16; height: 110
   1.132 +        source: "hourmin.svg"
   1.133 +        smooth: true
   1.134 +        transform: Rotation {
   1.135 +            id: minuteRotation
   1.136 +            origin.x: 8; origin.y: 120;
   1.137 +            angle: wecker.minutes * 6
   1.138 +            Behavior on angle {
   1.139 +                SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
   1.140 +            }
   1.141 +        }
   1.142 +    }
   1.143 +
   1.144 +    // opponent name like 'Vladimir KRAMNIK',
   1.145 +    // is sunken and dimmed when not active
   1.146 +    // due to toggle function taking action
   1.147 +    Text {
   1.148 +        id: playName
   1.149 +        y: 400; anchors.horizontalCenter: bgbraunbig.horizontalCenter
   1.150 +        color: "white"
   1.151 +        font.bold: true; font.pixelSize: 54
   1.152 +        style: Text.Raised; styleColor: "black"
   1.153 +    }
   1.154 +
   1.155 +    // two state definitions, opponent take turns waiting or playing
   1.156 +    states: [
   1.157 +        State {
   1.158 +            name: "playing"
   1.159 +            PropertyChanges { target: wecker; running: true }
   1.160 +        },
   1.161 +        State {
   1.162 +            name: "waiting"
   1.163 +            PropertyChanges { target: wecker; running: false }
   1.164 +        }
   1.165 +    ]
   1.166 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/qml/main.qml	Fri Jul 08 22:41:48 2011 +0200
     2.3 @@ -0,0 +1,142 @@
     2.4 +//
     2.5 +//  Schachuhr - Chess clock graphical user interface client
     2.6 +//  Copyright © 2011 Michael Schloh von Bennewitz <michael@schloh.com>
     2.7 +//
     2.8 +//  Schachuhr is free software: you can redistribute it and/or modify
     2.9 +//  it under the terms of the GNU General Public License as published
    2.10 +//  by the Free Software Foundation, either version 3 of the License,
    2.11 +//  or (at your option) any later version.
    2.12 +//
    2.13 +//  Schachuhr is distributed in the hope that it will be useful,
    2.14 +//  but WITHOUT ANY WARRANTY; without even the implied warranty
    2.15 +//  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
    2.16 +//  the GNU General Public License for more details.
    2.17 +//
    2.18 +//  You should have received a copy of the GNU General Public License
    2.19 +//  along with Schachuhr. If not, see <http://www.gnu.org/licenses/>.
    2.20 +//
    2.21 +//  This file is part of project Schachuhr, a chess clock graphical
    2.22 +//  user interface client and is found at http://schachuhr.europalab.com/
    2.23 +//
    2.24 +//  main.qml: QML implementation
    2.25 +//
    2.26 +
    2.27 +import QtQuick 1.0
    2.28 +
    2.29 +Rectangle {
    2.30 +    width: 854;       // until better layout design is learned, this hard
    2.31 +    height: 480;      // codes the client surface to fit on MeeGo handheld
    2.32 +    color: "#7D5C2E"  // light cocolate brown background
    2.33 +    property bool init: true  // indicates game clocks in initial state
    2.34 +
    2.35 +    // title bar is flush left and rotated
    2.36 +    Rectangle {
    2.37 +        id: progTitle
    2.38 +        width: 480; height: 90
    2.39 +        color: "#503014"
    2.40 +        Text {
    2.41 +            id: progLabel
    2.42 +            text: "Chess Clock"
    2.43 +            anchors.centerIn: parent
    2.44 +            color: "#7D5C2E"
    2.45 +            font.bold: true; font.pixelSize: 72
    2.46 +            style: Text.Raised
    2.47 +            styleColor: "black"
    2.48 +        }
    2.49 +        transform: Rotation { origin.x: 240; origin.y: 240; angle: 270}
    2.50 +    }
    2.51 +
    2.52 +    // aesthetic top corner is rounded to match clock circumference curve
    2.53 +    Image { x: 90; width: 190; height: 190; source: "cornerl.svg" }
    2.54 +    //Image {
    2.55 +    //    x: 80
    2.56 +    //    y: 270
    2.57 +    //    width: 50
    2.58 +    //    height: 50
    2.59 +    //    source: "cornerl.svg"
    2.60 +    //    transform: Rotation { origin.x: 25; origin.y: 25; angle: 270 }
    2.61 +    //}
    2.62 +
    2.63 +    Row {  // space two game subclocks and associated text in a row
    2.64 +        anchors.top: parent.top; anchors.topMargin: -10;
    2.65 +        anchors.left: parent.left; anchors.leftMargin: 80;
    2.66 +        Wecker {
    2.67 +            id: opponOne
    2.68 +            opponent: "Oppenent 1"  // name of player at left of clock
    2.69 +            zeitfrist: 15           // opponent's time limit
    2.70 +            altercolor: false       // opponent's clock colour
    2.71 +            MouseArea {               // clicking here is only signaled
    2.72 +                enabled: true         // at start of match when the 'init'
    2.73 +                id: weckoneArea       // variable is set and thus the entire
    2.74 +                anchors.fill: parent  // surface mouse area is disabled
    2.75 +                acceptedButtons: Qt.LeftButton | Qt.RightButton
    2.76 +                onClicked: {
    2.77 +                    //if (mouse.button == Qt.RightButton)
    2.78 +                    //    aboutDlg.visible = true
    2.79 +                    //else { // left button was pressed
    2.80 +                        init = false
    2.81 +                        //aboutDlg.visible = false
    2.82 +                        entireArea.enabled = true  // will take precedence
    2.83 +                        opponOne.toggle()   // start opponent one's clock
    2.84 +                        opponTwo.toggle()   // toggle opponent two's clock
    2.85 +                        opponTwo.toggle()   // twice to force into paused
    2.86 +                    //}
    2.87 +                }
    2.88 +            }
    2.89 +        }
    2.90 +        Wecker {
    2.91 +            id: opponTwo
    2.92 +            opponent: "Opponent 2"  // name of player at right of clock
    2.93 +            zeitfrist: 15           // opponent's time limit
    2.94 +            altercolor: true        // opponent's clock colour
    2.95 +            MouseArea {               // clicking here is only signaled
    2.96 +                enabled: true         // at start of match when the 'init'
    2.97 +                id: wecktwoArea       // variable is set and thus the entire
    2.98 +                anchors.fill: parent  // surface mouse area is disabled
    2.99 +                acceptedButtons: Qt.LeftButton | Qt.RightButton
   2.100 +                onClicked: {
   2.101 +                    //if (mouse.button == Qt.RightButton)
   2.102 +                    //    aboutDlg.visible = true
   2.103 +                    //else { // left button was pressed
   2.104 +                        init = false
   2.105 +                        //aboutDlg.visible = false
   2.106 +                        entireArea.enabled = true  // will take precedence
   2.107 +                        opponTwo.toggle()   // start opponent two's clock
   2.108 +                        opponOne.toggle()   // toggle opponent one's clock
   2.109 +                        opponOne.toggle()   // twice to force into paused
   2.110 +                    //}
   2.111 +                }
   2.112 +            }
   2.113 +        }
   2.114 +    }
   2.115 +
   2.116 +    //Image { id: aboutDlg; anchors.centerIn: parent; width: 423; height: 386; source: "wikichess.jpeg"; visible: false }
   2.117 +
   2.118 +    // the main area covering the entire client surface
   2.119 +    MouseArea {
   2.120 +        enabled: false
   2.121 +        id: entireArea
   2.122 +        anchors.fill: parent
   2.123 +        acceptedButtons: Qt.LeftButton | Qt.RightButton
   2.124 +        onClicked: {
   2.125 +            //if (mouse.button == Qt.LeftButton && init == false) {
   2.126 +                //aboutDlg.visible = false
   2.127 +                opponOne.toggle()  // stop or start opponent one's clock
   2.128 +                opponTwo.toggle()  // stop or start opponent two's clock
   2.129 +            //}
   2.130 +            //else if (mouse.button == Qt.RightButton && init == false)
   2.131 +            //    aboutDlg.visible = true
   2.132 +            //else                                          // assert clicked
   2.133 +            //    console.log("Problem click in initial.")  // in init state
   2.134 +        }
   2.135 +    }
   2.136 +
   2.137 +    Timer {             // just waits a second before moving the arms of
   2.138 +        interval: 1000  // the game subclocks into their initial position
   2.139 +        running: true
   2.140 +        onTriggered: {
   2.141 +            opponOne.timeInit()
   2.142 +            opponTwo.timeInit()
   2.143 +        }
   2.144 +    }
   2.145 +}

mercurial