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