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

snaps to x- or y-coordinates of path points More...

#include <KoSnapStrategy.h>

+ Inheritance diagram for OrthogonalSnapStrategy:

Public Member Functions

QPainterPath decoration (const KoViewConverter &converter) const override
 returns the current snap strategy decoration
 
 OrthogonalSnapStrategy ()
 
bool snap (const QPointF &mousePosition, KoSnapProxy *proxy, qreal maxSnapDistance) override
 
- Public Member Functions inherited from KoSnapStrategy
 KoSnapStrategy (KoSnapGuide::Strategy type)
 
QPointF snappedPosition () const
 returns the snapped position form the last call to snapToPoints
 
SnapType snappedType () const
 
KoSnapGuide::Strategy type () const
 returns the strategies type
 
virtual ~KoSnapStrategy ()
 

Private Attributes

QLineF m_hLine
 
QLineF m_vLine
 

Additional Inherited Members

- Public Types inherited from KoSnapStrategy
enum  SnapType { ToPoint = 0 , ToLine }
 
- Static Public Member Functions inherited from KoSnapStrategy
static qreal scalarProduct (const QPointF &p1, const QPointF &p2)
 
static qreal squareDistance (const QPointF &p1, const QPointF &p2)
 
- Protected Member Functions inherited from KoSnapStrategy
void setSnappedPosition (const QPointF &position, SnapType snapType)
 sets the current snapped position
 

Detailed Description

snaps to x- or y-coordinates of path points

Definition at line 65 of file KoSnapStrategy.h.

Constructor & Destructor Documentation

◆ OrthogonalSnapStrategy()

OrthogonalSnapStrategy::OrthogonalSnapStrategy ( )

Definition at line 64 of file KoSnapStrategy.cpp.

66{
67}
KoSnapStrategy(KoSnapGuide::Strategy type)

Member Function Documentation

◆ decoration()

QPainterPath OrthogonalSnapStrategy::decoration ( const KoViewConverter & converter) const
overridevirtual

returns the current snap strategy decoration

Implements KoSnapStrategy.

Definition at line 120 of file KoSnapStrategy.cpp.

121{
122 QPainterPath decoration;
123 if (! m_hLine.isNull()) {
124 decoration.moveTo(m_hLine.p1());
125 decoration.lineTo(m_hLine.p2());
126 }
127 if (! m_vLine.isNull()) {
128 decoration.moveTo(m_vLine.p1());
129 decoration.lineTo(m_vLine.p2());
130 }
131 return decoration;
132}
QPainterPath decoration(const KoViewConverter &converter) const override
returns the current snap strategy decoration

References decoration(), m_hLine, and m_vLine.

◆ snap()

bool OrthogonalSnapStrategy::snap ( const QPointF & mousePosition,
KoSnapProxy * proxy,
qreal maxSnapDistance )
overridevirtual

Implements KoSnapStrategy.

Definition at line 69 of file KoSnapStrategy.cpp.

70{
71 Q_ASSERT(std::isfinite(maxSnapDistance));
72 QPointF horzSnap, vertSnap;
73 qreal minVertDist = HUGE_VAL;
74 qreal minHorzDist = HUGE_VAL;
75
76 QList<KoShape*> shapes = proxy->shapes(true);
77 Q_FOREACH (KoShape * shape, shapes) {
78 QList<QPointF> points = proxy->pointsFromShape(shape);
79 foreach (const QPointF &point, points) {
80 qreal dx = fabs(point.x() - mousePosition.x());
81 if (dx < minHorzDist && dx < maxSnapDistance) {
82 minHorzDist = dx;
83 horzSnap = point;
84 }
85 qreal dy = fabs(point.y() - mousePosition.y());
86 if (dy < minVertDist && dy < maxSnapDistance) {
87 minVertDist = dy;
88 vertSnap = point;
89 }
90 }
91 }
92
93 QPointF snappedPoint = mousePosition;
95
96 if (minHorzDist < HUGE_VAL)
97 snappedPoint.setX(horzSnap.x());
98 if (minVertDist < HUGE_VAL)
99 snappedPoint.setY(vertSnap.y());
100
101 if (minHorzDist < HUGE_VAL) {
102 m_hLine = QLineF(horzSnap, snappedPoint);
103 } else {
104 m_hLine = QLineF();
106 }
107
108 if (minVertDist < HUGE_VAL) {
109 m_vLine = QLineF(vertSnap, snappedPoint);
110 } else {
111 m_vLine = QLineF();
113 }
114
115 setSnappedPosition(snappedPoint, snappedType);
116
117 return (minHorzDist < HUGE_VAL || minVertDist < HUGE_VAL);
118}
QList< QPointF > pointsFromShape(KoShape *shape)
returns list of points from given shape
QList< KoShape * > shapes(bool omitEditedShape=false)
returns list of all shapes
void setSnappedPosition(const QPointF &position, SnapType snapType)
sets the current snapped position
SnapType snappedType() const

References m_hLine, m_vLine, KoSnapProxy::pointsFromShape(), KoSnapStrategy::setSnappedPosition(), KoSnapProxy::shapes(), KoSnapStrategy::snappedType(), KoSnapStrategy::ToLine, and KoSnapStrategy::ToPoint.

Member Data Documentation

◆ m_hLine

QLineF OrthogonalSnapStrategy::m_hLine
private

Definition at line 72 of file KoSnapStrategy.h.

◆ m_vLine

QLineF OrthogonalSnapStrategy::m_vLine
private

Definition at line 73 of file KoSnapStrategy.h.


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