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