[Libreoffice-commits] core.git: vcl/inc vcl/qt5

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Thu Jun 6 18:25:42 UTC 2019


 vcl/inc/qt5/Qt5Widget.hxx |    2 ++
 vcl/qt5/Qt5Widget.cxx     |   33 +++++++++++++++++++++++----------
 2 files changed, 25 insertions(+), 10 deletions(-)

New commits:
commit 1d959beba1cfef5fde035a4a74ee4611e7a04869
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Thu Jun 6 01:01:11 2019 +0000
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Thu Jun 6 20:24:34 2019 +0200

    tdf#125201 fix QWheelEvent angleDelta() handling
    
    Comming back to my initial, known broken implementation from
    2017-11 (see commit 1426437be053 ("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: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/vcl/inc/qt5/Qt5Widget.hxx b/vcl/inc/qt5/Qt5Widget.hxx
index 6398fa7db55c..ce4e068cbbec 100644
--- a/vcl/inc/qt5/Qt5Widget.hxx
+++ b/vcl/inc/qt5/Qt5Widget.hxx
@@ -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);
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index 63eb68577da1..4b378cd44cb2 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -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);


More information about the Libreoffice-commits mailing list