Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "NodeEdge.hpp"
- //---------------------------------------------------------------------------------//
- //---------------------------------------------------------------------------------//
- NodeEdge::NodeEdge(
- NodeEdgeType type_,
- std::shared_ptr<Socket> start_,
- std::shared_ptr<Socket> finish_
- )
- : //QGraphicsObject(nullptr)
- // , QGraphicsPathItem()
- /*,*/ nodeType(type_)
- , start(start_)
- , finish(finish_)
- {
- QGraphicsObject::setFlag(QGraphicsObject::ItemIsSelectable);
- QGraphicsPathItem::setFlag(QGraphicsPathItem::ItemIsSelectable);
- QGraphicsObject::setZValue(-1);
- QGraphicsPathItem::setZValue(-1);
- }
- //---------------------------------------------------------------------------------//
- //---------------------------------------------------------------------------------//
- void NodeEdge::setSource (QPointF source_)
- {
- source = std::move(source_);
- }
- //---------------------------------------------------------------------------------//
- //---------------------------------------------------------------------------------//
- void NodeEdge::setDestination (QPointF destination_)
- {
- destination = std::move(destination_);
- }
- //---------------------------------------------------------------------------------//
- //---------------------------------------------------------------------------------//
- QRectF NodeEdge::boundingRect () const
- {
- return NodeEdge::QGraphicsPathItem::boundingRect();
- }
- //---------------------------------------------------------------------------------//
- //---------------------------------------------------------------------------------//
- void NodeEdge::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*)
- {
- switch (nodeType)
- {
- case (NodeEdgeType::DIRECT):
- {
- updatePathDirect();
- break;
- }
- case (NodeEdgeType::BEZIER):
- {
- updatePathBezier();
- break;
- }
- }
- if (QGraphicsObject::isSelected())
- {
- QPen pen(QColor("#00ff00"));
- pen.setWidth(2.0);
- painter->setPen(pen);
- }
- else
- {
- QPen pen(QColor("#001000"));
- pen.setWidth(2.0);
- painter->setPen(pen);
- }
- painter->setBrush(Qt::NoBrush);
- painter->drawPath(QGraphicsPathItem::path());
- }
- //---------------------------------------------------------------------------------//
- //---------------------------------------------------------------------------------//
- bool NodeEdge::contains(const QPointF &point) const
- {
- return QGraphicsPathItem::contains(point);
- }
- bool NodeEdge::isObscuredBy(const QGraphicsItem *item) const
- {
- return QGraphicsPathItem::isObscuredBy(item);
- }
- QPainterPath NodeEdge::opaqueArea() const
- {
- return QGraphicsPathItem::opaqueArea();
- }
- QPainterPath NodeEdge::shape() const
- {
- return QGraphicsPathItem::shape();
- }
- int NodeEdge::type() const
- {
- return QGraphicsPathItem::type();
- }
- //---------------------------------------------------------------------------------//
- //---------------------------------------------------------------------------------//
- void NodeEdge::updatePathDirect()
- {
- setSource (start->getSocketPosition());
- setDestination (finish->getSocketPosition());
- QPainterPath pathTemp(source);
- pathTemp.lineTo(destination);
- QGraphicsPathItem::setPath(pathTemp);
- }
- //---------------------------------------------------------------------------------//
- //---------------------------------------------------------------------------------//
- void NodeEdge::updatePathBezier()
- {
- setSource (start->getSocketPosition());
- setDestination (finish->getSocketPosition());
- double distance = (destination.x() - source.x()) * 0.5;
- if (source.x() > destination.x())
- {
- distance *= -1;
- }
- QPainterPath pathTemp(source);
- pathTemp.cubicTo(source.x() + distance, source.y(),
- destination.x() - distance, destination.y(),
- destination.x(), destination.y());
- QGraphicsPathItem::setPath(pathTemp);
- }
- //---------------------------------------------------------------------------------//
- //---------------------------------------------------------------------------------//
- NodeEdge::~NodeEdge()
- {
- #ifdef QT_DEBUG
- qDebug() << "Edge deleted.";
- #endif
- }
- //---------------------------------------------------------------------------------//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement