move halopainter unchanged in libplasma, keep it private and expose
drawhalo in PaintUtils iconwidgets uses it if there is no backgroundcolor explicitly setted CCMAIL:fredrik@kde.org svn path=/trunk/KDE/kdelibs/; revision=1054830
This commit is contained in:
parent
4b4645f564
commit
3c84247ae6
@ -107,6 +107,7 @@ set(plasma_LIB_SRCS
|
||||
private/windowpreview.cpp
|
||||
private/kineticscroll.cpp
|
||||
private/pulsershadow.cpp
|
||||
private/effects/halopainter.cpp
|
||||
querymatch.cpp
|
||||
remote/accessmanager.cpp
|
||||
remote/accessappletjob.cpp
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QPixmap>
|
||||
|
||||
#include "private/effects/blur.cpp"
|
||||
#include "private/effects/halopainter_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -121,6 +122,11 @@ QPixmap shadowText(QString text, const QFont &font, QColor textColor, QColor sha
|
||||
return finalPixmap;
|
||||
}
|
||||
|
||||
void drawHalo(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
HaloPainter::instance()->drawHalo(painter, rect.toRect());
|
||||
}
|
||||
|
||||
QPainterPath roundedRectangle(const QRectF &rect, qreal radius)
|
||||
{
|
||||
QPainterPath path(QPointF(rect.left(), rect.top() + radius));
|
||||
|
@ -61,6 +61,8 @@ PLASMA_EXPORT QPixmap shadowText(QString text,
|
||||
QPoint offset = QPoint(1,1),
|
||||
int radius = 2);
|
||||
|
||||
PLASMA_EXPORT void drawHalo(QPainter *painter, const QRectF &rect);
|
||||
|
||||
/**
|
||||
* Returns a nicely rounded rectanglular path for painting.
|
||||
*/
|
||||
|
@ -95,7 +95,7 @@ void IconWidgetPrivate::readColors()
|
||||
}
|
||||
|
||||
if (!textBgCustomized) {
|
||||
textBgColor = Theme::defaultTheme()->color(Theme::HighlightColor);
|
||||
textBgColor = QColor();
|
||||
}
|
||||
}
|
||||
|
||||
@ -913,8 +913,18 @@ void IconWidgetPrivate::layoutTextItems(const QStyleOptionGraphicsItem *option,
|
||||
QStyle::alignedRect(iconDirection(option), alignment, size.toSize(), textRect.toRect());
|
||||
|
||||
// Compute the positions where we should draw the layouts
|
||||
haloRects.clear();
|
||||
labelLayout->setPosition(QPointF(textRect.x(), textBoundingRect->y()));
|
||||
QTextLine line;
|
||||
for (int i = 0; i < labelLayout->lineCount(); ++i) {
|
||||
line = labelLayout->lineAt(i);
|
||||
haloRects.append(line.naturalTextRect().translated(labelLayout->position().toPoint()).toRect());
|
||||
}
|
||||
infoLayout->setPosition(QPointF(textRect.x(), textBoundingRect->y() + labelSize.height()));
|
||||
for (int i = 0; i < infoLayout->lineCount(); ++i) {
|
||||
line = infoLayout->lineAt(i);
|
||||
haloRects.append(line.naturalTextRect().translated(infoLayout->position().toPoint()).toRect());
|
||||
}
|
||||
//kDebug() << "final position is" << labelLayout->position();
|
||||
}
|
||||
|
||||
@ -1010,21 +1020,6 @@ void IconWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
||||
|
||||
d->layoutTextItems(option, icon, &labelLayout, &infoLayout, &textBoundingRect);
|
||||
|
||||
QImage shadow(textBoundingRect.size().toSize() + QSize(4, 4),
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
shadow.fill(Qt::transparent);
|
||||
{
|
||||
QPainter buffPainter(&shadow);
|
||||
buffPainter.translate(-textBoundingRect.x(), -textBoundingRect.y());
|
||||
d->drawTextItems(&buffPainter, option, labelLayout, infoLayout);
|
||||
}
|
||||
|
||||
QPoint shadowOffset = QPoint(1, 2);
|
||||
if (d->shadowColor.value() > 128) {
|
||||
shadowOffset = QPoint(0, 1);
|
||||
}
|
||||
|
||||
|
||||
if (d->textBgColor != QColor() &&
|
||||
!(d->text.isEmpty() && d->infoText.isEmpty()) &&
|
||||
!textBoundingRect.isEmpty() &&
|
||||
@ -1044,8 +1039,33 @@ void IconWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
||||
painter->drawPath(PaintUtils::roundedRectangle(rect.translated(0.5, 0.5), 4));
|
||||
}
|
||||
|
||||
PaintUtils::shadowBlur(shadow, 2, d->shadowColor);
|
||||
painter->drawImage(textBoundingRect.topLeft() + shadowOffset, shadow);
|
||||
|
||||
if (d->shadowColor.value() < 128 || textBackgroundColor() != QColor()) {
|
||||
QPoint shadowPos;
|
||||
if (d->shadowColor.value() < 128) {
|
||||
shadowPos = QPoint(1, 2);
|
||||
} else {
|
||||
shadowPos = QPoint(0, 0);
|
||||
}
|
||||
|
||||
QImage shadow(textBoundingRect.size().toSize() + QSize(4, 4),
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
shadow.fill(Qt::transparent);
|
||||
{
|
||||
QPainter buffPainter(&shadow);
|
||||
buffPainter.translate(-textBoundingRect.x(), -textBoundingRect.y());
|
||||
d->drawTextItems(&buffPainter, option, labelLayout, infoLayout);
|
||||
}
|
||||
|
||||
PaintUtils::shadowBlur(shadow, 2, d->shadowColor);
|
||||
painter->drawImage(textBoundingRect.topLeft() + shadowPos, shadow);
|
||||
} else if (!(d->text.isEmpty() && d->infoText.isEmpty())) {
|
||||
QRect labelRect = d->labelRectangle(option, icon, d->text).toRect();
|
||||
|
||||
foreach (QRect rect, d->haloRects) {
|
||||
Plasma::PaintUtils::drawHalo(painter, rect);
|
||||
}
|
||||
}
|
||||
d->drawTextItems(painter, option, labelLayout, infoLayout);
|
||||
}
|
||||
|
||||
|
@ -212,6 +212,7 @@ public:
|
||||
int numDisplayLines;
|
||||
QSizeF currentSize;
|
||||
QPointF clickStartPos;
|
||||
mutable QList<QRect> haloRects;
|
||||
|
||||
QList<IconAction*> cornerActions;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user