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, const KoColorDisplayRendererInterface *displayRenderInterface, bool cached, KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true)
 
void drawError (QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface)
 
void drawPath (QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface, bool drawActive=true)
 
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
 
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, const KoColorDisplayRendererInterface *displayRenderInterface, 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 91 of file kis_painting_assistant.h.

Constructor & Destructor Documentation

◆ KisPaintingAssistant() [1/2]

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

Definition at line 250 of file kis_painting_assistant.cc.

250 : d(new Private)
251{
252 d->s->id = id;
253 d->s->name = name;
254 d->s->isSnappingActive = true;
255 d->s->outlineVisible = true;
256}
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 419 of file kis_painting_assistant.cc.

420{
421 Q_FOREACH (KisPaintingAssistantHandleSP handle, d->handles) {
422 handle->unregisterAssistant(this);
423 }
424 if(!d->sideHandles.isEmpty()) {
425 Q_FOREACH (KisPaintingAssistantHandleSP handle, d->sideHandles) {
426 handle->unregisterAssistant(this);
427 }
428 }
429 delete d;
430}
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 258 of file kis_painting_assistant.cc.

262 , d(new Private(*(rhs.d)))
263{
264 dbgUI << "creating handles...";
265 Q_FOREACH (const KisPaintingAssistantHandleSP origHandle, rhs.d->handles) {
266 d->handles << d->reuseOrCreateHandle(handleMap, origHandle, this);
267 }
268 Q_FOREACH (const KisPaintingAssistantHandleSP origHandle, rhs.d->sideHandles) {
269 d->sideHandles << d->reuseOrCreateHandle(handleMap, origHandle, this);
270 }
271#define _REUSE_H(name) d->name = d->reuseOrCreateHandle(handleMap, rhs.d->name, this, /* registerAssistant = */ false)
280#undef _REUSE_H
281 dbgUI << "done";
282}
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 451 of file kis_painting_assistant.cc.

452{
453 Q_ASSERT(!d->handles.contains(handle));
454 if (HandleType::SIDE == type) {
455 d->sideHandles.append(handle);
456 } else {
457 d->handles.append(handle);
458 }
459
460 handle->registerAssistant(this);
461 handle.data()->setType(type);
462}
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 1041 of file kis_painting_assistant.cc.

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

◆ assistantCustomColor()

QColor KisPaintingAssistant::assistantCustomColor ( )

Definition at line 235 of file kis_painting_assistant.cc.

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

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

◆ bottomLeft() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::bottomLeft ( )

Definition at line 949 of file kis_painting_assistant.cc.

950{
951 return d->bottomLeft;
952}
KisPaintingAssistantHandleSP bottomLeft

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

◆ bottomLeft() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::bottomLeft ( ) const

Definition at line 954 of file kis_painting_assistant.cc.

955{
956 return d->bottomLeft;
957}

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

◆ bottomMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::bottomMiddle ( )

Definition at line 989 of file kis_painting_assistant.cc.

990{
991 return d->bottomMiddle;
992}
KisPaintingAssistantHandleSP bottomMiddle

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

◆ bottomMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::bottomMiddle ( ) const

Definition at line 994 of file kis_painting_assistant.cc.

995{
996 return d->bottomMiddle;
997}

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

◆ bottomRight() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::bottomRight ( )

Definition at line 969 of file kis_painting_assistant.cc.

970{
971 return d->bottomRight;
972}
KisPaintingAssistantHandleSP bottomRight

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

◆ bottomRight() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::bottomRight ( ) const

Definition at line 974 of file kis_painting_assistant.cc.

975{
976 return d->bottomRight;
977}

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

◆ boundingRect()

QRect KisPaintingAssistant::boundingRect ( ) const
protectedvirtual

Reimplemented in ConcentricEllipseAssistant, EllipseAssistant, FisheyePointAssistant, and PerspectiveEllipseAssistant.

Definition at line 545 of file kis_painting_assistant.cc.

546{
547 QRectF r;
548 Q_FOREACH (KisPaintingAssistantHandleSP h, handles()) {
549 r = r.united(QRectF(*h, QSizeF(1,1)));
550 }
551 return r.adjusted(-2, -2, 2, 2).toAlignedRect();
552}
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 317 of file kis_painting_assistant.cc.

318{
319 return false;
320}

◆ 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 1128 of file kis_painting_assistant.cc.

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

◆ closestCornerHandleFromPoint()

KisPaintingAssistantHandleSP KisPaintingAssistant::closestCornerHandleFromPoint ( QPointF point)

Definition at line 1049 of file kis_painting_assistant.cc.

1050{
1051 if (!d->s->m_canvas) {
1052 return 0;
1053 }
1054
1055
1056 if (areTwoPointsClose(point, pixelToView(topLeft()->toPoint()))) {
1057 return topLeft();
1058 } else if (areTwoPointsClose(point, pixelToView(topRight()->toPoint()))) {
1059 return topRight();
1060 } else if (areTwoPointsClose(point, pixelToView(bottomLeft()->toPoint()))) {
1061 return bottomLeft();
1062 } else if (areTwoPointsClose(point, pixelToView(bottomRight()->toPoint()))) {
1063 return bottomRight();
1064 }
1065 return 0;
1066}
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 189 of file kis_painting_assistant.cc.

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

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

◆ drawAssistant()

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

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

Definition at line 481 of file kis_painting_assistant.cc.

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

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

◆ drawCache()

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

◆ drawError()

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

Definition at line 391 of file kis_painting_assistant.cc.

392{
393 painter.save();
394 const QColor error = displayRenderInterface->convertColorToDisplayColorSpace(KoColor(QColor(255, 0, 0, 125), KoColorSpaceRegistry::instance()->rgb8()));
395 QPen pen_a(error, d->errorLineWidth * d->decorationThickness);
396 pen_a.setCosmetic(true);
397 painter.setPen(pen_a);
398 painter.drawPath(path);
399 painter.restore();
400}
virtual QColor convertColorToDisplayColorSpace(const KoColor color) const =0
convertColorToDisplayColorSpace
static KoColorSpaceRegistry * instance()

References KoColorDisplayRendererInterface::convertColorToDisplayColorSpace(), d, KisPaintingAssistant::Private::decorationThickness, KisPaintingAssistant::Private::errorLineWidth, and KoColorSpaceRegistry::instance().

◆ drawPath()

void KisPaintingAssistant::drawPath ( QPainter & painter,
const QPainterPath & path,
const KoColorDisplayRendererInterface * displayRenderInterface,
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 363 of file kis_painting_assistant.cc.

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

References KoColorDisplayRendererInterface::convertColorToDisplayColorSpace(), d, KisPaintingAssistant::Private::decorationThickness, effectiveAssistantColor(), KoColorSpaceRegistry::instance(), and KisPaintingAssistant::Private::mainLineWidth.

◆ drawPreview()

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

Definition at line 380 of file kis_painting_assistant.cc.

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

References KoColorDisplayRendererInterface::convertColorToDisplayColorSpace(), d, effectiveAssistantColor(), KoColorSpaceRegistry::instance(), and KisPaintingAssistant::Private::previewLineWidth.

◆ drawX()

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

Definition at line 402 of file kis_painting_assistant.cc.

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

References drawPath().

◆ editorWidgetOffset()

QPointF KisPaintingAssistant::editorWidgetOffset ( )

Definition at line 352 of file kis_painting_assistant.cc.

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

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

◆ effectiveAssistantColor()

QColor KisPaintingAssistant::effectiveAssistantColor ( ) const

Definition at line 245 of file kis_painting_assistant.cc.

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

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 1075 of file kis_painting_assistant.cc.

1076{
1077 QPointF mousePos;
1078
1079 if (d->s->followBrushPosition && d->s->adjustedPositionValid) {
1080 mousePos = converter->documentToWidget(d->s->adjustedBrushPosition);
1081 } else if (canvas) {
1082 // FIXME: this may be simple and cheap, but it's only integer precision!
1083 mousePos= canvas->canvasWidget()->mapFromGlobal(QCursor::pos());
1084 } else {
1085 //...of course, you need to have access to a canvas-widget for that.//
1086 mousePos = QCursor::pos(); //this'll give an offset//
1087 dbgUI << "no canvas given for assistant, you may have passed arguments incorrectly:";
1088 }
1089 return mousePos;
1090}
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 294 of file kis_painting_assistant.cc.

295{
296 d->s->adjustedPositionValid = false;
297 d->s->followBrushPosition = false;
299}

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

◆ findPerspectiveAssistantHandleLocation()

void KisPaintingAssistant::findPerspectiveAssistantHandleLocation ( )

Definition at line 799 of file kis_painting_assistant.cc.

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

1093{
1094 return 0;
1095}

◆ getDefaultEditorPosition()

◆ getEditorPosition()

QPointF KisPaintingAssistant::getEditorPosition ( ) const
virtual

Definition at line 312 of file kis_painting_assistant.cc.

313{
314 return getDefaultEditorPosition() + d->s->editorWidgetOffset;
315}
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 1102 of file kis_painting_assistant.cc.

1103{
1104 if (!isLocal() || !firstLocalHandle() || !secondLocalHandle()) {
1105 return QRectF();
1106 }
1107
1110
1111 QPointF topLeft = QPointF(qMin(first->x(), second->x()), qMin(first->y(), second->y()));
1112 QPointF bottomRight = QPointF(qMax(first->x(), second->x()), qMax(first->y(), second->y()));
1113
1114 QRectF rect(topLeft, bottomRight);
1115 return rect;
1116}
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 1024 of file kis_painting_assistant.cc.

1025{
1026 return d->handles;
1027}

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

◆ handles() [2/2]

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

Definition at line 1019 of file kis_painting_assistant.cc.

1020{
1021 return d->handles;
1022}

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

◆ id()

const QString & KisPaintingAssistant::id ( ) const

Definition at line 432 of file kis_painting_assistant.cc.

433{
434 return d->s->id;
435}

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

◆ initHandles()

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

Definition at line 410 of file kis_painting_assistant.cc.

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

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 554 of file kis_painting_assistant.cc.

555{
556 return true;
557}

◆ isDuplicating()

bool KisPaintingAssistant::isDuplicating ( )

isDuplicating

Returns
If the duplication button is pressed

Definition at line 347 of file kis_painting_assistant.cc.

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

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 322 of file kis_painting_assistant.cc.

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

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 332 of file kis_painting_assistant.cc.

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

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

◆ isSnappingActive()

bool KisPaintingAssistant::isSnappingActive ( ) const

Definition at line 284 of file kis_painting_assistant.cc.

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

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

◆ leftMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::leftMiddle ( )

Definition at line 1009 of file kis_painting_assistant.cc.

1010{
1011 return d->leftMiddle;
1012}

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

◆ leftMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::leftMiddle ( ) const

Definition at line 1014 of file kis_painting_assistant.cc.

1015{
1016 return d->leftMiddle;
1017}

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

◆ loadCustomXml()

bool KisPaintingAssistant::loadCustomXml ( QXmlStreamReader * xml)
virtual

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

Definition at line 717 of file kis_painting_assistant.cc.

718{
719 Q_UNUSED(xml);
720 return true;
721}

◆ loadXml()

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

Definition at line 633 of file kis_painting_assistant.cc.

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

438{
439 return d->s->name;
440}

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

◆ norm2()

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

Definition at line 1118 of file kis_painting_assistant.cc.

1119{
1120 return p.x() * p.x() + p.y() * p.y();
1121}
const Params2D p

References p.

◆ numHandles()

◆ oppHandleOne()

KisPaintingAssistantHandleSP KisPaintingAssistant::oppHandleOne ( )

Definition at line 920 of file kis_painting_assistant.cc.

921{
922 QPointF intersection(0,0);
923 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)
924 && (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))
925 {
926 return d->handles.at(1);
927 }
928 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)
929 && (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))
930 {
931 return d->handles.at(2);
932 }
933 else
934 {
935 return d->handles.at(3);
936 }
937}

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

◆ pixelToView()

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

Definition at line 1069 of file kis_painting_assistant.cc.

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

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

◆ replaceHandle()

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

Definition at line 442 of file kis_painting_assistant.cc.

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

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

◆ rightMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::rightMiddle ( )

Definition at line 999 of file kis_painting_assistant.cc.

1000{
1001 return d->rightMiddle;
1002}

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

◆ rightMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::rightMiddle ( ) const

Definition at line 1004 of file kis_painting_assistant.cc.

1005{
1006 return d->rightMiddle;
1007}

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

◆ saveCustomXml()

void KisPaintingAssistant::saveCustomXml ( QXmlStreamWriter * xml)
virtual

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

Definition at line 628 of file kis_painting_assistant.cc.

629{
630 Q_UNUSED(xml);
631}

◆ saveXml()

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

Definition at line 576 of file kis_painting_assistant.cc.

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

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

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 1097 of file kis_painting_assistant.cc.

1098{
1099 return 0;
1100}

◆ setAdjustedBrushPosition()

void KisPaintingAssistant::setAdjustedBrushPosition ( const QPointF position)
virtual

Definition at line 301 of file kis_painting_assistant.cc.

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

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

◆ setAssistantCustomColor()

void KisPaintingAssistant::setAssistantCustomColor ( QColor color)

Definition at line 230 of file kis_painting_assistant.cc.

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

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

◆ setAssistantGlobalColorCache()

void KisPaintingAssistant::setAssistantGlobalColorCache ( const QColor & color)

Definition at line 240 of file kis_painting_assistant.cc.

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

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

◆ setDecorationThickness()

void KisPaintingAssistant::setDecorationThickness ( int thickness)

Definition at line 1123 of file kis_painting_assistant.cc.

1124{
1125 d->decorationThickness = thickness;
1126}

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 342 of file kis_painting_assistant.cc.

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

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

◆ setEditorWidgetOffset()

void KisPaintingAssistant::setEditorWidgetOffset ( QPointF offset)

Definition at line 357 of file kis_painting_assistant.cc.

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

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

◆ setFollowBrushPosition()

void KisPaintingAssistant::setFollowBrushPosition ( bool follow)
virtual

Definition at line 307 of file kis_painting_assistant.cc.

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

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 327 of file kis_painting_assistant.cc.

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

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 337 of file kis_painting_assistant.cc.

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

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

◆ setSnappingActive()

void KisPaintingAssistant::setSnappingActive ( bool set)

Definition at line 289 of file kis_painting_assistant.cc.

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

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

◆ setUseCustomColor()

void KisPaintingAssistant::setUseCustomColor ( bool useCustomColor)

Definition at line 225 of file kis_painting_assistant.cc.

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

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

◆ sideHandles() [1/2]

QList< KisPaintingAssistantHandleSP > KisPaintingAssistant::sideHandles ( )

Definition at line 1034 of file kis_painting_assistant.cc.

1035{
1036 return d->sideHandles;
1037}

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

◆ sideHandles() [2/2]

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

Definition at line 1029 of file kis_painting_assistant.cc.

1030{
1031 return d->sideHandles;
1032}

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

◆ topLeft() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::topLeft ( )

Definition at line 939 of file kis_painting_assistant.cc.

940{
941 return d->topLeft;
942}

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 944 of file kis_painting_assistant.cc.

945{
946 return d->topLeft;
947}

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

◆ topMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::topMiddle ( )

Definition at line 979 of file kis_painting_assistant.cc.

980{
981 return d->topMiddle;
982}

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

◆ topMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::topMiddle ( ) const

Definition at line 984 of file kis_painting_assistant.cc.

985{
986 return d->topMiddle;
987}

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

◆ topRight() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::topRight ( )

Definition at line 959 of file kis_painting_assistant.cc.

960{
961 return d->topRight;
962}

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

◆ topRight() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::topRight ( ) const

Definition at line 964 of file kis_painting_assistant.cc.

965{
966 return d->topRight;
967}

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 559 of file kis_painting_assistant.cc.

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

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

◆ uncache()

void KisPaintingAssistant::uncache ( )

Definition at line 540 of file kis_painting_assistant.cc.

541{
542 d->s->cached = QPixmapCache::Key();
543}

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

◆ useCustomColor()

bool KisPaintingAssistant::useCustomColor ( )

Definition at line 220 of file kis_painting_assistant.cc.

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

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

◆ viewportConstrainedEditorPosition()

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

Definition at line 464 of file kis_painting_assistant.cc.

465{
466 QPointF editorDocumentPos = getEditorPosition();
467 QPointF editorWidgetPos = converter->documentToWidgetTransform().map(editorDocumentPos);
468 QSizeF canvasSize = converter->getCanvasWidgetSize();
469 const int padding = 16;
470
471 editorWidgetPos.rx() = qBound(0.0,
472 editorWidgetPos.x(),
473 canvasSize.width() - (editorSize.width() + padding));
474 editorWidgetPos.ry() = qBound(0.0,
475 editorWidgetPos.y(),
476 canvasSize.height() - (editorSize.height() + padding));
477
478 return converter->widgetToDocument(editorWidgetPos);
479}
_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 312 of file kis_painting_assistant.h.

◆ m_handles

QList<KisPaintingAssistantHandleSP> KisPaintingAssistant::m_handles
protected

Definition at line 260 of file kis_painting_assistant.h.

◆ m_hasBeenInsideLocalRect

bool KisPaintingAssistant::m_hasBeenInsideLocalRect {false}
protected

Definition at line 308 of file kis_painting_assistant.h.

308{false};

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