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

#include <EnhancedPathHandle.h>

Public Member Functions

void changePosition (const QPointF &position)
 
 EnhancedPathHandle (EnhancedPathShape *parent)
 
bool hasPosition () const
 Returns if the handle has valid positional parameters.S.
 
QPointF position ()
 
void setPolarCenter (EnhancedPathParameter *polarX, EnhancedPathParameter *polarY)
 
void setPosition (EnhancedPathParameter *positionX, EnhancedPathParameter *positionY)
 
void setRadiusRange (EnhancedPathParameter *minRadius, EnhancedPathParameter *maxRadius)
 
void setRangeX (EnhancedPathParameter *minX, EnhancedPathParameter *maxX)
 
void setRangeY (EnhancedPathParameter *minY, EnhancedPathParameter *maxY)
 
 ~EnhancedPathHandle ()
 Destroys the handle.
 

Private Member Functions

bool isPolar () const
 Returns if handle is polar.
 

Private Attributes

EnhancedPathParameterm_maximumX
 the maximum x-coordinate
 
EnhancedPathParameterm_maximumY
 the maximum y-coordinate
 
EnhancedPathParameterm_maxRadius
 the maximum polar radius
 
EnhancedPathParameterm_minimumX
 the minimum x-coordinate
 
EnhancedPathParameterm_minimumY
 the minimum y-coordinate
 
EnhancedPathParameterm_minRadius
 the minimum polar radius
 
EnhancedPathShapem_parent
 the enhanced path shape owning this handle
 
EnhancedPathParameterm_polarX
 the polar center x-coordinate
 
EnhancedPathParameterm_polarY
 the polar center y-coordinate
 
EnhancedPathParameterm_positionX
 the position x-coordinate
 
EnhancedPathParameterm_positionY
 the position y-coordinate
 

Detailed Description

An interaction handle used by the EnhancedPathShape for changing the shape interactively.

Definition at line 22 of file EnhancedPathHandle.h.

Constructor & Destructor Documentation

◆ EnhancedPathHandle()

EnhancedPathHandle::EnhancedPathHandle ( EnhancedPathShape * parent)
explicit

Constructs a new empty handle;

Note that an empty handle is not valid, as long as there are no positional parameters set with setPosition.

Definition at line 17 of file EnhancedPathHandle.cpp.

18 : m_parent(parent)
19 , m_positionX(0)
20 , m_positionY(0)
21 , m_minimumX(0)
22 , m_minimumY(0)
23 , m_maximumX(0)
24 , m_maximumY(0)
25 , m_polarX(0)
26 , m_polarY(0)
27 , m_minRadius(0)
28 , m_maxRadius(0)
29{
30 Q_ASSERT(m_parent);
31}
EnhancedPathParameter * m_positionY
the position y-coordinate
EnhancedPathParameter * m_polarY
the polar center y-coordinate
EnhancedPathParameter * m_minRadius
the minimum polar radius
EnhancedPathParameter * m_positionX
the position x-coordinate
EnhancedPathParameter * m_maximumX
the maximum x-coordinate
EnhancedPathShape * m_parent
the enhanced path shape owning this handle
EnhancedPathParameter * m_minimumY
the minimum y-coordinate
EnhancedPathParameter * m_polarX
the polar center x-coordinate
EnhancedPathParameter * m_maxRadius
the maximum polar radius
EnhancedPathParameter * m_maximumY
the maximum y-coordinate
EnhancedPathParameter * m_minimumX
the minimum x-coordinate

References m_parent.

◆ ~EnhancedPathHandle()

EnhancedPathHandle::~EnhancedPathHandle ( )

Destroys the handle.

Definition at line 33 of file EnhancedPathHandle.cpp.

34{
35}

Member Function Documentation

◆ changePosition()

void EnhancedPathHandle::changePosition ( const QPointF & position)

Attempts to changes the position of the handle. Only the coordinates of the handle which reference a modifier can be changed. The new position is automatically stored into the modifier of the given enhanced path.

Parameters
positionthe new position the handle to set
paththe enhanced path the handle is referenced from

Definition at line 65 of file EnhancedPathHandle.cpp.

66{
67 if (!hasPosition()) {
68 return;
69 }
70
71 QPointF constrainedPosition(position);
72
73 if (isPolar()) {
74 // convert cartesian coordinates into polar coordinates
75 QPointF polarCenter(m_polarX->evaluate(), m_polarY->evaluate());
76 QPointF diff = constrainedPosition - polarCenter;
77 // compute the polar radius
78 qreal radius = sqrt(diff.x() * diff.x() + diff.y() * diff.y());
79 // compute the polar angle
80 qreal angle = atan2(diff.y(), diff.x());
81 if (angle < 0.0) {
82 angle += 2 * M_PI;
83 }
84
85 // constrain the radius
86 if (m_minRadius) {
87 radius = qMax(m_minRadius->evaluate(), radius);
88 }
89 if (m_maxRadius) {
90 radius = qMin(m_maxRadius->evaluate(), radius);
91 }
92
93 constrainedPosition.setX(angle * 180.0 / M_PI);
94 constrainedPosition.setY(radius);
95 } else {
96 // constrain x coordinate
97 if (m_minimumX) {
98 constrainedPosition.setX(qMax(m_minimumX->evaluate(), constrainedPosition.x()));
99 }
100 if (m_maximumX) {
101 constrainedPosition.setX(qMin(m_maximumX->evaluate(), constrainedPosition.x()));
102 }
103
104 // constrain y coordinate
105 if (m_minimumY) {
106 constrainedPosition.setY(qMax(m_minimumY->evaluate(), constrainedPosition.y()));
107 }
108 if (m_maximumY) {
109 constrainedPosition.setY(qMin(m_maximumY->evaluate(), constrainedPosition.y()));
110 }
111 }
112
113 m_positionX->modify(constrainedPosition.x());
114 m_positionY->modify(constrainedPosition.y());
115}
bool hasPosition() const
Returns if the handle has valid positional parameters.S.
bool isPolar() const
Returns if handle is polar.
virtual qreal evaluate()=0
evaluates the parameter using the given path
virtual void modify(qreal value)
modifies the parameter if possible, using the new value
#define M_PI
Definition kis_global.h:111
KRITAIMAGE_EXPORT qreal atan2(qreal y, qreal x)
atan2 replacement

References EnhancedPathParameter::evaluate(), hasPosition(), isPolar(), m_maximumX, m_maximumY, m_maxRadius, m_minimumX, m_minimumY, m_minRadius, M_PI, m_polarX, m_polarY, m_positionX, m_positionY, EnhancedPathParameter::modify(), and position().

◆ hasPosition()

bool EnhancedPathHandle::hasPosition ( ) const

Returns if the handle has valid positional parameters.S.

Definition at line 37 of file EnhancedPathHandle.cpp.

38{
39 return m_positionX && m_positionY;
40}

References m_positionX, and m_positionY.

◆ isPolar()

bool EnhancedPathHandle::isPolar ( ) const
private

Returns if handle is polar.

Definition at line 141 of file EnhancedPathHandle.cpp.

142{
143 return m_polarX && m_polarY;
144}

References m_polarX, and m_polarY.

◆ position()

QPointF EnhancedPathHandle::position ( )

Evaluates the position of the handle.

Returns
the actual handle position

Definition at line 48 of file EnhancedPathHandle.cpp.

49{
50 if (!hasPosition()) {
51 return QPointF();
52 }
53
55 if (isPolar()) {
56 // convert polar coordinates into cartesian coordinates
57 QPointF center(m_polarX->evaluate(), m_polarY->evaluate());
58 qreal angleInRadian = position.x() * M_PI / 180.0;
59 position = center + position.y() * QPointF(cos(angleInRadian), sin(angleInRadian));
60 }
61
62 return position;
63}

References EnhancedPathParameter::evaluate(), hasPosition(), isPolar(), M_PI, m_polarX, m_polarY, m_positionX, m_positionY, and position().

◆ setPolarCenter()

void EnhancedPathHandle::setPolarCenter ( EnhancedPathParameter * polarX,
EnhancedPathParameter * polarY )

Sets the center of a polar handle.

If both parameters are valid pointers, then the handle behaves like a polar handle. This means the x-coordinate of the position represents an angle in degree and the y-coordinate a radius.

Parameters
polarXthe polar center x-coordinate
polarYthe polar center y-coordinate

Definition at line 129 of file EnhancedPathHandle.cpp.

130{
131 m_polarX = polarX;
132 m_polarY = polarY;
133}

References m_polarX, and m_polarY.

◆ setPosition()

void EnhancedPathHandle::setPosition ( EnhancedPathParameter * positionX,
EnhancedPathParameter * positionY )

Sets the positional parameters, making the handle valid.

It replaces the actual positional parameters.

Parameters
positionXthe x-coordinate of the handle position
positionYthe y-coordinate of the handle position

Definition at line 42 of file EnhancedPathHandle.cpp.

43{
44 m_positionX = positionX;
45 m_positionY = positionY;
46}

References m_positionX, and m_positionY.

◆ setRadiusRange()

void EnhancedPathHandle::setRadiusRange ( EnhancedPathParameter * minRadius,
EnhancedPathParameter * maxRadius )

Sets the range of the radius for polar handles.

Parameters
minRadiusthe minimum polar radius
maxRadiusthe maximum polar radius

Definition at line 135 of file EnhancedPathHandle.cpp.

136{
137 m_minRadius = minRadius;
138 m_maxRadius = maxRadius;
139}

References m_maxRadius, and m_minRadius.

◆ setRangeX()

void EnhancedPathHandle::setRangeX ( EnhancedPathParameter * minX,
EnhancedPathParameter * maxX )

Sets the range of the handles x-coordinate.

A zero pointer has the effect of no maximum/minimum value.

Parameters
minXthe minimum x-coordinate
maxXthe maximum x-coordinate

Definition at line 117 of file EnhancedPathHandle.cpp.

118{
119 m_minimumX = minX;
120 m_maximumX = maxX;
121}

References m_maximumX, and m_minimumX.

◆ setRangeY()

void EnhancedPathHandle::setRangeY ( EnhancedPathParameter * minY,
EnhancedPathParameter * maxY )

Sets the range of the handles y-coordinate.

A zero pointer has the effect of no maximum/minimum value.

Parameters
minYthe minimum y-coordinate
maxYthe maximum y-coordinate

Definition at line 123 of file EnhancedPathHandle.cpp.

124{
125 m_minimumY = minY;
126 m_maximumY = maxY;
127}

References m_maximumY, and m_minimumY.

Member Data Documentation

◆ m_maximumX

EnhancedPathParameter* EnhancedPathHandle::m_maximumX
private

the maximum x-coordinate

Definition at line 113 of file EnhancedPathHandle.h.

◆ m_maximumY

EnhancedPathParameter* EnhancedPathHandle::m_maximumY
private

the maximum y-coordinate

Definition at line 114 of file EnhancedPathHandle.h.

◆ m_maxRadius

EnhancedPathParameter* EnhancedPathHandle::m_maxRadius
private

the maximum polar radius

Definition at line 118 of file EnhancedPathHandle.h.

◆ m_minimumX

EnhancedPathParameter* EnhancedPathHandle::m_minimumX
private

the minimum x-coordinate

Definition at line 111 of file EnhancedPathHandle.h.

◆ m_minimumY

EnhancedPathParameter* EnhancedPathHandle::m_minimumY
private

the minimum y-coordinate

Definition at line 112 of file EnhancedPathHandle.h.

◆ m_minRadius

EnhancedPathParameter* EnhancedPathHandle::m_minRadius
private

the minimum polar radius

Definition at line 117 of file EnhancedPathHandle.h.

◆ m_parent

EnhancedPathShape* EnhancedPathHandle::m_parent
private

the enhanced path shape owning this handle

Definition at line 108 of file EnhancedPathHandle.h.

◆ m_polarX

EnhancedPathParameter* EnhancedPathHandle::m_polarX
private

the polar center x-coordinate

Definition at line 115 of file EnhancedPathHandle.h.

◆ m_polarY

EnhancedPathParameter* EnhancedPathHandle::m_polarY
private

the polar center y-coordinate

Definition at line 116 of file EnhancedPathHandle.h.

◆ m_positionX

EnhancedPathParameter* EnhancedPathHandle::m_positionX
private

the position x-coordinate

Definition at line 109 of file EnhancedPathHandle.h.

◆ m_positionY

EnhancedPathParameter* EnhancedPathHandle::m_positionY
private

the position y-coordinate

Definition at line 110 of file EnhancedPathHandle.h.


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