2 * Copyright (C) 2014-2016 Canonical, Ltd.
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.
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.
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/>.
18 import Unity.Application 0.1 // For Mir singleton
19 import Ubuntu.Components 1.3
20 import "../Components"
21 import "../Components/PanelState"
28 property alias title: titleLabel.text
29 property alias maximizeButtonShown: buttons.maximizeButtonShown
30 property bool active: false
31 acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
32 property alias overlayShown: buttons.overlayShown
35 signal minimizeClicked()
36 signal maximizeClicked()
37 signal maximizeHorizontallyClicked()
38 signal maximizeVerticallyClicked()
41 if (maximizeButtonShown && mouse.button == Qt.LeftButton) {
42 root.maximizeClicked();
48 property real distanceX
49 property real distanceY
50 property bool dragging
54 if (pressed && pressedButtons == Qt.LeftButton) {
55 var pos = mapToItem(root.target, mouseX, mouseY);
56 priv.distanceX = pos.x;
57 priv.distanceY = pos.y;
60 priv.dragging = false;
67 Mir.cursorName = "grabbing";
68 var pos = mapToItem(root.target.parent, mouseX, mouseY);
69 // Use integer coordinate values to ensure that target is left in a pixel-aligned
70 // position. Mouse movement could have subpixel precision, yielding a fractional
72 root.target.requestedX = Math.round(pos.x - priv.distanceX);
73 root.target.requestedY = Math.round(Math.max(pos.y - priv.distanceY, PanelState.panelHeight));
77 // do not let unhandled wheel event pass thru the decoration
78 onWheel: wheel.accepted = true;
82 anchors.bottomMargin: -radius
84 color: theme.palette.normal.background
90 leftMargin: overlayShown ? units.gu(5) : units.gu(1)
91 rightMargin: units.gu(1)
92 topMargin: units.gu(0.5)
93 bottomMargin: units.gu(0.5)
95 Behavior on anchors.leftMargin {
96 UbuntuNumberAnimation {}
101 WindowControlButtons {
103 height: parent.height
105 onCloseClicked: root.closeClicked();
106 onMinimizeClicked: root.minimizeClicked();
107 onMaximizeClicked: root.maximizeClicked();
108 onMaximizeHorizontallyClicked: root.maximizeHorizontallyClicked();
109 onMaximizeVerticallyClicked: root.maximizeVerticallyClicked();
110 closeButtonShown: root.target.application.appId !== "unity8-dash"
116 objectName: "windowDecorationTitle"
117 color: root.active ? "white" : UbuntuColors.slate
118 height: parent.height
119 width: parent.width - buttons.width - parent.anchors.rightMargin - parent.anchors.leftMargin
120 verticalAlignment: Text.AlignVCenter
122 font.weight: root.active ? Font.Light : Font.Medium
123 elide: Text.ElideRight
124 opacity: overlayShown ? 0 : 1
125 visible: opacity == 1
126 Behavior on opacity {
127 OpacityAnimator { duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing }