[vlc-devel] [PATCH 08/15] qt: fix QWheelEvent warnings when Qt 5.15 is used

Fatih Uzunoglu fuzun54 at outlook.com
Thu Feb 11 21:23:36 UTC 2021


---
 .../preferences/preferences_widgets.cpp       |  2 +-
 .../interface_window_handler.cpp              |  4 +++
 modules/gui/qt/maininterface/videosurface.cpp |  7 +++---
 modules/gui/qt/maininterface/videosurface.hpp |  4 +--
 .../gui/qt/widgets/native/customwidgets.cpp   | 25 +++++++++++++------
 .../gui/qt/widgets/native/customwidgets.hpp   |  4 +--
 6 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/modules/gui/qt/dialogs/preferences/preferences_widgets.cpp b/modules/gui/qt/dialogs/preferences/preferences_widgets.cpp
index 462d141400..54d5c1c175 100644
--- a/modules/gui/qt/dialogs/preferences/preferences_widgets.cpp
+++ b/modules/gui/qt/dialogs/preferences/preferences_widgets.cpp
@@ -1481,7 +1481,7 @@ void KeyInputDialog::keyPressEvent( QKeyEvent *e )
 
 void KeyInputDialog::wheelEvent( QWheelEvent *e )
 {
-    int i_vlck = qtWheelEventToVLCKey( e );
+    int i_vlck = qtWheelEventToVLCKey( *e );
     selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck, true ) );
     checkForConflicts( i_vlck, QString() );
     keyValue = i_vlck;
diff --git a/modules/gui/qt/maininterface/interface_window_handler.cpp b/modules/gui/qt/maininterface/interface_window_handler.cpp
index c1a2ffc3f5..3a46f02596 100644
--- a/modules/gui/qt/maininterface/interface_window_handler.cpp
+++ b/modules/gui/qt/maininterface/interface_window_handler.cpp
@@ -196,7 +196,11 @@ bool InterfaceWindowHandler::eventFilter(QObject*, QEvent* event)
         QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event);
         if (wheelEvent->modifiers() == Qt::ControlModifier)
         {
+#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
+            emit incrementIntfUserScaleFactor(wheelEvent->angleDelta().y() > 0);
+#else
             emit incrementIntfUserScaleFactor(wheelEvent->delta() > 0);
+#endif
             wheelEvent->accept();
             return true;
         }
diff --git a/modules/gui/qt/maininterface/videosurface.cpp b/modules/gui/qt/maininterface/videosurface.cpp
index aa746d5890..89d5e870b1 100644
--- a/modules/gui/qt/maininterface/videosurface.cpp
+++ b/modules/gui/qt/maininterface/videosurface.cpp
@@ -97,10 +97,9 @@ void VideoSurfaceProvider::onMouseMoved(float x, float y)
         vout_window_ReportMouseMoved(m_voutWindow, x, y);
 }
 
-void VideoSurfaceProvider::onMouseWheeled(const QPointF& pos, int delta, Qt::MouseButtons buttons,  Qt::KeyboardModifiers modifiers, Qt::Orientation orient)
+void VideoSurfaceProvider::onMouseWheeled(const QWheelEvent& event)
 {
-    QWheelEvent event(pos, delta, buttons, modifiers, orient);
-    int vlckey = qtWheelEventToVLCKey(&event);
+    int vlckey = qtWheelEventToVLCKey(event);
     QMutexLocker lock(&m_voutlock);
     if (m_voutWindow)
         vout_window_ReportKeyPress(m_voutWindow, vlckey);
@@ -242,7 +241,7 @@ void VideoSurface::geometryChanged(const QRectF& newGeometry, const QRectF& oldG
 #if QT_CONFIG(wheelevent)
 void VideoSurface::wheelEvent(QWheelEvent *event)
 {
-    emit mouseWheeled(event->posF(), event->delta(), event->buttons(), event->modifiers(), event->orientation());
+    emit mouseWheeled(*event);
     event->ignore();
 }
 #endif
diff --git a/modules/gui/qt/maininterface/videosurface.hpp b/modules/gui/qt/maininterface/videosurface.hpp
index d4570af5b7..427bb27ba3 100644
--- a/modules/gui/qt/maininterface/videosurface.hpp
+++ b/modules/gui/qt/maininterface/videosurface.hpp
@@ -52,7 +52,7 @@ public slots:
     void onMouseReleased( int vlcButton );
     void onMouseDoubleClick( int vlcButton );
     void onMouseMoved( float x, float y );
-    void onMouseWheeled(const QPointF &pos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient);
+    void onMouseWheeled(const QWheelEvent& event);
     void onKeyPressed(int key, Qt::KeyboardModifiers modifiers);
     void onSurfaceSizeChanged(QSizeF size);
 
@@ -110,7 +110,7 @@ signals:
     void mouseDblClicked( int vlcButton );
     void mouseMoved( float x, float y );
     void keyPressed(int key, Qt::KeyboardModifiers modifier);
-    void mouseWheeled(const QPointF& pos, int delta, Qt::MouseButtons buttons,  Qt::KeyboardModifiers modifiers, Qt::Orientation orient);
+    void mouseWheeled(const QWheelEvent& event);
 
 protected slots:
     void onProviderVideoChanged(bool);
diff --git a/modules/gui/qt/widgets/native/customwidgets.cpp b/modules/gui/qt/widgets/native/customwidgets.cpp
index d20a1eb52a..3aaa481a9e 100644
--- a/modules/gui/qt/widgets/native/customwidgets.cpp
+++ b/modules/gui/qt/widgets/native/customwidgets.cpp
@@ -109,13 +109,13 @@ void VLCQDial::paintEvent( QPaintEvent *event )
 /***************************************************************************
  * Hotkeys converters
  ***************************************************************************/
-int qtKeyModifiersToVLC( QInputEvent* e )
+int qtKeyModifiersToVLC( const QInputEvent& e )
 {
     int i_keyModifiers = 0;
-    if( e->modifiers() & Qt::ShiftModifier ) i_keyModifiers |= KEY_MODIFIER_SHIFT;
-    if( e->modifiers() & Qt::AltModifier ) i_keyModifiers |= KEY_MODIFIER_ALT;
-    if( e->modifiers() & Qt::ControlModifier ) i_keyModifiers |= KEY_MODIFIER_CTRL;
-    if( e->modifiers() & Qt::MetaModifier ) i_keyModifiers |= KEY_MODIFIER_META;
+    if( e.modifiers() & Qt::ShiftModifier ) i_keyModifiers |= KEY_MODIFIER_SHIFT;
+    if( e.modifiers() & Qt::AltModifier ) i_keyModifiers |= KEY_MODIFIER_ALT;
+    if( e.modifiers() & Qt::ControlModifier ) i_keyModifiers |= KEY_MODIFIER_CTRL;
+    if( e.modifiers() & Qt::MetaModifier ) i_keyModifiers |= KEY_MODIFIER_META;
     return i_keyModifiers;
 }
 
@@ -290,19 +290,28 @@ int qtEventToVLCKey( QKeyEvent *e )
     }
 
     /* Handle modifiers */
-    i_vlck |= qtKeyModifiersToVLC( e );
+    i_vlck |= qtKeyModifiersToVLC( *e );
     return i_vlck;
 }
 
-int qtWheelEventToVLCKey( QWheelEvent *e )
+int qtWheelEventToVLCKey( const QWheelEvent& e )
 {
     int i_vlck = 0;
     /* Handle modifiers */
     i_vlck |= qtKeyModifiersToVLC( e );
-    if ( e->delta() > 0 )
+
+#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
+    {
         i_vlck |= KEY_MOUSEWHEELDOWN;
+    }
     return i_vlck;
 }
 
diff --git a/modules/gui/qt/widgets/native/customwidgets.hpp b/modules/gui/qt/widgets/native/customwidgets.hpp
index 152d928973..efb0efa4d8 100644
--- a/modules/gui/qt/widgets/native/customwidgets.hpp
+++ b/modules/gui/qt/widgets/native/customwidgets.hpp
@@ -145,9 +145,9 @@ class QKeyEvent;
 class QWheelEvent;
 class QInputEvent;
 
-int qtKeyModifiersToVLC( QInputEvent* e );
+int qtKeyModifiersToVLC( const QInputEvent& e );
 int qtEventToVLCKey( QKeyEvent *e );
-int qtWheelEventToVLCKey( QWheelEvent *e );
+int qtWheelEventToVLCKey( const QWheelEvent& e );
 QString VLCKeyToString( unsigned val, bool );
 
 #endif
-- 
2.27.0



More information about the vlc-devel mailing list