Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_painting_assistant.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2008 Cyrille Berger <cberger@cberger.net>
3 * SPDX-FileCopyrightText: 2017 Scott Petrovic <scottpetrovic@gmail.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#ifndef _KIS_PAINTING_ASSISTANT_H_
9#define _KIS_PAINTING_ASSISTANT_H_
10
11#include <QString>
12#include <QPointF>
13#include <QRect>
14#include <QFile>
15#include <QObject>
16#include <QColor>
17#include <QXmlStreamWriter>
18#include <QMap>
19
20#include <kritaui_export.h>
21#include <kis_shared.h>
22#include <kis_types.h>
23
24class QPainter;
25class QRect;
26class QRectF;
27class KoStore;
29class KisCanvas2;
30class QDomDocument;
31class QDomElement;
32
33#include <kis_shared_ptr.h>
34#include <KoGenericRegistry.h>
35
39class QPainterPath;
40
48
49
54class KRITAUI_EXPORT KisPaintingAssistantHandle : public QPointF, public KisShared
55{
57
58public:
59 KisPaintingAssistantHandle(double x, double y);
60 explicit KisPaintingAssistantHandle(QPointF p);
63 void mergeWith(KisPaintingAssistantHandleSP);
64 void uncache();
66 void setType(char type);
67 char handleType() const;
68
74 KisPaintingAssistant* chiefAssistant() const;
75
76private:
77 void registerAssistant(KisPaintingAssistant*);
78 void unregisterAssistant(KisPaintingAssistant*);
79 bool containsAssistant(KisPaintingAssistant*) const;
80
81private:
82 struct Private;
83 Private* const d;
84};
85
90class KRITAUI_EXPORT KisPaintingAssistant
91{
92public:
93 KisPaintingAssistant(const QString& id, const QString& name);
94 virtual ~KisPaintingAssistant();
95 virtual KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap) const = 0;
96 const QString& id() const;
97 const QString& name() const;
98 bool isSnappingActive() const;
99 void setSnappingActive(bool set);
100 //copy SharedData from an assistant to this
101 void copySharedData(KisPaintingAssistantSP assistant);
102
103
115 virtual QPointF adjustPosition(const QPointF& point, const QPointF& strokeBegin, bool snapToAny, qreal moveThresholdPt) = 0;
116 virtual void adjustLine(QPointF& point, QPointF& strokeBegin) = 0;
117 virtual void endStroke();
118 virtual void setAdjustedBrushPosition(const QPointF position);
119 virtual void setFollowBrushPosition(bool follow);
120 virtual QPointF getDefaultEditorPosition() const = 0; // Returns standard editor widget position for this assistant
121 virtual QPointF getEditorPosition() const; // Returns editor widget position in document-space coordinates.
122 virtual int numHandles() const = 0;
123
128 virtual bool canBeLocal() const;
133 bool isLocal() const;
138 void setLocal(bool value);
139
144 bool isLocked();
149 void setLocked(bool value);
154 /*The duplication button must be depressed when the user clicks it. This getter function indicates to the
155 render function when the button is clicked*/
156 bool isDuplicating();
161 void setDuplicating(bool value);
162
163 QPointF editorWidgetOffset();
164 void setEditorWidgetOffset(QPointF offset);
165
166 void replaceHandle(KisPaintingAssistantHandleSP _handle, KisPaintingAssistantHandleSP _with);
167 void addHandle(KisPaintingAssistantHandleSP handle, HandleType type);
168
169 QPointF viewportConstrainedEditorPosition(const KisCoordinatesConverter* converter, const QSize editorSize);
170
171 QColor effectiveAssistantColor() const;
172 bool useCustomColor();
173 void setUseCustomColor(bool useCustomColor);
174 void setAssistantCustomColor(QColor color);
175 QColor assistantCustomColor();
176 void setAssistantGlobalColorCache(const QColor &color);
177
178 virtual void drawAssistant(QPainter& gc, const QRectF& updateRect, const KisCoordinatesConverter *converter, bool cached, KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true);
179 void uncache();
180 const QList<KisPaintingAssistantHandleSP>& handles() const;
182 const QList<KisPaintingAssistantHandleSP>& sideHandles() const;
184
185 QByteArray saveXml( QMap<KisPaintingAssistantHandleSP, int> &handleMap);
186 virtual void saveCustomXml(QXmlStreamWriter* xml); //in case specific assistants have custom properties (like vanishing point)
187
188 void loadXml(KoStore *store, QMap<int, KisPaintingAssistantHandleSP> &handleMap, QString path);
189 virtual bool loadCustomXml(QXmlStreamReader* xml);
190
191 void saveXmlList(QDomDocument& doc, QDomElement& assistantsElement, int count);
192 void findPerspectiveAssistantHandleLocation();
193 KisPaintingAssistantHandleSP oppHandleOne();
194
199 const KisPaintingAssistantHandleSP topLeft() const;
201 const KisPaintingAssistantHandleSP topRight() const;
203 const KisPaintingAssistantHandleSP bottomLeft() const;
204 KisPaintingAssistantHandleSP bottomLeft();
205 const KisPaintingAssistantHandleSP bottomRight() const;
206 KisPaintingAssistantHandleSP bottomRight();
207 const KisPaintingAssistantHandleSP topMiddle() const;
209 const KisPaintingAssistantHandleSP rightMiddle() const;
210 KisPaintingAssistantHandleSP rightMiddle();
211 const KisPaintingAssistantHandleSP leftMiddle() const;
212 KisPaintingAssistantHandleSP leftMiddle();
213 const KisPaintingAssistantHandleSP bottomMiddle() const;
214 KisPaintingAssistantHandleSP bottomMiddle();
215
216
217 // calculates whether a point is near one of the corner points of the assistant
218 // returns: a corner point from the perspective assistant if the given node is close
219 // only called once in code when calculating the perspective assistant
220 KisPaintingAssistantHandleSP closestCornerHandleFromPoint(QPointF point);
221
222 // determines if two points are close to each other
223 // only used by the nodeNearPoint function (perspective grid assistant).
224 bool areTwoPointsClose(const QPointF& pointOne, const QPointF& pointTwo);
225
229 virtual bool isAssistantComplete() const;
230
234 virtual void transform(const QTransform &transform);
235
236public:
240 void drawPath(QPainter& painter, const QPainterPath& path, bool drawActive=true);
241 void drawPreview(QPainter& painter, const QPainterPath& path);
242 // draw a path in a red color, signalizing incorrect state
243 void drawError(QPainter& painter, const QPainterPath& path);
244 // draw a vanishing point marker
245 void drawX(QPainter& painter, const QPointF& pt);
246 static double norm2(const QPointF& p);
247
248 void setDecorationThickness(int thickness);
249
250protected:
251 explicit KisPaintingAssistant(const KisPaintingAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
252
253 virtual QRect boundingRect() const;
254
256 virtual void drawCache(QPainter& gc, const KisCoordinatesConverter *converter, bool assistantVisible=true) = 0;
257
258 void initHandles(QList<KisPaintingAssistantHandleSP> _handles);
260
261 QPointF pixelToView(const QPoint pixelCoords) const;
268 QPointF effectiveBrushPosition(const KisCoordinatesConverter *converter, KisCanvas2 *canvas) const;
269
279 virtual KisPaintingAssistantHandleSP firstLocalHandle() const;
288 virtual KisPaintingAssistantHandleSP secondLocalHandle() const;
297 QRectF getLocalRect() const;
298
299
300public:
304 static QList<KisPaintingAssistantSP> cloneAssistantList(const QList<KisPaintingAssistantSP> &list);
305
306protected:
307 bool m_hasBeenInsideLocalRect {false};
308
309private:
310 struct Private;
311 Private* const d;
312
313};
314
318class KRITAUI_EXPORT KisPaintingAssistantFactory
319{
320public:
323 virtual QString id() const = 0;
324 virtual QString name() const = 0;
326
327};
328
329class KRITAUI_EXPORT KisPaintingAssistantFactoryRegistry : public KoGenericRegistry<KisPaintingAssistantFactory*>
330{
331 public:
334
336
337};
338
339#endif
float value(const T *src, size_t ch)
const Params2D p
PythonPluginManager * instance
virtual QString id() const =0
virtual QString name() const =0
virtual KisPaintingAssistant * createPaintingAssistant() const =0
virtual void drawCache(QPainter &gc, const KisCoordinatesConverter *converter, bool assistantVisible=true)=0
performance layer where the graphics can be drawn from a cache instead of generated every render upda...
virtual QPointF getDefaultEditorPosition() const =0
QList< KisPaintingAssistantHandleSP > m_handles
virtual KisPaintingAssistantSP clone(QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap) const =0
virtual int numHandles() const =0
virtual QPointF adjustPosition(const QPointF &point, const QPointF &strokeBegin, bool snapToAny, qreal moveThresholdPt)=0
virtual void adjustLine(QPointF &point, QPointF &strokeBegin)=0
KisShared & operator=(const KisShared &)
@ VANISHING_POINT
KisSharedPtr< KisPaintingAssistantHandle > KisPaintingAssistantHandleSP