From df65a0e0f2de58de313d3a2ae06f35181f08cc29 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Fri, 11 Nov 2022 11:56:40 -0500 Subject: [PATCH] mobileshell: Remove compile time QtFeedback dependency, and make it optional --- CMakeLists.txt | 1 - README.md | 1 - components/mobileshell/CMakeLists.txt | 1 - components/mobileshell/mobileshellplugin.cpp | 1 + .../QuickSettingsFullDelegate.qml | 8 ++++++-- .../QuickSettingsMinimizedDelegate.qml | 8 ++++++-- .../qml/components/HapticsEffectLoader.qml | 20 +++++++++++++++++++ .../qml/components/HapticsEffectWrapper.qml | 7 +++++++ .../qml/navigationpanel/NavigationPanel.qml | 6 +++++- components/mobileshell/resources.qrc | 2 ++ components/mobileshell/shellutil.cpp | 10 ---------- components/mobileshell/shellutil.h | 8 -------- look-and-feel/contents/lockscreen/Keypad.qml | 8 ++++++-- 13 files changed, 53 insertions(+), 28 deletions(-) create mode 100644 components/mobileshell/qml/components/HapticsEffectLoader.qml create mode 100644 components/mobileshell/qml/components/HapticsEffectWrapper.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ca75294..75f5750c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,6 @@ find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} CONFIG REQUIRED Core Qml Quick - Feedback ) if (QT_MAJOR_VERSION STREQUAL "5") if (QUICK_COMPILER) diff --git a/README.md b/README.md index f1cb1b2b..4bcd4c65 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,6 @@ Dependencies: * Plasma Nano * Kirigami * Kirigami Addons -* Qt Feedback To start the phone homescreen in a window, run: ``` diff --git a/components/mobileshell/CMakeLists.txt b/components/mobileshell/CMakeLists.txt index 72b89567..0499652c 100644 --- a/components/mobileshell/CMakeLists.txt +++ b/components/mobileshell/CMakeLists.txt @@ -38,7 +38,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/mobileshellplugin.cpp b/components/mobileshell/mobileshellplugin.cpp index bcd8b402..5186290f 100644 --- a/components/mobileshell/mobileshellplugin.cpp +++ b/components/mobileshell/mobileshellplugin.cpp @@ -72,6 +72,7 @@ void MobileShellPlugin::registerTypes(const char *uri) qmlRegisterType(resolvePath("components/ExtendedAbstractButton.qml"), uri, 1, 0, "ExtendedAbstractButton"); qmlRegisterType(resolvePath("components/Flickable.qml"), uri, 1, 0, "Flickable"); qmlRegisterType(resolvePath("components/GridView.qml"), uri, 1, 0, "GridView"); + qmlRegisterType(resolvePath("components/HapticsEffectLoader.qml"), uri, 1, 0, "HapticsEffectLoader"); qmlRegisterType(resolvePath("components/ListView.qml"), uri, 1, 0, "ListView"); qmlRegisterType(resolvePath("components/StartupFeedback.qml"), uri, 1, 0, "StartupFeedback"); qmlRegisterType(resolvePath("components/VelocityCalculator.qml"), uri, 1, 0, "VelocityCalculator"); diff --git a/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsFullDelegate.qml b/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsFullDelegate.qml index d760da92..fa6c7cc6 100644 --- a/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsFullDelegate.qml +++ b/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsFullDelegate.qml @@ -55,13 +55,17 @@ QuickSettingsDelegate { } } + MobileShell.HapticsEffectLoader { + id: haptics + } + contentItem: MouseArea { id: mouseArea - onPressed: MobileShell.ShellUtil.buttonVibrate() + onPressed: haptics.buttonVibrate() onClicked: root.delegateClick() onPressAndHold: { - MobileShell.ShellUtil.buttonVibrate(); + haptics.buttonVibrate(); root.delegatePressAndHold(); } diff --git a/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsMinimizedDelegate.qml b/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsMinimizedDelegate.qml index 2fe50094..723f7040 100644 --- a/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsMinimizedDelegate.qml +++ b/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsMinimizedDelegate.qml @@ -52,13 +52,17 @@ QuickSettingsDelegate { } } + MobileShell.HapticsEffectLoader { + id: haptics + } + contentItem: MouseArea { id: mouseArea - onPressed: MobileShell.ShellUtil.buttonVibrate(); + onPressed: haptics.buttonVibrate(); onClicked: root.delegateClick() onPressAndHold: { - MobileShell.ShellUtil.buttonVibrate(); + haptics.buttonVibrate(); root.delegatePressAndHold(); } diff --git a/components/mobileshell/qml/components/HapticsEffectLoader.qml b/components/mobileshell/qml/components/HapticsEffectLoader.qml new file mode 100644 index 00000000..322ebe8d --- /dev/null +++ b/components/mobileshell/qml/components/HapticsEffectLoader.qml @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Devin Lin +// SPDX-License-Identifier: GPL-2.0-or-later + +import QtQuick 2.15 + +import org.kde.plasma.private.mobileshell 1.0 as MobileShell + +Loader { + source: "qrc:/HapticsEffectWrapper.qml" + property bool valid: item !== null + + function buttonVibrate() { + if (valid && MobileShell.MobileShellSettings.vibrationsEnabled) { + item.intensity = MobileShell.MobileShellSettings.vibrationIntensity; + item.duration = MobileShell.MobileShellSettings.vibrationDuration; + item.start(); + } + } +} + diff --git a/components/mobileshell/qml/components/HapticsEffectWrapper.qml b/components/mobileshell/qml/components/HapticsEffectWrapper.qml new file mode 100644 index 00000000..5f37515e --- /dev/null +++ b/components/mobileshell/qml/components/HapticsEffectWrapper.qml @@ -0,0 +1,7 @@ +// SPDX-FileCopyrightText: 2022 Devin Lin +// SPDX-License-Identifier: GPL-2.0-or-later + +import QtFeedback 5.0 + +HapticsEffect {} + diff --git a/components/mobileshell/qml/navigationpanel/NavigationPanel.qml b/components/mobileshell/qml/navigationpanel/NavigationPanel.qml index bcb9bbd0..61dcb51d 100644 --- a/components/mobileshell/qml/navigationpanel/NavigationPanel.qml +++ b/components/mobileshell/qml/navigationpanel/NavigationPanel.qml @@ -61,12 +61,16 @@ Item { property NavigationPanelButton activeButton + MobileShell.HapticsEffectLoader { + id: haptics + } + onPressed: { startMouseX = oldMouseX = mouse.y; startMouseY = oldMouseY = mouse.y; activeButton = icons.childAt(mouse.x, mouse.y); if (activeButton && activeButton.enabled) { - MobileShell.ShellUtil.buttonVibrate(); + haptics.buttonVibrate(); } } diff --git a/components/mobileshell/resources.qrc b/components/mobileshell/resources.qrc index 6e447ddb..fad90ae1 100644 --- a/components/mobileshell/resources.qrc +++ b/components/mobileshell/resources.qrc @@ -24,6 +24,8 @@ qml/components/ExtendedAbstractButton.qml qml/components/Flickable.qml qml/components/GridView.qml + qml/components/HapticsEffectLoader.qml + qml/components/HapticsEffectWrapper.qml qml/components/ListView.qml qml/components/MarqueeLabel.qml qml/components/StartupFeedback.qml diff --git a/components/mobileshell/shellutil.cpp b/components/mobileshell/shellutil.cpp index 7bb281b9..904bb24f 100644 --- a/components/mobileshell/shellutil.cpp +++ b/components/mobileshell/shellutil.cpp @@ -28,7 +28,6 @@ ShellUtil::ShellUtil(QObject *parent) : QObject{parent} , m_localeConfig{KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::SimpleConfig)} , m_launchingApp{nullptr} - , m_hapticsEffect{std::make_unique()} { m_localeConfigWatcher = KConfigWatcher::create(m_localeConfig); @@ -133,12 +132,3 @@ void ShellUtil::clearLaunchingApp() m_launchingApp = nullptr; Q_EMIT isLaunchingAppChanged(); } - -void ShellUtil::buttonVibrate() -{ - if (MobileShellSettings::self()->vibrationsEnabled()) { - m_hapticsEffect->setDuration(MobileShellSettings::self()->vibrationDuration()); - m_hapticsEffect->setIntensity(MobileShellSettings::self()->vibrationIntensity()); - m_hapticsEffect->start(); - } -} diff --git a/components/mobileshell/shellutil.h b/components/mobileshell/shellutil.h index 48700fe0..d6b426c5 100644 --- a/components/mobileshell/shellutil.h +++ b/components/mobileshell/shellutil.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include @@ -82,11 +81,6 @@ public: */ Q_INVOKABLE void clearLaunchingApp(); - /** - * Initiates a vibration event, meant for a button. - */ - Q_INVOKABLE void buttonVibrate(); - Q_SIGNALS: void isSystem24HourFormatChanged(); void isLaunchingAppChanged(); @@ -99,6 +93,4 @@ private: KIO::ApplicationLauncherJob *m_launchingApp; QVector m_launchingAppPids; - - std::unique_ptr m_hapticsEffect; }; diff --git a/look-and-feel/contents/lockscreen/Keypad.qml b/look-and-feel/contents/lockscreen/Keypad.qml index 5a2b18ad..39cf58b6 100644 --- a/look-and-feel/contents/lockscreen/Keypad.qml +++ b/look-and-feel/contents/lockscreen/Keypad.qml @@ -54,6 +54,10 @@ Rectangle { } } + MobileShell.HapticsEffectLoader { + id: haptics + } + RectangularGlow { anchors.topMargin: 1 anchors.fill: passwordBar @@ -147,7 +151,7 @@ Rectangle { onPressedChanged: { if (pressed) { - MobileShell.ShellUtil.buttonVibrate(); + haptics.buttonVibrate(); } } @@ -162,7 +166,7 @@ Rectangle { } onPressAndHold: { if (modelData === "R") { - MobileShell.ShellUtil.buttonVibrate(); + haptics.buttonVibrate(); passwordBar.clear(); } }