Commit 64646d3c authored by Srikanth Raju's avatar Srikanth Raju

Qt/ML: Move more functions into VLCModel

doDelete() should be virtual
getMeta() and getArtPixmap() helpers in VLCModel
parent 7b9f7900
...@@ -94,7 +94,7 @@ void MLModel::clear() ...@@ -94,7 +94,7 @@ void MLModel::clear()
QModelIndex MLModel::index( int row, int column, QModelIndex MLModel::index( int row, int column,
const QModelIndex &parent ) const const QModelIndex &parent ) const
{ {
if( parent.isValid() ) if( parent.isValid() || row >= items.count() )
return QModelIndex(); return QModelIndex();
else else
{ {
...@@ -229,10 +229,12 @@ void MLModel::remove( MLItem *item ) ...@@ -229,10 +229,12 @@ void MLModel::remove( MLItem *item )
remove( createIndex( row, 0 ) ); remove( createIndex( row, 0 ) );
} }
void MLModel::remove( QModelIndexList list ) void MLModel::doDelete( QModelIndexList list )
{ {
for (int i = 0; i < list.size(); ++i) { for (int i = 0; i < list.size(); ++i)
remove( list.at(i) ); {
int id = getId( list.at(i) );
ml_DeleteSimple( p_ml, id );
} }
} }
...@@ -514,9 +516,9 @@ bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QMode ...@@ -514,9 +516,9 @@ bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QMode
QIcon addIcon( ":/buttons/playlist/playlist_add" ); QIcon addIcon( ":/buttons/playlist/playlist_add" );
menu.addSeparator(); menu.addSeparator();
menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) ); //menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) ); //menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) ); //menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );
if( index.isValid() ) if( index.isValid() )
{ {
...@@ -531,15 +533,14 @@ bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QMode ...@@ -531,15 +533,14 @@ bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QMode
else return false; else return false;
} }
void MLModel::popupPlay()
void MLModel::popupDel()
{ {
remove( current_selection ); play( current_index );
} }
void MLModel::popupPlay() void MLModel::popupDel()
{ {
play( current_index ); doDelete( current_selection );
} }
void MLModel::popupInfo() void MLModel::popupInfo()
......
...@@ -94,8 +94,8 @@ public: ...@@ -94,8 +94,8 @@ public:
int insertResultArray( vlc_array_t *p_result_array, int row = -1, int insertResultArray( vlc_array_t *p_result_array, int row = -1,
bool bSignal = true ); bool bSignal = true );
virtual void doDelete( QModelIndexList list );
void remove( MLItem *item ); void remove( MLItem *item );
void remove( QModelIndexList list );
void remove( QModelIndex idx ); void remove( QModelIndex idx );
void clear(); void clear();
......
...@@ -584,62 +584,6 @@ bool PLModel::canEdit() const ...@@ -584,62 +584,6 @@ bool PLModel::canEdit() const
); );
} }
QString PLModel::getMeta( const QModelIndex & index, int meta )
{
return index.model()->index( index.row(),
columnFromMeta( meta ),
index.parent() )
.data().toString();
}
QPixmap PLModel::getArtPixmap( const QModelIndex & index, const QSize & size )
{
PLItem *item = static_cast<PLItem*>( index.internalPointer() );
assert( item );
if( item == NULL )
return NULL;
QString artUrl = InputManager::decodeArtURL( item->inputItem() );
/* If empty, take one of the children art URL */
if( artUrl.isEmpty() )
{
for( int i = 0; i < item->childCount(); i++ )
{
artUrl = InputManager::decodeArtURL( item->child( i )->inputItem() );
if( !artUrl.isEmpty() )
break;
}
}
QPixmap artPix;
QString key = artUrl + QString("%1%2").arg(size.width()).arg(size.height());
/* Lookup in the QPixmapCache */
if( !QPixmapCache::find( key, artPix ))
{
if( artUrl.isEmpty() || !artPix.load( artUrl ) )
{
key = QString("noart%1%2").arg(size.width()).arg(size.height());
if( !QPixmapCache::find( key, artPix ) )
{
artPix = QPixmap( ":/noart" ).scaled( size,
Qt::KeepAspectRatio,
Qt::SmoothTransformation );
QPixmapCache::insert( key, artPix );
}
}
else
{
artPix = artPix.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
QPixmapCache::insert( key, artPix );
}
}
return artPix;
}
/************************* Updates handling *****************************/ /************************* Updates handling *****************************/
/**** Events processing ****/ /**** Events processing ****/
......
...@@ -86,12 +86,9 @@ public: ...@@ -86,12 +86,9 @@ public:
bool isCurrent( const QModelIndex &index ) const; bool isCurrent( const QModelIndex &index ) const;
int itemId( const QModelIndex &index ) const; int itemId( const QModelIndex &index ) const;
static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
static QString getMeta( const QModelIndex & index, int meta );
/* Actions */ /* Actions */
virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list ); virtual bool popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list );
void doDelete( QModelIndexList selected ); virtual void doDelete( QModelIndexList selected );
void search( const QString& search_text, const QModelIndex & root, bool b_recursive ); void search( const QString& search_text, const QModelIndex & root, bool b_recursive );
void sort( const int column, Qt::SortOrder order ); void sort( const int column, Qt::SortOrder order );
void sort( const int i_root_id, const int column, Qt::SortOrder order ); void sort( const int i_root_id, const int column, Qt::SortOrder order );
......
...@@ -74,8 +74,8 @@ void AbstractPlViewItemDelegate::paintBackground( ...@@ -74,8 +74,8 @@ void AbstractPlViewItemDelegate::paintBackground(
void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{ {
QString title = PLModel::getMeta( index, COLUMN_TITLE ); QString title = VLCModel::getMeta( index, COLUMN_TITLE );
QString artist = PLModel::getMeta( index, COLUMN_ARTIST ); QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
QFont font( index.data( Qt::FontRole ).value<QFont>() ); QFont font( index.data( Qt::FontRole ).value<QFont>() );
painter->setFont( font ); painter->setFont( font );
...@@ -85,7 +85,7 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -85,7 +85,7 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
int art_width = averagewidth * ICON_SCALER; int art_width = averagewidth * ICON_SCALER;
int art_height = averagewidth * ICON_SCALER; int art_height = averagewidth * ICON_SCALER;
QPixmap artPix = PLModel::getArtPixmap( index, QSize( art_width, art_height) ); QPixmap artPix = VLCModel::getArtPixmap( index, QSize( art_width, art_height) );
paintBackground( painter, option, index ); paintBackground( painter, option, index );
...@@ -177,13 +177,13 @@ QSize PlIconViewItemDelegate::sizeHint ( const QStyleOptionViewItem & option, co ...@@ -177,13 +177,13 @@ QSize PlIconViewItemDelegate::sizeHint ( const QStyleOptionViewItem & option, co
void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{ {
QString title = PLModel::getMeta( index, COLUMN_TITLE ); QString title = VLCModel::getMeta( index, COLUMN_TITLE );
QString duration = PLModel::getMeta( index, COLUMN_DURATION ); QString duration = VLCModel::getMeta( index, COLUMN_DURATION );
if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration ); if( !duration.isEmpty() ) title += QString(" [%1]").arg( duration );
QString artist = PLModel::getMeta( index, COLUMN_ARTIST ); QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
QString album = PLModel::getMeta( index, COLUMN_ALBUM ); QString album = VLCModel::getMeta( index, COLUMN_ALBUM );
QString trackNum = PLModel::getMeta( index, COLUMN_TRACK_NUMBER ); QString trackNum = VLCModel::getMeta( index, COLUMN_TRACK_NUMBER );
QString artistAlbum = artist; QString artistAlbum = artist;
if( !album.isEmpty() ) if( !album.isEmpty() )
{ {
...@@ -192,7 +192,7 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -192,7 +192,7 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
if( !trackNum.isEmpty() ) artistAlbum += QString( " [#%1]" ).arg( trackNum ); if( !trackNum.isEmpty() ) artistAlbum += QString( " [#%1]" ).arg( trackNum );
} }
QPixmap artPix = PLModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) ); QPixmap artPix = VLCModel::getArtPixmap( index, QSize( LISTVIEW_ART_SIZE, LISTVIEW_ART_SIZE ) );
//Draw selection rectangle and current playing item indication //Draw selection rectangle and current playing item indication
paintBackground( painter, option, index ); paintBackground( painter, option, index );
......
...@@ -31,3 +31,43 @@ VLCModel::VLCModel( intf_thread_t *_p_intf, QObject *parent ) ...@@ -31,3 +31,43 @@ VLCModel::VLCModel( intf_thread_t *_p_intf, QObject *parent )
VLCModel::~VLCModel() VLCModel::~VLCModel()
{ {
} }
QString VLCModel::getMeta( const QModelIndex & index, int meta )
{
return index.model()->index( index.row(), columnFromMeta( meta ), index.parent() ).
data().toString();
}
QPixmap VLCModel::getArtPixmap( const QModelIndex & index, const QSize & size )
{
QString artUrl;
artUrl = index.model()->index( index.row(),
COLUMN_COVER,
index.parent() )
.data().toString();
QPixmap artPix;
QString key = artUrl + QString("%1%2").arg(size.width()).arg(size.height());
if( !QPixmapCache::find( key, artPix ))
{
if( artUrl.isEmpty() || !artPix.load( artUrl ) )
{
key = QString("noart%1%2").arg(size.width()).arg(size.height());
if( !QPixmapCache::find( key, artPix ) )
{
artPix = QPixmap( ":/noart" ).scaled( size,
Qt::KeepAspectRatio,
Qt::SmoothTransformation );
QPixmapCache::insert( key, artPix );
}
}
else
{
artPix = artPix.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
QPixmapCache::insert( key, artPix );
}
}
return artPix;
}
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include <vlc_input.h> #include <vlc_input.h>
#include <QModelIndex> #include <QModelIndex>
#include <QPixmapCache>
#include <QSize>
#include <QAbstractItemModel> #include <QAbstractItemModel>
...@@ -52,7 +54,10 @@ public: ...@@ -52,7 +54,10 @@ public:
virtual QModelIndex currentIndex() const = 0; virtual QModelIndex currentIndex() const = 0;
virtual bool popup( const QModelIndex & index, virtual bool popup( const QModelIndex & index,
const QPoint &point, const QModelIndexList &list ) = 0; const QPoint &point, const QModelIndexList &list ) = 0;
virtual void doDelete( QModelIndexList ) = 0;
virtual ~VLCModel(); virtual ~VLCModel();
static QString getMeta( const QModelIndex & index, int meta );
static QPixmap getArtPixmap( const QModelIndex & index, const QSize & size );
public slots: public slots:
virtual void activateItem( const QModelIndex &index ) = 0; virtual void activateItem( const QModelIndex &index ) = 0;
......
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