]> sigrok.org Git - pulseview.git/commitdiff
Trace View: Allow context menu to show basic options in empty area
authorSoeren Apel <redacted>
Sat, 30 Jul 2022 20:58:23 +0000 (22:58 +0200)
committerSoeren Apel <redacted>
Sat, 30 Jul 2022 20:58:23 +0000 (22:58 +0200)
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index a7b483a7830555515700eb6e56597a40b0e45516..d4d0c5a81bca4c06fef1114147c3ca20d7837c1d 100644 (file)
@@ -1594,10 +1594,22 @@ void View::contextMenuEvent(QContextMenuEvent *event)
        QPoint pos = event->pos() - QPoint(0, ruler_->sizeHint().height());
 
        const shared_ptr<ViewItem> r = viewport_->get_mouse_over_item(pos);
-       if (!r)
-               return;
 
-       QMenu *menu = r->create_view_context_menu(this, pos);
+       QMenu* menu = nullptr;
+
+       if (!r) {
+               context_menu_x_pos_ = pos.x();
+
+               // No view item under cursor, use generic menu
+               menu = new QMenu(this);
+
+               QAction *const create_marker_here = new QAction(tr("Create marker here"), this);
+               connect(create_marker_here, SIGNAL(triggered()), this, SLOT(on_create_marker_here()));
+               menu->addAction(create_marker_here);
+       } else {
+               menu = r->create_view_context_menu(this, pos);
+       }
+
        if (menu)
                menu->popup(event->globalPos());
 }
@@ -2067,6 +2079,13 @@ void View::on_segment_changed(int segment)
        }
 }
 
+void View::on_create_marker_here()
+{
+       const QPoint p = ruler_->mapFrom(this, QPoint(context_menu_x_pos_, 0));
+
+       add_flag(ruler_->get_absolute_time_from_x_pos(p.x()));
+}
+
 void View::on_settingViewTriggerIsZeroTime_changed(const QVariant new_value)
 {
        (void)new_value;
index f8506cf409ac1c73f9555a1bcfa0d72fd7cc1900..7fef8419e625232b7013eb4e4e84a7bbcae60af0 100644 (file)
@@ -452,6 +452,8 @@ private Q_SLOTS:
 
        void on_settingViewTriggerIsZeroTime_changed(const QVariant new_value);
 
+       void on_create_marker_here();
+
        virtual void perform_delayed_view_update();
 
        void process_sticky_events();
@@ -574,6 +576,9 @@ private:
        // These are used to determine whether the view was altered after acq started
        double scale_at_acq_start_;
        pv::util::Timestamp offset_at_acq_start_;
+
+       // X coordinate of mouse cursor where the user clicked to open a context menu
+       uint32_t context_menu_x_pos_;
 };
 
 } // namespace trace