summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTamas Martinec <tamas.martinec@symbio.com>2021-10-26 16:13:51 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-11-12 08:58:48 +0000
commitd3f7ab59f37594eb3ad772819b2396c1dfbde663 (patch)
treea38dbfd3b51ae5ce769a96f9428041943dc8e278
parent4974e80ed780b94a716d6e73a83d3a8764a0dcae (diff)
QtSensors: Create a sensors showcase example
Create an example that demonstrates the sensor module sensors more visually than just displaying the sensor reading values. Task-number: QTBUG-72329 Change-Id: I7383722124c3aae333cf9218613d7001c9d04690 Reviewed-by: Juha Vuolle <juha.vuolle@insta.fi> (cherry picked from commit 851ec98b341ed8ad67caac32653178e0bb189bfe) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/sensors/CMakeLists.txt1
-rw-r--r--examples/sensors/sensorsshowcase/CMakeLists.txt63
-rw-r--r--examples/sensors/sensorsshowcase/Info.plist32
-rw-r--r--examples/sensors/sensorsshowcase/accelerometer.qml169
-rw-r--r--examples/sensors/sensorsshowcase/android/AndroidManifest.xml47
-rw-r--r--examples/sensors/sensorsshowcase/compass.qml111
-rw-r--r--examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.pngbin0 -> 29205 bytes
-rw-r--r--examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.pngbin0 -> 33722 bytes
-rw-r--r--examples/sensors/sensorsshowcase/doc/src/sensorsshowcase.qdoc95
-rw-r--r--examples/sensors/sensorsshowcase/gyroscope.qml221
-rw-r--r--examples/sensors/sensorsshowcase/images/compass.svg222
-rw-r--r--examples/sensors/sensorsshowcase/images/magnet.svg98
-rw-r--r--examples/sensors/sensorsshowcase/images/qt_logo.pngbin0 -> 6208 bytes
-rw-r--r--examples/sensors/sensorsshowcase/magnetometer.qml150
-rw-r--r--examples/sensors/sensorsshowcase/main.cpp61
-rw-r--r--examples/sensors/sensorsshowcase/proximity.qml118
-rw-r--r--examples/sensors/sensorsshowcase/sensorsshowcase.pro27
-rw-r--r--examples/sensors/sensorsshowcase/sensorsshowcase.qml123
-rw-r--r--examples/sensors/sensorsshowcase/sensorsshowcase.qrc13
19 files changed, 1551 insertions, 0 deletions
diff --git a/examples/sensors/CMakeLists.txt b/examples/sensors/CMakeLists.txt
index 329ae504..7fe6c4e9 100644
--- a/examples/sensors/CMakeLists.txt
+++ b/examples/sensors/CMakeLists.txt
@@ -7,6 +7,7 @@ if(TARGET Qt::Quick)
# add_subdirectory(shakeit)
if(TARGET Qt::Svg)
add_subdirectory(accelbubble)
+ add_subdirectory(sensorsshowcase)
endif()
endif()
# if(TARGET Qt::Widgets)
diff --git a/examples/sensors/sensorsshowcase/CMakeLists.txt b/examples/sensors/sensorsshowcase/CMakeLists.txt
new file mode 100644
index 00000000..b034dff6
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/CMakeLists.txt
@@ -0,0 +1,63 @@
+cmake_minimum_required(VERSION 3.16)
+project(sensorsshowcase LANGUAGES CXX)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+set(CMAKE_AUTOUIC ON)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
+endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sensors/sensorsshowcase")
+
+find_package(Qt6 COMPONENTS Core Gui Quick Sensors Svg)
+
+qt_add_executable(sensorsshowcase
+ main.cpp
+)
+set_target_properties(sensorsshowcase PROPERTIES
+ WIN32_EXECUTABLE TRUE
+ MACOSX_BUNDLE TRUE
+)
+
+if(ANDROID)
+set_property(TARGET sensorsshowcase APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
+ ${CMAKE_CURRENT_SOURCE_DIR}/android)
+endif()
+
+target_link_libraries(sensorsshowcase PUBLIC
+ Qt::Core
+ Qt::Gui
+ Qt::Quick
+ Qt::Sensors
+ Qt::Svg
+)
+
+# Resources:
+set(sensorsshowcase_resource_files
+ "sensorsshowcase.qml"
+ "accelerometer.qml"
+ "proximity.qml"
+ "compass.qml"
+ "magnetometer.qml"
+ "gyroscope.qml"
+ "images/magnet.svg"
+ "images/compass.svg"
+ "images/qt_logo.png"
+)
+
+qt6_add_resources(sensorsshowcase "sensorsshowcase"
+ PREFIX
+ "/"
+ FILES
+ ${sensorsshowcase_resource_files}
+)
+
+install(TARGETS sensorsshowcase
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/examples/sensors/sensorsshowcase/Info.plist b/examples/sensors/sensorsshowcase/Info.plist
new file mode 100644
index 00000000..61d01e5a
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/Info.plist
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDisplayName</key>
+ <string>sensorsshowcase</string>
+ <key>CFBundleExecutable</key>
+ <string>sensorsshowcase</string>
+ <key>CFBundleGetInfoString</key>
+ <string>Created by Qt/QMake</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.qt.sensorsshowcase</string>
+ <key>CFBundleName</key>
+ <string>sensorsshowcase</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UILaunchStoryboardName</key>
+ <string>LaunchScreen</string>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ </array>
+</dict>
+</plist>
diff --git a/examples/sensors/sensorsshowcase/accelerometer.qml b/examples/sensors/sensorsshowcase/accelerometer.qml
new file mode 100644
index 00000000..df7c7f1e
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/accelerometer.qml
@@ -0,0 +1,169 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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
+import QtQuick.Controls
+import QtQuick.Layouts
+import QtSensors
+
+Rectangle {
+ id: root
+ color: "dimgray"
+
+ function resetRotations() {
+ imageXRotation.angle = 0
+ imageYRotation.angle = 0
+ imageZRotation.angle = 0
+ }
+
+//! [0]
+ Accelerometer {
+ id: accelerometer
+ active: true
+ dataRate: 25
+
+ property real x: 0
+ property real y: 0
+ property real z: 0
+
+ onReadingChanged: {
+ x = reading.x
+ y = reading.y
+ z = reading.z
+
+ imageTranslation.x = -reading.x * 10
+ imageTranslation.y = reading.y * 10
+ }
+ }
+//! [0]
+
+ ColumnLayout {
+ anchors.fill: parent
+ id: layout
+
+ Text {
+ Layout.topMargin: titleTopMargin
+ Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
+ Layout.preferredHeight: textHeight
+ color: "White"
+ text: "Accelerometer"
+ font.pixelSize: titleFontSize
+ }
+
+ Image {
+ id: image
+ Layout.alignment: Qt.AlignCenter
+ Layout.fillHeight: true
+ Layout.preferredWidth: root.width/2
+ Layout.preferredHeight: root.height/3
+ source: "qrc:/images/qt_logo.png"
+ fillMode: Image.PreserveAspectFit
+
+ transform: [
+ Translate {
+ id: imageTranslation
+ x: 0
+ y: 0
+ }
+ ]
+ }
+
+ Text {
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "X: " + accelerometer.x.toFixed(2)
+ font.pixelSize: textFontSize
+ }
+
+ ProgressBar {
+ id: xbar
+ value: 0.5 + (accelerometer.x / 100)
+ Layout.preferredWidth: root.width
+ }
+
+ Text {
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "Y: " + accelerometer.y.toFixed(2)
+ font.pixelSize: textFontSize
+ }
+ ProgressBar {
+ id: ybar
+ value: 0.5 + (accelerometer.y / 100)
+ Layout.preferredWidth: root.width
+ }
+ Text {
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "Z: " + accelerometer.z.toFixed(2)
+ font.pixelSize: textFontSize
+ }
+ ProgressBar {
+ id: zbar
+ value: 0.5 + (accelerometer.z / 100)
+ Layout.preferredWidth: root.width
+ }
+ Button {
+ Layout.alignment: Qt.AlignBottom
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: buttonHeight
+ text:"Back"
+ font.pixelSize: buttonFontSize
+ onClicked:stack.pop()
+ }
+ }
+}
+
diff --git a/examples/sensors/sensorsshowcase/android/AndroidManifest.xml b/examples/sensors/sensorsshowcase/android/AndroidManifest.xml
new file mode 100644
index 00000000..3c152a90
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/android/AndroidManifest.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.qtproject.example.sensorsshowcase"
+ android:installLocation="auto"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <!-- The comment below will be replaced with dependencies permissions upon deployment.
+ Remove the comment if you do not require these default permissions. -->
+ <!-- %%INSERT_PERMISSIONS -->
+
+ <!-- The comment below will be replaced with dependencies permissions upon deployment.
+ Remove the comment if you do not require these default features. -->
+ <!-- %%INSERT_FEATURES -->
+
+ <supports-screens
+ android:anyDensity="true"
+ android:largeScreens="true"
+ android:normalScreens="true"
+ android:smallScreens="true" />
+ <application
+ android:name="org.qtproject.qt.android.bindings.QtApplication"
+ android:extractNativeLibs="true"
+ android:hardwareAccelerated="true"
+ android:label="-- %%INSERT_APP_NAME%% --"
+ android:requestLegacyExternalStorage="true">
+ <activity
+ android:name="org.qtproject.qt.android.bindings.QtActivity"
+ android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
+ android:label="-- %%INSERT_APP_NAME%% --"
+ android:launchMode="singleTop"
+ android:screenOrientation="portrait">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data
+ android:name="android.app.lib_name"
+ android:value="-- %%INSERT_APP_LIB_NAME%% --" />
+ <meta-data
+ android:name="android.app.background_running"
+ android:value="false" />
+ <meta-data
+ android:name="android.app.extract_android_style"
+ android:value="minimal" />
+ </activity>
+ </application>
+</manifest>
diff --git a/examples/sensors/sensorsshowcase/compass.qml b/examples/sensors/sensorsshowcase/compass.qml
new file mode 100644
index 00000000..b0fee5e4
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/compass.qml
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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
+import QtQuick.Controls
+import QtQuick.Layouts
+import QtSensors
+
+Rectangle {
+ id: root
+ color: "dimgray"
+ property real azimuth: 30
+ readonly property real buttonHeight: height/8
+
+ Compass {
+ id: compass
+ active: true
+ dataRate: 7
+ onReadingChanged: {
+ root.azimuth = -reading.azimuth
+ }
+ }
+
+ ColumnLayout {
+ anchors.fill: parent
+ id: layout
+
+ Text {
+ Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
+ Layout.preferredHeight: titleHeight
+ Layout.topMargin: titleTopMargin
+ verticalAlignment: Text.AlignVCenter
+ color: "White"
+ text: "Compass"
+ font.pixelSize: titleFontSize
+ }
+ Image {
+ Layout.alignment: Qt.AlignCenter
+ Layout.fillHeight: true
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: root.height
+ id: arrow
+ source: "qrc:/images/compass.svg"
+ fillMode: Image.PreserveAspectFit
+ rotation:root.azimuth
+ }
+ Text {
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "Azimuth: " + root.azimuth.toFixed(2) + "°"
+ font.pixelSize: textFontSize
+ }
+ Button {
+ Layout.alignment: Qt.AlignBottom
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: buttonHeight
+ text:"Back"
+ font.pixelSize: buttonFontSize
+ onClicked:stack.pop()
+ }
+ }
+}
diff --git a/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.png b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.png
new file mode 100644
index 00000000..b26aa459
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.png
Binary files differ
diff --git a/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.png b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.png
new file mode 100644
index 00000000..838b39c9
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.png
Binary files differ
diff --git a/examples/sensors/sensorsshowcase/doc/src/sensorsshowcase.qdoc b/examples/sensors/sensorsshowcase/doc/src/sensorsshowcase.qdoc
new file mode 100644
index 00000000..b845d5d7
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/doc/src/sensorsshowcase.qdoc
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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 sensorsshowcase
+ \title Qt Sensors - Sensors Showcase
+ \brief The Sensors Showcase example demonstrates sensor usage with visual examples.
+ \ingroup qtsensors-examples
+
+ \image sensorsshowcase-mainview.png
+
+ \section1 Overview
+
+ On startup, the application shows a menu with buttons for the subviews for each sensor.
+ The sensor views instantiate the given sensor, display the sensor's values as numbers,
+ and also visualize them with a simple graphical representation.
+
+ \section1 Main Menu
+
+ The main view shows the title with the name of the application and a button for each
+ subview laid out evenly by a \c ColumnLayout. The navigation between the subviews
+ and the main menu is managed by a \c StackView.
+
+ \section1 Accelerometer View
+
+ The accelerometer view shows the current device acceleration values and moves around
+ an image with an amount that is opposite of the device acceleration giving the image
+ an inertia effect that is proportional with the movement of the device.
+
+ Moving around the image happens in the accelerometer \c onReadingChanged method.
+
+ \snippet sensorsshowcase/accelerometer.qml 0
+
+ Whenever there is a new accelerometer value the image translation coordinates are
+ updated accordingly.
+
+ \section1 Proximity View
+
+ The proximity view shows an image that is enlarged whenever the proximity sensor of
+ the device is covered.
+
+ \section1 Compass View
+
+ The compass view shows a compass image that is rotated according to the Compass sensor
+ reading value making the compass turn towards north.
+
+ \section1 Magnetometer View
+
+ The magnetometer view displays a magnet image that is rotated around an amount that is
+ decided by the rotation angle of the vector given by the x and y magnetometer values.
+ This results in general in the same rotation as the compass gives, demonstrating one use
+ case of how the magnetometer readings can be used. Since the magnetometer provides
+ readings along all three axes, there is more freedom with how these readings can be used.
+
+ \snippet sensorsshowcase/magnetometer.qml 0
+
+ \section1 Gyroscope View
+
+ \image sensorsshowcase-gyroscope.png
+
+ The gyroscope view also shows an image that is rotated around three axes with an amount
+ that is calculated from the gyroscope readings. Since the gyroscope provides relative
+ rotational change around the three spatial axes and the time between reading updates
+ can vary, the time of the readings are stored and the rotational change is normalized
+ based on the time passed between reading updates.
+
+ \snippet sensorsshowcase/gyroscope.qml 0
+
+ By pressing the reset button the image rotation is reset to 0.
+*/
+
diff --git a/examples/sensors/sensorsshowcase/gyroscope.qml b/examples/sensors/sensorsshowcase/gyroscope.qml
new file mode 100644
index 00000000..1575255c
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/gyroscope.qml
@@ -0,0 +1,221 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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
+import QtQuick.Controls
+import QtQuick.Layouts
+import QtSensors
+
+Rectangle {
+ id: root
+ color: "dimgray"
+
+ function resetRotations() {
+ imageXRotation.angle = 0
+ imageYRotation.angle = 0
+ imageZRotation.angle = 0
+ }
+
+//! [0]
+ Gyroscope {
+ id: gyroscope
+ active: true
+ dataRate: 25
+
+ property variant lastTimeStamp: 0
+
+ property real x: 0
+ property real y: 0
+ property real z: 0
+
+ onReadingChanged: {
+
+ x = reading.x
+ y = reading.y
+ z = reading.z
+
+ var firstCall = false
+ if (lastTimeStamp == 0) {
+ firstCall = true
+ }
+
+ var timeSinceLast = reading.timestamp - lastTimeStamp
+ lastTimeStamp = reading.timestamp
+
+ //Skipping the initial time jump from 0
+ if (firstCall === true) return
+
+ var normalizedX = reading.x * (timeSinceLast/1000000)
+ imageXRotation.angle += normalizedX
+
+ var normalizedY = reading.y * (timeSinceLast/1000000)
+ imageYRotation.angle -= normalizedY
+
+ var normalizedZ = reading.z * (timeSinceLast/1000000)
+ imageZRotation.angle += normalizedZ
+ }
+ }
+//! [0]
+
+ ColumnLayout {
+ anchors.fill: parent
+ id: layout
+
+ Text {
+ Layout.topMargin: titleTopMargin
+ Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
+ Layout.preferredHeight: textHeight
+ color: "White"
+ text: "Gyroscope"
+ font.pixelSize: titleFontSize
+ }
+
+ Image {
+ id: image
+ Layout.alignment: Qt.AlignCenter
+ Layout.fillHeight: true
+ Layout.preferredWidth: root.height/3
+ Layout.preferredHeight: root.height/3
+ source: "qrc:/images/qt_logo.png"
+ fillMode: Image.PreserveAspectFit
+
+ transform: [
+ Rotation {
+ id: imageXRotation
+ origin.x: layout.width/2
+ origin.y: layout.height/3
+ axis.x: 1
+ axis.y: 0
+ axis.z: 0
+ angle: 0
+ },
+ Rotation {
+ id: imageYRotation
+ origin.x: layout.width/2
+ origin.y: layout.height/3
+ axis.x: 0
+ axis.y: 1
+ axis.z: 0
+ angle: 0
+ },
+ Rotation {
+ id: imageZRotation
+ origin.x: layout.width/2
+ origin.y: layout.height/3
+ axis.x: 0
+ axis.y: 0
+ axis.z: 1
+ angle: 0
+ }
+ ]
+ }
+
+ Text {
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "X: " + gyroscope.x.toFixed(2)
+ font.pixelSize: textFontSize
+ }
+
+ ProgressBar {
+ id: xbar
+ value: 0.5 + (gyroscope.x / 1000)
+ Layout.preferredWidth: root.width
+ }
+
+ Text {
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "Y: " + gyroscope.y.toFixed(2)
+ font.pixelSize: textFontSize
+ }
+ ProgressBar {
+ id: ybar
+ value: 0.5 + (gyroscope.y / 1000)
+ Layout.preferredWidth: root.width
+ }
+ Text {
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "Z: " + gyroscope.z.toFixed(2)
+ font.pixelSize: textFontSize
+ }
+ ProgressBar {
+ id: zbar
+ value: 0.5 + (gyroscope.z / 1000)
+ Layout.preferredWidth: root.width
+ }
+ Button {
+ Layout.alignment: Qt.AlignBottom
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: buttonHeight
+ text:"Reset rotation"
+ font.pixelSize: buttonFontSize
+ onClicked: {
+ resetRotations()
+ }
+ }
+ Button {
+ Layout.alignment: Qt.AlignBottom
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: buttonHeight
+ text:"Back"
+ font.pixelSize: buttonFontSize
+ onClicked:stack.pop()
+ }
+ }
+}
+
diff --git a/examples/sensors/sensorsshowcase/images/compass.svg b/examples/sensors/sensorsshowcase/images/compass.svg
new file mode 100644
index 00000000..009e6ffd
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/images/compass.svg
@@ -0,0 +1,222 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ width="123.29776mm"
+ height="123.29776mm"
+ viewBox="0 0 123.29776 123.29776"
+ version="1.1"
+ id="svg5"
+ inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
+ sodipodi:docname="compass.svg"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg">
+ <sodipodi:namedview
+ id="namedview7"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageshadow="2"
+ inkscape:pageopacity="0.0"
+ inkscape:pagecheckerboard="0"
+ inkscape:document-units="mm"
+ showgrid="false"
+ showborder="true"
+ inkscape:zoom="1.5554293"
+ inkscape:cx="118.61677"
+ inkscape:cy="123.76005"
+ inkscape:window-width="2560"
+ inkscape:window-height="1377"
+ inkscape:window-x="1912"
+ inkscape:window-y="72"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="layer1"
+ lock-margins="true"
+ fit-margin-top="15"
+ fit-margin-left="15"
+ fit-margin-right="15"
+ fit-margin-bottom="15" />
+ <defs
+ id="defs2" />
+ <g
+ inkscape:groupmode="layer"
+ id="layer2"
+ inkscape:label="Layer 2"
+ style="display:inline"
+ transform="translate(7.215891,-13.196477)">
+ <path
+ sodipodi:type="star"
+ style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.88976;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path2691"
+ inkscape:flatsided="false"
+ sodipodi:sides="4"
+ sodipodi:cx="131.1535"
+ sodipodi:cy="547.11584"
+ sodipodi:r1="75.011292"
+ sodipodi:r2="15.353019"
+ sodipodi:arg1="0.77933767"
+ sodipodi:arg2="1.5647358"
+ inkscape:rounded="0"
+ inkscape:randomized="0"
+ d="m 184.51497,599.83441 -53.26842,-37.36583 -52.811613,38.00874 37.365833,-53.26843 -38.008738,-52.81161 53.268428,37.36583 52.81161,-38.00874 -37.36583,53.26843 z"
+ transform="matrix(0.45357635,0,0,0.48302392,-5.0551384,-189.42468)" />
+ <circle
+ style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path25062"
+ cx="54.432987"
+ cy="74.84536"
+ r="30" />
+ <circle
+ style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.579683;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="circle25206"
+ cx="54.432987"
+ cy="74.84536"
+ r="34.780952" />
+ </g>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ style="display:inline"
+ transform="translate(7.215891,-13.196477)">
+ <path
+ sodipodi:type="star"
+ style="fill:none;stroke:#000000;stroke-width:1.88976;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path846"
+ inkscape:flatsided="false"
+ sodipodi:sides="4"
+ sodipodi:cx="205.73099"
+ sodipodi:cy="282.8801"
+ sodipodi:r1="176.15717"
+ sodipodi:r2="35.231434"
+ sodipodi:arg1="1.5707963"
+ sodipodi:arg2="2.3561945"
+ inkscape:rounded="0"
+ inkscape:randomized="0"
+ d="M 205.73099,459.03726 180.8186,307.79248 29.573822,282.8801 180.8186,257.96771 l 24.91238,-151.24478 24.91239,151.24478 151.24478,24.91238 -151.24478,24.91239 z"
+ transform="scale(0.26458333)" />
+ <path
+ style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="m 54.432988,28.237108 2e-6,93.216502"
+ id="path991" />
+ <path
+ style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="m 7.8247403,74.845359 93.2164997,-3e-6"
+ id="path993" />
+ <path
+ style="fill:none;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 47.841587,68.253956 C 61.024391,81.436759 61.024391,81.436759 61.024391,81.436759"
+ id="path995" />
+ <path
+ style="fill:#ff0000;stroke:#000000;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ d="M 61.024391,68.253956 47.841587,81.436759"
+ id="path997" />
+ <path
+ style="fill:#ff0000;stroke:#000000;stroke-width:0.607473;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 193.43534,269.62014 c -6.2322,-6.23407 -11.33698,-11.55089 -11.34397,-11.81517 -0.007,-0.26428 5.0921,-31.50414 11.33128,-69.4219 l 11.34397,-68.9414 0.0816,40.4123 c 0.0449,22.22675 0.0449,58.56721 0,80.75656 l -0.0816,40.34427 z"
+ id="path1073"
+ transform="scale(0.26458333)" />
+ <path
+ style="fill:#aa0000;stroke:#000000;stroke-width:0.607473;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 206.57191,200.26456 c 0.0205,-44.46429 0.0937,-80.62717 0.16276,-80.36197 0.27012,1.03808 22.62323,137.13728 22.62323,137.74386 0,0.42036 -3.98335,4.62794 -11.41164,12.05401 l -11.41164,11.40825 z"
+ id="path1186"
+ transform="scale(0.26458333)" />
+ <path
+ style="fill:#0000ff;stroke:#000000;stroke-width:0.607473;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 206.57191,365.49565 -0.0373,-80.84415 11.41164,11.40825 c 7.42829,7.42607 11.41164,11.63365 11.41164,12.05401 0,0.60657 -22.35311,136.70578 -22.62323,137.74386 -0.069,0.2652 -0.14225,-35.89769 -0.16276,-80.36197 z"
+ id="path1336"
+ transform="scale(0.26458333)" />
+ <path
+ style="fill:#0000aa;fill-opacity:1;stroke:#000000;stroke-width:0.607473;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="M 193.41121,377.30741 C 187.17832,339.428 182.08439,308.218 182.09137,307.95187 c 0.007,-0.26613 5.14794,-5.61759 11.42434,-11.89212 l 11.41164,-11.40825 v 80.76379 c 0,44.42008 -0.0413,80.76378 -0.0918,80.76378 -0.0505,0 -5.19144,-30.99224 -11.42433,-68.87166 z"
+ id="path1412"
+ transform="scale(0.26458333)" />
+ <path
+ style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.607473;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 41.628379,282.04372 c 0.2652,-0.0654 31.724078,-5.25942 69.908621,-11.5423 l 69.42643,-11.4234 11.57959,11.57959 11.57958,11.57958 -81.4882,-0.0373 c -44.818513,-0.0205 -81.271221,-0.0908 -81.006021,-0.15619 z"
+ id="path2360"
+ transform="scale(0.26458333)" />
+ <path
+ style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.607473;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 111.38404,295.24525 c -37.746813,-6.24278 -68.992206,-11.41247 -69.434206,-11.48821 -0.442001,-0.0757 35.865552,-0.15937 80.683446,-0.18586 l 81.48708,-0.0482 -11.56902,11.57237 c -6.36296,6.3648 -11.78675,11.55617 -12.05287,11.53638 -0.26612,-0.0198 -31.36762,-5.14373 -69.11443,-11.38651 z"
+ id="path2436"
+ transform="scale(0.26458333)" />
+ <path
+ style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.607473;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 218.92415,270.65241 11.58478,-11.58478 69.42124,11.42566 c 38.18168,6.28411 69.63822,11.48048 69.90342,11.54749 0.2652,0.067 -36.18751,0.13862 -81.00602,0.15913 l -81.4882,0.0373 z"
+ id="path2475"
+ transform="scale(0.26458333)" />
+ <path
+ style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.607473;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 218.91063,295.09538 -11.56902,-11.57237 81.48708,0.0373 c 44.81789,0.0205 81.2701,0.0921 81.0049,0.15913 -0.42568,0.10756 -139.03687,22.94832 -139.26393,22.94832 -0.0495,0 -5.29607,-5.20757 -11.65903,-11.57237 z"
+ id="path2514"
+ transform="scale(0.26458333)" />
+ <path
+ style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.21495;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 51.111292,281.19388 c 0.5304,-0.13818 29.895283,-5.01467 65.255298,-10.83664 l 64.29093,-10.5854 10.92713,10.91122 10.92713,10.91123 -76.18242,-0.0746 c -41.900341,-0.041 -75.748469,-0.18764 -75.218068,-0.32583 z"
+ id="path2999"
+ transform="scale(0.26458333)" />
+ <path
+ style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.21495;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ d="m 219.88208,295.10818 -10.92236,-10.94226 76.17766,0.0508 c 41.89771,0.0279 75.88835,0.15784 75.53475,0.28872 -0.3536,0.13088 -28.99521,4.88871 -63.64802,10.57296 -34.65281,5.68424 -63.72839,10.47833 -64.61239,10.65353 -1.3859,0.27467 -3.11163,-1.18855 -12.52964,-10.62371 z"
+ id="path3075"
+ transform="scale(0.26458333)" />
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
+ x="48.989689"
+ y="16.670103"
+ id="text6475"><tspan
+ sodipodi:role="line"
+ id="tspan6473"
+ style="stroke-width:0.264583"
+ x="48.989689"
+ y="16.670103"></tspan></text>
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
+ x="50.474586"
+ y="25.95421"
+ id="text29322"><tspan
+ sodipodi:role="line"
+ id="tspan29320"
+ style="stroke-width:0.264583"
+ x="50.474586"
+ y="25.95421">N</tspan></text>
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
+ x="51.019772"
+ y="131.41812"
+ id="text33982"><tspan
+ sodipodi:role="line"
+ id="tspan33980"
+ style="stroke-width:0.264583"
+ x="51.019772"
+ y="131.41812">S</tspan></text>
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
+ x="104.54184"
+ y="78.702988"
+ id="text37802"><tspan
+ sodipodi:role="line"
+ id="tspan37800"
+ style="stroke-width:0.264583"
+ x="104.54184"
+ y="78.702988">E</tspan></text>
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
+ x="-4.1540327"
+ y="78.702988"
+ id="text39852"><tspan
+ sodipodi:role="line"
+ id="tspan39850"
+ style="stroke-width:0.264583"
+ x="-4.1540327"
+ y="78.702988">W</tspan></text>
+ </g>
+</svg>
diff --git a/examples/sensors/sensorsshowcase/images/magnet.svg b/examples/sensors/sensorsshowcase/images/magnet.svg
new file mode 100644
index 00000000..21d9f46b
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/images/magnet.svg
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ width="152.6804mm"
+ height="186.70102mm"
+ viewBox="0 0 152.6804 186.70102"
+ version="1.1"
+ id="svg22292"
+ sodipodi:docname="magnet.svg"
+ inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:svg="http://www.w3.org/2000/svg">
+ <sodipodi:namedview
+ id="namedview22294"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageshadow="2"
+ inkscape:pageopacity="0.0"
+ inkscape:pagecheckerboard="0"
+ inkscape:document-units="mm"
+ showgrid="false"
+ inkscape:zoom="3.1108586"
+ inkscape:cx="384.62051"
+ inkscape:cy="214.24953"
+ inkscape:window-width="2560"
+ inkscape:window-height="1377"
+ inkscape:window-x="1912"
+ inkscape:window-y="72"
+ inkscape:window-maximized="1"
+ inkscape:current-layer="layer1" />
+ <defs
+ id="defs22289" />
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0.34020391,-51.711357)">
+ <path
+ style="fill:none;stroke:#0000ff;stroke-width:40;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path22661"
+ sodipodi:type="arc"
+ sodipodi:cx="76.206184"
+ sodipodi:cy="162.27835"
+ sodipodi:rx="56.134018"
+ sodipodi:ry="56.134018"
+ sodipodi:start="1.5707963"
+ sodipodi:end="3.1415927"
+ sodipodi:arc-type="arc"
+ d="M 76.206184,218.41237 A 56.134018,56.134018 0 0 1 36.513439,201.9711 56.134018,56.134018 0 0 1 20.072166,162.27835"
+ sodipodi:open="true" />
+ <rect
+ style="fill:#cccccc;fill-opacity:1;stroke:none;stroke-width:0.814709;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect22976"
+ width="39.829895"
+ height="50.35051"
+ x="0.17010537"
+ y="51.711357" />
+ <path
+ style="fill:#ff0000;stroke:#ff0000;stroke-width:40;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="path23734"
+ sodipodi:type="arc"
+ sodipodi:cx="-76.206184"
+ sodipodi:cy="162.27835"
+ sodipodi:rx="56.134018"
+ sodipodi:ry="56.134018"
+ sodipodi:start="1.5707963"
+ sodipodi:end="3.1415927"
+ sodipodi:arc-type="arc"
+ d="M -76.206184,218.41237 A 56.134018,56.134018 0 0 1 -115.89893,201.9711 56.134018,56.134018 0 0 1 -132.3402,162.27835"
+ sodipodi:open="true"
+ transform="scale(-1,1)" />
+ <rect
+ style="fill:#cccccc;fill-opacity:1;stroke:none;stroke-width:0.816447;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect24456"
+ width="40"
+ height="50.35051"
+ x="112.26804"
+ y="51.711357" />
+ <rect
+ style="fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:1.00283;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect24480"
+ width="40"
+ height="60.340206"
+ x="112.26804"
+ y="102.06187" />
+ <rect
+ style="fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:1.00563;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+ id="rect24580"
+ width="39.829895"
+ height="60.93557"
+ x="0.17010537"
+ y="102.06187" />
+ </g>
+</svg>
diff --git a/examples/sensors/sensorsshowcase/images/qt_logo.png b/examples/sensors/sensorsshowcase/images/qt_logo.png
new file mode 100644
index 00000000..30c621c9
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/images/qt_logo.png
Binary files differ
diff --git a/examples/sensors/sensorsshowcase/magnetometer.qml b/examples/sensors/sensorsshowcase/magnetometer.qml
new file mode 100644
index 00000000..17732c7f
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/magnetometer.qml
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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
+import QtQuick.Controls
+import QtQuick.Layouts
+import QtSensors
+
+Rectangle {
+ id: root
+ color: "dimgray"
+
+ property real magnetRotation: 40
+ property real magnetometerX: 0
+ property real magnetometerY: 0
+ property real magnetometerZ: 0
+ property int barScaleFactor: 10000
+
+//! [0]
+ Magnetometer {
+ id: magnetometer
+ active: true
+ dataRate: 25
+ onReadingChanged: {
+ root.magnetometerX = reading.x
+ root.magnetometerY = reading.y
+ root.magnetometerZ = reading.z
+ root.magnetRotation = ((Math.atan2(reading.x, reading.y) / Math.PI) * 180)
+ }
+ }
+//! [0]
+
+ ColumnLayout {
+ anchors.fill: parent
+ id: layout
+
+ Text {
+ Layout.topMargin: titleTopMargin
+ Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
+ Layout.preferredHeight: titleHeight
+ verticalAlignment: Text.AlignVCenter
+ color: "White"
+ text: "Magnetometer"
+ font.pixelSize: titleFontSize
+ }
+ Image {
+ Layout.alignment: Qt.AlignCenter
+ Layout.fillHeight: true
+ Layout.preferredWidth: root.width / 2
+ Layout.preferredHeight: root.height / 2
+ source: "qrc:/images/magnet.svg"
+ fillMode: Image.PreserveAspectFit
+ rotation: magnetRotation
+ }
+ Text {
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "X: " + root.magnetometerX.toFixed(9)
+ font.pixelSize: textFontSize
+ }
+ ProgressBar {
+ id: xbar
+ value: 0.5 + (root.magnetometerX * barScaleFactor)
+ Layout.preferredWidth: root.width
+ }
+ Text {
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "Y: " + root.magnetometerY.toFixed(9)
+ font.pixelSize: textFontSize
+ }
+ ProgressBar {
+ id: ybar
+ value: 0.5 + (root.magnetometerY * barScaleFactor)
+ Layout.preferredWidth: root.width
+ }
+ Text {
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "Z: " + root.magnetometerZ.toFixed(9)
+ font.pixelSize: textFontSize
+ }
+ ProgressBar {
+ id: zbar
+ value: 0.5 + (root.magnetometerZ * barScaleFactor)
+ Layout.preferredWidth: root.width
+ }
+ Button {
+ Layout.alignment: Qt.AlignBottom
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: buttonHeight
+ text:"Back"
+ font.pixelSize: buttonFontSize
+ onClicked:stack.pop()
+ }
+ }
+}
diff --git a/examples/sensors/sensorsshowcase/main.cpp b/examples/sensors/sensorsshowcase/main.cpp
new file mode 100644
index 00000000..4ee79963
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/main.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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 <QtGui/QGuiApplication>
+#include <QtQml/QQmlApplicationEngine>
+
+int main(int argc, char *argv[])
+{
+ QGuiApplication app(argc,argv);
+ QQmlApplicationEngine engine(QUrl("qrc:///sensorsshowcase.qml"));
+
+ return app.exec();
+}
diff --git a/examples/sensors/sensorsshowcase/proximity.qml b/examples/sensors/sensorsshowcase/proximity.qml
new file mode 100644
index 00000000..3a235490
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/proximity.qml
@@ -0,0 +1,118 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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
+import QtQuick.Controls
+import QtQuick.Layouts
+import QtSensors
+
+Rectangle {
+ id: root
+ color: "dimgray"
+ property bool near: false
+
+ ProximitySensor {
+ id: proximity
+ active: true
+ onReadingChanged: {
+ root.near = reading.near
+ }
+ }
+
+ ColumnLayout {
+ anchors.fill: parent
+ id: layout
+
+ Text {
+ Layout.topMargin: titleTopMargin
+ Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
+ Layout.preferredHeight: textHeight
+ color: "White"
+ text: "Proximity"
+ font.pixelSize: titleFontSize
+ }
+ Image {
+ Layout.alignment: Qt.AlignCenter
+ Layout.fillHeight: true
+ Layout.preferredWidth: root.near ? root.height/3 : root.height/4
+ Layout.preferredHeight: root.near ? root.height/3 : root.height/4
+ source: "qrc:/images/qt_logo.png"
+ fillMode: Image.PreserveAspectFit
+ }
+ Text {
+ visible: !proximity
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ font.pixelSize: textFontSize
+ verticalAlignment: Text.AlignVCenter
+ wrapMode: Text.WordWrap
+ color: "White"
+ text: "The proximity sensor is not available on this device!"
+ }
+ Text {
+// visible: typeof proximity.available !== 'undefined'
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: textHeight
+ Layout.leftMargin: layout.spacing
+ color: "White"
+ text: "Near: " + root.near
+ font.pixelSize: textFontSize
+ }
+ Button {
+ Layout.alignment: Qt.AlignBottom
+ Layout.preferredWidth: root.width
+ Layout.preferredHeight: buttonHeight
+ text:"Back"
+ font.pixelSize: buttonFontSize
+ onClicked:stack.pop()
+ }
+ }
+}
diff --git a/examples/sensors/sensorsshowcase/sensorsshowcase.pro b/examples/sensors/sensorsshowcase/sensorsshowcase.pro
new file mode 100644
index 00000000..f57733f5
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/sensorsshowcase.pro
@@ -0,0 +1,27 @@
+TEMPLATE = app
+TARGET = sensorsshowcase
+QT += quick sensors svg
+SOURCES = main.cpp
+
+RESOURCES += \
+ sensorsshowcase.qrc
+
+OTHER_FILES = \
+ $$files(*.qml) \
+ images \
+ android/AndroidManifest.xml
+
+target.path = $$[QT_INSTALL_EXAMPLES]/sensors/sensorsshowcase
+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/examples/sensors/sensorsshowcase/sensorsshowcase.qml b/examples/sensors/sensorsshowcase/sensorsshowcase.qml
new file mode 100644
index 00000000..dda6cda5
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/sensorsshowcase.qml
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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
+import QtQuick.Controls
+import QtQuick.Layouts
+import QtSensors
+
+ApplicationWindow {
+ title: "Sensors Showcase"
+ id: mainWindow
+ width: 540
+ height: 1200
+ visible: true
+ color: "dimgray"
+
+ property int titleHeight: height/7
+ readonly property real buttonHeight: height/7
+ property int textHeight: height/24
+ readonly property int buttonFontSize: 30
+ readonly property int textFontSize: 20
+ readonly property int titleFontSize: 35
+ readonly property int titleTopMargin: mainWindow.height/24
+
+ StackView {
+ id: stack
+ anchors.fill: parent
+ initialItem: ColumnLayout {
+ width: stack.width
+ Text {
+ Layout.topMargin: mainWindow.height/12
+ Layout.alignment: Qt.AlignCenter
+ Layout.preferredHeight: titleHeight
+ text: "Sensors Showcase"
+ color: "White"
+ font.pixelSize: titleFontSize
+ }
+
+ Button {
+ Layout.fillHeight: true
+ Layout.preferredWidth: stack.width
+ text: "Accelerometer"
+ font.pixelSize: buttonFontSize
+ onClicked: stack.push("qrc:/accelerometer.qml")
+ }
+ Button {
+ Layout.fillHeight: true
+ Layout.preferredWidth: stack.width
+ text: "Proximity"
+ font.pixelSize: buttonFontSize
+ onClicked: stack.push("qrc:/proximity.qml")
+ }
+ Button {
+ Layout.fillHeight: true
+ Layout.preferredWidth: stack.width
+ text: "Compass"
+ font.pixelSize: buttonFontSize
+ onClicked: stack.push("qrc:/compass.qml")
+ }
+ Button {
+ Layout.fillHeight: true
+ Layout.preferredWidth: stack.width
+ text: "Magnetometer"
+ font.pixelSize: buttonFontSize
+ onClicked: stack.push("qrc:/magnetometer.qml")
+ }
+ Button {
+ Layout.fillHeight: true
+ Layout.preferredWidth: stack.width
+ text: "Gyroscope"
+ font.pixelSize: buttonFontSize
+ onClicked: stack.push("qrc:/gyroscope.qml")
+ }
+ }
+ }
+}
diff --git a/examples/sensors/sensorsshowcase/sensorsshowcase.qrc b/examples/sensors/sensorsshowcase/sensorsshowcase.qrc
new file mode 100644
index 00000000..e647c384
--- /dev/null
+++ b/examples/sensors/sensorsshowcase/sensorsshowcase.qrc
@@ -0,0 +1,13 @@
+<RCC>
+ <qresource prefix="/">
+ <file>sensorsshowcase.qml</file>
+ <file>accelerometer.qml</file>
+ <file>proximity.qml</file>
+ <file>compass.qml</file>
+ <file>magnetometer.qml</file>
+ <file>gyroscope.qml</file>
+ <file>images/magnet.svg</file>
+ <file>images/compass.svg</file>
+ <file>images/qt_logo.png</file>
+ </qresource>
+</RCC>