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/>.
18import Lomiri.Components 1.3
23 readonly property bool areaActive: lateralPosition >= 0
24 property real stopScrollThreshold: units.gu(2)
25 property real progressThreshold: units.dp(4)
26 property int direction: Qt.LeftToRight
27 property real baseScrollAmount: units.dp(3)
28 property real maximumScrollAmount: units.dp(8)
29 property real lateralPosition: -1
30 property real forceScrollingPercentage: 0.4
32 signal scroll(real scrollAmount)
35 rotation: direction === Qt.LeftToRight ? 0 : 180
37 onAreaActiveChanged: areaActive ? handleEnter() : handleExit()
39 function handleEnter() {
40 d.thresholdAreaX = -scrollArea.stopScrollThreshold;
41 scrollTimer.restart();
43 d.passedProgressThreshold = false;
46 d.startingProgression = 0;
49 function handleExit() {
50 d.thresholdAreaX = -scrollArea.stopScrollThreshold;
54 onLateralPositionChanged: {
55 if (scrollArea.areaActive) {
56 if (lateralPosition > width * (1 - forceScrollingPercentage)) {
57 d.thresholdAreaX = width * (1 - forceScrollingPercentage);
58 if (!scrollTimer.running) scrollTimer.restart();
59 } else if (lateralPosition > d.thresholdAreaX + scrollArea.stopScrollThreshold) {
60 d.thresholdAreaX = lateralPosition - scrollArea.stopScrollThreshold;
61 if (!scrollTimer.running) scrollTimer.restart();
62 } else if (lateralPosition < d.thresholdAreaX) {
63 d.thresholdAreaX = lateralPosition;
67 d.progression = lateralPosition / width;
69 d.startingProgression = d.progression;
81 if (d.passedProgressThreshold ||
82 Math.abs(d.progression - d.startingProgression) * scrollArea.width > scrollArea.progressThreshold) {
83 d.passedProgressThreshold = true;
85 var scrollAmount = scrollArea.baseScrollAmount + scrollArea.maximumScrollAmount * d.progression;
86 scrollArea.scroll(scrollAmount);
93 property real startingProgression: 0
94 property bool init: true
96 property real progression: 0
97 property real thresholdAreaX: -scrollArea.stopScrollThreshold
98 property bool passedProgressThreshold: false