44#include <QPainterPath>
62 , geometryProtected(false)
65 , protectContent(false)
66 , paintOrder(defaultPaintOrder())
67 , inheritPaintOrder(true)
75 , localMatrix(rhs.localMatrix)
83 , additionalAttributes(rhs.additionalAttributes)
84 , additionalStyleAttributes(rhs.additionalStyleAttributes)
89 , visible(rhs.visible)
90 , printable(rhs.visible)
91 , geometryProtected(rhs.geometryProtected)
92 , keepAspect(rhs.keepAspect)
93 , selectable(rhs.selectable)
94 , protectContent(rhs.protectContent)
108 d->parent->model()->childChanged(
this, type);
123 d->shapeManagers.insert(manager);
128 d->shapeManagers.remove(manager);
152 d->listeners.clear();
162 d->parent->removeShape(
this);
169 d->shapeManagers.clear();
176 qWarning() <<
shapeId() <<
"cannot be cloned";
199 stroke()->paint(
this, painter);
206 stroke()->paintMarkers(
this, painter);
213 QTransform scaleMatrix;
214 scaleMatrix.translate(pos.x(), pos.y());
215 scaleMatrix.scale(sx, sy);
216 scaleMatrix.translate(-pos.x(), -pos.y());
217 s->localMatrix =
s->localMatrix * scaleMatrix;
225 QPointF center =
s->localMatrix.map(QPointF(0.5 *
size().width(), 0.5 *
size().height()));
226 QTransform rotateMatrix;
227 rotateMatrix.translate(center.x(), center.y());
228 rotateMatrix.rotate(angle);
229 rotateMatrix.translate(-center.x(), -center.y());
230 s->localMatrix =
s->localMatrix * rotateMatrix;
239 QTransform shearMatrix;
240 shearMatrix.translate(pos.x(), pos.y());
241 shearMatrix.shear(sx, sy);
242 shearMatrix.translate(-pos.x(), -pos.y());
243 s->localMatrix =
s->localMatrix * shearMatrix;
251 QSizeF oldSize(
size());
256 if (oldSize == newSize)
271 if (newPosition == currentPos)
273 QTransform translateMatrix;
274 translateMatrix.translate(newPosition.x() - currentPos.x(), newPosition.y() - currentPos.y());
275 s->localMatrix =
s->localMatrix * translateMatrix;
283 if (
d->parent &&
d->parent->isClipped(
this) && !
d->parent->hitTest(
position))
291 s->stroke->strokeInsets(
this, insets);
294 if (bb.contains(point))
306 s->stroke->strokeInsets(
this, insets);
315 return std::accumulate(shapes.begin(), shapes.end(), QRectF(),
326 return std::accumulate(shapes.begin(), shapes.end(), QRectF(),
339 QSizeF containerSize = container->
size();
340 QPointF containerPos = container->
absolutePosition() - QPointF(0.5 * containerSize.width(), 0.5 * containerSize.height());
341 matrix.translate(containerPos.x(), containerPos.y());
345 return s->localMatrix * matrix;
354 QTransform transformMatrix = globalMatrix * matrix * globalMatrix.inverted();
360 const QTransform newLocalMatrix = matrix *
s->localMatrix;
362 if (
s->localMatrix != newLocalMatrix) {
363 s->localMatrix = newLocalMatrix;
371 if (
s->localMatrix != matrix) {
372 s->localMatrix = matrix;
380 return s->localMatrix;
408 if (
s1 ==
s2)
return false;
420 bool foundCommonParent =
false;
421 int index1 =
s1->zIndex();
422 int index2 =
s2->zIndex();
425 while (parentShapeS1 && !foundCommonParent) {
427 index2 = parentShapeS2->
zIndex();
428 while (parentShapeS2) {
429 if (parentShapeS2 == parentShapeS1) {
430 foundCommonParent =
true;
434 index2 = parentShapeS2->
zIndex();
436 parentShapeS2 = parentShapeS2->
parent();
439 if (!foundCommonParent) {
441 index1 = parentShapeS1->
zIndex();
443 parentShapeS1 = parentShapeS1->
parent();
448 if (
s1 == parentShapeS2) {
451 if (
s2 == parentShapeS1) {
456 return index1 < index2;
494 if (ancestorsInQuestion.contains(shape)) {
507 const KoShape *thisShape =
this;
510 const KoShape *otherShape = shape;
512 if (thisShape == otherShape) {
515 otherShape = otherShape->
parent();
518 thisShape = thisShape->
parent();
532 if (!
d->shapeManagers.empty()) {
542 if (
rect.isEmpty() && !
rect.isNull()) {
547 if (!
d->shapeManagers.empty() &&
isVisible()) {
563 const QSizeF
s =
size();
564 return QRectF(QPointF(0, 0), QSizeF(qMax(
s.width(), qreal(0.0001)),
565 qMax(
s.height(), qreal(0.0001))));
572 QPointF point = rc.topLeft();
577 point = anchoredPoint;
586 QPointF translate = newPosition - currentAbsPosition;
587 QTransform translateMatrix;
588 translateMatrix.translate(translate.x(), translate.y());
596 s->size = shape->
size();
610 s->localMatrix = shape->
s->localMatrix;
627 return s->userData.data();
634 return !bg || bg->hasTransparency() ||
s->transparency > 0.0;
647 if (!recursive || !
parent()) {
648 return s->transparency;
651 const qreal childOpacity = 1.0-
s->transparency;
652 return 1.0-(parentOpacity*childOpacity);
660 s->stroke->strokeInsets(
this, answer);
670 if (order.at(1) == first) {
673 }
else if (order.at(2) == first) {
678 if (second != first && second !=
Stroke) {
679 if (order.at(2) == second) {
684 s->inheritPaintOrder =
false;
685 s->paintOrder = order;
691 if (!
s->inheritPaintOrder) {
692 order =
s->paintOrder;
707 s->inheritPaintOrder =
value;
712 return s->inheritPaintOrder;
721 if (fabs(fabs(
s->localMatrix.m12()) - fabs(
s->localMatrix.m21())) > 1e-10)
722 return std::numeric_limits<qreal>::quiet_NaN();
724 if (fabs(
s->localMatrix.m11() -
s->localMatrix.m22()) > 1e-10)
725 return std::numeric_limits<qreal>::quiet_NaN();
728 qreal angle = atan2(-
s->localMatrix.m21(),
s->localMatrix.m11()) * 180.0 /
M_PI;
743 return s->localMatrix.map(center) - center;
748 s->inheritBackground =
false;
759 if (!
s->inheritBackground) {
771 s->inheritBackground =
value;
772 if (
s->inheritBackground) {
779 return s->inheritBackground;
792 int _on = (on ? 1 : 0);
793 if (
s->visible == _on)
return;
829 s->selectable = selectable;
834 return s->selectable;
839 s->geometryProtected = on;
844 return s->geometryProtected;
849 s->protectContent = protect;
854 return s->protectContent;
864 s->keepAspect = keepAspect;
872 return s->keepAspect;
890 if (!
s->inheritStroke) {
902 s->inheritStroke =
false;
911 if (
s->inheritStroke) {
918 return s->inheritStroke;
942 return s->clipMask.data();
947 return s->localMatrix;
962 Q_UNUSED(asynchronous);
967 if (!
s->visible ||
s->geometryProtected)
970 if (recursive &&
d->parent) {
971 return d->parent->isShapeEditable(
true);
979 const QTransform originalPainterTransform = painter->transform();
983 painter->transform());
991 const QTransform originalPainterTransform = painter->transform();
994 painter->transform());
1030 if (!
d->dependees.contains(shape)) {
1031 d->dependees.append(shape);
1040 d->dependees.removeOne(shape);
1046 return d->dependees.contains(shape);
1051 return d->dependees;
1079 s->additionalAttributes.remove(
name);
1084 return s->additionalAttributes.contains(
name);
1089 return s->additionalAttributes.value(
name);
1094 s->additionalStyleAttributes.insert(
name,
value);
1099 s->additionalStyleAttributes.remove(
name);
1104 return d->toolDelegates;
1109 d->toolDelegates = delegates;
1114 return s->hyperLink;
1132 m_registeredShapes.append(shape);
1138 m_registeredShapes.removeAll(shape);
1145 notifyShapeChanged(type, shape);
1148 unregisterShape(shape);
1157 d->listeners.append(listener);
1164 d->listeners.removeAll(listener);
1170 return d->listeners;
1177 Q_FOREACH (
KoShape *shape, shapes) {
1196 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)
auto mem_bit_or(MemType Class::*ptr)
mem_bit_or is a binary functor that applies a bitwise-or operator to member of an object and a given ...
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()