new function texturedText()

FEATURE: draw text textured with an svg
This commit is contained in:
Marco Martin 2011-02-04 20:16:03 +01:00
parent 2a65dfbf5e
commit b9a34e131d
2 changed files with 46 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include "private/effects/blur.cpp"
#include "private/effects/halopainter_p.h"
#include "svg.h"
namespace Plasma
{
@ -103,6 +104,47 @@ QPixmap shadowText(QString text, const QFont &font, QColor textColor, QColor sha
return finalPixmap;
}
QPixmap texturedText(const QString &text, const QFont &font, Plasma::Svg *texture)
{
QFontMetrics fm(font);
QRect contentsRect = fm.boundingRect(text);
QPixmap pixmap(contentsRect.size());
pixmap.fill(Qt::transparent);
QPainter buffPainter(&pixmap);
buffPainter.setPen(Qt::black);
buffPainter.setFont(font);
buffPainter.drawText(contentsRect, Qt::AlignCenter, text);
buffPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
texture->paint(&buffPainter, contentsRect);
buffPainter.end();
//do the shadow
QImage image(pixmap.size(), QImage::Format_ARGB32_Premultiplied);
image.fill(Qt::transparent);
buffPainter.begin(&image);
buffPainter.setFont(font);
buffPainter.drawText(contentsRect, Qt::AlignCenter, text);
buffPainter.end();
Plasma::PaintUtils::shadowBlur(image, 1, Qt::black);
//hole in the shadow
buffPainter.begin(&image);
buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
buffPainter.setFont(font);
buffPainter.drawText(contentsRect, Qt::AlignCenter, text);
buffPainter.end();
QPixmap ret(contentsRect.size());
ret.fill(Qt::transparent);
buffPainter.begin(&ret);
buffPainter.drawImage(contentsRect, image);
buffPainter.drawPixmap(contentsRect, pixmap);
return ret;
}
void drawHalo(QPainter *painter, const QRectF &rect)
{
HaloPainter::instance()->drawHalo(painter, rect.toRect());

View File

@ -33,6 +33,8 @@
namespace Plasma
{
class Svg;
/**
* Namespace for all Image Effects specific to Plasma
**/
@ -61,6 +63,8 @@ PLASMA_EXPORT QPixmap shadowText(QString text,
QPoint offset = QPoint(1,1),
int radius = 2);
PLASMA_EXPORT QPixmap texturedText(const QString &text, const QFont &font, Plasma::Svg *texture);
PLASMA_EXPORT void drawHalo(QPainter *painter, const QRectF &rect);
/**