mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-17 04:21:22 +02:00
* ImageRegistry now supports opacity and pixmap tinting.
This commit is contained in:
@@ -48,7 +48,7 @@ ImageRegistry::icon( const QString& image, TomahawkUtils::ImageMode mode )
|
|||||||
|
|
||||||
|
|
||||||
QPixmap
|
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< qint64, QPixmap > subsubcache;
|
||||||
QHash< int, QHash< qint64, QPixmap > > subcache;
|
QHash< int, QHash< qint64, QPixmap > > subcache;
|
||||||
@@ -61,9 +61,9 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::I
|
|||||||
{
|
{
|
||||||
subsubcache = subcache.value( mode );
|
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 );
|
p.fill( Qt::transparent );
|
||||||
|
|
||||||
QPainter pixPainter( &p );
|
QPainter pixPainter( &p );
|
||||||
|
pixPainter.setOpacity( opacity );
|
||||||
svgRenderer.render( &pixPainter );
|
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;
|
pixmap = p;
|
||||||
}
|
}
|
||||||
@@ -99,7 +114,7 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::I
|
|||||||
if ( !size.isNull() && pixmap.size() != size )
|
if ( !size.isNull() && pixmap.size() != size )
|
||||||
pixmap = pixmap.scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
pixmap = pixmap.scaled( size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||||
|
|
||||||
putInCache( image, size, mode, pixmap );
|
putInCache( image, size, mode, opacity, pixmap );
|
||||||
}
|
}
|
||||||
|
|
||||||
return pixmap;
|
return pixmap;
|
||||||
@@ -107,7 +122,7 @@ ImageRegistry::pixmap( const QString& image, const QSize& size, TomahawkUtils::I
|
|||||||
|
|
||||||
|
|
||||||
void
|
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;
|
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 );
|
subcache.insert( mode, subsubcache );
|
||||||
s_cache.insert( image, subcache );
|
s_cache.insert( image, subcache );
|
||||||
}
|
}
|
||||||
|
@@ -31,10 +31,10 @@ public:
|
|||||||
explicit ImageRegistry();
|
explicit ImageRegistry();
|
||||||
|
|
||||||
QIcon icon( const QString& image, TomahawkUtils::ImageMode mode = TomahawkUtils::Original );
|
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:
|
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;
|
static ImageRegistry* s_instance;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user