Files

162 lines
2.4 KiB
C++
Raw Permalink Normal View History

2016-04-15 22:40:45 +02:00
#pragma once
#include <QtCore/QUuid>
2015-12-10 14:29:59 +01:00
#include <QtWidgets/QGraphicsObject>
2018-08-09 20:19:12 -06:00
#include "PortType.hpp"
#include "NodeData.hpp"
#include "NodeIndex.hpp"
#include "ConnectionGeometry.hpp"
#include "ConnectionState.hpp"
2015-12-10 14:29:59 +01:00
class QGraphicsSceneMouseEvent;
2017-01-30 10:31:43 +01:00
namespace QtNodes
{
class FlowScene;
2018-08-22 19:46:02 -04:00
struct ConnectionID;
2015-12-10 14:29:59 +01:00
2018-08-09 20:19:12 -06:00
/// Graphic Object for connection.
2015-12-10 14:29:59 +01:00
class ConnectionGraphicsObject
: public QGraphicsObject
{
Q_OBJECT
public:
ConnectionGraphicsObject(NodeIndex const& leftNode,
PortIndex leftPortIndex,
NodeIndex const& rightNode,
PortIndex rightPortIndex,
FlowScene& scene);
virtual
~ConnectionGraphicsObject();
2015-12-10 14:29:59 +01:00
enum { Type = UserType + 2 };
int
type() const override
{
return Type;
}
2015-12-10 14:29:59 +01:00
public:
NodeIndex
node(PortType pType) const
{
return pType == PortType::In ? _rightNode : _leftNode;
}
PortIndex
portIndex(PortType pType) const
{
return pType == PortType::In ? _rightPortIndex : _leftPortIndex;
}
2018-08-09 20:19:12 -06:00
FlowScene&
flowScene() const
{
return _scene;
}
ConnectionGeometry const&
geometry() const
{
return _geometry;
}
ConnectionGeometry&
geometry()
{
return _geometry;
}
ConnectionState const&
state() const
{
return _state;
}
ConnectionState&
state()
{
return _state;
}
2015-12-10 14:29:59 +01:00
QRectF
boundingRect() const override;
2015-12-11 14:53:53 +01:00
QPainterPath
shape() const override;
void
setGeometryChanged();
2018-08-09 20:19:12 -06:00
ConnectionID
id() const;
NodeDataType
dataType(PortType ty) const;
2018-08-09 20:19:12 -06:00
/// Updates the position of both ends
void
move();
void
lock(bool locked);
2018-08-09 20:19:12 -06:00
const FlowScene&
scene() const
{
return _scene;
}
2018-08-09 20:19:12 -06:00
FlowScene&
scene()
{
return _scene;
}
2018-08-09 20:19:12 -06:00
2015-12-10 14:29:59 +01:00
protected:
void
paint(QPainter* painter,
QStyleOptionGraphicsItem const* option,
QWidget* widget = 0) override;
2015-12-10 14:29:59 +01:00
void
mousePressEvent(QGraphicsSceneMouseEvent* event) override;
2015-12-11 12:47:50 +01:00
void
mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
2015-12-10 14:29:59 +01:00
void
mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
2015-12-10 14:29:59 +01:00
void
hoverEnterEvent(QGraphicsSceneHoverEvent* event) override;
2015-12-11 14:53:53 +01:00
void
hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override;
2015-12-10 14:29:59 +01:00
private:
void
addGraphicsEffect();
private:
FlowScene & _scene;
2018-08-09 20:19:12 -06:00
ConnectionGeometry _geometry;
ConnectionState _state;
2018-08-09 20:19:12 -06:00
NodeIndex _leftNode;
NodeIndex _rightNode;
PortIndex _leftPortIndex;
PortIndex _rightPortIndex;
2015-12-10 14:29:59 +01:00
};
2017-01-30 10:31:43 +01:00
}