[vlc-commits] Qt: main_interface: fix playlist widgets instances. (fix #6795)
Francois Cartegnie
git at videolan.org
Tue May 15 15:26:34 CEST 2012
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun May 13 14:55:53 2012 +0200| [0df9e699370faf5e41652dc162190589943f0fdf] | committer: 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0df9e699370faf5e41652dc162190589943f0fdf
---
modules/gui/qt4/components/playlist/playlist.hpp | 4 +-
modules/gui/qt4/dialogs/playlist.cpp | 36 ++++++++--
modules/gui/qt4/dialogs/playlist.hpp | 15 ++++-
modules/gui/qt4/main_interface.cpp | 81 +++++++++------------
modules/gui/qt4/main_interface.hpp | 1 +
5 files changed, 81 insertions(+), 56 deletions(-)
diff --git a/modules/gui/qt4/components/playlist/playlist.hpp b/modules/gui/qt4/components/playlist/playlist.hpp
index 7d10eb6..122c73f 100644
--- a/modules/gui/qt4/components/playlist/playlist.hpp
+++ b/modules/gui/qt4/components/playlist/playlist.hpp
@@ -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
diff --git a/modules/gui/qt4/dialogs/playlist.cpp b/modules/gui/qt4/dialogs/playlist.cpp
index 26c28d2..646fd53 100644
--- a/modules/gui/qt4/dialogs/playlist.cpp
+++ b/modules/gui/qt4/dialogs/playlist.cpp
@@ -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 )
diff --git a/modules/gui/qt4/dialogs/playlist.hpp b/modules/gui/qt4/dialogs/playlist.hpp
index e3215df..f7a2e49 100644
--- a/modules/gui/qt4/dialogs/playlist.hpp
+++ b/modules/gui/qt4/dialogs/playlist.hpp
@@ -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 );
};
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 377347f..f1d5ac6 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -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()
{
diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp
index c81d8b5..2b4bb26 100644
--- a/modules/gui/qt4/main_interface.hpp
+++ b/modules/gui/qt4/main_interface.hpp
@@ -189,6 +189,7 @@ public slots:
void toggleFSC();
void setStatusBarVisibility(bool b_visible);
+ void setPlaylistVisibility(bool b_visible);
void popupMenu( const QPoint& );
#ifdef WIN32
More information about the vlc-commits
mailing list