Unity 8
DecoratedWindow.qml
1 /*
2  * Copyright (C) 2014-2016 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.4
18 import Ubuntu.Components 1.3
19 import Unity.Application 0.1
20 
21 FocusScope {
22  id: root
23 
24  width: !counterRotate ? applicationWindow.width : applicationWindow.height
25  height: visibleDecorationHeight + (!counterRotate ? applicationWindow.height : applicationWindow.width)
26 
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
34 
35  readonly property bool decorationShown: !fullscreen
36  property bool highlightShown: false
37  property real shadowOpacity: 1
38 
39  property real requestedWidth
40  property real requestedHeight
41 
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
45 
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
53 
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
58 
59  readonly property Item clientAreaItem: applicationWindow
60 
61  signal closeClicked()
62  signal maximizeClicked()
63  signal maximizeHorizontallyClicked()
64  signal maximizeVerticallyClicked()
65  signal minimizeClicked()
66  signal decorationPressed()
67  signal decorationReleased()
68 
69  Rectangle {
70  id: selectionHighlight
71  anchors.fill: parent
72  anchors.margins: -units.gu(1)
73  color: "white"
74  opacity: highlightShown ? 0.15 : 0
75  }
76 
77  Rectangle {
78  anchors { left: selectionHighlight.left; right: selectionHighlight.right; bottom: selectionHighlight.bottom; }
79  height: units.dp(2)
80  color: theme.palette.normal.focus
81  visible: highlightShown
82  }
83 
84  BorderImage {
85  anchors {
86  fill: root
87  margins: active ? -units.gu(2) : -units.gu(1.5)
88  }
89  source: "graphics/dropshadow2gu.sci"
90  opacity: root.shadowOpacity * .3
91  visible: !fullscreen
92  }
93 
94  WindowDecoration {
95  id: decoration
96  target: root.parent
97  objectName: "appWindowDecoration"
98  anchors { left: parent.left; top: parent.top; right: parent.right }
99  height: units.gu(3)
100  width: root.width
101  title: applicationWindow.title
102  visible: root.decorationShown
103 
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();
110 
111  onPressedChanged: moveHandler.handlePressedChanged(pressed, pressedButtons, mouseX, mouseY)
112  onPositionChanged: moveHandler.handlePositionChanged(mouse)
113  onReleased: {
114  root.decorationReleased();
115  moveHandler.handleReleased();
116  }
117  }
118 
119  MoveHandler {
120  id: moveHandler
121  objectName: "moveHandler"
122  target: root.parent
123  buttonsWidth: decoration.buttonsWidth
124  }
125 
126  ApplicationWindow {
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
135  interactive: true
136  focus: true
137 
138  transform: Rotation {
139  readonly property int rotationAngle: applicationWindow.application &&
140  applicationWindow.application.rotatesWindowContents
141  ? ((360 - applicationWindow.surfaceOrientationAngle) % 360) : 0
142  origin.x: {
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;
146  else return 0;
147  }
148  origin.y: {
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;
152  else return 0;
153  }
154  angle: rotationAngle
155  }
156  }
157 }