1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-22 13:43:11 +02:00

add fading to track charts

This commit is contained in:
Leo Franchi
2012-04-05 23:31:21 -04:00
parent 30e239c311
commit 155cccb109
7 changed files with 59 additions and 12 deletions

View File

@@ -27,6 +27,7 @@
#include "source.h" #include "source.h"
#include "sourcelist.h" #include "sourcelist.h"
#include "playlistview.h"
#include "trackmodel.h" #include "trackmodel.h"
#include "trackmodelitem.h" #include "trackmodelitem.h"
#include "trackproxymodel.h" #include "trackproxymodel.h"
@@ -35,6 +36,8 @@
#include "utils/tomahawkutilsgui.h" #include "utils/tomahawkutilsgui.h"
#include "utils/logger.h" #include "utils/logger.h"
#include <utils/PixmapDelegateFader.h>
#include <utils/closure.h>
using namespace Tomahawk; using namespace Tomahawk;
@@ -55,6 +58,11 @@ PlaylistChartItemDelegate::PlaylistChartItemDelegate( TrackView* parent, TrackPr
m_bottomOption = QTextOption( Qt::AlignBottom ); m_bottomOption = QTextOption( Qt::AlignBottom );
m_bottomOption.setWrapMode( QTextOption::NoWrap ); m_bottomOption.setWrapMode( QTextOption::NoWrap );
connect( m_model->sourceModel(), SIGNAL( modelReset() ), this, SLOT( modelChanged() ) );
if ( PlaylistView* plView = qobject_cast< PlaylistView* >( parent ) )
connect( plView, SIGNAL( modelChanged() ), this, SLOT( modelChanged() ) );
} }
@@ -127,7 +135,7 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
if ( m_view->header()->visualIndex( index.column() ) > 0 ) if ( m_view->header()->visualIndex( index.column() ) > 0 )
return; return;
QPixmap pixmap, avatar; QPixmap avatar;
QString artist, track, upperText, lowerText; QString artist, track, upperText, lowerText;
unsigned int duration = 0; unsigned int duration = 0;
@@ -204,11 +212,15 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
painter->setPen( opt.palette.text().color() ); painter->setPen( opt.palette.text().color() );
QRect pixmapRect = r.adjusted( figureRect.width() + 6, 0, -option.rect.width() + figureRect.width() + option.rect.height() - 6 + r.left(), 0 ); QRect pixmapRect = r.adjusted( figureRect.width() + 6, 0, -option.rect.width() + figureRect.width() + option.rect.height() - 6 + r.left(), 0 );
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<PlaylistChartItemDelegate*>(this), SLOT( doUpdateIndex( const QPersistentModelIndex& ) ), QPersistentModelIndex( index ) );
closure->setAutoDelete( false );
} }
const QPixmap pixmap = m_pixmaps[ index ]->currentPixmap();
painter->drawPixmap( pixmapRect, pixmap ); painter->drawPixmap( pixmapRect, pixmap );
r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 ); r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 );
@@ -232,3 +244,18 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
} }
painter->restore(); painter->restore();
} }
void
PlaylistChartItemDelegate::doUpdateIndex( const QPersistentModelIndex& idx )
{
emit updateRequest( idx );
}
void
PlaylistChartItemDelegate::modelChanged()
{
m_pixmaps.clear();
}

View File

@@ -24,6 +24,10 @@
#include "dllmacro.h" #include "dllmacro.h"
namespace Tomahawk {
class PixmapDelegateFader;
}
class TrackModel; class TrackModel;
class TrackModelItem; class TrackModelItem;
class TrackProxyModel; class TrackProxyModel;
@@ -36,11 +40,18 @@ Q_OBJECT
public: public:
PlaylistChartItemDelegate( TrackView* parent = 0, TrackProxyModel* proxy = 0 ); PlaylistChartItemDelegate( TrackView* parent = 0, TrackProxyModel* proxy = 0 );
signals:
void updateRequest( const QModelIndex& idx );
protected: protected:
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const; QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const; QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
private slots:
void modelChanged();
void doUpdateIndex( const QPersistentModelIndex& idx );
private: private:
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ) const; void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ) const;
@@ -51,6 +62,8 @@ private:
TrackView* m_view; TrackView* m_view;
TrackProxyModel* m_model; TrackProxyModel* m_model;
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
}; };
#endif // PLAYLISTCHARTITEMDELEGATE_H #endif // PLAYLISTCHARTITEMDELEGATE_H

View File

@@ -56,6 +56,7 @@ public:
signals: signals:
void nameChanged( const QString& title ); void nameChanged( const QString& title );
void destroyed( QWidget* widget ); void destroyed( QWidget* widget );
void modelChanged();
protected: protected:
void keyPressEvent( QKeyEvent* event ); void keyPressEvent( QKeyEvent* event );

View File

@@ -674,7 +674,9 @@ Query::cover( const QSize& size, bool forceLoad ) const
m_artistPtr = Artist::get( artist(), false ); m_artistPtr = Artist::get( artist(), false );
m_albumPtr = Album::get( m_artistPtr, album(), false ); m_albumPtr = Album::get( m_artistPtr, album(), false );
connect( m_artistPtr.data(), SIGNAL( updated() ), SIGNAL( updated() ), Qt::UniqueConnection ); connect( m_artistPtr.data(), SIGNAL( updated() ), SIGNAL( updated() ), Qt::UniqueConnection );
connect( m_artistPtr.data(), SIGNAL( coverChanged() ), SIGNAL( coverChanged() ), Qt::UniqueConnection );
connect( m_albumPtr.data(), SIGNAL( updated() ), SIGNAL( updated() ), Qt::UniqueConnection ); connect( m_albumPtr.data(), SIGNAL( updated() ), SIGNAL( updated() ), Qt::UniqueConnection );
connect( m_albumPtr.data(), SIGNAL( coverChanged() ), SIGNAL( coverChanged() ), Qt::UniqueConnection );
} }
m_albumPtr->cover( size, forceLoad ); m_albumPtr->cover( size, forceLoad );

View File

@@ -139,6 +139,8 @@ signals:
void playableStateChanged( bool state ); void playableStateChanged( bool state );
void resolvingFinished( bool hasResults ); void resolvingFinished( bool hasResults );
void coverChanged();
// emitted when social actions are loaded // emitted when social actions are loaded
void socialActionsLoaded(); void socialActionsLoaded();
void updated(); void updated();

View File

@@ -83,7 +83,9 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
ui->tracksViewLeft->overlay()->setEnabled( false ); ui->tracksViewLeft->overlay()->setEnabled( false );
ui->tracksViewLeft->setHeaderHidden( true ); ui->tracksViewLeft->setHeaderHidden( true );
ui->tracksViewLeft->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->tracksViewLeft->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
ui->tracksViewLeft->setItemDelegate( new PlaylistChartItemDelegate( ui->tracksViewLeft, ui->tracksViewLeft->proxyModel() ) ); PlaylistChartItemDelegate* del = new PlaylistChartItemDelegate( ui->tracksViewLeft, ui->tracksViewLeft->proxyModel() );
connect( del, SIGNAL( updateRequest( QModelIndex ) ), ui->tracksViewLeft, SLOT( update( QModelIndex ) ) );
ui->tracksViewLeft->setItemDelegate( del );
ui->tracksViewLeft->setUniformRowHeights( false ); ui->tracksViewLeft->setUniformRowHeights( false );
TreeProxyModel* artistsProxy = new TreeProxyModel( ui->artistsViewLeft ); TreeProxyModel* artistsProxy = new TreeProxyModel( ui->artistsViewLeft );