X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fviews%2Ftrace%2Fcursor.cpp;h=8462a3a604c6e2509f0389c5ffbec96ba91c5908;hb=HEAD;hp=4fb4b65d9841deec2594422092997db66a386f01;hpb=1573bf16ba50d1c023ad3a9ce596f0ab6eaeacff;p=pulseview.git diff --git a/pv/views/trace/cursor.cpp b/pv/views/trace/cursor.cpp index 4fb4b65d..8462a3a6 100644 --- a/pv/views/trace/cursor.cpp +++ b/pv/views/trace/cursor.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -34,17 +35,17 @@ #include #include -using std::abs; // Force usage of std::abs() instead of C's abs(). +using std::abs; // NOLINT. Force usage of std::abs() instead of C's abs(). using std::shared_ptr; namespace pv { namespace views { namespace trace { -const QColor Cursor::FillColour(52, 101, 164); +const QColor Cursor::FillColor(52, 101, 164); Cursor::Cursor(View &view, double time) : - TimeMarker(view, FillColour, time) + TimeMarker(view, FillColor, time) { } @@ -59,7 +60,8 @@ QString Cursor::get_text() const const pv::util::Timestamp& diff = abs(time_ - other->time_); return Ruler::format_time_with_distance( - diff, time_, view_.tick_prefix(), view_.time_unit(), view_.tick_precision()); + diff, view_.ruler()->get_ruler_time_from_absolute_time(time_), + view_.tick_prefix(), view_.time_unit(), view_.tick_precision()); } QRectF Cursor::label_rect(const QRectF &rect) const @@ -70,7 +72,7 @@ QRectF Cursor::label_rect(const QRectF &rect) const const float x = get_x(); QFontMetrics m(QApplication::font()); - QSize text_size = m.boundingRect(get_text()).size(); + QSize text_size = m.boundingRect(get_display_text()).size(); const QSizeF label_size( text_size.width() + LabelPadding.width() * 2, @@ -88,6 +90,19 @@ QRectF Cursor::label_rect(const QRectF &rect) const return QRectF(x - label_size.width(), top, label_size.width(), height); } +QMenu *Cursor::create_header_context_menu(QWidget *parent) +{ + QMenu *const menu = new QMenu(parent); + + QAction *const snap_disable = new QAction(tr("Disable snapping"), this); + snap_disable->setCheckable(true); + snap_disable->setChecked(snapping_disabled_); + connect(snap_disable, &QAction::toggled, this, [=](bool checked){snapping_disabled_ = checked;}); + menu->addAction(snap_disable); + + return menu; +} + shared_ptr Cursor::get_other_cursor() const { const shared_ptr cursors(view_.cursors());