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/>.
18import Lomiri.Components 1.3
19import QtMir.Application 0.1
23 objectName: "childWindow"
27 property Item boundsItem
29 property alias requestedWidth: surfaceContainer.requestedWidth
30 property alias requestedHeight: surfaceContainer.requestedHeight
31 property real decorationHeight
33 width: surface ? surface.size.width : 0
34 height: surface ? surface.size.height : 0
36 // Make it get shown and hidden with a fade in/out effect
37 opacity: surface && surface.state !== Mir.MinimizedState && surface.state !== Mir.HiddenState ? 1.0 : 0.0
38 Behavior on opacity { LomiriNumberAnimation {} }
39 visible: opacity !== 0.0 // make it transparent to input as well
41 readonly property bool dragging: windowResizeArea.dragging || d.touchOverlayDragging || d.moveHandlerDragging
45 readonly property bool decorated: surface ? surface.type === Mir.UtilityType
46 || surface.type === Mir.DialogType
47 || surface.type === Mir.NormalType
48 || surface.type === Mir.SatelliteType
51 readonly property bool moveable: decorated
52 readonly property bool resizeable: decorated
54 property alias decoration: decorationLoader.item
55 property alias moveHandler: moveHandlerLoader.item
57 readonly property bool touchOverlayDragging: touchOverlayLoader.item ? touchOverlayLoader.item.dragging : false
58 readonly property bool moveHandlerDragging: moveHandlerLoader.item ? moveHandlerLoader.item.dragging : false
64 top: decorationLoader.top
66 left: parent.left; right: parent.right
69 boundsItem: root.boundsItem
70 minWidth: units.gu(10)
71 minHeight: units.gu(10)
72 borderThickness: units.gu(2)
75 onPressed: root.surface.activate();
79 property real shadowThickness: root.surface && root.surface.focused ? units.gu(2) : units.gu(1.5)
81 top: decorationLoader.top
83 left: parent.left; right: parent.right
84 margins: -shadowThickness
86 source: "../graphics/dropshadow2gu.sci"
92 anchors.bottom: root.top
93 anchors.left: root.left
94 anchors.right: root.right
99 height: item ? item.height : 0
101 sourceComponent: Component {
104 height: root.decorationHeight
105 title: root.surface ? root.surface.name : ""
106 active: root.surface ? root.surface.focused : false
107 minimizeButtonVisible: false
108 maximizeButtonShown: false
109 onPressed: root.surface.activate();
110 onPressedChanged: if (d.moveHandler) { d.moveHandler.handlePressedChanged(pressed, pressedButtons, mouseX, mouseY); }
111 onPositionChanged: if (d.moveHandler) {
112 d.moveHandler.handlePositionChanged(mouse);
114 onReleased: if (d.moveHandler) { d.moveHandler.handleReleased(); }
115 onCloseClicked: root.surface.close();
118 property: "topMargin"
119 value: windowDecoration.height
126 id: moveHandlerLoader
128 sourceComponent: Component {
131 buttonsWidth: d.decoration ? d.decoration.buttonsWidth : 0
132 boundsItem: root.boundsItem
133 boundsTopMargin: decorationLoader.height
141 // Do not hold on to a dead surface so that it can be destroyed.
142 // FIXME It should not be QML's job to release the MirSurface if its backing surface goes away. Instead backing
143 // MirSurface should go away but the MirSurfaceItem should be able to live on with the last drawn frame
145 surface: root.surface && root.surface.live ? root.surface : null
147 requestedWidth: surface ? surface.size.width : 0
148 requestedHeight: surface ? surface.size.height : 0
150 // TODO ChildWindow parent will probably want to control those
160 sourceComponent: Component {
162 acceptedButtons: Qt.LeftButton
163 property bool dragging: false
164 cursorShape: undefined // don't interfere with the cursor shape set by the underlying MirSurfaceItem
166 if (mouse.button == Qt.LeftButton && mouse.modifiers == Qt.AltModifier) {
167 d.moveHandler.handlePressedChanged(true, Qt.LeftButton, mouse.x, mouse.y);
169 mouse.accepted = true;
171 mouse.accepted = false;
176 d.moveHandler.handlePositionChanged(mouse);
181 d.moveHandler.handlePressedChanged(false, Qt.LeftButton);
182 d.moveHandler.handleReleased();
191 id: touchOverlayLoader
192 active: d.resizeable || d.moveable
193 anchors.top: decorationLoader.top
194 anchors.bottom: parent.bottom
195 anchors.left: parent.left
196 anchors.right: parent.right
197 sourceComponent: Component { WindowControlsOverlay {
199 resizeArea: windowResizeArea
200 boundsItem: root.boundsItem