Commit 50810ad7 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt4 - Resizing changes. Part 1

      Remove the QDockWidget, this widget is clearly not what we want, since it is a Qt::Tool and stay above the video, it doesn't want to grow in the MI and it doesn't record correctly its size. Moreover, this force the GNOME/Cleanlooks hack that is boring on Xfce, KDE4 and e17.
      Fix the resize when the video is done.
      Fix the qt-start-minimize bug
      Rename a few functions and separate the code functions.
      Simplify a few resize/update call.
parent 7e6486a9
...@@ -58,13 +58,23 @@ static int DoControl( intf_thread_t *, void *, int, va_list ); ...@@ -58,13 +58,23 @@ static int DoControl( intf_thread_t *, void *, int, va_list );
VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i ) VideoWidget::VideoWidget( intf_thread_t *_p_i ) : QFrame( NULL ), p_intf( _p_i )
{ {
/* Init */
vlc_mutex_init( p_intf, &lock ); vlc_mutex_init( p_intf, &lock );
p_vout = NULL; p_vout = NULL;
hide(); setMinimumSize( 16, 16 ); hide(); setMinimumSize( 16, 16 );
videoSize.rwidth() = -1;
videoSize.rheight() = -1;
// CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) ); /* Black background is more coherent for a Video Widget IMVHO */
QPalette plt = palette();
plt.setColor( QPalette::Active, QPalette::Window , Qt::black );
plt.setColor( QPalette::Inactive, QPalette::Window , Qt::black );
setPalette( plt );
/* The core can ask through a callback to show the video */
CONNECT( this, askVideoWidgetToShow(), this, show() ); CONNECT( this, askVideoWidgetToShow(), this, show() );
setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); /* The core can ask through a callback to resize the video */
// CONNECT( this, askResize( int, int ), this, SetSizing( int, int ) );
} }
VideoWidget::~VideoWidget() VideoWidget::~VideoWidget()
...@@ -88,11 +98,12 @@ VideoWidget::~VideoWidget() ...@@ -88,11 +98,12 @@ VideoWidget::~VideoWidget()
} }
/** /**
* Request the video to avoid the conflicts * Request the video to avoid the conflicts
**/ **/
void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y, void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
unsigned int *pi_width, unsigned int *pi_height ) unsigned int *pi_width, unsigned int *pi_height )
{ {
msg_Dbg( p_intf, "Video was requested %i, %i", *pi_x, *pi_y );
emit askVideoWidgetToShow(); emit askVideoWidgetToShow();
if( p_vout ) if( p_vout )
{ {
...@@ -104,19 +115,30 @@ void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y, ...@@ -104,19 +115,30 @@ void *VideoWidget::request( vout_thread_t *p_nvout, int *pi_x, int *pi_y,
} }
/* Set the Widget to the correct Size */ /* Set the Widget to the correct Size */
/* Function has to be called by the parent
Parent has to care about resizing himself*/
void VideoWidget::SetSizing( unsigned int w, unsigned int h ) void VideoWidget::SetSizing( unsigned int w, unsigned int h )
{ {
resize( w, h ); msg_Dbg( p_intf, "Video is resizing to: %i %i", w, h );
//updateGeometry(); // Needed for deinterlace videoSize.rwidth() = w;
msg_Dbg( p_intf, "%i %i", sizeHint().height(), sizeHint().width() ); videoSize.rheight() = h;
//emit askResize(); updateGeometry(); // Needed for deinterlace
} }
void VideoWidget::release( void *p_win ) void VideoWidget::release( void *p_win )
{ {
msg_Dbg( p_intf, "Video is non needed anymore" );
p_vout = NULL; p_vout = NULL;
videoSize.rwidth() = 0;
videoSize.rheight() = 0;
hide();
updateGeometry(); // Needed for deinterlace
} }
QSize VideoWidget::sizeHint() const
{
return videoSize;
}
/********************************************************************** /**********************************************************************
* Background Widget. Show a simple image background. Currently, * Background Widget. Show a simple image background. Currently,
......
...@@ -32,9 +32,10 @@ ...@@ -32,9 +32,10 @@
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc_interface.h> #include <vlc_interface.h>
#include <vlc_aout.h> #include <vlc_aout.h>
#include "qt4.hpp" #include "qt4.hpp"
#include "main_interface.hpp"
#include <QWidget> #include <QWidget>
#include <QFrame> #include <QFrame>
...@@ -50,6 +51,8 @@ class QHBoxLayout; ...@@ -50,6 +51,8 @@ class QHBoxLayout;
class VideoWidget : public QFrame class VideoWidget : public QFrame
{ {
Q_OBJECT Q_OBJECT
friend class MainInterface;
public: public:
VideoWidget( intf_thread_t * ); VideoWidget( intf_thread_t * );
virtual ~VideoWidget(); virtual ~VideoWidget();
...@@ -59,11 +62,13 @@ public: ...@@ -59,11 +62,13 @@ public:
void release( void * ); void release( void * );
int control( void *, int, va_list ); int control( void *, int, va_list );
virtual QSize sizeHint() const;
private: private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
vout_thread_t *p_vout; vout_thread_t *p_vout;
vlc_mutex_t lock; vlc_mutex_t lock;
QSize videoSize;
signals: signals:
void askVideoWidgetToShow(); void askVideoWidgetToShow();
......
...@@ -93,21 +93,21 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -93,21 +93,21 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
{ {
/* Variables initialisation */ /* Variables initialisation */
// need_components_update = false; // need_components_update = false;
bgWidget = NULL; videoWidget = NULL; playlistWidget = NULL; bgWidget = NULL;
videoWidget = NULL;
playlistWidget = NULL;
sysTray = NULL;
videoIsActive = false; videoIsActive = false;
input_name = "";
playlistVisible = false; playlistVisible = false;
input_name = "";
/* Ask for privacy */ /* Ask for privacy */
privacy(); askForPrivacy();
/** /**
* Configuration and settings * Configuration and settings
* Pre-building of interface * Pre-building of interface
**/ **/
settings = new QSettings( "vlc", "vlc-qt-interface" );
settings->beginGroup( "MainWindow" );
/* Main settings */ /* Main settings */
setFocusPolicy( Qt::StrongFocus ); setFocusPolicy( Qt::StrongFocus );
setAcceptDrops( true ); setAcceptDrops( true );
...@@ -121,10 +121,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -121,10 +121,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
i_visualmode = config_GetInt( p_intf, "qt-display-mode" ); i_visualmode = config_GetInt( p_intf, "qt-display-mode" );
/* Set the other interface settings */ /* Set the other interface settings */
settings = new QSettings( "vlc", "vlc-qt-interface" );
settings->beginGroup( "MainWindow" );
//TODO: I don't like that code //TODO: I don't like that code
visualSelectorEnabled = settings->value( "visual-selector", false ).toBool(); visualSelectorEnabled = settings->value( "visual-selector", false ).toBool();
notificationEnabled = config_GetInt( p_intf, "qt-notification" ) notificationEnabled = (bool)config_GetInt( p_intf, "qt-notification" );
? true : false;
/************************** /**************************
* UI and Widgets design * UI and Widgets design
...@@ -132,83 +134,26 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -132,83 +134,26 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
setVLCWindowsTitle(); setVLCWindowsTitle();
handleMainUi( settings ); handleMainUi( settings );
#if 0
/* Create a Dock to get the playlist */ /* Create a Dock to get the playlist */
dockPL = new QDockWidget( qtr( "Playlist" ), this ); /* dockPL = new QDockWidget( qtr( "Playlist" ), this );
dockPL->setSizePolicy( QSizePolicy::Preferred, dockPL->setSizePolicy( QSizePolicy::Preferred,
QSizePolicy::Expanding ); QSizePolicy::Expanding );
dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures ); dockPL->setFeatures( QDockWidget::AllDockWidgetFeatures );
dockPL->setAllowedAreas( Qt::LeftDockWidgetArea dockPL->setAllowedAreas( Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea | Qt::RightDockWidgetArea
| Qt::BottomDockWidgetArea ); | Qt::BottomDockWidgetArea );
dockPL->hide(); dockPL->hide();*/
#endif
/************ /************
* Menu Bar * Menu Bar
************/ ************/
QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled ); QVLCMenu::createMenuBar( this, p_intf, visualSelectorEnabled );
/**************** /* StatusBar Creation */
* Status Bar * createStatusBar();
****************/
/* Widgets Creation*/
b_remainingTime = false;
timeLabel = new TimeLabel;
timeLabel->setText( " --:--/--:-- " );
timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
nameLabel = new QLabel;
nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
| Qt::TextSelectableByKeyboard );
speedLabel = new QLabel( "1.00x" );
speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
/* Styling those labels */
timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
pgBar = new QProgressBar;
pgBar->hide();
/* and adding those */
statusBar()->addWidget( nameLabel, 8 );
statusBar()->addPermanentWidget( speedLabel, 0 );
statusBar()->addPermanentWidget( pgBar, 0 );
statusBar()->addPermanentWidget( timeLabel, 0 );
/* timeLabel behaviour:
- double clicking opens the goto time dialog
- right-clicking and clicking just toggle between remaining and
elapsed time.*/
CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
/* Speed Label behaviour:
- right click gives the vertical speed slider */
CONNECT( speedLabel, customContextMenuRequested( QPoint ),
this, showSpeedMenu( QPoint ) );
/**********************
* Systray Management *
**********************/
sysTray = NULL;
bool b_createSystray = false;
bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
if( config_GetInt( p_intf, "qt-start-minimized") )
{
if( b_systrayAvailable )
{
b_createSystray = true;
hide(); //FIXME BUG HERE
}
else msg_Warn( p_intf, "You can't minize if you haven't a system "
"tray bar" );
}
if( config_GetInt( p_intf, "qt-system-tray") )
b_createSystray = true;
if( b_systrayAvailable && b_createSystray )
createSystray();
/******************** /********************
* Input Manager * * Input Manager *
...@@ -259,8 +204,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -259,8 +204,12 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
updateSystrayTooltipStatus( int ) ); updateSystrayTooltipStatus( int ) );
} }
/* END CONNECTS ON IM */
/** OnTimeOut **/ /** OnTimeOut **/
// TODO /* TODO Remove this function, but so far, there is no choice because there
is no intf-should-die variable */
ON_TIMEOUT( updateOnTimer() ); ON_TIMEOUT( updateOnTimer() );
//ON_TIMEOUT( debug() ); //ON_TIMEOUT( debug() );
...@@ -282,45 +231,41 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) ...@@ -282,45 +231,41 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf )
} }
/* VideoWidget connect mess to avoid different threads speaking to each other */ /* VideoWidget connect mess to avoid different threads speaking to each other */
CONNECT( this, askReleaseVideo( void * ), this, releaseVideoSlot( void * ) ); CONNECT( this, askReleaseVideo( void * ),
this, releaseVideoSlot( void * ) );
CONNECT( this, askVideoToResize( unsigned int, unsigned int ), CONNECT( this, askVideoToResize( unsigned int, unsigned int ),
videoWidget, SetSizing( unsigned int, unsigned int ) ); videoWidget, SetSizing( unsigned int, unsigned int ) );
CONNECT( this, askUpdate(), this, doComponentsUpdate() ); CONNECT( this, askUpdate(), this, doComponentsUpdate() );
CONNECT( dockPL, topLevelChanged( bool ), this, doComponentsUpdate() );
CONNECT( controls, advancedControlsToggled( bool ), CONNECT( controls, advancedControlsToggled( bool ),
this, doComponentsUpdate() ); this, doComponentsUpdate() );
/* Size and placement of interface */ /* Size and placement of interface */
move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() ); move( settings->value( "pos", QPoint( 0, 0 ) ).toPoint() );
QSize newSize = settings->value( "size", QSize( 350, 60 ) ).toSize(); QSize newSize = settings->value( "size", QSize( 350, 60 ) ).toSize();
if( newSize.isValid() ) if( newSize.isValid() )
{
resize( newSize ); resize( newSize );
}
else else
{
msg_Warn( p_intf, "Invalid size in constructor" ); msg_Warn( p_intf, "Invalid size in constructor" );
}
/* Playlist */ /* Playlist */
int tgPlay = settings->value( "playlist-visible", 0 ).toInt(); if( settings->value( "playlist-visible", 0 ).toInt() ) togglePlaylist();
settings->endGroup(); settings->endGroup();
if( tgPlay )
{
togglePlaylist();
}
show(); 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();
/*****************************************************
* End everything by creating the Systray Management *
*****************************************************/
initSystray();
} }
MainInterface::~MainInterface() MainInterface::~MainInterface()
...@@ -332,7 +277,7 @@ MainInterface::~MainInterface() ...@@ -332,7 +277,7 @@ MainInterface::~MainInterface()
ExtendedDialog::getInstance( p_intf )->savingSettings(); ExtendedDialog::getInstance( p_intf )->savingSettings();
settings->beginGroup( "MainWindow" ); settings->beginGroup( "MainWindow" );
settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) ); // settings->setValue( "playlist-floats", (int)(dockPL->isFloating()) );
settings->setValue( "playlist-visible", (int)playlistVisible ); settings->setValue( "playlist-visible", (int)playlistVisible );
settings->setValue( "adv-controls", settings->setValue( "adv-controls",
getControlsVisibilityStatus() & CONTROLS_ADVANCED ); getControlsVisibilityStatus() & CONTROLS_ADVANCED );
...@@ -367,6 +312,71 @@ MainInterface::~MainInterface() ...@@ -367,6 +312,71 @@ MainInterface::~MainInterface()
* Main UI handling * * Main UI handling *
*****************************/ *****************************/
inline void MainInterface::createStatusBar()
{
/****************
* Status Bar *
****************/
/* Widgets Creation*/
b_remainingTime = false;
timeLabel = new TimeLabel;
timeLabel->setText( " --:--/--:-- " );
timeLabel->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
nameLabel = new QLabel;
nameLabel->setTextInteractionFlags( Qt::TextSelectableByMouse
| Qt::TextSelectableByKeyboard );
speedLabel = new QLabel( "1.00x" );
speedLabel->setContextMenuPolicy ( Qt::CustomContextMenu );
/* Styling those labels */
timeLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
speedLabel->setFrameStyle( QFrame::Sunken | QFrame::Panel );
nameLabel->setFrameStyle( QFrame::Sunken | QFrame::StyledPanel);
pgBar = new QProgressBar;
pgBar->hide();
/* and adding those */
statusBar()->addWidget( nameLabel, 8 );
statusBar()->addPermanentWidget( speedLabel, 0 );
statusBar()->addPermanentWidget( pgBar, 0 );
statusBar()->addPermanentWidget( timeLabel, 0 );
/* timeLabel behaviour:
- double clicking opens the goto time dialog
- right-clicking and clicking just toggle between remaining and
elapsed time.*/
CONNECT( timeLabel, timeLabelClicked(), this, toggleTimeDisplay() );
CONNECT( timeLabel, timeLabelDoubleClicked(), THEDP, gotoTimeDialog() );
CONNECT( timeLabel, timeLabelDoubleClicked(), this, toggleTimeDisplay() );
/* Speed Label behaviour:
- right click gives the vertical speed slider */
CONNECT( speedLabel, customContextMenuRequested( QPoint ),
this, showSpeedMenu( QPoint ) );
}
inline void MainInterface::initSystray()
{
bool b_createSystray = false;
bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
if( config_GetInt( p_intf, "qt-start-minimized") )
{
if( b_systrayAvailable )
{
b_createSystray = true;
hide();
}
else msg_Err( p_intf, "You can't minimize if you haven't a system "
"tray bar" );
}
if( config_GetInt( p_intf, "qt-system-tray") )
b_createSystray = true;
if( b_systrayAvailable && b_createSystray )
createSystray();
}
/** /**
* Give the decorations of the Main Window a correct Name. * Give the decorations of the Main Window a correct Name.
* If nothing is given, set it to VLC... * If nothing is given, set it to VLC...
...@@ -392,7 +402,7 @@ void MainInterface::handleMainUi( QSettings *settings ) ...@@ -392,7 +402,7 @@ void MainInterface::handleMainUi( QSettings *settings )
/* Margins, spacing */ /* Margins, spacing */
main->setContentsMargins( 0, 0, 0, 0 ); main->setContentsMargins( 0, 0, 0, 0 );
// main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ); main->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum );
mainLayout->setMargin( 0 ); mainLayout->setMargin( 0 );
/* Create the CONTROLS Widget */ /* Create the CONTROLS Widget */
...@@ -443,10 +453,10 @@ void MainInterface::handleMainUi( QSettings *settings ) ...@@ -443,10 +453,10 @@ void MainInterface::handleMainUi( QSettings *settings )
} }
/* Finish the sizing */ /* Finish the sizing */
updateGeometry(); main->updateGeometry();
} }
inline void MainInterface::privacy() inline void MainInterface::askForPrivacy()
{ {
/** /**
* Ask for the network policy on FIRST STARTUP * Ask for the network policy on FIRST STARTUP
...@@ -535,12 +545,6 @@ int MainInterface::privacyDialog( QList<ConfigControl *> controls ) ...@@ -535,12 +545,6 @@ int MainInterface::privacyDialog( QList<ConfigControl *> controls )
return privacy->exec(); return privacy->exec();
} }
//FIXME remove me at the end...
void MainInterface::debug()
{
msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
}
/********************************************************************** /**********************************************************************
* Handling of sizing of the components * Handling of sizing of the components
...@@ -554,6 +558,7 @@ void MainInterface::debug() ...@@ -554,6 +558,7 @@ void MainInterface::debug()
ask _parent->isFloating()... ask _parent->isFloating()...
If you think this would be better, please FIXME it... If you think this would be better, please FIXME it...
*/ */
#if 0
QSize MainInterface::sizeHint() const QSize MainInterface::sizeHint() const
{ {
int nwidth = controls->sizeHint().width(); int nwidth = controls->sizeHint().width();
...@@ -576,16 +581,16 @@ QSize MainInterface::sizeHint() const ...@@ -576,16 +581,16 @@ QSize MainInterface::sizeHint() const
nwidth = videoWidget->size().width(); nwidth = videoWidget->size().width();
msg_Dbg( p_intf, "2 %i %i", nheight, nwidth ); msg_Dbg( p_intf, "2 %i %i", nheight, nwidth );
} }
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_Dbg( p_intf, "3 %i %i", nheight, nwidth );
} }*/
msg_Dbg( p_intf, "4 %i %i", nheight, nwidth ); msg_Dbg( p_intf, "4 %i %i", nheight, nwidth );
return QSize( nwidth, nheight ); return QSize( nwidth, nheight );
} }
#endif
#if 0 #if 0
/* FIXME This is dead code and need to be removed AT THE END */ /* FIXME This is dead code and need to be removed AT THE END */
void MainInterface::resizeEvent( QResizeEvent *e ) void MainInterface::resizeEvent( QResizeEvent *e )
...@@ -607,6 +612,25 @@ void MainInterface::resizeEvent( QResizeEvent *e ) ...@@ -607,6 +612,25 @@ void MainInterface::resizeEvent( QResizeEvent *e )
} }
#endif #endif
void MainInterface::requestLayoutUpdate()
{
emit askUpdate();
}
//FIXME remove me at the end...
void MainInterface::debug()
{
msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
if( videoWidget->isVisible() )
{
// sleep( 10 );
msg_Dbg( p_intf, "size: %i - %i", size().height(), size().width() );
msg_Dbg( p_intf, "sizeHint: %i - %i", sizeHint().height(), sizeHint().width() );
}
adjustSize();
}
/**************************************************************************** /****************************************************************************
* Small right-click menu for rate control * Small right-click menu for rate control
****************************************************************************/ ****************************************************************************/
...@@ -635,6 +659,12 @@ private: ...@@ -635,6 +659,12 @@ private:
bool onTop; bool onTop;
}; };
/**
* README
* README
* 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
**/
/* function called from ::DoRequest in order to show a nice VideoWidget /* function called from ::DoRequest in order to show a nice VideoWidget