2 * Copyright 2014-2016 Canonical Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3
19 import Unity.Application 0.1
23 implicitWidth: requestedWidth
24 implicitHeight: requestedHeight
26 // to be read from outside
27 property alias interactive: surfaceContainer.interactive
28 property bool orientationChangesEnabled: d.supportsSurfaceResize ? d.surfaceOldEnoughToBeResized : true
29 readonly property string title: surface && surface.name !== "" ? surface.name : d.name
30 readonly property QtObject focusedSurface: d.focusedSurface.surface
31 readonly property alias surfaceInitialized: d.surfaceInitialized
33 // to be set from outside
34 property QtObject surface
35 property QtObject application
36 property int surfaceOrientationAngle
37 property int requestedWidth: -1
38 property int requestedHeight: -1
39 property real splashRotation: 0
41 readonly property int minimumWidth: surface ? surface.minimumWidth : 0
42 readonly property int minimumHeight: surface ? surface.minimumHeight : 0
43 readonly property int maximumWidth: surface ? surface.maximumWidth : 0
44 readonly property int maximumHeight: surface ? surface.maximumHeight : 0
45 readonly property int widthIncrement: surface ? surface.widthIncrement : 0
46 readonly property int heightIncrement: surface ? surface.heightIncrement : 0
49 // The order in which the instructions are executed here matters, to that the correct state
50 // transitions in stateGroup take place.
51 // More specifically, the moment surfaceContainer.surface gets updated relative to the
52 // other instructions.
54 surfaceContainer.surface = surface;
55 d.liveSurface = surface.live;
57 surfaceInitTimer.start();
59 if (d.surfaceInitialized) {
62 d.surfaceInitialized = false;
63 surfaceContainer.surface = null;
70 property bool liveSurface: false;
71 property var con: Connections {
73 onLiveChanged: d.liveSurface = root.surface.live
75 // using liveSurface instead of root.surface.live because with the latter
76 // this expression is not reevaluated when root.surface changes
77 readonly property bool needToTakeScreenshot: root.surface && d.surfaceInitialized && !d.liveSurface
78 && applicationState !== ApplicationInfoInterface.Running
79 onNeedToTakeScreenshotChanged: {
80 if (needToTakeScreenshot && screenshotImage.status === Image.Null) {
81 screenshotImage.take();
85 // helpers so that we don't have to check for the existence of an application everywhere
86 // (in order to avoid breaking qml binding due to a javascript exception)
87 readonly property string name: root.application ? root.application.name : ""
88 readonly property url icon: root.application ? root.application.icon : ""
89 readonly property int applicationState: root.application ? root.application.state : -1
90 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
91 readonly property url splashImage: root.application ? root.application.splashImage : ""
92 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
93 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
94 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
95 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
97 // Whether the Application had a surface before but lost it.
98 property bool hadSurface: false
100 //FIXME - this is a hack to avoid the first few rendered frames as they
101 // might show the UI accommodating due to surface resizes on startup.
102 // Remove this when possible
103 property bool surfaceInitialized: false
105 readonly property bool supportsSurfaceResize:
107 ((application.supportedOrientations & Qt.PortraitOrientation)
108 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
110 ((application.supportedOrientations & Qt.LandscapeOrientation)
111 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
113 property bool surfaceOldEnoughToBeResized: false
115 property Item focusedSurface: promptSurfacesRepeater.count === 0 ? surfaceContainer
116 : promptSurfacesRepeater.first
117 onFocusedSurfaceChanged: {
118 if (focusedSurface) {
119 focusedSurface.focus = true;
125 target: root.application
126 property: "initialSurfaceSize"
127 value: Qt.size(root.requestedWidth, root.requestedHeight)
134 if (root.surface && root.surface.live) {d.surfaceInitialized = true;}
139 id: surfaceIsOldTimer
141 onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
146 objectName: "screenshotImage"
148 fillMode: Image.PreserveAspectCrop
149 horizontalAlignment: Image.AlignLeft
150 verticalAlignment: Image.AlignTop
151 antialiasing: !root.interactive
155 // Save memory by using a half-resolution (thus quarter size) screenshot.
156 // Do not make this a binding, we can only take the screenshot once!
157 surfaceContainer.grabToImage(
159 screenshotImage.source = result.url;
161 Qt.size(root.width / 2, root.height / 2));
170 z: screenshotImage.z + 1
171 sourceComponent: Component {
174 title: d.splashTitle ? d.splashTitle : d.name
175 imageSource: d.splashImage
177 showHeader: d.splashShowHeader
178 backgroundColor: d.splashColor
179 headerColor: d.splashColorHeader
180 footerColor: d.splashColorFooter
182 rotation: root.splashRotation
183 anchors.centerIn: parent
184 width: rotation == 0 || rotation == 180 ? root.width : root.height
185 height: rotation == 0 || rotation == 180 ? root.height : root.width
193 z: splashLoader.z + 1
194 requestedWidth: root.requestedWidth
195 requestedHeight: root.requestedHeight
196 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
200 id: promptSurfacesRepeater
201 objectName: "promptSurfacesRepeater"
202 // show only along with the top-most application surface
204 if (root.application && root.surface === root.application.surfaceList.first) {
205 return root.application.promptSurfaceList;
210 delegate: SurfaceContainer {
211 id: promptSurfaceContainer
212 interactive: index === 0 && root.interactive
213 surface: model.surface
216 requestedWidth: root.requestedWidth
217 requestedHeight: root.requestedHeight
218 isPromptSurface: true
219 z: surfaceContainer.z + (promptSurfacesRepeater.count - index)
220 property int index: model.index
221 onIndexChanged: updateFirst()
222 Component.onCompleted: updateFirst()
223 function updateFirst() {
225 promptSurfacesRepeater.first = promptSurfaceContainer;
234 property Item first: null
239 objectName: "applicationWindowStateGroup"
244 d.hadSurface && (!root.surface || !d.surfaceInitialized)
246 screenshotImage.status !== Image.Ready
251 !d.hadSurface && (!root.surface || !d.surfaceInitialized)
253 screenshotImage.status !== Image.Ready
258 (root.surface && d.surfaceInitialized)
261 (d.applicationState !== ApplicationInfoInterface.Running
262 && screenshotImage.status !== Image.Ready))
265 implicitWidth: surfaceContainer.implicitWidth
266 implicitHeight: surfaceContainer.implicitHeight
272 screenshotImage.status === Image.Ready
274 (d.applicationState !== ApplicationInfoInterface.Running
275 || !root.surface || !d.surfaceInitialized)
278 // This is a dead end. From here we expect the surface to be removed from the model
279 // shortly after we stop referencing to it in our SurfaceContainer.
282 // The surface died while the application is running. It must have been closed
283 // by the shell or the application decided to destroy it by itself
284 root.surface && d.surfaceInitialized && !d.liveSurface
285 && d.applicationState === ApplicationInfoInterface.Running
291 from: ""; to: "splashScreen"
292 PropertyAction { target: splashLoader; property: "active"; value: true }
293 PropertyAction { target: surfaceContainer
294 property: "visible"; value: false }
297 from: "splashScreen"; to: "surface"
298 SequentialAnimation {
299 PropertyAction { target: surfaceContainer
300 property: "opacity"; value: 0.0 }
301 PropertyAction { target: surfaceContainer
302 property: "visible"; value: true }
303 UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
305 duration: UbuntuAnimation.BriskDuration }
306 ScriptAction { script: {
307 splashLoader.active = false;
308 surfaceIsOldTimer.start();
313 from: "surface"; to: "splashScreen"
314 SequentialAnimation {
315 ScriptAction { script: {
316 surfaceIsOldTimer.stop();
317 d.surfaceOldEnoughToBeResized = false;
318 splashLoader.active = true;
319 surfaceContainer.visible = true;
321 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
323 duration: UbuntuAnimation.BriskDuration }
324 PropertyAction { target: surfaceContainer
325 property: "visible"; value: false }
329 from: "surface"; to: "screenshot"
330 SequentialAnimation {
331 ScriptAction { script: {
332 surfaceIsOldTimer.stop();
333 d.surfaceOldEnoughToBeResized = false;
334 screenshotImage.visible = true;
336 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
338 duration: UbuntuAnimation.BriskDuration }
339 ScriptAction { script: {
340 surfaceContainer.visible = false;
341 surfaceContainer.surface = null;
347 from: "screenshot"; to: "surface"
348 SequentialAnimation {
349 PropertyAction { target: surfaceContainer
350 property: "visible"; value: true }
351 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
353 duration: UbuntuAnimation.BriskDuration }
354 ScriptAction { script: {
355 screenshotImage.visible = false;
356 screenshotImage.source = "";
357 surfaceIsOldTimer.start();
362 from: "splashScreen"; to: "screenshot"
363 SequentialAnimation {
364 PropertyAction { target: screenshotImage
365 property: "visible"; value: true }
366 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
368 duration: UbuntuAnimation.BriskDuration }
369 PropertyAction { target: splashLoader; property: "active"; value: false }
373 from: "surface"; to: "void"
374 ScriptAction { script: {
375 surfaceIsOldTimer.stop();
376 d.surfaceOldEnoughToBeResized = false;
377 surfaceContainer.visible = false;
381 from: "void"; to: "surface"
382 SequentialAnimation {
383 PropertyAction { target: surfaceContainer; property: "opacity"; value: 0.0 }
384 PropertyAction { target: surfaceContainer; property: "visible"; value: true }
385 UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
387 duration: UbuntuAnimation.BriskDuration }
388 ScriptAction { script: {
389 surfaceIsOldTimer.start();
395 SequentialAnimation {
396 ScriptAction { script: {
397 surfaceContainer.visible = false;
398 surfaceContainer.surface = null;