qml/Wecker.qml

Sun, 10 Jul 2011 10:49:24 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sun, 10 Jul 2011 10:49:24 +0200
changeset 12
1d13b7bae644
permissions
-rw-r--r--

Note consideration of name change to neater and cooler 'Pendule' d'echecs.

michael@3 1 //
michael@3 2 // Schachuhr - Chess clock graphical user interface client
michael@3 3 // Copyright © 2011 Michael Schloh von Bennewitz <michael@schloh.com>
michael@3 4 //
michael@3 5 // Schachuhr is free software: you can redistribute it and/or modify
michael@3 6 // it under the terms of the GNU General Public License as published
michael@3 7 // by the Free Software Foundation, either version 3 of the License,
michael@3 8 // or (at your option) any later version.
michael@3 9 //
michael@3 10 // Schachuhr is distributed in the hope that it will be useful,
michael@3 11 // but WITHOUT ANY WARRANTY; without even the implied warranty
michael@3 12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
michael@3 13 // the GNU General Public License for more details.
michael@3 14 //
michael@3 15 // You should have received a copy of the GNU General Public License
michael@3 16 // along with Schachuhr. If not, see <http://www.gnu.org/licenses/>.
michael@3 17 //
michael@3 18 // This file is part of project Schachuhr, a chess clock graphical
michael@3 19 // user interface client and is found at http://schachuhr.europalab.com/
michael@3 20 //
michael@3 21 // Wecker.qml: QML implementation
michael@3 22 //
michael@3 23
michael@3 24 import QtQuick 1.0
michael@3 25
michael@3 26 Item { // unsure if this should be a generic item
michael@3 27 id: wecker // or be rewritten as a QML component
michael@3 28 width: 365; height: 360 // roughly the size of a single clockface
michael@3 29
michael@3 30 property alias opponent: playName.text // opponent name
michael@3 31 property int hours // displayed hour hand
michael@3 32 property int minutes // displayed minute hand
michael@3 33 property int seconds // displayed second hand
michael@3 34 property real zeitfrist // opponent time allowance
michael@3 35 property bool altercolor: false // opponent clock colour choice
michael@3 36 property bool running: true // indicates wecker state
michael@3 37
michael@3 38 // called once when hands are initialized
michael@3 39 function timeInit() {
michael@3 40 seconds = 0
michael@3 41 minutes = 60 - zeitfrist % 60
michael@3 42 hours = 11 - zeitfrist / 60
michael@3 43 }
michael@3 44
michael@3 45 // called constantly as match progresses
michael@3 46 function timeChanged() {
michael@3 47 seconds = seconds + 1
michael@3 48 if (seconds % 60 == 0) {
michael@3 49 if (minutes == 59)
michael@3 50 hours++
michael@3 51 minutes++
michael@3 52 }
michael@3 53 }
michael@3 54
michael@3 55 // starts the timer of the next opponent,
michael@3 56 // and stops the timer of the current one
michael@3 57 // as well as indicating the running clock
michael@3 58 // using text color and clockface size
michael@3 59 function toggle() {
michael@3 60 if (wecker.state == "playing") {
michael@3 61 wecker.state = "waiting"
michael@3 62 timeLeft.running = false
michael@3 63 playName.color = "#A08050"
michael@3 64 playName.style = Text.Sunken
michael@3 65 }
michael@3 66 else {
michael@3 67 wecker.state = "playing"
michael@3 68 timeLeft.running = true
michael@3 69 playName.color = "white"
michael@3 70 playName.style = Text.Raised
michael@3 71 }
michael@3 72 }
michael@3 73
michael@3 74 // the match timer
michael@3 75 Timer {
michael@3 76 id: timeLeft
michael@3 77 interval: 1000; running: false; repeat: true; triggeredOnStart: true
michael@3 78 onTriggered: wecker.timeChanged()
michael@3 79 }
michael@3 80
michael@3 81 // a series of mutually exclusive clockface colours and sizes,
michael@3 82 // in which only one is used for each opponent at a given time
michael@3 83 Image { id: bgbraunlit; x: 50; y: 50; width: 320; height: 320; source: "clock-braun.png"; visible: wecker.altercolor == false && wecker.running == false }
michael@3 84 Image { id: bgbraunbig; width: 420; height: 420; source: "clock-brexp.png"; visible: wecker.altercolor == false && wecker.running == true }
michael@3 85 Image { id: bgbleuelit; x: 50; y: 50; width: 320; height: 320; source: "clock-bleu.png"; visible: wecker.altercolor == true && wecker.running == false }
michael@3 86 Image { id: bgbleuebig; width: 420; height: 420; source: "clock-blexp.png"; visible: wecker.altercolor == true && wecker.running == true }
michael@3 87
michael@3 88 // animated second hand is placed under the center graphic
michael@3 89 Image {
michael@3 90 x: 202; y: 80
michael@3 91 width: 15; height: 130
michael@3 92 source: "seconds.svg"
michael@3 93 smooth: true
michael@3 94 transform: Rotation {
michael@3 95 id: secondRotation
michael@3 96 origin.x: 7.5; origin.y: 130;
michael@3 97 angle: wecker.seconds * 6
michael@3 98 Behavior on angle {
michael@3 99 SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
michael@3 100 }
michael@3 101 }
michael@3 102 }
michael@3 103
michael@3 104 // the center graphic which covers or connects to various hands
michael@3 105 Image {
michael@3 106 width: 34; height: 34; anchors.centerIn: bgbraunbig; source: "centre.png"
michael@3 107 }
michael@3 108
michael@3 109 // animated hour hand is placed over the center graphic
michael@3 110 Image {
michael@3 111 x: 200; y: 130
michael@3 112 width: 20; height: 70
michael@3 113 source: "hourmin.svg"
michael@3 114 smooth: true
michael@3 115 transform: Rotation {
michael@3 116 id: hourRotation
michael@3 117 origin.x: 10; origin.y: 80;
michael@3 118 angle: (wecker.hours * 30) + (wecker.minutes * 0.5)
michael@3 119 Behavior on angle {
michael@3 120 SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
michael@3 121 }
michael@3 122 }
michael@3 123 }
michael@3 124
michael@3 125 // animated minute hand is placed over the center graphic
michael@3 126 Image {
michael@3 127 x: 202; y: 90
michael@3 128 width: 16; height: 110
michael@3 129 source: "hourmin.svg"
michael@3 130 smooth: true
michael@3 131 transform: Rotation {
michael@3 132 id: minuteRotation
michael@3 133 origin.x: 8; origin.y: 120;
michael@3 134 angle: wecker.minutes * 6
michael@3 135 Behavior on angle {
michael@3 136 SpringAnimation { spring: 2; damping: 0.2; modulus: 360 }
michael@3 137 }
michael@3 138 }
michael@3 139 }
michael@3 140
michael@3 141 // opponent name like 'Vladimir KRAMNIK',
michael@3 142 // is sunken and dimmed when not active
michael@3 143 // due to toggle function taking action
michael@3 144 Text {
michael@3 145 id: playName
michael@3 146 y: 400; anchors.horizontalCenter: bgbraunbig.horizontalCenter
michael@3 147 color: "white"
michael@3 148 font.bold: true; font.pixelSize: 54
michael@3 149 style: Text.Raised; styleColor: "black"
michael@3 150 }
michael@3 151
michael@3 152 // two state definitions, opponent take turns waiting or playing
michael@3 153 states: [
michael@3 154 State {
michael@3 155 name: "playing"
michael@3 156 PropertyChanges { target: wecker; running: true }
michael@3 157 },
michael@3 158 State {
michael@3 159 name: "waiting"
michael@3 160 PropertyChanges { target: wecker; running: false }
michael@3 161 }
michael@3 162 ]
michael@3 163 }

mercurial