Krita Source Code Documentation
Loading...
Searching...
No Matches
TwoPointAssistant.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: 2021 Nabil Maghfur Usman <nmaghfurusman@gmail.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8
9#ifndef _TWO_POINT_ASSISTANT_H_
10#define _TWO_POINT_ASSISTANT_H_
11
14#include <QObject>
15#include <QLineF>
16#include <QTransform>
17
19{
20 Q_OBJECT
21public:
22
30
31
33 QPointF adjustPosition(const QPointF& point, const QPointF& strokeBegin, const bool snapToAny, qreal moveThresholdPt) override;
34 void adjustLine(QPointF &point, QPointF& strokeBegin) override;
35 void endStroke() override;
36 KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap) const override;
37
38 QPointF getDefaultEditorPosition() const override;
39 int numHandles() const override { return isLocal() ? 5 : 3; }
40
41 void saveCustomXml(QXmlStreamWriter* xml) override;
42 bool loadCustomXml(QXmlStreamReader* xml) override;
43
44 double gridDensity();
45 void setGridDensity(double density);
46
47 /* If true, it means the assistant will have three handles
48 * If false,
49 * */
50 bool useVertical();
51 void setUseVertical(bool value);
52
53 bool isAssistantComplete() const override;
54 bool canBeLocal() const override;
55
56 bool contains(const QPointF& point) const override;
57 qreal distance(const QPointF& point) const override;
58 bool isActive() const override;
59
60 /* Generate a transform for converting handles into easier local
61 coordinate system that has the following properties:
62 - Rotated so horizon is perfectly horizontal
63 - Translated so the origin is the projection of the 3rd handle
64 onto the horizon; the handle lies on the local y axis
65 Parameters are the first VP, second VP, a 3rd point which
66 defines the center of vision, and lastly a reference to a size
67 variable which is the radius of the 90 degree cone of vision.
68 The transform only rotates and translates, so size is also an
69 image-space length. The horizon is at local y = 0.
70 (useful for computing snapping behaviour and drawing grid
71 lines) */
72 QTransform localTransform(QPointF vp_a, QPointF vp_b, QPointF pt_c, qreal* size) const;
73
74protected:
75 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;
76 void drawCache(QPainter& gc, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *displayRenderInterface, bool assistantVisible=true) override;
77
80
81
82private:
83 QPointF project(const QPointF& pt, const QPointF& strokeBegin, const bool snapToAny, qreal moveThreshold);
84 bool localPerspectiveData(const QPointF &point, QPointF *localPoint, qreal *size) const;
85 explicit TwoPointAssistant(const TwoPointAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
86 KisCanvas2 *m_canvas {nullptr};
87
88 QLineF m_snapLine;
89 double m_gridDensity {1.0};
90 bool m_useVertical {true};
91
92 int m_lastUsedPoint {-1}; // last used vanishing point
93
94};
95
97{
98public:
100 ~TwoPointAssistantFactory() override;
101 QString id() const override;
102 QString name() const override;
104};
105
106#endif
float value(const T *src, size_t ch)
QString name() const override
QString id() const override
KisPaintingAssistant * createPaintingAssistant() const override
KisPaintingAssistantSP clone(QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap) const override
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
QTransform localTransform(QPointF vp_a, QPointF vp_b, QPointF pt_c, qreal *size) const
void setGridDensity(double density)
void setUseVertical(bool value)
KisPaintingAssistantHandleSP secondLocalHandle() const override
secondLocalHandle Note: this doesn't guarantee it will be the bottomRight corner! For that,...
qreal distance(const QPointF &point) const override
bool localPerspectiveData(const QPointF &point, QPointF *localPoint, qreal *size) const
void endStroke() override
void saveCustomXml(QXmlStreamWriter *xml) override
QPointF adjustPosition(const QPointF &point, const QPointF &strokeBegin, const bool snapToAny, qreal moveThresholdPt) override
bool loadCustomXml(QXmlStreamReader *xml) override
QPointF getDefaultEditorPosition() const override
bool contains(const QPointF &point) const 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 project(const QPointF &pt, const QPointF &strokeBegin, const bool snapToAny, qreal moveThreshold)
void adjustLine(QPointF &point, QPointF &strokeBegin) override
bool isActive() const override
bool canBeLocal() const override
canBeLocal
int numHandles() const override
bool isAssistantComplete() const override
KisPaintingAssistantHandleSP firstLocalHandle() const override
firstLocalHandle Note: this doesn't guarantee it will be the topleft corner! For that,...