2
* Copyright (C) 2014 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 1.1
23
readonly property bool areaActive: lateralPosition >= 0
24
property real stopScrollThreshold: units.gu(2)
25
property int direction: Qt.LeftToRight
26
property real baseScrollAmount: units.dp(3)
27
property real maximumScrollAmount: units.dp(8)
28
property real lateralPosition: -1
29
property real forceScrollingPercentage: 0.4
31
signal scroll(real scrollAmount)
34
rotation: direction === Qt.LeftToRight ? 0 : 180
36
onAreaActiveChanged: areaActive ? handleEnter() : handleExit()
38
function handleEnter() {
39
d.thresholdAreaX = -scrollArea.stopScrollThreshold;
40
scrollTimer.restart();
43
function handleExit() {
44
d.thresholdAreaX = -scrollArea.stopScrollThreshold;
48
onLateralPositionChanged: {
49
if (scrollArea.areaActive) {
50
if (lateralPosition > width * (1 - forceScrollingPercentage)) {
51
d.thresholdAreaX = width * (1 - forceScrollingPercentage);
52
if (!scrollTimer.running) scrollTimer.restart();
53
} else if (lateralPosition > d.thresholdAreaX + scrollArea.stopScrollThreshold) {
54
d.thresholdAreaX = lateralPosition - scrollArea.stopScrollThreshold;
55
if (!scrollTimer.running) scrollTimer.restart();
56
} else if (lateralPosition < d.thresholdAreaX) {
57
d.thresholdAreaX = lateralPosition;
61
d.progression = lateralPosition / width;
71
var scrollAmount = scrollArea.baseScrollAmount + scrollArea.maximumScrollAmount * d.progression;
72
scrollArea.scroll(scrollAmount);
78
property real progression: 0
79
property real thresholdAreaX: -scrollArea.stopScrollThreshold