2 * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 0.1
19 import Ubuntu.Gestures 0.1
20 import LightDM 0.1 as LightDM
21 import "../Components"
26 created: greeterContentLoader.status == Loader.Ready && greeterContentLoader.item.ready
28 property url background
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)
53 function hideRight() {
55 hideAnimation = __rightHideAnimation
60 function tryToUnlock() {
62 greeterContentLoader.item.tryToUnlock()
68 greeterContentLoader.item.reset()
73 // Reset hide animation to default once we're finished with it
75 // Reset hide animation so that a hide() call is reliably left
76 hideAnimation = __leftHideAnimation
80 // Bi-directional revealer
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
91 rightEvaluator.reset()
94 function maybeTease() {
95 if (!greeter.locked || greeter.narrowMode)
99 onClicked: maybeTease()
100 onDragStart: maybeTease()
101 onPressAndHold: {} // eat event, but no need to tease, as drag will cover it
104 if (greeter.x > 0 && rightEvaluator.shouldAutoComplete()) {
106 } else if (greeter.x < 0 && leftEvaluator.shouldAutoComplete()) {
109 greeter.show(); // undo drag
113 onDragValueChanged: {
114 // dragValue is kept as a "step" value since we do this x adjusting on the fly
115 greeter.x += dragValue
120 trackedPosition: dragHandle.dragValue + greeter.x
121 maxDragDistance: parent.width
122 direction: Direction.Rightwards
127 trackedPosition: dragHandle.dragValue + greeter.x
128 maxDragDistance: parent.width
129 direction: Direction.Leftwards
133 targetItem: dragHandle
134 anchors.fill: targetItem
135 enabled: targetItem.enabled
139 id: greeterContentLoader
140 objectName: "greeterContentLoader"
142 property var model: LightDM.Users
143 property int currentIndex: 0
144 property var infographicModel: LightDM.Infographic
145 readonly property int backgroundTopMargin: -greeter.y
147 source: loadContent ? "GreeterContent.qml" : ""
150 selected(currentIndex);
154 target: greeterContentLoader.item
157 greeter.selected(uid);
158 greeterContentLoader.currentIndex = uid;
160 onUnlocked: greeter.unlocked(uid);
164 onTease: showLabelAnimation.start()
168 visible: greeter.shown
169 property real baseOpacity: 0.5
171 anchors.horizontalCenter: parent.horizontalCenter
172 anchors.bottom: parent.bottom
173 anchors.bottomMargin: units.gu(5)
174 text: "《 " + i18n.tr("Unlock") + " 》"
176 font.weight: Font.Light
178 SequentialAnimation on opacity {
179 id: showLabelAnimation
185 to: swipeHint.baseOpacity
186 duration: UbuntuAnimation.SleepyDuration
188 PauseAnimation { duration: UbuntuAnimation.BriskDuration }
190 from: swipeHint.baseOpacity
192 duration: UbuntuAnimation.SleepyDuration
199 anchors.left: parent.right
200 anchors.top: parent.top
201 anchors.bottom: parent.bottom
202 visible: parent.required
204 source: "../graphics/dropshadow_right.png"
209 anchors.right: parent.left
210 anchors.top: parent.top
211 anchors.bottom: parent.bottom
212 visible: parent.required
214 source: "../graphics/dropshadow_left.png"