commit 72e653a856a9ccbd48eacf8687518b3acb4f657f Author: Martchus Date: Fri Aug 31 15:41:12 2018 +0200 Initial import diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000..9072545 --- /dev/null +++ b/Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDisplayName + accelbubble + CFBundleExecutable + accelbubble + CFBundleGetInfoString + Created by Qt/QMake + CFBundleIdentifier + com.digia.accelbubble + CFBundleName + accelbubble + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + NOTE + This file was generated by Qt/QMake. + UILaunchStoryboardName + LaunchScreen + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + + diff --git a/accelbubble.pro b/accelbubble.pro new file mode 100644 index 0000000..d3b20a9 --- /dev/null +++ b/accelbubble.pro @@ -0,0 +1,28 @@ +TEMPLATE = app +TARGET = accelbubble +QT += quick sensors svg xml +SOURCES = main.cpp + +RESOURCES += \ + accelbubble.qrc + +OTHER_FILES = \ + $$files(*.qml) \ + content \ + images \ + android/AndroidManifest.xml + +target.path = $$[QT_INSTALL_EXAMPLES]/sensors/accelbubble +INSTALLS += target + +ios { +QMAKE_INFO_PLIST = Info.plist + +# manual plugin loading needed with older Qt +# QTPLUGIN += qsvg qtsensors_ios qtsensors_generic +} + +ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android + +EXAMPLE_FILES += \ + Info.plist diff --git a/accelbubble.qml b/accelbubble.qml new file mode 100644 index 0000000..f26179f --- /dev/null +++ b/accelbubble.qml @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +import QtQuick 2.1 +import QtQuick.Controls 1.0 + +//! [0] +import QtSensors 5.0 +//! [0] + + +ApplicationWindow { + title: "Accelerate Bubble" + id: mainWindow + width: 320 + height: 480 + visible: true + readonly property double radians_to_degrees: 180 / Math.PI + +//! [1] + Accelerometer { + id: accel + dataRate: 100 +//! [1] +//! [2] + active:true +//! [2] + +//! [3] + onReadingChanged: { + var newX = (bubble.x + calcRoll(accel.reading.x, accel.reading.y, accel.reading.z) * .1) + var newY = (bubble.y - calcPitch(accel.reading.x, accel.reading.y, accel.reading.z) * .1) + + if (isNaN(newX) || isNaN(newY)) + return; + + 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 + } +//! [3] + } + + function calcPitch(x,y,z) { + return -Math.atan2(y, Math.sqrt(x * x + z * z)) * mainWindow.radians_to_degrees; + } + function calcRoll(x,y,z) { + return -Math.atan2(x, Math.sqrt(y * y + z * z)) * mainWindow.radians_to_degrees; + } + + Image { + id: bubble + source: "content/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 + } + } + } +} diff --git a/accelbubble.qrc b/accelbubble.qrc new file mode 100644 index 0000000..5cb6945 --- /dev/null +++ b/accelbubble.qrc @@ -0,0 +1,6 @@ + + + accelbubble.qml + content/Bluebubble.svg + + diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml new file mode 100644 index 0000000..cf71b28 --- /dev/null +++ b/android/AndroidManifest.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/content/Bluebubble.svg b/content/Bluebubble.svg new file mode 100644 index 0000000..d9c406c --- /dev/null +++ b/content/Bluebubble.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/doc/images/accelbubble.png b/doc/images/accelbubble.png new file mode 100644 index 0000000..ad4cfc0 Binary files /dev/null and b/doc/images/accelbubble.png differ diff --git a/doc/src/accelbubble.qdoc b/doc/src/accelbubble.qdoc new file mode 100644 index 0000000..0247357 --- /dev/null +++ b/doc/src/accelbubble.qdoc @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example accelbubble + \title Qt Sensors - Accel Bubble + \brief The AccelBubble example demonstrates the Accelerometer QML type. + \ingroup qtsensors-examples + + \image accelbubble.png + +\section1 Overview + Writing a QML application that uses the Accelerometer QML sensors type requires the following steps: + + Import the Sensors Declarative module. + +\snippet accelbubble/accelbubble.qml 0 + + Add an Accelerometer QML type. + +\snippet accelbubble/accelbubble.qml 1 + + Use the 'active' property to start the sensor + +\snippet accelbubble/accelbubble.qml 2 + + Move the bubble according to a factor of the accelerator sensor + +\snippet accelbubble/accelbubble.qml 3 + +*/ + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e7ccc07 --- /dev/null +++ b/main.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc,argv); + QQmlApplicationEngine engine(QUrl("qrc:///accelbubble.qml")); + + return app.exec(); +}