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