mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-22 05:33:32 +02:00
Implement track count for ScriptCollections.
This commit is contained in:
@@ -108,6 +108,13 @@ source_ptr& Collection::source() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
Collection::trackCount() const
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Collection::addPlaylist( const Tomahawk::playlist_ptr& p )
|
Collection::addPlaylist( const Tomahawk::playlist_ptr& p )
|
||||||
{
|
{
|
||||||
|
@@ -98,6 +98,8 @@ public:
|
|||||||
const source_ptr& source() const;
|
const source_ptr& source() const;
|
||||||
unsigned int lastmodified() const { return m_lastmodified; }
|
unsigned int lastmodified() const { return m_lastmodified; }
|
||||||
|
|
||||||
|
virtual int trackCount() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void tracksAdded( const QList<unsigned int>& fileids );
|
void tracksAdded( const QList<unsigned int>& fileids );
|
||||||
void tracksRemoved( const QList<unsigned int>& fileids );
|
void tracksRemoved( const QList<unsigned int>& fileids );
|
||||||
|
@@ -177,6 +177,13 @@ DatabaseCollection::requestTracks( const Tomahawk::album_ptr& album )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
DatabaseCollection::trackCount() const
|
||||||
|
{
|
||||||
|
return source()->trackCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DatabaseCollection::autoPlaylistCreated( const source_ptr& source, const QVariantList& data )
|
DatabaseCollection::autoPlaylistCreated( const source_ptr& source, const QVariantList& data )
|
||||||
{
|
{
|
||||||
|
@@ -54,6 +54,8 @@ public:
|
|||||||
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist );
|
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist );
|
||||||
virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album );
|
virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album );
|
||||||
|
|
||||||
|
virtual int trackCount() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void addTracks( const QList<QVariant>& newitems );
|
virtual void addTracks( const QList<QVariant>& newitems );
|
||||||
virtual void removeTracks( const QDir& dir );
|
virtual void removeTracks( const QDir& dir );
|
||||||
|
@@ -914,6 +914,15 @@ QtScriptResolver::loadCollections()
|
|||||||
// at this point we assume that all the tracks browsable through a resolver belong to the local source
|
// at this point we assume that all the tracks browsable through a resolver belong to the local source
|
||||||
Tomahawk::ScriptCollection* sc = new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this );
|
Tomahawk::ScriptCollection* sc = new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this );
|
||||||
sc->setDescription( desc );
|
sc->setDescription( desc );
|
||||||
|
|
||||||
|
if ( collectionInfo.contains( "trackcount" ) ) //a resolver might not expose this
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
int trackCount = collectionInfo.value( "trackcount" ).toInt( &ok );
|
||||||
|
if ( ok )
|
||||||
|
sc->setTrackCount( trackCount );
|
||||||
|
}
|
||||||
|
|
||||||
Tomahawk::collection_ptr collection( sc );
|
Tomahawk::collection_ptr collection( sc );
|
||||||
|
|
||||||
m_collections.insert( collection->name(), collection );
|
m_collections.insert( collection->name(), collection );
|
||||||
|
@@ -37,6 +37,7 @@ ScriptCollection::ScriptCollection( const source_ptr& source,
|
|||||||
ExternalResolver* resolver,
|
ExternalResolver* resolver,
|
||||||
QObject* parent )
|
QObject* parent )
|
||||||
: Collection( source, QString( "scriptcollection:" + resolver->name() + ":" + uuid() ), parent )
|
: Collection( source, QString( "scriptcollection:" + resolver->name() + ":" + uuid() ), parent )
|
||||||
|
, m_trackCount( -1 ) //null value
|
||||||
{
|
{
|
||||||
Q_ASSERT( resolver != 0 );
|
Q_ASSERT( resolver != 0 );
|
||||||
qDebug() << Q_FUNC_INFO << resolver->name() << name();
|
qDebug() << Q_FUNC_INFO << resolver->name() << name();
|
||||||
@@ -155,3 +156,17 @@ ScriptCollection::requestTracks( const Tomahawk::album_ptr& album )
|
|||||||
|
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCollection::setTrackCount( int count )
|
||||||
|
{
|
||||||
|
m_trackCount = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
ScriptCollection::trackCount() const
|
||||||
|
{
|
||||||
|
return m_trackCount;
|
||||||
|
}
|
||||||
|
@@ -57,9 +57,13 @@ public:
|
|||||||
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist );
|
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist );
|
||||||
virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album );
|
virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album );
|
||||||
|
|
||||||
|
virtual void setTrackCount( int count );
|
||||||
|
virtual int trackCount() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ExternalResolver* m_resolver;
|
ExternalResolver* m_resolver;
|
||||||
QString m_description;
|
QString m_description;
|
||||||
|
int m_trackCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //ns
|
} //ns
|
||||||
|
@@ -204,6 +204,12 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
|
|
||||||
if ( !scItem->collection().isNull() )
|
if ( !scItem->collection().isNull() )
|
||||||
{
|
{
|
||||||
|
int trackCount = scItem->collection()->trackCount();
|
||||||
|
if ( trackCount >= 0 )
|
||||||
|
{
|
||||||
|
tracks = QString::number( trackCount );
|
||||||
|
figWidth = QFontMetrics( figFont ).width( tracks );
|
||||||
|
}
|
||||||
name = scItem->collection()->itemName();
|
name = scItem->collection()->itemName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,6 +317,7 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
painter->setPen( descColor );
|
painter->setPen( descColor );
|
||||||
painter->drawText( textRect, text, to );
|
painter->drawText( textRect, text, to );
|
||||||
|
|
||||||
|
bool shouldPaintTrackCount = false;
|
||||||
if ( type == SourcesModel::Collection )
|
if ( type == SourcesModel::Collection )
|
||||||
{
|
{
|
||||||
SourceItem* colItem = qobject_cast< SourceItem* >( item );
|
SourceItem* colItem = qobject_cast< SourceItem* >( item );
|
||||||
@@ -321,23 +328,30 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
m_trackRects[ index ] = textRect.adjusted( 0, 0, -textRect.width() + painter->fontMetrics().width( text ), 0 );
|
m_trackRects[ index ] = textRect.adjusted( 0, 0, -textRect.width() + painter->fontMetrics().width( text ), 0 );
|
||||||
else
|
else
|
||||||
m_trackRects.remove( index );
|
m_trackRects.remove( index );
|
||||||
|
if ( status && !tracks.isEmpty() )
|
||||||
|
shouldPaintTrackCount = true;
|
||||||
|
}
|
||||||
|
else if ( type == SourcesModel::ScriptCollection )
|
||||||
|
{
|
||||||
|
if ( !tracks.isEmpty() )
|
||||||
|
shouldPaintTrackCount = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ( status )
|
if ( shouldPaintTrackCount )
|
||||||
{
|
{
|
||||||
painter->setRenderHint( QPainter::Antialiasing );
|
painter->setRenderHint( QPainter::Antialiasing );
|
||||||
|
|
||||||
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 13, 0, -14, -option.rect.height() + option.fontMetrics.height() * 1.1 );
|
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 13, 0, -14, -option.rect.height() + option.fontMetrics.height() * 1.1 );
|
||||||
int hd = ( option.rect.height() - figRect.height() ) / 2;
|
int hd = ( option.rect.height() - figRect.height() ) / 2;
|
||||||
figRect.adjust( 0, hd, 0, hd );
|
figRect.adjust( 0, hd, 0, hd );
|
||||||
|
|
||||||
painter->setFont( figFont );
|
painter->setFont( figFont );
|
||||||
|
|
||||||
QColor figColor( 167, 183, 211 );
|
QColor figColor( 167, 183, 211 );
|
||||||
painter->setPen( figColor );
|
painter->setPen( figColor );
|
||||||
painter->setBrush( figColor );
|
painter->setBrush( figColor );
|
||||||
|
|
||||||
TomahawkUtils::drawBackgroundAndNumbers( painter, tracks, figRect );
|
TomahawkUtils::drawBackgroundAndNumbers( painter, tracks, figRect );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
Reference in New Issue
Block a user