Fixes
authorSoeren Apel <soeren@apelpie.net>
Thu, 20 Jun 2019 18:03:02 +0000 (20:03 +0200)
committerSoeren Apel <soeren@apelpie.net>
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

index 2a4c4372194749d5c9ce9a6d0bf377d507f1cfd6..7f77635d235791192bb05ed5db79f680dfc5ae6d 100644 (file)
@@ -790,37 +790,36 @@ bool View::cursors_shown() const
 
 void View::show_cursors(bool show)
 {
-    if (show_cursors_ != show) {
-        show_cursors_ = show;
-        cursor_state_changed(show);
-        ruler_->update();
-        viewport_->update();
+       if (show_cursors_ != show) {
+               show_cursors_ = show;
 
-    } else {
-        show_cursors_ = show;
-    }
+               cursor_state_changed(show);
+               ruler_->update();
+               viewport_->update();
+       }
 }
 
-void View::set_cursors(pv::util::Timestamp& first, pv::util::Timestamp& second) {
-    assert(cursors);
+void View::set_cursors(pv::util::Timestamp& first, pv::util::Timestamp& second)
+{
+       assert(cursors_);
 
-    cursors_->first()->set_time(first);
-    cursors_->second()->set_time(second);
+       cursors_->first()->set_time(first);
+       cursors_->second()->set_time(second);
 
-    ruler_->update();
-    viewport_->update();
+       ruler_->update();
+       viewport_->update();
 }
 
 void View::centre_cursors()
 {
-    assert(cursors);
+       assert(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);
+       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();
+       ruler_->update();
+       viewport_->update();
 }
 
 shared_ptr<CursorPair> View::cursors() const
index 8fdbc15d6a9d5e276ea87c4200c926bcc2143dbb..c6a7c55743caf64e9496e4c4fc0d054940cc4ab8 100644 (file)
@@ -278,10 +278,10 @@ 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);
+       /**
+        * 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 e20be24febd3cab49ddc0c20bfdf67eb75014de5..499471b91001bf3488d4b893cac0591548b7ad07 100644 (file)
@@ -253,10 +253,11 @@ void ViewWidget::mousePressEvent(QMouseEvent *event)
        assert(event);
 
        if (event->button() & Qt::LeftButton) {
-        if (event->modifiers() & Qt::ShiftModifier)
-            view_.show_cursors(false);
+               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_offset_ = view_.offset() + event->pos().x() * view_.scale();
                mouse_down_item_ = get_mouse_over_item(event->pos());
                mouse_left_press_event(event);
        }
@@ -288,38 +289,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 (event->modifiers() & Qt::ShiftModifier) { // Cursor drag 
-            pv::util::Timestamp current_offset =  view_.offset() + event->pos().x() * view_.scale();
+       if (event->buttons() & Qt::LeftButton) {
+               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);
+                       const int drag_distance = qAbs(current_offset.convert_to<double>() -
+                               mouse_down_offset_.convert_to<double>()) / view_.scale();
 
-            } else {
-                view_.show_cursors(false);
-            }
+                       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;
+               } else {
+                       if (!item_dragging_) {
+                               if ((event->pos() - mouse_down_point_).manhattanLength() <
+                                       QApplication::startDragDistance())
+                                       return;
 
-                if (!accept_drag())
-                    return;
+                               if (!accept_drag())
+                                       return;
 
-                item_dragging_ = true;
-            }
+                               item_dragging_ = true;
+                       }
 
-            // Do the drag
-            drag_items(event->pos() - mouse_down_point_);
-        }
+                       // Do the drag
+                       drag_items(event->pos() - mouse_down_point_);
+               }
        }
 }