2
* Copyright 2013 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
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 Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
\inqmlmodule Ubuntu.Components.Pickers 0.1
23
\ingroup ubuntu-pickers
24
\brief DialerHand represents a value selector on a Dialer.
26
DialerHand components have meaning only if those are placed inside Dialer
27
components. The dialer hand presents a value selection from the given dialer's
28
minimum and maximum values.
30
By default all hands are placed on the dialer's hand space, on the outer dialer
31
disk. By default all hands have teh same size, 0.5GU width and height same as
32
the handSpace specified in \l Dialer, however themes can specify preset values
35
Hands can also be placed onto the inner disk by setting \a hand.toCenterItem
41
// this dialer hand will take the space as defined by the theme.
44
hand.height: units.gu(3)
45
// this hand will have its width as defined by the theme
51
Items declared as children will be placed over the hands. These items will not
52
be rotated togehther with the hand, these will always be shown horizontally.
53
The hand can be hidden by setting false to \a hand.visible property, but that
54
does not hide the overlay content.
56
The following example demonstrates how to create a hidden dialer hand having
57
an overlay component on the hand.
64
anchors.centerIn: parent
68
color: Theme.palette.normal.background
71
text: Math.round(selector.value)
72
anchors.centerIn: parent
83
The property holds the selected value the dialer hand points to.
88
\qmlproperty real hand.width
89
\qmlproperty real hand.height
90
\qmlproperty bool hand.draggable
91
\qmlproperty bool hand.toCenterItem
92
\qmlproperty bool hand.visible
94
The \b hand.width and \b hand.height properties define the size of the hand.
95
The height of the hand must be in the [0..dialer.handSpace] range in order
96
to have the hand displayed in the hand area, however there is no restriction
97
applied on the size of the dialer hand. If no value is set, the width and
98
height will be defined by the style.
100
\b draggable property specifies whether the hand is draggable or not. When set to not draggable,
101
the hand is used only to indicate the given value. The default value is true.
103
\b toCenterItem property specifies whether the hand should be placed on the hand space (on the outer disk
104
- false) or onto the center disk (inner disk - true). The default value is false, meaning the hand will be placed onto the hand space disk.
106
\b visible property specifies whether to show the hand marker or not. The default value is true.
108
property DialerHandGroup hand: DialerHandGroup {
109
width: __styleInstance.handPreset(index, "width")
110
height: __styleInstance.handPreset(index, "height")
111
draggable: __styleInstance.handPreset(index, "draggable")
112
visible: __styleInstance.handPreset(index, "visible")
113
toCenterItem: __styleInstance.handPreset(index, "toCenterItem")
117
The property holds the dialer instance the hand is assigned to. This is a
118
helper property to enable access to the dialer component hosting the hand.
120
readonly property Dialer dialer: parent
123
\qmlproperty list<QtObject> overlay
125
The property holds the items that can be added on top of the hand. Note that
126
these items will not be rotated together with the hand pointer and pointer
127
visibility does not affect the overlay items visibility.
129
default property alias overlay: contentItem.data
132
\qmlproperty int index
134
The property holds the index of the hand. Note that this is not the child
135
index of the dialer children, this represents the index of the DialerHand
136
component added to the \l dialer.
138
readonly property alias index: grabber.index
140
z: __styleInstance.handPreset(index, "z")
141
anchors.centerIn: parent
143
height: parent.height
144
style: Theme.createStyleComponent("DialerHandStyle.qml", dialerHand)
148
if (dialer && !dialer.hasOwnProperty("handSpace")) {
149
console.log("WARNING: DialerHand can be a child of Dialer only.");
154
onValueChanged: grabber.updateHand();
156
Component.onCompleted: grabber.updateHand();
159
property alias __grabber: grabber
162
property int index: -1
163
parent: __styleInstance.handPointer
165
height: parent.height
168
horizontalCenter: parent.horizontalCenter
173
rotation: 360 - __styleInstance.rotation
176
function updateHand() {
177
if (!dialer || !__styleInstance) return;
178
__styleInstance.rotation =
179
MathUtils.projectValue(value,
180
dialer.minimumValue, dialer.maximumValue,
182
dialer.handUpdated(dialerHand);
186
anchors.fill: parent;
187
preventStealing: true;
188
enabled: dialerHand.hand.draggable;
189
property real centerX : dialerHand.width / 2
190
property real centerY : dialerHand.height / 2
191
property bool internalChange: false
194
if (internalChange) return;
195
internalChange = true;
196
var point = mapToItem (dialerHand, mouse.x, mouse.y);
197
var diffX = (point.x - centerX);
198
var diffY = -1 * (point.y - centerY);
199
var rad = Math.atan (diffY / diffX);
200
var deg = (rad * 180 / Math.PI);
202
if (diffX > 0 && diffY > 0) {
203
__styleInstance.rotation = 90 - Math.abs (deg);
205
else if (diffX > 0 && diffY < 0) {
206
__styleInstance.rotation = 90 + Math.abs (deg);
208
else if (diffX < 0 && diffY > 0) {
209
__styleInstance.rotation = 270 + Math.abs (deg);
211
else if (diffX < 0 && diffY < 0) {
212
__styleInstance.rotation = 270 - Math.abs (deg);
215
dialerHand.value = MathUtils.projectValue(__styleInstance.rotation,
217
dialer.minimumValue, dialer.maximumValue);
218
internalChange = false;