From aeec7e2dddaec64b20d9fa3ed281b3b413a5e3df Mon Sep 17 00:00:00 2001 From: Christoph Feck Date: Tue, 5 Oct 2010 13:13:40 +0000 Subject: [PATCH] Fix text shadow placement http://reviewboard.kde.org/r/5504/ svn path=/trunk/KDE/kdelibs/; revision=1182716 --- paintutils.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/paintutils.cpp b/paintutils.cpp index be8ea17dd..ae7f76604 100644 --- a/paintutils.cpp +++ b/paintutils.cpp @@ -90,32 +90,14 @@ QPixmap shadowText(QString text, const QFont &font, QColor textColor, QColor sha shadowBlur(img, radius, shadowColor); //Compose text and shadow - int addSizeX; - int addSizeY; - if (offset.x() > radius) { - addSizeX = abs(offset.x()) - radius; - } else { - addSizeX = 0; - } - if (offset.y() > radius) { - addSizeY = abs(offset.y()) - radius; - } else { - addSizeY = 0; - } + int addSizeX = qMax(0, qAbs(offset.x()) - radius); + int addSizeY = qMax(0, qAbs(offset.y()) - radius); QPixmap finalPixmap(img.size() + QSize(addSizeX, addSizeY)); finalPixmap.fill(Qt::transparent); p.begin(&finalPixmap); - QPointF offsetF(offset); - QPointF textTopLeft(finalPixmap.rect().topLeft() + - QPointF ((finalPixmap.width() - textPixmap.width()) / 2.0, (finalPixmap.height() - textPixmap.height()) / 2.0) - - (offsetF / 2.0)); - QPointF shadowTopLeft(finalPixmap.rect().topLeft() + - QPointF ((finalPixmap.width() - img.width()) / 2.0, (finalPixmap.height() - img.height()) / 2.0) + - (offsetF / 2.0)); - - p.drawImage(shadowTopLeft, img); - p.drawPixmap(textTopLeft, textPixmap); + p.drawImage(qMax(0, offset.x()), qMax(0, offset.y()), img); + p.drawPixmap(radius + qMax(0, -offset.x()), radius + qMax(0, -offset.y()), textPixmap); p.end(); return finalPixmap;