2 * Copyright 2015, 2016 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 // to be set from outside
23 property Item spreadDelegate
24 property Item background
26 property Item screenshot
29 if (window.orientationAngle === 0) {
30 if (spreadDelegate.shellOrientationAngle === 90) {
31 chosenAnimation = simple90Animation;
32 } else if (spreadDelegate.shellOrientationAngle === 180) {
33 chosenAnimation = halfLoopAnimation;
34 } else if (spreadDelegate.shellOrientationAngle === 270) {
35 chosenAnimation = moving90Animation;
37 chosenAnimation = null;
39 } else if (window.orientationAngle === 90) {
40 if (spreadDelegate.shellOrientationAngle === 0) {
41 chosenAnimation = simple90Animation;
42 } else if (spreadDelegate.shellOrientationAngle === 180) {
43 chosenAnimation = moving90Animation;
44 } else if (spreadDelegate.shellOrientationAngle === 270) {
45 chosenAnimation = halfLoopAnimation;
47 chosenAnimation = null;
49 } else if (window.orientationAngle === 180) {
50 if (spreadDelegate.shellOrientationAngle === 0) {
51 chosenAnimation = halfLoopAnimation;
52 } else if (spreadDelegate.shellOrientationAngle === 90) {
53 chosenAnimation = moving90Animation;
54 } else if (spreadDelegate.shellOrientationAngle === 270) {
55 chosenAnimation = simple90Animation;
57 chosenAnimation = null;
59 } else if (window.orientationAngle === 270) {
60 if (spreadDelegate.shellOrientationAngle === 0) {
61 chosenAnimation = moving90Animation;
62 } else if (spreadDelegate.shellOrientationAngle === 90) {
63 chosenAnimation = halfLoopAnimation;
64 } else if (spreadDelegate.shellOrientationAngle === 180) {
65 chosenAnimation = simple90Animation;
67 chosenAnimation = null;
71 if (chosenAnimation) {
72 chosenAnimation.setup();
76 property Connections chosenAnimationConns: Connections {
77 target: root.chosenAnimation
79 if (root.chosenAnimation.ready) {
80 root.chosenAnimation.start();
85 // to be read from outside
86 property bool running: chosenAnimation !== null
88 property int duration: 450
89 property int easingType: Easing.InOutCubic
91 property int shortestDimension: spreadDelegate.width < spreadDelegate.height
92 ? spreadDelegate.width : spreadDelegate.height
93 property int longestDimension: spreadDelegate.width > spreadDelegate.height
94 ? spreadDelegate.width : spreadDelegate.height
95 property string longestAxis: spreadDelegate.width > spreadDelegate.height ? "x" : "y"
97 property QtObject chosenAnimation: null
99 function setup90Animation() {
100 background.visible = true;
102 screenshot.width = window.width;
103 screenshot.height = window.height;
104 screenshot.window.anchors.topMargin = window.window.anchors.topMargin;
105 screenshot.transformOriginX = root.shortestDimension / 2;
106 screenshot.transformOriginY = root.shortestDimension / 2;
107 screenshot.visible = true;
110 window.width = spreadDelegate.width;
111 window.height = spreadDelegate.height;
112 window.transformOriginX = root.shortestDimension / 2;
113 window.transformOriginY = root.shortestDimension / 2;
116 function tearDown90Animation() {
117 window.orientationAngle = spreadDelegate.shellOrientationAngle;
118 screenshot.discard();
119 screenshot.visible = false;
120 background.visible = false;
121 chosenAnimation.ranSetup = false;
122 chosenAnimation = null;
125 property QtObject simple90Animation: SequentialAnimation {
126 id: simple90Animation
128 function setup() { screenshot.take(); ranSetup = true; }
129 property bool ranSetup: false
130 readonly property bool ready: ranSetup && root.screenshot && root.screenshot.ready
132 ScriptAction { script: setup90Animation() }
136 duration: root.duration
137 easing.type: root.easingType
138 from: window.orientationAngle - spreadDelegate.shellOrientationAngle
140 property: "transformRotationAngle"
143 target: root.screenshot
144 duration: root.duration
145 easing.type: root.easingType
146 from: window.orientationAngle - spreadDelegate.shellOrientationAngle
148 property: "transformRotationAngle"
151 target: root.screenshot
152 duration: root.duration
153 easing.type: root.easingType
160 duration: root.duration
161 easing.type: root.easingType
167 ScriptAction { script: tearDown90Animation() }
170 property QtObject moving90Animation: SequentialAnimation {
171 id: moving90Animation
173 function setup() { screenshot.take(); ranSetup = true; }
174 property bool ranSetup: false
175 readonly property bool ready: ranSetup && root.screenshot && root.screenshot.ready
177 ScriptAction { script: setup90Animation() }
181 duration: root.duration
182 easing.type: root.easingType
183 direction: RotationAnimation.Shortest
184 from: window.orientationAngle - spreadDelegate.shellOrientationAngle
186 property: "transformRotationAngle"
189 target: root.screenshot
190 duration: root.duration
191 easing.type: root.easingType
192 direction: RotationAnimation.Shortest
193 from: window.orientationAngle - spreadDelegate.shellOrientationAngle
195 property: "transformRotationAngle"
198 target: root.screenshot
199 duration: root.duration
200 easing.type: root.easingType
207 duration: root.duration
208 easing.type: root.easingType
215 duration: root.duration
216 easing.type: root.easingType
217 property: root.longestAxis
218 from: root.longestDimension - root.shortestDimension
222 target: root.screenshot
223 duration: root.duration
224 easing.type: root.easingType
225 property: root.longestAxis
226 from: root.longestDimension - root.shortestDimension
230 ScriptAction { script: tearDown90Animation() }
233 property QtObject halfLoopAnimation: SequentialAnimation {
234 id: halfLoopAnimation
236 function setup() { ready = true; }
237 property bool ready: false
239 ScriptAction { script: {
240 background.visible = true;
243 window.width = spreadDelegate.width;
244 window.height = spreadDelegate.height;
245 window.transformOriginX = window.width / 2
246 window.transformOriginY = window.height / 2
251 duration: root.duration
252 easing.type: root.easingType
253 from: window.orientationAngle - spreadDelegate.shellOrientationAngle
255 property: "transformRotationAngle"
258 ScriptAction { script: {
259 window.orientationAngle = spreadDelegate.shellOrientationAngle;
260 background.visible = false;
261 chosenAnimation = null;
262 halfLoopAnimation.ready = false;