Commit d85b1ca7 authored by Thorsten Zachmann's avatar Thorsten Zachmann

o added parameter shapes base class

o added a rectangle shape
o redesigned KoPathTool to also handle parameter shapes
o splitted KoPathPointMoveStrategy in KoPathPointMoveStrategy and
  KoPathControlPointMoveStrategy
o added commands for manipulating parameter shapes


svn path=/trunk/koffice/; revision=598767
parent 84630873
......@@ -34,6 +34,11 @@ set(flake_SRCS
KoPathCommand.cpp
KoPathPointRubberSelectStrategy.cpp
KoPathPointMoveStrategy.cpp
KoPathControlPointMoveStrategy.cpp
KoParameterShape.cpp
KoParameterChangeStrategy.cpp
KoRectangleShape.cpp
KoRectangleShapeFactory.cpp
)
kde4_automoc(${flake_SRCS})
......
/* 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.
*/
#include "KoParameterChangeStrategy.h"
#include "KoParameterShape.h"
#include "KoPathCommand.h"
KoParameterChangeStrategy::KoParameterChangeStrategy( KoTool *tool, KoCanvasBase *canvas, KoParameterShape * parameterShape, int handleId )
: KoInteractionStrategy( tool, canvas )
, m_parameterShape( parameterShape )
, m_handleId( handleId )
, m_startPoint( m_parameterShape->handlePosition( handleId ) )
{
}
KoParameterChangeStrategy::~KoParameterChangeStrategy()
{
}
void KoParameterChangeStrategy::handleMouseMove( const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers )
{
m_parameterShape->moveHandle( m_handleId, m_parameterShape->documentToShape( mouseLocation ), modifiers );
}
KCommand* KoParameterChangeStrategy::createCommand()
{
KoParameterChangeCommand *cmd = 0;
// check if handle position changed
if ( m_startPoint != m_parameterShape->handlePosition( m_handleId ) )
{
cmd = new KoParameterChangeCommand( m_parameterShape, m_handleId, m_startPoint, m_parameterShape->handlePosition( m_handleId ) );
}
return cmd;
}
/* 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 KOPATHPARAMETERCHANGESTRATEGY_H
#define KOPATHPARAMETERCHANGESTRATEGY_H
#include <QPointF>
#include <KoInteractionStrategy.h>
class KoParameterShape;
class KoParameterChangeStrategy : public KoInteractionStrategy
{
public:
KoParameterChangeStrategy( KoTool *tool, KoCanvasBase *canvas, KoParameterShape * parameterShape, int handleId );
virtual ~KoParameterChangeStrategy();
virtual void handleMouseMove( const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers );
virtual void finishInteraction( Qt::KeyboardModifiers modifiers ) { Q_UNUSED( modifiers ); }
virtual KCommand* createCommand();
private:
KoParameterShape * m_parameterShape;
int m_handleId;
QPointF m_startPoint;
};
#endif /* KOPATHPARAMETERCHANGESTRATEGY_H */
/* 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.
*/
#include "KoParameterShape.h"
#include <QDebug>
#include <QPainter>
KoParameterShape::KoParameterShape()
: m_modified( false )
{
}
KoParameterShape::~KoParameterShape()
{
}
void KoParameterShape::moveHandle( int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers )
{
if ( handleId >= m_handles.size() )
{
qWarning() << "handleId out of bounds";
return;
}
// function to do special stuff
moveHandleAction( handleId, point, modifiers );
updatePath( size() );
repaint();
}
int KoParameterShape::handleIdAt( const QRectF & rect ) const
{
int handle = -1;
for ( int i = 0; i < m_handles.size(); ++i )
{
if ( rect.contains( m_handles.at( i ) ) )
{
handle = i;
break;
}
}
return handle;
}
QPointF KoParameterShape::handlePosition( int handleId )
{
return m_handles[handleId];
}
void KoParameterShape::paintHandles( QPainter & painter, const KoViewConverter & converter )
{
applyConversion( painter, converter );
QWMatrix matrix;
matrix.rotate( 45.0 );
QPolygonF poly( converter.viewToDocument( handleRect( QPointF( 0, 0 ) ) ) );
poly = matrix.map( poly );
QList<QPointF>::const_iterator it( m_handles.begin() );
for ( ; it != m_handles.end(); ++it )
{
QPolygonF p( poly );
p.translate( *it );
painter.drawPolygon( p );
}
}
void KoParameterShape::paintHandle( QPainter & painter, const KoViewConverter & converter, int handleId )
{
applyConversion( painter, converter );
QWMatrix matrix;
matrix.rotate( 45.0 );
QPolygonF poly( converter.viewToDocument( handleRect( QPointF( 0, 0 ) ) ) );
poly = matrix.map( poly );
poly.translate( m_handles[handleId] );
painter.drawPolygon( poly );
}
void KoParameterShape::resize( const QSizeF &newSize )
{
QSizeF oldSize = size();
QMatrix matrix( newSize.width() / oldSize.width(), 0, 0, newSize.height() / oldSize.height(), 0, 0 );
for( int i = 0; i < m_handles.size(); ++i )
{
m_handles[i] = matrix.map( m_handles[i] );
}
KoPathShape::resize( newSize );
}
/* 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 KOPARAMETERSHAPE_H
#define KOPARAMETERSHAPE_H
#include "KoPathShape.h"
class KoParameterShape : public KoPathShape
{
public:
KoParameterShape();
~KoParameterShape();
/**
* @brief Move handle to point
*
* This method calls moveHandleAction. Overload moveHandleAction to get the behaviour you want.
* After that updatePath and a repaint is called.
*
* @param handleId of the handle
* @param point to move the handle to
* @param modifiers used during move to point
*/
virtual void moveHandle( int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers = Qt::NoModifier );
/**
* @brief Get the handleId in the rect
*
* @param rect in shape coordinates
* @return id of the found handle or -1 if one was found
*/
virtual int handleIdAt( const QRectF & rect ) const;
/**
* @brief Get the handle position
*
* @param handleId for which ti get the position in shape coordinates
*/
virtual QPointF handlePosition( int handleId );
/**
* @brief Paint the handles
*
* @param painter
* @param converter
*/
virtual void paintHandles( QPainter & painter, const KoViewConverter & converter );
/**
* @brief Paint the given handles
*
* @param painter
* @param converter
* @param handleId of the handle which should be repainted
*/
virtual void paintHandle( QPainter & painter, const KoViewConverter & converter, int handleId );
virtual void resize( const QSizeF &newSize );
/**
* @brief Check if object is a parametric shape
*
* It is no longer a parametric shape when the path was manipulated
*
* @return true if it is a parametic shape, false otherwise
*/
bool isParametricShape() const { return !m_modified; }
/**
* @brief Set the modified status.
*
* After the state is set to modified it is no longer possible to work
* with parameters on this shape.
*
* @param modified the modification state
*/
void setModified( bool modified ) { m_modified = modified; }
protected:
/**
* @brief Updates the internal state of a KoParameterShape.
*
* This method is called from moveHandle.
*
* @param handleId of the handle
* @param point to move the handle to
* @param modifiers used during move to point
*/
virtual void moveHandleAction( int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers = Qt::NoModifier ) = 0;
/**
* @brief Update the path of the parameter shape
*
* @param size of the shape
*/
virtual void updatePath( const QSizeF &size ) = 0;
QList<QPointF> m_handles;
bool m_modified;
};
#endif /* KOPARAMETERSHAPE_H */
......@@ -19,6 +19,7 @@
*/
#include "KoPathCommand.h"
#include "KoParameterShape.h"
#include "KoShapeControllerBase.h"
#include <klocale.h>
#include <kdebug.h>
......@@ -646,6 +647,62 @@ QString KoPathCombineCommand::name() const
return i18n( "Combine paths" );
}
KoParameterChangeCommand::KoParameterChangeCommand( KoParameterShape *shape, int handleId, const QPointF &startPoint, const QPointF &endPoint )
: m_shape( shape )
, m_handleId( handleId )
, m_startPoint( startPoint )
, m_endPoint( endPoint )
{
}
KoParameterChangeCommand::~KoParameterChangeCommand()
{
}
/// execute the command
void KoParameterChangeCommand::execute()
{
m_shape->moveHandle( m_handleId, m_endPoint );
m_shape->repaint();
}
/// revert the actions done in execute
void KoParameterChangeCommand::unexecute()
{
m_shape->moveHandle( m_handleId, m_startPoint );
m_shape->repaint();
}
/// return the name of this command
QString KoParameterChangeCommand::name() const
{
return i18n( "Change parameter" );
}
KoParameterToPathCommand::KoParameterToPathCommand( KoParameterShape *shape )
: m_shape( shape )
{
}
KoParameterToPathCommand::~KoParameterToPathCommand()
{
}
void KoParameterToPathCommand::execute()
{
m_shape->setModified( true );
}
void KoParameterToPathCommand::unexecute()
{
m_shape->setModified( false );
}
QString KoParameterToPathCommand::name() const
{
return i18n( "Modify path" );
}
KoPathSeparateCommand::KoPathSeparateCommand( KoShapeControllerBase *controller, const QList<KoPathShape*> &paths )
: m_controller( controller )
, m_paths( paths )
......
/* This file is part of the KDE project
* Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net>
* 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
......@@ -26,6 +27,8 @@
#include <QPointF>
#include "KoPathShape.h"
class KoParameterShape;
/// the base command for commands altering a path shape
class KoPathBaseCommand : public KCommand {
public:
......@@ -301,6 +304,43 @@ private:
bool m_isCombined;
};
/// The undo / redo command for changing a parameter
class KoParameterChangeCommand : public KCommand
{
public:
KoParameterChangeCommand( KoParameterShape *shape, int handleId, const QPointF &startPoint, const QPointF &endPoint );
virtual ~KoParameterChangeCommand();
/// execute the command
void execute();
/// revert the actions done in execute
void unexecute();
/// return the name of this command
QString name() const;
private:
KoParameterShape *m_shape;
int m_handleId;
QPointF m_startPoint;
QPointF m_endPoint;
};
/// The undo / redo command for changing a KoParameterShape into a KoPathShape
class KoParameterToPathCommand : public KCommand
{
public:
KoParameterToPathCommand( KoParameterShape *shape );
virtual ~KoParameterToPathCommand();
/// execute the command
void execute();
/// revert the actions done in execute
void unexecute();
/// return the name of this command
QString name() const;
private:
KoParameterShape *m_shape;
};
/// The undo / redo command for separating subpaths into different paths
class KoPathSeparateCommand : public KCommand
{
......
/* This file is part of the KDE project
* Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net>
* 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.
*/
#include "KoPathControlPointMoveStrategy.h"
#include "KoPathTool.h"
#include "KoPathCommand.h"
KoPathControlPointMoveStrategy::KoPathControlPointMoveStrategy( KoPathTool *tool, KoCanvasBase *canvas, KoPathPoint *point, KoPathPoint::KoPointType type, const QPointF &pos )
: KoInteractionStrategy( tool, canvas )
, m_lastPosition( pos )
, m_move( 0, 0 )
, m_tool( tool )
, m_point( point )
, m_pointType( type )
{
}
KoPathControlPointMoveStrategy::~KoPathControlPointMoveStrategy()
{
}
void KoPathControlPointMoveStrategy::handleMouseMove( const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers )
{
QPointF docPoint = m_tool->snapToGrid( mouseLocation, modifiers );
QPointF move = docPoint - m_lastPosition;
// as the last position can change when the top left is changed we have
// to save it in document pos and not in shape pos
m_lastPosition = docPoint;
m_move += move;
KoControlPointMoveCommand cmd( m_point, move, m_pointType );
cmd.execute();
}
void KoPathControlPointMoveStrategy::finishInteraction( Qt::KeyboardModifiers modifiers )
{
Q_UNUSED( modifiers );
}
KCommand* KoPathControlPointMoveStrategy::createCommand()
{
KCommand *cmd = 0;
if( !m_move.isNull() )
{
cmd = new KoControlPointMoveCommand( m_point, m_move, m_pointType );
}
return cmd;
}
/* This file is part of the KDE project
* Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net>
* 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 KOPATHCONTROLPOINTMOVESTRATEGY_H
#define KOPATHCONTROLPOINTMOVESTRATEGY_H
#include <QPointF>
#include "KoInteractionStrategy.h"
#include "KoPathShape.h"
class KoCanvasBase;
class KoPathTool;
/**
* @brief Strategy for moving points of a path shape.
*/
class KoPathControlPointMoveStrategy : public KoInteractionStrategy
{
public:
KoPathControlPointMoveStrategy( KoPathTool *tool, KoCanvasBase *canvas, KoPathPoint *point, KoPathPoint::KoPointType type, const QPointF &pos );
virtual ~KoPathControlPointMoveStrategy();
virtual void handleMouseMove( const QPointF &mouseLocation, Qt::KeyboardModifiers modifiers );
virtual void finishInteraction( Qt::KeyboardModifiers modifiers );
virtual KCommand* createCommand();
private:
/// the last mouse position
QPointF m_lastPosition;
/// the accumulated point move amount
QPointF m_move;
KoPathTool *m_tool;
KoPathPoint *m_point;
KoPathPoint::KoPointType m_pointType;
};
#endif /* KOPATHCONTROLPOINTMOVESTRATEGY_H */
......@@ -45,17 +45,8 @@ void KoPathPointMoveStrategy::handleMouseMove( const QPointF &mouseLocation, Qt:
m_move += move;
// only multiple nodes can be moved at once
if( m_tool->m_activeHandle.m_activePointType == KoPathPoint::Node )
{
KoPointMoveCommand cmd( m_tool->m_pointSelection.selectedPointMap(), move );
cmd.execute();
}
else
{
KoControlPointMoveCommand cmd( m_tool->m_activeHandle.m_activePoint, move, m_tool->m_activeHandle.m_activePointType );
cmd.execute();
}
KoPointMoveCommand cmd( m_tool->m_pointSelection.selectedPointMap(), move );
cmd.execute();
}
void KoPathPointMoveStrategy::finishInteraction( Qt::KeyboardModifiers modifiers )
......@@ -65,17 +56,10 @@ void KoPathPointMoveStrategy::finishInteraction( Qt::KeyboardModifiers modifiers
KCommand* KoPathPointMoveStrategy::createCommand()
{
QList<KoPathPoint*> selectedPoints = m_tool->m_pointSelection.selectedPoints().toList();
KoPathShape * pathShape = selectedPoints[0]->parent();
KCommand *cmd = 0;
if( !m_move.isNull() )
{
// only multiple nodes can be moved at once
if( m_tool->m_activeHandle.m_activePointType == KoPathPoint::Node )
cmd = new KoPointMoveCommand( m_tool->m_pointSelection.selectedPointMap(), m_move );
else
cmd = new KoControlPointMoveCommand( m_tool->m_activeHandle.m_activePoint, m_move, m_tool->m_activeHandle.m_activePointType );
cmd = new KoPointMoveCommand( m_tool->m_pointSelection.selectedPointMap(), m_move );
}
return cmd;
}
This diff is collapsed.
/* This file is part of the KDE project
* Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net>
* 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
......@@ -27,6 +28,7 @@
#include <QSet>
class KoCanvasBase;
class KoParameterShape;