| 1 |
/* |
| 2 |
* Copyright 2012 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 "PageWrapperUtils.js" as Utils |
| 19 |
|
| 20 |
/*! |
| 21 |
\internal |
| 22 |
\qmltype PageWrapper |
| 23 |
\inqmlmodule Lomiri.Components |
| 24 |
\ingroup lomiri |
| 25 |
\brief Internal class used by \l PageStack |
| 26 |
*/ |
| 27 |
PageTreeNode { |
| 28 |
id: pageWrapper |
| 29 |
anchors.fill: parent |
| 30 |
|
| 31 |
/*! |
| 32 |
The reference to the page object. This can be the page |
| 33 |
itself (which is an Item), but also a url pointing to a QML file. |
| 34 |
*/ |
| 35 |
property var reference |
| 36 |
|
| 37 |
/*! |
| 38 |
The initialized page object, or null if the object needs to be created. |
| 39 |
*/ |
| 40 |
property Item object: null |
| 41 |
|
| 42 |
/*! |
| 43 |
This variable will be true if \l object holds an object that was created |
| 44 |
from the given reference, and thus can be destroyed when no the page is deactivated. |
| 45 |
*/ |
| 46 |
property bool canDestroy: false |
| 47 |
|
| 48 |
/*! |
| 49 |
This value is updated when a PageWrapper is pushed to/popped from a PageStack. |
| 50 |
*/ |
| 51 |
active: false |
| 52 |
|
| 53 |
/*! |
| 54 |
\internal |
| 55 |
*/ |
| 56 |
onActiveChanged: { |
| 57 |
if (reference) { |
| 58 |
if (pageWrapper.active) Utils.activate(pageWrapper); |
| 59 |
else Utils.deactivate(pageWrapper); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
visible: active |
| 64 |
|
| 65 |
/*! |
| 66 |
Properties are use to initialize a new object, or if reference |
| 67 |
is already an object, properties are copied to the object when activated. |
| 68 |
Set properties before setting the reference. |
| 69 |
*/ |
| 70 |
property var properties |
| 71 |
|
| 72 |
/*! |
| 73 |
\internal |
| 74 |
*/ |
| 75 |
onReferenceChanged: { |
| 76 |
Utils.deactivate(pageWrapper); |
| 77 |
if (pageWrapper.object) pageWrapper.object = null; |
| 78 |
Utils.initPage(pageWrapper); |
| 79 |
if (pageWrapper.active && reference) { |
| 80 |
Utils.activate(pageWrapper); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
/*! |
| 85 |
\internal |
| 86 |
*/ |
| 87 |
Component.onDestruction: { |
| 88 |
Utils.deactivate(pageWrapper); |
| 89 |
if (pageWrapper.canDestroy) Utils.destroyObject(pageWrapper); |
| 90 |
} |
| 91 |
|
| 92 |
/*! |
| 93 |
\internal |
| 94 |
Destroy \l object. Only call this function if \l canDestroy |
| 95 |
*/ |
| 96 |
function destroyObject() { |
| 97 |
Utils.destroyObject(pageWrapper); |
| 98 |
} |
| 99 |
} |