on xenial help sign in
Add support for overriding orientations based on device type
994879fJosh Arenson
qml/DeviceConfiguration.qml+11−1
@@ -30,9 +30,18 @@ StateGroup {
30 | Qt.InvertedLandscapeOrientation
30 | Qt.InvertedLandscapeOrientation
31
31
32 property var deviceSpecificOrientationOverrides: QtObject{
32 property var deviceSpecificOrientationOverrides: QtObject{
33− property string hello: "world"
33+ id: overrides
34+ property int landscapeOrientation: Qt.LandscapeOrientation
35+ property int invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
36+ property int portraitOrientation: Qt.PortraitOrientation
37+ property int invertedPortraitOrientation: Qt.InvertedPortraitOrientation
34 }
38 }
35
39
40+ property alias landscapeOrientation: overrides.landscapeOrientation
41+ property alias invertedLandscapeOrientation: overrides.invertedLandscapeOrientation
42+ property alias portraitOrientation: overrides.portraitOrientation
43+ property alias invertedPortraitOrientation: overrides.invertedPortraitOrientation
44+
36 // Supported values so far:
45 // Supported values so far:
37 // "phone", "tablet" or "desktop"
46 // "phone", "tablet" or "desktop"
38 property string category: "phone"
47 property string category: "phone"
@@ -82,6 +91,7 @@ StateGroup {
82 name: "flo"
91 name: "flo"
83 PropertyChanges {
92 PropertyChanges {
84 target: root
93 target: root
94+ landscapeOrientation: Qt.InvertedLandscapeOrientation
85 primaryOrientation: Qt.InvertedLandscapeOrientation
95 primaryOrientation: Qt.InvertedLandscapeOrientation
86 category: "tablet"
96 category: "tablet"
87 }
97 }
qml/OrientedShell.qml+1−2
@@ -67,7 +67,6 @@ Rectangle {
67 }
67 }
68 }
68 }
69 Component.onCompleted: {
69 Component.onCompleted: {
70− console.log("JOSH: OrientedShell: " + deviceConfiguration.deviceSpecificOrientationOverrides.hello);
71 if (orientationLocked) {
70 if (orientationLocked) {
72 orientation = orientationLock.savedOrientation;
71 orientation = orientationLock.savedOrientation;
73 }
72 }
@@ -154,8 +153,8 @@ Rectangle {
154 objectName: "shell"
153 objectName: "shell"
155 width: root.width
154 width: root.width
156 height: root.height
155 height: root.height
157− orientation: root.angleToOrientation(orientationAngle)
158 deviceSpecificOrientationOverrides: deviceConfiguration.deviceSpecificOrientationOverrides
156 deviceSpecificOrientationOverrides: deviceConfiguration.deviceSpecificOrientationOverrides
157+ orientation: root.angleToOrientation(orientationAngle)
159 primaryOrientation: root.primaryOrientation
158 primaryOrientation: root.primaryOrientation
160 nativeOrientation: root.nativeOrientation
159 nativeOrientation: root.nativeOrientation
161 nativeWidth: root.width
160 nativeWidth: root.width
qml/Shell.qml−3
@@ -193,7 +193,6 @@ function serialize(object, maxDepth) {
193}
193}
194
194
195 Component.onCompleted: {
195 Component.onCompleted: {
196− console.log("JOSH: Shell: " + deviceSpecificOrientationOverrides.hello);
197 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
196 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
198 if (ApplicationManager.count > 0) {
197 if (ApplicationManager.count > 0) {
199 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
198 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
@@ -301,8 +300,6 @@ function serialize(object, maxDepth) {
301 }
300 }
302 }
301 }
303
302
304− onLoaded: console.log("JOSH in shell loader: " + deviceSpecificOrientationOverrides.hello)
305−
306 property bool interactive: tutorial.spreadEnabled
303 property bool interactive: tutorial.spreadEnabled
307 && (!greeter || !greeter.shown)
304 && (!greeter || !greeter.shown)
308 && panel.indicators.fullyClosed
305 && panel.indicators.fullyClosed
qml/Stages/PhoneStage.qml+4−2
@@ -39,10 +39,12 @@ Rectangle {
39 property bool keepDashRunning: true
39 property bool keepDashRunning: true
40 property bool suspended: false
40 property bool suspended: false
41 property int shellOrientationAngle: 0
41 property int shellOrientationAngle: 0
42+
43+ // For some reason qml doesn't seem to like to bind to a QtObject, so this is a var
44+ property var deviceSpecificOrientationOverrides
42 property int shellOrientation
45 property int shellOrientation
43 property int shellPrimaryOrientation
46 property int shellPrimaryOrientation
44 property int nativeOrientation
47 property int nativeOrientation
45− property QtObject deviceSpecificOrientationOverrides
46 property real nativeWidth
48 property real nativeWidth
47 property real nativeHeight
49 property real nativeHeight
48 property bool beingResized: false
50 property bool beingResized: false
@@ -529,9 +531,9 @@ Rectangle {
529 || (isDash && priv.focusedAppDelegateIsDislocated)
531 || (isDash && priv.focusedAppDelegateIsDislocated)
530
532
531
533
534+ deviceSpecificOrientationOverrides: root.deviceSpecificOrientationOverrides
532 shellOrientationAngle: root.shellOrientationAngle
535 shellOrientationAngle: root.shellOrientationAngle
533 shellOrientation: root.shellOrientation
536 shellOrientation: root.shellOrientation
534− deviceSpecificOrientationOverrides: root.deviceSpecificOrientationOverrides
535 shellPrimaryOrientation: root.shellPrimaryOrientation
537 shellPrimaryOrientation: root.shellPrimaryOrientation
536 nativeOrientation: root.nativeOrientation
538 nativeOrientation: root.nativeOrientation
537
539
qml/Stages/SpreadDelegate.qml+10−7
@@ -42,7 +42,7 @@ FocusScope {
42 property alias application: appWindow.application
42 property alias application: appWindow.application
43 property int shellOrientationAngle
43 property int shellOrientationAngle
44 property int shellOrientation
44 property int shellOrientation
45− property string deviceSpecificOrientationOverrides
45+ property QtObject deviceSpecificOrientationOverrides
46 property int shellPrimaryOrientation
46 property int shellPrimaryOrientation
47 property int nativeOrientation
47 property int nativeOrientation
48
48
@@ -140,6 +140,7 @@ FocusScope {
140 return angle % 360;
140 return angle % 360;
141 }
141 }
142
142
143+ property alias overrides: root.deviceSpecificOrientationOverrides
143 states: [
144 states: [
144 // Sets the initial orientationAngle of the window, when it first slides into view
145 // Sets the initial orientationAngle of the window, when it first slides into view
145 // (with the splash screen likely being displayed). At that point we just try to
146 // (with the splash screen likely being displayed). At that point we just try to
@@ -164,18 +165,20 @@ FocusScope {
164 // If it doesn't support shell's current orientation
165 // If it doesn't support shell's current orientation
165 // then simply pick some arbitraty one that it does support
166 // then simply pick some arbitraty one that it does support
166 var chosenOrientation = 0;
167 var chosenOrientation = 0;
167−
168− console.log("JOSH: SPREAD DELEGATE: " + root.deviceSpecificOrientationOverrides);
169 if (supportedOrientations & root.shellOrientation) {
168 if (supportedOrientations & root.shellOrientation) {
170 chosenOrientation = root.shellOrientation;
169 chosenOrientation = root.shellOrientation;
171 } else if (supportedOrientations & Qt.PortraitOrientation) {
170 } else if (supportedOrientations & Qt.PortraitOrientation) {
172− chosenOrientation = Qt.PortraitOrientation;
171+ chosenOrientation = overrides ?
172+ overrides.portraitOrientation : Qt.PortraitOrientation;
173 } else if (supportedOrientations & Qt.LandscapeOrientation) {
173 } else if (supportedOrientations & Qt.LandscapeOrientation) {
174− chosenOrientation = Qt.LandscapeOrientation;
174+ chosenOrientation = overrides ?
175+ overrides.landscapeOrientation : Qt.LandscapeOrientation;
175 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
176 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
177+ chosenOrientation = overrides ?
176− chosenOrientation = Qt.InvertedPortraitOrientation;
178+ overrides.invertedPortraitOrientation : Qt.InvertedPortraitOrientation;
177 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
179 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
180+ chosenOrientation = overrides ?
178− chosenOrientation = Qt.InvertedLandscapeOrientation;
181+ overrides.invertedLandscapeOrientation : Qt.InvertedLandscapeOrientation;
179 } else {
182 } else {
180 chosenOrientation = root.shellPrimaryOrientation;
183 chosenOrientation = root.shellPrimaryOrientation;
181 }
184 }
qml/Stages/TabletStage.qml+2−3
@@ -39,6 +39,8 @@ Rectangle {
39 property bool keepDashRunning: true
39 property bool keepDashRunning: true
40 property bool suspended: false
40 property bool suspended: false
41 property int shellOrientationAngle: 0
41 property int shellOrientationAngle: 0
42+
43+ // For some reason qml doesn't seem to like to bind to a QtObject, so this is a var
42 property var deviceSpecificOrientationOverrides
44 property var deviceSpecificOrientationOverrides
43 property int shellOrientation
45 property int shellOrientation
44 property int shellPrimaryOrientation
46 property int shellPrimaryOrientation
@@ -46,8 +48,6 @@ Rectangle {
46 property real nativeWidth
48 property real nativeWidth
47 property real nativeHeight
49 property real nativeHeight
48
50
49− Component.onCompleted: console.log("JOSH ts onComp: " + deviceSpecificOrientationOverrides)
50−
51 function updateFocusedAppOrientation() {
51 function updateFocusedAppOrientation() {
52 var mainStageAppIndex = priv.indexOf(priv.mainStageAppId);
52 var mainStageAppIndex = priv.indexOf(priv.mainStageAppId);
53 if (mainStageAppIndex >= 0 && mainStageAppIndex < spreadRepeater.count) {
53 if (mainStageAppIndex >= 0 && mainStageAppIndex < spreadRepeater.count) {
@@ -329,7 +329,6 @@ Rectangle {
329 // In case the ApplicationManager already holds an app when starting up we're missing animations
329 // In case the ApplicationManager already holds an app when starting up we're missing animations
330 // Make sure we end up in the same state
330 // Make sure we end up in the same state
331 Component.onCompleted: {
331 Component.onCompleted: {
332− console.log("JOSH: tablet stage: " + root.deviceSpecificOrientationOverrides)
333 spreadView.contentX = -spreadView.shift
332 spreadView.contentX = -spreadView.shift
334 }
333 }
335
334