@@ -177,6 +177,7 @@ Item {
177177 print("unhandled nextInStack case!!!!!");
178178 return -1;
179179 }
180+ property int nextZInStack: indexToZIndex(nextInStack)
180181 onNextInStackChanged: print("next in stack is", nextInStack)
181182
182183 states: [
@@ -241,6 +242,33 @@ Item {
241242 snapAnimation.start();
242243 }
243244
245+ // We need to shuffle z ordering a bit in order to keep side stage apps above main stage apps.
246+ // We don't want to really reorder them in the model because that allows us to keep track
247+ // of the last focused order.
248+ function indexToZIndex(index) {
249+ print("zindex asked", index)
250+ var app = ApplicationManager.get(index);
251+ var isActive = app.appId == priv.mainStageAppId || app.appId == priv.sideStageAppId;
252+ if (isActive && app.stage == ApplicationInfoInterface.MainStage) return 0;
253+ if (isActive && app.stage == ApplicationInfoInterface.SideStage) {
254+ if (spreadView.nextInStack >= 0 && ApplicationManager.get(spreadView.nextInStack).stage == ApplicationInfoInterface.MainStage) {
255+ return Math.max(index, 2);
256+ } else {
257+ return 1;
258+ }
259+ }
260+ if (index <= 2 && app.stage == ApplicationInfoInterface.MainStage && priv.sideStageAppId) {
261+ return priv.indexOf(priv.sideStageAppId) < index ? index - 1 : index;
262+ }
263+ if (index == spreadView.nextInStack && app.stage == ApplicationInfoInterface.SideStage) {
264+ if (priv.sideStageAppId) {
265+ return 2;
266+ }
267+ return 1;
268+ }
269+ return index;
270+ }
271+
244272 SequentialAnimation {
245273 id: snapAnimation
246274 property int targetContentX: 0
@@ -271,7 +299,7 @@ Item {
271299 x: spreadView.contentX
272300 height: root.height
273301// width: root.width
274− width: spreadView.width + Math.max(4, ApplicationManager.count) * spreadView.tileDistance
302+ width: spreadView.width + Math.max(spreadView.width, ApplicationManager.count * spreadView.tileDistance)
275303
276304 color: "black"
277305
@@ -279,107 +307,59 @@ Item {
279307 id: spreadRepeater
280308 model: ApplicationManager
281309
282− delegate: Rectangle {
310+ delegate: TransformedTabletSpreadDelegate {
311+ id: spreadTile
283312 height: spreadView.height
284− width: spreadView.tileDistance
285− color: "#44FF0000"
286− x: spreadView.width // - units.gu(10) // just to see 'em
287−
288− // We need to shuffle z ordering a bit in order to keep side stage apps above main stage apps.
289− // We don't want to really reorder them in the model because that allows us to keep track
290− // of the last focused order.
291− z: {
292− if (spreadTile.active && model.stage == ApplicationInfoInterface.MainStage) return 0;
293− if (spreadTile.active && model.stage == ApplicationInfoInterface.SideStage) {
294− if (spreadView.nextInStack >= 0 && ApplicationManager.get(spreadView.nextInStack).stage == ApplicationInfoInterface.MainStage) {
295− return Math.max(index, 2);
296− } else {
297− return 1;
298− }
299− }
300− if (index <= 2 && model.stage == ApplicationInfoInterface.MainStage && priv.sideStageAppId) {
301− return priv.indexOf(priv.sideStageAppId) < index ? index - 1 : index;
313+ width: model.stage == ApplicationInfoInterface.MainStage ? spreadView.width : spreadView.sideStageWidth
314+ x: spreadView.width
315+ z: spreadView.indexToZIndex(index)
316+
317+ onWidthChanged: print("width changed!", width)
318+
319+ active: model.appId == priv.mainStageAppId || model.appId == priv.sideStageAppId
320+ zIndex: z
321+ selected: spreadView.selectedIndex == index
322+ otherSelected: spreadView.selectedIndex >= 0 && !selected
323+ isInSideStage: priv.sideStageAppId == model.appId
324+ interactive: !spreadView.interactive
325+
326+ progress: {
327+ var tileProgress = (spreadView.contentX - zIndex * spreadView.tileDistance) / spreadView.width;
328+ // Some tiles (nextInStack, active) need to move directly from the beginning, normalize progress to immediately start at 0
329+ if ((index == spreadView.nextInStack && spreadView.phase < 2) || (active && spreadView.phase < 1)) {
330+ tileProgress += zIndex * spreadView.tileDistance / spreadView.width;
302331 }
303− if (index == spreadView.nextInStack && model.stage == ApplicationInfoInterface.SideStage) {
304− if (priv.sideStageAppId) {
305− return 2;
306− }
307− return 1;
308− }
309− return index;
332+ return tileProgress;
310333 }
311334
312− TransformedTabletSpreadDelegate {
313− id: spreadTile
314− height: spreadView.height
315− width: model.stage == ApplicationInfoInterface.MainStage ? spreadView.width : spreadView.sideStageWidth
316−// opacity: .3
317−
318− onWidthChanged: print("width changed!", width)
319−
320− active: model.appId == priv.mainStageAppId || model.appId == priv.sideStageAppId
321− zIndex: parent.z
322− selected: spreadView.selectedIndex == index
323− otherSelected: spreadView.selectedIndex >= 0 && !selected
324− isInSideStage: priv.sideStageAppId == model.appId
325− interactive: !spreadView.interactive
326−
327− progress: {
328− var tileProgress = (spreadView.contentX - zIndex * spreadView.tileDistance) / spreadView.width;
329− // The Tile which is next in the stack needs to move directly from the beginning...
330−// print("tile0Progress is", tileProgress, "next", spreadView.nextInStack, zIndex, "PHASE:", spreadView.phase)
331− if (index == spreadView.nextInStack && spreadView.phase < 2) {
332−// print("üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü")
333− tileProgress += zIndex * spreadView.tileDistance / spreadView.width;
334− }
335− return tileProgress;
336− }
337−
338− animatedProgress: {
339−// print("PHASE:", spreadView.phase)
340− if (spreadView.phase == 0 && (active || spreadView.nextInStack == index)) {
341− if (progress < spreadView.positionMarker1) {
342−// print("progress is", progress, "index", zIndex, "appid", model.appId)
343− return progress;
344− } else if (progress < spreadView.positionMarker1 + snappingCurve.period){
345−// print("progress is", progress, "index", zIndex, "appid", model.appId)
346− return spreadView.positionMarker1 + snappingCurve.value * 3;
347− } else {
348−// print("progress is", progress, "index", zIndex, "appid", model.appId)
349− return spreadView.positionMarker2;
350− }
335+ animatedProgress: {
336+ if (spreadView.phase == 0 && (spreadTile.active || spreadView.nextInStack == index)) {
337+ if (progress < spreadView.positionMarker1) {
338+ return progress;
339+ } else if (progress < spreadView.positionMarker1 + snappingCurve.period){
340+ return spreadView.positionMarker1 + snappingCurve.value * 3;
341+ } else {
342+ return spreadView.positionMarker2;
351343 }
352−// print("progress is", progress, "index", zIndex, "appid", model.appId)
353− return progress;
354344 }
345+ return progress;
346+ }
355347
356− onClicked: {
357− if (spreadView.phase == 2) {
358− if (ApplicationManager.focusedApplicationId == ApplicationManager.get(index).appId) {
359− spreadView.snapTo(index);
360− } else {
361− ApplicationManager.requestFocusApplication(ApplicationManager.get(index).appId);
362− }
348+ onClicked: {
349+ if (spreadView.phase == 2) {
350+ if (ApplicationManager.focusedApplicationId == ApplicationManager.get(index).appId) {
351+ spreadView.snapTo(index);
352+ } else {
353+ ApplicationManager.requestFocusApplication(ApplicationManager.get(index).appId);
363354 }
364355 }
356+ }
365357
366− EasingCurve {
367− id: snappingCurve
368− type: EasingCurve.Linear
369− period: (spreadView.positionMarker2 - spreadView.positionMarker1) / 3
370− progress: spreadTile.progress - spreadView.positionMarker1
371− }
372−
373−// Rectangle {
374−// anchors.fill: parent; color: "#FF00FF"
375−// border.width: units.gu(1)
376−// border.color: "black"
377−// Label {
378−// anchors { verticalCenter: parent.verticalCenter; left: parent.left; leftMargin: units.gu(2) }
379−// fontSize: "x-large"
380−// text: spreadTile.zIndex + "/" + model.index
381−// }
382−// }
358+ EasingCurve {
359+ id: snappingCurve
360+ type: EasingCurve.Linear
361+ period: (spreadView.positionMarker2 - spreadView.positionMarker1) / 3
362+ progress: spreadTile.progress - spreadView.positionMarker1
383363 }
384364 }
385365 }