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  // output
38 
39  // We need to shuffle z ordering a bit in order to keep side stage apps above main stage apps.
40  // We don't want to really reorder them in the model because that allows us to keep track
41  // of the last focused order.
42  readonly property int itemZ: {
43  // only shuffle when we've got a main and side stage
44  if (!sideStageDelegate) return itemIndex;
45 
46  // don't shuffle indexes greater than "actives or next"
47  if (itemIndex > 2) return itemIndex;
48 
49  if (thisDelegate == mainStageDelegate) {
50  // Active main stage always at 0
51  return 0;
52  }
53 
54  if (nextInStack > 0) {
55  var stageOfNextInStack = appRepeater.itemAt(nextInStack).stage;
56 
57  if (itemIndex === nextInStack) {
58  // this is the next app in stack.
59 
60  if (stage === ApplicationInfoInterface.SideStage) {
61  // if the next app in stack is a sidestage app, it must order on top of other side stage app
62  return Math.min(2, topLevelSurfaceList.count-1);
63  }
64  return 1;
65  }
66  if (stageOfNextInStack === ApplicationInfoInterface.SideStage) {
67  // if the next app in stack is a sidestage app, it must order on top of other side stage app
68  return 1;
69  }
70  return Math.min(2, topLevelSurfaceList.count-1);
71  }
72  return Math.min(index+1, topLevelSurfaceList.count-1);
73  }
74 
75 
76  property int itemX: {
77  if (mainStageDelegate == thisDelegate) {
78  return 0
79  }
80  if (sideStageDelegate == thisDelegate) {
81  return sideStageX;
82  }
83  return sceneWidth;
84  }
85  Behavior on itemX { enabled: root.animateX; UbuntuNumberAnimation {} }
86 
87  readonly property int itemWidth: stage == ApplicationInfoInterface.MainStage ?
88  sideStageDelegate != null ? sideStageX : sceneWidth :
89  stage == ApplicationInfoInterface.SideStage ? sideStageWidth : sceneWidth
90 }