Lomiri
Loading...
Searching...
No Matches
EdgeBarrier.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
17import QtQuick 2.12
18import Lomiri.Components 1.3
19
20/*
21 An edge barrier for the mouse pointer
22
23 The further you push against it, the stronger the visual hint. Until it's
24 overcome, when passed() is emitted.
25 */
26Item {
27 id: root
28
29 // Supported values are: Qt.LeftEdge, Qt.RightEdge
30 property int edge: Qt.LeftEdge
31
32 readonly property alias progress: controller.progress
33 readonly property alias containsMouse: controller.containsMouse
34
35 property Item target: parent
36 function push(amount) { controller.push(amount); }
37 signal passed()
38
39 anchors.top: (edge == Qt.LeftEdge || edge == Qt.RightEdge) ? target.top : undefined
40 anchors.bottom: (edge == Qt.LeftEdge || edge == Qt.RightEdge) ? target.bottom : undefined
41 anchors.left: edge == Qt.LeftEdge ? target.left : undefined
42 anchors.right: edge == Qt.RightEdge ? target.right : undefined
43
44 width: units.gu(0.5)
45
46 property Component material
47
48 Loader {
49 id: materialContainer
50
51 sourceComponent: root.material
52
53 anchors.top: parent.top
54 anchors.bottom: parent.bottom
55 anchors.left: root.edge == Qt.LeftEdge ? root.left : undefined
56 anchors.right: root.edge == Qt.RightEdge ? root.right : undefined
57
58 anchors.leftMargin: root.edge == Qt.LeftEdge ? -width * (1 - positionProgress) : 0
59 anchors.rightMargin: root.edge == Qt.RightEdge ? -width * (1 - positionProgress) : 0
60
61 property real positionProgress
62
63 visible: positionProgress > 0
64
65 width: units.gu(2)
66 }
67
68 EdgeBarrierController {
69 id: controller
70 objectName: "edgeBarrierController"
71 anchors.fill: parent
72 onPassed: root.passed();
73 }
74
75 state: {
76 if (controller.progress === 0.0) {
77 return "";
78 } else if (controller.progress < 1.0) {
79 return "resisting";
80 } else { // controller.progress == 1.0
81 return "passed";
82 }
83 }
84 states: [
85 State {
86 name: ""
87 PropertyChanges { target: materialContainer; opacity: 0.0 }
88 PropertyChanges { target: materialContainer; positionProgress: 0.0 }
89 },
90 State {
91 name: "resisting"
92 PropertyChanges { target: materialContainer; opacity: controller.progress }
93 PropertyChanges { target: materialContainer; positionProgress: controller.progress }
94 },
95 State {
96 name: "passed"
97 PropertyChanges { target: materialContainer; opacity: 0.0 }
98 PropertyChanges { target: materialContainer; positionProgress: 1.0 }
99 }
100 ]
101 transitions: [
102 Transition {
103 from: "passed"; to: ""
104 },
105 Transition {
106 from: "resisting"; to: ""
107 LomiriNumberAnimation { target: materialContainer; properties: "opacity,positionProgress" }
108 },
109 Transition {
110 from: "resisting"; to: "passed"
111 LomiriNumberAnimation { duration: LomiriAnimation.BriskDuration; target: materialContainer; property: "opacity" }
112 }
113 ]
114}