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

#include <EllipseAssistant.h>

+ Inheritance diagram for EllipseAssistant:

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
 
 EllipseAssistant ()
 
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

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

Private Attributes

Ellipse e
 

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 16 of file EllipseAssistant.h.

Constructor & Destructor Documentation

◆ EllipseAssistant() [1/2]

EllipseAssistant::EllipseAssistant ( )

Definition at line 24 of file EllipseAssistant.cc.

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

◆ EllipseAssistant() [2/2]

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

Definition at line 29 of file EllipseAssistant.cc.

30 : KisPaintingAssistant(rhs, handleMap)
31 , e(rhs.e)
32{
33}

Member Function Documentation

◆ adjustLine()

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

Implements KisPaintingAssistant.

Definition at line 53 of file EllipseAssistant.cc.

54{
55 const QPointF p1 = point;
56 const QPointF p2 = strokeBegin;
57
58 Q_ASSERT(isAssistantComplete());
59 e.set(*handles()[0], *handles()[1], *handles()[2]);
60
61 QPointF p3 = e.project(p1);
62 QPointF p4 = e.project(p2);
63 point = p3;
64 strokeBegin = p4;
65}
QPointF p2
QPointF p3
QPointF p1
bool isAssistantComplete() const override
bool set(const QPointF &m1, const QPointF &m2, const QPointF &p)
Definition Ellipse.cc:23
QPointF project(const QPointF &) const
Definition Ellipse.cc:39
const QList< KisPaintingAssistantHandleSP > & handles() const

References e, KisPaintingAssistant::handles(), isAssistantComplete(), p1, p2, p3, Ellipse::project(), and Ellipse::set().

◆ adjustPosition()

QPointF EllipseAssistant::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 47 of file EllipseAssistant.cc.

48{
49 return project(pt);
50
51}
QPointF project(const QPointF &pt) const

References project().

◆ boundingRect()

QRect EllipseAssistant::boundingRect ( ) const
overrideprotectedvirtual

Reimplemented from KisPaintingAssistant.

Definition at line 139 of file EllipseAssistant.cc.

140{
141 if (!isAssistantComplete()) {
143 }
144
145 if (e.set(*handles()[0], *handles()[1], *handles()[2])) {
146 return e.boundingRect().adjusted(-2, -2, 2, 2).toAlignedRect();
147 } else {
148 return QRect();
149 }
150}
QRectF boundingRect() const
Definition Ellipse.cc:62
virtual QRect boundingRect() const

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

◆ clone()

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

Implements KisPaintingAssistant.

Definition at line 35 of file EllipseAssistant.cc.

36{
37 return KisPaintingAssistantSP(new EllipseAssistant(*this, handleMap));
38}
QSharedPointer< KisPaintingAssistant > KisPaintingAssistantSP
Definition kis_types.h:189

References EllipseAssistant().

◆ drawAssistant()

void EllipseAssistant::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 67 of file EllipseAssistant.cc.

68{
69 gc.save();
70 gc.resetTransform();
71 QPoint mousePos;
72
73 if (canvas){
74 //simplest, cheapest way to get the mouse-position//
75 mousePos= canvas->canvasWidget()->mapFromGlobal(QCursor::pos());
76 }
77 else {
78 //...of course, you need to have access to a canvas-widget for that.//
79 mousePos = QCursor::pos();//this'll give an offset//
80 dbgFile<<"canvas does not exist in the ellipse assistant, you may have passed arguments incorrectly:"<<canvas;
81 }
82
83 QTransform initialTransform = converter->documentToWidgetTransform();
84
85 if (isSnappingActive() && boundingRect().contains(initialTransform.inverted().map(mousePos), false) && previewVisible==true){
86
88 if (e.set(*handles()[0], *handles()[1], *handles()[2])) {
89 // valid ellipse
90 gc.setTransform(initialTransform);
91 gc.setTransform(e.getInverse(), true);
92 QPainterPath path;
93 //path.moveTo(QPointF(-e.semiMajor(), 0)); path.lineTo(QPointF(e.semiMajor(), 0));
94 //path.moveTo(QPointF(0, -e.semiMinor())); path.lineTo(QPointF(0, e.semiMinor()));
95 // Draw the ellipse
96 path.addEllipse(QPointF(0, 0), e.semiMajor(), e.semiMinor());
97 drawPreview(gc, path);
98 }
99 }
100 }
101 gc.restore();
102 KisPaintingAssistant::drawAssistant(gc, updateRect, converter, cached, canvas, assistantVisible, previewVisible);
103
104}
QRect boundingRect() const override
qreal semiMajor() const
Definition Ellipse.h:33
const QTransform & getInverse() const
Definition Ellipse.h:32
qreal semiMinor() const
Definition Ellipse.h:34
KisAbstractCanvasWidget * canvasWidget
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)
#define dbgFile
Definition kis_debug.h:53

References boundingRect(), KisCanvas2::canvasWidget, dbgFile, KisCoordinatesConverter::documentToWidgetTransform(), KisPaintingAssistant::drawAssistant(), KisPaintingAssistant::drawPreview(), e, Ellipse::getInverse(), KisPaintingAssistant::handles(), isAssistantComplete(), KisPaintingAssistant::isSnappingActive(), Ellipse::semiMajor(), Ellipse::semiMinor(), and Ellipse::set().

◆ drawCache()

void EllipseAssistant::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 107 of file EllipseAssistant.cc.

108{
109
110 if (assistantVisible == false || handles().size() < 2){
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 if (e.set(*handles()[0], *handles()[1], *handles()[2])) {
126 // valid ellipse
127
128 gc.setTransform(initialTransform);
129 gc.setTransform(e.getInverse(), true);
130 QPainterPath path;
131 path.moveTo(QPointF(-e.semiMajor(), 0)); path.lineTo(QPointF(e.semiMajor(), 0));
132 path.moveTo(QPointF(0, -e.semiMinor())); path.lineTo(QPointF(0, e.semiMinor()));
133 // Draw the ellipse
134 path.addEllipse(QPointF(0, 0), e.semiMajor(), e.semiMinor());
135 drawPath(gc, path, isSnappingActive());
136 }
137}
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(), e, Ellipse::getInverse(), KisPaintingAssistant::handles(), KisPaintingAssistant::isSnappingActive(), Ellipse::semiMajor(), Ellipse::semiMinor(), and Ellipse::set().

◆ getDefaultEditorPosition()

QPointF EllipseAssistant::getDefaultEditorPosition ( ) const
overridevirtual

Implements KisPaintingAssistant.

Definition at line 152 of file EllipseAssistant.cc.

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

References KisPaintingAssistant::handles().

◆ isAssistantComplete()

bool EllipseAssistant::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 157 of file EllipseAssistant.cc.

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

References KisPaintingAssistant::handles().

◆ numHandles()

int EllipseAssistant::numHandles ( ) const
inlineoverridevirtual

Implements KisPaintingAssistant.

Definition at line 24 of file EllipseAssistant.h.

24{ return 3; }

◆ project()

QPointF EllipseAssistant::project ( const QPointF & pt) const
private

Definition at line 40 of file EllipseAssistant.cc.

41{
42 Q_ASSERT(isAssistantComplete());
43 e.set(*handles()[0], *handles()[1], *handles()[2]);
44 return e.project(pt);
45}

References e, KisPaintingAssistant::handles(), isAssistantComplete(), Ellipse::project(), and Ellipse::set().

◆ transform()

void EllipseAssistant::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 162 of file EllipseAssistant.cc.

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

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

Member Data Documentation

◆ e

Ellipse EllipseAssistant::e
mutableprivate

Definition at line 36 of file EllipseAssistant.h.


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