on fb3e090 help sign in
unity8/plugins/Unity/Indicators/qml/IndicatorPage.qml
182 lines 5.2 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 property int selectedIndex: -1
64 property bool blockCurrentIndexChange: false
65 // for count = 0
66 onCountChanged: {
67 if (count == 0 && selectedIndex != -1) {
68 selectedIndex = -1;
69 }
70 }
71 // for highlight following
72 onSelectedIndexChanged: {
73 if (currentIndex != selectedIndex) {
74 var blocked = blockCurrentIndexChange;
75 blockCurrentIndexChange = true;
77 currentIndex = selectedIndex;
79 blockCurrentIndexChange = blocked;
80 }
81 }
82 // for item addition/removal
83 onCurrentIndexChanged: {
84 if (!blockCurrentIndexChange) {
85 if (selectedIndex != -1 && selectedIndex != currentIndex) {
86 selectedIndex = currentIndex;
87 }
88 }
89 }
91 delegate: Item {
92 id: menuDelegate
94 anchors {
95 left: parent.left
96 right: parent.right
97 }
98 height: loader.height
99 visible: height > 0
101 Loader {
102 id: loader
103 asynchronous: true
105 property int modelIndex: index
107 anchors {
108 left: parent.left
109 right: parent.right
110 }
112 sourceComponent: factory.load(model)
114 onLoaded: {
115 if (model.type === rootMenuType) {
116 menuStack.push(mainMenu.model.submenu(index));
117 }
119 if (item.hasOwnProperty("menuSelected")) {
120 item.menuSelected = Qt.binding(function() { return mainMenu.selectedIndex == index; });
121 item.selectMenu.connect(function() { mainMenu.selectedIndex = index; });
122 item.deselectMenu.connect(function() { mainMenu.selectedIndex = -1; });
123 }
124 if (item.hasOwnProperty("menu")) {
125 item.menu = Qt.binding(function() { return model; });
126 }
127 }
129 Binding {
130 target: item ? item : null
131 property: "objectName"
132 value: model.action
133 }
134 }
135 }
136 }
138 MenuItemFactory {
139 id: factory
140 model: mainMenu.model
141 }
143 Components.Label {
144 id: emptyLabel
145 visible: mainMenu.count == 0
146 anchors {
147 top: parent.top
148 left: parent.left
149 right: parent.right
150 topMargin: units.gu(2)
151 }
152 wrapMode: Text.WordWrap
153 horizontalAlignment: Text.AlignHCenter
155 //style
156 color: "#e8e1d0"
157 fontSize: "medium"
159 text: "Empty!"
160 }
162 function start()
163 {
164 reset()
165 if (!active) {
166 active = true;
167 }
168 }
170 function stop()
171 {
172 if (active) {
173 active = false;
174 }
175 }
177 function reset()
178 {
179 mainMenu.selectedIndex = -1;
180 mainMenu.positionViewAtBeginning();
181 }