From: Soeren Apel Date: Mon, 20 Aug 2018 19:19:18 +0000 (+0200) Subject: Fix item dragging X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=119c5c232ef47e92ef6a5cc9f8b7c4c31dc2f387;p=pulseview.git Fix item dragging --- diff --git a/pv/views/trace/trace.cpp b/pv/views/trace/trace.cpp index fe5cc281..8511f750 100644 --- a/pv/views/trace/trace.cpp +++ b/pv/views/trace/trace.cpp @@ -87,11 +87,15 @@ bool Trace::is_selectable(QPoint pos) const return (pos.x() <= view->header_width()); } -bool Trace::is_draggable() const +bool Trace::is_draggable(QPoint pos) const { // While the header label that belongs to this trace is draggable, - // the trace itself shall not be - return false; + // the trace itself shall not be. Hence we return true if the header + // was clicked and false if the trace area was clicked + const View *view = owner_->view(); + assert(view); + + return (pos.x() <= view->header_width()); } void Trace::set_segment_display_mode(SegmentDisplayMode mode) diff --git a/pv/views/trace/trace.hpp b/pv/views/trace/trace.hpp index 4124ece2..0b4ecce4 100644 --- a/pv/views/trace/trace.hpp +++ b/pv/views/trace/trace.hpp @@ -110,7 +110,7 @@ public: /** * Returns true if the item may be dragged/moved. */ - virtual bool is_draggable() const; + virtual bool is_draggable(QPoint pos) const; /** * Configures the segment display mode to use. diff --git a/pv/views/trace/triggermarker.cpp b/pv/views/trace/triggermarker.cpp index 7ef5454a..3311f350 100644 --- a/pv/views/trace/triggermarker.cpp +++ b/pv/views/trace/triggermarker.cpp @@ -43,8 +43,9 @@ bool TriggerMarker::enabled() const return true; } -bool TriggerMarker::is_draggable() const +bool TriggerMarker::is_draggable(QPoint pos) const { + (void)pos; return false; } diff --git a/pv/views/trace/triggermarker.hpp b/pv/views/trace/triggermarker.hpp index 9137f28c..a97fefb0 100644 --- a/pv/views/trace/triggermarker.hpp +++ b/pv/views/trace/triggermarker.hpp @@ -22,6 +22,8 @@ #include "timeitem.hpp" +#include + namespace pv { namespace views { namespace trace { @@ -58,7 +60,7 @@ public: /** Returns true if the item may be dragged/moved. */ - bool is_draggable() const override; + bool is_draggable(QPoint pos) const override; /** * Sets the time of the marker. diff --git a/pv/views/trace/viewitem.cpp b/pv/views/trace/viewitem.cpp index 3627d8ca..2dd8ade8 100644 --- a/pv/views/trace/viewitem.cpp +++ b/pv/views/trace/viewitem.cpp @@ -55,8 +55,9 @@ void ViewItem::select(bool select) selected_ = select; } -bool ViewItem::is_draggable() const +bool ViewItem::is_draggable(QPoint pos) const { + (void)pos; return true; } @@ -67,8 +68,7 @@ bool ViewItem::dragging() const void ViewItem::drag() { - if (is_draggable()) - drag_point_ = drag_point(QRect()); + drag_point_ = drag_point(QRect()); } void ViewItem::drag_release() diff --git a/pv/views/trace/viewitem.hpp b/pv/views/trace/viewitem.hpp index 8421d861..53ed2a60 100644 --- a/pv/views/trace/viewitem.hpp +++ b/pv/views/trace/viewitem.hpp @@ -77,7 +77,7 @@ public: /** * Returns true if the item may be dragged/moved. */ - virtual bool is_draggable() const; + virtual bool is_draggable(QPoint pos) const; /** * Returns true if the item is being dragged. diff --git a/pv/views/trace/viewport.cpp b/pv/views/trace/viewport.cpp index e9a9df0c..e5fb6076 100644 --- a/pv/views/trace/viewport.cpp +++ b/pv/views/trace/viewport.cpp @@ -64,9 +64,9 @@ shared_ptr Viewport::get_mouse_over_item(const QPoint &pt) return nullptr; } -void Viewport::item_hover(const shared_ptr &item) +void Viewport::item_hover(const shared_ptr &item, QPoint pos) { - if (item && item->is_draggable()) + if (item && item->is_draggable(pos)) setCursor(dynamic_pointer_cast(item) ? Qt::SizeVerCursor : Qt::SizeHorCursor); else diff --git a/pv/views/trace/viewport.hpp b/pv/views/trace/viewport.hpp index a49084b4..1b77a0d0 100644 --- a/pv/views/trace/viewport.hpp +++ b/pv/views/trace/viewport.hpp @@ -22,6 +22,7 @@ #include +#include #include #include @@ -62,7 +63,7 @@ private: * @param item The item that is being hovered over, or @c nullptr * if no view item is being hovered over. */ - void item_hover(const shared_ptr &item); + void item_hover(const shared_ptr &item, QPoint pos); /** * Sets this item into the dragged state. diff --git a/pv/views/trace/viewwidget.cpp b/pv/views/trace/viewwidget.cpp index a14c4fd2..c3461614 100644 --- a/pv/views/trace/viewwidget.cpp +++ b/pv/views/trace/viewwidget.cpp @@ -50,9 +50,10 @@ void ViewWidget::clear_selection() i->select(false); } -void ViewWidget::item_hover(const shared_ptr &item) +void ViewWidget::item_hover(const shared_ptr &item, QPoint pos) { (void)item; + (void)pos; } void ViewWidget::item_clicked(const shared_ptr &item) @@ -180,7 +181,7 @@ void ViewWidget::mouse_left_press_event(QMouseEvent *event) bool item_dragged = false; const auto items = this->items(); for (auto &i : items) - if (i->selected()) { + if (i->selected() && i->is_draggable(event->pos())) { item_dragged = true; i->drag(); } @@ -281,7 +282,7 @@ void ViewWidget::mouseMoveEvent(QMouseEvent *event) mouse_point_ = event->pos(); if (!event->buttons()) - item_hover(get_mouse_over_item(event->pos())); + 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() < diff --git a/pv/views/trace/viewwidget.hpp b/pv/views/trace/viewwidget.hpp index e4fb73c8..f4928e67 100644 --- a/pv/views/trace/viewwidget.hpp +++ b/pv/views/trace/viewwidget.hpp @@ -22,6 +22,7 @@ #include +#include #include using std::shared_ptr; @@ -49,7 +50,7 @@ protected: * if no view item is being hovered over. * @remarks the default implementation does nothing. */ - virtual void item_hover(const shared_ptr &item); + virtual void item_hover(const shared_ptr &item, QPoint pos); /** * Indicates the event an a view item has been clicked.