Commit b2e67dd5 authored by Filip Matijević's avatar Filip Matijević

[rotation] simplify rotation usage by moving it to qml

parent e9156fc8
...@@ -29,22 +29,33 @@ ...@@ -29,22 +29,33 @@
** **
****************************************************************************************/ ****************************************************************************************/
function rotateObject(obj, r, nr) { import QtQuick 2.1
import QtQuick.Window 2.1
import org.nemomobile.lipstick 0.1
Item {
QtObject {
id: privateProperties
property int nativeRotation: Screen.angleBetween(nativeOrientation, Screen.primaryOrientation)
property bool nativeIsPortrait: ((nativeRotation === 0) || (nativeRotation === 180))
}
function rotateObject(obj, o) {
var r = Screen.angleBetween(o, Screen.primaryOrientation)
if (obj.rotation !== r) { if (obj.rotation !== r) {
var nativeIsPortrait = ((nr === 0) || (nr === 180))
var isPortrait = ((r === 0) || (r === 180))
var isPortrait = ((r === 0) || (r === 180))
var correction = 0 var correction = 0
var isNative=((nativeIsPortrait || isPortrait) && !(nativeIsPortrait && isPortrait)) //xor var isNative=((privateProperties.nativeIsPortrait || isPortrait) && !(privateProperties.nativeIsPortrait && isPortrait)) //xor
//xor //xor
if ((isNative || !nativeIsPortrait) && !(isNative && !nativeIsPortrait)) { if ((isNative || !privateProperties.nativeIsPortrait) && !(isNative && !privateProperties.nativeIsPortrait)) {
correction = obj.width / 2 - obj.height / 2 correction = obj.width / 2 - obj.height / 2
} }
var diff = Math.abs(r - obj.rotation) var diff = Math.abs(r - obj.rotation)
obj.rotation = r obj.rotation = r
if ((diff === 90) || (diff === 270)) { if ((diff === 90) || (diff === 270)) {
console.log("rotateObject swapping w,h")
var w = obj.width var w = obj.width
obj.width = obj.height obj.width = obj.height
obj.height = w obj.height = w
...@@ -52,4 +63,5 @@ function rotateObject(obj, r, nr) { ...@@ -52,4 +63,5 @@ function rotateObject(obj, r, nr) {
obj.x = correction obj.x = correction
obj.y = -correction obj.y = -correction
} }
}
} }
...@@ -38,7 +38,6 @@ import org.nemomobile.time 1.0 ...@@ -38,7 +38,6 @@ import org.nemomobile.time 1.0
import org.nemomobile.configuration 1.0 import org.nemomobile.configuration 1.0
import org.nemomobile.lipstick 0.1 import org.nemomobile.lipstick 0.1
import "scripts/desktop.js" as Desktop import "scripts/desktop.js" as Desktop
import "scripts/rotation.js" as Rotation
Page { Page {
// This is used in the favorites page and in the lock screen // This is used in the favorites page and in the lock screen
...@@ -71,17 +70,23 @@ Page { ...@@ -71,17 +70,23 @@ Page {
id: statusbar id: statusbar
} }
GlacierRotation {
id: glacierRotation
}
orientation: Lipstick.compositor.screenOrientation orientation: Lipstick.compositor.screenOrientation
onOrientationChanged: { onOrientationChanged: {
Rotation.rotateObject(desktop.parent, Screen.angleBetween(orientation,Screen.primaryOrientation), Screen.angleBetween(nativeOrientation, Screen.primaryOrientation)) glacierRotation.rotateObject(desktop.parent, orientation)
} }
onParentChanged: { onParentChanged: {
Rotation.rotateObject(desktop.parent, Screen.angleBetween(nativeOrientation, Screen.primaryOrientation), Screen.angleBetween(nativeOrientation, Screen.primaryOrientation)) glacierRotation.rotateObject(desktop.parent, nativeOrientation)
} }
Component.onCompleted: { Component.onCompleted: {
Desktop.instance = desktop Desktop.instance = desktop
Lipstick.compositor.screenOrientation = nativeOrientation
} }
function lockscreenVisible() { function lockscreenVisible() {
......
...@@ -34,7 +34,8 @@ qml.files = qml/MainScreen.qml \ ...@@ -34,7 +34,8 @@ qml.files = qml/MainScreen.qml \
qml/VolumeControl.qml \ qml/VolumeControl.qml \
qml/BatteryPanel.qml \ qml/BatteryPanel.qml \
qml/CommonPanel.qml \ qml/CommonPanel.qml \
qml/ShutdownScreen.qml qml/ShutdownScreen.qml \
qml/GlacierRotation.qml
qmlcompositor.path = /usr/share/lipstick-glacier-home-qt5/qml/compositor qmlcompositor.path = /usr/share/lipstick-glacier-home-qt5/qml/compositor
qmlcompositor.files = qml/compositor/WindowWrapperMystic.qml \ qmlcompositor.files = qml/compositor/WindowWrapperMystic.qml \
...@@ -106,6 +107,6 @@ OTHER_FILES += qml/*.qml \ ...@@ -106,6 +107,6 @@ OTHER_FILES += qml/*.qml \
qml/BatteryPanel.qml \ qml/BatteryPanel.qml \
qml/CommonPanel.qml \ qml/CommonPanel.qml \
qml/ShutdownScreen.qml \ qml/ShutdownScreen.qml \
qml/scripts/rotation.js qml/GlacierRotation.qml
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment