Skip to content

Commit

Permalink
cneben#185 Massive polishing.
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 9daff16 commit ef496bd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/qanAbstractDraggableCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class AbstractDraggableCtrl
//! \c dragInitialMousePos in window coordinate system.
virtual void beginDragMove(const QPointF& dragInitialMousePos, bool dragSelection = true) = 0;
//! \c delta in scene coordinate system.
virtual void dragMove(const QPointF& delta, bool dragSelection = true, bool disableSnapToGrid = false) = 0;
virtual void dragMove(const QPointF& delta, bool dragSelection = true,
bool disableSnapToGrid = false, bool disableOrientation = false) = 0;
virtual void endDragMove(bool dragSelection = true) = 0;
};

Expand Down
13 changes: 8 additions & 5 deletions src/qanDraggableCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ void DraggableCtrl::beginDragMove(const QPointF& sceneDragPos, bool dragSelec
}
}

void DraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection, bool disableSnapToGrid)
void DraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection,
bool disableSnapToGrid, bool disableOrientation)
{
// PRECONDITIONS:
// _graph must be configured (non nullptr)
Expand Down Expand Up @@ -241,10 +242,12 @@ void DraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection,
// or mouse delta > grid
// 2.2.1 Compute snapped position, apply it
const auto targetDragOrientation = _targetItem->getDragOrientation();
const auto dragHorizontally = (targetDragOrientation == qan::NodeItem::DragOrientation::DragAll) ||
(targetDragOrientation == qan::NodeItem::DragOrientation::DragHorizontal);
const auto dragVertically = (targetDragOrientation == qan::NodeItem::DragOrientation::DragAll) ||
(targetDragOrientation == qan::NodeItem::DragOrientation::DragVertical);
const auto dragHorizontally = disableOrientation ||
((targetDragOrientation == qan::NodeItem::DragOrientation::DragAll) ||
(targetDragOrientation == qan::NodeItem::DragOrientation::DragHorizontal));
const auto dragVertically = disableOrientation ||
((targetDragOrientation == qan::NodeItem::DragOrientation::DragAll) ||
(targetDragOrientation == qan::NodeItem::DragOrientation::DragVertical));
if (!disableSnapToGrid && getGraph()->getSnapToGrid()) {
const auto& gridSize = getGraph()->getSnapToGridSize();
bool applyX = dragHorizontally &&
Expand Down
3 changes: 2 additions & 1 deletion src/qanDraggableCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class DraggableCtrl : public qan::AbstractDraggableCtrl
//! \c sceneDragPos is current mouse drag position in scene coordinate system.
virtual void beginDragMove(const QPointF& sceneDragPos, bool dragSelection = true) override;
//! \c sceneDragPos is current mouse drag position in scene coordinate system.
virtual void dragMove(const QPointF& sceneDragPos, bool dragSelection = true, bool disableSnapToGrid = false) override;
virtual void dragMove(const QPointF& sceneDragPos, bool dragSelection = true,
bool disableSnapToGrid = false, bool disableOrientation = false) override;
virtual void endDragMove(bool dragSelection = true) override;

private:
Expand Down
28 changes: 21 additions & 7 deletions src/qanEdgeDraggableCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,39 @@ void EdgeDraggableCtrl::beginDragMove(const QPointF& sceneDragPos, bool dragS
dst->draggableCtrl().beginDragMove(sceneDragPos, false);
}

void EdgeDraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection, bool disableSnapToGrid)
void EdgeDraggableCtrl::dragMove(const QPointF& sceneDragPos, bool dragSelection,
bool disableSnapToGrid, bool disableOrientation)
{
Q_UNUSED(dragSelection)
Q_UNUSED(disableSnapToGrid)
Q_UNUSED(disableOrientation)
// PRECONDITIONS:
// _targetItem must be configured
if (!_targetItem)
return;
if (_targetItem->getSourceItem() == nullptr ||
_targetItem->getDestinationItem() == nullptr)
return;
// Get target edge adjacent nodes
auto src = _targetItem->getSourceItem() != nullptr &&
_targetItem->getSourceItem()->getNode() != nullptr ? _targetItem->getSourceItem()->getNode()->getItem() :
auto src = _targetItem->getSourceItem()->getNode() != nullptr ? _targetItem->getSourceItem()->getNode()->getItem() :
nullptr;
auto dst = _targetItem->getDestinationItem() != nullptr &&
_targetItem->getDestinationItem()->getNode() != nullptr ? _targetItem->getDestinationItem()->getNode()->getItem() :
auto dst = _targetItem->getDestinationItem()->getNode() != nullptr ? _targetItem->getDestinationItem()->getNode()->getItem() :
nullptr;
// Polish snapToGrid:
// When edge src|dst is not vertically or horizontally aligned: disable hook.
// If they are vertically/horizontally aligned: allow move snapToGrid it won't generate jiterring.
const auto disableHooksSnapToGrid = _targetItem->getSourceItem()->getDragOrientation() == qan::NodeItem::DragOrientation::DragAll ||
_targetItem->getSourceItem()->getDragOrientation() == qan::NodeItem::DragOrientation::DragAll ||
(_targetItem->getSourceItem()->getDragOrientation() != _targetItem->getDestinationItem()->getDragOrientation());
const auto disableHooksDragOrientation = (_targetItem->getSourceItem()->getDragOrientation() == qan::NodeItem::DragOrientation::DragHorizontal ||
_targetItem->getSourceItem()->getDragOrientation() == qan::NodeItem::DragOrientation::DragVertical) &&
(_targetItem->getSourceItem()->getDragOrientation() == _targetItem->getDestinationItem()->getDragOrientation());
if (src != nullptr)
src->draggableCtrl().dragMove(sceneDragPos, false, true); // disableSnapToGrid=true
src->draggableCtrl().dragMove(sceneDragPos, /*dragSelection=*/false,
/*disableSnapToGrid=*/disableHooksSnapToGrid, disableHooksDragOrientation);
if (dst != nullptr)
dst->draggableCtrl().dragMove(sceneDragPos, false, true); // disableSnapToGrid=true
dst->draggableCtrl().dragMove(sceneDragPos, /*dragSelection=*/false,
/*disableSnapToGrid=*/disableHooksSnapToGrid, disableHooksDragOrientation);
}

void EdgeDraggableCtrl::endDragMove(bool dragSelection)
Expand Down
4 changes: 2 additions & 2 deletions src/qanEdgeDraggableCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

// QuickQanava headers
#include "./qanAbstractDraggableCtrl.h"
#include "./qanStyle.h" // Used in handleDropEvent()
#include "./qanGroup.h"

namespace qan { // ::qan
Expand Down Expand Up @@ -92,7 +91,8 @@ class EdgeDraggableCtrl : public qan::AbstractDraggableCtrl
//! \c dragInitialMousePos in window coordinate system.
virtual void beginDragMove(const QPointF& sceneDragPos, bool dragSelection = true) override;
//! \c delta in scene coordinate system.
virtual void dragMove(const QPointF& sceneDragPos, bool dragSelection = true, bool disableSnapToGrid = false) override;
virtual void dragMove(const QPointF& sceneDragPos, bool dragSelection = true,
bool disableSnapToGrid = false, bool disableOrientation = false) override;
virtual void endDragMove(bool dragSelection = true) override;

private:
Expand Down
1 change: 0 additions & 1 deletion src/qanEdgeItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ private slots:
*
* Default to false.
*/
// FIXME #185
bool _draggable = true;

public:
Expand Down

0 comments on commit ef496bd

Please sign in to comment.