]> sigrok.org Git - pulseview.git/commitdiff
Eliminated get_nominal_offset
authorJoel Holdsworth <redacted>
Fri, 18 Jan 2013 18:33:01 +0000 (18:33 +0000)
committerJoel Holdsworth <redacted>
Sat, 19 Jan 2013 21:00:09 +0000 (21:00 +0000)
pv/view/analogsignal.cpp
pv/view/analogsignal.h
pv/view/header.cpp
pv/view/logicsignal.cpp
pv/view/logicsignal.h
pv/view/signal.cpp
pv/view/signal.h
pv/view/view.cpp
pv/view/viewport.cpp

index fb5eba6103ad6ba9f3f22936d86fe831d07a5d66..136080694bbb03029c21691efe0b9b3293ac5c3c 100644 (file)
@@ -39,11 +39,12 @@ AnalogSignal::AnalogSignal(QString name, shared_ptr<data::Analog> 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<pv::data::AnalogSnapshot> > &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
index 7bc0ed6eb6aaf25d9a605a22c1ab038dec3103a6..86471537abce44236291664b98a1e74084cc187d 100644 (file)
@@ -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<pv::data::Analog> _data;
index a615e8513e7ff04d95b1b56af7c24299858af4c9..e0e280b2826dc3c988c362d1c2eaecaf0a508f29 100644 (file)
@@ -71,11 +71,8 @@ boost::shared_ptr<pv::view::Signal> 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();
index d23da5bbf021815a5b668ccfb624ebfb401d9e38..051da4d89af92ef1694c88cdd08901c487a15b2b 100644 (file)
@@ -23,6 +23,7 @@
 #include <math.h>
 
 #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::Logic> 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<int64_t, bool> > 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<pv::data::LogicSnapshot> > &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
index e20f13c7a9fdb803a285d19c1fd19657f3476513..ad88241da34de704c783e77a7acc4bfb63763b87 100644 (file)
@@ -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<pv::data::Logic> _data;
index 33cfef2d418839a588bc269ac36729b30e67ae2b..2469d981632b59d9f8eaadb0b8cc2248d41e831c 100644 (file)
@@ -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());
 }
 
index 72019032e06a74e221f92c4d9ea0ddf57fa968e6..c35f557dcd7ac66a9ed6b80a5f7e563d6957fe92 100644 (file)
@@ -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;
index 10f6613c55da3fd2f362e51c67ff365a708b4359..34676334dc67867ba9b17fa064498232693e74e0 100644 (file)
@@ -228,7 +228,7 @@ void View::update_scroll()
 
 void View::reset_signal_layout()
 {
-       int offset = SignalMargin;
+       int offset = SignalMargin + SignalHeight;
        const vector< shared_ptr<Signal> > sigs(_session.get_signals());
        BOOST_FOREACH(shared_ptr<Signal> s, sigs) {
                s->set_v_offset(offset);
index f39c8201421d43956e5b6e3bc72c2768ab0cf365..5882600524d1b77bdfaf0d02ce38ad2e040a96e3 100644 (file)
@@ -74,11 +74,8 @@ void Viewport::paintEvent(QPaintEvent*)
        BOOST_FOREACH(const shared_ptr<Signal> 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);