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