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