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  Rectangle {
34  id: darkenedArea
35  property real darkenedOpacity: 0.6
36  anchors {
37  fill: parent
38  topMargin: panelHeight
39  }
40  color: "black"
41  opacity: indicators.unitProgress * darkenedOpacity
42  visible: !indicators.fullyClosed
43 
44  MouseArea {
45  anchors.fill: parent
46  onClicked: if (indicators.fullyOpened) indicators.hide();
47  hoverEnabled: true // should also eat hover events, otherwise they will pass through
48  }
49  }
50 
51  Binding {
52  target: PanelState
53  property: "panelHeight"
54  value: indicators.minimizedPanelHeight
55  }
56 
57  Item {
58  id: indicatorArea
59  objectName: "indicatorArea"
60 
61  anchors.fill: parent
62 
63  transform: Translate {
64  y: indicators.state === "initial"
65  ? (1.0 - indicatorAreaShowProgress) * -d.indicatorHeight
66  : 0
67  }
68 
69  BorderImage {
70  id: indicatorsDropShadow
71  anchors {
72  fill: indicators
73  leftMargin: -units.gu(1)
74  bottomMargin: -units.gu(1)
75  }
76  visible: !indicators.fullyClosed
77  source: "graphics/rectangular_dropshadow.sci"
78  }
79 
80  BorderImage {
81  id: panelDropShadow
82  anchors {
83  fill: indicatorAreaBackground
84  bottomMargin: -units.gu(1)
85  }
86  visible: PanelState.dropShadow && !callHint.visible
87  source: "graphics/rectangular_dropshadow.sci"
88  }
89 
90  Rectangle {
91  id: indicatorAreaBackground
92  color: callHint.visible ? UbuntuColors.green : theme.palette.normal.background
93  anchors {
94  top: parent.top
95  left: parent.left
96  right: parent.right
97  }
98  height: indicators.minimizedPanelHeight
99 
100  Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration } }
101  }
102 
103  MouseArea {
104  anchors {
105  top: parent.top
106  left: parent.left
107  right: indicators.left
108  }
109  height: indicators.minimizedPanelHeight
110  hoverEnabled: true
111  onClicked: callHint.visible ? callHint.showLiveCall() : PanelState.focusMaximizedApp()
112  onDoubleClicked: PanelState.maximize()
113 
114  // WindowControlButtons inside the mouse area, otherwise QML doesn't grok nested hover events :/
115  // cf. https://bugreports.qt.io/browse/QTBUG-32909
116  WindowControlButtons {
117  id: windowControlButtons
118  objectName: "panelWindowControlButtons"
119  anchors {
120  left: parent.left
121  top: parent.top
122  leftMargin: units.gu(1)
123  topMargin: units.gu(0.5)
124  bottomMargin: units.gu(0.5)
125  }
126  height: indicators.minimizedPanelHeight - anchors.topMargin - anchors.bottomMargin
127  visible: PanelState.buttonsVisible && parent.containsMouse && !root.locked && !callHint.visible
128  active: PanelState.buttonsVisible
129  onClose: PanelState.close()
130  onMinimize: PanelState.minimize()
131  onMaximize: PanelState.maximize()
132  }
133  }
134 
135  IndicatorsMenu {
136  id: __indicators
137  objectName: "indicators"
138 
139  anchors {
140  top: parent.top
141  right: parent.right
142  }
143 
144  shown: false
145  width: root.width - (windowControlButtons.visible ? windowControlButtons.width + titleLabel.width : 0)
146  minimizedPanelHeight: units.gu(3)
147  expandedPanelHeight: units.gu(7)
148  openedHeight: root.height
149 
150  overFlowWidth: {
151  if (callHint.visible) {
152  return Math.max(root.width - (callHint.width + units.gu(2)), 0)
153  }
154  return root.width
155  }
156  enableHint: !callHint.active && !fullscreenMode
157  showOnClick: !callHint.visible
158  panelColor: indicatorAreaBackground.color
159 
160  onShowTapped: {
161  if (callHint.active) {
162  callHint.showLiveCall();
163  }
164  }
165  }
166 
167  Label {
168  id: titleLabel
169  objectName: "windowDecorationTitle"
170  anchors {
171  left: parent.left
172  right: __indicators.left
173  top: parent.top
174  leftMargin: units.gu(1)
175  rightMargin: units.gu(1)
176  topMargin: units.gu(0.5)
177  bottomMargin: units.gu(0.5)
178  }
179  color: PanelState.buttonsVisible ? "#ffffff" : "#5d5d5d"
180  height: indicators.minimizedPanelHeight - anchors.topMargin - anchors.bottomMargin
181  visible: !windowControlButtons.visible && !root.locked && !callHint.visible
182  verticalAlignment: Text.AlignVCenter
183  fontSize: "medium"
184  font.weight: Font.Normal
185  text: PanelState.title
186  elide: Text.ElideRight
187  maximumLineCount: 1
188  }
189 
190  // TODO here would the Locally integrated menus come
191 
192  ActiveCallHint {
193  id: __callHint
194  anchors {
195  top: parent.top
196  left: parent.left
197  }
198  height: indicators.minimizedPanelHeight
199  visible: active && indicators.state == "initial"
200  }
201  }
202 
203  QtObject {
204  id: d
205  objectName: "panelPriv"
206  readonly property real indicatorHeight: indicators.minimizedPanelHeight
207  }
208 
209  states: [
210  State {
211  name: "onscreen" //fully opaque and visible at top edge of screen
212  when: !fullscreenMode
213  PropertyChanges {
214  target: indicatorArea;
215  anchors.topMargin: 0
216  opacity: 1;
217  }
218  },
219  State {
220  name: "offscreen" //pushed off screen
221  when: fullscreenMode
222  PropertyChanges {
223  target: indicatorArea;
224  anchors.topMargin: indicators.state === "initial" ? -d.indicatorHeight : 0
225  opacity: indicators.fullyClosed ? 0.0 : 1.0
226  }
227  PropertyChanges {
228  target: indicators.showDragHandle;
229  anchors.bottomMargin: -units.gu(1)
230  }
231  }
232  ]
233 
234  transitions: [
235  Transition {
236  to: "onscreen"
237  UbuntuNumberAnimation { target: indicatorArea; properties: "anchors.topMargin,opacity" }
238  },
239  Transition {
240  to: "offscreen"
241  UbuntuNumberAnimation { target: indicatorArea; properties: "anchors.topMargin,opacity" }
242  }
243  ]
244 }