blob: fceecb7b2bcfd6380c686c56b4d98d41267cceb3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
}
}
}
}
|