diff options
author | Dennis Oberst <dennis.oberst@qt.io> | 2023-09-28 16:38:16 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-10-20 10:55:37 +0000 |
commit | 00a7f671121c3310f470b8a1671deb7081eb5f46 (patch) | |
tree | 3842228bd01bd1ddef7cfaca1946c18bb87614df | |
parent | 49d13a43b8f06987b238f8099ea03cfff4defeeb (diff) |
Revamp Sensors Showcase Example
Update the style by using 'Material' as default for all platforms except
iOS and indicate the availability of sensors by graying out the buttons
if not present.
Put the example into the 'mobile example' category and update images
and icons.
Fixes: QTBUG-117369
Pick-to: 6.5
Change-Id: I2149ab0bc8b784e748a54beaac84152c370af0a2
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit 174bc349da9c4657660d4c3be4af5e966c4e17f5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
21 files changed, 123 insertions, 148 deletions
diff --git a/examples/sensors/sensorsshowcase/Accelerometer.qml b/examples/sensors/sensorsshowcase/Accelerometer.qml index e7e810d7..a22e1404 100644 --- a/examples/sensors/sensorsshowcase/Accelerometer.qml +++ b/examples/sensors/sensorsshowcase/Accelerometer.qml @@ -2,15 +2,12 @@ // 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 - property alias headingFontSize: heading.font.pixelSize - required property StackView parentStack required property int fontSize required property int imageSize @@ -40,15 +37,6 @@ Item { anchors.fill: parent spacing: 10 - Text { - id: heading - - Layout.fillWidth: true - horizontalAlignment: Text.AlignHCenter - text: "Accelerometer" - wrapMode: Text.Wrap - } - Image { id: image @@ -78,11 +66,5 @@ Item { zText: "Z: " + accelerometer.z.toFixed(2) zValue: 0.5 + (accelerometer.z / 100) } - - Button { - Layout.fillWidth: true - onClicked: root.parentStack.pop() - text: "Back" - } } } diff --git a/examples/sensors/sensorsshowcase/CMakeLists.txt b/examples/sensors/sensorsshowcase/CMakeLists.txt index 9805808b..a715344f 100644 --- a/examples/sensors/sensorsshowcase/CMakeLists.txt +++ b/examples/sensors/sensorsshowcase/CMakeLists.txt @@ -25,17 +25,16 @@ 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() -# default search path for the config file is "qrc:/" -qt_add_resources(sensorsshowcase "resources" +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() qt_add_qml_module(sensorsshowcase URI SensorShowcaseModule @@ -52,6 +51,8 @@ qt_add_qml_module(sensorsshowcase "images/compass.svg" "images/magnet.svg" "images/qt_logo.png" + SOURCES + sensorsupport.h ) target_link_libraries(sensorsshowcase diff --git a/examples/sensors/sensorsshowcase/Compass.qml b/examples/sensors/sensorsshowcase/Compass.qml index b3f06539..b4bc5ff1 100644 --- a/examples/sensors/sensorsshowcase/Compass.qml +++ b/examples/sensors/sensorsshowcase/Compass.qml @@ -2,17 +2,15 @@ // 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 - property alias headingFontSize: heading.font.pixelSize - required property StackView parentStack required property int fontSize required property int imageSize + property alias isActive: compass.active property real azimuth: 30 @@ -29,14 +27,6 @@ Item { anchors.fill: parent spacing: 10 - Text { - id: heading - Layout.preferredWidth: parent.width - horizontalAlignment: Text.AlignHCenter - wrapMode: Text.Wrap - text: "Compass" - } - Image { id: arrow @@ -67,11 +57,5 @@ Item { text: "Azimuth: " + root.azimuth.toFixed(2) + "°" font.pixelSize: root.fontSize } - - Button { - Layout.fillWidth: true - onClicked: root.parentStack.pop() - text: "Back" - } } } diff --git a/examples/sensors/sensorsshowcase/Gyroscope.qml b/examples/sensors/sensorsshowcase/Gyroscope.qml index 5835c5d9..9f0ffd2f 100644 --- a/examples/sensors/sensorsshowcase/Gyroscope.qml +++ b/examples/sensors/sensorsshowcase/Gyroscope.qml @@ -9,8 +9,6 @@ import QtSensors Item { id: root - property alias headingFontSize: heading.font.pixelSize - required property StackView parentStack required property int fontSize required property int imageSize @@ -62,15 +60,6 @@ Item { anchors.fill: parent spacing: 10 - Text { - id: heading - - Layout.fillWidth: true - horizontalAlignment: Text.AlignHCenter - text: "Gyroscope" - wrapMode: Text.Wrap - } - Image { id: image @@ -128,16 +117,12 @@ Item { Button { Layout.alignment: Qt.AlignHCenter + Layout.topMargin: 20 Layout.bottomMargin: 10 - Layout.topMargin: 10 + Layout.preferredWidth: parent.width / 2 + Layout.preferredHeight: 60 onClicked: root.resetRotations() text: "Reset rotation" } - - Button { - Layout.fillWidth: true - onClicked: root.parentStack.pop() - text: "Back" - } } } diff --git a/examples/sensors/sensorsshowcase/Magnetometer.qml b/examples/sensors/sensorsshowcase/Magnetometer.qml index 7940c76b..551f8627 100644 --- a/examples/sensors/sensorsshowcase/Magnetometer.qml +++ b/examples/sensors/sensorsshowcase/Magnetometer.qml @@ -2,15 +2,12 @@ // 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 - property alias headingFontSize: heading.font.pixelSize - required property StackView parentStack required property int fontSize required property int imageSize @@ -41,15 +38,6 @@ Item { anchors.fill: parent spacing: 10 - Text { - id: heading - Layout.fillWidth: true - horizontalAlignment: Text.AlignHCenter - wrapMode: Text.Wrap - text: "Magnetometer" - Layout.bottomMargin: 20 - } - Image { id: image @@ -76,11 +64,5 @@ Item { zText: "Z: " + root.magnetometerZ.toFixed(9) zValue: 0.5 + (root.magnetometerZ * root.barScaleFactor) } - - Button { - Layout.fillWidth: true - onClicked: root.parentStack.pop() - text: "Back" - } } } diff --git a/examples/sensors/sensorsshowcase/Main.qml b/examples/sensors/sensorsshowcase/Main.qml index 227e1cf3..4587ba21 100644 --- a/examples/sensors/sensorsshowcase/Main.qml +++ b/examples/sensors/sensorsshowcase/Main.qml @@ -1,6 +1,7 @@ // 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 @@ -8,9 +9,7 @@ import QtQuick.Layouts ApplicationWindow { id: root - readonly property int dynamicMargin: width / 12 - readonly property int defaultFontSize: 20 - readonly property int headingFontSize: 35 + readonly property int defaultFontSize: 22 readonly property int imageSize: width / 2 width: 420 @@ -18,68 +17,97 @@ ApplicationWindow { 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 - { - stack.push(object, { - parentStack: stack, - fontSize: root.defaultFontSize, - headingFontSize: root.headingFontSize, - imageSize: root.imageSize - }) + 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: root.dynamicMargin + anchors.margins: width / 12 initialItem: Item { ColumnLayout { id: initialItem - anchors.bottomMargin: (root.width < root.height) ? 2 * root.dynamicMargin : 0 anchors.fill: parent + anchors.topMargin: 20 + anchors.bottomMargin: 20 spacing: 5 - Text { - Layout.bottomMargin: root.dynamicMargin - Layout.preferredWidth: parent.width - horizontalAlignment: Text.AlignHCenter - font.bold: true - font.pixelSize: root.headingFontSize - text: "Sensors Showcase" - wrapMode: Text.WordWrap - } - component CustomButton: Button { + highlighted: true + font.pixelSize: root.defaultFontSize + font.letterSpacing: 1.5 + Layout.alignment: Qt.AlignCenter Layout.fillHeight: true Layout.fillWidth: true - font.pixelSize: root.defaultFontSize - highlighted: 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/Proximity.qml b/examples/sensors/sensorsshowcase/Proximity.qml index be1adfb7..a780692e 100644 --- a/examples/sensors/sensorsshowcase/Proximity.qml +++ b/examples/sensors/sensorsshowcase/Proximity.qml @@ -2,15 +2,12 @@ // 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 - property alias headingFontSize: heading.font.pixelSize - required property StackView parentStack required property int imageSize required property int fontSize @@ -27,14 +24,6 @@ Item { anchors.fill: parent spacing: 10 - Text { - id: heading - Layout.preferredWidth: parent.width - horizontalAlignment: Text.AlignHCenter - wrapMode: Text.Wrap - text: "Proximity" - } - Image { id: image @@ -57,28 +46,9 @@ Item { } Text { - id: error - visible: !proximity.active - Layout.preferredWidth: parent.width - horizontalAlignment: Text.AlignHCenter - text: "The proximity sensor is not available on this device!" - font.pixelSize: root.fontSize - font.bold: true - wrapMode: Text.Wrap - color: "red" - } - - Text { - visible: proximity.active Layout.fillHeight: true font.pixelSize: root.fontSize text: "Near: " + root.near } - - Button { - Layout.fillWidth: true - onClicked: root.parentStack.pop() - text: "Back" - } } } diff --git a/examples/sensors/sensorsshowcase/android/AndroidManifest.xml b/examples/sensors/sensorsshowcase/android/AndroidManifest.xml index 4d1a9269..359c0114 100644 --- a/examples/sensors/sensorsshowcase/android/AndroidManifest.xml +++ b/examples/sensors/sensorsshowcase/android/AndroidManifest.xml @@ -24,7 +24,8 @@ android:requestLegacyExternalStorage="true" android:allowNativeHeapPointerTagging="false" android:allowBackup="true" - android:fullBackupOnly="false"> + 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" 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/doc/images/sensorsshowcase-gyroscope.webp b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.webp Binary files differindex 3460852b..0ff45403 100644 --- a/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.webp +++ b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-gyroscope.webp diff --git a/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.webp b/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.webp Binary files differindex 2bfa9ac4..b045b7ba 100644 --- a/examples/sensors/sensorsshowcase/doc/images/sensorsshowcase-mainview.webp +++ 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 43be13c1..d3d31c34 100644 --- a/examples/sensors/sensorsshowcase/doc/src/sensorsshowcase.qdoc +++ b/examples/sensors/sensorsshowcase/doc/src/sensorsshowcase.qdoc @@ -7,6 +7,7 @@ \brief The Sensors Showcase example demonstrates sensor usage with visual examples. \meta tag {sensors,quick,mobile} \ingroup qtsensors-examples + \examplecategory {Mobile} \image sensorsshowcase-mainview.webp @@ -18,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 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/main.cpp b/examples/sensors/sensorsshowcase/main.cpp index bab92024..4a7bd285 100644 --- a/examples/sensors/sensorsshowcase/main.cpp +++ b/examples/sensors/sensorsshowcase/main.cpp @@ -1,8 +1,7 @@ // Copyright (C) 2023 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QtGui/qguiapplication.h> -#include <QtQml/qqmlapplicationengine.h> +#include <QGuiApplication> +#include <QQmlApplicationEngine> int main(int argc, char *argv[]) { diff --git a/examples/sensors/sensorsshowcase/qtquickcontrols2.conf b/examples/sensors/sensorsshowcase/qtquickcontrols2.conf index e2641ea3..76439328 100644 --- a/examples/sensors/sensorsshowcase/qtquickcontrols2.conf +++ b/examples/sensors/sensorsshowcase/qtquickcontrols2.conf @@ -1,10 +1,6 @@ [Controls] Style=Material -[Universal] -Background=Amber -Accent=Orange - [Material] -Background=Orange -Accent=DeepOrange +Background=#eafcf3 +Accent=#28c878 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 |