mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 14:14:15 +02:00
Merge pull request #1154 from ispyisail/fix/1145-shape-drag-snap
Fix #1145: drag a shape onto the grid by its corner
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "../undocommand/promoteshapecommand.h"
|
||||
|
||||
#include <QActionGroup>
|
||||
#include <algorithm>
|
||||
#include <QCursor>
|
||||
#include <QMenu>
|
||||
#include <QStatusBar>
|
||||
@@ -613,6 +614,34 @@ QRectF QetShapeItem::sceneOutlineRect() const
|
||||
return mapToScene(outline()).boundingRect();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetShapeItem::setPos
|
||||
Called with the unsnapped position while the shape is dragged. Dragged
|
||||
on its own, or with other shapes only, the shape goes on the grid by the
|
||||
top-left corner of what is drawn, as Snap to grid does: its pos() cannot
|
||||
be seen, and it is off the corner whenever the shape was drawn or
|
||||
resized with Ctrl held, or rotated. Dragged together with anything
|
||||
else, it snaps by pos() as before: the whole selection follows this
|
||||
shape's movement, and correcting the corner would take the symbols off
|
||||
the grid instead.
|
||||
@param p the new position of the item
|
||||
*/
|
||||
void QetShapeItem::setPos(const QPointF &p)
|
||||
{
|
||||
const auto selection = scene() ? scene()->selectedItems() : QList<QGraphicsItem *>();
|
||||
const bool shapes_only = std::all_of(selection.cbegin(), selection.cend(),
|
||||
[](const QGraphicsItem *item) { return item->type() == QetShapeItem::Type; });
|
||||
if (!shapes_only || !isMovable()) {
|
||||
QetGraphicsItem::setPos(p);
|
||||
return;
|
||||
}
|
||||
|
||||
const QPointF corner = sceneOutlineRect().topLeft() + (p - pos());
|
||||
const QPointF snapped = p + Diagram::snapToGrid(corner) - corner;
|
||||
if (snapped != pos())
|
||||
QGraphicsItem::setPos(snapped);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QetShapeItem::shape
|
||||
@return the shape of this item
|
||||
|
||||
@@ -221,6 +221,9 @@ class QetShapeItem : public QetGraphicsItem
|
||||
QPainterPath shape() const override;
|
||||
QRectF sceneOutlineRect() const;
|
||||
|
||||
using QetGraphicsItem::setPos;
|
||||
void setPos(const QPointF &p) override;
|
||||
|
||||
protected:
|
||||
void paint(
|
||||
QPainter *painter,
|
||||
|
||||
Reference in New Issue
Block a user