1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-22 21:54:00 +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 "sourcelist.h"
#include "playlistview.h"
#include "trackmodel.h"
#include "trackmodelitem.h"
#include "trackproxymodel.h"
@@ -35,6 +36,8 @@
#include "utils/tomahawkutilsgui.h"
#include "utils/logger.h"
#include <utils/PixmapDelegateFader.h>
#include <utils/closure.h>
using namespace Tomahawk;
@@ -55,6 +58,11 @@ PlaylistChartItemDelegate::PlaylistChartItemDelegate( TrackView* parent, TrackPr
m_bottomOption = QTextOption( Qt::AlignBottom );
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 )
return;
QPixmap pixmap, avatar;
QPixmap avatar;
QString artist, track, upperText, lowerText;
unsigned int duration = 0;
@@ -204,11 +212,15 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
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 );
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 );
r.adjust( pixmapRect.width() + figureRect.width() + 18, 1, -28, 0 );
@@ -232,3 +244,18 @@ PlaylistChartItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
}
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"
namespace Tomahawk {
class PixmapDelegateFader;
}
class TrackModel;
class TrackModelItem;
class TrackProxyModel;
@@ -36,11 +40,18 @@ Q_OBJECT
public:
PlaylistChartItemDelegate( TrackView* parent = 0, TrackProxyModel* proxy = 0 );
signals:
void updateRequest( const QModelIndex& idx );
protected:
void paint( QPainter* painter, 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;
private slots:
void modelChanged();
void doUpdateIndex( const QPersistentModelIndex& idx );
private:
void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, TrackModelItem* item ) const;
@@ -51,6 +62,8 @@ private:
TrackView* m_view;
TrackProxyModel* m_model;
mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
};
#endif // PLAYLISTCHARTITEMDELEGATE_H

View File

@@ -56,6 +56,7 @@ public:
signals:
void nameChanged( const QString& title );
void destroyed( QWidget* widget );
void modelChanged();
protected:
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_albumPtr = Album::get( m_artistPtr, album(), false );
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( coverChanged() ), SIGNAL( coverChanged() ), Qt::UniqueConnection );
}
m_albumPtr->cover( size, forceLoad );

View File

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

View File

@@ -83,7 +83,9 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
ui->tracksViewLeft->overlay()->setEnabled( false );
ui->tracksViewLeft->setHeaderHidden( true );
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 );
TreeProxyModel* artistsProxy = new TreeProxyModel( ui->artistsViewLeft );