[vlc-commits] Qt: handle special mouse buttons

Francois Cartegnie git at videolan.org
Fri Mar 2 01:36:16 CET 2012


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Feb 27 20:54:31 2012 +0100| [e3511f67bc3ea374382359ed92b6d4312282f7a9] | committer: Francois Cartegnie

Qt: handle special mouse buttons

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

 modules/gui/qt4/components/preferences_widgets.cpp |    8 ++++++++
 modules/gui/qt4/components/preferences_widgets.hpp |    1 +
 modules/gui/qt4/main_interface.cpp                 |   12 ++++++++++++
 modules/gui/qt4/main_interface.hpp                 |    1 +
 modules/gui/qt4/util/customwidgets.cpp             |   20 ++++++++++++++++++++
 modules/gui/qt4/util/customwidgets.hpp             |    1 +
 6 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/modules/gui/qt4/components/preferences_widgets.cpp b/modules/gui/qt4/components/preferences_widgets.cpp
index 59bda1a..6eb66d4 100644
--- a/modules/gui/qt4/components/preferences_widgets.cpp
+++ b/modules/gui/qt4/components/preferences_widgets.cpp
@@ -1614,3 +1614,11 @@ void KeyInputDialog::wheelEvent( QWheelEvent *e )
     keyValue = i_vlck;
 }
 
+void KeyInputDialog::mousePressEvent( QMouseEvent *e )
+{
+    int i_vlck = qtMouseEventToVLCKey( e );
+    selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
+    checkForConflicts( i_vlck );
+    keyValue = i_vlck;
+}
+
diff --git a/modules/gui/qt4/components/preferences_widgets.hpp b/modules/gui/qt4/components/preferences_widgets.hpp
index f7d7e36..20d2529 100644
--- a/modules/gui/qt4/components/preferences_widgets.hpp
+++ b/modules/gui/qt4/components/preferences_widgets.hpp
@@ -485,6 +485,7 @@ private:
     void checkForConflicts( int i_vlckey );
     void keyPressEvent( QKeyEvent *);
     void wheelEvent( QWheelEvent *);
+    void mousePressEvent( QMouseEvent * );
     bool b_global;
 };
 #endif
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 091a99b..e0a8562 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -1314,6 +1314,18 @@ void MainInterface::wheelEvent( QWheelEvent *e )
     e->accept();
 }
 
+void MainInterface::mousePressEvent( QMouseEvent *e )
+{
+    int i_vlckey = qtMouseEventToVLCKey( e );
+    if( i_vlckey > 0 )
+    {
+        var_SetInteger( p_intf->p_libvlc, "key-pressed", i_vlckey );
+        e->accept();
+    }
+    else
+        e->ignore();
+}
+
 void MainInterface::closeEvent( QCloseEvent *e )
 {
 //  hide();
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index 3567c4a..39c0de5 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -101,6 +101,7 @@ protected:
     virtual void closeEvent( QCloseEvent *);
     virtual void keyPressEvent( QKeyEvent *);
     virtual void wheelEvent( QWheelEvent * );
+    virtual void mousePressEvent( QMouseEvent * );
 
 private:
     /* Main Widgets Creation */
diff --git a/modules/gui/qt4/util/customwidgets.cpp b/modules/gui/qt4/util/customwidgets.cpp
index 16c6563..fce8555 100644
--- a/modules/gui/qt4/util/customwidgets.cpp
+++ b/modules/gui/qt4/util/customwidgets.cpp
@@ -286,6 +286,26 @@ int qtWheelEventToVLCKey( QWheelEvent *e )
     return i_vlck;
 }
 
+int qtMouseEventToVLCKey( QMouseEvent *e )
+{
+    int i_vlck = 0;
+    switch( e->button() )
+    {
+    case Qt::MidButton:
+        i_vlck |= KEY_MOUSEBUTTON_MID;
+        break;
+    case Qt::XButton1:
+        i_vlck |= KEY_MOUSEBUTTON_X1;
+        break;
+    case Qt::XButton2:
+        i_vlck |= KEY_MOUSEBUTTON_X2;
+    default:
+        break;
+    }
+    if ( i_vlck > 0 ) i_vlck |= qtKeyModifiersToVLC( e );
+    return i_vlck;
+}
+
 QString VLCKeyToString( unsigned val )
 {
     char *base = vlc_keycode2str (val);
diff --git a/modules/gui/qt4/util/customwidgets.hpp b/modules/gui/qt4/util/customwidgets.hpp
index 8f8fb3e..ac0d5fc 100644
--- a/modules/gui/qt4/util/customwidgets.hpp
+++ b/modules/gui/qt4/util/customwidgets.hpp
@@ -179,6 +179,7 @@ class QInputEvent;
 int qtKeyModifiersToVLC( QInputEvent* e );
 int qtEventToVLCKey( QKeyEvent *e );
 int qtWheelEventToVLCKey( QWheelEvent *e );
+int qtMouseEventToVLCKey( QMouseEvent *e );
 QString VLCKeyToString( unsigned val );
 
 #endif



More information about the vlc-commits mailing list