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 
22 MouseArea {
23  id: root
24  clip: true
25 
26  property Item target
27  property alias title: titleLabel.text
28  property bool active: false
29  hoverEnabled: true
30 
31  signal close()
32  signal minimize()
33  signal maximize()
34 
35  QtObject {
36  id: priv
37  property real distanceX
38  property real distanceY
39  property bool dragging
40  }
41 
42  onPressedChanged: {
43  if (pressed) {
44  var pos = mapToItem(root.target, mouseX, mouseY);
45  priv.distanceX = pos.x;
46  priv.distanceY = pos.y;
47  priv.dragging = true;
48  Mir.cursorName = "grabbing";
49  } else {
50  priv.dragging = false;
51  Mir.cursorName = "";
52  }
53  }
54  onPositionChanged: {
55  if (priv.dragging) {
56  var pos = mapToItem(root.target.parent, mouseX, mouseY);
57  root.target.x = pos.x - priv.distanceX;
58  root.target.y = pos.y - priv.distanceY;
59  }
60  }
61 
62  Rectangle {
63  anchors.fill: parent
64  anchors.bottomMargin: -radius
65  radius: units.gu(.5)
66  gradient: Gradient {
67  GradientStop { color: "#626055"; position: 0 }
68  GradientStop { color: "#3C3B37"; position: 1 }
69  }
70  }
71 
72  Row {
73  anchors { left: parent.left; top: parent.top; bottom: parent.bottom; margins: units.gu(0.7) }
74  spacing: units.gu(1)
75  opacity: root.active ? 1 : 0.5
76 
77  WindowControlButtons {
78  height: parent.height
79  onClose: root.close();
80  onMinimize: root.minimize();
81  onMaximize: root.maximize();
82  }
83 
84  Label {
85  id: titleLabel
86  objectName: "windowDecorationTitle"
87  color: "#DFDBD2"
88  height: parent.height
89  verticalAlignment: Text.AlignVCenter
90  fontSize: "small"
91  font.bold: true
92  }
93  }
94 }