diff -r 57bc4d78e5cd -r c5c9ba04c01a qml/Wecker.qml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qml/Wecker.qml Fri Jul 08 22:41:48 2011 +0200 @@ -0,0 +1,163 @@ +// +// Schachuhr - Chess clock graphical user interface client +// Copyright © 2011 Michael Schloh von Bennewitz +// +// Schachuhr is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published +// by the Free Software Foundation, either version 3 of the License, +// or (at your option) any later version. +// +// Schachuhr is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +// the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Schachuhr. If not, see . +// +// This file is part of project Schachuhr, a chess clock graphical +// user interface client and is found at http://schachuhr.europalab.com/ +// +// Wecker.qml: QML implementation +// + +import QtQuick 1.0 + +Item { // unsure if this should be a generic item + id: wecker // or be rewritten as a QML component + width: 365; height: 360 // roughly the size of a single clockface + + property alias opponent: playName.text // opponent name + property int hours // displayed hour hand + property int minutes // displayed minute hand + property int seconds // displayed second hand + property real zeitfrist // opponent time allowance + property bool altercolor: false // opponent clock colour choice + property bool running: true // indicates wecker state + + // called once when hands are initialized + function timeInit() { + seconds = 0 + minutes = 60 - zeitfrist % 60 + hours = 11 - zeitfrist / 60 + } + + // called constantly as match progresses + function timeChanged() { + seconds = seconds + 1 + if (seconds % 60 == 0) { + if (minutes == 59) + hours++ + minutes++ + } + } + + // starts the timer of the next opponent, + // and stops the timer of the current one + // as well as indicating the running clock + // using text color and clockface size + function toggle() { + if (wecker.state == "playing") { + wecker.state = "waiting" + timeLeft.running = false + playName.color = "#A08050" + playName.style = Text.Sunken + } + else { + wecker.state = "playing" + timeLeft.running = true + playName.color = "white" + playName.style = Text.Raised + } + } + + // the match timer + Timer { + id: timeLeft + interval: 1000; running: false; repeat: true; triggeredOnStart: true + onTriggered: wecker.timeChanged() + } + + // a series of mutually exclusive clockface colours and sizes, + // in which only one is used for each opponent at a given time + Image { id: bgbraunlit; x: 50; y: 50; width: 320; height: 320; source: "clock-braun.png"; visible: wecker.altercolor == false && wecker.running == false } + Image { id: bgbraunbig; width: 420; height: 420; source: "clock-brexp.png"; visible: wecker.altercolor == false && wecker.running == true } + Image { id: bgbleuelit; x: 50; y: 50; width: 320; height: 320; source: "clock-bleu.png"; visible: wecker.altercolor == true && wecker.running == false } + Image { id: bgbleuebig; width: 420; height: 420; source: "clock-blexp.png"; visible: wecker.altercolor == true && wecker.running == true } + + // animated second hand is placed under the center graphic + Image { + x: 202; y: 80 + width: 15; height: 130 + source: "seconds.svg" + smooth: true + transform: Rotation { + id: secondRotation + origin.x: 7.5; origin.y: 130; + angle: wecker.seconds * 6 + Behavior on angle { + SpringAnimation { spring: 2; damping: 0.2; modulus: 360 } + } + } + } + + // the center graphic which covers or connects to various hands + Image { + width: 34; height: 34; anchors.centerIn: bgbraunbig; source: "centre.png" + } + + // animated hour hand is placed over the center graphic + Image { + x: 200; y: 130 + width: 20; height: 70 + source: "hourmin.svg" + smooth: true + transform: Rotation { + id: hourRotation + origin.x: 10; origin.y: 80; + angle: (wecker.hours * 30) + (wecker.minutes * 0.5) + Behavior on angle { + SpringAnimation { spring: 2; damping: 0.2; modulus: 360 } + } + } + } + + // animated minute hand is placed over the center graphic + Image { + x: 202; y: 90 + width: 16; height: 110 + source: "hourmin.svg" + smooth: true + transform: Rotation { + id: minuteRotation + origin.x: 8; origin.y: 120; + angle: wecker.minutes * 6 + Behavior on angle { + SpringAnimation { spring: 2; damping: 0.2; modulus: 360 } + } + } + } + + // opponent name like 'Vladimir KRAMNIK', + // is sunken and dimmed when not active + // due to toggle function taking action + Text { + id: playName + y: 400; anchors.horizontalCenter: bgbraunbig.horizontalCenter + color: "white" + font.bold: true; font.pixelSize: 54 + style: Text.Raised; styleColor: "black" + } + + // two state definitions, opponent take turns waiting or playing + states: [ + State { + name: "playing" + PropertyChanges { target: wecker; running: true } + }, + State { + name: "waiting" + PropertyChanges { target: wecker; running: false } + } + ] +}