QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
RPainterPath.h
Go to the documentation of this file.
1
20#ifndef RPAINTERPATH_H
21#define RPAINTERPATH_H
22
23#include "core_global.h"
24
25#include <QBrush>
26#include <QFlags>
27#include <QPainterPath>
28#include <QPen>
29#include <QSharedPointer>
30
31#include "RVector.h"
32
33class RArc;
34class RBox;
35class RLine;
36class RShape;
37class RSpline;
38class RPolyline;
39
40
48class QCADCORE_EXPORT RPainterPath : public QPainterPath {
49
50public:
51 enum Mode {
52 NoModes = 0x0000,
53 Selected = 0x0001,
54 Highlighted = 0x0002,
55 Invalid = 0x0004,
56 FixedPenColor = 0x0008,
57 FixedBrushColor = 0x0010,
58 AutoRegen = 0x0020,
59 AlwaysRegen = 0x0040,
60 InheritPen = 0x0080,
61 PixelUnit = 0x0100,
62 NoClipping = 0x0200,
63 PixelWidth = 0x0400,
64 NoColorMode = 0x0800,
65 SimplePointDisplay = 0x1000,
66 PolylineGen = 0x2000,
67 NoPattern = 0x4000,
68 ScreenBasedLinetype = 0x8000,
69 Wipeout = 0x10000,
70 Frameless = 0x20000
71 };
72 Q_DECLARE_FLAGS(Modes, Mode)
73
74public:
76 RPainterPath(const QPainterPath& path);
77 RPainterPath(const RPainterPath& other);
78 virtual ~RPainterPath();
79
80 void setPath(const QPainterPath& path);
81
82 QList<QSharedPointer<RShape> > getShapes() const;
83
85 return RVector(currentPosition().x(), currentPosition().y());
86 }
87
88 bool isAtPosition(const RVector& p, double tolerance = RS::PointTolerance) const;
89
90 void moveTo(const RVector& v) {
91 QPainterPath::moveTo(v.x, v.y);
92 }
93
94 void moveToOrNop(const RVector& v) {
95 if (!isAtPosition(v)) {
96 moveTo(v);
97 }
98 }
99
100 void moveTo(qreal x, qreal y) {
101 QPainterPath::moveTo(x, y);
102 }
103
107 void moveTo(const QPointF& p) {
108 QPainterPath::moveTo(p);
109 }
110
111 void lineTo(const RVector& v) {
112 QPainterPath::lineTo(v.x, v.y);
113 }
114
115 void lineTo(qreal x, qreal y) {
116 QPainterPath::lineTo(x, y);
117 }
118
122 void lineTo(const QPointF& p) {
123 QPainterPath::lineTo(p);
124 }
125
126 void quadTo(const RVector& cp, const RVector& v) {
127 QPainterPath::quadTo(cp.x, cp.y, v.x, v.y);
128 }
129
130 void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty) {
131 QPainterPath::quadTo(ctrlPtx, ctrlPty, endPtx, endPty);
132 }
133
134 void cubicTo(const RVector& cp1, const RVector& cp2, const RVector& v) {
135 QPainterPath::cubicTo(cp1.x, cp1.y, cp2.x, cp2.y, v.x, v.y);
136 }
137
138 void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty) {
139 QPainterPath::cubicTo(ctrlPt1x, ctrlPt1y, ctrlPt2x, ctrlPt2y, endPtx, endPty);
140 }
141
143 QPainterPath::closeSubpath();
144 }
145
146// bool contains(const QPointF& point) const {
147// return QPainterPath::contains(point);
148// }
149
150// bool contains(const QRectF& rectangle) const {
151// return QPainterPath::contains(rectangle);
152// }
153
154// bool contains(const QPainterPath& p) const {
155// return QPainterPath::contains(p);
156// }
157
158 bool containsPoint(const RVector& v) const {
159 return QPainterPath::contains(QPointF(v.x, v.y));
160 }
161
162 void addPolyline(const RPolyline& pl);
163 void addPath(const RPainterPath& path);
164 void appendPath(const RPainterPath& path);
165 void addLine(const RLine& line);
166 void addArc(const RArc& arc);
167 void addSpline(const RSpline& spline);
168
169 void addRect(double x1, double y1, double x2, double y2);
170 void addRect(const QRectF& rect);
171 void addBox(const RBox& box);
172
173 RBox getBoundingBox() const;
174
175 RVector getStartPoint() const;
176 RVector getEndPoint() const;
177
178 bool isValid() const;
179 void setValid(bool on);
180
181 bool isSane() const;
182
183 int getZLevel() const;
184 void setZLevel(int zl);
185
186 //bool hasPen() const;
187 QPen getPen() const;
188 void setPen(const QPen& p);
189
190 QBrush getBrush() const;
191 void setBrush(const QBrush& b);
192
193 void setMode(RPainterPath::Mode mode, bool on = true);
194 bool getMode(RPainterPath::Mode mode) const;
195
196 void setHighlighted(bool on);
197 bool isHighlighted() const;
198
199 void setSelected(bool on);
200 bool isSelected() const;
201
202 void setFixedPenColor(bool on);
203 bool isFixedPenColor() const;
204
205 void setFixedBrushColor(bool on);
206 bool isFixedBrushColor() const;
207
208 void setAutoRegen(bool on);
209 bool getAutoRegen() const;
210
211 void setAlwaysRegen(bool on);
212 bool getAlwaysRegen() const;
213
214 void setInheritPen(bool on);
215 bool getInheritPen() const;
216
217 void setPixelUnit(bool on);
218 bool getPixelUnit() const;
219
220 void setNoClipping(bool on);
221 bool getNoClipping() const;
222
223 void setNoColorMode(bool on);
224 bool getNoColorMode() const;
225
226 void setSimplePointDisplay(bool on);
227 bool getSimplePointDisplay() const;
228
229 void setPolylineGen(bool on);
230 bool getPolylineGen() const;
231
232 void setNoPattern(bool on);
233 bool getNoPattern() const;
234
235 void setScreenBasedLinetype(bool on);
236 bool getScreenBasedLinetype() const;
237
238 void setWipeout(bool on);
239 bool getWipeout() const;
240
241 void setFrameless(bool on);
242 bool getFrameless() const;
243
244 void setPixelWidth(bool on);
245 bool getPixelWidth() const;
246
247 void setFeatureSize(double s);
248 double getFeatureSize() const;
249
250 void setPixelSizeHint(double s);
251 double getPixelSizeHint() const;
252
253 double getDistanceTo(const RVector& point) const;
254
255 void addPoint(const RVector& position);
256 bool hasPoints();
257 void setPoints(const QList<RVector>& p);
258 QList<RVector> getPoints() const;
259
260 void transform(const QTransform& t);
261 void move(const RVector& offset);
262 void rotate(double angle);
263 void scale(double fx, double fy);
264
265 int getElementCount() const;
266 double getXAt(int i) const;
267 double getYAt(int i) const;
268 QPainterPath::ElementType getTypeAt(int i) const;
269 bool isEmpty() const;
270
271 void addShape(QSharedPointer<RShape> shape);
272
273 void addOriginalShape(QSharedPointer<RShape> shape);
274 bool hasOriginalShapes() const;
275 int countOriginalShapes() const;
276 QSharedPointer<RShape> getOriginalShape(int i) const;
277
278#if QT_VERSION >= 0x060000
283 RPainterPath copy() const {
284 return *this;
285 }
286#endif
287
288 static void rotateList(QList<RPainterPath>& pps, double angle);
289 static void translateList(QList<RPainterPath>& pps, const RVector& offset);
290 static void scaleList(QList<RPainterPath>& pps, double fx, double fy);
291 static RVector getMinList(QList<RPainterPath>& pps);
292 static RVector getMaxList(QList<RPainterPath>& pps);
293
294private:
296 QPen pen;
297 QBrush brush;
298 Modes modes;
299 QList<RVector> points;
300 // < 0 for secondary path (e.g. bounding box of text)
303 QList<QSharedPointer<RShape> > originalShapes;
304};
305
306QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RPainterPath& p);
307
308//QDataStream& operator<< (QDataStream& stream, const RPainterPath& path);
309//QDataStream& operator>> (QDataStream& stream, RPainterPath& path);
310QCADCORE_EXPORT bool operator< (const RPainterPath& p1, const RPainterPath& p2);
311
312Q_DECLARE_OPERATORS_FOR_FLAGS(RPainterPath::Modes)
315Q_DECLARE_METATYPE(QList<RPainterPath>)
316Q_DECLARE_METATYPE(QList<RPainterPath>*)
319
320#endif
Q_DECLARE_METATYPE(RMath *)
QCADCORE_EXPORT bool operator<(const RPainterPath &p1, const RPainterPath &p2)
This operator allows us to sort painter paths based on z-level.
Definition RPainterPath.cpp:765
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RPainterPath &p)
Stream operator for QDebug.
Definition RPainterPath.cpp:772
int i
Copyright (c) 2011-2018 by Andrew Mustun.
Definition autostart.js:32
Low-level mathematical representation of an arc.
Definition RArc.h:42
Represents a box e.g.
Definition RBox.h:46
Low-level mathematical representation of a line.
Definition RLine.h:41
Extended painter path with a z-level and a pen.
Definition RPainterPath.h:48
QList< QSharedPointer< RShape > > originalShapes
Definition RPainterPath.h:303
void lineTo(const RVector &v)
Definition RPainterPath.h:111
void moveTo(const QPointF &p)
Definition RPainterPath.h:107
void cubicTo(const RVector &cp1, const RVector &cp2, const RVector &v)
Definition RPainterPath.h:134
void quadTo(const RVector &cp, const RVector &v)
Definition RPainterPath.h:126
double pixelSizeHint
Definition RPainterPath.h:302
QList< RVector > points
Definition RPainterPath.h:299
void lineTo(const QPointF &p)
Definition RPainterPath.h:122
double featureSize
Definition RPainterPath.h:301
void moveTo(const RVector &v)
Definition RPainterPath.h:90
Mode
Definition RPainterPath.h:51
QPen pen
Definition RPainterPath.h:296
RVector getCurrentPosition() const
Definition RPainterPath.h:84
int zLevel
Definition RPainterPath.h:295
void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty)
Definition RPainterPath.h:138
void moveTo(qreal x, qreal y)
Definition RPainterPath.h:100
bool containsPoint(const RVector &v) const
Definition RPainterPath.h:158
Modes modes
Definition RPainterPath.h:298
void lineTo(qreal x, qreal y)
Definition RPainterPath.h:115
void moveToOrNop(const RVector &v)
Definition RPainterPath.h:94
QBrush brush
Definition RPainterPath.h:297
void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty)
Definition RPainterPath.h:130
void closeSubpath()
Definition RPainterPath.h:142
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition RPolyline.h:50
static const double PointTolerance
Copyright (c) 2011-2018 by Andrew Mustun.
Definition RS.h:920
Interface for geometrical shape classes.
Definition RShape.h:72
Low-level mathematical representation of a spline.
Definition RSpline.h:59
Represents a 3d vector (x/y/z).
Definition RVector.h:47
double x
Getter function for this property: getX Setter function for this property: setX
Definition RVector.h:313
double y
Getter function for this property: getY Setter function for this property: setY
Definition RVector.h:319
#define QCADCORE_EXPORT
Definition core_global.h:10
void addSpline(void points, void closed)
Adds a spline to the drawing.
Definition simple_create.js:15
void addPolyline(void points, void closed, void relative)
Adds a polyline to the drawing.
Definition simple_create.js:79
void addArc(void center, void radius, void startAngle, void endAngle, void reversed)
Adds an arc to the drawing.
Definition simple_create.js:109
void rotate(void e, void angle, void center)
Rotates the given entity or shape by the given angle around the given center.
Definition simple_modify.js:109
void move(void e, void offset)
Moves the given entity or shape by the given offset.
Definition simple_modify.js:58
void scale(void e, void factor, void focusPoint)
Scales the given entity or shape by the given factor with the given focus point.
Definition simple_modify.js:15
void addShape(void shape, void color, void linetype, void lineweight)
Adds the given RShape to the drawing as a new entity using current layer and attributes.
Definition simple_create.js:50
void addPoint(void position)
Adds a point to the drawing.
Definition simple_create.js:210
void addLine(void startPoint, void endPoint)
Adds a line to the drawing.
Definition simple_create.js:198
char s
Definition opennurbs_string.cpp:32