Swiftray  1.0
layer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <shape/shape.h>
4 #include <canvas/cache-stack.h>
5 
6 class Document;
7 
9 
10 class Layer {
11 public:
12  enum class Type {
13  Line,
14  Fill,
15  FillLine,
16  Mixed // Compatible mode with Beam Studio, could be deprecated in the future
17  };
18 
21  Layer(Document *doc, const QColor &color, const QString &name);
22 
23  Layer(Document *doc, int layer_id);
24 
25  Layer(Document *doc);
26 
27  Layer();
28 
29 
30  ~Layer();
31 
32  int paint(QPainter *painter) const;
33 
34  // Add ShapePtr to children array
35  void addShape(const ShapePtr &shape);
36 
37  // Return children array
38  QList<ShapePtr> &children();
39 
40  // Clone the children and the layer itself
41  shared_ptr<Layer> clone();
42 
43  // Remove specific ShapePtr
44  void removeShape(const ShapePtr &shape);
45 
46  // Cache functions
47  void flushCache();
48 
51  const QColor &color() const;
52 
53  const QString &name() const;
54 
55  Type type() const;
56 
57  bool isLocked() const;
58 
59  bool isVisible() const;
60 
61  bool isUseDiode() const;
62 
63  int repeat() const;
64 
65  int speed() const;
66 
67  int power() const;
68 
69  double stepHeight() const;
70 
71  double targetHeight() const;
72 
73  Document &document();
74 
75 
78  void setColor(const QColor &color);
79 
80  void setUseDiode(bool is_diode);
81 
82  void setTargetHeight(double height);
83 
84  void setName(const QString &name);
85 
86  void setRepeat(int repeat);
87 
88  void setSpeed(int speed);
89 
90  void setStrength(int strength);
91 
92  void setType(Type type);
93 
94  void setLocked(bool isLocked);
95 
96  void setVisible(bool visible);
97 
98  void setStepHeight(double step_height);
99 
100  void setDocument(Document *doc);
101 
102  void setLayerCounter(int i);
103 
104  friend class DocumentSerializer;
105 
106 private:
108  Document *document_;
109  QColor color_;
110  QString name_;
111  QList<ShapePtr> children_;
112  Type type_;
113  bool use_diode_;
114  bool is_locked_;
115  bool is_visible_;
116  double target_height_;
117  double step_height_;
118  int repeat_;
119  int speed_;
120  int power_;
121 
123  mutable bool cache_valid_;
124  mutable unique_ptr<CacheStack> cache_;
125 };
126 
127 typedef shared_ptr<Layer> LayerPtr;
Document state store for layers, shapes, document specfic settings and current view state.
Definition: document.h:19
Save and load documents as binary format.
Definition: document-serializer.h:18
Definition: layer.h:10
Layer(Document *doc)
void setLayerCounter(int i)
void setDocument(Document *doc)
Definition: layer.cpp:166
Document & document()
Definition: layer.cpp:110
shared_ptr< Layer > clone()
Definition: layer.cpp:172
int paint(QPainter *painter) const
Definition: layer.cpp:42
void setVisible(bool visible)
Definition: layer.cpp:124
double stepHeight() const
Definition: layer.cpp:104
double targetHeight() const
Definition: layer.cpp:106
void setRepeat(int repeat)
Definition: layer.cpp:154
void setStrength(int strength)
Definition: layer.cpp:150
void setType(Type type)
Definition: layer.cpp:133
int repeat() const
Definition: layer.cpp:72
void setSpeed(int speed)
Definition: layer.cpp:146
void setLocked(bool isLocked)
Definition: layer.cpp:120
int power() const
Definition: layer.cpp:80
void setName(const QString &name)
Definition: layer.cpp:142
bool isLocked() const
Definition: layer.cpp:88
bool isUseDiode() const
Definition: layer.cpp:96
Layer()
Definition: layer.cpp:37
void setStepHeight(double step_height)
Definition: layer.cpp:162
int speed() const
Definition: layer.cpp:76
Type
Definition: layer.h:12
const QString & name() const
Definition: layer.cpp:84
QList< ShapePtr > & children()
Definition: layer.cpp:70
void flushCache()
Definition: layer.cpp:100
void addShape(const ShapePtr &shape)
Definition: layer.cpp:53
Type type() const
Definition: layer.cpp:108
void removeShape(const ShapePtr &shape)
Definition: layer.cpp:59
const QColor & color() const
Definition: layer.cpp:68
void setUseDiode(bool is_diode)
Definition: layer.cpp:158
void setColor(const QColor &color)
Definition: layer.cpp:128
bool isVisible() const
Definition: layer.cpp:92
void setTargetHeight(double height)
Definition: layer.cpp:138
shared_ptr< Layer > LayerPtr
Definition: layer.h:127
shared_ptr< Shape > ShapePtr
Definition: shape.h:137