@@ -32,20 +32,31 @@ Rectangle {
3232 implicitWidth: units.gu(40)
3333 implicitHeight: units.gu(71)
3434
35− // NB: native and primary orientations here don't map exactly to their QScreen counterparts
36− readonly property int nativeOrientation: width > height ? Qt.LandscapeOrientation : Qt.PortraitOrientation
37−
38− readonly property int primaryOrientation:
39− deviceConfiguration.primaryOrientation == deviceConfiguration.useNativeOrientation
40− ? nativeOrientation : deviceConfiguration.primaryOrientation
41−
4235 DeviceConfiguration {
4336 id: deviceConfiguration
4437 name: applicationArguments.deviceName
4538 }
4639
40+ property alias orientations: d.orientations
41+
42+ Item {
43+ id: d
44+
45+ property Orientations orientations: Orientations {
46+ id: orientations
47+ // NB: native and primary orientations here don't map exactly to their QScreen counterparts
48+ native_: root.width > root.height ? Qt.LandscapeOrientation : Qt.PortraitOrientation
4749
48− // to be overwritten by tests
50+ primary: deviceConfiguration.primaryOrientation == deviceConfiguration.useNativeOrientation
51+ ? native_ : deviceConfiguration.primaryOrientation
52+
53+ landscape: deviceConfiguration.landscapeOrientation
54+ invertedLandscape: deviceConfiguration.invertedLandscapeOrientation
55+ portrait: deviceConfiguration.portraitOrientation
56+ invertedPortrait: deviceConfiguration.invertedPortraitOrientation
57+ }
58+ }
59+ // to be overwritten by tests
4960 property var unity8Settings: Unity8Settings {}
5061 property var oskSettings: GSettings { schema.id: "com.canonical.keyboard.maliit" }
5162
@@ -78,8 +89,8 @@ Rectangle {
7889
7990 // we must rotate to a supported orientation regardless of shell's preference
8091 property bool orientationChangesEnabled:
81− (orientation & supportedOrientations) === 0 ? true
82− : shell.orientationChangesEnabled
92+ (shell.orientation & supportedOrientations) === 0 ? true
93+ : shell.orientationChangesEnabled
8394
8495
8596 Binding {
@@ -96,12 +107,12 @@ Rectangle {
96107
97108 readonly property int supportedOrientations: shell.supportedOrientations
98109 & (deviceConfiguration.supportedOrientations == deviceConfiguration.useNativeOrientation
99− ? nativeOrientation
110+ ? orientations.native_
100111 : deviceConfiguration.supportedOrientations)
101112
102113 property int acceptedOrientationAngle: {
103114 if (orientation & supportedOrientations) {
104− return Screen.angleBetween(nativeOrientation, orientation);
115+ return Screen.angleBetween(orientations.native_, orientation);
105116 } else if (shell.orientation & supportedOrientations) {
106117 // stay where we are
107118 return shell.orientationAngle;
@@ -111,16 +122,16 @@ Rectangle {
111122 // rotate to some supported orientation as we can't stay where we currently are
112123 // TODO: Choose the closest to the current one
113124 if (supportedOrientations & Qt.PortraitOrientation) {
114− return Screen.angleBetween(nativeOrientation, Qt.PortraitOrientation);
125+ return Screen.angleBetween(orientations.native_, Qt.PortraitOrientation);
115126 } else if (supportedOrientations & Qt.LandscapeOrientation) {
116− return Screen.angleBetween(nativeOrientation, Qt.LandscapeOrientation);
127+ return Screen.angleBetween(orientations.native_, Qt.LandscapeOrientation);
117128 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
118− return Screen.angleBetween(nativeOrientation, Qt.InvertedPortraitOrientation);
129+ return Screen.angleBetween(orientations.native_, Qt.InvertedPortraitOrientation);
119130 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
120− return Screen.angleBetween(nativeOrientation, Qt.InvertedLandscapeOrientation);
131+ return Screen.angleBetween(orientations.native_, Qt.InvertedLandscapeOrientation);
121132 } else {
122133 // if all fails, fallback to primary orientation
123− return Screen.angleBetween(nativeOrientation, primaryOrientation);
134+ return Screen.angleBetween(orientations.native_, orientations.primary);
124135 }
125136 }
126137 }
@@ -128,19 +139,19 @@ Rectangle {
128139 function angleToOrientation(angle) {
129140 switch (angle) {
130141 case 0:
131− return nativeOrientation;
142+ return orientations.native_;
132143 case 90:
133− return nativeOrientation === Qt.PortraitOrientation ? Qt.InvertedLandscapeOrientation
144+ return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedLandscapeOrientation
134145 : Qt.PortraitOrientation;
135146 case 180:
136− return nativeOrientation === Qt.PortraitOrientation ? Qt.InvertedPortraitOrientation
147+ return orientations.native_ === Qt.PortraitOrientation ? Qt.InvertedPortraitOrientation
137148 : Qt.InvertedLandscapeOrientation;
138149 case 270:
139− return nativeOrientation === Qt.PortraitOrientation ? Qt.LandscapeOrientation
150+ return orientations.native_ === Qt.PortraitOrientation ? Qt.LandscapeOrientation
140151 : Qt.InvertedPortraitOrientation;
141152 default:
142153 console.warn("angleToOrientation: Invalid orientation angle: " + angle);
143− return primaryOrientation;
154+ return orientations.primary;
144155 }
145156 }
146157
@@ -159,8 +170,7 @@ Rectangle {
159170 width: root.width
160171 height: root.height
161172 orientation: root.angleToOrientation(orientationAngle)
162− primaryOrientation: root.primaryOrientation
163− nativeOrientation: root.nativeOrientation
173+ orientations: root.orientations
164174 nativeWidth: root.width
165175 nativeHeight: root.height
166176 mode: applicationArguments.mode