From: Joel Holdsworth Date: Fri, 18 Jan 2013 18:33:01 +0000 (+0000) Subject: Eliminated get_nominal_offset X-Git-Tag: pulseview-0.1.0~153 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=2658961bdef3601e07d494a8ed3d01a8101b68cd Eliminated get_nominal_offset --- diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index fb5eba61..13608069 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -39,11 +39,12 @@ AnalogSignal::AnalogSignal(QString name, shared_ptr data) : _colour = Qt::blue; } -void AnalogSignal::paint(QPainter &p, const QRect &rect, double scale, +void AnalogSignal::paint(QPainter &p, int y, int left, int right, double scale, double offset) { assert(scale > 0); assert(_data); + assert(right >= left); const deque< shared_ptr > &snapshots = _data->get_snapshots(); @@ -59,15 +60,13 @@ void AnalogSignal::paint(QPainter &p, const QRect &rect, double scale, const int64_t last_sample = snapshot->get_sample_count() - 1; const double samples_per_pixel = samplerate * scale; const double start = samplerate * (offset - start_time); - const double end = start + samples_per_pixel * rect.width(); + const double end = start + samples_per_pixel * (right - left); const int64_t start_sample = min(max((int64_t)floor(start), (int64_t)0), last_sample); const int64_t end_sample = min(max((int64_t)ceil(end), (int64_t)0), last_sample); - const int y_offset = rect.center().y(); - const float* samples = snapshot->get_samples(); assert(samples); @@ -77,9 +76,8 @@ void AnalogSignal::paint(QPainter &p, const QRect &rect, double scale, for (int64_t sample = start_sample; sample != end_sample; sample++) { const float x = (sample / samples_per_pixel - - pixels_offset) + rect.left(); - const float y = samples[sample] + y_offset; - *point++ = QPointF(x, y); + pixels_offset) + left; + *point++ = QPointF(x, samples[sample] + y); } p.drawPoints(points, point - points); @@ -87,10 +85,5 @@ void AnalogSignal::paint(QPainter &p, const QRect &rect, double scale, delete[] points; } -int AnalogSignal::get_nominal_offset(const QRect &rect) const -{ - return rect.center().y(); -} - } // namespace view } // namespace pv diff --git a/pv/view/analogsignal.h b/pv/view/analogsignal.h index 7bc0ed6e..86471537 100644 --- a/pv/view/analogsignal.h +++ b/pv/view/analogsignal.h @@ -42,21 +42,15 @@ public: /** * Paints the signal with a QPainter * @param p the QPainter to paint into. - * @param rect the rectangular area to draw the trace into. + * @param y the y-coordinate to draw the signal at. + * @param left the x-coordinate of the left edge of the signal. + * @param right the x-coordinate of the right edge of the signal. * @param scale the scale in seconds per pixel. * @param offset the time to show at the left hand edge of * the view in seconds. **/ - void paint(QPainter &p, const QRect &rect, - double scale, double offset); - -private: - - /** - * When painting into the rectangle, calculate the y - * offset of the zero point. - **/ - int get_nominal_offset(const QRect &rect) const; + void paint(QPainter &p, int y, int left, int right, double scale, + double offset); private: boost::shared_ptr _data; diff --git a/pv/view/header.cpp b/pv/view/header.cpp index a615e851..e0e280b2 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -71,11 +71,8 @@ boost::shared_ptr Header::get_mouse_over_signal( { assert(s); - const QRect signal_heading_rect( - 0, s->get_v_offset() - v_offset, - w, View::SignalHeight); - - if (s->pt_in_label_rect(signal_heading_rect, pt)) + if (s->pt_in_label_rect(s->get_v_offset() - v_offset, + 0, w, pt)) return s; } @@ -97,13 +94,10 @@ void Header::paintEvent(QPaintEvent*) { assert(s); - const QRect signal_heading_rect( - 0, s->get_v_offset() - v_offset, - w, View::SignalHeight); - + const int y = s->get_v_offset() - v_offset; const bool highlight = !dragging && s->pt_in_label_rect( - signal_heading_rect, _mouse_point); - s->paint_label(painter, signal_heading_rect, highlight); + y, 0, w, _mouse_point); + s->paint_label(painter, y, w, highlight); } painter.end(); diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index d23da5bb..051da4d8 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -23,6 +23,7 @@ #include #include "logicsignal.h" +#include "view.h" #include "pv/data/logic.h" #include "pv/data/logicsnapshot.h" @@ -62,18 +63,21 @@ LogicSignal::LogicSignal(QString name, shared_ptr data, _probe_index % countof(LogicSignalColours)]; } -void LogicSignal::paint(QPainter &p, const QRect &rect, double scale, - double offset) +void LogicSignal::paint(QPainter &p, int y, int left, int right, + double scale, double offset) { + using pv::view::View; + QLineF *line; vector< pair > edges; assert(scale > 0); assert(_data); + assert(right >= left); - const float high_offset = rect.top() + 0.5f; - const float low_offset = rect.bottom() + 0.5f; + const float high_offset = y - View::SignalHeight + 0.5f; + const float low_offset = y + 0.5f; const deque< shared_ptr > &snapshots = _data->get_snapshots(); @@ -89,7 +93,7 @@ void LogicSignal::paint(QPainter &p, const QRect &rect, double scale, const int64_t last_sample = snapshot->get_sample_count() - 1; const double samples_per_pixel = samplerate * scale; const double start = samplerate * (offset - start_time); - const double end = start + samples_per_pixel * rect.width(); + const double end = start + samples_per_pixel * (right - left); snapshot->get_subsampled_edges(edges, min(max((int64_t)floor(start), (int64_t)0), last_sample), @@ -106,7 +110,7 @@ void LogicSignal::paint(QPainter &p, const QRect &rect, double scale, edges.begin() + 1; i != edges.end() - 1; i++) { const float x = ((*i).first / samples_per_pixel - - pixels_offset) + rect.left(); + pixels_offset) + left; *line++ = QLineF(x, high_offset, x, low_offset); } @@ -120,10 +124,10 @@ void LogicSignal::paint(QPainter &p, const QRect &rect, double scale, p.setPen(HighColour); paint_caps(p, cap_lines, edges, true, samples_per_pixel, - pixels_offset, rect.left(), high_offset); + pixels_offset, left, high_offset); p.setPen(LowColour); paint_caps(p, cap_lines, edges, false, samples_per_pixel, - pixels_offset, rect.left(), low_offset); + pixels_offset, left, low_offset); delete[] cap_lines; } @@ -148,10 +152,5 @@ void LogicSignal::paint_caps(QPainter &p, QLineF *const lines, p.drawLines(lines, line - lines); } -int LogicSignal::get_nominal_offset(const QRect &rect) const -{ - return rect.bottom(); -} - } // namespace view } // namespace pv diff --git a/pv/view/logicsignal.h b/pv/view/logicsignal.h index e20f13c7..ad88241d 100644 --- a/pv/view/logicsignal.h +++ b/pv/view/logicsignal.h @@ -52,12 +52,15 @@ public: /** * Paints the signal with a QPainter * @param p the QPainter to paint into. - * @param rect the rectangular area to draw the trace into. + * @param y the y-coordinate to draw the signal at. + * @param left the x-coordinate of the left edge of the signal. + * @param right the x-coordinate of the right edge of the signal. * @param scale the scale in seconds per pixel. * @param offset the time to show at the left hand edge of * the view in seconds. **/ - void paint(QPainter &p, const QRect &rect, double scale, double offset); + void paint(QPainter &p, int y, int left, int right, double scale, + double offset); private: @@ -66,12 +69,6 @@ private: bool level, double samples_per_pixel, double pixels_offset, float x_offset, float y_offset); - /** - * When painting into the rectangle, calculate the y - * offset of the zero point. - **/ - int get_nominal_offset(const QRect &rect) const; - private: int _probe_index; boost::shared_ptr _data; diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 33cfef2d..2469d981 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -78,21 +78,20 @@ void Signal::select(bool select) _selected = select; } -void Signal::paint_label(QPainter &p, const QRect &rect, bool hover) +void Signal::paint_label(QPainter &p, int y, int right, bool hover) { p.setBrush(_colour); const QColor colour = get_colour(); - const float nominal_offset = get_nominal_offset(rect); compute_text_size(p); - const QRectF label_rect = get_label_rect(rect); + const QRectF label_rect = get_label_rect(y, right); // Paint the label const QPointF points[] = { label_rect.topLeft(), label_rect.topRight(), - QPointF(rect.right(), nominal_offset), + QPointF(right, y), label_rect.bottomRight(), label_rect.bottomLeft() }; @@ -100,7 +99,7 @@ void Signal::paint_label(QPainter &p, const QRect &rect, bool hover) const QPointF highlight_points[] = { QPointF(label_rect.left() + 1, label_rect.top() + 1), QPointF(label_rect.right(), label_rect.top() + 1), - QPointF(rect.right() - 1, nominal_offset), + QPointF(right - 1, y), QPointF(label_rect.right(), label_rect.bottom() - 1), QPointF(label_rect.left() + 1, label_rect.bottom() - 1) }; @@ -130,15 +129,15 @@ void Signal::paint_label(QPainter &p, const QRect &rect, bool hover) p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name); } -bool Signal::pt_in_label_rect(const QRect &rect, const QPoint &point) +bool Signal::pt_in_label_rect(int y, int left, int right, + const QPoint &point) { - const QRectF label = get_label_rect(rect); + const QRectF label = get_label_rect(y, right); return QRectF( QPointF(label.left() - LabelHitPadding, label.top() - LabelHitPadding), - QPointF(rect.right(), - label.bottom() + LabelHitPadding) - ).contains(point); + QPointF(right, label.bottom() + LabelHitPadding) + ).contains(point); } void Signal::compute_text_size(QPainter &p) @@ -146,19 +145,17 @@ void Signal::compute_text_size(QPainter &p) _text_size = p.boundingRect(QRectF(), 0, _name).size(); } -QRectF Signal::get_label_rect(const QRect &rect) +QRectF Signal::get_label_rect(int y, int right) { using pv::view::View; - const float nominal_offset = get_nominal_offset(rect) + 0.5; const QSizeF label_size( _text_size.width() + View::LabelPadding.width() * 2, _text_size.height() + View::LabelPadding.height() * 2); const float label_arrow_length = label_size.height() / 2; return QRectF( - rect.right() - label_arrow_length - - label_size.width() - 0.5, - nominal_offset - label_size.height() / 2, + right - label_arrow_length - label_size.width() - 0.5, + y + 0.5f - label_size.height() / 2, label_size.width(), label_size.height()); } diff --git a/pv/view/signal.h b/pv/view/signal.h index 72019032..c35f557d 100644 --- a/pv/view/signal.h +++ b/pv/view/signal.h @@ -91,30 +91,38 @@ public: /** * Paints the signal with a QPainter * @param p the QPainter to paint into. - * @param rect the rectangular area to draw the trace into. + * @param y the y-coordinate to draw the signal at + * @param left the x-coordinate of the left edge of the signal + * @param right the x-coordinate of the right edge of the signal * @param scale the scale in seconds per pixel. * @param offset the time to show at the left hand edge of * the view in seconds. **/ - virtual void paint(QPainter &p, const QRect &rect, double scale, - double offset) = 0; - + virtual void paint(QPainter &p, int y, int left, int right, + double scale, double offset) = 0; /** * Paints the signal label into a QGLWidget. * @param p the QPainter to paint into. - * @param rect the rectangular area to draw the label into. + * @param y the y-coordinate of the signal. + * @param right the x-coordinate of the right edge of the header + * area. * @param hover true if the label is being hovered over by the mouse. */ - virtual void paint_label(QPainter &p, const QRect &rect, + virtual void paint_label(QPainter &p, int y, int right, bool hover); /** * Determines if a point is in the header label rect. - * @param rect the rectangular area to draw the label into. + * @param y the y-coordinate of the signal. + * @param left the x-coordinate of the left edge of the header + * area. + * @param right the x-coordinate of the right edge of the header + * area. * @param point the point to test. */ - bool pt_in_label_rect(const QRect &rect, const QPoint &point); + bool pt_in_label_rect(int y, int left, int right, + const QPoint &point); private: @@ -126,17 +134,12 @@ private: /** * Computes the outline rectangle of a label. * @param p the QPainter to lay out text with. - * @param rect The rectangle of the signal header. + * @param y the y-coordinate of the signal. + * @param right the x-coordinate of the right edge of the header + * area. * @return Returns the rectangle of the signal label. */ - QRectF get_label_rect(const QRect &rect); - -protected: - /** - * When painting into the rectangle, calculate the y - * offset of the zero point. - **/ - virtual int get_nominal_offset(const QRect &rect) const = 0; + QRectF get_label_rect(int y, int right); protected: QString _name; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 10f6613c..34676334 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -228,7 +228,7 @@ void View::update_scroll() void View::reset_signal_layout() { - int offset = SignalMargin; + int offset = SignalMargin + SignalHeight; const vector< shared_ptr > sigs(_session.get_signals()); BOOST_FOREACH(shared_ptr s, sigs) { s->set_v_offset(offset); diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index f39c8201..58826005 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -74,11 +74,8 @@ void Viewport::paintEvent(QPaintEvent*) BOOST_FOREACH(const shared_ptr s, sigs) { assert(s); - - const QRect signal_rect(0, s->get_v_offset() - v_offset, - width(), View::SignalHeight); - - s->paint(p, signal_rect, _view.scale(), _view.offset()); + s->paint(p, s->get_v_offset() - v_offset, 0, width(), + _view.scale(), _view.offset()); } draw_cursors_foreground(p);