File indexing completed on 2024-12-22 04:09:14

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2006, 2008 Jan Hambrecht <jaham@gmx.net>
0003  * SPDX-FileCopyrightText: 2006, 2007 Thorsten Zachmann <zachmann@kde.org>
0004  * SPDX-FileCopyrightText: 2007, 2010 Thomas Zander <zander@kde.org>
0005  * SPDX-FileCopyrightText: 2007 Boudewijn Rempt <boud@valdyas.org>
0006  *
0007  * SPDX-License-Identifier: LGPL-2.0-or-later
0008  */
0009 
0010 #ifndef KOPATHTOOLHANDLE_H
0011 #define KOPATHTOOLHANDLE_H
0012 
0013 #include <KoPathPoint.h>
0014 #include "KoInteractionStrategy.h"
0015 
0016 #include <QList>
0017 #include <QRect>
0018 
0019 class KoPathTool;
0020 class KoParameterShape;
0021 class KoViewConverter;
0022 class KoPointerEvent;
0023 class QPainter;
0024 class KoPathShape;
0025 class KisHandlePainterHelper;
0026 
0027 
0028 class KoPathToolHandle
0029 {
0030 public:
0031     explicit KoPathToolHandle(KoPathTool *tool);
0032     virtual ~KoPathToolHandle();
0033     virtual void paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius, int decorationThickness) = 0;
0034     virtual QRectF boundingRect() const = 0;
0035     virtual KoInteractionStrategy * handleMousePress(KoPointerEvent *event) = 0;
0036     // test if handle is still valid
0037     virtual bool check(const QList<KoPathShape*> &selectedShapes) = 0;
0038 
0039     virtual void trySelectHandle() {};
0040 
0041 protected:
0042     KoPathTool *m_tool;
0043 };
0044 
0045 class PointHandle : public KoPathToolHandle
0046 {
0047 public:
0048     PointHandle(KoPathTool *tool, KoPathPoint *activePoint, KoPathPoint::PointType activePointType);
0049     void paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius, int decorationThickness) override;
0050     QRectF boundingRect() const override;
0051     KoInteractionStrategy *handleMousePress(KoPointerEvent *event) override;
0052     bool check(const QList<KoPathShape*> &selectedShapes) override;
0053     KoPathPoint *activePoint() const;
0054     KoPathPoint::PointType activePointType() const;
0055     void trySelectHandle() override;
0056 private:
0057     KoPathPoint *m_activePoint;
0058     KoPathPoint::PointType m_activePointType;
0059     mutable QRectF m_oldRepaintedRect;
0060 };
0061 
0062 class ParameterHandle : public KoPathToolHandle
0063 {
0064 public:
0065     ParameterHandle(KoPathTool *tool, KoParameterShape *parameterShape, int handleId);
0066     void paint(QPainter &painter, const KoViewConverter &converter, qreal handleRadius, int decorationThickness) override;
0067     QRectF boundingRect() const override;
0068     KoInteractionStrategy *handleMousePress(KoPointerEvent *event) override;
0069     bool check(const QList<KoPathShape*> &selectedShapes) override;
0070 protected:
0071     KoParameterShape *m_parameterShape;
0072     int m_handleId;
0073 };
0074 
0075 #endif // KOPATHTOOLHANDLE_H