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 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 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/>.
18import Ubuntu.Components 0.1
19import Ubuntu.Gestures 0.1
20import "Math.js" as MathLocal
23 Put a DragHandle inside a Showable to enable the user to drag it from that handle.
24 Main use case is to drag fullscreen Showables into the screen or off the screen.
26 This example shows a DragHandle placed on the right corner of a Showable, used
27 to slide it away, off the screen.
32 width: ... // screen width
33 height: ... // screen height
37 anchors.right: parent.right
38 anchors.top: parent.top
39 anchors.bottom: parent.bottom
42 direction: DirectionalDragArea::Leftwards
49 objectName: "dragHandle"
51 property bool stretch: false
53 property alias autoCompleteDragThreshold: dragEvaluator.dragThreshold
55 // How far you can drag
56 property real maxTotalDragDistance: {
58 0; // not enough context information to set a sensible default
60 Direction.isHorizontal(direction) ? parent.width : parent.height;
64 property real hintDisplacement: 0
67 target: hintingAnimation
68 property: "targetValue"
71 to: Direction.isPositive(direction) ? d.startValue + hintDisplacement
72 : d.startValue - hintDisplacement
73 property real targetValue
74 onTargetValueChanged: {
79 if (Direction.isPositive(direction)) {
80 if (parent[d.targetProp] < targetValue) {
81 parent[d.targetProp] = targetValue;
84 if (parent[d.targetProp] > targetValue) {
85 parent[d.targetProp] = targetValue;
94 property var previousStatus: undefined
95 property real startValue
96 property real minValue: Direction.isPositive(direction) ? startValue
97 : startValue - maxTotalDragDistance
98 property real maxValue: Direction.isPositive(direction) ? startValue + maxTotalDragDistance
101 property var dragParent: dragArea.parent
103 // The property of DragHandle's parent that will be modified
104 property string targetProp: {
106 Direction.isHorizontal(direction) ? "width" : "height";
108 Direction.isHorizontal(direction) ? "x" : "y";
112 function limitMovement(step) {
113 var targetValue = MathLocal.clamp(dragParent[targetProp] + step, minValue, maxValue);
114 var step = targetValue - dragParent[targetProp];
116 if (hintDisplacement == 0) {
120 // we should not go behind hintingAnimation's current value
121 if (Direction.isPositive(direction)) {
122 if (dragParent[targetProp] + step < hintingAnimation.targetValue) {
123 step = hintingAnimation.targetValue - dragParent[targetProp];
126 if (dragParent[targetProp] + step > hintingAnimation.targetValue) {
127 step = hintingAnimation.targetValue - dragParent[targetProp];
134 function onFinishedRecognizedGesture() {
135 if (dragEvaluator.shouldAutoComplete()) {
142 function completeDrag() {
143 if (dragParent.shown) {
150 function rollbackDrag() {
151 if (dragParent.shown) {
159 property alias edgeDragEvaluator: dragEvaluator
162 objectName: "edgeDragEvaluator"
164 trackedPosition: sceneDistance
165 maxDragDistance: maxTotalDragDistance
166 direction: dragArea.direction
170 if (status === DirectionalDragArea.Recognized) {
171 // don't go the whole distance in order to smooth out the movement
172 var step = distance * 0.3;
174 step = d.limitMovement(step);
176 parent[d.targetProp] += step;
182 if (hintDisplacement > 0) {
183 hintingAnimation.targetValue = d.startValue;
184 hintingAnimation.start();
187 hintingAnimation.stop();
192 if (status === DirectionalDragArea.WaitingForTouch) {
193 if (d.previousStatus === DirectionalDragArea.Recognized) {
194 d.onFinishedRecognizedGesture();
196 d.startValue = parent[d.targetProp];
199 if (d.previousStatus === DirectionalDragArea.WaitingForTouch ||
200 d.previousStatus === undefined) {
201 dragEvaluator.reset();
202 d.startValue = parent[d.targetProp];
205 d.previousStatus = status;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list