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  property alias overlayShown: buttons.overlayShown
31 
32  hoverEnabled: true
33 
34  signal closeClicked()
35  signal minimizeClicked()
36  signal maximizeClicked()
37  signal maximizeHorizontallyClicked()
38  signal maximizeVerticallyClicked()
39 
40  onDoubleClicked: root.maximizeClicked()
41 
42  QtObject {
43  id: priv
44  property real distanceX
45  property real distanceY
46  property bool dragging
47  }
48 
49  onPressedChanged: {
50  if (pressed) {
51  var pos = mapToItem(root.target, mouseX, mouseY);
52  priv.distanceX = pos.x;
53  priv.distanceY = pos.y;
54  priv.dragging = true;
55  } else {
56  priv.dragging = false;
57  Mir.cursorName = "";
58  }
59  }
60 
61  onPositionChanged: {
62  if (priv.dragging) {
63  Mir.cursorName = "grabbing";
64  var pos = mapToItem(root.target.parent, mouseX, mouseY);
65  // Use integer coordinate values to ensure that target is left in a pixel-aligned
66  // position. Mouse movement could have subpixel precision, yielding a fractional
67  // mouse position.
68  root.target.x = Math.round(pos.x - priv.distanceX);
69  root.target.y = Math.round(Math.max(pos.y - priv.distanceY, PanelState.panelHeight));
70  }
71  }
72 
73  Rectangle {
74  anchors.fill: parent
75  anchors.bottomMargin: -radius
76  radius: units.gu(.5)
77  color: theme.palette.normal.background
78  }
79 
80  Row {
81  anchors {
82  fill: parent
83  leftMargin: overlayShown ? units.gu(5) : units.gu(1)
84  rightMargin: units.gu(1)
85  topMargin: units.gu(0.5)
86  bottomMargin: units.gu(0.5)
87  }
88  Behavior on anchors.leftMargin {
89  UbuntuNumberAnimation {}
90  }
91 
92  spacing: units.gu(3)
93 
94  WindowControlButtons {
95  id: buttons
96  height: parent.height
97  active: root.active
98  onCloseClicked: root.closeClicked();
99  onMinimizeClicked: root.minimizeClicked();
100  onMaximizeClicked: root.maximizeClicked();
101  onMaximizeHorizontallyClicked: root.maximizeHorizontallyClicked();
102  onMaximizeVerticallyClicked: root.maximizeVerticallyClicked();
103  closeButtonShown: root.target.application.appId !== "unity8-dash"
104  target: root.target
105  }
106 
107  Label {
108  id: titleLabel
109  objectName: "windowDecorationTitle"
110  color: root.active ? "white" : UbuntuColors.slate
111  height: parent.height
112  width: parent.width - buttons.width - parent.anchors.rightMargin - parent.anchors.leftMargin
113  verticalAlignment: Text.AlignVCenter
114  fontSize: "medium"
115  font.weight: root.active ? Font.Light : Font.Medium
116  elide: Text.ElideRight
117  opacity: overlayShown ? 0 : 1
118  visible: opacity == 1
119  Behavior on opacity {
120  OpacityAnimator { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }
121  }
122  }
123  }
124 }