| 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 |
|
| 20 |
/*! |
| 21 |
\internal |
| 22 |
Documentation is in Page.qdoc |
| 23 |
*/ |
| 24 |
PageTreeNode { |
| 25 |
id: page |
| 26 |
anchors { |
| 27 |
left: parent ? parent.left : undefined |
| 28 |
bottom: parent ? parent.bottom : undefined |
| 29 |
} |
| 30 |
// Set width and height so that a parent Loader can be automatically resized |
| 31 |
// to the size of the loaded Page. |
| 32 |
width: parentNode ? parentNode.width - page.x : undefined |
| 33 |
height: parentNode ? page.flickable ? parentNode.height : parentNode.height - internal.headerHeight : undefined |
| 34 |
|
| 35 |
isLeaf: true |
| 36 |
|
| 37 |
property string title: parentNode && parentNode.hasOwnProperty("title") ? parentNode.title : "" |
| 38 |
|
| 39 |
// deprecated |
| 40 |
property Item tools: toolsLoader.item |
| 41 |
|
| 42 |
Loader { |
| 43 |
id: toolsLoader |
| 44 |
source: internal.header && internal.header.useDeprecatedToolbar ? "ToolbarItems.qml" : "" |
| 45 |
asynchronous: true |
| 46 |
} |
| 47 |
|
| 48 |
/*! |
| 49 |
\internal |
| 50 |
\deprecated |
| 51 |
Set this property to replace the title label in the header by any Item. |
| 52 |
It will be automatically anchored to fill the title space in the header. |
| 53 |
*/ |
| 54 |
property Item __customHeaderContents: null |
| 55 |
|
| 56 |
property Flickable flickable: internal.getFlickableChild(page) |
| 57 |
|
| 58 |
/*! \internal */ |
| 59 |
onActiveChanged: { |
| 60 |
internal.updateActions(); |
| 61 |
} |
| 62 |
|
| 63 |
/*! |
| 64 |
\qmlproperty list<Action> actions |
| 65 |
*/ |
| 66 |
property alias actions: actionContext.actions |
| 67 |
|
| 68 |
Item { |
| 69 |
id: internal |
| 70 |
|
| 71 |
// Toolkit ActionContext registers automatically to ActionManager |
| 72 |
Toolkit.ActionContext { |
| 73 |
id: actionContext |
| 74 |
} |
| 75 |
|
| 76 |
function updateActions() { |
| 77 |
actionContext.active = page.active; |
| 78 |
} |
| 79 |
|
| 80 |
property Item header: page.__propagated && page.__propagated.header ? page.__propagated.header : null |
| 81 |
// Used to position the Page when there is no flickable. |
| 82 |
// When there is a flickable, the header will automatically position it. |
| 83 |
property real headerHeight: internal.header && internal.header.visible ? internal.header.height : 0 |
| 84 |
|
| 85 |
Binding { |
| 86 |
target: tools |
| 87 |
property: "pageStack" |
| 88 |
value: page.pageStack |
| 89 |
when: tools && tools.hasOwnProperty("pageStack") |
| 90 |
} |
| 91 |
Binding { |
| 92 |
target: tools |
| 93 |
property: "visible" |
| 94 |
value: false |
| 95 |
when: internal.header && !internal.header.useDeprecatedToolbar && |
| 96 |
page.tools !== null |
| 97 |
} |
| 98 |
|
| 99 |
function isVerticalFlickable(object) { |
| 100 |
if (object && object.hasOwnProperty("flickableDirection") && object.hasOwnProperty("contentHeight")) { |
| 101 |
var direction = object.flickableDirection; |
| 102 |
if ( ((direction === Flickable.AutoFlickDirection) && (object.contentHeight !== object.height) ) |
| 103 |
|| direction === Flickable.VerticalFlick |
| 104 |
|| direction === Flickable.HorizontalAndVerticalFlick) { |
| 105 |
return true; |
| 106 |
} |
| 107 |
} |
| 108 |
return false; |
| 109 |
} |
| 110 |
|
| 111 |
/*! |
| 112 |
Return the first flickable child of this page. |
| 113 |
*/ |
| 114 |
function getFlickableChild(item) { |
| 115 |
if (item && item.hasOwnProperty("children")) { |
| 116 |
for (var i=0; i < item.children.length; i++) { |
| 117 |
var child = item.children[i]; |
| 118 |
if (internal.isVerticalFlickable(child)) { |
| 119 |
if (child.anchors.top === page.top || child.anchors.fill === page) { |
| 120 |
return item.children[i]; |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
return null; |
| 126 |
} |
| 127 |
} |
| 128 |
} |