Unity 8
NinetyRotationAnimation.qml
1 /*
2  * Copyright (C) 2015-2016 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
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 General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.12
18 
19 SequentialAnimation {
20  id: root
21 
22  property int fromAngle
23  property int toAngle
24  property var info
25  property var shell
26 
27  readonly property real fromY: fromAngle === 0 || fromAngle === 90 ? 0 : orientedShell.height - orientedShell.width;
28  readonly property real toY: toAngle === 0 || toAngle === 90 ? 0 : orientedShell.height - orientedShell.width;
29  readonly property bool flipShellDimensions: toAngle == 90 || toAngle == 270
30 
31  ScriptAction { script: {
32  info.transitioning = true;
33 
34  shell.orientationAngle = root.toAngle;
35  shell.x = 0;
36  shell.width = flipShellDimensions ? orientedShell.height : orientedShell.width;
37  shell.height = flipShellDimensions ? orientedShell.width : orientedShell.height;
38  shell.transformOriginX = orientedShell.width / 2;
39  shell.transformOriginY = orientedShell.width / 2;
40  shell.updateFocusedAppOrientation();
41  shellCover.visible = true;
42 
43  shellSnapshot.transformOriginX = shell.transformOriginX;
44  shellSnapshot.transformOriginY = shell.transformOriginY;
45  shellSnapshot.transformRotationAngle = shell.transformRotationAngle;
46  shellSnapshot.visible = true;
47  } }
48  ParallelAnimation {
49  NumberAnimation {
50  target: shellCover; property: "opacity"; from: 1; to: 0;
51  duration: rotationDuration; easing.type: rotationEasing
52  }
53  RotationAnimation {
54  target: shell; property: "transformRotationAngle";
55  from: root.fromAngle; to: root.toAngle
56  direction: RotationAnimation.Shortest
57  duration: rotationDuration; easing.type: rotationEasing
58  }
59  NumberAnimation {
60  target: shell; property: "y"
61  from: root.fromY; to: root.toY
62  duration: rotationDuration; easing.type: rotationEasing
63  }
64 
65  NumberAnimation {
66  target: shellSnapshot; property: "opacity"; from: 1; to: 0;
67  duration: rotationDuration; easing.type: rotationEasing
68  }
69  RotationAnimation {
70  target: shellSnapshot; property: "transformRotationAngle";
71  from: root.fromAngle; to: root.toAngle
72  direction: RotationAnimation.Shortest
73  duration: rotationDuration; easing.type: rotationEasing
74  }
75  NumberAnimation {
76  target: shellSnapshot; property: "y"
77  from: root.fromY; to: root.toY
78  duration: rotationDuration; easing.type: rotationEasing
79  }
80  }
81  UpdateShellTransformations { shell: root.shell; rotationAngle: root.toAngle }
82  ScriptAction { script: {
83  shellSnapshot.visible = false;
84  shellSnapshot.discard();
85  shellCover.visible = false;
86  info.transitioning = false;
87  } }
88 }