[vlc-commits] qt: support 2d surfaces for horizontal scroll
Maxim Sergeev
git at videolan.org
Tue Apr 6 09:31:06 UTC 2021
vlc | branch: master | Maxim Sergeev <gudvinr at gmail.com> | Tue Apr 6 11:26:05 2021 +0200| [e8d929f348aabb28ca2921cb4a31125a5ff7a2fa] | 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.git/?a=commit;h=e8d929f348aabb28ca2921cb4a31125a5ff7a2fa
---
modules/gui/qt/widgets/native/customwidgets.cpp | 33 +++++++++++++++----------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/modules/gui/qt/widgets/native/customwidgets.cpp b/modules/gui/qt/widgets/native/customwidgets.cpp
index 3aaa481a9e..562d6f7ccf 100644
--- a/modules/gui/qt/widgets/native/customwidgets.cpp
+++ b/modules/gui/qt/widgets/native/customwidgets.cpp
@@ -30,6 +30,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>
@@ -296,22 +297,28 @@ int qtEventToVLCKey( QKeyEvent *e )
int qtWheelEventToVLCKey( const QWheelEvent& e )
{
- int i_vlck = 0;
- /* Handle modifiers */
- i_vlck |= qtKeyModifiersToVLC( e );
+ const qreal v_cos_deadzone = 0.45; // ~63 degrees
+ const qreal h_cos_deadzone = 0.95; // ~15 degrees
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
- if ( e.angleDelta().y() > 0 )
-#else
- if ( e.delta() > 0 )
-#endif
- {
- i_vlck |= KEY_MOUSEWHEELUP;
- }
- else
+ int i_vlck = qtKeyModifiersToVLC(e); // Handle modifiers
+
+ QPoint p = e.angleDelta();
+ if (!p.isNull())
{
- i_vlck |= KEY_MOUSEWHEELDOWN;
+ 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