summaryrefslogtreecommitdiffstats
path: root/src/gui/effects/qgraphicseffect.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/effects/qgraphicseffect.cpp')
-rw-r--r--src/gui/effects/qgraphicseffect.cpp59
1 files changed, 51 insertions, 8 deletions
diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp
index ccbf7fc..6629a6d 100644
--- a/src/gui/effects/qgraphicseffect.cpp
+++ b/src/gui/effects/qgraphicseffect.cpp
@@ -256,7 +256,8 @@ QPixmap QGraphicsEffectSource::pixmap(Qt::CoordinateSystem system, QPoint *offse
}
/*!
- Constructs a new QGraphicsEffect instance.
+ Constructs a new QGraphicsEffect instance having the
+ specified \a parent.
*/
QGraphicsEffect::QGraphicsEffect(QObject *parent)
: QObject(*new QGraphicsEffectPrivate, parent)
@@ -335,7 +336,7 @@ void QGraphicsEffect::setEnabled(bool enable)
d->isEnabled = enable;
if (d->source)
- d->source->update();
+ d->source->d_func()->effectBoundingRectChanged();
emit enabledChanged(enable);
}
@@ -349,6 +350,22 @@ void QGraphicsEffect::setEnabled(bool enable)
*/
/*!
+ Schedules a redraw of the source. Call this function whenever the source
+ needs to be redrawn.
+
+ This convenience function is equivalent to calling
+ QGraphicsEffectSource::update().
+
+ \sa updateBoundingRect(), QGraphicsEffectSource::update()
+*/
+void QGraphicsEffect::update()
+{
+ Q_D(QGraphicsEffect);
+ if (d->source)
+ d->source->update();
+}
+
+/*!
Returns a pointer to the source, which provides extra context information
that can be useful for the effect.
@@ -366,13 +383,15 @@ QGraphicsEffectSource *QGraphicsEffect::source() const
function whenever you change any parameters that will cause the virtual
boundingRectFor() function to return a different value.
+ This function will call update() if this is necessary.
+
\sa boundingRectFor(), boundingRect()
*/
void QGraphicsEffect::updateBoundingRect()
{
Q_D(QGraphicsEffect);
if (d->source)
- d->source->update();
+ d->source->d_func()->effectBoundingRectChanged();
}
/*!
@@ -523,6 +542,7 @@ void QGraphicsColorizeEffect::setColor(const QColor &color)
return;
d->filter->setColor(color);
+ update();
emit colorChanged(color);
}
@@ -610,6 +630,7 @@ void QGraphicsPixelizeEffect::setPixelSize(int size)
return;
d->pixelSize = size;
+ update();
emit pixelSizeChanged(size);
}
@@ -820,7 +841,7 @@ QGraphicsDropShadowEffect::~QGraphicsDropShadowEffect()
By default, the offset is 8 pixels towards the lower right.
- \sa blurRadius(), color()
+ \sa xOffset(), yOffset(), blurRadius(), color()
*/
QPointF QGraphicsDropShadowEffect::offset() const
{
@@ -840,6 +861,24 @@ void QGraphicsDropShadowEffect::setOffset(const QPointF &offset)
}
/*!
+ \property QGraphicsDropShadowEffect::xOffset
+ \brief the horizontal shadow offset in pixels.
+
+ By default, the horizontal shadow offset is 8 pixels.
+
+ \sa yOffset(), offset()
+*/
+
+/*!
+ \property QGraphicsDropShadowEffect::yOffset
+ \brief the vertical shadow offset in pixels.
+
+ By default, the vertical shadow offset is 8 pixels.
+
+ \sa xOffset(), offset()
+*/
+
+/*!
\fn void QGraphicsDropShadowEffect::offsetChanged(const QPointF &offset)
This signal is emitted whenever the effect's shadow offset changes.
@@ -903,6 +942,7 @@ void QGraphicsDropShadowEffect::setColor(const QColor &color)
return;
d->filter->setColor(color);
+ update();
emit colorChanged(color);
}
@@ -1012,6 +1052,7 @@ void QGraphicsOpacityEffect::setOpacity(qreal opacity)
d->isFullyOpaque = 0;
else
d->isFullyOpaque = qFuzzyIsNull(d->opacity - 1);
+ update();
emit opacityChanged(opacity);
}
@@ -1050,6 +1091,7 @@ void QGraphicsOpacityEffect::setOpacityMask(const QBrush &mask)
d->opacityMask = mask;
d->hasOpacityMask = (mask.style() != Qt::NoBrush);
+ update();
emit opacityMaskChanged(mask);
}
@@ -1088,19 +1130,20 @@ void QGraphicsOpacityEffect::draw(QPainter *painter, QGraphicsEffectSource *sour
const QPixmap pixmap = source->pixmap(Qt::LogicalCoordinates, &offset);
painter->drawPixmap(offset, pixmap);
} else {
- QRectF srcBrect = source->boundingRect();
- QPixmap pixmap(srcBrect.size().toSize());
+ QRect srcBrect = source->boundingRect().toAlignedRect();
+ offset = srcBrect.topLeft();
+ QPixmap pixmap(srcBrect.size());
pixmap.fill(Qt::transparent);
QPainter pixmapPainter(&pixmap);
pixmapPainter.setRenderHints(painter->renderHints());
- pixmapPainter.translate(-srcBrect.topLeft());
+ pixmapPainter.translate(-offset);
source->draw(&pixmapPainter);
pixmapPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
pixmapPainter.fillRect(srcBrect, d->opacityMask);
pixmapPainter.end();
- painter->drawPixmap(srcBrect.topLeft(), pixmap);
+ painter->drawPixmap(offset, pixmap);
}
} else {
// Draw pixmap in device coordinates to avoid pixmap scaling;