diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-09-06 13:51:02 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-09-22 20:46:30 +0200 |
commit | f6155aec30c343edbad5ba12b189ca2d9c4904b5 (patch) | |
tree | 38d65fd1ce30e02d8012037ecb867064296a93fa /src/widgets | |
parent | e0b1eac3ff1abbf4f8d27d6b0bdfe0ebc1d12b7c (diff) |
Redirect keyboard/mouse grab to the widget parent window.
Use the native parent's window if the widget in question does not
have one. This should be in line with Qt 4.8 using effectiveWinId().
Remove redundant code in grabMouse(QCursor).
Change-Id: Id6ab192e739221fe89f865f4d2f7a6d4671a190b
Reviewed-by: Qt Doc Bot <qt_docbot@qt-project.org>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/kernel/qwidget_qpa.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp index 7b649f6993..7c84c7fc29 100644 --- a/src/widgets/kernel/qwidget_qpa.cpp +++ b/src/widgets/kernel/qwidget_qpa.cpp @@ -362,13 +362,22 @@ QWidget *qt_pressGrab = 0; QWidget *qt_mouseGrb = 0; static QWidget *keyboardGrb = 0; +static inline QWindow *grabberWindow(const QWidget *w) +{ + QWindow *window = w->windowHandle(); + if (!window) + if (const QWidget *nativeParent = w->nativeParentWidget()) + window = nativeParent->windowHandle(); + return window; +} + void QWidget::grabMouse() { if (qt_mouseGrb) qt_mouseGrb->releaseMouse(); - if (windowHandle()) - windowHandle()->setMouseGrabEnabled(true); + if (QWindow *window = grabberWindow(this)) + window->setMouseGrabEnabled(true); qt_mouseGrb = this; qt_pressGrab = 0; @@ -378,15 +387,7 @@ void QWidget::grabMouse() void QWidget::grabMouse(const QCursor &cursor) { Q_UNUSED(cursor); - - if (qt_mouseGrb) - qt_mouseGrb->releaseMouse(); - - if (windowHandle()) - windowHandle()->setMouseGrabEnabled(true); - - qt_mouseGrb = this; - qt_pressGrab = 0; + grabMouse(); } #endif @@ -395,14 +396,15 @@ bool QWidgetPrivate::stealMouseGrab(bool grab) // This is like a combination of grab/releaseMouse() but with error checking // and it has no effect on the result of mouseGrabber(). Q_Q(QWidget); - return q->windowHandle() ? q->windowHandle()->setMouseGrabEnabled(grab) : false; + QWindow *window = grabberWindow(q); + return window ? window->setMouseGrabEnabled(grab) : false; } void QWidget::releaseMouse() { if (qt_mouseGrb == this) { - if (windowHandle()) - windowHandle()->setMouseGrabEnabled(false); + if (QWindow *window = grabberWindow(this)) + window->setMouseGrabEnabled(false); qt_mouseGrb = 0; } } @@ -411,8 +413,8 @@ void QWidget::grabKeyboard() { if (keyboardGrb) keyboardGrb->releaseKeyboard(); - if (windowHandle()) - windowHandle()->setKeyboardGrabEnabled(true); + if (QWindow *window = grabberWindow(this)) + window->setKeyboardGrabEnabled(true); keyboardGrb = this; } @@ -421,14 +423,15 @@ bool QWidgetPrivate::stealKeyboardGrab(bool grab) // This is like a combination of grab/releaseKeyboard() but with error // checking and it has no effect on the result of keyboardGrabber(). Q_Q(QWidget); - return q->windowHandle() ? q->windowHandle()->setKeyboardGrabEnabled(grab) : false; + QWindow *window = grabberWindow(q); + return window ? window->setKeyboardGrabEnabled(grab) : false; } void QWidget::releaseKeyboard() { if (keyboardGrb == this) { - if (windowHandle()) - windowHandle()->setKeyboardGrabEnabled(false); + if (QWindow *window = grabberWindow(this)) + window->setKeyboardGrabEnabled(false); keyboardGrb = 0; } } |