mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
use Qt-functions to rotate lines and polygons
This commit is contained in:
@@ -541,11 +541,11 @@ void RotateElementsCommand::undo()
|
||||
}
|
||||
else if (item->type() == PartLine::Type) {
|
||||
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
|
||||
line->setRotation(line->rotation()-90);
|
||||
line->setRotation(-90);
|
||||
}
|
||||
else if (item->type() == PartPolygon::Type) {
|
||||
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(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<PartLine*>(item);
|
||||
line->setRotation(line->rotation()+90);
|
||||
line->setRotation(+90);
|
||||
}
|
||||
else if (item->type() == PartPolygon::Type) {
|
||||
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
|
||||
poly->setRotation(poly->rotation()+90);
|
||||
poly->setRotation(+90);
|
||||
}
|
||||
else {
|
||||
item->setRotation(item->rotation()+90);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user