18#include <QGraphicsPathItem>
38class Port :
public QGraphicsPathItem
43 enum {
Type = QGraphicsItem::UserType + 1 };
47 QPainterPath
shape()
const override;
55 void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
override;
60 explicit Port(QGraphicsItem *parent =
nullptr);
187 QVariant
itemChange(GraphicsItemChange change,
const QVariant &value)
override;
218 QBrush currentBrush()
const;
232 explicit InputPort(QGraphicsItem *parent =
nullptr);
264 explicit OutputPort(QGraphicsItem *parent =
nullptr);
Central enumeration types for element types, groups, and signal status.
A bezier-curve wire connecting an output port to an input port in the scene.
Abstract base class for all graphical circuit elements in wiRedPanda.
void setStatus(const Status status) override
bool isInput() const override
bool isOutput() const override
OutputPort(QGraphicsItem *parent=nullptr)
Constructs an output port attached to parent.
bool isValid() const override
Abstract base class for circuit element ports (connection endpoints).
virtual bool isOutput() const =0
Returns true if this is an output port. Pure virtual.
void setCurrentBrush(const QBrush ¤tBrush)
Sets the brush used to fill the port shape.
QRectF boundingRect() const override
void attachConnection(Connection *conn)
Registers conn as a connection attached to this port.
int type() const override
virtual bool isValid() const =0
Returns true if the port satisfies its connection requirement. Pure virtual.
const GraphicElement * graphicElement() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void hoverEnter()
Applies hover-enter visual feedback.
void setRequired(const bool required)
Marks whether a wire to this port is mandatory.
virtual void setStatus(Status status)=0
void setGraphicElement(GraphicElement *graphicElement)
Binds this port to graphicElement.
QPen currentPen() const
Returns the pen paint() draws the port outline with for its current status.
void updateConnections()
Triggers a path update on all attached connections.
void detachConnection(Connection *conn)
Removes conn from this port's connection list.
static constexpr int kRadius
GraphicElement * graphicElement()
Returns the graphic element that owns this port.
Status status() const
Returns the current logical status (Active/Inactive/Unknown/Error).
void drainConnections(bool isInput)
Drains all attached connections, breaking back-references before deletion.
void hoverLeave()
Reverts hover-enter visual feedback.
int index() const
Returns the port's visual/logical index within the element.
Port(QGraphicsItem *parent=nullptr)
Constructs the port with optional parent item.
static quint64 makeSerialId(quint64 elementBase, int globalIndex)
QPainterPath shape() const override
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
Status defaultValue() const
Returns the default status applied when the port is unconnected.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void setDefaultStatus(const Status defaultStatus)
Sets the status applied when the port has no connection.
void updateTheme()
Reapplies the status-based pen and brush from the current ThemeManager palette.
virtual bool isInput() const =0
Returns true if this is an input port. Pure virtual.
bool isConnected(Port *otherPort)
Returns true if this port is connected to otherPort via any wire.
const QList< Connection * > & connections() const
Returns the list of wires attached to this port.
GraphicElement * m_graphicElement
bool isRequired() const
Returns true if a connection to this port is mandatory.
void setName(const QString &name)
Sets the label text shown next to the port.
QString name() const
Returns the port's label text.
void setIndex(const int index)
Sets the port's visual index within the element.
QList< Connection * > m_connections