mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-04 21:27:58 +02:00
Support drop-shadowed source icons and use them in the playlist
This commit is contained in:
@@ -41,11 +41,11 @@ typedef QMap< QString, QPixmap > SourceIconCache;
|
|||||||
Q_GLOBAL_STATIC( SourceIconCache, sourceIconCache );
|
Q_GLOBAL_STATIC( SourceIconCache, sourceIconCache );
|
||||||
static QMutex s_sourceIconMutex;
|
static QMutex s_sourceIconMutex;
|
||||||
|
|
||||||
inline QString sourceCacheKey( Resolver* resolver, const QSize& size )
|
inline QString sourceCacheKey( Resolver* resolver, const QSize& size, Result::SourceImageStyle style )
|
||||||
{
|
{
|
||||||
QString str;
|
QString str;
|
||||||
QTextStream stream( &str );
|
QTextStream stream( &str );
|
||||||
stream << resolver << size.width() << size.height();
|
stream << resolver << size.width() << size.height() << "_" << style;
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ Result::toVariant() const
|
|||||||
m.insert( "album", album()->name() );
|
m.insert( "album", album()->name() );
|
||||||
m.insert( "track", track() );
|
m.insert( "track", track() );
|
||||||
m.insert( "source", friendlySource() );
|
m.insert( "source", friendlySource() );
|
||||||
m.insert( "sourceIcon", sourceIcon() );
|
m.insert( "sourceIcon", sourceIcon( Plain ) );
|
||||||
m.insert( "mimetype", mimetype() );
|
m.insert( "mimetype", mimetype() );
|
||||||
m.insert( "size", size() );
|
m.insert( "size", size() );
|
||||||
m.insert( "bitrate", bitrate() );
|
m.insert( "bitrate", bitrate() );
|
||||||
@@ -309,7 +309,7 @@ Result::friendlySource() const
|
|||||||
|
|
||||||
|
|
||||||
QPixmap
|
QPixmap
|
||||||
Result::sourceIcon( const QSize& desiredSize ) const
|
Result::sourceIcon( SourceImageStyle style, const QSize& desiredSize ) const
|
||||||
{
|
{
|
||||||
if ( collection().isNull() )
|
if ( collection().isNull() )
|
||||||
{
|
{
|
||||||
@@ -319,12 +319,14 @@ Result::sourceIcon( const QSize& desiredSize ) const
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
QMutexLocker l( &s_sourceIconMutex );
|
QMutexLocker l( &s_sourceIconMutex );
|
||||||
const QString key = sourceCacheKey( m_resolvedBy.data(), desiredSize );
|
const QString key = sourceCacheKey( m_resolvedBy.data(), desiredSize, style );
|
||||||
if ( !sourceIconCache()->contains( key ) )
|
if ( !sourceIconCache()->contains( key ) )
|
||||||
{
|
{
|
||||||
QPixmap pixmap = guiResolver->icon();
|
QPixmap pixmap = guiResolver->icon();
|
||||||
if ( !desiredSize.isEmpty() )
|
if ( !desiredSize.isEmpty() )
|
||||||
pixmap = pixmap.scaled( desiredSize, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
pixmap = pixmap.scaled( desiredSize, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||||
|
if ( style == DropShadow )
|
||||||
|
pixmap = TomahawkUtils::addDropShadow( pixmap, QSize() );
|
||||||
sourceIconCache()->insert( key, pixmap );
|
sourceIconCache()->insert( key, pixmap );
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
@@ -50,6 +50,11 @@ friend class ::DatabaseCommand_AddFiles;
|
|||||||
friend class ::DatabaseCommand_LoadFile;
|
friend class ::DatabaseCommand_LoadFile;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum SourceImageStyle {
|
||||||
|
Plain,
|
||||||
|
DropShadow
|
||||||
|
};
|
||||||
|
|
||||||
static Tomahawk::result_ptr get( const QString& url );
|
static Tomahawk::result_ptr get( const QString& url );
|
||||||
static bool isCached( const QString& url );
|
static bool isCached( const QString& url );
|
||||||
virtual ~Result();
|
virtual ~Result();
|
||||||
@@ -73,10 +78,11 @@ public:
|
|||||||
QString url() const { return m_url; }
|
QString url() const { return m_url; }
|
||||||
QString mimetype() const { return m_mimetype; }
|
QString mimetype() const { return m_mimetype; }
|
||||||
QString friendlySource() const;
|
QString friendlySource() const;
|
||||||
QPixmap sourceIcon( const QSize& desiredSize = QSize() ) const;
|
|
||||||
QString purchaseUrl() const { return m_purchaseUrl; }
|
QString purchaseUrl() const { return m_purchaseUrl; }
|
||||||
QString linkUrl() const { return m_linkUrl; }
|
QString linkUrl() const { return m_linkUrl; }
|
||||||
|
|
||||||
|
QPixmap sourceIcon( SourceImageStyle style, const QSize& desiredSize = QSize() ) const;
|
||||||
|
|
||||||
unsigned int duration() const { return m_duration; }
|
unsigned int duration() const { return m_duration; }
|
||||||
unsigned int bitrate() const { return m_bitrate; }
|
unsigned int bitrate() const { return m_bitrate; }
|
||||||
unsigned int size() const { return m_size; }
|
unsigned int size() const { return m_size; }
|
||||||
|
@@ -218,7 +218,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
QFont smallFont = opt.font;
|
QFont smallFont = opt.font;
|
||||||
smallFont.setPointSize( TomahawkUtils::defaultFontSize() - 2 );
|
smallFont.setPointSize( TomahawkUtils::defaultFontSize() - 2 );
|
||||||
|
|
||||||
r.adjust( pixmapRect.width() + 12, 1, - 20 - avatar.width(), 0 );
|
r.adjust( pixmapRect.width() + 12, 1, - 16 - avatar.width(), 0 );
|
||||||
QRect leftRect = r.adjusted( 0, 0, -48, 0 );
|
QRect leftRect = r.adjusted( 0, 0, -48, 0 );
|
||||||
QRect rightRect = r.adjusted( r.width() - smallBoldFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 );
|
QRect rightRect = r.adjusted( r.width() - smallBoldFontMetrics.width( TomahawkUtils::timeToString( duration ) ), 0, 0, 0 );
|
||||||
|
|
||||||
@@ -243,14 +243,14 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
|
|
||||||
drawRichText( painter, option, leftRect, Qt::AlignBottom, textDoc );
|
drawRichText( painter, option, leftRect, Qt::AlignBottom, textDoc );
|
||||||
|
|
||||||
if ( !q->results().isEmpty() && !q->results().first()->sourceIcon().isNull() )
|
const int sourceIconSize = avatarRect.width() - 6;
|
||||||
|
if ( !q->results().isEmpty() && !q->results().first()->sourceIcon( Result::DropShadow, QSize( sourceIconSize, sourceIconSize ) ).isNull() )
|
||||||
{
|
{
|
||||||
const int iconSize = avatarRect.width() - 4;
|
const QPixmap sourceIcon = q->results().first()->sourceIcon( Result::DropShadow, QSize( sourceIconSize, sourceIconSize ) );
|
||||||
const QPixmap sourceIcon = q->results().first()->sourceIcon( QSize( iconSize, iconSize ) );
|
|
||||||
painter->setOpacity( 0.8 );
|
painter->setOpacity( 0.8 );
|
||||||
painter->drawPixmap( QRect( rightRect.right() - iconSize, r.center().y() - iconSize/2, iconSize, iconSize ), sourceIcon );
|
painter->drawPixmap( QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize/2, sourceIcon.width(), sourceIcon.height() ), sourceIcon );
|
||||||
painter->setOpacity( 1. );
|
painter->setOpacity( 1. );
|
||||||
rightRect.moveLeft( rightRect.left() - iconSize - 8 );
|
rightRect.moveLeft( rightRect.left() - sourceIcon.width() - 8 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( duration > 0 )
|
if ( duration > 0 )
|
||||||
|
Reference in New Issue
Block a user