Unity 8
WindowDecoration.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 
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 close()
33  signal minimize()
34  signal maximize()
35 
36  onDoubleClicked: root.maximize()
37 
38  QtObject {
39  id: priv
40  property real distanceX
41  property real distanceY
42  property bool dragging
43  }
44 
45  onPressedChanged: {
46  if (pressed) {
47  var pos = mapToItem(root.target, mouseX, mouseY);
48  priv.distanceX = pos.x;
49  priv.distanceY = pos.y;
50  priv.dragging = true;
51  } else {
52  priv.dragging = false;
53  Mir.cursorName = "";
54  }
55  }
56 
57  onPositionChanged: {
58  if (priv.dragging) {
59  Mir.cursorName = "grabbing";
60  var pos = mapToItem(root.target.parent, mouseX, mouseY);
61  root.target.x = pos.x - priv.distanceX;
62  root.target.y = Math.max(pos.y - priv.distanceY, PanelState.panelHeight);
63  }
64  }
65 
66  Rectangle {
67  anchors.fill: parent
68  anchors.bottomMargin: -radius
69  radius: units.gu(.5)
70  color: theme.palette.normal.background
71  }
72 
73  Row {
74  anchors {
75  fill: parent
76  leftMargin: units.gu(1)
77  rightMargin: units.gu(1)
78  topMargin: units.gu(0.5)
79  bottomMargin: units.gu(0.5)
80  }
81  spacing: units.gu(3)
82 
83  WindowControlButtons {
84  id: buttons
85  height: parent.height
86  active: root.active
87  onClose: root.close();
88  onMinimize: root.minimize();
89  onMaximize: root.maximize();
90  }
91 
92  Label {
93  id: titleLabel
94  objectName: "windowDecorationTitle"
95  color: root.active ? "white" : "#5d5d5d"
96  height: parent.height
97  width: parent.width - buttons.width - parent.anchors.rightMargin - parent.anchors.leftMargin
98  verticalAlignment: Text.AlignVCenter
99  fontSize: "medium"
100  font.weight: root.active ? Font.Light : Font.Normal
101  elide: Text.ElideRight
102  }
103  }
104 }