Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPaintingAssistant Class Referenceabstract

#include <kis_painting_assistant.h>

+ Inheritance diagram for KisPaintingAssistant:

Classes

struct  Private
 

Public Member Functions

void addHandle (KisPaintingAssistantHandleSP handle, HandleType type)
 
virtual void adjustLine (QPointF &point, QPointF &strokeBegin)=0
 
virtual QPointF adjustPosition (const QPointF &point, const QPointF &strokeBegin, bool snapToAny, qreal moveThresholdPt)=0
 
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
 
virtual KisPaintingAssistantSP clone (QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap) const =0
 
KisPaintingAssistantHandleSP closestCornerHandleFromPoint (QPointF point)
 
void copySharedData (KisPaintingAssistantSP assistant)
 
virtual void drawAssistant (QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, bool cached, KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true)
 
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 getDefaultEditorPosition () const =0
 
virtual QPointF getEditorPosition () const
 
QList< KisPaintingAssistantHandleSPhandles ()
 
const QList< KisPaintingAssistantHandleSP > & handles () const
 
const QString & id () const
 
virtual bool isAssistantComplete () 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
 
virtual int numHandles () const =0
 
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
 
virtual void transform (const QTransform &transform)
 
void uncache ()
 
bool useCustomColor ()
 
QPointF viewportConstrainedEditorPosition (const KisCoordinatesConverter *converter, const QSize editorSize)
 
virtual ~KisPaintingAssistant ()
 

Static Public Member Functions

static QList< KisPaintingAssistantSPcloneAssistantList (const QList< KisPaintingAssistantSP > &list)
 
static double norm2 (const QPointF &p)
 

Protected Member Functions

virtual QRect boundingRect () const
 
virtual void drawCache (QPainter &gc, const KisCoordinatesConverter *converter, bool assistantVisible=true)=0
 performance layer where the graphics can be drawn from a cache instead of generated every render update
 
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)
 

Protected Attributes

QList< KisPaintingAssistantHandleSPm_handles
 
bool m_hasBeenInsideLocalRect {false}
 

Private Attributes

Private *const d
 

Detailed Description

A KisPaintingAssistant is an object that assist the drawing on the canvas. With this class you can implement virtual equivalent to ruler or compass.

Definition at line 90 of file kis_painting_assistant.h.

Constructor & Destructor Documentation

◆ KisPaintingAssistant() [1/2]

KisPaintingAssistant::KisPaintingAssistant ( const QString & id,
const QString & name )

Definition at line 249 of file kis_painting_assistant.cc.

249 : d(new Private)
250{
251 d->s->id = id;
252 d->s->name = name;
253 d->s->isSnappingActive = true;
254 d->s->outlineVisible = true;
255}
const QString & name() const
const QString & id() const
QSharedPointer< SharedData > s

References d, id(), name(), and KisPaintingAssistant::Private::s.

◆ ~KisPaintingAssistant()

KisPaintingAssistant::~KisPaintingAssistant ( )
virtual

Definition at line 417 of file kis_painting_assistant.cc.

418{
419 Q_FOREACH (KisPaintingAssistantHandleSP handle, d->handles) {
420 handle->unregisterAssistant(this);
421 }
422 if(!d->sideHandles.isEmpty()) {
423 Q_FOREACH (KisPaintingAssistantHandleSP handle, d->sideHandles) {
424 handle->unregisterAssistant(this);
425 }
426 }
427 delete d;
428}
void unregisterAssistant(KisPaintingAssistant *)
QList< KisPaintingAssistantHandleSP > handles
QList< KisPaintingAssistantHandleSP > sideHandles

References d, KisPaintingAssistant::Private::handles, KisPaintingAssistant::Private::sideHandles, and KisPaintingAssistantHandle::unregisterAssistant().

◆ KisPaintingAssistant() [2/2]

KisPaintingAssistant::KisPaintingAssistant ( const KisPaintingAssistant & rhs,
QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > & handleMap )
explicitprotected

Definition at line 257 of file kis_painting_assistant.cc.

261 , d(new Private(*(rhs.d)))
262{
263 dbgUI << "creating handles...";
264 Q_FOREACH (const KisPaintingAssistantHandleSP origHandle, rhs.d->handles) {
265 d->handles << d->reuseOrCreateHandle(handleMap, origHandle, this);
266 }
267 Q_FOREACH (const KisPaintingAssistantHandleSP origHandle, rhs.d->sideHandles) {
268 d->sideHandles << d->reuseOrCreateHandle(handleMap, origHandle, this);
269 }
270#define _REUSE_H(name) d->name = d->reuseOrCreateHandle(handleMap, rhs.d->name, this, /* registerAssistant = */ false)
279#undef _REUSE_H
280 dbgUI << "done";
281}
const KisPaintingAssistantHandleSP topMiddle() const
const KisPaintingAssistantHandleSP bottomMiddle() const
KisPaintingAssistantHandleSP topLeft()
const KisPaintingAssistantHandleSP bottomLeft() const
const KisPaintingAssistantHandleSP rightMiddle() const
const KisPaintingAssistantHandleSP leftMiddle() const
const KisPaintingAssistantHandleSP topRight() const
KisPaintingAssistantHandleSP bottomRight()
#define dbgUI
Definition kis_debug.h:52
#define _REUSE_H(name)
KisPaintingAssistantHandleSP reuseOrCreateHandle(QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap, KisPaintingAssistantHandleSP origHandle, KisPaintingAssistant *q, bool registerAssistant=true)

References _REUSE_H, bottomLeft(), bottomMiddle(), bottomRight(), d, dbgUI, KisPaintingAssistant::Private::handles, leftMiddle(), KisPaintingAssistant::Private::reuseOrCreateHandle(), rightMiddle(), KisPaintingAssistant::Private::sideHandles, topLeft(), topMiddle(), and topRight().

Member Function Documentation

◆ addHandle()

void KisPaintingAssistant::addHandle ( KisPaintingAssistantHandleSP handle,
HandleType type )

Definition at line 449 of file kis_painting_assistant.cc.

450{
451 Q_ASSERT(!d->handles.contains(handle));
452 if (HandleType::SIDE == type) {
453 d->sideHandles.append(handle);
454 } else {
455 d->handles.append(handle);
456 }
457
458 handle->registerAssistant(this);
459 handle.data()->setType(type);
460}
void registerAssistant(KisPaintingAssistant *)

References d, KisSharedPtr< T >::data(), KisPaintingAssistant::Private::handles, KisPaintingAssistantHandle::registerAssistant(), KisPaintingAssistantHandle::setType(), SIDE, and KisPaintingAssistant::Private::sideHandles.

◆ adjustLine()

◆ adjustPosition()

virtual QPointF KisPaintingAssistant::adjustPosition ( const QPointF & point,
const QPointF & strokeBegin,
bool snapToAny,
qreal moveThresholdPt )
pure virtual

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)

Implemented in VanishingPointAssistant, ConcentricEllipseAssistant, CurvilinearPerspectiveAssistant, EllipseAssistant, FisheyePointAssistant, InfiniteRulerAssistant, ParallelRulerAssistant, PerspectiveAssistant, PerspectiveEllipseAssistant, RulerAssistant, SplineAssistant, and TwoPointAssistant.

◆ areTwoPointsClose()

bool KisPaintingAssistant::areTwoPointsClose ( const QPointF & pointOne,
const QPointF & pointTwo )

Definition at line 1039 of file kis_painting_assistant.cc.

1040{
1041 int m_handleSize = 16;
1042
1043 QRectF handlerect(pointTwo - QPointF(m_handleSize * 0.5, m_handleSize * 0.5), QSizeF(m_handleSize, m_handleSize));
1044 return handlerect.contains(pointOne);
1045}

◆ assistantCustomColor()

QColor KisPaintingAssistant::assistantCustomColor ( )

Definition at line 234 of file kis_painting_assistant.cc.

235{
236 return d->s->assistantCustomColor;
237}

References d, and KisPaintingAssistant::Private::s.

◆ bottomLeft() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::bottomLeft ( )

Definition at line 947 of file kis_painting_assistant.cc.

948{
949 return d->bottomLeft;
950}
KisPaintingAssistantHandleSP bottomLeft

References KisPaintingAssistant::Private::bottomLeft, and d.

◆ bottomLeft() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::bottomLeft ( ) const

Definition at line 952 of file kis_painting_assistant.cc.

953{
954 return d->bottomLeft;
955}

References KisPaintingAssistant::Private::bottomLeft, and d.

◆ bottomMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::bottomMiddle ( )

Definition at line 987 of file kis_painting_assistant.cc.

988{
989 return d->bottomMiddle;
990}
KisPaintingAssistantHandleSP bottomMiddle

References KisPaintingAssistant::Private::bottomMiddle, and d.

◆ bottomMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::bottomMiddle ( ) const

Definition at line 992 of file kis_painting_assistant.cc.

993{
994 return d->bottomMiddle;
995}

References KisPaintingAssistant::Private::bottomMiddle, and d.

◆ bottomRight() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::bottomRight ( )

Definition at line 967 of file kis_painting_assistant.cc.

968{
969 return d->bottomRight;
970}
KisPaintingAssistantHandleSP bottomRight

References KisPaintingAssistant::Private::bottomRight, and d.

◆ bottomRight() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::bottomRight ( ) const

Definition at line 972 of file kis_painting_assistant.cc.

973{
974 return d->bottomRight;
975}

References KisPaintingAssistant::Private::bottomRight, and d.

◆ boundingRect()

QRect KisPaintingAssistant::boundingRect ( ) const
protectedvirtual

Reimplemented in ConcentricEllipseAssistant, EllipseAssistant, FisheyePointAssistant, and PerspectiveEllipseAssistant.

Definition at line 543 of file kis_painting_assistant.cc.

544{
545 QRectF r;
546 Q_FOREACH (KisPaintingAssistantHandleSP h, handles()) {
547 r = r.united(QRectF(*h, QSizeF(1,1)));
548 }
549 return r.adjusted(-2, -2, 2, 2).toAlignedRect();
550}
const QList< KisPaintingAssistantHandleSP > & handles() const

References handles().

◆ canBeLocal()

bool KisPaintingAssistant::canBeLocal ( ) const
virtual

canBeLocal

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

Reimplemented in ParallelRulerAssistant, TwoPointAssistant, and VanishingPointAssistant.

Definition at line 316 of file kis_painting_assistant.cc.

317{
318 return false;
319}

◆ clone()

◆ cloneAssistantList()

QList< KisPaintingAssistantSP > KisPaintingAssistant::cloneAssistantList ( const QList< KisPaintingAssistantSP > & list)
static

clones the list of assistants the originally shared handles will still be shared the cloned assistants do not share any handle with the original assistants

Definition at line 1126 of file kis_painting_assistant.cc.

1127{
1128 QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> handleMap;
1130 for (auto i = list.begin(); i != list.end(); ++i) {
1131 clonedList << (*i)->clone(handleMap);
1132 }
1133 return clonedList;
1134}

◆ closestCornerHandleFromPoint()

KisPaintingAssistantHandleSP KisPaintingAssistant::closestCornerHandleFromPoint ( QPointF point)

Definition at line 1047 of file kis_painting_assistant.cc.

1048{
1049 if (!d->s->m_canvas) {
1050 return 0;
1051 }
1052
1053
1054 if (areTwoPointsClose(point, pixelToView(topLeft()->toPoint()))) {
1055 return topLeft();
1056 } else if (areTwoPointsClose(point, pixelToView(topRight()->toPoint()))) {
1057 return topRight();
1058 } else if (areTwoPointsClose(point, pixelToView(bottomLeft()->toPoint()))) {
1059 return bottomLeft();
1060 } else if (areTwoPointsClose(point, pixelToView(bottomRight()->toPoint()))) {
1061 return bottomRight();
1062 }
1063 return 0;
1064}
QPointF pixelToView(const QPoint pixelCoords) const
bool areTwoPointsClose(const QPointF &pointOne, const QPointF &pointTwo)

References areTwoPointsClose(), bottomLeft(), bottomRight(), d, pixelToView(), KisPaintingAssistant::Private::s, topLeft(), and topRight().

◆ copySharedData()

void KisPaintingAssistant::copySharedData ( KisPaintingAssistantSP assistant)

Definition at line 188 of file kis_painting_assistant.cc.

189{
190 // Clones do not get a copy of the shared data, so this function is necessary to copy
191 // the SharedData struct from the old assistant to this one. The function returns a
192 // reference to a new SharedData object copied from the original
195 *this->d->s = *sd;
196}

References d, and KisPaintingAssistant::Private::s.

◆ drawAssistant()

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

Reimplemented in ConcentricEllipseAssistant, EllipseAssistant, PerspectiveEllipseAssistant, RulerAssistant, SplineAssistant, CurvilinearPerspectiveAssistant, FisheyePointAssistant, InfiniteRulerAssistant, ParallelRulerAssistant, PerspectiveAssistant, TwoPointAssistant, and VanishingPointAssistant.

Definition at line 479 of file kis_painting_assistant.cc.

480{
481 Q_UNUSED(updateRect);
482
483 Q_UNUSED(previewVisible);
484
486
487 if (!useCache) {
488 gc.save();
489 drawCache(gc, converter, assistantVisible);
490 gc.restore();
491 return;
492 }
493
494 const QRect bound = boundingRect();
495 if (bound.isEmpty()) {
496 return;
497 }
498
499 const QTransform transform = converter->documentToWidgetTransform();
500 const QRect widgetBound = transform.mapRect(bound);
501
502 const QRect paintRect = transform.mapRect(bound).intersected(gc.viewport());
503 if (paintRect.isEmpty()) return;
504
505 QPixmap cached;
506 bool found = QPixmapCache::find(d->s->cached, &cached);
507
508 if (!(found &&
509 d->s->cachedTransform == transform &&
510 d->s->cachedRect.translated(widgetBound.topLeft()).contains(paintRect))) {
511
512 const QRect cacheRect = gc.viewport().adjusted(-100, -100, 100, 100).intersected(widgetBound);
513 Q_ASSERT(!cacheRect.isEmpty());
514
515 if (cached.isNull() || cached.size() != cacheRect.size()) {
516 cached = QPixmap(cacheRect.size());
517 }
518
519 cached.fill(Qt::transparent);
520 QPainter painter(&cached);
521 painter.setRenderHint(QPainter::Antialiasing);
522 painter.setWindow(cacheRect);
523 drawCache(painter, converter, assistantVisible);
524 painter.end();
525 d->s->cachedTransform = transform;
526 d->s->cachedRect = cacheRect.translated(-widgetBound.topLeft());
527 d->s->cached = QPixmapCache::insert(cached);
528 }
529
530 gc.drawPixmap(paintRect, cached, paintRect.translated(-widgetBound.topLeft() - d->s->cachedRect.topLeft()));
531
532
533 if (canvas) {
534 d->s->m_canvas = canvas;
535 }
536}
virtual QRect boundingRect() const
virtual void drawCache(QPainter &gc, const KisCoordinatesConverter *converter, bool assistantVisible=true)=0
performance layer where the graphics can be drawn from a cache instead of generated every render upda...
virtual void transform(const QTransform &transform)

References boundingRect(), d, KisCoordinatesConverter::documentToWidgetTransform(), drawCache(), findPerspectiveAssistantHandleLocation(), KisPaintingAssistant::Private::s, and transform().

◆ drawCache()

virtual void KisPaintingAssistant::drawCache ( QPainter & gc,
const KisCoordinatesConverter * converter,
bool assistantVisible = true )
protectedpure virtual

◆ drawError()

void KisPaintingAssistant::drawError ( QPainter & painter,
const QPainterPath & path )

Definition at line 390 of file kis_painting_assistant.cc.

391{
392 painter.save();
393 QPen pen_a(QColor(255, 0, 0, 125), d->errorLineWidth * d->decorationThickness);
394 pen_a.setCosmetic(true);
395 painter.setPen(pen_a);
396 painter.drawPath(path);
397 painter.restore();
398}

References d, KisPaintingAssistant::Private::decorationThickness, and KisPaintingAssistant::Private::errorLineWidth.

◆ drawPath()

void KisPaintingAssistant::drawPath ( QPainter & painter,
const QPainterPath & path,
bool drawActive = true )

This will render the final output. The drawCache does rendering most of the time so be sure to check that

Definition at line 362 of file kis_painting_assistant.cc.

363{
364
365 QColor paintingColor = effectiveAssistantColor();
366
367 if (!isSnappingOn) {
368 paintingColor.setAlpha(0.2 * paintingColor.alpha());
369 }
370
371 painter.save();
372 QPen pen_a(paintingColor, d->mainLineWidth * d->decorationThickness);
373 pen_a.setCosmetic(true);
374 painter.setPen(pen_a);
375 painter.drawPath(path);
376 painter.restore();
377}

References d, KisPaintingAssistant::Private::decorationThickness, effectiveAssistantColor(), and KisPaintingAssistant::Private::mainLineWidth.

◆ drawPreview()

void KisPaintingAssistant::drawPreview ( QPainter & painter,
const QPainterPath & path )

Definition at line 379 of file kis_painting_assistant.cc.

380{
381 painter.save();
383 pen_a.setStyle(Qt::SolidLine);
384 pen_a.setCosmetic(true);
385 painter.setPen(pen_a);
386 painter.drawPath(path);
387 painter.restore();
388}

References d, effectiveAssistantColor(), and KisPaintingAssistant::Private::previewLineWidth.

◆ drawX()

void KisPaintingAssistant::drawX ( QPainter & painter,
const QPointF & pt )

Definition at line 400 of file kis_painting_assistant.cc.

401{
402 QPainterPath path;
403 path.moveTo(QPointF(pt.x() - 5.0, pt.y() - 5.0)); path.lineTo(QPointF(pt.x() + 5.0, pt.y() + 5.0));
404 path.moveTo(QPointF(pt.x() - 5.0, pt.y() + 5.0)); path.lineTo(QPointF(pt.x() + 5.0, pt.y() - 5.0));
405 drawPath(painter, path);
406}
void drawPath(QPainter &painter, const QPainterPath &path, bool drawActive=true)

References drawPath().

◆ editorWidgetOffset()

QPointF KisPaintingAssistant::editorWidgetOffset ( )

Definition at line 351 of file kis_painting_assistant.cc.

352{
353 return d->s->editorWidgetOffset;
354}

References d, and KisPaintingAssistant::Private::s.

◆ effectiveAssistantColor()

QColor KisPaintingAssistant::effectiveAssistantColor ( ) const

Definition at line 244 of file kis_painting_assistant.cc.

245{
246 return d->s->useCustomColor ? d->s->assistantCustomColor : d->s->assistantGlobalColorCache;
247}

References d, and KisPaintingAssistant::Private::s.

◆ effectiveBrushPosition()

QPointF KisPaintingAssistant::effectiveBrushPosition ( const KisCoordinatesConverter * converter,
KisCanvas2 * canvas ) const
protected

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

Returns
the effective brush (cursor) position in widget coordinates

Definition at line 1073 of file kis_painting_assistant.cc.

1074{
1075 QPointF mousePos;
1076
1077 if (d->s->followBrushPosition && d->s->adjustedPositionValid) {
1078 mousePos = converter->documentToWidget(d->s->adjustedBrushPosition);
1079 } else if (canvas) {
1080 // FIXME: this may be simple and cheap, but it's only integer precision!
1081 mousePos= canvas->canvasWidget()->mapFromGlobal(QCursor::pos());
1082 } else {
1083 //...of course, you need to have access to a canvas-widget for that.//
1084 mousePos = QCursor::pos(); //this'll give an offset//
1085 dbgUI << "no canvas given for assistant, you may have passed arguments incorrectly:";
1086 }
1087 return mousePos;
1088}
KisAbstractCanvasWidget * canvasWidget
_Private::Traits< T >::Result documentToWidget(const T &obj) const

References KisCanvas2::canvasWidget, d, dbgUI, KisCoordinatesConverter::documentToWidget(), and KisPaintingAssistant::Private::s.

◆ endStroke()

void KisPaintingAssistant::endStroke ( )
virtual

Reimplemented in PerspectiveAssistant, and TwoPointAssistant.

Definition at line 293 of file kis_painting_assistant.cc.

294{
295 d->s->adjustedPositionValid = false;
296 d->s->followBrushPosition = false;
298}

References d, m_hasBeenInsideLocalRect, and KisPaintingAssistant::Private::s.

◆ findPerspectiveAssistantHandleLocation()

void KisPaintingAssistant::findPerspectiveAssistantHandleLocation ( )

Definition at line 797 of file kis_painting_assistant.cc.

797 {
800 uint vHole = 0,hHole = 0;
802 if (d->handles.size() == 4 && d->s->id == "perspective") {
803 //get the handle opposite to the first handle
804 oppHandle = oppHandleOne();
805 //Sorting handles into two list, X sorted and Y sorted into hHandlesList and vHandlesList respectively.
806 Q_FOREACH (const KisPaintingAssistantHandleSP handle,d->handles) {
807 hHandlesList.append(handle);
808 hHole = hHandlesList.size() - 1;
809 vHandlesList.append(handle);
810 vHole = vHandlesList.size() - 1;
811 /*
812 sort handles on the basis of X-coordinate
813 */
814 while(hHole > 0 && hHandlesList.at(hHole -1).data()->x() > handle.data()->x()) {
815 hHandlesList.swapItemsAt(hHole - 1, hHole);
816 hHole = hHole - 1;
817 }
818 /*
819 sort handles on the basis of Y-coordinate
820 */
821 while(vHole > 0 && vHandlesList.at(vHole -1).data()->y() > handle.data()->y()) {
822 vHandlesList.swapItemsAt(vHole-1, vHole);
823 vHole = vHole - 1;
824 }
825 }
826
827 /*
828 give the handles their respective positions
829 */
830 if(vHandlesList.at(0).data()->x() > vHandlesList.at(1).data()->x()) {
831 d->topLeft = vHandlesList.at(1);
832 d->topRight= vHandlesList.at(0);
833 }
834 else {
835 d->topLeft = vHandlesList.at(0);
836 d->topRight = vHandlesList.at(1);
837 }
838 if(vHandlesList.at(2).data()->x() > vHandlesList.at(3).data()->x()) {
839 d->bottomLeft = vHandlesList.at(3);
840 d->bottomRight = vHandlesList.at(2);
841 }
842 else {
843 d->bottomLeft= vHandlesList.at(2);
844 d->bottomRight = vHandlesList.at(3);
845 }
846
847 /*
848 find if the handles that should be opposite are actually oppositely positioned
849 */
850 if (( (d->topLeft == d->handles.at(0).data() && d->bottomRight == oppHandle) ||
851 (d->topLeft == oppHandle && d->bottomRight == d->handles.at(0).data()) ||
852 (d->topRight == d->handles.at(0).data() && d->bottomLeft == oppHandle) ||
853 (d->topRight == oppHandle && d->bottomLeft == d->handles.at(0).data()) ) )
854 {}
855 else {
856 if(hHandlesList.at(0).data()->y() > hHandlesList.at(1).data()->y()) {
857 d->topLeft = hHandlesList.at(1);
858 d->bottomLeft= hHandlesList.at(0);
859 }
860 else {
861 d->topLeft = hHandlesList.at(0);
862 d->bottomLeft = hHandlesList.at(1);
863 }
864 if(hHandlesList.at(2).data()->y() > hHandlesList.at(3).data()->y()) {
865 d->topRight = hHandlesList.at(3);
866 d->bottomRight = hHandlesList.at(2);
867 }
868 else {
869 d->topRight= hHandlesList.at(2);
870 d->bottomRight = hHandlesList.at(3);
871 }
872
873 }
874 /*
875 Setting the middle handles as needed
876 */
877 if(!d->bottomMiddle && !d->topMiddle && !d->leftMiddle && !d->rightMiddle) {
878
879 // Before re-adding the handles, clear old ones that have been
880 // potentially loaded from disk and not re-associated with the
881 // xxxMiddle pointers in d; otherwise those would stay in place.
882 if(!d->sideHandles.isEmpty()) {
883 Q_FOREACH (KisPaintingAssistantHandleSP handle, d->sideHandles) {
884 handle->unregisterAssistant(this);
885 }
886 d->sideHandles.clear();
887 }
888
890 (d->bottomLeft.data()->y() + d->bottomRight.data()->y())*0.5);
891 d->topMiddle = new KisPaintingAssistantHandle((d->topLeft.data()->x() + d->topRight.data()->x())*0.5,
892 (d->topLeft.data()->y() + d->topRight.data()->y())*0.5);
894 (d->topRight.data()->y() + d->bottomRight.data()->y())*0.5);
895 d->leftMiddle= new KisPaintingAssistantHandle((d->bottomLeft.data()->x() + d->topLeft.data()->x())*0.5,
896 (d->bottomLeft.data()->y() + d->topLeft.data()->y())*0.5);
897
902 }
903 else
904 {
905 d->bottomMiddle.data()->operator =(QPointF((d->bottomLeft.data()->x() + d->bottomRight.data()->x())*0.5,
906 (d->bottomLeft.data()->y() + d->bottomRight.data()->y())*0.5));
907 d->topMiddle.data()->operator =(QPointF((d->topLeft.data()->x() + d->topRight.data()->x())*0.5,
908 (d->topLeft.data()->y() + d->topRight.data()->y())*0.5));
909 d->rightMiddle.data()->operator =(QPointF((d->topRight.data()->x() + d->bottomRight.data()->x())*0.5,
910 (d->topRight.data()->y() + d->bottomRight.data()->y())*0.5));
911 d->leftMiddle.data()->operator =(QPointF((d->bottomLeft.data()->x() + d->topLeft.data()->x())*0.5,
912 (d->bottomLeft.data()->y() + d->topLeft.data()->y())*0.5));
913 }
914
915 }
916}
unsigned int uint
void addHandle(KisPaintingAssistantHandleSP handle, HandleType type)
KisPaintingAssistantHandleSP oppHandleOne()
KisPaintingAssistantHandleSP topRight
KisPaintingAssistantHandleSP topMiddle
KisPaintingAssistantHandleSP rightMiddle
KisPaintingAssistantHandleSP leftMiddle
KisPaintingAssistantHandleSP topLeft

References addHandle(), KisPaintingAssistant::Private::bottomLeft, KisPaintingAssistant::Private::bottomMiddle, KisPaintingAssistant::Private::bottomRight, d, KisSharedPtr< T >::data(), KisPaintingAssistant::Private::handles, KisPaintingAssistant::Private::leftMiddle, oppHandleOne(), KisPaintingAssistant::Private::rightMiddle, KisPaintingAssistant::Private::s, SIDE, KisPaintingAssistant::Private::sideHandles, KisPaintingAssistant::Private::topLeft, KisPaintingAssistant::Private::topMiddle, KisPaintingAssistant::Private::topRight, and KisPaintingAssistantHandle::unregisterAssistant().

◆ firstLocalHandle()

KisPaintingAssistantHandleSP KisPaintingAssistant::firstLocalHandle ( ) const
protectedvirtual

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 in ParallelRulerAssistant, TwoPointAssistant, and VanishingPointAssistant.

Definition at line 1090 of file kis_painting_assistant.cc.

1091{
1092 return 0;
1093}

◆ getDefaultEditorPosition()

◆ getEditorPosition()

QPointF KisPaintingAssistant::getEditorPosition ( ) const
virtual

Definition at line 311 of file kis_painting_assistant.cc.

312{
313 return getDefaultEditorPosition() + d->s->editorWidgetOffset;
314}
virtual QPointF getDefaultEditorPosition() const =0

References d, getDefaultEditorPosition(), and KisPaintingAssistant::Private::s.

◆ getLocalRect()

QRectF KisPaintingAssistant::getLocalRect ( ) const
protected

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.

Returns
the rectangle of the area that the assistant is limited to

Definition at line 1100 of file kis_painting_assistant.cc.

1101{
1102 if (!isLocal() || !firstLocalHandle() || !secondLocalHandle()) {
1103 return QRectF();
1104 }
1105
1108
1109 QPointF topLeft = QPointF(qMin(first->x(), second->x()), qMin(first->y(), second->y()));
1110 QPointF bottomRight = QPointF(qMax(first->x(), second->x()), qMax(first->y(), second->y()));
1111
1112 QRectF rect(topLeft, bottomRight);
1113 return rect;
1114}
virtual KisPaintingAssistantHandleSP secondLocalHandle() const
secondLocalHandle Note: this doesn't guarantee it will be the bottomRight corner! For that,...
virtual KisPaintingAssistantHandleSP firstLocalHandle() const
firstLocalHandle Note: this doesn't guarantee it will be the topleft corner! For that,...

References bottomRight(), firstLocalHandle(), isLocal(), secondLocalHandle(), and topLeft().

◆ handles() [1/2]

QList< KisPaintingAssistantHandleSP > KisPaintingAssistant::handles ( )

Definition at line 1022 of file kis_painting_assistant.cc.

1023{
1024 return d->handles;
1025}

References d, and KisPaintingAssistant::Private::handles.

◆ handles() [2/2]

const QList< KisPaintingAssistantHandleSP > & KisPaintingAssistant::handles ( ) const

Definition at line 1017 of file kis_painting_assistant.cc.

1018{
1019 return d->handles;
1020}

References d, and KisPaintingAssistant::Private::handles.

◆ id()

const QString & KisPaintingAssistant::id ( ) const

Definition at line 430 of file kis_painting_assistant.cc.

431{
432 return d->s->id;
433}

References d, and KisPaintingAssistant::Private::s.

◆ initHandles()

void KisPaintingAssistant::initHandles ( QList< KisPaintingAssistantHandleSP > _handles)
protected

Definition at line 408 of file kis_painting_assistant.cc.

409{
410 Q_ASSERT(d->handles.isEmpty());
411 d->handles = _handles;
412 Q_FOREACH (KisPaintingAssistantHandleSP handle, _handles) {
413 handle->registerAssistant(this);
414 }
415}

References d, KisPaintingAssistant::Private::handles, and KisPaintingAssistantHandle::registerAssistant().

◆ isAssistantComplete()

bool KisPaintingAssistant::isAssistantComplete ( ) const
virtual

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 in ConcentricEllipseAssistant, CurvilinearPerspectiveAssistant, EllipseAssistant, FisheyePointAssistant, InfiniteRulerAssistant, ParallelRulerAssistant, PerspectiveAssistant, PerspectiveEllipseAssistant, RulerAssistant, SplineAssistant, TwoPointAssistant, and VanishingPointAssistant.

Definition at line 552 of file kis_painting_assistant.cc.

553{
554 return true;
555}

◆ isDuplicating()

bool KisPaintingAssistant::isDuplicating ( )

isDuplicating

Returns
If the duplication button is pressed

Definition at line 346 of file kis_painting_assistant.cc.

347{
348 return d->s->isDuplicating;
349}

References d, and KisPaintingAssistant::Private::s.

◆ isLocal()

bool KisPaintingAssistant::isLocal ( ) const

isLocal

Returns
if the assistant is limited to a rectangular area or not

Definition at line 321 of file kis_painting_assistant.cc.

322{
323 return d->s->isLocal;
324}

References d, and KisPaintingAssistant::Private::s.

◆ isLocked()

bool KisPaintingAssistant::isLocked ( )

isLocked

Returns
if the assistant is locked (= cannot be moved, or edited in any way), or not

Definition at line 331 of file kis_painting_assistant.cc.

332{
333 return d->s->isLocked;
334}

References d, and KisPaintingAssistant::Private::s.

◆ isSnappingActive()

bool KisPaintingAssistant::isSnappingActive ( ) const

Definition at line 283 of file kis_painting_assistant.cc.

284{
285 return d->s->isSnappingActive;
286}

References d, and KisPaintingAssistant::Private::s.

◆ leftMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::leftMiddle ( )

Definition at line 1007 of file kis_painting_assistant.cc.

1008{
1009 return d->leftMiddle;
1010}

References d, and KisPaintingAssistant::Private::leftMiddle.

◆ leftMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::leftMiddle ( ) const

Definition at line 1012 of file kis_painting_assistant.cc.

1013{
1014 return d->leftMiddle;
1015}

References d, and KisPaintingAssistant::Private::leftMiddle.

◆ loadCustomXml()

bool KisPaintingAssistant::loadCustomXml ( QXmlStreamReader * xml)
virtual

Reimplemented in ParallelRulerAssistant, PerspectiveAssistant, RulerAssistant, TwoPointAssistant, and VanishingPointAssistant.

Definition at line 715 of file kis_painting_assistant.cc.

716{
717 Q_UNUSED(xml);
718 return true;
719}

◆ loadXml()

void KisPaintingAssistant::loadXml ( KoStore * store,
QMap< int, KisPaintingAssistantHandleSP > & handleMap,
QString path )

Definition at line 631 of file kis_painting_assistant.cc.

632{
633 int id = 0;
634 double x = 0.0, y = 0.0;
635 store->open(path);
636 QByteArray data = store->read(store->size());
637 QXmlStreamReader xml(data);
638 QMap<int, KisPaintingAssistantHandleSP> sideHandleMap;
639 while (!xml.atEnd()) {
640 switch (xml.readNext()) {
641 case QXmlStreamReader::StartElement:
642 if (xml.name() == "assistant") {
643
644 auto active = xml.attributes().value("active");
645 setSnappingActive( (active != "0") );
646
647 // load custom shared assistant properties
648 if ( xml.attributes().hasAttribute("useCustomColor")) {
649 auto useCustomColor = xml.attributes().value("useCustomColor");
650
651 bool usingColor = false;
652 if (useCustomColor.toString() == "1") {
653 usingColor = true;
654 }
655
656
657 setUseCustomColor(usingColor);
658 }
659
660 if (xml.attributes().hasAttribute("editorWidgetOffset_X") && xml.attributes().hasAttribute("editorWidgetOffset_Y")) {
661 setEditorWidgetOffset(QPointF(xml.attributes().value("editorWidgetOffset_X").toDouble(), xml.attributes().value("editorWidgetOffset_Y").toDouble()));
662 }
663
664 if ( xml.attributes().hasAttribute("customColor")) {
665 auto customColor = xml.attributes().value("customColor");
666 setAssistantCustomColor( KisDomUtils::qStringToQColor(customColor.toString()) );
667
668 }
669
670 if ( xml.attributes().hasAttribute("locked")) {
671 auto locked = xml.attributes().value("locked");
672 setLocked(locked == "1");
673 }
674
675 }
676
677 loadCustomXml(&xml);
678
679 if (xml.name() == "handle") {
680 QString strId = xml.attributes().value("id").toString(),
681 strX = xml.attributes().value("x").toString(),
682 strY = xml.attributes().value("y").toString();
683 if (!strId.isEmpty() && !strX.isEmpty() && !strY.isEmpty()) {
684 id = strId.toInt();
685 x = strX.toDouble();
686 y = strY.toDouble();
687 if (!handleMap.contains(id)) {
688 handleMap.insert(id, new KisPaintingAssistantHandle(x, y));
689 }
690 }
691 addHandle(handleMap.value(id), HandleType::NORMAL);
692 } else if (xml.name() == "sidehandle") {
693 QString strId = xml.attributes().value("id").toString(),
694 strX = xml.attributes().value("x").toString(),
695 strY = xml.attributes().value("y").toString();
696 if (!strId.isEmpty() && !strX.isEmpty() && !strY.isEmpty()) {
697 id = strId.toInt();
698 x = strX.toDouble();
699 y = strY.toDouble();
700 if (!sideHandleMap.contains(id)) {
701 sideHandleMap.insert(id, new KisPaintingAssistantHandle(x, y));
702 }
703 }
704 addHandle(sideHandleMap.value(id), HandleType::SIDE);
705
706 }
707 break;
708 default:
709 break;
710 }
711 }
712 store->close();
713}
void setLocked(bool value)
setLocked
void setEditorWidgetOffset(QPointF offset)
void setAssistantCustomColor(QColor color)
virtual bool loadCustomXml(QXmlStreamReader *xml)
void setUseCustomColor(bool useCustomColor)
bool close()
Definition KoStore.cpp:156
qint64 size() const
Definition KoStore.cpp:239
bool open(const QString &name)
Definition KoStore.cpp:109
QByteArray read(qint64 max)
Definition KoStore.cpp:181
QColor qStringToQColor(QString colorString)

References addHandle(), KoStore::close(), loadCustomXml(), NORMAL, KoStore::open(), KisDomUtils::qStringToQColor(), KoStore::read(), setAssistantCustomColor(), setEditorWidgetOffset(), setLocked(), setSnappingActive(), setUseCustomColor(), SIDE, KoStore::size(), and useCustomColor().

◆ name()

const QString & KisPaintingAssistant::name ( ) const

Definition at line 435 of file kis_painting_assistant.cc.

436{
437 return d->s->name;
438}

References d, and KisPaintingAssistant::Private::s.

◆ norm2()

double KisPaintingAssistant::norm2 ( const QPointF & p)
static

Definition at line 1116 of file kis_painting_assistant.cc.

1117{
1118 return p.x() * p.x() + p.y() * p.y();
1119}
const Params2D p

References p.

◆ numHandles()

◆ oppHandleOne()

KisPaintingAssistantHandleSP KisPaintingAssistant::oppHandleOne ( )

Definition at line 918 of file kis_painting_assistant.cc.

919{
920 QPointF intersection(0,0);
921 if((QLineF(d->handles.at(0).data()->toPoint(),d->handles.at(1).data()->toPoint()).intersects(QLineF(d->handles.at(2).data()->toPoint(),d->handles.at(3).data()->toPoint()), &intersection) != QLineF::NoIntersection)
922 && (QLineF(d->handles.at(0).data()->toPoint(),d->handles.at(1).data()->toPoint()).intersects(QLineF(d->handles.at(2).data()->toPoint(),d->handles.at(3).data()->toPoint()), &intersection) != QLineF::UnboundedIntersection))
923 {
924 return d->handles.at(1);
925 }
926 else if((QLineF(d->handles.at(0).data()->toPoint(),d->handles.at(2).data()->toPoint()).intersects(QLineF(d->handles.at(1).data()->toPoint(),d->handles.at(3).data()->toPoint()), &intersection) != QLineF::NoIntersection)
927 && (QLineF(d->handles.at(0).data()->toPoint(),d->handles.at(2).data()->toPoint()).intersects(QLineF(d->handles.at(1).data()->toPoint(),d->handles.at(3).data()->toPoint()), &intersection) != QLineF::UnboundedIntersection))
928 {
929 return d->handles.at(2);
930 }
931 else
932 {
933 return d->handles.at(3);
934 }
935}

References d, and KisPaintingAssistant::Private::handles.

◆ pixelToView()

QPointF KisPaintingAssistant::pixelToView ( const QPoint pixelCoords) const
protected

Definition at line 1067 of file kis_painting_assistant.cc.

1068{
1069 QPointF documentCoord = d->s->m_canvas->image()->pixelToDocument(pixelCoords);
1070 return d->s->m_canvas->viewConverter()->documentToView(documentCoord);
1071}

References d, and KisPaintingAssistant::Private::s.

◆ replaceHandle()

void KisPaintingAssistant::replaceHandle ( KisPaintingAssistantHandleSP _handle,
KisPaintingAssistantHandleSP _with )

Definition at line 440 of file kis_painting_assistant.cc.

441{
442 Q_ASSERT(d->handles.contains(_handle));
443 d->handles.replace(d->handles.indexOf(_handle), _with);
444 Q_ASSERT(!d->handles.contains(_handle));
445 _handle->unregisterAssistant(this);
446 _with->registerAssistant(this);
447}

References d, KisPaintingAssistant::Private::handles, KisPaintingAssistantHandle::registerAssistant(), and KisPaintingAssistantHandle::unregisterAssistant().

◆ rightMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::rightMiddle ( )

Definition at line 997 of file kis_painting_assistant.cc.

998{
999 return d->rightMiddle;
1000}

References d, and KisPaintingAssistant::Private::rightMiddle.

◆ rightMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::rightMiddle ( ) const

Definition at line 1002 of file kis_painting_assistant.cc.

1003{
1004 return d->rightMiddle;
1005}

References d, and KisPaintingAssistant::Private::rightMiddle.

◆ saveCustomXml()

void KisPaintingAssistant::saveCustomXml ( QXmlStreamWriter * xml)
virtual

Reimplemented in ParallelRulerAssistant, PerspectiveAssistant, RulerAssistant, TwoPointAssistant, and VanishingPointAssistant.

Definition at line 626 of file kis_painting_assistant.cc.

627{
628 Q_UNUSED(xml);
629}

◆ saveXml()

QByteArray KisPaintingAssistant::saveXml ( QMap< KisPaintingAssistantHandleSP, int > & handleMap)

Definition at line 574 of file kis_painting_assistant.cc.

575{
576 QByteArray data;
577 QXmlStreamWriter xml(&data);
578 xml.writeStartDocument();
579 xml.writeStartElement("assistant");
580 xml.writeAttribute("type",d->s->id);
581 xml.writeAttribute("active", QString::number(d->s->isSnappingActive));
582 xml.writeAttribute("useCustomColor", QString::number(d->s->useCustomColor));
583 xml.writeAttribute("customColor", KisDomUtils::qColorToQString(d->s->assistantCustomColor));
584 xml.writeAttribute("locked", QString::number(d->s->isLocked));
585 xml.writeAttribute("editorWidgetOffset_X", QString::number((double)(d->s->editorWidgetOffset.x()), 'f', 3));
586 xml.writeAttribute("editorWidgetOffset_Y", QString::number((double)(d->s->editorWidgetOffset.y()), 'f', 3));
587
588
589
590 saveCustomXml(&xml); // if any specific assistants have custom XML data to save to
591
592 // write individual handle data
593 xml.writeStartElement("handles");
594 Q_FOREACH (const KisPaintingAssistantHandleSP handle, d->handles) {
595 int id = handleMap.size();
596 if (!handleMap.contains(handle)){
597 handleMap.insert(handle, id);
598 }
599 id = handleMap.value(handle);
600 xml.writeStartElement("handle");
601 xml.writeAttribute("id", QString::number(id));
602 xml.writeAttribute("x", QString::number(double(handle->x()), 'f', 3));
603 xml.writeAttribute("y", QString::number(double(handle->y()), 'f', 3));
604 xml.writeEndElement();
605 }
606 xml.writeEndElement();
607 if (!d->sideHandles.isEmpty()) { // for vanishing points only
608 xml.writeStartElement("sidehandles");
609 QMap<KisPaintingAssistantHandleSP, int> sideHandleMap;
610 Q_FOREACH (KisPaintingAssistantHandleSP handle, d->sideHandles) {
611 int id = sideHandleMap.size();
612 sideHandleMap.insert(handle, id);
613 xml.writeStartElement("sidehandle");
614 xml.writeAttribute("id", QString::number(id));
615 xml.writeAttribute("x", QString::number(double(handle->x()), 'f', 3));
616 xml.writeAttribute("y", QString::number(double(handle->y()), 'f', 3));
617 xml.writeEndElement();
618 }
619 }
620
621 xml.writeEndElement();
622 xml.writeEndDocument();
623 return data;
624}
virtual void saveCustomXml(QXmlStreamWriter *xml)
QString qColorToQString(QColor color)

References d, KisPaintingAssistant::Private::handles, KisDomUtils::qColorToQString(), KisPaintingAssistant::Private::s, saveCustomXml(), and KisPaintingAssistant::Private::sideHandles.

◆ saveXmlList()

void KisPaintingAssistant::saveXmlList ( QDomDocument & doc,
QDomElement & assistantsElement,
int count )

Definition at line 721 of file kis_painting_assistant.cc.

722{
723 if (d->s->id == "ellipse"){
724 QDomElement assistantElement = doc.createElement("assistant");
725 assistantElement.setAttribute("type", "ellipse");
726 assistantElement.setAttribute("filename", QString("ellipse%1.assistant").arg(count));
727 assistantsElement.appendChild(assistantElement);
728 }
729 else if (d->s->id == "spline"){
730 QDomElement assistantElement = doc.createElement("assistant");
731 assistantElement.setAttribute("type", "spline");
732 assistantElement.setAttribute("filename", QString("spline%1.assistant").arg(count));
733 assistantsElement.appendChild(assistantElement);
734 }
735 else if (d->s->id == "perspective"){
736 QDomElement assistantElement = doc.createElement("assistant");
737 assistantElement.setAttribute("type", "perspective");
738 assistantElement.setAttribute("filename", QString("perspective%1.assistant").arg(count));
739 assistantsElement.appendChild(assistantElement);
740 }
741 else if (d->s->id == "vanishing point"){
742 QDomElement assistantElement = doc.createElement("assistant");
743 assistantElement.setAttribute("type", "vanishing point");
744 assistantElement.setAttribute("filename", QString("vanishing point%1.assistant").arg(count));
745 assistantsElement.appendChild(assistantElement);
746 }
747 else if (d->s->id == "infinite ruler"){
748 QDomElement assistantElement = doc.createElement("assistant");
749 assistantElement.setAttribute("type", "infinite ruler");
750 assistantElement.setAttribute("filename", QString("infinite ruler%1.assistant").arg(count));
751 assistantsElement.appendChild(assistantElement);
752 }
753 else if (d->s->id == "parallel ruler"){
754 QDomElement assistantElement = doc.createElement("assistant");
755 assistantElement.setAttribute("type", "parallel ruler");
756 assistantElement.setAttribute("filename", QString("parallel ruler%1.assistant").arg(count));
757 assistantsElement.appendChild(assistantElement);
758 }
759 else if (d->s->id == "concentric ellipse"){
760 QDomElement assistantElement = doc.createElement("assistant");
761 assistantElement.setAttribute("type", "concentric ellipse");
762 assistantElement.setAttribute("filename", QString("concentric ellipse%1.assistant").arg(count));
763 assistantsElement.appendChild(assistantElement);
764 }
765 else if (d->s->id == "fisheye-point"){
766 QDomElement assistantElement = doc.createElement("assistant");
767 assistantElement.setAttribute("type", "fisheye-point");
768 assistantElement.setAttribute("filename", QString("fisheye-point%1.assistant").arg(count));
769 assistantsElement.appendChild(assistantElement);
770 }
771 else if (d->s->id == "ruler"){
772 QDomElement assistantElement = doc.createElement("assistant");
773 assistantElement.setAttribute("type", "ruler");
774 assistantElement.setAttribute("filename", QString("ruler%1.assistant").arg(count));
775 assistantsElement.appendChild(assistantElement);
776 }
777 else if (d->s->id == "two point"){
778 QDomElement assistantElement = doc.createElement("assistant");
779 assistantElement.setAttribute("type", "two point");
780 assistantElement.setAttribute("filename", QString("two point%1.assistant").arg(count));
781 assistantsElement.appendChild(assistantElement);
782 }
783 else if (d->s->id == "perspective ellipse"){
784 QDomElement assistantElement = doc.createElement("assistant");
785 assistantElement.setAttribute("type", "perspective ellipse");
786 assistantElement.setAttribute("filename", QString("perspective ellipse%1.assistant").arg(count));
787 assistantsElement.appendChild(assistantElement);
788 }
789 else if (d->s->id == "curvilinear-perspective"){
790 QDomElement assistantElement = doc.createElement("assistant");
791 assistantElement.setAttribute("type", "curvilinear-perspective");
792 assistantElement.setAttribute("filename", QString("curvilinear-perspective%1.assistant").arg(count));
793 assistantsElement.appendChild(assistantElement);
794 }
795}

References d, and KisPaintingAssistant::Private::s.

◆ secondLocalHandle()

KisPaintingAssistantHandleSP KisPaintingAssistant::secondLocalHandle ( ) const
protectedvirtual

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 in ParallelRulerAssistant, TwoPointAssistant, and VanishingPointAssistant.

Definition at line 1095 of file kis_painting_assistant.cc.

1096{
1097 return 0;
1098}

◆ setAdjustedBrushPosition()

void KisPaintingAssistant::setAdjustedBrushPosition ( const QPointF position)
virtual

Definition at line 300 of file kis_painting_assistant.cc.

301{
302 d->s->adjustedBrushPosition = position;
303 d->s->adjustedPositionValid = true;
304}

References d, and KisPaintingAssistant::Private::s.

◆ setAssistantCustomColor()

void KisPaintingAssistant::setAssistantCustomColor ( QColor color)

Definition at line 229 of file kis_painting_assistant.cc.

230{
231 d->s->assistantCustomColor = color;
232}

References d, and KisPaintingAssistant::Private::s.

◆ setAssistantGlobalColorCache()

void KisPaintingAssistant::setAssistantGlobalColorCache ( const QColor & color)

Definition at line 239 of file kis_painting_assistant.cc.

240{
241 d->s->assistantGlobalColorCache = color;
242}

References d, and KisPaintingAssistant::Private::s.

◆ setDecorationThickness()

void KisPaintingAssistant::setDecorationThickness ( int thickness)

Definition at line 1121 of file kis_painting_assistant.cc.

1122{
1123 d->decorationThickness = thickness;
1124}

References d, and KisPaintingAssistant::Private::decorationThickness.

◆ setDuplicating()

void KisPaintingAssistant::setDuplicating ( bool value)

setDuplicating

Parameters
valuesetter function sets the indication that the duplication button is pressed

Definition at line 341 of file kis_painting_assistant.cc.

342{
343 d->s->isDuplicating = value;
344}
float value(const T *src, size_t ch)

References d, KisPaintingAssistant::Private::s, and value().

◆ setEditorWidgetOffset()

void KisPaintingAssistant::setEditorWidgetOffset ( QPointF offset)

Definition at line 356 of file kis_painting_assistant.cc.

357{
358 d->s->editorWidgetOffset = offset;
359}

References d, and KisPaintingAssistant::Private::s.

◆ setFollowBrushPosition()

void KisPaintingAssistant::setFollowBrushPosition ( bool follow)
virtual

Definition at line 306 of file kis_painting_assistant.cc.

307{
308 d->s->followBrushPosition = follow;
309}

References d, and KisPaintingAssistant::Private::s.

◆ setLocal()

void KisPaintingAssistant::setLocal ( bool value)

setLocal

Parameters
valueset the indication if the assistant is limited to a rectangular area or not

Definition at line 326 of file kis_painting_assistant.cc.

327{
328 d->s->isLocal = value;
329}

References d, KisPaintingAssistant::Private::s, and value().

◆ setLocked()

void KisPaintingAssistant::setLocked ( bool value)

setLocked

Parameters
valueset the indication if the assistant is locked (= cannot be moved, or edited in any way) or not

Definition at line 336 of file kis_painting_assistant.cc.

337{
338 d->s->isLocked = value;
339}

References d, KisPaintingAssistant::Private::s, and value().

◆ setSnappingActive()

void KisPaintingAssistant::setSnappingActive ( bool set)

Definition at line 288 of file kis_painting_assistant.cc.

289{
290 d->s->isSnappingActive = set;
291}

References d, and KisPaintingAssistant::Private::s.

◆ setUseCustomColor()

void KisPaintingAssistant::setUseCustomColor ( bool useCustomColor)

Definition at line 224 of file kis_painting_assistant.cc.

225{
226 d->s->useCustomColor = useCustomColor;
227}

References d, KisPaintingAssistant::Private::s, and useCustomColor().

◆ sideHandles() [1/2]

QList< KisPaintingAssistantHandleSP > KisPaintingAssistant::sideHandles ( )

Definition at line 1032 of file kis_painting_assistant.cc.

1033{
1034 return d->sideHandles;
1035}

References d, and KisPaintingAssistant::Private::sideHandles.

◆ sideHandles() [2/2]

const QList< KisPaintingAssistantHandleSP > & KisPaintingAssistant::sideHandles ( ) const

Definition at line 1027 of file kis_painting_assistant.cc.

1028{
1029 return d->sideHandles;
1030}

References d, and KisPaintingAssistant::Private::sideHandles.

◆ topLeft() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::topLeft ( )

Definition at line 937 of file kis_painting_assistant.cc.

938{
939 return d->topLeft;
940}

References d, and KisPaintingAssistant::Private::topLeft.

◆ topLeft() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::topLeft ( ) const

Get the topLeft, bottomLeft, topRight and BottomRight corners of the assistant Some assistants like the perspective grid have custom logic built around certain handles

Definition at line 942 of file kis_painting_assistant.cc.

943{
944 return d->topLeft;
945}

References d, and KisPaintingAssistant::Private::topLeft.

◆ topMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::topMiddle ( )

Definition at line 977 of file kis_painting_assistant.cc.

978{
979 return d->topMiddle;
980}

References d, and KisPaintingAssistant::Private::topMiddle.

◆ topMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::topMiddle ( ) const

Definition at line 982 of file kis_painting_assistant.cc.

983{
984 return d->topMiddle;
985}

References d, and KisPaintingAssistant::Private::topMiddle.

◆ topRight() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::topRight ( )

Definition at line 957 of file kis_painting_assistant.cc.

958{
959 return d->topRight;
960}

References d, and KisPaintingAssistant::Private::topRight.

◆ topRight() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::topRight ( ) const

Definition at line 962 of file kis_painting_assistant.cc.

963{
964 return d->topRight;
965}

References d, and KisPaintingAssistant::Private::topRight.

◆ transform()

void KisPaintingAssistant::transform ( const QTransform & transform)
virtual

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

Reimplemented in ConcentricEllipseAssistant, and EllipseAssistant.

Definition at line 557 of file kis_painting_assistant.cc.

558{
559 Q_FOREACH(KisPaintingAssistantHandleSP handle, handles()) {
560 if (handle->chiefAssistant() != this) continue;
561
562 *handle = transform.map(*handle);
563 }
564
565 Q_FOREACH(KisPaintingAssistantHandleSP handle, sideHandles()) {
566 if (handle->chiefAssistant() != this) continue;
567
568 *handle = transform.map(*handle);
569 }
570
571 uncache();
572}
KisPaintingAssistant * chiefAssistant() const
const QList< KisPaintingAssistantHandleSP > & sideHandles() const

References KisPaintingAssistantHandle::chiefAssistant(), handles(), sideHandles(), transform(), and uncache().

◆ uncache()

void KisPaintingAssistant::uncache ( )

Definition at line 538 of file kis_painting_assistant.cc.

539{
540 d->s->cached = QPixmapCache::Key();
541}

References d, and KisPaintingAssistant::Private::s.

◆ useCustomColor()

bool KisPaintingAssistant::useCustomColor ( )

Definition at line 219 of file kis_painting_assistant.cc.

220{
221 return d->s->useCustomColor;
222}

References d, and KisPaintingAssistant::Private::s.

◆ viewportConstrainedEditorPosition()

QPointF KisPaintingAssistant::viewportConstrainedEditorPosition ( const KisCoordinatesConverter * converter,
const QSize editorSize )

Definition at line 462 of file kis_painting_assistant.cc.

463{
464 QPointF editorDocumentPos = getEditorPosition();
465 QPointF editorWidgetPos = converter->documentToWidgetTransform().map(editorDocumentPos);
466 QSizeF canvasSize = converter->getCanvasWidgetSize();
467 const int padding = 16;
468
469 editorWidgetPos.rx() = qBound(0.0,
470 editorWidgetPos.x(),
471 canvasSize.width() - (editorSize.width() + padding));
472 editorWidgetPos.ry() = qBound(0.0,
473 editorWidgetPos.y(),
474 canvasSize.height() - (editorSize.height() + padding));
475
476 return converter->widgetToDocument(editorWidgetPos);
477}
_Private::Traits< T >::Result widgetToDocument(const T &obj) const
virtual QPointF getEditorPosition() const

References KisCoordinatesConverter::documentToWidgetTransform(), KisCoordinatesConverter::getCanvasWidgetSize(), getEditorPosition(), and KisCoordinatesConverter::widgetToDocument().

Member Data Documentation

◆ d

Private* const KisPaintingAssistant::d
private

Definition at line 311 of file kis_painting_assistant.h.

◆ m_handles

QList<KisPaintingAssistantHandleSP> KisPaintingAssistant::m_handles
protected

Definition at line 259 of file kis_painting_assistant.h.

◆ m_hasBeenInsideLocalRect

bool KisPaintingAssistant::m_hasBeenInsideLocalRect {false}
protected

Definition at line 307 of file kis_painting_assistant.h.

307{false};

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