on xenial help sign in
Moved all IndicatorPage/Widget code to default impls
78ee59aNick Dedekind
Panel/Indicators/DefaultIndicatorPage.qml+196−2
@@ -14,12 +14,206 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
15 *
16 * Authors:
16 * Authors:
17+ * Renato Araujo Oliveira Filho <renato@canonical.com>
17 * Nick Dedekind <nick.dedekind@canonical.com>
18 * Nick Dedekind <nick.dedekind@canonical.com>
18 */
19 */
19
20
20import QtQuick 2.0
21import QtQuick 2.0
22+import Ubuntu.Components 0.1 as Components
21import Unity.Indicators 0.1 as Indicators
23import Unity.Indicators 0.1 as Indicators
22
24
23−Indicators.IndicatorPage {
25+Indicators.IndicatorBase {
26+ id: main
27+
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
33+
34+ Indicators.UnityMenuModelStack {
35+ id: menuStack
36+ head: contentActive ? main.menuModel : null
37+
38+ property var rootMenu: null
39+
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+ }
53+
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+ }
63+
64+ ListView {
65+ id: mainMenu
66+ model: menuStack.rootMenu
67+
68+ anchors {
24− anchors.fill: parent
69+ fill: parent
70+ bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
71+
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+ }
83+
84+ // Ensure all delegates are cached in order to improve smoothness of scrolling
85+ cacheBuffer: 10000
86+
87+ // Only allow flicking if the content doesn't fit on the page
88+ interactive: contentHeight > height
89+
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;
103+
104+ currentIndex = selectedIndex;
105+
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+ }
117+
118+ delegate: Item {
119+ id: menuDelegate
120+
121+ anchors {
122+ left: parent.left
123+ right: parent.right
124+ }
125+ height: loader.height
126+ visible: height > 0
127+
128+ Loader {
129+ id: loader
130+ asynchronous: false
131+
132+ property int modelIndex: index
133+
134+ anchors {
135+ left: parent.left
136+ right: parent.right
137+ }
138+
139+ sourceComponent: factory.load(model)
140+
141+ onLoaded: {
142+ if (item.hasOwnProperty("menuSelected")) {
143+ item.menuSelected = mainMenu.selectedIndex == index;
144+ item.selectMenu.connect(function() { mainMenu.selectedIndex = index; });
145+ item.deselectMenu.connect(function() { mainMenu.selectedIndex = -1; });
146+ }
147+ if (item.hasOwnProperty("menuData")) {
148+ item.menuData = Qt.binding(function() { return model; });
149+ }
150+ if (item.hasOwnProperty("menuIndex")) {
151+ item.menuIndex = Qt.binding(function() { return modelIndex; });
152+ }
153+ }
154+
155+ Binding {
156+ target: item ? item : null
157+ property: "objectName"
158+ value: model.action
159+ }
160+
161+ // TODO: Fixes lp#1243146
162+ // This is a workaround for a Qt bug. https://bugreports.qt-project.org/browse/QTBUG-34351
163+ Connections {
164+ target: mainMenu
165+ onSelectedIndexChanged: {
166+ if (loader.item && loader.item.hasOwnProperty("menuSelected")) {
167+ loader.item.menuSelected = mainMenu.selectedIndex == index;
168+ }
169+ }
170+ }
171+ }
172+ }
173+ }
174+
175+ Indicators.MenuItemFactory {
176+ id: factory
177+ menuModel: mainMenu.model
178+ }
179+
180+ Components.Label {
181+ id: emptyLabel
182+ visible: mainMenu.count == 0
183+ anchors {
184+ top: parent.top
185+ left: parent.left
186+ right: parent.right
187+ topMargin: units.gu(2)
188+ }
189+ wrapMode: Text.WordWrap
190+ horizontalAlignment: Text.AlignHCenter
191+
192+ //style
193+ color: "#e8e1d0"
194+ fontSize: "medium"
195+
196+ text: "Empty!"
197+ }
198+
199+ function start()
200+ {
201+ reset()
202+ if (!contentActive) {
203+ contentActive = true;
204+ }
205+ }
206+
207+ function stop()
208+ {
209+ if (contentActive) {
210+ contentActive = false;
211+ }
212+ }
213+
214+ function reset()
215+ {
216+ mainMenu.selectedIndex = -1;
217+ mainMenu.positionViewAtBeginning();
218+ }
25}
219}
Panel/Indicators/DefaultIndicatorWidget.qml+5−3
@@ -21,15 +21,17 @@ import QtQuick 2.0
21import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
22import Unity.Indicators 0.1 as Indicators
22import Unity.Indicators 0.1 as Indicators
23
23
24−Indicators.IndicatorWidget {
24+Indicators.IndicatorBase {
25 id: indicatorWidget
25 id: indicatorWidget
26
26
27− width: itemRow.width
27+ property int iconSize: height
28−
29 property alias leftLabel: itemLeftLabel.text
28 property alias leftLabel: itemLeftLabel.text
30 property alias rightLabel: itemRightLabel.text
29 property alias rightLabel: itemRightLabel.text
31 property var icons: undefined
30 property var icons: undefined
32
31
32+ width: itemRow.width
33+ enabled: false
34+
33 Row {
35 Row {
34 id: itemRow
36 id: itemRow
35 width: childrenRect.width
37 width: childrenRect.width
plugins/Unity/Indicators/qml/IndicatorPage.qmldeleted−219
@@ -1,219 +0,0 @@
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− */
20−
21−import QtQuick 2.0
22−import Ubuntu.Components 0.1 as Components
23−import Unity.Indicators 0.1 as Indicators
24−
25−IndicatorBase {
26− id: main
27−
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
33−
34− Indicators.UnityMenuModelStack {
35− id: menuStack
36− head: contentActive ? main.menuModel : null
37−
38− property var rootMenu: null
39−
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− }
53−
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− }
63−
64− ListView {
65− id: mainMenu
66− model: menuStack.rootMenu
67−
68− anchors {
69− fill: parent
70− bottomMargin: Qt.inputMethod.visible ? (Qt.inputMethod.keyboardRectangle.height - main.anchors.bottomMargin) : 0
71−
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− }
83−
84− // Ensure all delegates are cached in order to improve smoothness of scrolling
85− cacheBuffer: 10000
86−
87− // Only allow flicking if the content doesn't fit on the page
88− interactive: contentHeight > height
89−
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;
103−
104− currentIndex = selectedIndex;
105−
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− }
117−
118− delegate: Item {
119− id: menuDelegate
120−
121− anchors {
122− left: parent.left
123− right: parent.right
124− }
125− height: loader.height
126− visible: height > 0
127−
128− Loader {
129− id: loader
130− asynchronous: false
131−
132− property int modelIndex: index
133−
134− anchors {
135− left: parent.left
136− right: parent.right
137− }
138−
139− sourceComponent: factory.load(model)
140−
141− onLoaded: {
142− if (item.hasOwnProperty("menuSelected")) {
143− item.menuSelected = mainMenu.selectedIndex == index;
144− item.selectMenu.connect(function() { mainMenu.selectedIndex = index; });
145− item.deselectMenu.connect(function() { mainMenu.selectedIndex = -1; });
146− }
147− if (item.hasOwnProperty("menuData")) {
148− item.menuData = Qt.binding(function() { return model; });
149− }
150− if (item.hasOwnProperty("menuIndex")) {
151− item.menuIndex = Qt.binding(function() { return modelIndex; });
152− }
153− }
154−
155− Binding {
156− target: item ? item : null
157− property: "objectName"
158− value: model.action
159− }
160−
161− // TODO: Fixes lp#1243146
162− // This is a workaround for a Qt bug. https://bugreports.qt-project.org/browse/QTBUG-34351
163− Connections {
164− target: mainMenu
165− onSelectedIndexChanged: {
166− if (loader.item && loader.item.hasOwnProperty("menuSelected")) {
167− loader.item.menuSelected = mainMenu.selectedIndex == index;
168− }
169− }
170− }
171− }
172− }
173− }
174−
175− MenuItemFactory {
176− id: factory
177− menuModel: mainMenu.model
178− }
179−
180− Components.Label {
181− id: emptyLabel
182− visible: mainMenu.count == 0
183− anchors {
184− top: parent.top
185− left: parent.left
186− right: parent.right
187− topMargin: units.gu(2)
188− }
189− wrapMode: Text.WordWrap
190− horizontalAlignment: Text.AlignHCenter
191−
192− //style
193− color: "#e8e1d0"
194− fontSize: "medium"
195−
196− text: "Empty!"
197− }
198−
199− function start()
200− {
201− reset()
202− if (!contentActive) {
203− contentActive = true;
204− }
205− }
206−
207− function stop()
208− {
209− if (contentActive) {
210− contentActive = false;
211− }
212− }
213−
214− function reset()
215− {
216− mainMenu.selectedIndex = -1;
217− mainMenu.positionViewAtBeginning();
218− }
219−}
plugins/Unity/Indicators/qml/IndicatorWidget.qmldeleted−28
@@ -1,28 +0,0 @@
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− * Nick Dedekind <nick.dedekind@canonical.com>
18− */
19−
20−import QtQuick 2.0
21−import Unity.Indicators 0.1 as Indicators
22−
23−IndicatorBase {
24− id: indicatorWidget
25−
26− enabled: false
27− property int iconSize: height
28−}
plugins/Unity/Indicators/qml/qmldir−2
@@ -9,8 +9,6 @@ DivMenuItem 0.1 DivMenuItem.qml
9FramedMenuItem 0.1 FramedMenuItem.qml
9FramedMenuItem 0.1 FramedMenuItem.qml
10HLine 0.1 HLine.qml
10HLine 0.1 HLine.qml
11IndicatorBase 0.1 IndicatorBase.qml
11IndicatorBase 0.1 IndicatorBase.qml
12−IndicatorPage 0.1 IndicatorPage.qml
13−IndicatorWidget 0.1 IndicatorWidget.qml
14MenuActionBinding 0.1 MenuActionBinding.qml
12MenuActionBinding 0.1 MenuActionBinding.qml
15MenuItemFactory 0.1 MenuItemFactory.qml
13MenuItemFactory 0.1 MenuItemFactory.qml
16ProgressMenuItem 0.1 ProgressMenuItem.qml
14ProgressMenuItem 0.1 ProgressMenuItem.qml