* Added the m_rotate_action to qetelementeditor.ui * Adding QAction to qetelementeditor.cpp and connecting it to new slot RotateElementsCommand defined in editorcommands.cpp

* Some types of elements need to specialize the setRotation method in order to behave correctly :
- PartTerminal needs to call setOrientation
- PartLine, PartRectangle and PartPolygon need a different rotation center.
This commit is contained in:
Adrien Allain
2021-09-13 20:38:39 +02:00
committed by Laurent Trinques
parent 9135099dbf
commit c640d96bca
12 changed files with 204 additions and 5 deletions

View File

@@ -603,6 +603,19 @@ void PartLine::setSecondEndLength(const qreal &l)
emit secondEndLengthChanged();
}
void PartLine::setRotation(qreal angle) {
QTransform rotation = QTransform().translate(m_line.p1().x(),m_line.p1().y()).rotate(angle-m_rot).translate(-m_line.p1().x(),-m_line.p1().y());
m_rot=angle;
setLine(rotation.map(m_line));
}
qreal PartLine::rotation() const {
return m_rot;
}
/**
@brief PartLine::path
@return this line has a QPainterPath.

View File

@@ -94,6 +94,8 @@ class PartLine : public CustomElementGraphicPart
void setFirstEndLength(const qreal &l);
qreal secondEndLength() const {return second_length;}
void setSecondEndLength(const qreal &l);
void setRotation(qreal angle);
qreal rotation() const;
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
@@ -124,5 +126,6 @@ class PartLine : public CustomElementGraphicPart
int m_vector_index = -1;
QPropertyUndoCommand *m_undo_command;
QVector<QetGraphicsHandlerItem *> m_handler_vector;
qreal m_rot;
};
#endif

View File

@@ -293,6 +293,21 @@ void PartPolygon::resetAllHandlerColor()
}
}
void PartPolygon::setRotation(qreal angle) {
QTransform rotation = QTransform().translate(m_polygon.first().x(),m_polygon.first().y()).rotate(angle-m_rot).translate(-m_polygon.first().x(),-m_polygon.first().y());
m_rot=angle;
setPolygon(rotation.map(m_polygon));
}
qreal PartPolygon::rotation() const {
return m_rot;
}
/**
@brief PartPolygon::itemChange
@param change

View File

@@ -87,6 +87,9 @@ class PartPolygon : public CustomElementGraphicPart
void setHandlerColor(QPointF pos, const QColor &color) final;
void resetAllHandlerColor() final;
void setRotation (qreal angle);
qreal rotation () const;
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
@@ -114,5 +117,6 @@ class PartPolygon : public CustomElementGraphicPart
QAction *m_insert_point,
*m_remove_point;
QPointF m_context_menu_pos;
qreal m_rot;
};
#endif

View File

@@ -30,7 +30,9 @@
*/
PartRectangle::PartRectangle(QETElementEditor *editor, QGraphicsItem *parent) :
CustomElementGraphicPart(editor, parent)
{}
{
m_rot=0;
}
/**
@brief PartRectangle::~PartRectangle
@@ -169,6 +171,18 @@ void PartRectangle::setYRadius(qreal Y)
emit YRadiusChanged();
}
void PartRectangle::setRotation(qreal angle) {
QTransform rotation = QTransform().rotate(angle-m_rot);
m_rot=angle;
setRect(rotation.mapRect(m_rect));
}
qreal PartRectangle::rotation() const {
return m_rot;
}
/**
@brief PartRectangle::sceneGeometricRect
@return the minimum, margin-less rectangle this part can fit into, in scene
@@ -187,7 +201,7 @@ QRectF PartRectangle::sceneGeometricRect() const
*/
QPointF PartRectangle::sceneTopLeft() const
{
return(mapToScene(rect().topLeft()));
return(mapToScene(rect().topLeft()));
}
/**

View File

@@ -34,6 +34,7 @@ class PartRectangle : public CustomElementGraphicPart
Q_PROPERTY(QRectF rect READ rect WRITE setRect)
Q_PROPERTY(qreal xRadius READ XRadius WRITE setXRadius NOTIFY XRadiusChanged)
Q_PROPERTY(qreal yRadius READ YRadius WRITE setYRadius NOTIFY YRadiusChanged)
Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
// constructors, destructor
public:
@@ -47,6 +48,7 @@ class PartRectangle : public CustomElementGraphicPart
void rectChanged();
void XRadiusChanged();
void YRadiusChanged();
void rotationChanged();
// methods
public:
@@ -69,6 +71,8 @@ class PartRectangle : public CustomElementGraphicPart
void setXRadius(qreal X);
qreal YRadius() const {return m_yRadius;}
void setYRadius(qreal Y);
void setRotation(qreal angle);
qreal rotation() const;
QRectF sceneGeometricRect() const override;
virtual QPointF sceneTopLeft() const;
@@ -109,5 +113,6 @@ class PartRectangle : public CustomElementGraphicPart
m_old_xRadius,
m_old_yRadius;
bool m_modifie_radius_equaly = false;
qreal m_rot;
};
#endif

View File

@@ -140,6 +140,7 @@ QRectF PartTerminal::boundingRect() const
return(br);
}
/**
Definit l'orientation de la borne
@param ori la nouvelle orientation de la borne
@@ -151,6 +152,32 @@ void PartTerminal::setOrientation(Qet::Orientation ori) {
updateSecondPoint();
emit orientationChanged();
}
/**
Redéfinit la fonction de rotation pour la traduire en orientation de la borne
@param angle
*/
void PartTerminal::setRotation(qreal angle) {
qreal angle_mod = std::fmod(angle,360);
Qet::Orientation new_ori = Qet::North;
if (0 <= angle_mod && angle_mod < 90 ) new_ori = Qet::North;
else if (90 <= angle_mod && angle_mod < 180) new_ori = Qet::East;
else if (180 <= angle_mod && angle_mod < 270) new_ori = Qet::South;
else new_ori = Qet::West;
setOrientation(new_ori);
}
qreal PartTerminal::rotation() const {
switch (d->m_orientation) {
case Qet::North : return 0;
case Qet::East : return 90;
case Qet::South : return 180;
case Qet::West : return 270;
}
}
/**
@brief PartTerminal::setName
@param name

View File

@@ -72,7 +72,11 @@ class PartTerminal : public CustomElementGraphicPart
void handleUserTransformation(const QRectF &, const QRectF &) override;
Qet::Orientation orientation() const {return d -> m_orientation;}
void setOrientation(Qet::Orientation ori);
void setOrientation(Qet::Orientation ori);
qreal rotation() const;
void setRotation(qreal angle);
QString name() const override { return d -> m_name; }
void setName(QString& name);