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