Commit 923c159d authored by Jan Hambrecht's avatar Jan Hambrecht

add clippath property to KoShape and use it when painting

parent f08a9cb7
......@@ -118,6 +118,7 @@ set(flake_SRCS
KoTextShapeDataBase.cpp
KoTosContainer.cpp
KoTosContainerModel.cpp
KoClipPath.cpp
commands/KoShapeGroupCommand.cpp
commands/KoShapeAlignCommand.cpp
commands/KoShapeBackgroundCommand.cpp
......@@ -157,6 +158,7 @@ set(flake_SRCS
commands/KoShapeRenameCommand.cpp
commands/KoPathPointMergeCommand.cpp
commands/KoShapeTransparencyCommand.cpp
commands/KoShapeClipCommand.cpp
tools/KoCreatePathTool.cpp
tools/KoCreatePathToolFactory.cpp
tools/KoCreateShapeStrategy.cpp
......
......@@ -43,6 +43,7 @@
#include "KoLineBorder.h"
#include "ShapeDeleter_p.h"
#include "KoShapeShadow.h"
#include "KoClipPath.h"
#include "KoEventAction.h"
#include "KoEventActionRegistry.h"
#include "KoOdfWorkaround.h"
......@@ -89,6 +90,7 @@ KoShapePrivate::KoShapePrivate(KoShape *shape)
border(0),
q_ptr(shape),
shadow(0),
clipPath(0),
filterEffectStack(0),
transparency(0.0),
zIndex(0),
......@@ -130,6 +132,8 @@ KoShapePrivate::~KoShapePrivate()
delete fill;
if (filterEffectStack && !filterEffectStack->deref())
delete filterEffectStack;
if (clipPath)
delete clipPath;
qDeleteAll(eventActions);
}
......@@ -1151,6 +1155,20 @@ KoShapeShadow *KoShape::shadow() const
return d->shadow;
}
void KoShape::setClipPath( KoClipPath * clipPath )
{
Q_D(KoShape);
d->clipPath = clipPath;
d->shapeChanged(ClipPathChanged);
notifyChanged();
}
KoClipPath * KoShape::clipPath() const
{
Q_D(const KoShape);
return d->clipPath;
}
QTransform KoShape::transform() const
{
Q_D(const KoShape);
......
......@@ -62,6 +62,7 @@ class KoEventAction;
class KoShapePrivate;
class KoFilterEffectStack;
class KoSnapData;
class KoClipPath;
/**
*
......@@ -127,7 +128,8 @@ public:
ContentChanged, ///< the content of the shape changed e.g. a new image inside a pixmap/text change inside a textshape
TextRunAroundChanged, ///< used after a setTextRunAroundSide()
ChildChanged, ///< a child of a container was changed/removed. This is propagated to all parents
ConnectionPointChanged ///< a connection point has changed
ConnectionPointChanged, ///< a connection point has changed
ClipPathChanged ///< the shapes clip path has changed
};
/// See QGraphicsItem::CacheMode
......@@ -636,6 +638,12 @@ public:
/// Returns the currently set shadow or 0 if there is no shadow set
KoShapeShadow *shadow() const;
/// Sets a new clip path, removing the old one
void setClipPath( KoClipPath * clipPath );
/// Returns the currently set clip path or 0 if there is no clip path set
KoClipPath * clipPath() const;
/**
* Setting the shape to keep its aspect-ratio has the effect that user-scaling will
* keep the width/hight ratio intact so as not to distort shapes that rely on that
......
/* This file is part of the KDE project
Copyright (C) 2007,2009 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2011 Jan Hambrecht <jaham@gmx.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -22,6 +23,7 @@
#include "KoShape.h"
#include "KoShapeManager.h"
#include "KoClipPath.h"
#include <QPainter>
class KoShapeManagerPaintingStrategy::Private
......@@ -49,6 +51,11 @@ void KoShapeManagerPaintingStrategy::paint(KoShape * shape, QPainter &painter, c
if (d->shapeManager) {
painter.save();
painter.setTransform(shape->absoluteTransformation(&converter) * painter.transform());
// apply clipping if clip path is set
if (shape->clipPath())
shape->clipPath()->applyClipping( painter, converter );
d->shapeManager->paintShape(shape, painter, converter, forPrint);
painter.restore(); // for the matrix
}
......
......@@ -21,7 +21,6 @@
#define KOSHAPEPRIVATE_H
#include "KoShape.h"
#include <QPixmapCache>
#include <QPoint>
#include <QPaintDevice>
......@@ -101,6 +100,7 @@ public:
KoShape *q_ptr;
QList<KoShape*> dependees; ///< list of shape dependent on this shape
KoShapeShadow * shadow; ///< the current shape shadow
KoClipPath * clipPath; ///< the current clip path
QMap<QString, QString> additionalAttributes;
QMap<QByteArray, QString> additionalStyleAttributes;
QSet<KoEventAction *> eventActions; ///< list of event actions the shape has
......
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