File indexing completed on 2024-12-22 04:13:02

0001 /*
0002  *  SPDX-FileCopyrightText: 2005 Adrian Page <adrian@pagenet.plus.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KIS_TOOL_SHAPE_H_
0008 #define KIS_TOOL_SHAPE_H_
0009 
0010 
0011 #include <kritaui_export.h>
0012 #include <kconfig.h>
0013 #include <kconfiggroup.h>
0014 
0015 #include <kis_painter.h>
0016 
0017 #include "kis_tool_paint.h"
0018 #include "KisSelectionToolFactoryBase.h"
0019 #include "KisToolShapeUtils.h"
0020 
0021 #include "ui_wdggeometryoptions.h"
0022 
0023 class KoCanvasBase;
0024 class KoPathShape;
0025 
0026 
0027 class WdgGeometryOptions : public QWidget, public Ui::WdgGeometryOptions
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     WdgGeometryOptions(QWidget *parent) : QWidget(parent) {
0033         setupUi(this);
0034     }
0035 };
0036 
0037 /**
0038  * Base for tools specialized in drawing shapes
0039  */
0040 class KRITAUI_EXPORT KisToolShape : public KisToolPaint
0041 {
0042 
0043     Q_OBJECT
0044 
0045 public:
0046     KisToolShape(KoCanvasBase * canvas, const QCursor & cursor);
0047     ~KisToolShape() override;
0048     int flags() const override;
0049     WdgGeometryOptions *m_shapeOptionsWidget;
0050 
0051 public Q_SLOTS:
0052     void activate(const QSet<KoShape*> &shapes) override;
0053     virtual void outlineSettingChanged(int value);
0054     virtual void fillSettingChanged(int value);
0055     virtual void patternRotationSettingChanged(qreal value);
0056     virtual void patternScaleSettingChanged(qreal value);
0057 
0058 protected:
0059     QWidget* createOptionWidget() override;
0060 
0061     KisToolShapeUtils::FillStyle fillStyle();
0062     KisToolShapeUtils::StrokeStyle strokeStyle();
0063     QTransform fillTransform();
0064 
0065     qreal currentStrokeWidth() const;
0066 
0067     struct KRITAUI_EXPORT ShapeAddInfo {
0068         bool shouldAddShape = false;
0069         bool shouldAddSelectionShape = false;
0070 
0071         void markAsSelectionShapeIfNeeded(KoShape *shape) const;
0072     };
0073 
0074     ShapeAddInfo shouldAddShape(KisNodeSP currentNode) const;
0075 
0076     void addShape(KoShape* shape);
0077 
0078     void addPathShape(KoPathShape* pathShape, const KUndo2MagicString& name);
0079 
0080     /**
0081      * Use these methods in subclassed to notify when the user starts and
0082      * finishes making a shape, and override to be notified
0083      */
0084     virtual void beginShape() {}
0085     virtual void endShape() {}
0086 
0087     KConfigGroup m_configGroup;
0088 };
0089 
0090 #endif // KIS_TOOL_SHAPE_H_
0091