52 QPen t = painter -> pen();
53 t.setCosmetic(options && options -> levelOfDetail < 1.0);
58 t.setJoinStyle(Qt::MiterJoin);
61 if (!
rect().width() || !
rect().height())
82 QDomElement xml_element = xml_document.createElement(
"rect");
84 xml_element.setAttribute(
"x", QString(
"%1").arg(top_left.x()));
85 xml_element.setAttribute(
"y", QString(
"%1").arg(top_left.y()));
86 xml_element.setAttribute(
"width", QString(
"%1").arg(
m_rect.width()));
87 xml_element.setAttribute(
"height", QString(
"%1").arg(
m_rect.height()));
91 if (x >
rect.width()/2) {
95 if (y >
rect.height()/2) {
99 xml_element.setAttribute(
"rx", QString::number(
m_xRadius));
100 xml_element.setAttribute(
"ry", QString::number(
m_yRadius));
114 setPos(mapFromScene(qde.attribute(
"x",
"0").toDouble(),
115 qde.attribute(
"y",
"0").toDouble()));
117 QRectF
rect(QPointF(0,0), QSizeF(qde.attribute(
"width",
"0").toDouble(),
118 qde.attribute(
"height",
"0").toDouble()));
121 setXRadius(qde.attribute(
"rx",
"0").toDouble());
122 setYRadius(qde.attribute(
"ry",
"0").toDouble());
141 prepareGeometryChange();
179 return(mapToScene(
rect().topLeft()));
191 QPainterPathStroker pps;
203 QPainterPathStroker pps;
206 return (pps.createStroke(
shape));
220 QRectF r =
m_rect.normalized();
221 r.adjust(-adjust, -adjust, adjust, adjust);
232 return(
rect().isNull());
243 Q_UNUSED(initial_selection_rect)
258 setRect(QRectF(mapFromScene(mapped_points.at(0)), mapFromScene(mapped_points.at(1))));
268 if (event->button() == Qt::LeftButton &&
event->buttonDownPos(Qt::LeftButton) ==
event->pos())
282 if (change == ItemSelectedHasChanged && scene())
284 if (value.toBool() ==
true)
290 if (scene()->selectedItems().size() == 1)
299 else if (change == ItemPositionHasChanged)
303 else if (change == ItemSceneChange)
311 return QGraphicsItem::itemChange(change, value);
332 if(event->type() == QEvent::GraphicsSceneMousePress)
337 else if(event->type() == QEvent::GraphicsSceneMouseMove)
342 else if (event->type() == QEvent::GraphicsSceneMouseRelease)
363 qghi->setColor(Qt::darkGreen);
372 qghi->setColor(Qt::magenta);
382 qghi->setColor(Qt::blue);
396 QVector <QPointF> points_vector;
407 points_vector = mapToScene(points_vector);
408 for (
int i = 0 ; i < points_vector.size() ; ++i)
446 QPointF new_pos =
event->scenePos();
447 if (event->modifiers() != Qt::ControlModifier)
449 new_pos = mapFromScene(new_pos);
480 QUndoCommand *undo =
new QUndoCommand(
"Modifier un rectangle");
504 if (this->isSelected() && scene()->selectedItems().size() == 1)
530 else {
color = Qt::magenta;}
532 handler->setColor(
color);
533 scene()->addItem(handler);
534 handler->installSceneEventFilter(
this);
535 handler->setZValue(this->zValue()+1);
void sceneSelectionChanged()
PartRectangle::sceneSelectionChanged When the scene selection change, if there are several primitive ...
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
void adjusteHandlerPos()
PartRectangle::adjusteHandlerPos.
virtual QPointF sceneTopLeft() const
PartRectangle::sceneTopLeft.
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
bool m_modifie_radius_equaly
QRectF boundingRect() const override
PartRectangle::boundingRect.
const QDomElement toXml(QDomDocument &) const override
PartRectangle::toXml Export this rectangle in xml.
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
PartRectangle(QETElementEditor *, QGraphicsItem *parent=nullptr)
PartRectangle::PartRectangle Constructor.
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
PartRectangle::paint Draw this Rectangle.
QPainterPath shape() const override
PartRectangle::shape.
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.
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
PartRectangle::sceneEventFilter.
void setRect(const QRectF &rect)
PartRectangle::setRect Sets the item's rectangle to be the given rectangle.
static void drawCross(const QPointF ¢er, QPainter *painter)
CustomElementGraphicPart::drawCross Draw a cross at pos center.
QList< QPointF > mapPoints(const QRectF &, const QRectF &, const QList< QPointF > &)
The CustomElementGraphicPart class This class is the base for all home-made primitive like line...
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartRectangle::handlerMouseMoveEvent.
static QRectF mirrorRectForPosAtIndex(const QRectF &old_rect, const QPointF &pos, int index)
QetGraphicsHandlerUtility::mirrorRectForPosAtIndex Return a rectangle after modification of the point...
void stylesToXml(QDomElement &) const
CustomElementGraphicPart::stylesToXml Write the curent style to xml element. The style are stored lik...
static QRectF rectForPosAtIndex(const QRectF &old_rect, const QPointF &pos, int index)
QetGraphicsHandlerUtility::rectForPosAtIndex Return a rectangle after modification of the point '' at...
void addHandler()
PartRectangle::addHandler Add handlers for this item.
QList< QPointF > saved_points_
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
void fromXml(const QDomElement &) override
PartRectangle::fromXml Import the properties of this rectangle from a xml element.
void handleUserTransformation(const QRectF &, const QRectF &) override
PartRectangle::handleUserTransformation Handle the user-induced transformation from initial_selection...
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
PartRectangle::mouseReleaseEvent Handle mouse release event.
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartRectangle::itemChange.
void removeHandler()
PartRectangle::removeHandler Remove the handlers of this item.
QPainterPath shadowShape() const override
bool isUseless() const override
PartRectangle::isUseless.
void stylesFromXml(const QDomElement &)
CustomElementGraphicPart::stylesFromXml Read the style used by this, from a xml element.
static QVector< QPointF > pointsForRect(const QRectF &rect)
QetGraphicsHandlerUtility::pointsForRect Return the keys points of the rectangle, stored in a vector...
~PartRectangle() override
PartRectangle::~PartRectangle.
QVector< QetGraphicsHandlerItem * > m_handler_vector
QRectF sceneGeometricRect() const override
PartRectangle::sceneGeometricRect.
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartRectangle::handlerMousePressEvent.
void switchResizeMode()
PartRectangle::switchResizeMode.
virtual ElementScene * elementScene() const
static QVector< QetGraphicsHandlerItem * > handlerForPoint(const QVector< QPointF > &points, int size=10)
QetGraphicsHandlerItem::handlerForPoint.
void setAnimated(bool animate=true, bool first_time=true)
QPropertyUndoCommand::setAnimated.
qreal penWeight() const
CustomElementGraphicPart::penWeight.
void startUserTransformation(const QRectF &) override
PartRectangle::startUserTransformation Start the user-induced transformation, provided this primitive...
void applyStylesToQPainter(QPainter &) const
CustomElementGraphicPart::applyStylesToQPainter Apply the current style to the QPainter.
QPointF snapToGrid(QPointF point)
void drawShadowShape(QPainter *painter)
CustomElementGraphicPart::drawShadowShape Draw a transparent blue shadow arround the shape of this it...