Krita Source Code Documentation
Loading...
Searching...
No Matches
freehand_stroke.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2011 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef __FREEHAND_STROKE_H
8#define __FREEHAND_STROKE_H
9
10
11#include <QPen>
12#include "kritaui_export.h"
13#include "kis_types.h"
14#include "kis_node.h"
18#include "kis_lod_transform.h"
19#include "KoColor.h"
20
21
22
24{
25public:
26 enum Flag {
27 None = 0x0,
28 SupportsContinuedInterstrokeData = 0x1,
29 SupportsTimedMergeId = 0x2
30 };
31 Q_DECLARE_FLAGS(Flags, Flag)
32
33public:
34 class Data : public KisStrokeJobData {
35 public:
48
49 Data(int _strokeInfoId,
50 const KisPaintInformation &_pi)
51 : KisStrokeJobData(KisStrokeJobData::UNIQUELY_CONCURRENT),
52 strokeInfoId(_strokeInfoId),
53 type(POINT), pi1(_pi)
54 {}
55
56 Data(int _strokeInfoId,
57 const KisPaintInformation &_pi1,
58 const KisPaintInformation &_pi2)
59 : KisStrokeJobData(KisStrokeJobData::UNIQUELY_CONCURRENT),
60 strokeInfoId(_strokeInfoId),
61 type(LINE), pi1(_pi1), pi2(_pi2)
62 {}
63
64 Data(int _strokeInfoId,
65 const KisPaintInformation &_pi1,
66 const QPointF &_control1,
67 const QPointF &_control2,
68 const KisPaintInformation &_pi2)
69 : KisStrokeJobData(KisStrokeJobData::UNIQUELY_CONCURRENT),
70 strokeInfoId(_strokeInfoId),
71 type(CURVE), pi1(_pi1), pi2(_pi2),
72 control1(_control1), control2(_control2)
73 {}
74
75 Data(int _strokeInfoId,
76 DabType _type,
77 const vQPointF &_points)
78 : KisStrokeJobData(KisStrokeJobData::UNIQUELY_CONCURRENT),
79 strokeInfoId(_strokeInfoId),
80 type(_type), points(_points)
81 {}
82
83 Data(int _strokeInfoId,
84 DabType _type,
85 const QRectF &_rect)
86 : KisStrokeJobData(KisStrokeJobData::UNIQUELY_CONCURRENT),
87 strokeInfoId(_strokeInfoId),
88 type(_type), rect(_rect)
89 {}
90
91 Data(int _strokeInfoId,
92 DabType _type,
93 const QPainterPath &_path)
94 : KisStrokeJobData(KisStrokeJobData::UNIQUELY_CONCURRENT),
95 strokeInfoId(_strokeInfoId),
96 type(_type), path(_path)
97 {}
98
99 Data(int _strokeInfoId,
100 DabType _type,
101 const QPainterPath &_path,
102 const QPen &_pen, const KoColor &_customColor)
103 : KisStrokeJobData(KisStrokeJobData::UNIQUELY_CONCURRENT),
104 strokeInfoId(_strokeInfoId),
105 type(_type), path(_path),
106 pen(_pen), customColor(_customColor)
107 {}
108
109 KisStrokeJobData* createLodClone(int levelOfDetail) override {
110 return new Data(*this, levelOfDetail);
111 }
112
113 private:
114 Data(const Data &rhs, int levelOfDetail)
115 : KisStrokeJobData(rhs),
116 strokeInfoId(rhs.strokeInfoId),
117 type(rhs.type)
118 {
119 KisLodTransform t(levelOfDetail);
120
121 switch(type) {
122 case Data::POINT:
123 pi1 = t.map(rhs.pi1);
124 break;
125 case Data::LINE:
126 pi1 = t.map(rhs.pi1);
127 pi2 = t.map(rhs.pi2);
128 break;
129 case Data::CURVE:
130 pi1 = t.map(rhs.pi1);
131 pi2 = t.map(rhs.pi2);
132 control1 = t.map(rhs.control1);
133 control2 = t.map(rhs.control2);
134 break;
135 case Data::POLYLINE:
136 points = t.map(rhs.points);
137 break;
138 case Data::POLYGON:
139 points = t.map(rhs.points);
140 break;
141 case Data::RECT:
142 rect = t.map(rhs.rect);
143 break;
144 case Data::ELLIPSE:
145 rect = t.map(rhs.rect);
146 break;
147 case Data::PAINTER_PATH:
148 path = t.map(rhs.path);
149 break;
150 case Data::QPAINTER_PATH:
151 path = t.map(rhs.path);
152 pen = rhs.pen;
153 break;
154 case Data::QPAINTER_PATH_FILL:
155 path = t.map(rhs.path);
156 pen = rhs.pen;
157 customColor = rhs.customColor;
158 break;
159 };
160 }
161 public:
163
167 QPointF control1;
168 QPointF control2;
169
171 QRectF rect;
172 QPainterPath path;
173 QPen pen;
175 };
176
177public:
179 KisFreehandStrokeInfo *strokeInfo,
180 const KUndo2MagicString &name,
181 Flags flags = None);
182
185 const KUndo2MagicString &name,
186 Flags flags = None);
187
188 ~FreehandStrokeStrategy() override;
189
190 void initStrokeCallback() override;
191 void finishStrokeCallback() override;
192
193 void doStrokeCallback(KisStrokeJobData *data) override;
194
195 KisStrokeStrategy* createLodClone(int levelOfDetail) override;
196
197 void notifyUserStartedStroke() override;
198 void notifyUserEndedStroke() override;
199
200protected:
201 FreehandStrokeStrategy(const FreehandStrokeStrategy &rhs, int levelOfDetail);
202
203private:
204 void init(FreehandStrokeStrategy::Flags flags);
205
206 void tryDoUpdate(bool forceEnd = false);
207 void issueSetDirtySignals();
208
209private:
210 struct Private;
211 const QScopedPointer<Private> m_d;
212};
213
214Q_DECLARE_OPERATORS_FOR_FLAGS(FreehandStrokeStrategy::Flags)
215
216#endif /* __FREEHAND_STROKE_H */
Q_DECLARE_FLAGS(KisUpdaterContextSnapshotEx, KisUpdaterContextSnapshotExTag)
Data(int _strokeInfoId, const KisPaintInformation &_pi1, const QPointF &_control1, const QPointF &_control2, const KisPaintInformation &_pi2)
Data(int _strokeInfoId, const KisPaintInformation &_pi)
Data(int _strokeInfoId, DabType _type, const vQPointF &_points)
Data(int _strokeInfoId, DabType _type, const QRectF &_rect)
Data(const Data &rhs, int levelOfDetail)
KisStrokeJobData * createLodClone(int levelOfDetail) override
Data(int _strokeInfoId, DabType _type, const QPainterPath &_path)
Data(int _strokeInfoId, const KisPaintInformation &_pi1, const KisPaintInformation &_pi2)
Data(int _strokeInfoId, DabType _type, const QPainterPath &_path, const QPen &_pen, const KoColor &_customColor)
const QScopedPointer< Private > m_d
KisPaintInformation map(KisPaintInformation pi) const
void doStrokeCallback(KisStrokeJobData *data) override
virtual void notifyUserEndedStroke()
virtual void notifyUserStartedStroke()
virtual KisStrokeStrategy * createLodClone(int levelOfDetail)
Q_DECLARE_OPERATORS_FOR_FLAGS(KisBaseRectsWalker::SubtreeVisitFlags)