From 4f3f30d24b5c9a8e7413a4460ed2a1024cd05677 Mon Sep 17 00:00:00 2001 From: dmatetelki Date: Fri, 22 May 2015 10:05:37 +0200 Subject: [PATCH] Node has m_radius --- lib/qtgraph/node.cpp | 16 ++++++++-------- lib/qtgraph/node.hpp | 4 +++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/qtgraph/node.cpp b/lib/qtgraph/node.cpp index 167e985..13fcc39 100644 --- a/lib/qtgraph/node.cpp +++ b/lib/qtgraph/node.cpp @@ -8,8 +8,9 @@ #include -Node::Node(GraphWidget *graphWidget) - : m_graphWidget(graphWidget) +Node::Node(GraphWidget *graphWidget, qreal radius) + : m_graphWidget(graphWidget) + , m_radius(radius) { setFlag(ItemIsMovable); setFlag(ItemSendsGeometryChanges); @@ -45,24 +46,23 @@ Edge* Node::edgeTo(const Node* n) const return 0; } - QRectF Node::boundingRect() const { qreal adjust = 2; - return QRectF( -10 - adjust, -10 - adjust, - 23 + adjust, 23 + adjust); + return QRectF( -m_radius - adjust, -m_radius - adjust, + m_radius*2 + adjust, m_radius*2 + adjust); } QPainterPath Node::shape() const { QPainterPath path; - path.addEllipse(-10, -10, 20, 20); + path.addEllipse(-m_radius, -m_radius, m_radius*2, m_radius*2); return path; } void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWidget *) { - QRadialGradient gradient(-3, -3, 10); + QRadialGradient gradient(-3, -3, m_radius); if (isSelected()) { gradient.setCenter(3, 3); gradient.setFocalPoint(3, 3); @@ -78,7 +78,7 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWid painter->setBrush(gradient); painter->setPen(QPen(Qt::black, 0)); - painter->drawEllipse(-10, -10, 20, 20); + painter->drawEllipse(-m_radius, -m_radius, m_radius*2, m_radius*2); } QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value) diff --git a/lib/qtgraph/node.hpp b/lib/qtgraph/node.hpp index 390e43f..e766d98 100644 --- a/lib/qtgraph/node.hpp +++ b/lib/qtgraph/node.hpp @@ -11,7 +11,8 @@ class QGraphicsSceneMouseEvent; class Node : public QGraphicsItem { public: - Node(GraphWidget *graphWidget); + Node(GraphWidget *graphWidget, + qreal radius = 4); void addEdge(Edge *edge); void removeEdge(Edge* edge); @@ -33,6 +34,7 @@ protected: private: QList edgeList; GraphWidget *m_graphWidget; + qreal m_radius; }; #endif