refactor: Node. much smaller

master
dmatetelki 10 years ago
parent 834c3239ff
commit 46357b5f61

@ -48,7 +48,7 @@ Edge* Node::edgeTo(const Node* n) const
QRectF Node::boundingRect() const QRectF Node::boundingRect() const
{ {
qreal adjust = 2; const qreal adjust = 0;
return QRectF( -m_radius - adjust, -m_radius - adjust, return QRectF( -m_radius - adjust, -m_radius - adjust,
m_radius*2 + adjust, m_radius*2 + adjust); m_radius*2 + adjust, m_radius*2 + adjust);
} }
@ -62,23 +62,16 @@ QPainterPath Node::shape() const
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWidget *) void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWidget *)
{ {
QRadialGradient gradient(-3, -3, m_radius);
if (isSelected()) { if (isSelected()) {
gradient.setCenter(3, 3); painter->setBrush(Qt::red);
gradient.setFocalPoint(3, 3);
gradient.setColorAt(0, Qt::red);
gradient.setColorAt(1, Qt::darkRed);
} else if (option->state & QStyle::State_MouseOver) { } else if (option->state & QStyle::State_MouseOver) {
gradient.setColorAt(0, Qt::green); painter->setBrush(Qt::green);
gradient.setColorAt(1, Qt::darkGreen);
} else { } else {
gradient.setColorAt(0, Qt::yellow); painter->setBrush(Qt::yellow);
gradient.setColorAt(1, Qt::darkYellow);
} }
painter->setBrush(gradient);
painter->setPen(QPen(Qt::black, 0)); painter->setPen(QPen(Qt::black, 0));
painter->drawEllipse(-m_radius, -m_radius, m_radius*2, m_radius*2); painter->drawEllipse(QRectF( -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,8 +11,7 @@ class QGraphicsSceneMouseEvent;
class Node : public QGraphicsItem class Node : public QGraphicsItem
{ {
public: public:
Node(GraphWidget *graphWidget, Node(GraphWidget *graphWidget, qreal radius = 0.2);
qreal radius = 4);
void addEdge(Edge *edge); void addEdge(Edge *edge);
void removeEdge(Edge* edge); void removeEdge(Edge* edge);

Loading…
Cancel
Save