Unity 8
StageMaths.qml
1 /*
2  * Copyright (C) 2017 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 Unity.Application 0.1
19 import Ubuntu.Components 1.3
20 
21 QtObject {
22  id: root
23 
24  // input
25  property int itemIndex: 0
26  property int nextInStack: 0
27  property int sceneWidth: 0
28  property int sideStageWidth: 0
29  property int sideStageX: sceneWidth
30  property bool animateX: false
31 
32  property int stage: ApplicationInfoInterface.MainStage
33  property var thisDelegate: null
34  property var mainStageDelegate: null
35  property var sideStageDelegate: null
36 
37  property int animationDuration: UbuntuAnimation.FastDuration
38 
39  // output
40 
41  // We need to shuffle z ordering a bit in order to keep side stage apps above main stage apps.
42  // We don't want to really reorder them in the model because that allows us to keep track
43  // of the last focused order.
44  readonly property int itemZ: {
45  // only shuffle when we've got a main and side stage
46  if (!sideStageDelegate) return itemIndex;
47 
48  // don't shuffle indexes greater than "actives or next"
49  if (itemIndex > 2) return itemIndex;
50 
51  if (thisDelegate == mainStageDelegate) {
52  // Active main stage always at 0
53  return 0;
54  }
55 
56  if (nextInStack > 0) {
57  var stageOfNextInStack = appRepeater.itemAt(nextInStack).stage;
58 
59  if (itemIndex === nextInStack) {
60  // this is the next app in stack.
61 
62  if (stage === ApplicationInfoInterface.SideStage) {
63  // if the next app in stack is a sidestage app, it must order on top of other side stage app
64  return Math.min(2, topLevelSurfaceList.count-1);
65  }
66  return 1;
67  }
68  if (stageOfNextInStack === ApplicationInfoInterface.SideStage) {
69  // if the next app in stack is a sidestage app, it must order on top of other side stage app
70  return 1;
71  }
72  return Math.min(2, topLevelSurfaceList.count-1);
73  }
74  return Math.min(index+1, topLevelSurfaceList.count-1);
75  }
76 
77 
78  property int itemX: {
79  if (mainStageDelegate == thisDelegate) {
80  return 0
81  }
82  if (sideStageDelegate == thisDelegate) {
83  return sideStageX;
84  }
85  return sceneWidth;
86  }
87  Behavior on itemX { enabled: root.animateX; UbuntuNumberAnimation {duration: animationDuration} }
88 
89  readonly property int itemWidth: stage == ApplicationInfoInterface.MainStage ?
90  sideStageDelegate != null ? sideStageX : sceneWidth :
91  stage == ApplicationInfoInterface.SideStage ? sideStageWidth : sceneWidth
92 }