diff --git a/src/global/SignalBlocker.cpp b/src/global/SignalBlocker.cpp index 533535e67..7a06488cb 100644 --- a/src/global/SignalBlocker.cpp +++ b/src/global/SignalBlocker.cpp @@ -7,8 +7,18 @@ #include +#include #include +bool mmqt::applyWheelEventFilter(QObject *const /*obj*/, QEvent *const event) +{ + if (event->type() == QEvent::Wheel) { + event->ignore(); + return true; + } + return false; +} + SignalBlocker::SignalBlocker(QObject &in) : obj{in} , wasBlocked{obj.signalsBlocked()} diff --git a/src/global/SignalBlocker.h b/src/global/SignalBlocker.h index 6ef7e2382..244db0c81 100644 --- a/src/global/SignalBlocker.h +++ b/src/global/SignalBlocker.h @@ -5,6 +5,7 @@ #include "RuleOf5.h" #include "utils.h" +#include #include #include @@ -23,3 +24,7 @@ class NODISCARD SignalBlocker final ~SignalBlocker(); DELETE_CTORS_AND_ASSIGN_OPS(SignalBlocker); }; + +namespace mmqt { +NODISCARD extern bool applyWheelEventFilter(QObject *obj, QEvent *event); +} diff --git a/src/preferences/configdialog.cpp b/src/preferences/configdialog.cpp index 397e1339b..662fb3272 100644 --- a/src/preferences/configdialog.cpp +++ b/src/preferences/configdialog.cpp @@ -7,6 +7,7 @@ #include "configdialog.h" #include "../configuration/configuration.h" +#include "../global/SignalBlocker.h" #include "audiopage.h" #include "autologpage.h" #include "clientpage.h" @@ -18,10 +19,28 @@ #include "pathmachinepage.h" #include "ui_configdialog.h" +#include +#include +#include #include #include #include +namespace { +class WheelEventFilter final : public QObject +{ +public: + explicit WheelEventFilter(QObject *const parent) + : QObject(parent) + {} + + bool eventFilter(QObject *const obj, QEvent *const event) override + { + return mmqt::applyWheelEventFilter(obj, event); + } +}; +} // namespace + ConfigDialog::ConfigDialog(QWidget *const parent) : QDialog(parent) , ui(new Ui::ConfigDialog) @@ -86,6 +105,17 @@ ConfigDialog::ConfigDialog(QWidget *const parent) &GraphicsPage::sig_graphicsSettingsChanged, this, &ConfigDialog::sig_graphicsSettingsChanged); + + auto *const filter = new WheelEventFilter(this); + for (auto *const comboBox : findChildren()) { + comboBox->installEventFilter(filter); + } + for (auto *const slider : findChildren()) { + slider->installEventFilter(filter); + } + for (auto *const spinBox : findChildren()) { + spinBox->installEventFilter(filter); + } } ConfigDialog::~ConfigDialog() diff --git a/tests/TestGlobal.cpp b/tests/TestGlobal.cpp index f2e84cc9e..fb7745e77 100644 --- a/tests/TestGlobal.cpp +++ b/tests/TestGlobal.cpp @@ -14,6 +14,7 @@ #include "../src/global/LineUtils.h" #include "../src/global/RAII.h" #include "../src/global/Signal2.h" +#include "../src/global/SignalBlocker.h" #include "../src/global/StringView.h" #include "../src/global/TaggedString.h" #include "../src/global/TextUtils.h" @@ -647,4 +648,27 @@ void TestGlobal::weakHandleTest() test::testWeakHandle(); } +void TestGlobal::wheelEventFilterTest() +{ + QObject obj; + QWheelEvent wheelEvent(QPointF(0, 0), + QPointF(0, 0), + QPoint(0, 0), + QPoint(0, 120), + Qt::NoButton, + Qt::NoModifier, + Qt::ScrollBegin, + false); + + wheelEvent.setAccepted(false); + QVERIFY(!wheelEvent.isAccepted()); + bool handled = mmqt::applyWheelEventFilter(&obj, &wheelEvent); + QVERIFY(handled); + QVERIFY(!wheelEvent.isAccepted()); // should be ignored + + QEvent otherEvent(QEvent::MouseButtonPress); + handled = mmqt::applyWheelEventFilter(&obj, &otherEvent); + QVERIFY(!handled); +} + QTEST_MAIN(TestGlobal) diff --git a/tests/TestGlobal.h b/tests/TestGlobal.h index 97e96d798..86c3f2194 100644 --- a/tests/TestGlobal.h +++ b/tests/TestGlobal.h @@ -40,4 +40,5 @@ private Q_SLOTS: static void toNumberTest(); static void unquoteTest(); static void weakHandleTest(); + static void wheelEventFilterTest(); };