mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 16:29:43 +01:00
* Added queries to AlbumModel. This will be renamed to ItemModel soon.
This commit is contained in:
parent
e27976c8a1
commit
7b801270c2
@ -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() ) );
|
||||
}
|
||||
|
@ -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<AlbumItem*> 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
|
||||
|
@ -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<AlbumItemDelegate*>(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<AlbumItemDelegate*>(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
|
||||
|
@ -399,6 +399,35 @@ AlbumModel::addArtists( const QList<Tomahawk::artist_ptr>& artists )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AlbumModel::addQueries( const QList<Tomahawk::query_ptr>& 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 )
|
||||
{
|
||||
|
@ -91,6 +91,7 @@ public slots:
|
||||
|
||||
void addAlbums( const QList<Tomahawk::album_ptr>& albums );
|
||||
void addArtists( const QList<Tomahawk::artist_ptr>& artists );
|
||||
void addQueries( const QList<Tomahawk::query_ptr>& queries );
|
||||
|
||||
signals:
|
||||
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
||||
|
Loading…
x
Reference in New Issue
Block a user