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

#include <kis_tool_smart_patch.h>

+ Inheritance diagram for KisToolSmartPatch:

Classes

class  InpaintCommand
 
struct  Private
 

Public Slots

void activate (const QSet< KoShape * > &shapes) override
 
void deactivate () override
 
- Public Slots inherited from KisToolPaint
void activate (const QSet< KoShape * > &shapes) override
 
void deactivate () override
 
- Public Slots inherited from KisTool
void activate (const QSet< KoShape * > &shapes) override
 
void canvasResourceChanged (int key, const QVariant &res) override
 
void deactivate () override
 
virtual void updateSettingsViews ()
 
- Public Slots inherited from KoToolBase
virtual void activate (const QSet< KoShape * > &shapes)
 
virtual void deactivate ()
 
virtual void documentResourceChanged (int key, const QVariant &res)
 
virtual void repaintDecorations ()
 
virtual void requestRedoDuringStroke ()
 
virtual void requestStrokeCancellation ()
 
virtual void requestStrokeEnd ()
 
virtual void requestUndoDuringStroke ()
 
void setStatusText (const QString &statusText)
 
void updateOptionsWidgetIcons ()
 

Public Member Functions

void activatePrimaryAction () override
 
void beginPrimaryAction (KoPointerEvent *event) override
 
void continuePrimaryAction (KoPointerEvent *event) override
 
QWidget * createOptionWidget () override
 
void deactivatePrimaryAction () override
 
void endPrimaryAction (KoPointerEvent *event) override
 
int flags () const override
 
 KisToolSmartPatch (KoCanvasBase *canvas)
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 
 ~KisToolSmartPatch () override
 
- Public Member Functions inherited from KisToolPaint
 KisToolPaint (KoCanvasBase *canvas, const QCursor &cursor)
 
void mouseMoveEvent (KoPointerEvent *event) override
 
void mousePressEvent (KoPointerEvent *event) override
 
void mouseReleaseEvent (KoPointerEvent *event) override
 
KisPopupWidgetInterfacepopupWidget () override
 
 ~KisToolPaint () override
 
- Public Member Functions inherited from KisTool
virtual bool alternateActionSupportsHiResEvents (AlternateAction action) const
 
virtual void beginAlternateDoubleClickAction (KoPointerEvent *event, AlternateAction action)
 
virtual void beginPrimaryDoubleClickAction (KoPointerEvent *event)
 
void deleteSelection () override
 
bool isActive () const
 
 KisTool (KoCanvasBase *canvas, const QCursor &cursor)
 
void mouseDoubleClickEvent (KoPointerEvent *event) override
 
void mouseTripleClickEvent (KoPointerEvent *event) override
 
virtual void newActivationWithExternalSource (KisPaintDeviceSP externalSource)
 newActivationWithExternalSource Makes sure that the tool is active and starts a new stroke, which will be able to access the pixels from the specified external source.
 
KisTool::NodePaintAbility nodePaintAbility ()
 
virtual bool primaryActionSupportsHiResEvents () const
 
virtual bool supportsPaintingAssistants () const
 
 ~KisTool () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KoToolBase
QAction * action (const QString &name) const
 
KoCanvasBasecanvas () const
 Returns the canvas the tool is working on.
 
virtual void copy () const
 
QCursor cursor () const
 return the last emitted cursor
 
virtual void customMoveEvent (KoPointerEvent *event)
 
virtual void customPressEvent (KoPointerEvent *event)
 
virtual void customReleaseEvent (KoPointerEvent *event)
 
virtual void cut ()
 
virtual QRectF decorationsRect () const
 
int decorationThickness () const
 decorationThickness The minimum thickness for tool decoration lines, this is derived from the screen magnification, thus the HiDPI settings. Note: to use this effectively, also set the pen to isCosmetic(true);
 
virtual void deselect ()
 deselect the tool should clear the selection if it has one.
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event, const QPointF &point)
 
virtual void dropEvent (QDropEvent *event, const QPointF &point)
 
virtual void explicitUserStrokeEndRequest ()
 explicitUserStrokeEndRequest is called by the input manager when the user presses the Enter key or any equivalent key. This callback comes before requestStrokeEnd(), which comes from a different source.
 
KoToolFactoryBasefactory () const
 
virtual void focusInEvent (QFocusEvent *event)
 
virtual void focusOutEvent (QFocusEvent *event)
 
virtual bool hasSelection ()
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
bool isInTextMode () const
 
bool isOpacityPresetMode () const
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
 KoToolBase (KoCanvasBase *canvas)
 
bool maskSyntheticEvents () const
 
QList< QPointer< QWidget > > optionWidgets ()
 
virtual bool paste ()
 
virtual QMenu * popupActionsMenu ()
 
virtual bool selectAll ()
 selectAll select all data the tool can select.
 
virtual KoToolSelectionselection ()
 
Q_INVOKABLE QString toolId () const
 
virtual bool wantsAutoScroll () const
 
 ~KoToolBase () override
 

Protected Slots

void resetCursorStyle () override
 
- Protected Slots inherited from KisTool
virtual void resetCursorStyle ()
 

Private Member Functions

void addMaskPath (KoPointerEvent *event)
 
QPainterPath brushOutline ()
 
QPainterPath getBrushOutlinePath (const QPointF &documentPos, const KoPointerEvent *event)
 
void requestUpdateOutline (const QPointF &outlineDocPoint, const KoPointerEvent *event) override
 

Private Attributes

const QScopedPointer< Privatem_d
 

Additional Inherited Members

- Public Types inherited from KisTool
enum  { FLAG_USES_CUSTOM_PRESET =0x01 , FLAG_USES_CUSTOM_COMPOSITEOP =0x02 , FLAG_USES_CUSTOM_SIZE =0x04 }
 
enum  AlternateAction {
  ChangeSize = AlternateChangeSize , ChangeSizeSnap = AlternateChangeSizeSnap , SampleFgNode = AlternateSampleFgNode , SampleBgNode = AlternateSampleBgNode ,
  SampleFgImage = AlternateSampleFgImage , SampleBgImage = AlternateSampleBgImage , Secondary = AlternateSecondary , Third = AlternateThird ,
  Fourth = AlternateFourth , Fifth = AlternateFifth , NONE = 10000
}
 
enum  NodePaintAbility {
  VECTOR , CLONE , PAINT , UNPAINTABLE ,
  MYPAINTBRUSH_UNPAINTABLE
}
 
enum  ToolAction {
  Primary , AlternateChangeSize , AlternateChangeSizeSnap , AlternateSampleFgNode ,
  AlternateSampleBgNode , AlternateSampleFgImage , AlternateSampleBgImage , AlternateSecondary ,
  AlternateThird , AlternateFourth , AlternateFifth , Alternate_NONE = 10000
}
 
- Signals inherited from KisToolPaint
void sigPaintingFinished ()
 
- Signals inherited from KisTool
void isActiveChanged (bool isActivated)
 
- Signals inherited from KoToolBase
void activateTool (const QString &id)
 
void cursorChanged (const QCursor &cursor)
 
void selectionChanged (bool hasSelection)
 
void statusTextChanged (const QString &statusText)
 
void textModeChanged (bool inTextMode)
 
- Static Public Member Functions inherited from KisTool
static AlternateAction actionToAlternateAction (ToolAction action)
 
- Public Attributes inherited from KisTool
KoColor currentBgColor
 
float currentExposure {1.0}
 
KoColor currentFgColor
 
KisFilterConfigurationSP currentGenerator
 
KoAbstractGradientSP currentGradient
 
KoPatternSP currentPattern
 
QCursor cursor
 
bool m_isActive {false}
 
ToolMode m_mode {HOVER_MODE}
 
QWidget * optionWidget {0}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 
- Protected Types inherited from KisTool
enum  ToolMode : int {
  HOVER_MODE , PAINT_MODE , SECONDARY_PAINT_MODE , MIRROR_AXIS_SETUP_MODE ,
  GESTURE_MODE , PAN_MODE , OTHER , OTHER_1
}
 
- Protected Member Functions inherited from KisToolPaint
void activateAlternateAction (AlternateAction action) override
 
void addOptionWidgetLayout (QLayout *layout)
 Add the tool-specific layout to the default option widget layout.
 
virtual void addOptionWidgetOption (QWidget *control, QWidget *label=nullptr)
 Add a widget and a label to the current option widget layout.
 
void beginAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void canvasResourceChanged (int key, const QVariant &v) override
 
void continueAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void deactivateAlternateAction (AlternateAction action) override
 
void enableControl (QWidget *control, bool value)
 
void endAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
virtual KisOptimizedBrushOutline getOutlinePath (const QPointF &documentPos, const KoPointerEvent *event, KisPaintOpSettings::OutlineMode outlineMode)
 
bool isEraser () const
 
bool isOutlineEnabled () const
 
bool isOutlineVisible () const
 
virtual QString quickHelp () const
 
void setMode (ToolMode mode) override
 
void setOutlineEnabled (bool enabled)
 
void setOutlineVisible (bool visible)
 
void setSupportOutline (bool supportOutline)
 
void showControl (QWidget *control, bool value)
 
- Protected Member Functions inherited from KisTool
bool blockUntilOperationsFinished ()
 
void blockUntilOperationsFinishedForced ()
 
QPointF convertDocumentToWidget (const QPointF &pt)
 
QPoint convertToImagePixelCoordFloored (KoPointerEvent *e)
 
QPointF convertToPixelCoord (const QPointF &pt)
 
QPointF convertToPixelCoord (KoPointerEvent *e)
 
QPointF convertToPixelCoordAndAlignOnWidget (const QPointF &pt)
 
QPointF convertToPixelCoordAndSnap (const QPointF &pt, const QPointF &offset=QPointF())
 
QPointF convertToPixelCoordAndSnap (KoPointerEvent *e, const QPointF &offset=QPointF(), bool useModifiers=true)
 
QRectF convertToPt (const QRectF &rect)
 
qreal convertToPt (qreal value)
 
KoColor currentBgColor ()
 
KoColor currentFgColor ()
 
KisFilterConfigurationSP currentGenerator ()
 
KoAbstractGradientSP currentGradient ()
 
KisImageWSP currentImage ()
 
KisNodeSP currentNode () const
 
KisPaintOpPresetSP currentPaintOpPreset ()
 
KoPatternSP currentPattern ()
 
QCursor cursor () const
 
KisImageWSP image () const
 
virtual bool listeningToModifiers ()
 
virtual void listenToModifiers (bool listen)
 
virtual ToolMode mode () const
 
bool nodeEditable ()
 Checks checks if the current node is editable.
 
bool overrideCursorIfNotEditable ()
 Override the cursor appropriately if current node is not editable.
 
void paintToolOutline (QPainter *painter, const KisOptimizedBrushOutline &path)
 
KisOptimizedBrushOutline pixelToView (const KisOptimizedBrushOutline &path) const
 
QPainterPath pixelToView (const QPainterPath &pixelPath) const
 Convert a pixel path into a view path.
 
QPointF pixelToView (const QPoint &pixelCoord) const
 
QPointF pixelToView (const QPointF &pixelCoord) const
 Convert a floating point pixel coordinate into a view coordinate.
 
QPolygonF pixelToView (const QPolygonF &pixelPolygon) const
 Convert a pixel polygon into a view path.
 
QRectF pixelToView (const QRectF &pixelRect) const
 Convert a pixel rectangle into a view rectangle.
 
KisNodeList selectedNodes () const
 
bool selectionEditable ()
 Checks checks if the selection is editable, only applies to local selection as global selection is always editable.
 
void setCursor (const QCursor &cursor)
 
void updateCanvasPixelRect (const QRectF &pixelRect)
 Update the canvas for the given rectangle in image pixel coordinates.
 
void updateCanvasViewRect (const QRectF &viewRect)
 Update the canvas for the given rectangle in view coordinates.
 
QPointF viewToPixel (const QPointF &viewCoord) const
 
QPointF widgetCenterInWidgetPixels ()
 
- Protected Member Functions inherited from KoToolBase
virtual QList< QPointer< QWidget > > createOptionWidgets ()
 
int grabSensitivity () const
 Convenience function to get the current grab sensitivity.
 
qreal handleDocRadius () const
 
QRectF handleGrabRect (const QPointF &position) const
 
QRectF handlePaintRect (const QPointF &position) const
 
int handleRadius () const
 Convenience function to get the current handle radius.
 
bool isActivated () const
 
 KoToolBase (KoToolBasePrivate &dd)
 
KoPointerEventlastDeliveredPointerEvent () const
 
void setAbstractResource (KoAbstractCanvasResourceInterfaceSP abstractResource)
 
void setConverter (KoDerivedResourceConverterSP converter)
 
void setIsOpacityPresetMode (bool value)
 
void setMaskSyntheticEvents (bool value)
 
void setTextMode (bool value)
 
QHash< int, KoAbstractCanvasResourceInterfaceSPtoolAbstractResources ()
 
QHash< int, KoDerivedResourceConverterSPtoolConverters ()
 
void useCursor (const QCursor &cursor)
 
- Protected Attributes inherited from KisToolPaint
KisOptimizedBrushOutline m_currentOutline
 
QRectF m_oldColorPreviewUpdateRect
 
QRectF m_oldOutlineRect
 
QPointF m_outlineDocPoint
 
bool m_paintOutline {false}
 
- Protected Attributes inherited from KoToolBase
KoToolBasePrivated_ptr
 
- Properties inherited from KisTool
bool isActive
 

Detailed Description

Definition at line 31 of file kis_tool_smart_patch.h.

Constructor & Destructor Documentation

◆ KisToolSmartPatch()

KisToolSmartPatch::KisToolSmartPatch ( KoCanvasBase * canvas)

Definition at line 68 of file kis_tool_smart_patch.cpp.

70 m_d(new Private)
71{
73 setObjectName("tool_SmartPatch");
74 m_d->maskDev = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8());
75 m_d->maskDevPainter.begin( m_d->maskDev );
76
77 m_d->maskDevPainter.setPaintColor(KoColor(Qt::magenta, m_d->maskDev->colorSpace()));
78 m_d->maskDevPainter.setBackgroundColor(KoColor(Qt::white, m_d->maskDev->colorSpace()));
79 m_d->maskDevPainter.setFillStyle( KisPainter::FillStyleForegroundColor );
80}
static QCursor blankCursor()
Definition kis_cursor.cc:89
@ FillStyleForegroundColor
void setSupportOutline(bool supportOutline)
KisToolPaint(KoCanvasBase *canvas, const QCursor &cursor)
const QScopedPointer< Private > m_d
static KoColorSpaceRegistry * instance()
KisCanvas2 * canvas

References KisPainter::FillStyleForegroundColor, KoColorSpaceRegistry::instance(), m_d, and KisToolPaint::setSupportOutline().

◆ ~KisToolSmartPatch()

KisToolSmartPatch::~KisToolSmartPatch ( )
override

Definition at line 82 of file kis_tool_smart_patch.cpp.

83{
84 m_d->optionsWidget = nullptr;
85 m_d->maskDevPainter.end();
86}

References m_d.

Member Function Documentation

◆ activate

void KisToolSmartPatch::activate ( const QSet< KoShape * > & shapes)
overrideslot

Definition at line 88 of file kis_tool_smart_patch.cpp.

89{
91}
void activate(const QSet< KoShape * > &shapes) override

References KisToolPaint::activate().

◆ activatePrimaryAction()

void KisToolSmartPatch::activatePrimaryAction ( )
overridevirtual

Called by KisToolProxy when the primary action of the tool is going to be started now, that is when all the modifiers are pressed and the only thing left is just to press the mouse button. On coming of this callback the tool is supposed to prepare the cursor and/or the outline to show the user shat is going to happen next

Reimplemented from KisToolPaint.

Definition at line 103 of file kis_tool_smart_patch.cpp.

104{
105 setOutlineVisible(true);
107}
void setOutlineVisible(bool visible)
void activatePrimaryAction() override

References KisToolPaint::activatePrimaryAction(), and KisToolPaint::setOutlineVisible().

◆ addMaskPath()

void KisToolSmartPatch::addMaskPath ( KoPointerEvent * event)
private

Definition at line 115 of file kis_tool_smart_patch.cpp.

116{
117 KisCanvas2 *canvas2 = dynamic_cast<KisCanvas2 *>(canvas());
118 KIS_ASSERT(canvas2);
119 const KisCoordinatesConverter *converter = canvas2->coordinatesConverter();
120
121 QPointF imagePos = currentImage()->documentToPixel(event->point);
122 QPainterPath currentBrushOutline = brushOutline().translated(KisAlgebra2D::alignForZoom(imagePos, converter->effectivePhysicalZoom()));
123 m_d->maskDevPainter.fillPainterPath(currentBrushOutline);
124
125 canvas()->updateCanvas(currentImage()->pixelToDocument(m_d->maskDev->exactBounds()));
126}
KisCoordinatesConverter * coordinatesConverter
void updateCanvas(const QRectF &rc) override
QPointF documentToPixel(const QPointF &documentCoord) const
QPointF point
The point in document coordinates.
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
QPointF alignForZoom(const QPointF &pt, qreal zoom)
KisImageWSP currentImage()
Definition kis_tool.cc:393

References KisAlgebra2D::alignForZoom(), brushOutline(), Private::canvas, KisCanvas2::coordinatesConverter, KisTool::currentImage(), KisImage::documentToPixel(), KisCoordinatesConverter::effectivePhysicalZoom(), KIS_ASSERT, m_d, KoPointerEvent::point, and KisCanvas2::updateCanvas().

◆ beginPrimaryAction()

void KisToolSmartPatch::beginPrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when a primary action for the tool is started. The event stores the original event that started the stroke. The event is accepted by default. If the tool decides to ignore this particular action (e.g. when the node is not editable), it should call event->ignore(). Then no further continuePrimaryAction() or endPrimaryAction() will be called until the next user action.

Reimplemented from KisTool.

Definition at line 128 of file kis_tool_smart_patch.cpp.

129{
130 //we can only apply inpaint operation to paint layer
131 if ( currentNode().isNull() || !currentNode()->inherits("KisPaintLayer") || nodePaintAbility()!=NodePaintAbility::PAINT ) {
132 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
133 kiscanvas->viewManager()->
134 showFloatingMessage(
135 i18n("Select a paint layer to use this tool"),
136 QIcon(), 2000, KisFloatingMessage::Medium, Qt::AlignCenter);
137 event->ignore();
138 return;
139 }
140
141 addMaskPath(event);
144}
KisViewManager * viewManager() const
void setMode(ToolMode mode) override
void addMaskPath(KoPointerEvent *event)
KisTool::NodePaintAbility nodePaintAbility()
Definition kis_tool.cc:539
virtual void beginPrimaryAction(KoPointerEvent *event)
Definition kis_tool.cc:431
KisNodeSP currentNode() const
Definition kis_tool.cc:370
@ PAINT_MODE
Definition kis_tool.h:300

References addMaskPath(), KisTool::beginPrimaryAction(), Private::canvas, KisTool::currentNode(), KisFloatingMessage::Medium, KisTool::nodePaintAbility(), KisTool::PAINT, KisTool::PAINT_MODE, KisToolPaint::setMode(), and KisCanvas2::viewManager().

◆ brushOutline()

QPainterPath KisToolSmartPatch::brushOutline ( void )
private

Definition at line 189 of file kis_tool_smart_patch.cpp.

190{
191 const qreal diameter = m_d->brushRadius;
192 QPainterPath outline;
193 outline.addEllipse(QPointF(0,0), -0.5 * diameter, -0.5 * diameter );
194 return outline;
195}

References m_d.

◆ continuePrimaryAction()

void KisToolSmartPatch::continuePrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when the primary action is in progress of pointer movement. If the tool has ignored the event in beginPrimaryAction(), this method will not be called.

Reimplemented from KisTool.

Definition at line 146 of file kis_tool_smart_patch.cpp.

147{
149 addMaskPath(event);
151}
#define CHECK_MODE_SANITY_OR_RETURN(_mode)
Definition kis_tool.h:27
virtual void continuePrimaryAction(KoPointerEvent *event)
Definition kis_tool.cc:441

References addMaskPath(), CHECK_MODE_SANITY_OR_RETURN, KisTool::continuePrimaryAction(), and KisTool::PAINT_MODE.

◆ createOptionWidget()

QWidget * KisToolSmartPatch::createOptionWidget ( )
overridevirtual

Reimplement this if your tool actually has an option widget. Sets the option widget to 0 by default.

Reimplemented from KisToolPaint.

Definition at line 268 of file kis_tool_smart_patch.cpp.

269{
270 KisCanvas2 * kiscanvas = dynamic_cast<KisCanvas2*>(canvas());
271 KIS_ASSERT(kiscanvas);
272
273 m_d->optionsWidget = new KisToolSmartPatchOptionsWidget(kiscanvas->viewManager()->canvasResourceProvider(), 0);
274 m_d->optionsWidget->setObjectName(toolId() + "option widget");
275
276 return m_d->optionsWidget;
277}
KisCanvasResourceProvider * canvasResourceProvider()
Q_INVOKABLE QString toolId() const

References Private::canvas, KisViewManager::canvasResourceProvider(), KIS_ASSERT, m_d, KoToolBase::toolId(), and KisCanvas2::viewManager().

◆ deactivate

void KisToolSmartPatch::deactivate ( )
overrideslot

Definition at line 93 of file kis_tool_smart_patch.cpp.

94{
96}
void deactivate() override

References KisToolPaint::deactivate().

◆ deactivatePrimaryAction()

void KisToolSmartPatch::deactivatePrimaryAction ( )
overridevirtual

Called by KisToolProxy when the primary is no longer possible to be started now, e.g. when its modifiers and released. The tool is supposed to revert all the preparations it has done in activatePrimaryAction().

Reimplemented from KisToolPaint.

Definition at line 109 of file kis_tool_smart_patch.cpp.

110{
111 setOutlineVisible(false);
113}
void deactivatePrimaryAction() override

References KisToolPaint::deactivatePrimaryAction(), and KisToolPaint::setOutlineVisible().

◆ endPrimaryAction()

void KisToolSmartPatch::endPrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when the primary action is being finished, that is while mouseRelease or tabletRelease event. If the tool has ignored the event in beginPrimaryAction(), this method will not be called.

Reimplemented from KisTool.

Definition at line 153 of file kis_tool_smart_patch.cpp.

154{
156 addMaskPath(event);
159
160 KisCursorOverrideLock cursorLock(KisCursor::waitCursor());
161
162 int accuracy = 50; //default accuracy - middle value
163 int patchRadius = 4; //default radius, which works well for most cases tested
164
165 if (m_d->optionsWidget) {
166 accuracy = m_d->optionsWidget->getAccuracy();
167 patchRadius = m_d->optionsWidget->getPatchRadius();
168 }
169
170 KisResourcesSnapshotSP resources =
171 new KisResourcesSnapshot(image(), currentNode(), this->canvas()->resourceManager());
172
174 kundo2_i18n("Smart Patch"));
175
176 //actual inpaint operation. filling in areas masked by user
177 applicator.applyCommand( new InpaintCommand( KisPainter::convertToAlphaAsAlpha(m_d->maskDev),
178 currentNode()->paintDevice(),
179 accuracy, patchRadius,
180 resources->activeSelection()),
182
183 applicator.end();
184 image()->waitForDone();
185
186 m_d->maskDev->clear();
187}
QVector< KisImageSignalType > KisImageSignalVector
static QCursor waitCursor()
Definition kis_cursor.cc:54
void waitForDone()
static KisPaintDeviceSP convertToAlphaAsAlpha(KisPaintDeviceSP src)
The KisResourcesSnapshot class takes a snapshot of the various resources like colors and settings use...
KisSelectionSP activeSelection() const
KUndo2MagicString kundo2_i18n(const char *text)
virtual void endPrimaryAction(KoPointerEvent *event)
Definition kis_tool.cc:446
KisImageWSP image() const
Definition kis_tool.cc:332
@ HOVER_MODE
Definition kis_tool.h:299

References KisResourcesSnapshot::activeSelection(), addMaskPath(), KisProcessingApplicator::applyCommand(), KisStrokeJobData::BARRIER, Private::canvas, CHECK_MODE_SANITY_OR_RETURN, KisPainter::convertToAlphaAsAlpha(), KisTool::currentNode(), KisProcessingApplicator::end(), KisTool::endPrimaryAction(), KisStrokeJobData::EXCLUSIVE, KisTool::HOVER_MODE, KisTool::image(), kundo2_i18n(), m_d, KisProcessingApplicator::NONE, KisTool::PAINT_MODE, KisToolPaint::setMode(), KisCursor::waitCursor(), and KisImage::waitForDone().

◆ flags()

int KisToolSmartPatch::flags ( ) const
inlineoverridevirtual

◆ getBrushOutlinePath()

QPainterPath KisToolSmartPatch::getBrushOutlinePath ( const QPointF & documentPos,
const KoPointerEvent * event )
private

Definition at line 197 of file kis_tool_smart_patch.cpp.

199{
200 Q_UNUSED(event);
201
202 QPointF imagePos = currentImage()->documentToPixel(documentPos);
203 QPainterPath path = brushOutline();
204
205 KisCanvas2 *canvas2 = dynamic_cast<KisCanvas2 *>(canvas());
206 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(canvas2, QPainterPath());
207 const KisCoordinatesConverter *converter = canvas2->coordinatesConverter();
208
209 return path.translated(KisAlgebra2D::alignForZoom(imagePos, converter->effectivePhysicalZoom()));
210}
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KisAlgebra2D::alignForZoom(), brushOutline(), Private::canvas, KisCanvas2::coordinatesConverter, KisTool::currentImage(), KisImage::documentToPixel(), KisCoordinatesConverter::effectivePhysicalZoom(), and KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE.

◆ paint()

void KisToolSmartPatch::paint ( QPainter & painter,
const KoViewConverter & converter )
overridevirtual

Called by the canvas to paint any decorations that the tool deems needed. The painter has the top left of the canvas as its origin.

Parameters
painterused for painting the shape
converterto convert between internal and view coordinates.

Reimplemented from KisToolPaint.

Definition at line 248 of file kis_tool_smart_patch.cpp.

249{
250 Q_UNUSED(converter);
251
252 painter.save();
253 QPainterPath path = pixelToView(m_d->brushOutline);
254 paintToolOutline(&painter, path);
255 painter.restore();
256
257 painter.save();
258 painter.setBrush(Qt::magenta);
259 KisCanvas2 * kiscanvas = dynamic_cast<KisCanvas2*>(canvas());
260 QImage img = kiscanvas->displayColorConverter()->convertImageToDisplayColorSpace(m_d->maskDev);
261 if( !img.size().isEmpty() ){
262
263 painter.drawImage(pixelToView(m_d->maskDev->exactBounds()), img);
264 }
265 painter.restore();
266}
KisDisplayColorConverter displayColorConverter
QImage convertImageToDisplayColorSpace(KisPaintDeviceSP srcDevice, QRect source=QRect(), bool applyOcio=false) const
convertImageToDisplayColorSpace Same as convertColorToDisplayColorSpace, but then for a KisPaintDevic...
QPointF pixelToView(const QPoint &pixelCoord) const
Definition kis_tool.cc:269
void paintToolOutline(QPainter *painter, const KisOptimizedBrushOutline &path)
Definition kis_tool.cc:589

References Private::canvas, KisDisplayColorConverter::convertImageToDisplayColorSpace(), KisCanvas2::displayColorConverter, m_d, KisTool::paintToolOutline(), and KisTool::pixelToView().

◆ requestUpdateOutline()

void KisToolSmartPatch::requestUpdateOutline ( const QPointF & outlineDocPoint,
const KoPointerEvent * event )
overrideprivatevirtual

Reimplemented from KisToolPaint.

Definition at line 212 of file kis_tool_smart_patch.cpp.

213{
214 static QPointF lastDocPoint = QPointF(0,0);
215 if( event )
216 lastDocPoint=outlineDocPoint;
217
218 m_d->brushRadius = currentPaintOpPreset()->settings()->paintOpSize();
219 m_d->brushOutline = getBrushOutlinePath(lastDocPoint, event);
220
221 QRectF outlinePixelRect = m_d->brushOutline.boundingRect();
222 QRectF outlineDocRect = currentImage()->pixelToDocument(outlinePixelRect);
223
224 // This adjusted call is needed as we paint with a 3 pixel wide brush and the pen is outside the bounds of the path
225 // Pen uses view coordinates so we have to zoom the document value to match 2 pixel in view coordinates
226 // See BUG 275829
227 qreal zoomX;
228 qreal zoomY;
229 canvas()->viewConverter()->zoom(&zoomX, &zoomY);
230 qreal xoffset = 2.0/zoomX;
231 qreal yoffset = 2.0/zoomY;
232
233 if (!outlineDocRect.isEmpty()) {
234 outlineDocRect.adjust(-xoffset,-yoffset,xoffset,yoffset);
235 }
236
237 if (!m_d->oldOutlineRect.isEmpty()) {
238 canvas()->updateCanvas(m_d->oldOutlineRect);
239 }
240
241 if (!outlineDocRect.isEmpty()) {
242 canvas()->updateCanvas(outlineDocRect);
243 }
244
245 m_d->oldOutlineRect = outlineDocRect;
246}
const KoViewConverter * viewConverter() const override
QPointF pixelToDocument(const QPointF &pixelCoord) const
QPainterPath getBrushOutlinePath(const QPointF &documentPos, const KoPointerEvent *event)
virtual void zoom(qreal *zoomX, qreal *zoomY) const
KisPaintOpPresetSP currentPaintOpPreset()
Definition kis_tool.cc:359

References Private::canvas, KisTool::currentImage(), KisTool::currentPaintOpPreset(), getBrushOutlinePath(), m_d, KisImage::pixelToDocument(), KisCanvas2::updateCanvas(), KisCanvas2::viewConverter(), and KoViewConverter::zoom().

◆ resetCursorStyle

void KisToolSmartPatch::resetCursorStyle ( )
overrideprotectedslot

Definition at line 98 of file kis_tool_smart_patch.cpp.

99{
101}
virtual void resetCursorStyle()
Definition kis_tool.cc:613

References KisTool::resetCursorStyle().

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisToolSmartPatch::m_d
private

Definition at line 65 of file kis_tool_smart_patch.h.


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