2 * Copyright 2013-2014 Canonical Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3 as Components
19 import Unity.Indicators 0.1 as Indicators
20 import "../Components"
27 property string title: rootActionState.title || rootActionState.accessibleName // some indicators don't expose a title but only the accessible-desc
28 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
29 readonly property alias factory: _factory
31 Indicators.UnityMenuModelStack {
35 property var rootMenu: null
40 } else if (rootMenu != tail) {
41 if (tail.get(0, "type") === rootMenuType) {
42 rootMenu = menuStack.tail.submenu(0);
52 target: menuStack.tail
54 // fix async creation with signal from model before it's finished.
55 Component.onCompleted: update();
56 onRowsInserted: update();
57 onModelReset: update();
60 if (menuStack.rootMenu !== menuStack.tail && menuStack.tail.get(0, "type") === rootMenuType) {
61 menuStack.rootMenu = menuStack.tail.submenu(0);
62 menuStack.push(menuStack.rootMenu, 0);
69 objectName: "mainMenu"
70 model: menuStack.rootMenu
74 bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
76 Behavior on bottomMargin {
79 easing.type: Easing.OutQuad
82 // TODO - does ever frame.
83 onBottomMarginChanged: {
84 mainMenu.positionViewAtIndex(mainMenu.currentIndex, ListView.End)
88 // Don't load all the delegates (only max of 3 pages worth -1/0/+1)
89 cacheBuffer: Math.max(height * 3, units.gu(70))
91 // Only allow flicking if the content doesn't fit on the page
92 interactive: contentHeight > height
94 property int selectedIndex: -1
95 property bool blockCurrentIndexChange: false
98 if (count == 0 && selectedIndex != -1) {
102 // for highlight following
103 onSelectedIndexChanged: {
104 if (currentIndex != selectedIndex) {
105 var blocked = blockCurrentIndexChange;
106 blockCurrentIndexChange = true;
108 currentIndex = selectedIndex;
110 blockCurrentIndexChange = blocked;
113 // for item addition/removal
114 onCurrentIndexChanged: {
115 if (!blockCurrentIndexChange) {
116 if (selectedIndex != -1 && selectedIndex != currentIndex) {
117 selectedIndex = currentIndex;
123 target: mainMenu.model ? mainMenu.model : null
124 onRowsAboutToBeRemoved: {
125 // track current item deletion.
126 if (mainMenu.selectedIndex >= first && mainMenu.selectedIndex <= last) {
127 mainMenu.selectedIndex = -1;
134 objectName: "menuItem" + index
135 width: ListView.view.width
136 visible: status == Loader.Ready
138 property int modelIndex: index
139 sourceComponent: factory.load(model, main.identifier)
142 if (item.hasOwnProperty("selected")) {
143 item.selected = mainMenu.selectedIndex == index;
145 if (item.hasOwnProperty("menuSelected")) {
146 item.menuSelected.connect(function() { mainMenu.selectedIndex = index; });
148 if (item.hasOwnProperty("menuDeselected")) {
149 item.menuDeselected.connect(function() { mainMenu.selectedIndex = -1; });
151 if (item.hasOwnProperty("menuData")) {
152 item.menuData = Qt.binding(function() { return model; });
154 if (item.hasOwnProperty("menuIndex")) {
155 item.menuIndex = Qt.binding(function() { return modelIndex; });
160 target: item ? item : null
161 property: "objectName"
165 // TODO: Fixes lp#1243146
166 // This is a workaround for a Qt bug. https://bugreports.qt-project.org/browse/QTBUG-34351
169 onSelectedIndexChanged: {
170 if (loader.item && loader.item.hasOwnProperty("selected")) {
171 loader.item.selected = mainMenu.selectedIndex == index;
180 rootModel: main.menuModel ? main.menuModel : null
181 menuModel: mainMenu.model ? mainMenu.model : null
186 mainMenu.positionViewAtBeginning();