-void Header::mouseLeftPressEvent(QMouseEvent *event)
-{
- (void)event;
-
- const bool ctrl_pressed =
- QApplication::keyboardModifiers() & Qt::ControlModifier;
-
- // Clear selection if control is not pressed and this item is unselected
- if ((!_mouse_down_item || !_mouse_down_item->selected()) &&
- !ctrl_pressed)
- for (shared_ptr<RowItem> r : _view)
- r->select(false);
-
- // Set the signal selection state if the item has been clicked
- if (_mouse_down_item) {
- if (ctrl_pressed)
- _mouse_down_item->select(!_mouse_down_item->selected());
- else
- _mouse_down_item->select(true);
- }
-
- // Save the offsets of any signals which will be dragged
- for (const shared_ptr<RowItem> r : _view)
- if (r->selected())
- r->drag();
-
- selection_changed();
- update();
-}
-
-void Header::mousePressEvent(QMouseEvent *event)
-{
- assert(event);
-
- _mouse_down_point = event->pos();
- _mouse_down_item = get_mouse_over_row_item(event->pos());
-
- if (event->button() & Qt::LeftButton)
- mouseLeftPressEvent(event);
-}
-
-void Header::mouseLeftReleaseEvent(QMouseEvent *event)
-{
- assert(event);
-
- const bool ctrl_pressed =
- QApplication::keyboardModifiers() & Qt::ControlModifier;
-
- // Unselect everything if control is not pressed
- const shared_ptr<RowItem> mouse_over =
- get_mouse_over_row_item(event->pos());
-
- for (auto &r : _view)
- r->drag_release();
-
- if (_dragging)
- _view.normalize_layout();
- else
- {
- if (!ctrl_pressed) {
- for (shared_ptr<RowItem> r : _view)
- if (_mouse_down_item != r)
- r->select(false);
-
- if (_mouse_down_item)
- show_popup(_mouse_down_item);
- }
- }
-
- _dragging = false;
-}
-
-void Header::mouseReleaseEvent(QMouseEvent *event)
-{
- assert(event);
- if (event->button() & Qt::LeftButton)
- mouseLeftReleaseEvent(event);
-
- _mouse_down_item = nullptr;
-}
-
-void Header::mouseMoveEvent(QMouseEvent *event)
-{
- assert(event);
- _mouse_point = event->pos();
-
- if (!(event->buttons() & Qt::LeftButton))
- return;
-
- if ((event->pos() - _mouse_down_point).manhattanLength() <
- QApplication::startDragDistance())
- return;
-
- // Check all the drag items share a common owner
- RowItemOwner *item_owner = nullptr;
- for (shared_ptr<RowItem> r : _view)
- if (r->dragging()) {
- if (!item_owner)
- item_owner = r->owner();
- else if(item_owner != r->owner())
- return;
- }
-
- if (!item_owner)
- return;
-
- // Do the drag
- _dragging = true;
-
- const int delta = event->pos().y() - _mouse_down_point.y();
-
- for (std::shared_ptr<RowItem> r : _view)
- if (r->dragging()) {
- r->set_v_offset(r->drag_point().y() + delta);
-
- // Ensure the trace is selected
- r->select();
- }
-
- signals_moved();
-
- update();
-}
-
-void Header::leaveEvent(QEvent*)
-{
- _mouse_point = QPoint(-1, -1);
- update();
-}
-