mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Added queries to AlbumModel. This will be renamed to ItemModel soon.
This commit is contained in:
@@ -103,3 +103,29 @@ AlbumItem::AlbumItem( const Tomahawk::artist_ptr& artist, AlbumItem* parent, int
|
|||||||
|
|
||||||
connect( artist.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
|
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 "Artist.h"
|
||||||
#include "Album.h"
|
#include "Album.h"
|
||||||
|
#include "Query.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
@@ -39,9 +40,11 @@ public:
|
|||||||
explicit AlbumItem( AlbumItem* parent = 0, QAbstractItemModel* model = 0 );
|
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::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::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::artist_ptr& artist() const { return m_artist; }
|
||||||
const Tomahawk::album_ptr& album() const { return m_album; }
|
const Tomahawk::album_ptr& album() const { return m_album; }
|
||||||
|
const Tomahawk::query_ptr& query() const { return m_query; }
|
||||||
|
|
||||||
AlbumItem* parent;
|
AlbumItem* parent;
|
||||||
QList<AlbumItem*> children;
|
QList<AlbumItem*> children;
|
||||||
@@ -57,6 +60,7 @@ signals:
|
|||||||
private:
|
private:
|
||||||
Tomahawk::artist_ptr m_artist;
|
Tomahawk::artist_ptr m_artist;
|
||||||
Tomahawk::album_ptr m_album;
|
Tomahawk::album_ptr m_album;
|
||||||
|
Tomahawk::query_ptr m_query;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ALBUMITEM_H
|
#endif // ALBUMITEM_H
|
||||||
|
@@ -96,10 +96,40 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
|||||||
|
|
||||||
QRect r = option.rect.adjusted( 6, 5, -6, -41 );
|
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 ) )
|
if ( !m_covers.contains( index ) )
|
||||||
{
|
{
|
||||||
m_covers.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->album(), r.size(), TomahawkUtils::CoverInCase ) ) );
|
if ( !item->album().isNull() )
|
||||||
_detail::Closure* closure = NewClosure( m_covers[ index ], SIGNAL( repaintRequest() ), const_cast<AlbumItemDelegate*>(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) );
|
{
|
||||||
|
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 );
|
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 );
|
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 );
|
painter->setFont( boldFont );
|
||||||
bool oneLiner = false;
|
bool oneLiner = false;
|
||||||
if ( item->album().isNull() || item->album()->artist().isNull() )
|
if ( bottom.isEmpty() )
|
||||||
oneLiner = true;
|
oneLiner = true;
|
||||||
else
|
else
|
||||||
oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->name() ).height() ||
|
oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( top ).height() ||
|
||||||
textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->artist()->name() ).height() );
|
textRect.height() / 2 < painter->fontMetrics().boundingRect( bottom ).height() );
|
||||||
|
|
||||||
if ( oneLiner )
|
if ( oneLiner )
|
||||||
{
|
{
|
||||||
to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
|
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 );
|
painter->drawText( textRect, text, to );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
to.setAlignment( Qt::AlignHCenter | Qt::AlignTop );
|
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 );
|
painter->drawText( textRect, text, to );
|
||||||
|
|
||||||
// If the user is hovering over an artist rect, draw a background so she knows it's clickable
|
// 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 );
|
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 );
|
painter->drawText( textRect.adjusted( 5, -1, -5, -1 ), text, to );
|
||||||
|
|
||||||
// Calculate rect of artist on-hover button click area
|
// 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
|
void
|
||||||
AlbumModel::onSourceAdded( const Tomahawk::source_ptr& source )
|
AlbumModel::onSourceAdded( const Tomahawk::source_ptr& source )
|
||||||
{
|
{
|
||||||
|
@@ -91,6 +91,7 @@ public slots:
|
|||||||
|
|
||||||
void addAlbums( const QList<Tomahawk::album_ptr>& albums );
|
void addAlbums( const QList<Tomahawk::album_ptr>& albums );
|
||||||
void addArtists( const QList<Tomahawk::artist_ptr>& artists );
|
void addArtists( const QList<Tomahawk::artist_ptr>& artists );
|
||||||
|
void addQueries( const QList<Tomahawk::query_ptr>& queries );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode );
|
||||||
|
Reference in New Issue
Block a user