From 455e525b1133d1ef4a0d7fdd279f7e8140e2be79 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 9 Dec 2012 06:38:57 +0100 Subject: [PATCH] * Added squareCenterPixmap( QPixmap ) to TomahawkUtils. --- src/libtomahawk/utils/TomahawkUtilsGui.cpp | 22 ++++++++++++++++++++++ src/libtomahawk/utils/TomahawkUtilsGui.h | 6 ++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/utils/TomahawkUtilsGui.cpp b/src/libtomahawk/utils/TomahawkUtilsGui.cpp index 6376171bc..9137949d9 100644 --- a/src/libtomahawk/utils/TomahawkUtilsGui.cpp +++ b/src/libtomahawk/utils/TomahawkUtilsGui.cpp @@ -913,6 +913,28 @@ addDropShadow( const QPixmap& source, const QSize& targetSize ) } +QPixmap +squareCenterPixmap( const QPixmap& sourceImage ) +{ + if ( sourceImage.width() != sourceImage.height() ) + { + const int sqwidth = qMin( sourceImage.width(), sourceImage.height() ); + const int delta = abs( sourceImage.width() - sourceImage.height() ); + + if ( sourceImage.width() > sourceImage.height() ) + { + return sourceImage.copy( delta / 2, 0, sqwidth, sqwidth ); + } + else + { + return sourceImage.copy( 0, delta / 2, sqwidth, sqwidth ); + } + } + + return sourceImage; +} + + void drawCompositedPopup( QWidget* widget, const QPainterPath& outline, diff --git a/src/libtomahawk/utils/TomahawkUtilsGui.h b/src/libtomahawk/utils/TomahawkUtilsGui.h index 4b2e97e7b..206a016cd 100644 --- a/src/libtomahawk/utils/TomahawkUtilsGui.h +++ b/src/libtomahawk/utils/TomahawkUtilsGui.h @@ -63,17 +63,15 @@ namespace TomahawkUtils DLLEXPORT int defaultFontHeight(); DLLEXPORT QSize defaultIconSize(); - DLLEXPORT QPixmap defaultPixmap( ImageType type, ImageMode mode = TomahawkUtils::Original, const QSize& size = QSize( 0, 0 ) ); - DLLEXPORT void prepareStyleOption( QStyleOptionViewItemV4* option, const QModelIndex& index, PlayableItem* item ); DLLEXPORT void drawRoundedButton( QPainter* painter, const QRect& btnRect, const QColor& color, const QColor &gradient1bottom = QColor(), const QColor& gradient2top = QColor(), const QColor& gradient2bottom = QColor() ); - DLLEXPORT void styleScrollBar( QScrollBar* scrollBar ); + DLLEXPORT QPixmap defaultPixmap( ImageType type, ImageMode mode = TomahawkUtils::Original, const QSize& size = QSize( 0, 0 ) ); DLLEXPORT QPixmap createTiledPixmap( int width, int height, const QImage& src ); - DLLEXPORT QPixmap addDropShadow( const QPixmap& sourceImage, const QSize& targetSize ); + DLLEXPORT QPixmap squareCenterPixmap( const QPixmap& sourceImage ); DLLEXPORT void drawCompositedPopup( QWidget* widget, const QPainterPath& outline, const QColor& lineColor, const QBrush& backgroundBrush, qreal opacity );