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 window: applicationWindow
30  property alias application: applicationWindow.application
31  property alias active: decoration.active
32  property alias title: decoration.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  signal close()
43  signal maximize()
44  signal minimize()
45  signal decorationPressed()
46 
47  Rectangle {
48  id: selectionHighlight
49  anchors.fill: parent
50  anchors.margins: -units.gu(1)
51  color: "white"
52  opacity: highlightShown ? 0.15 : 0
53  }
54 
55  Rectangle {
56  anchors { left: selectionHighlight.left; right: selectionHighlight.right; bottom: selectionHighlight.bottom; }
57  height: units.dp(2)
58  color: UbuntuColors.orange
59  visible: highlightShown
60  }
61 
62  BorderImage {
63  anchors {
64  fill: root
65  margins: active ? -units.gu(2) : -units.gu(1.5)
66  }
67  source: "graphics/dropshadow2gu.sci"
68  opacity: root.shadowOpacity * .3
69  enabled: !fullscreen
70  }
71 
72  WindowDecoration {
73  id: decoration
74  target: root.parent
75  objectName: application ? "appWindowDecoration_" + application.appId : "appWindowDecoration_null"
76  anchors { left: parent.left; top: parent.top; right: parent.right }
77  height: units.gu(3)
78  width: root.width
79  title: window.title
80  visible: root.decorationShown
81 
82  onClose: root.close();
83  onMaximize: { root.decorationPressed(); root.maximize(); }
84  onMinimize: root.minimize();
85  onPressed: root.decorationPressed();
86  }
87 
88  ApplicationWindow {
89  id: applicationWindow
90  objectName: application ? "appWindow_" + application.appId : "appWindow_null"
91  anchors.top: parent.top
92  anchors.topMargin: decoration.height
93  anchors.left: parent.left
94  requestedHeight: root.requestedHeight - (root.decorationShown ? decoration.height : 0)
95  interactive: true
96  focus: true
97  }
98 }