Swiftray  1.0
cache-stack.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QDebug>
4 #include <QList>
5 #include <shape/path-shape.h>
6 
7 class GroupShape;
8 
9 class Document;
10 
11 class Canvas;
12 
13 // Rewrite to support transform dirty or content dirty, transform dirty does not require heavy recalculation
14 class CacheStack {
15 public:
16  // Cache groups of shapes with similar properties
17  class Cache {
18  public:
19  enum class Type {
22  SelectedFilledPaths, // Compatible mode with mixed layer, could be deprecated
23  NonSelectedFilledPaths, // Compatible mode with mixed layer, could be deprecated
24  Bitmap,
25  Group
26  };
27 
28  Cache(CacheStack *stack, Type type);
29 
30  void merge(const QTransform &global_transform);
31 
32  Cache::Type type() const;
33 
34  const QList<Shape *> &shapes() const;
35 
36  // CacheFragment add shape
37  void addShape(Shape *shape);
38 
39  void cacheFill();
40 
41  // Painting functions
42  void stroke(QPainter *painter, const QPen &pen);
43 
44  void fill(QPainter *painter, const QPen &pen);
45 
46  private:
47  /* Main properties */
48  QList<Shape *> shapes_;
49  CacheStack *stack_;
50  Type type_;
51 
52  /* Cache properties */
53  QRectF bbox_;
54  QPixmap cache_pixmap_;
55  bool is_fill_cached_;
56  QPainterPath joined_path_;
57  };
58 
59  CacheStack(GroupShape *group);
60 
61  CacheStack(Layer *layer);
62 
63  void update();
64 
65  int paint(QPainter *painter);
66 
67  bool isGroup() const;
68 
69  bool isLayer() const;
70 
71  const Canvas &canvas() const;
72 
73  const Document &document() const;
74 
75  const QColor &color() const;
76 
77 
78 private:
79  // Categorize the shapes to different cache group
80  void addShape(Shape *shape);
81 
82  enum class Type {
83  Layer,
84  Group
85  };
86 
87  Type type_;
88  GroupShape *group_;
89  Layer *layer_;
90  QTransform global_transform_;
91  QList<Cache> caches_;
92 };
93 
CacheStack::Cache::Type CacheType
Definition: cache-stack.h:94
Definition: cache-stack.h:17
Cache(CacheStack *stack, Type type)
Definition: cache-stack.cpp:82
void merge(const QTransform &global_transform)
Definition: cache-stack.cpp:93
void cacheFill()
Definition: cache-stack.cpp:107
Type
Definition: cache-stack.h:19
void fill(QPainter *painter, const QPen &pen)
Definition: cache-stack.cpp:133
Cache::Type type() const
Definition: cache-stack.cpp:197
void stroke(QPainter *painter, const QPen &pen)
Definition: cache-stack.cpp:129
const QList< Shape * > & shapes() const
Definition: cache-stack.cpp:201
void addShape(Shape *shape)
Definition: cache-stack.cpp:88
Definition: cache-stack.h:14
bool isGroup() const
Definition: cache-stack.cpp:205
CacheStack(GroupShape *group)
Definition: cache-stack.cpp:9
bool isLayer() const
Definition: cache-stack.cpp:209
int paint(QPainter *painter)
Definition: cache-stack.cpp:144
const QColor & color() const
Definition: cache-stack.cpp:217
const Document & document() const
Definition: cache-stack.cpp:215
const Canvas & canvas() const
Definition: cache-stack.cpp:213
void update()
Definition: cache-stack.cpp:19
Definition: canvas.h:27
Document state store for layers, shapes, document specfic settings and current view state.
Definition: document.h:19
Definition: group-shape.h:8
Definition: layer.h:10
A base class for shape objects that contains transform and parent information.
Definition: shape.h:17