106 lines
3.1 KiB
C++
106 lines
3.1 KiB
C++
#pragma once
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <QGraphicsObject>
|
|
|
|
#include <data/node.h>
|
|
|
|
namespace Xybrid::UI {
|
|
class PortConnectionObject;
|
|
class PortObject : public QGraphicsObject {
|
|
friend class PortConnectionObject;
|
|
|
|
std::shared_ptr<Data::Port> port;
|
|
QGraphicsSimpleTextItem* labelShadow;
|
|
QGraphicsSimpleTextItem* label;
|
|
bool highlighted = false;
|
|
std::unique_ptr<QGraphicsLineItem> dragLine;
|
|
|
|
std::unordered_map<PortObject*, PortConnectionObject*> connections;
|
|
|
|
void connectTo(PortObject*);
|
|
void setHighlighted(bool, bool hideLabel = false);
|
|
|
|
protected:
|
|
|
|
public:
|
|
enum { Type = UserType + 101 };
|
|
int type() const override { return Type; }
|
|
|
|
PortObject(const std::shared_ptr<Data::Port>&);
|
|
~PortObject() override;
|
|
|
|
inline const std::shared_ptr<Data::Port>& getPort() const { return port; }
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent*) override;
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent*) override;
|
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent*) override;
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent*) override;
|
|
|
|
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
|
|
QRectF boundingRect() const override;
|
|
};
|
|
|
|
class PortConnectionObject : public QGraphicsObject {
|
|
friend class PortObject;
|
|
|
|
PortObject* in;
|
|
PortObject* out;
|
|
bool highlighted = false;
|
|
|
|
PortConnectionObject(PortObject* in, PortObject* out);
|
|
|
|
void updateEnds();
|
|
public:
|
|
~PortConnectionObject() override;
|
|
|
|
void disconnect();
|
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent*) override;
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent*) override;
|
|
|
|
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
|
|
QRectF boundingRect() const override;
|
|
QPainterPath shape(qreal width) const;
|
|
QPainterPath shape() const override { return shape(8); }
|
|
};
|
|
|
|
class NodeObject : public QGraphicsObject {
|
|
friend class PortObject;
|
|
|
|
std::shared_ptr<Data::Node> node;
|
|
std::unique_ptr<QGraphicsItem> inputPortContainer = nullptr;
|
|
std::unique_ptr<QGraphicsItem> outputPortContainer = nullptr;
|
|
|
|
void onMoved();
|
|
void bringToTop(bool force = false);
|
|
|
|
void createPorts();
|
|
void updateGeometry();
|
|
protected:
|
|
|
|
void focusInEvent(QFocusEvent*) override;
|
|
|
|
public:
|
|
enum { Type = UserType + 100 };
|
|
int type() const override { return Type; }
|
|
|
|
NodeObject(const std::shared_ptr<Data::Node>&);
|
|
|
|
inline const std::shared_ptr<Data::Node>& getNode() const { return node; }
|
|
void promptDelete();
|
|
|
|
void contextMenuEvent(QGraphicsSceneContextMenuEvent*) override;
|
|
|
|
void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override;
|
|
QRectF boundingRect() const override;
|
|
};
|
|
}
|