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

#include <kis_tool_pencil.h>

+ Inheritance diagram for __KisToolPencilLocalTool:

Public Member Functions

 __KisToolPencilLocalTool (KoCanvasBase *canvas, KisToolPencil *parentTool)
 
void addPathShape (KoPathShape *pathShape, bool closePath) override
 
QList< QPointer< QWidget > > createOptionWidgets () override
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 
virtual void paintPath (KoPathShape *path, QPainter &painter, const KoViewConverter &converter)
 
- Public Member Functions inherited from KoPencilTool
void activate (const QSet< KoShape * > &shapes) override
 
void deactivate () override
 
void keyPressEvent (QKeyEvent *event) override
 
 KoPencilTool (KoCanvasBase *canvas)
 
void mouseMoveEvent (KoPointerEvent *event) override
 
void mousePressEvent (KoPointerEvent *event) override
 
void mouseReleaseEvent (KoPointerEvent *event) override
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 
 ~KoPencilTool () override
 
- 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 deleteSelection ()
 
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 keyReleaseEvent (QKeyEvent *event)
 
 KoToolBase (KoCanvasBase *canvas)
 
bool maskSyntheticEvents () const
 
virtual void mouseDoubleClickEvent (KoPointerEvent *event)
 
virtual void mouseTripleClickEvent (KoPointerEvent *event)
 
QList< QPointer< QWidget > > optionWidgets ()
 
virtual bool paste ()
 
virtual QMenu * popupActionsMenu ()
 
virtual KisPopupWidgetInterfacepopupWidget ()
 
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 Member Functions

void slotUpdatePencilCursor () override
 
- Protected Member Functions inherited from KoPencilTool
QList< QPointer< QWidget > > createOptionWidgets () override
 
KoShapeStrokeSP createStroke ()
 
qreal getFittingError ()
 
KoPathShapepath ()
 
void setFittingError (qreal fittingError)
 
void setStrokeColor (QColor color)
 
- Protected Member Functions inherited from KoToolBase
virtual QWidget * createOptionWidget ()
 
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 Attributes

KisToolPencil *const m_parentTool
 

Additional Inherited Members

- Public Slots inherited from KoToolBase
virtual void canvasResourceChanged (int key, const QVariant &res)
 
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 ()
 
- 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)
 
- Protected Slots inherited from KoPencilTool
- Protected Attributes inherited from KoToolBase
KoToolBasePrivated_ptr
 

Detailed Description

Definition at line 23 of file kis_tool_pencil.h.

Constructor & Destructor Documentation

◆ __KisToolPencilLocalTool()

__KisToolPencilLocalTool::__KisToolPencilLocalTool ( KoCanvasBase * canvas,
KisToolPencil * parentTool )

Definition at line 97 of file kis_tool_pencil.cc.

98 : KoPencilTool(canvas), m_parentTool(parentTool) {
100}
KoPencilTool(KoCanvasBase *canvas)
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
void setIsOpacityPresetMode(bool value)
KisToolPencil *const m_parentTool

References KoToolBase::setIsOpacityPresetMode().

Member Function Documentation

◆ addPathShape()

void __KisToolPencilLocalTool::addPathShape ( KoPathShape * path,
bool closePath )
overridevirtual

Add path shape to document. This method can be overridden and change the behaviour of the tool. In that case the subclass takes ownership of pathShape. It gets only called, if there are two or more points in the path.

Reimplemented from KoPencilTool.

Definition at line 126 of file kis_tool_pencil.cc.

127{
128 if (closePath) {
129 pathShape->close();
130 pathShape->normalize();
131 }
132
133 m_parentTool->addPathShape(pathShape, kundo2_i18n("Draw Freehand Path"));
134}
KUndo2MagicString kundo2_i18n(const char *text)

References KoPathShape::close(), kundo2_i18n(), m_parentTool, and KoPathShape::normalize().

◆ createOptionWidgets()

QList< QPointer< QWidget > > KoPencilTool::createOptionWidgets ( )
overridevirtual

Reimplemented from KoToolBase.

Definition at line 40 of file KoPencilTool.cpp.

282{
283 m_mode = static_cast<PencilMode>(m_configGroup.readEntry<int>("pencilMode", m_mode));
284 m_optimizeRaw = m_configGroup.readEntry<bool>("optimizeRaw", m_optimizeRaw);
285 m_optimizeCurve = m_configGroup.readEntry<bool>("optimizeCurve", m_optimizeCurve);
286 m_combineAngle = m_configGroup.readEntry<qreal>("combineAngle", m_combineAngle);
287 m_fittingError = m_configGroup.readEntry<qreal>("fittingError", m_fittingError);
288
289 QList<QPointer<QWidget> > widgets;
290 QWidget *optionWidget = new QWidget();
291 QVBoxLayout * layout = new QVBoxLayout(optionWidget);
292
293 QHBoxLayout *modeLayout = new QHBoxLayout;
294 modeLayout->setSpacing(3);
295 QLabel *modeLabel = new QLabel(i18n("Precision:"), optionWidget);
296 QComboBox * modeBox = new QComboBox(optionWidget);
297 modeBox->addItem(i18nc("The raw line data", "Raw"));
298 modeBox->addItem(i18n("Curve"));
299 modeBox->addItem(i18n("Straight"));
300 modeLayout->addWidget(modeLabel);
301 modeLayout->addWidget(modeBox, 1);
302 layout->addLayout(modeLayout);
303
304 QStackedWidget * stackedWidget = new QStackedWidget(optionWidget);
305
306 QWidget * rawBox = new QWidget(stackedWidget);
307 QVBoxLayout * rawLayout = new QVBoxLayout(rawBox);
308 QCheckBox * optimizeRaw = new QCheckBox(i18n("Optimize"), rawBox);
309 optimizeRaw->setChecked(m_optimizeRaw);
310 rawLayout->addWidget(optimizeRaw);
311 rawLayout->setContentsMargins(0, 0, 0, 0);
312
313 QWidget * curveBox = new QWidget(stackedWidget);
314 QHBoxLayout * curveLayout = new QHBoxLayout(curveBox);
315 QCheckBox * optimizeCurve = new QCheckBox(i18n("Optimize"), curveBox);
316 optimizeCurve->setChecked(m_optimizeCurve);
317 QDoubleSpinBox * fittingError = new KisDoubleParseSpinBox(curveBox);
318 fittingError->setSingleStep(0.50);
319 fittingError->setMaximum(400.0);
320 fittingError->setMinimum(0.0);
321 fittingError->setValue(m_fittingError);
322 fittingError->setToolTip(i18n("Exactness:"));
323 curveLayout->addWidget(optimizeCurve);
324 curveLayout->addWidget(fittingError);
325 curveLayout->setContentsMargins(0, 0, 0, 0);
326
327 QWidget *straightBox = new QWidget(stackedWidget);
328 QVBoxLayout *straightLayout = new QVBoxLayout(straightBox);
329 QDoubleSpinBox *combineAngle = new KisDoubleParseSpinBox(straightBox);
330 combineAngle->setSingleStep(0.50);
331 combineAngle->setMaximum(360.0);
332 combineAngle->setMinimum(0.0);
333 combineAngle->setValue(m_combineAngle);
334 combineAngle->setSuffix(" deg");
335 // QT5TODO
336 //combineAngle->setLabel(i18n("Combine angle:"), Qt::AlignLeft | Qt::AlignVCenter);
337 straightLayout->addWidget(combineAngle);
338 straightLayout->setContentsMargins(0, 0, 0, 0);
339
340 stackedWidget->addWidget(rawBox);
341 stackedWidget->addWidget(curveBox);
342 stackedWidget->addWidget(straightBox);
343 layout->addWidget(stackedWidget);
344 layout->addStretch(1);
345
346 connect(modeBox, SIGNAL(activated(int)), stackedWidget, SLOT(setCurrentIndex(int)));
347 connect(modeBox, SIGNAL(activated(int)), this, SLOT(selectMode(int)));
348 connect(optimizeRaw, SIGNAL(stateChanged(int)), this, SLOT(setOptimize(int)));
349 connect(optimizeCurve, SIGNAL(stateChanged(int)), this, SLOT(setOptimize(int)));
350 connect(fittingError, SIGNAL(valueChanged(double)), this, SLOT(setDelta(double)));
351 connect(combineAngle, SIGNAL(valueChanged(double)), this, SLOT(setDelta(double)));
352
353 modeBox->setCurrentIndex(m_mode);
354 stackedWidget->setCurrentIndex(m_mode);
355 optionWidget->setObjectName(i18n("Pencil"));
356 optionWidget->setWindowTitle(i18n("Pencil"));
357 widgets.append(optionWidget);
358
361 m_strokeWidget->setWindowTitle(i18n("Line"));
362 connect(m_strokeWidget, SIGNAL(sigStrokeChanged()), SLOT(slotUpdatePencilCursor()));
363 if (isActivated()) {
365 }
366 widgets.append(m_strokeWidget);
367 return widgets;
368}
The KisDoubleParseSpinBox class is a cleverer doubleSpinBox, able to parse arithmetic expressions.
void setDelta(double delta)
void selectMode(int mode)
qreal m_fittingError
KoStrokeConfigWidget * m_strokeWidget
PencilMode m_mode
KConfigGroup m_configGroup
bool m_optimizeCurve
void setOptimize(int state)
qreal m_combineAngle
A widget for configuring the stroke of a shape.
void setNoSelectionTrackingMode(bool value)
bool isActivated() const
void slotUpdatePencilCursor() override

◆ paint()

void __KisToolPencilLocalTool::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 102 of file kis_tool_pencil.cc.

103{
104 if (m_parentTool->strokeStyle() == KisToolShapeUtils::StrokeStyleNone) {
105 paintPath(path(), painter, converter);
106 } else {
107 KoPencilTool::paint(painter, converter);
108 }
109}
KoPathShape * path()
void paint(QPainter &painter, const KoViewConverter &converter) override
virtual void paintPath(KoPathShape *path, QPainter &painter, const KoViewConverter &converter)

References m_parentTool, KoPencilTool::paint(), paintPath(), KoPencilTool::path(), and KisToolShapeUtils::StrokeStyleNone.

◆ paintPath()

void __KisToolPencilLocalTool::paintPath ( KoPathShape * path,
QPainter & painter,
const KoViewConverter & converter )
virtual

Definition at line 113 of file kis_tool_pencil.cc.

114{
115 Q_UNUSED(converter);
116 if (!pathShape) {
117 return;
118 }
119
120 QTransform matrix;
121 matrix.scale(m_parentTool->image()->xRes(), m_parentTool->image()->yRes());
122 matrix.translate(pathShape->position().x(), pathShape->position().y());
123 m_parentTool->paintToolOutline(&painter, m_parentTool->pixelToView(matrix.map(pathShape->outline())));
124}

References m_parentTool, KoPathShape::outline(), and KoShape::position().

◆ slotUpdatePencilCursor()

void __KisToolPencilLocalTool::slotUpdatePencilCursor ( )
overrideprotectedvirtual

Reimplemented from KoPencilTool.

Definition at line 136 of file kis_tool_pencil.cc.

137{
138 KoShapeStrokeSP stroke = this->createStroke();
139 m_parentTool->updatePencilCursor(stroke && stroke->isVisible());
140
141 auto style = m_parentTool->strokeStyle();
143 {
144 KoPencilTool::setStrokeColor(canvas()->resourceManager()->foregroundColor().toQColor());
145 }
147 {
148 KoPencilTool::setStrokeColor(canvas()->resourceManager()->backgroundColor().toQColor());
149 }
150}
void updatePencilCursor(bool value)
void setStrokeColor(QColor color)
KoShapeStrokeSP createStroke()

References KoToolBase::canvas(), KoPencilTool::createStroke(), m_parentTool, KoPencilTool::setStrokeColor(), KisToolShapeUtils::StrokeStyleBackground, KisToolShapeUtils::StrokeStyleForeground, and KisToolPencil::updatePencilCursor().

Member Data Documentation

◆ m_parentTool

KisToolPencil* const __KisToolPencilLocalTool::m_parentTool
private

Definition at line 36 of file kis_tool_pencil.h.


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