mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 22:56:42 +02:00
* Added createRoundedImage, which surprisingly creates rounded images.
This commit is contained in:
@@ -310,13 +310,44 @@ openUrl( const QUrl& url )
|
|||||||
|
|
||||||
|
|
||||||
QPixmap
|
QPixmap
|
||||||
createAvatarFrame( const QPixmap &avatar )
|
createRoundedImage( const QPixmap& pixmap, const QSize& size, float frameWidthPct )
|
||||||
{
|
{
|
||||||
QPixmap frame( ":/data/images/avatar_frame.png" );
|
int height;
|
||||||
QPixmap scaledAvatar = avatar.scaled( frame.height() * 75 / 100, frame.width() * 75 / 100, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
int width;
|
||||||
|
|
||||||
|
if ( !size.isEmpty() )
|
||||||
|
{
|
||||||
|
height = size.height();
|
||||||
|
width = size.width();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
height = pixmap.height();
|
||||||
|
width = pixmap.width();
|
||||||
|
}
|
||||||
|
|
||||||
|
int frameWidth = (float)width * frameWidthPct;
|
||||||
|
|
||||||
|
QPixmap scaledAvatar = pixmap.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||||
|
QPixmap frame( width, height );
|
||||||
|
frame.fill( Qt::transparent );
|
||||||
|
|
||||||
QPainter painter( &frame );
|
QPainter painter( &frame );
|
||||||
painter.drawPixmap( ( frame.height() - scaledAvatar.height() ) / 2, ( frame.width() - scaledAvatar.width() ) / 2, scaledAvatar );
|
painter.setRenderHint( QPainter::Antialiasing );
|
||||||
|
|
||||||
|
QRect outerRect( 0, 0, width, height );
|
||||||
|
QBrush brush( scaledAvatar );
|
||||||
|
QPen pen;
|
||||||
|
pen.setColor( Qt::transparent );
|
||||||
|
pen.setJoinStyle( Qt::RoundJoin );
|
||||||
|
|
||||||
|
painter.setBrush( brush );
|
||||||
|
painter.setPen( pen );
|
||||||
|
painter.drawRoundedRect( outerRect, frameWidth * 2, frameWidth * 2 );
|
||||||
|
|
||||||
|
/* painter.setBrush( Qt::transparent );
|
||||||
|
painter.setPen( Qt::white );
|
||||||
|
painter.drawRoundedRect( outerRect, frameWidth * 2, frameWidth * 2 ); */
|
||||||
|
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
@@ -408,7 +439,7 @@ defaultPixmap( ImageType type, ImageMode mode, const QSize& size )
|
|||||||
|
|
||||||
case DefaultSourceAvatar:
|
case DefaultSourceAvatar:
|
||||||
if ( mode == AvatarInFrame )
|
if ( mode == AvatarInFrame )
|
||||||
pixmap = TomahawkUtils::createAvatarFrame( QPixmap( RESPATH "images/user-avatar.png" ) );
|
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" );
|
||||||
break;
|
break;
|
||||||
|
@@ -48,7 +48,7 @@ namespace TomahawkUtils
|
|||||||
|
|
||||||
DLLEXPORT void openUrl( const QUrl& url );
|
DLLEXPORT void openUrl( const QUrl& url );
|
||||||
|
|
||||||
DLLEXPORT QPixmap createAvatarFrame( const QPixmap &avatar );
|
DLLEXPORT QPixmap createRoundedImage( const QPixmap& avatar, const QSize& size, float frameWidthPct = 0.10 );
|
||||||
|
|
||||||
DLLEXPORT QColor alphaBlend( const QColor& colorFrom, const QColor& colorTo, float opacity );
|
DLLEXPORT QColor alphaBlend( const QColor& colorFrom, const QColor& colorTo, float opacity );
|
||||||
DLLEXPORT QPixmap createDragPixmap( MediaType type, int itemCount = 1 );
|
DLLEXPORT QPixmap createDragPixmap( MediaType type, int itemCount = 1 );
|
||||||
|
Reference in New Issue
Block a user