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

« back to all changes in this revision

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

  • 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
#ifndef QWIDGET_H
 
30
#define QWIDGET_H
 
31
 
 
32
#include "QtGui/qwindowdefs.h"
 
33
#include "QtCore/qobject.h"
 
34
#include "QtGui/qpaintdevice.h"
 
35
#include "QtGui/qpalette.h"
 
36
#include "QtGui/qfont.h"
 
37
#include "QtGui/qfontmetrics.h"
 
38
#include "QtGui/qfontinfo.h"
 
39
#include "QtGui/qsizepolicy.h"
 
40
#include "QtGui/qregion.h"
 
41
#include "QtGui/qbrush.h"
 
42
#include "QtGui/qcursor.h"
 
43
#include "QtGui/qkeysequence.h"
 
44
 
 
45
#ifdef QT_INCLUDE_COMPAT
 
46
#include "QtGui/qevent.h"
 
47
#endif
 
48
 
 
49
class QLayout;
 
50
class QWSRegionManager;
 
51
class QStyle;
 
52
class QAction;
 
53
class QVariant;
 
54
 
 
55
class QActionEvent;
 
56
class QMouseEvent;
 
57
class QWheelEvent;
 
58
class QHoverEvent;
 
59
class QKeyEvent;
 
60
class QFocusEvent;
 
61
class QPaintEvent;
 
62
class QMoveEvent;
 
63
class QResizeEvent;
 
64
class QCloseEvent;
 
65
class QContextMenuEvent;
 
66
class QInputMethodEvent;
 
67
class QTabletEvent;
 
68
class QDragEnterEvent;
 
69
class QDragMoveEvent;
 
70
class QDragLeaveEvent;
 
71
class QDropEvent;
 
72
class QShowEvent;
 
73
class QHideEvent;
 
74
class QInputContext;
 
75
class QIcon;
 
76
#if defined(Q_WS_X11)
 
77
class QX11Info;
 
78
#endif
 
79
 
 
80
class QWidgetData
 
81
{
 
82
public:
 
83
    WId winid;
 
84
    uint widget_attributes;
 
85
    Qt::WindowFlags window_flags;
 
86
    uint window_state : 4;
 
87
    uint focus_policy : 4;
 
88
    uint sizehint_forced :1;
 
89
    uint is_closing :1;
 
90
    uint in_show : 1;
 
91
    uint in_set_window_state : 1;
 
92
    mutable uint fstrut_dirty : 1;
 
93
    uint context_menu_policy : 3;
 
94
    uint unused : 16;
 
95
    QRect crect;
 
96
    mutable QPalette pal;
 
97
    QFont fnt;
 
98
#if defined(Q_WS_QWS)
 
99
//    QRegion req_region;                 // Requested region
 
100
//     mutable QRegion paintable_region;   // Paintable region
 
101
//     mutable bool paintable_region_dirty;// needs to be recalculated
 
102
//     mutable QRegion alloc_region;       // Allocated region
 
103
//     mutable bool alloc_region_dirty;    // needs to be recalculated
 
104
//     mutable int overlapping_children;   // Handle overlapping children
 
105
 
 
106
    int alloc_region_index;
 
107
//    int alloc_region_revision;
 
108
#endif
 
109
    QRect wrect;
 
110
};
 
111
 
 
112
class QWidgetPrivate;
 
113
 
 
114
class Q_GUI_EXPORT QWidget : public QObject, public QPaintDevice
 
115
{
 
116
    Q_OBJECT
 
117
    Q_DECLARE_PRIVATE(QWidget)
 
118
 
 
119
    Q_PROPERTY(bool modal READ isModal)
 
120
    Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
 
121
    Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry)
 
122
    Q_PROPERTY(QRect frameGeometry READ frameGeometry)
 
123
    Q_PROPERTY(QRect normalGeometry READ normalGeometry)
 
124
    Q_PROPERTY(int x READ x)
 
125
    Q_PROPERTY(int y READ y)
 
126
    Q_PROPERTY(QPoint pos READ pos WRITE move DESIGNABLE false STORED false)
 
127
    Q_PROPERTY(QSize frameSize READ frameSize)
 
128
    Q_PROPERTY(QSize size READ size WRITE resize DESIGNABLE false STORED false)
 
129
    Q_PROPERTY(int width READ width)
 
130
    Q_PROPERTY(int height READ height)
 
131
    Q_PROPERTY(QRect rect READ rect)
 
132
    Q_PROPERTY(QRect childrenRect READ childrenRect)
 
133
    Q_PROPERTY(QRegion childrenRegion READ childrenRegion)
 
134
    Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)
 
135
    Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
 
136
    Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
 
137
    Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth STORED false DESIGNABLE false)
 
138
    Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight STORED false DESIGNABLE false)
 
139
    Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth STORED false DESIGNABLE false)
 
140
    Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight STORED false DESIGNABLE false)
 
141
    Q_PROPERTY(QSize sizeIncrement READ sizeIncrement WRITE setSizeIncrement)
 
142
    Q_PROPERTY(QSize baseSize READ baseSize WRITE setBaseSize)
 
143
    Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
 
144
    Q_PROPERTY(QFont font READ font WRITE setFont)
 
145
#ifndef QT_NO_CURSOR
 
146
    Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)
 
147
#endif
 
148
    Q_PROPERTY(bool mouseTracking READ hasMouseTracking WRITE setMouseTracking)
 
149
    Q_PROPERTY(bool isActiveWindow READ isActiveWindow)
 
150
    Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
 
151
    Q_PROPERTY(bool focus READ hasFocus)
 
152
    Q_PROPERTY(Qt::ContextMenuPolicy contextMenuPolicy READ contextMenuPolicy WRITE setContextMenuPolicy)
 
153
    Q_PROPERTY(bool updatesEnabled READ updatesEnabled WRITE setUpdatesEnabled DESIGNABLE false)
 
154
    Q_PROPERTY(bool visible READ isVisible WRITE setVisible DESIGNABLE false)
 
155
    Q_PROPERTY(bool minimized READ isMinimized)
 
156
    Q_PROPERTY(bool maximized READ isMaximized)
 
157
    Q_PROPERTY(bool fullScreen READ isFullScreen)
 
158
    Q_PROPERTY(QSize sizeHint READ sizeHint)
 
159
    Q_PROPERTY(QSize minimumSizeHint READ minimumSizeHint)
 
160
    Q_PROPERTY(bool acceptDrops READ acceptDrops WRITE setAcceptDrops)
 
161
    Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle DESIGNABLE isWindow)
 
162
    Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon DESIGNABLE isWindow)
 
163
    Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText DESIGNABLE isWindow)
 
164
    Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity DESIGNABLE false)
 
165
    Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified DESIGNABLE isWindow)
 
166
    Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip)
 
167
    Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip)
 
168
    Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis)
 
169
#ifndef QT_NO_ACCESSIBILITY
 
170
    Q_PROPERTY(QString accessibleName READ accessibleName WRITE setAccessibleName)
 
171
    Q_PROPERTY(QString accessibleDescription READ accessibleDescription WRITE setAccessibleDescription)
 
172
#endif
 
173
    Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection)
 
174
    QDOC_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
 
175
 
 
176
 
 
177
public:
 
178
    explicit QWidget(QWidget* parent = 0, Qt::WFlags f = 0);
 
179
#ifdef QT3_SUPPORT
 
180
    QT3_SUPPORT_CONSTRUCTOR QWidget(QWidget* parent, const char *name, Qt::WFlags f = 0);
 
181
#endif
 
182
    ~QWidget();
 
183
 
 
184
    int devType() const;
 
185
 
 
186
    WId winId() const;
 
187
#ifndef QT_NO_STYLE
 
188
    // GUI style setting
 
189
    QStyle *style() const;
 
190
    void setStyle(QStyle *);
 
191
#endif
 
192
    // Widget types and states
 
193
 
 
194
    bool isTopLevel() const;
 
195
    bool isWindow() const;
 
196
 
 
197
    bool isModal() const;
 
198
 
 
199
    bool isEnabled() const;
 
200
    bool isEnabledTo(QWidget*) const;
 
201
    bool isEnabledToTLW() const;
 
202
 
 
203
public slots:
 
204
    void setEnabled(bool);
 
205
    void setDisabled(bool);
 
206
    void setWindowModified(bool);
 
207
 
 
208
    // Widget coordinates
 
209
 
 
210
public:
 
211
    QRect frameGeometry() const;
 
212
    const QRect &geometry() const;
 
213
    QRect normalGeometry() const;
 
214
 
 
215
    int x() const;
 
216
    int y() const;
 
217
    QPoint pos() const;
 
218
    QSize frameSize() const;
 
219
    QSize size() const;
 
220
    inline int width() const;
 
221
    inline int height() const;
 
222
    inline QRect rect() const;
 
223
    QRect childrenRect() const;
 
224
    QRegion childrenRegion() const;
 
225
 
 
226
    QSize minimumSize() const;
 
227
    QSize maximumSize() const;
 
228
    int minimumWidth() const;
 
229
    int minimumHeight() const;
 
230
    int maximumWidth() const;
 
231
    int maximumHeight() const;
 
232
    void setMinimumSize(const QSize &);
 
233
    void setMinimumSize(int minw, int minh);
 
234
    void setMaximumSize(const QSize &);
 
235
    void setMaximumSize(int maxw, int maxh);
 
236
    void setMinimumWidth(int minw);
 
237
    void setMinimumHeight(int minh);
 
238
    void setMaximumWidth(int maxw);
 
239
    void setMaximumHeight(int maxh);
 
240
 
 
241
    QSize sizeIncrement() const;
 
242
    void setSizeIncrement(const QSize &);
 
243
    void setSizeIncrement(int w, int h);
 
244
    QSize baseSize() const;
 
245
    void setBaseSize(const QSize &);
 
246
    void setBaseSize(int basew, int baseh);
 
247
 
 
248
    void setFixedSize(const QSize &);
 
249
    void setFixedSize(int w, int h);
 
250
    void setFixedWidth(int w);
 
251
    void setFixedHeight(int h);
 
252
 
 
253
    // Widget coordinate mapping
 
254
 
 
255
    QPoint mapToGlobal(const QPoint &) const;
 
256
    QPoint mapFromGlobal(const QPoint &) const;
 
257
    QPoint mapToParent(const QPoint &) const;
 
258
    QPoint mapFromParent(const QPoint &) const;
 
259
    QPoint mapTo(QWidget *, const QPoint &) const;
 
260
    QPoint mapFrom(QWidget *, const QPoint &) const;
 
261
 
 
262
    QWidget *window() const;
 
263
    inline QWidget *topLevelWidget() const { return window(); }
 
264
 
 
265
    // Widget appearance functions
 
266
    const QPalette &palette() const;
 
267
    void setPalette(const QPalette &);
 
268
 
 
269
    void setBackgroundRole(QPalette::ColorRole);
 
270
    QPalette::ColorRole backgroundRole() const;
 
271
 
 
272
    void setForegroundRole(QPalette::ColorRole);
 
273
    QPalette::ColorRole foregroundRole() const;
 
274
 
 
275
    const QFont &font() const;
 
276
    void setFont(const QFont &);
 
277
    QFontMetrics fontMetrics() const;
 
278
    QFontInfo fontInfo() const;
 
279
 
 
280
#ifndef QT_NO_CURSOR
 
281
    QCursor cursor() const;
 
282
    void setCursor(const QCursor &);
 
283
    void unsetCursor();
 
284
#endif
 
285
 
 
286
    void setMouseTracking(bool enable);
 
287
    bool hasMouseTracking() const;
 
288
    bool underMouse() const;
 
289
 
 
290
    void setMask(const QBitmap &);
 
291
    void setMask(const QRegion &);
 
292
    QRegion mask() const;
 
293
    void clearMask();
 
294
 
 
295
    void setWindowTitle(const QString &);
 
296
    QString windowTitle() const;
 
297
    void setWindowIcon(const QIcon &icon);
 
298
    QIcon windowIcon() const;
 
299
    void setWindowIconText(const QString &);
 
300
    QString windowIconText() const;
 
301
    void setWindowRole(const QString &);
 
302
    QString windowRole() const;
 
303
 
 
304
    void setWindowOpacity(qreal level);
 
305
    qreal windowOpacity() const;
 
306
 
 
307
    bool isWindowModified() const;
 
308
 
 
309
    void setToolTip(const QString &);
 
310
    QString toolTip() const;
 
311
 
 
312
    void setStatusTip(const QString &);
 
313
    QString statusTip() const;
 
314
 
 
315
    void setWhatsThis(const QString &);
 
316
    QString whatsThis() const;
 
317
 
 
318
#ifndef QT_NO_ACCESSIBILITY
 
319
    QString accessibleName() const;
 
320
    void setAccessibleName(const QString &name);
 
321
    QString accessibleDescription() const;
 
322
    void setAccessibleDescription(const QString &description);
 
323
#endif
 
324
 
 
325
    void setLayoutDirection(Qt::LayoutDirection direction);
 
326
    Qt::LayoutDirection layoutDirection() const;
 
327
    void unsetLayoutDirection();
 
328
 
 
329
    inline bool isRightToLeft() const { return layoutDirection() == Qt::RightToLeft; }
 
330
    inline bool isLeftToRight() const { return layoutDirection() == Qt::LeftToRight; }
 
331
 
 
332
public slots:
 
333
    inline void setFocus() { setFocus(Qt::OtherFocusReason); }
 
334
 
 
335
public:
 
336
    bool isActiveWindow() const;
 
337
    void activateWindow();
 
338
    void clearFocus();
 
339
 
 
340
    void setFocus(Qt::FocusReason reason);
 
341
    Qt::FocusPolicy focusPolicy() const;
 
342
    void setFocusPolicy(Qt::FocusPolicy policy);
 
343
    bool hasFocus() const;
 
344
    static void setTabOrder(QWidget *, QWidget *);
 
345
    void setFocusProxy(QWidget *);
 
346
    QWidget *focusProxy() const;
 
347
    Qt::ContextMenuPolicy contextMenuPolicy() const;
 
348
    void setContextMenuPolicy(Qt::ContextMenuPolicy policy);
 
349
 
 
350
    // Grab functions
 
351
    void grabMouse();
 
352
#ifndef QT_NO_CURSOR
 
353
    void grabMouse(const QCursor &);
 
354
#endif
 
355
    void releaseMouse();
 
356
    void grabKeyboard();
 
357
    void releaseKeyboard();
 
358
    int grabShortcut(const QKeySequence &key, Qt::ShortcutContext context = Qt::WindowShortcut);
 
359
    void releaseShortcut(int id);
 
360
    void setShortcutEnabled(int id, bool enable = true);
 
361
    static QWidget *mouseGrabber();
 
362
    static QWidget *keyboardGrabber();
 
363
 
 
364
    // Update/refresh functions
 
365
    inline bool updatesEnabled() const;
 
366
    void setUpdatesEnabled(bool enable);
 
367
 
 
368
#if 0 //def Q_WS_QWS
 
369
    void repaintUnclipped(const QRegion &, bool erase = true);
 
370
#endif
 
371
 
 
372
public slots:
 
373
    void update();
 
374
    void repaint();
 
375
 
 
376
public:
 
377
    inline void update(int x, int y, int w, int h);
 
378
    void update(const QRect&);
 
379
    void update(const QRegion&);
 
380
 
 
381
    void repaint(int x, int y, int w, int h);
 
382
    void repaint(const QRect &);
 
383
    void repaint(const QRegion &);
 
384
 
 
385
public slots:
 
386
    // Widget management functions
 
387
 
 
388
    virtual void setVisible(bool visible);
 
389
    inline void setHidden(bool hidden) { setVisible(!hidden); }
 
390
    inline void show() { setVisible(true); }
 
391
    inline void hide() { setVisible(false); }
 
392
    inline QT_MOC_COMPAT void setShown(bool shown) { setVisible(shown); }
 
393
 
 
394
    void showMinimized();
 
395
    void showMaximized();
 
396
    void showFullScreen();
 
397
    void showNormal();
 
398
 
 
399
    bool close();
 
400
    void raise();
 
401
    void lower();
 
402
 
 
403
public:
 
404
    void stackUnder(QWidget*);
 
405
    void move(int x, int y);
 
406
    void move(const QPoint &);
 
407
    void resize(int w, int h);
 
408
    void resize(const QSize &);
 
409
    inline void setGeometry(int x, int y, int w, int h);
 
410
    void setGeometry(const QRect &);
 
411
    void adjustSize();
 
412
    bool isVisible() const;
 
413
    bool isVisibleTo(QWidget*) const;
 
414
    inline bool isHidden() const;
 
415
 
 
416
    bool isMinimized() const;
 
417
    bool isMaximized() const;
 
418
    bool isFullScreen() const;
 
419
 
 
420
    Qt::WindowStates windowState() const;
 
421
    void setWindowState(Qt::WindowStates state);
 
422
    void overrideWindowState(Qt::WindowStates state);
 
423
 
 
424
    virtual QSize sizeHint() const;
 
425
    virtual QSize minimumSizeHint() const;
 
426
 
 
427
    QSizePolicy sizePolicy() const;
 
428
    void setSizePolicy(QSizePolicy);
 
429
    inline void setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical);
 
430
    virtual int heightForWidth(int) const;
 
431
 
 
432
    QRegion visibleRegion() const;
 
433
 
 
434
    void setContentsMargins(int left, int top, int right, int bottom);
 
435
    void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
 
436
    QRect contentsRect() const;
 
437
 
 
438
public:
 
439
#ifndef QT_NO_LAYOUT
 
440
    QLayout *layout() const;
 
441
    void setLayout(QLayout *);
 
442
#endif
 
443
    void updateGeometry();
 
444
 
 
445
    void setParent(QWidget *parent);
 
446
    void setParent(QWidget *parent, Qt::WFlags f);
 
447
 
 
448
    void scroll(int dx, int dy);
 
449
    void scroll(int dx, int dy, const QRect&);
 
450
 
 
451
    // Misc. functions
 
452
 
 
453
    QWidget *focusWidget() const;
 
454
    QWidget *nextInFocusChain() const;
 
455
 
 
456
    // drag and drop
 
457
    bool acceptDrops() const;
 
458
    void setAcceptDrops(bool on);
 
459
 
 
460
    //actions
 
461
    void addAction(QAction *action);
 
462
    void addActions(QList<QAction*> actions);
 
463
    void insertAction(QAction *before, QAction *action);
 
464
    void insertActions(QAction *before, QList<QAction*> actions);
 
465
    void removeAction(QAction *action);
 
466
    QList<QAction*> actions() const;
 
467
 
 
468
    QWidget *parentWidget() const;
 
469
 
 
470
    void setWindowFlags(Qt::WindowFlags type);
 
471
    inline Qt::WindowFlags windowFlags() const;
 
472
    void overrideWindowFlags(Qt::WindowFlags type);
 
473
 
 
474
    inline Qt::WindowType windowType() const;
 
475
 
 
476
    static QWidget *find(WId);
 
477
#ifdef QT3_SUPPORT
 
478
    static QT3_SUPPORT QWidgetMapper *wmapper();
 
479
#endif
 
480
    inline QWidget *childAt(int x, int y) const;
 
481
    QWidget *childAt(const QPoint &p) const;
 
482
 
 
483
#if defined(Q_WS_X11)
 
484
    const QX11Info &x11Info() const;
 
485
    Qt::HANDLE x11PictureHandle() const;
 
486
#endif
 
487
 
 
488
#if defined(Q_WS_WIN)
 
489
    HDC getDC() const;
 
490
    void releaseDC(HDC) const;
 
491
#else
 
492
    Qt::HANDLE handle() const;
 
493
#endif
 
494
 
 
495
    void setAttribute(Qt::WidgetAttribute, bool on = true);
 
496
    inline bool testAttribute(Qt::WidgetAttribute) const;
 
497
 
 
498
    QPaintEngine *paintEngine() const;
 
499
 
 
500
    void ensurePolished() const;
 
501
 
 
502
    QInputContext *inputContext();
 
503
    void setInputContext(QInputContext *);
 
504
 
 
505
    bool isAncestorOf(const QWidget *child) const;
 
506
 
 
507
signals:
 
508
    void customContextMenuRequested(const QPoint &pos);
 
509
 
 
510
protected:
 
511
    // Event handlers
 
512
    bool event(QEvent *);
 
513
    virtual void mousePressEvent(QMouseEvent *);
 
514
    virtual void mouseReleaseEvent(QMouseEvent *);
 
515
    virtual void mouseDoubleClickEvent(QMouseEvent *);
 
516
    virtual void mouseMoveEvent(QMouseEvent *);
 
517
#ifndef QT_NO_WHEELEVENT
 
518
    virtual void wheelEvent(QWheelEvent *);
 
519
#endif
 
520
    virtual void keyPressEvent(QKeyEvent *);
 
521
    virtual void keyReleaseEvent(QKeyEvent *);
 
522
    virtual void focusInEvent(QFocusEvent *);
 
523
    virtual void focusOutEvent(QFocusEvent *);
 
524
    virtual void enterEvent(QEvent *);
 
525
    virtual void leaveEvent(QEvent *);
 
526
    virtual void paintEvent(QPaintEvent *);
 
527
    virtual void moveEvent(QMoveEvent *);
 
528
    virtual void resizeEvent(QResizeEvent *);
 
529
    virtual void closeEvent(QCloseEvent *);
 
530
    virtual void contextMenuEvent(QContextMenuEvent *);
 
531
    virtual void tabletEvent(QTabletEvent *);
 
532
    virtual void actionEvent(QActionEvent *);
 
533
 
 
534
#ifndef QT_NO_DRAGANDDROP
 
535
    virtual void dragEnterEvent(QDragEnterEvent *);
 
536
    virtual void dragMoveEvent(QDragMoveEvent *);
 
537
    virtual void dragLeaveEvent(QDragLeaveEvent *);
 
538
    virtual void dropEvent(QDropEvent *);
 
539
#endif
 
540
 
 
541
    virtual void showEvent(QShowEvent *);
 
542
    virtual void hideEvent(QHideEvent *);
 
543
 
 
544
#if defined(Q_WS_MAC)
 
545
    virtual bool macEvent(EventHandlerCallRef, EventRef);
 
546
#endif
 
547
#if defined(Q_WS_WIN)
 
548
    virtual bool winEvent(MSG *message, long *result);
 
549
#endif
 
550
#if defined(Q_WS_X11)
 
551
    virtual bool x11Event(XEvent *);
 
552
#endif
 
553
#if defined(Q_WS_QWS)
 
554
    virtual bool qwsEvent(QWSEvent *);
 
555
    virtual const uchar *qwsScanLine(int) const;
 
556
    virtual int qwsBytesPerLine() const;
 
557
#endif
 
558
 
 
559
    // Misc. protected functions
 
560
    virtual void changeEvent(QEvent *);
 
561
 
 
562
    int metric(PaintDeviceMetric) const;
 
563
 
 
564
    virtual void inputMethodEvent(QInputMethodEvent *);
 
565
public:
 
566
    virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const;
 
567
protected:
 
568
    void resetInputContext();
 
569
    void updateMicroFocus();
 
570
 
 
571
    void create(WId = 0, bool initializeWindow = true,
 
572
                         bool destroyOldWindow = true);
 
573
    void destroy(bool destroyWindow = true,
 
574
                 bool destroySubWindows = true);
 
575
 
 
576
    virtual bool focusNextPrevChild(bool next);
 
577
    inline bool focusNextChild() { return focusNextPrevChild(true); }
 
578
    inline bool focusPreviousChild() { return focusNextPrevChild(false); }
 
579
 
 
580
protected:
 
581
    QWidget(QWidgetPrivate &d, QWidget* parent, Qt::WFlags f);
 
582
private:
 
583
 
 
584
    bool testAttribute_helper(Qt::WidgetAttribute) const;
 
585
 
 
586
    friend class QApplication;
 
587
    friend class QApplicationPrivate;
 
588
    friend class QBaseApplication;
 
589
    friend class QPainter;
 
590
    friend class QPixmap; // for QPixmap::fill()
 
591
    friend class QFontMetrics;
 
592
    friend class QFontInfo;
 
593
    friend class QETWidget;
 
594
    friend class QLayout;
 
595
    friend class QWidgetItem;
 
596
    friend class QGLContext;
 
597
    friend class QX11PaintEngine;
 
598
    friend class QWin32PaintEngine;
 
599
    friend class QShortcutPrivate;
 
600
 
 
601
#ifdef Q_WS_MAC
 
602
    friend class QMacSavedPortInfo;
 
603
    friend class QQuickDrawPaintEngine;
 
604
    friend class QCoreGraphicsPaintEnginePrivate;
 
605
    friend QPoint qt_mac_posInWindow(const QWidget *w);
 
606
#endif
 
607
#ifdef Q_WS_QWS
 
608
    friend class QWSManager;
 
609
    friend class QWSManagerPrivate;
 
610
    friend class QDecoration;
 
611
#endif
 
612
 
 
613
private:
 
614
    Q_DISABLE_COPY(QWidget)
 
615
 
 
616
    QWidgetData *data;
 
617
 
 
618
#ifdef QT3_SUPPORT
 
619
public:
 
620
    inline QT3_SUPPORT bool isUpdatesEnabled() const { return updatesEnabled(); }
 
621
    QT3_SUPPORT QStyle *setStyle(const QString&);
 
622
    inline QT3_SUPPORT bool isVisibleToTLW() const;
 
623
    QT3_SUPPORT QRect visibleRect() const;
 
624
    inline QT3_SUPPORT void iconify() { showMinimized(); }
 
625
    inline QT3_SUPPORT void constPolish() const { ensurePolished(); }
 
626
    inline QT3_SUPPORT void polish() { ensurePolished(); }
 
627
    inline QT3_SUPPORT void reparent(QWidget *parent, Qt::WFlags f, const QPoint &p, bool showIt=false)
 
628
    { setParent(parent, f); setGeometry(p.x(),p.y(),width(),height()); if (showIt) show(); }
 
629
    inline QT3_SUPPORT void reparent(QWidget *parent, const QPoint &p, bool showIt=false)
 
630
    { setParent(parent, windowFlags() & ~Qt::WindowType_Mask); setGeometry(p.x(),p.y(),width(),height()); if (showIt) show(); }
 
631
    inline QT3_SUPPORT void recreate(QWidget *parent, Qt::WFlags f, const QPoint & p, bool showIt=false)
 
632
    { setParent(parent, f); setGeometry(p.x(),p.y(),width(),height()); if (showIt) show(); }
 
633
    inline QT3_SUPPORT void setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver, bool hfw)
 
634
    { QSizePolicy sp(hor, ver); sp.setHeightForWidth(hfw); setSizePolicy(sp);}
 
635
    inline QT3_SUPPORT bool hasMouse() const { return testAttribute(Qt::WA_UnderMouse); }
 
636
#ifndef QT_NO_CURSOR
 
637
    inline QT3_SUPPORT bool ownCursor() const { return testAttribute(Qt::WA_SetCursor); }
 
638
#endif
 
639
    inline QT3_SUPPORT bool ownFont() const { return testAttribute(Qt::WA_SetFont); }
 
640
    inline QT3_SUPPORT void unsetFont() { setFont(QFont()); }
 
641
    inline QT3_SUPPORT bool ownPalette() const { return testAttribute(Qt::WA_SetPalette); }
 
642
    inline QT3_SUPPORT void unsetPalette() { setPalette(QPalette()); }
 
643
    Qt::BackgroundMode QT3_SUPPORT backgroundMode() const;
 
644
    void QT3_SUPPORT setBackgroundMode(Qt::BackgroundMode, Qt::BackgroundMode = Qt::PaletteBackground);
 
645
    const QT3_SUPPORT QColor &eraseColor() const;
 
646
    void QT3_SUPPORT setEraseColor(const QColor &);
 
647
    const QT3_SUPPORT QColor &foregroundColor() const;
 
648
    const QT3_SUPPORT QPixmap *erasePixmap() const;
 
649
    void QT3_SUPPORT setErasePixmap(const QPixmap &);
 
650
    const QT3_SUPPORT QColor &paletteForegroundColor() const;
 
651
    void QT3_SUPPORT setPaletteForegroundColor(const QColor &);
 
652
    const QT3_SUPPORT QColor &paletteBackgroundColor() const;
 
653
    void QT3_SUPPORT setPaletteBackgroundColor(const QColor &);
 
654
    const QT3_SUPPORT QPixmap *paletteBackgroundPixmap() const;
 
655
    void QT3_SUPPORT setPaletteBackgroundPixmap(const QPixmap &);
 
656
    const QT3_SUPPORT QBrush& backgroundBrush() const;
 
657
    const QT3_SUPPORT QColor &backgroundColor() const;
 
658
    const QT3_SUPPORT QPixmap *backgroundPixmap() const;
 
659
    void QT3_SUPPORT setBackgroundPixmap(const QPixmap &);
 
660
    QT3_SUPPORT void setBackgroundColor(const QColor &);
 
661
    QT3_SUPPORT QColorGroup colorGroup() const;
 
662
    QT3_SUPPORT QWidget *parentWidget(bool sameWindow) const;
 
663
    inline QT3_SUPPORT void setKeyCompression(bool b) { setAttribute(Qt::WA_KeyCompression, b); }
 
664
    inline QT3_SUPPORT void setFont(const QFont &f, bool) { setFont(f); }
 
665
    inline QT3_SUPPORT void setPalette(const QPalette &p, bool) { setPalette(p); }
 
666
    enum BackgroundOrigin { WidgetOrigin, ParentOrigin, WindowOrigin, AncestorOrigin };
 
667
    inline QT3_SUPPORT void setBackgroundOrigin(BackgroundOrigin){};
 
668
    inline QT3_SUPPORT BackgroundOrigin backgroundOrigin() const { return WindowOrigin; }
 
669
    inline QT3_SUPPORT QPoint backgroundOffset() const { return QPoint(); }
 
670
    inline QT3_SUPPORT void repaint(bool) { repaint(); }
 
671
    inline QT3_SUPPORT void repaint(int x, int y, int w, int h, bool) { repaint(x,y,w,h); }
 
672
    inline QT3_SUPPORT void repaint(const QRect &r, bool) { repaint(r); }
 
673
    inline QT3_SUPPORT void repaint(const QRegion &rgn, bool) { repaint(rgn); }
 
674
    QT3_SUPPORT void erase();
 
675
    inline QT3_SUPPORT void erase(int x, int y, int w, int h) { erase_helper(x, y, w, h); }
 
676
    QT3_SUPPORT void erase(const QRect &);
 
677
    QT3_SUPPORT void erase(const QRegion &);
 
678
    QT3_SUPPORT void drawText(const QPoint &p, const QString &s)
 
679
    { drawText_helper(p.x(), p.y(), s); }
 
680
    inline QT3_SUPPORT void drawText(int x, int y, const QString &s)
 
681
    { drawText_helper(x, y, s); }
 
682
    QT3_SUPPORT bool close(bool);
 
683
    inline QT3_SUPPORT QWidget *childAt(int x, int y, bool includeThis) const
 
684
    {
 
685
        QWidget *w = childAt(x, y);
 
686
        return w ? w : ((includeThis && rect().contains(x,y))?const_cast<QWidget*>(this):0);
 
687
    }
 
688
    inline QT3_SUPPORT QWidget *childAt(const QPoint &p, bool includeThis) const
 
689
    {
 
690
        QWidget *w = childAt(p);
 
691
        return w ? w : ((includeThis && rect().contains(p))?const_cast<QWidget*>(this):0);
 
692
    }
 
693
    inline QT3_SUPPORT void setCaption(const QString &c)   { setWindowTitle(c); }
 
694
    QT3_SUPPORT void setIcon(const QPixmap &i);
 
695
    inline QT3_SUPPORT void setIconText(const QString &it) { setWindowIconText(it); }
 
696
    inline QT3_SUPPORT QString caption() const             { return windowTitle(); }
 
697
    QT3_SUPPORT const QPixmap *icon() const;
 
698
    inline QT3_SUPPORT QString iconText() const            { return windowIconText(); }
 
699
    inline QT3_SUPPORT void setInputMethodEnabled(bool b) { setAttribute(Qt::WA_InputMethodEnabled, b); }
 
700
    inline QT3_SUPPORT bool isInputMethodEnabled() const { return testAttribute(Qt::WA_InputMethodEnabled); }
 
701
    inline QT3_SUPPORT void setActiveWindow() { activateWindow(); }
 
702
    inline QT3_SUPPORT bool isShown() const { return !isHidden(); }
 
703
    inline QT3_SUPPORT bool isDialog() const { return windowType() == Qt::Dialog; }
 
704
    inline QT3_SUPPORT bool isPopup() const { return windowType() == Qt::Popup; }
 
705
    inline QT3_SUPPORT bool isDesktop() const { return windowType() == Qt::Desktop; }
 
706
 
 
707
 
 
708
private:
 
709
    void drawText_helper(int x, int y, const QString &);
 
710
    void erase_helper(int x, int y, int w, int h);
 
711
#endif
 
712
 
 
713
protected:
 
714
    virtual void styleChange(QStyle&); // compat
 
715
    virtual void enabledChange(bool);  // compat
 
716
    virtual void paletteChange(const QPalette &);  // compat
 
717
    virtual void fontChange(const QFont &); // compat
 
718
    virtual void windowActivationChange(bool);  // compat
 
719
    virtual void languageChange();  // compat
 
720
};
 
721
 
 
722
#if defined Q_CC_MSVC && _MSC_VER < 1300
 
723
template <> inline QWidget *qobject_cast_helper<QWidget*>(QObject *o, QWidget *)
 
724
{
 
725
    if (!o || !o->isWidgetType()) return 0;
 
726
    return (QWidget*)(o);
 
727
}
 
728
#else
 
729
template <> inline QWidget *qobject_cast<QWidget*>(QObject *o)
 
730
{
 
731
    if (!o || !o->isWidgetType()) return 0;
 
732
    return static_cast<QWidget*>(o);
 
733
}
 
734
template <> inline const QWidget *qobject_cast<const QWidget*>(const QObject *o)
 
735
{
 
736
    if (!o || !o->isWidgetType()) return 0;
 
737
    return static_cast<const QWidget*>(o);
 
738
}
 
739
#endif
 
740
 
 
741
inline QWidget *QWidget::childAt(int ax, int ay) const
 
742
{ return childAt(QPoint(ax, ay)); }
 
743
 
 
744
inline Qt::WindowType QWidget::windowType() const
 
745
{ return static_cast<Qt::WindowType>(int(data->window_flags & Qt::WindowType_Mask)); }
 
746
inline Qt::WindowFlags QWidget::windowFlags() const
 
747
{ return data->window_flags; }
 
748
 
 
749
inline WId QWidget::winId() const
 
750
{ return data->winid; }
 
751
 
 
752
inline bool QWidget::isTopLevel() const
 
753
{ return (windowType() & Qt::Window); }
 
754
 
 
755
inline bool QWidget::isWindow() const
 
756
{ return (windowType() & Qt::Window); }
 
757
 
 
758
inline bool QWidget::isEnabled() const
 
759
{ return !testAttribute(Qt::WA_Disabled); }
 
760
 
 
761
inline bool QWidget::isModal() const
 
762
{ return testAttribute(Qt::WA_ShowModal); }
 
763
 
 
764
inline bool QWidget::isEnabledToTLW() const
 
765
{ return isEnabled(); }
 
766
 
 
767
inline int QWidget::minimumWidth() const
 
768
{ return minimumSize().width(); }
 
769
 
 
770
inline int QWidget::minimumHeight() const
 
771
{ return minimumSize().height(); }
 
772
 
 
773
inline int QWidget::maximumWidth() const
 
774
{ return maximumSize().width(); }
 
775
 
 
776
inline int QWidget::maximumHeight() const
 
777
{ return maximumSize().height(); }
 
778
 
 
779
inline void QWidget::setMinimumSize(const QSize &s)
 
780
{ setMinimumSize(s.width(),s.height()); }
 
781
 
 
782
inline void QWidget::setMaximumSize(const QSize &s)
 
783
{ setMaximumSize(s.width(),s.height()); }
 
784
 
 
785
inline void QWidget::setSizeIncrement(const QSize &s)
 
786
{ setSizeIncrement(s.width(),s.height()); }
 
787
 
 
788
inline void QWidget::setBaseSize(const QSize &s)
 
789
{ setBaseSize(s.width(),s.height()); }
 
790
 
 
791
inline const QFont &QWidget::font() const
 
792
{ return data->fnt; }
 
793
 
 
794
inline QFontMetrics QWidget::fontMetrics() const
 
795
{ return QFontMetrics(data->fnt); }
 
796
 
 
797
inline QFontInfo QWidget::fontInfo() const
 
798
{ return QFontInfo(data->fnt); }
 
799
 
 
800
inline void QWidget::setMouseTracking(bool enable)
 
801
{ setAttribute(Qt::WA_MouseTracking, enable); }
 
802
 
 
803
inline bool QWidget::hasMouseTracking() const
 
804
{ return testAttribute(Qt::WA_MouseTracking); }
 
805
 
 
806
inline bool QWidget::underMouse() const
 
807
{ return testAttribute(Qt::WA_UnderMouse); }
 
808
 
 
809
inline bool QWidget::updatesEnabled() const
 
810
{ return !testAttribute(Qt::WA_UpdatesDisabled); }
 
811
 
 
812
inline void QWidget::update(int ax, int ay, int aw, int ah)
 
813
{ update(QRect(ax, ay, aw, ah)); }
 
814
 
 
815
inline bool QWidget::isVisible() const
 
816
{ return testAttribute(Qt::WA_WState_Visible); }
 
817
 
 
818
inline bool QWidget::isHidden() const
 
819
{ return testAttribute(Qt::WA_WState_Hidden); }
 
820
 
 
821
inline void QWidget::move(int ax, int ay)
 
822
{ move(QPoint(ax, ay)); }
 
823
 
 
824
inline void QWidget::resize(int w, int h)
 
825
{ resize(QSize(w, h)); }
 
826
 
 
827
inline void QWidget::setGeometry(int ax, int ay, int aw, int ah)
 
828
{ setGeometry(QRect(ax, ay, aw, ah)); }
 
829
 
 
830
inline QRect QWidget::rect() const
 
831
{ return QRect(0,0,data->crect.width(),data->crect.height()); }
 
832
 
 
833
inline const QRect &QWidget::geometry() const
 
834
{ return data->crect; }
 
835
 
 
836
inline QSize QWidget::size() const
 
837
{ return data->crect.size(); }
 
838
 
 
839
inline int QWidget::width() const
 
840
{ return data->crect.width(); }
 
841
 
 
842
inline int QWidget::height() const
 
843
{ return data->crect.height(); }
 
844
 
 
845
inline QWidget *QWidget::parentWidget() const
 
846
{ return static_cast<QWidget *>(QObject::parent()); }
 
847
 
 
848
inline void QWidget::setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver)
 
849
{ setSizePolicy(QSizePolicy(hor, ver)); }
 
850
 
 
851
inline bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const
 
852
{
 
853
    if (attribute < int(8*sizeof(uint)))
 
854
        return data->widget_attributes & (1<<attribute);
 
855
    return testAttribute_helper(attribute);
 
856
}
 
857
 
 
858
#ifdef QT3_SUPPORT
 
859
inline bool QWidget::isVisibleToTLW() const
 
860
{ return isVisible(); }
 
861
inline QWidget *QWidget::parentWidget(bool sameWindow) const
 
862
{
 
863
    if (sameWindow && isWindow())
 
864
        return 0;
 
865
    return static_cast<QWidget *>(QObject::parent());
 
866
}
 
867
inline QColorGroup QWidget::colorGroup() const
 
868
{ return QColorGroup(palette()); }
 
869
inline void QWidget::setPaletteForegroundColor(const QColor &c)
 
870
{ QPalette p = palette(); p.setColor(foregroundRole(), c); setPalette(p); }
 
871
inline const QBrush& QWidget::backgroundBrush() const { return palette().brush(backgroundRole()); }
 
872
inline void QWidget::setBackgroundPixmap(const QPixmap &pm)
 
873
{ QPalette p = palette(); p.setBrush(backgroundRole(), QBrush(pm)); setPalette(p); }
 
874
inline const QPixmap *QWidget::backgroundPixmap() const { return 0; }
 
875
inline void QWidget::setBackgroundColor(const QColor &c)
 
876
{ QPalette p = palette(); p.setColor(backgroundRole(), c); setPalette(p); }
 
877
inline const QColor & QWidget::backgroundColor() const { return palette().color(backgroundRole()); }
 
878
inline const QColor &QWidget::foregroundColor() const { return palette().color(foregroundRole());}
 
879
inline const QColor &QWidget::eraseColor() const { return palette().color(backgroundRole()); }
 
880
inline void QWidget::setEraseColor(const QColor &c)
 
881
{ QPalette p = palette(); p.setColor(backgroundRole(), c); setPalette(p); }
 
882
inline const QPixmap *QWidget::erasePixmap() const { return 0; }
 
883
inline void QWidget::setErasePixmap(const QPixmap &pm)
 
884
{ QPalette p = palette(); p.setBrush(backgroundRole(), QBrush(pm)); setPalette(p); }
 
885
inline const QColor &QWidget::paletteForegroundColor() const { return palette().color(foregroundRole());}
 
886
inline const QColor &QWidget::paletteBackgroundColor() const { return palette().color(backgroundRole()); }
 
887
inline void QWidget::setPaletteBackgroundColor(const QColor &c)
 
888
{ QPalette p = palette(); p.setColor(backgroundRole(), c); setPalette(p); }
 
889
inline const QPixmap *QWidget::paletteBackgroundPixmap() const
 
890
{ return 0; }
 
891
inline void QWidget::setPaletteBackgroundPixmap(const QPixmap &pm)
 
892
{ QPalette p = palette(); p.setBrush(backgroundRole(), QBrush(pm)); setPalette(p); }
 
893
inline QT3_SUPPORT void QWidget::erase() { erase_helper(0, 0, data->crect.width(), data->crect.height()); }
 
894
inline QT3_SUPPORT void QWidget::erase(const QRect &r) { erase_helper(r.x(), r.y(), r.width(), r.height()); }
 
895
#endif
 
896
 
 
897
#define QWIDGETSIZE_MAX ((1<<24)-1)
 
898
 
 
899
#endif // QWIDGET_H