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