File indexing completed on 2024-06-16 04:17:45

0001 /*
0002  *  SPDX-FileCopyrightText: 2012 Sven Langkamp <sven.langkamp@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KIS_TOOL_PENCIL_H_
0008 #define KIS_TOOL_PENCIL_H_
0009 
0010 #include <KoPencilTool.h>
0011 #include <KoToolFactoryBase.h>
0012 
0013 #include "flake/kis_node_shape.h"
0014 #include "kis_tool_shape.h"
0015 #include "kis_delegated_tool.h"
0016 #include <kis_icon.h>
0017 
0018 class KoCanvasBase;
0019 class KisToolPencil;
0020 
0021 ///
0022 
0023 class __KisToolPencilLocalTool : public KoPencilTool {
0024 public:
0025     __KisToolPencilLocalTool(KoCanvasBase * canvas, KisToolPencil* parentTool);
0026     void paint(QPainter &painter, const KoViewConverter &converter) override;
0027     virtual void paintPath(KoPathShape * path, QPainter &painter, const KoViewConverter &converter);
0028     void addPathShape(KoPathShape* pathShape, bool closePath) override;
0029 
0030     using KoPencilTool::createOptionWidgets;
0031 
0032 protected:
0033     void slotUpdatePencilCursor() override;
0034 
0035 private:
0036     KisToolPencil* const m_parentTool;
0037 };
0038 
0039 typedef KisDelegatedTool<KisToolShape,
0040 __KisToolPencilLocalTool,
0041 DeselectShapesActivationPolicy> DelegatedPencilTool;
0042 
0043 class KisToolPencil : public DelegatedPencilTool
0044 {
0045     Q_OBJECT
0046 
0047 public:
0048     KisToolPencil(KoCanvasBase * canvas);
0049     void mousePressEvent(KoPointerEvent *event) override;
0050     // reimplementing KoToolBase's method. It ignores the event, and then
0051     // Qt does not send mouseRelease event, which causes the tool to jump.
0052     void mouseDoubleClickEvent(KoPointerEvent *event) override;
0053 
0054     void beginPrimaryAction(KoPointerEvent* event) override;
0055     void continuePrimaryAction(KoPointerEvent *event) override;
0056     void endPrimaryAction(KoPointerEvent *event) override;
0057 
0058     QList<QPointer<QWidget> > createOptionWidgets() override;
0059 
0060 protected Q_SLOTS:
0061     void resetCursorStyle() override;
0062 
0063 private:
0064     void updatePencilCursor(bool value);
0065 
0066 private:
0067     friend class __KisToolPencilLocalTool;
0068 };
0069 
0070 class KisToolPencilFactory : public KoToolFactoryBase
0071 {
0072 
0073 public:
0074     KisToolPencilFactory()
0075         : KoToolFactoryBase("KisToolPencil") {
0076         setToolTip(i18n("Freehand Path Tool"));
0077         setSection(ToolBoxSection::Shape);
0078         setActivationShapeId(KRITA_TOOL_ACTIVATION_ID);
0079         setIconName(koIconNameCStr("krita_tool_freehandvector"));
0080         setPriority(9);
0081     }
0082 
0083     ~KisToolPencilFactory() override {}
0084 
0085     KoToolBase * createTool(KoCanvasBase *canvas) override {
0086         return new KisToolPencil(canvas);
0087     }
0088 };
0089 
0090 
0091 
0092 #endif // KIS_TOOL_PENCIL_H_
0093