Commit 7e5ea393 authored by Jan Hambrecht's avatar Jan Hambrecht

use bounding box units for filter regions so filters can be easily

applied to other shapes


svn path=/trunk/koffice/; revision=1002688
parent e9d831a5
......@@ -70,6 +70,15 @@ QRectF KoFilterEffect::clipRect() const
return d->clipRect;
}
QRectF KoFilterEffect::clipRectForBoundingRect(const QRectF &boundingRect) const
{
qreal x = boundingRect.x() + d->clipRect.x() * boundingRect.width();
qreal y = boundingRect.y() + d->clipRect.y() * boundingRect.height();
qreal w = d->clipRect.width() * boundingRect.width();
qreal h = d->clipRect.height() * boundingRect.height();
return QRectF(x, y, w, h);
}
void KoFilterEffect::setFilterRect(const QRectF &filterRect)
{
d->filterRect = filterRect;
......@@ -80,6 +89,15 @@ QRectF KoFilterEffect::filterRect() const
return d->filterRect;
}
QRectF KoFilterEffect::filterRectForBoundingRect(const QRectF &boundingRect) const
{
qreal x = boundingRect.x() + d->filterRect.x() * boundingRect.width();
qreal y = boundingRect.y() + d->filterRect.y() * boundingRect.height();
qreal w = d->filterRect.width() * boundingRect.width();
qreal h = d->filterRect.height() * boundingRect.height();
return QRectF(x, y, w, h);
}
QList<QString> KoFilterEffect::inputs() const
{
return d->inputs;
......
......@@ -49,17 +49,23 @@ public:
/// Returns the unique id of the filter
QString id() const;
/// Sets the clipping rectangle used for this filter
/// Sets the clipping rectangle used for this filter in bounding box units
void setClipRect(const QRectF &clipRect);
/// Returns the clipping rectangle used for this filter
/// Returns the clipping rectangle used for this filter in bounding box units
QRectF clipRect() const;
/// Sets the region the filter is applied to
/// Returns the clipping rectangle for the given bounding rect
QRectF clipRectForBoundingRect(const QRectF &boundingRect) const;
/// Sets the region the filter is applied to in bounding box units
void setFilterRect(const QRectF &filterRect);
/// Returns the region this filter is applied to
/// Returns the region this filter is applied to in bounding box units
QRectF filterRect() const;
/// Returns the region this filter is applied to for the given bounding rect
QRectF filterRectForBoundingRect(const QRectF &boundingRect) const;
/**
* Sets the name of the output image
......
......@@ -248,11 +248,6 @@ void KoShape::setSize(const QSizeF &newSize)
l->setLineBrush(brush);
}
foreach(KoFilterEffect *effect, d->filterEffects) {
effect->setClipRect(matrix.mapRect(effect->clipRect()));
effect->setFilterRect(matrix.mapRect(effect->filterRect()));
}
d->size = newSize;
notifyChanged();
......
......@@ -233,18 +233,18 @@ void KoShapeManager::paintShape(KoShape * shape, QPainter &painter, const KoView
}
} else {
// There are filter effets, then we need to prerender the shape on an image, to filter it
QRectF shapeBound(QPointF(), shape->size());
// First step, compute the rectangle used for the image
QRectF clipRegion;
foreach(KoFilterEffect* filterEffect, shape->filterEffectStack()) {
clipRegion |= filterEffect->clipRect();
clipRegion |= filterEffect->clipRectForBoundingRect(shapeBound);
}
clipRegion = converter.documentToView(clipRegion);
QRectF zoomedClipRegion = converter.documentToView(clipRegion);
// determine the offset of the clipping rect from the shapes origin
QPointF clippingOffset = clipRegion.topLeft();
QPointF clippingOffset = zoomedClipRegion.topLeft();
// Init the buffer image
QImage sourceGraphic(clipRegion.size().toSize(), QImage::Format_ARGB32_Premultiplied);
QImage sourceGraphic(zoomedClipRegion.size().toSize(), QImage::Format_ARGB32_Premultiplied);
sourceGraphic.fill(qRgba(0,0,0,0));
// Init the buffer painter
......@@ -276,7 +276,8 @@ void KoShapeManager::paintShape(KoShape * shape, QPainter &painter, const KoView
// Filter
foreach(KoFilterEffect* filterEffect, shape->filterEffectStack()) {
QRectF filterRegion = converter.documentToView(filterEffect->filterRect());
QRectF filterRegion = filterEffect->filterRectForBoundingRect(clipRegion);
filterRegion = converter.documentToView(filterRegion);
QPointF filterOffset = filterRegion.topLeft()-2*clippingOffset;
QRect subRegion = filterRegion.translated(filterOffset).toRect();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment