Kaydet (Commit) 1d959beb authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

tdf#125201 fix QWheelEvent angleDelta() handling

Comming back to my initial, known broken implementation from
2017-11 (see commit 1426437b ("QT5 implement some mouse
handling")), which just works with mouse scroll wheels.

This just fixes angleDelta() based scrolling. An additional
patch might be needed, if some driver just uses pixelDelta()
values, but Qt explicitly states: "On X11 the pixelDelta()
value is driver specific and unreliable, use angleDelta()
instead.", so we'll do just that for now.

Change-Id: I1be5f9392ed475aea7ab4d965a07e1e3c2574fe7
Reviewed-on: https://gerrit.libreoffice.org/73614
Tested-by: Jenkins
Reviewed-by: 's avatarJan-Marek Glogowski <glogow@fbihome.de>
üst caca5c73
......@@ -45,6 +45,8 @@ class Qt5Widget : public QWidget
Qt5Frame& m_rFrame;
bool m_bNonEmptyIMPreeditSeen;
int m_nDeltaX;
int m_nDeltaY;
bool handleKeyEvent(QKeyEvent*, bool);
void handleMouseButtonEvent(QMouseEvent*, bool);
......
......@@ -179,20 +179,31 @@ void Qt5Widget::wheelEvent(QWheelEvent* pEvent)
aEvent.mnY = pEvent->pos().y();
aEvent.mnCode = GetKeyModCode(pEvent->modifiers()) | GetMouseModCode(pEvent->buttons());
int nDelta = pEvent->angleDelta().x();
aEvent.mbHorz = true;
if (!nDelta)
// mouse wheel ticks are 120, which we map to 3 lines.
// we have to accumulate for touch scroll to keep track of the absolute delta.
int nDelta = pEvent->angleDelta().y(), lines;
aEvent.mbHorz = nDelta == 0;
if (aEvent.mbHorz)
{
nDelta = pEvent->angleDelta().x();
if (!nDelta)
return;
m_nDeltaX += nDelta;
lines = m_nDeltaX / 40;
m_nDeltaX = m_nDeltaX % 40;
}
else
{
nDelta = pEvent->angleDelta().y();
aEvent.mbHorz = false;
m_nDeltaY += nDelta;
lines = m_nDeltaY / 40;
m_nDeltaY = m_nDeltaY % 40;
}
if (!nDelta)
return;
nDelta /= 8;
aEvent.mnDelta = nDelta;
aEvent.mnNotchDelta = nDelta > 0 ? 1 : -1;
aEvent.mnScrollLines = 3;
aEvent.mnNotchDelta = nDelta < 0 ? -1 : 1;
aEvent.mnScrollLines = std::abs(lines);
m_rFrame.CallCallback(SalEvent::WheelMouse, &aEvent);
pEvent->accept();
......@@ -479,6 +490,8 @@ Qt5Widget::Qt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f)
: QWidget(Q_NULLPTR, f)
, m_rFrame(rFrame)
, m_bNonEmptyIMPreeditSeen(false)
, m_nDeltaX(0)
, m_nDeltaY(0)
{
create();
setMouseTracking(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment