Commit 8df4c5d0 authored by Artur Grunau's avatar Artur Grunau
Browse files

MDI: fix a problem with dragging docked windows

Docked MDI windows were either drawn at at offset from the cursor or
lost mouse focus entirely when the mouse pointer left their title bars
while they were being dragged. This could happen if the mouse was moved
fast.

Start mouse drag detection in response to mouse press events. This way
mouse move events don't have to be filtered, which prevents the errors
mentioned above.
parent 314c6247
......@@ -65,22 +65,12 @@ namespace campvis {
}
void MdiDockedWindow::mouseMoveEvent(QMouseEvent* event) {
const QPoint& widgetPos = this->widget()->mapFromParent(event->pos());
/*
* Only intercept non-resize (the window's current cursor is the default one) drag (the
* left mouse button is pressed) events; additionally, the mouse pointer has to be on the
* title bar.
* Only intercept mouse move events if the window is being dragged and the left mouse
* button is pressed.
*/
if (event->buttons().testFlag(Qt::LeftButton) && widgetPos.y() < 0 && this->cursor().shape() == Qt::ArrowCursor) {
if (_dragActive && event->buttons().testFlag(Qt::LeftButton)) {
const QPoint& mousePos = event->globalPos();
if (!_dragActive) {
_dragActive = true;
_lastMousePos = mousePos;
return QMdiSubWindow::mouseMoveEvent(event);
}
QPoint newPos = pos() + (mousePos - _lastMousePos);
/*
......@@ -104,6 +94,22 @@ namespace campvis {
QMdiSubWindow::mouseMoveEvent(event);
}
void MdiDockedWindow::mousePressEvent(QMouseEvent* event) {
const QPoint& widgetPos = this->widget()->mapFromParent(event->pos());
/*
* Mouse drag detection starts only in response to non-resize (the window's current cursor
* is the default one) drag (the left mouse button is pressed) events; additionally, the
* mouse pointer has to be on the title bar.
*/
if (event->button() == Qt::LeftButton && widgetPos.y() < 0 && this->cursor().shape() == Qt::ArrowCursor) {
_dragActive = true;
_lastMousePos = event->globalPos();
}
QMdiSubWindow::mousePressEvent(event);
}
void MdiDockedWindow::mouseReleaseEvent(QMouseEvent* event) {
if (event->button() == Qt::LeftButton)
stopWindowDrag();
......
......@@ -90,6 +90,11 @@ namespace campvis {
*/
virtual void mouseMoveEvent(QMouseEvent* event);
/**
* Event handler that receives mouse press events for the window.
*/
virtual void mousePressEvent(QMouseEvent * event);
/**
* Event handler that receives mouse release events for the window.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment