]> sigrok.org Git - pulseview.git/commitdiff
Added initial support for dragging
authorJoel Holdsworth <redacted>
Sat, 17 Nov 2012 08:54:39 +0000 (08:54 +0000)
committerJoel Holdsworth <redacted>
Sat, 17 Nov 2012 12:34:31 +0000 (12:34 +0000)
pv/view/header.cpp
pv/view/header.h
pv/view/view.cpp
pv/view/view.h

index 8434e2c8dc9ffb289c676f338d151793367e5a8e..00c4201cf39a28d0ee3e234b0f311e6838ab1a5b 100644 (file)
@@ -124,13 +124,45 @@ void Header::mousePressEvent(QMouseEvent *event)
        if(mouse_over_signal)
                mouse_over_signal->select(!mouse_over_signal->selected());
 
+       if(event->button() & Qt::LeftButton) {
+               _mouse_down_point = event->pos();
+
+               // Save the current signal offsets
+               BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+                       _mouse_down_signal_offsets[s.get()] =
+                               s->get_v_offset();
+       }
+
        update();
 }
 
+void Header::mouseReleaseEvent(QMouseEvent *event)
+{
+       assert(event);
+       if(event->button() == Qt::LeftButton)
+               _mouse_down_signal_offsets.clear();
+}
+
 void Header::mouseMoveEvent(QMouseEvent *event)
 {
        assert(event);
        _mouse_point = event->pos();
+
+       // Move the signals if we are dragging
+       if(!_mouse_down_signal_offsets.empty()) {
+               const vector< shared_ptr<Signal> > &sigs =
+                       _view.session().get_signals();
+               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(
+                                       _mouse_down_signal_offsets[s.get()] +
+                                       delta);
+
+               signals_moved();
+       }
+
        update();
 }
 
index e5cd241f6308bc79a2bc64f6a92b5382eb0993e8..ff058863c2d536a598b5b83a199801bd2ba9b1e5 100644 (file)
@@ -23,6 +23,8 @@
 
 #include <boost/shared_ptr.hpp>
 
+#include <map>
+
 #include <QWidget>
 
 namespace pv {
@@ -48,6 +50,8 @@ private:
 private:
        void mousePressEvent(QMouseEvent * event);
 
+       void mouseReleaseEvent(QMouseEvent *event);
+
        void mouseMoveEvent(QMouseEvent *event);
 
        void leaveEvent(QEvent *event);
@@ -59,10 +63,16 @@ private slots:
 
        void on_action_set_colour_triggered();
 
+signals:
+       void signals_moved();
+
 private:
        View &_view;
 
        QPoint _mouse_point;
+       QPoint _mouse_down_point;
+
+       std::map<const Signal*, int> _mouse_down_signal_offsets;
 
        boost::shared_ptr<Signal> _context_signal;
        QAction *_action_set_name;
index e36072ef78ce0d76b88547a32616a5f9a110f9b0..b6add2ee294fa911bf7d4cca5a2b30ccdb78c7db 100644 (file)
@@ -85,6 +85,9 @@ View::View(SigSession &session, QWidget *parent) :
        connect(&_cursors.second, SIGNAL(time_changed()),
                this, SLOT(marker_time_changed()));
 
+       connect(_header, SIGNAL(signals_moved()),
+               this, SLOT(signals_moved()));
+
        setViewportMargins(LabelMarginWidth, RulerHeight, 0, 0);
        setViewport(_viewport);
 
@@ -313,5 +316,11 @@ void View::marker_time_changed()
        _viewport->update();
 }
 
+void View::signals_moved()
+{
+       _header->update();
+       _viewport->update();
+}
+
 } // namespace view
 } // namespace pv
index 45ccd3459700a65c897fb9ab4a06efd8ba0f0083..cda0741d127ecc3f26551effa382206ca9025283 100644 (file)
@@ -129,6 +129,8 @@ private slots:
 
        void marker_time_changed();
 
+       void signals_moved();
+
 private:
        SigSession &_session;