on xenial help sign in
code improvements
1d3b58eMichael Zanetti
qml/Stages/PhoneStage.qml+27−27
@@ -206,10 +206,10 @@ Item {
206 if (dragging && !priv.waitingForScreenshot && attachedToView) {
206 if (dragging && !priv.waitingForScreenshot && attachedToView) {
207 spreadView.contentX = -touchX
207 spreadView.contentX = -touchX
208 }
208 }
209−// if (attachedToView && spreadView.contentX >= spreadView.width * spreadView.positionMarker3) {
209+ if (attachedToView && spreadView.contentX >= spreadView.width * spreadView.positionMarker3) {
210−// attachedToView = false;
210+ attachedToView = false;
211−// spreadView.snap();
211+ spreadView.snap();
212−// }
212+ }
213 }
213 }
214
214
215 onDraggingChanged: {
215 onDraggingChanged: {
@@ -240,10 +240,10 @@ Item {
240
240
241 property int tileDistance: width / 4
241 property int tileDistance: width / 4
242
242
243− property real positionMarker1: 0.25
243+ property real positionMarker1: 0.35
244− property real positionMarker2: 0.5
244+ property real positionMarker2: 0.45
245− property real positionMarker3: 0.7
245+ property real positionMarker3: 0.6
246− property real positionMarker4: 1.25
246+ property real positionMarker4: .9
247
247
248 // This is where the first app snaps to when bringing it in to the right.
248 // This is where the first app snaps to when bringing it in to the right.
249 property real snapPosition: 0.75
249 property real snapPosition: 0.75
@@ -279,9 +279,11 @@ Item {
279 } else if (contentX < positionMarker2 * width) {
279 } else if (contentX < positionMarker2 * width) {
280 snapTo(1)
280 snapTo(1)
281 } else if (contentX < positionMarker3 * width) {
281 } else if (contentX < positionMarker3 * width) {
282+ print("snappoing to stage1")
282 snapAnimation.targetContentX = width * positionMarker2 + 1;
283 snapAnimation.targetContentX = width * positionMarker2 + 1;
283 snapAnimation.start();
284 snapAnimation.start();
284 } else if (stage < 2){
285 } else if (stage < 2){
286+ print("snappoing to stage2")
285 snapAnimation.targetContentX = width * positionMarker4;
287 snapAnimation.targetContentX = width * positionMarker4;
286 snapAnimation.start();
288 snapAnimation.start();
287 }
289 }
@@ -312,18 +314,21 @@ Item {
312 snapAnimation.toIndex = -1;
314 snapAnimation.toIndex = -1;
313 spreadView.contentX = 0;
315 spreadView.contentX = 0;
314 }
316 }
315− if (spreadView.stage == 1) {
317+ if (spreadView.contentX == spreadView.width * spreadView.positionMarker2) {
316 spreadView.stage = 0;
318 spreadView.stage = 0;
317 spreadView.contentX = 0;
319 spreadView.contentX = 0;
318 }
320 }
321+ print("snapping done. stage:", spreadView.stage)
319 }
322 }
320 }
323 }
321 }
324 }
322
325
323
326
324− Row {
327+ Item {
325 id: spreadRow
328 id: spreadRow
326− width: implicitWidth + (spreadView.width * spreadView.positionMarker2) + (spreadView.width - spreadView.tileDistance)
329+ width: ApplicationManager.count * spreadView.tileDistance + (spreadView.width - spreadView.tileDistance) * 1.5 //(spreadView.width * spreadView.positionMarker2) + (spreadView.width - spreadView.tileDistance)
330+
331+ x: spreadView.contentX
327
332
328 Repeater {
333 Repeater {
329 model: ApplicationManager
334 model: ApplicationManager
@@ -334,16 +339,18 @@ Item {
334 endScale: 0.7
339 endScale: 0.7
335 startDistance: spreadView.tileDistance
340 startDistance: spreadView.tileDistance
336 endDistance: units.gu(.5)
341 endDistance: units.gu(.5)
342+ height: spreadView.height
337
343
338 z: index
344 z: index
339− height: spreadView.height
345+ x: index == 0 ? 0 : spreadView.width + (index - 1) * spreadView.tileDistance
346+
340 width: {
347 width: {
341 switch (index) {
348 switch (index) {
342 case 0:
349 case 0:
343 return spreadView.width;
350 return spreadView.width;
344 case 1:
351 case 1:
345 if (spreadView.stage == 0) {
352 if (spreadView.stage == 0) {
346− return spreadView.width / 2;
353+ return spreadView.width * spreadView.positionMarker2;
347 }
354 }
348 default:
355 default:
349 return spreadView.tileDistance;
356 return spreadView.tileDistance;
@@ -353,30 +360,25 @@ Item {
353 progress: {
360 progress: {
354 switch (index) {
361 switch (index) {
355 case 0:
362 case 0:
356− var progress = spreadView.contentX / spreadView.width;
363+ return spreadView.contentX / spreadView.width;
357− if (spreadView.stage == 2) {
358− progress -= spreadView.positionMarker1;
359− }
360−
361− return progress;
362 case 1:
364 case 1:
363 var progress = spreadView.contentX / spreadView.width;
365 var progress = spreadView.contentX / spreadView.width;
364− if (spreadView.stage != 0) {
366+ if (spreadView.stage == 2) {
365− progress -= spreadView.positionMarker2;
367+ progress -= spreadView.tileDistance / spreadView.width;
366 }
368 }
367−
368 return Math.max(0, progress);
369 return Math.max(0, progress);
369 }
370 }
371+ // This delays the progress for all tiles > 1 for the duration of stage 1
370− return (spreadView.contentX - (spreadView.positionMarker2 * spreadView.width) - spreadView.tileDistance * (index - 1)) / spreadView.width;
372+ var stage1Distance = spreadView.positionMarker2 * spreadView.width;
373+ var tileDistance = (index - 2) * spreadView.tileDistance;
374+ return (spreadView.contentX - stage1Distance - tileDistance) / spreadView.width;
371 }
375 }
372
376
373 animatedProgress: {
377 animatedProgress: {
374 if (spreadView.stage < 2 && index < 2) {
378 if (spreadView.stage < 2 && index < 2) {
375 if (spreadView.contentX < spreadView.width * spreadView.positionMarker1) {
379 if (spreadView.contentX < spreadView.width * spreadView.positionMarker1) {
376− if (index == 0) print("*********************", spreadView.contentX / spreadView.width)
377 return spreadView.contentX / spreadView.width
380 return spreadView.contentX / spreadView.width
378 } else if (spreadView.stage == 0){
381 } else if (spreadView.stage == 0){
379− if (index == 0) print("!!!!!!!!!!!!!!!11!", spreadView.positionMarker2)
380 return spreadView.positionMarker2
382 return spreadView.positionMarker2
381 }
383 }
382 }
384 }
@@ -393,10 +395,8 @@ Item {
393 target: spreadView
395 target: spreadView
394 onStageChanged: {
396 onStageChanged: {
395 if (spreadView.stage == 0) {
397 if (spreadView.stage == 0) {
396− print("************************ enabling")
397 enableAnimationTimer.start();
398 enableAnimationTimer.start();
398 } else {
399 } else {
399− print("************************ disabling")
400 stage1Animation.enabled = false;
400 stage1Animation.enabled = false;
401 }
401 }
402 }
402 }
qml/Stages/TransformedSpreadDelegate.qml+39−113
@@ -6,7 +6,6 @@ SpreadDelegate {
6 id: root
6 id: root
7
7
8 property real progress: 0
8 property real progress: 0
9−// onProgressChanged: if (index == 0) print("tile", index, "progress changed:", progress)
10 property real animatedProgress: 0
9 property real animatedProgress: 0
11
10
12 property real startAngle: 0
11 property real startAngle: 0
@@ -46,83 +45,52 @@ SpreadDelegate {
46
45
47 property real negativeProgress: (index - 1) * spreadView.positionMarker1
46 property real negativeProgress: (index - 1) * spreadView.positionMarker1
48
47
48+ function linearAnimation(startProgress, endProgress, startValue, endValue, progress) {
49+ // progress : progressDiff = value : valueDiff
50+ return (progress - startProgress) * (endValue - startValue) / (endProgress - startProgress) + startValue;
51+ }
52+
53+ function easingAnimation(startProgress, endProgress, startValue, endValue, progress) {
54+ helperEasingCurve.progress = progress - startProgress;
55+ helperEasingCurve.period = endProgress - startProgress;
56+ return helperEasingCurve.value * (endValue - startValue) + startValue;
57+ }
49
58
50 property real xTranslate: {
59 property real xTranslate: {
51 var translation = 0;
60 var translation = 0;
52 switch (index) {
61 switch (index) {
53 case 0:
62 case 0:
54 if (spreadView.stage == 0) {
63 if (spreadView.stage == 0) {
55− // Need to compensate the flickable movement (fixing first tile at the left edge)
64+ translation = linearAnimation(0, spreadView.positionMarker2, 0, -spreadView.width * .25, root.animatedProgress)
56− var compensation = root.progress * spreadView.width
57−
58− // Calculating the small movement of the first tile
59− var progress = root.animatedProgress
60− var progressDiff = spreadView.positionMarker2
61− var translateDiff = -spreadView.width * 0.25
62− // progress : progressDiff = translate : translateDiff
63− var movement = progress * translateDiff / progressDiff
64−
65− translation = compensation + movement;
66 } else if (spreadView.stage == 1){
65 } else if (spreadView.stage == 1){
67− // Need to compensate the flickable movement (fixing first tile at the left edge)
66+ // find where the main easing would be when reaching stage 2
68− var compensation = spreadView.contentX - spreadRow.x
67+ var targetTranslate = easingAnimation(0, spreadView.positionMarker4, 0, -spreadView.width, spreadView.positionMarker4) + spreadView.width
69−
68+ translation = linearAnimation(spreadView.positionMarker2, spreadView.positionMarker4, -spreadView.width * .25, targetTranslate, root.progress)
70− // When we start, we need to continue from where state 0 left
71− var stage0Movement = -spreadView.width * 0.25
72−
73− var progress = root.progress - spreadView.positionMarker2
74− var progressDiff = spreadView.positionMarker4 - spreadView.positionMarker2
75− var translateDiff = -stage0Movement;
76−
77− var movement = progress * translateDiff / progressDiff
78−
79− translation = compensation + stage0Movement + movement;
80 } else { // Stage 2
69 } else { // Stage 2
81− // Move the first tile a bit to the left to be aligned with the others
70+// // Move the first tile a bit to the right to be aligned with the others
82− translation += spreadView.contentX - spreadRow.x + spreadView.width
71+ translation += spreadView.width
83 // apply the same animation as with the rest
72 // apply the same animation as with the rest
84 translation += -easingCurve.value * spreadView.width
73 translation += -easingCurve.value * spreadView.width
85 }
74 }
86 break;
75 break;
87 case 1:
76 case 1:
88 if (spreadView.stage == 0) {
77 if (spreadView.stage == 0) {
89− // Need to compensate the flickable movement (fix it to the right edge)
90− var compensation = root.progress * spreadView.width
91−
92− // Calculate movemoent for the first app coming from the right
93− var progress = root.animatedProgress
94− var progressDiff = spreadView.positionMarker2
95− var translateDiff = -spreadView.width * spreadView.snapPosition
78+ translation = linearAnimation(0, spreadView.positionMarker2, 0, -spreadView.width * spreadView.snapPosition, root.animatedProgress)
96− // progress : progressDiff = translate : translateDiff
97− var movement = progress * translateDiff / progressDiff
98−
99− translation = compensation + movement;
100 break;
79 break;
101 } else if (spreadView.stage == 1) {
80 } else if (spreadView.stage == 1) {
102− // Need to compensate the flickable movement (fix it to the right edge)
103− var compensation = root.progress * spreadView.width + spreadView.width/2
104−
105− // Add where stage 0 has moved it to
106− var stage0Movement = -spreadView.width * spreadView.snapPosition;
107−
108− // Calclulate animation between stage0Movement and targetTranslate
109− var progress = root.progress
110− var progressDiff = spreadView.positionMarker4 - spreadView.positionMarker2
111−
112− // find where the main easing would be when reaching positionMarker4
81+// // find where the main easing would be when reaching stage 2
113− helperEasingCurve.progress = progressDiff;
82+ var stage2Progress = spreadView.positionMarker4 - spreadView.tileDistance / spreadView.width;
114− var targetTranslate = -helperEasingCurve.value * spreadView.width + root.endDistance
83+ targetTranslate = easingAnimation(0, stage2Progress, 0, -spreadView.width + root.endDistance, stage2Progress);
115
84
116− var translateDiff = targetTranslate - stage0Movement;
85+ translation = linearAnimation(spreadView.positionMarker2, spreadView.positionMarker4,
117− var movement = progress * translateDiff / progressDiff
86+ -spreadView.width * spreadView.snapPosition, targetTranslate, root.progress);
118
87
119− translation = compensation + stage0Movement + movement;
120 break;
88 break;
121 }
89 }
122
90
123 default:
91 default:
124− // Fix it at the right edge...
92+// // Fix it at the right edge...
125− translation += spreadView.contentX - spreadRow.x - ((index - 1) * root.startDistance)
93+ translation += -((index - 1) * root.startDistance)
126 // ...and use our easing to move them to the left. Stop a bit earlier for each tile
94 // ...and use our easing to move them to the left. Stop a bit earlier for each tile
127 translation += -easingCurve.value * spreadView.width + (index * root.endDistance)
95 translation += -easingCurve.value * spreadView.width + (index * root.endDistance)
128 if (isSelected) {
96 if (isSelected) {
@@ -149,44 +117,22 @@ SpreadDelegate {
149 switch (index) {
117 switch (index) {
150 case 0:
118 case 0:
151 if (spreadView.stage == 0) {
119 if (spreadView.stage == 0) {
152− var progress = root.animatedProgress;
153− var progressDiff = spreadView.positionMarker2;
154− var angleDiff = root.endAngle * spreadView.snapPosition;
120+ newAngle = linearAnimation(0, spreadView.positionMarker2, 0, root.endAngle * spreadView.snapPosition, root.animatedProgress)
155− // progress : progressDiff = angle : angleDiff
156− newAngle = progress * angleDiff / progressDiff;
157 break;
121 break;
158 } else if (spreadView.stage == 1) {
122 } else if (spreadView.stage == 1) {
159− var stage0Angle = root.endAngle * spreadView.snapPosition;
123+ newAngle = linearAnimation(spreadView.positionMarker2, spreadView.positionMarker4, root.endAngle * spreadView.snapPosition, root.endAngle, root.progress)
160−
161− var progress = root.progress - spreadView.positionMarker2;
162− var angleDiff = root.endAngle;
163− var progressDiff = 1 - spreadView.positionMarker2;
164− var angleTransform = progress * angleDiff / progressDiff;
165− newAngle = stage0Angle + angleTransform;
166− newAngle = Math.min(root.endAngle, newAngle);
167 break;
124 break;
168 }
125 }
169 case 1:
126 case 1:
170 if (spreadView.stage == 0) {
127 if (spreadView.stage == 0) {
171− var progress = root.animatedProgress;
128+ newAngle = linearAnimation(0, spreadView.positionMarker2, root.startAngle, root.startAngle * (1-spreadView.snapPosition), root.animatedProgress)
172− var progressDiff = spreadView.positionMarker2;
173− var angleDiff = root.startAngle * spreadView.snapPosition
174−
175− // progress : progressDiff = angle : angleDiff
176− var angleTranslate = progress * angleDiff / progressDiff;
177−
178− newAngle = root.startAngle - angleTranslate;
179 break;
129 break;
180 } else if (spreadView.stage == 1) {
130 } else if (spreadView.stage == 1) {
181− var stage0Angle = root.startAngle - (root.startAngle * spreadView.snapPosition)
131+ // find where the main easing would be when reaching stage 2
182−
183− var progress = root.progress
184− var progressDiff = spreadView.positionMarker4 - spreadView.positionMarker2
132+ helperEasingCurve.progress = spreadView.positionMarker4 - spreadView.tileDistance / spreadView.width;
185− var angleDiff = root.endAngle - stage0Angle;
133+ var targetAngle = root.startAngle - helperEasingCurve.value * (root.startAngle - root.endAngle)
186
134
187− // progress : progressDiff = angle : angleDiff
135+ newAngle = linearAnimation(spreadView.positionMarker2, spreadView.positionMarker4, root.startAngle * (1-spreadView.snapPosition), targetAngle, root.progress)
188− var angleTranslate = progress * angleDiff / progressDiff;
189− newAngle = stage0Angle + angleTranslate;
190 break;
136 break;
191 }
137 }
192
138
@@ -213,40 +159,20 @@ SpreadDelegate {
213 newScale = 1;
159 newScale = 1;
214 break
160 break
215 } else if(spreadView.stage == 1) {
161 } else if(spreadView.stage == 1) {
216− var progress = root.progress - spreadView.positionMarker2
162+ newScale = linearAnimation(spreadView.positionMarker2, spreadView.positionMarker4, 1, root.endScale, root.progress)
217− var progressDiff = spreadView.positionMarker4 - spreadView.positionMarker2
218− var scaleDiff = 1 - root.endScale;
219− // progress : progressDiff = angle : angleDiff
220− newScale = 1 - (progress * scaleDiff / progressDiff);
221 break;
163 break;
222 }
164 }
223 case 1:
165 case 1:
224 if (spreadView.stage == 0) {
166 if (spreadView.stage == 0) {
225− var progress = root.animatedProgress;
167+ newScale = linearAnimation(0, spreadView.positionMarker2, root.tile1StartScale, 1, root.animatedProgress)
226− var progressDiff = spreadView.positionMarker2;
227− var scaleDiff = (root.tile1StartScale - 1) * spreadView.snapPosition
228−
229− // progress : progressDiff = angle : angleDiff
230− var scaleTranslate = progress * scaleDiff / progressDiff;
231−
232− newScale = root.tile1StartScale - scaleTranslate;
233 break;
168 break;
234 } else if (spreadView.stage == 1) {
169 } else if (spreadView.stage == 1) {
235− var stage0Scale = root.tile1StartScale - (root.tile1StartScale - 1) * spreadView.snapPosition
236−
237− var progress = root.progress
238− var progressDiff = spreadView.positionMarker4 - spreadView.positionMarker2
239−
240− // find where the main easing would be when reaching positionMarker4
170+// // find where the main easing would be when reaching positionMarker4
241− helperEasingCurve.progress = progressDiff;
171+// helperEasingCurve.progress = spreadView.positionMarker4;
242− var targetScale = root.startScale - helperEasingCurve.value * (root.startScale - root.endScale)
172+// var targetScale = root.startScale - helperEasingCurve.value * (root.startScale - root.endScale)
243−
173+ var targetScale = easingAnimation(0, spreadView.positionMarker4, root.startScale, root.endScale, spreadView.positionMarker4);
244− var scaleDiff = stage0Scale - targetScale;
174+ newScale = linearAnimation(spreadView.positionMarker2, spreadView.positionMarker4, 1, targetScale, root.progress)
245−
175+ break;
246− // progress : progressDiff = angle : angleDiff
247− var scaleTranslate = progress * scaleDiff / progressDiff;
248−
249− return stage0Scale - scaleTranslate;
250 }
176 }
251
177
252 default:
178 default: