diff options
author | Rainer Keller <rainer.keller@digia.com> | 2014-06-11 11:25:47 +0200 |
---|---|---|
committer | Rainer Keller <rainer.keller@digia.com> | 2014-06-11 14:11:53 +0300 |
commit | 0d56278af6eace6747bd7c91215f6e5daef8b84e (patch) | |
tree | d6447a31e8e7ff9bbe7294adfed1f52064cffce0 /basicsuite | |
parent | 1ce9c5aa3d911963b05daf1194f2ad7daab8e491 (diff) |
Show sensors example in landscape view
Show sensors example in landscape view to match the way all
the other examples are presented in the qtlauncher.
Also the calculation is more pysically correct.
Task-number: QTEE-569
Change-Id: I12e1b27e62dfa082d9d768598891a5ce91109436
Reviewed-by: Gatis Paeglis <gatis.paeglis@digia.com>
Diffstat (limited to 'basicsuite')
-rw-r--r-- | basicsuite/sensors/Accelbubble.qml | 116 | ||||
-rw-r--r-- | basicsuite/sensors/Light.qml | 77 | ||||
-rw-r--r-- | basicsuite/sensors/main.qml | 34 | ||||
-rw-r--r-- | basicsuite/sensors/preview_l.jpg | bin | 19464 -> 16715 bytes |
4 files changed, 103 insertions, 124 deletions
diff --git a/basicsuite/sensors/Accelbubble.qml b/basicsuite/sensors/Accelbubble.qml index c5aeefc..f70aa32 100644 --- a/basicsuite/sensors/Accelbubble.qml +++ b/basicsuite/sensors/Accelbubble.qml @@ -41,90 +41,68 @@ import QtQuick 2.0 import QtSensors 5.0 -Item { - function calc() { - if (xAnimation.running || yAnimation.running) - return +Rectangle { + id: area + color: "lightblue" + border.width: 1 + border.color: "darkblue" + property real velocityX: 0 + property real velocityY: 0 - var newX = (bubble.x + calcRoll(accel.reading.x, accel.reading.y, accel.reading.z) * .8) - var newY = (bubble.y - calcPitch(accel.reading.x, accel.reading.y, accel.reading.z) * .8) + function updatePosition() { + velocityX += accel.reading.y + velocityY += accel.reading.x - if (newX < 0) + velocityX *= 0.95 + velocityY *= 0.95 + + var newX = bubble.x + velocityX + var newY = bubble.y + velocityY + var right = area.width - bubble.width + var bottom = area.height - bubble.height + + if (newX < 0) { newX = 0 - if (newY < 0) + velocityX = -velocityX * 0.9 + } + if (newY < 0) { newY = 0 + velocityY = -velocityY * 0.9 + } - var right = field.width - bubble.width - var bottom = field.height - bubble.height - - if (newX > right) + if (newX > right) { newX = right - if (newY > bottom) + velocityX = -velocityX * 0.9 + } + if (newY > bottom) { newY = bottom + velocityY = -velocityY * 0.9 + } bubble.x = newX bubble.y = newY - - yBehavior.enabled = true - xBehavior.enabled = true } - Rectangle { - id: field - color: "lightblue" - border.width: 1 - border.color: "darkblue" - width: parent.width - height: parent.height - Accelerometer { - id: accel - active:true - } - - Timer { - interval: 100 - running: true - repeat: true - onTriggered: calc() - } + Accelerometer { + id: accel + active:true + } - Image { - id: bubble - source: "bluebubble.png" - property real centerX: parent.width / 2 - property real centerY: parent.height / 2; - property real bubbleCenter: bubble.width / 2 - x: centerX - bubbleCenter - y: centerY - bubbleCenter - smooth: true + Component.onCompleted: timer.running = true - Behavior on y { - id: yBehavior - enabled: false - SmoothedAnimation { - id: yAnimation - easing.type: Easing.Linear - duration: 40 - onRunningChanged: calc() - } - } - Behavior on x { - id: xBehavior - enabled: false - SmoothedAnimation { - id: xAnimation - easing.type: Easing.Linear - duration: 40 - onRunningChanged: calc() - } - } - } + Timer { + id: timer + interval: 16 + running: false + repeat: true + onTriggered: updatePosition() } - function calcPitch(x,y,z) { - return Math.atan(y / Math.sqrt(x*x + z*z)) * 57.2957795; - } - function calcRoll(x,y,z) { - return Math.atan(x / Math.sqrt(y*y + z*z)) * 57.2957795; + Image { + id: bubble + source: "bluebubble.png" + smooth: true + x: parent.width/2 - bubble.width/2 + y: parent.height/2 - bubble.height/2 } } diff --git a/basicsuite/sensors/Light.qml b/basicsuite/sensors/Light.qml index 0cff8e6..24f3bd9 100644 --- a/basicsuite/sensors/Light.qml +++ b/basicsuite/sensors/Light.qml @@ -41,50 +41,47 @@ 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 - } +Rectangle { + id: bg + Image { + id: avatar + width: parent.width * 0.9 + height: parent.height * 0.9 + fillMode: Image.PreserveAspectFit + anchors.centerIn: parent + } + Text { + id: illuminanceLevel + font.pointSize: 20 + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + anchors.bottomMargin: 60 + } - 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" - } + AmbientLightSensor { + active: true + onReadingChanged: { + if (reading.lightLevel === AmbientLightReading.Dark) { + avatar.source = "3.png" + bg.color = "#1947A3" + } 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 = "#FFFF75" + } else { + avatar.text = "Unknown light level" } } + } - LightSensor { - active: true - onReadingChanged: { - illuminanceLevel.text = "Illuminance: " + reading.illuminance.toFixed(2); - } + LightSensor { + active: true + onReadingChanged: { + illuminanceLevel.text = "Illuminance: " + reading.illuminance.toFixed(2); } } } diff --git a/basicsuite/sensors/main.qml b/basicsuite/sensors/main.qml index b5a1207..d6e0e9d 100644 --- a/basicsuite/sensors/main.qml +++ b/basicsuite/sensors/main.qml @@ -42,30 +42,30 @@ import QtQuick 2.0 import QtSensors 5.0 import QtSensors 5.0 as Sensors -Item { +Rectangle { id: root - width: 800 - height: 1280 + anchors.fill: parent Component { id: sensorExample Rectangle { id: main - width: root.height - height: root.width - rotation: 90 + width: root.width + height: root.height + anchors.centerIn: parent + color: "blue" border.width: 1 + Accelbubble { + id: bubble + width: parent.width / 2 + height: parent.height + } Light { - id: lys - width: main.width - height: main.height / 2 + anchors.left: bubble.right + width: parent.width / 2 + height: parent.height } - Accelbubble { - width: main.width - height: main.height / 2 - anchors.top: lys.bottom - } } } @@ -74,10 +74,14 @@ Item { Rectangle { width: root.width height: root.height + color: "black" Text { - font.pixelSize: 22 + font.pixelSize: 80 + width: parent.width * 0.8 anchors.centerIn: parent + color: "white" text: "It appears that this device doesn't provide the required sensors!" + wrapMode: Text.WordWrap } } } diff --git a/basicsuite/sensors/preview_l.jpg b/basicsuite/sensors/preview_l.jpg Binary files differindex 7ce979d..d87d757 100644 --- a/basicsuite/sensors/preview_l.jpg +++ b/basicsuite/sensors/preview_l.jpg |