allow defining the font to use with the shadow text

svn path=/trunk/KDE/kdelibs/; revision=900826
This commit is contained in:
Aaron J. Seigo 2008-12-23 18:31:59 +00:00
parent 0ea6365356
commit 4edaeb129d
2 changed files with 18 additions and 2 deletions

View File

@ -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();

View File

@ -21,6 +21,7 @@
#ifndef PLASMA_PAINTUTILS_H
#define PLASMA_PAINTUTILS_H
#include <QtGui/QApplication>
#include <QtGui/QGraphicsItem>
#include <QtGui/QPainterPath>
@ -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),