~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/kernel/qwidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/****************************************************************************
2
2
**
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
 
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
5
6
**
6
7
** This file is part of the QtGui module of the Qt Toolkit.
7
8
**
8
9
** $QT_BEGIN_LICENSE:LGPL$
9
 
** Commercial Usage
10
 
** Licensees holding valid Qt Commercial licenses may use this file in
11
 
** accordance with the Qt Commercial License Agreement provided with the
12
 
** Software or, alternatively, in accordance with the terms contained in
13
 
** a written agreement between you and Nokia.
 
10
** No Commercial Usage
 
11
** This file contains pre-release code and may not be distributed.
 
12
** You may use this file in accordance with the terms and conditions
 
13
** contained in the Technology Preview License Agreement accompanying
 
14
** this package.
14
15
**
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22
23
**
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.
27
 
**
28
 
** GNU General Public License Usage
29
 
** Alternatively, this file may be used under the terms of the GNU
30
 
** General Public License version 3.0 as published by the Free Software
31
 
** Foundation and appearing in the file LICENSE.GPL included in the
32
 
** packaging of this file.  Please review the following information to
33
 
** ensure the GNU General Public License version 3.0 requirements will be
34
 
** met: http://www.gnu.org/copyleft/gpl.html.
35
 
**
36
 
** If you are unsure which license is appropriate for your use, please
37
 
** contact the sales department at http://www.qtsoftware.com/contact.
 
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.
 
27
**
 
28
** If you have questions regarding the use of this file, please contact
 
29
** Nokia at qt-info@nokia.com.
 
30
**
 
31
**
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
38
38
** $QT_END_LICENSE$
39
39
**
40
40
****************************************************************************/
82
82
#include "private/qstyle_p.h"
83
83
#include "private/qinputcontext_p.h"
84
84
#include "qfileinfo.h"
 
85
#include "private/qsoftkeymanager_p.h"
85
86
 
86
87
#if defined (Q_WS_WIN)
87
88
# include <private/qwininputcontext_p.h>
99
100
#endif
100
101
#include <private/qpaintengine_raster_p.h>
101
102
 
 
103
#if defined(Q_OS_SYMBIAN)
 
104
#include "private/qt_s60_p.h"
 
105
#endif
 
106
 
102
107
#include "qwidget_p.h"
103
108
#include "qaction_p.h"
104
109
#include "qlayout_p.h"
107
112
#include "private/qgraphicsproxywidget_p.h"
108
113
#include "QtGui/qabstractscrollarea.h"
109
114
#include "private/qabstractscrollarea_p.h"
 
115
#include "private/qevent_p.h"
110
116
 
111
117
#include "private/qgraphicssystem_p.h"
 
118
#include "private/qgesturemanager_p.h"
112
119
 
113
120
// widget/widget data creation count
114
121
//#define QWIDGET_EXTRA_DEBUG
167
174
extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp
168
175
extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp
169
176
 
170
 
QWidgetPrivate::QWidgetPrivate(int version) :
171
 
        QObjectPrivate(version), extra(0), focus_child(0)
172
 
        ,layout(0), widgetItem(0)
173
 
        ,leftmargin(0), topmargin(0), rightmargin(0), bottommargin(0)
174
 
        ,leftLayoutItemMargin(0), topLayoutItemMargin(0), rightLayoutItemMargin(0)
175
 
        ,bottomLayoutItemMargin(0)
176
 
        ,fg_role(QPalette::NoRole)
177
 
        ,bg_role(QPalette::NoRole)
178
 
        ,hd(0)
179
 
        ,dirty(0)
180
 
        ,needsFlush(0)
181
 
        ,dirtyOpaqueChildren(1)
182
 
        ,isOpaque(0)
183
 
        ,inDirtyList(0)
184
 
        ,isScrolled(0)
185
 
        ,isMoved(0)
186
 
        ,usesDoubleBufferedGLContext(0)
187
 
#ifdef Q_WS_WIN
188
 
        ,noPaintOnScreen(0)
 
177
QWidgetPrivate::QWidgetPrivate(int version)
 
178
    : QObjectPrivate(version)
 
179
      , extra(0)
 
180
      , focus_next(0)
 
181
      , focus_prev(0)
 
182
      , focus_child(0)
 
183
      , layout(0)
 
184
      , needsFlush(0)
 
185
      , redirectDev(0)
 
186
      , widgetItem(0)
 
187
      , extraPaintEngine(0)
 
188
      , polished(0)
 
189
      , graphicsEffect(0)
 
190
#if !defined(QT_NO_IM)
 
191
      , imHints(Qt::ImhNone)
189
192
#endif
190
 
        ,inheritedFontResolveMask(0)
191
 
        ,inheritedPaletteResolveMask(0)
 
193
      , inheritedFontResolveMask(0)
 
194
      , inheritedPaletteResolveMask(0)
 
195
      , leftmargin(0)
 
196
      , topmargin(0)
 
197
      , rightmargin(0)
 
198
      , bottommargin(0)
 
199
      , leftLayoutItemMargin(0)
 
200
      , topLayoutItemMargin(0)
 
201
      , rightLayoutItemMargin(0)
 
202
      , bottomLayoutItemMargin(0)
 
203
      , hd(0)
 
204
      , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred)
 
205
      , fg_role(QPalette::NoRole)
 
206
      , bg_role(QPalette::NoRole)
 
207
      , dirtyOpaqueChildren(1)
 
208
      , isOpaque(0)
 
209
      , inDirtyList(0)
 
210
      , isScrolled(0)
 
211
      , isMoved(0)
 
212
      , usesDoubleBufferedGLContext(0)
192
213
#if defined(Q_WS_X11)
193
 
        ,picture(0)
194
 
#endif
195
 
#ifdef Q_WS_MAC
196
 
        ,needWindowChange(0)
197
 
        ,isGLWidget(0)
198
 
#endif
199
 
        ,polished(0)
200
 
 
201
 
        , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred)
202
 
        , redirectDev(0)
 
214
      , picture(0)
 
215
#elif defined(Q_WS_WIN)
 
216
      , noPaintOnScreen(0)
 
217
#elif defined(Q_WS_MAC)
 
218
      , needWindowChange(0)
 
219
      , isGLWidget(0)
 
220
      , window_event(0)
 
221
      , qd_hd(0)
 
222
#endif
203
223
{
204
224
    if (!qApp) {
205
225
        qFatal("QWidget: Must construct a QApplication before a QPaintDevice");
225
245
 
226
246
    if (extra)
227
247
        deleteExtra();
 
248
 
 
249
    delete graphicsEffect;
228
250
}
229
251
 
230
252
QWindowSurface *QWidgetPrivate::createDefaultWindowSurface()
442
464
    \brief The QWidget class is the base class of all user interface objects.
443
465
 
444
466
    \ingroup basicwidgets
445
 
    \mainclass
 
467
 
446
468
 
447
469
    The widget is the atom of the user interface: it receives mouse, keyboard
448
470
    and other events from the window system, and paints a representation of
493
515
    been outlined to indicate their full sizes.
494
516
 
495
517
    If you want to use a QWidget to hold child widgets you will usually want to
496
 
    add a layout to the parent QWidget. See \l{Layout Classes} for more
 
518
    add a layout to the parent QWidget. See \l{Layout Management} for more
497
519
    information.
498
520
 
499
521
 
851
873
    \list
852
874
    \o X11: This feature relies on the use of an X server that supports ARGB visuals
853
875
    and a compositing window manager.
854
 
    \o Windows: This feature requires Windows 2000 or later. The widget needs to have
855
 
    the Qt::FramelessWindowHint window flag set for the translucency to work.
 
876
    \o Windows: The widget needs to have the Qt::FramelessWindowHint window flag set
 
877
    for the translucency to work.
856
878
    \endlist
857
879
 
858
880
 
878
900
    \endlist
879
901
 
880
902
    \sa QEvent, QPainter, QGridLayout, QBoxLayout
 
903
 
 
904
    \section1 Softkeys
 
905
    \since 4.6
 
906
 
 
907
    Softkeys are usually physical keys on a device that have a corresponding label or
 
908
    other visual representation on the screen that is generally located next to its
 
909
    physical counterpart. They are most often found on mobile phone platforms. In
 
910
    modern touch based user interfaces it is also possible to have softkeys that do
 
911
    not correspond to any physical keys. Softkeys differ from other onscreen labels
 
912
    in that they are contextual.
 
913
 
 
914
    In Qt, contextual softkeys are added to a widget by calling addAction() and
 
915
    passing a \c QAction with a softkey role set on it. When the widget
 
916
    containing the softkey actions has focus, its softkeys should appear in
 
917
    the user interface. Softkeys are discovered by traversing the widget
 
918
    heirarchy so it is possible to define a single set of softkeys that are
 
919
    present at all times by calling addAction() for a given top level widget.
 
920
 
 
921
    On some platforms, this concept overlaps with \c QMenuBar such that if no
 
922
    other softkeys are found and the top level widget is a QMainWindow containing
 
923
    a QMenuBar, the menubar actions may appear on one of the softkeys.
 
924
 
 
925
    Note: Currently softkeys are only supported on the Symbian Platform.
 
926
 
 
927
    \sa addAction(), QAction, QMenuBar
 
928
 
881
929
*/
882
930
 
883
 
QWidgetMapper *QWidgetPrivate::mapper = 0;                // widget with wid
884
 
QWidgetSet *QWidgetPrivate::uncreatedWidgets = 0;         // widgets with no wid
 
931
QWidgetMapper *QWidgetPrivate::mapper = 0;          // widget with wid
 
932
QWidgetSet *QWidgetPrivate::allWidgets = 0;         // widgets with no wid
885
933
 
886
934
 
887
935
/*****************************************************************************
921
969
  \endlist
922
970
*/
923
971
 
 
972
struct QWidgetExceptionCleaner
 
973
{
 
974
    /* this cleans up when the constructor throws an exception */
 
975
    static inline void cleanup(QWidget *that, QWidgetPrivate *d)
 
976
    {
 
977
#ifdef QT_NO_EXCEPTIONS
 
978
        Q_UNUSED(that);
 
979
        Q_UNUSED(d);
 
980
#else
 
981
        QWidgetPrivate::allWidgets->remove(that);
 
982
        if (d->focus_next != that) {
 
983
            if (d->focus_next)
 
984
                d->focus_next->d_func()->focus_prev = d->focus_prev;
 
985
            if (d->focus_prev)
 
986
                d->focus_prev->d_func()->focus_next = d->focus_next;
 
987
        }
 
988
#endif
 
989
    }
 
990
};
 
991
 
924
992
/*!
925
993
    Constructs a widget which is a child of \a parent, with  widget
926
994
    flags set to \a f.
950
1018
QWidget::QWidget(QWidget *parent, Qt::WindowFlags f)
951
1019
    : QObject(*new QWidgetPrivate, 0), QPaintDevice()
952
1020
{
953
 
    d_func()->init(parent, f);
 
1021
    QT_TRY {
 
1022
        d_func()->init(parent, f);
 
1023
    } QT_CATCH(...) {
 
1024
        QWidgetExceptionCleaner::cleanup(this, d_func());
 
1025
        QT_RETHROW;
 
1026
    }
954
1027
}
955
1028
 
956
1029
#ifdef QT3_SUPPORT
961
1034
QWidget::QWidget(QWidget *parent, const char *name, Qt::WindowFlags f)
962
1035
    : QObject(*new QWidgetPrivate, 0), QPaintDevice()
963
1036
{
964
 
    d_func()->init(parent , f);
965
 
    setObjectName(QString::fromAscii(name));
 
1037
    QT_TRY {
 
1038
        d_func()->init(parent , f);
 
1039
        setObjectName(QString::fromAscii(name));
 
1040
    } QT_CATCH(...) {
 
1041
        QWidgetExceptionCleaner::cleanup(this, d_func());
 
1042
        QT_RETHROW;
 
1043
    }
966
1044
}
967
1045
#endif
968
1046
 
971
1049
QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f)
972
1050
    : QObject(dd, 0), QPaintDevice()
973
1051
{
974
 
    d_func()->init(parent, f);
 
1052
    Q_D(QWidget);
 
1053
    QT_TRY {
 
1054
        d->init(parent, f);
 
1055
    } QT_CATCH(...) {
 
1056
        QWidgetExceptionCleaner::cleanup(this, d_func());
 
1057
        QT_RETHROW;
 
1058
    }
975
1059
}
976
1060
 
977
1061
/*!
1027
1111
    if (customize)
1028
1112
        ; // don't modify window flags if the user explicitely set them.
1029
1113
    else if (type == Qt::Dialog || type == Qt::Sheet)
1030
 
#ifndef Q_OS_WINCE
 
1114
#ifndef Q_WS_WINCE
1031
1115
        flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint | Qt::WindowCloseButtonHint;
1032
1116
#else
1033
1117
        flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
1043
1127
void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
1044
1128
{
1045
1129
    Q_Q(QWidget);
1046
 
    if (qApp->type() == QApplication::Tty)
 
1130
    if (QApplication::type() == QApplication::Tty)
1047
1131
        qFatal("QWidget: Cannot create a QWidget when no GUI is being used");
1048
1132
 
1049
 
    Q_ASSERT(uncreatedWidgets);
1050
 
    uncreatedWidgets->insert(q);
 
1133
    Q_ASSERT(allWidgets);
 
1134
    allWidgets->insert(q);
1051
1135
 
1052
1136
    QWidget *desktopWidget = 0;
1053
1137
    if (parentWidget && parentWidget->windowType() == Qt::Desktop) {
1058
1142
    q->data = &data;
1059
1143
 
1060
1144
#ifndef QT_NO_THREAD
1061
 
    if (!q->parent()) {
 
1145
    if (!parent) {
1062
1146
        Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget",
1063
1147
                   "Widgets must be created in the GUI thread.");
1064
1148
    }
1094
1178
    if (f & Qt::MSWindowsOwnDC)
1095
1179
        q->setAttribute(Qt::WA_NativeWindow);
1096
1180
 
1097
 
#ifdef Q_OS_WINCE
1098
 
    data.window_state_internal = 0;
1099
 
#endif
1100
 
 
1101
1181
    q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute()
1102
1182
    adjustQuitOnCloseAttribute();
1103
1183
 
1253
1333
    d->create_sys(window, initializeWindow, destroyOldWindow);
1254
1334
 
1255
1335
    // a real toplevel window needs a backing store
1256
 
    if (isWindow()) {
 
1336
    if (isWindow() && windowType() != Qt::Desktop) {
1257
1337
        delete d->topData()->backingStore;
1258
1338
        // QWidgetBackingStore will check this variable, hence it must be 0
1259
1339
        d->topData()->backingStore = 0;
1336
1416
#ifdef QT3_SUPPORT
1337
1417
    if (QApplicationPrivate::main_widget == this) {        // reset main widget
1338
1418
        QApplicationPrivate::main_widget = 0;
1339
 
        qApp->quit();
 
1419
        QApplication::quit();
1340
1420
    }
1341
1421
#endif
1342
1422
 
1343
 
    clearFocus();
 
1423
    QT_TRY {
 
1424
        clearFocus();
 
1425
    } QT_CATCH(...) {
 
1426
        // swallow this problem because we are in a destructor
 
1427
    }
1344
1428
 
1345
1429
    d->setDirtyOpaqueRegion();
1346
1430
 
1347
 
    if (isWindow() && isVisible() && internalWinId())
1348
 
        hide();
1349
 
#if defined(Q_WS_WIN) || defined(Q_WS_X11)
1350
 
    else if (!internalWinId() && isVisible())
1351
 
        qApp->d_func()->sendSyntheticEnterLeave(this);
 
1431
    if (isWindow() && isVisible() && internalWinId()) {
 
1432
        QT_TRY {
 
1433
            d->close_helper(QWidgetPrivate::CloseNoEvent);
 
1434
        } QT_CATCH(...) {
 
1435
            // if we're out of memory, at least hide the window.
 
1436
            QT_TRY {
 
1437
                hide();
 
1438
            } QT_CATCH(...) {
 
1439
                // and if that also doesn't work, then give up
 
1440
            }
 
1441
        }
 
1442
    }
 
1443
 
 
1444
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS)
 
1445
    else if (!internalWinId() && isVisible()) {
 
1446
        qApp->d_func()->sendSyntheticEnterLeave(this);
 
1447
#ifdef Q_WS_QWS
 
1448
    } else if (isVisible()) {
 
1449
        qApp->d_func()->sendSyntheticEnterLeave(this);
 
1450
#endif
 
1451
    }
1352
1452
#endif
1353
1453
 
1354
1454
    if (QWidgetBackingStore *bs = d->maybeBackingStore()) {
1363
1463
    // set all QPointers for this object to zero
1364
1464
    QObjectPrivate::clearGuards(this);
1365
1465
 
 
1466
    if (d->declarativeData) {
 
1467
        d->declarativeData->destroyed(this);
 
1468
        d->declarativeData = 0;                 // don't activate again in ~QObject
 
1469
    }
 
1470
 
1366
1471
    if (!d->children.isEmpty())
1367
1472
        d->deleteChildren();
1368
1473
 
1369
1474
    QApplication::removePostedEvents(this);
1370
1475
 
1371
 
    destroy();                                        // platform-dependent cleanup
1372
 
 
 
1476
    QT_TRY {
 
1477
        destroy();                                        // platform-dependent cleanup
 
1478
    } QT_CATCH(...) {
 
1479
        // if this fails we can't do anything about it but at least we are not allowed to throw.
 
1480
    }
1373
1481
    --QWidgetPrivate::instanceCounter;
1374
1482
 
1375
 
    if (QWidgetPrivate::uncreatedWidgets) // might have been deleted by ~QApplication
1376
 
        QWidgetPrivate::uncreatedWidgets->remove(this);
 
1483
    if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication
 
1484
        QWidgetPrivate::allWidgets->remove(this);
1377
1485
 
1378
1486
    QEvent e(QEvent::Destroy);
1379
1487
    QCoreApplication::sendEvent(this, &e);
1393
1501
    bool userDesktopWidget = qt_desktopWidget != 0 && qt_desktopWidget != q && q->windowType() == Qt::Desktop;
1394
1502
    if (mapper && data.winid && !userDesktopWidget) {
1395
1503
        mapper->remove(data.winid);
1396
 
        uncreatedWidgets->insert(q);
1397
1504
    }
1398
1505
 
1399
1506
    data.winid = id;
1402
1509
#endif
1403
1510
    if (mapper && id && !userDesktopWidget) {
1404
1511
        mapper->insert(data.winid, q);
1405
 
        uncreatedWidgets->remove(q);
1406
1512
    }
1407
1513
}
1408
1514
 
1412
1518
        createExtra();
1413
1519
    if (!extra->topextra) {
1414
1520
        QTLWExtra* x = extra->topextra = new QTLWExtra;
 
1521
        x->icon = 0;
 
1522
        x->iconPixmap = 0;
 
1523
        x->backingStore = 0;
1415
1524
        x->windowSurface = 0;
 
1525
        x->sharedPainter = 0;
 
1526
        x->incw = x->inch = 0;
 
1527
        x->basew = x->baseh = 0;
 
1528
        x->frameStrut.setCoords(0, 0, 0, 0);
 
1529
        x->normalGeometry = QRect(0,0,-1,-1);
 
1530
        x->savedFlags = 0;
1416
1531
        x->opacity = 255;
1417
1532
        x->posFromMove = false;
1418
1533
        x->sizeAdjusted = false;
1419
1534
        x->inTopLevelResize = false;
1420
1535
        x->inRepaint = false;
1421
 
        x->backingStore = 0;
1422
 
        x->icon = 0;
1423
 
        x->iconPixmap = 0;
1424
 
        x->frameStrut.setCoords(0, 0, 0, 0);
1425
 
        x->incw = x->inch = 0;
1426
 
        x->basew = x->baseh = 0;
1427
 
        x->normalGeometry = QRect(0,0,-1,-1);
1428
 
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_MAC)
1429
1536
        x->embedded = 0;
1430
 
#endif
1431
 
#if defined(Q_WS_X11)
1432
 
        x->parentWinId = 0;
1433
 
        x->spont_unmapped = 0;
1434
 
        x->dnd = 0;
1435
 
#endif
1436
 
        x->savedFlags = 0;
1437
 
#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
1438
 
        x->qwsManager = 0;
1439
 
#endif
1440
 
        x->sharedPainter = 0;
1441
1537
        createTLSysExtra();
1442
1538
#ifdef QWIDGET_EXTRA_DEBUG
1443
 
    static int count = 0;
1444
 
    qDebug() << "tlextra" << ++count;
 
1539
        static int count = 0;
 
1540
        qDebug() << "tlextra" << ++count;
1445
1541
#endif
1446
1542
    }
1447
1543
}
1455
1551
{
1456
1552
    if (!extra) {                                // if not exists
1457
1553
        extra = new QWExtra;
1458
 
        extra->minw = extra->minh = 0;
1459
 
        extra->maxw = extra->maxh = QWIDGETSIZE_MAX;
 
1554
        extra->glContext = 0;
 
1555
        extra->topextra = 0;
 
1556
        extra->proxyWidget = 0;
 
1557
#ifndef QT_NO_CURSOR
 
1558
        extra->curs = 0;
 
1559
#endif
 
1560
        extra->minw = 0;
 
1561
        extra->minh = 0;
 
1562
        extra->maxw = QWIDGETSIZE_MAX;
 
1563
        extra->maxh = QWIDGETSIZE_MAX;
 
1564
        extra->customDpiX = 0;
 
1565
        extra->customDpiY = 0;
1460
1566
        extra->explicitMinSize = 0;
1461
1567
        extra->explicitMaxSize = 0;
1462
1568
        extra->autoFillBackground = 0;
1463
1569
        extra->nativeChildrenForced = 0;
1464
1570
        extra->inRenderWithPainter = 0;
1465
1571
        extra->hasMask = 0;
1466
 
#ifndef QT_NO_CURSOR
1467
 
        extra->curs = 0;
1468
 
#endif
1469
 
        extra->style = 0;
1470
 
        extra->topextra = 0;
1471
 
        extra->proxyWidget = 0;
1472
 
        extra->glContext = 0;
1473
 
        extra->customDpiX = 0;
1474
 
        extra->customDpiY = 0;
1475
1572
        createSysExtra();
1476
1573
#ifdef QWIDGET_EXTRA_DEBUG
1477
 
    static int count = 0;
1478
 
    qDebug() << "extra" << ++count;
 
1574
        static int count = 0;
 
1575
        qDebug() << "extra" << ++count;
1479
1576
#endif
1480
1577
    }
1481
1578
}
1516
1613
}
1517
1614
 
1518
1615
/*
1519
 
  Returns true if the background is inherited; otherwise returns
1520
 
  false.
1521
 
 
1522
 
  Mainly used in the paintOnScreen case.
1523
 
*/
1524
 
 
1525
 
bool QWidgetPrivate::isBackgroundInherited() const
1526
 
{
1527
 
    Q_Q(const QWidget);
1528
 
 
1529
 
    // windows do not inherit their background
1530
 
    if (q->isWindow() || q->windowType() == Qt::SubWindow)
1531
 
        return false;
1532
 
 
1533
 
    if (q->testAttribute(Qt::WA_NoSystemBackground) || q->testAttribute(Qt::WA_OpaquePaintEvent))
1534
 
        return false;
1535
 
 
1536
 
    const QPalette &pal = q->palette();
1537
 
    QPalette::ColorRole bg = q->backgroundRole();
1538
 
    QBrush brush = pal.brush(bg);
1539
 
 
1540
 
    // non opaque brushes leaves us no choice, we must inherit
1541
 
    if (!q->autoFillBackground() || !brush.isOpaque())
1542
 
        return true;
1543
 
 
1544
 
    if (brush.style() == Qt::SolidPattern) {
1545
 
        // the background is just a solid color. If there is no
1546
 
        // propagated contents, then we claim as performance
1547
 
        // optimization that it was not inheritet. This is the normal
1548
 
        // case in standard Windows or Motif style.
1549
 
        const QWidget *w = q->parentWidget();
1550
 
        if (!w->d_func()->isBackgroundInherited())
1551
 
            return false;
1552
 
    }
1553
 
 
1554
 
    return true;
1555
 
}
1556
 
 
1557
 
/*
1558
1616
  Returns true if there are widgets above this which overlap with
1559
1617
  \a rect, which is in parent's coordinate system (same as crect).
1560
1618
*/
1579
1637
                continue;
1580
1638
            }
1581
1639
 
1582
 
            if (qRectIntersects(sibling->data->crect, r)) {
 
1640
            if (qRectIntersects(sibling->d_func()->effectiveRectFor(sibling->data->crect), r)) {
1583
1641
                const QWExtra *siblingExtra = sibling->d_func()->extra;
1584
 
                if (siblingExtra && siblingExtra->hasMask
 
1642
                if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect
1585
1643
                    && !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) {
1586
1644
                    continue;
1587
1645
                }
1680
1738
    const QWidget * w = q;
1681
1739
    if (!w->isVisible())
1682
1740
        return QRect();
1683
 
    QRect r = q->rect();
 
1741
    QRect r = effectiveRectFor(q->rect());
1684
1742
    int ox = 0;
1685
1743
    int oy = 0;
1686
1744
    while (w
1822
1880
            break;
1823
1881
        QWidgetPrivate *pd = w->parentWidget()->d_func();
1824
1882
        const int myIndex = pd->children.indexOf(const_cast<QWidget *>(w));
 
1883
        const QRect widgetGeometry = w->d_func()->effectiveRectFor(w->data->crect);
1825
1884
        for (int i = myIndex + 1; i < pd->children.size(); ++i) {
1826
1885
            QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
1827
1886
            if (!sibling || !sibling->isVisible() || sibling->isWindow())
1828
1887
                continue;
1829
1888
 
1830
 
            if (!qRectIntersects(sibling->data->crect, w->data->crect))
 
1889
            const QRect siblingGeometry = sibling->d_func()->effectiveRectFor(sibling->data->crect);
 
1890
            if (!qRectIntersects(siblingGeometry, widgetGeometry))
1831
1891
                continue;
1832
1892
 
1833
1893
            if (dirtyClipBoundingRect) {
1835
1895
                dirtyClipBoundingRect = false;
1836
1896
            }
1837
1897
 
1838
 
            if (!qRectIntersects(sibling->data->crect, clipBoundingRect.translated(parentOffset)))
 
1898
            if (!qRectIntersects(siblingGeometry, clipBoundingRect.translated(parentOffset)))
1839
1899
                continue;
1840
1900
 
1841
1901
            if (dirtyParentClip) {
1847
1907
            const QRect siblingClipRect(sibling->d_func()->clipRect());
1848
1908
            QRegion siblingDirty(parentClip);
1849
1909
            siblingDirty &= (siblingClipRect.translated(siblingPos));
1850
 
            const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask;
 
1910
            const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask
 
1911
                                 && !sibling->d_func()->graphicsEffect;
1851
1912
            if (hasMask)
1852
1913
                siblingDirty &= sibling->d_func()->extra->mask.translated(siblingPos);
1853
1914
            if (siblingDirty.isEmpty())
1858
1919
                    siblingDirty.translate(-parentOffset);
1859
1920
                    sourceRegion -= siblingDirty;
1860
1921
                } else {
1861
 
                    sourceRegion -= sibling->data->crect.translated(-parentOffset);
 
1922
                    sourceRegion -= siblingGeometry.translated(-parentOffset);
1862
1923
                }
1863
1924
            } else {
1864
1925
                if (hasDirtySiblingsAbove)
1889
1950
    const QWidget *w = q;
1890
1951
    QPoint offset;
1891
1952
 
 
1953
    if (graphicsEffect) {
 
1954
        w = q->parentWidget();
 
1955
        offset -= data.crect.topLeft();
 
1956
    }
 
1957
 
1892
1958
    while (w) {
1893
1959
        const QWidgetPrivate *wd = w->d_func();
1894
1960
        if (wd->extra && wd->extra->hasMask)
1900
1966
    }
1901
1967
}
1902
1968
 
1903
 
bool QWidgetPrivate::hasBackground() const
1904
 
{
1905
 
    Q_Q(const QWidget);
1906
 
    if (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_PaintOnScreen))
1907
 
        return true;
1908
 
    if (q->testAttribute(Qt::WA_PaintOnScreen))
1909
 
        return true;
1910
 
    if (!q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) {
1911
 
        const QPalette &pal = q->palette();
1912
 
        QPalette::ColorRole bg = q->backgroundRole();
1913
 
        QBrush bgBrush = pal.brush(bg);
1914
 
        return (bgBrush.style() != Qt::NoBrush &&
1915
 
                ((q->isWindow() || q->windowType() == Qt::SubWindow)
1916
 
                 || (QPalette::ColorRole(bg_role) != QPalette::NoRole || (pal.resolve() & (1<<bg)))));
1917
 
    }
1918
 
    return false;
1919
 
}
1920
 
 
1921
1969
bool QWidgetPrivate::paintOnScreen() const
1922
1970
{
1923
1971
#if defined(Q_WS_QWS)
1940
1988
    // hw: todo: only needed if opacity actually changed
1941
1989
    setDirtyOpaqueRegion();
1942
1990
 
 
1991
    if (graphicsEffect) {
 
1992
        // ### We should probably add QGraphicsEffect::isOpaque at some point.
 
1993
        setOpaque(false);
 
1994
        return;
 
1995
    }
 
1996
 
1943
1997
    Q_Q(QWidget);
1944
1998
#ifdef Q_WS_X11
1945
1999
    if (q->testAttribute(Qt::WA_X11OpenGLOverlay)) {
1987
2041
#ifdef Q_WS_WIN
1988
2042
    winUpdateIsOpaque();
1989
2043
#endif
 
2044
#ifdef Q_OS_SYMBIAN
 
2045
    s60UpdateIsOpaque();
 
2046
#endif
1990
2047
}
1991
2048
 
1992
2049
void QWidgetPrivate::updateIsTranslucent()
2000
2057
#ifdef Q_WS_WIN
2001
2058
    winUpdateIsOpaque();
2002
2059
#endif
 
2060
#ifdef Q_OS_SYMBIAN
 
2061
    s60UpdateIsOpaque();
 
2062
#endif
2003
2063
}
2004
2064
 
2005
2065
/*!
2020
2080
    QPainter p(this);
2021
2081
    p.translate(-off);
2022
2082
    widget->d_func()->paintBackground(&p, QRect(off, size()));
2023
 
 
2024
2083
}
2025
2084
 
2026
 
static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QPoint &offset, const QBrush &brush)
 
2085
static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush)
2027
2086
{
2028
2087
    Q_ASSERT(painter);
2029
2088
 
2032
2091
        // Optimize pattern filling on mac by using HITheme directly
2033
2092
        // when filling with the standard widget background.
2034
2093
        // Defined in qmacstyle_mac.cpp
2035
 
        extern void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QPoint &offset, const QBrush &brush);
2036
 
        qt_mac_fill_background(painter, rgn, offset, brush);
 
2094
        extern void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush);
 
2095
        qt_mac_fill_background(painter, rgn, brush);
2037
2096
#else
2038
 
        const QRegion translated = rgn.translated(offset);
2039
 
        const QRect rect(translated.boundingRect());
2040
 
        painter->setClipRegion(translated);
2041
 
        painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
2042
 
#endif
 
2097
#if !defined(QT_NO_STYLE_S60)
 
2098
        // Defined in qs60style.cpp
 
2099
        extern bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush);
 
2100
        if (!qt_s60_fill_background(painter, rgn, brush))
 
2101
#endif // !defined(QT_NO_STYLE_S60)
 
2102
        {
 
2103
            const QRect rect(rgn.boundingRect());
 
2104
            painter->setClipRegion(rgn);
 
2105
            painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
 
2106
        }
 
2107
#endif // Q_WS_MAC
 
2108
 
 
2109
    } else if (brush.gradient()
 
2110
               && brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode) {
 
2111
        painter->save();
 
2112
        painter->setClipRegion(rgn);
 
2113
        painter->fillRect(0, 0, painter->device()->width(), painter->device()->height(), brush);
 
2114
        painter->restore();
2043
2115
    } else {
2044
2116
        const QVector<QRect> &rects = rgn.rects();
2045
2117
        for (int i = 0; i < rects.size(); ++i)
2046
 
            painter->fillRect(rects.at(i).translated(offset), brush);
 
2118
            painter->fillRect(rects.at(i), brush);
2047
2119
    }
2048
2120
}
2049
2121
 
2050
 
 
2051
 
void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, const QPoint &offset, int flags) const
 
2122
void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const
2052
2123
{
2053
2124
    Q_Q(const QWidget);
2054
2125
 
 
2126
#ifndef QT_NO_SCROLLAREA
 
2127
    bool resetBrushOrigin = false;
 
2128
    QPointF oldBrushOrigin;
 
2129
    //If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture
 
2130
    QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent);
 
2131
    if (scrollArea && scrollArea->viewport() == q) {
 
2132
        QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data();
 
2133
        QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate);
 
2134
        oldBrushOrigin = painter->brushOrigin();
 
2135
        resetBrushOrigin = true;
 
2136
        painter->setBrushOrigin(-priv->contentsOffset());
 
2137
 
 
2138
    }
 
2139
#endif // QT_NO_SCROLLAREA
 
2140
 
2055
2141
    const QBrush autoFillBrush = q->palette().brush(q->backgroundRole());
2056
2142
 
2057
2143
    if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) {
2060
2146
        if (!(flags & DontSetCompositionMode) && painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff))
2061
2147
            painter->setCompositionMode(QPainter::CompositionMode_Source); //copy alpha straight in
2062
2148
#endif
2063
 
        fillRegion(painter, rgn, offset, bg);
 
2149
        fillRegion(painter, rgn, bg);
2064
2150
    }
2065
2151
 
2066
2152
    if (q->autoFillBackground())
2067
 
        fillRegion(painter, rgn, offset, autoFillBrush);
 
2153
        fillRegion(painter, rgn, autoFillBrush);
2068
2154
 
2069
2155
    if (q->testAttribute(Qt::WA_StyledBackground)) {
2070
 
        painter->setClipRegion(rgn.translated(offset));
 
2156
        painter->setClipRegion(rgn);
2071
2157
        QStyleOption opt;
2072
2158
        opt.initFrom(q);
2073
2159
        q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q);
2074
2160
    }
 
2161
 
 
2162
#ifndef QT_NO_SCROLLAREA
 
2163
    if (resetBrushOrigin)
 
2164
        painter->setBrushOrigin(oldBrushOrigin);
 
2165
#endif // QT_NO_SCROLLAREA
2075
2166
}
2076
2167
 
2077
2168
/*
2091
2182
{
2092
2183
    Q_Q(QWidget);
2093
2184
    // If this was the active application window, reset it
2094
 
    if (qApp->activeWindow() == q)
2095
 
        qApp->setActiveWindow(0);
 
2185
    if (QApplication::activeWindow() == q)
 
2186
        QApplication::setActiveWindow(0);
2096
2187
    // If the is the active mouse press widget, reset it
2097
2188
    if (q == qt_button_down)
2098
2189
        qt_button_down = 0;
2293
2384
 
2294
2385
    if (d->extra && d->extra->style)
2295
2386
        return d->extra->style;
2296
 
    return qApp->style();
 
2387
    return QApplication::style();
2297
2388
}
2298
2389
 
2299
2390
/*!
2612
2703
 */
2613
2704
Qt::WindowStates QWidget::windowState() const
2614
2705
{
2615
 
    return (Qt::WindowStates)data->window_state;
 
2706
    return Qt::WindowStates(data->window_state);
2616
2707
}
2617
2708
 
2618
2709
/*!\internal
2624
2715
 */
2625
2716
void QWidget::overrideWindowState(Qt::WindowStates newstate)
2626
2717
{
2627
 
    QWindowStateChangeEvent e((Qt::WindowStates)data->window_state, true);
 
2718
    QWindowStateChangeEvent e(Qt::WindowStates(data->window_state), true);
2628
2719
    data->window_state  = newstate;
2629
2720
    QApplication::sendEvent(this, &e);
2630
2721
}
2723
2814
    Calling this function only affects \l{isWindow()}{windows}.
2724
2815
 
2725
2816
    On X11, this function may not work properly with certain window
2726
 
    managers. See \l{geometry.html}{Window Geometry} for an explanation.
 
2817
    managers. See the \l{Window Geometry} documentation for an explanation.
2727
2818
 
2728
2819
    \sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible()
2729
2820
*/
2778
2869
bool QWidget::isEnabledTo(QWidget* ancestor) const
2779
2870
{
2780
2871
    const QWidget * w = this;
2781
 
    while (w && !w->testAttribute(Qt::WA_ForceDisabled)
 
2872
    while (!w->testAttribute(Qt::WA_ForceDisabled)
2782
2873
            && !w->isWindow()
2783
2874
            && w->parentWidget()
2784
2875
            && w->parentWidget() != ancestor)
2962
3053
    if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) {
2963
3054
        // enforce the windows behavior of clearing the cursor on
2964
3055
        // disabled widgets
2965
 
        extern void qt_x11_enforce_cursor(QWidget * w); // defined in qwidget_x11.cpp
2966
3056
        qt_x11_enforce_cursor(q);
2967
3057
    }
2968
3058
#endif
2969
3059
#if defined(Q_WS_MAC)
2970
3060
    setEnabled_helper_sys(enable);
2971
3061
#endif
2972
 
#if defined (Q_WS_WIN)
2973
 
    if (q->hasFocus())
2974
 
        QInputContextPrivate::updateImeStatus(q, true);
2975
 
#endif
 
3062
    if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) {
 
3063
        QInputContext *qic = inputContext();
 
3064
        if (enable) {
 
3065
            qic->setFocusWidget(q);
 
3066
        } else {
 
3067
            qic->reset();
 
3068
            qic->setFocusWidget(0);
 
3069
        }
 
3070
    }
2976
3071
    QEvent e(QEvent::EnabledChange);
2977
3072
    QApplication::sendEvent(q, &e);
2978
3073
#ifdef QT3_SUPPORT
3067
3162
    \brief geometry of the widget relative to its parent including any
3068
3163
    window frame
3069
3164
 
3070
 
    See the \link geometry.html Window Geometry documentation\endlink
3071
 
    for an overview of geometry issues with windows.
 
3165
    See the \l{Window Geometry} documentation for an overview of geometry
 
3166
    issues with windows.
3072
3167
 
3073
3168
    By default, this property contains a value that depends on the user's
3074
3169
    platform and screen geometry.
3094
3189
    \brief the x coordinate of the widget relative to its parent including
3095
3190
    any window frame
3096
3191
 
3097
 
    See the \link geometry.html Window Geometry documentation\endlink
3098
 
    for an overview of window geometry.
 
3192
    See the \l{Window Geometry} documentation for an overview of geometry
 
3193
    issues with windows.
3099
3194
 
3100
3195
    By default, this property has a value of 0.
3101
3196
 
3114
3209
    \brief the y coordinate of the widget relative to its parent and
3115
3210
    including any window frame
3116
3211
 
3117
 
    See the \link geometry.html Window Geometry documentation\endlink
3118
 
    for an overview of window geometry.
 
3212
    See the \l{Window Geometry} documentation for an overview of geometry
 
3213
    issues with windows.
3119
3214
 
3120
3215
    By default, this property has a value of 0.
3121
3216
 
3147
3242
    \warning Calling move() or setGeometry() inside moveEvent() can
3148
3243
    lead to infinite recursion.
3149
3244
 
3150
 
    See the \link geometry.html Window Geometry documentation\endlink
3151
 
    for an overview of window geometry.
 
3245
    See the \l{Window Geometry} documentation for an overview of geometry
 
3246
    issues with windows.
3152
3247
 
3153
3248
    \sa frameGeometry, size x(), y()
3154
3249
*/
3178
3273
    \warning Calling setGeometry() inside resizeEvent() or moveEvent()
3179
3274
    can lead to infinite recursion.
3180
3275
 
3181
 
    See the \link geometry.html Window Geometry documentation\endlink
3182
 
    for an overview of window geometry.
 
3276
    See the \l{Window Geometry} documentation for an overview of geometry
 
3277
    issues with windows.
3183
3278
 
3184
3279
    By default, this property contains a value that depends on the user's
3185
3280
    platform and screen geometry.
3228
3323
    \property QWidget::width
3229
3324
    \brief the width of the widget excluding any window frame
3230
3325
 
3231
 
    See the \link geometry.html Window Geometry documentation\endlink
3232
 
    for an overview of window geometry.
 
3326
    See the \l{Window Geometry} documentation for an overview of geometry
 
3327
    issues with windows.
3233
3328
 
3234
3329
    \note Do not use this function to find the width of a screen on
3235
3330
    a \l{QDesktopWidget}{multiple screen desktop}. Read
3236
 
    \l{multiple screens note}{this note} for details.
 
3331
    \l{QDesktopWidget#Screen Geometry}{this note} for details.
3237
3332
 
3238
3333
    By default, this property contains a value that depends on the user's
3239
3334
    platform and screen geometry.
3245
3340
    \property QWidget::height
3246
3341
    \brief the height of the widget excluding any window frame
3247
3342
 
3248
 
    See the \link geometry.html Window Geometry documentation\endlink
3249
 
    for an overview of window geometry.
 
3343
    See the \l{Window Geometry} documentation for an overview of geometry
 
3344
    issues with windows.
3250
3345
 
3251
3346
    \note Do not use this function to find the height of a screen
3252
 
    on a \l {QDesktopWidget} {multiple screen desktop}. Read
3253
 
    \l {multiple screens note} {this note} for details.
 
3347
    on a \l{QDesktopWidget}{multiple screen desktop}. Read
 
3348
    \l{QDesktopWidget#Screen Geometry}{this note} for details.
3254
3349
 
3255
3350
    By default, this property contains a value that depends on the user's
3256
3351
    platform and screen geometry.
3265
3360
 
3266
3361
    The rect property equals QRect(0, 0, width(), height()).
3267
3362
 
3268
 
    See the \link geometry.html Window Geometry documentation\endlink
3269
 
    for an overview of window geometry.
 
3363
    See the \l{Window Geometry} documentation for an overview of geometry
 
3364
    issues with windows.
3270
3365
 
3271
3366
    By default, this property contains a value that depends on the user's
3272
3367
    platform and screen geometry.
3506
3601
        }
3507
3602
    }
3508
3603
#endif
 
3604
    int mw = minw, mh = minh;
 
3605
    if (mw == QWIDGETSIZE_MAX)
 
3606
        mw = 0;
 
3607
    if (mh == QWIDGETSIZE_MAX)
 
3608
        mh = 0;
3509
3609
    if (minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX) {
3510
3610
        qWarning("QWidget::setMinimumSize: (%s/%s) "
3511
3611
                "The largest allowed size is (%d,%d)",
3512
3612
                 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
3513
3613
                QWIDGETSIZE_MAX);
3514
 
        minw = qMin<int>(minw, QWIDGETSIZE_MAX);
3515
 
        minh = qMin<int>(minh, QWIDGETSIZE_MAX);
 
3614
        minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX);
 
3615
        minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX);
3516
3616
    }
3517
3617
    if (minw < 0 || minh < 0) {
3518
3618
        qWarning("QWidget::setMinimumSize: (%s/%s) Negative sizes (%d,%d) "
3519
3619
                "are not possible",
3520
3620
                q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh);
3521
 
        minw = qMax(minw, 0);
3522
 
        minh = qMax(minh, 0);
 
3621
        minw = mw = qMax(minw, 0);
 
3622
        minh = mh = qMax(minh, 0);
3523
3623
    }
3524
3624
    createExtra();
3525
 
    if (extra->minw == minw && extra->minh == minh)
 
3625
    if (extra->minw == mw && extra->minh == mh)
3526
3626
        return false;
3527
 
    extra->minw = minw;
3528
 
    extra->minh = minh;
3529
 
    extra->explicitMinSize = (minw ? Qt::Horizontal : 0) | (minh ? Qt::Vertical : 0);
 
3627
    extra->minw = mw;
 
3628
    extra->minh = mh;
 
3629
    extra->explicitMinSize = (mw ? Qt::Horizontal : 0) | (mh ? Qt::Vertical : 0);
3530
3630
    return true;
3531
3631
}
3532
3632
 
3586
3686
        return false;
3587
3687
    extra->maxw = maxw;
3588
3688
    extra->maxh = maxh;
3589
 
    extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) | (maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0);
 
3689
    extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) |
 
3690
                             (maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0);
3590
3691
    return true;
3591
3692
}
3592
3693
 
3665
3766
 
3666
3767
    This will override the default size constraints set by QLayout.
3667
3768
 
 
3769
    To remove constraints, set the size to QWIDGETSIZE_MAX.
 
3770
 
3668
3771
    Alternatively, if you want the widget to have a
3669
3772
    fixed size based on its contents, you can call
3670
3773
    QLayout::setSizeConstraint(QLayout::SetFixedSize);
3706
3809
    else
3707
3810
        d->updateGeometry_helper(true);
3708
3811
 
3709
 
    resize(w, h);
 
3812
    if (w != QWIDGETSIZE_MAX || h != QWIDGETSIZE_MAX)
 
3813
        resize(w, h);
3710
3814
}
3711
3815
 
3712
3816
void QWidget::setMinimumWidth(int w)
4079
4183
  If \a role is QPalette::NoRole, then the widget inherits its
4080
4184
  parent's background role.
4081
4185
 
 
4186
  Note that styles are free to choose any color from the palette.
 
4187
  You can modify the palette or set a style sheet if you don't
 
4188
  achieve the result you want with setBackgroundRole().
 
4189
 
4082
4190
  \sa backgroundRole(), foregroundRole()
4083
4191
 */
4084
4192
 
4141
4249
  If \a role is QPalette::NoRole, the widget uses a foreground role
4142
4250
  that contrasts with the background role.
4143
4251
 
 
4252
  Note that styles are free to choose any color from the palette.
 
4253
  You can modify the palette or set a style sheet if you don't
 
4254
  achieve the result you want with setForegroundRole().
 
4255
 
4144
4256
  \sa foregroundRole(), backgroundRole()
4145
4257
 */
4146
4258
void QWidget::setForegroundRole(QPalette::ColorRole role)
4194
4306
    assigning roles to a widget's palette is not guaranteed to change the
4195
4307
    appearance of the widget. Instead, you may choose to apply a \l
4196
4308
    styleSheet. You can refer to our Knowledge Base article
4197
 
    \l{http://qtsoftware.com/developer/knowledgebase/22}{here} for more
 
4309
    \l{http://qt.nokia.com/developer/knowledgebase/22}{here} for more
4198
4310
    information.
4199
4311
 
4200
4312
    \warning Do not use this function in conjunction with \l{Qt Style Sheets}.
4209
4321
    if (!isEnabled()) {
4210
4322
        data->pal.setCurrentColorGroup(QPalette::Disabled);
4211
4323
    } else if ((!isVisible() || isActiveWindow())
4212
 
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
 
4324
#if defined(Q_OS_WIN) && !defined(Q_WS_WINCE)
4213
4325
        && !QApplicationPrivate::isBlockedByModal(const_cast<QWidget *>(this))
4214
4326
#endif
4215
4327
        ) {
4590
4702
    By default, this property contains a cursor with the Qt::ArrowCursor
4591
4703
    shape.
4592
4704
 
 
4705
    Some underlying window implementations will reset the cursor if it
 
4706
    leaves a widget even if the mouse is grabbed. If you want to have
 
4707
    a cursor set for all widgets, even when outside the window, consider
 
4708
    QApplication::setOverrideCursor().
 
4709
 
4593
4710
    \sa QApplication::setOverrideCursor()
4594
4711
*/
4595
4712
 
4616
4733
#endif
4617
4734
    {
4618
4735
        d->createExtra();
 
4736
        QCursor *newCursor = new QCursor(cursor);
4619
4737
        delete d->extra->curs;
4620
 
        d->extra->curs = new QCursor(cursor);
 
4738
        d->extra->curs = newCursor;
4621
4739
    }
4622
4740
    setAttribute(Qt::WA_SetCursor);
4623
4741
    d->setCursor_sys(cursor);
4797
4915
    }
4798
4916
 
4799
4917
    const qreal opacity = painter->opacity();
4800
 
    if (qFuzzyCompare(opacity + 1, qreal(1.0)))
 
4918
    if (qFuzzyIsNull(opacity))
4801
4919
        return; // Fully transparent.
4802
4920
 
4803
4921
    Q_D(QWidget);
4859
4977
    d->extra->inRenderWithPainter = false;
4860
4978
}
4861
4979
 
 
4980
/*!
 
4981
    \brief The graphicsEffect function returns a pointer to the
 
4982
    widget's graphics effect.
 
4983
 
 
4984
    If the widget has no graphics effect, 0 is returned.
 
4985
 
 
4986
    \since 4.6
 
4987
 
 
4988
    \sa setGraphicsEffect()
 
4989
*/
 
4990
QGraphicsEffect *QWidget::graphicsEffect() const
 
4991
{
 
4992
    Q_D(const QWidget);
 
4993
    return d->graphicsEffect;
 
4994
}
 
4995
 
 
4996
/*!
 
4997
 
 
4998
  \brief The setGraphicsEffect function is for setting the widget's graphics effect.
 
4999
 
 
5000
    Sets \a effect as the widget's effect. If there already is an effect installed
 
5001
    on this widget, QWidget will delete the existing effect before installing
 
5002
    the new \a effect.
 
5003
 
 
5004
    If \a effect is the installed on a different widget, setGraphicsEffect() will remove
 
5005
    the effect from the widget and install it on this widget.
 
5006
 
 
5007
    \note This function will apply the effect on itself and all its children.
 
5008
 
 
5009
    \since 4.6
 
5010
 
 
5011
    \sa graphicsEffect()
 
5012
*/
 
5013
void QWidget::setGraphicsEffect(QGraphicsEffect *effect)
 
5014
{
 
5015
    Q_D(QWidget);
 
5016
    if (d->graphicsEffect == effect)
 
5017
        return;
 
5018
 
 
5019
    if (d->graphicsEffect && effect) {
 
5020
        delete d->graphicsEffect;
 
5021
        d->graphicsEffect = 0;
 
5022
    }
 
5023
 
 
5024
    if (!effect) {
 
5025
        // Unset current effect.
 
5026
        QGraphicsEffectPrivate *oldEffectPrivate = d->graphicsEffect->d_func();
 
5027
        d->graphicsEffect = 0;
 
5028
        if (oldEffectPrivate) {
 
5029
            oldEffectPrivate->setGraphicsEffectSource(0); // deletes the current source.
 
5030
        }
 
5031
    } else {
 
5032
        // Set new effect.
 
5033
        QGraphicsEffectSourcePrivate *sourced = new QWidgetEffectSourcePrivate(this);
 
5034
        QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced);
 
5035
        d->graphicsEffect = effect;
 
5036
        effect->d_func()->setGraphicsEffectSource(source);
 
5037
    }
 
5038
 
 
5039
    d->updateIsOpaque();
 
5040
    update();
 
5041
}
 
5042
 
4862
5043
bool QWidgetPrivate::isAboutToShow() const
4863
5044
{
4864
5045
    if (data.in_show)
4950
5131
            return;
4951
5132
 
4952
5133
        QPixmap pixmap(size);
4953
 
        if (!(renderFlags & QWidget::DrawWindowBackground))
 
5134
        if (!(renderFlags & QWidget::DrawWindowBackground)
 
5135
            || !q->palette().brush(q->backgroundRole()).isOpaque())
4954
5136
            pixmap.fill(Qt::transparent);
4955
5137
        q->render(&pixmap, QPoint(), toBePainted, renderFlags);
4956
5138
 
5003
5185
        return;
5004
5186
 
5005
5187
    Q_Q(QWidget);
 
5188
    if (graphicsEffect && graphicsEffect->isEnabled()) {
 
5189
        QGraphicsEffectSource *source = graphicsEffect->d_func()->source;
 
5190
        QWidgetEffectSourcePrivate *sourced = static_cast<QWidgetEffectSourcePrivate *>
 
5191
                                                         (source->d_func());
 
5192
        if (!sourced->context) {
 
5193
            QWidgetPaintContext context(pdev, rgn, offset, flags, sharedPainter, backingStore);
 
5194
            sourced->context = &context;
 
5195
            if (!sharedPainter) {
 
5196
                QPaintEngine *paintEngine = pdev->paintEngine();
 
5197
                paintEngine->d_func()->systemClip = rgn.translated(offset);
 
5198
                QPainter p(pdev);
 
5199
                p.translate(offset);
 
5200
                context.painter = &p;
 
5201
                graphicsEffect->draw(&p, source);
 
5202
                paintEngine->d_func()->systemClip = QRegion();
 
5203
            } else {
 
5204
                context.painter = sharedPainter;
 
5205
                sharedPainter->save();
 
5206
                sharedPainter->translate(offset);
 
5207
                graphicsEffect->draw(sharedPainter, source);
 
5208
                sharedPainter->restore();
 
5209
            }
 
5210
            sourced->context = 0;
 
5211
            return;
 
5212
        }
 
5213
    }
 
5214
 
5006
5215
    const bool asRoot = flags & DrawAsRoot;
5007
5216
    const bool alsoOnScreen = flags & DrawPaintOnScreen;
5008
5217
    const bool recursive = flags & DrawRecursive;
5035
5244
                if (sharedPainter)
5036
5245
                    paintEngine->d_func()->systemClip = toBePainted;
5037
5246
                else
5038
 
                    paintEngine->setSystemRect(q->data->crect);
 
5247
                    paintEngine->d_func()->systemRect = q->data->crect;
5039
5248
 
5040
5249
                //paint the background
5041
5250
                if ((asRoot || q->autoFillBackground() || onScreen || q->testAttribute(Qt::WA_StyledBackground))
5042
5251
                    && !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) {
5043
5252
 
5044
5253
                    QPainter p(q);
5045
 
                    QPoint scrollAreaOffset;
5046
 
 
5047
 
#ifndef QT_NO_SCROLLAREA
5048
 
                    QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(q->parent());
5049
 
                    if (scrollArea && scrollArea->viewport() == q) {
5050
 
                        QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr;
5051
 
                        QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate);
5052
 
                        scrollAreaOffset = priv->contentsOffset();
5053
 
                        p.translate(-scrollAreaOffset);
5054
 
                    }
5055
 
#endif // QT_NO_SCROLLAREA
5056
 
 
5057
 
                    paintBackground(&p, toBePainted, scrollAreaOffset, (asRoot || onScreen) ? flags | DrawAsRoot : 0);
 
5254
                    paintBackground(&p, toBePainted, (asRoot || onScreen) ? flags | DrawAsRoot : 0);
5058
5255
                }
5059
5256
 
5060
5257
                if (!sharedPainter)
5086
5283
            if (paintEngine) {
5087
5284
                restoreRedirected();
5088
5285
                if (!sharedPainter)
5089
 
                    paintEngine->setSystemRect(QRect());
 
5286
                    paintEngine->d_func()->systemRect = QRect();
5090
5287
                else
5091
5288
                    paintEngine->d_func()->currentClipWidget = 0;
5092
5289
                paintEngine->d_func()->systemClip = QRegion();
5149
5346
                dirtyBoundingRect = false;
5150
5347
            }
5151
5348
 
5152
 
            if (qRectIntersects(boundingRect, x->data->crect)) {
 
5349
            if (qRectIntersects(boundingRect, x->d_func()->effectiveRectFor(x->data->crect))) {
5153
5350
#ifdef Q_BACKINGSTORE_SUBSURFACES
5154
5351
                if (x->windowSurface() == currentSurface)
5155
5352
#endif
5167
5364
 
5168
5365
    QWidgetPrivate *wd = w->d_func();
5169
5366
    const QPoint widgetPos(w->data->crect.topLeft());
5170
 
    const bool hasMask = wd->extra && wd->extra->hasMask;
 
5367
    const bool hasMask = wd->extra && wd->extra->hasMask && !wd->graphicsEffect;
5171
5368
 
5172
5369
    if (index > 0) {
5173
5370
        QRegion wr(rgn);
5182
5379
 
5183
5380
    if (w->updatesEnabled() && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget)) {
5184
5381
        QRegion wRegion(rgn);
5185
 
        wRegion &= w->data->crect;
 
5382
        wRegion &= wd->effectiveRectFor(w->data->crect);
5186
5383
        wRegion.translate(-widgetPos);
5187
5384
        if (hasMask)
5188
5385
            wRegion &= wd->extra->mask;
5190
5387
    }
5191
5388
}
5192
5389
 
 
5390
QRectF QWidgetEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const
 
5391
{
 
5392
    if (system != Qt::DeviceCoordinates)
 
5393
        return m_widget->rect();
 
5394
 
 
5395
    if (!context) {
 
5396
        // Device coordinates without context not yet supported.
 
5397
        qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");
 
5398
        return QRectF();
 
5399
    }
 
5400
 
 
5401
    return context->painter->worldTransform().mapRect(m_widget->rect());
 
5402
}
 
5403
 
 
5404
void QWidgetEffectSourcePrivate::draw(QPainter *painter)
 
5405
{
 
5406
    if (!context || context->painter != painter) {
 
5407
        m_widget->render(painter);
 
5408
        return;
 
5409
    }
 
5410
 
 
5411
    // The region saved in the context is neither clipped to the rect
 
5412
    // nor the mask, so we have to clip it here before calling drawWidget.
 
5413
    QRegion toBePainted = context->rgn;
 
5414
    toBePainted &= m_widget->rect();
 
5415
    QWidgetPrivate *wd = qt_widget_private(m_widget);
 
5416
    if (wd->extra && wd->extra->hasMask)
 
5417
        toBePainted &= wd->extra->mask;
 
5418
 
 
5419
    wd->drawWidget(context->pdev, toBePainted, context->offset, context->flags,
 
5420
                   context->sharedPainter, context->backingStore);
 
5421
}
 
5422
 
 
5423
QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset) const
 
5424
{
 
5425
    const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
 
5426
    if (!context && deviceCoordinates) {
 
5427
        // Device coordinates without context not yet supported.
 
5428
        qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
 
5429
        return QPixmap();
 
5430
    }
 
5431
 
 
5432
    QPoint pixmapOffset;
 
5433
    QRectF sourceRect = m_widget->rect();
 
5434
 
 
5435
    if (deviceCoordinates) {
 
5436
        const QTransform &painterTransform = context->painter->worldTransform();
 
5437
        sourceRect = painterTransform.mapRect(sourceRect);
 
5438
        pixmapOffset = painterTransform.map(pixmapOffset);
 
5439
    }
 
5440
 
 
5441
    QRect effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect();
 
5442
    if (offset)
 
5443
        *offset = effectRect.topLeft();
 
5444
 
 
5445
    if (deviceCoordinates) {
 
5446
        // Clip to device rect.
 
5447
        int left, top, right, bottom;
 
5448
        effectRect.getCoords(&left, &top, &right, &bottom);
 
5449
        if (left < 0) {
 
5450
            if (offset)
 
5451
                offset->rx() += -left;
 
5452
            effectRect.setX(0);
 
5453
        }
 
5454
        if (top < 0) {
 
5455
            if (offset)
 
5456
                offset->ry() += -top;
 
5457
            effectRect.setY(0);
 
5458
        }
 
5459
        // NB! We use +-1 for historical reasons (see QRect documentation).
 
5460
        QPaintDevice *device = context->painter->device();
 
5461
        const int deviceWidth = device->width();
 
5462
        const int deviceHeight = device->height();
 
5463
        if (right + 1 > deviceWidth)
 
5464
            effectRect.setRight(deviceWidth - 1);
 
5465
        if (bottom + 1 > deviceHeight)
 
5466
            effectRect.setBottom(deviceHeight -1);
 
5467
    }
 
5468
 
 
5469
    pixmapOffset -= effectRect.topLeft();
 
5470
 
 
5471
    QPixmap pixmap(effectRect.size());
 
5472
    pixmap.fill(Qt::transparent);
 
5473
    m_widget->render(&pixmap, pixmapOffset);
 
5474
    return pixmap;
 
5475
}
 
5476
 
5193
5477
/*!
5194
5478
    \internal
5195
5479
 
5288
5572
#ifndef Q_WS_MAC
5289
5573
    QString appName = QApplication::applicationName();
5290
5574
    if (!appName.isEmpty())
5291
 
        windowTitle += QLatin1String(" ") + QChar(0x2014) + QLatin1String(" ") + appName;
 
5575
        windowTitle += QLatin1Char(' ') + QChar(0x2014) + QLatin1Char(' ') + appName;
5292
5576
#endif
5293
5577
    return windowTitle;
5294
5578
}
5323
5607
    return QString();
5324
5608
}
5325
5609
 
 
5610
/*!
 
5611
    Returns a modified window title with the [*] place holder
 
5612
    replaced according to the rules described in QWidget::setWindowTitle
 
5613
 
 
5614
    This function assumes that "[*]" can be quoted by another
 
5615
    "[*]", so it will replace two place holders by one and
 
5616
    a single last one by either "*" or nothing depending on
 
5617
    the modified flag.
 
5618
 
 
5619
    \internal
 
5620
*/
5326
5621
QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widget)
5327
5622
{
5328
5623
    Q_ASSERT(widget);
5334
5629
    QString cap = title;
5335
5630
#endif
5336
5631
 
5337
 
    QString placeHolder(QLatin1String("[*]"));
 
5632
    if (cap.isEmpty())
 
5633
        return cap;
 
5634
 
 
5635
    QLatin1String placeHolder("[*]");
 
5636
    int placeHolderLength = 3; // QLatin1String doesn't have length()
5338
5637
 
5339
5638
    int index = cap.indexOf(placeHolder);
5340
5639
 
 
5640
    // here the magic begins
5341
5641
    while (index != -1) {
5342
 
        index += placeHolder.length();
 
5642
        index += placeHolderLength;
5343
5643
        int count = 1;
5344
5644
        while (cap.indexOf(placeHolder, index) == index) {
5345
5645
            ++count;
5346
 
            index += placeHolder.length();
 
5646
            index += placeHolderLength;
5347
5647
        }
5348
5648
 
5349
5649
        if (count%2) { // odd number of [*] -> replace last one
5352
5652
             && widget->style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, widget))
5353
5653
                cap.replace(lastIndex, 3, QWidget::tr("*"));
5354
5654
            else
5355
 
                cap.replace(lastIndex, 3, QLatin1String(""));
 
5655
                cap.remove(lastIndex, 3);
5356
5656
        }
5357
5657
 
5358
5658
        index = cap.indexOf(placeHolder, index);
5359
5659
    }
5360
5660
 
5361
 
    cap.replace(QLatin1String("[*][*]"), QLatin1String("[*]"));
 
5661
    cap.replace(QLatin1String("[*][*]"), placeHolder);
5362
5662
 
5363
5663
    return cap;
5364
5664
}
5393
5693
 
5394
5694
void QWidget::setWindowTitle(const QString &title)
5395
5695
{
5396
 
    if (QWidget::windowTitle() == title)
 
5696
    if (QWidget::windowTitle() == title && !title.isEmpty() && !title.isNull())
5397
5697
        return;
5398
5698
 
5399
5699
    Q_D(QWidget);
5424
5724
            return *d->extra->topextra->icon;
5425
5725
        w = w->parentWidget();
5426
5726
    }
5427
 
    return qApp->windowIcon();
 
5727
    return QApplication::windowIcon();
5428
5728
}
5429
5729
 
5430
5730
void QWidgetPrivate::setWindowIcon_helper()
5487
5787
 
5488
5788
    \list
5489
5789
    \o The file name of the specified path, obtained using QFileInfo::fileName().
5490
 
    \o An optional \c{*} character, if the \l windowModified property is set,
5491
 
    as per the Apple Human Interface Guidelines.
5492
5790
    \endlist
5493
5791
 
5494
5792
    On Windows and X11:
5537
5835
{
5538
5836
    if (extra->topextra && extra->topextra->caption.isEmpty()) {
5539
5837
#ifdef Q_WS_MAC
5540
 
        setWindowTitle_helper(filePath);
 
5838
        setWindowTitle_helper(QFileInfo(filePath).fileName());
5541
5839
#else
5542
5840
        Q_Q(QWidget);
5543
5841
        Q_UNUSED(filePath);
5670
5968
    isActiveWindow() active window\endlink. The \a reason argument will
5671
5969
    be passed into any focus event sent from this function, it is used
5672
5970
    to give an explanation of what caused the widget to get focus.
 
5971
    If the window is not active, the widget will be given the focus when
 
5972
    the window becomes active.
5673
5973
 
5674
5974
    First, a focus out event is sent to the focus widget (if any) to
5675
5975
    tell it that it is about to lose the focus. Then a focus in event
5687
5987
    called from focusOutEvent() or focusInEvent(), you may get an
5688
5988
    infinite recursion.
5689
5989
 
5690
 
    \sa focus(), hasFocus(), clearFocus(), focusInEvent(), focusOutEvent(),
 
5990
    \sa hasFocus(), clearFocus(), focusInEvent(), focusOutEvent(),
5691
5991
    setFocusPolicy(), focusWidget(), QApplication::focusWidget(), grabKeyboard(),
5692
5992
    grabMouse(), {Keyboard Focus}
5693
5993
*/
5908
6208
 
5909
6209
/*!
5910
6210
    Returns the next widget in this widget's focus chain.
 
6211
 
 
6212
    \sa previousInFocusChain()
5911
6213
*/
5912
6214
QWidget *QWidget::nextInFocusChain() const
5913
6215
{
5915
6217
}
5916
6218
 
5917
6219
/*!
 
6220
    \brief The previousInFocusChain function returns the previous
 
6221
    widget in this widget's focus chain.
 
6222
 
 
6223
    \sa nextInFocusChain()
 
6224
 
 
6225
    \since 4.6
 
6226
*/
 
6227
QWidget *QWidget::previousInFocusChain() const
 
6228
{
 
6229
    return const_cast<QWidget *>(d_func()->focus_prev);
 
6230
}
 
6231
 
 
6232
/*!
5918
6233
    \property QWidget::isActiveWindow
5919
6234
    \brief whether this widget's window is the active window
5920
6235
 
5932
6247
bool QWidget::isActiveWindow() const
5933
6248
{
5934
6249
    QWidget *tlw = window();
5935
 
    if(tlw == qApp->activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup)))
 
6250
    if(tlw == QApplication::activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup)))
5936
6251
        return true;
5937
6252
 
5938
6253
#ifndef QT_NO_GRAPHICSVIEW
5947
6262
    if(qt_mac_is_macdrawer(tlw) &&
5948
6263
       tlw->parentWidget() && tlw->parentWidget()->isActiveWindow())
5949
6264
        return true;
 
6265
 
 
6266
    extern bool qt_mac_insideKeyWindow(const QWidget *); //qwidget_mac.cpp
 
6267
    if (QApplication::testAttribute(Qt::AA_MacPluginApplication) && qt_mac_insideKeyWindow(tlw))
 
6268
        return true;
5950
6269
#endif
5951
6270
    if(style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, this)) {
5952
6271
        if(tlw->windowType() == Qt::Tool &&
5953
6272
           !tlw->isModal() &&
5954
6273
           (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow()))
5955
6274
           return true;
5956
 
        QWidget *w = qApp->activeWindow();
 
6275
        QWidget *w = QApplication::activeWindow();
5957
6276
        while(w && tlw->windowType() == Qt::Tool &&
5958
6277
              !w->isModal() && w->parentWidget()) {
5959
6278
            w = w->parentWidget()->window();
6136
6455
 
6137
6456
  This function is called from QDesktopwidget::screen(QPoint) to find the
6138
6457
  closest screen for a point.
 
6458
  In directional KeypadNavigation, it is called to find the closest
 
6459
  widget to the current focus widget center.
6139
6460
*/
6140
6461
int QWidgetPrivate::pointToRect(const QPoint &p, const QRect &r)
6141
6462
{
6152
6473
    return dx + dy;
6153
6474
}
6154
6475
 
6155
 
QRect QWidgetPrivate::fromOrToLayoutItemRect(const QRect &rect, int sign) const
6156
 
{
6157
 
    QRect r = rect;
6158
 
    r.adjust(-sign * leftLayoutItemMargin, -sign * topLayoutItemMargin,
6159
 
             +sign * rightLayoutItemMargin, +sign * bottomLayoutItemMargin);
6160
 
    return r;
6161
 
}
6162
 
 
6163
6476
/*!
6164
6477
    \property QWidget::frameSize
6165
6478
    \brief the size of the widget including any window frame
6248
6561
 
6249
6562
    \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 11
6250
6563
 
6251
 
    See the \link geometry.html Window Geometry documentation\endlink
6252
 
    for an overview of geometry issues with windows.
 
6564
    See the \l{Window Geometry} documentation for an overview of geometry
 
6565
    issues with windows.
6253
6566
 
6254
6567
    Use QMainWindow::saveState() to save the geometry and the state of
6255
6568
    toolbars and dock widgets.
6290
6603
 
6291
6604
    \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 12
6292
6605
 
6293
 
    See the \link geometry.html Window Geometry documentation\endlink
6294
 
    for an overview of geometry issues with windows.
 
6606
    See the \l{Window Geometry} documentation for an overview of geometry
 
6607
    issues with windows.
6295
6608
 
6296
6609
    Use QMainWindow::restoreState() to restore the geometry and the
6297
6610
    state of toolbars and dock widgets.
6408
6721
*/
6409
6722
 
6410
6723
/*!
6411
 
    Sets the margins around the contents of the widget to have the
6412
 
    sizes \a left, \a top, \a right, and \a bottom. The margins are
6413
 
    used by the layout system, and may be used by subclasses to
6414
 
    specify the area to draw in (e.g. excluding the frame).
6415
 
 
6416
 
    Changing the margins will trigger a resizeEvent().
6417
 
 
6418
 
    \sa contentsRect(), getContentsMargins()
 
6724
  Sets the margins around the contents of the widget to have the sizes
 
6725
  \a left, \a top, \a right, and \a bottom. The margins are used by
 
6726
  the layout system, and may be used by subclasses to specify the area
 
6727
  to draw in (e.g. excluding the frame).
 
6728
 
 
6729
  Changing the margins will trigger a resizeEvent().
 
6730
 
 
6731
  \sa contentsRect(), getContentsMargins()
6419
6732
*/
6420
6733
void QWidget::setContentsMargins(int left, int top, int right, int bottom)
6421
6734
{
6446
6759
    QApplication::sendEvent(this, &e);
6447
6760
}
6448
6761
 
6449
 
/*!  Returns the widget's contents margins for \a left, \a top, \a
 
6762
/*!
 
6763
  \overload
 
6764
  \since 4.6
 
6765
 
 
6766
  \brief The setContentsMargins function sets the margins around the
 
6767
  widget's contents.
 
6768
 
 
6769
  Sets the margins around the contents of the widget to have the
 
6770
  sizes determined by \a margins. The margins are
 
6771
  used by the layout system, and may be used by subclasses to
 
6772
  specify the area to draw in (e.g. excluding the frame).
 
6773
 
 
6774
  Changing the margins will trigger a resizeEvent().
 
6775
 
 
6776
  \sa contentsRect(), getContentsMargins()
 
6777
*/
 
6778
void QWidget::setContentsMargins(const QMargins &margins)
 
6779
{
 
6780
    setContentsMargins(margins.left(), margins.top(),
 
6781
                       margins.right(), margins.bottom());
 
6782
}
 
6783
 
 
6784
/*!
 
6785
  Returns the widget's contents margins for \a left, \a top, \a
6450
6786
  right, and \a bottom.
6451
6787
 
6452
6788
  \sa setContentsMargins(), contentsRect()
6465
6801
}
6466
6802
 
6467
6803
/*!
 
6804
  \since 4.6
 
6805
 
 
6806
  \brief The contentsMargins function returns the widget's contents margins.
 
6807
 
 
6808
  \sa getContentsMargins(), setContentsMargins(), contentsRect()
 
6809
 */
 
6810
QMargins QWidget::contentsMargins() const
 
6811
{
 
6812
    Q_D(const QWidget);
 
6813
    return QMargins(d->leftmargin, d->topmargin, d->rightmargin, d->bottommargin);
 
6814
}
 
6815
 
 
6816
 
 
6817
/*!
6468
6818
    Returns the area inside the widget's margins.
6469
6819
 
6470
6820
    \sa setContentsMargins(), getContentsMargins()
6746
7096
    // On Windows, show the popup now so that our own focus handling
6747
7097
    // stores the correct old focus widget even if it's stolen in the
6748
7098
    // showevent
6749
 
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
 
7099
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_OS_SYMBIAN)
6750
7100
    if (!isEmbedded && q->windowType() == Qt::Popup)
6751
7101
        qApp->d_func()->openPopup(q);
6752
7102
#endif
6763
7113
 
6764
7114
    show_sys();
6765
7115
 
6766
 
#if !defined(Q_WS_WIN) && !defined(Q_WS_MAC)
 
7116
#if !defined(Q_WS_WIN) && !defined(Q_WS_MAC) && !defined(Q_OS_SYMBIAN)
6767
7117
    if (!isEmbedded && q->windowType() == Qt::Popup)
6768
7118
        qApp->d_func()->openPopup(q);
6769
7119
#endif
6845
7195
    // next bit tries to move the focus if the focus widget is now
6846
7196
    // hidden.
6847
7197
    if (wasVisible) {
6848
 
#if defined(Q_WS_WIN) || defined(Q_WS_X11)
 
7198
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS)
6849
7199
        qApp->d_func()->sendSyntheticEnterLeave(q);
6850
7200
#endif
6851
7201
 
6883
7233
    widgets that are not visible.
6884
7234
 
6885
7235
 
6886
 
    Widgets are  hidden if they were created as independent
6887
 
    windows or as children of visible widgets, or if hide() or setVisible(false) was called.
6888
 
 
 
7236
    Widgets are hidden if:
 
7237
    \list
 
7238
        \o they were created as independent windows,
 
7239
        \o they were created as children of visible widgets,
 
7240
        \o hide() or setVisible(false) was called.
 
7241
    \endlist
6889
7242
*/
6890
7243
 
6891
7244
 
6974
7327
 
6975
7328
            d->show_helper();
6976
7329
 
6977
 
#if defined(Q_WS_WIN) || defined(Q_WS_X11)
 
7330
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS)
6978
7331
            qApp->d_func()->sendSyntheticEnterLeave(this);
6979
7332
#endif
6980
7333
        }
7089
7442
                widget->d_func()->hide_sys();
7090
7443
            }
7091
7444
        }
7092
 
#if defined(Q_WS_WIN) || defined(Q_WS_X11)
 
7445
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS)
7093
7446
        qApp->d_func()->sendSyntheticEnterLeave(widget);
7094
7447
#endif
7095
7448
#ifndef QT_NO_ACCESSIBILITY
7131
7484
 
7132
7485
#ifdef QT3_SUPPORT
7133
7486
    if (isMain)
7134
 
        qApp->quit();
 
7487
        QApplication::quit();
7135
7488
#endif
7136
7489
    // Attempt to close the application only if this widget has the
7137
7490
    // WA_QuitOnClose flag set set and has a non-visible parent
7256
7609
    if (!ancestor)
7257
7610
        return isVisible();
7258
7611
    const QWidget * w = this;
7259
 
    while (w
7260
 
            && !w->isHidden()
 
7612
    while (!w->isHidden()
7261
7613
            && !w->isWindow()
7262
7614
            && w->parentWidget()
7263
7615
            && w->parentWidget() != ancestor)
7314
7666
 
7315
7667
    if (q->isWindow()) {
7316
7668
        Qt::Orientations exp;
7317
 
        if (QLayout *l = q->layout()) {
7318
 
            if (l->hasHeightForWidth())
7319
 
                s.setHeight(l->totalHeightForWidth(s.width()));
7320
 
            exp = l->expandingDirections();
 
7669
        if (layout) {
 
7670
            if (layout->hasHeightForWidth())
 
7671
                s.setHeight(layout->totalHeightForWidth(s.width()));
 
7672
            exp = layout->expandingDirections();
7321
7673
        } else
7322
7674
        {
7323
7675
            if (q->sizePolicy().hasHeightForWidth())
7333
7685
#else // all others
7334
7686
        QRect screen = QApplication::desktop()->screenGeometry(q->pos());
7335
7687
#endif
7336
 
#if defined (Q_OS_WINCE)
 
7688
#if defined (Q_WS_WINCE) || defined (Q_OS_SYMBIAN)
7337
7689
        s.setWidth(qMin(s.width(), screen.width()));
7338
7690
        s.setHeight(qMin(s.height(), screen.height()));
7339
7691
#else
7520
7872
        case QEvent::MouseButtonRelease:
7521
7873
        case QEvent::MouseButtonDblClick:
7522
7874
        case QEvent::MouseMove:
 
7875
        case QEvent::TouchBegin:
 
7876
        case QEvent::TouchUpdate:
 
7877
        case QEvent::TouchEnd:
7523
7878
        case QEvent::ContextMenu:
7524
7879
#ifndef QT_NO_WHEELEVENT
7525
7880
        case QEvent::Wheel:
7585
7940
#ifdef QT_KEYPAD_NAVIGATION
7586
7941
        if (!k->isAccepted() && QApplication::keypadNavigationEnabled()
7587
7942
            && !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::ShiftModifier))) {
7588
 
            if (k->key() == Qt::Key_Up)
7589
 
                res = focusNextPrevChild(false);
7590
 
            else if (k->key() == Qt::Key_Down)
7591
 
                res = focusNextPrevChild(true);
 
7943
            if (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder) {
 
7944
                if (k->key() == Qt::Key_Up)
 
7945
                    res = focusNextPrevChild(false);
 
7946
                else if (k->key() == Qt::Key_Down)
 
7947
                    res = focusNextPrevChild(true);
 
7948
            } else if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
 
7949
                if (k->key() == Qt::Key_Up)
 
7950
                    res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionNorth);
 
7951
                else if (k->key() == Qt::Key_Right)
 
7952
                    res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionEast);
 
7953
                else if (k->key() == Qt::Key_Down)
 
7954
                    res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionSouth);
 
7955
                else if (k->key() == Qt::Key_Left)
 
7956
                    res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionWest);
 
7957
            }
7592
7958
            if (res) {
7593
7959
                k->accept();
7594
7960
                break;
7641
8007
        }
7642
8008
        break;
7643
8009
    case QEvent::FocusIn:
7644
 
#if defined(Q_WS_WIN)
7645
 
        QInputContextPrivate::updateImeStatus(this, true);
 
8010
#ifdef QT_SOFTKEYS_ENABLED
 
8011
        QSoftKeyManager::updateSoftKeys();
7646
8012
#endif
7647
8013
        focusInEvent((QFocusEvent*)event);
7648
8014
        break;
7649
8015
 
7650
8016
    case QEvent::FocusOut:
7651
 
#if defined(Q_WS_WIN)
7652
 
        QInputContextPrivate::updateImeStatus(this, false);
7653
 
#endif
7654
8017
        focusOutEvent((QFocusEvent*)event);
7655
8018
        break;
7656
8019
 
7796
8159
            if (w && w->isVisible() && !w->isWindow())
7797
8160
                QApplication::sendEvent(w, event);
7798
8161
        }
 
8162
 
 
8163
#ifdef QT_SOFTKEYS_ENABLED
 
8164
        if (isWindow() && isActiveWindow())
 
8165
            QSoftKeyManager::updateSoftKeys();
 
8166
#endif
 
8167
 
7799
8168
        break; }
7800
8169
 
7801
8170
    case QEvent::LanguageChange:
7836
8205
            QList<QObject*> childList = d->children;
7837
8206
            for (int i = 0; i < childList.size(); ++i) {
7838
8207
                QObject *o = childList.at(i);
7839
 
                if (o != qApp->activeModalWidget()) {
 
8208
                if (o != QApplication::activeModalWidget()) {
7840
8209
                    if (qobject_cast<QWidget *>(o) && static_cast<QWidget *>(o)->isWindow()) {
7841
8210
                        // do not forward the event to child windows,
7842
8211
                        // QApplication does this for us
7903
8272
    case QEvent::ActionAdded:
7904
8273
    case QEvent::ActionRemoved:
7905
8274
    case QEvent::ActionChanged:
 
8275
#ifdef QT_SOFTKEYS_ENABLED
 
8276
        QSoftKeyManager::updateSoftKeys();
 
8277
#endif
7906
8278
        actionEvent((QActionEvent*)event);
7907
8279
        break;
7908
8280
#endif
7925
8297
        d->needWindowChange = false;
7926
8298
        break;
7927
8299
#endif
 
8300
    case QEvent::TouchBegin:
 
8301
    case QEvent::TouchUpdate:
 
8302
    case QEvent::TouchEnd:
 
8303
    {
 
8304
        QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
 
8305
        const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first();
 
8306
        if (touchPoint.isPrimary())
 
8307
            break;
 
8308
 
 
8309
        // fake a mouse event!
 
8310
        QEvent::Type eventType = QEvent::None;
 
8311
        switch (touchEvent->type()) {
 
8312
        case QEvent::TouchBegin:
 
8313
            eventType = QEvent::MouseButtonPress;
 
8314
            break;
 
8315
        case QEvent::TouchUpdate:
 
8316
            eventType = QEvent::MouseMove;
 
8317
            break;
 
8318
        case QEvent::TouchEnd:
 
8319
            eventType = QEvent::MouseButtonRelease;
 
8320
            break;
 
8321
        default:
 
8322
            Q_ASSERT(!true);
 
8323
            break;
 
8324
        }
 
8325
        if (eventType == QEvent::None)
 
8326
            break;
 
8327
 
 
8328
        QMouseEvent mouseEvent(eventType,
 
8329
                               touchPoint.pos().toPoint(),
 
8330
                               touchPoint.screenPos().toPoint(),
 
8331
                               Qt::LeftButton,
 
8332
                               Qt::LeftButton,
 
8333
                               touchEvent->modifiers());
 
8334
        (void) QApplication::sendEvent(this, &mouseEvent);
 
8335
        break;
 
8336
    }
 
8337
    case QEvent::Gesture:
 
8338
        event->ignore();
 
8339
        break;
7928
8340
#ifndef QT_NO_PROPERTIES
7929
8341
    case QEvent::DynamicPropertyChange: {
7930
8342
        const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
7976
8388
 
7977
8389
    case QEvent::FontChange:
7978
8390
    case QEvent::StyleChange: {
 
8391
        Q_D(QWidget);
7979
8392
        update();
7980
8393
        updateGeometry();
 
8394
        if (d->layout)
 
8395
            d->layout->invalidate();
7981
8396
#ifdef Q_WS_QWS
7982
 
        Q_D(QWidget);
7983
8397
        if (isWindow())
7984
8398
            d->data.fstrut_dirty = true;
7985
8399
#endif
8059
8473
    if ((windowType() == Qt::Popup)) {
8060
8474
        event->accept();
8061
8475
        QWidget* w;
8062
 
        while ((w = qApp->activePopupWidget()) && w != this){
 
8476
        while ((w = QApplication::activePopupWidget()) && w != this){
8063
8477
            w->close();
8064
 
            if (qApp->activePopupWidget() == w) // widget does not want to dissappear
 
8478
            if (QApplication::activePopupWidget() == w) // widget does not want to dissappear
8065
8479
                w->hide(); // hide at least
8066
8480
        }
8067
8481
        if (!rect().contains(event->pos())){
8089
8503
 
8090
8504
    The default implementation generates a normal mouse press event.
8091
8505
 
8092
 
    Note that the widgets gets a mousePressEvent() and a
8093
 
    mouseReleaseEvent() before the mouseDoubleClickEvent().
 
8506
    \note The widget will also receive mouse press and mouse release
 
8507
    events in addition to the double click event. It is up to the
 
8508
    developer to ensure that the application interprets these events
 
8509
    correctly.
8094
8510
 
8095
8511
    \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
8096
8512
    event(), QMouseEvent
8471
8887
 
8472
8888
    \a query specifies which property is queried.
8473
8889
 
8474
 
    \sa inputMethodEvent(), QInputMethodEvent, QInputContext
 
8890
    \sa inputMethodEvent(), QInputMethodEvent, QInputContext, inputMethodHints
8475
8891
*/
8476
8892
QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const
8477
8893
{
8480
8896
        return QRect(width()/2, 0, 1, height());
8481
8897
    case Qt::ImFont:
8482
8898
        return font();
 
8899
    case Qt::ImAnchorPosition:
 
8900
        // Fallback.
 
8901
        return inputMethodQuery(Qt::ImCursorPosition);
8483
8902
    default:
8484
8903
        return QVariant();
8485
8904
    }
8486
8905
}
8487
8906
 
 
8907
/*!
 
8908
    \property QWidget::inputMethodHints
 
8909
    \brief What input method specific hints the widget has.
 
8910
 
 
8911
    This is only relevant for input widgets. It is used by
 
8912
    the input method to retrieve hints as to how the input method
 
8913
    should operate. For example, if the Qt::ImhFormattedNumbersOnly flag
 
8914
    is set, the input method may change its visual components to reflect
 
8915
    that only numbers can be entered.
 
8916
 
 
8917
    \note The flags are only hints, so the particular input method
 
8918
          implementation is free to ignore them. If you want to be
 
8919
          sure that a certain type of characters are entered,
 
8920
          you should also set a QValidator on the widget.
 
8921
 
 
8922
    The default value is Qt::ImhNone.
 
8923
 
 
8924
    \since 4.6
 
8925
 
 
8926
    \sa inputMethodQuery(), QInputContext
 
8927
*/
 
8928
Qt::InputMethodHints QWidget::inputMethodHints() const
 
8929
{
 
8930
    Q_D(const QWidget);
 
8931
    return d->imHints;
 
8932
}
 
8933
 
 
8934
void QWidget::setInputMethodHints(Qt::InputMethodHints hints)
 
8935
{
 
8936
    Q_D(QWidget);
 
8937
    d->imHints = hints;
 
8938
    // Optimisation to update input context only it has already been created.
 
8939
    if (d->ic || qApp->d_func()->inputContext) {
 
8940
        QInputContext *ic = inputContext();
 
8941
        if (ic)
 
8942
            ic->update();
 
8943
    }
 
8944
}
 
8945
 
 
8946
 
8488
8947
#ifndef QT_NO_DRAGANDDROP
8489
8948
 
8490
8949
/*!
8801
9260
    The layout manager sets the geometry of the widget's children
8802
9261
    that have been added to the layout.
8803
9262
 
8804
 
    \sa setLayout(), sizePolicy(), {Layout Classes}
 
9263
    \sa setLayout(), sizePolicy(), {Layout Management}
8805
9264
*/
8806
9265
QLayout *QWidget::layout() const
8807
9266
{
8831
9290
 
8832
9291
    The QWidget will take ownership of \a layout.
8833
9292
 
8834
 
    \sa layout(), {Layout Classes}
 
9293
    \sa layout(), {Layout Management}
8835
9294
*/
8836
9295
 
8837
9296
void QWidget::setLayout(QLayout *l)
9256
9715
    d->resolveLayoutDirection();
9257
9716
    d->resolveLocale();
9258
9717
 
9259
 
    // Note: GL widgets under Windows will always need a ParentChange
9260
 
    // event to handle recreation/rebinding of the GL context, hence
9261
 
    // the (f & Qt::MSWindowsOwnDC) clause
 
9718
    // Note: GL widgets under WGL or EGL will always need a ParentChange
 
9719
    // event to handle recreation/rebinding of the GL context, hence the
 
9720
    // (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all
 
9721
    // platforms).
9262
9722
    if (newParent
9263
 
#ifdef Q_WS_WIN
 
9723
#if defined(Q_WS_WIN) || defined(QT_OPENGL_ES)
9264
9724
        || (f & Qt::MSWindowsOwnDC)
9265
9725
#endif
9266
9726
        ) {
9682
10142
               "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute");
9683
10143
 
9684
10144
#ifdef Q_WS_WIN
9685
 
    if (attribute == Qt::WA_PaintOnScreen && on) {
 
10145
    // ### Don't use PaintOnScreen+paintEngine() to do native painting in 5.0
 
10146
    if (attribute == Qt::WA_PaintOnScreen && on && !inherits("QGLWidget")) {
9686
10147
        // see qwidget_win.cpp, ::paintEngine for details
9687
10148
        paintEngine();
9688
10149
        if (d->noPaintOnScreen)
9796
10257
            data->window_modality = (w && w->testAttribute(Qt::WA_GroupLeader))
9797
10258
                                    ? Qt::WindowModal
9798
10259
                                    : Qt::ApplicationModal;
 
10260
            // Some window managers does not allow us to enter modal after the
 
10261
            // window is showing. Therefore, to be consistent, we cannot call
 
10262
            // QApplicationPrivate::enterModal(this) here. The window must be
 
10263
            // hidden before changing modality.
9799
10264
        }
9800
10265
        if (testAttribute(Qt::WA_WState_Created)) {
9801
10266
            // don't call setModal_sys() before create_sys()
9806
10271
        QEvent e(QEvent::MouseTrackingChange);
9807
10272
        QApplication::sendEvent(this, &e);
9808
10273
        break; }
9809
 
#if !defined(QT_NO_DIRECT3D) && defined(Q_WS_WIN)
9810
 
    case Qt::WA_MSWindowsUseDirect3D:
9811
 
        if (!qApp->testAttribute(Qt::AA_MSWindowsUseDirect3DByDefault)) {
9812
 
            if (on) {
9813
 
                if (!d->extra)
9814
 
                    d->createExtra();
9815
 
                d->extra->had_auto_fill_bg = d->extra->autoFillBackground;
9816
 
                d->extra->had_no_system_bg = testAttribute(Qt::WA_NoSystemBackground);
9817
 
                d->extra->had_paint_on_screen = testAttribute(Qt::WA_PaintOnScreen);
9818
 
                // enforce the opaque widget state D3D needs
9819
 
                d->extra->autoFillBackground = true;
9820
 
                setAttribute(Qt::WA_PaintOnScreen);
9821
 
                setAttribute(Qt::WA_NoSystemBackground);
9822
 
            } else if (d->extra) {
9823
 
                d->extra->autoFillBackground = d->extra->had_auto_fill_bg;
9824
 
                setAttribute(Qt::WA_PaintOnScreen, d->extra->had_paint_on_screen);
9825
 
                setAttribute(Qt::WA_NoSystemBackground, d->extra->had_no_system_bg);
9826
 
            }
9827
 
        }
9828
 
        break;
9829
 
#endif
9830
10274
    case Qt::WA_NativeWindow: {
9831
10275
        QInputContext *ic = 0;
9832
10276
        if (on && !internalWinId() && testAttribute(Qt::WA_InputMethodEnabled) && hasFocus()) {
9838
10282
            parentWidget()->d_func()->enforceNativeChildren();
9839
10283
        if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created))
9840
10284
            d->createWinId();
9841
 
        if (ic)
 
10285
        if (ic && isEnabled())
9842
10286
            ic->setFocusWidget(this);
9843
10287
        break;
9844
10288
    }
9869
10313
#endif
9870
10314
        break;
9871
10315
    case Qt::WA_InputMethodEnabled: {
9872
 
#if defined(Q_WS_WIN) || (defined(Q_WS_QWS) && !defined(QT_NO_QWS_INPUTMETHODS))
9873
 
        if (hasFocus())
9874
 
            QInputContextPrivate::updateImeStatus(this, true);
9875
 
#endif
9876
10316
        QInputContext *ic = d->ic;
9877
 
        if (!ic) {
9878
 
            // implicitly create input context only if we have a focus
9879
 
            if (hasFocus())
9880
 
                ic = d->inputContext();
9881
 
        }
 
10317
        if (!ic && (!on || hasFocus()))
 
10318
            ic = d->inputContext();
9882
10319
        if (ic) {
9883
 
            if (on && hasFocus() && ic->focusWidget() != this) {
 
10320
            if (on && hasFocus() && ic->focusWidget() != this && isEnabled()) {
9884
10321
                ic->setFocusWidget(this);
9885
10322
            } else if (!on && ic->focusWidget() == this) {
9886
10323
                ic->reset();
9957
10394
        }
9958
10395
 
9959
10396
        break;
 
10397
    case Qt::WA_AcceptTouchEvents:
 
10398
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_WS_S60)
 
10399
        if (on)
 
10400
            d->registerTouchWindow();
 
10401
#endif
 
10402
        break;
9960
10403
    default:
9961
10404
        break;
9962
10405
    }
9987
10430
 
9988
10431
  By default the value of this property is 1.0.
9989
10432
 
9990
 
  This feature is available on Embedded Linux, Mac OS X, X11 platforms that
9991
 
  support the Composite extension, and Windows 2000 and later.
 
10433
  This feature is available on Embedded Linux, Mac OS X, Windows,
 
10434
  and X11 platforms that support the Composite extension.
9992
10435
 
9993
10436
  This feature is not available on Windows CE.
9994
10437
 
10312
10755
*/
10313
10756
void QWidget::updateMicroFocus()
10314
10757
{
10315
 
#if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS))
 
10758
#if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
10316
10759
    Q_D(QWidget);
10317
10760
    // and optimisation to update input context only it has already been created.
10318
10761
    if (d->ic || qApp->d_func()->inputContext) {
10959
11402
    return maybeTopData() ? maybeTopData()->frameStrut : QRect();
10960
11403
}
10961
11404
 
 
11405
#ifdef QT_KEYPAD_NAVIGATION
 
11406
/*!
 
11407
    \internal
 
11408
 
 
11409
    Changes the focus  from the current focusWidget to a widget in
 
11410
    the \a direction.
 
11411
 
 
11412
    Returns true, if there was a widget in that direction
 
11413
*/
 
11414
bool QWidgetPrivate::navigateToDirection(Direction direction)
 
11415
{
 
11416
    QWidget *targetWidget = widgetInNavigationDirection(direction);
 
11417
    if (targetWidget)
 
11418
        targetWidget->setFocus();
 
11419
    return (targetWidget != 0);
 
11420
}
 
11421
 
 
11422
/*!
 
11423
    \internal
 
11424
 
 
11425
    Searches for a widget that is positioned in the \a direction, starting
 
11426
    from the current focusWidget.
 
11427
 
 
11428
    Returns the pointer to a found widget or 0, if there was no widget in
 
11429
    that direction.
 
11430
*/
 
11431
QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction)
 
11432
{
 
11433
    const QWidget *sourceWidget = QApplication::focusWidget();
 
11434
    if (!sourceWidget)
 
11435
        return 0;
 
11436
    const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint()));
 
11437
    const int sourceX =
 
11438
            (direction == DirectionNorth || direction == DirectionSouth) ?
 
11439
                (sourceRect.left() + (sourceRect.right() - sourceRect.left()) / 2)
 
11440
                :(direction == DirectionEast ? sourceRect.right() : sourceRect.left());
 
11441
    const int sourceY =
 
11442
            (direction == DirectionEast || direction == DirectionWest) ?
 
11443
                (sourceRect.top() + (sourceRect.bottom() - sourceRect.top()) / 2)
 
11444
                :(direction == DirectionSouth ? sourceRect.bottom() : sourceRect.top());
 
11445
    const QPoint sourcePoint(sourceX, sourceY);
 
11446
    const QPoint sourceCenter = sourceRect.center();
 
11447
    const QWidget *sourceWindow = sourceWidget->window();
 
11448
 
 
11449
    QWidget *targetWidget = 0;
 
11450
    int shortestDistance = INT_MAX;
 
11451
    foreach(QWidget *targetCandidate, QApplication::allWidgets()) {
 
11452
 
 
11453
        const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint()));
 
11454
 
 
11455
        // For focus proxies, the child widget handling the focus can have keypad navigation focus,
 
11456
        // but the owner of the proxy cannot.
 
11457
        // Additionally, empty widgets should be ignored.
 
11458
        if (targetCandidate->focusProxy() || targetCandidateRect.isEmpty())
 
11459
            continue;
 
11460
 
 
11461
        // Only navigate to a target widget that...
 
11462
        if (       targetCandidate != sourceWidget
 
11463
                   // ...takes the focus,
 
11464
                && targetCandidate->focusPolicy() & Qt::TabFocus
 
11465
                   // ...is above if DirectionNorth,
 
11466
                && !(direction == DirectionNorth && targetCandidateRect.bottom() > sourceRect.top())
 
11467
                   // ...is on the right if DirectionEast,
 
11468
                && !(direction == DirectionEast  && targetCandidateRect.left()   < sourceRect.right())
 
11469
                   // ...is below if DirectionSouth,
 
11470
                && !(direction == DirectionSouth && targetCandidateRect.top()    < sourceRect.bottom())
 
11471
                   // ...is on the left if DirectionWest,
 
11472
                && !(direction == DirectionWest  && targetCandidateRect.right()  > sourceRect.left())
 
11473
                   // ...is enabled,
 
11474
                && targetCandidate->isEnabled()
 
11475
                   // ...is visible,
 
11476
                && targetCandidate->isVisible()
 
11477
                   // ...is in the same window,
 
11478
                && targetCandidate->window() == sourceWindow) {
 
11479
            const int targetCandidateDistance = pointToRect(sourcePoint, targetCandidateRect);
 
11480
            if (targetCandidateDistance < shortestDistance) {
 
11481
                shortestDistance = targetCandidateDistance;
 
11482
                targetWidget = targetCandidate;
 
11483
            }
 
11484
        }
 
11485
    }
 
11486
    return targetWidget;
 
11487
}
 
11488
#endif
 
11489
 
10962
11490
/*!
10963
11491
    \preliminary
10964
11492
    \since 4.2
11117
11645
}
11118
11646
 
11119
11647
 
11120
 
 
11121
 
 
11122
11648
#ifndef QT_NO_GRAPHICSVIEW
11123
11649
/*!
11124
11650
   \since 4.5
11147
11673
    Synonym for QList<QWidget *>.
11148
11674
*/
11149
11675
 
 
11676
void QWidget::grabGesture(Qt::GestureType type, Qt::GestureContext context)
 
11677
{
 
11678
    Q_D(QWidget);
 
11679
    d->gestureContext.insert(type, context);
 
11680
    (void)QGestureManager::instance(); // create a gesture manager
 
11681
}
 
11682
 
11150
11683
QT_END_NAMESPACE
11151
11684
 
11152
11685
#include "moc_qwidget.cpp"