| 1 |
/* |
| 2 |
* Copyright 2012-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 1.2 as Toolkit |
| 19 |
import Lomiri.PerformanceMetrics 1.0 |
| 20 |
import QtQuick.Window 2.2 |
| 21 |
|
| 22 |
/*! \internal */ |
| 23 |
// Documentation is in MainView.qdoc |
| 24 |
MainViewBase { |
| 25 |
id: mainView |
| 26 |
|
| 27 |
property alias automaticOrientation: canvas.automaticOrientation |
| 28 |
|
| 29 |
/*! |
| 30 |
\internal |
| 31 |
Use default property to ensure children added do not draw over the header. |
| 32 |
*/ |
| 33 |
default property alias contentsItem: contents.data |
| 34 |
OrientationHelper { |
| 35 |
id: canvas |
| 36 |
|
| 37 |
automaticOrientation: false |
| 38 |
anchorToKeyboard: mainView.anchorToKeyboard |
| 39 |
|
| 40 |
// clip the contents so that it does not overlap the header |
| 41 |
Item { |
| 42 |
id: contentsClipper |
| 43 |
anchors { |
| 44 |
left: parent.left |
| 45 |
right: parent.right |
| 46 |
top: headerItem.bottom |
| 47 |
bottom: parent.bottom |
| 48 |
} |
| 49 |
// only clip when necessary |
| 50 |
// ListView headers may be positioned at the top, independent from |
| 51 |
// flickable.contentY, so do not clip depending on activePage.flickable.contentY. |
| 52 |
clip: headerItem.bottomY > 0 && internal.activePage && internal.activePage.flickable |
| 53 |
|
| 54 |
Item { |
| 55 |
id: contents |
| 56 |
anchors { |
| 57 |
fill: parent |
| 58 |
|
| 59 |
// compensate so that the actual y is always 0 |
| 60 |
topMargin: -parent.y |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
/*! |
| 66 |
The header of the MainView. Can be used to obtain the height of the header |
| 67 |
in \l Page to determine the area for the \l Page to fill. |
| 68 |
*/ |
| 69 |
AppHeader { |
| 70 |
// This objectName is used in the MainView autopilot custom proxy object |
| 71 |
// in order to select the application header. |
| 72 |
objectName: "MainView_Header" |
| 73 |
id: headerItem |
| 74 |
property real bottomY: headerItem.y + headerItem.height |
| 75 |
animate: true |
| 76 |
dividerColor: Qt.darker(mainView.headerColor, 1.1) |
| 77 |
panelColor: Qt.lighter(mainView.headerColor, 1.1) |
| 78 |
|
| 79 |
title: internal.activePage ? internal.activePage.title : "" |
| 80 |
flickable: internal.activePage ? internal.activePage.flickable : null |
| 81 |
pageStack: internal.activePage ? internal.activePage.pageStack : null |
| 82 |
|
| 83 |
contents: internal.activePage ? |
| 84 |
internal.activePage.__customHeaderContents : null |
| 85 |
|
| 86 |
PageHeadConfiguration { |
| 87 |
id: defaultConfig |
| 88 |
// Used when there is no active Page, or a Page 1.0 is used which |
| 89 |
// does not have a PageHeadConfiguration. |
| 90 |
} |
| 91 |
config: internal.activePage && internal.activePage.hasOwnProperty("head") ? |
| 92 |
internal.activePage.head : defaultConfig |
| 93 |
|
| 94 |
// 'window' is defined by QML between startup and showing on the screen. |
| 95 |
// There is no signal for when it becomes available and re-declaring it is not safe. |
| 96 |
property bool windowActive: window !== null |
| 97 |
function updateWindowTitle() { |
| 98 |
if (window) { |
| 99 |
window.title = headerItem.title; |
| 100 |
} |
| 101 |
} |
| 102 |
onWindowActiveChanged: { |
| 103 |
updateWindowTitle(); |
| 104 |
} |
| 105 |
onTitleChanged: { |
| 106 |
updateWindowTitle(); |
| 107 |
} |
| 108 |
|
| 109 |
// Use of the deprecated toolbar is no longer supported in MainView 1.2. |
| 110 |
useDeprecatedToolbar: false |
| 111 |
} |
| 112 |
|
| 113 |
Connections { |
| 114 |
target: Qt.application |
| 115 |
function onActiveChanged() { |
| 116 |
if (Qt.application.active) { |
| 117 |
headerItem.animate = false; |
| 118 |
headerItem.show(); |
| 119 |
headerItem.animate = true; |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
Item { |
| 126 |
id: internal |
| 127 |
|
| 128 |
// Even when using MainView 1.1, we still support Page 1.0. |
| 129 |
// PageBase (=Page 1.0) is the superclass of Page 1.1. |
| 130 |
property PageTreeNode activePage: isPage(mainView.activeLeafNode) ? mainView.activeLeafNode : null |
| 131 |
|
| 132 |
function isPage(item) { |
| 133 |
return item && item.hasOwnProperty("__isPageTreeNode") && item.__isPageTreeNode && |
| 134 |
item.hasOwnProperty("title") && item.hasOwnProperty("tools"); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
__propagated: QtObject { |
| 139 |
/*! |
| 140 |
\internal |
| 141 |
The header that will be propagated to the children in the page tree node. |
| 142 |
It is used by Tabs to bind header's tabsModel. |
| 143 |
*/ |
| 144 |
property AppHeader header: headerItem |
| 145 |
|
| 146 |
/*! |
| 147 |
\internal |
| 148 |
The action manager that has the global context for the MainView's actions, |
| 149 |
and to which a local context can be added for each Page that has actions.actions. |
| 150 |
*/ |
| 151 |
property var actionManager: mainView.actionManager |
| 152 |
|
| 153 |
/*! |
| 154 |
\internal |
| 155 |
Used by PageStack. This property only exists in MainView 1.2 and later. |
| 156 |
*/ |
| 157 |
readonly property bool animateHeader: false |
| 158 |
|
| 159 |
// FIXME: Currently disabled to prevent bug 1461729 |
| 160 |
// readonly property bool animateHeader: headerItem.__styleInstance && |
| 161 |
// headerItem.__styleInstance.hasOwnProperty("animateIn") && |
| 162 |
// headerItem.__styleInstance.hasOwnProperty("animateOut") && |
| 163 |
// headerItem.__styleInstance.hasOwnProperty("animateInFinished") && |
| 164 |
// headerItem.__styleInstance.hasOwnProperty("animateOutFinished") |
| 165 |
} |
| 166 |
} |