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/>.
18
import Ubuntu.Components 0.1
23
property Showable target
24
property var hintingAnimation: hintingAnimation
25
property string boundProperty: orientation == Qt.Vertical ? "y" : "x"
26
property int orientation: Qt.Vertical
27
property int direction: Qt.LeftToRight
28
property real openedValue: orientation == Qt.Vertical ? y : x
29
property real closedValue: orientation == Qt.Vertical ? y + (direction == Qt.LeftToRight ? -height : height) : x + (direction == Qt.LeftToRight ? -width : width)
30
property real hintDisplacement: 0
31
property real handleSize: units.gu(2)
32
property real dragVelocity: draggingArea.dragVelocity != 0 ? Math.abs(draggingArea.dragVelocity) : -1
33
property real dragVelocityThreshold: units.gu(5)
34
property bool dragging: false
35
property bool pressed: draggingArea.pressed
36
property int lateralPosition: draggingArea.lateralPosition
37
property real dragPosition
38
property bool openOnPress: true
40
signal openPressed(int mouseX, int mouseY)
41
signal openReleased(int mouseX, int mouseY)
48
if (orientation == Qt.Vertical) {
49
value = draggingArea.dragValue + draggingArea.y
50
if (direction == Qt.RightToLeft) {
51
value += draggingArea.height - height
54
value = draggingArea.dragValue + draggingArea.x
55
if (direction == Qt.RightToLeft) {
56
value += draggingArea.width - width
60
if (direction == Qt.LeftToRight) {
65
} else if (dragging) {
66
if (direction == Qt.LeftToRight) {
67
value += hintDisplacement
69
value -= hintDisplacement
75
property var draggingArea: leftDraggingArea.enabled ? leftDraggingArea : rightDraggingArea
77
property real __hintValue: closedValue + (direction == Qt.LeftToRight ? hintDisplacement : -hintDisplacement)
79
function dragToValue(dragPosition) {
80
return dragPosition + closedValue
83
property bool __opened: target.shown
84
enabled: target.available
86
// Can be replaced with a fake implementation during tests
87
// property var __getCurrentTimeMs: function () { return new Date().getTime() }
88
property var __dateTime: new function() {
89
this.getCurrentTimeMs = function() {return new Date().getTime()}
92
Component.onCompleted: target[boundProperty] = __opened ? openedValue : closedValue
93
onOpenedValueChanged: if (__opened && !dragging) target[boundProperty] = openedValue
94
onClosedValueChanged: if (!__opened && !dragging) target[boundProperty] = closedValue
96
function __computeValue(dragPosition) {
97
return MathUtils.clamp(dragToValue(dragPosition), __hintValue, openedValue)
101
hintingAnimation.stop()
106
hintingAnimation.stop()
111
target.showAnimation.stop()
112
target.hideAnimation.stop()
113
hintingAnimation.restart()
116
function __settle() {
117
hintingAnimation.stop()
118
if (__opened) target.show()
122
function __startDragging() {
123
hintingAnimation.stop()
127
function __endDragging(dragVelocity) {
129
if (revealer.direction == Qt.RightToLeft) {
130
dragVelocity = -dragVelocity
132
if (Math.abs(dragVelocity) >= dragVelocityThreshold) {
133
if (dragVelocity > 0) __open()
143
target: revealer.target
144
property: revealer.boundProperty
145
value: __computeValue(dragPosition)
152
target: revealer.target
153
property: revealer.boundProperty
155
to: revealer.__hintValue
161
property bool isOpeningArea: revealer.direction == Qt.LeftToRight
163
height: orientation == Qt.Vertical ? handleSize : parent.height
164
width: orientation == Qt.Horizontal ? handleSize : parent.width
165
orientation: revealer.orientation
166
enabled: isOpeningArea ? !revealer.__opened : revealer.__opened
168
__dateTime: revealer.__dateTime
172
if (revealer.openOnPress) {
173
revealer.openPressed(mouseX, mouseY)
177
revealer.closePressed()
181
if (isOpeningArea && revealer.openOnPress) {
182
revealer.openReleased(mouseX, mouseY)
186
onDragStart: __startDragging()
187
onDragEnd: __endDragging(dragVelocity)
189
if (clickValidated) {
191
if (revealer.openOnPress) revealer.openClicked()
193
revealer.closeClicked()
200
id: rightDraggingArea
202
property bool isOpeningArea: revealer.direction == Qt.RightToLeft
204
x: orientation == Qt.Vertical ? 0 : parent.width - width
205
y: orientation == Qt.Vertical ? parent.height - height : 0
206
height: orientation == Qt.Vertical ? handleSize : parent.height
207
width: orientation == Qt.Horizontal ? handleSize : parent.width
208
orientation: revealer.orientation
209
enabled: isOpeningArea ? !revealer.__opened : revealer.__opened
211
__dateTime: revealer.__dateTime
215
if (revealer.openOnPress) {
216
revealer.openPressed(mouseX, mouseY)
220
revealer.closePressed()
224
if (isOpeningArea && revealer.openOnPress) {
225
revealer.openReleased(mouseX, mouseY)
229
onDragStart: __startDragging()
230
onDragEnd: __endDragging(dragVelocity)
232
if (clickValidated) {
234
if (revealer.openOnPress) revealer.openClicked()
236
revealer.closeClicked()