From: Joel Holdsworth Date: Sat, 17 Nov 2012 08:54:39 +0000 (+0000) Subject: Added initial support for dragging X-Git-Tag: pulseview-0.1.0~217 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=54401bbb93fbbd9b0de4874bf02c24b710643fe7;p=pulseview.git Added initial support for dragging --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 8434e2c8..00c4201c 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -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 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 > &sigs = + _view.session().get_signals(); + const int delta = event->pos().y() - _mouse_down_point.y(); + + BOOST_FOREACH(const shared_ptr s, sigs) + if(s->selected()) + s->set_v_offset( + _mouse_down_signal_offsets[s.get()] + + delta); + + signals_moved(); + } + update(); } diff --git a/pv/view/header.h b/pv/view/header.h index e5cd241f..ff058863 100644 --- a/pv/view/header.h +++ b/pv/view/header.h @@ -23,6 +23,8 @@ #include +#include + #include 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 _mouse_down_signal_offsets; boost::shared_ptr _context_signal; QAction *_action_set_name; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index e36072ef..b6add2ee 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -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 diff --git a/pv/view/view.h b/pv/view/view.h index 45ccd345..cda0741d 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -129,6 +129,8 @@ private slots: void marker_time_changed(); + void signals_moved(); + private: SigSession &_session;