Commit bc778682 authored by Jakob Leben's avatar Jakob Leben

Qt: add a list view

parent 01de7da1
......@@ -30,12 +30,32 @@
class QPainter;
class PLModel;
class PlListViewItemDelegate : public QStyledItemDelegate
class AbstractPlViewItemDelegate : public QStyledItemDelegate
{
public:
AbstractPlViewItemDelegate( QWidget * parent = 0 ) : QStyledItemDelegate(parent) {}
QString getMeta( const QModelIndex & index, int meta ) const;
void paintPlayingItemBg( QPainter *painter, const QStyleOptionViewItem & option ) const;
QPixmap getArtPixmap( const QModelIndex & index, const QSize & size ) const;
};
class PlIconViewItemDelegate : public AbstractPlViewItemDelegate
{
Q_OBJECT
public:
PlListViewItemDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent) {}
PlIconViewItemDelegate(QWidget *parent = 0) : AbstractPlViewItemDelegate(parent) {}
void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
};
class PlListViewItemDelegate : public AbstractPlViewItemDelegate
{
Q_OBJECT
public:
PlListViewItemDelegate(QWidget *parent = 0) : AbstractPlViewItemDelegate(parent) {}
void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
......@@ -49,5 +69,13 @@ public:
PlIconView( PLModel *model, QWidget *parent = 0 );
};
class PlListView : public QListView
{
Q_OBJECT
public:
PlListView( PLModel *model, QWidget *parent = 0 );
};
#endif
......@@ -339,7 +339,12 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
QFont f; f.setBold( true ); return QVariant( f );
}
}
else if( role == Qt::BackgroundRole && isCurrent( index ) )
{
return QVariant( QBrush( Qt::gray ) );
}
else if( role == IsCurrentRole ) return QVariant( isCurrent( index ) );
return QVariant();
}
......@@ -532,7 +537,7 @@ PLItem * PLModel::findInner( PLItem *root, int i_id, bool b_input )
#undef CACHE
#undef ICACHE
int PLModel::columnToMeta( int _column ) const
int PLModel::columnToMeta( int _column )
{
int meta = 1;
int column = 0;
......@@ -546,7 +551,7 @@ int PLModel::columnToMeta( int _column ) const
return meta;
}
int PLModel::columnFromMeta( int meta_col ) const
int PLModel::columnFromMeta( int meta_col )
{
int meta = 1;
int column = 0;
......
......@@ -90,6 +90,8 @@ public:
QModelIndex currentIndex();
bool isCurrent( const QModelIndex &index ) const;
int itemId( const QModelIndex &index ) const;
static int columnFromMeta( int meta_column );
static int columnToMeta( int column );
/* Actions */
void popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
......@@ -147,8 +149,6 @@ private:
PLItem *findById( PLItem *, int );
PLItem *findByInput( PLItem *, int );
PLItem *findInner( PLItem *, int , bool );
int columnFromMeta( int meta_column ) const;
int columnToMeta( int column ) const;
bool canEdit() const;
PLItem *p_cached_item;
......
......@@ -73,6 +73,7 @@ static inline char * psz_column_meta( input_item_t *p_item, uint32_t i_column )
return input_item_GetTitleFbName( p_item );
case COLUMN_DURATION:
i_duration = input_item_GetDuration( p_item ) / 1000000;
if( i_duration == 0 ) return NULL;
secstotimestr( psz_duration, i_duration );
return strdup( psz_duration );
case COLUMN_ARTIST:
......
......@@ -52,6 +52,10 @@
#include "sorting.h"
static const QString viewNames[] = { qtr( "Detailed View" ),
qtr( "Icon View" ),
qtr( "List View" ) };
StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
intf_thread_t *_p_intf,
playlist_t *p_playlist,
......@@ -64,6 +68,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
iconView = NULL;
treeView = NULL;
listView = NULL;
model = new PLModel( p_playlist, p_intf, p_root, this );
currentRootId = -1;
......@@ -101,15 +106,13 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
QActionGroup *actionGroup = new QActionGroup( this );
treeViewAction = actionGroup->addAction( "Detailed view" );
treeViewAction->setCheckable( true );
viewSelectionMapper->setMapping( treeViewAction, TREE_VIEW );
CONNECT( treeViewAction, triggered(), viewSelectionMapper, map() );
iconViewAction = actionGroup->addAction( "Icon view" );
iconViewAction->setCheckable( true );
viewSelectionMapper->setMapping( iconViewAction, ICON_VIEW );
CONNECT( iconViewAction, triggered(), viewSelectionMapper, map() );
for( int i = 0; i < VIEW_COUNT; i++ )
{
viewActions[i] = actionGroup->addAction( viewNames[i] );
viewActions[i]->setCheckable( true );
viewSelectionMapper->setMapping( viewActions[i], i );
CONNECT( viewActions[i], triggered(), viewSelectionMapper, map() );
}
BUTTONACT( viewButton, cycleViews() );
QMenu *viewMenu = new QMenu( this );
......@@ -138,7 +141,12 @@ StandardPLPanel::~StandardPLPanel()
getSettings()->beginGroup("Playlist");
if( treeView )
getSettings()->setValue( "headerStateV2", treeView->header()->saveState() );
getSettings()->setValue( "view-mode", ( currentView == iconView ) ? ICON_VIEW : TREE_VIEW );
if( currentView == treeView )
getSettings()->setValue( "view-mode", TREE_VIEW );
else if( currentView == listView )
getSettings()->setValue( "view-mode", LIST_VIEW );
else if( currentView == iconView )
getSettings()->setValue( "view-mode", ICON_VIEW );
getSettings()->endGroup();
}
......@@ -287,6 +295,21 @@ void StandardPLPanel::createIconView()
layout->addWidget( iconView, 1, 0, 1, -1 );
}
void StandardPLPanel::createListView()
{
listView = new PlListView( model, this );
listView->setContextMenuPolicy( Qt::CustomContextMenu );
CONNECT( listView, customContextMenuRequested( const QPoint & ),
this, popupPlView( const QPoint & ) );
CONNECT( listView, activated( const QModelIndex & ),
this, activate( const QModelIndex & ) );
CONNECT( locationBar, invoked( const QModelIndex & ),
listView, setRootIndex( const QModelIndex & ) );
layout->addWidget( listView, 1, 0, 1, -1 );
}
void StandardPLPanel::createTreeView()
{
/* Create and configure the QTreeView */
......@@ -354,9 +377,10 @@ void StandardPLPanel::showView( int i_view )
createTreeView();
locationBar->setIndex( treeView->rootIndex() );
if( iconView ) iconView->hide();
if( listView ) listView->hide();
treeView->show();
currentView = treeView;
treeViewAction->setChecked( true );
viewActions[i_view]->setChecked( true );
break;
}
case ICON_VIEW:
......@@ -364,11 +388,31 @@ void StandardPLPanel::showView( int i_view )
if( iconView == NULL )
createIconView();
locationBar->setIndex( iconView->rootIndex() );
if( treeView ) treeView->hide();
if( listView ) {
listView->hide();
iconView->setRootIndex( listView->rootIndex() );
}
locationBar->setIndex( iconView->rootIndex() );
iconView->show();
currentView = iconView;
iconViewAction->setChecked( true );
viewActions[i_view]->setChecked( true );
break;
}
case LIST_VIEW:
{
if( listView == NULL )
createListView();
if( treeView ) treeView->hide();
if( iconView ) {
iconView->hide();
listView->setRootIndex( iconView->rootIndex() );
}
locationBar->setIndex( listView->rootIndex() );
listView->show();
currentView = listView;
viewActions[i_view]->setChecked( true );
break;
}
default:;
......@@ -380,6 +424,8 @@ void StandardPLPanel::cycleViews()
if( currentView == iconView )
showView( TREE_VIEW );
else if( currentView == treeView )
showView( LIST_VIEW );
else if( currentView == listView )
showView( ICON_VIEW );
else
assert( 0 );
......@@ -395,8 +441,8 @@ void StandardPLPanel::activate( const QModelIndex &index )
{
if( model->hasChildren( index ) )
{
if( currentView == iconView ) {
iconView->setRootIndex( index );
if( currentView == iconView || currentView == listView ) {
currentView->setRootIndex( index );
locationBar->setIndex( index );
}
}
......@@ -429,8 +475,8 @@ void StandardPLPanel::browseInto( input_item_t *p_input )
playlist_Unlock( THEPL );
if( currentView == iconView ) {
iconView->setRootIndex( index );
if( currentView == iconView || currentView == listView ) {
currentView->setRootIndex( index );
locationBar->setIndex( index );
}
else
......
......@@ -46,6 +46,7 @@ class QPushButton;
class QKeyEvent;
class QWheelEvent;
class PlIconView;
class PlListView;
class LocationBar;
class StandardPLPanel: public QWidget
......@@ -64,6 +65,14 @@ protected:
PLModel *model;
private:
enum {
TREE_VIEW = 0,
ICON_VIEW,
LIST_VIEW,
VIEW_COUNT
};
intf_thread_t *p_intf;
QWidget *parent;
......@@ -74,8 +83,10 @@ private:
QTreeView *treeView;
PlIconView *iconView;
PlListView *listView;
QAbstractItemView *currentView;
QAction *viewActions[ VIEW_COUNT ];
QAction *iconViewAction, *treeViewAction;
int currentRootId;
QSignalMapper *selectColumnsSigMapper;
......@@ -83,14 +94,9 @@ private:
int last_activated_id;
enum {
TREE_VIEW = 0,
ICON_VIEW,
COVER_VIEW,
};
void createTreeView();
void createIconView();
void createListView();
public slots:
virtual void setRoot( playlist_item_t * );
......
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