Commit 48018aed authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Video Widget cleaning. Corrections of previous commits.

zoom and resize when stop should be fixed. #1652 and #1716
parent ac495caa
...@@ -67,16 +67,23 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i ) ...@@ -67,16 +67,23 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
{ {
/* Init */ /* Init */
i_vout = 0; i_vout = 0;
hide(); setMinimumSize( 16, 16 );
videoSize.rwidth() = -1; videoSize.rwidth() = -1;
videoSize.rheight() = -1; videoSize.rheight() = -1;
hide();
/* Set the policy to expand in both directions */
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
/* Black background is more coherent for a Video Widget IMVHO */ /* Black background is more coherent for a Video Widget */
QPalette plt = palette(); QPalette plt = palette();
plt.setColor( QPalette::Active, QPalette::Window , Qt::black ); plt.setColor( QPalette::Window, Qt::black );
plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
setPalette( plt ); setPalette( plt );
setAutoFillBackground(true);
/* Indicates that the widget wants to draw directly onto the screen.
Widgets with this attribute set do not participate in composition
management */
setAttribute( Qt::WA_PaintOnScreen, true ); setAttribute( Qt::WA_PaintOnScreen, true );
/* The core can ask through a callback to show the video. */ /* The core can ask through a callback to show the video. */
...@@ -85,7 +92,7 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i ) ...@@ -85,7 +92,7 @@ VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
this, SLOT(SetSizing(unsigned int, unsigned int )), this, SLOT(SetSizing(unsigned int, unsigned int )),
Qt::BlockingQueuedConnection ); Qt::BlockingQueuedConnection );
#else #else
#error This is broken. Fix it with a QEventLoop with a processEvents () #warning This is broken. Fix it with a QEventLoop with a processEvents ()
connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)), connect( this, SIGNAL(askVideoWidgetToShow( unsigned int, unsigned int)),
this, SLOT(SetSizing(unsigned int, unsigned int )) ); this, SLOT(SetSizing(unsigned int, unsigned int )) );
#endif #endif
...@@ -99,10 +106,11 @@ void VideoWidget::paintEvent(QPaintEvent *ev) ...@@ -99,10 +106,11 @@ void VideoWidget::paintEvent(QPaintEvent *ev)
#endif #endif
} }
/* Kill the vout at Destruction */
VideoWidget::~VideoWidget() VideoWidget::~VideoWidget()
{ {
vout_thread_t *p_vout = i_vout vout_thread_t *p_vout = i_vout ?
? (vout_thread_t *)vlc_object_get( i_vout ) : NULL; (vout_thread_t *)vlc_object_get( i_vout ) : NULL;
if( p_vout ) if( p_vout )
{ {
...@@ -134,7 +142,9 @@ void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y, ...@@ -134,7 +142,9 @@ void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
return NULL; return NULL;
} }
i_vout = p_nvout->i_object_id; i_vout = p_nvout->i_object_id;
#ifndef NDEBUG
msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() ); msg_Dbg( p_intf, "embedded video ready (handle %p)", winId() );
#endif
return ( void* )winId(); return ( void* )winId();
} }
...@@ -156,8 +166,8 @@ void VideoWidget::release( void *p_win ) ...@@ -156,8 +166,8 @@ void VideoWidget::release( void *p_win )
i_vout = 0; i_vout = 0;
videoSize.rwidth() = 0; videoSize.rwidth() = 0;
videoSize.rheight() = 0; videoSize.rheight() = 0;
updateGeometry();
hide(); hide();
updateGeometry(); // Needed for deinterlace
} }
QSize VideoWidget::sizeHint() const QSize VideoWidget::sizeHint() const
......
...@@ -41,26 +41,6 @@ ...@@ -41,26 +41,6 @@
#include <QWidget> #include <QWidget>
#include <QFrame> #include <QFrame>
#define VOLUME_MAX 200
/* on WIN32 hide() for fullscreen controller doesnt work, so it have to be
done by trick with setting the opacity of window */
#ifdef WIN32
#define WIN32TRICK
#endif
/* to trying transparency with fullscreen controller on windows enable that */
/* it can be enabled on-non windows systems,
but it will be transparent only with composite manager */
#ifndef WIN32
#define HAVE_TRANSPARENCY 1
#else
#define HAVE_TRANSPARENCY 0
#endif
/* Default value of opacity for FS controller */
#define DEFAULT_OPACITY 0.75
class ResizeEvent; class ResizeEvent;
class QPalette; class QPalette;
class QPixmap; class QPixmap;
...@@ -240,6 +220,24 @@ signals: ...@@ -240,6 +220,24 @@ signals:
void advancedControlsToggled( bool ); void advancedControlsToggled( bool );
}; };
/* on WIN32 hide() for fullscreen controller doesnt work, so it have to be
done by trick with setting the opacity of window */
#ifdef WIN32
#define WIN32TRICK
#endif
/* to trying transparency with fullscreen controller on windows enable that */
/* it can be enabled on-non windows systems,
but it will be transparent only with composite manager */
#ifndef WIN32
#define HAVE_TRANSPARENCY 1
#else
#define HAVE_TRANSPARENCY 0
#endif
/* Default value of opacity for FS controller */
#define DEFAULT_OPACITY 0.75
/*********************************** /***********************************
* Fullscreen controller * Fullscreen controller
***********************************/ ***********************************/
...@@ -302,7 +300,7 @@ private: ...@@ -302,7 +300,7 @@ private:
}; };
#define VOLUME_MAX 200
class VolumeClickHandler : public QObject class VolumeClickHandler : public QObject
{ {
public: public:
......
/***************************************************************************** /*****************************************************************************
* main_interface.cpp : Main interface * main_interface.cpp : Main interface
**************************************************************************** ****************************************************************************
* Copyright (C) 2006-2007 the VideoLAN team * Copyright (C) 2006-2008 the VideoLAN team
* $Id$ * $Id$
* *
* Authors: Clément Stenac <zorglub@videolan.org> * Authors: Clément Stenac <zorglub@videolan.org>
...@@ -51,9 +51,6 @@ ...@@ -51,9 +51,6 @@
#include <QLabel> #include <QLabel>
#include <QSlider> #include <QSlider>
#include <QWidgetAction> #include <QWidgetAction>
#if 0
#include <QDockWidget>
#endif
#include <QToolBar> #include <QToolBar>
#include <QGroupBox> #include <QGroupBox>
#include <QDate> #include <QDate>
...@@ -62,12 +59,6 @@ ...@@ -62,12 +59,6 @@
#include <vlc_keys.h> #include <vlc_keys.h>
#include <vlc_vout.h> #include <vlc_vout.h>
#define SET_WIDTH(i,j) i->widgetSize.setWidth(j)
#define SET_HEIGHT(i,j) i->widgetSize.setHeight(j)
#define SET_WH( i,j,k) i->widgetSize.setWidth(j); i->widgetSize.setHeight(k);
#define DS(i) i.width(),i.height()
/* Callback prototypes */ /* Callback prototypes */
static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable, static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
vlc_value_t old_val, vlc_value_t new_val, void *param ); vlc_value_t old_val, vlc_value_t new_val, void *param );
...@@ -112,8 +103,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -112,8 +103,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
settings = getSettings(); settings = getSettings();
settings->beginGroup( "MainWindow" ); settings->beginGroup( "MainWindow" );
//TODO: I don't like that code /* Visualisation, not really used yet */
visualSelectorEnabled = settings->value( "visual-selector", false ).toBool(); visualSelectorEnabled = settings->value( "visual-selector", false).toBool();
/* Do we want anoying popups or not */
notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" ); notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
/************************** /**************************
...@@ -134,11 +127,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -134,11 +127,10 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
dockPL->hide(); dockPL->hide();
#endif #endif
/************ /**************************
* Menu Bar * Menu Bar and Status Bar
************/ **************************/
QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled ); QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
/* StatusBar Creation */ /* StatusBar Creation */
createStatusBar(); createStatusBar();
...@@ -197,13 +189,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -197,13 +189,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
/** OnTimeOut **/ /** OnTimeOut **/
/* TODO Remove this function, but so far, there is no choice because there /* TODO Remove this function, but so far, there is no choice because there
is no intf-should-die variable */ is no intf-should-die variable #1365 */
ON_TIMEOUT( updateOnTimer() ); ON_TIMEOUT( updateOnTimer() );
//ON_TIMEOUT( debug() );
/** /************
* Callbacks * Callbacks
**/ ************/
var_Create( p_intf, "interaction", VLC_VAR_ADDRESS ); var_Create( p_intf, "interaction", VLC_VAR_ADDRESS );
var_AddCallback( p_intf, "interaction", InteractCallback, this ); var_AddCallback( p_intf, "interaction", InteractCallback, this );
p_intf->b_interaction = true; p_intf->b_interaction = true;
...@@ -213,7 +204,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -213,7 +204,8 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
/* Register callback for the intf-popupmenu variable */ /* Register callback for the intf-popupmenu variable */
var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf ); var_AddCallback( p_intf->p_libvlc, "intf-popupmenu", PopupMenuCB, p_intf );
/* VideoWidget connect mess to avoid different threads speaking to each other */
/* VideoWidget connects to avoid different threads speaking to each other */
CONNECT( this, askReleaseVideo( void * ), CONNECT( this, askReleaseVideo( void * ),
this, releaseVideoSlot( void * ) ); this, releaseVideoSlot( void * ) );
if( videoWidget ) if( videoWidget )
...@@ -230,14 +222,20 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -230,14 +222,20 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
if( settings->value( "playlist-visible", 0 ).toInt() ) togglePlaylist(); if( settings->value( "playlist-visible", 0 ).toInt() ) togglePlaylist();
settings->endGroup(); settings->endGroup();
/* Final sizing and showing */
setMinimumWidth( __MAX( controls->sizeHint().width(),
menuBar()->sizeHint().width() ) );
show(); show();
/* And switch to minimal view if needed
Must be called after the show() */
if( i_visualmode == QT_MINIMAL_MODE ) if( i_visualmode == QT_MINIMAL_MODE )
toggleMinimalView(); toggleMinimalView();
/* Update the geometry TODO: is it useful ?*/ /* Update the geometry TODO: is it useful ?*/
updateGeometry(); updateGeometry();
resize( sizeHint() ); // resize( sizeHint() );
/***************************************************** /*****************************************************
* End everything by creating the Systray Management * * End everything by creating the Systray Management *
...@@ -306,7 +304,6 @@ inline void MainInterface::createStatusBar() ...@@ -306,7 +304,6 @@ inline void MainInterface::createStatusBar()
speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel ); speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel); nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
/* and adding those */ /* and adding those */
statusBar()->addWidget( nameLabel, 8 ); statusBar()->addWidget( nameLabel, 8 );
statusBar()->addPermanentWidget( speedLabel, 0 ); statusBar()->addPermanentWidget( speedLabel, 0 );
...@@ -544,60 +541,34 @@ int MainInterface::privacyDialog( QList<ConfigControl *> *controls ) ...@@ -544,60 +541,34 @@ int MainInterface::privacyDialog( QList<ConfigControl *> *controls )
QSize MainInterface::sizeHint() const QSize MainInterface::sizeHint() const
{ {
int nwidth = __MAX( controls->sizeHint().width(), int nwidth = controls->sizeHint().width();
menuBar()->sizeHint().width() );
int nheight = controls->isVisible() ? int nheight = controls->isVisible() ?
controls->size().height() controls->size().height()
+ menuBar()->size().height() + menuBar()->size().height()
+ statusBar()->size().height() + statusBar()->size().height()
: 0 ; : 0 ;
msg_Dbg( p_intf, "1 %i %i", nheight, nwidth );
if( VISIBLE( bgWidget ) ) if( VISIBLE( bgWidget ) )
{ {
nheight += bgWidget->size().height(); nheight += bgWidget->size().height();
nwidth = bgWidget->size().width(); nwidth = bgWidget->size().width();
msg_Dbg( p_intf, "1b %i %i", nheight, nwidth );
} }
else if( videoIsActive ) else if( videoIsActive && videoWidget->isVisible() )
{ {
nheight += videoWidget->sizeHint().height(); nheight += videoWidget->sizeHint().height();
nwidth = videoWidget->sizeHint().width(); nwidth = videoWidget->sizeHint().width();
msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
} }
#if 0 #if 0
if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() ) if( !dockPL->isFloating() && dockPL->isVisible() && dockPL->widget() )
{ {
nheight += dockPL->size().height(); nheight += dockPL->size().height();
nwidth = __MAX( nwidth, dockPL->size().width() ); nwidth = __MAX( nwidth, dockPL->size().width() );
msg_Dbg( p_intf, "3 %i %i", nheight, nwidth ); msg_Warn( p_intf, "3 %i %i", nheight, nwidth );
} }
#endif #endif
msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
return QSize( nwidth, nheight ); return QSize( nwidth, nheight );
} }
#if 0
/* FIXME This is dead code and need to be removed AT THE END */
void MainInterface::resizeEvent( QResizeEvent *e )
{
if( videoWidget )
videoWidget->widgetSize.setWidth( e->size().width() - addSize.width() );
if( videoWidget && videoIsActive && videoWidget->widgetSize.height() > 1 )
{
SET_WH( videoWidget, e->size().width() - addSize.width(),
e->size().height() - addSize.height() );
videoWidget->updateGeometry();
}
if( VISIBLE( playlistWidget ) )
{
// SET_WH( playlistWidget , e->size().width() - addSize.width(),
// e->size().height() - addSize.height() );
playlistWidget->updateGeometry();
}
}
#endif
void MainInterface::toggleFSC() void MainInterface::toggleFSC()
{ {
if( !fullscreenControls ) return; if( !fullscreenControls ) return;
...@@ -605,25 +576,22 @@ void MainInterface::toggleFSC() ...@@ -605,25 +576,22 @@ void MainInterface::toggleFSC()
IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 ); IMEvent *eShow = new IMEvent( FullscreenControlToggle_Type, 0 );
QApplication::postEvent( fullscreenControls, static_cast<QEvent *>(eShow) ); QApplication::postEvent( fullscreenControls, static_cast<QEvent *>(eShow) );
} }
#if 0
void MainInterface::requestLayoutUpdate()
{
emit askUpdate();
}
#endif
//FIXME remove me at the end... //FIXME remove me at the end...
void MainInterface::debug() void MainInterface::debug()
{ {
#ifndef NDEBUG
msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() ); msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() ); msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
if( videoWidget && videoWidget->isVisible() ) if( videoWidget && videoWidget->isVisible() )
{ {
// sleep( 10 ); // sleep( 10 );
msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() ); msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() ); msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
} }
adjustSize(); adjustSize();
#endif
} }
/**************************************************************************** /****************************************************************************
...@@ -638,6 +606,9 @@ void MainInterface::showSpeedMenu( QPoint pos ) ...@@ -638,6 +606,9 @@ void MainInterface::showSpeedMenu( QPoint pos )
/**************************************************************************** /****************************************************************************
* Video Handling * Video Handling
****************************************************************************/ ****************************************************************************/
/* This event is used to deal with the fullscreen and always on top
issue conflict (bug in wx) */
class SetVideoOnTopQtEvent : public QEvent class SetVideoOnTopQtEvent : public QEvent
{ {
public: public:
...@@ -645,17 +616,13 @@ public: ...@@ -645,17 +616,13 @@ public:
QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop) QEvent( (QEvent::Type)SetVideoOnTopEvent_Type ), onTop( _onTop)
{} {}
bool OnTop() const bool OnTop() const { return onTop; }
{
return onTop;
}
private: private:
bool onTop; bool onTop;
}; };
/** /**
* README
* README * README
* Thou shall not call/resize/hide widgets from on another thread. * Thou shall not call/resize/hide widgets from on another thread.
* This is wrong, and this is TEH reason to emit signals on those Video Functions * This is wrong, and this is TEH reason to emit signals on those Video Functions
...@@ -664,8 +631,6 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x, ...@@ -664,8 +631,6 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
int *pi_y, unsigned int *pi_width, int *pi_y, unsigned int *pi_width,
unsigned int *pi_height ) unsigned int *pi_height )
{ {
bgWasVisible = false;
/* Request the videoWidget */ /* Request the videoWidget */
void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height ); void *ret = videoWidget->request( p_nvout,pi_x, pi_y, pi_width, pi_height );
if( ret ) /* The videoWidget is available */ if( ret ) /* The videoWidget is available */
...@@ -676,22 +641,12 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x, ...@@ -676,22 +641,12 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
bgWasVisible = true; bgWasVisible = true;
emit askBgWidgetToToggle(); emit askBgWidgetToToggle();
} }
#if 0 else
if( THEMIM->getIM()->hasVideo() || !bgWasVisible ) bgWasVisible = false;
{
videoWidget->widgetSize = QSize( *pi_width, *pi_height ); /* Consider the video active now */
}
else /* Background widget available, use its size */
{
/* Ok, our visualizations are bad, so don't do this for the moment
* use the requested size anyway */
// videoWidget->widgetSize = bgWidget->widgeTSize;
videoWidget->widgetSize = QSize( *pi_width, *pi_height );
}
#endif
videoIsActive = true; videoIsActive = true;
// emit askVideoToResize( *pi_width, *pi_height );
emit askUpdate(); emit askUpdate();
if( fullscreenControls ) fullscreenControls->attachVout( p_nvout ); if( fullscreenControls ) fullscreenControls->attachVout( p_nvout );
...@@ -699,6 +654,7 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x, ...@@ -699,6 +654,7 @@ void *MainInterface::requestVideo( vout_thread_t *p_nvout, int *pi_x,
return ret; return ret;
} }
/* Call from the WindowClose function */
void MainInterface::releaseVideo( void *p_win ) void MainInterface::releaseVideo( void *p_win )
{ {
if( fullscreenControls ) fullscreenControls->detachVout(); if( fullscreenControls ) fullscreenControls->detachVout();
...@@ -706,21 +662,23 @@ void MainInterface::releaseVideo( void *p_win ) ...@@ -706,21 +662,23 @@ void MainInterface::releaseVideo( void *p_win )
emit askReleaseVideo( p_win ); emit askReleaseVideo( p_win );
} }
/* Function that is CONNECTED to the previous emit */
void MainInterface::releaseVideoSlot( void *p_win ) void MainInterface::releaseVideoSlot( void *p_win )
{ {
videoWidget->release( p_win ); videoWidget->release( p_win );
videoWidget->hide();
if( bgWasVisible ) if( bgWasVisible )
{ {
/* Reset the bg state */
bgWasVisible = false; bgWasVisible = false;
bgWidget->show(); bgWidget->show();
} }
videoIsActive = false; /* Try to resize, except when you are in Fullscreen mode */
if( !isFullScreen() ) adjustSize(); if( !isFullScreen() ) doComponentsUpdate();
} }
/* Call from WindowControl function */
int MainInterface::controlVideo( void *p_window, int i_query, va_list args ) int MainInterface::controlVideo( void *p_window, int i_query, va_list args )
{ {
int i_ret = VLC_SUCCESS; int i_ret = VLC_SUCCESS;
...@@ -825,7 +783,7 @@ void MainInterface::toggleMinimalView() ...@@ -825,7 +783,7 @@ void MainInterface::toggleMinimalView()
else else
{ {
/* If video is visible, then toggle the status of bgWidget */ /* If video is visible, then toggle the status of bgWidget */
bgWasVisible = !bgWasVisible; bgWasVisible = !bgWasVisible;
} }
} }
...@@ -840,8 +798,8 @@ void MainInterface::toggleMinimalView() ...@