]> sigrok.org Git - pulseview.git/commitdiff
Header: Fixed dragging glitches
authorJoel Holdsworth <redacted>
Sun, 2 Nov 2014 17:04:25 +0000 (17:04 +0000)
committerJoel Holdsworth <redacted>
Wed, 19 Nov 2014 10:23:02 +0000 (10:23 +0000)
pv/view/header.cpp
pv/view/header.h

index 202ae101f76f6ada1fd9d44573cd89b06bafab2b..9ba4cf8f8814088749cf20b1909dee6cfec50e7e 100644 (file)
@@ -136,70 +136,78 @@ void Header::paintEvent(QPaintEvent*)
        painter.end();
 }
 
+void Header::mouseLeftPressEvent(QMouseEvent *event)
+{
+       const bool ctrl_pressed =
+               QApplication::keyboardModifiers() & Qt::ControlModifier;
+
+       // Clear selection if control is not pressed and this item is unselected
+       const shared_ptr<RowItem> mouse_over =
+               get_mouse_over_row_item(event->pos());
+       if (!ctrl_pressed && (!mouse_over || !mouse_over->selected()))
+               for (shared_ptr<RowItem> r : _view)
+                       r->select(false);
+
+       // Set the signal selection state if the item has been clicked
+       if (mouse_over) {
+               if (ctrl_pressed)
+                       mouse_over->select(!mouse_over->selected());
+               else
+                       mouse_over->select(true);
+       }
+
+       // Save the offsets of any signals which will be dragged
+       _mouse_down_point = event->pos();
+       for (const shared_ptr<RowItem> r : _view)
+               if (r->selected())
+                       _drag_row_items.push_back(
+                               make_pair(r, r->v_offset()));
+
+       selection_changed();
+       update();
+}
+
 void Header::mousePressEvent(QMouseEvent *event)
 {
        assert(event);
+       if (event->button() & Qt::LeftButton)
+               mouseLeftPressEvent(event);
+}
 
-       if (event->button() & Qt::LeftButton) {
-               _mouse_down_point = event->pos();
+void Header::mouseLeftReleaseEvent(QMouseEvent *event)
+{
+       assert(event);
 
-               // Save the offsets of any signals which will be dragged
-               for (const shared_ptr<RowItem> r : _view)
-                       if (r->selected())
-                               _drag_row_items.push_back(
-                                       make_pair(r, r->v_offset()));
-       }
+       const bool ctrl_pressed =
+               QApplication::keyboardModifiers() & Qt::ControlModifier;
 
-       // Select the signal if it has been clicked
-       const shared_ptr<RowItem> mouse_over_row_item =
+       // Unselect everything if control is not pressed
+       const shared_ptr<RowItem> mouse_over =
                get_mouse_over_row_item(event->pos());
-       if (mouse_over_row_item) {
-               if (mouse_over_row_item->selected())
-                       mouse_over_row_item->select(false);
-               else {
-                       mouse_over_row_item->select(true);
-
-                       if (~QApplication::keyboardModifiers() &
-                               Qt::ControlModifier)
-                               _drag_row_items.clear();
-
-                       // Add the signal to the drag list
-                       if (event->button() & Qt::LeftButton)
-                               _drag_row_items.push_back(
-                                       make_pair(mouse_over_row_item,
-                                       mouse_over_row_item->v_offset()));
-               }
-       }
 
-       if (~QApplication::keyboardModifiers() & Qt::ControlModifier) {
-               // Unselect all other signals because the Ctrl is not
-               // pressed
-               for (const shared_ptr<RowItem> r : _view)
-                       if (r != mouse_over_row_item)
-                               r->select(false);
+       if (_dragging)
+               _view.normalize_layout();
+       else
+       {
+               if (!ctrl_pressed) {
+                       for (shared_ptr<RowItem> r : _view)
+                               if (mouse_over != r)
+                                       r->select(false);
+
+                       if (mouse_over)
+                               show_popup(mouse_over);
+               }
        }
 
-       selection_changed();
-       update();
+       _dragging = false;
+       _drag_row_items.clear();
 }
 
 void Header::mouseReleaseEvent(QMouseEvent *event)
 {
        assert(event);
-       if (event->button() == Qt::LeftButton) {
-               if (_dragging)
-                       _view.normalize_layout();
-               else
-               {
-                       const shared_ptr<RowItem> mouse_over_row_item =
-                               get_mouse_over_row_item(event->pos());
-                       if (mouse_over_row_item)
-                               show_popup(mouse_over_row_item);
-               }
-
-               _dragging = false;
-               _drag_row_items.clear();
-       }
+       if (event->button() & Qt::LeftButton)
+               mouseLeftReleaseEvent(event);
 }
 
 void Header::mouseMoveEvent(QMouseEvent *event)
index 76899b3ab424dcc7002dae4984eb30901b6cf5e3..f190d50c919e518d81abdab31219ec2d8ec3d0f2 100644 (file)
@@ -65,8 +65,10 @@ private:
        void paintEvent(QPaintEvent *event);
 
 private:
+       void mouseLeftPressEvent(QMouseEvent *event);
        void mousePressEvent(QMouseEvent * event);
 
+       void mouseLeftReleaseEvent(QMouseEvent *event);
        void mouseReleaseEvent(QMouseEvent *event);
 
        void mouseMoveEvent(QMouseEvent *event);