From 2201ebd1d7167c755787399411b230ca8f3ce8b4 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Fri, 29 Apr 2022 18:59:14 -0400 Subject: [PATCH] Remove QtFeedback dependency --- CMakeLists.txt | 1 - components/mobileshell/CMakeLists.txt | 2 -- components/mobileshell/haptics.cpp | 26 ---------------- components/mobileshell/haptics.h | 18 ----------- components/mobileshell/mobileshellplugin.cpp | 6 +--- .../mobileshell/qml/components/Haptics.qml | 31 +++++++++++++++++++ .../qml/components/HapticsEffectWrapper.qml | 14 +++++++++ components/mobileshell/resources.qrc | 2 ++ 8 files changed, 48 insertions(+), 52 deletions(-) delete mode 100644 components/mobileshell/haptics.cpp delete mode 100644 components/mobileshell/haptics.h create mode 100644 components/mobileshell/qml/components/Haptics.qml create mode 100644 components/mobileshell/qml/components/HapticsEffectWrapper.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index 11155b6a..7b8ea595 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,6 @@ find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Qml Quick QuickCompiler - Feedback ) if (QUICK_COMPILER) diff --git a/components/mobileshell/CMakeLists.txt b/components/mobileshell/CMakeLists.txt index 60e059e0..12bb431e 100644 --- a/components/mobileshell/CMakeLists.txt +++ b/components/mobileshell/CMakeLists.txt @@ -6,7 +6,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) set(mobileshellplugin_SRCS mobileshellplugin.cpp - haptics.cpp mobileshellsettings.cpp quicksetting.cpp quicksettingsmodel.cpp @@ -38,7 +37,6 @@ target_link_libraries(mobileshellplugin Qt::Qml Qt::Gui Qt::Quick - Qt::Feedback KF5::ConfigWidgets # for KStandardAction KF5::KIOGui KF5::Plasma diff --git a/components/mobileshell/haptics.cpp b/components/mobileshell/haptics.cpp deleted file mode 100644 index 85b6f738..00000000 --- a/components/mobileshell/haptics.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Devin Lin - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#include "haptics.h" - -#include - -#include "mobileshellsettings.h" - -Haptics *Haptics::self() -{ - static Haptics *singleton = new Haptics(); - return singleton; -} - -void Haptics::buttonVibrate() -{ - if (MobileShellSettings::self()->vibrationsEnabled()) { - QFeedbackHapticsEffect rumble; - rumble.setIntensity(0.5); - rumble.setDuration(100); - rumble.start(); - } -} diff --git a/components/mobileshell/haptics.h b/components/mobileshell/haptics.h deleted file mode 100644 index 549008e7..00000000 --- a/components/mobileshell/haptics.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Devin Lin - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -#pragma once - -#include - -class Haptics : public QObject -{ - Q_OBJECT - -public: - static Haptics *self(); - - Q_INVOKABLE void buttonVibrate(); -}; diff --git a/components/mobileshell/mobileshellplugin.cpp b/components/mobileshell/mobileshellplugin.cpp index 536954ca..5e73d76e 100644 --- a/components/mobileshell/mobileshellplugin.cpp +++ b/components/mobileshell/mobileshellplugin.cpp @@ -19,7 +19,6 @@ #include "taskswitcher/displaysmodel.h" -#include "haptics.h" #include "mobileshellsettings.h" #include "quicksetting.h" #include "quicksettingsmodel.h" @@ -39,10 +38,6 @@ void MobileShellPlugin::registerTypes(const char *uri) return ShellUtil::instance(); }); - qmlRegisterSingletonType(uri, 1, 0, "Haptics", [](QQmlEngine *, QJSEngine *) -> QObject * { - return Haptics::self(); - }); - qmlRegisterSingletonType(uri, 1, 0, "MobileShellSettings", [](QQmlEngine *, QJSEngine *) -> QObject * { return MobileShellSettings::self(); }); @@ -82,6 +77,7 @@ void MobileShellPlugin::registerTypes(const char *uri) // /components qmlRegisterType(resolvePath("components/BaseItem.qml"), uri, 1, 0, "BaseItem"); + qmlRegisterSingletonType(resolvePath("components/Haptics.qml"), uri, 1, 0, "Haptics"); qmlRegisterType(resolvePath("components/StartupFeedback.qml"), uri, 1, 0, "StartupFeedback"); qmlRegisterType(resolvePath("components/VelocityCalculator.qml"), uri, 1, 0, "VelocityCalculator"); diff --git a/components/mobileshell/qml/components/Haptics.qml b/components/mobileshell/qml/components/Haptics.qml new file mode 100644 index 00000000..b8b80cb4 --- /dev/null +++ b/components/mobileshell/qml/components/Haptics.qml @@ -0,0 +1,31 @@ +/* + * SPDX-FileCopyrightText: 2022 Devin Lin + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +import QtQuick 2.15 +import QtFeedback 5.0 + +import org.kde.plasma.private.mobileshell 1.0 as MobileShell + +pragma Singleton + +QtObject { + id: root + + function buttonVibrate() { + if (MobileShell.MobileShellSettings.vibrationsEnabled) { + if (hapticsEffect.status == Loader.Ready) { + hapticsEffect.item.intensity = 0.5; + hapticsEffect.item.duration = 100; + hapticsEffect.item.start(); + } + } + } + + Component.onCompleted: { + hapticsEffect.setSource("HapticsEffectWrapper.qml"); + } + + property var hapticsEffect: Loader {} +} diff --git a/components/mobileshell/qml/components/HapticsEffectWrapper.qml b/components/mobileshell/qml/components/HapticsEffectWrapper.qml new file mode 100644 index 00000000..6ac4b46c --- /dev/null +++ b/components/mobileshell/qml/components/HapticsEffectWrapper.qml @@ -0,0 +1,14 @@ +/* + * SPDX-FileCopyrightText: 2022 Devin Lin + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +import QtQuick 2.15 +import QtFeedback 5.0 + +/** + * Private component that wraps a QtFeedback HapticsEffect, so that we can optionally load + * this component. + */ + +HapticsEffect {} diff --git a/components/mobileshell/resources.qrc b/components/mobileshell/resources.qrc index 4135c7c3..df7b502a 100644 --- a/components/mobileshell/resources.qrc +++ b/components/mobileshell/resources.qrc @@ -21,6 +21,8 @@ qml/actiondrawer/PortraitContentContainer.qml qml/components/BaseItem.qml + qml/components/Haptics.qml + qml/components/HapticsEffectWrapper.qml qml/components/MarqueeLabel.qml qml/components/StartupFeedback.qml qml/components/util.js