From: Joel Holdsworth Date: Sun, 2 Nov 2014 17:04:25 +0000 (+0000) Subject: Header: Fixed dragging glitches X-Git-Tag: pulseview-0.3.0~460 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e57ee799a5512ce13460b733e7ca08de8f1277cf;p=pulseview.git Header: Fixed dragging glitches --- diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 202ae101..9ba4cf8f 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -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 mouse_over = + get_mouse_over_row_item(event->pos()); + if (!ctrl_pressed && (!mouse_over || !mouse_over->selected())) + for (shared_ptr 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 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 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 mouse_over_row_item = + // Unselect everything if control is not pressed + const shared_ptr 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 r : _view) - if (r != mouse_over_row_item) - r->select(false); + if (_dragging) + _view.normalize_layout(); + else + { + if (!ctrl_pressed) { + for (shared_ptr 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 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) diff --git a/pv/view/header.h b/pv/view/header.h index 76899b3a..f190d50c 100644 --- a/pv/view/header.h +++ b/pv/view/header.h @@ -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);