00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KOPATHTOOL_H
00022 #define KOPATHTOOL_H
00023
00024 #include "KoPathShape.h"
00025
00026 #include <KoTool.h>
00027 #include <QMap>
00028 #include <QSet>
00029
00030 class KoCanvasBase;
00031 class KoParameterShape;
00032 class KoInteractionStrategy;
00033 class KoPathPointMoveStrategy;
00034 class KoPathPointRubberSelectStrategy;
00035
00036 class KoPathTool : public KoTool {
00037 public:
00038 KoPathTool(KoCanvasBase *canvas);
00039 ~KoPathTool();
00040
00041 void paint( QPainter &painter, KoViewConverter &converter );
00042
00043 void mousePressEvent( KoPointerEvent *event );
00044 void mouseDoubleClickEvent( KoPointerEvent *event );
00045 void mouseMoveEvent( KoPointerEvent *event );
00046 void mouseReleaseEvent( KoPointerEvent *event );
00047 void keyPressEvent(QKeyEvent *event);
00048 void keyReleaseEvent(QKeyEvent *event);
00049
00050 void activate (bool temporary=false);
00051 void deactivate();
00052
00053 private:
00060 void selectPoints( const QRectF &rect, bool clearSelection );
00061
00063 void repaint( const QRectF &repaintRect );
00065 QRectF handleRect( const QPointF &p );
00066
00067
00068 QPointF m_lastPoint;
00070 QPointF snapToGrid( const QPointF &p, Qt::KeyboardModifiers modifiers );
00071 private:
00072
00073 class ActiveHandle
00074 {
00075 public:
00076 ActiveHandle( KoPathTool *tool )
00077 : m_tool( tool )
00078 {}
00079 virtual ~ActiveHandle() {};
00080 virtual void paint( QPainter &painter, KoViewConverter &converter ) = 0;
00081 virtual void repaint() const = 0;
00082 virtual void mousePressEvent( KoPointerEvent *event ) = 0;
00083
00084 KoPathTool *m_tool;
00085 };
00086
00087 class ActivePointHandle : public ActiveHandle
00088 {
00089 public:
00090 ActivePointHandle( KoPathTool *tool, KoPathPoint *activePoint, KoPathPoint::KoPointType activePointType )
00091 : ActiveHandle( tool )
00092 , m_activePoint( activePoint )
00093 , m_activePointType( activePointType )
00094 {}
00095 void paint( QPainter &painter, KoViewConverter &converter );
00096 void repaint() const;
00097 void mousePressEvent( KoPointerEvent *event );
00098
00099 KoPathPoint *m_activePoint;
00100 KoPathPoint::KoPointType m_activePointType;
00101 };
00102
00103 class ActiveParameterHandle : public ActiveHandle
00104 {
00105 public:
00106 ActiveParameterHandle( KoPathTool *tool, KoParameterShape *parameterShape, int handleId )
00107 : ActiveHandle( tool )
00108 , m_parameterShape( parameterShape )
00109 , m_handleId( handleId )
00110 {}
00111 void paint( QPainter &painter, KoViewConverter &converter );
00112 void repaint() const;
00113 void mousePressEvent( KoPointerEvent *event );
00114
00115 KoParameterShape *m_parameterShape;
00116 int m_handleId;
00117 };
00118
00125 class KoPathPointSelection
00126 {
00127 public:
00128 KoPathPointSelection( KoPathTool * tool )
00129 : m_tool( tool )
00130 {}
00131 ~KoPathPointSelection() {}
00132
00134 void paint( QPainter &painter, KoViewConverter &converter );
00135
00142 void add( KoPathPoint * point, bool clear );
00143
00149 void remove( KoPathPoint * point );
00150
00154 void clear();
00155
00161 int objectCount() const { return m_shapePointMap.size(); }
00162
00168 int size() const { return m_selectedPoints.size(); }
00169
00175 bool contains( KoPathPoint * point ) { return m_selectedPoints.contains( point ); }
00176
00182 const QSet<KoPathPoint *> & selectedPoints() const { return m_selectedPoints; }
00183
00190 const KoPathShapePointMap & selectedPointMap() const { return m_shapePointMap; }
00191
00195 void repaint();
00196
00197 private:
00198 QSet<KoPathPoint *> m_selectedPoints;
00199 KoPathShapePointMap m_shapePointMap;
00200 KoPathTool * m_tool;
00201 };
00202
00203
00204 ActiveHandle * m_activeHandle;
00205 int m_handleRadius;
00206
00207 KoPathPointSelection m_pointSelection;
00208
00209 friend class ActiveNoHandle;
00210 friend class ActivePointHandle;
00211 friend class KoPathPointSelection;
00212 friend class KoPathPointMoveStrategy;
00213 friend class KoPathControlPointMoveStrategy;
00214 friend class KoPathPointRubberSelectStrategy;
00215
00216 KoInteractionStrategy *m_currentStrategy;
00217 };
00218
00219 #endif