Unity 8
 All Classes Functions
SessionContainer.qml
1 /*
2  * Copyright 2014 Canonical Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
17 import QtQuick 2.0
18 import "Animations"
19 
20 Item {
21  id: root
22  objectName: "sessionContainer"
23  property QtObject session
24  readonly property var childSessions: session ? session.childSessions : null
25  readonly property alias surface: _surfaceContainer.surface
26  property alias interactive: _surfaceContainer.interactive
27  property int orientation
28 
29  readonly property alias surfaceContainer: _surfaceContainer
30  SurfaceContainer {
31  id: _surfaceContainer
32  anchors.fill: parent
33  surface: session ? session.surface : null
34  orientation: root.orientation
35  }
36 
37 
38  Repeater {
39  model: root.childSessions
40 
41  delegate: Loader {
42  objectName: "childDelegate" + index
43  anchors.fill: surfaceContainer
44 
45  // Only way to do recursive qml items.
46  source: Qt.resolvedUrl("SessionContainer.qml")
47 
48  Binding {
49  target: item; when: item
50  property: "interactive"; value: root.interactive
51  }
52 
53  Binding {
54  target: item; when: item
55  property: "session"; value: modelData
56  }
57 
58  Binding {
59  target: item; when: item
60  property: "width"; value: root.width
61  }
62 
63  Binding {
64  target: item; when: item
65  property: "height"; value: root.height
66  }
67 
68  Binding {
69  target: item; when: item
70  property: "orientation"; value: root.orientation
71  }
72  }
73  }
74 
75  states: [
76  State {
77  name: "rootSession"
78  when: root.session && !root.session.parentSession
79  },
80 
81  State {
82  name: "childSession"
83  when: root.session && root.session.parentSession !== null && root.session.live
84  && !root.session.surface
85  },
86 
87  State {
88  name: "childSessionReady"
89  when: root.session && root.session.parentSession !== null && root.session.live
90  && root.session.surface !== null
91  },
92 
93  State {
94  name: "childSessionZombie"
95  when: root.session && root.session.parentSession !== null && !root.session.live
96  }
97  ]
98 
99  transitions: [
100  Transition {
101  to: "childSessionReady"
102  ScriptAction { script: { if (!surfaceContainer.hadSurface) { animateIn(swipeFromBottom); } } }
103  },
104  Transition {
105  to: "childSessionZombie"
106  ScriptAction { script: { animateOut(); } }
107  }
108  ]
109 
110  function animateIn(component) {
111  var animation = component.createObject(root, { "container": root, });
112  animation.start();
113 
114  var tmp = d.animations;
115  tmp.push(animation);
116  d.animations = tmp;
117  }
118 
119  function animateOut() {
120  if (d.animations.length > 0) {
121  var tmp = d.animations;
122  var popped = tmp.pop();
123  popped.completed.connect(function() { root.session.release(); } );
124  popped.end();
125  d.animations = tmp;
126  }
127  }
128 
129  Component {
130  id: swipeFromBottom
131  SwipeFromBottomAnimation {}
132  }
133 
134  QtObject {
135  id: d
136  property var animations: []
137  }
138 }