]> sigrok.org Git - pulseview.git/commitdiff
TraceView: Add shortcuts for attaching the cursor edges to the mouse
authorMiklos Marton <redacted>
Sun, 19 Jan 2020 15:40:47 +0000 (16:40 +0100)
committerUwe Hermann <redacted>
Wed, 22 Jan 2020 21:57:39 +0000 (22:57 +0100)
See https://github.com/sigrokproject/pulseview/pull/19

pv/views/trace/view.cpp
pv/views/trace/view.hpp

index 7a68c6e93408c113ae58c6d7876a49b2883b8a50..c8a7a2b88d08ce8aff081dee9c98c39238f27e53 100644 (file)
@@ -228,6 +228,21 @@ View::View(Session &session, bool is_main_view, QMainWindow *parent) :
                SLOT(on_scroll_to_end_shortcut_triggered()), nullptr, Qt::WidgetWithChildrenShortcut);
        end_shortcut_->setAutoRepeat(false);
 
+       grab_ruler_left_shortcut_ = new QShortcut(QKeySequence(Qt::Key_1), this);
+       connect(grab_ruler_left_shortcut_, &QShortcut::activated,
+               this, [=]{on_grab_ruler(1);});
+       grab_ruler_left_shortcut_->setAutoRepeat(false);
+
+       grab_ruler_right_shortcut_ = new QShortcut(QKeySequence(Qt::Key_2), this);
+       connect(grab_ruler_right_shortcut_, &QShortcut::activated,
+               this, [=]{on_grab_ruler(2);});
+       grab_ruler_right_shortcut_->setAutoRepeat(false);
+
+       cancel_grab_shortcut_ = new QShortcut(QKeySequence(Qt::Key_Escape), this);
+       connect(cancel_grab_shortcut_, &QShortcut::activated,
+               this, [=]{grabbed_widget_ = nullptr;});
+       cancel_grab_shortcut_->setAutoRepeat(false);
+
        // Trigger the initial event manually. The default device has signals
        // which were created before this object came into being
        signals_changed();
@@ -270,6 +285,7 @@ void View::reset_view_state()
        next_flag_text_ = 'A';
        trigger_markers_.clear();
        hover_widget_ = nullptr;
+       grabbed_widget_ = nullptr;
        hover_point_ = QPoint(-1, -1);
        scroll_needs_defaults_ = true;
        saved_v_offset_ = 0;
@@ -1405,7 +1421,20 @@ bool View::eventFilter(QObject *object, QEvent *event)
 
                update_hover_point();
 
+               if (grabbed_widget_) {
+                       int64_t nearest = get_nearest_level_change(hover_point_);
+                       pv::util::Timestamp mouse_time = offset_ + hover_point_.x() * scale_;
+
+                       if (nearest == -1) {
+                               grabbed_widget_->set_time(mouse_time);
+                       } else {
+                               grabbed_widget_->set_time(nearest / get_signal_under_mouse_cursor()->base()->get_samplerate());
+                       }
+               }
+
        } else if (type == QEvent::MouseButtonPress) {
+               grabbed_widget_ = nullptr;
+
                const QMouseEvent *const mouse_event = (QMouseEvent*)event;
                if ((object == viewport_) && (mouse_event->button() & Qt::LeftButton)) {
                        // Send event to all trace tree items
@@ -1592,6 +1621,22 @@ void View::v_scroll_value_changed()
        viewport_->update();
 }
 
+void View::on_grab_ruler(int ruler_id)
+{
+       if (cursors_shown()) {
+               // Release the grabbed widget if its trigger hotkey was pressed twice
+               if (ruler_id == 1)
+                       grabbed_widget_ = (grabbed_widget_ == cursors_->first().get()) ?
+                               nullptr : cursors_->first().get();
+               else
+                       grabbed_widget_ = (grabbed_widget_ == cursors_->second().get()) ?
+                               nullptr : cursors_->second().get();
+
+               if (grabbed_widget_)
+                       grabbed_widget_->set_time(offset_ + mapFromGlobal(QCursor::pos()).x() * scale_);
+       }
+}
+
 void View::signals_changed()
 {
        using sigrok::Channel;
index d79db4d487a6228ba2e24fb8ba502914154f932f..040bac1b828590514fe22937041f050a3b426aef 100644 (file)
@@ -439,6 +439,8 @@ private Q_SLOTS:
        void h_scroll_value_changed(int value);
        void v_scroll_value_changed();
 
+       void on_grab_ruler(int ruler_id);
+
        void signals_changed();
        void capture_state_updated(int state);
 
@@ -503,6 +505,8 @@ private:
        QShortcut *zoom_in_shortcut_, *zoom_in_shortcut_2_;
        QShortcut *zoom_out_shortcut_, *zoom_out_shortcut_2_;
        QShortcut *home_shortcut_, *end_shortcut_;
+       QShortcut *grab_ruler_left_shortcut_, *grab_ruler_right_shortcut_;
+       QShortcut *cancel_grab_shortcut_;
 
        unordered_set< shared_ptr<Signal> > signals_;
 
@@ -548,6 +552,7 @@ private:
        vector< shared_ptr<TriggerMarker> > trigger_markers_;
 
        QWidget* hover_widget_;
+       TimeMarker* grabbed_widget_;
        QPoint hover_point_;
        shared_ptr<Signal> signal_under_mouse_cursor_;
        uint16_t snap_distance_;