on xenial help sign in
remove/add item fixes
c04db5aNick Dedekind
qml/Panel/IndicatorItemRow.qml+15−1
@@ -144,6 +144,21 @@ Item {
144 model: indicatorsModel
144 model: indicatorsModel
145 visible: false
145 visible: false
146
146
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+
147 delegate: IndicatorItem {
162 delegate: IndicatorItem {
148 id: item
163 id: item
149 objectName: identifier+"-panelItem"
164 objectName: identifier+"-panelItem"
@@ -185,7 +200,6 @@ Item {
185
200
186 // micromovements of the highlight line when user moves the finger across the items while pulling
201 // micromovements of the highlight line when user moves the finger across the items while pulling
187 // the handle downwards.
202 // the handle downwards.
188−
189 property real highlightCenterOffset: {
203 property real highlightCenterOffset: {
190 if (!currentItem || lateralPosition == -1 || !enableLateralChanges) return 0;
204 if (!currentItem || lateralPosition == -1 || !enableLateralChanges) return 0;
191
205
qml/Panel/IndicatorsBar.qml+49−13
@@ -21,6 +21,7 @@ import "../Components"
21Item {
21Item {
22 id: root
22 id: root
23 property alias expanded: row.expanded
23 property alias expanded: row.expanded
24+ property alias interactive: flickable.interactive
24 property alias indicatorsModel: row.indicatorsModel
25 property alias indicatorsModel: row.indicatorsModel
25 property alias unitProgress: row.unitProgress
26 property alias unitProgress: row.unitProgress
26 property alias enableLateralChanges: row.enableLateralChanges
27 property alias enableLateralChanges: row.enableLateralChanges
@@ -43,10 +44,6 @@ Item {
43 row.setCurrentItemIndex(index);
44 row.setCurrentItemIndex(index);
44 }
45 }
45
46
46− function alignIndicators() {
47− alignmentTimer.start();
48− }
49−
50 function addScrollOffset(scrollAmmout) {
47 function addScrollOffset(scrollAmmout) {
51 if (scrollAmmout < 0) { // left scroll
48 if (scrollAmmout < 0) { // left scroll
52 if (flickable.contentX < 0) return; // already off the left.
49 if (flickable.contentX < 0) return; // already off the left.
@@ -89,6 +86,23 @@ Item {
89 Behavior on alignmentAdjustment {
86 Behavior on alignmentAdjustment {
90 NumberAnimation { duration: UbuntuAnimation.BriskDuration; easing: UbuntuAnimation.StandardEasing}
87 NumberAnimation { duration: UbuntuAnimation.BriskDuration; easing: UbuntuAnimation.StandardEasing}
91 }
88 }
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+ }
92 }
106 }
93
107
94 Rectangle {
108 Rectangle {
@@ -113,10 +127,16 @@ Item {
113
127
114 anchors.fill: parent
128 anchors.fill: parent
115 contentWidth: row.width
129 contentWidth: row.width
116− interactive: root.expanded
130+ interactive: false
117 // align right + offset from row selection + scrolling
131 // align right + offset from row selection + scrolling
118 contentX: row.width - flickable.width - d.combinedOffset
132 contentX: row.width - flickable.width - d.combinedOffset
119
133
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+
120 rebound: Transition {
140 rebound: Transition {
121 NumberAnimation {
141 NumberAnimation {
122 properties: "x"
142 properties: "x"
@@ -150,7 +170,7 @@ Item {
150 enabled: root.expanded
170 enabled: root.expanded
151 onClicked: {
171 onClicked: {
152 row.selectItemAt(mouse.x);
172 row.selectItemAt(mouse.x);
153− alignIndicators();
173+ d.alignIndicators();
154 }
174 }
155 }
175 }
156 }
176 }
@@ -162,11 +182,8 @@ Item {
162 id: alignmentTimer
182 id: alignmentTimer
163 interval: UbuntuAnimation.FastDuration // enough for row animation.
183 interval: UbuntuAnimation.FastDuration // enough for row animation.
164 repeat: false
184 repeat: false
185+
165− onTriggered: {
186+ onTriggered: d.alignIndicators();
166− if (expanded && !flickable.moving && row.width > flickable.width && flickable.contentX < 0) { // off the left.
167− d.alignmentAdjustment += flickable.contentX;
168− }
169− }
170 }
187 }
171
188
172 states: [
189 states: [
@@ -178,18 +195,18 @@ Item {
178 rowOffset: 0
195 rowOffset: 0
179 scrollOffset: 0
196 scrollOffset: 0
180 alignmentAdjustment: 0
197 alignmentAdjustment: 0
198+ combinedOffset: 0
181 restoreEntryValues: false
199 restoreEntryValues: false
182 }
200 }
183 },
201 },
184 State {
202 State {
185 name: "expanded"
203 name: "expanded"
186− when: expanded
204+ when: expanded && !interactive
187
205
188 PropertyChanges {
206 PropertyChanges {
189 target: d
207 target: d
190 combinedOffset: rowOffset + alignmentAdjustment - scrollOffset
208 combinedOffset: rowOffset + alignmentAdjustment - scrollOffset
191 }
209 }
192−
193 PropertyChanges {
210 PropertyChanges {
194 target: d
211 target: d
195 rowOffset: {
212 rowOffset: {
@@ -202,6 +219,25 @@ Item {
202 restoreEntryValues: false
219 restoreEntryValues: false
203 }
220 }
204 }
221 }
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+ }
205 ]
241 ]
206
242
207 transitions: [
243 transitions: [
qml/Panel/IndicatorsMenu.qml+6−29
@@ -87,6 +87,7 @@ Showable {
87 indicatorsModel: root.indicatorsModel
87 indicatorsModel: root.indicatorsModel
88 visible: root.unitProgress > 0
88 visible: root.unitProgress > 0
89 enabled: contentEnabled
89 enabled: contentEnabled
90+ currentMenuIndex: bar.currentItemIndex
90 }
91 }
91
92
92 Handle {
93 Handle {
@@ -207,7 +208,6 @@ Showable {
207 onRunningChanged: {
208 onRunningChanged: {
208 if (showAnimation.running) {
209 if (showAnimation.running) {
209 root.state = "commit";
210 root.state = "commit";
210− bar.alignIndicators();
211 }
211 }
212 }
212 }
213 }
213 }
@@ -221,35 +221,8 @@ Showable {
221 }
221 }
222 }
222 }
223
223
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−
250 QtObject {
224 QtObject {
251 id: d
225 id: d
252− property bool enableIndexChangeSignal: true
253 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
226 property var activeDragHandle: showDragHandle.dragging ? showDragHandle : hideDragHandle.dragging ? hideDragHandle : null
254
227
255 property real rowMappedLateralPosition: {
228 property real rowMappedLateralPosition: {
@@ -301,7 +274,11 @@ Showable {
301 },
274 },
302 State {
275 State {
303 name: "commit"
276 name: "commit"
304− PropertyChanges { target: bar; expanded: true }
277+ PropertyChanges {
278+ target: bar
279+ expanded: true
280+ interactive: true
281+ }
305 }
282 }
306 ]
283 ]
307 state: "initial"
284 state: "initial"
qml/Panel/MenuContent.qml+8−5
@@ -26,16 +26,14 @@ Rectangle {
26 id: content
26 id: content
27
27
28 property QtObject indicatorsModel: null
28 property QtObject indicatorsModel: null
29− readonly property alias currentMenuIndex: listViewContent.currentIndex
29+ property int currentMenuIndex: -1
30 color: "#221e1c" // FIXME not in palette yet
30 color: "#221e1c" // FIXME not in palette yet
31
31
32 width: units.gu(40)
32 width: units.gu(40)
33 height: units.gu(42)
33 height: units.gu(42)
34
34
35− function setCurrentMenuIndex(index) {
35+ onCurrentMenuIndexChanged: {
36− // FIXME - https://bugreports.qt-project.org/browse/QTBUG-41229
37− listViewContent.currentIndex = -1;
36+ listViewContent.currentIndex = currentMenuIndex;
38− listViewContent.currentIndex = index;
39 }
37 }
40
38
41 Flickables.ListView {
39 Flickables.ListView {
@@ -52,6 +50,11 @@ Rectangle {
52 // Load all the indicator menus (a big number)
50 // Load all the indicator menus (a big number)
53 cacheBuffer: 1073741823
51 cacheBuffer: 1073741823
54
52
53+ // for additions/removals.
54+ onCountChanged: {
55+ listViewContent.currentIndex = content.currentMenuIndex;
56+ }
57+
55 delegate: Loader {
58 delegate: Loader {
56 id: loader
59 id: loader
57
60
tests/qmltests/Panel/tst_IndicatorItemRow.qml+1
@@ -66,6 +66,7 @@ IndicatorTest {
66 }
66 }
67 onPressed: {
67 onPressed: {
68 if (pressed) {
68 if (pressed) {
69+ indicatorsRow.lateralPosition = mouse.x;
69 indicatorsRow.selectItemAt(mouse.x);
70 indicatorsRow.selectItemAt(mouse.x);
70 }
71 }
71 }
72 }