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  };
65  Q_DECLARE_FLAGS(Modes, Mode)
66 
67 public:
68  RPainterPath();
69  RPainterPath(const QPainterPath& path);
70  RPainterPath(const RPainterPath& other);
71  virtual ~RPainterPath();
72 
73  void setPath(const QPainterPath& path);
74 
75  QList<QSharedPointer<RShape> > getShapes() const;
76 
78  return RVector(currentPosition().x(), currentPosition().y());
79  }
80 
81  bool isAtPosition(const RVector& p, double tolerance = RS::PointTolerance) const;
82 
83  void moveTo(const RVector& v) {
84  QPainterPath::moveTo(v.x, v.y);
85  }
86 
87  void moveToOrNop(const RVector& v) {
88  if (!isAtPosition(v)) {
89  moveTo(v);
90  }
91  }
92 
93  void moveTo(qreal x, qreal y) {
94  QPainterPath::moveTo(x, y);
95  }
96 
100  void moveTo(const QPointF& p) {
101  QPainterPath::moveTo(p);
102  }
103 
104  void lineTo(const RVector& v) {
105  QPainterPath::lineTo(v.x, v.y);
106  }
107 
108  void lineTo(qreal x, qreal y) {
109  QPainterPath::lineTo(x, y);
110  }
111 
115  void lineTo(const QPointF& p) {
116  QPainterPath::lineTo(p);
117  }
118 
119  void quadTo(const RVector& cp, const RVector& v) {
120  QPainterPath::quadTo(cp.x, cp.y, v.x, v.y);
121  }
122 
123  void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty) {
124  QPainterPath::quadTo(ctrlPtx, ctrlPty, endPtx, endPty);
125  }
126 
127  void cubicTo(const RVector& cp1, const RVector& cp2, const RVector& v) {
128  QPainterPath::cubicTo(cp1.x, cp1.y, cp2.x, cp2.y, v.x, v.y);
129  }
130 
131  void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty) {
132  QPainterPath::cubicTo(ctrlPt1x, ctrlPt1y, ctrlPt2x, ctrlPt2y, endPtx, endPty);
133  }
134 
135  void closeSubpath() {
136  QPainterPath::closeSubpath();
137  }
138 
139 // bool contains(const QPointF& point) const {
140 // return QPainterPath::contains(point);
141 // }
142 
143 // bool contains(const QRectF& rectangle) const {
144 // return QPainterPath::contains(rectangle);
145 // }
146 
147 // bool contains(const QPainterPath& p) const {
148 // return QPainterPath::contains(p);
149 // }
150 
151  bool containsPoint(const RVector& v) const {
152  return QPainterPath::contains(QPointF(v.x, v.y));
153  }
154 
155  void addPolyline(const RPolyline& pl);
156  void addPath(const RPainterPath& path);
157  void appendPath(const RPainterPath& path);
158  void addLine(const RLine& line);
159  void addArc(const RArc& arc);
160  void addSpline(const RSpline& spline);
161 
162  void addRect(double x1, double y1, double x2, double y2);
163  void addRect(const QRectF& rect);
164  void addBox(const RBox& box);
165 
166  RBox getBoundingBox() const;
167 
168  RVector getStartPoint() const;
169  RVector getEndPoint() const;
170 
171  bool isValid() const;
172  void setValid(bool on);
173 
174  bool isSane() const;
175 
176  int getZLevel() const;
177  void setZLevel(int zl);
178 
179  //bool hasPen() const;
180  QPen getPen() const;
181  void setPen(const QPen& p);
182 
183  QBrush getBrush() const;
184  void setBrush(const QBrush& b);
185 
186  void setMode(RPainterPath::Mode mode, bool on = true);
187  bool getMode(RPainterPath::Mode mode) const;
188 
189  void setHighlighted(bool on);
190  bool isHighlighted() const;
191 
192  void setSelected(bool on);
193  bool isSelected() const;
194 
195  void setFixedPenColor(bool on);
196  bool isFixedPenColor() const;
197 
198  void setFixedBrushColor(bool on);
199  bool isFixedBrushColor() const;
200 
201  void setAutoRegen(bool on);
202  bool getAutoRegen() const;
203 
204  void setAlwaysRegen(bool on);
205  bool getAlwaysRegen() const;
206 
207  void setInheritPen(bool on);
208  bool getInheritPen() const;
209 
210  void setPixelUnit(bool on);
211  bool getPixelUnit() const;
212 
213  void setNoClipping(bool on);
214  bool getNoClipping() const;
215 
216  void setNoColorMode(bool on);
217  bool getNoColorMode() const;
218 
219  void setSimplePointDisplay(bool on);
220  bool getSimplePointDisplay() const;
221 
222  void setPixelWidth(bool on);
223  bool getPixelWidth() const;
224 
225  void setFeatureSize(double s);
226  double getFeatureSize() const;
227 
228  void setPixelSizeHint(double s);
229  double getPixelSizeHint() const;
230 
231  double getDistanceTo(const RVector& point) const;
232 
233  void addPoint(const RVector& position);
234  bool hasPoints();
235  void setPoints(const QList<RVector>& p);
236  QList<RVector> getPoints() const;
237 
238  void transform(const QTransform& t);
239  void move(const RVector& offset);
240  void rotate(double angle);
241  void scale(double fx, double fy);
242 
243  int getElementCount() const;
244  double getXAt(int i) const;
245  double getYAt(int i) const;
246  QPainterPath::ElementType getTypeAt(int i) const;
247  bool isEmpty() const;
248 
249  void addShape(QSharedPointer<RShape> shape);
250 
251  void addOriginalShape(QSharedPointer<RShape> shape);
252  bool hasOriginalShapes() const;
253  int countOriginalShapes() const;
254  QSharedPointer<RShape> getOriginalShape(int i) const;
255 
256  static void rotateList(QList<RPainterPath>& pps, double angle);
257  static void translateList(QList<RPainterPath>& pps, const RVector& offset);
258  static void scaleList(QList<RPainterPath>& pps, double fx, double fy);
259  static RVector getMinList(QList<RPainterPath>& pps);
260  static RVector getMaxList(QList<RPainterPath>& pps);
261 
262 private:
263  int zLevel;
264  QPen pen;
265  QBrush brush;
266  Modes modes;
267  QList<RVector> points;
268  // < 0 for secondary path (e.g. bounding box of text)
269  double featureSize;
271  QList<QSharedPointer<RShape> > originalShapes;
272 };
273 
274 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RPainterPath& p);
275 
276 //QDataStream& operator<< (QDataStream& stream, const RPainterPath& path);
277 //QDataStream& operator>> (QDataStream& stream, RPainterPath& path);
278 QCADCORE_EXPORT bool operator< (const RPainterPath& p1, const RPainterPath& p2);
279 
280 Q_DECLARE_OPERATORS_FOR_FLAGS(RPainterPath::Modes)
283 Q_DECLARE_METATYPE(QList<RPainterPath>)
284 Q_DECLARE_METATYPE(QList<RPainterPath>*)
287 
288 #endif
addPoint
void addPoint(void position)
Adds a point to the drawing.
Definition: simple_create.js:147
RPainterPath::moveTo
void moveTo(qreal x, qreal y)
Definition: RPainterPath.h:93
RPainterPath::cubicTo
void cubicTo(const RVector &cp1, const RVector &cp2, const RVector &v)
Definition: RPainterPath.h:127
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:104
RPainterPath::moveToOrNop
void moveToOrNop(const RVector &v)
Definition: RPainterPath.h:87
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:32
RS::PointTolerance
static const double PointTolerance
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: RS.h:696
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:182
i
int i
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: autostart.js:21
RPainterPath::moveTo
void moveTo(const RVector &v)
Definition: RPainterPath.h:83
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:123
addArc
void addArc(void center, void radius, void startAngle, void endAngle, void reversed)
Adds an arc to the drawing.
Definition: simple_create.js:22
addLine
void addLine(void startPoint, void endPoint)
Adds a line to the drawing.
Definition: simple_create.js:168
RLine
Low-level mathematical representation of a line.
Definition: RLine.h:41
RPainterPath::modes
Modes modes
Definition: RPainterPath.h:266
RPainterPath::lineTo
void lineTo(qreal x, qreal y)
Definition: RPainterPath.h:108
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:264
RPainterPath::cubicTo
void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty)
Definition: RPainterPath.h:131
RPainterPath::originalShapes
QList< QSharedPointer< RShape > > originalShapes
Definition: RPainterPath.h:271
RPainterPath::brush
QBrush brush
Definition: RPainterPath.h:265
RPainterPath::moveTo
void moveTo(const QPointF &p)
Definition: RPainterPath.h:100
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:723
addSpline
void addSpline(void points, void closed)
Adds a spline to the drawing.
Definition: simple_create.js:48
RPainterPath::points
QList< RVector > points
Definition: RPainterPath.h:267
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:77
RPainterPath::containsPoint
bool containsPoint(const RVector &v) const
Definition: RPainterPath.h:151
RPainterPath::zLevel
int zLevel
Definition: RPainterPath.h:263
RPainterPath::lineTo
void lineTo(const QPointF &p)
Definition: RPainterPath.h:115
RPainterPath::featureSize
double featureSize
Definition: RPainterPath.h:269
RPainterPath::closeSubpath
void closeSubpath()
Definition: RPainterPath.h:135
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:104
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:60
RPainterPath::quadTo
void quadTo(const RVector &cp, const RVector &v)
Definition: RPainterPath.h:119
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:46
RPainterPath::pixelSizeHint
double pixelSizeHint
Definition: RPainterPath.h:270
operator<<
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RPainterPath &p)
Stream operator for QDebug.
Definition: RPainterPath.cpp:730