Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -256,26 +261,26 @@ 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;
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class WallItem : public graphicsUtils::AbstractItem, public SolidItem

QPainterPath mPath;
int mWallWidth {10};
QPointF mEstimatedPos;
};

}
Expand Down
2 changes: 1 addition & 1 deletion qrtranslations/fr/plugins/robots/twoDModel_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
<context>
<name>twoDModel::items::WallItem</name>
<message>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp" line="+61"/>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp" line="+64"/>
<source>Wall (W)</source>
<translation>Mur (W)</translation>
</message>
Expand Down
2 changes: 1 addition & 1 deletion qrtranslations/ru/plugins/robots/twoDModel_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@
<context>
<name>twoDModel::items::WallItem</name>
<message>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp" line="+61"/>
<location filename="../../../../plugins/robots/common/twoDModel/src/engine/items/wallItem.cpp" line="+64"/>
<source>Wall (W)</source>
<translation>Стена (W)</translation>
</message>
Expand Down
1 change: 1 addition & 0 deletions qrutils/graphicsUtils/abstractItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ void AbstractItem::mousePressEvent(QGraphicsSceneMouseEvent *event)

void AbstractItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
setFlag(QGraphicsItem::ItemIsMovable, mEditable);
QGraphicsItem::mouseReleaseEvent(event);
emit mouseInteractionStopped();
}
Expand Down
15 changes: 14 additions & 1 deletion qrutils/graphicsUtils/abstractScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbstractItem*>(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);
Expand Down