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
 
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)
 
void drawHandles (KisPaintingAssistantSP assistant, QPainter &gc, const KisCoordinatesConverter *converter)
 
- 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 73 of file kis_painting_assistants_decoration.h.

Constructor & Destructor Documentation

◆ KisPaintingAssistantsDecoration()

KisPaintingAssistantsDecoration::KisPaintingAssistantsDecoration ( QPointer< KisView > parent)

Definition at line 58 of file kis_painting_assistants_decoration.cpp.

58 :
59 KisCanvasDecoration("paintingAssistantsDecoration", parent),
60 d(new Private)
61{
64 setPriority(95);
65 d->snapOnlyOneAssistant = true; //turn on by default.
66 d->snapEraser = false;
67
68 slotConfigChanged(); // load the initial config
69}
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 71 of file kis_painting_assistants_decoration.cpp.

72{
73 delete d;
74}

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

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

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

◆ addAssistant()

void KisPaintingAssistantsDecoration::addAssistant ( KisPaintingAssistantSP assistant)

Definition at line 95 of file kis_painting_assistants_decoration.cpp.

96{
97 QList<KisPaintingAssistantSP> assistants = view()->document()->assistants();
98 if (assistants.contains(assistant)) return;
99
100 assistants.append(assistant);
101 assistant->setAssistantGlobalColorCache(view()->document()->assistantsGlobalColor());
102
103 view()->document()->setAssistants(assistants);
104 setVisible(!assistants.isEmpty());
105 Q_EMIT assistantChanged();
106}
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 246 of file kis_painting_assistants_decoration.cpp.

247{
248 if (assistants().empty()) {
249 // No assistants, so no adjustment
250 return;
251 }
252
253 // TODO: figure it out
254 if (!d->snapEraser
256 // No snapping if eraser snapping is disabled and brush is an eraser
257 return;
258 }
259
260 QPointF originalPoint = point;
261 QPointF originalStrokeBegin = strokeBegin;
262
263 qreal minDistance = 10000.0;
264 bool minDistValid = false;
265 QPointF finalPoint = originalPoint;
266 QPointF finalStrokeBegin = originalStrokeBegin;
267 int id = 0;
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 id ++;
288 }
289 if (bestAssistant) {
290 bestAssistant->setFollowBrushPosition(true);
291 }
292 point = finalPoint;
293 strokeBegin = finalStrokeBegin;
294}
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 166 of file kis_painting_assistants_decoration.cpp.

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

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

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

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

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

306{
307 if(assistants().isEmpty()) {
308 return; // no assistants to worry about, ok to exit
309 }
310
311 if (!canvas) {
312 dbgFile<<"canvas does not exist in painting assistant decoration, you may have passed arguments incorrectly:"<<canvas;
313 } else {
314 d->m_canvas = canvas;
315 }
316
317 // the preview functionality for assistants. do not show while editing
318
319 KoToolProxy *proxy = view()->canvasBase()->toolProxy();
321 KisToolProxy *kritaProxy = dynamic_cast<KisToolProxy*>(proxy);
323
324 const bool outlineVisible =
327 kritaProxy->supportsPaintingAssistants();
328
329 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
330 assistant->drawAssistant(gc, updateRect, converter, d->useCache, canvas, assistantVisibility(), outlineVisible);
331
332 if (isEditingAssistants()) {
333 drawHandles(assistant, gc, converter);
334 }
335 }
336
337 // draw editor controls on top of all assistant lines (why this code is last)
338 if (isEditingAssistants()) {
339 Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
340 drawEditorWidget(assistant, gc, converter);
341 }
342 }
343}
void drawEditorWidget(KisPaintingAssistantSP assistant, QPainter &gc, const KisCoordinatesConverter *converter)
bool assistantVisibility()
returns assistant visibility
void drawHandles(KisPaintingAssistantSP assistant, QPainter &gc, const KisCoordinatesConverter *converter)
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, 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 )
protected

Definition at line 561 of file kis_painting_assistants_decoration.cpp.

562{
563 if (!assistant->isAssistantComplete() || !globalEditorWidgetData.widgetActivated) {
564 return;
565 }
566
567 QTransform initialTransform = converter->documentToWidgetTransform();
568 QPointF actionsPosition = initialTransform.map(assistant->viewportConstrainedEditorPosition(converter, globalEditorWidgetData.boundingSize));
569
570 //draw editor widget background
571 QBrush backgroundColor = d->m_canvas->viewManager()->mainWindowAsQWidget()->palette().window();
572 QPointF actionsBGRectangle(actionsPosition + QPointF(globalEditorWidgetData.widgetOffset,globalEditorWidgetData.widgetOffset));
573 QPen stroke(QColor(60, 60, 60, 80), 2);
574
575 gc.setRenderHint(QPainter::Antialiasing);
576
577
578 QPainterPath bgPath;
579 bgPath.addRoundedRect(QRectF(actionsBGRectangle.x(), actionsBGRectangle.y(), globalEditorWidgetData.boundingSize.width(), globalEditorWidgetData.boundingSize.height()), 6, 6);
580
581
582 // if the assistant is selected, make outline stroke fatter and use theme's highlight color
583 // for better visual feedback
584 if (selectedAssistant()) { // there might not be a selected assistant, so do not seg fault
585 if (assistant->getEditorPosition() == selectedAssistant()->getEditorPosition()) {
586 stroke.setWidth(6);
587 stroke.setColor(qApp->palette().color(QPalette::Highlight));
588
589 }
590 }
591
592 gc.setPen(stroke);
593 gc.drawPath(bgPath);
594 gc.fillPath(bgPath, backgroundColor);
595
596
597 //draw drag handle
598 QColor dragDecorationColor(150,150,150,255);
599
600 QPainterPath dragRect;
602 int height = actionsPosition.y()+globalEditorWidgetData.boundingSize.height()+globalEditorWidgetData.widgetOffset;
604
605 gc.fillPath(bgPath.intersected(dragRect),dragDecorationColor);
606
607 //draw dot decoration on handle
608 QPainterPath dragRectDots;
609 QColor dragDecorationDotsColor(50,50,50,255);
610 int dotSize = 2;
611 dragRectDots.addEllipse(3,2.5,dotSize,dotSize);
612 dragRectDots.addEllipse(3,7.5,dotSize,dotSize);
613 dragRectDots.addEllipse(3,-2.5,dotSize,dotSize);
614 dragRectDots.addEllipse(3,-7.5,dotSize,dotSize);
615 dragRectDots.addEllipse(-3,2.5,dotSize,dotSize);
616 dragRectDots.addEllipse(-3,7.5,dotSize,dotSize);
617 dragRectDots.addEllipse(-3,-2.5,dotSize,dotSize);
618 dragRectDots.addEllipse(-3,-7.5,dotSize,dotSize);
619 dragRectDots.translate((globalEditorWidgetData.dragDecorationWidth/2)+width,(globalEditorWidgetData.boundingSize.height()/2)+actionsPosition.y()+globalEditorWidgetData.widgetOffset);
620 gc.fillPath(dragRectDots,dragDecorationDotsColor);
621
622
623 //loop over all visible buttons and render them
625 QPointF iconMovePosition(actionsPosition + globalEditorWidgetData.moveIconPosition);
626 gc.drawPixmap(iconMovePosition, globalEditorWidgetData.m_iconMove);
627 }
629 QPointF iconSnapPosition(actionsPosition + globalEditorWidgetData.snapIconPosition);
630 if (assistant->isSnappingActive() == true) {
631 gc.drawPixmap(iconSnapPosition, globalEditorWidgetData.m_iconSnapOn);
632 }else {
633 gc.drawPixmap(iconSnapPosition, globalEditorWidgetData.m_iconSnapOff);
634 }
635 }
637 QPointF iconLockedPosition(actionsPosition + globalEditorWidgetData.lockedIconPosition);
638 if (assistant->isLocked()) {
639 gc.drawPixmap(iconLockedPosition, globalEditorWidgetData.m_iconLockOn);
640 } else {
641 qreal oldOpacity = gc.opacity();
642 gc.setOpacity(0.35);
643 gc.drawPixmap(iconLockedPosition, globalEditorWidgetData.m_iconLockOff);
644 gc.setOpacity(oldOpacity);
645 }
646 }
648 QPointF iconDuplicatePosition(actionsPosition + globalEditorWidgetData.duplicateIconPosition);
649 if(assistant->isDuplicating()) {
650 //draw button depressed
651 qreal oldOpacity = gc.opacity();
652 gc.setOpacity(0.35);
653 gc.drawPixmap(iconDuplicatePosition,globalEditorWidgetData.m_iconDuplicate);
654 gc.setOpacity(oldOpacity);
655 }else {
656 gc.drawPixmap(iconDuplicatePosition,globalEditorWidgetData.m_iconDuplicate);
657 }
658 }
660 QPointF iconDeletePosition(actionsPosition + globalEditorWidgetData.deleteIconPosition);
661 gc.drawPixmap(iconDeletePosition, globalEditorWidgetData.m_iconDelete);
662 }
663
664
665
666
667}
KisViewManager * viewManager() const
QWidget * mainWindowAsQWidget() const

References AssistantEditorData::boundingSize, d, AssistantEditorData::deleteButtonActivated, AssistantEditorData::deleteIconPosition, KisCoordinatesConverter::documentToWidgetTransform(), AssistantEditorData::dragDecorationWidth, AssistantEditorData::duplicateButtonActivated, AssistantEditorData::duplicateIconPosition, globalEditorWidgetData, AssistantEditorData::lockButtonActivated, AssistantEditorData::lockedIconPosition, KisPaintingAssistantsDecoration::Private::m_canvas, AssistantEditorData::m_iconDelete, AssistantEditorData::m_iconDuplicate, AssistantEditorData::m_iconLockOff, AssistantEditorData::m_iconLockOn, AssistantEditorData::m_iconMove, AssistantEditorData::m_iconSnapOff, AssistantEditorData::m_iconSnapOn, KisViewManager::mainWindowAsQWidget(), AssistantEditorData::moveButtonActivated, AssistantEditorData::moveIconPosition, selectedAssistant(), AssistantEditorData::snapButtonActivated, AssistantEditorData::snapIconPosition, KisCanvas2::viewManager(), AssistantEditorData::widgetActivated, and AssistantEditorData::widgetOffset.

◆ drawHandles()

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

Definition at line 345 of file kis_painting_assistants_decoration.cpp.

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

References KisCoordinatesConverter::documentToWidgetTransform(), and handleSize().

◆ endStroke()

void KisPaintingAssistantsDecoration::endStroke ( )

Definition at line 296 of file kis_painting_assistants_decoration.cpp.

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

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

◆ globalAssistantsColor()

QColor KisPaintingAssistantsDecoration::globalAssistantsColor ( )

Definition at line 490 of file kis_painting_assistants_decoration.cpp.

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

References KisCanvasDecoration::view().

◆ handles()

QList< KisPaintingAssistantHandleSP > KisPaintingAssistantsDecoration::handles ( )

Definition at line 393 of file kis_painting_assistants_decoration.cpp.

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

References assistants().

◆ handleSize()

int KisPaintingAssistantsDecoration::handleSize ( )

◆ hasPaintableAssistants()

bool KisPaintingAssistantsDecoration::hasPaintableAssistants ( ) const

Definition at line 422 of file kis_painting_assistants_decoration.cpp.

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

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

526{
527 return d->m_isEditingAssistants;
528}

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

◆ outlineVisibility()

bool KisPaintingAssistantsDecoration::outlineVisibility ( )

◆ raiseAssistant()

void KisPaintingAssistantsDecoration::raiseAssistant ( KisPaintingAssistantSP assistant)

Definition at line 109 of file kis_painting_assistants_decoration.cpp.

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

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

◆ removeAll()

void KisPaintingAssistantsDecoration::removeAll ( )

Definition at line 135 of file kis_painting_assistants_decoration.cpp.

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

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

◆ removeAssistant()

void KisPaintingAssistantsDecoration::removeAssistant ( KisPaintingAssistantSP assistant)

Definition at line 123 of file kis_painting_assistants_decoration.cpp.

124{
125 QList<KisPaintingAssistantSP> assistants = view()->document()->assistants();
126 KIS_ASSERT_RECOVER_NOOP(assistants.contains(assistant));
127
128 if (assistants.removeAll(assistant)) {
129 view()->document()->setAssistants(assistants);
130 setVisible(!assistants.isEmpty());
131 Q_EMIT assistantChanged();
132 }
133}
#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 427 of file kis_painting_assistants_decoration.cpp.

428{
429 return d->selectedAssistant;
430}

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

◆ selectedAssistantChanged

void KisPaintingAssistantsDecoration::selectedAssistantChanged ( )
signal

◆ setAdjustedBrushPosition()

void KisPaintingAssistantsDecoration::setAdjustedBrushPosition ( const QPointF position)

Definition at line 156 of file kis_painting_assistants_decoration.cpp.

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

References assistants().

◆ setAssistants()

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

Definition at line 145 of file kis_painting_assistants_decoration.cpp.

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

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

◆ setAssistantVisible()

void KisPaintingAssistantsDecoration::setAssistantVisible ( bool set)

sets whether the main assistant is visible

Definition at line 444 of file kis_painting_assistants_decoration.cpp.

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

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

◆ setEraserSnap()

void KisPaintingAssistantsDecoration::setEraserSnap ( bool assistant)

sets whether eraser brushes snap

Definition at line 459 of file kis_painting_assistants_decoration.cpp.

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

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

◆ setGlobalAssistantsColor()

void KisPaintingAssistantsDecoration::setGlobalAssistantsColor ( QColor color)

Definition at line 495 of file kis_painting_assistants_decoration.cpp.

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

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

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

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

◆ setOutlineVisible()

void KisPaintingAssistantsDecoration::setOutlineVisible ( bool set)

sets whether the preview is visible

Definition at line 449 of file kis_painting_assistants_decoration.cpp.

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

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

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

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

◆ snapToGuide [1/2]

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

Definition at line 543 of file kis_painting_assistants_decoration.cpp.

544{
545 if (!d->m_canvas) {
546 return pt;
547 }
548
549
550 KoSnapGuide *snapGuide = d->m_canvas->snapGuide();
551 QPointF pos = snapGuide->snap(pt, offset, Qt::NoModifier);
552
553 return pos;
554}
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 530 of file kis_painting_assistants_decoration.cpp.

531{
532 if (!d->m_canvas || !d->m_canvas->currentImage()) {
533 return e->point;
534 }
535
536
537 KoSnapGuide *snapGuide = d->m_canvas->snapGuide();
538 QPointF pos = snapGuide->snap(e->point, offset, useModifiers ? e->modifiers() : Qt::NoModifier);
539
540 return pos;
541}
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 478 of file kis_painting_assistants_decoration.cpp.

479{
481 uncache();
482}

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

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

References outlineVisibility(), and setOutlineVisible().

◆ uncache()

void KisPaintingAssistantsDecoration::uncache ( )

uncache all assistants

Definition at line 472 of file kis_painting_assistants_decoration.cpp.

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

References assistants().

Member Data Documentation

◆ d

Private* const KisPaintingAssistantsDecoration::d
private

Definition at line 167 of file kis_painting_assistants_decoration.h.

◆ globalEditorWidgetData

struct AssistantEditorData KisPaintingAssistantsDecoration::globalEditorWidgetData

Definition at line 91 of file kis_painting_assistants_decoration.h.


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