diff options
Diffstat (limited to 'examples/sensors/sensorsshowcase')
33 files changed, 718 insertions, 700 deletions
diff --git a/examples/sensors/sensorsshowcase/Accelerometer.qml b/examples/sensors/sensorsshowcase/Accelerometer.qml new file mode 100644 index 00000000..a22e1404 --- /dev/null +++ b/examples/sensors/sensorsshowcase/Accelerometer.qml @@ -0,0 +1,70 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Layouts +import QtSensors + +Item { + id: root + + required property int fontSize + required property int imageSize + + //! [0] + Accelerometer { + id: accelerometer + + property real x: 0 + property real y: 0 + property real z: 0 + + active: true + dataRate: 25 + + onReadingChanged: { + x = (reading as AccelerometerReading).x + y = (reading as AccelerometerReading).y + z = (reading as AccelerometerReading).z + imageTranslation.x = -x * 10 + imageTranslation.y = y * 10 + } + } + //! [0] + ColumnLayout { + id: layout + + anchors.fill: parent + spacing: 10 + + Image { + id: image + + Layout.alignment: Qt.AlignCenter + Layout.preferredHeight: root.imageSize + Layout.preferredWidth: root.imageSize + fillMode: Image.PreserveAspectFit + source: "images/qt_logo.png" + + transform: [ + Translate { + id: imageTranslation + + x: 0 + y: 0 + } + ] + } + + ProgressXYZBar { + Layout.fillWidth: true + fontSize: root.fontSize + xText: "X: " + accelerometer.x.toFixed(2) + xValue: 0.5 + (accelerometer.x / 100) + yText: "Y: " + accelerometer.y.toFixed(2) + yValue: 0.5 + (accelerometer.y / 100) + zText: "Z: " + accelerometer.z.toFixed(2) + zValue: 0.5 + (accelerometer.z / 100) + } + } +} diff --git a/examples/sensors/sensorsshowcase/CMakeLists.txt b/examples/sensors/sensorsshowcase/CMakeLists.txt index eb27f7ef..b949213a 100644 --- a/examples/sensors/sensorsshowcase/CMakeLists.txt +++ b/examples/sensors/sensorsshowcase/CMakeLists.txt @@ -1,18 +1,16 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(sensorsshowcase LANGUAGES CXX) -set(CMAKE_AUTOMOC ON) - if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/sensors/sensorsshowcase") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Sensors Svg) +find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Svg Sensors) +qt_standard_project_setup(REQUIRES 6.5) qt_add_executable(sensorsshowcase main.cpp @@ -26,43 +24,47 @@ set_target_properties(sensorsshowcase PROPERTIES if(ANDROID) set_property(TARGET sensorsshowcase PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android) - endif() -if(APPLE) - if(IOS) - set_property(TARGET sensorsshowcase PROPERTY - MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist" - ) - endif() endif() -target_link_libraries(sensorsshowcase PUBLIC - Qt::Core - Qt::Gui - Qt::Quick - Qt::Sensors - Qt::Svg -) +if(APPLE AND IOS) + set_property(TARGET sensorsshowcase PROPERTY + MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist" + ) +else() + # default search path for the config file is "qrc:/" + qt_add_resources(sensorsshowcase "resources" + FILES qtquickcontrols2.conf) +endif() -# 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" +qt_add_qml_module(sensorsshowcase + URI SensorShowcaseModule + VERSION 1.0 + QML_FILES + "Main.qml" + "Accelerometer.qml" + "Compass.qml" + "Gyroscope.qml" + "Magnetometer.qml" + "Proximity.qml" + "ProgressXYZBar.qml" + RESOURCES + "images/compass.svg" + "images/magnet.svg" + "images/qt_logo.png" + SOURCES + sensorsupport.h ) -qt6_add_resources(sensorsshowcase "sensorsshowcase" - PREFIX - "/" - FILES - ${sensorsshowcase_resource_files} +target_link_libraries(sensorsshowcase + PRIVATE + Qt::Core + Qt::Gui + Qt::Quick + Qt::Svg + Qt::Sensors ) + install(TARGETS sensorsshowcase RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/sensors/sensorsshowcase/Compass.qml b/examples/sensors/sensorsshowcase/Compass.qml new file mode 100644 index 00000000..b4bc5ff1 --- /dev/null +++ b/examples/sensors/sensorsshowcase/Compass.qml @@ -0,0 +1,61 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Layouts +import QtSensors + +Item { + id: root + + required property int fontSize + required property int imageSize + property alias isActive: compass.active + + property real azimuth: 30 + + Compass { + id: compass + active: true + dataRate: 7 + onReadingChanged: root.azimuth = -(reading as CompassReading).azimuth + } + + ColumnLayout { + id: layout + + anchors.fill: parent + spacing: 10 + + Image { + id: arrow + + Layout.alignment: Qt.AlignHCenter + Layout.preferredWidth: root.imageSize * 1.25 + Layout.fillHeight: true + + source: "images/compass.svg" + fillMode: Image.PreserveAspectFit + rotation: root.azimuth + } + + Rectangle { + id: separator + + Layout.topMargin: 10 + Layout.preferredWidth: parent.width * 0.75 + Layout.preferredHeight: 1 + Layout.alignment: Qt.AlignHCenter + color: "black" + } + + Text { + id: info + Layout.fillWidth: true + Layout.fillHeight: true + Layout.topMargin: 10 + text: "Azimuth: " + root.azimuth.toFixed(2) + "°" + font.pixelSize: root.fontSize + } + } +} diff --git a/examples/sensors/sensorsshowcase/Gyroscope.qml b/examples/sensors/sensorsshowcase/Gyroscope.qml new file mode 100644 index 00000000..9f0ffd2f --- /dev/null +++ b/examples/sensors/sensorsshowcase/Gyroscope.qml @@ -0,0 +1,128 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import QtSensors + +Item { + id: root + + required property int fontSize + required property int imageSize + + function resetRotations() : void + { + imageXRotation.angle = 0 + imageYRotation.angle = 0 + imageZRotation.angle = 0 + } + + //! [0] + Gyroscope { + id: gyroscope + + property var lastTimeStamp: 0 + property real x: 0 + property real y: 0 + property real z: 0 + + active: true + dataRate: 25 + + onReadingChanged: { + x = (reading as GyroscopeReading).x + y = (reading as GyroscopeReading).y + z = (reading as GyroscopeReading).z + let firstCall = false + if (lastTimeStamp == 0) { + firstCall = true + } + let timeSinceLast = reading.timestamp - lastTimeStamp + lastTimeStamp = reading.timestamp + + //Skipping the initial time jump from 0 + if (firstCall === true) + return + let normalizedX = x * (timeSinceLast / 1000000) + imageXRotation.angle += normalizedX + let normalizedY = y * (timeSinceLast / 1000000) + imageYRotation.angle -= normalizedY + let normalizedZ = z * (timeSinceLast / 1000000) + imageZRotation.angle += normalizedZ + } + } + //! [0] + ColumnLayout { + id: layout + + anchors.fill: parent + spacing: 10 + + Image { + id: image + + Layout.alignment: Qt.AlignHCenter + Layout.fillHeight: true + Layout.preferredWidth: root.imageSize + fillMode: Image.PreserveAspectFit + source: "images/qt_logo.png" + + transform: [ + Rotation { + id: imageXRotation + + angle: 0 + axis.x: 1 + axis.y: 0 + axis.z: 0 + origin.x: layout.width / 2 + origin.y: layout.height / 3 + }, + Rotation { + id: imageYRotation + + angle: 0 + axis.x: 0 + axis.y: 1 + axis.z: 0 + origin.x: layout.width / 2 + origin.y: layout.height / 3 + }, + Rotation { + id: imageZRotation + + angle: 0 + axis.x: 0 + axis.y: 0 + axis.z: 1 + origin.x: layout.width / 2 + origin.y: layout.height / 3 + } + ] + } + + ProgressXYZBar { + Layout.fillWidth: true + Layout.topMargin: 20 + fontSize: root.fontSize + xText: "X: " + gyroscope.x.toFixed(2) + xValue: 0.5 + (gyroscope.x / 1000) + yText: "Y: " + gyroscope.y.toFixed(2) + yValue: 0.5 + (gyroscope.y / 1000) + zText: "Z: " + gyroscope.z.toFixed(2) + zValue: 0.5 + (gyroscope.z / 1000) + } + + Button { + Layout.alignment: Qt.AlignHCenter + Layout.topMargin: 20 + Layout.bottomMargin: 10 + Layout.preferredWidth: parent.width / 2 + Layout.preferredHeight: 60 + onClicked: root.resetRotations() + text: "Reset rotation" + } + } +} diff --git a/examples/sensors/sensorsshowcase/Magnetometer.qml b/examples/sensors/sensorsshowcase/Magnetometer.qml new file mode 100644 index 00000000..551f8627 --- /dev/null +++ b/examples/sensors/sensorsshowcase/Magnetometer.qml @@ -0,0 +1,68 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Layouts +import QtSensors + +Item { + id: root + + required property int fontSize + required property int imageSize + + 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 as MagnetometerReading).x + root.magnetometerY = (reading as MagnetometerReading).y + root.magnetometerZ = (reading as MagnetometerReading).z + root.magnetRotation = + ((Math.atan2(root.magnetometerX, root.magnetometerY) / Math.PI) * 180) + } + } + //! [0] + + ColumnLayout { + id: layout + + anchors.fill: parent + spacing: 10 + + Image { + id: image + + Layout.alignment: Qt.AlignHCenter + Layout.bottomMargin: 20 + Layout.preferredWidth: root.imageSize * 0.9 + Layout.preferredHeight: root.imageSize * 0.9 + + source: "images/magnet.svg" + fillMode: Image.PreserveAspectFit + rotation: root.magnetRotation + } + + ProgressXYZBar { + Layout.fillWidth: true + fontSize: root.fontSize + + xText: "X: " + root.magnetometerX.toFixed(9) + xValue: 0.5 + (root.magnetometerX * root.barScaleFactor) + + yText: "Y: " + root.magnetometerY.toFixed(9) + yValue: 0.5 + (root.magnetometerY * root.barScaleFactor) + + zText: "Z: " + root.magnetometerZ.toFixed(9) + zValue: 0.5 + (root.magnetometerZ * root.barScaleFactor) + } + } +} diff --git a/examples/sensors/sensorsshowcase/Main.qml b/examples/sensors/sensorsshowcase/Main.qml new file mode 100644 index 00000000..4587ba21 --- /dev/null +++ b/examples/sensors/sensorsshowcase/Main.qml @@ -0,0 +1,116 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma ComponentBehavior: Bound + +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +ApplicationWindow { + id: root + + readonly property int defaultFontSize: 22 + readonly property int imageSize: width / 2 + + width: 420 + height: 760 + visible: true + title: "Sensors Showcase" + + header : ToolBar { + RowLayout { + anchors.fill: parent + anchors.leftMargin: 10 + anchors.rightMargin: 10 + ToolButton { + id: back + text: qsTr("Back") + font.pixelSize: root.defaultFontSize - 4 + visible: stack.depth > 1 + onClicked: { + stack.pop(); + heading.text = root.title; + } + Layout.alignment: Qt.AlignLeft + } + Label { + id: heading + text: root.title + font.pixelSize: root.defaultFontSize + font.weight: Font.Medium + verticalAlignment: Qt.AlignVCenter + Layout.alignment: Qt.AlignCenter + Layout.preferredHeight: 55 + } + Item { + visible: back.visible + Layout.preferredWidth: back.width + } + } + } + + StackView { + id: stack + + // Pushes the object and forwards the properties + function pusher(object : string) : void { + // Trim the suffix and set it as new heading + heading.text = object.split(".")[0] + return stack.push(object, { + fontSize: root.defaultFontSize, + imageSize: root.imageSize + }) + } + + anchors.fill: parent + anchors.margins: width / 12 + + initialItem: Item { + ColumnLayout { + id: initialItem + + anchors.fill: parent + anchors.topMargin: 20 + anchors.bottomMargin: 20 + spacing: 5 + + component CustomButton: Button { + highlighted: true + font.pixelSize: root.defaultFontSize + font.letterSpacing: 1.5 + + Layout.alignment: Qt.AlignCenter + Layout.fillHeight: true + Layout.fillWidth: true + } + + CustomButton { + text: "Accelerometer" + onClicked: stack.pusher("Accelerometer.qml") + enabled: SensorSupport.hasAccelerometer() + } + CustomButton { + text: "Proximity" + onClicked: stack.pusher("Proximity.qml") + enabled: SensorSupport.hasProximity() + } + CustomButton { + text: "Compass" + onClicked: stack.pusher("Compass.qml") + enabled: SensorSupport.hasCompass() + } + CustomButton { + text: "Magnetometer" + onClicked: stack.pusher("Magnetometer.qml") + enabled: SensorSupport.hasMagnetometer() + } + CustomButton { + text: "Gyroscope" + onClicked: stack.pusher("Gyroscope.qml") + enabled: SensorSupport.hasGyroscope() + } + } + } + } + +} diff --git a/examples/sensors/sensorsshowcase/ProgressXYZBar.qml b/examples/sensors/sensorsshowcase/ProgressXYZBar.qml new file mode 100644 index 00000000..be7bf7ae --- /dev/null +++ b/examples/sensors/sensorsshowcase/ProgressXYZBar.qml @@ -0,0 +1,45 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +ColumnLayout { + id: root + spacing: 0 + + required property int fontSize + property alias xText: xBar.text + property alias xValue: xBar.value + property alias yText: yBar.text + property alias yValue: yBar.value + property alias zText: zBar.text + property alias zValue: zBar.value + + component NamedProgressBar: ColumnLayout { + property alias text: axes.text + property alias value: bar.value + Text { + id: axes + font.pixelSize: root.fontSize + Layout.fillWidth: true + } + ProgressBar { + id: bar + Layout.fillWidth: true + } + } + + NamedProgressBar { + id: xBar + } + + NamedProgressBar { + id: yBar + } + + NamedProgressBar { + id: zBar + } +} diff --git a/examples/sensors/sensorsshowcase/Proximity.qml b/examples/sensors/sensorsshowcase/Proximity.qml new file mode 100644 index 00000000..41121983 --- /dev/null +++ b/examples/sensors/sensorsshowcase/Proximity.qml @@ -0,0 +1,55 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +pragma ComponentBehavior: Bound +import QtQuick +import QtQuick.Layouts +import QtSensors + +Item { + id: root + + required property int imageSize + required property int fontSize + + property bool near: false + + ProximitySensor { + id: proximity + onReadingChanged: root.near = (reading as ProximityReading).near + active: true + } + + ColumnLayout { + id: layout + + anchors.fill: parent + spacing: 10 + + Image { + id: image + + Layout.alignment: Qt.AlignHCenter + Layout.preferredWidth: root.near ? root.imageSize : root.imageSize * 0.75 + Layout.fillHeight: true + + source: "images/qt_logo.png" + fillMode: Image.PreserveAspectFit + } + + Rectangle { + id: separator + Layout.topMargin: 10 + Layout.bottomMargin: 10 + Layout.preferredWidth: parent.width * 0.75 + Layout.preferredHeight: 1 + Layout.alignment: Qt.AlignHCenter + color: "black" + } + + Text { + Layout.fillHeight: true + font.pixelSize: root.fontSize + text: "Near: " + root.near + } + } +} diff --git a/examples/sensors/sensorsshowcase/accelerometer.qml b/examples/sensors/sensorsshowcase/accelerometer.qml deleted file mode 100644 index e4f6e39b..00000000 --- a/examples/sensors/sensorsshowcase/accelerometer.qml +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -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 index 3c152a90..359c0114 100644 --- a/examples/sensors/sensorsshowcase/android/AndroidManifest.xml +++ b/examples/sensors/sensorsshowcase/android/AndroidManifest.xml @@ -11,7 +11,6 @@ <!-- 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" @@ -22,26 +21,37 @@ android:extractNativeLibs="true" android:hardwareAccelerated="true" android:label="-- %%INSERT_APP_NAME%% --" - android:requestLegacyExternalStorage="true"> + android:requestLegacyExternalStorage="true" + android:allowNativeHeapPointerTagging="false" + android:allowBackup="true" + android:fullBackupOnly="false" + android:icon="@drawable/icon"> <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"> + android:screenOrientation="portrait" + android:exported="true"> <intent-filter> - <action android:name="android.intent.action.MAIN"/> - <category android:name="android.intent.category.LAUNCHER"/> + <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.arguments" + android:value="" /> + <meta-data android:name="android.app.extract_android_style" android:value="minimal" /> + + <meta-data + android:name="android.app.background_running" + android:value="false" /> </activity> </application> </manifest> diff --git a/examples/sensors/sensorsshowcase/android/res/drawable-hdpi/icon.png b/examples/sensors/sensorsshowcase/android/res/drawable-hdpi/icon.png Binary files differnew file mode 100644 index 00000000..5f61088b --- /dev/null +++ b/examples/sensors/sensorsshowcase/android/res/drawable-hdpi/icon.png diff --git a/examples/sensors/sensorsshowcase/android/res/drawable-ldpi/icon.png b/examples/sensors/sensorsshowcase/android/res/drawable-ldpi/icon.png Binary files differnew file mode 100644 index 00000000..605497de --- /dev/null +++ b/examples/sensors/sensorsshowcase/android/res/drawable-ldpi/icon.png diff --git a/examples/sensors/sensorsshowcase/android/res/drawable-mdpi/icon.png b/examples/sensors/sensorsshowcase/android/res/drawable-mdpi/icon.png Binary files differnew file mode 100644 index 00000000..3eb10832 --- /dev/null +++ b/examples/sensors/sensorsshowcase/android/res/drawable-mdpi/icon.png diff --git a/examples/sensors/sensorsshowcase/android/res/drawable-xhdpi/icon.png b/examples/sensors/sensorsshowcase/android/res/drawable-xhdpi/icon.png Binary files differnew file mode 100644 index 00000000..a9e39f88 --- /dev/null +++ b/examples/sensors/sensorsshowcase/android/res/drawable-xhdpi/icon.png diff --git a/examples/sensors/sensorsshowcase/android/res/drawable-xxhdpi/icon.png b/examples/sensors/sensorsshowcase/android/res/drawable-xxhdpi/icon.png Binary files differnew file mode 100644 index 00000000..b489d81e --- /dev/null +++ b/examples/sensors/sensorsshowcase/android/res/drawable-xxhdpi/icon.png diff --git a/examples/sensors/sensorsshowcase/android/res/drawable-xxxhdpi/icon.png b/examples/sensors/sensorsshowcase/android/res/drawable-xxxhdpi/icon.png Binary files differnew file mode 100644 index 00000000..9443da63 --- /dev/null +++ b/examples/sensors/sensorsshowcase/android/res/drawable-xxxhdpi/icon.png diff --git a/examples/sensors/sensorsshowcase/compass.qml b/examples/sensors/sensorsshowcase/compass.qml deleted file mode 100644 index 65ea3543..00000000 --- a/examples/sensors/sensorsshowcase/compass.qml +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -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 Binary files differdeleted file mode 100644 index b26aa459..00000000 --- a/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.png +++ /dev/null diff --git a/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.webp b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.webp Binary files differnew file mode 100644 index 00000000..0ff45403 --- /dev/null +++ b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.webp diff --git a/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.png b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.png Binary files differdeleted file mode 100644 index 838b39c9..00000000 --- a/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.png +++ /dev/null diff --git a/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.webp b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.webp Binary files differnew file mode 100644 index 00000000..b045b7ba --- /dev/null +++ b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.webp diff --git a/examples/sensors/sensorsshowcase/doc/src/sensorsshowcase.qdoc b/examples/sensors/sensorsshowcase/doc/src/sensorsshowcase.qdoc index b2971f01..d3d31c34 100644 --- a/examples/sensors/sensorsshowcase/doc/src/sensorsshowcase.qdoc +++ b/examples/sensors/sensorsshowcase/doc/src/sensorsshowcase.qdoc @@ -1,13 +1,15 @@ -// Copyright (C) 2021 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \example sensorsshowcase - \title Qt Sensors - Sensors Showcase + \title Sensors Showcase \brief The Sensors Showcase example demonstrates sensor usage with visual examples. + \meta tag {sensors,quick,mobile} \ingroup qtsensors-examples + \examplecategory {Mobile} - \image sensorsshowcase-mainview.png + \image sensorsshowcase-mainview.webp \section1 Overview @@ -17,9 +19,14 @@ \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. + 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. A \c StackView + manages the navigation between the subviews and the main menu. The + application checks the availability of the sensors during startup and + disables the buttons for the sensors that are not available. + + \note To simplify the example, the sensor availability is checked only once + during the startup. \section1 Accelerometer View @@ -29,7 +36,7 @@ Moving around the image happens in the accelerometer \c onReadingChanged method. - \snippet sensorsshowcase/accelerometer.qml 0 + \snippet sensorsshowcase/Accelerometer.qml 0 Whenever there is a new accelerometer value the image translation coordinates are updated accordingly. @@ -52,11 +59,11 @@ 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 + \snippet sensorsshowcase/Magnetometer.qml 0 \section1 Gyroscope View - \image sensorsshowcase-gyroscope.png + \image sensorsshowcase-gyroscope.webp 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 @@ -64,7 +71,7 @@ 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 + \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 deleted file mode 100644 index 39252c0e..00000000 --- a/examples/sensors/sensorsshowcase/gyroscope.qml +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -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/qt_logo.png b/examples/sensors/sensorsshowcase/images/qt_logo.png Binary files differindex 30c621c9..3a75e10c 100644 --- a/examples/sensors/sensorsshowcase/images/qt_logo.png +++ b/examples/sensors/sensorsshowcase/images/qt_logo.png diff --git a/examples/sensors/sensorsshowcase/magnetometer.qml b/examples/sensors/sensorsshowcase/magnetometer.qml deleted file mode 100644 index c40bb867..00000000 --- a/examples/sensors/sensorsshowcase/magnetometer.qml +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -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 index 52e27a06..4a7bd285 100644 --- a/examples/sensors/sensorsshowcase/main.cpp +++ b/examples/sensors/sensorsshowcase/main.cpp @@ -1,14 +1,18 @@ -// Copyright (C) 2021 The Qt Company Ltd. +// Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - - -#include <QtGui/QGuiApplication> -#include <QtQml/QQmlApplicationEngine> +#include <QGuiApplication> +#include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc,argv); - QQmlApplicationEngine engine(QUrl("qrc:///sensorsshowcase.qml")); + QGuiApplication::setOrganizationName("QtProject"); + QGuiApplication::setApplicationName("Sensors Showcase"); + + QQmlApplicationEngine engine; + engine.loadFromModule("SensorShowcaseModule", "Main"); + if (engine.rootObjects().isEmpty()) + return -1; return app.exec(); } diff --git a/examples/sensors/sensorsshowcase/proximity.qml b/examples/sensors/sensorsshowcase/proximity.qml deleted file mode 100644 index 7e4f6486..00000000 --- a/examples/sensors/sensorsshowcase/proximity.qml +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -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/qmldir b/examples/sensors/sensorsshowcase/qmldir new file mode 100644 index 00000000..76e61cdf --- /dev/null +++ b/examples/sensors/sensorsshowcase/qmldir @@ -0,0 +1,9 @@ +module SensorShowcaseModule +prefer :/qt/qml/SensorShowcaseModule/ +Main 1.0 Main.qml +Accelerometer 1.0 Accelerometer.qml +Compass 1.0 Compass.qml +Gyroscope 1.0 Gyroscope.qml +Magnetometer 1.0 Magnetometer.qml +Proximity 1.0 Proximity.qml +ProgressXYZBar 1.0 ProgressXYZBar.qml diff --git a/examples/sensors/sensorsshowcase/qtquickcontrols2.conf b/examples/sensors/sensorsshowcase/qtquickcontrols2.conf new file mode 100644 index 00000000..76439328 --- /dev/null +++ b/examples/sensors/sensorsshowcase/qtquickcontrols2.conf @@ -0,0 +1,6 @@ +[Controls] +Style=Material + +[Material] +Background=#eafcf3 +Accent=#28c878 diff --git a/examples/sensors/sensorsshowcase/sensorsshowcase.pro b/examples/sensors/sensorsshowcase/sensorsshowcase.pro index f57733f5..cded9071 100644 --- a/examples/sensors/sensorsshowcase/sensorsshowcase.pro +++ b/examples/sensors/sensorsshowcase/sensorsshowcase.pro @@ -1,27 +1,46 @@ -TEMPLATE = app -TARGET = sensorsshowcase +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + QT += quick sensors svg + +TARGET = sensorsshowcase +TEMPLATE = app + SOURCES = main.cpp -RESOURCES += \ - sensorsshowcase.qrc +qml_resources.files = \ + qmldir \ + Main.qml \ + Accelerometer.qml \ + Compass.qml \ + Gyroscope.qml \ + Magnetometer.qml \ + Proximity.qml \ + ProgressXYZBar.qml \ + images/compass.svg \ + images/magnet.svg \ + images/qt_logo.png -OTHER_FILES = \ - $$files(*.qml) \ - images \ - android/AndroidManifest.xml +qml_resources.prefix = /qt/qml/SensorShowcaseModule -target.path = $$[QT_INSTALL_EXAMPLES]/sensors/sensorsshowcase -INSTALLS += target +data_resources.files = \ + qtquickcontrols2.conf -ios { -QMAKE_INFO_PLIST = Info.plist +data_resources.prefix = / + +RESOURCES += \ + qml_resources \ + data_resources -# manual plugin loading needed with older Qt -# QTPLUGIN += qsvg qtsensors_ios qtsensors_generic +android { + OTHER_FILES = android/AndroidManifest.xml + ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android } -ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android +ios { + QMAKE_INFO_PLIST = Info.plist + EXAMPLE_FILES += Info.plist +} -EXAMPLE_FILES += \ - Info.plist +target.path = $$[QT_INSTALL_EXAMPLES]/sensors/sensorsshowcase +INSTALLS += target diff --git a/examples/sensors/sensorsshowcase/sensorsshowcase.qml b/examples/sensors/sensorsshowcase/sensorsshowcase.qml deleted file mode 100644 index e0fbd944..00000000 --- a/examples/sensors/sensorsshowcase/sensorsshowcase.qml +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -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 deleted file mode 100644 index e647c384..00000000 --- a/examples/sensors/sensorsshowcase/sensorsshowcase.qrc +++ /dev/null @@ -1,13 +0,0 @@ -<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> diff --git a/examples/sensors/sensorsshowcase/sensorsupport.h b/examples/sensors/sensorsshowcase/sensorsupport.h new file mode 100644 index 00000000..915157f8 --- /dev/null +++ b/examples/sensors/sensorsshowcase/sensorsupport.h @@ -0,0 +1,41 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +#ifndef SENSORSUPPORT_H +#define SENSORSUPPORT_H + +#include <QObject> +#include <QtQmlIntegration> +#include <QtSensors/QtSensors> + +class SensorSupport : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_SINGLETON + QML_UNCREATABLE("SensorSupport is a utility class") +public: + explicit SensorSupport(QObject *parent = nullptr) : QObject(parent) { } + + Q_INVOKABLE static bool hasAccelerometer() + { + return !QSensor::sensorsForType(QAccelerometer::sensorType).empty(); + } + Q_INVOKABLE static bool hasCompass() + { + return !QSensor::sensorsForType(QCompass::sensorType).empty(); + } + Q_INVOKABLE static bool hasGyroscope() + { + return !QSensor::sensorsForType(QGyroscope::sensorType).empty(); + } + Q_INVOKABLE static bool hasMagnetometer() + { + return !QSensor::sensorsForType(QMagnetometer::sensorType).empty(); + } + Q_INVOKABLE static bool hasProximity() + { + return !QSensor::sensorsForType(QProximitySensor::sensorType).empty(); + } +}; + +#endif // SENSORSUPPORT_H |