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

#include <kis_tool_select_path.h>

+ Inheritance diagram for __KisToolSelectPathLocalTool:

Public Member Functions

 __KisToolSelectPathLocalTool (KoCanvasBase *canvas, KisToolSelectPath *parentTool)
 
void addPathShape (KoPathShape *pathShape) override
 
void cancelPath ()
 
QList< QPointer< QWidget > > createOptionWidgets () override
 reimplemented
 
void endPath ()
 
void endPathWithoutLastPoint ()
 
void paintPath (KoPathShape &path, QPainter &painter, const KoViewConverter &converter) override
 
void removeLastPoint ()
 
- Public Member Functions inherited from KoCreatePathTool
QRectF decorationsRect () const override
 
 KoCreatePathTool (KoCanvasBase *canvas)
 
void mouseDoubleClickEvent (KoPointerEvent *event) override
 reimplemented
 
void mouseMoveEvent (KoPointerEvent *event) override
 reimplemented
 
void mousePressEvent (KoPointerEvent *event) override
 reimplemented
 
void mouseReleaseEvent (KoPointerEvent *event) override
 reimplemented
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 reimplemented
 
bool pathStarted () const
 
void setEnableClosePathShortcut (bool value)
 
bool tryMergeInPathShape (KoPathShape *pathShape)
 
 ~KoCreatePathTool () 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 ()
 
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 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
 
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
 

Private Member Functions

void beginShape () override
 
void endShape () override
 

Private Attributes

KisToolSelectPath *const m_selectionTool
 

Additional Inherited Members

- Public Slots inherited from KoCreatePathTool
void activate (const QSet< KoShape * > &shapes) override
 reimplemented
 
void canvasResourceChanged (int key, const QVariant &res) override
 reimplemented
 
void deactivate () override
 reimplemented
 
- Public Slots inherited from KoToolBase
virtual void activate (const QSet< KoShape * > &shapes)
 
virtual void canvasResourceChanged (int key, const QVariant &res)
 
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 ()
 
- Signals inherited from KoCreatePathTool
void sigUpdateAutoSmoothCurvesGUI (bool value)
 
- 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 Member Functions inherited from KoCreatePathTool
bool addPathShapeImpl (KoPathShape *pathShape, bool tryMergeOnly)
 
void cancelPath ()
 
QList< QPointer< QWidget > > createOptionWidgets () override
 reimplemented
 
void endPath ()
 
void endPathWithoutLastPoint ()
 
void handleMouseMove (const KoPointerEvent *event, bool considerDrag)
 
void removeLastPoint ()
 
- 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)
 
- Protected Attributes inherited from KoToolBase
KoToolBasePrivated_ptr
 

Detailed Description

Definition at line 22 of file kis_tool_select_path.h.

Constructor & Destructor Documentation

◆ __KisToolSelectPathLocalTool()

__KisToolSelectPathLocalTool::__KisToolSelectPathLocalTool ( KoCanvasBase * canvas,
KisToolSelectPath * parentTool )

Definition at line 127 of file kis_tool_select_path.cc.

129{
131}
KoCreatePathTool(KoCanvasBase *canvas)
void setEnableClosePathShortcut(bool value)
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
KisToolSelectPath *const m_selectionTool

References KoCreatePathTool::setEnableClosePathShortcut().

Member Function Documentation

◆ addPathShape()

void __KisToolSelectPathLocalTool::addPathShape ( KoPathShape * pathShape)
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 KoCreatePathTool.

Definition at line 146 of file kis_tool_select_path.cc.

147{
148 pathShape->normalize();
149 pathShape->close();
150
151 KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
152 if (!kisCanvas)
153 return;
154
155 KisImageWSP image = kisCanvas->image();
156
157 KisSelectionToolHelper helper(kisCanvas, kundo2_i18n("Select by Bezier Curve"));
158
159 const SelectionMode mode =
160 helper.tryOverrideSelectionMode(kisCanvas->viewManager()->selection(),
163
164 if (mode == PIXEL_SELECTION) {
165 KisProcessingApplicator applicator(
166 m_selectionTool->currentImage(),
167 m_selectionTool->currentNode(),
170 kundo2_i18n("Select by Bezier Curve"));
171
173 new KisDefaultBounds(m_selectionTool->currentImage()));
174
175 const bool antiAlias = m_selectionTool->antiAliasSelection();
176 const int grow = m_selectionTool->growSelection();
177 const int feather = m_selectionTool->featherSelection();
178
179 QTransform matrix;
180 matrix.scale(image->xRes(), image->yRes());
181 matrix.translate(pathShape->position().x(), pathShape->position().y());
182
183 QPainterPath path = matrix.map(pathShape->outline());
184
186 [tmpSel, antiAlias, grow, feather, path]() mutable
187 -> KUndo2Command * {
188 KisPainter painter(tmpSel);
189 painter.setPaintColor(KoColor(Qt::black, tmpSel->colorSpace()));
190 // Since the feathering already smooths the selection, the
191 // antiAlias is not applied if we must feather
192 painter.setAntiAliasPolygonFill(antiAlias && feather == 0);
193 painter.setFillStyle(KisPainter::FillStyleForegroundColor);
194 painter.setStrokeStyle(KisPainter::StrokeStyleNone);
195
196 painter.fillPainterPath(path);
197
198 if (grow > 0) {
199 KisGrowSelectionFilter biggy(grow, grow);
200 biggy.process(tmpSel,
201 tmpSel->selectedRect().adjusted(-grow,
202 -grow,
203 grow,
204 grow));
205 } else if (grow < 0) {
206 KisShrinkSelectionFilter tiny(-grow, -grow, false);
207 tiny.process(tmpSel, tmpSel->selectedRect());
208 }
209 if (feather > 0) {
210 KisFeatherSelectionFilter feathery(feather);
211 feathery.process(tmpSel,
212 tmpSel->selectedRect().adjusted(-feather,
213 -feather,
214 feather,
215 feather));
216 }
217
218 if (grow == 0 && feather == 0) {
219 tmpSel->setOutlineCache(path);
220 } else {
221 tmpSel->invalidateOutlineCache();
222 }
223
224 return 0;
225 });
226
227 applicator.applyCommand(cmd, KisStrokeJobData::SEQUENTIAL);
228 helper.selectPixelSelection(applicator,
229 tmpSel,
231 applicator.end();
232
233 delete pathShape;
234
235 } else {
236 helper.addSelectionShape(pathShape, m_selectionTool->selectionAction());
237 }
238}
SelectionMode
@ PIXEL_SELECTION
KisImageWSP image() const
KisViewManager * viewManager() const
double xRes() const
double yRes() const
const KoColorSpace * colorSpace() const
@ FillStyleForegroundColor
SelectionAction selectionAction() const
SelectionMode selectionMode() const
bool antiAliasSelection() const
KisSelectionSP selection()
virtual QPointF normalize()
Normalizes the path data.
void close()
Closes the current subpath.
QPainterPath outline() const override
reimplemented
QPointF position() const
Get the position of the shape in pt.
Definition KoShape.cpp:825
KUndo2MagicString kundo2_i18n(const char *text)
The LambdaCommand struct is a shorthand for creation of AggregateCommand commands using C++ lambda fe...
void setOutlineCache(const QPainterPath &cache)

References KisSelectionToolHelper::addSelectionShape(), KisToolSelectBase< BaseClass >::antiAliasSelection(), KisProcessingApplicator::applyCommand(), KoToolBase::canvas(), KoPathShape::close(), KisPaintDevice::colorSpace(), KisProcessingApplicator::end(), KisToolSelectBase< BaseClass >::featherSelection(), KisPainter::fillPainterPath(), KisPainter::FillStyleForegroundColor, KisToolSelectBase< BaseClass >::growSelection(), KisCanvas2::image(), KisPixelSelection::invalidateOutlineCache(), kundo2_i18n(), m_selectionTool, KisProcessingApplicator::NONE, KoPathShape::normalize(), KoPathShape::outline(), PIXEL_SELECTION, KoShape::position(), KisFeatherSelectionFilter::process(), KisGrowSelectionFilter::process(), KisShrinkSelectionFilter::process(), KisPixelSelection::selectedRect(), KisViewManager::selection(), KisToolSelectBase< BaseClass >::selectionAction(), KisToolSelectBase< BaseClass >::selectionMode(), KisSelectionToolHelper::selectPixelSelection(), KisStrokeJobData::SEQUENTIAL, KisPainter::setAntiAliasPolygonFill(), KisPainter::setFillStyle(), KisPixelSelection::setOutlineCache(), KisPainter::setPaintColor(), KisPainter::setStrokeStyle(), KisPainter::StrokeStyleNone, KisSelectionToolHelper::tryOverrideSelectionMode(), KisCanvas2::viewManager(), KisImage::xRes(), and KisImage::yRes().

◆ beginShape()

void __KisToolSelectPathLocalTool::beginShape ( )
overrideprivatevirtual

Use these methods in subclassed to notify when the user starts and finishes making a shape, and override to be notified

Reimplemented from KoCreatePathTool.

Definition at line 240 of file kis_tool_select_path.cc.

241{
242 KisToolSelectPath* selectPathTool = dynamic_cast<KisToolSelectPath*>(m_selectionTool);
243 KIS_ASSERT(selectPathTool);
244 selectPathTool->beginSelectInteraction();
245}
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References KisToolSelectBase< BaseClass >::beginSelectInteraction(), KIS_ASSERT, and m_selectionTool.

◆ cancelPath()

void KoCreatePathTool::cancelPath ( )

Definition at line 97 of file KoCreatePathTool.cpp.

421{
422 Q_D(KoCreatePathTool);
423
424 if (!d->shape) {
425 return;
426 }
427 d->firstPoint = 0;
428 d->activePoint = 0;
429 d->cleanUp();
431 endShape();
432}
virtual void repaintDecorations()

◆ createOptionWidgets()

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

reimplemented

Reimplemented from KoToolBase.

Definition at line 103 of file KoCreatePathTool.cpp.

556{
557 Q_D(KoCreatePathTool);
558
560
561 QWidget *widget = new QWidget();
562 widget->setObjectName("bezier-curve-tool-widget");
563 widget->setWindowTitle(i18n("Path options"));
564
565 QCheckBox *smoothCurves = new QCheckBox(i18n("Autosmooth curve"), widget);
566 smoothCurves->setObjectName("smooth-curves-widget");
567 smoothCurves->setChecked(d->autoSmoothCurves);
568
569 QCheckBox *angleSnap = new QCheckBox(i18n("Activate angle snap"), widget);
570 angleSnap->setObjectName("angle-snap-widget");
571 angleSnap->setChecked(false);
572 angleSnap->setCheckable(true);
573
574 KisAngleSelector *angleEdit = new KisAngleSelector(widget);
575 angleEdit->setObjectName("angle-edit-widget");
576 angleEdit->setAngle(d->angleSnappingDelta);
577 angleEdit->setRange(1, 360);
578 angleEdit->setDecimals(0);
580 angleEdit->setEnabled(angleSnap->isChecked());
581
582 QHBoxLayout *angleEditLayout = new QHBoxLayout;
583 angleEditLayout->setContentsMargins(10, 0, 0, 0);
584 angleEditLayout->setSpacing(0);
585 angleEditLayout->addWidget(angleEdit);
586
587 QVBoxLayout *mainLayout = new QVBoxLayout;
588 mainLayout->setContentsMargins(0, 0, 0, 0);
589 mainLayout->setSpacing(5);
590
591 mainLayout->addWidget(smoothCurves);
592 mainLayout->addWidget(angleSnap);
593 mainLayout->addLayout(angleEditLayout);
594
595 widget->setLayout(mainLayout);
596
597 list.append(widget);
598
599 connect(smoothCurves,
600 SIGNAL(toggled(bool)),
601 this,
602 SLOT(autoSmoothCurvesChanged(bool)));
603 connect(this,
604 SIGNAL(sigUpdateAutoSmoothCurvesGUI(bool)),
605 smoothCurves,
606 SLOT(setChecked(bool)));
607 connect(angleEdit, SIGNAL(angleChanged(qreal)), this, SLOT(angleDeltaChanged(qreal)));
608 connect(angleSnap, SIGNAL(stateChanged(int)), this, SLOT(angleSnapChanged(int)));
609 connect(angleSnap,
610 SIGNAL(toggled(bool)),
611 angleEdit,
612 SLOT(setEnabled(bool)));
613
614 return list;
615}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
A widget with several options to select an angle.
@ FlipOptionsMode_MenuButton
The flip options are shown as a menu accessible via a options button.
void setFlipOptionsMode(FlipOptionsMode newMode)
Sets the mode in which the flip options should be shown.
void setAngle(qreal newAngle)
Sets the current angle.
void setRange(qreal newMinimum, qreal newMaximum)
Sets the minimum and maximum values for the angle.
void setDecimals(int newNumberOfDecimals)
Sets the number of decimals (precision) used by the angle.
void sigUpdateAutoSmoothCurvesGUI(bool value)
void angleSnapChanged(int)) Q_PRIVATE_SLOT(d_func()

◆ endPath()

void KoCreatePathTool::endPath ( )

Definition at line 95 of file KoCreatePathTool.cpp.

395{
396 Q_D(KoCreatePathTool);
397
398 if (!d->shape) {
399 return;
400 }
401 d->addPathShape();
403 endShape();
404}

◆ endPathWithoutLastPoint()

void KoCreatePathTool::endPathWithoutLastPoint ( )

Definition at line 96 of file KoCreatePathTool.cpp.

407{
408 Q_D(KoCreatePathTool);
409
410 if (!d->shape) {
411 return;
412 }
413 delete d->shape->removePoint(d->shape->pathPointIndex(d->activePoint));
414 d->addPathShape();
415
417 endShape();
418}

◆ endShape()

void __KisToolSelectPathLocalTool::endShape ( )
overrideprivatevirtual

Reimplemented from KoCreatePathTool.

Definition at line 247 of file kis_tool_select_path.cc.

248{
249 KisToolSelectPath* selectPathTool = dynamic_cast<KisToolSelectPath*>(m_selectionTool);
250 KIS_ASSERT(selectPathTool);
251 selectPathTool->endSelectInteraction();
252}

References KisToolSelectBase< BaseClass >::endSelectInteraction(), KIS_ASSERT, and m_selectionTool.

◆ paintPath()

void __KisToolSelectPathLocalTool::paintPath ( KoPathShape & pathShape,
QPainter & painter,
const KoViewConverter & converter )
overridevirtual

This method is called to paint the path. Decorations are drawn by KoCreatePathTool afterwards.

Reimplemented from KoCreatePathTool.

Definition at line 133 of file kis_tool_select_path.cc.

134{
135 Q_UNUSED(converter);
136 KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
137 if (!kisCanvas)
138 return;
139
140 QTransform matrix;
141 matrix.scale(kisCanvas->image()->xRes(), kisCanvas->image()->yRes());
142 matrix.translate(pathShape.position().x(), pathShape.position().y());
143 m_selectionTool->paintToolOutline(&painter, m_selectionTool->pixelToView(matrix.map(pathShape.outline())));
144}

References KoToolBase::canvas(), KisCanvas2::image(), m_selectionTool, KoPathShape::outline(), KoShape::position(), KisImage::xRes(), and KisImage::yRes().

◆ removeLastPoint()

void KoCreatePathTool::removeLastPoint ( )

Definition at line 98 of file KoCreatePathTool.cpp.

435{
436 Q_D(KoCreatePathTool);
437
438 if ((d->shape)) {
439 KoPathPointIndex lastPointIndex = d->shape->pathPointIndex(d->activePoint);
440
441 if (lastPointIndex.second > 1) {
442 lastPointIndex.second--;
443 delete d->shape->removePoint(lastPointIndex);
444
445 d->hoveredPoint = 0;
446
448 }
449 }
450}
QPair< int, int > KoPathPointIndex
Definition KoPathShape.h:28

Member Data Documentation

◆ m_selectionTool

KisToolSelectPath* const __KisToolSelectPathLocalTool::m_selectionTool
private

Definition at line 35 of file kis_tool_select_path.h.


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