Unity 8
 All Classes Functions Properties
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 
30  // 1 when fully shown and 0 when fully hidden
31  property real showProgress: MathUtils.clamp((width + x) / width, 0, 1)
32 
33  showAnimation: StandardAnimation { property: "x"; to: 0 }
34  hideAnimation: StandardAnimation { property: "x"; to: -width }
35 
36  property alias dragHandleWidth: dragHandle.width
37  property alias model: greeterContentLoader.model
38  property bool locked: shown && !LightDM.Greeter.promptless
39 
40  readonly property bool narrowMode: !multiUser && height > width
41  readonly property bool multiUser: LightDM.Users.count > 1
42 
43  readonly property bool leftTeaserPressed: greeterContentLoader.status == Loader.Ready &&
44  greeterContentLoader.item.leftTeaserPressed
45  readonly property bool rightTeaserPressed: greeterContentLoader.status == Loader.Ready &&
46  greeterContentLoader.item.rightTeaserPressed
47 
48  readonly property int currentIndex: greeterContentLoader.currentIndex
49 
50  signal selected(int uid)
51  signal unlocked(int uid)
52 
53  onRightTeaserPressedChanged: {
54  if (rightTeaserPressed && (!locked || narrowMode) && x == 0) {
55  teasingTimer.start();
56  }
57  }
58 
59  Loader {
60  id: greeterContentLoader
61  objectName: "greeterContentLoader"
62  anchors.fill: parent
63  property var model: LightDM.Users
64  property int currentIndex: 0
65  property var infographicModel: LightDM.Infographic
66  readonly property int backgroundTopMargin: -greeter.y
67 
68  source: required ? "GreeterContent.qml" : ""
69 
70  onLoaded: {
71  selected(currentIndex);
72  }
73 
74  Connections {
75  target: greeterContentLoader.item
76 
77  onSelected: {
78  greeter.selected(uid);
79  greeterContentLoader.currentIndex = uid;
80  }
81  onUnlocked: greeter.unlocked(uid);
82  }
83  }
84 
85  Timer {
86  id: teasingTimer
87  interval: 200
88  }
89 
90  states: [
91  State {
92  name: "teasing"
93  when: teasingTimer.running
94  PropertyChanges {
95  target: greeter
96  x: -dragHandle.hintDisplacement
97  }
98  }
99  ]
100  transitions: [
101  Transition {
102  from: "*"
103  to: "*"
104  NumberAnimation {
105  target: greeter
106  property: "x"
107  duration: 300
108  easing.type: Easing.OutCubic
109  }
110  }
111  ]
112 
113  DragHandle {
114  id: dragHandle
115 
116  anchors.top: parent.top
117  anchors.bottom: parent.bottom
118  anchors.right: parent.right
119 
120  hintDisplacement: units.gu(2)
121 
122  enabled: greeter.narrowMode || !greeter.locked
123 
124  direction: Direction.Leftwards
125  }
126 }