00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KOGUIDES_H
00023 #define KOGUIDES_H
00024
00025 #include <QEvent>
00026 #include <QObject>
00027
00028 #include <QMouseEvent>
00029 #include <QList>
00030 #include <QKeyEvent>
00031
00032 #include <koffice_export.h>
00033
00034 class QPaintDevice;
00035 class KoPoint;
00036 class KoRect;
00037 class KoView;
00038 class KoZoomHandler;
00039
00040 class KOFFICEUI_EXPORT KoGuides : public QObject
00041 {
00042 Q_OBJECT
00043 public:
00050 KoGuides( KoView *view, KoZoomHandler *zoomHandler );
00051
00055 ~KoGuides();
00056
00062 void paintGuides( QPainter &painter );
00063
00064 typedef int SnapStatus;
00065 static const SnapStatus SNAP_NONE, SNAP_HORIZ, SNAP_VERT, SNAP_BOTH;
00066
00084 bool mousePressEvent( QMouseEvent *e );
00085
00099 bool mouseMoveEvent( QMouseEvent *e );
00100
00108 bool mouseReleaseEvent( QMouseEvent *e );
00109
00117 bool keyPressEvent( QKeyEvent *e );
00118
00127 void setGuideLines( const QList<double> &horizontalPos, const QList<double> &verticalPos );
00128
00137 void setAutoGuideLines( const QList<double> &horizontalPos, const QList<double> &verticalPos );
00138
00148 void getGuideLines( QList<double> &horizontalPos, QList<double> &verticalPos ) const;
00149
00164 void snapToGuideLines( KoRect &rect, int snap, SnapStatus &snapStatus, KoPoint &diff );
00165
00176 void snapToGuideLines( KoPoint &pos, int snap, SnapStatus &snapStatus, KoPoint &diff );
00177
00185 void repaintSnapping( const KoRect &snappedRect );
00186
00194 void repaintSnapping( const KoPoint &snappedPoint, SnapStatus snapStatus );
00195
00202 void repaintAfterSnapping( );
00203
00211 void diffNextGuide( KoRect &rect, KoPoint &diff );
00212
00213 public slots:
00225 void moveGuide( const QPoint &pos, bool horizontal, int rulerWidth );
00226
00237 void addGuide( const QPoint &pos, bool horizontal, int rulerWidth );
00238
00239 signals:
00247 void guideLinesChanged( KoView * view );
00248
00254 void moveGuides( bool state );
00255
00265 void paintGuides( bool state );
00266
00267 private slots:
00271 void slotChangePosition();
00272
00276 void slotRemove();
00277
00278 private:
00280 struct KoGuideLine
00281 {
00282 KoGuideLine( Qt::Orientation o, double pos, bool a = false )
00283 : orientation( o )
00284 , position( pos )
00285 , selected( false )
00286 , snapping( false )
00287 , automatic( a )
00288 {}
00289 Qt::Orientation orientation;
00290 double position;
00291 bool selected;
00292 bool snapping;
00293 bool automatic;
00294 };
00295
00299 void paint();
00300
00307 void add( Qt::Orientation o, QPoint &pos );
00308
00314 void select( KoGuideLine *guideLine );
00315
00321 void unselect( KoGuideLine *guideLine );
00322
00329 bool unselectAll();
00330
00334 void removeSelected();
00335
00342 bool hasSelected();
00343
00357 KoGuideLine * find( KoPoint &p, double diff );
00358
00367 void moveSelectedBy( QPoint &p );
00368
00376 KoPoint mapFromScreen( const QPoint & pos );
00377
00385 QPoint mapToScreen( const KoPoint & pos );
00386
00396 bool virtuallyEqual( double a, double b ) { return QABS( a - b ) < 1E-4; }
00397
00399 KoView * m_view;
00401 KoZoomHandler * m_zoomHandler;
00402
00403 enum GuideLineType
00404 {
00405 GL,
00406 GL_SELECTED,
00407 GL_AUTOMATIC,
00408 GL_END
00409 };
00410
00412 QList<KoGuideLine *> m_guideLines[GL_END];
00413
00415 QPoint m_lastPoint;
00417 bool m_mouseSelected;
00419 bool m_insertGuide;
00421 class Popup;
00422 Popup * m_popup;
00423 };
00424
00425 #endif