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