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 = 0x000,
51  Selected = 0x001,
52  Highlighted = 0x002,
53  Invalid = 0x004,
54  FixedPenColor = 0x008,
55  FixedBrushColor = 0x010,
56  AutoRegen = 0x020,
57  AlwaysRegen = 0x040,
58  InheritPen = 0x080,
59  PixelUnit = 0x100,
60  NoClipping = 0x200
61  };
62  Q_DECLARE_FLAGS(Modes, Mode)
63 
64 public:
65  RPainterPath();
66  RPainterPath(const QPainterPath& path);
67  RPainterPath(const RPainterPath& other);
68  virtual ~RPainterPath();
69 
70  void setPath(const QPainterPath& path);
71 
72  QList<QSharedPointer<RShape> > getShapes() const;
73 
74  RVector getCurrentPosition() const {
75  return RVector(currentPosition().x(), currentPosition().y());
76  }
77 
78  bool isAtPosition(const RVector& p, double tolerance = RS::PointTolerance) const;
79 
80  void moveTo(const RVector& v) {
81  QPainterPath::moveTo(v.x, v.y);
82  }
83 
84  void moveToOrNop(const RVector& v) {
85  if (!isAtPosition(v)) {
86  moveTo(v);
87  }
88  }
89 
90  void moveTo(qreal x, qreal y) {
91  QPainterPath::moveTo(x, y);
92  }
93 
97  void moveTo(const QPointF& p) {
98  QPainterPath::moveTo(p);
99  }
100 
101  void lineTo(const RVector& v) {
102  QPainterPath::lineTo(v.x, v.y);
103  }
104 
105  void lineTo(qreal x, qreal y) {
106  QPainterPath::lineTo(x, y);
107  }
108 
112  void lineTo(const QPointF& p) {
113  QPainterPath::lineTo(p);
114  }
115 
116  void quadTo(const RVector& cp, const RVector& v) {
117  QPainterPath::quadTo(cp.x, cp.y, v.x, v.y);
118  }
119 
120  void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty) {
121  QPainterPath::quadTo(ctrlPtx, ctrlPty, endPtx, endPty);
122  }
123 
124  void cubicTo(const RVector& cp1, const RVector& cp2, const RVector& v) {
125  QPainterPath::cubicTo(cp1.x, cp1.y, cp2.x, cp2.y, v.x, v.y);
126  }
127 
128  void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty) {
129  QPainterPath::cubicTo(ctrlPt1x, ctrlPt1y, ctrlPt2x, ctrlPt2y, endPtx, endPty);
130  }
131 
132  void closeSubpath() {
133  QPainterPath::closeSubpath();
134  }
135 
136 // bool contains(const QPointF& point) const {
137 // return QPainterPath::contains(point);
138 // }
139 
140 // bool contains(const QRectF& rectangle) const {
141 // return QPainterPath::contains(rectangle);
142 // }
143 
144 // bool contains(const QPainterPath& p) const {
145 // return QPainterPath::contains(p);
146 // }
147 
148  bool containsPoint(const RVector& v) const {
149  return QPainterPath::contains(QPointF(v.x, v.y));
150  }
151 
152  void addPolyline(const RPolyline& pl);
153  void addPath(const RPainterPath& path);
154  void appendPath(const RPainterPath& path);
155  void addLine(const RLine& line);
156  void addArc(const RArc& arc);
157  void addSpline(const RSpline& spline);
158 
159  void addRect(double x1, double y1, double x2, double y2);
160  void addRect(const QRectF& rect);
161  void addBox(const RBox& box);
162 
163  RBox getBoundingBox() const;
164 
165  RVector getStartPoint() const;
166  RVector getEndPoint() const;
167 
168  bool isValid() const;
169  void setValid(bool on);
170 
171  bool isSane() const;
172 
173  int getZLevel() const;
174  void setZLevel(int zl);
175 
176  //bool hasPen() const;
177  QPen getPen() const;
178  void setPen(const QPen& p);
179 
180  QBrush getBrush() const;
181  void setBrush(const QBrush& b);
182 
183  void setMode(RPainterPath::Mode mode, bool on = true);
184  bool getMode(RPainterPath::Mode mode) const;
185 
186  void setHighlighted(bool on);
187  bool isHighlighted() const;
188 
189  void setSelected(bool on);
190  bool isSelected() const;
191 
192  void setFixedPenColor(bool on);
193  bool isFixedPenColor() const;
194 
195  void setFixedBrushColor(bool on);
196  bool isFixedBrushColor() const;
197 
198  void setAutoRegen(bool on);
199  bool getAutoRegen() const;
200 
201  void setAlwaysRegen(bool on);
202  bool getAlwaysRegen() const;
203 
204  void setInheritPen(bool on);
205  bool getInheritPen() const;
206 
207  void setPixelUnit(bool on);
208  bool getPixelUnit() const;
209 
210  void setNoClipping(bool on);
211  bool getNoClipping() const;
212 
213  void setFeatureSize(double s);
214  double getFeatureSize() const;
215 
216  void setPixelSizeHint(double s);
217  double getPixelSizeHint() const;
218 
219  double getDistanceTo(const RVector& point) const;
220 
221  void addPoint(const RVector& position);
222  bool hasPoints();
223  void setPoints(const QList<RVector>& p);
224  QList<RVector> getPoints() const;
225 
226  void transform(const QTransform& t);
227  void move(const RVector& offset);
228  void rotate(double angle);
229  void scale(double fx, double fy);
230 
231  int getElementCount() const;
232  double getXAt(int i) const;
233  double getYAt(int i) const;
234  QPainterPath::ElementType getTypeAt(int i) const;
235  bool isEmpty() const;
236 
237  void addShape(QSharedPointer<RShape> shape);
238 
239  static void rotateList(QList<RPainterPath>& pps, double angle);
240  static void translateList(QList<RPainterPath>& pps, const RVector& offset);
241  static void scaleList(QList<RPainterPath>& pps, double fx, double fy);
242  static RVector getMinList(QList<RPainterPath>& pps);
243  static RVector getMaxList(QList<RPainterPath>& pps);
244 
245 private:
246  int zLevel;
247  QPen pen;
248  QBrush brush;
249  Modes modes;
250  QList<RVector> points;
251  // < 0 for secondary path (e.g. bounding box of text)
252  double featureSize;
254 };
255 
256 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RPainterPath& p);
257 
258 //QDataStream& operator<< (QDataStream& stream, const RPainterPath& path);
259 //QDataStream& operator>> (QDataStream& stream, RPainterPath& path);
260 QCADCORE_EXPORT bool operator< (const RPainterPath& p1, const RPainterPath& p2);
261 
262 Q_DECLARE_OPERATORS_FOR_FLAGS(RPainterPath::Modes)
269 
270 #endif
Represents a box e.g.
Definition: RBox.h:43
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
void addShape(void shape)
Adds the given RShape to the drawing using current layer and attributes.
Definition: simple_create.js:18
Modes modes
Definition: RPainterPath.h:249
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RSpline.h:56
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, RPainterPath &p)
Stream operator for QDebug.
Definition: RPainterPath.cpp:616
void closeSubpath()
Definition: RPainterPath.h:132
Mode
Definition: RPainterPath.h:49
Low-level mathematical representation of an arc.
Definition: RArc.h:41
bool containsPoint(const RVector &v) const
Definition: RPainterPath.h:148
QBrush brush
Definition: RPainterPath.h:248
#define QCADCORE_EXPORT
Definition: core_global.h:10
void rotate(void e, void angle, void p1, void p2)
Rotates the given entity or shape by the given angle around the given center.
Definition: simple_modify.js:54
void addPolyline(void points, void closed)
Adds a polyline to the drawing.
Definition: simple_create.js:86
void moveToOrNop(const RVector &v)
Definition: RPainterPath.h:84
void addLine(void p1, void p2, void p3, void p4)
Adds a line to the drawing.
Definition: simple_create.js:50
void quadTo(const RVector &cp, const RVector &v)
Definition: RPainterPath.h:116
double pixelSizeHint
Definition: RPainterPath.h:253
void lineTo(qreal x, qreal y)
Definition: RPainterPath.h:105
void move(void e, void p1, void p2)
Moves the given entity or shape by the given offset.
Definition: simple_modify.js:14
double y
Getter function for this property: getY.
Definition: RVector.h:291
int zLevel
Definition: RPainterPath.h:246
void cubicTo(qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty)
Definition: RPainterPath.h:128
void lineTo(const QPointF &p)
Definition: RPainterPath.h:112
void addSpline(void points, void closed)
Adds a spline to the drawing.
Definition: simple_create.js:109
QList< RVector > points
Definition: RPainterPath.h:250
void quadTo(qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty)
Definition: RPainterPath.h:120
void addArc(void p1, void p2, void p3, void p4, void p5, void p6)
Adds an arc to the drawing.
Definition: simple_create.js:61
double featureSize
Definition: RPainterPath.h:252
static const double PointTolerance
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RS.h:551
Q_DECLARE_METATYPE(RMath *)
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:46
void lineTo(const RVector &v)
Definition: RPainterPath.h:101
void moveTo(const RVector &v)
Definition: RPainterPath.h:80
void addPoint(void p1, void p2)
Adds a point to the drawing.
Definition: simple_create.js:72
void scale(void e, void factor, void p1, void p2)
Scales the given entity or shape by the given factor with the given focus point.
Definition: simple_modify.js:27
void moveTo(const QPointF &p)
Definition: RPainterPath.h:97
Low-level mathematical representation of a line.
Definition: RLine.h:42
void moveTo(qreal x, qreal y)
Definition: RPainterPath.h:90
double x
Getter function for this property: getX.
Definition: RVector.h:285
QPen pen
Definition: RPainterPath.h:247
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:50
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:609
Interface for geometrical shape classes.
Definition: RShape.h:52
void cubicTo(const RVector &cp1, const RVector &cp2, const RVector &v)
Definition: RPainterPath.h:124