Unity 8
WindowDecoration.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 "../Components"
20 
21 MouseArea {
22  id: root
23  clip: true
24 
25  property Item target // appDelegate
26  property alias title: titleLabel.text
27  property alias maximizeButtonShown: buttons.maximizeButtonShown
28  property bool active: false
29  property alias overlayShown: buttons.overlayShown
30 
31  readonly property real buttonsWidth: buttons.width + row.spacing
32 
33  acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
34  hoverEnabled: true
35 
36  signal closeClicked()
37  signal minimizeClicked()
38  signal maximizeClicked()
39  signal maximizeHorizontallyClicked()
40  signal maximizeVerticallyClicked()
41 
42  onDoubleClicked: {
43  if (target.canBeMaximized && mouse.button == Qt.LeftButton) {
44  root.maximizeClicked();
45  }
46  }
47 
48  // do not let unhandled wheel event pass thru the decoration
49  onWheel: wheel.accepted = true;
50 
51  Rectangle {
52  anchors.fill: parent
53  anchors.bottomMargin: -radius
54  radius: units.gu(.5)
55  color: theme.palette.normal.background
56  }
57 
58  Row {
59  id: row
60  anchors {
61  fill: parent
62  leftMargin: overlayShown ? units.gu(5) : units.gu(1)
63  rightMargin: units.gu(1)
64  topMargin: units.gu(0.5)
65  bottomMargin: units.gu(0.5)
66  }
67  Behavior on anchors.leftMargin {
68  UbuntuNumberAnimation {}
69  }
70 
71  spacing: units.gu(3)
72 
73  WindowControlButtons {
74  id: buttons
75  height: parent.height
76  active: root.active
77  onCloseClicked: root.closeClicked();
78  onMinimizeClicked: root.minimizeClicked();
79  onMaximizeClicked: root.maximizeClicked();
80  onMaximizeHorizontallyClicked: if (root.target.canBeMaximizedHorizontally) root.maximizeHorizontallyClicked();
81  onMaximizeVerticallyClicked: if (root.target.canBeMaximizedVertically) root.maximizeVerticallyClicked();
82  closeButtonShown: root.target.application.appId !== "unity8-dash"
83  }
84 
85  Label {
86  id: titleLabel
87  objectName: "windowDecorationTitle"
88  color: root.active ? "white" : UbuntuColors.slate
89  height: parent.height
90  width: parent.width - buttons.width - parent.anchors.rightMargin - parent.anchors.leftMargin
91  verticalAlignment: Text.AlignVCenter
92  fontSize: "medium"
93  font.weight: root.active ? Font.Light : Font.Medium
94  elide: Text.ElideRight
95  opacity: overlayShown ? 0 : 1
96  visible: opacity != 0
97  Behavior on opacity { UbuntuNumberAnimation {} }
98  }
99  }
100 }