@@ -0,0 +1,97 @@
1+import QtQuick 2.4
2+import Ubuntu.Components 1.3
3+import "../../Components"
4+
5+DraggingArea {
6+ id: root
7+ onPressed: mouse.accepted = true;
8+ hoverEnabled: true
9+
10+ property bool closeable: true
11+
12+ property bool moving: false
13+ property real distance: 0
14+ readonly property int threshold: units.gu(2)
15+ property int offset: 0
16+
17+ readonly property real minSpeedToClose: units.gu(40)
18+
19+ signal close();
20+
21+ onMouseYChanged: {
22+ if (pressed) {
23+ appDelegate.y
24+ }
25+ }
26+
27+ onDragValueChanged: {
28+ if (!dragging) {
29+ return;
30+ }
31+ moving = moving || Math.abs(dragValue) > threshold;
32+ if (moving) {
33+ distance = dragValue + offset;
34+ }
35+ }
36+
37+ onMovingChanged: {
38+ if (moving) {
39+ offset = (dragValue > 0 ? -threshold: threshold)
40+ } else {
41+ offset = 0;
42+ }
43+ }
44+
45+ onDragEnd: {
46+ if (!root.closeable) {
47+ animation.animate("center")
48+ return;
49+ }
50+
51+ // velocity and distance values specified by design prototype
52+ if ((dragVelocity < -minSpeedToClose && distance < -units.gu(8)) || distance < -root.height / 2) {
53+ animation.animate("up")
54+ } else if ((dragVelocity > minSpeedToClose && distance > units.gu(8)) || distance > root.height / 2) {
55+ animation.animate("down")
56+ } else {
57+ animation.animate("center")
58+ }
59+ }
60+
61+ UbuntuNumberAnimation {
62+ id: animation
63+ objectName: "closeAnimation"
64+ target: dragArea
65+ property: "distance"
66+ property bool requestClose: false
67+
68+ function animate(direction) {
69+ animation.from = dragArea.distance;
70+ switch (direction) {
71+ case "up":
72+ animation.to = -root.height * 1.5;
73+ requestClose = true;
74+ break;
75+ case "down":
76+ animation.to = root.height * 1.5;
77+ requestClose = true;
78+ break;
79+ default:
80+ animation.to = 0
81+ }
82+ animation.start();
83+ }
84+
85+ onRunningChanged: {
86+ if (!running) {
87+ dragArea.moving = false;
88+ if (requestClose) {
89+ root.close();
90+ } else {
91+ dragArea.distance = 0;
92+ }
93+ }
94+ }
95+ }
96+}
97+