00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef QSCTOOL_H
00019 #define QSCTOOL_H
00020
00021 #include<qobject.h>
00022 #include<qevent.h>
00023 #include"qscoord.h"
00024
00025 class QSPlotView;
00026 class QSDrvQt;
00027
00036 class QSTool : public QObject
00037 {
00038 Q_OBJECT
00039 public:
00043 QSTool( QObject *parent = NULL );
00047 virtual ~QSTool();
00054 virtual void activate( QSPlotView *parentView );
00058 virtual void deactivate();
00065 virtual bool canvasEvent( QEvent *e );
00071 virtual void draw() {}
00072
00073 protected:
00077 virtual void canvasClicked( const QPoint& pos, int keyState );
00081 virtual void canvasMiddleButtonClicked( const QPoint& pos, int keyState );
00085 virtual void canvasRightButtonClicked( const QPoint& pos, int keyState );
00089 virtual void canvasDoubleClicked( const QPoint& pos, int keyState );
00094 virtual bool canvasDragStart( const QPoint& pos, int keyState );
00098 virtual void canvasDragMove( const QPoint& pos, const QPoint& prevPos, const QPoint& startPos, int keyState, int prevKeyState, int startKeyState );
00103 virtual void canvasDragEnd( const QPoint& pos, const QPoint& startPos, int keyState, int startKeyState );
00107 virtual void canvasMove( const QPoint& pos );
00111 QSPt2f snapToGrid( const QPoint& pos, int keyState=0 );
00115 QSPt2f snapToGrid( const QSPt2f& pos, int keyState=0 );
00120 double snapToGridX( double canvas_x, int keyState=0 );
00124 double snapToGridY( double canvas_y, int keyState=0 );
00128 int snapAngle( int angle, int keyState=0 );
00132 virtual bool eventMouseDblClick( QMouseEvent * );
00136 virtual bool eventMousePress( QMouseEvent* );
00140 virtual bool eventMouseRelease( QMouseEvent* );
00144 virtual bool eventMouseMove( QMouseEvent* );
00148 virtual bool eventKeyPress( QKeyEvent* );
00152 virtual bool eventKeyRelease( QKeyEvent* );
00157 QSDrvQt *driver();
00158
00159 QSDrvQt *m_drv;
00160 QSPlotView *m_view;
00161 private:
00162 enum State { StateReady = 0,
00163 StateLeftButtonPressed,
00164 StateMiddleButtonPressed,
00165 StateRightButtonPressed,
00166 StateDragging };
00167 State m_state;
00168 bool m_snap_to_grid;
00169 QPoint m_drag_start_pos;
00170 QPoint m_drag_prev_pos;
00171 int m_drag_start_key;
00172 int m_drag_prev_key;
00173 void release_driver();
00174 };
00175
00176 #endif