on fcccc72 help sign in
unity8/qml/Stages/ApplicationWindow.qml
289 lines 13 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 Ubuntu.Components 1.1
19import Unity.Application 0.1
21FocusScope {
22 id: root
24 // to be read from outside
25 readonly property bool fullscreen: application ? application.fullscreen : false
26 property alias interactive: sessionContainer.interactive
27 property bool orientationChangesEnabled: d.supportsSurfaceResize ? d.surfaceOldEnoughToBeResized : true
29 // to be set from outside
30 property QtObject application
31 property int surfaceOrientationAngle
33 QtObject {
34 id: d
36 // helpers so that we don't have to check for the existence of an application everywhere
37 // (in order to avoid breaking qml binding due to a javascript exception)
38 readonly property string name: root.application ? root.application.name : ""
39 readonly property url icon: root.application ? root.application.icon : ""
40 readonly property int applicationState: root.application ? root.application.state : -1
41 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
42 readonly property url splashImage: root.application ? root.application.splashImage : ""
43 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
44 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
45 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
46 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
47 readonly property url defaultScreenshot: (root.application && root.application.defaultScreenshot !== undefined) ? root.application.defaultScreenshot : ""
49 // Whether the Application had a surface before but lost it.
50 property bool hadSurface: sessionContainer.surfaceContainer.hadSurface
52 property bool needToTakeScreenshot:
53 sessionContainer.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
54 && d.applicationState === ApplicationInfoInterface.Stopped
55 onNeedToTakeScreenshotChanged: {
56 if (needToTakeScreenshot) {
57 screenshotImage.take();
58 }
59 }
61 //FIXME - this is a hack to avoid the first few rendered frames as they
62 // might show the UI accommodating due to surface resizes on startup.
63 // Remove this when possible
64 property bool surfaceInitialized: false
66 property bool supportsSurfaceResize:
67 application &&
68 ((application.supportedOrientations & Qt.PortraitOrientation)
69 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
70 &&
71 ((application.supportedOrientations & Qt.LandscapeOrientation)
72 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
74 property bool surfaceOldEnoughToBeResized: false
75 }
77 Timer {
78 id: surfaceInitTimer
79 interval: 100
80 onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
81 }
83 Timer {
84 id: surfaceIsOldTimer
85 interval: 1000
86 onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
87 }
89 Image {
90 id: screenshotImage
91 objectName: "screenshotImage"
92 source: d.defaultScreenshot
93 anchors.fill: parent
94 antialiasing: !root.interactive
96 function take() {
97 // Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
98 // eg: "image://application/calculator-app/123456"
99 var timeMs = new Date().getTime();
100 source = "image://application/" + root.application.appId + "/" + timeMs;
101 }
103 // Save memory by using a half-resolution (thus quarter size) screenshot
104 sourceSize.width: root.width / 2
105 sourceSize.height: root.height / 2
106 }
108 Loader {
109 id: splashLoader
110 visible: active
111 active: false
112 anchors.fill: parent
113 sourceComponent: Component {
114 Splash {
115 id: splash
116 title: d.splashTitle ? d.splashTitle : d.name
117 imageSource: d.splashImage
118 icon: d.icon
119 showHeader: d.splashShowHeader
120 backgroundColor: d.splashColor
121 headerColor: d.splashColorHeader
122 footerColor: d.splashColorFooter
123 }
124 }
125 }
127 SessionContainer {
128 id: sessionContainer
129 // A fake application might not even have a session property.
130 session: application && application.session ? application.session : null
131 anchors.fill: parent
133 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
135 onSurfaceChanged: {
136 if (sessionContainer.surface) {
137 surfaceInitTimer.start();
138 } else {
139 d.surfaceInitialized = false;
140 }
141 }
143 focus: true
144 }
146 StateGroup {
147 id: stateGroup
148 objectName: "applicationWindowStateGroup"
149 states: [
150 State {
151 name: "void"
152 when:
153 d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
154 &&
155 screenshotImage.status !== Image.Ready
156 },
157 State {
158 name: "splashScreen"
159 when:
160 !d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
161 &&
162 screenshotImage.status !== Image.Ready
163 },
164 State {
165 name: "surface"
166 when:
167 (sessionContainer.surface && d.surfaceInitialized)
168 &&
169 (d.applicationState !== ApplicationInfoInterface.Stopped
170 || screenshotImage.status !== Image.Ready)
171 },
172 State {
173 name: "screenshot"
174 when:
175 screenshotImage.status === Image.Ready
176 &&
177 (d.applicationState === ApplicationInfoInterface.Stopped
178 || !sessionContainer.surface || !d.surfaceInitialized)
179 }
180 ]
182 transitions: [
183 Transition {
184 from: ""; to: "splashScreen"
185 PropertyAction { target: splashLoader; property: "active"; value: true }
186 PropertyAction { target: sessionContainer.surfaceContainer
187 property: "visible"; value: false }
188 },
189 Transition {
190 from: "splashScreen"; to: "surface"
191 SequentialAnimation {
192 PropertyAction { target: sessionContainer.surfaceContainer
193 property: "opacity"; value: 0.0 }
194 PropertyAction { target: sessionContainer.surfaceContainer
195 property: "visible"; value: true }
196 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
197 from: 0.0; to: 1.0
198 duration: UbuntuAnimation.BriskDuration }
199 ScriptAction { script: {
200 splashLoader.active = false;
201 surfaceIsOldTimer.start();
202 } }
203 }
204 },
205 Transition {
206 from: "surface"; to: "splashScreen"
207 SequentialAnimation {
208 ScriptAction { script: {
209 surfaceIsOldTimer.stop();
210 d.surfaceOldEnoughToBeResized = false;
211 splashLoader.active = true;
212 sessionContainer.surfaceContainer.visible = true;
213 } }
214 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
215 from: 0.0; to: 1.0
216 duration: UbuntuAnimation.BriskDuration }
217 PropertyAction { target: sessionContainer.surfaceContainer
218 property: "visible"; value: false }
219 }
220 },
221 Transition {
222 from: "surface"; to: "screenshot"
223 SequentialAnimation {
224 ScriptAction { script: {
225 surfaceIsOldTimer.stop();
226 d.surfaceOldEnoughToBeResized = false;
227 screenshotImage.visible = true;
228 } }
229 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
230 from: 0.0; to: 1.0
231 duration: UbuntuAnimation.BriskDuration }
232 ScriptAction { script: {
233 sessionContainer.surfaceContainer.visible = false;
234 if (sessionContainer.session) { sessionContainer.session.release(); }
235 } }
236 }
237 },
238 Transition {
239 from: "screenshot"; to: "surface"
240 SequentialAnimation {
241 PropertyAction { target: sessionContainer.surfaceContainer
242 property: "visible"; value: true }
243 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
244 from: 1.0; to: 0.0
245 duration: UbuntuAnimation.BriskDuration }
246 ScriptAction { script: {
247 screenshotImage.visible = false;
248 screenshotImage.source = "";
249 surfaceIsOldTimer.start();
250 } }
251 }
252 },
253 Transition {
254 from: "splashScreen"; to: "screenshot"
255 SequentialAnimation {
256 PropertyAction { target: screenshotImage
257 property: "visible"; value: true }
258 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
259 from: 0.0; to: 1.0
260 duration: UbuntuAnimation.BriskDuration }
261 PropertyAction { target: splashLoader; property: "active"; value: false }
262 }
263 },
264 Transition {
265 from: "surface"; to: "void"
266 ScriptAction { script: {
267 surfaceIsOldTimer.stop();
268 d.surfaceOldEnoughToBeResized = false;
269 sessionContainer.surfaceContainer.visible = false;
270 if (sessionContainer.session) { sessionContainer.session.release(); }
271 } }
272 },
273 Transition {
274 from: "void"; to: "surface"
275 SequentialAnimation {
276 PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
277 PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
278 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
279 from: 0.0; to: 1.0
280 duration: UbuntuAnimation.BriskDuration }
281 ScriptAction { script: {
282 surfaceIsOldTimer.start();
283 } }
284 }
285 }
286 ]
287 }