Warning, file /office/calligra/libs/flake/KoSnapGuide.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2008-2009 Jan Hambrecht <jaham@gmx.net>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #ifndef KOSNAPGUIDE_H
0021 #define KOSNAPGUIDE_H
0022 
0023 #include "flake_export.h"
0024 
0025 #include <QList>
0026 #include <Qt>
0027 
0028 class KoSnapStrategy;
0029 class KoShape;
0030 class KoPathPoint;
0031 class KoViewConverter;
0032 class KoCanvasBase;
0033 class QPainter;
0034 class QPointF;
0035 class QRectF;
0036 
0037 /**
0038  * This class is the place where all the snapping (i.e. snap to grid) is handled.
0039  *
0040  * What this class does is snapping a given position (i.e. mouse position) to various
0041  * snapping targets like grid, boundbox etc.
0042  * The snap guide does not know anything about the specific snapping target. This
0043  * is handled by the different snapping strategies which are derived from KoSnapStrategy.
0044  * Snapping strategies can be enabled/disabled by passing a mask of corresponding
0045  * snapping ids to KoSnapGuide::enableSnapStrategies. There can be one or more snapping
0046  * strategies enabled at the same time. The best result (with the nearest distance to the
0047  * original position) is then returned to the caller of KoSnapGuide::snap.
0048  *
0049  * The snap guide is part of the KoCanvasBase class and thus can be accessed by any tool
0050  * or application via the canvas pointer.
0051  * For letting the user manage which snap strategies to enable, there is a snap guide config
0052  * widget in guiutils.
0053  *
0054  */
0055 class FLAKE_EXPORT KoSnapGuide
0056 {
0057 public:
0058     /// the different possible snap Strategies
0059     enum Strategy
0060     {
0061         OrthogonalSnapping = 1,
0062         NodeSnapping = 2,
0063         ExtensionSnapping = 4,
0064         IntersectionSnapping = 8,
0065         GridSnapping = 0x10,
0066         BoundingBoxSnapping = 0x20,
0067         GuideLineSnapping = 0x40,
0068         CustomSnapping = 0x80
0069     };
0070     Q_DECLARE_FLAGS(Strategies, Strategy)
0071 
0072     /// Creates the snap guide to work on the given canvas
0073     explicit KoSnapGuide(KoCanvasBase *canvas);
0074 
0075     virtual ~KoSnapGuide();
0076 
0077     /// snaps the mouse position, returns if mouse was snapped
0078     QPointF snap(const QPointF &mousePosition, Qt::KeyboardModifiers modifiers);
0079 
0080     /// paints the guide
0081     void paint(QPainter &painter, const KoViewConverter &converter);
0082 
0083     /// returns the bounding rect of the guide
0084     QRectF boundingRect() const;
0085 
0086     /// Adds an additional shape to snap to (useful when creating a path)
0087     void setEditedShape(KoShape *shape);
0088 
0089     /// returns the extra shapes to use
0090     KoShape *editedShape() const;
0091 
0092     /// enables the strategies used for snapping
0093     void enableSnapStrategies(Strategies strategies);
0094 
0095     /// returns the enabled snap strategies
0096     KoSnapGuide::Strategies enabledSnapStrategies() const;
0097 
0098     /**
0099      * Adds a custom snap strategy
0100      *
0101      * The snap guide take ownership of the strategy. All custom strategies
0102      * are destroyed when calling reset().
0103      */
0104     bool addCustomSnapStrategy(KoSnapStrategy *customStrategy);
0105 
0106     /// enables the snapping guides
0107     void enableSnapping(bool on);
0108 
0109     /// returns if snapping is enabled
0110     bool isSnapping() const;
0111 
0112     /// sets the snap distances in pixels
0113     void setSnapDistance(int distance);
0114 
0115     /// returns the snap distance in pixels
0116     int snapDistance() const;
0117 
0118     /// returns the canvas the snap guide is working on
0119     KoCanvasBase *canvas() const;
0120 
0121     /// Sets a list of path points to ignore
0122     void setIgnoredPathPoints(const QList<KoPathPoint*> &ignoredPoints);
0123 
0124     /// Returns list of ignored points
0125     QList<KoPathPoint*> ignoredPathPoints() const;
0126 
0127     /// Sets list of ignored shapes
0128     void setIgnoredShapes(const QList<KoShape*> &ignoredShapes);
0129 
0130     /// Returns list of ignored shapes
0131     QList<KoShape*> ignoredShapes() const;
0132 
0133     /// Resets the snap guide
0134     void reset();
0135 
0136 private:
0137     class Private;
0138     Private * const d;
0139 };
0140 
0141 Q_DECLARE_OPERATORS_FOR_FLAGS(KoSnapGuide::Strategies)
0142 
0143 #endif // KOSNAPGUIDE_H