mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-17 07:07:15 -05:00
Move MouseWheelWidgetAdjustmentGuard
This commit is contained in:
parent
2cb62eae96
commit
be23065988
|
|
@ -252,6 +252,8 @@ target_sources(
|
|||
src/utils/file-selection.hpp
|
||||
src/utils/macro-list.cpp
|
||||
src/utils/macro-list.hpp
|
||||
src/utils/mouse-wheel-guard.cpp
|
||||
src/utils/mouse-wheel-guard.hpp
|
||||
src/utils/name-dialog.cpp
|
||||
src/utils/name-dialog.hpp
|
||||
src/utils/process-config.cpp
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "macro-segment.hpp"
|
||||
#include "section.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "mouse-wheel-guard.hpp"
|
||||
|
||||
#include <obs.hpp>
|
||||
#include <QEvent>
|
||||
|
|
@ -81,22 +82,6 @@ void MacroSegment::DecrementVariableRef()
|
|||
_variableRefs--;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
MacroSegmentEdit::MacroSegmentEdit(bool highlight, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
_section(new Section(300)),
|
||||
|
|
@ -247,13 +232,7 @@ void MacroSegmentEdit::SetFocusPolicyOfWidgets()
|
|||
{
|
||||
QList<QWidget *> widgets = this->findChildren<QWidget *>();
|
||||
for (auto w : widgets) {
|
||||
w->setFocusPolicy(Qt::StrongFocus);
|
||||
// Ignore QScrollBar as there is no danger of accidentally modifying anything
|
||||
// and long expanded QComboBox would be difficult to interact with otherwise.
|
||||
if (qobject_cast<QScrollBar *>(w)) {
|
||||
continue;
|
||||
}
|
||||
w->installEventFilter(new MouseWheelWidgetAdjustmentGuard(w));
|
||||
PreventMouseWheelAdjustWithoutFocus(w);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,11 +113,3 @@ private:
|
|||
|
||||
friend class MacroSegmentList;
|
||||
};
|
||||
|
||||
class MouseWheelWidgetAdjustmentGuard : public QObject {
|
||||
public:
|
||||
explicit MouseWheelWidgetAdjustmentGuard(QObject *parent);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *o, QEvent *e) override;
|
||||
};
|
||||
|
|
|
|||
31
src/utils/mouse-wheel-guard.cpp
Normal file
31
src/utils/mouse-wheel-guard.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include "mouse-wheel-guard.hpp"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QScrollBar>
|
||||
|
||||
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)
|
||||
{
|
||||
w->setFocusPolicy(Qt::StrongFocus);
|
||||
// Ignore QScrollBar as there is no danger of accidentally modifying anything
|
||||
// and long expanded QComboBox would be difficult to interact with otherwise.
|
||||
if (qobject_cast<QScrollBar *>(w)) {
|
||||
return;
|
||||
}
|
||||
w->installEventFilter(new MouseWheelWidgetAdjustmentGuard(w));
|
||||
}
|
||||
12
src/utils/mouse-wheel-guard.hpp
Normal file
12
src/utils/mouse-wheel-guard.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
#include <QWidget>
|
||||
|
||||
class MouseWheelWidgetAdjustmentGuard : public QObject {
|
||||
public:
|
||||
explicit MouseWheelWidgetAdjustmentGuard(QObject *parent);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *o, QEvent *e) override;
|
||||
};
|
||||
|
||||
void PreventMouseWheelAdjustWithoutFocus(QWidget *);
|
||||
Loading…
Reference in New Issue
Block a user