You've already forked nodeeditor
mirror of
https://github.com/AxioDL/nodeeditor.git
synced 2026-03-30 11:48:31 -07:00
114 lines
2.1 KiB
C++
114 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <utility>
|
|
|
|
#include <QtCore/QUuid>
|
|
#include <QtWidgets/QGraphicsObject>
|
|
|
|
#include "Definitions.hpp"
|
|
#include "ConnectionState.hpp"
|
|
|
|
class QGraphicsSceneMouseEvent;
|
|
|
|
namespace QtNodes
|
|
{
|
|
|
|
class GraphicsScene;
|
|
class Connection;
|
|
class ConnectionGeometry;
|
|
|
|
/// Graphic Object for connection. Adds itself to scene
|
|
class ConnectionGraphicsObject
|
|
: public QGraphicsObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
/// Defines whether we construct a new connection
|
|
/// or it is already binding two nodes.
|
|
enum State
|
|
{
|
|
Pending = 0,
|
|
Connected = 1
|
|
};
|
|
|
|
public:
|
|
|
|
using ConnectionId = std::pair<NodeId, NodeId>;
|
|
|
|
ConnectionGraphicsObject(GraphicsScene & scene,
|
|
ConnectionId connectionId);
|
|
|
|
virtual ~ConnectionGraphicsObject();
|
|
|
|
enum { Type = UserType + 2 };
|
|
int type() const override { return Type; }
|
|
|
|
public:
|
|
|
|
ConnectionId connectionId();
|
|
|
|
QRectF boundingRect() const override;
|
|
|
|
QPainterPath shape() const override;
|
|
|
|
QPointF const & endPoint(PortType portType) const;
|
|
QPointF & endPoint(PortType portType);
|
|
|
|
std::pair<QPointF, QPointF> pointsC1C2() const;
|
|
|
|
void setEndPoint(PortType portType, QPointF const & point);
|
|
|
|
void moveEndPointBy(PortType portType, QPointF const & offset);
|
|
|
|
|
|
void setGeometryChanged();
|
|
|
|
/// Updates the position of both ends
|
|
void move();
|
|
|
|
void lock(bool locked);
|
|
|
|
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 hoverEnterEvent(QGraphicsSceneHoverEvent * event) override;
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent * event) override;
|
|
|
|
private:
|
|
|
|
void addGraphicsEffect();
|
|
|
|
private:
|
|
|
|
GraphicsScene & _scene;
|
|
|
|
ConnectionState _connectionState;
|
|
|
|
ConnectionId _connectionId;
|
|
|
|
State _state;
|
|
|
|
QPointF _in;
|
|
QPointF _out;
|
|
|
|
bool _hovered;
|
|
|
|
};
|
|
}
|