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