Commit 30dc6027 authored by Thomas Guillem's avatar Thomas Guillem

qt: handle window mouse events

Ref #9787
parent 34821277
......@@ -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" );
......
......@@ -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 );
......
......@@ -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;
......
......@@ -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 );
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment