on xenial help sign in
Add support for overriding orientations based on device type
commit994879facbdd39f86abafdc6a94002405691daac authorJosh Arenson <joshua.arenson@canonical.com> dateFri 21 Aug 2015, 07:20 (11 years ago) parentbd74b71
6 files changed+28−18
qml/DeviceConfiguration.qml+11−1 qml/OrientedShell.qml+1−2 qml/Shell.qml−3 qml/Stages/PhoneStage.qml+4−2 qml/Stages/SpreadDelegate.qml+10−7 qml/Stages/TabletStage.qml+2−3
qml/DeviceConfiguration.qml+11−1
@@ -30,9 +30,18 @@ StateGroup {
3030 | Qt.InvertedLandscapeOrientation
3131
3232 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
3438 }
3539
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+
3645 // Supported values so far:
3746 // "phone", "tablet" or "desktop"
3847 property string category: "phone"
@@ -82,6 +91,7 @@ StateGroup {
8291 name: "flo"
8392 PropertyChanges {
8493 target: root
94+ landscapeOrientation: Qt.InvertedLandscapeOrientation
8595 primaryOrientation: Qt.InvertedLandscapeOrientation
8696 category: "tablet"
8797 }
qml/OrientedShell.qml+1−2
@@ -67,7 +67,6 @@ Rectangle {
6767 }
6868 }
6969 Component.onCompleted: {
70− console.log("JOSH: OrientedShell: " + deviceConfiguration.deviceSpecificOrientationOverrides.hello);
7170 if (orientationLocked) {
7271 orientation = orientationLock.savedOrientation;
7372 }
@@ -154,8 +153,8 @@ Rectangle {
154153 objectName: "shell"
155154 width: root.width
156155 height: root.height
157− orientation: root.angleToOrientation(orientationAngle)
158156 deviceSpecificOrientationOverrides: deviceConfiguration.deviceSpecificOrientationOverrides
157+ orientation: root.angleToOrientation(orientationAngle)
159158 primaryOrientation: root.primaryOrientation
160159 nativeOrientation: root.nativeOrientation
161160 nativeWidth: root.width
qml/Shell.qml−3
@@ -193,7 +193,6 @@ function serialize(object, maxDepth) {
193193}
194194
195195 Component.onCompleted: {
196− console.log("JOSH: Shell: " + deviceSpecificOrientationOverrides.hello);
197196 Theme.name = "Ubuntu.Components.Themes.SuruGradient"
198197 if (ApplicationManager.count > 0) {
199198 ApplicationManager.focusApplication(ApplicationManager.get(0).appId);
@@ -301,8 +300,6 @@ function serialize(object, maxDepth) {
301300 }
302301 }
303302
304− onLoaded: console.log("JOSH in shell loader: " + deviceSpecificOrientationOverrides.hello)
305−
306303 property bool interactive: tutorial.spreadEnabled
307304 && (!greeter || !greeter.shown)
308305 && panel.indicators.fullyClosed
qml/Stages/PhoneStage.qml+4−2
@@ -39,10 +39,12 @@ Rectangle {
3939 property bool keepDashRunning: true
4040 property bool suspended: false
4141 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
4245 property int shellOrientation
4346 property int shellPrimaryOrientation
4447 property int nativeOrientation
45− property QtObject deviceSpecificOrientationOverrides
4648 property real nativeWidth
4749 property real nativeHeight
4850 property bool beingResized: false
@@ -529,9 +531,9 @@ Rectangle {
529531 || (isDash && priv.focusedAppDelegateIsDislocated)
530532
531533
534+ deviceSpecificOrientationOverrides: root.deviceSpecificOrientationOverrides
532535 shellOrientationAngle: root.shellOrientationAngle
533536 shellOrientation: root.shellOrientation
534− deviceSpecificOrientationOverrides: root.deviceSpecificOrientationOverrides
535537 shellPrimaryOrientation: root.shellPrimaryOrientation
536538 nativeOrientation: root.nativeOrientation
537539
qml/Stages/SpreadDelegate.qml+10−7
@@ -42,7 +42,7 @@ FocusScope {
4242 property alias application: appWindow.application
4343 property int shellOrientationAngle
4444 property int shellOrientation
45− property string deviceSpecificOrientationOverrides
45+ property QtObject deviceSpecificOrientationOverrides
4646 property int shellPrimaryOrientation
4747 property int nativeOrientation
4848
@@ -140,6 +140,7 @@ FocusScope {
140140 return angle % 360;
141141 }
142142
143+ property alias overrides: root.deviceSpecificOrientationOverrides
143144 states: [
144145 // Sets the initial orientationAngle of the window, when it first slides into view
145146 // (with the splash screen likely being displayed). At that point we just try to
@@ -164,18 +165,20 @@ FocusScope {
164165 // If it doesn't support shell's current orientation
165166 // then simply pick some arbitraty one that it does support
166167 var chosenOrientation = 0;
167−
168− console.log("JOSH: SPREAD DELEGATE: " + root.deviceSpecificOrientationOverrides);
169168 if (supportedOrientations & root.shellOrientation) {
170169 chosenOrientation = root.shellOrientation;
171170 } else if (supportedOrientations & Qt.PortraitOrientation) {
172− chosenOrientation = Qt.PortraitOrientation;
171+ chosenOrientation = overrides ?
172+ overrides.portraitOrientation : Qt.PortraitOrientation;
173173 } else if (supportedOrientations & Qt.LandscapeOrientation) {
174− chosenOrientation = Qt.LandscapeOrientation;
174+ chosenOrientation = overrides ?
175+ overrides.landscapeOrientation : Qt.LandscapeOrientation;
175176 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
176− chosenOrientation = Qt.InvertedPortraitOrientation;
177+ chosenOrientation = overrides ?
178+ overrides.invertedPortraitOrientation : Qt.InvertedPortraitOrientation;
177179 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
178− chosenOrientation = Qt.InvertedLandscapeOrientation;
180+ chosenOrientation = overrides ?
181+ overrides.invertedLandscapeOrientation : Qt.InvertedLandscapeOrientation;
179182 } else {
180183 chosenOrientation = root.shellPrimaryOrientation;
181184 }
qml/Stages/TabletStage.qml+2−3
@@ -39,6 +39,8 @@ Rectangle {
3939 property bool keepDashRunning: true
4040 property bool suspended: false
4141 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
4244 property var deviceSpecificOrientationOverrides
4345 property int shellOrientation
4446 property int shellPrimaryOrientation
@@ -46,8 +48,6 @@ Rectangle {
4648 property real nativeWidth
4749 property real nativeHeight
4850
49− Component.onCompleted: console.log("JOSH ts onComp: " + deviceSpecificOrientationOverrides)
50−
5151 function updateFocusedAppOrientation() {
5252 var mainStageAppIndex = priv.indexOf(priv.mainStageAppId);
5353 if (mainStageAppIndex >= 0 && mainStageAppIndex < spreadRepeater.count) {
@@ -329,7 +329,6 @@ Rectangle {
329329 // In case the ApplicationManager already holds an app when starting up we're missing animations
330330 // Make sure we end up in the same state
331331 Component.onCompleted: {
332− console.log("JOSH: tablet stage: " + root.deviceSpecificOrientationOverrides)
333332 spreadView.contentX = -spreadView.shift
334333 }
335334