diff --git a/plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp b/plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp index e505af4539..f7723973d4 100644 --- a/plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp +++ b/plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp @@ -35,6 +35,9 @@ WallItem::WallItem(const QPointF &begin, const QPointF &end) setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsScenePositionChanges); setPrivateData(); setAcceptDrops(true); + connect(this, &AbstractItem::mouseInteractionStarted, this, [this](){ + mEstimatedPos = pos(); + }); } WallItem *WallItem::clone() const @@ -191,6 +194,8 @@ void WallItem::recalculateBorders() void WallItem::resizeItem(QGraphicsSceneMouseEvent *event) { + mEstimatedPos += event->scenePos() - event->lastScenePos(); + if (event->modifiers() & Qt::ShiftModifier && (dragState() == TopLeft || dragState() == BottomRight)) { AbstractItem::resizeItem(event); reshapeRectWithShift(); @@ -245,7 +250,7 @@ void WallItem::resizeWithGrid(QGraphicsSceneMouseEvent *event, int indexGrid) const qreal x = mapFromScene(event->scenePos()).x(); const qreal y = mapFromScene(event->scenePos()).y(); - setFlag(QGraphicsItem::ItemIsMovable, dragState() == None); + setFlag(QGraphicsItem::ItemIsMovable, false); if (dragState() == TopLeft) { setX1(x); @@ -256,17 +261,16 @@ void WallItem::resizeWithGrid(QGraphicsSceneMouseEvent *event, int indexGrid) setY2(y); reshapeEndWithGrid(indexGrid); } else { - auto newPos = QPointF(alignedCoordinate(pos().x(), indexGrid), - alignedCoordinate(pos().y(), indexGrid)); - setPos(newPos); - update(); + setPos(mEstimatedPos); + moveBy(alignedCoordinate(begin().x(), indexGrid) - begin().x() + , alignedCoordinate(begin().y(), indexGrid) - begin().y()); } } void WallItem::reshapeEndWithGrid(int indexGrid) { - setX2(alignedCoordinate(x2(), indexGrid)); - setY2(alignedCoordinate(y2(), indexGrid)); + setX2(alignedCoordinate(end().x(), indexGrid) - pos().x()); + setY2(alignedCoordinate(end().y(), indexGrid) - pos().y()); mCellNumbX2 = x2() / indexGrid; mCellNumbY2 = y2() / indexGrid; @@ -274,8 +278,9 @@ void WallItem::reshapeEndWithGrid(int indexGrid) void WallItem::reshapeBeginWithGrid(int indexGrid) { - setX1(alignedCoordinate(x1(), indexGrid)); - setY1(alignedCoordinate(y1(), indexGrid)); + setX1(alignedCoordinate(begin().x(), indexGrid) - pos().x()); + setY1(alignedCoordinate(begin().y(), indexGrid) - pos().y()); + mCellNumbX1 = x1() / indexGrid; mCellNumbY1 = y1() / indexGrid; } diff --git a/plugins/robots/common/twoDModel/src/engine/items/wallItem.h b/plugins/robots/common/twoDModel/src/engine/items/wallItem.h index 98147b4f70..da80d98675 100644 --- a/plugins/robots/common/twoDModel/src/engine/items/wallItem.h +++ b/plugins/robots/common/twoDModel/src/engine/items/wallItem.h @@ -93,6 +93,7 @@ class WallItem : public graphicsUtils::AbstractItem, public SolidItem QPainterPath mPath; int mWallWidth {10}; + QPointF mEstimatedPos; }; } diff --git a/qrtranslations/fr/plugins/robots/twoDModel_fr.ts b/qrtranslations/fr/plugins/robots/twoDModel_fr.ts index 21bbe71f27..5f64637abd 100644 --- a/qrtranslations/fr/plugins/robots/twoDModel_fr.ts +++ b/qrtranslations/fr/plugins/robots/twoDModel_fr.ts @@ -353,7 +353,7 @@ twoDModel::items::WallItem - + Wall (W) Mur (W) diff --git a/qrtranslations/ru/plugins/robots/twoDModel_ru.ts b/qrtranslations/ru/plugins/robots/twoDModel_ru.ts index 9a16aa8064..9ea814e410 100644 --- a/qrtranslations/ru/plugins/robots/twoDModel_ru.ts +++ b/qrtranslations/ru/plugins/robots/twoDModel_ru.ts @@ -629,7 +629,7 @@ twoDModel::items::WallItem - + Wall (W) Стена (W) diff --git a/qrutils/graphicsUtils/abstractItem.cpp b/qrutils/graphicsUtils/abstractItem.cpp index a087eed751..c437c56671 100644 --- a/qrutils/graphicsUtils/abstractItem.cpp +++ b/qrutils/graphicsUtils/abstractItem.cpp @@ -596,6 +596,7 @@ void AbstractItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void AbstractItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + setFlag(QGraphicsItem::ItemIsMovable, mEditable); QGraphicsItem::mouseReleaseEvent(event); emit mouseInteractionStopped(); } diff --git a/qrutils/graphicsUtils/abstractScene.cpp b/qrutils/graphicsUtils/abstractScene.cpp index acb74d9e58..5f54fe7cf5 100644 --- a/qrutils/graphicsUtils/abstractScene.cpp +++ b/qrutils/graphicsUtils/abstractScene.cpp @@ -83,12 +83,25 @@ void AbstractScene::setX2andY2(QGraphicsSceneMouseEvent *event) void AbstractScene::reshapeItem(QGraphicsSceneMouseEvent *event) { + setX2andY2(event); + if (!mGraphicsItem) return; + auto oldPos = mGraphicsItem->pos(); reshapeItem(event, mGraphicsItem); + auto delta = mGraphicsItem->pos() - oldPos; + if (mGraphicsItem->isSelected()) { + mGraphicsItem->setPos(oldPos); + } + for (auto selectedItem : selectedItems()) { + if (auto item = dynamic_cast(selectedItem)) { + if (!item->parentItem()) { + item->moveBy(delta.x(), delta.y()); + } + } + } } void AbstractScene::reshapeItem(QGraphicsSceneMouseEvent *event, graphicsUtils::AbstractItem *item) { - setX2andY2(event); if (item && item->editable()) { if (item->dragState() != graphicsUtils::AbstractItem::None) { mView->setDragMode(QGraphicsView::NoDrag);