[vlc-commits] qt: support 2d surfaces for horizontal scroll

Maxim Sergeev git at videolan.org
Tue Apr 6 08:36:29 UTC 2021


vlc/vlc-3.0 | branch: master | Maxim Sergeev <gudvinr at gmail.com> | Sun Jun 28 17:07:42 2020 +0200| [704ccf4ea627458dd374d2936146c55ba00ffa12] | committer: Pierre Lamot

qt: support 2d surfaces for horizontal scroll

Fixes #20498

To avoid detection of erratic movements along the lines
introduce allowance zone for each axis.

Angle determines how close to axis angle delta is.
For horizontal events it is set to 30 degrees (15 for each side).
For vertical events angle is 53 degrees (30 * 16/9).
It is a little wider since touchpads are asymmetrical.

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=704ccf4ea627458dd374d2936146c55ba00ffa12
---

 modules/gui/qt/util/customwidgets.cpp | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/modules/gui/qt/util/customwidgets.cpp b/modules/gui/qt/util/customwidgets.cpp
index 3879cc350b..f8d2acf5e3 100644
--- a/modules/gui/qt/util/customwidgets.cpp
+++ b/modules/gui/qt/util/customwidgets.cpp
@@ -31,6 +31,7 @@
 #include "customwidgets.hpp"
 #include "qt.hpp"               /* needed for qtr,  but not necessary */
 
+#include <QtMath>  // for wheel deadzone calculation
 #include <QPainter>
 #include <QRect>
 #include <QKeyEvent>
@@ -297,13 +298,28 @@ int qtEventToVLCKey( QKeyEvent *e )
 
 int qtWheelEventToVLCKey( QWheelEvent *e )
 {
-    int i_vlck = 0;
-    /* Handle modifiers */
-    i_vlck |= qtKeyModifiersToVLC( e );
-    if ( e->delta() > 0 )
-        i_vlck |= KEY_MOUSEWHEELUP;
-    else
-        i_vlck |= KEY_MOUSEWHEELDOWN;
+    const qreal v_cos_deadzone = 0.45; // ~63 degrees
+    const qreal h_cos_deadzone = 0.95; // ~15 degrees
+
+    int i_vlck = qtKeyModifiersToVLC(e);  // Handle modifiers
+
+    QPoint p = e->angleDelta();
+    if (!p.isNull())
+    {
+        qreal cos = qFabs(p.x())/qSqrt(qPow(p.x(), 2) + qPow(p.y(), 2));
+
+        if (cos < v_cos_deadzone)
+        {
+            if (p.y() > 0) i_vlck |= KEY_MOUSEWHEELUP;
+            else           i_vlck |= KEY_MOUSEWHEELDOWN;
+        }
+        else if (cos > h_cos_deadzone)
+        {
+            if (p.x() > 0) i_vlck |= KEY_MOUSEWHEELLEFT;
+            else           i_vlck |= KEY_MOUSEWHEELRIGHT;
+        }
+    }
+
     return i_vlck;
 }
 



More information about the vlc-commits mailing list