X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fplaylist%2Fstandardpanel.cpp;h=6b57047e85bbf1533958bc7b98e96d60f01ae121;hb=7e4419bcc6ed629cd9a06863965260b96b9cb1fa;hp=7b237fddfbed1795fb0f7b774afcbd8dbe5b1c5a;hpb=771fe0b86d7251baa24b9b1732acb95711bdb16a;p=vlc diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp index 7b237fddfb..6b57047e85 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.cpp +++ b/modules/gui/qt4/components/playlist/standardpanel.cpp @@ -21,9 +21,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include "qt4.hpp" #include "dialogs_provider.hpp" -#include "playlist_model.hpp" + +#include "components/playlist/playlist_model.hpp" #include "components/playlist/panels.hpp" #include "util/customwidgets.hpp" @@ -40,9 +45,11 @@ #include #include #include - +#include #include +#include "sorting.h" + StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, intf_thread_t *_p_intf, playlist_t *p_playlist, @@ -50,26 +57,43 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, PLPanel( _parent, _p_intf ) { model = new PLModel( p_playlist, p_intf, p_root, -1, this ); - + + QVBoxLayout *layout = new QVBoxLayout(); + layout->setSpacing( 0 ); layout->setMargin( 0 ); + /* Create and configure the QTreeView */ - view = new QVLCTreeView( 0 ); - view->setModel(model); - view->setIconSize( QSize(20,20) ); + view = new QVLCTreeView; + view->header()->setSortIndicator( 0 , Qt::AscendingOrder ); + view->setSortingEnabled( true ); + 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 ); + + + getSettings()->beginGroup("Playlist"); + if( getSettings()->contains( "headerState" ) ) + { + view->header()->restoreState( + getSettings()->value( "headerState" ).toByteArray() ); + } + else + { + /* Configure the size of the header */ + view->header()->resizeSection( 0, 200 ); + view->header()->resizeSection( 1, 80 ); + } view->header()->setSortIndicatorShown( true ); view->header()->setClickable( true ); view->header()->setContextMenuPolicy( Qt::CustomContextMenu ); - + getSettings()->endGroup(); + + /* Connections for the TreeView */ CONNECT( view, activated( const QModelIndex& ) , model,activateItem( const QModelIndex& ) ); CONNECT( view, rightClicked( QModelIndex , QPoint ), @@ -80,98 +104,121 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, this, popupSelectColumn( QPoint ) ); currentRootId = -1; - CONNECT( parent, rootChanged(int), this, setCurrentRootId( int ) ); - - QVBoxLayout *layout = new QVBoxLayout(); - layout->setSpacing( 0 ); layout->setMargin( 0 ); + CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) ); /* Buttons configuration */ - QHBoxLayout *buttons = new QHBoxLayout(); - - addButton = new QPushButton( QIcon( ":/pixmaps/playlist_add.png" ), "", this ); - addButton->setMaximumWidth( 25 ); + QHBoxLayout *buttons = new QHBoxLayout; + + /* Add item to the playlist button */ + addButton = new QPushButton; + addButton->setIcon( QIcon( ":/playlist_add" ) ); + addButton->setMaximumWidth( 30 ); BUTTONACT( addButton, popupAdd() ); buttons->addWidget( addButton ); + /* Random 2-state button */ randomButton = new QPushButton( this ); - randomButton->setIcon( model->hasRandom() ? - QIcon( ":/pixmaps/playlist_shuffle_on.png" ) : - QIcon( ":/pixmaps/playlist_shuffle_off.png" ) ); + if( model->hasRandom() ) + { + randomButton->setIcon( QIcon( ":/shuffle_on" )); + randomButton->setToolTip( qtr( I_PL_RANDOM )); + } + else + { + randomButton->setIcon( QIcon( ":/shuffle_off" ) ); + randomButton->setToolTip( qtr( I_PL_NORANDOM )); + } BUTTONACT( randomButton, toggleRandom() ); buttons->addWidget( randomButton ); - QSpacerItem *spacer = new QSpacerItem( 10, 20 ); - buttons->addItem( spacer ); - + /* Repeat 3-state button */ repeatButton = new QPushButton( this ); - if( model->hasRepeat() ) repeatButton->setIcon( - QIcon( ":/pixmaps/playlist_repeat_one.png" ) ); - else if( model->hasLoop() ) repeatButton->setIcon( - QIcon( ":/pixmaps/playlist_repeat_all.png" ) ); - else repeatButton->setIcon( - QIcon( ":/pixmaps/playlist_repeat_off.png" ) ); + if( model->hasRepeat() ) + { + repeatButton->setIcon( QIcon( ":/repeat_one" ) ); + repeatButton->setToolTip( qtr( I_PL_REPEAT )); + } + else if( model->hasLoop() ) + { + repeatButton->setIcon( QIcon( ":/repeat_all" ) ); + repeatButton->setToolTip( qtr( I_PL_LOOP )); + } + else + { + repeatButton->setIcon( QIcon( ":/repeat_off" ) ); + repeatButton->setToolTip( qtr( I_PL_NOREPEAT )); + } BUTTONACT( repeatButton, toggleRepeat() ); buttons->addWidget( repeatButton ); + /* Goto */ + gotoPlayingButton = new QPushButton; + BUTTON_SET_ACT_I( gotoPlayingButton, "", jump_to, + qtr( "Show the current item" ), gotoPlayingItem() ); + buttons->addWidget( gotoPlayingButton ); + + /* A Spacer and the search possibilities */ + QSpacerItem *spacer = new QSpacerItem( 10, 20 ); + buttons->addItem( spacer ); QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " ); buttons->addWidget( filter ); - 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 ); + SearchLineEdit *search = new SearchLineEdit( this ); + buttons->addWidget( search ); + filter->setBuddy( search ); + CONNECT( search, textChanged( QString ), this, search( QString ) ); + /* Finish the layout */ layout->addWidget( view ); layout->addLayout( buttons ); // layout->addWidget( bar ); setLayout( layout ); } +/* Function to toggle between the Repeat states */ void StandardPLPanel::toggleRepeat() { if( model->hasRepeat() ) { model->setRepeat( false ); model->setLoop( true ); - repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_all.png" ) ); + repeatButton->setIcon( QIcon( ":/repeat_all" ) ); + repeatButton->setToolTip( qtr( I_PL_LOOP )); } else if( model->hasLoop() ) { model->setRepeat( false ) ; model->setLoop( false ); - repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_off.png" ) ); + repeatButton->setIcon( QIcon( ":/repeat_off" ) ); + repeatButton->setToolTip( qtr( I_PL_NOREPEAT )); } else { model->setRepeat( true ); - repeatButton->setIcon( QIcon( ":/pixmaps/playlist_repeat_one.png" ) ); + repeatButton->setIcon( QIcon( ":/repeat_one" ) ); + repeatButton->setToolTip( qtr( I_PL_REPEAT )); } } +/* Function to toggle between the Random states */ void StandardPLPanel::toggleRandom() { bool prev = model->hasRandom(); model->setRandom( !prev ); randomButton->setIcon( prev ? - QIcon( ":/pixmaps/playlist_shuffle_off.png" ) : - QIcon( ":/pixmaps/playlist_shuffle_on.png" ) ); + QIcon( ":/shuffle_off" ) : + QIcon( ":/shuffle_on" ) ); + randomButton->setToolTip( prev ? qtr( I_PL_NORANDOM ) : qtr(I_PL_RANDOM ) ); +} + +void StandardPLPanel::gotoPlayingItem() +{ + view->scrollTo( view->currentIndex() ); } void StandardPLPanel::handleExpansion( const QModelIndex &index ) { - QModelIndex parent; if( model->isCurrent( index ) ) - { view->scrollTo( index, QAbstractItemView::EnsureVisible ); - parent = index; - while( parent.isValid() ) - { - view->setExpanded( parent, true ); - parent = model->parent( parent ); - } - } } void StandardPLPanel::setCurrentRootId( int _new ) @@ -183,8 +230,10 @@ void StandardPLPanel::setCurrentRootId( int _new ) 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 ) + else if( ( THEPL->p_ml_category && + currentRootId == THEPL->p_ml_category->i_id ) || + ( THEPL->p_ml_onelevel && + currentRootId == THEPL->p_ml_onelevel->i_id ) ) { addButton->setEnabled( true ); addButton->setToolTip( qtr(I_PL_ADDML) ); @@ -193,60 +242,51 @@ void StandardPLPanel::setCurrentRootId( int _new ) addButton->setEnabled( false ); } +/* PopupAdd Menu for the Add Menu */ 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_ADDF), 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 ) + else if( ( THEPL->p_ml_category && + currentRootId == THEPL->p_ml_category->i_id ) || + ( THEPL->p_ml_onelevel && + 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_ADDF), THEDP, SLOT( MLAppendDialog() ) ); popup.addAction( qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) ); } - popup.exec( QCursor::pos() ); + popup.exec( QCursor::pos() - addButton->mapFromGlobal( QCursor::pos() ) + + QPoint( 0, addButton->height() ) ); } -void StandardPLPanel::popupSelectColumn( QPoint ) +void StandardPLPanel::popupSelectColumn( QPoint pos ) { 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() ); - } + int i_column = 1; + for( i_column = 1; i_column != COLUMN_END; i_column<<=1 ) + { + QAction* option = selectColMenu.addAction( + qfu( psz_column_title( i_column ) ) ); + option->setCheckable( true ); + option->setChecked( model->shownFlags() & i_column ); + ContextUpdateMapper->setMapping( option, i_column ); + CONNECT( option, triggered(), ContextUpdateMapper, map() ); + } -void StandardPLPanel::clearFilter() -{ - searchLine->setText( "" ); + selectColMenu.exec( QCursor::pos() ); } +/* Search in the playlist */ void StandardPLPanel::search( QString searchText ) { model->search( searchText ); @@ -260,13 +300,17 @@ void StandardPLPanel::doPopup( QModelIndex index, QPoint point ) model->popup( index, point, list ); } +/* Set the root of the new Playlist */ +/* This activated by the selector selection */ void StandardPLPanel::setRoot( int i_root_id ) { - playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id, - VLC_TRUE ); + QPL_LOCK; + playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id ); assert( p_item ); p_item = playlist_GetPreferredNode( THEPL, p_item ); assert( p_item ); + QPL_UNLOCK; + model->rebuild( p_item ); } @@ -275,6 +319,8 @@ void StandardPLPanel::removeItem( int i_id ) model->removeItem( i_id ); } +/* Delete and Suppr key remove the selection + FilterKey function and code function */ void StandardPLPanel::keyPressEvent( QKeyEvent *e ) { switch( e->key() ) @@ -294,4 +340,10 @@ void StandardPLPanel::deleteSelection() } StandardPLPanel::~StandardPLPanel() -{} +{ + getSettings()->beginGroup("Playlist"); + getSettings()->setValue( "headerState", view->header()->saveState() ); + getSettings()->endGroup(); +} + +