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  property alias active: decoration.active
30  readonly property alias title: applicationWindow.title
31  property alias fullscreen: applicationWindow.fullscreen
32  property alias maximizeButtonShown: decoration.maximizeButtonShown
33 
34  readonly property bool decorationShown: !fullscreen
35  property bool highlightShown: false
36  property real shadowOpacity: 1
37 
38  property real requestedWidth
39  property real requestedHeight
40 
41  property alias surfaceOrientationAngle: applicationWindow.surfaceOrientationAngle
42  readonly property real visibleDecorationHeight: root.decorationShown ? decoration.height : 0
43  readonly property bool counterRotate: surfaceOrientationAngle != 0 && surfaceOrientationAngle != 180
44 
45  readonly property int minimumWidth: !counterRotate ? applicationWindow.minimumWidth : applicationWindow.minimumHeight
46  readonly property int minimumHeight: visibleDecorationHeight + (!counterRotate ? applicationWindow.minimumHeight : applicationWindow.minimumWidth)
47  readonly property int maximumWidth: !counterRotate ? applicationWindow.maximumWidth : applicationWindow.maximumHeight
48  readonly property int maximumHeight: (root.decorationShown && applicationWindow.maximumHeight > 0 ? decoration.height : 0)
49  + (!counterRotate ? applicationWindow.maximumHeight : applicationWindow.maximumWidth)
50  readonly property int widthIncrement: !counterRotate ? applicationWindow.widthIncrement : applicationWindow.heightIncrement
51  readonly property int heightIncrement: !counterRotate ? applicationWindow.heightIncrement : applicationWindow.widthIncrement
52 
53  property alias overlayShown: decoration.overlayShown
54 
55  signal closeClicked()
56  signal maximizeClicked()
57  signal maximizeHorizontallyClicked()
58  signal maximizeVerticallyClicked()
59  signal minimizeClicked()
60  signal decorationPressed()
61 
62  Rectangle {
63  id: selectionHighlight
64  anchors.fill: parent
65  anchors.margins: -units.gu(1)
66  color: "white"
67  opacity: highlightShown ? 0.15 : 0
68  }
69 
70  Rectangle {
71  anchors { left: selectionHighlight.left; right: selectionHighlight.right; bottom: selectionHighlight.bottom; }
72  height: units.dp(2)
73  color: theme.palette.normal.focus
74  visible: highlightShown
75  }
76 
77  BorderImage {
78  anchors {
79  fill: root
80  margins: active ? -units.gu(2) : -units.gu(1.5)
81  }
82  source: "graphics/dropshadow2gu.sci"
83  opacity: root.shadowOpacity * .3
84  visible: !fullscreen
85  }
86 
87  WindowDecoration {
88  id: decoration
89  target: root.parent
90  objectName: "appWindowDecoration"
91  anchors { left: parent.left; top: parent.top; right: parent.right }
92  height: units.gu(3)
93  width: root.width
94  title: applicationWindow.title
95  visible: root.decorationShown
96 
97  onCloseClicked: root.closeClicked();
98  onMaximizeClicked: { root.decorationPressed(); root.maximizeClicked(); }
99  onMaximizeHorizontallyClicked: { root.decorationPressed(); root.maximizeHorizontallyClicked(); }
100  onMaximizeVerticallyClicked: { root.decorationPressed(); root.maximizeVerticallyClicked(); }
101  onMinimizeClicked: root.minimizeClicked();
102  onPressed: root.decorationPressed();
103  }
104 
105  ApplicationWindow {
106  id: applicationWindow
107  objectName: "appWindow"
108  anchors.top: parent.top
109  anchors.topMargin: decoration.height
110  anchors.left: parent.left
111  readonly property real requestedHeightMinusDecoration: root.requestedHeight - root.visibleDecorationHeight
112  requestedHeight: !counterRotate ? requestedHeightMinusDecoration : root.requestedWidth
113  requestedWidth: !counterRotate ? root.requestedWidth : requestedHeightMinusDecoration
114  interactive: true
115  focus: true
116 
117  transform: Rotation {
118  readonly property int rotationAngle: applicationWindow.application &&
119  applicationWindow.application.rotatesWindowContents
120  ? ((360 - applicationWindow.surfaceOrientationAngle) % 360) : 0
121  origin.x: {
122  if (rotationAngle == 90) return applicationWindow.height / 2;
123  else if (rotationAngle == 270) return applicationWindow.width / 2;
124  else if (rotationAngle == 180) return applicationWindow.width / 2;
125  else return 0;
126  }
127  origin.y: {
128  if (rotationAngle == 90) return applicationWindow.height / 2;
129  else if (rotationAngle == 270) return applicationWindow.width / 2;
130  else if (rotationAngle == 180) return applicationWindow.height / 2;
131  else return 0;
132  }
133  angle: rotationAngle
134  }
135  }
136 }