on xenial help sign in
Fixed currentIndex indicator removal causing misalignment
commitea717a0b000090aee8f7fd628735436b782c8e9f authorNick Dedekind <nicholas.dedekind@gmail.com> dateMon 13 Jan 2014, 16:25 (13 years ago) parent1fd10cb
3 files changed+66−38
qml/Panel/IndicatorRow.qml+51−29 qml/Panel/Indicators.qml+13−3 qml/Panel/MenuContent.qml+2−6
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+13−3
@@ -193,7 +193,6 @@ Showable {
193193 clip: !indicators.fullyOpened
194194 activeHeader: indicators.state == "hint" || indicators.state == "reveal"
195195 enabled: contentEnabled
196− visibleIndicators: indicatorRow.visibleIndicators
197196
198197 //small shadow gradient at bottom of menu
199198 Rectangle {
@@ -249,8 +248,6 @@ Showable {
249248
250249 Indicators.IndicatorsModel {
251250 id: indicatorsModel
252−
253− Component.onCompleted: load()
254251 }
255252
256253 IndicatorRow {
@@ -265,6 +262,14 @@ Showable {
265262 state: indicators.state
266263 unitProgress: indicators.unitProgress
267264
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);
270+ }
271+ }
272+
268273 EdgeDragArea {
269274 id: rowDragArea
270275 anchors.fill: indicatorRow
@@ -431,4 +436,9 @@ Showable {
431436 NumberAnimation {targets: [indicatorRow, menuContent]; property: "y"; duration: 300; easing.type: Easing.OutCubic}
432437 }
433438 ]
439+
440+ Component.onCompleted: initialise();
441+ function initialise() {
442+ indicatorsModel.load();
443+ }
434444}
qml/Panel/MenuContent.qml+2−6
@@ -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;
@@ -74,10 +74,6 @@ MainView {
7474
7575 filterRole: Indicators.IndicatorsModelRole.IsVisible
7676 filterRegExp: RegExp("^true$")
77−
78− onDataChanged: tabs.selectedTabIndexChanged();
79− onRowsInserted: tabs.selectedTabIndexChanged();
80− onRowsRemoved: tabs.selectedTabIndexChanged();
8177 }
8278
8379 Indicators.VisibleIndicatorsModel {