Element editor : improve polygon edition

This commit is contained in:
joshua
2019-09-01 20:29:26 +02:00
parent 3fa071841c
commit 86b610dc84
10 changed files with 456 additions and 279 deletions

View File

@@ -91,6 +91,8 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar
QVariant property (const char *name) const override {return QObject::property(name);}
virtual QPainterPath shadowShape ()const = 0;
virtual void setHandlerColor(QPointF /*pos*/, const QColor &/*color*/) {}
virtual void resetAllHandlerColor() {}
protected:
void stylesToXml (QDomElement &) const;

View File

@@ -254,7 +254,33 @@ void PartPolygon::setClosed(bool close)
if (m_closed == close) return;
prepareGeometryChange();
m_closed = close;
emit closedChange();
emit closedChange();
}
/**
* @brief PartPolygon::setHandlerColor
* Set the handler at pos @pos (in polygon coordinate) to color @color.
* @param pos
* @param color
*/
void PartPolygon::setHandlerColor(QPointF pos, const QColor &color)
{
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
if (qghi->pos() == mapToScene(pos)) {
qghi->setColor(color);
}
}
}
/**
* @brief PartPolygon::resetAllHandlerColor
* Reset the color of every handlers
*/
void PartPolygon::resetAllHandlerColor()
{
for (QetGraphicsHandlerItem *qghi : m_handler_vector) {
qghi->setColor(Qt::blue);
}
}
/**
@@ -518,6 +544,7 @@ void PartPolygon::removePoint()
if (index > -1 && index<m_handler_vector.count())
{
QPolygonF polygon = this->polygon();
qDebug() << index;
polygon.removeAt(index);
//Wrap the undo for avoid to merge the undo commands when user add several points.

View File

@@ -84,6 +84,9 @@ class PartPolygon : public CustomElementGraphicPart
bool isClosed () const {return m_closed;}
void setClosed (bool close);
void setHandlerColor(QPointF pos, const QColor &color) final;
void resetAllHandlerColor() final;
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;