]> sigrok.org Git - pulseview.git/commitdiff
DecodeTrace: Make tool tips use mapToGlobal() of the view's viewport
authorSoeren Apel <redacted>
Tue, 18 Nov 2014 19:02:29 +0000 (19:02 +0000)
committerJoel Holdsworth <redacted>
Tue, 18 Nov 2014 22:56:43 +0000 (22:56 +0000)
pv/view/decodetrace.cpp

index e290e55fe2ae68fa72c0f9cfefae29e371c5d72c..5ee86452d8fe9d6db49048702a39d848bb84ba84 100644 (file)
@@ -45,6 +45,7 @@ extern "C" {
 #include <pv/data/decode/annotation.h>
 #include <pv/view/logicsignal.h>
 #include <pv/view/view.h>
+#include <pv/view/viewport.h>
 #include <pv/widgets/decodergroupbox.h>
 #include <pv/widgets/decodermenu.h>
 
@@ -606,18 +607,29 @@ void DecodeTrace::show_hover_annotation()
 
        assert(_view);
        assert(_row_height);
-       assert(_text_height);
 
        if (!ann.isEmpty()) {
                const int hover_row = get_row_at_hover_point();
 
+               QFontMetrics m(QToolTip::font());
+               const QRect text_size = m.boundingRect(QRect(), 0, ann);
+
+               // This is OS-specific and unfortunately we can't query it, so
+               // use an approximation to at least try to minimize the error.
+               const int padding = 8;
+
                // Make sure the tool tip doesn't overlap with the mouse cursor.
                // If it did, the tool tip would constantly hide and re-appear.
+               // We also push it up by one row so that it appears above the
+               // decode trace, not below.
                QPoint hp = _view->hover_point();
-               hp.setY(get_y() - (_row_height/2) +
-                       (hover_row * _row_height) - _text_height);
 
-               QToolTip::showText(_view->mapToGlobal(hp), ann);
+               hp.setX(hp.x() - (text_size.width() / 2) - padding);
+
+               hp.setY(get_y() - (_row_height / 2) + (hover_row * _row_height)
+                       - _row_height - text_size.height());
+
+               QToolTip::showText(_view->viewport()->mapToGlobal(hp), ann);
        } else
                hide_hover_annotation();
 }