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 bool interactive: true
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  Binding {
38  target: surfaceContainer.surface
39  when: surfaceContainer.surface
40  property: "enabled"
41  value: root.interactive
42  }
43  Binding {
44  target: surfaceContainer.surface
45  when: surfaceContainer.surface
46  property: "focus"
47  value: root.interactive
48  }
49 
50  Repeater {
51  model: root.childSessions
52 
53  delegate: Loader {
54  objectName: "childDelegate" + index
55  anchors.fill: surfaceContainer
56 
57  // Only way to do recursive qml items.
58  source: Qt.resolvedUrl("SessionContainer.qml")
59 
60  Binding {
61  target: item; when: item
62  property: "interactive"; value: root.interactive
63  }
64 
65  Binding {
66  target: item; when: item
67  property: "session"; value: modelData
68  }
69 
70  Binding {
71  target: item; when: item
72  property: "width"; value: root.width
73  }
74 
75  Binding {
76  target: item; when: item
77  property: "height"; value: root.height
78  }
79 
80  Binding {
81  target: item; when: item
82  property: "orientation"; value: root.orientation
83  }
84  }
85  }
86 
87  states: [
88  State {
89  name: "rootSession"
90  when: root.session && !root.session.parentSession
91  },
92 
93  State {
94  name: "childSession"
95  when: root.session && root.session.parentSession !== null && root.session.live
96  && !root.session.surface
97  },
98 
99  State {
100  name: "childSessionReady"
101  when: root.session && root.session.parentSession !== null && root.session.live
102  && root.session.surface !== null
103  },
104 
105  State {
106  name: "childSessionZombie"
107  when: root.session && root.session.parentSession !== null && !root.session.live
108  }
109  ]
110 
111  transitions: [
112  Transition {
113  to: "childSessionReady"
114  ScriptAction { script: { if (!surfaceContainer.hadSurface) { animateIn(swipeFromBottom); } } }
115  },
116  Transition {
117  to: "childSessionZombie"
118  ScriptAction { script: { animateOut(); } }
119  }
120  ]
121 
122  function animateIn(component) {
123  var animation = component.createObject(root, { "container": root, });
124  animation.start();
125 
126  var tmp = d.animations;
127  tmp.push(animation);
128  d.animations = tmp;
129  }
130 
131  function animateOut() {
132  if (d.animations.length > 0) {
133  var tmp = d.animations;
134  var popped = tmp.pop();
135  popped.completed.connect(function() { root.session.release(); } );
136  popped.end();
137  d.animations = tmp;
138  }
139  }
140 
141  Component {
142  id: swipeFromBottom
143  SwipeFromBottomAnimation {}
144  }
145 
146  QtObject {
147  id: d
148  property var animations: []
149  }
150 }