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/>.
18import Lomiri.Components 1.3
19import QtMir.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
32 readonly property bool supportsResize: d.surfaceOldEnoughToBeResized && d.supportsSurfaceResize
34 // to be set from outside
35 property QtObject surface
36 property QtObject application
37 property int surfaceOrientationAngle
38 property int requestedWidth: -1
39 property int requestedHeight: -1
40 property real splashRotation: 0
41 property bool clip: false
43 readonly property int minimumWidth: surface ? surface.minimumWidth : 0
44 readonly property int minimumHeight: surface ? surface.minimumHeight : 0
45 readonly property int maximumWidth: surface ? surface.maximumWidth : 0
46 readonly property int maximumHeight: surface ? surface.maximumHeight : 0
47 readonly property int widthIncrement: surface ? surface.widthIncrement : 0
48 readonly property int heightIncrement: surface ? surface.heightIncrement : 0
50 signal sizeChanged(size size)
53 let width = Math.max(size.width, root.minimumWidth)
54 width = Math.min(width, root.maximumWidth)
55 let height = Math.max(size.height, root.minimumHeight)
56 height = Math.min(height, root.maximumHeight)
58 implicitHeight = height
63 onReady: d.surfaceUp()
66 Component.onCompleted: {
68 if (surface && surface.live && surface.isReady) {
74 // The order in which the instructions are executed here matters, to that the correct state
75 // transitions in stateGroup take place.
76 // More specifically, the moment surfaceContainer.surface gets updated relative to the
77 // other instructions.
79 surfaceContainer.surface = surface;
81 d.surfaceInitialized = false;
82 surfaceContainer.surface = null;
89 // helpers so that we don't have to check for the existence of an application everywhere
90 // (in order to avoid breaking qml binding due to a javascript exception)
91 readonly property string name: root.application ? root.application.name : ""
92 readonly property url icon: root.application ? root.application.icon : ""
93 readonly property int applicationState: root.application ? root.application.state : -1
94 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
95 readonly property url splashImage: root.application ? root.application.splashImage : ""
96 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
97 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
98 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
99 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
101 // Whether the Application had a surface before but lost it.
102 property bool hadSurface: false
104 //FIXME - this is a hack to avoid the first few rendered frames as they
105 // might show the UI accommodating due to surface resizes on startup.
106 // Remove this when possible
107 property bool surfaceInitialized: false
109 readonly property bool supportsSurfaceResize:
111 ((application.supportedOrientations & Qt.PortraitOrientation)
112 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
114 ((application.supportedOrientations & Qt.LandscapeOrientation)
115 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
117 !((root.minimumWidth === root.maximumWidth) && (root.minimumHeight === root.maximumHeight))
119 property bool surfaceOldEnoughToBeResized: false
121 property Item focusedSurface: promptSurfacesRepeater.count === 0 ? surfaceContainer
122 : promptSurfacesRepeater.first
123 function surfaceUp() {
124 d.surfaceInitialized = true;
126 d.surfaceOldEnoughToBeResized = true;
129 onFocusedSurfaceChanged: {
130 if (focusedSurface) {
131 focusedSurface.focus = true;
137 target: root.application
138 property: "initialSurfaceSize"
139 value: Qt.size(root.requestedWidth, root.requestedHeight)
146 running: root.surface && !d.surfaceInitialized
148 if (root.surface && root.surface.isReady) {
157 requestedWidth: root.requestedWidth
158 requestedHeight: root.requestedHeight
159 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
161 onSizeChanged: root.sizeChanged(size)
166 objectName: "splashLoader"
168 sourceComponent: Component {
171 title: d.splashTitle ? d.splashTitle : d.name
172 imageSource: d.splashImage
174 showHeader: d.splashShowHeader
175 backgroundColor: d.splashColor
176 headerColor: d.splashColorHeader
177 footerColor: d.splashColorFooter
179 rotation: root.splashRotation
180 anchors.centerIn: parent
181 width: rotation == 0 || rotation == 180 ? root.width : root.height
182 height: rotation == 0 || rotation == 180 ? root.height : root.width
188 id: promptSurfacesRepeater
189 objectName: "promptSurfacesRepeater"
190 // show only along with the top-most application surface
192 if (root.application && (
193 root.surface === root.application.surfaceList.first ||
194 root.application.surfaceList.count === 0)) {
195 return root.application.promptSurfaceList;
200 delegate: SurfaceContainer {
201 id: promptSurfaceContainer
202 interactive: index === 0 && root.interactive
203 surface: model.surface
206 requestedWidth: root.requestedWidth
207 requestedHeight: root.requestedHeight
208 isPromptSurface: true
209 z: surfaceContainer.z + (promptSurfacesRepeater.count - index)
210 property int index: model.index
211 onIndexChanged: updateFirst()
212 Component.onCompleted: updateFirst()
213 function updateFirst() {
215 promptSurfacesRepeater.first = promptSurfaceContainer;
224 property Item first: null
229 objectName: "applicationWindowStateGroup"
233 when: (root.surface && d.surfaceInitialized)
237 when: (!root.surface || !d.surfaceInitialized) || !root.surface.live || d.hadSurface
244 SequentialAnimation {
245 PropertyAnimation { target: splashLoader; property: "opacity"; from: 1; to: 0; easing.type: Easing.OutQuad }
246 PropertyAction { target: splashLoader; property: "active"; value: false }