mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Merge pull request #352 from plc-user/master
fix movement of element, when origin is outside of graphics
This commit is contained in:
commit
f308ea6b93
@ -418,8 +418,8 @@ const QDomDocument ElementScene::toXml(bool all_parts)
|
|||||||
// we move the element to the origin to solve this default before saving
|
// we move the element to the origin to solve this default before saving
|
||||||
if (!size.contains(0,0) && all_parts)
|
if (!size.contains(0,0) && all_parts)
|
||||||
{
|
{
|
||||||
centerElementToOrigine();
|
centerElementToOrigin();
|
||||||
//recalcul the size after movement
|
//recalculate the size after movement
|
||||||
size = elementSceneGeometricRect();
|
size = elementSceneGeometricRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -598,6 +598,7 @@ QRectF ElementScene::elementSceneGeometricRect() const
|
|||||||
foreach (QGraphicsItem *qgi, items()) {
|
foreach (QGraphicsItem *qgi, items()) {
|
||||||
if (qgi->type() == ElementPrimitiveDecorator::Type) continue;
|
if (qgi->type() == ElementPrimitiveDecorator::Type) continue;
|
||||||
if (qgi->type() == QGraphicsRectItem::Type) continue;
|
if (qgi->type() == QGraphicsRectItem::Type) continue;
|
||||||
|
if (qgi->type() == PartText::Type) continue;
|
||||||
if (qgi->type() == PartDynamicTextField::Type) continue;
|
if (qgi->type() == PartDynamicTextField::Type) continue;
|
||||||
if (CustomElementPart *cep = dynamic_cast <CustomElementPart*> (qgi)) {
|
if (CustomElementPart *cep = dynamic_cast <CustomElementPart*> (qgi)) {
|
||||||
esgr |= cep -> sceneGeometricRect();
|
esgr |= cep -> sceneGeometricRect();
|
||||||
@ -1317,29 +1318,21 @@ bool ElementScene::zValueLessThan(QGraphicsItem *item1, QGraphicsItem *item2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief ElementScene::centerElementToOrigine
|
@brief ElementScene::centerElementToOrigin
|
||||||
try to center better is possible the element to the scene
|
try to center better is possible the element to the scene
|
||||||
(the calcul isn't optimal but work good)
|
|
||||||
*/
|
*/
|
||||||
void ElementScene::centerElementToOrigine()
|
void ElementScene::centerElementToOrigin()
|
||||||
{
|
{
|
||||||
QRectF size= elementSceneGeometricRect();
|
QRectF size= elementSceneGeometricRect();
|
||||||
int center_x = qRound(size.center().x());
|
// relative move of each primitive with @move with integer values
|
||||||
int center_y = qRound(size.center().y());
|
int offsetX = qRound(size.center().x()) * (-1);
|
||||||
|
int offsetY = qRound(size.center().y()) * (-1);
|
||||||
//define the movement of translation
|
|
||||||
int move_x = center_x - (center_x %10);
|
|
||||||
if (center_x < 0) move_x -= 10;
|
|
||||||
int move_y = center_y - (center_y %10);
|
|
||||||
if (center_y < 0) move_y -= 10;
|
|
||||||
|
|
||||||
//move each primitive by @move
|
|
||||||
foreach (QGraphicsItem *qgi, items()) {
|
foreach (QGraphicsItem *qgi, items()) {
|
||||||
if (qgi -> type() == ElementPrimitiveDecorator::Type) continue;
|
if (qgi -> type() == ElementPrimitiveDecorator::Type) continue;
|
||||||
if (qgi -> type() == QGraphicsRectItem::Type) continue;
|
if (qgi -> type() == QGraphicsRectItem::Type) continue;
|
||||||
//deselect item for disable decorator
|
// deselect item to disable decorator
|
||||||
qgi -> setSelected(false);
|
qgi -> setSelected(false);
|
||||||
qgi -> moveBy(-(move_x), -(move_y));
|
qgi -> moveBy(offsetX, offsetY);
|
||||||
}
|
}
|
||||||
emit (needZoomFit());
|
emit (needZoomFit());
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ class ElementScene : public QGraphicsScene
|
|||||||
void initPasteArea();
|
void initPasteArea();
|
||||||
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
|
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
|
||||||
QMutex *m_decorator_lock;
|
QMutex *m_decorator_lock;
|
||||||
void centerElementToOrigine();
|
void centerElementToOrigin();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slot_select(const ElementContent &);
|
void slot_select(const ElementContent &);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user