diff options
author | Sergio Ahumada <sergio.ahumada@digia.com> | 2013-09-06 14:33:04 +0200 |
---|---|---|
committer | Sergio Ahumada <sergio.ahumada@digia.com> | 2013-09-06 14:33:04 +0200 |
commit | 0784f45d046f481f91dd9b701e237836c8b3fb11 (patch) | |
tree | 2e001c09ec5ef3945440d232c007297755d72bab /examples/sensors/grue/grue.qml | |
parent | d9776fc6aa8e90926fa024bb64c4e31406d1d091 (diff) | |
parent | ed96b2ea42bd95feeba1085665286a33c9672ab1 (diff) |
Merge remote-tracking branch 'origin/stable' into dev
Change-Id: Ie5c68600ed2b7d6145497dcbceae5f320f7eea6f
Diffstat (limited to 'examples/sensors/grue/grue.qml')
-rw-r--r-- | examples/sensors/grue/grue.qml | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/examples/sensors/grue/grue.qml b/examples/sensors/grue/grue.qml index 65980165..acafdb69 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 } } } } |