@@ -50,25 +50,21 @@ Item {
5050 row.setCurrentItemIndex(index);
5151 }
5252
53− function alignIndicatorsToLeft() {
54− alignmentTimer.start()
53+ function alignIndicators() {
54+ alignmentTimer.start();
5555 }
5656
5757 function addScrollOffset(scrollAmmout) {
58− var proposedScrollOffset = d.scrollOffset + scrollAmmout;
59− var proposedCombinedOffset = d.combinedOffset - scrollAmmout;
60−
61− if (scrollAmmout < 0 && d.combinedOffset > (row.width - rowContainer.width)) return;
62−
63− if (scrollAmmout > 0 && proposedCombinedOffset < 0) {
64− // get the combined offset back to 0
65− proposedScrollOffset = proposedScrollOffset + proposedCombinedOffset;
66− } else if (scrollAmmout < 0 && proposedCombinedOffset > row.width - rowContainer.width) {
67− // get the combined offset back to max
68− proposedScrollOffset = proposedScrollOffset + (proposedCombinedOffset - (row.width - rowContainer.width));
58+ if (scrollAmmout < 0) { // left scroll
59+ if (flickable.contentX < 0) return; // already off the left.
60+ if (flickable.contentX + scrollAmmout < 0) scrollAmmout = -flickable.contentX; // going to be off the left
61+ } else { // right scroll
62+ if (flickable.contentX + flickable.width > row.width) return; // already off the right.
63+ if (flickable.contentX + flickable.width + scrollAmmout > row.width) { // going to be off the right
64+ scrollAmmout = row.width - (flickable.contentX + flickable.width);
65+ }
6966 }
70−
71− d.scrollOffset = proposedScrollOffset;
67+ d.scrollOffset = d.scrollOffset + scrollAmmout;
7268 }
7369
7470 QtObject {
@@ -76,7 +72,6 @@ Item {
7672 property var initialItem
7773 // the non-expanded distance from row offset to center of initial item
7874 property real originalDistanceFromRight: -1
79− property real originalItemWidth: -1
8075
8176 // calculate the distance from row offset to center of initial item
8277 property real distanceFromRight: {
@@ -87,37 +82,19 @@ Item {
8782
8883 // offset to the intially selected expanded item
8984 property real rowOffset: 0
90− property real alignmentAdjustment: 0
9185 property real scrollOffset: 0
92− property real combinedOffset: rowOffset + alignmentAdjustment - scrollOffset
86+ property real alignmentAdjustment: 0
87+ property real combinedOffset: 0
9388
9489 // when the scroll offset changes, we need to reclaculate the relative lateral position
9590 onScrollOffsetChanged: root.lateralPositionChanged()
9691
9792 onInitialItemChanged: {
98− if (initialItem) {
99− originalItemWidth = initialItem.width;
100− originalDistanceFromRight = row.width - initialItem.x - initialItem.width/2;
101− } else {
102− originalItemWidth = -1;
103− originalDistanceFromRight = -1;
104− }
93+ originalDistanceFromRight = initialItem ? (row.width - initialItem.x - initialItem.width/2) : -1;
10594 }
10695
10796 Behavior on alignmentAdjustment {
108− NumberAnimation { duration: UbuntuAnimation.SnapDuration; easing: UbuntuAnimation.StandardEasing}
109− }
110− }
111−
112− onExpandedChanged: {
113− if (!expanded) flickable.moved = false;
114− }
115−
116− Connections {
117− target: row
118− onCurrentItemChanged: {
119− if (!row.currentItem) d.initialItem = undefined;
120− else if (!d.initialItem) d.initialItem = row.currentItem;
97+ NumberAnimation { duration: UbuntuAnimation.BriskDuration; easing: UbuntuAnimation.StandardEasing}
12198 }
12299 }
123100
@@ -137,34 +114,15 @@ Item {
137114 anchors.fill: parent
138115 clip: expanded || row.width > rowContainer.width
139116
140− IndicatorItemRow {
141− id: row
142− objectName: "indicatorItemRow"
143− anchors {
144− top: parent.top
145− bottom: parent.bottom
146− right: parent.right
147− rightMargin: -d.combinedOffset
148− }
149−
150− lateralPosition: {
151− if (root.lateralPosition == -1) return -1;
152−
153− var mapped = root.mapToItem(row, root.lateralPosition, 0);
154− return Math.min(Math.max(mapped.x, 0), row.width);
155− }
156− }
157−
158117 Flickable {
159118 id: flickable
119+ objectName: "flickable"
120+
160121 anchors.fill: parent
161122 contentWidth: row.width
162123 interactive: root.expanded
163−
164− property bool moved: false
165− onMovingChanged: {
166− moved = true;
167− }
124+ // align right + offset from row selection + scrolling
125+ contentX: row.width - flickable.width - d.combinedOffset
168126
169127 rebound: Transition {
170128 NumberAnimation {
@@ -174,21 +132,46 @@ Item {
174132 }
175133 }
176134
177− MouseArea {
178− anchors.fill: parent
179− enabled: root.expanded
180− onClicked: row.selectItemAt(mouse.x);
135+ IndicatorItemRow {
136+ id: row
137+ objectName: "indicatorItemRow"
138+ anchors {
139+ top: parent.top
140+ bottom: parent.bottom
141+ }
142+
143+ lateralPosition: {
144+ if (root.lateralPosition == -1) return -1;
145+
146+ var mapped = root.mapToItem(row, root.lateralPosition, 0);
147+ return Math.min(Math.max(mapped.x, 0), row.width);
148+ }
149+
150+ onCurrentItemChanged: {
151+ if (!currentItem) d.initialItem = undefined;
152+ else if (!d.initialItem) d.initialItem = currentItem;
153+ }
154+
155+ MouseArea {
156+ anchors.fill: parent
157+ enabled: root.expanded
158+ onClicked: {
159+ row.selectItemAt(mouse.x);
160+ alignIndicators();
161+ }
162+ }
181163 }
164+
182165 }
183166 }
184167
185168 Timer {
186169 id: alignmentTimer
187− interval: UbuntuAnimation.SnapDuration // enough for row animation.
170+ interval: UbuntuAnimation.FastDuration // enough for row animation.
188171 repeat: false
189172 onTriggered: {
190− if (expanded && row.x > 0) {
191− d.alignmentAdjustment = -row.x;
173+ if (expanded && !flickable.moving && row.width > flickable.width && flickable.contentX < 0) { // off the left.
174+ d.alignmentAdjustment += flickable.contentX;
192175 }
193176 }
194177 }
@@ -200,14 +183,19 @@ Item {
200183 PropertyChanges {
201184 target: d
202185 rowOffset: 0
203− alignmentAdjustment: 0
204186 scrollOffset: 0
187+ alignmentAdjustment: 0
205188 restoreEntryValues: false
206189 }
207190 },
208191 State {
209192 name: "expanded"
210− when: expanded && !flickable.moved
193+ when: expanded
194+
195+ PropertyChanges {
196+ target: d
197+ combinedOffset: rowOffset + alignmentAdjustment - scrollOffset
198+ }
211199
212200 PropertyChanges {
213201 target: d
@@ -216,34 +204,10 @@ Item {
216204 if (distanceFromRight - initialItem.width <= 0) return 0;
217205
218206 var rowOffset = distanceFromRight - originalDistanceFromRight;
219− if (originalDistanceFromRight + originalItemWidth/2 > rowContainer.width) {
220− rowOffset = rowOffset + originalItemWidth;
221− }
222207 return rowOffset;
223208 }
224− }
225− // keep flickable inline with row
226− PropertyChanges {
227− target: flickable
228− contentX: (flickable.contentWidth - flickable.width) - d.combinedOffset
229209 restoreEntryValues: false
230210 }
231− },
232− State {
233− name: "moved"
234− when: expanded && flickable.moved
235−
236− StateChangeScript {
237− script: {
238− // unbind contentX
239− flickable.contentX = flickable.contentX;
240− d.scrollOffset = 0;
241− }
242− }
243− PropertyChanges {
244− target: row
245− anchors.rightMargin: - (flickable.contentWidth - flickable.width) + (flickable.contentX) + d.scrollOffset
246− }
247211 }
248212 ]
249213
@@ -251,25 +215,17 @@ Item {
251215 Transition {
252216 from: "expanded"
253217 to: "minimized"
218+ PropertyAction {
219+ target: d
220+ properties: "rowOffset, scrollOffset, alignmentAdjustment"
221+ value: 0
222+ }
254223 PropertyAnimation {
255− target: d;
256− properties: "rowOffset, scrollOffset"
224+ target: d
225+ properties: "combinedOffset"
257226 duration: UbuntuAnimation.SnapDuration
258227 easing: UbuntuAnimation.StandardEasing
259228 }
260− },
261− Transition {
262− from: "moved"
263− to: "minimized"
264− SequentialAnimation {
265− PropertyAction { target: d; properties: "rowOffset, alignmentAdjustment, scrollOffset" }
266− PropertyAnimation {
267− target: row;
268− properties: "anchors.rightMargin"
269− duration: UbuntuAnimation.SnapDuration
270− easing: UbuntuAnimation.StandardEasing
271− }
272− }
273229 }
274230 ]
275231}