2 * Copyright 2013 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/>.
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 * Nick Dedekind <nick.dedekind@canonical.com>
22 import Ubuntu.Components 0.1 as Components
23 import Unity.Indicators 0.1 as Indicators
29 property string title: rootActionState.title
30 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
32 Indicators.UnityMenuModelStack {
36 property var rootMenu: null
41 } else if (rootMenu != tail) {
42 if (tail.get(0, "type") === rootMenuType) {
43 rootMenu = menuStack.tail.submenu(0);
53 target: menuStack.tail
55 if (menuStack.rootMenu !== menuStack.tail && menuStack.tail.get(0, "type") === rootMenuType) {
56 menuStack.rootMenu = menuStack.tail.submenu(0);
57 menuStack.push(menuStack.rootMenu, 0);
61 if (menuStack.rootMenu !== menuStack.tail && menuStack.tail.get(0, "type") === rootMenuType) {
62 menuStack.rootMenu = menuStack.tail.submenu(0);
63 menuStack.push(menuStack.rootMenu, 0);
70 objectName: "mainMenu"
71 model: menuStack.rootMenu
75 bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
77 Behavior on bottomMargin {
80 easing.type: Easing.OutQuad
83 // TODO - does ever frame.
84 onBottomMarginChanged: {
85 mainMenu.positionViewAtIndex(mainMenu.currentIndex, ListView.End)
89 // Don't load all the delegates (only max of 3 pages worth -1/0/+1)
90 cacheBuffer: Math.max(height * 3, units.gu(70))
92 // Only allow flicking if the content doesn't fit on the page
93 interactive: contentHeight > height
94 // FIXME - https://bugreports.qt-project.org/browse/QTBUG-41207
95 boundsBehavior: Flickable.StopAtBounds
97 property int selectedIndex: -1
98 property bool blockCurrentIndexChange: false
101 if (count == 0 && selectedIndex != -1) {
105 // for highlight following
106 onSelectedIndexChanged: {
107 if (currentIndex != selectedIndex) {
108 var blocked = blockCurrentIndexChange;
109 blockCurrentIndexChange = true;
111 currentIndex = selectedIndex;
113 blockCurrentIndexChange = blocked;
116 // for item addition/removal
117 onCurrentIndexChanged: {
118 if (!blockCurrentIndexChange) {
119 if (selectedIndex != -1 && selectedIndex != currentIndex) {
120 selectedIndex = currentIndex;
127 objectName: "menuItem" + index
129 width: ListView.view.width
130 visible: status == Loader.Ready
132 property int modelIndex: index
133 sourceComponent: factory.load(model, main.identifier)
136 if (item.hasOwnProperty("selected")) {
137 item.selected = mainMenu.selectedIndex == index;
139 if (item.hasOwnProperty("menuSelected")) {
140 item.menuSelected.connect(function() { mainMenu.selectedIndex = index; });
142 if (item.hasOwnProperty("menuDeselected")) {
143 item.menuDeselected.connect(function() { mainMenu.selectedIndex = -1; });
145 if (item.hasOwnProperty("menuData")) {
146 item.menuData = Qt.binding(function() { return model; });
148 if (item.hasOwnProperty("menuIndex")) {
149 item.menuIndex = Qt.binding(function() { return modelIndex; });
154 target: item ? item : null
155 property: "objectName"
159 // TODO: Fixes lp#1243146
160 // This is a workaround for a Qt bug. https://bugreports.qt-project.org/browse/QTBUG-34351
163 onSelectedIndexChanged: {
164 if (loader.item && loader.item.hasOwnProperty("selected")) {
165 loader.item.selected = mainMenu.selectedIndex == index;
174 rootModel: main.menuModel ? main.menuModel : null
175 menuModel: mainMenu.model ? mainMenu.model : null
180 mainMenu.positionViewAtBeginning();