]> sigrok.org Git - pulseview.git/commitdiff
Fix regression introduced by 2980ff2da269c9ed
authorSoeren Apel <redacted>
Fri, 10 Aug 2018 15:51:48 +0000 (17:51 +0200)
committerUwe Hermann <redacted>
Tue, 21 Aug 2018 10:02:38 +0000 (12:02 +0200)
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.

pv/views/trace/trace.cpp
pv/views/trace/trace.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp
pv/views/trace/viewitem.cpp
pv/views/trace/viewitem.hpp
pv/views/trace/viewwidget.cpp

index 8c450a088604e543a2b1f41e421011e0e3d719db..fe5cc281d46984c27aa331910f84e926b11f2dee 100644 (file)
@@ -78,6 +78,22 @@ shared_ptr<data::SignalBase> 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<int, int> 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)
index 0c493d7206b56577c8915c8d5cf90962895376ef..4124ece2e3705415fff359214d3184746293c124 100644 (file)
@@ -102,6 +102,16 @@ public:
         */
        shared_ptr<data::SignalBase> 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.
         */
index 1e4f07aa3ddab2fa3f0861881c5b50709e1e75f7..65b06aea82cba76279f185f40b4af933578a18dd 100644 (file)
@@ -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()
index 1cff6ab7bbf245f52a7508c20b52b446e26d15bc..8e78b6260e2143dcbb141ad2a5aa0f1b4836c822 100644 (file)
@@ -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:
index 43c9ca2673de149ed6fcbdf50a4e7cec9ee723e1..3627d8ca6f1bcefb160b84d609f0b0fae6c9564d 100644 (file)
@@ -39,6 +39,12 @@ ViewItem::ViewItem() :
 {
 }
 
+bool ViewItem::is_selectable(QPoint pos) const
+{
+       (void)pos;
+       return true;
+}
+
 bool ViewItem::selected() const
 {
        return selected_;
index 89a57e5edeb248b2dab9b59618cab71b9d268667..8421d8614914078fc61b7c3a26a3a647f57f99c4 100644 (file)
@@ -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.
         */
index 5a1aa3c3ea447e27356c8ace74273b2f1da63333..a14c4fd224395eb95bc8c46d97766051a7ec0e51 100644 (file)
@@ -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