qmlqtsensors.qml Example File
qmlqtsensors/qmlqtsensors.qml
import QtQuick 2.0
import "components"
import QtSensors 5.0
ApplicationWindow {
TiltSensor {
id: tilt
active: false
}
AmbientLightSensor {
id: ambientlight
active: false
onReadingChanged: {
if (reading.lightLevel == AmbientLightReading.Dark)
ambientlighttext.text = "Ambient light: Dark";
else if (reading.lightLevel == AmbientLightReading.Twilight)
ambientlighttext.text = "Ambient light: Twilight";
else if (reading.lightLevel == AmbientLightReading.Light)
ambientlighttext.text = "Ambient light: Light";
else if (reading.lightLevel == AmbientLightReading.Bright)
ambientlighttext.text = "Ambient light: Bright";
else if (reading.lightLevel == AmbientLightReading.Sunny)
ambientlighttext.text = "Ambient light: Sunny";
else
ambientlighttext.text = "Ambient light: Unknown";
}
}
ProximitySensor {
id: proxi
active: false
}
Column {
spacing: 10
anchors.fill: parent
anchors.margins: 5
Text {
id: labelTitle
width: parent.width
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 30
font.bold: true
text: "QML QtSensors"
}
Divider { label: "TiltSensor" }
Row {
spacing: 20
width: parent.width
anchors.margins: 5
Button {
id: calibrate
height: 30
width: 80
text: "Calibrate"
onClicked: tilt.calibrate();
}
Text {
id: xrottext
height: 30
verticalAlignment: Text.AlignVCenter
text: "X Rotation: " + (tilt.reading ? tilt.reading.xRotation.toFixed(2) + "??" : "Unknown")
}
}
Row {
spacing: 20
width: parent.width
anchors.margins: 5
Button {
id: tiltStart
height: 30
width: 80
text: tilt.active ? "Stop" : "Start"
onClicked: {
tilt.active = (tiltStart.text === "Start");
}
}
Text {
id: yrottext
height: 30
verticalAlignment: Text.AlignVCenter
text: "Y Rotation: " + (tilt.reading ? tilt.reading.yRotation.toFixed(2) + "??" : "Unknown")
}
}
Divider { label: "AmbientLightSensor" }
Row {
spacing: 20
width: parent.width
anchors.margins: 5
Button{
id: ambientlightStart
height: 30
width: 80
text: ambientlight.active ? "Stop" : "Start"
onClicked: {
ambientlight.active = (ambientlightStart.text === "Start" ? true : false);
}
}
Text {
id: ambientlighttext
height: 30
verticalAlignment: Text.AlignVCenter
text: "Ambient light: Unknown"
}
}
Divider { label: "ProximitySensor" }
Row {
spacing: 20
width: parent.width
anchors.margins: 5
Button {
id: proxiStart
height: 30
width: 80
text: proxi.active ? "Stop" : "Start"
onClicked: {
proxi.active = (proxiStart.text === "Start" ? true: false);
}
}
Text {
id: proxitext
height: 30
verticalAlignment: Text.AlignVCenter
text: "Proximity: " +
(proxi.active ? (proxi.reading.near ? "Near" : "Far") : "Unknown")
}
}
}
}