on bf4f7ea help sign in
unity8/plugins/Unity/Indicators/qml/IndicatorPage.qml
205 lines 5.9 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 bool contentActive: false
30 property string title: rootActionState.title
31 property alias emptyText: emptyLabel.text
32 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
34 Indicators.UnityMenuModelStack {
35 id: menuStack
36 head: contentActive ? main.menuModel : null
38 property var rootMenu: null
40 onTailChanged: {
41 if (!tail) {
42 rootMenu = null;
43 } else if (rootMenu != tail) {
44 if (tail.get(0, "type") === rootMenuType) {
45 rootMenu = menuStack.tail.submenu(0);
46 push(rootMenu, 0);
47 } else {
48 rootMenu = null;
49 }
50 }
51 }
52 }
54 Connections {
55 target: menuStack.tail
56 onRowsInserted: {
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);
60 }
61 }
62 }
64 ListView {
65 id: mainMenu
66 model: menuStack.rootMenu
68 anchors {
69 fill: parent
70 bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
72 Behavior on bottomMargin {
73 NumberAnimation {
74 duration: 175
75 easing.type: Easing.OutQuad
76 }
77 }
78 // TODO - does ever frame.
79 onBottomMarginChanged: {
80 mainMenu.positionViewAtIndex(mainMenu.currentIndex, ListView.End)
81 }
82 }
84 // Ensure all delegates are cached in order to improve smoothness of scrolling
85 cacheBuffer: 10000
87 // Only allow flicking if the content doesn't fit on the page
88 interactive: contentHeight > height
90 property int selectedIndex: -1
91 property bool blockCurrentIndexChange: false
92 // for count = 0
93 onCountChanged: {
94 if (count == 0 && selectedIndex != -1) {
95 selectedIndex = -1;
96 }
97 }
98 // for highlight following
99 onSelectedIndexChanged: {
100 if (currentIndex != selectedIndex) {
101 var blocked = blockCurrentIndexChange;
102 blockCurrentIndexChange = true;
104 currentIndex = selectedIndex;
106 blockCurrentIndexChange = blocked;
107 }
108 }
109 // for item addition/removal
110 onCurrentIndexChanged: {
111 if (!blockCurrentIndexChange) {
112 if (selectedIndex != -1 && selectedIndex != currentIndex) {
113 selectedIndex = currentIndex;
114 }
115 }
116 }
118 delegate: Item {
119 id: menuDelegate
121 anchors {
122 left: parent.left
123 right: parent.right
124 }
125 height: loader.height
126 visible: height > 0
128 Loader {
129 id: loader
130 asynchronous: false
132 property int modelIndex: index
134 anchors {
135 left: parent.left
136 right: parent.right
137 }
139 sourceComponent: factory.load(model)
141 onLoaded: {
142 if (item.hasOwnProperty("menuSelected")) {
143 item.menuSelected = Qt.binding(function() { return mainMenu.selectedIndex == index; });
144 item.selectMenu.connect(function() { mainMenu.selectedIndex = index; });
145 item.deselectMenu.connect(function() { mainMenu.selectedIndex = -1; });
146 }
147 if (item.hasOwnProperty("menu")) {
148 item.menu = Qt.binding(function() { return model; });
149 }
150 }
152 Binding {
153 target: item ? item : null
154 property: "objectName"
155 value: model.action
156 }
157 }
158 }
159 }
161 MenuItemFactory {
162 id: factory
163 model: mainMenu.model
164 }
166 Components.Label {
167 id: emptyLabel
168 visible: mainMenu.count == 0
169 anchors {
170 top: parent.top
171 left: parent.left
172 right: parent.right
173 topMargin: units.gu(2)
174 }
175 wrapMode: Text.WordWrap
176 horizontalAlignment: Text.AlignHCenter
178 //style
179 color: "#e8e1d0"
180 fontSize: "medium"
182 text: "Empty!"
183 }
185 function start()
186 {
187 reset()
188 if (!contentActive) {
189 contentActive = true;
190 }
191 }
193 function stop()
194 {
195 if (contentActive) {
196 contentActive = false;
197 }
198 }
200 function reset()
201 {
202 mainMenu.selectedIndex = -1;
203 mainMenu.positionViewAtBeginning();
204 }