diff options
Diffstat (limited to 'examples/animation/stickman/node.cpp')
-rw-r--r-- | examples/animation/stickman/node.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/animation/stickman/node.cpp b/examples/animation/stickman/node.cpp new file mode 100644 index 0000000..f3468d0 --- /dev/null +++ b/examples/animation/stickman/node.cpp @@ -0,0 +1,42 @@ +#include "node.h" + +#include <QRectF> +#include <QPainter> +#include <QGraphicsSceneMouseEvent> + +Node::Node(const QPointF &pos, QGraphicsItem *parent) + : QGraphicsItem(parent), m_dragging(false) +{ + setPos(pos); +} + +Node::~Node() +{ +} + +QRectF Node::boundingRect() const +{ + return QRectF(-6.0, -6.0, 12.0, 12.0); +} + +void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + painter->setPen(Qt::white); + painter->drawEllipse(QPointF(0.0, 0.0), 5.0, 5.0); +} + +void Node::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + m_dragging = true; +} + +void Node::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if (m_dragging) + setPos(mapToParent(event->pos())); +} + +void Node::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + m_dragging = false; +}
\ No newline at end of file |