From b35ce293bf028d9b3c3ff1e55ff8b6a47fb4511d Mon Sep 17 00:00:00 2001 From: Tats Date: Sun, 28 Dec 2014 18:01:39 -0500 Subject: [PATCH] Sync of vertices control points retroactive (to make ellipse works) (not fully working yet). --- Mapper.cpp | 38 ++++++++++++++++++++++++++++---------- Mapper.h | 1 + 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Mapper.cpp b/Mapper.cpp index 6059405..fd8c73f 100644 --- a/Mapper.cpp +++ b/Mapper.cpp @@ -37,23 +37,31 @@ ShapeGraphicsItem::ShapeGraphicsItem(Mapping::ptr mapping, bool output) bool ShapeGraphicsItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event) { - VertexGraphicsItem* child = static_cast(watched); - Q_ASSERT(child); - // Change vertex in model according to moved item. if (event->type() == QEvent::GraphicsSceneMouseMove) { + QGraphicsSceneMoveEvent* moveEvent = static_cast(event); + Q_ASSERT(moveEvent); + int idx = childItems().indexOf(watched); Q_ASSERT(idx != -1); - QPointF pos = child->pos(); + + QPointF pos = moveEvent->newPos(); _shape->setVertex(idx, pos); + + _syncVertices(); + + // Refresh this shape. + update(); + + // override default + return true; + } + else + { + // Returns false to allow the child item to process its event. + return false; } - - // Refresh this shape. - update(); - - // Returns false to allow the child item to process its event. - return false; } void ShapeGraphicsItem::_createVertices() @@ -85,6 +93,16 @@ void ShapeGraphicsItem::_syncShape() } } +void ShapeGraphicsItem::_syncVertices() +{ + for (int i=0; i<_shape->nVertices(); i++) + { + QPointF pos = _shape->getVertex(i);// - this->pos(); + childItems().at(i)->setPos(pos); + childItems().at(i)->update(); + } +} + QPainterPath PolygonColorGraphicsItem::shape() const { QPainterPath path; diff --git a/Mapper.h b/Mapper.h index 6d14143..40730e0 100644 --- a/Mapper.h +++ b/Mapper.h @@ -77,6 +77,7 @@ public: protected: virtual void _createVertices(); virtual void _syncShape(); + virtual void _syncVertices(); Mapping::ptr _mapping; MShape::ptr _shape;