X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fqt4%2Fcomponents%2Fplaylist%2Fstandardpanel.cpp;h=51cb0f9f15b7c95170e0359901de402cc51f12b6;hb=5f81bec53ccae76400188a5baa9d7ce099fdadef;hp=3a770a71fdec7e3109aafbc17d679c003f199eef;hpb=9846f39f69d0beff78c4152cc51df6d64dafa838;p=vlc diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp index 3a770a71fd..51cb0f9f15 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.cpp +++ b/modules/gui/qt4/components/playlist/standardpanel.cpp @@ -21,109 +21,299 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "playlist_model.hpp" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "qt4.hpp" +#include "dialogs_provider.hpp" + +#include "components/playlist/playlist_model.hpp" #include "components/playlist/panels.hpp" -#include +#include "util/customwidgets.hpp" + +#include + #include #include #include #include #include -#include "qt4.hpp" -#include #include +#include +#include +#include +#include +#include + +#include "sorting.h" -StandardPLPanel::StandardPLPanel( QWidget *_parent, intf_thread_t *_p_intf, +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 ); - view = new QTreeView( 0 ); - view->setModel(model); - view->header()->resizeSection( 0, 300 ); + model = new PLModel( p_playlist, p_intf, p_root, -1, this ); - connect( view, SIGNAL( activated( const QModelIndex& ) ), model, - SLOT( activateItem( const QModelIndex& ) ) ); + QVBoxLayout *layout = new QVBoxLayout(); + layout->setSpacing( 0 ); layout->setMargin( 0 ); - connect( model, - SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ), - this, SLOT( handleExpansion( const QModelIndex& ) ) ); + /* Create and configure the QTreeView */ + 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->setSelectionBehavior( QAbstractItemView::SelectRows ); + view->setSelectionMode( QAbstractItemView::ExtendedSelection ); + view->setDragEnabled( true ); + view->setAcceptDrops( true ); + view->setDropIndicatorShown( true ); - model->Rebuild(); - QVBoxLayout *layout = new QVBoxLayout(); - layout->setSpacing( 0 ); layout->setMargin( 0 ); + 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(); - QHBoxLayout *buttons = new QHBoxLayout(); - repeatButton = new QPushButton( this ); - buttons->addWidget( repeatButton ); + /* Connections for the TreeView */ + CONNECT( view, activated( const QModelIndex& ) , + model,activateItem( const QModelIndex& ) ); + CONNECT( view, rightClicked( QModelIndex , QPoint ), + this, doPopup( QModelIndex, QPoint ) ); + CONNECT( view->header(), customContextMenuRequested( const QPoint & ), + this, popupSelectColumn( QPoint ) ); + CONNECT( model, currentChanged( const QModelIndex& ), + this, handleExpansion( const QModelIndex& ) ); + + currentRootId = -1; + CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) ); + + /* Buttons configuration */ + QHBoxLayout *buttons = new QHBoxLayout; + + /* Add item to the playlist button */ + addButton = new QPushButton; + addButton->setIcon( QIcon( ":/buttons/playlist/playlist_add" ) ); + addButton->setMaximumWidth( 30 ); + BUTTONACT( addButton, popupAdd() ); + buttons->addWidget( addButton ); + + /* Random 2-state button */ randomButton = new QPushButton( this ); + randomButton->setIcon( QIcon( ":/buttons/playlist/shuffle_on" )); + randomButton->setToolTip( qtr( I_PL_RANDOM )); + randomButton->setCheckable( true ); + randomButton->setChecked( model->hasRandom() ); + BUTTONACT( randomButton, toggleRandom() ); buttons->addWidget( randomButton ); - if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) ); - else randomButton->setText( qtr( "No random" ) ); + /* Repeat 3-state button */ + repeatButton = new QPushButton( this ); + repeatButton->setToolTip( qtr( "Click to toggle between loop one, loop all" ) ); + repeatButton->setCheckable( true ); + + if( model->hasRepeat() ) + { + repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) ); + repeatButton->setChecked( true ); + } + else if( model->hasLoop() ) + { + repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) ); + repeatButton->setChecked( true ); + } + else + { + repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) ); + repeatButton->setChecked( false ); + } + BUTTONACT( repeatButton, toggleRepeat() ); + buttons->addWidget( repeatButton ); + + /* Goto */ + gotoPlayingButton = new QPushButton; + BUTTON_SET_ACT_I( gotoPlayingButton, "", buttons/playlist/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 ); - if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) ); - else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) ); - else repeatButton->setText( qtr( "No Repeat" ) ); + QLabel *filter = new QLabel( qtr(I_PL_SEARCH) + " " ); + buttons->addWidget( filter ); - connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() )); - connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() )); + SearchLineEdit *search = new SearchLineEdit( this ); + buttons->addWidget( search ); + filter->setBuddy( search ); + CONNECT( search, textChanged( const QString& ), this, search( const 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->setText( qtr( "Repeat All" ) ); + repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) ); + repeatButton->setChecked( true ); } else if( model->hasLoop() ) { model->setRepeat( false ) ; model->setLoop( false ); - repeatButton->setText( qtr( "No Repeat" ) ); + repeatButton->setChecked( false ); + repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) ); } else { - model->setRepeat( true ); - repeatButton->setText( qtr( "Repeat One" ) ); + model->setRepeat( true ); model->setLoop( false ); + repeatButton->setChecked( true ); + repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) ); } } +/* Function to toggle between the Random states */ void StandardPLPanel::toggleRandom() { bool prev = model->hasRandom(); model->setRandom( !prev ); - randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) ); } -void StandardPLPanel::handleExpansion( const QModelIndex &index ) +void StandardPLPanel::gotoPlayingItem() +{ + view->scrollTo( view->currentIndex() ); +} + +void StandardPLPanel::handleExpansion( const QModelIndex& index ) { - QModelIndex parent; - if( model->isCurrent( index ) ) + view->scrollTo( index, QAbstractItemView::EnsureVisible ); +} + +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( ( 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) ); + } + else + 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_ADDDIR), THEDP, SLOT( PLAppendDir()) ); + popup.addAction( qtr(I_OP_ADVOP), THEDP, SLOT( PLAppendDialog()) ); + } + 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_ADDDIR), THEDP, SLOT( MLAppendDir() ) ); + popup.addAction( qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) ); + } + + popup.exec( QCursor::pos() - addButton->mapFromGlobal( QCursor::pos() ) + + QPoint( 0, addButton->height() ) ); +} + +void StandardPLPanel::popupSelectColumn( QPoint pos ) +{ + ContextUpdateMapper = new QSignalMapper(this); + + QMenu selectColMenu; + + CONNECT( ContextUpdateMapper, mapped( int ), model, viewchanged( int ) ); + + int i_column = 1; + for( i_column = 1; i_column != COLUMN_END; i_column<<=1 ) { - parent = index; - while( parent.isValid() ) - { - view->setExpanded( parent, true ); - parent = model->parent( parent ); - } + 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() ); } + + selectColMenu.exec( QCursor::pos() ); +} + +/* Search in the playlist */ +void StandardPLPanel::search( const QString& searchText ) +{ + model->search( searchText ); +} + +void StandardPLPanel::doPopup( QModelIndex index, QPoint point ) +{ + if( !index.isValid() ) return; + QItemSelectionModel *selection = view->selectionModel(); + QModelIndexList list = selection->selectedIndexes(); + 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 ) { + QPL_LOCK; playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id ); assert( p_item ); - model->rebuildRoot( p_item ); - model->Rebuild(); + p_item = playlist_GetPreferredNode( THEPL, p_item ); + assert( p_item ); + QPL_UNLOCK; + + model->rebuild( p_item ); +} + +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() ) @@ -143,4 +333,10 @@ void StandardPLPanel::deleteSelection() } StandardPLPanel::~StandardPLPanel() -{} +{ + getSettings()->beginGroup("Playlist"); + getSettings()->setValue( "headerState", view->header()->saveState() ); + getSettings()->endGroup(); +} + +