/usr/lib/x86_64-linux-gnu/qt5/qml/Ubuntu/Components/Pickers/1.2/DialerHand.qml is in qml-module-ubuntu-components 1.3.1918+16.04.20160404-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | /*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.4
import Ubuntu.Components 1.2
/*!
\qmltype DialerHand
\inqmlmodule Ubuntu.Components.Pickers 1.0
\ingroup ubuntu-pickers
\brief DialerHand represents a value selector on a Dialer.
DialerHand components have meaning only if those are placed inside Dialer
components. The dialer hand presents a value selection from the given dialer's
minimum and maximum values.
By default all hands are placed on the dialer's hand space, on the outer dialer
disk. By default all hands have teh same size, 0.5GU width and height same as
the handSpace specified in \l Dialer, however themes can specify preset values
for each hand.
Hands can also be placed onto the inner disk by setting \a hand.toCenterItem
property to true.
\qml
Dialer {
DialerHand {
// this dialer hand will take the space as defined by the theme.
}
DialerHand {
hand.height: units.gu(3)
// this hand will have its width as defined by the theme
// but height as 3 GU
}
}
\endqml
Items declared as children will be placed over the hands. These items will not
be rotated togehther with the hand, these will always be shown horizontally.
The hand can be hidden by setting false to \a hand.visible property, but that
does not hide the overlay content.
The following example demonstrates how to create a hidden dialer hand having
an overlay component on the hand.
\qml
Dialer {
DialerHand {
id: selector
hand.visible: false
Rectangle {
anchors.centerIn: parent
width: height
height: units.gu(3)
radius: width / 2
color: Theme.palette.normal.background
antialiasing: true
Label {
text: Math.round(selector.value)
anchors.centerIn: parent
}
}
}
}
\endqml
*/
StyledItem {
id: dialerHand
/*!
The property holds the selected value the dialer hand points to.
*/
property real value
/*!
\qmlproperty real hand.width
\qmlproperty real hand.height
\qmlproperty bool hand.draggable
\qmlproperty bool hand.toCenterItem
\qmlproperty bool hand.visible
The \b hand.width and \b hand.height properties define the size of the hand.
The height of the hand must be in the [0..dialer.handSpace] range in order
to have the hand displayed in the hand area, however there is no restriction
applied on the size of the dialer hand. If no value is set, the width and
height will be defined by the style.
\b draggable property specifies whether the hand is draggable or not. When set to not draggable,
the hand is used only to indicate the given value. The default value is true.
\b toCenterItem property specifies whether the hand should be placed on the hand space (on the outer disk
- 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.
\b visible property specifies whether to show the hand marker or not. The default value is true.
*/
property DialerHandGroup hand: DialerHandGroup {
width: __styleInstance.handPreset(index, "width")
height: __styleInstance.handPreset(index, "height")
draggable: __styleInstance.handPreset(index, "draggable")
visible: __styleInstance.handPreset(index, "visible")
toCenterItem: __styleInstance.handPreset(index, "toCenterItem")
}
/*!
The property holds the dialer instance the hand is assigned to. This is a
helper property to enable access to the dialer component hosting the hand.
*/
readonly property Dialer dialer: parent
/*!
\qmlproperty list<QtObject> overlay
\default
The property holds the items that can be added on top of the hand. Note that
these items will not be rotated together with the hand pointer and pointer
visibility does not affect the overlay items visibility.
*/
default property alias overlay: contentItem.data
/*!
\qmlproperty int index
\readonly
The property holds the index of the hand. Note that this is not the child
index of the dialer children, this represents the index of the DialerHand
component added to the \l dialer.
*/
readonly property alias index: grabber.index
z: __styleInstance.handPreset(index, "z")
anchors.centerIn: parent
width: parent.width
height: parent.height
activeFocusOnPress: true
style: Theme.createStyleComponent("DialerHandStyle.qml", dialerHand)
/*! \internal */
onParentChanged: {
if (dialer && !dialer.hasOwnProperty("handSpace")) {
console.log("WARNING: DialerHand can be a child of Dialer only.");
}
}
/*! \internal */
onValueChanged: grabber.updateHand();
/*! \internal */
Component.onCompleted: grabber.updateHand();
/*! \internal */
property alias __grabber: grabber
Item {
id: grabber
property int index: -1
parent: __styleInstance.handPointer
width: units.gu(4)
height: parent.height
anchors {
top: parent.top
horizontalCenter: parent.horizontalCenter
}
Item {
id: contentItem
anchors.fill: parent
rotation: 360 - __styleInstance.rotation
}
function updateHand() {
if (!dialer || !__styleInstance) return;
__styleInstance.rotation =
MathUtils.projectValue(value,
dialer.minimumValue, dialer.maximumValue,
0.0, 360.0);
dialer.handUpdated(dialerHand);
}
MouseArea{
anchors.fill: parent;
preventStealing: true;
enabled: dialerHand.hand.draggable;
property real centerX : dialerHand.width / 2
property real centerY : dialerHand.height / 2
property bool internalChange: false
onPositionChanged: {
if (internalChange) return;
internalChange = true;
dialerHand.requestFocus(Qt.MouseFocusReason);
var point = mapToItem (dialerHand, mouse.x, mouse.y);
var diffX = (point.x - centerX);
var diffY = -1 * (point.y - centerY);
var rad = Math.atan (diffY / diffX);
var deg = (rad * 180 / Math.PI);
if (diffX > 0 && diffY > 0) {
__styleInstance.rotation = 90 - Math.abs (deg);
}
else if (diffX > 0 && diffY < 0) {
__styleInstance.rotation = 90 + Math.abs (deg);
}
else if (diffX < 0 && diffY > 0) {
__styleInstance.rotation = 270 + Math.abs (deg);
}
else if (diffX < 0 && diffY < 0) {
__styleInstance.rotation = 270 - Math.abs (deg);
}
dialerHand.value = MathUtils.projectValue(__styleInstance.rotation,
0.0, 360.0,
dialer.minimumValue, dialer.maximumValue);
internalChange = false;
}
}
}
}
|