2 * Copyright (C) 2014-2016 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/>.
18 import Ubuntu.Components 1.3
19 import Unity.Application 0.1
24 width: !counterRotate ? applicationWindow.width : applicationWindow.height
25 height: visibleDecorationHeight + (!counterRotate ? applicationWindow.height : applicationWindow.width)
27 property alias application: applicationWindow.application
28 property alias surface: applicationWindow.surface
29 readonly property alias focusedSurface: applicationWindow.focusedSurface
30 property alias active: decoration.active
31 readonly property alias title: applicationWindow.title
32 property alias fullscreen: applicationWindow.fullscreen
33 property alias maximizeButtonShown: decoration.maximizeButtonShown
35 readonly property bool decorationShown: !fullscreen
36 property bool highlightShown: false
37 property real shadowOpacity: 1
39 property real requestedWidth
40 property real requestedHeight
42 property alias surfaceOrientationAngle: applicationWindow.surfaceOrientationAngle
43 readonly property real visibleDecorationHeight: root.decorationShown ? decoration.height : 0
44 readonly property bool counterRotate: surfaceOrientationAngle != 0 && surfaceOrientationAngle != 180
46 readonly property int minimumWidth: !counterRotate ? applicationWindow.minimumWidth : applicationWindow.minimumHeight
47 readonly property int minimumHeight: visibleDecorationHeight + (!counterRotate ? applicationWindow.minimumHeight : applicationWindow.minimumWidth)
48 readonly property int maximumWidth: !counterRotate ? applicationWindow.maximumWidth : applicationWindow.maximumHeight
49 readonly property int maximumHeight: (root.decorationShown && applicationWindow.maximumHeight > 0 ? decoration.height : 0)
50 + (!counterRotate ? applicationWindow.maximumHeight : applicationWindow.maximumWidth)
51 readonly property int widthIncrement: !counterRotate ? applicationWindow.widthIncrement : applicationWindow.heightIncrement
52 readonly property int heightIncrement: !counterRotate ? applicationWindow.heightIncrement : applicationWindow.widthIncrement
54 property alias overlayShown: decoration.overlayShown
55 property alias stageWidth: moveHandler.stageWidth
56 property alias stageHeight: moveHandler.stageHeight
57 readonly property alias dragging: moveHandler.dragging
59 readonly property Item clientAreaItem: applicationWindow
62 signal maximizeClicked()
63 signal maximizeHorizontallyClicked()
64 signal maximizeVerticallyClicked()
65 signal minimizeClicked()
66 signal decorationPressed()
67 signal decorationReleased()
70 id: selectionHighlight
72 anchors.margins: -units.gu(1)
74 opacity: highlightShown ? 0.15 : 0
78 anchors { left: selectionHighlight.left; right: selectionHighlight.right; bottom: selectionHighlight.bottom; }
80 color: theme.palette.normal.focus
81 visible: highlightShown
87 margins: active ? -units.gu(2) : -units.gu(1.5)
89 source: "graphics/dropshadow2gu.sci"
90 opacity: root.shadowOpacity * .3
97 objectName: "appWindowDecoration"
98 anchors { left: parent.left; top: parent.top; right: parent.right }
101 title: applicationWindow.title
102 visible: root.decorationShown
104 onCloseClicked: root.closeClicked();
105 onMaximizeClicked: { root.decorationPressed(); root.maximizeClicked(); }
106 onMaximizeHorizontallyClicked: { root.decorationPressed(); root.maximizeHorizontallyClicked(); }
107 onMaximizeVerticallyClicked: { root.decorationPressed(); root.maximizeVerticallyClicked(); }
108 onMinimizeClicked: root.minimizeClicked();
109 onPressed: root.decorationPressed();
111 onPressedChanged: moveHandler.handlePressedChanged(pressed, pressedButtons, mouseX, mouseY)
112 onPositionChanged: moveHandler.handlePositionChanged(mouse)
114 root.decorationReleased();
115 moveHandler.handleReleased();
121 objectName: "moveHandler"
123 buttonsWidth: decoration.buttonsWidth
127 id: applicationWindow
128 objectName: "appWindow"
129 anchors.top: parent.top
130 anchors.topMargin: decoration.height
131 anchors.left: parent.left
132 readonly property real requestedHeightMinusDecoration: root.requestedHeight - root.visibleDecorationHeight
133 requestedHeight: !counterRotate ? requestedHeightMinusDecoration : root.requestedWidth
134 requestedWidth: !counterRotate ? root.requestedWidth : requestedHeightMinusDecoration
138 transform: Rotation {
139 readonly property int rotationAngle: applicationWindow.application &&
140 applicationWindow.application.rotatesWindowContents
141 ? ((360 - applicationWindow.surfaceOrientationAngle) % 360) : 0
143 if (rotationAngle == 90) return applicationWindow.height / 2;
144 else if (rotationAngle == 270) return applicationWindow.width / 2;
145 else if (rotationAngle == 180) return applicationWindow.width / 2;
149 if (rotationAngle == 90) return applicationWindow.height / 2;
150 else if (rotationAngle == 270) return applicationWindow.width / 2;
151 else if (rotationAngle == 180) return applicationWindow.height / 2;