]> sigrok.org Git - pulseview.git/blobdiff - pv/views/trace/cursor.cpp
trace: fix crash on empty channel name in popup form
[pulseview.git] / pv / views / trace / cursor.cpp
index 0fcb6faf44dd9048b9ea842fdc57d7734b28a3f9..8462a3a604c6e2509f0389c5ffbec96ba91c5908 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QApplication>
 #include <QBrush>
+#include <QMenu>
 #include <QPainter>
 #include <QPointF>
 #include <QRect>
@@ -71,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,
@@ -89,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> Cursor::get_other_cursor() const
 {
        const shared_ptr<CursorPair> cursors(view_.cursors());