summaryrefslogtreecommitdiffstats
path: root/basicsuite/Sensors/Light.qml
diff options
context:
space:
mode:
Diffstat (limited to 'basicsuite/Sensors/Light.qml')
-rw-r--r--basicsuite/Sensors/Light.qml50
1 files changed, 50 insertions, 0 deletions
diff --git a/basicsuite/Sensors/Light.qml b/basicsuite/Sensors/Light.qml
new file mode 100644
index 0000000..fceecb7
--- /dev/null
+++ b/basicsuite/Sensors/Light.qml
@@ -0,0 +1,50 @@
+import QtQuick 2.0
+import QtSensors 5.0
+
+Item {
+ rotation: 180
+ Rectangle {
+ id: bg
+ width: parent.width
+ height: parent.height
+ Text {
+ id: illuminanceLevel
+ anchors.horizontalCenter: parent.horizontalCenter
+ font.pointSize: 26
+ anchors.top: parent.top
+ }
+ Image {
+ id: avatar
+ anchors.top: illuminanceLevel.bottom
+ anchors.topMargin: 30
+ anchors.centerIn: parent
+ }
+
+ AmbientLightSensor {
+ active: true
+ onReadingChanged: {
+ if (reading.lightLevel === AmbientLightReading.Dark) {
+ avatar.source = "3.png"
+ bg.color = "midnightblue"
+ } else if (reading.lightLevel === AmbientLightReading.Twilight
+ || reading.lightLevel === AmbientLightReading.Light) {
+ avatar.source = "2.png"
+ bg.color = "steelblue"
+ } else if (reading.lightLevel === AmbientLightReading.Bright
+ || reading.lightLevel === AmbientLightReading.Sunny) {
+ avatar.source = "1.png"
+ bg.color = "yellow"
+ } else {
+ avatar.text = "Unknown light level"
+ }
+ }
+ }
+
+ LightSensor {
+ active: true
+ onReadingChanged: {
+ illuminanceLevel.text = "Illuminance: " + reading.illuminance
+ }
+ }
+ }
+}