From 43d2bb77160e884fb346a52c872200938506e480 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 6 Jun 2012 16:40:06 +0200 Subject: [PATCH] * Fancy avatars are now scaled ignoring the aspect ratio. This fixed some odd clipping issues. --- src/libtomahawk/utils/TomahawkUtilsGui.cpp | 45 +++++++++++++++------- src/libtomahawk/utils/TomahawkUtilsGui.h | 3 ++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/libtomahawk/utils/TomahawkUtilsGui.cpp b/src/libtomahawk/utils/TomahawkUtilsGui.cpp index d0067379f..ccf8cdf2c 100644 --- a/src/libtomahawk/utils/TomahawkUtilsGui.cpp +++ b/src/libtomahawk/utils/TomahawkUtilsGui.cpp @@ -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; } diff --git a/src/libtomahawk/utils/TomahawkUtilsGui.h b/src/libtomahawk/utils/TomahawkUtilsGui.h index 79cf6e5a2..1c89f8bce 100644 --- a/src/libtomahawk/utils/TomahawkUtilsGui.h +++ b/src/libtomahawk/utils/TomahawkUtilsGui.h @@ -22,6 +22,7 @@ #include #include +#include #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();