1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/* This file is part of the KDE project
* Copyright (C) 2008-2009 Jan Hambrecht <jaham@gmx.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KOSNAPSTRATEGY_H
#define KOSNAPSTRATEGY_H
#include "KoSnapGuide.h"
#include <QPointF>
#include <QPainterPath>
class TestSnapStrategy;
class KoPathPoint;
class KoSnapProxy;
class KoViewConverter;
class FLAKE_TEST_EXPORT KoSnapStrategy
{
public:
KoSnapStrategy(KoSnapGuide::Strategy type);
virtual ~KoSnapStrategy() {};
virtual bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) = 0;
/// returns the strategies type
KoSnapGuide::Strategy type() const;
static qreal squareDistance(const QPointF &p1, const QPointF &p2);
static qreal scalarProduct(const QPointF &p1, const QPointF &p2);
/// returns the snapped position form the last call to snapToPoints
QPointF snappedPosition() const;
/// returns the current snap strategy decoration
virtual QPainterPath decoration(const KoViewConverter &converter) const = 0;
protected:
/// sets the current snapped position
void setSnappedPosition(const QPointF &position);
private:
KoSnapGuide::Strategy m_snapType;
QPointF m_snappedPosition;
};
/// snaps to x- or y-coordinates of path points
class FLAKE_TEST_EXPORT OrthogonalSnapStrategy : public KoSnapStrategy
{
public:
OrthogonalSnapStrategy();
virtual bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance);
virtual QPainterPath decoration(const KoViewConverter &converter) const;
private:
QLineF m_hLine;
QLineF m_vLine;
};
/// snaps to path points
class FLAKE_TEST_EXPORT NodeSnapStrategy : public KoSnapStrategy
{
public:
NodeSnapStrategy();
virtual bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance);
virtual QPainterPath decoration(const KoViewConverter &converter) const;
};
/// snaps extension lines of path shapes
class FLAKE_TEST_EXPORT ExtensionSnapStrategy : public KoSnapStrategy
{
friend class TestSnapStrategy;
public:
ExtensionSnapStrategy();
virtual bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance);
virtual QPainterPath decoration(const KoViewConverter &converter) const;
private:
qreal project(const QPointF &lineStart , const QPointF &lineEnd, const QPointF &point);
QPointF extensionDirection(KoPathPoint * point, const QTransform &matrix);
bool snapToExtension(QPointF &position, KoPathPoint * point, const QTransform &matrix);
QList<QLineF> m_lines;
};
/// snaps to intersections of shapes
class FLAKE_TEST_EXPORT IntersectionSnapStrategy : public KoSnapStrategy
{
public:
IntersectionSnapStrategy();
virtual bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance);
virtual QPainterPath decoration(const KoViewConverter &converter) const;
};
/// snaps to the canvas grid
class FLAKE_TEST_EXPORT GridSnapStrategy : public KoSnapStrategy
{
public:
GridSnapStrategy();
virtual bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance);
virtual QPainterPath decoration(const KoViewConverter &converter) const;
};
/// snaps to shape bounding boxes
class FLAKE_TEST_EXPORT BoundingBoxSnapStrategy : public KoSnapStrategy
{
friend class TestSnapStrategy;
public:
BoundingBoxSnapStrategy();
virtual bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance);
virtual QPainterPath decoration(const KoViewConverter &converter) const;
private:
qreal squareDistanceToLine(const QPointF &lineA, const QPointF &lineB, const QPointF &point, QPointF &pointOnLine);
QPointF m_boxPoints[5];
};
/// snaps to line guides
class FLAKE_TEST_EXPORT LineGuideSnapStrategy : public KoSnapStrategy
{
public:
LineGuideSnapStrategy();
virtual bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance);
virtual QPainterPath decoration(const KoViewConverter &converter) const;
private:
int m_orientation;
};
#endif // KOSNAPSTRATEGY_H
|