mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-13 20:39:57 +01:00
* ImageRegistry now supports opacity and pixmap tinting.
This commit is contained in:
parent
1181e18feb
commit
a306f9a2d4
@ -48,7 +48,7 @@ ImageRegistry::icon( const QString& image, TomahawkUtils::ImageMode mode )
|
||||
|
||||
|
||||
QPixmap
|
||||
ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode )
|
||||
ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, QColor tint )
|
||||
{
|
||||
QHash< qint64, QPixmap > subsubcache;
|
||||
QHash< int, QHash< qint64, QPixmap > > subcache;
|
||||
@ -61,9 +61,9 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::I
|
||||
{
|
||||
subsubcache = subcache.value( mode );
|
||||
|
||||
if ( subsubcache.contains( size.width() * size.height() ) )
|
||||
if ( subsubcache.contains( size.width() * 100 + size.height() * 10 + ( opacity * 100.0 ) ) )
|
||||
{
|
||||
return subsubcache.value( size.width() * size.height() );
|
||||
return subsubcache.value( size.width() * 100 + size.height() * 10 + ( opacity * 100.0 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,7 +77,22 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::I
|
||||
p.fill( Qt::transparent );
|
||||
|
||||
QPainter pixPainter( &p );
|
||||
pixPainter.setOpacity( opacity );
|
||||
svgRenderer.render( &pixPainter );
|
||||
pixPainter.end();
|
||||
|
||||
if ( tint.alpha() > 0 )
|
||||
{
|
||||
QImage resultImage( p.size(), QImage::Format_ARGB32_Premultiplied );
|
||||
QPainter painter( &resultImage );
|
||||
painter.drawPixmap( 0, 0, p );
|
||||
painter.setCompositionMode( QPainter::CompositionMode_Screen );
|
||||
painter.fillRect( resultImage.rect(), tint );
|
||||
painter.end();
|
||||
|
||||
resultImage.setAlphaChannel( p.toImage().alphaChannel() );
|
||||
p = QPixmap::fromImage( resultImage );
|
||||
}
|
||||
|
||||
pixmap = p;
|
||||
}
|
||||
@ -99,7 +114,7 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::I
|
||||
if ( !size.isNull() && pixmap.size() != size )
|
||||
pixmap = pixmap.scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||
|
||||
putInCache( image, size, mode, pixmap );
|
||||
putInCache( image, size, mode, opacity, pixmap );
|
||||
}
|
||||
|
||||
return pixmap;
|
||||
@ -107,7 +122,7 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::I
|
||||
|
||||
|
||||
void
|
||||
ImageRegistry::putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, const QPixmap& pixmap )
|
||||
ImageRegistry::putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, const QPixmap& pixmap )
|
||||
{
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding to image cache:" << image << size << mode;
|
||||
|
||||
@ -129,7 +144,7 @@ ImageRegistry::putInCache( const QString& image, const QSize& size, TomahawkUtil
|
||||
}
|
||||
}
|
||||
|
||||
subsubcache.insert( size.width() * size.height(), pixmap );
|
||||
subsubcache.insert( size.width() * 100 + size.height() * 10 + ( opacity * 100.0 ), pixmap );
|
||||
subcache.insert( mode, subsubcache );
|
||||
s_cache.insert( image, subcache );
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ public:
|
||||
explicit ImageRegistry();
|
||||
|
||||
QIcon icon( const QString& image, TomahawkUtils::ImageMode mode = TomahawkUtils::Original );
|
||||
QPixmap pixmap( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode = TomahawkUtils::Original );
|
||||
QPixmap pixmap( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode = TomahawkUtils::Original, float opacity = 1.0, QColor tint = QColor( 0, 0, 0, 0 ) );
|
||||
|
||||
private:
|
||||
void putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, const QPixmap& pixmap );
|
||||
void putInCache( const QString& image, const QSize& size, TomahawkUtils::ImageMode mode, float opacity, const QPixmap& pixmap );
|
||||
|
||||
static ImageRegistry* s_instance;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user