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 Unity.Application 0.1 // For Mir singleton
19 import Ubuntu.Components 1.3
20 import "../Components"
21 import "../Components/PanelState"
22 
23 MouseArea {
24  id: root
25  clip: true
26 
27  property Item target
28  property alias title: titleLabel.text
29  property bool active: false
30  hoverEnabled: true
31 
32  signal closeClicked()
33  signal minimizeClicked()
34  signal maximizeClicked()
35  signal maximizeHorizontallyClicked()
36  signal maximizeVerticallyClicked()
37 
38  onDoubleClicked: root.maximizeClicked()
39 
40  QtObject {
41  id: priv
42  property real distanceX
43  property real distanceY
44  property bool dragging
45  }
46 
47  onPressedChanged: {
48  if (pressed) {
49  var pos = mapToItem(root.target, mouseX, mouseY);
50  priv.distanceX = pos.x;
51  priv.distanceY = pos.y;
52  priv.dragging = true;
53  } else {
54  priv.dragging = false;
55  Mir.cursorName = "";
56  }
57  }
58 
59  onPositionChanged: {
60  if (priv.dragging) {
61  Mir.cursorName = "grabbing";
62  var pos = mapToItem(root.target.parent, mouseX, mouseY);
63  root.target.x = pos.x - priv.distanceX;
64  root.target.y = Math.max(pos.y - priv.distanceY, PanelState.panelHeight);
65  }
66  }
67 
68  Rectangle {
69  anchors.fill: parent
70  anchors.bottomMargin: -radius
71  radius: units.gu(.5)
72  color: theme.palette.normal.background
73  }
74 
75  Row {
76  anchors {
77  fill: parent
78  leftMargin: units.gu(1)
79  rightMargin: units.gu(1)
80  topMargin: units.gu(0.5)
81  bottomMargin: units.gu(0.5)
82  }
83  spacing: units.gu(3)
84 
85  WindowControlButtons {
86  id: buttons
87  height: parent.height
88  active: root.active
89  onCloseClicked: root.closeClicked();
90  onMinimizeClicked: root.minimizeClicked();
91  onMaximizeClicked: root.maximizeClicked();
92  onMaximizeHorizontallyClicked: root.maximizeHorizontallyClicked();
93  onMaximizeVerticallyClicked: root.maximizeVerticallyClicked();
94  closeButtonShown: root.target.application.appId !== "unity8-dash"
95  }
96 
97  Label {
98  id: titleLabel
99  objectName: "windowDecorationTitle"
100  color: root.active ? "white" : UbuntuColors.slate
101  height: parent.height
102  width: parent.width - buttons.width - parent.anchors.rightMargin - parent.anchors.leftMargin
103  verticalAlignment: Text.AlignVCenter
104  fontSize: "medium"
105  font.weight: root.active ? Font.Light : Font.Medium
106  elide: Text.ElideRight
107  }
108  }
109 }