Swiftray  1.0
shape.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QPainter>
4 #include <QPainterPath>
5 #include <QRectF>
6 
7 using namespace std;
8 
9 class Layer;
10 
11 class DocumentSerializer;
12 
17 class Shape {
18 public:
19  enum class Type {
20  None, Path, Bitmap, Text, Group
21  };
22 
23  Shape() noexcept;
24 
25  virtual ~Shape();
26 
27  // General attributes
28  bool selected() const;
29 
30  Layer *layer() const;
31 
32  QPointF pos() const;
33 
34  qreal rotation() const;
35 
36  qreal x() const;
37 
38  qreal y() const;
39 
40  Shape *parent() const;
41 
42  void setRotation(qreal r);
43 
44  void setLayer(Layer *layer);
45 
46  void setSelected(bool selected);
47 
48  void setParent(Shape *parent);
49 
50 
51  // Bounding box
52  QRectF boundingRect() const;
53 
54  QPolygonF rotatedBBox() const;
55 
56  void flushCache();
57 
61  const QTransform &transform() const;
62 
63  const QTransform &tempTransform() const;
64 
68  QTransform globalTransform() const;
69 
74  void applyTransform(const QTransform &transform);
75 
80  void setTransform(const QTransform &transform);
81 
86  void setTempTransform(const QTransform &transform);
87 
88  bool hasLayer() const;
89 
90  bool isParentSelected() const;
91 
93  bool isLayerLocked() const;
94 
95  virtual shared_ptr<Shape> clone() const;
96 
97  virtual bool hitTest(QPointF global_coord, qreal tolerance) const;
98 
99  virtual bool hitTest(QRectF global_coord_rect) const;
100 
101  virtual void paint(QPainter *painter) const;
102 
104  virtual Type type() const;
105 
106  virtual operator QString();
107 
108  friend class DocumentSerializer;
109 
110 protected:
112  virtual void calcBoundingBox() const;
113 
114 private:
116  Layer *layer_;
118  Shape *parent_;
120  qreal rotation_;
122  mutable bool bbox_need_recalc_;
123 
124 protected:
126  QTransform temp_transform_;
128  QTransform transform_;
130  mutable QPolygonF rotated_bbox_;
132  mutable QRectF bbox_;
134  bool selected_;
135 };
136 
137 typedef shared_ptr<Shape> ShapePtr;
Save and load documents as binary format.
Definition: document-serializer.h:18
Definition: layer.h:10
A base class for shape objects that contains transform and parent information.
Definition: shape.h:17
Type
Definition: shape.h:19
shared_ptr< Shape > ShapePtr
Definition: shape.h:137