on 31bb5ed help sign in
unity8/plugins/Unity/Indicators/qml/IndicatorPage.qml
184 lines 5.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 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
37 }
39 ListView {
40 id: mainMenu
41 model: menuStack.tail ? menuStack.tail : null
43 anchors {
44 fill: parent
45 bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
47 Behavior on bottomMargin {
48 NumberAnimation {
49 duration: 175
50 easing.type: Easing.OutQuad
51 }
52 }
53 // TODO - does ever frame.
54 onBottomMarginChanged: {
55 mainMenu.positionViewAtIndex(mainMenu.currentIndex, ListView.End)
56 }
57 }
59 // Ensure all delegates are cached in order to improve smoothness of scrolling
60 cacheBuffer: 10000
62 // Only allow flicking if the content doesn't fit on the page
63 interactive: contentHeight > height
65 property int selectedIndex: -1
66 property bool blockCurrentIndexChange: false
67 // for count = 0
68 onCountChanged: {
69 if (count == 0 && selectedIndex != -1) {
70 selectedIndex = -1;
71 }
72 }
73 // for highlight following
74 onSelectedIndexChanged: {
75 if (currentIndex != selectedIndex) {
76 var blocked = blockCurrentIndexChange;
77 blockCurrentIndexChange = true;
79 currentIndex = selectedIndex;
81 blockCurrentIndexChange = blocked;
82 }
83 }
84 // for item addition/removal
85 onCurrentIndexChanged: {
86 if (!blockCurrentIndexChange) {
87 if (selectedIndex != -1 && selectedIndex != currentIndex) {
88 selectedIndex = currentIndex;
89 }
90 }
91 }
93 delegate: Item {
94 id: menuDelegate
96 anchors {
97 left: parent.left
98 right: parent.right
99 }
100 height: loader.height
101 visible: height > 0
103 Loader {
104 id: loader
105 asynchronous: true
107 property int modelIndex: index
109 anchors {
110 left: parent.left
111 right: parent.right
112 }
114 sourceComponent: factory.load(model)
116 onLoaded: {
117 if (model.type === rootMenuType) {
118 menuStack.push(mainMenu.model.submenu(index));
119 }
121 if (item.hasOwnProperty("menuSelected")) {
122 item.menuSelected = Qt.binding(function() { return mainMenu.selectedIndex == index; });
123 item.selectMenu.connect(function() { mainMenu.selectedIndex = index; });
124 item.deselectMenu.connect(function() { mainMenu.selectedIndex = -1; });
125 }
126 if (item.hasOwnProperty("menu")) {
127 item.menu = Qt.binding(function() { return model; });
128 }
129 }
131 Binding {
132 target: item ? item : null
133 property: "objectName"
134 value: model.action
135 }
136 }
137 }
138 }
140 MenuItemFactory {
141 id: factory
142 model: mainMenu.model
143 }
145 Components.Label {
146 id: emptyLabel
147 visible: mainMenu.count == 0
148 anchors {
149 top: parent.top
150 left: parent.left
151 right: parent.right
152 topMargin: units.gu(2)
153 }
154 wrapMode: Text.WordWrap
155 horizontalAlignment: Text.AlignHCenter
157 //style
158 color: "#e8e1d0"
159 fontSize: "medium"
161 text: "Empty!"
162 }
164 function start()
165 {
166 reset()
167 if (!contentActive) {
168 contentActive = true;
169 }
170 }
172 function stop()
173 {
174 if (contentActive) {
175 contentActive = false;
176 }
177 }
179 function reset()
180 {
181 mainMenu.selectedIndex = -1;
182 mainMenu.positionViewAtBeginning();
183 }