diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-06-07 15:38:45 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-06-08 14:47:22 +0200 |
commit | 4469de4ce7a72ab6824629bfe8483131aaf22137 (patch) | |
tree | cc5b1c11c0681975e972f2d6aeab80e106d328c8 /src/widgets/kernel | |
parent | 88f3b059a935d1ce7735a5ae082c256619eea8c1 (diff) |
Cursor support in xcb plug-in.
Custom cursor pixmaps with depth greater than 1 are not yet supported
and will be converted to monochrome always.
Reviewed-by: Samuel Rødal
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 6 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget_p.h | 3 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget_qpa.cpp | 96 |
3 files changed, 50 insertions, 55 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 6c92e0bb94..9a7ad9fc0c 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -3348,6 +3348,12 @@ void QWidgetPrivate::setEnabled_helper(bool enable) // disabled widgets qt_x11_enforce_cursor(q); } +#elif defined(Q_WS_QPA) + if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) { + // enforce the windows behavior of clearing the cursor on + // disabled widgets + qt_qpa_set_cursor(q, false); + } #endif #if defined(Q_WS_MAC) setEnabled_helper_sys(enable); diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index cc894d514d..46c5ecfe33 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -903,9 +903,6 @@ public: void setFullScreenSize_helper(); bool stealKeyboardGrab(bool grab); bool stealMouseGrab(bool grab); -#ifndef QT_NO_CURSOR - void updateCursor() const; -#endif #elif defined(Q_OS_SYMBIAN) // <--------------------------------------------------------- SYMBIAN static QWidget *mouseGrabber; static QWidget *keyboardGrabber; diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp index 4bf8d5dd73..66a1a4ce35 100644 --- a/src/widgets/kernel/qwidget_qpa.cpp +++ b/src/widgets/kernel/qwidget_qpa.cpp @@ -299,20 +299,13 @@ void QWidgetPrivate::setCursor_sys(const QCursor &cursor) { Q_UNUSED(cursor); Q_Q(QWidget); - if (q->isVisible()) - qt_qpa_set_cursor(q, false); + qt_qpa_set_cursor(q, false); } void QWidgetPrivate::unsetCursor_sys() { Q_Q(QWidget); - if (q->isVisible()) - qt_qpa_set_cursor(q, false); -} - -void QWidgetPrivate::updateCursor() const -{ - // XXX + qt_qpa_set_cursor(q, false); } #endif //QT_NO_CURSOR @@ -858,56 +851,55 @@ void QWidgetPrivate::setModal_sys() } #ifndef QT_NO_CURSOR -void qt_qpa_set_cursor(QWidget * w, bool force) +static void applyCursor(QWidget *w, const QCursor &c) { - static QCursor arrowCursor(Qt::ArrowCursor); - static QPointer<QWidget> lastUnderMouse = 0; - - QCursor * override = QApplication::overrideCursor(); + QCursor cc = c; + QList<QWeakPointer<QPlatformCursor> > cursors = QPlatformCursorPrivate::getInstances(); + int cursorCount = cursors.count(); + for (int i = 0; i < cursorCount; ++i) { + const QWeakPointer<QPlatformCursor> &cursor(cursors.at(i)); + if (cursor) + cursor.data()->changeCursor(&cc, w->window()->windowHandle()); + } +} - if (override && w != 0) +void qt_qpa_set_cursor(QWidget *w, bool force) +{ + if (!w->testAttribute(Qt::WA_WState_Created)) return; - QWidget *cursorWidget; - QCursor cursorCursor; - - do { - if (w == 0) { - if (override) { - cursorCursor = *override; - cursorWidget = QApplication::topLevelAt(QCursor::pos()); - break; - } - w = QApplication::widgetAt(QCursor::pos()); - if (w == 0) // clear the override cursor while over empty space - w = QApplication::desktop(); - } else if (force) { - lastUnderMouse = w; - } else if (w->testAttribute(Qt::WA_WState_Created) && lastUnderMouse - && lastUnderMouse->effectiveWinId() == w->effectiveWinId()) { - w = lastUnderMouse; - } - if (w == QApplication::desktop() && !override) { - cursorCursor = arrowCursor; - cursorWidget = w; - break; - } + static QPointer<QWidget> lastUnderMouse = 0; + if (force) { + lastUnderMouse = w; + } else if (lastUnderMouse && lastUnderMouse->effectiveWinId() == w->effectiveWinId()) { + w = lastUnderMouse; + } else if (!w->internalWinId()) { + return; // The mouse is not under this widget, and it's not native, so don't change it. + } - QWidget * curWin = QApplication::activeWindow(); - if (!curWin && w && w->internalWinId()) - return; - QWidget* cW = w && !w->internalWinId() ? w : curWin; + while (!w->internalWinId() && w->parentWidget() && !w->isWindow() + && !w->testAttribute(Qt::WA_SetCursor)) + w = w->parentWidget(); - if (!cW || cW->window() != w->window() || - !cW->isVisible() || !cW->underMouse() || override) - return; + QWidget *nativeParent = w; + if (!w->internalWinId()) + nativeParent = w->nativeParentWidget(); + if (!nativeParent || !nativeParent->internalWinId()) + return; - cursorCursor = w->cursor(); - cursorWidget = w; - } while (0); - foreach (QWeakPointer<QPlatformCursor> cursor, QPlatformCursorPrivate::getInstances()) - if (cursor) - cursor.data()->changeCursor(&cursorCursor, cursorWidget->windowHandle()); + if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) { + QCursor *oc = QApplication::overrideCursor(); + if (oc) + applyCursor(nativeParent, *oc); + else if (w->isEnabled()) + applyCursor(nativeParent, w->cursor()); + else + // Enforce the windows behavior of clearing the cursor on + // disabled widgets. + applyCursor(nativeParent, Qt::ArrowCursor); + } else { + applyCursor(nativeParent, Qt::ArrowCursor); + } } #endif //QT_NO_CURSOR |