Commit ba2f3bcf authored by Thomas Zander's avatar Thomas Zander

Move the default tool to live as a plugin.

This enables us to use classes from the guiutil lib in the default tool.

svn path=/trunk/koffice/; revision=741170
parent 57079f09
......@@ -38,6 +38,7 @@
#include <KoID.h>
#include <KoCanvasBase.h>
#include <KoViewConverter.h>
#include <KoSelection.h>
#include <KoCompositeOp.h>
#include <KoShapeManager.h>
......
......@@ -15,8 +15,6 @@ set(flake_SRCS
KoCanvasResourceProvider.cpp
KoInteractionStrategy.cpp
KoInteractionTool.cpp
KoInteractionToolWidget.cpp
KoInteractionToolFactory.cpp
KoPathShape.cpp
KoPathPoint.cpp
KoSelection.cpp
......@@ -26,10 +24,6 @@ set(flake_SRCS
KoShapeConnection.cpp
KoShapeManagerPaintingStrategy.cpp
KoShapeManager.cpp
KoShapeMoveStrategy.cpp
KoShapeResizeStrategy.cpp
KoShapeRotateStrategy.cpp
KoShapeShearStrategy.cpp
KoShapeRubberSelectStrategy.cpp
KoTool.cpp
KoCanvasController.cpp
......@@ -122,7 +116,6 @@ set(flake_SRCS
)
kde4_add_ui_files(flake_SRCS
KoInteractionToolWidget.ui
PathToolOptionWidgetBase.ui
KoConnectionShapeConfigWidget.ui
)
......
......@@ -26,6 +26,7 @@
#include "KoPointerEvent.h"
#include "KoInteractionStrategy.h"
#include "KoCreateShapeStrategy.h"
class KoCreateShapesTool::Private {
......@@ -52,11 +53,6 @@ void KoCreateShapesTool::paint( QPainter &painter, const KoViewConverter &conver
m_currentStrategy->paint( painter, converter);
}
void KoCreateShapesTool::mouseMoveEvent( KoPointerEvent *event ) {
if(m_currentStrategy)
m_currentStrategy->handleMouseMove( event->point, event->modifiers() );
}
void KoCreateShapesTool::mouseReleaseEvent( KoPointerEvent *event ) {
KoInteractionTool::mouseReleaseEvent(event);
emit KoTool::done();
......@@ -77,3 +73,8 @@ void KoCreateShapesTool::setShapeProperties( KoProperties *properties ) {
KoProperties const * KoCreateShapesTool::shapeProperties() {
return d->newShapeProperties;
}
KoInteractionStrategy *KoCreateShapesTool::createStrategy(KoPointerEvent *event) {
return new KoCreateShapeStrategy(this, m_canvas, event->point);
}
......@@ -46,8 +46,7 @@ public:
explicit KoCreateShapesTool( KoCanvasBase *canvas );
/// destructor
virtual ~KoCreateShapesTool();
void mouseMoveEvent( KoPointerEvent *event );
void mouseReleaseEvent( KoPointerEvent *event );
virtual void mouseReleaseEvent( KoPointerEvent *event );
void paint( QPainter &painter, const KoViewConverter &converter );
......@@ -76,6 +75,9 @@ public:
*/
KoProperties const * shapeProperties();
protected:
virtual KoInteractionStrategy *createStrategy(KoPointerEvent *event);
private:
friend class KoCreateShapeStrategy;
......
......@@ -73,70 +73,7 @@ QPointF KoInteractionStrategy::snapToGrid( const QPointF &point, Qt::KeyboardMod
}
// static
KoInteractionStrategy* KoInteractionStrategy::createStrategy(KoPointerEvent *event, KoInteractionTool *parent, KoCanvasBase *canvas) {
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();
KoSelection *select = shapeManager->selection();
bool insideSelection, editableShape=false;
KoFlake::SelectionHandle handle = parent->handleAt(event->point, &insideSelection);
foreach (KoShape* shape, select->selectedShapes()) {
if( isEditable( shape ) ) {
editableShape = true;
break;
}
}
if(editableShape && (event->modifiers() == Qt::NoModifier )) {
// manipulation of selected shapes goes first
if(handle != KoFlake::NoHandle) {
if(insideSelection)
return new KoShapeResizeStrategy(parent, canvas, event->point, handle);
if(handle == KoFlake::TopMiddleHandle || handle == KoFlake::RightMiddleHandle ||
handle == KoFlake::BottomMiddleHandle || handle == KoFlake::LeftMiddleHandle)
return new KoShapeShearStrategy(parent, canvas, event->point, handle);
return new KoShapeRotateStrategy(parent, canvas, event->point);
}
// This is wrong now when there is a single rotated object as you get it also when pressing outside of the object
if(select->boundingRect().contains(event->point))
return new KoShapeMoveStrategy(parent, canvas, event->point);
}
KoShape * object( shapeManager->shapeAt( event->point, (event->modifiers() & Qt::ShiftModifier) ? KoFlake::NextUnselected : KoFlake::ShapeOnTop ) );
if( !object && handle == KoFlake::NoHandle) {
if ( ( event->modifiers() & Qt::ControlModifier ) == 0 )
{
parent->repaintDecorations();
select->deselectAll();
}
return new KoShapeRubberSelectStrategy(parent, canvas, event->point);
}
if(select->isSelected(object)) {
if ((event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier ) {
parent->repaintDecorations();
select->deselect(object);
}
}
else if(handle == KoFlake::NoHandle) { // clicked on object which is not selected
parent->repaintDecorations();
if ( ( event->modifiers() & Qt::ControlModifier ) == 0 )
shapeManager->selection()->deselectAll();
select->select(object);
parent->repaintDecorations();
return new KoShapeMoveStrategy(parent, canvas, event->point);
}
return 0;
}
// static
bool KoInteractionStrategy::isEditable( KoShape * shape ) {
bool KoInteractionStrategy::isEditable( const KoShape * shape ) {
Q_ASSERT(shape);
if( !shape || !shape->isVisible() || shape->isLocked() )
......
......@@ -22,11 +22,12 @@
#ifndef KOINTERACTIONSTRATEGY_H
#define KOINTERACTIONSTRATEGY_H
#include "flake_export.h"
#include "KoSelection.h"
#include <QList>
#include <QPainter>
#include <KoSelection.h>
class KoPointerEvent;
class QUndoCommand;
class KoCanvasBase;
......@@ -44,7 +45,7 @@ class KoTool;
* The mouseMove events are forwarded to the handleMouseMove() method and the interaction
* is either finished with finishInteraction() or cancelInteraction() (never both).
*/
class KoInteractionStrategy
class FLAKE_EXPORT KoInteractionStrategy
{
public:
/// Destructor
......@@ -79,11 +80,6 @@ public:
*/
virtual void finishInteraction( Qt::KeyboardModifiers modifiers ) = 0;
/**
* This instanciates a new strategy object and decides which one created based on the params.
*/
static KoInteractionStrategy* createStrategy(KoPointerEvent *event, KoInteractionTool *parentTool, KoCanvasBase *canvas);
protected:
/// protected constructor. Use the createStrategy method()
KoInteractionStrategy(KoTool *parent, KoCanvasBase *canvas);
......@@ -101,8 +97,9 @@ protected:
*/
QPointF snapToGrid( const QPointF &point, Qt::KeyboardModifiers modifiers );
friend class KoInteractionTool;
/// checks recursively if the shape or one of its parents is not visible or locked
static bool isEditable( KoShape * shape );
static bool isEditable( const KoShape * shape );
protected: // members
KoTool *m_parent; ///< the KoTool instance that controls this strategy.
......
This diff is collapsed.
......@@ -23,17 +23,10 @@
#define KOINTERACTIONTOOL_H
#include "KoTool.h"
#include "KoSelection.h"
#include "commands/KoShapeAlignCommand.h"
#include <flake_export.h>
//#include <k3staticdeleter.h>
#include <QImage>
#include <QTime>
#include "flake_export.h"
class KoInteractionStrategy;
class KoShape;
#define KoInteractionTool_ID "InteractionTool"
......@@ -58,112 +51,30 @@ public:
virtual ~KoInteractionTool();
public:
virtual bool wantsAutoScroll();
virtual void paint( QPainter &painter, const KoViewConverter &converter );
virtual void repaintDecorations();
/**
* Returns which selection handle is at params point (or NoHandle if none).
* @return which selection handle is at params point (or NoHandle if none).
* @param point the location (in pt) where we should look for a handle
* @param innerHandleMeaning this boolean is altered to true if the point
* is inside the selection rectangle and false if it is just outside.
* The value of innerHandleMeaning is undefined if the handle location is NoHandle
*/
KoFlake::SelectionHandle handleAt(const QPointF &point, bool *innerHandleMeaning = 0);
public slots:
void activate(bool temporary = false);
private slots:
void selectionAlignHorizontalLeft();
void selectionAlignHorizontalCenter();
void selectionAlignHorizontalRight();
void selectionAlignVerticalTop();
void selectionAlignVerticalCenter();
void selectionAlignVerticalBottom();
void updateHotPosition( KoFlake::Position hotPosition );
public: // Events
virtual void mousePressEvent( KoPointerEvent *event );
virtual void mouseMoveEvent( KoPointerEvent *event );
virtual void mouseReleaseEvent( KoPointerEvent *event );
virtual void mouseDoubleClickEvent( KoPointerEvent *event );
virtual void keyPressEvent(QKeyEvent *event);
virtual void keyReleaseEvent(QKeyEvent *event);
protected:
KoInteractionStrategy *m_currentStrategy; ///< the strategy that is 'in progress'
QWidget* createOptionWidget();
private:
void setupActions();
void recalcSelectionBox();
void updateCursor();
/// Returns rotation angle of given handle of the current selection
double rotationOfHandle( KoFlake::SelectionHandle handle, bool useEdgeRotation );
void selectionAlign(KoShapeAlignCommand::Align align);
virtual KoInteractionStrategy *createStrategy(KoPointerEvent *event) = 0;
/// checks recursively if the shape or one of its parents is not visible or locked
static bool shapeIsEditable( const KoShape * shape );
private:
KoInteractionTool(const KoInteractionTool&);
KoInteractionTool& operator=(const KoInteractionTool&);
QRectF handlesSize();
// convenience method;
KoSelection * koSelection();
class Private;
Private * const d;
};
/**
* The SelectionDecorator is used to paint extra user-interface items on top of a selection.
*/
class SelectionDecorator {
public:
/**
* Constructor.
* @param arrows the direction that needs highlighting. (currently unused)
* @param rotationHandles if true; the rotation handles will be drawn
* @param shearHandles if true; the shearhandles will be drawn
*/
SelectionDecorator(KoFlake::SelectionHandle arrows, bool rotationHandles, bool shearHandles);
~SelectionDecorator() {}
/**
* paint the decortations.
* @param painter the painter to paint to.
* @param converter to convert between internal and view coordinates.
*/
void paint(QPainter &painter, const KoViewConverter &converter);
/**
* set the selection that is to be painted.
* @param selection the current selection.
*/
void setSelection(KoSelection *selection);
/**
* set the radius of the selection handles
* @param radius the new handle radius
*/
void setHandleRadius( int radius );
/// Sets the hot position to highlight
static void setHotPosition( KoFlake::Position hotPosition );
private:
bool m_rotationHandles, m_shearHandles;
KoFlake::SelectionHandle m_arrows;
static KoFlake::Position m_hotPosition;
KoSelection *m_selection;
int m_handleRadius;
static QImage *s_rotateCursor;
};
#endif /* KOINTERACTIONTOOL_H */
......@@ -26,6 +26,8 @@
#include <QRectF>
#include <flake_export.h>
class QPainter;
class QPointF;
......@@ -35,7 +37,7 @@ class KoTool;
/**
* Implement the rubber band selection of flake objects.
*/
class KoShapeRubberSelectStrategy : public KoInteractionStrategy
class FLAKE_EXPORT KoShapeRubberSelectStrategy : public KoInteractionStrategy
{
public:
/**
......
......@@ -27,9 +27,9 @@
#include "KoCreatePathToolFactory.h"
#include "KoCreateShapesToolFactory.h"
#include "KoCreateShapesTool.h"
#include "KoInteractionToolFactory.h"
#include "KoPathToolFactory.h"
#include "KoCanvasController.h"
#include "KoShape.h"
#include "KoShapeRegistry.h"
#include "KoShapeManager.h"
#include "KoCanvasBase.h"
......@@ -83,7 +83,7 @@ public:
class KoToolManager::Private {
public:
Private() : defaultTool(0), canvasData(0)
Private() : canvasData(0)
{
tabletEventTimer.setSingleShot(true);
}
......@@ -93,7 +93,6 @@ public:
}
QList<ToolHelper*> tools; // list of all available tools via their factories.
ToolHelper *defaultTool; // the pointer thingy
QHash<KoTool*, int> uniqueToolIds; // for the changedTool signal
QHash<KoCanvasController*, QList<CanvasData*> > canvasses;
......@@ -166,8 +165,6 @@ void KoToolManager::setup() {
d->tools.append( new ToolHelper(new KoPathToolFactory(this)) );
d->tools.append( new ToolHelper(new KoZoomToolFactory(this)) );
d->tools.append( new ToolHelper(new KoPanToolFactory(this)) );
d->defaultTool = new ToolHelper(new KoInteractionToolFactory(this));
d->tools.append(d->defaultTool);
KoShapeRegistry::instance();
KoToolRegistry *registry = KoToolRegistry::instance();
......@@ -397,8 +394,8 @@ void KoToolManager::attachCanvas(KoCanvasController *controller) {
if(tp)
tp->setCanvasController(controller);
if (cd->activeTool == 0)
toolActivated(d->defaultTool);
// if (cd->activeTool == 0)
// toolActivated(d->defaultTool); // TODO
Connector *connector = new Connector(controller->canvas()->shapeManager());
connect(connector, SIGNAL(selectionChanged(QList<KoShape*>)), this,
......
......@@ -39,11 +39,6 @@ KoZoomTool::KoZoomTool(KoCanvasBase *canvas)
m_outCursor = QCursor(outPixmap);
}
void KoZoomTool::paint( QPainter &painter, const KoViewConverter &converter) {
if ( m_currentStrategy )
m_currentStrategy->paint( painter, converter);
}
void KoZoomTool::wheelEvent ( KoPointerEvent * event )
{
if(event->modifiers() & Qt::ControlModifier)
......@@ -64,10 +59,6 @@ void KoZoomTool::mouseReleaseEvent( KoPointerEvent *event ) {
emit KoTool::done();
}
void KoZoomTool::mousePressEvent( KoPointerEvent *event ) {
m_currentStrategy = new KoZoomStrategy(this, m_controller, event->point);
}
void KoZoomTool::mouseMoveEvent( KoPointerEvent *event ) {
if(event->modifiers() & Qt::ControlModifier)
useCursor(m_outCursor);
......@@ -106,5 +97,6 @@ void KoZoomTool::mouseDoubleClickEvent( KoPointerEvent *event ) {
mousePressEvent(event);
}
void KoZoomTool::repaintDecorations() {
KoInteractionStrategy *KoZoomTool::createStrategy(KoPointerEvent *event) {
return new KoZoomStrategy(this, m_controller, event->point);
}
......@@ -43,8 +43,6 @@ public:
/// reimplemented method
virtual void mouseReleaseEvent( KoPointerEvent *event );
/// reimplemented method
virtual void mousePressEvent( KoPointerEvent *event );
/// reimplemented method
virtual void mouseMoveEvent( KoPointerEvent *event );
/// reimplemented method
virtual void keyPressEvent( QKeyEvent *event );
......@@ -55,13 +53,12 @@ public:
/// reimplemented method
virtual void mouseDoubleClickEvent( KoPointerEvent *event );
/// reimplemented method
virtual void repaintDecorations();
/// reimplemented method
virtual void paint( QPainter &painter, const KoViewConverter &converter );
void setCanvasController(KoCanvasController *controller) { m_controller = controller; }
private:
/// reimplemented method
virtual KoInteractionStrategy *createStrategy(KoPointerEvent *event);
KoCanvasController *m_controller;
QCursor m_inCursor;
QCursor m_outCursor;
......
kde4_install_icons( ${DATA_INSTALL_DIR}/koffice/icons )
install( FILES rotate.png shear.png zoom_in_cursor.png zoom_out_cursor.png DESTINATION ${DATA_INSTALL_DIR}/koffice/icons)
project( defaulttools )
include_directories( ${FLAKE_INCLUDES} ${QT_INCLUDES} ${KOMAIN_INCLUDES} )
include_directories( ${FLAKE_INCLUDES} ${QT_INCLUDES} ${KOMAIN_INCLUDES} ${KOGUIUTIL_INCLUDES})
add_subdirectory(pics)
########### Flake Plugin library ###############
......@@ -8,10 +11,19 @@ SET ( defaulttools_SRCS
Plugin.cpp
ConnectionTool.cpp
ConnectionToolFactory.cpp
defaulttool/DefaultTool.cpp
defaulttool/DefaultToolFactory.cpp
defaulttool/DefaultToolWidget.cpp
defaulttool/ShapeMoveStrategy.cpp
defaulttool/ShapeResizeStrategy.cpp
defaulttool/ShapeRotateStrategy.cpp
defaulttool/ShapeShearStrategy.cpp
defaulttool/SelectionDecorator.cpp
)
#kde4_add_ui_files(defaulttools_SRCS
#)
kde4_add_ui_files(defaulttools_SRCS
defaulttool/DefaultToolWidget.ui
)
kde4_add_plugin(defaulttools ${defaulttools_SRCS})
target_link_libraries(defaulttools flake koguiutils kotext)
......
......@@ -18,6 +18,7 @@
*/
#include "Plugin.h"
#include "ConnectionToolFactory.h"
#include "defaulttool/DefaultToolFactory.h"
#include <KoShapeRegistry.h>
#include <KoToolRegistry.h>
......@@ -30,6 +31,7 @@ Plugin::Plugin(QObject * parent, const QStringList &)
: QObject(parent)
{
KoToolRegistry::instance()->add(new ConnectionToolFactory(parent));
KoToolRegistry::instance()->add(new DefaultToolFactory(parent));
}
#include "Plugin.moc"
This diff is collapsed.
/* This file is part of the KDE project
Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2006-2007 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 DEFAULTTOOL_H
#define DEFAULTTOOL_H
#include <KoInteractionTool.h>
#include <KoSelection.h>
#include <commands/KoShapeAlignCommand.h>
//#include <k3staticdeleter.h>
#include <QImage>
#include <QTime>
class KoInteractionStrategy;
class KoShapeMoveCommand;
/**
* 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 DefaultTool : public KoInteractionTool
{
Q_OBJECT
public:
/**
* Constructor for basic interaction tool where user actions are translated
* and handled by interaction strategies of type KoInteractionStrategy.
* @param canvas the canvas this tool will be working for.
*/
explicit DefaultTool( KoCanvasBase *canvas );
virtual ~DefaultTool();
public:
virtual bool wantsAutoScroll();
virtual void paint( QPainter &painter, const KoViewConverter &converter );
virtual void repaintDecorations();
/**
* Returns which selection handle is at params point (or NoHandle if none).
* @return which selection handle is at params point (or NoHandle if none).
* @param point the location (in pt) where we should look for a handle
* @param innerHandleMeaning this boolean is altered to true if the point
* is inside the selection rectangle and false if it is just outside.
* The value of innerHandleMeaning is undefined if the handle location is NoHandle
*/
KoFlake::SelectionHandle handleAt(const QPointF &point, bool *innerHandleMeaning = 0);
public slots:
void activate(bool temporary = false);
private slots:
void selectionAlignHorizontalLeft();
void selectionAlignHorizontalCenter();
void selectionAlignHorizontalRight();
void selectionAlignVerticalTop();
void selectionAlignVerticalCenter();
void selectionAlignVerticalBottom();
void updateHotPosition( KoFlake::Position hotPosition );
public: // Events
virtual void mousePressEvent( KoPointerEvent *event );
virtual void mouseMoveEvent( KoPointerEvent *event );
virtual void mouseReleaseEvent( KoPointerEvent *event );
virtual void mouseDoubleClickEvent( KoPointerEvent *event );
virtual void keyPressEvent(QKeyEvent *event);
protected:
QWidget* createOptionWidget();
virtual KoInteractionStrategy *createStrategy(KoPointerEvent *event);
private:
void setupActions();
void recalcSelectionBox();
void updateCursor();
/// Returns rotation angle of given handle of the current selection
double rotationOfHandle( KoFlake::SelectionHandle handle, bool useEdgeRotation );
void selectionAlign(KoShapeAlignCommand::Align align);
QRectF handlesSize();
// convenience method;
KoSelection * koSelection();
KoFlake::SelectionHandle m_lastHandle;
KoFlake::Position m_hotPosition;
bool m_mouseWasInsideHandles;
QPointF m_selectionBox[8];
QPolygonF m_selectionOutline;
QPointF m_lastPoint;
KoShapeMoveCommand *m_moveCommand;
QTime m_lastUsedMoveCommand;
// TODO alter these 3 arrays to be static const instead
QCursor m_sizeCursors[8];
QCursor m_rotateCursors[8];
QCursor m_shearCursors[8];
double m_angle;
};
#endif
......@@ -18,14 +18,12 @@
* Boston, MA 02110-1301, USA.
*/
#include "KoInteractionToolFactory.h"
#include "KoInteractionTool.h"
#include "DefaultToolFactory.h"
#include "DefaultTool.h"
#include <klocale.h>
#include <QPixmap>
KoInteractionToolFactory::KoInteractionToolFactory(QObject *parent)
DefaultToolFactory::DefaultToolFactory(QObject *parent)
: KoToolFactory(parent, KoInteractionTool_ID, i18n("Default Tool"))
{
setToolTip(i18n("Default tool"));
......@@ -35,9 +33,9 @@ KoInteractionToolFactory::KoInteractionToolFactory(QObject *parent)
setActivationShapeId("flake/always");
}
KoInteractionToolFactory::~KoInteractionToolFactory() {
DefaultToolFactory::~DefaultToolFactory() {
}
KoTool* KoInteractionToolFactory::createTool(KoCanvasBase *canvas) {
return new KoInteractionTool(canvas);
KoTool* DefaultToolFactory::createTool(KoCanvasBase *canvas) {
return new DefaultTool(canvas);
}