diff --git a/src/AudioControls.cpp b/src/AudioControls.cpp index 6cd0c842e..58316cc83 100644 --- a/src/AudioControls.cpp +++ b/src/AudioControls.cpp @@ -283,9 +283,11 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result ) onControlStateChanged(); - QPixmap sourceIcon = result->sourceIcon( Result::Plain, ui->ownerButton->size() ); + QPixmap sourceIcon = result->sourceIcon( TomahawkUtils::RoundedCorners, ui->ownerButton->size() ); if ( !sourceIcon.isNull() ) + { ui->ownerButton->setPixmap( sourceIcon ); + } else { ui->ownerButton->clear(); diff --git a/src/libtomahawk/Result.cpp b/src/libtomahawk/Result.cpp index 7c09d434c..dfd2cbd78 100644 --- a/src/libtomahawk/Result.cpp +++ b/src/libtomahawk/Result.cpp @@ -42,7 +42,7 @@ typedef QMap< QString, QPixmap > SourceIconCache; Q_GLOBAL_STATIC( SourceIconCache, sourceIconCache ); static QMutex s_sourceIconMutex; -inline QString sourceCacheKey( Resolver* resolver, const QSize& size, Result::SourceImageStyle style ) +inline QString sourceCacheKey( Resolver* resolver, const QSize& size, TomahawkUtils::ImageMode style ) { QString str; QTextStream stream( &str ); @@ -50,6 +50,7 @@ inline QString sourceCacheKey( Resolver* resolver, const QSize& size, Result::So return str; } + Tomahawk::result_ptr Result::get( const QString& url ) { @@ -192,7 +193,6 @@ Result::toVariant() const m.insert( "album", album()->name() ); m.insert( "track", track() ); m.insert( "source", friendlySource() ); - m.insert( "sourceIcon", sourceIcon( Plain ) ); m.insert( "mimetype", mimetype() ); m.insert( "size", size() ); m.insert( "bitrate", bitrate() ); @@ -316,24 +316,40 @@ Result::friendlySource() const QPixmap -Result::sourceIcon( SourceImageStyle style, const QSize& desiredSize ) const +Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) const { if ( collection().isNull() ) { const ExternalResolverGui* guiResolver = qobject_cast< ExternalResolverGui* >( m_resolvedBy.data() ); if ( !guiResolver ) + { return QPixmap(); + } else { QMutexLocker l( &s_sourceIconMutex ); + const QString key = sourceCacheKey( m_resolvedBy.data(), desiredSize, style ); if ( !sourceIconCache()->contains( key ) ) { QPixmap pixmap = guiResolver->icon(); if ( !desiredSize.isEmpty() ) pixmap = pixmap.scaled( desiredSize, Qt::KeepAspectRatio, Qt::SmoothTransformation ); - if ( style == DropShadow ) - pixmap = TomahawkUtils::addDropShadow( pixmap, QSize() ); + + switch ( style ) + { + case TomahawkUtils::DropShadow: + pixmap = TomahawkUtils::addDropShadow( pixmap, QSize() ); + break; + + case TomahawkUtils::RoundedCorners: + pixmap = TomahawkUtils::createRoundedImage( pixmap, QSize() ); + break; + + default: + break; + } + sourceIconCache()->insert( key, pixmap ); return pixmap; } @@ -345,10 +361,10 @@ Result::sourceIcon( SourceImageStyle style, const QSize& desiredSize ) const } else { - QPixmap avatar = collection()->source()->avatar( Source::FancyStyle, desiredSize ); + QPixmap avatar = collection()->source()->avatar( TomahawkUtils::RoundedCorners, desiredSize ); if ( !avatar ) { - avatar = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, TomahawkUtils::AvatarInFrame, desiredSize ); + avatar = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, TomahawkUtils::RoundedCorners, desiredSize ); } return avatar; } diff --git a/src/libtomahawk/Result.h b/src/libtomahawk/Result.h index 622337b02..3a5143017 100644 --- a/src/libtomahawk/Result.h +++ b/src/libtomahawk/Result.h @@ -26,6 +26,7 @@ #include #include +#include "utils/TomahawkUtils.h" #include "Typedefs.h" #include "DllMacro.h" @@ -52,11 +53,6 @@ friend class ::DatabaseCommand_AddFiles; friend class ::DatabaseCommand_LoadFile; public: - enum SourceImageStyle { - Plain, - DropShadow - }; - static Tomahawk::result_ptr get( const QString& url ); static bool isCached( const QString& url ); virtual ~Result(); @@ -83,7 +79,7 @@ public: QString purchaseUrl() const { return m_purchaseUrl; } QString linkUrl() const { return m_linkUrl; } - QPixmap sourceIcon( SourceImageStyle style, const QSize& desiredSize = QSize() ) const; + QPixmap sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize = QSize() ) const; unsigned int duration() const { return m_duration; } unsigned int bitrate() const { return m_bitrate; } diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index 0a3482d74..bc0b888a2 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -154,7 +154,7 @@ Source::setAvatar( const QPixmap& avatar ) QPixmap -Source::avatar( AvatarStyle style, const QSize& size ) +Source::avatar( TomahawkUtils::ImageMode style, const QSize& size ) { if ( !m_avatar && m_avatarUpdated ) { @@ -172,14 +172,18 @@ Source::avatar( AvatarStyle style, const QSize& size ) m_avatarUpdated = false; } - if ( style == FancyStyle && m_avatar && !m_avatar->isNull() && !m_fancyAvatar ) + if ( style == TomahawkUtils::RoundedCorners && m_avatar && !m_avatar->isNull() && !m_fancyAvatar ) m_fancyAvatar = new QPixmap( TomahawkUtils::createRoundedImage( QPixmap( *m_avatar ), QSize( 0, 0 ) ) ); QPixmap pixmap; - if ( style == Original && m_avatar ) - pixmap = *m_avatar; - else if ( style == FancyStyle && m_fancyAvatar ) + if ( style == TomahawkUtils::RoundedCorners && m_fancyAvatar ) + { pixmap = *m_fancyAvatar; + } + else if ( m_avatar ) + { + pixmap = *m_avatar; + } if ( !pixmap.isNull() && !size.isEmpty() ) { diff --git a/src/libtomahawk/Source.h b/src/libtomahawk/Source.h index 1e57d4479..786d61a42 100644 --- a/src/libtomahawk/Source.h +++ b/src/libtomahawk/Source.h @@ -28,6 +28,7 @@ #include "network/DbSyncConnection.h" #include "Collection.h" #include "Query.h" +#include "utils/TomahawkUtils.h" #include "DllMacro.h" @@ -54,8 +55,6 @@ friend class ::DatabaseCommand_DeleteFiles; friend class ::MusicScanner; public: - enum AvatarStyle { Original, FancyStyle }; - explicit Source( int id, const QString& username = QString() ); virtual ~Source(); @@ -68,7 +67,7 @@ public: #ifndef ENABLE_HEADLESS void setAvatar( const QPixmap& avatar ); - QPixmap avatar( AvatarStyle style = Original, const QSize& size = QSize() ); + QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() ); #endif collection_ptr collection() const; @@ -164,7 +163,7 @@ private: mutable QPixmap* m_avatar; mutable QPixmap* m_fancyAvatar; mutable QByteArray m_avatarHash; - mutable QHash< AvatarStyle, QHash< int, QPixmap > > m_coverCache; + mutable QHash< TomahawkUtils::ImageMode, QHash< int, QPixmap > > m_coverCache; Tomahawk::playlistinterface_ptr m_playlistInterface; }; diff --git a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp index 0d20e1c38..a8ec08575 100644 --- a/src/libtomahawk/playlist/PlaylistItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistItemDelegate.cpp @@ -182,7 +182,7 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& if ( useAvatars ) { if ( !source.isNull() ) - pixmap = source->avatar( Source::FancyStyle, ir.size() ); + pixmap = source->avatar( TomahawkUtils::RoundedCorners, ir.size() ); } else pixmap = item->query()->cover( ir.size(), false ); @@ -192,7 +192,7 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem& if ( !useAvatars ) pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, ir.size() ); else - pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, TomahawkUtils::AvatarInFrame, ir.size() ); + pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, TomahawkUtils::RoundedCorners, ir.size() ); } painter->drawPixmap( ir, pixmap ); diff --git a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp index 390afd905..90d1200fc 100644 --- a/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp +++ b/src/libtomahawk/playlist/PlaylistLargeItemDelegate.cpp @@ -151,7 +151,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& source_ptr source = item->query()->playedBy().first; if ( m_mode == RecentlyPlayed && !source.isNull() ) { - avatar = source->avatar( Source::FancyStyle, avatarSize ); + avatar = source->avatar( TomahawkUtils::RoundedCorners, avatarSize ); QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ), true ); if ( source == SourceList::instance()->getLocal() ) @@ -244,12 +244,12 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& drawRichText( painter, option, leftRect, Qt::AlignBottom, textDoc ); const int sourceIconSize = avatarRect.width() - 6; - if ( !q->results().isEmpty() && !q->results().first()->sourceIcon( Result::DropShadow, QSize( sourceIconSize, sourceIconSize ) ).isNull() ) + if ( q->numResults() && !q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ).isNull() ) { - const QPixmap sourceIcon = q->results().first()->sourceIcon( Result::DropShadow, QSize( sourceIconSize, sourceIconSize ) ); + const QPixmap sourceIcon = q->results().first()->sourceIcon( TomahawkUtils::RoundedCorners, QSize( sourceIconSize, sourceIconSize ) ); painter->setOpacity( 0.8 ); - painter->drawPixmap( QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize/2, sourceIcon.width(), sourceIcon.height() ), sourceIcon ); - painter->setOpacity( 1. ); + painter->drawPixmap( QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, sourceIcon.width(), sourceIcon.height() ), sourceIcon ); + painter->setOpacity( 1.0 ); rightRect.moveLeft( rightRect.left() - sourceIcon.width() - 8 ); } diff --git a/src/libtomahawk/playlist/TreeModel.cpp b/src/libtomahawk/playlist/TreeModel.cpp index 9781eb099..05689836e 100644 --- a/src/libtomahawk/playlist/TreeModel.cpp +++ b/src/libtomahawk/playlist/TreeModel.cpp @@ -261,7 +261,7 @@ TreeModel::addCollection( const collection_ptr& collection ) connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); if ( !collection->source()->avatar().isNull() ) - setIcon( collection->source()->avatar( Source::FancyStyle ) ); + setIcon( collection->source()->avatar( TomahawkUtils::RoundedCorners ) ); if ( collection->source()->isLocal() ) setTitle( tr( "My Collection" ) ); diff --git a/src/libtomahawk/utils/TomahawkUtils.h b/src/libtomahawk/utils/TomahawkUtils.h index fef9539c8..65d52d6e9 100644 --- a/src/libtomahawk/utils/TomahawkUtils.h +++ b/src/libtomahawk/utils/TomahawkUtils.h @@ -56,9 +56,10 @@ namespace TomahawkUtils { Original, CoverInCase, - AvatarInFrame, ScaledCover, - Grid + Grid, + DropShadow, + RoundedCorners }; diff --git a/src/libtomahawk/utils/TomahawkUtilsGui.cpp b/src/libtomahawk/utils/TomahawkUtilsGui.cpp index 5e4823582..9c5eaa2d8 100644 --- a/src/libtomahawk/utils/TomahawkUtilsGui.cpp +++ b/src/libtomahawk/utils/TomahawkUtilsGui.cpp @@ -442,7 +442,7 @@ defaultPixmap( ImageType type, ImageMode mode, const QSize& size ) break; case DefaultSourceAvatar: - if ( mode == AvatarInFrame ) + if ( mode == RoundedCorners ) pixmap = TomahawkUtils::createRoundedImage( QPixmap( RESPATH "images/user-avatar.png" ), size ); else pixmap = QPixmap( RESPATH "images/user-avatar.png" ); diff --git a/src/libtomahawk/widgets/WelcomeWidget.cpp b/src/libtomahawk/widgets/WelcomeWidget.cpp index f6ab7f3fa..fdb621783 100644 --- a/src/libtomahawk/widgets/WelcomeWidget.cpp +++ b/src/libtomahawk/widgets/WelcomeWidget.cpp @@ -339,7 +339,7 @@ PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, } QRect r( option.rect.width() - option.fontMetrics.height() * 2.5 - 10, option.rect.top() + option.rect.height() / 3 - option.fontMetrics.height(), option.fontMetrics.height() * 2.5, option.fontMetrics.height() * 2.5 ); - QPixmap avatar = index.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->avatar( Source::FancyStyle, r.size() ); + QPixmap avatar = index.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->avatar( TomahawkUtils::RoundedCorners, r.size() ); if ( avatar.isNull() ) avatar = m_defaultAvatar; painter->drawPixmap( r, avatar ); diff --git a/src/sourcetree/items/SourceItem.cpp b/src/sourcetree/items/SourceItem.cpp index 3753ead25..c848793b9 100644 --- a/src/sourcetree/items/SourceItem.cpp +++ b/src/sourcetree/items/SourceItem.cpp @@ -206,7 +206,7 @@ SourceItem::pixmap( const QSize& size ) const if ( m_source->avatar().isNull() ) return m_defaultAvatar; else - return m_source->avatar( Source::FancyStyle, size ); + return m_source->avatar( TomahawkUtils::RoundedCorners, size ); } }