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

#include <kis_temporary_paint_constraint.h>

Public Types

enum class  InteractionMode { Normal , SnapToAngle }
 

Public Member Functions

QPointF adjustPosition (const QPointF &point, const QPointF &strokeBegin, bool checkForInitialMovement, qreal moveThresholdPt) const
 
void beginLine (const QPointF &anchor)
 
bool hasLine () const
 
bool hasValidLine () const
 
InteractionMode interactionMode () const
 
bool isLocked () const
 
QPointF lineAnchor () const
 
QPointF lineSecondPoint () const
 
void setInteractionMode (InteractionMode mode)
 
void setLocked (bool locked)
 
void updateLine (const QPointF &secondPoint, bool snapToAngle=false)
 

Private Attributes

QPointF m_anchor
 
bool m_angleSnapped {false}
 
bool m_hasLine {false}
 
InteractionMode m_interactionMode {InteractionMode::Normal}
 
bool m_locked {false}
 
QPointF m_secondPoint
 

Detailed Description

Definition at line 13 of file kis_temporary_paint_constraint.h.

Member Enumeration Documentation

◆ InteractionMode

Member Function Documentation

◆ adjustPosition()

QPointF KisTemporaryPaintConstraint::adjustPosition ( const QPointF & point,
const QPointF & strokeBegin,
bool checkForInitialMovement,
qreal moveThresholdPt ) const

Definition at line 100 of file kis_temporary_paint_constraint.cpp.

104{
105 if (!m_locked || !hasValidLine()) {
106 return point;
107 }
108
109 if (checkForInitialMovement && KisAlgebra2D::norm(point - strokeBegin) < moveThresholdPt) {
110 return strokeBegin;
111 }
112
113 const QPointF delta = m_secondPoint - m_anchor;
114 const qreal squareLength = KisAlgebra2D::normSquared(delta);
115 if (qFuzzyIsNull(squareLength)) {
116 return point;
117 }
118
119 const qreal t = KisAlgebra2D::dotProduct(point - m_anchor, delta) / squareLength;
120 return m_anchor + delta * t;
121}
static bool qFuzzyIsNull(half h)
qreal normSquared(const T &a)
qreal norm(const T &a)
PointTypeTraits< T >::value_type dotProduct(const T &a, const T &b)

References KisAlgebra2D::dotProduct(), hasValidLine(), m_anchor, m_locked, m_secondPoint, KisAlgebra2D::norm(), KisAlgebra2D::normSquared(), and qFuzzyIsNull().

◆ beginLine()

void KisTemporaryPaintConstraint::beginLine ( const QPointF & anchor)

◆ hasLine()

bool KisTemporaryPaintConstraint::hasLine ( ) const

Definition at line 70 of file kis_temporary_paint_constraint.cpp.

71{
72 return m_hasLine;
73}

References m_hasLine.

◆ hasValidLine()

bool KisTemporaryPaintConstraint::hasValidLine ( ) const

Definition at line 85 of file kis_temporary_paint_constraint.cpp.

86{
87 return m_hasLine && KisAlgebra2D::normSquared(m_secondPoint - m_anchor) > minLineLengthSquared;
88}

References m_anchor, m_hasLine, m_secondPoint, and KisAlgebra2D::normSquared().

◆ interactionMode()

KisTemporaryPaintConstraint::InteractionMode KisTemporaryPaintConstraint::interactionMode ( ) const

Definition at line 37 of file kis_temporary_paint_constraint.cpp.

38{
39 return m_interactionMode;
40}

References m_interactionMode.

◆ isLocked()

bool KisTemporaryPaintConstraint::isLocked ( ) const

Definition at line 80 of file kis_temporary_paint_constraint.cpp.

81{
82 return m_locked;
83}

References m_locked.

◆ lineAnchor()

QPointF KisTemporaryPaintConstraint::lineAnchor ( ) const

Definition at line 90 of file kis_temporary_paint_constraint.cpp.

91{
92 return m_anchor;
93}

References m_anchor.

◆ lineSecondPoint()

QPointF KisTemporaryPaintConstraint::lineSecondPoint ( ) const

Definition at line 95 of file kis_temporary_paint_constraint.cpp.

96{
97 return m_secondPoint;
98}

References m_secondPoint.

◆ setInteractionMode()

void KisTemporaryPaintConstraint::setInteractionMode ( InteractionMode mode)

Definition at line 32 of file kis_temporary_paint_constraint.cpp.

33{
34 m_interactionMode = mode;
35}

References m_interactionMode.

◆ setLocked()

void KisTemporaryPaintConstraint::setLocked ( bool locked)

Definition at line 75 of file kis_temporary_paint_constraint.cpp.

76{
77 m_locked = locked && hasValidLine();
78}

References hasValidLine(), and m_locked.

◆ updateLine()

void KisTemporaryPaintConstraint::updateLine ( const QPointF & secondPoint,
bool snapToAngle = false )

Definition at line 51 of file kis_temporary_paint_constraint.cpp.

52{
53 if (m_locked) {
54 return;
55 }
56
57 if (!m_hasLine) {
58 beginLine(secondPoint);
59 return;
60 }
61
62 if (snapToAngle) {
63 m_secondPoint = snappedEndpoint(m_anchor, secondPoint);
64 m_angleSnapped = true;
65 } else if (!m_angleSnapped) {
66 m_secondPoint = secondPoint;
67 }
68}

References beginLine(), m_anchor, m_angleSnapped, m_hasLine, m_locked, and m_secondPoint.

Member Data Documentation

◆ m_anchor

QPointF KisTemporaryPaintConstraint::m_anchor
private

Definition at line 41 of file kis_temporary_paint_constraint.h.

◆ m_angleSnapped

bool KisTemporaryPaintConstraint::m_angleSnapped {false}
private

Definition at line 46 of file kis_temporary_paint_constraint.h.

46{false};

◆ m_hasLine

bool KisTemporaryPaintConstraint::m_hasLine {false}
private

Definition at line 44 of file kis_temporary_paint_constraint.h.

44{false};

◆ m_interactionMode

InteractionMode KisTemporaryPaintConstraint::m_interactionMode {InteractionMode::Normal}
private

◆ m_locked

bool KisTemporaryPaintConstraint::m_locked {false}
private

Definition at line 45 of file kis_temporary_paint_constraint.h.

45{false};

◆ m_secondPoint

QPointF KisTemporaryPaintConstraint::m_secondPoint
private

Definition at line 42 of file kis_temporary_paint_constraint.h.


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