Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions qtfred/src/ui/widgets/renderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ void RenderWidget::keyPressEvent(QKeyEvent* key) {
if (_viewport != nullptr && key->key() == Qt::Key_Escape && _viewport->button_down) {
_viewport->cancel_drag();
_usingMarkingBox = false;
_window->setMouseGrabEnabled(false);
key->accept();
return;
}
Expand Down Expand Up @@ -206,6 +207,7 @@ void RenderWidget::mousePressEvent(QMouseEvent* event) {
if (_viewport != nullptr && _viewport->button_down) {
_viewport->cancel_drag();
_usingMarkingBox = false;
_window->setMouseGrabEnabled(false);
event->accept();
return;
}
Expand Down Expand Up @@ -242,6 +244,11 @@ void RenderWidget::mousePressEvent(QMouseEvent* event) {
event->position().y() * _window->devicePixelRatio());
_viewport->button_down = 1;

// Grab the mouse for the duration of the drag. The render surface is an embedded QWindow that
// only receives (and forwards) mouse events while the cursor is over it, so a fast drag out of
// the viewport would otherwise drop the move/release events and strand the selection box.
_window->setMouseGrabEnabled(true);

if (event->modifiers().testFlag(Qt::ControlModifier)) { // add a new object
if (_viewport->on_object == -1) {
_viewport->Selection_lock = false; // force off selection lock
Expand Down Expand Up @@ -369,6 +376,10 @@ void RenderWidget::mouseMoveEvent(QMouseEvent* event) {
updateCursor();

if (!event->buttons().testFlag(Qt::LeftButton)) {
if (_viewport->button_down) {
// Button came up without a release event reaching us; drop the grab so it never dangles.
_window->setMouseGrabEnabled(false);
}
_viewport->button_down = false;
}

Expand Down Expand Up @@ -424,6 +435,9 @@ void RenderWidget::mouseReleaseEvent(QMouseEvent* event) {
_markingBox.x2 = event->position().x() * _window->devicePixelRatio();
_markingBox.y2 = event->position().y() * _window->devicePixelRatio();

// Drag finished: drop the grab taken in mousePressEvent (before any modal dialog below runs).
_window->setMouseGrabEnabled(false);

if (_viewport->button_down) {
if (abs(_markingBox.x1 - _markingBox.x2) > 1 || abs(_markingBox.y1 - _markingBox.y2) > 1) {
_viewport->moved = true;
Expand Down
Loading