Commit 0df9e699 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: main_interface: fix playlist widgets instances. (fix #6795)

PlaylistDialog::getInstance was duplicating the playlist widget
instanciated in main interface. This explains the empty playlist
bug of the popup dialogs replacing the current playlist by
parenting their menu using getInstance().
To avoid further mistakes, PlaylistWiget's constructor is now only
available to playlistdialog, which also manages the widget
through the different configurations (embedded or floating).
Dialog also now saves and restores geometry, which only happened
when the widget was on its side.
parent 88a69655
...@@ -52,7 +52,6 @@ class PlaylistWidget : public QWidget ...@@ -52,7 +52,6 @@ class PlaylistWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
PlaylistWidget( intf_thread_t *_p_i, QWidget * );
virtual ~PlaylistWidget(); virtual ~PlaylistWidget();
void forceHide(); void forceHide();
...@@ -72,12 +71,15 @@ private: ...@@ -72,12 +71,15 @@ private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
protected: protected:
PlaylistWidget( intf_thread_t *_p_i, QWidget * );
virtual void dropEvent( QDropEvent *); virtual void dropEvent( QDropEvent *);
virtual void dragEnterEvent( QDragEnterEvent * ); virtual void dragEnterEvent( QDragEnterEvent * );
virtual void closeEvent( QCloseEvent * ); virtual void closeEvent( QCloseEvent * );
private slots: private slots:
void changeView( const QModelIndex& index ); void changeView( const QModelIndex& index );
void clearPlaylist(); void clearPlaylist();
friend class PlaylistDialog;
}; };
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
......
...@@ -40,21 +40,43 @@ PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) ...@@ -40,21 +40,43 @@ PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf )
setWindowRole( "vlc-playlist" ); setWindowRole( "vlc-playlist" );
setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) ); setWindowOpacity( var_InheritFloat( p_intf, "qt-opacity" ) );
getSettings()->beginGroup("playlistdialog");
playlistWidget = new PlaylistWidget( p_intf, this ); playlistWidget = new PlaylistWidget( p_intf, this );
setCentralWidget( playlistWidget ); setCentralWidget( playlistWidget );
readSettings( getSettings(), QSize( 600,700 ) ); readSettings( "playlistdialog", QSize( 600,700 ) );
}
getSettings()->endGroup(); PlaylistWidget *PlaylistDialog::exportPlaylistWidget()
{
Q_ASSERT( playlistWidget );
PlaylistWidget *widget = playlistWidget;
layout()->removeWidget( playlistWidget );
playlistWidget = NULL;
return widget;
}
void PlaylistDialog::importPlaylistWidget( PlaylistWidget *widget )
{
Q_ASSERT( !playlistWidget );
playlistWidget = widget;
setCentralWidget( playlistWidget );
playlistWidget->show();
}
bool PlaylistDialog::hasPlaylistWidget()
{
return ( !! playlistWidget );
}
void PlaylistDialog::hideEvent( QHideEvent * event )
{
QWidget::hideEvent( event );
emit visibilityChanged( false );
} }
PlaylistDialog::~PlaylistDialog() PlaylistDialog::~PlaylistDialog()
{ {
getSettings()->beginGroup("playlistdialog"); writeSettings( "playlistdialog" );
writeSettings( getSettings() );
getSettings()->endGroup();
} }
void PlaylistDialog::dropEvent( QDropEvent *event ) void PlaylistDialog::dropEvent( QDropEvent *event )
......
...@@ -34,14 +34,22 @@ class QSignalMapper; ...@@ -34,14 +34,22 @@ class QSignalMapper;
class PLSelector; class PLSelector;
class PLPanel; class PLPanel;
class QSettings; class QSettings;
class QHideEvent;
class PlaylistDialog : public QVLCMW, public Singleton<PlaylistDialog> class PlaylistDialog : public QVLCMW, public Singleton<PlaylistDialog>
{ {
Q_OBJECT Q_OBJECT
private:
PlaylistWidget *playlistWidget; public:
PlaylistWidget *exportPlaylistWidget( );
void importPlaylistWidget( PlaylistWidget * );
bool hasPlaylistWidget();
protected:
virtual void hideEvent( QHideEvent * );
private: private:
PlaylistWidget *playlistWidget;
PlaylistDialog( intf_thread_t * ); PlaylistDialog( intf_thread_t * );
virtual ~PlaylistDialog(); virtual ~PlaylistDialog();
...@@ -51,6 +59,9 @@ private: ...@@ -51,6 +59,9 @@ private:
void dragLeaveEvent( QDragLeaveEvent * ); void dragLeaveEvent( QDragLeaveEvent * );
friend class Singleton<PlaylistDialog>; friend class Singleton<PlaylistDialog>;
signals:
void visibilityChanged( bool );
}; };
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "components/controller.hpp" // controllers #include "components/controller.hpp" // controllers
#include "components/playlist/playlist.hpp" // plWidget #include "components/playlist/playlist.hpp" // plWidget
#include "dialogs/firstrun.hpp" // First Run #include "dialogs/firstrun.hpp" // First Run
#include "dialogs/playlist.hpp" // PlaylistDialog
#include "menus.hpp" // Menu creation #include "menus.hpp" // Menu creation
#include "recents.hpp" // RecentItems when DnD #include "recents.hpp" // RecentItems when DnD
...@@ -284,8 +285,8 @@ MainInterface::~MainInterface() ...@@ -284,8 +285,8 @@ MainInterface::~MainInterface()
settings->beginGroup("MainWindow"); settings->beginGroup("MainWindow");
settings->setValue( "pl-dock-status", b_plDocked ); settings->setValue( "pl-dock-status", b_plDocked );
/* Save playlist state */ /* Save playlist state */
if( playlistWidget )
settings->setValue( "playlist-visible", playlistVisible ); settings->setValue( "playlist-visible", playlistVisible );
settings->setValue( "adv-controls", settings->setValue( "adv-controls",
...@@ -300,12 +301,6 @@ MainInterface::~MainInterface() ...@@ -300,12 +301,6 @@ MainInterface::~MainInterface()
/* Save this size */ /* Save this size */
QVLCTools::saveWidgetPosition(settings, this); QVLCTools::saveWidgetPosition(settings, this);
/* Save undocked playlist size */
if( playlistWidget && !isPlDocked() )
QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget );
delete playlistWidget;
delete statusBar(); delete statusBar();
/* Unregister callbacks */ /* Unregister callbacks */
...@@ -528,6 +523,7 @@ inline void MainInterface::restoreStackOldWidget() ...@@ -528,6 +523,7 @@ inline void MainInterface::restoreStackOldWidget()
inline void MainInterface::showTab( QWidget *widget ) inline void MainInterface::showTab( QWidget *widget )
{ {
if ( !widget ) widget = bgWidget; /* trying to restore a null oldwidget */
#ifdef DEBUG_INTF #ifdef DEBUG_INTF
if ( stackCentralOldWidget ) if ( stackCentralOldWidget )
msg_Dbg( p_intf, "Old stackCentralOldWidget %s at index %i", msg_Dbg( p_intf, "Old stackCentralOldWidget %s at index %i",
...@@ -804,36 +800,26 @@ int MainInterface::controlVideo( int i_query, va_list args ) ...@@ -804,36 +800,26 @@ int MainInterface::controlVideo( int i_query, va_list args )
**/ **/
void MainInterface::createPlaylist() void MainInterface::createPlaylist()
{ {
playlistWidget = new PlaylistWidget( p_intf, this ); PlaylistDialog *dialog = PlaylistDialog::getInstance( p_intf );
if( b_plDocked ) if( b_plDocked )
{ {
playlistWidget = dialog->exportPlaylistWidget();
stackCentralW->addWidget( playlistWidget ); stackCentralW->addWidget( playlistWidget );
stackWidgetsSizes[playlistWidget] = settings->value( "playlistSize", QSize( 600, 300 ) ).toSize(); stackWidgetsSizes[playlistWidget] = settings->value( "playlistSize", QSize( 600, 300 ) ).toSize();
} }
else CONNECT( dialog, visibilityChanged(bool), this, setPlaylistVisibility(bool) );
{
#ifdef WIN32
playlistWidget->setParent( NULL );
#endif
playlistWidget->setWindowFlags( Qt::Window );
/* This will restore the geometry but will not work for position,
because of parenting */
QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
playlistWidget, QSize( 600, 300 ) );
}
} }
void MainInterface::togglePlaylist() void MainInterface::togglePlaylist()
{ {
if( !playlistWidget ) if( !playlistWidget ) createPlaylist();
{
createPlaylist();
}
PlaylistDialog *dialog = PlaylistDialog::getInstance( p_intf );
if( b_plDocked ) if( b_plDocked )
{ {
if ( dialog->hasPlaylistWidget() )
playlistWidget = dialog->exportPlaylistWidget();
/* Playlist is not visible, show it */ /* Playlist is not visible, show it */
if( stackCentralW->currentWidget() != playlistWidget ) if( stackCentralW->currentWidget() != playlistWidget )
{ {
...@@ -849,12 +835,13 @@ void MainInterface::togglePlaylist() ...@@ -849,12 +835,13 @@ void MainInterface::togglePlaylist()
} }
else else
{ {
#ifdef WIN32
playlistWidget->setParent( NULL );
#endif
playlistWidget->setWindowFlags( Qt::Window );
playlistVisible = !playlistVisible; playlistVisible = !playlistVisible;
playlistWidget->setVisible( playlistVisible ); if ( ! dialog->hasPlaylistWidget() )
dialog->importPlaylistWidget( playlistWidget );
if ( playlistVisible )
dialog->show();
else
dialog->hide();
} }
debug(); debug();
} }
...@@ -862,35 +849,30 @@ void MainInterface::togglePlaylist() ...@@ -862,35 +849,30 @@ void MainInterface::togglePlaylist()
void MainInterface::dockPlaylist( bool p_docked ) void MainInterface::dockPlaylist( bool p_docked )
{ {
if( b_plDocked == p_docked ) return; if( b_plDocked == p_docked ) return;
/* some extra check */
if ( b_plDocked && !playlistWidget ) createPlaylist();
b_plDocked = p_docked; b_plDocked = p_docked;
PlaylistDialog *dialog = PlaylistDialog::getInstance( p_intf );
if( !playlistWidget ) return; /* Playlist wasn't created yet */
if( !p_docked ) /* Previously docked */ if( !p_docked ) /* Previously docked */
{ {
/* If playlist is invisible don't show it */ playlistVisible = playlistWidget->isVisible();
if( stackCentralW->currentWidget() != playlistWidget ) return;
stackCentralW->removeWidget( playlistWidget ); stackCentralW->removeWidget( playlistWidget );
#ifdef WIN32 dialog->importPlaylistWidget( playlistWidget );
playlistWidget->setParent( NULL ); if ( playlistVisible ) dialog->show();
#endif
playlistWidget->setWindowFlags( Qt::Window );
QVLCTools::restoreWidgetPosition( p_intf, "Playlist",
playlistWidget, QSize( 600, 300 ) );
playlistWidget->show();
restoreStackOldWidget(); restoreStackOldWidget();
} }
else /* Previously undocked */ else /* Previously undocked */
{ {
QVLCTools::saveWidgetPosition( p_intf, "Playlist", playlistWidget ); playlistVisible = dialog->isVisible();
playlistWidget->setWindowFlags( Qt::Widget ); // Probably a Qt bug here dialog->hide();
// It would be logical that QStackWidget::addWidget reset the flags... playlistWidget = dialog->exportPlaylistWidget();
stackCentralW->addWidget( playlistWidget ); stackCentralW->addWidget( playlistWidget );
/* If playlist is invisible don't show it */ /* If playlist is invisible don't show it */
if( !playlistWidget->isVisible() ) return; if( playlistVisible ) showTab( playlistWidget );
showTab( playlistWidget );
} }
playlistVisible = true;
} }
/* /*
...@@ -954,6 +936,13 @@ void MainInterface::setStatusBarVisibility( bool b_visible ) ...@@ -954,6 +936,13 @@ void MainInterface::setStatusBarVisibility( bool b_visible )
if( controls ) controls->setGripVisible( !b_statusbarVisible ); if( controls ) controls->setGripVisible( !b_statusbarVisible );
} }
void MainInterface::setPlaylistVisibility( bool b_visible )
{
if ( !isPlDocked() )
playlistVisible = b_visible;
}
#if 0 #if 0
void MainInterface::visual() void MainInterface::visual()
{ {
......
...@@ -189,6 +189,7 @@ public slots: ...@@ -189,6 +189,7 @@ public slots:
void toggleFSC(); void toggleFSC();
void setStatusBarVisibility(bool b_visible); void setStatusBarVisibility(bool b_visible);
void setPlaylistVisibility(bool b_visible);
void popupMenu( const QPoint& ); void popupMenu( const QPoint& );
#ifdef WIN32 #ifdef WIN32
......
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