46 setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
47 setAcceptHoverEvents(
true);
48 m_pen.setStyle(Qt::SolidLine);
50 connect(
this, &QetShapeItem::zChanged, [
this]()
53 qghi->setZValue(this->zValue()+1);
108 prepareGeometryChange();
113 prepareGeometryChange();
127 prepareGeometryChange();
144 prepareGeometryChange();
165 prepareGeometryChange();
180 prepareGeometryChange();
217 prepareGeometryChange();
237 prepareGeometryChange();
241 }
while (i < number);
249 return shape().boundingRect().adjusted(-6, -6, 6, 6);
270 path.addEllipse(QRectF(
m_P1,
m_P2));
283 QPainterPathStroker pps;
285 pps.setJoinStyle(Qt::RoundJoin);
286 path = pps.createStroke(path);
300 Q_UNUSED(option); Q_UNUSED(widget);
303 painter->setRenderHint(QPainter::Antialiasing,
true);
304 painter->setPen(
m_pen);
311 QColor color(Qt::darkBlue);
313 painter ->
setBrush (QBrush (color));
314 painter ->
setPen (Qt::NoPen);
315 painter -> drawPath (
shape());
316 painter -> restore ();
321 case Line: painter->drawLine(QLineF(
m_P1,
m_P2));
break;
338 QetGraphicsItem::hoverEnterEvent(event);
349 QetGraphicsItem::hoverLeaveEvent(event);
357 if (event->button() == Qt::LeftButton) {
371 if (change == ItemSelectedHasChanged)
373 if (value.toBool() ==
true) {
386 else if (change == ItemPositionHasChanged) {
389 else if (change == ItemSceneHasChanged)
397 return QGraphicsItem::itemChange(change, value);
418 if(event->type() == QEvent::GraphicsSceneMousePress)
423 else if(event->type() == QEvent::GraphicsSceneMouseMove)
428 else if (event->type() == QEvent::GraphicsSceneMouseRelease)
450 if (
diagram()->selectedItems().isEmpty()) {
451 this->setSelected(
true);
454 if (isSelected() && scene()->selectedItems().size() == 1)
459 for (QGraphicsView *view :
diagram()->views())
461 if (view->isActiveWindow())
471 QScopedPointer<QMenu> menu(
new QMenu());
478 if (qghi->contains(qghi->mapFromScene(event->scenePos())))
486 menu.data()->addSeparator();
488 menu.data()->exec(event->screenPos());
496 QetGraphicsItem::contextMenuEvent(event);
510 qghi->setColor(Qt::darkGreen);
517 qghi->setColor(Qt::blue);
527 qghi->setColor(Qt::darkGreen);
536 qghi->setColor(Qt::magenta);
546 qghi->setColor(Qt::blue);
557 QVector <QPointF> points_vector;
579 if(!points_vector.isEmpty() && scene())
585 handler->setZValue(this->zValue()+1);
586 handler->setColor(Qt::blue);
587 scene()->addItem(handler);
588 handler->installSceneEventFilter(
this);
604 QVector <QPointF> points_vector;
632 points_vector = mapToScene(points_vector);
633 for (
int i = 0 ; i < points_vector.size() ; ++i)
653 QUndoCommand *undo =
new QUndoCommand(
tr(
"Ajouter un point à un polygone"));
675 if (qghi->contains(qghi->mapFromScene(point)))
684 polygon.removeAt(index);
687 QUndoCommand *undo =
new QUndoCommand(
tr(
"Supprimer un point d'un polygone"));
722 QPointF new_pos =
event->scenePos();
723 if (event->modifiers() != Qt::ControlModifier)
725 new_pos = mapFromScene(new_pos);
730 prepareGeometryChange();
770 prepareGeometryChange();
829 undo->setText(
tr(
"Modifier %1").arg(
name()));
843 if (e.tagName() !=
"shape")
return (
false);
846 m_closed = e.attribute(
"closed",
"0").toInt();
850 QString
type = e.attribute(
"type");
852 if (
type.size() == 1)
854 switch(e.attribute(
"type",
"0").toInt())
865 QMetaEnum me = metaObject()->enumerator(metaObject()->indexOfEnumerator(
"ShapeType"));
871 m_P1.setX(e.attribute(
"x1",
nullptr).toDouble());
872 m_P1.setY(e.attribute(
"y1",
nullptr).toDouble());
873 m_P2.setX(e.attribute(
"x2",
nullptr).toDouble());
874 m_P2.setY(e.attribute(
"y2",
nullptr).toDouble());
878 setXRadius(e.attribute(
"rx",
"0").toDouble());
879 setYRadius(e.attribute(
"ry",
"0").toDouble());
884 m_polygon << QPointF(
de.attribute(
"x",
nullptr).toDouble(),
de.attribute(
"y",
nullptr).toDouble());
887 setZValue(e.attribute(
"z", QString::number(this->zValue())).toDouble());
900 QDomElement result = document.createElement(
"shape");
903 QMetaEnum me = metaObject()->enumerator(metaObject()->indexOfEnumerator(
"ShapeType"));
904 result.setAttribute(
"type", me.valueToKey(
m_shapeType));
907 result.setAttribute(
"is_movable",
bool(
is_movable_));
908 result.setAttribute(
"closed",
bool(
m_closed));
912 result.setAttribute(
"x1", QString::number(mapToScene(
m_P1).x()));
913 result.setAttribute(
"y1", QString::number(mapToScene(
m_P1).y()));
914 result.setAttribute(
"x2", QString::number(mapToScene(
m_P2).x()));
915 result.setAttribute(
"y2", QString::number(mapToScene(
m_P2).y()));
922 if (x >
rect.width()/2) {
926 if (y >
rect.height()/2) {
930 result.setAttribute(
"rx", QString::number(
m_xRadius));
931 result.setAttribute(
"ry", QString::number(
m_yRadius));
936 QDomElement points = document.createElement(
"points");
939 QDomElement point = document.createElement(
"point");
940 QPointF pf = mapToScene(p);
941 point.setAttribute(
"x", QString::number(pf.x()));
942 point.setAttribute(
"y", QString::number(pf.y()));
943 points.appendChild(point);
945 result.appendChild(points);
947 result.setAttribute(
"z", QString::number(this->zValue()));
966 default:
return false;
976 if (
diagram() -> isReadOnly())
return;
988 case Line:
return tr(
"une ligne");
991 case Polygon:
return tr(
"une polyligne");
992 default:
return tr(
"une shape");
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
QetShapeItem::sceneEventFilter.
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override
QetShapeItem::contextMenuEvent.
bool setPolygon(const QPolygonF &polygon)
QetShapeItem::setPolygon Set this item geometry to polygon (only available if shape is a polyline) ...
QVector< QetGraphicsHandlerItem * > m_handler_vector
QRectF boundingRect() const override
QetShapeItem::boundingRect.
virtual bool fromXml(const QDomElement &)
QetShapeItem::fromXml Build this item from the xml description.
void removePoints(int number=1)
QetShapeItem::removePoints Number of point to remove on the polygon If is superior to number of poly...
static int getcolorCode(const long red, const long green, const long blue)
Createdxf::getcolorCode This function returns the ACI color which is the "nearest" color to the color...
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
QetShapeItem::itemChange.
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
QPolygonF polygon() const
static void drawRectangle(const QString &filepath, double, double, double, double, const int &colorcode)
Diagram * diagram() const
QetGraphicsItem::diagram return the diagram of this item.
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
QetShapeItem::handlerMousePressEvent.
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
QetShapeItem::hoverLeaveEvent Handle hover leave event.
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
QetGraphicsItem::mousePressEvent handle the mouse click.
void adjusteHandlerPos()
QetShapeItem::adjusteHandlerPos Adjust the position of the handler item.
static QVector< QPointF > pointForRadiusRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
QetGraphicsHandlerUtility::pointForRadiusRect.
static qreal radiusForPosAtIndex(const QRectF &rect, const QPointF &pos, int index, Qt::SizeMode mode=Qt::AbsoluteSize)
QetGraphicsHandlerUtility::radiusForPosAtIndex.
QDomElement penToXml(QDomDocument &parent_document, const QPen &pen)
QETXML::penToXml Write attribute of a QPen in xml element.
QetShapeItem(QPointF, QPointF=QPointF(0, 0), ShapeType=Line, QGraphicsItem *parent=nullptr)
QetShapeItem::QetShapeItem Constructor of shape item. point 1 and 2 must be in scene coordinate...
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
QetShapeItem::handlerMouseMoveEvent.
The PropertiesEditorDialog class Create a dialog to edit some properties of a thing. Only create a instance of this class and call exec, all is done for you in this class. The first argument (a template) must be a subclass of QWidget and provide the 3 methods bellow : QString::title() void::apply() void::reset() You can subclass the interface PropertiesEditorWidget who provide all this methods. This dialog take ownership of the editor, so the editor will be deleted by this dialog.
void setP2(const QPointF &P2)
QetShapeItem::setP2 Set the second point of this item. If this item is a polyline, the last point of the polyline is replaced by P2.
QPainterPath shape() const override
QetShapeItem::shape.
int type() const override
static QPolygonF polygonForInsertPoint(const QPolygonF &old_polygon, bool closed, const QPointF &pos)
QetGraphicsHandlerUtility::polygonForInsertPoint.
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
static QRectF mirrorRectForPosAtIndex(const QRectF &old_rect, const QPointF &pos, int index)
QetGraphicsHandlerUtility::mirrorRectForPosAtIndex Return a rectangle after modification of the point...
QDomElement brushToXml(QDomDocument &parent_document, const QBrush &brush)
QETXML::brushToXml Write attribute of a QBrush in xml element.
virtual QDomElement toXml(QDomDocument &document) const
QetShapeItem::toXml Save this item to xml element.
static QRectF rectForPosAtIndex(const QRectF &old_rect, const QPointF &pos, int index)
QetGraphicsHandlerUtility::rectForPosAtIndex Return a rectangle after modification of the point '' at...
QList< QDomElement > findInDomElement(const QDomElement &, const QString &)
QPen penFromXml(const QDomElement &element)
QETXML::penFromXml Build a QPen from a xml description.
int pointsCount() const
QetShapeItem::pointCount.
ShapeType m_shapeType
ATTRIBUTES.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
QetShapeItem::paint Paint this item.
void editProperty() override
QetShapeItem::editProperty Edit the property of this item.
void setClosed(bool close)
QetShapeItem::setClosed Close this item, have effect only if this item is a polygon.
bool setRect(const QRectF &rect)
QetShapeItem::setRect Set this item geometry to rect (only available if shape is a rectangle or an el...
bool m_modifie_radius_equaly
QList< QAction * > contextMenuActions() const
DiagramView::contextMenuActions.
void setPen(const QPen &pen)
QetShapeItem::setPen Set the pen to use for draw the shape.
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
QetShapeItem::hoverEnterEvent Handle hover enter event.
static QPointF snapToGrid(const QPointF &p)
Diagram::snapToGrid Return a nearest snap point of p.
static QVector< QPointF > pointsForRect(const QRectF &rect)
QetGraphicsHandlerUtility::pointsForRect Return the keys points of the rectangle, stored in a vector...
static void drawEllipse(const QString &filepath, const QRectF &rect, const int &colorcode)
Createdxf::drawEllipse Conveniance function for draw ellipse.
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
QetShapeItem::handlerMouseReleaseEvent.
QPointF m_context_menu_pos
bool setLine(const QLineF &line)
QetShapeItem::setLine Set item geometry to line (only available for line shape)
static QVector< QetGraphicsHandlerItem * > handlerForPoint(const QVector< QPointF > &points, int size=10)
QetGraphicsHandlerItem::handlerForPoint.
void setBrush(const QBrush &brush)
QetShapeItem::setBrush Set the brush to use for the fill the shape.
void setAnimated(bool animate=true, bool first_time=true)
QPropertyUndoCommand::setAnimated.
QString name() const override
QetShapeItem::name.
static void drawLine(const QString &filapath, double, double, double, double, const int &clorcode)
QBrush brushFromXml(const QDomElement &element)
QETXML::brushFromXml Build a QBrush from a xml description.
void setNextPoint(QPointF P)
QetShapeItem::setNextPoint Add a new point to the curent polygon.
virtual bool toDXF(const QString &filepath, const QPen &pen)
QetShapeItem::toDXF Draw this element to the dxf document.
void switchResizeMode()
QetShapeItem::switchResizeMode.