on a8aed54 help sign in
unity8/qml/Greeter/Greeter.qml
211 lines 6.3 kB history raw
1/*
2 * Copyright (C) 2013 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.0
18import Ubuntu.Components 0.1
19import Ubuntu.Gestures 0.1
20import LightDM 0.1 as LightDM
21import "../Components"
23Showable {
24 id: greeter
25 enabled: shown
26 created: greeterContentLoader.status == Loader.Ready && greeterContentLoader.item.ready
28 property url defaultBackground
29 property bool loadContent: required
31 // 1 when fully shown and 0 when fully hidden
32 property real showProgress: MathUtils.clamp((width - Math.abs(x)) / width, 0, 1)
34 showAnimation: StandardAnimation { property: "x"; to: 0; duration: UbuntuAnimation.FastDuration }
35 hideAnimation: __leftHideAnimation
37 property alias dragHandleWidth: dragHandle.width
38 property alias model: greeterContentLoader.model
39 property bool locked: true
41 readonly property bool narrowMode: !multiUser && height > width
42 readonly property bool multiUser: LightDM.Users.count > 1
44 readonly property int currentIndex: greeterContentLoader.currentIndex
46 property var __leftHideAnimation: StandardAnimation { property: "x"; to: -width }
47 property var __rightHideAnimation: StandardAnimation { property: "x"; to: width }
49 signal selected(int uid)
50 signal unlocked(int uid)
51 signal tease()
53 function hideRight() {
54 if (shown) {
55 hideAnimation = __rightHideAnimation
56 hide()
57 }
58 }
60 function tryToUnlock() {
61 if (created) {
62 greeterContentLoader.item.tryToUnlock()
63 }
64 }
66 function reset() {
67 if (created) {
68 greeterContentLoader.item.reset()
69 }
70 }
72 onRequiredChanged: {
73 // Reset hide animation to default once we're finished with it
74 if (required) {
75 // Reset hide animation so that a hide() call is reliably left
76 hideAnimation = __leftHideAnimation
77 }
78 }
80 // Bi-directional revealer
81 DraggingArea {
82 id: dragHandle
83 anchors.fill: parent
84 enabled: (greeter.narrowMode || !greeter.locked) && greeter.enabled && greeter.shown
85 orientation: Qt.Horizontal
86 propagateComposedEvents: true
88 Component.onCompleted: {
89 // set evaluators to baseline of dragValue == 0
90 leftEvaluator.reset()
91 rightEvaluator.reset()
92 }
94 function maybeTease() {
95 if (!greeter.locked || greeter.narrowMode)
96 greeter.tease();
97 }
99 onClicked: maybeTease()
100 onDragStart: maybeTease()
101 onPressAndHold: {} // eat event, but no need to tease, as drag will cover it
103 onDragEnd: {
104 if (greeter.x > 0 && rightEvaluator.shouldAutoComplete()) {
105 greeter.hideRight()
106 } else if (greeter.x < 0 && leftEvaluator.shouldAutoComplete()) {
107 greeter.hide();
108 } else {
109 greeter.show(); // undo drag
110 }
111 }
113 onDragValueChanged: {
114 // dragValue is kept as a "step" value since we do this x adjusting on the fly
115 greeter.x += dragValue
116 }
118 EdgeDragEvaluator {
119 id: rightEvaluator
120 trackedPosition: dragHandle.dragValue + greeter.x
121 maxDragDistance: parent.width
122 direction: Direction.Rightwards
123 }
125 EdgeDragEvaluator {
126 id: leftEvaluator
127 trackedPosition: dragHandle.dragValue + greeter.x
128 maxDragDistance: parent.width
129 direction: Direction.Leftwards
130 }
131 }
133 Loader {
134 id: greeterContentLoader
135 objectName: "greeterContentLoader"
136 anchors.fill: parent
137 property var model: LightDM.Users
138 property int currentIndex: 0
139 property var infographicModel: LightDM.Infographic
140 readonly property int backgroundTopMargin: -greeter.y
142 source: loadContent ? "GreeterContent.qml" : ""
144 onLoaded: {
145 selected(currentIndex);
146 }
148 Connections {
149 target: greeterContentLoader.item
151 onSelected: {
152 greeter.selected(uid);
153 greeterContentLoader.currentIndex = uid;
154 }
155 onUnlocked: greeter.unlocked(uid);
156 }
157 }
159 onTease: showLabelAnimation.start()
161 Label {
162 id: swipeHint
163 visible: greeter.shown
164 property real baseOpacity: 0.5
165 opacity: 0.0
166 anchors.horizontalCenter: parent.horizontalCenter
167 anchors.bottom: parent.bottom
168 anchors.bottomMargin: units.gu(5)
169 text: "《 " + i18n.tr("Unlock") + " 》"
170 color: "white"
171 font.weight: Font.Light
173 SequentialAnimation on opacity {
174 id: showLabelAnimation
175 running: false
176 loops: 2
178 StandardAnimation {
179 from: 0.0
180 to: swipeHint.baseOpacity
181 duration: UbuntuAnimation.SleepyDuration
182 }
183 PauseAnimation { duration: UbuntuAnimation.BriskDuration }
184 StandardAnimation {
185 from: swipeHint.baseOpacity
186 to: 0.0
187 duration: UbuntuAnimation.SleepyDuration
188 }
189 }
190 }
192 // right side shadow
193 Image {
194 anchors.left: parent.right
195 anchors.top: parent.top
196 anchors.bottom: parent.bottom
197 visible: parent.required
198 fillMode: Image.Tile
199 source: "../graphics/dropshadow_right.png"
200 }
202 // left side shadow
203 Image {
204 anchors.right: parent.left
205 anchors.top: parent.top
206 anchors.bottom: parent.bottom
207 visible: parent.required
208 fillMode: Image.Tile
209 source: "../graphics/dropshadow_left.png"
210 }