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

#include <ParallelRulerAssistant.h>

+ Inheritance diagram for ParallelRulerAssistant:

Public Member Functions

void adjustLine (QPointF &point, QPointF &strokeBegin) override
 
QPointF adjustPosition (const QPointF &point, const QPointF &strokeBegin, const bool snapToAny, qreal moveThresholdPt) override
 
bool canBeLocal () const override
 canBeLocal
 
KisPaintingAssistantSP clone (QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap) const override
 
QPointF getDefaultEditorPosition () const override
 
bool isAssistantComplete () const override
 
bool loadCustomXml (QXmlStreamReader *xml) override
 
int numHandles () const override
 
 ParallelRulerAssistant ()
 
void saveCustomXml (QXmlStreamWriter *xml) 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
 
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
 
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
 
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
 
virtual void transform (const QTransform &transform)
 
void uncache ()
 
bool useCustomColor ()
 
QPointF viewportConstrainedEditorPosition (const KisCoordinatesConverter *converter, const QSize editorSize)
 
virtual ~KisPaintingAssistant ()
 

Protected Member Functions

void drawAssistant (QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, bool cached=true, KisCanvas2 *canvas=0, 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
 
KisPaintingAssistantHandleSP firstLocalHandle () const override
 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.
 
KisPaintingAssistantHandleSP secondLocalHandle () const override
 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)
 
- Protected Member Functions inherited from KisPaintingAssistant
virtual QRect boundingRect () const
 
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().
 
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
 

Private Member Functions

 ParallelRulerAssistant (const ParallelRulerAssistant &rhs, QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap)
 
QPointF project (const QPointF &pt, const QPointF &strokeBegin, qreal moveThresholdPt)
 

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 20 of file ParallelRulerAssistant.h.

Constructor & Destructor Documentation

◆ ParallelRulerAssistant() [1/2]

ParallelRulerAssistant::ParallelRulerAssistant ( )

Definition at line 27 of file ParallelRulerAssistant.cc.

28 : KisPaintingAssistant("parallel ruler", i18n("Parallel Ruler assistant"))
29{
30}
KisPaintingAssistant(const QString &id, const QString &name)

◆ ParallelRulerAssistant() [2/2]

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

Definition at line 37 of file ParallelRulerAssistant.cc.

38 : KisPaintingAssistant(rhs, handleMap)
39{
40}

Member Function Documentation

◆ adjustLine()

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

Implements KisPaintingAssistant.

Definition at line 77 of file ParallelRulerAssistant.cc.

78{
79 point = project(point, strokeBegin, 0.0);
80}
QPointF project(const QPointF &pt, const QPointF &strokeBegin, qreal moveThresholdPt)

References project().

◆ adjustPosition()

QPointF ParallelRulerAssistant::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 72 of file ParallelRulerAssistant.cc.

73{
74 return project(pt, strokeBegin, moveThresholdPt);
75}

References project().

◆ canBeLocal()

bool ParallelRulerAssistant::canBeLocal ( ) const
overridevirtual

canBeLocal

Returns
if the assistant can be potentially a "local assistant" (limited to rectangular area) or not

Reimplemented from KisPaintingAssistant.

Definition at line 180 of file ParallelRulerAssistant.cc.

181{
182 return true;
183}

◆ clone()

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

Implements KisPaintingAssistant.

Definition at line 32 of file ParallelRulerAssistant.cc.

33{
34 return KisPaintingAssistantSP(new ParallelRulerAssistant(*this, handleMap));
35}
QSharedPointer< KisPaintingAssistant > KisPaintingAssistantSP
Definition kis_types.h:189

References ParallelRulerAssistant().

◆ drawAssistant()

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

Reimplemented from KisPaintingAssistant.

Definition at line 82 of file ParallelRulerAssistant.cc.

83{
84 gc.save();
85 gc.resetTransform();
86
87 QTransform initialTransform = converter->documentToWidgetTransform();
88 QRectF local = getLocalRect();
89 QRectF localTransformed = initialTransform.mapRect(local);
90 const QRect viewport= gc.viewport();
91 QPolygonF viewportAndLocal = !localTransformed.isEmpty() ? QPolygonF(QRectF(viewport)).intersected(localTransformed) : QRectF(viewport);
92
93
94
95 if (assistantVisible && isLocal() && isAssistantComplete()) {
96 QPainterPath path;
97 // note: be careful; bottom and right only work with RectF, not Rect
98 path.moveTo(initialTransform.map(local.topLeft()));
99
100 path.lineTo(initialTransform.map(local.topRight()));
101 path.lineTo(initialTransform.map(local.bottomRight()));
102 path.lineTo(initialTransform.map(local.bottomLeft()));
103 path.lineTo(initialTransform.map(local.topLeft()));
104 drawPath(gc, path, isSnappingActive());//and we draw the preview.
105 }
106
107
108 if (isAssistantComplete() && isSnappingActive() && previewVisible==true) {
109 //don't draw if invalid.
110 QLineF snapLine= QLineF(initialTransform.map(*handles()[0]), initialTransform.map(*handles()[1]));
111
112 QPointF mousePos = effectiveBrushPosition(converter, canvas);
113
114 QPointF translation = (initialTransform.map(*handles()[0])-mousePos)*-1.0;
115 snapLine= snapLine.translated(translation);
116
117 KisAlgebra2D::cropLineToConvexPolygon(snapLine, viewportAndLocal, true, true);
118
119
120 QPainterPath path;
121 path.moveTo(snapLine.p1());
122 path.lineTo(snapLine.p2());
123
124 drawPreview(gc, path);//and we draw the preview.
125 }
126 gc.restore();
127
128 KisPaintingAssistant::drawAssistant(gc, updateRect, converter, cached, canvas, assistantVisible, previewVisible);
129
130}
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 drawPath(QPainter &painter, const QPainterPath &path, bool drawActive=true)
void drawPreview(QPainter &painter, const QPainterPath &path)
QRectF getLocalRect() const
getLocalRect The function deals with local handles not being topLeft and bottomRight gracefully and r...
virtual void drawAssistant(QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, bool cached, KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true)
const QList< KisPaintingAssistantHandleSP > & handles() const
bool isAssistantComplete() const override
void cropLineToConvexPolygon(QLineF &line, const QPolygonF polygon, bool extendFirst, bool extendSecond)

References KisAlgebra2D::cropLineToConvexPolygon(), KisCoordinatesConverter::documentToWidgetTransform(), KisPaintingAssistant::drawAssistant(), KisPaintingAssistant::drawPath(), KisPaintingAssistant::drawPreview(), KisPaintingAssistant::effectiveBrushPosition(), KisPaintingAssistant::getLocalRect(), KisPaintingAssistant::handles(), isAssistantComplete(), KisPaintingAssistant::isLocal(), and KisPaintingAssistant::isSnappingActive().

◆ drawCache()

void ParallelRulerAssistant::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 132 of file ParallelRulerAssistant.cc.

133{
134 if (assistantVisible == false || handles().size() < 2) {
135 return;
136 }
137
138 QTransform initialTransform = converter->documentToWidgetTransform();
139
140 // Draw the line
141 QPointF p1 = *handles()[0];
142 QPointF p2 = *handles()[1];
143
144 gc.setTransform(initialTransform);
145 QPainterPath path;
146 path.moveTo(p1);
147 path.lineTo(p2);
148 drawPath(gc, path, isSnappingActive());
149
150}
QPointF p2
QPointF p1
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References KisCoordinatesConverter::documentToWidgetTransform(), KisPaintingAssistant::drawPath(), KisPaintingAssistant::handles(), KisPaintingAssistant::isSnappingActive(), p1, and p2.

◆ firstLocalHandle()

KisPaintingAssistantHandleSP ParallelRulerAssistant::firstLocalHandle ( ) const
overrideprotectedvirtual

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.

Returns
the first handle of the rectangle of the limited area

Reimplemented from KisPaintingAssistant.

Definition at line 152 of file ParallelRulerAssistant.cc.

153{
154 return handles().size() > 2 ? handles()[2] : 0;
155}

References KisPaintingAssistant::handles().

◆ getDefaultEditorPosition()

QPointF ParallelRulerAssistant::getDefaultEditorPosition ( ) const
overridevirtual

Implements KisPaintingAssistant.

Definition at line 162 of file ParallelRulerAssistant.cc.

163{
164 if (handles().size() > 1) {
165 return (*handles()[0] + *handles()[1]) * 0.5;
166 } else if (handles().size() > 0) {
168 return *handles()[0];
169 } else {
170 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(false, QPointF(0, 0));
171 return QPointF(0, 0);
172 }
173}
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KisPaintingAssistant::handles(), and KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE.

◆ isAssistantComplete()

bool ParallelRulerAssistant::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 175 of file ParallelRulerAssistant.cc.

176{
177 return handles().size() >= numHandles();
178}
int numHandles() const override

References KisPaintingAssistant::handles(), and numHandles().

◆ loadCustomXml()

bool ParallelRulerAssistant::loadCustomXml ( QXmlStreamReader * xml)
overridevirtual

Reimplemented from KisPaintingAssistant.

Definition at line 192 of file ParallelRulerAssistant.cc.

193{
194 if (xml && xml->name() == "isLocal") {
195 this->setLocal((bool)KisDomUtils::toInt(xml->attributes().value("value").toString()));
196 }
197 return true;
198}
void setLocal(bool value)
setLocal
int toInt(const QString &str, bool *ok=nullptr)

References KisPaintingAssistant::setLocal(), and KisDomUtils::toInt().

◆ numHandles()

int ParallelRulerAssistant::numHandles ( ) const
inlineoverridevirtual

Implements KisPaintingAssistant.

Definition at line 28 of file ParallelRulerAssistant.h.

28{ return isLocal() ? 4 : 2; }

References KisPaintingAssistant::isLocal().

◆ project()

QPointF ParallelRulerAssistant::project ( const QPointF & pt,
const QPointF & strokeBegin,
qreal moveThresholdPt )
private

Definition at line 42 of file ParallelRulerAssistant.cc.

43{
44 Q_ASSERT(isAssistantComplete());
45
46 if (isLocal() && isAssistantComplete()) {
47 if (getLocalRect().contains(pt)) {
49 } else if (isLocal() && !m_hasBeenInsideLocalRect) {
50 return QPointF(qQNaN(), qQNaN());
51 }
52 }
53
54 //dbgKrita<<strokeBegin<< ", " <<*handles()[0];
55 QLineF snapLine = QLineF(*handles()[0], *handles()[1]);
56 QPointF translation = (*handles()[0]-strokeBegin)*-1.0;
57 snapLine = snapLine.translated(translation);
58
59 qreal dx = snapLine.dx();
60 qreal dy = snapLine.dy();
61
62 const qreal
63 dx2 = dx * dx,
64 dy2 = dy * dy,
65 invsqrlen = 1.0 / (dx2 + dy2);
66 QPointF r(dx2 * pt.x() + dy2 * snapLine.x1() + dx * dy * (pt.y() - snapLine.y1()),
67 dx2 * snapLine.y1() + dy2 * pt.y() + dx * dy * (pt.x() - snapLine.x1()));
68 r *= invsqrlen;
69 return r;
70}

References KisPaintingAssistant::getLocalRect(), KisPaintingAssistant::handles(), isAssistantComplete(), KisPaintingAssistant::isLocal(), and KisPaintingAssistant::m_hasBeenInsideLocalRect.

◆ saveCustomXml()

void ParallelRulerAssistant::saveCustomXml ( QXmlStreamWriter * xml)
overridevirtual

Reimplemented from KisPaintingAssistant.

Definition at line 185 of file ParallelRulerAssistant.cc.

186{
187 xml->writeStartElement("isLocal");
188 xml->writeAttribute("value", KisDomUtils::toString( (int)this->isLocal()));
189 xml->writeEndElement();
190}
QString toString(const QString &value)

References KisPaintingAssistant::isLocal(), and KisDomUtils::toString().

◆ secondLocalHandle()

KisPaintingAssistantHandleSP ParallelRulerAssistant::secondLocalHandle ( ) const
overrideprotectedvirtual

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)

Returns

Reimplemented from KisPaintingAssistant.

Definition at line 157 of file ParallelRulerAssistant.cc.

158{
159 return handles().size() > 3 ? handles()[3] : 0;
160}

References KisPaintingAssistant::handles().


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