on xenial help sign in
add some stacking animation
commitdf925486ce3bd9f6d0a89ae665169a89f9ce02a0 authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 26 Mar 2015, 10:15 (12 years ago) parentc5dcb2d
3 files changed+104−41
qml/Stages/DesktopStage.qml+21−6 qml/Stages/SpreadMaths.qml+74−35 tests/qmltests/tst_DesktopShell.qml+9
qml/Stages/DesktopStage.qml+21−6
@@ -46,7 +46,7 @@ FocusScope {
4646 if (root.altTabPressed) {
4747 print("should tab next")
4848 appRepeater.highlightedIndex = (appRepeater.highlightedIndex + 1) % ApplicationManager.count
49− spreadFlickable.snapTo(spreadFlickable.width / 5 * Math.max(0, Math.min(ApplicationManager.count - 5, appRepeater.highlightedIndex - 2)))
49+ spreadFlickable.snapTo(spreadFlickable.width / 5 * Math.max(0, Math.min(ApplicationManager.count - 5, appRepeater.highlightedIndex - 3)))
5050 }
5151 }
5252
@@ -55,7 +55,7 @@ FocusScope {
5555 if (root.altTabPressed) {
5656 var newIndex = appRepeater.highlightedIndex - 1 >= 0 ? appRepeater.highlightedIndex - 1 : ApplicationManager.count - 1;
5757 appRepeater.highlightedIndex = newIndex;
58− spreadFlickable.snapTo(spreadFlickable.width / 5 * Math.max(0, Math.min(ApplicationManager.count - 5, appRepeater.highlightedIndex - 2)))
58+ spreadFlickable.snapTo(spreadFlickable.width / 5 * Math.max(0, Math.min(ApplicationManager.count - 5, appRepeater.highlightedIndex - 1)))
5959 }
6060 }
6161
@@ -151,9 +151,9 @@ FocusScope {
151151 name: "altTab"; when: root.state == "altTab"
152152 PropertyChanges {
153153 target: appDelegate
154− x: spreadMaths.desktopX(index, root.width, spreadFlickable.contentX)
154+ x: spreadMaths.animatedX
155155 y: spreadMaths.desktopY(root.height, appDelegate.height)
156− angle: spreadMaths.desktopAngle(index, spreadFlickable.contentX)
156+ angle: spreadMaths.animatedAngle
157157 itemScale: spreadMaths.desktopScale(root.height, appDelegate.height)
158158 itemScaleOriginY: appDelegate.height;
159159 color: "green"
@@ -169,7 +169,7 @@ FocusScope {
169169 }
170170 PropertyChanges {
171171 target: tileInfo
172− visible: true
172+ visible: spreadMaths.desktopTitleInfoShown(index, spreadFlickable.contentX)
173173 }
174174 }
175175 ]
@@ -187,6 +187,9 @@ FocusScope {
187187
188188 SpreadMaths {
189189 id: spreadMaths
190+ flickable: spreadFlickable
191+ itemIndex: index
192+ totalItems: ApplicationManager.count
190193 }
191194
192195 WindowMoveResizeArea {
@@ -269,7 +272,11 @@ FocusScope {
269272 anchors.fill: parent
270273 contentWidth: ApplicationManager.count * width / 5
271274 visible: false
272− onContentXChanged: print("flickable flicked", contentX)
275+ //boundsBehavior: Flickable.StopAtBounds
276+
277+ function ensureVisible(index) {
278+
279+ }
273280
274281 function snapTo(contentX) {
275282 snapAnimation.to = contentX
@@ -283,6 +290,14 @@ FocusScope {
283290 }
284291 }
285292
293+ Label {
294+ anchors { left: parent.left; bottom: parent.bottom; margins: units.gu(1) }
295+ text: "Progress: " + (spreadFlickable.contentX / (spreadFlickable.contentWidth - spreadFlickable.width))
296+ color: "red"
297+ fontSize: "x-large"
298+ z: 100
299+ }
300+
286301 states: [
287302 State {
288303 name: "windowed"
qml/Stages/SpreadMaths.qml+74−35
@@ -1,43 +1,66 @@
11import QtQuick 2.2
2+import Ubuntu.Components 1.1
23import Utils 0.1
34import Unity.Application 0.1
45
5−QtObject {
6− id: root
6+Item {
77
8− function desktopX(index, totalWidth, flickableX) {
9− var margins = units.gu(5);
10− var distance = (totalWidth - margins * 2) / 5;
11− var foldedDistance = units.gu(0.5)
12− var reverseIndex = ApplicationManager.count - index
13−
14− var x = (index * distance) - flickableX + margins;
15− // limit at left
16− x = Math.max(margins + foldedDistance * index, x);
17− // limit at right
18− x = Math.min(totalWidth - margins - distance - foldedDistance * reverseIndex, x);
19−
20− return x
21−
22−
23− var startProgress = 0;
24− var endProgress = 1;
25− var startValue = index * distance;
26− var endValue = 0;
27− var progress = 1.0 * flickableX / startValue;
28− print("progress for tile", index, ":", startProgress, endProgress, startValue, endValue, progress)
29− var x = easingAnimation(startProgress, endProgress, startValue, endValue, progress);
30− print("resulting x:", x)
31− return x + units.gu(5);
8+ Label {
9+ anchors {left: parent.left; top: parent.top }
10+ text: "prog:" + transitionCurve.progress.toFixed(2)
11+ color: isInLeftFoldingArea ? "red" : "black"
3212 }
3313
14+ id: root
15+ anchors { left: parent.left; top: parent.top; margins: units.gu(1) }
16+
17+ property int itemIndex: 0
18+ property int totalItems: 0
19+ property Item flickable: null
20+ property int margins: units.gu(5)
21+ property int foldingAreaWidth: units.gu(5)
22+
23+ property int maxVisibleItems: 5
24+
25+ readonly property int flickableWidth: flickable ? flickable.width : 0
26+ readonly property int flickableContentWidth: flickable ? flickable.contentWidth: 0
27+ readonly property real flickableProgress: flickable ? flickable.contentX / (flickable.contentWidth - flickableWidth) : 0
28+
29+ readonly property int contentWidth: flickableWidth - root.margins * 2
30+
31+ readonly property int unfoldedDistance: (contentWidth - foldingAreaWidth) / maxVisibleItems
32+
33+ // Internal
34+ readonly property real progressSlice: 1 / totalItems;
35+ readonly property real startProgress: Math.max(0, index - 2) * progressSlice
36+ readonly property real endProgress: (index + 3) * progressSlice
37+
38+ readonly property real startX: index < maxVisibleItems ?
39+ margins + index * unfoldedDistance
40+ : contentWidth - foldingAreaWidth + (startLayout.value * foldingAreaWidth)
41+
42+ readonly property real endX: totalItems - maxVisibleItems < index ?
43+ contentWidth - (totalItems - index) * unfoldedDistance
44+ : margins + foldingAreaWidth - (endLayout.value * foldingAreaWidth)
45+
46+ readonly property int animatedX: transitionCurve.value * (endX - startX) + startX
47+
3448 function desktopY(sceneHeight, itemHeight) {
3549 return sceneHeight - itemHeight - (sceneHeight * 0.2);
3650 }
3751
38− function desktopAngle(index, flickableX) {
39− return 40;
40− }
52+ property int leftEndFoldedAngle: 80
53+ property int rightEndFoldedAngle: 60
54+ property int unfoldedAngle: 30
55+
56+ property bool isInLeftFoldingArea: animatedX < foldingAreaWidth + margins
57+
58+ // x : foldingAreaWidth = leftEndFoldedAngle: unfoldedAngle:
59+
60+ readonly property int animatedAngle: isInLeftFoldingArea ?
61+ ((foldingAreaWidth + margins) - x) * unfoldedAngle / leftEndFoldedAngle
62+ : unfoldedAngle
63+
4164
4265 function desktopScale(sceneHeight, itemHeight) {
4366 var maxHeight = sceneHeight * 0.35;
@@ -47,14 +70,30 @@ QtObject {
4770 return 1;
4871 }
4972
50− function easingAnimation(startProgress, endProgress, startValue, endValue, progress) {
51− easingCurve.progress = progress - startProgress;
52− easingCurve.period = endProgress - startProgress;
53− return easingCurve.value * (endValue - startValue) + startValue;
73+ function desktopTitleInfoShown(index, flickableX) {
74+ return true;
75+ }
76+
77+ EasingCurve {
78+ id: transitionCurve
79+ type: easingCurve.InOutSine
80+
81+ readonly property real normalizedEndProgress: endProgress - startProgress
82+ readonly property real normalizedProgress: (root.flickableProgress - root.startProgress) / normalizedEndProgress
83+ progress: normalizedProgress
84+ }
85+
86+ EasingCurve {
87+ id: startLayout
88+ type: EasingCurve.OutSine
89+ // total : 1 = index : p
90+ progress: 1.0 * index / root.totalItems
5491 }
5592
56− property var easingCurve: EasingCurve {
93+ EasingCurve {
94+ id: endLayout
5795 type: EasingCurve.OutSine
58− period: 1
96+ // total : 1 = index : p
97+ progress: 1 - (1.0 * index / root.totalItems)
5998 }
6099}
tests/qmltests/tst_DesktopShell.qml+9
@@ -126,6 +126,15 @@ Item {
126126 }
127127 }
128128
129+ Button {
130+ text: "Start all apps"
131+ onClicked: {
132+ for (var i = 0; i < ApplicationManager.availableApplications.length; i++) {
133+ ApplicationManager.startApplication(ApplicationManager.availableApplications[i])
134+ }
135+ }
136+ }
137+
129138 Repeater {
130139 id: apps
131140 model: ApplicationManager.availableApplications