]> sigrok.org Git - pulseview.git/commitdiff
Add temporary snapping disable menu to markers and cursors
authorMiklos Marton <redacted>
Wed, 10 Jul 2019 07:55:47 +0000 (09:55 +0200)
committerUwe Hermann <redacted>
Sat, 9 Nov 2019 15:21:41 +0000 (16:21 +0100)
Add context menu to the cursors and time markers for temporary disabling
the snapping to digital edges of the markers.

pv/views/trace/cursor.cpp
pv/views/trace/cursor.hpp
pv/views/trace/flag.cpp
pv/views/trace/timeitem.cpp
pv/views/trace/timeitem.hpp

index 0fcb6faf44dd9048b9ea842fdc57d7734b28a3f9..80eaba232b1d8157b2bbfacbb40ebe202e79670a 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QApplication>
 #include <QBrush>
+#include <QMenu>
 #include <QPainter>
 #include <QPointF>
 #include <QRect>
@@ -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());
index c3960d6d39aa57d5d3bd8c6a02773ccc14eb65e2..08be9707eb1fcbc4c7cc4eb4ce3326806eb498a8 100644 (file)
@@ -67,6 +67,8 @@ public:
         */
        QRectF label_rect(const QRectF &rect) const;
 
+       virtual QMenu* create_header_context_menu(QWidget *parent) override;
+
 private:
        shared_ptr<Cursor> get_other_cursor() const;
 };
index 81af10868f46a070aaf8d8c45a56cce7359d622b..ea3cd609854c813783ffe6e406143b887915693a 100644 (file)
@@ -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;
 }
 
index f2eb5957c45ce2d92f914afb2f7ba636957be916..3de62258ae4fff0e3371f001036d15df81a9f628 100644 (file)
@@ -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
index e0114a5aca8e36a9434c1fe3b92aec8d2f487d37..06d850505ce8ebde350ecfbcbaeecbd5b3a79c3a 100644 (file)
@@ -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_;
 };