1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

* Fancy avatars are now scaled ignoring the aspect ratio. This fixed some odd clipping issues.

This commit is contained in:
Christian Muehlhaeuser 2012-06-06 16:40:06 +02:00
parent 06d79cd788
commit 43d2bb7716
2 changed files with 35 additions and 13 deletions

View File

@ -62,23 +62,24 @@ createDragPixmap( MediaType type, int itemCount )
{
xCount = 5;
size = 16;
} else if( itemCount > 9 )
}
else if( itemCount > 9 )
{
xCount = 4;
size = 22;
}
if( itemCount < xCount )
if ( itemCount < xCount )
{
xCount = itemCount;
}
int yCount = itemCount / xCount;
if( itemCount % xCount != 0 )
if ( itemCount % xCount != 0 )
{
++yCount;
}
if( yCount > xCount )
if ( yCount > xCount )
{
yCount = xCount;
}
@ -105,7 +106,7 @@ createDragPixmap( MediaType type, int itemCount )
int x = 0;
int y = 0;
for( int i = 0; i < itemCount; ++i )
for ( int i = 0; i < itemCount; ++i )
{
painter.drawPixmap( x, y, pixmap );
@ -126,9 +127,29 @@ createDragPixmap( MediaType type, int itemCount )
}
void
drawShadowText( QPainter* painter, const QRect& rect, const QString& text, const QTextOption& textOption )
{
painter->save();
painter->drawText( rect, text, textOption );
/* QFont font = painter->font();
font.setPixelSize( font.pixelSize() + 2 );
painter->setFont( font );
painter->setPen( Qt::black );
painter->drawText( rect, text, textOption );*/
painter->restore();
}
void
drawBackgroundAndNumbers( QPainter* painter, const QString& text, const QRect& figRectIn )
{
painter->save();
QRect figRect = figRectIn;
if ( text.length() == 1 )
figRect.adjust( -painter->fontMetrics().averageCharWidth(), 0, 0, 0 );
@ -155,15 +176,13 @@ drawBackgroundAndNumbers( QPainter* painter, const QString& text, const QRect& f
ppath.arcTo( leftArcRect, 270, 180 );
painter->drawPath( ppath );
painter->setPen( origpen );
#ifdef Q_WS_MAC
figRect.adjust( -1, 0, 0, 0 );
#endif
QTextOption to( Qt::AlignCenter );
painter->setPen( origpen );
painter->setPen( Qt::white );
painter->drawText( figRect.adjusted( -5, 0, 6, 0 ), text, to );
painter->drawText( figRect.adjusted( -5, 0, 6, 0 ), text, QTextOption( Qt::AlignCenter ) );
painter->restore();
}
@ -277,10 +296,10 @@ QPixmap
createAvatarFrame( const QPixmap &avatar )
{
QPixmap frame( ":/data/images/avatar_frame.png" );
QPixmap scaledAvatar = avatar.scaled( frame.height() * 75 / 100, frame.width() * 75 / 100, Qt::KeepAspectRatio, Qt::SmoothTransformation );
QPixmap scaledAvatar = avatar.scaled( frame.height() * 75 / 100, frame.width() * 75 / 100, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
QPainter painter( &frame );
painter.drawPixmap( (frame.height() - scaledAvatar.height()) / 2, (frame.width() - scaledAvatar.width()) / 2, scaledAvatar );
painter.drawPixmap( ( frame.height() - scaledAvatar.height() ) / 2, ( frame.width() - scaledAvatar.width() ) / 2, scaledAvatar );
return frame;
}

View File

@ -22,6 +22,7 @@
#include <QSize>
#include <QModelIndex>
#include <QTextOption>
#include "TomahawkUtils.h"
#include "DllMacro.h"
@ -47,7 +48,9 @@ namespace TomahawkUtils
DLLEXPORT QColor alphaBlend( const QColor& colorFrom, const QColor& colorTo, float opacity );
DLLEXPORT QPixmap createDragPixmap( MediaType type, int itemCount = 1 );
DLLEXPORT void drawShadowText( QPainter* p, const QRect& rect, const QString& text, const QTextOption& textOption );
DLLEXPORT void drawBackgroundAndNumbers( QPainter* p, const QString& text, const QRect& rect );
DLLEXPORT void unmarginLayout( QLayout* layout );
DLLEXPORT int headerHeight();