F:/KPlato/koffice/libs/flake/KoPathTool.h

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002  * Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net>
00003  * Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
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     // needed for interaction strategy
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

Généré le Wed Nov 22 23:40:59 2006 pour KPlato par  doxygen 1.5.1-p1