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#include <QPen>
20
21#include <kritaui_export.h>
22#include <kis_shared.h>
23#include <kis_types.h>
24
25class QPainter;
26class QRect;
27class QRectF;
28class KoStore;
30class KisCanvas2;
31class QDomDocument;
32class QDomElement;
34
35#include <kis_shared_ptr.h>
36#include <KoGenericRegistry.h>
37
41class QPainterPath;
42
50
51
56class KRITAUI_EXPORT KisPaintingAssistantHandle : public QPointF, public KisShared
57{
59
60public:
61 KisPaintingAssistantHandle(double x, double y);
62 explicit KisPaintingAssistantHandle(QPointF p);
65 void mergeWith(KisPaintingAssistantHandleSP);
66 void uncache();
68 void setType(char type);
69 char handleType() const;
70
76 KisPaintingAssistant* chiefAssistant() const;
77
78private:
79 void registerAssistant(KisPaintingAssistant*);
80 void unregisterAssistant(KisPaintingAssistant*);
81 bool containsAssistant(KisPaintingAssistant*) const;
82
83private:
84 struct Private;
85 Private* const d;
86};
87
92class KRITAUI_EXPORT KisPaintingAssistant
93{
94public:
95 KisPaintingAssistant(const QString& id, const QString& name);
96 virtual ~KisPaintingAssistant();
97 virtual KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap) const = 0;
98 const QString& id() const;
99 const QString& name() const;
100 bool isSnappingActive() const;
101 void setSnappingActive(bool set);
102 int brushPriority() const;
103 void setBrushPriority(int priority);
104 //copy SharedData from an assistant to this
105 void copySharedData(KisPaintingAssistantSP assistant);
106
107
119 virtual QPointF adjustPosition(const QPointF& point, const QPointF& strokeBegin, bool snapToAny, qreal moveThresholdPt) = 0;
120 virtual void adjustLine(QPointF& point, QPointF& strokeBegin) = 0;
121 virtual void endStroke();
122 virtual void setAdjustedBrushPosition(const QPointF position);
123 virtual void setFollowBrushPosition(bool follow);
124 virtual QPointF getDefaultEditorPosition() const = 0; // Returns standard editor widget position for this assistant
125 virtual QPointF getEditorPosition() const; // Returns editor widget position in document-space coordinates.
126 virtual int numHandles() const = 0;
127
132 virtual bool canBeLocal() const;
137 bool isLocal() const;
142 void setLocal(bool value);
143
148 bool isLocked();
153 void setLocked(bool value);
158 /*The duplication button must be depressed when the user clicks it. This getter function indicates to the
159 render function when the button is clicked*/
160 bool isDuplicating();
165 void setDuplicating(bool value);
166
167 QPointF editorWidgetOffset();
168 void setEditorWidgetOffset(QPointF offset);
169
170 void replaceHandle(KisPaintingAssistantHandleSP _handle, KisPaintingAssistantHandleSP _with);
171 void addHandle(KisPaintingAssistantHandleSP handle, HandleType type);
172
173 QPointF viewportConstrainedEditorPosition(const KisCoordinatesConverter* converter, const QSize editorSize);
174
175 QColor effectiveAssistantColor() const;
176 bool useCustomColor();
177 void setUseCustomColor(bool useCustomColor);
178 void setAssistantCustomColor(QColor color);
179 QColor assistantCustomColor();
180 void setAssistantGlobalColorCache(const QColor &color);
181
182 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);
183 void uncache();
184 const QList<KisPaintingAssistantHandleSP>& handles() const;
186 const QList<KisPaintingAssistantHandleSP>& sideHandles() const;
188
189 QByteArray saveXml( QMap<KisPaintingAssistantHandleSP, int> &handleMap);
190 virtual void saveCustomXml(QXmlStreamWriter* xml); //in case specific assistants have custom properties (like vanishing point)
191
192 void loadXml(KoStore *store, QMap<int, KisPaintingAssistantHandleSP> &handleMap, QString path);
193 virtual bool loadCustomXml(QXmlStreamReader* xml);
194
195 void saveXmlList(QDomDocument& doc, QDomElement& assistantsElement, int count);
196 void findPerspectiveAssistantHandleLocation();
197 KisPaintingAssistantHandleSP oppHandleOne();
198
203 const KisPaintingAssistantHandleSP topLeft() const;
205 const KisPaintingAssistantHandleSP topRight() const;
207 const KisPaintingAssistantHandleSP bottomLeft() const;
208 KisPaintingAssistantHandleSP bottomLeft();
209 const KisPaintingAssistantHandleSP bottomRight() const;
210 KisPaintingAssistantHandleSP bottomRight();
211 const KisPaintingAssistantHandleSP topMiddle() const;
213 const KisPaintingAssistantHandleSP rightMiddle() const;
214 KisPaintingAssistantHandleSP rightMiddle();
215 const KisPaintingAssistantHandleSP leftMiddle() const;
216 KisPaintingAssistantHandleSP leftMiddle();
217 const KisPaintingAssistantHandleSP bottomMiddle() const;
218 KisPaintingAssistantHandleSP bottomMiddle();
219
220
221 // calculates whether a point is near one of the corner points of the assistant
222 // returns: a corner point from the perspective assistant if the given node is close
223 // only called once in code when calculating the perspective assistant
224 KisPaintingAssistantHandleSP closestCornerHandleFromPoint(QPointF point);
225
226 // determines if two points are close to each other
227 // only used by the nodeNearPoint function (perspective grid assistant).
228 bool areTwoPointsClose(const QPointF& pointOne, const QPointF& pointTwo);
229
233 virtual bool isAssistantComplete() const;
234
238 virtual void transform(const QTransform &transform);
239
240public:
244 void drawPath(QPainter& painter, const QPainterPath& path, const KoColorDisplayRendererInterface *displayRenderInterface, bool drawActive=true, QPen startingPen = QPen());
245 void drawPreview(QPainter& painter, const QPainterPath& path, const KoColorDisplayRendererInterface *displayRenderInterface);
246 // draw a path in a red color, signalizing incorrect state
247 void drawError(QPainter& painter, const QPainterPath& path, const KoColorDisplayRendererInterface *displayRenderInterface);
248 // draw a vanishing point marker
249 void drawX(QPainter& painter, const QPointF& pt, const KoColorDisplayRendererInterface *displayRenderInterface);
250 static double norm2(const QPointF& p);
251
252 void setDecorationThickness(int thickness);
253
254protected:
255 explicit KisPaintingAssistant(const KisPaintingAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
256
257 virtual QRect boundingRect() const;
258
260 virtual void drawCache(QPainter& gc, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *displayRenderInterface, bool assistantVisible=true) = 0;
261
262 void initHandles(QList<KisPaintingAssistantHandleSP> _handles);
264
265 QPointF pixelToView(const QPoint pixelCoords) const;
272 QPointF effectiveBrushPosition(const KisCoordinatesConverter *converter, KisCanvas2 *canvas) const;
273
283 virtual KisPaintingAssistantHandleSP firstLocalHandle() const;
292 virtual KisPaintingAssistantHandleSP secondLocalHandle() const;
301 QRectF getLocalRect() const;
302
303
304public:
308 static QList<KisPaintingAssistantSP> cloneAssistantList(const QList<KisPaintingAssistantSP> &list);
309
310protected:
311 bool m_hasBeenInsideLocalRect {false};
312
313private:
314 struct Private;
315 Private* const d;
316
317};
318
322class KRITAUI_EXPORT KisPaintingAssistantFactory
323{
324public:
327 virtual QString id() const = 0;
328 virtual QString name() const = 0;
330
331};
332
333class KRITAUI_EXPORT KisPaintingAssistantFactoryRegistry : public KoGenericRegistry<KisPaintingAssistantFactory*>
334{
335 public:
338
340
341};
342
343#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 QPointF getDefaultEditorPosition() const =0
QList< KisPaintingAssistantHandleSP > m_handles
virtual KisPaintingAssistantSP clone(QMap< KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP > &handleMap) const =0
virtual int numHandles() const =0
virtual void drawCache(QPainter &gc, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *displayRenderInterface, bool assistantVisible=true)=0
performance layer where the graphics can be drawn from a cache instead of generated every render upda...
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