diff --git a/src/libtomahawk/playlist/AlbumItem.cpp b/src/libtomahawk/playlist/AlbumItem.cpp index 5759c861e..d97b222bf 100644 --- a/src/libtomahawk/playlist/AlbumItem.cpp +++ b/src/libtomahawk/playlist/AlbumItem.cpp @@ -103,3 +103,29 @@ AlbumItem::AlbumItem( const Tomahawk::artist_ptr& artist, AlbumItem* parent, int connect( artist.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) ); } + + +AlbumItem::AlbumItem( const Tomahawk::query_ptr& query, AlbumItem* parent, int row ) + : QObject( parent ) + , m_query( query ) +{ + this->parent = parent; + if ( parent ) + { + if ( row < 0 ) + { + parent->children.append( this ); + row = parent->children.count() - 1; + } + else + { + parent->children.insert( row, this ); + } + + this->model = parent->model; + } + + toberemoved = false; + + connect( query.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) ); +} diff --git a/src/libtomahawk/playlist/AlbumItem.h b/src/libtomahawk/playlist/AlbumItem.h index f5f70e0d6..7ced56118 100644 --- a/src/libtomahawk/playlist/AlbumItem.h +++ b/src/libtomahawk/playlist/AlbumItem.h @@ -26,6 +26,7 @@ #include "Artist.h" #include "Album.h" +#include "Query.h" #include "DllMacro.h" @@ -39,9 +40,11 @@ public: explicit AlbumItem( AlbumItem* parent = 0, QAbstractItemModel* model = 0 ); explicit AlbumItem( const Tomahawk::artist_ptr& artist, AlbumItem* parent = 0, int row = -1 ); explicit AlbumItem( const Tomahawk::album_ptr& album, AlbumItem* parent = 0, int row = -1 ); + explicit AlbumItem( const Tomahawk::query_ptr& query, AlbumItem* parent = 0, int row = -1 ); const Tomahawk::artist_ptr& artist() const { return m_artist; } const Tomahawk::album_ptr& album() const { return m_album; } + const Tomahawk::query_ptr& query() const { return m_query; } AlbumItem* parent; QList children; @@ -57,6 +60,7 @@ signals: private: Tomahawk::artist_ptr m_artist; Tomahawk::album_ptr m_album; + Tomahawk::query_ptr m_query; }; #endif // ALBUMITEM_H diff --git a/src/libtomahawk/playlist/AlbumItemDelegate.cpp b/src/libtomahawk/playlist/AlbumItemDelegate.cpp index db0a0a74f..533ed8fb2 100644 --- a/src/libtomahawk/playlist/AlbumItemDelegate.cpp +++ b/src/libtomahawk/playlist/AlbumItemDelegate.cpp @@ -96,10 +96,40 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, QRect r = option.rect.adjusted( 6, 5, -6, -41 ); + QString top, bottom; + if ( !item->album().isNull() ) + { + top = item->album()->name(); + + if ( !item->album()->artist().isNull() ) + bottom = item->album()->artist()->name(); + } + else if ( !item->artist().isNull() ) + { + top = item->artist()->name(); + } + else + { + top = item->query()->track(); + bottom = item->query()->artist(); + } + if ( !m_covers.contains( index ) ) { - m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::CoverInCase ) ) ); - _detail::Closure* closure = NewClosure( m_covers[ index ], SIGNAL( repaintRequest() ), const_cast(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) ); + if ( !item->album().isNull() ) + { + m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::CoverInCase ) ) ); + } + else if ( !item->artist().isNull() ) + { + m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->artist(), r.size(), TomahawkUtils::CoverInCase ) ) ); + } + else + { + m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->query(), r.size(), TomahawkUtils::CoverInCase ) ) ); + } + + _detail::Closure* closure = NewClosure( m_covers[ index ], SIGNAL( repaintRequest() ), const_cast(this), SLOT( doUpdateIndex( QPersistentModelIndex ) ), QPersistentModelIndex( index ) ); closure->setAutoDelete( false ); } @@ -138,30 +168,24 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, QRect textRect = option.rect.adjusted( 0, option.rect.height() - 32, 0, -2 ); - QString name; - if ( !item->album().isNull() ) - name = item->album()->name(); - else if ( !item->artist().isNull() ) - name = item->artist()->name(); - painter->setFont( boldFont ); bool oneLiner = false; - if ( item->album().isNull() || item->album()->artist().isNull() ) + if ( bottom.isEmpty() ) oneLiner = true; else - oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->name() ).height() || - textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->artist()->name() ).height() ); + oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( top ).height() || + textRect.height() / 2 < painter->fontMetrics().boundingRect( bottom ).height() ); if ( oneLiner ) { to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); - text = painter->fontMetrics().elidedText( name, Qt::ElideRight, textRect.width() - 3 ); + text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); } else { to.setAlignment( Qt::AlignHCenter | Qt::AlignTop ); - text = painter->fontMetrics().elidedText( item->album()->name(), Qt::ElideRight, textRect.width() - 3 ); + text = painter->fontMetrics().elidedText( top, Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); // If the user is hovering over an artist rect, draw a background so she knows it's clickable @@ -184,7 +208,7 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, } to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom ); - text = painter->fontMetrics().elidedText( item->album()->artist()->name(), Qt::ElideRight, textRect.width() - 10 ); + text = painter->fontMetrics().elidedText( bottom, Qt::ElideRight, textRect.width() - 10 ); painter->drawText( textRect.adjusted( 5, -1, -5, -1 ), text, to ); // Calculate rect of artist on-hover button click area diff --git a/src/libtomahawk/playlist/AlbumModel.cpp b/src/libtomahawk/playlist/AlbumModel.cpp index 2b709ff1a..b04a8e203 100644 --- a/src/libtomahawk/playlist/AlbumModel.cpp +++ b/src/libtomahawk/playlist/AlbumModel.cpp @@ -399,6 +399,35 @@ AlbumModel::addArtists( const QList& artists ) } +void +AlbumModel::addQueries( const QList& queries ) +{ + emit loadingFinished(); + + if ( m_overwriteOnAdd ) + clear(); + + int c = rowCount( QModelIndex() ); + QPair< int, int > crows; + crows.first = c; + crows.second = c + queries.count() - 1; + + emit beginInsertRows( QModelIndex(), crows.first, crows.second ); + + AlbumItem* albumitem; + foreach ( const query_ptr& query, queries ) + { + albumitem = new AlbumItem( query, m_rootItem ); + albumitem->index = createIndex( m_rootItem->children.count() - 1, 0, albumitem ); + + connect( albumitem, SIGNAL( dataChanged() ), SLOT( onDataChanged() ) ); + } + + emit endInsertRows(); + emit itemCountChanged( rowCount( QModelIndex() ) ); +} + + void AlbumModel::onSourceAdded( const Tomahawk::source_ptr& source ) { diff --git a/src/libtomahawk/playlist/AlbumModel.h b/src/libtomahawk/playlist/AlbumModel.h index 297e600c6..71d7743d8 100644 --- a/src/libtomahawk/playlist/AlbumModel.h +++ b/src/libtomahawk/playlist/AlbumModel.h @@ -91,6 +91,7 @@ public slots: void addAlbums( const QList& albums ); void addArtists( const QList& artists ); + void addQueries( const QList& queries ); signals: void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );