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 ()
 
void temporaryConstraintAvailabilityChanged ()
 

Public Member Functions

void activateAssistantsEditor ()
 
void addAssistant (KisPaintingAssistantSP assistant)
 
void adjustLine (QPointF &point, QPointF &strokeBegin)
 
QPointF adjustPosition (const QPointF &point, const QPointF &strokeBegin)
 
QList< KisPaintingAssistantSP > assistants () const
 
bool assistantVisibility ()
 returns assistant visibility
 
void deactivateAssistantsEditor ()
 
void deselectAssistant ()
 
void endStroke ()
 
QColor globalAssistantsColor ()
 
QList< KisPaintingAssistantHandleSP > handles ()
 
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 setTemporaryConstraint (std::optional< KisTemporaryPaintConstraint > constraint)
 
std::optional< KisTemporaryPaintConstraint > temporaryConstraint () const
 
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< KisView > view () 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 78 of file kis_painting_assistants_decoration.h.

Constructor & Destructor Documentation

◆ KisPaintingAssistantsDecoration()

KisPaintingAssistantsDecoration::KisPaintingAssistantsDecoration ( QPointer< KisView > parent)

Definition at line 75 of file kis_painting_assistants_decoration.cpp.

75 :
76 KisCanvasDecoration("paintingAssistantsDecoration", parent),
77 d(new Private)
78{
81 setPriority(95);
82 d->snapOnlyOneAssistant = true; //turn on by default.
83 d->snapEraser = false;
84
85 slotConfigChanged(); // load the initial config
86}
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 88 of file kis_painting_assistants_decoration.cpp.

89{
90 delete d;
91}

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 641 of file kis_painting_assistants_decoration.cpp.

642{
643 setVisible(true); // this turns on the decorations in general. we leave it on at this point
644 d->m_isEditingAssistants = true;
645 uncache(); // updates visuals when editing
646}
virtual void setVisible(bool v)

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

◆ addAssistant()

void KisPaintingAssistantsDecoration::addAssistant ( KisPaintingAssistantSP assistant)

Definition at line 112 of file kis_painting_assistants_decoration.cpp.

113{
114 QList<KisPaintingAssistantSP> assistants = view()->document()->assistants();
115 if (assistants.contains(assistant)) return;
116
117 assistants.append(assistant);
118 assistant->setAssistantGlobalColorCache(view()->document()->assistantsGlobalColor());
119
120 view()->document()->setAssistants(assistants);
122 Q_EMIT assistantChanged();
123}
QPointer< KisView > view() const
QList< KisPaintingAssistantSP > assistants() const

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

◆ adjustLine()

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

Definition at line 283 of file kis_painting_assistants_decoration.cpp.

284{
285 if (assistants().empty()) {
286 // No assistants, so no adjustment
287 return;
288 }
289
290 // TODO: figure it out
291 if (!d->snapEraser
293 // No snapping if eraser snapping is disabled and brush is an eraser
294 return;
295 }
296
297 QPointF originalPoint = point;
298 QPointF originalStrokeBegin = strokeBegin;
299
300 qreal minDistance = 10000.0;
301 bool minDistValid = false;
302 QPointF finalPoint = originalPoint;
303 QPointF finalStrokeBegin = originalStrokeBegin;
304 KisPaintingAssistantSP bestAssistant;
305 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
306 if(assistant->isSnappingActive() == true){//this checks if the assistant in question has it's snapping boolean turned on//
307 //QPointF pt = assistant->adjustPosition(point, strokeBegin, true);
308 QPointF p1 = originalPoint;
309 QPointF p2 = originalStrokeBegin;
310 assistant->adjustLine(p1, p2);
311 if (p1.isNull() || p2.isNull()) {
312 // possibly lines cannot snap to this assistant, or this line cannot, at least
313 continue;
314 }
315 qreal distance = kisSquareDistance(p1, originalPoint) + kisSquareDistance(p2, originalStrokeBegin);
316 if (distance < minDistance || !minDistValid) {
317 finalPoint = p1;
318 finalStrokeBegin = p2;
319 minDistValid = true;
320 bestAssistant = assistant;
321 }
322 }
323 }
324 if (bestAssistant) {
325 bestAssistant->setFollowBrushPosition(true);
326 }
327 point = finalPoint;
328 strokeBegin = finalStrokeBegin;
329}
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 192 of file kis_painting_assistants_decoration.cpp.

193{
194 if (assistants().empty() && !hasLockedValidTemporaryConstraint(d->temporaryConstraint)) {
195 // No assistants, so no adjustment
196 return point;
197 }
198
199 if (!d->m_canvas && view()) {
200 d->m_canvas = view()->canvasBase();
201 }
202
203 if (!d->m_canvas) {
204 return point;
205 }
206
207 if (!d->snapEraser
209 // No snapping if eraser snapping is disabled and brush is an eraser
210 return point;
211 }
212
213 KisImageSP image = d->m_canvas->image();
215
217 const qreal moveThresholdPt = 4.0 / (converter->effectiveZoom() * qMax(image->xRes(), image->yRes()));
218
219 if (hasLockedValidTemporaryConstraint(d->temporaryConstraint)) {
220 return d->temporaryConstraint->adjustPosition(point, strokeBegin, false, 0.0);
221 }
222
223 QPointF best = point;
224 qreal minSquareDistance = std::numeric_limits<qreal>::max();
225 qreal secondSquareDistance = std::numeric_limits<qreal>::max();
226
228 // In these cases the best assistant needs to be determined.
229 int numSuitableAssistants = 0;
230 KisPaintingAssistantSP bestAssistant;
231
232 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
233 if (assistant->isSnappingActive() == true){ // the toggle button with eye icon to disable assistants
234 QPointF newpoint = assistant->adjustPosition(point, strokeBegin, true, moveThresholdPt);
235 // Assistants that can't or don't want to snap return NaN values (aside from possible numeric issues)
236 // NOTE: It would be safer to also reject points too far outside canvas (or widget?) area,
237 // because for example squashed concentric ellipses can currently shoot points far off.
238 if (qIsNaN(newpoint.x()) || qIsNaN(newpoint.y())) {
239 continue;
240 }
241 ++numSuitableAssistants;
242 qreal dist = kisSquareDistance(newpoint, point);
243 if (dist < minSquareDistance) {
244 best = newpoint;
245 secondSquareDistance = minSquareDistance;
246 minSquareDistance = dist;
247 bestAssistant = assistant;
248 } else if (dist < secondSquareDistance) {
249 secondSquareDistance = dist;
250 }
251 assistant->setFollowBrushPosition(true);
252 }
253 }
254
255 // When there are multiple choices within moveThresholdPt, delay the decision until movement leaves
256 // threshold to determine which curve follows cursor movement the closest. Assistants with multiple
257 // snapping curves also need this movement to decide the best choice.
258 // NOTE: It is currently not possible to tell painting tools that a decision is pending, or that
259 // the active snapping curve changed, so certain artifact lines from snapping changes are unavoidable.
260
261 if (numSuitableAssistants > 1 && KisAlgebra2D::norm(point - strokeBegin) <= moveThresholdPt
262 && (sqrt(secondSquareDistance) < moveThresholdPt)) {
263 return strokeBegin;
264 } else if (numSuitableAssistants > 0 && d->snapOnlyOneAssistant) {
265 // if only snapping to one assistant, register it
266 d->firstAssistant = bestAssistant;
267 }
268 } else {
269 // Make sure BUG:448187 doesn't crop up again
270 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(d->firstAssistant->isSnappingActive(), point);
271 // there already is an assistant locked in, check if it can be used
272 QPointF newpoint = d->firstAssistant->adjustPosition(point, strokeBegin, false, moveThresholdPt);
273 // BUGFIX: 402535
274 // assistants might return (NaN,NaN), must always check for that
275 if (!(qIsNaN(newpoint.x()) || qIsNaN(newpoint.y()))) {
276 best = newpoint;
277 }
278 }
279
280 return best;
281}
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)
std::optional< KisTemporaryPaintConstraint > temporaryConstraint

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, KisPaintingAssistantsDecoration::Private::temporaryConstraint, KisCanvasDecoration::view(), KisImage::xRes(), and KisImage::yRes().

◆ assistantChanged

void KisPaintingAssistantsDecoration::assistantChanged ( )
signal

◆ assistants()

QList< KisPaintingAssistantSP > KisPaintingAssistantsDecoration::assistants ( ) const

Definition at line 538 of file kis_painting_assistants_decoration.cpp.

539{
541 if (view()) {
542 if (view()->document()) {
543 assistants = view()->document()->assistants();
544 }
545 }
546 return assistants;
547}

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 648 of file kis_painting_assistants_decoration.cpp.

649{
650 if (!d->m_canvas) {
651 return;
652 }
653
654 d->m_isEditingAssistants = false; // some elements are hidden when we aren't editing
655 uncache(); // updates visuals when not editing
656}

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 366 of file kis_painting_assistants_decoration.cpp.

367{
368 if (!canvas) {
369 dbgFile<<"canvas does not exist in painting assistant decoration, you may have passed arguments incorrectly:"<<canvas;
370 } else {
371 d->m_canvas = canvas;
372 }
373
374 if(assistants().isEmpty() && !d->temporaryConstraint) {
375 return; // no assistants to worry about, ok to exit
376 }
377
378 // the preview functionality for assistants. do not show while editing
379
380 KoToolProxy *proxy = view()->canvasBase()->toolProxy();
382 KisToolProxy *kritaProxy = dynamic_cast<KisToolProxy*>(proxy);
384
385 const bool outlineVisible =
388 kritaProxy->supportsPaintingAssistants();
389
390 if (outlineVisible && d->temporaryConstraint && d->temporaryConstraint->hasLine()) {
391 gc.save();
392 gc.resetTransform();
393 gc.setRenderHint(QPainter::Antialiasing, true);
394
395 QTransform initialTransform = converter->documentToWidgetTransform();
396 QPointF p1 = initialTransform.map(d->temporaryConstraint->lineAnchor());
397 QPointF p2 = initialTransform.map(d->temporaryConstraint->lineSecondPoint());
398
399 QColor color = globalAssistantsColor();
400 color.setAlpha(180);
402 pen.setCosmetic(true);
403 gc.setPen(pen);
404
405 if (!d->temporaryConstraint->isLocked()) {
406 QPen anchorOutlinePen(QColor(0, 0, 0, 180), 1.0);
407 anchorOutlinePen.setCosmetic(true);
408 gc.setPen(anchorOutlinePen);
409 gc.setBrush(Qt::NoBrush);
410 gc.drawEllipse(p1, 4.0, 4.0);
411
413 anchorPen.setCosmetic(true);
414 gc.setPen(anchorPen);
415 gc.drawLine(p1 + QPointF(-6.0, 0.0), p1 + QPointF(6.0, 0.0));
416 gc.drawLine(p1 + QPointF(0.0, -6.0), p1 + QPointF(0.0, 6.0));
417 }
418
419 gc.setPen(pen);
420 if (KisAlgebra2D::normSquared(p1 - p2) > 1e-6) {
421 QLineF snapLine(p1, p2);
422 KisAlgebra2D::intersectLineRect(snapLine, gc.viewport(), true);
423
424 QPainterPath path;
425 path.moveTo(snapLine.p1());
426 path.lineTo(snapLine.p2());
427 gc.drawPath(path);
428 }
429
430 if (d->temporaryConstraint) {
431 const QPointF markerDocPos =
434 d->temporaryConstraint->lineSecondPoint();
435
436 const QPointF brushPos = initialTransform.map(markerDocPos);
437 const qreal markerRadius = 9.0;
438
439 QPen markerOutlinePen(QColor(0, 0, 0, 190), 1.0);
440 markerOutlinePen.setCosmetic(true);
441 gc.setPen(markerOutlinePen);
442 gc.setBrush(Qt::NoBrush);
443 gc.drawEllipse(brushPos, markerRadius, markerRadius);
444
446 markerPen.setCosmetic(true);
447 gc.setPen(markerPen);
448 gc.drawEllipse(brushPos, markerRadius - 2.0, markerRadius - 2.0);
449 }
450 gc.restore();
451 }
452
453
454 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
455 assistant->drawAssistant(gc, updateRect, converter, canvas->displayRendererInterface(), d->useCache, canvas, assistantVisibility(), outlineVisible);
456
457 if (isEditingAssistants()) {
458 drawHandles(assistant, gc, converter, canvas->displayRendererInterface());
459 }
460 }
461
462 // draw editor controls on top of all assistant lines (why this code is last)
463 if (isEditingAssistants()) {
464 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
465 drawEditorWidget(assistant, gc, converter, canvas->displayRendererInterface());
466 }
467 }
468}
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
virtual QColor convertColorToDisplayColorSpace(const KoColor color) const =0
convertColorToDisplayColorSpace
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define dbgFile
Definition kis_debug.h:57
qreal normSquared(const T &a)
bool intersectLineRect(QLineF &line, const QRect rect, bool extend)
static KoColorSpaceRegistry * instance()

References assistants(), assistantVisibility(), KoColorDisplayRendererInterface::convertColorToDisplayColorSpace(), d, dbgFile, KisCanvas2::displayRendererInterface(), KisCoordinatesConverter::documentToWidgetTransform(), drawEditorWidget(), drawHandles(), globalAssistantsColor(), KisPaintingAssistantsDecoration::Private::hasTemporaryAdjustedBrushPosition, KoColorSpaceRegistry::instance(), KisAlgebra2D::intersectLineRect(), isEditingAssistants(), KIS_SAFE_ASSERT_RECOVER_RETURN, KisPaintingAssistantsDecoration::Private::m_canvas, KisPaintingAssistantsDecoration::Private::m_isEditingAssistants, KisAlgebra2D::normSquared(), outlineVisibility(), p1, p2, KisToolProxy::supportsPaintingAssistants(), KisPaintingAssistantsDecoration::Private::temporaryAdjustedBrushPosition, KisPaintingAssistantsDecoration::Private::temporaryConstraint, KisPaintingAssistantsDecoration::Private::useCache, and KisCanvasDecoration::view().

◆ drawEditorWidget()

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

Definition at line 744 of file kis_painting_assistants_decoration.cpp.

745{
746 if (!assistant->isAssistantComplete() || !globalEditorWidgetData.widgetActivated) {
747 return;
748 }
749
750 QTransform initialTransform = converter->documentToWidgetTransform();
751 QPointF actionsPosition = initialTransform.map(assistant->viewportConstrainedEditorPosition(converter, globalEditorWidgetData.boundingSize));
752
753 //draw editor widget background
754 QPalette sysPalette = renderInterface->systemPaletteForDisplayColorSpace();
755
756 QBrush backgroundColor = sysPalette.window();
757 QPointF actionsBGRectangle(actionsPosition + QPointF(globalEditorWidgetData.widgetOffset,globalEditorWidgetData.widgetOffset));
758 QPen stroke(sysPalette.window(), 2);
759
760
761 gc.setRenderHint(QPainter::Antialiasing);
762
763
764 QPainterPath bgPath;
765 QRectF bgRect(actionsBGRectangle.x(),
766 actionsBGRectangle.y(),
769 bgPath.addRoundedRect(bgRect, 6, 6);
770
771
772 // if the assistant is selected, make outline stroke fatter and use theme's highlight color
773 // for better visual feedback
774 if (selectedAssistant()) { // there might not be a selected assistant, so do not seg fault
775 if (assistant->getEditorPosition() == selectedAssistant()->getEditorPosition()) {
776 stroke.setWidth(6);
777 stroke.setColor(sysPalette.color(QPalette::Highlight));
778
779 }
780 }
781
782 gc.setPen(stroke);
783 gc.drawPath(bgPath);
784 gc.fillPath(bgPath, backgroundColor);
785
786 // If the assistant uses a custom color, draw a colored strip at the bottom
787 // of the editor rectangle so that the association is clear.
788 if (assistant->useCustomColor()) {
789 KoColor c;
790 c.fromQColor(assistant->effectiveAssistantColor());
791 QColor assistantColor = renderInterface->convertColorToDisplayColorSpace(c);
792 assistantColor.setAlpha(255); // No point in having transparency here.
793
794 gc.save();
795 gc.setClipPath(bgPath, Qt::IntersectClip);
796 gc.fillRect(QRectF(QPointF(bgRect.left(), bgRect.bottom() - 4.0), bgRect.bottomRight()), assistantColor);
797 gc.restore();
798 }
799
800 //draw drag handle
801 KoColor c;
802 c.fromQColor(QColor(150,150,150,255));
803 QColor dragDecorationColor = renderInterface->convertColorToDisplayColorSpace(c);
804
805 QPainterPath dragRect;
808
809 gc.fillPath(bgPath.intersected(dragRect),dragDecorationColor);
810
811 //draw dot decoration on handle
812 QPainterPath dragRectDots;
813 c.fromQColor(QColor(50,50,50,255));
814 QColor dragDecorationDotsColor = renderInterface->convertColorToDisplayColorSpace(c);
815 int dotSize = 2;
816 dragRectDots.addEllipse(3,2.5,dotSize,dotSize);
817 dragRectDots.addEllipse(3,7.5,dotSize,dotSize);
818 dragRectDots.addEllipse(3,-2.5,dotSize,dotSize);
819 dragRectDots.addEllipse(3,-7.5,dotSize,dotSize);
820 dragRectDots.addEllipse(-3,2.5,dotSize,dotSize);
821 dragRectDots.addEllipse(-3,7.5,dotSize,dotSize);
822 dragRectDots.addEllipse(-3,-2.5,dotSize,dotSize);
823 dragRectDots.addEllipse(-3,-7.5,dotSize,dotSize);
824 dragRectDots.translate((globalEditorWidgetData.dragDecorationWidth/2)+width,(globalEditorWidgetData.boundingSize.height()/2)+actionsPosition.y()+globalEditorWidgetData.widgetOffset);
825 gc.fillPath(dragRectDots,dragDecorationDotsColor);
826
827 QRect buttonRect(QPoint(0,0), QSize(globalEditorWidgetData.buttonSize, globalEditorWidgetData.buttonSize));
828 //loop over all visible buttons and render them
830 QPoint pos = QPointF(actionsPosition + globalEditorWidgetData.moveIconPosition).toPoint();
831 drawSingleState(gc, globalEditorWidgetData.m_iconMove, QSize(globalEditorWidgetData.buttonSize+10, globalEditorWidgetData.buttonSize+10), buttonRect, pos, renderInterface, QPoint(5, 5));
832 }
834 QPoint pos = QPointF(actionsPosition + globalEditorWidgetData.snapIconPosition).toPoint();
836 }
838 QPoint pos = QPointF(actionsPosition + globalEditorWidgetData.lockedIconPosition).toPoint();
840 }
842 QPoint pos = QPointF(actionsPosition + globalEditorWidgetData.duplicateIconPosition).toPoint();
844 }
846 QPoint pos = QPointF(actionsPosition + globalEditorWidgetData.deleteIconPosition).toPoint();
848 }
849}
virtual QPalette systemPaletteForDisplayColorSpace() const =0
systemPaletteForDisplayColorSpace
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213
void drawDoubleState(QPainter &gc, const QIcon &icon, const QSize &iconSize, const QIcon &icon2, QRect maxRect, const QPoint &position, const bool state, const KoColorDisplayRendererInterface *renderInterface)
void drawSingleState(QPainter &gc, const QIcon &icon, const QSize &iconSize, QRect maxRect, const QPoint &position, const KoColorDisplayRendererInterface *renderInterface, QPoint additional=QPoint())

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 470 of file kis_painting_assistants_decoration.cpp.

471{
472 QTransform initialTransform = converter->documentToWidgetTransform();
473
474 KoColor c;
475 c.fromQColor(assistant->effectiveAssistantColor());
476 QColor colorToPaint = renderInterface->convertColorToDisplayColorSpace(c);
477
478 Q_FOREACH (const KisPaintingAssistantHandleSP handle, assistant->handles()) {
479
480
481 QPointF transformedHandle = initialTransform.map(*handle);
482 QRectF ellipse(transformedHandle - QPointF(handleSize() * 0.5, handleSize() * 0.5), QSizeF(handleSize(), handleSize()));
483
484 QPainterPath path;
485 path.addEllipse(ellipse);
486
487 gc.save();
488 gc.setPen(Qt::NoPen);
489 gc.setBrush(colorToPaint);
490 gc.drawPath(path);
491 gc.restore();
492 }
493
494 // some assistants have side handles like the vanishing point assistant
495 Q_FOREACH (const KisPaintingAssistantHandleSP handle, assistant->sideHandles()) {
496 QPointF transformedHandle = initialTransform.map(*handle);
497 QRectF ellipse(transformedHandle - QPointF(handleSize() * 0.5, handleSize() * 0.5), QSizeF(handleSize(), handleSize()));
498
499 QPainterPath path;
500 path.addEllipse(ellipse);
501
502 gc.save();
503 gc.setPen(Qt::NoPen);
504 gc.setBrush(colorToPaint);
505 gc.drawPath(path);
506 gc.restore();
507 }
508}

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

◆ endStroke()

void KisPaintingAssistantsDecoration::endStroke ( )

Definition at line 331 of file kis_painting_assistants_decoration.cpp.

332{
333 d->firstAssistant.clear();
334
335 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
336 assistant->endStroke();
337 }
338}

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

◆ globalAssistantsColor()

QColor KisPaintingAssistantsDecoration::globalAssistantsColor ( )

Definition at line 623 of file kis_painting_assistants_decoration.cpp.

624{
625 return view()->document()->assistantsGlobalColor();
626}

References KisCanvasDecoration::view().

◆ handles()

QList< KisPaintingAssistantHandleSP > KisPaintingAssistantsDecoration::handles ( )

Definition at line 520 of file kis_painting_assistants_decoration.cpp.

521{
523 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
524 Q_FOREACH (const KisPaintingAssistantHandleSP handle, assistant->handles()) {
525 if (!hs.contains(handle)) {
526 hs.push_back(handle);
527 }
528 }
529 Q_FOREACH (const KisPaintingAssistantHandleSP handle, assistant->sideHandles()) {
530 if (!hs.contains(handle)) {
531 hs.push_back(handle);
532 }
533 }
534 }
535 return hs;
536}

References assistants().

◆ handleSize()

int KisPaintingAssistantsDecoration::handleSize ( )

◆ hasPaintableAssistants()

bool KisPaintingAssistantsDecoration::hasPaintableAssistants ( ) const

Definition at line 549 of file kis_painting_assistants_decoration.cpp.

550{
551 return !assistants().isEmpty() || hasLockedValidTemporaryConstraint(d->temporaryConstraint);
552}

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

◆ 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 658 of file kis_painting_assistants_decoration.cpp.

659{
660 return d->m_isEditingAssistants;
661}

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

◆ outlineVisibility()

bool KisPaintingAssistantsDecoration::outlineVisibility ( )

◆ raiseAssistant()

void KisPaintingAssistantsDecoration::raiseAssistant ( KisPaintingAssistantSP assistant)

Definition at line 126 of file kis_painting_assistants_decoration.cpp.

127{
128 QList<KisPaintingAssistantSP> assistants = view()->document()->assistants();
129 assistants.removeOne(assistant);
130
131 if (!assistant) return;
132 assistants.append(assistant);
133
134 view()->document()->setAssistants(assistants);
136 Q_EMIT assistantChanged();
137
138}

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

◆ removeAll()

void KisPaintingAssistantsDecoration::removeAll ( )

Definition at line 152 of file kis_painting_assistants_decoration.cpp.

153{
154 QList<KisPaintingAssistantSP> assistants = view()->document()->assistants();
155 assistants.clear();
156 view()->document()->setAssistants(assistants);
158
159 Q_EMIT assistantChanged();
160}

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

◆ removeAssistant()

void KisPaintingAssistantsDecoration::removeAssistant ( KisPaintingAssistantSP assistant)

Definition at line 140 of file kis_painting_assistants_decoration.cpp.

141{
142 QList<KisPaintingAssistantSP> assistants = view()->document()->assistants();
143 KIS_ASSERT_RECOVER_NOOP(assistants.contains(assistant));
144
145 if (assistants.removeAll(assistant)) {
146 view()->document()->setAssistants(assistants);
148 Q_EMIT assistantChanged();
149 }
150}
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97

References assistantChanged(), assistants(), KIS_ASSERT_RECOVER_NOOP, slotUpdateDecorationVisibility(), 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 554 of file kis_painting_assistants_decoration.cpp.

555{
556 return d->selectedAssistant;
557}

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

◆ selectedAssistantChanged

void KisPaintingAssistantsDecoration::selectedAssistantChanged ( )
signal

◆ setAdjustedBrushPosition()

void KisPaintingAssistantsDecoration::setAdjustedBrushPosition ( const QPointF position)

◆ setAssistants()

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

Definition at line 162 of file kis_painting_assistants_decoration.cpp.

163{
164 Q_FOREACH (KisPaintingAssistantSP assistant, assistants) {
165 assistant->setAssistantGlobalColorCache(view()->document()->assistantsGlobalColor());
166 }
167 view()->document()->setAssistants(assistants);
169
170 Q_EMIT assistantChanged();
171}

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

◆ setAssistantVisible()

void KisPaintingAssistantsDecoration::setAssistantVisible ( bool set)

sets whether the main assistant is visible

Definition at line 571 of file kis_painting_assistants_decoration.cpp.

572{
573 d->assistantVisible=set;
574}

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

◆ setEraserSnap()

void KisPaintingAssistantsDecoration::setEraserSnap ( bool assistant)

sets whether eraser brushes snap

Definition at line 586 of file kis_painting_assistants_decoration.cpp.

587{
588 d->snapEraser = assistant;
589}

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

◆ setGlobalAssistantsColor()

void KisPaintingAssistantsDecoration::setGlobalAssistantsColor ( QColor color)

Definition at line 628 of file kis_painting_assistants_decoration.cpp.

629{
630 // view()->document() is referenced multiple times in this class
631 // it is used to later store things in the KRA file when saving.
632 view()->document()->setAssistantsGlobalColor(color);
633
634 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
635 assistant->setAssistantGlobalColorCache(color);
636 }
637
638 uncache();
639}

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 581 of file kis_painting_assistants_decoration.cpp.

582{
583 d->snapOnlyOneAssistant = assistant;
584}

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

◆ setOutlineVisible()

void KisPaintingAssistantsDecoration::setOutlineVisible ( bool set)

sets whether the preview is visible

Definition at line 576 of file kis_painting_assistants_decoration.cpp.

577{
578 d->outlineVisible=set;
579}

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

◆ setSelectedAssistant()

void KisPaintingAssistantsDecoration::setSelectedAssistant ( KisPaintingAssistantSP assistant)

◆ setTemporaryConstraint()

void KisPaintingAssistantsDecoration::setTemporaryConstraint ( std::optional< KisTemporaryPaintConstraint > constraint)

Definition at line 340 of file kis_painting_assistants_decoration.cpp.

341{
342 const bool hadTemporaryConstraint = d->temporaryConstraint.has_value();
343 d->temporaryConstraint = constraint;
344 const bool hasTemporaryConstraint = d->temporaryConstraint.has_value();
345
346 if (!hasLockedValidTemporaryConstraint(d->temporaryConstraint)) {
348 }
349
350 if (hadTemporaryConstraint != hasTemporaryConstraint) {
352 }
353
355
356 if (d->m_canvas) {
358 }
359}

References d, KisPaintingAssistantsDecoration::Private::hasTemporaryAdjustedBrushPosition, KisPaintingAssistantsDecoration::Private::m_canvas, slotUpdateDecorationVisibility(), KisPaintingAssistantsDecoration::Private::temporaryConstraint, temporaryConstraintAvailabilityChanged(), and KisCanvas2::updateCanvasDecorations().

◆ slotConfigChanged

void KisPaintingAssistantsDecoration::slotConfigChanged ( )
slot

◆ slotUpdateDecorationVisibility

void KisPaintingAssistantsDecoration::slotUpdateDecorationVisibility ( )
slot

Definition at line 93 of file kis_painting_assistants_decoration.cpp.

94{
95 const bool shouldBeVisible = !assistants().isEmpty() || d->temporaryConstraint.has_value();
96
97 if (visible() != shouldBeVisible) {
98 setVisible(shouldBeVisible);
99 }
100}

References assistants(), d, KisCanvasDecoration::setVisible(), KisPaintingAssistantsDecoration::Private::temporaryConstraint, and KisCanvasDecoration::visible().

◆ snapToGuide [1/2]

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

Definition at line 676 of file kis_painting_assistants_decoration.cpp.

677{
678 if (!d->m_canvas) {
679 return pt;
680 }
681
682
683 KoSnapGuide *snapGuide = d->m_canvas->snapGuide();
684 QPointF pos = snapGuide->snap(pt, offset, Qt::NoModifier);
685
686 return pos;
687}
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 663 of file kis_painting_assistants_decoration.cpp.

664{
665 if (!d->m_canvas || !d->m_canvas->currentImage()) {
666 return e->point;
667 }
668
669
670 KoSnapGuide *snapGuide = d->m_canvas->snapGuide();
671 QPointF pos = snapGuide->snap(e->point, offset, useModifiers ? e->modifiers() : Qt::NoModifier);
672
673 return pos;
674}
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.

◆ temporaryConstraint()

std::optional< KisTemporaryPaintConstraint > KisPaintingAssistantsDecoration::temporaryConstraint ( ) const

◆ temporaryConstraintAvailabilityChanged

void KisPaintingAssistantsDecoration::temporaryConstraintAvailabilityChanged ( )
signal

◆ toggleAssistantVisible

void KisPaintingAssistantsDecoration::toggleAssistantVisible ( )
slot

toggles whether the assistant is active or not

Definition at line 610 of file kis_painting_assistants_decoration.cpp.

611{
613 uncache();
614}

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 616 of file kis_painting_assistants_decoration.cpp.

617{
618 // "outline" means assistant preview (line that depends on the mouse cursor)
620 uncache();
621}

References outlineVisibility(), setOutlineVisible(), and uncache().

◆ uncache()

void KisPaintingAssistantsDecoration::uncache ( )

uncache all assistants

Definition at line 599 of file kis_painting_assistants_decoration.cpp.

600{
601 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
602 assistant->uncache();
603 }
604
605 // Redraw canvas decorations in case the change was made off canvas
606 if (d->m_canvas) {
608 }
609}

References assistants(), d, KisPaintingAssistantsDecoration::Private::m_canvas, and KisCanvas2::updateCanvasDecorations().

Member Data Documentation

◆ d

Private* const KisPaintingAssistantsDecoration::d
private

Definition at line 175 of file kis_painting_assistants_decoration.h.

◆ globalEditorWidgetData

struct AssistantEditorData KisPaintingAssistantsDecoration::globalEditorWidgetData

Definition at line 98 of file kis_painting_assistants_decoration.h.


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