diff options
author | Leena Miettinen <riitta-leena.miettinen@digia.com> | 2013-10-28 11:10:55 +0100 |
---|---|---|
committer | Leena Miettinen <riitta-leena.miettinen@digia.com> | 2013-10-29 15:22:17 +0100 |
commit | 48fb32e0fe48226f59b6bf4008346281e12b82ef (patch) | |
tree | 22d2249507875dcc7c6d70f82314c5bf49b7a8dd /doc/examples | |
parent | bad74c6b558e817daf384df8eeb2d091d75d6fbd (diff) | |
download | qt-creator-48fb32e0fe48226f59b6bf4008346281e12b82ef.tar.gz |
Doc: update the Android tutorial
Use the Qt Quick Controls application wizard to
streamline the process.
Remove snippet files and store compilable example code
in doc/examples. Do not store generated files.
Change-Id: I920484e84b2ef23bce9e77a7b0eddf963fe94552
Reviewed-by: Venugopal Shivashankar <venugopal.shivashankar@digia.com>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/accelbubble/main.qml | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/doc/examples/accelbubble/main.qml b/doc/examples/accelbubble/main.qml new file mode 100644 index 0000000000..313be9cd70 --- /dev/null +++ b/doc/examples/accelbubble/main.qml @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (c) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator +** +** +** GNU Free Documentation License +** +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of this +** file. +** +** +****************************************************************************/ + +// ********************************************************************** +// NOTE: the sections are not ordered by their logical order to avoid +// reshuffling the file each time the index order changes (i.e., often). +// Run the fixnavi.pl script to adjust the links to the index order. +// ********************************************************************** + +import QtQuick 2.1 +import QtQuick.Controls 1.0 + +import QtSensors 5.0 + +ApplicationWindow { + title: qsTr("Accelerate Bubble") + id: mainWindow + width: 640 + height: 480 + visible: true + + Accelerometer { + id: accel + dataRate: 100 + active:true + + onReadingChanged: { + var newX = (bubble.x + calcRoll(accel.reading.x, accel.reading.y, accel.reading.z) * 0.1) + var newY = (bubble.y - calcPitch(accel.reading.x, accel.reading.y, accel.reading.z) * 0.1) + + if (newX < 0) + newX = 0 + + if (newX > mainWindow.width - bubble.width) + newX = mainWindow.width - bubble.width + + if (newY < 18) + newY = 18 + + if (newY > mainWindow.height - bubble.height) + newY = mainWindow.height - bubble.height + + bubble.x = newX + bubble.y = newY + } + } + + 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.svg" + smooth: true + property real centerX: mainWindow.width / 2 + property real centerY: mainWindow.height / 2 + property real bubbleCenter: bubble.width / 2 + x: centerX - bubbleCenter + y: centerY - bubbleCenter + + Behavior on y { + SmoothedAnimation { + easing.type: Easing.Linear + duration: 100 + } + } + Behavior on x { + SmoothedAnimation { + easing.type: Easing.Linear + duration: 100 + } + } + + MenuBar { + Menu { + title: qsTr("File") + MenuItem { + text: qsTr("Exit") + onTriggered: Qt.quit(); + } + } + } + } +} |