CableItem.hpp
1 #pragma once
2 #include <Process/Dataflow/Cable.hpp>
3 #include <Process/Dataflow/Port.hpp>
4 
5 #include <ossia/detail/ptr_set.hpp>
6 
7 #include <QGraphicsItem>
8 #include <QObject>
9 
10 #include <verdigris>
11 namespace Dataflow
12 {
13 class CableItem;
14 }
15 
16 namespace Process
17 {
18 struct Context;
19 }
20 namespace Dataflow
21 {
22 class PortItem;
23 class SCORE_LIB_PROCESS_EXPORT CableItem final
24  : public QObject
25  , public QGraphicsItem
26 {
27  W_OBJECT(CableItem)
28  Q_INTERFACES(QGraphicsItem)
29 
30 public:
31  static bool g_cables_enabled;
32  CableItem(
33  const Process::Cable& c, const Process::Context& ctx,
34  QGraphicsItem* parent = nullptr);
35  ~CableItem() override;
36  const Id<Process::Cable>& id() const { return m_cable.id(); }
37  const Process::Cable& model() const { return m_cable; }
38 
39  static const constexpr int Type = QGraphicsItem::UserType + 9999;
40  int type() const final override { return Type; }
41 
42  void resize();
43  void check();
44  PortItem* source() const noexcept;
45  PortItem* target() const noexcept;
46  void setSource(PortItem* p);
47  void setTarget(PortItem* p);
48 
49 public:
50  void removeRequested() E_SIGNAL(SCORE_LIB_PROCESS_EXPORT, removeRequested)
51 
52 private:
53  QRectF boundingRect() const override;
54  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
55  override;
56  QPainterPath shape() const override;
57  QPainterPath opaqueArea() const override;
58  bool contains(const QPointF& point) const override;
59  void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
60  void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
61  void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
62  void keyPressEvent(QKeyEvent* event) override;
63  void keyReleaseEvent(QKeyEvent* event) override;
64 
65  const Process::Cable& m_cable;
66  const Process::Context& m_context;
67  QPointer<PortItem> m_p1, m_p2;
68  QPainterPath m_path;
69  Process::PortType m_type{};
70 };
71 }
Definition: CableItem.hpp:26
Definition: score-lib-process/Process/Dataflow/PortItem.hpp:39
Definition: Cable.hpp:38
The id_base_t class.
Definition: Identifier.hpp:57
Base classes and tools to implement processes and layers.
Definition: JSONVisitor.hpp:1324
Definition: ProcessContext.hpp:12