on 1839efc help sign in
unity8/qml/Panel/Panel.qml
236 lines 7.9 kB history raw
1/*
2 * Copyright (C) 2013-2015 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 ? UbuntuColors.green : 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 anchors {
96 top: parent.top
97 left: parent.left
98 right: indicators.left
99 }
100 height: indicators.minimizedPanelHeight
101 hoverEnabled: true
102 onClicked: callHint.visible ? callHint.showLiveCall() : PanelState.focusMaximizedApp()
103 onDoubleClicked: PanelState.maximize()
105 // WindowControlButtons inside the mouse area, otherwise QML doesn't grok nested hover events :/
106 // cf. https://bugreports.qt.io/browse/QTBUG-32909
107 WindowControlButtons {
108 id: windowControlButtons
109 objectName: "panelWindowControlButtons"
110 anchors {
111 left: parent.left
112 top: parent.top
113 leftMargin: units.gu(1)
114 topMargin: units.gu(0.5)
115 bottomMargin: units.gu(0.5)
116 }
117 height: indicators.minimizedPanelHeight - anchors.topMargin - anchors.bottomMargin
118 visible: PanelState.buttonsVisible && parent.containsMouse && !root.locked && !callHint.visible
119 active: PanelState.buttonsVisible
120 closeButtonShown: PanelState.closeButtonShown
121 onClose: PanelState.close()
122 onMinimize: PanelState.minimize()
123 onMaximize: PanelState.maximize()
124 }
125 }
127 IndicatorsMenu {
128 id: __indicators
129 objectName: "indicators"
131 anchors {
132 top: parent.top
133 right: parent.right
134 }
136 shown: false
137 width: root.width - (windowControlButtons.visible ? windowControlButtons.width + titleLabel.width : 0)
138 minimizedPanelHeight: units.gu(3)
139 expandedPanelHeight: units.gu(7)
140 openedHeight: root.height
142 overFlowWidth: {
143 if (callHint.visible) {
144 return Math.max(root.width - (callHint.width + units.gu(2)), 0)
145 }
146 return root.width
147 }
148 enableHint: !callHint.active && !fullscreenMode
149 showOnClick: !callHint.visible
150 panelColor: indicatorAreaBackground.color
152 onShowTapped: {
153 if (callHint.active) {
154 callHint.showLiveCall();
155 }
156 }
157 }
159 Label {
160 id: titleLabel
161 objectName: "windowDecorationTitle"
162 anchors {
163 left: parent.left
164 right: __indicators.left
165 top: parent.top
166 leftMargin: units.gu(1)
167 rightMargin: units.gu(1)
168 topMargin: units.gu(0.5)
169 bottomMargin: units.gu(0.5)
170 }
171 color: "white"
172 height: indicators.minimizedPanelHeight - anchors.topMargin - anchors.bottomMargin
173 visible: !windowControlButtons.visible && !root.locked && !callHint.visible
174 verticalAlignment: Text.AlignVCenter
175 fontSize: "medium"
176 font.weight: PanelState.buttonsVisible ? Font.Light : Font.Medium
177 text: PanelState.title
178 elide: Text.ElideRight
179 maximumLineCount: 1
180 }
182 // TODO here would the Locally integrated menus come
184 ActiveCallHint {
185 id: __callHint
186 anchors {
187 top: parent.top
188 left: parent.left
189 }
190 height: indicators.minimizedPanelHeight
191 visible: active && indicators.state == "initial"
192 }
193 }
195 QtObject {
196 id: d
197 objectName: "panelPriv"
198 readonly property real indicatorHeight: indicators.minimizedPanelHeight
199 }
201 states: [
202 State {
203 name: "onscreen" //fully opaque and visible at top edge of screen
204 when: !fullscreenMode
205 PropertyChanges {
206 target: indicatorArea;
207 anchors.topMargin: 0
208 opacity: 1;
209 }
210 },
211 State {
212 name: "offscreen" //pushed off screen
213 when: fullscreenMode
214 PropertyChanges {
215 target: indicatorArea;
216 anchors.topMargin: indicators.state === "initial" ? -d.indicatorHeight : 0
217 opacity: indicators.fullyClosed ? 0.0 : 1.0
218 }
219 PropertyChanges {
220 target: indicators.showDragHandle;
221 anchors.bottomMargin: -units.gu(1)
222 }
223 }
224 ]
226 transitions: [
227 Transition {
228 to: "onscreen"
229 UbuntuNumberAnimation { target: indicatorArea; properties: "anchors.topMargin,opacity" }
230 },
231 Transition {
232 to: "offscreen"
233 UbuntuNumberAnimation { target: indicatorArea; properties: "anchors.topMargin,opacity" }
234 }
235 ]