on xenial help sign in
WIP - Move a bunch of properties into a Orientations container
commitc69bac969f1bc6afd580ec4e574c27fedb3c77db authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateMon 24 Aug 2015, 15:59 (11 years ago) parentfdda1b1
9 files changed+170−145
qml/Components/Orientations.qml+29 qml/DeviceConfiguration.qml+82−76 qml/OrientedShell.qml+24−18 qml/Shell.qml+5−17 qml/Stages/DesktopStage.qml+2−2 qml/Stages/PhoneStage.qml+3−9 qml/Stages/SpreadDelegate.qml+8−15 qml/Stages/TabletStage.qml+11−6 tests/qmltests/Stages/tst_SpreadDelegate.qml+6−2
qml/Components/Orientations.qmlnew file+29
@@ -0,0 +1,29 @@
1+/*
2+ * Copyright 2015 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.3
18+
19+QtObject {
20+ // Just because "native" is a reserved keyword :(
21+ property int native_: Qt.PortraitOrientation
22+
23+ property int primary: Qt.PortraitOrientation
24+
25+ property int landscape: Qt.LandscapeOrientation
26+ property int invertedLandscape: Qt.InvertedLandscapeOrientation
27+ property int portrait: Qt.PortraitOrientation
28+ property int invertedPortrait: Qt.InvertedPortraitOrientation
29+}
qml/DeviceConfiguration.qml+82−76
@@ -16,93 +16,99 @@
1616
1717import QtQuick 2.0
1818
19−StateGroup {
19+QtObject {
2020 id: root
2121
22− readonly property int useNativeOrientation: -1
22+ readonly property int UseNativeOrientation: -1
2323
24− property int primaryOrientation: useNativeOrientation
24+ // The only writable property in the API
25+ // all other properties are set according to the device name
26+ property alias name: priv.state
2527
26− property int supportedOrientations: Qt.PortraitOrientation
27− | Qt.InvertedPortraitOrientation
28− | Qt.LandscapeOrientation
29− | Qt.InvertedLandscapeOrientation
28+ readonly property alias primaryOrientation: priv.primaryOrientation
29+ readonly property alias supportedOrientations: priv.supportedOrientations
30+ readonly property alias landscapeOrientation: priv.landscapeOrientation
31+ readonly property alias invertedLandscapeOrientation: priv.invertedLandscapeOrientation
32+ readonly property alias portraitOrientation: priv.portraitOrientation
33+ readonly property alias invertedPortraitOrientation: priv.invertedPortraitOrientation
34+
35+ readonly property alias category: "phone"
36+
37+ readonly property alias ignoredMice: 0
38+
39+ StateGroup {
40+ id: priv
41+
42+ property int primaryOrientation: root.UseNativeOrientation
43+
44+ property int supportedOrientations: Qt.PortraitOrientation
45+ | Qt.InvertedPortraitOrientation
46+ | Qt.LandscapeOrientation
47+ | Qt.InvertedLandscapeOrientation
3048
31− property var deviceSpecificOrientationOverrides: QtObject{
32− id: overrides
3349 property int landscapeOrientation: Qt.LandscapeOrientation
3450 property int invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
3551 property int portraitOrientation: Qt.PortraitOrientation
3652 property int invertedPortraitOrientation: Qt.InvertedPortraitOrientation
37− }
38−
39− // PropertyChanges don't like assigning to nested properties
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−
45− // Supported values so far:
46− // "phone", "tablet" or "desktop"
47− property string category: "phone"
4853
49− property int ignoredMice: 0
54+ // Supported values so far:
55+ // "phone", "tablet" or "desktop"
56+ property string category: "phone"
5057
58+ property int ignoredMice: 0
5159
52− property alias name: root.state
53−
54− states: [
55− State {
56− name: "mako"
57− PropertyChanges {
58− target: root
59− supportedOrientations: Qt.PortraitOrientation
60− | Qt.LandscapeOrientation
61− | Qt.InvertedLandscapeOrientation
62− }
63− },
64− State {
65− name: "krillin"
66− PropertyChanges {
67− target: root
68− supportedOrientations: Qt.PortraitOrientation
69− | Qt.LandscapeOrientation
70− | Qt.InvertedLandscapeOrientation
71− }
72− },
73− State {
74− name: "arale"
75− PropertyChanges {
76− target: root
77− supportedOrientations: Qt.PortraitOrientation
78− | Qt.LandscapeOrientation
79− | Qt.InvertedLandscapeOrientation
80− ignoredMice: 1
81− }
82− },
83− State {
84− name: "manta"
85− PropertyChanges {
86− target: root
87− category: "tablet"
60+ states: [
61+ State {
62+ name: "mako"
63+ PropertyChanges {
64+ target: priv
65+ supportedOrientations: Qt.PortraitOrientation
66+ | Qt.LandscapeOrientation
67+ | Qt.InvertedLandscapeOrientation
68+ }
69+ },
70+ State {
71+ name: "krillin"
72+ PropertyChanges {
73+ target: priv
74+ supportedOrientations: Qt.PortraitOrientation
75+ | Qt.LandscapeOrientation
76+ | Qt.InvertedLandscapeOrientation
77+ }
78+ },
79+ State {
80+ name: "arale"
81+ PropertyChanges {
82+ target: priv
83+ supportedOrientations: Qt.PortraitOrientation
84+ | Qt.LandscapeOrientation
85+ | Qt.InvertedLandscapeOrientation
86+ ignoredMice: 1
87+ }
88+ },
89+ State {
90+ name: "manta"
91+ PropertyChanges {
92+ target: priv
93+ category: "tablet"
94+ }
95+ },
96+ State {
97+ name: "flo"
98+ PropertyChanges {
99+ target: priv
100+ landscapeOrientation: Qt.InvertedLandscapeOrientation
101+ primaryOrientation: Qt.InvertedLandscapeOrientation
102+ category: "tablet"
103+ }
104+ },
105+ State {
106+ name: "desktop"
107+ PropertyChanges {
108+ target: priv
109+ category: "desktop"
110+ }
88111 }
89− },
90− State {
91− name: "flo"
92− PropertyChanges {
93− target: root
94− landscapeOrientation: Qt.InvertedLandscapeOrientation
95− primaryOrientation: Qt.InvertedLandscapeOrientation
96− category: "tablet"
97− }
98− },
99− State {
100− name: "desktop"
101− PropertyChanges {
102− target: root
103− category: "desktop"
104− }
105− }
106− ]
107−
112+ ]
113+ }
108114}
qml/OrientedShell.qml+24−18
@@ -32,18 +32,26 @@ 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 var orientations: Orientations {
41+ id: orientations
42+ // NB: native and primary orientations here don't map exactly to their QScreen counterparts
43+ native_: root.width > root.height ? Qt.LandscapeOrientation : Qt.PortraitOrientation
44+
45+ primary: deviceConfiguration.primaryOrientation == deviceConfiguration.UseNativeOrientation
46+ ? nativeOrientation : deviceConfiguration.primaryOrientation
47+
48+ landscape: deviceConfiguration.landscapeOrientation
49+ invertedLandscape: deviceConfiguration.invertedLandscapeOrientation
50+ portrait: deviceConfiguration.portraitOrientation
51+ invertedPortrait: deviceConfiguration.invertedPortraitOrientation
52+ }
53+
54+
4755
4856 // to be overwritten by tests
4957 property var unity8Settings: Unity8Settings {}
@@ -92,7 +100,7 @@ Rectangle {
92100 & deviceConfiguration.supportedOrientations
93101 property int acceptedOrientationAngle: {
94102 if (orientation & supportedOrientations) {
95− return Screen.angleBetween(nativeOrientation, orientation);
103+ return Screen.angleBetween(orientations.native_, orientation);
96104 } else if (shell.orientation & supportedOrientations) {
97105 // stay where we are
98106 return shell.orientationAngle;
@@ -102,16 +110,16 @@ Rectangle {
102110 // rotate to some supported orientation as we can't stay where we currently are
103111 // TODO: Choose the closest to the current one
104112 if (supportedOrientations & Qt.PortraitOrientation) {
105− return Screen.angleBetween(nativeOrientation, Qt.PortraitOrientation);
106− } else if (supportedOrientations & Qt.LandcscapeOrientation) {
107− return Screen.angleBetween(nativeOrientation, Qt.LandscapeOrientation);
113+ return Screen.angleBetween(orientations.native_, Qt.PortraitOrientation);
114+ } else if (supportedOrientations & Qt.LandscapeOrientation) {
115+ return Screen.angleBetween(orientations.native_, Qt.LandscapeOrientation);
108116 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
109− return Screen.angleBetween(nativeOrientation, Qt.InvertedPortraitOrientation);
117+ return Screen.angleBetween(orientations.native_, Qt.InvertedPortraitOrientation);
110118 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
111− return Screen.angleBetween(nativeOrientation, Qt.InvertedLandscapeOrientation);
119+ return Screen.angleBetween(orientations.native_, Qt.InvertedLandscapeOrientation);
112120 } else {
113121 // if all fails, fallback to primary orientation
114− return Screen.angleBetween(nativeOrientation, primaryOrientation);
122+ return Screen.angleBetween(orientations.native_, orientations.primary);
115123 }
116124 }
117125 }
@@ -135,7 +143,7 @@ Rectangle {
135143 break;
136144 default:
137145 console.warn("angleToOrientation: Invalid orientation angle: " + angle);
138− return primaryOrientation;
146+ return orientations.primary;
139147 }
140148 }
141149
@@ -153,10 +161,8 @@ Rectangle {
153161 objectName: "shell"
154162 width: root.width
155163 height: root.height
156− deviceSpecificOrientationOverrides: deviceConfiguration.deviceSpecificOrientationOverrides
157164 orientation: root.angleToOrientation(orientationAngle)
158− primaryOrientation: root.primaryOrientation
159− nativeOrientation: root.nativeOrientation
165+ orientations: root.orientations
160166 nativeWidth: root.width
161167 nativeHeight: root.height
162168 mode: applicationArguments.mode
qml/Shell.qml+5−17
@@ -48,9 +48,7 @@ Item {
4848 // to be set from outside
4949 property int orientationAngle: 0
5050 property int orientation
51− property QtObject deviceSpecificOrientationOverrides
52− property int primaryOrientation
53− property int nativeOrientation
51+ property Orientations orientations
5452 property real nativeWidth
5553 property real nativeHeight
5654 property alias indicatorAreaShowProgress: panel.indicatorAreaShowProgress
@@ -319,29 +317,19 @@ Item {
319317 }
320318 Binding {
321319 target: applicationsDisplayLoader.item
322− property: "background"
323− value: shell.background
324− }
325− Binding {
326− target: applicationsDisplayLoader.item
327− property: "shellPrimaryOrientation"
328− value: shell.primaryOrientation
320+ property: "orientations"
321+ value: shell.orientations
329322 }
330323 Binding {
331324 target: applicationsDisplayLoader.item
332− property: "nativeOrientation"
333− value: shell.nativeOrientation
325+ property: "background"
326+ value: shell.background
334327 }
335328 Binding {
336329 target: applicationsDisplayLoader.item
337330 property: "nativeWidth"
338331 value: shell.nativeWidth
339332 }
340− Binding {
341− target: applicationsDisplayLoader.item
342− property: "deviceSpecificOrientationOverrides"
343− value: shell.deviceSpecificOrientationOverrides
344− }
345333 Binding {
346334 target: applicationsDisplayLoader.item
347335 property: "nativeHeight"
qml/Stages/DesktopStage.qml+2−2
@@ -21,6 +21,7 @@ import QtQuick.Layouts 1.1
2121import Ubuntu.Components 1.1
2222import Unity.Application 0.1
2323import "../Components/PanelState"
24+import "../Components"
2425import Utils 0.1
2526import Ubuntu.Gestures 0.1
2627
@@ -36,8 +37,7 @@ Rectangle {
3637 property real inverseProgress: 0 // just to comply with the interface shared between stages
3738 property int shellOrientationAngle: 0
3839 property int shellOrientation
39− property int shellPrimaryOrientation
40− property int nativeOrientation
40+ property Orientations orientations
4141 property bool beingResized: false
4242 property bool keepDashRunning: true
4343 property bool suspended: false
qml/Stages/PhoneStage.qml+3−9
@@ -40,11 +40,8 @@ Rectangle {
4040 property bool suspended: false
4141 property int shellOrientationAngle: 0
4242
43− // For some reason qml doesn't seem to like to bind to a QtObject, so this is a var
44− property var deviceSpecificOrientationOverrides
4543 property int shellOrientation
46− property int shellPrimaryOrientation
47− property int nativeOrientation
44+ property Orientations orientations
4845 property real nativeWidth
4946 property real nativeHeight
5047 property bool beingResized: false
@@ -79,7 +76,7 @@ Rectangle {
7976
8077 var supportedOrientations = spreadDelegate.application.supportedOrientations;
8178 if (supportedOrientations === Qt.PrimaryOrientation) {
82− supportedOrientations = spreadDelegate.shellPrimaryOrientation;
79+ supportedOrientations = root.orientations.primary;
8380 }
8481
8582 if (delta === 180 && (supportedOrientations & spreadDelegate.shellOrientation)) {
@@ -530,12 +527,9 @@ Rectangle {
530527 visible: (progress >= 0 && progress < 1.7)
531528 || (isDash && priv.focusedAppDelegateIsDislocated)
532529
533−
534− deviceSpecificOrientationOverrides: root.deviceSpecificOrientationOverrides
535530 shellOrientationAngle: root.shellOrientationAngle
536531 shellOrientation: root.shellOrientation
537− shellPrimaryOrientation: root.shellPrimaryOrientation
538− nativeOrientation: root.nativeOrientation
532+ orientations: root.orientations
539533
540534 onClicked: {
541535 if (root.altTabEnabled && spreadView.phase == 2) {
qml/Stages/SpreadDelegate.qml+8−15
@@ -42,9 +42,7 @@ FocusScope {
4242 property alias application: appWindow.application
4343 property int shellOrientationAngle
4444 property int shellOrientation
45− property QtObject deviceSpecificOrientationOverrides
46− property int shellPrimaryOrientation
47− property int nativeOrientation
45+ property Orientations orientations
4846
4947 function matchShellOrientation() {
5048 if (!root.application)
@@ -140,7 +138,6 @@ FocusScope {
140138 return angle % 360;
141139 }
142140
143− property alias overrides: root.deviceSpecificOrientationOverrides
144141 states: [
145142 // Sets the initial orientationAngle of the window, when it first slides into view
146143 // (with the splash screen likely being displayed). At that point we just try to
@@ -159,7 +156,7 @@ FocusScope {
159156 var supportedOrientations = root.application.supportedOrientations;
160157
161158 if (supportedOrientations === Qt.PrimaryOrientation) {
162− supportedOrientations = root.shellPrimaryOrientation;
159+ supportedOrientations = root.orientations.primary;
163160 }
164161
165162 // If it doesn't support shell's current orientation
@@ -168,22 +165,18 @@ FocusScope {
168165 if (supportedOrientations & root.shellOrientation) {
169166 chosenOrientation = root.shellOrientation;
170167 } else if (supportedOrientations & Qt.PortraitOrientation) {
171− chosenOrientation = overrides ?
172− overrides.portraitOrientation : Qt.PortraitOrientation;
168+ chosenOrientation = root.orientations.portrait;
173169 } else if (supportedOrientations & Qt.LandscapeOrientation) {
174− chosenOrientation = overrides ?
175− overrides.landscapeOrientation : Qt.LandscapeOrientation;
170+ chosenOrientation = root.orientations.landscape;
176171 } else if (supportedOrientations & Qt.InvertedPortraitOrientation) {
177− chosenOrientation = overrides ?
178− overrides.invertedPortraitOrientation : Qt.InvertedPortraitOrientation;
172+ chosenOrientation = root.orientations.invertedPortrait;
179173 } else if (supportedOrientations & Qt.InvertedLandscapeOrientation) {
180− chosenOrientation = overrides ?
181− overrides.invertedLandscapeOrientation : Qt.InvertedLandscapeOrientation;
174+ chosenOrientation = root.orientations.invertedLandscape;
182175 } else {
183− chosenOrientation = root.shellPrimaryOrientation;
176+ chosenOrientation = root.orientations.primary;
184177 }
185178
186− return Screen.angleBetween(root.nativeOrientation, chosenOrientation);
179+ return Screen.angleBetween(root.orientations.native_, chosenOrientation);
187180 }
188181
189182 rotation: normalizeAngle(appWindowWithShadow.orientationAngle - root.shellOrientationAngle)
qml/Stages/TabletStage.qml+11−6
@@ -43,8 +43,7 @@ Rectangle {
4343 // For some reason qml doesn't seem to like to bind to a QtObject, so this is a var
4444 property var deviceSpecificOrientationOverrides
4545 property int shellOrientation
46− property int shellPrimaryOrientation
47− property int nativeOrientation
46+ property Orientations orientations
4847 property real nativeWidth
4948 property real nativeHeight
5049
@@ -68,7 +67,7 @@ Rectangle {
6867
6968 var supportedOrientations = spreadDelegate.application.supportedOrientations;
7069 if (supportedOrientations === Qt.PrimaryOrientation) {
71− supportedOrientations = spreadDelegate.shellPrimaryOrientation;
70+ supportedOrientations = spreadDelegate.orientations.primary;
7271 }
7372
7473 if (delta === 180 && (supportedOrientations & spreadDelegate.shellOrientation)) {
@@ -134,7 +133,7 @@ Rectangle {
134133 property string oldFocusedAppId: ""
135134 property bool mainAppOrientationChangesEnabled: false
136135
137− property real landscapeHeight: root.nativeOrientation == Qt.LandscapeOrientation ?
136+ property real landscapeHeight: root.orientations.native_ == Qt.LandscapeOrientation ?
138137 root.nativeHeight : root.nativeWidth
139138
140139 property bool shellIsLandscape: root.shellOrientation === Qt.LandscapeOrientation
@@ -696,8 +695,14 @@ Rectangle {
696695 deviceSpecificOrientationOverrides: root.deviceSpecificOrientationOverrides
697696 shellOrientationAngle: wantsMainStage ? root.shellOrientationAngle : 0
698697 shellOrientation: wantsMainStage ? root.shellOrientation : Qt.PortraitOrientation
699− shellPrimaryOrientation: wantsMainStage ? root.shellPrimaryOrientation : Qt.PortraitOrientation
700− nativeOrientation: wantsMainStage ? root.nativeOrientation : Qt.PortraitOrientation
698+ orientations: Orientations {
699+ primary: spreadTile.wantsMainStage ? root.orientations.primary : Qt.PortraitOrientation
700+ native_: spreadTile.wantsMainStage ? root.orientations.native_ : Qt.PortraitOrientation
701+ portrait: root.orientations.portrait
702+ invertedPortrait: root.orientations.invertedPortrait
703+ landscape: root.orientations.landscape
704+ invertedLandscape: root.orientations.invertedLandscape
705+ }
701706
702707
703708 onClicked: {
tests/qmltests/Stages/tst_SpreadDelegate.qml+6−2
@@ -18,6 +18,7 @@ import QtQuick 2.0
1818import QtTest 1.0
1919import Unity.Test 0.1 as UT
2020import ".."
21+import "../../../qml/Components"
2122import "../../../qml/Stages"
2223import Ubuntu.Components 0.1
2324import Ubuntu.Components.ListItems 1.0 as ListItem
@@ -73,8 +74,11 @@ Rectangle {
7374 return Qt.LandscapeOrientation;
7475 }
7576 }
76− shellPrimaryOrientation: Qt.PortraitOrientation
77− nativeOrientation: Qt.PortraitOrientation
77+
78+ orientations: Orientations {
79+ // the default values will do
80+ }
81+
7882 maximizedAppTopMargin: units.gu(3)
7983 Component.onDestruction: {
8084 spreadDelegateLoader.itemDestroyed = true;