mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
* Added global common image cache.
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 15 KiB |
Binary file not shown.
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 7.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 12 KiB |
@@ -100,8 +100,6 @@ AudioControls::AudioControls( QWidget* parent )
|
||||
m_sliderTimeLine.setCurveShape( QTimeLine::LinearCurve );
|
||||
ui->seekSlider->setTimeLine( &m_sliderTimeLine );
|
||||
|
||||
m_defaultCover = QPixmap( RESPATH "images/no-album-no-case.png" ).scaled( ui->coverImage->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||
|
||||
connect( &m_phononTickCheckTimer, SIGNAL( timeout() ), SLOT( phononTickCheckTimeout() ) );
|
||||
connect( &m_sliderTimeLine, SIGNAL( frameChanged( int ) ), ui->seekSlider, SLOT( setValue( int ) ) );
|
||||
|
||||
@@ -271,7 +269,7 @@ AudioControls::setAlbumCover()
|
||||
ui->coverImage->setPixmap( cover );
|
||||
}
|
||||
else
|
||||
ui->coverImage->setPixmap( m_defaultCover );
|
||||
ui->coverImage->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::ScaledCover, ui->coverImage->size() ) );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -91,8 +91,6 @@ private:
|
||||
|
||||
Ui::AudioControls *ui;
|
||||
|
||||
QPixmap m_defaultCover;
|
||||
|
||||
Tomahawk::result_ptr m_currentTrack;
|
||||
Tomahawk::PlaylistInterface::RepeatMode m_repeatMode;
|
||||
bool m_shuffled;
|
||||
|
@@ -122,29 +122,29 @@ Album::cover( const QSize& size, bool forceLoad ) const
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||
}
|
||||
|
||||
if ( !m_cover )
|
||||
m_cover = new QPixmap();
|
||||
|
||||
if ( m_cover->isNull() && !m_coverBuffer.isEmpty() )
|
||||
if ( !m_cover && !m_coverBuffer.isEmpty() )
|
||||
{
|
||||
m_cover = new QPixmap();
|
||||
m_cover->loadFromData( m_coverBuffer );
|
||||
}
|
||||
|
||||
if ( !m_cover->isNull() && !size.isEmpty() )
|
||||
if ( m_cover && !m_cover->isNull() && !size.isEmpty() )
|
||||
{
|
||||
if ( m_coverCache.contains( size.width() ) )
|
||||
{
|
||||
return m_coverCache.value( size.width() );
|
||||
}
|
||||
else
|
||||
{
|
||||
QPixmap scaledCover;
|
||||
scaledCover = m_cover->scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||
m_coverCache.insert( size.width(), scaledCover );
|
||||
}
|
||||
|
||||
QPixmap scaledCover;
|
||||
scaledCover = m_cover->scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||
m_coverCache.insert( size.width(), scaledCover );
|
||||
return scaledCover;
|
||||
}
|
||||
|
||||
return *m_cover;
|
||||
if ( m_cover )
|
||||
return *m_cover;
|
||||
else
|
||||
return QPixmap();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -113,29 +113,29 @@ Artist::cover( const QSize& size, bool forceLoad ) const
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||
}
|
||||
|
||||
if ( !m_cover )
|
||||
m_cover = new QPixmap();
|
||||
|
||||
if ( m_cover->isNull() && !m_coverBuffer.isEmpty() )
|
||||
if ( !m_cover && !m_coverBuffer.isEmpty() )
|
||||
{
|
||||
m_cover = new QPixmap();
|
||||
m_cover->loadFromData( m_coverBuffer );
|
||||
}
|
||||
|
||||
if ( !m_cover->isNull() && !size.isEmpty() )
|
||||
if ( m_cover && !m_cover->isNull() && !size.isEmpty() )
|
||||
{
|
||||
if ( m_coverCache.contains( size.width() ) )
|
||||
{
|
||||
return m_coverCache.value( size.width() );
|
||||
}
|
||||
else
|
||||
{
|
||||
QPixmap scaledCover;
|
||||
scaledCover = m_cover->scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||
m_coverCache.insert( size.width(), scaledCover );
|
||||
}
|
||||
|
||||
QPixmap scaledCover;
|
||||
scaledCover = m_cover->scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
|
||||
m_coverCache.insert( size.width(), scaledCover );
|
||||
return scaledCover;
|
||||
}
|
||||
|
||||
return *m_cover;
|
||||
if ( m_cover )
|
||||
return *m_cover;
|
||||
else
|
||||
return QPixmap();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -40,7 +40,6 @@ AlbumItemDelegate::AlbumItemDelegate( QAbstractItemView* parent, AlbumProxyModel
|
||||
, m_view( parent )
|
||||
, m_model( proxy )
|
||||
{
|
||||
m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" );
|
||||
}
|
||||
|
||||
|
||||
@@ -94,15 +93,14 @@ AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
if ( !item->album().isNull() )
|
||||
{
|
||||
cover = item->album()->cover( r.size() );
|
||||
if ( cover.isNull() )
|
||||
cover = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::CoverInCase, r.size() );
|
||||
}
|
||||
else if ( !item->artist().isNull() )
|
||||
{
|
||||
cover = item->artist()->cover( r.size() );
|
||||
}
|
||||
|
||||
if ( cover.isNull() )
|
||||
cover = m_defaultCover;
|
||||
|
||||
if ( option.state & QStyle::State_Selected )
|
||||
{
|
||||
#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
|
||||
|
@@ -53,7 +53,6 @@ private:
|
||||
QPersistentModelIndex m_hoveringOver;
|
||||
|
||||
QPixmap m_shadowPixmap;
|
||||
QPixmap m_defaultCover;
|
||||
};
|
||||
|
||||
#endif // ALBUMITEMDELEGATE_H
|
||||
|
@@ -156,18 +156,14 @@ TreeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option,
|
||||
if ( !item->album().isNull() )
|
||||
{
|
||||
cover = item->album()->cover( r.size(), false );
|
||||
if ( cover.isNull() )
|
||||
cover = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultAlbumCover, TomahawkUtils::ScaledCover, r.size() );
|
||||
}
|
||||
else if ( !item->artist().isNull() )
|
||||
{
|
||||
cover = item->artist()->cover( r.size(), false );
|
||||
}
|
||||
|
||||
if ( cover.isNull() )
|
||||
{
|
||||
if ( !item->artist().isNull() )
|
||||
cover = m_defaultArtistImage;
|
||||
else
|
||||
cover = m_defaultAlbumCover;
|
||||
if ( cover.isNull() )
|
||||
cover = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::ScaledCover, r.size() );
|
||||
}
|
||||
|
||||
painter->drawPixmap( r, cover );
|
||||
|
@@ -42,6 +42,18 @@ namespace TomahawkUtils
|
||||
MediaTypeTrack
|
||||
};
|
||||
|
||||
enum ImageType
|
||||
{
|
||||
DefaultAlbumCover,
|
||||
DefaultArtistImage
|
||||
};
|
||||
enum ImageMode
|
||||
{
|
||||
NoDefaultCover,
|
||||
CoverInCase,
|
||||
ScaledCover
|
||||
};
|
||||
|
||||
class DLLEXPORT NetworkProxyFactory : public QNetworkProxyFactory
|
||||
{
|
||||
public:
|
||||
|
@@ -36,6 +36,8 @@
|
||||
#include <windowsx.h>
|
||||
#endif
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
namespace TomahawkUtils
|
||||
{
|
||||
static int s_headerHeight = 0;
|
||||
@@ -83,15 +85,15 @@ createDragPixmap( MediaType type, int itemCount )
|
||||
QPixmap pixmap;
|
||||
switch ( type )
|
||||
{
|
||||
case MediaTypeArtist:
|
||||
pixmap = QPixmap( ":/data/images/artist-icon.png" ).scaledToWidth( size, Qt::SmoothTransformation );
|
||||
break;
|
||||
case MediaTypeAlbum:
|
||||
pixmap = QPixmap( ":/data/images/album-icon.png" ).scaledToWidth( size, Qt::SmoothTransformation );
|
||||
break;
|
||||
case MediaTypeTrack:
|
||||
pixmap = QPixmap( QString( ":/data/images/track-icon-%2x%2.png" ).arg( size ) );
|
||||
break;
|
||||
case MediaTypeArtist:
|
||||
pixmap = QPixmap( ":/data/images/artist-icon.png" ).scaledToWidth( size, Qt::SmoothTransformation );
|
||||
break;
|
||||
case MediaTypeAlbum:
|
||||
pixmap = QPixmap( ":/data/images/album-icon.png" ).scaledToWidth( size, Qt::SmoothTransformation );
|
||||
break;
|
||||
case MediaTypeTrack:
|
||||
pixmap = QPixmap( QString( ":/data/images/track-icon-%2x%2.png" ).arg( size ) );
|
||||
break;
|
||||
}
|
||||
|
||||
int x = 0;
|
||||
@@ -303,4 +305,59 @@ alphaBlend( const QColor& colorFrom, const QColor& colorTo, float opacity )
|
||||
return QColor( r, g, b );
|
||||
}
|
||||
|
||||
|
||||
QPixmap
|
||||
defaultPixmap( ImageType type, ImageMode mode, const QSize& size )
|
||||
{
|
||||
QPixmap pixmap;
|
||||
QHash< int, QPixmap > subsubcache;
|
||||
QHash< int, QHash< int, QPixmap > > subcache;
|
||||
static QHash< int, QHash< int, QHash< int, QPixmap > > > cache;
|
||||
|
||||
if ( cache.contains( type ) )
|
||||
{
|
||||
subcache = cache.value( type );
|
||||
|
||||
if ( subcache.contains( mode ) )
|
||||
{
|
||||
subsubcache = subcache.value( mode );
|
||||
|
||||
if ( subsubcache.contains( size.width() ) )
|
||||
return subsubcache.value( size.width() );
|
||||
}
|
||||
}
|
||||
|
||||
switch ( type )
|
||||
{
|
||||
case DefaultAlbumCover:
|
||||
if ( mode == CoverInCase )
|
||||
pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" );
|
||||
else
|
||||
pixmap = QPixmap( RESPATH "images/no-album-no-case.png" );
|
||||
break;
|
||||
|
||||
case DefaultArtistImage:
|
||||
pixmap = QPixmap( RESPATH "images/no-artist-image-placeholder.png" );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ( pixmap.isNull() )
|
||||
{
|
||||
Q_ASSERT( false );
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
if ( !size.isNull() )
|
||||
pixmap = pixmap.scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||
|
||||
subsubcache.insert( size.width(), pixmap );
|
||||
subcache.insert( mode, subsubcache );
|
||||
cache.insert( type, subcache );
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
} // ns
|
||||
|
@@ -19,6 +19,8 @@
|
||||
#ifndef TOMAHAWKUTILSGUI_H
|
||||
#define TOMAHAWKUTILSGUI_H
|
||||
|
||||
#include <QSize>
|
||||
|
||||
#include "tomahawkutils.h"
|
||||
#include "dllmacro.h"
|
||||
|
||||
@@ -46,6 +48,8 @@ namespace TomahawkUtils
|
||||
|
||||
DLLEXPORT int headerHeight();
|
||||
DLLEXPORT void setHeaderHeight( int height );
|
||||
|
||||
DLLEXPORT QPixmap defaultPixmap( ImageType type, ImageMode mode, const QSize& size = QSize( 0, 0 ) );
|
||||
}
|
||||
|
||||
#endif // TOMAHAWKUTILSGUI_H
|
||||
|
@@ -61,7 +61,7 @@ AlbumInfoWidget::AlbumInfoWidget( const Tomahawk::album_ptr& album, ModelMode st
|
||||
ui->tracksView->setTreeModel( m_tracksModel );
|
||||
ui->tracksView->setRootIsDecorated( false );
|
||||
|
||||
m_pixmap = QPixmap( RESPATH "images/no-album-art-placeholder.png" ).scaledToWidth( 48, Qt::SmoothTransformation );
|
||||
m_pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::ScaledCover, QSize( 48, 48 ) );
|
||||
|
||||
m_button = new OverlayButton( ui->tracksView );
|
||||
m_button->setCheckable( true );
|
||||
|
@@ -77,7 +77,7 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
|
||||
ui->topHits->setTrackModel( m_topHitsModel );
|
||||
ui->topHits->setSortingEnabled( false );
|
||||
|
||||
m_pixmap = QPixmap( RESPATH "images/no-album-no-case.png" ).scaledToWidth( 48, Qt::SmoothTransformation );
|
||||
m_pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultArtistImage, TomahawkUtils::ScaledCover, QSize( 48, 48 ) );
|
||||
|
||||
m_button = new OverlayButton( ui->albums );
|
||||
m_button->setText( tr( "Click to show Super Collection Albums" ) );
|
||||
|
Reference in New Issue
Block a user