Krita Source Code Documentation
Loading...
Searching...
No Matches
PerspectiveAssistant.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2008 Cyrille Berger <cberger@cberger.net>
3 * SPDX-FileCopyrightText: 2010 Geoffry Song <goffrie@gmail.com>
4 * SPDX-FileCopyrightText: 2017 Scott Petrovic <scottpetrovic@gmail.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8
9#ifndef _PERSPECTIVE_ASSISTANT_H_
10#define _PERSPECTIVE_ASSISTANT_H_
11
14#include <QObject>
15#include <QPolygonF>
16#include <QLineF>
17#include <QTransform>
18
20
22{
23 Q_OBJECT
24public:
25 PerspectiveAssistant(QObject * parent = 0);
26 KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap) const override;
27
28 QPointF adjustPosition(const QPointF& point, const QPointF& strokeBegin, const bool snapToAny, qreal moveThresholdPt) override;
29 void adjustLine(QPointF &point, QPointF& strokeBegin) override;
30 void endStroke() override;
31
32 QPointF getDefaultEditorPosition() const override;
33 int numHandles() const override { return 4; }
34 void drawAssistant(QPainter& gc, const QRectF& updateRect, const KisCoordinatesConverter* converter, bool cached = true,KisCanvas2* canvas=0, bool assistantVisible=true, bool previewVisible=true) override;
35
36 bool contains(const QPointF& point) const override;
37 qreal distance(const QPointF& point) const override;
38 bool isActive() const override;
39
40 int subdivisions() const;
42
43 bool isAssistantComplete() const override;
44
45 void saveCustomXml(QXmlStreamWriter *xml) override;
46 bool loadCustomXml(QXmlStreamReader *xml) override;
47
48protected:
49 void drawCache(QPainter& gc, const KisCoordinatesConverter *converter, bool assistantVisible=true) override;
50private:
51 QPointF project(const QPointF& pt, const QPointF& strokeBegin, const bool snapToAnyDirection, qreal moveThresholdPt);
52 // creates the convex hull, returns false if it's not a quadrilateral
53 // finds the transform from perspective coordinates (a unit square) to the document
54 bool getTransform(QPolygonF& polyOut, QTransform& transformOut) const;
55 explicit PerspectiveAssistant(const PerspectiveAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
56
57 // The number of subdivisions to draw
59 // which direction to snap to (in transformed coordinates)
60 QLineF m_snapLine;
61 // cached information
62 mutable QTransform m_cachedTransform;
63 mutable QPolygonF m_cachedPolygon;
64 mutable QPointF m_cachedPoints[4];
65 mutable bool m_cacheValid {false};
66
68
69};
70
72{
73public:
76 QString id() const override;
77 QString name() const override;
79};
80
81#endif
KisPaintingAssistant * createPaintingAssistant() const override
QString name() const override
bool getTransform(QPolygonF &polyOut, QTransform &transformOut) const
void drawAssistant(QPainter &gc, const QRectF &updateRect, const KisCoordinatesConverter *converter, bool cached=true, KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true) override
PerspectiveAssistant(QObject *parent=0)
bool isAssistantComplete() const override
QPointF project(const QPointF &pt, const QPointF &strokeBegin, const bool snapToAnyDirection, qreal moveThresholdPt)
int numHandles() const override
QPointF getDefaultEditorPosition() const override
void saveCustomXml(QXmlStreamWriter *xml) override
void drawCache(QPainter &gc, const KisCoordinatesConverter *converter, bool assistantVisible=true) override
performance layer where the graphics can be drawn from a cache instead of generated every render upda...
bool contains(const QPointF &point) const override
KisPaintingAssistantSP clone(QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap) const override
qreal distance(const QPointF &point) const override
PerspectiveBasedAssistantHelper::CacheData m_cache
bool isActive() const override
void adjustLine(QPointF &point, QPointF &strokeBegin) override
bool loadCustomXml(QXmlStreamReader *xml) override
void setSubdivisions(int subdivisions)
QPointF adjustPosition(const QPointF &point, const QPointF &strokeBegin, const bool snapToAny, qreal moveThresholdPt) override