From 135e9d5a8286e5abd35e04213c232d73c2df15b5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 20 Jun 2014 11:05:11 +0200 Subject: Implement QWidget::grabCursor(const QCursor&). Implement using QGuiApplication::setOverrideCursor(). Task-number: QTBUG-39311 Change-Id: I83e289bfd5e911c31f08df9a4fc17fb8a0cf27f2 Reviewed-by: Shawn Rutledge --- src/widgets/dialogs/qcolordialog.cpp | 11 ++----- src/widgets/kernel/qwidget.cpp | 59 +++++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 714dcfa1f4..3f1773c88e 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -1553,12 +1553,10 @@ void QColorDialogPrivate::_q_pickScreenColor() q->installEventFilter(colorPickingEventFilter); // If user pushes Escape, the last color before picking will be restored. beforeScreenColorPicking = cs->currentColor(); - /*For some reason, q->grabMouse(Qt::CrossCursor) doesn't change - * the cursor, and therefore I have to change it manually. - */ - q->grabMouse(); #ifndef QT_NO_CURSOR - q->setCursor(Qt::CrossCursor); + q->grabMouse(Qt::CrossCursor); +#else + q->grabMouse(); #endif q->grabKeyboard(); /* With setMouseTracking(true) the desired color can be more precisedly picked up, @@ -1583,9 +1581,6 @@ void QColorDialogPrivate::releaseColorPicking() q->removeEventFilter(colorPickingEventFilter); q->releaseMouse(); q->releaseKeyboard(); -#ifndef QT_NO_CURSOR - q->setCursor(Qt::ArrowCursor); -#endif q->setMouseTracking(false); lblScreenColorInfo->setText(QLatin1String("\n")); addCusBt->setDisabled(false); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 52d39759dc..6a46731c51 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -12175,6 +12175,7 @@ QPoint QWidget::mapFromGlobal(const QPoint &pos) const QWidget *qt_pressGrab = 0; QWidget *qt_mouseGrb = 0; +static bool mouseGrabWithCursor = false; static QWidget *keyboardGrb = 0; static inline QWindow *grabberWindow(const QWidget *w) @@ -12186,6 +12187,46 @@ static inline QWindow *grabberWindow(const QWidget *w) return window; } +#ifndef QT_NO_CURSOR +static void grabMouseForWidget(QWidget *widget, const QCursor *cursor = 0) +#else +static void grabMouseForWidget(QWidget *widget) +#endif +{ + if (qt_mouseGrb) + qt_mouseGrb->releaseMouse(); + + mouseGrabWithCursor = false; + if (QWindow *window = grabberWindow(widget)) { +#ifndef QT_NO_CURSOR + if (cursor) { + mouseGrabWithCursor = true; + QGuiApplication::setOverrideCursor(*cursor); + } +#endif // !QT_NO_CURSOR + window->setMouseGrabEnabled(true); + } + + qt_mouseGrb = widget; + qt_pressGrab = 0; +} + +static void releaseMouseGrabOfWidget(QWidget *widget) +{ + if (qt_mouseGrb == widget) { + if (QWindow *window = grabberWindow(widget)) { +#ifndef QT_NO_CURSOR + if (mouseGrabWithCursor) { + QGuiApplication::restoreOverrideCursor(); + mouseGrabWithCursor = false; + } +#endif // !QT_NO_CURSOR + window->setMouseGrabEnabled(false); + } + } + qt_mouseGrb = 0; +} + /*! \fn void QWidget::grabMouse() @@ -12217,14 +12258,7 @@ static inline QWindow *grabberWindow(const QWidget *w) */ void QWidget::grabMouse() { - if (qt_mouseGrb) - qt_mouseGrb->releaseMouse(); - - if (QWindow *window = grabberWindow(this)) - window->setMouseGrabEnabled(true); - - qt_mouseGrb = this; - qt_pressGrab = 0; + grabMouseForWidget(this); } /*! @@ -12246,8 +12280,7 @@ void QWidget::grabMouse() #ifndef QT_NO_CURSOR void QWidget::grabMouse(const QCursor &cursor) { - Q_UNUSED(cursor); - grabMouse(); + grabMouseForWidget(this, &cursor); } #endif @@ -12269,11 +12302,7 @@ bool QWidgetPrivate::stealMouseGrab(bool grab) */ void QWidget::releaseMouse() { - if (qt_mouseGrb == this) { - if (QWindow *window = grabberWindow(this)) - window->setMouseGrabEnabled(false); - qt_mouseGrb = 0; - } + releaseMouseGrabOfWidget(this); } /*! -- cgit v1.2.3