on xenial help sign in
IndicatorsBar
commit193b02cce5469fb7864e5dd5183fded94941deb3 authorNick Dedekind <nick.dedekind@canonical.com> dateTue 23 Sep 2014, 09:00 (12 years ago) parentce9db1a
6 files changed+400−9
qml/Panel/New/IndicatorItem.qml+7−7 qml/Panel/New/IndicatorsBar.qml+144 qml/Panel/New/IndicatorsRow.qml+10−1 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Panel/New/tst_NewIndicatorsBar.qml+238 tests/qmltests/Panel/New/tst_NewIndicatorsRow.qml−1
qml/Panel/New/IndicatorItem.qml+7−7
@@ -105,7 +105,7 @@ IndicatorBase {
105105 if (!selected) return Theme.palette.selected.backgroundText;
106106 return Theme.palette.normal.foregroundText;
107107 }
108− Behavior on color { ColorAnimation{ duration: 1 } }
108+ Behavior on color { ColorAnimation{ duration: UbuntuAnimation.SnapDuration } }
109109 }
110110 }
111111 }
@@ -179,7 +179,7 @@ IndicatorBase {
179179 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
180180 AnchorChanges { target: itemLeftLabel; anchors.left: undefined; anchors.right: iconsItem.left }
181181 PropertyChanges { target: itemLeftLabel; opacity: 0 }
182− PropertyChanges { target: mainItems; width: Math.max(iconsItem.width, indicatorName.width); anchors.verticalCenterOffset: -units.gu(1) }
182+ PropertyChanges { target: mainItems; width: Math.max(iconsItem.width, indicatorName.width) + units.gu(2); anchors.verticalCenterOffset: -units.gu(1) }
183183 PropertyChanges { target: itemLeftLabel; opacity: 0 }
184184 PropertyChanges { target: itemRightLabel; opacity: 0 }
185185 },
@@ -192,7 +192,7 @@ IndicatorBase {
192192 AnchorChanges { target: iconsItem; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
193193 AnchorChanges { target: itemLeftLabel; anchors.left: undefined; anchors.right: iconsItem.left }
194194 PropertyChanges { target: itemLeftLabel; opacity: 0 }
195− PropertyChanges { target: mainItems; width: Math.max(iconsItem.width, indicatorName.width); anchors.verticalCenterOffset: -units.gu(1) }
195+ PropertyChanges { target: mainItems; width: Math.max(iconsItem.width, indicatorName.width) + units.gu(2); anchors.verticalCenterOffset: -units.gu(1) }
196196 PropertyChanges { target: itemLeftLabel; opacity: 0 }
197197 PropertyChanges { target: itemRightLabel; opacity: 0 }
198198 },
@@ -202,7 +202,7 @@ IndicatorBase {
202202 when: expanded && (!icons || icons.length === 0) && rightLabel !== ""
203203 PropertyChanges { target: indicatorName; visible: true; opacity: 1}
204204 AnchorChanges { target: itemRightLabel; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
205− PropertyChanges { target: mainItems; width: Math.max(itemRightLabel.width, indicatorName.width); anchors.verticalCenterOffset: -units.gu(1) }
205+ PropertyChanges { target: mainItems; width: Math.max(itemRightLabel.width, indicatorName.width) + units.gu(2); anchors.verticalCenterOffset: -units.gu(1) }
206206 PropertyChanges { target: iconsItem; opacity: 0 }
207207 PropertyChanges { target: itemLeftLabel; opacity: 0 }
208208 },
@@ -212,7 +212,7 @@ IndicatorBase {
212212 when: expanded && (!icons || icons.length === 0) && leftLabel !== ""
213213 PropertyChanges { target: indicatorName; visible: true; opacity: 1}
214214 AnchorChanges { target: itemLeftLabel; anchors.left: undefined; anchors.horizontalCenter: parent.horizontalCenter }
215− PropertyChanges { target: mainItems; width: Math.max(itemLeftLabel.width, indicatorName.width); anchors.verticalCenterOffset: -units.gu(1) }
215+ PropertyChanges { target: mainItems; width: Math.max(itemLeftLabel.width, indicatorName.width) + units.gu(2); anchors.verticalCenterOffset: -units.gu(1) }
216216 PropertyChanges { target: iconsItem; opacity: 0 }
217217 PropertyChanges { target: itemRightLabel; opacity: 0 }
218218 }
@@ -223,12 +223,12 @@ IndicatorBase {
223223 PropertyAction { target: d; property: "useFallbackIcon"}
224224 AnchorAnimation {
225225 targets: [ mainItems, iconsItem, itemLeftLabel, itemRightLabel ]
226− duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
226+ duration: 1000; easing: UbuntuAnimation.StandardEasing
227227 }
228228 PropertyAnimation {
229229 targets: [ mainItems, iconsItem, itemLeftLabel, itemRightLabel, indicatorName ]
230230 properties: "width, opacity, anchors.verticalCenterOffset";
231− duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing
231+ duration: 1000; easing: UbuntuAnimation.StandardEasing
232232 }
233233 }
234234 ]
qml/Panel/New/IndicatorsBar.qmlnew file+144
@@ -0,0 +1,144 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU 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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import Ubuntu.Components 0.1
19+
20+Item {
21+ id: root
22+ property alias expanded: row.expanded
23+ property alias indicatorsModel: row.indicatorsModel
24+
25+ function selectItemAt(lateralPosition) {
26+ if (!expanded)
27+ d.initialItem = null;
28+ var mapped = root.mapToItem(row, lateralPosition, 0);
29+ row.selectItemAt(mapped.x);
30+ }
31+
32+ QtObject {
33+ id: d
34+ property var initialItem: null
35+ // the non-expanded distance from row offset to center of initial item
36+ property real originalDistanceFromRight: -1
37+
38+ // calculate the distance from row offset to center of initial item
39+ property real distanceFromRight: {
40+ if (originalDistanceFromRight == -1) return 0;
41+ if (!initialItem) return 0;
42+ return row.width - initialItem.x - initialItem.width /2;
43+ }
44+
45+ // offset to the intially selected expanded item
46+ property real rowOffset: 0
47+
48+ onInitialItemChanged: {
49+ console.log("INITIAL CHANGED ", initialItem)
50+ if (initialItem) {
51+ originalDistanceFromRight = row.width - initialItem.x - initialItem.width/2;
52+ } else {
53+ originalDistanceFromRight = -1;
54+ }
55+ }
56+ }
57+
58+ onExpandedChanged: {
59+ console.log("EXPANDED CHANGED ", expanded)
60+ }
61+
62+ Connections {
63+ target: row
64+ onCurrentItemChanged: {
65+ if (!row.currentItem) d.initialItem = null;
66+ else if (!d.initialItem) d.initialItem = row.currentItem;
67+ }
68+ }
69+
70+ Flickable {
71+ id: flickable
72+ flickableDirection: Qt.Horizontal
73+ anchors.fill: parent
74+ contentWidth: row.width
75+ interactive: expanded
76+ clip: true
77+
78+ rebound: Transition {
79+ NumberAnimation {
80+ properties: "x"
81+ duration: 600
82+ easing.type: Easing.OutCubic
83+ }
84+ }
85+
86+ contentX: {
87+ var cX = row.width - flickable.width > 0 ? row.width - flickable.width : 0
88+ if (cX !== 0) {
89+ cX -= d.rowOffset;
90+ }
91+ return cX;
92+ }
93+ Behavior on contentX { enabled: !expanded; NumberAnimation { duration: 1000; easing: UbuntuAnimation.StandardEasing } }
94+
95+ IndicatorsRow {
96+ id: row
97+ enabled: false
98+ anchors {
99+ top: parent.top
100+ bottom: parent.bottom
101+ right: parent.right
102+ rightMargin: {
103+ var rM = row.width - flickable.width < 0 ? row.width - flickable.width : 0;
104+ if (rM !== 0) {
105+ rM -= d.rowOffset;
106+ }
107+ return rM;
108+ }
109+ }
110+ }
111+ }
112+
113+ states: [
114+ State {
115+ name: "minimized"
116+ when: !expanded
117+ PropertyChanges {
118+ target: d
119+ rowOffset: 0
120+ }
121+ },
122+ State {
123+ name: "expanded"
124+ when: expanded
125+ PropertyChanges {
126+ target: d
127+ rowOffset: {
128+ if (!initialItem) return 0;
129+ if (distanceFromRight - initialItem.width <= 0) return 0;
130+
131+ var rowOffset = distanceFromRight - originalDistanceFromRight;
132+ return rowOffset;
133+ }
134+ }
135+ }
136+ ]
137+
138+ transitions: [
139+ Transition {
140+ to: "minimized"
141+ PropertyAnimation { target: d; properties: "rowOffset"; duration: 1000; easing: UbuntuAnimation.StandardEasing }
142+ }
143+ ]
144+}
qml/Panel/New/IndicatorsRow.qml+10−1
@@ -22,7 +22,7 @@ Item {
2222 id: indicatorRow
2323
2424 property QtObject indicatorsModel: null
25− property int overFlowWidth: width
25+ property real overFlowWidth: width
2626 property bool showAll: false
2727 property bool expanded: false
2828 property real currentItemOffset: 0.0
@@ -40,6 +40,15 @@ Item {
4040 currentItem = null
4141 }
4242
43+ function selectItemAt(lateralPosition) {
44+ var item = indicatorAt(lateralPosition, 0);
45+ if (item.opacity > 0) {
46+ currentItem = item;
47+ } else {
48+ currentItem = null;
49+ }
50+ }
51+
4352 Timer {
4453 id: allVisible
4554 interval: 1000
tests/qmltests/CMakeLists.txt+1
@@ -78,6 +78,7 @@ add_qml_test(Panel Panel)
7878add_qml_test(Panel SearchIndicator)
7979add_qml_test(Panel/New NewIndicatorItem)
8080add_qml_test(Panel/New NewIndicatorsRow ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
81+add_qml_test(Panel/New NewIndicatorsBar ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
8182add_qml_test(Panel/Indicators DefaultIndicatorWidget ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
8283add_qml_test(Panel/Indicators DefaultIndicatorPage ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
8384add_qml_test(Panel/Indicators CachedUnityMenuModel ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
tests/qmltests/Panel/New/tst_NewIndicatorsBar.qmlnew file+238
@@ -0,0 +1,238 @@
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 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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.1
18+import QtQuick.Layouts 1.1
19+import QtTest 1.0
20+import ".."
21+import "../../../../qml/Panel/New"
22+import Ubuntu.Components 0.1
23+import Unity.Test 0.1 as UT
24+import Unity.Indicators 0.1 as Indicators
25+
26+Rectangle {
27+ width: units.gu(100)
28+ height: units.gu(30)
29+ color: "white"
30+
31+ Component.onCompleted: {
32+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake1",
33+ "/com/canonical/indicators/fake1",
34+ "/com/canonical/indicators/fake1",
35+ {
36+ "title": "Bluetooth",
37+ "icons": [ "image://theme/bluetooth-active" ],
38+ });
39+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake2",
40+ "/com/canonical/indicators/fake2",
41+ "/com/canonical/indicators/fake2",
42+ {
43+ "title": "Network",
44+ "icons": [ "image://theme/simcard-error", "image://theme/wifi-high" ],
45+ });
46+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake3",
47+ "/com/canonical/indicators/fake3",
48+ "/com/canonical/indicators/fake3",
49+ {
50+ "title": "Sound",
51+ "icons": [ "image://theme/audio-volume-high" ],
52+ });
53+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake4",
54+ "/com/canonical/indicators/fake4",
55+ "/com/canonical/indicators/fake4",
56+ {
57+ "title": "Battery",
58+ "icons": [ "image://theme/battery-020" ],
59+ });
60+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake5",
61+ "/com/canonical/indicators/fake5",
62+ "/com/canonical/indicators/fake5",
63+ {
64+ "title": "Location",
65+ "icons": [ "image://theme/gps" ],
66+ });
67+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake6",
68+ "/com/canonical/indicators/fake6",
69+ "/com/canonical/indicators/fake6",
70+ {
71+ "title": "Notifications",
72+ "icons": [ "image://theme/messages-new" ],
73+ });
74+ Indicators.UnityMenuModelCache.setCachedModelData("com.canonical.indicators.fake7",
75+ "/com/canonical/indicators/fake7",
76+ "/com/canonical/indicators/fake7",
77+ {
78+ "title": "Upcoming Events",
79+ "label": "12:04",
80+ });
81+ }
82+
83+ Indicators.FakeIndicatorsModel {
84+ id: indicatorsModel
85+
86+ indicatorData: [
87+ {
88+ "identifier": "indicator-fake1",
89+ "indicatorProperties": {
90+ "enabled": true,
91+ "busName": "com.canonical.indicators.fake1",
92+ "menuObjectPath": "/com/canonical/indicators/fake1",
93+ "actionsObjectPath": "/com/canonical/indicators/fake1"
94+ }
95+ },
96+ {
97+ "identifier": "indicator-fake2",
98+ "indicatorProperties": {
99+ "enabled": true,
100+ "busName": "com.canonical.indicators.fake2",
101+ "menuObjectPath": "/com/canonical/indicators/fake2",
102+ "actionsObjectPath": "/com/canonical/indicators/fake2"
103+ }
104+ },
105+ {
106+ "identifier": "indicator-fake3",
107+ "indicatorProperties": {
108+ "enabled": true,
109+ "busName": "com.canonical.indicators.fake3",
110+ "menuObjectPath": "/com/canonical/indicators/fake3",
111+ "actionsObjectPath": "/com/canonical/indicators/fake3"
112+ }
113+ },
114+ {
115+ "identifier": "indicator-fake4",
116+ "indicatorProperties": {
117+ "enabled": true,
118+ "busName": "com.canonical.indicators.fake4",
119+ "menuObjectPath": "/com/canonical/indicators/fake4",
120+ "actionsObjectPath": "/com/canonical/indicators/fake4"
121+ }
122+ },
123+ {
124+ "identifier": "indicator-fake5",
125+ "indicatorProperties": {
126+ "enabled": true,
127+ "busName": "com.canonical.indicators.fake5",
128+ "menuObjectPath": "/com/canonical/indicators/fake5",
129+ "actionsObjectPath": "/com/canonical/indicators/fake5"
130+ }
131+ },
132+ {
133+ "identifier": "indicator-fake6",
134+ "indicatorProperties": {
135+ "enabled": true,
136+ "busName": "com.canonical.indicators.fake6",
137+ "menuObjectPath": "/com/canonical/indicators/fake6",
138+ "actionsObjectPath": "/com/canonical/indicators/fake6"
139+ }
140+ },
141+ {
142+ "identifier": "indicator-fake7",
143+ "indicatorProperties": {
144+ "enabled": true,
145+ "busName": "com.canonical.indicators.fake7",
146+ "menuObjectPath": "/com/canonical/indicators/fake7",
147+ "actionsObjectPath": "/com/canonical/indicators/fake7"
148+ }
149+ },
150+ {
151+ "identifier": "indicator-fake8",
152+ "indicatorProperties": {
153+ "enabled": true,
154+ "busName": "com.canonical.indicators.fake1",
155+ "menuObjectPath": "/com/canonical/indicators/fake1",
156+ "actionsObjectPath": "/com/canonical/indicators/fake1"
157+ }
158+ },
159+ {
160+ "identifier": "indicator-fake9",
161+ "indicatorProperties": {
162+ "enabled": true,
163+ "busName": "com.canonical.indicators.fake1",
164+ "menuObjectPath": "/com/canonical/indicators/fake1",
165+ "actionsObjectPath": "/com/canonical/indicators/fake1"
166+ }
167+ },
168+ {
169+ "identifier": "indicator-fake10",
170+ "indicatorProperties": {
171+ "enabled": true,
172+ "busName": "com.canonical.indicators.fake1",
173+ "menuObjectPath": "/com/canonical/indicators/fake1",
174+ "actionsObjectPath": "/com/canonical/indicators/fake1"
175+ }
176+ },
177+ ]
178+ }
179+
180+ Rectangle {
181+ id: itemArea
182+ color: "blue"
183+ anchors {
184+ top: parent.top
185+ bottom: parent.bottom
186+ }
187+ width: units.gu(50)
188+
189+ Rectangle {
190+ color: "black"
191+ anchors.fill: indicatorsBar
192+ }
193+
194+ IndicatorsBar {
195+ id: indicatorsBar
196+ height: expanded ? units.gu(7) : units.gu(3)
197+ width: units.gu(30)
198+ anchors.centerIn: parent
199+ indicatorsModel: indicatorsModel
200+
201+ Behavior on height { NumberAnimation { duration: 1000; easing: UbuntuAnimation.StandardEasing } }
202+
203+ MouseArea {
204+ anchors.fill: parent
205+ enabled: !indicatorsBar.expanded
206+ onPressed: {
207+ console.log("click")
208+ indicatorsBar.selectItemAt(mouse.x);
209+ indicatorsBar.expanded = true
210+ }
211+ }
212+ }
213+ }
214+
215+ ColumnLayout {
216+ anchors {
217+ top: parent.top
218+ bottom: button.top
219+ left: itemArea.right
220+ right: parent.right
221+ }
222+ }
223+
224+ Button {
225+ id: button
226+ anchors {
227+ left: parent.left
228+ right: parent.right
229+ bottom: parent.bottom
230+ }
231+ text: indicatorsBar.expanded ? "Collapse" : "Expand"
232+ onClicked: indicatorsBar.expanded = !indicatorsBar.expanded
233+ }
234+
235+ UT.UnityTestCase {
236+ name: "IndicatorsRow"
237+ }
238+}
tests/qmltests/Panel/New/tst_NewIndicatorsRow.qml−1
@@ -64,7 +64,6 @@ Rectangle {
6464 "title": "Upcoming Events",
6565 "label": "12:04",
6666 });
67− console.log("PLOP")
6867 }
6968
7069 Indicators.FakeIndicatorsModel {