X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fruler.cpp;h=97c0be6822506ffa1c3056493a629d14428dc6e2;hp=27db2f4e844e2398320f9a944026ec084687c59a;hb=ce6e73a8e2a2a353233b440f4bbbd53007602e1a;hpb=ccdd3ef548ce34f25c6c168598556a350831aa37 diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index 27db2f4e..97c0be68 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the PulseView project. * * Copyright (C) 2012 Joel Holdsworth * @@ -21,7 +21,7 @@ #include "ruler.h" #include "view.h" -#include "../../extdef.h" +#include #include #include @@ -48,6 +48,7 @@ Ruler::Ruler(View &parent) : void Ruler::paintEvent(QPaintEvent *event) { QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); const double MinSpacing = 80; @@ -56,7 +57,7 @@ void Ruler::paintEvent(QPaintEvent *event) const int order = (int)floorf(log10f(min_period)); const double order_decimal = pow(10, order); - int unit = 0; + unsigned int unit = 0; double tick_period = 0.0f; do @@ -64,10 +65,12 @@ void Ruler::paintEvent(QPaintEvent *event) tick_period = order_decimal * ScaleUnits[unit++]; } while(tick_period < min_period && unit < countof(ScaleUnits)); - const int prefix = (order - FirstSIPrefixPower) / 3; + const unsigned int prefix = (order - FirstSIPrefixPower) / 3; assert(prefix >= 0); assert(prefix < countof(SIPrefixes)); + 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(); @@ -96,16 +99,17 @@ void Ruler::paintEvent(QPaintEvent *event) // Draw a major tick QString s; QTextStream ts(&s); - ts << (t / order_decimal) << SIPrefixes[prefix] << "s"; + 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++;