Implement QWidget::grabCursor(const QCursor&).

Implement using QGuiApplication::setOverrideCursor().

Task-number: QTBUG-39311
Change-Id: I83e289bfd5e911c31f08df9a4fc17fb8a0cf27f2
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
bb10
Friedemann Kleint 2014-06-20 11:05:11 +02:00
parent a4c4c12f0a
commit 135e9d5a82
2 changed files with 47 additions and 23 deletions

View File

@ -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);

View File

@ -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);
}
/*!