14
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Renato Araujo Oliveira Filho <renato@canonical.com>
18
17
* Nick Dedekind <nick.dedekind@canonical.com>
22
import Ubuntu.Components 0.1 as Components
23
21
import Unity.Indicators 0.1 as Indicators
25
Indicators.IndicatorBase {
29
property bool contentActive: false
30
property string title: rootActionState.title
31
property alias emptyText: emptyLabel.text
32
property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
34
Indicators.UnityMenuModelStack {
36
head: contentActive ? main.menuModel : null
38
property var rootMenu: null
43
} else if (rootMenu != tail) {
44
if (tail.get(0, "type") === rootMenuType) {
45
rootMenu = menuStack.tail.submenu(0);
55
target: menuStack.tail
57
if (menuStack.rootMenu !== menuStack.tail && menuStack.tail.get(0, "type") === rootMenuType) {
58
menuStack.rootMenu = menuStack.tail.submenu(0);
59
menuStack.push(menuStack.rootMenu, 0);
63
if (menuStack.rootMenu !== menuStack.tail && menuStack.tail.get(0, "type") === rootMenuType) {
64
menuStack.rootMenu = menuStack.tail.submenu(0);
65
menuStack.push(menuStack.rootMenu, 0);
72
objectName: "mainMenu"
73
model: menuStack.rootMenu
77
bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
79
Behavior on bottomMargin {
82
easing.type: Easing.OutQuad
85
// TODO - does ever frame.
86
onBottomMarginChanged: {
87
mainMenu.positionViewAtIndex(mainMenu.currentIndex, ListView.End)
91
// Ensure all delegates are cached in order to improve smoothness of scrolling
94
// Only allow flicking if the content doesn't fit on the page
95
interactive: contentHeight > height
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
131
property int modelIndex: index
138
sourceComponent: factory.load(model)
141
if (item.hasOwnProperty("selected")) {
142
item.selected = mainMenu.selectedIndex == index;
144
if (item.hasOwnProperty("menuSelected")) {
145
item.menuSelected.connect(function() { mainMenu.selectedIndex = index; });
147
if (item.hasOwnProperty("menuDeselected")) {
148
item.menuDeselected.connect(function() { mainMenu.selectedIndex = -1; });
150
if (item.hasOwnProperty("menuData")) {
151
item.menuData = Qt.binding(function() { return model; });
153
if (item.hasOwnProperty("menuIndex")) {
154
item.menuIndex = Qt.binding(function() { return modelIndex; });
159
target: item ? item : null
160
property: "objectName"
164
// TODO: Fixes lp#1243146
165
// This is a workaround for a Qt bug. https://bugreports.qt-project.org/browse/QTBUG-34351
168
onSelectedIndexChanged: {
169
if (loader.item && loader.item.hasOwnProperty("selected")) {
170
loader.item.selected = mainMenu.selectedIndex == index;
177
Indicators.MenuItemFactory {
179
menuModel: mainMenu.model ? mainMenu.model : null
184
objectName: "emptyLabel"
185
visible: mainMenu.count == 0
190
topMargin: units.gu(2)
192
wrapMode: Text.WordWrap
193
horizontalAlignment: Text.AlignHCenter
205
if (!contentActive) {
206
contentActive = true;
213
contentActive = false;
219
mainMenu.selectedIndex = -1;
220
mainMenu.positionViewAtBeginning();
23
Indicators.IndicatorPage {