]> sigrok.org Git - pulseview.git/blobdiff - pv/view/ruler.cpp
Render ruler and signals with sub-pixel accuracy
[pulseview.git] / pv / view / ruler.cpp
index f71240de1722c301d9b6ad0bb1960a8ff338e5ed..97c0be6822506ffa1c3056493a629d14428dc6e2 100644 (file)
@@ -48,6 +48,7 @@ Ruler::Ruler(View &parent) :
 void Ruler::paintEvent(QPaintEvent *event)
 {
        QPainter p(this);
+       p.setRenderHint(QPainter::Antialiasing);
 
        const double MinSpacing = 80;
 
@@ -68,7 +69,7 @@ void Ruler::paintEvent(QPaintEvent *event)
        assert(prefix >= 0);
        assert(prefix < countof(SIPrefixes));
 
-       const double multiplier = pow(0.1, prefix * 3 + FirstSIPrefixPower);
+       const double multiplier = pow(10.0, - prefix * 3 - FirstSIPrefixPower);
 
        const int text_height = p.boundingRect(0, 0, INT_MAX, INT_MAX,
                Qt::AlignLeft | Qt::AlignTop, "8").height();
@@ -101,13 +102,14 @@ void Ruler::paintEvent(QPaintEvent *event)
                        ts << (t * multiplier) << SIPrefixes[prefix] << "s";
                        p.drawText(x, 0, 0, text_height, Qt::AlignCenter |
                                Qt::AlignTop | Qt::TextDontClip, s);
-                       p.drawLine(x, text_height, x, height());
+                       p.drawLine(QPointF(x, text_height),
+                               QPointF(x, height()));
                }
                else
                {
                        // Draw a minor tick
-                       p.drawLine(x, (text_height + height()) / 2,
-                               x, height());
+                       p.drawLine(QPointF(x, (text_height + height()) / 2),
+                               QPointF(x, height()));
                }
 
                division++;