on 239fdcc help sign in
unity8/qml/Components/EdgeBarrier.qml
111 lines 3.6 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 Ubuntu.Components 1.3
20/*
21 An edge barrier for the mouse pointer
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
29 // Supported values are: Qt.LeftEdge, Qt.RightEdge
30 property int edge: Qt.LeftEdge
32 property Item target: parent
33 function push(amount) { controller.push(amount); }
34 signal passed()
36 anchors.top: (edge == Qt.LeftEdge || edge == Qt.RightEdge) ? target.top : undefined
37 anchors.bottom: (edge == Qt.LeftEdge || edge == Qt.RightEdge) ? target.bottom : undefined
38 anchors.left: edge == Qt.LeftEdge ? target.left : undefined
39 anchors.right: edge == Qt.RightEdge ? target.right : undefined
41 width: units.gu(0.5)
43 property Component material
45 Loader {
46 id: materialContainer
48 sourceComponent: root.material
50 anchors.top: parent.top
51 anchors.bottom: parent.bottom
52 anchors.left: root.edge == Qt.LeftEdge ? root.left : undefined
53 anchors.right: root.edge == Qt.RightEdge ? root.right : undefined
55 anchors.leftMargin: root.edge == Qt.LeftEdge ? -width * (1 - positionProgress) : 0
56 anchors.rightMargin: root.edge == Qt.RightEdge ? -width * (1 - positionProgress) : 0
58 property real positionProgress
60 visible: positionProgress > 0
62 width: units.gu(2)
63 }
65 EdgeBarrierController {
66 id: controller
67 objectName: "edgeBarrierController"
68 anchors.fill: parent
69 onPassed: root.passed();
70 }
72 state: {
73 if (controller.progress === 0.0) {
74 return "";
75 } else if (controller.progress < 1.0) {
76 return "resisting";
77 } else { // controller.progress == 1.0
78 return "passed";
79 }
80 }
81 states: [
82 State {
83 name: ""
84 PropertyChanges { target: materialContainer; opacity: 0.0 }
85 PropertyChanges { target: materialContainer; positionProgress: 0.0 }
86 },
87 State {
88 name: "resisting"
89 PropertyChanges { target: materialContainer; opacity: controller.progress }
90 PropertyChanges { target: materialContainer; positionProgress: controller.progress }
91 },
92 State {
93 name: "passed"
94 PropertyChanges { target: materialContainer; opacity: 0.0 }
95 PropertyChanges { target: materialContainer; positionProgress: 1.0 }
96 }
97 ]
98 transitions: [
99 Transition {
100 from: "passed"; to: ""
101 },
102 Transition {
103 from: "resisting"; to: ""
104 UbuntuNumberAnimation { target: materialContainer; properties: "opacity,positionProgress" }
105 },
106 Transition {
107 from: "resisting"; to: "passed"
108 UbuntuNumberAnimation { duration: UbuntuAnimation.BriskDuration; target: materialContainer; property: "opacity" }
109 }
110 ]