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.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 
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  objectName: "coverPageDragHandle"
133  anchors.fill: parent
134  anchors.leftMargin: root.dragHandleLeftMargin
135  enabled: root.draggable
136  direction: Direction.Horizontal
137 
138  onPressedChanged: {
139  if (pressed) {
140  root.tease();
141  showLabelAnimation.start();
142  }
143  }
144  }
145 
146  // right side shadow
147  Image {
148  anchors.left: parent.right
149  anchors.top: parent.top
150  anchors.bottom: parent.bottom
151  fillMode: Image.Tile
152  source: "../graphics/dropshadow_right.png"
153  }
154 
155  // left side shadow
156  Image {
157  anchors.right: parent.left
158  anchors.top: parent.top
159  anchors.bottom: parent.bottom
160  fillMode: Image.Tile
161  source: "../graphics/dropshadow_left.png"
162  }
163 
164  Binding {
165  id: positionLock
166 
167  property bool enabled: false
168  onEnabledChanged: {
169  if (enabled === __enabled) {
170  return;
171  }
172 
173  if (enabled) {
174  if (root.x > 0) {
175  value = Qt.binding(function() { return root.width; })
176  } else {
177  value = Qt.binding(function() { return -root.width; })
178  }
179  }
180 
181  __enabled = enabled;
182  }
183 
184  property bool __enabled: false
185 
186  target: root
187  when: __enabled
188  property: "x"
189  }
190 
191  hideAnimation: SequentialAnimation {
192  id: hideAnimation
193  objectName: "hideAnimation"
194  property var target // unused, here to silence Showable warning
195  StandardAnimation {
196  id: hideTranslation
197  property: "x"
198  target: root
199  }
200  PropertyAction { target: root; property: "visible"; value: false }
201  PropertyAction { target: positionLock; property: "enabled"; value: true }
202  }
203 
204  showAnimation: SequentialAnimation {
205  id: showAnimation
206  objectName: "showAnimation"
207  property var target // unused, here to silence Showable warning
208  PropertyAction { target: root; property: "visible"; value: true }
209  PropertyAction { target: positionLock; property: "enabled"; value: false }
210  StandardAnimation {
211  property: "x"
212  target: root
213  to: 0
214  duration: UbuntuAnimation.FastDuration
215  }
216  }
217 }