From: Soeren Apel Date: Fri, 10 Aug 2018 15:51:48 +0000 (+0200) Subject: Fix regression introduced by 2980ff2da269c9ed X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cbd9ec7f751a5403d1465e966ccecd31b7086e8a;p=pulseview.git Fix regression introduced by 2980ff2da269c9ed The regression was that when clicking+dragging on a trace in the trace view area, the individual trace was moving, not the view area itself. This was unintended. --- diff --git a/pv/views/trace/trace.cpp b/pv/views/trace/trace.cpp index 8c450a08..fe5cc281 100644 --- a/pv/views/trace/trace.cpp +++ b/pv/views/trace/trace.cpp @@ -78,6 +78,22 @@ shared_ptr Trace::base() const return base_; } +bool Trace::is_selectable(QPoint pos) const +{ + // True if the header was clicked, false if the trace area was clicked + const View *view = owner_->view(); + assert(view); + + return (pos.x() <= view->header_width()); +} + +bool Trace::is_draggable() const +{ + // While the header label that belongs to this trace is draggable, + // the trace itself shall not be + return false; +} + void Trace::set_segment_display_mode(SegmentDisplayMode mode) { segment_display_mode_ = mode; @@ -189,10 +205,16 @@ QRectF Trace::label_rect(const QRectF &rect) const QRectF Trace::hit_box_rect(const ViewItemPaintParams &pp) const { + // This one is only for the trace itself, excluding the header area + const View *view = owner_->view(); + assert(view); + pair extents = v_extents(); const int top = pp.top() + get_visual_y() + extents.first; const int height = extents.second - extents.first; - return QRectF(pp.left(), top, pp.width(), height); + + return QRectF(pp.left() + view->header_width(), top, + pp.width() - view->header_width(), height); } void Trace::set_current_segment(const int segment) diff --git a/pv/views/trace/trace.hpp b/pv/views/trace/trace.hpp index 0c493d72..4124ece2 100644 --- a/pv/views/trace/trace.hpp +++ b/pv/views/trace/trace.hpp @@ -102,6 +102,16 @@ public: */ shared_ptr base() const; + /** + * Returns true if the item may be selected. + */ + virtual bool is_selectable(QPoint pos) const; + + /** + * Returns true if the item may be dragged/moved. + */ + virtual bool is_draggable() const; + /** * Configures the segment display mode to use. */ diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 1e4f07aa..65b06aea 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -875,6 +875,11 @@ void View::restack_all_trace_tree_items() i->animate_to_layout_v_offset(); } +int View::header_width() const +{ + return header_->extended_size_hint().width(); +} + void View::on_setting_changed(const QString &key, const QVariant &value) { if (key == GlobalSettings::Key_View_TriggerIsZeroTime) @@ -1087,12 +1092,11 @@ void View::set_scroll_default() void View::determine_if_header_was_shrunk() { const int header_pane_width = splitter_->sizes().front(); - const int header_width = header_->extended_size_hint().width(); // Allow for a slight margin of error so that we also accept // slight differences when e.g. a label name change increased // the overall width - header_was_shrunk_ = (header_pane_width < (header_width - 10)); + header_was_shrunk_ = (header_pane_width < (header_width() - 10)); } void View::resize_header_to_fit() diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index 1cff6ab7..8e78b626 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -64,12 +64,10 @@ namespace views { namespace trace { -class CursorHeader; class DecodeTrace; class Header; class Ruler; class Signal; -class Trace; class Viewport; class TriggerMarker; @@ -305,6 +303,8 @@ public: void restack_all_trace_tree_items(); + int header_width() const; + void on_setting_changed(const QString &key, const QVariant &value); Q_SIGNALS: diff --git a/pv/views/trace/viewitem.cpp b/pv/views/trace/viewitem.cpp index 43c9ca26..3627d8ca 100644 --- a/pv/views/trace/viewitem.cpp +++ b/pv/views/trace/viewitem.cpp @@ -39,6 +39,12 @@ ViewItem::ViewItem() : { } +bool ViewItem::is_selectable(QPoint pos) const +{ + (void)pos; + return true; +} + bool ViewItem::selected() const { return selected_; diff --git a/pv/views/trace/viewitem.hpp b/pv/views/trace/viewitem.hpp index 89a57e5e..8421d861 100644 --- a/pv/views/trace/viewitem.hpp +++ b/pv/views/trace/viewitem.hpp @@ -59,6 +59,11 @@ public: */ virtual bool enabled() const = 0; + /** + * Returns true if the item may be selected. + */ + virtual bool is_selectable(QPoint pos) const; + /** * Returns true if the item has been selected by the user. */ diff --git a/pv/views/trace/viewwidget.cpp b/pv/views/trace/viewwidget.cpp index 5a1aa3c3..a14c4fd2 100644 --- a/pv/views/trace/viewwidget.cpp +++ b/pv/views/trace/viewwidget.cpp @@ -169,7 +169,7 @@ void ViewWidget::mouse_left_press_event(QMouseEvent *event) clear_selection(); // Set the signal selection state if the item has been clicked - if (mouse_down_item_) { + if (mouse_down_item_ && mouse_down_item_->is_selectable(event->pos())) { if (ctrl_pressed) mouse_down_item_->select(!mouse_down_item_->selected()); else