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) {
|
else if (item->type() == PartLine::Type) {
|
||||||
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
|
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
|
||||||
line->setRotation(line->rotation()-90);
|
line->setRotation(-90);
|
||||||
}
|
}
|
||||||
else if (item->type() == PartPolygon::Type) {
|
else if (item->type() == PartPolygon::Type) {
|
||||||
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
|
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
|
||||||
poly->setRotation(poly->rotation()-90);
|
poly->setRotation(-90);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
item->setRotation(item->rotation()-90);
|
item->setRotation(item->rotation()-90);
|
||||||
@@ -578,11 +578,11 @@ void RotateElementsCommand::redo()
|
|||||||
}
|
}
|
||||||
else if (item->type() == PartLine::Type) {
|
else if (item->type() == PartLine::Type) {
|
||||||
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
|
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
|
||||||
line->setRotation(line->rotation()+90);
|
line->setRotation(+90);
|
||||||
}
|
}
|
||||||
else if (item->type() == PartPolygon::Type) {
|
else if (item->type() == PartPolygon::Type) {
|
||||||
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
|
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
|
||||||
poly->setRotation(poly->rotation()+90);
|
poly->setRotation(+90);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
item->setRotation(item->rotation()+90);
|
item->setRotation(item->rotation()+90);
|
||||||
|
|||||||
@@ -579,26 +579,9 @@ void PartLine::setSecondEndLength(const qreal &l)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PartLine::setRotation(qreal angle) {
|
void PartLine::setRotation(qreal angle) {
|
||||||
double tmp, x, y;
|
m_rot += angle;
|
||||||
if (angle > 0) {
|
m_line.setP1(QTransform().rotate(angle).map(m_line.p1()));
|
||||||
tmp = m_line.p1().y();
|
m_line.setP2(QTransform().rotate(angle).map(m_line.p2()));
|
||||||
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));
|
|
||||||
}
|
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
setLine(m_line);
|
setLine(m_line);
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
|
|||||||
@@ -297,21 +297,9 @@ void PartPolygon::resetAllHandlerColor()
|
|||||||
|
|
||||||
|
|
||||||
void PartPolygon::setRotation(qreal angle) {
|
void PartPolygon::setRotation(qreal angle) {
|
||||||
for (auto &punkt : m_polygon) {
|
QTransform rotation = QTransform().rotate(angle);
|
||||||
double tmp, x, y;
|
m_rot += angle;
|
||||||
if (angle > 0) {
|
setPolygon(rotation.map(m_polygon));
|
||||||
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);
|
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
emit polygonChanged();
|
emit polygonChanged();
|
||||||
|
|||||||
Reference in New Issue
Block a user