Warning, file /office/calligra/libs/flake/KoSnapStrategy.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 KOSNAPSTRATEGY_H 0021 #define KOSNAPSTRATEGY_H 0022 0023 #include "KoSnapGuide.h" 0024 0025 #include <QLineF> 0026 #include <QVector> 0027 0028 class TestSnapStrategy; 0029 class KoPathPoint; 0030 class KoSnapProxy; 0031 class KoViewConverter; 0032 0033 class QTransform; 0034 class QPainterPath; 0035 0036 class FLAKE_EXPORT KoSnapStrategy 0037 { 0038 public: 0039 explicit KoSnapStrategy(KoSnapGuide::Strategy type); 0040 virtual ~KoSnapStrategy() {}; 0041 0042 virtual bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) = 0; 0043 0044 /// returns the strategies type 0045 KoSnapGuide::Strategy type() const; 0046 0047 static qreal squareDistance(const QPointF &p1, const QPointF &p2); 0048 static qreal scalarProduct(const QPointF &p1, const QPointF &p2); 0049 0050 /// returns the snapped position form the last call to snapToPoints 0051 QPointF snappedPosition() const; 0052 0053 /// returns the current snap strategy decoration 0054 virtual QPainterPath decoration(const KoViewConverter &converter) const = 0; 0055 0056 protected: 0057 /// sets the current snapped position 0058 void setSnappedPosition(const QPointF &position); 0059 0060 private: 0061 KoSnapGuide::Strategy m_snapType; 0062 QPointF m_snappedPosition; 0063 }; 0064 0065 /// snaps to x- or y-coordinates of path points 0066 class FLAKE_EXPORT OrthogonalSnapStrategy : public KoSnapStrategy 0067 { 0068 public: 0069 OrthogonalSnapStrategy(); 0070 bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) override; 0071 QPainterPath decoration(const KoViewConverter &converter) const override; 0072 private: 0073 QLineF m_hLine; 0074 QLineF m_vLine; 0075 }; 0076 0077 /// snaps to path points 0078 class FLAKE_EXPORT NodeSnapStrategy : public KoSnapStrategy 0079 { 0080 public: 0081 NodeSnapStrategy(); 0082 bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) override; 0083 QPainterPath decoration(const KoViewConverter &converter) const override; 0084 }; 0085 0086 /// snaps extension lines of path shapes 0087 class FLAKE_EXPORT ExtensionSnapStrategy : public KoSnapStrategy 0088 { 0089 friend class TestSnapStrategy; 0090 public: 0091 ExtensionSnapStrategy(); 0092 bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) override; 0093 QPainterPath decoration(const KoViewConverter &converter) const override; 0094 private: 0095 qreal project(const QPointF &lineStart , const QPointF &lineEnd, const QPointF &point); 0096 QPointF extensionDirection(KoPathPoint * point, const QTransform &matrix); 0097 bool snapToExtension(QPointF &position, KoPathPoint * point, const QTransform &matrix); 0098 QVector<QLineF> m_lines; 0099 }; 0100 0101 /// snaps to intersections of shapes 0102 class FLAKE_EXPORT IntersectionSnapStrategy : public KoSnapStrategy 0103 { 0104 public: 0105 IntersectionSnapStrategy(); 0106 bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) override; 0107 QPainterPath decoration(const KoViewConverter &converter) const override; 0108 }; 0109 0110 /// snaps to the canvas grid 0111 class FLAKE_EXPORT GridSnapStrategy : public KoSnapStrategy 0112 { 0113 public: 0114 GridSnapStrategy(); 0115 bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) override; 0116 QPainterPath decoration(const KoViewConverter &converter) const override; 0117 }; 0118 0119 /// snaps to shape bounding boxes 0120 class FLAKE_EXPORT BoundingBoxSnapStrategy : public KoSnapStrategy 0121 { 0122 friend class TestSnapStrategy; 0123 public: 0124 BoundingBoxSnapStrategy(); 0125 bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) override; 0126 QPainterPath decoration(const KoViewConverter &converter) const override; 0127 private: 0128 qreal squareDistanceToLine(const QPointF &lineA, const QPointF &lineB, const QPointF &point, QPointF &pointOnLine); 0129 QPointF m_boxPoints[5]; 0130 }; 0131 0132 /// snaps to line guides 0133 class FLAKE_EXPORT LineGuideSnapStrategy : public KoSnapStrategy 0134 { 0135 public: 0136 LineGuideSnapStrategy(); 0137 bool snap(const QPointF &mousePosition, KoSnapProxy * proxy, qreal maxSnapDistance) override; 0138 QPainterPath decoration(const KoViewConverter &converter) const override; 0139 private: 0140 int m_orientation; 0141 }; 0142 0143 #endif // KOSNAPSTRATEGY_H