compass.qml Example File
SensorDemo/assets/compass.qml
import bb.cascades 1.0
import QtMobility.sensors 1.2
import bb.vibrationController 1.0
Container {
attachedObjects: [
OrientationHandler {
onOrientationAboutToChange: {
if (displayDirection == DisplayDirection.North) {
compass.userOrientation = 0;
} else if (displayDirection == DisplayDirection.South) {
compass.userOrientation = 180;
} else if (displayDirection == DisplayDirection.East) {
compass.userOrientation = 270;
} else if (displayDirection == DisplayDirection.West) {
compass.userOrientation = 90;
}
}
},
Compass {
id: compass
property double azimuth: 0
active: true
axesOrientationMode: Compass.UserOrientation
onReadingChanged: {
compass.azimuth = reading.azimuth;
}
},
OrientationSensor {
id: orientation
property bool face_down: false
active: true
onReadingChanged: {
face_down = (reading.orientation == OrientationReading.FaceDown);
}
}
]
layout: DockLayout {}
Container {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
opacity: orientation.face_down ? 0 : 1
Label {
horizontalAlignment: HorizontalAlignment.Center
text: qsTr("%1\u00B0").arg(compass.azimuth.toFixed())
textStyle {
base: SystemDefaults.TextStyles.BodyText
color: Color.White
}
}
ImageView {
imageSource: "images/MID-Dial.png"
rotationZ: - compass.azimuth
maxWidth: 500.0
maxHeight: 500.0
attachedObjects: [
ImplicitAnimationController {
enabled: false
}
]
}
attachedObjects: [
ImplicitAnimationController {
enabled: false
}
]
}
Container {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
opacity: orientation.face_down ? 1 : 0
Label {
horizontalAlignment: HorizontalAlignment.Center
text: qsTr("%1\u00B0").arg(compass.azimuth.toFixed())
textStyle {
base: SystemDefaults.TextStyles.BodyText
color: Color.Yellow
fontWeight: FontWeight.Bold
}
}
ImageView {
imageSource: "images/MID-Dial-reverse.png"
rotationZ: 360 + compass.azimuth
maxWidth: 500.0
maxHeight: 500.0
attachedObjects: [
ImplicitAnimationController {
enabled: false
}
]
}
attachedObjects: [
ImplicitAnimationController {
enabled: false
}
]
}
}