Skip to content

Commit

Permalink
cneben#185 Snap to grid experimentation.
Browse files Browse the repository at this point in the history
Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben authored and emmenlau committed Mar 31, 2023
1 parent 7559d74 commit 6be8c9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
12 changes: 6 additions & 6 deletions quickqanava.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ test-cpp.subdir = samples/cpp
test-tools.subdir = samples/tools

# Uncomment to activate samples projects:
SUBDIRS += test-nodes
SUBDIRS += test-edges
SUBDIRS += test-connector
#SUBDIRS += test-nodes
#SUBDIRS += test-edges
#SUBDIRS += test-connector
SUBDIRS += test-groups
SUBDIRS += test-selection
#SUBDIRS += test-selection
#SUBDIRS += test-style
SUBDIRS += test-topology
SUBDIRS += test-dataflow
#SUBDIRS += test-topology
#SUBDIRS += test-dataflow
#SUBDIRS += test-cpp
#SUBDIRS += test-tools

Expand Down
15 changes: 11 additions & 4 deletions src/qanDraggableCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
// \date 2017 03 15
//-----------------------------------------------------------------------------

// Qt headers
// Nil

// QuickQanava headers
#include "./qanDraggableCtrl.h"
#include "./qanNodeItem.h"
Expand Down Expand Up @@ -228,8 +225,18 @@ void DraggableCtrl::dragMove(const QPointF& delta, bool dragSelection)
}
}

// FIXME #185
const auto gridSize = QSizeF{10., 10.};
const auto localPos = _targetItem->position();
_targetItem->setPosition(localPos + delta);
qWarning() << "delta=" << delta;
qWarning() << "std::fmod(delta.x(), gridSize.width())=" << std::fmod(delta.x(), gridSize.width());
qWarning() << "std::fmod(delta.y(), gridSize.height())=" << std::fmod(delta.x(), gridSize.width());
const auto snappedDelta = QPointF{
std::trunc(delta.x() / gridSize.width()) * gridSize.width(),
std::trunc(delta.y() / gridSize.height()) * gridSize.height(),
};
_targetItem->setPosition(localPos + snappedDelta);
//_targetItem->setPosition(localPos + delta);

if (dragSelection) {
auto dragMoveSelected = [this, &delta] (auto primitive) { // Call dragMove() on a given node or group
Expand Down

0 comments on commit 6be8c9d

Please sign in to comment.