Merge lp:~nik90/ubuntu-clock-app/timer-code-refactor into lp:ubuntu-clock-app/saucy
- timer-code-refactor
- Merge into saucy
Status: | Merged |
---|---|
Approved by: | Renato Araujo Oliveira Filho |
Approved revision: | 85 |
Merged at revision: | 71 |
Proposed branch: | lp:~nik90/ubuntu-clock-app/timer-code-refactor |
Merge into: | lp:ubuntu-clock-app/saucy |
Diff against target: |
1385 lines (+543/-647) 5 files modified
common/AnalogClockMarker.qml (+1/-1) timer/AnalogTimer.qml (+326/-0) timer/TimerLabelRow.qml (+94/-0) timer/TimerPage.qml (+110/-555) timer/TimerScript.js (+12/-91) |
To merge this branch: | bzr merge lp:~nik90/ubuntu-clock-app/timer-code-refactor |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Renato Araujo Oliveira Filho (community) | Approve | ||
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Ubuntu Clock Developers | Pending | ||
Review via email: mp+163409@code.launchpad.net |
Commit message
This commits achieves the following,
- moving the Analog Timer face into a new component.
- Fixes a qml storage bug which was accessing the hours, minutes and seconds unnecessarily.
- Fixes the AnalogClockMarker repeater issue (a really small issue fixed by adding a (-) minus sign :)
- Refactors code in the Timer component.
Description of the change
This MP achieves the following,
- moving the Analog Timer face into a new component.
- Fixes a qml storage bug which was accessing the hours, minutes and seconds unnecessarily.
- Fixes the AnalogClockMarker repeater issue (a really small issue fixed by adding a (-) minus sign :)
- Refactors code in the Timer component.
Nekhelesh Ramananthan (nik90) wrote : | # |
Nekhelesh Ramananthan (nik90) wrote : | # |
The AnalogTimer now takes the function of keeping track of time, controlling the timer and drawing the main analog timer face.
The TimerPage deals with timer presets, drawing ui for the buttons (start, stop, reset, done)
This is all very similar to the stopwatch code refactor we did.
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
Why are you using a if here if you have the same code for both states?
- onItemRemoved: if (backgroundTime
1009 + onItemRemoved: if (swipeDelete.state == "SwipingRight") {
1010 storageTimer.
1011 TScript.
1012 } else {
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
I would suggest to move this function to the timerpage, and rename it to something more easy to understand, like
setTime / updateTime / ...
1081 +function calculateTime ( sec ) {
1082 + var time = sec
1083 + timerPage.seconds = time % 60
1084 + time = Math.floor(time / 60)
1085 + timerPage.minutes = time % 60
1086 + timerPage.hours = Math.floor(time / 60)
1087 }
Nekhelesh Ramananthan (nik90) wrote : | # |
At the moment, swiping right and left perform the same action which is to delete a saved timer preset.
However the intention was to make it such that swipe left to edit a preset and swipe right to delete a preset. However the code infrastructure to edit a preset has not been implemented.
You are right. I will remove the if loops but will include a TODO comment there to change the behaviour later.
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
> I would suggest to move this function to the timerpage, and rename it to
> something more easy to understand, like
> setTime / updateTime / ...
>
> 1081 +function calculateTime ( sec ) {
> 1082 + var time = sec
> 1083 + timerPage.seconds = time % 60
> 1084 + time = Math.floor(time / 60)
> 1085 + timerPage.minutes = time % 60
> 1086 + timerPage.hours = Math.floor(time / 60)
> 1087 }
Maybe is better if you move to AnalogTimer element, since the properties on timerPage is just a alias.
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
Do you think that is possible to create a separated element for the timer label?
// Timer label hh:mm:ss
Row {
id: topTimerRow
Try move this to a new element and export properties that will be possible to control it from the TimerPage.
Nekhelesh Ramananthan (nik90) wrote : | # |
>Maybe is better if you move to AnalogTimer element, since the properties on timerPage is just a alias.
Done. I moved it the AnalogTimer file.
> Why are you using a if here if you have the same code for both states?
> - onItemRemoved: if (backgroundTime
> 1009 + onItemRemoved: if (swipeDelete.state == "SwipingRight") {
> 1010 storageTimer.
> 1011 TScript.
> 1012 } else {
Code removed. Added a TODO to change the behavior based on the swipe direction.
> I would suggest to move this function to the timerpage, and rename it to something more easy to understand, > like setTime / updateTime / ...
Done.
> Do you think that is possible to create a separated element for the timer label?
> // Timer label hh:mm:ss
> Row {
> id: topTimerRow
> Try move this to a new element and export properties that will be possible to control it from the TimerPage.
I think this would be difficult. I tried doing it, however I noticed some issues while implementing it. For instance, the topTimerRow needs to modify the timerHand.rotation property of AnalogTimer. When I tried doing from the topTimerRow file, it did not update visually for some reason. I will give this a shot again tomorrow morning.
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:85
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Nekhelesh Ramananthan (nik90) wrote : | # |
> Do you think that is possible to create a separated element for the timer label?
> // Timer label hh:mm:ss
> Row {
> id: topTimerRow
> Try move this to a new element and export properties that will be possible to control it from the TimerPage.
Done.
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
this function totalTime:
1059 storageTimer.
Does not return the same value as:
does not return the same value as:
465 + property alias totalTime: analogTimer.
Nekhelesh Ramananthan (nik90) wrote : | # |
> this function totalTime:
>
> 1059 storageTimer.
> TScript.
>
> Does not return the same value as:
>
> does not return the same value as:
>
> 465 + property alias totalTime: analogTimer.
The analogTimer.
So storageTimer.
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
great work.
Preview Diff
1 | === modified file 'common/AnalogClockMarker.qml' |
2 | --- common/AnalogClockMarker.qml 2013-05-09 20:12:52 +0000 |
3 | +++ common/AnalogClockMarker.qml 2013-05-12 14:25:31 +0000 |
4 | @@ -49,7 +49,7 @@ |
5 | |
6 | transform: Translate { |
7 | x: parent.width * distance * Math.sin(radAngle) |
8 | - y: parent.height * distance * Math.cos(radAngle) |
9 | + y: -parent.height * distance * Math.cos(radAngle) |
10 | } |
11 | |
12 | } |
13 | |
14 | === added file 'timer/AnalogTimer.qml' |
15 | --- timer/AnalogTimer.qml 1970-01-01 00:00:00 +0000 |
16 | +++ timer/AnalogTimer.qml 2013-05-12 14:25:31 +0000 |
17 | @@ -0,0 +1,326 @@ |
18 | +/* |
19 | + * Copyright (C) 2013 Canonical Ltd |
20 | + * |
21 | + * This program is free software: you can redistribute it and/or modify |
22 | + * it under the terms of the GNU General Public License version 3 as |
23 | + * published by the Free Software Foundation. |
24 | + * |
25 | + * This program is distributed in the hope that it will be useful, |
26 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
27 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
28 | + * GNU General Public License for more details. |
29 | + * |
30 | + * You should have received a copy of the GNU General Public License |
31 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
32 | + * |
33 | + * Authored by: Nekhelesh Ramananthan <krnekhelesh@gmail.com> |
34 | + */ |
35 | + |
36 | +import QtQuick 2.0 |
37 | +import Ubuntu.Components 0.1 |
38 | +import "../common" |
39 | +import "../common/Constants.js" as Constants |
40 | + |
41 | +// Component which draws the analog timer face. |
42 | +AnalogFaceBase { |
43 | + id: clockOuterCircle |
44 | + |
45 | + // Properties to store/set the time variables |
46 | + property int seconds: 0; |
47 | + property int minutes: 0; |
48 | + property int hours: 0; |
49 | + property int totalTime: 0; |
50 | + property int timerValue: 0; |
51 | + |
52 | + // Property to activate/deactivate the timer |
53 | + property bool timerOn: false; |
54 | + |
55 | + // Properties to get/set the timer hand properties |
56 | + property alias timerHandColor: timerHand.colortop; |
57 | + property alias timerHandRotation: timerHand.rotationAngle; |
58 | + |
59 | + // Properties to set/determine the input focus |
60 | + property bool secondsFlag |
61 | + property bool minutesFlag |
62 | + property bool hoursFlag |
63 | + property bool inProgressFlag |
64 | + |
65 | + onTotalTimeChanged: { |
66 | + if (totalTime < 0) { |
67 | + timerOn = false; |
68 | + } |
69 | + else { |
70 | + setTime(totalTime); |
71 | + } |
72 | + } |
73 | + |
74 | + // Timer function called by the main clock loop |
75 | + function onTimerUpdate () { |
76 | + if( timerOn ) { |
77 | + totalTime--; |
78 | + timerHand.rotationAngle = seconds * 6; |
79 | + } |
80 | + } |
81 | + |
82 | + // Function to calculate the hours, minutes and seconds from the total time |
83 | + function setTime ( sec ) { |
84 | + var time = sec |
85 | + seconds = time % 60 |
86 | + time = Math.floor(time / 60) |
87 | + minutes = time % 60 |
88 | + hours = Math.floor(time / 60) |
89 | + } |
90 | + |
91 | + // Function to disable timer and reset time |
92 | + function reset() { |
93 | + timerOn = false; |
94 | + hours = minutes = seconds = totalTime = timerValue = timerHand.rotationAngle = 0; |
95 | + } |
96 | + |
97 | + AnalogHand { |
98 | + id: timerHand |
99 | + |
100 | + widthhand: units.gu(2); heighthand: units.gu(16); heighttop: units.gu(5) |
101 | + rotationAngle: seconds * 6 |
102 | + colorhand: Constants.brightWhite |
103 | + colortop: Constants.ubuntuOrange |
104 | + } |
105 | + |
106 | + Rectangle { |
107 | + id: secondsCircle |
108 | + |
109 | + width: units.gu(5); height: units.gu(5) |
110 | + radius: width / 2 |
111 | + anchors.centerIn: parent |
112 | + color: Constants.brightWhite |
113 | + antialiasing: true |
114 | + z: parent.z + 100 |
115 | + } |
116 | + |
117 | + Repeater { |
118 | + model: ["0", "15", "30", "45"] |
119 | + delegate: AnalogClockMarker { |
120 | + number: modelData |
121 | + distance: 0.60 |
122 | + textDisplay: true |
123 | + } |
124 | + } |
125 | + |
126 | + Repeater { |
127 | + model: 12 |
128 | + delegate: AnalogClockMarker { |
129 | + number: index |
130 | + size: 0.5 |
131 | + distance: 0.55 |
132 | + color: Constants.pitchBlack |
133 | + } |
134 | + } |
135 | + |
136 | + // Implements touch support |
137 | + MouseArea { |
138 | + id: timerbackmousearea |
139 | + |
140 | + property real truex: mouseX - clockOuterCircle.width/2 |
141 | + property real truey: clockOuterCircle.height/2 - mouseY |
142 | + property real angle: Math.atan2(truex, truey) |
143 | + property real strictangle: parseInt(angle * 180 / Math.PI) |
144 | + property real modulo: strictangle % 6 |
145 | + property int seconds_up_flag: 0 |
146 | + property int seconds_down_flag: 0 |
147 | + property int minutes_up_flag: 0 |
148 | + property int minutes_down_flag: 0 |
149 | + property int temp_seconds: 0 |
150 | + property int temp_minutes: 0 |
151 | + |
152 | + enabled: !inProgressFlag |
153 | + anchors.fill: parent |
154 | + preventStealing: true |
155 | + |
156 | + onPositionChanged: if (timerbackmousearea.angle < 0) { |
157 | + timerHand.rotationAngle = strictangle - modulo + 360; |
158 | + timerValue = parseInt(timerHand.rotationAngle/6); |
159 | + |
160 | + if (secondsFlag) { |
161 | + seconds = timerValue; |
162 | + |
163 | + // FIXME: This whole code section below should be implemented in a more logical fashion. |
164 | + if (seconds == 0) { |
165 | + if (temp_seconds - seconds > 58) { |
166 | + // increasing minutes |
167 | + seconds_up_flag = 1 |
168 | + temp_seconds = 0 |
169 | + } |
170 | + else if (temp_seconds - seconds > 0) { |
171 | + // decreasing minutes |
172 | + seconds_down_flag = 1 |
173 | + temp_seconds = 0 |
174 | + } |
175 | + else {} |
176 | + |
177 | + if (seconds_up_flag == 1) { |
178 | + if (minutes == 59) { |
179 | + hours += 1 |
180 | + minutes = 0 |
181 | + } |
182 | + else { |
183 | + minutes += 1 |
184 | + } |
185 | + seconds_up_flag = 0; |
186 | + } |
187 | + } |
188 | + |
189 | + if (seconds == 1) { |
190 | + temp_seconds = seconds |
191 | + } |
192 | + |
193 | + if (seconds == 59) { |
194 | + temp_seconds = seconds |
195 | + if (seconds_down_flag == 1) { |
196 | + if (minutes == 0) { |
197 | + minutes = 59 |
198 | + hours -= 1 |
199 | + } |
200 | + else { |
201 | + minutes -= 1 |
202 | + } |
203 | + seconds_down_flag = 0; |
204 | + } |
205 | + } |
206 | + |
207 | + |
208 | + } |
209 | + |
210 | + if (minutesFlag) { |
211 | + minutes = timerValue; |
212 | + |
213 | + if (minutes == 0) { |
214 | + if (temp_minutes - minutes > 58) { |
215 | + // increasing hours |
216 | + minutes_up_flag = 1 |
217 | + temp_minutes = 0 |
218 | + } |
219 | + else if (temp_minutes - minutes > 0) { |
220 | + // decreasing hours |
221 | + minutes_down_flag = 1 |
222 | + temp_minutes = 0 |
223 | + } |
224 | + else {} |
225 | + |
226 | + if (minutes_up_flag == 1 && hours != 59) { |
227 | + hours += 1 |
228 | + minutes_up_flag = 0; |
229 | + } |
230 | + } |
231 | + |
232 | + if (minutes == 1) { |
233 | + temp_minutes = minutes |
234 | + } |
235 | + |
236 | + if (minutes == 59) { |
237 | + temp_minutes = minutes |
238 | + if (minutes_down_flag == 1 && hours != 0) { |
239 | + hours -= 1 |
240 | + minutes_down_flag = 0; |
241 | + } |
242 | + } |
243 | + } |
244 | + |
245 | + if (hoursFlag) { |
246 | + hours = timerValue; |
247 | + } |
248 | + } |
249 | + else { |
250 | + timerHand.rotationAngle = strictangle - modulo + 6; |
251 | + timerValue = parseInt(timerHand.rotationAngle/6); |
252 | + |
253 | + if (secondsFlag) { |
254 | + seconds = timerValue; |
255 | + |
256 | + if (seconds == 0) { |
257 | + if (temp_seconds - seconds > 58) { |
258 | + // increasing minutes |
259 | + seconds_up_flag = 1 |
260 | + temp_seconds = 0 |
261 | + } |
262 | + else if (temp_seconds - seconds > 0) { |
263 | + // decreasing minutes |
264 | + seconds_down_flag = 1 |
265 | + temp_seconds = 0 |
266 | + } |
267 | + else {} |
268 | + |
269 | + if (seconds_up_flag == 1) { |
270 | + if (minutes == 59) { |
271 | + hours += 1 |
272 | + minutes = 0 |
273 | + } |
274 | + else { |
275 | + minutes += 1 |
276 | + } |
277 | + seconds_up_flag = 0; |
278 | + } |
279 | + } |
280 | + |
281 | + if (seconds == 1) { |
282 | + temp_seconds = seconds |
283 | + } |
284 | + |
285 | + if (seconds == 59) { |
286 | + temp_seconds = seconds |
287 | + if (seconds_down_flag == 1) { |
288 | + if (minutes == 0) { |
289 | + minutes = 59 |
290 | + hours -= 1 |
291 | + } |
292 | + else { |
293 | + minutes -= 1 |
294 | + } |
295 | + seconds_down_flag = 0; |
296 | + } |
297 | + } |
298 | + |
299 | + |
300 | + } |
301 | + |
302 | + if (minutesFlag) { |
303 | + minutes = timerValue; |
304 | + |
305 | + if (minutes == 0) { |
306 | + if (temp_minutes - minutes > 58) { |
307 | + // increasing hours |
308 | + minutes_up_flag = 1 |
309 | + temp_minutes = 0 |
310 | + } |
311 | + else if (temp_minutes - minutes > 0) { |
312 | + // decreasing hours |
313 | + minutes_down_flag = 1 |
314 | + temp_minutes = 0 |
315 | + } |
316 | + else {} |
317 | + |
318 | + if (minutes_up_flag == 1 && hours != 59) { |
319 | + hours += 1 |
320 | + minutes_up_flag = 0; |
321 | + } |
322 | + } |
323 | + |
324 | + if (minutes == 1) { |
325 | + temp_minutes = minutes |
326 | + } |
327 | + |
328 | + if (minutes == 59) { |
329 | + temp_minutes = minutes |
330 | + if (minutes_down_flag == 1 && hours != 0) { |
331 | + hours -= 1 |
332 | + minutes_down_flag = 0; |
333 | + } |
334 | + } |
335 | + } |
336 | + |
337 | + if (hoursFlag) { |
338 | + hours = timerValue; |
339 | + } |
340 | + } |
341 | + } |
342 | +} |
343 | + |
344 | |
345 | === renamed file 'timer/BackgroundTimer.qml' => 'timer/SwipeDelete.qml' |
346 | === added file 'timer/TimerLabelRow.qml' |
347 | --- timer/TimerLabelRow.qml 1970-01-01 00:00:00 +0000 |
348 | +++ timer/TimerLabelRow.qml 2013-05-12 14:25:31 +0000 |
349 | @@ -0,0 +1,94 @@ |
350 | +import QtQuick 2.0 |
351 | +import Ubuntu.Components 0.1 |
352 | +import "../common" |
353 | +import "../common/Constants.js" as Constants |
354 | + |
355 | +Row { |
356 | + id: topTimerRow |
357 | + |
358 | + // Properties to set the timer labels and input focus (using flags) |
359 | + property alias hoursLabel: hourslabelTimer.text; |
360 | + property alias minutesLabel: minuteslabelTimer.text; |
361 | + property alias secondsLabel: secondslabelTimer.text; |
362 | + property alias hoursLabelFlag: hourslabelTimer.flag; |
363 | + property alias minutesLabelFlag: minuteslabelTimer.flag; |
364 | + property alias secondsLabelFlag: secondslabelTimer.flag; |
365 | + |
366 | + // Properties to retrieve the status of the timer and the timer page |
367 | + property bool timerOn; |
368 | + property string viewState; |
369 | + |
370 | + spacing: units.gu(0.3) |
371 | + anchors { |
372 | + horizontalCenter: parent.horizontalCenter |
373 | + top: parent.top |
374 | + topMargin: units.gu(6) |
375 | + } |
376 | + |
377 | + Label { |
378 | + id: hourslabelTimer |
379 | + |
380 | + // flag boolean variable to determine if the timer hand adjusts the hours or not |
381 | + property bool flag: false |
382 | + |
383 | + fontSize: "x-large" |
384 | + color: flag && !timerOn ? Constants.ubuntuOrange : Constants.darkGrey |
385 | + visible: hours > 0 ? true : false |
386 | + |
387 | + MouseArea { |
388 | + anchors.fill: parent |
389 | + enabled: !timerOn && viewState != "SAVEDPRESETS" |
390 | + onClicked: topTimerRow.state = "FOCUS-HOR" |
391 | + } |
392 | + } |
393 | + |
394 | + Label { |
395 | + id: colonTimer1 |
396 | + |
397 | + color: Constants.darkGrey |
398 | + visible: hourslabelTimer.visible ? true : false |
399 | + fontSize: "x-large" |
400 | + text: i18n.tr(":") |
401 | + } |
402 | + |
403 | + Label { |
404 | + id: minuteslabelTimer |
405 | + |
406 | + // flag boolean variable to determine if the timer hand adjusts the minutes or not |
407 | + property bool flag: false |
408 | + |
409 | + fontSize: "x-large" |
410 | + color: flag && !timerOn ? Constants.ubuntuOrange : Constants.darkGrey |
411 | + |
412 | + MouseArea { |
413 | + anchors.fill: parent |
414 | + enabled: !timerOn && viewState != "SAVEDPRESETS" |
415 | + onClicked: topTimerRow.state = "FOCUS-MIN" |
416 | + } |
417 | + } |
418 | + |
419 | + Label { |
420 | + id: colonTimer2 |
421 | + |
422 | + color: Constants.darkGrey |
423 | + fontSize: "x-large" |
424 | + |
425 | + text: i18n.tr(":") |
426 | + } |
427 | + |
428 | + Label { |
429 | + id: secondslabelTimer |
430 | + |
431 | + // flag boolean variable to determine if the timer hand adjusts the minutes or not |
432 | + property bool flag: true |
433 | + |
434 | + fontSize: "x-large" |
435 | + color: flag && !timerOn ? Constants.ubuntuOrange : Constants.darkGrey |
436 | + |
437 | + MouseArea { |
438 | + anchors.fill: parent |
439 | + enabled: !timerOn && viewState != "SAVEDPRESETS" |
440 | + onClicked: topTimerRow.state = "FOCUS-SEC" |
441 | + } |
442 | + } |
443 | +} |
444 | |
445 | === modified file 'timer/TimerPage.qml' |
446 | --- timer/TimerPage.qml 2013-05-04 23:47:04 +0000 |
447 | +++ timer/TimerPage.qml 2013-05-12 14:25:31 +0000 |
448 | @@ -28,16 +28,29 @@ |
449 | Page { |
450 | id: timerPage |
451 | |
452 | - property bool timerOn: false; |
453 | - property int seconds: 0; |
454 | - property int minutes: 0; |
455 | - property int hours: 0; |
456 | - property int totalTime: 0; |
457 | - property int timerValue: 0; |
458 | property int lastindex: -1; |
459 | property string selectItemPreset: ""; |
460 | property string viewState: "TIMER" |
461 | |
462 | + property alias hours: analogTimer.hours; |
463 | + property alias minutes: analogTimer.minutes; |
464 | + property alias seconds: analogTimer.seconds; |
465 | + property alias totalTime: analogTimer.totalTime; |
466 | + property alias timerValue: analogTimer.timerValue; |
467 | + property alias timerOn: analogTimer.timerOn; |
468 | + |
469 | + function onTimerUpdate() { |
470 | + analogTimer.onTimerUpdate(); |
471 | + } |
472 | + |
473 | + function reset() { |
474 | + analogTimer.reset(); |
475 | + topTimerRow.state = "FOCUS-SEC" |
476 | + namePreset.text = ""; |
477 | + } |
478 | + |
479 | + onViewStateChanged: topTimerRow.viewState = viewState; |
480 | + |
481 | Component.onCompleted: { |
482 | Utils.log("TimerPage loaded"); |
483 | } |
484 | @@ -46,519 +59,65 @@ |
485 | id: storageTimer |
486 | } |
487 | |
488 | - // Timer function called by the main clock loop |
489 | - function onTimerUpdate () { |
490 | - if(timerOn == true) { |
491 | - TScript.countDown() |
492 | - timerHand.rotationAngle = seconds * 6; |
493 | - } |
494 | - } |
495 | - |
496 | anchors.margins: units.gu(2) |
497 | |
498 | - Rectangle { |
499 | - id: timerSwipeArea |
500 | - |
501 | - // It may be necessary to fine tune this value to tweak the swipe experience |
502 | - // until it works to our liking |
503 | - property int swipeLength: 20; |
504 | - |
505 | - width:timerPage.width; height:timerPage.height/4; |
506 | - anchors.bottom: timerPage.bottom |
507 | - color: "transparent" |
508 | - |
509 | - MouseArea { |
510 | - anchors.fill: timerSwipeArea |
511 | - property int yStart: 0 |
512 | - |
513 | - onPressed: { |
514 | - yStart = mouseY |
515 | - } |
516 | - |
517 | - onReleased: { |
518 | - // Swipe up condition |
519 | - if (yStart - mouseY > timerSwipeArea.swipeLength) { |
520 | - TScript.showTimerPage(false); |
521 | - TScript.showAddPresetPage(false); |
522 | - TScript.showViewPresetPage(true); |
523 | - TScript.populatePreset(); |
524 | - |
525 | - addPreset.visible = true; |
526 | - editPreset.visible = false; |
527 | - deletePreset.visible = true; |
528 | - |
529 | - toolbarTimer.back.visible = true; |
530 | - toolbarTimer.locked = false; |
531 | - toolbarTimer.opened = false; |
532 | - } |
533 | - |
534 | - // Swipe down condition |
535 | - if (yStart - mouseY < -timerSwipeArea.swipeLength) { |
536 | - TScript.showAddPresetPage(false); |
537 | - TScript.showViewPresetPage(false); |
538 | - |
539 | - if(!timerOn) { |
540 | - TScript.resetAll() |
541 | - } |
542 | - |
543 | - TScript.showTimerPage(true); |
544 | - } |
545 | - } |
546 | - } |
547 | - } |
548 | - |
549 | // Timer label hh:mm:ss |
550 | - Row { |
551 | + TimerLabelRow { |
552 | id: topTimerRow |
553 | |
554 | - spacing: units.gu(0.3) |
555 | - anchors { |
556 | - horizontalCenter: parent.horizontalCenter |
557 | - top: parent.top |
558 | - topMargin: units.gu(6) |
559 | - } |
560 | - |
561 | - Label { |
562 | - id: hourslabelTimer |
563 | - |
564 | - // flag boolean variable to determine if the timer hand adjusts the hours or not |
565 | - property bool flag: false |
566 | - |
567 | - color: Constants.darkGrey |
568 | - fontSize: "x-large" |
569 | - text: i18n.tr("00") |
570 | - visible: { |
571 | - if (hours > 0) { |
572 | - true |
573 | - } |
574 | - else { |
575 | - false |
576 | - } |
577 | - } |
578 | - |
579 | - MouseArea { |
580 | - anchors.fill: parent |
581 | - |
582 | - onClicked: { |
583 | - if (!timerOn && viewState != "SAVEDPRESETS") { |
584 | - timerHand.rotationAngle = hours * 6; |
585 | - hourslabelTimer.color = Constants.ubuntuOrange; |
586 | - hourslabelTimer.flag = true; |
587 | - secondslabelTimer.color = Constants.darkGrey; |
588 | - secondslabelTimer.flag = false; |
589 | - minuteslabelTimer.color = Constants.darkGrey; |
590 | - minuteslabelTimer.flag = false; |
591 | - } |
592 | - } |
593 | - } |
594 | - } |
595 | - |
596 | - Label { |
597 | - id: colonTimer1 |
598 | - |
599 | - color: Constants.darkGrey |
600 | - visible: { |
601 | - if (hourslabelTimer.visible) { |
602 | - true |
603 | - } |
604 | - else { |
605 | - false |
606 | - } |
607 | - } |
608 | - fontSize: "x-large" |
609 | - |
610 | - text: i18n.tr(":") |
611 | - } |
612 | - |
613 | - Label { |
614 | - id: minuteslabelTimer |
615 | - |
616 | - // flag boolean variable to determine if the timer hand adjusts the minutes or not |
617 | - property bool flag: false |
618 | - |
619 | - color: Constants.darkGrey |
620 | - fontSize: "x-large" |
621 | - |
622 | - text: i18n.tr("00") |
623 | - |
624 | - MouseArea { |
625 | - anchors.fill: parent |
626 | - |
627 | - onClicked: { |
628 | - if (!timerOn && viewState != "SAVEDPRESETS") { |
629 | - timerHand.rotationAngle = minutes * 6; |
630 | - minuteslabelTimer.color = Constants.ubuntuOrange; |
631 | - minuteslabelTimer.flag = true; |
632 | - secondslabelTimer.color = Constants.darkGrey; |
633 | - secondslabelTimer.flag = false; |
634 | - hourslabelTimer.color = Constants.darkGrey; |
635 | - hourslabelTimer.flag = false; |
636 | - } |
637 | - } |
638 | - } |
639 | - } |
640 | - |
641 | - Label { |
642 | - id: colonTimer2 |
643 | - |
644 | - color: Constants.darkGrey |
645 | - fontSize: "x-large" |
646 | - |
647 | - text: i18n.tr(":") |
648 | - } |
649 | - |
650 | - Label { |
651 | - id: secondslabelTimer |
652 | - |
653 | - // flag boolean variable to determine if the timer hand adjusts the minutes or not |
654 | - property bool flag: true |
655 | - |
656 | - color: Constants.ubuntuOrange; |
657 | - fontSize: "x-large" |
658 | - |
659 | - text: i18n.tr("00") |
660 | - |
661 | - MouseArea { |
662 | - anchors.fill: parent |
663 | - |
664 | - onClicked: { |
665 | - if (!timerOn && viewState != "SAVEDPRESETS") { |
666 | - timerHand.rotationAngle = seconds * 6; |
667 | - secondslabelTimer.color = Constants.ubuntuOrange; |
668 | - secondslabelTimer.flag = true; |
669 | - minuteslabelTimer.color = Constants.darkGrey; |
670 | - minuteslabelTimer.flag = false; |
671 | - hourslabelTimer.color = Constants.darkGrey; |
672 | - hourslabelTimer.flag = false; |
673 | - } |
674 | - } |
675 | - } |
676 | - } |
677 | + timerOn: analogTimer.timerOn; |
678 | + viewState: timerPage.viewState; |
679 | + hoursLabel: Utils.zeroleft(hours, 2); |
680 | + minutesLabel: Utils.zeroleft(minutes, 2); |
681 | + secondsLabel: Utils.zeroleft(seconds, 2); |
682 | + |
683 | + states:[ |
684 | + State { |
685 | + name: "FOCUS-SEC" |
686 | + PropertyChanges { target: topTimerRow; secondsLabelFlag: true } |
687 | + PropertyChanges { target: topTimerRow; minutesLabelFlag: false } |
688 | + PropertyChanges { target: topTimerRow; hoursLabelFlag: false } |
689 | + PropertyChanges { target: analogTimer; timerHandRotation: seconds * 6 } |
690 | + }, |
691 | + |
692 | + State { |
693 | + name: "FOCUS-MIN" |
694 | + PropertyChanges { target: topTimerRow; secondsLabelFlag: false } |
695 | + PropertyChanges { target: topTimerRow; minutesLabelFlag: true } |
696 | + PropertyChanges { target: topTimerRow; hoursLabelFlag: false } |
697 | + PropertyChanges { target: analogTimer; timerHandRotation: minutes * 6 } |
698 | + }, |
699 | + |
700 | + State { |
701 | + name: "FOCUS-HOR" |
702 | + PropertyChanges { target: topTimerRow; secondsLabelFlag: false } |
703 | + PropertyChanges { target: topTimerRow; minutesLabelFlag: false } |
704 | + PropertyChanges { target: topTimerRow; hoursLabelFlag: true } |
705 | + PropertyChanges { target: analogTimer; timerHandRotation: hours * 6 } |
706 | + }, |
707 | + |
708 | + State { |
709 | + name: "DISABLED" |
710 | + when: timerOn == true || viewState == "SAVEDPRESETS" || buttonTimer.state == "DONE" |
711 | + PropertyChanges { target: topTimerRow; secondsLabelFlag: false } |
712 | + PropertyChanges { target: topTimerRow; minutesLabelFlag: false } |
713 | + PropertyChanges { target: topTimerRow; hoursLabelFlag: false } |
714 | + } |
715 | + ] |
716 | } |
717 | |
718 | - AnalogFaceBase { |
719 | - id: clockOuterCircle |
720 | - |
721 | - AnalogHand { |
722 | - id: timerHand |
723 | - |
724 | - widthhand: units.gu(2); heighthand: units.gu(16); heighttop: units.gu(5) |
725 | - rotationAngle: seconds * 6 |
726 | - colorhand: Constants.brightWhite |
727 | - colortop: Constants.ubuntuOrange |
728 | - } |
729 | - |
730 | - Rectangle { |
731 | - id: secondsCircle |
732 | - |
733 | - width: units.gu(5); height: units.gu(5) |
734 | - radius: width / 2 |
735 | - anchors.centerIn: parent |
736 | - color: Constants.brightWhite |
737 | - antialiasing: true |
738 | - z: parent.z + 100 |
739 | - } |
740 | - |
741 | - // Add analog clock texts 0,15,30 and 45. Ready for translation to other languages if necessary |
742 | - Label { |
743 | - id: point0 |
744 | - |
745 | - anchors { |
746 | - horizontalCenter: clockOuterCircle.horizontalCenter |
747 | - bottom: clockOuterCircle.top |
748 | - bottomMargin: 20 |
749 | - } |
750 | - |
751 | - fontSize: "medium" |
752 | - text: i18n.tr("0") |
753 | - } |
754 | - |
755 | - Label { |
756 | - id: point15 |
757 | - |
758 | - anchors { |
759 | - verticalCenter: clockOuterCircle.verticalCenter |
760 | - left: clockOuterCircle.right |
761 | - leftMargin: 20 |
762 | - } |
763 | - |
764 | - fontSize: "medium" |
765 | - text: i18n.tr("15") |
766 | - } |
767 | - |
768 | - Label { |
769 | - id: point30 |
770 | - |
771 | - anchors { |
772 | - horizontalCenter: clockOuterCircle.horizontalCenter |
773 | - top: clockOuterCircle.bottom |
774 | - topMargin: 20 |
775 | - } |
776 | - |
777 | - fontSize: "medium" |
778 | - text: i18n.tr("30") |
779 | - } |
780 | - |
781 | - Label { |
782 | - id: point45 |
783 | - |
784 | - anchors { |
785 | - verticalCenter: clockOuterCircle.verticalCenter |
786 | - right: clockOuterCircle.left |
787 | - rightMargin: 20 |
788 | - } |
789 | - |
790 | - fontSize: "medium" |
791 | - text: i18n.tr("45") |
792 | - } |
793 | - |
794 | - Repeater { |
795 | - model: 12 |
796 | - delegate: AnalogClockMarker { |
797 | - number: index |
798 | - size: 0.5 |
799 | - distance: 0.55 |
800 | - color: Constants.pitchBlack |
801 | - } |
802 | - } |
803 | - |
804 | - // Implements touch support |
805 | - MouseArea { |
806 | - id: timerbackmousearea |
807 | - |
808 | - property real truex: mouseX - clockOuterCircle.width/2 |
809 | - property real truey: clockOuterCircle.height/2 - mouseY |
810 | - property real angle: Math.atan2(truex, truey) |
811 | - property real strictangle: parseInt(angle * 180 / Math.PI) |
812 | - property real modulo: strictangle % 6 |
813 | - property int seconds_up_flag: 0 |
814 | - property int seconds_down_flag: 0 |
815 | - property int minutes_up_flag: 0 |
816 | - property int minutes_down_flag: 0 |
817 | - property int temp_seconds: 0 |
818 | - property int temp_minutes: 0 |
819 | - |
820 | - enabled: !timerOn |
821 | - |
822 | - anchors.fill: parent |
823 | - preventStealing: true // move only Timer hand and ensures that the sideway motion of pages do not interrupt moving the clock hand |
824 | - onPositionChanged: if (buttonTimer.state != "STOP" && buttonTimer.state != "DONE") { |
825 | - if (timerbackmousearea.angle < 0) { |
826 | - timerHand.rotationAngle = strictangle - modulo + 360; |
827 | - timerValue = parseInt(timerHand.rotationAngle/6); |
828 | - |
829 | - if (secondslabelTimer.flag) { |
830 | - secondslabelTimer.text = Utils.zeroleft(timerValue, 2); |
831 | - seconds = timerValue; |
832 | - |
833 | - if (seconds == 0) { |
834 | - if (temp_seconds - seconds > 58) { |
835 | - // increasing minutes |
836 | - seconds_up_flag = 1 |
837 | - temp_seconds = 0 |
838 | - } |
839 | - else if (temp_seconds - seconds > 0) { |
840 | - // decreasing minutes |
841 | - seconds_down_flag = 1 |
842 | - temp_seconds = 0 |
843 | - } |
844 | - else {} |
845 | - |
846 | - if (seconds_up_flag == 1) { |
847 | - if (minutes == 59) { |
848 | - hours += 1 |
849 | - hourslabelTimer.text = Utils.zeroleft(hours, 2); |
850 | - minutes = 0 |
851 | - } |
852 | - else { |
853 | - minutes += 1 |
854 | - } |
855 | - minuteslabelTimer.text = Utils.zeroleft(minutes, 2); |
856 | - seconds_up_flag = 0; |
857 | - } |
858 | - } |
859 | - |
860 | - if (seconds == 1) { |
861 | - temp_seconds = seconds |
862 | - } |
863 | - |
864 | - if (seconds == 59) { |
865 | - temp_seconds = seconds |
866 | - if (seconds_down_flag == 1) { |
867 | - if (minutes == 0) { |
868 | - minutes = 59 |
869 | - hours -= 1 |
870 | - hourslabelTimer.text = Utils.zeroleft(hours, 2); |
871 | - } |
872 | - else { |
873 | - minutes -= 1 |
874 | - } |
875 | - minuteslabelTimer.text = Utils.zeroleft(minutes, 2); |
876 | - seconds_down_flag = 0; |
877 | - } |
878 | - } |
879 | - |
880 | - |
881 | - } |
882 | - |
883 | - if (minuteslabelTimer.flag) { |
884 | - minuteslabelTimer.text = Utils.zeroleft(timerValue, 2); |
885 | - minutes = timerValue; |
886 | - |
887 | - if (minutes == 0) { |
888 | - if (temp_minutes - minutes > 58) { |
889 | - // increasing hours |
890 | - minutes_up_flag = 1 |
891 | - temp_minutes = 0 |
892 | - } |
893 | - else if (temp_minutes - minutes > 0) { |
894 | - // decreasing hours |
895 | - minutes_down_flag = 1 |
896 | - temp_minutes = 0 |
897 | - } |
898 | - else {} |
899 | - |
900 | - if (minutes_up_flag == 1 && hours != 59) { |
901 | - hours += 1 |
902 | - hourslabelTimer.text = Utils.zeroleft(hours, 2); |
903 | - minutes_up_flag = 0; |
904 | - } |
905 | - } |
906 | - |
907 | - if (minutes == 1) { |
908 | - temp_minutes = minutes |
909 | - } |
910 | - |
911 | - if (minutes == 59) { |
912 | - temp_minutes = minutes |
913 | - if (minutes_down_flag == 1 && hours != 0) { |
914 | - hours -= 1 |
915 | - hourslabelTimer.text = Utils.zeroleft(hours, 2); |
916 | - minutes_down_flag = 0; |
917 | - } |
918 | - } |
919 | - } |
920 | - |
921 | - if (hourslabelTimer.flag) { |
922 | - hourslabelTimer.text = Utils.zeroleft(timerValue, 2); |
923 | - hours = timerValue; |
924 | - } |
925 | - |
926 | - if(secondslabelTimer.text != "00" || minuteslabelTimer.text != "00" || hourslabelTimer.text != "00") { |
927 | - buttonTimer.state = "START"; |
928 | - } else { |
929 | - buttonTimer.state = "PRESETS"; |
930 | - } |
931 | - } |
932 | - else { |
933 | - timerHand.rotationAngle = strictangle - modulo + 6; |
934 | - timerValue = parseInt(timerHand.rotationAngle/6); |
935 | - |
936 | - if (secondslabelTimer.flag) { |
937 | - secondslabelTimer.text = Utils.zeroleft(timerValue, 2); |
938 | - seconds = timerValue; |
939 | - |
940 | - if (seconds == 0) { |
941 | - if (temp_seconds - seconds > 58) { |
942 | - // increasing minutes |
943 | - seconds_up_flag = 1 |
944 | - temp_seconds = 0 |
945 | - } |
946 | - else if (temp_seconds - seconds > 0) { |
947 | - // decreasing minutes |
948 | - seconds_down_flag = 1 |
949 | - temp_seconds = 0 |
950 | - } |
951 | - else {} |
952 | - |
953 | - if (seconds_up_flag == 1) { |
954 | - if (minutes == 59) { |
955 | - hours += 1 |
956 | - hourslabelTimer.text = Utils.zeroleft(hours, 2); |
957 | - minutes = 0 |
958 | - } |
959 | - else { |
960 | - minutes += 1 |
961 | - } |
962 | - minuteslabelTimer.text = Utils.zeroleft(minutes, 2); |
963 | - seconds_up_flag = 0; |
964 | - } |
965 | - } |
966 | - |
967 | - if (seconds == 1) { |
968 | - temp_seconds = seconds |
969 | - } |
970 | - |
971 | - if (seconds == 59) { |
972 | - temp_seconds = seconds |
973 | - if (seconds_down_flag == 1) { |
974 | - if (minutes == 0) { |
975 | - minutes = 59 |
976 | - hours -= 1 |
977 | - hourslabelTimer.text = Utils.zeroleft(hours, 2); |
978 | - } |
979 | - else { |
980 | - minutes -= 1 |
981 | - } |
982 | - minuteslabelTimer.text = Utils.zeroleft(minutes, 2); |
983 | - seconds_down_flag = 0; |
984 | - } |
985 | - } |
986 | - |
987 | - |
988 | - } |
989 | - |
990 | - if (minuteslabelTimer.flag) { |
991 | - minuteslabelTimer.text = Utils.zeroleft(timerValue, 2); |
992 | - minutes = timerValue; |
993 | - |
994 | - if (minutes == 0) { |
995 | - if (temp_minutes - minutes > 58) { |
996 | - // increasing hours |
997 | - minutes_up_flag = 1 |
998 | - temp_minutes = 0 |
999 | - } |
1000 | - else if (temp_minutes - minutes > 0) { |
1001 | - // decreasing hours |
1002 | - minutes_down_flag = 1 |
1003 | - temp_minutes = 0 |
1004 | - } |
1005 | - else {} |
1006 | - |
1007 | - if (minutes_up_flag == 1 && hours != 59) { |
1008 | - hours += 1 |
1009 | - hourslabelTimer.text = Utils.zeroleft(hours, 2); |
1010 | - minutes_up_flag = 0; |
1011 | - } |
1012 | - } |
1013 | - |
1014 | - if (minutes == 1) { |
1015 | - temp_minutes = minutes |
1016 | - } |
1017 | - |
1018 | - if (minutes == 59) { |
1019 | - temp_minutes = minutes |
1020 | - if (minutes_down_flag == 1 && hours != 0) { |
1021 | - hours -= 1 |
1022 | - hourslabelTimer.text = Utils.zeroleft(hours, 2); |
1023 | - minutes_down_flag = 0; |
1024 | - } |
1025 | - } |
1026 | - } |
1027 | - |
1028 | - if (hourslabelTimer.flag) { |
1029 | - hourslabelTimer.text = Utils.zeroleft(timerValue, 2); |
1030 | - hours = timerValue; |
1031 | - } |
1032 | - |
1033 | - if(secondslabelTimer.text != "00" || minuteslabelTimer.text != "00" || hourslabelTimer.text != "00") { |
1034 | - buttonTimer.state = "START"; |
1035 | - } else { |
1036 | - buttonTimer.state = "PRESETS"; |
1037 | - } |
1038 | - } |
1039 | - } |
1040 | - } |
1041 | + AnalogTimer { |
1042 | + id: analogTimer |
1043 | + |
1044 | + secondsFlag: topTimerRow.secondsLabelFlag; |
1045 | + minutesFlag: topTimerRow.minutesLabelFlag; |
1046 | + hoursFlag: topTimerRow.hoursLabelFlag; |
1047 | + inProgressFlag: (timerOn == true || buttonTimer.state == "DONE") ? true : false; |
1048 | + |
1049 | + onHoursChanged: topTimerRow.hoursLabel = Utils.zeroleft(hours, 2); |
1050 | + onMinutesChanged: topTimerRow.minutesLabel = Utils.zeroleft(minutes, 2); |
1051 | + onSecondsChanged: topTimerRow.secondsLabel = Utils.zeroleft(seconds, 2); |
1052 | + onTimerOnChanged: topTimerRow.timerOn = timerOn; |
1053 | } |
1054 | |
1055 | // Add preset done circle which is shown when the add preset toolbar button is pressed |
1056 | @@ -588,7 +147,7 @@ |
1057 | onClicked: { |
1058 | if (namePreset.text != "" && (hours > 0 || minutes > 0 || seconds > 0)) { |
1059 | storageTimer.setTimerValue(namePreset.text, TScript.totalSeconds(hours, minutes, seconds)); |
1060 | - TScript.resetAll(); |
1061 | + reset(); |
1062 | TScript.showAddPresetPage(false) |
1063 | TScript.showTimerPage(true) |
1064 | } |
1065 | @@ -613,41 +172,44 @@ |
1066 | states:[ |
1067 | State { |
1068 | name: "PRESETS" |
1069 | + when: (totalTime == "0" && timerOn == false && text != "Done") |
1070 | PropertyChanges { target: buttonTimer; color: Constants.brightWhite; text: i18n.tr("Presets") } |
1071 | - PropertyChanges { target: timerHand; colortop: Constants.ubuntuOrange } |
1072 | - PropertyChanges { target: clockOuterCircle; glowColor: Constants.analogClockFaceGlowColor } |
1073 | + PropertyChanges { target: analogTimer; timerHandColor: Constants.ubuntuOrange } |
1074 | + PropertyChanges { target: analogTimer; glowColor: Constants.analogClockFaceGlowColor } |
1075 | }, |
1076 | |
1077 | State { |
1078 | name: "START" |
1079 | + when: ((seconds != "0" || minutes != "0" || hours != "0") && timerOn == false) |
1080 | PropertyChanges { target: buttonTimer; color: Constants.ubuntuOrange; text: i18n.tr("Start") } |
1081 | - PropertyChanges { target: timerHand; colortop: Constants.ubuntuOrange } |
1082 | - PropertyChanges { target: clockOuterCircle; glowColor: Constants.analogClockFaceGlowColor } |
1083 | + PropertyChanges { target: analogTimer; timerHandColor: Constants.ubuntuOrange } |
1084 | + PropertyChanges { target: analogTimer; glowColor: Constants.analogClockFaceGlowColor } |
1085 | }, |
1086 | |
1087 | State { |
1088 | name: "STOP" |
1089 | PropertyChanges { target: buttonTimer; color: Constants.darkGrey; text: i18n.tr("Stop") } |
1090 | - PropertyChanges { target: timerHand; colortop: Constants.ubuntuOrange } |
1091 | - PropertyChanges { target: clockOuterCircle; glowColor: Constants.analogClockFaceGlowColor } |
1092 | + PropertyChanges { target: analogTimer; timerHandColor: Constants.ubuntuOrange } |
1093 | + PropertyChanges { target: analogTimer; glowColor: Constants.analogClockFaceGlowColor } |
1094 | }, |
1095 | |
1096 | State { |
1097 | name: "DONE" |
1098 | + when: (totalTime == "-1" && timerOn == false) |
1099 | PropertyChanges { target: buttonTimer; color: Constants.green; text: i18n.tr("Done") } |
1100 | - PropertyChanges { target: timerHand; colortop: Constants.green } |
1101 | - PropertyChanges { target: clockOuterCircle; glowColor: Constants.analogClockFaceGlowColorTimerDown } |
1102 | + PropertyChanges { target: analogTimer; timerHandColor: Constants.green } |
1103 | + PropertyChanges { target: analogTimer; glowColor: Constants.analogClockFaceGlowColorTimerDown } |
1104 | } |
1105 | ] |
1106 | |
1107 | onClicked: { |
1108 | switch (text) { |
1109 | case "Presets": |
1110 | - if (timerPage.viewState == "TIMER") { |
1111 | - TScript.resetAll(); |
1112 | + if (viewState == "TIMER") { |
1113 | + reset(); |
1114 | TScript.showTimerPage(false); |
1115 | + TScript.populatePreset(); |
1116 | TScript.showViewPresetPage(true); |
1117 | - TScript.populatePreset(); |
1118 | |
1119 | addPreset.visible = true; |
1120 | editPreset.visible = false; |
1121 | @@ -661,44 +223,41 @@ |
1122 | TScript.showViewPresetPage(false); |
1123 | |
1124 | if (!timerOn) { |
1125 | - TScript.resetAll(); |
1126 | + reset(); |
1127 | } |
1128 | |
1129 | TScript.showTimerPage(true); |
1130 | } |
1131 | - |
1132 | break; |
1133 | + |
1134 | case "Start": |
1135 | - TScript.prepareStartTimer(); |
1136 | - if (totalTime > 0) { |
1137 | - timerPage.timerOn = true; |
1138 | - state = "STOP"; |
1139 | - } |
1140 | + totalTime = TScript.totalSeconds(hours, minutes, seconds); |
1141 | + timerOn = true; |
1142 | + state = "STOP"; |
1143 | |
1144 | - if (timerPage.viewState == "SAVEDPRESETS") { |
1145 | + if (viewState == "SAVEDPRESETS") { |
1146 | TScript.showViewPresetPage(false); |
1147 | TScript.showTimerPage(true); |
1148 | } |
1149 | - |
1150 | break; |
1151 | + |
1152 | case "Stop": |
1153 | - timerPage.timerOn = false; |
1154 | + timerOn = false; |
1155 | state = "PRESETS"; |
1156 | - TScript.resetAll(); |
1157 | + reset(); |
1158 | |
1159 | - if (timerPage.viewState == "SAVEDPRESETS") { |
1160 | + if (viewState == "SAVEDPRESETS") { |
1161 | TScript.showViewPresetPage(true) |
1162 | } |
1163 | - |
1164 | break; |
1165 | + |
1166 | case "Done": |
1167 | state = "PRESETS"; |
1168 | - TScript.resetAll(); |
1169 | + reset(); |
1170 | |
1171 | - if (timerPage.viewState == "SAVEDPRESETS") { |
1172 | + if (viewState == "SAVEDPRESETS") { |
1173 | TScript.showViewPresetPage(true) |
1174 | } |
1175 | - |
1176 | break; |
1177 | } |
1178 | } |
1179 | @@ -736,23 +295,21 @@ |
1180 | selected: select |
1181 | removable: true |
1182 | |
1183 | - backgroundIndicator: BackgroundTimer { |
1184 | - id: backgroundTimer |
1185 | + backgroundIndicator: SwipeDelete { |
1186 | + id: swipeDelete |
1187 | state: swipingState |
1188 | } |
1189 | |
1190 | - onItemRemoved: if (backgroundTimer.state == "SwipingRight") { |
1191 | - storageTimer.delTimerValue(text); |
1192 | - TScript.populatePreset(); |
1193 | - } else { |
1194 | - storageTimer.delTimerValue(text); |
1195 | - TScript.populatePreset(); |
1196 | - } |
1197 | + // TODO: Implement different based actions based on the swipe direction. |
1198 | + onItemRemoved: { |
1199 | + storageTimer.delTimerValue(text); |
1200 | + TScript.populatePreset(); |
1201 | + } |
1202 | |
1203 | onClicked: { |
1204 | if (!timerOn) { |
1205 | buttonTimer.state = "START"; |
1206 | - TScript.setlabelTimer(secondstimer); |
1207 | + analogTimer.setTime(secondstimer); |
1208 | if (lastindex == -1) { |
1209 | listModel.setProperty(index, "select", true) |
1210 | lastindex = index; |
1211 | @@ -800,7 +357,7 @@ |
1212 | text: i18n.tr("Add Preset") |
1213 | |
1214 | onTriggered: { |
1215 | - TScript.resetAll() |
1216 | + reset() |
1217 | TScript.showTimerPage(false); |
1218 | TScript.showViewPresetPage(false); |
1219 | TScript.showAddPresetPage(true); |
1220 | @@ -851,8 +408,7 @@ |
1221 | storageTimer.delTimerValue(selectItemPreset); |
1222 | TScript.populatePreset(); |
1223 | } |
1224 | - TScript.resetAll(); |
1225 | - TScript.showViewPresetPage(true); |
1226 | + analogTimer.reset(); |
1227 | } |
1228 | } |
1229 | } |
1230 | @@ -866,10 +422,9 @@ |
1231 | TScript.showTimerPage(true); |
1232 | |
1233 | if (!timerOn) { |
1234 | - TScript.resetAll(); |
1235 | + reset(); |
1236 | } |
1237 | } |
1238 | } |
1239 | } |
1240 | } |
1241 | - |
1242 | |
1243 | === modified file 'timer/TimerScript.js' |
1244 | --- timer/TimerScript.js 2013-04-28 13:07:23 +0000 |
1245 | +++ timer/TimerScript.js 2013-05-12 14:25:31 +0000 |
1246 | @@ -20,102 +20,26 @@ |
1247 | Qt.include("../common/ClockUtils.js") |
1248 | Qt.include("../common/Constants.js") |
1249 | |
1250 | -// Function to calculate the hours, minutes and seconds from the total time |
1251 | -function setlabelTimer ( sec ) { |
1252 | - var hor = parseInt(sec / 3600); |
1253 | - var change = sec - (hor * 3600); |
1254 | - var min = parseInt(change / 60); |
1255 | - change = change - (min * 60); |
1256 | - |
1257 | - timerPage.hours = hor; |
1258 | - timerPage.minutes = min; |
1259 | - timerPage.seconds = change; |
1260 | - |
1261 | - hourslabelTimer.text = zeroleft(hor, 2); |
1262 | - minuteslabelTimer.text = zeroleft(min, 2); |
1263 | - secondslabelTimer.text = zeroleft(change, 2); |
1264 | -} |
1265 | - |
1266 | -// Countdown timer function |
1267 | -function countDown () { |
1268 | - if (timerPage.totalTime > 0) { |
1269 | - timerPage.totalTime--; |
1270 | - setlabelTimer(timerPage.totalTime); |
1271 | - } else { |
1272 | - buttonTimer.state = "DONE"; |
1273 | - timerPage.timerOn = false; |
1274 | - } |
1275 | -} |
1276 | - |
1277 | // Function to return total seconds. |
1278 | function totalSeconds ( hou, min, sec ) { |
1279 | - var totalsec = (hou * 60 * 60) + (min * 60) + sec; |
1280 | - return totalsec; |
1281 | + return( (hou * 60 * 60) + (min * 60) + sec ); |
1282 | } |
1283 | |
1284 | // Function to calculate the hours, minutes and seconds from the total time |
1285 | -function getstringTimer ( sec ) { |
1286 | - var stringTimer; |
1287 | - var hor = parseInt(sec / 3600); |
1288 | - var change = sec - (hor * 3600); |
1289 | - var min = parseInt(change / 60); |
1290 | - change = change - (min * 60); |
1291 | - |
1292 | - timerPage.hours = hor; |
1293 | - timerPage.minutes = min; |
1294 | - timerPage.seconds = change; |
1295 | - |
1296 | - stringTimer = zeroleft(hor, 2) + ':' + zeroleft(min, 2) + ':' + zeroleft(change, 2); |
1297 | - |
1298 | - return stringTimer |
1299 | -} |
1300 | - |
1301 | -// Function to adjust timer properties before starting timer. |
1302 | -function prepareStartTimer () { |
1303 | - timerPage.totalTime = totalSeconds(timerPage.hours, timerPage.minutes, timerPage.seconds); |
1304 | - |
1305 | - secondslabelTimer.color = Constants.pitchBlack |
1306 | - minuteslabelTimer.color = Constants.pitchBlack |
1307 | - hourslabelTimer.color = Constants.pitchBlack |
1308 | - |
1309 | - colonTimer1.color = Constants.pitchBlack |
1310 | - colonTimer2.color = Constants.pitchBlack |
1311 | -} |
1312 | - |
1313 | -// Restore timer to its original state |
1314 | -function resetAll () { |
1315 | - hourslabelTimer.text = "00"; |
1316 | - hourslabelTimer.color = darkGrey; |
1317 | - hourslabelTimer.flag = false; |
1318 | - |
1319 | - minuteslabelTimer.text = "00"; |
1320 | - minuteslabelTimer.color = darkGrey; |
1321 | - minuteslabelTimer.flag = false; |
1322 | - |
1323 | - secondslabelTimer.text = "00"; |
1324 | - secondslabelTimer.color = ubuntuOrange; |
1325 | - secondslabelTimer.flag = true; |
1326 | - |
1327 | - colonTimer1.color = darkGrey; |
1328 | - colonTimer2.color = darkGrey; |
1329 | - |
1330 | - timerPage.hours = 0; |
1331 | - timerPage.minutes = 0; |
1332 | - timerPage.seconds = 0; |
1333 | - timerPage.totalTime = 0; |
1334 | - timerPage.timerValue = 0; |
1335 | - |
1336 | - timerPage.timerOn = false; |
1337 | - timerHand.rotationAngle = 0; |
1338 | - buttonTimer.state = "PRESETS"; |
1339 | - |
1340 | - namePreset.text = ""; |
1341 | +function getstringTimer ( seconds ) { |
1342 | + var time = seconds |
1343 | + var sec = time % 60 |
1344 | + time = Math.floor(time / 60) |
1345 | + var min = time % 60 |
1346 | + var hor = Math.floor(time / 60) |
1347 | + return Utils.hmsToString(hor, min, sec); |
1348 | } |
1349 | |
1350 | // Show/Hide Timer Page |
1351 | function showTimerPage ( mode ) { |
1352 | - clockOuterCircle.visible = mode; |
1353 | + analogTimer.visible = mode; |
1354 | |
1355 | + // TODO: Remove these anchor changes once the flickable is implemented. |
1356 | if (mode) { |
1357 | timerPage.viewState = "TIMER"; |
1358 | buttonTimer.visible = true |
1359 | @@ -134,7 +58,7 @@ |
1360 | |
1361 | // Show/Hide Add Preset Page |
1362 | function showAddPresetPage ( mode ) { |
1363 | - clockOuterCircle.visible = mode; |
1364 | + analogTimer.visible = mode; |
1365 | addPresetCircleDone.visible = mode; |
1366 | namePreset.visible = mode; |
1367 | buttonTimer.visible = !mode |
1368 | @@ -148,16 +72,13 @@ |
1369 | function showViewPresetPage ( mode ) { |
1370 | listPreset.visible = mode; |
1371 | |
1372 | + //TODO: These anchors changes should be removed once a flickable is used. |
1373 | if (mode) { |
1374 | timerPage.viewState = "SAVEDPRESETS"; |
1375 | buttonTimer.visible = true |
1376 | buttonTimer.anchors.bottom = topTimerRow.bottom; |
1377 | buttonTimer.anchors.bottomMargin = -units.gu(10); |
1378 | } |
1379 | - |
1380 | - if (mode == true && !timerOn) { |
1381 | - secondslabelTimer.color = darkGrey; |
1382 | - } |
1383 | } |
1384 | |
1385 | // Call Workerscript to populate the preset list |
@Renato, Please ignore the whole noodle code mess (from line 137 to 315) in the AnalogTimer.qml file. A better logic for that code is required which will be addressed in a later MP.
This MP solely deals with,
- moving the Analog Timer face into a new component.
- Fixes a qml storage bug which was accessing the hours, minutes and seconds unnecessarily.
- Fixes the AnalogClockMarker repeater issue (a really small issue fixed by adding a (-) minus sign :)
- Refactors code in the Timer component.