on 331bab5 help sign in
90 lines 3.0 kB history raw
1/*
2 * Copyright 2013 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 * Authors:
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 */
20import QtQuick 2.0
22Item {
23 id: __menuFactory
25 property QtObject menu
26 property QtObject listView
27 property QtObject actionGroup
28 property variant widgetsMap
29 property bool isCurrentItem
30 readonly property bool empty: (__loader.source !== "" && __loader.status == Loader.Ready) ? __loader.item.state === "EMPTY" : true
32 signal selectItem(int targetIndex)
34 implicitHeight: (__loader.status === Loader.Ready) ? __loader.item.implicitHeight : 0
35 Loader {
36 id: __loader
37 anchors.fill: parent
38 asynchronous: true
39 source: {
40 if (!__menuFactory.menu || !__menuFactory.menu.extra || !__menuFactory.widgetsMap) {
41 return ''
42 }
44 var widgetType = __menuFactory.menu.extra.canonical_type
45 var sourceFile = null
46 if (widgetType) {
47 sourceFile = __menuFactory.widgetsMap.find(widgetType)
48 }
49 if (!sourceFile) {
50 if (widgetType === "com.canonical.indicator.root") {
51 sourceFile == ""
52 // Try discovery the item based on the basic properties
53 } else if (menu.hasSection) {
54 sourceFile = "SectionMenu.qml"
55 } else {
56 sourceFile = "Menu.qml"
57 }
58 }
59 return sourceFile
60 }
61 onStatusChanged: {
62 if (status == Loader.Ready) {
63 item.listViewIsCurrentItem = __menuFactory.isCurrentItem
64 }
65 }
67 // Binding all properties for the item, to make sure that any change in the
68 // property will be propagated to the __loader.item at any time
69 Binding {
70 target: __loader.item
71 property: "listViewIsCurrentItem"
72 value: isCurrentItem
73 when: (__loader.status == Loader.Ready)
74 }
76 Binding {
77 target: __loader.item
78 property: "actionGroup"
79 value: __menuFactory.actionGroup
80 when: (__loader.status == Loader.Ready)
81 }
83 Binding {
84 target: __loader.item
85 property: "menu"
86 value: __menuFactory.menu
87 when: (__loader.status == Loader.Ready)
88 }
89 }