on 6ca9421 help sign in
unity8/qml/Stages/SessionContainer.qml
154 lines 4.7 kB history raw
1/*
2 * Copyright 2014-2015 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*/
17import QtQuick 2.0
18import "Animations"
20FocusScope {
21 id: root
22 objectName: "sessionContainer"
23 implicitWidth: _surfaceContainer.implicitWidth
24 implicitHeight: _surfaceContainer.implicitHeight
25 property QtObject session
26 readonly property var childSessions: session ? session.childSessions : null
27 readonly property alias surface: _surfaceContainer.surface
28 property alias interactive: _surfaceContainer.interactive
29 property alias surfaceOrientationAngle: _surfaceContainer.surfaceOrientationAngle
30 property alias resizeSurface: _surfaceContainer.resizeSurface
32 readonly property alias surfaceContainer: _surfaceContainer
33 SurfaceContainer {
34 id: _surfaceContainer
35 anchors.fill: parent
36 surface: session ? session.surface : null
37 }
39 Repeater {
40 id: childSessionsRepeater
41 model: root.childSessions
43 delegate: Loader {
44 objectName: "childDelegate" + index
45 anchors.fill: surfaceContainer
47 // Only way to do recursive qml items.
48 source: Qt.resolvedUrl("SessionContainer.qml")
50 z: index
52 // Since a Loader is a FocusScope, propagate its focus to the loaded Item
53 Binding {
54 target: item; when: item
55 property: "focus"; value: focus
56 }
58 Binding {
59 target: item; when: item
60 property: "interactive"; value: index == (childSessionsRepeater.count - 1) && root.interactive
61 }
63 Binding {
64 target: item; when: item
65 property: "session"; value: modelData
66 }
68 Binding {
69 target: item; when: item
70 property: "width"; value: root.width
71 }
73 Binding {
74 target: item; when: item
75 property: "height"; value: root.height
76 }
77 }
78 }
80 states: [
81 State {
82 name: "rootSession"
83 when: root.session && !root.session.parentSession
84 },
86 State {
87 name: "childSession"
88 when: root.session && root.session.parentSession !== null && root.session.live
89 && !root.session.surface
90 },
92 State {
93 name: "childSessionReady"
94 when: root.session && root.session.parentSession !== null && root.session.live
95 && root.session.surface !== null
96 },
98 State {
99 name: "childSessionZombie"
100 when: root.session && root.session.parentSession !== null && !root.session.live
101 }
102 ]
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 ]
115 function animateIn(component) {
116 var animation = component.createObject(root, { "container": root, });
117 animation.start();
119 var tmp = d.animations;
120 tmp.push(animation);
121 d.animations = tmp;
122 }
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 }
134 Component {
135 id: swipeFromBottom
136 SwipeFromBottomAnimation {}
137 }
139 QtObject {
140 id: d
141 property var animations: []
143 property var focusedChild: {
144 if (childSessionsRepeater.count == 0) {
145 return _surfaceContainer;
146 } else {
147 return childSessionsRepeater.itemAt(childSessionsRepeater.count - 1);
148 }
149 }
150 onFocusedChildChanged: {
151 focusedChild.focus = true;
152 }
153 }