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
 
int brushPriority () 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, QPen startingPen=QPen())
 
void drawPreview (QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface)
 
void drawX (QPainter &painter, const QPointF &pt, const KoColorDisplayRendererInterface *displayRenderInterface)
 
QPointF editorWidgetOffset ()
 
QColor effectiveAssistantColor () const
 
virtual void endStroke ()
 
void findPerspectiveAssistantHandleLocation ()
 
virtual QPointF getDefaultEditorPosition () const =0
 
virtual QPointF getEditorPosition () const
 
QList< KisPaintingAssistantHandleSP > handles ()
 
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 setBrushPriority (int priority)
 
void setDecorationThickness (int thickness)
 
void setDuplicating (bool value)
 setDuplicating
 
void setEditorWidgetOffset (QPointF offset)
 
virtual void setFollowBrushPosition (bool follow)
 
void setLocal (bool value)
 setLocal
 
void setLocked (bool value)
 setLocked
 
void setSnappingActive (bool set)
 
void setUseCustomColor (bool useCustomColor)
 
QList< KisPaintingAssistantHandleSP > sideHandles ()
 
const QList< KisPaintingAssistantHandleSP > & sideHandles () const
 
KisPaintingAssistantHandleSP topLeft ()
 
const KisPaintingAssistantHandleSP topLeft () const
 
KisPaintingAssistantHandleSP topMiddle ()
 
const KisPaintingAssistantHandleSP topMiddle () const
 
KisPaintingAssistantHandleSP topRight ()
 
const KisPaintingAssistantHandleSP topRight () const
 
virtual void transform (const QTransform &transform)
 
void uncache ()
 
bool useCustomColor ()
 
QPointF viewportConstrainedEditorPosition (const KisCoordinatesConverter *converter, const QSize editorSize)
 
virtual ~KisPaintingAssistant ()
 

Static Public Member Functions

static QList< KisPaintingAssistantSP > cloneAssistantList (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< KisPaintingAssistantHandleSP > m_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 92 of file kis_painting_assistant.h.

Constructor & Destructor Documentation

◆ KisPaintingAssistant() [1/2]

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

Definition at line 251 of file kis_painting_assistant.cc.

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

433{
434 Q_FOREACH (KisPaintingAssistantHandleSP handle, d->handles) {
435 handle->unregisterAssistant(this);
436 }
437 if(!d->sideHandles.isEmpty()) {
438 Q_FOREACH (KisPaintingAssistantHandleSP handle, d->sideHandles) {
439 handle->unregisterAssistant(this);
440 }
441 }
442 delete d;
443}
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 259 of file kis_painting_assistant.cc.

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

465{
466 Q_ASSERT(!d->handles.contains(handle));
467 if (HandleType::SIDE == type) {
468 d->sideHandles.append(handle);
469 } else {
470 d->handles.append(handle);
471 }
472
473 handle->registerAssistant(this);
474 handle.data()->setType(type);
475}
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 1059 of file kis_painting_assistant.cc.

1060{
1061 int m_handleSize = 16;
1062
1063 QRectF handlerect(pointTwo - QPointF(m_handleSize * 0.5, m_handleSize * 0.5), QSizeF(m_handleSize, m_handleSize));
1064 return handlerect.contains(pointOne);
1065}

◆ assistantCustomColor()

QColor KisPaintingAssistant::assistantCustomColor ( )

Definition at line 236 of file kis_painting_assistant.cc.

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

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

◆ bottomLeft() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::bottomLeft ( )

Definition at line 967 of file kis_painting_assistant.cc.

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

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

◆ bottomLeft() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::bottomLeft ( ) const

Definition at line 972 of file kis_painting_assistant.cc.

973{
974 return d->bottomLeft;
975}

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

◆ bottomMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::bottomMiddle ( )

Definition at line 1007 of file kis_painting_assistant.cc.

1008{
1009 return d->bottomMiddle;
1010}
KisPaintingAssistantHandleSP bottomMiddle

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

◆ bottomMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::bottomMiddle ( ) const

Definition at line 1012 of file kis_painting_assistant.cc.

1013{
1014 return d->bottomMiddle;
1015}

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

◆ bottomRight() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::bottomRight ( )

Definition at line 987 of file kis_painting_assistant.cc.

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

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

◆ bottomRight() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::bottomRight ( ) const

Definition at line 992 of file kis_painting_assistant.cc.

993{
994 return d->bottomRight;
995}

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

◆ boundingRect()

QRect KisPaintingAssistant::boundingRect ( ) const
protectedvirtual

Reimplemented in ConcentricEllipseAssistant, EllipseAssistant, FisheyePointAssistant, and PerspectiveEllipseAssistant.

Definition at line 558 of file kis_painting_assistant.cc.

559{
560 QRectF r;
561 Q_FOREACH (KisPaintingAssistantHandleSP h, handles()) {
562 r = r.united(QRectF(*h, QSizeF(1,1)));
563 }
564 return r.adjusted(-2, -2, 2, 2).toAlignedRect();
565}
const QList< KisPaintingAssistantHandleSP > & handles() const

References handles().

◆ brushPriority()

int KisPaintingAssistant::brushPriority ( ) const

Definition at line 295 of file kis_painting_assistant.cc.

296{
297 return d->s->brushPriority;
298}

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

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

329{
330 return false;
331}

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

1147{
1148 QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> handleMap;
1150 for (auto i = list.begin(); i != list.end(); ++i) {
1151 clonedList << (*i)->clone(handleMap);
1152 }
1153 return clonedList;
1154}

◆ closestCornerHandleFromPoint()

KisPaintingAssistantHandleSP KisPaintingAssistant::closestCornerHandleFromPoint ( QPointF point)

Definition at line 1067 of file kis_painting_assistant.cc.

1068{
1069 if (!d->s->m_canvas) {
1070 return 0;
1071 }
1072
1073
1074 if (areTwoPointsClose(point, pixelToView(topLeft()->toPoint()))) {
1075 return topLeft();
1076 } else if (areTwoPointsClose(point, pixelToView(topRight()->toPoint()))) {
1077 return topRight();
1078 } else if (areTwoPointsClose(point, pixelToView(bottomLeft()->toPoint()))) {
1079 return bottomLeft();
1080 } else if (areTwoPointsClose(point, pixelToView(bottomRight()->toPoint()))) {
1081 return bottomRight();
1082 }
1083 return 0;
1084}
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 190 of file kis_painting_assistant.cc.

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

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

495{
496 Q_UNUSED(updateRect);
497
498 Q_UNUSED(previewVisible);
499
501
502 if (!useCache) {
503 gc.save();
504 drawCache(gc, converter, displayRenderInterface, assistantVisible);
505 gc.restore();
506 return;
507 }
508
509 const QRect bound = boundingRect();
510 if (bound.isEmpty()) {
511 return;
512 }
513
514 const QTransform transform = converter->documentToWidgetTransform();
515 const QRect widgetBound = transform.mapRect(bound);
516
517 const QRect paintRect = transform.mapRect(bound).intersected(gc.viewport());
518 if (paintRect.isEmpty()) return;
519
520 QPixmap cached;
521 bool found = QPixmapCache::find(d->s->cached, &cached);
522
523 if (!(found &&
524 d->s->cachedTransform == transform &&
525 d->s->cachedRect.translated(widgetBound.topLeft()).contains(paintRect))) {
526
527 const QRect cacheRect = gc.viewport().adjusted(-100, -100, 100, 100).intersected(widgetBound);
528 Q_ASSERT(!cacheRect.isEmpty());
529
530 if (cached.isNull() || cached.size() != cacheRect.size()) {
531 cached = QPixmap(cacheRect.size());
532 }
533
534 cached.fill(Qt::transparent);
535 QPainter painter(&cached);
536 painter.setRenderHint(QPainter::Antialiasing);
537 painter.setWindow(cacheRect);
538 drawCache(painter, converter, displayRenderInterface, assistantVisible);
539 painter.end();
540 d->s->cachedTransform = transform;
541 d->s->cachedRect = cacheRect.translated(-widgetBound.topLeft());
542 d->s->cached = QPixmapCache::insert(cached);
543 }
544
545 gc.drawPixmap(paintRect, cached, paintRect.translated(-widgetBound.topLeft() - d->s->cachedRect.topLeft()));
546
547
548 if (canvas) {
549 d->s->m_canvas = canvas;
550 }
551}
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 404 of file kis_painting_assistant.cc.

405{
406 painter.save();
407 const QColor error = displayRenderInterface->convertColorToDisplayColorSpace(KoColor(QColor(255, 0, 0, 125), KoColorSpaceRegistry::instance()->rgb8()));
408 QPen pen_a(error, d->errorLineWidth * d->decorationThickness);
409 pen_a.setCosmetic(true);
410 painter.setPen(pen_a);
411 painter.drawPath(path);
412 painter.restore();
413}
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,
QPen startingPen = QPen() )

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

Definition at line 374 of file kis_painting_assistant.cc.

375{
376
377 QColor paintingColor = displayRenderInterface->convertColorToDisplayColorSpace(KoColor(effectiveAssistantColor(), KoColorSpaceRegistry::instance()->rgb8()));;
378
379 if (!isSnappingOn) {
380 paintingColor.setAlpha(0.2 * paintingColor.alpha());
381 }
382
383 painter.save();
384 QPen pen_a = startingPen;
385 pen_a.setColor(paintingColor);
386 pen_a.setWidth(d->mainLineWidth * d->decorationThickness);
387 pen_a.setCosmetic(true);
388 painter.setPen(pen_a);
389 painter.drawPath(path);
390 painter.restore();
391}

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

394{
395 painter.save();
397 pen_a.setStyle(Qt::SolidLine);
398 pen_a.setCosmetic(true);
399 painter.setPen(pen_a);
400 painter.drawPath(path);
401 painter.restore();
402}

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

416{
417 QPainterPath path;
418 path.moveTo(QPointF(pt.x() - 5.0, pt.y() - 5.0)); path.lineTo(QPointF(pt.x() + 5.0, pt.y() + 5.0));
419 path.moveTo(QPointF(pt.x() - 5.0, pt.y() + 5.0)); path.lineTo(QPointF(pt.x() + 5.0, pt.y() - 5.0));
420 drawPath(painter, path, displayRenderInterface);
421}
void drawPath(QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface, bool drawActive=true, QPen startingPen=QPen())

References drawPath().

◆ editorWidgetOffset()

QPointF KisPaintingAssistant::editorWidgetOffset ( )

Definition at line 363 of file kis_painting_assistant.cc.

364{
365 return d->s->editorWidgetOffset;
366}

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

◆ effectiveAssistantColor()

QColor KisPaintingAssistant::effectiveAssistantColor ( ) const

Definition at line 246 of file kis_painting_assistant.cc.

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

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

1094{
1095 QPointF mousePos;
1096
1097 if (d->s->followBrushPosition && d->s->adjustedPositionValid) {
1098 mousePos = converter->documentToWidget(d->s->adjustedBrushPosition);
1099 } else if (canvas) {
1100 // FIXME: this may be simple and cheap, but it's only integer precision!
1101 mousePos= canvas->canvasWidget()->mapFromGlobal(QCursor::pos());
1102 } else {
1103 //...of course, you need to have access to a canvas-widget for that.//
1104 mousePos = QCursor::pos(); //this'll give an offset//
1105 dbgUI << "no canvas given for assistant, you may have passed arguments incorrectly:";
1106 }
1107 return mousePos;
1108}
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 305 of file kis_painting_assistant.cc.

306{
307 d->s->adjustedPositionValid = false;
308 d->s->followBrushPosition = false;
310}

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

◆ findPerspectiveAssistantHandleLocation()

void KisPaintingAssistant::findPerspectiveAssistantHandleLocation ( )

Definition at line 817 of file kis_painting_assistant.cc.

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

1111{
1112 return 0;
1113}

◆ getDefaultEditorPosition()

◆ getEditorPosition()

QPointF KisPaintingAssistant::getEditorPosition ( ) const
virtual

Definition at line 323 of file kis_painting_assistant.cc.

324{
325 return getDefaultEditorPosition() + d->s->editorWidgetOffset;
326}
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 1120 of file kis_painting_assistant.cc.

1121{
1122 if (!isLocal() || !firstLocalHandle() || !secondLocalHandle()) {
1123 return QRectF();
1124 }
1125
1128
1129 QPointF topLeft = QPointF(qMin(first->x(), second->x()), qMin(first->y(), second->y()));
1130 QPointF bottomRight = QPointF(qMax(first->x(), second->x()), qMax(first->y(), second->y()));
1131
1132 QRectF rect(topLeft, bottomRight);
1133 return rect;
1134}
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 1042 of file kis_painting_assistant.cc.

1043{
1044 return d->handles;
1045}

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

◆ handles() [2/2]

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

Definition at line 1037 of file kis_painting_assistant.cc.

1038{
1039 return d->handles;
1040}

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

◆ id()

const QString & KisPaintingAssistant::id ( ) const

Definition at line 445 of file kis_painting_assistant.cc.

446{
447 return d->s->id;
448}

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

◆ initHandles()

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

Definition at line 423 of file kis_painting_assistant.cc.

424{
425 Q_ASSERT(d->handles.isEmpty());
426 d->handles = _handles;
427 Q_FOREACH (KisPaintingAssistantHandleSP handle, _handles) {
428 handle->registerAssistant(this);
429 }
430}

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

568{
569 return true;
570}

◆ isDuplicating()

bool KisPaintingAssistant::isDuplicating ( )

isDuplicating

Returns
If the duplication button is pressed

Definition at line 358 of file kis_painting_assistant.cc.

359{
360 return d->s->isDuplicating;
361}

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

334{
335 return d->s->isLocal;
336}

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

344{
345 return d->s->isLocked;
346}

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

◆ isSnappingActive()

bool KisPaintingAssistant::isSnappingActive ( ) const

Definition at line 285 of file kis_painting_assistant.cc.

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

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

◆ leftMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::leftMiddle ( )

Definition at line 1027 of file kis_painting_assistant.cc.

1028{
1029 return d->leftMiddle;
1030}

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

◆ leftMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::leftMiddle ( ) const

Definition at line 1032 of file kis_painting_assistant.cc.

1033{
1034 return d->leftMiddle;
1035}

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

◆ loadCustomXml()

bool KisPaintingAssistant::loadCustomXml ( QXmlStreamReader * xml)
virtual

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

Definition at line 735 of file kis_painting_assistant.cc.

736{
737 Q_UNUSED(xml);
738 return true;
739}

◆ loadXml()

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

Definition at line 647 of file kis_painting_assistant.cc.

648{
649 int id = 0;
650 double x = 0.0, y = 0.0;
651 store->open(path);
652 QByteArray data = store->read(store->size());
653 QXmlStreamReader xml(data);
654 QMap<int, KisPaintingAssistantHandleSP> sideHandleMap;
655 while (!xml.atEnd()) {
656 switch (xml.readNext()) {
657 case QXmlStreamReader::StartElement:
658 if (xml.name() == "assistant") {
659
660 auto active = xml.attributes().value("active");
661 setSnappingActive( (active != "0") );
662
663 if (xml.attributes().hasAttribute("brushPriority")) {
664 setBrushPriority(xml.attributes().value("brushPriority").toInt());
665 }
666
667 // load custom shared assistant properties
668 if ( xml.attributes().hasAttribute("useCustomColor")) {
669 auto useCustomColor = xml.attributes().value("useCustomColor");
670
671 bool usingColor = false;
672 if (useCustomColor.toString() == "1") {
673 usingColor = true;
674 }
675
676
677 setUseCustomColor(usingColor);
678 }
679
680 if (xml.attributes().hasAttribute("editorWidgetOffset_X") && xml.attributes().hasAttribute("editorWidgetOffset_Y")) {
681 setEditorWidgetOffset(QPointF(xml.attributes().value("editorWidgetOffset_X").toDouble(), xml.attributes().value("editorWidgetOffset_Y").toDouble()));
682 }
683
684 if ( xml.attributes().hasAttribute("customColor")) {
685 auto customColor = xml.attributes().value("customColor");
686 setAssistantCustomColor( KisDomUtils::qStringToQColor(customColor.toString()) );
687
688 }
689
690 if ( xml.attributes().hasAttribute("locked")) {
691 auto locked = xml.attributes().value("locked");
692 setLocked(locked == "1");
693 }
694
695 }
696
697 loadCustomXml(&xml);
698
699 if (xml.name() == "handle") {
700 QString strId = xml.attributes().value("id").toString(),
701 strX = xml.attributes().value("x").toString(),
702 strY = xml.attributes().value("y").toString();
703 if (!strId.isEmpty() && !strX.isEmpty() && !strY.isEmpty()) {
704 id = strId.toInt();
705 x = strX.toDouble();
706 y = strY.toDouble();
707 if (!handleMap.contains(id)) {
708 handleMap.insert(id, new KisPaintingAssistantHandle(x, y));
709 }
710 }
711 addHandle(handleMap.value(id), HandleType::NORMAL);
712 } else if (xml.name() == "sidehandle") {
713 QString strId = xml.attributes().value("id").toString(),
714 strX = xml.attributes().value("x").toString(),
715 strY = xml.attributes().value("y").toString();
716 if (!strId.isEmpty() && !strX.isEmpty() && !strY.isEmpty()) {
717 id = strId.toInt();
718 x = strX.toDouble();
719 y = strY.toDouble();
720 if (!sideHandleMap.contains(id)) {
721 sideHandleMap.insert(id, new KisPaintingAssistantHandle(x, y));
722 }
723 }
724 addHandle(sideHandleMap.value(id), HandleType::SIDE);
725
726 }
727 break;
728 default:
729 break;
730 }
731 }
732 store->close();
733}
void setLocked(bool value)
setLocked
void setBrushPriority(int priority)
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(), setBrushPriority(), setEditorWidgetOffset(), setLocked(), setSnappingActive(), setUseCustomColor(), SIDE, KoStore::size(), and useCustomColor().

◆ name()

const QString & KisPaintingAssistant::name ( ) const

Definition at line 450 of file kis_painting_assistant.cc.

451{
452 return d->s->name;
453}

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

◆ norm2()

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

Definition at line 1136 of file kis_painting_assistant.cc.

1137{
1138 return p.x() * p.x() + p.y() * p.y();
1139}
const Params2D p

References p.

◆ numHandles()

◆ oppHandleOne()

KisPaintingAssistantHandleSP KisPaintingAssistant::oppHandleOne ( )

Definition at line 938 of file kis_painting_assistant.cc.

939{
940 QPointF intersection(0,0);
941 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)
942 && (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))
943 {
944 return d->handles.at(1);
945 }
946 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)
947 && (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))
948 {
949 return d->handles.at(2);
950 }
951 else
952 {
953 return d->handles.at(3);
954 }
955}

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

◆ pixelToView()

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

Definition at line 1087 of file kis_painting_assistant.cc.

1088{
1089 QPointF documentCoord = d->s->m_canvas->image()->pixelToDocument(pixelCoords);
1090 return d->s->m_canvas->viewConverter()->documentToView(documentCoord);
1091}

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

◆ replaceHandle()

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

Definition at line 455 of file kis_painting_assistant.cc.

456{
457 Q_ASSERT(d->handles.contains(_handle));
458 d->handles.replace(d->handles.indexOf(_handle), _with);
459 Q_ASSERT(!d->handles.contains(_handle));
460 _handle->unregisterAssistant(this);
461 _with->registerAssistant(this);
462}

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

◆ rightMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::rightMiddle ( )

Definition at line 1017 of file kis_painting_assistant.cc.

1018{
1019 return d->rightMiddle;
1020}

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

◆ rightMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::rightMiddle ( ) const

Definition at line 1022 of file kis_painting_assistant.cc.

1023{
1024 return d->rightMiddle;
1025}

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

◆ saveCustomXml()

void KisPaintingAssistant::saveCustomXml ( QXmlStreamWriter * xml)
virtual

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

Definition at line 642 of file kis_painting_assistant.cc.

643{
644 Q_UNUSED(xml);
645}

◆ saveXml()

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

Definition at line 589 of file kis_painting_assistant.cc.

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

742{
743 if (d->s->id == "ellipse"){
744 QDomElement assistantElement = doc.createElement("assistant");
745 assistantElement.setAttribute("type", "ellipse");
746 assistantElement.setAttribute("filename", QString("ellipse%1.assistant").arg(count));
747 assistantsElement.appendChild(assistantElement);
748 }
749 else if (d->s->id == "spline"){
750 QDomElement assistantElement = doc.createElement("assistant");
751 assistantElement.setAttribute("type", "spline");
752 assistantElement.setAttribute("filename", QString("spline%1.assistant").arg(count));
753 assistantsElement.appendChild(assistantElement);
754 }
755 else if (d->s->id == "perspective"){
756 QDomElement assistantElement = doc.createElement("assistant");
757 assistantElement.setAttribute("type", "perspective");
758 assistantElement.setAttribute("filename", QString("perspective%1.assistant").arg(count));
759 assistantsElement.appendChild(assistantElement);
760 }
761 else if (d->s->id == "vanishing point"){
762 QDomElement assistantElement = doc.createElement("assistant");
763 assistantElement.setAttribute("type", "vanishing point");
764 assistantElement.setAttribute("filename", QString("vanishing point%1.assistant").arg(count));
765 assistantsElement.appendChild(assistantElement);
766 }
767 else if (d->s->id == "infinite ruler"){
768 QDomElement assistantElement = doc.createElement("assistant");
769 assistantElement.setAttribute("type", "infinite ruler");
770 assistantElement.setAttribute("filename", QString("infinite ruler%1.assistant").arg(count));
771 assistantsElement.appendChild(assistantElement);
772 }
773 else if (d->s->id == "parallel ruler"){
774 QDomElement assistantElement = doc.createElement("assistant");
775 assistantElement.setAttribute("type", "parallel ruler");
776 assistantElement.setAttribute("filename", QString("parallel ruler%1.assistant").arg(count));
777 assistantsElement.appendChild(assistantElement);
778 }
779 else if (d->s->id == "concentric ellipse"){
780 QDomElement assistantElement = doc.createElement("assistant");
781 assistantElement.setAttribute("type", "concentric ellipse");
782 assistantElement.setAttribute("filename", QString("concentric ellipse%1.assistant").arg(count));
783 assistantsElement.appendChild(assistantElement);
784 }
785 else if (d->s->id == "fisheye-point"){
786 QDomElement assistantElement = doc.createElement("assistant");
787 assistantElement.setAttribute("type", "fisheye-point");
788 assistantElement.setAttribute("filename", QString("fisheye-point%1.assistant").arg(count));
789 assistantsElement.appendChild(assistantElement);
790 }
791 else if (d->s->id == "ruler"){
792 QDomElement assistantElement = doc.createElement("assistant");
793 assistantElement.setAttribute("type", "ruler");
794 assistantElement.setAttribute("filename", QString("ruler%1.assistant").arg(count));
795 assistantsElement.appendChild(assistantElement);
796 }
797 else if (d->s->id == "two point"){
798 QDomElement assistantElement = doc.createElement("assistant");
799 assistantElement.setAttribute("type", "two point");
800 assistantElement.setAttribute("filename", QString("two point%1.assistant").arg(count));
801 assistantsElement.appendChild(assistantElement);
802 }
803 else if (d->s->id == "perspective ellipse"){
804 QDomElement assistantElement = doc.createElement("assistant");
805 assistantElement.setAttribute("type", "perspective ellipse");
806 assistantElement.setAttribute("filename", QString("perspective ellipse%1.assistant").arg(count));
807 assistantsElement.appendChild(assistantElement);
808 }
809 else if (d->s->id == "curvilinear-perspective"){
810 QDomElement assistantElement = doc.createElement("assistant");
811 assistantElement.setAttribute("type", "curvilinear-perspective");
812 assistantElement.setAttribute("filename", QString("curvilinear-perspective%1.assistant").arg(count));
813 assistantsElement.appendChild(assistantElement);
814 }
815}

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

1116{
1117 return 0;
1118}

◆ setAdjustedBrushPosition()

void KisPaintingAssistant::setAdjustedBrushPosition ( const QPointF position)
virtual

Definition at line 312 of file kis_painting_assistant.cc.

313{
314 d->s->adjustedBrushPosition = position;
315 d->s->adjustedPositionValid = true;
316}

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

◆ setAssistantCustomColor()

void KisPaintingAssistant::setAssistantCustomColor ( QColor color)

Definition at line 231 of file kis_painting_assistant.cc.

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

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

◆ setAssistantGlobalColorCache()

void KisPaintingAssistant::setAssistantGlobalColorCache ( const QColor & color)

Definition at line 241 of file kis_painting_assistant.cc.

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

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

◆ setBrushPriority()

void KisPaintingAssistant::setBrushPriority ( int priority)

Definition at line 300 of file kis_painting_assistant.cc.

301{
302 d->s->brushPriority = priority;
303}

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

◆ setDecorationThickness()

void KisPaintingAssistant::setDecorationThickness ( int thickness)

Definition at line 1141 of file kis_painting_assistant.cc.

1142{
1143 d->decorationThickness = thickness;
1144}

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

354{
355 d->s->isDuplicating = value;
356}
float value(const T *src, size_t ch)

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

◆ setEditorWidgetOffset()

void KisPaintingAssistant::setEditorWidgetOffset ( QPointF offset)

Definition at line 368 of file kis_painting_assistant.cc.

369{
370 d->s->editorWidgetOffset = offset;
371}

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

◆ setFollowBrushPosition()

void KisPaintingAssistant::setFollowBrushPosition ( bool follow)
virtual

Definition at line 318 of file kis_painting_assistant.cc.

319{
320 d->s->followBrushPosition = follow;
321}

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

339{
340 d->s->isLocal = value;
341}

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

349{
350 d->s->isLocked = value;
351}

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

◆ setSnappingActive()

void KisPaintingAssistant::setSnappingActive ( bool set)

Definition at line 290 of file kis_painting_assistant.cc.

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

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

◆ setUseCustomColor()

void KisPaintingAssistant::setUseCustomColor ( bool useCustomColor)

Definition at line 226 of file kis_painting_assistant.cc.

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

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

◆ sideHandles() [1/2]

QList< KisPaintingAssistantHandleSP > KisPaintingAssistant::sideHandles ( )

Definition at line 1052 of file kis_painting_assistant.cc.

1053{
1054 return d->sideHandles;
1055}

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

◆ sideHandles() [2/2]

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

Definition at line 1047 of file kis_painting_assistant.cc.

1048{
1049 return d->sideHandles;
1050}

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

◆ topLeft() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::topLeft ( )

Definition at line 957 of file kis_painting_assistant.cc.

958{
959 return d->topLeft;
960}

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

963{
964 return d->topLeft;
965}

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

◆ topMiddle() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::topMiddle ( )

Definition at line 997 of file kis_painting_assistant.cc.

998{
999 return d->topMiddle;
1000}

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

◆ topMiddle() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::topMiddle ( ) const

Definition at line 1002 of file kis_painting_assistant.cc.

1003{
1004 return d->topMiddle;
1005}

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

◆ topRight() [1/2]

KisPaintingAssistantHandleSP KisPaintingAssistant::topRight ( )

Definition at line 977 of file kis_painting_assistant.cc.

978{
979 return d->topRight;
980}

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

◆ topRight() [2/2]

const KisPaintingAssistantHandleSP KisPaintingAssistant::topRight ( ) const

Definition at line 982 of file kis_painting_assistant.cc.

983{
984 return d->topRight;
985}

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

573{
574 Q_FOREACH(KisPaintingAssistantHandleSP handle, handles()) {
575 if (handle->chiefAssistant() != this) continue;
576
577 *handle = transform.map(*handle);
578 }
579
580 Q_FOREACH(KisPaintingAssistantHandleSP handle, sideHandles()) {
581 if (handle->chiefAssistant() != this) continue;
582
583 *handle = transform.map(*handle);
584 }
585
586 uncache();
587}
KisPaintingAssistant * chiefAssistant() const
const QList< KisPaintingAssistantHandleSP > & sideHandles() const

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

◆ uncache()

void KisPaintingAssistant::uncache ( )

Definition at line 553 of file kis_painting_assistant.cc.

554{
555 d->s->cached = QPixmapCache::Key();
556}

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

◆ useCustomColor()

bool KisPaintingAssistant::useCustomColor ( )

Definition at line 221 of file kis_painting_assistant.cc.

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

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

◆ viewportConstrainedEditorPosition()

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

Definition at line 477 of file kis_painting_assistant.cc.

478{
479 QPointF editorDocumentPos = getEditorPosition();
480 QPointF editorWidgetPos = converter->documentToWidgetTransform().map(editorDocumentPos);
481 QSizeF canvasSize = converter->getCanvasWidgetSize();
482 const int padding = 16;
483
484 editorWidgetPos.rx() = qBound(0.0,
485 editorWidgetPos.x(),
486 canvasSize.width() - (editorSize.width() + padding));
487 editorWidgetPos.ry() = qBound(0.0,
488 editorWidgetPos.y(),
489 canvasSize.height() - (editorSize.height() + padding));
490
491 return converter->widgetToDocument(editorWidgetPos);
492}
_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 315 of file kis_painting_assistant.h.

◆ m_handles

QList<KisPaintingAssistantHandleSP> KisPaintingAssistant::m_handles
protected

Definition at line 263 of file kis_painting_assistant.h.

◆ m_hasBeenInsideLocalRect

bool KisPaintingAssistant::m_hasBeenInsideLocalRect {false}
protected

Definition at line 311 of file kis_painting_assistant.h.

311{false};

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