Commit bc4880fa authored by Thomas Zander's avatar Thomas Zander

The KoShapeGroup used to be a virtual object. That is, it has no size,

no position etc.
I changed that so now the size and position of a Group will be based
on the items contained in it. Add a shape and the size of the group
changes.
This makes adding shapes tricky; so just use the command. It makes
altering the position of the whole group easy; just move the group
and all children will move :)

svn path=/trunk/koffice/; revision=568208
parent 5f452132
......@@ -183,16 +183,29 @@ KoGroupShapesCommand::KoGroupShapesCommand() {
}
void KoGroupShapesCommand::execute () {
QList <QPointF> positions;
QRectF bound = m_container->boundingRect();
foreach(KoShape *shape, m_shapes) {
positions.append(shape->absolutePosition());
bound = bound.unite(shape->boundingRect());
m_container->addChild(shape);
shape->setPosition(shape->position() - m_container->position());
}
for(int i=0; i < m_shapes.count(); i++) {
m_shapes[i]->setAbsolutePosition( positions[i] );
}
m_container->setPosition( bound.topLeft() );
m_container->resize( bound.size() );
}
void KoGroupShapesCommand::unexecute () {
foreach(KoShape *shape, m_shapes) {
m_container->removeChild(shape);
shape->setPosition(shape->position() + m_container->position());
QList <QPointF> positions;
foreach(KoShape *shape, m_shapes)
positions.append(shape->absolutePosition());
for(int i=0; i < m_shapes.count(); i++) {
m_container->removeChild(m_shapes[i]);
m_shapes[i]->setAbsolutePosition( positions[i] );
}
}
......
......@@ -264,7 +264,7 @@ class KoShapeAlignCommand : public KCommand {
public:
enum Align
{
ALIGN_HORIZONTAL_LEFT,
ALIGN_HORIZONTAL_LEFT, // TODO make naming more Qt / C++ like : HorizontalLeftAlignment
ALIGN_HORIZONTAL_CENTER,
ALIGN_HORIZONTAL_RIGHT,
ALIGN_VERTICAL_BOTTOM,
......
......@@ -35,20 +35,22 @@ KoShapeContainer::~KoShapeContainer() {
delete m_children;
}
void KoShapeContainer::addChild(KoShape *object) {
Q_ASSERT(object);
void KoShapeContainer::addChild(KoShape *shape) {
Q_ASSERT(shape);
if(m_children == 0)
m_children = new ChildrenData();
m_children->add(object);
object->setParent(this);
m_children->add(shape);
shape->setParent(this);
childCountChanged();
}
void KoShapeContainer::removeChild(KoShape *object) {
Q_ASSERT(object);
void KoShapeContainer::removeChild(KoShape *shape) {
Q_ASSERT(shape);
if(m_children == 0)
return;
m_children->remove(object);
object->setParent(0);
m_children->remove(shape);
shape->setParent(0);
childCountChanged();
}
int KoShapeContainer::childCount() const {
......
......@@ -190,6 +190,9 @@ public:
*/
QList<KoShape*> iterator() const;
protected:
virtual void childCountChanged() { }
private:
/**
*/
......
......@@ -67,28 +67,8 @@ bool KoShapeGroup::GroupMembers::childClipped(const KoShape *child) const {
return false;
}
void KoShapeGroup::setPosition( const QPointF &position ) {
QPointF newPos = position - boundingRect().topLeft();
foreach(KoShape *shape, iterator()) {
shape->repaint();
shape->setAbsolutePosition( shape->absolutePosition() + newPos);
shape->repaint();
}
Q_ASSERT(boundingRect().topLeft() == position);
}
QRectF KoShapeGroup::boundingRect() const {
bool first=true;
QRectF boundingRect;
foreach(KoShape *shape, iterator()) {
if(first) {
boundingRect = shape->boundingRect();
first = false;
}
else
boundingRect = boundingRect.unite( shape->boundingRect() );
}
return boundingRect;
void KoShapeGroup::childCountChanged() {
QRectF br = boundingRect();
setPosition( br.topLeft() );
resize( br.size() );
}
......@@ -47,9 +47,6 @@ public:
void paintComponent(QPainter &painter, KoViewConverter &converter);
/// always returns false since the group itself can't be selected or hit
bool hitTest( const QPointF &position ) const;
virtual QRectF boundingRect() const;
void setPosition( const QPointF &position );
private:
class GroupMembers: public KoGraphicsContainerModel {
......@@ -67,6 +64,8 @@ private:
private: // members
QList <KoShape *> m_groupMembers;
};
void childCountChanged();
};
#endif
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