mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-13 20:39:57 +01:00
Add fading to various custom large track delegates and support query in fader
This commit is contained in:
parent
155cccb109
commit
84773f7956
@ -28,6 +28,7 @@
|
||||
#include "source.h"
|
||||
#include "sourcelist.h"
|
||||
|
||||
#include "playlistview.h"
|
||||
#include "trackmodel.h"
|
||||
#include "trackmodelitem.h"
|
||||
#include "trackproxymodel.h"
|
||||
@ -36,6 +37,8 @@
|
||||
|
||||
#include "utils/tomahawkutilsgui.h"
|
||||
#include "utils/logger.h"
|
||||
#include <utils/PixmapDelegateFader.h>
|
||||
#include <utils/closure.h>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -54,6 +57,10 @@ PlaylistLargeItemDelegate::PlaylistLargeItemDelegate( DisplayMode mode, TrackVie
|
||||
|
||||
m_bottomOption = QTextOption( Qt::AlignBottom );
|
||||
m_bottomOption.setWrapMode( QTextOption::NoWrap );
|
||||
|
||||
connect( proxy->sourceModel(), SIGNAL( modelReset() ), this, SLOT( modelChanged() ) );
|
||||
if ( PlaylistView* plView = qobject_cast< PlaylistView* >( parent ) )
|
||||
connect( plView, SIGNAL( modelChanged() ), this, SLOT( modelChanged() ) );
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +136,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
if ( m_view->header()->visualIndex( index.column() ) > 0 )
|
||||
return;
|
||||
|
||||
QPixmap pixmap, avatar;
|
||||
QPixmap avatar;
|
||||
QString artist, track, lowerText;
|
||||
unsigned int duration = 0;
|
||||
|
||||
@ -188,12 +195,15 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
QRect avatarRect = r.adjusted( option.rect.width() - r.left() - 12 - avatarSize.width(), ( option.rect.height() - avatarSize.height() ) / 2 - 5, 0, 0 );
|
||||
avatarRect.setSize( avatarSize );
|
||||
|
||||
pixmap = item->query()->cover( pixmapRect.size(), false );
|
||||
if ( !pixmap )
|
||||
|
||||
if ( !m_pixmaps.contains( index ) )
|
||||
{
|
||||
pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, pixmapRect.size() );
|
||||
m_pixmaps.insert( index, QSharedPointer< Tomahawk::PixmapDelegateFader >( new Tomahawk::PixmapDelegateFader( item->query(), pixmapRect.size(), false ) ) );
|
||||
_detail::Closure* closure = NewClosure( m_pixmaps[ index ], SIGNAL( repaintRequest() ), const_cast<PlaylistLargeItemDelegate*>(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) );
|
||||
closure->setAutoDelete( false );
|
||||
}
|
||||
|
||||
const QPixmap pixmap = m_pixmaps[ index ]->currentPixmap();
|
||||
painter->drawPixmap( pixmapRect, pixmap );
|
||||
|
||||
if ( !avatar.isNull() )
|
||||
@ -245,3 +255,18 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistLargeItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
|
||||
{
|
||||
if ( idx.isValid() )
|
||||
emit updateIndex( idx );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistLargeItemDelegate::modelChanged()
|
||||
{
|
||||
m_pixmaps.clear();
|
||||
}
|
||||
|
@ -24,6 +24,11 @@
|
||||
#include <QTextOption>
|
||||
|
||||
#include "dllmacro.h"
|
||||
#include <signal.h>
|
||||
|
||||
namespace Tomahawk {
|
||||
class PixmapDelegateFader;
|
||||
}
|
||||
|
||||
class TrackModel;
|
||||
class TrackModelItem;
|
||||
@ -45,6 +50,13 @@ protected:
|
||||
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||
|
||||
signals:
|
||||
void updateIndex( const QModelIndex& idx );
|
||||
|
||||
private slots:
|
||||
void modelChanged();
|
||||
void doUpdateIndex( const QPersistentModelIndex& idx );
|
||||
|
||||
private:
|
||||
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ) const;
|
||||
void drawRichText( QPainter* painter, const QRect& rect, int flags, QTextDocument& text ) const;
|
||||
@ -53,6 +65,8 @@ private:
|
||||
QTextOption m_centerRightOption;
|
||||
QTextOption m_bottomOption;
|
||||
|
||||
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
|
||||
|
||||
TrackView* m_view;
|
||||
TrackProxyModel* m_model;
|
||||
DisplayMode m_mode;
|
||||
|
@ -80,6 +80,8 @@ PlaylistView::setPlaylistModel( PlaylistModel* model )
|
||||
connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
|
||||
connect( m_model, SIGNAL( playlistDeleted() ), SLOT( onDeleted() ) );
|
||||
connect( m_model, SIGNAL( playlistChanged() ), SLOT( onChanged() ) );
|
||||
|
||||
emit modelChanged();
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,6 +53,20 @@ PixmapDelegateFader::PixmapDelegateFader( const album_ptr& album, const QSize& s
|
||||
}
|
||||
|
||||
|
||||
PixmapDelegateFader::PixmapDelegateFader( const query_ptr& track, const QSize& size, bool forceLoad )
|
||||
: m_track( track )
|
||||
, m_size( size )
|
||||
{
|
||||
if ( !m_track.isNull() )
|
||||
{
|
||||
connect( m_track.data(), SIGNAL( coverChanged() ), this, SLOT( trackChanged() ) );
|
||||
m_currentReference = m_track->cover( size, forceLoad );
|
||||
}
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
PixmapDelegateFader::~PixmapDelegateFader()
|
||||
{
|
||||
|
||||
@ -75,7 +89,13 @@ PixmapDelegateFader::init()
|
||||
if ( m_currentReference.isNull() )
|
||||
{
|
||||
// No cover loaded yet, use default and don't fade in
|
||||
m_current = m_currentReference = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::CoverInCase, m_size );
|
||||
if ( !m_album.isNull() )
|
||||
m_current = m_currentReference = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::CoverInCase, m_size );
|
||||
else if ( !m_artist.isNull() )
|
||||
m_current = m_currentReference = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::CoverInCase, m_size );
|
||||
else if ( !m_track.isNull() )
|
||||
m_current = m_currentReference = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::CoverInCase, m_size );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -102,6 +122,16 @@ PixmapDelegateFader::artistChanged()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PixmapDelegateFader::trackChanged()
|
||||
{
|
||||
if ( m_track.isNull() || m_track->cover( m_size ).isNull() )
|
||||
return;
|
||||
|
||||
setPixmap( m_track->cover( m_size ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PixmapDelegateFader::setPixmap( const QPixmap& pixmap )
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "artist.h"
|
||||
#include "album.h"
|
||||
#include "query.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimeLine>
|
||||
@ -41,6 +42,7 @@ class PixmapDelegateFader : public QObject
|
||||
public:
|
||||
PixmapDelegateFader( const artist_ptr& artist, const QSize& size, bool forceLoad = true );
|
||||
PixmapDelegateFader( const album_ptr& album, const QSize& size, bool forceLoad = true );
|
||||
PixmapDelegateFader( const query_ptr& track, const QSize& size, bool forceLoad = true );
|
||||
|
||||
virtual ~PixmapDelegateFader();
|
||||
|
||||
@ -54,6 +56,7 @@ signals:
|
||||
private slots:
|
||||
void artistChanged();
|
||||
void albumChanged();
|
||||
void trackChanged();
|
||||
|
||||
void onAnimationStep( int );
|
||||
void onAnimationFinished();
|
||||
@ -62,6 +65,7 @@ private:
|
||||
|
||||
artist_ptr m_artist;
|
||||
album_ptr m_album;
|
||||
query_ptr m_track;
|
||||
QSize m_size;
|
||||
|
||||
QQueue<QPixmap> m_pixmapQueue;
|
||||
|
@ -444,7 +444,9 @@ ViewManager::showTopLovedPage()
|
||||
if ( !m_topLovedWidget )
|
||||
{
|
||||
CustomPlaylistView* view = new CustomPlaylistView( CustomPlaylistView::TopLovedTracks, source_ptr(), m_widget );
|
||||
view->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LovedTracks, view, view->proxyModel() ) );
|
||||
PlaylistLargeItemDelegate* del = new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LovedTracks, view, view->proxyModel() );
|
||||
connect( del, SIGNAL( updateIndex( QModelIndex ) ), view, SLOT( update( QModelIndex ) ) );
|
||||
view->setItemDelegate( del );
|
||||
|
||||
m_topLovedWidget = view;
|
||||
}
|
||||
@ -465,7 +467,10 @@ ViewManager::showRecentPlaysPage()
|
||||
RecentlyPlayedModel* raModel = new RecentlyPlayedModel( source_ptr(), pv );
|
||||
raModel->setStyle( TrackModel::Large );
|
||||
|
||||
pv->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::RecentlyPlayed, pv, pv->proxyModel() ) );
|
||||
PlaylistLargeItemDelegate* del = new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::RecentlyPlayed, pv, pv->proxyModel() );
|
||||
connect( del, SIGNAL( updateIndex( QModelIndex ) ), pv, SLOT( update( QModelIndex ) ) );
|
||||
pv->setItemDelegate( del );
|
||||
|
||||
pv->setPlaylistModel( raModel );
|
||||
|
||||
m_recentPlaysWidget = pv;
|
||||
|
@ -504,7 +504,9 @@ SourceItem::lovedTracksClicked()
|
||||
if ( !m_lovedTracksPage )
|
||||
{
|
||||
CustomPlaylistView* view = new CustomPlaylistView( m_source.isNull() ? CustomPlaylistView::TopLovedTracks : CustomPlaylistView::SourceLovedTracks, m_source, ViewManager::instance()->widget() );
|
||||
view->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LovedTracks, view, view->proxyModel() ) );
|
||||
PlaylistLargeItemDelegate* del = new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LovedTracks, view, view->proxyModel() );
|
||||
connect( del, SIGNAL( updateIndex( QModelIndex ) ), view, SLOT( update( QModelIndex ) ) );
|
||||
view->setItemDelegate( del );
|
||||
|
||||
m_lovedTracksPage = view;
|
||||
}
|
||||
@ -533,7 +535,10 @@ SourceItem::latestAdditionsClicked()
|
||||
RecentlyAddedModel* raModel = new RecentlyAddedModel( m_source, cv );
|
||||
raModel->setStyle( TrackModel::Large );
|
||||
|
||||
cv->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LatestAdditions, cv, cv->proxyModel() ) );
|
||||
PlaylistLargeItemDelegate* del = new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::LatestAdditions, cv, cv->proxyModel() );
|
||||
connect( del, SIGNAL( updateIndex( QModelIndex ) ), cv, SLOT( update( QModelIndex ) ) );
|
||||
cv->setItemDelegate( del );
|
||||
|
||||
cv->setTrackModel( raModel );
|
||||
cv->sortByColumn( TrackModel::Age, Qt::DescendingOrder );
|
||||
|
||||
@ -564,7 +569,10 @@ SourceItem::recentPlaysClicked()
|
||||
RecentlyPlayedModel* raModel = new RecentlyPlayedModel( m_source, pv );
|
||||
raModel->setStyle( TrackModel::Large );
|
||||
|
||||
pv->setItemDelegate( new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::RecentlyPlayed, pv, pv->proxyModel() ) );
|
||||
PlaylistLargeItemDelegate* del = new PlaylistLargeItemDelegate( PlaylistLargeItemDelegate::RecentlyPlayed, pv, pv->proxyModel() );
|
||||
connect( del, SIGNAL( updateIndex( QModelIndex ) ), pv, SLOT( update( QModelIndex ) ) );
|
||||
pv->setItemDelegate( del );
|
||||
|
||||
pv->setPlaylistModel( raModel );
|
||||
|
||||
m_recentPlaysPage = pv;
|
||||
|
Loading…
x
Reference in New Issue
Block a user