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;
33
34#include <kis_shared_ptr.h>
35#include <KoGenericRegistry.h>
36
40class QPainterPath;
41
49
50
55class KRITAUI_EXPORT KisPaintingAssistantHandle : public QPointF, public KisShared
56{
58
59public:
60 KisPaintingAssistantHandle(double x, double y);
61 explicit KisPaintingAssistantHandle(QPointF p);
64 void mergeWith(KisPaintingAssistantHandleSP);
65 void uncache();
67 void setType(char type);
68 char handleType() const;
69
75 KisPaintingAssistant* chiefAssistant() const;
76
77private:
78 void registerAssistant(KisPaintingAssistant*);
79 void unregisterAssistant(KisPaintingAssistant*);
80 bool containsAssistant(KisPaintingAssistant*) const;
81
82private:
83 struct Private;
84 Private* const d;
85};
86
91class KRITAUI_EXPORT KisPaintingAssistant
92{
93public:
94 KisPaintingAssistant(const QString& id, const QString& name);
95 virtual ~KisPaintingAssistant();
96 virtual KisPaintingAssistantSP clone(QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap) const = 0;
97 const QString& id() const;
98 const QString& name() const;
99 bool isSnappingActive() const;
100 void setSnappingActive(bool set);
101 //copy SharedData from an assistant to this
102 void copySharedData(KisPaintingAssistantSP assistant);
103
104
116 virtual QPointF adjustPosition(const QPointF& point, const QPointF& strokeBegin, bool snapToAny, qreal moveThresholdPt) = 0;
117 virtual void adjustLine(QPointF& point, QPointF& strokeBegin) = 0;
118 virtual void endStroke();
119 virtual void setAdjustedBrushPosition(const QPointF position);
120 virtual void setFollowBrushPosition(bool follow);
121 virtual QPointF getDefaultEditorPosition() const = 0; // Returns standard editor widget position for this assistant
122 virtual QPointF getEditorPosition() const; // Returns editor widget position in document-space coordinates.
123 virtual int numHandles() const = 0;
124
129 virtual bool canBeLocal() const;
134 bool isLocal() const;
139 void setLocal(bool value);
140
145 bool isLocked();
150 void setLocked(bool value);
155 /*The duplication button must be depressed when the user clicks it. This getter function indicates to the
156 render function when the button is clicked*/
157 bool isDuplicating();
162 void setDuplicating(bool value);
163
164 QPointF editorWidgetOffset();
165 void setEditorWidgetOffset(QPointF offset);
166
167 void replaceHandle(KisPaintingAssistantHandleSP _handle, KisPaintingAssistantHandleSP _with);
168 void addHandle(KisPaintingAssistantHandleSP handle, HandleType type);
169
170 QPointF viewportConstrainedEditorPosition(const KisCoordinatesConverter* converter, const QSize editorSize);
171
172 QColor effectiveAssistantColor() const;
173 bool useCustomColor();
174 void setUseCustomColor(bool useCustomColor);
175 void setAssistantCustomColor(QColor color);
176 QColor assistantCustomColor();
177 void setAssistantGlobalColorCache(const QColor &color);
178
179 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);
180 void uncache();
181 const QList<KisPaintingAssistantHandleSP>& handles() const;
183 const QList<KisPaintingAssistantHandleSP>& sideHandles() const;
185
186 QByteArray saveXml( QMap<KisPaintingAssistantHandleSP, int> &handleMap);
187 virtual void saveCustomXml(QXmlStreamWriter* xml); //in case specific assistants have custom properties (like vanishing point)
188
189 void loadXml(KoStore *store, QMap<int, KisPaintingAssistantHandleSP> &handleMap, QString path);
190 virtual bool loadCustomXml(QXmlStreamReader* xml);
191
192 void saveXmlList(QDomDocument& doc, QDomElement& assistantsElement, int count);
193 void findPerspectiveAssistantHandleLocation();
194 KisPaintingAssistantHandleSP oppHandleOne();
195
200 const KisPaintingAssistantHandleSP topLeft() const;
202 const KisPaintingAssistantHandleSP topRight() const;
204 const KisPaintingAssistantHandleSP bottomLeft() const;
205 KisPaintingAssistantHandleSP bottomLeft();
206 const KisPaintingAssistantHandleSP bottomRight() const;
207 KisPaintingAssistantHandleSP bottomRight();
208 const KisPaintingAssistantHandleSP topMiddle() const;
210 const KisPaintingAssistantHandleSP rightMiddle() const;
211 KisPaintingAssistantHandleSP rightMiddle();
212 const KisPaintingAssistantHandleSP leftMiddle() const;
213 KisPaintingAssistantHandleSP leftMiddle();
214 const KisPaintingAssistantHandleSP bottomMiddle() const;
215 KisPaintingAssistantHandleSP bottomMiddle();
216
217
218 // calculates whether a point is near one of the corner points of the assistant
219 // returns: a corner point from the perspective assistant if the given node is close
220 // only called once in code when calculating the perspective assistant
221 KisPaintingAssistantHandleSP closestCornerHandleFromPoint(QPointF point);
222
223 // determines if two points are close to each other
224 // only used by the nodeNearPoint function (perspective grid assistant).
225 bool areTwoPointsClose(const QPointF& pointOne, const QPointF& pointTwo);
226
230 virtual bool isAssistantComplete() const;
231
235 virtual void transform(const QTransform &transform);
236
237public:
241 void drawPath(QPainter& painter, const QPainterPath& path, const KoColorDisplayRendererInterface *displayRenderInterface, bool drawActive=true);
242 void drawPreview(QPainter& painter, const QPainterPath& path, const KoColorDisplayRendererInterface *displayRenderInterface);
243 // draw a path in a red color, signalizing incorrect state
244 void drawError(QPainter& painter, const QPainterPath& path, const KoColorDisplayRendererInterface *displayRenderInterface);
245 // draw a vanishing point marker
246 void drawX(QPainter& painter, const QPointF& pt, const KoColorDisplayRendererInterface *displayRenderInterface);
247 static double norm2(const QPointF& p);
248
249 void setDecorationThickness(int thickness);
250
251protected:
252 explicit KisPaintingAssistant(const KisPaintingAssistant &rhs, QMap<KisPaintingAssistantHandleSP, KisPaintingAssistantHandleSP> &handleMap);
253
254 virtual QRect boundingRect() const;
255
257 virtual void drawCache(QPainter& gc, const KisCoordinatesConverter *converter, const KoColorDisplayRendererInterface *displayRenderInterface, bool assistantVisible=true) = 0;
258
259 void initHandles(QList<KisPaintingAssistantHandleSP> _handles);
261
262 QPointF pixelToView(const QPoint pixelCoords) const;
269 QPointF effectiveBrushPosition(const KisCoordinatesConverter *converter, KisCanvas2 *canvas) const;
270
280 virtual KisPaintingAssistantHandleSP firstLocalHandle() const;
289 virtual KisPaintingAssistantHandleSP secondLocalHandle() const;
298 QRectF getLocalRect() const;
299
300
301public:
305 static QList<KisPaintingAssistantSP> cloneAssistantList(const QList<KisPaintingAssistantSP> &list);
306
307protected:
308 bool m_hasBeenInsideLocalRect {false};
309
310private:
311 struct Private;
312 Private* const d;
313
314};
315
319class KRITAUI_EXPORT KisPaintingAssistantFactory
320{
321public:
324 virtual QString id() const = 0;
325 virtual QString name() const = 0;
327
328};
329
330class KRITAUI_EXPORT KisPaintingAssistantFactoryRegistry : public KoGenericRegistry<KisPaintingAssistantFactory*>
331{
332 public:
335
337
338};
339
340#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