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