on 5d86cc3 help sign in
unity8/qml/Components/EdgeBarrier.qml
113 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 readonly property alias progress: controller.progress
34 property Item target: parent
35 function push(amount) { controller.push(amount); }
36 signal passed()
38 anchors.top: (edge == Qt.LeftEdge || edge == Qt.RightEdge) ? target.top : undefined
39 anchors.bottom: (edge == Qt.LeftEdge || edge == Qt.RightEdge) ? target.bottom : undefined
40 anchors.left: edge == Qt.LeftEdge ? target.left : undefined
41 anchors.right: edge == Qt.RightEdge ? target.right : undefined
43 width: units.gu(0.5)
45 property Component material
47 Loader {
48 id: materialContainer
50 sourceComponent: root.material
52 anchors.top: parent.top
53 anchors.bottom: parent.bottom
54 anchors.left: root.edge == Qt.LeftEdge ? root.left : undefined
55 anchors.right: root.edge == Qt.RightEdge ? root.right : undefined
57 anchors.leftMargin: root.edge == Qt.LeftEdge ? -width * (1 - positionProgress) : 0
58 anchors.rightMargin: root.edge == Qt.RightEdge ? -width * (1 - positionProgress) : 0
60 property real positionProgress
62 visible: positionProgress > 0
64 width: units.gu(2)
65 }
67 EdgeBarrierController {
68 id: controller
69 objectName: "edgeBarrierController"
70 anchors.fill: parent
71 onPassed: root.passed();
72 }
74 state: {
75 if (controller.progress === 0.0) {
76 return "";
77 } else if (controller.progress < 1.0) {
78 return "resisting";
79 } else { // controller.progress == 1.0
80 return "passed";
81 }
82 }
83 states: [
84 State {
85 name: ""
86 PropertyChanges { target: materialContainer; opacity: 0.0 }
87 PropertyChanges { target: materialContainer; positionProgress: 0.0 }
88 },
89 State {
90 name: "resisting"
91 PropertyChanges { target: materialContainer; opacity: controller.progress }
92 PropertyChanges { target: materialContainer; positionProgress: controller.progress }
93 },
94 State {
95 name: "passed"
96 PropertyChanges { target: materialContainer; opacity: 0.0 }
97 PropertyChanges { target: materialContainer; positionProgress: 1.0 }
98 }
99 ]
100 transitions: [
101 Transition {
102 from: "passed"; to: ""
103 },
104 Transition {
105 from: "resisting"; to: ""
106 UbuntuNumberAnimation { target: materialContainer; properties: "opacity,positionProgress" }
107 },
108 Transition {
109 from: "resisting"; to: "passed"
110 UbuntuNumberAnimation { duration: UbuntuAnimation.BriskDuration; target: materialContainer; property: "opacity" }
111 }
112 ]