assert(event);
if (event->button() & Qt::LeftButton) {
+ if (event->modifiers() & Qt::ShiftModifier)
+ view_.show_cursors(false);
+
mouse_down_point_ = event->pos();
+ mouse_down_offset_ = view_.offset() + event->pos().x() * view_.scale();
mouse_down_item_ = get_mouse_over_item(event->pos());
mouse_left_press_event(event);
}
mouse_down_item_ = nullptr;
}
+void ViewWidget::keyReleaseEvent(QKeyEvent *event)
+{
+ // Update mouse_modifiers_ also if modifiers change, but pointer doesn't move
+ if ((mouse_point_.x() >= 0) && (mouse_point_.y() >= 0)) // mouse is inside
+ mouse_modifiers_ = event->modifiers();
+ update();
+}
+
+void ViewWidget::keyPressEvent(QKeyEvent *event)
+{
+ // Update mouse_modifiers_ also if modifiers change, but pointer doesn't move
+ if ((mouse_point_.x() >= 0) && (mouse_point_.y() >= 0)) // mouse is inside
+ mouse_modifiers_ = event->modifiers();
+ update();
+}
+
void ViewWidget::mouseMoveEvent(QMouseEvent *event)
{
assert(event);
mouse_point_ = event->pos();
+ mouse_modifiers_ = event->modifiers();
if (!event->buttons())
item_hover(get_mouse_over_item(event->pos()), event->pos());
- else if (event->buttons() & Qt::LeftButton) {
- if (!item_dragging_) {
- if ((event->pos() - mouse_down_point_).manhattanLength() <
- QApplication::startDragDistance())
- return;
- if (!accept_drag())
- return;
+ if (event->buttons() & Qt::LeftButton) {
+ if (event->modifiers() & Qt::ShiftModifier) {
+ // Cursor drag
+ pv::util::Timestamp current_offset = view_.offset() + event->pos().x() * view_.scale();
- item_dragging_ = true;
- }
+ const int drag_distance = qAbs(current_offset.convert_to<double>() -
+ mouse_down_offset_.convert_to<double>()) / view_.scale();
+
+ if (drag_distance > QApplication::startDragDistance()) {
+ view_.show_cursors(true);
+ view_.set_cursors(mouse_down_offset_, current_offset);
+ } else
+ view_.show_cursors(false);
- // Do the drag
- drag_items(event->pos() - mouse_down_point_);
+ } else {
+ if (!item_dragging_) {
+ if ((event->pos() - mouse_down_point_).manhattanLength() <
+ QApplication::startDragDistance())
+ return;
+
+ if (!accept_drag())
+ return;
+
+ item_dragging_ = true;
+ }
+
+ // Do the drag
+ drag_items(event->pos() - mouse_down_point_);
+ }
}
+
+ // Force a repaint of the widget to update highlighted parts
+ update();
}
void ViewWidget::leaveEvent(QEvent*)
{
- mouse_point_ = QPoint(-1, -1);
+ bool cursor_above_widget = rect().contains(mapFromGlobal(QCursor::pos()));
+
+ // We receive leaveEvent also when the widget loses focus even when
+ // the mouse cursor hasn't moved at all - e.g. when the popup shows.
+ // However, we don't want to reset mouse_position_ when the mouse is
+ // still above this widget as doing so would break the context menu
+ if (!cursor_above_widget)
+ mouse_point_ = QPoint(INT_MIN, INT_MIN);
+
+ mouse_modifiers_ = Qt::NoModifier;
+ item_hover(nullptr, QPoint());
+
update();
}