Unity 8
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 
17 import QtQuick 2.12
18 import Ubuntu.Components 1.3
19 import Ubuntu.Gestures 0.1 // For TouchGate
20 import Utils 0.1 // for InputWatcher
21 import Unity.Application 0.1 // for MirSurfaceItem
22 
23 FocusScope {
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  onSurfaceChanged: {
43  // Not a binding because animations might remove the surface from the surfaceItem
44  // programatically (in order to signal that a zombie surface is free for deletion),
45  // even though root.surface is still !null.
46  surfaceItem.surface = surface;
47  }
48 
49  InputWatcher {
50  target: surfaceItem
51  onTargetPressedChanged: {
52  if (targetPressed && root.interactive) {
53  root.focus = true;
54  root.forceActiveFocus();
55  }
56  }
57  }
58 
59  MirSurfaceItem {
60  id: surfaceItem
61  objectName: "surfaceItem"
62  anchors.fill: parent
63 
64  focus: true
65 
66  fillMode: MirSurfaceItem.PadOrCrop
67  consumesInput: true
68 
69  surfaceWidth: root.requestedWidth
70  surfaceHeight: root.requestedHeight
71 
72  enabled: root.interactive
73  antialiasing: !root.interactive
74  orientationAngle: root.surfaceOrientationAngle
75  }
76 
77  TouchGate {
78  targetItem: surfaceItem
79  anchors.fill: root
80  enabled: surfaceItem.enabled
81  }
82 
83  Loader {
84  id: animationsLoader
85  objectName: "animationsLoader"
86  active: root.surface
87  source: {
88  if (root.isPromptSurface) {
89  return "PromptSurfaceAnimations.qml";
90  } else {
91  // Let ApplicationWindow do the animations
92  return "";
93  }
94  }
95  Binding {
96  target: animationsLoader.item
97  when: animationsLoader.item
98  property: "surfaceItem"
99  value: surfaceItem
100  }
101  Binding {
102  target: animationsLoader.item
103  when: animationsLoader.item
104  property: "container"
105  value: root
106  }
107  }
108 }