Skip to content

Commit 8f9ea33

Browse files
committed
Avoid having Rotation animations accessing context from parent
Make things more explicit
1 parent 8ef39f8 commit 8f9ea33

File tree

4 files changed

+63
-41
lines changed

4 files changed

+63
-41
lines changed

qml/Rotation/HalfLoopRotationAnimation.qml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014 Canonical, Ltd.
2+
* Copyright (C) 2015 Canonical, Ltd.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -19,13 +19,16 @@ import QtQuick 2.3
1919
SequentialAnimation {
2020
id: root
2121

22+
// set from outside
2223
property int fromAngle
2324
property int toAngle
25+
property var info
26+
property var shell
2427

2528
readonly property bool flipShellDimensions: toAngle == 90 || toAngle == 270
2629

2730
ScriptAction { script: {
28-
d.transitioning = true;
31+
info.transitioning = true;
2932
shell.orientationAngle = root.toAngle;
3033
shell.x = (orientedShell.width - shell.width) / 2
3134
shell.y = (orientedShell.height - shell.height) / 2;
@@ -39,5 +42,5 @@ SequentialAnimation {
3942
from: root.fromAngle; to: root.toAngle
4043
duration: rotationDuration; easing.type: rotationEasing
4144
}
42-
ScriptAction { script: { d.transitioning = false; } }
45+
ScriptAction { script: { info.transitioning = false; } }
4346
}
+25-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014 Canonical, Ltd.
2+
* Copyright (C) 2015 Canonical, Ltd.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -16,25 +16,30 @@
1616

1717
import QtQuick 2.3
1818

19-
ScriptAction { script: {
20-
d.transitioning = true;
21-
shell.orientationAngle = d.requestedOrientationAngle;
22-
shell.transformRotationAngle = d.requestedOrientationAngle;
19+
ScriptAction {
20+
property var info
21+
property var shell
2322

24-
// Making bindings as orientedShell's dimensions might wiggle during startup.
25-
if (d.requestedOrientationAngle === 90 || d.requestedOrientationAngle === 270) {
26-
shell.width = Qt.binding(function() { return orientedShell.height; });
27-
shell.height = Qt.binding(function() { return orientedShell.width; });
28-
} else {
29-
shell.width = Qt.binding(function() { return orientedShell.width; });
30-
shell.height = Qt.binding(function() { return orientedShell.height; });
31-
}
23+
script: {
24+
info.transitioning = true;
25+
shell.orientationAngle = info.requestedOrientationAngle;
26+
shell.transformRotationAngle = info.requestedOrientationAngle;
27+
28+
// Making bindings as orientedShell's dimensions might wiggle during startup.
29+
if (info.requestedOrientationAngle === 90 || info.requestedOrientationAngle === 270) {
30+
shell.width = Qt.binding(function() { return orientedShell.height; });
31+
shell.height = Qt.binding(function() { return orientedShell.width; });
32+
} else {
33+
shell.width = Qt.binding(function() { return orientedShell.width; });
34+
shell.height = Qt.binding(function() { return orientedShell.height; });
35+
}
3236

33-
shell.x = Qt.binding(function() { return (orientedShell.width - shell.width) / 2; });
34-
shell.y = Qt.binding(function() { return (orientedShell.height - shell.height) / 2; });
35-
shell.transformOriginX = Qt.binding(function() { return shell.width / 2; });
36-
shell.transformOriginY = Qt.binding(function() { return shell.height / 2; });
37+
shell.x = Qt.binding(function() { return (orientedShell.width - shell.width) / 2; });
38+
shell.y = Qt.binding(function() { return (orientedShell.height - shell.height) / 2; });
39+
shell.transformOriginX = Qt.binding(function() { return shell.width / 2; });
40+
shell.transformOriginY = Qt.binding(function() { return shell.height / 2; });
3741

38-
shell.updateFocusedAppOrientation();
39-
d.transitioning = false;
40-
} }
42+
shell.updateFocusedAppOrientation();
43+
info.transitioning = false;
44+
}
45+
}

qml/Rotation/NinetyRotationAnimation.qml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014 Canonical, Ltd.
2+
* Copyright (C) 2015 Canonical, Ltd.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -21,13 +21,15 @@ SequentialAnimation {
2121

2222
property int fromAngle
2323
property int toAngle
24+
property var info
25+
property var shell
2426

2527
readonly property real fromY: fromAngle === 0 || fromAngle === 90 ? 0 : orientedShell.height - orientedShell.width;
2628
readonly property real toY: toAngle === 0 || toAngle === 90 ? 0 : orientedShell.height - orientedShell.width;
2729
readonly property bool flipShellDimensions: toAngle == 90 || toAngle == 270
2830

2931
ScriptAction { script: {
30-
d.transitioning = true;
32+
info.transitioning = true;
3133
windowScreenshot.take();
3234
windowScreenshot.visible = true;
3335
shell.orientationAngle = root.toAngle;
@@ -83,6 +85,6 @@ SequentialAnimation {
8385
windowScreenshot.visible = false;
8486
windowScreenshot.discard();
8587
shellCover.visible = false;
86-
d.transitioning = false;
88+
info.transitioning = false;
8789
} }
8890
}

qml/Rotation/RotationStates.qml

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2014 Canonical, Ltd.
2+
* Copyright (C) 2015 Canonical, Ltd.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -170,67 +170,79 @@ StateGroup {
170170
Transition {
171171
from: "90"; to: "0"
172172
enabled: d.animationType == d.fullAnimation
173-
NinetyRotationAnimation { fromAngle: 90; toAngle: 0 }
173+
NinetyRotationAnimation { fromAngle: 90; toAngle: 0
174+
info: d; shell: root.shell }
174175
},
175176
Transition {
176177
from: "0"; to: "90"
177178
enabled: d.animationType == d.fullAnimation
178-
NinetyRotationAnimation { fromAngle: 0; toAngle: 90 }
179+
NinetyRotationAnimation { fromAngle: 0; toAngle: 90
180+
info: d; shell: root.shell }
179181
},
180182
Transition {
181183
from: "0"; to: "270"
182184
enabled: d.animationType == d.fullAnimation
183-
NinetyRotationAnimation { fromAngle: 0; toAngle: 270 }
185+
NinetyRotationAnimation { fromAngle: 0; toAngle: 270
186+
info: d; shell: root.shell }
184187
},
185188
Transition {
186189
from: "270"; to: "0"
187190
enabled: d.animationType == d.fullAnimation
188-
NinetyRotationAnimation { fromAngle: 270; toAngle: 0 }
191+
NinetyRotationAnimation { fromAngle: 270; toAngle: 0
192+
info: d; shell: root.shell }
189193
},
190194
Transition {
191195
from: "90"; to: "180"
192196
enabled: d.animationType == d.fullAnimation
193-
NinetyRotationAnimation { fromAngle: 90; toAngle: 180 }
197+
NinetyRotationAnimation { fromAngle: 90; toAngle: 180
198+
info: d; shell: root.shell }
194199
},
195200
Transition {
196201
from: "180"; to: "90"
197202
enabled: d.animationType == d.fullAnimation
198-
NinetyRotationAnimation { fromAngle: 180; toAngle: 90 }
203+
NinetyRotationAnimation { fromAngle: 180; toAngle: 90
204+
info: d; shell: root.shell }
199205
},
200206
Transition {
201207
from: "180"; to: "270"
202208
enabled: d.animationType == d.fullAnimation
203-
NinetyRotationAnimation { fromAngle: 180; toAngle: 270 }
209+
NinetyRotationAnimation { fromAngle: 180; toAngle: 270
210+
info: d; shell: root.shell }
204211
},
205212
Transition {
206213
from: "270"; to: "180"
207214
enabled: d.animationType == d.fullAnimation
208-
NinetyRotationAnimation { fromAngle: 270; toAngle: 180 }
215+
NinetyRotationAnimation { fromAngle: 270; toAngle: 180
216+
info: d; shell: root.shell }
209217
},
210218
Transition {
211219
from: "0"; to: "180"
212220
enabled: d.animationType == d.fullAnimation
213-
HalfLoopRotationAnimation { fromAngle: 0; toAngle: 180 }
221+
HalfLoopRotationAnimation { fromAngle: 0; toAngle: 180
222+
info: d; shell: root.shell }
214223
},
215224
Transition {
216225
from: "180"; to: "0"
217226
enabled: d.animationType == d.fullAnimation
218-
HalfLoopRotationAnimation { fromAngle: 180; toAngle: 0 }
227+
HalfLoopRotationAnimation { fromAngle: 180; toAngle: 0
228+
info: d; shell: root.shell }
219229
},
220230
Transition {
221231
from: "90"; to: "270"
222232
enabled: d.animationType == d.fullAnimation
223-
HalfLoopRotationAnimation { fromAngle: 90; toAngle: 270 }
233+
HalfLoopRotationAnimation { fromAngle: 90; toAngle: 270
234+
info: d; shell: root.shell }
224235
},
225236
Transition {
226237
from: "270"; to: "90"
227238
enabled: d.animationType == d.fullAnimation
228-
HalfLoopRotationAnimation { fromAngle: 270; toAngle: 90 }
239+
HalfLoopRotationAnimation { fromAngle: 270; toAngle: 90
240+
info: d; shell: root.shell }
229241
},
230242
Transition {
231243
objectName: "immediateTransition"
232244
enabled: d.animationType == d.noAnimation
233-
ImmediateRotationAction {}
245+
ImmediateRotationAction { info: d; shell: root.shell }
234246
},
235247
Transition {
236248
enabled: d.animationType == d.indicatorsBarAnimation
@@ -243,7 +255,7 @@ StateGroup {
243255
target: root.shell; property: "indicatorAreaShowProgress"
244256
from: 1.0; to: 0.0
245257
}
246-
ImmediateRotationAction {}
258+
ImmediateRotationAction { info: d; shell: root.shell }
247259
NumberAnimation {
248260
duration: UbuntuAnimation.FastDuration; easing: UbuntuAnimation.StandardEasing
249261
target: root.shell; property: "indicatorAreaShowProgress"

0 commit comments

Comments
 (0)