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