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 "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

@@ -594,7 +594,7 @@ Query::setLoved( bool loved )
DatabaseCommand_SocialAction* cmd = new DatabaseCommand_SocialAction( q, QString( "Love" ), loved ? QString( "true" ) : QString( "false" ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
emit socialActionsLoaded();
}
}
@@ -638,7 +638,7 @@ Query::socialActionDescription( const QString& action, DescriptionMode mode ) co
else
desc += ", ";
}
if ( sa.source->isLocal() )
{
if ( loveCounter == 1 )
@@ -654,13 +654,13 @@ Query::socialActionDescription( const QString& action, DescriptionMode mode ) co
{
if ( loveCounter > 3 )
desc += " " + tr( "and" ) + " <b>" + tr( "%n other(s)", "", loveCounter - 3 ) + "</b>";
if ( mode == Short )
desc = "<b>" + tr( "%1 people" ).arg( loveCounter ) + "</b>";
desc += " " + tr( "loved this track" ); //FIXME: more action descs required
}
return desc;
}
@@ -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 );
@@ -685,7 +687,7 @@ Query::cover( const QSize& size, bool forceLoad ) const
return m_artistPtr->cover( size );
}
return QPixmap();
}
#endif

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();
@@ -156,7 +158,7 @@ public slots:
// resolve if not solved()
void onResolverAdded();
void onResolverRemoved();
private slots:
void onResultStatusChanged();
void refreshResults();

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 );

View File

@@ -127,7 +127,7 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw
SLOT( onAutoPlaylistsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
connect( source->collection().data(), SIGNAL( stationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ),
SLOT( onStationsAdded( QList<Tomahawk::dynplaylist_ptr> ) ), Qt::QueuedConnection );
if ( m_source->isLocal() )
QTimer::singleShot( 0, this, SLOT( requestExpanding() ) );
}