]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/standardpanel.cpp
QT4: only scroll playlist to new item when it changes
[vlc] / modules / gui / qt4 / components / playlist / standardpanel.cpp
index e5ba2e6d134f746c7524ec6cc079857c54cc0f7d..51cb0f9f15b7c95170e0359901de402cc51f12b6 100644 (file)
 
 #include <vlc_intf_strings.h>
 
-#include <QTreeView>
 #include <QPushButton>
 #include <QHBoxLayout>
 #include <QVBoxLayout>
 #include <QHeaderView>
 #include <QKeyEvent>
 #include <QModelIndexList>
-#include <QToolBar>
 #include <QLabel>
 #include <QSpacerItem>
 #include <QMenu>
@@ -69,11 +67,11 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     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 );
-    view->setAutoScroll( true );
 
 
     getSettings()->beginGroup("Playlist");
@@ -98,10 +96,10 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
              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, currentChanged( const QModelIndex& ),
+             this, handleExpansion( const QModelIndex& ) );
 
     currentRootId = -1;
     CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) );
@@ -111,49 +109,46 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
 
     /* Add item to the playlist button */
     addButton = new QPushButton;
-    addButton->setIcon( QIcon( ":/playlist_add" ) );
+    addButton->setIcon( QIcon( ":/buttons/playlist/playlist_add" ) );
     addButton->setMaximumWidth( 30 );
     BUTTONACT( addButton, popupAdd() );
     buttons->addWidget( addButton );
 
     /* Random 2-state button */
     randomButton = new QPushButton( this );
-    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 ));
-    }
+    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 );
 
     /* 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( ":/repeat_one" ) );
-        repeatButton->setToolTip( qtr( I_PL_REPEAT ));
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
+        repeatButton->setChecked( true );
     }
     else if( model->hasLoop() )
     {
-        repeatButton->setIcon( QIcon( ":/repeat_all" ) );
-        repeatButton->setToolTip( qtr( I_PL_LOOP ));
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) );
+        repeatButton->setChecked( true );
     }
     else
     {
-        repeatButton->setIcon( QIcon( ":/repeat_off" ) );
-        repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
+        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, "", jump_to,
+    BUTTON_SET_ACT_I( gotoPlayingButton, "", buttons/playlist/jump_to,
             qtr( "Show the current item" ), gotoPlayingItem() );
     buttons->addWidget( gotoPlayingButton );
 
@@ -167,7 +162,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     SearchLineEdit *search = new SearchLineEdit( this );
     buttons->addWidget( search );
     filter->setBuddy( search );
-    CONNECT( search, textChanged( QString ), this, search( QString ) );
+    CONNECT( search, textChanged( const QString& ), this, search( const QString& ) );
 
     /* Finish the layout */
     layout->addWidget( view );
@@ -182,20 +177,20 @@ void StandardPLPanel::toggleRepeat()
     if( model->hasRepeat() )
     {
         model->setRepeat( false ); model->setLoop( true );
-        repeatButton->setIcon( QIcon( ":/repeat_all" ) );
-        repeatButton->setToolTip( qtr( I_PL_LOOP ));
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_all" ) );
+        repeatButton->setChecked( true );
     }
     else if( model->hasLoop() )
     {
         model->setRepeat( false ) ; model->setLoop( false );
-        repeatButton->setIcon( QIcon( ":/repeat_off" ) );
-        repeatButton->setToolTip( qtr( I_PL_NOREPEAT ));
+        repeatButton->setChecked( false );
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
     }
     else
     {
-        model->setRepeat( true );
-        repeatButton->setIcon( QIcon( ":/repeat_one" ) );
-        repeatButton->setToolTip( qtr( I_PL_REPEAT ));
+        model->setRepeat( true ); model->setLoop( false );
+        repeatButton->setChecked( true );
+        repeatButton->setIcon( QIcon( ":/buttons/playlist/repeat_one" ) );
     }
 }
 
@@ -204,10 +199,6 @@ void StandardPLPanel::toggleRandom()
 {
     bool prev = model->hasRandom();
     model->setRandom( !prev );
-    randomButton->setIcon( prev ?
-                QIcon( ":/shuffle_off" ) :
-                QIcon( ":/shuffle_on" ) );
-    randomButton->setToolTip( prev ? qtr( I_PL_NORANDOM ) : qtr(I_PL_RANDOM ) );
 }
 
 void StandardPLPanel::gotoPlayingItem()
@@ -215,10 +206,9 @@ void StandardPLPanel::gotoPlayingItem()
     view->scrollTo( view->currentIndex() );
 }
 
-void StandardPLPanel::handleExpansion( const QModelIndex &index )
+void StandardPLPanel::handleExpansion( const QModelIndexindex )
 {
-    if( model->isCurrent( index ) )
-        view->scrollTo( index, QAbstractItemView::EnsureVisible );
+    view->scrollTo( index, QAbstractItemView::EnsureVisible );
 }
 
 void StandardPLPanel::setCurrentRootId( int _new )
@@ -249,17 +239,20 @@ void StandardPLPanel::popupAdd()
     if( currentRootId == THEPL->p_local_category->i_id ||
         currentRootId == THEPL->p_local_onelevel->i_id )
     {
-        popup.addAction( qtr(I_PL_ADDF), THEDP, SLOT(PLAppendDialog()) );
+        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( MLAppendDialog() ) );
+        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() ) );
 }
@@ -287,7 +280,7 @@ void StandardPLPanel::popupSelectColumn( QPoint pos )
 }
 
 /* Search in the playlist */
-void StandardPLPanel::search( QString searchText )
+void StandardPLPanel::search( const QString& searchText )
 {
     model->search( searchText );
 }
@@ -305,8 +298,7 @@ void StandardPLPanel::doPopup( QModelIndex index, QPoint point )
 void StandardPLPanel::setRoot( int i_root_id )
 {
     QPL_LOCK;
-    playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id,
-                                                    pl_Locked );
+    playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id );
     assert( p_item );
     p_item = playlist_GetPreferredNode( THEPL, p_item );
     assert( p_item );