43#include <QPainterPath>
61 , geometryProtected(false)
64 , protectContent(false)
65 , paintOrder(defaultPaintOrder())
66 , inheritPaintOrder(true)
74 , localMatrix(rhs.localMatrix)
82 , additionalAttributes(rhs.additionalAttributes)
83 , additionalStyleAttributes(rhs.additionalStyleAttributes)
88 , visible(rhs.visible)
89 , printable(rhs.visible)
90 , geometryProtected(rhs.geometryProtected)
91 , keepAspect(rhs.keepAspect)
92 , selectable(rhs.selectable)
93 , protectContent(rhs.protectContent)
107 d->parent->model()->childChanged(
this, type);
122 d->shapeManagers.insert(manager);
127 d->shapeManagers.remove(manager);
151 d->listeners.clear();
161 d->parent->removeShape(
this);
168 d->shapeManagers.clear();
175 qWarning() <<
shapeId() <<
"cannot be cloned";
198 stroke()->paint(
this, painter);
205 stroke()->paintMarkers(
this, painter);
212 QTransform scaleMatrix;
213 scaleMatrix.translate(pos.x(), pos.y());
214 scaleMatrix.scale(sx, sy);
215 scaleMatrix.translate(-pos.x(), -pos.y());
216 s->localMatrix =
s->localMatrix * scaleMatrix;
224 QPointF center =
s->localMatrix.map(QPointF(0.5 *
size().width(), 0.5 *
size().height()));
225 QTransform rotateMatrix;
226 rotateMatrix.translate(center.x(), center.y());
227 rotateMatrix.rotate(angle);
228 rotateMatrix.translate(-center.x(), -center.y());
229 s->localMatrix =
s->localMatrix * rotateMatrix;
238 QTransform shearMatrix;
239 shearMatrix.translate(pos.x(), pos.y());
240 shearMatrix.shear(sx, sy);
241 shearMatrix.translate(-pos.x(), -pos.y());
242 s->localMatrix =
s->localMatrix * shearMatrix;
250 QSizeF oldSize(
size());
255 if (oldSize == newSize)
270 if (newPosition == currentPos)
272 QTransform translateMatrix;
273 translateMatrix.translate(newPosition.x() - currentPos.x(), newPosition.y() - currentPos.y());
274 s->localMatrix =
s->localMatrix * translateMatrix;
282 if (
d->parent &&
d->parent->isClipped(
this) && !
d->parent->hitTest(
position))
290 s->stroke->strokeInsets(
this, insets);
293 if (bb.contains(point))
305 s->stroke->strokeInsets(
this, insets);
315 Q_FOREACH (
KoShape *shape, shapes) {
329 Q_FOREACH (
KoShape *shape, shapes) {
344 QSizeF containerSize = container->
size();
345 QPointF containerPos = container->
absolutePosition() - QPointF(0.5 * containerSize.width(), 0.5 * containerSize.height());
346 matrix.translate(containerPos.x(), containerPos.y());
350 return s->localMatrix * matrix;
359 QTransform transformMatrix = globalMatrix * matrix * globalMatrix.inverted();
365 const QTransform newLocalMatrix = matrix *
s->localMatrix;
367 if (
s->localMatrix != newLocalMatrix) {
368 s->localMatrix = newLocalMatrix;
376 if (
s->localMatrix != matrix) {
377 s->localMatrix = matrix;
385 return s->localMatrix;
413 if (
s1 ==
s2)
return false;
425 bool foundCommonParent =
false;
426 int index1 =
s1->zIndex();
427 int index2 =
s2->zIndex();
430 while (parentShapeS1 && !foundCommonParent) {
432 index2 = parentShapeS2->
zIndex();
433 while (parentShapeS2) {
434 if (parentShapeS2 == parentShapeS1) {
435 foundCommonParent =
true;
439 index2 = parentShapeS2->
zIndex();
441 parentShapeS2 = parentShapeS2->
parent();
444 if (!foundCommonParent) {
446 index1 = parentShapeS1->
zIndex();
448 parentShapeS1 = parentShapeS1->
parent();
453 if (
s1 == parentShapeS2) {
456 if (
s2 == parentShapeS1) {
461 return index1 < index2;
499 if (ancestorsInQuestion.contains(shape)) {
512 const KoShape *thisShape =
this;
515 const KoShape *otherShape = shape;
517 if (thisShape == otherShape) {
520 otherShape = otherShape->
parent();
523 thisShape = thisShape->
parent();
537 if (!
d->shapeManagers.empty()) {
547 if (
rect.isEmpty() && !
rect.isNull()) {
552 if (!
d->shapeManagers.empty() &&
isVisible()) {
568 const QSizeF
s =
size();
569 return QRectF(QPointF(0, 0), QSizeF(qMax(
s.width(), qreal(0.0001)),
570 qMax(
s.height(), qreal(0.0001))));
577 QPointF point = rc.topLeft();
582 point = anchoredPoint;
591 QPointF translate = newPosition - currentAbsPosition;
592 QTransform translateMatrix;
593 translateMatrix.translate(translate.x(), translate.y());
601 s->size = shape->
size();
615 s->localMatrix = shape->
s->localMatrix;
632 return s->userData.data();
639 return !bg || bg->hasTransparency() ||
s->transparency > 0.0;
652 if (!recursive || !
parent()) {
653 return s->transparency;
656 const qreal childOpacity = 1.0-
s->transparency;
657 return 1.0-(parentOpacity*childOpacity);
665 s->stroke->strokeInsets(
this, answer);
675 if (order.at(1) == first) {
678 }
else if (order.at(2) == first) {
683 if (second != first && second !=
Stroke) {
684 if (order.at(2) == second) {
689 s->inheritPaintOrder =
false;
690 s->paintOrder = order;
696 if (!
s->inheritPaintOrder) {
697 order =
s->paintOrder;
712 s->inheritPaintOrder =
value;
717 return s->inheritPaintOrder;
726 if (fabs(fabs(
s->localMatrix.m12()) - fabs(
s->localMatrix.m21())) > 1e-10)
727 return std::numeric_limits<qreal>::quiet_NaN();
729 if (fabs(
s->localMatrix.m11() -
s->localMatrix.m22()) > 1e-10)
730 return std::numeric_limits<qreal>::quiet_NaN();
733 qreal angle = atan2(-
s->localMatrix.m21(),
s->localMatrix.m11()) * 180.0 /
M_PI;
748 return s->localMatrix.map(center) - center;
753 s->inheritBackground =
false;
764 if (!
s->inheritBackground) {
776 s->inheritBackground =
value;
777 if (
s->inheritBackground) {
784 return s->inheritBackground;
797 int _on = (on ? 1 : 0);
798 if (
s->visible == _on)
return;
834 s->selectable = selectable;
839 return s->selectable;
844 s->geometryProtected = on;
849 return s->geometryProtected;
854 s->protectContent = protect;
859 return s->protectContent;
869 s->keepAspect = keepAspect;
877 return s->keepAspect;
895 if (!
s->inheritStroke) {
907 s->inheritStroke =
false;
916 if (
s->inheritStroke) {
923 return s->inheritStroke;
947 return s->clipMask.data();
952 return s->localMatrix;
967 Q_UNUSED(asynchronous);
972 if (!
s->visible ||
s->geometryProtected)
975 if (recursive &&
d->parent) {
976 return d->parent->isShapeEditable(
true);
984 const QTransform originalPainterTransform = painter->transform();
988 painter->transform());
996 const QTransform originalPainterTransform = painter->transform();
999 painter->transform());
1035 if (!
d->dependees.contains(shape)) {
1036 d->dependees.append(shape);
1045 d->dependees.removeOne(shape);
1051 return d->dependees.contains(shape);
1056 return d->dependees;
1084 s->additionalAttributes.remove(
name);
1089 return s->additionalAttributes.contains(
name);
1094 return s->additionalAttributes.value(
name);
1099 s->additionalStyleAttributes.insert(
name,
value);
1104 s->additionalStyleAttributes.remove(
name);
1109 return d->toolDelegates;
1114 d->toolDelegates = delegates;
1119 return s->hyperLink;
1137 m_registeredShapes.append(shape);
1143 m_registeredShapes.removeAll(shape);
1150 notifyShapeChanged(type, shape);
1153 unregisterShape(shape);
1162 d->listeners.append(listener);
1169 d->listeners.removeAll(listener);
1175 return d->listeners;
1182 Q_FOREACH (
KoShape *shape, shapes) {
1201 Q_FOREACH (
KoShape *shape, sortedShapes) {
float value(const T *src, size_t ch)
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
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
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)
void setName(const QString &name)
virtual QRectF outlineRect() const
bool hasCommonParent(const KoShape *shape) const
static const qint16 minZIndex
void setContentProtected(bool protect)
void addShapeChangeListener(ShapeChangeListener *listener)
void setInheritBackground(bool value)
setInheritBackground marks a shape as inheriting the background from the parent shape....
void setZIndex(qint16 zIndex)
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)
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.
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
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 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
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)
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)
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
@ ShearChanged
used after a shear()
@ ParentChanged
used after a setParent()
@ ClipMaskChanged
the shapes clip path 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
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.
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...
void setInheritStroke(bool value)
setInheritStroke marks a shape as inheriting the stroke from the parent shape. NOTE: The currently se...
void setGeometryProtected(bool on)
QSharedDataPointer< SharedData > s
void setParent(KoShapeContainer *parent)
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)
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
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()