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

Last change on this file since 651 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

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