[vlc-commits] qt: handle window mouse events

Thomas Guillem git at videolan.org
Wed Nov 30 17:23:33 CET 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Nov 30 15:43:37 2016 +0100| [30dc60272da1871df722eb1779bb1d21d6b133b5] | committer: Thomas Guillem

qt: handle window mouse events

Ref #9787

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

 modules/gui/qt/components/interface_widgets.cpp | 72 ++++++++++++++++++++++++-
 modules/gui/qt/components/interface_widgets.hpp |  8 ++-
 modules/gui/qt/main_interface.cpp               | 27 +++++++---
 modules/gui/qt/main_interface.hpp               |  8 +--
 modules/gui/qt/qt.cpp                           |  9 +++-
 5 files changed, 112 insertions(+), 12 deletions(-)

diff --git a/modules/gui/qt/components/interface_widgets.cpp b/modules/gui/qt/components/interface_widgets.cpp
index 688c293..7d4b43b 100644
--- a/modules/gui/qt/components/interface_widgets.cpp
+++ b/modules/gui/qt/components/interface_widgets.cpp
@@ -104,7 +104,8 @@ void VideoWidget::sync( void )
  * Request the video to avoid the conflicts
  **/
 WId VideoWidget::request( struct vout_window_t *p_wnd, unsigned int *pi_width,
-                          unsigned int *pi_height, bool b_keep_size )
+                          unsigned int *pi_height, bool b_keep_size,
+                          bool b_mouse_events )
 {
     if( stable )
     {
@@ -137,6 +138,11 @@ WId VideoWidget::request( struct vout_window_t *p_wnd, unsigned int *pi_width,
 #if !defined (QT5_HAS_X11) && !defined (Q_WS_X11) && !defined (Q_WS_QPA)
     stable->setAttribute( Qt::WA_PaintOnScreen, true );
 #endif
+    if( b_mouse_events )
+    {
+        stable->setMouseTracking( true );
+        setMouseTracking( true );
+    }
 
     layout->addWidget( stable );
 
@@ -181,6 +187,70 @@ void VideoWidget::resizeEvent( QResizeEvent *event )
     QWidget::resizeEvent( event );
 }
 
+int VideoWidget::qtMouseButton2VLC( Qt::MouseButton qtButton )
+{
+    if( !b_mouse_events || p_window == NULL )
+        return -1;
+    switch( qtButton )
+    {
+        case Qt::LeftButton:
+            return 0;
+        case Qt::RightButton:
+            return 2;
+        case Qt::MiddleButton:
+            return 1;
+        default:
+            return -1;
+    }
+}
+
+void VideoWidget::mouseReleaseEvent( QMouseEvent *event )
+{
+    int vlc_button = qtMouseButton2VLC( event->button() );
+    if( vlc_button >= 0 )
+    {
+        vout_window_ReportMouseReleased( p_window, vlc_button );
+        event->accept();
+    }
+    else
+        event->ignore();
+}
+
+void VideoWidget::mousePressEvent( QMouseEvent* event )
+{
+    int vlc_button = qtMouseButton2VLC( event->button() );
+    if( vlc_button >= 0 )
+    {
+        vout_window_ReportMousePressed( p_window, vlc_button );
+        event->accept();
+    }
+    else
+        event->ignore();
+}
+
+void VideoWidget::mouseMoveEvent( QMouseEvent *event )
+{
+    if( b_mouse_events && p_window != NULL )
+    {
+        vout_window_ReportMouseMoved( p_window, event->x(), event->y() );
+        event->accept();
+    }
+    else
+        event->ignore();
+}
+
+void VideoWidget::mouseDoubleClickEvent( QMouseEvent *event )
+{
+    if( qtMouseButton2VLC( event->button() ) == 0 )
+    {
+        vout_window_ReportMouseDoubleClick( p_window );
+        event->accept();
+    }
+    else
+        event->ignore();
+}
+
+
 void VideoWidget::release( void )
 {
     msg_Dbg( p_intf, "Video is not needed anymore" );
diff --git a/modules/gui/qt/components/interface_widgets.hpp b/modules/gui/qt/components/interface_widgets.hpp
index a07119e..b746bc3 100644
--- a/modules/gui/qt/components/interface_widgets.hpp
+++ b/modules/gui/qt/components/interface_widgets.hpp
@@ -59,7 +59,7 @@ public:
     VideoWidget( intf_thread_t * );
     virtual ~VideoWidget();
 
-    WId request( struct vout_window_t *, unsigned int *, unsigned int *, bool );
+    WId request( struct vout_window_t *, unsigned int *, unsigned int *, bool, bool );
     void  release( void );
     void  sync( void );
 
@@ -70,13 +70,19 @@ protected:
     }
 
     virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
+    void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+    void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+    void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
+    void mouseDoubleClickEvent(QMouseEvent *) Q_DECL_OVERRIDE;
 
 private:
+    int qtMouseButton2VLC( Qt::MouseButton );
     intf_thread_t *p_intf;
     vout_window_t *p_window;
 
     QWidget *stable;
     QLayout *layout;
+    bool b_mouse_events;
 signals:
     void sizeChanged( int, int );
 
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index 81eea83..b05d00c 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -204,8 +204,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
     /* VideoWidget connects for asynchronous calls */
     b_videoFullScreen = false;
-    connect( this, SIGNAL(askGetVideo(WId*,struct vout_window_t*,unsigned*,unsigned *, bool)),
-             this, SLOT(getVideoSlot(WId*,struct vout_window_t*,unsigned*,unsigned*, bool)),
+    connect( this, SIGNAL(askGetVideo(WId*,struct vout_window_t*,unsigned*,unsigned *, bool, bool)),
+             this, SLOT(getVideoSlot(WId*,struct vout_window_t*,unsigned*,unsigned*, bool, bool)),
              Qt::BlockingQueuedConnection );
     connect( this, SIGNAL(askReleaseVideo( void )),
              this, SLOT(releaseVideoSlot( void )),
@@ -224,6 +224,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
 
         CONNECT( this, askVideoSetFullScreen( bool ),
                  this, setVideoFullScreen( bool ) );
+        CONNECT( this, askHideMouse( bool ),
+                 this, setHideMouse( bool ) );
     }
 
     CONNECT( THEDP, toolBarConfUpdated(), this, toolBarConfUpdated() );
@@ -710,7 +712,7 @@ void MainInterface::toggleFSC()
  */
 WId MainInterface::getVideo( struct vout_window_t *p_wnd,
                              unsigned int *pi_width, unsigned int *pi_height,
-                             bool fullscreen )
+                             bool fullscreen, bool mouse_events )
 {
     if( !videoWidget )
         return 0;
@@ -718,20 +720,21 @@ WId MainInterface::getVideo( struct vout_window_t *p_wnd,
     /* This is a blocking call signal. Results are returned through pointers.
      * Beware of deadlocks! */
     WId id;
-    emit askGetVideo( &id, p_wnd, pi_width, pi_height, fullscreen );
+    emit askGetVideo( &id, p_wnd, pi_width, pi_height, fullscreen, mouse_events );
     return id;
 }
 
 void MainInterface::getVideoSlot( WId *p_id, struct vout_window_t *p_wnd,
                                   unsigned *pi_width, unsigned *pi_height,
-                                  bool fullscreen )
+                                  bool fullscreen, bool b_mouse_events )
 {
     /* Hidden or minimized, activate */
     if( isHidden() || isMinimized() )
         toggleUpdateSystrayMenu();
 
     /* Request the videoWidget */
-    WId ret = videoWidget->request( p_wnd, pi_width, pi_height, !b_autoresize );
+    WId ret = videoWidget->request( p_wnd, pi_width, pi_height, !b_autoresize,
+                                    b_mouse_events );
     *p_id = ret;
     if( ret ) /* The videoWidget is available */
     {
@@ -867,6 +870,11 @@ void MainInterface::setVideoFullScreen( bool fs )
     videoWidget->sync();
 }
 
+void MainInterface::setHideMouse( bool hide )
+{
+    videoWidget->setCursor( hide ? Qt::BlankCursor : Qt::ArrowCursor );
+}
+
 /* Slot to change the video always-on-top flag.
  * Emit askVideoOnTop() to invoke this from other thread. */
 void MainInterface::setVideoOnTop( bool on_top )
@@ -913,6 +921,13 @@ int MainInterface::controlVideo( int i_query, va_list args )
         emit askVideoSetFullScreen( b_fs );
         return VLC_SUCCESS;
     }
+    case VOUT_WINDOW_HIDE_MOUSE:
+    {
+        bool b_hide = va_arg( args, int );
+
+        emit askHideMouse( b_hide );
+        return VLC_SUCCESS;
+    }
     default:
         msg_Warn( p_intf, "unsupported control query" );
         return VLC_EGENERIC;
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index 18ab8ce..b37ec16 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -70,7 +70,7 @@ public:
 
     /* Video requests from core */
     WId  getVideo( struct vout_window_t *,
-                   unsigned int *pi_width, unsigned int *pi_height, bool );
+                   unsigned int *pi_width, unsigned int *pi_height, bool, bool );
     void releaseVideo( void );
     int  controlVideo( int i_query, va_list args );
 
@@ -212,7 +212,7 @@ public slots:
 
     /* Manage the Video Functions from the vout threads */
     void getVideoSlot( WId *p_id, struct vout_window_t *,
-                       unsigned *pi_width, unsigned *pi_height, bool );
+                       unsigned *pi_width, unsigned *pi_height, bool, bool );
     void releaseVideoSlot( void );
 
     void emitBoss();
@@ -255,6 +255,7 @@ private slots:
     void setVideoSize( unsigned int, unsigned int );
     void videoSizeChanged( int, int );
     void setVideoFullScreen( bool );
+    void setHideMouse( bool );
     void setVideoOnTop( bool );
     void setBoss();
     void setRaise();
@@ -265,10 +266,11 @@ private slots:
 
 signals:
     void askGetVideo( WId *, struct vout_window_t *, unsigned *, unsigned *,
-                      bool );
+                      bool, bool );
     void askReleaseVideo( );
     void askVideoToResize( unsigned int, unsigned int );
     void askVideoSetFullScreen( bool );
+    void askHideMouse( bool );
     void askVideoOnTop( bool );
     void minimalViewToggled( bool );
     void fullscreenInterfaceToggled( bool );
diff --git a/modules/gui/qt/qt.cpp b/modules/gui/qt/qt.cpp
index 3af00c0..d0c614a 100644
--- a/modules/gui/qt/qt.cpp
+++ b/modules/gui/qt/qt.cpp
@@ -735,8 +735,15 @@ static int WindowOpen( vout_window_t *p_wnd, const vout_window_cfg_t *cfg )
 
     unsigned i_width = cfg->width;
     unsigned i_height = cfg->height;
+#ifndef _WIN32
+    const bool b_mouse_support = var_InheritBool( p_wnd, "mouse-events" );
+#else
+    /* FIXME: rework win32/events.c to dispatch events to QT */
+    const bool b_mouse_support = false;
+#endif
 
-    WId wid = p_mi->getVideo( p_wnd, &i_width, &i_height, cfg->is_fullscreen );
+    WId wid = p_mi->getVideo( p_wnd, &i_width, &i_height, cfg->is_fullscreen,
+                              b_mouse_support );
     if( !wid )
         return VLC_EGENERIC;
 



More information about the vlc-commits mailing list