on xenial help sign in
Fixes visible indicator misalignment in indicator items/menus (lp#1264678). Fixes: https://bugs.launchpad.net/bugs/1264678.

Approved by PS Jenkins bot, Albert Astals Cid.

commit0e7091da800f2d5db0bdb07e53c2d5538e630fcd authorNick Dedekind <nicholas.dedekind@gmail.com> dateThu 16 Jan 2014, 12:17 (13 years ago) parent59e849ef612b65
10 files changed+180−97
qml/Panel/IndicatorRow.qml+51−29 qml/Panel/Indicators.qml+46−34 qml/Panel/MenuContent.qml+2−2 tests/mocks/Unity/Indicators/IndicatorsModel.qml+2−5 tests/mocks/Unity/Indicators/qml/fake_menu_widget2.qml+1−3 tests/mocks/Unity/Indicators/qml/fake_menu_widget3.qml+1−1 tests/qmltests/Panel/tst_IndicatorRow.qml+2−1 tests/qmltests/Panel/tst_Indicators.qml+59−8 tests/qmltests/Panel/tst_MenuContent.qml+2−2 tests/qmltests/Panel/tst_Panel.qml+14−12
qml/Panel/IndicatorRow.qml+51−29
@@ -26,7 +26,7 @@ Item {
2626 readonly property int currentItemIndex: currentItem ? currentItem.ownIndex : -1
2727 property alias row: row
2828 property QtObject indicatorsModel: null
29− property var visibleIndicators: defined
29+ property var visibleIndicators: undefined
3030 property int overFlowWidth: width
3131 property bool showAll: false
3232 property real currentItemOffset: 0.0
@@ -94,34 +94,56 @@ Item {
9494 property real opacityMultiplier: highlighted ? 1 : (1 - indicatorRow.unitProgress)
9595
9696 IndicatorItem {
97− id: indicatorItem
98− identifier: model.identifier
99− height: parent.height
100−
101− dimmed: itemWrapper.dimmed
102−
103− widgetSource: model.widgetSource
104− indicatorProperties : model.indicatorProperties
105−
106− Component.onCompleted: {
107− if (visibleIndicators == undefined) {
108− visibleIndicators = {}
109− }
110− indicatorRow.visibleIndicators[model.identifier] = indicatorVisible;
111− indicatorRow.visibleIndicatorsChanged();
112− }
113− onIndicatorVisibleChanged: {
114− if (visibleIndicators == undefined) {
115− visibleIndicators = {}
116− }
117− indicatorRow.visibleIndicators[model.identifier] = indicatorVisible;
118− indicatorRow.visibleIndicatorsChanged();
119−
120− if (indicatorVisible) {
121− showAll = true;
122− allVisible.start();
123− }
124− }
97+ id: indicatorItem
98+ identifier: model.identifier
99+ height: parent.height
100+
101+ dimmed: itemWrapper.dimmed
102+
103+ widgetSource: model.widgetSource
104+ indicatorProperties : model.indicatorProperties
105+
106+ Component.onCompleted: {
107+ updateVisiblility();
108+ }
109+ onIndicatorVisibleChanged: {
110+ updateVisiblility();
111+
112+ if (indicatorVisible) {
113+ showAll = true;
114+ allVisible.start();
115+ }
116+ }
117+
118+ function updateVisiblility() {
119+ if (visibleIndicators == undefined) {
120+ visibleIndicators = {}
121+ }
122+ indicatorRow.visibleIndicators[model.identifier] = indicatorVisible;
123+
124+ // removed current index?
125+ if (indicatorRow.currentItemIndex === index && !indicatorVisible) {
126+ // find the next closest visible indicator (after current, else before)
127+ var newIndex = -1;
128+ for (var i = index+1; i < rowRepeater.count; i++) {
129+ if (indicatorRow.visibleIndicators[i] === undefined || indicatorRow.visibleIndicators[model.identifier]) {
130+ newIndex = i;
131+ break;
132+ }
133+ }
134+ if (newIndex === -1) {
135+ for (i = index - 1; i >= 0; i--) {
136+ if (indicatorRow.visibleIndicators[i] === undefined || indicatorRow.visibleIndicators[model.identifier]) {
137+ newIndex = i;
138+ break;
139+ }
140+ }
141+ }
142+ indicatorRow.setCurrentItem(newIndex);
143+ }
144+
145+ indicatorRow.visibleIndicatorsChanged();
146+ }
125147 }
126148
127149 states: [
qml/Panel/Indicators.qml+46−34
@@ -193,21 +193,6 @@ Showable {
193193 clip: !indicators.fullyOpened
194194 activeHeader: indicators.state == "hint" || indicators.state == "reveal"
195195 enabled: contentEnabled
196− visibleIndicators: indicatorRow.visibleIndicators
197−
198− Connections {
199− property bool enableIndexChangeSignal: true
200−
201− target: enableIndexChangeSignal ? indicatorRow : null
202− onCurrentItemIndexChanged: {
203− var oldActive = enableIndexChangeSignal;
204− enableIndexChangeSignal = false;
205−
206− menuContent.setCurrentMenuIndex(indicatorRow.currentItemIndex);
207−
208− enableIndexChangeSignal = oldActive;
209− }
210− }
211196
212197 //small shadow gradient at bottom of menu
213198 Rectangle {
@@ -263,8 +248,6 @@ Showable {
263248
264249 Indicators.IndicatorsModel {
265250 id: indicatorsModel
266−
267− Component.onCompleted: load()
268251 }
269252
270253 IndicatorRow {
@@ -279,17 +262,11 @@ Showable {
279262 state: indicators.state
280263 unitProgress: indicators.unitProgress
281264
282− Connections {
283− property bool enableIndexChangeSignal: true
284−
285− target: enableIndexChangeSignal ? menuContent : null
286− onCurrentMenuIndexChanged: {
287− var oldActive = enableIndexChangeSignal;
288− enableIndexChangeSignal = false;
289−
290− indicatorRow.setCurrentItem(menuContent.currentMenuIndex);
291−
292− enableIndexChangeSignal = oldActive;
265+ onVisibleIndicatorsChanged: {
266+ // need to do it here so we can control sequence
267+ if (visibleIndicators !== undefined) {
268+ menuContent.visibleIndicators = visibleIndicators;
269+ menuContent.setCurrentMenuIndex(currentItemIndex);
293270 }
294271 }
295272
@@ -341,15 +318,45 @@ Showable {
341318 }
342319 }
343320
344− property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
321+ QtObject {
322+ id: d
323+ property bool enableIndexChangeSignal: true
324+ property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
325+ }
326+
327+ Connections {
328+ target: menuContent
329+ onCurrentMenuIndexChanged: {
330+ var oldActive = d.enableIndexChangeSignal;
331+ if (!oldActive) return;
332+ d.enableIndexChangeSignal = false;
333+
334+ indicatorRow.setCurrentItem(menuContent.currentMenuIndex);
335+
336+ d.enableIndexChangeSignal = oldActive;
337+ }
338+ }
339+
340+ Connections {
341+ target: indicatorRow
342+ onCurrentItemIndexChanged: {
343+ var oldActive = d.enableIndexChangeSignal;
344+ if (!oldActive) return;
345+ d.enableIndexChangeSignal = false;
346+
347+ menuContent.setCurrentMenuIndex(indicatorRow.currentItemIndex);
348+
349+ d.enableIndexChangeSignal = oldActive;
350+ }
351+ }
345352 // connections to the active drag handle
346353 Connections {
347− target: activeDragHandle
354+ target: d.activeDragHandle
348355 onTouchXChanged: {
349− indicators.calculateCurrentItem(activeDragHandle.touchX, true);
356+ indicators.calculateCurrentItem(d.activeDragHandle.touchX, true);
350357 }
351358 onTouchSceneYChanged: {
352− yVelocityCalculator.trackedPosition = activeDragHandle.touchSceneY;
359+ yVelocityCalculator.trackedPosition = d.activeDragHandle.touchSceneY;
353360 }
354361 }
355362
@@ -403,8 +410,8 @@ Showable {
403410 }
404411 StateChangeScript {
405412 script: {
406− if (activeDragHandle) {
407− calculateCurrentItem(activeDragHandle.touchX, false);
413+ if (d.activeDragHandle) {
414+ calculateCurrentItem(d.activeDragHandle.touchX, false);
408415 }
409416 }
410417 }
@@ -429,4 +436,9 @@ Showable {
429436 NumberAnimation {targets: [indicatorRow, menuContent]; property: "y"; duration: 300; easing.type: Easing.OutCubic}
430437 }
431438 ]
439+
440+ Component.onCompleted: initialise();
441+ function initialise() {
442+ indicatorsModel.load();
443+ }
432444}
qml/Panel/MenuContent.qml+2−2
@@ -39,10 +39,10 @@ MainView {
3939 height: units.gu(42)
4040
4141 function setCurrentMenuIndex(index) {
42− var filteredIndex = filteredIndicators.mapFromSource(index)
42+ var filteredIndex = filteredIndicators.mapFromSource(index);
4343
4444 if (tabs.selectedTabIndex !== filteredIndex) {
45− if (tabs.selectedTabIndex == -1 || !animateNextMenuChange) {
45+ if (tabs.selectedTabIndex === -1 || !animateNextMenuChange) {
4646 tabs.tabBar.animate = false;
4747 }
4848 tabs.selectedTabIndex = filteredIndex;
tests/mocks/Unity/Indicators/IndicatorsModel.qml+2−5
@@ -21,12 +21,9 @@ ListModel {
2121
2222 property var indicatorData : undefined
2323
24− function load() {}
24+ function load() {
25+ clear();
2526
26− // Need to do this dynamically.
27− // Apparently ListModels dont order roles visually when using ListElement
28− // which throws off the filter for non-visible indicators.
29− Component.onCompleted: {
3027 append({ "identifier": "indicator-fake1",
3128 "position": 0,
3229 "widgetSource": "qrc:/tests/indciators/qml/fake_menu_widget1.qml",
tests/mocks/Unity/Indicators/qml/fake_menu_widget2.qml+1−3
@@ -19,7 +19,5 @@ import QtQuick 2.0
1919Rectangle {
2020 width: 40
2121 height: 40
22− color : "yellow"
23−
24− enabled: false
22+ color : "blue"
2523}
tests/mocks/Unity/Indicators/qml/fake_menu_widget3.qml+1−1
@@ -19,5 +19,5 @@ import QtQuick 2.0
1919Rectangle {
2020 width: 40
2121 height: 40
22− color : "blue"
22+ color : "yellow"
2323}
tests/qmltests/Panel/tst_IndicatorRow.qml+2−1
@@ -32,6 +32,8 @@ Item {
3232
3333 function init_test()
3434 {
35+ indicatorModel.load();
36+
3537 indicatorRow.state = "initial";
3638 indicatorRow.currentItem = null;
3739 indicatorRow.unitProgress = 0.0;
@@ -53,7 +55,6 @@ Item {
5355
5456 Indicators.IndicatorsModel {
5557 id: indicatorModel
56− Component.onCompleted: load()
5758 }
5859
5960 UT.UnityTestCase {
tests/qmltests/Panel/tst_Indicators.qml+59−8
@@ -83,6 +83,8 @@ Item {
8383 when: windowShown
8484
8585 function init() {
86+ indicators.initialise();
87+
8688 indicators.hide();
8789 tryCompare(indicators.hideAnimation, "running", false);
8890 tryCompare(indicators, "state", "initial");
@@ -161,21 +163,70 @@ Item {
161163 compare(indicators.fullyOpened, true);
162164 }
163165
166+ function init_invisible_indicator(identifier) {
167+ tryCompareFunction(function() { return findChild(indicators, identifier+"-widget") !== null }, true);
168+ var item = findChild(indicators, identifier+"-widget");
169+
170+ item.enabled = false;
171+ }
172+
164173 function test_row_visible_menuContent_visible_data() { return [
165− {tag: "visible", index: 0, name: "indicator-fake1", visible: true },
166− {tag: "invisible", index: 1, name: "indicator-fake2", visible: false }]
174+ {tag: "first", visible: [false, true, true, true, true] },
175+ {tag: "adjacent", visible: [true, false, false, true, true] },
176+ {tag: "bounds", visible: [false, true, true, true, false] },
177+ {tag: "disjoint", visible: [true, false, true, false, true] },
178+ {tag: "last", visible: [true, true, true, true, false] }];
167179 }
168180
169181 function test_row_visible_menuContent_visible(data) {
182+
183+ indicators.show();
184+
170185 var indicatorTabs = findChild(indicators, "tabs");
171− var rowRepeater = findChild(indicators, "rowRepeater");
186+ var rowRepeater = findChild(indicators, "rowRepeater")
187+
188+
189+ for (var i = 0; i< data.visible.length; i++) {
190+ if (data.visible[i] === false)
191+ init_invisible_indicator("indicator-fake" + (i + 1));
192+ }
193+
194+ for (i = 0; i < data.visible.length; i++) {
195+ var shouldBeVisible = data.visible[i];
172196
173− var indicatorItem = rowRepeater.itemAt(data.index);
174− tryCompareFunction(function() { return indicatorItem.width > 0}, true);
175− tryCompare(indicatorItem, "visible", data.visible);
197+ // check item visibility
198+ var indicatorItem = rowRepeater.itemAt(i);
199+ tryCompare(indicatorItem, "visible", shouldBeVisible);
200+ // check tab visibility
201+ tryCompareFunction(function() { return findChild(indicatorTabs, "indicator-fake" + (i + 1)) !== null }, shouldBeVisible);
202+ }
203+ }
204+
205+ function test_indicator_visible_correct_tabs_data() { return [
206+ {tag: "current-first", currentIndex: 0, visible: [false, true, true, true, true], expected: 1 },
207+ {tag: "current-last", currentIndex: 4, visible: [true, true, true, true, false], expected: 3 },
208+ {tag: "after", currentIndex: 0, visible: [true, false, true, true, true], expected: 0 },
209+ {tag: "before", currentIndex: 1, visible: [false, true, true, true, true], expected: 1 }];
210+ }
211+
212+ function test_indicator_visible_correct_tabs(data) {
213+
214+ var indicatorTabs = findChild(indicators, "tabs");
215+ var indicatorRow = findChild(indicators, "indicatorRow");
216+
217+ indicators.show();
218+ indicatorRow.setCurrentItem(data.currentIndex);
219+ tryCompare(indicators, "fullyOpened", true);
220+
221+ for (var i = 0; i< data.visible.length; i++) {
222+ if (data.visible[i] === false)
223+ init_invisible_indicator("indicator-fake" + (i + 1));
224+ }
176225
177− var indicatorTab = findChild(indicatorTabs, data.name)
178− tryCompareFunction(function() { return indicatorTab !== null }, data.visible);
226+ // check for current selected item
227+ tryCompare(indicatorRow, "currentItemIndex", data.expected);
228+ // check for current selected tab
229+ tryCompareFunction(function() { return findChild(indicatorTabs, "indicator-fake" + (data.expected + 1)) === indicatorTabs.selectedTab }, true);
179230 }
180231 }
181232}
tests/qmltests/Panel/tst_MenuContent.qml+2−2
@@ -103,13 +103,13 @@ Item {
103103
104104 function selected_tab_equals_test_tab() {
105105 var currentTab = menu_content_test.findChild(menuContent, "tabs").selectedTab
106− if (currentTab == undefined) {
106+ if (currentTab === null) {
107107 console.log("selected tab undefined");
108108 return false;
109109 }
110110
111111 var testTab = menu_content_test.findChild(menuContent, testTabObjectName);
112− if (testTab == undefined) {
112+ if (testTab === null) {
113113 console.log("test_tab " + testTabObjectName + " undefined");
114114 return false;
115115 }
tests/qmltests/Panel/tst_Panel.qml+14−12
@@ -56,6 +56,8 @@ Item {
5656 }
5757
5858 function init() {
59+ panel.indicators.initialise();
60+
5961 searchClicked = false;
6062 panel.indicators.hide();
6163 tryCompare(panel.indicators.hideAnimation, "running", false);
@@ -64,16 +66,16 @@ Item {
6466
6567 function get_indicator_item(index) {
6668 var rowRepeater = findChild(panel.indicators, "rowRepeater");
67− verify(rowRepeater != undefined);
69+ verify(rowRepeater !== null);
6870 return rowRepeater.itemAt(index);
6971 }
7072
7173 function get_indicator_item_position(index) {
7274 var indicatorRow = findChild(panel.indicators, "indicatorRow");
73− verify(indicatorRow != undefined);
75+ verify(indicatorRow !== null);
7476
7577 var indicatorItem = get_indicator_item(index);
76− verify(indicatorItem != undefined);
78+ verify(indicatorItem !== null);
7779
7880 return panel.mapFromItem(indicatorItem, indicatorItem.width/2, indicatorItem.height/2);
7981 }
@@ -118,7 +120,7 @@ Item {
118120 // no hint animation when fullscreen
119121 compare(panel.indicators.y, -panel.panelHeight);
120122 var indicatorRow = findChild(panel.indicators, "indicatorRow");
121− verify(indicatorRow != undefined);
123+ verify(indicatorRow !== null);
122124 compare(indicatorRow.y, 0);
123125 compare(panel.indicators.height, panel.indicators.panelHeight);
124126 compare(panel.indicators.partiallyOpened, false,
@@ -143,13 +145,13 @@ Item {
143145 }
144146
145147 var indicatorRow = findChild(panel.indicators, "indicatorRow");
146− verify(indicatorRow != undefined);
148+ verify(indicatorRow !== null);
147149
148150 var rowRepeater = findChild(panel.indicators, "rowRepeater");
149− verify(indicatorRow != undefined);
151+ verify(indicatorRow !== null);
150152
151153 var menuContent = findChild(panel.indicators, "menuContent");
152− verify(indicatorRow != undefined);
154+ verify(indicatorRow !== null);
153155
154156 // Wait for the indicators to get into position.
155157 // (switches between normal and fullscreen modes are animated)
@@ -203,7 +205,7 @@ Item {
203205 panel.searchVisible = true;
204206
205207 var searchIndicator = findChild(panel, "search");
206− verify(searchIndicator != undefined);
208+ verify(searchIndicator !== null);
207209
208210 tap(searchIndicator, 1, 1);
209211
@@ -216,7 +218,7 @@ Item {
216218 panel.searchVisible = false;
217219
218220 var searchIndicator = findChild(panel, "search");
219− verify(searchIndicator != undefined);
221+ verify(searchIndicator !== null);
220222
221223 tap(searchIndicator, 1, 1);
222224
@@ -232,14 +234,14 @@ Item {
232234 panel.searchVisible = false;
233235
234236 var indicatorRow = findChild(panel.indicators, "indicatorRow");
235− verify(indicatorRow != undefined);
237+ verify(indicatorRow !== null);
236238
237239 var rowRepeater = findChild(panel.indicators, "rowRepeater");
238− verify(indicatorRow != undefined);
240+ verify(indicatorRow !== null);
239241
240242 // Get the first indicator
241243 var indicatorItemFirst = get_indicator_item(0);
242− verify(indicatorItemFirst != undefined);
244+ verify(indicatorItemFirst !== undefined);
243245
244246 var indicatorItemCoordFirst = get_indicator_item_position(0);
245247 var indicatorItemCoordNext = get_indicator_item_position(indicatorRow.count - 1);