mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
* 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:
parent
9135099dbf
commit
c640d96bca
@ -609,3 +609,67 @@ void changeElementDataCommand::redo() {
|
|||||||
m_scene->setElementData(m_new);
|
m_scene->setElementData(m_new);
|
||||||
QUndoCommand::redo();
|
QUndoCommand::redo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RotateElementsCommand::RotateElementsCommand(ElementScene *scene, QUndoCommand *parent) :
|
||||||
|
ElementEditionCommand(QObject::tr("Pivoter la selection", "undo caption"), scene, nullptr, parent)
|
||||||
|
{
|
||||||
|
m_items = scene->selectedItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief RotateElementsCommand::undo
|
||||||
|
*/
|
||||||
|
void RotateElementsCommand::undo()
|
||||||
|
{
|
||||||
|
for (QGraphicsItem *item : m_items)
|
||||||
|
{
|
||||||
|
if (item->type() == PartTerminal::Type) {
|
||||||
|
PartTerminal* term = qgraphicsitem_cast<PartTerminal*>(item);
|
||||||
|
term->setRotation(term->rotation()-90);
|
||||||
|
}
|
||||||
|
else if (item->type() == PartRectangle::Type) {
|
||||||
|
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
|
||||||
|
rect->setRotation(rect->rotation()-90);
|
||||||
|
}
|
||||||
|
else if (item->type() == PartLine::Type) {
|
||||||
|
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
|
||||||
|
line->setRotation(line->rotation()-90);
|
||||||
|
}
|
||||||
|
else if (item->type() == PartPolygon::Type) {
|
||||||
|
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
|
||||||
|
poly->setRotation(poly->rotation()-90);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
item->setRotation(item->rotation()-90);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
@brief RotateElementsCommand::redo
|
||||||
|
*/
|
||||||
|
void RotateElementsCommand::redo()
|
||||||
|
{
|
||||||
|
for (QGraphicsItem *item : m_items)
|
||||||
|
{
|
||||||
|
if (item->type() == PartTerminal::Type) {
|
||||||
|
PartTerminal* term = qgraphicsitem_cast<PartTerminal*>(item);
|
||||||
|
term->setRotation(term->rotation()+90);
|
||||||
|
}
|
||||||
|
else if (item->type() == PartRectangle::Type) {
|
||||||
|
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
|
||||||
|
rect->setRotation(rect->rotation()+90);
|
||||||
|
}
|
||||||
|
else if (item->type() == PartLine::Type) {
|
||||||
|
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
|
||||||
|
line->setRotation(line->rotation()+90);
|
||||||
|
}
|
||||||
|
else if (item->type() == PartPolygon::Type) {
|
||||||
|
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
|
||||||
|
poly->setRotation(poly->rotation()+90);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
item->setRotation(item->rotation()+90);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -22,6 +22,19 @@
|
|||||||
#include "elementcontent.h"
|
#include "elementcontent.h"
|
||||||
#include "elementscene.h"
|
#include "elementscene.h"
|
||||||
#include "elementview.h"
|
#include "elementview.h"
|
||||||
|
#include "graphicspart/abstractpartellipse.h"
|
||||||
|
#include "graphicspart/customelementgraphicpart.h"
|
||||||
|
#include "graphicspart/customelementpart.h"
|
||||||
|
#include "graphicspart/partarc.h"
|
||||||
|
#include "graphicspart/partdynamictextfield.h"
|
||||||
|
#include "graphicspart/partellipse.h"
|
||||||
|
#include "graphicspart/partline.h"
|
||||||
|
#include "graphicspart/partpolygon.h"
|
||||||
|
#include "graphicspart/partrectangle.h"
|
||||||
|
#include "graphicspart/partterminal.h"
|
||||||
|
#include "graphicspart/parttext.h"
|
||||||
|
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief The ElementEditionCommand class
|
@brief The ElementEditionCommand class
|
||||||
@ -279,4 +292,24 @@ class changeElementDataCommand : public ElementEditionCommand
|
|||||||
m_new;
|
m_new;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief The RotateSelectionInESCommand class
|
||||||
|
Rotate the selected items in the element editor
|
||||||
|
*/
|
||||||
|
|
||||||
|
class RotateElementsCommand : public ElementEditionCommand
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
RotateElementsCommand(ElementScene *scene, QUndoCommand *parent=nullptr);
|
||||||
|
void undo() override;
|
||||||
|
void redo() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ElementScene *m_scene =nullptr;
|
||||||
|
QList<QGraphicsItem*> m_items;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -603,6 +603,19 @@ void PartLine::setSecondEndLength(const qreal &l)
|
|||||||
emit secondEndLengthChanged();
|
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
|
@brief PartLine::path
|
||||||
@return this line has a QPainterPath.
|
@return this line has a QPainterPath.
|
||||||
|
@ -94,6 +94,8 @@ class PartLine : public CustomElementGraphicPart
|
|||||||
void setFirstEndLength(const qreal &l);
|
void setFirstEndLength(const qreal &l);
|
||||||
qreal secondEndLength() const {return second_length;}
|
qreal secondEndLength() const {return second_length;}
|
||||||
void setSecondEndLength(const qreal &l);
|
void setSecondEndLength(const qreal &l);
|
||||||
|
void setRotation(qreal angle);
|
||||||
|
qreal rotation() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||||
@ -124,5 +126,6 @@ class PartLine : public CustomElementGraphicPart
|
|||||||
int m_vector_index = -1;
|
int m_vector_index = -1;
|
||||||
QPropertyUndoCommand *m_undo_command;
|
QPropertyUndoCommand *m_undo_command;
|
||||||
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
QVector<QetGraphicsHandlerItem *> m_handler_vector;
|
||||||
|
qreal m_rot;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -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
|
@brief PartPolygon::itemChange
|
||||||
@param change
|
@param change
|
||||||
|
@ -87,6 +87,9 @@ class PartPolygon : public CustomElementGraphicPart
|
|||||||
void setHandlerColor(QPointF pos, const QColor &color) final;
|
void setHandlerColor(QPointF pos, const QColor &color) final;
|
||||||
void resetAllHandlerColor() final;
|
void resetAllHandlerColor() final;
|
||||||
|
|
||||||
|
void setRotation (qreal angle);
|
||||||
|
qreal rotation () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override;
|
||||||
@ -114,5 +117,6 @@ class PartPolygon : public CustomElementGraphicPart
|
|||||||
QAction *m_insert_point,
|
QAction *m_insert_point,
|
||||||
*m_remove_point;
|
*m_remove_point;
|
||||||
QPointF m_context_menu_pos;
|
QPointF m_context_menu_pos;
|
||||||
|
qreal m_rot;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -30,7 +30,9 @@
|
|||||||
*/
|
*/
|
||||||
PartRectangle::PartRectangle(QETElementEditor *editor, QGraphicsItem *parent) :
|
PartRectangle::PartRectangle(QETElementEditor *editor, QGraphicsItem *parent) :
|
||||||
CustomElementGraphicPart(editor, parent)
|
CustomElementGraphicPart(editor, parent)
|
||||||
{}
|
{
|
||||||
|
m_rot=0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief PartRectangle::~PartRectangle
|
@brief PartRectangle::~PartRectangle
|
||||||
@ -169,6 +171,18 @@ void PartRectangle::setYRadius(qreal Y)
|
|||||||
emit YRadiusChanged();
|
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
|
@brief PartRectangle::sceneGeometricRect
|
||||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
@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
|
QPointF PartRectangle::sceneTopLeft() const
|
||||||
{
|
{
|
||||||
return(mapToScene(rect().topLeft()));
|
return(mapToScene(rect().topLeft()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +34,7 @@ class PartRectangle : public CustomElementGraphicPart
|
|||||||
Q_PROPERTY(QRectF rect READ rect WRITE setRect)
|
Q_PROPERTY(QRectF rect READ rect WRITE setRect)
|
||||||
Q_PROPERTY(qreal xRadius READ XRadius WRITE setXRadius NOTIFY XRadiusChanged)
|
Q_PROPERTY(qreal xRadius READ XRadius WRITE setXRadius NOTIFY XRadiusChanged)
|
||||||
Q_PROPERTY(qreal yRadius READ YRadius WRITE setYRadius NOTIFY YRadiusChanged)
|
Q_PROPERTY(qreal yRadius READ YRadius WRITE setYRadius NOTIFY YRadiusChanged)
|
||||||
|
Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
|
||||||
|
|
||||||
// constructors, destructor
|
// constructors, destructor
|
||||||
public:
|
public:
|
||||||
@ -47,6 +48,7 @@ class PartRectangle : public CustomElementGraphicPart
|
|||||||
void rectChanged();
|
void rectChanged();
|
||||||
void XRadiusChanged();
|
void XRadiusChanged();
|
||||||
void YRadiusChanged();
|
void YRadiusChanged();
|
||||||
|
void rotationChanged();
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
@ -69,6 +71,8 @@ class PartRectangle : public CustomElementGraphicPart
|
|||||||
void setXRadius(qreal X);
|
void setXRadius(qreal X);
|
||||||
qreal YRadius() const {return m_yRadius;}
|
qreal YRadius() const {return m_yRadius;}
|
||||||
void setYRadius(qreal Y);
|
void setYRadius(qreal Y);
|
||||||
|
void setRotation(qreal angle);
|
||||||
|
qreal rotation() const;
|
||||||
|
|
||||||
QRectF sceneGeometricRect() const override;
|
QRectF sceneGeometricRect() const override;
|
||||||
virtual QPointF sceneTopLeft() const;
|
virtual QPointF sceneTopLeft() const;
|
||||||
@ -109,5 +113,6 @@ class PartRectangle : public CustomElementGraphicPart
|
|||||||
m_old_xRadius,
|
m_old_xRadius,
|
||||||
m_old_yRadius;
|
m_old_yRadius;
|
||||||
bool m_modifie_radius_equaly = false;
|
bool m_modifie_radius_equaly = false;
|
||||||
|
qreal m_rot;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -140,6 +140,7 @@ QRectF PartTerminal::boundingRect() const
|
|||||||
return(br);
|
return(br);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Definit l'orientation de la borne
|
Definit l'orientation de la borne
|
||||||
@param ori la nouvelle orientation de la borne
|
@param ori la nouvelle orientation de la borne
|
||||||
@ -151,6 +152,32 @@ void PartTerminal::setOrientation(Qet::Orientation ori) {
|
|||||||
updateSecondPoint();
|
updateSecondPoint();
|
||||||
emit orientationChanged();
|
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
|
@brief PartTerminal::setName
|
||||||
@param name
|
@param name
|
||||||
|
@ -72,7 +72,11 @@ class PartTerminal : public CustomElementGraphicPart
|
|||||||
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
void handleUserTransformation(const QRectF &, const QRectF &) override;
|
||||||
|
|
||||||
Qet::Orientation orientation() const {return d -> m_orientation;}
|
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; }
|
QString name() const override { return d -> m_name; }
|
||||||
void setName(QString& name);
|
void setName(QString& name);
|
||||||
|
@ -109,6 +109,7 @@ void QETElementEditor::contextMenu(QPoint p, QList<QAction *> actions)
|
|||||||
menu.addAction(ui->m_delete_action);
|
menu.addAction(ui->m_delete_action);
|
||||||
menu.addAction(ui->m_cut_action);
|
menu.addAction(ui->m_cut_action);
|
||||||
menu.addAction(ui->m_copy_action);
|
menu.addAction(ui->m_copy_action);
|
||||||
|
menu.addAction((ui->m_rotate_action));
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
menu.addAction(ui->m_paste_action);
|
menu.addAction(ui->m_paste_action);
|
||||||
menu.addAction(ui->m_paste_in_area_action);
|
menu.addAction(ui->m_paste_in_area_action);
|
||||||
@ -1018,7 +1019,10 @@ void QETElementEditor::setupActions()
|
|||||||
depth_toolbar -> addActions(m_depth_action_group -> actions());
|
depth_toolbar -> addActions(m_depth_action_group -> actions());
|
||||||
addToolBar(Qt::TopToolBarArea, depth_toolbar);
|
addToolBar(Qt::TopToolBarArea, depth_toolbar);
|
||||||
|
|
||||||
//Zoom action
|
//Rotate action
|
||||||
|
connect(ui->m_rotate_action, &QAction::triggered, [this]() {this -> elementScene() -> undoStack().push(new RotateElementsCommand(this->elementScene()));});
|
||||||
|
|
||||||
|
//Zoom action
|
||||||
ui->m_zoom_in_action -> setShortcut(QKeySequence::ZoomIn);
|
ui->m_zoom_in_action -> setShortcut(QKeySequence::ZoomIn);
|
||||||
ui->m_zoom_out_action -> setShortcut(QKeySequence::ZoomOut);
|
ui->m_zoom_out_action -> setShortcut(QKeySequence::ZoomOut);
|
||||||
ui->m_zoom_fit_best_action -> setShortcut(QKeySequence(tr("Ctrl+9")));
|
ui->m_zoom_fit_best_action -> setShortcut(QKeySequence(tr("Ctrl+9")));
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>21</height>
|
<height>20</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="m_file_menu">
|
<widget class="QMenu" name="m_file_menu">
|
||||||
@ -75,6 +75,7 @@
|
|||||||
<addaction name="m_edit_names_action"/>
|
<addaction name="m_edit_names_action"/>
|
||||||
<addaction name="m_edit_author_action"/>
|
<addaction name="m_edit_author_action"/>
|
||||||
<addaction name="m_edit_element_properties_action"/>
|
<addaction name="m_edit_element_properties_action"/>
|
||||||
|
<addaction name="m_rotate_action"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="m_display_menu">
|
<widget class="QMenu" name="m_display_menu">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
@ -488,6 +489,18 @@
|
|||||||
<string>Affiche des informations sur la bibliothèque Qt</string>
|
<string>Affiche des informations sur la bibliothèque Qt</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="m_rotate_action">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/orientations.png</normaloff>:/ico/16x16/orientations.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Rotation</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Space</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../../qelectrotech.qrc"/>
|
<include location="../../../qelectrotech.qrc"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user