on 436b607 help sign in
unity8/qml/Stages/ApplicationWindow.qml
253 lines 11 kB history raw
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 */
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
28 // to be set from outside
29 property QtObject application
30 property int orientation
32 QtObject {
33 id: d
35 // helpers so that we don't have to check for the existence of an application everywhere
36 // (in order to avoid breaking qml binding due to a javascript exception)
37 readonly property string name: root.application ? root.application.name : ""
38 readonly property url icon: root.application ? root.application.icon : ""
39 readonly property int applicationState: root.application ? root.application.state : -1
40 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
41 readonly property url splashImage: root.application ? root.application.splashImage : ""
42 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
43 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
44 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
45 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
46 readonly property url defaultScreenshot: (root.application && root.application.defaultScreenshot !== undefined) ? root.application.defaultScreenshot : ""
48 // Whether the Application had a surface before but lost it.
49 property bool hadSurface: sessionContainer.surfaceContainer.hadSurface
51 property bool needToTakeScreenshot:
52 sessionContainer.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
53 && d.applicationState === ApplicationInfoInterface.Stopped
54 onNeedToTakeScreenshotChanged: {
55 if (needToTakeScreenshot) {
56 screenshotImage.take();
57 }
58 }
60 //FIXME - this is a hack to avoid the first few rendered frames as they
61 // might show the UI accommodating due to surface resizes on startup.
62 // Remove this when possible
63 property bool surfaceInitialized: false
65 }
67 Timer {
68 id: surfaceInitTimer
69 interval: 100
70 onTriggered: { if (sessionContainer.surface) {d.surfaceInitialized = true;} }
71 }
73 Image {
74 id: screenshotImage
75 objectName: "screenshotImage"
76 source: d.defaultScreenshot
77 anchors.fill: parent
78 antialiasing: !root.interactive
80 function take() {
81 // Format: "image://application/$APP_ID/$CURRENT_TIME_MS"
82 // eg: "image://application/calculator-app/123456"
83 var timeMs = new Date().getTime();
84 source = "image://application/" + root.application.appId + "/" + timeMs;
85 }
87 // Save memory by using a half-resolution (thus quarter size) screenshot
88 sourceSize.width: root.width / 2
89 sourceSize.height: root.height / 2
90 }
92 Loader {
93 id: splashLoader
94 visible: active
95 active: false
96 anchors.fill: parent
97 sourceComponent: Component {
98 Splash {
99 id: splash
100 title: d.splashTitle ? d.splashTitle : d.name
101 imageSource: d.splashImage
102 icon: d.icon
103 showHeader: d.splashShowHeader
104 backgroundColor: d.splashColor
105 headerColor: d.splashColorHeader
106 footerColor: d.splashColorFooter
107 }
108 }
109 }
111 SessionContainer {
112 id: sessionContainer
113 session: application ? application.session : null
114 anchors.fill: parent
115 orientation: root.orientation
117 onSurfaceChanged: {
118 if (sessionContainer.surface) {
119 surfaceInitTimer.start();
120 } else {
121 d.surfaceInitialized = false;
122 }
123 }
125 focus: true
126 }
128 StateGroup {
129 id: stateGroup
130 objectName: "applicationWindowStateGroup"
131 states: [
132 State {
133 name: "void"
134 when:
135 d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
136 &&
137 screenshotImage.status !== Image.Ready
138 },
139 State {
140 name: "splashScreen"
141 when:
142 !d.hadSurface && (!sessionContainer.surface || !d.surfaceInitialized)
143 &&
144 screenshotImage.status !== Image.Ready
145 },
146 State {
147 name: "surface"
148 when:
149 (sessionContainer.surface && d.surfaceInitialized)
150 &&
151 (d.applicationState !== ApplicationInfoInterface.Stopped
152 || screenshotImage.status !== Image.Ready)
153 },
154 State {
155 name: "screenshot"
156 when:
157 screenshotImage.status === Image.Ready
158 &&
159 (d.applicationState === ApplicationInfoInterface.Stopped
160 || !sessionContainer.surface || !d.surfaceInitialized)
161 }
162 ]
164 transitions: [
165 Transition {
166 from: ""; to: "splashScreen"
167 PropertyAction { target: splashLoader; property: "active"; value: true }
168 PropertyAction { target: sessionContainer.surfaceContainer
169 property: "visible"; value: false }
170 },
171 Transition {
172 from: "splashScreen"; to: "surface"
173 SequentialAnimation {
174 PropertyAction { target: sessionContainer.surfaceContainer
175 property: "opacity"; value: 0.0 }
176 PropertyAction { target: sessionContainer.surfaceContainer
177 property: "visible"; value: true }
178 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
179 from: 0.0; to: 1.0
180 duration: UbuntuAnimation.BriskDuration }
181 PropertyAction { target: splashLoader; property: "active"; value: false }
182 }
183 },
184 Transition {
185 from: "surface"; to: "splashScreen"
186 SequentialAnimation {
187 PropertyAction { target: splashLoader; property: "active"; value: true }
188 PropertyAction { target: sessionContainer.surfaceContainer
189 property: "visible"; value: true }
190 UbuntuNumberAnimation { target: splashLoader; property: "opacity";
191 from: 0.0; to: 1.0
192 duration: UbuntuAnimation.BriskDuration }
193 PropertyAction { target: sessionContainer.surfaceContainer
194 property: "visible"; value: false }
195 }
196 },
197 Transition {
198 from: "surface"; to: "screenshot"
199 SequentialAnimation {
200 PropertyAction { target: screenshotImage
201 property: "visible"; value: true }
202 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
203 from: 0.0; to: 1.0
204 duration: UbuntuAnimation.BriskDuration }
205 PropertyAction { target: sessionContainer.surfaceContainer
206 property: "visible"; value: false }
207 ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
208 }
209 },
210 Transition {
211 from: "screenshot"; to: "surface"
212 SequentialAnimation {
213 PropertyAction { target: sessionContainer.surfaceContainer
214 property: "visible"; value: true }
215 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
216 from: 1.0; to: 0.0
217 duration: UbuntuAnimation.BriskDuration }
218 PropertyAction { target: screenshotImage; property: "visible"; value: false }
219 PropertyAction { target: screenshotImage; property: "source"; value: "" }
220 }
221 },
222 Transition {
223 from: "splashScreen"; to: "screenshot"
224 SequentialAnimation {
225 PropertyAction { target: screenshotImage
226 property: "visible"; value: true }
227 UbuntuNumberAnimation { target: screenshotImage; property: "opacity";
228 from: 0.0; to: 1.0
229 duration: UbuntuAnimation.BriskDuration }
230 PropertyAction { target: splashLoader; property: "active"; value: false }
231 }
232 },
233 Transition {
234 from: "surface"; to: "void"
235 SequentialAnimation {
236 PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: false }
237 ScriptAction { script: { if (sessionContainer.session) { sessionContainer.session.release(); } } }
238 }
239 },
240 Transition {
241 from: "void"; to: "surface"
242 SequentialAnimation {
243 PropertyAction { target: sessionContainer.surfaceContainer; property: "opacity"; value: 0.0 }
244 PropertyAction { target: sessionContainer.surfaceContainer; property: "visible"; value: true }
245 UbuntuNumberAnimation { target: sessionContainer.surfaceContainer; property: "opacity";
246 from: 0.0; to: 1.0
247 duration: UbuntuAnimation.BriskDuration }
248 }
249 }
250 ]
251 }