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
32 // to be set from outside
33 property QtObject surface
34 property QtObject application
35 property int surfaceOrientationAngle
36 property int requestedWidth: -1
37 property int requestedHeight: -1
38 property real splashRotation: 0
40 readonly property int minimumWidth: surface ? surface.minimumWidth : 0
41 readonly property int minimumHeight: surface ? surface.minimumHeight : 0
42 readonly property int maximumWidth: surface ? surface.maximumWidth : 0
43 readonly property int maximumHeight: surface ? surface.maximumHeight : 0
44 readonly property int widthIncrement: surface ? surface.widthIncrement : 0
45 readonly property int heightIncrement: surface ? surface.heightIncrement : 0
48 // The order in which the instructions are executed here matters, to that the correct state
49 // transitions in stateGroup take place.
50 // More specifically, the moment surfaceContainer.surface gets updated relative to the
51 // other instructions.
53 surfaceContainer.surface = surface;
54 d.liveSurface = surface.live;
56 surfaceInitTimer.start();
58 if (d.surfaceInitialized) {
61 d.surfaceInitialized = false;
62 surfaceContainer.surface = null;
69 property bool liveSurface: false;
70 property var con: Connections {
72 onLiveChanged: d.liveSurface = root.surface.live
74 // using liveSurface instead of root.surface.live because with the latter
75 // this expression is not reevaluated when root.surface changes
76 readonly property bool needToTakeScreenshot: root.surface && d.surfaceInitialized && !d.liveSurface
77 && applicationState !== ApplicationInfoInterface.Running
78 onNeedToTakeScreenshotChanged: {
79 if (needToTakeScreenshot && screenshotImage.status === Image.Null) {
80 screenshotImage.take();
84 // helpers so that we don't have to check for the existence of an application everywhere
85 // (in order to avoid breaking qml binding due to a javascript exception)
86 readonly property string name: root.application ? root.application.name : ""
87 readonly property url icon: root.application ? root.application.icon : ""
88 readonly property int applicationState: root.application ? root.application.state : -1
89 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
90 readonly property url splashImage: root.application ? root.application.splashImage : ""
91 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
92 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
93 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
94 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
96 // Whether the Application had a surface before but lost it.
97 property bool hadSurface: false
99 //FIXME - this is a hack to avoid the first few rendered frames as they
100 // might show the UI accommodating due to surface resizes on startup.
101 // Remove this when possible
102 property bool surfaceInitialized: false
104 readonly property bool supportsSurfaceResize:
106 ((application.supportedOrientations & Qt.PortraitOrientation)
107 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
109 ((application.supportedOrientations & Qt.LandscapeOrientation)
110 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
112 property bool surfaceOldEnoughToBeResized: false
114 property Item focusedSurface: promptSurfacesRepeater.count === 0 ? surfaceContainer
115 : promptSurfacesRepeater.first
116 onFocusedSurfaceChanged: {
117 if (focusedSurface) {
118 focusedSurface.focus = true;
124 target: root.application
125 property: "initialSurfaceSize"
126 value: Qt.size(root.requestedWidth, root.requestedHeight)
133 if (root.surface && root.surface.live) {d.surfaceInitialized = true;}
138 id: surfaceIsOldTimer
140 onTriggered: { if (stateGroup.state === "surface") { d.surfaceOldEnoughToBeResized = true; } }
145 objectName: "screenshotImage"
147 fillMode: Image.PreserveAspectCrop
148 horizontalAlignment: Image.AlignLeft
149 verticalAlignment: Image.AlignTop
150 antialiasing: !root.interactive
154 // Save memory by using a half-resolution (thus quarter size) screenshot.
155 // Do not make this a binding, we can only take the screenshot once!
156 surfaceContainer.grabToImage(
158 screenshotImage.source = result.url;
160 Qt.size(root.width / 2, root.height / 2));
169 z: screenshotImage.z + 1
170 sourceComponent: Component {
173 title: d.splashTitle ? d.splashTitle : d.name
174 imageSource: d.splashImage
176 showHeader: d.splashShowHeader
177 backgroundColor: d.splashColor
178 headerColor: d.splashColorHeader
179 footerColor: d.splashColorFooter
181 rotation: root.splashRotation
182 anchors.centerIn: parent
183 width: rotation == 0 || rotation == 180 ? root.width : root.height
184 height: rotation == 0 || rotation == 180 ? root.height : root.width
192 z: splashLoader.z + 1
193 requestedWidth: root.requestedWidth
194 requestedHeight: root.requestedHeight
195 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
199 id: promptSurfacesRepeater
200 objectName: "promptSurfacesRepeater"
201 // show only along with the top-most application surface
203 if (root.application && root.surface === root.application.surfaceList.first) {
204 return root.application.promptSurfaceList;
209 delegate: SurfaceContainer {
210 id: promptSurfaceContainer
211 interactive: index === 0 && root.interactive
212 surface: model.surface
215 requestedWidth: root.requestedWidth
216 requestedHeight: root.requestedHeight
217 isPromptSurface: true
218 z: surfaceContainer.z + (promptSurfacesRepeater.count - index)
219 property int index: model.index
220 onIndexChanged: updateFirst()
221 Component.onCompleted: updateFirst()
222 function updateFirst() {
224 promptSurfacesRepeater.first = promptSurfaceContainer;
233 property Item first: null
238 objectName: "applicationWindowStateGroup"
243 d.hadSurface && (!root.surface || !d.surfaceInitialized)
245 screenshotImage.status !== Image.Ready
250 !d.hadSurface && (!root.surface || !d.surfaceInitialized)
252 screenshotImage.status !== Image.Ready
257 (root.surface && d.surfaceInitialized)
260 (d.applicationState !== ApplicationInfoInterface.Running
261 && screenshotImage.status !== Image.Ready))
264 implicitWidth: surfaceContainer.implicitWidth
265 implicitHeight: surfaceContainer.implicitHeight
271 screenshotImage.status === Image.Ready
273 (d.applicationState !== ApplicationInfoInterface.Running
274 || !root.surface || !d.surfaceInitialized)
277 // This is a dead end. From here we expect the surface to be removed from the model
278 // shortly after we stop referencing to it in our SurfaceContainer.
281 // The surface died while the application is running. It must have been closed
282 // by the shell or the application decided to destroy it by itself
283 root.surface && d.surfaceInitialized && !d.liveSurface
284 && d.applicationState === ApplicationInfoInterface.Running
290 from: ""; to: "splashScreen"
291 PropertyAction { target: splashLoader; property: "active"; value: true }
292 PropertyAction { target: surfaceContainer
293 property: "visible"; value: false }
296 from: "splashScreen"; to: "surface"
297 SequentialAnimation {
298 PropertyAction { target: surfaceContainer
299 property: "opacity"; value: 0.0 }
300 PropertyAction { target: surfaceContainer
301 property: "visible"; value: true }
302 UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
304 duration: UbuntuAnimation.BriskDuration }
305 ScriptAction { script: {
306 splashLoader.active = false;
307 surfaceIsOldTimer.start();
312 from: "surface"; to: "splashScreen"
313 SequentialAnimation {
314 ScriptAction { script: {
315 surfaceIsOldTimer.stop();
316 d.surfaceOldEnoughToBeResized = false;
317 splashLoader.active = true;
318 surfaceContainer.visible = true;
320 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
322 duration: UbuntuAnimation.BriskDuration }
323 PropertyAction { target: surfaceContainer
324 property: "visible"; value: false }
328 from: "surface"; to: "screenshot"
329 SequentialAnimation {
330 ScriptAction { script: {
331 surfaceIsOldTimer.stop();
332 d.surfaceOldEnoughToBeResized = false;
333 screenshotImage.visible = true;
335 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
337 duration: UbuntuAnimation.BriskDuration }
338 ScriptAction { script: {
339 surfaceContainer.visible = false;
340 surfaceContainer.surface = null;
346 from: "screenshot"; to: "surface"
347 SequentialAnimation {
348 PropertyAction { target: surfaceContainer
349 property: "visible"; value: true }
350 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
352 duration: UbuntuAnimation.BriskDuration }
353 ScriptAction { script: {
354 screenshotImage.visible = false;
355 screenshotImage.source = "";
356 surfaceIsOldTimer.start();
361 from: "splashScreen"; to: "screenshot"
362 SequentialAnimation {
363 PropertyAction { target: screenshotImage
364 property: "visible"; value: true }
365 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
367 duration: UbuntuAnimation.BriskDuration }
368 PropertyAction { target: splashLoader; property: "active"; value: false }
372 from: "surface"; to: "void"
373 ScriptAction { script: {
374 surfaceIsOldTimer.stop();
375 d.surfaceOldEnoughToBeResized = false;
376 surfaceContainer.visible = false;
380 from: "void"; to: "surface"
381 SequentialAnimation {
382 PropertyAction { target: surfaceContainer; property: "opacity"; value: 0.0 }
383 PropertyAction { target: surfaceContainer; property: "visible"; value: true }
384 UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
386 duration: UbuntuAnimation.BriskDuration }
387 ScriptAction { script: {
388 surfaceIsOldTimer.start();
394 SequentialAnimation {
395 ScriptAction { script: {
396 surfaceContainer.visible = false;
397 surfaceContainer.surface = null;