Files

114 lines
2.1 KiB
C++
Raw Permalink Normal View History

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;
/// 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>;
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
enum { Type = UserType + 2 };
2020-02-03 23:31:42 +01:00
int type() const override { return Type; }
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;
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();
/// Updates the position of both ends
2020-02-03 23:31:42 +01:00
void move();
2020-02-03 23:31:42 +01:00
void lock(bool locked);
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:
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;
2015-12-10 14:29:59 +01:00
private:
2020-02-03 23:31:42 +01:00
void addGraphicsEffect();
private:
2020-02-18 09:32:41 +01:00
GraphicsScene & _scene;
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
}