]> sigrok.org Git - pulseview.git/blobdiff - pv/view/decodetrace.cpp
ViewItem: Moved in paint_fore, paint_mid and paint_back
[pulseview.git] / pv / view / decodetrace.cpp
index 94ef5f9a4a1364a9fac3c843cbb84173f3228031..669a1d95d3a5347c89b0bb51f1925027a377612f 100644 (file)
@@ -160,21 +160,21 @@ pair<int, int> DecodeTrace::v_extents() const
 {
        /// @todo Replace this with an implementation that knows the true
        /// height of the trace
-       const int row_height = (RowItemPaintParams::text_height() * 6) / 4;
+       const int row_height = (ViewItemPaintParams::text_height() * 6) / 4;
        return make_pair(-row_height / 2, row_height * 7 / 2);
 }
 
-void DecodeTrace::paint_back(QPainter &p, const RowItemPaintParams &pp)
+void DecodeTrace::paint_back(QPainter &p, const ViewItemPaintParams &pp)
 {
        Trace::paint_back(p, pp);
        paint_axis(p, pp, get_visual_y());
 }
 
-void DecodeTrace::paint_mid(QPainter &p, const RowItemPaintParams &pp)
+void DecodeTrace::paint_mid(QPainter &p, const ViewItemPaintParams &pp)
 {
        using namespace pv::data::decode;
 
-       text_height_ = RowItemPaintParams::text_height();
+       text_height_ = ViewItemPaintParams::text_height();
        row_height_ = (text_height_ * 6) / 4;
        const int annotation_height = (text_height_ * 5) / 4;
 
@@ -224,7 +224,7 @@ void DecodeTrace::paint_mid(QPainter &p, const RowItemPaintParams &pp)
        draw_unresolved_period(p, annotation_height, pp.left(), pp.right());
 }
 
-void DecodeTrace::paint_fore(QPainter &p, const RowItemPaintParams &pp)
+void DecodeTrace::paint_fore(QPainter &p, const ViewItemPaintParams &pp)
 {
        using namespace pv::data::decode;
 
@@ -333,7 +333,7 @@ QMenu* DecodeTrace::create_context_menu(QWidget *parent)
 }
 
 void DecodeTrace::draw_annotation(const pv::data::decode::Annotation &a,
-       QPainter &p, int h, const RowItemPaintParams &pp, int y,
+       QPainter &p, int h, const ViewItemPaintParams &pp, int y,
        size_t base_colour) const
 {
        double samples_per_pixel, pixels_offset;
@@ -435,7 +435,7 @@ void DecodeTrace::draw_range(const pv::data::decode::Annotation &a, QPainter &p,
 }
 
 void DecodeTrace::draw_error(QPainter &p, const QString &message,
-       const RowItemPaintParams &pp)
+       const ViewItemPaintParams &pp)
 {
        const int y = get_visual_y();
 
@@ -556,9 +556,15 @@ int DecodeTrace::get_row_at_point(const QPoint &point)
        if (!row_height_)
                return -1;
 
-       const int row = (point.y() - get_visual_y() + row_height_ / 2) /
-               row_height_;
-       if (row < 0 || row >= (int)visible_rows_.size())
+       const int y = (point.y() - get_visual_y() + row_height_ / 2);
+
+       /* Integer divison of (x-1)/x would yield 0, so we check for this. */
+       if (y < 0)
+               return -1;
+
+       const int row = y / row_height_;
+
+       if (row >= (int)visible_rows_.size())
                return -1;
 
        return row;
@@ -587,11 +593,6 @@ const QString DecodeTrace::get_annotation_at_point(const QPoint &point)
                QString() : annotations[0].annotations().front();
 }
 
-void DecodeTrace::hide_hover_annotation()
-{
-       QToolTip::hideText();
-}
-
 void DecodeTrace::hover_point_changed()
 {
        assert(owner_);
@@ -605,7 +606,7 @@ void DecodeTrace::hover_point_changed()
        assert(view);
 
        if (!row_height_ || ann.isEmpty()) {
-               hide_hover_annotation();
+               QToolTip::hideText();
                return;
        }
 
@@ -626,7 +627,7 @@ void DecodeTrace::hover_point_changed()
 
        hp.setY(get_visual_y() - (row_height_ / 2) +
                (hover_row * row_height_) -
-               row_height_ - text_size.height());
+               row_height_ - text_size.height() - padding);
 
        QToolTip::showText(view->viewport()->mapToGlobal(hp), ann);
 }