Trace view: Allow setting cursors via shift-drag
[pulseview.git] / pv / views / trace / viewwidget.cpp
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_);
+        }
        }
 }