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 @@
#include <QWidget>
#include <QString>
#include <vlc_playlist.h>
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 );
......
......@@ -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<PLSelector *>( selector )->model,
/* CONNECT( qobject_cast<PLSelector *>( selector )->model,
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 */
addWidget( leftW );
......
......@@ -62,7 +62,7 @@ protected:
virtual void closeEvent( QCloseEvent * );
signals:
void rootChanged( int );
void rootChanged( playlist_item_t *);
};
class ArtLabel : public CoverArtLabel
......
......@@ -25,30 +25,36 @@
# include "config.h"
#endif
#include <assert.h>
#include "components/playlist/selector.hpp"
#include "qt4.hpp"
#include <QVBoxLayout>
#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)
{
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<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()
{
}
......@@ -31,10 +31,12 @@
#include "components/playlist/playlist_model.hpp"
#include <QWidget>
#include <QTreeWidgetItem>
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 );
};
......
......@@ -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;
......
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