File indexing completed on 2024-05-26 04:32:08
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 * 0007 * SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef _VANISHINGPOINT_ASSISTANT_H_ 0011 #define _VANISHINGPOINT_ASSISTANT_H_ 0012 0013 #include "kis_painting_assistant.h" 0014 #include <QObject> 0015 #include <QPolygonF> 0016 #include <QLineF> 0017 #include <QTransform> 0018 /* Design: 0019 *The idea behind the vanishing point ruler is that in a perspective deformed landscape, a set of parallel 0020 *lines al share a single vanishing point. 0021 *Therefore, a perspective can contain an theoretical infinite of vanishing points. 0022 *It's a pity if we only allowed an artist to access 1, 2 or 3 of these at any given time, as other 0023 *solutions for perspective tools do. 0024 *Hence a vanishing point ruler. 0025 * 0026 *This ruler is relatively simple compared to the other perspective ruler: 0027 *It has only one vanishing point that is required to draw. 0028 *However, it does have it's own weaknesses in how to determine onto which of these infinite rulers to snap. 0029 *Furthermore, it has four extra handles for adding a perspective ruler to a preexisting perspective. 0030 */ 0031 //class VanishingPoint; 0032 0033 class VanishingPointAssistant : public KisPaintingAssistant 0034 { 0035 public: 0036 VanishingPointAssistant(); 0037 0038 enum VanishingPointAssistantHandle { 0039 VanishingPointHandle, 0040 LocalFirstHandle, 0041 LocalSecondHandle 0042 }; 0043 0044 KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap) const override; 0045 QPointF adjustPosition(const QPointF& point, const QPointF& strokeBegin, bool snapToAny, qreal moveThresholdPt) override; 0046 void adjustLine(QPointF &point, QPointF& strokeBegin) override; 0047 QPointF getDefaultEditorPosition() const override; 0048 int numHandles() const override { return isLocal() ? 3 : 1; } 0049 0050 float referenceLineDensity(); 0051 void setReferenceLineDensity(float value); 0052 0053 bool isAssistantComplete() const override; 0054 bool canBeLocal() const override; 0055 0056 void saveCustomXml(QXmlStreamWriter* xml) override; 0057 bool loadCustomXml(QXmlStreamReader* xml) override; 0058 0059 protected: 0060 void drawAssistant(QPainter& gc, const QRectF& updateRect, const KisCoordinatesConverter* converter, bool cached = true,KisCanvas2* canvas=nullptr, bool assistantVisible=true, bool previewVisible=true) override; 0061 void drawCache(QPainter& gc, const KisCoordinatesConverter *converter, bool assistantVisible=true) override; 0062 0063 KisPaintingAssistantHandleSP firstLocalHandle() const override; 0064 KisPaintingAssistantHandleSP secondLocalHandle() const override; 0065 0066 private: 0067 0068 0069 QPointF project(const QPointF& pt, const QPointF& strokeBegin, qreal moveThresholdPt); 0070 explicit VanishingPointAssistant(const VanishingPointAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap); 0071 0072 KisCanvas2 *m_canvas {nullptr}; 0073 0074 float m_referenceLineDensity {15.0}; 0075 }; 0076 0077 class VanishingPointAssistantFactory : public KisPaintingAssistantFactory 0078 { 0079 public: 0080 VanishingPointAssistantFactory(); 0081 ~VanishingPointAssistantFactory() override; 0082 QString id() const override; 0083 QString name() const override; 0084 KisPaintingAssistant* createPaintingAssistant() const override; 0085 }; 0086 0087 #endif