25 #include <QPaintEngine>
28 #include "private/effects/blur.cpp"
29 #include "private/effects/halopainter_p.h"
38 void shadowBlur(QImage &image,
int radius,
const QColor &color)
47 expblur<16, 7>(image, radius);
50 p.setCompositionMode(QPainter::CompositionMode_SourceIn);
51 p.fillRect(image.rect(), color);
56 QPixmap
shadowText(QString text, QColor textColor, QColor shadowColor, QPoint offset,
int radius)
58 return shadowText(text, qApp->font(), textColor, shadowColor, offset, radius);
61 QPixmap
shadowText(QString text,
const QFont &font, QColor textColor, QColor shadowColor, QPoint offset,
int radius)
69 QFontMetrics fm(font);
70 QRect textRect = fm.boundingRect(text);
71 QPixmap textPixmap(textRect.width(), fm.height());
72 textPixmap.fill(Qt::transparent);
73 QPainter p(&textPixmap);
82 p.drawText(textPixmap.rect(), Qt::AlignCenter, text);
86 QImage img(textRect.size() + QSize(radius * 2, radius * 2), QImage::Format_ARGB32_Premultiplied);
89 p.drawImage(QPoint(radius, radius), textPixmap.toImage());
94 int addSizeX = qMax(0, qAbs(offset.x()) - radius);
95 int addSizeY = qMax(0, qAbs(offset.y()) - radius);
97 QPixmap finalPixmap(img.size() + QSize(addSizeX, addSizeY));
98 finalPixmap.fill(Qt::transparent);
99 p.begin(&finalPixmap);
100 p.drawImage(qMax(0, offset.x()), qMax(0, offset.y()), img);
101 p.drawPixmap(radius + qMax(0, -offset.x()), radius + qMax(0, -offset.y()), textPixmap);
109 QFontMetrics fm(font);
111 QRect contentsRect = fm.boundingRect(text).adjusted(0, 0, 2, 2);
112 contentsRect.moveTo(0,0);
114 QPixmap pixmap(contentsRect.size());
115 pixmap.fill(Qt::transparent);
117 QPainter buffPainter(&pixmap);
118 buffPainter.setPen(Qt::black);
120 buffPainter.setFont(font);
121 buffPainter.drawText(contentsRect, Qt::AlignCenter, text);
122 buffPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
123 texture->
paint(&buffPainter, contentsRect,
"foreground");
127 QImage image(pixmap.size() + QSize(2, 2), QImage::Format_ARGB32_Premultiplied);
128 image.fill(Qt::transparent);
129 buffPainter.begin(&image);
130 buffPainter.setFont(font);
131 buffPainter.drawText(contentsRect.translated(1, 1), Qt::AlignCenter, text);
132 buffPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
133 texture->
paint(&buffPainter, contentsRect.adjusted(-1, -1, 1, 1),
"shadow");
136 expblur<16, 7>(image, 1);
138 buffPainter.begin(&image);
139 buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationOut);
140 buffPainter.setFont(font);
141 buffPainter.drawText(contentsRect.translated(1, 1), Qt::AlignCenter, text);
144 QPixmap ret(image.size());
145 ret.fill(Qt::transparent);
146 buffPainter.begin(&ret);
147 buffPainter.setCompositionMode(QPainter::CompositionMode_SourceOver);
148 buffPainter.drawImage(QPoint(0,0), image);
149 buffPainter.drawPixmap(QPoint(1,1), pixmap);
154 void drawHalo(QPainter *painter,
const QRectF &rect)
156 HaloPainter::instance()->drawHalo(painter, rect.toRect());
161 QPainterPath path(QPointF(rect.left(), rect.top() + radius));
162 path.quadTo(rect.left(), rect.top(), rect.left() + radius, rect.top());
163 path.lineTo(rect.right() - radius, rect.top());
164 path.quadTo(rect.right(), rect.top(), rect.right(), rect.top() + radius);
165 path.lineTo(rect.right(), rect.bottom() - radius);
166 path.quadTo(rect.right(), rect.bottom(), rect.right() - radius, rect.bottom());
167 path.lineTo(rect.left() + radius, rect.bottom());
168 path.quadTo(rect.left(), rect.bottom(), rect.left(), rect.bottom() - radius);
176 if (from.size() == to.size() && from.hasAlphaChannel() && to.hasAlphaChannel()) {
180 QRect fromRect(from.rect());
181 QRect toRect(to.rect());
183 QRect actualRect = QRect(QPoint(0,0), fromRect.size().expandedTo(toRect.size()));
184 fromRect.moveCenter(actualRect.center());
185 toRect.moveCenter(actualRect.center());
187 if (from.size() != actualRect.size() || !from.hasAlphaChannel()) {
188 QPixmap result(actualRect.size());
189 result.fill(Qt::transparent);
191 p.setCompositionMode(QPainter::CompositionMode_Source);
192 p.drawPixmap(fromRect.topLeft(), from);
197 if (to.size() != actualRect.size() || !to.hasAlphaChannel()) {
198 QPixmap result(actualRect.size());
199 result.fill(Qt::transparent);
201 p.setCompositionMode(QPainter::CompositionMode_Source);
202 p.drawPixmap(toRect.topLeft(), to);
208 QPixmap
transition(
const QPixmap &from,
const QPixmap &to, qreal amount)
210 if (from.isNull() && to.isNull()) {
214 if (qFuzzyCompare(amount + 1, qreal(1.0))) {
218 QRect startRect(from.rect());
219 QRect targetRect(to.rect());
220 QSize pixmapSize = startRect.size().expandedTo(targetRect.size());
221 QRect toRect = QRect(QPoint(0,0), pixmapSize);
222 targetRect.moveCenter(toRect.center());
223 startRect.moveCenter(toRect.center());
227 color.setAlphaF(amount);
230 QPaintEngine *paintEngine = from.paintEngine();
232 paintEngine->hasFeature(QPaintEngine::PorterDuff) &&
233 paintEngine->hasFeature(QPaintEngine::BlendModes)) {
234 QPixmap startPixmap(pixmapSize);
235 startPixmap.fill(Qt::transparent);
237 QPixmap targetPixmap(pixmapSize);
238 targetPixmap.fill(Qt::transparent);
241 p.begin(&targetPixmap);
242 p.drawPixmap(targetRect, to);
243 p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
244 p.fillRect(targetRect, color);
247 p.begin(&startPixmap);
248 p.drawPixmap(startRect, from);
249 p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
250 p.fillRect(startRect, color);
251 p.setCompositionMode(QPainter::CompositionMode_Plus);
252 p.drawPixmap(targetRect, targetPixmap);
257 #if defined(Q_WS_X11) && defined(HAVE_XRENDER)
259 else if (paintEngine && paintEngine->hasFeature(QPaintEngine::PorterDuff)) {
271 QPixmap source(targetPixmap), destination(startPixmap);
274 destination.detach();
276 Display *dpy = QX11Info::display();
278 XRenderPictFormat *format = XRenderFindStandardFormat(dpy, PictStandardA8);
279 XRenderPictureAttributes pa;
283 Pixmap pixmap = XCreatePixmap(dpy, destination.handle(), 1, 1, 8);
284 Picture alpha = XRenderCreatePicture(dpy, pixmap, format, CPRepeat, &pa);
285 XFreePixmap(dpy, pixmap);
289 xcolor.alpha = quint16(0xffff * amount);
290 XRenderFillRectangle(dpy, PictOpSrc, alpha, &xcolor, 0, 0, 1, 1);
293 XRenderComposite(dpy, PictOpOutReverse, alpha, None, destination.x11PictureHandle(),
294 0, 0, 0, 0, 0, 0, destination.width(), destination.height());
297 XRenderComposite(dpy, PictOpAdd, source.x11PictureHandle(), alpha,
298 destination.x11PictureHandle(),
299 toRect.x(), toRect.y(), 0, 0, 0, 0, destination.width(), destination.height());
301 XRenderFreePicture(dpy, alpha);
307 QImage under(pixmapSize, QImage::Format_ARGB32_Premultiplied);
308 under.fill(Qt::transparent);
309 QImage over(pixmapSize, QImage::Format_ARGB32_Premultiplied);
310 over.fill(Qt::transparent);
314 p.drawPixmap(targetRect, to);
315 p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
316 p.fillRect(over.rect(), color);
320 p.drawPixmap(startRect, from);
321 p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
322 p.fillRect(startRect, color);
323 p.setCompositionMode(QPainter::CompositionMode_Plus);
324 p.drawImage(toRect.topLeft(), over);
327 return QPixmap::fromImage(under);
QPixmap texturedText(const QString &text, const QFont &font, Plasma::Svg *texture)
void drawHalo(QPainter *painter, const QRectF &rect)
QPainterPath roundedRectangle(const QRectF &rect, qreal radius)
Returns a nicely rounded rectanglular path for painting.
Q_INVOKABLE void paint(QPainter *painter, const QPointF &point, const QString &elementID=QString())
Paints all or part of the SVG represented by this object.
QPixmap shadowText(QString text, QColor textColor, QColor shadowColor, QPoint offset, int radius)
void shadowBlur(QImage &image, int radius, const QColor &color)
Creates a blurred shadow of the supplied image.
QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount)
Blends a pixmap into another.
void centerPixmaps(QPixmap &from, QPixmap &to)
center two pixmap together in the biggest rectangle
A theme aware image-centric SVG class.