SceneSwitcher/lib/utils/mouse-wheel-guard.cpp
WarmUpTill 7d0332dd0e Restructure library and plugins
The "core" macro conditions and actions have been extracted out to the
"base" plugin.

The library now mostly contains functionality which is required across
all plugins and (e.g. definitions for macro segments).

The goal is to reduce the complexity and cross-dependencies and group
the source files in a better way.

This should relsove the "library limit of 65535 objects exceeded" build
issue occuring in some Windows build environments.
2024-01-27 14:10:34 +01:00

40 lines
1.0 KiB
C++

#include "mouse-wheel-guard.hpp"
#include <QEvent>
#include <QScrollBar>
namespace advss {
MouseWheelWidgetAdjustmentGuard::MouseWheelWidgetAdjustmentGuard(QObject *parent)
: QObject(parent)
{
}
bool MouseWheelWidgetAdjustmentGuard::eventFilter(QObject *o, QEvent *e)
{
const QWidget *widget = static_cast<QWidget *>(o);
if (e->type() == QEvent::Wheel && widget && !widget->hasFocus()) {
e->ignore();
return true;
}
return QObject::eventFilter(o, e);
}
void PreventMouseWheelAdjustWithoutFocus(QWidget *w)
{
// Ignore QScrollBar as there is no danger of accidentally modifying anything
// and long expanded QComboBox would be difficult to interact with otherwise.
// Ignore OSCMessageElementEdit to allow OSCMessageEdit list to up update
// current index correctly.
if (qobject_cast<QScrollBar *>(w) ||
QString(w->metaObject()->className()) ==
"advss::OSCMessageElementEdit") {
return;
}
w->setFocusPolicy(Qt::StrongFocus);
w->installEventFilter(new MouseWheelWidgetAdjustmentGuard(w));
}
} // namespace advss