File indexing completed on 2024-12-22 04:13:03
0001 /* 0002 * SPDX-FileCopyrightText: 2000 John Califf <jcaliff@compuzone.net> 0003 * SPDX-FileCopyrightText: 2002 Patrick Julien <freak@codepimps.org> 0004 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org> 0005 * SPDX-FileCopyrightText: 2015 Michael Abrahams <miabraha@gmail.com> 0006 * 0007 * SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #ifndef KISTOOLOUTLINEBASE_H 0011 #define KISTOOLOUTLINEBASE_H 0012 0013 #include <kis_tool_shape.h> 0014 #include <kis_cursor.h> 0015 0016 class KRITAUI_EXPORT KisToolOutlineBase : public KisToolShape 0017 { 0018 Q_OBJECT 0019 0020 public: 0021 enum ToolType { 0022 PAINT, 0023 SELECT 0024 }; 0025 0026 KisToolOutlineBase(KoCanvasBase *canvas, 0027 ToolType type, 0028 const QCursor & cursor=KisCursor::load("tool_outline_selection_cursor.png", 6, 6)); 0029 ~KisToolOutlineBase() override; 0030 0031 void beginPrimaryAction(KoPointerEvent *event) override; 0032 void continuePrimaryAction(KoPointerEvent *event) override; 0033 void endPrimaryAction(KoPointerEvent *event) override; 0034 void paint(QPainter& gc, const KoViewConverter &converter) override; 0035 0036 void keyPressEvent(QKeyEvent *event) override; 0037 void keyReleaseEvent(QKeyEvent *event) override; 0038 void mouseMoveEvent(KoPointerEvent *event) override; 0039 bool eventFilter(QObject *obj, QEvent *event) override; 0040 KisPopupWidgetInterface* popupWidget() override; 0041 0042 bool hasUserInteractionRunning() const; 0043 0044 public Q_SLOTS: 0045 void activate(const QSet<KoShape*> &shapes) override; 0046 void deactivate() override; 0047 void requestStrokeEnd() override; 0048 void requestStrokeCancellation() override; 0049 0050 void undoLastPoint(); 0051 0052 protected: 0053 virtual void finishOutline(const QVector<QPointF>& points) = 0; 0054 0055 private: 0056 static constexpr int FEEDBACK_LINE_WIDTH{2}; 0057 0058 QPainterPath m_paintPath; 0059 QVector<QPointF> m_points; 0060 bool m_continuedMode; 0061 QPointF m_lastCursorPos; 0062 ToolType m_type; 0063 int m_numberOfContinuedModePoints; 0064 bool m_hasUserInteractionRunning; 0065 0066 void updateFeedback(); 0067 void updateContinuedMode(); 0068 void updateCanvas(); 0069 void endStroke(); 0070 void cancelStroke(); 0071 QRectF dragBoundingRect(); 0072 }; 0073 0074 #endif