Krita Source Code Documentation
Loading...
Searching...
No Matches
KoSnapProxy Class Reference

#include <KoSnapProxy.h>

Public Member Functions

KoCanvasBasecanvas ()
 returns canvas we are working on
 
 KoSnapProxy (KoSnapGuide *snapGuide)
 
QList< QPointF > pointsFromShape (KoShape *shape)
 returns list of points from given shape
 
QList< QPointF > pointsInRect (const QRectF &rect, bool omitEditedShape)
 returns list of points in given rectangle in document coordinates
 
QList< KoPathSegmentsegmentsInRect (const QRectF &rect, bool omitEditedShape)
 returns list of points in given rectangle in document coordinates
 
QList< KoShape * > shapes (bool omitEditedShape=false)
 returns list of all shapes
 
QList< KoShape * > shapesInRect (const QRectF &rect, bool omitEditedShape=false)
 returns list of shape in given rectangle in document coordinates
 

Private Attributes

KoSnapGuidem_snapGuide
 

Detailed Description

This class provides access to different shape related snap targets to snap strategies.

Definition at line 22 of file KoSnapProxy.h.

Constructor & Destructor Documentation

◆ KoSnapProxy()

KoSnapProxy::KoSnapProxy ( KoSnapGuide * snapGuide)

Definition at line 16 of file KoSnapProxy.cpp.

17 : m_snapGuide(snapGuide)
18{
19}
KoSnapGuide * m_snapGuide
Definition KoSnapProxy.h:46

Member Function Documentation

◆ canvas()

KoCanvasBase * KoSnapProxy::canvas ( )

returns canvas we are working on

Definition at line 172 of file KoSnapProxy.cpp.

173{
174 return m_snapGuide->canvas();
175}
KoCanvasBase * canvas

References KoSnapGuide::canvas, and m_snapGuide.

◆ pointsFromShape()

QList< QPointF > KoSnapProxy::pointsFromShape ( KoShape * shape)

returns list of points from given shape

Definition at line 63 of file KoSnapProxy.cpp.

64{
65 QList<QPointF> snapPoints;
66 // no snapping to hidden shapes
67 if (! shape->isVisible())
68 return snapPoints;
69
70 // return the special snap points of the shape
71 snapPoints += shape->snapData().snapPoints();
72
73 KoPathShape * path = dynamic_cast<KoPathShape*>(shape);
74 if (path) {
75 QTransform m = path->absoluteTransformation();
76
78
79 int subpathCount = path->subpathCount();
80 for (int subpathIndex = 0; subpathIndex < subpathCount; ++subpathIndex) {
81 int pointCount = path->subpathPointCount(subpathIndex);
82 for (int pointIndex = 0; pointIndex < pointCount; ++pointIndex) {
83 KoPathPoint * p = path->pointByIndex(KoPathPointIndex(subpathIndex, pointIndex));
84 if (! p || ignoredPoints.contains(p))
85 continue;
86
87 snapPoints.append(m.map(p->point()));
88 }
89 }
90 }
91 else
92 {
93 // add the bounding box corners as default snap points
94 QRectF bbox = shape->boundingRect();
95 snapPoints.append(bbox.topLeft());
96 snapPoints.append(bbox.topRight());
97 snapPoints.append(bbox.bottomRight());
98 snapPoints.append(bbox.bottomLeft());
99 }
100
101 return snapPoints;
102}
const Params2D p
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28
A KoPathPoint represents a point in a path.
The position of a path point within a path shape.
Definition KoPathShape.h:63
virtual KoSnapData snapData() const
Returns additional snap data the shape wants to have snapping to.
Definition KoShape.cpp:1259
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
QTransform absoluteTransformation() const
Definition KoShape.cpp:382
bool isVisible(bool recursive=true) const
Definition KoShape.cpp:979
QList< QPointF > snapPoints() const
Returns list of points to snap to.
QList< KoPathPoint * > ignoredPathPoints() const
Returns list of ignored points.

References KoShape::absoluteTransformation(), KoShape::boundingRect(), KoSnapGuide::ignoredPathPoints(), KoShape::isVisible(), m_snapGuide, p, KoShape::snapData(), and KoSnapData::snapPoints().

◆ pointsInRect()

QList< QPointF > KoSnapProxy::pointsInRect ( const QRectF & rect,
bool omitEditedShape )

returns list of points in given rectangle in document coordinates

Definition at line 21 of file KoSnapProxy.cpp.

22{
23 QList<QPointF> points;
24 QList<KoShape*> shapes = shapesInRect(rect, omitEditedShape);
25 Q_FOREACH (KoShape * shape, shapes) {
26 Q_FOREACH (const QPointF & point, pointsFromShape(shape)) {
27 if (rect.contains(point))
28 points.append(point);
29 }
30 }
31
32 return points;
33}
QList< QPointF > pointsFromShape(KoShape *shape)
returns list of points from given shape
QList< KoShape * > shapesInRect(const QRectF &rect, bool omitEditedShape=false)
returns list of shape in given rectangle in document coordinates
QList< KoShape * > shapes(bool omitEditedShape=false)
returns list of all shapes

References pointsFromShape(), shapes(), and shapesInRect().

◆ segmentsInRect()

QList< KoPathSegment > KoSnapProxy::segmentsInRect ( const QRectF & rect,
bool omitEditedShape )

returns list of points in given rectangle in document coordinates

Definition at line 104 of file KoSnapProxy.cpp.

105{
106
107 QList<KoShape*> shapes = shapesInRect(rect, omitEditedShape);
109
110 QList<KoPathSegment> segments;
111 Q_FOREACH (KoShape * shape, shapes) {
112 QList<KoPathSegment> shapeSegments;
113 QRectF rectOnShape = shape->documentToShape(rect);
114 KoPathShape * path = dynamic_cast<KoPathShape*>(shape);
115 if (path) {
116 shapeSegments = path->segmentsAt(rectOnShape);
117 } else {
118 Q_FOREACH (const KoPathSegment & s, shape->snapData().snapSegments()) {
119 QRectF controlRect = s.controlPointRect();
120 if (! rect.intersects(controlRect) && ! controlRect.contains(rect))
121 continue;
122 QRectF bound = s.boundingRect();
123 if (! rect.intersects(bound) && ! bound.contains(rect))
124 continue;
125 shapeSegments.append(s);
126 }
127 }
128
129 QTransform m = shape->absoluteTransformation();
130 // transform segments to document coordinates
131 Q_FOREACH (const KoPathSegment & s, shapeSegments) {
132 if (ignoredPoints.contains(s.first()) || ignoredPoints.contains(s.second()))
133 continue;
134 segments.append(s.mapped(m));
135 }
136 }
137 return segments;
138}
A KoPathSegment consist of two neighboring KoPathPoints.
KoPathSegment mapped(const QTransform &matrix) const
Returns transformed segment.
QRectF controlPointRect() const
Returns the control point bounding rect.
KoPathPoint * first
KoPathPoint * second
QRectF boundingRect() const
Returns the axis aligned tight bounding rect.
QPointF documentToShape(const QPointF &point) const
Transforms point from document coordinates to shape coordinates.
Definition KoShape.cpp:1211
QList< KoPathSegment > snapSegments() const
Returns list of segments to snap to.

References KoShape::absoluteTransformation(), KoPathSegment::boundingRect(), KoPathSegment::controlPointRect(), KoShape::documentToShape(), KoPathSegment::first, KoSnapGuide::ignoredPathPoints(), m_snapGuide, KoPathSegment::mapped(), KoPathSegment::second, shapes(), shapesInRect(), KoShape::snapData(), and KoSnapData::snapSegments().

◆ shapes()

QList< KoShape * > KoSnapProxy::shapes ( bool omitEditedShape = false)

returns list of all shapes

Definition at line 140 of file KoSnapProxy.cpp.

141{
143 QList<KoShape*> filteredShapes;
144 QList<KoShape*> ignoredShapes = m_snapGuide->ignoredShapes();
145
146 // filter all hidden and ignored shapes
147 Q_FOREACH (KoShape * shape, allShapes) {
148 if (shape->isVisible() &&
149 !ignoredShapes.contains(shape) &&
150 !dynamic_cast<KoShapeLayer*>(shape)) {
151
152 filteredShapes.append(shape);
153 }
154 }
155
156 if (omitEditedShape) {
157 Q_FOREACH (KoPathPoint *point, m_snapGuide->ignoredPathPoints()) {
158 const int index = filteredShapes.indexOf(point->parent());
159 if (index >= 0) {
160 filteredShapes.removeAt(index);
161 }
162 }
163 }
164
165 if (!omitEditedShape && m_snapGuide->additionalEditedShape()) {
166 filteredShapes.append(m_snapGuide->additionalEditedShape());
167 }
168
169 return filteredShapes;
170}
virtual KoShapeManager * shapeManager() const =0
KoPathShape * parent() const
Get the path shape the point belongs to.
QList< KoShape * > shapes
QList< KoShape * > ignoredShapes
KoShape * additionalEditedShape

References KoSnapGuide::additionalEditedShape, KoSnapGuide::canvas, KoSnapGuide::ignoredPathPoints(), KoSnapGuide::ignoredShapes, KoShape::isVisible(), m_snapGuide, KoPathPoint::parent(), KoCanvasBase::shapeManager(), and KoShapeManager::shapes.

◆ shapesInRect()

QList< KoShape * > KoSnapProxy::shapesInRect ( const QRectF & rect,
bool omitEditedShape = false )

returns list of shape in given rectangle in document coordinates

Definition at line 35 of file KoSnapProxy.cpp.

36{
38 Q_FOREACH (KoShape * shape, m_snapGuide->ignoredShapes()) {
39 const int index = shapes.indexOf(shape);
40 if (index >= 0) {
41 shapes.removeAt(index);
42 }
43 }
44
45
46 if (omitEditedShape) {
47 Q_FOREACH (KoPathPoint *point, m_snapGuide->ignoredPathPoints()) {
48 const int index = shapes.indexOf(point->parent());
49 if (index >= 0) {
50 shapes.removeAt(index);
51 }
52 }
53 }
54
55 if (!omitEditedShape && m_snapGuide->additionalEditedShape()) {
57 if (rect.intersects(bound) || rect.contains(bound))
59 }
60 return shapes;
61}
QList< KoShape * > shapesAt(const QRectF &rect, bool omitHiddenShapes=true, bool containedMode=false)

References KoSnapGuide::additionalEditedShape, KoShape::boundingRect(), KoSnapGuide::canvas, KoSnapGuide::ignoredPathPoints(), KoSnapGuide::ignoredShapes, m_snapGuide, KoPathPoint::parent(), KoCanvasBase::shapeManager(), shapes(), and KoShapeManager::shapesAt().

Member Data Documentation

◆ m_snapGuide

KoSnapGuide* KoSnapProxy::m_snapGuide
private

Definition at line 46 of file KoSnapProxy.h.


The documentation for this class was generated from the following files: