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: applicationWindow.width
27  height: (decorationShown ? decoration.height : 0) + applicationWindow.height
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 alias requestedWidth: applicationWindow.requestedWidth
40  property real requestedHeight
41 
42  property alias minimumWidth: applicationWindow.minimumWidth
43  readonly property int minimumHeight: (root.decorationShown ? decoration.height : 0) + applicationWindow.minimumHeight
44  property alias maximumWidth: applicationWindow.maximumWidth
45  readonly property int maximumHeight: (root.decorationShown ? decoration.height : 0) + applicationWindow.maximumHeight
46  property alias widthIncrement: applicationWindow.widthIncrement
47  property alias heightIncrement: applicationWindow.heightIncrement
48 
49  signal closeClicked()
50  signal maximizeClicked()
51  signal maximizeHorizontallyClicked()
52  signal maximizeVerticallyClicked()
53  signal minimizeClicked()
54  signal decorationPressed()
55 
56  Rectangle {
57  id: selectionHighlight
58  anchors.fill: parent
59  anchors.margins: -units.gu(1)
60  color: "white"
61  opacity: highlightShown ? 0.15 : 0
62  }
63 
64  Rectangle {
65  anchors { left: selectionHighlight.left; right: selectionHighlight.right; bottom: selectionHighlight.bottom; }
66  height: units.dp(2)
67  color: theme.palette.normal.focus
68  visible: highlightShown
69  }
70 
71  BorderImage {
72  anchors {
73  fill: root
74  margins: active ? -units.gu(2) : -units.gu(1.5)
75  }
76  source: "graphics/dropshadow2gu.sci"
77  opacity: root.shadowOpacity * .3
78  visible: !fullscreen
79  }
80 
81  WindowDecoration {
82  id: decoration
83  target: root.parent
84  objectName: "appWindowDecoration"
85  anchors { left: parent.left; top: parent.top; right: parent.right }
86  height: units.gu(3)
87  width: root.width
88  title: applicationWindow.title
89  visible: root.decorationShown
90 
91  onCloseClicked: root.closeClicked();
92  onMaximizeClicked: { root.decorationPressed(); root.maximizeClicked(); }
93  onMaximizeHorizontallyClicked: { root.decorationPressed(); root.maximizeHorizontallyClicked(); }
94  onMaximizeVerticallyClicked: { root.decorationPressed(); root.maximizeVerticallyClicked(); }
95  onMinimizeClicked: root.minimizeClicked();
96  onPressed: root.decorationPressed();
97  }
98 
99  ApplicationWindow {
100  id: applicationWindow
101  objectName: "appWindow"
102  anchors.top: parent.top
103  anchors.topMargin: decoration.height
104  anchors.left: parent.left
105  requestedHeight: root.requestedHeight - (root.decorationShown ? decoration.height : 0)
106  interactive: true
107  focus: true
108  }
109 }