Debian Codegraph @

src/imports/Components/Themes/Ambiance/1.3/PageHeadStyle.qml

raw
1 /*
2 * Copyright 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 Lesser 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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 import QtQuick 2.4
17 import QtQuick.Window 2.0
18 import Lomiri.Components 1.3
19 import Lomiri.Components.Popups 1.3
20 import Lomiri.Components.Styles 1.3 as Style
21
22 Style.PageHeadStyle {
23 id: headerStyle
24 objectName: "PageHeadStyle" // used in unit tests
25 contentHeight: Screen.height > units.gu(50) ? units.gu(6) : units.gu(5)
26 fontWeight: Font.Light
27 textSize: Label.Large
28 textLeftMargin: units.gu(2)
29 maximumNumberOfActions: 3
30
31 PageHeadConfiguration {
32 id: defaultConfig
33 }
34
35 property PageHeadConfiguration config: styledItem.config ?
36 styledItem.config :
37 defaultConfig
38 /*!
39 The color of the buttons in the header.
40 */
41 property color buttonColor: headerStyle.config.foregroundColor
42
43 /*!
44 The color of the title text.
45 */
46 property color titleColor: headerStyle.config.foregroundColor
47
48 /*!
49 The background color of the header.
50 */
51 property color backgroundColor: styledItem.backgroundColor
52 Rectangle {
53 id: background
54 anchors.fill: parent
55 color: headerStyle.backgroundColor
56
57 // The border is shown to warn the developer that the AppHeader
58 // is deprecated. See bug #1583636
59 property bool showBorder: styledItem.hasOwnProperty("showDeprecatedWarning") &&
60 styledItem.showDeprecatedWarning
61 border {
62 width: background.showBorder ? units.gu(0.5) : 0
63 color: background.showBorder ? LomiriColors.red : "transparent"
64 }
65 }
66
67 // FIXME: When the three panel color properties below are removed,
68 // update lomiri/Dash/PageHeader to use the new theming (currently
69 // in progress) to set these colors.
70 /*!
71 \deprecated
72 The background color of the tabs panel and the actions overflow panel.
73 */
74 property color panelBackgroundColor: styledItem.panelColor
75
76 /*!
77 \deprecated
78 The background color of the tapped item in the panel.
79 */
80 property color panelHighlightColor: theme.palette.highlighted.background
81
82 /*!
83 \deprecated
84 The foreground color (icon and text) of actions in the panel.
85 */
86 property color panelForegroundColor: styledItem.enabled
87 ? theme.palette.normal.backgroundText
88 : theme.palette.disabled.backgroundText
89
90 /*!
91 The text color of unselected sections and the section divider.
92 */
93 property color sectionColor: styledItem.enabled
94 ? theme.palette.normal.backgroundText
95 : theme.palette.disabled.backgroundText
96
97 /*!
98 The text color of the selected section.
99 */
100 property color selectedSectionColor: styledItem.enabled
101 ? theme.palette.selected.backgroundText
102 : theme.palette.selectedDisabled.backgroundText
103
104 /*!
105 The background color of the pressed section.
106 */
107 property color sectionHighlightColor: theme.palette.highlighted.background
108
109 implicitHeight: headerStyle.contentHeight + divider.height + sectionsItem.height
110
111 // Used by unit tests and autopilot tests to wait for animations to finish
112 readonly property bool animating: headerStyle.state == "OUT"
113 || leftAnchor.anchors.leftMargin < 0
114
115 // for Lomiri
116 // FIXME: Remove this property when we introduce a header preset that does not
117 // have a separator.
118 property alias __separator_visible: divider.visible
119
120 Rectangle {
121 id: divider
122 anchors {
123 left: parent.left
124 right: parent.right
125 bottom: parent.bottom
126 }
127 height: units.dp(1)
128 color: styledItem.dividerColor
129 }
130
131 SectionsForPageHead {
132 id: sectionsItem
133 objectName: "headerSectionsItem"
134 anchors {
135 left: parent.left
136 leftMargin: units.gu(2)
137 bottom: divider.top
138 }
139 visible: model && model.length > 0
140 enabled: sections.enabled
141 height: visible ? implicitHeight : 0
142
143 property PageHeadSections sections: headerStyle.config.sections
144 model: sections ? sections.model : null
145
146 onSelectedIndexChanged: {
147 if (sections) {
148 sections.selectedIndex = sectionsItem.selectedIndex;
149 }
150 }
151
152 Binding {
153 target: sectionsItem
154 when: sectionsItem.sections
155 property: "selectedIndex"
156 value: sectionsItem.sections.selectedIndex
157 }
158 }
159
160 states: [
161 State {
162 name: "IN"
163 PropertyChanges {
164 target: allContents
165 opacity: 1.0
166 }
167 },
168 State {
169 name: "OUT"
170 PropertyChanges {
171 target: allContents
172 opacity: 0.0
173 }
174 }
175 ]
176
177 function animateOut() {
178 state = "OUT";
179 }
180 function animateIn() {
181 state = "IN";
182 }
183
184 signal animateOutFinished()
185 signal animateInFinished()
186
187 transitions: [
188 Transition {
189 id: transitionOut
190 from: "IN"
191 to: "OUT"
192 SequentialAnimation {
193 ParallelAnimation {
194 LomiriNumberAnimation {
195 target: allContents
196 property: "opacity"
197 from: 1.0
198 to: 0.0
199 }
200 LomiriNumberAnimation {
201 target: leftAnchor
202 properties: "anchors.leftMargin"
203 from: 0.0
204 to: -units.gu(5)
205 }
206 LomiriNumberAnimation {
207 target: rightAnchor
208 properties: "anchors.rightMargin"
209 from: 0
210 to: -units.gu(5)
211 }
212 }
213 ScriptAction {
214 script: headerStyle.animateOutFinished()
215 }
216 }
217 },
218 Transition {
219 id: transitionIn
220 from: "OUT"
221 to: "IN"
222 SequentialAnimation {
223 ParallelAnimation {
224 LomiriNumberAnimation {
225 target: allContents
226 property: "opacity"
227 from: 0.0
228 to: 1.0
229 }
230 LomiriNumberAnimation {
231 target: leftAnchor
232 properties: "anchors.leftMargin"
233 from: -units.gu(5)
234 to: 0
235 }
236 LomiriNumberAnimation {
237 target: rightAnchor
238 properties: "anchors.rightMargin"
239 from: -units.gu(5)
240 to: 0
241 }
242 }
243 ScriptAction {
244 script: headerStyle.animateInFinished()
245 }
246 }
247 }
248 ]
249
250 Item {
251 id: allContents
252 anchors.fill: parent
253
254 Item {
255 id: leftAnchor
256 anchors {
257 top: parent.top
258 bottom: parent.bottom
259 left: parent.left
260 leftMargin: 0
261 }
262 width: 0
263 }
264 Item {
265 id: rightAnchor
266 anchors {
267 top: parent.top
268 bottom: parent.bottom
269 right: parent.right
270 rightMargin: 0
271 }
272 width: 0
273 }
274
275 Item {
276 id: leftButtonContainer
277 anchors {
278 left: leftAnchor.right
279 top: parent.top
280 leftMargin: width > 0 ? units.gu(1) : 0
281 }
282 width: childrenRect.width
283 height: headerStyle.contentHeight
284
285 PageHeadButton {
286 id: customBackButton
287 objectName: "customBackButton"
288 action: headerStyle.config.backAction
289 visible: null !== headerStyle.config.backAction &&
290 headerStyle.config.backAction.visible
291 color: headerStyle.config.foregroundColor
292 }
293
294 PageHeadButton {
295 id: backButton
296 objectName: "backButton"
297
298 iconName: "back"
299 property bool stackBack: styledItem.pageStack !== null &&
300 styledItem.pageStack !== undefined &&
301 styledItem.pageStack.depth > 1
302
303 // MultiColumnView adds the following properties: multiColumn, page, showBackButton.
304 property bool treeBack: styledItem.hasOwnProperty("multiColumn") &&
305 styledItem.showBackButton
306
307 visible: !headerStyle.config.backAction && (stackBack || treeBack)
308
309 text: "back"
310 color: headerStyle.config.foregroundColor
311
312 onTriggered: {
313 if (stackBack) {
314 styledItem.pageStack.pop();
315 } else {
316 // treeBack
317 styledItem.multiColumn.removePages(styledItem.page);
318 }
319 }
320 }
321
322 PageHeadButton {
323 id: tabsButton
324 objectName: "tabsButton"
325
326 iconName: "navigation-menu"
327 visible: styledItem.tabsModel !== null &&
328 styledItem.tabsModel !== undefined &&
329 !backButton.visible &&
330 !customBackButton.visible
331 text: visible ? styledItem.tabsModel.count + " tabs" : ""
332 color: headerStyle.buttonColor
333
334 onTriggered: PopupUtils.open(tabsPopoverComponent, tabsButton)
335
336 Component {
337 id: tabsPopoverComponent
338
339 OverflowPanel {
340 id: tabsPopover
341 objectName: "tabsPopover"
342 actions: actionsFromTabs(styledItem.tabsModel)
343
344 function getActionFromTab(tab) {
345 return tab.__protected.action;
346 }
347
348 function actionsFromTabs(tabsList) {
349 var result = [];
350 var tab;
351 for (var i=0; i < tabsList.count; i++) {
352 tab = tabsList.get(i).tab;
353 result.push(getActionFromTab(tab));
354 }
355 return result;
356 }
357 backgroundColor: headerStyle.panelBackgroundColor
358 foregroundColor: headerStyle.panelForegroundColor
359 highlightColor: headerStyle.panelHighlightColor
360 }
361 }
362 }
363 }
364
365 Item {
366 id: foreground
367 anchors {
368 left: leftButtonContainer.right
369 top: parent.top
370 // don't keep a margin if there is already a button with spacing
371 leftMargin: leftButtonContainer.width > 0 ? 0 : headerStyle.textLeftMargin
372 }
373 width: parent.width - anchors.leftMargin
374 - leftButtonContainer.anchors.leftMargin - leftButtonContainer.width
375 - actionsContainer.anchors.rightMargin - actionsContainer.width
376 height: headerStyle.contentHeight
377
378 Label {
379 objectName: "header_title_label"
380 LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
381 visible: !contentsContainer.visible && headerStyle.config.preset === ""
382 anchors {
383 left: parent.left
384 right: parent.right
385 verticalCenter: parent.verticalCenter
386 }
387 text: headerStyle.config.title
388 font.weight: headerStyle.fontWeight
389 textSize: headerStyle.textSize
390 color: headerStyle.titleColor
391 elide: Text.ElideRight
392 }
393
394 Item {
395 // This Item is used to make the custom header item invisible
396 // when styledItem.contents is unset and its parent is not updated
397 // when the bindings below is no longer active
398 id: contentsContainer
399 anchors.fill: parent
400 visible: styledItem.contents || headerStyle.config.contents
401 }
402 Binding {
403 target: styledItem.contents
404 property: "anchors.fill"
405 value: contentsContainer
406 when: styledItem.contents
407 }
408 Binding {
409 target: styledItem.contents
410 property: "parent"
411 value: contentsContainer
412 when: styledItem.contents
413 }
414 Binding {
415 target: headerStyle.config.contents
416 property: "parent"
417 value: contentsContainer
418 when: headerStyle.config.contents && !styledItem.contents
419 }
420 }
421
422 ActionBar {
423 id: actionsContainer
424 objectName: "headerActionBar"
425 anchors {
426 top: parent.top
427 right: rightAnchor.left
428 rightMargin: actionsContainer.width > 0 ? units.gu(1) : 0
429 }
430 height: headerStyle.contentHeight
431
432 actions: headerStyle.config.actions
433 numberOfSlots: 3
434
435 delegate: AbstractButton {
436 style: IconButtonStyle { }
437 objectName: action.objectName + "_button"
438 height: parent ? parent.height : undefined
439 action: modelData
440 activeFocusOnTab: true
441 StyleHints {
442 foregroundColor: headerStyle.buttonColor
443 }
444 }
445 }
446 }
447 }