]> sigrok.org Git - pulseview.git/commitdiff
Trace view: Allow setting cursors via shift-drag
authorjaseg <redacted>
Sat, 8 Jun 2019 02:19:48 +0000 (11:19 +0900)
committerSoeren Apel <redacted>
Thu, 4 Jul 2019 21:17:27 +0000 (23:17 +0200)
pv/views/trace/view.cpp
pv/views/trace/view.hpp
pv/views/trace/viewwidget.cpp
pv/views/trace/viewwidget.hpp

index 05e6da3e67000a75720595aba455697ac7d265d7..2a4c4372194749d5c9ce9a6d0bf377d507f1cfd6 100644 (file)
@@ -790,22 +790,37 @@ bool View::cursors_shown() const
 
 void View::show_cursors(bool show)
 {
-       show_cursors_ = show;
-       cursor_state_changed(show);
-       ruler_->update();
-       viewport_->update();
+    if (show_cursors_ != show) {
+        show_cursors_ = show;
+        cursor_state_changed(show);
+        ruler_->update();
+        viewport_->update();
+
+    } else {
+        show_cursors_ = show;
+    }
+}
+
+void View::set_cursors(pv::util::Timestamp& first, pv::util::Timestamp& second) {
+    assert(cursors);
+
+    cursors_->first()->set_time(first);
+    cursors_->second()->set_time(second);
+
+    ruler_->update();
+    viewport_->update();
 }
 
 void View::centre_cursors()
 {
-       if (cursors_) {
-               const double time_width = scale_ * viewport_->width();
-               cursors_->first()->set_time(offset_ + time_width * 0.4);
-               cursors_->second()->set_time(offset_ + time_width * 0.6);
+    assert(cursors);
 
-               ruler_->update();
-               viewport_->update();
-       }
+    const double time_width = scale_ * viewport_->width();
+    cursors_->first()->set_time(offset_ + time_width * 0.4);
+    cursors_->second()->set_time(offset_ + time_width * 0.6);
+
+    ruler_->update();
+    viewport_->update();
 }
 
 shared_ptr<CursorPair> View::cursors() const
index e66f7d0e8bd8a35f6d6bcb5aa4b0a830d83ea9ee..8fdbc15d6a9d5e276ea87c4200c926bcc2143dbb 100644 (file)
@@ -278,6 +278,11 @@ public:
         */
        void show_cursors(bool show = true);
 
+    /**
+     * Sets the cursors to the given offsets. You will still have to call show_cursors separately.
+     */
+    void set_cursors(pv::util::Timestamp& first, pv::util::Timestamp& second);
+
        /**
         * Moves the cursors to a convenient position in the view.
         */
index 46946a5cd5d36b5cff8d09d2f29471a8454867c2..e20be24febd3cab49ddc0c20bfdf67eb75014de5 100644 (file)
@@ -253,7 +253,10 @@ void ViewWidget::mousePressEvent(QMouseEvent *event)
        assert(event);
 
        if (event->button() & Qt::LeftButton) {
+        if (event->modifiers() & Qt::ShiftModifier)
+            view_.show_cursors(false);
                mouse_down_point_ = event->pos();
+               mouse_down_offset_ =  view_.offset() + event->pos().x() * view_.scale();
                mouse_down_item_ = get_mouse_over_item(event->pos());
                mouse_left_press_event(event);
        }
@@ -285,22 +288,38 @@ void ViewWidget::mouseMoveEvent(QMouseEvent *event)
        assert(event);
        mouse_point_ = event->pos();
 
-       if (!event->buttons())
+       if (!event->buttons()) {
                item_hover(get_mouse_over_item(event->pos()), event->pos());
-       else if (event->buttons() & Qt::LeftButton) {
-               if (!item_dragging_) {
-                       if ((event->pos() - mouse_down_point_).manhattanLength() <
-                               QApplication::startDragDistance())
-                               return;
 
-                       if (!accept_drag())
-                               return;
+    } else if (event->buttons() & Qt::LeftButton) {
 
-                       item_dragging_ = true;
-               }
+        if (event->modifiers() & Qt::ShiftModifier) { // Cursor drag 
+            pv::util::Timestamp current_offset =  view_.offset() + event->pos().x() * view_.scale();
+
+            // TODO: Is startDragDistance the right constant here?
+            if (qAbs(current_offset - mouse_down_offset_)/view_.scale() > QApplication::startDragDistance()) {
+                view_.show_cursors(true);
+                view_.set_cursors(mouse_down_offset_, current_offset);
+
+            } else {
+                view_.show_cursors(false);
+            }
+
+        } else {
+            if (!item_dragging_) {
+                if ((event->pos() - mouse_down_point_).manhattanLength() <
+                    QApplication::startDragDistance())
+                    return;
+
+                if (!accept_drag())
+                    return;
+
+                item_dragging_ = true;
+            }
 
-               // Do the drag
-               drag_items(event->pos() - mouse_down_point_);
+            // Do the drag
+            drag_items(event->pos() - mouse_down_point_);
+        }
        }
 }
 
index f4928e67f885bcd948c10ae0b72a7da03bff5d5b..0e012560859e7aa939fe746d1ebe55660d751add 100644 (file)
@@ -25,6 +25,8 @@
 #include <QPoint>
 #include <QWidget>
 
+#include <pv/util.hpp>
+
 using std::shared_ptr;
 using std::vector;
 
@@ -143,6 +145,7 @@ protected:
        pv::views::trace::View &view_;
        QPoint mouse_point_;
        QPoint mouse_down_point_;
+       pv::util::Timestamp mouse_down_offset_;
        shared_ptr<ViewItem> mouse_down_item_;
        bool item_dragging_;
 };