From 5190beae8166e615d2f910109cf081505ebe6807 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 3 May 2012 14:58:25 +0300 Subject: Add setCursor API to QWindow Change-Id: Id430ea9c94475356c9367a135f678f5f9ef795fc Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll --- src/gui/kernel/qwindow.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++ src/gui/kernel/qwindow.h | 13 ++++++++++ src/gui/kernel/qwindow_p.h | 7 ++++++ 3 files changed, 81 insertions(+) (limited to 'src') diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index 2117835609..8b37fce50c 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -59,6 +59,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -1684,4 +1685,64 @@ void QWindowPrivate::maybeQuitOnLastWindowClosed() } +/*! + \property QWindow::cursor + \brief the cursor shape for this window + + The mouse cursor will assume this shape when it is over this + window, unless an override cursor is set. See the \link + Qt::CursorShape list of predefined cursor objects\endlink for a + range of useful shapes. + + By default, this property contains a cursor with the Qt::ArrowCursor + shape. + + Some underlying window implementations will reset the cursor if it + leaves a window even if the mouse is grabbed. If you want to have + a cursor set for all windows, even when outside the window, consider + QGuiApplication::setOverrideCursor(). + + \sa QGuiApplication::setOverrideCursor() +*/ + +#ifndef QT_NO_CURSOR +QCursor QWindow::cursor() const +{ + Q_D(const QWindow); + return d->cursor; +} + +void QWindow::setCursor(const QCursor &cursor) +{ + Q_D(QWindow); + if (QPlatformCursor *platformCursor = d->screen->handle()->cursor()) { + d->cursor = cursor; + QCursor *oc = QGuiApplication::overrideCursor(); + QCursor c = oc ? *oc : d->cursor; + platformCursor->changeCursor(&c, this); + QEvent event(QEvent::CursorChange); + QGuiApplication::sendEvent(this, &event); + } +} + +/*! + \brief Restores the default arrow cursor for this window. + */ +void QWindow::unsetCursor() +{ + Q_D(QWindow); + if (QPlatformCursor *platformCursor = d->screen->handle()->cursor()) { + d->cursor = Qt::ArrowCursor; + QCursor *oc = QGuiApplication::overrideCursor(); + if (!oc) { + QCursor c = d->cursor; + platformCursor->changeCursor(&c, this); + } + QEvent event(QEvent::CursorChange); + QGuiApplication::sendEvent(this, &event); + } +} + +#endif + QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h index e99c062158..57c2f6f755 100644 --- a/src/gui/kernel/qwindow.h +++ b/src/gui/kernel/qwindow.h @@ -53,6 +53,10 @@ #include #include +#ifndef QT_NO_CURSOR +#include +#endif + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -92,6 +96,9 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged) +#ifndef QT_NO_CURSOR + Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor) +#endif public: @@ -205,6 +212,12 @@ public: QPoint mapToGlobal(const QPoint &pos) const; QPoint mapFromGlobal(const QPoint &pos) const; +#ifndef QT_NO_CURSOR + QCursor cursor() const; + void setCursor(const QCursor &); + void unsetCursor(); +#endif + public Q_SLOTS: void setVisible(bool visible); diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h index 375bd1e729..0afd903ead 100644 --- a/src/gui/kernel/qwindow_p.h +++ b/src/gui/kernel/qwindow_p.h @@ -84,6 +84,9 @@ public: , blockedByModalWindow(false) , transientParent(0) , screen(0) +#ifndef QT_NO_CURSOR + , cursor(Qt::ArrowCursor) +#endif { isWindow = true; } @@ -128,6 +131,10 @@ public: QPointer transientParent; QScreen *screen; + +#ifndef QT_NO_CURSOR + QCursor cursor; +#endif }; -- cgit v1.2.3