diff --git a/paintutils.cpp b/paintutils.cpp index 8f868d251..1e6457d23 100644 --- a/paintutils.cpp +++ b/paintutils.cpp @@ -47,19 +47,27 @@ void shadowBlur(QImage &image, int radius, const QColor &color) p.end(); } +//TODO: we should have shadowText methods that paint the results directly into a QPainter passed in QPixmap shadowText(QString text, QColor textColor, QColor shadowColor, QPoint offset, int radius) +{ + return shadowText(text, qApp->font(), textColor, shadowColor, offset, radius); +} + +QPixmap shadowText(QString text, const QFont &font, QColor textColor, QColor shadowColor, QPoint offset, int radius) { //don't try to paint stuff on a future null pixmap because the text is empty if (text.isEmpty()) { return QPixmap(); } + // Draw text - QFontMetrics fm(text); + QFontMetrics fm(font); QRect textRect = fm.boundingRect(text); - QPixmap textPixmap(textRect.size()); + QPixmap textPixmap(textRect.width(), fm.height()); textPixmap.fill(Qt::transparent); QPainter p(&textPixmap); p.setPen(textColor); + p.setFont(font); p.drawText(textPixmap.rect(), Qt::AlignLeft, text); p.end(); diff --git a/paintutils.h b/paintutils.h index 1927290d9..8a4ac5a41 100644 --- a/paintutils.h +++ b/paintutils.h @@ -21,6 +21,7 @@ #ifndef PLASMA_PAINTUTILS_H #define PLASMA_PAINTUTILS_H +#include #include #include @@ -47,6 +48,13 @@ PLASMA_EXPORT void shadowBlur(QImage &image, int radius, const QColor &color); * Returns a pixmap containing text with blurred shadow. * Text and shadow colors default to Plasma::Theme colors. */ +PLASMA_EXPORT QPixmap shadowText(QString text, + const QFont &font, + QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor), + QColor shadowColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor), + QPoint offset = QPoint(1,1), + int radius = 2); + PLASMA_EXPORT QPixmap shadowText(QString text, QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor), QColor shadowColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor),