-
Notifications
You must be signed in to change notification settings - Fork 948
Expand file tree
/
Copy pathConnectionGraphicsObject.hpp
More file actions
104 lines (65 loc) · 2.38 KB
/
ConnectionGraphicsObject.hpp
File metadata and controls
104 lines (65 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#pragma once
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include <utility>
#include <QPainterPath>
#include <QPolygonF>
#include <QtCore/QUuid>
#include <QtWidgets/QGraphicsObject>
#include "ConnectionState.hpp"
#include "Definitions.hpp"
class QGraphicsSceneMouseEvent;
namespace QtNodes {
class AbstractGraphModel;
class BasicGraphicsScene;
/// Graphic Object for connection. Adds itself to scene
class ConnectionGraphicsObject : public QGraphicsObject
{
Q_OBJECT
public:
// Needed for qgraphicsitem_cast
enum { Type = UserType + 2 };
int type() const override { return Type; }
public:
ConnectionGraphicsObject(BasicGraphicsScene &scene, ConnectionId const connectionId);
~ConnectionGraphicsObject() = default;
public:
AbstractGraphModel &graphModel() const;
BasicGraphicsScene *nodeScene() const;
ConnectionId const &connectionId() const;
QRectF boundingRect() const override;
QPainterPath shape() const override;
QPointF const &endPoint(PortType portType) const;
QPointF out() const { return _out; }
QPointF in() const { return _in; }
std::pair<QPointF, QPointF> pointsC1C2() const;
QPolygonF arrow(QPainterPath target, qreal delta = M_PI / 8) const;
void setEndPoint(PortType portType, QPointF const &point);
/// Updates the position of both ends
void move();
ConnectionState const &connectionState() const;
ConnectionState &connectionState();
protected:
void paint(QPainter *painter,
QStyleOptionGraphicsItem const *option,
QWidget *widget = 0) override;
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
private:
void initializePosition();
void addGraphicsEffect();
std::pair<QPointF, QPointF> pointsC1C2Horizontal() const;
std::pair<QPointF, QPointF> pointsC1C2Vertical() const;
private:
ConnectionId _connectionId;
AbstractGraphModel &_graphModel;
ConnectionState _connectionState;
mutable QPointF _out;
mutable QPointF _in;
};
} // namespace QtNodes