]> sigrok.org Git - pulseview.git/commitdiff
AnalogSignal: Implement info text for V/div display
authorSoeren Apel <redacted>
Thu, 7 Apr 2016 20:03:40 +0000 (22:03 +0200)
committerSoeren Apel <redacted>
Thu, 7 Apr 2016 20:03:40 +0000 (22:03 +0200)
pv/view/analogsignal.cpp
pv/view/analogsignal.hpp

index 6703ce9ed8b2c1b4e40cab8b905231b284cf450e..7e5bcd11facdb6d1a81368c27fd866da1afc6ff9 100644 (file)
@@ -31,6 +31,7 @@
 #include <QGridLayout>
 #include <QLabel>
 #include <QSpinBox>
+#include <QString>
 
 #include "analogsignal.hpp"
 #include "pv/data/analog.hpp"
@@ -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,6 +177,27 @@ 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));
index 9c9c6db8aeffd04321799567935ecf3ba17417ec..47a9980c0ff9dc8272aad16b391f96a8e361799d 100644 (file)
@@ -48,6 +48,7 @@ private:
 
        static const int MaximumVDivs;
        static const int MaxScaleIndex, MinScaleIndex;
+       static const int InfoTextMarginRight, InfoTextMarginBottom;
 
 public:
        AnalogSignal(pv::Session &session,
@@ -96,6 +97,13 @@ public:
         */
        void paint_mid(QPainter &p, const ViewItemPaintParams &pp);
 
+       /**
+        * Paints the foreground layer of the item with a QPainter
+        * @param p the QPainter to paint into.
+        * @param pp the painting parameters object to paint with.
+        */
+       void paint_fore(QPainter &p, const ViewItemPaintParams &pp);
+
 private:
        void paint_grid(QPainter &p, int y, int left, int right);