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

#include <kis_painting_assistants_decoration.h>

+ Inheritance diagram for KisPaintingAssistantsDecoration:

Classes

struct  Private
 

Public Slots

void slotConfigChanged ()
 
void slotUpdateDecorationVisibility ()
 
QPointF snapToGuide (const QPointF &pt, const QPointF &offset)
 
QPointF snapToGuide (KoPointerEvent *e, const QPointF &offset, bool useModifiers)
 
void toggleAssistantVisible ()
 toggles whether the assistant is active or not
 
void toggleOutlineVisible ()
 toggles whether there will be a preview of the assistant result when painting
 
- Public Slots inherited from KisCanvasDecoration
virtual void setVisible (bool v)
 
void toggleVisibility ()
 

Signals

void assistantChanged ()
 
void selectedAssistantChanged ()
 

Public Member Functions

void activateAssistantsEditor ()
 
void addAssistant (KisPaintingAssistantSP assistant)
 
void adjustLine (QPointF &point, QPointF &strokeBegin)
 
QPointF adjustPosition (const QPointF &point, const QPointF &strokeBegin)
 
QList< KisPaintingAssistantSPassistants () const
 
bool assistantVisibility ()
 returns assistant visibility
 
void deactivateAssistantsEditor ()
 
void deselectAssistant ()
 
void endStroke ()
 
QColor globalAssistantsColor ()
 
QList< KisPaintingAssistantHandleSPhandles ()
 
int handleSize ()
 
bool hasPaintableAssistants () const
 
bool isEditingAssistants ()
 
 KisPaintingAssistantsDecoration (QPointer< KisView > parent)
 
bool outlineVisibility ()
 returns preview visibility
 
void raiseAssistant (KisPaintingAssistantSP assistant)
 
void removeAll ()
 
void removeAssistant (KisPaintingAssistantSP assistant)
 
KisPaintingAssistantSP selectedAssistant ()
 
void setAdjustedBrushPosition (const QPointF position)
 
void setAssistants (const QList< KisPaintingAssistantSP > &assistants)
 
void setAssistantVisible (bool set)
 sets whether the main assistant is visible
 
void setEraserSnap (bool assistant)
 sets whether eraser brushes snap
 
void setGlobalAssistantsColor (QColor color)
 
void setHandleSize (int handleSize)
 
void setOnlyOneAssistantSnap (bool assistant)
 sets whether we snap to only one assistant
 
void setOutlineVisible (bool set)
 sets whether the preview is visible
 
void setSelectedAssistant (KisPaintingAssistantSP assistant)
 
void uncache ()
 uncache all assistants
 
 ~KisPaintingAssistantsDecoration () override
 
- Public Member Functions inherited from KisCanvasDecoration
const QString & id () const
 
 KisCanvasDecoration (const QString &id, QPointer< KisView >parent)
 
virtual void notifyWindowMinimized (bool minimized)
 
void paint (QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, KisCanvas2 *canvas)
 
int priority () const
 
virtual void setCanvasWidget (KisCanvasWidgetBase *canvas)
 
void setView (QPointer< KisView > imageView)
 
bool visible () const
 
 ~KisCanvasDecoration () override
 
- Public Member Functions inherited from KisShared
bool deref ()
 
bool ref ()
 
int refCount ()
 
QAtomicInt * sharedWeakReference ()
 

Public Attributes

struct AssistantEditorData globalEditorWidgetData
 

Protected Member Functions

void drawDecoration (QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, KisCanvas2 *canvas) override
 
void drawEditorWidget (KisPaintingAssistantSP assistant, QPainter &gc, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *renderInterface)
 
void drawHandles (KisPaintingAssistantSP assistant, QPainter &gc, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *renderInterface)
 
- Protected Member Functions inherited from KisCanvasDecoration
int decorationThickness () const
 
void setPriority (int value)
 
QPointer< KisViewview () const
 
- Protected Member Functions inherited from KisShared
 KisShared ()
 
 ~KisShared ()
 

Private Attributes

Private *const d
 

Additional Inherited Members

- Static Public Member Functions inherited from KisCanvasDecoration
static bool comparePriority (KisCanvasDecorationSP decoration1, KisCanvasDecorationSP decoration2)
 

Detailed Description

KisPaintingAssistantsDecoration draws the assistants stored in the document on the canvas. In the application flow, each canvas holds one of these classes to manage the assistants There is an assistants manager, but that is higher up in the flow and makes sure each view gets one of these Since this is off the canvas level, the decoration can be seen across all tools. The contents from here will be in front of the kis_assistant_tool, which hold and displays the editor controls.

Many of the events this receives such as adding and removing assistants comes from kis_assistant_tool

Definition at line 74 of file kis_painting_assistants_decoration.h.

Constructor & Destructor Documentation

◆ KisPaintingAssistantsDecoration()

KisPaintingAssistantsDecoration::KisPaintingAssistantsDecoration ( QPointer< KisView > parent)

Definition at line 59 of file kis_painting_assistants_decoration.cpp.

59 :
60 KisCanvasDecoration("paintingAssistantsDecoration", parent),
61 d(new Private)
62{
65 setPriority(95);
66 d->snapOnlyOneAssistant = true; //turn on by default.
67 d->snapEraser = false;
68
69 slotConfigChanged(); // load the initial config
70}
KisCanvasDecoration(const QString &id, QPointer< KisView >parent)
void setAssistantVisible(bool set)
sets whether the main assistant is visible
void setOutlineVisible(bool set)
sets whether the preview is visible

References d, setAssistantVisible(), setOutlineVisible(), KisCanvasDecoration::setPriority(), slotConfigChanged(), KisPaintingAssistantsDecoration::Private::snapEraser, and KisPaintingAssistantsDecoration::Private::snapOnlyOneAssistant.

◆ ~KisPaintingAssistantsDecoration()

KisPaintingAssistantsDecoration::~KisPaintingAssistantsDecoration ( )
override

Definition at line 72 of file kis_painting_assistants_decoration.cpp.

73{
74 delete d;
75}

References d.

Member Function Documentation

◆ activateAssistantsEditor()

void KisPaintingAssistantsDecoration::activateAssistantsEditor ( )

called when assistant editor is activated right now this happens when the assistants tool is selected

Definition at line 509 of file kis_painting_assistants_decoration.cpp.

510{
511 setVisible(true); // this turns on the decorations in general. we leave it on at this point
512 d->m_isEditingAssistants = true;
513 uncache(); // updates visuals when editing
514}
virtual void setVisible(bool v)

References d, KisPaintingAssistantsDecoration::Private::m_isEditingAssistants, KisCanvasDecoration::setVisible(), and uncache().

◆ addAssistant()

void KisPaintingAssistantsDecoration::addAssistant ( KisPaintingAssistantSP assistant)

Definition at line 96 of file kis_painting_assistants_decoration.cpp.

97{
98 QList<KisPaintingAssistantSP> assistants = view()->document()->assistants();
99 if (assistants.contains(assistant)) return;
100
101 assistants.append(assistant);
102 assistant->setAssistantGlobalColorCache(view()->document()->assistantsGlobalColor());
103
104 view()->document()->setAssistants(assistants);
105 setVisible(!assistants.isEmpty());
106 Q_EMIT assistantChanged();
107}
QPointer< KisView > view() const
QList< KisPaintingAssistantSP > assistants() const

References assistantChanged(), assistants(), KisCanvasDecoration::setVisible(), and KisCanvasDecoration::view().

◆ adjustLine()

void KisPaintingAssistantsDecoration::adjustLine ( QPointF & point,
QPointF & strokeBegin )

Definition at line 247 of file kis_painting_assistants_decoration.cpp.

248{
249 if (assistants().empty()) {
250 // No assistants, so no adjustment
251 return;
252 }
253
254 // TODO: figure it out
255 if (!d->snapEraser
257 // No snapping if eraser snapping is disabled and brush is an eraser
258 return;
259 }
260
261 QPointF originalPoint = point;
262 QPointF originalStrokeBegin = strokeBegin;
263
264 qreal minDistance = 10000.0;
265 bool minDistValid = false;
266 QPointF finalPoint = originalPoint;
267 QPointF finalStrokeBegin = originalStrokeBegin;
268 KisPaintingAssistantSP bestAssistant;
269 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
270 if(assistant->isSnappingActive() == true){//this checks if the assistant in question has it's snapping boolean turned on//
271 //QPointF pt = assistant->adjustPosition(point, strokeBegin, true);
272 QPointF p1 = originalPoint;
273 QPointF p2 = originalStrokeBegin;
274 assistant->adjustLine(p1, p2);
275 if (p1.isNull() || p2.isNull()) {
276 // possibly lines cannot snap to this assistant, or this line cannot, at least
277 continue;
278 }
279 qreal distance = kisSquareDistance(p1, originalPoint) + kisSquareDistance(p2, originalStrokeBegin);
280 if (distance < minDistance || !minDistValid) {
281 finalPoint = p1;
282 finalStrokeBegin = p2;
283 minDistValid = true;
284 bestAssistant = assistant;
285 }
286 }
287 }
288 if (bestAssistant) {
289 bestAssistant->setFollowBrushPosition(true);
290 }
291 point = finalPoint;
292 strokeBegin = finalStrokeBegin;
293}
QPointF p2
QPointF p1
const QString COMPOSITE_ERASE
qreal distance(const QPointF &p1, const QPointF &p2)
QPointer< KoCanvasResourceProvider > resourceManager
qreal kisSquareDistance(const QPointF &pt1, const QPointF &pt2)
Definition kis_global.h:194

References assistants(), COMPOSITE_ERASE, KoCanvasResource::CurrentEffectiveCompositeOp, d, distance(), kisSquareDistance(), KisPaintingAssistantsDecoration::Private::m_canvas, p1, p2, KoCanvasBase::resourceManager, and KisPaintingAssistantsDecoration::Private::snapEraser.

◆ adjustPosition()

QPointF KisPaintingAssistantsDecoration::adjustPosition ( const QPointF & point,
const QPointF & strokeBegin )

Definition at line 167 of file kis_painting_assistants_decoration.cpp.

168{
169
170 if (assistants().empty()) {
171 // No assistants, so no adjustment
172 return point;
173 }
174
175 if (!d->snapEraser
177 // No snapping if eraser snapping is disabled and brush is an eraser
178 return point;
179 }
180
181 KisImageSP image = d->m_canvas->image();
183
185 const qreal moveThresholdPt = 4.0 / (converter->effectiveZoom() * qMax(image->xRes(), image->yRes()));
186
187 QPointF best = point;
188 qreal minSquareDistance = std::numeric_limits<qreal>::max();
189 qreal secondSquareDistance = std::numeric_limits<qreal>::max();
190
192 // In these cases the best assistant needs to be determined.
193 int numSuitableAssistants = 0;
194 KisPaintingAssistantSP bestAssistant;
195
196 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
197 if (assistant->isSnappingActive() == true){ // the toggle button with eye icon to disable assistants
198 QPointF newpoint = assistant->adjustPosition(point, strokeBegin, true, moveThresholdPt);
199 // Assistants that can't or don't want to snap return NaN values (aside from possible numeric issues)
200 // NOTE: It would be safer to also reject points too far outside canvas (or widget?) area,
201 // because for example squashed concentric ellipses can currently shoot points far off.
202 if (qIsNaN(newpoint.x()) || qIsNaN(newpoint.y())) {
203 continue;
204 }
205 ++numSuitableAssistants;
206 qreal dist = kisSquareDistance(newpoint, point);
207 if (dist < minSquareDistance) {
208 best = newpoint;
209 secondSquareDistance = minSquareDistance;
210 minSquareDistance = dist;
211 bestAssistant = assistant;
212 } else if (dist < secondSquareDistance) {
213 secondSquareDistance = dist;
214 }
215 assistant->setFollowBrushPosition(true);
216 }
217 }
218
219 // When there are multiple choices within moveThresholdPt, delay the decision until movement leaves
220 // threshold to determine which curve follows cursor movement the closest. Assistants with multiple
221 // snapping curves also need this movement to decide the best choice.
222 // NOTE: It is currently not possible to tell painting tools that a decision is pending, or that
223 // the active snapping curve changed, so certain artifact lines from snapping changes are unavoidable.
224
225 if (numSuitableAssistants > 1 && KisAlgebra2D::norm(point - strokeBegin) <= moveThresholdPt
226 && (sqrt(secondSquareDistance) < moveThresholdPt)) {
227 return strokeBegin;
228 } else if (numSuitableAssistants > 0 && d->snapOnlyOneAssistant) {
229 // if only snapping to one assistant, register it
230 d->firstAssistant = bestAssistant;
231 }
232 } else {
233 // Make sure BUG:448187 doesn't crop up again
234 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(d->firstAssistant->isSnappingActive(), point);
235 // there already is an assistant locked in, check if it can be used
236 QPointF newpoint = d->firstAssistant->adjustPosition(point, strokeBegin, false, moveThresholdPt);
237 // BUGFIX: 402535
238 // assistants might return (NaN,NaN), must always check for that
239 if (!(qIsNaN(newpoint.x()) || qIsNaN(newpoint.y()))) {
240 best = newpoint;
241 }
242 }
243
244 return best;
245}
KisCoordinatesConverter * coordinatesConverter
KisImageWSP image() const
double xRes() const
double yRes() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
qreal norm(const T &a)

References assistants(), COMPOSITE_ERASE, KisCanvas2::coordinatesConverter, KoCanvasResource::CurrentEffectiveCompositeOp, d, KisCoordinatesConverter::effectiveZoom(), KisPaintingAssistantsDecoration::Private::firstAssistant, KisCanvas2::image(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, kisSquareDistance(), KisPaintingAssistantsDecoration::Private::m_canvas, KisAlgebra2D::norm(), KoCanvasBase::resourceManager, KisPaintingAssistantsDecoration::Private::snapEraser, KisPaintingAssistantsDecoration::Private::snapOnlyOneAssistant, KisImage::xRes(), and KisImage::yRes().

◆ assistantChanged

void KisPaintingAssistantsDecoration::assistantChanged ( )
signal

◆ assistants()

QList< KisPaintingAssistantSP > KisPaintingAssistantsDecoration::assistants ( ) const

Definition at line 412 of file kis_painting_assistants_decoration.cpp.

413{
415 if (view()) {
416 if (view()->document()) {
417 assistants = view()->document()->assistants();
418 }
419 }
420 return assistants;
421}

References assistants(), and KisCanvasDecoration::view().

◆ assistantVisibility()

bool KisPaintingAssistantsDecoration::assistantVisibility ( )

◆ deactivateAssistantsEditor()

void KisPaintingAssistantsDecoration::deactivateAssistantsEditor ( )

called when assistant editor is deactivated right now this happens when the assistants tool is un-selected

Definition at line 516 of file kis_painting_assistants_decoration.cpp.

517{
518 if (!d->m_canvas) {
519 return;
520 }
521
522 d->m_isEditingAssistants = false; // some elements are hidden when we aren't editing
523 uncache(); // updates visuals when not editing
524}

References d, KisPaintingAssistantsDecoration::Private::m_canvas, KisPaintingAssistantsDecoration::Private::m_isEditingAssistants, and uncache().

◆ deselectAssistant()

void KisPaintingAssistantsDecoration::deselectAssistant ( )

◆ drawDecoration()

void KisPaintingAssistantsDecoration::drawDecoration ( QPainter & gc,
const QRectF & updateRect,
const KisCoordinatesConverter * converter,
KisCanvas2 * canvas )
overrideprotectedvirtual

Implements KisCanvasDecoration.

Definition at line 304 of file kis_painting_assistants_decoration.cpp.

305{
306 if(assistants().isEmpty()) {
307 return; // no assistants to worry about, ok to exit
308 }
309
310 if (!canvas) {
311 dbgFile<<"canvas does not exist in painting assistant decoration, you may have passed arguments incorrectly:"<<canvas;
312 } else {
313 d->m_canvas = canvas;
314 }
315
316 // the preview functionality for assistants. do not show while editing
317
318 KoToolProxy *proxy = view()->canvasBase()->toolProxy();
320 KisToolProxy *kritaProxy = dynamic_cast<KisToolProxy*>(proxy);
322
323 const bool outlineVisible =
326 kritaProxy->supportsPaintingAssistants();
327
328 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
329 assistant->drawAssistant(gc, updateRect, converter, canvas->displayRendererInterface(), d->useCache, canvas, assistantVisibility(), outlineVisible);
330
331 if (isEditingAssistants()) {
332 drawHandles(assistant, gc, converter, canvas->displayRendererInterface());
333 }
334 }
335
336 // draw editor controls on top of all assistant lines (why this code is last)
337 if (isEditingAssistants()) {
338 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
339 drawEditorWidget(assistant, gc, converter, canvas->displayRendererInterface());
340 }
341 }
342}
KoColorDisplayRendererInterface * displayRendererInterface() const override
displayRendererInterface The display renderer interface has a number of color conversion functions wh...
void drawHandles(KisPaintingAssistantSP assistant, QPainter &gc, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *renderInterface)
void drawEditorWidget(KisPaintingAssistantSP assistant, QPainter &gc, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *renderInterface)
bool assistantVisibility()
returns assistant visibility
bool supportsPaintingAssistants() const
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define dbgFile
Definition kis_debug.h:53

References assistants(), assistantVisibility(), d, dbgFile, KisCanvas2::displayRendererInterface(), drawEditorWidget(), drawHandles(), isEditingAssistants(), KIS_SAFE_ASSERT_RECOVER_RETURN, KisPaintingAssistantsDecoration::Private::m_canvas, KisPaintingAssistantsDecoration::Private::m_isEditingAssistants, outlineVisibility(), KisToolProxy::supportsPaintingAssistants(), KisPaintingAssistantsDecoration::Private::useCache, and KisCanvasDecoration::view().

◆ drawEditorWidget()

void KisPaintingAssistantsDecoration::drawEditorWidget ( KisPaintingAssistantSP assistant,
QPainter & gc,
const KisCoordinatesConverter * converter,
const KoColorDisplayRendererInterface * renderInterface )
protected

Definition at line 587 of file kis_painting_assistants_decoration.cpp.

588{
589 if (!assistant->isAssistantComplete() || !globalEditorWidgetData.widgetActivated) {
590 return;
591 }
592
593 QTransform initialTransform = converter->documentToWidgetTransform();
594 QPointF actionsPosition = initialTransform.map(assistant->viewportConstrainedEditorPosition(converter, globalEditorWidgetData.boundingSize));
595
596 //draw editor widget background
597 QPalette sysPalette = renderInterface->systemPaletteForDisplayColorSpace();
598
599 QBrush backgroundColor = sysPalette.window();
600 QPointF actionsBGRectangle(actionsPosition + QPointF(globalEditorWidgetData.widgetOffset,globalEditorWidgetData.widgetOffset));
601 QPen stroke(sysPalette.window(), 2);
602
603
604 gc.setRenderHint(QPainter::Antialiasing);
605
606
607 QPainterPath bgPath;
608 bgPath.addRoundedRect(QRectF(actionsBGRectangle.x(), actionsBGRectangle.y(), globalEditorWidgetData.boundingSize.width(), globalEditorWidgetData.boundingSize.height()), 6, 6);
609
610
611 // if the assistant is selected, make outline stroke fatter and use theme's highlight color
612 // for better visual feedback
613 if (selectedAssistant()) { // there might not be a selected assistant, so do not seg fault
614 if (assistant->getEditorPosition() == selectedAssistant()->getEditorPosition()) {
615 stroke.setWidth(6);
616 stroke.setColor(sysPalette.color(QPalette::Highlight));
617
618 }
619 }
620
621 gc.setPen(stroke);
622 gc.drawPath(bgPath);
623 gc.fillPath(bgPath, backgroundColor);
624
625 //draw drag handle
626 KoColor c;
627 c.fromQColor(QColor(150,150,150,255));
628 QColor dragDecorationColor = renderInterface->convertColorToDisplayColorSpace(c);
629
630 QPainterPath dragRect;
633
634 gc.fillPath(bgPath.intersected(dragRect),dragDecorationColor);
635
636 //draw dot decoration on handle
637 QPainterPath dragRectDots;
638 c.fromQColor(QColor(50,50,50,255));
639 QColor dragDecorationDotsColor = renderInterface->convertColorToDisplayColorSpace(c);
640 int dotSize = 2;
641 dragRectDots.addEllipse(3,2.5,dotSize,dotSize);
642 dragRectDots.addEllipse(3,7.5,dotSize,dotSize);
643 dragRectDots.addEllipse(3,-2.5,dotSize,dotSize);
644 dragRectDots.addEllipse(3,-7.5,dotSize,dotSize);
645 dragRectDots.addEllipse(-3,2.5,dotSize,dotSize);
646 dragRectDots.addEllipse(-3,7.5,dotSize,dotSize);
647 dragRectDots.addEllipse(-3,-2.5,dotSize,dotSize);
648 dragRectDots.addEllipse(-3,-7.5,dotSize,dotSize);
649 dragRectDots.translate((globalEditorWidgetData.dragDecorationWidth/2)+width,(globalEditorWidgetData.boundingSize.height()/2)+actionsPosition.y()+globalEditorWidgetData.widgetOffset);
650 gc.fillPath(dragRectDots,dragDecorationDotsColor);
651
652 QRect buttonRect(QPoint(0,0), QSize(globalEditorWidgetData.buttonSize, globalEditorWidgetData.buttonSize));
653 //loop over all visible buttons and render them
655 QPoint pos = QPointF(actionsPosition + globalEditorWidgetData.moveIconPosition).toPoint();
656 drawSingleState(gc, globalEditorWidgetData.m_iconMove, buttonRect, pos, renderInterface, QPoint(5, 5));
657 }
659 QPoint pos = QPointF(actionsPosition + globalEditorWidgetData.snapIconPosition).toPoint();
660 drawDoubleState(gc, globalEditorWidgetData.m_iconSnapOn, globalEditorWidgetData.m_iconSnapOff, buttonRect, pos, assistant->isSnappingActive(), renderInterface);
661 }
663 QPoint pos = QPointF(actionsPosition + globalEditorWidgetData.lockedIconPosition).toPoint();
664 drawDoubleState(gc, globalEditorWidgetData.m_iconLockOn, globalEditorWidgetData.m_iconLockOff, buttonRect, pos, assistant->isLocked(), renderInterface);
665 }
667 QPoint pos = QPointF(actionsPosition + globalEditorWidgetData.duplicateIconPosition).toPoint();
668 drawDoubleState(gc, globalEditorWidgetData.m_iconDuplicate, globalEditorWidgetData.m_iconDuplicate, buttonRect, pos, !assistant->isDuplicating(), renderInterface);
669 }
671 QPoint pos = QPointF(actionsPosition + globalEditorWidgetData.deleteIconPosition).toPoint();
672 drawSingleState(gc, globalEditorWidgetData.m_iconDelete, buttonRect, pos, renderInterface);
673 }
674}
virtual QColor convertColorToDisplayColorSpace(const KoColor color) const =0
convertColorToDisplayColorSpace
virtual QPalette systemPaletteForDisplayColorSpace() const =0
systemPaletteForDisplayColorSpace
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213
void drawSingleState(QPainter &gc, const QImage &icon, QRect maxRect, const QPoint &position, const KoColorDisplayRendererInterface *renderInterface, QPoint additional=QPoint())
void drawDoubleState(QPainter &gc, const QImage &icon, const QImage &icon2, QRect maxRect, const QPoint &position, const bool state, const KoColorDisplayRendererInterface *renderInterface)

References AssistantEditorData::boundingSize, AssistantEditorData::buttonSize, KoColorDisplayRendererInterface::convertColorToDisplayColorSpace(), AssistantEditorData::deleteButtonActivated, AssistantEditorData::deleteIconPosition, KisCoordinatesConverter::documentToWidgetTransform(), AssistantEditorData::dragDecorationWidth, drawDoubleState(), drawSingleState(), AssistantEditorData::duplicateButtonActivated, AssistantEditorData::duplicateIconPosition, KoColor::fromQColor(), globalEditorWidgetData, AssistantEditorData::lockButtonActivated, AssistantEditorData::lockedIconPosition, AssistantEditorData::m_iconDelete, AssistantEditorData::m_iconDuplicate, AssistantEditorData::m_iconLockOff, AssistantEditorData::m_iconLockOn, AssistantEditorData::m_iconMove, AssistantEditorData::m_iconSnapOff, AssistantEditorData::m_iconSnapOn, AssistantEditorData::moveButtonActivated, AssistantEditorData::moveIconPosition, selectedAssistant(), AssistantEditorData::snapButtonActivated, AssistantEditorData::snapIconPosition, KoColorDisplayRendererInterface::systemPaletteForDisplayColorSpace(), AssistantEditorData::widgetActivated, and AssistantEditorData::widgetOffset.

◆ drawHandles()

void KisPaintingAssistantsDecoration::drawHandles ( KisPaintingAssistantSP assistant,
QPainter & gc,
const KisCoordinatesConverter * converter,
const KoColorDisplayRendererInterface * renderInterface )
protected

Definition at line 344 of file kis_painting_assistants_decoration.cpp.

345{
346 QTransform initialTransform = converter->documentToWidgetTransform();
347
348 KoColor c;
349 c.fromQColor(assistant->effectiveAssistantColor());
350 QColor colorToPaint = renderInterface->convertColorToDisplayColorSpace(c);
351
352 Q_FOREACH (const KisPaintingAssistantHandleSP handle, assistant->handles()) {
353
354
355 QPointF transformedHandle = initialTransform.map(*handle);
356 QRectF ellipse(transformedHandle - QPointF(handleSize() * 0.5, handleSize() * 0.5), QSizeF(handleSize(), handleSize()));
357
358 QPainterPath path;
359 path.addEllipse(ellipse);
360
361 gc.save();
362 gc.setPen(Qt::NoPen);
363 gc.setBrush(colorToPaint);
364 gc.drawPath(path);
365 gc.restore();
366 }
367
368 // some assistants have side handles like the vanishing point assistant
369 Q_FOREACH (const KisPaintingAssistantHandleSP handle, assistant->sideHandles()) {
370 QPointF transformedHandle = initialTransform.map(*handle);
371 QRectF ellipse(transformedHandle - QPointF(handleSize() * 0.5, handleSize() * 0.5), QSizeF(handleSize(), handleSize()));
372
373 QPainterPath path;
374 path.addEllipse(ellipse);
375
376 gc.save();
377 gc.setPen(Qt::NoPen);
378 gc.setBrush(colorToPaint);
379 gc.drawPath(path);
380 gc.restore();
381 }
382}

References KoColorDisplayRendererInterface::convertColorToDisplayColorSpace(), KisCoordinatesConverter::documentToWidgetTransform(), KoColor::fromQColor(), and handleSize().

◆ endStroke()

void KisPaintingAssistantsDecoration::endStroke ( )

Definition at line 295 of file kis_painting_assistants_decoration.cpp.

296{
297 d->firstAssistant.clear();
298
299 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
300 assistant->endStroke();
301 }
302}

References assistants(), d, and KisPaintingAssistantsDecoration::Private::firstAssistant.

◆ globalAssistantsColor()

QColor KisPaintingAssistantsDecoration::globalAssistantsColor ( )

Definition at line 491 of file kis_painting_assistants_decoration.cpp.

492{
493 return view()->document()->assistantsGlobalColor();
494}

References KisCanvasDecoration::view().

◆ handles()

QList< KisPaintingAssistantHandleSP > KisPaintingAssistantsDecoration::handles ( )

Definition at line 394 of file kis_painting_assistants_decoration.cpp.

395{
397 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
398 Q_FOREACH (const KisPaintingAssistantHandleSP handle, assistant->handles()) {
399 if (!hs.contains(handle)) {
400 hs.push_back(handle);
401 }
402 }
403 Q_FOREACH (const KisPaintingAssistantHandleSP handle, assistant->sideHandles()) {
404 if (!hs.contains(handle)) {
405 hs.push_back(handle);
406 }
407 }
408 }
409 return hs;
410}

References assistants().

◆ handleSize()

int KisPaintingAssistantsDecoration::handleSize ( )

◆ hasPaintableAssistants()

bool KisPaintingAssistantsDecoration::hasPaintableAssistants ( ) const

Definition at line 423 of file kis_painting_assistants_decoration.cpp.

424{
425 return !assistants().isEmpty();
426}

References assistants().

◆ isEditingAssistants()

bool KisPaintingAssistantsDecoration::isEditingAssistants ( )

brings back if we are currently editing assistants or not useful for some assistants (like spline) that draw bezier curves

Definition at line 526 of file kis_painting_assistants_decoration.cpp.

527{
528 return d->m_isEditingAssistants;
529}

References d, and KisPaintingAssistantsDecoration::Private::m_isEditingAssistants.

◆ outlineVisibility()

bool KisPaintingAssistantsDecoration::outlineVisibility ( )

◆ raiseAssistant()

void KisPaintingAssistantsDecoration::raiseAssistant ( KisPaintingAssistantSP assistant)

Definition at line 110 of file kis_painting_assistants_decoration.cpp.

111{
112 QList<KisPaintingAssistantSP> assistants = view()->document()->assistants();
113 assistants.removeOne(assistant);
114
115 if (!assistant) return;
116 assistants.append(assistant);
117
118 view()->document()->setAssistants(assistants);
119 setVisible(!assistants.isEmpty());
120 Q_EMIT assistantChanged();
121
122}

References assistantChanged(), assistants(), KisCanvasDecoration::setVisible(), and KisCanvasDecoration::view().

◆ removeAll()

void KisPaintingAssistantsDecoration::removeAll ( )

Definition at line 136 of file kis_painting_assistants_decoration.cpp.

137{
138 QList<KisPaintingAssistantSP> assistants = view()->document()->assistants();
139 assistants.clear();
140 view()->document()->setAssistants(assistants);
141 setVisible(!assistants.isEmpty());
142
143 Q_EMIT assistantChanged();
144}

References assistantChanged(), assistants(), KisCanvasDecoration::setVisible(), and KisCanvasDecoration::view().

◆ removeAssistant()

void KisPaintingAssistantsDecoration::removeAssistant ( KisPaintingAssistantSP assistant)

Definition at line 124 of file kis_painting_assistants_decoration.cpp.

125{
126 QList<KisPaintingAssistantSP> assistants = view()->document()->assistants();
127 KIS_ASSERT_RECOVER_NOOP(assistants.contains(assistant));
128
129 if (assistants.removeAll(assistant)) {
130 view()->document()->setAssistants(assistants);
131 setVisible(!assistants.isEmpty());
132 Q_EMIT assistantChanged();
133 }
134}
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97

References assistantChanged(), assistants(), KIS_ASSERT_RECOVER_NOOP, KisCanvasDecoration::setVisible(), and KisCanvasDecoration::view().

◆ selectedAssistant()

KisPaintingAssistantSP KisPaintingAssistantsDecoration::selectedAssistant ( )

getter and setter functions for what assistant is currently selected this is used to control some tool options that are specific to a assistant

Definition at line 428 of file kis_painting_assistants_decoration.cpp.

429{
430 return d->selectedAssistant;
431}

References d, and KisPaintingAssistantsDecoration::Private::selectedAssistant.

◆ selectedAssistantChanged

void KisPaintingAssistantsDecoration::selectedAssistantChanged ( )
signal

◆ setAdjustedBrushPosition()

void KisPaintingAssistantsDecoration::setAdjustedBrushPosition ( const QPointF position)

Definition at line 157 of file kis_painting_assistants_decoration.cpp.

158{
159 if (!assistants().empty()) {
160 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
161 assistant->setAdjustedBrushPosition(position);
162 }
163 }
164}

References assistants().

◆ setAssistants()

void KisPaintingAssistantsDecoration::setAssistants ( const QList< KisPaintingAssistantSP > & assistants)

Definition at line 146 of file kis_painting_assistants_decoration.cpp.

147{
148 Q_FOREACH (KisPaintingAssistantSP assistant, assistants) {
149 assistant->setAssistantGlobalColorCache(view()->document()->assistantsGlobalColor());
150 }
151 view()->document()->setAssistants(assistants);
152 setVisible(!assistants.isEmpty());
153
154 Q_EMIT assistantChanged();
155}

References assistantChanged(), assistants(), KisCanvasDecoration::setVisible(), and KisCanvasDecoration::view().

◆ setAssistantVisible()

void KisPaintingAssistantsDecoration::setAssistantVisible ( bool set)

sets whether the main assistant is visible

Definition at line 445 of file kis_painting_assistants_decoration.cpp.

446{
447 d->assistantVisible=set;
448}

References KisPaintingAssistantsDecoration::Private::assistantVisible, and d.

◆ setEraserSnap()

void KisPaintingAssistantsDecoration::setEraserSnap ( bool assistant)

sets whether eraser brushes snap

Definition at line 460 of file kis_painting_assistants_decoration.cpp.

461{
462 d->snapEraser = assistant;
463}

References d, and KisPaintingAssistantsDecoration::Private::snapEraser.

◆ setGlobalAssistantsColor()

void KisPaintingAssistantsDecoration::setGlobalAssistantsColor ( QColor color)

Definition at line 496 of file kis_painting_assistants_decoration.cpp.

497{
498 // view()->document() is referenced multiple times in this class
499 // it is used to later store things in the KRA file when saving.
500 view()->document()->setAssistantsGlobalColor(color);
501
502 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
503 assistant->setAssistantGlobalColorCache(color);
504 }
505
506 uncache();
507}

References assistants(), uncache(), and KisCanvasDecoration::view().

◆ setHandleSize()

void KisPaintingAssistantsDecoration::setHandleSize ( int handleSize)

◆ setOnlyOneAssistantSnap()

void KisPaintingAssistantsDecoration::setOnlyOneAssistantSnap ( bool assistant)

sets whether we snap to only one assistant

Definition at line 455 of file kis_painting_assistants_decoration.cpp.

456{
457 d->snapOnlyOneAssistant = assistant;
458}

References d, and KisPaintingAssistantsDecoration::Private::snapOnlyOneAssistant.

◆ setOutlineVisible()

void KisPaintingAssistantsDecoration::setOutlineVisible ( bool set)

sets whether the preview is visible

Definition at line 450 of file kis_painting_assistants_decoration.cpp.

451{
452 d->outlineVisible=set;
453}

References d, and KisPaintingAssistantsDecoration::Private::outlineVisible.

◆ setSelectedAssistant()

void KisPaintingAssistantsDecoration::setSelectedAssistant ( KisPaintingAssistantSP assistant)

◆ slotConfigChanged

void KisPaintingAssistantsDecoration::slotConfigChanged ( )
slot

◆ slotUpdateDecorationVisibility

void KisPaintingAssistantsDecoration::slotUpdateDecorationVisibility ( )
slot

Definition at line 77 of file kis_painting_assistants_decoration.cpp.

78{
79 const bool shouldBeVisible = !assistants().isEmpty();
80
81 if (visible() != shouldBeVisible) {
82 setVisible(shouldBeVisible);
83 }
84}

References assistants(), KisCanvasDecoration::setVisible(), and KisCanvasDecoration::visible().

◆ snapToGuide [1/2]

QPointF KisPaintingAssistantsDecoration::snapToGuide ( const QPointF & pt,
const QPointF & offset )
slot

Definition at line 544 of file kis_painting_assistants_decoration.cpp.

545{
546 if (!d->m_canvas) {
547 return pt;
548 }
549
550
551 KoSnapGuide *snapGuide = d->m_canvas->snapGuide();
552 QPointF pos = snapGuide->snap(pt, offset, Qt::NoModifier);
553
554 return pos;
555}
KoSnapGuide * snapGuide
QPointF snap(const QPointF &mousePosition, Qt::KeyboardModifiers modifiers)
snaps the mouse position, returns if mouse was snapped

References d, KisPaintingAssistantsDecoration::Private::m_canvas, KoSnapGuide::snap(), and KoCanvasBase::snapGuide.

◆ snapToGuide [2/2]

QPointF KisPaintingAssistantsDecoration::snapToGuide ( KoPointerEvent * e,
const QPointF & offset,
bool useModifiers )
slot

Definition at line 531 of file kis_painting_assistants_decoration.cpp.

532{
533 if (!d->m_canvas || !d->m_canvas->currentImage()) {
534 return e->point;
535 }
536
537
538 KoSnapGuide *snapGuide = d->m_canvas->snapGuide();
539 QPointF pos = snapGuide->snap(e->point, offset, useModifiers ? e->modifiers() : Qt::NoModifier);
540
541 return pos;
542}
KisImageWSP currentImage() const
Qt::KeyboardModifiers modifiers() const
QPointF point
The point in document coordinates.

References KisCanvas2::currentImage(), d, KisPaintingAssistantsDecoration::Private::m_canvas, KoPointerEvent::modifiers(), KoPointerEvent::point, KoSnapGuide::snap(), and KoCanvasBase::snapGuide.

◆ toggleAssistantVisible

void KisPaintingAssistantsDecoration::toggleAssistantVisible ( )
slot

toggles whether the assistant is active or not

Definition at line 479 of file kis_painting_assistants_decoration.cpp.

480{
482 uncache();
483}

References assistantVisibility(), setAssistantVisible(), and uncache().

◆ toggleOutlineVisible

void KisPaintingAssistantsDecoration::toggleOutlineVisible ( )
slot

toggles whether there will be a preview of the assistant result when painting

Definition at line 485 of file kis_painting_assistants_decoration.cpp.

486{
487 // "outline" means assistant preview (line that depends on the mouse cursor)
489}

References outlineVisibility(), and setOutlineVisible().

◆ uncache()

void KisPaintingAssistantsDecoration::uncache ( )

uncache all assistants

Definition at line 473 of file kis_painting_assistants_decoration.cpp.

474{
475 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
476 assistant->uncache();
477 }
478}

References assistants().

Member Data Documentation

◆ d

Private* const KisPaintingAssistantsDecoration::d
private

Definition at line 168 of file kis_painting_assistants_decoration.h.

◆ globalEditorWidgetData

struct AssistantEditorData KisPaintingAssistantsDecoration::globalEditorWidgetData

Definition at line 92 of file kis_painting_assistants_decoration.h.


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