source: trunk/src/gui/kernel/qwidget.h@ 441

Last change on this file since 441 was 352, checked in by Dmitry A. Kuminov, 16 years ago

gui/kernel: Added QWidget::internalFrameWinId() and effectiveFrameWinId() non-portable OS/2-specific functions for easy access to the frame window of top-level widgets which may sometimes be necessary for tighter integration with the platform.

File size: 36.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information (qt-info@nokia.com)
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at qt-sales@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QWIDGET_H
43#define QWIDGET_H
44
45#include <QtGui/qwindowdefs.h>
46#include <QtCore/qobject.h>
47#include <QtGui/qpaintdevice.h>
48#include <QtGui/qpalette.h>
49#include <QtGui/qfont.h>
50#include <QtGui/qfontmetrics.h>
51#include <QtGui/qfontinfo.h>
52#include <QtGui/qsizepolicy.h>
53#include <QtGui/qregion.h>
54#include <QtGui/qbrush.h>
55#include <QtGui/qcursor.h>
56#include <QtGui/qkeysequence.h>
57
58#ifdef QT_INCLUDE_COMPAT
59#include <QtGui/qevent.h>
60#endif
61
62QT_BEGIN_HEADER
63
64QT_BEGIN_NAMESPACE
65
66QT_MODULE(Gui)
67
68class QLayout;
69class QWSRegionManager;
70class QStyle;
71class QAction;
72class QVariant;
73
74class QActionEvent;
75class QMouseEvent;
76class QWheelEvent;
77class QHoverEvent;
78class QKeyEvent;
79class QFocusEvent;
80class QPaintEvent;
81class QMoveEvent;
82class QResizeEvent;
83class QCloseEvent;
84class QContextMenuEvent;
85class QInputMethodEvent;
86class QTabletEvent;
87class QDragEnterEvent;
88class QDragMoveEvent;
89class QDragLeaveEvent;
90class QDropEvent;
91class QShowEvent;
92class QHideEvent;
93class QInputContext;
94class QIcon;
95class QWindowSurface;
96class QLocale;
97class QGraphicsProxyWidget;
98#if defined(Q_WS_X11)
99class QX11Info;
100#endif
101
102class QWidgetData
103{
104public:
105 WId winid;
106 uint widget_attributes;
107 Qt::WindowFlags window_flags;
108 uint window_state : 4;
109 uint focus_policy : 4;
110 uint sizehint_forced :1;
111 uint is_closing :1;
112 uint in_show : 1;
113 uint in_set_window_state : 1;
114 mutable uint fstrut_dirty : 1;
115 uint context_menu_policy : 3;
116 uint window_modality : 2;
117 uint in_destructor : 1;
118 uint unused : 13;
119 QRect crect;
120 mutable QPalette pal;
121 QFont fnt;
122#if defined(Q_WS_QWS)
123// QRegion req_region; // Requested region
124// mutable QRegion paintable_region; // Paintable region
125// mutable bool paintable_region_dirty;// needs to be recalculated
126// mutable QRegion alloc_region; // Allocated region
127// mutable bool alloc_region_dirty; // needs to be recalculated
128// mutable int overlapping_children; // Handle overlapping children
129
130 int alloc_region_index;
131// int alloc_region_revision;
132#endif
133#if defined(Q_OS_WINCE)
134 uint window_state_internal : 4;
135#endif
136 QRect wrect;
137};
138
139class QWidgetPrivate;
140
141class Q_GUI_EXPORT QWidget : public QObject, public QPaintDevice
142{
143 Q_OBJECT
144 Q_DECLARE_PRIVATE(QWidget)
145
146 Q_PROPERTY(bool modal READ isModal)
147 Q_PROPERTY(Qt::WindowModality windowModality READ windowModality WRITE setWindowModality)
148 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
149 Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry)
150 Q_PROPERTY(QRect frameGeometry READ frameGeometry)
151 Q_PROPERTY(QRect normalGeometry READ normalGeometry)
152 Q_PROPERTY(int x READ x)
153 Q_PROPERTY(int y READ y)
154 Q_PROPERTY(QPoint pos READ pos WRITE move DESIGNABLE false STORED false)
155 Q_PROPERTY(QSize frameSize READ frameSize)
156 Q_PROPERTY(QSize size READ size WRITE resize DESIGNABLE false STORED false)
157 Q_PROPERTY(int width READ width)
158 Q_PROPERTY(int height READ height)
159 Q_PROPERTY(QRect rect READ rect)
160 Q_PROPERTY(QRect childrenRect READ childrenRect)
161 Q_PROPERTY(QRegion childrenRegion READ childrenRegion)
162 Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)
163 Q_PROPERTY(QSize minimumSize READ minimumSize WRITE setMinimumSize)
164 Q_PROPERTY(QSize maximumSize READ maximumSize WRITE setMaximumSize)
165 Q_PROPERTY(int minimumWidth READ minimumWidth WRITE setMinimumWidth STORED false DESIGNABLE false)
166 Q_PROPERTY(int minimumHeight READ minimumHeight WRITE setMinimumHeight STORED false DESIGNABLE false)
167 Q_PROPERTY(int maximumWidth READ maximumWidth WRITE setMaximumWidth STORED false DESIGNABLE false)
168 Q_PROPERTY(int maximumHeight READ maximumHeight WRITE setMaximumHeight STORED false DESIGNABLE false)
169 Q_PROPERTY(QSize sizeIncrement READ sizeIncrement WRITE setSizeIncrement)
170 Q_PROPERTY(QSize baseSize READ baseSize WRITE setBaseSize)
171 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
172 Q_PROPERTY(QFont font READ font WRITE setFont)
173#ifndef QT_NO_CURSOR
174 Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)
175#endif
176 Q_PROPERTY(bool mouseTracking READ hasMouseTracking WRITE setMouseTracking)
177 Q_PROPERTY(bool isActiveWindow READ isActiveWindow)
178 Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
179 Q_PROPERTY(bool focus READ hasFocus)
180 Q_PROPERTY(Qt::ContextMenuPolicy contextMenuPolicy READ contextMenuPolicy WRITE setContextMenuPolicy)
181 Q_PROPERTY(bool updatesEnabled READ updatesEnabled WRITE setUpdatesEnabled DESIGNABLE false)
182 Q_PROPERTY(bool visible READ isVisible WRITE setVisible DESIGNABLE false)
183 Q_PROPERTY(bool minimized READ isMinimized)
184 Q_PROPERTY(bool maximized READ isMaximized)
185 Q_PROPERTY(bool fullScreen READ isFullScreen)
186 Q_PROPERTY(QSize sizeHint READ sizeHint)
187 Q_PROPERTY(QSize minimumSizeHint READ minimumSizeHint)
188 Q_PROPERTY(bool acceptDrops READ acceptDrops WRITE setAcceptDrops)
189 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle DESIGNABLE isWindow)
190 Q_PROPERTY(QIcon windowIcon READ windowIcon WRITE setWindowIcon DESIGNABLE isWindow)
191 Q_PROPERTY(QString windowIconText READ windowIconText WRITE setWindowIconText DESIGNABLE isWindow)
192 Q_PROPERTY(double windowOpacity READ windowOpacity WRITE setWindowOpacity DESIGNABLE isWindow)
193 Q_PROPERTY(bool windowModified READ isWindowModified WRITE setWindowModified DESIGNABLE isWindow)
194#ifndef QT_NO_TOOLTIP
195 Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip)
196#endif
197#ifndef QT_NO_STATUSTIP
198 Q_PROPERTY(QString statusTip READ statusTip WRITE setStatusTip)
199#endif
200#ifndef QT_NO_WHATSTHIS
201 Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis)
202#endif
203#ifndef QT_NO_ACCESSIBILITY
204 Q_PROPERTY(QString accessibleName READ accessibleName WRITE setAccessibleName)
205 Q_PROPERTY(QString accessibleDescription READ accessibleDescription WRITE setAccessibleDescription)
206#endif
207 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection)
208 QDOC_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
209 Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground)
210#ifndef QT_NO_STYLE_STYLESHEET
211 Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
212#endif
213 Q_PROPERTY(QLocale locale READ locale WRITE setLocale RESET unsetLocale)
214 Q_PROPERTY(QString windowFilePath READ windowFilePath WRITE setWindowFilePath DESIGNABLE isWindow)
215
216public:
217 enum RenderFlag {
218 DrawWindowBackground = 0x1,
219 DrawChildren = 0x2,
220 IgnoreMask = 0x4
221 };
222 Q_DECLARE_FLAGS(RenderFlags, RenderFlag)
223
224 explicit QWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
225#ifdef QT3_SUPPORT
226 QT3_SUPPORT_CONSTRUCTOR QWidget(QWidget* parent, const char *name, Qt::WindowFlags f = 0);
227#endif
228 ~QWidget();
229
230 int devType() const;
231
232 WId winId() const;
233 void createWinId(); // internal, going away
234 inline WId internalWinId() const { return data->winid; }
235 WId effectiveWinId() const;
236
237 // GUI style setting
238 QStyle *style() const;
239 void setStyle(QStyle *);
240 // Widget types and states
241
242 bool isTopLevel() const;
243 bool isWindow() const;
244
245 bool isModal() const;
246 Qt::WindowModality windowModality() const;
247 void setWindowModality(Qt::WindowModality windowModality);
248
249 bool isEnabled() const;
250 bool isEnabledTo(QWidget*) const;
251 bool isEnabledToTLW() const;
252
253public Q_SLOTS:
254 void setEnabled(bool);
255 void setDisabled(bool);
256 void setWindowModified(bool);
257
258 // Widget coordinates
259
260public:
261 QRect frameGeometry() const;
262 const QRect &geometry() const;
263 QRect normalGeometry() const;
264
265 int x() const;
266 int y() const;
267 QPoint pos() const;
268 QSize frameSize() const;
269 QSize size() const;
270 inline int width() const;
271 inline int height() const;
272 inline QRect rect() const;
273 QRect childrenRect() const;
274 QRegion childrenRegion() const;
275
276 QSize minimumSize() const;
277 QSize maximumSize() const;
278 int minimumWidth() const;
279 int minimumHeight() const;
280 int maximumWidth() const;
281 int maximumHeight() const;
282 void setMinimumSize(const QSize &);
283 void setMinimumSize(int minw, int minh);
284 void setMaximumSize(const QSize &);
285 void setMaximumSize(int maxw, int maxh);
286 void setMinimumWidth(int minw);
287 void setMinimumHeight(int minh);
288 void setMaximumWidth(int maxw);
289 void setMaximumHeight(int maxh);
290
291 QSize sizeIncrement() const;
292 void setSizeIncrement(const QSize &);
293 void setSizeIncrement(int w, int h);
294 QSize baseSize() const;
295 void setBaseSize(const QSize &);
296 void setBaseSize(int basew, int baseh);
297
298 void setFixedSize(const QSize &);
299 void setFixedSize(int w, int h);
300 void setFixedWidth(int w);
301 void setFixedHeight(int h);
302
303 // Widget coordinate mapping
304
305 QPoint mapToGlobal(const QPoint &) const;
306 QPoint mapFromGlobal(const QPoint &) const;
307 QPoint mapToParent(const QPoint &) const;
308 QPoint mapFromParent(const QPoint &) const;
309 QPoint mapTo(QWidget *, const QPoint &) const;
310 QPoint mapFrom(QWidget *, const QPoint &) const;
311
312 QWidget *window() const;
313 QWidget *nativeParentWidget() const;
314 inline QWidget *topLevelWidget() const { return window(); }
315
316 // Widget appearance functions
317 const QPalette &palette() const;
318 void setPalette(const QPalette &);
319
320 void setBackgroundRole(QPalette::ColorRole);
321 QPalette::ColorRole backgroundRole() const;
322
323 void setForegroundRole(QPalette::ColorRole);
324 QPalette::ColorRole foregroundRole() const;
325
326 const QFont &font() const;
327 void setFont(const QFont &);
328 QFontMetrics fontMetrics() const;
329 QFontInfo fontInfo() const;
330
331#ifndef QT_NO_CURSOR
332 QCursor cursor() const;
333 void setCursor(const QCursor &);
334 void unsetCursor();
335#endif
336
337 void setMouseTracking(bool enable);
338 bool hasMouseTracking() const;
339 bool underMouse() const;
340
341 void setMask(const QBitmap &);
342 void setMask(const QRegion &);
343 QRegion mask() const;
344 void clearMask();
345
346 void render(QPaintDevice *target, const QPoint &targetOffset = QPoint(),
347 const QRegion &sourceRegion = QRegion(),
348 RenderFlags renderFlags = RenderFlags(DrawWindowBackground | DrawChildren));
349
350 void render(QPainter *painter, const QPoint &targetOffset = QPoint(),
351 const QRegion &sourceRegion = QRegion(),
352 RenderFlags renderFlags = RenderFlags(DrawWindowBackground | DrawChildren));
353
354public Q_SLOTS:
355 void setWindowTitle(const QString &);
356#ifndef QT_NO_STYLE_STYLESHEET
357 void setStyleSheet(const QString& styleSheet);
358#endif
359public:
360#ifndef QT_NO_STYLE_STYLESHEET
361 QString styleSheet() const;
362#endif
363 QString windowTitle() const;
364 void setWindowIcon(const QIcon &icon);
365 QIcon windowIcon() const;
366 void setWindowIconText(const QString &);
367 QString windowIconText() const;
368 void setWindowRole(const QString &);
369 QString windowRole() const;
370 void setWindowFilePath(const QString &filePath);
371 QString windowFilePath() const;
372
373 void setWindowOpacity(qreal level);
374 qreal windowOpacity() const;
375
376 bool isWindowModified() const;
377#ifndef QT_NO_TOOLTIP
378 void setToolTip(const QString &);
379 QString toolTip() const;
380#endif
381#ifndef QT_NO_STATUSTIP
382 void setStatusTip(const QString &);
383 QString statusTip() const;
384#endif
385#ifndef QT_NO_WHATSTHIS
386 void setWhatsThis(const QString &);
387 QString whatsThis() const;
388#endif
389#ifndef QT_NO_ACCESSIBILITY
390 QString accessibleName() const;
391 void setAccessibleName(const QString &name);
392 QString accessibleDescription() const;
393 void setAccessibleDescription(const QString &description);
394#endif
395
396 void setLayoutDirection(Qt::LayoutDirection direction);
397 Qt::LayoutDirection layoutDirection() const;
398 void unsetLayoutDirection();
399
400 void setLocale(const QLocale &locale);
401 QLocale locale() const;
402 void unsetLocale();
403
404 inline bool isRightToLeft() const { return layoutDirection() == Qt::RightToLeft; }
405 inline bool isLeftToRight() const { return layoutDirection() == Qt::LeftToRight; }
406
407public Q_SLOTS:
408 inline void setFocus() { setFocus(Qt::OtherFocusReason); }
409
410public:
411 bool isActiveWindow() const;
412 void activateWindow();
413 void clearFocus();
414
415 void setFocus(Qt::FocusReason reason);
416 Qt::FocusPolicy focusPolicy() const;
417 void setFocusPolicy(Qt::FocusPolicy policy);
418 bool hasFocus() const;
419 static void setTabOrder(QWidget *, QWidget *);
420 void setFocusProxy(QWidget *);
421 QWidget *focusProxy() const;
422 Qt::ContextMenuPolicy contextMenuPolicy() const;
423 void setContextMenuPolicy(Qt::ContextMenuPolicy policy);
424
425 // Grab functions
426 void grabMouse();
427#ifndef QT_NO_CURSOR
428 void grabMouse(const QCursor &);
429#endif
430 void releaseMouse();
431 void grabKeyboard();
432 void releaseKeyboard();
433#ifndef QT_NO_SHORTCUT
434 int grabShortcut(const QKeySequence &key, Qt::ShortcutContext context = Qt::WindowShortcut);
435 void releaseShortcut(int id);
436 void setShortcutEnabled(int id, bool enable = true);
437 void setShortcutAutoRepeat(int id, bool enable = true);
438#endif
439 static QWidget *mouseGrabber();
440 static QWidget *keyboardGrabber();
441
442 // Update/refresh functions
443 inline bool updatesEnabled() const;
444 void setUpdatesEnabled(bool enable);
445
446#if 0 //def Q_WS_QWS
447 void repaintUnclipped(const QRegion &, bool erase = true);
448#endif
449
450#ifndef QT_NO_GRAPHICSVIEW
451 QGraphicsProxyWidget *graphicsProxyWidget() const;
452#endif
453
454public Q_SLOTS:
455 void update();
456 void repaint();
457
458public:
459 inline void update(int x, int y, int w, int h);
460 void update(const QRect&);
461 void update(const QRegion&);
462
463 void repaint(int x, int y, int w, int h);
464 void repaint(const QRect &);
465 void repaint(const QRegion &);
466
467public Q_SLOTS:
468 // Widget management functions
469
470 virtual void setVisible(bool visible);
471 inline void setHidden(bool hidden) { setVisible(!hidden); }
472#ifndef Q_OS_WINCE
473 inline void show() { setVisible(true); }
474#else
475 void show();
476#endif
477 inline void hide() { setVisible(false); }
478 inline QT_MOC_COMPAT void setShown(bool shown) { setVisible(shown); }
479
480 void showMinimized();
481 void showMaximized();
482 void showFullScreen();
483 void showNormal();
484
485 bool close();
486 void raise();
487 void lower();
488
489public:
490 void stackUnder(QWidget*);
491 void move(int x, int y);
492 void move(const QPoint &);
493 void resize(int w, int h);
494 void resize(const QSize &);
495 inline void setGeometry(int x, int y, int w, int h);
496 void setGeometry(const QRect &);
497 QByteArray saveGeometry() const;
498 bool restoreGeometry(const QByteArray &geometry);
499 void adjustSize();
500 bool isVisible() const;
501 bool isVisibleTo(QWidget*) const;
502 // ### Qt 5: bool isVisibleTo(_const_ QWidget *) const
503 inline bool isHidden() const;
504
505 bool isMinimized() const;
506 bool isMaximized() const;
507 bool isFullScreen() const;
508
509 Qt::WindowStates windowState() const;
510 void setWindowState(Qt::WindowStates state);
511 void overrideWindowState(Qt::WindowStates state);
512
513 virtual QSize sizeHint() const;
514 virtual QSize minimumSizeHint() const;
515
516 QSizePolicy sizePolicy() const;
517 void setSizePolicy(QSizePolicy);
518 inline void setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical);
519 virtual int heightForWidth(int) const;
520
521 QRegion visibleRegion() const;
522
523 void setContentsMargins(int left, int top, int right, int bottom);
524 void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
525 QRect contentsRect() const;
526
527public:
528 QLayout *layout() const;
529 void setLayout(QLayout *);
530 void updateGeometry();
531
532 void setParent(QWidget *parent);
533 void setParent(QWidget *parent, Qt::WindowFlags f);
534
535 void scroll(int dx, int dy);
536 void scroll(int dx, int dy, const QRect&);
537
538 // Misc. functions
539
540 QWidget *focusWidget() const;
541 QWidget *nextInFocusChain() const;
542
543 // drag and drop
544 bool acceptDrops() const;
545 void setAcceptDrops(bool on);
546
547#ifndef QT_NO_ACTION
548 //actions
549 void addAction(QAction *action);
550 void addActions(QList<QAction*> actions);
551 void insertAction(QAction *before, QAction *action);
552 void insertActions(QAction *before, QList<QAction*> actions);
553 void removeAction(QAction *action);
554 QList<QAction*> actions() const;
555#endif
556
557 QWidget *parentWidget() const;
558
559 void setWindowFlags(Qt::WindowFlags type);
560 inline Qt::WindowFlags windowFlags() const;
561 void overrideWindowFlags(Qt::WindowFlags type);
562
563 inline Qt::WindowType windowType() const;
564
565 static QWidget *find(WId);
566#ifdef QT3_SUPPORT
567 static QT3_SUPPORT QWidgetMapper *wmapper();
568#endif
569 inline QWidget *childAt(int x, int y) const;
570 QWidget *childAt(const QPoint &p) const;
571
572#if defined(Q_WS_X11)
573 const QX11Info &x11Info() const;
574 Qt::HANDLE x11PictureHandle() const;
575#endif
576
577#if defined(Q_WS_MAC)
578 Qt::HANDLE macQDHandle() const;
579 Qt::HANDLE macCGHandle() const;
580#endif
581
582#if defined(Q_WS_WIN)
583 HDC getDC() const;
584 void releaseDC(HDC) const;
585#elif defined(Q_WS_PM)
586 WId internalFrameWinId() const;
587 WId effectiveFrameWinId() const;
588 HPS getPS() const;
589 void releasePS(HPS) const;
590#else
591 Qt::HANDLE handle() const;
592#endif
593
594 void setAttribute(Qt::WidgetAttribute, bool on = true);
595 inline bool testAttribute(Qt::WidgetAttribute) const;
596
597 QPaintEngine *paintEngine() const;
598
599 void ensurePolished() const;
600
601 QInputContext *inputContext();
602 void setInputContext(QInputContext *);
603
604 bool isAncestorOf(const QWidget *child) const;
605
606#ifdef QT_KEYPAD_NAVIGATION
607 bool hasEditFocus() const;
608 void setEditFocus(bool on);
609#endif
610
611 bool autoFillBackground() const;
612 void setAutoFillBackground(bool enabled);
613
614 void setWindowSurface(QWindowSurface *surface);
615 QWindowSurface *windowSurface() const;
616
617Q_SIGNALS:
618 void customContextMenuRequested(const QPoint &pos);
619
620protected:
621 // Event handlers
622 bool event(QEvent *);
623 virtual void mousePressEvent(QMouseEvent *);
624 virtual void mouseReleaseEvent(QMouseEvent *);
625 virtual void mouseDoubleClickEvent(QMouseEvent *);
626 virtual void mouseMoveEvent(QMouseEvent *);
627#ifndef QT_NO_WHEELEVENT
628 virtual void wheelEvent(QWheelEvent *);
629#endif
630 virtual void keyPressEvent(QKeyEvent *);
631 virtual void keyReleaseEvent(QKeyEvent *);
632 virtual void focusInEvent(QFocusEvent *);
633 virtual void focusOutEvent(QFocusEvent *);
634 virtual void enterEvent(QEvent *);
635 virtual void leaveEvent(QEvent *);
636 virtual void paintEvent(QPaintEvent *);
637 virtual void moveEvent(QMoveEvent *);
638 virtual void resizeEvent(QResizeEvent *);
639 virtual void closeEvent(QCloseEvent *);
640#ifndef QT_NO_CONTEXTMENU
641 virtual void contextMenuEvent(QContextMenuEvent *);
642#endif
643#ifndef QT_NO_TABLETEVENT
644 virtual void tabletEvent(QTabletEvent *);
645#endif
646#ifndef QT_NO_ACTION
647 virtual void actionEvent(QActionEvent *);
648#endif
649
650#ifndef QT_NO_DRAGANDDROP
651 virtual void dragEnterEvent(QDragEnterEvent *);
652 virtual void dragMoveEvent(QDragMoveEvent *);
653 virtual void dragLeaveEvent(QDragLeaveEvent *);
654 virtual void dropEvent(QDropEvent *);
655#endif
656
657 virtual void showEvent(QShowEvent *);
658 virtual void hideEvent(QHideEvent *);
659
660#if defined(Q_WS_MAC)
661 virtual bool macEvent(EventHandlerCallRef, EventRef);
662#endif
663#if defined(Q_WS_WIN)
664 virtual bool winEvent(MSG *message, long *result);
665#endif
666#if defined(Q_WS_PM)
667 virtual bool pmEvent(QMSG *message, MRESULT *result);
668#endif
669#if defined(Q_WS_X11)
670 virtual bool x11Event(XEvent *);
671#endif
672#if defined(Q_WS_QWS)
673 virtual bool qwsEvent(QWSEvent *);
674#endif
675
676 // Misc. protected functions
677 virtual void changeEvent(QEvent *);
678
679 int metric(PaintDeviceMetric) const;
680
681 virtual void inputMethodEvent(QInputMethodEvent *);
682public:
683 virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const;
684protected:
685 void resetInputContext();
686protected Q_SLOTS:
687 void updateMicroFocus();
688protected:
689
690 void create(WId = 0, bool initializeWindow = true,
691 bool destroyOldWindow = true);
692 void destroy(bool destroyWindow = true,
693 bool destroySubWindows = true);
694
695 virtual bool focusNextPrevChild(bool next);
696 inline bool focusNextChild() { return focusNextPrevChild(true); }
697 inline bool focusPreviousChild() { return focusNextPrevChild(false); }
698
699protected:
700 QWidget(QWidgetPrivate &d, QWidget* parent, Qt::WindowFlags f);
701private:
702
703 bool testAttribute_helper(Qt::WidgetAttribute) const;
704
705 QLayout *takeLayout();
706
707 friend class QBackingStoreDevice;
708 friend class QWidgetBackingStore;
709 friend class QApplication;
710 friend class QApplicationPrivate;
711 friend class QBaseApplication;
712 friend class QPainter;
713 friend class QPainterPrivate;
714 friend class QPixmap; // for QPixmap::fill()
715 friend class QFontMetrics;
716 friend class QFontInfo;
717 friend class QETWidget;
718 friend class QLayout;
719 friend class QWidgetItem;
720 friend class QWidgetItemV2;
721 friend class QGLContext;
722 friend class QGLWidget;
723 friend class QGLWindowSurface;
724 friend class QVGWindowSurface;
725 friend class QX11PaintEngine;
726 friend class QWin32PaintEngine;
727 friend class QShortcutPrivate;
728 friend class QShortcutMap;
729 friend class QWindowSurface;
730 friend class QD3DWindowSurface;
731 friend class QGraphicsProxyWidget;
732 friend class QGraphicsProxyWidgetPrivate;
733 friend class QStyleSheetStyle;
734
735#ifdef Q_WS_MAC
736 friend class QCoreGraphicsPaintEnginePrivate;
737 friend QPoint qt_mac_posInWindow(const QWidget *w);
738 friend OSWindowRef qt_mac_window_for(const QWidget *w);
739 friend bool qt_mac_is_metal(const QWidget *w);
740 friend OSViewRef qt_mac_nativeview_for(const QWidget *w);
741 friend void qt_event_request_window_change(QWidget *widget);
742 friend bool qt_mac_sendMacEventToWidget(QWidget *widget, EventRef ref);
743#endif
744#ifdef Q_WS_QWS
745 friend class QWSBackingStore;
746 friend class QWSManager;
747 friend class QWSManagerPrivate;
748 friend class QDecoration;
749 friend class QWSWindowSurface;
750 friend class QScreen;
751 friend class QVNCScreen;
752 friend bool isWidgetOpaque(const QWidget *);
753 friend class QGLWidgetPrivate;
754#endif
755#ifdef Q_WS_X11
756 friend void qt_net_update_user_time(QWidget *tlw, unsigned long timestamp);
757 friend void qt_net_remove_user_time(QWidget *tlw);
758#endif
759
760 friend Q_GUI_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget);
761 friend Q_GUI_EXPORT QWidgetPrivate *qt_widget_private(QWidget *widget);
762
763private:
764 Q_DISABLE_COPY(QWidget)
765 Q_PRIVATE_SLOT(d_func(), void _q_showIfNotHidden())
766
767 QWidgetData *data;
768
769#ifdef QT3_SUPPORT
770public:
771 inline QT3_SUPPORT bool isUpdatesEnabled() const { return updatesEnabled(); }
772 QT3_SUPPORT QStyle *setStyle(const QString&);
773 inline QT3_SUPPORT bool isVisibleToTLW() const;
774 QT3_SUPPORT QRect visibleRect() const;
775 inline QT3_SUPPORT void iconify() { showMinimized(); }
776 inline QT3_SUPPORT void constPolish() const { ensurePolished(); }
777 inline QT3_SUPPORT void polish() { ensurePolished(); }
778 inline QT3_SUPPORT void reparent(QWidget *parent, Qt::WindowFlags f, const QPoint &p, bool showIt=false)
779 { setParent(parent, f); setGeometry(p.x(),p.y(),width(),height()); if (showIt) show(); }
780 inline QT3_SUPPORT void reparent(QWidget *parent, const QPoint &p, bool showIt=false)
781 { setParent(parent, windowFlags() & ~Qt::WindowType_Mask); setGeometry(p.x(),p.y(),width(),height()); if (showIt) show(); }
782 inline QT3_SUPPORT void recreate(QWidget *parent, Qt::WindowFlags f, const QPoint & p, bool showIt=false)
783 { setParent(parent, f); setGeometry(p.x(),p.y(),width(),height()); if (showIt) show(); }
784 inline QT3_SUPPORT void setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver, bool hfw)
785 { QSizePolicy sp(hor, ver); sp.setHeightForWidth(hfw); setSizePolicy(sp);}
786 inline QT3_SUPPORT bool hasMouse() const { return testAttribute(Qt::WA_UnderMouse); }
787#ifndef QT_NO_CURSOR
788 inline QT3_SUPPORT bool ownCursor() const { return testAttribute(Qt::WA_SetCursor); }
789#endif
790 inline QT3_SUPPORT bool ownFont() const { return testAttribute(Qt::WA_SetFont); }
791 inline QT3_SUPPORT void unsetFont() { setFont(QFont()); }
792 inline QT3_SUPPORT bool ownPalette() const { return testAttribute(Qt::WA_SetPalette); }
793 inline QT3_SUPPORT void unsetPalette() { setPalette(QPalette()); }
794 Qt::BackgroundMode QT3_SUPPORT backgroundMode() const;
795 void QT3_SUPPORT setBackgroundMode(Qt::BackgroundMode, Qt::BackgroundMode = Qt::PaletteBackground);
796 const QT3_SUPPORT QColor &eraseColor() const;
797 void QT3_SUPPORT setEraseColor(const QColor &);
798 const QT3_SUPPORT QColor &foregroundColor() const;
799 const QT3_SUPPORT QPixmap *erasePixmap() const;
800 void QT3_SUPPORT setErasePixmap(const QPixmap &);
801 const QT3_SUPPORT QColor &paletteForegroundColor() const;
802 void QT3_SUPPORT setPaletteForegroundColor(const QColor &);
803 const QT3_SUPPORT QColor &paletteBackgroundColor() const;
804 void QT3_SUPPORT setPaletteBackgroundColor(const QColor &);
805 const QT3_SUPPORT QPixmap *paletteBackgroundPixmap() const;
806 void QT3_SUPPORT setPaletteBackgroundPixmap(const QPixmap &);
807 const QT3_SUPPORT QBrush& backgroundBrush() const;
808 const QT3_SUPPORT QColor &backgroundColor() const;
809 const QT3_SUPPORT QPixmap *backgroundPixmap() const;
810 void QT3_SUPPORT setBackgroundPixmap(const QPixmap &);
811 QT3_SUPPORT void setBackgroundColor(const QColor &);
812 QT3_SUPPORT QColorGroup colorGroup() const;
813 QT3_SUPPORT QWidget *parentWidget(bool sameWindow) const;
814 inline QT3_SUPPORT void setKeyCompression(bool b) { setAttribute(Qt::WA_KeyCompression, b); }
815 inline QT3_SUPPORT void setFont(const QFont &f, bool) { setFont(f); }
816 inline QT3_SUPPORT void setPalette(const QPalette &p, bool) { setPalette(p); }
817 enum BackgroundOrigin { WidgetOrigin, ParentOrigin, WindowOrigin, AncestorOrigin };
818 inline QT3_SUPPORT void setBackgroundOrigin(BackgroundOrigin){};
819 inline QT3_SUPPORT BackgroundOrigin backgroundOrigin() const { return WindowOrigin; }
820 inline QT3_SUPPORT QPoint backgroundOffset() const { return QPoint(); }
821 inline QT3_SUPPORT void repaint(bool) { repaint(); }
822 inline QT3_SUPPORT void repaint(int x, int y, int w, int h, bool) { repaint(x,y,w,h); }
823 inline QT3_SUPPORT void repaint(const QRect &r, bool) { repaint(r); }
824 inline QT3_SUPPORT void repaint(const QRegion &rgn, bool) { repaint(rgn); }
825 QT3_SUPPORT void erase();
826 inline QT3_SUPPORT void erase(int x, int y, int w, int h) { erase_helper(x, y, w, h); }
827 QT3_SUPPORT void erase(const QRect &);
828 QT3_SUPPORT void erase(const QRegion &);
829 QT3_SUPPORT void drawText(const QPoint &p, const QString &s)
830 { drawText_helper(p.x(), p.y(), s); }
831 inline QT3_SUPPORT void drawText(int x, int y, const QString &s)
832 { drawText_helper(x, y, s); }
833 QT3_SUPPORT bool close(bool);
834 inline QT3_SUPPORT QWidget *childAt(int x, int y, bool includeThis) const
835 {
836 QWidget *w = childAt(x, y);
837 return w ? w : ((includeThis && rect().contains(x,y))?const_cast<QWidget*>(this):0);
838 }
839 inline QT3_SUPPORT QWidget *childAt(const QPoint &p, bool includeThis) const
840 {
841 QWidget *w = childAt(p);
842 return w ? w : ((includeThis && rect().contains(p))?const_cast<QWidget*>(this):0);
843 }
844 inline QT3_SUPPORT void setCaption(const QString &c) { setWindowTitle(c); }
845 QT3_SUPPORT void setIcon(const QPixmap &i);
846 inline QT3_SUPPORT void setIconText(const QString &it) { setWindowIconText(it); }
847 inline QT3_SUPPORT QString caption() const { return windowTitle(); }
848 QT3_SUPPORT const QPixmap *icon() const;
849 inline QT3_SUPPORT QString iconText() const { return windowIconText(); }
850 inline QT3_SUPPORT void setInputMethodEnabled(bool b) { setAttribute(Qt::WA_InputMethodEnabled, b); }
851 inline QT3_SUPPORT bool isInputMethodEnabled() const { return testAttribute(Qt::WA_InputMethodEnabled); }
852 inline QT3_SUPPORT void setActiveWindow() { activateWindow(); }
853 inline QT3_SUPPORT bool isShown() const { return !isHidden(); }
854 inline QT3_SUPPORT bool isDialog() const { return windowType() == Qt::Dialog; }
855 inline QT3_SUPPORT bool isPopup() const { return windowType() == Qt::Popup; }
856 inline QT3_SUPPORT bool isDesktop() const { return windowType() == Qt::Desktop; }
857
858
859private:
860 void drawText_helper(int x, int y, const QString &);
861 void erase_helper(int x, int y, int w, int h);
862#endif // QT3_SUPPORT
863
864protected:
865 virtual void styleChange(QStyle&); // compat
866 virtual void enabledChange(bool); // compat
867 virtual void paletteChange(const QPalette &); // compat
868 virtual void fontChange(const QFont &); // compat
869 virtual void windowActivationChange(bool); // compat
870 virtual void languageChange(); // compat
871};
872
873Q_DECLARE_OPERATORS_FOR_FLAGS(QWidget::RenderFlags)
874
875#if defined Q_CC_MSVC && _MSC_VER < 1300
876template <> inline QWidget *qobject_cast_helper<QWidget*>(QObject *o, QWidget *)
877{
878 if (!o || !o->isWidgetType()) return 0;
879 return (QWidget*)(o);
880}
881#else
882template <> inline QWidget *qobject_cast<QWidget*>(QObject *o)
883{
884 if (!o || !o->isWidgetType()) return 0;
885 return static_cast<QWidget*>(o);
886}
887template <> inline const QWidget *qobject_cast<const QWidget*>(const QObject *o)
888{
889 if (!o || !o->isWidgetType()) return 0;
890 return static_cast<const QWidget*>(o);
891}
892#endif
893
894inline QWidget *QWidget::childAt(int ax, int ay) const
895{ return childAt(QPoint(ax, ay)); }
896
897inline Qt::WindowType QWidget::windowType() const
898{ return static_cast<Qt::WindowType>(int(data->window_flags & Qt::WindowType_Mask)); }
899inline Qt::WindowFlags QWidget::windowFlags() const
900{ return data->window_flags; }
901
902inline bool QWidget::isTopLevel() const
903{ return (windowType() & Qt::Window); }
904
905inline bool QWidget::isWindow() const
906{ return (windowType() & Qt::Window); }
907
908inline bool QWidget::isEnabled() const
909{ return !testAttribute(Qt::WA_Disabled); }
910
911inline bool QWidget::isModal() const
912{ return data->window_modality != Qt::NonModal; }
913
914inline bool QWidget::isEnabledToTLW() const
915{ return isEnabled(); }
916
917inline int QWidget::minimumWidth() const
918{ return minimumSize().width(); }
919
920inline int QWidget::minimumHeight() const
921{ return minimumSize().height(); }
922
923inline int QWidget::maximumWidth() const
924{ return maximumSize().width(); }
925
926inline int QWidget::maximumHeight() const
927{ return maximumSize().height(); }
928
929inline void QWidget::setMinimumSize(const QSize &s)
930{ setMinimumSize(s.width(),s.height()); }
931
932inline void QWidget::setMaximumSize(const QSize &s)
933{ setMaximumSize(s.width(),s.height()); }
934
935inline void QWidget::setSizeIncrement(const QSize &s)
936{ setSizeIncrement(s.width(),s.height()); }
937
938inline void QWidget::setBaseSize(const QSize &s)
939{ setBaseSize(s.width(),s.height()); }
940
941inline const QFont &QWidget::font() const
942{ return data->fnt; }
943
944inline QFontMetrics QWidget::fontMetrics() const
945{ return QFontMetrics(data->fnt); }
946
947inline QFontInfo QWidget::fontInfo() const
948{ return QFontInfo(data->fnt); }
949
950inline void QWidget::setMouseTracking(bool enable)
951{ setAttribute(Qt::WA_MouseTracking, enable); }
952
953inline bool QWidget::hasMouseTracking() const
954{ return testAttribute(Qt::WA_MouseTracking); }
955
956inline bool QWidget::underMouse() const
957{ return testAttribute(Qt::WA_UnderMouse); }
958
959inline bool QWidget::updatesEnabled() const
960{ return !testAttribute(Qt::WA_UpdatesDisabled); }
961
962inline void QWidget::update(int ax, int ay, int aw, int ah)
963{ update(QRect(ax, ay, aw, ah)); }
964
965inline bool QWidget::isVisible() const
966{ return testAttribute(Qt::WA_WState_Visible); }
967
968inline bool QWidget::isHidden() const
969{ return testAttribute(Qt::WA_WState_Hidden); }
970
971inline void QWidget::move(int ax, int ay)
972{ move(QPoint(ax, ay)); }
973
974inline void QWidget::resize(int w, int h)
975{ resize(QSize(w, h)); }
976
977inline void QWidget::setGeometry(int ax, int ay, int aw, int ah)
978{ setGeometry(QRect(ax, ay, aw, ah)); }
979
980inline QRect QWidget::rect() const
981{ return QRect(0,0,data->crect.width(),data->crect.height()); }
982
983inline const QRect &QWidget::geometry() const
984{ return data->crect; }
985
986inline QSize QWidget::size() const
987{ return data->crect.size(); }
988
989inline int QWidget::width() const
990{ return data->crect.width(); }
991
992inline int QWidget::height() const
993{ return data->crect.height(); }
994
995inline QWidget *QWidget::parentWidget() const
996{ return static_cast<QWidget *>(QObject::parent()); }
997
998inline void QWidget::setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver)
999{ setSizePolicy(QSizePolicy(hor, ver)); }
1000
1001inline bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const
1002{
1003 if (attribute < int(8*sizeof(uint)))
1004 return data->widget_attributes & (1<<attribute);
1005 return testAttribute_helper(attribute);
1006}
1007
1008#ifdef QT3_SUPPORT
1009inline bool QWidget::isVisibleToTLW() const
1010{ return isVisible(); }
1011inline QWidget *QWidget::parentWidget(bool sameWindow) const
1012{
1013 if (sameWindow && isWindow())
1014 return 0;
1015 return static_cast<QWidget *>(QObject::parent());
1016}
1017inline QColorGroup QWidget::colorGroup() const
1018{ return QColorGroup(palette()); }
1019inline void QWidget::setPaletteForegroundColor(const QColor &c)
1020{ QPalette p = palette(); p.setColor(foregroundRole(), c); setPalette(p); }
1021inline const QBrush& QWidget::backgroundBrush() const { return palette().brush(backgroundRole()); }
1022inline void QWidget::setBackgroundPixmap(const QPixmap &pm)
1023{ QPalette p = palette(); p.setBrush(backgroundRole(), QBrush(pm)); setPalette(p); }
1024inline const QPixmap *QWidget::backgroundPixmap() const { return 0; }
1025inline void QWidget::setBackgroundColor(const QColor &c)
1026{ QPalette p = palette(); p.setColor(backgroundRole(), c); setPalette(p); }
1027inline const QColor & QWidget::backgroundColor() const { return palette().color(backgroundRole()); }
1028inline const QColor &QWidget::foregroundColor() const { return palette().color(foregroundRole());}
1029inline const QColor &QWidget::eraseColor() const { return palette().color(backgroundRole()); }
1030inline void QWidget::setEraseColor(const QColor &c)
1031{ QPalette p = palette(); p.setColor(backgroundRole(), c); setPalette(p); }
1032inline const QPixmap *QWidget::erasePixmap() const { return 0; }
1033inline void QWidget::setErasePixmap(const QPixmap &pm)
1034{ QPalette p = palette(); p.setBrush(backgroundRole(), QBrush(pm)); setPalette(p); }
1035inline const QColor &QWidget::paletteForegroundColor() const { return palette().color(foregroundRole());}
1036inline const QColor &QWidget::paletteBackgroundColor() const { return palette().color(backgroundRole()); }
1037inline void QWidget::setPaletteBackgroundColor(const QColor &c)
1038{ QPalette p = palette(); p.setColor(backgroundRole(), c); setPalette(p); }
1039inline const QPixmap *QWidget::paletteBackgroundPixmap() const
1040{ return 0; }
1041inline void QWidget::setPaletteBackgroundPixmap(const QPixmap &pm)
1042{ QPalette p = palette(); p.setBrush(backgroundRole(), QBrush(pm)); setPalette(p); }
1043inline QT3_SUPPORT void QWidget::erase() { erase_helper(0, 0, data->crect.width(), data->crect.height()); }
1044inline QT3_SUPPORT void QWidget::erase(const QRect &r) { erase_helper(r.x(), r.y(), r.width(), r.height()); }
1045#endif
1046
1047#define QWIDGETSIZE_MAX ((1<<24)-1)
1048
1049QT_END_NAMESPACE
1050
1051QT_END_HEADER
1052
1053#endif // QWIDGET_H
Note: See TracBrowser for help on using the repository browser.