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

#include <KoCreatePathTool_p.h>

+ Inheritance diagram for AngleSnapStrategy:

Public Member Functions

void activate ()
 
 AngleSnapStrategy (qreal angleStep, bool active)
 
void deactivate ()
 
QPainterPath decoration (const KoViewConverter &converter) const override
 returns the current snap strategy decoration
 
void setAngleStep (qreal angleStep)
 
void setStartPoint (const QPointF &startPoint)
 
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

bool m_active
 
qreal m_angleStep
 
QPointF m_startPoint
 

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

Definition at line 98 of file KoCreatePathTool_p.h.

Constructor & Destructor Documentation

◆ AngleSnapStrategy()

AngleSnapStrategy::AngleSnapStrategy ( qreal angleStep,
bool active )
inlineexplicit

Definition at line 101 of file KoCreatePathTool_p.h.

103 }
KoSnapStrategy(KoSnapGuide::Strategy type)

Member Function Documentation

◆ activate()

void AngleSnapStrategy::activate ( )
inline

Definition at line 154 of file KoCreatePathTool_p.h.

154 {
155 m_active = true;
156 }

References m_active.

◆ deactivate()

void AngleSnapStrategy::deactivate ( )
inline

Definition at line 150 of file KoCreatePathTool_p.h.

150 {
151 m_active = false;
152 }

References m_active.

◆ decoration()

QPainterPath AngleSnapStrategy::decoration ( const KoViewConverter & converter) const
inlineoverridevirtual

returns the current snap strategy decoration

Implements KoSnapStrategy.

Definition at line 141 of file KoCreatePathTool_p.h.

141 {
142 Q_UNUSED(converter);
143
144 QPainterPath decoration;
145 decoration.moveTo(m_startPoint);
146 decoration.lineTo(snappedPosition());
147 return decoration;
148 }
QPainterPath decoration(const KoViewConverter &converter) const override
returns the current snap strategy decoration
QPointF snappedPosition() const
returns the snapped position form the last call to snapToPoints

References decoration(), m_startPoint, and KoSnapStrategy::snappedPosition().

◆ setAngleStep()

void AngleSnapStrategy::setAngleStep ( qreal angleStep)
inline

Definition at line 109 of file KoCreatePathTool_p.h.

109 {
110 m_angleStep = qAbs(angleStep);
111 }

References m_angleStep.

◆ setStartPoint()

void AngleSnapStrategy::setStartPoint ( const QPointF & startPoint)
inline

Definition at line 105 of file KoCreatePathTool_p.h.

105 {
106 m_startPoint = startPoint;
107 }

References m_startPoint.

◆ snap()

bool AngleSnapStrategy::snap ( const QPointF & mousePosition,
KoSnapProxy * proxy,
qreal maxSnapDistance )
inlineoverridevirtual

Implements KoSnapStrategy.

Definition at line 113 of file KoCreatePathTool_p.h.

113 {
114 Q_UNUSED(proxy);
115
116 if (!m_active)
117 return false;
118
119 QLineF line(m_startPoint, mousePosition);
120 qreal currentAngle = line.angle();
121 int prevStep = qAbs(currentAngle / m_angleStep);
122 int nextStep = prevStep + 1;
123 qreal prevAngle = prevStep * m_angleStep;
124 qreal nextAngle = nextStep * m_angleStep;
125
126 if (qAbs(currentAngle - prevAngle) <= qAbs(currentAngle - nextAngle)) {
127 line.setAngle(prevAngle);
128 } else {
129 line.setAngle(nextAngle);
130 }
131
132 qreal maxSquareSnapDistance = maxSnapDistance * maxSnapDistance;
133 qreal snapDistance = squareDistance(mousePosition, line.p2());
134 if (snapDistance > maxSquareSnapDistance)
135 return false;
136
137 setSnappedPosition(line.p2(), ToLine);
138 return true;
139 }
void setSnappedPosition(const QPointF &position, SnapType snapType)
sets the current snapped position
static qreal squareDistance(const QPointF &p1, const QPointF &p2)

References m_active, m_angleStep, m_startPoint, KoSnapStrategy::setSnappedPosition(), KoSnapStrategy::squareDistance(), and KoSnapStrategy::ToLine.

Member Data Documentation

◆ m_active

bool AngleSnapStrategy::m_active
private

Definition at line 161 of file KoCreatePathTool_p.h.

◆ m_angleStep

qreal AngleSnapStrategy::m_angleStep
private

Definition at line 160 of file KoCreatePathTool_p.h.

◆ m_startPoint

QPointF AngleSnapStrategy::m_startPoint
private

Definition at line 159 of file KoCreatePathTool_p.h.


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