46#include <QPainterPath>
61 , filterEffectStack(0)
67 , geometryProtected(false)
70 , protectContent(false)
71 , textRunAroundSide(
KoShape::BiggestRunAroundSide)
72 , textRunAroundDistanceLeft(0.0)
73 , textRunAroundDistanceTop(0.0)
74 , textRunAroundDistanceRight(0.0)
75 , textRunAroundDistanceBottom(0.0)
76 , textRunAroundThreshold(0.0)
77 , textRunAroundContour(
KoShape::ContourFull)
78 , paintOrder(defaultPaintOrder())
79 , inheritPaintOrder(true)
87 , localMatrix(rhs.localMatrix)
96 , additionalAttributes(rhs.additionalAttributes)
97 , additionalStyleAttributes(rhs.additionalStyleAttributes)
104 , visible(rhs.visible)
105 , printable(rhs.visible)
106 , geometryProtected(rhs.geometryProtected)
107 , keepAspect(rhs.keepAspect)
108 , selectable(rhs.selectable)
109 , protectContent(rhs.protectContent)
135 d->parent->model()->childChanged(
this, type);
150 d->shapeManagers.insert(manager);
155 d->shapeManagers.remove(manager);
179 d->listeners.clear();
189 d->parent->removeShape(
this);
196 d->shapeManagers.clear();
203 qWarning() <<
shapeId() <<
"cannot be cloned";
226 stroke()->paint(
this, painter);
233 stroke()->paintMarkers(
this, painter);
240 QTransform scaleMatrix;
241 scaleMatrix.translate(pos.x(), pos.y());
242 scaleMatrix.scale(sx, sy);
243 scaleMatrix.translate(-pos.x(), -pos.y());
244 s->localMatrix =
s->localMatrix * scaleMatrix;
252 QPointF center =
s->localMatrix.map(QPointF(0.5 *
size().width(), 0.5 *
size().height()));
253 QTransform rotateMatrix;
254 rotateMatrix.translate(center.x(), center.y());
255 rotateMatrix.rotate(angle);
256 rotateMatrix.translate(-center.x(), -center.y());
257 s->localMatrix =
s->localMatrix * rotateMatrix;
266 QTransform shearMatrix;
267 shearMatrix.translate(pos.x(), pos.y());
268 shearMatrix.shear(sx, sy);
269 shearMatrix.translate(-pos.x(), -pos.y());
270 s->localMatrix =
s->localMatrix * shearMatrix;
278 QSizeF oldSize(
size());
283 if (oldSize == newSize)
298 if (newPosition == currentPos)
300 QTransform translateMatrix;
301 translateMatrix.translate(newPosition.x() - currentPos.x(), newPosition.y() - currentPos.y());
302 s->localMatrix =
s->localMatrix * translateMatrix;
310 if (
d->parent &&
d->parent->isClipped(
this) && !
d->parent->hitTest(
position))
318 s->stroke->strokeInsets(
this, insets);
321 if (bb.contains(point))
332 return bb.contains(point);
342 s->stroke->strokeInsets(
this, insets);
348 s->shadow->insets(insets);
351 if (
s->filterEffectStack) {
352 QRectF clipRect =
s->filterEffectStack->clipRectForBoundingRect(
outlineRect());
362 Q_FOREACH (
KoShape *shape, shapes) {
376 Q_FOREACH (
KoShape *shape, shapes) {
391 QSizeF containerSize = container->
size();
392 QPointF containerPos = container->
absolutePosition() - QPointF(0.5 * containerSize.width(), 0.5 * containerSize.height());
393 matrix.translate(containerPos.x(), containerPos.y());
397 return s->localMatrix * matrix;
406 QTransform transformMatrix = globalMatrix * matrix * globalMatrix.inverted();
412 s->localMatrix = matrix *
s->localMatrix;
419 s->localMatrix = matrix;
426 return s->localMatrix;
454 if (
s1 ==
s2)
return false;
460 int runThrough1 =
s1->runThrough();
461 int runThrough2 =
s2->runThrough();
462 while (parentShapeS1) {
466 runThrough1 = runThrough1 + parentShapeS1->
runThrough();
468 parentShapeS1 = parentShapeS1->
parent();
471 while (parentShapeS2) {
475 runThrough2 = runThrough2 + parentShapeS2->
runThrough();
477 parentShapeS2 = parentShapeS2->
parent();
480 if (runThrough1 > runThrough2) {
483 if (runThrough1 < runThrough2) {
496 bool foundCommonParent =
false;
497 int index1 =
s1->zIndex();
498 int index2 =
s2->zIndex();
501 while (parentShapeS1 && !foundCommonParent) {
503 index2 = parentShapeS2->
zIndex();
504 while (parentShapeS2) {
505 if (parentShapeS2 == parentShapeS1) {
506 foundCommonParent =
true;
510 index2 = parentShapeS2->
zIndex();
512 parentShapeS2 = parentShapeS2->
parent();
515 if (!foundCommonParent) {
517 index1 = parentShapeS1->
zIndex();
519 parentShapeS1 = parentShapeS1->
parent();
524 if (
s1 == parentShapeS2) {
527 if (
s2 == parentShapeS1) {
532 return index1 < index2;
570 if (ancestorsInQuestion.contains(shape)) {
583 const KoShape *thisShape =
this;
586 const KoShape *otherShape = shape;
588 if (thisShape == otherShape) {
591 otherShape = otherShape->
parent();
594 thisShape = thisShape->
parent();
608 if (!
d->shapeManagers.empty()) {
618 if (
rect.isEmpty() && !
rect.isNull()) {
623 if (!
d->shapeManagers.empty() &&
isVisible()) {
639 const QSizeF
s =
size();
640 return QRectF(QPointF(0, 0), QSizeF(qMax(
s.width(), qreal(0.0001)),
641 qMax(
s.height(), qreal(0.0001))));
650 return QPainterPath();
657 QPointF point = rc.topLeft();
662 point = anchoredPoint;
671 QPointF translate = newPosition - currentAbsPosition;
672 QTransform translateMatrix;
673 translateMatrix.translate(translate.x(), translate.y());
681 s->size = shape->
size();
695 s->localMatrix = shape->
s->localMatrix;
712 return s->userData.data();
719 return !bg || bg->hasTransparency() ||
s->transparency > 0.0;
732 if (!recursive || !
parent()) {
733 return s->transparency;
736 const qreal childOpacity = 1.0-
s->transparency;
737 return 1.0-(parentOpacity*childOpacity);
745 s->stroke->strokeInsets(
this, answer);
755 if (order.at(1) == first) {
758 }
else if (order.at(2) == first) {
763 if (second != first && second !=
Stroke) {
764 if (order.at(2) == second) {
769 s->inheritPaintOrder =
false;
770 s->paintOrder = order;
776 if (!
s->inheritPaintOrder) {
777 order =
s->paintOrder;
792 s->inheritPaintOrder =
value;
797 return s->inheritPaintOrder;
806 if (fabs(fabs(
s->localMatrix.m12()) - fabs(
s->localMatrix.m21())) > 1e-10)
807 return std::numeric_limits<qreal>::quiet_NaN();
809 if (fabs(
s->localMatrix.m11() -
s->localMatrix.m22()) > 1e-10)
810 return std::numeric_limits<qreal>::quiet_NaN();
813 qreal angle = atan2(-
s->localMatrix.m21(),
s->localMatrix.m11()) * 180.0 /
M_PI;
828 return s->localMatrix.map(center) - center;
833 return s->textRunAroundSide;
849 if (
s->textRunAroundSide == side) {
853 s->textRunAroundSide = side;
860 return s->textRunAroundDistanceTop;
870 return s->textRunAroundDistanceLeft;
880 return s->textRunAroundDistanceRight;
885 s->textRunAroundDistanceRight =
distance;
890 return s->textRunAroundDistanceBottom;
895 s->textRunAroundDistanceBottom =
distance;
900 return s->textRunAroundThreshold;
905 s->textRunAroundThreshold = threshold;
910 return s->textRunAroundContour;
915 s->textRunAroundContour = contour;
920 s->inheritBackground =
false;
931 if (!
s->inheritBackground) {
943 s->inheritBackground =
value;
944 if (
s->inheritBackground) {
951 return s->inheritBackground;
964 return s->runThrough;
974 int _on = (on ? 1 : 0);
975 if (
s->visible == _on)
return;
1004 return s->printable;
1011 s->selectable = selectable;
1016 return s->selectable;
1021 s->geometryProtected = on;
1026 return s->geometryProtected;
1031 s->protectContent = protect;
1036 return s->protectContent;
1046 s->keepAspect = keepAspect;
1054 return s->keepAspect;
1072 if (!
s->inheritStroke) {
1084 s->inheritStroke =
false;
1092 s->inheritStroke =
value;
1093 if (
s->inheritStroke) {
1100 return s->inheritStroke;
1142 return s->clipMask.data();
1147 return s->localMatrix;
1162 Q_UNUSED(asynchronous);
1167 if (!
s->visible ||
s->geometryProtected)
1170 if (recursive &&
d->parent) {
1171 return d->parent->isShapeEditable(
true);
1179 const QTransform originalPainterTransform = painter->transform();
1183 painter->transform());
1191 const QTransform originalPainterTransform = painter->transform();
1194 painter->transform());
1230 if (!
d->dependees.contains(shape))
1231 d->dependees.append(shape);
1238 int index =
d->dependees.indexOf(shape);
1240 d->dependees.removeAt(index);
1245 return d->dependees.contains(shape);
1250 return d->dependees;
1271 s->additionalAttributes.remove(
name);
1276 return s->additionalAttributes.contains(
name);
1281 return s->additionalAttributes.value(
name);
1286 s->additionalStyleAttributes.insert(
name,
value);
1291 s->additionalStyleAttributes.remove(
name);
1296 return s->filterEffectStack;
1301 if (
s->filterEffectStack)
1302 s->filterEffectStack->
deref();
1304 if (
s->filterEffectStack) {
1305 s->filterEffectStack->
ref();
1312 return d->toolDelegates;
1317 d->toolDelegates = delegates;
1322 return s->hyperLink;
1340 m_registeredShapes.append(shape);
1346 m_registeredShapes.removeAll(shape);
1353 notifyShapeChanged(type, shape);
1356 unregisterShape(shape);
1365 d->listeners.append(listener);
1372 d->listeners.removeAll(listener);
1378 return d->listeners;
1385 Q_FOREACH (
KoShape *shape, shapes) {
1404 Q_FOREACH (
KoShape *shape, sortedShapes) {
float value(const T *src, size_t ch)
qreal distance(const QPointF &p1, const QPointF &p2)
The KisHandlePainterHelper class is a special helper for painting handles around objects....
Clip path used to clip shapes.
QPainterPath clipPath
the compiled clip path in shape coordinates of the clipped shape
This class manages a stack of filter effects.
KoShapeContainer::ShapeInterface shapeInterface
QList< KoShape * > shapes() const
bool inheritsTransform(const KoShape *shape) const
KoShapeManager::ShapeInterface shapeInterface
void update(const QRectF &rect, const KoShape *shape=0, bool selectionHandles=false)
void notifyShapeChanged(KoShape *shape)
void setToolDelegates(const QSet< KoShape * > &delegates)
virtual void setPaintOrder(PaintOrder first, PaintOrder second)
setPaintOrder set the paint order. As there's only three entries in any given paintorder,...
KoShapeUserData * userData() const
void setTextRunAroundContour(TextRunAroundContour contour)
QScopedPointer< Private > d
virtual void paintStroke(QPainter &painter) const
paintStroke paints the shape's stroked outline
bool isContentProtected() const
virtual QSizeF size() const
Get the size of the shape in pt.
void setHyperLink(const QString &hyperLink)
TextRunAroundContour textRunAroundContour() const
void setName(const QString &name)
virtual QRectF outlineRect() const
bool hasCommonParent(const KoShape *shape) const
static const qint16 minZIndex
void setContentProtected(bool protect)
void setTextRunAroundDistanceLeft(qreal distance)
void addShapeChangeListener(ShapeChangeListener *listener)
void setInheritBackground(bool value)
setInheritBackground marks a shape as inheriting the background from the parent shape....
void setZIndex(qint16 zIndex)
void setTextRunAroundDistanceRight(qreal distance)
virtual QPainterPath outline() const
KoShapeAnchor * anchor() const
virtual QVector< PaintOrder > paintOrder() const
paintOrder
KoShape * cloneShapeAndBakeAbsoluteTransform() const
creates a deep copy of the shape/shapes tree and bakes the absolute transform of this into the result...
void rotate(qreal angle)
Rotate the shape (relative)
virtual KoSnapData snapData() const
Returns additional snap data the shape wants to have snapping to.
void setKeepAspectRatio(bool keepAspect)
void setTextRunAroundDistanceTop(qreal distance)
void setTextRunAroundSide(TextRunAroundSide side, RunThroughLevel runThrough=Background)
bool isSelectable() const
QPointF shapeToDocument(const QPointF &point) const
Transforms point from shape coordinates to document coordinates.
QPointF absolutePosition(KoFlake::AnchorPosition anchor=KoFlake::Center) const
void removeShapeChangeListener(ShapeChangeListener *listener)
void setClipMask(KoClipMask *clipMask)
Sets a new clip mask, removing the old one. The mask is owned by the shape.
void setShadow(KoShapeShadow *shadow)
Sets the new shadow, removing the old one.
virtual bool isShapeEditable(bool recursive=true) const
checks recursively if the shape or one of its parents is not visible or locked
void addShapeManager(KoShapeManager *manager)
void setTransparency(qreal transparency)
static QVector< PaintOrder > defaultPaintOrder()
default paint order as per SVG specification
void setFilterEffectStack(KoFilterEffectStack *filterEffectStack)
Sets the new filter effect stack, removing the old one.
QList< KoShape * > dependees() const
Returns list of shapes depending on this shape.
virtual KoShapeStrokeModelSP stroke() const
void applyAbsoluteTransformation(const QTransform &matrix)
virtual void setResolution(qreal xRes, qreal yRes)
static bool compareShapeZIndex(KoShape *s1, KoShape *s2)
void setSizeImpl(const QSizeF &size) const
void setPrintable(bool on)
void copySettings(const KoShape *shape)
void setTextRunAroundDistanceBottom(qreal distance)
void removeAdditionalStyleAttribute(const char *name)
bool isGeometryProtected() const
QString hyperLink() const
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
QSet< KoShape * > toolDelegates() const
void shear(qreal sx, qreal sy)
Shear the shape The shape will be sheared using the zero-point which is the top-left corner.
QList< ShapeChangeListener * > listeners() const
KoInsets strokeInsets() const
virtual QRectF boundingRect() const
Get the bounding box of the shape.
KoClipPath * clipPath() const
Returns the currently set clip path or 0 if there is no clip path set.
void setSelectable(bool selectable)
virtual void update() const
void applyTransformation(const QTransform &matrix)
QRectF absoluteOutlineRect() const
virtual void shapeChanged(ChangeType type, KoShape *shape=0)
KoShapeContainer * parent() const
bool inheritStroke() const
inheritStroke shows if the shape inherits the stroke from its parent
void removeShapeManager(KoShapeManager *manager)
void shapeChangedPriv(KoShape::ChangeType type)
ChildZOrderPolicy
Used by compareShapeZIndex() to order shapes.
@ ChildZParentChild
normal parent/child ordering
qreal textRunAroundDistanceTop() const
virtual void setStroke(KoShapeStrokeModelSP stroke)
bool inheritBackground() const
inheritBackground shows if the shape inherits background from its parent
static QList< KoShape * > linearizeSubtreeSorted(const QList< KoShape * > &shapes)
void setAdditionalAttribute(const QString &name, const QString &value)
QTransform absoluteTransformation() const
virtual void paintMarkers(QPainter &painter) const
paintStroke paints the shape's markers
void setTransformation(const QTransform &matrix)
static KisHandlePainterHelper createHandlePainterHelperDocument(QPainter *painter, KoShape *shape, qreal handleRadius, int decorationThickness)
TextRunAroundContour
The behavior text should do when intersecting this shape.
KoShapeShadow * shadow() const
Returns the currently set shadow or 0 if there is no shadow set.
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
void setClipPath(KoClipPath *clipPath)
Sets a new clip path, removing the old one.
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
bool hasAdditionalAttribute(const QString &name) const
KoClipMask * clipMask() const
Returns the currently set clip mask or 0 if there is no clip mask set.
static QList< KoShape * > linearizeSubtree(const QList< KoShape * > &shapes)
TextRunAroundSide
The behavior text should do when intersecting this shape.
@ RunThrough
The text will completely ignore the frame and layout as if it was not there.
ChangeType
Used by shapeChanged() to select which change was made.
@ RotationChanged
used after a setRotation()
@ StrokeChanged
the shapes stroke has changed
@ PositionChanged
used after a setPosition()
@ TransparencyChanged
the shapetransparency value has changed
@ Deleted
the shape was deleted
@ ClipPathChanged
the shapes clip path has changed
@ TextRunAroundChanged
used after a setTextRunAroundSide()
@ ShearChanged
used after a shear()
@ ParentChanged
used after a setParent()
@ ClipMaskChanged
the shapes clip path has changed
@ ShadowChanged
the shapes shadow has changed
@ BackgroundChanged
the shapes background has changed
@ ScaleChanged
used after a scale()
@ KeepAspectRatioChange
used after setKeepAspectRatio()
@ SizeChanged
used after a setSize()
@ GenericMatrixChange
used after the matrix was changed without knowing which property explicitly changed
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
qreal textRunAroundDistanceRight() const
void scale(qreal sx, qreal sy)
Scale the shape using the zero-point which is the top-left corner.
void setUserData(KoShapeUserData *userData)
virtual QSharedPointer< KoShapeBackground > background() const
virtual ChildZOrderPolicy childZOrderPolicy()
QString additionalAttribute(const QString &name) const
virtual bool hasTransparency() const
void removeDependee(KoShape *shape)
QTransform transformation() const
Returns the shapes local transformation matrix.
KoFilterEffectStack * filterEffectStack() const
bool inheritPaintOrder() const
inheritPaintOrder
virtual void setPosition(const QPointF &position)
Set the position of the shape in pt.
bool keepAspectRatio() const
virtual void updateAbsolute(const QRectF &rect) const
bool inheritsTransformFromAny(const QList< KoShape * > ancestorsInQuestion) const
inheritsTransformFromAny checks if the shape inherits transformation from any of the shapes listed in...
qreal textRunAroundDistanceBottom() const
void setInheritStroke(bool value)
setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently se...
void setGeometryProtected(bool on)
virtual void setRunThrough(short int runThrough)
QSharedDataPointer< SharedData > s
qreal textRunAroundThreshold() const
virtual QPainterPath shadowOutline() const
void setParent(KoShapeContainer *parent)
TextRunAroundSide textRunAroundSide() const
bool addDependee(KoShape *shape)
virtual bool hitTest(const QPointF &position) const
Check if the shape is hit on position.
virtual ~KoShape()
Destructor.
void setShapeId(const QString &id)
void removeAdditionalAttribute(const QString &name)
void setAdditionalStyleAttribute(const char *name, const QString &value)
qreal textRunAroundDistanceLeft() const
QTransform transform() const
return the current matrix that contains the rotation/scale/position of this shape
void setInheritPaintOrder(bool value)
setInheritPaintOrder set inherit paint order.
bool hasDependee(KoShape *shape) const
Returns if the given shape is dependent on this shape.
void setAbsolutePosition(const QPointF &newPosition, KoFlake::AnchorPosition anchor=KoFlake::Center)
static const qint16 maxZIndex
void setTextRunAroundThreshold(qreal threshold)
bool isVisible(bool recursive=true) const
qreal transparency(bool recursive=false) const
virtual void setSize(const QSizeF &size)
Resize the shape.
QPointF position() const
Get the position of the shape in pt.
virtual void waitUntilReady(bool asynchronous=true) const
virtual QPointF documentToView(const QPointF &documentPoint) const
#define KIS_SAFE_ASSERT_RECOVER(cond)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
KRITAFLAKE_EXPORT QPointF anchorToPoint(AnchorPosition anchor, const QRectF rect, bool *valid=0)
qreal bottom
Bottom inset.
void removeShape(KoShape *shape)
void addShape(KoShape *shape)
void notifyShapeDestructed(KoShape *shape)
QList< KoShape * > m_registeredShapes
void unregisterShape(KoShape *shape)
void registerShape(KoShape *shape)
void notifyShapeChangedImpl(ChangeType type, KoShape *shape)
virtual ~ShapeChangeListener()