2 * Copyright 2015 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;
72 chosenAnimation.start();
75 // to be read from outside
76 property bool running: chosenAnimation ? chosenAnimation.running : false
78 property int duration: 450
79 property int easingType: Easing.InOutCubic
81 property int shortestDimension: spreadDelegate.width < spreadDelegate.height
82 ? spreadDelegate.width : spreadDelegate.height
83 property int longestDimension: spreadDelegate.width > spreadDelegate.height
84 ? spreadDelegate.width : spreadDelegate.height
85 property string longestAxis: spreadDelegate.width > spreadDelegate.height ? "x" : "y"
87 property QtObject chosenAnimation
89 function setup90Animation() {
90 background.visible = true;
92 screenshot.width = window.width;
93 screenshot.height = window.height;
94 screenshot.window.anchors.topMargin = window.window.anchors.topMargin;
96 screenshot.transformOriginX = root.shortestDimension / 2;
97 screenshot.transformOriginY = root.shortestDimension / 2;
98 screenshot.visible = true;
101 window.width = spreadDelegate.width;
102 window.height = spreadDelegate.height;
103 window.transformOriginX = root.shortestDimension / 2;
104 window.transformOriginY = root.shortestDimension / 2;
107 function tearDown90Animation() {
108 window.orientationAngle = spreadDelegate.shellOrientationAngle;
109 screenshot.discard();
110 screenshot.visible = false;
111 background.visible = false;
114 property QtObject simple90Animation: SequentialAnimation {
115 id: simple90Animation
117 ScriptAction { script: setup90Animation() }
121 duration: root.duration
122 easing.type: root.easingType
123 from: window.orientationAngle - spreadDelegate.shellOrientationAngle
125 property: "transformRotationAngle"
128 target: root.screenshot
129 duration: root.duration
130 easing.type: root.easingType
131 from: window.orientationAngle - spreadDelegate.shellOrientationAngle
133 property: "transformRotationAngle"
136 target: root.screenshot
137 duration: root.duration
138 easing.type: root.easingType
145 duration: root.duration
146 easing.type: root.easingType
152 ScriptAction { script: tearDown90Animation() }
155 property QtObject moving90Animation: SequentialAnimation {
156 id: moving90Animation
158 ScriptAction { script: setup90Animation() }
162 duration: root.duration
163 easing.type: root.easingType
164 direction: RotationAnimation.Shortest
165 from: window.orientationAngle - spreadDelegate.shellOrientationAngle
167 property: "transformRotationAngle"
170 target: root.screenshot
171 duration: root.duration
172 easing.type: root.easingType
173 direction: RotationAnimation.Shortest
174 from: window.orientationAngle - spreadDelegate.shellOrientationAngle
176 property: "transformRotationAngle"
179 target: root.screenshot
180 duration: root.duration
181 easing.type: root.easingType
188 duration: root.duration
189 easing.type: root.easingType
196 duration: root.duration
197 easing.type: root.easingType
198 property: root.longestAxis
199 from: root.longestDimension - root.shortestDimension
203 target: root.screenshot
204 duration: root.duration
205 easing.type: root.easingType
206 property: root.longestAxis
207 from: root.longestDimension - root.shortestDimension
211 ScriptAction { script: tearDown90Animation() }
214 property QtObject halfLoopAnimation: SequentialAnimation {
215 id: halfLoopAnimation
217 ScriptAction { script: {
218 background.visible = true;
221 window.width = spreadDelegate.width;
222 window.height = spreadDelegate.height;
223 window.transformOriginX = window.width / 2
224 window.transformOriginY = window.height / 2
229 duration: root.duration
230 easing.type: root.easingType
231 from: window.orientationAngle - spreadDelegate.shellOrientationAngle
233 property: "transformRotationAngle"
236 ScriptAction { script: {
237 window.orientationAngle = spreadDelegate.shellOrientationAngle;
238 background.visible = false;