Unity 8
EdgeBarrierController.qml
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  */
16 
17 import QtQuick 2.4
18 import Utils 0.1 // For EdgeBarrierSettings
19 
20 MouseArea {
21  id: root
22 
23  hoverEnabled: true
24 
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)
28 
29  // Emitted when progress reaches 1.0
30  // Should trigger the action associated with this edge
31  signal passed()
32 
33  onPressed: mouse.accepted = false;
34 
35  function push(amount) {
36  if (!root._containsMouse) {
37  return;
38  }
39 
40  if (_accumulatedPush === EdgeBarrierSettings.pushThreshold) {
41  // NO-OP
42  return;
43  }
44 
45  if (_accumulatedPush + amount > EdgeBarrierSettings.pushThreshold) {
46  _accumulatedPush = EdgeBarrierSettings.pushThreshold;
47  } else {
48  _accumulatedPush += amount;
49  }
50 
51  if (_accumulatedPush === EdgeBarrierSettings.pushThreshold) {
52  passed();
53  }
54  }
55 
56  onEnabledChanged: {
57  if (!enabled) {
58  // reset
59  _accumulatedPush = 0;
60  }
61  }
62 
63  // to be overwritten by tests
64  property bool _containsMouse: root.containsMouse
65  on_ContainsMouseChanged: {
66  if (!_containsMouse) {
67  // reset
68  _accumulatedPush = 0;
69  }
70  }
71 
72  property real _accumulatedPush: 0
73 }