2015-12-13 21:42:10 +01:00
|
|
|
#include "NodePainter.hpp"
|
|
|
|
|
|
2015-12-20 17:46:00 +01:00
|
|
|
#include <QtCore/QMargins>
|
|
|
|
|
|
2015-12-13 21:42:10 +01:00
|
|
|
#include "NodeGeometry.hpp"
|
2015-12-16 11:01:56 +01:00
|
|
|
#include "NodeState.hpp"
|
2015-12-13 21:42:10 +01:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NodePainter::
|
|
|
|
|
paint(QPainter* painter,
|
|
|
|
|
NodeGeometry const& geom,
|
2015-12-16 11:01:56 +01:00
|
|
|
NodeState const& state)
|
2015-12-13 21:42:10 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (geom.hovered())
|
|
|
|
|
{
|
|
|
|
|
QPen p(Qt::white, 2.0);
|
|
|
|
|
painter->setPen(p);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QPen p(Qt::white, 1.5);
|
|
|
|
|
painter->setPen(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->setBrush(QColor(Qt::darkGray));
|
|
|
|
|
|
|
|
|
|
unsigned int diam = geom.connectionPointDiameter();
|
2015-12-13 22:39:37 +01:00
|
|
|
QRectF boundary(0.0, 0.0, geom.width(), geom.height());
|
2015-12-13 21:42:10 +01:00
|
|
|
QMargins m(diam, diam, diam, diam);
|
|
|
|
|
|
|
|
|
|
double const radius = 3.0;
|
|
|
|
|
|
|
|
|
|
painter->drawRoundedRect(boundary.marginsAdded(m), radius, radius);
|
|
|
|
|
|
|
|
|
|
drawConnectionPoints(painter, geom);
|
|
|
|
|
|
2015-12-16 11:01:56 +01:00
|
|
|
drawFilledConnectionPoints(painter, geom, state);
|
2015-12-13 21:42:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NodePainter::
|
|
|
|
|
drawConnectionPoints(QPainter* painter,
|
|
|
|
|
NodeGeometry const& geom)
|
|
|
|
|
{
|
|
|
|
|
painter->setBrush(QColor(Qt::darkGray));
|
|
|
|
|
double totalHeight = 0;
|
|
|
|
|
|
|
|
|
|
auto diameter = geom.connectionPointDiameter();
|
|
|
|
|
|
|
|
|
|
double const h = geom.entryHeight();
|
|
|
|
|
for (size_t i = 0; i < geom.nSinks(); ++i)
|
|
|
|
|
{
|
|
|
|
|
double y = totalHeight + (geom.spacing() + h) / 2;
|
2015-12-15 23:14:45 +01:00
|
|
|
double x = 0.0 - diameter;
|
2015-12-13 22:39:37 +01:00
|
|
|
|
|
|
|
|
QPointF p(x, y);
|
|
|
|
|
|
|
|
|
|
auto diff = geom.draggingPos() - p;
|
|
|
|
|
double dist = std::sqrt(QPointF::dotProduct(diff, diff));
|
|
|
|
|
|
|
|
|
|
double const thres = 40.0;
|
|
|
|
|
|
|
|
|
|
double const r = (dist < thres) ?
|
|
|
|
|
(2.0 - dist / thres / 2.) :
|
|
|
|
|
1.0;
|
|
|
|
|
|
|
|
|
|
painter->drawEllipse(p,
|
|
|
|
|
diameter * 0.6 * r,
|
|
|
|
|
diameter * 0.6 * r);
|
2015-12-13 21:42:10 +01:00
|
|
|
|
|
|
|
|
totalHeight += h + geom.spacing();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totalHeight += geom.spacing();
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < geom.nSources(); ++i)
|
|
|
|
|
{
|
|
|
|
|
double y = totalHeight + (geom.spacing() + h) / 2;
|
2015-12-15 23:14:45 +01:00
|
|
|
double x = geom.width() + diameter;
|
2015-12-13 22:39:37 +01:00
|
|
|
|
|
|
|
|
QPointF p(x, y);
|
|
|
|
|
|
|
|
|
|
auto diff = geom.draggingPos() - p;
|
|
|
|
|
double dist = std::sqrt(QPointF::dotProduct(diff, diff));
|
|
|
|
|
|
|
|
|
|
double const thres = 20.0;
|
|
|
|
|
|
|
|
|
|
double const r = (dist < thres) ?
|
|
|
|
|
(2.0 - dist / thres / 2.) :
|
|
|
|
|
1.0;
|
|
|
|
|
|
|
|
|
|
painter->drawEllipse(p,
|
|
|
|
|
diameter * 0.6 * r,
|
|
|
|
|
diameter * 0.6 * r);
|
2015-12-13 21:42:10 +01:00
|
|
|
|
|
|
|
|
totalHeight += h + geom.spacing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NodePainter::
|
|
|
|
|
drawFilledConnectionPoints(QPainter* painter,
|
|
|
|
|
NodeGeometry const& geom,
|
2015-12-16 11:01:56 +01:00
|
|
|
NodeState const& state)
|
2015-12-13 21:42:10 +01:00
|
|
|
{
|
|
|
|
|
painter->setPen(Qt::cyan);
|
|
|
|
|
painter->setBrush(Qt::cyan);
|
|
|
|
|
|
|
|
|
|
double totalHeight = 0;
|
|
|
|
|
|
|
|
|
|
auto diameter = geom.connectionPointDiameter();
|
|
|
|
|
|
|
|
|
|
double const h = geom.entryHeight();
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < geom.nSinks(); ++i)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
double y = totalHeight + (geom.spacing() + h) / 2;
|
2015-12-15 23:14:45 +01:00
|
|
|
double x = 0.0 - diameter;
|
2015-12-13 21:42:10 +01:00
|
|
|
|
2015-12-16 11:01:56 +01:00
|
|
|
if (!state.connectionID(EndType::SINK, i).isNull())
|
2015-12-13 21:42:10 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
painter->drawEllipse(QPointF(x, y),
|
|
|
|
|
diameter * 0.4,
|
|
|
|
|
diameter * 0.4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totalHeight += h + geom.spacing();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totalHeight += geom.spacing();
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < geom.nSources(); ++i)
|
|
|
|
|
{
|
|
|
|
|
double y = totalHeight + (geom.spacing() + h) / 2;
|
2015-12-15 23:14:45 +01:00
|
|
|
double x = geom.width() + diameter;
|
2015-12-13 21:42:10 +01:00
|
|
|
|
2015-12-16 11:01:56 +01:00
|
|
|
if (!state.connectionID(EndType::SOURCE, i).isNull())
|
2015-12-13 21:42:10 +01:00
|
|
|
{
|
|
|
|
|
painter->drawEllipse(QPointF(x, y),
|
|
|
|
|
diameter * 0.4,
|
|
|
|
|
diameter * 0.4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
totalHeight += h + geom.spacing();
|
|
|
|
|
}
|
|
|
|
|
}
|