Unity 8
DecoratedWindow.qml
1 /*
2  * Copyright (C) 2014-2015 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  * Authors: Michael Zanetti <michael.zanetti@canonical.com>
17  */
18 
19 import QtQuick 2.4
20 import Ubuntu.Components 1.3
21 import Unity.Application 0.1
22 
23 FocusScope {
24  id: root
25 
26  width: !counterRotate ? applicationWindow.width : applicationWindow.height
27  height: visibleDecorationHeight + (!counterRotate ? applicationWindow.height : applicationWindow.width)
28 
29  property alias application: applicationWindow.application
30  property alias surface: applicationWindow.surface
31  property alias active: decoration.active
32  readonly property alias title: applicationWindow.title
33  property alias fullscreen: applicationWindow.fullscreen
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  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: visibleDecorationHeight + (!counterRotate ? applicationWindow.maximumHeight : applicationWindow.maximumWidth)
49  readonly property int widthIncrement: !counterRotate ? applicationWindow.widthIncrement : applicationWindow.heightIncrement
50  readonly property int heightIncrement: !counterRotate ? applicationWindow.heightIncrement : applicationWindow.widthIncrement
51 
52  property alias overlayShown: decoration.overlayShown
53 
54  signal closeClicked()
55  signal maximizeClicked()
56  signal maximizeHorizontallyClicked()
57  signal maximizeVerticallyClicked()
58  signal minimizeClicked()
59  signal decorationPressed()
60 
61  Rectangle {
62  id: selectionHighlight
63  anchors.fill: parent
64  anchors.margins: -units.gu(1)
65  color: "white"
66  opacity: highlightShown ? 0.15 : 0
67  }
68 
69  Rectangle {
70  anchors { left: selectionHighlight.left; right: selectionHighlight.right; bottom: selectionHighlight.bottom; }
71  height: units.dp(2)
72  color: theme.palette.normal.focus
73  visible: highlightShown
74  }
75 
76  BorderImage {
77  anchors {
78  fill: root
79  margins: active ? -units.gu(2) : -units.gu(1.5)
80  }
81  source: "graphics/dropshadow2gu.sci"
82  opacity: root.shadowOpacity * .3
83  visible: !fullscreen
84  }
85 
86  WindowDecoration {
87  id: decoration
88  target: root.parent
89  objectName: "appWindowDecoration"
90  anchors { left: parent.left; top: parent.top; right: parent.right }
91  height: units.gu(3)
92  width: root.width
93  title: applicationWindow.title
94  visible: root.decorationShown
95 
96  onCloseClicked: root.closeClicked();
97  onMaximizeClicked: { root.decorationPressed(); root.maximizeClicked(); }
98  onMaximizeHorizontallyClicked: { root.decorationPressed(); root.maximizeHorizontallyClicked(); }
99  onMaximizeVerticallyClicked: { root.decorationPressed(); root.maximizeVerticallyClicked(); }
100  onMinimizeClicked: root.minimizeClicked();
101  onPressed: root.decorationPressed();
102  }
103 
104  ApplicationWindow {
105  id: applicationWindow
106  objectName: "appWindow"
107  anchors.top: parent.top
108  anchors.topMargin: decoration.height
109  anchors.left: parent.left
110  readonly property real requestedHeightMinusDecoration: root.requestedHeight - root.visibleDecorationHeight
111  requestedHeight: !counterRotate ? requestedHeightMinusDecoration : root.requestedWidth
112  requestedWidth: !counterRotate ? root.requestedWidth : requestedHeightMinusDecoration
113  interactive: true
114  focus: true
115 
116  transform: Rotation {
117  readonly property int rotationAngle: applicationWindow.application &&
118  applicationWindow.application.rotatesWindowContents
119  ? ((360 - applicationWindow.surfaceOrientationAngle) % 360) : 0
120  origin.x: {
121  if (rotationAngle == 90) return applicationWindow.height / 2;
122  else if (rotationAngle == 270) return applicationWindow.width / 2;
123  else if (rotationAngle == 180) return applicationWindow.width / 2;
124  else return 0;
125  }
126  origin.y: {
127  if (rotationAngle == 90) return applicationWindow.height / 2;
128  else if (rotationAngle == 270) return applicationWindow.width / 2;
129  else if (rotationAngle == 180) return applicationWindow.height / 2;
130  else return 0;
131  }
132  angle: rotationAngle
133  }
134  }
135 }