X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=inline;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fplaylist%2Fstandardpanel.cpp;h=d80f965e61e96044725792ebccfb708dd44e4c84;hb=6ee1e193fd896ab9a4729fde14f009d9ce629815;hp=c080e29b6e811766d02b505f725752480aedebb6;hpb=f9ed4872f2a595f23613df66c225d4ab0b9f2a13;p=vlc diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp index c080e29b6e..d80f965e61 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.cpp +++ b/modules/gui/qt4/components/playlist/standardpanel.cpp @@ -21,76 +21,108 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#include "qt4.hpp" +#include "dialogs_provider.hpp" #include "playlist_model.hpp" #include "components/playlist/panels.hpp" +#include "util/customwidgets.hpp" + +#include + #include #include #include #include #include #include -#include "qt4.hpp" -#include #include #include #include #include -#include "util/views.hpp" -#include "util/customwidgets.hpp" +#include -StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf, +#include + +StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, + intf_thread_t *_p_intf, playlist_t *p_playlist, playlist_item_t *p_root ): PLPanel( _parent, _p_intf ) { - model = new PLModel( p_playlist, p_root, -1, this ); + model = new PLModel( p_playlist, p_intf, p_root, -1, this ); + + /* Create and configure the QTreeView */ view = new QVLCTreeView( 0 ); view->setModel(model); view->setIconSize( QSize(20,20) ); view->setAlternatingRowColors( true ); + view->setAnimated( true ); + view->setSortingEnabled( true ); + view->setSelectionMode( QAbstractItemView::ExtendedSelection ); + view->setDragEnabled( true ); + view->setAcceptDrops( true ); + view->setDropIndicatorShown( true ); + view->setAutoScroll( true ); + view->header()->resizeSection( 0, 230 ); + view->header()->resizeSection( 1, 170 ); view->header()->setSortIndicatorShown( true ); view->header()->setClickable( true ); - view->setSelectionMode( QAbstractItemView::ExtendedSelection ); - - connect( view, SIGNAL( activated( const QModelIndex& ) ), model, - SLOT( activateItem( const QModelIndex& ) ) ); - - connect( view, SIGNAL( rightClicked( QModelIndex , QPoint ) ), - this, SLOT( doPopup( QModelIndex, QPoint ) ) ); + view->header()->setContextMenuPolicy( Qt::CustomContextMenu ); + + CONNECT( view, activated( const QModelIndex& ) , + model,activateItem( const QModelIndex& ) ); + CONNECT( view, rightClicked( QModelIndex , QPoint ), + this, doPopup( QModelIndex, QPoint ) ); + CONNECT( model, dataChanged( const QModelIndex&, const QModelIndex& ), + this, handleExpansion( const QModelIndex& ) ); + CONNECT( view->header(), customContextMenuRequested( const QPoint & ), + this, popupSelectColumn( QPoint ) ); - connect( model, - SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ), - this, SLOT( handleExpansion( const QModelIndex& ) ) ); + currentRootId = -1; + CONNECT( parent, rootChanged(int), this, setCurrentRootId( int ) ); QVBoxLayout *layout = new QVBoxLayout(); layout->setSpacing( 0 ); layout->setMargin( 0 ); + /* Buttons configuration */ QHBoxLayout *buttons = new QHBoxLayout(); + + addButton = new QPushButton( QIcon( ":/pixmaps/vlc_playlist_add.png" ), "", this ); + addButton->setMaximumWidth( 25 ); + BUTTONACT( addButton, popupAdd() ); + 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" ) ); - connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() )); + repeatButton = new QPushButton( this ); + if( model->hasRepeat() ) repeatButton->setIcon( + QIcon( ":/pixmaps/vlc_playlist_repeat_one.png" ) ); + else if( model->hasLoop() ) repeatButton->setIcon( + QIcon( ":/pixmaps/vlc_playlist_repeat_all.png" ) ); + else repeatButton->setIcon( + QIcon( ":/pixmaps/vlc_playlist_repeat_off.png" ) ); + BUTTONACT( repeatButton, toggleRepeat() ); + buttons->addWidget( repeatButton ); - randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton ); - if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) ); - else randomButton->setText( qtr( "No random" ) ); - connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() )); + randomButton = new QPushButton( this ); + randomButton->setIcon( model->hasRandom() ? + QIcon( ":/pixmaps/vlc_playlist_shuffle_on.png" ) : + QIcon( ":/pixmaps/vlc_playlist_shuffle_off.png" ) ); + BUTTONACT( randomButton, toggleRandom() ); + buttons->addWidget( randomButton ); - QSpacerItem *spacer = new QSpacerItem( 10, 20 );buttons->addItem( spacer ); + QSpacerItem *spacer = new QSpacerItem( 10, 20 ); + buttons->addItem( spacer ); - QLabel *filter = new QLabel( qfu( "&Search:" ) + " " ); + QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " ); buttons->addWidget( filter ); - searchLine = new ClickLineEdit( qfu( "Playlist filter" ), 0 ); - connect( searchLine, SIGNAL( textChanged(QString) ), - this, SLOT( search(QString)) ); + searchLine = new ClickLineEdit( qtr(I_PL_FILTER), 0 ); + CONNECT( searchLine, textChanged(QString), this, search(QString)); buttons->addWidget( searchLine ); filter->setBuddy( searchLine ); QPushButton *clear = new QPushButton( qfu( "CL") ); + clear->setMaximumWidth( 30 ); + BUTTONACT( clear, clearFilter() ); buttons->addWidget( clear ); - connect( clear, SIGNAL( clicked() ), this, SLOT( clearFilter() ) ); layout->addWidget( view ); layout->addLayout( buttons ); @@ -103,17 +135,17 @@ void StandardPLPanel::toggleRepeat() if( model->hasRepeat() ) { model->setRepeat( false ); model->setLoop( true ); - repeatButton->setText( qtr( "Repeat All" ) ); + repeatButton->setIcon( QIcon( ":/pixmaps/vlc_playlist_repeat_all.png" ) ); } else if( model->hasLoop() ) { model->setRepeat( false ) ; model->setLoop( false ); - repeatButton->setText( qtr( "No Repeat" ) ); + repeatButton->setIcon( QIcon( ":/pixmaps/vlc_playlist_repeat_off.png" ) ); } else { model->setRepeat( true ); - repeatButton->setText( qtr( "Repeat One" ) ); + repeatButton->setIcon( QIcon( ":/pixmaps/vlc_playlist_repeat_one.png" ) ); } } @@ -121,7 +153,9 @@ void StandardPLPanel::toggleRandom() { bool prev = model->hasRandom(); model->setRandom( !prev ); - randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) ); + randomButton->setIcon( prev ? + QIcon( ":/pixmaps/vlc_playlist_shuffle_off.png" ) : + QIcon( ":/pixmaps/vlc_playlist_shuffle_on.png" ) ); } void StandardPLPanel::handleExpansion( const QModelIndex &index ) @@ -129,6 +163,7 @@ void StandardPLPanel::handleExpansion( const QModelIndex &index ) QModelIndex parent; if( model->isCurrent( index ) ) { + view->scrollTo( index, QAbstractItemView::EnsureVisible ); parent = index; while( parent.isValid() ) { @@ -138,6 +173,74 @@ 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(I_PL_ADDPL) ); + } + else if( currentRootId == THEPL->p_ml_category->i_id || + currentRootId == THEPL->p_ml_onelevel->i_id ) + { + addButton->setEnabled( true ); + addButton->setToolTip( qtr(I_PL_ADDML) ); + } + else + addButton->setEnabled( false ); +} + +void StandardPLPanel::popupAdd() +{ + QMenu popup; + if( currentRootId == THEPL->p_local_category->i_id || + currentRootId == THEPL->p_local_onelevel->i_id ) + { + popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simplePLAppendDialog())); + popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT(PLAppendDialog()) ); + popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( PLAppendDir()) ); + } + else if( currentRootId == THEPL->p_ml_category->i_id || + currentRootId == THEPL->p_ml_onelevel->i_id ) + { + popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(simpleMLAppendDialog())); + popup.addAction( qtr(I_PL_ADVADD), THEDP, SLOT( MLAppendDialog() ) ); + popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) ); + } + popup.exec( QCursor::pos() ); +} + +void StandardPLPanel::popupSelectColumn( QPoint ) +{ + ContextUpdateMapper = new QSignalMapper(this); + + QMenu selectColMenu; + +#define ADD_META_ACTION( meta ) { \ + QAction* option = selectColMenu.addAction( qfu(VLC_META_##meta) ); \ + option->setCheckable( true ); \ + option->setChecked( model->shownFlags() & VLC_META_ENGINE_##meta ); \ + ContextUpdateMapper->setMapping( option, VLC_META_ENGINE_##meta ); \ + CONNECT( option, triggered(), ContextUpdateMapper, map() ); \ + } + CONNECT( ContextUpdateMapper, mapped( int ), model, viewchanged( int ) ); + + ADD_META_ACTION( TITLE ); + ADD_META_ACTION( ARTIST ); + ADD_META_ACTION( DURATION ); + ADD_META_ACTION( COLLECTION ); + ADD_META_ACTION( GENRE ); + ADD_META_ACTION( SEQ_NUM ); + ADD_META_ACTION( RATING ); + ADD_META_ACTION( DESCRIPTION ); + +#undef ADD_META_ACTION + + selectColMenu.exec( QCursor::pos() ); + } + void StandardPLPanel::clearFilter() { searchLine->setText( "" ); @@ -150,7 +253,7 @@ void StandardPLPanel::search( QString searchText ) void StandardPLPanel::doPopup( QModelIndex index, QPoint point ) { - assert( index.isValid() ); + if( !index.isValid() ) return; QItemSelectionModel *selection = view->selectionModel(); QModelIndexList list = selection->selectedIndexes(); model->popup( index, point, list ); @@ -158,13 +261,19 @@ void StandardPLPanel::doPopup( QModelIndex index, QPoint point ) void StandardPLPanel::setRoot( int i_root_id ) { - playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id ); + playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id, + VLC_TRUE ); assert( p_item ); p_item = playlist_GetPreferredNode( THEPL, p_item ); assert( p_item ); model->rebuild( p_item ); } +void StandardPLPanel::removeItem( int i_id ) +{ + model->removeItem( i_id ); +} + void StandardPLPanel::keyPressEvent( QKeyEvent *e ) { switch( e->key() )