Move some cursor handling to QGuiApplication from QApplication.

This commit is contained in:
Samuel Rødal 2011-05-04 14:58:13 +02:00
parent 8c626b7079
commit 7a0ae98978
9 changed files with 317 additions and 311 deletions

View File

@ -43,7 +43,7 @@
#ifndef QT_NO_CURSOR
#include <qapplication.h>
#include <qcoreapplication.h>
#include <qbitmap.h>
#include <qimage.h>
#include <qdatastream.h>
@ -410,7 +410,7 @@ void QCursorData::initialize()
QCursor::QCursor()
{
if (!QCursorData::initialized) {
if (QApplication::startingUp()) {
if (QCoreApplication::startingUp()) {
d = 0;
return;
}

View File

@ -47,7 +47,7 @@
#include "qevent.h"
#include "qfile.h"
#include "qtextcodec.h"
#include "qapplication.h"
#include "qguiapplication.h"
#include "qpoint.h"
#include "qwidget.h"
#include "qbuffer.h"
@ -60,7 +60,7 @@
#include "qdebug.h"
#include <ctype.h>
#include <private/qapplication_p.h>
#include <private/qguiapplication_p.h>
#ifndef QT_NO_DRAGANDDROP
@ -154,7 +154,7 @@ QDragManager::~QDragManager()
{
#ifndef QT_NO_CURSOR
if (restoreCursor)
QApplication::restoreOverrideCursor();
QGuiApplication::restoreOverrideCursor();
#endif
instance = 0;
delete dropData;
@ -173,14 +173,14 @@ QPixmap QDragManager::dragCursor(Qt::DropAction action) const
if (d && d->customCursors.contains(action))
return d->customCursors[action];
else if (action == Qt::MoveAction)
return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragMoveCursor);
return QGuiApplicationPrivate::instance()->getPixmapCursor(Qt::DragMoveCursor);
else if (action == Qt::CopyAction)
return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragCopyCursor);
return QGuiApplicationPrivate::instance()->getPixmapCursor(Qt::DragCopyCursor);
else if (action == Qt::LinkAction)
return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragLinkCursor);
return QGuiApplicationPrivate::instance()->getPixmapCursor(Qt::DragLinkCursor);
#ifdef Q_WS_WIN
else if (action == Qt::IgnoreAction)
return QApplicationPrivate::instance()->getPixmapCursor(Qt::ForbiddenCursor);
return QGuiApplicationPrivate::instance()->getPixmapCursor(Qt::ForbiddenCursor);
#endif
return QPixmap();
}

View File

@ -64,6 +64,8 @@
#include "private/qwindow_p.h"
#include "private/qkeymapper_p.h"
#include <QtGui/QPixmap>
#ifndef QT_NO_CLIPBOARD
#include <QtGui/QClipboard>
#endif
@ -144,6 +146,10 @@ QGuiApplication::~QGuiApplication()
delete QGuiApplicationPrivate::qt_clipboard;
QGuiApplicationPrivate::qt_clipboard = 0;
#ifndef QT_NO_CURSOR
d->cursor_list.clear();
#endif
}
QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags)
@ -466,7 +472,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
#if 0
if (self->inPopupMode()) {
//popup mouse handling is magical...
mouseWindow = qApp->activePopupWidget();
mouseWindow = qGuiApp->activePopupWidget();
implicit_mouse_grabber.clear();
//### how should popup mode and implicit mouse grab interact?
@ -878,6 +884,63 @@ Qt::LayoutDirection QGuiApplication::layoutDirection()
return layout_direction;
}
/*!
\fn QCursor *QGuiApplication::overrideCursor()
Returns the active application override cursor.
This function returns 0 if no application cursor has been defined (i.e. the
internal cursor stack is empty).
\sa setOverrideCursor(), restoreOverrideCursor()
*/
#ifndef QT_NO_CURSOR
QCursor *QGuiApplication::overrideCursor()
{
return qGuiApp->d_func()->cursor_list.isEmpty() ? 0 : &qGuiApp->d_func()->cursor_list.first();
}
/*!
Changes the currently active application override cursor to \a cursor.
This function has no effect if setOverrideCursor() was not called.
\sa setOverrideCursor(), overrideCursor(), restoreOverrideCursor(),
QWidget::setCursor()
*/
void QGuiApplication::changeOverrideCursor(const QCursor &cursor)
{
if (qGuiApp->d_func()->cursor_list.isEmpty())
return;
qGuiApp->d_func()->cursor_list.removeFirst();
setOverrideCursor(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
void QGuiApplication::setOverrideCursor(const QCursor &cursor)
{
qGuiApp->d_func()->cursor_list.prepend(cursor);
qt_qpa_set_cursor(0, false);
}
void QGuiApplication::restoreOverrideCursor()
{
if (qGuiApp->d_func()->cursor_list.isEmpty())
return;
qGuiApp->d_func()->cursor_list.removeFirst();
qt_qpa_set_cursor(0, false);
}
#endif// QT_NO_CURSOR
// Returns the current platform used by keyBindings
uint QGuiApplicationPrivate::currentKeyPlatform()
{
@ -935,5 +998,230 @@ Qt::LayoutDirection QGuiApplication::keyboardInputDirection()
QFontDatabase::removeApplicationFont()
*/
// These pixmaps approximate the images in the Windows User Interface Guidelines.
// XPM
static const char * const move_xpm[] = {
"11 20 3 1",
". c None",
#if defined(Q_WS_WIN)
"a c #000000",
"X c #FFFFFF", // Windows cursor is traditionally white
#else
"a c #FFFFFF",
"X c #000000", // X11 cursor is traditionally black
#endif
"aa.........",
"aXa........",
"aXXa.......",
"aXXXa......",
"aXXXXa.....",
"aXXXXXa....",
"aXXXXXXa...",
"aXXXXXXXa..",
"aXXXXXXXXa.",
"aXXXXXXXXXa",
"aXXXXXXaaaa",
"aXXXaXXa...",
"aXXaaXXa...",
"aXa..aXXa..",
"aa...aXXa..",
"a.....aXXa.",
"......aXXa.",
".......aXXa",
".......aXXa",
"........aa."};
#ifdef Q_WS_WIN
/* XPM */
static const char * const ignore_xpm[] = {
"24 30 3 1",
". c None",
"a c #000000",
"X c #FFFFFF",
"aa......................",
"aXa.....................",
"aXXa....................",
"aXXXa...................",
"aXXXXa..................",
"aXXXXXa.................",
"aXXXXXXa................",
"aXXXXXXXa...............",
"aXXXXXXXXa..............",
"aXXXXXXXXXa.............",
"aXXXXXXaaaa.............",
"aXXXaXXa................",
"aXXaaXXa................",
"aXa..aXXa...............",
"aa...aXXa...............",
"a.....aXXa..............",
"......aXXa.....XXXX.....",
".......aXXa..XXaaaaXX...",
".......aXXa.XaaaaaaaaX..",
"........aa.XaaaXXXXaaaX.",
"...........XaaaaX..XaaX.",
"..........XaaXaaaX..XaaX",
"..........XaaXXaaaX.XaaX",
"..........XaaX.XaaaXXaaX",
"..........XaaX..XaaaXaaX",
"...........XaaX..XaaaaX.",
"...........XaaaXXXXaaaX.",
"............XaaaaaaaaX..",
".............XXaaaaXX...",
"...............XXXX....."};
#endif
/* XPM */
static const char * const copy_xpm[] = {
"24 30 3 1",
". c None",
"a c #000000",
"X c #FFFFFF",
#if defined(Q_WS_WIN) // Windows cursor is traditionally white
"aa......................",
"aXa.....................",
"aXXa....................",
"aXXXa...................",
"aXXXXa..................",
"aXXXXXa.................",
"aXXXXXXa................",
"aXXXXXXXa...............",
"aXXXXXXXXa..............",
"aXXXXXXXXXa.............",
"aXXXXXXaaaa.............",
"aXXXaXXa................",
"aXXaaXXa................",
"aXa..aXXa...............",
"aa...aXXa...............",
"a.....aXXa..............",
"......aXXa..............",
".......aXXa.............",
".......aXXa.............",
"........aa...aaaaaaaaaaa",
#else
"XX......................",
"XaX.....................",
"XaaX....................",
"XaaaX...................",
"XaaaaX..................",
"XaaaaaX.................",
"XaaaaaaX................",
"XaaaaaaaX...............",
"XaaaaaaaaX..............",
"XaaaaaaaaaX.............",
"XaaaaaaXXXX.............",
"XaaaXaaX................",
"XaaXXaaX................",
"XaX..XaaX...............",
"XX...XaaX...............",
"X.....XaaX..............",
"......XaaX..............",
".......XaaX.............",
".......XaaX.............",
"........XX...aaaaaaaaaaa",
#endif
".............aXXXXXXXXXa",
".............aXXXXXXXXXa",
".............aXXXXaXXXXa",
".............aXXXXaXXXXa",
".............aXXaaaaaXXa",
".............aXXXXaXXXXa",
".............aXXXXaXXXXa",
".............aXXXXXXXXXa",
".............aXXXXXXXXXa",
".............aaaaaaaaaaa"};
/* XPM */
static const char * const link_xpm[] = {
"24 30 3 1",
". c None",
"a c #000000",
"X c #FFFFFF",
#if defined(Q_WS_WIN) // Windows cursor is traditionally white
"aa......................",
"aXa.....................",
"aXXa....................",
"aXXXa...................",
"aXXXXa..................",
"aXXXXXa.................",
"aXXXXXXa................",
"aXXXXXXXa...............",
"aXXXXXXXXa..............",
"aXXXXXXXXXa.............",
"aXXXXXXaaaa.............",
"aXXXaXXa................",
"aXXaaXXa................",
"aXa..aXXa...............",
"aa...aXXa...............",
"a.....aXXa..............",
"......aXXa..............",
".......aXXa.............",
".......aXXa.............",
"........aa...aaaaaaaaaaa",
#else
"XX......................",
"XaX.....................",
"XaaX....................",
"XaaaX...................",
"XaaaaX..................",
"XaaaaaX.................",
"XaaaaaaX................",
"XaaaaaaaX...............",
"XaaaaaaaaX..............",
"XaaaaaaaaaX.............",
"XaaaaaaXXXX.............",
"XaaaXaaX................",
"XaaXXaaX................",
"XaX..XaaX...............",
"XX...XaaX...............",
"X.....XaaX..............",
"......XaaX..............",
".......XaaX.............",
".......XaaX.............",
"........XX...aaaaaaaaaaa",
#endif
".............aXXXXXXXXXa",
".............aXXXaaaaXXa",
".............aXXXXaaaXXa",
".............aXXXaaaaXXa",
".............aXXaaaXaXXa",
".............aXXaaXXXXXa",
".............aXXaXXXXXXa",
".............aXXXaXXXXXa",
".............aXXXXXXXXXa",
".............aaaaaaaaaaa"};
QPixmap QGuiApplicationPrivate::getPixmapCursor(Qt::CursorShape cshape)
{
#if defined(Q_WS_X11) || defined(Q_WS_WIN)
if (!move_cursor) {
move_cursor = new QPixmap((const char **)move_xpm);
copy_cursor = new QPixmap((const char **)copy_xpm);
link_cursor = new QPixmap((const char **)link_xpm);
#ifdef Q_WS_WIN
ignore_cursor = new QPixmap((const char **)ignore_xpm);
#endif
}
switch (cshape) {
case Qt::DragMoveCursor:
return *move_cursor;
case Qt::DragCopyCursor:
return *copy_cursor;
case Qt::DragLinkCursor:
return *link_cursor;
#ifdef Q_WS_WIN
case Qt::ForbiddenCursor:
return *ignore_cursor;
#endif
default:
break;
}
#else
Q_UNUSED(cshape);
#endif
return QPixmap();
}
QT_END_NAMESPACE

View File

@ -57,6 +57,16 @@ QT_MODULE(Gui)
class QGuiApplicationPrivate;
class QPlatformNativeInterface;
#if defined(qApp)
#undef qApp
#endif
#define qApp (static_cast<QGuiApplication *>(QCoreApplication::instance()))
#if defined(qGuiApp)
#undef qGuiApp
#endif
#define qGuiApp (static_cast<QGuiApplication *>(QCoreApplication::instance()))
class Q_GUI_EXPORT QGuiApplication : public QCoreApplication
{
Q_OBJECT
@ -68,13 +78,11 @@ public:
QGuiApplication(int &argc, char **argv, int = ApplicationFlags);
virtual ~QGuiApplication();
#if 0
#ifndef QT_NO_CURSOR
static QCursor *overrideCursor();
static void setOverrideCursor(const QCursor &);
static void changeOverrideCursor(const QCursor &);
static void restoreOverrideCursor();
#endif
#endif
static QFont font();

View File

@ -130,6 +130,9 @@ public:
return alignment;
}
QPixmap getPixmapCursor(Qt::CursorShape cshape);
static QGuiApplicationPrivate *instance() { return self; }
static bool app_do_modal;
@ -146,6 +149,10 @@ public:
static QClipboard *qt_clipboard;
#endif
#ifndef QT_NO_CURSOR
QList<QCursor> cursor_list;
#endif
static QFont *app_font;
private:
void init();
@ -153,6 +160,8 @@ private:
static QGuiApplicationPrivate *self;
};
extern void qt_qpa_set_cursor(QWidget *, bool);
QT_END_NAMESPACE
QT_END_HEADER

View File

@ -1124,9 +1124,6 @@ QApplication::~QApplication()
QApplicationPrivate::app_style = 0;
delete QApplicationPrivate::app_icon;
QApplicationPrivate::app_icon = 0;
#ifndef QT_NO_CURSOR
d->cursor_list.clear();
#endif
#ifndef QT_NO_DRAGANDDROP
if (qt_is_gui_used)
@ -3551,47 +3548,6 @@ Qt::Alignment QApplication::horizontalAlignment(Qt::Alignment align)
}
#endif
/*!
\fn QCursor *QApplication::overrideCursor()
Returns the active application override cursor.
This function returns 0 if no application cursor has been defined (i.e. the
internal cursor stack is empty).
\sa setOverrideCursor(), restoreOverrideCursor()
*/
#ifndef QT_NO_CURSOR
QCursor *QApplication::overrideCursor()
{
return qApp->d_func()->cursor_list.isEmpty() ? 0 : &qApp->d_func()->cursor_list.first();
}
/*!
Changes the currently active application override cursor to \a cursor.
This function has no effect if setOverrideCursor() was not called.
\sa setOverrideCursor(), overrideCursor(), restoreOverrideCursor(),
QWidget::setCursor()
*/
void QApplication::changeOverrideCursor(const QCursor &cursor)
{
if (qApp->d_func()->cursor_list.isEmpty())
return;
qApp->d_func()->cursor_list.removeFirst();
setOverrideCursor(cursor);
}
#endif
/*!
\fn void QApplication::setOverrideCursor(const QCursor &cursor, bool replace)
Use changeOverrideCursor(\a cursor) (if \a replace is true) or
setOverrideCursor(\a cursor) (if \a replace is false).
*/
/*!
Enters the main event loop and waits until exit() is called, then returns
the value that was set to exit() (which is 0 if exit() is called via
@ -5733,232 +5689,6 @@ QGestureManager* QGestureManager::instance()
}
#endif // QT_NO_GESTURES
// These pixmaps approximate the images in the Windows User Interface Guidelines.
// XPM
static const char * const move_xpm[] = {
"11 20 3 1",
". c None",
#if defined(Q_WS_WIN)
"a c #000000",
"X c #FFFFFF", // Windows cursor is traditionally white
#else
"a c #FFFFFF",
"X c #000000", // X11 cursor is traditionally black
#endif
"aa.........",
"aXa........",
"aXXa.......",
"aXXXa......",
"aXXXXa.....",
"aXXXXXa....",
"aXXXXXXa...",
"aXXXXXXXa..",
"aXXXXXXXXa.",
"aXXXXXXXXXa",
"aXXXXXXaaaa",
"aXXXaXXa...",
"aXXaaXXa...",
"aXa..aXXa..",
"aa...aXXa..",
"a.....aXXa.",
"......aXXa.",
".......aXXa",
".......aXXa",
"........aa."};
#ifdef Q_WS_WIN
/* XPM */
static const char * const ignore_xpm[] = {
"24 30 3 1",
". c None",
"a c #000000",
"X c #FFFFFF",
"aa......................",
"aXa.....................",
"aXXa....................",
"aXXXa...................",
"aXXXXa..................",
"aXXXXXa.................",
"aXXXXXXa................",
"aXXXXXXXa...............",
"aXXXXXXXXa..............",
"aXXXXXXXXXa.............",
"aXXXXXXaaaa.............",
"aXXXaXXa................",
"aXXaaXXa................",
"aXa..aXXa...............",
"aa...aXXa...............",
"a.....aXXa..............",
"......aXXa.....XXXX.....",
".......aXXa..XXaaaaXX...",
".......aXXa.XaaaaaaaaX..",
"........aa.XaaaXXXXaaaX.",
"...........XaaaaX..XaaX.",
"..........XaaXaaaX..XaaX",
"..........XaaXXaaaX.XaaX",
"..........XaaX.XaaaXXaaX",
"..........XaaX..XaaaXaaX",
"...........XaaX..XaaaaX.",
"...........XaaaXXXXaaaX.",
"............XaaaaaaaaX..",
".............XXaaaaXX...",
"...............XXXX....."};
#endif
/* XPM */
static const char * const copy_xpm[] = {
"24 30 3 1",
". c None",
"a c #000000",
"X c #FFFFFF",
#if defined(Q_WS_WIN) // Windows cursor is traditionally white
"aa......................",
"aXa.....................",
"aXXa....................",
"aXXXa...................",
"aXXXXa..................",
"aXXXXXa.................",
"aXXXXXXa................",
"aXXXXXXXa...............",
"aXXXXXXXXa..............",
"aXXXXXXXXXa.............",
"aXXXXXXaaaa.............",
"aXXXaXXa................",
"aXXaaXXa................",
"aXa..aXXa...............",
"aa...aXXa...............",
"a.....aXXa..............",
"......aXXa..............",
".......aXXa.............",
".......aXXa.............",
"........aa...aaaaaaaaaaa",
#else
"XX......................",
"XaX.....................",
"XaaX....................",
"XaaaX...................",
"XaaaaX..................",
"XaaaaaX.................",
"XaaaaaaX................",
"XaaaaaaaX...............",
"XaaaaaaaaX..............",
"XaaaaaaaaaX.............",
"XaaaaaaXXXX.............",
"XaaaXaaX................",
"XaaXXaaX................",
"XaX..XaaX...............",
"XX...XaaX...............",
"X.....XaaX..............",
"......XaaX..............",
".......XaaX.............",
".......XaaX.............",
"........XX...aaaaaaaaaaa",
#endif
".............aXXXXXXXXXa",
".............aXXXXXXXXXa",
".............aXXXXaXXXXa",
".............aXXXXaXXXXa",
".............aXXaaaaaXXa",
".............aXXXXaXXXXa",
".............aXXXXaXXXXa",
".............aXXXXXXXXXa",
".............aXXXXXXXXXa",
".............aaaaaaaaaaa"};
/* XPM */
static const char * const link_xpm[] = {
"24 30 3 1",
". c None",
"a c #000000",
"X c #FFFFFF",
#if defined(Q_WS_WIN) // Windows cursor is traditionally white
"aa......................",
"aXa.....................",
"aXXa....................",
"aXXXa...................",
"aXXXXa..................",
"aXXXXXa.................",
"aXXXXXXa................",
"aXXXXXXXa...............",
"aXXXXXXXXa..............",
"aXXXXXXXXXa.............",
"aXXXXXXaaaa.............",
"aXXXaXXa................",
"aXXaaXXa................",
"aXa..aXXa...............",
"aa...aXXa...............",
"a.....aXXa..............",
"......aXXa..............",
".......aXXa.............",
".......aXXa.............",
"........aa...aaaaaaaaaaa",
#else
"XX......................",
"XaX.....................",
"XaaX....................",
"XaaaX...................",
"XaaaaX..................",
"XaaaaaX.................",
"XaaaaaaX................",
"XaaaaaaaX...............",
"XaaaaaaaaX..............",
"XaaaaaaaaaX.............",
"XaaaaaaXXXX.............",
"XaaaXaaX................",
"XaaXXaaX................",
"XaX..XaaX...............",
"XX...XaaX...............",
"X.....XaaX..............",
"......XaaX..............",
".......XaaX.............",
".......XaaX.............",
"........XX...aaaaaaaaaaa",
#endif
".............aXXXXXXXXXa",
".............aXXXaaaaXXa",
".............aXXXXaaaXXa",
".............aXXXaaaaXXa",
".............aXXaaaXaXXa",
".............aXXaaXXXXXa",
".............aXXaXXXXXXa",
".............aXXXaXXXXXa",
".............aXXXXXXXXXa",
".............aaaaaaaaaaa"};
QPixmap QApplicationPrivate::getPixmapCursor(Qt::CursorShape cshape)
{
#if defined(Q_WS_X11) || defined(Q_WS_WIN)
if (!move_cursor) {
move_cursor = new QPixmap((const char **)move_xpm);
copy_cursor = new QPixmap((const char **)copy_xpm);
link_cursor = new QPixmap((const char **)link_xpm);
#ifdef Q_WS_WIN
ignore_cursor = new QPixmap((const char **)ignore_xpm);
#endif
}
switch (cshape) {
case Qt::DragMoveCursor:
return *move_cursor;
case Qt::DragCopyCursor:
return *copy_cursor;
case Qt::DragLinkCursor:
return *link_cursor;
#ifdef Q_WS_WIN
case Qt::ForbiddenCursor:
return *ignore_cursor;
#endif
default:
break;
}
#else
Q_UNUSED(cshape);
#endif
return QPixmap();
}
QString QApplicationPrivate::qmljsDebugArgumentsString()
{
return qmljs_debug_arguments;

View File

@ -156,12 +156,6 @@ public:
// ### Qt4 compatibility, remove?
static inline void setGraphicsSystem(const QString &) {}
#ifndef QT_NO_CURSOR
static QCursor *overrideCursor();
static void setOverrideCursor(const QCursor &);
static void changeOverrideCursor(const QCursor &);
static void restoreOverrideCursor();
#endif
static QPalette palette();
static QPalette palette(const QWidget *);
static QPalette palette(const char *className);

View File

@ -367,9 +367,6 @@ public:
bool is_session_restored;
#endif
#ifndef QT_NO_CURSOR
QList<QCursor> cursor_list;
#endif
#ifndef QT_NO_GRAPHICSVIEW
// Maintain a list of all scenes to ensure font and palette propagation to
// all scenes.
@ -528,7 +525,6 @@ public:
#if defined(Q_WS_WIN)
QPixmap *ignore_cursor;
#endif
QPixmap getPixmapCursor(Qt::CursorShape cshape);
QMap<int, QWeakPointer<QWidget> > widgetForTouchPointId;
QMap<int, QTouchEvent::TouchPoint> appCurrentTouchPoints;
@ -622,8 +618,6 @@ Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window,
extern void qt_x11_enforce_cursor(QWidget *);
#elif defined(Q_OS_SYMBIAN)
extern void qt_symbian_set_cursor(QWidget *, bool);
#elif defined (Q_WS_QPA)
extern void qt_qpa_set_cursor(QWidget *, bool);
#endif
QT_END_NAMESPACE

View File

@ -333,23 +333,6 @@ bool QApplication::isEffectEnabled(Qt::UIEffect effect)
}
}
#ifndef QT_NO_CURSOR
void QApplication::setOverrideCursor(const QCursor &cursor)
{
qApp->d_func()->cursor_list.prepend(cursor);
qt_qpa_set_cursor(0, false);
}
void QApplication::restoreOverrideCursor()
{
if (qApp->d_func()->cursor_list.isEmpty())
return;
qApp->d_func()->cursor_list.removeFirst();
qt_qpa_set_cursor(0, false);
}
#endif// QT_NO_CURSOR
QWidget *QApplication::topLevelAt(const QPoint &pos)
{
QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();