Unity 8
NinetyRotationAnimation.qml
1 /*
2  * Copyright (C) 2015 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.4
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  windowScreenshot.take();
34  windowScreenshot.visible = true;
35  shell.orientationAngle = root.toAngle;
36  shell.x = 0;
37  shell.width = flipShellDimensions ? orientedShell.height : orientedShell.width;
38  shell.height = flipShellDimensions ? orientedShell.width : orientedShell.height;
39  shell.transformOriginX = orientedShell.width / 2;
40  shell.transformOriginY = orientedShell.width / 2;
41  shell.updateFocusedAppOrientation();
42  shellCover.visible = true;
43 
44  windowScreenshot.transformOriginX = orientedShell.width / 2;
45  if (fromAngle == 180 || fromAngle == 270) {
46  windowScreenshot.transformOriginY = orientedShell.height - (orientedShell.width / 2);
47  } else {
48  windowScreenshot.transformOriginY = orientedShell.width / 2;
49  }
50  } }
51  ParallelAnimation {
52  NumberAnimation {
53  target: shellCover; property: "opacity"; from: 1; to: 0;
54  duration: rotationDuration; easing.type: rotationEasing
55  }
56  RotationAnimation {
57  target: shell; property: "transformRotationAngle";
58  from: root.fromAngle; to: root.toAngle
59  direction: RotationAnimation.Shortest
60  duration: rotationDuration; easing.type: rotationEasing
61  }
62  NumberAnimation {
63  target: shell; property: "y"
64  from: root.fromY; to: root.toY
65  duration: rotationDuration; easing.type: rotationEasing
66  }
67 
68  NumberAnimation {
69  target: windowScreenshot; property: "opacity"; from: 1; to: 0;
70  duration: rotationDuration; easing.type: rotationEasing
71  }
72  RotationAnimation {
73  target: windowScreenshot; property: "transformRotationAngle";
74  from: 0; to: root.toAngle - root.fromAngle
75  direction: RotationAnimation.Shortest
76  duration: rotationDuration; easing.type: rotationEasing
77  }
78  NumberAnimation {
79  target: windowScreenshot; property: "y"
80  from: 0; to: root.toY - root.fromY
81  duration: rotationDuration; easing.type: rotationEasing
82  }
83  }
84  ScriptAction { script: {
85  windowScreenshot.visible = false;
86  windowScreenshot.discard();
87  shellCover.visible = false;
88  info.transitioning = false;
89  } }
90 }