on 115baaa help sign in
unity8/qml/Components/EdgeBarrierController.qml
71 lines 2.0 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17import QtQuick 2.4
18import Utils 0.1 // For EdgeBarrierSettings
20MouseArea {
21 id: root
23 hoverEnabled: true
25 // Edge push progress
26 // Value range is [0.0, 1.0]
27 readonly property real progress: Math.min(Math.max(0.0, _accumulatedPush / EdgeBarrierSettings.pushThreshold), 1.0)
29 // Emitted when progress reaches 1.0
30 // Should trigger the action associated with this edge
31 signal passed()
33 function push(amount) {
34 if (!root._containsMouse) {
35 return;
36 }
38 if (_accumulatedPush === EdgeBarrierSettings.pushThreshold) {
39 // NO-OP
40 return;
41 }
43 if (_accumulatedPush + amount > EdgeBarrierSettings.pushThreshold) {
44 _accumulatedPush = EdgeBarrierSettings.pushThreshold;
45 } else {
46 _accumulatedPush += amount;
47 }
49 if (_accumulatedPush === EdgeBarrierSettings.pushThreshold) {
50 passed();
51 }
52 }
54 onEnabledChanged: {
55 if (!enabled) {
56 // reset
57 _accumulatedPush = 0;
58 }
59 }
61 // to be overwritten by tests
62 property bool _containsMouse: root.containsMouse
63 on_ContainsMouseChanged: {
64 if (!_containsMouse) {
65 // reset
66 _accumulatedPush = 0;
67 }
68 }
70 property real _accumulatedPush: 0