2 * Copyright (C) 2016-2017 Canonical Ltd.
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.
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.
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/>.
19import Lomiri.Components 1.3
20import QtMir.Application 0.1
24 objectName: "childWindow"
28 property Item boundsItem
30 property alias requestedWidth: surfaceContainer.requestedWidth
31 property alias requestedHeight: surfaceContainer.requestedHeight
32 property real decorationHeight
34 width: surface ? surface.size.width : 0
35 height: surface ? surface.size.height : 0
37 // Make it get shown and hidden with a fade in/out effect
38 opacity: surface && surface.state !== Mir.MinimizedState && surface.state !== Mir.HiddenState ? 1.0 : 0.0
39 Behavior on opacity { LomiriNumberAnimation {} }
40 visible: opacity !== 0.0 // make it transparent to input as well
42 readonly property bool dragging: windowResizeArea.dragging || d.touchOverlayDragging || d.moveHandlerDragging
46 readonly property bool decorated: surface ? surface.type === Mir.UtilityType
47 || surface.type === Mir.DialogType
48 || surface.type === Mir.NormalType
49 || surface.type === Mir.SatelliteType
52 readonly property bool moveable: decorated
53 readonly property bool resizeable: decorated
55 property alias decoration: decorationLoader.item
56 property alias moveHandler: moveHandlerLoader.item
58 readonly property bool touchOverlayDragging: touchOverlayLoader.item ? touchOverlayLoader.item.dragging : false
59 readonly property bool moveHandlerDragging: moveHandlerLoader.item ? moveHandlerLoader.item.dragging : false
65 top: decorationLoader.top
67 left: parent.left; right: parent.right
70 boundsItem: root.boundsItem
71 minWidth: units.gu(10)
72 minHeight: units.gu(10)
73 borderThickness: units.gu(2)
76 onPressed: root.surface.activate();
80 property real shadowThickness: root.surface && root.surface.focused ? units.gu(2) : units.gu(1.5)
82 top: decorationLoader.top
84 left: parent.left; right: parent.right
85 margins: -shadowThickness
87 source: "../graphics/dropshadow2gu.sci"
93 anchors.bottom: root.top
94 anchors.left: root.left
95 anchors.right: root.right
100 height: item ? item.height : 0
102 sourceComponent: Component {
105 height: root.decorationHeight
106 title: root.surface ? root.surface.name : ""
107 active: root.surface ? root.surface.focused : false
108 minimizeButtonVisible: false
109 maximizeButtonShown: false
110 onPressed: root.surface.activate();
111 onPressedChanged: if (d.moveHandler) { d.moveHandler.handlePressedChanged(pressed, pressedButtons, mouseX, mouseY); }
112 onPositionChanged: if (d.moveHandler) {
113 d.moveHandler.handlePositionChanged(mouse);
115 onReleased: if (d.moveHandler) { d.moveHandler.handleReleased(); }
116 onCloseClicked: root.surface.close();
119 restoreMode: Binding.RestoreBinding
120 property: "topMargin"
121 value: windowDecoration.height
128 id: moveHandlerLoader
130 sourceComponent: Component {
133 buttonsWidth: d.decoration ? d.decoration.buttonsWidth : 0
134 boundsItem: root.boundsItem
135 boundsTopMargin: decorationLoader.height
143 // Do not hold on to a dead surface so that it can be destroyed.
144 // FIXME It should not be QML's job to release the MirSurface if its backing surface goes away. Instead backing
145 // MirSurface should go away but the MirSurfaceItem should be able to live on with the last drawn frame
147 surface: root.surface && root.surface.live ? root.surface : null
149 requestedWidth: surface ? surface.size.width : 0
150 requestedHeight: surface ? surface.size.height : 0
152 // TODO ChildWindow parent will probably want to control those
162 sourceComponent: Component {
164 acceptedButtons: Qt.LeftButton
165 property bool dragging: false
166 cursorShape: undefined // don't interfere with the cursor shape set by the underlying MirSurfaceItem
168 if (mouse.button == Qt.LeftButton && mouse.modifiers == Qt.AltModifier) {
169 d.moveHandler.handlePressedChanged(true, Qt.LeftButton, mouse.x, mouse.y);
171 mouse.accepted = true;
173 mouse.accepted = false;
178 d.moveHandler.handlePositionChanged(mouse);
183 d.moveHandler.handlePressedChanged(false, Qt.LeftButton);
184 d.moveHandler.handleReleased();
193 id: touchOverlayLoader
194 active: d.resizeable || d.moveable
195 anchors.top: decorationLoader.top
196 anchors.bottom: parent.bottom
197 anchors.left: parent.left
198 anchors.right: parent.right
199 sourceComponent: Component { WindowControlsOverlay {
201 resizeArea: windowResizeArea
202 boundsItem: root.boundsItem