allow defining the font to use with the shadow text
svn path=/trunk/KDE/kdelibs/; revision=900826
This commit is contained in:
parent
0ea6365356
commit
4edaeb129d
@ -47,19 +47,27 @@ void shadowBlur(QImage &image, int radius, const QColor &color)
|
|||||||
p.end();
|
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)
|
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
|
//don't try to paint stuff on a future null pixmap because the text is empty
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw text
|
// Draw text
|
||||||
QFontMetrics fm(text);
|
QFontMetrics fm(font);
|
||||||
QRect textRect = fm.boundingRect(text);
|
QRect textRect = fm.boundingRect(text);
|
||||||
QPixmap textPixmap(textRect.size());
|
QPixmap textPixmap(textRect.width(), fm.height());
|
||||||
textPixmap.fill(Qt::transparent);
|
textPixmap.fill(Qt::transparent);
|
||||||
QPainter p(&textPixmap);
|
QPainter p(&textPixmap);
|
||||||
p.setPen(textColor);
|
p.setPen(textColor);
|
||||||
|
p.setFont(font);
|
||||||
p.drawText(textPixmap.rect(), Qt::AlignLeft, text);
|
p.drawText(textPixmap.rect(), Qt::AlignLeft, text);
|
||||||
p.end();
|
p.end();
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#ifndef PLASMA_PAINTUTILS_H
|
#ifndef PLASMA_PAINTUTILS_H
|
||||||
#define PLASMA_PAINTUTILS_H
|
#define PLASMA_PAINTUTILS_H
|
||||||
|
|
||||||
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QGraphicsItem>
|
#include <QtGui/QGraphicsItem>
|
||||||
#include <QtGui/QPainterPath>
|
#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.
|
* Returns a pixmap containing text with blurred shadow.
|
||||||
* Text and shadow colors default to Plasma::Theme colors.
|
* 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,
|
PLASMA_EXPORT QPixmap shadowText(QString text,
|
||||||
QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor),
|
QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor),
|
||||||
QColor shadowColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor),
|
QColor shadowColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user