ui: horizontal scroll fix

* prevented the mouse wheel from scrolling a horizontal scrollbar when the mouse happens to enter the scrollbar's area.
This commit is contained in:
malte_langkabel
2015-11-03 12:40:03 +01:00
parent 11147e982f
commit 006e73ef4c
2 changed files with 40 additions and 0 deletions
+28
View File
@@ -23,6 +23,31 @@
#include "settings/ApplicationSettings.h"
#include "settings/ColorScheme.h"
MouseWheelOverScrollbarFilter::MouseWheelOverScrollbarFilter(QObject* parent)
: QObject(parent)
{
}
bool MouseWheelOverScrollbarFilter::eventFilter(QObject* obj, QEvent* event)
{
QScrollBar* scrollbar = dynamic_cast<QScrollBar*>(obj);
if (event->type() == QEvent::Wheel && scrollbar)
{
QRect scrollbarArea(scrollbar->pos(), scrollbar->size());
QPoint globalMousePos = dynamic_cast<QWheelEvent*>(event)->globalPos();
QPoint localMousePos = scrollbar->mapFromGlobal(globalMousePos);
// instead of "scrollbar->underMouse()" we need this check implemented here because "underMouse()"
// does not work when the mouse enters the area without being moved
if (scrollbarArea.contains(localMousePos))
{
event->ignore();
return true;
}
}
return QObject::eventFilter(obj, event);
}
QtCodeArea::LineNumberArea::LineNumberArea(QtCodeArea *codeArea)
: QWidget(codeArea)
, m_codeArea(codeArea)
@@ -87,6 +112,9 @@ QtCodeArea::QtCodeArea(
connect(this, SIGNAL(selectionChanged()), this, SLOT(clearSelection()));
this->setMouseTracking(true);
// MouseWheelOverScrollbarFilter is deleted by parent.
horizontalScrollBar()->installEventFilter(new MouseWheelOverScrollbarFilter(this));
}
QtCodeArea::~QtCodeArea()
+12
View File
@@ -19,6 +19,18 @@ class QWidget;
class TokenLocation;
class TokenLocationFile;
class MouseWheelOverScrollbarFilter
: public QObject
{
Q_OBJECT
public:
MouseWheelOverScrollbarFilter(QObject* parent);
protected:
bool eventFilter(QObject*obj, QEvent* event);
};
class QtCodeArea
: public QPlainTextEdit
{