Lomiri
Loading...
Searching...
No Matches
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
17import QtQuick 2.12
18import QtQuick.Layouts 1.1
19import Lomiri.Components 1.3
20import QtMir.Application 0.1
21import "../Components"
22import "../Components/PanelState"
23import "../ApplicationMenus"
24
25MouseArea {
26 id: root
27
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
38 property PanelState panelState
39
40 readonly property real buttonsWidth: buttons.width + row.spacing
41
42 acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
43 hoverEnabled: true
44
45 signal closeClicked()
46 signal minimizeClicked()
47 signal maximizeClicked()
48 signal maximizeHorizontallyClicked()
49 signal maximizeVerticallyClicked()
50
51 signal pressedChangedEx(bool pressed, var pressedButtons, real mouseX, real mouseY)
52
53 onDoubleClicked: {
54 if (mouse.button == Qt.LeftButton) {
55 root.maximizeClicked();
56 }
57 }
58
59 // do not let unhandled wheel event pass thru the decoration
60 onWheel: wheel.accepted = true;
61
62 QtObject {
63 id: priv
64 property var menuBar: menuBarLoader.item
65
66 property bool shouldShowMenus: root.enableMenus &&
67 menuBar &&
68 menuBar.valid &&
69 (menuBar.showRequested || root.containsMouse)
70 }
71
72 Rectangle {
73 id: background
74 anchors.fill: parent
75 radius: units.gu(.5)
76 color: theme.palette.normal.background
77 }
78
79 Rectangle {
80 anchors {
81 bottom: background.bottom
82 left: parent.left
83 right: parent.right
84 }
85 height: background.radius
86 color: theme.palette.normal.background
87 }
88
89 RowLayout {
90 id: row
91 anchors {
92 fill: parent
93 leftMargin: overlayShown ? units.gu(5) : units.gu(1)
94 rightMargin: units.gu(1)
95 }
96 Behavior on anchors.leftMargin {
97 LomiriNumberAnimation {}
98 }
99
100 spacing: units.gu(3)
101
102 WindowControlButtons {
103 Layout.fillHeight: true
104 Layout.fillWidth: false
105 Layout.topMargin: units.gu(0.5)
106 Layout.bottomMargin: units.gu(0.5)
107
108 id: buttons
109 active: root.active
110 onCloseClicked: root.closeClicked();
111 onMinimizeClicked: root.minimizeClicked();
112 onMaximizeClicked: root.maximizeClicked();
113 onMaximizeHorizontallyClicked: root.maximizeHorizontallyClicked();
114 onMaximizeVerticallyClicked: root.maximizeVerticallyClicked();
115 }
116
117 Item {
118 Layout.preferredHeight: parent.height
119 Layout.fillWidth: true
120
121 Label {
122 id: titleLabel
123 objectName: "windowDecorationTitle"
124 color: root.active ? "white" : LomiriColors.slate
125 height: parent.height
126 width: parent.width
127 verticalAlignment: Text.AlignVCenter
128 fontSize: "medium"
129 font.weight: root.active ? Font.Light : Font.Medium
130 elide: Text.ElideRight
131 opacity: overlayShown || menuBarLoader.visible ? 0 : 1
132 visible: opacity != 0
133 Behavior on opacity { LomiriNumberAnimation {} }
134 }
135
136 Loader {
137 id: menuBarLoader
138 objectName: "menuBarLoader"
139 anchors.bottom: parent.bottom
140 height: parent.height
141 width: parent.width
142 active: root.menu !== undefined
143
144 sourceComponent: MenuBar {
145 id: menuBar
146 height: menuBarLoader.height
147 enableKeyFilter: valid && root.active && root.enableMenus
148 lomiriMenuModel: root.menu
149 windowMoving: root.windowMoving
150 panelState: root.panelState
151
152 onPressed: root.onPressed(mouse)
153 onPressedChangedEx: root.pressedChangedEx(pressed, pressedButtons, mouseX, mouseY)
154 onPositionChanged: root.onPositionChanged(mouse)
155 onReleased: root.onReleased(mouse)
156 onDoubleClicked: root.onDoubleClicked(mouse)
157 }
158
159 opacity: (!overlayShown && priv.shouldShowMenus) || (active && priv.menuBar.valid && root.windowMoving) ? 1 : 0
160 visible: opacity == 1
161 Behavior on opacity { LomiriNumberAnimation {} }
162 }
163 }
164 }
165}