[vlc-devel] [PATCH] mouse wheel support for qt4 gui

Sergey Volk sergey.volk at gmail.com
Tue Apr 10 12:08:11 CEST 2007


Hi,
Here is a patch for mouse wheel support in qt4 gui. It adds wheel handler to
MainInterface, which gets wheel events only when no other child control
handled it yet - so any slider/scrollbar controls should intercept wheel
events and are supposed to continue working as usual, but when focused
control doesn't handle wheel events (buttons, status bar, video widget area
in non-fullscreen mode) - they will be re-routed to vlc-lib.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20070410/d55caff5/attachment.html>
-------------- next part --------------
Index: gui/qt4/main_interface.cpp
===================================================================
--- gui/qt4/main_interface.cpp	(revision 19754)
+++ gui/qt4/main_interface.cpp	(working copy)
@@ -551,6 +551,21 @@
         e->ignore();
 }
 
+void MainInterface::wheelEvent( QWheelEvent *e )
+{
+    int i_vlckey = 0;
+
+    if ( e->delta() > 0 )
+       i_vlckey = KEY_MOUSEWHEELUP;
+    else
+       i_vlckey = KEY_MOUSEWHEELDOWN;
+  
+    /* Handle modifiers */
+    i_vlckey |= qtKeyModifiersToVLC( e );
+    var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
+    e->accept();
+}
+
 void MainInterface::stop()
 {
     playlist_Stop( THEPL );
Index: gui/qt4/main_interface.hpp
===================================================================
--- gui/qt4/main_interface.hpp	(revision 19754)
+++ gui/qt4/main_interface.hpp	(working copy)
@@ -76,6 +76,7 @@
     /* Video */
     VideoWidget         *videoWidget;
     virtual void keyPressEvent( QKeyEvent *);
+    virtual void wheelEvent( QWheelEvent * );
 
     bool embeddedPlaylistWasActive;
     bool videoIsActive;
Index: gui/qt4/util/customwidgets.cpp
===================================================================
--- gui/qt4/util/customwidgets.cpp	(revision 19754)
+++ gui/qt4/util/customwidgets.cpp	(working copy)
@@ -97,15 +97,21 @@
 /***************************************************************************
  * Hotkeys converters
  ***************************************************************************/
+int qtKeyModifiersToVLC( 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;
+    return i_keyModifiers;
+}
 
 int qtEventToVLCKey( QKeyEvent *e )
 {
     int i_vlck = 0;
     /* Handle modifiers */
-    if( e->modifiers()& Qt::ShiftModifier ) i_vlck |= KEY_MODIFIER_SHIFT;
-    if( e->modifiers()& Qt::AltModifier ) i_vlck |= KEY_MODIFIER_ALT;
-    if( e->modifiers()& Qt::ControlModifier ) i_vlck |= KEY_MODIFIER_CTRL;
-    if( e->modifiers()& Qt::MetaModifier ) i_vlck |= KEY_MODIFIER_META;
+    i_vlck |= qtKeyModifiersToVLC( e );
 
     bool found = false;
     /* Look for some special keys */
Index: gui/qt4/util/customwidgets.hpp
===================================================================
--- gui/qt4/util/customwidgets.hpp	(revision 19754)
+++ gui/qt4/util/customwidgets.hpp	(working copy)
@@ -88,5 +88,6 @@
 class QKeyEvent;
 int qtEventToVLCKey( QKeyEvent *e );
 QString VLCKeyToString( int val );
+int qtKeyModifiersToVLC( QInputEvent* e );
 
 #endif


More information about the vlc-devel mailing list