on xenial help sign in
make it actually switch apps
commit5c60a3c7c25a7aff1adc8bb75c69109b812305fc authorMichael Zanetti <michael.zanetti@canonical.com> dateWed 8 Jan 2014, 21:18 (13 years ago) parentc3628b9
1 file changed+99−34
qml/Stages/PhoneStage.qml+99−34
qml/Stages/PhoneStage.qml+99−34
@@ -190,11 +190,12 @@ Item {
190190// print("touchX changed", touchX)
191191 coverFlip.progress = -(touchX - root.dragAreaWidth) / root.width
192192 }
193−// onDraggingChanged: {
194−// if (dragging) {
195−// coverFlip.visible = true
196−// }
197−// }
193+
194+ onDraggingChanged: {
195+ if (!dragging) {
196+ coverFlip.snap();
197+ }
198+ }
198199
199200 Rectangle {
200201 anchors.fill: parent
@@ -210,6 +211,22 @@ Item {
210211 visible: coverFlip.visible
211212 }
212213
214+ InputFilterArea {
215+ anchors.fill: root
216+ blockInput: coverFlip.visible
217+ }
218+// MouseArea {
219+// anchors.fill: root
220+// enabled: coverFlip.visible
221+// property int oldMouseX
222+
223+// onPressed: oldMouseX = mouseX
224+// onMouseXChanged: {
225+// coverFlip.progress += (oldMouseX - mouseX) * .001
226+// oldMouseX = mouseX
227+// }
228+// }
229+
213230 Row {
214231 id: coverFlip
215232 height: parent.height
@@ -221,6 +238,36 @@ Item {
221238 property real minScale: .6
222239// onProgressChanged: print("CoverFlip progress changed", progress)
223240
241+ function snap() {
242+ if (coverFlip.progress < 0.25) {
243+ snapAnimation.targetProgress = 0
244+ } else if (coverFlip.progress < 0.75) {
245+ snapAnimation.targetProgress = 0.5
246+ } else {
247+ snapAnimation.targetProgress = 1;
248+ }
249+ snapAnimation.start();
250+ }
251+
252+ SequentialAnimation {
253+ id: snapAnimation
254+ property var targetProgress
255+
256+ UbuntuNumberAnimation {
257+ target: coverFlip
258+ properties: "progress"
259+ to: snapAnimation.targetProgress
260+ }
261+ ScriptAction {
262+ script: {
263+ if (snapAnimation.targetProgress == 0.5) {
264+ ApplicationManager.focusApplication(ApplicationManager.get(1).appId);
265+ coverFlip.progress = 0;
266+ }
267+ }
268+ }
269+ }
270+
224271 Repeater {
225272 model: ApplicationManager
226273
@@ -234,6 +281,8 @@ Item {
234281 source: ApplicationManager.get(index).screenshot
235282 scale: 1
236283
284+ property real progress: coverFlip.progress
285+
237286 transform: [
238287 Rotation {
239288 origin { x: units.gu(5); y: height / 2 }
@@ -242,21 +291,21 @@ Item {
242291 var newAngle = 0;
243292 switch (index) {
244293 case 0:
245− if (coverFlip.progress < .5) {
246− newAngle = coverFlip.progress * coverFlip.maxAngle;
294+ if (appImage.progress < .5) {
295+ newAngle = appImage.progress * coverFlip.maxAngle;
247296 } else {
248− newAngle = (coverFlip.progress - .5) * coverFlip.maxAngle * 2;
297+ newAngle = (appImage.progress - .5) * coverFlip.maxAngle * 2;
249298 }
250299 break;
251300 case 1:
252− if (coverFlip.progress < .5) {
253− newAngle = coverFlip.maxAngle - (coverFlip.progress * coverFlip.maxAngle * 2);
301+ if (appImage.progress < .5) {
302+ newAngle = coverFlip.maxAngle - (appImage.progress * coverFlip.maxAngle * 2);
254303 } else {
255− newAngle = (coverFlip.progress - .5) * coverFlip.maxAngle * 2;
304+ newAngle = (appImage.progress - .5) * coverFlip.maxAngle * 2;
256305 }
257306 break;
258307 default:
259− newAngle = Math.min(coverFlip.progress, .75) * coverFlip.maxAngle;
308+ newAngle = Math.min(appImage.progress, .75) * coverFlip.maxAngle;
260309 }
261310 return Math.min(newAngle, coverFlip.maxAngle);
262311 }
@@ -265,11 +314,11 @@ Item {
265314 x: {
266315 switch (index) {
267316 case 1:
268− if (coverFlip.progress < .5) {
269− return -root.width * coverFlip.progress;
270− } else if (coverFlip.progress < .75) {
317+ if (appImage.progress < .5) {
318+ return -root.width * appImage.progress;
319+ } else if (appImage.progress < .75) {
271320 // relation equation: x : width/2 = progress-.5 : 0.25
272− return (-root.width * .5) + (root.width/2) * (coverFlip.progress - .5) / 0.25
321+ return (-root.width * .5) + (root.width/2) * (appImage.progress - .5) / 0.25
273322 }
274323 }
275324 return 0;
@@ -281,35 +330,51 @@ Item {
281330 var scale = 1;
282331 // progress : 1 = x : root.width
283332 var progress = root.width / (root.width - x)
284− if (coverFlip.progress > .5) {
333+ if (appImage.progress > .5) {
285334 // relation equation: scale : (1-minScale) = progress-.5 : 0.5
286− scale = 1 - (1 - coverFlip.minScale) * (coverFlip.progress - 0.5) / 0.5
335+ scale = 1 - (1 - coverFlip.minScale) * (appImage.progress - 0.5) / 0.5
287336 }
288337 scale = Math.max(coverFlip.minScale, scale);
289− print("scaling to", scale)
290338 return scale;
291339 }
292340 yScale: xScale
293341 }
294342 ]
343+
295344 }
296− }
297− }
345+ MouseArea {
346+ anchors.fill: parent
298347
299− }
300− InputFilterArea {
301− anchors.fill: root
302− blockInput: coverFlip.visible
303− }
304− MouseArea {
305− anchors.fill: root
306− enabled: coverFlip.visible
307− property int oldMouseX
348+ property int oldMouseX
349+
350+ onPressed: oldMouseX = mouseX
351+ onMouseXChanged: {
352+ coverFlip.progress += (oldMouseX - mouseX) * .001
353+ oldMouseX = mouseX
354+ }
355+
356+ onClicked: {
357+ print("clicked item", index)
358+ switchToAppAnimation.start();
359+ }
360+ }
308361
309− onPressed: oldMouseX = mouseX
310− onMouseXChanged: {
311− coverFlip.progress += (oldMouseX - mouseX) * .001
312− oldMouseX = mouseX
362+ SequentialAnimation {
363+ id: switchToAppAnimation
364+ ParallelAnimation {
365+ UbuntuNumberAnimation { target: appImage; property: "progress"; to: 0 }
366+ UbuntuNumberAnimation { target: appImage; property: "x"; to: -width * index }
367+ }
368+ ScriptAction {
369+ script: {
370+ ApplicationManager.focusApplication(ApplicationManager.get(index).appId);
371+ coverFlip.progress = 0;
372+ appImage.x = 0;
373+ }
374+ }
375+
376+ }
377+ }
313378 }
314379 }
315380}