diff --git a/sources/editor/editorcommands.cpp b/sources/editor/editorcommands.cpp index b452c9df2..4fc2e81d7 100644 --- a/sources/editor/editorcommands.cpp +++ b/sources/editor/editorcommands.cpp @@ -541,11 +541,11 @@ void RotateElementsCommand::undo() } else if (item->type() == PartLine::Type) { PartLine* line = qgraphicsitem_cast(item); - line->setRotation(line->rotation()-90); + line->setRotation(-90); } else if (item->type() == PartPolygon::Type) { PartPolygon* poly = qgraphicsitem_cast(item); - poly->setRotation(poly->rotation()-90); + poly->setRotation(-90); } else { item->setRotation(item->rotation()-90); @@ -578,11 +578,11 @@ void RotateElementsCommand::redo() } else if (item->type() == PartLine::Type) { PartLine* line = qgraphicsitem_cast(item); - line->setRotation(line->rotation()+90); + line->setRotation(+90); } else if (item->type() == PartPolygon::Type) { PartPolygon* poly = qgraphicsitem_cast(item); - poly->setRotation(poly->rotation()+90); + poly->setRotation(+90); } else { item->setRotation(item->rotation()+90); diff --git a/sources/editor/graphicspart/partline.cpp b/sources/editor/graphicspart/partline.cpp index 01d9e76af..94c7f8437 100644 --- a/sources/editor/graphicspart/partline.cpp +++ b/sources/editor/graphicspart/partline.cpp @@ -579,26 +579,9 @@ void PartLine::setSecondEndLength(const qreal &l) } void PartLine::setRotation(qreal angle) { - double tmp, x, y; - if (angle > 0) { - tmp = m_line.p1().y(); - y = m_line.p1().x(); - x = (-1) * tmp; - m_line.setP1(QPointF(x, y)); - tmp = m_line.p2().y(); - y = m_line.p2().x(); - x = (-1) * tmp; - m_line.setP2(QPointF(x, y)); - } else { - tmp = m_line.p1().x(); - x = m_line.p1().y(); - y = (-1) * tmp; - m_line.setP1(QPointF(x, y)); - tmp = m_line.p2().x(); - x = m_line.p2().y(); - y = (-1) * tmp; - m_line.setP2(QPointF(x, y)); - } + m_rot += angle; + m_line.setP1(QTransform().rotate(angle).map(m_line.p1())); + m_line.setP2(QTransform().rotate(angle).map(m_line.p2())); prepareGeometryChange(); setLine(m_line); adjustHandlerPos(); diff --git a/sources/editor/graphicspart/partpolygon.cpp b/sources/editor/graphicspart/partpolygon.cpp index 06061914b..9a3e019f9 100644 --- a/sources/editor/graphicspart/partpolygon.cpp +++ b/sources/editor/graphicspart/partpolygon.cpp @@ -297,21 +297,9 @@ void PartPolygon::resetAllHandlerColor() void PartPolygon::setRotation(qreal angle) { - for (auto &punkt : m_polygon) { - double tmp, x, y; - if (angle > 0) { - tmp = punkt.y(); - y = punkt.x(); - x = (-1) * tmp; - } else { - tmp = punkt.x(); - x = punkt.y(); - y = (-1) * tmp; - } - punkt = QPointF(x, y); - } - - setPolygon(m_polygon); + QTransform rotation = QTransform().rotate(angle); + m_rot += angle; + setPolygon(rotation.map(m_polygon)); prepareGeometryChange(); adjustHandlerPos(); emit polygonChanged();