]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/playlist/standardpanel.cpp
Qt4 - Playlist: AutoScroll the playlist.
[vlc] / modules / gui / qt4 / components / playlist / standardpanel.cpp
index 8f306ebb4ce4b0b97d4cdb6af75d1007b851b569..1c3d93d02a26b7f13c4294d1eeaff4f320a43265 100644 (file)
  * 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 <vlc_intf_strings.h>
+
 #include <QTreeView>
 #include <QPushButton>
 #include <QHBoxLayout>
 #include <QVBoxLayout>
 #include <QHeaderView>
 #include <QKeyEvent>
-#include "qt4.hpp"
-#include <assert.h>
 #include <QModelIndexList>
+#include <QToolBar>
+#include <QLabel>
+#include <QSpacerItem>
+#include <QMenu>
 
-#include "util/views.hpp"
+#include <assert.h>
 
-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 )
 {
-    model = new PLModel( p_playlist, p_root, -1, this );
+    model = new PLModel( p_playlist, p_intf, p_root, -1, this );
     view = new QVLCTreeView( 0 );
     view->setModel(model);
-    view->header()->resizeSection( 0, 300 );
-    view->setSelectionMode( QAbstractItemView::ExtendedSelection );
+    view->setIconSize( QSize(20,20) );
+    view->setAlternatingRowColors( true );
+    view->header()->resizeSection( 0, 230 );
+    view->header()->resizeSection( 1, 170 );
+    view->header()->setSortIndicatorShown( true );
+    view->header()->setClickable( true );
 
-    connect( view, SIGNAL( activated( const QModelIndex& ) ), model,
-             SLOT( activateItem( const QModelIndex& ) ) );
+    view->setSelectionMode( QAbstractItemView::ExtendedSelection );
+    view->setDragEnabled( true );
+    view->setAcceptDrops( true );
+    view->setDropIndicatorShown( true );
+    view->setAutoScroll( true );
 
-    connect( view, SIGNAL( rightClicked( QModelIndex , QPoint ) ),
-             this, SLOT( doPopup( QModelIndex, QPoint ) ) );
+    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( 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 );
 
     QHBoxLayout *buttons = new QHBoxLayout();
-    repeatButton = new QPushButton( this );
-    buttons->addWidget( repeatButton );
-    randomButton = new QPushButton( this );
-    buttons->addWidget( randomButton );
 
-    if( model->hasRandom() ) randomButton->setText( qtr( "Random" ) );
-    else randomButton->setText( qtr( "No random" ) );
+    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( "R1" ) );
+    else if( model->hasLoop() ) repeatButton->setText( qtr( "RA" ) );
+    else repeatButton->setText( qtr( "NR" ) );
+    BUTTONACT( repeatButton, toggleRepeat() );
 
-    if( model->hasRepeat() ) repeatButton->setText( qtr( "Repeat One" ) );
-    else if( model->hasLoop() ) repeatButton->setText( qtr( "Repeat All" ) );
-    else repeatButton->setText( qtr( "No Repeat" ) );
+    randomButton = new QPushButton( 0 ); buttons->addWidget( randomButton );
+    if( model->hasRandom() ) randomButton->setText( qtr( " RND" ) );
+    else randomButton->setText( qtr( "NRND" ) );
+    BUTTONACT( randomButton, toggleRandom() );
 
-    connect( repeatButton, SIGNAL( clicked() ), this, SLOT( toggleRepeat() ));
-    connect( randomButton, SIGNAL( clicked() ), this, SLOT( toggleRandom() ));
+    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 );
+    buttons->addWidget( clear );
+    BUTTONACT( clear, clearFilter() );
 
     layout->addWidget( view );
     layout->addLayout( buttons );
+//    layout->addWidget( bar );
     setLayout( layout );
 }
 
@@ -85,17 +120,17 @@ void StandardPLPanel::toggleRepeat()
     if( model->hasRepeat() )
     {
         model->setRepeat( false ); model->setLoop( true );
-        repeatButton->setText( qtr( "Repeat All" ) );
+        repeatButton->setText( qtr(I_PL_LOOP) );
     }
     else if( model->hasLoop() )
     {
         model->setRepeat( false ) ; model->setLoop( false );
-        repeatButton->setText( qtr( "No Repeat" ) );
+        repeatButton->setText( qtr(I_PL_NOREPEAT) );
     }
     else
     {
         model->setRepeat( true );
-        repeatButton->setText( qtr( "Repeat One" ) );
+        repeatButton->setText( qtr(I_PL_REPEAT) );
     }
 }
 
@@ -103,7 +138,7 @@ void StandardPLPanel::toggleRandom()
 {
     bool prev = model->hasRandom();
     model->setRandom( !prev );
-    randomButton->setText( prev ? qtr( "No Random" ) : qtr( "Random" ) );
+    randomButton->setText( prev ? qtr(I_PL_NORANDOM) : qtr(I_PL_RANDOM) );
 }
 
 void StandardPLPanel::handleExpansion( const QModelIndex &index )
@@ -120,9 +155,58 @@ 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::add()
+{
+    QMenu *popup = new QMenu();
+    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->popup( QCursor::pos() );
+}
+
+void StandardPLPanel::clearFilter()
+{
+    searchLine->setText( "" );
+}
+
+void StandardPLPanel::search( QString searchText )
+{
+    model->search( 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 );
@@ -130,11 +214,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() )