Unity 8
CoverPage.qml
1 /*
2  * Copyright (C) 2013-2016 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.4
18 import Ubuntu.Components 1.3
19 import Ubuntu.Gestures 0.1
20 import "../Components"
21 
22 Showable {
23  id: root
24 
25  property real dragHandleLeftMargin
26  property real launcherOffset
27  property alias background: greeterBackground.source
28  property real backgroundTopMargin
29  property var infographicModel
30  property bool draggable: true
31 
32  property alias infographics: infographics
33 
34  readonly property real showProgress: MathUtils.clamp((width - Math.abs(x)) / width, 0, 1)
35 
36  signal tease()
37  signal clicked()
38 
39  function hideRight() {
40  d.forceRightOnNextHideAnimation = true;
41  hide();
42  }
43 
44  function showErrorMessage(msg) {
45  d.errorMessage = msg;
46  showLabelAnimation.start();
47  errorMessageAnimation.start();
48  }
49 
50  QtObject {
51  id: d
52  property bool forceRightOnNextHideAnimation: false
53  property string errorMessage
54  }
55 
56  prepareToHide: function () {
57  hideTranslation.from = root.x + translation.x
58  hideTranslation.to = root.x > 0 || d.forceRightOnNextHideAnimation ? root.width : -root.width;
59  d.forceRightOnNextHideAnimation = false;
60  }
61 
62  // We don't directly bind "x" because that's owned by the DragHandle. So
63  // instead, we can get a little extra horizontal push by using transforms.
64  transform: Translate { id: translation; x: root.draggable ? launcherOffset : 0 }
65 
66  // Eat events elsewhere on the coverpage, except mouse clicks which we pass
67  // up (they are used in the NarrowView to hide the cover page)
68  MouseArea {
69  anchors.fill: parent
70  onClicked: root.clicked()
71 
72  MultiPointTouchArea {
73  anchors.fill: parent
74  mouseEnabled: false
75  }
76  }
77 
78  Rectangle {
79  // In case background fails to load
80  id: backgroundBackup
81  anchors.fill: parent
82  color: "black"
83  }
84 
85  CrossFadeImage {
86  id: greeterBackground
87  objectName: "greeterBackground"
88  anchors {
89  fill: parent
90  topMargin: root.backgroundTopMargin
91  }
92  fillMode: Image.PreserveAspectCrop
93  // Limit how much memory we'll reserve for this image
94  sourceSize.height: height
95  sourceSize.width: width
96  }
97 
98  // Darkens wallpaper so that we can read text on it and see infographic
99  Rectangle {
100  anchors.fill: parent
101  color: "black"
102  opacity: 0.4
103  }
104 
105  Infographics {
106  id: infographics
107  objectName: "infographics"
108  height: parent.height
109  model: root.infographicModel
110  clip: true // clip large data bubbles
111 
112  anchors {
113  verticalCenter: parent.verticalCenter
114  left: parent.left
115  right: parent.right
116  }
117  }
118 
119  Label {
120  id: swipeHint
121  objectName: "swipeHint"
122  property real baseOpacity: 0.5
123  opacity: 0.0
124  anchors.horizontalCenter: parent.horizontalCenter
125  anchors.bottom: parent.bottom
126  anchors.bottomMargin: units.gu(5)
127  text: "《 " + (d.errorMessage ? d.errorMessage : i18n.tr("Unlock")) + " 》"
128  color: "white"
129  font.weight: Font.Light
130 
131  readonly property var opacityAnimation: showLabelAnimation // for testing
132 
133  SequentialAnimation on opacity {
134  id: showLabelAnimation
135  running: false
136  loops: 2
137 
138  StandardAnimation {
139  from: 0.0
140  to: swipeHint.baseOpacity
141  duration: UbuntuAnimation.SleepyDuration
142  }
143  PauseAnimation { duration: UbuntuAnimation.BriskDuration }
144  StandardAnimation {
145  from: swipeHint.baseOpacity
146  to: 0.0
147  duration: UbuntuAnimation.SleepyDuration
148  }
149 
150  onRunningChanged: {
151  if (!running)
152  d.errorMessage = "";
153  }
154  }
155  }
156 
157  WrongPasswordAnimation {
158  id: errorMessageAnimation
159  objectName: "errorMessageAnimation"
160  target: swipeHint
161  }
162 
163  DragHandle {
164  id: dragHandle
165  objectName: "coverPageDragHandle"
166  anchors.fill: parent
167  anchors.leftMargin: root.dragHandleLeftMargin
168  enabled: root.draggable
169  direction: Direction.Horizontal
170 
171  onPressedChanged: {
172  if (pressed) {
173  root.tease();
174  showLabelAnimation.start();
175  }
176  }
177  }
178 
179  // right side shadow
180  Image {
181  anchors.left: parent.right
182  anchors.top: parent.top
183  anchors.bottom: parent.bottom
184  fillMode: Image.Tile
185  source: "../graphics/dropshadow_right.png"
186  }
187 
188  // left side shadow
189  Image {
190  anchors.right: parent.left
191  anchors.top: parent.top
192  anchors.bottom: parent.bottom
193  fillMode: Image.Tile
194  source: "../graphics/dropshadow_left.png"
195  }
196 
197  Binding {
198  id: positionLock
199 
200  property bool enabled: false
201  onEnabledChanged: {
202  if (enabled === __enabled) {
203  return;
204  }
205 
206  if (enabled) {
207  if (root.x > 0) {
208  value = Qt.binding(function() { return root.width; })
209  } else {
210  value = Qt.binding(function() { return -root.width; })
211  }
212  }
213 
214  __enabled = enabled;
215  }
216 
217  property bool __enabled: false
218 
219  target: root
220  when: __enabled
221  property: "x"
222  }
223 
224  hideAnimation: SequentialAnimation {
225  id: hideAnimation
226  objectName: "hideAnimation"
227  property var target // unused, here to silence Showable warning
228  StandardAnimation {
229  id: hideTranslation
230  property: "x"
231  target: root
232  }
233  PropertyAction { target: root; property: "visible"; value: false }
234  PropertyAction { target: positionLock; property: "enabled"; value: true }
235  }
236 
237  showAnimation: SequentialAnimation {
238  id: showAnimation
239  objectName: "showAnimation"
240  property var target // unused, here to silence Showable warning
241  PropertyAction { target: root; property: "visible"; value: true }
242  PropertyAction { target: positionLock; property: "enabled"; value: false }
243  StandardAnimation {
244  property: "x"
245  target: root
246  to: 0
247  duration: UbuntuAnimation.FastDuration
248  }
249  }
250 }