Unity 8
SurfaceContainer.qml
1 /*
2  * Copyright 2014-2015 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.0
18 import Ubuntu.Components 1.1
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 
27  property var surface: null
28  property bool hadSurface: false
29  property bool interactive
30  property int surfaceOrientationAngle: 0
31  property bool resizeSurface: true
32 
33  onSurfaceChanged: {
34  if (surface) {
35  surfaceItem.surface = surface;
36  root.hadSurface = false;
37  }
38  }
39 
40  InputWatcher {
41  target: surfaceItem
42  onTargetPressedChanged: {
43  if (targetPressed && root.interactive) {
44  root.focus = true;
45  root.forceActiveFocus();
46  }
47  }
48  }
49 
50  MirSurfaceItem {
51  id: surfaceItem
52  objectName: "surfaceItem"
53 
54  consumesInput: true
55 
56  surfaceWidth: root.resizeSurface ? width : -1
57  surfaceHeight: root.resizeSurface ? height : -1
58 
59  anchors.fill: root
60  enabled: root.interactive
61  focus: true
62  antialiasing: !root.interactive
63  orientationAngle: root.surfaceOrientationAngle
64  }
65 
66  TouchGate {
67  targetItem: surfaceItem
68  anchors.fill: root
69  enabled: surfaceItem.enabled
70  }
71 
72  states: [
73  State {
74  name: "zombie"
75  when: surfaceItem.surface && !surfaceItem.live
76  }
77  ]
78  transitions: [
79  Transition {
80  from: ""; to: "zombie"
81  SequentialAnimation {
82  UbuntuNumberAnimation { target: surfaceItem; property: "opacity"; to: 0.0
83  duration: UbuntuAnimation.BriskDuration }
84  PropertyAction { target: surfaceItem; property: "visible"; value: false }
85  ScriptAction { script: {
86  surfaceItem.surface = null;
87  root.hadSurface = true;
88  } }
89  }
90  },
91  Transition {
92  from: "zombie"; to: ""
93  ScriptAction { script: {
94  surfaceItem.opacity = 1.0;
95  surfaceItem.visible = true;
96  } }
97  }
98  ]
99 }