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