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
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
51 d.surfaceInitialized = true;
53 d.surfaceOldEnoughToBeResized = true;
57 // Best effort scenario: after a desktop mode switch we don't know the ready status
58 // FIXME: Expose ready property as part of the lomiri-api MirSurfaceInterface
59 Component.onCompleted: {
60 if (surface && surface.live) {
61 d.surfaceInitialized = true;
63 d.surfaceOldEnoughToBeResized = true;
68 // The order in which the instructions are executed here matters, to that the correct state
69 // transitions in stateGroup take place.
70 // More specifically, the moment surfaceContainer.surface gets updated relative to the
71 // other instructions.
73 surfaceContainer.surface = surface;
75 d.surfaceInitialized = false;
76 surfaceContainer.surface = null;
83 // helpers so that we don't have to check for the existence of an application everywhere
84 // (in order to avoid breaking qml binding due to a javascript exception)
85 readonly property string name: root.application ? root.application.name : ""
86 readonly property url icon: root.application ? root.application.icon : ""
87 readonly property int applicationState: root.application ? root.application.state : -1
88 readonly property string splashTitle: root.application ? root.application.splashTitle : ""
89 readonly property url splashImage: root.application ? root.application.splashImage : ""
90 readonly property bool splashShowHeader: root.application ? root.application.splashShowHeader : true
91 readonly property color splashColor: root.application ? root.application.splashColor : "#00000000"
92 readonly property color splashColorHeader: root.application ? root.application.splashColorHeader : "#00000000"
93 readonly property color splashColorFooter: root.application ? root.application.splashColorFooter : "#00000000"
95 // Whether the Application had a surface before but lost it.
96 property bool hadSurface: false
98 //FIXME - this is a hack to avoid the first few rendered frames as they
99 // might show the UI accommodating due to surface resizes on startup.
100 // Remove this when possible
101 property bool surfaceInitialized: false
103 readonly property bool supportsSurfaceResize:
105 ((application.supportedOrientations & Qt.PortraitOrientation)
106 || (application.supportedOrientations & Qt.InvertedPortraitOrientation))
108 ((application.supportedOrientations & Qt.LandscapeOrientation)
109 || (application.supportedOrientations & Qt.InvertedLandscapeOrientation))
111 property bool surfaceOldEnoughToBeResized: false
113 property Item focusedSurface: promptSurfacesRepeater.count === 0 ? surfaceContainer
114 : promptSurfacesRepeater.first
115 onFocusedSurfaceChanged: {
116 if (focusedSurface) {
117 focusedSurface.focus = true;
123 target: root.application
124 property: "initialSurfaceSize"
125 value: Qt.size(root.requestedWidth, root.requestedHeight)
132 running: root.surface && !d.surfaceInitialized
135 d.surfaceInitialized = true;
137 d.surfaceOldEnoughToBeResized = true;
148 sourceComponent: Component {
151 title: d.splashTitle ? d.splashTitle : d.name
152 imageSource: d.splashImage
154 showHeader: d.splashShowHeader
155 backgroundColor: d.splashColor
156 headerColor: d.splashColorHeader
157 footerColor: d.splashColorFooter
159 rotation: root.splashRotation
160 anchors.centerIn: parent
161 width: rotation == 0 || rotation == 180 ? root.width : root.height
162 height: rotation == 0 || rotation == 180 ? root.height : root.width
170 z: splashLoader.z + 1
171 requestedWidth: root.requestedWidth
172 requestedHeight: root.requestedHeight
173 surfaceOrientationAngle: application && application.rotatesWindowContents ? root.surfaceOrientationAngle : 0
177 id: promptSurfacesRepeater
178 objectName: "promptSurfacesRepeater"
179 // show only along with the top-most application surface
181 if (root.application && (
182 root.surface === root.application.surfaceList.first ||
183 root.application.surfaceList.count === 0)) {
184 return root.application.promptSurfaceList;
189 delegate: SurfaceContainer {
190 id: promptSurfaceContainer
191 interactive: index === 0 && root.interactive
192 surface: model.surface
195 requestedWidth: root.requestedWidth
196 requestedHeight: root.requestedHeight
197 isPromptSurface: true
198 z: surfaceContainer.z + (promptSurfacesRepeater.count - index)
199 property int index: model.index
200 onIndexChanged: updateFirst()
201 Component.onCompleted: updateFirst()
202 function updateFirst() {
204 promptSurfacesRepeater.first = promptSurfaceContainer;
213 property Item first: null
218 objectName: "applicationWindowStateGroup"
222 when: (root.surface && d.surfaceInitialized)
223 PropertyChanges { target: splashLoader; active: false }
227 when: (!root.surface || !d.surfaceInitialized) || !root.surface.live || d.hadSurface
228 PropertyChanges { target: splashLoader; active: true }