~ubuntu-sdk-team/ubuntu-ui-toolkit/trunk

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/1.3/PageTreeNode.qml

  • Committer: CI Train Bot
  • Author(s): Christian Dywan, Zsombor Egri, Zoltán Balogh, Tim Peeters, Albert Astals Cid, Michael Sheldon, Benjamin Zeller
  • Date: 2015-12-17 17:13:49 UTC
  • mfrom: (1000.739.27 OTA9-landing-2015-12-16)
  • Revision ID: ci-train-bot@canonical.com-20151217171349-8xwclnhnx8v9oz4m
OTA9-landing-2015-12-16
Approved by: Zoltan Balogh

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 Ubuntu.Components 1.3 as Toolkit
19
 
 
20
 
/*!
21
 
    \internal
22
 
    \qmltype PageTreeNode
23
 
    \inqmlmodule Ubuntu.Components 1.1
24
 
    \ingroup ubuntu
25
 
    \brief The common parent of \l Page, \l MainView, \l PageStack and \l Tabs.
26
 
 
27
 
    It is used to propagate properties such as \l header and \l toolbar from a
28
 
    \l MainView (the root node) to each \l Page (leaf node) in the tree.
29
 
*/
30
 
Toolkit.StyledItem {
31
 
    id: node
32
 
 
33
 
    /*!
34
 
      \internal
35
 
      Used to determine whether an Item is a PageTreeNode
36
 
     */
37
 
    property bool __isPageTreeNode: true
38
 
 
39
 
    /*! \internal */
40
 
    onParentChanged: internal.updatePageTree()
41
 
    /*! \internal */
42
 
    Component.onCompleted: internal.updatePageTree()
43
 
 
44
 
    /*!
45
 
      \deprecated
46
 
      The toolbar of the node. Propagates down from the root node.
47
 
      This property is DEPRECATED.
48
 
     */
49
 
    property Item toolbar: node.__propagated && node.__propagated.hasOwnProperty("toolbar")
50
 
                              ? node.__propagated.toolbar : null
51
 
 
52
 
    /*!
53
 
      \internal
54
 
      QtObject containing all the properties that are propagated from the
55
 
      root (MainView) of a page tree to its leafs (Pages).
56
 
      This object contains properties such as the header and toolbar that are
57
 
      instantiated by the MainView.
58
 
 
59
 
      This property is internal because the derived classes (MainView and Page)
60
 
      need to access it, but other components using those classes should not have
61
 
      access to it.
62
 
     */
63
 
    property QtObject __propagated: node.parentNode ? node.parentNode.__propagated : null
64
 
 
65
 
    /*!
66
 
      At any time, there is exactly one path from the root node to a Page leaf node
67
 
      where all nodes are active. All other nodes are not active. This is used by
68
 
      \l Tabs and \l PageStack to determine which of multiple nodes in the Tabs or
69
 
      PageStack is the currently active one.
70
 
     */
71
 
    property bool active: node.parentNode ? node.parentNode.active : false
72
 
 
73
 
    /*!
74
 
      The \l PageStack that this Page has been pushed on, or null if it is not
75
 
      part of a PageStack. This value is automatically set for pages that are pushed
76
 
      on a PageStack, and propagates to its child nodes.
77
 
     */
78
 
    // Note: pageStack is not included in the propagated property because there may
79
 
    //  be multiple PageStacks in a single page tree.
80
 
    property Item pageStack: node.parentNode ? node.parentNode.pageStack : null
81
 
 
82
 
    /*!
83
 
      The parent node of the current node in the page tree.
84
 
     */
85
 
    property Item parentNode: null
86
 
 
87
 
    /*!
88
 
      The leaf node that is active.
89
 
     */
90
 
    property Item activeLeafNode
91
 
 
92
 
    /*!
93
 
      Whether or not this node is a leaf, that is if it has no descendant that are nodes.
94
 
      Pages are leafs, and they don't have descendants in the PageTree.
95
 
     */
96
 
    property bool isLeaf: false
97
 
 
98
 
    // turn on focusing
99
 
    activeFocusOnPress: true
100
 
 
101
 
    Binding {
102
 
        target: node.parentNode
103
 
        property: "activeLeafNode"
104
 
        value: node.isLeaf ? node : node.activeLeafNode
105
 
        when: node.active
106
 
    }
107
 
 
108
 
    Item {
109
 
        id: internal
110
 
 
111
 
        function isPageTreeNode(object) {
112
 
            // FIXME: Use QuickUtils.className() when it becomes available.
113
 
            return (object && object.hasOwnProperty("__isPageTreeNode") && object.__isPageTreeNode);
114
 
        }
115
 
 
116
 
        /*!
117
 
          Return the parent node in the page tree, or null if the item is the root node or invalid.
118
 
         */
119
 
        function getParentPageTreeNode(item) {
120
 
            var node = null;
121
 
            if (item) {
122
 
                var i = item.parent;
123
 
                while (i) {
124
 
                    if (internal.isPageTreeNode(i)) {
125
 
                        if (i.isLeaf) {
126
 
                            // children of a leaf are not part of the tree
127
 
                            node = null;
128
 
                        } else {
129
 
                            // current node is part of the tree with i as its parent.
130
 
                            node = i;
131
 
                        }
132
 
                        break;
133
 
                    }
134
 
                    i = i.parent;
135
 
                }
136
 
            }
137
 
            return node;
138
 
        }
139
 
 
140
 
        /*!
141
 
          Find the parent node.
142
 
         */
143
 
        function updatePageTree() {
144
 
            node.parentNode = internal.getParentPageTreeNode(node);
145
 
        }
146
 
    }
147
 
}