on cfda370 help sign in
unity8/plugins/Unity/Indicators/qml/IndicatorPage.qml
160 lines 4.5 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; });
100 item.activate.connect(onActivateMenu);
101 item.changeState.connect(onChangeState);
102 }
103 }
105 function onActivateMenu(value) {
106 mainMenu.model.activate(index, value);
107 }
109 function onChangeState(value) {
110 mainMenu.model.changeState(index, value);
111 }
112 }
113 }
114 }
116 MenuItemFactory {
117 id: factory
118 model: mainMenu.model
119 }
121 Components.Label {
122 id: emptyLabel
123 visible: mainMenu.count == 0
124 anchors {
125 top: parent.top
126 left: parent.left
127 right: parent.right
128 topMargin: units.gu(2)
129 }
130 wrapMode: Text.WordWrap
131 horizontalAlignment: Text.AlignHCenter
133 //style
134 color: "#e8e1d0"
135 fontSize: "medium"
137 text: "Empty!"
138 }
140 function start()
141 {
142 reset()
143 if (!active) {
144 active = true;
145 }
146 }
148 function stop()
149 {
150 if (active) {
151 active = false;
152 }
153 }
155 function reset()
156 {
157 mainMenu.currentIndex = -1;
158 mainMenu.positionViewAtBeginning();
159 }