on xenial help sign in
remove/add item fixes
commitc04db5a3018968c62a827743f75d147c25a0c30b authorNick Dedekind <nick.dedekind@canonical.com> dateWed 15 Oct 2014, 16:57 (12 years ago) parent5518725
5 files changed+79−48
qml/Panel/IndicatorItemRow.qml+15−1 qml/Panel/IndicatorsBar.qml+49−13 qml/Panel/IndicatorsMenu.qml+6−29 qml/Panel/MenuContent.qml+8−5 tests/qmltests/Panel/tst_IndicatorItemRow.qml+1
qml/Panel/IndicatorItemRow.qml+15−1
@@ -144,6 +144,21 @@ Item {
144144 model: indicatorsModel
145145 visible: false
146146
147+ onItemRemoved: {
148+ // current item removed.
149+ if (currentItem === item) {
150+ var i = 0;
151+ while (i < row.children.length) {
152+ var childItem = row.children[i];
153+ if (childItem !== item) {
154+ setCurrentItemIndex(i);
155+ break;
156+ }
157+ i++;
158+ }
159+ }
160+ }
161+
147162 delegate: IndicatorItem {
148163 id: item
149164 objectName: identifier+"-panelItem"
@@ -185,7 +200,6 @@ Item {
185200
186201 // micromovements of the highlight line when user moves the finger across the items while pulling
187202 // the handle downwards.
188−
189203 property real highlightCenterOffset: {
190204 if (!currentItem || lateralPosition == -1 || !enableLateralChanges) return 0;
191205
qml/Panel/IndicatorsBar.qml+49−13
@@ -21,6 +21,7 @@ import "../Components"
2121Item {
2222 id: root
2323 property alias expanded: row.expanded
24+ property alias interactive: flickable.interactive
2425 property alias indicatorsModel: row.indicatorsModel
2526 property alias unitProgress: row.unitProgress
2627 property alias enableLateralChanges: row.enableLateralChanges
@@ -43,10 +44,6 @@ Item {
4344 row.setCurrentItemIndex(index);
4445 }
4546
46− function alignIndicators() {
47− alignmentTimer.start();
48− }
49−
5047 function addScrollOffset(scrollAmmout) {
5148 if (scrollAmmout < 0) { // left scroll
5249 if (flickable.contentX < 0) return; // already off the left.
@@ -89,6 +86,23 @@ Item {
8986 Behavior on alignmentAdjustment {
9087 NumberAnimation { duration: UbuntuAnimation.BriskDuration; easing: UbuntuAnimation.StandardEasing}
9188 }
89+
90+ function alignIndicators() {
91+ flickable.resetContentXComponents();
92+
93+ if (expanded && !flickable.moving) {
94+ // gap between left and row?
95+ if (row.width > flickable.width && flickable.contentX < 0) {
96+ d.alignmentAdjustment += flickable.contentX;
97+ // current item overlap on left
98+ } else if (row.currentItem.x < flickable.contentX) {
99+ d.alignmentAdjustment -= (row.currentItem.x - flickable.contentX);
100+ // current item overlap on right
101+ } else if (row.currentItem.x + row.currentItem.width > flickable.contentX + flickable.width) {
102+ d.alignmentAdjustment -= ((row.currentItem.x + row.currentItem.width) - (flickable.contentX + flickable.width));
103+ }
104+ }
105+ }
92106 }
93107
94108 Rectangle {
@@ -113,10 +127,16 @@ Item {
113127
114128 anchors.fill: parent
115129 contentWidth: row.width
116− interactive: root.expanded
130+ interactive: false
117131 // align right + offset from row selection + scrolling
118132 contentX: row.width - flickable.width - d.combinedOffset
119133
134+ // contentX can change by user interaction as well as user offset changes
135+ // This function re-aligns the offsets so that the offsets match the contentX
136+ function resetContentXComponents() {
137+ d.scrollOffset += (flickable.contentX - (row.width - flickable.width - d.combinedOffset));
138+ }
139+
120140 rebound: Transition {
121141 NumberAnimation {
122142 properties: "x"
@@ -150,7 +170,7 @@ Item {
150170 enabled: root.expanded
151171 onClicked: {
152172 row.selectItemAt(mouse.x);
153− alignIndicators();
173+ d.alignIndicators();
154174 }
155175 }
156176 }
@@ -162,11 +182,8 @@ Item {
162182 id: alignmentTimer
163183 interval: UbuntuAnimation.FastDuration // enough for row animation.
164184 repeat: false
165− onTriggered: {
166− if (expanded && !flickable.moving && row.width > flickable.width && flickable.contentX < 0) { // off the left.
167− d.alignmentAdjustment += flickable.contentX;
168− }
169− }
185+
186+ onTriggered: d.alignIndicators();
170187 }
171188
172189 states: [
@@ -178,18 +195,18 @@ Item {
178195 rowOffset: 0
179196 scrollOffset: 0
180197 alignmentAdjustment: 0
198+ combinedOffset: 0
181199 restoreEntryValues: false
182200 }
183201 },
184202 State {
185203 name: "expanded"
186− when: expanded
204+ when: expanded && !interactive
187205
188206 PropertyChanges {
189207 target: d
190208 combinedOffset: rowOffset + alignmentAdjustment - scrollOffset
191209 }
192−
193210 PropertyChanges {
194211 target: d
195212 rowOffset: {
@@ -202,6 +219,25 @@ Item {
202219 restoreEntryValues: false
203220 }
204221 }
222+ , State {
223+ name: "interactive"
224+ when: expanded && interactive
225+
226+ StateChangeScript {
227+ script: {
228+ // don't use row offset anymore.
229+ d.scrollOffset -= d.rowOffset;
230+ d.rowOffset = 0;
231+ d.initialItem = undefined;
232+ alignmentTimer.start();
233+ }
234+ }
235+ PropertyChanges {
236+ target: d
237+ combinedOffset: rowOffset + alignmentAdjustment - scrollOffset
238+ restoreEntryValues: false
239+ }
240+ }
205241 ]
206242
207243 transitions: [
qml/Panel/IndicatorsMenu.qml+6−29
@@ -87,6 +87,7 @@ Showable {
8787 indicatorsModel: root.indicatorsModel
8888 visible: root.unitProgress > 0
8989 enabled: contentEnabled
90+ currentMenuIndex: bar.currentItemIndex
9091 }
9192
9293 Handle {
@@ -207,7 +208,6 @@ Showable {
207208 onRunningChanged: {
208209 if (showAnimation.running) {
209210 root.state = "commit";
210− bar.alignIndicators();
211211 }
212212 }
213213 }
@@ -221,35 +221,8 @@ Showable {
221221 }
222222 }
223223
224− Connections {
225− target: content
226− onCurrentMenuIndexChanged: {
227− var oldActive = d.enableIndexChangeSignal;
228− if (!oldActive) return;
229− d.enableIndexChangeSignal = false;
230−
231− bar.setCurrentItemIndex(content.currentMenuIndex);
232−
233− d.enableIndexChangeSignal = oldActive;
234− }
235− }
236−
237− Connections {
238− target: bar
239− onCurrentItemIndexChanged: {
240− var oldActive = d.enableIndexChangeSignal;
241− if (!oldActive) return;
242− d.enableIndexChangeSignal = false;
243−
244− content.setCurrentMenuIndex(bar.currentItemIndex);
245−
246− d.enableIndexChangeSignal = oldActive;
247− }
248− }
249−
250224 QtObject {
251225 id: d
252− property bool enableIndexChangeSignal: true
253226 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
254227
255228 property real rowMappedLateralPosition: {
@@ -301,7 +274,11 @@ Showable {
301274 },
302275 State {
303276 name: "commit"
304− PropertyChanges { target: bar; expanded: true }
277+ PropertyChanges {
278+ target: bar
279+ expanded: true
280+ interactive: true
281+ }
305282 }
306283 ]
307284 state: "initial"
qml/Panel/MenuContent.qml+8−5
@@ -26,16 +26,14 @@ Rectangle {
2626 id: content
2727
2828 property QtObject indicatorsModel: null
29− readonly property alias currentMenuIndex: listViewContent.currentIndex
29+ property int currentMenuIndex: -1
3030 color: "#221e1c" // FIXME not in palette yet
3131
3232 width: units.gu(40)
3333 height: units.gu(42)
3434
35− function setCurrentMenuIndex(index) {
36− // FIXME - https://bugreports.qt-project.org/browse/QTBUG-41229
37− listViewContent.currentIndex = -1;
38− listViewContent.currentIndex = index;
35+ onCurrentMenuIndexChanged: {
36+ listViewContent.currentIndex = currentMenuIndex;
3937 }
4038
4139 Flickables.ListView {
@@ -52,6 +50,11 @@ Rectangle {
5250 // Load all the indicator menus (a big number)
5351 cacheBuffer: 1073741823
5452
53+ // for additions/removals.
54+ onCountChanged: {
55+ listViewContent.currentIndex = content.currentMenuIndex;
56+ }
57+
5558 delegate: Loader {
5659 id: loader
5760
tests/qmltests/Panel/tst_IndicatorItemRow.qml+1
@@ -66,6 +66,7 @@ IndicatorTest {
6666 }
6767 onPressed: {
6868 if (pressed) {
69+ indicatorsRow.lateralPosition = mouse.x;
6970 indicatorsRow.selectItemAt(mouse.x);
7071 }
7172 }