Node has m_radius

master
dmatetelki 10 years ago
parent 2728f36c25
commit 4f3f30d24b

@ -8,8 +8,9 @@
#include <QtGui/QStyleOption> #include <QtGui/QStyleOption>
Node::Node(GraphWidget *graphWidget) Node::Node(GraphWidget *graphWidget, qreal radius)
: m_graphWidget(graphWidget) : m_graphWidget(graphWidget)
, m_radius(radius)
{ {
setFlag(ItemIsMovable); setFlag(ItemIsMovable);
setFlag(ItemSendsGeometryChanges); setFlag(ItemSendsGeometryChanges);
@ -45,24 +46,23 @@ Edge* Node::edgeTo(const Node* n) const
return 0; return 0;
} }
QRectF Node::boundingRect() const QRectF Node::boundingRect() const
{ {
qreal adjust = 2; qreal adjust = 2;
return QRectF( -10 - adjust, -10 - adjust, return QRectF( -m_radius - adjust, -m_radius - adjust,
23 + adjust, 23 + adjust); m_radius*2 + adjust, m_radius*2 + adjust);
} }
QPainterPath Node::shape() const QPainterPath Node::shape() const
{ {
QPainterPath path; QPainterPath path;
path.addEllipse(-10, -10, 20, 20); path.addEllipse(-m_radius, -m_radius, m_radius*2, m_radius*2);
return path; return path;
} }
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWidget *) void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWidget *)
{ {
QRadialGradient gradient(-3, -3, 10); QRadialGradient gradient(-3, -3, m_radius);
if (isSelected()) { if (isSelected()) {
gradient.setCenter(3, 3); gradient.setCenter(3, 3);
gradient.setFocalPoint(3, 3); gradient.setFocalPoint(3, 3);
@ -78,7 +78,7 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWid
painter->setBrush(gradient); painter->setBrush(gradient);
painter->setPen(QPen(Qt::black, 0)); 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) QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)

@ -11,7 +11,8 @@ class QGraphicsSceneMouseEvent;
class Node : public QGraphicsItem class Node : public QGraphicsItem
{ {
public: public:
Node(GraphWidget *graphWidget); Node(GraphWidget *graphWidget,
qreal radius = 4);
void addEdge(Edge *edge); void addEdge(Edge *edge);
void removeEdge(Edge* edge); void removeEdge(Edge* edge);
@ -33,6 +34,7 @@ protected:
private: private:
QList<Edge *> edgeList; QList<Edge *> edgeList;
GraphWidget *m_graphWidget; GraphWidget *m_graphWidget;
qreal m_radius;
}; };
#endif #endif

Loading…
Cancel
Save