Skip to content

Commit

Permalink
Merge pull request #356 from plc-user/master
Browse files Browse the repository at this point in the history
element-editor: fix rotation and more
  • Loading branch information
scorpio810 authored Feb 15, 2025
2 parents 9afc971 + b9a8dc0 commit 5aee30e
Show file tree
Hide file tree
Showing 75 changed files with 4,934 additions and 4,560 deletions.
Binary file added ico/16x16/flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ico/16x16/mirror.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lang/qet_ar.qm
Binary file not shown.
319 changes: 158 additions & 161 deletions lang/qet_ar.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_ca.qm
Binary file not shown.
319 changes: 158 additions & 161 deletions lang/qet_ca.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_cs.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_cs.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_da.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_da.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_de.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_de.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_el.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_el.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_en.qm
Binary file not shown.
323 changes: 160 additions & 163 deletions lang/qet_en.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_es.qm
Binary file not shown.
319 changes: 158 additions & 161 deletions lang/qet_es.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_fr.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_fr.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_hr.qm
Binary file not shown.
319 changes: 158 additions & 161 deletions lang/qet_hr.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_hu.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_hu.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_it.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_it.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_ja.qm
Binary file not shown.
319 changes: 158 additions & 161 deletions lang/qet_ja.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_mn.qm
Binary file not shown.
319 changes: 158 additions & 161 deletions lang/qet_mn.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_nb.qm
Binary file not shown.
319 changes: 158 additions & 161 deletions lang/qet_nb.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_nl.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_nl.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_nl_BE.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_nl_BE.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_pl.qm
Binary file not shown.
322 changes: 159 additions & 163 deletions lang/qet_pl.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_pt.qm
Binary file not shown.
319 changes: 158 additions & 161 deletions lang/qet_pt.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_pt_BR.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_pt_BR.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_ro.qm
Binary file not shown.
319 changes: 158 additions & 161 deletions lang/qet_ro.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_ru.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_ru.ts

Large diffs are not rendered by default.

319 changes: 158 additions & 161 deletions lang/qet_sk.ts

Large diffs are not rendered by default.

319 changes: 158 additions & 161 deletions lang/qet_sl.ts

Large diffs are not rendered by default.

319 changes: 158 additions & 161 deletions lang/qet_sr.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_tr.qm
Binary file not shown.
319 changes: 158 additions & 161 deletions lang/qet_tr.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_uk.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_uk.ts

Large diffs are not rendered by default.

Binary file modified lang/qet_zh.qm
Binary file not shown.
321 changes: 159 additions & 162 deletions lang/qet_zh.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions qelectrotech.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<file>ico/16x16/endline-none.png</file>
<file>ico/16x16/endline-simple.png</file>
<file>ico/16x16/endline-triangle.png</file>
<file>ico/16x16/flip.png</file>
<file>ico/16x16/folder-new.png</file>
<file>ico/16x16/folder.png</file>
<file>ico/16x16/go-company.png</file>
Expand All @@ -60,6 +61,7 @@
<file>ico/16x16/list-add.png</file>
<file>ico/16x16/list-remove.png</file>
<file>ico/16x16/masquer.png</file>
<file>ico/16x16/mirror.png</file>
<file>ico/16x16/neutral.png</file>
<file>ico/16x16/north.png</file>
<file>ico/16x16/orientations.png</file>
Expand Down
119 changes: 113 additions & 6 deletions sources/editor/editorcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,28 @@ void RotateElementsCommand::undo()
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
rect->setRotation(rect->rotation()-90);
}
else if (item->type() == PartArc::Type) {
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
arc->setRotation(arc->rotation()-90);
}
else if (item->type() == PartEllipse::Type) {
PartEllipse* ellipse = qgraphicsitem_cast<PartEllipse*>(item);
ellipse->setRotation(ellipse->rotation()-90);
}
else if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(line->rotation()-15);
line->setRotation(line->rotation()-90);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(poly->rotation()-15);
poly->setRotation(poly->rotation()-90);
}
else {
item->setRotation(item->rotation()-15);
item->setRotation(item->rotation()-90);
}
}
}

/**
@brief RotateElementsCommand::redo
*/
Expand All @@ -559,17 +568,115 @@ void RotateElementsCommand::redo()
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
rect->setRotation(rect->rotation()+90);
}
else if (item->type() == PartArc::Type) {
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
arc->setRotation(arc->rotation()+90);
}
else if (item->type() == PartEllipse::Type) {
PartEllipse* ellipse = qgraphicsitem_cast<PartEllipse*>(item);
ellipse->setRotation(ellipse->rotation()+90);
}
else if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(line->rotation()+15);
line->setRotation(line->rotation()+90);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(poly->rotation()+15);
poly->setRotation(poly->rotation()+90);
}
else {
item->setRotation(item->rotation()+15);
item->setRotation(item->rotation()+90);
}
}
}


MirrorElementsCommand::MirrorElementsCommand(ElementScene *scene, QUndoCommand *parent) :
ElementEditionCommand(QObject::tr("Miroir de sélection", "undo caption"), scene, nullptr, parent)
{
m_items = scene->selectedItems();
}

/**
@brief MirrorElementsCommand::redo
*/
void MirrorElementsCommand::redo()
{
foreach (auto *item, m_items) {
if ((item->type() == PartText::Type) ||
(item->type() == PartDynamicTextField::Type)) {
continue;
} else if (item->type() == PartArc::Type) {
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
arc->mirror();
} else if (item->type() == PartEllipse::Type) {
PartEllipse* ellipse = qgraphicsitem_cast<PartEllipse*>(item);
ellipse->mirror();
} else if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->mirror();
} else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->mirror();
} else if (item->type() == PartRectangle::Type) {
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
rect->mirror();
} else if (item->type() == PartTerminal::Type) {
PartTerminal* term = qgraphicsitem_cast<PartTerminal*>(item);
term->mirror();
}
}
}
/**
@brief MirrorElementsCommand::undo
*/
void MirrorElementsCommand::undo()
{
redo();
}


FlipElementsCommand::FlipElementsCommand(ElementScene *scene, QUndoCommand *parent) :
ElementEditionCommand(QObject::tr("Retourner la sélection", "undo caption"), scene, nullptr, parent)
{
m_items = scene->selectedItems();
}

/**
@brief FlipElementsCommand::redo
*/
void FlipElementsCommand::redo()
{
foreach (auto *item, m_items) {
if ((item->type() == PartText::Type) ||
(item->type() == PartDynamicTextField::Type)) {
continue;
} else if (item->type() == PartArc::Type) {
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
arc->flip();
} else if (item->type() == PartEllipse::Type) {
PartEllipse* ellipse = qgraphicsitem_cast<PartEllipse*>(item);
ellipse->flip();
} else if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->flip();
} else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->flip();
} else if (item->type() == PartRectangle::Type) {
PartRectangle* rect = qgraphicsitem_cast<PartRectangle*>(item);
rect->flip();
} else if (item->type() == PartTerminal::Type) {
PartTerminal* term = qgraphicsitem_cast<PartTerminal*>(item);
term->flip();
}
}
}

/**
@brief FlipElementsCommand::undo
*/
void FlipElementsCommand::undo()
{
redo();
}
22 changes: 22 additions & 0 deletions sources/editor/editorcommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,26 @@ class RotateElementsCommand : public ElementEditionCommand

};

class MirrorElementsCommand : public ElementEditionCommand
{
public:
MirrorElementsCommand(ElementScene *scene, QUndoCommand *parent=nullptr);
void undo() override;
void redo() override;
private:
ElementScene *m_scene =nullptr;
QList<QGraphicsItem*> m_items;
};

class FlipElementsCommand : public ElementEditionCommand
{
public:
FlipElementsCommand(ElementScene *scene, QUndoCommand *parent=nullptr);
void undo() override;
void redo() override;
private:
ElementScene *m_scene =nullptr;
QList<QGraphicsItem*> m_items;
};

#endif
56 changes: 56 additions & 0 deletions sources/editor/graphicspart/partarc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,62 @@ QPainterPath PartArc::shadowShape() const
return (pps.createStroke(shape));
}


void PartArc::setRotation(qreal angle) {
// idea taken from QET_ElementScaler:
if (angle > 0) {
m_start_angle += 270.0 * 16;
while (m_start_angle < 0) { m_start_angle += (360*16); }
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x = (m_rect.y() + m_rect.height()) * (-1);
qreal y = m_rect.x();
m_rect = QRectF(x, y, width, height);
} else {
m_start_angle -= 270.0 * 16;
while (m_start_angle < 0) { m_start_angle += (360*16); }
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x = m_rect.y();
qreal y = (m_rect.x() + m_rect.width()) * (-1);
m_rect = QRectF(x, y, width, height);
}

prepareGeometryChange();
adjustHandlerPos();
emit rectChanged();
}

qreal PartArc::rotation() const {
return qRound(m_rot * 100.0) / 100.0;
}

void PartArc::flip() {
m_start_angle = (-1) * m_start_angle;
m_span_angle = (-1) * m_span_angle;
while (m_start_angle < 0) { m_start_angle += (360*16); }
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }
qreal y = ((-1.0) * m_rect.y()) - m_rect.height();
m_rect = QRectF(m_rect.x(), y, m_rect.width(), m_rect.height());
prepareGeometryChange();
adjustHandlerPos();
emit rectChanged();
}

void PartArc::mirror() {
m_start_angle = (180.0 * 16) - m_start_angle;
m_span_angle = (-1) * m_span_angle;
while (m_start_angle < 0) { m_start_angle += (360*16); }
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }
qreal x = ((-1.0) * m_rect.x()) - m_rect.width();
m_rect = QRectF(x, m_rect.y(), m_rect.width(), m_rect.height());
prepareGeometryChange();
adjustHandlerPos();
emit rectChanged();
}

/**
* @brief PartArc::sceneGeometricRect
* @return the minimum,
Expand Down
5 changes: 5 additions & 0 deletions sources/editor/graphicspart/partarc.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class PartArc : public AbstractPartEllipse
void setStartAngle(const int &start_angle) override {AbstractPartEllipse::setStartAngle(start_angle); adjustHandlerPos();}
void setSpanAngle(const int &span_angle) override {AbstractPartEllipse::setSpanAngle(span_angle); adjustHandlerPos();}
QRectF sceneGeometricRect() const override;
void setRotation(qreal angle);
qreal rotation() const;
void flip();
void mirror();

void addHandler() override;
void removeHandler() override;
Expand All @@ -83,5 +87,6 @@ class PartArc : public AbstractPartEllipse
m_vector_index = -1;
QPointF m_span_point;
QVector<QetGraphicsHandlerItem *> m_handler_vector;
qreal m_rot = 0;
};
#endif
44 changes: 44 additions & 0 deletions sources/editor/graphicspart/partellipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,50 @@ bool PartEllipse::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
return false;
}


void PartEllipse::setRotation(qreal angle) {
// idea taken from QET_ElementScaler:
if (angle > 0) {
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x = (m_rect.y() + m_rect.height()) * (-1);
qreal y = m_rect.x();
m_rect = QRectF(x, y, width, height);
} else {
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x = m_rect.y();
qreal y = (m_rect.x() + m_rect.width()) * (-1);
m_rect = QRectF(x, y, width, height);
}
prepareGeometryChange();
adjustHandlerPos();
emit rectChanged();
}

qreal PartEllipse::rotation() const {
return qRound(m_rot * 100.0) / 100.0;
}

void PartEllipse::flip() {
qreal y = ((-1.0) * m_rect.y()) - m_rect.height();
m_rect = QRectF(m_rect.x(), y, m_rect.width(), m_rect.height());
prepareGeometryChange();
adjustHandlerPos();
emit rectChanged();
}

void PartEllipse::mirror() {
qreal x = ((-1.0) * m_rect.x()) - m_rect.width();
m_rect = QRectF(x, m_rect.y(), m_rect.width(), m_rect.height());
prepareGeometryChange();
adjustHandlerPos();
emit rectChanged();
}




void PartEllipse::switchResizeMode()
{
if (m_resize_mode == 1)
Expand Down
10 changes: 9 additions & 1 deletion sources/editor/graphicspart/partellipse.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class QPropertyUndoCommand;
This class represents an ellipse primitive which may be used to compose the
drawing of an electrical element within the element editor.
*/
class PartEllipse : public AbstractPartEllipse
class PartEllipse : public AbstractPartEllipse
{
Q_OBJECT

Expand All @@ -39,6 +39,9 @@ class PartEllipse : public AbstractPartEllipse
private:
PartEllipse(const PartEllipse &);

signals:
void rotationChanged();

// methods
public:
enum { Type = UserType + 1103 };
Expand All @@ -57,6 +60,10 @@ class PartEllipse : public AbstractPartEllipse
QPainterPath shape() const override;
QPainterPath shadowShape() const override;
void setRect(const QRectF &rect) override {AbstractPartEllipse::setRect(rect); adjustHandlerPos();}
void setRotation(qreal angle);
qreal rotation() const;
void flip();
void mirror();

void addHandler() override;
void removeHandler() override;
Expand All @@ -77,5 +84,6 @@ class PartEllipse : public AbstractPartEllipse
QPropertyUndoCommand *m_undo_command;
int m_resize_mode = 1,
m_vector_index = -1;
qreal m_rot = 0;
};
#endif
Loading

0 comments on commit 5aee30e

Please sign in to comment.