Commit c66223a3 authored by Inge Wallin's avatar Inge Wallin

Fix bug 260535 - kpresenter:openoffice:Shadow of the picture is not getting displayed.

This patch solves the problem that only shapes with a fill/background
and/or a stroke can have a shadow. This was bad for the picture shape
that most of the time had neither.

BUG: 250535
REVIEW: 104844
parent 142e1c4a
......@@ -609,7 +609,17 @@ QPainterPath KoShape::outline() const
QRectF KoShape::outlineRect() const
{
const QSizeF s = size();
return QRectF(QPointF(0, 0), QSizeF(qMax(s.width(), qreal(0.0001)), qMax(s.height(), qreal(0.0001))));
return QRectF(QPointF(0, 0), QSizeF(qMax(s.width(), qreal(0.0001)),
qMax(s.height(), qreal(0.0001))));
}
QPainterPath KoShape::shadowOutline() const
{
Q_D(const KoShape);
if (d->fill)
return outline();
return QPainterPath();
}
QPointF KoShape::absolutePosition(KoFlake::Position anchor) const
......
......@@ -637,6 +637,18 @@ public:
*/
virtual QRectF outlineRect() const;
/**
* returns the outline of the shape in the form of a path for the use of painting a shadow.
*
* Normally this would be the same as outline() if there is a fill (background) set on the
* shape and empty if not. However, a shape could reimplement this to return an outline
* even if no fill is defined. A typical example of this would be the picture shape
* which has a picture but almost never a background.
*
* @returns the outline of the shape in the form of a path.
*/
virtual QPainterPath shadowOutline() const;
/**
* Returns the currently set stroke, or 0 if there is no stroke.
* @return the currently set stroke, or 0 if there is no stroke.
......
......@@ -83,14 +83,18 @@ void KoShapeShadow::Private::paintGroupShadow(KoShapeGroup *group, QPainter &pai
void KoShapeShadow::Private::paintShadow(KoShape *shape, QPainter &painter, const KoViewConverter &converter)
{
if (shape->background()) {
QPainterPath path(shape->shadowOutline());
if (!path.isEmpty()) {
painter.save();
KoShape::applyConversion(painter, converter);
painter.setBrush(QBrush(color));
// Make sure the shadow has the same fill rule as the shape.
QPainterPath path(shape->outline());
KoPathShape * pathShape = dynamic_cast<KoPathShape*>(shape);
if (pathShape)
path.setFillRule(pathShape->fillRule());
painter.drawPath(path);
painter.restore();
}
......@@ -183,6 +187,11 @@ void KoShapeShadow::Private::blurShadow(QImage &image, int radius, const QColor&
p.end();
}
// ----------------------------------------------------------------
// KoShapeShadow
KoShapeShadow::KoShapeShadow()
: d(new Private())
{
......
......@@ -173,6 +173,12 @@ ClippingRect PictureShape::parseClippingRectString(QString string) const
return rect;
}
QPainterPath PictureShape::shadowOutline() const
{
// Always return an outline for a shadow even if no fill is defined.
return outline();
}
void PictureShape::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &)
{
QRectF viewRect = converter.documentToView(QRectF(QPointF(0,0), size()));
......
......@@ -22,6 +22,7 @@
#ifndef PICTURESHAPE_H
#define PICTURESHAPE_H
#include <QPainterPath>
#include <QPixmap>
#include <QImage>
#include <QRunnable>
......@@ -114,6 +115,8 @@ public:
// reimplemented
virtual void paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext);
// reimplemented
virtual QPainterPath shadowOutline() const;
// reimplemented
virtual void saveOdf(KoShapeSavingContext &context) const;
// reimplemented
virtual bool loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context);
......
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