mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 08:19:42 +01:00
* Consolidate Result's and Source's image modes into TomahawkUtils::ImageMode.
This commit is contained in:
parent
a329eb4940
commit
580b18c561
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QtCore/QVariant>
|
||||
#include <QMutex>
|
||||
|
||||
#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; }
|
||||
|
@ -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() )
|
||||
{
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -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" ) );
|
||||
|
@ -56,9 +56,10 @@ namespace TomahawkUtils
|
||||
{
|
||||
Original,
|
||||
CoverInCase,
|
||||
AvatarInFrame,
|
||||
ScaledCover,
|
||||
Grid
|
||||
Grid,
|
||||
DropShadow,
|
||||
RoundedCorners
|
||||
};
|
||||
|
||||
|
||||
|
@ -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" );
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user