Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/global/SignalBlocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@

#include <cassert>

#include <QEvent>
#include <QWidget>

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()}
Expand Down
5 changes: 5 additions & 0 deletions src/global/SignalBlocker.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "RuleOf5.h"
#include "utils.h"

#include <QEvent>
#include <QObject>
#include <QVector>

Expand All @@ -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);
}
30 changes: 30 additions & 0 deletions src/preferences/configdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "configdialog.h"

#include "../configuration/configuration.h"
#include "../global/SignalBlocker.h"
#include "audiopage.h"
#include "autologpage.h"
#include "clientpage.h"
Expand All @@ -18,10 +19,28 @@
#include "pathmachinepage.h"
#include "ui_configdialog.h"

#include <QAbstractSlider>
#include <QAbstractSpinBox>
#include <QComboBox>
#include <QIcon>
#include <QListWidget>
#include <QtWidgets>

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)
Expand Down Expand Up @@ -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<QComboBox *>()) {
comboBox->installEventFilter(filter);
}
for (auto *const slider : findChildren<QAbstractSlider *>()) {
slider->installEventFilter(filter);
}
for (auto *const spinBox : findChildren<QAbstractSpinBox *>()) {
spinBox->installEventFilter(filter);
}
}

ConfigDialog::~ConfigDialog()
Expand Down
24 changes: 24 additions & 0 deletions tests/TestGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions tests/TestGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ private Q_SLOTS:
static void toNumberTest();
static void unquoteTest();
static void weakHandleTest();
static void wheelEventFilterTest();
};
Loading