From ce6e73a8e2a2a353233b440f4bbbd53007602e1a Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Wed, 24 Oct 2012 21:22:58 +0100 Subject: [PATCH] Render ruler and signals with sub-pixel accuracy --- pv/logicsignal.cpp | 14 +++++++------- pv/logicsignal.h | 2 +- pv/view/ruler.cpp | 8 +++++--- pv/view/viewport.cpp | 1 + 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pv/logicsignal.cpp b/pv/logicsignal.cpp index 28d71d3c..a0dabe4a 100644 --- a/pv/logicsignal.cpp +++ b/pv/logicsignal.cpp @@ -70,8 +70,8 @@ void LogicSignal::paint(QPainter &p, const QRect &rect, double scale, assert(scale > 0); assert(_data); - const float high_offset = rect.top() + Margin; - const float low_offset = rect.bottom() - Margin; + const float high_offset = rect.top() + Margin + 0.5f; + const float low_offset = rect.bottom() - Margin + 0.5f; const deque< shared_ptr > &snapshots = _data->get_snapshots(); @@ -102,7 +102,7 @@ void LogicSignal::paint(QPainter &p, const QRect &rect, double scale, for(vector::const_iterator i = edges.begin() + 1; i != edges.end() - 1; i++) { - const int x = (int)((*i).first / samples_per_pixel - + const float x = ((*i).first / samples_per_pixel - pixels_offset) + rect.left(); *line++ = QLineF(x, high_offset, x, low_offset); } @@ -127,8 +127,8 @@ void LogicSignal::paint(QPainter &p, const QRect &rect, double scale, void LogicSignal::paint_caps(QPainter &p, QLineF *const lines, vector< pair > &edges, bool level, - double samples_per_pixel, double pixels_offset, int x_offset, - int y_offset) + double samples_per_pixel, double pixels_offset, float x_offset, + float y_offset) { QLineF *line = lines; @@ -136,9 +136,9 @@ void LogicSignal::paint_caps(QPainter &p, QLineF *const lines, i != (edges.end() - 1); i++) if((*i).second == level) { *line++ = QLineF( - (int)((*i).first / samples_per_pixel - + ((*i).first / samples_per_pixel - pixels_offset) + x_offset, y_offset, - (int)((*(i+1)).first / samples_per_pixel - + ((*(i+1)).first / samples_per_pixel - pixels_offset) + x_offset, y_offset); } diff --git a/pv/logicsignal.h b/pv/logicsignal.h index 54145a8c..5c527206 100644 --- a/pv/logicsignal.h +++ b/pv/logicsignal.h @@ -61,7 +61,7 @@ private: void paint_caps(QPainter &p, QLineF *const lines, std::vector< std::pair > &edges, bool level, double samples_per_pixel, double pixels_offset, - int x_offset, int y_offset); + float x_offset, float y_offset); /** * Get the colour of the logic signal diff --git a/pv/view/ruler.cpp b/pv/view/ruler.cpp index 5dea1947..97c0be68 100644 --- a/pv/view/ruler.cpp +++ b/pv/view/ruler.cpp @@ -48,6 +48,7 @@ Ruler::Ruler(View &parent) : void Ruler::paintEvent(QPaintEvent *event) { QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); const double MinSpacing = 80; @@ -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++; diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index c1490fc8..99e08b27 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -61,6 +61,7 @@ void Viewport::paintEvent(QPaintEvent *event) _view.session().get_signals(); QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); // Plot the signal int offset = -_view.v_offset(); -- 2.30.2