QGraphicsLink::QGraphicsLink(QGraphicsNode* output, int outLine, QGraphicsNode* input, int inLine)
{
setZValue(1.0f);
setFlags(ItemIsSelectable | ItemIsFocusable);
//setCacheMode(QGraphicsItem::ItemCoordinateCache);
}
QRectF QGraphicsLink
::boundingRect() const {
qreal extra = pen().width() * 0.5f + 60.f;
line().p1(),
QSizeF(line
().
dx(), line
().
dy()) ).normalized().adjusted(-extra, -extra, extra, extra);
}
{
painter
->setRenderHint
(QPainter::Antialiasing,
true);
//---- Choose the color
int penWidth = 2;
int arrowDelta = 11;
if (OutputNode)
{
QConnector connector = OutputNode->GetOutputConnector(OutputConnectorIdx);
if (connector.Type == PG_VNGEOMETRY)
drawColor = PG_VNGEOMETRY_COLOR;
else if (connector.Type == PG_VNCAMERA)
drawColor = PG_VNCAMERA_COLOR;
else if (connector.Type == PG_VNLIGHT)
drawColor = PG_VNLIGHT_COLOR;
else if (connector.Type == PG_VNMATERIAL)
drawColor = PG_VNMATERIAL_COLOR;
else if (connector.Type == PG_VNFILM)
drawColor = PG_VNFILM_COLOR;
else if (connector.Type == PG_VNINTEGRATOR)
drawColor = PG_VNINTEGRATOR_COLOR;
else if (connector.Type == PG_MNSPECTRUM)
drawColor = PG_MNSPECTRUM_COLOR;
else if (connector.Type == PG_MNSPECTRALFUNCTION)
drawColor = PG_MNSPECTRALFUNCTION_COLOR;
else if (connector.Type == PG_MNFLOAT)
drawColor = PG_MNFLOAT_COLOR;
else if (connector.Type == PG_MNFRESNEL)
drawColor = PG_MNFRESNEL_COLOR;
else if (connector.Type == PG_MNMICROFACETDISTRIBUTION)
drawColor = PG_MNMICROFACETDISTRIBUTION_COLOR;
}
else
{
drawColor
= QColor(220,
220,
220);
arrowDelta = 5;
}
if (isSelected())
{
drawColor
= QColor(220,
220,
220);
penWidth = 4;
}
//---- Curve
if (line().y1() < line().y2())
{
path.moveTo(line().x1(), line().y1());
float deltaX = 0.25f * (line().x2() - line().x1());
float deltaY = 0.25f * (line().y2() - line().y1());
path.cubicTo(
line().x1(), line().y1() + 3 * 14,
line().x1() + 4 * deltaX, line().y1() + 1 * 14,
line().x2(), line().y2() - 14);
}
else
{
path.moveTo(line().x1(), line().y1());
float deltaX = 0.25f * (line().x2() - line().x1());
float deltaY = 0.25f * (line().y2() - line().y1());
path.cubicTo(
line().x1() + 40, line().y1() + 40,
line().x2() - 40 , line().y2() - 40 - 14,
line().x2(), line().y2() - 14);
}
painter
->setPen
(QPen(drawColor, penWidth, Qt
::SolidLine, Qt
::RoundCap, Qt
::RoundJoin));
painter->drawPath(path);
//---- Arrow
//Draw an arrow-head shaped path at the end of the line's path
arrowHead.setFillRule(Qt::WindingFill);
//-- Bottom arrow
mat.translate(line().p2().x(), line().p2().y() - arrowDelta);
arrowHead = mat.map(arrowHead);
// Create a graphics path item based on this path
painter->setBrush(drawColor);
painter->drawPath(arrowHead);
}
{
//---- Curve
if (line().y1() < line().y2())
{
path.moveTo(line().x1(), line().y1());
float deltaX = 0.25f * (line().x2() - line().x1());
float deltaY = 0.25f * (line().y2() - line().y1());
path.cubicTo(
line().x1(), line().y1() + 3 * 14,
line().x1() + 4 * deltaX, line().y1() + 1 * 14,
line().x2(), line().y2() - 14);
}
else
{
path.moveTo(line().x1(), line().y1());
float deltaX = 0.25f * (line().x2() - line().x1());
float deltaY = 0.25f * (line().y2() - line().y1());
path.cubicTo(
line().x1() + 40, line().y1() + 40,
line().x2() - 40 , line().y2() - 40 - 14,
line().x2(), line().y2() - 14);
}
//---- Arrow
path.setFillRule(Qt::WindingFill);
mat.translate(line().p2().x(), line().p2().y() - 11);
path = mat.map(path);
}
{
// We unfortunately need this hack as QPainterPathStroker will set a width of 1.0
// if we pass a value of 0.0 to QPainterPathStroker::setWidth()
const qreal penWidthZero = qreal(0.00000001);
return path;
ps.setCapStyle(pen.capStyle());
if (pen.widthF() <= 0.f)
ps.setWidth(penWidthZero);
else
ps.setWidth(pen.widthF());
ps.setJoinStyle(pen.joinStyle());
ps.setMiterLimit(pen.miterLimit());
p.addPath(path);
return p;
}
QGraphicsLink::QGraphicsLink(QGraphicsNode* output, int outLine, QGraphicsNode* input, int inLine)
{
setZValue(1.0f);
setFlags(ItemIsSelectable | ItemIsFocusable);
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
//setCacheMode(QGraphicsItem::ItemCoordinateCache);
}
QRectF QGraphicsLink::boundingRect() const
{
qreal extra = pen().width() * 0.5f + 60.f;
return QRectF(
line().p1(),
QSizeF(line().dx(), line().dy())
).normalized().adjusted(-extra, -extra, extra, extra);
}
void QGraphicsLink::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0)
{
painter->setRenderHint(QPainter::Antialiasing, true);
//---- Choose the color
int penWidth = 2;
int arrowDelta = 11;
QColor drawColor = Qt::black;
if (OutputNode)
{
QConnector connector = OutputNode->GetOutputConnector(OutputConnectorIdx);
if (connector.Type == PG_VNGEOMETRY)
drawColor = PG_VNGEOMETRY_COLOR;
else if (connector.Type == PG_VNCAMERA)
drawColor = PG_VNCAMERA_COLOR;
else if (connector.Type == PG_VNLIGHT)
drawColor = PG_VNLIGHT_COLOR;
else if (connector.Type == PG_VNMATERIAL)
drawColor = PG_VNMATERIAL_COLOR;
else if (connector.Type == PG_VNFILM)
drawColor = PG_VNFILM_COLOR;
else if (connector.Type == PG_VNINTEGRATOR)
drawColor = PG_VNINTEGRATOR_COLOR;
else if (connector.Type == PG_MNSPECTRUM)
drawColor = PG_MNSPECTRUM_COLOR;
else if (connector.Type == PG_MNSPECTRALFUNCTION)
drawColor = PG_MNSPECTRALFUNCTION_COLOR;
else if (connector.Type == PG_MNFLOAT)
drawColor = PG_MNFLOAT_COLOR;
else if (connector.Type == PG_MNFRESNEL)
drawColor = PG_MNFRESNEL_COLOR;
else if (connector.Type == PG_MNMICROFACETDISTRIBUTION)
drawColor = PG_MNMICROFACETDISTRIBUTION_COLOR;
}
else
{
drawColor = QColor(220, 220, 220);
arrowDelta = 5;
}
if (isSelected())
{
drawColor = QColor(220, 220, 220);
penWidth = 4;
}
//---- Curve
QPainterPath path;
if (line().y1() < line().y2())
{
path.moveTo(line().x1(), line().y1());
float deltaX = 0.25f * (line().x2() - line().x1());
float deltaY = 0.25f * (line().y2() - line().y1());
path.cubicTo(
line().x1(), line().y1() + 3 * 14,
line().x1() + 4 * deltaX, line().y1() + 1 * 14,
line().x2(), line().y2() - 14);
}
else
{
path.moveTo(line().x1(), line().y1());
float deltaX = 0.25f * (line().x2() - line().x1());
float deltaY = 0.25f * (line().y2() - line().y1());
path.cubicTo(
line().x1() + 40, line().y1() + 40,
line().x2() - 40 , line().y2() - 40 - 14,
line().x2(), line().y2() - 14);
}
painter->setPen(QPen(drawColor, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter->drawPath(path);
//---- Arrow
//Draw an arrow-head shaped path at the end of the line's path
QPainterPath arrowHead;
arrowHead.setFillRule(Qt::WindingFill);
//-- Bottom arrow
QPointF pos;
arrowHead.moveTo(QPointF(-4, -5));
arrowHead.lineTo(QPointF(0, 5));
arrowHead.lineTo(QPointF(4, -5));
arrowHead.lineTo(QPointF(-4, -5));
QMatrix mat;
mat.translate(line().p2().x(), line().p2().y() - arrowDelta);
arrowHead = mat.map(arrowHead);
// Create a graphics path item based on this path
painter->setBrush(drawColor);
painter->drawPath(arrowHead);
}
QPainterPath QGraphicsLink::shape() const
{
//---- Curve
QPainterPath path;
if (line().y1() < line().y2())
{
path.moveTo(line().x1(), line().y1());
float deltaX = 0.25f * (line().x2() - line().x1());
float deltaY = 0.25f * (line().y2() - line().y1());
path.cubicTo(
line().x1(), line().y1() + 3 * 14,
line().x1() + 4 * deltaX, line().y1() + 1 * 14,
line().x2(), line().y2() - 14);
}
else
{
path.moveTo(line().x1(), line().y1());
float deltaX = 0.25f * (line().x2() - line().x1());
float deltaY = 0.25f * (line().y2() - line().y1());
path.cubicTo(
line().x1() + 40, line().y1() + 40,
line().x2() - 40 , line().y2() - 40 - 14,
line().x2(), line().y2() - 14);
}
//---- Arrow
path.setFillRule(Qt::WindingFill);
QPointF pos;
path.moveTo(QPointF(-4, -5));
path.lineTo(QPointF(0, 5));
path.lineTo(QPointF(4, -5));
path.lineTo(QPointF(-4, -5));
QMatrix mat;
mat.translate(line().p2().x(), line().p2().y() - 11);
path = mat.map(path);
return ShapeFromPath(path, QPen(QColor(), 6));
}
QPainterPath QGraphicsLink::ShapeFromPath(const QPainterPath &path, const QPen &pen)
{
// We unfortunately need this hack as QPainterPathStroker will set a width of 1.0
// if we pass a value of 0.0 to QPainterPathStroker::setWidth()
const qreal penWidthZero = qreal(0.00000001);
if (path == QPainterPath())
return path;
QPainterPathStroker ps;
ps.setCapStyle(pen.capStyle());
if (pen.widthF() <= 0.f)
ps.setWidth(penWidthZero);
else
ps.setWidth(pen.widthF());
ps.setJoinStyle(pen.joinStyle());
ps.setMiterLimit(pen.miterLimit());
QPainterPath p = ps.createStroke(path);
p.addPath(path);
return p;
}
To copy to clipboard, switch view to plain text mode
QGraphicsNode::QGraphicsNode(QNodesScene* qscene)
{
static int count = 0;
setObjectName
( QString("object%1").
arg(count
++) );
setRect(-QGraphicsNodeWidth, -QGraphicsNodeHeight, QGraphicsNodeWidth, QGraphicsNodeHeight);
qscene->addItem(this);
qscene->AddQGraphicsNode(this);
setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable | ItemSendsScenePositionChanges);
//setCacheMode(QGraphicsItem::ItemCoordinateCache);
setZValue(2.0f);
}
void QGraphicsNode::initializeBackground(QLinearGradient& gradient)
{
gradient.
setColorAt(0.0f,
QColor(60,
60,
60,
255));
gradient.
setColorAt(0.3f,
QColor(30,
30,
30,
255));
gradient.
setColorAt(0.31f,
QColor(20,
20,
20,
255));
gradient.
setColorAt(1.0f,
QColor(20,
20,
20,
255));
}
{
Q_UNUSED(w)
if (HasSubTitle())
setRect(-QGraphicsNodeWidth, -QGraphicsNodeHeight, QGraphicsNodeWidth, QGraphicsNodeHeight + 20);
//---- Draw the background
if(isSelected())
{
grad.
setColorAt(0.0f,
QColor(150,
60,
60,
255));
grad.
setColorAt(0.3f,
QColor(120,
30,
30,
255));
grad.
setColorAt(0.31f,
QColor(110,
20,
20,
255));
grad.
setColorAt(1.0f,
QColor(110,
20,
20,
255));
}
else
initializeBackground(grad);
p->fillRect(rect(), grad);
p->drawRect(rect());
//---- Draw the input connectors
for(int i = 0; i < GetInputConnectorCount(); i++)
{
int connectorType = GetInputConnector(i).Type;
QRectF ir
= GetInputConnectorRect
(i
);
if (connectorType == PG_VNGEOMETRY)
p->fillRect(ir, PG_VNGEOMETRY_COLOR);
else if (connectorType == PG_VNCAMERA)
p->fillRect(ir, PG_VNCAMERA_COLOR);
else if (connectorType == PG_VNLIGHT)
p->fillRect(ir, PG_VNLIGHT_COLOR);
else if (connectorType == PG_VNMATERIAL)
p->fillRect(ir, PG_VNMATERIAL_COLOR);
else if (connectorType == PG_VNFILM)
p->fillRect(ir, PG_VNFILM_COLOR);
else if (connectorType == PG_VNINTEGRATOR)
p->fillRect(ir, PG_VNINTEGRATOR_COLOR);
p->drawRect(ir);
}
//---- Draw the output connectors
for(int i = 0; i < GetOutputConnectorCount(); i++)
{
int connectorType = GetOutputConnector(i).Type;
QRectF or
= GetOutputConnectorRect
(i
);
if (connectorType == PG_VNGEOMETRY)
p->fillRect(or, PG_VNGEOMETRY_COLOR);
else if (connectorType == PG_VNCAMERA)
p->fillRect(or, PG_VNCAMERA_COLOR);
else if (connectorType == PG_VNLIGHT)
p->fillRect(or, PG_VNLIGHT_COLOR);
else if (connectorType == PG_VNMATERIAL)
p->fillRect(or, PG_VNMATERIAL_COLOR);
else if (connectorType == PG_VNFILM)
p->fillRect(or, PG_VNFILM_COLOR);
else if (connectorType == PG_VNINTEGRATOR)
p->fillRect(or, PG_VNINTEGRATOR_COLOR);
else if (connectorType == PG_MNSPECTRUM)
p->fillRect(or, PG_MNSPECTRUM_COLOR);
else if (connectorType == PG_MNSPECTRALFUNCTION)
p->fillRect(or, PG_MNSPECTRALFUNCTION_COLOR);
else if (connectorType == PG_MNFLOAT)
p->fillRect(or, PG_MNFLOAT_COLOR);
else if (connectorType == PG_MNFRESNEL)
p->fillRect(or, PG_MNFRESNEL_COLOR);
else if (connectorType == PG_MNMICROFACETDISTRIBUTION)
p->fillRect(or, PG_MNMICROFACETDISTRIBUTION_COLOR);
p->drawRect(or);
}
//---- Name
QRectF nameRect
(rect
().
left(), rect
().
top(), rect
().
width(),
25);
font.
setWeight(QFont::DemiBold);
p->setFont(font);
p->setPen(Qt::white);
p->drawText(nameRect, Qt::AlignCenter, nodeName);
//---- Sub title
if (!HasSubTitle())
return;
QRectF subTitleRect
(rect
().
left(), rect
().
top() + 20, rect
().
width(),
25);
font.
setWeight(QFont::Light);
p->setFont(font);
p->drawText(subTitleRect, Qt::AlignCenter, GetSubTitle());
}
QGraphicsNode::QGraphicsNode(QNodesScene* qscene)
{
static int count = 0;
setObjectName( QString("object%1").arg(count++) );
setRect(-QGraphicsNodeWidth, -QGraphicsNodeHeight, QGraphicsNodeWidth, QGraphicsNodeHeight);
qscene->addItem(this);
qscene->AddQGraphicsNode(this);
setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable | ItemSendsScenePositionChanges);
setCacheMode(QGraphicsItem::DeviceCoordinateCache);
//setCacheMode(QGraphicsItem::ItemCoordinateCache);
setZValue(2.0f);
}
void QGraphicsNode::initializeBackground(QLinearGradient& gradient)
{
gradient.setColorAt(0.0f, QColor(60,60,60,255));
gradient.setColorAt(0.3f, QColor(30,30,30,255));
gradient.setColorAt(0.31f, QColor(20,20,20,255));
gradient.setColorAt(1.0f, QColor(20,20,20,255));
}
void QGraphicsNode::paint(QPainter* p, const QStyleOptionGraphicsItem* opt, QWidget* w)
{
Q_UNUSED(w)
if (HasSubTitle())
setRect(-QGraphicsNodeWidth, -QGraphicsNodeHeight, QGraphicsNodeWidth, QGraphicsNodeHeight + 20);
//---- Draw the background
QLinearGradient grad(rect().topLeft(), rect().bottomLeft());
if(isSelected())
{
grad.setColorAt(0.0f, QColor(150,60,60,255));
grad.setColorAt(0.3f, QColor(120,30,30,255));
grad.setColorAt(0.31f, QColor(110,20,20,255));
grad.setColorAt(1.0f, QColor(110,20,20,255));
}
else
initializeBackground(grad);
p->fillRect(rect(), grad);
p->drawRect(rect());
//---- Draw the input connectors
for(int i = 0; i < GetInputConnectorCount(); i++)
{
int connectorType = GetInputConnector(i).Type;
QRectF ir = GetInputConnectorRect(i);
if (connectorType == PG_VNGEOMETRY)
p->fillRect(ir, PG_VNGEOMETRY_COLOR);
else if (connectorType == PG_VNCAMERA)
p->fillRect(ir, PG_VNCAMERA_COLOR);
else if (connectorType == PG_VNLIGHT)
p->fillRect(ir, PG_VNLIGHT_COLOR);
else if (connectorType == PG_VNMATERIAL)
p->fillRect(ir, PG_VNMATERIAL_COLOR);
else if (connectorType == PG_VNFILM)
p->fillRect(ir, PG_VNFILM_COLOR);
else if (connectorType == PG_VNINTEGRATOR)
p->fillRect(ir, PG_VNINTEGRATOR_COLOR);
p->drawRect(ir);
}
//---- Draw the output connectors
for(int i = 0; i < GetOutputConnectorCount(); i++)
{
int connectorType = GetOutputConnector(i).Type;
QRectF or = GetOutputConnectorRect(i);
if (connectorType == PG_VNGEOMETRY)
p->fillRect(or, PG_VNGEOMETRY_COLOR);
else if (connectorType == PG_VNCAMERA)
p->fillRect(or, PG_VNCAMERA_COLOR);
else if (connectorType == PG_VNLIGHT)
p->fillRect(or, PG_VNLIGHT_COLOR);
else if (connectorType == PG_VNMATERIAL)
p->fillRect(or, PG_VNMATERIAL_COLOR);
else if (connectorType == PG_VNFILM)
p->fillRect(or, PG_VNFILM_COLOR);
else if (connectorType == PG_VNINTEGRATOR)
p->fillRect(or, PG_VNINTEGRATOR_COLOR);
else if (connectorType == PG_MNSPECTRUM)
p->fillRect(or, PG_MNSPECTRUM_COLOR);
else if (connectorType == PG_MNSPECTRALFUNCTION)
p->fillRect(or, PG_MNSPECTRALFUNCTION_COLOR);
else if (connectorType == PG_MNFLOAT)
p->fillRect(or, PG_MNFLOAT_COLOR);
else if (connectorType == PG_MNFRESNEL)
p->fillRect(or, PG_MNFRESNEL_COLOR);
else if (connectorType == PG_MNMICROFACETDISTRIBUTION)
p->fillRect(or, PG_MNMICROFACETDISTRIBUTION_COLOR);
p->drawRect(or);
}
//---- Name
QString nodeName = GetName();
QRectF nameRect(rect().left(), rect().top(), rect().width(), 25);
QFont font(p->font());
font.setWeight(QFont::DemiBold);
p->setFont(font);
p->setPen(Qt::white);
p->drawText(nameRect, Qt::AlignCenter, nodeName);
//---- Sub title
if (!HasSubTitle())
return;
QRectF subTitleRect(rect().left(), rect().top() + 20, rect().width(), 25);
font.setWeight(QFont::Light);
p->setFont(font);
p->drawText(subTitleRect, Qt::AlignCenter, GetSubTitle());
}
To copy to clipboard, switch view to plain text mode
Bookmarks