| 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 |
|
| 17 |
import QtQuick 2.4 |
| 18 |
import Lomiri.Components.Private as Privates |
| 19 |
|
| 20 |
/*! |
| 21 |
\internal |
| 22 |
\qmltype AppHeader |
| 23 |
\inqmlmodule Lomiri.Components |
| 24 |
\ingroup lomiri |
| 25 |
*/ |
| 26 |
Privates.AppHeaderBase { |
| 27 |
// Note: styleName is set to "PageHeadStyle" in UCAppHeaderBase. |
| 28 |
id: header |
| 29 |
|
| 30 |
anchors { |
| 31 |
left: parent.left |
| 32 |
right: parent.right |
| 33 |
} |
| 34 |
|
| 35 |
/*! |
| 36 |
The background color of the header. Value set by MainView. |
| 37 |
*/ |
| 38 |
property color backgroundColor |
| 39 |
|
| 40 |
/*! |
| 41 |
The background color of the divider. Value set by MainView. |
| 42 |
*/ |
| 43 |
property color dividerColor |
| 44 |
|
| 45 |
/*! |
| 46 |
The background color of the panel. Value set by MainView. |
| 47 |
*/ |
| 48 |
property color panelColor |
| 49 |
|
| 50 |
// prevent triggering buttons in the header when it is moving |
| 51 |
enabled: header.exposed && !header.moving |
| 52 |
|
| 53 |
/*! |
| 54 |
The text to display in the header |
| 55 |
*/ |
| 56 |
property string title: "" |
| 57 |
|
| 58 |
/*! |
| 59 |
The contents of the header. If this is set, \l title will be ignored. |
| 60 |
DEPRECATED and replaced by Page.head.contents. |
| 61 |
*/ |
| 62 |
property Item contents: null |
| 63 |
|
| 64 |
/*! |
| 65 |
A model of tabs to represent in the header. |
| 66 |
This is automatically set by \l Tabs. |
| 67 |
*/ |
| 68 |
property var tabsModel: null |
| 69 |
|
| 70 |
/*! |
| 71 |
If it is possible to pop this PageStack, a back button will be |
| 72 |
shown in the header. |
| 73 |
*/ |
| 74 |
property var pageStack: null |
| 75 |
|
| 76 |
/*! |
| 77 |
\deprecated |
| 78 |
\qmlproperty list<Action> actions |
| 79 |
The list of actions actions that will be shown in the header. |
| 80 |
DEPRECATED. Use Page.head.actions instead. |
| 81 |
*/ |
| 82 |
property var actions |
| 83 |
onActionsChanged: print("WARNING: Header.actions property is DEPRECATED. "+ |
| 84 |
"Use Page.head.actions instead.") |
| 85 |
|
| 86 |
/*! |
| 87 |
\internal |
| 88 |
\deprecated |
| 89 |
Action shown before the title. Setting this will disable the back |
| 90 |
button and tabs drawer button in the new header and replace it with a button |
| 91 |
representing the action below. |
| 92 |
DEPRECATED. Use Page.head.backAction property instead. |
| 93 |
*/ |
| 94 |
property var __customBackAction: null |
| 95 |
|
| 96 |
// FIXME: Currently autopilot can only get visual items, but once bug #1273956 |
| 97 |
// is fixed to support non-visual items, a QtObject may be used. |
| 98 |
// --timp - 2014-03-20 |
| 99 |
Item { |
| 100 |
// FIXME: This is a workaround to be able to get the properties of |
| 101 |
// tabsModel in an autopilot test. |
| 102 |
objectName: "tabsModelProperties" |
| 103 |
property int count: tabsModel ? tabsModel.count : 0 |
| 104 |
property int selectedIndex: tabsModel ? tabsModel.selectedIndex : -1 |
| 105 |
} |
| 106 |
Item { |
| 107 |
// FIXME: This is a workaround to be able to get the properties of |
| 108 |
// the sections in an autopilot test. |
| 109 |
objectName: "sectionsProperties" |
| 110 |
property int selectedIndex: header.config ? header.config.sections.selectedIndex : -1 |
| 111 |
} |
| 112 |
|
| 113 |
/*! |
| 114 |
Configuration of the header. |
| 115 |
FIXME: Must be of type PageHeadConfiguration. Setting that as the property type |
| 116 |
however will use the latest version (1.3) and a Page that uses an older |
| 117 |
version (1.1) will no longer work. |
| 118 |
*/ |
| 119 |
property QtObject config: null |
| 120 |
|
| 121 |
animate: false |
| 122 |
exposed: false |
| 123 |
Component.onCompleted: { |
| 124 |
internal.updateProperties(); |
| 125 |
header.animate = true; |
| 126 |
} |
| 127 |
onConfigChanged: internal.updateProperties() |
| 128 |
|
| 129 |
onExposedChanged: { |
| 130 |
if(header.config) { |
| 131 |
header.config.visible = exposed; |
| 132 |
} |
| 133 |
} |
| 134 |
Connections { |
| 135 |
target: header.config |
| 136 |
ignoreUnknownSignals: true |
| 137 |
function onVisibleChanged() { |
| 138 |
header.exposed = header.config.visible; |
| 139 |
} |
| 140 |
function onLockedChanged() { |
| 141 |
if (header.config.locked) { |
| 142 |
header.flickable = null; |
| 143 |
} else { |
| 144 |
header.flickable = header.config.flickable; |
| 145 |
} |
| 146 |
} |
| 147 |
function onFlickableChanged() { |
| 148 |
if (!header.config.locked) { |
| 149 |
header.flickable = header.config.flickable; |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
QtObject { |
| 155 |
id: internal |
| 156 |
function updateProperties() { |
| 157 |
if (header.config.locked) { |
| 158 |
header.flickable = null; |
| 159 |
} else { |
| 160 |
header.flickable = header.config.flickable; |
| 161 |
} |
| 162 |
|
| 163 |
if (!header.flickable && !header.config.visible) { |
| 164 |
// locked. |
| 165 |
header.exposed = false; |
| 166 |
} else { |
| 167 |
header.config.visible = true; |
| 168 |
header.exposed = true; |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
} |