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.3
20 import Ubuntu.Components 1.1
21 import Unity.Application 0.1
22 
23 FocusScope {
24  id: root
25 
26  property alias window: applicationWindow
27  property alias application: applicationWindow.application
28  property alias active: decoration.active
29 
30  property bool decorationShown: true
31  property bool highlightShown: false
32  property real shadowOpacity: 1
33 
34  property int windowWidth: width
35  property int windowHeight: height
36 
37  signal close();
38  signal maximize();
39  signal minimize();
40 
41  state: "normal"
42  states: [
43  State {
44  name: "normal"
45  PropertyChanges {
46  target: root
47  width: windowWidth
48  height: windowHeight
49  }
50  },
51  State {
52  name: "transformed"
53  PropertyChanges {
54  target: applicationWindow
55  itemScale: Math.max(root.width / root.windowWidth, root.height / root.windowHeight)
56  interactive: false
57  }
58  PropertyChanges {
59  target: clipper
60  clip: true
61  }
62  }
63  ]
64 
65  BorderImage {
66  anchors {
67  fill: root
68  margins: -units.gu(2)
69  }
70  source: "graphics/dropshadow2gu.sci"
71  opacity: root.shadowOpacity * .3
72  }
73 
74  Rectangle {
75  id: selectionHighlight
76  anchors.fill: parent
77  anchors.margins: -units.gu(1)
78  color: "white"
79  opacity: highlightShown ? 0.15 : 0
80  }
81 
82  Rectangle {
83  anchors { left: selectionHighlight.left; right: selectionHighlight.right; bottom: selectionHighlight.bottom; }
84  height: units.dp(2)
85  color: UbuntuColors.orange
86  visible: root.highlightShown
87  }
88 
89  WindowDecoration {
90  id: decoration
91  objectName: application ? "appWindowDecoration_" + application.appId : "appWindowDecoration_null"
92  anchors { left: parent.left; top: parent.top; right: parent.right }
93  height: units.gu(3)
94  title: model.name
95  onClose: root.close();
96  onMaximize: root.maximize();
97  onMinimize: root.minimize();
98  visible: decorationShown
99  }
100 
101  Item {
102  id: clipper
103  anchors.fill: parent
104 
105  ApplicationWindow {
106  id: applicationWindow
107  objectName: application ? "appWindow_" + application.appId : "appWindow_null"
108  anchors.top: parent.top
109  anchors.topMargin: root.decorationShown ? decoration.height : 0
110  anchors.left: parent.left
111  width: root.windowWidth
112  height: root.windowHeight - (root.decorationShown ? decoration.height : 0)
113  interactive: true
114  focus: true
115 
116  property real itemScale: 1
117  transform: [
118  Scale {
119  origin.x: 0; origin.y: 0
120  xScale: applicationWindow.itemScale
121  yScale: applicationWindow.itemScale
122  }
123  ]
124  }
125  }
126 }