From: Miklos Marton Date: Wed, 10 Jul 2019 07:55:47 +0000 (+0200) Subject: Add temporary snapping disable menu to markers and cursors X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=0aabc15a4e23b2a636d2452ae1a69981bdb77329;p=pulseview.git Add temporary snapping disable menu to markers and cursors Add context menu to the cursors and time markers for temporary disabling the snapping to digital edges of the markers. --- diff --git a/pv/views/trace/cursor.cpp b/pv/views/trace/cursor.cpp index 0fcb6faf..80eaba23 100644 --- a/pv/views/trace/cursor.cpp +++ b/pv/views/trace/cursor.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -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::get_other_cursor() const { const shared_ptr cursors(view_.cursors()); diff --git a/pv/views/trace/cursor.hpp b/pv/views/trace/cursor.hpp index c3960d6d..08be9707 100644 --- a/pv/views/trace/cursor.hpp +++ b/pv/views/trace/cursor.hpp @@ -67,6 +67,8 @@ public: */ QRectF label_rect(const QRectF &rect) const; + virtual QMenu* create_header_context_menu(QWidget *parent) override; + private: shared_ptr get_other_cursor() const; }; diff --git a/pv/views/trace/flag.cpp b/pv/views/trace/flag.cpp index 81af1086..ea3cd609 100644 --- a/pv/views/trace/flag.cpp +++ b/pv/views/trace/flag.cpp @@ -137,6 +137,12 @@ QMenu* Flag::create_header_context_menu(QWidget *parent) connect(del, SIGNAL(triggered()), this, SLOT(on_delete())); menu->addAction(del); + 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; } diff --git a/pv/views/trace/timeitem.cpp b/pv/views/trace/timeitem.cpp index f2eb5957..3de62258 100644 --- a/pv/views/trace/timeitem.cpp +++ b/pv/views/trace/timeitem.cpp @@ -31,13 +31,17 @@ TimeItem::TimeItem(View &view) : void TimeItem::drag_by(const QPoint &delta) { - int64_t sample_num = view_.get_nearest_level_change(drag_point_ + delta); - - if (sample_num > -1) - set_time(sample_num / view_.get_signal_under_mouse_cursor()->base()->get_samplerate()); - else + if (snapping_disabled_) { set_time(view_.offset() + (drag_point_.x() + delta.x() - 0.5) * view_.scale()); + } else { + int64_t sample_num = view_.get_nearest_level_change(drag_point_ + delta); + + if (sample_num > -1) + set_time(sample_num / view_.get_signal_under_mouse_cursor()->base()->get_samplerate()); + else + set_time(view_.offset() + (drag_point_.x() + delta.x() - 0.5) * view_.scale()); + } } const pv::util::Timestamp TimeItem::delta(const pv::util::Timestamp& other) const @@ -45,6 +49,12 @@ const pv::util::Timestamp TimeItem::delta(const pv::util::Timestamp& other) cons return other - time(); } + +bool TimeItem::is_snapping_disabled() const +{ + return snapping_disabled_; +} + } // namespace trace } // namespace views } // namespace pv diff --git a/pv/views/trace/timeitem.hpp b/pv/views/trace/timeitem.hpp index e0114a5a..06d85050 100644 --- a/pv/views/trace/timeitem.hpp +++ b/pv/views/trace/timeitem.hpp @@ -43,6 +43,8 @@ protected: */ TimeItem(View &view); + bool snapping_disabled_ = false; + public: /** * Sets the time of the marker. @@ -65,6 +67,8 @@ public: */ void drag_by(const QPoint &delta); + bool is_snapping_disabled() const; + protected: View &view_; };