13#include <klocalizedstring.h>
16#include <QPainterPath>
17#include <QLinearGradient>
33 , m_canvas(rhs.m_canvas)
34 , m_referenceLineDensity(rhs.m_referenceLineDensity)
51 return QPointF(qQNaN(), qQNaN());
56 QLineF snapLine = QLineF(*
handles()[0], strokeBegin);
59 qreal dx = snapLine.dx();
60 qreal dy = snapLine.dy();
62 const qreal dx2 = dx * dx;
63 const qreal dy2 = dy * dy;
64 const qreal invsqrlen = 1.0 / (dx2 + dy2);
66 QPointF r(dx2 * pt.x() + dy2 * snapLine.x1() + dx * dy * (pt.y() - snapLine.y1()),
67 dx2 * snapLine.y1() + dy2 * pt.y() + dx * dy * (pt.x() - snapLine.x1()));
75 return project(pt, strokeBegin, moveThresholdPt);
80 point =
project(point, strokeBegin, 0.0);
88 QPointF vpPoint = *
handles()[0];
98 QRect viewport= gc.viewport();
110 QPointF startPoint = initialTransform.map(*
handles()[0]);
113 QLineF snapLine= QLineF(startPoint, mousePos);
119 path.moveTo(snapLine.p2());
120 path.lineTo(snapLine.p1());
135 QPointF
p0 = initialTransform.map(*
handles()[0]);
139 QPointF p4 = initialTransform.map(*
sideHandles()[3]);
142 QRectF ellipse = QRectF(QPointF(
p0.x() -15,
p0.y() -15), QSizeF(30, 30));
144 QPainterPath pathCenter;
145 pathCenter.addEllipse(ellipse);
175 QPointF
p2 = QPointF(
p1.x(),
p3.y());
176 QPointF p4 = QPointF(
p3.x(),
p1.y());
178 path.moveTo(initialTransform.map(
p1));
180 path.lineTo(initialTransform.map(
p2));
181 path.lineTo(initialTransform.map(
p3));
182 path.lineTo(initialTransform.map(p4));
183 path.lineTo(initialTransform.map(
p1));
192 QPointF
p0 = initialTransform.map(*
handles()[0]);
197 float xPos = cos(currentAngle *
M_PI / 180);
198 float yPos = sin(currentAngle *
M_PI / 180);
200 unitAngle.setX(
p0.x() + xPos);
201 unitAngle.setY(
p0.y() + yPos);
204 QLineF snapLine= QLineF(
p0, unitAngle);
209 path.moveTo(snapLine.p1());
210 path.lineTo(snapLine.p2());
232 QPointF
p0 = initialTransform.map(*
handles()[0]);
236 path.moveTo(QPointF(
p0.x() - 10.0,
p0.y() - 10.0));
237 path.lineTo(QPointF(
p0.x() + 10.0,
p0.y() + 10.0));
239 path.moveTo(QPointF(
p0.x() - 10.0,
p0.y() + 10.0));
240 path.lineTo(QPointF(
p0.x() + 10.0,
p0.y() - 10.0));
267 if (
handles().size() > pointHandle) {
268 return *
handles().at(pointHandle);
271 return QPointF(0, 0);
302 xml->writeStartElement(
"angleDensity");
304 xml->writeEndElement();
305 xml->writeStartElement(
"isLocal");
307 xml->writeEndElement();
312 if (xml && xml->name() ==
"angleDensity") {
315 if (xml && xml->name() ==
"isLocal") {
333 return "vanishing point";
338 return i18n(
"Vanishing Point");
float value(const T *src, size_t ch)
KisPaintingAssistantsDecorationSP paintingAssistantsDecoration() const
QTransform documentToWidgetTransform() const
QPointF effectiveBrushPosition(const KisCoordinatesConverter *converter, KisCanvas2 *canvas) const
Query the effective brush position to be used for preview lines. This is intended to be used for pain...
bool isSnappingActive() const
void addHandle(KisPaintingAssistantHandleSP handle, HandleType type)
void drawPreview(QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface)
virtual void drawAssistant(QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *displayRenderInterface, bool cached, KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true)
QColor effectiveAssistantColor() const
QRectF getLocalRect() const
getLocalRect The function deals with local handles not being topLeft and bottomRight gracefully and r...
bool isLocal() const
isLocal
const QList< KisPaintingAssistantHandleSP > & sideHandles() const
void drawPath(QPainter &painter, const QPainterPath &path, const KoColorDisplayRendererInterface *displayRenderInterface, bool drawActive=true, QPen startingPen=QPen())
bool m_hasBeenInsideLocalRect
void setLocal(bool value)
setLocal
const QList< KisPaintingAssistantHandleSP > & handles() const
bool isEditingAssistants()
KisPaintingAssistant * createPaintingAssistant() const override
QString name() const override
VanishingPointAssistantFactory()
~VanishingPointAssistantFactory() override
QString id() const override
QPointF project(const QPointF &pt, const QPointF &strokeBegin, qreal moveThresholdPt)
void drawAssistant(QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *displayRenderInterface, bool cached=true, KisCanvas2 *canvas=nullptr, bool assistantVisible=true, bool previewVisible=true) override
void drawCache(QPainter &gc, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *displayRenderInterface, bool assistantVisible=true) override
performance layer where the graphics can be drawn from a cache instead of generated every render upda...
QPointF getDefaultEditorPosition() const override
void setReferenceLineDensity(float value)
void saveCustomXml(QXmlStreamWriter *xml) override
VanishingPointAssistant()
float m_referenceLineDensity
int numHandles() const override
KisPaintingAssistantHandleSP secondLocalHandle() const override
secondLocalHandle Note: this doesn't guarantee it will be the bottomRight corner! For that,...
void adjustLine(QPointF &point, QPointF &strokeBegin) override
bool isAssistantComplete() const override
bool loadCustomXml(QXmlStreamReader *xml) override
QPointF adjustPosition(const QPointF &point, const QPointF &strokeBegin, bool snapToAny, qreal moveThresholdPt) override
KisPaintingAssistantHandleSP firstLocalHandle() const override
firstLocalHandle Note: this doesn't guarantee it will be the topleft corner! For that,...
bool canBeLocal() const override
canBeLocal
KisPaintingAssistantSP clone(QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap) const override
float referenceLineDensity()
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
QSharedPointer< KisPaintingAssistant > KisPaintingAssistantSP
void cropLineToConvexPolygon(QLineF &line, const QPolygonF polygon, bool extendFirst, bool extendSecond)
bool intersectLineConvexPolygon(QLineF &line, const QPolygonF polygon, bool extendFirst, bool extendSecond)
double toDouble(const QString &str, bool *ok=nullptr)
int toInt(const QString &str, bool *ok=nullptr)
QString toString(const QString &value)