+ // Show the info section on the right side of the trace
+ const QString infotext = QString("%1 V/div").arg(resolution_);
+
+ p.setPen(base_->colour());
+ p.setFont(QApplication::font());
+
+ const QRectF bounding_rect = QRectF(pp.left(),
+ y + v_extents().first,
+ pp.width() - InfoTextMarginRight,
+ v_extents().second - v_extents().first - InfoTextMarginBottom);
+
+ p.drawText(bounding_rect, Qt::AlignRight | Qt::AlignBottom, infotext);
+}
+
+void AnalogSignal::paint_grid(QPainter &p, int y, int left, int right)
+{
+ p.setRenderHint(QPainter::Antialiasing, false);
+
+ p.setPen(QPen(GridMajorColor, 1, Qt::DashLine));
+ for (int i = 1; i <= vdivs_; i++) {
+ const float dy = i * div_height_;
+ p.drawLine(QLineF(left, y - dy, right, y - dy));
+ p.drawLine(QLineF(left, y + dy, right, y + dy));
+ }
+
+ p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
+ for (int i = 0; i < vdivs_; i++) {
+ const float dy = i * div_height_;
+ const float dy25 = dy + (0.25 * div_height_);
+ const float dy50 = dy + (0.50 * div_height_);
+ const float dy75 = dy + (0.75 * div_height_);
+ p.drawLine(QLineF(left, y - dy25, right, y - dy25));
+ p.drawLine(QLineF(left, y + dy25, right, y + dy25));
+ p.drawLine(QLineF(left, y - dy50, right, y - dy50));
+ p.drawLine(QLineF(left, y + dy50, right, y + dy50));
+ p.drawLine(QLineF(left, y - dy75, right, y - dy75));
+ p.drawLine(QLineF(left, y + dy75, right, y + dy75));
+ }
+
+ p.setRenderHint(QPainter::Antialiasing, true);
+}
+
+void AnalogSignal::paint_trace(QPainter &p,
+ const shared_ptr<pv::data::AnalogSegment> &segment,
+ int y, int left, const int64_t start, const int64_t end,
+ const double pixels_offset, const double samples_per_pixel)
+{
+ const int64_t sample_count = end - start;
+
+ const float *const samples = segment->get_samples(start, end);
+ assert(samples);
+
+ p.setPen(base_->colour());
+
+ QPointF *points = new QPointF[sample_count];
+ QPointF *point = points;
+
+ for (int64_t sample = start; sample != end; sample++) {
+ const float x = (sample / samples_per_pixel -
+ pixels_offset) + left;
+ *point++ = QPointF(x,
+ y - samples[sample - start] * scale_);
+ }
+
+ p.drawPolyline(points, point - points);
+
+ delete[] samples;
+ delete[] points;
+}
+
+void AnalogSignal::paint_envelope(QPainter &p,
+ const shared_ptr<pv::data::AnalogSegment> &segment,
+ int y, int left, const int64_t start, const int64_t end,
+ const double pixels_offset, const double samples_per_pixel)
+{
+ using pv::data::AnalogSegment;
+
+ AnalogSegment::EnvelopeSection e;
+ segment->get_envelope_section(e, start, end, samples_per_pixel);
+
+ if (e.length < 2)
+ return;
+
+ p.setPen(QPen(Qt::NoPen));
+ p.setBrush(base_->colour());
+
+ QRectF *const rects = new QRectF[e.length];
+ QRectF *rect = rects;
+
+ for (uint64_t sample = 0; sample < e.length-1; sample++) {
+ const float x = ((e.scale * sample + e.start) /
+ samples_per_pixel - pixels_offset) + left;
+ const AnalogSegment::EnvelopeSample *const s =
+ e.samples + sample;
+
+ // We overlap this sample with the next so that vertical
+ // gaps do not appear during steep rising or falling edges
+ const float b = y - max(s->max, (s+1)->min) * scale_;
+ const float t = y - min(s->min, (s+1)->max) * scale_;
+
+ float h = b - t;
+ if (h >= 0.0f && h <= 1.0f)
+ h = 1.0f;
+ if (h <= 0.0f && h >= -1.0f)
+ h = -1.0f;
+
+ *rect++ = QRectF(x, t, 1.0f, h);
+ }
+
+ p.drawRects(rects, e.length);
+
+ delete[] rects;
+ delete[] e.samples;
+}
+
+float AnalogSignal::get_resolution(int scale_index)
+{
+ const float seq[] = {1.0f, 2.0f, 5.0f};
+
+ const int offset = std::numeric_limits<int>::max() / (2 * countof(seq));
+ const std::div_t d = std::div(
+ (int)(scale_index + countof(seq) * offset),
+ countof(seq));
+
+ return powf(10.0f, d.quot - offset) * seq[d.rem];
+}
+
+void AnalogSignal::update_scale()
+{
+ resolution_ = get_resolution(scale_index_);
+ scale_ = div_height_ / resolution_;
+}
+
+void AnalogSignal::populate_popup_form(QWidget *parent, QFormLayout *form)