]> sigrok.org Git - pulseview.git/commitdiff
Added snap to grid drag behaviour
authorJoel Holdsworth <redacted>
Sat, 17 Nov 2012 09:08:41 +0000 (09:08 +0000)
committerJoel Holdsworth <redacted>
Sat, 17 Nov 2012 12:34:31 +0000 (12:34 +0000)
pv/view/header.cpp
pv/view/view.cpp
pv/view/view.h

index 00c4201cf39a28d0ee3e234b0f311e6838ab1a5b..976172137987e3780382a50a75e0eced462a2be7 100644 (file)
@@ -155,10 +155,16 @@ void Header::mouseMoveEvent(QMouseEvent *event)
                const int delta = event->pos().y() - _mouse_down_point.y();
 
                BOOST_FOREACH(const shared_ptr<Signal> 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();
        }
index b6add2ee294fa911bf7d4cca5a2b30ccdb78c7db..0a31e808f20d9e78603994584677631ff1b94c13 100644 (file)
@@ -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);
 
index cda0741d127ecc3f26551effa382206ca9025283..fb52f530fcb1dccae46ac2bdc773875f7adb7d4e 100644 (file)
@@ -54,6 +54,7 @@ private:
 
 public:
        static const int SignalHeight;
+       static const int SignalSnapGridSize;
 
        static const QColor CursorAreaColour;