Commit cbc15f9a authored by Thomas Zander's avatar Thomas Zander

Make inheriting transformation an explicit property.

When the KoShapeContainer was introduced it had a 'clipped'
property which implied two things;
 * the shape is clipped to the outline of its parent container.
 * the shape inherits the transformation of its parent container.

When I used a container, now 4 years later, I was confused why my
shape didn't inherit the transformation and only by reading the code
did I figure out thats because I designed it that way...
Now it doesn't make sense to me anymore that one implies the other,
the connection between them is a bit thin.
So, split up the two properties and provide plenty of API docs on the
matter.

Incidentally, this helps a usecase where I need the inherit concept
but not the clipping concept ;)

svn path=/trunk/koffice/; revision=1129452
parent 1194280b
......@@ -98,6 +98,18 @@ bool KisShapeSelectionModel::isClipped(const KoShape *child) const
return false;
}
void KisShapeSelectionModel::setInheritsTransform(const KoShape *shape, bool inherit)
{
Q_UNUSED(shape);
Q_UNUSED(inherit);
}
bool KisShapeSelectionModel::inheritsTransform(const KoShape *shape) const
{
Q_UNUSED(shape);
return false;
}
int KisShapeSelectionModel::count() const
{
return m_shapeMap.count();
......
......@@ -38,6 +38,8 @@ public:
void setClipped(const KoShape *child, bool clipping);
bool isClipped(const KoShape *child) const;
virtual void setInheritsTransform(const KoShape *shape, bool inherit);
virtual bool inheritsTransform(const KoShape *shape) const;
int count() const;
QList<KoShape*> shapes() const;
......
......@@ -342,7 +342,7 @@ QMatrix KoShape::absoluteTransformation(const KoViewConverter *converter) const
// apply parents matrix to inherit any transformations done there.
KoShapeContainer * container = d->parent;
if (container) {
if (container->isClipped(this)) {
if (container->inheritsTransform(this)) {
// We do need to pass the converter here, otherwise the parent's
// translation is not inherited.
matrix = container->absoluteTransformation(converter);
......
......@@ -119,6 +119,22 @@ void KoShapeContainer::setClipped(const KoShape *child, bool clipping)
d->model->setClipped(child, clipping);
}
void KoShapeContainer::setInheritsTransform(const KoShape *shape, bool inherit)
{
Q_D(KoShapeContainer);
if (d->model == 0)
return;
d->model->setInheritsTransform(shape, inherit);
}
bool KoShapeContainer::inheritsTransform(const KoShape *shape) const
{
Q_D(const KoShapeContainer);
if (d->model == 0)
return false;
return d->model->inheritsTransform(shape);
}
void KoShapeContainer::paint(QPainter &painter, const KoViewConverter &converter)
{
Q_D(KoShapeContainer);
......
......@@ -143,6 +143,36 @@ public:
*/
bool isChildLocked(const KoShape *child) const;
/**
* Set the shape to inherit the container transform.
*
* A shape that inherits the transform of the parent container will have its
* share / rotation / skew etc be calculated as being the product of both its
* own local transformation and also that of its parent container.
* If you set this to true and rotate the container, the shape will get that
* rotation as well automatically.
*
* @param shape the shape for which the property will be changed.
* @param inherit the new value
*/
void setInheritsTransform(const KoShape *shape, bool inherit);
/**
* Returns if the shape inherits the container transform.
*
* A shape that inherits the transform of the parent container will have its
* share / rotation / skew etc be calculated as being the product of both its
* own local transformation and also that of its parent container.
* If you set this to true and rotate the container, the shape will get that
* rotation as well automatically.
*
* @return if the argument shape has its 'inherits transform' property set.
* @param shape the shape for which the property will be returned.
*/
bool inheritsTransform(const KoShape *shape) const;
/// reimplemented
virtual void paint(QPainter &painter, const KoViewConverter &converter);
......
/* This file is part of the KDE project
* Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2006-2007, 2010 Thomas Zander <zander@kde.org>
* Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
* Copyright (C) 2009 Thorsten Zachmann <zachmann@kde.org>
*
......@@ -30,7 +30,7 @@ public:
{
public:
explicit Relation(KoShape *child)
: m_inside(false)
: inside(false)
, m_child(child)
{}
......@@ -39,7 +39,8 @@ public:
return m_child;
}
bool m_inside; ///< if true, the child will be clipped by the parent.
uint inside : 1; ///< if true, the child will be clipped by the parent.
uint inheritsTransform : 1;
private:
KoShape *m_child;
......@@ -101,9 +102,9 @@ void KoShapeContainerDefaultModel::setClipped(const KoShape *child, bool clippin
Private::Relation *relation = d->findRelation(child);
if (relation == 0)
return;
if (relation->m_inside == clipping)
if (relation->inside == clipping)
return;
relation->m_inside = clipping;
relation->inside = clipping;
relation->child()->update();
relation->child()->notifyChanged();
relation->child()->update();
......@@ -112,7 +113,7 @@ void KoShapeContainerDefaultModel::setClipped(const KoShape *child, bool clippin
bool KoShapeContainerDefaultModel::isClipped(const KoShape *child) const
{
Private::Relation *relation = d->findRelation(child);
return relation ? relation->m_inside: false;
return relation ? relation->inside: false;
}
void KoShapeContainerDefaultModel::remove(KoShape *child)
......@@ -145,3 +146,23 @@ bool KoShapeContainerDefaultModel::isChildLocked(const KoShape *child) const
void KoShapeContainerDefaultModel::containerChanged(KoShapeContainer *, KoShape::ChangeType)
{
}
void KoShapeContainerDefaultModel::setInheritsTransform(const KoShape *shape, bool inherit)
{
Private::Relation *relation = d->findRelation(shape);
if (relation == 0)
return;
if (relation->inheritsTransform == inherit)
return;
relation->inheritsTransform = inherit;
relation->child()->update();
relation->child()->notifyChanged();
relation->child()->update();
}
bool KoShapeContainerDefaultModel::inheritsTransform(const KoShape *shape) const
{
Private::Relation *relation = d->findRelation(shape);
return relation ? relation->inheritsTransform: false;
}
/* This file is part of the KDE project
* Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2006-2007, 2010 Thomas Zander <zander@kde.org>
* Copyright (C) 2009 Thorsten Zachmann <zachmann@kde.org>
*
* This library is free software; you can redistribute it and/or
......@@ -46,6 +46,12 @@ public:
/// reimplemented
virtual bool isClipped(const KoShape *child) const;
/// reimplemented
virtual void setInheritsTransform(const KoShape *shape, bool inherit);
/// reimplemented
virtual bool inheritsTransform(const KoShape *shape) const;
// reimplemented
virtual void remove(KoShape *child);
......
......@@ -86,6 +86,34 @@ public:
*/
virtual bool isClipped(const KoShape *shape) const = 0;
/**
* Set the shape to inherit the container transform.
*
* A shape that inherits the transform of the parent container will have its
* share / rotation / skew etc be calculated as being the product of both its
* own local transformation and also that of its parent container.
* If you set this to true and rotate the container, the shape will get that
* rotation as well automatically.
*
* @param shape the shape for which the property will be changed.
* @param inherit the new value
*/
virtual void setInheritsTransform(const KoShape *shape, bool inherit) = 0;
/**
* Returns if the shape inherits the container transform.
*
* A shape that inherits the transform of the parent container will have its
* share / rotation / skew etc be calculated as being the product of both its
* own local transformation and also that of its parent container.
* If you set this to true and rotate the container, the shape will get that
* rotation as well automatically.
*
* @return if the argument shape has its 'inherits transform' property set.
* @param shape the shape for which the property will be returned.
*/
virtual bool inheritsTransform(const KoShape *shape) const = 0;
/**
* Return wheather the child has the effective state of being locked for user modifications.
* The model has to call KoShape::isGeometryProtected() and base its return value upon that, it can
......
/* This file is part of the KDE project
* Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2006-2007, 2010 Thomas Zander <zander@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -50,6 +50,10 @@ public:
Q_ASSERT(child->parent());
return child->isGeometryProtected() || child->parent()->isGeometryProtected();
}
void setInheritsTransform(const KoShape *, bool ) { }
bool inheritsTransform(const KoShape *) const {
return false;
}
private: // members
QList <KoShape *> m_members;
......
......@@ -151,6 +151,11 @@ public:
void childChanged(KoShape *, KoShape::ChangeType) {
m_childChangedCalled++;
}
void setInheritsTransform(const KoShape *, bool) {
}
bool inheritsTransform(const KoShape *) const {
return false;
}
int containerChangedCalled() const {
return m_containerChangedCalled;
......
......@@ -28,7 +28,7 @@ void TestPosition::init()
container = new MockContainer();
container->setPosition(QPointF(100, 100));
container->addShape(childShape1);
container->setClipped(childShape1, false);
container->setInheritsTransform(childShape1, false);
childShape2 = new MockShape();
childShape2->setPosition(QPointF(25, 25));
......@@ -68,10 +68,10 @@ void TestPosition::testAbsolutePosition()
QCOMPARE(childShape1->absolutePosition(), QPointF(100 + 20 + 25, 100 + 20 + 25));
// rotated
container2->setClipped(childShape2, false);
container2->setInheritsTransform(childShape2, false);
QCOMPARE(container2->absolutePosition(), QPointF(150, 250));
QCOMPARE(childShape2->absolutePosition(), QPointF(130, 232.5));
container2->setClipped(childShape2, true);
container2->setInheritsTransform(childShape2, true);
QCOMPARE(childShape2->absolutePosition(), QPointF(167.5, 230));
shape1->rotate(90);
......@@ -100,12 +100,12 @@ void TestPosition::testSetAbsolutePosition()
QCOMPARE(childShape1->absolutePosition(), QPointF(0, 0));
QCOMPARE(container2->position(), QPointF(100, 200)); // make sure nobody changed it
container2->setClipped(childShape2, false);
container2->setInheritsTransform(childShape2, false);
childShape2->setAbsolutePosition(QPointF(0, 0));
QCOMPARE(childShape2->position(), QPointF(-100 - 5, -200 - 7.5));
QCOMPARE(childShape2->absolutePosition(), QPointF(0, 0));
container2->setClipped(childShape2, true);
container2->setInheritsTransform(childShape2, true);
childShape2->setAbsolutePosition(QPointF(0, 0));
QCOMPARE(childShape2->absolutePosition(), QPointF(0, 0));
QCOMPARE(childShape2->position(), QPointF(-200 - 5, 200 - 7.5));
......@@ -129,7 +129,7 @@ void TestPosition::testSetAbsolutePosition2()
childShape1->setAbsolutePosition(QPointF(0, 0), KoFlake::TopRightCorner);
QCOMPARE(childShape1->position(), QPointF(-150, -100));
container2->setClipped(childShape2, true);
container2->setInheritsTransform(childShape2, true);
childShape2->setAbsolutePosition(QPointF(0, 0), KoFlake::TopLeftCorner);
QCOMPARE(childShape2->position(), QPointF(-200, 200));
}
......
......@@ -32,11 +32,12 @@
class Relation
{
public:
Relation(KoShape *shape) : child(shape), anchor(0), nested(false) {}
Relation(KoShape *shape) : child(shape), anchor(0), nested(false), inheritsTransform(false) {}
~Relation();
KoShape *child;
KoTextAnchor *anchor;
bool nested;
uint nested : 1;
uint inheritsTransform :1;
};
......@@ -105,6 +106,21 @@ bool KoTextShapeContainerModel::isClipped(const KoShape *child) const
return relation->nested;
}
void KoTextShapeContainerModel::setInheritsTransform(const KoShape *shape, bool inherit)
{
Relation *relation = d->children.value(shape);
Q_ASSERT(relation);
relation->inheritsTransform = inherit;
}
bool KoTextShapeContainerModel::inheritsTransform(const KoShape *shape) const
{
Relation *relation = d->children.value(shape);
Q_ASSERT(relation);
return relation->inheritsTransform;
}
int KoTextShapeContainerModel::count() const
{
return d->children.count();
......
......@@ -58,6 +58,10 @@ public:
virtual void childChanged(KoShape *child, KoShape::ChangeType type);
/// reimplemented from KoShapeContainerModel
virtual bool isChildLocked(const KoShape *child) const;
/// reimplemented from KoShapeContainerModel
virtual void setInheritsTransform(const KoShape *shape, bool inherit);
/// reimplemented from KoShapeContainerModel
virtual bool inheritsTransform(const KoShape *shape) const;
/// each child that is added due to being anchored in the text has an anchor; register it for rules based placement.
void addAnchor(KoTextAnchor *anchor);
......
/*
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2007, 2010 Thomas Zander <zander@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -41,6 +41,15 @@ bool FolderShapeModel::isClipped(const KoShape *) const
return true;
}
bool FolderShapeModel::inheritsTransform(const KoShape *shape) const
{
return true;
}
void FolderShapeModel::setInheritsTransform(const KoShape *, bool)
{
}
bool FolderShapeModel::isChildLocked(const KoShape *) const
{
return false;
......
/*
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
* Copyright (C) 2007, 2010 Thomas Zander <zander@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -37,6 +37,8 @@ public:
/// always returns true clipping any child to the folder outline
virtual bool isClipped(const KoShape *child) const;
virtual bool isChildLocked(const KoShape *child) const;
virtual bool inheritsTransform(const KoShape *shape) const;
virtual void setInheritsTransform(const KoShape *shape, bool inherit);
/// return content item count
virtual int count() const;
/// returns content items added earlier
......
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