AnalogSignal: Make sure the trace is redrawn when changing vdiv count
[pulseview.git] / pv / view / analogsignal.cpp
index 6703ce9ed8b2c1b4e40cab8b905231b284cf450e..9001924a687f4f301e63c4fcc1bec24aae4d7b69 100644 (file)
@@ -31,6 +31,7 @@
 #include <QGridLayout>
 #include <QLabel>
 #include <QSpinBox>
+#include <QString>
 
 #include "analogsignal.hpp"
 #include "pv/data/analog.hpp"
@@ -57,8 +58,8 @@ const QColor AnalogSignal::SignalColours[4] = {
        QColor(0x4E, 0x9A, 0x06)        // Green
 };
 
-const QColor AnalogSignal::GridMajorColor = QColor(0xB0, 0xB0, 0xB0);
-const QColor AnalogSignal::GridMinorColor = QColor(0xD0, 0xD0, 0xD0);
+const QColor AnalogSignal::GridMajorColor = QColor(0, 0, 0, 40*256/100);
+const QColor AnalogSignal::GridMinorColor = QColor(0, 0, 0, 20*256/100);
 
 const float AnalogSignal::EnvelopeThreshold = 256.0f;
 
@@ -66,6 +67,9 @@ const int AnalogSignal::MaximumVDivs = 10;
 const int AnalogSignal::MinScaleIndex = -6;
 const int AnalogSignal::MaxScaleIndex = 7;
 
+const int AnalogSignal::InfoTextMarginRight = 20;
+const int AnalogSignal::InfoTextMarginBottom = 5;
+
 AnalogSignal::AnalogSignal(
        pv::Session &session,
        shared_ptr<Channel> channel,
@@ -173,18 +177,41 @@ void AnalogSignal::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
                        pixels_offset, samples_per_pixel);
 }
 
+void AnalogSignal::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
+{
+       if (!enabled())
+               return;
+
+       const int y = get_visual_y();
+
+       // Show the info section on the right side of the trace
+       const QString infotext = QString("%1 V/div").arg(resolution_);
+
+       p.setPen(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.setPen(QPen(GridMajorColor, 0.5, Qt::DashLine));
+       p.setRenderHint(QPainter::Antialiasing, false);
+
+       p.setPen(QPen(GridMajorColor, 1, Qt::DashLine));
        for (int i = 1; i <= vdivs_; i++) {
-               const int dy = i * div_height_;
+               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, 0.5, Qt::DashLine));
+       p.setPen(QPen(GridMinorColor, 1, Qt::DashLine));
        for (int i = 0; i < vdivs_; i++) {
-               const int dy = i * div_height_;
+               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_);
@@ -195,6 +222,8 @@ void AnalogSignal::paint_grid(QPainter &p, int y, int left, int right)
                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,
@@ -331,8 +360,11 @@ void AnalogSignal::on_vdivs_changed(int vdivs)
 {
        vdivs_ = vdivs;
 
-       if (owner_)
+       if (owner_) {
+               // Call order is important, otherwise the lazy event handler won't work
                owner_->extents_changed(false, true);
+               owner_->row_item_appearance_changed(false, true);
+       }
 }
 
 void AnalogSignal::on_resolution_changed(int index)