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  Component.onDestruction: {
74  root.session.surface.forceActiveFocus();
75  }
76  }
77  }
78 
79  states: [
80  State {
81  name: "rootSession"
82  when: root.session && !root.session.parentSession
83  },
84 
85  State {
86  name: "childSession"
87  when: root.session && root.session.parentSession !== null && root.session.live
88  && !root.session.surface
89  },
90 
91  State {
92  name: "childSessionReady"
93  when: root.session && root.session.parentSession !== null && root.session.live
94  && root.session.surface !== null
95  },
96 
97  State {
98  name: "childSessionZombie"
99  when: root.session && root.session.parentSession !== null && !root.session.live
100  }
101  ]
102 
103  transitions: [
104  Transition {
105  to: "childSessionReady"
106  ScriptAction { script: { if (!surfaceContainer.hadSurface) { animateIn(swipeFromBottom); } } }
107  },
108  Transition {
109  to: "childSessionZombie"
110  ScriptAction { script: { animateOut(); } }
111  }
112  ]
113 
114  function animateIn(component) {
115  var animation = component.createObject(root, { "container": root, });
116  animation.start();
117 
118  var tmp = d.animations;
119  tmp.push(animation);
120  d.animations = tmp;
121  }
122 
123  function animateOut() {
124  if (d.animations.length > 0) {
125  var tmp = d.animations;
126  var popped = tmp.pop();
127  popped.completed.connect(function() { root.session.release(); } );
128  popped.end();
129  d.animations = tmp;
130  }
131  }
132 
133  Component {
134  id: swipeFromBottom
135  SwipeFromBottomAnimation {}
136  }
137 
138  QtObject {
139  id: d
140  property var animations: []
141  }
142 }