Unity 8
SurfaceContainer.qml
1 /*
2  * Copyright 2014 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 
21 FocusScope {
22  id: root
23  objectName: "surfaceContainer"
24  property Item surface: null
25  property bool hadSurface: false
26  property int orientation
27  property bool interactive
28 
29  signal surfacePressed()
30 
31  onSurfaceChanged: {
32  if (surface) {
33  // Set the surface focus *after* it is added to the scene to
34  // ensure an update to the scene's active focus.
35  surface.focus = false;
36  surface.parent = root;
37  surface.focus = true;
38  } else {
39  hadSurface = true;
40  }
41  }
42  Binding { target: surface; property: "anchors.fill"; value: root }
43  Binding { target: surface; property: "orientation"; value: root.orientation }
44  Binding { target: surface; property: "z"; value: 1 }
45  Binding { target: surface; property: "enabled"; value: root.interactive; when: surface }
46  Binding { target: surface; property: "antialiasing"; value: !root.interactive; when: surface }
47 
48  TouchGate {
49  targetItem: surface
50  anchors.fill: root
51  enabled: root.surface ? root.surface.enabled : false
52  z: 2
53  onPressed: {
54  root.focus = true;
55  if (root.interactive) {
56  root.forceActiveFocus();
57  }
58  }
59  }
60 
61  states: [
62  State {
63  name: "zombie"
64  when: surface && !surface.live
65  }
66  ]
67  transitions: [
68  Transition {
69  from: ""; to: "zombie"
70  SequentialAnimation {
71  UbuntuNumberAnimation { target: surface; property: "opacity"; to: 0.0
72  duration: UbuntuAnimation.BriskDuration }
73  PropertyAction { target: surface; property: "visible"; value: false }
74  ScriptAction { script: { if (root.surface) { root.surface.release(); } } }
75  }
76  }
77  ]
78 }