Sync of vertices control points retroactive (to make ellipse works) (not fully working yet).

This commit is contained in:
Tats
2014-12-28 18:01:39 -05:00
parent 31e315363e
commit b35ce293bf
2 changed files with 29 additions and 10 deletions
+28 -10
View File
@@ -37,23 +37,31 @@ ShapeGraphicsItem::ShapeGraphicsItem(Mapping::ptr mapping, bool output)
bool ShapeGraphicsItem::sceneEventFilter(QGraphicsItem * watched, QEvent * event)
{
VertexGraphicsItem* child = static_cast<VertexGraphicsItem*>(watched);
Q_ASSERT(child);
// Change vertex in model according to moved item.
if (event->type() == QEvent::GraphicsSceneMouseMove)
{
QGraphicsSceneMoveEvent* moveEvent = static_cast<QGraphicsSceneMoveEvent*>(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;