File indexing completed on 2024-06-23 04:25:57
0001 /* 0002 * SPDX-FileCopyrightText: 2008 Cyrille Berger <cberger@cberger.net> 0003 * SPDX-FileCopyrightText: 2010 Geoffry Song <goffrie@gmail.com> 0004 * SPDX-FileCopyrightText: 2014 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com> 0005 * SPDX-FileCopyrightText: 2017 Scott Petrovic <scottpetrovic@gmail.com> 0006 * SPDX-FileCopyrightText: 2022 Julian Schmidt <julisch1107@web.de> 0007 * 0008 * SPDX-License-Identifier: LGPL-2.0-or-later 0009 */ 0010 0011 #ifndef _INFINITERULER_ASSISTANT_H_ 0012 #define _INFINITERULER_ASSISTANT_H_ 0013 0014 #include "RulerAssistant.h" 0015 0016 #include <QObject> 0017 #include <QPolygonF> 0018 #include <QLineF> 0019 #include <QTransform> 0020 0021 0022 0023 class InfiniteRulerAssistant : public RulerAssistant 0024 { 0025 public: 0026 InfiniteRulerAssistant(); 0027 KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap) const override; 0028 QPointF adjustPosition(const QPointF& point, const QPointF& strokeBegin, const bool snapToAny, qreal moveThresholdPt) override; 0029 void adjustLine(QPointF &point, QPointF& strokeBegin) override; 0030 QPointF getDefaultEditorPosition() const override; 0031 int numHandles() const override { return 2; } 0032 bool isAssistantComplete() const override; 0033 0034 protected: 0035 void drawAssistant(QPainter& gc, const QRectF& updateRect, const KisCoordinatesConverter* converter, bool cached = true,KisCanvas2* canvas=0, bool assistantVisible=true, bool previewVisible=true) override; 0036 0037 private: 0038 QPointF project(const QPointF& pt, const QPointF& strokeBegin, const bool checkForInitialMovement, qreal moveThresholdPt); 0039 explicit InfiniteRulerAssistant(const InfiniteRulerAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap); 0040 0041 void drawSubdivisions(QPainter& gc, const KisCoordinatesConverter *converter); 0042 0043 // Helper struct for clipLineParametric's return type 0044 struct ClippingResult { 0045 bool intersects; 0046 qreal tmin; 0047 qreal tmax; 0048 }; 0049 // Like KisAlgebra2D::clipLineRect, but returns the parametric positions 0050 static ClippingResult clipLineParametric(QLineF line, QRectF rect, bool extendFirst=true, bool extendSecond=true); 0051 }; 0052 0053 class InfiniteRulerAssistantFactory : public KisPaintingAssistantFactory 0054 { 0055 public: 0056 InfiniteRulerAssistantFactory(); 0057 ~InfiniteRulerAssistantFactory() override; 0058 QString id() const override; 0059 QString name() const override; 0060 KisPaintingAssistant* createPaintingAssistant() const override; 0061 }; 0062 0063 #endif