From: Joel Holdsworth Date: Sat, 17 Nov 2012 08:08:40 +0000 (+0000) Subject: Use static signal offsets instead of offsets calculated on-the-fly X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;ds=sidebyside;h=2e57535108a0ae2e5d1ee454f1e61b71d23afdb3;p=pulseview.git Use static signal offsets instead of offsets calculated on-the-fly This will be needed for dragging --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 2f02e77..125d3c2 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -64,18 +64,17 @@ void Header::paintEvent(QPaintEvent *event) QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); - int offset = -_view.v_offset(); + const int v_offset = _view.v_offset(); BOOST_FOREACH(const shared_ptr s, sigs) { assert(s); const QRect signal_heading_rect( - 0, offset, w, View::SignalHeight); + 0, s->get_v_offset() - v_offset, + w, View::SignalHeight); s->paint_label(painter, signal_heading_rect, s->pt_in_label_rect(signal_heading_rect, _mouse_point)); - - offset += View::SignalHeight; } painter.end(); @@ -100,13 +99,14 @@ void Header::contextMenuEvent(QContextMenuEvent *event) const vector< shared_ptr > &sigs = _view.session().get_signals(); - int offset = -_view.v_offset(); + const int v_offset = _view.v_offset(); BOOST_FOREACH(const shared_ptr s, sigs) { assert(s); const QRect signal_heading_rect( - 0, offset, w, View::SignalHeight); + 0, s->get_v_offset() - v_offset, + w, View::SignalHeight); if(s->pt_in_label_rect(signal_heading_rect, _mouse_point)) { QMenu menu(this); @@ -119,8 +119,6 @@ void Header::contextMenuEvent(QContextMenuEvent *event) break; } - - offset += View::SignalHeight; } } diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 3e951b3..02732ff 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -29,7 +29,8 @@ namespace view { const int Signal::LabelHitPadding = 2; Signal::Signal(QString name) : - _name(name) + _name(name), + _v_offset(0) { } @@ -53,6 +54,16 @@ void Signal::set_colour(QColor colour) _colour = colour; } +int Signal::get_v_offset() const +{ + return _v_offset; +} + +void Signal::set_v_offset(int v_offset) +{ + _v_offset = v_offset; +} + void Signal::paint_label(QPainter &p, const QRect &rect, bool hover) { p.setBrush(_colour); diff --git a/pv/view/signal.h b/pv/view/signal.h index 6f08e94..b321239 100644 --- a/pv/view/signal.h +++ b/pv/view/signal.h @@ -65,6 +65,16 @@ public: */ void set_colour(QColor colour); + /** + * Gets the vertical layout offset of this signal. + */ + int get_v_offset() const; + + /** + * Sets the vertical layout offset of this signal. + */ + void set_v_offset(int v_offset); + /** * Paints the signal with a QPainter * @param p the QPainter to paint into. @@ -118,6 +128,7 @@ protected: protected: QString _name; QColor _colour; + int _v_offset; QSizeF _text_size; }; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 81b3fcd..e36072e 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -30,6 +30,7 @@ #include "header.h" #include "ruler.h" +#include "signal.h" #include "view.h" #include "viewport.h" @@ -200,6 +201,16 @@ void View::update_scroll() _viewport->get_total_height() - areaSize.height()); } +void View::reset_signal_layout() +{ + int offset = 0; + vector< shared_ptr > &sigs = _session.get_signals(); + BOOST_FOREACH(shared_ptr s, sigs) { + s->set_v_offset(offset); + offset += SignalHeight; + } +} + bool View::eventFilter(QObject *object, QEvent *event) { const QEvent::Type type = event->type(); @@ -291,6 +302,9 @@ void View::data_updated() // Repaint the view _viewport->update(); + + /// @todo: Call this only once when the signals are first created. + reset_signal_layout(); } void View::marker_time_changed() diff --git a/pv/view/view.h b/pv/view/view.h index 3397ba2..45ccd34 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -111,6 +111,8 @@ private: void update_scroll(); + void reset_signal_layout(); + private: bool eventFilter(QObject *object, QEvent *event); diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index d9b0ff1..7d844d2 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -66,17 +66,15 @@ void Viewport::paintEvent(QPaintEvent *event) draw_cursors_background(p); // Plot the signal - int offset = -_view.v_offset(); + const int v_offset = _view.v_offset(); BOOST_FOREACH(const shared_ptr s, sigs) { assert(s); - const QRect signal_rect(0, offset, + const QRect signal_rect(0, s->get_v_offset() - v_offset, width(), View::SignalHeight); s->paint(p, signal_rect, _view.scale(), _view.offset()); - - offset += View::SignalHeight; } draw_cursors_foreground(p);