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 QtQuick.Layouts 1.1
19 import Ubuntu.Components 1.3
20 import Unity.Application 0.1
21 import "../Components"
22 import "../Components/PanelState"
23 import "../ApplicationMenus"
28 property alias closeButtonVisible: buttons.closeButtonShown
29 property alias title: titleLabel.text
30 property alias maximizeButtonShown: buttons.maximizeButtonShown
31 property alias minimizeButtonVisible: buttons.minimizeButtonVisible
32 property bool active: false
33 property alias overlayShown: buttons.overlayShown
34 property var menu: undefined
35 property bool enableMenus: true
36 property bool windowMoving: false
37 property alias windowControlButtonsVisible: buttons.visible
39 readonly property real buttonsWidth: buttons.width + row.spacing
41 acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
45 signal minimizeClicked()
46 signal maximizeClicked()
47 signal maximizeHorizontallyClicked()
48 signal maximizeVerticallyClicked()
50 signal pressedChangedEx(bool pressed, var pressedButtons, real mouseX, real mouseY)
53 if (mouse.button == Qt.LeftButton) {
54 root.maximizeClicked();
58 // do not let unhandled wheel event pass thru the decoration
59 onWheel: wheel.accepted = true;
63 property var menuBar: menuBarLoader.item
65 property bool shouldShowMenus: root.enableMenus &&
68 (menuBar.showRequested || root.containsMouse)
75 color: theme.palette.normal.background
80 bottom: background.bottom
84 height: background.radius
85 color: theme.palette.normal.background
92 leftMargin: overlayShown ? units.gu(5) : units.gu(1)
93 rightMargin: units.gu(1)
95 Behavior on anchors.leftMargin {
96 UbuntuNumberAnimation {}
101 WindowControlButtons {
102 Layout.fillHeight: true
103 Layout.fillWidth: false
104 Layout.topMargin: units.gu(0.5)
105 Layout.bottomMargin: units.gu(0.5)
109 onCloseClicked: root.closeClicked();
110 onMinimizeClicked: root.minimizeClicked();
111 onMaximizeClicked: root.maximizeClicked();
112 onMaximizeHorizontallyClicked: root.maximizeHorizontallyClicked();
113 onMaximizeVerticallyClicked: root.maximizeVerticallyClicked();
117 Layout.preferredHeight: parent.height
118 Layout.fillWidth: true
122 objectName: "windowDecorationTitle"
123 color: root.active ? "white" : UbuntuColors.slate
124 height: parent.height
126 verticalAlignment: Text.AlignVCenter
128 font.weight: root.active ? Font.Light : Font.Medium
129 elide: Text.ElideRight
130 opacity: overlayShown || menuBarLoader.visible ? 0 : 1
131 visible: opacity != 0
132 Behavior on opacity { UbuntuNumberAnimation {} }
137 objectName: "menuBarLoader"
138 anchors.bottom: parent.bottom
139 height: parent.height
141 active: root.menu !== undefined
143 sourceComponent: MenuBar {
145 height: menuBarLoader.height
146 enableKeyFilter: valid && root.active && root.enableMenus
147 unityMenuModel: root.menu
148 windowMoving: root.windowMoving
150 onPressed: root.onPressed(mouse)
151 onPressedChangedEx: root.pressedChangedEx(pressed, pressedButtons, mouseX, mouseY)
152 onPositionChanged: root.onPositionChanged(mouse)
153 onReleased: root.onReleased(mouse)
154 onDoubleClicked: root.onDoubleClicked(mouse)
157 opacity: (!overlayShown && priv.shouldShowMenus) || (active && priv.menuBar.valid && root.windowMoving) ? 1 : 0
158 visible: opacity == 1
159 Behavior on opacity { UbuntuNumberAnimation {} }