feat: socket hover colors

This commit is contained in:
parker
2025-06-21 02:31:10 +01:00
parent dcc5c25a2d
commit a6a0bec1c0
3 changed files with 21 additions and 4 deletions

View File

@@ -21,7 +21,6 @@ void FloatingEdgeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsIte
{
// auto pen = QPen("white");
std::cout << "draw\n";
QLinearGradient gradient(socket1_->scenePos(), floatPos_);
gradient.setColorAt(0.0, QColor(255, 255, 255, 255));
gradient.setColorAt(1.0, QColor(255, 255, 255, 50));
@@ -35,7 +34,6 @@ void FloatingEdgeGraphic::paint(QPainter *painter, const QStyleOptionGraphicsIte
}
void FloatingEdgeGraphic::setFloatPos(QPointF floatPos) {
std::cout << "moving" << floatPos.x() << " " << floatPos.y() << "\n";
prepareGeometryChange();
floatPos_ = floatPos;
update();

View File

@@ -6,7 +6,10 @@
SocketGraphic::SocketGraphic(QGraphicsItem *parent)
: QGraphicsItem(parent)
{
brushActive_ = QBrush("white");
brushInactive_ = QBrush("#9f9f9f");
socketSize_ = 3;
setAcceptHoverEvents(true);
}
QRectF SocketGraphic::boundingRect() const
@@ -18,11 +21,21 @@ QRectF SocketGraphic::boundingRect() const
void SocketGraphic::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QBrush whiteBrush = QBrush("white");
painter->setPen(Qt::NoPen);
painter->setBrush(whiteBrush);
painter->setBrush(hovered_ ? brushActive_ : brushInactive_);
painter->drawEllipse(QPoint(0,0), socketSize_, socketSize_);
}
void SocketGraphic::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
hovered_ = true;
update();
}
void SocketGraphic::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
hovered_ = false;
update();
}

View File

@@ -13,5 +13,11 @@ public:
private:
int socketSize_ = 1;
QBrush brushInactive_;
QBrush brushActive_;
bool hovered_=false;
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
};