on bf461a2 help sign in
unity8/plugins/Unity/Indicators/qml/IndicatorPage.qml
155 lines 4.3 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 * Nick Dedekind <nick.dedekind@canonical.com>
19 */
21import QtQuick 2.0
22import Ubuntu.Components 0.1 as Components
23import Unity.Indicators 0.1 as Indicators
25IndicatorBase {
26 id: main
28 //const
29 property alias emptyText: emptyLabel.text
30 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
32 Indicators.UnityMenuModelStack {
33 id: menuStack
34 head: main.menuModel
35 }
37 ListView {
38 id: mainMenu
39 model: menuStack.tail ? menuStack.tail : null
41 anchors {
42 fill: parent
43 bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
45 Behavior on bottomMargin {
46 NumberAnimation {
47 duration: 175
48 easing.type: Easing.OutQuad
49 }
50 }
51 // TODO - does ever frame.
52 onBottomMarginChanged: {
53 mainMenu.positionViewAtIndex(mainMenu.currentIndex, ListView.End)
54 }
55 }
57 // Ensure all delegates are cached in order to improve smoothness of scrolling
58 cacheBuffer: 10000
60 // Only allow flicking if the content doesn't fit on the page
61 interactive: contentHeight > height
63 currentIndex: -1
64 delegate: Item {
65 id: menuDelegate
67 anchors {
68 left: parent.left
69 right: parent.right
70 }
71 height: loader.height
72 visible: height > 0
74 Loader {
75 id: loader
76 asynchronous: true
78 property int modelIndex: index
80 anchors {
81 left: parent.left
82 right: parent.right
83 }
85 sourceComponent: factory.load(model)
87 onLoaded: {
88 if (model.type === rootMenuType) {
89 menuStack.push(mainMenu.model.submenu(index));
90 }
92 if (item.hasOwnProperty("menuActivated")) {
93 item.menuActivated = Qt.binding(function() { return ListView.isCurrentItem; });
94 item.selectMenu.connect(function() { ListView.view.currentIndex = index });
95 item.deselectMenu.connect(function() { ListView.view.currentIndex = -1 });
96 }
97 if (item.hasOwnProperty("menu")) {
98 item.menu = Qt.binding(function() { return model; });
99 }
100 }
102 Binding {
103 target: item ? item : null
104 property: "objectName"
105 value: model.action
106 }
107 }
108 }
109 }
111 MenuItemFactory {
112 id: factory
113 model: mainMenu.model
114 }
116 Components.Label {
117 id: emptyLabel
118 visible: mainMenu.count == 0
119 anchors {
120 top: parent.top
121 left: parent.left
122 right: parent.right
123 topMargin: units.gu(2)
124 }
125 wrapMode: Text.WordWrap
126 horizontalAlignment: Text.AlignHCenter
128 //style
129 color: "#e8e1d0"
130 fontSize: "medium"
132 text: "Empty!"
133 }
135 function start()
136 {
137 reset()
138 if (!active) {
139 active = true;
140 }
141 }
143 function stop()
144 {
145 if (active) {
146 active = false;
147 }
148 }
150 function reset()
151 {
152 mainMenu.currentIndex = -1;
153 mainMenu.positionViewAtBeginning();
154 }