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

#include <ConcentricEllipseAssistant.h>

+ Inheritance diagram for ConcentricEllipseAssistant:

Public Member Functions

void adjustLine (QPointF &point, QPointF &strokeBegin) override
 
QPointF adjustPosition (const QPointF &point, const QPointF &strokeBegin, const bool snapToAny, qreal moveThresholdPt) override
 
KisPaintingAssistantSP clone (QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap) const override
 
 ConcentricEllipseAssistant ()
 
QPointF getDefaultEditorPosition () const override
 
bool isAssistantComplete () const override
 
int numHandles () const override
 
void transform (const QTransform &transform) override
 
- Public Member Functions inherited from KisPaintingAssistant
void addHandle (KisPaintingAssistantHandleSP handle, HandleType type)
 
bool areTwoPointsClose (const QPointF &pointOne, const QPointF &pointTwo)
 
QColor assistantCustomColor ()
 
KisPaintingAssistantHandleSP bottomLeft ()
 
const KisPaintingAssistantHandleSP bottomLeft () const
 
KisPaintingAssistantHandleSP bottomMiddle ()
 
const KisPaintingAssistantHandleSP bottomMiddle () const
 
KisPaintingAssistantHandleSP bottomRight ()
 
const KisPaintingAssistantHandleSP bottomRight () const
 
virtual bool canBeLocal () const
 canBeLocal
 
KisPaintingAssistantHandleSP closestCornerHandleFromPoint (QPointF point)
 
void copySharedData (KisPaintingAssistantSP assistant)
 
void drawError (QPainter &painter, const QPainterPath &path)
 
void drawPath (QPainter &painter, const QPainterPath &path, bool drawActive=true)
 
void drawPreview (QPainter &painter, const QPainterPath &path)
 
void drawX (QPainter &painter, const QPointF &pt)
 
QPointF editorWidgetOffset ()
 
QColor effectiveAssistantColor () const
 
virtual void endStroke ()
 
void findPerspectiveAssistantHandleLocation ()
 
virtual QPointF getEditorPosition () const
 
QList< KisPaintingAssistantHandleSPhandles ()
 
const QList< KisPaintingAssistantHandleSP > & handles () const
 
const QString & id () const
 
bool isDuplicating ()
 isDuplicating
 
bool isLocal () const
 isLocal
 
bool isLocked ()
 isLocked
 
bool isSnappingActive () const
 
 KisPaintingAssistant (const QString &id, const QString &name)
 
KisPaintingAssistantHandleSP leftMiddle ()
 
const KisPaintingAssistantHandleSP leftMiddle () const
 
virtual bool loadCustomXml (QXmlStreamReader *xml)
 
void loadXml (KoStore *store, QMap< int, KisPaintingAssistantHandleSP > &handleMap, QString path)
 
const QString & name () const
 
KisPaintingAssistantHandleSP oppHandleOne ()
 
void replaceHandle (KisPaintingAssistantHandleSP _handle, KisPaintingAssistantHandleSP _with)
 
KisPaintingAssistantHandleSP rightMiddle ()
 
const KisPaintingAssistantHandleSP rightMiddle () const
 
virtual void saveCustomXml (QXmlStreamWriter *xml)
 
QByteArray saveXml (QMap< KisPaintingAssistantHandleSP, int > &handleMap)
 
void saveXmlList (QDomDocument &doc, QDomElement &assistantsElement, int count)
 
virtual void setAdjustedBrushPosition (const QPointF position)
 
void setAssistantCustomColor (QColor color)
 
void setAssistantGlobalColorCache (const QColor &color)
 
void setDecorationThickness (int thickness)
 
void setDuplicating (bool value)
 setDuplicating
 
void setEditorWidgetOffset (QPointF offset)
 
virtual void setFollowBrushPosition (bool follow)
 
void setLocal (bool value)
 setLocal
 
void setLocked (bool value)
 setLocked
 
void setSnappingActive (bool set)
 
void setUseCustomColor (bool useCustomColor)
 
QList< KisPaintingAssistantHandleSPsideHandles ()
 
const QList< KisPaintingAssistantHandleSP > & sideHandles () const
 
KisPaintingAssistantHandleSP topLeft ()
 
const KisPaintingAssistantHandleSP topLeft () const
 
KisPaintingAssistantHandleSP topMiddle ()
 
const KisPaintingAssistantHandleSP topMiddle () const
 
KisPaintingAssistantHandleSP topRight ()
 
const KisPaintingAssistantHandleSP topRight () const
 
void uncache ()
 
bool useCustomColor ()
 
QPointF viewportConstrainedEditorPosition (const KisCoordinatesConverter *converter, const QSize editorSize)
 
virtual ~KisPaintingAssistant ()
 

Protected Member Functions

QRect boundingRect () const override
 
void drawAssistant (QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, bool cached, KisCanvas2 *canvas, bool assistantVisible=true, bool previewVisible=true) override
 
void drawCache (QPainter &gc, const KisCoordinatesConverter *converter, bool assistantVisible=true) override
 performance layer where the graphics can be drawn from a cache instead of generated every render update
 
- Protected Member Functions inherited from KisPaintingAssistant
QPointF effectiveBrushPosition (const KisCoordinatesConverter *converter, KisCanvas2 *canvas) const
 Query the effective brush position to be used for preview lines. This is intended to be used for painting the dynamic preview lines for assistants that feature them. Affected by setAdjustedBrushPosition() and setFollowBrushPosition().
 
virtual KisPaintingAssistantHandleSP firstLocalHandle () const
 firstLocalHandle Note: this doesn't guarantee it will be the topleft corner! For that, use getLocalRect().topLeft() The only purpose of those functions to exist is to be able to put getLocalRect() function in the KisPaintingAssistant instead of reimplementing it in every specific assistant.
 
QRectF getLocalRect () const
 getLocalRect The function deals with local handles not being topLeft and bottomRight gracefully and returns a correct rectangle. Thanks to that the user can place handles in a "wrong" order or move them around but the local rectangle will still be correct.
 
void initHandles (QList< KisPaintingAssistantHandleSP > _handles)
 
 KisPaintingAssistant (const KisPaintingAssistant &rhs, QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap)
 
QPointF pixelToView (const QPoint pixelCoords) const
 
virtual KisPaintingAssistantHandleSP secondLocalHandle () const
 secondLocalHandle Note: this doesn't guarantee it will be the bottomRight corner! For that, use getLocalRect().bottomRight() (and remember that for QRect bottomRight() works differently than for QRectF, so don't convert to QRect before accessing the corner)
 

Private Member Functions

 ConcentricEllipseAssistant (const ConcentricEllipseAssistant &rhs, QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap)
 
QPointF project (const QPointF &pt, const QPointF &strokeBegin) const
 

Private Attributes

Ellipse m_ellipse
 
Ellipse m_extraEllipse
 

Additional Inherited Members

- Static Public Member Functions inherited from KisPaintingAssistant
static QList< KisPaintingAssistantSPcloneAssistantList (const QList< KisPaintingAssistantSP > &list)
 
static double norm2 (const QPointF &p)
 
- Protected Attributes inherited from KisPaintingAssistant
QList< KisPaintingAssistantHandleSPm_handles
 
bool m_hasBeenInsideLocalRect {false}
 

Detailed Description

Definition at line 19 of file ConcentricEllipseAssistant.h.

Constructor & Destructor Documentation

◆ ConcentricEllipseAssistant() [1/2]

ConcentricEllipseAssistant::ConcentricEllipseAssistant ( )

Definition at line 23 of file ConcentricEllipseAssistant.cc.

24 : KisPaintingAssistant("concentric ellipse", i18n("Concentric Ellipse assistant"))
25{
26}
KisPaintingAssistant(const QString &id, const QString &name)

◆ ConcentricEllipseAssistant() [2/2]

ConcentricEllipseAssistant::ConcentricEllipseAssistant ( const ConcentricEllipseAssistant & rhs,
QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > & handleMap )
explicitprivate

Member Function Documentation

◆ adjustLine()

void ConcentricEllipseAssistant::adjustLine ( QPointF & point,
QPointF & strokeBegin )
overridevirtual

Implements KisPaintingAssistant.

Definition at line 69 of file ConcentricEllipseAssistant.cc.

70{
71 point = project(point, strokeBegin);
72}
QPointF project(const QPointF &pt, const QPointF &strokeBegin) const

References project().

◆ adjustPosition()

QPointF ConcentricEllipseAssistant::adjustPosition ( const QPointF & point,
const QPointF & strokeBegin,
const bool snapToAny,
qreal moveThresholdPt )
overridevirtual

Adjust the position given in parameter.

Parameters
pointthe coordinates in point in the document reference
strokeBeginthe coordinates of the beginning of the stroke
snapToAnybecause now assistants can be composited out of multiple inside assistants. snapToAny true means that you can use any of the inside assistant, while it being false means you should use the last used one. The logic determining when it happens (first stroke etc.) is in the decoration, so those two options are enough.
moveThresholdPtthe threshold for the "move" of the cursor measured in pt (usually equals to 2px in screen coordinates converted to pt)

Implements KisPaintingAssistant.

Definition at line 64 of file ConcentricEllipseAssistant.cc.

65{
66 return project(pt, strokeBegin);
67}

References project().

◆ boundingRect()

QRect ConcentricEllipseAssistant::boundingRect ( ) const
overrideprotectedvirtual

Reimplemented from KisPaintingAssistant.

Definition at line 140 of file ConcentricEllipseAssistant.cc.

141{
142 if (!isAssistantComplete()) {
144 }
145
146 if (m_ellipse.set(*handles()[0], *handles()[1], *handles()[2])) {
147 return m_ellipse.boundingRect().adjusted(-2, -2, 2, 2).toAlignedRect();
148 } else {
149 return QRect();
150 }
151}
bool set(const QPointF &m1, const QPointF &m2, const QPointF &p)
Definition Ellipse.cc:23
QRectF boundingRect() const
Definition Ellipse.cc:62
virtual QRect boundingRect() const
const QList< KisPaintingAssistantHandleSP > & handles() const

References KisPaintingAssistant::boundingRect(), Ellipse::boundingRect(), KisPaintingAssistant::handles(), isAssistantComplete(), m_ellipse, and Ellipse::set().

◆ clone()

KisPaintingAssistantSP ConcentricEllipseAssistant::clone ( QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > & handleMap) const
overridevirtual

Implements KisPaintingAssistant.

Definition at line 28 of file ConcentricEllipseAssistant.cc.

29{
30 return KisPaintingAssistantSP(new ConcentricEllipseAssistant(*this, handleMap));
31}
QSharedPointer< KisPaintingAssistant > KisPaintingAssistantSP
Definition kis_types.h:189

References ConcentricEllipseAssistant().

◆ drawAssistant()

void ConcentricEllipseAssistant::drawAssistant ( QPainter & gc,
const QRectF & updateRect,
const KisCoordinatesConverter * converter,
bool cached,
KisCanvas2 * canvas,
bool assistantVisible = true,
bool previewVisible = true )
overrideprotectedvirtual

Reimplemented from KisPaintingAssistant.

Definition at line 74 of file ConcentricEllipseAssistant.cc.

75{
76 gc.save();
77 gc.resetTransform();
78
79 if (isSnappingActive() && previewVisible == true){
80
82
83 QTransform initialTransform = converter->documentToWidgetTransform();
84
85 if (m_ellipse.set(*handles()[0], *handles()[1], *handles()[2])) {
86 QPointF mousePos = effectiveBrushPosition(converter, canvas);
87 QPointF initial = m_ellipse.project(initialTransform.inverted().map(mousePos));
88 QPointF center = m_ellipse.boundingRect().center();
89 qreal Ratio = QLineF(center, initialTransform.inverted().map(mousePos)).length() /QLineF(center, initial).length();
90 //line from center to handle 1 * difference.
91 //set handle1 translated to
92 // valid ellipse
93 gc.setTransform(initialTransform);
94 gc.setTransform(m_ellipse.getInverse(), true);
95 QPainterPath path;
96 // Draw the ellipse
97 path.addEllipse(QPointF(0, 0), m_ellipse.semiMajor()*Ratio, m_ellipse.semiMinor()*Ratio);
98 drawPreview(gc, path);
99 }
100 }
101 }
102 gc.restore();
103 KisPaintingAssistant::drawAssistant(gc, updateRect, converter, cached, canvas, assistantVisible, previewVisible);
104
105}
qreal semiMajor() const
Definition Ellipse.h:33
const QTransform & getInverse() const
Definition Ellipse.h:32
qreal semiMinor() const
Definition Ellipse.h:34
QPointF project(const QPointF &) const
Definition Ellipse.cc:39
QPointF effectiveBrushPosition(const KisCoordinatesConverter *converter, KisCanvas2 *canvas) const
Query the effective brush position to be used for preview lines. This is intended to be used for pain...
void drawPreview(QPainter &painter, const QPainterPath &path)
virtual void drawAssistant(QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, bool cached, KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true)

References Ellipse::boundingRect(), KisCoordinatesConverter::documentToWidgetTransform(), KisPaintingAssistant::drawAssistant(), KisPaintingAssistant::drawPreview(), KisPaintingAssistant::effectiveBrushPosition(), Ellipse::getInverse(), KisPaintingAssistant::handles(), isAssistantComplete(), KisPaintingAssistant::isSnappingActive(), m_ellipse, Ellipse::project(), Ellipse::semiMajor(), Ellipse::semiMinor(), and Ellipse::set().

◆ drawCache()

void ConcentricEllipseAssistant::drawCache ( QPainter & gc,
const KisCoordinatesConverter * converter,
bool assistantVisible = true )
overrideprotectedvirtual

performance layer where the graphics can be drawn from a cache instead of generated every render update

Implements KisPaintingAssistant.

Definition at line 108 of file ConcentricEllipseAssistant.cc.

109{
110 if (assistantVisible == false || handles().size() < 2) { // 2 points means a line, so we can continue after 1 point
111 return;
112 }
113
114 QTransform initialTransform = converter->documentToWidgetTransform();
115
116 if (handles().size() == 2) {
117 // just draw the axis
118 gc.setTransform(initialTransform);
119 QPainterPath path;
120 path.moveTo(*handles()[0]);
121 path.lineTo(*handles()[1]);
122 drawPath(gc, path, isSnappingActive());
123 return;
124 }
125
126 if (m_ellipse.set(*handles()[0], *handles()[1], *handles()[2])) {
127 // valid ellipse
128
129 gc.setTransform(initialTransform);
130 gc.setTransform(m_ellipse.getInverse(), true);
131 QPainterPath path;
132 path.moveTo(QPointF(-m_ellipse.semiMajor(), 0)); path.lineTo(QPointF(m_ellipse.semiMajor(), 0));
133 path.moveTo(QPointF(0, -m_ellipse.semiMinor())); path.lineTo(QPointF(0, m_ellipse.semiMinor()));
134 // Draw the ellipse
135 path.addEllipse(QPointF(0, 0), m_ellipse.semiMajor(), m_ellipse.semiMinor());
136 drawPath(gc, path, isSnappingActive());
137 }
138}
void drawPath(QPainter &painter, const QPainterPath &path, bool drawActive=true)
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References KisCoordinatesConverter::documentToWidgetTransform(), KisPaintingAssistant::drawPath(), Ellipse::getInverse(), KisPaintingAssistant::handles(), KisPaintingAssistant::isSnappingActive(), m_ellipse, Ellipse::semiMajor(), Ellipse::semiMinor(), and Ellipse::set().

◆ getDefaultEditorPosition()

QPointF ConcentricEllipseAssistant::getDefaultEditorPosition ( ) const
overridevirtual

Implements KisPaintingAssistant.

Definition at line 153 of file ConcentricEllipseAssistant.cc.

154{
155 return (*handles()[0] + *handles()[1]) * 0.5;
156}

References KisPaintingAssistant::handles().

◆ isAssistantComplete()

bool ConcentricEllipseAssistant::isAssistantComplete ( ) const
overridevirtual

determines if the assistant has enough handles to be considered created new assistants get in a "creation" phase where they are currently being made on the canvas it will return false if we are in the middle of creating the assistant.

Reimplemented from KisPaintingAssistant.

Definition at line 158 of file ConcentricEllipseAssistant.cc.

159{
160 return handles().size() >= 3;
161}

References KisPaintingAssistant::handles().

◆ numHandles()

int ConcentricEllipseAssistant::numHandles ( ) const
inlineoverridevirtual

Implements KisPaintingAssistant.

Definition at line 30 of file ConcentricEllipseAssistant.h.

30{ return 3; }

◆ project()

QPointF ConcentricEllipseAssistant::project ( const QPointF & pt,
const QPointF & strokeBegin ) const
private

Definition at line 40 of file ConcentricEllipseAssistant.cc.

41{
42 Q_ASSERT(isAssistantComplete());
43 m_ellipse.set(*handles()[0], *handles()[1], *handles()[2]);
44
45 //calculate ratio
46 QPointF initial = m_ellipse.project(strokeBegin);
47 QPointF center = m_ellipse.boundingRect().center();
48 qreal Ratio = QLineF(center, strokeBegin).length() /QLineF(center, initial).length();
49
50 //calculate the points of the extrapolated ellipse.
51 QLineF extrapolate0 = QLineF(center, *handles()[0]);
52 extrapolate0.setLength(extrapolate0.length()*Ratio);
53 QLineF extrapolate1 = QLineF(center, *handles()[1]);
54 extrapolate1.setLength(extrapolate1.length()*Ratio);
55 QLineF extrapolate2 = QLineF(center, *handles()[2]);
56 extrapolate2.setLength(extrapolate2.length()*Ratio);
57
58 //set the extrapolation ellipse.
59 m_extraEllipse.set(extrapolate0.p2(), extrapolate1.p2(), extrapolate2.p2());
60
61 return m_extraEllipse.project(pt);
62}
static double extrapolate2(struct osn_context *ctx, int xsb, int ysb, double dx, double dy)

References Ellipse::boundingRect(), extrapolate2(), KisPaintingAssistant::handles(), isAssistantComplete(), m_ellipse, m_extraEllipse, Ellipse::project(), and Ellipse::set().

◆ transform()

void ConcentricEllipseAssistant::transform ( const QTransform & transform)
overridevirtual

Transform the assistant using the given transform. Please note that transform should be in 'document' coordinate system. Used with image-wide transformations.

Reimplemented from KisPaintingAssistant.

Definition at line 163 of file ConcentricEllipseAssistant.cc.

164{
165 m_ellipse.set(*handles()[0], *handles()[1], *handles()[2]);
166
167 QPointF newAxes;
168 QTransform newTransform;
169
170 std::tie(newAxes, newTransform) = KisAlgebra2D::transformEllipse(QPointF(m_ellipse.semiMajor(), m_ellipse.semiMinor()), m_ellipse.getInverse() * transform);
171
172 const QPointF p1 = newTransform.map(QPointF(newAxes.x(), 0));
173 const QPointF p2 = newTransform.map(QPointF(-newAxes.x(), 0));
174 const QPointF p3 = newTransform.map(QPointF(0, newAxes.y()));
175
176 *handles()[0] = p1;
177 *handles()[1] = p2;
178 *handles()[2] = p3;
179
180 uncache();
181}
QPointF p2
QPointF p3
QPointF p1
void transform(const QTransform &transform) override
std::pair< QPointF, QTransform > transformEllipse(const QPointF &axes, const QTransform &fullLocalToGlobal)

References Ellipse::getInverse(), KisPaintingAssistant::handles(), m_ellipse, p1, p2, p3, Ellipse::semiMajor(), Ellipse::semiMinor(), Ellipse::set(), transform(), KisAlgebra2D::transformEllipse(), and KisPaintingAssistant::uncache().

Member Data Documentation

◆ m_ellipse

Ellipse ConcentricEllipseAssistant::m_ellipse
mutableprivate

Definition at line 42 of file ConcentricEllipseAssistant.h.

◆ m_extraEllipse

Ellipse ConcentricEllipseAssistant::m_extraEllipse
mutableprivate

Definition at line 43 of file ConcentricEllipseAssistant.h.


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