Unity 8
Panel.qml
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  */
16 
17 import QtQuick 2.4
18 import Ubuntu.Components 1.3
19 import Unity.Application 0.1
20 import "../Components"
21 import "../Components/PanelState"
22 import ".."
23 
24 Item {
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
32 
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  }
41 
42  Binding {
43  target: PanelState
44  property: "panelHeight"
45  value: indicators.minimizedPanelHeight
46  }
47 
48  Item {
49  id: indicatorArea
50  objectName: "indicatorArea"
51 
52  anchors.fill: parent
53 
54  transform: Translate {
55  y: indicators.state === "initial"
56  ? (1.0 - indicatorAreaShowProgress) * -d.indicatorHeight
57  : 0
58  }
59 
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  }
70 
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  }
80 
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
90 
91  Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration } }
92  }
93 
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: if (callHint.visible) { callHint.showLiveCall(); }
104 
105  onPressed: {
106  if (!callHint.visible) {
107  // let it fall through to the window decoration of the maximized window behind, if any
108  mouse.accepted = false;
109  }
110  }
111 
112  // WindowControlButtons inside the mouse area, otherwise QML doesn't grok nested hover events :/
113  // cf. https://bugreports.qt.io/browse/QTBUG-32909
114  WindowControlButtons {
115  id: windowControlButtons
116  objectName: "panelWindowControlButtons"
117  anchors {
118  left: parent.left
119  top: parent.top
120  }
121  height: indicators.minimizedPanelHeight
122 
123  visible: ((PanelState.buttonsVisible && parent.containsMouse) || PanelState.buttonsAlwaysVisible)
124  && !root.locked && !callHint.visible
125  active: PanelState.buttonsVisible || PanelState.buttonsAlwaysVisible
126  windowIsMaximized: true
127  onCloseClicked: PanelState.closeClicked()
128  onMinimizeClicked: PanelState.minimizeClicked()
129  onMaximizeClicked: PanelState.restoreClicked()
130  closeButtonShown: PanelState.closeButtonShown
131  }
132  }
133 
134  IndicatorsMenu {
135  id: __indicators
136  objectName: "indicators"
137 
138  anchors {
139  top: parent.top
140  right: parent.right
141  }
142 
143  shown: false
144  width: root.width - (windowControlButtons.visible ? windowControlButtons.width + titleLabel.width : 0)
145  minimizedPanelHeight: units.gu(3)
146  expandedPanelHeight: units.gu(7)
147  openedHeight: root.height
148 
149  overFlowWidth: {
150  if (callHint.visible) {
151  return Math.max(root.width - (callHint.width + units.gu(2)), 0)
152  }
153  return root.width
154  }
155  enableHint: !callHint.active && !fullscreenMode
156  showOnClick: !callHint.visible
157  panelColor: indicatorAreaBackground.color
158 
159  onShowTapped: {
160  if (callHint.active) {
161  callHint.showLiveCall();
162  }
163  }
164  }
165 
166  Label {
167  id: titleLabel
168  objectName: "windowDecorationTitle"
169  anchors {
170  left: parent.left
171  right: __indicators.left
172  top: parent.top
173  leftMargin: units.gu(1)
174  rightMargin: units.gu(1)
175  topMargin: units.gu(0.5)
176  bottomMargin: units.gu(0.5)
177  }
178  color: "white"
179  height: indicators.minimizedPanelHeight - anchors.topMargin - anchors.bottomMargin
180  opacity: !windowControlButtons.visible && !root.locked && !callHint.visible ? 1 : 0
181  visible: opacity != 0
182  verticalAlignment: Text.AlignVCenter
183  fontSize: "medium"
184  font.weight: PanelState.buttonsVisible ? Font.Light : Font.Medium
185  text: PanelState.title
186  elide: Text.ElideRight
187  maximumLineCount: 1
188  Behavior on opacity { UbuntuNumberAnimation {} }
189  }
190 
191  // TODO here would the Locally integrated menus come
192 
193  ActiveCallHint {
194  id: __callHint
195  anchors {
196  top: parent.top
197  left: parent.left
198  }
199  height: indicators.minimizedPanelHeight
200  visible: active && indicators.state == "initial"
201  }
202  }
203 
204  QtObject {
205  id: d
206  objectName: "panelPriv"
207  readonly property real indicatorHeight: indicators.minimizedPanelHeight
208  }
209 
210  states: [
211  State {
212  name: "onscreen" //fully opaque and visible at top edge of screen
213  when: !fullscreenMode
214  PropertyChanges {
215  target: indicatorArea;
216  anchors.topMargin: 0
217  opacity: 1;
218  }
219  },
220  State {
221  name: "offscreen" //pushed off screen
222  when: fullscreenMode
223  PropertyChanges {
224  target: indicatorArea;
225  anchors.topMargin: indicators.state === "initial" ? -d.indicatorHeight : 0
226  opacity: indicators.fullyClosed ? 0.0 : 1.0
227  }
228  PropertyChanges {
229  target: indicators.showDragHandle;
230  anchors.bottomMargin: -units.gu(1)
231  }
232  }
233  ]
234 
235  transitions: [
236  Transition {
237  to: "onscreen"
238  UbuntuNumberAnimation { target: indicatorArea; properties: "anchors.topMargin,opacity" }
239  },
240  Transition {
241  to: "offscreen"
242  UbuntuNumberAnimation { target: indicatorArea; properties: "anchors.topMargin,opacity" }
243  }
244  ]
245 }