Unity 8
ChildWindowTree.qml
1 /*
2  * Copyright (C) 2016-2017 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU 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 General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.12
18 import Ubuntu.Components 1.3
19 import Unity.Application 0.1
20 
21 FocusScope {
22  id: root
23 
24  property alias surface: childWindow.surface
25  property real displacementX: 0
26  property real displacementY: 0
27  property alias boundsItem: childWindow.boundsItem
28  property alias decorationHeight: childWindow.decorationHeight
29 
30  x: surface ? surface.position.x + displacementX : 0
31  y: surface ? surface.position.y + displacementY : 0
32  width: childWindow.width
33  height: childWindow.height
34 
35  ////
36  // API expected by MoveHandler (and some by WindowResizeArea as well)
37  readonly property bool maximized: false
38  readonly property bool maximizedLeft: false
39  readonly property bool maximizedRight: false
40  readonly property bool maximizedHorizontally: false
41  readonly property bool maximizedVertically: false
42  readonly property bool maximizedTopLeft: false
43  readonly property bool maximizedTopRight: false
44  readonly property bool maximizedBottomLeft: false
45  readonly property bool maximizedBottomRight: false
46  readonly property bool anyMaximized: maximized || maximizedLeft || maximizedRight || maximizedHorizontally || maximizedVertically ||
47  maximizedTopLeft || maximizedTopRight || maximizedBottomLeft || maximizedBottomRight
48 
49  readonly property bool canBeCornerMaximized: false
50  readonly property bool canBeMaximizedLeftRight: false
51  readonly property bool canBeMaximized: false
52 
53  readonly property var resizeArea: QtObject {
54  property real normalWidth: units.gu(1)
55  property real normalHeight: units.gu(1)
56  }
57 
58  readonly property bool windowedTransitionRunning: false
59 
60  // NB: those bindings will be overwritten by MoveHandler when you first move the window
61  property real windowedX: x
62  property real windowedY: y
63 
64  state: "restored"
65  // end of API expected by MoveHandler
66  ////
67 
68  ////
69  // API expected by WindowResizeArea
70  property real windowedWidth: childWindow.width
71  property real windowedHeight: childWindow.height
72  // end of API expected by WindowResizeArea
73  ////
74 
75  ////
76  // API expected by WindowControlsOverlay
77  function activate() {
78  surface.activate();
79  }
80  // end of API expected by WindowControlsOverlay
81  ////
82 
83  Binding {
84  target: root.surface
85  when: childWindow.dragging
86  property: "requestedPosition"
87  value: Qt.point(root.windowedX - root.displacementX,
88  root.windowedY - root.displacementY);
89  }
90 
91  // It's a separate Item so that a window can be hid independently of its children
92  ChildWindow {
93  id: childWindow
94  target: root
95  requestedWidth: root.windowedWidth
96  requestedHeight: root.windowedHeight
97  }
98 
99  Connections {
100  target: root.surface
101  onFocusRequested: {
102  root.surface.activate();
103  }
104  onFocusedChanged: {
105  if (root.surface.focused) {
106  childWindow.focus = true;
107  // Propagate
108  root.focus = true;
109  }
110  }
111  }
112 
113  // Using a loader here mainly to circunvent the "ChildWindowTree is instantiated recursively" error from the QML engine
114  Loader {
115  id: childRepeaterLoader
116  source: "ChildWindowRepeater.qml"
117  active: root.surface && root.surface.childSurfaceList.count > 0
118  Binding {
119  target: childRepeaterLoader.item
120  when: childRepeaterLoader.item
121  property: "model"
122  value: root.surface ? root.surface.childSurfaceList : null
123  }
124  Binding {
125  target: childRepeaterLoader.item
126  when: childRepeaterLoader.item
127  property: "boundsItem"
128  value: root.boundsItem
129  }
130  onFocusChanged: {
131  if (focus) {
132  // A surface in some ChildWindowTree got focused.
133  // Propagate
134  root.focus = true;
135  }
136  }
137  }
138 }