allow snapping with multi-select (relative to dragged item)

portability/boost
zetaPRIME 2018-12-31 22:53:12 -05:00
parent 8680b57a3d
commit b6922e4f75
1 changed files with 9 additions and 2 deletions

View File

@ -198,13 +198,20 @@ void NodeObject::promptDelete() {
void NodeObject::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
QGraphicsObject::mouseMoveEvent(e);
if (scene()->selectedItems().size() == 1 && e->modifiers() & Qt::Modifier::SHIFT) {
// snap to grid (by center) if single selection and shift held
if (e->modifiers() & Qt::Modifier::SHIFT) {
auto oPos = pos();
// snap to grid (by center) if shift held
constexpr qreal grid = 16.0;
auto r = boundingRect();
auto cx = r.width()/2.0;
auto cy = r.height()/2.0;
setPos(std::round((x()+cx)/grid)*grid-cx, std::round((y()+cy)/grid)*grid-cy);
auto posDelta = pos() - oPos;
for (auto itm : scene()->selectedItems()) {
if (itm == this) continue;
itm->moveBy(posDelta.x(), posDelta.y()); // apply snap to everything else, in relative terms
}
}
}