src/gui/kernel/qwidget.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtGui module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef QWIDGET_H
00025 #define QWIDGET_H
00026 
00027 #include <QtGui/qwindowdefs.h>
00028 #include <QtCore/qobject.h>
00029 #include <QtGui/qpaintdevice.h>
00030 #include <QtGui/qpalette.h>
00031 #include <QtGui/qfont.h>
00032 #include <QtGui/qfontmetrics.h>
00033 #include <QtGui/qfontinfo.h>
00034 #include <QtGui/qsizepolicy.h>
00035 #include <QtGui/qregion.h>
00036 #include <QtGui/qbrush.h>
00037 #include <QtGui/qcursor.h>
00038 #include <QtGui/qkeysequence.h>
00039 
00040 #ifdef QT_INCLUDE_COMPAT
00041 #include <QtGui/qevent.h>
00042 #endif
00043 
00044 QT_BEGIN_HEADER
00045 
00046 QT_MODULE(Gui)
00047 
00048 class QLayout;
00049 class QWSRegionManager;
00050 class QStyle;
00051 class QAction;
00052 class QVariant;
00053 
00054 class QActionEvent;
00055 class QMouseEvent;
00056 class QWheelEvent;
00057 class QHoverEvent;
00058 class QKeyEvent;
00059 class QFocusEvent;
00060 class QPaintEvent;
00061 class QMoveEvent;
00062 class QResizeEvent;
00063 class QCloseEvent;
00064 class QContextMenuEvent;
00065 class QInputMethodEvent;
00066 class QTabletEvent;
00067 class QDragEnterEvent;
00068 class QDragMoveEvent;
00069 class QDragLeaveEvent;
00070 class QDropEvent;
00071 class QShowEvent;
00072 class QHideEvent;
00073 class QInputContext;
00074 class QIcon;
00075 class QWindowSurface;
00076 #if defined(Q_WS_X11)
00077 class QX11Info;
00078 #endif
00079 
00080 class QWidgetData
00081 {
00082 public:
00083     WId winid;
00084     uint widget_attributes;
00085     Qt::WindowFlags window_flags;
00086     uint window_state : 4;
00087     uint focus_policy : 4;
00088     uint sizehint_forced :1;
00089     uint is_closing :1;
00090     uint in_show : 1;
00091     uint in_set_window_state : 1;
00092     mutable uint fstrut_dirty : 1;
00093     uint context_menu_policy : 3;
00094     uint window_modality : 2;
00095     uint unused : 14;
00096     QRect crect;
00097     mutable QPalette pal;
00098     QFont fnt;
00099 #if defined(Q_WS_QWS)
00100 //    QRegion req_region;                 // Requested region
00101 //     mutable QRegion paintable_region;   // Paintable region
00102 //     mutable bool paintable_region_dirty;// needs to be recalculated
00103 //     mutable QRegion alloc_region;       // Allocated region
00104 //     mutable bool alloc_region_dirty;    // needs to be recalculated
00105 //     mutable int overlapping_children;   // Handle overlapping children
00106 
00107     int alloc_region_index;
00108 //    int alloc_region_revision;
00109 #endif
00110     QRect wrect;
00111 };
00112 
00113 class QWidgetPrivate;
00114 
00115 class Q_GUI_EXPORT QWidget : public QObject, public QPaintDevice
00116 {
00117     Q_OBJECT
00118     Q_DECLARE_PRIVATE(QWidget)
00119 
00120     Q_PROPERTY(bool modal READ isModal)
00121     Q_PROPERTY(Qt::WindowModality windowModality READ windowModality WRITE setWindowModality)
00122     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
00123     Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry)
00124     Q_PROPERTY(QRect frameGeometry READ frameGeometry)
00125     Q_PROPERTY(QRect normalGeometry READ normalGeometry)
00126     Q_PROPERTY(int x READ x)
00127     Q_PROPERTY(int y READ y)
00128     Q_PROPERTY(QPoint pos READ pos WRITE move DESIGNABLE false STORED false)
00129     Q_PROPERTY(QSize frameSize READ frameSize)
00130     Q_PROPERTY(QSize size READ size WRITE resize DESIGNABLE false STORED false)
00131     Q_PROPERTY(int width READ width)
00132     Q_PROPERTY(int height READ height)
00133     Q_PROPERTY(QRect rect READ rect)
00134     Q_PROPERTY(QRect childrenRect READ childrenRect)
00135     Q_PROPERTY(QRegion childrenRegion READ childrenRegion)
00136     Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)
00137     Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
00138     Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
00139     Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth STORED false DESIGNABLE false)
00140     Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight STORED false DESIGNABLE false)
00141     Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth STORED false DESIGNABLE false)
00142     Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight STORED false DESIGNABLE false)
00143     Q_PROPERTY(QSize sizeIncrement READ sizeIncrement WRITE setSizeIncrement)
00144     Q_PROPERTY(QSize baseSize READ baseSize WRITE setBaseSize)
00145     Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
00146     Q_PROPERTY(QFont font READ font WRITE setFont)
00147 #ifndef QT_NO_CURSOR
00148     Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)
00149 #endif
00150     Q_PROPERTY(bool mouseTracking READ hasMouseTracking WRITE setMouseTracking)
00151     Q_PROPERTY(bool isActiveWindow READ isActiveWindow)
00152     Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
00153     Q_PROPERTY(bool focus READ hasFocus)
00154     Q_PROPERTY(Qt::ContextMenuPolicy contextMenuPolicy READ contextMenuPolicy WRITE setContextMenuPolicy)
00155     Q_PROPERTY(bool updatesEnabled READ updatesEnabled WRITE setUpdatesEnabled DESIGNABLE false)
00156     Q_PROPERTY(bool visible READ isVisible WRITE setVisible DESIGNABLE false)
00157     Q_PROPERTY(bool minimized READ isMinimized)
00158     Q_PROPERTY(bool maximized READ isMaximized)
00159     Q_PROPERTY(bool fullScreen READ isFullScreen)
00160     Q_PROPERTY(QSize sizeHint READ sizeHint)
00161     Q_PROPERTY(QSize minimumSizeHint READ minimumSizeHint)
00162     Q_PROPERTY(bool acceptDrops READ acceptDrops WRITE setAcceptDrops)
00163     Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle DESIGNABLE isWindow)
00164     Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon DESIGNABLE isWindow)
00165     Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText DESIGNABLE isWindow)
00166     Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity DESIGNABLE isWindow)
00167     Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified DESIGNABLE isWindow)
00168 #ifndef QT_NO_TOOLTIP
00169     Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip)
00170 #endif
00171 #ifndef QT_NO_STATUSTIP
00172     Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip)
00173 #endif
00174 #ifndef QT_NO_WHATSTHIS
00175     Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis)
00176 #endif
00177 #ifndef QT_NO_ACCESSIBILITY
00178     Q_PROPERTY(QString accessibleName READ accessibleName WRITE setAccessibleName)
00179     Q_PROPERTY(QString accessibleDescription READ accessibleDescription WRITE setAccessibleDescription)
00180 #endif
00181     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection)
00182     QDOC_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
00183     Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground)
00184 #ifndef QT_NO_STYLE_STYLESHEET
00185     Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
00186 #endif
00187 
00188 public:
00189     explicit QWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
00190 #ifdef QT3_SUPPORT
00191     QT3_SUPPORT_CONSTRUCTOR QWidget(QWidget* parent, const char *name, Qt::WindowFlags f = 0);
00192 #endif
00193     ~QWidget();
00194 
00195     int devType() const;
00196 
00197     WId winId() const;
00198     void createWinId(); // internal, going away
00199     inline WId internalWinId() const { return data->winid; }
00200 
00201     // GUI style setting
00202     QStyle *style() const;
00203     void setStyle(QStyle *);
00204     // Widget types and states
00205 
00206     bool isTopLevel() const;
00207     bool isWindow() const;
00208 
00209     bool isModal() const;
00210     Qt::WindowModality windowModality() const;
00211     void setWindowModality(Qt::WindowModality windowModality);
00212 
00213     bool isEnabled() const;
00214     bool isEnabledTo(QWidget*) const;
00215     bool isEnabledToTLW() const;
00216 
00217 public Q_SLOTS:
00218     void setEnabled(bool);
00219     void setDisabled(bool);
00220     void setWindowModified(bool);
00221 
00222     // Widget coordinates
00223 
00224 public:
00225     QRect frameGeometry() const;
00226     const QRect &geometry() const;
00227     QRect normalGeometry() const;
00228 
00229     int x() const;
00230     int y() const;
00231     QPoint pos() const;
00232     QSize frameSize() const;
00233     QSize size() const;
00234     inline int width() const;
00235     inline int height() const;
00236     inline QRect rect() const;
00237     QRect childrenRect() const;
00238     QRegion childrenRegion() const;
00239 
00240     QSize minimumSize() const;
00241     QSize maximumSize() const;
00242     int minimumWidth() const;
00243     int minimumHeight() const;
00244     int maximumWidth() const;
00245     int maximumHeight() const;
00246     void setMinimumSize(const QSize &);
00247     void setMinimumSize(int minw, int minh);
00248     void setMaximumSize(const QSize &);
00249     void setMaximumSize(int maxw, int maxh);
00250     void setMinimumWidth(int minw);
00251     void setMinimumHeight(int minh);
00252     void setMaximumWidth(int maxw);
00253     void setMaximumHeight(int maxh);
00254 
00255     QSize sizeIncrement() const;
00256     void setSizeIncrement(const QSize &);
00257     void setSizeIncrement(int w, int h);
00258     QSize baseSize() const;
00259     void setBaseSize(const QSize &);
00260     void setBaseSize(int basew, int baseh);
00261 
00262     void setFixedSize(const QSize &);
00263     void setFixedSize(int w, int h);
00264     void setFixedWidth(int w);
00265     void setFixedHeight(int h);
00266 
00267     // Widget coordinate mapping
00268 
00269     QPoint mapToGlobal(const QPoint &) const;
00270     QPoint mapFromGlobal(const QPoint &) const;
00271     QPoint mapToParent(const QPoint &) const;
00272     QPoint mapFromParent(const QPoint &) const;
00273     QPoint mapTo(QWidget *, const QPoint &) const;
00274     QPoint mapFrom(QWidget *, const QPoint &) const;
00275 
00276     QWidget *window() const;
00277     inline QWidget *topLevelWidget() const { return window(); }
00278 
00279     // Widget appearance functions
00280     const QPalette &palette() const;
00281     void setPalette(const QPalette &);
00282 
00283     void setBackgroundRole(QPalette::ColorRole);
00284     QPalette::ColorRole backgroundRole() const;
00285 
00286     void setForegroundRole(QPalette::ColorRole);
00287     QPalette::ColorRole foregroundRole() const;
00288 
00289     const QFont &font() const;
00290     void setFont(const QFont &);
00291     QFontMetrics fontMetrics() const;
00292     QFontInfo fontInfo() const;
00293 
00294 #ifndef QT_NO_CURSOR
00295     QCursor cursor() const;
00296     void setCursor(const QCursor &);
00297     void unsetCursor();
00298 #endif
00299 
00300     void setMouseTracking(bool enable);
00301     bool hasMouseTracking() const;
00302     bool underMouse() const;
00303 
00304     void setMask(const QBitmap &);
00305     void setMask(const QRegion &);
00306     QRegion mask() const;
00307     void clearMask();
00308 
00309 public Q_SLOTS:
00310     void setWindowTitle(const QString &);
00311 #ifndef QT_NO_STYLE_STYLESHEET
00312     void setStyleSheet(const QString& styleSheet);
00313 #endif
00314 public:
00315 #ifndef QT_NO_STYLE_STYLESHEET
00316     QString styleSheet() const;
00317 #endif
00318     QString windowTitle() const;
00319     void setWindowIcon(const QIcon &icon);
00320     QIcon windowIcon() const;
00321     void setWindowIconText(const QString &);
00322     QString windowIconText() const;
00323     void setWindowRole(const QString &);
00324     QString windowRole() const;
00325 
00326     void setWindowOpacity(qreal level);
00327     qreal windowOpacity() const;
00328 
00329     bool isWindowModified() const;
00330 #ifndef QT_NO_TOOLTIP
00331     void setToolTip(const QString &);
00332     QString toolTip() const;
00333 #endif
00334 #ifndef QT_NO_STATUSTIP
00335     void setStatusTip(const QString &);
00336     QString statusTip() const;
00337 #endif
00338 #ifndef QT_NO_WHATSTHIS
00339     void setWhatsThis(const QString &);
00340     QString whatsThis() const;
00341 #endif
00342 #ifndef QT_NO_ACCESSIBILITY
00343     QString accessibleName() const;
00344     void setAccessibleName(const QString &name);
00345     QString accessibleDescription() const;
00346     void setAccessibleDescription(const QString &description);
00347 #endif
00348 
00349     void setLayoutDirection(Qt::LayoutDirection direction);
00350     Qt::LayoutDirection layoutDirection() const;
00351     void unsetLayoutDirection();
00352 
00353     inline bool isRightToLeft() const { return layoutDirection() == Qt::RightToLeft; }
00354     inline bool isLeftToRight() const { return layoutDirection() == Qt::LeftToRight; }
00355 
00356 public Q_SLOTS:
00357     inline void setFocus() { setFocus(Qt::OtherFocusReason); }
00358 
00359 public:
00360     bool isActiveWindow() const;
00361     void activateWindow();
00362     void clearFocus();
00363 
00364     void setFocus(Qt::FocusReason reason);
00365     Qt::FocusPolicy focusPolicy() const;
00366     void setFocusPolicy(Qt::FocusPolicy policy);
00367     bool hasFocus() const;
00368     static void setTabOrder(QWidget *, QWidget *);
00369     void setFocusProxy(QWidget *);
00370     QWidget *focusProxy() const;
00371     Qt::ContextMenuPolicy contextMenuPolicy() const;
00372     void setContextMenuPolicy(Qt::ContextMenuPolicy policy);
00373 
00374     // Grab functions
00375     void grabMouse();
00376 #ifndef QT_NO_CURSOR
00377     void grabMouse(const QCursor &);
00378 #endif
00379     void releaseMouse();
00380     void grabKeyboard();
00381     void releaseKeyboard();
00382 #ifndef QT_NO_SHORTCUT
00383     int grabShortcut(const QKeySequence &key, Qt::ShortcutContext context = Qt::WindowShortcut);
00384     void releaseShortcut(int id);
00385     void setShortcutEnabled(int id, bool enable = true);
00386     void setShortcutAutoRepeat(int id, bool enable = true);
00387 #endif
00388     static QWidget *mouseGrabber();
00389     static QWidget *keyboardGrabber();
00390 
00391     // Update/refresh functions
00392     inline bool updatesEnabled() const;
00393     void setUpdatesEnabled(bool enable);
00394 
00395 #if 0 //def Q_WS_QWS
00396     void repaintUnclipped(const QRegion &, bool erase = true);
00397 #endif
00398 
00399 public Q_SLOTS:
00400     void update();
00401     void repaint();
00402 
00403 public:
00404     inline void update(int x, int y, int w, int h);
00405     void update(const QRect&);
00406     void update(const QRegion&);
00407 
00408     void repaint(int x, int y, int w, int h);
00409     void repaint(const QRect &);
00410     void repaint(const QRegion &);
00411 
00412 public Q_SLOTS:
00413     // Widget management functions
00414 
00415     virtual void setVisible(bool visible);
00416     inline void setHidden(bool hidden) { setVisible(!hidden); }
00417     inline void show() { setVisible(true); }
00418     inline void hide() { setVisible(false); }
00419     inline QT_MOC_COMPAT void setShown(bool shown) { setVisible(shown); }
00420 
00421     void showMinimized();
00422     void showMaximized();
00423     void showFullScreen();
00424     void showNormal();
00425 
00426     bool close();
00427     void raise();
00428     void lower();
00429 
00430 public:
00431     void stackUnder(QWidget*);
00432     void move(int x, int y);
00433     void move(const QPoint &);
00434     void resize(int w, int h);
00435     void resize(const QSize &);
00436     inline void setGeometry(int x, int y, int w, int h);
00437     void setGeometry(const QRect &);
00438     QByteArray saveGeometry() const;
00439     bool restoreGeometry(const QByteArray &geometry);
00440     void adjustSize();
00441     bool isVisible() const;
00442     bool isVisibleTo(QWidget*) const;
00443     inline bool isHidden() const;
00444 
00445     bool isMinimized() const;
00446     bool isMaximized() const;
00447     bool isFullScreen() const;
00448 
00449     Qt::WindowStates windowState() const;
00450     void setWindowState(Qt::WindowStates state);
00451     void overrideWindowState(Qt::WindowStates state);
00452 
00453     virtual QSize sizeHint() const;
00454     virtual QSize minimumSizeHint() const;
00455 
00456     QSizePolicy sizePolicy() const;
00457     void setSizePolicy(QSizePolicy);
00458     inline void setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical);
00459     virtual int heightForWidth(int) const;
00460 
00461     QRegion visibleRegion() const;
00462 
00463     void setContentsMargins(int left, int top, int right, int bottom);
00464     void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
00465     QRect contentsRect() const;
00466 
00467 public:
00468     QLayout *layout() const;
00469     void setLayout(QLayout *);
00470     void updateGeometry();
00471 
00472     void setParent(QWidget *parent);
00473     void setParent(QWidget *parent, Qt::WindowFlags f);
00474 
00475     void scroll(int dx, int dy);
00476     void scroll(int dx, int dy, const QRect&);
00477 
00478     // Misc. functions
00479 
00480     QWidget *focusWidget() const;
00481     QWidget *nextInFocusChain() const;
00482 
00483     // drag and drop
00484     bool acceptDrops() const;
00485     void setAcceptDrops(bool on);
00486 
00487 #ifndef QT_NO_ACTION
00488     //actions
00489     void addAction(QAction *action);
00490     void addActions(QList<QAction*> actions);
00491     void insertAction(QAction *before, QAction *action);
00492     void insertActions(QAction *before, QList<QAction*> actions);
00493     void removeAction(QAction *action);
00494     QList<QAction*> actions() const;
00495 #endif
00496 
00497     QWidget *parentWidget() const;
00498 
00499     void setWindowFlags(Qt::WindowFlags type);
00500     inline Qt::WindowFlags windowFlags() const;
00501     void overrideWindowFlags(Qt::WindowFlags type);
00502 
00503     inline Qt::WindowType windowType() const;
00504 
00505     static QWidget *find(WId);
00506 #ifdef QT3_SUPPORT
00507     static QT3_SUPPORT QWidgetMapper *wmapper();
00508 #endif
00509     inline QWidget *childAt(int x, int y) const;
00510     QWidget *childAt(const QPoint &p) const;
00511 
00512 #if defined(Q_WS_X11)
00513     const QX11Info &x11Info() const;
00514     Qt::HANDLE x11PictureHandle() const;
00515 #endif
00516 
00517 #if defined(Q_WS_WIN)
00518     HDC getDC() const;
00519     void releaseDC(HDC) const;
00520 #else
00521     Qt::HANDLE handle() const;
00522 #endif
00523 
00524     void setAttribute(Qt::WidgetAttribute, bool on = true);
00525     inline bool testAttribute(Qt::WidgetAttribute) const;
00526 
00527     QPaintEngine *paintEngine() const;
00528 
00529     void ensurePolished() const;
00530 
00531     QInputContext *inputContext();
00532     void setInputContext(QInputContext *);
00533 
00534     bool isAncestorOf(const QWidget *child) const;
00535 
00536 #ifdef QT_KEYPAD_NAVIGATION
00537     bool hasEditFocus() const;
00538     void setEditFocus(bool on);
00539 #endif
00540 
00541     bool autoFillBackground() const;
00542     void setAutoFillBackground(bool enabled);
00543 
00544     void setWindowSurface(QWindowSurface *surface);
00545     QWindowSurface *windowSurface() const;
00546 
00547 Q_SIGNALS:
00548     void customContextMenuRequested(const QPoint &pos);
00549 
00550 protected:
00551     // Event handlers
00552     bool event(QEvent *);
00553     virtual void mousePressEvent(QMouseEvent *);
00554     virtual void mouseReleaseEvent(QMouseEvent *);
00555     virtual void mouseDoubleClickEvent(QMouseEvent *);
00556     virtual void mouseMoveEvent(QMouseEvent *);
00557 #ifndef QT_NO_WHEELEVENT
00558     virtual void wheelEvent(QWheelEvent *);
00559 #endif
00560     virtual void keyPressEvent(QKeyEvent *);
00561     virtual void keyReleaseEvent(QKeyEvent *);
00562     virtual void focusInEvent(QFocusEvent *);
00563     virtual void focusOutEvent(QFocusEvent *);
00564     virtual void enterEvent(QEvent *);
00565     virtual void leaveEvent(QEvent *);
00566     virtual void paintEvent(QPaintEvent *);
00567     virtual void moveEvent(QMoveEvent *);
00568     virtual void resizeEvent(QResizeEvent *);
00569     virtual void closeEvent(QCloseEvent *);
00570     virtual void contextMenuEvent(QContextMenuEvent *);
00571 #ifndef QT_NO_TABLETEVENT
00572     virtual void tabletEvent(QTabletEvent *);
00573 #endif
00574 #ifndef QT_NO_ACTION
00575     virtual void actionEvent(QActionEvent *);
00576 #endif
00577 
00578 #ifndef QT_NO_DRAGANDDROP
00579     virtual void dragEnterEvent(QDragEnterEvent *);
00580     virtual void dragMoveEvent(QDragMoveEvent *);
00581     virtual void dragLeaveEvent(QDragLeaveEvent *);
00582     virtual void dropEvent(QDropEvent *);
00583 #endif
00584 
00585     virtual void showEvent(QShowEvent *);
00586     virtual void hideEvent(QHideEvent *);
00587 
00588 #if defined(Q_WS_MAC)
00589     virtual bool macEvent(EventHandlerCallRef, EventRef);
00590 #endif
00591 #if defined(Q_WS_WIN)
00592     virtual bool winEvent(MSG *message, long *result);
00593 #endif
00594 #if defined(Q_WS_X11)
00595     virtual bool x11Event(XEvent *);
00596 #endif
00597 #if defined(Q_WS_QWS)
00598     virtual bool qwsEvent(QWSEvent *);
00599 #endif
00600 
00601     // Misc. protected functions
00602     virtual void changeEvent(QEvent *);
00603 
00604     int metric(PaintDeviceMetric) const;
00605 
00606     virtual void inputMethodEvent(QInputMethodEvent *);
00607 public:
00608     virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const;
00609 protected:
00610     void resetInputContext();
00611 protected Q_SLOTS:
00612     void updateMicroFocus();
00613 protected:
00614 
00615     void create(WId = 0, bool initializeWindow = true,
00616                          bool destroyOldWindow = true);
00617     void destroy(bool destroyWindow = true,
00618                  bool destroySubWindows = true);
00619 
00620     virtual bool focusNextPrevChild(bool next);
00621     inline bool focusNextChild() { return focusNextPrevChild(true); }
00622     inline bool focusPreviousChild() { return focusNextPrevChild(false); }
00623 
00624 protected:
00625     QWidget(QWidgetPrivate &d, QWidget* parent, Qt::WindowFlags f);
00626 private:
00627 
00628     bool testAttribute_helper(Qt::WidgetAttribute) const;
00629 
00630     friend void qt_syncBackingStore(QWidget *);
00631     friend void qt_syncBackingStore(QRegion, QWidget *);
00632     friend void qt_syncBackingStore(QRegion, QWidget *, bool);
00633     friend class QBackingStoreDevice;
00634     friend class QWidgetBackingStore;
00635     friend class QApplication;
00636     friend class QApplicationPrivate;
00637     friend class QBaseApplication;
00638     friend class QPainter;
00639     friend class QPixmap; // for QPixmap::fill()
00640     friend class QFontMetrics;
00641     friend class QFontInfo;
00642     friend class QETWidget;
00643     friend class QLayout;
00644     friend class QWidgetItem;
00645     friend class QGLContext;
00646     friend class QX11PaintEngine;
00647     friend class QWin32PaintEngine;
00648     friend class QShortcutPrivate;
00649 
00650 #ifdef Q_WS_MAC
00651     friend class QMacSavedPortInfo;
00652     friend class QCoreGraphicsPaintEnginePrivate;
00653     friend QPoint qt_mac_posInWindow(const QWidget *w);
00654     friend WindowPtr qt_mac_window_for(const QWidget *w);
00655     friend bool qt_mac_is_metal(const QWidget *w);
00656     friend HIViewRef qt_mac_hiview_for(const QWidget *w);
00657 #endif
00658 #ifdef Q_WS_QWS
00659     friend class QWSBackingStore;
00660     friend class QWSManager;
00661     friend class QWSManagerPrivate;
00662     friend class QDecoration;
00663     friend class QWSWindowSurface;
00664 #endif
00665 
00666     friend Q_GUI_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget);
00667 
00668 private:
00669     Q_DISABLE_COPY(QWidget)
00670     Q_PRIVATE_SLOT(d_func(), void _q_showIfNotHidden())
00671 
00672     QWidgetData *data;
00673 
00674 #ifdef QT3_SUPPORT
00675 public:
00676     inline QT3_SUPPORT bool isUpdatesEnabled() const { return updatesEnabled(); }
00677     QT3_SUPPORT QStyle *setStyle(const QString&);
00678     inline QT3_SUPPORT bool isVisibleToTLW() const;
00679     QT3_SUPPORT QRect visibleRect() const;
00680     inline QT3_SUPPORT void iconify() { showMinimized(); }
00681     inline QT3_SUPPORT void constPolish() const { ensurePolished(); }
00682     inline QT3_SUPPORT void polish() { ensurePolished(); }
00683     inline QT3_SUPPORT void reparent(QWidget *parent, Qt::WindowFlags f, const QPoint &p, bool showIt=false)
00684     { setParent(parent, f); setGeometry(p.x(),p.y(),width(),height()); if (showIt) show(); }
00685     inline QT3_SUPPORT void reparent(QWidget *parent, const QPoint &p, bool showIt=false)
00686     { setParent(parent, windowFlags() & ~Qt::WindowType_Mask); setGeometry(p.x(),p.y(),width(),height()); if (showIt) show(); }
00687     inline QT3_SUPPORT void recreate(QWidget *parent, Qt::WindowFlags f, const QPoint & p, bool showIt=false)
00688     { setParent(parent, f); setGeometry(p.x(),p.y(),width(),height()); if (showIt) show(); }
00689     inline QT3_SUPPORT void setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver, bool hfw)
00690     { QSizePolicy sp(hor, ver); sp.setHeightForWidth(hfw); setSizePolicy(sp);}
00691     inline QT3_SUPPORT bool hasMouse() const { return testAttribute(Qt::WA_UnderMouse); }
00692 #ifndef QT_NO_CURSOR
00693     inline QT3_SUPPORT bool ownCursor() const { return testAttribute(Qt::WA_SetCursor); }
00694 #endif
00695     inline QT3_SUPPORT bool ownFont() const { return testAttribute(Qt::WA_SetFont); }
00696     inline QT3_SUPPORT void unsetFont() { setFont(QFont()); }
00697     inline QT3_SUPPORT bool ownPalette() const { return testAttribute(Qt::WA_SetPalette); }
00698     inline QT3_SUPPORT void unsetPalette() { setPalette(QPalette()); }
00699     Qt::BackgroundMode QT3_SUPPORT backgroundMode() const;
00700     void QT3_SUPPORT setBackgroundMode(Qt::BackgroundMode, Qt::BackgroundMode = Qt::PaletteBackground);
00701     const QT3_SUPPORT QColor &eraseColor() const;
00702     void QT3_SUPPORT setEraseColor(const QColor &);
00703     const QT3_SUPPORT QColor &foregroundColor() const;
00704     const QT3_SUPPORT QPixmap *erasePixmap() const;
00705     void QT3_SUPPORT setErasePixmap(const QPixmap &);
00706     const QT3_SUPPORT QColor &paletteForegroundColor() const;
00707     void QT3_SUPPORT setPaletteForegroundColor(const QColor &);
00708     const QT3_SUPPORT QColor &paletteBackgroundColor() const;
00709     void QT3_SUPPORT setPaletteBackgroundColor(const QColor &);
00710     const QT3_SUPPORT QPixmap *paletteBackgroundPixmap() const;
00711     void QT3_SUPPORT setPaletteBackgroundPixmap(const QPixmap &);
00712     const QT3_SUPPORT QBrush& backgroundBrush() const;
00713     const QT3_SUPPORT QColor &backgroundColor() const;
00714     const QT3_SUPPORT QPixmap *backgroundPixmap() const;
00715     void QT3_SUPPORT setBackgroundPixmap(const QPixmap &);
00716     QT3_SUPPORT void setBackgroundColor(const QColor &);
00717     QT3_SUPPORT QColorGroup colorGroup() const;
00718     QT3_SUPPORT QWidget *parentWidget(bool sameWindow) const;
00719     inline QT3_SUPPORT void setKeyCompression(bool b) { setAttribute(Qt::WA_KeyCompression, b); }
00720     inline QT3_SUPPORT void setFont(const QFont &f, bool) { setFont(f); }
00721     inline QT3_SUPPORT void setPalette(const QPalette &p, bool) { setPalette(p); }
00722     enum BackgroundOrigin { WidgetOrigin, ParentOrigin, WindowOrigin, AncestorOrigin };
00723     inline QT3_SUPPORT void setBackgroundOrigin(BackgroundOrigin){};
00724     inline QT3_SUPPORT BackgroundOrigin backgroundOrigin() const { return WindowOrigin; }
00725     inline QT3_SUPPORT QPoint backgroundOffset() const { return QPoint(); }
00726     inline QT3_SUPPORT void repaint(bool) { repaint(); }
00727     inline QT3_SUPPORT void repaint(int x, int y, int w, int h, bool) { repaint(x,y,w,h); }
00728     inline QT3_SUPPORT void repaint(const QRect &r, bool) { repaint(r); }
00729     inline QT3_SUPPORT void repaint(const QRegion &rgn, bool) { repaint(rgn); }
00730     QT3_SUPPORT void erase();
00731     inline QT3_SUPPORT void erase(int x, int y, int w, int h) { erase_helper(x, y, w, h); }
00732     QT3_SUPPORT void erase(const QRect &);
00733     QT3_SUPPORT void erase(const QRegion &);
00734     QT3_SUPPORT void drawText(const QPoint &p, const QString &s)
00735     { drawText_helper(p.x(), p.y(), s); }
00736     inline QT3_SUPPORT void drawText(int x, int y, const QString &s)
00737     { drawText_helper(x, y, s); }
00738     QT3_SUPPORT bool close(bool);
00739     inline QT3_SUPPORT QWidget *childAt(int x, int y, bool includeThis) const
00740     {
00741         QWidget *w = childAt(x, y);
00742         return w ? w : ((includeThis && rect().contains(x,y))?const_cast<QWidget*>(this):0);
00743     }
00744     inline QT3_SUPPORT QWidget *childAt(const QPoint &p, bool includeThis) const
00745     {
00746         QWidget *w = childAt(p);
00747         return w ? w : ((includeThis && rect().contains(p))?const_cast<QWidget*>(this):0);
00748     }
00749     inline QT3_SUPPORT void setCaption(const QString &c)   { setWindowTitle(c); }
00750     QT3_SUPPORT void setIcon(const QPixmap &i);
00751     inline QT3_SUPPORT void setIconText(const QString &it) { setWindowIconText(it); }
00752     inline QT3_SUPPORT QString caption() const             { return windowTitle(); }
00753     QT3_SUPPORT const QPixmap *icon() const;
00754     inline QT3_SUPPORT QString iconText() const            { return windowIconText(); }
00755     inline QT3_SUPPORT void setInputMethodEnabled(bool b) { setAttribute(Qt::WA_InputMethodEnabled, b); }
00756     inline QT3_SUPPORT bool isInputMethodEnabled() const { return testAttribute(Qt::WA_InputMethodEnabled); }
00757     inline QT3_SUPPORT void setActiveWindow() { activateWindow(); }
00758     inline QT3_SUPPORT bool isShown() const { return !isHidden(); }
00759     inline QT3_SUPPORT bool isDialog() const { return windowType() == Qt::Dialog; }
00760     inline QT3_SUPPORT bool isPopup() const { return windowType() == Qt::Popup; }
00761     inline QT3_SUPPORT bool isDesktop() const { return windowType() == Qt::Desktop; }
00762 
00763 
00764 private:
00765     void drawText_helper(int x, int y, const QString &);
00766     void erase_helper(int x, int y, int w, int h);
00767 #endif // QT3_SUPPORT
00768 
00769 protected:
00770     virtual void styleChange(QStyle&); // compat
00771     virtual void enabledChange(bool);  // compat
00772     virtual void paletteChange(const QPalette &);  // compat
00773     virtual void fontChange(const QFont &); // compat
00774     virtual void windowActivationChange(bool);  // compat
00775     virtual void languageChange();  // compat
00776 };
00777 
00778 #if defined Q_CC_MSVC && _MSC_VER < 1300
00779 template <> inline QWidget *qobject_cast_helper<QWidget*>(QObject *o, QWidget *)
00780 {
00781     if (!o || !o->isWidgetType()) return 0;
00782     return (QWidget*)(o);
00783 }
00784 #else
00785 template <> inline QWidget *qobject_cast<QWidget*>(QObject *o)
00786 {
00787     if (!o || !o->isWidgetType()) return 0;
00788     return static_cast<QWidget*>(o);
00789 }
00790 template <> inline const QWidget *qobject_cast<const QWidget*>(const QObject *o)
00791 {
00792     if (!o || !o->isWidgetType()) return 0;
00793     return static_cast<const QWidget*>(o);
00794 }
00795 #endif
00796 
00797 inline QWidget *QWidget::childAt(int ax, int ay) const
00798 { return childAt(QPoint(ax, ay)); }
00799 
00800 inline Qt::WindowType QWidget::windowType() const
00801 { return static_cast<Qt::WindowType>(int(data->window_flags & Qt::WindowType_Mask)); }
00802 inline Qt::WindowFlags QWidget::windowFlags() const
00803 { return data->window_flags; }
00804 
00805 inline bool QWidget::isTopLevel() const
00806 { return (windowType() & Qt::Window); }
00807 
00808 inline bool QWidget::isWindow() const
00809 { return (windowType() & Qt::Window); }
00810 
00811 inline bool QWidget::isEnabled() const
00812 { return !testAttribute(Qt::WA_Disabled); }
00813 
00814 inline bool QWidget::isModal() const
00815 { return data->window_modality != Qt::NonModal; }
00816 
00817 inline bool QWidget::isEnabledToTLW() const
00818 { return isEnabled(); }
00819 
00820 inline int QWidget::minimumWidth() const
00821 { return minimumSize().width(); }
00822 
00823 inline int QWidget::minimumHeight() const
00824 { return minimumSize().height(); }
00825 
00826 inline int QWidget::maximumWidth() const
00827 { return maximumSize().width(); }
00828 
00829 inline int QWidget::maximumHeight() const
00830 { return maximumSize().height(); }
00831 
00832 inline void QWidget::setMinimumSize(const QSize &s)
00833 { setMinimumSize(s.width(),s.height()); }
00834 
00835 inline void QWidget::setMaximumSize(const QSize &s)
00836 { setMaximumSize(s.width(),s.height()); }
00837 
00838 inline void QWidget::setSizeIncrement(const QSize &s)
00839 { setSizeIncrement(s.width(),s.height()); }
00840 
00841 inline void QWidget::setBaseSize(const QSize &s)
00842 { setBaseSize(s.width(),s.height()); }
00843 
00844 inline const QFont &QWidget::font() const
00845 { return data->fnt; }
00846 
00847 inline QFontMetrics QWidget::fontMetrics() const
00848 { return QFontMetrics(data->fnt); }
00849 
00850 inline QFontInfo QWidget::fontInfo() const
00851 { return QFontInfo(data->fnt); }
00852 
00853 inline void QWidget::setMouseTracking(bool enable)
00854 { setAttribute(Qt::WA_MouseTracking, enable); }
00855 
00856 inline bool QWidget::hasMouseTracking() const
00857 { return testAttribute(Qt::WA_MouseTracking); }
00858 
00859 inline bool QWidget::underMouse() const
00860 { return testAttribute(Qt::WA_UnderMouse); }
00861 
00862 inline bool QWidget::updatesEnabled() const
00863 { return !testAttribute(Qt::WA_UpdatesDisabled); }
00864 
00865 inline void QWidget::update(int ax, int ay, int aw, int ah)
00866 { update(QRect(ax, ay, aw, ah)); }
00867 
00868 inline bool QWidget::isVisible() const
00869 { return testAttribute(Qt::WA_WState_Visible); }
00870 
00871 inline bool QWidget::isHidden() const
00872 { return testAttribute(Qt::WA_WState_Hidden); }
00873 
00874 inline void QWidget::move(int ax, int ay)
00875 { move(QPoint(ax, ay)); }
00876 
00877 inline void QWidget::resize(int w, int h)
00878 { resize(QSize(w, h)); }
00879 
00880 inline void QWidget::setGeometry(int ax, int ay, int aw, int ah)
00881 { setGeometry(QRect(ax, ay, aw, ah)); }
00882 
00883 inline QRect QWidget::rect() const
00884 { return QRect(0,0,data->crect.width(),data->crect.height()); }
00885 
00886 inline const QRect &QWidget::geometry() const
00887 { return data->crect; }
00888 
00889 inline QSize QWidget::size() const
00890 { return data->crect.size(); }
00891 
00892 inline int QWidget::width() const
00893 { return data->crect.width(); }
00894 
00895 inline int QWidget::height() const
00896 { return data->crect.height(); }
00897 
00898 inline QWidget *QWidget::parentWidget() const
00899 { return static_cast<QWidget *>(QObject::parent()); }
00900 
00901 inline void QWidget::setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver)
00902 { setSizePolicy(QSizePolicy(hor, ver)); }
00903 
00904 inline bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const
00905 {
00906     if (attribute < int(8*sizeof(uint)))
00907         return data->widget_attributes & (1<<attribute);
00908     return testAttribute_helper(attribute);
00909 }
00910 
00911 #ifdef QT3_SUPPORT
00912 inline bool QWidget::isVisibleToTLW() const
00913 { return isVisible(); }
00914 inline QWidget *QWidget::parentWidget(bool sameWindow) const
00915 {
00916     if (sameWindow && isWindow())
00917         return 0;
00918     return static_cast<QWidget *>(QObject::parent());
00919 }
00920 inline QColorGroup QWidget::colorGroup() const
00921 { return QColorGroup(palette()); }
00922 inline void QWidget::setPaletteForegroundColor(const QColor &c)
00923 { QPalette p = palette(); p.setColor(foregroundRole(), c); setPalette(p); }
00924 inline const QBrush& QWidget::backgroundBrush() const { return palette().brush(backgroundRole()); }
00925 inline void QWidget::setBackgroundPixmap(const QPixmap &pm)
00926 { QPalette p = palette(); p.setBrush(backgroundRole(), QBrush(pm)); setPalette(p); }
00927 inline const QPixmap *QWidget::backgroundPixmap() const { return 0; }
00928 inline void QWidget::setBackgroundColor(const QColor &c)
00929 { QPalette p = palette(); p.setColor(backgroundRole(), c); setPalette(p); }
00930 inline const QColor & QWidget::backgroundColor() const { return palette().color(backgroundRole()); }
00931 inline const QColor &QWidget::foregroundColor() const { return palette().color(foregroundRole());}
00932 inline const QColor &QWidget::eraseColor() const { return palette().color(backgroundRole()); }
00933 inline void QWidget::setEraseColor(const QColor &c)
00934 { QPalette p = palette(); p.setColor(backgroundRole(), c); setPalette(p); }
00935 inline const QPixmap *QWidget::erasePixmap() const { return 0; }
00936 inline void QWidget::setErasePixmap(const QPixmap &pm)
00937 { QPalette p = palette(); p.setBrush(backgroundRole(), QBrush(pm)); setPalette(p); }
00938 inline const QColor &QWidget::paletteForegroundColor() const { return palette().color(foregroundRole());}
00939 inline const QColor &QWidget::paletteBackgroundColor() const { return palette().color(backgroundRole()); }
00940 inline void QWidget::setPaletteBackgroundColor(const QColor &c)
00941 { QPalette p = palette(); p.setColor(backgroundRole(), c); setPalette(p); }
00942 inline const QPixmap *QWidget::paletteBackgroundPixmap() const
00943 { return 0; }
00944 inline void QWidget::setPaletteBackgroundPixmap(const QPixmap &pm)
00945 { QPalette p = palette(); p.setBrush(backgroundRole(), QBrush(pm)); setPalette(p); }
00946 inline QT3_SUPPORT void QWidget::erase() { erase_helper(0, 0, data->crect.width(), data->crect.height()); }
00947 inline QT3_SUPPORT void QWidget::erase(const QRect &r) { erase_helper(r.x(), r.y(), r.width(), r.height()); }
00948 #endif
00949 
00950 #define QWIDGETSIZE_MAX ((1<<24)-1)
00951 
00952 QT_END_HEADER
00953 
00954 #endif // QWIDGET_H

Generated on Thu Mar 15 11:55:18 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1