mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
element-editor: fix rotation, add mirror, add flip for graphical primitives
Now that the problem with the translations of keyboard shortcuts has been resolved and rotation using the space bar works reliably in principle, I took a closer look at the rotation function itself in the element editor. I noticed, for example, that arcs can be rotated at an angle of 15°. This doesn't really make sense, as the “arc” part doesn't have the “rotation” property. There is only width and height. And somehow rotating arcs didn't work well: start- and span-angles weren't adjusted. Lines and polygons can be rotated in 15° increments, which doesn't make much sense, if other parts that can only be rotated in 90° increments are selected at the same time. To make a long story short: I reworked the rotation functions of the graphical parts so that now all parts are rotated in 90° steps around the origin! This means that it is now possible to mark several parts and rotate them around the same point at the same time! In addition, the functions for mirroring graphic parts at y-axis (shortcut "M") and flipping at x-axis (shortcut "F") have been implemented. I have saved the text elements for later! (or someone else)
This commit is contained in:
@@ -168,17 +168,62 @@ void PartRectangle::setYRadius(qreal Y)
|
||||
}
|
||||
|
||||
void PartRectangle::setRotation(qreal angle) {
|
||||
// for whatever reason: with "rect" we need to use scene-positions...
|
||||
auto pos = mapToScene(m_rect.x(),m_rect.y());
|
||||
qreal width = m_rect.height();
|
||||
qreal height = m_rect.width();
|
||||
qreal x; qreal y;
|
||||
if (angle > 0) {
|
||||
x = (pos.y() + m_rect.height()) * (-1);
|
||||
y = pos.x();
|
||||
} else {
|
||||
x = pos.y();
|
||||
y = (pos.x() + m_rect.width()) * (-1);
|
||||
}
|
||||
|
||||
QTransform rotation = QTransform().rotate(angle-m_rot);
|
||||
m_rot=angle;
|
||||
pos = mapFromScene(x, y);
|
||||
m_rect.setX(pos.x()); m_rect.setY(pos.y());
|
||||
m_rect.setWidth(width); m_rect.setHeight(height);
|
||||
std::swap (m_xRadius, m_yRadius);
|
||||
|
||||
setRect(rotation.mapRect(m_rect));
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
emit rectChanged();
|
||||
}
|
||||
|
||||
qreal PartRectangle::rotation() const {
|
||||
return m_rot;
|
||||
return qRound(m_rot * 100.0) / 100.0;
|
||||
}
|
||||
|
||||
void PartRectangle::flip() {
|
||||
// for whatever reason: with "rect" we need to use scene-positions...
|
||||
qreal height = m_rect.height();
|
||||
auto pos = mapToScene(m_rect.x(),m_rect.y());
|
||||
qreal x = pos.x();
|
||||
qreal y = ((-1.0) * pos.y()) - height;
|
||||
pos = mapFromScene(x, y);
|
||||
m_rect.setX(pos.x()); m_rect.setY(pos.y());
|
||||
m_rect.setHeight(height);
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
emit rectChanged();
|
||||
}
|
||||
|
||||
void PartRectangle::mirror() {
|
||||
// for whatever reason: with "rect" we need to use scene-positions...
|
||||
qreal width = m_rect.width();
|
||||
auto pos = mapToScene(m_rect.x(),m_rect.y());
|
||||
qreal x = ((-1.0) * pos.x()) - width;
|
||||
qreal y = pos.y();
|
||||
pos = mapFromScene(x, y);
|
||||
m_rect.setX(pos.x()); m_rect.setY(pos.y());
|
||||
m_rect.setWidth(width);
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
emit rectChanged();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@brief PartRectangle::sceneGeometricRect
|
||||
@return the minimum, margin-less rectangle this part can fit into, in scene
|
||||
|
||||
Reference in New Issue
Block a user