Fixes
[pulseview.git] / pv / views / trace / viewwidget.cpp
index d5b949c0dabcf89e196dadeeb35bf37a230c2cf2..499471b91001bf3488d4b893cac0591548b7ad07 100644 (file)
@@ -105,9 +105,9 @@ void ViewWidget::drag_items(const QPoint &delta)
        bool item_dragged = false;
 
        // Drag the row items
-       const vector< shared_ptr<RowItem> > row_items(
-               view_.list_by_type<RowItem>());
-       for (const shared_ptr<RowItem>& r : row_items)
+       const vector< shared_ptr<ViewItem> > row_items(
+               view_.list_by_type<ViewItem>());
+       for (const shared_ptr<ViewItem>& r : row_items)
                if (r->dragging()) {
                        r->drag_by(delta);
 
@@ -252,17 +252,25 @@ void ViewWidget::mousePressEvent(QMouseEvent *event)
 {
        assert(event);
 
-       /* Ignore right click events as they will open context menus when
+       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);
+       }
+
+       /* Don't forward right click events as they will open context menus when
         * used on trace labels. Those menus prevent ViewWidget::mouseReleaseEvent()
         * to be triggered upon button release, making mouse_down_item_
         * hold the last reference to a view item that might have been deleted
         * from the context menu, preventing it from being freed as intended.
+        * TODO Remove this once context menus are handled separately
         */
-       if (event->button() & Qt::LeftButton) {
+       if (event->button() & Qt::RightButton)
                mouse_down_point_ = event->pos();
-               mouse_down_item_ = get_mouse_over_item(event->pos());
-               mouse_left_press_event(event);
-       }
 }
 
 void ViewWidget::mouseReleaseEvent(QMouseEvent *event)
@@ -283,20 +291,36 @@ void ViewWidget::mouseMoveEvent(QMouseEvent *event)
 
        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;
+       if (event->buttons() & Qt::LeftButton) {
+               if (event->modifiers() & Qt::ShiftModifier) {
+                       // Cursor drag
+                       pv::util::Timestamp current_offset = view_.offset() + event->pos().x() * view_.scale();
 
-                       item_dragging_ = true;
-               }
+                       const int drag_distance = qAbs(current_offset.convert_to<double>() -
+                               mouse_down_offset_.convert_to<double>()) / view_.scale();
+
+                       if (drag_distance > 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;
 
-               // Do the drag
-               drag_items(event->pos() - mouse_down_point_);
+                               if (!accept_drag())
+                                       return;
+
+                               item_dragging_ = true;
+                       }
+
+                       // Do the drag
+                       drag_items(event->pos() - mouse_down_point_);
+               }
        }
 }