grue.qml Example File
grue/grue.qml
import QtQuick 2.0
import QtSensors 5.0
import Grue 1.0
Rectangle {
id: root
width: 320
height: 480
color: "black"
property int percent: 0
property string text: ""
property real grueOpacity: 0.0
function updateStatus(newPercent, newOpacity, newText) {
if (root.percent === newPercent)
return;
timer.interval = (newPercent < root.percent) ? 500 : 0;
root.percent = newPercent;
root.text = newText;
root.grueOpacity = newOpacity;
timer.start()
}
Timer {
id: timer
running: false
repeat: false
onTriggered: {
text.text = root.text
grueimg.opacity = root.grueOpacity
}
}
GrueSensor {
id: sensor
active: true
onReadingChanged: {
var percent = reading.chanceOfBeingEaten;
if (percent === 0) {
updateStatus(percent, 0.0, "It is light.<br>You are safe from Grues.");
}
else if (percent === 100) {
updateStatus(percent, 1.0, "You have been eaten by a Grue!");
sensor.active = false;
}
else if (percent > 0) {
updateStatus(percent, 0.05 + (percent * 0.001),
"It is dark.<br>You are " + percent +" % " +
"likely to be eaten by a Grue.");
}
}
}
Text {
id: text
anchors.top: parent.top
anchors.topMargin: 0
anchors.left: parent.left
anchors.right: parent.right
wrapMode: Text.WordWrap
text: "I can't tell if you're going to be eaten by a Grue or not. You're on your own!"
font.pixelSize: 30
color: "lightgray"
}
Image {
id: grueimg
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
source: "grue.png"
opacity: 0.0
Behavior on opacity { PropertyAnimation { duration: 250 } }
}
}