qml/Wecker.qml

changeset 3
c5c9ba04c01a
     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 +}

mercurial