Add glowing lines

This commit is contained in:
Joey Yakimowich-Payne 2026-02-06 12:54:33 -07:00
commit cdb32287e3
4 changed files with 57 additions and 4 deletions

View file

@ -1,4 +1,5 @@
#include "SquareConnectionPainter.h"
#include "WarpGraphModel.h"
#include <QtNodes/internal/BasicGraphicsScene.hpp>
#include <QtNodes/internal/ConnectionGraphicsObject.hpp>
@ -187,6 +188,30 @@ void SquareConnectionPainter::paint(
auto path = orthogonalPath(cgo);
float peakLevel = 0.0f;
auto *scene = cgo.nodeScene();
if (scene) {
auto *model = dynamic_cast<WarpGraphModel *>(&scene->graphModel());
if (model) {
auto cId = cgo.connectionId();
peakLevel = std::max(model->nodePeakLevel(cId.outNodeId),
model->nodePeakLevel(cId.inNodeId));
}
}
auto activeColor = [&](QColor base) -> QColor {
if (peakLevel < 0.005f)
return base;
float t = std::min(peakLevel * 2.0f, 1.0f);
int r = static_cast<int>(base.red() + t * (60 - base.red()));
int g = static_cast<int>(base.green() + t * (210 - base.green()));
int b = static_cast<int>(base.blue() + t * (80 - base.blue()));
return QColor(std::clamp(r, 0, 255),
std::clamp(g, 0, 255),
std::clamp(b, 0, 255),
base.alpha());
};
if (hovered || selected) {
QPen pen;
pen.setWidth(static_cast<int>(2 * style.lineWidth()));
@ -205,9 +230,15 @@ void SquareConnectionPainter::paint(
painter->setBrush(Qt::NoBrush);
painter->drawPath(path);
} else {
QColor base = selected ? style.selectedColor() : style.normalColor();
QColor color = activeColor(base);
float width = style.lineWidth();
if (peakLevel > 0.005f)
width += peakLevel * 1.5f;
QPen pen;
pen.setWidth(style.lineWidth());
pen.setColor(selected ? style.selectedColor() : style.normalColor());
pen.setWidthF(width);
pen.setColor(color);
painter->setPen(pen);
painter->setBrush(Qt::NoBrush);
painter->drawPath(path);