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

#include <TwoPointAssistant.h>

+ Inheritance diagram for TwoPointAssistant:

Public Types

enum  TwoPointHandle {
  FirstHandle , SecondHandle , VerticalHandle , LocalFirstHandle ,
  LocalSecondHandle
}
 

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
 
bool contains (const QPointF &point) const override
 
qreal distance (const QPointF &point) const override
 
void endStroke () override
 
QPointF getDefaultEditorPosition () const override
 
double gridDensity ()
 
bool isActive () const override
 
bool isAssistantComplete () const override
 
bool loadCustomXml (QXmlStreamReader *xml) override
 
QTransform localTransform (QPointF vp_a, QPointF vp_b, QPointF pt_c, qreal *size) const
 
int numHandles () const override
 
void saveCustomXml (QXmlStreamWriter *xml) override
 
void setGridDensity (double density)
 
void setUseVertical (bool value)
 
 TwoPointAssistant ()
 
bool useVertical ()
 
- Public Member Functions inherited from KisAbstractPerspectiveGrid
 KisAbstractPerspectiveGrid (QObject *parent=0)
 
 ~KisAbstractPerspectiveGrid () 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
 
int brushPriority () const
 
KisPaintingAssistantHandleSP closestCornerHandleFromPoint (QPointF point)
 
void copySharedData (KisPaintingAssistantSP assistant)
 
void drawError (QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface)
 
void drawPath (QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface, bool drawActive=true, QPen startingPen=QPen())
 
void drawPreview (QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface)
 
void drawX (QPainter &painter, const QPointF &pt, const KoColorDisplayRendererInterface *displayRenderInterface)
 
QPointF editorWidgetOffset ()
 
QColor effectiveAssistantColor () const
 
void findPerspectiveAssistantHandleLocation ()
 
virtual QPointF getEditorPosition () const
 
QList< KisPaintingAssistantHandleSP > handles ()
 
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 setBrushPriority (int priority)
 
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< KisPaintingAssistantHandleSP > sideHandles ()
 
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, const KoColorDisplayRendererInterface *displayRenderInterface, bool cached=true, KisCanvas2 *canvas=nullptr, bool assistantVisible=true, bool previewVisible=true) override
 
void drawCache (QPainter &gc, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *displayRenderInterface, 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

bool localPerspectiveData (const QPointF &point, QPointF *localPoint, qreal *size) const
 
QPointF project (const QPointF &pt, const QPointF &strokeBegin, const bool snapToAny, qreal moveThreshold)
 
 TwoPointAssistant (const TwoPointAssistant &rhs, QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap)
 

Private Attributes

KisCanvas2 * m_canvas {nullptr}
 
double m_gridDensity {1.0}
 
int m_lastUsedPoint {-1}
 
QLineF m_snapLine
 
bool m_useVertical {true}
 

Additional Inherited Members

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

Detailed Description

Definition at line 18 of file TwoPointAssistant.h.

Member Enumeration Documentation

◆ TwoPointHandle

Enumerator
FirstHandle 
SecondHandle 
VerticalHandle 
LocalFirstHandle 
LocalSecondHandle 

Definition at line 23 of file TwoPointAssistant.h.

Constructor & Destructor Documentation

◆ TwoPointAssistant() [1/2]

TwoPointAssistant::TwoPointAssistant ( )

Definition at line 28 of file TwoPointAssistant.cc.

30 , KisPaintingAssistant("two point", i18n("Two point assistant"))
31{
32}
KisPaintingAssistant(const QString &id, const QString &name)

◆ TwoPointAssistant() [2/2]

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

Member Function Documentation

◆ adjustLine()

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

Implements KisPaintingAssistant.

Definition at line 149 of file TwoPointAssistant.cc.

150{
151 QPointF p = project(point, strokeBegin, true, 0.0);
152 point = p;
153}
const Params2D p
QPointF project(const QPointF &pt, const QPointF &strokeBegin, const bool snapToAny, qreal moveThreshold)

References p, and project().

◆ adjustPosition()

QPointF TwoPointAssistant::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 144 of file TwoPointAssistant.cc.

145{
146 return project(pt, strokeBegin, snapToAny, moveThresholdPt);
147}

References project().

◆ canBeLocal()

bool TwoPointAssistant::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 490 of file TwoPointAssistant.cc.

491{
492 return true;
493}

◆ clone()

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

Implements KisPaintingAssistant.

Definition at line 45 of file TwoPointAssistant.cc.

46{
47 return KisPaintingAssistantSP(new TwoPointAssistant(*this, handleMap));
48}
QSharedPointer< KisPaintingAssistant > KisPaintingAssistantSP
Definition kis_types.h:189

References TwoPointAssistant().

◆ contains()

bool TwoPointAssistant::contains ( const QPointF & point) const
overridevirtual

Implements KisAbstractPerspectiveGrid.

Definition at line 528 of file TwoPointAssistant.cc.

529{
530 QPointF localPoint;
531 qreal size = 0.0;
532
533 if (!localPerspectiveData(point, &localPoint, &size)) {
534 return false;
535 }
536
537 if (isLocal() && handles().size() == numHandles() && !getLocalRect().contains(point)) {
538 return false;
539 }
540
541 const qreal distanceToHorizon = qAbs(localPoint.y());
542 // Rotation can move a point on the inclusive boundary just outside it.
543 return distanceToHorizon <= size || qFuzzyCompare(distanceToHorizon, size);
544}
QRectF getLocalRect() const
getLocalRect The function deals with local handles not being topLeft and bottomRight gracefully and r...
const QList< KisPaintingAssistantHandleSP > & handles() const
bool localPerspectiveData(const QPointF &point, QPointF *localPoint, qreal *size) const
bool contains(const QPointF &point) const override
int numHandles() const override
static bool qFuzzyCompare(half p1, half p2)
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References contains(), KisPaintingAssistant::getLocalRect(), KisPaintingAssistant::handles(), KisPaintingAssistant::isLocal(), localPerspectiveData(), numHandles(), and qFuzzyCompare().

◆ distance()

qreal TwoPointAssistant::distance ( const QPointF & pt) const
overridevirtual

Returns the reciprocal of the distance from the given point to the 'observer', in the range [0, 1] where 0 = infinite distance and 1 = closest.

Implements KisAbstractPerspectiveGrid.

Definition at line 546 of file TwoPointAssistant.cc.

547{
548 QPointF localPoint;
549 qreal size = 0.0;
550
551 if (!localPerspectiveData(point, &localPoint, &size)) {
552 return 1.0;
553 }
554
555 return qBound<qreal>(0.0, qAbs(localPoint.y()) / size, 1.0);
556}

References localPerspectiveData().

◆ drawAssistant()

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

Reimplemented from KisPaintingAssistant.

Definition at line 155 of file TwoPointAssistant.cc.

156{
157 Q_UNUSED(updateRect);
158 Q_UNUSED(cached);
159 gc.save();
160 gc.resetTransform();
161
162 const QColor canvasAssistantColor = displayRenderInterface->convertColorToDisplayColorSpace(KoColor(effectiveAssistantColor(), KoColorSpaceRegistry::instance()->rgb8()));
163
164 const QTransform initialTransform = converter->documentToWidgetTransform();
165 bool isEditing = false;
166 bool showLocal = isLocal() && handles().size() == 5;
167
168 if (canvas) {
169 isEditing = canvas->paintingAssistantsDecoration()->isEditingAssistants();
170 }
171
172 if (isEditing) {
173 Q_FOREACH (const QPointF* handle, handles()) {
174 QPointF h = initialTransform.map(*handle);
175 QRectF ellipse = QRectF(QPointF(h.x() -15, h.y() -15), QSizeF(30, 30));
176
177 QPainterPath pathCenter;
178 pathCenter.addEllipse(ellipse);
179 drawPath(gc, pathCenter, displayRenderInterface, isSnappingActive());
180
181 // Draw circle to represent center of vision
182 if (handles().length() == 3 && handle == handles()[2]) {
183 const QLineF horizon = QLineF(*handles()[0],*handles()[1]);
184 QLineF normal = horizon.normalVector();
185 normal.translate(*handles()[2]-normal.p1());
186 QPointF cov = horizon.center();
187 normal.intersects(horizon,&cov);
188 const QPointF center = initialTransform.map(cov);
189 QRectF center_ellipse = QRectF(QPointF(center.x() -15, center.y() -15), QSizeF(30, 30));
190 QPainterPath pathCenter;
191 pathCenter.addEllipse(center_ellipse);
192 drawPath(gc, pathCenter, displayRenderInterface, isSnappingActive());
193 }
194 }
195
196 if (handles().size() <= 2) {
197 QPainterPath path;
198 int tempDensity = m_gridDensity * 10; // the vanishing point density seems visibly more dense, hence let's make it less dense
199 QRect viewport = gc.viewport();
200
201 for (int i = 0; i < handles().size(); i++) {
202 const QPointF p = initialTransform.map(*handles()[i]);
203 for (int currentAngle=0; currentAngle <= 180; currentAngle = currentAngle + tempDensity) {
204
205 // determine the correct angle based on the iteration
206 float xPos = cos(currentAngle * M_PI / 180);
207 float yPos = sin(currentAngle * M_PI / 180);
208 float length = 100;
209 QPointF unit = QPointF(length*xPos, length*yPos);
210
211 // find point
212 QLineF snapLine = QLineF(p, p + unit);
213 if (KisAlgebra2D::intersectLineRect(snapLine, viewport, false)) {
214 // make a line from VP center to edge of canvas with that angle
215
216 path.moveTo(snapLine.p1());
217 path.lineTo(snapLine.p2());
218 }
219
220 QLineF snapLine2 = QLineF(p, p - unit);
221 if (KisAlgebra2D::intersectLineRect(snapLine2, viewport, false)) {
222 // make a line from VP center to edge of canvas with that angle
223
224 path.moveTo(snapLine2.p1());
225 path.lineTo(snapLine2.p2());
226 }
227
228
229 }
230
231 drawPreview(gc, path, displayRenderInterface);//and we draw the preview.
232
233 }
234 }
235
236 }
237
238 if (handles().size() >= 2) {
239 QPointF mousePos = effectiveBrushPosition(converter, canvas);
240 const QPointF p1 = *handles()[0];
241 const QPointF p2 = *handles()[1];
242 const QRect viewport= gc.viewport();
243
244 const QPolygonF localPoly = (isLocal() && handles().size() == 5) ? initialTransform.map(QPolygonF(getLocalRect())) : QPolygonF();
245 const QPolygonF viewportAndLocalPoly = !localPoly.isEmpty() ? QPolygonF(QRectF(viewport)).intersected(localPoly) : QRectF(viewport);
246
247
248 QPainterPath path;
249 QPainterPath previewPath; // part of the preview, instead of the assistant itself
250
251 // draw the horizon
252 if (assistantVisible == true || isEditing == true) {
253 QLineF horizonLine = initialTransform.map(QLineF(p1,p2));
254 KisAlgebra2D::cropLineToConvexPolygon(horizonLine, viewportAndLocalPoly, true, true);
255 path.moveTo(horizonLine.p1());
256 path.lineTo(horizonLine.p2());
257 }
258
259 // draw the VP-->mousePos lines
260 if (isEditing == false && previewVisible == true && isSnappingActive() == true) {
261 // draw the line vp <-> mouse even outside of the local rectangle
262 // but only if the mouse pos is inside the rectangle
263 QLineF snapMouse1 = QLineF(initialTransform.map(p1), mousePos);
264 QLineF snapMouse2 = QLineF(initialTransform.map(p2), mousePos);
265 KisAlgebra2D::cropLineToConvexPolygon(snapMouse1, viewportAndLocalPoly, false, true);
266 KisAlgebra2D::cropLineToConvexPolygon(snapMouse2, viewportAndLocalPoly, false, true);
267 previewPath.moveTo(snapMouse1.p1());
268 previewPath.lineTo(snapMouse1.p2());
269 previewPath.moveTo(snapMouse2.p1());
270 previewPath.lineTo(snapMouse2.p2());
271 }
272
273 // draw the side handle bars
274 if (isEditing == true && !sideHandles().isEmpty()) {
275 path.moveTo(initialTransform.map(p1));
276 path.lineTo(initialTransform.map(*sideHandles()[0]));
277 path.lineTo(initialTransform.map(*sideHandles()[1]));
278 path.moveTo(initialTransform.map(p2));
279 path.lineTo(initialTransform.map(*sideHandles()[2]));
280 path.lineTo(initialTransform.map(*sideHandles()[3]));
281 path.moveTo(initialTransform.map(p1));
282 path.lineTo(initialTransform.map(*sideHandles()[4]));
283 path.lineTo(initialTransform.map(*sideHandles()[5]));
284 path.moveTo(initialTransform.map(p2));
285 path.lineTo(initialTransform.map(*sideHandles()[6]));
286 path.lineTo(initialTransform.map(*sideHandles()[7]));
287 }
288
289 // draw the local rectangle
290 if (showLocal && assistantVisible) {
291 QPointF p1 = *handles()[(int)LocalFirstHandle];
292 QPointF p3 = *handles()[(int)LocalSecondHandle];
293 QPointF p2 = QPointF(p1.x(), p3.y());
294 QPointF p4 = QPointF(p3.x(), p1.y());
295
296 path.moveTo(initialTransform.map(p1));
297
298 path.lineTo(initialTransform.map(p2));
299 path.lineTo(initialTransform.map(p3));
300 path.lineTo(initialTransform.map(p4));
301 path.lineTo(initialTransform.map(p1));
302 }
303
304
305 drawPreview(gc,previewPath, displayRenderInterface);
306 drawPath(gc, path, displayRenderInterface, isSnappingActive());
307
308 if (handles().size() >= 3 && isSnappingActive()) {
309 path = QPainterPath(); // clear
310 const QPointF p3 = *handles()[2];
311
312 qreal size = 0;
313 const QTransform t = localTransform(p1,p2,p3,&size);
314 const QTransform inv = t.inverted();
315 const QPointF vp_a = t.map(p1);
316 const QPointF vp_b = t.map(p2);
317
318 if ((vp_a.x() < 0 && vp_b.x() > 0) ||
319 (vp_a.x() > 0 && vp_b.x() < 0)) {
320 if (m_useVertical) {
321 // Draw vertical line, but only if the center is between both VPs
322 QLineF vertical = initialTransform.map(inv.map(QLineF::fromPolar(1,90)));
323 if (!isEditing) vertical.translate(mousePos - vertical.p1());
324 KisAlgebra2D::cropLineToConvexPolygon(vertical, viewportAndLocalPoly, true, true);
325 if (previewVisible) {
326 path.moveTo(vertical.p1());
327 path.lineTo(vertical.p2());
328 }
329
330 if (assistantVisible) {
331 // Display a notch to represent the center of vision
332 path.moveTo(initialTransform.map(inv.map(QPointF(0,-10))));
333 path.lineTo(initialTransform.map(inv.map(QPointF(0,10))));
334 }
335 drawPreview(gc,path, displayRenderInterface);
336 path = QPainterPath(); // clear
337 }
338 }
339
340 const QPointF upper = QPointF(0, size);
341 const QPointF lower = QPointF(0, -size);
342
343 // Set up the fading effect for the grid lines
344 // Needed so the grid density doesn't look distracting
345 QColor color = canvasAssistantColor;
346 QGradient fade = QLinearGradient(initialTransform.map(inv.map(upper)),
347 initialTransform.map(inv.map(lower)));
348 color.setAlphaF(0);
349 fade.setColorAt(0.4, canvasAssistantColor);
350 fade.setColorAt(0.5, color);
351 fade.setColorAt(0.6, canvasAssistantColor);
352 const QPen pen = gc.pen();
353 const QBrush new_brush = QBrush(fade);
354 int width = 1;
355 const QPen new_pen = QPen(new_brush, width, pen.style());
356 gc.setPen(new_pen);
357
358 const QList<QPointF> station_points = {upper, lower};
359 const QList<QPointF> vanishing_points = {vp_a, vp_b};
360
361 // Draw grid lines above and below the horizon
362 Q_FOREACH (const QPointF sp, station_points) {
363
364 // Draw grid lines towards each vanishing point
365 Q_FOREACH (const QPointF vp, vanishing_points) {
366
367 // Interval between each grid line, uses grid density specified by user
368 const qreal initial_angle = QLineF(sp, vp).angle();
369 const qreal interval = size*m_gridDensity / cos((initial_angle - 90) * M_PI/180);
370 const QPointF translation = QPointF(interval, 0);
371
372 // Draw grid lines originating from both the left and right of the central vertical line
373 Q_FOREACH (const int dir, QList<int>({-1, 1})) {
374
375 // Limit at 300 grid lines per direction, reasonable even for m_gridDensity=0.1;
376 for (int i = 0; i <= 300; i++) {
377 const QLineF gridline = QLineF(sp + translation * i * dir, vp);
378
379 // Don't bother drawing lines that are nearly parallel to horizon
380 const qreal angle = gridline.angle();
381 if (angle < 0.25 || angle > 359.75 || (angle < 180.25 && angle > 179.75)) {
382 break;
383 }
384
385 QLineF drawn_gridline = initialTransform.map(inv.map(gridline));
386 KisAlgebra2D::cropLineToConvexPolygon(drawn_gridline, viewportAndLocalPoly, true, false);
387
388 if (assistantVisible || isEditing == true) {
389 path.moveTo(drawn_gridline.p2());
390 path.lineTo(drawn_gridline.p1());
391 }
392 }
393 }
394 }
395 }
396 gc.drawPath(path);
397 }
398 }
399
400 gc.restore();
401 //KisPaintingAssistant::drawAssistant(gc, updateRect, converter, cached, canvas, assistantVisible, previewVisible);
402}
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
QPointF p2
QPointF p3
QPointF p1
KisPaintingAssistantsDecorationSP paintingAssistantsDecoration() 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 pain...
void drawPreview(QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface)
const QList< KisPaintingAssistantHandleSP > & sideHandles() const
void drawPath(QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface, bool drawActive=true, QPen startingPen=QPen())
virtual QColor convertColorToDisplayColorSpace(const KoColor color) const =0
convertColorToDisplayColorSpace
QTransform localTransform(QPointF vp_a, QPointF vp_b, QPointF pt_c, qreal *size) const
#define M_PI
Definition kis_global.h:111
void cropLineToConvexPolygon(QLineF &line, const QPolygonF polygon, bool extendFirst, bool extendSecond)
bool intersectLineRect(QLineF &line, const QRect rect, bool extend)
static KoColorSpaceRegistry * instance()

References KoColorDisplayRendererInterface::convertColorToDisplayColorSpace(), KisAlgebra2D::cropLineToConvexPolygon(), KisCoordinatesConverter::documentToWidgetTransform(), KisPaintingAssistant::drawPath(), KisPaintingAssistant::drawPreview(), KisPaintingAssistant::effectiveAssistantColor(), KisPaintingAssistant::effectiveBrushPosition(), KisPaintingAssistant::getLocalRect(), KisPaintingAssistant::handles(), KoColorSpaceRegistry::instance(), KisAlgebra2D::intersectLineRect(), KisPaintingAssistantsDecoration::isEditingAssistants(), KisPaintingAssistant::isLocal(), KisPaintingAssistant::isSnappingActive(), length(), LocalFirstHandle, LocalSecondHandle, localTransform(), m_gridDensity, M_PI, m_useVertical, p, p1, p2, p3, KisCanvas2::paintingAssistantsDecoration(), and KisPaintingAssistant::sideHandles().

◆ drawCache()

void TwoPointAssistant::drawCache ( QPainter & gc,
const KisCoordinatesConverter * converter,
const KoColorDisplayRendererInterface * displayRenderInterface,
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 404 of file TwoPointAssistant.cc.

405{
406 Q_UNUSED(gc);
407 Q_UNUSED(converter);
408 Q_UNUSED(assistantVisible);
409 Q_UNUSED(displayRenderInterface);
410 if (!m_canvas || !isAssistantComplete()) {
411 return;
412 }
413
414 if (assistantVisible == false || m_canvas->paintingAssistantsDecoration()->isEditingAssistants()) {
415 return;
416 }
417}
bool isAssistantComplete() const override

References isAssistantComplete(), KisPaintingAssistantsDecoration::isEditingAssistants(), m_canvas, and KisCanvas2::paintingAssistantsDecoration().

◆ endStroke()

void TwoPointAssistant::endStroke ( )
overridevirtual

Reimplemented from KisPaintingAssistant.

Definition at line 137 of file TwoPointAssistant.cc.

138{
139 m_snapLine = QLineF();
140 m_lastUsedPoint = -1;
142}

References KisPaintingAssistant::endStroke(), m_lastUsedPoint, and m_snapLine.

◆ firstLocalHandle()

KisPaintingAssistantHandleSP TwoPointAssistant::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 419 of file TwoPointAssistant.cc.

420{
421 if (handles().size() > LocalFirstHandle) {
422 return handles().at(LocalFirstHandle);
423 } else {
424 return nullptr;
425 }
426}

References KisPaintingAssistant::handles(), and LocalFirstHandle.

◆ getDefaultEditorPosition()

QPointF TwoPointAssistant::getDefaultEditorPosition ( ) const
overridevirtual

Implements KisPaintingAssistant.

Definition at line 437 of file TwoPointAssistant.cc.

438{
439 int centerOfVisionHandle = 2;
440 if (handles().size() > centerOfVisionHandle) {
441 return *handles().at(centerOfVisionHandle);
442 } else if (handles().size() > 0) {
444 return *handles().at(0);
445 } else {
446 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(false, QPointF(0, 0));
447 return QPointF(0, 0);
448 }
449}
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KisPaintingAssistant::handles(), and KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE.

◆ gridDensity()

double TwoPointAssistant::gridDensity ( )

Definition at line 466 of file TwoPointAssistant.cc.

467{
468 return m_gridDensity;
469}

References m_gridDensity.

◆ isActive()

bool TwoPointAssistant::isActive ( ) const
overridevirtual

Implements KisAbstractPerspectiveGrid.

Definition at line 558 of file TwoPointAssistant.cc.

559{
560 return isSnappingActive();
561}

References KisPaintingAssistant::isSnappingActive().

◆ isAssistantComplete()

bool TwoPointAssistant::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 485 of file TwoPointAssistant.cc.

486{
487 return handles().size() >= numHandles();
488}

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

◆ loadCustomXml()

bool TwoPointAssistant::loadCustomXml ( QXmlStreamReader * xml)
overridevirtual

Reimplemented from KisPaintingAssistant.

Definition at line 577 of file TwoPointAssistant.cc.

578{
579 if (xml && xml->name() == "gridDensity") {
580 this->setGridDensity((float)KisDomUtils::toDouble(xml->attributes().value("value").toString()));
581 }
582 if (xml && xml->name() == "useVertical") {
583 this->setUseVertical((bool)KisDomUtils::toInt(xml->attributes().value("value").toString()));
584 }
585 if (xml && xml->name() == "isLocal") {
586 this->setLocal((bool)KisDomUtils::toInt(xml->attributes().value("value").toString()));
587 }
588 return true;
589}
void setLocal(bool value)
setLocal
void setGridDensity(double density)
void setUseVertical(bool value)
double toDouble(const QString &str, bool *ok=nullptr)
int toInt(const QString &str, bool *ok=nullptr)

References setGridDensity(), KisPaintingAssistant::setLocal(), setUseVertical(), KisDomUtils::toDouble(), and KisDomUtils::toInt().

◆ localPerspectiveData()

bool TwoPointAssistant::localPerspectiveData ( const QPointF & point,
QPointF * localPoint,
qreal * size ) const
private

Definition at line 495 of file TwoPointAssistant.cc.

496{
497 if (!isAssistantComplete()) {
498 return false;
499 }
500
501 const QPointF vpA = *handles()[FirstHandle];
502 const QPointF vpB = *handles()[SecondHandle];
503 const QPointF center = *handles()[VerticalHandle];
504
505 qreal localSize = 0.0;
506 const QTransform transform = localTransform(vpA, vpB, center, &localSize);
507
508 if (!std::isfinite(localSize) || localSize <= 0.0) {
509 return false;
510 }
511
512 const QPointF mappedVpA = transform.map(vpA);
513 const QPointF mappedVpB = transform.map(vpB);
514 if (!std::isfinite(mappedVpA.y()) || !std::isfinite(mappedVpB.y())) {
515 return false;
516 }
517
518 if (localPoint) {
519 *localPoint = transform.map(point);
520 }
521 if (size) {
522 *size = localSize;
523 }
524
525 return true;
526}
virtual void transform(const QTransform &transform)

References FirstHandle, KisPaintingAssistant::handles(), isAssistantComplete(), localTransform(), SecondHandle, KisPaintingAssistant::transform(), and VerticalHandle.

◆ localTransform()

QTransform TwoPointAssistant::localTransform ( QPointF vp_a,
QPointF vp_b,
QPointF pt_c,
qreal * size ) const

Definition at line 471 of file TwoPointAssistant.cc.

472{
473 QTransform t = QTransform();
474 t.rotate(QLineF(vp_a, vp_b).angle());
475 // Translate in the rotated frame: the third handle defines x = 0,
476 // while the vanishing points define the horizon at y = 0.
477 t *= QTransform::fromTranslate(-t.map(pt_c).x(), -t.map(vp_a).y());
478 // For orthogonal vanishing directions the cone radius is the geometric
479 // mean of the distances from the center of vision to the two VPs.
480 *size = std::sqrt(-t.map(vp_a).x() * t.map(vp_b).x());
481
482 return t;
483}

◆ numHandles()

int TwoPointAssistant::numHandles ( ) const
inlineoverridevirtual

Implements KisPaintingAssistant.

Definition at line 39 of file TwoPointAssistant.h.

39{ return isLocal() ? 5 : 3; }

References KisPaintingAssistant::isLocal().

◆ project()

QPointF TwoPointAssistant::project ( const QPointF & pt,
const QPointF & strokeBegin,
const bool snapToAny,
qreal moveThreshold )
private

Definition at line 50 of file TwoPointAssistant.cc.

51{
52 Q_ASSERT(isAssistantComplete());
53
54 QPointF best_pt = point;
55 double best_dist = DBL_MAX;
56 QList<int> possibleHandles;
57
58 // must be above or equal to 0;
59 // if useVertical, then last used point must be below 3, because 2 means vertical
60 // and it's the last possible point here (sanity check)
61 // if !useVertical, then it must be below 2, because 2 means vertical
62 bool isLastUsedPointCorrectNow = m_lastUsedPoint >= 0 && (m_useVertical ? m_lastUsedPoint < 3 : m_lastUsedPoint < 2);
63
64 if (isLocal() && handles().size() == 5) {
65 // here we can just return since we don't want to do anything
66 // so we're returning a NaN
67 // but only if we don't have a point/axes it was already using
68
69 QRectF rect = getLocalRect();
70 bool insideLocalRect = rect.contains(point);
71 if (!insideLocalRect && (!isLastUsedPointCorrectNow || !m_hasBeenInsideLocalRect)) {
72 return QPointF(qQNaN(), qQNaN());
73 } else if (insideLocalRect) {
75 }
76 }
77
78 if (!isLastUsedPointCorrectNow && KisAlgebra2D::norm(point - strokeBegin) < moveThreshold) {
79 return strokeBegin;
80 }
81
82 if (!snapToAny && isLastUsedPointCorrectNow) {
83 possibleHandles = QList<int>({m_lastUsedPoint});
84 } else {
85 if (m_useVertical) {
86 possibleHandles = QList<int>({0, 1, 2});
87 } else {
88 possibleHandles = QList<int>({0, 1});
89 }
90 }
91
92 Q_FOREACH (int vpIndex, possibleHandles) {
93 QPointF vp = *handles()[vpIndex];
94 double dist = 0;
95 QPointF pt = QPointF();
96 QLineF snapLine = QLineF();
97
98 // TODO: Would be a good idea to generalize this whole routine
99 // in KisAlgebra2d, as it's all lifted from the vanishing
100 // point assistant and parallel ruler assistant, and by
101 // extension the perspective assistant...
102 qreal dx = point.x() - strokeBegin.x();
103 qreal dy = point.y() - strokeBegin.y();
104
105 if (vp != *handles()[2]) {
106 snapLine = QLineF(vp, strokeBegin);
107 } else {
108 QLineF vertical = QLineF(*handles()[0],*handles()[1]).normalVector();
109 snapLine = QLineF(vertical.p1(), vertical.p2());
110 QPointF translation = (vertical.p1()-strokeBegin)*-1.0;
111 snapLine = snapLine.translated(translation);
112 }
113
114 dx = snapLine.dx();
115 dy = snapLine.dy();
116
117 const qreal dx2 = dx * dx;
118 const qreal dy2 = dy * dy;
119 const qreal invsqrlen = 1.0 / (dx2 + dy2);
120
121 pt = QPointF(dx2 * point.x() + dy2 * snapLine.x1() + dx * dy * (point.y() - snapLine.y1()),
122 dx2 * snapLine.y1() + dy2 * point.y() + dx * dy * (point.x() - snapLine.x1()));
123
124 pt *= invsqrlen;
125 dist = qAbs(pt.x() - point.x()) + qAbs(pt.y() - point.y());
126
127 if (dist < best_dist) {
128 best_pt = pt;
129 best_dist = dist;
130 m_lastUsedPoint = vpIndex;
131 }
132 }
133
134 return best_pt;
135}
qreal norm(const T &a)

References KisPaintingAssistant::getLocalRect(), KisPaintingAssistant::handles(), isAssistantComplete(), KisPaintingAssistant::isLocal(), KisPaintingAssistant::m_hasBeenInsideLocalRect, m_lastUsedPoint, m_useVertical, and KisAlgebra2D::norm().

◆ saveCustomXml()

void TwoPointAssistant::saveCustomXml ( QXmlStreamWriter * xml)
overridevirtual

Reimplemented from KisPaintingAssistant.

Definition at line 563 of file TwoPointAssistant.cc.

564{
565 xml->writeStartElement("gridDensity");
566 xml->writeAttribute("value", KisDomUtils::toString( this->gridDensity()));
567 xml->writeEndElement();
568 xml->writeStartElement("useVertical");
569 xml->writeAttribute("value", KisDomUtils::toString( (int)this->useVertical()));
570 xml->writeEndElement();
571 xml->writeStartElement("isLocal");
572 xml->writeAttribute("value", KisDomUtils::toString( (int)this->isLocal()));
573 xml->writeEndElement();
574
575}
QString toString(const QString &value)

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

◆ secondLocalHandle()

KisPaintingAssistantHandleSP TwoPointAssistant::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 428 of file TwoPointAssistant.cc.

429{
430 if (handles().size() > LocalSecondHandle) {
431 return handles().at(LocalSecondHandle);
432 } else {
433 return nullptr;
434 }
435}

References KisPaintingAssistant::handles(), and LocalSecondHandle.

◆ setGridDensity()

void TwoPointAssistant::setGridDensity ( double density)

Definition at line 451 of file TwoPointAssistant.cc.

452{
453 m_gridDensity = density;
454}

References m_gridDensity.

◆ setUseVertical()

void TwoPointAssistant::setUseVertical ( bool value)

Definition at line 461 of file TwoPointAssistant.cc.

462{
464}
float value(const T *src, size_t ch)

References m_useVertical, and value().

◆ useVertical()

bool TwoPointAssistant::useVertical ( )

Definition at line 456 of file TwoPointAssistant.cc.

457{
458 return m_useVertical;
459}

References m_useVertical.

Member Data Documentation

◆ m_canvas

KisCanvas2* TwoPointAssistant::m_canvas {nullptr}
private

Definition at line 86 of file TwoPointAssistant.h.

86{nullptr};

◆ m_gridDensity

double TwoPointAssistant::m_gridDensity {1.0}
private

Definition at line 89 of file TwoPointAssistant.h.

89{1.0};

◆ m_lastUsedPoint

int TwoPointAssistant::m_lastUsedPoint {-1}
private

Definition at line 92 of file TwoPointAssistant.h.

92{-1}; // last used vanishing point

◆ m_snapLine

QLineF TwoPointAssistant::m_snapLine
private

Definition at line 88 of file TwoPointAssistant.h.

◆ m_useVertical

bool TwoPointAssistant::m_useVertical {true}
private

Definition at line 90 of file TwoPointAssistant.h.

90{true};

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