Swiftray  1.0
path-edit.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QMouseEvent>
5 #include <shape/path-shape.h>
6 
7 namespace Controls {
8 
9  class PathEdit : public CanvasControl {
10  public:
11  class PathNode {
12  public:
14  bool selected;
15 
16  PathNode(PathShape::NodeType node_type) : type{node_type} {};
17  };
18 
19  PathEdit(Canvas *canvas) noexcept;
20 
21  bool mousePressEvent(QMouseEvent *e) override;
22 
23  bool mouseMoveEvent(QMouseEvent *e) override;
24 
25  bool mouseReleaseEvent(QMouseEvent *e) override;
26 
27  bool hoverEvent(QHoverEvent *e, Qt::CursorShape *cursor) override;
28 
29  bool keyPressEvent(QKeyEvent *e) override;
30 
31  void paint(QPainter *painter) override;
32 
33  bool isActive() override;
34 
35  void moveElementTo(int index, QPointF local_coord);
36 
37  void exit() override;
38 
39  int hitTest(QPointF canvas_coord);
40 
41  qreal distance(QPointF point);
42 
43  PathShape &target();
44 
45  QPointF getLocalCoord(QPointF canvas_coord);
46 
47  void setTarget(ShapePtr &target);
48 
49  const QPainterPath &path() const;
50 
51  void setPath(const QPainterPath &path);
52 
53  private:
54  ShapePtr target_;
55  QPainterPath path_;
56  int dragging_index_;
57  bool is_closed_shape_;
58  QList<PathNode> cache_;
59  };
60 
61 }
Definition: canvas.h:27
Definition: canvas-control.h:16
Canvas & canvas()
Definition: canvas-control.cpp:34
Definition: path-edit.h:11
bool selected
Definition: path-edit.h:14
PathShape::NodeType type
Definition: path-edit.h:13
PathNode(PathShape::NodeType node_type)
Definition: path-edit.h:16
Definition: path-edit.h:9
void setTarget(ShapePtr &target)
Definition: path-edit.cpp:215
bool hoverEvent(QHoverEvent *e, Qt::CursorShape *cursor) override
Definition: path-edit.cpp:110
bool isActive() override
Definition: path-edit.cpp:19
void setPath(const QPainterPath &path)
Definition: path-edit.cpp:251
bool keyPressEvent(QKeyEvent *e) override
Definition: path-edit.cpp:239
qreal distance(QPointF point)
Definition: path-edit.cpp:106
PathEdit(Canvas *canvas) noexcept
Definition: path-edit.cpp:12
bool mouseMoveEvent(QMouseEvent *e) override
Definition: path-edit.cpp:33
void paint(QPainter *painter) override
Definition: path-edit.cpp:149
void moveElementTo(int index, QPointF local_coord)
Definition: path-edit.cpp:52
bool mouseReleaseEvent(QMouseEvent *e) override
Definition: path-edit.cpp:125
PathShape & target()
Definition: path-edit.cpp:211
const QPainterPath & path() const
Definition: path-edit.cpp:247
bool mousePressEvent(QMouseEvent *e) override
Definition: path-edit.cpp:21
int hitTest(QPointF canvas_coord)
Definition: path-edit.cpp:136
QPointF getLocalCoord(QPointF canvas_coord)
Definition: path-edit.cpp:207
void exit() override
Definition: path-edit.cpp:256
Definition: path-shape.h:7
NodeType
Definition: path-shape.h:9
In-canvas controls with its own painting and event handling functions.
Definition: canvas-control.h:8
shared_ptr< Shape > ShapePtr
Definition: shape.h:137