~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): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the gui module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qapplication.h"
 
30
#include "qapplication_p.h"
 
31
#include "qbrush.h"
 
32
#include "qcursor.h"
 
33
#include "qdesktopwidget.h"
 
34
#include "qevent.h"
 
35
#include "qhash.h"
 
36
#include "qlayout.h"
 
37
#include "qmenu.h"
 
38
#include "qmetaobject.h"
 
39
#include "qpixmap.h"
 
40
#include "qpointer.h"
 
41
#include "qstack.h"
 
42
#include "qstyle.h"
 
43
#include "qstylefactory.h"
 
44
#include "qvariant.h"
 
45
#include "qwidget.h"
 
46
#ifndef QT_NO_ACCESSIBILITY
 
47
#include "qaccessible.h"
 
48
#endif
 
49
#if defined(Q_WS_WIN)
 
50
#include "qt_windows.h"
 
51
#endif
 
52
#ifdef Q_WS_MAC
 
53
# include "qt_mac_p.h"
 
54
#endif
 
55
#if defined(Q_WS_QWS)
 
56
#include "qwsmanager_qws.h"
 
57
#endif
 
58
#include "qpainter.h"
 
59
#include "qtooltip.h"
 
60
#include "qwhatsthis.h"
 
61
#include "qdebug.h"
 
62
 
 
63
#include "qinputcontext.h"
 
64
 
 
65
#ifdef Q_WS_WIN
 
66
#include <private/qwininputcontext_p.h>
 
67
#endif
 
68
 
 
69
#if defined(Q_WS_X11)
 
70
#include <private/qpaintengine_x11_p.h>
 
71
#include "qx11info_x11.h"
 
72
#endif
 
73
 
 
74
#include "qwidget_p.h"
 
75
#include "qaction_p.h"
 
76
#include "qlayout_p.h"
 
77
 
 
78
QWidgetPrivate::QWidgetPrivate(int version) :
 
79
        QObjectPrivate(version), extra(0), focus_child(0)
 
80
#ifndef QT_NO_LAYOUT
 
81
        ,layout(0)
 
82
#endif
 
83
        ,leftmargin(0), topmargin(0), rightmargin(0), bottommargin(0)
 
84
        ,fg_role(QPalette::NoRole)
 
85
        ,bg_role(QPalette::NoRole)
 
86
        ,hd(0)
 
87
#if defined(Q_WS_X11)
 
88
        ,picture(0)
 
89
#elif defined(Q_WS_MAC)
 
90
        ,cg_hd(0)
 
91
#endif
 
92
        ,polished(0)
 
93
 
 
94
{
 
95
    if (version != QObjectPrivateVersion)
 
96
        qFatal("Cannot mix incompatible Qt libraries");
 
97
 
 
98
    isWidget = true;
 
99
    memset(high_attributes, 0, sizeof(high_attributes));
 
100
}
 
101
 
 
102
 
 
103
QWidgetPrivate::~QWidgetPrivate()
 
104
{
 
105
    if (extra)
 
106
        deleteExtra();
 
107
}
 
108
 
 
109
/*!
 
110
    \internal
 
111
    This is an internal function, you should never call this.
 
112
 
 
113
    This function is called to remove focus from associated input
 
114
    context.
 
115
 
 
116
    \sa QInputContext::unsetFocus()
 
117
 */
 
118
void QWidgetPrivate::unfocusInputContext()
 
119
{
 
120
#ifndef QT_NO_IM
 
121
    Q_Q(QWidget);
 
122
    QInputContext *qic = q->inputContext();
 
123
    if ( qic ) {
 
124
        qic->setFocusWidget( 0 );
 
125
    }
 
126
#endif // QT_NO_IM
 
127
}
 
128
 
 
129
/*!
 
130
    \internal
 
131
    This is an internal function, you should never call this.
 
132
 
 
133
    This function is called to focus associated input context. The
 
134
    code intends to eliminate duplicate focus for the context even if
 
135
    the context is shared between widgets
 
136
 
 
137
    \sa QInputContext::setFocus()
 
138
 */
 
139
void QWidgetPrivate::focusInputContext()
 
140
{
 
141
#ifndef QT_NO_IM
 
142
    Q_Q(QWidget);
 
143
    QInputContext *qic = q->inputContext();
 
144
    if (qic) {
 
145
        if(qic->focusWidget() != q)
 
146
            qic->setFocusWidget(q);
 
147
    }
 
148
#endif // QT_NO_IM
 
149
}
 
150
 
 
151
/*!
 
152
    This function returns the QInputContext for this widget. By
 
153
    default the input context is inherited from the widgets
 
154
    parent. For toplevels it is inherited from QApplication.
 
155
 
 
156
    You can override this and set a special input context for this
 
157
    widget by using the setInputContext() method.
 
158
 
 
159
    \sa setInputContext()
 
160
*/
 
161
QInputContext *QWidget::inputContext()
 
162
{
 
163
    Q_D(QWidget);
 
164
    if (!testAttribute(Qt::WA_InputMethodEnabled))
 
165
        return 0;
 
166
 
 
167
    if (d->ic)
 
168
        return d->ic;
 
169
    return qApp->inputContext();
 
170
}
 
171
 
 
172
/*!
 
173
  This function sets the input context \a context
 
174
  on this widget.
 
175
 
 
176
  \sa inputContext()
 
177
*/
 
178
void QWidget::setInputContext(QInputContext *context)
 
179
{
 
180
    Q_D(QWidget);
 
181
    if (!testAttribute(Qt::WA_InputMethodEnabled))
 
182
        return;
 
183
    if (d->ic)
 
184
        delete d->ic;
 
185
    d->ic = context;
 
186
}
 
187
 
 
188
 
 
189
/*!
 
190
    This function is called when text widgets need to be neutral state to
 
191
    execute text operations properly. See qlineedit.cpp and qtextedit.cpp as
 
192
    example.
 
193
 
 
194
    Ordinary reset that along with changing focus to another widget,
 
195
    moving the cursor, etc, is implicitly handled via
 
196
    unfocusInputContext() because whether reset or not when such
 
197
    situation is a responsibility of input methods. So we delegate the
 
198
    responsibility to the input context via unfocusInputContext(). See
 
199
    'Preedit preservation' section of the class description of
 
200
    QInputContext for further information.
 
201
 
 
202
    \sa QInputContext, QInputContext::reset()
 
203
*/
 
204
void QWidget::resetInputContext()
 
205
{
 
206
    if (!hasFocus())
 
207
        return;
 
208
#ifndef QT_NO_IM
 
209
    QInputContext *qic = this->inputContext();
 
210
    if( qic )
 
211
        qic->reset();
 
212
#endif // QT_NO_IM
 
213
}
 
214
 
 
215
 
 
216
/*!
 
217
    \class QWidget qwidget.h
 
218
    \brief The QWidget class is the base class of all user interface objects.
 
219
 
 
220
    \ingroup abstractwidgets
 
221
    \mainclass
 
222
 
 
223
    The widget is the atom of the user interface: it receives mouse,
 
224
    keyboard and other events from the window system, and paints a
 
225
    representation of itself on the screen. Every widget is
 
226
    rectangular, and they are sorted in a Z-order. A widget is
 
227
    clipped by its parent and by the widgets in front of it.
 
228
 
 
229
    A widget that isn't embedded in a parent widget is called a
 
230
    window. Usually, windows have a frame and a title bar, although
 
231
    it is also possible to create windows without such decoration using
 
232
    suitable \l{Qt::WindowFlags}{window flags}). In Qt,
 
233
    QMainWindow and the various subclasses of QDialog are the most
 
234
    common window types.
 
235
 
 
236
    A widget without a parent widget is always an independent window.
 
237
 
 
238
    Non-window widgets are child widgets. These are child windows
 
239
    in their parent widgets. You cannot usually distinguish a child
 
240
    widget from its parent visually. Most other widgets in Qt are
 
241
    useful only as child widgets. (It is possible to make, say, a
 
242
    button into a window, but most people prefer to put
 
243
    their buttons inside other widgets, e.g. QDialog.)
 
244
 
 
245
    If you want to use a QWidget to hold child widgets you will
 
246
    probably want to add a layout to the parent QWidget. (See \link
 
247
    layout.html Layouts\endlink.)
 
248
 
 
249
    QWidget has many member functions, but some of them have little
 
250
    direct functionality: for example, QWidget has a font property,
 
251
    but never uses this itself. There are many subclasses which
 
252
    provide real functionality, such as QPushButton, QListWidget and
 
253
    QTabWidget, etc.
 
254
 
 
255
    \section1 Groups of functions:
 
256
 
 
257
    \table
 
258
    \header \i Context \i Functions
 
259
 
 
260
    \row \i Window functions \i
 
261
        show(),
 
262
        hide(),
 
263
        raise(),
 
264
        lower(),
 
265
        close().
 
266
 
 
267
    \row \i Top-level windows \i
 
268
        isWindowModified(),
 
269
        setWindowModified(),
 
270
        windowTitle(),
 
271
        setWindowTitle(),
 
272
        windowIcon(),
 
273
        setWindowIcon(),
 
274
        windowIconText(),
 
275
        setWindowIconText(),
 
276
        isActiveWindow(),
 
277
        activateWindow(),
 
278
        showMinimized().
 
279
        showMaximized(),
 
280
        showFullScreen(),
 
281
        showNormal().
 
282
 
 
283
    \row \i Window contents \i
 
284
        update(),
 
285
        repaint(),
 
286
        scroll().
 
287
 
 
288
    \row \i Geometry \i
 
289
        pos(),
 
290
        size(),
 
291
        rect(),
 
292
        x(),
 
293
        y(),
 
294
        width(),
 
295
        height(),
 
296
        sizePolicy(),
 
297
        setSizePolicy(),
 
298
        sizeHint(),
 
299
        updateGeometry(),
 
300
        layout(),
 
301
        move(),
 
302
        resize(),
 
303
        setGeometry(),
 
304
        frameGeometry(),
 
305
        geometry(),
 
306
        childrenRect(),
 
307
        adjustSize(),
 
308
        mapFromGlobal(),
 
309
        mapFromParent()
 
310
        mapToGlobal(),
 
311
        mapToParent(),
 
312
        maximumSize(),
 
313
        minimumSize(),
 
314
        sizeIncrement(),
 
315
        setMaximumSize(),
 
316
        setMinimumSize(),
 
317
        setSizeIncrement(),
 
318
        setBaseSize(),
 
319
        setFixedSize()
 
320
 
 
321
    \row \i Mode \i
 
322
        isVisible(),
 
323
        isVisibleTo(),
 
324
        isMinimized(),
 
325
        isEnabled(),
 
326
        isEnabledTo(),
 
327
        isModal(),
 
328
        isWindow(),
 
329
        setEnabled(),
 
330
        hasMouseTracking(),
 
331
        setMouseTracking(),
 
332
        updatesEnabled(),
 
333
        setUpdatesEnabled(),
 
334
        visibleRegion().
 
335
 
 
336
    \row \i Look and feel \i
 
337
        style(),
 
338
        setStyle(),
 
339
        cursor(),
 
340
        setCursor()
 
341
        font(),
 
342
        setFont(),
 
343
        palette(),
 
344
        setPalette(),
 
345
        backgroundRole(),
 
346
        setBackgroundRole(),
 
347
        fontMetrics(),
 
348
        fontInfo().
 
349
 
 
350
    \row \i Keyboard focus functions \i
 
351
        setFocusPolicy(),
 
352
        focusPolicy(),
 
353
        hasFocus(),
 
354
        setFocus(),
 
355
        clearFocus(),
 
356
        setTabOrder(),
 
357
        setFocusProxy().
 
358
 
 
359
    \row \i Mouse and keyboard grabbing \i
 
360
        grabMouse(),
 
361
        releaseMouse(),
 
362
        grabKeyboard(),
 
363
        releaseKeyboard(),
 
364
        mouseGrabber(),
 
365
        keyboardGrabber().
 
366
 
 
367
    \row \i Event handlers \i
 
368
        event(),
 
369
        mousePressEvent(),
 
370
        mouseReleaseEvent(),
 
371
        mouseDoubleClickEvent(),
 
372
        mouseMoveEvent(),
 
373
        keyPressEvent(),
 
374
        keyReleaseEvent(),
 
375
        focusInEvent(),
 
376
        focusOutEvent(),
 
377
        wheelEvent(),
 
378
        enterEvent(),
 
379
        leaveEvent(),
 
380
        paintEvent(),
 
381
        moveEvent(),
 
382
        resizeEvent(),
 
383
        closeEvent(),
 
384
        dragEnterEvent(),
 
385
        dragMoveEvent(),
 
386
        dragLeaveEvent(),
 
387
        dropEvent(),
 
388
        childEvent(),
 
389
        showEvent(),
 
390
        hideEvent(),
 
391
        customEvent().
 
392
        changeEvent(),
 
393
 
 
394
    \row \i System functions \i
 
395
        parentWidget(),
 
396
        window(),
 
397
        setParent(),
 
398
        winId(),
 
399
        find(),
 
400
        metric().
 
401
 
 
402
    \row \i What's this help \i
 
403
        setWhatsThis()
 
404
 
 
405
    \row \i Focus functions \i
 
406
        focusNextChild(),
 
407
        focusPreviousChild()
 
408
 
 
409
    \endtable
 
410
 
 
411
    Every widget's constructor accepts one or two standard arguments:
 
412
    \list 1
 
413
    \i \c{QWidget *parent = 0} is the parent of the new widget.
 
414
    If it is 0 (the default), the new widget will be a window.
 
415
    If not, it will be a child of \e parent, and be constrained by \e
 
416
    parent's geometry (unless you specify \c Qt::Window as
 
417
    window flag).
 
418
    \i \c{Qt::WFlags f = 0} (where available) sets the window flags; the
 
419
    default is suitable for almost all widgets, but to get, for
 
420
    example, a window without a window system frame, you
 
421
    must use special flags.
 
422
    \endlist
 
423
 
 
424
    The \l widgets/calculator example program is good example of a simple
 
425
    widget. It contains event handlers (as all widgets must),
 
426
    routines that are specific to it (as all useful widgets
 
427
    do), and has children and connections. Everything it does
 
428
    is done in response to an event: this is by far the most common way
 
429
    to design GUI applications.
 
430
 
 
431
    You will need to supply the content for your widgets yourself, but
 
432
    here is a brief run-down of the events, starting with the most common
 
433
    ones:
 
434
 
 
435
    \list
 
436
 
 
437
    \i paintEvent() - called whenever the widget needs to be
 
438
    repainted. Every widget which displays output must implement it.
 
439
    Painting using a QPainter can only take place in a paintEvent() or
 
440
    a function called by a paintEvent().
 
441
 
 
442
    \i resizeEvent() - called when the widget has been resized.
 
443
 
 
444
    \i mousePressEvent() - called when a mouse button is pressed.
 
445
    There are six mouse-related events, but the mouse press and mouse
 
446
    release events are by far the most important. A widget receives
 
447
    mouse press events when the mouse is inside it, or when it has
 
448
    grabbed the mouse using grabMouse().
 
449
 
 
450
    \i mouseReleaseEvent() - called when a mouse button is released.
 
451
    A widget receives mouse release events when it has received the
 
452
    corresponding mouse press event. This means that if the user
 
453
    presses the mouse inside \e your widget, then drags the mouse to
 
454
    somewhere else, then releases, \e your widget receives the release
 
455
    event. There is one exception: if a popup menu appears while the
 
456
    mouse button is held down, this popup immediately steals the mouse
 
457
    events.
 
458
 
 
459
    \i mouseDoubleClickEvent() - not quite as obvious as it might seem.
 
460
    If the user double-clicks, the widget receives a mouse press event
 
461
    (perhaps a mouse move event or two if they don't hold the mouse
 
462
    quite steady), a mouse release event and finally this event. It is
 
463
    \e{not possible} to distinguish a click from a double click until you've
 
464
    seen whether the second click arrives. (This is one reason why most GUI
 
465
    books recommend that double clicks be an extension of single clicks,
 
466
    rather than trigger a different action.)
 
467
 
 
468
    \endlist
 
469
 
 
470
    If your widget only contains child widgets, you probably do not need to
 
471
    implement any event handlers. If you want to detect a mouse click in
 
472
    a child widget call the child's underMouse() function inside the
 
473
    parent widget's mousePressEvent().
 
474
 
 
475
    Widgets that accept keyboard input need to reimplement a few more
 
476
    event handlers:
 
477
 
 
478
    \list
 
479
 
 
480
    \i keyPressEvent() - called whenever a key is pressed, and again
 
481
    when a key has been held down long enough for it to auto-repeat.
 
482
    Note that the Tab and Shift+Tab keys are only passed to the widget
 
483
    if they are not used by the focus-change mechanisms. To force those
 
484
    keys to be processed by your widget, you must reimplement
 
485
    QWidget::event().
 
486
 
 
487
    \i focusInEvent() - called when the widget gains keyboard focus
 
488
    (assuming you have called setFocusPolicy()). Well written widgets
 
489
    indicate that they own the keyboard focus in a clear but discreet
 
490
    way.
 
491
 
 
492
    \i focusOutEvent() - called when the widget loses keyboard focus.
 
493
 
 
494
    \endlist
 
495
 
 
496
    Some widgets will also need to reimplement some of the less common
 
497
    event handlers:
 
498
 
 
499
    \list
 
500
 
 
501
    \i mouseMoveEvent() - called whenever the mouse moves while a
 
502
    button is held down. This is useful for, for example, dragging. If
 
503
    you call setMouseTracking(true), you get mouse move events even
 
504
    when no buttons are held down. (See also the \link dnd.html drag
 
505
    and drop\endlink information.)
 
506
 
 
507
    \i keyReleaseEvent() - called whenever a key is released, and also
 
508
    while it is held down if the key is auto-repeating. In that case
 
509
    the widget receives a key release event and immediately a key press
 
510
    event for every repeat. Note that the Tab and Shift+Tab keys are
 
511
    only passed to the widget if they are not used by the focus-change
 
512
    mechanisms. To force those keys to be processed by your widget, you
 
513
    must reimplement QWidget::event().
 
514
 
 
515
    \i wheelEvent() -- called whenever the user turns the mouse wheel
 
516
    while the widget has the focus.
 
517
 
 
518
    \i enterEvent() - called when the mouse enters the widget's screen
 
519
    space. (This excludes screen space owned by any children of the
 
520
    widget.)
 
521
 
 
522
    \i leaveEvent() - called when the mouse leaves the widget's screen
 
523
    space.
 
524
 
 
525
    \i moveEvent() - called when the widget has been moved relative to its
 
526
    parent.
 
527
 
 
528
    \i closeEvent() - called when the user closes the widget (or when
 
529
    close() is called).
 
530
 
 
531
    \endlist
 
532
 
 
533
    There are also some rather obscure events. They are listed in
 
534
    \c qevent.h and you need to reimplement event() to handle them.
 
535
    The default implementation of event() handles Tab and Shift+Tab
 
536
    (to move the keyboard focus), and passes on most other events to
 
537
    one of the more specialized handlers above.
 
538
 
 
539
    When implementing a widget, there are a few more things to
 
540
    consider.
 
541
 
 
542
    \list
 
543
 
 
544
    \i In the constructor, be sure to set up your member variables
 
545
    early on, before there's any chance that you might receive an event.
 
546
 
 
547
    \i It is almost always useful to reimplement sizeHint() and to set
 
548
    the correct size policy with setSizePolicy(), so users of your class
 
549
    can set up layout management more easily. A size policy lets you
 
550
    supply good defaults for the layout management handling, so that
 
551
    other widgets can contain and manage yours easily. sizeHint()
 
552
    indicates a "good" size for the widget.
 
553
 
 
554
    \i If your widget is a window, setWindowTitle() and
 
555
    setWindowIcon() set the title bar and icon respectively.
 
556
 
 
557
    \endlist
 
558
 
 
559
    From Qt 4.0, QWidget automatically double-buffers its painting, so
 
560
    there's no need to write double-buffering code in paintEvent() to
 
561
    avoid flicker.
 
562
 
 
563
    \sa QEvent, QPainter, QGridLayout, QBoxLayout
 
564
*/
 
565
 
 
566
 
 
567
QWidgetMapper *QWidgetPrivate::mapper = 0;                // app global widget mapper
 
568
 
 
569
 
 
570
/*****************************************************************************
 
571
  QWidget utility functions
 
572
 *****************************************************************************/
 
573
 
 
574
 
 
575
static QFont qt_naturalWidgetFont(QWidget* w) {
 
576
    QFont naturalfont = QApplication::font(w);
 
577
    if (! w->isWindow()) {
 
578
        if (! naturalfont.isCopyOf(QApplication::font()))
 
579
            naturalfont = naturalfont.resolve(w->parentWidget()->font());
 
580
        else
 
581
            naturalfont = w->parentWidget()->font();
 
582
    }
 
583
    naturalfont.resolve(0);
 
584
    return naturalfont;
 
585
}
 
586
 
 
587
static QPalette qt_naturalWidgetPalette(QWidget* w) {
 
588
    QPalette naturalpalette = QApplication::palette(w);
 
589
    if (! w->isWindow()) {
 
590
        if (! naturalpalette.isCopyOf(QApplication::palette()))
 
591
            naturalpalette = naturalpalette.resolve(w->parentWidget()->palette());
 
592
        else
 
593
            naturalpalette = w->parentWidget()->palette();
 
594
    }
 
595
    naturalpalette.resolve(0);
 
596
    return naturalpalette;
 
597
}
 
598
 
 
599
 
 
600
/*****************************************************************************
 
601
  QWidget member functions
 
602
 *****************************************************************************/
 
603
 
 
604
/*
 
605
    Widget state flags:
 
606
  \list
 
607
  \i Qt::WA_WState_Created The widget has a valid winId().
 
608
  \i Qt::WA_WState_Visible The widget is currently visible.
 
609
  \i Qt::WA_WState_Hidden The widget is hidden, i.e. it won't
 
610
  become visible unless you call show() on it. Qt::WA_WState_Hidden
 
611
  implies !Qt::WA_WState_Visible.
 
612
  \i Qt::WA_WState_CompressKeys Compress keyboard events.
 
613
  \i Qt::WA_WState_BlockUpdates Repaints and updates are disabled.
 
614
  \i Qt::WA_WState_InPaintEvent Currently processing a paint event.
 
615
  \i Qt::WA_WState_Reparented The widget has been reparented.
 
616
  \i Qt::WA_WState_ConfigPending A configuration (resize/move) event is pending.
 
617
  \i Qt::WA_WState_DND The widget supports drag and drop, see setAcceptDrops(). ### depricated
 
618
  \endlist
 
619
*/
 
620
 
 
621
/*!
 
622
    Constructs a widget which is a child of \a parent, with  widget
 
623
    flags set to \a f.
 
624
 
 
625
    If \a parent is 0, the new widget becomes a window. If
 
626
    \a parent is another widget, this widget becomes a child window
 
627
    inside \a parent. The new widget is deleted when its \a parent is
 
628
    deleted.
 
629
 
 
630
    The widget flags argument, \a f, is normally 0, but it can be set
 
631
    to customize the frame of a window (i.e. \a
 
632
    parent must be 0). To customize the frame, use a value composed
 
633
    from the bitwise OR of any of the \l{Qt::WindowFlags}{window flags}.
 
634
 
 
635
    If you add a child widget to an already visible widget you must
 
636
    explicitly show the child to make it visible.
 
637
 
 
638
    Note that the X11 version of Qt may not be able to deliver all
 
639
    combinations of style flags on all systems. This is because on
 
640
    X11, Qt can only ask the window manager, and the window manager
 
641
    can override the application's settings. On Windows, Qt can set
 
642
    whatever flags you want.
 
643
*/
 
644
 
 
645
QWidget::QWidget(QWidget *parent, Qt::WFlags f)
 
646
    : QObject(*new QWidgetPrivate, ((parent && (parent->windowType() == Qt::Desktop)) ? 0 : parent)), QPaintDevice()
 
647
{
 
648
    d_func()->init(f);
 
649
}
 
650
 
 
651
#ifdef QT3_SUPPORT
 
652
/*!
 
653
    \overload
 
654
    \obsolete
 
655
 */
 
656
QWidget::QWidget(QWidget *parent, const char *name, Qt::WFlags f)
 
657
    : QObject(*new QWidgetPrivate, ((parent && (parent->windowType() == Qt::Desktop)) ? 0 : parent)), QPaintDevice()
 
658
{
 
659
    d_func()->init(f);
 
660
    setObjectName(name);
 
661
}
 
662
#endif
 
663
 
 
664
/*! \internal
 
665
*/
 
666
QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WFlags f)
 
667
    : QObject(dd, ((parent && (parent->windowType() == Qt::Desktop)) ? 0 : parent)), QPaintDevice()
 
668
{
 
669
    d_func()->init(f);
 
670
}
 
671
 
 
672
/*!
 
673
    \internal
 
674
*/
 
675
int QWidget::devType() const
 
676
{
 
677
    return QInternal::Widget;
 
678
}
 
679
 
 
680
void QWidgetPrivate::init(Qt::WFlags f)
 
681
{
 
682
    Q_Q(QWidget);
 
683
    q->data = &data;
 
684
    if (qApp->type() == QApplication::Tty)
 
685
        qWarning("QWidget: Cannot create a QWidget when no GUI is being used");
 
686
 
 
687
#ifdef QT_THREAD_SUPPORT
 
688
    if (!q->parent()) {
 
689
        Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget",
 
690
                   "Widgets must be created in the GUI thread.");
 
691
    }
 
692
#endif
 
693
 
 
694
    data.fstrut_dirty = 1;
 
695
 
 
696
    data.winid = 0;
 
697
    data.widget_attributes = 0;
 
698
    data.window_flags = f;
 
699
    data.window_state = 0;
 
700
    data.focus_policy = 0;
 
701
    data.context_menu_policy = Qt::DefaultContextMenu;
 
702
 
 
703
    data.sizehint_forced = 0;
 
704
    data.is_closing = 0;
 
705
    data.in_show = 0;
 
706
    data.in_set_window_state = 0;
 
707
 
 
708
    q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in create()
 
709
 
 
710
    q->create();                                        // platform-dependent init
 
711
#if defined(Q_WS_X11)
 
712
    data.fnt.x11SetScreen(xinfo.screen());
 
713
#endif // Q_WS_X11
 
714
 
 
715
    if (!(q->windowType() == Qt::Desktop))
 
716
        updateSystemBackground();
 
717
    if (q->isWindow()) {
 
718
        if (QApplication::isRightToLeft())
 
719
            q->setAttribute(Qt::WA_RightToLeft);
 
720
#ifdef Q_WS_MAC
 
721
        extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp
 
722
        if(!qt_mac_is_macdrawer(q)) //special case
 
723
            q->setAttribute(Qt::WA_WState_Hidden);
 
724
#else
 
725
        q->setAttribute(Qt::WA_WState_Hidden);
 
726
#endif
 
727
        createTLExtra();
 
728
    } else {
 
729
        QWidget *parentWidget = q->parentWidget();
 
730
        // propagate palette
 
731
        data.pal = parentWidget->data->pal;
 
732
        data.pal.resolve(0);
 
733
        //propagate font
 
734
        data.fnt = parentWidget->data->fnt;
 
735
        data.fnt.resolve(0);
 
736
        // propagate enabled state
 
737
        if (!parentWidget->isEnabled())
 
738
            q->setAttribute(Qt::WA_Disabled, true);
 
739
        // propgate updates enabled state
 
740
        if (!parentWidget->updatesEnabled())
 
741
            q->setAttribute(Qt::WA_UpdatesDisabled, true);
 
742
        //propagate layout direction
 
743
        if (parentWidget->testAttribute(Qt::WA_RightToLeft))
 
744
            q->setAttribute(Qt::WA_RightToLeft);
 
745
        // new widgets do not show up in already visible parents
 
746
        if (parentWidget->isVisible())
 
747
            q->setAttribute(Qt::WA_WState_Hidden);
 
748
    }
 
749
 
 
750
    if (q->isWindow()) {
 
751
        focus_next = q;
 
752
    } else {
 
753
        // insert at the end of the focus chain
 
754
        QWidget *focus_handler = q->window();
 
755
        QWidget *w = focus_handler;
 
756
        while (w->d_func()->focus_next != focus_handler)
 
757
            w = w->d_func()->focus_next;
 
758
        w->d_func()->focus_next = q;
 
759
        focus_next = focus_handler;
 
760
    }
 
761
 
 
762
    q->setAttribute(Qt::WA_PendingMoveEvent);
 
763
    q->setAttribute(Qt::WA_PendingResizeEvent);
 
764
 
 
765
    if (++QWidgetPrivate::instanceCounter > QWidgetPrivate::maxInstances)
 
766
        QWidgetPrivate::maxInstances = QWidgetPrivate::instanceCounter;
 
767
 
 
768
    QEvent e(QEvent::Create);
 
769
    QApplication::sendEvent(q, &e);
 
770
    QApplication::postEvent(q, new QEvent(QEvent::PolishRequest));
 
771
 
 
772
    extraPaintEngine = 0;
 
773
 
 
774
    // send and post remaining QObject events
 
775
    if (q->parent() && sendChildEvents) {
 
776
        QChildEvent e(QEvent::ChildAdded, q);
 
777
        QApplication::sendEvent(q->parent(), &e);
 
778
#ifdef QT3_SUPPORT
 
779
        QApplication::postEvent(q->parent(), new QChildEvent(QEvent::ChildInserted, q));
 
780
#endif
 
781
    }
 
782
}
 
783
 
 
784
 
 
785
/*!
 
786
    Creates a new widget window if \a window is 0, otherwise sets the
 
787
    widget's window to \a window.
 
788
 
 
789
    Initializes the window (sets the geometry etc.) if \a
 
790
    initializeWindow is true. If \a initializeWindow is false, no
 
791
    initialization is performed. This parameter only makes sense if \a
 
792
    window is a valid window.
 
793
 
 
794
    Destroys the old window if \a destroyOldWindow is true. If \a
 
795
    destroyOldWindow is false, you are responsible for destroying the
 
796
    window yourself (using platform native code).
 
797
 
 
798
    The QWidget constructor calls create(0,true,true) to create a
 
799
    window for this widget.
 
800
*/
 
801
 
 
802
void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow)
 
803
{
 
804
    Q_D(QWidget);
 
805
    if (testAttribute(Qt::WA_WState_Created) && window == 0)
 
806
        return;
 
807
    setAttribute(Qt::WA_WState_Created);                        // set created flag
 
808
 
 
809
    Qt::WindowType type = windowType();
 
810
    Qt::WindowFlags &flags = data->window_flags;
 
811
 
 
812
    if (type == Qt::Widget && !parentWidget()) {
 
813
        type = Qt::Window;
 
814
        flags |= Qt::Window;
 
815
    }
 
816
#ifdef QT3_SUPPORT
 
817
    if (flags & Qt::WStaticContents)
 
818
        setAttribute(Qt::WA_StaticContents);
 
819
    if (flags & Qt::WDestructiveClose)
 
820
        setAttribute(Qt::WA_DeleteOnClose);
 
821
    if (flags & Qt::WShowModal)
 
822
        setAttribute(Qt::WA_ShowModal);
 
823
    if (flags & Qt::WMouseNoMask)
 
824
        setAttribute(Qt::WA_MouseNoMask);
 
825
    if (flags & Qt::WGroupLeader)
 
826
        setAttribute(Qt::WA_GroupLeader);
 
827
    if (flags & Qt::WNoMousePropagation)
 
828
        setAttribute(Qt::WA_NoMousePropagation);
 
829
#endif
 
830
    if(type == Qt::Dialog && !testAttribute(Qt::WA_ShowModal)
 
831
       && parentWidget() && parentWidget()->testAttribute(Qt::WA_ShowModal))
 
832
        setAttribute(Qt::WA_ShowModal);
 
833
 
 
834
    if ( type != Qt::Widget && type != Qt::Window)
 
835
        setAttribute(Qt::WA_QuitOnClose, false);
 
836
 
 
837
    d->create_sys(window, initializeWindow, destroyOldWindow);
 
838
 
 
839
#ifdef QT_EVAL
 
840
    extern void qt_eval_init_widget(QWidget *w);
 
841
    qt_eval_init_widget(this);
 
842
#endif
 
843
}
 
844
 
 
845
/*!
 
846
    Destroys the widget.
 
847
 
 
848
    All this widget's children are deleted first. The application
 
849
    exits if this widget is the main widget.
 
850
*/
 
851
 
 
852
QWidget::~QWidget()
 
853
{
 
854
    Q_D(QWidget);
 
855
#if defined (QT_CHECK_STATE)
 
856
    if (paintingActive())
 
857
        qWarning("%s (%s): deleted while being painted", className(), name());
 
858
#endif
 
859
 
 
860
    // remove all actions from this widget
 
861
    for (int i = 0; i < d->actions.size(); ++i) {
 
862
        QActionPrivate *apriv = d->actions.at(i)->d_func();
 
863
        apriv->widgets.removeAll(this);
 
864
    }
 
865
    d->actions.clear();
 
866
 
 
867
    // Remove all shortcuts grabbed by this
 
868
    // widget, unless application is closing
 
869
    if (!QApplicationPrivate::is_app_closing && testAttribute(Qt::WA_GrabbedShortcut))
 
870
        qApp->d_func()->shortcutMap.removeShortcut(0, this, QKeySequence());
 
871
 
 
872
    // delete layout while we still are a valid widget
 
873
#ifndef QT_NO_LAYOUT
 
874
    delete d->layout;
 
875
#endif
 
876
    // Remove myself focus list
 
877
    // ### Focus: maybe remove children aswell?
 
878
    QWidget *w = this;
 
879
    while (w->d_func()->focus_next != this)
 
880
        w = w->d_func()->focus_next;
 
881
    w->d_func()->focus_next = d_func()->focus_next;
 
882
    d_func()->focus_next = 0;
 
883
 
 
884
#ifdef QT3_SUPPORT
 
885
    if (QApplicationPrivate::main_widget == this) {        // reset main widget
 
886
        QApplicationPrivate::main_widget = 0;
 
887
        qApp->quit();
 
888
    }
 
889
#endif
 
890
 
 
891
    clearFocus();
 
892
 
 
893
    if (isWindow() && isVisible() && winId())
 
894
        hide();
 
895
 
 
896
    // A parent widget must destroy all its children before destroying itself
 
897
    while (!d->children.isEmpty())
 
898
        delete d->children.takeFirst();
 
899
 
 
900
    QApplication::removePostedEvents(this);
 
901
 
 
902
    destroy();                                        // platform-dependent cleanup
 
903
 
 
904
    --QWidgetPrivate::instanceCounter;
 
905
 
 
906
    QEvent e(QEvent::Destroy);
 
907
    QCoreApplication::sendEvent(this, &e);
 
908
}
 
909
 
 
910
int QWidgetPrivate::instanceCounter = 0;  // Current number of widget instances
 
911
int QWidgetPrivate::maxInstances = 0;     // Maximum number of widget instances
 
912
 
 
913
void QWidgetPrivate::setWinId(WId id)                // set widget identifier
 
914
{
 
915
    Q_Q(QWidget);
 
916
    if (!mapper)                                // mapper destroyed
 
917
        return;
 
918
    if (data.winid)
 
919
        mapper->remove(data.winid);
 
920
 
 
921
    data.winid = id;
 
922
#if defined(Q_WS_X11)
 
923
    hd = id; // X11: hd == ident
 
924
#endif
 
925
    if (id)
 
926
        mapper->insert(data.winid, q);
 
927
}
 
928
 
 
929
void QWidgetPrivate::createTLExtra()
 
930
{
 
931
    if (!extra)
 
932
        createExtra();
 
933
    if (!extra->topextra) {
 
934
        QTLWExtra* x = extra->topextra = new QTLWExtra;
 
935
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined (Q_WS_QWS)
 
936
        x->opacity = 255;
 
937
#endif
 
938
#ifndef QT_NO_WIDGET_TOPEXTRA
 
939
        x->icon = 0;
 
940
        x->iconPixmap = 0;
 
941
#endif
 
942
        x->fleft = x->fright = x->ftop = x->fbottom = 0;
 
943
        x->incw = x->inch = 0;
 
944
        x->basew = x->baseh = 0;
 
945
        x->normalGeometry = QRect(0,0,-1,-1);
 
946
#if defined(Q_WS_X11)
 
947
        x->embedded = 0;
 
948
        x->parentWinId = 0;
 
949
        x->spont_unmapped = 0;
 
950
        x->dnd = 0;
 
951
        x->uspos = 0;
 
952
        x->ussize = 0;
 
953
#endif
 
954
        x->savedFlags = 0;
 
955
#if defined(Q_WS_QWS)
 
956
        x->inPaintTransaction = false;
 
957
        x->backingStore = 0;
 
958
#if !defined(QT_NO_QWS_MANAGER)
 
959
        x->qwsManager = 0;
 
960
#endif
 
961
#endif
 
962
        createTLSysExtra();
 
963
    }
 
964
}
 
965
 
 
966
/*!
 
967
  \internal
 
968
  Creates the widget extra data.
 
969
*/
 
970
 
 
971
void QWidgetPrivate::createExtra()
 
972
{
 
973
    if (!extra) {                                // if not exists
 
974
        extra = new QWExtra;
 
975
        extra->minw = extra->minh = 0;
 
976
        extra->maxw = extra->maxh = QWIDGETSIZE_MAX;
 
977
        extra->explicitMinSize = 0;
 
978
#ifndef QT_NO_CURSOR
 
979
        extra->curs = 0;
 
980
#endif
 
981
        extra->topextra = 0;
 
982
        extra->style = 0;
 
983
        extra->size_policy = QSizePolicy(QSizePolicy::Preferred,
 
984
                                          QSizePolicy::Preferred);
 
985
        createSysExtra();
 
986
    }
 
987
}
 
988
 
 
989
 
 
990
/*!
 
991
  \internal
 
992
  Deletes the widget extra data.
 
993
*/
 
994
 
 
995
void QWidgetPrivate::deleteExtra()
 
996
{
 
997
    if (extra) {                                // if exists
 
998
#ifndef QT_NO_CURSOR
 
999
        delete extra->curs;
 
1000
#endif
 
1001
        deleteSysExtra();
 
1002
        if (extra->topextra) {
 
1003
            deleteTLSysExtra();
 
1004
#ifndef QT_NO_WIDGET_TOPEXTRA
 
1005
            delete extra->topextra->icon;
 
1006
            delete extra->topextra->iconPixmap;
 
1007
#endif
 
1008
#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
 
1009
            delete extra->topextra->qwsManager;
 
1010
#endif
 
1011
            delete extra->topextra;
 
1012
        }
 
1013
        delete extra;
 
1014
        // extra->xic destroyed in QWidget::destroy()
 
1015
        extra = 0;
 
1016
    }
 
1017
}
 
1018
 
 
1019
/*
 
1020
  Returns true if the background is inherited; otherwise returns
 
1021
  false.
 
1022
 
 
1023
  A widget does not inherit its parent's background if
 
1024
  setBackgroundRole() was called, or a brush is defined for the
 
1025
  background role.
 
1026
*/
 
1027
 
 
1028
bool QWidgetPrivate::isBackgroundInherited() const
 
1029
{
 
1030
    Q_Q(const QWidget);
 
1031
 
 
1032
    // windows do not inherit their background
 
1033
    if (q->isWindow() || q->windowType() == Qt::SubWindow)
 
1034
        return false;
 
1035
 
 
1036
    if (q->testAttribute(Qt::WA_NoSystemBackground) || q->testAttribute(Qt::WA_NoBackground))
 
1037
        return false;
 
1038
 
 
1039
    const QPalette &pal = q->palette();
 
1040
    QPalette::ColorRole bg = q->backgroundRole();
 
1041
    QBrush brush = pal.brush(bg);
 
1042
 
 
1043
    // non opaque brushes leaves us no choice, we must inherit
 
1044
    if (!brush.isOpaque())
 
1045
        return true;
 
1046
 
 
1047
    // if we have a background role set, or a custom brush for the
 
1048
    // background role, then the background is not inherited
 
1049
    if (QPalette::ColorRole(bg_role) != QPalette::NoRole || (pal.resolve() & (1<<bg)))
 
1050
        return false;
 
1051
 
 
1052
    if (brush.style() == Qt::SolidPattern) {
 
1053
        // the background is just a solid color. If there is no
 
1054
        // propagated contents, then we claim as performance
 
1055
        // optimization that it was not inheritet. This is the normal
 
1056
        // case in standard Windows or Motif style.
 
1057
        const QWidget *w = q->parentWidget();
 
1058
        if (!w->testAttribute(Qt::WA_ContentsPropagated) && !w->d_func()->isBackgroundInherited())
 
1059
            return false;
 
1060
    }
 
1061
 
 
1062
    return true;
 
1063
}
 
1064
 
 
1065
/*
 
1066
  In case a widget inherits its parent's pixmap background or content,
 
1067
  and possibly propagates it further to its own children, this
 
1068
  function updates everthing that needs to be updated after a move.
 
1069
 
 
1070
  This is necessary because the pixmap offset has changed. This is not
 
1071
  necessary on Mac OS X because due to the composite manager we get
 
1072
  this for free, and as a result doing it here will actually force
 
1073
  more paints than are necessary, this is a NO-OP for a composited
 
1074
  windowing system like Mac OS X.
 
1075
 */
 
1076
void QWidgetPrivate::updateInheritedBackground()
 
1077
{
 
1078
#if !defined(Q_WS_MAC) && !defined(Q_WS_QWS)
 
1079
    Q_Q(QWidget);
 
1080
    if (!q->isVisible() || !isBackgroundInherited())
 
1081
        return;
 
1082
    q->repaint();
 
1083
    for (int i = 0; i < children.size(); ++i)
 
1084
        if (QWidget *w = qobject_cast<QWidget *>(children.at(i)))
 
1085
            w->d_func()->updateInheritedBackground();
 
1086
#endif
 
1087
}
 
1088
 
 
1089
/*
 
1090
  In case a widget propagates its or its ancestor's contents to its
 
1091
  children, this function updates everything that needs to be updated
 
1092
  after a resize.
 
1093
 
 
1094
  Call this only when Qt::WA_ContentsPropagated is set. This is not
 
1095
  necessary on Mac OS X because due to the composite manager we get
 
1096
  this for free, and as a result doing it here will actually force
 
1097
  more paints than are necessary, this is a NO-OP for a composited
 
1098
  windowing system like Mac OS X.
 
1099
 */
 
1100
void QWidgetPrivate::updatePropagatedBackground(const QRegion *reg)
 
1101
{
 
1102
#if !defined(Q_WS_MAC) && !defined(Q_WS_QWS)
 
1103
    for (int i = 0; i < children.size(); ++i) {
 
1104
        if (QWidget *w = qobject_cast<QWidget*>(children.at(i))) {
 
1105
            if (reg && !reg->boundingRect().intersects(w->geometry()))
 
1106
                continue;
 
1107
            w->d_func()->updateInheritedBackground();
 
1108
        }
 
1109
    }
 
1110
#else
 
1111
    Q_UNUSED(reg)
 
1112
#endif
 
1113
}
 
1114
 
 
1115
 
 
1116
void QWidgetPrivate::composeBackground(const QRect &crect)
 
1117
{
 
1118
    Q_Q(QWidget);
 
1119
#if 0 //DEBUG
 
1120
    static int ii = 0;
 
1121
    //QColor bgCol = QColor::fromHsv(double(ii%5)/5.0, double(ii%33+22)/55.0, double(ii%17+33)/50.0);
 
1122
    QColor bgCol = QColor::fromHsv((ii%5*360)/5, (255*(ii%33+22))/55, (255*(ii%17+33)/50));
 
1123
    QPainter bgPainter(q);
 
1124
    bgPainter.fillRect(crect, bgCol);
 
1125
    ii = (ii+1) % 4095;
 
1126
    return;
 
1127
#endif
 
1128
 
 
1129
 
 
1130
    QPoint offset;
 
1131
    QVector<QWidget*> layers;
 
1132
    QWidget *w = q;
 
1133
    layers += w;
 
1134
 
 
1135
    // Build the stack of widgets to composite
 
1136
    while (w->d_func()->isBackgroundInherited()) {
 
1137
        offset += w->pos();
 
1138
        layers += (w = w->parentWidget());
 
1139
    }
 
1140
 
 
1141
    QWidget *top = w;
 
1142
    for (int i=layers.size() - 1; i>=0; --i) {
 
1143
        w = layers.at(i);
 
1144
 
 
1145
        // Remove the offset for previous layer.
 
1146
        if (top != w)
 
1147
            offset -= w->pos();
 
1148
 
 
1149
        // Do the background if needed.
 
1150
        QBrush bgBrush = w->palette().brush(w->backgroundRole());
 
1151
        if (w == top || (!bgBrush.isOpaque() && w->testAttribute(Qt::WA_SetPalette))) {
 
1152
            QPainter bgPainter(q);
 
1153
            bgPainter.setBrushOrigin(-offset);
 
1154
            bgPainter.fillRect(crect, bgBrush);
 
1155
        }
 
1156
 
 
1157
        // Propagate contents if enabled and w is not the actual widget.
 
1158
        if (w->testAttribute(Qt::WA_ContentsPropagated) && i>0) {
 
1159
            // Setup redirection from w to this widget.
 
1160
            QRect rr = crect;
 
1161
            rr.translate(offset);
 
1162
            bool was_in_paint_event = w->testAttribute(Qt::WA_WState_InPaintEvent);
 
1163
            w->setAttribute(Qt::WA_WState_InPaintEvent);
 
1164
            QPainter::setRedirected(w, q, offset);
 
1165
            QPaintEvent e(rr);
 
1166
            QApplication::sendEvent(w, &e);
 
1167
            w->setAttribute(Qt::WA_WState_InPaintEvent, was_in_paint_event);
 
1168
            QPainter::restoreRedirected(w);
 
1169
        }
 
1170
    }
 
1171
}
 
1172
 
 
1173
 
 
1174
void QWidgetPrivate::setUpdatesEnabled_helper(bool enable)
 
1175
{
 
1176
    Q_Q(QWidget);
 
1177
 
 
1178
    if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->updatesEnabled())
 
1179
        return; // nothing we can do
 
1180
 
 
1181
    if (enable != q->testAttribute(Qt::WA_UpdatesDisabled))
 
1182
        return; // nothing to do
 
1183
 
 
1184
    q->setAttribute(Qt::WA_UpdatesDisabled, !enable);
 
1185
    if (enable)
 
1186
        q->update();
 
1187
 
 
1188
    Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceUpdatesDisabled : Qt::WA_UpdatesDisabled;
 
1189
    for (int i = 0; i < children.size(); ++i) {
 
1190
        QWidget *w = qobject_cast<QWidget *>(children.at(i));
 
1191
        if (w && !w->testAttribute(attribute))
 
1192
            w->d_func()->setUpdatesEnabled_helper(enable);
 
1193
    }
 
1194
}
 
1195
 
 
1196
void QWidgetPrivate::propagatePaletteChange()
 
1197
{
 
1198
    Q_Q(QWidget);
 
1199
    QEvent pc(QEvent::PaletteChange);
 
1200
    QApplication::sendEvent(q, &pc);
 
1201
    if(!children.isEmpty()) {
 
1202
        for(int i = 0; i < children.size(); ++i) {
 
1203
            QWidget *w = qobject_cast<QWidget*>(children.at(i));
 
1204
            if (w && !w->isWindow())
 
1205
                w->d_func()->resolvePalette();
 
1206
        }
 
1207
    }
 
1208
#if defined(QT3_SUPPORT)
 
1209
    q->paletteChange(q->palette()); // compatibility
 
1210
#endif
 
1211
}
 
1212
 
 
1213
 
 
1214
/*
 
1215
  Returns the widget's clipping rectangle.
 
1216
*/
 
1217
QRect QWidgetPrivate::clipRect() const
 
1218
{
 
1219
    Q_Q(const QWidget);
 
1220
    const QWidget * w = q;
 
1221
    if (!w->isVisible())
 
1222
        return QRect();
 
1223
    QRect r = q->rect();
 
1224
    int ox = 0;
 
1225
    int oy = 0;
 
1226
    while (w
 
1227
            && w->isVisible()
 
1228
            && !w->isWindow()
 
1229
            && w->parentWidget()) {
 
1230
        ox -= w->x();
 
1231
        oy -= w->y();
 
1232
        w = w->parentWidget();
 
1233
        r &= QRect(ox, oy, w->width(), w->height());
 
1234
    }
 
1235
    return r;
 
1236
}
 
1237
 
 
1238
bool QWidgetPrivate::isFullyOpaque() const
 
1239
{
 
1240
    Q_Q(const QWidget);
 
1241
    if (q->testAttribute(Qt::WA_NoBackground) || q->testAttribute(Qt::WA_NoSystemBackground)
 
1242
        || q->isWindow() || q->windowType() == Qt::SubWindow)
 
1243
        return true;
 
1244
 
 
1245
    const QPalette &pal = q->palette();
 
1246
    QPalette::ColorRole bg = q->backgroundRole();
 
1247
    QBrush bgBrush = pal.brush(bg);
 
1248
    QPalette::ColorRole bgrl = bg_role;
 
1249
    return (bgBrush.style() != Qt::NoBrush && bgBrush.isOpaque()
 
1250
            && ((bgrl != QPalette::NoRole || (pal.resolve() & (1<<bg)))));
 
1251
}
 
1252
 
 
1253
/*
 
1254
  Returns true if the widget's clipping region (excluding siblings) is
 
1255
  complex; otherwise returns false.
 
1256
*/
 
1257
bool QWidgetPrivate::hasComplexClipRegion() const
 
1258
{
 
1259
    Q_Q(const QWidget);
 
1260
    QRect r(q->rect());
 
1261
    const QWidget * w = q;
 
1262
    const QWidget *ignoreUpTo;
 
1263
    int ox = 0;
 
1264
    int oy = 0;
 
1265
    while (w
 
1266
           && w->isVisible()
 
1267
           && !w->isWindow()
 
1268
           && w->parentWidget()) {
 
1269
        ox -= w->x();
 
1270
        oy -= w->y();
 
1271
        ignoreUpTo = w;
 
1272
        w = w->parentWidget();
 
1273
        r &= QRect(ox, oy, w->width(), w->height());
 
1274
 
 
1275
        int i = 0;
 
1276
        while(w->d_func()->children.at(i++) != static_cast<const QObject *>(ignoreUpTo))
 
1277
            ;
 
1278
        for ( ; i < w->d_func()->children.size(); ++i) {
 
1279
            if(QWidget *sibling = qobject_cast<QWidget *>(w->d_func()->children.at(i))) {
 
1280
                if(sibling->isVisible() && !sibling->isWindow()) {
 
1281
                    QRect siblingRect(ox+sibling->x(), oy+sibling->y(),
 
1282
                                      sibling->width(), sibling->height());
 
1283
                    if(siblingRect.intersects(q->rect()))
 
1284
                        return true;
 
1285
                }
 
1286
            }
 
1287
        }
 
1288
    }
 
1289
    return false;
 
1290
}
 
1291
 
 
1292
 
 
1293
/*!
 
1294
    \fn void QPixmap::fill(const QWidget *widget, const QPoint &offset)
 
1295
 
 
1296
    Fills the pixmap with the \a widget's background color or pixmap.
 
1297
 
 
1298
    The \a offset point is an offset in the widget.
 
1299
 
 
1300
    The point \a offset is a point in the widget's coordinate
 
1301
    system. The pixmap's top-left pixel will be mapped to the point \a
 
1302
    offset in the widget. This is significant if the widget has a
 
1303
    background pixmap; otherwise the pixmap will simply be filled with
 
1304
    the background color of the widget.
 
1305
*/
 
1306
 
 
1307
void QPixmap::fill( const QWidget *widget, const QPoint &off )
 
1308
{
 
1309
    QPainter::setRedirected(widget, this, off);
 
1310
    const_cast<QWidget *>(widget)->d_func()->composeBackground(widget->rect());
 
1311
    QPainter::restoreRedirected(widget);
 
1312
}
 
1313
 
 
1314
/*!
 
1315
  \internal
 
1316
  This function is called when a widget is hidden or destroyed.
 
1317
  It resets some application global pointers that should only refer active,
 
1318
  visible widgets.
 
1319
*/
 
1320
 
 
1321
void QWidgetPrivate::deactivateWidgetCleanup()
 
1322
{
 
1323
    Q_Q(QWidget);
 
1324
    // If this was the active application window, reset it
 
1325
    if (qApp->activeWindow() == q)
 
1326
        qApp->setActiveWindow(0);
 
1327
    // If the is the active mouse press widget, reset it
 
1328
#ifdef Q_WS_MAC
 
1329
    extern QPointer<QWidget> qt_button_down;
 
1330
#else
 
1331
    extern QWidget *qt_button_down;
 
1332
#endif
 
1333
    if (q == qt_button_down)
 
1334
        qt_button_down = 0;
 
1335
}
 
1336
 
 
1337
 
 
1338
/*!
 
1339
    Returns a pointer to the widget with window identifer/handle \a
 
1340
    id.
 
1341
 
 
1342
    The window identifier type depends on the underlying window
 
1343
    system, see \c qwindowdefs.h for the actual definition. If there
 
1344
    is no widget with this identifier, 0 is returned.
 
1345
*/
 
1346
 
 
1347
QWidget *QWidget::find(WId id)
 
1348
{
 
1349
    return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0;
 
1350
}
 
1351
 
 
1352
 
 
1353
 
 
1354
/*!
 
1355
    \fn WId QWidget::winId() const
 
1356
 
 
1357
    Returns the window system identifier of the widget.
 
1358
 
 
1359
    Portable in principle, but if you use it you are probably about to
 
1360
    do something non-portable. Be careful.
 
1361
 
 
1362
 
 
1363
    \sa find()
 
1364
*/
 
1365
 
 
1366
/*!
 
1367
    Returns the GUI style for this widget
 
1368
 
 
1369
    \sa QWidget::setStyle(), QApplication::setStyle(), QApplication::style()
 
1370
*/
 
1371
 
 
1372
QStyle *QWidget::style() const
 
1373
{
 
1374
    Q_D(const QWidget);
 
1375
    if (d->extra && d->extra->style)
 
1376
        return d->extra->style;
 
1377
    return qApp->style();
 
1378
}
 
1379
 
 
1380
/*!
 
1381
    Sets the widget's GUI style to \a style. Ownership of the style
 
1382
    object is not transferred.
 
1383
 
 
1384
    If no style is set, the widget uses the application's style,
 
1385
    QApplication::style() instead.
 
1386
 
 
1387
    Setting a widget's style has no effect on existing or future child
 
1388
    widgets.
 
1389
 
 
1390
    \warning This function is particularly useful for demonstration
 
1391
    purposes, where you want to show Qt's styling capabilities. Real
 
1392
    applications should avoid it and use one consistent GUI style
 
1393
    instead.
 
1394
 
 
1395
    \sa style(), QStyle, QApplication::style(), QApplication::setStyle()
 
1396
*/
 
1397
 
 
1398
void QWidget::setStyle(QStyle *style)
 
1399
{
 
1400
    Q_D(QWidget);
 
1401
    QStyle *old  = QWidget::style();
 
1402
    d->createExtra();
 
1403
    d->extra->style = style;
 
1404
    if (!(windowType() == Qt::Desktop) // (except desktop)
 
1405
         && d->polished) { // (and have been polished)
 
1406
        old->unpolish(this);
 
1407
        QWidget::style()->polish(this);
 
1408
    }
 
1409
    QEvent e(QEvent::StyleChange);
 
1410
    QApplication::sendEvent(this, &e);
 
1411
#ifdef QT3_SUPPORT
 
1412
    styleChange(*old);
 
1413
#endif
 
1414
}
 
1415
 
 
1416
#ifdef QT3_SUPPORT
 
1417
/*!
 
1418
    \overload
 
1419
 
 
1420
    Sets the widget's GUI style to \a style using the QStyleFactory.
 
1421
*/
 
1422
QStyle* QWidget::setStyle(const QString &style)
 
1423
{
 
1424
    QStyle *s = QStyleFactory::create(style);
 
1425
    setStyle(s);
 
1426
    return s;
 
1427
}
 
1428
#endif
 
1429
 
 
1430
/*!
 
1431
    \property QWidget::isWindow
 
1432
    \brief whether the widget is an independent window
 
1433
 
 
1434
    A window is a widget that isn't visually the child of any other
 
1435
    widget and that usually has a frame and a
 
1436
    \l{QWidget::setWindowTitle()}{window title}.
 
1437
 
 
1438
    A window can have a \l{QWidget::parentWidget()}{parent widget}.
 
1439
    It will then be grouped with its parent and deleted when the
 
1440
    parent is deleted, minimized when the parent is minimized etc. If
 
1441
    supported by the window manager, it will also have a common
 
1442
    taskbar entry with its parent.
 
1443
 
 
1444
    QDialog and QMainWindow widgets are by default windows, even if a
 
1445
    parent widget is specified in the constructor. This behavior is
 
1446
    specified by the Qt::Window flag.
 
1447
 
 
1448
    \sa window(), isModal(), parentWidget()
 
1449
*/
 
1450
 
 
1451
/*!
 
1452
    \property QWidget::modal
 
1453
    \brief whether the widget is a modal widget
 
1454
 
 
1455
    This property only makes sense for windows. A modal widget
 
1456
    prevents widgets in all other windows from getting any input.
 
1457
 
 
1458
    \sa isWindow(), QDialog
 
1459
*/
 
1460
 
 
1461
/*!
 
1462
    \fn bool QWidget::underMouse() const
 
1463
 
 
1464
    Returns true if the widget is under the mouse cursor; otherwise
 
1465
    returns false.
 
1466
 
 
1467
    This value is not updated properly during drag and drop
 
1468
    operations.
 
1469
 
 
1470
    \sa enterEvent(), leaveEvent()
 
1471
*/
 
1472
 
 
1473
/*!
 
1474
    \property QWidget::minimized
 
1475
    \brief whether this widget is minimized (iconified)
 
1476
 
 
1477
    This property is only relevant for windows.
 
1478
 
 
1479
    \sa showMinimized(), visible, show(), hide(), showNormal(), maximized
 
1480
*/
 
1481
bool QWidget::isMinimized() const
 
1482
{ return data->window_state & Qt::WindowMinimized; }
 
1483
 
 
1484
/*!
 
1485
    Shows the widget minimized, as an icon.
 
1486
 
 
1487
    Calling this function only affects \l{isWindow()}{windows}.
 
1488
 
 
1489
    \sa showNormal(), showMaximized(), show(), hide(), isVisible(),
 
1490
        isMinimized()
 
1491
*/
 
1492
void QWidget::showMinimized()
 
1493
{
 
1494
    bool isMin = isMinimized();
 
1495
    if (isMin && isVisible()) return;
 
1496
 
 
1497
    ensurePolished();
 
1498
#ifdef QT3_SUPPORT
 
1499
    if (parent())
 
1500
        QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
 
1501
#endif
 
1502
 
 
1503
    if (!isMin)
 
1504
        setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized);
 
1505
    show();
 
1506
}
 
1507
 
 
1508
/*!
 
1509
    \property QWidget::maximized
 
1510
    \brief whether this widget is maximized
 
1511
 
 
1512
    This property is only relevant for windows.
 
1513
 
 
1514
    Note that due to limitations in some window-systems, this does not
 
1515
    always report the expected results (e.g. if the user on X11
 
1516
    maximizes the window via the window manager, Qt has no way of
 
1517
    distinguishing this from any other resize). This is expected to
 
1518
    improve as window manager protocols evolve.
 
1519
 
 
1520
    \sa windowState(), showMaximized(), visible, show(), hide(), showNormal(), minimized
 
1521
*/
 
1522
bool QWidget::isMaximized() const
 
1523
{ return data->window_state & Qt::WindowMaximized; }
 
1524
 
 
1525
 
 
1526
 
 
1527
/*!  Returns the current window state. The window state is a OR'ed
 
1528
  combination of Qt::WindowState: \c Qt::WindowMinimized, \c
 
1529
  Qt::WindowMaximized, \c Qt::WindowFullScreen and \c Qt::WindowActive.
 
1530
 
 
1531
  \sa Qt::WindowState setWindowState()
 
1532
 */
 
1533
Qt::WindowStates QWidget::windowState() const
 
1534
{
 
1535
    return (Qt::WindowStates)data->window_state;
 
1536
}
 
1537
 
 
1538
/*!\internal
 
1539
 
 
1540
   The function sets the window state without sending any events. It
 
1541
   exists mainly to keep Q3Workspace working.
 
1542
 */
 
1543
void QWidget::overrideWindowState(Qt::WindowStates newstate)
 
1544
{
 
1545
    data->window_state  = newstate;
 
1546
}
 
1547
 
 
1548
/*!
 
1549
  \fn void QWidget::setWindowState(Qt::WindowStates windowState)
 
1550
 
 
1551
  Sets the window state to \a windowState. The window state is a OR'ed
 
1552
  combination of Qt::WindowState: \c Qt::WindowMinimized, \c
 
1553
  Qt::WindowMaximized, \c Qt::WindowFullScreen and \c Qt::WindowActive.
 
1554
 
 
1555
  If the window is not visible (i.e. isVisible() returns false), the
 
1556
  window state will take effect when show() is called. For visible
 
1557
  windows, the change is immediate. For example, to toggle between
 
1558
  full-screen and mormal mode, use the following code:
 
1559
 
 
1560
  \code
 
1561
        w->setWindowState(w->windowState() ^ Qt::WindowFullScreen);
 
1562
  \endcode
 
1563
 
 
1564
  In order to restore and activate a minimized window (while
 
1565
  preserving its maximized and/or full-screen state), use the following:
 
1566
 
 
1567
  \code
 
1568
        w->setWindowState(w->windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
 
1569
  \endcode
 
1570
 
 
1571
  Note: On some window systems \c Qt::WindowActive is not immediate, and may be
 
1572
  ignored in certain cases.
 
1573
 
 
1574
  \sa Qt::WindowState windowState()
 
1575
*/
 
1576
 
 
1577
/*!
 
1578
    \property QWidget::fullScreen
 
1579
    \brief whether the widget is full screen
 
1580
 
 
1581
    \sa windowState(), minimized, maximized
 
1582
*/
 
1583
bool QWidget::isFullScreen() const
 
1584
{ return data->window_state & Qt::WindowFullScreen; }
 
1585
 
 
1586
/*!
 
1587
    Shows the widget in full-screen mode.
 
1588
 
 
1589
    Calling this function only affects windows.
 
1590
 
 
1591
    To return from full-screen mode, call showNormal().
 
1592
 
 
1593
    Full-screen mode works fine under Windows, but has certain
 
1594
    problems under X. These problems are due to limitations of the
 
1595
    ICCCM protocol that specifies the communication between X11
 
1596
    clients and the window manager. ICCCM simply does not understand
 
1597
    the concept of non-decorated full-screen windows. Therefore, the
 
1598
    best we can do is to request a borderless window and place and
 
1599
    resize it to fill the entire screen. Depending on the window
 
1600
    manager, this may or may not work. The borderless window is
 
1601
    requested using MOTIF hints, which are at least partially
 
1602
    supported by virtually all modern window managers.
 
1603
 
 
1604
    An alternative would be to bypass the window manager entirely and
 
1605
    create a window with the Qt::WX11BypassWM flag. This has other severe
 
1606
    problems though, like totally broken keyboard focus and very
 
1607
    strange effects on desktop changes or when the user raises other
 
1608
    windows.
 
1609
 
 
1610
    X11 window managers that follow modern post-ICCCM specifications
 
1611
    support full-screen mode properly.
 
1612
 
 
1613
    \sa showNormal(), showMaximized(), show(), hide(), isVisible()
 
1614
*/
 
1615
void QWidget::showFullScreen()
 
1616
{
 
1617
    bool isFull = isFullScreen();
 
1618
    if (isFull && isVisible())
 
1619
        return;
 
1620
 
 
1621
    ensurePolished();
 
1622
#ifdef QT3_SUPPORT
 
1623
    if (parent())
 
1624
        QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
 
1625
#endif
 
1626
 
 
1627
    if (!isFull)
 
1628
        setWindowState(windowState() | Qt::WindowFullScreen);
 
1629
    show();
 
1630
    activateWindow();
 
1631
}
 
1632
 
 
1633
/*!
 
1634
    Shows the widget maximized.
 
1635
 
 
1636
    Calling this function only affects \l{isWindow()}{windows}.
 
1637
 
 
1638
    On X11, this function may not work properly with certain window
 
1639
    managers. See \l{geometry.html}{Window Geometry} for an explanation.
 
1640
 
 
1641
    \sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible()
 
1642
*/
 
1643
void QWidget::showMaximized()
 
1644
{
 
1645
    if (isMaximized() && isVisible() && !isMinimized())
 
1646
        return;
 
1647
 
 
1648
    ensurePolished();
 
1649
#ifdef QT3_SUPPORT
 
1650
    if (parent())
 
1651
        QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
 
1652
#endif
 
1653
 
 
1654
    setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowMaximized);
 
1655
    show();
 
1656
}
 
1657
 
 
1658
/*!
 
1659
    Restores the widget after it has been maximized or minimized.
 
1660
 
 
1661
    Calling this function only affects \l{isWindow()}{windows}.
 
1662
 
 
1663
    \sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible()
 
1664
*/
 
1665
void QWidget::showNormal()
 
1666
{
 
1667
    ensurePolished();
 
1668
#ifdef QT3_SUPPORT
 
1669
    if (parent())
 
1670
        QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
 
1671
#endif
 
1672
 
 
1673
    setWindowState(Qt::WindowNoState);
 
1674
    show();
 
1675
}
 
1676
 
 
1677
/*!
 
1678
    Returns true if this widget would become enabled if \a ancestor is
 
1679
    enabled; otherwise returns false.
 
1680
 
 
1681
 
 
1682
 
 
1683
    This is the case if neither the widget itself nor every parent up
 
1684
    to but excluding \a ancestor has been explicitly disabled.
 
1685
 
 
1686
    isEnabledTo(0) is equivalent to isEnabled().
 
1687
 
 
1688
    \sa setEnabled() enabled
 
1689
*/
 
1690
 
 
1691
bool QWidget::isEnabledTo(QWidget* ancestor) const
 
1692
{
 
1693
    const QWidget * w = this;
 
1694
    while (w && !w->testAttribute(Qt::WA_ForceDisabled)
 
1695
            && !w->isWindow()
 
1696
            && w->parentWidget()
 
1697
            && w->parentWidget() != ancestor)
 
1698
        w = w->parentWidget();
 
1699
    return !w->testAttribute(Qt::WA_ForceDisabled);
 
1700
}
 
1701
 
 
1702
/*!
 
1703
    Appends the action \a action to this widget's list of actions.
 
1704
 
 
1705
    All QWidgets have list of QActions, however they can be
 
1706
    represented graphically in many different ways. The default use of
 
1707
    the QAction list (as returned by actions()) is to create a context
 
1708
    QMenu.
 
1709
 
 
1710
    \sa removeAction() QMenu
 
1711
*/
 
1712
void QWidget::addAction(QAction *action)
 
1713
{
 
1714
    insertAction(0, action);
 
1715
}
 
1716
 
 
1717
/*!
 
1718
    Appends the actions \a actions to this widget's list of actions.
 
1719
 
 
1720
    \sa removeAction() QMenu addAction()
 
1721
*/
 
1722
void QWidget::addActions(QList<QAction*> actions)
 
1723
{
 
1724
    for(int i = 0; i < actions.count(); i++)
 
1725
        insertAction(0, actions.at(i));
 
1726
}
 
1727
 
 
1728
/*!
 
1729
    Inserts the action \a action to this widget's list of actions,
 
1730
    before the action \a before. It appends the action if \a before is 0 or
 
1731
    \a before is not a valid action for this widget.
 
1732
 
 
1733
    \sa addAction()
 
1734
*/
 
1735
void QWidget::insertAction(QAction *before, QAction *action)
 
1736
{
 
1737
    if(!action) {
 
1738
        qWarning("Attempt to insert null action!");
 
1739
        return;
 
1740
    }
 
1741
 
 
1742
    Q_D(QWidget);
 
1743
    if(d->actions.contains(action))
 
1744
        d->actions.removeAll(action);
 
1745
    int pos = d->actions.indexOf(before);
 
1746
    if (pos < 0) {
 
1747
        before = 0;
 
1748
        pos = d->actions.size();
 
1749
    }
 
1750
    d->actions.insert(pos, action);
 
1751
 
 
1752
    QActionPrivate *apriv = action->d_func();
 
1753
    apriv->widgets.append(this);
 
1754
 
 
1755
    QActionEvent e(QEvent::ActionAdded, action, before);
 
1756
    QApplication::sendEvent(this, &e);
 
1757
}
 
1758
 
 
1759
/*!
 
1760
    Inserts the actions \a actions to this widget's list of actions,
 
1761
    before the action \a before. It appends the action if \a before is 0 or
 
1762
    \a before is not a valid action for this widget.
 
1763
 
 
1764
    \sa removeAction() QMenu insertAction()
 
1765
*/
 
1766
void QWidget::insertActions(QAction *before, QList<QAction*> actions)
 
1767
{
 
1768
    for(int i = 0; i < actions.count(); ++i)
 
1769
        insertAction(before, actions.at(i));
 
1770
}
 
1771
 
 
1772
/*!
 
1773
    Removes the action \a action from this widget's list of actions.
 
1774
*/
 
1775
void QWidget::removeAction(QAction *action)
 
1776
{
 
1777
    if (!action)
 
1778
        return;
 
1779
 
 
1780
    Q_D(QWidget);
 
1781
 
 
1782
    QActionPrivate *apriv = action->d_func();
 
1783
    apriv->widgets.removeAll(this);
 
1784
 
 
1785
    if (d->actions.removeAll(action)) {
 
1786
        QActionEvent e(QEvent::ActionRemoved, action);
 
1787
        QApplication::sendEvent(this, &e);
 
1788
    }
 
1789
}
 
1790
 
 
1791
/*!
 
1792
    Returns the (possibly empty) list of this widget's actions.
 
1793
*/
 
1794
QList<QAction*> QWidget::actions() const
 
1795
{
 
1796
    Q_D(const QWidget);
 
1797
    return d->actions;
 
1798
}
 
1799
 
 
1800
/*!
 
1801
  \fn bool QWidget::isEnabledToTLW() const
 
1802
  \obsolete
 
1803
 
 
1804
  This function is deprecated. It is equivalent to isEnabled()
 
1805
*/
 
1806
 
 
1807
/*!
 
1808
    \property QWidget::enabled
 
1809
    \brief whether the widget is enabled
 
1810
 
 
1811
    An enabled widget handles keyboard and mouse events; a disabled
 
1812
    widget does not.
 
1813
 
 
1814
 
 
1815
 
 
1816
    Some widgets display themselves differently when they are
 
1817
    disabled. For example a button might draw its label grayed out. If
 
1818
    your widget needs to know when it becomes enabled or disabled, you
 
1819
    can use the changeEvent() with type QEvent::EnabledChange.
 
1820
 
 
1821
    Disabling a widget implicitly disables all its children. Enabling
 
1822
    respectively enables all child widgets unless they have been
 
1823
    explicitly disabled.
 
1824
 
 
1825
    \sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent()
 
1826
*/
 
1827
void QWidget::setEnabled(bool enable)
 
1828
{
 
1829
    Q_D(QWidget);
 
1830
    setAttribute(Qt::WA_ForceDisabled, !enable);
 
1831
    d->setEnabled_helper(enable);
 
1832
}
 
1833
 
 
1834
void QWidgetPrivate::setEnabled_helper(bool enable)
 
1835
{
 
1836
    Q_Q(QWidget);
 
1837
 
 
1838
    if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->isEnabled())
 
1839
        return; // nothing we can do
 
1840
 
 
1841
    if (enable != q->testAttribute(Qt::WA_Disabled))
 
1842
        return; // nothing to do
 
1843
 
 
1844
    q->setAttribute(Qt::WA_Disabled, !enable);
 
1845
    updateSystemBackground();
 
1846
 
 
1847
    if (!enable && q->window()->focusWidget() == q) {
 
1848
        bool parentIsEnabled = (!q->parentWidget() || q->parentWidget()->isEnabled());
 
1849
        if (!parentIsEnabled || !q->focusNextChild())
 
1850
            q->clearFocus();
 
1851
    }
 
1852
 
 
1853
    Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceDisabled : Qt::WA_Disabled;
 
1854
    for (int i = 0; i < children.size(); ++i) {
 
1855
        QWidget *w = qobject_cast<QWidget *>(children.at(i));
 
1856
        if (w && !w->testAttribute(attribute))
 
1857
            w->d_func()->setEnabled_helper(enable);
 
1858
    }
 
1859
#if defined(Q_WS_X11)
 
1860
    if (q->testAttribute(Qt::WA_SetCursor)) {
 
1861
        // enforce the windows behavior of clearing the cursor on
 
1862
        // disabled widgets
 
1863
        extern void qt_x11_enforce_cursor(QWidget * w); // defined in qwidget_x11.cpp
 
1864
        qt_x11_enforce_cursor(q);
 
1865
    }
 
1866
#endif
 
1867
#ifdef Q_WS_WIN
 
1868
    QWinInputContext::enable(q, q->testAttribute(Qt::WA_InputMethodEnabled) && enable);
 
1869
#endif
 
1870
    QEvent e(QEvent::EnabledChange);
 
1871
    QApplication::sendEvent(q, &e);
 
1872
#ifdef QT3_SUPPORT
 
1873
    q->enabledChange(!enable); // compatibility
 
1874
#endif
 
1875
}
 
1876
 
 
1877
/*!
 
1878
    \property QWidget::acceptDrops
 
1879
    \brief whether drop events are enabled for this widget
 
1880
 
 
1881
    Setting this property to true announces to the system that this
 
1882
    widget \e may be able to accept drop events.
 
1883
 
 
1884
    If the widget is the desktop (QWidget::(windowType() == Qt::Desktop)), this may
 
1885
    fail if another application is using the desktop; you can call
 
1886
    acceptDrops() to test if this occurs.
 
1887
 
 
1888
    \warning
 
1889
    Do not modify this property in a Drag&Drop event handler.
 
1890
*/
 
1891
bool QWidget::acceptDrops() const
 
1892
{
 
1893
    return testAttribute(Qt::WA_AcceptDrops);
 
1894
}
 
1895
 
 
1896
void QWidget::setAcceptDrops(bool on)
 
1897
{
 
1898
    setAttribute(Qt::WA_ForceAcceptDrops, on);
 
1899
    d_func()->setAcceptDrops_helper(on);
 
1900
}
 
1901
 
 
1902
void QWidgetPrivate::setAcceptDrops_helper(bool on)
 
1903
{
 
1904
    Q_Q(QWidget);
 
1905
 
 
1906
    if (!on && !q->isWindow() && q->parentWidget() && q->parentWidget()->acceptDrops())
 
1907
        return; // nothing we can do
 
1908
 
 
1909
    if (on == q->testAttribute(Qt::WA_AcceptDrops))
 
1910
        return; // nothing to do
 
1911
 
 
1912
    if (!setAcceptDrops_sys(on))
 
1913
        return; // nothing was changed
 
1914
 
 
1915
    q->setAttribute(Qt::WA_AcceptDrops, on);
 
1916
 
 
1917
    Qt::WidgetAttribute attribute = on ? Qt::WA_AcceptDrops : Qt::WA_ForceAcceptDrops;
 
1918
    for (int i = 0; i < children.size(); ++i) {
 
1919
        QWidget *w = qobject_cast<QWidget *>(children.at(i));
 
1920
        if (w && !w->testAttribute(attribute))
 
1921
            w->d_func()->setAcceptDrops_helper(on);
 
1922
    }
 
1923
}
 
1924
 
 
1925
/*!
 
1926
    \fn void QWidget::enabledChange(bool)
 
1927
 
 
1928
    \internal
 
1929
    \obsolete
 
1930
*/
 
1931
 
 
1932
/*!
 
1933
    \fn void QWidget::paletteChange(const QPalette &)
 
1934
 
 
1935
    \internal
 
1936
    \obsolete
 
1937
*/
 
1938
 
 
1939
/*!
 
1940
    \fn void QWidget::fontChange(const QFont &)
 
1941
 
 
1942
    \internal
 
1943
    \obsolete
 
1944
*/
 
1945
 
 
1946
/*!
 
1947
    \fn void QWidget::windowActivationChange(bool)
 
1948
 
 
1949
    \internal
 
1950
    \obsolete
 
1951
*/
 
1952
 
 
1953
/*!
 
1954
    \fn void QWidget::languageChange()
 
1955
 
 
1956
    \internal
 
1957
    \obsolete
 
1958
*/
 
1959
 
 
1960
/*!
 
1961
    \fn void QWidget::styleChange(QStyle& style)
 
1962
 
 
1963
    \internal
 
1964
    \obsolete
 
1965
*/
 
1966
 
 
1967
/*!
 
1968
    Disables widget input events if \a disable is true; otherwise
 
1969
    enables input events.
 
1970
 
 
1971
    See the \l enabled documentation for more information.
 
1972
 
 
1973
    \sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent()
 
1974
*/
 
1975
void QWidget::setDisabled(bool disable)
 
1976
{
 
1977
    setEnabled(!disable);
 
1978
}
 
1979
 
 
1980
/*!
 
1981
    \property QWidget::frameGeometry
 
1982
    \brief geometry of the widget relative to its parent including any
 
1983
    window frame
 
1984
 
 
1985
    See the \link geometry.html Window Geometry documentation\endlink
 
1986
    for an overview of geometry issues with windows.
 
1987
 
 
1988
    \sa geometry() x() y() pos()
 
1989
*/
 
1990
QRect QWidget::frameGeometry() const
 
1991
{
 
1992
    Q_D(const QWidget);
 
1993
    if (isWindow() && ! (windowType() == Qt::Popup)) {
 
1994
        if (data->fstrut_dirty)
 
1995
            d->updateFrameStrut();
 
1996
        QTLWExtra *top = d->topData();
 
1997
        return QRect(data->crect.x() - top->fleft,
 
1998
                     data->crect.y() - top->ftop,
 
1999
                     data->crect.width() + top->fleft + top->fright,
 
2000
                     data->crect.height() + top->ftop + top->fbottom);
 
2001
    }
 
2002
    return data->crect;
 
2003
}
 
2004
 
 
2005
/*!
 
2006
    \property QWidget::x
 
2007
 
 
2008
    \brief the x coordinate of the widget relative to its parent including
 
2009
    any window frame
 
2010
 
 
2011
    See the \link geometry.html Window Geometry documentation\endlink
 
2012
    for an overview of window geometry.
 
2013
 
 
2014
    \sa frameGeometry, y, pos
 
2015
*/
 
2016
int QWidget::x() const
 
2017
{
 
2018
    Q_D(const QWidget);
 
2019
    if (isWindow() && ! (windowType() == Qt::Popup)) {
 
2020
        if (data->fstrut_dirty)
 
2021
            d->updateFrameStrut();
 
2022
        return data->crect.x() - d->topData()->fleft;
 
2023
    }
 
2024
    return data->crect.x();
 
2025
}
 
2026
 
 
2027
/*!
 
2028
    \property QWidget::y
 
2029
    \brief the y coordinate of the widget relative to its parent and
 
2030
    including any window frame
 
2031
 
 
2032
    See the \link geometry.html Window Geometry documentation\endlink
 
2033
    for an overview of window geometry.
 
2034
 
 
2035
    \sa frameGeometry, x, pos
 
2036
*/
 
2037
int QWidget::y() const
 
2038
{
 
2039
    Q_D(const QWidget);
 
2040
    if (isWindow() && ! (windowType() == Qt::Popup)) {
 
2041
        if (data->fstrut_dirty)
 
2042
            d->updateFrameStrut();
 
2043
        return data->crect.y() - d->topData()->ftop;
 
2044
    }
 
2045
    return data->crect.y();
 
2046
}
 
2047
 
 
2048
/*!
 
2049
    \property QWidget::pos
 
2050
    \brief the position of the widget within its parent widget
 
2051
 
 
2052
    If the widget is a window, the position is that of the widget on
 
2053
    the desktop, including its frame.
 
2054
 
 
2055
    When changing the position, the widget, if visible, receives a
 
2056
    move event (moveEvent()) immediately. If the widget is not
 
2057
    currently visible, it is guaranteed to receive an event before it
 
2058
    is shown.
 
2059
 
 
2060
    move() is virtual, and all other overloaded move() implementations
 
2061
    in Qt call it.
 
2062
 
 
2063
    \warning Calling move() or setGeometry() inside moveEvent() can
 
2064
    lead to infinite recursion.
 
2065
 
 
2066
    See the \link geometry.html Window Geometry documentation\endlink
 
2067
    for an overview of window geometry.
 
2068
 
 
2069
    \sa frameGeometry, size x(), y()
 
2070
*/
 
2071
QPoint QWidget::pos() const
 
2072
{
 
2073
    Q_D(const QWidget);
 
2074
    if (isWindow() && ! (windowType() == Qt::Popup)) {
 
2075
        if (data->fstrut_dirty)
 
2076
            d->updateFrameStrut();
 
2077
        QTLWExtra *top = d->topData();
 
2078
        return QPoint(data->crect.x() - top->fleft, data->crect.y() - top->ftop);
 
2079
    }
 
2080
    return data->crect.topLeft();
 
2081
}
 
2082
 
 
2083
/*!
 
2084
    \property QWidget::geometry
 
2085
    \brief the geometry of the widget relative to its parent and
 
2086
    excluding the window frame
 
2087
 
 
2088
    When changing the geometry, the widget, if visible, receives a
 
2089
    move event (moveEvent()) and/or a resize event (resizeEvent())
 
2090
    immediately. If the widget is not currently visible, it is
 
2091
    guaranteed to receive appropriate events before it is shown.
 
2092
 
 
2093
    The size component is adjusted if it lies outside the range
 
2094
    defined by minimumSize() and maximumSize().
 
2095
 
 
2096
    \warning Calling setGeometry() inside resizeEvent() or moveEvent()
 
2097
    can lead to infinite recursion.
 
2098
 
 
2099
    See the \link geometry.html Window Geometry documentation\endlink
 
2100
    for an overview of window geometry.
 
2101
 
 
2102
    \sa frameGeometry(), rect(), move(), resize(), moveEvent(),
 
2103
        resizeEvent(), minimumSize(), maximumSize()
 
2104
*/
 
2105
 
 
2106
/*!
 
2107
    \property QWidget::normalGeometry
 
2108
    \brief the geometry a toplevel widget has when it is not maximized or fullscreen
 
2109
 
 
2110
    For child widgets this property always holds an empty rect.
 
2111
 
 
2112
    \sa QWidget::windowState(), QWidget::geometry
 
2113
*/
 
2114
 
 
2115
/*!
 
2116
    \property QWidget::size
 
2117
    \brief the size of the widget excluding any window frame
 
2118
 
 
2119
    If the widget is visible when it is being resized, it receives a resize event
 
2120
    (resizeEvent()) immediately. If the widget is not currently
 
2121
    visible, it is guaranteed to receive an event before it is shown.
 
2122
 
 
2123
    The size is adjusted if it lies outside the range defined by
 
2124
    minimumSize() and maximumSize(). For windows, the minimum size
 
2125
    is always at least QSize(1, 1), and it might be larger, depending on
 
2126
    the window manager.
 
2127
 
 
2128
    \warning Calling resize() or setGeometry() inside resizeEvent() can
 
2129
    lead to infinite recursion.
 
2130
 
 
2131
    \sa pos, geometry, minimumSize, maximumSize, resizeEvent()
 
2132
*/
 
2133
 
 
2134
/*!
 
2135
    \property QWidget::width
 
2136
    \brief the width of the widget excluding any window frame
 
2137
 
 
2138
    See the \link geometry.html Window Geometry documentation\endlink
 
2139
    for an overview of window geometry.
 
2140
 
 
2141
    \sa geometry, height, size
 
2142
*/
 
2143
 
 
2144
/*!
 
2145
    \property QWidget::height
 
2146
    \brief the height of the widget excluding any window frame
 
2147
 
 
2148
    See the \link geometry.html Window Geometry documentation\endlink
 
2149
    for an overview of window geometry.
 
2150
 
 
2151
    \sa geometry, width, size
 
2152
*/
 
2153
 
 
2154
/*!
 
2155
    \property QWidget::rect
 
2156
    \brief the internal geometry of the widget excluding any window
 
2157
    frame
 
2158
 
 
2159
    The rect property equals QRect(0, 0, width(), height()).
 
2160
 
 
2161
    See the \link geometry.html Window Geometry documentation\endlink
 
2162
    for an overview of window geometry.
 
2163
 
 
2164
    \sa size
 
2165
*/
 
2166
 
 
2167
 
 
2168
QRect QWidget::normalGeometry() const
 
2169
{
 
2170
    Q_D(const QWidget);
 
2171
    if (!d->extra || !d->extra->topextra)
 
2172
        return QRect();
 
2173
 
 
2174
    if (!isMaximized() && !isFullScreen())
 
2175
        return geometry();
 
2176
 
 
2177
    return d->topData()->normalGeometry;
 
2178
}
 
2179
 
 
2180
 
 
2181
/*!
 
2182
    \property QWidget::childrenRect
 
2183
    \brief the bounding rectangle of the widget's children
 
2184
 
 
2185
    Hidden children are excluded.
 
2186
 
 
2187
    \sa childrenRegion() geometry()
 
2188
*/
 
2189
 
 
2190
QRect QWidget::childrenRect() const
 
2191
{
 
2192
    Q_D(const QWidget);
 
2193
    QRect r(0, 0, 0, 0);
 
2194
    for (int i = 0; i < d->children.size(); ++i) {
 
2195
        QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
 
2196
        if (w && !w->isWindow() && !w->isHidden())
 
2197
            r |= w->geometry();
 
2198
    }
 
2199
    return r;
 
2200
}
 
2201
 
 
2202
/*!
 
2203
    \property QWidget::childrenRegion
 
2204
    \brief the combined region occupied by the widget's children
 
2205
 
 
2206
    Hidden children are excluded.
 
2207
 
 
2208
    \sa childrenRect() geometry()
 
2209
*/
 
2210
 
 
2211
QRegion QWidget::childrenRegion() const
 
2212
{
 
2213
    Q_D(const QWidget);
 
2214
    QRegion r;
 
2215
    for (int i = 0; i < d->children.size(); ++i) {
 
2216
        QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
 
2217
        if (w && !w->isWindow() && !w->isHidden()) {
 
2218
            QRegion mask = w->mask();
 
2219
            if (mask.isEmpty())
 
2220
                r |= w->geometry();
 
2221
            else
 
2222
                r |= mask;
 
2223
        }
 
2224
    }
 
2225
    return r;
 
2226
}
 
2227
 
 
2228
 
 
2229
/*!
 
2230
    \property QWidget::minimumSize
 
2231
    \brief the widget's minimum size
 
2232
 
 
2233
    The widget cannot be resized to a smaller size than the minimum
 
2234
    widget size. The widget's size is forced to the minimum size if
 
2235
    the current size is smaller.
 
2236
 
 
2237
    The minimum size set by this function will override the minimum size defined by QLayout.
 
2238
 
 
2239
    \sa minimumWidth, minimumHeight, maximumSize, sizeIncrement
 
2240
*/
 
2241
 
 
2242
QSize QWidget::minimumSize() const
 
2243
{
 
2244
    Q_D(const QWidget);
 
2245
    return d->extra ? QSize(d->extra->minw, d->extra->minh) : QSize(0, 0);
 
2246
}
 
2247
 
 
2248
/*!
 
2249
    \property QWidget::maximumSize
 
2250
    \brief the widget's maximum size
 
2251
 
 
2252
    The widget cannot be resized to a larger size than the maximum
 
2253
    widget size.
 
2254
 
 
2255
    \sa maximumWidth, maximumHeight, minimumSize, sizeIncrement
 
2256
*/
 
2257
 
 
2258
QSize QWidget::maximumSize() const
 
2259
{
 
2260
    Q_D(const QWidget);
 
2261
    return d->extra ? QSize(d->extra->maxw, d->extra->maxh)
 
2262
                 : QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
 
2263
}
 
2264
 
 
2265
 
 
2266
/*!
 
2267
    \property QWidget::minimumWidth
 
2268
    \brief the widget's minimum width
 
2269
 
 
2270
    This property corresponds to minimumSize().width().
 
2271
 
 
2272
    \sa minimumSize, minimumHeight
 
2273
*/
 
2274
 
 
2275
/*!
 
2276
    \property QWidget::minimumHeight
 
2277
    \brief the widget's minimum height
 
2278
 
 
2279
    This property corresponds to minimumSize().height().
 
2280
 
 
2281
    \sa minimumSize, minimumWidth
 
2282
*/
 
2283
 
 
2284
/*!
 
2285
    \property QWidget::maximumWidth
 
2286
    \brief the widget's maximum width
 
2287
 
 
2288
    This property corresponds to maximumSize().width().
 
2289
 
 
2290
    \sa maximumSize, maximumHeight
 
2291
*/
 
2292
 
 
2293
/*!
 
2294
    \property QWidget::maximumHeight
 
2295
    \brief the widget's maximum height
 
2296
 
 
2297
    This property corresponds to maximumSize().height().
 
2298
 
 
2299
    \sa maximumSize, maximumWidth
 
2300
*/
 
2301
 
 
2302
/*!
 
2303
    \property QWidget::sizeIncrement
 
2304
    \brief the size increment of the widget
 
2305
 
 
2306
    When the user resizes the window, the size will move in steps of
 
2307
    sizeIncrement().width() pixels horizontally and
 
2308
    sizeIncrement.height() pixels vertically, with baseSize() as the
 
2309
    basis. Preferred widget sizes are for non-negative integers \e i
 
2310
    and \e j:
 
2311
    \code
 
2312
        width = baseSize().width() + i * sizeIncrement().width();
 
2313
        height = baseSize().height() + j * sizeIncrement().height();
 
2314
    \endcode
 
2315
 
 
2316
    Note that while you can set the size increment for all widgets, it
 
2317
    only affects windows.
 
2318
 
 
2319
    \warning The size increment has no effect under Windows, and may
 
2320
    be disregarded by the window manager on X.
 
2321
 
 
2322
    \sa size, minimumSize, maximumSize
 
2323
*/
 
2324
QSize QWidget::sizeIncrement() const
 
2325
{
 
2326
    Q_D(const QWidget);
 
2327
    return (d->extra && d->extra->topextra)
 
2328
        ? QSize(d->extra->topextra->incw, d->extra->topextra->inch)
 
2329
        : QSize(0, 0);
 
2330
}
 
2331
 
 
2332
/*!
 
2333
    \property QWidget::baseSize
 
2334
    \brief the base size of the widget
 
2335
 
 
2336
    The base size is used to calculate a proper widget size if the
 
2337
    widget defines sizeIncrement().
 
2338
 
 
2339
    \sa setSizeIncrement()
 
2340
*/
 
2341
 
 
2342
QSize QWidget::baseSize() const
 
2343
{
 
2344
    Q_D(const QWidget);
 
2345
    return (d->extra != 0 && d->extra->topextra != 0)
 
2346
        ? QSize(d->extra->topextra->basew, d->extra->topextra->baseh)
 
2347
        : QSize(0, 0);
 
2348
}
 
2349
 
 
2350
#ifdef Q_WS_QWS
 
2351
extern QRect qt_maxWindowRect;
 
2352
#endif
 
2353
 
 
2354
/*!
 
2355
    \overload
 
2356
 
 
2357
    This function corresponds to setMinimumSize(QSize(minw, minh)).
 
2358
    Sets the minimum width to \a minw and the minimum height to \a
 
2359
    minh.
 
2360
*/
 
2361
 
 
2362
void QWidget::setMinimumSize(int minw, int minh)
 
2363
{
 
2364
    Q_D(QWidget);
 
2365
#ifdef Q_WS_QWS
 
2366
    if (!qt_maxWindowRect.isEmpty()) {
 
2367
        // ### This is really just a work-around. Layout shouldn't be asking
 
2368
        // for minimum sizes bigger than the screen.
 
2369
        if (minw > qt_maxWindowRect.width())
 
2370
            minw = qt_maxWindowRect.width();
 
2371
        if (minh > qt_maxWindowRect.height())
 
2372
            minh = qt_maxWindowRect.height();
 
2373
    }
 
2374
#endif
 
2375
    if (minw < 0 || minh < 0)
 
2376
        qWarning("QWidget::setMinimumSize: The smallest allowed size is (0,0)");
 
2377
    d->createExtra();
 
2378
    if (d->extra->minw == minw && d->extra->minh == minh)
 
2379
        return;
 
2380
    d->extra->minw = minw;
 
2381
    d->extra->minh = minh;
 
2382
    d->extra->explicitMinSize = (minw ? Qt::Horizontal : 0) | (minh ? Qt::Vertical : 0);
 
2383
 
 
2384
    if (minw > width() || minh > height()) {
 
2385
        bool resized = testAttribute(Qt::WA_Resized);
 
2386
        bool maximized = isMaximized();
 
2387
        resize(qMax(minw,width()), qMax(minh,height()));
 
2388
        setAttribute(Qt::WA_Resized, resized); //not a user resize
 
2389
        if (maximized)
 
2390
            data->window_state = data->window_state | Qt::WindowMaximized;
 
2391
    }
 
2392
    if (isWindow())
 
2393
        d->setConstraints_sys();
 
2394
    updateGeometry();
 
2395
}
 
2396
 
 
2397
/*!
 
2398
    \overload
 
2399
 
 
2400
    This function corresponds to setMaximumSize(QSize(\a maxw, \a
 
2401
    maxh)). Sets the maximum width to \a maxw and the maximum height
 
2402
    to \a maxh.
 
2403
*/
 
2404
void QWidget::setMaximumSize(int maxw, int maxh)
 
2405
{
 
2406
    Q_D(QWidget);
 
2407
    if (maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX) {
 
2408
        qWarning("QWidget::setMaximumSize: (%s/%s) "
 
2409
                "The largest allowed size is (%d,%d)",
 
2410
                 objectName().toLocal8Bit().data(), metaObject()->className(), QWIDGETSIZE_MAX,
 
2411
                QWIDGETSIZE_MAX);
 
2412
        maxw = qMin<int>(maxw, QWIDGETSIZE_MAX);
 
2413
        maxh = qMin<int>(maxh, QWIDGETSIZE_MAX);
 
2414
    }
 
2415
    if (maxw < 0 || maxh < 0) {
 
2416
        qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) "
 
2417
                "are not possible",
 
2418
                objectName().toLocal8Bit().data(), metaObject()->className(), maxw, maxh);
 
2419
        maxw = qMax(maxw, 0);
 
2420
        maxh = qMax(maxh, 0);
 
2421
    }
 
2422
    d->createExtra();
 
2423
    if (d->extra->maxw == maxw && d->extra->maxh == maxh)
 
2424
        return;
 
2425
    d->extra->maxw = maxw;
 
2426
    d->extra->maxh = maxh;
 
2427
    if (maxw < width() || maxh < height()) {
 
2428
        bool resized = testAttribute(Qt::WA_Resized);
 
2429
        resize(qMin(maxw,width()), qMin(maxh,height()));
 
2430
        setAttribute(Qt::WA_Resized, resized); //not a user resize
 
2431
    }
 
2432
    if (isWindow())
 
2433
        d->setConstraints_sys();
 
2434
    updateGeometry();
 
2435
}
 
2436
 
 
2437
/*!
 
2438
    \overload
 
2439
 
 
2440
    Sets the x (width) size increment to \a w and the y (height) size
 
2441
    increment to \a h.
 
2442
*/
 
2443
void QWidget::setSizeIncrement(int w, int h)
 
2444
{
 
2445
    Q_D(QWidget);
 
2446
    d->createTLExtra();
 
2447
    QTLWExtra* x = d->topData();
 
2448
    if (x->incw == w && x->inch == h)
 
2449
        return;
 
2450
    x->incw = w;
 
2451
    x->inch = h;
 
2452
    if (isWindow())
 
2453
        d->setConstraints_sys();
 
2454
}
 
2455
 
 
2456
/*!
 
2457
    \overload
 
2458
 
 
2459
    This corresponds to setBaseSize(QSize(\a basew, \a baseh)). Sets
 
2460
    the widgets base size to width \a basew and height \a baseh.
 
2461
*/
 
2462
void QWidget::setBaseSize(int basew, int baseh)
 
2463
{
 
2464
    Q_D(QWidget);
 
2465
    d->createTLExtra();
 
2466
    QTLWExtra* x = d->topData();
 
2467
    if (x->basew == basew && x->baseh == baseh)
 
2468
        return;
 
2469
    x->basew = basew;
 
2470
    x->baseh = baseh;
 
2471
    if (isWindow())
 
2472
        d->setConstraints_sys();
 
2473
}
 
2474
 
 
2475
/*!
 
2476
    Sets both the minimum and maximum sizes of the widget to \a s,
 
2477
    thereby preventing it from ever growing or shrinking.
 
2478
 
 
2479
    This will override the default size constraints set by QLayout.
 
2480
 
 
2481
    Alternatively, if you want the widget to have a
 
2482
    fixed size based on its contents, you can call
 
2483
    QLayout::setSizeConstraint(QLayout::SetFixedSize);
 
2484
 
 
2485
    \sa maximumSize, minimumSize
 
2486
*/
 
2487
 
 
2488
void QWidget::setFixedSize(const QSize & s)
 
2489
{
 
2490
    setMinimumSize(s);
 
2491
    setMaximumSize(s);
 
2492
    resize(s);
 
2493
}
 
2494
 
 
2495
 
 
2496
/*!
 
2497
    \fn void QWidget::setFixedSize(int w, int h)
 
2498
    \overload
 
2499
 
 
2500
    Sets the width of the widget to \a w and the height to \a h.
 
2501
*/
 
2502
 
 
2503
void QWidget::setFixedSize(int w, int h)
 
2504
{
 
2505
    setMinimumSize(w, h);
 
2506
    setMaximumSize(w, h);
 
2507
    resize(w, h);
 
2508
}
 
2509
 
 
2510
void QWidget::setMinimumWidth(int w)
 
2511
{
 
2512
    Q_D(QWidget);
 
2513
    d->createExtra();
 
2514
    uint expl = d->extra->explicitMinSize | (w ? Qt::Horizontal : 0);
 
2515
    setMinimumSize(w, minimumSize().height());
 
2516
    d->extra->explicitMinSize = expl;
 
2517
}
 
2518
 
 
2519
void QWidget::setMinimumHeight(int h)
 
2520
{
 
2521
    Q_D(QWidget);
 
2522
    d->createExtra();
 
2523
    uint expl = d->extra->explicitMinSize | (h ? Qt::Vertical : 0);
 
2524
    setMinimumSize(minimumSize().width(), h);
 
2525
    d->extra->explicitMinSize = expl;
 
2526
}
 
2527
 
 
2528
void QWidget::setMaximumWidth(int w)
 
2529
{
 
2530
    setMaximumSize(w, maximumSize().height());
 
2531
}
 
2532
 
 
2533
void QWidget::setMaximumHeight(int h)
 
2534
{
 
2535
    setMaximumSize(maximumSize().width(), h);
 
2536
}
 
2537
 
 
2538
/*!
 
2539
    Sets both the minimum and maximum width of the widget to \a w
 
2540
    without changing the heights. Provided for convenience.
 
2541
 
 
2542
    \sa sizeHint() minimumSize() maximumSize() setFixedSize()
 
2543
*/
 
2544
 
 
2545
void QWidget::setFixedWidth(int w)
 
2546
{
 
2547
    Q_D(QWidget);
 
2548
    d->createExtra();
 
2549
    uint expl = d->extra->explicitMinSize | Qt::Horizontal;
 
2550
    setMinimumSize(w, minimumSize().height());
 
2551
    setMaximumSize(w, maximumSize().height());
 
2552
    d->extra->explicitMinSize = expl;
 
2553
}
 
2554
 
 
2555
 
 
2556
/*!
 
2557
    Sets both the minimum and maximum heights of the widget to \a h
 
2558
    without changing the widths. Provided for convenience.
 
2559
 
 
2560
    \sa sizeHint() minimumSize() maximumSize() setFixedSize()
 
2561
*/
 
2562
 
 
2563
void QWidget::setFixedHeight(int h)
 
2564
{
 
2565
    Q_D(QWidget);
 
2566
    d->createExtra();
 
2567
    uint expl = d->extra->explicitMinSize | Qt::Vertical;
 
2568
    setMinimumSize(minimumSize().width(), h);
 
2569
    setMaximumSize(maximumSize().width(), h);
 
2570
    d->extra->explicitMinSize = expl;
 
2571
}
 
2572
 
 
2573
 
 
2574
/*!
 
2575
    Translates the widget coordinate \a pos to the coordinate system
 
2576
    of \a parent. The \a parent must not be 0 and must be a parent
 
2577
    of the calling widget.
 
2578
 
 
2579
    \sa mapFrom() mapToParent() mapToGlobal() underMouse()
 
2580
*/
 
2581
 
 
2582
QPoint QWidget::mapTo(QWidget * parent, const QPoint & pos) const
 
2583
{
 
2584
    QPoint p = pos;
 
2585
    if (parent) {
 
2586
        const QWidget * w = this;
 
2587
        while (w != parent) {
 
2588
            p = w->mapToParent(p);
 
2589
            w = w->parentWidget();
 
2590
        }
 
2591
    }
 
2592
    return p;
 
2593
}
 
2594
 
 
2595
 
 
2596
/*!
 
2597
    Translates the widget coordinate \a pos from the coordinate system
 
2598
    of \a parent to this widget's coordinate system. The \a parent
 
2599
    must not be 0 and must be a parent of the calling widget.
 
2600
 
 
2601
    \sa mapTo() mapFromParent() mapFromGlobal() underMouse()
 
2602
*/
 
2603
 
 
2604
QPoint QWidget::mapFrom(QWidget * parent, const QPoint & pos) const
 
2605
{
 
2606
    QPoint p(pos);
 
2607
    if (parent) {
 
2608
        const QWidget * w = this;
 
2609
        while (w != parent) {
 
2610
            p = w->mapFromParent(p);
 
2611
            w = w->parentWidget();
 
2612
        }
 
2613
    }
 
2614
    return p;
 
2615
}
 
2616
 
 
2617
 
 
2618
/*!
 
2619
    Translates the widget coordinate \a pos to a coordinate in the
 
2620
    parent widget.
 
2621
 
 
2622
    Same as mapToGlobal() if the widget has no parent.
 
2623
 
 
2624
    \sa mapFromParent() mapTo() mapToGlobal() underMouse()
 
2625
*/
 
2626
 
 
2627
QPoint QWidget::mapToParent(const QPoint &pos) const
 
2628
{
 
2629
    return pos + data->crect.topLeft();
 
2630
}
 
2631
 
 
2632
/*!
 
2633
    Translates the parent widget coordinate \a pos to widget
 
2634
    coordinates.
 
2635
 
 
2636
    Same as mapFromGlobal() if the widget has no parent.
 
2637
 
 
2638
    \sa mapToParent() mapFrom() mapFromGlobal() underMouse()
 
2639
*/
 
2640
 
 
2641
QPoint QWidget::mapFromParent(const QPoint &pos) const
 
2642
{
 
2643
    return pos - data->crect.topLeft();
 
2644
}
 
2645
 
 
2646
 
 
2647
/*!
 
2648
    Returns the window for this widget, i.e. the next ancestor widget
 
2649
    that has (or could have) a window-system frame.
 
2650
 
 
2651
    If the widget is a window, the widget itself is returned.
 
2652
 
 
2653
    Typical usage is changing the window title:
 
2654
 
 
2655
    \code
 
2656
        aWidget->window()->setWindowTitle("New Window Title");
 
2657
    \endcode
 
2658
 
 
2659
    \sa isWindow()
 
2660
*/
 
2661
 
 
2662
QWidget *QWidget::window() const
 
2663
{
 
2664
    QWidget *w = (QWidget *)this;
 
2665
    QWidget *p = w->parentWidget();
 
2666
    while (!w->isWindow() && p) {
 
2667
        w = p;
 
2668
        p = p->parentWidget();
 
2669
    }
 
2670
    return w;
 
2671
}
 
2672
 
 
2673
/*! \fn QWidget *QWidget::topLevelWidget() const
 
2674
    \obsolete
 
2675
 
 
2676
    Use window() instead.
 
2677
*/
 
2678
 
 
2679
#ifdef QT3_SUPPORT
 
2680
/*!
 
2681
    Returns the color role used for painting the widget's background.
 
2682
 
 
2683
    Use QPalette(backgroundRole(()) instead.
 
2684
*/
 
2685
Qt::BackgroundMode QWidget::backgroundMode() const
 
2686
{
 
2687
    if (testAttribute(Qt::WA_NoSystemBackground))
 
2688
        return Qt::NoBackground;
 
2689
    switch(backgroundRole()) {
 
2690
    case QPalette::Foreground:
 
2691
        return Qt::PaletteForeground;
 
2692
    case QPalette::Button:
 
2693
        return Qt::PaletteButton;
 
2694
    case QPalette::Light:
 
2695
        return Qt::PaletteLight;
 
2696
    case QPalette::Midlight:
 
2697
        return Qt::PaletteMidlight;
 
2698
    case QPalette::Dark:
 
2699
        return Qt::PaletteDark;
 
2700
    case QPalette::Mid:
 
2701
        return Qt::PaletteMid;
 
2702
    case QPalette::Text:
 
2703
        return Qt::PaletteText;
 
2704
    case QPalette::BrightText:
 
2705
        return Qt::PaletteBrightText;
 
2706
    case QPalette::Base:
 
2707
        return Qt::PaletteBase;
 
2708
    case QPalette::Background:
 
2709
        return Qt::PaletteBackground;
 
2710
    case QPalette::Shadow:
 
2711
        return Qt::PaletteShadow;
 
2712
    case QPalette::Highlight:
 
2713
        return Qt::PaletteHighlight;
 
2714
    case QPalette::HighlightedText:
 
2715
        return Qt::PaletteHighlightedText;
 
2716
    case QPalette::ButtonText:
 
2717
        return Qt::PaletteButtonText;
 
2718
    case QPalette::Link:
 
2719
        return Qt::PaletteLink;
 
2720
    case QPalette::LinkVisited:
 
2721
        return Qt::PaletteLinkVisited;
 
2722
    default:
 
2723
        break;
 
2724
    }
 
2725
    return Qt::NoBackground;
 
2726
}
 
2727
 
 
2728
/*!
 
2729
    \fn void QWidget::setBackgroundMode(Qt::BackgroundMode
 
2730
    widgetBackground, Qt::BackgroundMode paletteBackground)
 
2731
 
 
2732
    Sets the color role used for painting the widget's background to
 
2733
    background mode \a widgetBackground. The \a paletteBackground mode
 
2734
    parameter is ignored.
 
2735
*/
 
2736
void QWidget::setBackgroundMode(Qt::BackgroundMode m, Qt::BackgroundMode)
 
2737
{
 
2738
    Q_D(QWidget);
 
2739
    if(m == Qt::NoBackground) {
 
2740
        setAttribute(Qt::WA_NoSystemBackground, true);
 
2741
        return;
 
2742
    }
 
2743
    setAttribute(Qt::WA_NoSystemBackground, false);
 
2744
    d->fg_role = QPalette::NoRole;
 
2745
    QPalette::ColorRole role = d->bg_role;
 
2746
    switch(m) {
 
2747
    case Qt::FixedColor:
 
2748
    case Qt::FixedPixmap:
 
2749
        break;
 
2750
    case Qt::PaletteForeground:
 
2751
        role = QPalette::Foreground;
 
2752
        break;
 
2753
    case Qt::PaletteButton:
 
2754
        role = QPalette::Button;
 
2755
        break;
 
2756
    case Qt::PaletteLight:
 
2757
        role = QPalette::Light;
 
2758
        break;
 
2759
    case Qt::PaletteMidlight:
 
2760
        role = QPalette::Midlight;
 
2761
        break;
 
2762
    case Qt::PaletteDark:
 
2763
        role = QPalette::Dark;
 
2764
        break;
 
2765
    case Qt::PaletteMid:
 
2766
        role = QPalette::Mid;
 
2767
        break;
 
2768
    case Qt::PaletteText:
 
2769
        role = QPalette::Text;
 
2770
        break;
 
2771
    case Qt::PaletteBrightText:
 
2772
        role = QPalette::BrightText;
 
2773
        break;
 
2774
    case Qt::PaletteBase:
 
2775
        role = QPalette::Base;
 
2776
        break;
 
2777
    case Qt::PaletteBackground:
 
2778
        role = QPalette::Background;
 
2779
        break;
 
2780
    case Qt::PaletteShadow:
 
2781
        role = QPalette::Shadow;
 
2782
        break;
 
2783
    case Qt::PaletteHighlight:
 
2784
        role = QPalette::Highlight;
 
2785
        break;
 
2786
    case Qt::PaletteHighlightedText:
 
2787
        role = QPalette::HighlightedText;
 
2788
        break;
 
2789
    case Qt::PaletteButtonText:
 
2790
        role = QPalette::ButtonText;
 
2791
        break;
 
2792
    case Qt::PaletteLink:
 
2793
        role = QPalette::Link;
 
2794
        break;
 
2795
    case Qt::PaletteLinkVisited:
 
2796
        role = QPalette::LinkVisited;
 
2797
        break;
 
2798
    case Qt::X11ParentRelative:
 
2799
        d->fg_role = role = QPalette::NoRole;
 
2800
    default:
 
2801
        break;
 
2802
    }
 
2803
    setBackgroundRole(role);
 
2804
}
 
2805
 
 
2806
/*!
 
2807
    The widget mapper is no longer part of the public API.
 
2808
*/
 
2809
QT3_SUPPORT QWidgetMapper *QWidget::wmapper() { return QWidgetPrivate::mapper; }
 
2810
 
 
2811
#endif
 
2812
 
 
2813
 
 
2814
/*!
 
2815
  Returns the background role of the widget.
 
2816
 
 
2817
  The background role defines the brush from the widget's \l palette that
 
2818
  is used to render the background.
 
2819
 
 
2820
  If no explicit background role is set, the widget inherts its parent
 
2821
  widget's background role.
 
2822
 
 
2823
  \sa setBackgroundRole(), foregroundRole()
 
2824
 */
 
2825
QPalette::ColorRole QWidget::backgroundRole() const
 
2826
{
 
2827
 
 
2828
    const QWidget *w = this;
 
2829
    do {
 
2830
        QPalette::ColorRole role = w->d_func()->bg_role;
 
2831
        if (role != QPalette::NoRole)
 
2832
            return role;
 
2833
        if (w->isWindow() || w->windowType() == Qt::SubWindow)
 
2834
            break;
 
2835
        w = w->parentWidget();
 
2836
    } while (w);
 
2837
    return QPalette::Background;
 
2838
}
 
2839
 
 
2840
/*!
 
2841
  Sets the background role of the widget to \a role.
 
2842
 
 
2843
  The background role defines the brush from the widget's \l palette that
 
2844
  is used to render the background.
 
2845
 
 
2846
  If \a role is \c QPalette::NoRole, then the widget inherits its
 
2847
  parent's background role.
 
2848
 
 
2849
  \sa backgroundRole(), foregroundRole()
 
2850
 */
 
2851
 
 
2852
void QWidget::setBackgroundRole(QPalette::ColorRole role)
 
2853
{
 
2854
    Q_D(QWidget);
 
2855
    d->bg_role = role;
 
2856
    d->updateSystemBackground();
 
2857
    d->propagatePaletteChange();
 
2858
}
 
2859
 
 
2860
/*!
 
2861
  Returns the foreground role.
 
2862
 
 
2863
  The foreground role defines the color from the widget's \l palette that
 
2864
  is used to draw the foreground.
 
2865
 
 
2866
  If no explicit foreground role is set, the function returns a role
 
2867
  that contrasts with the background role.
 
2868
 
 
2869
  \sa setForegroundRole(), backgroundRole()
 
2870
 */
 
2871
QPalette::ColorRole QWidget::foregroundRole() const
 
2872
{
 
2873
    Q_D(const QWidget);
 
2874
    QPalette::ColorRole rl = QPalette::ColorRole(d->fg_role);
 
2875
    if (rl != QPalette::NoRole)
 
2876
        return rl;
 
2877
    QPalette::ColorRole role = QPalette::Foreground;
 
2878
    switch (backgroundRole()) {
 
2879
    case QPalette::Button:
 
2880
        role = QPalette::ButtonText;
 
2881
        break;
 
2882
    case QPalette::Base:
 
2883
        role = QPalette::Text;
 
2884
        break;
 
2885
    case QPalette::Dark:
 
2886
    case QPalette::Shadow:
 
2887
        role = QPalette::Light;
 
2888
        break;
 
2889
    case QPalette::Highlight:
 
2890
        role = QPalette::HighlightedText;
 
2891
        break;
 
2892
    default:
 
2893
        ;
 
2894
    }
 
2895
    return role;
 
2896
}
 
2897
 
 
2898
/*!
 
2899
  Sets the foreground role of the widget to \a role.
 
2900
 
 
2901
  The foreground role defines the color from the widget's \l palette that
 
2902
  is used to draw the foreground.
 
2903
 
 
2904
  If \a role is \c QPalette::NoRole, the widget uses a foreground role
 
2905
  that contrasts with the background role.
 
2906
 
 
2907
  \sa foregroundRole(), backgroundRole()
 
2908
 */
 
2909
void QWidget::setForegroundRole(QPalette::ColorRole role)
 
2910
{
 
2911
    Q_D(QWidget);
 
2912
    d->fg_role = role;
 
2913
    d->updateSystemBackground();
 
2914
    d->propagatePaletteChange();
 
2915
}
 
2916
 
 
2917
/*!
 
2918
    \property QWidget::palette
 
2919
    \brief the widget's palette
 
2920
 
 
2921
    As long as no special palette has been set, this is either a
 
2922
    special palette for the widget class, the parent's palette or (if
 
2923
    this widget is a top level widget), the default application
 
2924
    palette.
 
2925
 
 
2926
    \sa QApplication::palette()
 
2927
*/
 
2928
const QPalette &QWidget::palette() const
 
2929
{
 
2930
    if (!isEnabled()) {
 
2931
        data->pal.setCurrentColorGroup(QPalette::Disabled);
 
2932
    } else if (!isVisible() || isActiveWindow()) {
 
2933
        data->pal.setCurrentColorGroup(QPalette::Active);
 
2934
    } else {
 
2935
#ifdef Q_WS_MAC
 
2936
        extern bool qt_mac_can_clickThrough(const QWidget *); //qwidget_mac.cpp
 
2937
        if (qt_mac_can_clickThrough(this))
 
2938
            data->pal.setCurrentColorGroup(QPalette::Active);
 
2939
        else
 
2940
#endif
 
2941
            data->pal.setCurrentColorGroup(QPalette::Inactive);
 
2942
    }
 
2943
    return data->pal;
 
2944
}
 
2945
 
 
2946
void QWidget::setPalette(const QPalette &palette)
 
2947
{
 
2948
    Q_D(QWidget);
 
2949
    setAttribute(Qt::WA_SetPalette, palette.resolve() != 0);
 
2950
    d->setPalette_helper(palette.resolve(qt_naturalWidgetPalette(this)));
 
2951
}
 
2952
 
 
2953
void QWidgetPrivate::resolvePalette()
 
2954
{
 
2955
    Q_Q(QWidget);
 
2956
    setPalette_helper(data.pal.resolve(qt_naturalWidgetPalette(q)));
 
2957
}
 
2958
 
 
2959
void QWidgetPrivate::setPalette_helper(const QPalette &palette)
 
2960
{
 
2961
    if (data.pal == palette && data.pal.resolve() == palette.resolve())
 
2962
        return;
 
2963
    data.pal = palette;
 
2964
    updateSystemBackground();
 
2965
    propagatePaletteChange();
 
2966
}
 
2967
 
 
2968
 
 
2969
/*!
 
2970
    \property QWidget::font
 
2971
    \brief the font currently set for the widget
 
2972
 
 
2973
    The fontInfo() function reports the actual font that is being used
 
2974
    by the widget.
 
2975
 
 
2976
    As long as no special font has been set, or after setFont(QFont())
 
2977
    is called, this is either a special font for the widget class, the
 
2978
    parent's font or (if this widget is a top level widget), the
 
2979
    default application font.
 
2980
 
 
2981
    This code fragment sets a 12 point helvetica bold font:
 
2982
    \code
 
2983
    QFont f("Helvetica", 12, QFont::Bold);
 
2984
    setFont(f);
 
2985
    \endcode
 
2986
 
 
2987
    In addition to setting the font, setFont() informs all children
 
2988
    about the change.
 
2989
 
 
2990
    \sa fontInfo() fontMetrics()
 
2991
*/
 
2992
 
 
2993
void QWidget::setFont(const QFont &font)
 
2994
{
 
2995
    Q_D(QWidget);
 
2996
    setAttribute(Qt::WA_SetFont, font.resolve() != 0);
 
2997
    d->setFont_helper(font);
 
2998
}
 
2999
 
 
3000
void QWidgetPrivate::resolveFont()
 
3001
{
 
3002
    Q_Q(QWidget);
 
3003
    setFont_helper(data.fnt.resolve(qt_naturalWidgetFont(q)));
 
3004
}
 
3005
 
 
3006
void QWidgetPrivate::setFont_helper(const QFont &font)
 
3007
{
 
3008
    if (data.fnt == font && data.fnt.resolve() == font.resolve())
 
3009
        return;
 
3010
 
 
3011
    Q_Q(QWidget);
 
3012
#ifdef QT3_SUPPORT
 
3013
    QFont old = data.fnt;
 
3014
#endif
 
3015
    data.fnt = font;
 
3016
#if defined(Q_WS_X11)
 
3017
    // make sure the font set on this widget is associated with the correct screen
 
3018
    data.fnt.x11SetScreen(xinfo.screen());
 
3019
#endif
 
3020
    for (int i = 0; i < children.size(); ++i) {
 
3021
        QWidget *w = qobject_cast<QWidget*>(children.at(i));
 
3022
        if (w && !w->isWindow())
 
3023
            w->d_func()->resolveFont();
 
3024
    }
 
3025
    QEvent e(QEvent::FontChange);
 
3026
    QApplication::sendEvent(q, &e);
 
3027
#ifdef QT3_SUPPORT
 
3028
    q->fontChange(old);
 
3029
#endif
 
3030
}
 
3031
 
 
3032
void QWidgetPrivate::setLayoutDirection_helper(Qt::LayoutDirection direction)
 
3033
{
 
3034
    Q_Q(QWidget);
 
3035
 
 
3036
    if ( (direction == Qt::RightToLeft) == q->testAttribute(Qt::WA_RightToLeft))
 
3037
        return;
 
3038
    q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft));
 
3039
    if (!children.isEmpty()) {
 
3040
        for (int i = 0; i < children.size(); ++i) {
 
3041
            QWidget *w = qobject_cast<QWidget*>(children.at(i));
 
3042
            if (w && !w->isWindow() && !w->testAttribute(Qt::WA_SetLayoutDirection))
 
3043
                w->d_func()->setLayoutDirection_helper(direction);
 
3044
        }
 
3045
    }
 
3046
    QEvent e(QEvent::LayoutDirectionChange);
 
3047
    QApplication::sendEvent(q, &e);
 
3048
}
 
3049
 
 
3050
void QWidgetPrivate::resolveLayoutDirection()
 
3051
{
 
3052
    Q_Q(const QWidget);
 
3053
    if (!q->testAttribute(Qt::WA_SetLayoutDirection))
 
3054
        setLayoutDirection_helper(q->isWindow() ? QApplication::layoutDirection() : q->parentWidget()->layoutDirection());
 
3055
}
 
3056
 
 
3057
/*!\property QWidget::layoutDirection
 
3058
 
 
3059
   \brief the layout direction for this widget
 
3060
 
 
3061
   \sa QApplication::layoutDirection
 
3062
 */
 
3063
void QWidget::setLayoutDirection(Qt::LayoutDirection direction)
 
3064
{
 
3065
    Q_D(QWidget);
 
3066
 
 
3067
    setAttribute(Qt::WA_SetLayoutDirection);
 
3068
    d->setLayoutDirection_helper(direction);
 
3069
}
 
3070
 
 
3071
Qt::LayoutDirection QWidget::layoutDirection() const
 
3072
{
 
3073
    return testAttribute(Qt::WA_RightToLeft) ? Qt::RightToLeft : Qt::LeftToRight;
 
3074
}
 
3075
 
 
3076
void QWidget::unsetLayoutDirection()
 
3077
{
 
3078
    Q_D(QWidget);
 
3079
    setAttribute(Qt::WA_SetLayoutDirection, false);
 
3080
    d->resolveLayoutDirection();
 
3081
}
 
3082
 
 
3083
/*!
 
3084
    \fn QFontMetrics QWidget::fontMetrics() const
 
3085
 
 
3086
    Returns the font metrics for the widget's current font.
 
3087
    Equivalent to QFontMetrics(widget->font()).
 
3088
 
 
3089
    \sa font(), fontInfo(), setFont()
 
3090
*/
 
3091
 
 
3092
/*!
 
3093
    \fn QFontInfo QWidget::fontInfo() const
 
3094
 
 
3095
    Returns the font info for the widget's current font.
 
3096
    Equivalent to QFontInto(widget->font()).
 
3097
 
 
3098
    \sa font(), fontMetrics(), setFont()
 
3099
*/
 
3100
 
 
3101
 
 
3102
/*!
 
3103
    \property QWidget::cursor
 
3104
    \brief the cursor shape for this widget
 
3105
 
 
3106
    The mouse cursor will assume this shape when it's over this
 
3107
    widget. See the \link Qt::CursorShape list of predefined cursor
 
3108
    objects\endlink for a range of useful shapes.
 
3109
 
 
3110
    An editor widget might use an I-beam cursor:
 
3111
    \code
 
3112
        setCursor(Qt::IBeamCursor);
 
3113
    \endcode
 
3114
 
 
3115
    If no cursor has been set, or after a call to unsetCursor(), the
 
3116
    parent's cursor is used. The function unsetCursor() has no effect
 
3117
    on windows.
 
3118
 
 
3119
    \sa QApplication::setOverrideCursor()
 
3120
*/
 
3121
 
 
3122
#ifndef QT_NO_CURSOR
 
3123
QCursor QWidget::cursor() const
 
3124
{
 
3125
    Q_D(const QWidget);
 
3126
    if (testAttribute(Qt::WA_SetCursor))
 
3127
        return (d->extra && d->extra->curs)
 
3128
            ? *d->extra->curs
 
3129
            : QCursor(Qt::ArrowCursor);
 
3130
    if (isWindow() || !parentWidget())
 
3131
        return QCursor(Qt::ArrowCursor);
 
3132
    return parentWidget()->cursor();
 
3133
}
 
3134
#endif
 
3135
/*!
 
3136
    \property QWidget::windowTitle
 
3137
    \brief the window title (caption)
 
3138
 
 
3139
    This property only makes sense for windows. If no
 
3140
    caption has been set, the title is an empty string.
 
3141
 
 
3142
    If you use the \l windowModified mechanism, the window title must
 
3143
    contain a "[*]" placeholder, which indicates where the '*' should
 
3144
    appear. Normally, it should appear right after the file name
 
3145
    (e.g., "document1.txt[*] - Text Editor"). If the \l
 
3146
    windowModified property is false (the default), the placeholder
 
3147
    is simply removed.
 
3148
 
 
3149
    \sa windowIcon, windowIconText, windowModified
 
3150
*/
 
3151
QString QWidget::windowTitle() const
 
3152
{
 
3153
    Q_D(const QWidget);
 
3154
    return d->extra && d->extra->topextra
 
3155
        ? d->extra->topextra->caption
 
3156
        : QString();
 
3157
}
 
3158
 
 
3159
QString qt_setWindowTitle_helperHelper(const QString &title, QWidget *widget)
 
3160
{
 
3161
    Q_ASSERT(widget);
 
3162
 
 
3163
#ifdef QT_EVAL
 
3164
    extern QString qt_eval_adapt_window_title(const QString &title);
 
3165
    QString cap = qt_eval_adapt_window_title(title);
 
3166
#else
 
3167
    QString cap = title;
 
3168
#endif
 
3169
 
 
3170
    QString placeHolder(QLatin1String("[*]"));
 
3171
 
 
3172
    int index = cap.indexOf(placeHolder);
 
3173
 
 
3174
    while (index != -1) {
 
3175
        index += placeHolder.length();
 
3176
        int count = 1;
 
3177
        while (cap.indexOf(placeHolder, index) == index) {
 
3178
            ++count;
 
3179
            index += placeHolder.length();
 
3180
        }
 
3181
 
 
3182
        if (count%2) { // odd number of [*] -> replace last one
 
3183
            int lastIndex = cap.lastIndexOf(placeHolder, index - 1);
 
3184
            if (widget->isWindowModified()
 
3185
             && widget->style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, widget))
 
3186
                cap.replace(lastIndex, 3, QWidget::tr("*"));
 
3187
            else
 
3188
                cap.replace(lastIndex, 3, QLatin1String(""));
 
3189
        }
 
3190
 
 
3191
        index = cap.indexOf(placeHolder, index);
 
3192
    }
 
3193
 
 
3194
    cap.replace(QLatin1String("[*][*]"), QLatin1String("[*]"));
 
3195
 
 
3196
    return cap;
 
3197
}
 
3198
 
 
3199
#ifndef QT_NO_WIDGET_TOPEXTRA
 
3200
void QWidgetPrivate::setWindowTitle_helper(const QString &title)
 
3201
{
 
3202
    Q_Q(QWidget);
 
3203
    setWindowTitle_sys(qt_setWindowTitle_helperHelper(title, q));
 
3204
}
 
3205
#endif
 
3206
 
 
3207
void QWidgetPrivate::setWindowIconText_helper(const QString &title)
 
3208
{
 
3209
    Q_Q(QWidget);
 
3210
    setWindowIconText_sys(qt_setWindowTitle_helperHelper(title, q));
 
3211
}
 
3212
 
 
3213
void QWidget::setWindowIconText(const QString &iconText)
 
3214
{
 
3215
    if (QWidget::windowIconText() == iconText)
 
3216
        return;
 
3217
 
 
3218
    Q_D(QWidget);
 
3219
    d->topData()->iconText = iconText;
 
3220
    d->setWindowIconText_helper(iconText);
 
3221
 
 
3222
    QEvent e(QEvent::IconTextChange);
 
3223
    QApplication::sendEvent(this, &e);
 
3224
}
 
3225
 
 
3226
void QWidget::setWindowTitle(const QString &title)
 
3227
{
 
3228
    if (QWidget::windowTitle() == title)
 
3229
        return;
 
3230
 
 
3231
    Q_D(QWidget);
 
3232
#ifndef QT_NO_WIDGET_TOPEXTRA
 
3233
    d->topData()->caption = title;
 
3234
    d->setWindowTitle_helper(title);
 
3235
#endif
 
3236
 
 
3237
    QEvent e(QEvent::WindowTitleChange);
 
3238
    QApplication::sendEvent(this, &e);
 
3239
}
 
3240
 
 
3241
/*!
 
3242
    \property QWidget::windowIcon
 
3243
    \brief the widget's icon
 
3244
 
 
3245
    This property only makes sense for windows. If no icon
 
3246
    has been set, windowIcon() returns the application icon
 
3247
    (QApplication::windowIcon()).
 
3248
 
 
3249
    \sa windowIconText, windowTitle
 
3250
*/
 
3251
QIcon QWidget::windowIcon() const
 
3252
{
 
3253
    const QWidget *w = this;
 
3254
    while (w) {
 
3255
        const QWidgetPrivate *d = w->d_func();
 
3256
        if (d->extra && d->extra->topextra && d->extra->topextra->icon)
 
3257
            return *d->extra->topextra->icon;
 
3258
        w = w->parentWidget();
 
3259
    }
 
3260
    return qApp->windowIcon();
 
3261
}
 
3262
 
 
3263
void QWidget::setWindowIcon(const QIcon &icon)
 
3264
{
 
3265
    Q_D(QWidget);
 
3266
 
 
3267
    setAttribute(Qt::WA_SetWindowIcon, !icon.isNull());
 
3268
    d->createTLExtra();
 
3269
 
 
3270
    if (!d->extra->topextra->icon)
 
3271
        d->extra->topextra->icon = new QIcon();
 
3272
    *d->extra->topextra->icon = icon;
 
3273
 
 
3274
    delete d->extra->topextra->iconPixmap;
 
3275
    d->extra->topextra->iconPixmap = 0;
 
3276
 
 
3277
    d->setWindowIcon_sys();
 
3278
    QEvent e(QEvent::WindowIconChange);
 
3279
    QApplication::sendEvent(this, &e);
 
3280
}
 
3281
 
 
3282
 
 
3283
/*!
 
3284
    \property QWidget::windowIconText
 
3285
    \brief the widget's icon text
 
3286
 
 
3287
    This property only makes sense for windows. If no icon
 
3288
    text has been set, this functions returns an empty string.
 
3289
 
 
3290
    \sa windowIcon, windowTitle
 
3291
*/
 
3292
 
 
3293
QString QWidget::windowIconText() const
 
3294
{
 
3295
    Q_D(const QWidget);
 
3296
    return (d->extra && d->extra->topextra) ? d->extra->topextra->iconText : QString();
 
3297
}
 
3298
 
 
3299
/*!
 
3300
    Returns the window's role, or an empty string.
 
3301
 
 
3302
    \sa windowIcon, windowTitle
 
3303
*/
 
3304
 
 
3305
QString QWidget::windowRole() const
 
3306
{
 
3307
    Q_D(const QWidget);
 
3308
    return (d->extra && d->extra->topextra) ? d->extra->topextra->role : QString();
 
3309
}
 
3310
 
 
3311
/*!
 
3312
    Sets the window's role to \a role. This only makes sense for
 
3313
    windows on X11.
 
3314
*/
 
3315
void QWidget::setWindowRole(const QString &role)
 
3316
{
 
3317
#if defined(Q_WS_X11)
 
3318
    Q_D(QWidget);
 
3319
    d->topData()->role = role;
 
3320
    d->setWindowRole(role.toUtf8().constData());
 
3321
#else
 
3322
    Q_UNUSED(role)
 
3323
#endif
 
3324
}
 
3325
 
 
3326
/*!
 
3327
    \property QWidget::mouseTracking
 
3328
    \brief whether mouse tracking is enabled for the widget
 
3329
 
 
3330
    If mouse tracking is disabled (the default), the widget only
 
3331
    receives mouse move events when at least one mouse button is
 
3332
    pressed while the mouse is being moved.
 
3333
 
 
3334
    If mouse tracking is enabled, the widget receives mouse move
 
3335
    events even if no buttons are pressed.
 
3336
 
 
3337
    \sa mouseMoveEvent()
 
3338
*/
 
3339
 
 
3340
 
 
3341
/*!
 
3342
    Sets the widget's focus proxy to widget \a w. If \a w is 0, the
 
3343
    function resets this widget to have no focus proxy.
 
3344
 
 
3345
    Some widgets can "have focus", but create a child widget, such as
 
3346
    QLineEdit, to actually handle the focus. In this case, the widget
 
3347
    can set the line edit to be its focus proxy.
 
3348
 
 
3349
    setFocusProxy() sets the widget which will actually get focus when
 
3350
    "this widget" gets it. If there is a focus proxy, setFocus() and
 
3351
    hasFocus() operate on the focus proxy.
 
3352
 
 
3353
    \sa focusProxy()
 
3354
*/
 
3355
 
 
3356
void QWidget::setFocusProxy(QWidget * w)
 
3357
{
 
3358
    Q_D(QWidget);
 
3359
    if (!w && !d->extra)
 
3360
        return;
 
3361
 
 
3362
    for (QWidget* fp  = w; fp; fp = fp->focusProxy()) {
 
3363
        if (fp == this) {
 
3364
            qWarning("%s (%s): already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData());
 
3365
            return;
 
3366
        }
 
3367
    }
 
3368
 
 
3369
    d->createExtra();
 
3370
    d->extra->focus_proxy = w;
 
3371
}
 
3372
 
 
3373
 
 
3374
/*!
 
3375
    Returns the focus proxy, or 0 if there is no focus proxy.
 
3376
 
 
3377
    \sa setFocusProxy()
 
3378
*/
 
3379
 
 
3380
QWidget * QWidget::focusProxy() const
 
3381
{
 
3382
    Q_D(const QWidget);
 
3383
    return d->extra ? (QWidget *)d->extra->focus_proxy : 0;
 
3384
}
 
3385
 
 
3386
 
 
3387
/*!
 
3388
    \property QWidget::focus
 
3389
    \brief whether this widget (or its focus proxy) has the keyboard
 
3390
    input focus
 
3391
 
 
3392
    Effectively equivalent to \c {QApplication::focusWidget() == this}.
 
3393
 
 
3394
    \sa setFocus(), clearFocus(), setFocusPolicy(), QApplication::focusWidget()
 
3395
*/
 
3396
bool QWidget::hasFocus() const
 
3397
{
 
3398
    const QWidget* w = this;
 
3399
    while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
 
3400
        w = w->d_func()->extra->focus_proxy;
 
3401
    return (QApplication::focusWidget() == w);
 
3402
}
 
3403
 
 
3404
/*!
 
3405
    Gives the keyboard input focus to this widget (or its focus
 
3406
    proxy) if this widget or one of its parents is the \link
 
3407
    isActiveWindow() active window\endlink. The \a reason argument will
 
3408
    be passed into any focus event sent from this function, it is used
 
3409
    to give an explanation of what caused the widget to get focus.
 
3410
 
 
3411
    First, a focus out event is sent to the focus widget (if any) to
 
3412
    tell it that it is about to lose the focus. Then a focus in event
 
3413
    is sent to this widget to tell it that it just received the focus.
 
3414
    (Nothing happens if the focus in and focus out widgets are the
 
3415
    same.)
 
3416
 
 
3417
    setFocus() gives focus to a widget regardless of its focus policy,
 
3418
    but does not clear any keyboard grab (see grabKeyboard()).
 
3419
 
 
3420
    Be aware that if the widget is hidden, it will not accept focus.
 
3421
 
 
3422
    \warning If you call setFocus() in a function which may itself be
 
3423
    called from focusOutEvent() or focusInEvent(), you may get an
 
3424
    infinite recursion.
 
3425
 
 
3426
    \sa hasFocus() clearFocus() focusInEvent() focusOutEvent()
 
3427
    setFocusPolicy() QApplication::focusWidget() grabKeyboard()
 
3428
    grabMouse(), {Keyboard Focus}
 
3429
*/
 
3430
 
 
3431
void QWidget::setFocus(Qt::FocusReason reason)
 
3432
{
 
3433
    if (!isEnabled())
 
3434
        return;
 
3435
 
 
3436
    QWidget *f = this;
 
3437
    while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
 
3438
        f = f->d_func()->extra->focus_proxy;
 
3439
 
 
3440
    if (QApplication::focusWidget() == f
 
3441
#if defined(Q_WS_WIN)
 
3442
        && GetFocus() == f->winId()
 
3443
#endif
 
3444
       )
 
3445
        return;
 
3446
 
 
3447
 
 
3448
    QWidget *w = f;
 
3449
    if (isHidden()) {
 
3450
        while (w && w->isHidden()) {
 
3451
            w->d_func()->focus_child = f;
 
3452
            w = w->isWindow() ? 0 : w->parentWidget();
 
3453
        }
 
3454
    } else {
 
3455
        while (w) {
 
3456
            w->d_func()->focus_child = f;
 
3457
            w = w->isWindow() ? 0 : w->parentWidget();
 
3458
        }
 
3459
    }
 
3460
 
 
3461
    if (f->isActiveWindow()) {
 
3462
        QWidget *prev = QApplication::focusWidget();
 
3463
        if (prev) {
 
3464
            // This part is never executed when Q_WS_X11? Preceding XFocusOut
 
3465
            // had already reset focus_widget when received XFocusIn
 
3466
 
 
3467
            // Don't reset input context explicitly here. Whether reset or not
 
3468
            // when focusing out is a responsibility of input methods. So we
 
3469
            // delegate the responsibility to input context via
 
3470
            // unfocusInputContext(). See 'Preedit preservation' section of
 
3471
            // QInputContext.
 
3472
            if (prev != f) {
 
3473
#if !defined(Q_WS_MAC)
 
3474
                prev->d_func()->unfocusInputContext();
 
3475
#else
 
3476
                prev->resetInputContext();
 
3477
#endif
 
3478
            }
 
3479
        }
 
3480
 
 
3481
        QApplicationPrivate::setFocusWidget(f, reason);
 
3482
        f->d_func()->focusInputContext();
 
3483
 
 
3484
#if defined(Q_WS_WIN)
 
3485
        if (!(f->window()->windowType() == Qt::Popup))
 
3486
            SetFocus(f->winId());
 
3487
        else {
 
3488
#endif
 
3489
#ifndef QT_NO_ACCESSIBILITY
 
3490
            QAccessible::updateAccessibility(f, 0, QAccessible::Focus);
 
3491
#endif
 
3492
#if defined(Q_WS_WIN)
 
3493
        }
 
3494
#endif
 
3495
    }
 
3496
}
 
3497
 
 
3498
/*!
 
3499
    \fn void QWidget::setFocus()
 
3500
    \overload
 
3501
 
 
3502
    Gives the keyboard input focus to this widget (or its focus
 
3503
    proxy) if this widget or one of its parents is the
 
3504
    \l{isActiveWindow()}{active window}.
 
3505
*/
 
3506
 
 
3507
/*!
 
3508
    Takes keyboard input focus from the widget.
 
3509
 
 
3510
    If the widget has active focus, a \link focusOutEvent() focus out
 
3511
    event\endlink is sent to this widget to tell it that it is about
 
3512
    to lose the focus.
 
3513
 
 
3514
    This widget must enable focus setting in order to get the keyboard
 
3515
    input focus, i.e. it must call setFocusPolicy().
 
3516
 
 
3517
    \sa hasFocus(), setFocus(), focusInEvent(), focusOutEvent(),
 
3518
    setFocusPolicy(), QApplication::focusWidget()
 
3519
*/
 
3520
 
 
3521
void QWidget::clearFocus()
 
3522
{
 
3523
    QWidget *w = this;
 
3524
    while (w && w->d_func()->focus_child == this) {
 
3525
        w->d_func()->focus_child = 0;
 
3526
        w = w->isWindow() ? 0 : w->parentWidget();
 
3527
    }
 
3528
    if (hasFocus()) {
 
3529
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
 
3530
        Q_D(QWidget);
 
3531
        d->unfocusInputContext();
 
3532
#endif
 
3533
        QApplicationPrivate::setFocusWidget(0, Qt::OtherFocusReason);
 
3534
#if defined(Q_WS_WIN)
 
3535
        if (!(windowType() == Qt::Popup) && GetFocus() == winId())
 
3536
            SetFocus(0);
 
3537
        else {
 
3538
#endif
 
3539
#ifndef QT_NO_ACCESSIBILITY
 
3540
            QAccessible::updateAccessibility(this, 0, QAccessible::Focus);
 
3541
#endif
 
3542
#if defined(Q_WS_WIN)
 
3543
        }
 
3544
#endif
 
3545
    }
 
3546
}
 
3547
 
 
3548
 
 
3549
/*!
 
3550
    \fn bool QWidget::focusNextChild()
 
3551
 
 
3552
    Finds a new widget to give the keyboard focus to, as appropriate
 
3553
    for \key Tab, and returns true if it can find a new widget, or
 
3554
    false if it can't.
 
3555
 
 
3556
    This is the same as focusNextPrevChild(true).
 
3557
 
 
3558
    \sa focusPreviousChild()
 
3559
*/
 
3560
 
 
3561
/*!
 
3562
    \fn bool QWidget::focusPreviousChild()
 
3563
 
 
3564
    Finds a new widget to give the keyboard focus to, as appropriate
 
3565
    for \key Shift+Tab, and returns true if it can find a new widget,
 
3566
    or false if it can't.
 
3567
 
 
3568
    This is the same as focusNextPrevChild(false).
 
3569
 
 
3570
    \sa focusNextChild()
 
3571
*/
 
3572
 
 
3573
/*!
 
3574
    Finds a new widget to give the keyboard focus to, as appropriate
 
3575
    for Tab and Shift+Tab, and returns true if it can find a new
 
3576
    widget, or false if it can't.
 
3577
 
 
3578
    If \a next is true, this function searches "forwards", if \a next
 
3579
    is false, it searches "backwards".
 
3580
 
 
3581
    Sometimes, you will want to reimplement this function. For
 
3582
    example, a web browser might reimplement it to move its "current
 
3583
    active link" forward or backward, and call
 
3584
    focusNextPrevChild() only when it reaches the last or
 
3585
    first link on the "page".
 
3586
 
 
3587
    Child widgets call focusNextPrevChild() on their parent widgets,
 
3588
    but only the window that contains the child widgets decides where
 
3589
    to redirect focus. By reimplementing this function for an object,
 
3590
    you thus gain control of focus traversal for all child widgets.
 
3591
 
 
3592
    \sa focusNextChild(), focusPreviousChild()
 
3593
*/
 
3594
 
 
3595
bool QWidget::focusNextPrevChild(bool next)
 
3596
{
 
3597
    QWidget* p = parentWidget();
 
3598
    if (!isWindow() && p)
 
3599
        return p->focusNextPrevChild(next);
 
3600
 
 
3601
    extern bool qt_tab_all_widgets;
 
3602
    uint focus_flag = qt_tab_all_widgets ? Qt::TabFocus : Qt::StrongFocus;
 
3603
 
 
3604
    QWidget *f = focusWidget();
 
3605
    if (!f)
 
3606
        f = this;
 
3607
 
 
3608
    QWidget *w = f;
 
3609
    QWidget *test = f->d_func()->focus_next;
 
3610
    while (test && test != f) {
 
3611
        if ((test->focusPolicy() & focus_flag) == focus_flag
 
3612
            && !(test->d_func()->extra && test->d_func()->extra->focus_proxy)
 
3613
            && test->isVisibleTo(this) && test->isEnabled()) {
 
3614
            w = test;
 
3615
            if (next)
 
3616
                break;
 
3617
        }
 
3618
        test = test->d_func()->focus_next;
 
3619
    }
 
3620
    if (w == f) {
 
3621
        extern bool qt_in_tab_key_event; // defined in qapplication.cpp
 
3622
        if (qt_in_tab_key_event) {
 
3623
            w->window()->setAttribute(Qt::WA_KeyboardFocusChange);
 
3624
            w->update();
 
3625
        }
 
3626
        return false;
 
3627
    }
 
3628
    w->setFocus(next ? Qt::TabFocusReason : Qt::BacktabFocusReason);
 
3629
    return true;
 
3630
}
 
3631
 
 
3632
/*!
 
3633
    Returns the last child of this widget that setFocus had been
 
3634
    called on.  For top level widgets this is the widget that will get
 
3635
    focus in case this window gets activated
 
3636
 
 
3637
    This is not the same as QApplication::focusWidget(), which returns
 
3638
    the focus widget in the currently active window.
 
3639
*/
 
3640
 
 
3641
QWidget *QWidget::focusWidget() const
 
3642
{
 
3643
    return const_cast<QWidget *>(d_func()->focus_child);
 
3644
}
 
3645
 
 
3646
/*!
 
3647
    Returns the next widget in this widget's focus chain.
 
3648
*/
 
3649
QWidget *QWidget::nextInFocusChain() const
 
3650
{
 
3651
    return const_cast<QWidget *>(d_func()->focus_next);
 
3652
}
 
3653
 
 
3654
/*!
 
3655
    \property QWidget::isActiveWindow
 
3656
    \brief whether this widget's window is the active window
 
3657
 
 
3658
    The active window is the window that contains the widget that
 
3659
    has keyboard focus.
 
3660
 
 
3661
    When popup windows are visible, this property is true for both the
 
3662
    active window \e and for the popup.
 
3663
 
 
3664
    \sa activateWindow(), QApplication::activeWindow()
 
3665
*/
 
3666
bool QWidget::isActiveWindow() const
 
3667
{
 
3668
    QWidget *tlw = window();
 
3669
    if((windowType() == Qt::SubWindow) && parentWidget())
 
3670
        tlw = parentWidget()->window();
 
3671
    if(tlw == qApp->activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup)))
 
3672
        return true;
 
3673
#ifdef Q_WS_MAC
 
3674
    { //check process
 
3675
        Boolean compare;
 
3676
        ProcessSerialNumber current, front;
 
3677
        GetCurrentProcess(&current);
 
3678
        GetFrontProcess(&front);
 
3679
        if(SameProcess(&current, &front, &compare) == noErr && !compare)
 
3680
            return false;
 
3681
    }
 
3682
    extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp
 
3683
    if(qt_mac_is_macdrawer(tlw) &&
 
3684
       tlw->parentWidget() && tlw->parentWidget()->isActiveWindow())
 
3685
        return true;
 
3686
#endif
 
3687
    if(style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, this)) {
 
3688
        if(((tlw->windowType() == Qt::Dialog) || (tlw->windowType() == Qt::Tool)) &&
 
3689
           !tlw->testAttribute(Qt::WA_ShowModal) &&
 
3690
           (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow()))
 
3691
           return true;
 
3692
        QWidget *w = qApp->activeWindow();
 
3693
        if(!(windowType() == Qt::SubWindow) && w && (w->windowType() == Qt::SubWindow) &&
 
3694
            w->parentWidget()->window() == tlw)
 
3695
            return true;
 
3696
        while(w && ((tlw->windowType() == Qt::Dialog) || (tlw->windowType() == Qt::Tool)) &&
 
3697
              !w->testAttribute(Qt::WA_ShowModal) && w->parentWidget()) {
 
3698
            w = w->parentWidget()->window();
 
3699
            if(w == tlw)
 
3700
                return true;
 
3701
        }
 
3702
    }
 
3703
#if defined(Q_WS_WIN32)
 
3704
    HWND parent = tlw->winId();
 
3705
    HWND topparent = GetActiveWindow();
 
3706
    while (parent) {
 
3707
        parent = ::GetParent(parent);
 
3708
        if (parent && parent == topparent)
 
3709
            return true;
 
3710
    }
 
3711
#endif
 
3712
 
 
3713
    return false;
 
3714
}
 
3715
 
 
3716
/*!
 
3717
    Moves the \a second widget around the ring of focus widgets so
 
3718
    that keyboard focus moves from the \a first widget to the \a
 
3719
    second widget when the Tab key is pressed.
 
3720
 
 
3721
    Note that since the tab order of the \a second widget is changed,
 
3722
    you should order a chain like this:
 
3723
 
 
3724
    \code
 
3725
        setTabOrder(a, b); // a to b
 
3726
        setTabOrder(b, c); // a to b to c
 
3727
        setTabOrder(c, d); // a to b to c to d
 
3728
    \endcode
 
3729
 
 
3730
    \e not like this:
 
3731
 
 
3732
    \code
 
3733
        setTabOrder(c, d); // c to d   WRONG
 
3734
        setTabOrder(a, b); // a to b AND c to d
 
3735
        setTabOrder(b, c); // a to b to c, but not c to d
 
3736
    \endcode
 
3737
 
 
3738
    If \a first or \a second has a focus proxy, setTabOrder()
 
3739
    correctly substitutes the proxy.
 
3740
 
 
3741
    \sa setFocusPolicy(), setFocusProxy(), {Keyboard Focus}
 
3742
*/
 
3743
void QWidget::setTabOrder(QWidget* first, QWidget *second)
 
3744
{
 
3745
    if (!first || !second || first->focusPolicy() == Qt::NoFocus || second->focusPolicy() == Qt::NoFocus)
 
3746
        return;
 
3747
 
 
3748
    QWidget *fp = first->focusProxy();
 
3749
    if (fp) {
 
3750
        // If first is redirected, set first to the last child of first
 
3751
        // that can take keyboard focus so that second is inserted after
 
3752
        // that last child, and the focus order within first is (more
 
3753
        // likely to be) preserved.
 
3754
        QList<QWidget *> l = qFindChildren<QWidget *>(first);
 
3755
        for (int i = l.size()-1; i >= 0; --i) {
 
3756
            QWidget * next = l.at(i);
 
3757
            if (next->window() == fp->window()) {
 
3758
                fp = next;
 
3759
                if (fp->focusPolicy() != Qt::NoFocus)
 
3760
                    break;
 
3761
            }
 
3762
        }
 
3763
        first = fp;
 
3764
    }
 
3765
 
 
3766
    if (QWidget *sp = second->focusProxy())
 
3767
        second = sp;
 
3768
 
 
3769
    QWidget *p = second;
 
3770
    while (p->d_func()->focus_next != second)
 
3771
        p = p->d_func()->focus_next;
 
3772
    p->d_func()->focus_next = second->d_func()->focus_next;
 
3773
 
 
3774
    second->d_func()->focus_next = first->d_func()->focus_next;
 
3775
    first->d_func()->focus_next = second;
 
3776
}
 
3777
 
 
3778
/*!\internal
 
3779
 
 
3780
  Moves the relevant subwidgets of this widget from the \a oldtlw's
 
3781
  tab chain to that of the new parent, if there's anything to move and
 
3782
  we're really moving
 
3783
 
 
3784
  This function is called from QWidget::reparent() *after* the widget
 
3785
  has been reparented.
 
3786
 
 
3787
  \sa reparent()
 
3788
*/
 
3789
 
 
3790
void QWidgetPrivate::reparentFocusWidgets(QWidget * oldtlw)
 
3791
{
 
3792
    Q_Q(QWidget);
 
3793
    if (oldtlw == q->window())
 
3794
        return; // nothing to do
 
3795
 
 
3796
    if(focus_child)
 
3797
        focus_child->clearFocus();
 
3798
 
 
3799
    // seperate the focus chain
 
3800
    QWidget *topLevel = q->window();
 
3801
    QWidget *w = q;
 
3802
    QWidget *firstOld = 0;
 
3803
    QWidget *firstNew = 0;
 
3804
    QWidget *o = 0;
 
3805
    QWidget *n = 0;
 
3806
    do {
 
3807
        if (w == q || q->isAncestorOf(w)) {
 
3808
            if (!firstNew)
 
3809
                firstNew = w;
 
3810
            if (n)
 
3811
                n->d_func()->focus_next = w;
 
3812
            n = w;
 
3813
        } else {
 
3814
            if (!firstOld)
 
3815
                firstOld = w;
 
3816
            if (o)
 
3817
                o->d_func()->focus_next = w;
 
3818
            o = w;
 
3819
        }
 
3820
    } while ((w = w->d_func()->focus_next) != q);
 
3821
    if(o)
 
3822
        o->d_func()->focus_next = firstOld;
 
3823
    if(n)
 
3824
        n->d_func()->focus_next = firstNew;
 
3825
 
 
3826
    if (!q->isWindow()) {
 
3827
        //insert chain
 
3828
        w = topLevel;
 
3829
        while (w->d_func()->focus_next != topLevel)
 
3830
            w = w->d_func()->focus_next;
 
3831
        w->d_func()->focus_next = q;
 
3832
        n->d_func()->focus_next = topLevel;
 
3833
    } else {
 
3834
        n->d_func()->focus_next = q;
 
3835
    }
 
3836
}
 
3837
 
 
3838
/*!\internal
 
3839
 
 
3840
  Measures the shortest distance from a point to a rect.
 
3841
 
 
3842
  This function is called from QDesktopwidget::screen(QPoint) to find the
 
3843
  closest screen for a point.
 
3844
*/
 
3845
int QWidgetPrivate::pointToRect(const QPoint &p, const QRect &r)
 
3846
{
 
3847
    int dx = 0;
 
3848
    int dy = 0;
 
3849
    if (p.x() < r.left())
 
3850
        dx = r.left() - p.x();
 
3851
    else if (p.x() > r.right())
 
3852
        dx = p.x() - r.right();
 
3853
    if (p.y() < r.top())
 
3854
        dy = r.top() - p.y();
 
3855
    else if (p.y() > r.bottom())
 
3856
        dy = p.y() - r.bottom();
 
3857
    return dx + dy;
 
3858
}
 
3859
 
 
3860
/*!
 
3861
    \property QWidget::frameSize
 
3862
    \brief the size of the widget including any window frame
 
3863
*/
 
3864
QSize QWidget::frameSize() const
 
3865
{
 
3866
    Q_D(const QWidget);
 
3867
    if (isWindow() && !(windowType() == Qt::Popup)) {
 
3868
        if (data->fstrut_dirty)
 
3869
            d->updateFrameStrut();
 
3870
        QWidget *that = (QWidget *) this;
 
3871
        QTLWExtra *top = that->d_func()->topData();
 
3872
        return QSize(data->crect.width() + top->fleft + top->fright,
 
3873
                      data->crect.height() + top->ftop + top->fbottom);
 
3874
    }
 
3875
    return data->crect.size();
 
3876
}
 
3877
 
 
3878
/*! \fn void QWidget::move(int x, int y)
 
3879
 
 
3880
    \overload
 
3881
 
 
3882
    This corresponds to move(QPoint(\a x, \a y)).
 
3883
*/
 
3884
 
 
3885
void QWidget::move(const QPoint &p)
 
3886
{
 
3887
    Q_D(QWidget);
 
3888
    QPoint oldp = pos();
 
3889
    setAttribute(Qt::WA_Moved);
 
3890
    d->setGeometry_sys(p.x() + geometry().x() - QWidget::x(),
 
3891
                       p.y() + geometry().y() - QWidget::y(),
 
3892
                       width(), height(), true);
 
3893
    if (oldp != pos())
 
3894
        d->updateInheritedBackground();
 
3895
}
 
3896
 
 
3897
/*! \fn void QWidget::resize(int w, int h)
 
3898
    \overload
 
3899
 
 
3900
    This corresponds to resize(QSize(\a w, \a h)).
 
3901
*/
 
3902
 
 
3903
void QWidget::resize(const QSize &s)
 
3904
{
 
3905
    Q_D(QWidget);
 
3906
    setAttribute(Qt::WA_Resized);
 
3907
    QSize olds = size();
 
3908
    d->setGeometry_sys(geometry().x(), geometry().y(), s.width(), s.height(), false);
 
3909
    if (testAttribute(Qt::WA_ContentsPropagated) &&  olds != size())
 
3910
        d->updatePropagatedBackground();
 
3911
}
 
3912
 
 
3913
void QWidget::setGeometry(const QRect &r)
 
3914
{
 
3915
    Q_D(QWidget);
 
3916
    QPoint oldp = pos();
 
3917
    QSize olds = size();
 
3918
    setAttribute(Qt::WA_Resized);
 
3919
    setAttribute(Qt::WA_Moved);
 
3920
    d->setGeometry_sys(r.x(), r.y(), r.width(), r.height(), true);
 
3921
 
 
3922
    if (testAttribute(Qt::WA_ContentsPropagated) && olds != size())
 
3923
        d->updatePropagatedBackground();
 
3924
    else if (oldp != pos())
 
3925
        d->updateInheritedBackground();
 
3926
}
 
3927
 
 
3928
 
 
3929
/*!\fn void QWidget::setGeometry(int x, int y, int w, int h)
 
3930
    \overload
 
3931
 
 
3932
    This corresponds to setGeometry(QRect(\a x, \a y, \a w, \a h)).
 
3933
*/
 
3934
 
 
3935
/*!
 
3936
    Sets the margins around the contents of the widget to have the
 
3937
    sizes \a left, \a top, \a right, and \a bottom. The margins are
 
3938
    used by the layout system, and may be used by subclasses to
 
3939
    specify the area to draw in (e.g. excluding the frame).
 
3940
 
 
3941
    Changing the margins will trigger a resizeEvent().
 
3942
 
 
3943
    \sa contentsRect(), getContentsMargins()
 
3944
*/
 
3945
void QWidget::setContentsMargins(int left, int top, int right, int bottom)
 
3946
{
 
3947
    Q_D(QWidget);
 
3948
    if (left == d->leftmargin && top == d->topmargin
 
3949
         && right == d->rightmargin && bottom == d->bottommargin)
 
3950
        return;
 
3951
    d->leftmargin = left;
 
3952
    d->topmargin = top;
 
3953
    d->rightmargin = right;
 
3954
    d->bottommargin = bottom;
 
3955
 
 
3956
    if (QLayout *l=d->layout)
 
3957
        l->update(); //force activate; will do updateGeometry
 
3958
    else
 
3959
        updateGeometry();
 
3960
 
 
3961
    if (isVisible()) {
 
3962
        update();
 
3963
        QResizeEvent e(data->crect.size(), data->crect.size());
 
3964
        QApplication::sendEvent(this, &e);
 
3965
    } else {
 
3966
        setAttribute(Qt::WA_PendingResizeEvent, true);
 
3967
    }
 
3968
}
 
3969
 
 
3970
/*!  Returns the widget's contents margins for \a left, \a top, \a
 
3971
  right, and \a bottom.
 
3972
 
 
3973
  \sa setContentsMargins(), contentsRect()
 
3974
 */
 
3975
void QWidget::getContentsMargins(int *left, int *top, int *right, int *bottom) const
 
3976
{
 
3977
    Q_D(const QWidget);
 
3978
    if (left)
 
3979
        *left = d->leftmargin;
 
3980
    if (top)
 
3981
        *top = d->topmargin;
 
3982
    if (right)
 
3983
        *right = d->rightmargin;
 
3984
    if (bottom)
 
3985
        *bottom = d->bottommargin;
 
3986
}
 
3987
 
 
3988
/*!
 
3989
    Returns the area inside the widget's margins.
 
3990
 
 
3991
    \sa setContentsMargins(), getContentsMargins()
 
3992
*/
 
3993
QRect QWidget::contentsRect() const
 
3994
{
 
3995
    Q_D(const QWidget);
 
3996
    return QRect(QPoint(d->leftmargin, d->topmargin),
 
3997
                 QPoint(data->crect.width() - 1 - d->rightmargin,
 
3998
                        data->crect.height() - 1 - d->bottommargin));
 
3999
 
 
4000
}
 
4001
 
 
4002
 
 
4003
/*!
 
4004
  \fn void QWidget::customContextMenuRequested(const QPoint &pos)
 
4005
 
 
4006
  This signal is emitted when the widget's \l contextMenuPolicy is
 
4007
  Qt::CustomContextMenu, and the user has requested a context menu on
 
4008
  the widget. The position \a pos is the position of the request in
 
4009
  widget coordinates.
 
4010
 
 
4011
  \sa mapToGlobal() QMenu contextMenuPolicy
 
4012
*/
 
4013
 
 
4014
/*!
 
4015
    \property QWidget::contextMenuPolicy
 
4016
    \brief how the widget shows a context menu
 
4017
 
 
4018
    The default value of this property is Qt::DefaultContextMenu,
 
4019
    which means the contextMenuEvent() handler is called. Other values
 
4020
    are Qt::NoContextMenu, Qt::ActionsContextMenu, and
 
4021
    Qt::CustomContextMenu. With Qt::CustomContextMenu, the signal
 
4022
    customContextMenuRequested() is emitted.
 
4023
 
 
4024
    \sa contextMenuEvent() customContextMenuRequested()
 
4025
*/
 
4026
 
 
4027
Qt::ContextMenuPolicy QWidget::contextMenuPolicy() const
 
4028
{
 
4029
    return (Qt::ContextMenuPolicy)data->context_menu_policy;
 
4030
}
 
4031
 
 
4032
void QWidget::setContextMenuPolicy(Qt::ContextMenuPolicy policy)
 
4033
{
 
4034
    data->context_menu_policy = (uint) policy;
 
4035
}
 
4036
 
 
4037
/*!
 
4038
    \property QWidget::focusPolicy
 
4039
    \brief the way the widget accepts keyboard focus
 
4040
 
 
4041
    The policy is \c Qt::TabFocus if the widget accepts keyboard
 
4042
    focus by tabbing, \c Qt::ClickFocus if the widget accepts
 
4043
    focus by clicking, \c Qt::StrongFocus if it accepts both, and
 
4044
    \c Qt::NoFocus (the default) if it does not accept focus at
 
4045
    all.
 
4046
 
 
4047
    You must enable keyboard focus for a widget if it processes
 
4048
    keyboard events. This is normally done from the widget's
 
4049
    constructor. For instance, the QLineEdit constructor calls
 
4050
    setFocusPolicy(Qt::StrongFocus).
 
4051
 
 
4052
    \sa focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), enabled
 
4053
*/
 
4054
 
 
4055
 
 
4056
Qt::FocusPolicy QWidget::focusPolicy() const
 
4057
{
 
4058
    return (Qt::FocusPolicy)data->focus_policy;
 
4059
}
 
4060
 
 
4061
void QWidget::setFocusPolicy(Qt::FocusPolicy policy)
 
4062
{
 
4063
    data->focus_policy = (uint) policy;
 
4064
}
 
4065
 
 
4066
/*!
 
4067
    \property QWidget::updatesEnabled
 
4068
    \brief whether updates are enabled
 
4069
 
 
4070
    An updates enabled widget receives paint events and has a system
 
4071
    background; a disabled widget does not. This also implies that
 
4072
    calling update() and repaint() has no effect if updates are
 
4073
    disabled.
 
4074
 
 
4075
    setUpdatesEnabled() is normally used to disable updates for a
 
4076
    short period of time, for instance to avoid screen flicker during
 
4077
    large changes. In Qt, widgets normally do not generate screen
 
4078
    flicker, but on X11 the server might erase regions on the screen
 
4079
    when widgets get hidden before they can be replaced by other
 
4080
    widgets. Disabling updates solves this.
 
4081
 
 
4082
    Example:
 
4083
    \code
 
4084
        setUpdatesEnabled(false);
 
4085
        bigVisualChanges();
 
4086
        setUpdatesEnabled(true);
 
4087
    \endcode
 
4088
 
 
4089
    Disabling a widget implicitly disables all its children. Enabling
 
4090
    respectively enables all child widgets unless they have been
 
4091
    explicitly disabled. Re-enabling updates implicitly calls update()
 
4092
    on the widget.
 
4093
 
 
4094
    \sa paintEvent()
 
4095
*/
 
4096
void QWidget::setUpdatesEnabled(bool enable)
 
4097
{
 
4098
    Q_D(QWidget);
 
4099
    setAttribute(Qt::WA_ForceUpdatesDisabled, !enable);
 
4100
    d->setUpdatesEnabled_helper(enable);
 
4101
}
 
4102
 
 
4103
/*!  \fn void QWidget::show()
 
4104
 
 
4105
    Shows the widget and its child widgets. This function is
 
4106
    equivalent to setVisible(true).
 
4107
 
 
4108
    \sa showEvent(), hide(), setVisible(), showMinimized(), showMaximized(),
 
4109
    showNormal(), isVisible()
 
4110
*/
 
4111
 
 
4112
 
 
4113
/*! \internal
 
4114
 
 
4115
   Makes the widget visible in the isVisible() meaning of the word.
 
4116
   It is only called for toplevels or widgets with visible parents.
 
4117
 */
 
4118
void QWidgetPrivate::show_recursive()
 
4119
{
 
4120
    Q_Q(QWidget);
 
4121
    // polish if necessary
 
4122
    q->ensurePolished();
 
4123
 
 
4124
#ifdef QT3_SUPPORT
 
4125
    if(sendChildEvents)
 
4126
        QApplication::sendPostedEvents(q, QEvent::ChildInserted);
 
4127
#endif
 
4128
#ifndef QT_NO_LAYOUT
 
4129
    if (!q->isWindow() && q->parentWidget()->d_func()->layout)
 
4130
        q->parentWidget()->d_func()->layout->activate();
 
4131
#endif
 
4132
#ifndef QT_NO_LAYOUT
 
4133
    // activate our layout before we and our children become visible
 
4134
    if (layout)
 
4135
        layout->activate();
 
4136
#endif
 
4137
 
 
4138
    show_helper();
 
4139
}
 
4140
 
 
4141
void QWidgetPrivate::show_helper()
 
4142
{
 
4143
    Q_Q(QWidget);
 
4144
    data.in_show = true; // qws optimization
 
4145
    // make sure we receive pending move and resize events
 
4146
    if (q->testAttribute(Qt::WA_PendingMoveEvent)) {
 
4147
        QMoveEvent e(data.crect.topLeft(), data.crect.topLeft());
 
4148
        QApplication::sendEvent(q, &e);
 
4149
        q->setAttribute(Qt::WA_PendingMoveEvent, false);
 
4150
    }
 
4151
    if (q->testAttribute(Qt::WA_PendingResizeEvent)) {
 
4152
        QResizeEvent e(data.crect.size(), data.crect.size());
 
4153
        QApplication::sendEvent(q, &e);
 
4154
        q->setAttribute(Qt::WA_PendingResizeEvent, false);
 
4155
    }
 
4156
 
 
4157
    // become visible before showing all children
 
4158
    q->setAttribute(Qt::WA_WState_Visible);
 
4159
 
 
4160
    // finally show all children recursively
 
4161
    showChildren(false);
 
4162
 
 
4163
#ifdef QT3_SUPPORT
 
4164
    if (q->parentWidget() && sendChildEvents)
 
4165
        QApplication::sendPostedEvents(q->parentWidget(),
 
4166
                                        QEvent::ChildInserted);
 
4167
#endif
 
4168
 
 
4169
 
 
4170
    // popup handling: new popups and tools need to be raised, and
 
4171
    // exisiting popups must be closed. Also propagate the current
 
4172
    // windows's KeyboardFocusChange status.
 
4173
    if (q->isWindow()) {
 
4174
        if ((q->windowType() == Qt::Tool) || (q->windowType() == Qt::Popup) || q->windowType() == Qt::ToolTip) {
 
4175
            q->raise();
 
4176
            if (q->parentWidget() && q->parentWidget()->window()->testAttribute(Qt::WA_KeyboardFocusChange))
 
4177
                q->setAttribute(Qt::WA_KeyboardFocusChange);
 
4178
        } else {
 
4179
            while (QApplication::activePopupWidget()) {
 
4180
                if (!QApplication::activePopupWidget()->close())
 
4181
                    break;
 
4182
            }
 
4183
        }
 
4184
    }
 
4185
 
 
4186
    // On Windows, show the popup now so that our own focus handling
 
4187
    // stores the correct old focus widget even if it's stolen in the
 
4188
    // showevent
 
4189
#if defined(Q_WS_WIN)
 
4190
    if ((q->windowType() == Qt::Popup))
 
4191
        qApp->d_func()->openPopup(q);
 
4192
#endif
 
4193
 
 
4194
    // send the show event before showing the window
 
4195
    QShowEvent showEvent;
 
4196
    QApplication::sendEvent(q, &showEvent);
 
4197
 
 
4198
    if (q->testAttribute(Qt::WA_ShowModal))
 
4199
        // QApplicationPrivate::enterModal *before* show, otherwise the initial
 
4200
        // stacking might be wrong
 
4201
        QApplicationPrivate::enterModal(q);
 
4202
 
 
4203
    q->setAttribute(Qt::WA_Mapped);
 
4204
    show_sys();
 
4205
 
 
4206
#if !defined(Q_WS_WIN)
 
4207
    if ((q->windowType() == Qt::Popup))
 
4208
        qApp->d_func()->openPopup(q);
 
4209
#endif
 
4210
 
 
4211
#ifndef QT_NO_ACCESSIBILITY
 
4212
    QAccessible::updateAccessibility(q, 0, QAccessible::ObjectShow);
 
4213
#endif
 
4214
 
 
4215
    data.in_show = false;  // reset qws optimization
 
4216
}
 
4217
 
 
4218
/*! \fn void QWidget::hide()
 
4219
 
 
4220
    Hides the widget. This function is equivalent to
 
4221
    setVisible(false).
 
4222
 
 
4223
    \sa hideEvent(), isHidden(), show(), setVisible(), isVisible(), close()
 
4224
*/
 
4225
 
 
4226
/*!\internal
 
4227
 */
 
4228
void QWidgetPrivate::hide_helper()
 
4229
{
 
4230
    Q_Q(QWidget);
 
4231
    if ((q->windowType() == Qt::Popup))
 
4232
        qApp->d_func()->closePopup(q);
 
4233
 
 
4234
    // Move test modal here.  Otherwise, a modal dialog could get
 
4235
    // destroyed and we lose all access to its parent because we haven't
 
4236
    // left modality.  (Eg. modal Progress Dialog)
 
4237
    if (q->testAttribute(Qt::WA_ShowModal))
 
4238
        QApplicationPrivate::leaveModal(q);
 
4239
 
 
4240
#if defined(Q_WS_WIN)
 
4241
    if (q->isWindow() && !(q->windowType() == Qt::Popup) && q->parentWidget() && q->isActiveWindow())
 
4242
        q->parentWidget()->activateWindow();        // Activate parent
 
4243
#endif
 
4244
 
 
4245
    q->setAttribute(Qt::WA_Mapped, false);
 
4246
    hide_sys();
 
4247
 
 
4248
    bool wasVisible = q->testAttribute(Qt::WA_WState_Visible);
 
4249
 
 
4250
    if (wasVisible) {
 
4251
        q->setAttribute(Qt::WA_WState_Visible, false);
 
4252
 
 
4253
    }
 
4254
 
 
4255
    QHideEvent hideEvent;
 
4256
    QApplication::sendEvent(q, &hideEvent);
 
4257
    hideChildren(false);
 
4258
 
 
4259
    // next bit tries to move the focus if the focus widget is now
 
4260
    // hidden.
 
4261
    if (wasVisible) {
 
4262
        QWidget *fw = QApplication::focusWidget();
 
4263
        while (fw &&  !fw->isWindow()) {
 
4264
            if (fw == q) {
 
4265
                q->focusNextPrevChild(true);
 
4266
                break;
 
4267
            }
 
4268
            fw = fw->parentWidget();
 
4269
        }
 
4270
    }
 
4271
 
 
4272
 
 
4273
#ifndef QT_NO_ACCESSIBILITY
 
4274
    if (wasVisible)
 
4275
        QAccessible::updateAccessibility(q, 0, QAccessible::ObjectHide);
 
4276
#endif
 
4277
#ifndef QT_NO_LAYOUT
 
4278
    // invalidate layout similar to updateGeometry()
 
4279
    if (!q->isWindow() && q->parentWidget()) {
 
4280
        if (q->parentWidget()->d_func()->layout)
 
4281
            q->parentWidget()->d_func()->layout->update();
 
4282
        if (wasVisible)
 
4283
            QApplication::postEvent(q->parentWidget(), new QEvent(QEvent::LayoutRequest));
 
4284
    }
 
4285
#endif
 
4286
}
 
4287
 
 
4288
/*!
 
4289
    \fn bool QWidget::isHidden() const
 
4290
 
 
4291
    Returns true if the widget is hidden, otherwise returns false.
 
4292
 
 
4293
    A hidden widget will only become visible when show() is called on
 
4294
    it. It will not be automatically shown when the parent is shown.
 
4295
 
 
4296
    To check visiblity, use !isVisible() instead (notice the exclamation mark).
 
4297
 
 
4298
    isHidden() implies !isVisible(), but a widget can be not visible
 
4299
    and not hidden at the same time. This is the case for widgets that are children of
 
4300
    widgets that are not visible.
 
4301
 
 
4302
 
 
4303
    Widgets are  hidden if they were created as independent
 
4304
    windows or as children of visible widgets, or if hide() or setVisible(false) was called.
 
4305
 
 
4306
*/
 
4307
 
 
4308
 
 
4309
void QWidget::setVisible(bool visible)
 
4310
{
 
4311
    if (visible) { // show
 
4312
        if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
 
4313
            return;
 
4314
 
 
4315
#ifdef Q_WS_X11
 
4316
        if (windowType() == Qt::Window)
 
4317
            QApplicationPrivate::applyX11SpecificCommandLineArguments(this);
 
4318
#endif
 
4319
 
 
4320
        bool wasResized = testAttribute(Qt::WA_Resized);
 
4321
        Qt::WindowStates initialWindowState = windowState();
 
4322
 
 
4323
        Q_D(QWidget);
 
4324
        if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon))
 
4325
            d->setWindowIcon_sys();
 
4326
 
 
4327
        // polish if necessary
 
4328
        ensurePolished();
 
4329
 
 
4330
        // remember that show was called explicitly
 
4331
        setAttribute(Qt::WA_WState_ExplicitShowHide);
 
4332
        // whether we need to inform the parent widget immediately
 
4333
        bool needUpdateGeometry = !isWindow() && testAttribute(Qt::WA_WState_Hidden);
 
4334
        // we are no longer hidden
 
4335
        setAttribute(Qt::WA_WState_Hidden, false);
 
4336
 
 
4337
        if (needUpdateGeometry)
 
4338
            updateGeometry();
 
4339
 
 
4340
#ifdef QT3_SUPPORT
 
4341
        QApplication::sendPostedEvents(this, QEvent::ChildInserted);
 
4342
#endif
 
4343
#ifndef QT_NO_LAYOUT
 
4344
        if (!isWindow() && parentWidget()->d_func()->layout)
 
4345
            parentWidget()->d_func()->layout->activate();
 
4346
#endif
 
4347
#ifndef QT_NO_LAYOUT
 
4348
        // activate our layout before we and our children become visible
 
4349
        if (d->layout)
 
4350
            d->layout->activate();
 
4351
#endif
 
4352
 
 
4353
        // adjust size if necessary
 
4354
        if (!wasResized
 
4355
            && (isWindow() || !parentWidget()->d_func()->layout))  {
 
4356
            if (isWindow()) {
 
4357
                adjustSize();
 
4358
                if (windowState() != initialWindowState)
 
4359
                    setWindowState(initialWindowState);
 
4360
            } else {
 
4361
                adjustSize();
 
4362
            }
 
4363
            setAttribute(Qt::WA_Resized, false);
 
4364
        }
 
4365
 
 
4366
        setAttribute(Qt::WA_KeyboardFocusChange, false);
 
4367
 
 
4368
        if (isWindow() || parentWidget()->isVisible())
 
4369
            d->show_helper();
 
4370
 
 
4371
        QEvent showToParentEvent(QEvent::ShowToParent);
 
4372
        QApplication::sendEvent(this, &showToParentEvent);
 
4373
    } else { // hide
 
4374
        if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden))
 
4375
            return;
 
4376
 
 
4377
        Q_D(QWidget);
 
4378
        setAttribute(Qt::WA_WState_Hidden);
 
4379
        if (testAttribute(Qt::WA_WState_ExplicitShowHide))
 
4380
            d->hide_helper();
 
4381
        else
 
4382
            setAttribute(Qt::WA_WState_ExplicitShowHide);
 
4383
        QEvent hideToParentEvent(QEvent::HideToParent);
 
4384
        QApplication::sendEvent(this, &hideToParentEvent);
 
4385
    }
 
4386
}
 
4387
 
 
4388
/*!\fn void QWidget::setHidden(bool hidden)
 
4389
 
 
4390
    Convenience function, equivalent to setVisible(!\a hidden).
 
4391
*/
 
4392
 
 
4393
/*!\fn void QWidget::setShown(bool shown)
 
4394
 
 
4395
    Use setVisible(\a shown) instead.
 
4396
*/
 
4397
 
 
4398
void QWidgetPrivate::showChildren(bool spontaneous)
 
4399
{
 
4400
    QList<QObject*> childList = children;
 
4401
    for (int i = 0; i < childList.size(); ++i) {
 
4402
        QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
 
4403
        if (!widget
 
4404
            || widget->isWindow()
 
4405
            || widget->testAttribute(Qt::WA_WState_Hidden))
 
4406
            continue;
 
4407
        if (spontaneous) {
 
4408
            widget->setAttribute(Qt::WA_Mapped);
 
4409
            widget->d_func()->showChildren(true);
 
4410
            QShowEvent e;
 
4411
            QApplication::sendSpontaneousEvent(widget, &e);
 
4412
        } else {
 
4413
            if (widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
 
4414
                widget->d_func()->show_recursive();
 
4415
            else
 
4416
                widget->show();
 
4417
        }
 
4418
    }
 
4419
}
 
4420
 
 
4421
void QWidgetPrivate::hideChildren(bool spontaneous)
 
4422
{
 
4423
    QList<QObject*> childList = children;
 
4424
    for (int i = 0; i < childList.size(); ++i) {
 
4425
        QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
 
4426
        if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden))
 
4427
            continue;
 
4428
        if (spontaneous)
 
4429
            widget->setAttribute(Qt::WA_Mapped, false);
 
4430
        else
 
4431
            widget->setAttribute(Qt::WA_WState_Visible, false);
 
4432
        widget->d_func()->hideChildren(spontaneous);
 
4433
        QHideEvent e;
 
4434
        if (spontaneous)
 
4435
            QApplication::sendSpontaneousEvent(widget, &e);
 
4436
        else
 
4437
            QApplication::sendEvent(widget, &e);
 
4438
    }
 
4439
}
 
4440
 
 
4441
bool QWidgetPrivate::close_helper(CloseMode mode)
 
4442
{
 
4443
    if (data.is_closing)
 
4444
        return true;
 
4445
 
 
4446
    Q_Q(QWidget);
 
4447
    data.is_closing = 1;
 
4448
 
 
4449
    QPointer<QWidget> that = q;
 
4450
 
 
4451
#ifdef QT3_SUPPORT
 
4452
    bool isMain = (QApplicationPrivate::main_widget == q);
 
4453
#endif
 
4454
    bool quitOnClose = q->testAttribute(Qt::WA_QuitOnClose);
 
4455
 
 
4456
    if (mode != CloseNoEvent) {
 
4457
        QCloseEvent e;
 
4458
        if (mode == CloseWithSpontaneousEvent)
 
4459
            QApplication::sendSpontaneousEvent(q, &e);
 
4460
        else
 
4461
            QApplication::sendEvent(q, &e);
 
4462
        if (!that.isNull() && !e.isAccepted()) {
 
4463
            data.is_closing = 0;
 
4464
            return false;
 
4465
        }
 
4466
    }
 
4467
 
 
4468
    if (!that.isNull() && !q->isHidden())
 
4469
        q->hide();
 
4470
 
 
4471
#ifdef QT3_SUPPORT
 
4472
    if (isMain)
 
4473
        qApp->quit();
 
4474
#endif
 
4475
    if (quitOnClose) {
 
4476
        /* if there is no non-withdrawn top level window left
 
4477
           (except the desktop, popups, or dialogs/tools with
 
4478
           parents), we emit the lastWindowClosed signal */
 
4479
        QWidgetList list = QApplication::topLevelWidgets();
 
4480
        bool lastWindowClosed = true;
 
4481
        for (int i = 0; i < list.size(); ++i) {
 
4482
            QWidget *w = list.at(i);
 
4483
            if (!w->isVisible() || !w->testAttribute(Qt::WA_QuitOnClose))
 
4484
                continue;
 
4485
            lastWindowClosed = false;
 
4486
            break;
 
4487
        }
 
4488
        if (lastWindowClosed)
 
4489
            QApplicationPrivate::emitLastWindowClosed();
 
4490
    }
 
4491
 
 
4492
    if (!that.isNull()) {
 
4493
        data.is_closing = 0;
 
4494
        if (q->testAttribute(Qt::WA_DeleteOnClose)) {
 
4495
            q->setAttribute(Qt::WA_DeleteOnClose, false);
 
4496
            q->deleteLater();
 
4497
        }
 
4498
    }
 
4499
    return true;
 
4500
}
 
4501
 
 
4502
 
 
4503
/*!
 
4504
    Closes this widget. Returns true if the widget was closed;
 
4505
    otherwise returns false.
 
4506
 
 
4507
    First it sends the widget a QCloseEvent. The widget is \link
 
4508
    hide() hidden\endlink if it \link QCloseEvent::accept()
 
4509
    accepts\endlink the close event. If it \link QCloseEvent::ignore()
 
4510
    ignores\endlink the event, nothing happens. The default
 
4511
    implementation of QWidget::closeEvent() accepts the close event.
 
4512
 
 
4513
    If the widget has the \c Qt::WA_DeleteOnClose flag, the widget
 
4514
    is also deleted. A close events is delivered to the widget no
 
4515
    matter if the widget is visible or not.
 
4516
 
 
4517
    The \l QApplication::lastWindowClosed() signal is emitted when the
 
4518
    last visible top level widget with the Qt::WA_QuitOnClose
 
4519
    attribute set is closed. By default this attribute is set for all
 
4520
    widgets except transient top level widgets such as splash screens,
 
4521
    popup menus, and dialogs.
 
4522
 
 
4523
*/
 
4524
 
 
4525
bool QWidget::close()
 
4526
{
 
4527
    return d_func()->close_helper(QWidgetPrivate::CloseWithEvent);
 
4528
}
 
4529
 
 
4530
/*!
 
4531
    \property QWidget::visible
 
4532
    \brief whether the widget is visible
 
4533
 
 
4534
    Calling setVisible(true) or show() sets the widget to visible
 
4535
    status if all its parent widgets up to the window are visible. If
 
4536
    an ancestor is not visible, the widget won't become visible until
 
4537
    all its ancestors are shown. If its size or position has changed,
 
4538
    Qt guarantees that a widget gets move and resize events just
 
4539
    before it is shown. If the widget has not been resized yet, Qt
 
4540
    will adjust the widget's size to a useful default using
 
4541
    adjustSize().
 
4542
 
 
4543
    Calling setVisible(false) or hide() hides a widget explicitly. An
 
4544
    explicitly hidden widget will never become visible, even if all
 
4545
    its ancestors become visible, unless you show it.
 
4546
 
 
4547
    A widget receives show and hide events when its visibility status
 
4548
    changes. Between a hide and a show event, there is no need to
 
4549
    waste CPU cycles preparing or displaying information to the user.
 
4550
    A video application, for example, might simply stop generating new
 
4551
    frames.
 
4552
 
 
4553
    A widget that happens to be obscured by other windows on the
 
4554
    screen is considered to be visible. The same applies to iconified
 
4555
    windows and windows that exist on another virtual
 
4556
    desktop (on platforms that support this concept). A widget
 
4557
    receives spontaneous show and hide events when its mapping status
 
4558
    is changed by the window system, e.g. a spontaneous hide event
 
4559
    when the user minimizes the window, and a spontaneous show event
 
4560
    when the window is restored again.
 
4561
 
 
4562
    You almost never have to reimplement the setVisible() function. If
 
4563
    you need to change some settings before a widget is shown, use
 
4564
    showEvent() instead. If you need to do some delayed initialization
 
4565
    use the Polish event delivered to the event() method
 
4566
 
 
4567
    \sa show(), hide(), isHidden(), isVisibleTo(), isMinimized(),
 
4568
    showEvent(), hideEvent()
 
4569
*/
 
4570
 
 
4571
 
 
4572
/*!
 
4573
    Returns true if this widget would become visible if \a ancestor is
 
4574
    shown; otherwise returns false.
 
4575
 
 
4576
    The true case occurs if neither the widget itself nor any parent
 
4577
    up to but excluding \a ancestor has been explicitly hidden.
 
4578
 
 
4579
    This function will still return true if the widget is obscured by
 
4580
    other windows on the screen, but could be physically visible if it
 
4581
    or they were to be moved.
 
4582
 
 
4583
    isVisibleTo(0) is identical to isVisible().
 
4584
 
 
4585
    \sa show() hide() isVisible()
 
4586
*/
 
4587
 
 
4588
bool QWidget::isVisibleTo(QWidget* ancestor) const
 
4589
{
 
4590
    if (!ancestor)
 
4591
        return isVisible();
 
4592
    const QWidget * w = this;
 
4593
    while (w
 
4594
            && !w->isHidden()
 
4595
            && !w->isWindow()
 
4596
            && w->parentWidget()
 
4597
            && w->parentWidget() != ancestor)
 
4598
        w = w->parentWidget();
 
4599
    return !w->isHidden();
 
4600
}
 
4601
 
 
4602
#ifdef QT3_SUPPORT
 
4603
QRect QWidget::visibleRect() const
 
4604
{
 
4605
    return d_func()->clipRect();
 
4606
}
 
4607
#endif
 
4608
 
 
4609
/*!
 
4610
    Returns the unobscured region where paint events can occur.
 
4611
 
 
4612
    For visible widgets, this is an approximation of the area not
 
4613
    covered by other widgets; otherwise, this is an empty region.
 
4614
 
 
4615
    The repaint() function calls this function if necessary, so in
 
4616
    general you do not need to call it.
 
4617
 
 
4618
*/
 
4619
QRegion QWidget::visibleRegion() const
 
4620
{
 
4621
    return d_func()->clipRect();
 
4622
}
 
4623
 
 
4624
 
 
4625
/*!
 
4626
    Adjusts the size of the widget to fit the contents.
 
4627
 
 
4628
    Uses sizeHint() if valid (i.e if the size hint's width and height
 
4629
    are \>= 0), otherwise sets the size to the children rectangle (the
 
4630
    union of all child widget geometries). For toplevel widgets, the
 
4631
    function also takes the screen size into account.
 
4632
 
 
4633
    \sa sizeHint(), childrenRect()
 
4634
*/
 
4635
 
 
4636
void QWidget::adjustSize()
 
4637
{
 
4638
    ensurePolished();
 
4639
 
 
4640
    QSize s = sizeHint();
 
4641
 
 
4642
    if (isWindow()) {
 
4643
        Qt::Orientations exp;
 
4644
#ifndef QT_NO_LAYOUT
 
4645
        if (QLayout *l = layout()) {
 
4646
            if (l->hasHeightForWidth())
 
4647
                s.setHeight(l->totalHeightForWidth(s.width()));
 
4648
            exp = l->expandingDirections();
 
4649
        } else
 
4650
#endif
 
4651
        {
 
4652
            if (sizePolicy().hasHeightForWidth())
 
4653
                s.setHeight(heightForWidth(s.width()));
 
4654
            exp = sizePolicy().expandingDirections();
 
4655
        }
 
4656
        if (exp & Qt::Horizontal)
 
4657
            s.setWidth(qMax(s.width(), 200));
 
4658
        if (exp & Qt::Vertical)
 
4659
            s.setHeight(qMax(s.height(), 150));
 
4660
#if defined(Q_WS_X11)
 
4661
        QRect screen = QApplication::desktop()->screenGeometry(x11Info().screen());
 
4662
#else // all others
 
4663
        QRect screen = QApplication::desktop()->screenGeometry(pos());
 
4664
#endif
 
4665
        s.setWidth(qMin(s.width(), screen.width()*2/3));
 
4666
        s.setHeight(qMin(s.height(), screen.height()*2/3));
 
4667
    }
 
4668
 
 
4669
    if (!s.isValid()) {
 
4670
        QRect r = childrenRect(); // get children rectangle
 
4671
        if (r.isNull())
 
4672
            return;
 
4673
        s = r.size() + QSize(2 * r.x(), 2 * r.y());
 
4674
    }
 
4675
 
 
4676
    resize(s);
 
4677
}
 
4678
 
 
4679
 
 
4680
/*!
 
4681
    \property QWidget::sizeHint
 
4682
    \brief the recommended size for the widget
 
4683
 
 
4684
    If the value of this property is an invalid size, no size is
 
4685
    recommended.
 
4686
 
 
4687
    The default implementation of sizeHint() returns an invalid size
 
4688
    if there is no layout for this widget, and returns the layout's
 
4689
    preferred size otherwise.
 
4690
 
 
4691
    \sa QSize::isValid(), minimumSizeHint(), sizePolicy(),
 
4692
    setMinimumSize(), updateGeometry()
 
4693
*/
 
4694
 
 
4695
QSize QWidget::sizeHint() const
 
4696
{
 
4697
    Q_D(const QWidget);
 
4698
#ifndef QT_NO_LAYOUT
 
4699
    if (d->layout)
 
4700
        return d->layout->totalSizeHint();
 
4701
#endif
 
4702
    return QSize(-1, -1);
 
4703
}
 
4704
 
 
4705
/*!
 
4706
    \property QWidget::minimumSizeHint
 
4707
    \brief the recommended minimum size for the widget
 
4708
 
 
4709
    If the value of this property is an invalid size, no minimum size
 
4710
    is recommended.
 
4711
 
 
4712
    The default implementation of minimumSizeHint() returns an invalid
 
4713
    size if there is no layout for this widget, and returns the
 
4714
    layout's minimum size otherwise. Most built-in widgets reimplement
 
4715
    minimumSizeHint().
 
4716
 
 
4717
    \l QLayout will never resize a widget to a size smaller than the
 
4718
    minimum size hint unless minimumSize() is set or the size policy is
 
4719
    set to \c QSizePolicy::Ignore. If minimumSize() is set, the minimum
 
4720
    size hint will be ignored.
 
4721
 
 
4722
    \sa QSize::isValid(), resize(), setMinimumSize(), sizePolicy()
 
4723
*/
 
4724
QSize QWidget::minimumSizeHint() const
 
4725
{
 
4726
    Q_D(const QWidget);
 
4727
#ifndef QT_NO_LAYOUT
 
4728
    if (d->layout)
 
4729
        return d->layout->totalMinimumSize();
 
4730
#endif
 
4731
    return QSize(-1, -1);
 
4732
}
 
4733
 
 
4734
 
 
4735
/*!
 
4736
    \fn QWidget *QWidget::parentWidget() const
 
4737
 
 
4738
    Returns the parent of this widget, or 0 if it does not have any
 
4739
    parent widget.
 
4740
*/
 
4741
 
 
4742
 
 
4743
/*!
 
4744
    Returns true if this widget is a parent, (or grandparent and so on
 
4745
    to any level), of the given \a child, and both widgets are within
 
4746
    the same window; otherwise returns false.
 
4747
*/
 
4748
 
 
4749
bool QWidget::isAncestorOf(const QWidget *child) const
 
4750
{
 
4751
    while (child) {
 
4752
        if (child == this)
 
4753
            return true;
 
4754
        if (child->isWindow())
 
4755
            return false;
 
4756
        child = child->parentWidget();
 
4757
    }
 
4758
    return false;
 
4759
}
 
4760
 
 
4761
 
 
4762
 
 
4763
/*****************************************************************************
 
4764
  QWidget event handling
 
4765
 *****************************************************************************/
 
4766
 
 
4767
/*!
 
4768
    This is the main event handler; it handles event \a e. You can
 
4769
    reimplement this function in a subclass, but we recommend using
 
4770
    one of the specialized event handlers instead.
 
4771
 
 
4772
    Key press and release events are treated differently from other
 
4773
    events. event() checks for Tab and Shift+Tab and tries to move the
 
4774
    focus appropriately. If there is no widget to move the focus to
 
4775
    (or the key press is not Tab or Shift+Tab), event() calls
 
4776
    keyPressEvent().
 
4777
 
 
4778
    Mouse and tablet event handling is also slightly special: only
 
4779
    when the widget is \l enabled, event() will call the specialized
 
4780
    handlers such as mousePressEvent(); otherwise it will discard the
 
4781
    event.
 
4782
 
 
4783
    This function returns true if the event was recognized, otherwise
 
4784
    it returns false.  If the recognized event was accepted (see \l
 
4785
    QEvent::accepted), any further processing such as event
 
4786
    propagation to the parent widget stops.
 
4787
 
 
4788
    \sa closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(),
 
4789
    keyPressEvent(), keyReleaseEvent(), leaveEvent(),
 
4790
    mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(),
 
4791
    mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(),
 
4792
    QObject::event(), QObject::timerEvent()
 
4793
*/
 
4794
 
 
4795
bool QWidget::event(QEvent *e)
 
4796
{
 
4797
    Q_D(QWidget);
 
4798
 
 
4799
    // ignore mouse events when disabled
 
4800
    if (!isEnabled()) {
 
4801
        switch(e->type()) {
 
4802
        case QEvent::TabletPress:
 
4803
        case QEvent::TabletRelease:
 
4804
        case QEvent::TabletMove:
 
4805
        case QEvent::MouseButtonPress:
 
4806
        case QEvent::MouseButtonRelease:
 
4807
        case QEvent::MouseButtonDblClick:
 
4808
        case QEvent::MouseMove:
 
4809
        case QEvent::ContextMenu:
 
4810
#ifndef QT_NO_WHEELEVENT
 
4811
        case QEvent::Wheel:
 
4812
#endif
 
4813
            return false;
 
4814
        default:
 
4815
            break;
 
4816
        }
 
4817
    }
 
4818
    switch (e->type()) {
 
4819
    case QEvent::MouseMove:
 
4820
        mouseMoveEvent((QMouseEvent*)e);
 
4821
        break;
 
4822
 
 
4823
    case QEvent::MouseButtonPress:
 
4824
        // Don't reset input context here. Whether reset or not is
 
4825
        // a responsibility of input method. reset() will be
 
4826
        // called by mouseHandler() of input method if necessary
 
4827
        // via mousePressEvent() of text widgets.
 
4828
#if 0
 
4829
        resetInputContext();
 
4830
#endif
 
4831
        mousePressEvent((QMouseEvent*)e);
 
4832
        break;
 
4833
 
 
4834
    case QEvent::MouseButtonRelease:
 
4835
        mouseReleaseEvent((QMouseEvent*)e);
 
4836
        break;
 
4837
 
 
4838
    case QEvent::MouseButtonDblClick:
 
4839
        mouseDoubleClickEvent((QMouseEvent*)e);
 
4840
        break;
 
4841
#ifndef QT_NO_WHEELEVENT
 
4842
    case QEvent::Wheel:
 
4843
        wheelEvent((QWheelEvent*)e);
 
4844
        break;
 
4845
#endif
 
4846
    case QEvent::TabletMove:
 
4847
    case QEvent::TabletPress:
 
4848
    case QEvent::TabletRelease:
 
4849
        tabletEvent((QTabletEvent*)e);
 
4850
        break;
 
4851
#ifdef QT3_SUPPORT
 
4852
    case QEvent::Accel:
 
4853
        e->ignore();
 
4854
        return false;
 
4855
#endif
 
4856
    case QEvent::KeyPress: {
 
4857
        QKeyEvent *k = (QKeyEvent *)e;
 
4858
        bool res = false;
 
4859
        if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) {
 
4860
            if (k->key() == Qt::Key_Backtab
 
4861
                || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier)))
 
4862
                res = focusNextPrevChild(false);
 
4863
            else if (k->key() == Qt::Key_Tab)
 
4864
                res = focusNextPrevChild(true);
 
4865
            if (res)
 
4866
                break;
 
4867
        }
 
4868
        keyPressEvent(k);
 
4869
        if (!k->isAccepted()
 
4870
            && k->modifiers() & Qt::ShiftModifier && k->key() == Qt::Key_F1
 
4871
            && d->whatsThis.size()) {
 
4872
            QWhatsThis::showText(mapToGlobal(inputMethodQuery(Qt::ImMicroFocus).toRect().center()), d->whatsThis, this);
 
4873
            k->accept();
 
4874
        }
 
4875
    }
 
4876
        break;
 
4877
 
 
4878
    case QEvent::KeyRelease:
 
4879
        keyReleaseEvent((QKeyEvent*)e);
 
4880
        // fall through
 
4881
    case QEvent::ShortcutOverride:
 
4882
        break;
 
4883
 
 
4884
    case QEvent::InputMethod:
 
4885
        inputMethodEvent((QInputMethodEvent *) e);
 
4886
        break;
 
4887
 
 
4888
    case QEvent::PolishRequest:
 
4889
        ensurePolished();
 
4890
        break;
 
4891
 
 
4892
    case QEvent::Polish: {
 
4893
        style()->polish(this);
 
4894
        setAttribute(Qt::WA_WState_Polished);
 
4895
        if (!testAttribute(Qt::WA_SetFont) && !QApplication::font(this).isCopyOf(QApplication::font()))
 
4896
            d->resolveFont();
 
4897
        if (!QApplication::palette(this).isCopyOf(QApplication::palette()))
 
4898
            d->resolvePalette();
 
4899
#ifdef QT3_SUPPORT
 
4900
        if(d->sendChildEvents)
 
4901
            QApplication::sendPostedEvents(this, QEvent::ChildInserted);
 
4902
#endif
 
4903
    }
 
4904
        break;
 
4905
 
 
4906
    case QEvent::ApplicationWindowIconChange:
 
4907
        if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon))
 
4908
            d->setWindowIcon_sys();
 
4909
        break;
 
4910
 
 
4911
    case QEvent::FocusIn:
 
4912
        focusInEvent((QFocusEvent*)e);
 
4913
        break;
 
4914
 
 
4915
    case QEvent::FocusOut:
 
4916
        focusOutEvent((QFocusEvent*)e);
 
4917
        break;
 
4918
 
 
4919
    case QEvent::Enter:
 
4920
        if (d->statusTip.size()) {
 
4921
            QStatusTipEvent tip(d->statusTip);
 
4922
            QApplication::sendEvent(const_cast<QWidget *>(this), &tip);
 
4923
        }
 
4924
        enterEvent(e);
 
4925
        break;
 
4926
 
 
4927
    case QEvent::Leave:
 
4928
        if (d->statusTip.size()) {
 
4929
            QString empty;
 
4930
            QStatusTipEvent tip(empty);
 
4931
            QApplication::sendEvent(const_cast<QWidget *>(this), &tip);
 
4932
        }
 
4933
        leaveEvent(e);
 
4934
        break;
 
4935
 
 
4936
    case QEvent::HoverEnter:
 
4937
    case QEvent::HoverLeave:
 
4938
        update();
 
4939
        break;
 
4940
 
 
4941
    case QEvent::Paint:
 
4942
        // At this point the event has to be delivered, regardless
 
4943
        // whether the widget isVisible() or not because it
 
4944
        // already went through the filters
 
4945
        paintEvent((QPaintEvent*)e);
 
4946
        break;
 
4947
 
 
4948
    case QEvent::Move:
 
4949
        moveEvent((QMoveEvent*)e);
 
4950
        break;
 
4951
 
 
4952
    case QEvent::Resize:
 
4953
        resizeEvent((QResizeEvent*)e);
 
4954
        break;
 
4955
 
 
4956
    case QEvent::Close:
 
4957
        closeEvent((QCloseEvent *)e);
 
4958
        break;
 
4959
 
 
4960
    case QEvent::ContextMenu:
 
4961
        switch (data->context_menu_policy) {
 
4962
        case Qt::DefaultContextMenu:
 
4963
            contextMenuEvent(static_cast<QContextMenuEvent *>(e));
 
4964
            break;
 
4965
        case Qt::CustomContextMenu:
 
4966
            emit customContextMenuRequested(static_cast<QContextMenuEvent *>(e)->pos());
 
4967
            break;
 
4968
        case Qt::ActionsContextMenu:
 
4969
            if (d->actions.count()) {
 
4970
                QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(e)->globalPos());
 
4971
                break;
 
4972
            }
 
4973
            // fall through
 
4974
        default:
 
4975
            e->ignore();
 
4976
            break;
 
4977
        }
 
4978
        break;
 
4979
 
 
4980
#ifndef QT_NO_DRAGANDDROP
 
4981
    case QEvent::Drop:
 
4982
        dropEvent((QDropEvent*) e);
 
4983
        break;
 
4984
 
 
4985
    case QEvent::DragEnter:
 
4986
        dragEnterEvent((QDragEnterEvent*) e);
 
4987
        break;
 
4988
 
 
4989
    case QEvent::DragMove:
 
4990
        dragMoveEvent((QDragMoveEvent*) e);
 
4991
        break;
 
4992
 
 
4993
    case QEvent::DragLeave:
 
4994
        dragLeaveEvent((QDragLeaveEvent*) e);
 
4995
        break;
 
4996
#endif
 
4997
 
 
4998
    case QEvent::Show:
 
4999
        showEvent((QShowEvent*) e);
 
5000
        break;
 
5001
 
 
5002
    case QEvent::Hide:
 
5003
        hideEvent((QHideEvent*) e);
 
5004
        break;
 
5005
 
 
5006
    case QEvent::ShowWindowRequest:
 
5007
        if (!isHidden())
 
5008
            d->show_sys();
 
5009
        break;
 
5010
 
 
5011
    case QEvent::ApplicationFontChange:
 
5012
        d->resolveFont();
 
5013
        break;
 
5014
    case QEvent::ApplicationPaletteChange:
 
5015
        if (!(windowType() == Qt::Desktop))
 
5016
            d->resolvePalette();
 
5017
        break;
 
5018
    case QEvent::ToolBarChange:
 
5019
    case QEvent::ActivationChange:
 
5020
    case QEvent::EnabledChange:
 
5021
    case QEvent::FontChange:
 
5022
    case QEvent::StyleChange:
 
5023
    case QEvent::PaletteChange:
 
5024
    case QEvent::WindowTitleChange:
 
5025
    case QEvent::IconTextChange:
 
5026
    case QEvent::ModifiedChange:
 
5027
    case QEvent::MouseTrackingChange:
 
5028
    case QEvent::ParentChange:
 
5029
    case QEvent::WindowStateChange:
 
5030
        changeEvent(e);
 
5031
        break;
 
5032
 
 
5033
    case QEvent::WindowActivate:
 
5034
    case QEvent::WindowDeactivate: {
 
5035
#ifdef QT3_SUPPORT
 
5036
        windowActivationChange(e->type() != QEvent::WindowActivate);
 
5037
#endif
 
5038
        if (isVisible()) {
 
5039
            for(int role=0; role < (int)QPalette::NColorRoles; role++) {
 
5040
                if(data->pal.brush(QPalette::Active, (QPalette::ColorRole)role) !=
 
5041
                   data->pal.brush(QPalette::Inactive, (QPalette::ColorRole)role)) {
 
5042
                    QPalette::ColorRole bg_role = backgroundRole();
 
5043
                    if (!testAttribute(Qt::WA_NoSystemBackground) && bg_role < QPalette::NColorRoles &&
 
5044
                         (role == bg_role || (role < bg_role && data->pal.brush(QPalette::Active, bg_role) !=
 
5045
                                              data->pal.brush(QPalette::Inactive, bg_role))))
 
5046
                        d->updateSystemBackground();
 
5047
                    else if(role <= QPalette::Shadow)
 
5048
                        update();
 
5049
                    break;
 
5050
                }
 
5051
            }
 
5052
        }
 
5053
        QList<QObject*> childList = d->children;
 
5054
        for (int i = 0; i < childList.size(); ++i) {
 
5055
            QWidget *w = qobject_cast<QWidget *>(childList.at(i));
 
5056
            if (w && w->isVisible() && !w->isWindow())
 
5057
                QApplication::sendEvent(w, e);
 
5058
        }
 
5059
        break; }
 
5060
 
 
5061
    case QEvent::LanguageChange:
 
5062
        changeEvent(e);
 
5063
#ifdef QT3_SUPPORT
 
5064
        languageChange();
 
5065
#endif
 
5066
        // fall through
 
5067
    case QEvent::LocaleChange:
 
5068
        {
 
5069
            QList<QObject*> childList = d->children;
 
5070
            for (int i = 0; i < childList.size(); ++i) {
 
5071
                QObject *o = childList.at(i);
 
5072
                QApplication::sendEvent(o, e);
 
5073
            }
 
5074
        }
 
5075
        update();
 
5076
        break;
 
5077
 
 
5078
    case QEvent::ApplicationLayoutDirectionChange:
 
5079
        d->resolveLayoutDirection();
 
5080
        break;
 
5081
 
 
5082
    case QEvent::LayoutDirectionChange:
 
5083
        if (d->layout)
 
5084
            d->layout->invalidate();
 
5085
        update();
 
5086
        break;
 
5087
 
 
5088
#if defined(Q_WS_X11)
 
5089
    case QEvent::UpdateRequest:
 
5090
        if (!d->invalidated_region.isEmpty()) {
 
5091
            QRegion rgn = d->invalidated_region;
 
5092
            d->invalidated_region = QRegion();
 
5093
            repaint(rgn);
 
5094
        }
 
5095
        break;
 
5096
#endif
 
5097
#if defined(Q_WS_QWS)
 
5098
    case QEvent::QWSUpdate:
 
5099
        repaint(static_cast<QWSUpdateEvent*>(e)->region());
 
5100
        break;
 
5101
#endif
 
5102
 
 
5103
    case QEvent::WindowBlocked:
 
5104
    case QEvent::WindowUnblocked:
 
5105
        {
 
5106
            QList<QObject*> childList = d->children;
 
5107
            for (int i = 0; i < childList.size(); ++i) {
 
5108
                QObject *o = childList.at(i);
 
5109
                if (o != qApp->activeModalWidget())
 
5110
                    QApplication::sendEvent(o, e);
 
5111
            }
 
5112
        }
 
5113
        break;
 
5114
 
 
5115
    case QEvent::ToolTip:
 
5116
        if (d->toolTip.size() && isActiveWindow())
 
5117
            QToolTip::showText(static_cast<QHelpEvent*>(e)->globalPos(), d->toolTip, this);
 
5118
        else
 
5119
            e->ignore();
 
5120
        break;
 
5121
 
 
5122
#ifndef QT_NO_WHATSTHIS
 
5123
    case QEvent::WhatsThis:
 
5124
        if (d->whatsThis.size())
 
5125
            QWhatsThis::showText(static_cast<QHelpEvent *>(e)->globalPos(), d->whatsThis, this);
 
5126
        else
 
5127
            e->ignore();
 
5128
        break;
 
5129
    case QEvent::QueryWhatsThis:
 
5130
        if (d->whatsThis.isEmpty())
 
5131
            e->ignore();
 
5132
        break;
 
5133
#endif
 
5134
#ifndef QT_NO_ACCESSIBILITY
 
5135
    case QEvent::AccessibilityDescription:
 
5136
    case QEvent::AccessibilityHelp: {
 
5137
        QAccessibleEvent *ev = static_cast<QAccessibleEvent *>(e);
 
5138
        if (ev->child())
 
5139
            return false;
 
5140
        switch (ev->type()) {
 
5141
        case QEvent::AccessibilityDescription:
 
5142
            ev->setValue(d->toolTip);
 
5143
            break;
 
5144
        case QEvent::AccessibilityHelp:
 
5145
            ev->setValue(d->whatsThis);
 
5146
            break;
 
5147
        default:
 
5148
            return false;
 
5149
        }
 
5150
        break; }
 
5151
#endif
 
5152
    case QEvent::EmbeddingControl:
 
5153
        data->window_flags & ~Qt::WindowType_Mask;
 
5154
        d->topData()->ftop = 0;
 
5155
        d->topData()->fright = 0;
 
5156
        d->topData()->fleft = 0;
 
5157
        d->topData()->fbottom = 0;
 
5158
        break;
 
5159
    case QEvent::ActionAdded:
 
5160
    case QEvent::ActionRemoved:
 
5161
    case QEvent::ActionChanged:
 
5162
        actionEvent((QActionEvent*)e);
 
5163
        break;
 
5164
    default:
 
5165
        return QObject::event(e);
 
5166
    }
 
5167
    return true;
 
5168
}
 
5169
 
 
5170
/*!
 
5171
  This event handler can be reimplemented to handle state changes.
 
5172
 
 
5173
  The state being changed in this event can be retrieved through event \a
 
5174
  e.
 
5175
 
 
5176
*/
 
5177
void QWidget::changeEvent(QEvent * e)
 
5178
{
 
5179
    switch(e->type()) {
 
5180
    case QEvent::EnabledChange:
 
5181
        update();
 
5182
#ifndef QT_NO_ACCESSIBILITY
 
5183
        QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged);
 
5184
#endif
 
5185
        break;
 
5186
 
 
5187
    case QEvent::FontChange:
 
5188
    case QEvent::StyleChange:
 
5189
        update();
 
5190
        updateGeometry();
 
5191
        break;
 
5192
 
 
5193
    case QEvent::PaletteChange:
 
5194
        update();
 
5195
        break;
 
5196
 
 
5197
    default:
 
5198
        break;
 
5199
    }
 
5200
}
 
5201
 
 
5202
/*!
 
5203
    This event handler, for event \a e, can be reimplemented in a
 
5204
    subclass to receive mouse move events for the widget.
 
5205
 
 
5206
    If mouse tracking is switched off, mouse move events only occur if
 
5207
    a mouse button is pressed while the mouse is being moved. If mouse
 
5208
    tracking is switched on, mouse move events occur even if no mouse
 
5209
    button is pressed.
 
5210
 
 
5211
    QMouseEvent::pos() reports the position of the mouse cursor,
 
5212
    relative to this widget. For press and release events, the
 
5213
    position is usually the same as the position of the last mouse
 
5214
    move event, but it might be different if the user's hand shakes.
 
5215
    This is a feature of the underlying window system, not Qt.
 
5216
 
 
5217
    \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(),
 
5218
    mouseDoubleClickEvent(), event(), QMouseEvent
 
5219
*/
 
5220
 
 
5221
void QWidget::mouseMoveEvent(QMouseEvent * e)
 
5222
{
 
5223
    e->ignore();
 
5224
}
 
5225
 
 
5226
/*!
 
5227
    This event handler, for event \a e, can be reimplemented in a
 
5228
    subclass to receive mouse press events for the widget.
 
5229
 
 
5230
    If you create new widgets in the mousePressEvent() the
 
5231
    mouseReleaseEvent() may not end up where you expect, depending on
 
5232
    the underlying window system (or X11 window manager), the widgets'
 
5233
    location and maybe more.
 
5234
 
 
5235
    The default implementation implements the closing of popup widgets
 
5236
    when you click outside the window. For other widget types it does
 
5237
    nothing.
 
5238
 
 
5239
    \sa mouseReleaseEvent(), mouseDoubleClickEvent(),
 
5240
    mouseMoveEvent(), event(), QMouseEvent
 
5241
*/
 
5242
 
 
5243
void QWidget::mousePressEvent(QMouseEvent *e)
 
5244
{
 
5245
    e->ignore();
 
5246
    if ((windowType() == Qt::Popup)) {
 
5247
        e->accept();
 
5248
        QWidget* w;
 
5249
        while ((w = qApp->activePopupWidget()) && w != this){
 
5250
            w->close();
 
5251
            if (qApp->activePopupWidget() == w) // widget does not want to dissappear
 
5252
                w->hide(); // hide at least
 
5253
        }
 
5254
        if (!rect().contains(e->pos())){
 
5255
            close();
 
5256
        }
 
5257
    }
 
5258
}
 
5259
 
 
5260
/*!
 
5261
    This event handler, for event \a e, can be reimplemented in a
 
5262
    subclass to receive mouse release events for the widget.
 
5263
 
 
5264
    \sa mousePressEvent(), mouseDoubleClickEvent(),
 
5265
    mouseMoveEvent(), event(), QMouseEvent
 
5266
*/
 
5267
 
 
5268
void QWidget::mouseReleaseEvent(QMouseEvent * e)
 
5269
{
 
5270
    e->ignore();
 
5271
}
 
5272
 
 
5273
/*!
 
5274
    This event handler, for event \a e, can be reimplemented in a
 
5275
    subclass to receive mouse double click events for the widget.
 
5276
 
 
5277
    The default implementation generates a normal mouse press event.
 
5278
 
 
5279
    Note that the widgets gets a mousePressEvent() and a
 
5280
    mouseReleaseEvent() before the mouseDoubleClickEvent().
 
5281
 
 
5282
    \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(),
 
5283
    event(), QMouseEvent
 
5284
*/
 
5285
 
 
5286
void QWidget::mouseDoubleClickEvent(QMouseEvent *e)
 
5287
{
 
5288
    mousePressEvent(e);                        // try mouse press event
 
5289
}
 
5290
 
 
5291
#ifndef QT_NO_WHEELEVENT
 
5292
/*!
 
5293
    This event handler, for event \a e, can be reimplemented in a
 
5294
    subclass to receive wheel events for the widget.
 
5295
 
 
5296
    If you reimplement this handler, it is very important that you
 
5297
    \link QWheelEvent ignore()\endlink the event if you do not handle
 
5298
    it, so that the widget's parent can interpret it.
 
5299
 
 
5300
    The default implementation ignores the event.
 
5301
 
 
5302
    \sa QWheelEvent::ignore(), QWheelEvent::accept(), event(),
 
5303
    QWheelEvent
 
5304
*/
 
5305
 
 
5306
void QWidget::wheelEvent(QWheelEvent *e)
 
5307
{
 
5308
    e->ignore();
 
5309
}
 
5310
#endif
 
5311
 
 
5312
 
 
5313
/*!
 
5314
    This event handler, for event \a e, can be reimplemented in a
 
5315
    subclass to receive tablet events for the widget.
 
5316
 
 
5317
    If you reimplement this handler, it is very important that you
 
5318
    \link QTabletEvent ignore()\endlink the event if you do not handle
 
5319
    it, so that the widget's parent can interpret it.
 
5320
 
 
5321
    The default implementation ignores the event.
 
5322
 
 
5323
    \sa QTabletEvent::ignore(), QTabletEvent::accept(), event(),
 
5324
    QTabletEvent
 
5325
*/
 
5326
 
 
5327
void QWidget::tabletEvent(QTabletEvent *e)
 
5328
{
 
5329
    e->ignore();
 
5330
}
 
5331
 
 
5332
/*!
 
5333
    This event handler, for event \a e, can be reimplemented in a
 
5334
    subclass to receive key press events for the widget.
 
5335
 
 
5336
    A widget must call setFocusPolicy() to accept focus initially and
 
5337
    have focus in order to receive a key press event.
 
5338
 
 
5339
    If you reimplement this handler, it is very important that you
 
5340
    \link QKeyEvent ignore()\endlink the event if you do not
 
5341
    understand it, so that the widget's parent can interpret it.
 
5342
 
 
5343
    The default implementation closes popup widgets if the user
 
5344
    presses Esc. Otherwise the event is ignored.
 
5345
 
 
5346
    \sa keyReleaseEvent(), QKeyEvent::ignore(), setFocusPolicy(),
 
5347
    focusInEvent(), focusOutEvent(), event(), QKeyEvent
 
5348
*/
 
5349
 
 
5350
void QWidget::keyPressEvent(QKeyEvent *e)
 
5351
{
 
5352
    if ((windowType() == Qt::Popup) && e->key() == Qt::Key_Escape) {
 
5353
        e->accept();
 
5354
        close();
 
5355
    } else {
 
5356
        e->ignore();
 
5357
    }
 
5358
}
 
5359
 
 
5360
/*!
 
5361
    This event handler, for event \a e, can be reimplemented in a
 
5362
    subclass to receive key release events for the widget.
 
5363
 
 
5364
    A widget must \link setFocusPolicy() accept focus\endlink
 
5365
    initially and \link hasFocus() have focus\endlink in order to
 
5366
    receive a key release event.
 
5367
 
 
5368
    If you reimplement this handler, it is very important that you
 
5369
    \link QKeyEvent ignore()\endlink the release if you do not
 
5370
    understand it, so that the widget's parent can interpret it.
 
5371
 
 
5372
    The default implementation ignores the event.
 
5373
 
 
5374
    \sa keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(),
 
5375
    focusInEvent(), focusOutEvent(), event(), QKeyEvent
 
5376
*/
 
5377
 
 
5378
void QWidget::keyReleaseEvent(QKeyEvent *e)
 
5379
{
 
5380
    e->ignore();
 
5381
}
 
5382
 
 
5383
/*!
 
5384
    \fn void QWidget::focusInEvent(QFocusEvent *event)
 
5385
 
 
5386
    This event handler can be reimplemented in a subclass to receive
 
5387
    keyboard focus events (focus received) for the widget. The event
 
5388
    is passed in the \a event parameter
 
5389
 
 
5390
    A widget normally must setFocusPolicy() to something other than
 
5391
    \c Qt::NoFocus in order to receive focus events. (Note that the
 
5392
    application programmer can call setFocus() on any widget, even
 
5393
    those that do not normally accept focus.)
 
5394
 
 
5395
    The default implementation updates the widget (except for windows
 
5396
    that do not specify a focusPolicy()).
 
5397
 
 
5398
    \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(),
 
5399
    keyReleaseEvent(), event(), QFocusEvent
 
5400
*/
 
5401
 
 
5402
void QWidget::focusInEvent(QFocusEvent *)
 
5403
{
 
5404
    if (focusPolicy() != Qt::NoFocus || !isWindow()) {
 
5405
        update();
 
5406
    }
 
5407
}
 
5408
 
 
5409
/*!
 
5410
    \fn void QWidget::focusOutEvent(QFocusEvent *event)
 
5411
 
 
5412
    This event handler can be reimplemented in a subclass to receive
 
5413
    keyboard focus events (focus lost) for the widget. The events is
 
5414
    passed in the \a event parameter.
 
5415
 
 
5416
    A widget normally must setFocusPolicy() to something other than
 
5417
    \c Qt::NoFocus in order to receive focus events. (Note that the
 
5418
    application programmer can call setFocus() on any widget, even
 
5419
    those that do not normally accept focus.)
 
5420
 
 
5421
    The default implementation updates the widget (except for windows
 
5422
    that do not specify a focusPolicy()).
 
5423
 
 
5424
    \sa focusInEvent(), setFocusPolicy(), keyPressEvent(),
 
5425
    keyReleaseEvent(), event(), QFocusEvent
 
5426
*/
 
5427
 
 
5428
void QWidget::focusOutEvent(QFocusEvent *)
 
5429
{
 
5430
    if (focusPolicy() != Qt::NoFocus || !isWindow())
 
5431
        update();
 
5432
}
 
5433
 
 
5434
/*!
 
5435
    \fn void QWidget::enterEvent(QEvent *event)
 
5436
 
 
5437
    This event handler can be reimplemented in a subclass to receive
 
5438
    widget enter events which are passed in the \a event parameter.
 
5439
 
 
5440
    An event is sent to the widget when the mouse cursor enters the
 
5441
    widget.
 
5442
 
 
5443
    \sa leaveEvent(), mouseMoveEvent(), event()
 
5444
*/
 
5445
 
 
5446
void QWidget::enterEvent(QEvent *)
 
5447
{
 
5448
}
 
5449
 
 
5450
/*!
 
5451
    \fn void QWidget::leaveEvent(QEvent *event)
 
5452
 
 
5453
    This event handler can be reimplemented in a subclass to receive
 
5454
    widget leave events which are passed in the \a event parameter.
 
5455
 
 
5456
    A leave event is sent to the widget when the mouse cursor leaves
 
5457
    the widget.
 
5458
 
 
5459
    \sa enterEvent(), mouseMoveEvent(), event()
 
5460
*/
 
5461
 
 
5462
void QWidget::leaveEvent(QEvent *)
 
5463
{
 
5464
}
 
5465
 
 
5466
/*!
 
5467
    \fn void QWidget::paintEvent(QPaintEvent *event)
 
5468
 
 
5469
    This event handler can be reimplemented in a subclass to receive
 
5470
    paint events which are passed in the \a event parameter.
 
5471
 
 
5472
    A paint event is a request to repaint all or part of the widget.
 
5473
    It can happen as a result of repaint() or update(), or because the
 
5474
    widget was obscured and has now been uncovered, or for many other
 
5475
    reasons.
 
5476
 
 
5477
    Many widgets can simply repaint their entire surface when asked
 
5478
    to, but some slow widgets need to optimize by painting only the
 
5479
    requested region: QPaintEvent::region(). This speed optimization
 
5480
    does not change the result, as painting is clipped to that region
 
5481
    during event processing. QListView and QTableView do this, for
 
5482
    example.
 
5483
 
 
5484
    Qt also tries to speed up painting by merging multiple paint
 
5485
    events into one. When update() is called several times or the
 
5486
    window system sends several paint events, Qt merges these events
 
5487
    into one event with a larger region (see QRegion::unite()).
 
5488
    repaint() does not permit this optimization, so we suggest using
 
5489
    update() when possible.
 
5490
 
 
5491
    When the paint event occurs, the update region has normally been
 
5492
    erased, so that you're painting on the widget's background.
 
5493
 
 
5494
    The background can be set using setBackgroundRole() and
 
5495
    setPalette().
 
5496
 
 
5497
    From Qt 4.0, QWidget automatically double-buffers its painting, so
 
5498
    there's no need to write double-buffering code in paintEvent() to
 
5499
    avoid flicker.
 
5500
 
 
5501
    Note: Under X11 it is possible to toggle the global double
 
5502
    buffering by calling \c qt_x11_set_global_double_buffer().
 
5503
    Example usage:
 
5504
    \code
 
5505
    ...
 
5506
    extern void qt_x11_set_global_double_buffer(bool);
 
5507
    qt_x11_set_global_double_buffer(false);
 
5508
    ...
 
5509
    \endcode
 
5510
 
 
5511
    \sa event(), repaint(), update(), QPainter, QPixmap, QPaintEvent
 
5512
*/
 
5513
 
 
5514
void QWidget::paintEvent(QPaintEvent *)
 
5515
{
 
5516
}
 
5517
 
 
5518
 
 
5519
/*!
 
5520
    \fn void QWidget::moveEvent(QMoveEvent *event)
 
5521
 
 
5522
    This event handler can be reimplemented in a subclass to receive
 
5523
    widget move events which are passed in the \a event parameter.
 
5524
    When the widget receives this event, it is already at the new
 
5525
    position.
 
5526
 
 
5527
    The old position is accessible through QMoveEvent::oldPos().
 
5528
 
 
5529
    \sa resizeEvent(), event(), move(), QMoveEvent
 
5530
*/
 
5531
 
 
5532
void QWidget::moveEvent(QMoveEvent *)
 
5533
{
 
5534
}
 
5535
 
 
5536
 
 
5537
/*!
 
5538
    \fn void QWidget::resizeEvent(QResizeEvent *event)
 
5539
 
 
5540
    This event handler can be reimplemented in a subclass to receive
 
5541
    widget resize events which are passed in the \a event parameter.
 
5542
    When resizeEvent() is called, the widget already has its new
 
5543
    geometry. The old size is accessible through
 
5544
    QResizeEvent::oldSize().
 
5545
 
 
5546
    The widget will be erased and receive a paint event immediately
 
5547
    after processing the resize event. No drawing need be (or should
 
5548
    be) done inside this handler.
 
5549
 
 
5550
 
 
5551
    \sa moveEvent(), event(), resize(), QResizeEvent, paintEvent()
 
5552
*/
 
5553
 
 
5554
void QWidget::resizeEvent(QResizeEvent *)
 
5555
{
 
5556
}
 
5557
 
 
5558
/*!
 
5559
    \fn void QWidget::actionEvent(QActionEvent *event)
 
5560
 
 
5561
    This event handler is called with the given \a event whenever the
 
5562
    widget's actions are changed.
 
5563
 
 
5564
    \sa addAction(), insertAction(), removeAction(), actions(), QActionEvent
 
5565
*/
 
5566
void QWidget::actionEvent(QActionEvent *)
 
5567
{
 
5568
 
 
5569
}
 
5570
 
 
5571
/*!
 
5572
    This event handler, for event \a e, can be reimplemented in a
 
5573
    subclass to receive widget close events.
 
5574
 
 
5575
    \sa event(), hide(), close(), QCloseEvent
 
5576
*/
 
5577
 
 
5578
void QWidget::closeEvent(QCloseEvent *e)
 
5579
{
 
5580
    Q_UNUSED(e);
 
5581
}
 
5582
 
 
5583
 
 
5584
/*!
 
5585
    This event handler, for event \a e, can be reimplemented in a
 
5586
    subclass to receive widget context menu events.
 
5587
 
 
5588
    The handler is called when the widget's \l contextMenuPolicy is
 
5589
    Qt::DefaultContextMenu.
 
5590
 
 
5591
    The default implementation calls e->ignore(), which rejects the
 
5592
    context event. See the \l QContextMenuEvent documentation for
 
5593
    more details.
 
5594
 
 
5595
    \sa event(), QContextMenuEvent customContextMenuRequested()
 
5596
*/
 
5597
 
 
5598
void QWidget::contextMenuEvent(QContextMenuEvent *e)
 
5599
{
 
5600
    e->ignore();
 
5601
}
 
5602
 
 
5603
 
 
5604
/*!
 
5605
    This event handler, for event \a e, can be reimplemented in a
 
5606
    subclass to receive Input Method composition events. This handler
 
5607
    is called when the state of the input method changes.
 
5608
 
 
5609
    The default implementation calls e->ignore(), which rejects the
 
5610
    Input Method event. See the \l QInputMethodEvent documentation for more
 
5611
    details.
 
5612
 
 
5613
    \sa event(), QInputMethodEvent
 
5614
*/
 
5615
void QWidget::inputMethodEvent(QInputMethodEvent *e)
 
5616
{
 
5617
    e->ignore();
 
5618
}
 
5619
 
 
5620
/*!
 
5621
    This method is only relevant for input widgets. It is used by the
 
5622
    input method to query a set of properties of the widget to be
 
5623
    able to support complex input method operations as support for
 
5624
    surrounding text and reconversions.
 
5625
 
 
5626
    \a query specifies which property is queried.
 
5627
 
 
5628
    \sa inputMethodEvent(), QInputMethodEvent, QInputContext
 
5629
*/
 
5630
QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const
 
5631
{
 
5632
    switch(query) {
 
5633
    case Qt::ImMicroFocus:
 
5634
        return QRect(width()/2, 0, 1, height());
 
5635
    case Qt::ImFont:
 
5636
        return font();
 
5637
    default:
 
5638
        return QVariant();
 
5639
    }
 
5640
}
 
5641
 
 
5642
#ifndef QT_NO_DRAGANDDROP
 
5643
 
 
5644
/*!
 
5645
    \fn void QWidget::dragEnterEvent(QDragEnterEvent *event)
 
5646
 
 
5647
    This event handler is called when a drag is in progress and the
 
5648
    mouse enters this widget. The event is passed in the \a event parameter.
 
5649
 
 
5650
    See the \link dnd.html Drag-and-drop documentation\endlink for an
 
5651
    overview of how to provide drag-and-drop in your application.
 
5652
 
 
5653
    \sa QTextDrag, QImageDrag, QDragEnterEvent
 
5654
*/
 
5655
void QWidget::dragEnterEvent(QDragEnterEvent *)
 
5656
{
 
5657
}
 
5658
 
 
5659
/*!
 
5660
    \fn void QWidget::dragMoveEvent(QDragMoveEvent *event)
 
5661
 
 
5662
    This event handler is called if a drag is in progress, and when
 
5663
    any of the following conditions occurs: the cursor enters this widget,
 
5664
    the cursor moves within this widget, or a modifier key is pressed on
 
5665
    the keyboard while this widget has the focus. The event is passed
 
5666
    in the \a event parameter.
 
5667
 
 
5668
    See the \link dnd.html Drag-and-drop documentation\endlink for an
 
5669
    overview of how to provide drag-and-drop in your application.
 
5670
 
 
5671
    \sa QTextDrag, QImageDrag, QDragMoveEvent
 
5672
*/
 
5673
void QWidget::dragMoveEvent(QDragMoveEvent *)
 
5674
{
 
5675
}
 
5676
 
 
5677
/*!
 
5678
    \fn void QWidget::dragLeaveEvent(QDragLeaveEvent *event)
 
5679
 
 
5680
    This event handler is called when a drag is in progress and the
 
5681
    mouse leaves this widget. The event is passed in the \a event
 
5682
    parameter.
 
5683
 
 
5684
    See the \link dnd.html Drag-and-drop documentation\endlink for an
 
5685
    overview of how to provide drag-and-drop in your application.
 
5686
 
 
5687
    \sa QTextDrag, QImageDrag, QDragLeaveEvent
 
5688
*/
 
5689
void QWidget::dragLeaveEvent(QDragLeaveEvent *)
 
5690
{
 
5691
}
 
5692
 
 
5693
/*!
 
5694
    \fn void QWidget::dropEvent(QDropEvent *event)
 
5695
 
 
5696
    This event handler is called when the drag is dropped on this
 
5697
    widget which are passed in the \a event parameter.
 
5698
 
 
5699
    See the \link dnd.html Drag-and-drop documentation\endlink for an
 
5700
    overview of how to provide drag-and-drop in your application.
 
5701
 
 
5702
    \sa QTextDrag, QImageDrag, QDropEvent
 
5703
*/
 
5704
void QWidget::dropEvent(QDropEvent *)
 
5705
{
 
5706
}
 
5707
 
 
5708
#endif // QT_NO_DRAGANDDROP
 
5709
 
 
5710
/*!
 
5711
    \fn void QWidget::showEvent(QShowEvent *event)
 
5712
 
 
5713
    This event handler can be reimplemented in a subclass to receive
 
5714
    widget show events which are passed in the \a event parameter.
 
5715
 
 
5716
    Non-spontaneous show events are sent to widgets immediately
 
5717
    before they are shown. The spontaneous show events of windows are
 
5718
    delivered afterwards.
 
5719
 
 
5720
    Note: A widget receives spontaneous show and hide events when its
 
5721
    mapping status is changed by the window system, e.g. a spontaneous
 
5722
    hide event when the user minimizes the window, and a spontaneous
 
5723
    show event when the window is restored again. After receiving a
 
5724
    spontaneous hide event, a widget is still considered visible in
 
5725
    the sense of isVisible().
 
5726
 
 
5727
    \sa visible, event(), QShowEvent
 
5728
*/
 
5729
void QWidget::showEvent(QShowEvent *)
 
5730
{
 
5731
}
 
5732
 
 
5733
/*!
 
5734
    \fn void QWidget::hideEvent(QHideEvent *event)
 
5735
 
 
5736
    This event handler can be reimplemented in a subclass to receive
 
5737
    widget hide events. The event is passed in the \a event parameter.
 
5738
 
 
5739
    Hide events are sent to widgets immediately after they have been
 
5740
    hidden.
 
5741
 
 
5742
    Note: A widget receives spontaneous show and hide events when its
 
5743
    mapping status is changed by the window system, e.g. a spontaneous
 
5744
    hide event when the user minimizes the window, and a spontaneous
 
5745
    show event when the window is restored again. After receiving a
 
5746
    spontaneous hide event, a widget is still considered visible in
 
5747
    the sense of isVisible().
 
5748
 
 
5749
    \sa visible, event(), QHideEvent
 
5750
*/
 
5751
void QWidget::hideEvent(QHideEvent *)
 
5752
{
 
5753
}
 
5754
 
 
5755
/*
 
5756
    \fn QWidget::x11Event(MSG *)
 
5757
 
 
5758
    This special event handler can be reimplemented in a subclass to
 
5759
    receive native X11 events.
 
5760
 
 
5761
    In your reimplementation of this function, if you want to stop the
 
5762
    event being handled by Qt, return true. If you return false, this
 
5763
    native event is passed back to Qt, which translates the event into
 
5764
    a Qt event and sends it to the widget.
 
5765
 
 
5766
    \warning This function is not portable.
 
5767
 
 
5768
    \sa QApplication::x11EventFilter()
 
5769
*/
 
5770
 
 
5771
 
 
5772
#if defined(Q_WS_MAC)
 
5773
 
 
5774
/*!
 
5775
    \fn bool QWidget::macEvent(EventHandlerCallRef caller, EventRef event)
 
5776
 
 
5777
    This special event handler can be reimplemented in a subclass to
 
5778
    receive native Macintosh events which are passed from the \a
 
5779
    caller with the event details in the \a event parameter.
 
5780
 
 
5781
    In your reimplementation of this function, if you want to stop the
 
5782
    event being handled by Qt, return true. If you return false, this
 
5783
    native event is passed back to Qt, which translates the event into
 
5784
    a Qt event and sends it to the widget.
 
5785
 
 
5786
    \warning This function is not portable.
 
5787
 
 
5788
    \sa QApplication::macEventFilter()
 
5789
*/
 
5790
 
 
5791
bool QWidget::macEvent(EventHandlerCallRef, EventRef)
 
5792
{
 
5793
    return false;
 
5794
}
 
5795
 
 
5796
#endif
 
5797
#if defined(Q_WS_WIN)
 
5798
 
 
5799
/*!
 
5800
    This special event handler can be reimplemented in a subclass to
 
5801
    receive native Windows events which are passed in the \a message
 
5802
    parameter.
 
5803
 
 
5804
    In your reimplementation of this function, if you want to stop the
 
5805
    event being handled by Qt, return true and set \a result to the value
 
5806
    that the window procedure should return. If you return false, this
 
5807
    native event is passed back to Qt, which translates the event into
 
5808
    a Qt event and sends it to the widget.
 
5809
 
 
5810
    \warning This function is not portable.
 
5811
 
 
5812
    \sa QApplication::winEventFilter()
 
5813
*/
 
5814
bool QWidget::winEvent(MSG *message, long *result)
 
5815
{
 
5816
    Q_UNUSED(message);
 
5817
    Q_UNUSED(result);
 
5818
    return false;
 
5819
}
 
5820
 
 
5821
#endif
 
5822
#if defined(Q_WS_X11)
 
5823
 
 
5824
/*!
 
5825
    \fn bool QWidget::x11Event(XEvent *event)
 
5826
 
 
5827
    This special event handler can be reimplemented in a subclass to
 
5828
    receive native X11 events which are passed in the \a event
 
5829
    parameter.
 
5830
 
 
5831
    In your reimplementation of this function, if you want to stop the
 
5832
    event being handled by Qt, return true. If you return false, this
 
5833
    native event is passed back to Qt, which translates the event into
 
5834
    a Qt event and sends it to the widget.
 
5835
 
 
5836
    \warning This function is not portable.
 
5837
 
 
5838
    \sa QApplication::x11EventFilter()
 
5839
*/
 
5840
bool QWidget::x11Event(XEvent *)
 
5841
{
 
5842
    return false;
 
5843
}
 
5844
 
 
5845
#endif
 
5846
#if defined(Q_WS_QWS)
 
5847
 
 
5848
/*!
 
5849
    \fn bool QWidget::qwsEvent(QWSEvent *event)
 
5850
 
 
5851
    This special event handler can be reimplemented in a subclass to
 
5852
    receive native Qt/Embedded events which are passed in the \a event
 
5853
    parameter.
 
5854
 
 
5855
    In your reimplementation of this function, if you want to stop the
 
5856
    event being handled by Qt, return true. If you return false, this
 
5857
    native event is passed back to Qt, which translates the event into
 
5858
    a Qt event and sends it to the widget.
 
5859
 
 
5860
    \warning This function is not portable.
 
5861
 
 
5862
    \sa QApplication::qwsEventFilter()
 
5863
*/
 
5864
bool QWidget::qwsEvent(QWSEvent *)
 
5865
{
 
5866
    return false;
 
5867
}
 
5868
 
 
5869
#endif
 
5870
 
 
5871
 
 
5872
/*!
 
5873
    Ensures that the widget has been polished by QStyle (i.e., has a
 
5874
    proper font and palette).
 
5875
 
 
5876
    QWidget calls this function after it has been fully constructed but
 
5877
    before it is shown the very first time. You can call this function if you
 
5878
    want to ensure that the widget is polished before doing an operation
 
5879
    (e.g., the correct font size might be needed in the widget's sizeHint()
 
5880
    reimplementation).
 
5881
 
 
5882
    Polishing is useful for final initialization that must happen after
 
5883
    all constructors (from base classes as well as from subclasses)
 
5884
    have been called.
 
5885
 
 
5886
    If you need to change some settings when a widget is polished,
 
5887
    reimplement event() and handle the QEvent::Polish event type.
 
5888
 
 
5889
    Note: The function is declared const so that it can be called from
 
5890
    other const functions (e.g., sizeHint()).
 
5891
 
 
5892
    \sa event()
 
5893
*/
 
5894
void QWidget::ensurePolished() const
 
5895
{
 
5896
    Q_D(const QWidget);
 
5897
 
 
5898
    const QMetaObject *m = metaObject();
 
5899
    if (m == d->polished)
 
5900
        return;
 
5901
    d->polished = m;
 
5902
 
 
5903
    QEvent e(QEvent::Polish);
 
5904
    QCoreApplication::sendEvent(const_cast<QWidget *>(this), &e);
 
5905
 
 
5906
    // polish children after 'this'
 
5907
    QList<QObject*> children = d->children;
 
5908
    for (int i = 0; i < children.size(); ++i) {
 
5909
        QObject *o = children.at(i);
 
5910
        if(!o->isWidgetType())
 
5911
            continue;
 
5912
        if (QWidget *w = qobject_cast<QWidget *>(o))
 
5913
            w->ensurePolished();
 
5914
    }
 
5915
 
 
5916
    if (d->parent && d->sendChildEvents) {
 
5917
        QChildEvent e(QEvent::ChildPolished, const_cast<QWidget *>(this));
 
5918
        QCoreApplication::sendEvent(d->parent, &e);
 
5919
    }
 
5920
}
 
5921
 
 
5922
/*!
 
5923
    Returns the mask currently set on a widget. If no mask is set the
 
5924
    return value will be an empty region.
 
5925
 
 
5926
    \sa setMask(), clearMask(), QRegion::isEmpty()
 
5927
*/
 
5928
QRegion QWidget::mask() const
 
5929
{
 
5930
    Q_D(const QWidget);
 
5931
    return d->extra ? d->extra->mask : QRegion();
 
5932
}
 
5933
 
 
5934
#ifndef QT_NO_LAYOUT
 
5935
/*!
 
5936
    Returns the layout engine that manages the geometry of this
 
5937
    widget's children.
 
5938
 
 
5939
    If the widget does not have a layout, layout() returns 0.
 
5940
 
 
5941
    \sa  setLayout(), sizePolicy()
 
5942
*/
 
5943
QLayout* QWidget::layout() const
 
5944
{
 
5945
    return d_func()->layout;
 
5946
}
 
5947
 
 
5948
 
 
5949
/*!
 
5950
    Sets the layout engine for this widget to \a l.
 
5951
 
 
5952
    There can be only one top-level layout for a widget.
 
5953
 
 
5954
    \sa layout()
 
5955
*/
 
5956
 
 
5957
void QWidget::setLayout(QLayout *l)
 
5958
{
 
5959
    if (!l) {
 
5960
        qWarning("cannot set layout to 0");
 
5961
        return;
 
5962
    }
 
5963
    if (layout()) {
 
5964
        if (layout() != l)
 
5965
            qWarning("QWidget::setLayout() : QLayout \"%s\" added to %s \"%s\", which already has a"
 
5966
                     " layout", l->objectName().toLocal8Bit().data(), metaObject()->className(),
 
5967
                     objectName().toLocal8Bit().data());
 
5968
        return;
 
5969
    }
 
5970
    l->d_func()->topLevel = true;
 
5971
    d_func()->layout = l;
 
5972
    if (l->parent() != this) {
 
5973
        l->setParent(this);
 
5974
        l->d_func()->reparentChildWidgets(this);
 
5975
        l->invalidate();
 
5976
    }
 
5977
}
 
5978
 
 
5979
#endif
 
5980
 
 
5981
 
 
5982
/*!
 
5983
    \property QWidget::sizePolicy
 
5984
    \brief the default layout behavior of the widget
 
5985
 
 
5986
    If there is a QLayout that manages this widget's children, the
 
5987
    size policy specified by that layout is used. If there is no such
 
5988
    QLayout, the result of this function is used.
 
5989
 
 
5990
    The default policy is Preferred/Preferred, which means that the
 
5991
    widget can be freely resized, but prefers to be the size
 
5992
    sizeHint() returns. Button-like widgets set the size policy to
 
5993
    specify that they may stretch horizontally, but are fixed
 
5994
    vertically. The same applies to lineedit controls (such as
 
5995
    QLineEdit, QSpinBox or an editable QComboBox) and other
 
5996
    horizontally orientated widgets (such as QProgressBar).
 
5997
    QToolButton's are normally square, so they allow growth in both
 
5998
    directions. Widgets that support different directions (such as
 
5999
    QSlider, QScrollBar or QHeader) specify stretching in the
 
6000
    respective direction only. Widgets that can provide scrollbars
 
6001
    (usually subclasses of QScrollView) tend to specify that they can
 
6002
    use additional space, and that they can make do with less than
 
6003
    sizeHint().
 
6004
 
 
6005
    \sa sizeHint() QLayout QSizePolicy updateGeometry()
 
6006
*/
 
6007
QSizePolicy QWidget::sizePolicy() const
 
6008
{
 
6009
    Q_D(const QWidget);
 
6010
    // GCC 2.95.x on FreeBSD can't handle this as a turnary operator.
 
6011
    if (d->extra)
 
6012
        return d->extra->size_policy;
 
6013
    return QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
 
6014
}
 
6015
 
 
6016
void QWidget::setSizePolicy(QSizePolicy policy)
 
6017
{
 
6018
    setAttribute(Qt::WA_WState_OwnSizePolicy);
 
6019
    if (policy == sizePolicy())
 
6020
        return;
 
6021
 
 
6022
    Q_D(QWidget);
 
6023
    d->createExtra();
 
6024
    d->extra->size_policy = policy;
 
6025
    updateGeometry();
 
6026
}
 
6027
 
 
6028
/*!
 
6029
    \fn void QWidget::setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
6030
    \overload
 
6031
 
 
6032
    Sets the size policy of the widget to \a horizontal and \a
 
6033
    vertical, with standard stretch and no height-for-width.
 
6034
 
 
6035
    \sa QSizePolicy::QSizePolicy()
 
6036
*/
 
6037
 
 
6038
/*!
 
6039
    Returns the preferred height for this widget, given the width \a w.
 
6040
 
 
6041
    If this widget has a layout, the default implementation returns
 
6042
    the layout's preferred height.  if there is no layout, the default
 
6043
    implementation returns -1 indicating that the preferred height
 
6044
    does not depend on the width.
 
6045
*/
 
6046
 
 
6047
int QWidget::heightForWidth(int w) const
 
6048
{
 
6049
#ifndef QT_NO_LAYOUT
 
6050
    if (layout() && layout()->hasHeightForWidth())
 
6051
        return layout()->totalHeightForWidth(w);
 
6052
#endif
 
6053
    return -1;
 
6054
}
 
6055
 
 
6056
/*!
 
6057
    \fn QWidget *QWidget::childAt(int x, int y) const
 
6058
 
 
6059
    Returns the visible child widget at the position (\a{x}, \a{y})
 
6060
    in the widget's coordinate system. If there is no visible child
 
6061
    widget at the specified position, the function returns 0.
 
6062
*/
 
6063
 
 
6064
/*!
 
6065
    \overload
 
6066
 
 
6067
    Returns the visible child widget at point \a p in the widget's own
 
6068
    coordinate system.
 
6069
*/
 
6070
 
 
6071
QWidget *QWidget::childAt(const QPoint &p) const
 
6072
{
 
6073
    if (!rect().contains(p))
 
6074
        return 0;
 
6075
    Q_D(const QWidget);
 
6076
    for (int i = d->children.size(); i > 0 ;) {
 
6077
        --i;
 
6078
        QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
 
6079
        if (w && !w->isWindow() && !w->isHidden() && w->geometry().contains(p)) {
 
6080
            if (w->testAttribute(Qt::WA_TransparentForMouseEvents))
 
6081
                continue;
 
6082
            if (QWidget *t = w->childAt(p.x() - w->x(), p.y() - w->y()))
 
6083
                return t;
 
6084
            // if WMouseNoMask is set the widget mask is ignored, if
 
6085
            // the widget has no mask then the WMouseNoMask flag has no
 
6086
            // effect
 
6087
            if (w->testAttribute(Qt::WA_MouseNoMask) || w->mask().contains(p)
 
6088
                || w->mask().isEmpty())
 
6089
                return w;
 
6090
        }
 
6091
    }
 
6092
    return 0;
 
6093
}
 
6094
 
 
6095
 
 
6096
/*!
 
6097
    Notifies the layout system that this widget has changed and may
 
6098
    need to change geometry.
 
6099
 
 
6100
    Call this function if the sizeHint() or sizePolicy() have changed.
 
6101
 
 
6102
    For explicitly hidden widgets, updateGeometry() is a no-op. The
 
6103
    layout system will be notified as soon as the widget is shown.
 
6104
*/
 
6105
 
 
6106
void QWidget::updateGeometry()
 
6107
{
 
6108
#ifndef QT_NO_LAYOUT
 
6109
    if (!isWindow() && !isHidden() && parentWidget()) {
 
6110
        if (parentWidget()->d_func()->layout)
 
6111
            parentWidget()->d_func()->layout->invalidate();
 
6112
        else if (parentWidget()->isVisible())
 
6113
            QApplication::postEvent(parentWidget(), new QEvent(QEvent::LayoutRequest));
 
6114
    }
 
6115
#endif
 
6116
}
 
6117
 
 
6118
/*! \property QWidget::windowFlags
 
6119
 
 
6120
    Window flags are a combination of a type (e.g. Qt::Dialog) and
 
6121
    zero or more hints to the window system (e.g.
 
6122
    Qt::FramelessWindowHint).
 
6123
 
 
6124
    If the widget had type Qt::Widget or Qt::SubWindow and becomes a
 
6125
    window (Qt::Window, Qt::Dialog, etc.), it is put at position (0,
 
6126
    0) on the desktop. If the widget is a window and becomes a
 
6127
    Qt::Widget or Qt::SubWindow, it is put at position (0, 0)
 
6128
    relative to its parent widget.
 
6129
 
 
6130
    \sa windowType()
 
6131
*/
 
6132
void QWidget::setWindowFlags(Qt::WindowFlags flags)
 
6133
{
 
6134
    if (data->window_flags == flags)
 
6135
        return;
 
6136
 
 
6137
    if ((data->window_flags | flags) & Qt::Window) {
 
6138
        // the old type was a window and/or the new type is a window
 
6139
        QPoint oldPos = pos();
 
6140
        setParent(parentWidget(), flags);
 
6141
 
 
6142
        // if both types are windows or neither of them are, we restore
 
6143
        // the old position
 
6144
        if (!((data->window_flags ^ flags) & Qt::Window))
 
6145
            move(oldPos);
 
6146
    } else {
 
6147
        data->window_flags = flags;
 
6148
    }
 
6149
}
 
6150
 
 
6151
/*!
 
6152
    Sets the window flags for the widget to \a flags,
 
6153
    \e without telling the window system.
 
6154
 
 
6155
    \warning Do not call this function unless you really know what
 
6156
    you're doing.
 
6157
 
 
6158
    \sa setWindowFlags()
 
6159
*/
 
6160
void QWidget::overrideWindowFlags(Qt::WindowFlags flags)
 
6161
{
 
6162
    data->window_flags = flags;
 
6163
}
 
6164
 
 
6165
/*!
 
6166
    \fn Qt::WindowType QWidget::windowType() const
 
6167
 
 
6168
    Returns the window type of this widget. This is identical to
 
6169
    windowFlags() & Qt::WindowType_Mask.
 
6170
 
 
6171
    \sa windowFlags
 
6172
*/
 
6173
 
 
6174
/*!
 
6175
    Sets the parent of the widget to \a parent. The widget is moved
 
6176
    to position (0, 0) in its new parent.
 
6177
 
 
6178
    If the new parent widget is in a different window, the
 
6179
    reparented widget and its children are appended to the end of the
 
6180
    \l{setFocusPolicy()}{tab chain} of the new parent
 
6181
    widget, in the same internal order as before. If one of the moved
 
6182
    widgets had keyboard focus, setParent() calls clearFocus() for that
 
6183
    widget.
 
6184
 
 
6185
    If the new parent widget is in the same window as the
 
6186
    old parent, setting the parent doesn't change the tab order or
 
6187
    keyboard focus.
 
6188
 
 
6189
    If the "new" parent widget is the old parent widget, this function
 
6190
    does nothing.
 
6191
 
 
6192
    \warning It is very unlikely that you will ever need this
 
6193
    function. If you have a widget that changes its content
 
6194
    dynamically, it is far easier to use \l QStackedWidget.
 
6195
 
 
6196
    \sa setWindowFlags()
 
6197
*/
 
6198
void QWidget::setParent(QWidget *parent)
 
6199
{
 
6200
    if (parent == parentWidget())
 
6201
        return;
 
6202
    setParent((QWidget*)parent, windowFlags() & ~Qt::WindowType_Mask);
 
6203
}
 
6204
 
 
6205
/*!
 
6206
    \overload
 
6207
 
 
6208
    This function also takes widget flags, \a f as an argument.
 
6209
*/
 
6210
 
 
6211
void QWidget::setParent(QWidget *parent, Qt::WFlags f)
 
6212
{
 
6213
    Q_D(QWidget);
 
6214
    bool resized = testAttribute(Qt::WA_Resized);
 
6215
    QWidget *oldtlw = window();
 
6216
    bool newParent = (parent != parentWidget());
 
6217
 
 
6218
    if (newParent) {
 
6219
        QEvent e(QEvent::ParentAboutToChange);
 
6220
        QApplication::sendEvent(this, &e);
 
6221
    }
 
6222
 
 
6223
    d->setParent_sys(parent, f);
 
6224
    d->reparentFocusWidgets(oldtlw);
 
6225
    setAttribute(Qt::WA_Resized, resized);
 
6226
    d->resolveFont();
 
6227
    d->resolvePalette();
 
6228
    d->resolveLayoutDirection();
 
6229
 
 
6230
    if (newParent) {
 
6231
        // send and post remaining QObject events
 
6232
        if (parent && d->sendChildEvents) {
 
6233
            QChildEvent e(QEvent::ChildAdded, this);
 
6234
            QApplication::sendEvent(parent, &e);
 
6235
#ifdef QT3_SUPPORT
 
6236
            QApplication::postEvent(parent, new QChildEvent(QEvent::ChildInserted, this));
 
6237
#endif
 
6238
        }
 
6239
 
 
6240
        if (parent && d->sendChildEvents && d->polished) {
 
6241
            QChildEvent e(QEvent::ChildPolished, this);
 
6242
            QCoreApplication::sendEvent(parent, &e);
 
6243
        }
 
6244
        QEvent e(QEvent::ParentChange);
 
6245
        QApplication::sendEvent(this, &e);
 
6246
    }
 
6247
}
 
6248
 
 
6249
/*!
 
6250
    Repaints the widget directly by calling paintEvent() immediately,
 
6251
    unless updates are disabled or the widget is hidden.
 
6252
 
 
6253
    We suggest only using repaint() if you need an immediate repaint,
 
6254
    for example during animation. In almost all circumstances update()
 
6255
    is better, as it permits Qt to optimize for speed and minimize
 
6256
    flicker.
 
6257
 
 
6258
    \warning If you call repaint() in a function which may itself be
 
6259
    called from paintEvent(), you may get infinite recursion. The
 
6260
    update() function never causes recursion.
 
6261
 
 
6262
    \sa update(), paintEvent(), setUpdatesEnabled()
 
6263
*/
 
6264
 
 
6265
void QWidget::repaint()
 
6266
{
 
6267
    Q_D(QWidget);
 
6268
#if defined(Q_WS_X11)
 
6269
//     d->removePendingPaintEvents(); // ### this is far too slow to go in
 
6270
#endif
 
6271
    repaint(d->clipRect());
 
6272
}
 
6273
 
 
6274
/*! \overload
 
6275
 
 
6276
    This version repaints a rectangle (\a x, \a y, \a w, \a h) inside
 
6277
    the widget.
 
6278
 
 
6279
    If \a w is negative, it is replaced with \c{width() - x}, and if
 
6280
    \a h is negative, it is replaced width \c{height() - y}.
 
6281
*/
 
6282
void QWidget::repaint(int x, int y, int w, int h)
 
6283
{
 
6284
    if (x > data->crect.width() || y > data->crect.height())
 
6285
        return;
 
6286
 
 
6287
    Q_D(QWidget);
 
6288
    if (w < 0)
 
6289
        w = data->crect.width()  - x;
 
6290
    if (h < 0)
 
6291
        h = data->crect.height() - y;
 
6292
    repaint(d->clipRect().intersect(QRect(x, y, w, h)));
 
6293
}
 
6294
 
 
6295
/*! \overload
 
6296
 
 
6297
    This version repaints a rectangle \a r inside the widget.
 
6298
*/
 
6299
void QWidget::repaint(const QRect &r)
 
6300
{
 
6301
    Q_D(QWidget);
 
6302
    repaint(QRegion(d->clipRect().intersect(r)));
 
6303
}
 
6304
 
 
6305
/*! \fn void QWidget::repaint(const QRegion &rgn)
 
6306
    \overload
 
6307
 
 
6308
    This version repaints a region \a rgn inside the widget.
 
6309
*/
 
6310
 
 
6311
/*! \fn void QWidget::update()
 
6312
    Updates the widget unless updates are disabled or the widget is
 
6313
    hidden.
 
6314
 
 
6315
    This function does not cause an immediate repaint; instead it
 
6316
    schedules a paint event for processing when Qt returns to the main
 
6317
    event loop. This permits Qt to optimize for more speed and less
 
6318
    flicker than a call to repaint() does.
 
6319
 
 
6320
    Calling update() several times normally results in just one
 
6321
    paintEvent() call.
 
6322
 
 
6323
    Qt normally erases the widget's area before the paintEvent() call.
 
6324
    If the \c Qt::WRepaintNoErase widget flag is set, the widget is
 
6325
    responsible for painting all its pixels itself.
 
6326
 
 
6327
    \sa repaint() paintEvent(), setUpdatesEnabled()
 
6328
*/
 
6329
 
 
6330
/*! \fn void QWidget::update(int x, int y, int w, int h)
 
6331
    \overload
 
6332
 
 
6333
    This version updates a rectangle (\a x, \a y, \a w, \a h) inside
 
6334
    the widget.
 
6335
*/
 
6336
 
 
6337
 
 
6338
/*!
 
6339
    \fn void QWidget::update(const QRect &r)
 
6340
    \overload
 
6341
 
 
6342
    This version updates a rectangle \a r inside the widget.
 
6343
*/
 
6344
 
 
6345
/*! \fn void QWidget::update(const QRegion &rgn)
 
6346
    \overload
 
6347
 
 
6348
    This version repaints a region \a rgn inside the widget.
 
6349
*/
 
6350
 
 
6351
#ifdef QT3_SUPPORT
 
6352
/*!
 
6353
    Clear the rectangle at point (\a x, \a y) of width \a w and height
 
6354
    \a h.
 
6355
 
 
6356
    \warning This is best done in a paintEvent().
 
6357
*/
 
6358
void QWidget::erase_helper(int x, int y, int w, int h)
 
6359
{
 
6360
    if (testAttribute(Qt::WA_NoSystemBackground) || testAttribute(Qt::WA_UpdatesDisabled) ||  !testAttribute(Qt::WA_WState_Visible))
 
6361
        return;
 
6362
    if (w < 0)
 
6363
        w = data->crect.width()  - x;
 
6364
    if (h < 0)
 
6365
        h = data->crect.height() - y;
 
6366
    if (w != 0 && h != 0) {
 
6367
        QPainter p(this);
 
6368
        p.eraseRect(QRect(x, y, w, h));
 
6369
    }
 
6370
}
 
6371
 
 
6372
/*!
 
6373
    \overload
 
6374
 
 
6375
    Clear the given region, \a rgn.
 
6376
 
 
6377
    Drawing may only take place in a QPaintEvent. Overload
 
6378
    paintEvent() to do your erasing and call update() to schedule a
 
6379
    replaint whenever necessary. See also QPainter.
 
6380
*/
 
6381
void QWidget::erase(const QRegion& rgn)
 
6382
{
 
6383
    if (testAttribute(Qt::WA_NoSystemBackground) || testAttribute(Qt::WA_UpdatesDisabled) || !testAttribute(Qt::WA_WState_Visible))
 
6384
        return;
 
6385
 
 
6386
    QPainter p(this);
 
6387
    p.setClipRegion(rgn);
 
6388
    p.eraseRect(rgn.boundingRect());
 
6389
}
 
6390
 
 
6391
void QWidget::drawText_helper(int x, int y, const QString &str)
 
6392
{
 
6393
    if(!testAttribute(Qt::WA_WState_Visible))
 
6394
        return;
 
6395
    QPainter paint(this);
 
6396
    paint.drawText(x, y, str);
 
6397
}
 
6398
 
 
6399
 
 
6400
/*!
 
6401
    Closes the widget.
 
6402
 
 
6403
    Use the no-argument overload instead.
 
6404
*/
 
6405
bool QWidget::close(bool alsoDelete)
 
6406
{
 
6407
    QPointer<QWidget> that = this;
 
6408
    bool accepted = close();
 
6409
    if (alsoDelete && accepted && that)
 
6410
        deleteLater();
 
6411
    return accepted;
 
6412
}
 
6413
 
 
6414
void QWidget::setIcon(const QPixmap &i)
 
6415
{
 
6416
    setWindowIcon(i);
 
6417
}
 
6418
 
 
6419
/*!
 
6420
    Return's the widget's icon.
 
6421
 
 
6422
    Use windowIconText() instead().
 
6423
*/
 
6424
const QPixmap *QWidget::icon() const
 
6425
{
 
6426
    Q_D(const QWidget);
 
6427
    return (d->extra && d->extra->topextra) ? d->extra->topextra->iconPixmap : 0;
 
6428
}
 
6429
 
 
6430
#endif // QT3_SUPPORT
 
6431
 
 
6432
/*!
 
6433
    Sets the attribute \a attribute on this widget if \a on is true;
 
6434
    otherwise clears the attribute.
 
6435
 
 
6436
    \sa testAttribute()
 
6437
*/
 
6438
void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
 
6439
{
 
6440
    Q_D(QWidget);
 
6441
    Q_ASSERT_X(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8),
 
6442
               "QWidget::setAttribute(WidgetAttribute, bool)",
 
6443
               "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute");
 
6444
    if (attribute < int(8*sizeof(uint))) {
 
6445
        if (on)
 
6446
            data->widget_attributes |= (1<<attribute);
 
6447
        else
 
6448
            data->widget_attributes &= ~(1<<attribute);
 
6449
    } else {
 
6450
        const int x = attribute - 8*sizeof(uint);
 
6451
        const int int_off = x / (8*sizeof(uint));
 
6452
        if (on)
 
6453
            d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
 
6454
        else
 
6455
            d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
 
6456
    }
 
6457
    switch (attribute) {
 
6458
    case Qt::WA_NoChildEventsForParent:
 
6459
        d->sendChildEvents = !on;
 
6460
        break;
 
6461
    case Qt::WA_NoChildEventsFromChildren:
 
6462
        d->receiveChildEvents = !on;
 
6463
        break;
 
6464
    case Qt::WA_MacMetalStyle:
 
6465
#ifdef Q_WS_MAC
 
6466
        extern void qt_mac_update_metal_style(QWidget*); //qwidget_mac.cpp
 
6467
        qt_mac_update_metal_style(this);
 
6468
#endif
 
6469
        break;
 
6470
    case Qt::WA_MouseTracking: {
 
6471
        QEvent e(QEvent::MouseTrackingChange);
 
6472
        QApplication::sendEvent(this, &e);
 
6473
        break; }
 
6474
    case Qt::WA_NoSystemBackground:
 
6475
    case Qt::WA_UpdatesDisabled:
 
6476
        d->updateSystemBackground();
 
6477
        break;
 
6478
    case Qt::WA_TransparentForMouseEvents:
 
6479
#ifdef Q_WS_MAC
 
6480
        extern void qt_mac_update_ignore_mouseevents(QWidget*); //qwidget_mac.cpp
 
6481
        qt_mac_update_ignore_mouseevents(this);
 
6482
#endif
 
6483
        break;
 
6484
    case Qt::WA_ContentsPropagated:
 
6485
        if (isVisible())
 
6486
            d->updatePropagatedBackground();
 
6487
        break;
 
6488
#ifdef Q_WS_WIN
 
6489
    case Qt::WA_InputMethodEnabled:
 
6490
        QWinInputContext::enable(this, on);
 
6491
        break;
 
6492
#endif
 
6493
    default:
 
6494
        break;
 
6495
    }
 
6496
}
 
6497
 
 
6498
/*! \fn bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const
 
6499
 
 
6500
  Returns true if attribute \a attribute is set on this widget;
 
6501
  otherwise returns false.
 
6502
 
 
6503
  \sa setAttribute()
 
6504
 */
 
6505
bool QWidget::testAttribute_helper(Qt::WidgetAttribute attribute) const
 
6506
{
 
6507
    Q_D(const QWidget);
 
6508
    const int x = attribute - 8*sizeof(uint);
 
6509
    const int int_off = x / (8*sizeof(uint));
 
6510
    return (d->high_attributes[int_off] & (1<<(x-(int_off*8*sizeof(uint)))));
 
6511
}
 
6512
 
 
6513
/*!
 
6514
  \property QWidget::windowOpacity
 
6515
 
 
6516
  \brief The level of opacity for the window.
 
6517
 
 
6518
  The valid range of opacity is from 1.0 (completely opaque) to
 
6519
  0.0 (completely transparent).
 
6520
 
 
6521
  By default the value of this property is 1.0.
 
6522
 
 
6523
  This feature is only present on Mac OS X and Windows 2000 and up.
 
6524
 
 
6525
  \warning Changing this property from opaque to transparent might issue a
 
6526
  paint event that needs to be processed before the window is displayed
 
6527
  correctly. This affects mainly the use of QPixmap::grabWindow(). Also note
 
6528
  that semi-transparent windows update and resize significantly slower than
 
6529
  opaque windows.
 
6530
*/
 
6531
 
 
6532
/*!
 
6533
    \property QWidget::windowModified
 
6534
    \brief whether the document shown in the window has unsaved changes
 
6535
 
 
6536
    A modified window is a window whose content has changed but has
 
6537
    not been saved to disk. This flag will have different effects
 
6538
    varied by the platform. On Mac OS X the close button will have a
 
6539
    modified look; on other platforms, the window title will have an
 
6540
    '*' (asterisk).
 
6541
 
 
6542
    The window title must contain a "[*]" placeholder, which
 
6543
    indicates where the '*' should appear. Normally, it should appear
 
6544
    right after the file name (e.g., "document1.txt[*] - Text
 
6545
    Editor"). If the window isn't modified, the placeholder is simply
 
6546
    removed.
 
6547
 
 
6548
    \sa windowTitle
 
6549
*/
 
6550
bool QWidget::isWindowModified() const
 
6551
{
 
6552
    return testAttribute(Qt::WA_WindowModified);
 
6553
}
 
6554
 
 
6555
void QWidget::setWindowModified(bool mod)
 
6556
{
 
6557
    Q_D(QWidget);
 
6558
    setAttribute(Qt::WA_WindowModified, mod);
 
6559
 
 
6560
    if (!windowTitle().contains("[*]") && mod)
 
6561
        qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder!");
 
6562
    d->setWindowTitle_helper(windowTitle());
 
6563
    d->setWindowIconText_helper(windowIconText());
 
6564
#ifdef Q_WS_MAC
 
6565
    d->setWindowModified_sys(mod);
 
6566
#endif
 
6567
 
 
6568
    QEvent e(QEvent::ModifiedChange);
 
6569
    QApplication::sendEvent(this, &e);
 
6570
}
 
6571
 
 
6572
/*!
 
6573
  \property QWidget::toolTip
 
6574
 
 
6575
  \brief the widget's tooltip
 
6576
 
 
6577
  \sa QToolTip statusTip whatsThis
 
6578
*/
 
6579
void QWidget::setToolTip(const QString &s)
 
6580
{
 
6581
    Q_D(QWidget);
 
6582
    d->toolTip = s;
 
6583
}
 
6584
 
 
6585
QString QWidget::toolTip() const
 
6586
{
 
6587
    Q_D(const QWidget);
 
6588
    return d->toolTip;
 
6589
}
 
6590
 
 
6591
/*!
 
6592
  \property QWidget::statusTip
 
6593
 
 
6594
  \brief the widget's status tip
 
6595
 
 
6596
  \sa toolTip whatsThis
 
6597
*/
 
6598
void QWidget::setStatusTip(const QString &s)
 
6599
{
 
6600
    Q_D(QWidget);
 
6601
    d->statusTip = s;
 
6602
}
 
6603
 
 
6604
QString QWidget::statusTip() const
 
6605
{
 
6606
    Q_D(const QWidget);
 
6607
    return d->statusTip;
 
6608
}
 
6609
 
 
6610
/*!
 
6611
  \property QWidget::whatsThis
 
6612
 
 
6613
  \brief the widget's What's This help text.
 
6614
 
 
6615
  \sa QWhatsThis QWidget::toolTip QWidget::statusTip
 
6616
*/
 
6617
void QWidget::setWhatsThis(const QString &s)
 
6618
{
 
6619
    Q_D(QWidget);
 
6620
    d->whatsThis = s;
 
6621
}
 
6622
 
 
6623
QString QWidget::whatsThis() const
 
6624
{
 
6625
    Q_D(const QWidget);
 
6626
    return d->whatsThis;
 
6627
}
 
6628
 
 
6629
#ifndef QT_NO_ACCESSIBILITY
 
6630
/*!
 
6631
  \property QWidget::accessibleName
 
6632
 
 
6633
  \brief the widget's name as seen by assistive technologies
 
6634
 
 
6635
  \sa QAccessibleInterface::text()
 
6636
*/
 
6637
void QWidget::setAccessibleName(const QString &name)
 
6638
{
 
6639
    Q_D(QWidget);
 
6640
    d->accessibleName = name;
 
6641
}
 
6642
 
 
6643
QString QWidget::accessibleName() const
 
6644
{
 
6645
    Q_D(const QWidget);
 
6646
    return d->accessibleName;
 
6647
}
 
6648
 
 
6649
/*!
 
6650
  \property QWidget::accessibleDescription
 
6651
 
 
6652
  \brief the widget's description as seen by assistive technologies
 
6653
 
 
6654
  \sa QAccessibleInterface::text()
 
6655
*/
 
6656
void QWidget::setAccessibleDescription(const QString &description)
 
6657
{
 
6658
    Q_D(QWidget);
 
6659
    d->accessibleDescription = description;
 
6660
}
 
6661
 
 
6662
QString QWidget::accessibleDescription() const
 
6663
{
 
6664
    Q_D(const QWidget);
 
6665
    return d->accessibleDescription;
 
6666
}
 
6667
#endif
 
6668
 
 
6669
/*!
 
6670
    Adds a shortcut to Qt's shortcut system that watches for the given
 
6671
    \a key sequence in the given \a context. If the \a context is not
 
6672
    \c OnApplication, the shortcut is local to this widget; otherwise
 
6673
    it applies to the application as a whole.
 
6674
 
 
6675
    If the same \a key sequence has been grabbed by several widgets,
 
6676
    when the \a key sequence occurs a QEvent::Shortcut event is sent
 
6677
    to all the widgets to which it applies in a non-deterministic
 
6678
    order, but with the ``ambiguous'' flag set to true.
 
6679
 
 
6680
    \warning You should not normally need to use this function;
 
6681
    instead create \l{QAction}s with the shortcut key sequences you
 
6682
    require (if you also want equivalent menu options and toolbar
 
6683
    buttons), or create \l{QShortcut}s if you just need key sequences.
 
6684
    Both QAction and QShortcut handle all the event filtering for you,
 
6685
    and provide signals which are triggered when the user triggers the
 
6686
    key sequence, so are much easier to use than this low-level
 
6687
    function.
 
6688
 
 
6689
    \sa releaseShortcut() setShortcutEnabled()
 
6690
*/
 
6691
int QWidget::grabShortcut(const QKeySequence &key, Qt::ShortcutContext context)
 
6692
{
 
6693
    Q_ASSERT(qApp);
 
6694
    if (key.isEmpty())
 
6695
        return 0;
 
6696
    setAttribute(Qt::WA_GrabbedShortcut);
 
6697
    return qApp->d_func()->shortcutMap.addShortcut(this, key, context);
 
6698
}
 
6699
 
 
6700
 
 
6701
/*!
 
6702
    Removes the shortcut with the given \a id from Qt's shortcut
 
6703
    system. The widget will no longer receive QEvent::Shortcut events
 
6704
    for the shortcut's key sequence (unless it has other shortcuts
 
6705
    with the same key sequence).
 
6706
 
 
6707
    \warning You should not normally need to use this function since
 
6708
    Qt's shortcut system removes shortcuts automatically when their
 
6709
    parent widget is destroyed. It is best to use QAction or
 
6710
    QShortcut to handle shortcuts, since they are easier to use than
 
6711
    this low-level function. Note also that this is an expensive
 
6712
    operation.
 
6713
 
 
6714
    \sa grabShortcut() setShortcutEnabled()
 
6715
*/
 
6716
void QWidget::releaseShortcut(int id)
 
6717
{
 
6718
    Q_ASSERT(qApp);
 
6719
    if (id)
 
6720
        qApp->d_func()->shortcutMap.removeShortcut(id, this, 0);
 
6721
}
 
6722
 
 
6723
/*!
 
6724
    If \a enable is true, the shortcut with the given \a id is
 
6725
    enabled; otherwise the shortcut is disabled.
 
6726
 
 
6727
    \warning You should not normally need to use this function since
 
6728
    Qt's shortcut system enables/disables shortcuts automatically as
 
6729
    widgets become hidden/visible and gain or lose focus. It is best
 
6730
    to use QAction or QShortcut to handle shortcuts, since they are
 
6731
    easier to use than this low-level function.
 
6732
 
 
6733
    \sa grabShortcut() releaseShortcut()
 
6734
*/
 
6735
void QWidget::setShortcutEnabled(int id, bool enable)
 
6736
{
 
6737
    Q_ASSERT(qApp);
 
6738
    if (id)
 
6739
        qApp->d_func()->shortcutMap.setShortcutEnabled(enable, id, this, 0);
 
6740
}
 
6741
 
 
6742
 
 
6743
/*!
 
6744
    Updates the widget's micro focus.
 
6745
 
 
6746
    \sa QInputContext
 
6747
*/
 
6748
void QWidget::updateMicroFocus()
 
6749
{
 
6750
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
 
6751
    QInputContext *ic = inputContext();
 
6752
    if (ic)
 
6753
        ic->update();
 
6754
#endif
 
6755
#ifndef QT_NO_ACCESSIBILITY
 
6756
    // ##### is this correct
 
6757
    QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged);
 
6758
#endif
 
6759
}
 
6760
 
 
6761
 
 
6762
#if defined (Q_WS_WIN)
 
6763
/*!
 
6764
    Returns the window system handle of the widget, for low-level
 
6765
    access. Using this function is not portable.
 
6766
 
 
6767
    An HDC aquired with getDC() has to be released with releaseDC().
 
6768
 
 
6769
    \warning Using this function is not portable.
 
6770
*/
 
6771
HDC QWidget::getDC() const
 
6772
{
 
6773
    Q_D(const QWidget);
 
6774
    return (HDC) d->hd;
 
6775
}
 
6776
 
 
6777
/*!
 
6778
    Releases the HDC \a hdc aquired by a previous call to getDC().
 
6779
 
 
6780
    \warning Using this function is not portable.
 
6781
*/
 
6782
void QWidget::releaseDC(HDC hdc) const
 
6783
{
 
6784
    Q_D(const QWidget);
 
6785
    Q_ASSERT(d->hd == hdc);
 
6786
}
 
6787
#else
 
6788
/*!
 
6789
    Returns the window system handle of the widget, for low-level
 
6790
    access. Using this function is not portable.
 
6791
 
 
6792
    The HANDLE type varies with platform; see \c qwindowdefs.h for
 
6793
    details.
 
6794
*/
 
6795
Qt::HANDLE QWidget::handle() const
 
6796
{
 
6797
    Q_D(const QWidget);
 
6798
    return d->hd;
 
6799
}
 
6800
#endif
 
6801
 
 
6802
 
 
6803
/*!
 
6804
    Raises this widget to the top of the parent widget's stack.
 
6805
 
 
6806
    After this call the widget will be visually in front of any
 
6807
    overlapping sibling widgets.
 
6808
 
 
6809
    \sa lower(), stackUnder()
 
6810
*/
 
6811
 
 
6812
void QWidget::raise()
 
6813
{
 
6814
    Q_D(QWidget);
 
6815
    QWidget *p = parentWidget();
 
6816
    int from;
 
6817
    if (p && (from = p->d_func()->children.indexOf(this)) >= 0)
 
6818
        p->d_func()->children.move(from, p->d_func()->children.size() - 1);
 
6819
    d->raise_sys();
 
6820
 
 
6821
    QEvent e(QEvent::ZOrderChange);
 
6822
    QApplication::sendEvent(this, &e);
 
6823
}
 
6824
 
 
6825
/*!
 
6826
    Lowers the widget to the bottom of the parent widget's stack.
 
6827
 
 
6828
    After this call the widget will be visually behind (and therefore
 
6829
    obscured by) any overlapping sibling widgets.
 
6830
 
 
6831
    \sa raise(), stackUnder()
 
6832
*/
 
6833
 
 
6834
void QWidget::lower()
 
6835
{
 
6836
    Q_D(QWidget);
 
6837
    QWidget *p = parentWidget();
 
6838
    int from;
 
6839
    if (p && (from = p->d_func()->children.indexOf(this)) >= 0)
 
6840
        p->d_func()->children.move(from, 0);
 
6841
    d->lower_sys();
 
6842
 
 
6843
    QEvent e(QEvent::ZOrderChange);
 
6844
    QApplication::sendEvent(this, &e);
 
6845
}
 
6846
 
 
6847
 
 
6848
/*!
 
6849
    Places the widget under \a w in the parent widget's stack.
 
6850
 
 
6851
    To make this work, the widget itself and \a w must be siblings.
 
6852
 
 
6853
    \sa raise(), lower()
 
6854
*/
 
6855
void QWidget::stackUnder(QWidget* w)
 
6856
{
 
6857
    Q_D(QWidget);
 
6858
    QWidget *p = parentWidget();
 
6859
    int from;
 
6860
    int to;
 
6861
    if (!w || isWindow() || p != w->parentWidget() || this == w)
 
6862
        return;
 
6863
    if (p && (to = p->d_func()->children.indexOf(w)) >= 0 && (from = p->d_func()->children.indexOf(this)) >= 0) {
 
6864
        if (from < to)
 
6865
            --to;
 
6866
        p->d_func()->children.move(from, to);
 
6867
    }
 
6868
    d->stackUnder_sys(w);
 
6869
 
 
6870
    QEvent e(QEvent::ZOrderChange);
 
6871
    QApplication::sendEvent(this, &e);
 
6872
}
 
6873
 
 
6874
void QWidget::styleChange(QStyle&) { }
 
6875
void QWidget::enabledChange(bool) { }  // compat
 
6876
void QWidget::paletteChange(const QPalette &) { }  // compat
 
6877
void QWidget::fontChange(const QFont &) { }  // compat
 
6878
void QWidget::windowActivationChange(bool) { }  // compat
 
6879
void QWidget::languageChange() { }  // compat
 
6880
 
 
6881
 
 
6882
/*!
 
6883
    \property QWidget::visibleRect
 
6884
    \brief holds the widget's visible rectangle
 
6885
 
 
6886
    \compat
 
6887
*/
 
6888
 
 
6889
/*!
 
6890
    \enum QWidget::BackgroundOrigin
 
6891
 
 
6892
    \compat
 
6893
 
 
6894
    \value WidgetOrigin
 
6895
    \value ParentOrigin
 
6896
    \value WindowOrigin
 
6897
    \value AncestorOrigin
 
6898
 
 
6899
*/
 
6900
 
 
6901
/*!
 
6902
    \fn bool QWidget::isVisibleToTLW() const
 
6903
 
 
6904
    Use isVisible() instead.
 
6905
*/
 
6906
 
 
6907
/*!
 
6908
    \fn void QWidget::iconify()
 
6909
 
 
6910
    Use showMinimized() instead.
 
6911
*/
 
6912
 
 
6913
/*!
 
6914
    \fn void QWidget::constPolish() const
 
6915
 
 
6916
    Use ensurePolished() instead.
 
6917
*/
 
6918
 
 
6919
/*!
 
6920
    \fn void QWidget::reparent(QWidget *parent, Qt::WFlags f, const QPoint &p, bool showIt)
 
6921
 
 
6922
    Use setParent() to change the parent or the widget's widget flags;
 
6923
    use move() to move the widget, and use show() to show the widget.
 
6924
*/
 
6925
 
 
6926
/*!
 
6927
    \fn void QWidget::reparent(QWidget *parent, const QPoint &p, bool showIt)
 
6928
 
 
6929
    Use setParent() to change the parent; use move() to move the
 
6930
    widget, and use show() to show the widget.
 
6931
*/
 
6932
 
 
6933
/*!
 
6934
    \fn void QWidget::recreate(QWidget *parent, Qt::WFlags f, const QPoint & p, bool showIt)
 
6935
 
 
6936
    Use setParent() to change the parent or the widget's widget flags;
 
6937
    use move() to move the widget, and use show() to show the widget.
 
6938
*/
 
6939
 
 
6940
/*!
 
6941
    \fn bool QWidget::hasMouse() const
 
6942
 
 
6943
    Use testAttribute(Qt::WA_UnderMouse) instead.
 
6944
*/
 
6945
 
 
6946
/*!
 
6947
    \fn bool QWidget::ownCursor() const
 
6948
 
 
6949
    Use testAttribute(Qt::WA_SetCursor) instead.
 
6950
*/
 
6951
 
 
6952
/*!
 
6953
    \fn bool QWidget::ownFont() const
 
6954
 
 
6955
    Use testAttribute(Qt::WA_SetFont) instead.
 
6956
*/
 
6957
 
 
6958
/*!
 
6959
    \fn void QWidget::unsetFont()
 
6960
 
 
6961
    Use setFont(QFont()) instead.
 
6962
*/
 
6963
 
 
6964
/*!
 
6965
    \fn bool QWidget::ownPalette() const
 
6966
 
 
6967
    Use testAttribute(Qt::WA_SetPalette) instead.
 
6968
*/
 
6969
 
 
6970
/*!
 
6971
    \fn void QWidget::unsetPalette()
 
6972
 
 
6973
    Use setPalette(QPalette()) instead.
 
6974
*/
 
6975
 
 
6976
/*!
 
6977
    \fn void QWidget::setEraseColor(const QColor &color)
 
6978
 
 
6979
    Use the palette instead.
 
6980
 
 
6981
    \oldcode
 
6982
    widget->setEraseColor(color);
 
6983
    \newcode
 
6984
    QPalette palette;
 
6985
    palette.setColor(widget->backgroundRole(), color);
 
6986
    widget->setPalette(palette);
 
6987
    \endcode
 
6988
*/
 
6989
 
 
6990
/*!
 
6991
    \fn void QWidget::setErasePixmap(const QPixmap &pixmap)
 
6992
 
 
6993
    Use the palette instead.
 
6994
 
 
6995
    \oldcode
 
6996
    widget->setErasePixmap(pixmap);
 
6997
    \newcode
 
6998
    QPalette palette;
 
6999
    palette.setBrush(widget->backgroundRole(), QBrush(pixmap));
 
7000
    widget->setPalette(palette);
 
7001
    \endcode
 
7002
*/
 
7003
 
 
7004
/*!
 
7005
    \fn void QWidget::setPaletteForegroundColor(const QColor &color)
 
7006
 
 
7007
    Use the palette directly.
 
7008
 
 
7009
    \oldcode
 
7010
    widget->setPaletteForegroundColor(color);
 
7011
    \newcode
 
7012
    QPalette palette;
 
7013
    palette.setColor(widget->foregroundRole(), color);
 
7014
    widget->setPalette(palette);
 
7015
    \endcode
 
7016
*/
 
7017
 
 
7018
/*!
 
7019
    \fn void QWidget::setPaletteBackgroundColor(const QColor &color)
 
7020
 
 
7021
    Use the palette directly.
 
7022
 
 
7023
    \oldcode
 
7024
    widget->setPaletteBackgroundColor(color);
 
7025
    \newcode
 
7026
    QPalette palette;
 
7027
    palette.setColor(widget->backgroundRole(), color);
 
7028
    widget->setPalette(palette);
 
7029
    \endcode
 
7030
*/
 
7031
 
 
7032
/*!
 
7033
    \fn void QWidget::setPaletteBackgroundPixmap(const QPixmap &pixmap)
 
7034
 
 
7035
    Use the palette directly.
 
7036
 
 
7037
    \oldcode
 
7038
    widget->setPaletteBackgroundPixmap(pixmap);
 
7039
    \newcode
 
7040
    QPalette palette;
 
7041
    palette.setBrush(widget->backgroundRole(), QBrush(pixmap));
 
7042
    widget->setPalette(palette);
 
7043
    \endcode
 
7044
*/
 
7045
 
 
7046
/*!
 
7047
    \fn void QWidget::setBackgroundPixmap(const QPixmap &pixmap)
 
7048
 
 
7049
    Use the palette instead.
 
7050
 
 
7051
    \oldcode
 
7052
    widget->setBackgroundPixmap(pixmap);
 
7053
    \newcode
 
7054
    QPalette palette;
 
7055
    palette.setBrush(widget->backgroundRole(), QBrush(pixmap));
 
7056
    widget->setPalette(palette);
 
7057
    \endcode
 
7058
*/
 
7059
 
 
7060
/*!
 
7061
    \fn void QWidget::setBackgroundColor(const QColor &color)
 
7062
 
 
7063
    Use the palette instead.
 
7064
 
 
7065
    \oldcode
 
7066
    widget->setBackgroundColor(color);
 
7067
    \newcode
 
7068
    QPalette palette;
 
7069
    palette.setColor(widget->backgroundRole(), color);
 
7070
    widget->setPalette(palette);
 
7071
    \endcode
 
7072
*/
 
7073
 
 
7074
/*!
 
7075
    \fn QColorGroup QWidget::colorGroup() const
 
7076
 
 
7077
    Use QColorGroup(palette()) instead.
 
7078
*/
 
7079
 
 
7080
/*!
 
7081
    \fn QWidget *QWidget::parentWidget(bool sameWindow) const
 
7082
 
 
7083
    Use the no-argument overload instead.
 
7084
*/
 
7085
 
 
7086
/*!
 
7087
    \fn void QWidget::setKeyCompression(bool b)
 
7088
 
 
7089
    Use setAttribute(Qt::WA_KeyCompression, b) instead.
 
7090
*/
 
7091
 
 
7092
/*!
 
7093
    \fn void QWidget::setFont(const QFont &f, bool b)
 
7094
 
 
7095
    Use the single-argument overload instead.
 
7096
*/
 
7097
 
 
7098
/*!
 
7099
    \fn void QWidget::setPalette(const QPalette &p, bool b)
 
7100
 
 
7101
    Use the single-argument overload instead.
 
7102
*/
 
7103
 
 
7104
/*!
 
7105
    \fn void QWidget::setBackgroundOrigin(BackgroundOrigin background)
 
7106
 
 
7107
    \obsolete
 
7108
*/
 
7109
 
 
7110
/*!
 
7111
    \fn BackgroundOrigin QWidget::backgroundOrigin() const
 
7112
 
 
7113
    \obsolete
 
7114
 
 
7115
    Always returns \c WindowOrigin.
 
7116
*/
 
7117
 
 
7118
/*!
 
7119
    \fn QPoint QWidget::backgroundOffset() const
 
7120
 
 
7121
    \obsolete
 
7122
 
 
7123
    Always returns QPoint().
 
7124
*/
 
7125
 
 
7126
/*!
 
7127
    \fn void QWidget::repaint(bool b)
 
7128
 
 
7129
    The boolean parameter \a b is ignored. Use the no-argument overload instead.
 
7130
*/
 
7131
 
 
7132
/*!
 
7133
    \fn void QWidget::repaint(int x, int y, int w, int h, bool b)
 
7134
 
 
7135
    The boolean parameter \a b is ignored. Use the four-argument overload instead.
 
7136
*/
 
7137
 
 
7138
/*!
 
7139
    \fn void QWidget::repaint(const QRect &r, bool b)
 
7140
 
 
7141
    The boolean parameter \a b is ignored. Use the single rect-argument overload instead.
 
7142
*/
 
7143
 
 
7144
/*!
 
7145
    \fn void QWidget::repaint(const QRegion &rgn, bool b)
 
7146
 
 
7147
    The boolean parameter \a b is ignored. Use the single region-argument overload instead.
 
7148
*/
 
7149
 
 
7150
/*!
 
7151
    \fn void QWidget::erase()
 
7152
 
 
7153
    Drawing may only take place in a QPaintEvent. Overload
 
7154
    paintEvent() to do your erasing and call update() to schedule a
 
7155
    replaint whenever necessary. See also QPainter.
 
7156
*/
 
7157
 
 
7158
/*!
 
7159
    \fn void QWidget::erase(int x, int y, int w, int h)
 
7160
 
 
7161
    Drawing may only take place in a QPaintEvent. Overload
 
7162
    paintEvent() to do your erasing and call update() to schedule a
 
7163
    replaint whenever necessary. See also QPainter.
 
7164
*/
 
7165
 
 
7166
/*!
 
7167
    \fn void QWidget::erase(const QRect &rect)
 
7168
 
 
7169
    Drawing may only take place in a QPaintEvent. Overload
 
7170
    paintEvent() to do your erasing and call update() to schedule a
 
7171
    replaint whenever necessary. See also QPainter.
 
7172
*/
 
7173
 
 
7174
/*!
 
7175
    \fn void QWidget::drawText(const QPoint &p, const QString &s)
 
7176
 
 
7177
    Drawing may only take place in a QPaintEvent. Overload
 
7178
    paintEvent() to do your drawing and call update() to schedule a
 
7179
    replaint whenever necessary. See also QPainter.
 
7180
*/
 
7181
 
 
7182
/*!
 
7183
    \fn void QWidget::drawText(int x, int y, const QString &s)
 
7184
 
 
7185
    Drawing may only take place in a QPaintEvent. Overload
 
7186
    paintEvent() to do your drawing and call update() to schedule a
 
7187
    replaint whenever necessary. See also QPainter.
 
7188
*/
 
7189
 
 
7190
/*!
 
7191
    \fn QWidget *QWidget::childAt(const QPoint &p, bool includeThis) const
 
7192
 
 
7193
    Use the single point argument overload instead.
 
7194
*/
 
7195
 
 
7196
/*!
 
7197
    \fn void QWidget::setCaption(const QString &c)
 
7198
 
 
7199
    Use setWindowTitle() instead.
 
7200
*/
 
7201
 
 
7202
/*!
 
7203
    \fn void QWidget::setIcon(const QPixmap &i)
 
7204
 
 
7205
    Use setWindowIcon() instead.
 
7206
*/
 
7207
 
 
7208
/*!
 
7209
    \fn void QWidget::setIconText(const QString &it)
 
7210
 
 
7211
    Use setWindowIconText() instead.
 
7212
*/
 
7213
 
 
7214
/*!
 
7215
    \fn QString QWidget::caption() const
 
7216
 
 
7217
    Use windowTitle() instead.
 
7218
*/
 
7219
 
 
7220
/*!
 
7221
    \fn QString QWidget::iconText() const
 
7222
 
 
7223
    Use windowIconText() instead().
 
7224
*/
 
7225
 
 
7226
/*!
 
7227
    \fn bool QWidget::isTopLevel() const
 
7228
    \obsolete
 
7229
 
 
7230
    Use isWindow() instead.
 
7231
*/
 
7232
 
 
7233
/*!
 
7234
    \fn bool QWidget::isRightToLeft() const
 
7235
    \internal
 
7236
*/
 
7237
 
 
7238
/*!
 
7239
    \fn bool QWidget::isLeftToRight() const
 
7240
    \internal
 
7241
*/
 
7242
 
 
7243
/*!
 
7244
    \fn void QWidget::setInputMethodEnabled(bool enabled)
 
7245
 
 
7246
    Use setAttribute(Qt::WA_InputMethodEnabled, \a enabled) instead.
 
7247
*/
 
7248
 
 
7249
/*!
 
7250
    \fn bool QWidget::isInputMethodEnabled() const
 
7251
 
 
7252
    Use testAttribute(Qt::WA_InputMethodEnabled) instead.
 
7253
*/
 
7254
 
 
7255
/*!
 
7256
    \fn void QWidget::setActiveWindow()
 
7257
 
 
7258
    Use activateWindow() instead.
 
7259
*/
 
7260
 
 
7261
/*!
 
7262
    \fn bool QWidget::isShown() const
 
7263
 
 
7264
    Use !isHidden() instead (notice the exclamation mark), or use isVisible() to check whether the widget is visible.
 
7265
*/
 
7266
 
 
7267
/*!
 
7268
    \fn bool QWidget::isDialog() const
 
7269
 
 
7270
    Use windowType() == Qt::Dialog instead.
 
7271
*/
 
7272
 
 
7273
/*!
 
7274
    \fn bool QWidget::isPopup() const
 
7275
 
 
7276
    Use windowType() == Qt::Popup instead.
 
7277
*/
 
7278
 
 
7279
/*!
 
7280
    \fn bool QWidget::isDesktop() const
 
7281
 
 
7282
    Use windowType() == Qt::Desktop instead.
 
7283
*/
 
7284
 
 
7285
/*!
 
7286
    \fn void QWidget::polish()
 
7287
 
 
7288
    Use ensurePolished() instead.
 
7289
*/
 
7290
 
 
7291
/*!
 
7292
    \fn QWidget *QWidget::childAt(int x, int y, bool includeThis) const
 
7293
 
 
7294
    Use the childAt() overload that doesn't have an \a includeThis parameter.
 
7295
 
 
7296
    \oldcode
 
7297
        return widget->childAt(x, y, true);
 
7298
    \newcode
 
7299
        QWidget *child = widget->childAt(x, y, true);
 
7300
        if (child)
 
7301
            return child;
 
7302
        if (widget->rect().contains(x, y))
 
7303
            return widget;
 
7304
    \endcode
 
7305
*/
 
7306
 
 
7307
/*!
 
7308
    \fn void QWidget::setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver, bool hfw)
 
7309
    \compat
 
7310
 
 
7311
    Use the \l sizePolicy property and heightForWidth() function instead.
 
7312
*/
 
7313
 
 
7314
/*!
 
7315
    \fn bool QWidget::isUpdatesEnabled() const
 
7316
    \compat
 
7317
 
 
7318
    Use the \l updatesEnabled property instead.
 
7319
*/
 
7320
 
 
7321
#include "moc_qwidget.cpp"