mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Consolidate Result's and Source's image modes into TomahawkUtils::ImageMode.
This commit is contained in:
@@ -283,9 +283,11 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
|
|||||||
|
|
||||||
onControlStateChanged();
|
onControlStateChanged();
|
||||||
|
|
||||||
QPixmap sourceIcon = result->sourceIcon( Result::Plain, ui->ownerButton->size() );
|
QPixmap sourceIcon = result->sourceIcon( TomahawkUtils::RoundedCorners, ui->ownerButton->size() );
|
||||||
if ( !sourceIcon.isNull() )
|
if ( !sourceIcon.isNull() )
|
||||||
|
{
|
||||||
ui->ownerButton->setPixmap( sourceIcon );
|
ui->ownerButton->setPixmap( sourceIcon );
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui->ownerButton->clear();
|
ui->ownerButton->clear();
|
||||||
|
@@ -42,7 +42,7 @@ 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, Result::SourceImageStyle style )
|
inline QString sourceCacheKey( Resolver* resolver, const QSize& size, TomahawkUtils::ImageMode style )
|
||||||
{
|
{
|
||||||
QString str;
|
QString str;
|
||||||
QTextStream stream( &str );
|
QTextStream stream( &str );
|
||||||
@@ -50,6 +50,7 @@ inline QString sourceCacheKey( Resolver* resolver, const QSize& size, Result::So
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Tomahawk::result_ptr
|
Tomahawk::result_ptr
|
||||||
Result::get( const QString& url )
|
Result::get( const QString& url )
|
||||||
{
|
{
|
||||||
@@ -192,7 +193,6 @@ 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( 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() );
|
||||||
@@ -316,24 +316,40 @@ Result::friendlySource() const
|
|||||||
|
|
||||||
|
|
||||||
QPixmap
|
QPixmap
|
||||||
Result::sourceIcon( SourceImageStyle style, const QSize& desiredSize ) const
|
Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) const
|
||||||
{
|
{
|
||||||
if ( collection().isNull() )
|
if ( collection().isNull() )
|
||||||
{
|
{
|
||||||
const ExternalResolverGui* guiResolver = qobject_cast< ExternalResolverGui* >( m_resolvedBy.data() );
|
const ExternalResolverGui* guiResolver = qobject_cast< ExternalResolverGui* >( m_resolvedBy.data() );
|
||||||
if ( !guiResolver )
|
if ( !guiResolver )
|
||||||
|
{
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QMutexLocker l( &s_sourceIconMutex );
|
QMutexLocker l( &s_sourceIconMutex );
|
||||||
|
|
||||||
const QString key = sourceCacheKey( m_resolvedBy.data(), desiredSize, style );
|
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 )
|
|
||||||
|
switch ( style )
|
||||||
|
{
|
||||||
|
case TomahawkUtils::DropShadow:
|
||||||
pixmap = TomahawkUtils::addDropShadow( pixmap, QSize() );
|
pixmap = TomahawkUtils::addDropShadow( pixmap, QSize() );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TomahawkUtils::RoundedCorners:
|
||||||
|
pixmap = TomahawkUtils::createRoundedImage( pixmap, QSize() );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
sourceIconCache()->insert( key, pixmap );
|
sourceIconCache()->insert( key, pixmap );
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
@@ -345,10 +361,10 @@ Result::sourceIcon( SourceImageStyle style, const QSize& desiredSize ) const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QPixmap avatar = collection()->source()->avatar( Source::FancyStyle, desiredSize );
|
QPixmap avatar = collection()->source()->avatar( TomahawkUtils::RoundedCorners, desiredSize );
|
||||||
if ( !avatar )
|
if ( !avatar )
|
||||||
{
|
{
|
||||||
avatar = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, TomahawkUtils::AvatarInFrame, desiredSize );
|
avatar = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, TomahawkUtils::RoundedCorners, desiredSize );
|
||||||
}
|
}
|
||||||
return avatar;
|
return avatar;
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include <QtCore/QVariant>
|
#include <QtCore/QVariant>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
|
#include "utils/TomahawkUtils.h"
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
@@ -52,11 +53,6 @@ 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();
|
||||||
@@ -83,7 +79,7 @@ public:
|
|||||||
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;
|
QPixmap sourceIcon( TomahawkUtils::ImageMode 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; }
|
||||||
|
@@ -154,7 +154,7 @@ Source::setAvatar( const QPixmap& avatar )
|
|||||||
|
|
||||||
|
|
||||||
QPixmap
|
QPixmap
|
||||||
Source::avatar( AvatarStyle style, const QSize& size )
|
Source::avatar( TomahawkUtils::ImageMode style, const QSize& size )
|
||||||
{
|
{
|
||||||
if ( !m_avatar && m_avatarUpdated )
|
if ( !m_avatar && m_avatarUpdated )
|
||||||
{
|
{
|
||||||
@@ -172,14 +172,18 @@ Source::avatar( AvatarStyle style, const QSize& size )
|
|||||||
m_avatarUpdated = false;
|
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 ) ) );
|
m_fancyAvatar = new QPixmap( TomahawkUtils::createRoundedImage( QPixmap( *m_avatar ), QSize( 0, 0 ) ) );
|
||||||
|
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
if ( style == Original && m_avatar )
|
if ( style == TomahawkUtils::RoundedCorners && m_fancyAvatar )
|
||||||
pixmap = *m_avatar;
|
{
|
||||||
else if ( style == FancyStyle && m_fancyAvatar )
|
|
||||||
pixmap = *m_fancyAvatar;
|
pixmap = *m_fancyAvatar;
|
||||||
|
}
|
||||||
|
else if ( m_avatar )
|
||||||
|
{
|
||||||
|
pixmap = *m_avatar;
|
||||||
|
}
|
||||||
|
|
||||||
if ( !pixmap.isNull() && !size.isEmpty() )
|
if ( !pixmap.isNull() && !size.isEmpty() )
|
||||||
{
|
{
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include "network/DbSyncConnection.h"
|
#include "network/DbSyncConnection.h"
|
||||||
#include "Collection.h"
|
#include "Collection.h"
|
||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
|
#include "utils/TomahawkUtils.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
@@ -54,8 +55,6 @@ friend class ::DatabaseCommand_DeleteFiles;
|
|||||||
friend class ::MusicScanner;
|
friend class ::MusicScanner;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum AvatarStyle { Original, FancyStyle };
|
|
||||||
|
|
||||||
explicit Source( int id, const QString& username = QString() );
|
explicit Source( int id, const QString& username = QString() );
|
||||||
virtual ~Source();
|
virtual ~Source();
|
||||||
|
|
||||||
@@ -68,7 +67,7 @@ public:
|
|||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
void setAvatar( const QPixmap& avatar );
|
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
|
#endif
|
||||||
|
|
||||||
collection_ptr collection() const;
|
collection_ptr collection() const;
|
||||||
@@ -164,7 +163,7 @@ private:
|
|||||||
mutable QPixmap* m_avatar;
|
mutable QPixmap* m_avatar;
|
||||||
mutable QPixmap* m_fancyAvatar;
|
mutable QPixmap* m_fancyAvatar;
|
||||||
mutable QByteArray m_avatarHash;
|
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;
|
Tomahawk::playlistinterface_ptr m_playlistInterface;
|
||||||
};
|
};
|
||||||
|
@@ -182,7 +182,7 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
if ( useAvatars )
|
if ( useAvatars )
|
||||||
{
|
{
|
||||||
if ( !source.isNull() )
|
if ( !source.isNull() )
|
||||||
pixmap = source->avatar( Source::FancyStyle, ir.size() );
|
pixmap = source->avatar( TomahawkUtils::RoundedCorners, ir.size() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pixmap = item->query()->cover( ir.size(), false );
|
pixmap = item->query()->cover( ir.size(), false );
|
||||||
@@ -192,7 +192,7 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
if ( !useAvatars )
|
if ( !useAvatars )
|
||||||
pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, ir.size() );
|
pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, ir.size() );
|
||||||
else
|
else
|
||||||
pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, TomahawkUtils::AvatarInFrame, ir.size() );
|
pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultSourceAvatar, TomahawkUtils::RoundedCorners, ir.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->drawPixmap( ir, pixmap );
|
painter->drawPixmap( ir, pixmap );
|
||||||
|
@@ -151,7 +151,7 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
source_ptr source = item->query()->playedBy().first;
|
source_ptr source = item->query()->playedBy().first;
|
||||||
if ( m_mode == RecentlyPlayed && !source.isNull() )
|
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 );
|
QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ), true );
|
||||||
|
|
||||||
if ( source == SourceList::instance()->getLocal() )
|
if ( source == SourceList::instance()->getLocal() )
|
||||||
@@ -244,12 +244,12 @@ PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem&
|
|||||||
drawRichText( painter, option, leftRect, Qt::AlignBottom, textDoc );
|
drawRichText( painter, option, leftRect, Qt::AlignBottom, textDoc );
|
||||||
|
|
||||||
const int sourceIconSize = avatarRect.width() - 6;
|
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->setOpacity( 0.8 );
|
||||||
painter->drawPixmap( QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize/2, sourceIcon.width(), sourceIcon.height() ), sourceIcon );
|
painter->drawPixmap( QRect( rightRect.right() - sourceIconSize, r.center().y() - sourceIconSize / 2, sourceIcon.width(), sourceIcon.height() ), sourceIcon );
|
||||||
painter->setOpacity( 1. );
|
painter->setOpacity( 1.0 );
|
||||||
rightRect.moveLeft( rightRect.left() - sourceIcon.width() - 8 );
|
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 );
|
connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection );
|
||||||
|
|
||||||
if ( !collection->source()->avatar().isNull() )
|
if ( !collection->source()->avatar().isNull() )
|
||||||
setIcon( collection->source()->avatar( Source::FancyStyle ) );
|
setIcon( collection->source()->avatar( TomahawkUtils::RoundedCorners ) );
|
||||||
|
|
||||||
if ( collection->source()->isLocal() )
|
if ( collection->source()->isLocal() )
|
||||||
setTitle( tr( "My Collection" ) );
|
setTitle( tr( "My Collection" ) );
|
||||||
|
@@ -56,9 +56,10 @@ namespace TomahawkUtils
|
|||||||
{
|
{
|
||||||
Original,
|
Original,
|
||||||
CoverInCase,
|
CoverInCase,
|
||||||
AvatarInFrame,
|
|
||||||
ScaledCover,
|
ScaledCover,
|
||||||
Grid
|
Grid,
|
||||||
|
DropShadow,
|
||||||
|
RoundedCorners
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@@ -442,7 +442,7 @@ defaultPixmap( ImageType type, ImageMode mode, const QSize& size )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DefaultSourceAvatar:
|
case DefaultSourceAvatar:
|
||||||
if ( mode == AvatarInFrame )
|
if ( mode == RoundedCorners )
|
||||||
pixmap = TomahawkUtils::createRoundedImage( QPixmap( RESPATH "images/user-avatar.png" ), size );
|
pixmap = TomahawkUtils::createRoundedImage( QPixmap( RESPATH "images/user-avatar.png" ), size );
|
||||||
else
|
else
|
||||||
pixmap = QPixmap( RESPATH "images/user-avatar.png" );
|
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 );
|
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() )
|
if ( avatar.isNull() )
|
||||||
avatar = m_defaultAvatar;
|
avatar = m_defaultAvatar;
|
||||||
painter->drawPixmap( r, avatar );
|
painter->drawPixmap( r, avatar );
|
||||||
|
@@ -206,7 +206,7 @@ SourceItem::pixmap( const QSize& size ) const
|
|||||||
if ( m_source->avatar().isNull() )
|
if ( m_source->avatar().isNull() )
|
||||||
return m_defaultAvatar;
|
return m_defaultAvatar;
|
||||||
else
|
else
|
||||||
return m_source->avatar( Source::FancyStyle, size );
|
return m_source->avatar( TomahawkUtils::RoundedCorners, size );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user