Commit dc2b921d authored by Thomas Zander's avatar Thomas Zander

Add a new Tool, a CreateShape tool. It allows you to drag an outline over

the canvas and will replace it with a created shape afterwards.

svn path=/trunk/koffice/; revision=546693
parent 9dacf003
......@@ -21,6 +21,8 @@ set(flake_SRCS
KoShapeRubberSelectStrategy.cpp
KoTool.cpp
KoCanvasView.cpp
KoCreateShapeStrategy.cpp
KoCreateShapesTool.cpp
)
kde4_automoc(${flake_SRCS})
......
......@@ -171,17 +171,15 @@ KoShapeCreateCommand::~KoShapeCreateCommand() {
}
void KoShapeCreateCommand::execute () {
if( ! m_shape || ! m_controller )
return;
Q_ASSERT(m_shape);
Q_ASSERT(m_controller);
m_controller->addShape( m_shape );
m_deleteShape = false;
}
void KoShapeCreateCommand::unexecute () {
if( ! m_shape || ! m_controller )
return;
Q_ASSERT(m_shape);
Q_ASSERT(m_controller);
m_controller->removeShape( m_shape );
m_deleteShape = true;
}
......
/* This file is part of the KDE project
* Copyright (C) 2006 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
* 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.
*/
#include "KoCreateShapeStrategy.h"
#include "KoCreateShapesTool.h"
#include "KoShapeControllerInterface.h"
#include "KoCommand.h"
#include "KoCanvasBase.h"
KoCreateShapeStrategy::KoCreateShapeStrategy( KoCreateShapesTool *tool, KoCanvasBase *canvas, const QPointF &clicked)
: KoShapeRubberSelectStrategy(tool, canvas, clicked)
, m_tool(tool)
{
}
KCommand* KoCreateShapeStrategy::createCommand() {
KoShape *shape = m_tool->controller()->createShape(selectRect());
KoShapeCreateCommand *cmd = new KoShapeCreateCommand(m_tool->controller(), shape);
cmd->execute();
return cmd;
}
void KoCreateShapeStrategy::finishInteraction() {
m_canvas->updateCanvas(selectRect());
}
/* This file is part of the KDE project
* Copyright (C) 2006 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
* 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 KOCREATESHAPESTRATEGY_H
#define KOCREATESHAPESTRATEGY_H
#include "KoShapeRubberSelectStrategy.h"
#include <QPointF>
class KoCanvasBase;
class KoCreateShapesTool;
/**
* A strategy for the KoCreateShapesTool.
*/
class KoCreateShapeStrategy : public KoShapeRubberSelectStrategy {
public:
/**
* Constructor that starts to create a new shape.
* @param tool the parent tool which controls this strategy
* @param canvas the canvas interface which will supply things like a selection object
* @param clicked the initial point that the user depressed (in pt).
*/
KoCreateShapeStrategy( KoCreateShapesTool *tool, KoCanvasBase *canvas, const QPointF &clicked );
virtual ~KoCreateShapeStrategy() {}
void finishInteraction();
KCommand* createCommand();
private:
KoCreateShapesTool *m_tool;
};
#endif /* KOSHAPEROTATESTRATEGY_H */
/* This file is part of the KDE project
*
* Copyright (C) 2006 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
* 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.
*/
#include "KoCreateShapesTool.h"
#include <QDebug>
#include <QMouseEvent>
#include <QPainter>
#include "KoInteractionStrategy.h"
#include <kcommand.h>
KoCreateShapesTool::KoCreateShapesTool(KoCanvasBase *canvas, KoShapeControllerInterface *sci )
: KoInteractionTool( canvas )
, m_shapeController( sci )
{
}
QCursor KoCreateShapesTool::cursor( const QPointF &position ) {
return Qt::ArrowCursor; // TODO
}
void KoCreateShapesTool::paint( QPainter &painter, KoViewConverter &converter) {
if ( m_currentStrategy )
m_currentStrategy->paint( painter, converter);
}
/* This file is part of the KDE project
*
* Copyright (C) 2006 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
* 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 KOCREATESHAPESTOOL_H
#define KOCREATESHAPESTOOL_H
#include "KoInteractionTool.h"
#include <koffice_export.h>
class KoCanvasBase;
class KoShapeControllerInterface;
class FLAKE_EXPORT KoCreateShapesTool : public KoInteractionTool
{
public:
KoCreateShapesTool( KoCanvasBase *canvas, KoShapeControllerInterface *sci );
virtual ~KoCreateShapesTool() {};
QCursor cursor( const QPointF &position );
void paint( QPainter &painter, KoViewConverter &converter );
KoShapeControllerInterface* controller() const { return m_shapeController; }
private:
KoShapeControllerInterface *m_shapeController;
};
#endif
......@@ -25,6 +25,8 @@
#include "KoShapeMoveStrategy.h"
#include "KoShapeRotateStrategy.h"
#include "KoShapeResizeStrategy.h"
#include "KoCreateShapeStrategy.h"
#include "KoCreateShapesTool.h"
#include "KoInteractionTool.h"
#include "KoCanvasBase.h"
#include "KoTool.h"
......@@ -52,6 +54,10 @@ KoInteractionStrategy* KoInteractionStrategy::createStrategy(KoGfxEvent *event,
if((event->buttons() & Qt::LeftButton) == 0)
return 0; // Nothing to do for middle/right mouse button
KoCreateShapesTool *crs = dynamic_cast<KoCreateShapesTool*>(parent);
if(crs)
return new KoCreateShapeStrategy(crs, canvas, event->point);
KoShapeManager *shapeManager = canvas->shapeManager();
KoShape * object( shapeManager->getObjectAt( event->point ) );
KoSelection *select = shapeManager->selection();
......
......@@ -30,11 +30,12 @@
class KoInteractionStrategy;
/**
* The default tool (associated with the arrow icon) implements the moving
* and selecting of flake objects.
*
* XXX: Also transforms? Or better use a separate tool for that.
* XXX: We already have a moveTool; and 'default' does not say much about the class. What about renaming to KoSelectTool ? (TZ)
* The default tool (associated with the arrow icon) implements the default
* interactions you have with flake objects.<br>
* The tool provides scaling, moving, selecting, rotation and soon skewing of
* any number of shapes.
* <p>Note that the implementation of those different strategies are delegated
* to the InteractionStrategy class and its subclasses.
*/
class FLAKE_EXPORT KoInteractionTool : public KoTool
{
......@@ -106,13 +107,15 @@ signals:
void sigDone();
protected:
KoInteractionStrategy *m_currentStrategy;
private:
void recalcSelectionBox();
KoInteractionTool(const KoInteractionTool&);
KoInteractionTool& operator=(const KoInteractionTool&);
KoInteractionStrategy *m_currentStrategy;
QRectF handlesSize();
// convenience method;
......
......@@ -22,9 +22,9 @@
#define KOSHAPECONTROLLERINTERFACE_H
/**
* The shape controller is an abstract interface to be implemented by the
* different applications document classes to allow passing them
* to commands which can add, remove or otherwise change shapes.
* The shape controller is an abstract interface that the applications class
* that controls the shapes should implement. This tends to be the document.
* @see KoShapeDeleteCommand, KoShapeCreateCommand
*/
class KoShapeControllerInterface
{
......@@ -32,12 +32,29 @@ public:
KoShapeControllerInterface() { }
virtual ~KoShapeControllerInterface() { }
/// adds a new shape
/**
* Add a shape to the shape controller, allowing it to be seen and saved.
* The controller should add the shape to the ShapeManager instance(s) manually
* if the shape is one that should be currently shown on screen.
* @param shape the new shape
*/
virtual void addShape( KoShape* shape ) = 0;
/// removes an existing shape
/**
* Remove a shape from the shape controllers control, allowing it to be deleted shortly after
* The controller should remove the shape from all the ShapeManager instance(s) manually
* @param shape the shape to remove
*/
virtual void removeShape( KoShape* shape ) = 0;
/**
* Factory method to create shapes.
* The CreateShapesTool will call this one when the user selected the outline for
* the position and size of the shape.<br>
* The implementor of this interface can choose to create different types of shapes
* based on things like which button was pressed to activate the create tool.
*/
virtual KoShape* createShape(QRectF outline) const = 0;
};
#endif // KOSHAPECONTROLLERINTERFACE_H
......@@ -100,3 +100,7 @@ void KoShapeRubberSelectStrategy::finishInteraction()
m_parent->repaintDecorations();
m_canvas->updateCanvas(m_selectRect.normalized());
}
const QRectF KoShapeRubberSelectStrategy::selectRect() const {
return m_selectRect.normalized();
}
......@@ -53,8 +53,11 @@ public:
void paint( QPainter &painter, KoViewConverter &converter);
void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers);
KCommand* createCommand() { return 0; }
void finishInteraction();
virtual KCommand* createCommand() { return 0; }
virtual void finishInteraction();
protected:
const QRectF selectRect() const;
private:
QRectF m_selectRect;
......
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