From 84251f84b6e7deadb7d50527b877d13cea74ad4b Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 26 Sep 2011 22:59:46 +0200 Subject: [PATCH] Implement support for QGuiApp::setOverrideCursor() Properly support application override cursors and move the documentation into the proper place. Change-Id: I0198b38e0d2e7b10f0fcae342b468e7f8341bf02 Reviewed-on: http://codereview.qt-project.org/5562 Reviewed-by: Qt Sanity Bot Reviewed-by: Paul Olav Tvete --- src/gui/kernel/qguiapplication.cpp | 61 ++++++++++++++++++++++++++--- src/widgets/kernel/qapplication.cpp | 38 ------------------ 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 2aaa2e65f8..77b04bc057 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1146,24 +1146,73 @@ void QGuiApplication::changeOverrideCursor(const QCursor &cursor) } #endif -/*! - \fn void QGuiApplication::setOverrideCursor(const QCursor &cursor, bool replace) - - Use changeOverrideCursor(\a cursor) (if \a replace is true) or - setOverrideCursor(\a cursor) (if \a replace is false). -*/ #ifndef QT_NO_CURSOR +static void applyCursor(QWindow *w, const QCursor &c) +{ + QCursor cc = c; + QList > cursors = QPlatformCursorPrivate::getInstances(); + int cursorCount = cursors.count(); + for (int i = 0; i < cursorCount; ++i) { + const QWeakPointer &cursor(cursors.at(i)); + if (cursor) + cursor.data()->changeCursor(&cc, w); + } +} + + +/*! + \fn void QGuiApplication::setOverrideCursor(const QCursor &cursor) + + Sets the application override cursor to \a cursor. + + Application override cursors are intended for showing the user that the + application is in a special state, for example during an operation that + might take some time. + + This cursor will be displayed in all the application's widgets until + restoreOverrideCursor() or another setOverrideCursor() is called. + + Application cursors are stored on an internal stack. setOverrideCursor() + pushes the cursor onto the stack, and restoreOverrideCursor() pops the + active cursor off the stack. changeOverrideCursor() changes the curently + active application override cursor. + + Every setOverrideCursor() must eventually be followed by a corresponding + restoreOverrideCursor(), otherwise the stack will never be emptied. + + Example: + \snippet doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp 0 + + \sa overrideCursor(), restoreOverrideCursor(), changeOverrideCursor(), + QWidget::setCursor() +*/ void QGuiApplication::setOverrideCursor(const QCursor &cursor) { qGuiApp->d_func()->cursor_list.prepend(cursor); + for (int i = 0; i < QGuiApplicationPrivate::window_list.size(); ++i) + applyCursor(QGuiApplicationPrivate::window_list.at(i), cursor); } +/*! + \fn void QGuiApplication::restoreOverrideCursor() + + Undoes the last setOverrideCursor(). + + If setOverrideCursor() has been called twice, calling + restoreOverrideCursor() will activate the first cursor set. Calling this + function a second time restores the original widgets' cursors. + + \sa setOverrideCursor(), overrideCursor() +*/ void QGuiApplication::restoreOverrideCursor() { if (qGuiApp->d_func()->cursor_list.isEmpty()) return; qGuiApp->d_func()->cursor_list.removeFirst(); + QCursor c(qGuiApp->d_func()->cursor_list.value(0, QCursor())); + for (int i = 0; i < QGuiApplicationPrivate::window_list.size(); ++i) + applyCursor(QGuiApplicationPrivate::window_list.at(i), c); } #endif// QT_NO_CURSOR diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 7550e7dec3..1f4016bd95 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -5084,44 +5084,6 @@ int QApplication::keyboardInputInterval() available in Qt for Embedded Linux. */ -/*! - \fn void QApplication::setOverrideCursor(const QCursor &cursor) - - Sets the application override cursor to \a cursor. - - Application override cursors are intended for showing the user that the - application is in a special state, for example during an operation that - might take some time. - - This cursor will be displayed in all the application's widgets until - restoreOverrideCursor() or another setOverrideCursor() is called. - - Application cursors are stored on an internal stack. setOverrideCursor() - pushes the cursor onto the stack, and restoreOverrideCursor() pops the - active cursor off the stack. changeOverrideCursor() changes the curently - active application override cursor. - - Every setOverrideCursor() must eventually be followed by a corresponding - restoreOverrideCursor(), otherwise the stack will never be emptied. - - Example: - \snippet doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp 0 - - \sa overrideCursor(), restoreOverrideCursor(), changeOverrideCursor(), - QWidget::setCursor() -*/ - -/*! - \fn void QApplication::restoreOverrideCursor() - - Undoes the last setOverrideCursor(). - - If setOverrideCursor() has been called twice, calling - restoreOverrideCursor() will activate the first cursor set. Calling this - function a second time restores the original widgets' cursors. - - \sa setOverrideCursor(), overrideCursor() -*/ /*! \macro qApp