2016-04-15 22:40:45 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-02-07 17:36:32 +01:00
|
|
|
#include <utility>
|
2015-12-10 14:29:59 +01:00
|
|
|
|
2020-02-07 17:36:32 +01:00
|
|
|
#include <QtCore/QUuid>
|
2015-12-10 14:29:59 +01:00
|
|
|
#include <QtWidgets/QGraphicsObject>
|
|
|
|
|
|
2020-02-07 17:36:32 +01:00
|
|
|
#include "Definitions.hpp"
|
2020-02-27 00:01:45 +01:00
|
|
|
#include "ConnectionState.hpp"
|
2020-02-07 17:36:32 +01:00
|
|
|
|
2015-12-10 14:29:59 +01:00
|
|
|
class QGraphicsSceneMouseEvent;
|
|
|
|
|
|
2017-01-30 10:31:43 +01:00
|
|
|
namespace QtNodes
|
|
|
|
|
{
|
|
|
|
|
|
2020-02-18 09:32:41 +01:00
|
|
|
class GraphicsScene;
|
2015-12-10 14:29:59 +01:00
|
|
|
class Connection;
|
|
|
|
|
class ConnectionGeometry;
|
|
|
|
|
|
2016-04-16 19:13:02 +02:00
|
|
|
/// Graphic Object for connection. Adds itself to scene
|
2015-12-10 14:29:59 +01:00
|
|
|
class ConnectionGraphicsObject
|
|
|
|
|
: public QGraphicsObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
2020-02-19 23:05:22 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/// Defines whether we construct a new connection
|
|
|
|
|
/// or it is already binding two nodes.
|
|
|
|
|
enum State
|
|
|
|
|
{
|
|
|
|
|
Pending = 0,
|
|
|
|
|
Connected = 1
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-10 14:29:59 +01:00
|
|
|
public:
|
|
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
using ConnectionId = std::pair<NodeId, NodeId>;
|
2016-05-24 10:07:41 +02:00
|
|
|
|
2020-02-18 09:32:41 +01:00
|
|
|
ConnectionGraphicsObject(GraphicsScene & scene,
|
|
|
|
|
ConnectionId connectionId);
|
2020-02-03 23:31:42 +01:00
|
|
|
|
|
|
|
|
virtual ~ConnectionGraphicsObject();
|
2015-12-10 14:29:59 +01:00
|
|
|
|
2017-03-18 07:05:15 -06:00
|
|
|
enum { Type = UserType + 2 };
|
2020-02-03 23:31:42 +01:00
|
|
|
int type() const override { return Type; }
|
2017-03-18 07:05:15 -06:00
|
|
|
|
2015-12-10 14:29:59 +01:00
|
|
|
public:
|
|
|
|
|
|
2020-02-18 09:32:41 +01:00
|
|
|
ConnectionId connectionId();
|
2015-12-10 14:29:59 +01:00
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
QRectF boundingRect() const override;
|
2015-12-11 14:53:53 +01:00
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
QPainterPath shape() const override;
|
2016-11-07 22:12:44 +01:00
|
|
|
|
2020-03-02 10:11:52 +01:00
|
|
|
QPointF const & endPoint(PortType portType) const;
|
|
|
|
|
QPointF & endPoint(PortType portType);
|
|
|
|
|
|
|
|
|
|
std::pair<QPointF, QPointF> pointsC1C2() const;
|
2020-02-19 23:05:22 +01:00
|
|
|
|
|
|
|
|
void setEndPoint(PortType portType, QPointF const & point);
|
|
|
|
|
|
|
|
|
|
void moveEndPointBy(PortType portType, QPointF const & offset);
|
|
|
|
|
|
|
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
void setGeometryChanged();
|
2016-05-24 10:07:41 +02:00
|
|
|
|
2016-09-22 09:56:42 +02:00
|
|
|
/// Updates the position of both ends
|
2020-02-03 23:31:42 +01:00
|
|
|
void move();
|
2016-09-22 09:56:42 +02:00
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
void lock(bool locked);
|
2017-05-07 19:02:44 +02:00
|
|
|
|
2020-02-27 00:01:45 +01:00
|
|
|
ConnectionState const & connectionState() const;
|
|
|
|
|
ConnectionState & connectionState();
|
|
|
|
|
|
2020-02-19 23:05:22 +01:00
|
|
|
|
2015-12-10 14:29:59 +01:00
|
|
|
protected:
|
2016-04-16 19:13:02 +02:00
|
|
|
|
2020-02-18 09:32:41 +01:00
|
|
|
void paint(QPainter * painter,
|
2020-02-03 23:31:42 +01:00
|
|
|
QStyleOptionGraphicsItem const * option,
|
2020-02-18 09:32:41 +01:00
|
|
|
QWidget * widget = 0) override;
|
2015-12-10 14:29:59 +01:00
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
|
2015-12-11 12:47:50 +01:00
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent * event) override;
|
2015-12-10 14:29:59 +01:00
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent * event) override;
|
2015-12-10 14:29:59 +01:00
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent * event) override;
|
2015-12-11 14:53:53 +01:00
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent * event) override;
|
2016-04-16 19:13:02 +02:00
|
|
|
|
2015-12-10 14:29:59 +01:00
|
|
|
private:
|
|
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
void addGraphicsEffect();
|
2016-04-16 19:13:02 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2020-02-18 09:32:41 +01:00
|
|
|
GraphicsScene & _scene;
|
2016-05-24 10:07:41 +02:00
|
|
|
|
2020-02-27 00:01:45 +01:00
|
|
|
ConnectionState _connectionState;
|
|
|
|
|
|
2020-02-03 23:31:42 +01:00
|
|
|
ConnectionId _connectionId;
|
2020-02-19 23:05:22 +01:00
|
|
|
|
|
|
|
|
State _state;
|
|
|
|
|
|
2020-03-02 10:11:52 +01:00
|
|
|
QPointF _in;
|
|
|
|
|
QPointF _out;
|
2020-02-19 23:05:22 +01:00
|
|
|
|
|
|
|
|
bool _hovered;
|
|
|
|
|
|
2015-12-10 14:29:59 +01:00
|
|
|
};
|
2017-01-30 10:31:43 +01:00
|
|
|
}
|