Commit 3c7ac765 authored by Thomas Zander's avatar Thomas Zander

follow refactor in flake

svn path=/trunk/koffice/; revision=1067059
parent 5e77fab2
......@@ -738,16 +738,16 @@ void DefaultTool::customMoveEvent(KoPointerEvent * event)
if (zoom > move && zoom > rotate) {
// zoom
if (! m_customEventStrategy)
m_customEventStrategy = new ShapeResizeStrategy(this, m_canvas, event->point, KoFlake::TopLeftHandle);
m_customEventStrategy = new ShapeResizeStrategy(this, event->point, KoFlake::TopLeftHandle);
} else if (move > zoom && move > rotate) { // check if x-/y-movement is dominant
// move
if (! m_customEventStrategy)
m_customEventStrategy = new ShapeMoveStrategy(this, m_canvas, event->point);
m_customEventStrategy = new ShapeMoveStrategy(this, event->point);
} else if (rotate > zoom && rotate > move) // rotation is dominant
{
// rotate
if (! m_customEventStrategy)
m_customEventStrategy = new ShapeRotateStrategy(this, m_canvas, event->point, event->buttons());
m_customEventStrategy = new ShapeRotateStrategy(this, event->point, event->buttons());
}
if (m_customEventStrategy)
......@@ -1150,20 +1150,20 @@ KoInteractionStrategy *DefaultTool::createStrategy(KoPointerEvent *event)
if (event->buttons() == Qt::LeftButton) {
// resizing or shearing only with left mouse button
if (insideSelection)
return new ShapeResizeStrategy(this, m_canvas, event->point, handle);
return new ShapeResizeStrategy(this, event->point, handle);
if (handle == KoFlake::TopMiddleHandle || handle == KoFlake::RightMiddleHandle ||
handle == KoFlake::BottomMiddleHandle || handle == KoFlake::LeftMiddleHandle)
return new ShapeShearStrategy(this, m_canvas, event->point, handle);
return new ShapeShearStrategy(this, event->point, handle);
}
// rotating is allowed for rigth mouse button too
if (handle == KoFlake::TopLeftHandle || handle == KoFlake::TopRightHandle ||
handle == KoFlake::BottomLeftHandle || handle == KoFlake::BottomRightHandle)
return new ShapeRotateStrategy(this, m_canvas, event->point, event->buttons());
return new ShapeRotateStrategy(this, event->point, event->buttons());
}
if (! (selectMultiple || selectNextInStack) && event->buttons() == Qt::LeftButton) {
const QPainterPath outlinePath = select->transformation().map(select->outline());
if (outlinePath.contains(event->point) || outlinePath.intersects(handlePaintRect(event->point)))
return new ShapeMoveStrategy(this, m_canvas, event->point);
return new ShapeMoveStrategy(this, event->point);
}
}
......@@ -1182,7 +1182,7 @@ KoInteractionStrategy *DefaultTool::createStrategy(KoPointerEvent *event)
repaintDecorations();
select->deselectAll();
}
return new KoShapeRubberSelectStrategy(this, m_canvas, event->point);
return new KoShapeRubberSelectStrategy(this, event->point);
}
if (select->isSelected(shape)) {
......@@ -1197,7 +1197,7 @@ KoInteractionStrategy *DefaultTool::createStrategy(KoPointerEvent *event)
shapeManager->selection()->deselectAll();
select->select(shape, selectNextInStack ? false : true);
repaintDecorations();
return new ShapeMoveStrategy(this, m_canvas, event->point);
return new ShapeMoveStrategy(this, event->point);
}
return 0;
}
......
......@@ -33,11 +33,11 @@
#include <KoTool.h>
#include <KLocale>
ShapeMoveStrategy::ShapeMoveStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked)
: KoInteractionStrategy(tool, canvas)
, m_start(clicked)
ShapeMoveStrategy::ShapeMoveStrategy(KoTool *tool, const QPointF &clicked)
: KoInteractionStrategy(tool),
m_start(clicked)
{
QList<KoShape*> selectedShapes = canvas->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
QList<KoShape*> selectedShapes = tool->canvas()->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
QRectF boundingRect;
foreach(KoShape *shape, selectedShapes) {
if( ! shape->isEditable() )
......@@ -47,10 +47,10 @@ ShapeMoveStrategy::ShapeMoveStrategy( KoTool *tool, KoCanvasBase *canvas, const
m_newPositions << shape->position();
boundingRect = boundingRect.unite( shape->boundingRect() );
}
KoSelection * selection = m_canvas->shapeManager()->selection();
KoSelection * selection = tool->canvas()->shapeManager()->selection();
m_initialOffset = selection->absolutePosition( SelectionDecorator::hotPosition() ) - m_start;
m_initialSelectionPosition = selection->position();
m_canvas->snapGuide()->setIgnoredShapes( selection->selectedShapes( KoFlake::FullSelection ) );
tool->canvas()->snapGuide()->setIgnoredShapes( selection->selectedShapes( KoFlake::FullSelection ) );
tool->setStatusText( i18n("Press ALT to hold x- or y-position.") );
}
......@@ -71,9 +71,9 @@ void ShapeMoveStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifi
else
{
QPointF positionToSnap = point + m_initialOffset;
m_canvas->updateCanvas( m_canvas->snapGuide()->boundingRect() );
QPointF snappedPosition = m_canvas->snapGuide()->snap( positionToSnap, modifiers );
m_canvas->updateCanvas( m_canvas->snapGuide()->boundingRect() );
tool()->canvas()->updateCanvas( tool()->canvas()->snapGuide()->boundingRect() );
QPointF snappedPosition = tool()->canvas()->snapGuide()->snap( positionToSnap, modifiers );
tool()->canvas()->updateCanvas( tool()->canvas()->snapGuide()->boundingRect() );
diff = snappedPosition - m_initialOffset - m_start;
}
......@@ -84,7 +84,7 @@ void ShapeMoveStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifi
void ShapeMoveStrategy::handleCustomEvent( KoPointerEvent * event )
{
QPointF diff = m_canvas->viewConverter()->viewToDocument( event->pos() );
QPointF diff = tool()->canvas()->viewConverter()->viewToDocument( event->pos() );
if( event->modifiers() & (Qt::AltModifier | Qt::ControlModifier)) {
// keep x or y position unchanged
......@@ -109,7 +109,7 @@ void ShapeMoveStrategy::moveBy( const QPointF &diff )
QPointF delta = m_previousPositions.at(i) + m_diff - shape->position();
if(shape->parent())
shape->parent()->model()->proposeMove(shape, delta);
m_canvas->clipToDocument(shape, delta);
tool()->canvas()->clipToDocument(shape, delta);
QPointF newPos (shape->position() + delta);
m_newPositions[i] = newPos;
shape->update();
......@@ -117,12 +117,12 @@ void ShapeMoveStrategy::moveBy( const QPointF &diff )
shape->update();
i++;
}
m_canvas->shapeManager()->selection()->setPosition(m_initialSelectionPosition + m_diff);
tool()->canvas()->shapeManager()->selection()->setPosition(m_initialSelectionPosition + m_diff);
}
QUndoCommand* ShapeMoveStrategy::createCommand()
{
m_canvas->snapGuide()->reset();
tool()->canvas()->snapGuide()->reset();
if(m_diff.x() == 0 && m_diff.y() == 0)
return 0;
return new KoShapeMoveCommand(m_selectedShapes, m_previousPositions, m_newPositions);
......@@ -131,7 +131,7 @@ QUndoCommand* ShapeMoveStrategy::createCommand()
void ShapeMoveStrategy::paint( QPainter &painter, const KoViewConverter &converter)
{
SelectionDecorator decorator (KoFlake::NoHandle, false, false);
decorator.setSelection(m_canvas->shapeManager()->selection());
decorator.setHandleRadius( m_canvas->resourceProvider()->handleRadius() );
decorator.setSelection(tool()->canvas()->shapeManager()->selection());
decorator.setHandleRadius( tool()->canvas()->resourceProvider()->handleRadius() );
decorator.paint(painter, converter);
}
......@@ -25,9 +25,11 @@
#include <KoInteractionStrategy.h>
#include <QPointF>
#include <QList>
class KoCanvasBase;
class KoTool;
class KoShape;
/**
* Implements the Move action on an object or selected objects.
......@@ -41,7 +43,7 @@ public:
* @param canvas the canvas interface which will supply things like a selection object
* @param clicked the initial point that the user depressed (in pt).
*/
ShapeMoveStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked );
ShapeMoveStrategy(KoTool *tool, const QPointF &clicked);
virtual ~ShapeMoveStrategy() {}
void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers);
......@@ -54,6 +56,7 @@ private:
QList<QPointF> m_previousPositions;
QList<QPointF> m_newPositions;
QPointF m_start, m_diff, m_initialSelectionPosition, m_initialOffset;
QList<KoShape*> m_selectedShapes;
};
#endif
......@@ -33,12 +33,12 @@
#include <klocale.h>
#include <limits>
ShapeResizeStrategy::ShapeResizeStrategy( KoTool *tool, KoCanvasBase *canvas,
ShapeResizeStrategy::ShapeResizeStrategy(KoTool *tool,
const QPointF &clicked, KoFlake::SelectionHandle direction )
: KoInteractionStrategy(tool, canvas), m_lastScale(1.0,1.0)
: KoInteractionStrategy(tool), m_lastScale(1.0,1.0)
{
Q_ASSERT( canvas->shapeManager()->selection()->count() > 0);
QList<KoShape*> selectedShapes = canvas->shapeManager()->selection()->selectedShapes(KoFlake::StrippedSelection);
Q_ASSERT(tool->canvas()->shapeManager()->selection()->count() > 0);
QList<KoShape*> selectedShapes = tool->canvas()->shapeManager()->selection()->selectedShapes(KoFlake::StrippedSelection);
foreach(KoShape *shape, selectedShapes) {
if ( ! shape->isEditable() )
continue;
......@@ -51,10 +51,10 @@ ShapeResizeStrategy::ShapeResizeStrategy( KoTool *tool, KoCanvasBase *canvas,
m_start = clicked;
KoShape *shp = 0;
if (canvas->shapeManager()->selection()->count()>1)
shp = canvas->shapeManager()->selection();
if (canvas->shapeManager()->selection()->count()==1)
shp = canvas->shapeManager()->selection()->firstSelectedShape();
if (tool->canvas()->shapeManager()->selection()->count()>1)
shp = tool->canvas()->shapeManager()->selection();
if (tool->canvas()->shapeManager()->selection()->count()==1)
shp = tool->canvas()->shapeManager()->selection()->firstSelectedShape();
if ( shp )
{
......@@ -98,7 +98,7 @@ ShapeResizeStrategy::ShapeResizeStrategy( KoTool *tool, KoCanvasBase *canvas,
void ShapeResizeStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers)
{
QPointF newPos = m_canvas->snapGuide()->snap( point, modifiers );
QPointF newPos = tool()->canvas()->snapGuide()->snap( point, modifiers );
bool keepAspect = modifiers & Qt::ShiftModifier;
foreach(KoShape *shape, m_selectedShapes)
......@@ -223,7 +223,7 @@ void ShapeResizeStrategy::resizeBy( const QPointF &center, qreal zoomX, qreal zo
shape->update();
i++;
}
m_canvas->shapeManager()->selection()->applyAbsoluteTransformation( matrix * m_scaleMatrix.inverted() );
tool()->canvas()->shapeManager()->selection()->applyAbsoluteTransformation( matrix * m_scaleMatrix.inverted() );
m_scaleMatrix = matrix;
}
......@@ -246,7 +246,7 @@ QUndoCommand* ShapeResizeStrategy::createCommand()
void ShapeResizeStrategy::paint( QPainter &painter, const KoViewConverter &converter)
{
SelectionDecorator decorator (KoFlake::NoHandle, false, false);
decorator.setSelection(m_canvas->shapeManager()->selection());
decorator.setHandleRadius( m_canvas->resourceProvider()->handleRadius() );
decorator.setSelection(tool()->canvas()->shapeManager()->selection());
decorator.setHandleRadius( tool()->canvas()->resourceProvider()->handleRadius() );
decorator.paint(painter, converter);
}
......@@ -21,11 +21,14 @@
#define SHAPERESIZESTRATEGY_H
#include <KoInteractionStrategy.h>
#include <KoFlake.h>
#include <QPointF>
#include <QList>
class KoCanvasBase;
class KoTool;
class KoShape;
/**
* A strategy for the KoInteractionTool.
......@@ -38,7 +41,7 @@ public:
/**
* Constructor
*/
ShapeResizeStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked, KoFlake::SelectionHandle direction );
ShapeResizeStrategy(KoTool *tool, const QPointF &clicked, KoFlake::SelectionHandle direction);
virtual ~ShapeResizeStrategy() {}
void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers);
......@@ -60,6 +63,7 @@ private:
QList<QMatrix> m_oldTransforms;
QList<QMatrix> m_transformations;
QPointF m_lastScale;
QList<KoShape*> m_selectedShapes;
};
#endif
......
......@@ -24,6 +24,7 @@
#include <KoInteractionTool.h>
#include <KoCanvasBase.h>
#include <KoSelection.h>
#include <KoPointerEvent.h>
#include <KoShapeManager.h>
#include <KoCanvasResourceProvider.h>
......@@ -33,14 +34,14 @@
#include <math.h>
#include <klocale.h>
ShapeRotateStrategy::ShapeRotateStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked, Qt::MouseButtons buttons)
: KoInteractionStrategy(tool, canvas)
ShapeRotateStrategy::ShapeRotateStrategy(KoTool *tool, const QPointF &clicked, Qt::MouseButtons buttons)
: KoInteractionStrategy(tool)
, m_initialBoundingRect()
, m_start(clicked)
{
m_initialSelectionMatrix = canvas->shapeManager()->selection()->transformation();
m_initialSelectionMatrix = tool->canvas()->shapeManager()->selection()->transformation();
QList<KoShape*> selectedShapes = canvas->shapeManager()->selection()->selectedShapes(KoFlake::StrippedSelection);
QList<KoShape*> selectedShapes = tool->canvas()->shapeManager()->selection()->selectedShapes(KoFlake::StrippedSelection);
foreach(KoShape *shape, selectedShapes) {
if( ! shape->isEditable() )
continue;
......@@ -53,7 +54,7 @@ ShapeRotateStrategy::ShapeRotateStrategy( KoTool *tool, KoCanvasBase *canvas, co
}
if( buttons & Qt::RightButton )
m_rotationCenter = canvas->shapeManager()->selection()->absolutePosition( SelectionDecorator::hotPosition() );
m_rotationCenter = tool->canvas()->shapeManager()->selection()->absolutePosition( SelectionDecorator::hotPosition() );
else
m_rotationCenter = m_initialBoundingRect.center();
......@@ -86,7 +87,7 @@ void ShapeRotateStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModi
shape->applyAbsoluteTransformation( applyMatrix );
shape->update();
}
m_canvas->shapeManager()->selection()->applyAbsoluteTransformation( applyMatrix );
tool()->canvas()->shapeManager()->selection()->applyAbsoluteTransformation( applyMatrix );
}
void ShapeRotateStrategy::handleCustomEvent( KoPointerEvent * event )
......@@ -102,7 +103,7 @@ void ShapeRotateStrategy::handleCustomEvent( KoPointerEvent * event )
shape->applyAbsoluteTransformation( matrix );
shape->update();
}
m_canvas->shapeManager()->selection()->applyAbsoluteTransformation( matrix );
tool()->canvas()->shapeManager()->selection()->applyAbsoluteTransformation( matrix );
}
void ShapeRotateStrategy::rotateBy( qreal angle )
......@@ -119,13 +120,13 @@ void ShapeRotateStrategy::rotateBy( qreal angle )
shape->applyAbsoluteTransformation( applyMatrix );
shape->update();
}
m_canvas->shapeManager()->selection()->applyAbsoluteTransformation( applyMatrix );
tool()->canvas()->shapeManager()->selection()->applyAbsoluteTransformation( applyMatrix );
}
void ShapeRotateStrategy::paint( QPainter &painter, const KoViewConverter &converter) {
SelectionDecorator decorator(KoFlake::NoHandle, true, false);
decorator.setSelection(m_canvas->shapeManager()->selection());
decorator.setHandleRadius( m_canvas->resourceProvider()->handleRadius() );
decorator.setSelection(tool()->canvas()->shapeManager()->selection());
decorator.setHandleRadius( tool()->canvas()->resourceProvider()->handleRadius() );
decorator.paint(painter, converter);
// paint the rotation center
......@@ -144,7 +145,7 @@ QUndoCommand* ShapeRotateStrategy::createCommand() {
KoShapeTransformCommand * cmd = new KoShapeTransformCommand( m_selectedShapes, m_oldTransforms, newTransforms );
cmd->setText( i18n("Rotate") );
KoSelection * sel = m_canvas->shapeManager()->selection();
KoSelection * sel = tool()->canvas()->shapeManager()->selection();
new SelectionTransformCommand(sel, m_initialSelectionMatrix, sel->transformation(), cmd);
return cmd;
}
......@@ -23,9 +23,13 @@
#include <KoInteractionStrategy.h>
#include <QPointF>
#include <QRectF>
#include <QMatrix>
#include <QList>
class KoCanvasBase;
class KoTool;
class KoShape;
/**
* A strategy for the KoInteractionTool.
......@@ -38,10 +42,9 @@ public:
/**
* Constructor that starts to rotate the objects.
* @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).
*/
ShapeRotateStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked, Qt::MouseButtons buttons );
ShapeRotateStrategy( KoTool *tool, const QPointF &clicked, Qt::MouseButtons buttons );
virtual ~ShapeRotateStrategy() {}
void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers);
......@@ -58,6 +61,7 @@ private:
QMatrix m_initialSelectionMatrix;
QList<QMatrix> m_oldTransforms;
QPointF m_rotationCenter;
QList<KoShape*> m_selectedShapes;
};
#endif
......
......@@ -38,11 +38,11 @@
#include <kdebug.h>
#include <klocale.h>
ShapeShearStrategy::ShapeShearStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked, KoFlake::SelectionHandle direction )
: KoInteractionStrategy(tool, canvas)
ShapeShearStrategy::ShapeShearStrategy( KoTool *tool, const QPointF &clicked, KoFlake::SelectionHandle direction )
: KoInteractionStrategy(tool)
, m_start(clicked)
{
KoSelection * sel = canvas->shapeManager()->selection();
KoSelection *sel = tool->canvas()->shapeManager()->selection();
QList<KoShape*> selectedShapes = sel->selectedShapes(KoFlake::StrippedSelection);
foreach(KoShape *shape, selectedShapes) {
if( ! shape->isEditable() )
......@@ -112,7 +112,7 @@ ShapeShearStrategy::ShapeShearStrategy( KoTool *tool, KoCanvasBase *canvas, cons
m_initialSelectionAngle = currentAngle - angle;
kDebug(30006) <<" PREsol.x=" << m_solidPoint.x() <<" sol.y=" << m_solidPoint.y();
m_solidPoint = canvas->shapeManager()->selection()->absoluteTransformation(0).map( m_solidPoint );
m_solidPoint = tool->canvas()->shapeManager()->selection()->absoluteTransformation(0).map( m_solidPoint );
// use crossproduct of top edge and left edge of selection bounding rect
// to determine if the selection is mirrored
......@@ -161,14 +161,14 @@ void ShapeShearStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModif
shape->applyAbsoluteTransformation( applyMatrix );
shape->update();
}
m_canvas->shapeManager()->selection()->applyAbsoluteTransformation( applyMatrix );
tool()->canvas()->shapeManager()->selection()->applyAbsoluteTransformation( applyMatrix );
m_shearMatrix = matrix;
}
void ShapeShearStrategy::paint( QPainter &painter, const KoViewConverter &converter) {
SelectionDecorator decorator(KoFlake::NoHandle, true, false);
decorator.setSelection(m_canvas->shapeManager()->selection());
decorator.setHandleRadius( m_canvas->resourceProvider()->handleRadius() );
decorator.setSelection(tool()->canvas()->shapeManager()->selection());
decorator.setHandleRadius( tool()->canvas()->resourceProvider()->handleRadius() );
decorator.paint(painter, converter);
}
......@@ -178,7 +178,7 @@ QUndoCommand* ShapeShearStrategy::createCommand() {
newTransforms << shape->transformation();
KoShapeTransformCommand * cmd = new KoShapeTransformCommand( m_selectedShapes, m_oldTransforms, newTransforms );
cmd->setText( i18n("Shear") );
KoSelection * sel = m_canvas->shapeManager()->selection();
KoSelection * sel = tool()->canvas()->shapeManager()->selection();
new SelectionTransformCommand(sel, m_initialSelectionMatrix, sel->transformation(), cmd);
return cmd;
}
......@@ -21,11 +21,15 @@
#define SHAPESHEARSTRATEGY_H
#include <KoInteractionStrategy.h>
#include <KoFlake.h>
#include <QPointF>
#include <QSizeF>
#include <QMatrix>
class KoCanvasBase;
class KoTool;
class KoShape;
/**
* A strategy for the KoInteractionTool.
......@@ -38,11 +42,10 @@ public:
/**
* Constructor that starts to rotate the objects.
* @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).
* @param direction the handle that was grabbed
*/
ShapeShearStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked, KoFlake::SelectionHandle direction );
ShapeShearStrategy( KoTool *tool, const QPointF &clicked, KoFlake::SelectionHandle direction );
virtual ~ShapeShearStrategy() {}
void handleMouseMove(const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers);
......@@ -60,6 +63,7 @@ private:
bool m_isMirrored;
QList<QMatrix> m_oldTransforms;
QMatrix m_initialSelectionMatrix;
QList<KoShape*> m_selectedShapes;
};
#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