on a7ea6aa help sign in
unity8/plugins/Unity/Indicators/qml/IndicatorPage.qml
191 lines 5.4 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
24IndicatorBase {
25 id: main
27 //const
28 property alias emptyText: emptyLabel.text
29 property alias highlightFollowsCurrentItem : mainMenu.highlightFollowsCurrentItem
30 property bool __active: false
32 ListView {
33 id: mainMenu
35 property int visibleItems: 0
37 model: proxyModel
38 anchors {
39 fill: parent
40 bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
42 Behavior on bottomMargin {
43 NumberAnimation {
44 duration: 175
45 easing.type: Easing.OutQuad
46 }
47 }
48 // TODO - does ever frame.
49 onBottomMarginChanged: {
50 mainMenu.positionViewAtIndex(mainMenu.currentIndex, ListView.End)
51 }
52 }
54 // Ensure all delegates are cached in order to improve smoothness of scrolling
55 cacheBuffer: 10000
57 // Only allow flicking if the content doesn't fit on the page
58 interactive: contentHeight > height
60 currentIndex: -1
61 delegate: Item {
62 id: item
63 property bool ready: false
64 property alias empty: factory.empty
66 anchors {
67 left: parent.left
68 right: parent.right
69 }
70 height: div.height + factory.implicitHeight
71 visible: height > 0
73 Component.onCompleted: {
74 if (!item.empty) {
75 mainMenu.visibleItems += 1;
76 }
77 ready = true;
78 }
79 Component.onDestruction: {
80 if (!item.empty) {
81 mainMenu.visibleItems -= 1;
82 }
83 ready = false;
84 }
86 onEmptyChanged: {
87 if (!ready) {
88 return;
89 }
90 if (empty) {
91 mainMenu.visibleItems -= 1;
92 } else {
93 mainMenu.visibleItems += 1;
94 }
95 }
97 ListView.onRemove: {
98 if (!highlightFollowsCurrentItem) {
99 mainMenu.currentIndex = -1;
100 }
101 }
103 Column {
104 id: contents
106 anchors.fill: parent
108 DivMenuItem {
109 id: div
111 anchors.left: parent.left
112 anchors.right: parent.right
113 // only visible if is a root or a section header element and the factory is visible
114 height: {
115 // skipe first item
116 if (item.y == 0) {
117 return 0;
118 }
119 if (hasSection || ((depth == 0) && (!factory.empty))) {
120 return implicitHeight;
121 } else {
122 return 0;
123 }
124 }
125 }
127 MenuItemFactory {
128 id: factory
130 actionGroup: main.actionGroup
131 isCurrentItem: item.ListView.isCurrentItem
132 anchors {
133 left: parent.left
134 right: parent.right
135 }
136 menu: model
138 Connections {
139 target : factory
140 onActivated: item.ListView.view.currentIndex = index
141 onDeactivated: item.ListView.view.currentIndex = -1
142 }
143 }
144 }
145 }
146 }
148 Components.Label {
149 id: emptyLabel
150 visible: (mainMenu.visibleItems === 0)
151 anchors {
152 top: parent.top
153 left: parent.left
154 right: parent.right
155 topMargin: units.gu(2)
156 }
157 wrapMode: Text.WordWrap
158 horizontalAlignment: Text.AlignHCenter
160 //style
161 color: "#e8e1d0"
162 fontSize: "medium"
164 text: "Empty!"
165 }
167 function start()
168 {
169 reset()
170 if (!__active) {
171 proxyModel.start();
172 actionGroup.start();
173 __active = true;
174 }
175 }
177 function stop()
178 {
179 if (__active) {
180 __active = false;
181 proxyModel.stop();
182 actionGroup.stop();
183 }
184 }
186 function reset()
187 {
188 mainMenu.currentIndex = -1;
189 mainMenu.positionViewAtBeginning();
190 }