From: Soeren Apel Date: Sat, 30 Jul 2022 20:58:23 +0000 (+0200) Subject: Trace View: Allow context menu to show basic options in empty area X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=153225bc3339c2ee9a861a32cba2a15f2ddddd1f;p=pulseview.git Trace View: Allow context menu to show basic options in empty area --- diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index a7b483a7..d4d0c5a8 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -1594,10 +1594,22 @@ void View::contextMenuEvent(QContextMenuEvent *event) QPoint pos = event->pos() - QPoint(0, ruler_->sizeHint().height()); const shared_ptr 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; diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index f8506cf4..7fef8419 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -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