[vlc-commits] qt: handle video widget cursor automatically (refs #18661)

Rémi Denis-Courmont git at videolan.org
Sun May 20 19:51:29 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri May 18 18:16:27 2018 +0300| [d278550e77913aa9a9dfd48be52b061a418320c8] | committer: Rémi Denis-Courmont

qt: handle video widget cursor automatically (refs #18661)

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

 modules/gui/qt/components/interface_widgets.cpp | 21 +++++++++++++++++++++
 modules/gui/qt/components/interface_widgets.hpp |  7 +++++++
 modules/gui/qt/main_interface.cpp               | 14 --------------
 modules/gui/qt/main_interface.hpp               |  2 --
 4 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/modules/gui/qt/components/interface_widgets.cpp b/modules/gui/qt/components/interface_widgets.cpp
index 78dbc2f9c3..dc4f45188a 100644
--- a/modules/gui/qt/components/interface_widgets.cpp
+++ b/modules/gui/qt/components/interface_widgets.cpp
@@ -88,6 +88,12 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i, QWidget* p_parent )
     layout->setContentsMargins( 0, 0, 0, 0 );
     stable = NULL;
     p_window = NULL;
+
+    cursorTimer = new QTimer( this );
+    cursorTimer->setSingleShot( true );
+    connect( cursorTimer, SIGNAL(timeout()), this, SLOT(hideCursor()) );
+    cursorTimeout = var_InheritInteger( _p_i, "mouse-hide-timeout" );
+
     show();
 }
 
@@ -297,6 +303,17 @@ void VideoWidget::resizeEvent( QResizeEvent *event )
     reportSize();
 }
 
+void VideoWidget::hideCursor()
+{
+    setCursor( Qt::BlankCursor );
+}
+
+void VideoWidget::showCursor()
+{
+    setCursor( Qt::ArrowCursor );
+    cursorTimer->start( cursorTimeout );
+}
+
 int VideoWidget::qtMouseButton2VLC( Qt::MouseButton qtButton )
 {
     if( p_window == NULL )
@@ -320,6 +337,7 @@ void VideoWidget::mouseReleaseEvent( QMouseEvent *event )
     if( vlc_button >= 0 )
     {
         vout_window_ReportMouseReleased( p_window, vlc_button );
+        showCursor();
         event->accept();
     }
     else
@@ -332,6 +350,7 @@ void VideoWidget::mousePressEvent( QMouseEvent* event )
     if( vlc_button >= 0 )
     {
         vout_window_ReportMousePressed( p_window, vlc_button );
+        showCursor();
         event->accept();
     }
     else
@@ -350,6 +369,7 @@ void VideoWidget::mouseMoveEvent( QMouseEvent *event )
         current_pos *= devicePixelRatio();
 #endif
         vout_window_ReportMouseMoved( p_window, current_pos.x(), current_pos.y() );
+        showCursor();
         event->accept();
     }
     else
@@ -362,6 +382,7 @@ void VideoWidget::mouseDoubleClickEvent( QMouseEvent *event )
     if( vlc_button >= 0 )
     {
         vout_window_ReportMouseDoubleClick( p_window, vlc_button );
+        showCursor();
         event->accept();
     }
     else
diff --git a/modules/gui/qt/components/interface_widgets.hpp b/modules/gui/qt/components/interface_widgets.hpp
index 772a6b7232..232ffe3e91 100644
--- a/modules/gui/qt/components/interface_widgets.hpp
+++ b/modules/gui/qt/components/interface_widgets.hpp
@@ -47,6 +47,7 @@
 
 class QMenu;
 class QSlider;
+class QTimer;
 class QWidgetAction;
 class SpeedControlWidget;
 struct vout_window_t;
@@ -84,14 +85,20 @@ private:
 
     QWidget *stable;
     QLayout *layout;
+    QTimer *cursorTimer;
+    int cursorTimeout;
 
     void reportSize();
+    void showCursor();
 
 signals:
     void sizeChanged( int, int );
 
 public slots:
     void setSize( unsigned int, unsigned int );
+
+private slots:
+    void hideCursor();
 };
 
 /******************** Background Widget ****************/
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index 6e2e4b9d38..1b005a7690 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -222,8 +222,6 @@ 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() );
@@ -930,11 +928,6 @@ 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 )
@@ -1000,13 +993,6 @@ 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 2fcf2d36e7..1094c24406 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -262,7 +262,6 @@ protected slots:
     void setVideoSize( unsigned int, unsigned int );
     void videoSizeChanged( int, int );
     virtual void setVideoFullScreen( bool );
-    void setHideMouse( bool );
     void setVideoOnTop( bool );
     void setBoss();
     void setRaise();
@@ -279,7 +278,6 @@ signals:
     void askReleaseVideo( );
     void askVideoToResize( unsigned int, unsigned int );
     void askVideoSetFullScreen( bool );
-    void askHideMouse( bool );
     void askVideoOnTop( bool );
     void minimalViewToggled( bool );
     void fullscreenInterfaceToggled( bool );



More information about the vlc-commits mailing list