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/qwidget.cpp

    r467 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**
     
    8383#include "private/qinputcontext_p.h"
    8484#include "qfileinfo.h"
     85#include "private/qsoftkeymanager_p.h"
    8586
    8687#if defined (Q_WS_WIN)
     
    9798#endif
    9899
     100#include <private/qgraphicseffect_p.h>
    99101#include <private/qwindowsurface_p.h>
    100102#include <private/qbackingstore_p.h>
     
    103105#endif
    104106#include <private/qpaintengine_raster_p.h>
     107
     108#if defined(Q_OS_SYMBIAN)
     109#include "private/qt_s60_p.h"
     110#endif
    105111
    106112#include "qwidget_p.h"
     
    112118#include "QtGui/qabstractscrollarea.h"
    113119#include "private/qabstractscrollarea_p.h"
     120#include "private/qevent_p.h"
    114121
    115122#include "private/qgraphicssystem_p.h"
     123#include "private/qgesturemanager_p.h"
    116124
    117125// widget/widget data creation count
     
    147155}
    148156
    149 /*!
    150     \internal
    151 
    152     Returns true if \a p or any of its parents enable the
    153     Qt::BypassGraphicsProxyWidget window flag. Used in QWidget::show() and
    154     QWidget::setParent() to determine whether it's necessary to embed the
    155     widget into a QGraphicsProxyWidget or not.
    156 */
    157 static inline bool bypassGraphicsProxyWidget(QWidget *p)
    158 {
    159     while (p) {
    160         if (p->windowFlags() & Qt::BypassGraphicsProxyWidget)
    161             return true;
    162         p = p->parentWidget();
    163     }
    164     return false;
    165 }
    166 
    167157#ifdef Q_WS_MAC
    168158#  define QT_NO_PAINT_DEBUG
     
    172162extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp
    173163
    174 QWidgetPrivate::QWidgetPrivate(int version) :
    175         QObjectPrivate(version), extra(0), focus_child(0)
    176         ,layout(0), widgetItem(0)
    177         ,leftmargin(0), topmargin(0), rightmargin(0), bottommargin(0)
    178         ,leftLayoutItemMargin(0), topLayoutItemMargin(0), rightLayoutItemMargin(0)
    179         ,bottomLayoutItemMargin(0)
    180         ,fg_role(QPalette::NoRole)
    181         ,bg_role(QPalette::NoRole)
    182         ,hd(0)
    183         ,dirty(0)
    184         ,needsFlush(0)
    185         ,dirtyOpaqueChildren(1)
    186         ,isOpaque(0)
    187         ,inDirtyList(0)
    188         ,isScrolled(0)
    189         ,isMoved(0)
    190 #if defined(Q_WS_WIN) || defined(Q_WS_PM)
    191         ,noPaintOnScreen(0)
    192 #endif
    193         ,inheritedFontResolveMask(0)
    194         ,inheritedPaletteResolveMask(0)
     164QWidgetPrivate::QWidgetPrivate(int version)
     165    : QObjectPrivate(version)
     166      , extra(0)
     167      , focus_next(0)
     168      , focus_prev(0)
     169      , focus_child(0)
     170      , layout(0)
     171      , needsFlush(0)
     172      , redirectDev(0)
     173      , widgetItem(0)
     174      , extraPaintEngine(0)
     175      , polished(0)
     176      , graphicsEffect(0)
     177#if !defined(QT_NO_IM)
     178      , imHints(Qt::ImhNone)
     179#endif
     180      , inheritedFontResolveMask(0)
     181      , inheritedPaletteResolveMask(0)
     182      , leftmargin(0)
     183      , topmargin(0)
     184      , rightmargin(0)
     185      , bottommargin(0)
     186      , leftLayoutItemMargin(0)
     187      , topLayoutItemMargin(0)
     188      , rightLayoutItemMargin(0)
     189      , bottomLayoutItemMargin(0)
     190      , hd(0)
     191      , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred)
     192      , fg_role(QPalette::NoRole)
     193      , bg_role(QPalette::NoRole)
     194      , dirtyOpaqueChildren(1)
     195      , isOpaque(0)
     196      , inDirtyList(0)
     197      , isScrolled(0)
     198      , isMoved(0)
     199      , usesDoubleBufferedGLContext(0)
    195200#if defined(Q_WS_X11)
    196         ,picture(0)
    197 #endif
    198 #ifdef Q_WS_MAC
    199         ,needWindowChange(0)
    200         ,isGLWidget(0)
    201 #endif
    202         ,polished(0)
    203 
    204         , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred)
    205         , redirectDev(0)
     201      , picture(0)
     202#elif defined(Q_WS_PM)
     203      , noPaintOnScreen(0)
     204#elif defined(Q_WS_WIN)
     205      , noPaintOnScreen(0)
     206      , nativeGesturePanEnabled(0)
     207#elif defined(Q_WS_MAC)
     208      , needWindowChange(0)
     209      , isGLWidget(0)
     210      , window_event(0)
     211      , qd_hd(0)
     212#endif
    206213{
    207214    if (!qApp) {
     
    229236    if (extra)
    230237        deleteExtra();
     238
     239#ifndef QT_NO_GRAPHICSEFFECT
     240    delete graphicsEffect;
     241#endif //QT_NO_GRAPHICSEFFECT
    231242}
    232243
     
    362373    change focus.
    363374
    364     This feature is only available in Qt for Embedded Linux.
     375    This feature is only available in Qt for Embedded Linux and Qt
     376    for Symbian.
    365377
    366378    \sa hasEditFocus(), QApplication::keypadNavigationEnabled()
     
    446458
    447459    \ingroup basicwidgets
    448     \mainclass
     460
    449461
    450462    The widget is the atom of the user interface: it receives mouse, keyboard
     
    497509
    498510    If you want to use a QWidget to hold child widgets you will usually want to
    499     add a layout to the parent QWidget. See \l{Layout Classes} for more
     511    add a layout to the parent QWidget. See \l{Layout Management} for more
    500512    information.
    501513
     
    855867    \o X11: This feature relies on the use of an X server that supports ARGB visuals
    856868    and a compositing window manager.
    857     \o Windows: This feature requires Windows 2000 or later. The widget needs to have
    858     the Qt::FramelessWindowHint window flag set for the translucency to work.
     869    \o Windows: The widget needs to have the Qt::FramelessWindowHint window flag set
     870    for the translucency to work.
    859871    \endlist
    860872
     
    882894
    883895    \sa QEvent, QPainter, QGridLayout, QBoxLayout
    884 */
    885 
    886 QWidgetMapper *QWidgetPrivate::mapper = 0;                // widget with wid
    887 QWidgetSet *QWidgetPrivate::uncreatedWidgets = 0;         // widgets with no wid
     896
     897    \section1 Softkeys
     898
     899    Since Qt 4.6, Softkeys are usually physical keys on a device that have a corresponding label or
     900    other visual representation on the screen that is generally located next to its
     901    physical counterpart. They are most often found on mobile phone platforms. In
     902    modern touch based user interfaces it is also possible to have softkeys that do
     903    not correspond to any physical keys. Softkeys differ from other onscreen labels
     904    in that they are contextual.
     905
     906    In Qt, contextual softkeys are added to a widget by calling addAction() and
     907    passing a \c QAction with a softkey role set on it. When the widget
     908    containing the softkey actions has focus, its softkeys should appear in
     909    the user interface. Softkeys are discovered by traversing the widget
     910    hierarchy so it is possible to define a single set of softkeys that are
     911    present at all times by calling addAction() for a given top level widget.
     912
     913    On some platforms, this concept overlaps with \c QMenuBar such that if no
     914    other softkeys are found and the top level widget is a QMainWindow containing
     915    a QMenuBar, the menubar actions may appear on one of the softkeys.
     916
     917    Note: Currently softkeys are only supported on the Symbian Platform.
     918
     919    \sa addAction(), QAction, QMenuBar
     920
     921*/
     922
     923QWidgetMapper *QWidgetPrivate::mapper = 0;          // widget with wid
     924QWidgetSet *QWidgetPrivate::allWidgets = 0;         // widgets with no wid
    888925
    889926
     
    925962*/
    926963
     964struct QWidgetExceptionCleaner
     965{
     966    /* this cleans up when the constructor throws an exception */
     967    static inline void cleanup(QWidget *that, QWidgetPrivate *d)
     968    {
     969#ifdef QT_NO_EXCEPTIONS
     970        Q_UNUSED(that);
     971        Q_UNUSED(d);
     972#else
     973        QWidgetPrivate::allWidgets->remove(that);
     974        if (d->focus_next != that) {
     975            if (d->focus_next)
     976                d->focus_next->d_func()->focus_prev = d->focus_prev;
     977            if (d->focus_prev)
     978                d->focus_prev->d_func()->focus_next = d->focus_next;
     979        }
     980#endif
     981    }
     982};
     983
    927984/*!
    928985    Constructs a widget which is a child of \a parent, with  widget
     
    9541011    : QObject(*new QWidgetPrivate, 0), QPaintDevice()
    9551012{
    956     d_func()->init(parent, f);
     1013    QT_TRY {
     1014        d_func()->init(parent, f);
     1015    } QT_CATCH(...) {
     1016        QWidgetExceptionCleaner::cleanup(this, d_func());
     1017        QT_RETHROW;
     1018    }
    9571019}
    9581020
     
    9651027    : QObject(*new QWidgetPrivate, 0), QPaintDevice()
    9661028{
    967     d_func()->init(parent , f);
    968     setObjectName(QString::fromAscii(name));
     1029    QT_TRY {
     1030        d_func()->init(parent , f);
     1031        setObjectName(QString::fromAscii(name));
     1032    } QT_CATCH(...) {
     1033        QWidgetExceptionCleaner::cleanup(this, d_func());
     1034        QT_RETHROW;
     1035    }
    9691036}
    9701037#endif
     
    9751042    : QObject(dd, 0), QPaintDevice()
    9761043{
    977     d_func()->init(parent, f);
     1044    Q_D(QWidget);
     1045    QT_TRY {
     1046        d->init(parent, f);
     1047    } QT_CATCH(...) {
     1048        QWidgetExceptionCleaner::cleanup(this, d_func());
     1049        QT_RETHROW;
     1050    }
    9781051}
    9791052
     
    10311104        ; // don't modify window flags if the user explicitely set them.
    10321105    else if (type == Qt::Dialog || type == Qt::Sheet)
    1033 #ifndef Q_OS_WINCE
     1106#ifndef Q_WS_WINCE
    10341107        flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint | Qt::WindowCloseButtonHint;
    10351108#else
     
    10471120{
    10481121    Q_Q(QWidget);
    1049     if (qApp->type() == QApplication::Tty)
     1122    if (QApplication::type() == QApplication::Tty)
    10501123        qFatal("QWidget: Cannot create a QWidget when no GUI is being used");
    10511124
    1052     Q_ASSERT(uncreatedWidgets);
    1053     uncreatedWidgets->insert(q);
     1125    Q_ASSERT(allWidgets);
     1126    allWidgets->insert(q);
    10541127
    10551128    QWidget *desktopWidget = 0;
     
    10621135
    10631136#ifndef QT_NO_THREAD
    1064     if (!q->parent()) {
     1137    if (!parent) {
    10651138        Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget",
    10661139                   "Widgets must be created in the GUI thread.");
     
    10971170    if (f & Qt::MSWindowsOwnDC)
    10981171        q->setAttribute(Qt::WA_NativeWindow);
    1099 
    1100 #ifdef Q_OS_WINCE
    1101     data.window_state_internal = 0;
    1102 #endif
    11031172
    11041173    q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute()
     
    12571326
    12581327    // a real toplevel window needs a backing store
    1259     if (isWindow()) {
     1328    if (isWindow() && windowType() != Qt::Desktop) {
    12601329        delete d->topData()->backingStore;
    12611330        // QWidgetBackingStore will check this variable, hence it must be 0
     
    12801349    if (isWindow() && !d->topData()->iconText.isEmpty())
    12811350        d->setWindowIconText_helper(d->topData()->iconText);
     1351    if (isWindow() && !d->topData()->caption.isEmpty())
     1352        d->setWindowTitle_helper(d->topData()->caption);
    12821353    if (windowType() != Qt::Desktop) {
    12831354        d->updateSystemBackground();
     
    13401411    if (QApplicationPrivate::main_widget == this) {        // reset main widget
    13411412        QApplicationPrivate::main_widget = 0;
    1342         qApp->quit();
    1343     }
    1344 #endif
    1345 
    1346     clearFocus();
     1413        QApplication::quit();
     1414    }
     1415#endif
     1416
     1417    QT_TRY {
     1418        clearFocus();
     1419    } QT_CATCH(...) {
     1420        // swallow this problem because we are in a destructor
     1421    }
    13471422
    13481423    d->setDirtyOpaqueRegion();
    13491424
    1350     if (isWindow() && isVisible() && internalWinId())
    1351         hide();
    1352 #if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
    1353     else if (!internalWinId() && isVisible())
     1425    if (isWindow() && isVisible() && internalWinId()) {
     1426        QT_TRY {
     1427            d->close_helper(QWidgetPrivate::CloseNoEvent);
     1428        } QT_CATCH(...) {
     1429            // if we're out of memory, at least hide the window.
     1430            QT_TRY {
     1431                hide();
     1432            } QT_CATCH(...) {
     1433                // and if that also doesn't work, then give up
     1434            }
     1435        }
     1436    }
     1437
     1438#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_PM)
     1439    else if (!internalWinId() && isVisible()) {
    13541440        qApp->d_func()->sendSyntheticEnterLeave(this);
     1441#ifdef Q_WS_QWS
     1442    } else if (isVisible()) {
     1443        qApp->d_func()->sendSyntheticEnterLeave(this);
     1444#endif
     1445    }
    13551446#endif
    13561447
     
    13671458    QObjectPrivate::clearGuards(this);
    13681459
     1460    if (d->declarativeData) {
     1461        d->declarativeData->destroyed(this);
     1462        d->declarativeData = 0;                 // don't activate again in ~QObject
     1463    }
     1464
    13691465    if (!d->children.isEmpty())
    13701466        d->deleteChildren();
     
    13721468    QApplication::removePostedEvents(this);
    13731469
    1374     destroy();                                        // platform-dependent cleanup
    1375 
     1470    QT_TRY {
     1471        destroy();                                        // platform-dependent cleanup
     1472    } QT_CATCH(...) {
     1473        // if this fails we can't do anything about it but at least we are not allowed to throw.
     1474    }
    13761475    --QWidgetPrivate::instanceCounter;
    13771476
    1378     if (QWidgetPrivate::uncreatedWidgets) // might have been deleted by ~QApplication
    1379         QWidgetPrivate::uncreatedWidgets->remove(this);
     1477    if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication
     1478        QWidgetPrivate::allWidgets->remove(this);
    13801479
    13811480    QEvent e(QEvent::Destroy);
     
    13971496    if (mapper && data.winid && !userDesktopWidget) {
    13981497        mapper->remove(data.winid);
    1399         uncreatedWidgets->insert(q);
    1400     }
     1498    }
     1499
     1500    const WId oldWinId = data.winid;
    14011501
    14021502    data.winid = id;
     
    14061506    if (mapper && id && !userDesktopWidget) {
    14071507        mapper->insert(data.winid, q);
    1408         uncreatedWidgets->remove(q);
     1508    }
     1509
     1510    if(oldWinId != id) {
     1511        // Do not emit an event when the old winId is destroyed.  This only
     1512        // happens (a) during widget destruction, and (b) immediately prior
     1513        // to creation of a new winId, for example as a result of re-parenting.
     1514        if(id != 0) {
     1515            QEvent e(QEvent::WinIdChange);
     1516            QCoreApplication::sendEvent(q, &e);
     1517        }
    14091518    }
    14101519}
     
    14161525    if (!extra->topextra) {
    14171526        QTLWExtra* x = extra->topextra = new QTLWExtra;
     1527        x->icon = 0;
     1528        x->iconPixmap = 0;
     1529        x->backingStore = 0;
    14181530        x->windowSurface = 0;
     1531        x->sharedPainter = 0;
     1532        x->incw = x->inch = 0;
     1533        x->basew = x->baseh = 0;
     1534        x->frameStrut.setCoords(0, 0, 0, 0);
     1535        x->normalGeometry = QRect(0,0,-1,-1);
     1536        x->savedFlags = 0;
    14191537        x->opacity = 255;
    14201538        x->posFromMove = false;
     
    14221540        x->inTopLevelResize = false;
    14231541        x->inRepaint = false;
    1424         x->backingStore = 0;
    1425         x->icon = 0;
    1426         x->iconPixmap = 0;
    1427         x->frameStrut.setCoords(0, 0, 0, 0);
    1428         x->incw = x->inch = 0;
    1429         x->basew = x->baseh = 0;
    1430         x->normalGeometry = QRect(0,0,-1,-1);
    1431 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_MAC)
    14321542        x->embedded = 0;
    1433 #endif
    1434 #if defined(Q_WS_X11)
    1435         x->parentWinId = 0;
    1436         x->spont_unmapped = 0;
    1437         x->dnd = 0;
    1438 #endif
    1439         x->savedFlags = 0;
    1440 #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
    1441         x->qwsManager = 0;
    1442 #endif
    1443         x->sharedPainter = 0;
    14441543        createTLSysExtra();
    14451544#ifdef QWIDGET_EXTRA_DEBUG
    1446     static int count = 0;
    1447     qDebug() << "tlextra" << ++count;
     1545        static int count = 0;
     1546        qDebug() << "tlextra" << ++count;
    14481547#endif
    14491548    }
     
    14591558    if (!extra) {                                // if not exists
    14601559        extra = new QWExtra;
    1461         extra->minw = extra->minh = 0;
    1462         extra->maxw = extra->maxh = QWIDGETSIZE_MAX;
     1560        extra->glContext = 0;
     1561        extra->topextra = 0;
     1562#ifndef QT_NO_GRAPHICSVIEW
     1563        extra->proxyWidget = 0;
     1564#endif
     1565#ifndef QT_NO_CURSOR
     1566        extra->curs = 0;
     1567#endif
     1568        extra->minw = 0;
     1569        extra->minh = 0;
     1570        extra->maxw = QWIDGETSIZE_MAX;
     1571        extra->maxh = QWIDGETSIZE_MAX;
     1572        extra->customDpiX = 0;
     1573        extra->customDpiY = 0;
    14631574        extra->explicitMinSize = 0;
    14641575        extra->explicitMaxSize = 0;
     
    14671578        extra->inRenderWithPainter = 0;
    14681579        extra->hasMask = 0;
    1469 #ifndef QT_NO_CURSOR
    1470         extra->curs = 0;
    1471 #endif
    1472         extra->style = 0;
    1473         extra->topextra = 0;
    1474         extra->proxyWidget = 0;
    1475         extra->glContext = 0;
    1476         extra->customDpiX = 0;
    1477         extra->customDpiY = 0;
    14781580        createSysExtra();
    14791581#ifdef QWIDGET_EXTRA_DEBUG
    1480     static int count = 0;
    1481     qDebug() << "extra" << ++count;
     1582        static int count = 0;
     1583        qDebug() << "extra" << ++count;
    14821584#endif
    14831585    }
     
    15171619        extra = 0;
    15181620    }
    1519 }
    1520 
    1521 /*
    1522   Returns true if the background is inherited; otherwise returns
    1523   false.
    1524 
    1525   Mainly used in the paintOnScreen case.
    1526 */
    1527 
    1528 bool QWidgetPrivate::isBackgroundInherited() const
    1529 {
    1530     Q_Q(const QWidget);
    1531 
    1532     // windows do not inherit their background
    1533     if (q->isWindow() || q->windowType() == Qt::SubWindow)
    1534         return false;
    1535 
    1536     if (q->testAttribute(Qt::WA_NoSystemBackground) || q->testAttribute(Qt::WA_OpaquePaintEvent))
    1537         return false;
    1538 
    1539     const QPalette &pal = q->palette();
    1540     QPalette::ColorRole bg = q->backgroundRole();
    1541     QBrush brush = pal.brush(bg);
    1542 
    1543     // non opaque brushes leaves us no choice, we must inherit
    1544     if (!q->autoFillBackground() || !brush.isOpaque())
    1545         return true;
    1546 
    1547     if (brush.style() == Qt::SolidPattern) {
    1548         // the background is just a solid color. If there is no
    1549         // propagated contents, then we claim as performance
    1550         // optimization that it was not inheritet. This is the normal
    1551         // case in standard Windows or Motif style.
    1552         const QWidget *w = q->parentWidget();
    1553         if (!w->d_func()->isBackgroundInherited())
    1554             return false;
    1555     }
    1556 
    1557     return true;
    15581621}
    15591622
     
    15831646            }
    15841647
    1585             if (qRectIntersects(sibling->data->crect, r)) {
     1648            if (qRectIntersects(sibling->d_func()->effectiveRectFor(sibling->data->crect), r)) {
    15861649                const QWExtra *siblingExtra = sibling->d_func()->extra;
    1587                 if (siblingExtra && siblingExtra->hasMask
     1650                if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect
    15881651                    && !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) {
    15891652                    continue;
     
    16491712    Q_Q(QWidget);
    16501713    // Propagate a new inherited mask to all children.
     1714#ifndef QT_NO_GRAPHICSVIEW
    16511715    if (!q->parentWidget() && extra && extra->proxyWidget) {
    1652 #ifndef QT_NO_GRAPHICSVIEW
    16531716        QGraphicsProxyWidget *p = extra->proxyWidget;
    16541717        inheritedPaletteResolveMask = p->d_func()->inheritedPaletteResolveMask | p->palette().resolve();
     1718    } else
    16551719#endif //QT_NO_GRAPHICSVIEW
    1656     } else if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
     1720        if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
    16571721        inheritedPaletteResolveMask = 0;
    16581722    }
     
    16841748    if (!w->isVisible())
    16851749        return QRect();
    1686     QRect r = q->rect();
     1750    QRect r = effectiveRectFor(q->rect());
    16871751    int ox = 0;
    16881752    int oy = 0;
     
    17391803}
    17401804
     1805#ifndef QT_NO_GRAPHICSEFFECT
     1806void QWidgetPrivate::invalidateGraphicsEffectsRecursively()
     1807{
     1808    Q_Q(QWidget);
     1809    QWidget *w = q;
     1810    do {
     1811        if (w->graphicsEffect()) {
     1812            QWidgetEffectSourcePrivate *sourced =
     1813                static_cast<QWidgetEffectSourcePrivate *>(w->graphicsEffect()->source()->d_func());
     1814            if (!sourced->updateDueToGraphicsEffect)
     1815                w->graphicsEffect()->source()->d_func()->invalidateCache();
     1816        }
     1817        w = w->parentWidget();
     1818    } while (w);
     1819}
     1820#endif //QT_NO_GRAPHICSEFFECT
     1821
    17411822void QWidgetPrivate::setDirtyOpaqueRegion()
    17421823{
     
    17441825
    17451826    dirtyOpaqueChildren = true;
     1827
     1828#ifndef QT_NO_GRAPHICSEFFECT
     1829    invalidateGraphicsEffectsRecursively();
     1830#endif //QT_NO_GRAPHICSEFFECT
    17461831
    17471832    if (q->isWindow())
     
    17581843}
    17591844
    1760 QRegion QWidgetPrivate::getOpaqueRegion() const
    1761 {
    1762     Q_Q(const QWidget);
    1763 
    1764     QRegion r = isOpaque ? q->rect() : getOpaqueChildren();
    1765     if (extra && extra->hasMask)
    1766         r &= extra->mask;
    1767     if (r.isEmpty())
    1768         return r;
    1769     return r & clipRect();
    1770 }
    1771 
    17721845const QRegion &QWidgetPrivate::getOpaqueChildren() const
    17731846{
     
    17841857
    17851858        const QPoint offset = child->geometry().topLeft();
    1786         that->opaqueChildren += child->d_func()->getOpaqueRegion().translated(offset);
    1787     }
    1788 
     1859        QWidgetPrivate *childd = child->d_func();
     1860        QRegion r = childd->isOpaque ? child->rect() : childd->getOpaqueChildren();
     1861        if (childd->extra && childd->extra->hasMask)
     1862            r &= childd->extra->mask;
     1863        if (r.isEmpty())
     1864            continue;
     1865        r.translate(offset);
     1866        that->opaqueChildren += r;
     1867    }
     1868
     1869    that->opaqueChildren &= q_func()->rect();
    17891870    that->dirtyOpaqueChildren = false;
    17901871
     
    18261907        QWidgetPrivate *pd = w->parentWidget()->d_func();
    18271908        const int myIndex = pd->children.indexOf(const_cast<QWidget *>(w));
     1909        const QRect widgetGeometry = w->d_func()->effectiveRectFor(w->data->crect);
    18281910        for (int i = myIndex + 1; i < pd->children.size(); ++i) {
    18291911            QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
     
    18311913                continue;
    18321914
    1833             if (!qRectIntersects(sibling->data->crect, w->data->crect))
     1915            const QRect siblingGeometry = sibling->d_func()->effectiveRectFor(sibling->data->crect);
     1916            if (!qRectIntersects(siblingGeometry, widgetGeometry))
    18341917                continue;
    18351918
     
    18391922            }
    18401923
    1841             if (!qRectIntersects(sibling->data->crect, clipBoundingRect.translated(parentOffset)))
     1924            if (!qRectIntersects(siblingGeometry, clipBoundingRect.translated(parentOffset)))
    18421925                continue;
    18431926
     
    18511934            QRegion siblingDirty(parentClip);
    18521935            siblingDirty &= (siblingClipRect.translated(siblingPos));
    1853             const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask;
     1936            const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask
     1937                                 && !sibling->d_func()->graphicsEffect;
    18541938            if (hasMask)
    18551939                siblingDirty &= sibling->d_func()->extra->mask.translated(siblingPos);
     
    18621946                    sourceRegion -= siblingDirty;
    18631947                } else {
    1864                     sourceRegion -= sibling->data->crect.translated(-parentOffset);
     1948                    sourceRegion -= siblingGeometry.translated(-parentOffset);
    18651949                }
    18661950            } else {
     
    18931977    QPoint offset;
    18941978
     1979#ifndef QT_NO_GRAPHICSEFFECT
     1980    if (graphicsEffect) {
     1981        w = q->parentWidget();
     1982        offset -= data.crect.topLeft();
     1983    }
     1984#endif //QT_NO_GRAPHICSEFFECT
     1985
    18951986    while (w) {
    18961987        const QWidgetPrivate *wd = w->d_func();
     
    19021993        w = w->parentWidget();
    19031994    }
    1904 }
    1905 
    1906 bool QWidgetPrivate::hasBackground() const
    1907 {
    1908     Q_Q(const QWidget);
    1909     if (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_PaintOnScreen))
    1910         return true;
    1911     if (q->testAttribute(Qt::WA_PaintOnScreen))
    1912         return true;
    1913     if (!q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) {
    1914         const QPalette &pal = q->palette();
    1915         QPalette::ColorRole bg = q->backgroundRole();
    1916         QBrush bgBrush = pal.brush(bg);
    1917         return (bgBrush.style() != Qt::NoBrush &&
    1918                 ((q->isWindow() || q->windowType() == Qt::SubWindow)
    1919                  || (QPalette::ColorRole(bg_role) != QPalette::NoRole || (pal.resolve() & (1<<bg)))));
    1920     }
    1921     return false;
    19221995}
    19231996
     
    19442017    setDirtyOpaqueRegion();
    19452018
     2019#ifndef QT_NO_GRAPHICSEFFECT
     2020    if (graphicsEffect) {
     2021        // ### We should probably add QGraphicsEffect::isOpaque at some point.
     2022        setOpaque(false);
     2023        return;
     2024    }
     2025#endif //QT_NO_GRAPHICSEFFECT
     2026
    19462027    Q_Q(QWidget);
    19472028#ifdef Q_WS_X11
     
    19912072    winUpdateIsOpaque();
    19922073#endif
     2074#ifdef Q_OS_SYMBIAN
     2075    s60UpdateIsOpaque();
     2076#endif
    19932077}
    19942078
     
    20032087#ifdef Q_WS_WIN
    20042088    winUpdateIsOpaque();
     2089#endif
     2090#ifdef Q_OS_SYMBIAN
     2091    s60UpdateIsOpaque();
    20052092#endif
    20062093}
     
    20242111    p.translate(-off);
    20252112    widget->d_func()->paintBackground(&p, QRect(off, size()));
    2026 
    2027 }
    2028 
    2029 static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QPoint &offset, const QBrush &brush)
     2113}
     2114
     2115static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush)
    20302116{
    20312117    Q_ASSERT(painter);
     
    20362122        // when filling with the standard widget background.
    20372123        // Defined in qmacstyle_mac.cpp
    2038         extern void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QPoint &offset, const QBrush &brush);
    2039         qt_mac_fill_background(painter, rgn, offset, brush);
     2124        extern void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush);
     2125        qt_mac_fill_background(painter, rgn, brush);
    20402126#else
    2041         const QRegion translated = rgn.translated(offset);
    2042         const QRect rect(translated.boundingRect());
    2043         painter->setClipRegion(translated);
    2044         painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
    2045 #endif
     2127#if !defined(QT_NO_STYLE_S60)
     2128        // Defined in qs60style.cpp
     2129        extern bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush);
     2130        if (!qt_s60_fill_background(painter, rgn, brush))
     2131#endif // !defined(QT_NO_STYLE_S60)
     2132        {
     2133            const QRect rect(rgn.boundingRect());
     2134            painter->setClipRegion(rgn);
     2135            painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
     2136        }
     2137#endif // Q_WS_MAC
     2138
     2139    } else if (brush.gradient()
     2140               && brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode) {
     2141        painter->save();
     2142        painter->setClipRegion(rgn);
     2143        painter->fillRect(0, 0, painter->device()->width(), painter->device()->height(), brush);
     2144        painter->restore();
    20462145    } else {
    20472146        const QVector<QRect> &rects = rgn.rects();
    20482147        for (int i = 0; i < rects.size(); ++i)
    2049             painter->fillRect(rects.at(i).translated(offset), brush);
    2050     }
    2051 }
    2052 
    2053 
    2054 void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, const QPoint &offset, int flags) const
     2148            painter->fillRect(rects.at(i), brush);
     2149    }
     2150}
     2151
     2152void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const
    20552153{
    20562154    Q_Q(const QWidget);
     2155
     2156#ifndef QT_NO_SCROLLAREA
     2157    bool resetBrushOrigin = false;
     2158    QPointF oldBrushOrigin;
     2159    //If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture
     2160    QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent);
     2161    if (scrollArea && scrollArea->viewport() == q) {
     2162        QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data();
     2163        QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate);
     2164        oldBrushOrigin = painter->brushOrigin();
     2165        resetBrushOrigin = true;
     2166        painter->setBrushOrigin(-priv->contentsOffset());
     2167
     2168    }
     2169#endif // QT_NO_SCROLLAREA
    20572170
    20582171    const QBrush autoFillBrush = q->palette().brush(q->backgroundRole());
     
    20642177            painter->setCompositionMode(QPainter::CompositionMode_Source); //copy alpha straight in
    20652178#endif
    2066         fillRegion(painter, rgn, offset, bg);
     2179        fillRegion(painter, rgn, bg);
    20672180    }
    20682181
    20692182    if (q->autoFillBackground())
    2070         fillRegion(painter, rgn, offset, autoFillBrush);
     2183        fillRegion(painter, rgn, autoFillBrush);
    20712184
    20722185    if (q->testAttribute(Qt::WA_StyledBackground)) {
    2073         painter->setClipRegion(rgn.translated(offset));
     2186        painter->setClipRegion(rgn);
    20742187        QStyleOption opt;
    20752188        opt.initFrom(q);
    20762189        q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q);
    20772190    }
     2191
     2192#ifndef QT_NO_SCROLLAREA
     2193    if (resetBrushOrigin)
     2194        painter->setBrushOrigin(oldBrushOrigin);
     2195#endif // QT_NO_SCROLLAREA
    20782196}
    20792197
     
    20952213    Q_Q(QWidget);
    20962214    // If this was the active application window, reset it
    2097     if (qApp->activeWindow() == q)
    2098         qApp->setActiveWindow(0);
     2215    if (QApplication::activeWindow() == q)
     2216        QApplication::setActiveWindow(0);
    20992217    // If the is the active mouse press widget, reset it
    21002218    if (q == qt_button_down)
     
    21372255    will be provided a native handle.
    21382256
    2139     \note We recommend that you do not store this value as it is likely to
    2140     change at run-time.
     2257    On Mac OS X, the type returned depends on which framework Qt was linked
     2258    against. If Qt is using Carbon, the {WId} is actually an HIViewRef. If Qt
     2259    is using Cocoa, {WId} is a pointer to an NSView.
     2260
     2261    This value may change at run-time. An event with type QEvent::WinIdChange
     2262    will be sent to the widget following a change in window system identifier.
    21412263
    21422264    \sa find()
     
    22392361    widget's style, as described in the \l{Qt Style Sheets} document.
    22402362
    2241     \note Qt style sheets are currently not supported for QMacStyle
    2242     (the default style on Mac OS X). We plan to address this in some future
    2243     release.
     2363    Since Qt 4.5, Qt style sheets fully supports Mac OS X.
     2364
     2365    \warning Qt style sheets are currently not supported for custom QStyle
     2366    subclasses. We plan to address this in some future release.
    22442367
    22452368    \sa setStyle(), QApplication::styleSheet, {Qt Style Sheets}
     
    22922415    if (d->extra && d->extra->style)
    22932416        return d->extra->style;
    2294     return qApp->style();
     2417    return QApplication::style();
    22952418}
    22962419
     
    23422465{
    23432466    Q_Q(QWidget);
    2344     createExtra();
    2345 
    23462467    QStyle *oldStyle  = q->style();
    23472468#ifndef QT_NO_STYLE_STYLESHEET
    2348     QStyle *origStyle = extra->style;
    2349 #endif
    2350     extra->style = newStyle;
     2469    QStyle *origStyle = 0;
     2470#endif
     2471
     2472#ifdef Q_WS_MAC
     2473    // the metalhack boolean allows Qt/Mac to do a proper re-polish depending
     2474    // on how the Qt::WA_MacBrushedMetal attribute is set. It is only ever
     2475    // set when changing that attribute and passes the widget's CURRENT style.
     2476    // therefore no need to do a reassignment.
     2477    if (!metalHack)
     2478#endif
     2479    {
     2480        createExtra();
     2481
     2482#ifndef QT_NO_STYLE_STYLESHEET
     2483        origStyle = extra->style;
     2484#endif
     2485        extra->style = newStyle;
     2486    }
    23512487
    23522488    // repolish
     
    25982734Qt::WindowStates QWidget::windowState() const
    25992735{
    2600     return (Qt::WindowStates)data->window_state;
     2736    return Qt::WindowStates(data->window_state);
    26012737}
    26022738
     
    26102746void QWidget::overrideWindowState(Qt::WindowStates newstate)
    26112747{
    2612     QWindowStateChangeEvent e((Qt::WindowStates)data->window_state, true);
     2748    QWindowStateChangeEvent e(Qt::WindowStates(data->window_state), true);
    26132749    data->window_state  = newstate;
    26142750    QApplication::sendEvent(this, &e);
     
    27092845
    27102846    On X11, this function may not work properly with certain window
    2711     managers. See \l{geometry.html}{Window Geometry} for an explanation.
     2847    managers. See the \l{Window Geometry} documentation for an explanation.
    27122848
    27132849    \sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible()
     
    27642900{
    27652901    const QWidget * w = this;
    2766     while (w && !w->testAttribute(Qt::WA_ForceDisabled)
     2902    while (!w->testAttribute(Qt::WA_ForceDisabled)
    27672903            && !w->isWindow()
    27682904            && w->parentWidget()
     
    29483084        // enforce the windows behavior of clearing the cursor on
    29493085        // disabled widgets
    2950         extern void qt_x11_enforce_cursor(QWidget * w); // defined in qwidget_x11.cpp
    29513086        qt_x11_enforce_cursor(q);
    29523087    }
     
    29553090    setEnabled_helper_sys(enable);
    29563091#endif
    2957 #if defined (Q_WS_WIN)
    2958     if (q->hasFocus())
    2959         QInputContextPrivate::updateImeStatus(q, true);
    2960 #endif
     3092#ifndef QT_NO_IM
     3093    if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) {
     3094        QWidget *focusWidget = effectiveFocusWidget();
     3095        QInputContext *qic = focusWidget->d_func()->inputContext();
     3096        if (enable) {
     3097            qic->setFocusWidget(focusWidget);
     3098        } else {
     3099            qic->reset();
     3100            qic->setFocusWidget(0);
     3101        }
     3102    }
     3103#endif //QT_NO_IM
    29613104    QEvent e(QEvent::EnabledChange);
    29623105    QApplication::sendEvent(q, &e);
     
    30533196    window frame
    30543197
    3055     See the \link geometry.html Window Geometry documentation\endlink
    3056     for an overview of geometry issues with windows.
     3198    See the \l{Window Geometry} documentation for an overview of geometry
     3199    issues with windows.
    30573200
    30583201    By default, this property contains a value that depends on the user's
     
    30803223    any window frame
    30813224
    3082     See the \link geometry.html Window Geometry documentation\endlink
    3083     for an overview of window geometry.
     3225    See the \l{Window Geometry} documentation for an overview of geometry
     3226    issues with windows.
    30843227
    30853228    By default, this property has a value of 0.
     
    31003243    including any window frame
    31013244
    3102     See the \link geometry.html Window Geometry documentation\endlink
    3103     for an overview of window geometry.
     3245    See the \l{Window Geometry} documentation for an overview of geometry
     3246    issues with windows.
    31043247
    31053248    By default, this property has a value of 0.
     
    31333276    lead to infinite recursion.
    31343277
    3135     See the \link geometry.html Window Geometry documentation\endlink
    3136     for an overview of window geometry.
     3278    See the \l{Window Geometry} documentation for an overview of geometry
     3279    issues with windows.
    31373280
    31383281    \sa frameGeometry, size x(), y()
     
    31643307    can lead to infinite recursion.
    31653308
    3166     See the \link geometry.html Window Geometry documentation\endlink
    3167     for an overview of window geometry.
     3309    See the \l{Window Geometry} documentation for an overview of geometry
     3310    issues with windows.
    31683311
    31693312    By default, this property contains a value that depends on the user's
     
    32143357    \brief the width of the widget excluding any window frame
    32153358
    3216     See the \link geometry.html Window Geometry documentation\endlink
    3217     for an overview of window geometry.
     3359    See the \l{Window Geometry} documentation for an overview of geometry
     3360    issues with windows.
    32183361
    32193362    \note Do not use this function to find the width of a screen on
    32203363    a \l{QDesktopWidget}{multiple screen desktop}. Read
    3221     \l{multiple screens note}{this note} for details.
     3364    \l{QDesktopWidget#Screen Geometry}{this note} for details.
    32223365
    32233366    By default, this property contains a value that depends on the user's
     
    32313374    \brief the height of the widget excluding any window frame
    32323375
    3233     See the \link geometry.html Window Geometry documentation\endlink
    3234     for an overview of window geometry.
     3376    See the \l{Window Geometry} documentation for an overview of geometry
     3377    issues with windows.
    32353378
    32363379    \note Do not use this function to find the height of a screen
    3237     on a \l {QDesktopWidget} {multiple screen desktop}. Read
    3238     \l {multiple screens note} {this note} for details.
     3380    on a \l{QDesktopWidget}{multiple screen desktop}. Read
     3381    \l{QDesktopWidget#Screen Geometry}{this note} for details.
    32393382
    32403383    By default, this property contains a value that depends on the user's
     
    32513394    The rect property equals QRect(0, 0, width(), height()).
    32523395
    3253     See the \link geometry.html Window Geometry documentation\endlink
    3254     for an overview of window geometry.
     3396    See the \l{Window Geometry} documentation for an overview of geometry
     3397    issues with windows.
    32553398
    32563399    By default, this property contains a value that depends on the user's
     
    34923635    }
    34933636#endif
     3637    int mw = minw, mh = minh;
     3638    if (mw == QWIDGETSIZE_MAX)
     3639        mw = 0;
     3640    if (mh == QWIDGETSIZE_MAX)
     3641        mh = 0;
    34943642    if (minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX) {
    34953643        qWarning("QWidget::setMinimumSize: (%s/%s) "
     
    34973645                 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
    34983646                QWIDGETSIZE_MAX);
    3499         minw = qMin<int>(minw, QWIDGETSIZE_MAX);
    3500         minh = qMin<int>(minh, QWIDGETSIZE_MAX);
     3647        minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX);
     3648        minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX);
    35013649    }
    35023650    if (minw < 0 || minh < 0) {
     
    35043652                "are not possible",
    35053653                q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh);
    3506         minw = qMax(minw, 0);
    3507         minh = qMax(minh, 0);
     3654        minw = mw = qMax(minw, 0);
     3655        minh = mh = qMax(minh, 0);
    35083656    }
    35093657    createExtra();
    3510     if (extra->minw == minw && extra->minh == minh)
     3658    if (extra->minw == mw && extra->minh == mh)
    35113659        return false;
    3512     extra->minw = minw;
    3513     extra->minh = minh;
    3514     extra->explicitMinSize = (minw ? Qt::Horizontal : 0) | (minh ? Qt::Vertical : 0);
     3660    extra->minw = mw;
     3661    extra->minh = mh;
     3662    extra->explicitMinSize = (mw ? Qt::Horizontal : 0) | (mh ? Qt::Vertical : 0);
    35153663    return true;
    35163664}
     
    35723720    extra->maxw = maxw;
    35733721    extra->maxh = maxh;
    3574     extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) | (maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0);
     3722    extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) |
     3723                             (maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0);
    35753724    return true;
    35763725}
     
    36513800    This will override the default size constraints set by QLayout.
    36523801
     3802    To remove constraints, set the size to QWIDGETSIZE_MAX.
     3803
    36533804    Alternatively, if you want the widget to have a
    36543805    fixed size based on its contents, you can call
     
    36923843        d->updateGeometry_helper(true);
    36933844
    3694     resize(w, h);
     3845    if (w != QWIDGETSIZE_MAX || h != QWIDGETSIZE_MAX)
     3846        resize(w, h);
    36953847}
    36963848
     
    40654217  parent's background role.
    40664218
     4219  Note that styles are free to choose any color from the palette.
     4220  You can modify the palette or set a style sheet if you don't
     4221  achieve the result you want with setBackgroundRole().
     4222
    40674223  \sa backgroundRole(), foregroundRole()
    40684224 */
     
    41274283  that contrasts with the background role.
    41284284
     4285  Note that styles are free to choose any color from the palette.
     4286  You can modify the palette or set a style sheet if you don't
     4287  achieve the result you want with setForegroundRole().
     4288
    41294289  \sa foregroundRole(), backgroundRole()
    41304290 */
     
    41804340    appearance of the widget. Instead, you may choose to apply a \l
    41814341    styleSheet. You can refer to our Knowledge Base article
    4182     \l{http://qtsoftware.com/developer/knowledgebase/22}{here} for more
     4342    \l{http://qt.nokia.com/developer/knowledgebase/22}{here} for more
    41834343    information.
    41844344
     
    41954355        data->pal.setCurrentColorGroup(QPalette::Disabled);
    41964356    } else if ((!isVisible() || isActiveWindow())
    4197 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
     4357#if defined(Q_OS_WIN) && !defined(Q_WS_WINCE)
    41984358        && !QApplicationPrivate::isBlockedByModal(const_cast<QWidget *>(this))
    41994359#endif
     
    42404400    QPalette naturalPalette = QApplication::palette(q);
    42414401    if (!q->testAttribute(Qt::WA_StyleSheet)
    4242         && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) || (extra && extra->proxyWidget))) {
     4402        && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation)
     4403#ifndef QT_NO_GRAPHICSVIEW
     4404            || (extra && extra->proxyWidget)
     4405#endif //QT_NO_GRAPHICSVIEW
     4406            )) {
    42434407        if (QWidget *p = q->parentWidget()) {
    42444408            if (!p->testAttribute(Qt::WA_StyleSheet)) {
     
    42514415                }
    42524416            }
    4253         } else if (extra && extra->proxyWidget) {
     4417        }
    42544418#ifndef QT_NO_GRAPHICSVIEW
     4419        else if (extra && extra->proxyWidget) {
    42554420            QPalette inheritedPalette = extra->proxyWidget->palette();
    42564421            inheritedPalette.resolve(inheritedMask);
    42574422            naturalPalette = inheritedPalette.resolve(naturalPalette);
     4423        }
    42584424#endif //QT_NO_GRAPHICSVIEW
    4259         }
    42604425    }
    42614426    naturalPalette.resolve(0);
     
    43754540    QFont naturalFont = QApplication::font(q);
    43764541    if (!q->testAttribute(Qt::WA_StyleSheet)
    4377         && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) || (extra && extra->proxyWidget))) {
     4542        && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation)
     4543#ifndef QT_NO_GRAPHICSVIEW
     4544            || (extra && extra->proxyWidget)
     4545#endif //QT_NO_GRAPHICSVIEW
     4546            )) {
    43784547        if (QWidget *p = q->parentWidget()) {
    43794548            if (!p->testAttribute(Qt::WA_StyleSheet)) {
     
    43864555                }
    43874556            }
    4388         } else if (extra && extra->proxyWidget) {
     4557        }
    43894558#ifndef QT_NO_GRAPHICSVIEW
     4559        else if (extra && extra->proxyWidget) {
    43904560            QFont inheritedFont = extra->proxyWidget->font();
    43914561            inheritedFont.resolve(inheritedMask);
    43924562            naturalFont = inheritedFont.resolve(naturalFont);
     4563        }
    43934564#endif //QT_NO_GRAPHICSVIEW
    4394         }
    43954565    }
    43964566    naturalFont.resolve(0);
     
    44394609#endif
    44404610    // Combine new mask with natural mask and propagate to children.
     4611#ifndef QT_NO_GRAPHICSVIEW
    44414612    if (!q->parentWidget() && extra && extra->proxyWidget) {
    4442 #ifndef QT_NO_GRAPHICSVIEW
    44434613        QGraphicsProxyWidget *p = extra->proxyWidget;
    44444614        inheritedFontResolveMask = p->d_func()->inheritedFontResolveMask | p->font().resolve();
     4615    } else
    44454616#endif //QT_NO_GRAPHICSVIEW
    4446     } else if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
     4617    if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
    44474618        inheritedFontResolveMask = 0;
    44484619    }
     
    45144685
    45154686    When the layout direction is set on a widget, it will propagate to
    4516     the widget's children. Children added after the call to \c
    4517     setLayoutDirection() will not inherit the parent's layout
     4687    the widget's children, but not to a child that is a window and not
     4688    to a child for which setLayoutDirection() has been explicitly
     4689    called. Also, child widgets added \e after setLayoutDirection()
     4690    has been called for the parent do not inherit the parent's layout
    45184691    direction.
    45194692
     
    45754748    By default, this property contains a cursor with the Qt::ArrowCursor
    45764749    shape.
     4750
     4751    Some underlying window implementations will reset the cursor if it
     4752    leaves a widget even if the mouse is grabbed. If you want to have
     4753    a cursor set for all widgets, even when outside the window, consider
     4754    QApplication::setOverrideCursor().
    45774755
    45784756    \sa QApplication::setOverrideCursor()
     
    46024780    {
    46034781        d->createExtra();
     4782        QCursor *newCursor = new QCursor(cursor);
    46044783        delete d->extra->curs;
    4605         d->extra->curs = new QCursor(cursor);
     4784        d->extra->curs = newCursor;
    46064785    }
    46074786    setAttribute(Qt::WA_SetCursor);
     
    47134892        target = redirected;
    47144893        offset -= redirectionOffset;
    4715         if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp).
    4716             const QRegion redirectedSystemClip = redirected->paintEngine()->systemClip();
    4717             if (!redirectedSystemClip.isEmpty())
    4718                 paintRegion &= redirectedSystemClip.translated(-offset);
     4894    }
     4895
     4896    if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp).
     4897        if (QPaintEngine *targetEngine = target->paintEngine()) {
     4898            const QRegion targetSystemClip = targetEngine->systemClip();
     4899            if (!targetSystemClip.isEmpty())
     4900                paintRegion &= targetSystemClip.translated(-offset);
    47194901        }
    47204902    }
     
    47804962
    47814963    const qreal opacity = painter->opacity();
    4782     if (qFuzzyCompare(opacity + 1, qreal(1.0)))
     4964    if (qFuzzyIsNull(opacity))
    47834965        return; // Fully transparent.
    47844966
     
    48014983    QPaintEnginePrivate *enginePriv = engine->d_func();
    48024984    Q_ASSERT(enginePriv);
    4803     QPaintDevice *target = painter->worldMatrixEnabled() ? engine->paintDevice() : painter->device();
     4985    QPaintDevice *target = engine->paintDevice();
    48044986    Q_ASSERT(target);
    48054987
     
    48205002    const QRegion oldSystemViewport = enginePriv->systemViewport;
    48215003
    4822     // This ensures that transformed system clips are inside the current system clip.
    4823     enginePriv->setSystemViewport(oldSystemClip);
     5004    // This ensures that all painting triggered by render() is clipped to the current engine clip.
     5005    if (painter->hasClipping()) {
     5006        const QRegion painterClip = painter->deviceTransform().map(painter->clipRegion());
     5007        enginePriv->setSystemViewport(oldSystemClip.isEmpty() ? painterClip : oldSystemClip & painterClip);
     5008    } else {
     5009        enginePriv->setSystemViewport(oldSystemClip);
     5010    }
    48245011
    48255012    render(target, targetOffset, toBePainted, renderFlags);
     
    48365023    d->extra->inRenderWithPainter = false;
    48375024}
     5025
     5026/*!
     5027    \brief The graphicsEffect function returns a pointer to the
     5028    widget's graphics effect.
     5029
     5030    If the widget has no graphics effect, 0 is returned.
     5031
     5032    \since 4.6
     5033
     5034    \sa setGraphicsEffect()
     5035*/
     5036#ifndef QT_NO_GRAPHICSEFFECT
     5037QGraphicsEffect *QWidget::graphicsEffect() const
     5038{
     5039    Q_D(const QWidget);
     5040    return d->graphicsEffect;
     5041}
     5042#endif //QT_NO_GRAPHICSEFFECT
     5043
     5044/*!
     5045
     5046  \brief The setGraphicsEffect function is for setting the widget's graphics effect.
     5047
     5048    Sets \a effect as the widget's effect. If there already is an effect installed
     5049    on this widget, QWidget will delete the existing effect before installing
     5050    the new \a effect.
     5051
     5052    If \a effect is the installed on a different widget, setGraphicsEffect() will remove
     5053    the effect from the widget and install it on this widget.
     5054
     5055    QWidget takes ownership of \a effect.
     5056
     5057    \note This function will apply the effect on itself and all its children.
     5058
     5059    \since 4.6
     5060
     5061    \sa graphicsEffect()
     5062*/
     5063#ifndef QT_NO_GRAPHICSEFFECT
     5064void QWidget::setGraphicsEffect(QGraphicsEffect *effect)
     5065{
     5066    Q_D(QWidget);
     5067    if (d->graphicsEffect == effect)
     5068        return;
     5069
     5070    if (d->graphicsEffect) {
     5071        d->invalidateBuffer(rect());
     5072        delete d->graphicsEffect;
     5073        d->graphicsEffect = 0;
     5074    }
     5075
     5076    if (effect) {
     5077        // Set new effect.
     5078        QGraphicsEffectSourcePrivate *sourced = new QWidgetEffectSourcePrivate(this);
     5079        QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced);
     5080        d->graphicsEffect = effect;
     5081        effect->d_func()->setGraphicsEffectSource(source);
     5082        update();
     5083    }
     5084
     5085    d->updateIsOpaque();
     5086}
     5087#endif //QT_NO_GRAPHICSEFFECT
    48385088
    48395089bool QWidgetPrivate::isAboutToShow() const
     
    49285178
    49295179        QPixmap pixmap(size);
    4930         if (!(renderFlags & QWidget::DrawWindowBackground))
     5180        if (!(renderFlags & QWidget::DrawWindowBackground) || !isOpaque)
    49315181            pixmap.fill(Qt::transparent);
    49325182        q->render(&pixmap, QPoint(), toBePainted, renderFlags);
     
    49815231
    49825232    Q_Q(QWidget);
     5233#ifndef QT_NO_GRAPHICSEFFECT
     5234    if (graphicsEffect && graphicsEffect->isEnabled()) {
     5235        QGraphicsEffectSource *source = graphicsEffect->d_func()->source;
     5236        QWidgetEffectSourcePrivate *sourced = static_cast<QWidgetEffectSourcePrivate *>
     5237                                                         (source->d_func());
     5238        if (!sourced->context) {
     5239            QWidgetPaintContext context(pdev, rgn, offset, flags, sharedPainter, backingStore);
     5240            sourced->context = &context;
     5241            if (!sharedPainter) {
     5242                QPaintEngine *paintEngine = pdev->paintEngine();
     5243                paintEngine->d_func()->systemClip = rgn.translated(offset);
     5244                QPainter p(pdev);
     5245                p.translate(offset);
     5246                context.painter = &p;
     5247                graphicsEffect->draw(&p);
     5248                paintEngine->d_func()->systemClip = QRegion();
     5249            } else {
     5250                context.painter = sharedPainter;
     5251                if (sharedPainter->worldTransform() != sourced->lastEffectTransform) {
     5252                    sourced->invalidateCache();
     5253                    sourced->lastEffectTransform = sharedPainter->worldTransform();
     5254                }
     5255                sharedPainter->save();
     5256                sharedPainter->translate(offset);
     5257                graphicsEffect->draw(sharedPainter);
     5258                sharedPainter->restore();
     5259            }
     5260            sourced->context = 0;
     5261            return;
     5262        }
     5263    }
     5264#endif //QT_NO_GRAFFICSEFFECT
     5265
    49835266    const bool asRoot = flags & DrawAsRoot;
    49845267    const bool alsoOnScreen = flags & DrawPaintOnScreen;
     
    50135296                    paintEngine->d_func()->systemClip = toBePainted;
    50145297                else
    5015                     paintEngine->setSystemRect(q->data->crect);
     5298                    paintEngine->d_func()->systemRect = q->data->crect;
    50165299
    50175300                //paint the background
     
    50205303
    50215304                    QPainter p(q);
    5022                     QPoint scrollAreaOffset;
    5023 
    5024 #ifndef QT_NO_SCROLLAREA
    5025                     QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(q->parent());
    5026                     if (scrollArea && scrollArea->viewport() == q) {
    5027                         QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr;
    5028                         QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate);
    5029                         scrollAreaOffset = priv->contentsOffset();
    5030                         p.translate(-scrollAreaOffset);
    5031                     }
    5032 #endif // QT_NO_SCROLLAREA
    5033 
    5034                     paintBackground(&p, toBePainted, scrollAreaOffset, (asRoot || onScreen) ? flags | DrawAsRoot : 0);
     5305                    paintBackground(&p, toBePainted, (asRoot || onScreen) ? flags | DrawAsRoot : 0);
    50355306                }
    50365307
     
    50645335                restoreRedirected();
    50655336                if (!sharedPainter)
    5066                     paintEngine->setSystemRect(QRect());
     5337                    paintEngine->d_func()->systemRect = QRect();
    50675338                else
    50685339                    paintEngine->d_func()->currentClipWidget = 0;
     
    51275398            }
    51285399
    5129             if (qRectIntersects(boundingRect, x->data->crect)) {
     5400            if (qRectIntersects(boundingRect, x->d_func()->effectiveRectFor(x->data->crect))) {
    51305401#ifdef Q_BACKINGSTORE_SUBSURFACES
    51315402                if (x->windowSurface() == currentSurface)
     
    51455416    QWidgetPrivate *wd = w->d_func();
    51465417    const QPoint widgetPos(w->data->crect.topLeft());
    5147     const bool hasMask = wd->extra && wd->extra->hasMask;
    5148 
     5418    const bool hasMask = wd->extra && wd->extra->hasMask && !wd->graphicsEffect;
    51495419    if (index > 0) {
    51505420        QRegion wr(rgn);
     
    51585428    }
    51595429
    5160     if (w->updatesEnabled() && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget)) {
     5430    if (w->updatesEnabled()
     5431#ifndef QT_NO_GRAPHICSVIEW
     5432            && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget)
     5433#endif //QT_NO_GRAPHICSVIEW
     5434       ) {
    51615435        QRegion wRegion(rgn);
    5162         wRegion &= w->data->crect;
     5436        wRegion &= wd->effectiveRectFor(w->data->crect);
    51635437        wRegion.translate(-widgetPos);
    51645438        if (hasMask)
     
    51685442}
    51695443
     5444#ifndef QT_NO_GRAPHICSEFFECT
     5445QRectF QWidgetEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const
     5446{
     5447    if (system != Qt::DeviceCoordinates)
     5448        return m_widget->rect();
     5449
     5450    if (!context) {
     5451        // Device coordinates without context not yet supported.
     5452        qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");
     5453        return QRectF();
     5454    }
     5455
     5456    return context->painter->worldTransform().mapRect(m_widget->rect());
     5457}
     5458
     5459void QWidgetEffectSourcePrivate::draw(QPainter *painter)
     5460{
     5461    if (!context || context->painter != painter) {
     5462        m_widget->render(painter);
     5463        return;
     5464    }
     5465
     5466    // The region saved in the context is neither clipped to the rect
     5467    // nor the mask, so we have to clip it here before calling drawWidget.
     5468    QRegion toBePainted = context->rgn;
     5469    toBePainted &= m_widget->rect();
     5470    QWidgetPrivate *wd = qt_widget_private(m_widget);
     5471    if (wd->extra && wd->extra->hasMask)
     5472        toBePainted &= wd->extra->mask;
     5473
     5474    wd->drawWidget(context->pdev, toBePainted, context->offset, context->flags,
     5475                   context->sharedPainter, context->backingStore);
     5476}
     5477
     5478QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset,
     5479                                           QGraphicsEffect::PixmapPadMode mode) const
     5480{
     5481    const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
     5482    if (!context && deviceCoordinates) {
     5483        // Device coordinates without context not yet supported.
     5484        qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
     5485        return QPixmap();
     5486    }
     5487
     5488    QPoint pixmapOffset;
     5489    QRectF sourceRect = m_widget->rect();
     5490
     5491    if (deviceCoordinates) {
     5492        const QTransform &painterTransform = context->painter->worldTransform();
     5493        sourceRect = painterTransform.mapRect(sourceRect);
     5494        pixmapOffset = painterTransform.map(pixmapOffset);
     5495    }
     5496
     5497
     5498    QRect effectRect;
     5499
     5500    if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) {
     5501        effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect();
     5502
     5503    } else if (mode == QGraphicsEffect::PadToTransparentBorder) {
     5504        effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect();
     5505
     5506    } else {
     5507        effectRect = sourceRect.toAlignedRect();
     5508
     5509    }
     5510
     5511    if (offset)
     5512        *offset = effectRect.topLeft();
     5513
     5514    if (deviceCoordinates) {
     5515        // Clip to device rect.
     5516        int left, top, right, bottom;
     5517        effectRect.getCoords(&left, &top, &right, &bottom);
     5518        if (left < 0) {
     5519            if (offset)
     5520                offset->rx() += -left;
     5521            effectRect.setX(0);
     5522        }
     5523        if (top < 0) {
     5524            if (offset)
     5525                offset->ry() += -top;
     5526            effectRect.setY(0);
     5527        }
     5528        // NB! We use +-1 for historical reasons (see QRect documentation).
     5529        QPaintDevice *device = context->painter->device();
     5530        const int deviceWidth = device->width();
     5531        const int deviceHeight = device->height();
     5532        if (right + 1 > deviceWidth)
     5533            effectRect.setRight(deviceWidth - 1);
     5534        if (bottom + 1 > deviceHeight)
     5535            effectRect.setBottom(deviceHeight -1);
     5536    }
     5537
     5538    pixmapOffset -= effectRect.topLeft();
     5539
     5540    QPixmap pixmap(effectRect.size());
     5541    pixmap.fill(Qt::transparent);
     5542    m_widget->render(&pixmap, pixmapOffset);
     5543    return pixmap;
     5544}
     5545#endif //QT_NO_GRAPHICSEFFECT
     5546
     5547#ifndef QT_NO_GRAPHICSVIEW
    51705548/*!
    51715549    \internal
     
    51765554    widget was found.
    51775555*/
    5178 QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(QWidget *origin)
     5556QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin)
    51795557{
    51805558    if (origin) {
     
    51865564    return 0;
    51875565}
     5566#endif
    51885567
    51895568/*!
     
    52665645    QString appName = QApplication::applicationName();
    52675646    if (!appName.isEmpty())
    5268         windowTitle += QLatin1String(" ") + QChar(0x2014) + QLatin1String(" ") + appName;
     5647        windowTitle += QLatin1Char(' ') + QChar(0x2014) + QLatin1Char(' ') + appName;
    52695648#endif
    52705649    return windowTitle;
     
    53015680}
    53025681
     5682/*!
     5683    Returns a modified window title with the [*] place holder
     5684    replaced according to the rules described in QWidget::setWindowTitle
     5685
     5686    This function assumes that "[*]" can be quoted by another
     5687    "[*]", so it will replace two place holders by one and
     5688    a single last one by either "*" or nothing depending on
     5689    the modified flag.
     5690
     5691    \internal
     5692*/
    53035693QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widget)
    53045694{
     
    53125702#endif
    53135703
    5314     QString placeHolder(QLatin1String("[*]"));
     5704    if (cap.isEmpty())
     5705        return cap;
     5706
     5707    QLatin1String placeHolder("[*]");
     5708    int placeHolderLength = 3; // QLatin1String doesn't have length()
    53155709
    53165710    int index = cap.indexOf(placeHolder);
    53175711
     5712    // here the magic begins
    53185713    while (index != -1) {
    5319         index += placeHolder.length();
     5714        index += placeHolderLength;
    53205715        int count = 1;
    53215716        while (cap.indexOf(placeHolder, index) == index) {
    53225717            ++count;
    5323             index += placeHolder.length();
     5718            index += placeHolderLength;
    53245719        }
    53255720
     
    53305725                cap.replace(lastIndex, 3, QWidget::tr("*"));
    53315726            else
    5332                 cap.replace(lastIndex, 3, QLatin1String(""));
     5727                cap.remove(lastIndex, 3);
    53335728        }
    53345729
     
    53365731    }
    53375732
    5338     cap.replace(QLatin1String("[*][*]"), QLatin1String("[*]"));
     5733    cap.replace(QLatin1String("[*][*]"), placeHolder);
    53395734
    53405735    return cap;
     
    53445739{
    53455740    Q_Q(QWidget);
    5346     if (!q->testAttribute(Qt::WA_WState_Created))
    5347         createWinId();
    5348     setWindowTitle_sys(qt_setWindowTitle_helperHelper(title, q));
     5741    if (q->testAttribute(Qt::WA_WState_Created))
     5742        setWindowTitle_sys(qt_setWindowTitle_helperHelper(title, q));
    53495743}
    53505744
     
    53715765void QWidget::setWindowTitle(const QString &title)
    53725766{
    5373     if (QWidget::windowTitle() == title)
     5767    if (QWidget::windowTitle() == title && !title.isEmpty() && !title.isNull())
    53745768        return;
    53755769
     
    54025796        w = w->parentWidget();
    54035797    }
    5404     return qApp->windowIcon();
     5798    return QApplication::windowIcon();
    54055799}
    54065800
     
    54655859    \list
    54665860    \o The file name of the specified path, obtained using QFileInfo::fileName().
    5467     \o An optional \c{*} character, if the \l windowModified property is set,
    5468     as per the Apple Human Interface Guidelines.
    54695861    \endlist
    54705862
     
    55155907    if (extra->topextra && extra->topextra->caption.isEmpty()) {
    55165908#ifdef Q_WS_MAC
    5517         setWindowTitle_helper(filePath);
     5909        setWindowTitle_helper(QFileInfo(filePath).fileName());
    55185910#else
    55195911        Q_Q(QWidget);
     
    56486040    be passed into any focus event sent from this function, it is used
    56496041    to give an explanation of what caused the widget to get focus.
     6042    If the window is not active, the widget will be given the focus when
     6043    the window becomes active.
    56506044
    56516045    First, a focus out event is sent to the focus widget (if any) to
     
    56556049    same.)
    56566050
     6051    \note On embedded platforms, setFocus() will not cause an input panel
     6052    to be opened by the input method. If you want this to happen, you
     6053    have to send a QEvent::RequestSoftwareInputPanel event to the
     6054    widget yourself.
     6055
    56576056    setFocus() gives focus to a widget regardless of its focus policy,
    56586057    but does not clear any keyboard grab (see grabKeyboard()).
     
    56666065
    56676066    \sa hasFocus(), clearFocus(), focusInEvent(), focusOutEvent(),
    5668     setFocusPolicy(), QApplication::focusWidget(), grabKeyboard(),
    5669     grabMouse(), {Keyboard Focus}
     6067    setFocusPolicy(), focusWidget(), QApplication::focusWidget(), grabKeyboard(),
     6068    grabMouse(), {Keyboard Focus}, QEvent::RequestSoftwareInputPanel
    56706069*/
    56716070
     
    57826181{
    57836182    QWidget *w = this;
    5784     while (w && w->d_func()->focus_child == this) {
    5785         w->d_func()->focus_child = 0;
     6183    while (w) {
     6184        if (w->d_func()->focus_child == this)
     6185            w->d_func()->focus_child = 0;
    57866186        w = w->parentWidget();
    57876187    }
     
    58856285/*!
    58866286    Returns the next widget in this widget's focus chain.
     6287
     6288    \sa previousInFocusChain()
    58876289*/
    58886290QWidget *QWidget::nextInFocusChain() const
    58896291{
    58906292    return const_cast<QWidget *>(d_func()->focus_next);
     6293}
     6294
     6295/*!
     6296    \brief The previousInFocusChain function returns the previous
     6297    widget in this widget's focus chain.
     6298
     6299    \sa nextInFocusChain()
     6300
     6301    \since 4.6
     6302*/
     6303QWidget *QWidget::previousInFocusChain() const
     6304{
     6305    return const_cast<QWidget *>(d_func()->focus_prev);
    58916306}
    58926307
     
    59096324{
    59106325    QWidget *tlw = window();
    5911     if(tlw == qApp->activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup)))
     6326    if(tlw == QApplication::activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup)))
    59126327        return true;
    59136328
     
    59246339       tlw->parentWidget() && tlw->parentWidget()->isActiveWindow())
    59256340        return true;
     6341
     6342    extern bool qt_mac_insideKeyWindow(const QWidget *); //qwidget_mac.cpp
     6343    if (QApplication::testAttribute(Qt::AA_MacPluginApplication) && qt_mac_insideKeyWindow(tlw))
     6344        return true;
    59266345#endif
    59276346    if(style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, this)) {
     
    59306349           (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow()))
    59316350           return true;
    5932         QWidget *w = qApp->activeWindow();
     6351        QWidget *w = QApplication::activeWindow();
    59336352        while(w && tlw->windowType() == Qt::Tool &&
    59346353              !w->isModal() && w->parentWidget()) {
     
    61136532  This function is called from QDesktopwidget::screen(QPoint) to find the
    61146533  closest screen for a point.
     6534  In directional KeypadNavigation, it is called to find the closest
     6535  widget to the current focus widget center.
    61156536*/
    61166537int QWidgetPrivate::pointToRect(const QPoint &p, const QRect &r)
     
    61276548        dy = p.y() - r.bottom();
    61286549    return dx + dy;
    6129 }
    6130 
    6131 QRect QWidgetPrivate::fromOrToLayoutItemRect(const QRect &rect, int sign) const
    6132 {
    6133     QRect r = rect;
    6134     r.adjust(-sign * leftLayoutItemMargin, -sign * topLayoutItemMargin,
    6135              +sign * rightLayoutItemMargin, +sign * bottomLayoutItemMargin);
    6136     return r;
    61376550}
    61386551
     
    62256638    \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 11
    62266639
    6227     See the \link geometry.html Window Geometry documentation\endlink
    6228     for an overview of geometry issues with windows.
     6640    See the \l{Window Geometry} documentation for an overview of geometry
     6641    issues with windows.
    62296642
    62306643    Use QMainWindow::saveState() to save the geometry and the state of
     
    62606673
    62616674    If the restored geometry is off-screen, it will be modified to be
    6262     inside the the available screen geometry.
     6675    inside the available screen geometry.
    62636676
    62646677    To restore geometry saved using QSettings, you can use code like
     
    62676680    \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 12
    62686681
    6269     See the \link geometry.html Window Geometry documentation\endlink
    6270     for an overview of geometry issues with windows.
     6682    See the \l{Window Geometry} documentation for an overview of geometry
     6683    issues with windows.
    62716684
    62726685    Use QMainWindow::restoreState() to restore the geometry and the
     
    63856798
    63866799/*!
    6387     Sets the margins around the contents of the widget to have the
    6388     sizes \a left, \a top, \a right, and \a bottom. The margins are
    6389     used by the layout system, and may be used by subclasses to
    6390     specify the area to draw in (e.g. excluding the frame).
    6391 
    6392     Changing the margins will trigger a resizeEvent().
    6393 
    6394     \sa contentsRect(), getContentsMargins()
     6800  Sets the margins around the contents of the widget to have the sizes
     6801  \a left, \a top, \a right, and \a bottom. The margins are used by
     6802  the layout system, and may be used by subclasses to specify the area
     6803  to draw in (e.g. excluding the frame).
     6804
     6805  Changing the margins will trigger a resizeEvent().
     6806
     6807  \sa contentsRect(), getContentsMargins()
    63956808*/
    63966809void QWidget::setContentsMargins(int left, int top, int right, int bottom)
     
    64236836}
    64246837
    6425 /*!  Returns the widget's contents margins for \a left, \a top, \a
     6838/*!
     6839  \overload
     6840  \since 4.6
     6841
     6842  \brief The setContentsMargins function sets the margins around the
     6843  widget's contents.
     6844
     6845  Sets the margins around the contents of the widget to have the
     6846  sizes determined by \a margins. The margins are
     6847  used by the layout system, and may be used by subclasses to
     6848  specify the area to draw in (e.g. excluding the frame).
     6849
     6850  Changing the margins will trigger a resizeEvent().
     6851
     6852  \sa contentsRect(), getContentsMargins()
     6853*/
     6854void QWidget::setContentsMargins(const QMargins &margins)
     6855{
     6856    setContentsMargins(margins.left(), margins.top(),
     6857                       margins.right(), margins.bottom());
     6858}
     6859
     6860/*!
     6861  Returns the widget's contents margins for \a left, \a top, \a
    64266862  right, and \a bottom.
    64276863
     
    64406876        *bottom = d->bottommargin;
    64416877}
     6878
     6879/*!
     6880  \since 4.6
     6881
     6882  \brief The contentsMargins function returns the widget's contents margins.
     6883
     6884  \sa getContentsMargins(), setContentsMargins(), contentsRect()
     6885 */
     6886QMargins QWidget::contentsMargins() const
     6887{
     6888    Q_D(const QWidget);
     6889    return QMargins(d->leftmargin, d->topmargin, d->rightmargin, d->bottommargin);
     6890}
     6891
    64426892
    64436893/*!
     
    67237173    // stores the correct old focus widget even if it's stolen in the
    67247174    // showevent
    6725 #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
     7175#if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_OS_SYMBIAN)
    67267176    if (!isEmbedded && q->windowType() == Qt::Popup)
    67277177        qApp->d_func()->openPopup(q);
     
    67407190    show_sys();
    67417191
    6742 #if !defined(Q_WS_WIN) && !defined(Q_WS_MAC)
     7192#if !defined(Q_WS_WIN) && !defined(Q_WS_MAC) && !defined(Q_OS_SYMBIAN)
    67437193    if (!isEmbedded && q->windowType() == Qt::Popup)
    67447194        qApp->d_func()->openPopup(q);
     
    68227272    // hidden.
    68237273    if (wasVisible) {
    6824 #if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
     7274#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_PM)
    68257275        qApp->d_func()->sendSyntheticEnterLeave(q);
    68267276#endif
     
    68607310
    68617311
    6862     Widgets are  hidden if they were created as independent
    6863     windows or as children of visible widgets, or if hide() or setVisible(false) was called.
    6864 
     7312    Widgets are hidden if:
     7313    \list
     7314        \o they were created as independent windows,
     7315        \o they were created as children of visible widgets,
     7316        \o hide() or setVisible(false) was called.
     7317    \endlist
    68657318*/
    68667319
     
    69267379                parent = parent->parentWidget();
    69277380            }
    6928             if (parent && !d->getOpaqueRegion().isEmpty())
     7381            if (parent)
    69297382                parent->d_func()->setDirtyOpaqueRegion();
    69307383        }
     
    69517404            d->show_helper();
    69527405
    6953 #if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
     7406#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_PM)
    69547407            qApp->d_func()->sendSyntheticEnterLeave(this);
    69557408#endif
     
    70667519            }
    70677520        }
    7068 #if defined(Q_WS_WIN) || defined(Q_WS_PM) || defined(Q_WS_X11)
     7521#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_PM)
    70697522        qApp->d_func()->sendSyntheticEnterLeave(widget);
    70707523#endif
     
    71087561#ifdef QT3_SUPPORT
    71097562    if (isMain)
    7110         qApp->quit();
     7563        QApplication::quit();
    71117564#endif
    71127565    // Attempt to close the application only if this widget has the
     
    72337686        return isVisible();
    72347687    const QWidget * w = this;
    7235     while (w
    7236             && !w->isHidden()
     7688    while (!w->isHidden()
    72377689            && !w->isWindow()
    72387690            && w->parentWidget()
     
    72917743    if (q->isWindow()) {
    72927744        Qt::Orientations exp;
    7293         if (QLayout *l = q->layout()) {
    7294             if (l->hasHeightForWidth())
    7295                 s.setHeight(l->totalHeightForWidth(s.width()));
    7296             exp = l->expandingDirections();
     7745        if (layout) {
     7746            if (layout->hasHeightForWidth())
     7747                s.setHeight(layout->totalHeightForWidth(s.width()));
     7748            exp = layout->expandingDirections();
    72977749        } else
    72987750        {
     
    73107762        QRect screen = QApplication::desktop()->screenGeometry(q->pos());
    73117763#endif
    7312 #if defined (Q_OS_WINCE)
     7764#if defined (Q_WS_WINCE) || defined (Q_OS_SYMBIAN)
    73137765        s.setWidth(qMin(s.width(), screen.width()));
    73147766        s.setHeight(qMin(s.height(), screen.height()));
     
    73527804    ensurePolished();
    73537805    QSize s = d->adjustedSize();
     7806
     7807    if (d->layout)
     7808        d->layout->activate();
     7809
    73547810    if (s.isValid())
    73557811        resize(s);
     
    74977953        case QEvent::MouseButtonDblClick:
    74987954        case QEvent::MouseMove:
     7955        case QEvent::TouchBegin:
     7956        case QEvent::TouchUpdate:
     7957        case QEvent::TouchEnd:
    74997958        case QEvent::ContextMenu:
    75007959#ifndef QT_NO_WHEELEVENT
     
    75628021        if (!k->isAccepted() && QApplication::keypadNavigationEnabled()
    75638022            && !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::ShiftModifier))) {
    7564             if (k->key() == Qt::Key_Up)
    7565                 res = focusNextPrevChild(false);
    7566             else if (k->key() == Qt::Key_Down)
    7567                 res = focusNextPrevChild(true);
     8023            if (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder) {
     8024                if (k->key() == Qt::Key_Up)
     8025                    res = focusNextPrevChild(false);
     8026                else if (k->key() == Qt::Key_Down)
     8027                    res = focusNextPrevChild(true);
     8028            } else if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
     8029                if (k->key() == Qt::Key_Up)
     8030                    res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionNorth);
     8031                else if (k->key() == Qt::Key_Right)
     8032                    res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionEast);
     8033                else if (k->key() == Qt::Key_Down)
     8034                    res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionSouth);
     8035                else if (k->key() == Qt::Key_Left)
     8036                    res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionWest);
     8037            }
    75688038            if (res) {
    75698039                k->accept();
     
    76188088        break;
    76198089    case QEvent::FocusIn:
    7620 #if defined(Q_WS_WIN)
    7621         QInputContextPrivate::updateImeStatus(this, true);
     8090#ifdef QT_SOFTKEYS_ENABLED
     8091        QSoftKeyManager::updateSoftKeys();
    76228092#endif
    76238093        focusInEvent((QFocusEvent*)event);
     
    76258095
    76268096    case QEvent::FocusOut:
    7627 #if defined(Q_WS_WIN)
    7628         QInputContextPrivate::updateImeStatus(this, false);
    7629 #endif
    76308097        focusOutEvent((QFocusEvent*)event);
    76318098        break;
     
    77738240                QApplication::sendEvent(w, event);
    77748241        }
     8242
     8243#ifdef QT_SOFTKEYS_ENABLED
     8244        if (isWindow() && isActiveWindow())
     8245            QSoftKeyManager::updateSoftKeys();
     8246#endif
     8247
    77758248        break; }
    77768249
     
    77848257            for (int i = 0; i < childList.size(); ++i) {
    77858258                QObject *o = childList.at(i);
    7786                 QApplication::sendEvent(o, event);
     8259                if (o)
     8260                    QApplication::sendEvent(o, event);
    77878261            }
    77888262        }
     
    78138287            for (int i = 0; i < childList.size(); ++i) {
    78148288                QObject *o = childList.at(i);
    7815                 if (o != qApp->activeModalWidget()) {
     8289                if (o && o != QApplication::activeModalWidget()) {
    78168290                    if (qobject_cast<QWidget *>(o) && static_cast<QWidget *>(o)->isWindow()) {
    78178291                        // do not forward the event to child windows,
     
    78808354    case QEvent::ActionRemoved:
    78818355    case QEvent::ActionChanged:
     8356#ifdef QT_SOFTKEYS_ENABLED
     8357        QSoftKeyManager::updateSoftKeys();
     8358#endif
    78828359        actionEvent((QActionEvent*)event);
    78838360        break;
     
    79028379        break;
    79038380#endif
     8381    case QEvent::TouchBegin:
     8382    case QEvent::TouchUpdate:
     8383    case QEvent::TouchEnd:
     8384    {
     8385#ifndef Q_WS_MAC
     8386        QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
     8387        const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first();
     8388        if (touchPoint.isPrimary() || touchEvent->deviceType() == QTouchEvent::TouchPad)
     8389            break;
     8390
     8391        // fake a mouse event!
     8392        QEvent::Type eventType = QEvent::None;
     8393        switch (touchEvent->type()) {
     8394        case QEvent::TouchBegin:
     8395            eventType = QEvent::MouseButtonPress;
     8396            break;
     8397        case QEvent::TouchUpdate:
     8398            eventType = QEvent::MouseMove;
     8399            break;
     8400        case QEvent::TouchEnd:
     8401            eventType = QEvent::MouseButtonRelease;
     8402            break;
     8403        default:
     8404            Q_ASSERT(!true);
     8405            break;
     8406        }
     8407        if (eventType == QEvent::None)
     8408            break;
     8409
     8410        QMouseEvent mouseEvent(eventType,
     8411                               touchPoint.pos().toPoint(),
     8412                               touchPoint.screenPos().toPoint(),
     8413                               Qt::LeftButton,
     8414                               Qt::LeftButton,
     8415                               touchEvent->modifiers());
     8416        (void) QApplication::sendEvent(this, &mouseEvent);
     8417#endif // Q_WS_MAC
     8418        break;
     8419    }
     8420    case QEvent::Gesture:
     8421        event->ignore();
     8422        break;
    79048423#ifndef QT_NO_PROPERTIES
    79058424    case QEvent::DynamicPropertyChange: {
     
    79538472    case QEvent::FontChange:
    79548473    case QEvent::StyleChange: {
     8474        Q_D(QWidget);
    79558475        update();
    79568476        updateGeometry();
     8477        if (d->layout)
     8478            d->layout->invalidate();
    79578479#ifdef Q_WS_QWS
    7958         Q_D(QWidget);
    79598480        if (isWindow())
    79608481            d->data.fstrut_dirty = true;
     
    80368557        event->accept();
    80378558        QWidget* w;
    8038         while ((w = qApp->activePopupWidget()) && w != this){
     8559        while ((w = QApplication::activePopupWidget()) && w != this){
    80398560            w->close();
    8040             if (qApp->activePopupWidget() == w) // widget does not want to dissappear
     8561            if (QApplication::activePopupWidget() == w) // widget does not want to dissappear
    80418562                w->hide(); // hide at least
    80428563        }
     
    80668587    The default implementation generates a normal mouse press event.
    80678588
    8068     Note that the widgets gets a mousePressEvent() and a
    8069     mouseReleaseEvent() before the mouseDoubleClickEvent().
     8589    \note The widget will also receive mouse press and mouse release
     8590    events in addition to the double click event. It is up to the
     8591    developer to ensure that the application interprets these events
     8592    correctly.
    80708593
    80718594    \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
     
    84488971    \a query specifies which property is queried.
    84498972
    8450     \sa inputMethodEvent(), QInputMethodEvent, QInputContext
     8973    \sa inputMethodEvent(), QInputMethodEvent, QInputContext, inputMethodHints
    84518974*/
    84528975QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const
     
    84578980    case Qt::ImFont:
    84588981        return font();
     8982    case Qt::ImAnchorPosition:
     8983        // Fallback.
     8984        return inputMethodQuery(Qt::ImCursorPosition);
    84598985    default:
    84608986        return QVariant();
    84618987    }
    84628988}
     8989
     8990/*!
     8991    \property QWidget::inputMethodHints
     8992    \brief What input method specific hints the widget has.
     8993
     8994    This is only relevant for input widgets. It is used by
     8995    the input method to retrieve hints as to how the input method
     8996    should operate. For example, if the Qt::ImhFormattedNumbersOnly flag
     8997    is set, the input method may change its visual components to reflect
     8998    that only numbers can be entered.
     8999
     9000    \note The flags are only hints, so the particular input method
     9001          implementation is free to ignore them. If you want to be
     9002          sure that a certain type of characters are entered,
     9003          you should also set a QValidator on the widget.
     9004
     9005    The default value is Qt::ImhNone.
     9006
     9007    \since 4.6
     9008
     9009    \sa inputMethodQuery(), QInputContext
     9010*/
     9011Qt::InputMethodHints QWidget::inputMethodHints() const
     9012{
     9013    Q_D(const QWidget);
     9014#ifndef QT_NO_IM
     9015    return d->imHints;
     9016#else //QT_NO_IM
     9017    return 0;
     9018#endif //QT_NO_IM
     9019}
     9020
     9021void QWidget::setInputMethodHints(Qt::InputMethodHints hints)
     9022{
     9023#ifndef QT_NO_IM
     9024    Q_D(QWidget);
     9025    d->imHints = hints;
     9026    // Optimisation to update input context only it has already been created.
     9027    if (d->ic || qApp->d_func()->inputContext) {
     9028        QInputContext *ic = inputContext();
     9029        if (ic)
     9030            ic->update();
     9031    }
     9032#endif //QT_NO_IM
     9033}
     9034
    84639035
    84649036#ifndef QT_NO_DRAGANDDROP
     
    88039375    that have been added to the layout.
    88049376
    8805     \sa setLayout(), sizePolicy(), {Layout Classes}
     9377    \sa setLayout(), sizePolicy(), {Layout Management}
    88069378*/
    88079379QLayout *QWidget::layout() const
     
    88339405    The QWidget will take ownership of \a layout.
    88349406
    8835     \sa layout(), {Layout Classes}
     9407    \sa layout(), {Layout Management}
    88369408*/
    88379409
     
    92349806#endif
    92359807
    9236     if (newParent) {
    9237         if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) {
     9808    if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) {
     9809        if (newParent)
    92389810            oldBs->removeDirtyWidget(this);
    9239             // Move the widget and all its static children from
    9240             // the old backing store to the new one.
    9241             oldBs->moveStaticWidgets(this);
    9242         }
     9811        // Move the widget and all its static children from
     9812        // the old backing store to the new one.
     9813        oldBs->moveStaticWidgets(this);
    92439814    }
    92449815
     
    92689839    d->resolveLocale();
    92699840
    9270     // Note: GL widgets under Windows will always need a ParentChange
    9271     // event to handle recreation/rebinding of the GL context, hence
    9272     // the (f & Qt::MSWindowsOwnDC) clause
     9841    // Note: GL widgets under WGL or EGL will always need a ParentChange
     9842    // event to handle recreation/rebinding of the GL context, hence the
     9843    // (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all
     9844    // platforms).
    92739845    if (newParent
    9274 #ifdef Q_WS_WIN
     9846#if defined(Q_WS_WIN) || defined(QT_OPENGL_ES)
    92759847        || (f & Qt::MSWindowsOwnDC)
    92769848#endif
     
    93709942#ifndef QT_NO_GRAPHICSVIEW
    93719943    if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) {
    9372         // Graphics View maintains its own dirty region as a list of rects;
    9373         // until we can connect item updates directly to the view, we must
    9374         // separately add a translated dirty region.
    9375         if (!d->dirty.isEmpty()) {
    9376             foreach (const QRect &rect, (d->dirty.translated(dx, dy)).rects())
    9377                 proxy->update(rect);
    9378         }
     9944        // Graphics View maintains its own dirty region as a list of rects;
     9945        // until we can connect item updates directly to the view, we must
     9946        // separately add a translated dirty region.
     9947        if (!d->dirty.isEmpty()) {
     9948            foreach (const QRect &rect, (d->dirty.translated(dx, dy)).rects())
     9949                proxy->update(rect);
     9950        }
    93799951        proxy->scroll(dx, dy, proxy->subWidgetRect(this));
    93809952        return;
     
    94059977#ifndef QT_NO_GRAPHICSVIEW
    94069978    if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) {
    9407         // Graphics View maintains its own dirty region as a list of rects;
    9408         // until we can connect item updates directly to the view, we must
    9409         // separately add a translated dirty region.
    9410         if (!d->dirty.isEmpty()) {
    9411             foreach (const QRect &rect, (d->dirty.translated(dx, dy) & r).rects())
    9412                 proxy->update(rect);
    9413         }
     9979        // Graphics View maintains its own dirty region as a list of rects;
     9980        // until we can connect item updates directly to the view, we must
     9981        // separately add a translated dirty region.
     9982        if (!d->dirty.isEmpty()) {
     9983            foreach (const QRect &rect, (d->dirty.translated(dx, dy) & r).rects())
     9984                proxy->update(rect);
     9985        }
    94149986        proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint()));
    94159987        return;
     
    947710049        return;
    947810050
    9479     QTLWExtra *tlwExtra = !d->paintOnScreen() ? window()->d_func()->maybeTopData() : 0;
    9480     if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) {
    9481         tlwExtra->inRepaint = true;
    9482         tlwExtra->backingStore->markDirty(rect, this, true);
    9483         tlwExtra->inRepaint = false;
     10051    if (hasBackingStoreSupport()) {
     10052        QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
     10053        if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) {
     10054            tlwExtra->inRepaint = true;
     10055            tlwExtra->backingStore->markDirty(rect, this, true);
     10056            tlwExtra->inRepaint = false;
     10057        }
    948410058    } else {
    948510059        d->repaint_sys(rect);
     
    950410078        return;
    950510079
    9506     QTLWExtra *tlwExtra = !d->paintOnScreen() ? window()->d_func()->maybeTopData() : 0;
    9507     if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) {
    9508         tlwExtra->inRepaint = true;
    9509         tlwExtra->backingStore->markDirty(rgn, this, true);
    9510         tlwExtra->inRepaint = false;
     10080    if (hasBackingStoreSupport()) {
     10081        QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
     10082        if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) {
     10083            tlwExtra->inRepaint = true;
     10084            tlwExtra->backingStore->markDirty(rgn, this, true);
     10085            tlwExtra->inRepaint = false;
     10086        }
    951110087    } else {
    951210088        d->repaint_sys(rgn);
     
    969010266
    969110267#if defined(Q_WS_WIN) || defined(Q_WS_PM)
    9692     if (attribute == Qt::WA_PaintOnScreen && on) {
     10268    // ### Don't use PaintOnScreen+paintEngine() to do native painting in 5.0
     10269    if (attribute == Qt::WA_PaintOnScreen && on && !inherits("QGLWidget")) {
    969310270        // see qwidget_[win|pm].cpp, ::paintEngine for details
    969410271        paintEngine();
     
    980410381                                    ? Qt::WindowModal
    980510382                                    : Qt::ApplicationModal;
     10383            // Some window managers does not allow us to enter modal after the
     10384            // window is showing. Therefore, to be consistent, we cannot call
     10385            // QApplicationPrivate::enterModal(this) here. The window must be
     10386            // hidden before changing modality.
    980610387        }
    980710388        if (testAttribute(Qt::WA_WState_Created)) {
     
    981410395        QApplication::sendEvent(this, &e);
    981510396        break; }
    9816 #if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
    9817     case Qt::WA_MSWindowsUseDirect3D:
    9818         if (!qApp->testAttribute(Qt::AA_MSWindowsUseDirect3DByDefault)) {
    9819             if (on) {
    9820                 if (!d->extra)
    9821                     d->createExtra();
    9822                 d->extra->had_auto_fill_bg = d->extra->autoFillBackground;
    9823                 d->extra->had_no_system_bg = testAttribute(Qt::WA_NoSystemBackground);
    9824                 d->extra->had_paint_on_screen = testAttribute(Qt::WA_PaintOnScreen);
    9825                 // enforce the opaque widget state D3D needs
    9826                 d->extra->autoFillBackground = true;
    9827                 setAttribute(Qt::WA_PaintOnScreen);
    9828                 setAttribute(Qt::WA_NoSystemBackground);
    9829             } else if (d->extra) {
    9830                 d->extra->autoFillBackground = d->extra->had_auto_fill_bg;
    9831                 setAttribute(Qt::WA_PaintOnScreen, d->extra->had_paint_on_screen);
    9832                 setAttribute(Qt::WA_NoSystemBackground, d->extra->had_no_system_bg);
    9833             }
    9834         }
    9835         break;
    9836 #endif
    983710397    case Qt::WA_NativeWindow: {
    983810398#ifndef QT_NO_IM
     10399        QWidget *focusWidget = d->effectiveFocusWidget();
    983910400        QInputContext *ic = 0;
    984010401        if (on && !internalWinId() && testAttribute(Qt::WA_InputMethodEnabled) && hasFocus()) {
    9841             ic = d->inputContext();
     10402            ic = focusWidget->d_func()->inputContext();
    984210403            ic->reset();
    984310404            ic->setFocusWidget(0);
     
    984810409        if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created))
    984910410            d->createWinId();
    9850 #ifndef QT_NO_IM
    9851         if (ic)
    9852             ic->setFocusWidget(this);
    9853 #endif
     10411        if (ic && isEnabled())
     10412            ic->setFocusWidget(focusWidget);
     10413#endif //QT_NO_IM
    985410414        break;
    985510415    }
     
    988110441        break;
    988210442    case Qt::WA_InputMethodEnabled: {
    9883 #if defined(Q_WS_WIN) || (defined(Q_WS_QWS) && !defined(QT_NO_QWS_INPUTMETHODS))
    9884         if (hasFocus())
    9885             QInputContextPrivate::updateImeStatus(this, true);
    9886 #endif
    988710443#ifndef QT_NO_IM
    9888         QInputContext *ic = d->ic;
    9889         if (!ic) {
    9890             // implicitly create input context only if we have a focus
    9891             if (hasFocus())
    9892                 ic = d->inputContext();
    9893         }
     10444        QWidget *focusWidget = d->effectiveFocusWidget();
     10445        QInputContext *ic = focusWidget->d_func()->ic;
     10446        if (!ic && (!on || hasFocus()))
     10447            ic = focusWidget->d_func()->inputContext();
    989410448        if (ic) {
    9895             if (on && hasFocus() && ic->focusWidget() != this) {
    9896                 ic->setFocusWidget(this);
    9897             } else if (!on && ic->focusWidget() == this) {
     10449            if (on && hasFocus() && ic->focusWidget() != focusWidget && isEnabled()) {
     10450                ic->setFocusWidget(focusWidget);
     10451            } else if (!on && ic->focusWidget() == focusWidget) {
    989810452                ic->reset();
    989910453                ic->setFocusWidget(0);
    990010454            }
    990110455        }
    9902 #endif
     10456#endif //QT_NO_IM
    990310457        break;
    990410458    }
     
    997110525
    997210526        break;
     10527    case Qt::WA_AcceptTouchEvents:
     10528#if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_WS_S60)
     10529        if (on)
     10530            d->registerTouchWindow();
     10531#endif
     10532        break;
    997310533    default:
    997410534        break;
     
    1000110561  By default the value of this property is 1.0.
    1000210562
    10003   This feature is available on Embedded Linux, Mac OS X, X11 platforms that
    10004   support the Composite extension, and Windows 2000 and later.
     10563  This feature is available on Embedded Linux, Mac OS X, Windows,
     10564  and X11 platforms that support the Composite extension.
    1000510565
    1000610566  This feature is not available on Windows CE.
     
    1032610886void QWidget::updateMicroFocus()
    1032710887{
    10328 #if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS))
     10888#if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
    1032910889    Q_D(QWidget);
    1033010890    // and optimisation to update input context only it has already been created.
     
    1103311593*/
    1103411594
     11595/*!
     11596    \fn QWidget::setupUi(QWidget *widget)
     11597
     11598    Sets up the user interface for the specified \a widget.
     11599
     11600    \note This function is available with widgets that derive from user
     11601    interface descriptions created using \l{uic}.
     11602
     11603    \sa {Using a Designer UI File in Your Application}
     11604*/
     11605
    1103511606QRect QWidgetPrivate::frameStrut() const
    1103611607{
     
    1105111622    return maybeTopData() ? maybeTopData()->frameStrut : QRect();
    1105211623}
     11624
     11625#ifdef QT_KEYPAD_NAVIGATION
     11626/*!
     11627    \internal
     11628
     11629    Changes the focus  from the current focusWidget to a widget in
     11630    the \a direction.
     11631
     11632    Returns true, if there was a widget in that direction
     11633*/
     11634bool QWidgetPrivate::navigateToDirection(Direction direction)
     11635{
     11636    QWidget *targetWidget = widgetInNavigationDirection(direction);
     11637    if (targetWidget)
     11638        targetWidget->setFocus();
     11639    return (targetWidget != 0);
     11640}
     11641
     11642/*!
     11643    \internal
     11644
     11645    Searches for a widget that is positioned in the \a direction, starting
     11646    from the current focusWidget.
     11647
     11648    Returns the pointer to a found widget or 0, if there was no widget in
     11649    that direction.
     11650*/
     11651QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction)
     11652{
     11653    const QWidget *sourceWidget = QApplication::focusWidget();
     11654    if (!sourceWidget)
     11655        return 0;
     11656    const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint()));
     11657    const int sourceX =
     11658            (direction == DirectionNorth || direction == DirectionSouth) ?
     11659                (sourceRect.left() + (sourceRect.right() - sourceRect.left()) / 2)
     11660                :(direction == DirectionEast ? sourceRect.right() : sourceRect.left());
     11661    const int sourceY =
     11662            (direction == DirectionEast || direction == DirectionWest) ?
     11663                (sourceRect.top() + (sourceRect.bottom() - sourceRect.top()) / 2)
     11664                :(direction == DirectionSouth ? sourceRect.bottom() : sourceRect.top());
     11665    const QPoint sourcePoint(sourceX, sourceY);
     11666    const QPoint sourceCenter = sourceRect.center();
     11667    const QWidget *sourceWindow = sourceWidget->window();
     11668
     11669    QWidget *targetWidget = 0;
     11670    int shortestDistance = INT_MAX;
     11671    foreach(QWidget *targetCandidate, QApplication::allWidgets()) {
     11672
     11673        const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint()));
     11674
     11675        // For focus proxies, the child widget handling the focus can have keypad navigation focus,
     11676        // but the owner of the proxy cannot.
     11677        // Additionally, empty widgets should be ignored.
     11678        if (targetCandidate->focusProxy() || targetCandidateRect.isEmpty())
     11679            continue;
     11680
     11681        // Only navigate to a target widget that...
     11682        if (       targetCandidate != sourceWidget
     11683                   // ...takes the focus,
     11684                && targetCandidate->focusPolicy() & Qt::TabFocus
     11685                   // ...is above if DirectionNorth,
     11686                && !(direction == DirectionNorth && targetCandidateRect.bottom() > sourceRect.top())
     11687                   // ...is on the right if DirectionEast,
     11688                && !(direction == DirectionEast  && targetCandidateRect.left()   < sourceRect.right())
     11689                   // ...is below if DirectionSouth,
     11690                && !(direction == DirectionSouth && targetCandidateRect.top()    < sourceRect.bottom())
     11691                   // ...is on the left if DirectionWest,
     11692                && !(direction == DirectionWest  && targetCandidateRect.right()  > sourceRect.left())
     11693                   // ...is enabled,
     11694                && targetCandidate->isEnabled()
     11695                   // ...is visible,
     11696                && targetCandidate->isVisible()
     11697                   // ...is in the same window,
     11698                && targetCandidate->window() == sourceWindow) {
     11699            const int targetCandidateDistance = pointToRect(sourcePoint, targetCandidateRect);
     11700            if (targetCandidateDistance < shortestDistance) {
     11701                shortestDistance = targetCandidateDistance;
     11702                targetWidget = targetCandidate;
     11703            }
     11704        }
     11705    }
     11706    return targetWidget;
     11707}
     11708#endif
    1105311709
    1105411710/*!
     
    1121011866
    1121111867
    11212 
    11213 
    1121411868#ifndef QT_NO_GRAPHICSVIEW
    1121511869/*!
     
    1124011894*/
    1124111895
    11242 QT_END_NAMESPACE
    11243 
    11244 #include "moc_qwidget.cpp"
     11896/*!
     11897    Subscribes the widget to a given \a gesture with specific \a flags.
     11898
     11899    \sa ungrabGesture(), QGestureEvent
     11900    \since 4.6
     11901*/
     11902void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags)
     11903{
     11904    Q_D(QWidget);
     11905    d->gestureContext.insert(gesture, flags);
     11906    (void)QGestureManager::instance(); // create a gesture manager
     11907}
     11908
     11909/*!
     11910    Unsubscribes the widget from a given \a gesture type
     11911
     11912    \sa grabGesture(), QGestureEvent
     11913    \since 4.6
     11914*/
     11915void QWidget::ungrabGesture(Qt::GestureType gesture)
     11916{
     11917    Q_D(QWidget);
     11918    if (d->gestureContext.remove(gesture)) {
     11919        QGestureManager *manager = QGestureManager::instance();
     11920        manager->cleanupCachedGestures(this, gesture);
     11921    }
     11922}
     11923
    1124511924
    1124611925/*!
     
    1131411993    button is released.
    1131511994
    11316     Note that only visible widgets can grab mouse input. If
    11317     isVisible() returns false for a widget, that widget cannot call
    11318     grabMouse().
    11319 
    11320     \sa releaseMouse() grabKeyboard() releaseKeyboard() grabKeyboard()
    11321     focusWidget()
     11995    \note Only visible widgets can grab mouse input. If isVisible()
     11996    returns false for a widget, that widget cannot call grabMouse().
     11997
     11998    \note \bold{(Mac OS X developers)} For \e Cocoa, calling
     11999    grabMouse() on a widget only works when the mouse is inside the
     12000    frame of that widget.  For \e Carbon, it works outside the widget's
     12001    frame as well, like for Windows and X11.
     12002
     12003    \sa releaseMouse() grabKeyboard() releaseKeyboard()
    1132212004*/
    1132312005
    1132412006/*!
    1132512007    \fn void QWidget::grabMouse(const QCursor &cursor)
    11326     \overload
     12008    \overload grabMouse()
    1132712009
    1132812010    Grabs the mouse input and changes the cursor shape.
     
    1133312015
    1133412016    \warning Grabbing the mouse might lock the terminal.
     12017
     12018    \note \bold{(Mac OS X developers)} See the note in QWidget::grabMouse().
    1133512019
    1133612020    \sa releaseMouse(), grabKeyboard(), releaseKeyboard(), setCursor()
     
    1153912223}
    1154012224
     12225/*! \fn const QX11Info &QWidget::x11Info() const
     12226    Returns information about the configuration of the X display used to display
     12227    the widget.
     12228
     12229    \warning This function is only available on X11.
     12230*/
     12231
     12232/*! \fn Qt::HANDLE QWidget::x11PictureHandle() const
     12233    Returns the X11 Picture handle of the widget for XRender
     12234    support. Use of this function is not portable. This function will
     12235    return 0 if XRender support is not compiled into Qt, if the
     12236    XRender extension is not supported on the X11 display, or if the
     12237    handle could not be created.
     12238*/
     12239
     12240#ifdef Q_OS_SYMBIAN
     12241void QWidgetPrivate::_q_delayedDestroy(WId winId)
     12242{
     12243    delete winId;
     12244}
     12245#endif
     12246
     12247QT_END_NAMESPACE
     12248
     12249#include "moc_qwidget.cpp"
     12250
Note: See TracChangeset for help on using the changeset viewer.