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

#include <KisToolKnife.h>

+ Inheritance diagram for KisToolKnife:

Classes

struct  Private
 

Public Slots

void activate (const QSet< KoShape * > &shapes) override
 
KoInteractionStrategycreateStrategy (KoPointerEvent *event) override
 
void deactivate () override
 
bool isValidForCurrentLayer () const
 
void mouseMoveEvent (KoPointerEvent *event) override
 
void mousePressEvent (KoPointerEvent *event)
 
void mouseReleaseEvent (KoPointerEvent *event) override
 
- 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 ()
 

Public Member Functions

QWidget * createOptionWidget () override
 
 KisToolKnife (KoCanvasBase *canvas)
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 
 ~KisToolKnife () override
 
- Public Member Functions inherited from KoInteractionTool
void keyPressEvent (QKeyEvent *event) override
 
void keyReleaseEvent (QKeyEvent *event) override
 
 KoInteractionTool (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
 
 ~KoInteractionTool () 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 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
 
 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
 

Private Attributes

const QScopedPointer< Privatem_d
 

Additional Inherited Members

- 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 KoInteractionTool
void addInteractionFactory (KoInteractionStrategyFactory *factory)
 
void cancelCurrentStrategy ()
 Cancels the current strategy and deletes it.
 
virtual KoInteractionStrategycreateStrategy (KoPointerEvent *event)=0
 
KoInteractionStrategycreateStrategyBase (KoPointerEvent *event)
 
KoInteractionStrategycurrentStrategy ()
 
bool hasInteractionFactory (const QString &id)
 
 KoInteractionTool (KoInteractionToolPrivate &dd)
 
void removeInteractionFactory (const QString &id)
 
bool tryUseCustomCursor ()
 
- 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 KoToolBase
KoToolBasePrivated_ptr
 

Detailed Description

Definition at line 32 of file KisToolKnife.h.

Constructor & Destructor Documentation

◆ KisToolKnife()

KisToolKnife::KisToolKnife ( KoCanvasBase * canvas)

Definition at line 57 of file KisToolKnife.cpp.

59 m_d(new Private)
60{
61 setObjectName("tool_knife");
62 useCursor(Qt::ArrowCursor);
64}
const QScopedPointer< Private > m_d
KoInteractionTool(KoCanvasBase *canvas)
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
virtual void repaintDecorations()
void useCursor(const QCursor &cursor)

References KoToolBase::repaintDecorations(), and KoToolBase::useCursor().

◆ ~KisToolKnife()

KisToolKnife::~KisToolKnife ( )
override

Definition at line 66 of file KisToolKnife.cpp.

67{
68 m_d->optionsWidget = nullptr;
69}

References m_d.

Member Function Documentation

◆ activate

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

Definition at line 187 of file KisToolKnife.cpp.

188{
191
192}
static QCursor arrowCursor()
Definition kis_cursor.cc:24
virtual void activate(const QSet< KoShape * > &shapes)

References KoToolBase::activate(), KisCursor::arrowCursor(), and KoToolBase::useCursor().

◆ createOptionWidget()

QWidget * KisToolKnife::createOptionWidget ( )
overridevirtual

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

Reimplemented from KoToolBase.

Definition at line 272 of file KisToolKnife.cpp.

273{
274 KisCanvas2 * kiscanvas = dynamic_cast<KisCanvas2*>(canvas());
275 KIS_ASSERT(kiscanvas);
276 qreal resolution = 1.0;
277 if (kiscanvas->image()) {
278 // we're going to assume isotropic image
279 resolution = kiscanvas->image()->xRes();
280 }
281
282 m_d->optionsWidget = new KisToolKnifeOptionsWidget(kiscanvas->viewManager()->canvasResourceProvider(), 0, toolId(), resolution);
283 m_d->optionsWidget->setObjectName(toolId() + "option widget");
284
285
286 return m_d->optionsWidget;
287}
KisImageWSP image() const
KisViewManager * viewManager() const
double xRes() const
KisCanvasResourceProvider * canvasResourceProvider()
Q_INVOKABLE QString toolId() const
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

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

◆ createStrategy

KoInteractionStrategy * KisToolKnife::createStrategy ( KoPointerEvent * event)
overrideslot

Definition at line 251 of file KisToolKnife.cpp.

252{
253 QList<KoShape*> shapes = canvas()->shapeManager()->shapes();
254
255 if (m_d->optionsWidget->getToolMode() == KisToolKnifeOptionsWidget::ToolMode::AddGutter) {
256 return new CutThroughShapeStrategy(this, canvas()->selectedShapesProxy()->selection(), shapes, event->point, m_d->optionsWidget->getCurrentWidthsConfig());
257 } else {
258 return new RemoveGutterStrategy(this, canvas()->selectedShapesProxy()->selection(), shapes, event->point);
259 }
260
261 //return NULL;
262}
virtual KoShapeManager * shapeManager() const =0
QPointF point
The point in document coordinates.
QList< KoShape * > shapes
virtual KoToolSelection * selection()

References KisToolKnifeOptionsWidget::AddGutter, KoToolBase::canvas(), m_d, KoPointerEvent::point, KoToolBase::selection(), KoCanvasBase::shapeManager(), and KoShapeManager::shapes.

◆ deactivate

void KisToolKnife::deactivate ( )
overrideslot

Definition at line 194 of file KisToolKnife.cpp.

195{
197}
virtual void deactivate()

References KoToolBase::deactivate().

◆ isValidForCurrentLayer

bool KisToolKnife::isValidForCurrentLayer ( ) const
slot

Definition at line 264 of file KisToolKnife.cpp.

265{
266 KisCanvas2 *kisCanvas = static_cast<KisCanvas2 *>(canvas());
268 const KisShapeLayer *shapeLayer = qobject_cast<const KisShapeLayer*>(node.data());
269 return (shapeLayer != nullptr);
270}

References KoToolBase::canvas(), KisViewManager::canvasResourceProvider(), KisCanvasResourceProvider::currentNode(), KisSharedPtr< T >::data(), and KisCanvas2::viewManager().

◆ mouseMoveEvent

void KisToolKnife::mouseMoveEvent ( KoPointerEvent * event)
overrideslot

Definition at line 213 of file KisToolKnife.cpp.

214{
216
217 if (event->buttons().testFlag(Qt::MouseButton::LeftButton)) {
218
219 m_d->endPoint = event->point;
220 QRectF dirtyRect;
221 KisAlgebra2D::accumulateBounds(m_d->startPoint, &dirtyRect);
222 KisAlgebra2D::accumulateBounds(m_d->endPoint, &dirtyRect);
223
224 QRectF accumulatedWithPrevious = m_d->previousLineDirtyRect;
225 accumulatedWithPrevious |= dirtyRect;
226
227 canvas()->updateCanvas(accumulatedWithPrevious);
228 m_d->previousLineDirtyRect = dirtyRect;
229
230 }
231
233}
virtual void updateCanvas(const QRectF &rc)=0
void mouseMoveEvent(KoPointerEvent *event) override
Qt::MouseButtons buttons() const
return buttons pressed (see QMouseEvent::buttons());
void accumulateBounds(const Point &pt, Rect *bounds)

References KisAlgebra2D::accumulateBounds(), KoPointerEvent::buttons(), KoToolBase::canvas(), m_d, KoInteractionTool::mouseMoveEvent(), KoToolBase::repaintDecorations(), and KoCanvasBase::updateCanvas().

◆ mousePressEvent

void KisToolKnife::mousePressEvent ( KoPointerEvent * event)
slot

Definition at line 199 of file KisToolKnife.cpp.

200{
201 // this tool only works on a vector layer right now, so give a warning if another layer type is trying to use it
202 if (!isValidForCurrentLayer()) {
203 KisCanvas2 *kiscanvas = static_cast<KisCanvas2 *>(canvas());
204 kiscanvas->viewManager()->showFloatingMessage(
205 i18n("This tool only works on vector layers. You probably want to create a vector layer and a starting shape first."),
206 QIcon(), 2000, KisFloatingMessage::Medium, Qt::AlignCenter);
207 return;
208 }
209
211}
bool isValidForCurrentLayer() const
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
void mousePressEvent(KoPointerEvent *event) override

References KoToolBase::canvas(), isValidForCurrentLayer(), KisFloatingMessage::Medium, KoInteractionTool::mousePressEvent(), KisViewManager::showFloatingMessage(), and KisCanvas2::viewManager().

◆ mouseReleaseEvent

void KisToolKnife::mouseReleaseEvent ( KoPointerEvent * event)
overrideslot

Definition at line 235 of file KisToolKnife.cpp.

236{
238
239 m_d->endPoint = event->point;
240
241 QRectF dirtyRect;
242 KisAlgebra2D::accumulateBounds(m_d->startPoint, &dirtyRect);
243 KisAlgebra2D::accumulateBounds(m_d->endPoint, &dirtyRect);
244
245 QRectF accumulatedWithPrevious = m_d->previousLineDirtyRect | dirtyRect;
246
247 canvas()->updateCanvas(accumulatedWithPrevious);
248 m_d->previousLineDirtyRect = dirtyRect;
249}
void mouseReleaseEvent(KoPointerEvent *event) override

References KisAlgebra2D::accumulateBounds(), KoToolBase::canvas(), m_d, KoInteractionTool::mouseReleaseEvent(), and KoCanvasBase::updateCanvas().

◆ paint()

void KisToolKnife::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 139 of file KisToolKnife.cpp.

140{
141 Q_UNUSED(converter);
142
143 painter.save();
144 painter.restore();
145
146 painter.save();
147 painter.setBrush(Qt::darkGray);
148 //painter.drawEllipse(converter.documentToView(m_d->mousePoint), 4, 4);
149
150 painter.restore();
151
152 KoInteractionTool::paint(painter, converter);
153
154
155#ifdef KNIFE_DEBUG
156 bool paintSelection = true;
157 if (paintSelection) {
158
160 KIS_SAFE_ASSERT_RECOVER_RETURN(canvas()->selectedShapesProxy());
161
162 KIS_SAFE_ASSERT_RECOVER_RETURN(canvas()->selectedShapesProxy()->selection());
163
165
166 QList<KoShape*> shapes = selection->selectedEditableShapes();
167
168 Q_FOREACH(KoShape* shape, shapes) {
170 painter.save();
171 painter.setTransform(painter.transform());
172 for (int i = 0; i < vector.segmentsCount(); i++) {
173 paintSelectedEdge(painter, converter, shape->absoluteTransformation().map(vector.segmentAtAsLine(i)));
174 }
175 for (int i = 0; i < vector.pointsCount(); i++) {
176 paintSelectedPoint(painter, converter, shape->absoluteTransformation().map(vector.pointAt(i).endPoint));
177 }
178 painter.restore();
179
180 }
181 }
182#endif
183
184
185}
void paintSelectedEdge(QPainter &painter, const KoViewConverter &converter, const QLineF &lineSegment)
void paintSelectedPoint(QPainter &painter, const KoViewConverter &converter, const QPointF &point)
VectorPathPoint pointAt(int i) const
QLineF segmentAtAsLine(int i) const
virtual KoSelectedShapesProxy * selectedShapesProxy() const =0
selectedShapesProxy() is a special interface for keeping a persistent connections to selectionChanged...
void paint(QPainter &painter, const KoViewConverter &converter) override
virtual KoSelection * selection()=0
virtual QPainterPath outline() const
Definition KoShape.cpp:559
QTransform absoluteTransformation() const
Definition KoShape.cpp:335
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KoShape::absoluteTransformation(), KoToolBase::canvas(), KisAlgebra2D::VectorPath::VectorPathPoint::endPoint, KIS_SAFE_ASSERT_RECOVER_RETURN, KoShape::outline(), KoInteractionTool::paint(), paintSelectedEdge(), paintSelectedPoint(), KisAlgebra2D::VectorPath::pointAt(), KisAlgebra2D::VectorPath::pointsCount(), KisAlgebra2D::VectorPath::segmentAtAsLine(), KisAlgebra2D::VectorPath::segmentsCount(), KoCanvasBase::selectedShapesProxy(), KoToolBase::selection(), and KoSelectedShapesProxy::selection().

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisToolKnife::m_d
private

Definition at line 59 of file KisToolKnife.h.


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