Krita Source Code Documentation
Loading...
Searching...
No Matches
KisToolBasicBrushBase Class Referenceabstract

#include <KisToolBasicBrushBase.h>

+ Inheritance diagram for KisToolBasicBrushBase:

Public Types

enum  ToolType { PAINT , SELECT }
 
- 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
}
 

Public Slots

void activate (const QSet< KoShape * > &shapes) override
 
void deactivate () override
 
void setPreviewColor (const QColor &color)
 
- Public Slots inherited from KisToolShape
void activate (const QSet< KoShape * > &shapes) override
 
virtual void fillSettingChanged (int value)
 
virtual void outlineSettingChanged (int value)
 
virtual void patternRotationSettingChanged (qreal value)
 
virtual void patternScaleSettingChanged (qreal value)
 
- 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 activateAlternateAction (AlternateAction action) override
 
void beginAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void beginPrimaryAction (KoPointerEvent *event) override
 
void continueAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void continuePrimaryAction (KoPointerEvent *event) override
 
void deactivateAlternateAction (AlternateAction action) override
 
void endAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void endPrimaryAction (KoPointerEvent *event) override
 
 KisToolBasicBrushBase (KoCanvasBase *canvas, ToolType type, const QCursor &cursor=KisCursor::load("tool_outline_selection_cursor.png", 5, 5))
 
void mouseMoveEvent (KoPointerEvent *event) override
 
void paint (QPainter &gc, const KoViewConverter &converter) override
 
qreal pressureToCurve (qreal pressure)
 
 ~KisToolBasicBrushBase () override
 
- Public Member Functions inherited from KisToolShape
int flags () const override
 
 KisToolShape (KoCanvasBase *canvas, const QCursor &cursor)
 
 ~KisToolShape () 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 Enter key or any equivalent. 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
 
void updateSettings ()
 
- Protected Slots inherited from KisTool
virtual void resetCursorStyle ()
 

Protected Member Functions

virtual void finishStroke (const QPainterPath &stroke)=0
 
KisOptimizedBrushOutline getOutlinePath (const QPointF &documentPos, const KoPointerEvent *event, KisPaintOpSettings::OutlineMode outlineMode) override
 
- Protected Member Functions inherited from KisToolShape
void addPathShape (KoPathShape *pathShape, const KUndo2MagicString &name)
 
void addShape (KoShape *shape)
 
virtual void beginShape ()
 
QWidget * createOptionWidget () override
 
qreal currentStrokeWidth () const
 
virtual void endShape ()
 
KisToolShapeUtils::FillStyle fillStyle ()
 
QTransform fillTransform ()
 
ShapeAddInfo shouldAddShape (KisNodeSP currentNode) const
 
KisToolShapeUtils::StrokeStyle strokeStyle ()
 
- Protected Member Functions inherited from KisToolPaint
void activateAlternateAction (AlternateAction action) override
 
void activatePrimaryAction () 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 deactivatePrimaryAction () override
 
void enableControl (QWidget *control, bool value)
 
void endAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
bool isEraser () const
 
bool isOutlineEnabled () const
 
bool isOutlineVisible () const
 
void paint (QPainter &gc, const KoViewConverter &converter) override
 
virtual QString quickHelp () const
 
virtual void requestUpdateOutline (const QPointF &outlineDocPoint, const KoPointerEvent *event)
 
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)
 

Private Member Functions

QPainterPath generateSegment (const QPointF &point1, qreal radius1, const QPointF &point2, qreal radius2) const
 
void update (const QRectF &strokeSegmentRect)
 

Private Attributes

QPointF m_changeSizeInitialGestureDocPoint
 
QPoint m_changeSizeInitialGestureGlobalPoint
 
QPointF m_changeSizeLastDocumentPoint
 
qreal m_changeSizeLastPaintOpSize {0.0}
 
bool m_forceAlwaysFullSizedOutline {true}
 
QPointF m_lastPosition
 
qreal m_lastPressure {1.0}
 
OutlineStyle m_outlineStyle {OUTLINE_FULL}
 
QPainterPath m_path
 
QVector< qreal > m_pressureSamples
 
QColor m_previewColor
 
bool m_showOutlineWhilePainting {true}
 
ToolType m_type {PAINT}
 

Static Private Attributes

static constexpr int feedbackLineWidth {2}
 
static constexpr int levelOfPressureResolution = 1024
 

Additional Inherited Members

- 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 KisToolShape
WdgGeometryOptionsm_shapeOptionsWidget
 
- 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 Attributes inherited from KisToolShape
KConfigGroup m_configGroup
 
- 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 13 of file KisToolBasicBrushBase.h.

Member Enumeration Documentation

◆ ToolType

Enumerator
PAINT 
SELECT 

Definition at line 18 of file KisToolBasicBrushBase.h.

Constructor & Destructor Documentation

◆ KisToolBasicBrushBase()

KisToolBasicBrushBase::KisToolBasicBrushBase ( KoCanvasBase * canvas,
ToolType type,
const QCursor & cursor = KisCursor::load("tool_outline_selection_cursor.png", 5, 5) )

Definition at line 25 of file KisToolBasicBrushBase.cpp.

27 , m_type(type)
28 , m_previewColor(0, 255, 0, 128)
29{
31 connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(updateSettings()));
33}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static KisConfigNotifier * instance()
void setSupportOutline(bool supportOutline)
KisToolShape(KoCanvasBase *canvas, const QCursor &cursor)
QCursor cursor
Definition kis_tool.cc:64
KisCanvas2 * canvas

References connect(), KisConfigNotifier::instance(), KisToolPaint::setSupportOutline(), and updateSettings().

◆ ~KisToolBasicBrushBase()

KisToolBasicBrushBase::~KisToolBasicBrushBase ( )
override

Definition at line 35 of file KisToolBasicBrushBase.cpp.

36{}

Member Function Documentation

◆ activate

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

Definition at line 281 of file KisToolBasicBrushBase.cpp.

282{
283 m_lastPressure = 1.0;
284
286}
void activate(const QSet< KoShape * > &shapes) override

References KisToolShape::activate(), and m_lastPressure.

◆ activateAlternateAction()

void KisToolBasicBrushBase::activateAlternateAction ( AlternateAction action)
overridevirtual

Reimplemented from KisTool.

Definition at line 124 of file KisToolBasicBrushBase.cpp.

125{
126 if (action != ChangeSize && action != ChangeSizeSnap) {
128 return;
129 }
130
132 setOutlineVisible(true);
133}
static QCursor blankCursor()
Definition kis_cursor.cc:89
void setOutlineVisible(bool visible)
void useCursor(const QCursor &cursor)
QAction * action(const QString &name) const
virtual void activateAlternateAction(AlternateAction action)
Definition kis_tool.cc:456
@ ChangeSizeSnap
Definition kis_tool.h:136
@ ChangeSize
Definition kis_tool.h:135

References KoToolBase::action(), KisTool::activateAlternateAction(), KisCursor::blankCursor(), KisTool::ChangeSize, KisTool::ChangeSizeSnap, KisToolPaint::setOutlineVisible(), and KoToolBase::useCursor().

◆ beginAlternateAction()

void KisToolBasicBrushBase::beginAlternateAction ( KoPointerEvent * event,
AlternateAction action )
overridevirtual

Reimplemented from KisTool.

Definition at line 146 of file KisToolBasicBrushBase.cpp.

147{
148 if (action != ChangeSize && action != ChangeSizeSnap) {
150 return;
151 }
152
156
157 m_changeSizeLastDocumentPoint = event->point;
158 m_changeSizeLastPaintOpSize = currentPaintOpPreset()->settings()->paintOpSize();
159}
void setMode(ToolMode mode) override
KisPaintOpPresetSP currentPaintOpPreset()
Definition kis_tool.cc:359
@ GESTURE_MODE
Definition kis_tool.h:303
virtual void beginAlternateAction(KoPointerEvent *event, AlternateAction action)
Definition kis_tool.cc:466

References KoToolBase::action(), KisTool::beginAlternateAction(), KisTool::ChangeSize, KisTool::ChangeSizeSnap, KisTool::currentPaintOpPreset(), KisTool::GESTURE_MODE, m_changeSizeInitialGestureDocPoint, m_changeSizeInitialGestureGlobalPoint, m_changeSizeLastDocumentPoint, m_changeSizeLastPaintOpSize, and KisToolPaint::setMode().

◆ beginPrimaryAction()

void KisToolBasicBrushBase::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 58 of file KisToolBasicBrushBase.cpp.

59{
60 NodePaintAbility paintability = nodePaintAbility();
61 if ((m_type == PAINT && (!nodeEditable() || paintability == UNPAINTABLE || paintability == KisToolPaint::CLONE || paintability == KisToolPaint::MYPAINTBRUSH_UNPAINTABLE)) || (m_type == SELECT && !selectionEditable())) {
62
63 if (paintability == KisToolPaint::CLONE){
64 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
65 QString message = i18n("This tool cannot paint on clone layers. Please select a paint or vector layer or mask.");
66 kiscanvas->viewManager()->showFloatingMessage(message, koIcon("object-locked"));
67 }
68
69 if (paintability == KisToolPaint::MYPAINTBRUSH_UNPAINTABLE) {
70 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
71 QString message = i18n("The MyPaint Brush Engine is not available for this colorspace");
72 kiscanvas->viewManager()->showFloatingMessage(message, koIcon("object-locked"));
73 }
74
75 event->ignore();
76 return;
77 }
78
80
81 beginShape();
82
83 const QPointF position = convertToPixelCoord(event);
84 const qreal pressure = pressureToCurve(event->pressure());
85 const qreal radius = pressure * currentPaintOpPreset()->settings()->paintOpSize() / 2.0;
86 m_path = QPainterPath(position);
87 m_path.setFillRule(Qt::WindingFill);
88 m_path.addEllipse(position, radius, radius);
89
90 m_lastPosition = position;
91 m_lastPressure = pressure;
92
93 update(m_path.boundingRect());
94}
KisViewManager * viewManager() const
void update(const QRectF &strokeSegmentRect)
qreal pressureToCurve(qreal pressure)
virtual void beginShape()
void showFloatingMessage(const QString &message, const QIcon &icon, int timeout=4500, KisFloatingMessage::Priority priority=KisFloatingMessage::Medium, int alignment=Qt::AlignCenter|Qt::TextWordWrap)
shows a floating message in the top right corner of the canvas
qreal pressure() const
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25
QPointF convertToPixelCoord(KoPointerEvent *e)
Definition kis_tool.cc:189
KisTool::NodePaintAbility nodePaintAbility()
Definition kis_tool.cc:539
bool nodeEditable()
Checks checks if the current node is editable.
Definition kis_tool.cc:651
@ PAINT_MODE
Definition kis_tool.h:300
bool selectionEditable()
Checks checks if the selection is editable, only applies to local selection as global selection is al...
Definition kis_tool.cc:696
NodePaintAbility
Definition kis_tool.h:148
@ MYPAINTBRUSH_UNPAINTABLE
Definition kis_tool.h:153
@ UNPAINTABLE
Definition kis_tool.h:152

References KisToolShape::beginShape(), Private::canvas, KisTool::CLONE, KisTool::convertToPixelCoord(), KisTool::currentPaintOpPreset(), koIcon, m_lastPosition, m_lastPressure, m_path, m_type, KisTool::MYPAINTBRUSH_UNPAINTABLE, KisTool::nodeEditable(), KisTool::nodePaintAbility(), PAINT, KisTool::PAINT_MODE, KoPointerEvent::pressure(), pressureToCurve(), SELECT, KisTool::selectionEditable(), KisToolPaint::setMode(), KisViewManager::showFloatingMessage(), KisTool::UNPAINTABLE, update(), and KisCanvas2::viewManager().

◆ continueAlternateAction()

void KisToolBasicBrushBase::continueAlternateAction ( KoPointerEvent * event,
AlternateAction action )
overridevirtual

Reimplemented from KisTool.

Definition at line 161 of file KisToolBasicBrushBase.cpp.

162{
163 if (action != ChangeSize && action != ChangeSizeSnap) {
165 return;
166 }
167
168 QPointF lastWidgetPosition = convertDocumentToWidget(m_changeSizeLastDocumentPoint);
169 QPointF actualWidgetPosition = convertDocumentToWidget(event->point);
170
171 QPointF offset = actualWidgetPosition - lastWidgetPosition;
172
173 KisCanvas2 *canvas2 = dynamic_cast<KisCanvas2 *>(canvas());
174 KIS_ASSERT(canvas2);
175 QRect screenRect = QGuiApplication::primaryScreen()->availableVirtualGeometry();
176
177 qreal scaleX = 0;
178 qreal scaleY = 0;
179 canvas2->coordinatesConverter()->imageScale(&scaleX, &scaleY);
180
181 const qreal maxBrushSize = KisImageConfig(true).maxBrushSize();
182 const qreal effectiveMaxDragSize = 0.5 * screenRect.width();
183 const qreal effectiveMaxBrushSize = qMin(maxBrushSize, effectiveMaxDragSize / scaleX);
184
185 const qreal scaleCoeff = effectiveMaxBrushSize / effectiveMaxDragSize;
186 const qreal sizeDiff = scaleCoeff * offset.x() ;
187
188 if (qAbs(sizeDiff) > 0.01) {
189 KisPaintOpSettingsSP settings = currentPaintOpPreset()->settings();
190
191 qreal newSize = m_changeSizeLastPaintOpSize + sizeDiff;
192
193 if (action == ChangeSizeSnap) {
194 newSize = qMax(qRound(newSize), 1);
195 }
196
197 newSize = qBound(0.01, newSize, maxBrushSize);
198
199 settings->setPaintOpSize(newSize);
200
202
203 m_changeSizeLastDocumentPoint = event->point;
205 }
206}
KisCoordinatesConverter * coordinatesConverter
void imageScale(qreal *scaleX, qreal *scaleY) const
int maxBrushSize(bool defaultValue=false) const
virtual void requestUpdateOutline(const QPointF &outlineDocPoint, const KoPointerEvent *event)
QPointF point
The point in document coordinates.
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
virtual void continueAlternateAction(KoPointerEvent *event, AlternateAction action)
Definition kis_tool.cc:477
QPointF convertDocumentToWidget(const QPointF &pt)
Definition kis_tool.cc:181

References KoToolBase::action(), Private::canvas, KisTool::ChangeSize, KisTool::ChangeSizeSnap, KisTool::continueAlternateAction(), KisTool::convertDocumentToWidget(), KisCanvas2::coordinatesConverter, KisTool::currentPaintOpPreset(), KisCoordinatesConverter::imageScale(), KIS_ASSERT, m_changeSizeInitialGestureDocPoint, m_changeSizeLastDocumentPoint, m_changeSizeLastPaintOpSize, KisImageConfig::maxBrushSize(), KoPointerEvent::point, and KisToolPaint::requestUpdateOutline().

◆ continuePrimaryAction()

void KisToolBasicBrushBase::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 96 of file KisToolBasicBrushBase.cpp.

97{
99
100 const QPointF position = convertToPixelCoord(event);
101 const qreal pressure = pressureToCurve(event->pressure());
102 const qreal brushRadius = currentPaintOpPreset()->settings()->paintOpSize() / 2.0;
103 const QPainterPath segment = generateSegment(m_lastPosition, m_lastPressure * brushRadius, position, pressure * brushRadius);
104 m_path.addPath(segment);
105
106 m_lastPosition = position;
107 m_lastPressure = pressure;
108
109 requestUpdateOutline(event->point, event);
110 update(segment.boundingRect());
111}
QPainterPath generateSegment(const QPointF &point1, qreal radius1, const QPointF &point2, qreal radius2) const
#define CHECK_MODE_SANITY_OR_RETURN(_mode)
Definition kis_tool.h:27

References CHECK_MODE_SANITY_OR_RETURN, KisTool::convertToPixelCoord(), KisTool::currentPaintOpPreset(), generateSegment(), m_lastPosition, m_lastPressure, m_path, KisTool::PAINT_MODE, KoPointerEvent::point, KoPointerEvent::pressure(), pressureToCurve(), KisToolPaint::requestUpdateOutline(), and update().

◆ deactivate

void KisToolBasicBrushBase::deactivate ( )
overrideslot

Definition at line 288 of file KisToolBasicBrushBase.cpp.

289{
290 KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
291 KIS_ASSERT_RECOVER_RETURN(kisCanvas);
292 kisCanvas->updateCanvas();
293
295}
void updateCanvas(const QRectF &rc) override
virtual void deactivate()
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75

References Private::canvas, KoToolBase::deactivate(), KIS_ASSERT_RECOVER_RETURN, and KisCanvas2::updateCanvas().

◆ deactivateAlternateAction()

void KisToolBasicBrushBase::deactivateAlternateAction ( AlternateAction action)
overridevirtual

Reimplemented from KisTool.

Definition at line 135 of file KisToolBasicBrushBase.cpp.

136{
137 if (action != ChangeSize && action != ChangeSizeSnap) {
139 return;
140 }
141
143 setOutlineVisible(false);
144}
virtual void deactivateAlternateAction(AlternateAction action)
Definition kis_tool.cc:461

References KoToolBase::action(), KisTool::ChangeSize, KisTool::ChangeSizeSnap, KisTool::deactivateAlternateAction(), resetCursorStyle(), and KisToolPaint::setOutlineVisible().

◆ endAlternateAction()

void KisToolBasicBrushBase::endAlternateAction ( KoPointerEvent * event,
AlternateAction action )
overridevirtual

◆ endPrimaryAction()

void KisToolBasicBrushBase::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 113 of file KisToolBasicBrushBase.cpp.

114{
115 Q_UNUSED(event);
116
119
120 endShape();
122}
virtual void finishStroke(const QPainterPath &stroke)=0
virtual void endShape()

References CHECK_MODE_SANITY_OR_RETURN, KisToolShape::endShape(), finishStroke(), KisTool::HOVER_MODE, m_path, KisTool::PAINT_MODE, and KisToolPaint::setMode().

◆ finishStroke()

virtual void KisToolBasicBrushBase::finishStroke ( const QPainterPath & stroke)
protectedpure virtual

Implemented in KisBrushEnclosingProducer.

◆ generateSegment()

QPainterPath KisToolBasicBrushBase::generateSegment ( const QPointF & point1,
qreal radius1,
const QPointF & point2,
qreal radius2 ) const
private

Definition at line 343 of file KisToolBasicBrushBase.cpp.

344{
345 const QPointF &p1 = radius1 < radius2 ? point2 : point1;
346 const QPointF &p2 = radius1 < radius2 ? point1 : point2;
347 const qreal &r1 = radius1 < radius2 ? radius2 : radius1;
348 const qreal &r2 = radius1 < radius2 ? radius1 : radius2;
349 const QPointF deltaP1P2 = p2 - p1;
350 const qreal deltaR1R2 = r1 - r2;
351 QPointF tangentPointP11, tangentPointP12, tangentPointP21, tangentPointP22;
352
353 if (qFuzzyIsNull(deltaR1R2)) {
354 // Same radius case
355 const qreal deltaP1P2Length = std::sqrt(deltaP1P2.x() * deltaP1P2.x() + deltaP1P2.y() * deltaP1P2.y());
356 const QPointF deltaP1P2Normalized = deltaP1P2 / deltaP1P2Length;
357 tangentPointP11 = p1 + QPointF(deltaP1P2Normalized.y(), -deltaP1P2Normalized.x()) * r1;
358 tangentPointP12 = p1 + QPointF(-deltaP1P2Normalized.y(), deltaP1P2Normalized.x()) * r1;
359 tangentPointP21 = p2 + QPointF(deltaP1P2Normalized.y(), -deltaP1P2Normalized.x()) * r2;
360 tangentPointP22 = p2 + QPointF(-deltaP1P2Normalized.y(), deltaP1P2Normalized.x()) * r2;
361 } else {
362 // General case
363 const QPointF tangentIntersectionPoint(
364 (p2.x() * r1 - p1.x() * r2) / deltaR1R2,
365 (p2.y() * r1 - p1.y() * r2) / deltaR1R2
366 );
367 auto f = [](qreal t1, qreal t2, qreal t3, qreal t4, qreal sign) -> qreal
368 {
369 return (t1 + sign * t2) / t3 + t4;
370 };
371 {
372 const qreal r1Squared = r1 * r1;
373 const QPointF deltaP1TangentIntersectionPoint = tangentIntersectionPoint - p1;
374 const qreal deltaP1TangentIntersectionPointLengthSquared =
375 deltaP1TangentIntersectionPoint.x() * deltaP1TangentIntersectionPoint.x() +
376 deltaP1TangentIntersectionPoint.y() * deltaP1TangentIntersectionPoint.y();
377 const QPointF t11 = r1Squared * deltaP1TangentIntersectionPoint;
378 const QPointF t12 = r1 * deltaP1TangentIntersectionPoint * std::sqrt(deltaP1TangentIntersectionPointLengthSquared - r1Squared);
379 tangentPointP11 = QPointF(
380 f(t11.x(), t12.y(), deltaP1TangentIntersectionPointLengthSquared, p1.x(), 1.0),
381 f(t11.y(), t12.x(), deltaP1TangentIntersectionPointLengthSquared, p1.y(), -1.0)
382 );
383 tangentPointP12 = QPointF(
384 f(t11.x(), t12.y(), deltaP1TangentIntersectionPointLengthSquared, p1.x(), -1.0),
385 f(t11.y(), t12.x(), deltaP1TangentIntersectionPointLengthSquared, p1.y(), 1.0)
386 );
387 }
388 {
389 const qreal r2Squared = r2 * r2;
390 const QPointF deltaP2TangentIntersectionPoint = tangentIntersectionPoint - p2;
391 const qreal deltaP2TangentIntersectionPointLengthSquared =
392 deltaP2TangentIntersectionPoint.x() * deltaP2TangentIntersectionPoint.x() +
393 deltaP2TangentIntersectionPoint.y() * deltaP2TangentIntersectionPoint.y();
394 const QPointF t11 = r2Squared * deltaP2TangentIntersectionPoint;
395 const QPointF t12 = r2 * deltaP2TangentIntersectionPoint * std::sqrt(deltaP2TangentIntersectionPointLengthSquared - r2Squared);
396 tangentPointP21 = QPointF(
397 f(t11.x(), t12.y(), deltaP2TangentIntersectionPointLengthSquared, p2.x(), 1.0),
398 f(t11.y(), t12.x(), deltaP2TangentIntersectionPointLengthSquared, p2.y(), -1.0)
399 );
400 tangentPointP22 = QPointF(
401 f(t11.x(), t12.y(), deltaP2TangentIntersectionPointLengthSquared, p2.x(), -1.0),
402 f(t11.y(), t12.x(), deltaP2TangentIntersectionPointLengthSquared, p2.y(), 1.0)
403 );
404 }
405 }
406
407 QPainterPath path;
408 path.setFillRule(Qt::WindingFill);
409 path.moveTo(tangentPointP11);
410 path.lineTo(tangentPointP21);
411 path.lineTo(tangentPointP22);
412 path.lineTo(tangentPointP12);
413 path.closeSubpath();
414 path.addEllipse(point2, radius2, radius2);
415 return path;
416}
QPointF r2
QPointF r1
QPointF p2
QPointF p1
static bool qFuzzyIsNull(half h)

References p1, p2, qFuzzyIsNull(), r1, r2, and sign().

◆ getOutlinePath()

KisOptimizedBrushOutline KisToolBasicBrushBase::getOutlinePath ( const QPointF & documentPos,
const KoPointerEvent * event,
KisPaintOpSettings::OutlineMode outlineMode )
overrideprotectedvirtual

Reimplemented from KisToolPaint.

Definition at line 254 of file KisToolBasicBrushBase.cpp.

257{
258 Q_UNUSED(documentPos);
259 Q_UNUSED(event);
260
261 if (!outlineMode.isVisible) {
262 return {};
263 }
264 const qreal radius =
265 mode() != KisTool::PAINT_MODE || outlineMode.forceFullSize
266 ? currentPaintOpPreset()->settings()->paintOpSize() / 2.0
267 : m_lastPressure * currentPaintOpPreset()->settings()->paintOpSize() / 2.0;
268 QPainterPath outline;
269 outline.addEllipse(m_lastPosition, radius, radius);
270 return outline;
271}
virtual ToolMode mode() const
Definition kis_tool.cc:407

References KisTool::currentPaintOpPreset(), KisPaintOpSettings::OutlineMode::forceFullSize, KisPaintOpSettings::OutlineMode::isVisible, m_lastPosition, m_lastPressure, KisTool::mode(), and KisTool::PAINT_MODE.

◆ mouseMoveEvent()

void KisToolBasicBrushBase::mouseMoveEvent ( KoPointerEvent * event)
overridevirtual

Called when the mouse or stylus moved over the canvas. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this mouse or stylus move

Reimplemented from KisTool.

Definition at line 50 of file KisToolBasicBrushBase.cpp.

51{
52 if (mode() == KisTool::HOVER_MODE) {
54 }
56}
virtual void mouseMoveEvent(KoPointerEvent *event)=0

References KisTool::convertToPixelCoord(), KisTool::HOVER_MODE, m_lastPosition, KisTool::mode(), and KoToolBase::mouseMoveEvent().

◆ paint()

void KisToolBasicBrushBase::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.

Implements KoToolBase.

Definition at line 273 of file KisToolBasicBrushBase.cpp.

274{
275 if (mode() == KisTool::PAINT_MODE) {
276 gc.fillPath(pixelToView(m_path), m_previewColor);
277 }
278 KisToolShape::paint(gc, converter);
279}
virtual void paint(QPainter &painter, const KoViewConverter &converter)=0
QPointF pixelToView(const QPoint &pixelCoord) const
Definition kis_tool.cc:269

References m_path, m_previewColor, KisTool::mode(), KoToolBase::paint(), KisTool::PAINT_MODE, and KisTool::pixelToView().

◆ pressureToCurve()

qreal KisToolBasicBrushBase::pressureToCurve ( qreal pressure)

Definition at line 338 of file KisToolBasicBrushBase.cpp.

339{
341}
QVector< qreal > m_pressureSamples
static qreal interpolateLinear(qreal normalizedValue, const QVector< qreal > &transfer)

References KisCubicCurve::interpolateLinear(), and m_pressureSamples.

◆ resetCursorStyle

void KisToolBasicBrushBase::resetCursorStyle ( )
overrideprotectedslot

Definition at line 302 of file KisToolBasicBrushBase.cpp.

303{
304 KisConfig cfg(true);
305
306 switch (cfg.newCursorStyle()) {
309 break;
312 break;
315 break;
318 break;
321 break;
324 break;
327 break;
330 break;
332 default:
334 break;
335 }
336}
static QCursor pixelBlackCursor()
Definition kis_cursor.cc:44
static QCursor crossCursor()
Definition kis_cursor.cc:34
static QCursor triangleRightHandedCursor()
static QCursor arrowCursor()
Definition kis_cursor.cc:24
static QCursor triangleLeftHandedCursor()
static QCursor roundCursor()
Definition kis_cursor.cc:39
static QCursor pixelWhiteCursor()
Definition kis_cursor.cc:49
@ CURSOR_STYLE_POINTER
Definition kis_global.h:65
@ CURSOR_STYLE_SMALL_ROUND
Definition kis_global.h:66
@ CURSOR_STYLE_CROSSHAIR
Definition kis_global.h:67
@ CURSOR_STYLE_TOOLICON
Definition kis_global.h:64
@ CURSOR_STYLE_TRIANGLE_RIGHTHANDED
Definition kis_global.h:68
@ CURSOR_STYLE_WHITE_PIXEL
Definition kis_global.h:71
@ CURSOR_STYLE_BLACK_PIXEL
Definition kis_global.h:70
@ CURSOR_STYLE_TRIANGLE_LEFTHANDED
Definition kis_global.h:69
@ CURSOR_STYLE_NO_CURSOR
Definition kis_global.h:63
virtual void resetCursorStyle()
Definition kis_tool.cc:613

References KisCursor::arrowCursor(), KisCursor::blankCursor(), KisCursor::crossCursor(), CURSOR_STYLE_BLACK_PIXEL, CURSOR_STYLE_CROSSHAIR, CURSOR_STYLE_NO_CURSOR, CURSOR_STYLE_POINTER, CURSOR_STYLE_SMALL_ROUND, CURSOR_STYLE_TOOLICON, CURSOR_STYLE_TRIANGLE_LEFTHANDED, CURSOR_STYLE_TRIANGLE_RIGHTHANDED, CURSOR_STYLE_WHITE_PIXEL, KisConfig::newCursorStyle(), KisCursor::pixelBlackCursor(), KisCursor::pixelWhiteCursor(), KisTool::resetCursorStyle(), KisCursor::roundCursor(), KisCursor::triangleLeftHandedCursor(), KisCursor::triangleRightHandedCursor(), and KoToolBase::useCursor().

◆ setPreviewColor

void KisToolBasicBrushBase::setPreviewColor ( const QColor & color)
slot

Definition at line 297 of file KisToolBasicBrushBase.cpp.

298{
299 m_previewColor = color;
300}

References m_previewColor.

◆ update()

void KisToolBasicBrushBase::update ( const QRectF & strokeSegmentRect)
private

Definition at line 221 of file KisToolBasicBrushBase.cpp.

222{
223 QRectF segmentRect;
224 QRectF outlineRect;
225 // Segment rect
226 if (mode() == KisTool::PAINT_MODE) {
227 if (strokeSegmentRect.isValid()) {
228 segmentRect = kisGrowRect(strokeSegmentRect, feedbackLineWidth);
229 }
230 }
231 // Outline rect
234 const qreal radius =
236 ? currentPaintOpPreset()->settings()->paintOpSize() / 2.0
237 : m_lastPressure * currentPaintOpPreset()->settings()->paintOpSize() / 2.0;
238 outlineRect =
240 QRectF(m_lastPosition - QPointF(radius, radius), m_lastPosition + QPointF(radius, radius)),
242 );
243 }
244 // Update
245 if (segmentRect.isValid() && outlineRect.isValid()) {
246 updateCanvasPixelRect(segmentRect.united(outlineRect));
247 } else if (segmentRect.isValid()) {
248 updateCanvasPixelRect(segmentRect);
249 } else if (outlineRect.isValid()) {
250 updateCanvasPixelRect(outlineRect);
251 }
252}
static constexpr int feedbackLineWidth
@ OUTLINE_NONE
Definition kis_global.h:54
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186
void updateCanvasPixelRect(const QRectF &pixelRect)
Update the canvas for the given rectangle in image pixel coordinates.
Definition kis_tool.cc:322

References KisTool::currentPaintOpPreset(), feedbackLineWidth, kisGrowRect(), m_forceAlwaysFullSizedOutline, m_lastPosition, m_lastPressure, m_outlineStyle, m_showOutlineWhilePainting, KisTool::mode(), OUTLINE_NONE, KisTool::PAINT_MODE, and KisTool::updateCanvasPixelRect().

◆ updateSettings

void KisToolBasicBrushBase::updateSettings ( )
protectedslot

Definition at line 38 of file KisToolBasicBrushBase.cpp.

39{
40 KisConfig cfg(true);
41 // Pressure curve
42 KisCubicCurve curve(cfg.pressureTabletCurve());
43 m_pressureSamples = curve.floatTransfer(levelOfPressureResolution + 1);
44 // Outline options
45 m_outlineStyle = cfg.newOutlineStyle();
46 m_showOutlineWhilePainting = cfg.showOutlineWhilePainting();
47 m_forceAlwaysFullSizedOutline = cfg.forceAlwaysFullSizedOutline();
48}
static constexpr int levelOfPressureResolution

References KisCubicCurve::floatTransfer(), KisConfig::forceAlwaysFullSizedOutline(), levelOfPressureResolution, m_forceAlwaysFullSizedOutline, m_outlineStyle, m_pressureSamples, m_showOutlineWhilePainting, KisConfig::newOutlineStyle(), KisConfig::pressureTabletCurve(), and KisConfig::showOutlineWhilePainting().

Member Data Documentation

◆ feedbackLineWidth

constexpr int KisToolBasicBrushBase::feedbackLineWidth {2}
staticconstexprprivate

Definition at line 58 of file KisToolBasicBrushBase.h.

58{2};

◆ levelOfPressureResolution

constexpr int KisToolBasicBrushBase::levelOfPressureResolution = 1024
staticconstexprprivate

Definition at line 57 of file KisToolBasicBrushBase.h.

◆ m_changeSizeInitialGestureDocPoint

QPointF KisToolBasicBrushBase::m_changeSizeInitialGestureDocPoint
private

Definition at line 70 of file KisToolBasicBrushBase.h.

◆ m_changeSizeInitialGestureGlobalPoint

QPoint KisToolBasicBrushBase::m_changeSizeInitialGestureGlobalPoint
private

Definition at line 73 of file KisToolBasicBrushBase.h.

◆ m_changeSizeLastDocumentPoint

QPointF KisToolBasicBrushBase::m_changeSizeLastDocumentPoint
private

Definition at line 71 of file KisToolBasicBrushBase.h.

◆ m_changeSizeLastPaintOpSize

qreal KisToolBasicBrushBase::m_changeSizeLastPaintOpSize {0.0}
private

Definition at line 72 of file KisToolBasicBrushBase.h.

72{0.0};

◆ m_forceAlwaysFullSizedOutline

bool KisToolBasicBrushBase::m_forceAlwaysFullSizedOutline {true}
private

Definition at line 68 of file KisToolBasicBrushBase.h.

68{true};

◆ m_lastPosition

QPointF KisToolBasicBrushBase::m_lastPosition
private

Definition at line 61 of file KisToolBasicBrushBase.h.

◆ m_lastPressure

qreal KisToolBasicBrushBase::m_lastPressure {1.0}
private

Definition at line 62 of file KisToolBasicBrushBase.h.

62{1.0};

◆ m_outlineStyle

OutlineStyle KisToolBasicBrushBase::m_outlineStyle {OUTLINE_FULL}
private

Definition at line 66 of file KisToolBasicBrushBase.h.

@ OUTLINE_FULL
Definition kis_global.h:56

◆ m_path

QPainterPath KisToolBasicBrushBase::m_path
private

Definition at line 60 of file KisToolBasicBrushBase.h.

◆ m_pressureSamples

QVector<qreal> KisToolBasicBrushBase::m_pressureSamples
private

Definition at line 65 of file KisToolBasicBrushBase.h.

◆ m_previewColor

QColor KisToolBasicBrushBase::m_previewColor
private

Definition at line 75 of file KisToolBasicBrushBase.h.

◆ m_showOutlineWhilePainting

bool KisToolBasicBrushBase::m_showOutlineWhilePainting {true}
private

Definition at line 67 of file KisToolBasicBrushBase.h.

67{true};

◆ m_type

ToolType KisToolBasicBrushBase::m_type {PAINT}
private

Definition at line 63 of file KisToolBasicBrushBase.h.

63{PAINT};

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