From a01c61f610ed96c124703d670a7eed7dbfac63c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Stenac?= Date: Fri, 22 Sep 2006 20:42:33 +0000 Subject: [PATCH] Put the dock/undock back in the menu Put the add button in the playlist standard panel Remove duplicated code for playlist widgets --- .../gui/qt4/components/interface_widgets.cpp | 67 +++---------------- .../gui/qt4/components/interface_widgets.hpp | 15 ++--- .../gui/qt4/components/playlist/panels.hpp | 14 +++- .../qt4/components/playlist/standardpanel.cpp | 62 +++++++++++++++-- modules/gui/qt4/dialogs/playlist.cpp | 43 ++---------- modules/gui/qt4/main_interface.cpp | 30 +++++++-- modules/gui/qt4/main_interface.hpp | 2 + modules/gui/qt4/menus.cpp | 12 +++- modules/gui/qt4/menus.hpp | 4 +- modules/gui/qt4/qt4.hpp | 11 +++ 10 files changed, 136 insertions(+), 124 deletions(-) diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp index 0fafbb50b8..a64070ad2f 100644 --- a/modules/gui/qt4/components/interface_widgets.cpp +++ b/modules/gui/qt4/components/interface_widgets.cpp @@ -168,8 +168,8 @@ VisualSelector::~VisualSelector() #include "components/playlist/panels.hpp" #include "components/playlist/selector.hpp" -PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : QFrame(NULL), - p_intf( _p_intf ) +PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : + BasePlaylistWidget ( _p_intf) { QVBoxLayout *left = new QVBoxLayout( ); QHBoxLayout *middle = new QHBoxLayout; @@ -178,17 +178,12 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : QFrame(NULL), selector->setMaximumWidth( 130 ); left->addWidget( selector ); - QPushButton *undockButton = new QPushButton( "UN", this ); +/* QPushButton *undockButton = new QPushButton( "UN", this ); undockButton->setMaximumWidth( 25 ); undockButton->setToolTip( qtr( "Undock playlist for main interface" ) ); BUTTONACT( undockButton, undock() ); middle->addWidget( undockButton ); - - addButton = new QPushButton( "+", this ); - addButton->setMaximumWidth( 25 ); - BUTTONACT( addButton, add() ); - middle->addWidget( addButton ); - +*/ left->addLayout( middle ); QLabel *art = new QLabel( "" ); @@ -200,13 +195,15 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_intf ) : QFrame(NULL), playlist_item_t *p_root = playlist_GetPreferredNode( THEPL, THEPL->p_local_category ); - currentRootId = p_root->i_id; rightPanel = qobject_cast(new StandardPLPanel( this, p_intf, THEPL, p_root ) ); CONNECT( selector, activated( int ), rightPanel, setRoot( int ) ); - CONNECT( selector, activated( int ), this, setCurrentRootId( int ) ); + + connect( selector, SIGNAL(activated( int )), + this, SIGNAL( rootChanged( int ) ) ); + emit rootChanged( p_root->i_id ); QHBoxLayout *layout = new QHBoxLayout(this); layout->addLayout( left, 0 ); @@ -218,54 +215,6 @@ PlaylistWidget::~PlaylistWidget() { } -void PlaylistWidget::setCurrentRootId( int _new ) -{ - currentRootId = _new; - if( currentRootId == THEPL->p_local_category->i_id || - currentRootId == THEPL->p_local_onelevel->i_id ) - { - addButton->setEnabled( true ); - addButton->setToolTip( qtr("Add to playlist" ) ); - } - else if( currentRootId == THEPL->p_ml_category->i_id || - currentRootId == THEPL->p_ml_onelevel->i_id ) - { - addButton->setEnabled( true ); - addButton->setToolTip( qtr("Add to media library" ) ); - } - else - addButton->setEnabled( false ); -} - -void PlaylistWidget::undock() -{ - hide(); - THEDP->playlistDialog(); - deleteLater(); - - QEvent *event = new QEvent( (QEvent::Type)(PLUndockEvent_Type) ); - QApplication::postEvent( p_intf->p_sys->p_mi, event ); -} - -void PlaylistWidget::add() -{ - QMenu *popup = new QMenu(); - if( currentRootId == THEPL->p_local_category->i_id || - currentRootId == THEPL->p_local_onelevel->i_id ) - { - popup->addAction( "Add file", THEDP, SLOT( simplePLAppendDialog() ) ); - popup->addAction( "Advanced add", THEDP, SLOT( PLAppendDialog() ) ); - } - else if( currentRootId == THEPL->p_ml_category->i_id || - currentRootId == THEPL->p_ml_onelevel->i_id ) - { - popup->addAction( "Add file", THEDP, SLOT( simpleMLAppendDialog() ) ); - popup->addAction( "Advanced add", THEDP, SLOT( MLAppendDialog() ) ); - popup->addAction( "Directory", THEDP, SLOT( openMLDirectory() ) ); - } - popup->popup( QCursor::pos() ); -} - QSize PlaylistWidget::sizeHint() const { return widgetSize; diff --git a/modules/gui/qt4/components/interface_widgets.hpp b/modules/gui/qt4/components/interface_widgets.hpp index 6d46766455..fd894685a2 100644 --- a/modules/gui/qt4/components/interface_widgets.hpp +++ b/modules/gui/qt4/components/interface_widgets.hpp @@ -26,6 +26,9 @@ #include #include + +#include "qt4.hpp" + #include #include #include @@ -88,14 +91,14 @@ private: intf_thread_t *p_intf; }; -/******************** Playlist Widget ****************/ +/******************** Playlist Widgets ****************/ #include class QSignalMapper; class PLSelector; class PLPanel; class QPushButton; -class PlaylistWidget : public QFrame +class PlaylistWidget : public BasePlaylistWidget { Q_OBJECT; public: @@ -106,13 +109,9 @@ public: private: PLSelector *selector; PLPanel *rightPanel; - intf_thread_t *p_intf; - int currentRootId; QPushButton *addButton; -private slots: - void undock(); - void add(); - void setCurrentRootId( int ); +signals: + void rootChanged( int ); }; #endif diff --git a/modules/gui/qt4/components/playlist/panels.hpp b/modules/gui/qt4/components/playlist/panels.hpp index 2e2eb45cdf..f6d3336591 100644 --- a/modules/gui/qt4/components/playlist/panels.hpp +++ b/modules/gui/qt4/components/playlist/panels.hpp @@ -25,6 +25,9 @@ #define _PLPANELS_H_ #include + +#include "qt4.hpp" + #include #include #include @@ -39,13 +42,15 @@ class PLPanel: public QWidget { Q_OBJECT; public: - PLPanel( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ) + PLPanel( BasePlaylistWidget *p, intf_thread_t *_p_intf ) : QWidget( p ) { p_intf = _p_intf; + parent = p; } virtual ~PLPanel() {}; protected: intf_thread_t *p_intf; + BasePlaylistWidget *parent; public slots: virtual void setRoot( int ) = 0; }; @@ -55,7 +60,7 @@ class StandardPLPanel: public PLPanel { Q_OBJECT; public: - StandardPLPanel( QWidget *, intf_thread_t *, + StandardPLPanel( BasePlaylistWidget *, intf_thread_t *, playlist_t *,playlist_item_t * ); virtual ~StandardPLPanel(); protected: @@ -63,8 +68,9 @@ protected: private: PLModel *model; QTreeView *view; - QPushButton *repeatButton , *randomButton; + QPushButton *repeatButton , *randomButton,*addButton; ClickLineEdit *searchLine; + int currentRootId; public slots: virtual void setRoot( int ); private slots: @@ -75,6 +81,8 @@ private slots: void doPopup( QModelIndex index, QPoint point ); void search( QString search ); void clearFilter(); + void add(); + void setCurrentRootId( int ); }; #endif diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp index d2b054b924..74f6b48933 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.cpp +++ b/modules/gui/qt4/components/playlist/standardpanel.cpp @@ -22,6 +22,7 @@ *****************************************************************************/ #include "qt4.hpp" +#include "dialogs_provider.hpp" #include "playlist_model.hpp" #include "components/playlist/panels.hpp" #include "util/customwidgets.hpp" @@ -36,10 +37,12 @@ #include #include #include +#include #include -StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf, +StandardPLPanel::StandardPLPanel( BasePlaylistWidget *_parent, + intf_thread_t *_p_intf, playlist_t *p_playlist, playlist_item_t *p_root ): PLPanel( _parent, _p_intf ) @@ -62,20 +65,28 @@ StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf, CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ), this, handleExpansion( const QModelIndex& ) ); + currentRootId = -1; + CONNECT( parent, rootChanged(int), this, setCurrentRootId( int ) ); + QVBoxLayout *layout = new QVBoxLayout(); layout->setSpacing( 0 ); layout->setMargin( 0 ); QHBoxLayout *buttons = new QHBoxLayout(); + addButton = new QPushButton( "+", this ); + addButton->setMaximumWidth( 25 ); + BUTTONACT( addButton, add() ); + buttons->addWidget( addButton ); + repeatButton = new QPushButton( 0 ); buttons->addWidget( repeatButton ); - if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) ); - else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) ); - else repeatButton->setText( qtr( "No Repeat" ) ); + if( model->hasRepeat() ) repeatButton->setText( qtr( "R1" ) ); + else if( model->hasLoop() ) repeatButton->setText( qtr( "RA" ) ); + else repeatButton->setText( qtr( "NR" ) ); BUTTONACT( repeatButton, toggleRepeat() ); randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton ); - if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) ); - else randomButton->setText( qtr( "No random" ) ); + if( model->hasRandom() ) randomButton->setText( qtr( " RND" ) ); + else randomButton->setText( qtr( "NRND" ) ); BUTTONACT( randomButton, toggleRandom() ); QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer ); @@ -87,6 +98,7 @@ StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf, buttons->addWidget( searchLine ); filter->setBuddy( searchLine ); QPushButton *clear = new QPushButton( qfu( "CL") ); + clear->setMaximumWidth( 30 ); buttons->addWidget( clear ); BUTTONACT( clear, clearFilter() ); @@ -136,6 +148,44 @@ void StandardPLPanel::handleExpansion( const QModelIndex &index ) } } +void StandardPLPanel::setCurrentRootId( int _new ) +{ + currentRootId = _new; + if( currentRootId == THEPL->p_local_category->i_id || + currentRootId == THEPL->p_local_onelevel->i_id ) + { + addButton->setEnabled( true ); + addButton->setToolTip( qtr("Add to playlist" ) ); + } + else if( currentRootId == THEPL->p_ml_category->i_id || + currentRootId == THEPL->p_ml_onelevel->i_id ) + { + addButton->setEnabled( true ); + addButton->setToolTip( qtr("Add to media library" ) ); + } + else + addButton->setEnabled( false ); +} + +void StandardPLPanel::add() +{ + QMenu *popup = new QMenu(); + if( currentRootId == THEPL->p_local_category->i_id || + currentRootId == THEPL->p_local_onelevel->i_id ) + { + popup->addAction( "Add file", THEDP, SLOT( simplePLAppendDialog() ) ); + popup->addAction( "Advanced add", THEDP, SLOT( PLAppendDialog() ) ); + } + else if( currentRootId == THEPL->p_ml_category->i_id || + currentRootId == THEPL->p_ml_onelevel->i_id ) + { + popup->addAction( "Add file", THEDP, SLOT( simpleMLAppendDialog() ) ); + popup->addAction( "Advanced add", THEDP, SLOT( MLAppendDialog() ) ); + popup->addAction( "Directory", THEDP, SLOT( openMLDirectory() ) ); + } + popup->popup( QCursor::pos() ); +} + void StandardPLPanel::clearFilter() { searchLine->setText( "" ); diff --git a/modules/gui/qt4/dialogs/playlist.cpp b/modules/gui/qt4/dialogs/playlist.cpp index 5e55081fc7..0cbc2bea7d 100644 --- a/modules/gui/qt4/dialogs/playlist.cpp +++ b/modules/gui/qt4/dialogs/playlist.cpp @@ -26,8 +26,7 @@ #include "qt4.hpp" #include "main_interface.hpp" #include "util/qvlcframe.hpp" -#include "components/playlist/panels.hpp" -#include "components/playlist/selector.hpp" +#include "components/interface_widgets.hpp" #include "dialogs_provider.hpp" #include "menus.hpp" @@ -45,22 +44,12 @@ PlaylistDialog::PlaylistDialog( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) setCentralWidget( main ); setWindowTitle( qtr( "Playlist" ) ); - createPlMenuBar( menuBar(), p_intf ); + createPlMenuBar( menuBar(), p_intf ); - selector = new PLSelector( centralWidget(), p_intf, THEPL ); - selector->setMaximumWidth( 130 ); + QHBoxLayout *l = new QHBoxLayout( centralWidget() ); + PlaylistWidget *plw = new PlaylistWidget( p_intf ); + l->addWidget( plw ); - playlist_item_t *p_root = playlist_GetPreferredNode( THEPL, - THEPL->p_local_category ); - - rightPanel = qobject_cast(new StandardPLPanel( centralWidget(), - p_intf, THEPL, p_root ) ); - CONNECT( selector, activated( int ), rightPanel, setRoot( int ) ); - - QHBoxLayout *layout = new QHBoxLayout(); - layout->addWidget( selector, 0 ); - layout->addWidget( rightPanel, 10 ); - centralWidget()->setLayout( layout ); readSettings( "playlist", QSize( 600,700 ) ); } @@ -72,27 +61,9 @@ PlaylistDialog::~PlaylistDialog() void PlaylistDialog::createPlMenuBar( QMenuBar *bar, intf_thread_t *p_intf ) { QMenu *manageMenu = new QMenu(); - manageMenu->setTitle( qtr("Add") ); - - QMenu *subPlaylist = new QMenu(); - subPlaylist->setTitle( qtr("Add to current playlist") ); - subPlaylist->addAction( "&File...", THEDP, - SLOT( simplePLAppendDialog() ) ); - subPlaylist->addAction( "&Advanced add...", THEDP, - SLOT( PLAppendDialog() ) ); - manageMenu->addMenu( subPlaylist ); - manageMenu->addSeparator(); - - QMenu *subML = new QMenu(); - subML->setTitle( qtr("Add to Media library") ); - subML->addAction( "&File...", THEDP, - SLOT( simpleMLAppendDialog() ) ); - subML->addAction( "Directory", THEDP, SLOT( openMLDirectory() )); - subML->addAction( "&Advanced add...", THEDP, - SLOT( MLAppendDialog() ) ); - manageMenu->addMenu( subML ); + manageMenu->setTitle( qtr("Manage") ); manageMenu->addAction( "Open playlist file", THEDP, SLOT( openPlaylist() )); - + manageMenu->addSeparator(); manageMenu->addAction( "Dock playlist", this, SLOT( dock() ) ); bar->addMenu( manageMenu ); bar->addMenu( QVLCMenu::SDMenu( p_intf ) ); diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp index b34261bc49..9fe6506546 100644 --- a/modules/gui/qt4/main_interface.cpp +++ b/modules/gui/qt4/main_interface.cpp @@ -93,7 +93,7 @@ MainInterface::MainInterface( intf_thread_t *_p_intf ) : QVLCMW( _p_intf ) setWindowTitle( QString::fromUtf8( _("VLC media player") ) ); handleMainUi( settings ); - QVLCMenu::createMenuBar( menuBar(), p_intf, playlistEmbeddedFlag ); + QVLCMenu::createMenuBar( this, p_intf, playlistEmbeddedFlag ); /* Status bar */ timeLabel = new QLabel( 0 ); @@ -437,23 +437,39 @@ void MainInterface::doComponentsUpdate() resize( mainSize ); } -void MainInterface::customEvent( QEvent *event ) +void MainInterface::undockPlaylist() { - if( event->type() == PLUndockEvent_Type ) + if( playlistWidget ) { + playlistWidget->hide(); + playlistWidget->deleteLater(); ui.vboxLayout->removeWidget( playlistWidget ); playlistWidget = NULL; playlistEmbeddedFlag = false; - doComponentsUpdate(); + menuBar()->clear(); - QVLCMenu::createMenuBar( menuBar(), p_intf, false ); + QVLCMenu::createMenuBar( this, p_intf, false ); + + if( videoIsActive ) + { + videoWidget->widgetSize = savedVideoSize; + videoWidget->resize( videoWidget->widgetSize ); + videoWidget->updateGeometry(); + } + + doComponentsUpdate(); + THEDP->playlistDialog(); } - else if( event->type() == PLDockEvent_Type ) +} + +void MainInterface::customEvent( QEvent *event ) +{ + if( event->type() == PLDockEvent_Type ) { PlaylistDialog::killInstance(); playlistEmbeddedFlag = true; menuBar()->clear(); - QVLCMenu::createMenuBar( menuBar(), p_intf, true ); + QVLCMenu::createMenuBar(this, p_intf, true ); playlist(); } } diff --git a/modules/gui/qt4/main_interface.hpp b/modules/gui/qt4/main_interface.hpp index 41b4cf19dd..2cfb0ac8ba 100644 --- a/modules/gui/qt4/main_interface.hpp +++ b/modules/gui/qt4/main_interface.hpp @@ -88,6 +88,8 @@ private: QLabel *nameLabel; void customEvent( QEvent *); +public slots: + void undockPlaylist(); private slots: void setStatus( int ); void setName( QString ); diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp index 6f336ef0d6..f814834b32 100644 --- a/modules/gui/qt4/menus.cpp +++ b/modules/gui/qt4/menus.cpp @@ -27,6 +27,8 @@ #include #include +#include "main_interface.hpp" + #include "menus.hpp" #include "dialogs_provider.hpp" #include "input_manager.hpp" @@ -117,13 +119,14 @@ static int AudioAutoMenuBuilder( vlc_object_t *p_object, CONNECT( menu, aboutToShow(), THEDP->menusUpdateMapper, map() ); \ THEDP->menusUpdateMapper->setMapping( menu, f ); } -void QVLCMenu::createMenuBar( QMenuBar *bar, intf_thread_t *p_intf, +void QVLCMenu::createMenuBar( MainInterface *mi, intf_thread_t *p_intf, bool playlist ) { + QMenuBar *bar = mi->menuBar(); BAR_ADD( FileMenu(), qtr("File") ); if( playlist ) { - BAR_ADD( PlaylistMenu( p_intf ), qtr("Playlist" ) ); + BAR_ADD( PlaylistMenu( mi,p_intf ), qtr("Playlist" ) ); } BAR_ADD( ToolsMenu( p_intf ), qtr("Tools") ); BAR_DADD( VideoMenu( p_intf, NULL ), qtr("Video"), 1 ); @@ -144,7 +147,7 @@ QMenu *QVLCMenu::FileMenu() return menu; } -QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf ) +QMenu *QVLCMenu::PlaylistMenu( MainInterface *mi, intf_thread_t *p_intf ) { QMenu *menu = new QMenu(); menu->addMenu( SDMenu( p_intf ) ); @@ -152,6 +155,9 @@ QMenu *QVLCMenu::PlaylistMenu( intf_thread_t *p_intf ) DP_SADD( qtr( "Open playlist file"), "", "", openPlaylist() ); // DP_SADD( qtr( "Save playlist to file" ), "", "", savePlaylist() ); + menu->addSeparator(); + menu->addAction( qtr("Undock from interface"), mi, + SLOT( undockPlaylist() ) ); return menu; } diff --git a/modules/gui/qt4/menus.hpp b/modules/gui/qt4/menus.hpp index 7e27e62afa..8929c6da57 100644 --- a/modules/gui/qt4/menus.hpp +++ b/modules/gui/qt4/menus.hpp @@ -58,12 +58,12 @@ class QVLCMenu : public QObject { Q_OBJECT; public: - static void createMenuBar( QMenuBar *, intf_thread_t *, bool ); + static void createMenuBar( MainInterface *mi, intf_thread_t *, bool ); /* Menus */ static QMenu *FileMenu(); static QMenu *SDMenu( intf_thread_t * ); - static QMenu *PlaylistMenu( intf_thread_t *); + static QMenu *PlaylistMenu( MainInterface *, intf_thread_t *); static QMenu *ToolsMenu( intf_thread_t *, bool with_intf = true ); static QMenu *NavigMenu( intf_thread_t * , QMenu * ); static QMenu *VideoMenu( intf_thread_t * , QMenu * ); diff --git a/modules/gui/qt4/qt4.hpp b/modules/gui/qt4/qt4.hpp index 39e6d7f736..fe66a737e5 100644 --- a/modules/gui/qt4/qt4.hpp +++ b/modules/gui/qt4/qt4.hpp @@ -82,4 +82,15 @@ public: intf_dialog_args_t *p_arg; }; +/* Ugly to put it here, but don't want more files ... */ +#include +class BasePlaylistWidget : public QFrame +{ +public: + BasePlaylistWidget( intf_thread_t *_p_i ) : p_intf( _p_i) {}; + virtual ~BasePlaylistWidget() {}; +protected: + intf_thread_t *p_intf; +}; + #endif -- GitLab