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