]> sigrok.org Git - pulseview.git/commitdiff
Render ruler and signals with sub-pixel accuracy
authorJoel Holdsworth <redacted>
Wed, 24 Oct 2012 20:22:58 +0000 (21:22 +0100)
committerJoel Holdsworth <redacted>
Wed, 24 Oct 2012 20:22:58 +0000 (21:22 +0100)
pv/logicsignal.cpp
pv/logicsignal.h
pv/view/ruler.cpp
pv/view/viewport.cpp

index 28d71d3cbc5070b853842bec03b81d70c23dafa2..a0dabe4a00ed1c39bf1d68c51a950238afc448f4 100644 (file)
@@ -70,8 +70,8 @@ void LogicSignal::paint(QPainter &p, const QRect &rect, double scale,
        assert(scale > 0);
        assert(_data);
 
        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<LogicDataSnapshot> > &snapshots =
                _data->get_snapshots();
 
        const deque< shared_ptr<LogicDataSnapshot> > &snapshots =
                _data->get_snapshots();
@@ -102,7 +102,7 @@ void LogicSignal::paint(QPainter &p, const QRect &rect, double scale,
        for(vector<LogicDataSnapshot::EdgePair>::const_iterator i =
                        edges.begin() + 1;
                i != edges.end() - 1; i++) {
        for(vector<LogicDataSnapshot::EdgePair>::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);
        }
                        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<int64_t, bool> > &edges, bool level,
 
 void LogicSignal::paint_caps(QPainter &p, QLineF *const lines,
        vector< pair<int64_t, bool> > &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;
 
 {
        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(
            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,
                                        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);
                }
 
                                        pixels_offset) + x_offset, y_offset);
                }
 
index 54145a8c231d0e6632b7426773dba244886c695e..5c527206d521faf915345aa3940a949ae937cb68 100644 (file)
@@ -61,7 +61,7 @@ private:
        void paint_caps(QPainter &p, QLineF *const lines,
                std::vector< std::pair<int64_t, bool> > &edges,
                bool level, double samples_per_pixel, double pixels_offset,
        void paint_caps(QPainter &p, QLineF *const lines,
                std::vector< std::pair<int64_t, bool> > &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
 
        /**
         * Get the colour of the logic signal
index 5dea19474c84714a3f653e8449ff099f0f700625..97c0be6822506ffa1c3056493a629d14428dc6e2 100644 (file)
@@ -48,6 +48,7 @@ Ruler::Ruler(View &parent) :
 void Ruler::paintEvent(QPaintEvent *event)
 {
        QPainter p(this);
 void Ruler::paintEvent(QPaintEvent *event)
 {
        QPainter p(this);
+       p.setRenderHint(QPainter::Antialiasing);
 
        const double MinSpacing = 80;
 
 
        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);
                        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
                }
                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++;
                }
 
                division++;
index c1490fc82725c2ab739ebab53e3a5af79f558f6c..99e08b277d151160bbf3b0842d68f0119c60582a 100644 (file)
@@ -61,6 +61,7 @@ void Viewport::paintEvent(QPaintEvent *event)
                _view.session().get_signals();
 
        QPainter p(this);
                _view.session().get_signals();
 
        QPainter p(this);
+       p.setRenderHint(QPainter::Antialiasing);
 
        // Plot the signal
        int offset = -_view.v_offset();
 
        // Plot the signal
        int offset = -_view.v_offset();