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