@@ -215,17 +215,47 @@ Item {
215215 anchors.fill: root
216216 blockInput: coverFlip.visible
217217 }
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−// }
218+ MouseArea {
219+ anchors.fill: root
220+ enabled: coverFlip.visible
221+ property int oldMouseX
222+ property int startX
223+
224+ property bool isDrag: false
225+
226+ onPressed: {
227+ isDrag = false
228+ oldMouseX = mouseX
229+ startX = mouseX
230+ }
231+
232+ onMouseXChanged: {
233+ var diff = (oldMouseX - mouseX) * .001;
234+ coverFlip.progress = Math.max(.8, coverFlip.progress + diff);
235+ oldMouseX = mouseX
236+ print("mousex changed", mouseX - startX)
237+ if (Math.abs(mouseX - startX) > units.gu(.5)) {
238+ isDrag = true;
239+ }
240+ }
241+ onClicked: {
242+ // From Qt docs:
243+ // "A click is defined as a press followed by a release, both inside the
244+ // MouseArea (pressing, moving outside the MouseArea, and then moving back
245+ // inside and releasing is also considered a click)."
246+ // This means, that pressing, moving the coverFlip around and then releasing
247+ // will still be threated as a click. Let's add our own logic to not activate
248+ // a tile if the user just wants to drag stuff around.
249+ if (isDrag) {
250+ return;
251+ }
252+
253+ var index = Math.floor(mouseX / coverFlip.tileWidth)
254+ index = Math.min(tileRepeater.count - 1, index)
255+ print("clicked item", index)
256+ coverFlip.selectItem(index);
257+ }
258+ }
229259
230260 Row {
231261 id: coverFlip
@@ -236,19 +266,28 @@ Item {
236266 property real progress: 0
237267 property int maxAngle: 45
238268 property real minScale: .6
269+ property bool animatingBack: false
270+
271+ property real tileWidth: Math.max(units.gu(2), root.width - (coverFlip.progress * root.width))
272+
239273// onProgressChanged: print("CoverFlip progress changed", progress)
274+ onXChanged: print("coverflip x changed", x)
240275
241276 function snap() {
242277 if (coverFlip.progress < 0.25) {
243278 snapAnimation.targetProgress = 0
244− } else if (coverFlip.progress < 0.75) {
279+ } else if (coverFlip.progress < 0.6) {
245280 snapAnimation.targetProgress = 0.5
246281 } else {
247− snapAnimation.targetProgress = 1;
282+ snapAnimation.targetProgress = .8;
248283 }
249284 snapAnimation.start();
250285 }
251286
287+ function selectItem(index) {
288+ tileRepeater.itemAt(index).select();
289+ }
290+
252291 SequentialAnimation {
253292 id: snapAnimation
254293 property var targetProgress
@@ -269,15 +308,21 @@ Item {
269308 }
270309
271310 Repeater {
311+ id: tileRepeater
272312 model: ApplicationManager
273313
274314 Item {
275315 height: parent.height
276− width: Math.max(root.width / ApplicationManager.count, appImage.implicitWidth - (coverFlip.progress * appImage.implicitWidth))
316+ width: coverFlip.tileWidth
317+
318+ function select() {
319+ switchToAppAnimation.start();
320+ }
277321
278322 Image {
279323 id: appImage
280− height: parent.height
324+ anchors { left: parent.left; bottom: parent.bottom }
325+ width: root.width
281326 source: ApplicationManager.get(index).screenshot
282327 scale: 1
283328
@@ -289,29 +334,37 @@ Item {
289334 axis { x: 0; y: 1; z: 0 }
290335 angle: {
291336 var newAngle = 0;
292− switch (index) {
293− case 0:
294− if (appImage.progress < .5) {
295− newAngle = appImage.progress * coverFlip.maxAngle;
296− } else {
297− newAngle = (appImage.progress - .5) * coverFlip.maxAngle * 2;
298− }
299− break;
300− case 1:
301− if (appImage.progress < .5) {
302− newAngle = coverFlip.maxAngle - (appImage.progress * coverFlip.maxAngle * 2);
303− } else {
304− newAngle = (appImage.progress - .5) * coverFlip.maxAngle * 2;
305− }
306− break;
307− default:
337+ if (coverFlip.animatingBack) {
308338 newAngle = Math.min(appImage.progress, .75) * coverFlip.maxAngle;
339+ } else {
340+ switch (index) {
341+ case 0:
342+ if (appImage.progress < .5) {
343+ newAngle = appImage.progress * coverFlip.maxAngle;
344+ } else {
345+ newAngle = (appImage.progress - .5) * coverFlip.maxAngle * 2;
346+ }
347+ break;
348+ case 1:
349+ if (appImage.progress < .5) {
350+ newAngle = coverFlip.maxAngle - (appImage.progress * coverFlip.maxAngle * 2);
351+ } else {
352+ newAngle = (appImage.progress - .5) * coverFlip.maxAngle * 2;
353+ }
354+ break;
355+ default:
356+ newAngle = Math.min(appImage.progress, .75) * coverFlip.maxAngle;
357+ }
309358 }
310359 return Math.min(newAngle, coverFlip.maxAngle);
311360 }
312361 },
313362 Translate {
314363 x: {
364+ if (coverFlip.animatingBack) {
365+ return 0;
366+ }
367+
315368 switch (index) {
316369 case 1:
317370 if (appImage.progress < .5) {
@@ -342,37 +395,23 @@ Item {
342395 ]
343396
344397 }
345− MouseArea {
346− anchors.fill: parent
347−
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− }
361398
362399 SequentialAnimation {
363400 id: switchToAppAnimation
401+ PropertyAction { target: coverFlip; property: "animatingBack"; value: true }
364402 ParallelAnimation {
365− UbuntuNumberAnimation { target: appImage; property: "progress"; to: 0 }
366− UbuntuNumberAnimation { target: appImage; property: "x"; to: -width * index }
403+ UbuntuNumberAnimation { target: coverFlip; property: "progress"; to: 0 }
404+ UbuntuNumberAnimation { target: coverFlip; property: "x"; to: -root.width * index }
367405 }
368406 ScriptAction {
369407 script: {
370408 ApplicationManager.focusApplication(ApplicationManager.get(index).appId);
371409 coverFlip.progress = 0;
410+ coverFlip.x = 0;
411+ coverFlip.animatingBack = false;
372412 appImage.x = 0;
373413 }
374414 }
375−
376415 }
377416 }
378417 }