~mpredotka/ubuntu-clock-app/fix-1272628

« back to all changes in this revision

Viewing changes to timer/AnalogTimer.qml

  • Committer: Tarmac
  • Author(s): Nekhelesh Ramananthan
  • Date: 2014-01-10 14:22:15 UTC
  • mfrom: (281.1.22 dialer)
  • Revision ID: tarmac-20140110142215-2c7r1cn1q5g0ewmz
Transitions the clock app to use the SDK Dialer widget. Fixes: https://bugs.launchpad.net/bugs/1266945.

Approved by Ubuntu Phone Apps Jenkins Bot, Michael Zanetti.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 Canonical Ltd
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License version 3 as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authored by: Nekhelesh Ramananthan <krnekhelesh@gmail.com>
17
 
 */
18
 
 
19
 
import QtQuick 2.0
20
 
import Ubuntu.Components 0.1
21
 
import "../common"
22
 
 
23
 
// Component which draws the analog timer face.
24
 
AnalogFaceBase {
25
 
    id: clockOuterCircle
26
 
 
27
 
    property var startTime: 0;
28
 
    property var remTime: 0;
29
 
 
30
 
    // Properties to store/set the time variables
31
 
    property int seconds: 0;
32
 
    property int minutes: 0;    
33
 
    property int totalTime: 0;
34
 
    property int pauseTime: 0;
35
 
 
36
 
    // Property to activate/deactivate the timer
37
 
    property bool timerOn: false;
38
 
    property bool inProgressFlag
39
 
 
40
 
    // Timer function called by the main clock loop
41
 
    function onTimerUpdate () {
42
 
        if( timerOn ) {
43
 
            inProgressFlag = true;
44
 
            remTime = totalTime - Math.floor((new Date() - startTime)/ 1000) - pauseTime;
45
 
 
46
 
            if (remTime < 0) {
47
 
                timerOn = false
48
 
                totalTime = -1;
49
 
            } else {
50
 
                ssToTime(remTime);
51
 
            }
52
 
        }
53
 
    }
54
 
 
55
 
    // Function to convert time (in seconds) to hh:mm:ss format
56
 
    function ssToTime(time) {
57
 
        seconds = time % 60
58
 
        time = Math.floor(time / 60)
59
 
        minutes = time % 60        
60
 
        secondHand.rotationValue = seconds * 6;
61
 
        minuteHand.rotationValue = minutes * 6;        
62
 
    }
63
 
 
64
 
    // Function to disable timer and reset time
65
 
    Timer {
66
 
        id: reset_timer
67
 
 
68
 
        interval: 200
69
 
        repeat: false
70
 
        onTriggered: {
71
 
            inProgressFlag = true;
72
 
            minuteHand.rotationValue = secondHand.rotationValue = 0;
73
 
            inProgressFlag = false;
74
 
        }
75
 
    }
76
 
 
77
 
    function reset() {
78
 
        reset_timer.start();
79
 
        timerOn = false;
80
 
        state = "";
81
 
        startTime = remTime = pauseTime = 0;
82
 
        minutes = seconds = totalTime = 0;
83
 
        minuteHand.timerValue = secondHand.timerValue = 0;
84
 
    }
85
 
 
86
 
    Repeater {
87
 
        model: 12
88
 
        delegate: AnalogClockMarker {
89
 
            number: index
90
 
            size: 0.5
91
 
            distance: 0.48            
92
 
        }
93
 
    }
94
 
 
95
 
    // Minute hand with touch/mouse drag support
96
 
    AnalogTouchHand {
97
 
        id: minuteHand
98
 
        objectName: "minuteHand"
99
 
 
100
 
        onTimerValueChanged: minutes = timerValue;
101
 
 
102
 
        handHeight: units.gu(14.5); handWidth: units.gu(0.5);
103
 
        animateFlag: inProgressFlag;
104
 
        enabled: !inProgressFlag;
105
 
        grabMargin: units.gu(0)
106
 
        grabHeight: units.gu(7)
107
 
    }
108
 
 
109
 
    // Second hand with touch/mouse drag support
110
 
    AnalogTouchHand {
111
 
        id: secondHand
112
 
 
113
 
        onTimerValueChanged: seconds = timerValue;
114
 
 
115
 
        handHeight: units.gu(17); handWidth: units.gu(0.5);
116
 
        z: parent.z - 1;
117
 
        animateFlag: inProgressFlag;
118
 
        enabled: !inProgressFlag;
119
 
        grabMargin: -units.gu(2)
120
 
    }
121
 
}