2
* Copyright (C) 2013 Canonical Ltd
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.
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.
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/>.
16
* Authored by: Nekhelesh Ramananthan <krnekhelesh@gmail.com>
20
import Ubuntu.Components 0.1
23
// Qml item to enable touch input to the AnalogClockHand component
28
width: parent.width; height: width;
29
anchors.centerIn: parent;
32
Enable/Disable rotation animation. Disable it while dragging the clock hand to avoid
33
receiving inaccurate input values.
35
property alias animateFlag: hand.handRotationAnimation
38
Set if the dial should be rotated by the seconds, minutes or hours. This generally needs to be
39
multiplied by 6 to convert it into degrees per second/hour/minute.
41
property alias rotationValue: hand.rotation;
43
// Set the touch/mouse grab area height and top margin
44
property alias grabHeight: grabArea.height;
45
property int grabMargin: units.gu(0);
47
// Height and width of the clock hand
48
property alias handHeight: hand.handHeight;
49
property alias handWidth: hand.handWidth;
51
// internal properties required for the functioning of the AnalogTouchHand
52
property int timerValue: 0
53
property real centerX : width / 2
54
property real centerY : height / 2
56
// Clock hand which lies above the rotating dial. This is stationary w.r.t to the rotating dial.
60
handHeight: units.gu(0); handWidth: units.gu(0);
63
Element to define the grab area of the clock hand. This allows us to define small clock hand
64
which are still easier to grab.
69
width: units.gu(5); height: width;
70
anchors { top: hand.top; topMargin: touchHand.grabMargin; horizontalCenter: hand.horizontalCenter }
74
anchors.fill: grabArea;
75
preventStealing: true;
78
var point = mapToItem (touchHand, mouse.x, mouse.y);
79
var diffX = (point.x - touchHand.centerX);
80
var diffY = -1 * (point.y - touchHand.centerY);
81
var rad = Math.atan (diffY / diffX);
82
var deg = (rad * 180 / Math.PI);
84
if (diffX > 0 && diffY > 0) {
85
hand.rotation = 90 - Math.abs (deg);
87
else if (diffX > 0 && diffY < 0) {
88
hand.rotation = 90 + Math.abs (deg);
90
else if (diffX < 0 && diffY > 0) {
91
hand.rotation = 270 + Math.abs (deg);
93
else if (diffX < 0 && diffY < 0) {
94
hand.rotation = 270 - Math.abs (deg);
97
if (Math.round(hand.rotation/6) === 60) {
98
touchHand.timerValue = 0
100
touchHand.timerValue = Math.round(hand.rotation/6);