From: Joel Holdsworth Date: Sat, 17 Nov 2012 09:08:41 +0000 (+0000) Subject: Added snap to grid drag behaviour X-Git-Tag: pulseview-0.1.0~216 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=491536836d878a3abf7959800f56641ac093bd11;p=pulseview.git Added snap to grid drag behaviour --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 00c4201c..97617213 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -155,10 +155,16 @@ void Header::mouseMoveEvent(QMouseEvent *event) const int delta = event->pos().y() - _mouse_down_point.y(); BOOST_FOREACH(const shared_ptr s, sigs) - if(s->selected()) - s->set_v_offset( + if(s->selected()) { + const int y = _mouse_down_signal_offsets[s.get()] + - delta); + delta; + const int y_snap = + ((y + View::SignalSnapGridSize / 2) / + View::SignalSnapGridSize) * + View::SignalSnapGridSize; + s->set_v_offset(y_snap ); + } signals_moved(); } diff --git a/pv/view/view.cpp b/pv/view/view.cpp index b6add2ee..0a31e808 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -53,6 +53,7 @@ const int View::RulerHeight = 30; const int View::MaxScrollValue = INT_MAX / 2; const int View::SignalHeight = 50; +const int View::SignalSnapGridSize = 10; const QColor View::CursorAreaColour(220, 231, 243); diff --git a/pv/view/view.h b/pv/view/view.h index cda0741d..fb52f530 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -54,6 +54,7 @@ private: public: static const int SignalHeight; + static const int SignalSnapGridSize; static const QColor CursorAreaColour;