From: Jean-Baptiste Kempf Date: Tue, 1 Sep 2009 22:46:34 +0000 (+0200) Subject: Qt4: move the selector from View/Model to QTreeWidget X-Git-Tag: 1.1.0-ff~3495 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=0fb61d20ed442d49e8e98f15ff5a5fd44633792f;p=vlc Qt4: move the selector from View/Model to QTreeWidget The idea behind this is to simplify the playlist_model and have a better SD control. --- diff --git a/modules/gui/qt4/components/playlist/panels.hpp b/modules/gui/qt4/components/playlist/panels.hpp index 4654b09e3f..d949c40ad2 100644 --- a/modules/gui/qt4/components/playlist/panels.hpp +++ b/modules/gui/qt4/components/playlist/panels.hpp @@ -35,6 +35,8 @@ #include #include +#include + class QSignalMapper; class QTreeView; class PLModel; @@ -56,6 +58,7 @@ protected: QFrame *parent; public slots: virtual void setRoot( int ) = 0; + virtual void setRoot( playlist_item_t * ) = 0; }; @@ -79,6 +82,7 @@ private: public slots: void removeItem( int ); virtual void setRoot( int ); + virtual void setRoot( playlist_item_t * ); private slots: void deleteSelection(); void handleExpansion( const QModelIndex& ); @@ -87,7 +91,7 @@ private slots: void gotoPlayingItem(); void doPopup( QModelIndex index, QPoint point ); void search( const QString& searchText ); - void setCurrentRootId( int ); + void setCurrentRootId( playlist_item_t * ); void popupAdd(); void popupSelectColumn( QPoint ); void toggleColumnShown( int ); diff --git a/modules/gui/qt4/components/playlist/playlist.cpp b/modules/gui/qt4/components/playlist/playlist.cpp index 4ae5a301f8..7851073a63 100644 --- a/modules/gui/qt4/components/playlist/playlist.cpp +++ b/modules/gui/qt4/components/playlist/playlist.cpp @@ -77,20 +77,21 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i ) rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root ); /* Connect the activation of the selector to a redefining of the PL */ - CONNECT( selector, activated( int ), rightPanel, setRoot( int ) ); + CONNECT( selector, activated( playlist_item_t * ), + rightPanel, setRoot( playlist_item_t * ) ); /* Connect the activated() to the rootChanged() signal This will be used by StandardPLPanel to setCurrentRootId, that will change the label of the addButton */ - connect( selector, SIGNAL( activated( int ) ), - this, SIGNAL( rootChanged( int ) ) ); + connect( selector, SIGNAL( activated( playlist_item_t * ) ), + this, SIGNAL( rootChanged( playlist_item_t * ) ) ); /* Forward removal requests from the selector to the main panel */ - CONNECT( qobject_cast( selector )->model, +/* CONNECT( qobject_cast( selector )->model, shouldRemove( int ), - qobject_cast( rightPanel ), removeItem( int ) ); + qobject_cast( rightPanel ), removeItem( int ) ); */ - emit rootChanged( p_root->i_id ); + emit rootChanged( p_root ); /* Add the two sides of the QSplitter */ addWidget( leftW ); diff --git a/modules/gui/qt4/components/playlist/playlist.hpp b/modules/gui/qt4/components/playlist/playlist.hpp index ee3dad65dd..38270e6749 100644 --- a/modules/gui/qt4/components/playlist/playlist.hpp +++ b/modules/gui/qt4/components/playlist/playlist.hpp @@ -62,7 +62,7 @@ protected: virtual void closeEvent( QCloseEvent * ); signals: - void rootChanged( int ); + void rootChanged( playlist_item_t *); }; class ArtLabel : public CoverArtLabel diff --git a/modules/gui/qt4/components/playlist/selector.cpp b/modules/gui/qt4/components/playlist/selector.cpp index 22cad94f6b..40632214dd 100644 --- a/modules/gui/qt4/components/playlist/selector.cpp +++ b/modules/gui/qt4/components/playlist/selector.cpp @@ -25,30 +25,36 @@ # include "config.h" #endif +#include + #include "components/playlist/selector.hpp" #include "qt4.hpp" #include #include -#include +#include + +#include PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_intf(_p_intf) { - model = new PLModel( THEPL, p_intf, THEPL->p_root_category, 1, this ); - view = new QTreeView( 0 ); +// model = new PLModel( THEPL, p_intf, THEPL->p_root_category, 1, this ); + view = new QTreeWidget; view->setIconSize( QSize( 24,24 ) ); - view->setAlternatingRowColors( true ); +// view->setAlternatingRowColors( true ); view->setIndentation( 0 ); view->header()->hide(); - view->setModel( model ); +// view->setModel( model ); view->setAcceptDrops(true); view->setDropIndicatorShown(true); - CONNECT( view, activated( const QModelIndex& ), - this, setSource( const QModelIndex& ) ); - CONNECT( view, clicked( const QModelIndex& ), - this, setSource( const QModelIndex& ) ); + + createItems(); + CONNECT( view, itemActivated( QTreeWidgetItem *, int ), + this, setSource( QTreeWidgetItem *) ); + CONNECT( view, itemClicked( QTreeWidgetItem *, int ), + this, setSource( QTreeWidgetItem *) ); QVBoxLayout *layout = new QVBoxLayout(); layout->setSpacing( 0 ); layout->setMargin( 0 ); @@ -56,15 +62,38 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_i setLayout( layout ); /* select the first item */ - view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) ); +// view->setCurrentIndex( model->index( 0, 0, QModelIndex() ) ); } -void PLSelector::setSource( const QModelIndex &index ) +void PLSelector::setSource( QTreeWidgetItem *item ) { - if( model ) - emit activated( model->itemId( index ) ); + if( item ) + { + playlist_item_t *pl_item = + item->data( 0, Qt::UserRole ).value(); + emit activated( pl_item ); + } } +void PLSelector::createItems() +{ + assert( view ); + QTreeWidgetItem *pl = new QTreeWidgetItem( view ); + pl->setText( 0, qtr( "Playlist" ) ); + pl->setData( 0, Qt::UserRole, QVariant::fromValue( THEPL->p_local_category ) ); +/* QTreeWidgetItem *empty = new QTreeWidgetItem( view ); + empty->setFlags(Qt::NoItemFlags); +*/ + QTreeWidgetItem *lib = new QTreeWidgetItem( view ); + lib->setText( 0, qtr( "Library" ) ); + lib->setData( 0, Qt::UserRole, QVariant::fromValue( THEPL->p_ml_category ) ); +/* + QTreeWidgetItem *empty2 = new QTreeWidgetItem( view ); + empty2->setFlags(Qt::NoItemFlags);*/ + + + +} PLSelector::~PLSelector() { } diff --git a/modules/gui/qt4/components/playlist/selector.hpp b/modules/gui/qt4/components/playlist/selector.hpp index 63a514e51a..f496dd9dff 100644 --- a/modules/gui/qt4/components/playlist/selector.hpp +++ b/modules/gui/qt4/components/playlist/selector.hpp @@ -31,10 +31,12 @@ #include "components/playlist/playlist_model.hpp" #include +#include -class QTreeView; +class QTreeWidget; class PlaylistWidget; +Q_DECLARE_METATYPE( playlist_item_t *); class PLSelector: public QWidget { Q_OBJECT; @@ -46,11 +48,13 @@ protected: friend class PlaylistWidget; private: intf_thread_t *p_intf; - QTreeView *view; + QTreeWidget *view; + void createItems(); private slots: - void setSource( const QModelIndex& ); + void setSource( QTreeWidgetItem *item ); signals: void activated( int ); + void activated( playlist_item_t * ); void shouldRemove( int ); }; diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp index d7cabd4a12..5ecaf301a8 100644 --- a/modules/gui/qt4/components/playlist/standardpanel.cpp +++ b/modules/gui/qt4/components/playlist/standardpanel.cpp @@ -107,7 +107,8 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, this, handleExpansion( const QModelIndex& ) ); currentRootId = -1; - CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) ); + CONNECT( parent, rootChanged( playlist_item_t * ), + this, setCurrentRootId( playlist_item_t * ) ); /* Buttons configuration */ QHBoxLayout *buttons = new QHBoxLayout; @@ -219,19 +220,16 @@ void StandardPLPanel::handleExpansion( const QModelIndex& index ) view->scrollTo( index ); } -void StandardPLPanel::setCurrentRootId( int _new ) +void StandardPLPanel::setCurrentRootId( playlist_item_t *p_item ) { - currentRootId = _new; - if( currentRootId == THEPL->p_local_category->i_id || - currentRootId == THEPL->p_local_onelevel->i_id ) + if( p_item == THEPL->p_local_category || + p_item == THEPL->p_local_onelevel ) { 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 ) ) + else if( ( THEPL->p_ml_category && p_item == THEPL->p_ml_category) || + ( THEPL->p_ml_onelevel && p_item == THEPL->p_ml_onelevel ) ) { addButton->setEnabled( true ); addButton->setToolTip( qtr(I_PL_ADDML) ); @@ -310,6 +308,14 @@ void StandardPLPanel::setRoot( int i_root_id ) playlist_item_t *p_item = playlist_ItemGetById( THEPL, i_root_id ); assert( p_item ); p_item = playlist_GetPreferredNode( THEPL, p_item ); + setRoot( p_item ); + QPL_UNLOCK; +} + +void StandardPLPanel::setRoot( playlist_item_t *p_item ) +{ + QPL_LOCK; + p_item = playlist_GetPreferredNode( THEPL, p_item ); assert( p_item ); QPL_UNLOCK;