Commit a911ddd6 authored by Peter Simonsson's avatar Peter Simonsson

* Remove KoShapeAddRemoveData

* Make KoPAPageBase a KoShapeContainer
* Fix drawing of child shapes in KoShapeContainer
* Make KoShapeLayer resize correctly depending on the children
* Fix adding and removing of child shapes in KoShapeManager
Plus everything I've forgotten ;)

svn path=/trunk/koffice/; revision=617691
parent 36707823
......@@ -231,7 +231,7 @@ public:
m_currentImage->disconnect( m_currentImage, 0, doc, 0 );
// First clear the current set of shapes away
foreach( KoShape* shape, layerShapes ) {
doc->removeShape( shape, 0 );
doc->removeShape( shape );
delete shape; // XXX: What happes with stuff on the
// clipboard? And how about undo information?
......@@ -292,7 +292,7 @@ KisDoc2::KisDoc2(QWidget *parentWidget, QObject *parent, bool singleViewMode)
KisDoc2::~KisDoc2()
{
foreach( KoShape* shape, m_d->layerShapes ) {
removeShape( shape, 0 );
removeShape( shape );
delete shape; // XXX: What happes with stuff on the
// clipboard? And how about undo information?
}
......@@ -1310,9 +1310,8 @@ void KisDoc2::initEmpty()
newImage("", cfg.defImgWidth(), cfg.defImgHeight(), rgb);
}
void KisDoc2::addShape( KoShape* shape, KoShapeAddRemoveData *addRemoveData )
void KisDoc2::addShape( KoShape* shape )
{
Q_UNUSED( addRemoveData );
kDebug() << ">>>>> KisDoc2::addShape: " << shape->shapeId() << ", active layer: " << m_d->activeLayerShape() << endl;
if ( m_d->activeLayerShape() ) kDebug() << "active layer shape id: " << m_d->activeLayerShape()->shapeId() << endl;
......@@ -1372,9 +1371,8 @@ void KisDoc2::addShape( KoShape* shape, KoShapeAddRemoveData *addRemoveData )
setModified( true );
}
void KisDoc2::removeShape( KoShape* shape, KoShapeAddRemoveData *addRemoveData )
void KisDoc2::removeShape( KoShape* shape )
{
Q_UNUSED( addRemoveData );
if ( !shape ) return;
kDebug() << ">>>>> KisDoc2::removeShape: " << shape->shapeId() << ", active layer: " << m_d->activeLayerShape() << endl;
......@@ -1386,7 +1384,7 @@ void KisDoc2::removeShape( KoShape* shape, KoShapeAddRemoveData *addRemoveData )
// If there are no longer children, remove the container
// layer, too.
if ( container->childCount() == 0 ) {
removeShape( container, 0 );
removeShape( container );
}
}
......
......@@ -41,8 +41,6 @@ class KoColorProfile;
class KoColorSpace;
class KoColor;
class KoShapeAddRemoveData;
class KisView2;
class KisNameServer;
class KisChildDoc;
......@@ -201,8 +199,8 @@ public:
// Implement KoShapeController
virtual void addShape( KoShape* shape, KoShapeAddRemoveData *addRemoveData );
virtual void removeShape( KoShape* shape, KoShapeAddRemoveData *addRemoveData );
virtual void addShape( KoShape* shape );
virtual void removeShape( KoShape* shape );
private:
......
......@@ -23,7 +23,6 @@
#include "KoShapeController.h"
KoCanvasBase::KoCanvasBase( KoShapeControllerBase * shapeControllerBase )
: m_addRemoveData( 0 )
{
m_resourceProvider = new KoCanvasResourceProvider(0);
m_shapeController = new KoShapeController( this, shapeControllerBase );
......
......@@ -40,7 +40,6 @@ class KoToolProxy;
class KoViewConverter;
class KoShapeController;
class KoShapeControllerBase;
class KoShapeAddRemoveData;
/**
* KoCanvasBase is the interface actual application canvas classes
......@@ -143,18 +142,6 @@ public:
*/
KoShapeController * shapeController() const { return m_shapeController; }
/**
* @brief Get data passed along during add/remove of a shape
* This will return 0 if it has not set.
*/
KoShapeAddRemoveData * addRemoveData() const { return m_addRemoveData; }
/**
* @brief Set data used for passing along during add/remove of a shape
* @param addRemoveData data used for inserting a shape
*/
void setAddRemoveData( KoShapeAddRemoveData * addRemoveData ) { m_addRemoveData = addRemoveData; }
#if 0
/* The next list of methods are naming taken from Krita, which means they have already been
......@@ -288,7 +275,6 @@ private:
KoShapeController *m_shapeController;
KoCanvasResourceProvider * m_resourceProvider;
KoShapeAddRemoveData *m_addRemoveData;
};
......
......@@ -21,6 +21,7 @@
#include "KoPathCommand.h"
#include "KoParameterShape.h"
#include "KoShapeControllerBase.h"
#include "KoShapeContainer.h"
#include <klocale.h>
#include <kdebug.h>
#include <math.h>
......@@ -627,13 +628,12 @@ void KoSegmentTypeCommand::undo()
}
KoPathCombineCommand::KoPathCombineCommand( KoShapeControllerBase *controller, const QList<KoPathShape*> &paths,
KoShapeAddRemoveData * addRemoveData, QUndoCommand *parent )
QUndoCommand *parent )
: QUndoCommand( parent )
, m_controller( controller )
, m_paths( paths )
, m_combinedPath( 0 )
, m_isCombined( false )
, m_addRemoveData( addRemoveData )
{
setText( i18n( "Combine paths" ) );
}
......@@ -657,6 +657,9 @@ void KoPathCombineCommand::redo()
if( ! m_combinedPath )
{
m_combinedPath = new KoPathShape();
KoShapeContainer * parent = m_paths.first()->parent();
if(parent)
parent->addChild(m_combinedPath);
m_combinedPath->setBorder( m_paths.first()->border() );
m_combinedPath->setShapeId( m_paths.first()->shapeId() );
// combine the paths
......@@ -669,9 +672,9 @@ void KoPathCombineCommand::redo()
if( m_controller )
{
foreach( KoPathShape* p, m_paths )
m_controller->removeShape( p, m_addRemoveData );
m_controller->removeShape( p );
m_controller->addShape( m_combinedPath, m_addRemoveData );
m_controller->addShape( m_combinedPath );
}
}
......@@ -684,9 +687,11 @@ void KoPathCombineCommand::undo()
if( m_controller )
{
m_controller->removeShape( m_combinedPath, m_addRemoveData );
m_controller->removeShape( m_combinedPath );
foreach( KoPathShape* p, m_paths )
m_controller->addShape( p, m_addRemoveData );
{
m_controller->addShape( p );
}
}
}
......@@ -760,12 +765,11 @@ void KoParameterToPathCommand::undo()
}
KoPathSeparateCommand::KoPathSeparateCommand( KoShapeControllerBase *controller, const QList<KoPathShape*> &paths,
KoShapeAddRemoveData *addRemoveData, QUndoCommand *parent )
QUndoCommand *parent )
: QUndoCommand( parent )
, m_controller( controller )
, m_paths( paths )
, m_isSeparated( false )
, m_addRemoveData( addRemoveData )
{
setText( i18n( "Separate paths" ) );
}
......@@ -786,7 +790,7 @@ KoPathSeparateCommand::~KoPathSeparateCommand()
void KoPathSeparateCommand::redo()
{
if( ! m_separatedPaths.size() )
if( m_separatedPaths.isEmpty() )
{
foreach( KoPathShape* p, m_paths )
{
......@@ -801,9 +805,9 @@ void KoPathSeparateCommand::redo()
if( m_controller )
{
foreach( KoPathShape* p, m_paths )
m_controller->removeShape( p, m_addRemoveData );
m_controller->removeShape( p );
foreach( KoPathShape *p, m_separatedPaths )
m_controller->addShape( p, m_addRemoveData );
m_controller->addShape( p );
}
foreach( KoPathShape* p, m_paths )
p->repaint();
......@@ -814,9 +818,9 @@ void KoPathSeparateCommand::undo()
if( m_controller )
{
foreach( KoPathShape *p, m_separatedPaths )
m_controller->removeShape( p, m_addRemoveData );
m_controller->removeShape( p );
foreach( KoPathShape* p, m_paths )
m_controller->addShape( p, m_addRemoveData );
m_controller->addShape( p );
}
m_isSeparated = false;
......
......@@ -29,7 +29,6 @@
#include <koffice_export.h>
class KoParameterShape;
class KoShapeAddRemoveData;
/// the base command for commands altering a path shape
class KoPathBaseCommand : public QUndoCommand {
......@@ -304,11 +303,9 @@ public:
* Command for combining a list of paths into one single path.
* @param controller the controller to used for removing/inserting.
* @param paths the list of paths to combine
* @param addRemoveData additional data for shape creation
* @param parent the parent command used for macro commands
*/
KoPathCombineCommand( KoShapeControllerBase *controller, const QList<KoPathShape*> &paths,
KoShapeAddRemoveData *addRemoveData = 0, QUndoCommand *parent = 0 );
KoPathCombineCommand( KoShapeControllerBase *controller, const QList<KoPathShape*> &paths, QUndoCommand *parent = 0 );
virtual ~KoPathCombineCommand();
/// redo the command
void redo();
......@@ -319,7 +316,6 @@ private:
QList<KoPathShape*> m_paths;
KoPathShape *m_combinedPath;
bool m_isCombined;
KoShapeAddRemoveData *m_addRemoveData;
};
/// The undo / redo command for changing a parameter
......@@ -365,11 +361,10 @@ public:
* Command for separating subpaths of a list of paths into different paths.
* @param controller the controller to used for removing/inserting.
* @param paths the list of paths to separate
* @param addRemoveData additional data for shape creation
* @param parent the parent command used for macro commands
*/
KoPathSeparateCommand( KoShapeControllerBase *controller, const QList<KoPathShape*> &paths,
KoShapeAddRemoveData *addRemoveData = 0, QUndoCommand *parent = 0 );
KoPathSeparateCommand( KoShapeControllerBase *controller, const QList<KoPathShape*> &paths,
QUndoCommand *parent = 0 );
virtual ~KoPathSeparateCommand();
/// redo the command
void redo();
......@@ -380,7 +375,6 @@ private:
QList<KoPathShape*> m_paths;
QList<KoPathShape*> m_separatedPaths;
bool m_isSeparated;
KoShapeAddRemoveData *m_addRemoveData;
};
#endif
/* This file is part of the KDE project
Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KOSHAPEADDREMOVEDATA_H
#define KOSHAPEADDREMOVEDATA_H
#include <koffice_export.h>
/**
* This is a virtual base class for an object that is passed to a KoShapeControllerBase
* during add/remove of a shape. A application can use it it pass any information that
* can be used to add/remove a shape.
* Only if an application sets this in KoCanvasBase the information is passed.
*/
class FLAKE_EXPORT KoShapeAddRemoveData
{
public:
/**
* @brief Constructor
*/
KoShapeAddRemoveData() {}
/**
* @brief Destructor
*/
virtual ~KoShapeAddRemoveData() {}
/**
* @brief Clone the object
*
* @return a copy of the object
*/
virtual KoShapeAddRemoveData * clone() const = 0;
};
#endif /* KOSHAPEADDREMOVEDATA_H */
......@@ -87,15 +87,19 @@ void KoShapeContainer::paint(QPainter &painter, const KoViewConverter &converter
// QPolygon clip = (myMatrix * shapeMatrix.inverted()).mapToPolygon(clipRect.toRect());
// painter.setClipRegion(QRegion(clip));
if(! childClipped(shape) )
continue;
/* if(! childClipped(shape) )
continue;*/
painter.save();
QRectF clipRect(QPointF(0, 0), size());
clipRect = converter.documentToView(clipRect);
QPolygon clip = myMatrix.mapToPolygon(clipRect.toRect());
clip.translate( (position() - converter.documentToView(position())).toPoint() );
painter.setClipRegion(QRegion(clip));
if( childClipped(shape) ) {
QRectF clipRect(QPointF(0, 0), size());
clipRect = converter.documentToView(clipRect);
QPolygon clip = myMatrix.mapToPolygon(clipRect.toRect());
clip.translate( (position() - converter.documentToView(position())).toPoint() );
painter.setClipRegion(QRegion(clip));
}
//kDebug() << "rect: " << position() << endl;
//kDebug() << "polygon: " << clip.boundingRect() << endl;
//painter.drawPolygon(clip);
......@@ -191,6 +195,9 @@ void KoShapeContainer::repaint() const {
}
QList<KoShape*> KoShapeContainer::iterator() const {
if(m_children == 0)
return QList<KoShape*>();
return m_children->iterator();
}
......
......@@ -97,13 +97,13 @@ QUndoCommand* KoShapeController::addShape( KoShape *shape )
{
shape->setParent( m_canvas->shapeManager()->selection()->activeLayer() );
}
KoShapeCreateCommand *cmd = new KoShapeCreateCommand( m_shapeController, shape, m_canvas->addRemoveData() );
KoShapeCreateCommand *cmd = new KoShapeCreateCommand( m_shapeController, shape );
return cmd;
}
QUndoCommand* KoShapeController::removeShape( KoShape *shape )
{
KoShapeDeleteCommand *cmd = new KoShapeDeleteCommand( m_shapeController, shape, m_canvas->addRemoveData() );
return cmd;
KoShapeDeleteCommand *cmd = new KoShapeDeleteCommand( m_shapeController, shape );
return cmd;
}
......@@ -23,7 +23,6 @@
#define KOSHAPECONTROLLERBASE_H
class KoShape;
class KoShapeAddRemoveData;
/**
* The shape controller is an abstract interface that the applications class
......@@ -42,7 +41,7 @@ public:
* @param shape the new shape
* @param addRemoveData additional data which can be used for adding the new shape
*/
virtual void addShape( KoShape* shape, KoShapeAddRemoveData* addRemoveData ) = 0;
virtual void addShape( KoShape* shape ) = 0;
/**
* Remove a shape from the shape controllers control, allowing it to be deleted shortly after
......@@ -50,7 +49,7 @@ public:
* @param shape the shape to remove
* @param addRemoveData additional data which can be used for removing the new shape
*/
virtual void removeShape( KoShape* shape, KoShapeAddRemoveData* addRemoveData ) = 0;
virtual void removeShape( KoShape* shape ) = 0;
};
#endif
......@@ -22,6 +22,7 @@
KoShapeLayer::KoShapeLayer()
: KoShapeContainer(new LayerMembers())
{
setSelectable(false);
}
bool KoShapeLayer::hitTest( const QPointF &position ) const
......@@ -32,19 +33,31 @@ bool KoShapeLayer::hitTest( const QPointF &position ) const
QRectF KoShapeLayer::boundingRect() const
{
QRectF bb;
QRectF bb(0.0, 0.0, 1.0, 1.0);
QRectF shapeRect;
foreach( KoShape* shape, iterator() )
{
if( bb.isEmpty() )
bb = shape->boundingRect();
else
bb = bb.unite( shape->boundingRect() );
}
foreach( KoShape* shape, iterator() )
{
shapeRect.setTopLeft(shape->position());
shapeRect.setSize(shape->size());
return bb;
bb = bb.unite( shapeRect );
}
return bb;
}
QSizeF KoShapeLayer::size() const
{
return boundingRect().size();
}
QPointF KoShapeLayer::position() const
{
return QPointF(0.0, 0.0);
}
// ############# LayerMembers #############
KoShapeLayer::LayerMembers::LayerMembers()
{
......
......@@ -40,6 +40,8 @@ public:
virtual void paintComponent(QPainter &, const KoViewConverter &) {};
bool hitTest( const QPointF &position ) const;
virtual QRectF boundingRect() const;
virtual QSizeF size() const;
virtual QPointF position() const;
private:
class LayerMembers: public KoShapeContainerModel {
public:
......
......@@ -90,6 +90,17 @@ void KoShapeManager::add( KoShape *shape )
m_tree.insert( br, shape );
}
shape->repaint();
// add the children of a KoShapeContainer
KoShapeContainer* container = dynamic_cast<KoShapeContainer*>(shape);
if(container)
{
foreach(KoShape* containerShape, container->iterator())
{
add(containerShape);
}
}
}
void KoShapeManager::remove( KoShape *shape )
......@@ -100,6 +111,17 @@ void KoShapeManager::remove( KoShape *shape )
m_aggregate4update.remove( shape );
m_tree.remove( shape );
m_shapes.removeAll(shape);
// remove the children of a KoShapeContainer
KoShapeContainer* container = dynamic_cast<KoShapeContainer*>(shape);
if(container)
{
foreach(KoShape* containerShape, container->iterator())
{
remove(containerShape);
}
}
}
void KoShapeManager::paint( QPainter &painter, const KoViewConverter &converter, bool forPrint)
......
......@@ -22,29 +22,22 @@
#include "KoShape.h"
#include "KoShapeContainer.h"
#include "KoShapeControllerBase.h"
#include "KoShapeAddRemoveData.h"
#include <klocale.h>
KoShapeCreateCommand::KoShapeCreateCommand( KoShapeControllerBase *controller, KoShape *shape,
KoShapeAddRemoveData *addRemoveData, QUndoCommand *parent )
KoShapeCreateCommand::KoShapeCreateCommand( KoShapeControllerBase *controller, KoShape *shape, QUndoCommand *parent )
: QUndoCommand( parent )
, m_controller( controller )
, m_shape( shape )
, m_shapeParent( shape->parent() )
, m_deleteShape( true )
, m_addRemoveData( 0 )
{
if ( addRemoveData )
m_addRemoveData = addRemoveData->clone();
setText( i18n( "Create shape" ) );
}
KoShapeCreateCommand::~KoShapeCreateCommand() {
if( m_shape && m_deleteShape )
delete m_shape;
delete m_addRemoveData;
}
void KoShapeCreateCommand::redo () {
......@@ -67,9 +60,9 @@ void KoShapeCreateCommand::undo () {
void KoShapeCreateCommand::recurse(KoShape *shape, const AddRemove ar) {
if(ar == Remove)
m_controller->removeShape( m_shape, m_addRemoveData );
m_controller->removeShape( m_shape );
else
m_controller->addShape( m_shape, m_addRemoveData );
m_controller->addShape( m_shape );
KoShapeContainer *container = dynamic_cast<KoShapeContainer*> (shape);
if(container) {
......
......@@ -26,7 +26,6 @@
class KoShape;
class KoShapeContainer;
class KoShapeControllerBase;
class KoShapeAddRemoveData;
/// The undo / redo command for creating shapes
class FLAKE_EXPORT KoShapeCreateCommand : public QUndoCommand {
......@@ -35,11 +34,10 @@ public:
* Command used on creation of new shapes
* @param controller the controller used to add/remove the shape from
* @param shape the shape thats just been created.
* @param addRemoveData additional data for shape creation
* @param parent the parent command used for macro commands
*/
KoShapeCreateCommand( KoShapeControllerBase *controller, KoShape *shape,
KoShapeAddRemoveData *addRemoveData, QUndoCommand *parent = 0 );
QUndoCommand *parent = 0 );
virtual ~KoShapeCreateCommand();
/// redo the command
void redo ();
......@@ -53,7 +51,6 @@ private:
KoShape *m_shape;
KoShapeContainer *m_shapeParent;
bool m_deleteShape;
KoShapeAddRemoveData * m_addRemoveData;
};
#endif
......@@ -21,41 +21,31 @@
#include "KoShapeDeleteCommand.h"
#include "KoShapeContainer.h"
#include "KoShapeControllerBase.h"
#include "KoShapeAddRemoveData.h"
#include <klocale.h>
KoShapeDeleteCommand::KoShapeDeleteCommand( KoShapeControllerBase *controller, KoShape *shape,
KoShapeAddRemoveData *addRemoveData, QUndoCommand *parent )
KoShapeDeleteCommand::KoShapeDeleteCommand( KoShapeControllerBase *controller, KoShape *shape, QUndoCommand *parent )
: QUndoCommand( parent )
, m_controller( controller )
, m_deleteShapes( false )
, m_addRemoveData( 0 )
{
m_shapes.append( shape );
m_oldParents.append( shape->parent() );
if ( addRemoveData )
m_addRemoveData = addRemoveData->clone();
setText( i18n( "Delete shapes" ) );
}
KoShapeDeleteCommand::KoShapeDeleteCommand( KoShapeControllerBase *controller, const KoSelectionSet &shapes,
KoShapeAddRemoveData *addRemoveData, QUndoCommand *parent)
QUndoCommand *parent)
: QUndoCommand( parent )
, m_controller( controller )
, m_deleteShapes( false )
, m_addRemoveData( 0 )
{
m_shapes = shapes.toList();
foreach( KoShape *shape, m_shapes ) {
m_oldParents.append( shape->parent() );
}
if ( addRemoveData )
m_addRemoveData = addRemoveData->clone();
setText( i18n( "Delete shapes" ) );
}
......@@ -66,7 +56,6 @@ KoShapeDeleteCommand::~KoShapeDeleteCommand() {
foreach (KoShape *shape, m_shapes ) {
delete shape;
}
delete m_addRemoveData;
}
void KoShapeDeleteCommand::redo () {
......@@ -76,7 +65,7 @@ void KoShapeDeleteCommand::redo () {
for(int i=0; i < m_shapes.count(); i++) {
if( m_oldParents.at( i ) )
m_oldParents.at( i )->removeChild( m_shapes[i] );
m_controller->removeShape( m_shapes[i], m_addRemoveData );
m_controller->removeShape( m_shapes[i] );
}
m_deleteShapes = true;
}
......@@ -88,7 +77,7 @@ void KoShapeDeleteCommand::undo () {
for(int i=0; i < m_shapes.count(); i++) {
if( m_oldParents.at( i ) )
m_oldParents.at( i )->addChild( m_shapes[i] );
m_controller->addShape( m_shapes[i], m_addRemoveData );
m_controller->addShape( m_shapes[i] );
}
m_deleteShapes = false;
}
......@@ -29,7 +29,6 @@
class KoShape;
class KoShapeContainer;