From 72e653a856a9ccbd48eacf8687518b3acb4f657f Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 31 Aug 2018 15:41:12 +0200 Subject: [PATCH] Initial import --- Info.plist | 34 +++++++++ accelbubble.pro | 28 ++++++++ accelbubble.qml | 133 ++++++++++++++++++++++++++++++++++++ accelbubble.qrc | 6 ++ android/AndroidManifest.xml | 48 +++++++++++++ content/Bluebubble.svg | 10 +++ doc/images/accelbubble.png | Bin 0 -> 5025 bytes doc/src/accelbubble.qdoc | 56 +++++++++++++++ main.cpp | 61 +++++++++++++++++ 9 files changed, 376 insertions(+) create mode 100644 Info.plist create mode 100644 accelbubble.pro create mode 100644 accelbubble.qml create mode 100644 accelbubble.qrc create mode 100644 android/AndroidManifest.xml create mode 100644 content/Bluebubble.svg create mode 100644 doc/images/accelbubble.png create mode 100644 doc/src/accelbubble.qdoc create mode 100644 main.cpp 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 0000000000000000000000000000000000000000..ad4cfc0765563e95192a3b486acdb3cfd0c361a4 GIT binary patch literal 5025 zcmd5E_tsHH*dA&KYxb^m$u{(3X_otZQ9%{S-FeCPK&XU_MfSluz^=Mm@O;Najl zH8HT};P_4PX#T~`dBi-|=%;aToc1v_xDAaY)25FZ zG8YWbj6PNpSq9mKJ+U^pduSr($!nbtmumzW)>OQ#zgJ;<_Ve4%d4@g|!}u_{``w@{ z_%m7R#UzP~NvB0-`XjxjYdU|%UP&=cDYi0zZL)kk5NU7Rya=1RBQX}&_&FX`kKnMO z*cA=PVfWz%HSSArQAo=t_eTZ9`dSnUg~iH8VU6!X70<;)NADjT^v~O&{o$R9j&U&i zomsoM>r8q{_pD%N*ZBt}JKMh|8j_Nd#+Diz?mzS3hR@(xnTElgrFQUSnG3wsK zuMAU<=#Z8oIHejYj~UU@(9qD*%IKx~ZA)}U(5D0|fD_OgHsQT>X4xI+87z})u*qNi z4dR}am?|n1Bf#2ZO==8It)E7^X=d*z_XL<3Fk+ zM>d{lkF)cYoHN%j%U4`&LZ_5O5i1mmtuhHw=Q)q@ZJpI@+6i=`9Da*~g78yZGl%pp z9sgF>$RDq6F(}>B@TDC?WA=9SXr`G>pRZO8fqo43;^w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+CwE*Y#i0Zv2B2++G;(d*kQGXhI^1DmS(641GxAn3#2=SW)aZdKwgD-+R z+vj$6(JD!~Xtd0Cn z?&xoeD;y&F&pF)xF74lC`(HTm_=4`y@Zy-?u49A)$c+U@AY%)me3S_O9$op#?%yia z#;&P!GD8?1lqR^FSV)r4?AF@{e$WQ7Q1n87H4aB$@2}*mxCT&~5dE9& z>F2cwo5MQCjvbp1iF!K2hRVxoA%EEMJC6(guG{QAQsTQW=8zXo!;gO>kviyo=cT2k zvz-_U_x|$Cca9j*+toc}ZjLo}O*D9`IJbtenT!coQ$xdMuc+%J-aj94IBKqvD-}$_ z-g^RaI|{vy?*nqZ*K=5%s(fWf895oh~ zUgvrXB3Y}m+AN(vsJHn^eJmVRy~04aEXc7~tZdvF0!VsR>HXyB=xE4V$L<}3MigLm zc{%z>1U2PmcmR`MYw~U24542#uH9Y{xo}p-B&wH|*1_Bud_NUIfoM%#3%>+|!4O+t zjIYGrAX?mWxr9M%3;@;<+2aP|;Ylb|@_Nou$POPa(mrZM3~PJb(;>XFWA? z+hPxPs?|F(tJWr5;}U-EN6DCfYiLgpMiVSGM>btzXc`46d;$V@2#=U%@E4hQ_L$`@ zrSO4P2bYIekg{lNG@xJQkigRvFjWZKE3Wjo+u%R093_!S$8cMYpVeV_#>U3N;j}#k z4`6}kVBSFN`?y1Pb!da9hd&&in@?&0%#_;~q?U|*WXv;FJ{?8;1V>qw)OsJwn-~Jc z(2|fm6F%--&x~5Gu8NM1P7b +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc,argv); + QQmlApplicationEngine engine(QUrl("qrc:///accelbubble.qml")); + + return app.exec(); +}