lib

KoGuides.h

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
00004    Copyright (C) 2005 Casper Boemann Rasmussen <cbr@boemann.dk>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef KOGUIDES_H
00023 #define KOGUIDES_H
00024 
00025 #include <qevent.h>
00026 #include <qobject.h>
00027 
00028 #include <koffice_export.h>
00029 
00030 class QPaintDevice;
00031 class KoPoint;
00032 class KoRect;
00033 class KoView;
00034 class KoZoomHandler;
00035 
00036 class KOFFICEUI_EXPORT KoGuides : public QObject
00037 {
00038     Q_OBJECT
00039 public:        
00046     KoGuides( KoView *view, KoZoomHandler *zoomHandler );
00047 
00051     ~KoGuides();
00052         
00058     void paintGuides( QPainter &painter );
00059 
00060     typedef int SnapStatus;
00061     static const SnapStatus SNAP_NONE, SNAP_HORIZ, SNAP_VERT, SNAP_BOTH;
00062 
00080     bool mousePressEvent( QMouseEvent *e );
00081 
00095     bool mouseMoveEvent( QMouseEvent *e );
00096     
00104     bool mouseReleaseEvent( QMouseEvent *e );
00105     
00113     bool keyPressEvent( QKeyEvent *e );
00114 
00123     void setGuideLines( const QValueList<double> &horizontalPos, const QValueList<double> &verticalPos );
00124 
00133     void setAutoGuideLines( const QValueList<double> &horizontalPos, const QValueList<double> &verticalPos );
00134 
00144     void getGuideLines( QValueList<double> &horizontalPos, QValueList<double> &verticalPos ) const;
00145 
00160     void snapToGuideLines( KoRect &rect, int snap, SnapStatus &snapStatus, KoPoint &diff );
00161 
00172     void snapToGuideLines( KoPoint &pos, int snap, SnapStatus &snapStatus, KoPoint &diff );
00173 
00181     void repaintSnapping( const KoRect &snappedRect );
00182 
00190     void repaintSnapping( const KoPoint &snappedPoint, SnapStatus snapStatus );
00191 
00198     void repaintAfterSnapping( );
00199 
00207     void diffNextGuide( KoRect &rect, KoPoint &diff );
00208 
00209 public slots:
00221     void moveGuide( const QPoint &pos, bool horizontal, int rulerWidth );
00222 
00233     void addGuide( const QPoint &pos, bool horizontal, int rulerWidth );
00234 
00235 signals:
00243     void guideLinesChanged( KoView * view );
00244 
00250     void moveGuides( bool state );
00251 
00261     void paintGuides( bool state );
00262 
00263 private slots:
00267     void slotChangePosition();
00268 
00272     void slotRemove();
00273 
00274 private:
00276     struct KoGuideLine 
00277     {
00278         KoGuideLine( Qt::Orientation o, double pos, bool a = false )
00279         : orientation( o )
00280         , position( pos )
00281         , selected( false )
00282         , snapping( false )
00283         , automatic( a )
00284         {}
00285         Qt::Orientation orientation;
00286         double position;
00287         bool selected; // if this guide is selected
00288         bool snapping; // if this guide is being snapped to
00289         bool automatic; // if this is a atomatic guide line
00290     };
00291 
00295     void paint();
00296 
00303     void add( Qt::Orientation o, QPoint &pos );
00304     
00310     void select( KoGuideLine *guideLine );
00311 
00317     void unselect( KoGuideLine *guideLine );
00318         
00325     bool unselectAll();
00326 
00330     void removeSelected();
00331 
00338     bool hasSelected();
00339 
00353     KoGuideLine * find( KoPoint &p, double diff );
00354 
00363     void moveSelectedBy( QPoint &p );
00364 
00372     KoPoint mapFromScreen( const QPoint & pos );
00373 
00381     QPoint mapToScreen( const KoPoint & pos );
00382 
00392     bool virtuallyEqual( double a, double b ) { return QABS( a - b ) < 1E-4; }
00393 
00395     KoView * m_view;
00397     KoZoomHandler * m_zoomHandler;
00398 
00399     enum GuideLineType
00400     {
00401         GL,
00402         GL_SELECTED, 
00403         GL_AUTOMATIC,
00404         GL_END
00405     };
00406 
00408     QValueList<KoGuideLine *> m_guideLines[GL_END];
00409     
00411     QPoint m_lastPoint;
00413     bool m_mouseSelected;
00415     bool m_insertGuide;
00417     class Popup;
00418     Popup * m_popup;
00419 };
00420 
00421 #endif /* KOGUIDES_H */
KDE Home | KDE Accessibility Home | Description of Access Keys