@@ -26,9 +26,58 @@ Item {
2626 width: tablet ? units.gu(160) : applicationArguments.hasGeometry() ? applicationArguments.width() : units.gu(40)
2727 height: tablet ? units.gu(100) : applicationArguments.hasGeometry() ? applicationArguments.height() : units.gu(71)
2828
29− property int orientationAngle: Screen.angleBetween(Screen.primaryOrientation, Screen.orientation)
29+ property int acceptedOrientationAngle: {
30+ var screenOrientation = Screen.orientation;
31+ var acceptedOrientation;
3032
31− state: orientationAngle.toString()
33+ if (screenOrientation & shell.supportedScreenOrientations) {
34+ acceptedOrientation = screenOrientation;
35+ } else {
36+ // try orientations at -90, 90 and 180
37+ switch (screenOrientation) {
38+ case Qt.PortraitOrientation:
39+ if (Qt.LandscapeOrientation & shell.supportedScreenOrientations) {
40+ acceptedOrientation = Qt.LandscapeOrientation;
41+ } else if (Qt.InvertedLandscapeOrientation & shell.supportedScreenOrientations) {
42+ acceptedOrientation = Qt.InvertedLandscapeOrientation;
43+ } else {
44+ acceptedOrientation = Qt.InvertedPortraitOrientation;
45+ }
46+ break;
47+ case Qt.InvertedPortraitOrientation:
48+ if (Qt.LandscapeOrientation & shell.supportedScreenOrientations) {
49+ acceptedOrientation = Qt.LandscapeOrientation;
50+ } else if (Qt.InvertedLandscapeOrientation & shell.supportedScreenOrientations) {
51+ acceptedOrientation = Qt.InvertedLandscapeOrientation;
52+ } else {
53+ acceptedOrientation = Qt.PortraitOrientation;
54+ }
55+ break;
56+ case Qt.LandscapeOrientation:
57+ if (Qt.PortraitOrientation & shell.supportedScreenOrientations) {
58+ acceptedOrientation = Qt.PortraitOrientation;
59+ } else if (Qt.InvertedPortraitOrientation & shell.supportedScreenOrientations) {
60+ acceptedOrientation = Qt.InvertedPortraitOrientation;
61+ } else {
62+ acceptedOrientation = Qt.InvertedLandscapeOrientation;
63+ }
64+ break;
65+ default: // Qt.InvertedLandscapeOrientation
66+ if (Qt.PortraitOrientation & shell.supportedScreenOrientations) {
67+ acceptedOrientation = Qt.PortraitOrientation;
68+ } else if (Qt.InvertedPortraitOrientation & shell.supportedScreenOrientations) {
69+ acceptedOrientation = Qt.InvertedPortraitOrientation;
70+ } else {
71+ acceptedOrientation = Qt.LandscapeOrientation;
72+ }
73+ break;
74+ }
75+ }
76+
77+ return Screen.angleBetween(Screen.primaryOrientation, acceptedOrientation);
78+ }
79+
80+ state: acceptedOrientationAngle.toString()
3281 states: [
3382 State {
3483 name: "0"
@@ -79,6 +128,6 @@ Item {
79128 Shell {
80129 id: shell
81130 transformOrigin: Item.TopLeft
82− orientationAngle: orientedShell.orientationAngle
131+ orientationAngle: orientedShell.acceptedOrientationAngle
83132 }
84133}