Unity 8
StageMaths.qml
1 import QtQuick 2.4
2 import Unity.Application 0.1
3 import Ubuntu.Components 1.3
4 
5 QtObject {
6  id: root
7 
8  // input
9  property int itemIndex: 0
10  property int nextInStack: 0
11  property int sceneWidth: 0
12  property int sideStageWidth: 0
13  property int sideStageX: sceneWidth
14  property bool animateX: false
15 
16  property int stage: ApplicationInfoInterface.MainStage
17  property var thisDelegate: null
18  property var mainStageDelegate: null
19  property var sideStageDelegate: null
20 
21  // output
22 
23  // We need to shuffle z ordering a bit in order to keep side stage apps above main stage apps.
24  // We don't want to really reorder them in the model because that allows us to keep track
25  // of the last focused order.
26  readonly property int itemZ: {
27  // only shuffle when we've got a main and side stage
28  if (!sideStageDelegate) return itemIndex;
29 
30  // don't shuffle indexes greater than "actives or next"
31  if (itemIndex > 2) return itemIndex;
32 
33  if (thisDelegate == mainStageDelegate) {
34  // Active main stage always at 0
35  return 0;
36  }
37 
38  if (nextInStack > 0) {
39  var stageOfNextInStack = appRepeater.itemAt(nextInStack).stage;
40 
41  if (itemIndex === nextInStack) {
42  // this is the next app in stack.
43 
44  if (stage === ApplicationInfoInterface.SideStage) {
45  // if the next app in stack is a sidestage app, it must order on top of other side stage app
46  return Math.min(2, topLevelSurfaceList.count-1);
47  }
48  return 1;
49  }
50  if (stageOfNextInStack === ApplicationInfoInterface.SideStage) {
51  // if the next app in stack is a sidestage app, it must order on top of other side stage app
52  return 1;
53  }
54  return Math.min(2, topLevelSurfaceList.count-1);
55  }
56  return Math.min(index+1, topLevelSurfaceList.count-1);
57  }
58 
59 
60  property int itemX: {
61  if (mainStageDelegate == thisDelegate) {
62  return 0
63  }
64  if (sideStageDelegate == thisDelegate) {
65  return sideStageX;
66  }
67  return sceneWidth;
68  }
69  Behavior on itemX { enabled: root.animateX; UbuntuNumberAnimation {} }
70 
71  readonly property int itemWidth: stage == ApplicationInfoInterface.MainStage ?
72  sideStageDelegate != null ? sideStageX : sceneWidth :
73  stage == ApplicationInfoInterface.SideStage ? sideStageWidth : sceneWidth
74 }