X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fview%2Fcursorheader.cpp;h=a9b709f2ecc30966a70e86350133d00bce340b4f;hb=0dda6fe595932b2e340930104fad8ac4fc574895;hp=d1660276417d65a79e42a628aeee87cfd92bc716;hpb=84a0d458a4b04141dd45af6dec44d36782ee163e;p=pulseview.git diff --git a/pv/view/cursorheader.cpp b/pv/view/cursorheader.cpp index d1660276..a9b709f2 100644 --- a/pv/view/cursorheader.cpp +++ b/pv/view/cursorheader.cpp @@ -20,9 +20,11 @@ #include "cursorheader.h" +#include "ruler.h" #include "view.h" #include +#include #include #include @@ -32,18 +34,27 @@ using std::shared_ptr; namespace pv { namespace view { -const int CursorHeader::CursorHeaderHeight = 26; +const int CursorHeader::Padding = 20; +const int CursorHeader::BaselineOffset = 5; + +int CursorHeader::calculateTextHeight() +{ + QFontMetrics fm(font()); + return fm.boundingRect(0, 0, INT_MAX, INT_MAX, + Qt::AlignLeft | Qt::AlignTop, "8").height(); +} CursorHeader::CursorHeader(View &parent) : MarginWidget(parent), - _dragging(false) + _dragging(false), + _textHeight(calculateTextHeight()) { setMouseTracking(true); } QSize CursorHeader::sizeHint() const { - return QSize(0, CursorHeaderHeight); + return QSize(0, _textHeight + Padding + BaselineOffset); } void CursorHeader::clear_selection() @@ -59,9 +70,16 @@ void CursorHeader::paintEvent(QPaintEvent*) QPainter p(this); p.setRenderHint(QPainter::Antialiasing); + unsigned int prefix = pv::view::Ruler::calculate_tick_spacing( + p, _view.scale(), _view.offset()).second; + // Draw the cursors if (_view.cursors_shown()) { - _view.cursors().draw_markers(p, rect(), 0); //prefix); + // The cursor labels are not drawn with the arrows exactly on the + // bottom line of the widget, because then the selection shadow + // would be clipped away. + const QRect r = rect().adjusted(0, 0, 0, -BaselineOffset); + _view.cursors().draw_markers(p, r, prefix); } } @@ -114,8 +132,8 @@ void CursorHeader::mouseReleaseEvent(QMouseEvent *) if (!_dragging) if (shared_ptr m = _grabbed_marker.lock()) { Popup *const p = m->create_popup(&_view); - p->set_position(mapToGlobal(QPoint(m->get_x(), - height())), Popup::Bottom); + const QPoint arrpos(m->get_x(), height() - BaselineOffset); + p->set_position(mapToGlobal(arrpos), Popup::Bottom); p->show(); }