Lomiri
Loading...
Searching...
No Matches
SurfaceContainer.qml
1/*
2 * Copyright 2014-2016 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*/
16
17import QtQuick 2.12
18import Lomiri.Components 1.3
19import Lomiri.Gestures 0.1 // For TouchGate
20import Utils 0.1 // for InputWatcher
21import QtMir.Application 0.1 // for MirSurfaceItem
22
23FocusScope {
24 id: root
25 objectName: "surfaceContainer"
26 implicitWidth: surfaceItem.implicitWidth
27 implicitHeight: surfaceItem.implicitHeight
28
29 // Must be set from outside
30 property var surface: null
31
32 // Might be changed from outside
33 property int requestedWidth: -1
34 property int requestedHeight: -1
35 property bool interactive
36 property int surfaceOrientationAngle: 0
37 property bool isPromptSurface: false
38 // FIME - dont export, use interactive property. Need to fix qtmir to handle consumesInputChanged
39 // to update surface activeFocus. See mock MirSurfaceItem.
40 property alias consumesInput: surfaceItem.consumesInput
41
42 property bool hadSurface: false
43
44 signal sizeChanged(size size)
45
46 onSurfaceChanged: {
47 // Not a binding because animations might remove the surface from the surfaceItem
48 // programatically (in order to signal that a zombie surface is free for deletion),
49 // even though root.surface is still !null.
50 if (surface != null)
51 root.hadSurface = true;
52
53 surfaceItem.surface = surface;
54 }
55
56 InputWatcher {
57 target: surfaceItem
58 onTargetPressedChanged: {
59 if (targetPressed && root.interactive) {
60 root.focus = true;
61 root.forceActiveFocus();
62 }
63 }
64 }
65
66 MirSurfaceItem {
67 id: surfaceItem
68 objectName: "surfaceItem"
69 anchors.fill: parent
70
71 focus: true
72
73 fillMode: MirSurfaceItem.PadOrCrop
74 consumesInput: true
75
76 surfaceWidth: root.requestedWidth
77 surfaceHeight: root.requestedHeight
78
79 enabled: root.interactive
80 antialiasing: !root.interactive
81 orientationAngle: root.surfaceOrientationAngle
82
83 Connections {
84 target: surfaceItem.surface
85 onSizeChanged: {
86 root.sizeChanged(value)
87 }
88 }
89 }
90
91 TouchGate {
92 targetItem: surfaceItem
93 anchors.fill: root
94 enabled: surfaceItem.enabled
95 }
96
97 Loader {
98 id: animationsLoader
99 objectName: "animationsLoader"
100 active: root.surface || root.hadSurface
101 source: {
102 if (root.isPromptSurface) {
103 return "PromptSurfaceAnimations.qml";
104 } else {
105 // Let ApplicationWindow do the animations
106 return "";
107 }
108 }
109 Binding {
110 target: animationsLoader.item
111 when: animationsLoader.item
112 property: "surfaceItem"
113 value: surfaceItem
114 }
115 Binding {
116 target: animationsLoader.item
117 when: animationsLoader.item
118 property: "container"
119 value: root
120 }
121 Binding {
122 target: animationsLoader.item
123 when: animationsLoader.item
124 property: "hadSurface"
125 value: hadSurface
126 }
127 }
128}