17 : QGraphicsPathItem(parent)
21 setFlag(QGraphicsItem::ItemSendsScenePositionChanges);
22 setCacheMode(QGraphicsItem::DeviceCoordinateCache);
41 return QGraphicsPathItem::boundingRect().adjusted(-1, -1, 1, 1);
44void Port::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
53 painter->setBrush(brush());
54 painter->drawPath(path());
97 [&](
auto *conn) { return (conn->startPort() == otherPort) || (conn->endPort() == otherPort); });
104 conn->updatePosFromPorts();
131 if (change == ItemScenePositionHasChanged) {
135 return QGraphicsPathItem::itemChange(change, value);
158 return (elementBase << 16) | (
static_cast<quint64
>(
globalIndex) & 0xFFFF);
178QBrush Port::currentBrush()
const
189 if (brush().color() != Qt::yellow) {
190 setBrush(currentBrush);
215 setBrush(currentBrush());
235 case Status::Unknown: {
240 case Status::Inactive: {
245 case Status::Active: {
250 case Status::Error: {
266 conn->setEndPort(
nullptr);
268 conn->setStartPort(
nullptr);
Connection: a wire that connects an output port to an input port in the circuit scene.
Abstract base class for all graphical circuit elements.
Port classes: Port (base), InputPort, and OutputPort.
Theme management types and singleton ThemeManager.
A bezier-curve wire connecting an output port to an input port in the scene.
OutputPort * startPort() const
Returns the output port this connection originates from.
InputPort * endPort() const
Returns the input port this connection leads to.
void setEndPort(InputPort *port)
Sets the input port this connection leads to.
void setStartPort(OutputPort *port)
Sets the output port this connection originates from.
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
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.
virtual bool isValid() const =0
Returns true if the port satisfies its connection requirement. Pure virtual.
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.
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
static const ThemeAttributes & attributes()
Returns the current ThemeAttributes color set.