/usr/share/unity8/Components/DragHandle.qml is in unity8-common 8.12+16.04.20160401-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 | /*
* Copyright (C) 2013 Canonical, Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.4
import Ubuntu.Components 1.3
import Ubuntu.Gestures 0.1
/*
Put a DragHandle inside a Showable to enable the user to drag it from that handle.
Main use case is to drag fullscreen Showables into the screen or off the screen.
This example shows a DragHandle placed on the right corner of a Showable, used
to slide it away, off the screen.
Showable {
x: 0
y: 0
width: ... // screen width
height: ... // screen height
shown: true
...
DragHandle {
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
width: units.gu(2)
direction: DirectionalDragArea::Leftwards
}
}
*/
DirectionalDragArea {
id: dragArea
property bool stretch: false
property alias autoCompleteDragThreshold: dragEvaluator.dragThreshold
// How far you can drag
property real maxTotalDragDistance: {
if (stretch) {
0; // not enough context information to set a sensible default
} else {
Direction.isHorizontal(direction) ? parent.width : parent.height;
}
}
property real hintDisplacement: 0
immediateRecognition: hintDisplacement > 0
property var overrideStartValue: undefined
SmoothedAnimation {
id: hintingAnimation
target: hintingAnimation
property: "targetValue"
duration: 150
velocity: -1
to: Direction.isPositive(direction) ? d.startValue + hintDisplacement
: d.startValue - hintDisplacement
property real targetValue
onTargetValueChanged: {
if (!running) {
return;
}
if (Direction.isPositive(direction)) {
if (parent[d.targetProp] < targetValue) {
parent[d.targetProp] = targetValue;
}
} else {
if (parent[d.targetProp] > targetValue) {
parent[d.targetProp] = targetValue;
}
}
}
}
// Private stuff
QtObject {
id: d
property real startValue
property real minValue: {
if (direction == Direction.Horizontal) {
return startValue - maxTotalDragDistance;
} else if (Direction.isPositive(direction)) {
return startValue;
} else {
return startValue - maxTotalDragDistance;
}
}
property real maxValue: Direction.isPositive(direction) ? startValue + maxTotalDragDistance
: startValue
property var dragParent: dragArea.parent
// The property of DragHandle's parent that will be modified
property string targetProp: {
if (stretch) {
Direction.isHorizontal(direction) ? "width" : "height";
} else {
Direction.isHorizontal(direction) ? "x" : "y";
}
}
function limitMovement(inputStep) {
var targetValue = MathUtils.clamp(dragParent[targetProp] + inputStep, minValue, maxValue);
var step = targetValue - dragParent[targetProp];
if (hintDisplacement == 0) {
return step;
}
// we should not go behind hintingAnimation's current value
if (Direction.isPositive(direction)) {
if (dragParent[targetProp] + step < hintingAnimation.targetValue) {
step = hintingAnimation.targetValue - dragParent[targetProp];
}
} else {
if (dragParent[targetProp] + step > hintingAnimation.targetValue) {
step = hintingAnimation.targetValue - dragParent[targetProp];
}
}
return step;
}
function onFinishedRecognizedGesture() {
if (dragEvaluator.shouldAutoComplete()) {
completeDrag();
} else {
rollbackDrag();
}
}
function completeDrag() {
if (dragParent.shown) {
dragParent.hide();
} else {
dragParent.show();
}
}
function rollbackDrag() {
if (dragParent.shown) {
dragParent.show();
} else {
dragParent.hide();
}
}
}
property alias edgeDragEvaluator: dragEvaluator
EdgeDragEvaluator {
objectName: "edgeDragEvaluator"
id: dragEvaluator
// Effectively convert distance into the drag position projected onto the gesture direction axis
trackedPosition: Direction.isPositive(dragArea.direction) ? sceneDistance : -sceneDistance
maxDragDistance: maxTotalDragDistance
direction: dragArea.direction
}
onDistanceChanged: {
if (dragging) {
// don't go the whole distance in order to smooth out the movement
var step = distance * 0.3;
step = d.limitMovement(step);
parent[d.targetProp] += step;
}
}
onDraggingChanged: {
if (dragging) {
dragEvaluator.reset();
if (overrideStartValue !== undefined) {
d.startValue = overrideStartValue;
} else {
d.startValue = parent[d.targetProp];
}
if (hintDisplacement > 0) {
hintingAnimation.targetValue = d.startValue;
hintingAnimation.start();
}
} else {
hintingAnimation.stop();
d.onFinishedRecognizedGesture();
}
}
}
|