From: Joel Holdsworth Date: Sat, 17 Nov 2012 12:48:27 +0000 (+0000) Subject: Improved propagation of drag event so that the scroll bars can be updated X-Git-Tag: pulseview-0.1.0~213 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=0720481923d46cde06148c8a4aec2f96def66643 Improved propagation of drag event so that the scroll bars can be updated --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index a141b616..e167bffc 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -54,6 +54,9 @@ Header::Header(View &parent) : this, SLOT(on_action_set_name_triggered())); connect(_action_set_colour, SIGNAL(triggered()), this, SLOT(on_action_set_colour_triggered())); + + connect(&_view, SIGNAL(signals_moved()), + this, SLOT(on_signals_moved())); } boost::shared_ptr Header::get_mouse_over_signal( @@ -113,14 +116,6 @@ void Header::mousePressEvent(QMouseEvent *event) const vector< shared_ptr > &sigs = _view.session().get_signals(); - if(~QApplication::keyboardModifiers() & Qt::ControlModifier) { - // Unselect all other signals because the Ctrl is not - // pressed - _drag_sigs.clear(); - BOOST_FOREACH(const shared_ptr s, sigs) - s->select(false); - } - if(event->button() & Qt::LeftButton) { _mouse_down_point = event->pos(); @@ -140,13 +135,26 @@ void Header::mousePressEvent(QMouseEvent *event) else { mouse_over_signal->select(true); + if(~QApplication::keyboardModifiers() & + Qt::ControlModifier) + _drag_sigs.clear(); + // Add the signal to the drag list - _drag_sigs.push_back( - make_pair(mouse_over_signal, + if(event->button() & Qt::LeftButton) + _drag_sigs.push_back( + make_pair(mouse_over_signal, mouse_over_signal->get_v_offset())); } } + if(~QApplication::keyboardModifiers() & Qt::ControlModifier) { + // Unselect all other signals because the Ctrl is not + // pressed + BOOST_FOREACH(const shared_ptr s, sigs) + if(s != mouse_over_signal) + s->select(false); + } + update(); } @@ -238,5 +246,11 @@ void Header::on_action_set_colour_triggered() context_signal->set_colour(new_colour); } +void Header::on_signals_moved() +{ + update(); +} + + } // namespace view } // namespace pv diff --git a/pv/view/header.h b/pv/view/header.h index 35f16de1..8e180b8a 100644 --- a/pv/view/header.h +++ b/pv/view/header.h @@ -65,6 +65,8 @@ private slots: void on_action_set_colour_triggered(); + void on_signals_moved(); + signals: void signals_moved(); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 0a31e808..e3210fa3 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -87,7 +87,7 @@ View::View(SigSession &session, QWidget *parent) : this, SLOT(marker_time_changed())); connect(_header, SIGNAL(signals_moved()), - this, SLOT(signals_moved())); + this, SLOT(on_signals_moved())); setViewportMargins(LabelMarginWidth, RulerHeight, 0, 0); setViewport(_viewport); @@ -317,10 +317,10 @@ void View::marker_time_changed() _viewport->update(); } -void View::signals_moved() +void View::on_signals_moved() { - _header->update(); - _viewport->update(); + update_scroll(); + signals_moved(); } } // namespace view diff --git a/pv/view/view.h b/pv/view/view.h index fb52f530..6d7ac36d 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -107,6 +107,8 @@ public: signals: void hover_point_changed(); + void signals_moved(); + private: void get_scroll_layout(double &length, double &offset) const; @@ -130,7 +132,7 @@ private slots: void marker_time_changed(); - void signals_moved(); + void on_signals_moved(); private: SigSession &_session; diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 7d844d27..96111875 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -41,18 +41,21 @@ Viewport::Viewport(View &parent) : setMouseTracking(true); setAutoFillBackground(true); setBackgroundRole(QPalette::Base); + + connect(&_view, SIGNAL(signals_moved()), + this, SLOT(on_signals_moved())); } int Viewport::get_total_height() const { - int height = 0; + int h = 0; BOOST_FOREACH(const shared_ptr s, _view.session().get_signals()) { assert(s); - height += View::SignalHeight; + h = max(s->get_v_offset() + View::SignalHeight, h); } - return height; + return h; } void Viewport::paintEvent(QPaintEvent *event) @@ -142,5 +145,10 @@ void Viewport::draw_cursors_foreground(QPainter &p) cursors.second.paint(p, r); } +void Viewport::on_signals_moved() +{ + update(); +} + } // namespace view } // namespace pv diff --git a/pv/view/viewport.h b/pv/view/viewport.h index 49b97e3b..7d32c433 100644 --- a/pv/view/viewport.h +++ b/pv/view/viewport.h @@ -56,6 +56,9 @@ private: void draw_cursors_foreground(QPainter &p); +private slots: + void on_signals_moved(); + private: View &_view;