summaryrefslogtreecommitdiff
path: root/examples/sensors/grue/grue.qml
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@digia.com>2013-08-13 14:40:13 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-14 21:03:53 +0200
commit52c831db165f5068826dddef4d41427a98a42dfd (patch)
tree6d79c1c09ca5894fc3beb3f9627047f9cff6e435 /examples/sensors/grue/grue.qml
parent6dd954f2b9ce1f241d968d201183f8a80d729e57 (diff)
downloadqtsensors-52c831db165f5068826dddef4d41427a98a42dfd.tar.gz
Doc: Update Grue Sensor example
Fix a number of issues with the example: - Add \omit to generated doc sections, we don't want qdoc to process these (not part of Qt docs) - Combine the 5 separate examples into a single \example and discuss each subproject in a subsection - Add example image to doc - Fix deployment/build target directories and import paths - Define a 'reading' property for the sensor to make it work on QtSensors 5.1 - Fix the Grue QML application to avoid flicker from frequent updates. Task-number: QTBUG-32881 Change-Id: I2785faead1baaf5b1ae9d05df3398e018e945418 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com> Reviewed-by: Lorn Potter <lorn.potter@jollamobile.com>
Diffstat (limited to 'examples/sensors/grue/grue.qml')
-rw-r--r--examples/sensors/grue/grue.qml54
1 files changed, 39 insertions, 15 deletions
diff --git a/examples/sensors/grue/grue.qml b/examples/sensors/grue/grue.qml
index 6598016..acafdb6 100644
--- a/examples/sensors/grue/grue.qml
+++ b/examples/sensors/grue/grue.qml
@@ -43,33 +43,56 @@ 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;
+
+ // Delay updating the visual status to prevent flicker
+ 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;
- var thetext = "";
- var theopacity = 0;
if (percent === 0) {
- thetext = "It is light. You are safe from Grues.";
+ updateStatus(percent, 0.0, "It is light.<br>You are safe from Grues.");
}
else if (percent === 100) {
- thetext = "You have been eaten by a Grue!";
+ updateStatus(percent, 1.0, "You have been eaten by a Grue!");
sensor.active = false;
- theopacity = 1;
}
else if (percent > 0) {
- thetext = "It is dark. You are likely to be eaten by a Grue. "
- + "Your chance of being eaten by a Grue: "+percent+" percent.";
- theopacity = 0.05 + (percent * 0.001);
+ updateStatus(percent, 0.05 + (percent * 0.001),
+ "It is dark.<br>You are " + percent +" % " +
+ "likely to be eaten by a Grue.");
}
- text.font.pixelSize = 30;
- text.text = "<p>" + thetext + "</p>";
- grueimg.opacity = theopacity;
}
}
@@ -79,10 +102,10 @@ Rectangle {
anchors.topMargin: 0
anchors.left: parent.left
anchors.right: parent.right
- text: "I can't tell if you're going to be eaten by a Grue or not. You're on your own!"
wrapMode: Text.WordWrap
- font.pixelSize: 50
- color: "white"
+ 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 {
@@ -90,6 +113,7 @@ Rectangle {
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
source: "grue.png"
- opacity: 0
+ opacity: 0.0
+ Behavior on opacity { PropertyAnimation { duration: 250 } }
}
}