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