Unity 8
CoverPage.qml
1 /*
2  * Copyright (C) 2013,2014,2015 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.3
18 import Ubuntu.Components 1.1
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 
38  function hideRight() {
39  d.forceRightOnNextHideAnimation = true;
40  hide();
41  }
42 
43  QtObject {
44  id: d
45  property bool forceRightOnNextHideAnimation: false
46  }
47 
48  prepareToHide: function () {
49  hideTranslation.from = root.x + translation.x
50  hideTranslation.to = root.x > 0 || d.forceRightOnNextHideAnimation ? root.width : -root.width;
51  d.forceRightOnNextHideAnimation = false;
52  }
53 
54  // We don't directly bind "x" because that's owned by the DragHandle. So
55  // instead, we can get a little extra horizontal push by using transforms.
56  transform: Translate { id: translation; x: root.draggable ? launcherOffset : 0 }
57 
58  MouseArea { anchors.fill: parent; }
59 
60  Rectangle {
61  // In case background fails to load
62  id: backgroundBackup
63  anchors.fill: parent
64  color: "black"
65  }
66 
67  CrossFadeImage {
68  id: greeterBackground
69  objectName: "greeterBackground"
70  anchors {
71  fill: parent
72  topMargin: root.backgroundTopMargin
73  }
74  fillMode: Image.PreserveAspectCrop
75  // Limit how much memory we'll reserve for this image
76  sourceSize.height: height
77  sourceSize.width: width
78  }
79 
80  Rectangle {
81  anchors.fill: parent
82  color: "black"
83  opacity: 0.4
84  }
85 
86  Infographics {
87  id: infographics
88  objectName: "infographics"
89  height: parent.height
90  model: root.infographicModel
91  clip: true // clip large data bubbles
92 
93  anchors {
94  verticalCenter: parent.verticalCenter
95  left: parent.left
96  right: parent.right
97  }
98  }
99 
100  Label {
101  id: swipeHint
102  property real baseOpacity: 0.5
103  opacity: 0.0
104  anchors.horizontalCenter: parent.horizontalCenter
105  anchors.bottom: parent.bottom
106  anchors.bottomMargin: units.gu(5)
107  text: "《 " + i18n.tr("Unlock") + " 》"
108  color: "white"
109  font.weight: Font.Light
110 
111  SequentialAnimation on opacity {
112  id: showLabelAnimation
113  running: false
114  loops: 2
115 
116  StandardAnimation {
117  from: 0.0
118  to: swipeHint.baseOpacity
119  duration: UbuntuAnimation.SleepyDuration
120  }
121  PauseAnimation { duration: UbuntuAnimation.BriskDuration }
122  StandardAnimation {
123  from: swipeHint.baseOpacity
124  to: 0.0
125  duration: UbuntuAnimation.SleepyDuration
126  }
127  }
128  }
129 
130  DragHandle {
131  id: dragHandle
132  anchors.fill: parent
133  anchors.leftMargin: root.dragHandleLeftMargin
134  enabled: root.draggable
135  direction: Direction.Horizontal
136 
137  onDraggingChanged: {
138  if (dragging) {
139  root.tease();
140  showLabelAnimation.start();
141  }
142  }
143  }
144 
145  // right side shadow
146  Image {
147  anchors.left: parent.right
148  anchors.top: parent.top
149  anchors.bottom: parent.bottom
150  fillMode: Image.Tile
151  source: "../graphics/dropshadow_right.png"
152  }
153 
154  // left side shadow
155  Image {
156  anchors.right: parent.left
157  anchors.top: parent.top
158  anchors.bottom: parent.bottom
159  fillMode: Image.Tile
160  source: "../graphics/dropshadow_left.png"
161  }
162 
163  Binding {
164  id: positionLock
165 
166  property bool enabled: false
167  onEnabledChanged: {
168  if (enabled === __enabled) {
169  return;
170  }
171 
172  if (enabled) {
173  if (root.x > 0) {
174  value = Qt.binding(function() { return root.width; })
175  } else {
176  value = Qt.binding(function() { return -root.width; })
177  }
178  }
179 
180  __enabled = enabled;
181  }
182 
183  property bool __enabled: false
184 
185  target: root
186  when: __enabled
187  property: "x"
188  }
189 
190  hideAnimation: SequentialAnimation {
191  id: hideAnimation
192  objectName: "hideAnimation"
193  property var target // unused, here to silence Showable warning
194  StandardAnimation {
195  id: hideTranslation
196  property: "x"
197  target: root
198  }
199  PropertyAction { target: root; property: "visible"; value: false }
200  PropertyAction { target: positionLock; property: "enabled"; value: true }
201  }
202 
203  showAnimation: SequentialAnimation {
204  id: showAnimation
205  objectName: "showAnimation"
206  property var target // unused, here to silence Showable warning
207  PropertyAction { target: root; property: "visible"; value: true }
208  PropertyAction { target: positionLock; property: "enabled"; value: false }
209  StandardAnimation {
210  property: "x"
211  target: root
212  to: 0
213  duration: UbuntuAnimation.FastDuration
214  }
215  }
216 }