36 m_undo_command(nullptr)
62 void PartPolygon::paint(QPainter *painter,
const QStyleOptionGraphicsItem *options, QWidget *widget)
68 QPen t = painter -> pen();
69 t.setCosmetic(options && options -> levelOfDetail < 1.0);
70 if (isSelected()) t.setColor(Qt::red);
99 QPolygonF temp_polygon;
100 for (
int j = 1 ; j < i ; ++ j)
102 temp_polygon << QPointF(qde.attribute(QString(
"x%1").arg(j)).toDouble(),
103 qde.attribute(QString(
"y%1").arg(j)).toDouble());
107 m_closed = qde.attribute(
"closed") !=
"false";
118 QDomElement xml_element = xml_document.createElement(
"polygon");
121 point = mapToScene(point);
122 xml_element.setAttribute(QString(
"x%1").arg(i), QString(
"%1").arg(point.x()));
123 xml_element.setAttribute(QString(
"y%1").arg(i), QString(
"%1").arg(point.y()));
126 if (!
m_closed) xml_element.setAttribute(
"closed",
"false");
140 for (
int i = 1 ; i <
m_polygon.count() ; ++ i)
165 Q_UNUSED(initial_selection_rect)
178 m_polygon = (mapFromScene(QPolygonF(mapped_points.toVector())));
208 prepareGeometryChange();
221 prepareGeometryChange();
235 prepareGeometryChange();
247 prepareGeometryChange();
255 prepareGeometryChange();
268 if (change == ItemSelectedHasChanged && scene())
270 if (value.toBool() ==
true)
276 if (scene()->selectedItems().size() == 1)
285 else if (change == ItemPositionHasChanged)
289 else if (change == ItemSceneChange)
297 return QGraphicsItem::itemChange(change, value);
318 if(event->type() == QEvent::GraphicsSceneMousePress)
323 else if(event->type() == QEvent::GraphicsSceneMouseMove)
328 else if (event->type() == QEvent::GraphicsSceneMouseRelease)
346 QList<QAction *> list;
352 if (qghi->contains(qghi->mapFromScene(event->scenePos())))
374 QVector <QPointF> points_vector = mapToScene(
m_polygon);
375 for (
int i = 0 ; i < points_vector.size() ; ++i)
409 QPointF new_pos =
event->scenePos();
410 if (event->modifiers() != Qt::ControlModifier)
412 new_pos = mapFromScene(new_pos);
414 prepareGeometryChange();
442 if (this->isSelected() && scene()->selectedItems().size() == 1)
460 handler->setColor(Qt::blue);
461 scene()->addItem(handler);
462 handler->installSceneEventFilter(
this);
463 handler->setZValue(this->zValue()+1);
492 QUndoCommand *undo =
new QUndoCommand(
tr(
"Ajouter un point à un polygone"));
512 if (qghi->contains(qghi->mapFromScene(point)))
521 polygon.removeAt(index);
524 QUndoCommand *undo =
new QUndoCommand(
tr(
"Supprimer un point d'un polygone"));
543 QPainterPathStroker pps;
558 QPainterPathStroker pps;
561 return (pps.createStroke(
shape));
577 r.adjust(-adjust, -adjust, adjust, adjust);
void fromXml(const QDomElement &) override
PartPolygon::fromXml Import the properties of this polygon from a xml element.
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
QPolygonF polygon() const
void addPoint(const QPointF &point)
PartPolygon::addPoint Add new point to polygon.
void adjusteHandlerPos()
PartPolygon::adjusteHandlerPos.
void removeHandler()
PartPolygon::removeHandler Remove the handlers of this item.
void removePoint()
PartPolygon::removePoint remove a point on this polygon.
QVector< QetGraphicsHandlerItem * > m_handler_vector
void sceneSelectionChanged()
PartPolygon::sceneSelectionChanged When the scene selection change, if there are several primitive se...
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartPolygon::handlerMouseReleaseEvent.
QPainterPath shape() const override
PartPolygon::shape.
~PartPolygon() override
PartPolygon::~PartPolygon.
void setLastPoint(const QPointF &point)
PartPolygon::setLastPoint Set the last point of polygon to .
void setClosed(bool close)
void addHandler()
PartPolygon::addHandler Add handlers for this item.
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
PartPolygon::paint Draw this polygon.
QList< QPointF > mapPoints(const QRectF &, const QRectF &, const QList< QPointF > &)
QETElementEditor * editor() const
The CustomElementGraphicPart class This class is the base for all home-made primitive like line...
void insertPoint()
PartPolygon::insertPoint Insert a point in this polygone.
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartPolygon::handlerMousePressEvent.
QET::ScalingMethod preferredScalingMethod() const override
PartPolygon::preferredScalingMethod This method is called by the decorator when it needs to determine...
static QPolygonF polygonForInsertPoint(const QPolygonF &old_polygon, bool closed, const QPointF &pos)
QetGraphicsHandlerUtility::polygonForInsertPoint.
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
void startUserTransformation(const QRectF &) override
PartPolygon::startUserTransformation Start the user-induced transformation, provided this primitive i...
void stylesToXml(QDomElement &) const
CustomElementGraphicPart::stylesToXml Write the curent style to xml element. The style are stored lik...
void removeLastPoint()
PartPolygon::removeLastPoint Remove the last point of polygon.
adjust the scaling movement so that the induced scaling ratios are rounded
PartPolygon(QETElementEditor *editor, QGraphicsItem *parent=nullptr)
PartPolygon::PartPolygon Constructor.
QPointF m_context_menu_pos
QRectF boundingRect() const override
PartPolygon::boundingRect.
void handleUserTransformation(const QRectF &, const QRectF &) override
PartPolygon::handleUserTransformation Handle the user-induced transformation from initial_selection_r...
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
PartPolygon::sceneEventFilter.
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartPolygon::itemChange.
QPainterPath shadowShape() const override
ScalingMethod
Supported types of interactive scaling, typically for a single element primitive. ...
bool isUseless() const override
PartPolygon::isUseless.
bool attributeIsAReal(const QDomElement &, const QString &, qreal *=nullptr)
QRectF sceneGeometricRect() const override
PartPolygon::sceneGeometricRect.
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartPolygon::handlerMouseMoveEvent.
void setPolygon(const QPolygonF &polygon)
PartPolygon::setPolygon Sets the item's polygon to be the given polygon.
void stylesFromXml(const QDomElement &)
CustomElementGraphicPart::stylesFromXml Read the style used by this, from a xml element.
void contextMenu(QPoint p, QList< QAction *> actions=QList< QAction *>())
QETElementEditor::contextMenu Display a context menu, with all available action.
const QDomElement toXml(QDomDocument &) const override
PartPolygon::toXml Export this polygin in xml.
virtual ElementScene * elementScene() const
QPropertyUndoCommand * m_undo_command
static QVector< QetGraphicsHandlerItem * > handlerForPoint(const QVector< QPointF > &points, int size=10)
QetGraphicsHandlerItem::handlerForPoint.
qreal penWeight() const
CustomElementGraphicPart::penWeight.
QList< QPointF > saved_points_
void applyStylesToQPainter(QPainter &) const
CustomElementGraphicPart::applyStylesToQPainter Apply the current style to the QPainter.
QPointF snapToGrid(QPointF point)
void setNewValue(const QVariant &new_value)
QPropertyUndoCommand::setNewValue Set the new value of the property (set with redo) to ...
void drawShadowShape(QPainter *painter)
CustomElementGraphicPart::drawShadowShape Draw a transparent blue shadow arround the shape of this it...