Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/kernel/qapplication.cpp

    r428 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
    4040****************************************************************************/
    4141
     42#include "qplatformdefs.h"
    4243#include "qabstracteventdispatcher.h"
    4344#include "qaccessible.h"
     
    7576#ifdef Q_WS_X11
    7677#include <private/qt_x11_p.h>
     78#endif
     79
     80#if defined(Q_WS_X11) || defined(Q_WS_S60)
    7781#include "qinputcontextfactory.h"
    7882#endif
     83
     84#include "qguiplatformplugin_p.h"
    7985
    8086#include <qthread.h>
     
    8692
    8793#include "qapplication_p.h"
     94#include "qevent_p.h"
    8895#include "qwidget_p.h"
    8996
    9097#include "qapplication.h"
    9198
    92 #ifdef Q_OS_WINCE
     99#include "qgesture.h"
     100#include "private/qgesturemanager_p.h"
     101
     102#ifndef QT_NO_LIBRARY
     103#include "qlibrary.h"
     104#endif
     105
     106#ifdef Q_WS_WINCE
    93107#include "qdatetime.h"
    94108#include "qguifunctions_wince.h"
     
    98112#endif
    99113
     114#include "qdatetime.h"
     115
     116#ifdef QT_MAC_USE_COCOA
     117#include <private/qt_cocoa_helpers_mac_p.h>
     118#endif
     119
    100120//#define ALIEN_DEBUG
    101121
    102122static void initResources()
    103123{
    104 #ifdef Q_OS_WINCE
     124#ifdef Q_WS_WINCE
    105125    Q_INIT_RESOURCE(qstyle_wince);
    106126#else
     
    108128#endif
    109129
    110 #if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
    111     Q_INIT_RESOURCE(qpaintengine_d3d);
    112 #endif
    113130    Q_INIT_RESOURCE(qmessagebox);
    114131#if !defined(QT_NO_PRINTDIALOG)
     
    128145
    129146#ifndef QT_NO_IM
    130 QInputContext *QApplicationPrivate::inputContext;
     147QInputContext *QApplicationPrivate::inputContext = 0;
    131148#endif
    132149
    133150bool QApplicationPrivate::quitOnLastWindowClosed = true;
    134151
    135 #ifdef Q_OS_WINCE
     152#ifdef Q_WS_WINCE
    136153int QApplicationPrivate::autoMaximizeThreshold = -1;
    137154bool QApplicationPrivate::autoSipEnabled = false;
     155#else
     156bool QApplicationPrivate::autoSipEnabled = true;
    138157#endif
    139158
     
    161180#endif
    162181
     182    gestureManager = 0;
     183    gestureWidget = 0;
     184
    163185    if (!self)
    164186        self = this;
     
    176198    flow and main settings.
    177199
    178     \ingroup application
    179     \mainclass
    180 
    181200    QApplication contains the main event loop, where all events from the window
    182201    system and other sources are processed and dispatched. It also handles the
    183     application's initialization and finalization, and provides session
    184     management. In addition, it handles most system-wide and application-wide
    185     settings.
    186 
    187     For any GUI application using Qt, there is precisely one QApplication
     202    application's initialization, finalization, and provides session
     203    management. In addition, QApplication handles most of the system-wide and
     204    application-wide settings.
     205
     206    For any GUI application using Qt, there is precisely \bold one QApplication
    188207    object, no matter whether the application has 0, 1, 2 or more windows at
    189208    any given time. For non-GUI Qt applications, use QCoreApplication instead,
     
    241260        \endlist
    242261
    243     The QApplication object does so much initialization. Hence, it \e{must} be
     262    Since the QApplication object does so much initialization, it \e{must} be
    244263    created before any other objects related to the user interface are created.
    245     Since QApplication also deals with common command line arguments, it is
     264    QApplication also deals with common command line arguments. Hence, it is
    246265    usually a good idea to create it \e before any interpretation or
    247266    modification of \c argv is done in the application itself.
     
    397416
    398417QStyle *QApplicationPrivate::app_style = 0;        // default application style
     418QString QApplicationPrivate::styleOverride;        // style override
    399419
    400420#ifndef QT_NO_STYLE_STYLESHEET
     
    411431QString QApplicationPrivate::graphics_system_name;         // graphics system id - for delayed initialization
    412432
    413 Q_GLOBAL_STATIC(QMutex, applicationFontMutex);
     433Q_GLOBAL_STATIC(QMutex, applicationFontMutex)
    414434QFont *QApplicationPrivate::app_font = 0;        // default application font
    415435QFont *QApplicationPrivate::sys_font = 0;        // default system font
     
    433453int qt_antialiasing_threshold = -1;
    434454static int drag_time = 500;
     455#ifdef Q_OS_SYMBIAN
     456// The screens are a bit too small to for your thumb when using only 4 pixels drag distance.
     457static int drag_distance = 8;
     458#else
    435459static int drag_distance = 4;
     460#endif
    436461static Qt::LayoutDirection layout_direction = Qt::LeftToRight;
    437462QSize QApplicationPrivate::app_strut = QSize(0,0); // no default application strut
     
    444469bool QApplicationPrivate::animate_toolbox = false;
    445470bool QApplicationPrivate::widgetCount = false;
    446 QString* QApplicationPrivate::styleOverride = 0;
    447 #if defined(Q_WS_WIN) && !defined(Q_OS_WINCE)
    448 bool QApplicationPrivate::inSizeMove = false;
    449 #endif
     471bool QApplicationPrivate::load_testability = false;
    450472#ifdef QT_KEYPAD_NAVIGATION
    451 bool QApplicationPrivate::keypadNavigation = false;
     473#  ifdef Q_OS_SYMBIAN
     474Qt::NavigationMode QApplicationPrivate::navigationMode = Qt::NavigationModeKeypadDirectional;
     475#  else
     476Qt::NavigationMode QApplicationPrivate::navigationMode = Qt::NavigationModeKeypadTabOrder;
     477#  endif
    452478QWidget *QApplicationPrivate::oldEditFocus = 0;
    453479#endif
     
    456482static bool force_reverse = false;
    457483
    458 static inline bool isAlien(QWidget *widget)
     484inline bool QApplicationPrivate::isAlien(QWidget *widget)
    459485{
    460486    if (!widget)
    461487        return false;
    462 #ifdef Q_WS_MAC // Fake alien behavior on the Mac :)
     488#if defined(Q_WS_MAC) // Fake alien behavior on the Mac :)
    463489    return !widget->isWindow() && widget->window()->testAttribute(Qt::WA_DontShowOnScreen);
     490#elif defined(Q_WS_QWS)
     491    return !widget->isWindow()
     492# ifdef Q_BACKINGSTORE_SUBSURFACES
     493        && !(widget->d_func()->maybeTopData() && widget->d_func()->maybeTopData()->windowSurface)
     494# endif
     495        ;
    464496#else
    465497    return !widget->internalWinId();
     
    469501// ######## move to QApplicationPrivate
    470502// Default application palettes and fonts (per widget type)
    471 
    472 typedef QHash<QByteArray, QPalette> PaletteHash;
    473503Q_GLOBAL_STATIC(PaletteHash, app_palettes)
    474504PaletteHash *qt_app_palettes_hash()
     
    477507}
    478508
    479 typedef QHash<QByteArray, QFont> FontHash;
    480509Q_GLOBAL_STATIC(FontHash, app_fonts)
    481510FontHash *qt_app_fonts_hash()
     
    497526void QApplicationPrivate::process_cmdline()
    498527{
    499     Q_Q(QApplication);
    500     Q_UNUSED(q);// only static members being used.
    501528    // process platform-indep command line
    502529    if (!qt_is_gui_used || !argc)
     
    543570        } else if (qstrcmp(arg, "-reverse") == 0) {
    544571            force_reverse = true;
    545             q->setLayoutDirection(Qt::RightToLeft);
     572            QApplication::setLayoutDirection(Qt::RightToLeft);
    546573        } else if (qstrcmp(arg, "-widgetcount") == 0) {
    547574            widgetCount = true;
     575        } else if (qstrcmp(arg, "-testability") == 0) {
     576            load_testability = true;
    548577        } else if (arg == "-graphicssystem" && i < argc-1) {
    549578            graphics_system_name = QString::fromLocal8Bit(argv[++i]);
     
    556585                app_style = 0;
    557586            }
    558             if (!styleOverride)
    559                 styleOverride = new QString;
    560             *styleOverride = s;
     587            styleOverride = s;
    561588        }
    562589    }
     
    621648        \o  -graphicssystem, sets the backend to be used for on-screen widgets
    622649            and QPixmaps. Available options are \c{raster} and \c{opengl}.
    623     \endlist
    624 
    625     The Windows version of Qt supports an additional command line  option, if
    626     Direct3D support has been compiled into Qt:
    627     \list
    628         \o  -direct3d will make the Direct3D paint engine the default widget
    629             paint engine in Qt. \bold {This functionality is experimental.}
    630650    \endlist
    631651
     
    689709    On X11, the window system is initialized if \a GUIenabled is true. If
    690710    \a GUIenabled is false, the application does not connect to the X server.
    691     On Windows and Macintosh, currently the window system is always
    692     initialized, regardless of the value of GUIenabled. This may change in
    693     future versions of Qt.
     711    On Windows and Mac OS, currently the window system is always initialized,
     712    regardless of the value of GUIenabled. This may change in future versions
     713    of Qt.
    694714
    695715    The following example shows how to create an application that uses a
     
    756776    extern void qt_gui_eval_init(uint);
    757777    qt_gui_eval_init(application_type);
     778#endif
     779
     780#ifndef QT_NO_LIBRARY
     781    if(load_testability) {
     782        QLibrary testLib(QLatin1String("qttestability"));
     783        if (testLib.load()) {
     784            typedef void (*TasInitialize)(void);
     785            TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
     786            if (initFunction) {
     787                initFunction();
     788            } else {
     789                qCritical("Library qttestability resolve failed!");
     790            }
     791        } else {
     792            qCritical("Library qttestability load failed!");
     793        }
     794    }
     795
     796    //make sure the plugin is loaded
     797    if (qt_is_gui_used)
     798        qt_guiPlatformPlugin();
    758799#endif
    759800}
     
    835876#endif // Q_WS_X11
    836877
    837 
    838 /*!
     878extern void qInitDrawhelperAsm();
     879extern int qRegisterGuiVariant();
     880extern int qUnregisterGuiVariant();
     881#ifndef QT_NO_STATEMACHINE
     882extern int qRegisterGuiStateMachine();
     883extern int qUnregisterGuiStateMachine();
     884#endif
     885
     886/*!
     887  \fn void QApplicationPrivate::initialize()
     888
    839889  Initializes the QApplication object, called from the constructors.
    840890*/
    841 extern void qInitDrawhelperAsm();
    842 
    843891void QApplicationPrivate::initialize()
    844892{
    845893    QWidgetPrivate::mapper = new QWidgetMapper;
    846     QWidgetPrivate::uncreatedWidgets = new QWidgetSet;
     894    QWidgetPrivate::allWidgets = new QWidgetSet;
    847895    if (qt_appType != QApplication::Tty)
    848896        (void) QApplication::style();  // trigger creation of application style
    849897    // trigger registering of QVariant's GUI types
    850     extern int qRegisterGuiVariant();
    851898    qRegisterGuiVariant();
     899#ifndef QT_NO_STATEMACHINE
     900    // trigger registering of QStateMachine's GUI types
     901    qRegisterGuiStateMachine();
     902#endif
    852903
    853904    is_app_running = true; // no longer starting up
     
    862913        q->setAttribute(Qt::AA_NativeWindows);
    863914
    864 #if defined(Q_WS_WIN)
    865     // Alien is not currently working on Windows 98
    866     if (QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based)
    867         q->setAttribute(Qt::AA_NativeWindows);
    868 #endif
    869 
    870 #ifdef Q_OS_WINCE
     915#ifdef Q_WS_WINCE
    871916#ifdef QT_AUTO_MAXIMIZE_THRESHOLD
    872917    autoMaximizeThreshold = QT_AUTO_MAXIMIZE_THRESHOLD;
     
    877922        autoMaximizeThreshold = -1;
    878923#endif //QT_AUTO_MAXIMIZE_THRESHOLD
    879 #endif //Q_OS_WINCE
     924#endif //Q_WS_WINCE
    880925
    881926    // Set up which span functions should be used in raster engine...
     
    889934#endif
    890935#ifndef QT_NO_WHEELEVENT
    891 #ifdef QT_MAC_USE_COCOA
    892     QApplicationPrivate::wheel_scroll_lines = 1;
    893 #else
    894936    QApplicationPrivate::wheel_scroll_lines = 3;
    895937#endif
    896 #endif
     938
     939    if (qt_is_gui_used)
     940        initializeMultitouch();
    897941}
    898942
     
    9781022    d->eventDispatcher->closingDown();
    9791023    d->eventDispatcher = 0;
     1024    QApplicationPrivate::is_app_closing = true;
     1025    QApplicationPrivate::is_app_running = false;
    9801026
    9811027    delete qt_desktopWidget;
    9821028    qt_desktopWidget = 0;
    983     QApplicationPrivate::is_app_closing = true;
    984     QApplicationPrivate::is_app_running = false;
    9851029
    9861030#ifndef QT_NO_CLIPBOARD
     
    9891033#endif
    9901034
    991     // delete widget mapper
    992     if (QWidgetPrivate::mapper) {
    993         QWidgetMapper * myMapper = QWidgetPrivate::mapper;
    994         QWidgetPrivate::mapper = 0;
    995         for (QWidgetMapper::Iterator it = myMapper->begin(); it != myMapper->end(); ++it) {
    996             register QWidget *w = *it;
    997             if (!w->parent())                        // window
    998                 w->destroy(true, true);
    999         }
    1000         delete myMapper;
    1001     }
    1002 
    1003     // delete uncreated widgets
    1004     if (QWidgetPrivate::uncreatedWidgets) {
    1005         QWidgetSet *mySet = QWidgetPrivate::uncreatedWidgets;
    1006         QWidgetPrivate::uncreatedWidgets = 0;
    1007         for (QWidgetSet::Iterator it = mySet->begin(); it != mySet->end(); ++it) {
     1035    delete QWidgetPrivate::mapper;
     1036    QWidgetPrivate::mapper = 0;
     1037
     1038    // delete all widgets
     1039    if (QWidgetPrivate::allWidgets) {
     1040        QWidgetSet *mySet = QWidgetPrivate::allWidgets;
     1041        QWidgetPrivate::allWidgets = 0;
     1042        for (QWidgetSet::ConstIterator it = mySet->constBegin(); it != mySet->constEnd(); ++it) {
    10081043            register QWidget *w = *it;
    10091044            if (!w->parent())                        // window
     
    10441079        delete QDragManager::self();
    10451080#endif
     1081
     1082    d->cleanupMultitouch();
    10461083
    10471084    qt_cleanup();
     
    10711108    QApplicationPrivate::widgetCount = false;
    10721109
     1110#ifndef QT_NO_STATEMACHINE
     1111    // trigger unregistering of QStateMachine's GUI types
     1112    qUnregisterGuiStateMachine();
     1113#endif
    10731114    // trigger unregistering of QVariant's GUI types
    1074     extern int qUnregisterGuiVariant();
    10751115    qUnregisterGuiVariant();
    10761116}
     
    11531193          || event->type() == QEvent::Move
    11541194          || event->type() == QEvent::LanguageChange
     1195          || event->type() == QEvent::UpdateSoftKeys
    11551196          || event->type() == QEvent::InputMethod)) {
    11561197        for (int i = 0; i < postedEvents->size(); ++i) {
     
    11701211            } else if (cur.event->type() == QEvent::LanguageChange) {
    11711212                ;
     1213            } else if (cur.event->type() == QEvent::UpdateSoftKeys) {
     1214                ;
    11721215            } else if ( cur.event->type() == QEvent::InputMethod ) {
    11731216                *(QInputMethodEvent *)(cur.event) = *(QInputMethodEvent *)event;
     
    11991242    \brief defines a threshold for auto maximizing widgets
    12001243
    1201     The auto maximize threshold is only available as part of Qt for Windows CE.
     1244    \bold{The auto maximize threshold is only available as part of Qt for
     1245    Windows CE.}
    12021246
    12031247    This property defines a threshold for the size of a window as a percentage
    12041248    of the screen size. If the minimum size hint of a window exceeds the
    1205     threshold, calling show() will then cause the window to be maximized
     1249    threshold, calling show() will cause the window to be maximized
    12061250    automatically.
    12071251
    1208     Setting the threshold to be 100 or greater means that it will cause it to
    1209     always be maximized. Setting it to be 50 means that the widget is maximized
    1210     if the vertical minimum size hint is at least 50% of the vertical screen
    1211     size.
    1212 
    1213     If -1 is specified then this will disable the feature.
    1214 
    1215     On Windows CE the default is -1 (i.e. it is disabled).
     1252    Setting the threshold to 100 or greater means that the widget will always
     1253    be maximized. Alternatively, setting the threshold to 50 means that the
     1254    widget will be maximized only if the vertical minimum size hint is at least
     1255    50% of the vertical screen size.
     1256
     1257    Setting the threshold to -1 disables the feature.
     1258
     1259    On Windows CE the default is -1 (i.e., it is disabled).
    12161260    On Windows Mobile the default is 40.
    12171261*/
     
    12221266    \brief toggles automatic SIP (software input panel) visibility
    12231267
    1224     The auto SIP property is only available as part of Qt for Windows CE.
    1225 
    1226     Set this property to true to automatically display the SIP when entering
     1268    Set this property to \c true to automatically display the SIP when entering
    12271269    widgets that accept keyboard input. This property only affects widgets with
    1228     the WA_InputMethodEnabled attribute set.
    1229 */
    1230 
    1231 #ifdef Q_OS_WINCE
     1270    the WA_InputMethodEnabled attribute set, and is typically used to launch
     1271    a virtual keyboard on devices which have very few or no keys.
     1272
     1273    \bold{ The property only has an effect on platforms which use software input
     1274    panels, such as Windows CE and Symbian.}
     1275
     1276    The default is platform dependent.
     1277*/
     1278
     1279#ifdef Q_WS_WINCE
    12321280void QApplication::setAutoMaximizeThreshold(const int threshold)
    12331281{
     
    12391287    return QApplicationPrivate::autoMaximizeThreshold;
    12401288}
     1289#endif
    12411290
    12421291void QApplication::setAutoSipEnabled(const bool enabled)
     
    12491298    return QApplicationPrivate::autoSipEnabled;
    12501299}
    1251 #endif
    12521300
    12531301#ifndef QT_NO_STYLE_STYLESHEET
     
    12911339    }
    12921340
    1293 #if defined(Q_WS_X11)
    1294     if(!QApplicationPrivate::styleOverride)
    1295         QApplicationPrivate::x11_initialize_style(); // run-time search for default style
    1296 #endif
    12971341    if (!QApplicationPrivate::app_style) {
    12981342        // Compile-time search for default style
    12991343        //
    13001344        QString style;
    1301         if (QApplicationPrivate::styleOverride) {
    1302             style = *QApplicationPrivate::styleOverride;
    1303             delete QApplicationPrivate::styleOverride;
    1304             QApplicationPrivate::styleOverride = 0;
    1305         } else {
    1306 #if defined(Q_WS_WIN) && defined(Q_OS_WINCE)
    1307     if (qt_wince_is_smartphone() || qt_wince_is_pocket_pc())
    1308         style = QLatin1String("WindowsMobile");
    1309      else
    1310         style = QLatin1String("WindowsCE");
    1311 
    1312 #elif defined(Q_WS_WIN)
    1313             if ((QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA
    1314                 && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
    1315                 style = QLatin1String("WindowsVista");
    1316                 else if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
    1317                 && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
    1318                 style = QLatin1String("WindowsXP");
    1319             else
    1320                 style = QLatin1String("Windows");                // default styles for Windows
    1321 #elif defined(Q_WS_X11) && defined(Q_OS_SOLARIS)
    1322             style = QLatin1String("CDE");                        // default style for X11 on Solaris
    1323 #elif defined(Q_WS_X11) && defined(Q_OS_IRIX)
    1324             style = QLatin1String("SGI");                        // default style for X11 on IRIX
    1325 #elif defined(Q_WS_X11) || defined(Q_WS_QWS)
    1326             style = QLatin1String("Plastique");                  // default style for X11 and small devices
    1327 #elif defined(Q_WS_MAC)
    1328                 style = QLatin1String("Macintosh");              // default style for all Mac's
    1329 #endif
    1330         }
     1345        if (!QApplicationPrivate::styleOverride.isEmpty())
     1346            style = QApplicationPrivate::styleOverride;
     1347        else
     1348            style = QApplicationPrivate::desktopStyleKey();
    13311349
    13321350        QStyle *&app_style = QApplicationPrivate::app_style;
     
    14161434#endif // QT_NO_STYLE_STYLESHEET
    14171435        QApplicationPrivate::app_style = style;
    1418 
    14191436    QApplicationPrivate::app_style->setParent(qApp); // take ownership
    14201437
     
    15531570            texts and pixmaps with few colors. With this option, the
    15541571            application uses system global colors. This works fine for most
    1555             applications under X11, but on Windows machines it may cause
     1572            applications under X11, but on the Windows platform, it may cause
    15561573            dithering of non-standard colors.
    15571574        \o  QApplication::CustomColor. Use this option if your application
     
    19401957}
    19411958
     1959/*! \internal
     1960*/
     1961QString QApplicationPrivate::desktopStyleKey()
     1962{
     1963    return qt_guiPlatformPlugin()->styleName();
     1964}
     1965
    19421966/*!
    19431967    \property QApplication::windowIcon
     
    20122036QWidgetList QApplication::allWidgets()
    20132037{
    2014     QWidgetList list;
    2015     if (QWidgetPrivate::mapper)
    2016         list += QWidgetPrivate::mapper->values();
    2017     if (QWidgetPrivate::uncreatedWidgets)
    2018         list += QWidgetPrivate::uncreatedWidgets->toList();
    2019     return list;
     2038    if (QWidgetPrivate::allWidgets)
     2039        return QWidgetPrivate::allWidgets->toList();
     2040    return QWidgetList();
    20202041}
    20212042
     
    20342055void QApplicationPrivate::setFocusWidget(QWidget *focus, Qt::FocusReason reason)
    20352056{
    2036     if (focus && focus->window()
    20372057#ifndef QT_NO_GRAPHICSVIEW
    2038         && focus->window()->graphicsProxyWidget()
    2039 #endif
    2040        )
     2058    if (focus && focus->window()->graphicsProxyWidget())
    20412059        return;
     2060#endif
    20422061
    20432062    hidden_focus_widget = 0;
     
    20572076        QWidget *prev = focus_widget;
    20582077        focus_widget = focus;
    2059 
    20602078#ifndef QT_NO_IM
    20612079        if (prev && ((reason != Qt::PopupFocusReason && reason != Qt::MenuBarFocusReason
     
    20712089            }
    20722090        }
    2073 #endif
     2091#endif //QT_NO_IM
    20742092
    20752093        if(focus_widget)
     
    20822100#ifdef QT_KEYPAD_NAVIGATION
    20832101                if (QApplication::keypadNavigationEnabled()) {
    2084                     if (prev->hasEditFocus() && reason != Qt::PopupFocusReason)
     2102                    if (prev->hasEditFocus() && reason != Qt::PopupFocusReason
     2103#ifdef Q_OS_SYMBIAN
     2104                            && reason != Qt::ActiveWindowFocusReason
     2105#endif
     2106                            )
    20852107                        prev->setEditFocus(false);
     2108                }
     2109#endif
     2110#ifndef QT_NO_IM
     2111                if (focus) {
     2112                    QInputContext *prevIc;
     2113                    prevIc = prev->inputContext();
     2114                    if (prevIc && prevIc != focus->inputContext()) {
     2115                        QEvent closeSIPEvent(QEvent::CloseSoftwareInputPanel);
     2116                        QApplication::sendEvent(prev, &closeSIPEvent);
     2117                    }
    20862118                }
    20872119#endif
     
    20962128                if (focus->testAttribute(Qt::WA_InputMethodEnabled)) {
    20972129                    QInputContext *qic = focus->inputContext();
    2098                     if (qic && focus_widget->testAttribute(Qt::WA_WState_Created))
    2099                         qic->setFocusWidget( focus_widget );
     2130                    if (qic && focus->testAttribute(Qt::WA_WState_Created)
     2131                        && focus->isEnabled())
     2132                        qic->setFocusWidget(focus);
    21002133                }
    2101 #endif
     2134#endif //QT_NO_IM
    21022135                QFocusEvent in(QEvent::FocusIn, reason);
    21032136                QPointer<QWidget> that = focus;
     
    21062139                    QApplication::sendEvent(that->style(), &in);
    21072140            }
    2108         }
    2109         emit qApp->focusChanged(prev, focus_widget);
     2141            emit qApp->focusChanged(prev, focus_widget);
     2142        }
    21102143    }
    21112144}
     
    23172350            d->toolTipFallAsleep.stop();
    23182351        }
    2319 #ifdef QT_MAC_USE_COCOA
    2320     } else if (e->type() == QEvent::CocoaRequestModal) {
    2321         d->_q_runAppModalWindow();
    2322 #endif
    23232352    }
    23242353    return QCoreApplication::event(e);
     
    24642493 * Helper function that returns the new focus widget, but does not set the focus reason.
    24652494 * Returns 0 if a new focus widget could not be found.
     2495 * Shared with QGraphicsProxyWidgetPrivate::findFocusChild()
    24662496*/
    24672497QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool next)
     
    25042534    widget \a leave is left.
    25052535 */
    2506 #if defined(Q_WS_WIN)
    2507   extern void qt_win_set_cursor(QWidget *, bool);
    2508 #elif defined(Q_WS_PM)
    2509   extern void qt_pm_set_cursor(QWidget *, bool);
    2510 #elif defined(Q_WS_X11)
    2511   extern void qt_x11_enforce_cursor(QWidget *, bool);
    2512 #endif
    2513 
    25142536void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave) {
    25152537#if 0
     
    25862608    for (int i = 0; i < leaveList.size(); ++i) {
    25872609        w = leaveList.at(i);
    2588         if (!qApp->activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
     2610        if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
    25892611#if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
    25902612            if (leaveAfterRelease == w)
     
    25932615            QApplication::sendEvent(w, &leaveEvent);
    25942616            if (w->testAttribute(Qt::WA_Hover) &&
    2595                 (!qApp->activePopupWidget() || qApp->activePopupWidget() == w->window())) {
     2617                (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
    25962618                Q_ASSERT(instance());
    25972619                QHoverEvent he(QEvent::HoverLeave, QPoint(-1, -1), w->mapFromGlobal(QApplicationPrivate::instance()->hoverGlobalPos));
     
    26042626    for (int i = 0; i < enterList.size(); ++i) {
    26052627        w = enterList.at(i);
    2606         if (!qApp->activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
     2628        if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
    26072629            QApplication::sendEvent(w, &enterEvent);
    26082630            if (w->testAttribute(Qt::WA_Hover) &&
    2609                 (!qApp->activePopupWidget() || qApp->activePopupWidget() == w->window())) {
     2631                (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
    26102632                QHoverEvent he(QEvent::HoverEnter, w->mapFromGlobal(posEnter), QPoint(-1, -1));
    26112633                qApp->d_func()->notify_helper(w, &he);
     
    26272649            break;
    26282650        if (w->testAttribute(Qt::WA_SetCursor)) {
    2629             parentOfLeavingCursor = w->parentWidget();
     2651            QWidget *parent = w->parentWidget();
     2652            while (parent && parent->d_func()->data.in_destructor)
     2653                parent = parent->parentWidget();
     2654            parentOfLeavingCursor = parent;
    26302655            //continue looping, we need to find the downest alien widget with a cursor.
    26312656            // (downest on the screen)
     
    26592684#if defined(Q_WS_WIN)
    26602685            qt_win_set_cursor(cursorWidget, true);
     2686#elif defined(Q_WS_X11)
     2687            qt_x11_enforce_cursor(cursorWidget, true);
     2688#elif defined(Q_WS_S60)
     2689            qt_symbian_set_cursor(cursorWidget, true);
    26612690#elif defined(Q_WS_PM)
    26622691            qt_pm_set_cursor(cursorWidget, true);
    2663 #elif defined(Q_WS_X11)
    2664             qt_x11_enforce_cursor(cursorWidget, true);
    26652692#endif
    26662693        }
     
    26832710    if (!modalState())
    26842711        return false;
    2685     if (qApp->activePopupWidget() == widget)
     2712    if (QApplication::activePopupWidget() == widget)
    26862713        return false;
    26872714
     
    27722799{
    27732800    QSet<QWidget*> blocked;
    2774     QList<QWidget*> windows = qApp->topLevelWidgets();
     2801    QList<QWidget*> windows = QApplication::topLevelWidgets();
    27752802    for (int i = 0; i < windows.count(); ++i) {
    27762803        QWidget *window = windows.at(i);
     
    27812808    enterModal_sys(widget);
    27822809
    2783     windows = qApp->topLevelWidgets();
     2810    windows = QApplication::topLevelWidgets();
    27842811    QEvent e(QEvent::WindowBlocked);
    27852812    for (int i = 0; i < windows.count(); ++i) {
     
    27952822{
    27962823    QSet<QWidget*> blocked;
    2797     QList<QWidget*> windows = qApp->topLevelWidgets();
     2824    QList<QWidget*> windows = QApplication::topLevelWidgets();
    27982825    for (int i = 0; i < windows.count(); ++i) {
    27992826        QWidget *window = windows.at(i);
     
    28042831    leaveModal_sys(widget);
    28052832
    2806     windows = qApp->topLevelWidgets();
     2833    windows = QApplication::topLevelWidgets();
    28072834    QEvent e(QEvent::WindowUnblocked);
    28082835    for (int i = 0; i < windows.count(); ++i) {
     
    28272854
    28282855    // the active popup widget always gets the input event
    2829     if (qApp->activePopupWidget())
     2856    if (QApplication::activePopupWidget())
    28302857        return true;
    28312858
     
    28612888
    28622889    if (!mouseGrabber)
    2863         mouseGrabber = buttonDown ? buttonDown : alienWidget;
     2890        mouseGrabber = (buttonDown && !isBlockedByModal(buttonDown)) ? buttonDown : alienWidget;
    28642891
    28652892    if (mouseGrabber && mouseGrabber != candidate) {
     
    28802907bool QApplicationPrivate::sendMouseEvent(QWidget *receiver, QMouseEvent *event,
    28812908                                         QWidget *alienWidget, QWidget *nativeWidget,
    2882                                          QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver)
     2909                                         QWidget **buttonDown, QPointer<QWidget> &lastMouseReceiver,
     2910                                         bool spontaneous)
    28832911{
    28842912    Q_ASSERT(receiver);
     
    28932921    QPointer<QWidget> nativeGuard = nativeWidget;
    28942922    QPointer<QWidget> alienGuard = alienWidget;
    2895     QPointer<QWidget> activePopupWidget = qApp->activePopupWidget();
     2923    QPointer<QWidget> activePopupWidget = QApplication::activePopupWidget();
    28962924
    28972925    const bool graphicsWidget = nativeWidget->testAttribute(Qt::WA_DontShowOnScreen);
     
    29332961    // leaveAfterRelease is set to null, but we shall not update lastMouseReceiver.
    29342962    const bool wasLeaveAfterRelease = leaveAfterRelease != 0;
    2935     bool result = QApplication::sendSpontaneousEvent(receiver, event);
     2963    bool result;
     2964    if (spontaneous)
     2965        result = QApplication::sendSpontaneousEvent(receiver, event);
     2966    else
     2967        result = QApplication::sendEvent(receiver, event);
    29362968
    29372969    if (!graphicsWidget && leaveAfterRelease && event->type() == QEvent::MouseButtonRelease
     
    29622994}
    29632995
    2964 #if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
     2996#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_PM)
    29652997/*
    29662998    This function should only be called when the widget changes visibility, i.e.
     
    29743006{
    29753007#ifndef QT_NO_CURSOR
     3008#ifdef Q_WS_QWS
     3009    if (!widget || widget->isWindow())
     3010        return;
     3011#else
    29763012    if (!widget || widget->internalWinId() || widget->isWindow())
    29773013        return;
    2978 
     3014#endif
    29793015    const bool widgetInShow = widget->isVisible() && !widget->data->in_destructor;
    29803016    if (!widgetInShow && widget != qt_last_mouse_receiver)
     
    30143050
    30153051    // Send enter/leave events followed by a mouse move on the entered widget.
    3016     QMouseEvent e(QEvent::MouseMove, pos, globalPos, Qt::NoButton, mouse_buttons, modifier_buttons);
     3052    QMouseEvent e(QEvent::MouseMove, pos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier);
    30173053    sendMouseEvent(widgetUnderCursor, &e, widgetUnderCursor, tlw, &qt_button_down, qt_last_mouse_receiver);
    30183054#endif // QT_NO_CURSOR
     
    34893525        return;
    34903526    qApp->d_func()->cursor_list.removeFirst();
     3527#ifdef QT_MAC_USE_COCOA
     3528    // We use native NSCursor stacks in Cocoa. The currentCursor is the
     3529    // top of this stack. So to avoid flickering of cursor, we have to
     3530    // change the cusor instead of pop-ing the existing OverrideCursor
     3531    // and pushing the new one.
     3532    qApp->d_func()->cursor_list.prepend(cursor);
     3533    qt_cocoaChangeOverrideCursor(cursor);
     3534    return;
     3535#endif
    34913536    setOverrideCursor(cursor);
    34923537}
     
    35193564    We recommend that you connect clean-up code to the
    35203565    \l{QCoreApplication::}{aboutToQuit()} signal, instead of putting it in your
    3521     application's \c{main()} function because on some platforms the
    3522     QApplication::exec() call may not return. For example, on Windows when the
    3523     user logs off, the system terminates the process after Qt closes all
    3524     top-level windows. Hence, there is no guarantee that the application will
    3525     have time to exit its event loop and execute code at the end of the
    3526     \c{main()} function after the QApplication::exec() call.
     3566    application's \c{main()} function. This is because, on some platforms the
     3567    QApplication::exec() call may not return. For example, on the Windows
     3568    platform, when the user logs off, the system terminates the process after Qt
     3569    closes all top-level windows. Hence, there is \e{no guarantee} that the
     3570    application will have time to exit its event loop and execute code at the
     3571    end of the \c{main()} function, after the QApplication::exec() call.
    35273572
    35283573    \sa quitOnLastWindowClosed, quit(), exit(), processEvents(),
     
    35743619                else
    35753620                    QApplicationPrivate::mouse_buttons &= ~me->button();
    3576         }
     3621            }
    35773622#if !defined(QT_NO_WHEELEVENT) || !defined(QT_NO_TABLETEVENT)
    3578         else if (
     3623            else if (false
    35793624#  ifndef QT_NO_WHEELEVENT
    3580                  e->type() == QEvent::Wheel ||
     3625                     || e->type() == QEvent::Wheel
    35813626#  endif
    35823627#  ifndef QT_NO_TABLETEVENT
    3583                  e->type() == QEvent::TabletMove
    3584                  || e->type() == QEvent::TabletPress
    3585                  || e->type() == QEvent::TabletRelease
     3628                     || e->type() == QEvent::TabletMove
     3629                     || e->type() == QEvent::TabletPress
     3630                     || e->type() == QEvent::TabletRelease
    35863631#  endif
    3587         ) {
     3632                     ) {
    35883633            QInputEvent *ie = static_cast<QInputEvent*>(e);
    35893634            QApplicationPrivate::modifier_buttons = ie->modifiers();
     
    35913636#endif // !QT_NO_WHEELEVENT || !QT_NO_TABLETEVENT
    35923637    }
     3638
     3639    // walk through parents and check for gestures
     3640    if (d->gestureManager) {
     3641        switch (e->type()) {
     3642        case QEvent::Paint:
     3643        case QEvent::MetaCall:
     3644        case QEvent::DeferredDelete:
     3645        case QEvent::DragEnter: case QEvent::DragMove: case QEvent::DragLeave:
     3646        case QEvent::Drop: case QEvent::DragResponse:
     3647        case QEvent::ChildAdded: case QEvent::ChildPolished:
     3648#ifdef QT3_SUPPORT
     3649        case QEvent::ChildInsertedRequest:
     3650        case QEvent::ChildInserted:
     3651        case QEvent::LayoutHint:
     3652#endif
     3653        case QEvent::ChildRemoved:
     3654        case QEvent::UpdateRequest:
     3655        case QEvent::UpdateLater:
     3656        case QEvent::AccessibilityPrepare:
     3657        case QEvent::LocaleChange:
     3658        case QEvent::Style:
     3659        case QEvent::IconDrag:
     3660        case QEvent::StyleChange:
     3661        case QEvent::AccessibilityHelp:
     3662        case QEvent::AccessibilityDescription:
     3663        case QEvent::GraphicsSceneDragEnter:
     3664        case QEvent::GraphicsSceneDragMove:
     3665        case QEvent::GraphicsSceneDragLeave:
     3666        case QEvent::GraphicsSceneDrop:
     3667        case QEvent::DynamicPropertyChange:
     3668        case QEvent::NetworkReplyUpdated:
     3669            break;
     3670        default:
     3671            if (receiver->isWidgetType()) {
     3672                if (d->gestureManager->filterEvent(static_cast<QWidget *>(receiver), e))
     3673                    return true;
     3674            } else {
     3675                // a special case for events that go to QGesture objects.
     3676                // We pass the object to the gesture manager and it'll figure
     3677                // out if it's QGesture or not.
     3678                if (d->gestureManager->filterEvent(receiver, e))
     3679                    return true;
     3680            }
     3681        }
     3682    }
     3683
    35933684
    35943685    // User input and window activation makes tooltips sleep
     
    36043695    case QEvent::MouseButtonDblClick:
    36053696        d->toolTipFallAsleep.stop();
     3697        // fall-through
    36063698    case QEvent::Leave:
    36073699        d->toolTipWakeUp.stop();
     
    37193811
    37203812            if (e->spontaneous()) {
     3813#ifndef QT_NO_IM
     3814                QInputContext *ic = w->inputContext();
     3815                if (ic
     3816                        && w->testAttribute(Qt::WA_InputMethodEnabled)
     3817                        && ic->filterEvent(mouse))
     3818                    return true;
     3819#endif
    37213820
    37223821                if (e->type() == QEvent::MouseButtonPress) {
    3723                     QWidget *fw = w;
    3724                     while (fw) {
    3725                         if (fw->isEnabled()
    3726                             && QApplicationPrivate::shouldSetFocus(fw, Qt::ClickFocus)) {
    3727                             fw->setFocus(Qt::MouseFocusReason);
    3728                             break;
    3729                         }
    3730                         if (fw->isWindow())
    3731                             break;
    3732                         fw = fw->parentWidget();
    3733                     }
     3822                    QApplicationPrivate::giveFocusAccordingToFocusPolicy(w,
     3823                                                                         Qt::ClickFocus,
     3824                                                                         Qt::MouseFocusReason);
    37343825                }
    37353826
     3827                // ### Qt 5 These dynamic tool tips should be an OPT-IN feature. Some platforms
     3828                // like Mac OS X (probably others too), can optimize their views by not
     3829                // dispatching mouse move events. We have attributes to control hover,
     3830                // and mouse tracking, but as long as we are deciding to implement this
     3831                // feature without choice of opting-in or out, you ALWAYS have to have
     3832                // tracking enabled. Therefore, the other properties give a false sense of
     3833                // performance enhancement.
    37363834                if (e->type() == QEvent::MouseMove && mouse->buttons() == 0) {
    37373835                    d->toolTipWidget = w;
     
    37903888                while (w) {
    37913889                    if (w->testAttribute(Qt::WA_Hover) &&
    3792                         (!qApp->activePopupWidget() || qApp->activePopupWidget() == w->window())) {
     3890                        (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
    37933891                        QHoverEvent he(QEvent::HoverMove, relpos, relpos - diff);
    37943892                        d->notify_helper(w, &he);
     
    38133911
    38143912            if (e->spontaneous()) {
    3815                 QWidget *fw = w;
    3816                 while (fw) {
    3817                     if (fw->isEnabled()
    3818                         && QApplicationPrivate::shouldSetFocus(fw, Qt::WheelFocus)) {
    3819                         fw->setFocus(Qt::MouseFocusReason);
    3820                         break;
    3821                     }
    3822                     if (fw->isWindow())
    3823                         break;
    3824                     fw = fw->parentWidget();
    3825                 }
     3913                QApplicationPrivate::giveFocusAccordingToFocusPolicy(w,
     3914                                                                     Qt::WheelFocus,
     3915                                                                     Qt::MouseFocusReason);
    38263916            }
    38273917
     
    40284118        break;
    40294119#endif
    4030 
     4120    case QEvent::TouchBegin:
     4121    // Note: TouchUpdate and TouchEnd events are never propagated
     4122    {
     4123        QWidget *widget = static_cast<QWidget *>(receiver);
     4124        QTouchEvent *touchEvent = static_cast<QTouchEvent *>(e);
     4125        bool eventAccepted = touchEvent->isAccepted();
     4126        if (widget->testAttribute(Qt::WA_AcceptTouchEvents) && e->spontaneous()) {
     4127            // give the widget focus if the focus policy allows it
     4128            QApplicationPrivate::giveFocusAccordingToFocusPolicy(widget,
     4129                                                                 Qt::ClickFocus,
     4130                                                                 Qt::MouseFocusReason);
     4131        }
     4132
     4133        while (widget) {
     4134            // first, try to deliver the touch event
     4135            bool acceptTouchEvents = widget->testAttribute(Qt::WA_AcceptTouchEvents);
     4136            touchEvent->setWidget(widget);
     4137            touchEvent->setAccepted(acceptTouchEvents);
     4138            QWeakPointer<QWidget> p = widget;
     4139            res = acceptTouchEvents && d->notify_helper(widget, touchEvent);
     4140            eventAccepted = touchEvent->isAccepted();
     4141            if (p.isNull()) {
     4142                // widget was deleted
     4143                widget = 0;
     4144            } else {
     4145                widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, res && eventAccepted);
     4146            }
     4147            touchEvent->spont = false;
     4148            if (res && eventAccepted) {
     4149                // the first widget to accept the TouchBegin gets an implicit grab.
     4150                for (int i = 0; i < touchEvent->touchPoints().count(); ++i) {
     4151                    const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().at(i);
     4152                    d->widgetForTouchPointId[touchPoint.id()] = widget;
     4153                }
     4154                break;
     4155            } else if (p.isNull() || widget->isWindow() || widget->testAttribute(Qt::WA_NoMousePropagation)) {
     4156                break;
     4157            }
     4158            QPoint offset = widget->pos();
     4159            widget = widget->parentWidget();
     4160            touchEvent->setWidget(widget);
     4161            for (int i = 0; i < touchEvent->_touchPoints.size(); ++i) {
     4162                QTouchEvent::TouchPoint &pt = touchEvent->_touchPoints[i];
     4163                QRectF rect = pt.rect();
     4164                rect.moveCenter(offset);
     4165                pt.d->rect = rect;
     4166                pt.d->startPos = pt.startPos() + offset;
     4167                pt.d->lastPos = pt.lastPos() + offset;
     4168            }
     4169        }
     4170
     4171        touchEvent->setAccepted(eventAccepted);
     4172        break;
     4173    }
     4174    case QEvent::RequestSoftwareInputPanel:
     4175    case QEvent::CloseSoftwareInputPanel:
     4176#ifndef QT_NO_IM
     4177        if (receiver->isWidgetType()) {
     4178            QWidget *w = static_cast<QWidget *>(receiver);
     4179            QInputContext *ic = w->inputContext();
     4180            if (ic && ic->filterEvent(e)) {
     4181                break;
     4182            }
     4183        }
     4184#endif
     4185        res = d->notify_helper(receiver, e);
     4186        break;
     4187
     4188    case QEvent::NativeGesture:
     4189    {
     4190        // only propagate the first gesture event (after the GID_BEGIN)
     4191        QWidget *w = static_cast<QWidget *>(receiver);
     4192        while (w) {
     4193            e->ignore();
     4194            res = d->notify_helper(w, e);
     4195            if ((res && e->isAccepted()) || w->isWindow())
     4196                break;
     4197            w = w->parentWidget();
     4198        }
     4199        break;
     4200    }
     4201    case QEvent::Gesture:
     4202    case QEvent::GestureOverride:
     4203    {
     4204        if (receiver->isWidgetType()) {
     4205            QWidget *w = static_cast<QWidget *>(receiver);
     4206            QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(e);
     4207            QList<QGesture *> allGestures = gestureEvent->gestures();
     4208
     4209            bool eventAccepted = gestureEvent->isAccepted();
     4210            bool wasAccepted = eventAccepted;
     4211            while (w) {
     4212                // send only gestures the widget expects
     4213                QList<QGesture *> gestures;
     4214                QWidgetPrivate *wd = w->d_func();
     4215                for (int i = 0; i < allGestures.size();) {
     4216                    QGesture *g = allGestures.at(i);
     4217                    Qt::GestureType type = g->gestureType();
     4218                    QMap<Qt::GestureType, Qt::GestureFlags>::iterator contextit =
     4219                            wd->gestureContext.find(type);
     4220                    bool deliver = contextit != wd->gestureContext.end() &&
     4221                        (g->state() == Qt::GestureStarted || w == receiver ||
     4222                         (contextit.value() & Qt::ReceivePartialGestures));
     4223                    if (deliver) {
     4224                        allGestures.removeAt(i);
     4225                        gestures.append(g);
     4226                    } else {
     4227                        ++i;
     4228                    }
     4229                }
     4230                if (!gestures.isEmpty()) { // we have gestures for this w
     4231                    QGestureEvent ge(gestures);
     4232                    ge.t = gestureEvent->t;
     4233                    ge.spont = gestureEvent->spont;
     4234                    ge.m_accept = wasAccepted;
     4235                    ge.d_func()->accepted = gestureEvent->d_func()->accepted;
     4236                    res = d->notify_helper(w, &ge);
     4237                    gestureEvent->spont = false;
     4238                    eventAccepted = ge.isAccepted();
     4239                    for (int i = 0; i < gestures.size(); ++i) {
     4240                        QGesture *g = gestures.at(i);
     4241                        if ((res && eventAccepted) || (!eventAccepted && ge.isAccepted(g))) {
     4242                            // if the gesture was accepted, mark the target widget for it
     4243                            gestureEvent->d_func()->targetWidgets[g->gestureType()] = w;
     4244                            gestureEvent->setAccepted(g, true);
     4245                        } else if (!eventAccepted && !ge.isAccepted(g)) {
     4246                            // if the gesture was explicitly ignored by the application,
     4247                            // put it back so a parent can get it
     4248                            allGestures.append(g);
     4249                        }
     4250                    }
     4251                }
     4252                if (allGestures.isEmpty()) // everything delivered
     4253                    break;
     4254                if (w->isWindow())
     4255                    break;
     4256                w = w->parentWidget();
     4257            }
     4258            foreach (QGesture *g, allGestures)
     4259                gestureEvent->setAccepted(g, false);
     4260            gestureEvent->m_accept = false; // to make sure we check individual gestures
     4261        } else {
     4262            res = d->notify_helper(receiver, e);
     4263        }
     4264        break;
     4265    }
    40314266    default:
    40324267        res = d->notify_helper(receiver, e);
     
    40464281        QWidget *widget = static_cast<QWidget *>(receiver);
    40474282
    4048 #if !defined(Q_OS_WINCE) || (defined(GWES_ICONCURS) && !defined(QT_NO_CURSOR))
     4283#if !defined(Q_WS_WINCE) || (defined(GWES_ICONCURS) && !defined(QT_NO_CURSOR))
    40494284        // toggle HasMouse widget state on enter and leave
    40504285        if ((e->type() == QEvent::Enter || e->type() == QEvent::DragEnter) &&
    4051             (!qApp->activePopupWidget() || qApp->activePopupWidget() == widget->window()))
     4286            (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == widget->window()))
    40524287            widget->setAttribute(Qt::WA_UnderMouse, true);
    40534288        else if (e->type() == QEvent::Leave || e->type() == QEvent::DragLeave)
     
    40744309    \class QSessionManager
    40754310    \brief The QSessionManager class provides access to the session manager.
    4076 
    4077     \ingroup application
    4078     \ingroup environment
    40794311
    40804312    A session manager in a desktop environment (in which Qt GUI applications
     
    43764608    // We will use the following information to create the GUID
    43774609    // 1. absolute path to application
    4378     wchar_t tempFilename[512];
    4379     if (!GetModuleFileNameW(0, tempFilename, 512))
     4610    wchar_t tempFilename[MAX_PATH];
     4611    if (!GetModuleFileName(0, tempFilename, MAX_PATH))
    43804612        return S_FALSE;
    4381     unsigned int hash = qHash(QString::fromUtf16((const unsigned short *) tempFilename));
     4613    unsigned int hash = qHash(QString::fromWCharArray(tempFilename));
    43824614    guid->Data1 = hash;
    43834615    // 2. creation time of file
    4384     QFileInfo info(QString::fromUtf16((const unsigned short *) tempFilename));
     4616    QFileInfo info(QString::fromWCharArray(tempFilename));
    43854617    guid->Data2 = qHash(info.created().toTime_t());
    43864618    // 3. current system time
     
    44164648    CoCreateGuid(&guid);
    44174649    StringFromGUID2(guid, guidstr, 40);
    4418     id = QString::fromUtf16((ushort*)guidstr);
     4650    id = QString::fromWCharArray(guidstr);
    44194651    CoCreateGuid(&guid);
    44204652    StringFromGUID2(guid, guidstr, 40);
    4421     key = QString::fromUtf16((ushort*)guidstr);
     4653    key = QString::fromWCharArray(guidstr);
    44224654#endif
    44234655    d->sessionId = id;
     
    45794811    app.setWinStyleHighlightColor(color);
    45804812    \newcode
    4581     QPalette palette(qApp->palette());
     4813    QPalette palette(QApplication::palette());
    45824814    palette.setColor(QPalette::Highlight, color);
    4583     qApp->setPalette(palette);
     4815    QApplication::setPalette(palette);
    45844816    \endcode
    45854817*/
     
    46004832    \fn const QColor &QApplication::winStyleHighlightColor()
    46014833
    4602     Use qApp->palette().color(QPalette::Active, QPalette::Highlight) instead.
     4834    Use QApplication::palette().color(QPalette::Active, QPalette::Highlight) instead.
    46034835*/
    46044836
     
    46854917#ifdef QT_KEYPAD_NAVIGATION
    46864918/*!
     4919    Sets the kind of focus navigation Qt should use to \a mode.
     4920
     4921    This feature is available in Qt for Embedded Linux, Symbian and Windows CE
     4922    only.
     4923
     4924    \note On Windows CE this feature is disabled by default for touch device
     4925          mkspecs. To enable keypad navigation, build Qt with
     4926          QT_KEYPAD_NAVIGATION defined.
     4927
     4928    \note On Symbian, setting the mode to Qt::NavigationModeCursorAuto will enable a
     4929          virtual mouse cursor on non touchscreen devices, which is controlled
     4930          by the cursor keys if there is no analog pointer device.
     4931          On other platforms and on touchscreen devices, it has the same
     4932          meaning as Qt::NavigationModeNone.
     4933
     4934    \since 4.6
     4935
     4936    \sa keypadNavigationEnabled()
     4937*/
     4938void QApplication::setNavigationMode(Qt::NavigationMode mode)
     4939{
     4940#ifdef Q_OS_SYMBIAN
     4941    QApplicationPrivate::setNavigationMode(mode);
     4942#else
     4943    QApplicationPrivate::navigationMode = mode;
     4944#endif
     4945}
     4946
     4947/*!
     4948    Returns what kind of focus navigation Qt is using.
     4949
     4950    This feature is available in Qt for Embedded Linux, Symbian and Windows CE
     4951    only.
     4952
     4953    \note On Windows CE this feature is disabled by default for touch device
     4954          mkspecs. To enable keypad navigation, build Qt with
     4955          QT_KEYPAD_NAVIGATION defined.
     4956
     4957    \note On Symbian, the default mode is Qt::NavigationModeNone for touch
     4958          devices, and Qt::NavigationModeKeypadDirectional.
     4959
     4960    \since 4.6
     4961
     4962    \sa keypadNavigationEnabled()
     4963*/
     4964Qt::NavigationMode QApplication::navigationMode()
     4965{
     4966    return QApplicationPrivate::navigationMode;
     4967}
     4968
     4969/*!
    46874970    Sets whether Qt should use focus navigation suitable for use with a
    46884971    minimal keypad.
    46894972
    4690     If \a enable is true, Qt::Key_Up and Qt::Key_Down are used to change focus.
    4691 
    4692     This feature is available in Qt for Embedded Linux only.
    4693 
    4694     \sa keypadNavigationEnabled()
     4973    This feature is available in Qt for Embedded Linux, Symbian and Windows CE
     4974    only.
     4975
     4976    \note On Windows CE this feature is disabled by default for touch device
     4977          mkspecs. To enable keypad navigation, build Qt with
     4978          QT_KEYPAD_NAVIGATION defined.
     4979
     4980    \deprecated
     4981
     4982    \sa setNavigationMode()
    46954983*/
    46964984void QApplication::setKeypadNavigationEnabled(bool enable)
    46974985{
    4698     QApplicationPrivate::keypadNavigation = enable;
     4986    if (enable) {
     4987#ifdef Q_OS_SYMBIAN
     4988        QApplication::setNavigationMode(Qt::NavigationModeKeypadDirectional);
     4989#else
     4990        QApplication::setNavigationMode(Qt::NavigationModeKeypadTabOrder);
     4991#endif
     4992    }
     4993    else {
     4994        QApplication::setNavigationMode(Qt::NavigationModeNone);
     4995    }
    46994996}
    47004997
    47014998/*!
    47024999    Returns true if Qt is set to use keypad navigation; otherwise returns
    4703     false. The default is false.
    4704 
    4705     This feature is available in Qt for Embedded Linux only.
    4706 
    4707     \sa setKeypadNavigationEnabled()
     5000    false.  The default value is true on Symbian, but false on other platforms.
     5001
     5002    This feature is available in Qt for Embedded Linux, Symbian and Windows CE
     5003    only.
     5004
     5005    \note On Windows CE this feature is disabled by default for touch device
     5006          mkspecs. To enable keypad navigation, build Qt with
     5007          QT_KEYPAD_NAVIGATION defined.
     5008
     5009    \deprecated
     5010
     5011    \sa navigationMode()
    47085012*/
    47095013bool QApplication::keypadNavigationEnabled()
    47105014{
    4711     return QApplicationPrivate::keypadNavigation;
     5015    return QApplicationPrivate::navigationMode == Qt::NavigationModeKeypadTabOrder ||
     5016        QApplicationPrivate::navigationMode == Qt::NavigationModeKeypadDirectional;
    47125017}
    47135018#endif
     
    47275032    application icon to bounce in the dock.
    47285033
    4729     On Windows this causes the window's taskbar entry to flash for a time. If
     5034    On Windows, this causes the window's taskbar entry to flash for a time. If
    47305035    \a msec is zero, the flashing will stop and the taskbar entry will turn a
    47315036    different color (currently orange).
     
    47445049    flash time, then hidden for the same amount of time, but this may vary.
    47455050
    4746     The default value on X11 is 1000 milliseconds. On Windows, the control
    4747     panel value is used. Widgets should not cache this value since it may be
    4748     changed at any time by the user changing the global desktop settings.
    4749 
    4750     \note On Microsoft Windows, setting this property sets the cursor flash
    4751     time for all applications.
     5051    The default value on X11 is 1000 milliseconds. On Windows, the
     5052    \gui{Control Panel} value is used and setting this property sets the cursor
     5053    flash time for all applications.
     5054
     5055    We recommend that widgets do not cache this value as it may change at any
     5056    time if the user changes the global desktop settings.
    47525057*/
    47535058
    47545059/*!
    47555060    \property QApplication::doubleClickInterval
    4756     \brief the time limit in milliseconds that distinguishes a double click from two
    4757     consecutive mouse clicks
    4758 
    4759     The default value on X11 is 400 milliseconds. On Windows and Mac OS X, the
    4760     operating system's value is used.
    4761 
    4762     On Microsoft Windows, calling this function sets the double click interval
    4763     for all applications.
     5061    \brief the time limit in milliseconds that distinguishes a double click
     5062    from two consecutive mouse clicks
     5063
     5064    The default value on X11 is 400 milliseconds. On Windows and Mac OS, the
     5065    operating system's value is used. However, on Windows and Symbian OS,
     5066    calling this function sets the double click interval for all applications.
    47645067*/
    47655068
     
    47705073    \since 4.2
    47715074
    4772     The default value on X11 is 400 milliseconds. On Windows and Mac OS X, the
     5075    The default value on X11 is 400 milliseconds. On Windows and Mac OS, the
    47735076    operating system's value is used.
    47745077*/
     
    48355138    is an alternative.
    48365139
    4837     For X11, this function also resizes and moves the main widget according
     5140    On X11, this function also resizes and moves the main widget according
    48385141    to the \e -geometry command-line option, so you should set the default
    48395142    geometry (using \l QWidget::setGeometry()) before calling setMainWidget().
     
    48645167    pushes the cursor onto the stack, and restoreOverrideCursor() pops the
    48655168    active cursor off the stack. changeOverrideCursor() changes the curently
    4866     active application override cursor. Every setOverrideCursor() must
    4867     eventually be followed by a corresponding restoreOverrideCursor(),
    4868     otherwise the stack will never be emptied.
     5169    active application override cursor.
     5170
     5171    Every setOverrideCursor() must eventually be followed by a corresponding
     5172    restoreOverrideCursor(), otherwise the stack will never be emptied.
    48695173
    48705174    Example:
     
    49205224        return;
    49215225    }
    4922     if (d->inputContext)
    4923         delete d->inputContext;
     5226    delete d->inputContext;
    49245227    d->inputContext = inputContext;
    49255228#endif
     
    49365239    Q_D(const QApplication);
    49375240    Q_UNUSED(d);// only static members being used.
     5241    if (QApplicationPrivate::is_app_closing)
     5242        return d->inputContext;
    49385243#ifdef Q_WS_X11
    49395244    if (!X11)
     
    49465251            qic = QInputContextFactory::create(QLatin1String("xim"), that);
    49475252        that->d_func()->inputContext = qic;
     5253    }
     5254#elif defined(Q_WS_S60)
     5255    if (!d->inputContext) {
     5256        QApplication *that = const_cast<QApplication *>(this);
     5257        that->d_func()->inputContext = QInputContextFactory::create(QString::fromLatin1("coefep"), that);
    49485258    }
    49495259#endif
     
    49675277    if (X11->desktopEnvironment == DE_CDE)
    49685278        platform |= KB_CDE;
     5279#elif defined(Q_OS_SYMBIAN)
     5280    platform = KB_S60;
    49695281#endif
    49705282    return platform;
     
    49995311        return Qt::LeftToRight;
    50005312    return qt_keymapper_private()->keyboardInputDirection;
     5313}
     5314
     5315void QApplicationPrivate::giveFocusAccordingToFocusPolicy(QWidget *widget,
     5316                                                          Qt::FocusPolicy focusPolicy,
     5317                                                          Qt::FocusReason focusReason)
     5318{
     5319    QWidget *focusWidget = widget;
     5320    while (focusWidget) {
     5321        if (focusWidget->isEnabled()
     5322            && QApplicationPrivate::shouldSetFocus(focusWidget, focusPolicy)) {
     5323            focusWidget->setFocus(focusReason);
     5324            break;
     5325        }
     5326        if (focusWidget->isWindow())
     5327            break;
     5328        focusWidget = focusWidget->parentWidget();
     5329    }
    50015330}
    50025331
     
    50145343}
    50155344
     5345/*! \fn QDecoration &QApplication::qwsDecoration()
     5346    Return the QWSDecoration used for decorating windows.
     5347
     5348    \warning This method is non-portable. It is only available in
     5349    Qt for Embedded Linux.
     5350
     5351    \sa QDecoration
     5352*/
     5353
     5354/*!
     5355    \fn void QApplication::qwsSetDecoration(QDecoration *decoration)
     5356
     5357    Sets the QDecoration derived class to use for decorating the
     5358    windows used by Qt for Embedded Linux to the \a decoration
     5359    specified.
     5360
     5361    This method is non-portable. It is only available in Qt for Embedded Linux.
     5362
     5363    \sa QDecoration
     5364*/
     5365
     5366/*! \fn QDecoration* QApplication::qwsSetDecoration(const QString &decoration)
     5367    \overload
     5368
     5369    Requests a QDecoration object for \a decoration from the
     5370    QDecorationFactory.
     5371
     5372    The string must be one of the QDecorationFactory::keys(). Keys are case
     5373    insensitive.
     5374
     5375    A later call to the QApplication constructor will override the requested
     5376    style when a "-style" option is passed in as a commandline parameter.
     5377
     5378    Returns 0 if an unknown \a decoration is passed, otherwise the QStyle object
     5379    returned is set as the application's GUI style.
     5380*/
     5381
     5382/*!
     5383    \fn bool QApplication::qwsEventFilter(QWSEvent *event)
     5384
     5385    This virtual function is only implemented under Qt for Embedded Linux.
     5386
     5387    If you create an application that inherits QApplication and
     5388    reimplement this function, you get direct access to all QWS (Q
     5389    Window System) events that the are received from the QWS master
     5390    process. The events are passed in the \a event parameter.
     5391
     5392    Return true if you want to stop the event from being processed.
     5393    Return false for normal event dispatching. The default
     5394    implementation returns false.
     5395*/
     5396
     5397/*! \fn void QApplication::qwsSetCustomColors(QRgb *colorTable, int start, int numColors)
     5398    Set Qt for Embedded Linux custom color table.
     5399
     5400    Qt for Embedded Linux on 8-bpp displays allocates a standard 216 color cube.
     5401    The remaining 40 colors may be used by setting a custom color
     5402    table in the QWS master process before any clients connect.
     5403
     5404    \a colorTable is an array of up to 40 custom colors. \a start is
     5405    the starting index (0-39) and \a numColors is the number of colors
     5406    to be set (1-40).
     5407
     5408    This method is non-portable. It is available \e only in
     5409    Qt for Embedded Linux.
     5410
     5411    \note The custom colors will not be used by the default screen
     5412    driver. To make use of the new colors, implement a custom screen
     5413    driver, or use QDirectPainter.
     5414*/
     5415
     5416/*! \fn int QApplication::qwsProcessEvent(QWSEvent* event)
     5417    \internal
     5418*/
     5419
     5420/*! \fn int QApplication::x11ClientMessage(QWidget* w, XEvent* event, bool passive_only)
     5421    \internal
     5422*/
     5423
     5424/*! \fn int QApplication::x11ProcessEvent(XEvent* event)
     5425    This function does the core processing of individual X
     5426    \a{event}s, normally by dispatching Qt events to the right
     5427    destination.
     5428
     5429    It returns 1 if the event was consumed by special handling, 0 if
     5430    the \a event was consumed by normal handling, and -1 if the \a
     5431    event was for an unrecognized widget.
     5432
     5433    \sa x11EventFilter()
     5434*/
     5435
     5436/*!
     5437    \fn bool QApplication::x11EventFilter(XEvent *event)
     5438
     5439    \warning This virtual function is only implemented under X11.
     5440
     5441    If you create an application that inherits QApplication and
     5442    reimplement this function, you get direct access to all X events
     5443    that the are received from the X server. The events are passed in
     5444    the \a event parameter.
     5445
     5446    Return true if you want to stop the event from being processed.
     5447    Return false for normal event dispatching. The default
     5448    implementation returns false.
     5449
     5450    It is only the directly addressed messages that are filtered.
     5451    You must install an event filter directly on the event
     5452    dispatcher, which is returned by
     5453    QAbstractEventDispatcher::instance(), to handle system wide
     5454    messages.
     5455
     5456    \sa x11ProcessEvent()
     5457*/
     5458
     5459/*! \fn void QApplication::winFocus(QWidget *widget, bool gotFocus)
     5460    \internal
     5461    \since 4.1
     5462
     5463    If \a gotFocus is true, \a widget will become the active window.
     5464    Otherwise the active window is reset to 0.
     5465*/
     5466
     5467/*! \fn void QApplication::winMouseButtonUp()
     5468  \internal
     5469 */
     5470
     5471/*! \fn void QApplication::syncX()
     5472  Synchronizes with the X server in the X11 implementation.
     5473  This normally takes some time. Does nothing on other platforms.
     5474*/
     5475
     5476void QApplicationPrivate::updateTouchPointsForWidget(QWidget *widget, QTouchEvent *touchEvent)
     5477{
     5478    for (int i = 0; i < touchEvent->touchPoints().count(); ++i) {
     5479        QTouchEvent::TouchPoint &touchPoint = touchEvent->_touchPoints[i];
     5480
     5481        // preserve the sub-pixel resolution
     5482        QRectF rect = touchPoint.screenRect();
     5483        const QPointF screenPos = rect.center();
     5484        const QPointF delta = screenPos - screenPos.toPoint();
     5485
     5486        rect.moveCenter(widget->mapFromGlobal(screenPos.toPoint()) + delta);
     5487        touchPoint.d->rect = rect;
     5488        if (touchPoint.state() == Qt::TouchPointPressed) {
     5489            touchPoint.d->startPos = widget->mapFromGlobal(touchPoint.startScreenPos().toPoint()) + delta;
     5490            touchPoint.d->lastPos = widget->mapFromGlobal(touchPoint.lastScreenPos().toPoint()) + delta;
     5491        }
     5492    }
     5493}
     5494
     5495void QApplicationPrivate::initializeMultitouch()
     5496{
     5497    widgetForTouchPointId.clear();
     5498    appCurrentTouchPoints.clear();
     5499
     5500    initializeMultitouch_sys();
     5501}
     5502
     5503void QApplicationPrivate::cleanupMultitouch()
     5504{
     5505    cleanupMultitouch_sys();
     5506
     5507    widgetForTouchPointId.clear();
     5508    appCurrentTouchPoints.clear();
     5509}
     5510
     5511int QApplicationPrivate::findClosestTouchPointId(const QPointF &screenPos)
     5512{
     5513    int closestTouchPointId = -1;
     5514    qreal closestDistance = qreal(0.);
     5515    foreach (const QTouchEvent::TouchPoint &touchPoint, appCurrentTouchPoints) {
     5516        qreal distance = QLineF(screenPos, touchPoint.screenPos()).length();
     5517        if (closestTouchPointId == -1 || distance < closestDistance) {
     5518            closestTouchPointId = touchPoint.id();
     5519            closestDistance = distance;
     5520        }
     5521    }
     5522    return closestTouchPointId;
     5523}
     5524
     5525void QApplicationPrivate::translateRawTouchEvent(QWidget *window,
     5526                                                 QTouchEvent::DeviceType deviceType,
     5527                                                 const QList<QTouchEvent::TouchPoint> &touchPoints)
     5528{
     5529    QApplicationPrivate *d = self;
     5530    typedef QPair<Qt::TouchPointStates, QList<QTouchEvent::TouchPoint> > StatesAndTouchPoints;
     5531    QHash<QWidget *, StatesAndTouchPoints> widgetsNeedingEvents;
     5532
     5533    for (int i = 0; i < touchPoints.count(); ++i) {
     5534        QTouchEvent::TouchPoint touchPoint = touchPoints.at(i);
     5535        // explicitly detach from the original touch point that we got, so even
     5536        // if the touchpoint structs are reused, we will make a copy that we'll
     5537        // deliver to the user (which might want to store the struct for later use).
     5538        touchPoint.d = touchPoint.d->detach();
     5539
     5540        // update state
     5541        QWeakPointer<QWidget> widget;
     5542        switch (touchPoint.state()) {
     5543        case Qt::TouchPointPressed:
     5544        {
     5545            if (deviceType == QTouchEvent::TouchPad) {
     5546                // on touch-pads, send all touch points to the same widget
     5547                widget = d->widgetForTouchPointId.isEmpty()
     5548                         ? QWeakPointer<QWidget>()
     5549                         : d->widgetForTouchPointId.constBegin().value();
     5550            }
     5551
     5552            if (!widget) {
     5553                // determine which widget this event will go to
     5554                if (!window)
     5555                    window = QApplication::topLevelAt(touchPoint.screenPos().toPoint());
     5556                if (!window)
     5557                    continue;
     5558                widget = window->childAt(window->mapFromGlobal(touchPoint.screenPos().toPoint()));
     5559                if (!widget)
     5560                    widget = window;
     5561            }
     5562
     5563            if (deviceType == QTouchEvent::TouchScreen) {
     5564                int closestTouchPointId = d->findClosestTouchPointId(touchPoint.screenPos());
     5565                QWidget *closestWidget = d->widgetForTouchPointId.value(closestTouchPointId).data();
     5566                if (closestWidget
     5567                    && (widget.data()->isAncestorOf(closestWidget) || closestWidget->isAncestorOf(widget.data()))) {
     5568                    widget = closestWidget;
     5569                }
     5570            }
     5571
     5572            d->widgetForTouchPointId[touchPoint.id()] = widget;
     5573            touchPoint.d->startScreenPos = touchPoint.screenPos();
     5574            touchPoint.d->lastScreenPos = touchPoint.screenPos();
     5575            touchPoint.d->startNormalizedPos = touchPoint.normalizedPos();
     5576            touchPoint.d->lastNormalizedPos = touchPoint.normalizedPos();
     5577            if (touchPoint.pressure() < qreal(0.))
     5578                touchPoint.d->pressure = qreal(1.);
     5579
     5580            d->appCurrentTouchPoints.insert(touchPoint.id(), touchPoint);
     5581            break;
     5582        }
     5583        case Qt::TouchPointReleased:
     5584        {
     5585            widget = d->widgetForTouchPointId.take(touchPoint.id());
     5586            if (!widget)
     5587                continue;
     5588
     5589            QTouchEvent::TouchPoint previousTouchPoint = d->appCurrentTouchPoints.take(touchPoint.id());
     5590            touchPoint.d->startScreenPos = previousTouchPoint.startScreenPos();
     5591            touchPoint.d->lastScreenPos = previousTouchPoint.screenPos();
     5592            touchPoint.d->startPos = previousTouchPoint.startPos();
     5593            touchPoint.d->lastPos = previousTouchPoint.pos();
     5594            touchPoint.d->startNormalizedPos = previousTouchPoint.startNormalizedPos();
     5595            touchPoint.d->lastNormalizedPos = previousTouchPoint.normalizedPos();
     5596            if (touchPoint.pressure() < qreal(0.))
     5597                touchPoint.d->pressure = qreal(0.);
     5598            break;
     5599        }
     5600        default:
     5601            widget = d->widgetForTouchPointId.value(touchPoint.id());
     5602            if (!widget)
     5603                continue;
     5604
     5605            Q_ASSERT(d->appCurrentTouchPoints.contains(touchPoint.id()));
     5606            QTouchEvent::TouchPoint previousTouchPoint = d->appCurrentTouchPoints.value(touchPoint.id());
     5607            touchPoint.d->startScreenPos = previousTouchPoint.startScreenPos();
     5608            touchPoint.d->lastScreenPos = previousTouchPoint.screenPos();
     5609            touchPoint.d->startPos = previousTouchPoint.startPos();
     5610            touchPoint.d->lastPos = previousTouchPoint.pos();
     5611            touchPoint.d->startNormalizedPos = previousTouchPoint.startNormalizedPos();
     5612            touchPoint.d->lastNormalizedPos = previousTouchPoint.normalizedPos();
     5613            if (touchPoint.pressure() < qreal(0.))
     5614                touchPoint.d->pressure = qreal(1.);
     5615            d->appCurrentTouchPoints[touchPoint.id()] = touchPoint;
     5616            break;
     5617        }
     5618        Q_ASSERT(widget.data() != 0);
     5619
     5620        // make the *scene* functions return the same as the *screen* functions
     5621        touchPoint.d->sceneRect = touchPoint.screenRect();
     5622        touchPoint.d->startScenePos = touchPoint.startScreenPos();
     5623        touchPoint.d->lastScenePos = touchPoint.lastScreenPos();
     5624
     5625        StatesAndTouchPoints &maskAndPoints = widgetsNeedingEvents[widget.data()];
     5626        maskAndPoints.first |= touchPoint.state();
     5627        if (touchPoint.isPrimary())
     5628            maskAndPoints.first |= Qt::TouchPointPrimary;
     5629        maskAndPoints.second.append(touchPoint);
     5630    }
     5631
     5632    if (widgetsNeedingEvents.isEmpty())
     5633        return;
     5634
     5635    QHash<QWidget *, StatesAndTouchPoints>::ConstIterator it = widgetsNeedingEvents.constBegin();
     5636    const QHash<QWidget *, StatesAndTouchPoints>::ConstIterator end = widgetsNeedingEvents.constEnd();
     5637    for (; it != end; ++it) {
     5638        QWidget *widget = it.key();
     5639        if (!QApplicationPrivate::tryModalHelper(widget, 0))
     5640            continue;
     5641
     5642        QEvent::Type eventType;
     5643        switch (it.value().first & Qt::TouchPointStateMask) {
     5644        case Qt::TouchPointPressed:
     5645            eventType = QEvent::TouchBegin;
     5646            break;
     5647        case Qt::TouchPointReleased:
     5648            eventType = QEvent::TouchEnd;
     5649            break;
     5650        case Qt::TouchPointStationary:
     5651            // don't send the event if nothing changed
     5652            continue;
     5653        default:
     5654            eventType = QEvent::TouchUpdate;
     5655            break;
     5656        }
     5657
     5658        QTouchEvent touchEvent(eventType,
     5659                               deviceType,
     5660                               QApplication::keyboardModifiers(),
     5661                               it.value().first,
     5662                               it.value().second);
     5663        updateTouchPointsForWidget(widget, &touchEvent);
     5664
     5665        switch (touchEvent.type()) {
     5666        case QEvent::TouchBegin:
     5667        {
     5668            // if the TouchBegin handler recurses, we assume that means the event
     5669            // has been implicitly accepted and continue to send touch events
     5670            widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent);
     5671            (void ) QApplication::sendSpontaneousEvent(widget, &touchEvent);
     5672            break;
     5673        }
     5674        default:
     5675            if (widget->testAttribute(Qt::WA_WState_AcceptedTouchBeginEvent)) {
     5676                if (touchEvent.type() == QEvent::TouchEnd)
     5677                    widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent, false);
     5678                (void) QApplication::sendSpontaneousEvent(widget, &touchEvent);
     5679            }
     5680            break;
     5681        }
     5682    }
     5683}
     5684
     5685Q_GUI_EXPORT void qt_translateRawTouchEvent(QWidget *window,
     5686                                            QTouchEvent::DeviceType deviceType,
     5687                                            const QList<QTouchEvent::TouchPoint> &touchPoints)
     5688{
     5689    QApplicationPrivate::translateRawTouchEvent(window, deviceType, touchPoints);
     5690}
     5691
     5692QGestureManager* QGestureManager::instance()
     5693{
     5694    QApplicationPrivate *qAppPriv = QApplicationPrivate::instance();
     5695    if (!qAppPriv->gestureManager)
     5696        qAppPriv->gestureManager = new QGestureManager(qApp);
     5697    return qAppPriv->gestureManager;
     5698}
     5699
    50165700QT_END_NAMESPACE
    50175701
Note: See TracChangeset for help on using the changeset viewer.