on db4dbae help sign in
unity8/qml/Panel/Panel.qml
248 lines 8.4 kB history raw
1/*
2 * Copyright (C) 2013-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 */
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19import Unity.Application 0.1
20import "../Components"
21import "../Components/PanelState"
22import ".."
24Item {
25 id: root
26 readonly property real panelHeight: indicatorArea.y + d.indicatorHeight
27 property alias indicators: __indicators
28 property alias callHint: __callHint
29 property bool fullscreenMode: false
30 property real indicatorAreaShowProgress: 1.0
31 property bool locked: false
33 MouseArea {
34 anchors.fill: parent
35 anchors.topMargin: panelHeight
36 visible: !indicators.fullyClosed
37 enabled: visible
38 onClicked: if (indicators.fullyOpened) indicators.hide();
39 hoverEnabled: true // should also eat hover events, otherwise they will pass through
40 }
42 Binding {
43 target: PanelState
44 property: "panelHeight"
45 value: indicators.minimizedPanelHeight
46 }
48 Item {
49 id: indicatorArea
50 objectName: "indicatorArea"
52 anchors.fill: parent
54 transform: Translate {
55 y: indicators.state === "initial"
56 ? (1.0 - indicatorAreaShowProgress) * -d.indicatorHeight
57 : 0
58 }
60 BorderImage {
61 id: indicatorsDropShadow
62 anchors {
63 fill: indicators
64 leftMargin: -units.gu(1)
65 bottomMargin: -units.gu(1)
66 }
67 visible: !indicators.fullyClosed
68 source: "graphics/rectangular_dropshadow.sci"
69 }
71 BorderImage {
72 id: panelDropShadow
73 anchors {
74 fill: indicatorAreaBackground
75 bottomMargin: -units.gu(1)
76 }
77 visible: PanelState.dropShadow && !callHint.visible
78 source: "graphics/rectangular_dropshadow.sci"
79 }
81 Rectangle {
82 id: indicatorAreaBackground
83 color: callHint.visible ? theme.palette.normal.positive : theme.palette.normal.background
84 anchors {
85 top: parent.top
86 left: parent.left
87 right: parent.right
88 }
89 height: indicators.minimizedPanelHeight
91 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration } }
92 }
94 MouseArea {
95 objectName: "windowControlArea"
96 anchors {
97 top: parent.top
98 left: parent.left
99 right: indicators.left
100 }
101 height: indicators.minimizedPanelHeight
102 hoverEnabled: true
103 onClicked: callHint.visible ? callHint.showLiveCall() : PanelState.focusMaximizedApp()
104 onDoubleClicked: PanelState.restoreClicked()
106 property bool mouseWasPressed: false
107 onPressed: mouseWasPressed = containsPress
108 onMouseYChanged: {
109 if (mouseWasPressed && mouseY > panelHeight) {
110 PanelState.restoreClicked(); // restore the window when "dragging" the panel down
111 mouseWasPressed = false;
112 }
113 }
115 // WindowControlButtons inside the mouse area, otherwise QML doesn't grok nested hover events :/
116 // cf. https://bugreports.qt.io/browse/QTBUG-32909
117 WindowControlButtons {
118 id: windowControlButtons
119 objectName: "panelWindowControlButtons"
120 anchors {
121 left: parent.left
122 top: parent.top
123 }
124 height: indicators.minimizedPanelHeight
126 visible: ((PanelState.buttonsVisible && parent.containsMouse) || PanelState.buttonsAlwaysVisible)
127 && !root.locked && !callHint.visible
128 active: PanelState.buttonsVisible || PanelState.buttonsAlwaysVisible
129 windowIsMaximized: true
130 onCloseClicked: PanelState.closeClicked()
131 onMinimizeClicked: PanelState.minimizeClicked()
132 onMaximizeClicked: PanelState.restoreClicked()
133 closeButtonShown: PanelState.closeButtonShown
134 }
135 }
137 IndicatorsMenu {
138 id: __indicators
139 objectName: "indicators"
141 anchors {
142 top: parent.top
143 right: parent.right
144 }
146 shown: false
147 width: root.width - (windowControlButtons.visible ? windowControlButtons.width + titleLabel.width : 0)
148 minimizedPanelHeight: units.gu(3)
149 expandedPanelHeight: units.gu(7)
150 openedHeight: root.height
152 overFlowWidth: {
153 if (callHint.visible) {
154 return Math.max(root.width - (callHint.width + units.gu(2)), 0)
155 }
156 return root.width
157 }
158 enableHint: !callHint.active && !fullscreenMode
159 showOnClick: !callHint.visible
160 panelColor: indicatorAreaBackground.color
162 onShowTapped: {
163 if (callHint.active) {
164 callHint.showLiveCall();
165 }
166 }
167 }
169 Label {
170 id: titleLabel
171 objectName: "windowDecorationTitle"
172 anchors {
173 left: parent.left
174 right: __indicators.left
175 top: parent.top
176 leftMargin: units.gu(1)
177 rightMargin: units.gu(1)
178 topMargin: units.gu(0.5)
179 bottomMargin: units.gu(0.5)
180 }
181 color: "white"
182 height: indicators.minimizedPanelHeight - anchors.topMargin - anchors.bottomMargin
183 opacity: !windowControlButtons.visible && !root.locked && !callHint.visible ? 1 : 0
184 visible: opacity != 0
185 verticalAlignment: Text.AlignVCenter
186 fontSize: "medium"
187 font.weight: PanelState.buttonsVisible ? Font.Light : Font.Medium
188 text: PanelState.title
189 elide: Text.ElideRight
190 maximumLineCount: 1
191 Behavior on opacity { UbuntuNumberAnimation {} }
192 }
194 // TODO here would the Locally integrated menus come
196 ActiveCallHint {
197 id: __callHint
198 anchors {
199 top: parent.top
200 left: parent.left
201 }
202 height: indicators.minimizedPanelHeight
203 visible: active && indicators.state == "initial"
204 }
205 }
207 QtObject {
208 id: d
209 objectName: "panelPriv"
210 readonly property real indicatorHeight: indicators.minimizedPanelHeight
211 }
213 states: [
214 State {
215 name: "onscreen" //fully opaque and visible at top edge of screen
216 when: !fullscreenMode
217 PropertyChanges {
218 target: indicatorArea;
219 anchors.topMargin: 0
220 opacity: 1;
221 }
222 },
223 State {
224 name: "offscreen" //pushed off screen
225 when: fullscreenMode
226 PropertyChanges {
227 target: indicatorArea;
228 anchors.topMargin: indicators.state === "initial" ? -d.indicatorHeight : 0
229 opacity: indicators.fullyClosed ? 0.0 : 1.0
230 }
231 PropertyChanges {
232 target: indicators.showDragHandle;
233 anchors.bottomMargin: -units.gu(1)
234 }
235 }
236 ]
238 transitions: [
239 Transition {
240 to: "onscreen"
241 UbuntuNumberAnimation { target: indicatorArea; properties: "anchors.topMargin,opacity" }
242 },
243 Transition {
244 to: "offscreen"
245 UbuntuNumberAnimation { target: indicatorArea; properties: "anchors.topMargin,opacity" }
246 }
247 ]