Commit 0fb61d20 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

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.
parent 935cc5d2
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include <QWidget> #include <QWidget>
#include <QString> #include <QString>
#include <vlc_playlist.h>
class QSignalMapper; class QSignalMapper;
class QTreeView; class QTreeView;
class PLModel; class PLModel;
...@@ -56,6 +58,7 @@ protected: ...@@ -56,6 +58,7 @@ protected:
QFrame *parent; QFrame *parent;
public slots: public slots:
virtual void setRoot( int ) = 0; virtual void setRoot( int ) = 0;
virtual void setRoot( playlist_item_t * ) = 0;
}; };
...@@ -79,6 +82,7 @@ private: ...@@ -79,6 +82,7 @@ private:
public slots: public slots:
void removeItem( int ); void removeItem( int );
virtual void setRoot( int ); virtual void setRoot( int );
virtual void setRoot( playlist_item_t * );
private slots: private slots:
void deleteSelection(); void deleteSelection();
void handleExpansion( const QModelIndex& ); void handleExpansion( const QModelIndex& );
...@@ -87,7 +91,7 @@ private slots: ...@@ -87,7 +91,7 @@ private slots:
void gotoPlayingItem(); void gotoPlayingItem();
void doPopup( QModelIndex index, QPoint point ); void doPopup( QModelIndex index, QPoint point );
void search( const QString& searchText ); void search( const QString& searchText );
void setCurrentRootId( int ); void setCurrentRootId( playlist_item_t * );
void popupAdd(); void popupAdd();
void popupSelectColumn( QPoint ); void popupSelectColumn( QPoint );
void toggleColumnShown( int ); void toggleColumnShown( int );
......
...@@ -77,20 +77,21 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i ) ...@@ -77,20 +77,21 @@ PlaylistWidget::PlaylistWidget( intf_thread_t *_p_i ) : p_intf ( _p_i )
rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root ); rightPanel = new StandardPLPanel( this, p_intf, THEPL, p_root );
/* Connect the activation of the selector to a redefining of the PL */ /* 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 /* Connect the activated() to the rootChanged() signal
This will be used by StandardPLPanel to setCurrentRootId, that will This will be used by StandardPLPanel to setCurrentRootId, that will
change the label of the addButton */ change the label of the addButton */
connect( selector, SIGNAL( activated( int ) ), connect( selector, SIGNAL( activated( playlist_item_t * ) ),
this, SIGNAL( rootChanged( int ) ) ); this, SIGNAL( rootChanged( playlist_item_t * ) ) );
/* Forward removal requests from the selector to the main panel */ /* Forward removal requests from the selector to the main panel */
CONNECT( qobject_cast<PLSelector *>( selector )->model, /* CONNECT( qobject_cast<PLSelector *>( selector )->model,
shouldRemove( int ), shouldRemove( int ),
qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) ); qobject_cast<StandardPLPanel *>( rightPanel ), removeItem( int ) ); */
emit rootChanged( p_root->i_id ); emit rootChanged( p_root );
/* Add the two sides of the QSplitter */ /* Add the two sides of the QSplitter */
addWidget( leftW ); addWidget( leftW );
......
...@@ -62,7 +62,7 @@ protected: ...@@ -62,7 +62,7 @@ protected:
virtual void closeEvent( QCloseEvent * ); virtual void closeEvent( QCloseEvent * );
signals: signals:
void rootChanged( int ); void rootChanged( playlist_item_t *);
}; };
class ArtLabel : public CoverArtLabel class ArtLabel : public CoverArtLabel
......
...@@ -25,30 +25,36 @@ ...@@ -25,30 +25,36 @@
# include "config.h" # include "config.h"
#endif #endif
#include <assert.h>
#include "components/playlist/selector.hpp" #include "components/playlist/selector.hpp"
#include "qt4.hpp" #include "qt4.hpp"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHeaderView> #include <QHeaderView>
#include <QTreeView> #include <QTreeWidget>
#include <vlc_playlist.h>
PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_intf(_p_intf) 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 ); // model = new PLModel( THEPL, p_intf, THEPL->p_root_category, 1, this );
view = new QTreeView( 0 ); view = new QTreeWidget;
view->setIconSize( QSize( 24,24 ) ); view->setIconSize( QSize( 24,24 ) );
view->setAlternatingRowColors( true ); // view->setAlternatingRowColors( true );
view->setIndentation( 0 ); view->setIndentation( 0 );
view->header()->hide(); view->header()->hide();
view->setModel( model ); // view->setModel( model );
view->setAcceptDrops(true); view->setAcceptDrops(true);
view->setDropIndicatorShown(true); view->setDropIndicatorShown(true);
CONNECT( view, activated( const QModelIndex& ),
this, setSource( const QModelIndex& ) ); createItems();
CONNECT( view, clicked( const QModelIndex& ), CONNECT( view, itemActivated( QTreeWidgetItem *, int ),
this, setSource( const QModelIndex& ) ); this, setSource( QTreeWidgetItem *) );
CONNECT( view, itemClicked( QTreeWidgetItem *, int ),
this, setSource( QTreeWidgetItem *) );
QVBoxLayout *layout = new QVBoxLayout(); QVBoxLayout *layout = new QVBoxLayout();
layout->setSpacing( 0 ); layout->setMargin( 0 ); layout->setSpacing( 0 ); layout->setMargin( 0 );
...@@ -56,15 +62,38 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_i ...@@ -56,15 +62,38 @@ PLSelector::PLSelector( QWidget *p, intf_thread_t *_p_intf ) : QWidget( p ), p_i
setLayout( layout ); setLayout( layout );
/* select the first item */ /* 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 ) if( item )
emit activated( model->itemId( index ) ); {
playlist_item_t *pl_item =
item->data( 0, Qt::UserRole ).value<playlist_item_t *>();
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() PLSelector::~PLSelector()
{ {
} }
...@@ -31,10 +31,12 @@ ...@@ -31,10 +31,12 @@
#include "components/playlist/playlist_model.hpp" #include "components/playlist/playlist_model.hpp"
#include <QWidget> #include <QWidget>
#include <QTreeWidgetItem>
class QTreeView; class QTreeWidget;
class PlaylistWidget; class PlaylistWidget;
Q_DECLARE_METATYPE( playlist_item_t *);
class PLSelector: public QWidget class PLSelector: public QWidget
{ {
Q_OBJECT; Q_OBJECT;
...@@ -46,11 +48,13 @@ protected: ...@@ -46,11 +48,13 @@ protected:
friend class PlaylistWidget; friend class PlaylistWidget;
private: private:
intf_thread_t *p_intf; intf_thread_t *p_intf;
QTreeView *view; QTreeWidget *view;
void createItems();
private slots: private slots:
void setSource( const QModelIndex& ); void setSource( QTreeWidgetItem *item );
signals: signals:
void activated( int ); void activated( int );
void activated( playlist_item_t * );
void shouldRemove( int ); void shouldRemove( int );
}; };
......
...@@ -107,7 +107,8 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -107,7 +107,8 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
this, handleExpansion( const QModelIndex& ) ); this, handleExpansion( const QModelIndex& ) );
currentRootId = -1; currentRootId = -1;
CONNECT( parent, rootChanged( int ), this, setCurrentRootId( int ) ); CONNECT( parent, rootChanged( playlist_item_t * ),
this, setCurrentRootId( playlist_item_t * ) );
/* Buttons configuration */ /* Buttons configuration */
QHBoxLayout *buttons = new QHBoxLayout; QHBoxLayout *buttons = new QHBoxLayout;
...@@ -219,19 +220,16 @@ void StandardPLPanel::handleExpansion( const QModelIndex& index ) ...@@ -219,19 +220,16 @@ void StandardPLPanel::handleExpansion( const QModelIndex& index )
view->scrollTo( index ); view->scrollTo( index );
} }
void StandardPLPanel::setCurrentRootId( int _new ) void StandardPLPanel::setCurrentRootId( playlist_item_t *p_item )
{ {
currentRootId = _new; if( p_item == THEPL->p_local_category ||
if( currentRootId == THEPL->p_local_category->i_id || p_item == THEPL->p_local_onelevel )
currentRootId == THEPL->p_local_onelevel->i_id )
{ {
addButton->setEnabled( true ); addButton->setEnabled( true );
addButton->setToolTip( qtr(I_PL_ADDPL) ); addButton->setToolTip( qtr(I_PL_ADDPL) );
} }
else if( ( THEPL->p_ml_category && else if( ( THEPL->p_ml_category && p_item == THEPL->p_ml_category) ||
currentRootId == THEPL->p_ml_category->i_id ) || ( THEPL->p_ml_onelevel && p_item == THEPL->p_ml_onelevel ) )
( THEPL->p_ml_onelevel &&
currentRootId == THEPL->p_ml_onelevel->i_id ) )
{ {
addButton->setEnabled( true ); addButton->setEnabled( true );
addButton->setToolTip( qtr(I_PL_ADDML) ); addButton->setToolTip( qtr(I_PL_ADDML) );
...@@ -310,6 +308,14 @@ void StandardPLPanel::setRoot( int i_root_id ) ...@@ -310,6 +308,14 @@ 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 );
assert( p_item ); assert( p_item );
p_item = playlist_GetPreferredNode( THEPL, 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 ); assert( p_item );
QPL_UNLOCK; QPL_UNLOCK;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment