Unity 8
Panel.qml
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  */
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: callHint.visible ? callHint.showLiveCall() : PanelState.focusMaximizedApp()
104  onDoubleClicked: PanelState.restoreClicked()
105 
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  }
114 
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  leftMargin: units.gu(1)
124  topMargin: units.gu(0.5)
125  bottomMargin: units.gu(0.5)
126  }
127  height: indicators.minimizedPanelHeight - anchors.topMargin - anchors.bottomMargin
128 
129  visible: ((PanelState.buttonsVisible && parent.containsMouse) || PanelState.buttonsAlwaysVisible)
130  && !root.locked && !callHint.visible
131  active: PanelState.buttonsVisible || PanelState.buttonsAlwaysVisible
132  windowIsMaximized: true
133  onCloseClicked: PanelState.closeClicked()
134  onMinimizeClicked: PanelState.minimizeClicked()
135  onMaximizeClicked: PanelState.restoreClicked()
136  closeButtonShown: PanelState.closeButtonShown
137  }
138  }
139 
140  IndicatorsMenu {
141  id: __indicators
142  objectName: "indicators"
143 
144  anchors {
145  top: parent.top
146  right: parent.right
147  }
148 
149  shown: false
150  width: root.width - (windowControlButtons.visible ? windowControlButtons.width + titleLabel.width : 0)
151  minimizedPanelHeight: units.gu(3)
152  expandedPanelHeight: units.gu(7)
153  openedHeight: root.height
154 
155  overFlowWidth: {
156  if (callHint.visible) {
157  return Math.max(root.width - (callHint.width + units.gu(2)), 0)
158  }
159  return root.width
160  }
161  enableHint: !callHint.active && !fullscreenMode
162  showOnClick: !callHint.visible
163  panelColor: indicatorAreaBackground.color
164 
165  onShowTapped: {
166  if (callHint.active) {
167  callHint.showLiveCall();
168  }
169  }
170  }
171 
172  Label {
173  id: titleLabel
174  objectName: "windowDecorationTitle"
175  anchors {
176  left: parent.left
177  right: __indicators.left
178  top: parent.top
179  leftMargin: units.gu(1)
180  rightMargin: units.gu(1)
181  topMargin: units.gu(0.5)
182  bottomMargin: units.gu(0.5)
183  }
184  color: "white"
185  height: indicators.minimizedPanelHeight - anchors.topMargin - anchors.bottomMargin
186  visible: !windowControlButtons.visible && !root.locked && !callHint.visible
187  verticalAlignment: Text.AlignVCenter
188  fontSize: "medium"
189  font.weight: PanelState.buttonsVisible ? Font.Light : Font.Medium
190  text: PanelState.title
191  elide: Text.ElideRight
192  maximumLineCount: 1
193  }
194 
195  // TODO here would the Locally integrated menus come
196 
197  ActiveCallHint {
198  id: __callHint
199  anchors {
200  top: parent.top
201  left: parent.left
202  }
203  height: indicators.minimizedPanelHeight
204  visible: active && indicators.state == "initial"
205  }
206  }
207 
208  QtObject {
209  id: d
210  objectName: "panelPriv"
211  readonly property real indicatorHeight: indicators.minimizedPanelHeight
212  }
213 
214  states: [
215  State {
216  name: "onscreen" //fully opaque and visible at top edge of screen
217  when: !fullscreenMode
218  PropertyChanges {
219  target: indicatorArea;
220  anchors.topMargin: 0
221  opacity: 1;
222  }
223  },
224  State {
225  name: "offscreen" //pushed off screen
226  when: fullscreenMode
227  PropertyChanges {
228  target: indicatorArea;
229  anchors.topMargin: indicators.state === "initial" ? -d.indicatorHeight : 0
230  opacity: indicators.fullyClosed ? 0.0 : 1.0
231  }
232  PropertyChanges {
233  target: indicators.showDragHandle;
234  anchors.bottomMargin: -units.gu(1)
235  }
236  }
237  ]
238 
239  transitions: [
240  Transition {
241  to: "onscreen"
242  UbuntuNumberAnimation { target: indicatorArea; properties: "anchors.topMargin,opacity" }
243  },
244  Transition {
245  to: "offscreen"
246  UbuntuNumberAnimation { target: indicatorArea; properties: "anchors.topMargin,opacity" }
247  }
248  ]
249 }