diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-06-20 11:05:11 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-07-03 06:32:50 +0200 |
commit | 135e9d5a8286e5abd35e04213c232d73c2df15b5 (patch) | |
tree | 7a29ec8a5855085d824b2b91228d119e3c47049e /src/widgets/kernel | |
parent | a4c4c12f0a7d00f238ede46f1fa8f89f61dce9a0 (diff) |
Implement QWidget::grabCursor(const QCursor&).
Implement using QGuiApplication::setOverrideCursor().
Task-number: QTBUG-39311
Change-Id: I83e289bfd5e911c31f08df9a4fc17fb8a0cf27f2
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 59 |
1 files changed, 44 insertions, 15 deletions
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); } /*! |