|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qapplication.h" |
|
43 #include "qapplication_p.h" |
|
44 #include "qbrush.h" |
|
45 #include "qcursor.h" |
|
46 #include "qdesktopwidget.h" |
|
47 #include "qevent.h" |
|
48 #include "qhash.h" |
|
49 #include "qlayout.h" |
|
50 #include "qmenu.h" |
|
51 #include "qmetaobject.h" |
|
52 #include "qpixmap.h" |
|
53 #include "qpointer.h" |
|
54 #include "qstack.h" |
|
55 #include "qstyle.h" |
|
56 #include "qstylefactory.h" |
|
57 #include "qvariant.h" |
|
58 #include "qwidget.h" |
|
59 #include "qstyleoption.h" |
|
60 #ifndef QT_NO_ACCESSIBILITY |
|
61 # include "qaccessible.h" |
|
62 #endif |
|
63 #if defined(Q_WS_WIN) |
|
64 # include "qt_windows.h" |
|
65 #endif |
|
66 #ifdef Q_WS_MAC |
|
67 # include "qt_mac_p.h" |
|
68 # include "qt_cocoa_helpers_mac_p.h" |
|
69 # include "qmainwindow.h" |
|
70 #endif |
|
71 #if defined(Q_WS_QWS) |
|
72 # include "qwsdisplay_qws.h" |
|
73 # include "qwsmanager_qws.h" |
|
74 # include "qpaintengine.h" // for PorterDuff |
|
75 # include "private/qwindowsurface_qws_p.h" |
|
76 #endif |
|
77 #include "qpainter.h" |
|
78 #include "qtooltip.h" |
|
79 #include "qwhatsthis.h" |
|
80 #include "qdebug.h" |
|
81 #include "private/qstylesheetstyle_p.h" |
|
82 #include "private/qstyle_p.h" |
|
83 #include "private/qinputcontext_p.h" |
|
84 #include "qfileinfo.h" |
|
85 #include "private/qsoftkeymanager_p.h" |
|
86 |
|
87 #if defined (Q_WS_WIN) |
|
88 # include <private/qwininputcontext_p.h> |
|
89 #endif |
|
90 |
|
91 #if defined(Q_WS_X11) |
|
92 # include <private/qpaintengine_x11_p.h> |
|
93 # include "qx11info_x11.h" |
|
94 #endif |
|
95 |
|
96 #include <private/qgraphicseffect_p.h> |
|
97 #include <private/qwindowsurface_p.h> |
|
98 #include <private/qbackingstore_p.h> |
|
99 #ifdef Q_WS_MAC |
|
100 # include <private/qpaintengine_mac_p.h> |
|
101 #endif |
|
102 #include <private/qpaintengine_raster_p.h> |
|
103 |
|
104 #if defined(Q_OS_SYMBIAN) |
|
105 #include "private/qt_s60_p.h" |
|
106 #endif |
|
107 |
|
108 #include "qwidget_p.h" |
|
109 #include "qaction_p.h" |
|
110 #include "qlayout_p.h" |
|
111 #include "QtGui/qgraphicsproxywidget.h" |
|
112 #include "QtGui/qgraphicsscene.h" |
|
113 #include "private/qgraphicsproxywidget_p.h" |
|
114 #include "QtGui/qabstractscrollarea.h" |
|
115 #include "private/qabstractscrollarea_p.h" |
|
116 #include "private/qevent_p.h" |
|
117 |
|
118 #include "private/qgraphicssystem_p.h" |
|
119 #include "private/qgesturemanager_p.h" |
|
120 |
|
121 // widget/widget data creation count |
|
122 //#define QWIDGET_EXTRA_DEBUG |
|
123 //#define ALIEN_DEBUG |
|
124 |
|
125 QT_BEGIN_NAMESPACE |
|
126 |
|
127 #if !defined(Q_WS_QWS) |
|
128 static bool qt_enable_backingstore = true; |
|
129 #endif |
|
130 #ifdef Q_WS_X11 |
|
131 // for compatibility with Qt 4.0 |
|
132 Q_GUI_EXPORT void qt_x11_set_global_double_buffer(bool enable) |
|
133 { |
|
134 qt_enable_backingstore = enable; |
|
135 } |
|
136 #endif |
|
137 |
|
138 static inline bool qRectIntersects(const QRect &r1, const QRect &r2) |
|
139 { |
|
140 return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right()) && |
|
141 qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom())); |
|
142 } |
|
143 |
|
144 static inline bool hasBackingStoreSupport() |
|
145 { |
|
146 #ifdef Q_WS_MAC |
|
147 return QApplicationPrivate::graphicsSystem() != 0; |
|
148 #else |
|
149 return true; |
|
150 #endif |
|
151 } |
|
152 |
|
153 #ifdef Q_WS_MAC |
|
154 # define QT_NO_PAINT_DEBUG |
|
155 #endif |
|
156 |
|
157 extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp |
|
158 extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp |
|
159 |
|
160 QWidgetPrivate::QWidgetPrivate(int version) |
|
161 : QObjectPrivate(version) |
|
162 , extra(0) |
|
163 , focus_next(0) |
|
164 , focus_prev(0) |
|
165 , focus_child(0) |
|
166 , layout(0) |
|
167 , needsFlush(0) |
|
168 , redirectDev(0) |
|
169 , widgetItem(0) |
|
170 , extraPaintEngine(0) |
|
171 , polished(0) |
|
172 , graphicsEffect(0) |
|
173 #if !defined(QT_NO_IM) |
|
174 , imHints(Qt::ImhNone) |
|
175 #endif |
|
176 , inheritedFontResolveMask(0) |
|
177 , inheritedPaletteResolveMask(0) |
|
178 , leftmargin(0) |
|
179 , topmargin(0) |
|
180 , rightmargin(0) |
|
181 , bottommargin(0) |
|
182 , leftLayoutItemMargin(0) |
|
183 , topLayoutItemMargin(0) |
|
184 , rightLayoutItemMargin(0) |
|
185 , bottomLayoutItemMargin(0) |
|
186 , hd(0) |
|
187 , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred) |
|
188 , fg_role(QPalette::NoRole) |
|
189 , bg_role(QPalette::NoRole) |
|
190 , dirtyOpaqueChildren(1) |
|
191 , isOpaque(0) |
|
192 , inDirtyList(0) |
|
193 , isScrolled(0) |
|
194 , isMoved(0) |
|
195 , usesDoubleBufferedGLContext(0) |
|
196 #if defined(Q_WS_X11) |
|
197 , picture(0) |
|
198 #elif defined(Q_WS_WIN) |
|
199 , noPaintOnScreen(0) |
|
200 #elif defined(Q_WS_MAC) |
|
201 , needWindowChange(0) |
|
202 , isGLWidget(0) |
|
203 , window_event(0) |
|
204 , qd_hd(0) |
|
205 #endif |
|
206 { |
|
207 if (!qApp) { |
|
208 qFatal("QWidget: Must construct a QApplication before a QPaintDevice"); |
|
209 return; |
|
210 } |
|
211 |
|
212 if (version != QObjectPrivateVersion) |
|
213 qFatal("Cannot mix incompatible Qt libraries"); |
|
214 |
|
215 isWidget = true; |
|
216 memset(high_attributes, 0, sizeof(high_attributes)); |
|
217 #ifdef QWIDGET_EXTRA_DEBUG |
|
218 static int count = 0; |
|
219 qDebug() << "widgets" << ++count; |
|
220 #endif |
|
221 } |
|
222 |
|
223 |
|
224 QWidgetPrivate::~QWidgetPrivate() |
|
225 { |
|
226 if (widgetItem) |
|
227 widgetItem->wid = 0; |
|
228 |
|
229 if (extra) |
|
230 deleteExtra(); |
|
231 |
|
232 delete graphicsEffect; |
|
233 } |
|
234 |
|
235 QWindowSurface *QWidgetPrivate::createDefaultWindowSurface() |
|
236 { |
|
237 Q_Q(QWidget); |
|
238 if (QApplicationPrivate::graphicsSystem()) |
|
239 return QApplicationPrivate::graphicsSystem()->createWindowSurface(q); |
|
240 return createDefaultWindowSurface_sys(); |
|
241 } |
|
242 |
|
243 /*! |
|
244 \internal |
|
245 */ |
|
246 void QWidgetPrivate::scrollChildren(int dx, int dy) |
|
247 { |
|
248 Q_Q(QWidget); |
|
249 if (q->children().size() > 0) { // scroll children |
|
250 QPoint pd(dx, dy); |
|
251 QObjectList childObjects = q->children(); |
|
252 for (int i = 0; i < childObjects.size(); ++i) { // move all children |
|
253 QWidget *w = qobject_cast<QWidget*>(childObjects.at(i)); |
|
254 if (w && !w->isWindow()) { |
|
255 QPoint oldp = w->pos(); |
|
256 QRect r(w->pos() + pd, w->size()); |
|
257 w->data->crect = r; |
|
258 #ifndef Q_WS_QWS |
|
259 if (w->testAttribute(Qt::WA_WState_Created)) |
|
260 w->d_func()->setWSGeometry(); |
|
261 #endif |
|
262 w->d_func()->setDirtyOpaqueRegion(); |
|
263 QMoveEvent e(r.topLeft(), oldp); |
|
264 QApplication::sendEvent(w, &e); |
|
265 } |
|
266 } |
|
267 } |
|
268 } |
|
269 |
|
270 QInputContext *QWidgetPrivate::inputContext() const |
|
271 { |
|
272 #ifndef QT_NO_IM |
|
273 if (ic) |
|
274 return ic; |
|
275 #endif |
|
276 return qApp->inputContext(); |
|
277 } |
|
278 |
|
279 /*! |
|
280 This function returns the QInputContext for this widget. By |
|
281 default the input context is inherited from the widgets |
|
282 parent. For toplevels it is inherited from QApplication. |
|
283 |
|
284 You can override this and set a special input context for this |
|
285 widget by using the setInputContext() method. |
|
286 |
|
287 \sa setInputContext() |
|
288 */ |
|
289 QInputContext *QWidget::inputContext() |
|
290 { |
|
291 Q_D(QWidget); |
|
292 if (!testAttribute(Qt::WA_InputMethodEnabled)) |
|
293 return 0; |
|
294 |
|
295 return d->inputContext(); |
|
296 } |
|
297 |
|
298 /*! |
|
299 This function sets the input context \a context |
|
300 on this widget. |
|
301 |
|
302 \sa inputContext() |
|
303 */ |
|
304 void QWidget::setInputContext(QInputContext *context) |
|
305 { |
|
306 Q_D(QWidget); |
|
307 if (!testAttribute(Qt::WA_InputMethodEnabled)) |
|
308 return; |
|
309 #ifndef QT_NO_IM |
|
310 if (d->ic) |
|
311 delete d->ic; |
|
312 d->ic = context; |
|
313 #endif |
|
314 } |
|
315 |
|
316 |
|
317 /*! |
|
318 \obsolete |
|
319 |
|
320 This function can be called on the widget that currently has focus |
|
321 to reset the input method operating on it. |
|
322 |
|
323 This function is providing for convenience, instead you should use |
|
324 \l{QInputContext::}{reset()} on the input context that was |
|
325 returned by inputContext(). |
|
326 |
|
327 \sa QInputContext, inputContext(), QInputContext::reset() |
|
328 */ |
|
329 void QWidget::resetInputContext() |
|
330 { |
|
331 if (!hasFocus()) |
|
332 return; |
|
333 #ifndef QT_NO_IM |
|
334 QInputContext *qic = this->inputContext(); |
|
335 if(qic) |
|
336 qic->reset(); |
|
337 #endif // QT_NO_IM |
|
338 } |
|
339 |
|
340 #ifdef QT_KEYPAD_NAVIGATION |
|
341 QPointer<QWidget> QWidgetPrivate::editingWidget; |
|
342 |
|
343 /*! |
|
344 Returns true if this widget currently has edit focus; otherwise false. |
|
345 |
|
346 This feature is only available in Qt for Embedded Linux. |
|
347 |
|
348 \sa setEditFocus(), QApplication::keypadNavigationEnabled() |
|
349 */ |
|
350 bool QWidget::hasEditFocus() const |
|
351 { |
|
352 const QWidget* w = this; |
|
353 while (w->d_func()->extra && w->d_func()->extra->focus_proxy) |
|
354 w = w->d_func()->extra->focus_proxy; |
|
355 return QWidgetPrivate::editingWidget == w; |
|
356 } |
|
357 |
|
358 /*! |
|
359 \fn void QWidget::setEditFocus(bool enable) |
|
360 |
|
361 If \a enable is true, make this widget have edit focus, in which |
|
362 case Qt::Key_Up and Qt::Key_Down will be delivered to the widget |
|
363 normally; otherwise, Qt::Key_Up and Qt::Key_Down are used to |
|
364 change focus. |
|
365 |
|
366 This feature is only available in Qt for Embedded Linux. |
|
367 |
|
368 \sa hasEditFocus(), QApplication::keypadNavigationEnabled() |
|
369 */ |
|
370 void QWidget::setEditFocus(bool on) |
|
371 { |
|
372 QWidget *f = this; |
|
373 while (f->d_func()->extra && f->d_func()->extra->focus_proxy) |
|
374 f = f->d_func()->extra->focus_proxy; |
|
375 |
|
376 if (QWidgetPrivate::editingWidget && QWidgetPrivate::editingWidget != f) |
|
377 QWidgetPrivate::editingWidget->setEditFocus(false); |
|
378 |
|
379 if (on && !f->hasFocus()) |
|
380 f->setFocus(); |
|
381 |
|
382 if ((!on && !QWidgetPrivate::editingWidget) |
|
383 || (on && QWidgetPrivate::editingWidget == f)) { |
|
384 return; |
|
385 } |
|
386 |
|
387 if (!on && QWidgetPrivate::editingWidget == f) { |
|
388 QWidgetPrivate::editingWidget = 0; |
|
389 QEvent event(QEvent::LeaveEditFocus); |
|
390 QApplication::sendEvent(f, &event); |
|
391 QApplication::sendEvent(f->style(), &event); |
|
392 } else if (on) { |
|
393 QWidgetPrivate::editingWidget = f; |
|
394 QEvent event(QEvent::EnterEditFocus); |
|
395 QApplication::sendEvent(f, &event); |
|
396 QApplication::sendEvent(f->style(), &event); |
|
397 } |
|
398 } |
|
399 #endif |
|
400 |
|
401 /*! |
|
402 \property QWidget::autoFillBackground |
|
403 \brief whether the widget background is filled automatically |
|
404 \since 4.1 |
|
405 |
|
406 If enabled, this property will cause Qt to fill the background of the |
|
407 widget before invoking the paint event. The color used is defined by the |
|
408 QPalette::Window color role from the widget's \l{QPalette}{palette}. |
|
409 |
|
410 In addition, Windows are always filled with QPalette::Window, unless the |
|
411 WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set. |
|
412 |
|
413 This property cannot be turned off (i.e., set to false) if a widget's |
|
414 parent has a static gradient for its background. |
|
415 |
|
416 \warning Use this property with caution in conjunction with |
|
417 \l{Qt Style Sheets}. When a widget has a style sheet with a valid |
|
418 background or a border-image, this property is automatically disabled. |
|
419 |
|
420 By default, this property is false. |
|
421 |
|
422 \sa Qt::WA_OpaquePaintEvent, Qt::WA_NoSystemBackground, |
|
423 {QWidget#Transparency and Double Buffering}{Transparency and Double Buffering} |
|
424 */ |
|
425 bool QWidget::autoFillBackground() const |
|
426 { |
|
427 Q_D(const QWidget); |
|
428 return d->extra && d->extra->autoFillBackground; |
|
429 } |
|
430 |
|
431 void QWidget::setAutoFillBackground(bool enabled) |
|
432 { |
|
433 Q_D(QWidget); |
|
434 if (!d->extra) |
|
435 d->createExtra(); |
|
436 if (d->extra->autoFillBackground == enabled) |
|
437 return; |
|
438 |
|
439 d->extra->autoFillBackground = enabled; |
|
440 d->updateIsOpaque(); |
|
441 update(); |
|
442 d->updateIsOpaque(); |
|
443 } |
|
444 |
|
445 /*! |
|
446 \class QWidget |
|
447 \brief The QWidget class is the base class of all user interface objects. |
|
448 |
|
449 \ingroup basicwidgets |
|
450 |
|
451 |
|
452 The widget is the atom of the user interface: it receives mouse, keyboard |
|
453 and other events from the window system, and paints a representation of |
|
454 itself on the screen. Every widget is rectangular, and they are sorted in a |
|
455 Z-order. A widget is clipped by its parent and by the widgets in front of |
|
456 it. |
|
457 |
|
458 A widget that is not embedded in a parent widget is called a window. |
|
459 Usually, windows have a frame and a title bar, although it is also possible |
|
460 to create windows without such decoration using suitable |
|
461 \l{Qt::WindowFlags}{window flags}). In Qt, QMainWindow and the various |
|
462 subclasses of QDialog are the most common window types. |
|
463 |
|
464 Every widget's constructor accepts one or two standard arguments: |
|
465 |
|
466 \list 1 |
|
467 \i \c{QWidget *parent = 0} is the parent of the new widget. If it is 0 |
|
468 (the default), the new widget will be a window. If not, it will be |
|
469 a child of \e parent, and be constrained by \e parent's geometry |
|
470 (unless you specify Qt::Window as window flag). |
|
471 \i \c{Qt::WindowFlags f = 0} (where available) sets the window flags; |
|
472 the default is suitable for almost all widgets, but to get, for |
|
473 example, a window without a window system frame, you must use |
|
474 special flags. |
|
475 \endlist |
|
476 |
|
477 QWidget has many member functions, but some of them have little direct |
|
478 functionality; for example, QWidget has a font property, but never uses |
|
479 this itself. There are many subclasses which provide real functionality, |
|
480 such as QLabel, QPushButton, QListWidget, and QTabWidget. |
|
481 |
|
482 |
|
483 \section1 Top-Level and Child Widgets |
|
484 |
|
485 A widget without a parent widget is always an independent window (top-level |
|
486 widget). For these widgets, setWindowTitle() and setWindowIcon() set the |
|
487 title bar and icon respectively. |
|
488 |
|
489 Non-window widgets are child widgets, displayed within their parent |
|
490 widgets. Most widgets in Qt are mainly useful as child widgets. For |
|
491 example, it is possible to display a button as a top-level window, but most |
|
492 people prefer to put their buttons inside other widgets, such as QDialog. |
|
493 |
|
494 \image parent-child-widgets.png A parent widget containing various child widgets. |
|
495 |
|
496 The diagram above shows a QGroupBox widget being used to hold various child |
|
497 widgets in a layout provided by QGridLayout. The QLabel child widgets have |
|
498 been outlined to indicate their full sizes. |
|
499 |
|
500 If you want to use a QWidget to hold child widgets you will usually want to |
|
501 add a layout to the parent QWidget. See \l{Layout Management} for more |
|
502 information. |
|
503 |
|
504 |
|
505 \section1 Composite Widgets |
|
506 |
|
507 When a widget is used as a container to group a number of child widgets, it |
|
508 is known as a composite widget. These can be created by constructing a |
|
509 widget with the required visual properties - a QFrame, for example - and |
|
510 adding child widgets to it, usually managed by a layout. The above diagram |
|
511 shows such a composite widget that was created using \l{Qt Designer}. |
|
512 |
|
513 Composite widgets can also be created by subclassing a standard widget, |
|
514 such as QWidget or QFrame, and adding the necessary layout and child |
|
515 widgets in the constructor of the subclass. Many of the \l{Qt Examples} |
|
516 {examples provided with Qt} use this approach, and it is also covered in |
|
517 the Qt \l{Tutorials}. |
|
518 |
|
519 |
|
520 \section1 Custom Widgets and Painting |
|
521 |
|
522 Since QWidget is a subclass of QPaintDevice, subclasses can be used to |
|
523 display custom content that is composed using a series of painting |
|
524 operations with an instance of the QPainter class. This approach contrasts |
|
525 with the canvas-style approach used by the \l{Graphics View} |
|
526 {Graphics View Framework} where items are added to a scene by the |
|
527 application and are rendered by the framework itself. |
|
528 |
|
529 Each widget performs all painting operations from within its paintEvent() |
|
530 function. This is called whenever the widget needs to be redrawn, either |
|
531 as a result of some external change or when requested by the application. |
|
532 |
|
533 The \l{widgets/analogclock}{Analog Clock example} shows how a simple widget |
|
534 can handle paint events. |
|
535 |
|
536 |
|
537 \section1 Size Hints and Size Policies |
|
538 |
|
539 When implementing a new widget, it is almost always useful to reimplement |
|
540 sizeHint() to provide a reasonable default size for the widget and to set |
|
541 the correct size policy with setSizePolicy(). |
|
542 |
|
543 By default, composite widgets which do not provide a size hint will be |
|
544 sized according to the space requirements of their child widgets. |
|
545 |
|
546 The size policy lets you supply good default behavior for the layout |
|
547 management system, so that other widgets can contain and manage yours |
|
548 easily. The default size policy indicates that the size hint represents |
|
549 the preferred size of the widget, and this is often good enough for many |
|
550 widgets. |
|
551 |
|
552 \note The size of top-level widgets are constrained to 2/3 of the desktop's |
|
553 height and width. You can resize() the widget manually if these bounds are |
|
554 inadequate. |
|
555 |
|
556 |
|
557 \section1 Events |
|
558 |
|
559 Widgets respond to events that are typically caused by user actions. Qt |
|
560 delivers events to widgets by calling specific event handler functions with |
|
561 instances of QEvent subclasses containing information about each event. |
|
562 |
|
563 If your widget only contains child widgets, you probably do not need to |
|
564 implement any event handlers. If you want to detect a mouse click in a |
|
565 child widget call the child's underMouse() function inside the widget's |
|
566 mousePressEvent(). |
|
567 |
|
568 The \l{widgets/scribble}{Scribble example} implements a wider set of |
|
569 events to handle mouse movement, button presses, and window resizing. |
|
570 |
|
571 You will need to supply the behavior and content for your own widgets, but |
|
572 here is a brief overview of the events that are relevant to QWidget, |
|
573 starting with the most common ones: |
|
574 |
|
575 \list |
|
576 \i paintEvent() is called whenever the widget needs to be repainted. |
|
577 Every widget displaying custom content must implement it. Painting |
|
578 using a QPainter can only take place in a paintEvent() or a |
|
579 function called by a paintEvent(). |
|
580 \i resizeEvent() is called when the widget has been resized. |
|
581 \i mousePressEvent() is called when a mouse button is pressed while |
|
582 the mouse cursor is inside the widget, or when the widget has |
|
583 grabbed the mouse using grabMouse(). Pressing the mouse without |
|
584 releasing it is effectively the same as calling grabMouse(). |
|
585 \i mouseReleaseEvent() is called when a mouse button is released. A |
|
586 widget receives mouse release events when it has received the |
|
587 corresponding mouse press event. This means that if the user |
|
588 presses the mouse inside \e your widget, then drags the mouse |
|
589 somewhere else before releasing the mouse button, \e your widget |
|
590 receives the release event. There is one exception: if a popup menu |
|
591 appears while the mouse button is held down, this popup immediately |
|
592 steals the mouse events. |
|
593 \i mouseDoubleClickEvent() is called when the user double-clicks in |
|
594 the widget. If the user double-clicks, the widget receives a mouse |
|
595 press event, a mouse release event and finally this event instead |
|
596 of a second mouse press event. (Some mouse move events may also be |
|
597 received if the mouse is not held steady during this operation.) It |
|
598 is \e{not possible} to distinguish a click from a double-click |
|
599 until the second click arrives. (This is one reason why most GUI |
|
600 books recommend that double-clicks be an extension of |
|
601 single-clicks, rather than trigger a different action.) |
|
602 \endlist |
|
603 |
|
604 Widgets that accept keyboard input need to reimplement a few more event |
|
605 handlers: |
|
606 |
|
607 \list |
|
608 \i keyPressEvent() is called whenever a key is pressed, and again when |
|
609 a key has been held down long enough for it to auto-repeat. The |
|
610 \key Tab and \key Shift+Tab keys are only passed to the widget if |
|
611 they are not used by the focus-change mechanisms. To force those |
|
612 keys to be processed by your widget, you must reimplement |
|
613 QWidget::event(). |
|
614 \i focusInEvent() is called when the widget gains keyboard focus |
|
615 (assuming you have called setFocusPolicy()). Well-behaved widgets |
|
616 indicate that they own the keyboard focus in a clear but discreet |
|
617 way. |
|
618 \i focusOutEvent() is called when the widget loses keyboard focus. |
|
619 \endlist |
|
620 |
|
621 You may be required to also reimplement some of the less common event |
|
622 handlers: |
|
623 |
|
624 \list |
|
625 \i mouseMoveEvent() is called whenever the mouse moves while a mouse |
|
626 button is held down. This can be useful during drag and drop |
|
627 operations. If you call setMouseTracking(true), you get mouse move |
|
628 events even when no buttons are held down. (See also the \l{Drag |
|
629 and Drop} guide.) |
|
630 \i keyReleaseEvent() is called whenever a key is released and while it |
|
631 is held down (if the key is auto-repeating). In that case, the |
|
632 widget will receive a pair of key release and key press event for |
|
633 every repeat. The \key Tab and \key Shift+Tab keys are only passed |
|
634 to the widget if they are not used by the focus-change mechanisms. |
|
635 To force those keys to be processed by your widget, you must |
|
636 reimplement QWidget::event(). |
|
637 \i wheelEvent() is called whenever the user turns the mouse wheel |
|
638 while the widget has the focus. |
|
639 \i enterEvent() is called when the mouse enters the widget's screen |
|
640 space. (This excludes screen space owned by any of the widget's |
|
641 children.) |
|
642 \i leaveEvent() is called when the mouse leaves the widget's screen |
|
643 space. If the mouse enters a child widget it will not cause a |
|
644 leaveEvent(). |
|
645 \i moveEvent() is called when the widget has been moved relative to |
|
646 its parent. |
|
647 \i closeEvent() is called when the user closes the widget (or when |
|
648 close() is called). |
|
649 \endlist |
|
650 |
|
651 There are also some rather obscure events described in the documentation |
|
652 for QEvent::Type. To handle these events, you need to reimplement event() |
|
653 directly. |
|
654 |
|
655 The default implementation of event() handles \key Tab and \key Shift+Tab |
|
656 (to move the keyboard focus), and passes on most of the other events to |
|
657 one of the more specialized handlers above. |
|
658 |
|
659 Events and the mechanism used to deliver them are covered in the |
|
660 \l{Events and Event Filters} document. |
|
661 |
|
662 \section1 Groups of Functions and Properties |
|
663 |
|
664 \table |
|
665 \header \i Context \i Functions and Properties |
|
666 |
|
667 \row \i Window functions \i |
|
668 show(), |
|
669 hide(), |
|
670 raise(), |
|
671 lower(), |
|
672 close(). |
|
673 |
|
674 \row \i Top-level windows \i |
|
675 \l windowModified, \l windowTitle, \l windowIcon, \l windowIconText, |
|
676 \l isActiveWindow, activateWindow(), \l minimized, showMinimized(), |
|
677 \l maximized, showMaximized(), \l fullScreen, showFullScreen(), |
|
678 showNormal(). |
|
679 |
|
680 \row \i Window contents \i |
|
681 update(), |
|
682 repaint(), |
|
683 scroll(). |
|
684 |
|
685 \row \i Geometry \i |
|
686 \l pos, x(), y(), \l rect, \l size, width(), height(), move(), resize(), |
|
687 \l sizePolicy, sizeHint(), minimumSizeHint(), |
|
688 updateGeometry(), layout(), |
|
689 \l frameGeometry, \l geometry, \l childrenRect, \l childrenRegion, |
|
690 adjustSize(), |
|
691 mapFromGlobal(), mapToGlobal(), |
|
692 mapFromParent(), mapToParent(), |
|
693 \l maximumSize, \l minimumSize, \l sizeIncrement, |
|
694 \l baseSize, setFixedSize() |
|
695 |
|
696 \row \i Mode \i |
|
697 \l visible, isVisibleTo(), |
|
698 \l enabled, isEnabledTo(), |
|
699 \l modal, |
|
700 isWindow(), |
|
701 \l mouseTracking, |
|
702 \l updatesEnabled, |
|
703 visibleRegion(). |
|
704 |
|
705 \row \i Look and feel \i |
|
706 style(), |
|
707 setStyle(), |
|
708 \l styleSheet, |
|
709 \l cursor, |
|
710 \l font, |
|
711 \l palette, |
|
712 backgroundRole(), setBackgroundRole(), |
|
713 fontInfo(), fontMetrics(). |
|
714 |
|
715 \row \i Keyboard focus functions \i |
|
716 \l focus, \l focusPolicy, |
|
717 setFocus(), clearFocus(), setTabOrder(), setFocusProxy(), |
|
718 focusNextChild(), focusPreviousChild(). |
|
719 |
|
720 \row \i Mouse and keyboard grabbing \i |
|
721 grabMouse(), releaseMouse(), |
|
722 grabKeyboard(), releaseKeyboard(), |
|
723 mouseGrabber(), keyboardGrabber(). |
|
724 |
|
725 \row \i Event handlers \i |
|
726 event(), |
|
727 mousePressEvent(), |
|
728 mouseReleaseEvent(), |
|
729 mouseDoubleClickEvent(), |
|
730 mouseMoveEvent(), |
|
731 keyPressEvent(), |
|
732 keyReleaseEvent(), |
|
733 focusInEvent(), |
|
734 focusOutEvent(), |
|
735 wheelEvent(), |
|
736 enterEvent(), |
|
737 leaveEvent(), |
|
738 paintEvent(), |
|
739 moveEvent(), |
|
740 resizeEvent(), |
|
741 closeEvent(), |
|
742 dragEnterEvent(), |
|
743 dragMoveEvent(), |
|
744 dragLeaveEvent(), |
|
745 dropEvent(), |
|
746 childEvent(), |
|
747 showEvent(), |
|
748 hideEvent(), |
|
749 customEvent(). |
|
750 changeEvent(), |
|
751 |
|
752 \row \i System functions \i |
|
753 parentWidget(), window(), setParent(), winId(), |
|
754 find(), metric(). |
|
755 |
|
756 \row \i Interactive help \i |
|
757 setToolTip(), setWhatsThis() |
|
758 |
|
759 \endtable |
|
760 |
|
761 |
|
762 \section1 Widget Style Sheets |
|
763 |
|
764 In addition to the standard widget styles for each platform, widgets can |
|
765 also be styled according to rules specified in a \l{styleSheet} |
|
766 {style sheet}. This feature enables you to customize the appearance of |
|
767 specific widgets to provide visual cues to users about their purpose. For |
|
768 example, a button could be styled in a particular way to indicate that it |
|
769 performs a destructive action. |
|
770 |
|
771 The use of widget style sheets is described in more detail in the |
|
772 \l{Qt Style Sheets} document. |
|
773 |
|
774 |
|
775 \section1 Transparency and Double Buffering |
|
776 |
|
777 Since Qt 4.0, QWidget automatically double-buffers its painting, so there |
|
778 is no need to write double-buffering code in paintEvent() to avoid |
|
779 flicker. |
|
780 |
|
781 Since Qt 4.1, the Qt::WA_ContentsPropagated widget attribute has been |
|
782 deprecated. Instead, the contents of parent widgets are propagated by |
|
783 default to each of their children as long as Qt::WA_PaintOnScreen is not |
|
784 set. Custom widgets can be written to take advantage of this feature by |
|
785 updating irregular regions (to create non-rectangular child widgets), or |
|
786 painting with colors that have less than full alpha component. The |
|
787 following diagram shows how attributes and properties of a custom widget |
|
788 can be fine-tuned to achieve different effects. |
|
789 |
|
790 \image propagation-custom.png |
|
791 |
|
792 In the above diagram, a semi-transparent rectangular child widget with an |
|
793 area removed is constructed and added to a parent widget (a QLabel showing |
|
794 a pixmap). Then, different properties and widget attributes are set to |
|
795 achieve different effects: |
|
796 |
|
797 \list |
|
798 \i The left widget has no additional properties or widget attributes |
|
799 set. This default state suits most custom widgets using |
|
800 transparency, are irregularly-shaped, or do not paint over their |
|
801 entire area with an opaque brush. |
|
802 \i The center widget has the \l autoFillBackground property set. This |
|
803 property is used with custom widgets that rely on the widget to |
|
804 supply a default background, and do not paint over their entire |
|
805 area with an opaque brush. |
|
806 \i The right widget has the Qt::WA_OpaquePaintEvent widget attribute |
|
807 set. This indicates that the widget will paint over its entire area |
|
808 with opaque colors. The widget's area will initially be |
|
809 \e{uninitialized}, represented in the diagram with a red diagonal |
|
810 grid pattern that shines through the overpainted area. The |
|
811 Qt::WA_OpaquePaintArea attribute is useful for widgets that need to |
|
812 paint their own specialized contents quickly and do not need a |
|
813 default filled background. |
|
814 \endlist |
|
815 |
|
816 To rapidly update custom widgets with simple background colors, such as |
|
817 real-time plotting or graphing widgets, it is better to define a suitable |
|
818 background color (using setBackgroundRole() with the |
|
819 QPalette::Window role), set the \l autoFillBackground property, and only |
|
820 implement the necessary drawing functionality in the widget's paintEvent(). |
|
821 |
|
822 To rapidly update custom widgets that constantly paint over their entire |
|
823 areas with opaque content, e.g., video streaming widgets, it is better to |
|
824 set the widget's Qt::WA_OpaquePaintEvent, avoiding any unnecessary overhead |
|
825 associated with repainting the widget's background. |
|
826 |
|
827 If a widget has both the Qt::WA_OpaquePaintEvent widget attribute \e{and} |
|
828 the \l autoFillBackground property set, the Qt::WA_OpaquePaintEvent |
|
829 attribute takes precedence. Depending on your requirements, you should |
|
830 choose either one of them. |
|
831 |
|
832 Since Qt 4.1, the contents of parent widgets are also propagated to |
|
833 standard Qt widgets. This can lead to some unexpected results if the |
|
834 parent widget is decorated in a non-standard way, as shown in the diagram |
|
835 below. |
|
836 |
|
837 \image propagation-standard.png |
|
838 |
|
839 The scope for customizing the painting behavior of standard Qt widgets, |
|
840 without resorting to subclassing, is slightly less than that possible for |
|
841 custom widgets. Usually, the desired appearance of a standard widget can be |
|
842 achieved by setting its \l autoFillBackground property. |
|
843 |
|
844 |
|
845 \section1 Creating Translucent Windows |
|
846 |
|
847 Since Qt 4.5, it has been possible to create windows with translucent regions |
|
848 on window systems that support compositing. |
|
849 |
|
850 To enable this feature in a top-level widget, set its Qt::WA_TranslucentBackground |
|
851 attribute with setAttribute() and ensure that its background is painted with |
|
852 non-opaque colors in the regions you want to be partially transparent. |
|
853 |
|
854 Platform notes: |
|
855 |
|
856 \list |
|
857 \o X11: This feature relies on the use of an X server that supports ARGB visuals |
|
858 and a compositing window manager. |
|
859 \o Windows: The widget needs to have the Qt::FramelessWindowHint window flag set |
|
860 for the translucency to work. |
|
861 \endlist |
|
862 |
|
863 |
|
864 \section1 Native Widgets vs Alien Widgets |
|
865 |
|
866 Introduced in Qt 4.4, alien widgets are widgets unknown to the windowing |
|
867 system. They do not have a native window handle associated with them. This |
|
868 feature significantly speeds up widget painting, resizing, and removes flicker. |
|
869 |
|
870 Should you require the old behavior with native windows, you can choose |
|
871 one of the following options: |
|
872 |
|
873 \list 1 |
|
874 \i Use the \c{QT_USE_NATIVE_WINDOWS=1} in your environment. |
|
875 \i Set the Qt::AA_NativeWindows attribute on your application. All |
|
876 widgets will be native widgets. |
|
877 \i Set the Qt::WA_NativeWindow attribute on widgets: The widget itself |
|
878 and all of its ancestors will become native (unless |
|
879 Qt::WA_DontCreateNativeAncestors is set). |
|
880 \i Call QWidget::winId to enforce a native window (this implies 3). |
|
881 \i Set the Qt::WA_PaintOnScreen attribute to enforce a native window |
|
882 (this implies 3). |
|
883 \endlist |
|
884 |
|
885 \sa QEvent, QPainter, QGridLayout, QBoxLayout |
|
886 |
|
887 \section1 Softkeys |
|
888 |
|
889 Since Qt 4.6, Softkeys are usually physical keys on a device that have a corresponding label or |
|
890 other visual representation on the screen that is generally located next to its |
|
891 physical counterpart. They are most often found on mobile phone platforms. In |
|
892 modern touch based user interfaces it is also possible to have softkeys that do |
|
893 not correspond to any physical keys. Softkeys differ from other onscreen labels |
|
894 in that they are contextual. |
|
895 |
|
896 In Qt, contextual softkeys are added to a widget by calling addAction() and |
|
897 passing a \c QAction with a softkey role set on it. When the widget |
|
898 containing the softkey actions has focus, its softkeys should appear in |
|
899 the user interface. Softkeys are discovered by traversing the widget |
|
900 heirarchy so it is possible to define a single set of softkeys that are |
|
901 present at all times by calling addAction() for a given top level widget. |
|
902 |
|
903 On some platforms, this concept overlaps with \c QMenuBar such that if no |
|
904 other softkeys are found and the top level widget is a QMainWindow containing |
|
905 a QMenuBar, the menubar actions may appear on one of the softkeys. |
|
906 |
|
907 Note: Currently softkeys are only supported on the Symbian Platform. |
|
908 |
|
909 \sa addAction(), QAction, QMenuBar |
|
910 |
|
911 */ |
|
912 |
|
913 QWidgetMapper *QWidgetPrivate::mapper = 0; // widget with wid |
|
914 QWidgetSet *QWidgetPrivate::allWidgets = 0; // widgets with no wid |
|
915 |
|
916 |
|
917 /***************************************************************************** |
|
918 QWidget utility functions |
|
919 *****************************************************************************/ |
|
920 |
|
921 QRegion qt_dirtyRegion(QWidget *widget) |
|
922 { |
|
923 if (!widget) |
|
924 return QRegion(); |
|
925 |
|
926 QWidgetBackingStore *bs = qt_widget_private(widget)->maybeBackingStore(); |
|
927 if (!bs) |
|
928 return QRegion(); |
|
929 |
|
930 return bs->dirtyRegion(widget); |
|
931 } |
|
932 |
|
933 /***************************************************************************** |
|
934 QWidget member functions |
|
935 *****************************************************************************/ |
|
936 |
|
937 /* |
|
938 Widget state flags: |
|
939 \list |
|
940 \i Qt::WA_WState_Created The widget has a valid winId(). |
|
941 \i Qt::WA_WState_Visible The widget is currently visible. |
|
942 \i Qt::WA_WState_Hidden The widget is hidden, i.e. it won't |
|
943 become visible unless you call show() on it. Qt::WA_WState_Hidden |
|
944 implies !Qt::WA_WState_Visible. |
|
945 \i Qt::WA_WState_CompressKeys Compress keyboard events. |
|
946 \i Qt::WA_WState_BlockUpdates Repaints and updates are disabled. |
|
947 \i Qt::WA_WState_InPaintEvent Currently processing a paint event. |
|
948 \i Qt::WA_WState_Reparented The widget has been reparented. |
|
949 \i Qt::WA_WState_ConfigPending A configuration (resize/move) event is pending. |
|
950 \i Qt::WA_WState_DND (Deprecated) The widget supports drag and drop, see setAcceptDrops(). |
|
951 \endlist |
|
952 */ |
|
953 |
|
954 struct QWidgetExceptionCleaner |
|
955 { |
|
956 /* this cleans up when the constructor throws an exception */ |
|
957 static inline void cleanup(QWidget *that, QWidgetPrivate *d) |
|
958 { |
|
959 #ifdef QT_NO_EXCEPTIONS |
|
960 Q_UNUSED(that); |
|
961 Q_UNUSED(d); |
|
962 #else |
|
963 QWidgetPrivate::allWidgets->remove(that); |
|
964 if (d->focus_next != that) { |
|
965 if (d->focus_next) |
|
966 d->focus_next->d_func()->focus_prev = d->focus_prev; |
|
967 if (d->focus_prev) |
|
968 d->focus_prev->d_func()->focus_next = d->focus_next; |
|
969 } |
|
970 #endif |
|
971 } |
|
972 }; |
|
973 |
|
974 /*! |
|
975 Constructs a widget which is a child of \a parent, with widget |
|
976 flags set to \a f. |
|
977 |
|
978 If \a parent is 0, the new widget becomes a window. If |
|
979 \a parent is another widget, this widget becomes a child window |
|
980 inside \a parent. The new widget is deleted when its \a parent is |
|
981 deleted. |
|
982 |
|
983 The widget flags argument, \a f, is normally 0, but it can be set |
|
984 to customize the frame of a window (i.e. \a |
|
985 parent must be 0). To customize the frame, use a value composed |
|
986 from the bitwise OR of any of the \l{Qt::WindowFlags}{window flags}. |
|
987 |
|
988 If you add a child widget to an already visible widget you must |
|
989 explicitly show the child to make it visible. |
|
990 |
|
991 Note that the X11 version of Qt may not be able to deliver all |
|
992 combinations of style flags on all systems. This is because on |
|
993 X11, Qt can only ask the window manager, and the window manager |
|
994 can override the application's settings. On Windows, Qt can set |
|
995 whatever flags you want. |
|
996 |
|
997 \sa windowFlags |
|
998 */ |
|
999 |
|
1000 QWidget::QWidget(QWidget *parent, Qt::WindowFlags f) |
|
1001 : QObject(*new QWidgetPrivate, 0), QPaintDevice() |
|
1002 { |
|
1003 QT_TRY { |
|
1004 d_func()->init(parent, f); |
|
1005 } QT_CATCH(...) { |
|
1006 QWidgetExceptionCleaner::cleanup(this, d_func()); |
|
1007 QT_RETHROW; |
|
1008 } |
|
1009 } |
|
1010 |
|
1011 #ifdef QT3_SUPPORT |
|
1012 /*! |
|
1013 \overload |
|
1014 \obsolete |
|
1015 */ |
|
1016 QWidget::QWidget(QWidget *parent, const char *name, Qt::WindowFlags f) |
|
1017 : QObject(*new QWidgetPrivate, 0), QPaintDevice() |
|
1018 { |
|
1019 QT_TRY { |
|
1020 d_func()->init(parent , f); |
|
1021 setObjectName(QString::fromAscii(name)); |
|
1022 } QT_CATCH(...) { |
|
1023 QWidgetExceptionCleaner::cleanup(this, d_func()); |
|
1024 QT_RETHROW; |
|
1025 } |
|
1026 } |
|
1027 #endif |
|
1028 |
|
1029 /*! \internal |
|
1030 */ |
|
1031 QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f) |
|
1032 : QObject(dd, 0), QPaintDevice() |
|
1033 { |
|
1034 Q_D(QWidget); |
|
1035 QT_TRY { |
|
1036 d->init(parent, f); |
|
1037 } QT_CATCH(...) { |
|
1038 QWidgetExceptionCleaner::cleanup(this, d_func()); |
|
1039 QT_RETHROW; |
|
1040 } |
|
1041 } |
|
1042 |
|
1043 /*! |
|
1044 \internal |
|
1045 */ |
|
1046 int QWidget::devType() const |
|
1047 { |
|
1048 return QInternal::Widget; |
|
1049 } |
|
1050 |
|
1051 |
|
1052 //### w is a "this" ptr, passed as a param because QWorkspace needs special logic |
|
1053 void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w) |
|
1054 { |
|
1055 bool customize = (flags & (Qt::CustomizeWindowHint |
|
1056 | Qt::FramelessWindowHint |
|
1057 | Qt::WindowTitleHint |
|
1058 | Qt::WindowSystemMenuHint |
|
1059 | Qt::WindowMinimizeButtonHint |
|
1060 | Qt::WindowMaximizeButtonHint |
|
1061 | Qt::WindowCloseButtonHint |
|
1062 | Qt::WindowContextHelpButtonHint)); |
|
1063 |
|
1064 uint type = (flags & Qt::WindowType_Mask); |
|
1065 |
|
1066 if ((type == Qt::Widget || type == Qt::SubWindow) && w && !w->parent()) { |
|
1067 type = Qt::Window; |
|
1068 flags |= Qt::Window; |
|
1069 } |
|
1070 |
|
1071 if (flags & Qt::CustomizeWindowHint) { |
|
1072 // modify window flags to make them consistent. |
|
1073 // Only enable this on non-Mac platforms. Since the old way of doing this would |
|
1074 // interpret WindowSystemMenuHint as a close button and we can't change that behavior |
|
1075 // we can't just add this in. |
|
1076 #ifndef Q_WS_MAC |
|
1077 if (flags & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint)) { |
|
1078 flags |= Qt::WindowSystemMenuHint; |
|
1079 #else |
|
1080 if (flags & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint |
|
1081 | Qt::WindowSystemMenuHint)) { |
|
1082 #endif |
|
1083 flags |= Qt::WindowTitleHint; |
|
1084 flags &= ~Qt::FramelessWindowHint; |
|
1085 } |
|
1086 } else if (customize && !(flags & Qt::FramelessWindowHint)) { |
|
1087 // if any of the window hints that affect the titlebar are set |
|
1088 // and the window is supposed to have frame, we add a titlebar |
|
1089 // and system menu by default. |
|
1090 flags |= Qt::WindowSystemMenuHint; |
|
1091 flags |= Qt::WindowTitleHint; |
|
1092 } |
|
1093 if (customize) |
|
1094 ; // don't modify window flags if the user explicitely set them. |
|
1095 else if (type == Qt::Dialog || type == Qt::Sheet) |
|
1096 #ifndef Q_WS_WINCE |
|
1097 flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint | Qt::WindowCloseButtonHint; |
|
1098 #else |
|
1099 flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; |
|
1100 #endif |
|
1101 else if (type == Qt::Tool) |
|
1102 flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; |
|
1103 else |
|
1104 flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint; |
|
1105 |
|
1106 |
|
1107 } |
|
1108 |
|
1109 void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) |
|
1110 { |
|
1111 Q_Q(QWidget); |
|
1112 if (QApplication::type() == QApplication::Tty) |
|
1113 qFatal("QWidget: Cannot create a QWidget when no GUI is being used"); |
|
1114 |
|
1115 Q_ASSERT(allWidgets); |
|
1116 allWidgets->insert(q); |
|
1117 |
|
1118 QWidget *desktopWidget = 0; |
|
1119 if (parentWidget && parentWidget->windowType() == Qt::Desktop) { |
|
1120 desktopWidget = parentWidget; |
|
1121 parentWidget = 0; |
|
1122 } |
|
1123 |
|
1124 q->data = &data; |
|
1125 |
|
1126 #ifndef QT_NO_THREAD |
|
1127 if (!parent) { |
|
1128 Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget", |
|
1129 "Widgets must be created in the GUI thread."); |
|
1130 } |
|
1131 #endif |
|
1132 |
|
1133 #if defined(Q_WS_X11) |
|
1134 if (desktopWidget) { |
|
1135 // make sure the widget is created on the same screen as the |
|
1136 // programmer specified desktop widget |
|
1137 xinfo = desktopWidget->d_func()->xinfo; |
|
1138 } |
|
1139 #else |
|
1140 Q_UNUSED(desktopWidget); |
|
1141 #endif |
|
1142 |
|
1143 data.fstrut_dirty = true; |
|
1144 |
|
1145 data.winid = 0; |
|
1146 data.widget_attributes = 0; |
|
1147 data.window_flags = f; |
|
1148 data.window_state = 0; |
|
1149 data.focus_policy = 0; |
|
1150 data.context_menu_policy = Qt::DefaultContextMenu; |
|
1151 data.window_modality = Qt::NonModal; |
|
1152 |
|
1153 data.sizehint_forced = 0; |
|
1154 data.is_closing = 0; |
|
1155 data.in_show = 0; |
|
1156 data.in_set_window_state = 0; |
|
1157 data.in_destructor = false; |
|
1158 |
|
1159 // Widgets with Qt::MSWindowsOwnDC (typically QGLWidget) must have a window handle. |
|
1160 if (f & Qt::MSWindowsOwnDC) |
|
1161 q->setAttribute(Qt::WA_NativeWindow); |
|
1162 |
|
1163 q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute() |
|
1164 adjustQuitOnCloseAttribute(); |
|
1165 |
|
1166 q->setAttribute(Qt::WA_WState_Hidden); |
|
1167 |
|
1168 //give potential windows a bigger "pre-initial" size; create_sys() will give them a new size later |
|
1169 data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,640,480); |
|
1170 |
|
1171 focus_next = focus_prev = q; |
|
1172 |
|
1173 if ((f & Qt::WindowType_Mask) == Qt::Desktop) |
|
1174 q->create(); |
|
1175 else if (parentWidget) |
|
1176 q->setParent(parentWidget, data.window_flags); |
|
1177 else { |
|
1178 adjustFlags(data.window_flags, q); |
|
1179 resolveLayoutDirection(); |
|
1180 // opaque system background? |
|
1181 const QBrush &background = q->palette().brush(QPalette::Window); |
|
1182 setOpaque(q->isWindow() && background.style() != Qt::NoBrush && background.isOpaque()); |
|
1183 } |
|
1184 data.fnt = QFont(data.fnt, q); |
|
1185 #if defined(Q_WS_X11) |
|
1186 data.fnt.x11SetScreen(xinfo.screen()); |
|
1187 #endif // Q_WS_X11 |
|
1188 |
|
1189 q->setAttribute(Qt::WA_PendingMoveEvent); |
|
1190 q->setAttribute(Qt::WA_PendingResizeEvent); |
|
1191 |
|
1192 if (++QWidgetPrivate::instanceCounter > QWidgetPrivate::maxInstances) |
|
1193 QWidgetPrivate::maxInstances = QWidgetPrivate::instanceCounter; |
|
1194 |
|
1195 if (QApplicationPrivate::app_compile_version < 0x040200 |
|
1196 || QApplicationPrivate::testAttribute(Qt::AA_ImmediateWidgetCreation)) |
|
1197 q->create(); |
|
1198 |
|
1199 |
|
1200 QEvent e(QEvent::Create); |
|
1201 QApplication::sendEvent(q, &e); |
|
1202 QApplication::postEvent(q, new QEvent(QEvent::PolishRequest)); |
|
1203 |
|
1204 extraPaintEngine = 0; |
|
1205 } |
|
1206 |
|
1207 |
|
1208 |
|
1209 void QWidgetPrivate::createRecursively() |
|
1210 { |
|
1211 Q_Q(QWidget); |
|
1212 q->create(0, true, true); |
|
1213 for (int i = 0; i < children.size(); ++i) { |
|
1214 QWidget *child = qobject_cast<QWidget *>(children.at(i)); |
|
1215 if (child && !child->isHidden() && !child->isWindow() && !child->testAttribute(Qt::WA_WState_Created)) |
|
1216 child->d_func()->createRecursively(); |
|
1217 } |
|
1218 } |
|
1219 |
|
1220 |
|
1221 |
|
1222 |
|
1223 /*! |
|
1224 Creates a new widget window if \a window is 0, otherwise sets the |
|
1225 widget's window to \a window. |
|
1226 |
|
1227 Initializes the window (sets the geometry etc.) if \a |
|
1228 initializeWindow is true. If \a initializeWindow is false, no |
|
1229 initialization is performed. This parameter only makes sense if \a |
|
1230 window is a valid window. |
|
1231 |
|
1232 Destroys the old window if \a destroyOldWindow is true. If \a |
|
1233 destroyOldWindow is false, you are responsible for destroying the |
|
1234 window yourself (using platform native code). |
|
1235 |
|
1236 The QWidget constructor calls create(0,true,true) to create a |
|
1237 window for this widget. |
|
1238 */ |
|
1239 |
|
1240 void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) |
|
1241 { |
|
1242 Q_D(QWidget); |
|
1243 if (testAttribute(Qt::WA_WState_Created) && window == 0 && internalWinId()) |
|
1244 return; |
|
1245 |
|
1246 if (d->data.in_destructor) |
|
1247 return; |
|
1248 |
|
1249 Qt::WindowType type = windowType(); |
|
1250 Qt::WindowFlags &flags = data->window_flags; |
|
1251 |
|
1252 if ((type == Qt::Widget || type == Qt::SubWindow) && !parentWidget()) { |
|
1253 type = Qt::Window; |
|
1254 flags |= Qt::Window; |
|
1255 } |
|
1256 |
|
1257 if (QWidget *parent = parentWidget()) { |
|
1258 if (type & Qt::Window) { |
|
1259 if (!parent->testAttribute(Qt::WA_WState_Created)) |
|
1260 parent->createWinId(); |
|
1261 } else if (testAttribute(Qt::WA_NativeWindow) && !parent->internalWinId() |
|
1262 && !testAttribute(Qt::WA_DontCreateNativeAncestors)) { |
|
1263 // We're about to create a native child widget that doesn't have a native parent; |
|
1264 // enforce a native handle for the parent unless the Qt::WA_DontCreateNativeAncestors |
|
1265 // attribute is set. |
|
1266 d->createWinId(window); |
|
1267 // Nothing more to do. |
|
1268 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); |
|
1269 Q_ASSERT(internalWinId()); |
|
1270 return; |
|
1271 } |
|
1272 } |
|
1273 |
|
1274 #ifdef QT3_SUPPORT |
|
1275 if (flags & Qt::WStaticContents) |
|
1276 setAttribute(Qt::WA_StaticContents); |
|
1277 if (flags & Qt::WDestructiveClose) |
|
1278 setAttribute(Qt::WA_DeleteOnClose); |
|
1279 if (flags & Qt::WShowModal) |
|
1280 setWindowModality(Qt::ApplicationModal); |
|
1281 if (flags & Qt::WMouseNoMask) |
|
1282 setAttribute(Qt::WA_MouseNoMask); |
|
1283 if (flags & Qt::WGroupLeader) |
|
1284 setAttribute(Qt::WA_GroupLeader); |
|
1285 if (flags & Qt::WNoMousePropagation) |
|
1286 setAttribute(Qt::WA_NoMousePropagation); |
|
1287 #endif |
|
1288 |
|
1289 static int paintOnScreenEnv = -1; |
|
1290 if (paintOnScreenEnv == -1) |
|
1291 paintOnScreenEnv = qgetenv("QT_ONSCREEN_PAINT").toInt() > 0 ? 1 : 0; |
|
1292 if (paintOnScreenEnv == 1) |
|
1293 setAttribute(Qt::WA_PaintOnScreen); |
|
1294 |
|
1295 if (QApplicationPrivate::testAttribute(Qt::AA_NativeWindows)) |
|
1296 setAttribute(Qt::WA_NativeWindow); |
|
1297 |
|
1298 #ifdef ALIEN_DEBUG |
|
1299 qDebug() << "QWidget::create:" << this << "parent:" << parentWidget() |
|
1300 << "Alien?" << !testAttribute(Qt::WA_NativeWindow); |
|
1301 #endif |
|
1302 |
|
1303 #if defined (Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP) |
|
1304 // Unregister the dropsite (if already registered) before we |
|
1305 // re-create the widget with a native window. |
|
1306 if (testAttribute(Qt::WA_WState_Created) && !internalWinId() && testAttribute(Qt::WA_NativeWindow) |
|
1307 && d->extra && d->extra->dropTarget) { |
|
1308 d->registerDropSite(false); |
|
1309 } |
|
1310 #endif // defined (Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP) |
|
1311 |
|
1312 d->updateIsOpaque(); |
|
1313 |
|
1314 setAttribute(Qt::WA_WState_Created); // set created flag |
|
1315 d->create_sys(window, initializeWindow, destroyOldWindow); |
|
1316 |
|
1317 // a real toplevel window needs a backing store |
|
1318 if (isWindow() && windowType() != Qt::Desktop) { |
|
1319 delete d->topData()->backingStore; |
|
1320 // QWidgetBackingStore will check this variable, hence it must be 0 |
|
1321 d->topData()->backingStore = 0; |
|
1322 if (hasBackingStoreSupport()) |
|
1323 d->topData()->backingStore = new QWidgetBackingStore(this); |
|
1324 } |
|
1325 |
|
1326 d->setModal_sys(); |
|
1327 |
|
1328 if (!isWindow() && parentWidget() && parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)) |
|
1329 setAttribute(Qt::WA_DropSiteRegistered, true); |
|
1330 |
|
1331 #ifdef QT_EVAL |
|
1332 extern void qt_eval_init_widget(QWidget *w); |
|
1333 qt_eval_init_widget(this); |
|
1334 #endif |
|
1335 |
|
1336 // need to force the resting of the icon after changing parents |
|
1337 if (testAttribute(Qt::WA_SetWindowIcon)) |
|
1338 d->setWindowIcon_sys(true); |
|
1339 if (isWindow() && !d->topData()->iconText.isEmpty()) |
|
1340 d->setWindowIconText_helper(d->topData()->iconText); |
|
1341 if (isWindow() && !d->topData()->caption.isEmpty()) |
|
1342 d->setWindowTitle_helper(d->topData()->caption); |
|
1343 if (windowType() != Qt::Desktop) { |
|
1344 d->updateSystemBackground(); |
|
1345 |
|
1346 if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon)) |
|
1347 d->setWindowIcon_sys(); |
|
1348 } |
|
1349 } |
|
1350 |
|
1351 /*! |
|
1352 Destroys the widget. |
|
1353 |
|
1354 All this widget's children are deleted first. The application |
|
1355 exits if this widget is the main widget. |
|
1356 */ |
|
1357 |
|
1358 QWidget::~QWidget() |
|
1359 { |
|
1360 Q_D(QWidget); |
|
1361 d->data.in_destructor = true; |
|
1362 |
|
1363 #if defined (QT_CHECK_STATE) |
|
1364 if (paintingActive()) |
|
1365 qWarning("QWidget: %s (%s) deleted while being painted", className(), name()); |
|
1366 #endif |
|
1367 |
|
1368 // force acceptDrops false before winId is destroyed. |
|
1369 d->registerDropSite(false); |
|
1370 |
|
1371 #ifndef QT_NO_ACTION |
|
1372 // remove all actions from this widget |
|
1373 for (int i = 0; i < d->actions.size(); ++i) { |
|
1374 QActionPrivate *apriv = d->actions.at(i)->d_func(); |
|
1375 apriv->widgets.removeAll(this); |
|
1376 } |
|
1377 d->actions.clear(); |
|
1378 #endif |
|
1379 |
|
1380 #ifndef QT_NO_SHORTCUT |
|
1381 // Remove all shortcuts grabbed by this |
|
1382 // widget, unless application is closing |
|
1383 if (!QApplicationPrivate::is_app_closing && testAttribute(Qt::WA_GrabbedShortcut)) |
|
1384 qApp->d_func()->shortcutMap.removeShortcut(0, this, QKeySequence()); |
|
1385 #endif |
|
1386 |
|
1387 // delete layout while we still are a valid widget |
|
1388 delete d->layout; |
|
1389 // Remove myself from focus list |
|
1390 |
|
1391 Q_ASSERT(d->focus_next->d_func()->focus_prev == this); |
|
1392 Q_ASSERT(d->focus_prev->d_func()->focus_next == this); |
|
1393 |
|
1394 if (d->focus_next != this) { |
|
1395 d->focus_next->d_func()->focus_prev = d->focus_prev; |
|
1396 d->focus_prev->d_func()->focus_next = d->focus_next; |
|
1397 d->focus_next = d->focus_prev = 0; |
|
1398 } |
|
1399 |
|
1400 #ifdef QT3_SUPPORT |
|
1401 if (QApplicationPrivate::main_widget == this) { // reset main widget |
|
1402 QApplicationPrivate::main_widget = 0; |
|
1403 QApplication::quit(); |
|
1404 } |
|
1405 #endif |
|
1406 |
|
1407 QT_TRY { |
|
1408 clearFocus(); |
|
1409 } QT_CATCH(...) { |
|
1410 // swallow this problem because we are in a destructor |
|
1411 } |
|
1412 |
|
1413 d->setDirtyOpaqueRegion(); |
|
1414 |
|
1415 if (isWindow() && isVisible() && internalWinId()) { |
|
1416 QT_TRY { |
|
1417 d->close_helper(QWidgetPrivate::CloseNoEvent); |
|
1418 } QT_CATCH(...) { |
|
1419 // if we're out of memory, at least hide the window. |
|
1420 QT_TRY { |
|
1421 hide(); |
|
1422 } QT_CATCH(...) { |
|
1423 // and if that also doesn't work, then give up |
|
1424 } |
|
1425 } |
|
1426 } |
|
1427 |
|
1428 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) |
|
1429 else if (!internalWinId() && isVisible()) { |
|
1430 qApp->d_func()->sendSyntheticEnterLeave(this); |
|
1431 #ifdef Q_WS_QWS |
|
1432 } else if (isVisible()) { |
|
1433 qApp->d_func()->sendSyntheticEnterLeave(this); |
|
1434 #endif |
|
1435 } |
|
1436 #endif |
|
1437 |
|
1438 if (QWidgetBackingStore *bs = d->maybeBackingStore()) { |
|
1439 bs->removeDirtyWidget(this); |
|
1440 if (testAttribute(Qt::WA_StaticContents)) |
|
1441 bs->removeStaticWidget(this); |
|
1442 } |
|
1443 |
|
1444 delete d->needsFlush; |
|
1445 d->needsFlush = 0; |
|
1446 |
|
1447 // set all QPointers for this object to zero |
|
1448 QObjectPrivate::clearGuards(this); |
|
1449 |
|
1450 if (d->declarativeData) { |
|
1451 d->declarativeData->destroyed(this); |
|
1452 d->declarativeData = 0; // don't activate again in ~QObject |
|
1453 } |
|
1454 |
|
1455 if (!d->children.isEmpty()) |
|
1456 d->deleteChildren(); |
|
1457 |
|
1458 QApplication::removePostedEvents(this); |
|
1459 |
|
1460 QT_TRY { |
|
1461 destroy(); // platform-dependent cleanup |
|
1462 } QT_CATCH(...) { |
|
1463 // if this fails we can't do anything about it but at least we are not allowed to throw. |
|
1464 } |
|
1465 --QWidgetPrivate::instanceCounter; |
|
1466 |
|
1467 if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication |
|
1468 QWidgetPrivate::allWidgets->remove(this); |
|
1469 |
|
1470 QEvent e(QEvent::Destroy); |
|
1471 QCoreApplication::sendEvent(this, &e); |
|
1472 } |
|
1473 |
|
1474 int QWidgetPrivate::instanceCounter = 0; // Current number of widget instances |
|
1475 int QWidgetPrivate::maxInstances = 0; // Maximum number of widget instances |
|
1476 |
|
1477 void QWidgetPrivate::setWinId(WId id) // set widget identifier |
|
1478 { |
|
1479 Q_Q(QWidget); |
|
1480 // the user might create a widget with Qt::Desktop window |
|
1481 // attribute (or create another QDesktopWidget instance), which |
|
1482 // will have the same windowid (the root window id) as the |
|
1483 // qt_desktopWidget. We should not add the second desktop widget |
|
1484 // to the mapper. |
|
1485 bool userDesktopWidget = qt_desktopWidget != 0 && qt_desktopWidget != q && q->windowType() == Qt::Desktop; |
|
1486 if (mapper && data.winid && !userDesktopWidget) { |
|
1487 mapper->remove(data.winid); |
|
1488 } |
|
1489 |
|
1490 const WId oldWinId = data.winid; |
|
1491 |
|
1492 data.winid = id; |
|
1493 #if defined(Q_WS_X11) |
|
1494 hd = id; // X11: hd == ident |
|
1495 #endif |
|
1496 if (mapper && id && !userDesktopWidget) { |
|
1497 mapper->insert(data.winid, q); |
|
1498 } |
|
1499 |
|
1500 if(oldWinId != id) { |
|
1501 // Do not emit an event when the old winId is destroyed. This only |
|
1502 // happens (a) during widget destruction, and (b) immediately prior |
|
1503 // to creation of a new winId, for example as a result of re-parenting. |
|
1504 if(id != 0) { |
|
1505 QEvent e(QEvent::WinIdChange); |
|
1506 QCoreApplication::sendEvent(q, &e); |
|
1507 } |
|
1508 } |
|
1509 } |
|
1510 |
|
1511 void QWidgetPrivate::createTLExtra() |
|
1512 { |
|
1513 if (!extra) |
|
1514 createExtra(); |
|
1515 if (!extra->topextra) { |
|
1516 QTLWExtra* x = extra->topextra = new QTLWExtra; |
|
1517 x->icon = 0; |
|
1518 x->iconPixmap = 0; |
|
1519 x->backingStore = 0; |
|
1520 x->windowSurface = 0; |
|
1521 x->sharedPainter = 0; |
|
1522 x->incw = x->inch = 0; |
|
1523 x->basew = x->baseh = 0; |
|
1524 x->frameStrut.setCoords(0, 0, 0, 0); |
|
1525 x->normalGeometry = QRect(0,0,-1,-1); |
|
1526 x->savedFlags = 0; |
|
1527 x->opacity = 255; |
|
1528 x->posFromMove = false; |
|
1529 x->sizeAdjusted = false; |
|
1530 x->inTopLevelResize = false; |
|
1531 x->inRepaint = false; |
|
1532 x->embedded = 0; |
|
1533 createTLSysExtra(); |
|
1534 #ifdef QWIDGET_EXTRA_DEBUG |
|
1535 static int count = 0; |
|
1536 qDebug() << "tlextra" << ++count; |
|
1537 #endif |
|
1538 } |
|
1539 } |
|
1540 |
|
1541 /*! |
|
1542 \internal |
|
1543 Creates the widget extra data. |
|
1544 */ |
|
1545 |
|
1546 void QWidgetPrivate::createExtra() |
|
1547 { |
|
1548 if (!extra) { // if not exists |
|
1549 extra = new QWExtra; |
|
1550 extra->glContext = 0; |
|
1551 extra->topextra = 0; |
|
1552 extra->proxyWidget = 0; |
|
1553 #ifndef QT_NO_CURSOR |
|
1554 extra->curs = 0; |
|
1555 #endif |
|
1556 extra->minw = 0; |
|
1557 extra->minh = 0; |
|
1558 extra->maxw = QWIDGETSIZE_MAX; |
|
1559 extra->maxh = QWIDGETSIZE_MAX; |
|
1560 extra->customDpiX = 0; |
|
1561 extra->customDpiY = 0; |
|
1562 extra->explicitMinSize = 0; |
|
1563 extra->explicitMaxSize = 0; |
|
1564 extra->autoFillBackground = 0; |
|
1565 extra->nativeChildrenForced = 0; |
|
1566 extra->inRenderWithPainter = 0; |
|
1567 extra->hasMask = 0; |
|
1568 createSysExtra(); |
|
1569 #ifdef QWIDGET_EXTRA_DEBUG |
|
1570 static int count = 0; |
|
1571 qDebug() << "extra" << ++count; |
|
1572 #endif |
|
1573 } |
|
1574 } |
|
1575 |
|
1576 |
|
1577 /*! |
|
1578 \internal |
|
1579 Deletes the widget extra data. |
|
1580 */ |
|
1581 |
|
1582 void QWidgetPrivate::deleteExtra() |
|
1583 { |
|
1584 if (extra) { // if exists |
|
1585 #ifndef QT_NO_CURSOR |
|
1586 delete extra->curs; |
|
1587 #endif |
|
1588 deleteSysExtra(); |
|
1589 #ifndef QT_NO_STYLE_STYLESHEET |
|
1590 // dereference the stylesheet style |
|
1591 if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(extra->style)) |
|
1592 proxy->deref(); |
|
1593 #endif |
|
1594 if (extra->topextra) { |
|
1595 deleteTLSysExtra(); |
|
1596 delete extra->topextra->backingStore; |
|
1597 delete extra->topextra->icon; |
|
1598 delete extra->topextra->iconPixmap; |
|
1599 #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER) |
|
1600 delete extra->topextra->qwsManager; |
|
1601 #endif |
|
1602 delete extra->topextra->windowSurface; |
|
1603 delete extra->topextra; |
|
1604 } |
|
1605 delete extra; |
|
1606 // extra->xic destroyed in QWidget::destroy() |
|
1607 extra = 0; |
|
1608 } |
|
1609 } |
|
1610 |
|
1611 /* |
|
1612 Returns true if there are widgets above this which overlap with |
|
1613 \a rect, which is in parent's coordinate system (same as crect). |
|
1614 */ |
|
1615 |
|
1616 bool QWidgetPrivate::isOverlapped(const QRect &rect) const |
|
1617 { |
|
1618 Q_Q(const QWidget); |
|
1619 |
|
1620 const QWidget *w = q; |
|
1621 QRect r = rect; |
|
1622 while (w) { |
|
1623 if (w->isWindow()) |
|
1624 return false; |
|
1625 QWidgetPrivate *pd = w->parentWidget()->d_func(); |
|
1626 bool above = false; |
|
1627 for (int i = 0; i < pd->children.size(); ++i) { |
|
1628 QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i)); |
|
1629 if (!sibling || !sibling->isVisible() || sibling->isWindow()) |
|
1630 continue; |
|
1631 if (!above) { |
|
1632 above = (sibling == w); |
|
1633 continue; |
|
1634 } |
|
1635 |
|
1636 if (qRectIntersects(sibling->d_func()->effectiveRectFor(sibling->data->crect), r)) { |
|
1637 const QWExtra *siblingExtra = sibling->d_func()->extra; |
|
1638 if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect |
|
1639 && !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) { |
|
1640 continue; |
|
1641 } |
|
1642 return true; |
|
1643 } |
|
1644 } |
|
1645 w = w->parentWidget(); |
|
1646 r.translate(pd->data.crect.topLeft()); |
|
1647 } |
|
1648 return false; |
|
1649 } |
|
1650 |
|
1651 void QWidgetPrivate::syncBackingStore() |
|
1652 { |
|
1653 if (paintOnScreen()) { |
|
1654 repaint_sys(dirty); |
|
1655 dirty = QRegion(); |
|
1656 } else if (QWidgetBackingStore *bs = maybeBackingStore()) { |
|
1657 bs->sync(); |
|
1658 } |
|
1659 } |
|
1660 |
|
1661 void QWidgetPrivate::syncBackingStore(const QRegion ®ion) |
|
1662 { |
|
1663 if (paintOnScreen()) |
|
1664 repaint_sys(region); |
|
1665 else if (QWidgetBackingStore *bs = maybeBackingStore()) |
|
1666 bs->sync(q_func(), region); |
|
1667 } |
|
1668 |
|
1669 void QWidgetPrivate::setUpdatesEnabled_helper(bool enable) |
|
1670 { |
|
1671 Q_Q(QWidget); |
|
1672 |
|
1673 if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->updatesEnabled()) |
|
1674 return; // nothing we can do |
|
1675 |
|
1676 if (enable != q->testAttribute(Qt::WA_UpdatesDisabled)) |
|
1677 return; // nothing to do |
|
1678 |
|
1679 q->setAttribute(Qt::WA_UpdatesDisabled, !enable); |
|
1680 if (enable) |
|
1681 q->update(); |
|
1682 |
|
1683 Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceUpdatesDisabled : Qt::WA_UpdatesDisabled; |
|
1684 for (int i = 0; i < children.size(); ++i) { |
|
1685 QWidget *w = qobject_cast<QWidget *>(children.at(i)); |
|
1686 if (w && !w->isWindow() && !w->testAttribute(attribute)) |
|
1687 w->d_func()->setUpdatesEnabled_helper(enable); |
|
1688 } |
|
1689 } |
|
1690 |
|
1691 /*! |
|
1692 \internal |
|
1693 |
|
1694 Propagate this widget's palette to all children, except style sheet |
|
1695 widgets, and windows that don't enable window propagation (palettes don't |
|
1696 normally propagate to windows). |
|
1697 */ |
|
1698 void QWidgetPrivate::propagatePaletteChange() |
|
1699 { |
|
1700 Q_Q(QWidget); |
|
1701 // Propagate a new inherited mask to all children. |
|
1702 if (!q->parentWidget() && extra && extra->proxyWidget) { |
|
1703 #ifndef QT_NO_GRAPHICSVIEW |
|
1704 QGraphicsProxyWidget *p = extra->proxyWidget; |
|
1705 inheritedPaletteResolveMask = p->d_func()->inheritedPaletteResolveMask | p->palette().resolve(); |
|
1706 #endif //QT_NO_GRAPHICSVIEW |
|
1707 } else if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) { |
|
1708 inheritedPaletteResolveMask = 0; |
|
1709 } |
|
1710 int mask = data.pal.resolve() | inheritedPaletteResolveMask; |
|
1711 |
|
1712 QEvent pc(QEvent::PaletteChange); |
|
1713 QApplication::sendEvent(q, &pc); |
|
1714 for (int i = 0; i < children.size(); ++i) { |
|
1715 QWidget *w = qobject_cast<QWidget*>(children.at(i)); |
|
1716 if (w && !w->testAttribute(Qt::WA_StyleSheet) |
|
1717 && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) { |
|
1718 QWidgetPrivate *wd = w->d_func(); |
|
1719 wd->inheritedPaletteResolveMask = mask; |
|
1720 wd->resolvePalette(); |
|
1721 } |
|
1722 } |
|
1723 #if defined(QT3_SUPPORT) |
|
1724 q->paletteChange(q->palette()); // compatibility |
|
1725 #endif |
|
1726 } |
|
1727 |
|
1728 /* |
|
1729 Returns the widget's clipping rectangle. |
|
1730 */ |
|
1731 QRect QWidgetPrivate::clipRect() const |
|
1732 { |
|
1733 Q_Q(const QWidget); |
|
1734 const QWidget * w = q; |
|
1735 if (!w->isVisible()) |
|
1736 return QRect(); |
|
1737 QRect r = effectiveRectFor(q->rect()); |
|
1738 int ox = 0; |
|
1739 int oy = 0; |
|
1740 while (w |
|
1741 && w->isVisible() |
|
1742 && !w->isWindow() |
|
1743 && w->parentWidget()) { |
|
1744 ox -= w->x(); |
|
1745 oy -= w->y(); |
|
1746 w = w->parentWidget(); |
|
1747 r &= QRect(ox, oy, w->width(), w->height()); |
|
1748 } |
|
1749 return r; |
|
1750 } |
|
1751 |
|
1752 /* |
|
1753 Returns the widget's clipping region (without siblings). |
|
1754 */ |
|
1755 QRegion QWidgetPrivate::clipRegion() const |
|
1756 { |
|
1757 Q_Q(const QWidget); |
|
1758 if (!q->isVisible()) |
|
1759 return QRegion(); |
|
1760 QRegion r(q->rect()); |
|
1761 const QWidget * w = q; |
|
1762 const QWidget *ignoreUpTo; |
|
1763 int ox = 0; |
|
1764 int oy = 0; |
|
1765 while (w |
|
1766 && w->isVisible() |
|
1767 && !w->isWindow() |
|
1768 && w->parentWidget()) { |
|
1769 ox -= w->x(); |
|
1770 oy -= w->y(); |
|
1771 ignoreUpTo = w; |
|
1772 w = w->parentWidget(); |
|
1773 r &= QRegion(ox, oy, w->width(), w->height()); |
|
1774 |
|
1775 int i = 0; |
|
1776 while(w->d_func()->children.at(i++) != static_cast<const QObject *>(ignoreUpTo)) |
|
1777 ; |
|
1778 for ( ; i < w->d_func()->children.size(); ++i) { |
|
1779 if(QWidget *sibling = qobject_cast<QWidget *>(w->d_func()->children.at(i))) { |
|
1780 if(sibling->isVisible() && !sibling->isWindow()) { |
|
1781 QRect siblingRect(ox+sibling->x(), oy+sibling->y(), |
|
1782 sibling->width(), sibling->height()); |
|
1783 if (qRectIntersects(siblingRect, q->rect())) |
|
1784 r -= QRegion(siblingRect); |
|
1785 } |
|
1786 } |
|
1787 } |
|
1788 } |
|
1789 return r; |
|
1790 } |
|
1791 |
|
1792 void QWidgetPrivate::invalidateGraphicsEffectsRecursively() |
|
1793 { |
|
1794 Q_Q(QWidget); |
|
1795 QWidget *w = q; |
|
1796 do { |
|
1797 if (w->graphicsEffect()) { |
|
1798 QWidgetEffectSourcePrivate *sourced = |
|
1799 static_cast<QWidgetEffectSourcePrivate *>(w->graphicsEffect()->source()->d_func()); |
|
1800 if (!sourced->updateDueToGraphicsEffect) |
|
1801 w->graphicsEffect()->source()->d_func()->invalidateCache(); |
|
1802 } |
|
1803 w = w->parentWidget(); |
|
1804 } while (w); |
|
1805 } |
|
1806 |
|
1807 void QWidgetPrivate::setDirtyOpaqueRegion() |
|
1808 { |
|
1809 Q_Q(QWidget); |
|
1810 |
|
1811 dirtyOpaqueChildren = true; |
|
1812 |
|
1813 invalidateGraphicsEffectsRecursively(); |
|
1814 |
|
1815 if (q->isWindow()) |
|
1816 return; |
|
1817 |
|
1818 QWidget *parent = q->parentWidget(); |
|
1819 if (!parent) |
|
1820 return; |
|
1821 |
|
1822 // TODO: instead of setting dirtyflag, manipulate the dirtyregion directly? |
|
1823 QWidgetPrivate *pd = parent->d_func(); |
|
1824 if (!pd->dirtyOpaqueChildren) |
|
1825 pd->setDirtyOpaqueRegion(); |
|
1826 } |
|
1827 |
|
1828 QRegion QWidgetPrivate::getOpaqueRegion() const |
|
1829 { |
|
1830 Q_Q(const QWidget); |
|
1831 |
|
1832 QRegion r = isOpaque ? q->rect() : getOpaqueChildren(); |
|
1833 if (extra && extra->hasMask) |
|
1834 r &= extra->mask; |
|
1835 if (r.isEmpty()) |
|
1836 return r; |
|
1837 return r & clipRect(); |
|
1838 } |
|
1839 |
|
1840 const QRegion &QWidgetPrivate::getOpaqueChildren() const |
|
1841 { |
|
1842 if (!dirtyOpaqueChildren) |
|
1843 return opaqueChildren; |
|
1844 |
|
1845 QWidgetPrivate *that = const_cast<QWidgetPrivate*>(this); |
|
1846 that->opaqueChildren = QRegion(); |
|
1847 |
|
1848 for (int i = 0; i < children.size(); ++i) { |
|
1849 QWidget *child = qobject_cast<QWidget *>(children.at(i)); |
|
1850 if (!child || !child->isVisible() || child->isWindow()) |
|
1851 continue; |
|
1852 |
|
1853 const QPoint offset = child->geometry().topLeft(); |
|
1854 that->opaqueChildren += child->d_func()->getOpaqueRegion().translated(offset); |
|
1855 } |
|
1856 |
|
1857 that->dirtyOpaqueChildren = false; |
|
1858 |
|
1859 return that->opaqueChildren; |
|
1860 } |
|
1861 |
|
1862 void QWidgetPrivate::subtractOpaqueChildren(QRegion &source, const QRect &clipRect) const |
|
1863 { |
|
1864 if (children.isEmpty() || clipRect.isEmpty()) |
|
1865 return; |
|
1866 |
|
1867 const QRegion &r = getOpaqueChildren(); |
|
1868 if (!r.isEmpty()) |
|
1869 source -= (r & clipRect); |
|
1870 } |
|
1871 |
|
1872 //subtract any relatives that are higher up than me --- this is too expensive !!! |
|
1873 void QWidgetPrivate::subtractOpaqueSiblings(QRegion &sourceRegion, bool *hasDirtySiblingsAbove, |
|
1874 bool alsoNonOpaque) const |
|
1875 { |
|
1876 Q_Q(const QWidget); |
|
1877 static int disableSubtractOpaqueSiblings = qgetenv("QT_NO_SUBTRACTOPAQUESIBLINGS").toInt(); |
|
1878 if (disableSubtractOpaqueSiblings || q->isWindow()) |
|
1879 return; |
|
1880 |
|
1881 QRect clipBoundingRect; |
|
1882 bool dirtyClipBoundingRect = true; |
|
1883 |
|
1884 QRegion parentClip; |
|
1885 bool dirtyParentClip = true; |
|
1886 |
|
1887 QPoint parentOffset = data.crect.topLeft(); |
|
1888 |
|
1889 const QWidget *w = q; |
|
1890 |
|
1891 while (w) { |
|
1892 if (w->isWindow()) |
|
1893 break; |
|
1894 QWidgetPrivate *pd = w->parentWidget()->d_func(); |
|
1895 const int myIndex = pd->children.indexOf(const_cast<QWidget *>(w)); |
|
1896 const QRect widgetGeometry = w->d_func()->effectiveRectFor(w->data->crect); |
|
1897 for (int i = myIndex + 1; i < pd->children.size(); ++i) { |
|
1898 QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i)); |
|
1899 if (!sibling || !sibling->isVisible() || sibling->isWindow()) |
|
1900 continue; |
|
1901 |
|
1902 const QRect siblingGeometry = sibling->d_func()->effectiveRectFor(sibling->data->crect); |
|
1903 if (!qRectIntersects(siblingGeometry, widgetGeometry)) |
|
1904 continue; |
|
1905 |
|
1906 if (dirtyClipBoundingRect) { |
|
1907 clipBoundingRect = sourceRegion.boundingRect(); |
|
1908 dirtyClipBoundingRect = false; |
|
1909 } |
|
1910 |
|
1911 if (!qRectIntersects(siblingGeometry, clipBoundingRect.translated(parentOffset))) |
|
1912 continue; |
|
1913 |
|
1914 if (dirtyParentClip) { |
|
1915 parentClip = sourceRegion.translated(parentOffset); |
|
1916 dirtyParentClip = false; |
|
1917 } |
|
1918 |
|
1919 const QPoint siblingPos(sibling->data->crect.topLeft()); |
|
1920 const QRect siblingClipRect(sibling->d_func()->clipRect()); |
|
1921 QRegion siblingDirty(parentClip); |
|
1922 siblingDirty &= (siblingClipRect.translated(siblingPos)); |
|
1923 const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask |
|
1924 && !sibling->d_func()->graphicsEffect; |
|
1925 if (hasMask) |
|
1926 siblingDirty &= sibling->d_func()->extra->mask.translated(siblingPos); |
|
1927 if (siblingDirty.isEmpty()) |
|
1928 continue; |
|
1929 |
|
1930 if (sibling->d_func()->isOpaque || alsoNonOpaque) { |
|
1931 if (hasMask) { |
|
1932 siblingDirty.translate(-parentOffset); |
|
1933 sourceRegion -= siblingDirty; |
|
1934 } else { |
|
1935 sourceRegion -= siblingGeometry.translated(-parentOffset); |
|
1936 } |
|
1937 } else { |
|
1938 if (hasDirtySiblingsAbove) |
|
1939 *hasDirtySiblingsAbove = true; |
|
1940 if (sibling->d_func()->children.isEmpty()) |
|
1941 continue; |
|
1942 QRegion opaqueSiblingChildren(sibling->d_func()->getOpaqueChildren()); |
|
1943 opaqueSiblingChildren.translate(-parentOffset + siblingPos); |
|
1944 sourceRegion -= opaqueSiblingChildren; |
|
1945 } |
|
1946 if (sourceRegion.isEmpty()) |
|
1947 return; |
|
1948 |
|
1949 dirtyClipBoundingRect = true; |
|
1950 dirtyParentClip = true; |
|
1951 } |
|
1952 |
|
1953 w = w->parentWidget(); |
|
1954 parentOffset += pd->data.crect.topLeft(); |
|
1955 dirtyParentClip = true; |
|
1956 } |
|
1957 } |
|
1958 |
|
1959 void QWidgetPrivate::clipToEffectiveMask(QRegion ®ion) const |
|
1960 { |
|
1961 Q_Q(const QWidget); |
|
1962 |
|
1963 const QWidget *w = q; |
|
1964 QPoint offset; |
|
1965 |
|
1966 if (graphicsEffect) { |
|
1967 w = q->parentWidget(); |
|
1968 offset -= data.crect.topLeft(); |
|
1969 } |
|
1970 |
|
1971 while (w) { |
|
1972 const QWidgetPrivate *wd = w->d_func(); |
|
1973 if (wd->extra && wd->extra->hasMask) |
|
1974 region &= (w != q) ? wd->extra->mask.translated(offset) : wd->extra->mask; |
|
1975 if (w->isWindow()) |
|
1976 return; |
|
1977 offset -= wd->data.crect.topLeft(); |
|
1978 w = w->parentWidget(); |
|
1979 } |
|
1980 } |
|
1981 |
|
1982 bool QWidgetPrivate::paintOnScreen() const |
|
1983 { |
|
1984 #if defined(Q_WS_QWS) |
|
1985 return false; |
|
1986 #elif defined(QT_NO_BACKINGSTORE) |
|
1987 return true; |
|
1988 #else |
|
1989 Q_Q(const QWidget); |
|
1990 if (q->testAttribute(Qt::WA_PaintOnScreen) |
|
1991 || (!q->isWindow() && q->window()->testAttribute(Qt::WA_PaintOnScreen))) { |
|
1992 return true; |
|
1993 } |
|
1994 |
|
1995 return !qt_enable_backingstore; |
|
1996 #endif |
|
1997 } |
|
1998 |
|
1999 void QWidgetPrivate::updateIsOpaque() |
|
2000 { |
|
2001 // hw: todo: only needed if opacity actually changed |
|
2002 setDirtyOpaqueRegion(); |
|
2003 |
|
2004 if (graphicsEffect) { |
|
2005 // ### We should probably add QGraphicsEffect::isOpaque at some point. |
|
2006 setOpaque(false); |
|
2007 return; |
|
2008 } |
|
2009 |
|
2010 Q_Q(QWidget); |
|
2011 #ifdef Q_WS_X11 |
|
2012 if (q->testAttribute(Qt::WA_X11OpenGLOverlay)) { |
|
2013 setOpaque(false); |
|
2014 return; |
|
2015 } |
|
2016 #endif |
|
2017 |
|
2018 if (q->testAttribute(Qt::WA_OpaquePaintEvent) || q->testAttribute(Qt::WA_PaintOnScreen)) { |
|
2019 setOpaque(true); |
|
2020 return; |
|
2021 } |
|
2022 |
|
2023 const QPalette &pal = q->palette(); |
|
2024 |
|
2025 if (q->autoFillBackground()) { |
|
2026 const QBrush &autoFillBrush = pal.brush(q->backgroundRole()); |
|
2027 if (autoFillBrush.style() != Qt::NoBrush && autoFillBrush.isOpaque()) { |
|
2028 setOpaque(true); |
|
2029 return; |
|
2030 } |
|
2031 } |
|
2032 |
|
2033 if (q->isWindow() && !q->testAttribute(Qt::WA_NoSystemBackground)) { |
|
2034 const QBrush &windowBrush = q->palette().brush(QPalette::Window); |
|
2035 if (windowBrush.style() != Qt::NoBrush && windowBrush.isOpaque()) { |
|
2036 setOpaque(true); |
|
2037 return; |
|
2038 } |
|
2039 } |
|
2040 setOpaque(false); |
|
2041 } |
|
2042 |
|
2043 void QWidgetPrivate::setOpaque(bool opaque) |
|
2044 { |
|
2045 if (isOpaque == opaque) |
|
2046 return; |
|
2047 isOpaque = opaque; |
|
2048 #ifdef Q_WS_MAC |
|
2049 macUpdateIsOpaque(); |
|
2050 #endif |
|
2051 #ifdef Q_WS_X11 |
|
2052 x11UpdateIsOpaque(); |
|
2053 #endif |
|
2054 #ifdef Q_WS_WIN |
|
2055 winUpdateIsOpaque(); |
|
2056 #endif |
|
2057 #ifdef Q_OS_SYMBIAN |
|
2058 s60UpdateIsOpaque(); |
|
2059 #endif |
|
2060 } |
|
2061 |
|
2062 void QWidgetPrivate::updateIsTranslucent() |
|
2063 { |
|
2064 #ifdef Q_WS_MAC |
|
2065 macUpdateIsOpaque(); |
|
2066 #endif |
|
2067 #ifdef Q_WS_X11 |
|
2068 x11UpdateIsOpaque(); |
|
2069 #endif |
|
2070 #ifdef Q_WS_WIN |
|
2071 winUpdateIsOpaque(); |
|
2072 #endif |
|
2073 #ifdef Q_OS_SYMBIAN |
|
2074 s60UpdateIsOpaque(); |
|
2075 #endif |
|
2076 } |
|
2077 |
|
2078 /*! |
|
2079 \fn void QPixmap::fill(const QWidget *widget, const QPoint &offset) |
|
2080 |
|
2081 Fills the pixmap with the \a widget's background color or pixmap |
|
2082 according to the given offset. |
|
2083 |
|
2084 The QPoint \a offset defines a point in widget coordinates to |
|
2085 which the pixmap's top-left pixel will be mapped to. This is only |
|
2086 significant if the widget has a background pixmap; otherwise the |
|
2087 pixmap will simply be filled with the background color of the |
|
2088 widget. |
|
2089 */ |
|
2090 |
|
2091 void QPixmap::fill( const QWidget *widget, const QPoint &off ) |
|
2092 { |
|
2093 QPainter p(this); |
|
2094 p.translate(-off); |
|
2095 widget->d_func()->paintBackground(&p, QRect(off, size())); |
|
2096 } |
|
2097 |
|
2098 static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush) |
|
2099 { |
|
2100 Q_ASSERT(painter); |
|
2101 |
|
2102 if (brush.style() == Qt::TexturePattern) { |
|
2103 #ifdef Q_WS_MAC |
|
2104 // Optimize pattern filling on mac by using HITheme directly |
|
2105 // when filling with the standard widget background. |
|
2106 // Defined in qmacstyle_mac.cpp |
|
2107 extern void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush); |
|
2108 qt_mac_fill_background(painter, rgn, brush); |
|
2109 #else |
|
2110 #if !defined(QT_NO_STYLE_S60) |
|
2111 // Defined in qs60style.cpp |
|
2112 extern bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush); |
|
2113 if (!qt_s60_fill_background(painter, rgn, brush)) |
|
2114 #endif // !defined(QT_NO_STYLE_S60) |
|
2115 { |
|
2116 const QRect rect(rgn.boundingRect()); |
|
2117 painter->setClipRegion(rgn); |
|
2118 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); |
|
2119 } |
|
2120 #endif // Q_WS_MAC |
|
2121 |
|
2122 } else if (brush.gradient() |
|
2123 && brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode) { |
|
2124 painter->save(); |
|
2125 painter->setClipRegion(rgn); |
|
2126 painter->fillRect(0, 0, painter->device()->width(), painter->device()->height(), brush); |
|
2127 painter->restore(); |
|
2128 } else { |
|
2129 const QVector<QRect> &rects = rgn.rects(); |
|
2130 for (int i = 0; i < rects.size(); ++i) |
|
2131 painter->fillRect(rects.at(i), brush); |
|
2132 } |
|
2133 } |
|
2134 |
|
2135 void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const |
|
2136 { |
|
2137 Q_Q(const QWidget); |
|
2138 |
|
2139 #ifndef QT_NO_SCROLLAREA |
|
2140 bool resetBrushOrigin = false; |
|
2141 QPointF oldBrushOrigin; |
|
2142 //If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture |
|
2143 QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent); |
|
2144 if (scrollArea && scrollArea->viewport() == q) { |
|
2145 QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data(); |
|
2146 QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate); |
|
2147 oldBrushOrigin = painter->brushOrigin(); |
|
2148 resetBrushOrigin = true; |
|
2149 painter->setBrushOrigin(-priv->contentsOffset()); |
|
2150 |
|
2151 } |
|
2152 #endif // QT_NO_SCROLLAREA |
|
2153 |
|
2154 const QBrush autoFillBrush = q->palette().brush(q->backgroundRole()); |
|
2155 |
|
2156 if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) { |
|
2157 const QBrush bg = q->palette().brush(QPalette::Window); |
|
2158 #ifdef Q_WS_QWS |
|
2159 if (!(flags & DontSetCompositionMode) && painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff)) |
|
2160 painter->setCompositionMode(QPainter::CompositionMode_Source); //copy alpha straight in |
|
2161 #endif |
|
2162 fillRegion(painter, rgn, bg); |
|
2163 } |
|
2164 |
|
2165 if (q->autoFillBackground()) |
|
2166 fillRegion(painter, rgn, autoFillBrush); |
|
2167 |
|
2168 if (q->testAttribute(Qt::WA_StyledBackground)) { |
|
2169 painter->setClipRegion(rgn); |
|
2170 QStyleOption opt; |
|
2171 opt.initFrom(q); |
|
2172 q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q); |
|
2173 } |
|
2174 |
|
2175 #ifndef QT_NO_SCROLLAREA |
|
2176 if (resetBrushOrigin) |
|
2177 painter->setBrushOrigin(oldBrushOrigin); |
|
2178 #endif // QT_NO_SCROLLAREA |
|
2179 } |
|
2180 |
|
2181 /* |
|
2182 \internal |
|
2183 This function is called when a widget is hidden or destroyed. |
|
2184 It resets some application global pointers that should only refer active, |
|
2185 visible widgets. |
|
2186 */ |
|
2187 |
|
2188 #ifdef Q_WS_MAC |
|
2189 extern QPointer<QWidget> qt_button_down; |
|
2190 #else |
|
2191 extern QWidget *qt_button_down; |
|
2192 #endif |
|
2193 |
|
2194 void QWidgetPrivate::deactivateWidgetCleanup() |
|
2195 { |
|
2196 Q_Q(QWidget); |
|
2197 // If this was the active application window, reset it |
|
2198 if (QApplication::activeWindow() == q) |
|
2199 QApplication::setActiveWindow(0); |
|
2200 // If the is the active mouse press widget, reset it |
|
2201 if (q == qt_button_down) |
|
2202 qt_button_down = 0; |
|
2203 } |
|
2204 |
|
2205 |
|
2206 /*! |
|
2207 Returns a pointer to the widget with window identifer/handle \a |
|
2208 id. |
|
2209 |
|
2210 The window identifier type depends on the underlying window |
|
2211 system, see \c qwindowdefs.h for the actual definition. If there |
|
2212 is no widget with this identifier, 0 is returned. |
|
2213 */ |
|
2214 |
|
2215 QWidget *QWidget::find(WId id) |
|
2216 { |
|
2217 return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0; |
|
2218 } |
|
2219 |
|
2220 |
|
2221 |
|
2222 /*! |
|
2223 \fn WId QWidget::internalWinId() const |
|
2224 \internal |
|
2225 Returns the window system identifier of the widget, or 0 if the widget is not created yet. |
|
2226 |
|
2227 */ |
|
2228 |
|
2229 /*! |
|
2230 \fn WId QWidget::winId() const |
|
2231 |
|
2232 Returns the window system identifier of the widget. |
|
2233 |
|
2234 Portable in principle, but if you use it you are probably about to |
|
2235 do something non-portable. Be careful. |
|
2236 |
|
2237 If a widget is non-native (alien) and winId() is invoked on it, that widget |
|
2238 will be provided a native handle. |
|
2239 |
|
2240 On Mac OS X, the type returned depends on which framework Qt was linked |
|
2241 against. If Qt is using Carbon, the {WId} is actually an HIViewRef. If Qt |
|
2242 is using Cocoa, {WId} is a pointer to an NSView. |
|
2243 |
|
2244 This value may change at run-time. An event with type QEvent::WinIdChange |
|
2245 will be sent to the widget following a change in window system identifier. |
|
2246 |
|
2247 \sa find() |
|
2248 */ |
|
2249 WId QWidget::winId() const |
|
2250 { |
|
2251 if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) { |
|
2252 QWidget *that = const_cast<QWidget*>(this); |
|
2253 that->setAttribute(Qt::WA_NativeWindow); |
|
2254 that->d_func()->createWinId(); |
|
2255 return that->data->winid; |
|
2256 } |
|
2257 return data->winid; |
|
2258 } |
|
2259 |
|
2260 |
|
2261 void QWidgetPrivate::createWinId(WId winid) |
|
2262 { |
|
2263 Q_Q(QWidget); |
|
2264 const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow); |
|
2265 if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) { |
|
2266 if (!q->isWindow()) { |
|
2267 QWidget *parent = q->parentWidget(); |
|
2268 QWidgetPrivate *pd = parent->d_func(); |
|
2269 if (forceNativeWindow && !q->testAttribute(Qt::WA_DontCreateNativeAncestors)) |
|
2270 parent->setAttribute(Qt::WA_NativeWindow); |
|
2271 if (!parent->internalWinId()) { |
|
2272 pd->createWinId(); |
|
2273 } |
|
2274 |
|
2275 for (int i = 0; i < pd->children.size(); ++i) { |
|
2276 QWidget *w = qobject_cast<QWidget *>(pd->children.at(i)); |
|
2277 if (w && !w->isWindow() && (!w->testAttribute(Qt::WA_WState_Created) |
|
2278 || (!w->internalWinId() && w->testAttribute(Qt::WA_NativeWindow)))) { |
|
2279 if (w!=q) { |
|
2280 w->create(); |
|
2281 } else { |
|
2282 w->create(winid); |
|
2283 // if the window has already been created, we |
|
2284 // need to raise it to its proper stacking position |
|
2285 if (winid) |
|
2286 w->raise(); |
|
2287 } |
|
2288 } |
|
2289 } |
|
2290 } else { |
|
2291 q->create(); |
|
2292 } |
|
2293 } |
|
2294 } |
|
2295 |
|
2296 |
|
2297 /*! |
|
2298 \internal |
|
2299 Ensures that the widget has a window system identifier, i.e. that it is known to the windowing system. |
|
2300 |
|
2301 */ |
|
2302 |
|
2303 void QWidget::createWinId() |
|
2304 { |
|
2305 Q_D(QWidget); |
|
2306 // qWarning("QWidget::createWinId is obsolete, please fix your code."); |
|
2307 d->createWinId(); |
|
2308 } |
|
2309 |
|
2310 /*! |
|
2311 \since 4.4 |
|
2312 |
|
2313 Returns the effective window system identifier of the widget, i.e. the |
|
2314 native parent's window system identifier. |
|
2315 |
|
2316 If the widget is native, this function returns the native widget ID. |
|
2317 Otherwise, the window ID of the first native parent widget, i.e., the |
|
2318 top-level widget that contains this widget, is returned. |
|
2319 |
|
2320 \note We recommend that you do not store this value as it is likely to |
|
2321 change at run-time. |
|
2322 |
|
2323 \sa nativeParentWidget() |
|
2324 */ |
|
2325 WId QWidget::effectiveWinId() const |
|
2326 { |
|
2327 WId id = internalWinId(); |
|
2328 if (id || !testAttribute(Qt::WA_WState_Created)) |
|
2329 return id; |
|
2330 QWidget *realParent = nativeParentWidget(); |
|
2331 Q_ASSERT(realParent); |
|
2332 Q_ASSERT(realParent->internalWinId()); |
|
2333 return realParent->internalWinId(); |
|
2334 } |
|
2335 |
|
2336 #ifndef QT_NO_STYLE_STYLESHEET |
|
2337 |
|
2338 /*! |
|
2339 \property QWidget::styleSheet |
|
2340 \brief the widget's style sheet |
|
2341 \since 4.2 |
|
2342 |
|
2343 The style sheet contains a textual description of customizations to the |
|
2344 widget's style, as described in the \l{Qt Style Sheets} document. |
|
2345 |
|
2346 Since Qt 4.5, Qt style sheets fully supports Mac OS X. |
|
2347 |
|
2348 \warning Qt style sheets are currently not supported for custom QStyle |
|
2349 subclasses. We plan to address this in some future release. |
|
2350 |
|
2351 \sa setStyle(), QApplication::styleSheet, {Qt Style Sheets} |
|
2352 */ |
|
2353 QString QWidget::styleSheet() const |
|
2354 { |
|
2355 Q_D(const QWidget); |
|
2356 if (!d->extra) |
|
2357 return QString(); |
|
2358 return d->extra->styleSheet; |
|
2359 } |
|
2360 |
|
2361 void QWidget::setStyleSheet(const QString& styleSheet) |
|
2362 { |
|
2363 Q_D(QWidget); |
|
2364 d->createExtra(); |
|
2365 |
|
2366 QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(d->extra->style); |
|
2367 d->extra->styleSheet = styleSheet; |
|
2368 if (styleSheet.isEmpty()) { // stylesheet removed |
|
2369 if (!proxy) |
|
2370 return; |
|
2371 |
|
2372 d->inheritStyle(); |
|
2373 return; |
|
2374 } |
|
2375 |
|
2376 if (proxy) { // style sheet update |
|
2377 proxy->repolish(this); |
|
2378 return; |
|
2379 } |
|
2380 |
|
2381 if (testAttribute(Qt::WA_SetStyle)) { |
|
2382 d->setStyle_helper(new QStyleSheetStyle(d->extra->style), true); |
|
2383 } else { |
|
2384 d->setStyle_helper(new QStyleSheetStyle(0), true); |
|
2385 } |
|
2386 } |
|
2387 |
|
2388 #endif // QT_NO_STYLE_STYLESHEET |
|
2389 |
|
2390 /*! |
|
2391 \sa QWidget::setStyle(), QApplication::setStyle(), QApplication::style() |
|
2392 */ |
|
2393 |
|
2394 QStyle *QWidget::style() const |
|
2395 { |
|
2396 Q_D(const QWidget); |
|
2397 |
|
2398 if (d->extra && d->extra->style) |
|
2399 return d->extra->style; |
|
2400 return QApplication::style(); |
|
2401 } |
|
2402 |
|
2403 /*! |
|
2404 Sets the widget's GUI style to \a style. The ownership of the style |
|
2405 object is not transferred. |
|
2406 |
|
2407 If no style is set, the widget uses the application's style, |
|
2408 QApplication::style() instead. |
|
2409 |
|
2410 Setting a widget's style has no effect on existing or future child |
|
2411 widgets. |
|
2412 |
|
2413 \warning This function is particularly useful for demonstration |
|
2414 purposes, where you want to show Qt's styling capabilities. Real |
|
2415 applications should avoid it and use one consistent GUI style |
|
2416 instead. |
|
2417 |
|
2418 \warning Qt style sheets are currently not supported for custom QStyle |
|
2419 subclasses. We plan to address this in some future release. |
|
2420 |
|
2421 \sa style(), QStyle, QApplication::style(), QApplication::setStyle() |
|
2422 */ |
|
2423 |
|
2424 void QWidget::setStyle(QStyle *style) |
|
2425 { |
|
2426 Q_D(QWidget); |
|
2427 setAttribute(Qt::WA_SetStyle, style != 0); |
|
2428 d->createExtra(); |
|
2429 #ifndef QT_NO_STYLE_STYLESHEET |
|
2430 if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(style)) { |
|
2431 //if for some reason someone try to set a QStyleSheetStyle, ref it |
|
2432 //(this may happen for exemple in QButtonDialogBox which propagates its style) |
|
2433 proxy->ref(); |
|
2434 d->setStyle_helper(style, false); |
|
2435 } else if (qobject_cast<QStyleSheetStyle *>(d->extra->style) || !qApp->styleSheet().isEmpty()) { |
|
2436 // if we have an application stylesheet or have a proxy already, propagate |
|
2437 d->setStyle_helper(new QStyleSheetStyle(style), true); |
|
2438 } else |
|
2439 #endif |
|
2440 d->setStyle_helper(style, false); |
|
2441 } |
|
2442 |
|
2443 void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate, bool |
|
2444 #ifdef Q_WS_MAC |
|
2445 metalHack |
|
2446 #endif |
|
2447 ) |
|
2448 { |
|
2449 Q_Q(QWidget); |
|
2450 QStyle *oldStyle = q->style(); |
|
2451 #ifndef QT_NO_STYLE_STYLESHEET |
|
2452 QStyle *origStyle = 0; |
|
2453 #endif |
|
2454 |
|
2455 #ifdef Q_WS_MAC |
|
2456 // the metalhack boolean allows Qt/Mac to do a proper re-polish depending |
|
2457 // on how the Qt::WA_MacBrushedMetal attribute is set. It is only ever |
|
2458 // set when changing that attribute and passes the widget's CURRENT style. |
|
2459 // therefore no need to do a reassignment. |
|
2460 if (!metalHack) |
|
2461 #endif |
|
2462 { |
|
2463 createExtra(); |
|
2464 |
|
2465 #ifndef QT_NO_STYLE_STYLESHEET |
|
2466 origStyle = extra->style; |
|
2467 #endif |
|
2468 extra->style = newStyle; |
|
2469 } |
|
2470 |
|
2471 // repolish |
|
2472 if (q->windowType() != Qt::Desktop) { |
|
2473 if (polished) { |
|
2474 oldStyle->unpolish(q); |
|
2475 #ifdef Q_WS_MAC |
|
2476 if (metalHack) |
|
2477 macUpdateMetalAttribute(); |
|
2478 #endif |
|
2479 q->style()->polish(q); |
|
2480 #ifdef Q_WS_MAC |
|
2481 } else if (metalHack) { |
|
2482 macUpdateMetalAttribute(); |
|
2483 #endif |
|
2484 } |
|
2485 } |
|
2486 |
|
2487 if (propagate) { |
|
2488 for (int i = 0; i < children.size(); ++i) { |
|
2489 QWidget *c = qobject_cast<QWidget*>(children.at(i)); |
|
2490 if (c) |
|
2491 c->d_func()->inheritStyle(); |
|
2492 } |
|
2493 } |
|
2494 |
|
2495 QEvent e(QEvent::StyleChange); |
|
2496 QApplication::sendEvent(q, &e); |
|
2497 #ifdef QT3_SUPPORT |
|
2498 q->styleChange(*oldStyle); |
|
2499 #endif |
|
2500 |
|
2501 #ifndef QT_NO_STYLE_STYLESHEET |
|
2502 if (!qobject_cast<QStyleSheetStyle*>(newStyle)) { |
|
2503 if (const QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(origStyle)) { |
|
2504 cssStyle->clearWidgetFont(q); |
|
2505 } |
|
2506 } |
|
2507 #endif |
|
2508 |
|
2509 #ifndef QT_NO_STYLE_STYLESHEET |
|
2510 // dereference the old stylesheet style |
|
2511 if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(origStyle)) |
|
2512 proxy->deref(); |
|
2513 #endif |
|
2514 } |
|
2515 |
|
2516 // Inherits style from the current parent and propagates it as necessary |
|
2517 void QWidgetPrivate::inheritStyle() |
|
2518 { |
|
2519 #ifndef QT_NO_STYLE_STYLESHEET |
|
2520 Q_Q(QWidget); |
|
2521 |
|
2522 QStyleSheetStyle *proxy = extra ? qobject_cast<QStyleSheetStyle *>(extra->style) : 0; |
|
2523 |
|
2524 if (!q->styleSheet().isEmpty()) { |
|
2525 Q_ASSERT(proxy); |
|
2526 proxy->repolish(q); |
|
2527 return; |
|
2528 } |
|
2529 |
|
2530 QStyle *origStyle = proxy ? proxy->base : (extra ? (QStyle*)extra->style : 0); |
|
2531 QWidget *parent = q->parentWidget(); |
|
2532 QStyle *parentStyle = (parent && parent->d_func()->extra) ? (QStyle*)parent->d_func()->extra->style : 0; |
|
2533 // If we have stylesheet on app or parent has stylesheet style, we need |
|
2534 // to be running a proxy |
|
2535 if (!qApp->styleSheet().isEmpty() || qobject_cast<QStyleSheetStyle *>(parentStyle)) { |
|
2536 QStyle *newStyle = parentStyle; |
|
2537 if (q->testAttribute(Qt::WA_SetStyle)) |
|
2538 newStyle = new QStyleSheetStyle(origStyle); |
|
2539 else if (QStyleSheetStyle *newProxy = qobject_cast<QStyleSheetStyle *>(parentStyle)) |
|
2540 newProxy->ref(); |
|
2541 |
|
2542 setStyle_helper(newStyle, true); |
|
2543 return; |
|
2544 } |
|
2545 |
|
2546 // So, we have no stylesheet on parent/app and we have an empty stylesheet |
|
2547 // we just need our original style back |
|
2548 if (origStyle == (extra ? (QStyle*)extra->style : 0)) // is it any different? |
|
2549 return; |
|
2550 |
|
2551 // We could have inherited the proxy from our parent (which has a custom style) |
|
2552 // In such a case we need to start following the application style (i.e revert |
|
2553 // the propagation behavior of QStyleSheetStyle) |
|
2554 if (!q->testAttribute(Qt::WA_SetStyle)) |
|
2555 origStyle = 0; |
|
2556 |
|
2557 setStyle_helper(origStyle, true); |
|
2558 #endif // QT_NO_STYLE_STYLESHEET |
|
2559 } |
|
2560 |
|
2561 #ifdef QT3_SUPPORT |
|
2562 /*! |
|
2563 \overload |
|
2564 |
|
2565 Sets the widget's GUI style to \a style using the QStyleFactory. |
|
2566 */ |
|
2567 QStyle* QWidget::setStyle(const QString &style) |
|
2568 { |
|
2569 QStyle *s = QStyleFactory::create(style); |
|
2570 setStyle(s); |
|
2571 return s; |
|
2572 } |
|
2573 #endif |
|
2574 |
|
2575 /*! |
|
2576 \fn bool QWidget::isWindow() const |
|
2577 |
|
2578 Returns true if the widget is an independent window, otherwise |
|
2579 returns false. |
|
2580 |
|
2581 A window is a widget that isn't visually the child of any other |
|
2582 widget and that usually has a frame and a |
|
2583 \l{QWidget::setWindowTitle()}{window title}. |
|
2584 |
|
2585 A window can have a \l{QWidget::parentWidget()}{parent widget}. |
|
2586 It will then be grouped with its parent and deleted when the |
|
2587 parent is deleted, minimized when the parent is minimized etc. If |
|
2588 supported by the window manager, it will also have a common |
|
2589 taskbar entry with its parent. |
|
2590 |
|
2591 QDialog and QMainWindow widgets are by default windows, even if a |
|
2592 parent widget is specified in the constructor. This behavior is |
|
2593 specified by the Qt::Window flag. |
|
2594 |
|
2595 \sa window(), isModal(), parentWidget() |
|
2596 */ |
|
2597 |
|
2598 /*! |
|
2599 \property QWidget::modal |
|
2600 \brief whether the widget is a modal widget |
|
2601 |
|
2602 This property only makes sense for windows. A modal widget |
|
2603 prevents widgets in all other windows from getting any input. |
|
2604 |
|
2605 By default, this property is false. |
|
2606 |
|
2607 \sa isWindow(), windowModality, QDialog |
|
2608 */ |
|
2609 |
|
2610 /*! |
|
2611 \property QWidget::windowModality |
|
2612 \brief which windows are blocked by the modal widget |
|
2613 \since 4.1 |
|
2614 |
|
2615 This property only makes sense for windows. A modal widget |
|
2616 prevents widgets in other windows from getting input. The value of |
|
2617 this property controls which windows are blocked when the widget |
|
2618 is visible. Changing this property while the window is visible has |
|
2619 no effect; you must hide() the widget first, then show() it again. |
|
2620 |
|
2621 By default, this property is Qt::NonModal. |
|
2622 |
|
2623 \sa isWindow(), QWidget::modal, QDialog |
|
2624 */ |
|
2625 |
|
2626 Qt::WindowModality QWidget::windowModality() const |
|
2627 { |
|
2628 return static_cast<Qt::WindowModality>(data->window_modality); |
|
2629 } |
|
2630 |
|
2631 void QWidget::setWindowModality(Qt::WindowModality windowModality) |
|
2632 { |
|
2633 data->window_modality = windowModality; |
|
2634 // setModal_sys() will be called by setAttribute() |
|
2635 setAttribute(Qt::WA_ShowModal, (data->window_modality != Qt::NonModal)); |
|
2636 setAttribute(Qt::WA_SetWindowModality, true); |
|
2637 } |
|
2638 |
|
2639 /*! |
|
2640 \fn bool QWidget::underMouse() const |
|
2641 |
|
2642 Returns true if the widget is under the mouse cursor; otherwise |
|
2643 returns false. |
|
2644 |
|
2645 This value is not updated properly during drag and drop |
|
2646 operations. |
|
2647 |
|
2648 \sa enterEvent(), leaveEvent() |
|
2649 */ |
|
2650 |
|
2651 /*! |
|
2652 \property QWidget::minimized |
|
2653 \brief whether this widget is minimized (iconified) |
|
2654 |
|
2655 This property is only relevant for windows. |
|
2656 |
|
2657 By default, this property is false. |
|
2658 |
|
2659 \sa showMinimized(), visible, show(), hide(), showNormal(), maximized |
|
2660 */ |
|
2661 bool QWidget::isMinimized() const |
|
2662 { return data->window_state & Qt::WindowMinimized; } |
|
2663 |
|
2664 /*! |
|
2665 Shows the widget minimized, as an icon. |
|
2666 |
|
2667 Calling this function only affects \l{isWindow()}{windows}. |
|
2668 |
|
2669 \sa showNormal(), showMaximized(), show(), hide(), isVisible(), |
|
2670 isMinimized() |
|
2671 */ |
|
2672 void QWidget::showMinimized() |
|
2673 { |
|
2674 bool isMin = isMinimized(); |
|
2675 if (isMin && isVisible()) |
|
2676 return; |
|
2677 |
|
2678 ensurePolished(); |
|
2679 #ifdef QT3_SUPPORT |
|
2680 if (parent()) |
|
2681 QApplication::sendPostedEvents(parent(), QEvent::ChildInserted); |
|
2682 #endif |
|
2683 |
|
2684 if (!isMin) |
|
2685 setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized); |
|
2686 show(); |
|
2687 } |
|
2688 |
|
2689 /*! |
|
2690 \property QWidget::maximized |
|
2691 \brief whether this widget is maximized |
|
2692 |
|
2693 This property is only relevant for windows. |
|
2694 |
|
2695 \note Due to limitations on some window systems, this does not always |
|
2696 report the expected results (e.g., if the user on X11 maximizes the |
|
2697 window via the window manager, Qt has no way of distinguishing this |
|
2698 from any other resize). This is expected to improve as window manager |
|
2699 protocols evolve. |
|
2700 |
|
2701 By default, this property is false. |
|
2702 |
|
2703 \sa windowState(), showMaximized(), visible, show(), hide(), showNormal(), minimized |
|
2704 */ |
|
2705 bool QWidget::isMaximized() const |
|
2706 { return data->window_state & Qt::WindowMaximized; } |
|
2707 |
|
2708 |
|
2709 |
|
2710 /*! |
|
2711 Returns the current window state. The window state is a OR'ed |
|
2712 combination of Qt::WindowState: Qt::WindowMinimized, |
|
2713 Qt::WindowMaximized, Qt::WindowFullScreen, and Qt::WindowActive. |
|
2714 |
|
2715 \sa Qt::WindowState setWindowState() |
|
2716 */ |
|
2717 Qt::WindowStates QWidget::windowState() const |
|
2718 { |
|
2719 return Qt::WindowStates(data->window_state); |
|
2720 } |
|
2721 |
|
2722 /*!\internal |
|
2723 |
|
2724 The function sets the window state on child widgets similar to |
|
2725 setWindowState(). The difference is that the window state changed |
|
2726 event has the isOverride() flag set. It exists mainly to keep |
|
2727 Q3Workspace working. |
|
2728 */ |
|
2729 void QWidget::overrideWindowState(Qt::WindowStates newstate) |
|
2730 { |
|
2731 QWindowStateChangeEvent e(Qt::WindowStates(data->window_state), true); |
|
2732 data->window_state = newstate; |
|
2733 QApplication::sendEvent(this, &e); |
|
2734 } |
|
2735 |
|
2736 /*! |
|
2737 \fn void QWidget::setWindowState(Qt::WindowStates windowState) |
|
2738 |
|
2739 Sets the window state to \a windowState. The window state is a OR'ed |
|
2740 combination of Qt::WindowState: Qt::WindowMinimized, |
|
2741 Qt::WindowMaximized, Qt::WindowFullScreen, and Qt::WindowActive. |
|
2742 |
|
2743 If the window is not visible (i.e. isVisible() returns false), the |
|
2744 window state will take effect when show() is called. For visible |
|
2745 windows, the change is immediate. For example, to toggle between |
|
2746 full-screen and normal mode, use the following code: |
|
2747 |
|
2748 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 0 |
|
2749 |
|
2750 In order to restore and activate a minimized window (while |
|
2751 preserving its maximized and/or full-screen state), use the following: |
|
2752 |
|
2753 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 1 |
|
2754 |
|
2755 Calling this function will hide the widget. You must call show() to make |
|
2756 the widget visible again. |
|
2757 |
|
2758 \note On some window systems Qt::WindowActive is not immediate, and may be |
|
2759 ignored in certain cases. |
|
2760 |
|
2761 When the window state changes, the widget receives a changeEvent() |
|
2762 of type QEvent::WindowStateChange. |
|
2763 |
|
2764 \sa Qt::WindowState windowState() |
|
2765 */ |
|
2766 |
|
2767 /*! |
|
2768 \property QWidget::fullScreen |
|
2769 \brief whether the widget is shown in full screen mode |
|
2770 |
|
2771 A widget in full screen mode occupies the whole screen area and does not |
|
2772 display window decorations, such as a title bar. |
|
2773 |
|
2774 By default, this property is false. |
|
2775 |
|
2776 \sa windowState(), minimized, maximized |
|
2777 */ |
|
2778 bool QWidget::isFullScreen() const |
|
2779 { return data->window_state & Qt::WindowFullScreen; } |
|
2780 |
|
2781 /*! |
|
2782 Shows the widget in full-screen mode. |
|
2783 |
|
2784 Calling this function only affects \l{isWindow()}{windows}. |
|
2785 |
|
2786 To return from full-screen mode, call showNormal(). |
|
2787 |
|
2788 Full-screen mode works fine under Windows, but has certain |
|
2789 problems under X. These problems are due to limitations of the |
|
2790 ICCCM protocol that specifies the communication between X11 |
|
2791 clients and the window manager. ICCCM simply does not understand |
|
2792 the concept of non-decorated full-screen windows. Therefore, the |
|
2793 best we can do is to request a borderless window and place and |
|
2794 resize it to fill the entire screen. Depending on the window |
|
2795 manager, this may or may not work. The borderless window is |
|
2796 requested using MOTIF hints, which are at least partially |
|
2797 supported by virtually all modern window managers. |
|
2798 |
|
2799 An alternative would be to bypass the window manager entirely and |
|
2800 create a window with the Qt::X11BypassWindowManagerHint flag. This |
|
2801 has other severe problems though, like totally broken keyboard focus |
|
2802 and very strange effects on desktop changes or when the user raises |
|
2803 other windows. |
|
2804 |
|
2805 X11 window managers that follow modern post-ICCCM specifications |
|
2806 support full-screen mode properly. |
|
2807 |
|
2808 \sa showNormal(), showMaximized(), show(), hide(), isVisible() |
|
2809 */ |
|
2810 void QWidget::showFullScreen() |
|
2811 { |
|
2812 ensurePolished(); |
|
2813 #ifdef QT3_SUPPORT |
|
2814 if (parent()) |
|
2815 QApplication::sendPostedEvents(parent(), QEvent::ChildInserted); |
|
2816 #endif |
|
2817 |
|
2818 setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowMaximized)) |
|
2819 | Qt::WindowFullScreen); |
|
2820 show(); |
|
2821 activateWindow(); |
|
2822 } |
|
2823 |
|
2824 /*! |
|
2825 Shows the widget maximized. |
|
2826 |
|
2827 Calling this function only affects \l{isWindow()}{windows}. |
|
2828 |
|
2829 On X11, this function may not work properly with certain window |
|
2830 managers. See the \l{Window Geometry} documentation for an explanation. |
|
2831 |
|
2832 \sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible() |
|
2833 */ |
|
2834 void QWidget::showMaximized() |
|
2835 { |
|
2836 ensurePolished(); |
|
2837 #ifdef QT3_SUPPORT |
|
2838 if (parent()) |
|
2839 QApplication::sendPostedEvents(parent(), QEvent::ChildInserted); |
|
2840 #endif |
|
2841 |
|
2842 setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen)) |
|
2843 | Qt::WindowMaximized); |
|
2844 show(); |
|
2845 } |
|
2846 |
|
2847 /*! |
|
2848 Restores the widget after it has been maximized or minimized. |
|
2849 |
|
2850 Calling this function only affects \l{isWindow()}{windows}. |
|
2851 |
|
2852 \sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible() |
|
2853 */ |
|
2854 void QWidget::showNormal() |
|
2855 { |
|
2856 ensurePolished(); |
|
2857 #ifdef QT3_SUPPORT |
|
2858 if (parent()) |
|
2859 QApplication::sendPostedEvents(parent(), QEvent::ChildInserted); |
|
2860 #endif |
|
2861 |
|
2862 setWindowState(windowState() & ~(Qt::WindowMinimized |
|
2863 | Qt::WindowMaximized |
|
2864 | Qt::WindowFullScreen)); |
|
2865 show(); |
|
2866 } |
|
2867 |
|
2868 /*! |
|
2869 Returns true if this widget would become enabled if \a ancestor is |
|
2870 enabled; otherwise returns false. |
|
2871 |
|
2872 |
|
2873 |
|
2874 This is the case if neither the widget itself nor every parent up |
|
2875 to but excluding \a ancestor has been explicitly disabled. |
|
2876 |
|
2877 isEnabledTo(0) is equivalent to isEnabled(). |
|
2878 |
|
2879 \sa setEnabled() enabled |
|
2880 */ |
|
2881 |
|
2882 bool QWidget::isEnabledTo(QWidget* ancestor) const |
|
2883 { |
|
2884 const QWidget * w = this; |
|
2885 while (!w->testAttribute(Qt::WA_ForceDisabled) |
|
2886 && !w->isWindow() |
|
2887 && w->parentWidget() |
|
2888 && w->parentWidget() != ancestor) |
|
2889 w = w->parentWidget(); |
|
2890 return !w->testAttribute(Qt::WA_ForceDisabled); |
|
2891 } |
|
2892 |
|
2893 #ifndef QT_NO_ACTION |
|
2894 /*! |
|
2895 Appends the action \a action to this widget's list of actions. |
|
2896 |
|
2897 All QWidgets have a list of \l{QAction}s, however they can be |
|
2898 represented graphically in many different ways. The default use of |
|
2899 the QAction list (as returned by actions()) is to create a context |
|
2900 QMenu. |
|
2901 |
|
2902 A QWidget should only have one of each action and adding an action |
|
2903 it already has will not cause the same action to be in the widget twice. |
|
2904 |
|
2905 The ownership of \a action is not transferred to this QWidget. |
|
2906 |
|
2907 \sa removeAction(), insertAction(), actions(), QMenu |
|
2908 */ |
|
2909 void QWidget::addAction(QAction *action) |
|
2910 { |
|
2911 insertAction(0, action); |
|
2912 } |
|
2913 |
|
2914 /*! |
|
2915 Appends the actions \a actions to this widget's list of actions. |
|
2916 |
|
2917 \sa removeAction(), QMenu, addAction() |
|
2918 */ |
|
2919 void QWidget::addActions(QList<QAction*> actions) |
|
2920 { |
|
2921 for(int i = 0; i < actions.count(); i++) |
|
2922 insertAction(0, actions.at(i)); |
|
2923 } |
|
2924 |
|
2925 /*! |
|
2926 Inserts the action \a action to this widget's list of actions, |
|
2927 before the action \a before. It appends the action if \a before is 0 or |
|
2928 \a before is not a valid action for this widget. |
|
2929 |
|
2930 A QWidget should only have one of each action. |
|
2931 |
|
2932 \sa removeAction(), addAction(), QMenu, contextMenuPolicy, actions() |
|
2933 */ |
|
2934 void QWidget::insertAction(QAction *before, QAction *action) |
|
2935 { |
|
2936 if(!action) { |
|
2937 qWarning("QWidget::insertAction: Attempt to insert null action"); |
|
2938 return; |
|
2939 } |
|
2940 |
|
2941 Q_D(QWidget); |
|
2942 if(d->actions.contains(action)) |
|
2943 removeAction(action); |
|
2944 |
|
2945 int pos = d->actions.indexOf(before); |
|
2946 if (pos < 0) { |
|
2947 before = 0; |
|
2948 pos = d->actions.size(); |
|
2949 } |
|
2950 d->actions.insert(pos, action); |
|
2951 |
|
2952 QActionPrivate *apriv = action->d_func(); |
|
2953 apriv->widgets.append(this); |
|
2954 |
|
2955 QActionEvent e(QEvent::ActionAdded, action, before); |
|
2956 QApplication::sendEvent(this, &e); |
|
2957 } |
|
2958 |
|
2959 /*! |
|
2960 Inserts the actions \a actions to this widget's list of actions, |
|
2961 before the action \a before. It appends the action if \a before is 0 or |
|
2962 \a before is not a valid action for this widget. |
|
2963 |
|
2964 A QWidget can have at most one of each action. |
|
2965 |
|
2966 \sa removeAction(), QMenu, insertAction(), contextMenuPolicy |
|
2967 */ |
|
2968 void QWidget::insertActions(QAction *before, QList<QAction*> actions) |
|
2969 { |
|
2970 for(int i = 0; i < actions.count(); ++i) |
|
2971 insertAction(before, actions.at(i)); |
|
2972 } |
|
2973 |
|
2974 /*! |
|
2975 Removes the action \a action from this widget's list of actions. |
|
2976 \sa insertAction(), actions(), insertAction() |
|
2977 */ |
|
2978 void QWidget::removeAction(QAction *action) |
|
2979 { |
|
2980 if (!action) |
|
2981 return; |
|
2982 |
|
2983 Q_D(QWidget); |
|
2984 |
|
2985 QActionPrivate *apriv = action->d_func(); |
|
2986 apriv->widgets.removeAll(this); |
|
2987 |
|
2988 if (d->actions.removeAll(action)) { |
|
2989 QActionEvent e(QEvent::ActionRemoved, action); |
|
2990 QApplication::sendEvent(this, &e); |
|
2991 } |
|
2992 } |
|
2993 |
|
2994 /*! |
|
2995 Returns the (possibly empty) list of this widget's actions. |
|
2996 |
|
2997 \sa contextMenuPolicy, insertAction(), removeAction() |
|
2998 */ |
|
2999 QList<QAction*> QWidget::actions() const |
|
3000 { |
|
3001 Q_D(const QWidget); |
|
3002 return d->actions; |
|
3003 } |
|
3004 #endif // QT_NO_ACTION |
|
3005 |
|
3006 /*! |
|
3007 \fn bool QWidget::isEnabledToTLW() const |
|
3008 \obsolete |
|
3009 |
|
3010 This function is deprecated. It is equivalent to isEnabled() |
|
3011 */ |
|
3012 |
|
3013 /*! |
|
3014 \property QWidget::enabled |
|
3015 \brief whether the widget is enabled |
|
3016 |
|
3017 An enabled widget handles keyboard and mouse events; a disabled |
|
3018 widget does not. |
|
3019 |
|
3020 Some widgets display themselves differently when they are |
|
3021 disabled. For example a button might draw its label grayed out. If |
|
3022 your widget needs to know when it becomes enabled or disabled, you |
|
3023 can use the changeEvent() with type QEvent::EnabledChange. |
|
3024 |
|
3025 Disabling a widget implicitly disables all its children. Enabling |
|
3026 respectively enables all child widgets unless they have been |
|
3027 explicitly disabled. |
|
3028 |
|
3029 By default, this property is true. |
|
3030 |
|
3031 \sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent() |
|
3032 */ |
|
3033 void QWidget::setEnabled(bool enable) |
|
3034 { |
|
3035 Q_D(QWidget); |
|
3036 setAttribute(Qt::WA_ForceDisabled, !enable); |
|
3037 d->setEnabled_helper(enable); |
|
3038 } |
|
3039 |
|
3040 void QWidgetPrivate::setEnabled_helper(bool enable) |
|
3041 { |
|
3042 Q_Q(QWidget); |
|
3043 |
|
3044 if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->isEnabled()) |
|
3045 return; // nothing we can do |
|
3046 |
|
3047 if (enable != q->testAttribute(Qt::WA_Disabled)) |
|
3048 return; // nothing to do |
|
3049 |
|
3050 q->setAttribute(Qt::WA_Disabled, !enable); |
|
3051 updateSystemBackground(); |
|
3052 |
|
3053 if (!enable && q->window()->focusWidget() == q) { |
|
3054 bool parentIsEnabled = (!q->parentWidget() || q->parentWidget()->isEnabled()); |
|
3055 if (!parentIsEnabled || !q->focusNextChild()) |
|
3056 q->clearFocus(); |
|
3057 } |
|
3058 |
|
3059 Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceDisabled : Qt::WA_Disabled; |
|
3060 for (int i = 0; i < children.size(); ++i) { |
|
3061 QWidget *w = qobject_cast<QWidget *>(children.at(i)); |
|
3062 if (w && !w->testAttribute(attribute)) |
|
3063 w->d_func()->setEnabled_helper(enable); |
|
3064 } |
|
3065 #if defined(Q_WS_X11) |
|
3066 if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) { |
|
3067 // enforce the windows behavior of clearing the cursor on |
|
3068 // disabled widgets |
|
3069 qt_x11_enforce_cursor(q); |
|
3070 } |
|
3071 #endif |
|
3072 #if defined(Q_WS_MAC) |
|
3073 setEnabled_helper_sys(enable); |
|
3074 #endif |
|
3075 if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) { |
|
3076 QInputContext *qic = inputContext(); |
|
3077 if (enable) { |
|
3078 qic->setFocusWidget(q); |
|
3079 } else { |
|
3080 qic->reset(); |
|
3081 qic->setFocusWidget(0); |
|
3082 } |
|
3083 } |
|
3084 QEvent e(QEvent::EnabledChange); |
|
3085 QApplication::sendEvent(q, &e); |
|
3086 #ifdef QT3_SUPPORT |
|
3087 q->enabledChange(!enable); // compatibility |
|
3088 #endif |
|
3089 } |
|
3090 |
|
3091 /*! |
|
3092 \property QWidget::acceptDrops |
|
3093 \brief whether drop events are enabled for this widget |
|
3094 |
|
3095 Setting this property to true announces to the system that this |
|
3096 widget \e may be able to accept drop events. |
|
3097 |
|
3098 If the widget is the desktop (windowType() == Qt::Desktop), this may |
|
3099 fail if another application is using the desktop; you can call |
|
3100 acceptDrops() to test if this occurs. |
|
3101 |
|
3102 \warning Do not modify this property in a drag and drop event handler. |
|
3103 |
|
3104 By default, this property is false. |
|
3105 |
|
3106 \sa {Drag and Drop} |
|
3107 */ |
|
3108 bool QWidget::acceptDrops() const |
|
3109 { |
|
3110 return testAttribute(Qt::WA_AcceptDrops); |
|
3111 } |
|
3112 |
|
3113 void QWidget::setAcceptDrops(bool on) |
|
3114 { |
|
3115 setAttribute(Qt::WA_AcceptDrops, on); |
|
3116 |
|
3117 } |
|
3118 |
|
3119 /*! |
|
3120 \fn void QWidget::enabledChange(bool) |
|
3121 |
|
3122 \internal |
|
3123 \obsolete |
|
3124 */ |
|
3125 |
|
3126 /*! |
|
3127 \fn void QWidget::paletteChange(const QPalette &) |
|
3128 |
|
3129 \internal |
|
3130 \obsolete |
|
3131 */ |
|
3132 |
|
3133 /*! |
|
3134 \fn void QWidget::fontChange(const QFont &) |
|
3135 |
|
3136 \internal |
|
3137 \obsolete |
|
3138 */ |
|
3139 |
|
3140 /*! |
|
3141 \fn void QWidget::windowActivationChange(bool) |
|
3142 |
|
3143 \internal |
|
3144 \obsolete |
|
3145 */ |
|
3146 |
|
3147 /*! |
|
3148 \fn void QWidget::languageChange() |
|
3149 |
|
3150 \obsolete |
|
3151 */ |
|
3152 |
|
3153 /*! |
|
3154 \fn void QWidget::styleChange(QStyle& style) |
|
3155 |
|
3156 \internal |
|
3157 \obsolete |
|
3158 */ |
|
3159 |
|
3160 /*! |
|
3161 Disables widget input events if \a disable is true; otherwise |
|
3162 enables input events. |
|
3163 |
|
3164 See the \l enabled documentation for more information. |
|
3165 |
|
3166 \sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent() |
|
3167 */ |
|
3168 void QWidget::setDisabled(bool disable) |
|
3169 { |
|
3170 setEnabled(!disable); |
|
3171 } |
|
3172 |
|
3173 /*! |
|
3174 \property QWidget::frameGeometry |
|
3175 \brief geometry of the widget relative to its parent including any |
|
3176 window frame |
|
3177 |
|
3178 See the \l{Window Geometry} documentation for an overview of geometry |
|
3179 issues with windows. |
|
3180 |
|
3181 By default, this property contains a value that depends on the user's |
|
3182 platform and screen geometry. |
|
3183 |
|
3184 \sa geometry() x() y() pos() |
|
3185 */ |
|
3186 QRect QWidget::frameGeometry() const |
|
3187 { |
|
3188 Q_D(const QWidget); |
|
3189 if (isWindow() && ! (windowType() == Qt::Popup)) { |
|
3190 QRect fs = d->frameStrut(); |
|
3191 return QRect(data->crect.x() - fs.left(), |
|
3192 data->crect.y() - fs.top(), |
|
3193 data->crect.width() + fs.left() + fs.right(), |
|
3194 data->crect.height() + fs.top() + fs.bottom()); |
|
3195 } |
|
3196 return data->crect; |
|
3197 } |
|
3198 |
|
3199 /*! |
|
3200 \property QWidget::x |
|
3201 |
|
3202 \brief the x coordinate of the widget relative to its parent including |
|
3203 any window frame |
|
3204 |
|
3205 See the \l{Window Geometry} documentation for an overview of geometry |
|
3206 issues with windows. |
|
3207 |
|
3208 By default, this property has a value of 0. |
|
3209 |
|
3210 \sa frameGeometry, y, pos |
|
3211 */ |
|
3212 int QWidget::x() const |
|
3213 { |
|
3214 Q_D(const QWidget); |
|
3215 if (isWindow() && ! (windowType() == Qt::Popup)) |
|
3216 return data->crect.x() - d->frameStrut().left(); |
|
3217 return data->crect.x(); |
|
3218 } |
|
3219 |
|
3220 /*! |
|
3221 \property QWidget::y |
|
3222 \brief the y coordinate of the widget relative to its parent and |
|
3223 including any window frame |
|
3224 |
|
3225 See the \l{Window Geometry} documentation for an overview of geometry |
|
3226 issues with windows. |
|
3227 |
|
3228 By default, this property has a value of 0. |
|
3229 |
|
3230 \sa frameGeometry, x, pos |
|
3231 */ |
|
3232 int QWidget::y() const |
|
3233 { |
|
3234 Q_D(const QWidget); |
|
3235 if (isWindow() && ! (windowType() == Qt::Popup)) |
|
3236 return data->crect.y() - d->frameStrut().top(); |
|
3237 return data->crect.y(); |
|
3238 } |
|
3239 |
|
3240 /*! |
|
3241 \property QWidget::pos |
|
3242 \brief the position of the widget within its parent widget |
|
3243 |
|
3244 If the widget is a window, the position is that of the widget on |
|
3245 the desktop, including its frame. |
|
3246 |
|
3247 When changing the position, the widget, if visible, receives a |
|
3248 move event (moveEvent()) immediately. If the widget is not |
|
3249 currently visible, it is guaranteed to receive an event before it |
|
3250 is shown. |
|
3251 |
|
3252 By default, this property contains a position that refers to the |
|
3253 origin. |
|
3254 |
|
3255 \warning Calling move() or setGeometry() inside moveEvent() can |
|
3256 lead to infinite recursion. |
|
3257 |
|
3258 See the \l{Window Geometry} documentation for an overview of geometry |
|
3259 issues with windows. |
|
3260 |
|
3261 \sa frameGeometry, size x(), y() |
|
3262 */ |
|
3263 QPoint QWidget::pos() const |
|
3264 { |
|
3265 Q_D(const QWidget); |
|
3266 if (isWindow() && ! (windowType() == Qt::Popup)) { |
|
3267 QRect fs = d->frameStrut(); |
|
3268 return QPoint(data->crect.x() - fs.left(), data->crect.y() - fs.top()); |
|
3269 } |
|
3270 return data->crect.topLeft(); |
|
3271 } |
|
3272 |
|
3273 /*! |
|
3274 \property QWidget::geometry |
|
3275 \brief the geometry of the widget relative to its parent and |
|
3276 excluding the window frame |
|
3277 |
|
3278 When changing the geometry, the widget, if visible, receives a |
|
3279 move event (moveEvent()) and/or a resize event (resizeEvent()) |
|
3280 immediately. If the widget is not currently visible, it is |
|
3281 guaranteed to receive appropriate events before it is shown. |
|
3282 |
|
3283 The size component is adjusted if it lies outside the range |
|
3284 defined by minimumSize() and maximumSize(). |
|
3285 |
|
3286 \warning Calling setGeometry() inside resizeEvent() or moveEvent() |
|
3287 can lead to infinite recursion. |
|
3288 |
|
3289 See the \l{Window Geometry} documentation for an overview of geometry |
|
3290 issues with windows. |
|
3291 |
|
3292 By default, this property contains a value that depends on the user's |
|
3293 platform and screen geometry. |
|
3294 |
|
3295 \sa frameGeometry(), rect(), move(), resize(), moveEvent(), |
|
3296 resizeEvent(), minimumSize(), maximumSize() |
|
3297 */ |
|
3298 |
|
3299 /*! |
|
3300 \property QWidget::normalGeometry |
|
3301 |
|
3302 \brief the geometry of the widget as it will appear when shown as |
|
3303 a normal (not maximized or full screen) top-level widget |
|
3304 |
|
3305 For child widgets this property always holds an empty rectangle. |
|
3306 |
|
3307 By default, this property contains an empty rectangle. |
|
3308 |
|
3309 \sa QWidget::windowState(), QWidget::geometry |
|
3310 */ |
|
3311 |
|
3312 /*! |
|
3313 \property QWidget::size |
|
3314 \brief the size of the widget excluding any window frame |
|
3315 |
|
3316 If the widget is visible when it is being resized, it receives a resize event |
|
3317 (resizeEvent()) immediately. If the widget is not currently |
|
3318 visible, it is guaranteed to receive an event before it is shown. |
|
3319 |
|
3320 The size is adjusted if it lies outside the range defined by |
|
3321 minimumSize() and maximumSize(). |
|
3322 |
|
3323 By default, this property contains a value that depends on the user's |
|
3324 platform and screen geometry. |
|
3325 |
|
3326 \warning Calling resize() or setGeometry() inside resizeEvent() can |
|
3327 lead to infinite recursion. |
|
3328 |
|
3329 \note Setting the size to \c{QSize(0, 0)} will cause the widget to not |
|
3330 appear on screen. This also applies to windows. |
|
3331 |
|
3332 \sa pos, geometry, minimumSize, maximumSize, resizeEvent() |
|
3333 */ |
|
3334 |
|
3335 /*! |
|
3336 \property QWidget::width |
|
3337 \brief the width of the widget excluding any window frame |
|
3338 |
|
3339 See the \l{Window Geometry} documentation for an overview of geometry |
|
3340 issues with windows. |
|
3341 |
|
3342 \note Do not use this function to find the width of a screen on |
|
3343 a \l{QDesktopWidget}{multiple screen desktop}. Read |
|
3344 \l{QDesktopWidget#Screen Geometry}{this note} for details. |
|
3345 |
|
3346 By default, this property contains a value that depends on the user's |
|
3347 platform and screen geometry. |
|
3348 |
|
3349 \sa geometry, height, size |
|
3350 */ |
|
3351 |
|
3352 /*! |
|
3353 \property QWidget::height |
|
3354 \brief the height of the widget excluding any window frame |
|
3355 |
|
3356 See the \l{Window Geometry} documentation for an overview of geometry |
|
3357 issues with windows. |
|
3358 |
|
3359 \note Do not use this function to find the height of a screen |
|
3360 on a \l{QDesktopWidget}{multiple screen desktop}. Read |
|
3361 \l{QDesktopWidget#Screen Geometry}{this note} for details. |
|
3362 |
|
3363 By default, this property contains a value that depends on the user's |
|
3364 platform and screen geometry. |
|
3365 |
|
3366 \sa geometry, width, size |
|
3367 */ |
|
3368 |
|
3369 /*! |
|
3370 \property QWidget::rect |
|
3371 \brief the internal geometry of the widget excluding any window |
|
3372 frame |
|
3373 |
|
3374 The rect property equals QRect(0, 0, width(), height()). |
|
3375 |
|
3376 See the \l{Window Geometry} documentation for an overview of geometry |
|
3377 issues with windows. |
|
3378 |
|
3379 By default, this property contains a value that depends on the user's |
|
3380 platform and screen geometry. |
|
3381 |
|
3382 \sa size |
|
3383 */ |
|
3384 |
|
3385 |
|
3386 QRect QWidget::normalGeometry() const |
|
3387 { |
|
3388 Q_D(const QWidget); |
|
3389 if (!d->extra || !d->extra->topextra) |
|
3390 return QRect(); |
|
3391 |
|
3392 if (!isMaximized() && !isFullScreen()) |
|
3393 return geometry(); |
|
3394 |
|
3395 return d->topData()->normalGeometry; |
|
3396 } |
|
3397 |
|
3398 |
|
3399 /*! |
|
3400 \property QWidget::childrenRect |
|
3401 \brief the bounding rectangle of the widget's children |
|
3402 |
|
3403 Hidden children are excluded. |
|
3404 |
|
3405 By default, for a widget with no children, this property contains a |
|
3406 rectangle with zero width and height located at the origin. |
|
3407 |
|
3408 \sa childrenRegion() geometry() |
|
3409 */ |
|
3410 |
|
3411 QRect QWidget::childrenRect() const |
|
3412 { |
|
3413 Q_D(const QWidget); |
|
3414 QRect r(0, 0, 0, 0); |
|
3415 for (int i = 0; i < d->children.size(); ++i) { |
|
3416 QWidget *w = qobject_cast<QWidget *>(d->children.at(i)); |
|
3417 if (w && !w->isWindow() && !w->isHidden()) |
|
3418 r |= w->geometry(); |
|
3419 } |
|
3420 return r; |
|
3421 } |
|
3422 |
|
3423 /*! |
|
3424 \property QWidget::childrenRegion |
|
3425 \brief the combined region occupied by the widget's children |
|
3426 |
|
3427 Hidden children are excluded. |
|
3428 |
|
3429 By default, for a widget with no children, this property contains an |
|
3430 empty region. |
|
3431 |
|
3432 \sa childrenRect() geometry() mask() |
|
3433 */ |
|
3434 |
|
3435 QRegion QWidget::childrenRegion() const |
|
3436 { |
|
3437 Q_D(const QWidget); |
|
3438 QRegion r; |
|
3439 for (int i = 0; i < d->children.size(); ++i) { |
|
3440 QWidget *w = qobject_cast<QWidget *>(d->children.at(i)); |
|
3441 if (w && !w->isWindow() && !w->isHidden()) { |
|
3442 QRegion mask = w->mask(); |
|
3443 if (mask.isEmpty()) |
|
3444 r |= w->geometry(); |
|
3445 else |
|
3446 r |= mask.translated(w->pos()); |
|
3447 } |
|
3448 } |
|
3449 return r; |
|
3450 } |
|
3451 |
|
3452 |
|
3453 /*! |
|
3454 \property QWidget::minimumSize |
|
3455 \brief the widget's minimum size |
|
3456 |
|
3457 The widget cannot be resized to a smaller size than the minimum |
|
3458 widget size. The widget's size is forced to the minimum size if |
|
3459 the current size is smaller. |
|
3460 |
|
3461 The minimum size set by this function will override the minimum size |
|
3462 defined by QLayout. In order to unset the minimum size, use a |
|
3463 value of \c{QSize(0, 0)}. |
|
3464 |
|
3465 By default, this property contains a size with zero width and height. |
|
3466 |
|
3467 \sa minimumWidth, minimumHeight, maximumSize, sizeIncrement |
|
3468 */ |
|
3469 |
|
3470 QSize QWidget::minimumSize() const |
|
3471 { |
|
3472 Q_D(const QWidget); |
|
3473 return d->extra ? QSize(d->extra->minw, d->extra->minh) : QSize(0, 0); |
|
3474 } |
|
3475 |
|
3476 /*! |
|
3477 \property QWidget::maximumSize |
|
3478 \brief the widget's maximum size in pixels |
|
3479 |
|
3480 The widget cannot be resized to a larger size than the maximum |
|
3481 widget size. |
|
3482 |
|
3483 By default, this property contains a size in which both width and height |
|
3484 have values of 16777215. |
|
3485 |
|
3486 \note The definition of the \c QWIDGETSIZE_MAX macro limits the maximum size |
|
3487 of widgets. |
|
3488 |
|
3489 \sa maximumWidth, maximumHeight, minimumSize, sizeIncrement |
|
3490 */ |
|
3491 |
|
3492 QSize QWidget::maximumSize() const |
|
3493 { |
|
3494 Q_D(const QWidget); |
|
3495 return d->extra ? QSize(d->extra->maxw, d->extra->maxh) |
|
3496 : QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); |
|
3497 } |
|
3498 |
|
3499 |
|
3500 /*! |
|
3501 \property QWidget::minimumWidth |
|
3502 \brief the widget's minimum width in pixels |
|
3503 |
|
3504 This property corresponds to the width held by the \l minimumSize property. |
|
3505 |
|
3506 By default, this property has a value of 0. |
|
3507 |
|
3508 \sa minimumSize, minimumHeight |
|
3509 */ |
|
3510 |
|
3511 /*! |
|
3512 \property QWidget::minimumHeight |
|
3513 \brief the widget's minimum height in pixels |
|
3514 |
|
3515 This property corresponds to the height held by the \l minimumSize property. |
|
3516 |
|
3517 By default, this property has a value of 0. |
|
3518 |
|
3519 \sa minimumSize, minimumWidth |
|
3520 */ |
|
3521 |
|
3522 /*! |
|
3523 \property QWidget::maximumWidth |
|
3524 \brief the widget's maximum width in pixels |
|
3525 |
|
3526 This property corresponds to the width held by the \l maximumSize property. |
|
3527 |
|
3528 By default, this property contains a value of 16777215. |
|
3529 |
|
3530 \note The definition of the \c QWIDGETSIZE_MAX macro limits the maximum size |
|
3531 of widgets. |
|
3532 |
|
3533 \sa maximumSize, maximumHeight |
|
3534 */ |
|
3535 |
|
3536 /*! |
|
3537 \property QWidget::maximumHeight |
|
3538 \brief the widget's maximum height in pixels |
|
3539 |
|
3540 This property corresponds to the height held by the \l maximumSize property. |
|
3541 |
|
3542 By default, this property contains a value of 16777215. |
|
3543 |
|
3544 \note The definition of the \c QWIDGETSIZE_MAX macro limits the maximum size |
|
3545 of widgets. |
|
3546 |
|
3547 \sa maximumSize, maximumWidth |
|
3548 */ |
|
3549 |
|
3550 /*! |
|
3551 \property QWidget::sizeIncrement |
|
3552 \brief the size increment of the widget |
|
3553 |
|
3554 When the user resizes the window, the size will move in steps of |
|
3555 sizeIncrement().width() pixels horizontally and |
|
3556 sizeIncrement.height() pixels vertically, with baseSize() as the |
|
3557 basis. Preferred widget sizes are for non-negative integers \e i |
|
3558 and \e j: |
|
3559 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 2 |
|
3560 |
|
3561 Note that while you can set the size increment for all widgets, it |
|
3562 only affects windows. |
|
3563 |
|
3564 By default, this property contains a size with zero width and height. |
|
3565 |
|
3566 \warning The size increment has no effect under Windows, and may |
|
3567 be disregarded by the window manager on X11. |
|
3568 |
|
3569 \sa size, minimumSize, maximumSize |
|
3570 */ |
|
3571 QSize QWidget::sizeIncrement() const |
|
3572 { |
|
3573 Q_D(const QWidget); |
|
3574 return (d->extra && d->extra->topextra) |
|
3575 ? QSize(d->extra->topextra->incw, d->extra->topextra->inch) |
|
3576 : QSize(0, 0); |
|
3577 } |
|
3578 |
|
3579 /*! |
|
3580 \property QWidget::baseSize |
|
3581 \brief the base size of the widget |
|
3582 |
|
3583 The base size is used to calculate a proper widget size if the |
|
3584 widget defines sizeIncrement(). |
|
3585 |
|
3586 By default, for a newly-created widget, this property contains a size with |
|
3587 zero width and height. |
|
3588 |
|
3589 \sa setSizeIncrement() |
|
3590 */ |
|
3591 |
|
3592 QSize QWidget::baseSize() const |
|
3593 { |
|
3594 Q_D(const QWidget); |
|
3595 return (d->extra != 0 && d->extra->topextra != 0) |
|
3596 ? QSize(d->extra->topextra->basew, d->extra->topextra->baseh) |
|
3597 : QSize(0, 0); |
|
3598 } |
|
3599 |
|
3600 bool QWidgetPrivate::setMinimumSize_helper(int &minw, int &minh) |
|
3601 { |
|
3602 Q_Q(QWidget); |
|
3603 |
|
3604 #ifdef Q_WS_QWS |
|
3605 if (q->isWindow()) { |
|
3606 const QRect maxWindowRect = QApplication::desktop()->availableGeometry(QApplication::desktop()->screenNumber(q)); |
|
3607 if (!maxWindowRect.isEmpty()) { |
|
3608 // ### This is really just a work-around. Layout shouldn't be |
|
3609 // asking for minimum sizes bigger than the screen. |
|
3610 if (minw > maxWindowRect.width()) |
|
3611 minw = maxWindowRect.width(); |
|
3612 if (minh > maxWindowRect.height()) |
|
3613 minh = maxWindowRect.height(); |
|
3614 } |
|
3615 } |
|
3616 #endif |
|
3617 int mw = minw, mh = minh; |
|
3618 if (mw == QWIDGETSIZE_MAX) |
|
3619 mw = 0; |
|
3620 if (mh == QWIDGETSIZE_MAX) |
|
3621 mh = 0; |
|
3622 if (minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX) { |
|
3623 qWarning("QWidget::setMinimumSize: (%s/%s) " |
|
3624 "The largest allowed size is (%d,%d)", |
|
3625 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX, |
|
3626 QWIDGETSIZE_MAX); |
|
3627 minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX); |
|
3628 minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX); |
|
3629 } |
|
3630 if (minw < 0 || minh < 0) { |
|
3631 qWarning("QWidget::setMinimumSize: (%s/%s) Negative sizes (%d,%d) " |
|
3632 "are not possible", |
|
3633 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh); |
|
3634 minw = mw = qMax(minw, 0); |
|
3635 minh = mh = qMax(minh, 0); |
|
3636 } |
|
3637 createExtra(); |
|
3638 if (extra->minw == mw && extra->minh == mh) |
|
3639 return false; |
|
3640 extra->minw = mw; |
|
3641 extra->minh = mh; |
|
3642 extra->explicitMinSize = (mw ? Qt::Horizontal : 0) | (mh ? Qt::Vertical : 0); |
|
3643 return true; |
|
3644 } |
|
3645 |
|
3646 /*! |
|
3647 \overload |
|
3648 |
|
3649 This function corresponds to setMinimumSize(QSize(minw, minh)). |
|
3650 Sets the minimum width to \a minw and the minimum height to \a |
|
3651 minh. |
|
3652 */ |
|
3653 |
|
3654 void QWidget::setMinimumSize(int minw, int minh) |
|
3655 { |
|
3656 Q_D(QWidget); |
|
3657 if (!d->setMinimumSize_helper(minw, minh)) |
|
3658 return; |
|
3659 |
|
3660 if (isWindow()) |
|
3661 d->setConstraints_sys(); |
|
3662 if (minw > width() || minh > height()) { |
|
3663 bool resized = testAttribute(Qt::WA_Resized); |
|
3664 bool maximized = isMaximized(); |
|
3665 resize(qMax(minw,width()), qMax(minh,height())); |
|
3666 setAttribute(Qt::WA_Resized, resized); //not a user resize |
|
3667 if (maximized) |
|
3668 data->window_state = data->window_state | Qt::WindowMaximized; |
|
3669 } |
|
3670 #ifndef QT_NO_GRAPHICSVIEW |
|
3671 if (d->extra) { |
|
3672 if (d->extra->proxyWidget) |
|
3673 d->extra->proxyWidget->setMinimumSize(minw, minh); |
|
3674 } |
|
3675 #endif |
|
3676 d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh); |
|
3677 } |
|
3678 |
|
3679 bool QWidgetPrivate::setMaximumSize_helper(int &maxw, int &maxh) |
|
3680 { |
|
3681 Q_Q(QWidget); |
|
3682 if (maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX) { |
|
3683 qWarning("QWidget::setMaximumSize: (%s/%s) " |
|
3684 "The largest allowed size is (%d,%d)", |
|
3685 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX, |
|
3686 QWIDGETSIZE_MAX); |
|
3687 maxw = qMin<int>(maxw, QWIDGETSIZE_MAX); |
|
3688 maxh = qMin<int>(maxh, QWIDGETSIZE_MAX); |
|
3689 } |
|
3690 if (maxw < 0 || maxh < 0) { |
|
3691 qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) " |
|
3692 "are not possible", |
|
3693 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), maxw, maxh); |
|
3694 maxw = qMax(maxw, 0); |
|
3695 maxh = qMax(maxh, 0); |
|
3696 } |
|
3697 createExtra(); |
|
3698 if (extra->maxw == maxw && extra->maxh == maxh) |
|
3699 return false; |
|
3700 extra->maxw = maxw; |
|
3701 extra->maxh = maxh; |
|
3702 extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) | |
|
3703 (maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0); |
|
3704 return true; |
|
3705 } |
|
3706 |
|
3707 /*! |
|
3708 \overload |
|
3709 |
|
3710 This function corresponds to setMaximumSize(QSize(\a maxw, \a |
|
3711 maxh)). Sets the maximum width to \a maxw and the maximum height |
|
3712 to \a maxh. |
|
3713 */ |
|
3714 void QWidget::setMaximumSize(int maxw, int maxh) |
|
3715 { |
|
3716 Q_D(QWidget); |
|
3717 if (!d->setMaximumSize_helper(maxw, maxh)) |
|
3718 return; |
|
3719 |
|
3720 if (isWindow()) |
|
3721 d->setConstraints_sys(); |
|
3722 if (maxw < width() || maxh < height()) { |
|
3723 bool resized = testAttribute(Qt::WA_Resized); |
|
3724 resize(qMin(maxw,width()), qMin(maxh,height())); |
|
3725 setAttribute(Qt::WA_Resized, resized); //not a user resize |
|
3726 } |
|
3727 |
|
3728 #ifndef QT_NO_GRAPHICSVIEW |
|
3729 if (d->extra) { |
|
3730 if (d->extra->proxyWidget) |
|
3731 d->extra->proxyWidget->setMaximumSize(maxw, maxh); |
|
3732 } |
|
3733 #endif |
|
3734 |
|
3735 d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh); |
|
3736 } |
|
3737 |
|
3738 /*! |
|
3739 \overload |
|
3740 |
|
3741 Sets the x (width) size increment to \a w and the y (height) size |
|
3742 increment to \a h. |
|
3743 */ |
|
3744 void QWidget::setSizeIncrement(int w, int h) |
|
3745 { |
|
3746 Q_D(QWidget); |
|
3747 d->createTLExtra(); |
|
3748 QTLWExtra* x = d->topData(); |
|
3749 if (x->incw == w && x->inch == h) |
|
3750 return; |
|
3751 x->incw = w; |
|
3752 x->inch = h; |
|
3753 if (isWindow()) |
|
3754 d->setConstraints_sys(); |
|
3755 } |
|
3756 |
|
3757 /*! |
|
3758 \overload |
|
3759 |
|
3760 This corresponds to setBaseSize(QSize(\a basew, \a baseh)). Sets |
|
3761 the widgets base size to width \a basew and height \a baseh. |
|
3762 */ |
|
3763 void QWidget::setBaseSize(int basew, int baseh) |
|
3764 { |
|
3765 Q_D(QWidget); |
|
3766 d->createTLExtra(); |
|
3767 QTLWExtra* x = d->topData(); |
|
3768 if (x->basew == basew && x->baseh == baseh) |
|
3769 return; |
|
3770 x->basew = basew; |
|
3771 x->baseh = baseh; |
|
3772 if (isWindow()) |
|
3773 d->setConstraints_sys(); |
|
3774 } |
|
3775 |
|
3776 /*! |
|
3777 Sets both the minimum and maximum sizes of the widget to \a s, |
|
3778 thereby preventing it from ever growing or shrinking. |
|
3779 |
|
3780 This will override the default size constraints set by QLayout. |
|
3781 |
|
3782 To remove constraints, set the size to QWIDGETSIZE_MAX. |
|
3783 |
|
3784 Alternatively, if you want the widget to have a |
|
3785 fixed size based on its contents, you can call |
|
3786 QLayout::setSizeConstraint(QLayout::SetFixedSize); |
|
3787 |
|
3788 \sa maximumSize, minimumSize |
|
3789 */ |
|
3790 |
|
3791 void QWidget::setFixedSize(const QSize & s) |
|
3792 { |
|
3793 setFixedSize(s.width(), s.height()); |
|
3794 } |
|
3795 |
|
3796 |
|
3797 /*! |
|
3798 \fn void QWidget::setFixedSize(int w, int h) |
|
3799 \overload |
|
3800 |
|
3801 Sets the width of the widget to \a w and the height to \a h. |
|
3802 */ |
|
3803 |
|
3804 void QWidget::setFixedSize(int w, int h) |
|
3805 { |
|
3806 Q_D(QWidget); |
|
3807 #ifdef Q_WS_QWS |
|
3808 // temporary fix for 4.3.x. |
|
3809 // Should move the embedded spesific contraints in setMinimumSize_helper into QLayout |
|
3810 int tmpW = w; |
|
3811 int tmpH = h; |
|
3812 bool minSizeSet = d->setMinimumSize_helper(tmpW, tmpH); |
|
3813 #else |
|
3814 bool minSizeSet = d->setMinimumSize_helper(w, h); |
|
3815 #endif |
|
3816 bool maxSizeSet = d->setMaximumSize_helper(w, h); |
|
3817 if (!minSizeSet && !maxSizeSet) |
|
3818 return; |
|
3819 |
|
3820 if (isWindow()) |
|
3821 d->setConstraints_sys(); |
|
3822 else |
|
3823 d->updateGeometry_helper(true); |
|
3824 |
|
3825 if (w != QWIDGETSIZE_MAX || h != QWIDGETSIZE_MAX) |
|
3826 resize(w, h); |
|
3827 } |
|
3828 |
|
3829 void QWidget::setMinimumWidth(int w) |
|
3830 { |
|
3831 Q_D(QWidget); |
|
3832 d->createExtra(); |
|
3833 uint expl = d->extra->explicitMinSize | (w ? Qt::Horizontal : 0); |
|
3834 setMinimumSize(w, minimumSize().height()); |
|
3835 d->extra->explicitMinSize = expl; |
|
3836 } |
|
3837 |
|
3838 void QWidget::setMinimumHeight(int h) |
|
3839 { |
|
3840 Q_D(QWidget); |
|
3841 d->createExtra(); |
|
3842 uint expl = d->extra->explicitMinSize | (h ? Qt::Vertical : 0); |
|
3843 setMinimumSize(minimumSize().width(), h); |
|
3844 d->extra->explicitMinSize = expl; |
|
3845 } |
|
3846 |
|
3847 void QWidget::setMaximumWidth(int w) |
|
3848 { |
|
3849 Q_D(QWidget); |
|
3850 d->createExtra(); |
|
3851 uint expl = d->extra->explicitMaxSize | (w == QWIDGETSIZE_MAX ? 0 : Qt::Horizontal); |
|
3852 setMaximumSize(w, maximumSize().height()); |
|
3853 d->extra->explicitMaxSize = expl; |
|
3854 } |
|
3855 |
|
3856 void QWidget::setMaximumHeight(int h) |
|
3857 { |
|
3858 Q_D(QWidget); |
|
3859 d->createExtra(); |
|
3860 uint expl = d->extra->explicitMaxSize | (h == QWIDGETSIZE_MAX ? 0 : Qt::Vertical); |
|
3861 setMaximumSize(maximumSize().width(), h); |
|
3862 d->extra->explicitMaxSize = expl; |
|
3863 } |
|
3864 |
|
3865 /*! |
|
3866 Sets both the minimum and maximum width of the widget to \a w |
|
3867 without changing the heights. Provided for convenience. |
|
3868 |
|
3869 \sa sizeHint() minimumSize() maximumSize() setFixedSize() |
|
3870 */ |
|
3871 |
|
3872 void QWidget::setFixedWidth(int w) |
|
3873 { |
|
3874 Q_D(QWidget); |
|
3875 d->createExtra(); |
|
3876 uint explMin = d->extra->explicitMinSize | Qt::Horizontal; |
|
3877 uint explMax = d->extra->explicitMaxSize | Qt::Horizontal; |
|
3878 setMinimumSize(w, minimumSize().height()); |
|
3879 setMaximumSize(w, maximumSize().height()); |
|
3880 d->extra->explicitMinSize = explMin; |
|
3881 d->extra->explicitMaxSize = explMax; |
|
3882 } |
|
3883 |
|
3884 |
|
3885 /*! |
|
3886 Sets both the minimum and maximum heights of the widget to \a h |
|
3887 without changing the widths. Provided for convenience. |
|
3888 |
|
3889 \sa sizeHint() minimumSize() maximumSize() setFixedSize() |
|
3890 */ |
|
3891 |
|
3892 void QWidget::setFixedHeight(int h) |
|
3893 { |
|
3894 Q_D(QWidget); |
|
3895 d->createExtra(); |
|
3896 uint explMin = d->extra->explicitMinSize | Qt::Vertical; |
|
3897 uint explMax = d->extra->explicitMaxSize | Qt::Vertical; |
|
3898 setMinimumSize(minimumSize().width(), h); |
|
3899 setMaximumSize(maximumSize().width(), h); |
|
3900 d->extra->explicitMinSize = explMin; |
|
3901 d->extra->explicitMaxSize = explMax; |
|
3902 } |
|
3903 |
|
3904 |
|
3905 /*! |
|
3906 Translates the widget coordinate \a pos to the coordinate system |
|
3907 of \a parent. The \a parent must not be 0 and must be a parent |
|
3908 of the calling widget. |
|
3909 |
|
3910 \sa mapFrom() mapToParent() mapToGlobal() underMouse() |
|
3911 */ |
|
3912 |
|
3913 QPoint QWidget::mapTo(QWidget * parent, const QPoint & pos) const |
|
3914 { |
|
3915 QPoint p = pos; |
|
3916 if (parent) { |
|
3917 const QWidget * w = this; |
|
3918 while (w != parent) { |
|
3919 Q_ASSERT_X(w, "QWidget::mapTo(QWidget *parent, const QPoint &pos)", |
|
3920 "parent must be in parent hierarchy"); |
|
3921 p = w->mapToParent(p); |
|
3922 w = w->parentWidget(); |
|
3923 } |
|
3924 } |
|
3925 return p; |
|
3926 } |
|
3927 |
|
3928 |
|
3929 /*! |
|
3930 Translates the widget coordinate \a pos from the coordinate system |
|
3931 of \a parent to this widget's coordinate system. The \a parent |
|
3932 must not be 0 and must be a parent of the calling widget. |
|
3933 |
|
3934 \sa mapTo() mapFromParent() mapFromGlobal() underMouse() |
|
3935 */ |
|
3936 |
|
3937 QPoint QWidget::mapFrom(QWidget * parent, const QPoint & pos) const |
|
3938 { |
|
3939 QPoint p(pos); |
|
3940 if (parent) { |
|
3941 const QWidget * w = this; |
|
3942 while (w != parent) { |
|
3943 Q_ASSERT_X(w, "QWidget::mapFrom(QWidget *parent, const QPoint &pos)", |
|
3944 "parent must be in parent hierarchy"); |
|
3945 |
|
3946 p = w->mapFromParent(p); |
|
3947 w = w->parentWidget(); |
|
3948 } |
|
3949 } |
|
3950 return p; |
|
3951 } |
|
3952 |
|
3953 |
|
3954 /*! |
|
3955 Translates the widget coordinate \a pos to a coordinate in the |
|
3956 parent widget. |
|
3957 |
|
3958 Same as mapToGlobal() if the widget has no parent. |
|
3959 |
|
3960 \sa mapFromParent() mapTo() mapToGlobal() underMouse() |
|
3961 */ |
|
3962 |
|
3963 QPoint QWidget::mapToParent(const QPoint &pos) const |
|
3964 { |
|
3965 return pos + data->crect.topLeft(); |
|
3966 } |
|
3967 |
|
3968 /*! |
|
3969 Translates the parent widget coordinate \a pos to widget |
|
3970 coordinates. |
|
3971 |
|
3972 Same as mapFromGlobal() if the widget has no parent. |
|
3973 |
|
3974 \sa mapToParent() mapFrom() mapFromGlobal() underMouse() |
|
3975 */ |
|
3976 |
|
3977 QPoint QWidget::mapFromParent(const QPoint &pos) const |
|
3978 { |
|
3979 return pos - data->crect.topLeft(); |
|
3980 } |
|
3981 |
|
3982 |
|
3983 /*! |
|
3984 Returns the window for this widget, i.e. the next ancestor widget |
|
3985 that has (or could have) a window-system frame. |
|
3986 |
|
3987 If the widget is a window, the widget itself is returned. |
|
3988 |
|
3989 Typical usage is changing the window title: |
|
3990 |
|
3991 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 3 |
|
3992 |
|
3993 \sa isWindow() |
|
3994 */ |
|
3995 |
|
3996 QWidget *QWidget::window() const |
|
3997 { |
|
3998 QWidget *w = (QWidget *)this; |
|
3999 QWidget *p = w->parentWidget(); |
|
4000 while (!w->isWindow() && p) { |
|
4001 w = p; |
|
4002 p = p->parentWidget(); |
|
4003 } |
|
4004 return w; |
|
4005 } |
|
4006 |
|
4007 /*! |
|
4008 \since 4.4 |
|
4009 |
|
4010 Returns the native parent for this widget, i.e. the next ancestor widget |
|
4011 that has a system identifier, or 0 if it does not have any native parent. |
|
4012 |
|
4013 \sa effectiveWinId() |
|
4014 */ |
|
4015 QWidget *QWidget::nativeParentWidget() const |
|
4016 { |
|
4017 QWidget *parent = parentWidget(); |
|
4018 while (parent && !parent->internalWinId()) |
|
4019 parent = parent->parentWidget(); |
|
4020 return parent; |
|
4021 } |
|
4022 |
|
4023 /*! \fn QWidget *QWidget::topLevelWidget() const |
|
4024 \obsolete |
|
4025 |
|
4026 Use window() instead. |
|
4027 */ |
|
4028 |
|
4029 #ifdef QT3_SUPPORT |
|
4030 /*! |
|
4031 Returns the color role used for painting the widget's background. |
|
4032 |
|
4033 Use QPalette(backgroundRole(()) instead. |
|
4034 */ |
|
4035 Qt::BackgroundMode QWidget::backgroundMode() const |
|
4036 { |
|
4037 if (testAttribute(Qt::WA_NoSystemBackground)) |
|
4038 return Qt::NoBackground; |
|
4039 switch(backgroundRole()) { |
|
4040 case QPalette::WindowText: |
|
4041 return Qt::PaletteForeground; |
|
4042 case QPalette::Button: |
|
4043 return Qt::PaletteButton; |
|
4044 case QPalette::Light: |
|
4045 return Qt::PaletteLight; |
|
4046 case QPalette::Midlight: |
|
4047 return Qt::PaletteMidlight; |
|
4048 case QPalette::Dark: |
|
4049 return Qt::PaletteDark; |
|
4050 case QPalette::Mid: |
|
4051 return Qt::PaletteMid; |
|
4052 case QPalette::Text: |
|
4053 return Qt::PaletteText; |
|
4054 case QPalette::BrightText: |
|
4055 return Qt::PaletteBrightText; |
|
4056 case QPalette::Base: |
|
4057 return Qt::PaletteBase; |
|
4058 case QPalette::Window: |
|
4059 return Qt::PaletteBackground; |
|
4060 case QPalette::Shadow: |
|
4061 return Qt::PaletteShadow; |
|
4062 case QPalette::Highlight: |
|
4063 return Qt::PaletteHighlight; |
|
4064 case QPalette::HighlightedText: |
|
4065 return Qt::PaletteHighlightedText; |
|
4066 case QPalette::ButtonText: |
|
4067 return Qt::PaletteButtonText; |
|
4068 case QPalette::Link: |
|
4069 return Qt::PaletteLink; |
|
4070 case QPalette::LinkVisited: |
|
4071 return Qt::PaletteLinkVisited; |
|
4072 default: |
|
4073 break; |
|
4074 } |
|
4075 return Qt::NoBackground; |
|
4076 } |
|
4077 |
|
4078 /*! |
|
4079 \fn void QWidget::setBackgroundMode(Qt::BackgroundMode |
|
4080 widgetBackground, Qt::BackgroundMode paletteBackground) |
|
4081 |
|
4082 Sets the color role used for painting the widget's background to |
|
4083 background mode \a widgetBackground. The \a paletteBackground mode |
|
4084 parameter is ignored. |
|
4085 */ |
|
4086 void QWidget::setBackgroundMode(Qt::BackgroundMode m, Qt::BackgroundMode) |
|
4087 { |
|
4088 Q_D(QWidget); |
|
4089 if(m == Qt::NoBackground) { |
|
4090 setAttribute(Qt::WA_NoSystemBackground, true); |
|
4091 return; |
|
4092 } |
|
4093 setAttribute(Qt::WA_NoSystemBackground, false); |
|
4094 d->fg_role = QPalette::NoRole; |
|
4095 QPalette::ColorRole role = d->bg_role; |
|
4096 switch(m) { |
|
4097 case Qt::FixedColor: |
|
4098 case Qt::FixedPixmap: |
|
4099 break; |
|
4100 case Qt::PaletteForeground: |
|
4101 role = QPalette::WindowText; |
|
4102 break; |
|
4103 case Qt::PaletteButton: |
|
4104 role = QPalette::Button; |
|
4105 break; |
|
4106 case Qt::PaletteLight: |
|
4107 role = QPalette::Light; |
|
4108 break; |
|
4109 case Qt::PaletteMidlight: |
|
4110 role = QPalette::Midlight; |
|
4111 break; |
|
4112 case Qt::PaletteDark: |
|
4113 role = QPalette::Dark; |
|
4114 break; |
|
4115 case Qt::PaletteMid: |
|
4116 role = QPalette::Mid; |
|
4117 break; |
|
4118 case Qt::PaletteText: |
|
4119 role = QPalette::Text; |
|
4120 break; |
|
4121 case Qt::PaletteBrightText: |
|
4122 role = QPalette::BrightText; |
|
4123 break; |
|
4124 case Qt::PaletteBase: |
|
4125 role = QPalette::Base; |
|
4126 break; |
|
4127 case Qt::PaletteBackground: |
|
4128 role = QPalette::Window; |
|
4129 break; |
|
4130 case Qt::PaletteShadow: |
|
4131 role = QPalette::Shadow; |
|
4132 break; |
|
4133 case Qt::PaletteHighlight: |
|
4134 role = QPalette::Highlight; |
|
4135 break; |
|
4136 case Qt::PaletteHighlightedText: |
|
4137 role = QPalette::HighlightedText; |
|
4138 break; |
|
4139 case Qt::PaletteButtonText: |
|
4140 role = QPalette::ButtonText; |
|
4141 break; |
|
4142 case Qt::PaletteLink: |
|
4143 role = QPalette::Link; |
|
4144 break; |
|
4145 case Qt::PaletteLinkVisited: |
|
4146 role = QPalette::LinkVisited; |
|
4147 break; |
|
4148 case Qt::X11ParentRelative: |
|
4149 d->fg_role = role = QPalette::NoRole; |
|
4150 default: |
|
4151 break; |
|
4152 } |
|
4153 setBackgroundRole(role); |
|
4154 } |
|
4155 |
|
4156 /*! |
|
4157 The widget mapper is no longer part of the public API. |
|
4158 */ |
|
4159 QT3_SUPPORT QWidgetMapper *QWidget::wmapper() { return QWidgetPrivate::mapper; } |
|
4160 |
|
4161 #endif |
|
4162 |
|
4163 |
|
4164 /*! |
|
4165 Returns the background role of the widget. |
|
4166 |
|
4167 The background role defines the brush from the widget's \l palette that |
|
4168 is used to render the background. |
|
4169 |
|
4170 If no explicit background role is set, the widget inherts its parent |
|
4171 widget's background role. |
|
4172 |
|
4173 \sa setBackgroundRole(), foregroundRole() |
|
4174 */ |
|
4175 QPalette::ColorRole QWidget::backgroundRole() const |
|
4176 { |
|
4177 |
|
4178 const QWidget *w = this; |
|
4179 do { |
|
4180 QPalette::ColorRole role = w->d_func()->bg_role; |
|
4181 if (role != QPalette::NoRole) |
|
4182 return role; |
|
4183 if (w->isWindow() || w->windowType() == Qt::SubWindow) |
|
4184 break; |
|
4185 w = w->parentWidget(); |
|
4186 } while (w); |
|
4187 return QPalette::Window; |
|
4188 } |
|
4189 |
|
4190 /*! |
|
4191 Sets the background role of the widget to \a role. |
|
4192 |
|
4193 The background role defines the brush from the widget's \l palette that |
|
4194 is used to render the background. |
|
4195 |
|
4196 If \a role is QPalette::NoRole, then the widget inherits its |
|
4197 parent's background role. |
|
4198 |
|
4199 Note that styles are free to choose any color from the palette. |
|
4200 You can modify the palette or set a style sheet if you don't |
|
4201 achieve the result you want with setBackgroundRole(). |
|
4202 |
|
4203 \sa backgroundRole(), foregroundRole() |
|
4204 */ |
|
4205 |
|
4206 void QWidget::setBackgroundRole(QPalette::ColorRole role) |
|
4207 { |
|
4208 Q_D(QWidget); |
|
4209 d->bg_role = role; |
|
4210 d->updateSystemBackground(); |
|
4211 d->propagatePaletteChange(); |
|
4212 d->updateIsOpaque(); |
|
4213 } |
|
4214 |
|
4215 /*! |
|
4216 Returns the foreground role. |
|
4217 |
|
4218 The foreground role defines the color from the widget's \l palette that |
|
4219 is used to draw the foreground. |
|
4220 |
|
4221 If no explicit foreground role is set, the function returns a role |
|
4222 that contrasts with the background role. |
|
4223 |
|
4224 \sa setForegroundRole(), backgroundRole() |
|
4225 */ |
|
4226 QPalette::ColorRole QWidget::foregroundRole() const |
|
4227 { |
|
4228 Q_D(const QWidget); |
|
4229 QPalette::ColorRole rl = QPalette::ColorRole(d->fg_role); |
|
4230 if (rl != QPalette::NoRole) |
|
4231 return rl; |
|
4232 QPalette::ColorRole role = QPalette::WindowText; |
|
4233 switch (backgroundRole()) { |
|
4234 case QPalette::Button: |
|
4235 role = QPalette::ButtonText; |
|
4236 break; |
|
4237 case QPalette::Base: |
|
4238 role = QPalette::Text; |
|
4239 break; |
|
4240 case QPalette::Dark: |
|
4241 case QPalette::Shadow: |
|
4242 role = QPalette::Light; |
|
4243 break; |
|
4244 case QPalette::Highlight: |
|
4245 role = QPalette::HighlightedText; |
|
4246 break; |
|
4247 case QPalette::ToolTipBase: |
|
4248 role = QPalette::ToolTipText; |
|
4249 break; |
|
4250 default: |
|
4251 ; |
|
4252 } |
|
4253 return role; |
|
4254 } |
|
4255 |
|
4256 /*! |
|
4257 Sets the foreground role of the widget to \a role. |
|
4258 |
|
4259 The foreground role defines the color from the widget's \l palette that |
|
4260 is used to draw the foreground. |
|
4261 |
|
4262 If \a role is QPalette::NoRole, the widget uses a foreground role |
|
4263 that contrasts with the background role. |
|
4264 |
|
4265 Note that styles are free to choose any color from the palette. |
|
4266 You can modify the palette or set a style sheet if you don't |
|
4267 achieve the result you want with setForegroundRole(). |
|
4268 |
|
4269 \sa foregroundRole(), backgroundRole() |
|
4270 */ |
|
4271 void QWidget::setForegroundRole(QPalette::ColorRole role) |
|
4272 { |
|
4273 Q_D(QWidget); |
|
4274 d->fg_role = role; |
|
4275 d->updateSystemBackground(); |
|
4276 d->propagatePaletteChange(); |
|
4277 } |
|
4278 |
|
4279 /*! |
|
4280 \property QWidget::palette |
|
4281 \brief the widget's palette |
|
4282 |
|
4283 This property describes the widget's palette. The palette is used by the |
|
4284 widget's style when rendering standard components, and is available as a |
|
4285 means to ensure that custom widgets can maintain consistency with the |
|
4286 native platform's look and feel. It's common that different platforms, or |
|
4287 different styles, have different palettes. |
|
4288 |
|
4289 When you assign a new palette to a widget, the color roles from this |
|
4290 palette are combined with the widget's default palette to form the |
|
4291 widget's final palette. The palette entry for the widget's background role |
|
4292 is used to fill the widget's background (see QWidget::autoFillBackground), |
|
4293 and the foreground role initializes QPainter's pen. |
|
4294 |
|
4295 The default depends on the system environment. QApplication maintains a |
|
4296 system/theme palette which serves as a default for all widgets. There may |
|
4297 also be special palette defaults for certain types of widgets (e.g., on |
|
4298 Windows XP and Vista, all classes that derive from QMenuBar have a special |
|
4299 default palette). You can also define default palettes for widgets |
|
4300 yourself by passing a custom palette and the name of a widget to |
|
4301 QApplication::setPalette(). Finally, the style always has the option of |
|
4302 polishing the palette as it's assigned (see QStyle::polish()). |
|
4303 |
|
4304 QWidget propagates explicit palette roles from parent to child. If you |
|
4305 assign a brush or color to a specific role on a palette and assign that |
|
4306 palette to a widget, that role will propagate to all the widget's |
|
4307 children, overriding any system defaults for that role. Note that palettes |
|
4308 by default don't propagate to windows (see isWindow()) unless the |
|
4309 Qt::WA_WindowPropagation attribute is enabled. |
|
4310 |
|
4311 QWidget's palette propagation is similar to its font propagation. |
|
4312 |
|
4313 The current style, which is used to render the content of all standard Qt |
|
4314 widgets, is free to choose colors and brushes from the widget palette, or |
|
4315 in some cases, to ignore the palette (partially, or completely). In |
|
4316 particular, certain styles like GTK style, Mac style, Windows XP, and |
|
4317 Vista style, depend on third party APIs to render the content of widgets, |
|
4318 and these styles typically do not follow the palette. Because of this, |
|
4319 assigning roles to a widget's palette is not guaranteed to change the |
|
4320 appearance of the widget. Instead, you may choose to apply a \l |
|
4321 styleSheet. You can refer to our Knowledge Base article |
|
4322 \l{http://qt.nokia.com/developer/knowledgebase/22}{here} for more |
|
4323 information. |
|
4324 |
|
4325 \warning Do not use this function in conjunction with \l{Qt Style Sheets}. |
|
4326 When using style sheets, the palette of a widget can be customized using |
|
4327 the "color", "background-color", "selection-color", |
|
4328 "selection-background-color" and "alternate-background-color". |
|
4329 |
|
4330 \sa QApplication::palette(), QWidget::font() |
|
4331 */ |
|
4332 const QPalette &QWidget::palette() const |
|
4333 { |
|
4334 if (!isEnabled()) { |
|
4335 data->pal.setCurrentColorGroup(QPalette::Disabled); |
|
4336 } else if ((!isVisible() || isActiveWindow()) |
|
4337 #if defined(Q_OS_WIN) && !defined(Q_WS_WINCE) |
|
4338 && !QApplicationPrivate::isBlockedByModal(const_cast<QWidget *>(this)) |
|
4339 #endif |
|
4340 ) { |
|
4341 data->pal.setCurrentColorGroup(QPalette::Active); |
|
4342 } else { |
|
4343 #ifdef Q_WS_MAC |
|
4344 extern bool qt_mac_can_clickThrough(const QWidget *); //qwidget_mac.cpp |
|
4345 if (qt_mac_can_clickThrough(this)) |
|
4346 data->pal.setCurrentColorGroup(QPalette::Active); |
|
4347 else |
|
4348 #endif |
|
4349 data->pal.setCurrentColorGroup(QPalette::Inactive); |
|
4350 } |
|
4351 return data->pal; |
|
4352 } |
|
4353 |
|
4354 void QWidget::setPalette(const QPalette &palette) |
|
4355 { |
|
4356 Q_D(QWidget); |
|
4357 setAttribute(Qt::WA_SetPalette, palette.resolve() != 0); |
|
4358 |
|
4359 // Determine which palette is inherited from this widget's ancestors and |
|
4360 // QApplication::palette, resolve this against \a palette (attributes from |
|
4361 // the inherited palette are copied over this widget's palette). Then |
|
4362 // propagate this palette to this widget's children. |
|
4363 QPalette naturalPalette = d->naturalWidgetPalette(d->inheritedPaletteResolveMask); |
|
4364 QPalette resolvedPalette = palette.resolve(naturalPalette); |
|
4365 d->setPalette_helper(resolvedPalette); |
|
4366 } |
|
4367 |
|
4368 /*! |
|
4369 \internal |
|
4370 |
|
4371 Returns the palette that the widget \a w inherits from its ancestors and |
|
4372 QApplication::palette. \a inheritedMask is the combination of the widget's |
|
4373 ancestors palette request masks (i.e., which attributes from the parent |
|
4374 widget's palette are implicitly imposed on this widget by the user). Note |
|
4375 that this font does not take into account the palette set on \a w itself. |
|
4376 */ |
|
4377 QPalette QWidgetPrivate::naturalWidgetPalette(uint inheritedMask) const |
|
4378 { |
|
4379 Q_Q(const QWidget); |
|
4380 QPalette naturalPalette = QApplication::palette(q); |
|
4381 if (!q->testAttribute(Qt::WA_StyleSheet) |
|
4382 && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) || (extra && extra->proxyWidget))) { |
|
4383 if (QWidget *p = q->parentWidget()) { |
|
4384 if (!p->testAttribute(Qt::WA_StyleSheet)) { |
|
4385 if (!naturalPalette.isCopyOf(QApplication::palette())) { |
|
4386 QPalette inheritedPalette = p->palette(); |
|
4387 inheritedPalette.resolve(inheritedMask); |
|
4388 naturalPalette = inheritedPalette.resolve(naturalPalette); |
|
4389 } else { |
|
4390 naturalPalette = p->palette(); |
|
4391 } |
|
4392 } |
|
4393 } else if (extra && extra->proxyWidget) { |
|
4394 #ifndef QT_NO_GRAPHICSVIEW |
|
4395 QPalette inheritedPalette = extra->proxyWidget->palette(); |
|
4396 inheritedPalette.resolve(inheritedMask); |
|
4397 naturalPalette = inheritedPalette.resolve(naturalPalette); |
|
4398 #endif //QT_NO_GRAPHICSVIEW |
|
4399 } |
|
4400 } |
|
4401 naturalPalette.resolve(0); |
|
4402 return naturalPalette; |
|
4403 } |
|
4404 /*! |
|
4405 \internal |
|
4406 |
|
4407 Determine which palette is inherited from this widget's ancestors and |
|
4408 QApplication::palette, resolve this against this widget's palette |
|
4409 (attributes from the inherited palette are copied over this widget's |
|
4410 palette). Then propagate this palette to this widget's children. |
|
4411 */ |
|
4412 void QWidgetPrivate::resolvePalette() |
|
4413 { |
|
4414 QPalette naturalPalette = naturalWidgetPalette(inheritedPaletteResolveMask); |
|
4415 QPalette resolvedPalette = data.pal.resolve(naturalPalette); |
|
4416 setPalette_helper(resolvedPalette); |
|
4417 } |
|
4418 |
|
4419 void QWidgetPrivate::setPalette_helper(const QPalette &palette) |
|
4420 { |
|
4421 Q_Q(QWidget); |
|
4422 if (data.pal == palette && data.pal.resolve() == palette.resolve()) |
|
4423 return; |
|
4424 data.pal = palette; |
|
4425 updateSystemBackground(); |
|
4426 propagatePaletteChange(); |
|
4427 updateIsOpaque(); |
|
4428 q->update(); |
|
4429 updateIsOpaque(); |
|
4430 } |
|
4431 |
|
4432 /*! |
|
4433 \property QWidget::font |
|
4434 \brief the font currently set for the widget |
|
4435 |
|
4436 This property describes the widget's requested font. The font is used by |
|
4437 the widget's style when rendering standard components, and is available as |
|
4438 a means to ensure that custom widgets can maintain consistency with the |
|
4439 native platform's look and feel. It's common that different platforms, or |
|
4440 different styles, define different fonts for an application. |
|
4441 |
|
4442 When you assign a new font to a widget, the properties from this font are |
|
4443 combined with the widget's default font to form the widget's final |
|
4444 font. You can call fontInfo() to get a copy of the widget's final |
|
4445 font. The final font is also used to initialize QPainter's font. |
|
4446 |
|
4447 The default depends on the system environment. QApplication maintains a |
|
4448 system/theme font which serves as a default for all widgets. There may |
|
4449 also be special font defaults for certain types of widgets. You can also |
|
4450 define default fonts for widgets yourself by passing a custom font and the |
|
4451 name of a widget to QApplication::setFont(). Finally, the font is matched |
|
4452 against Qt's font database to find the best match. |
|
4453 |
|
4454 QWidget propagates explicit font properties from parent to child. If you |
|
4455 change a specific property on a font and assign that font to a widget, |
|
4456 that property will propagate to all the widget's children, overriding any |
|
4457 system defaults for that property. Note that fonts by default don't |
|
4458 propagate to windows (see isWindow()) unless the Qt::WA_WindowPropagation |
|
4459 attribute is enabled. |
|
4460 |
|
4461 QWidget's font propagation is similar to its palette propagation. |
|
4462 |
|
4463 The current style, which is used to render the content of all standard Qt |
|
4464 widgets, is free to choose to use the widget font, or in some cases, to |
|
4465 ignore it (partially, or completely). In particular, certain styles like |
|
4466 GTK style, Mac style, Windows XP, and Vista style, apply special |
|
4467 modifications to the widget font to match the platform's native look and |
|
4468 feel. Because of this, assigning properties to a widget's font is not |
|
4469 guaranteed to change the appearance of the widget. Instead, you may choose |
|
4470 to apply a \l styleSheet. |
|
4471 |
|
4472 \note If \l{Qt Style Sheets} are used on the same widget as setFont(), |
|
4473 style sheets will take precedence if the settings conflict. |
|
4474 |
|
4475 \sa fontInfo(), fontMetrics() |
|
4476 */ |
|
4477 |
|
4478 void QWidget::setFont(const QFont &font) |
|
4479 { |
|
4480 Q_D(QWidget); |
|
4481 |
|
4482 #ifndef QT_NO_STYLE_STYLESHEET |
|
4483 const QStyleSheetStyle* style; |
|
4484 if (d->extra && (style = qobject_cast<const QStyleSheetStyle*>(d->extra->style))) { |
|
4485 style->saveWidgetFont(this, font); |
|
4486 } |
|
4487 #endif |
|
4488 |
|
4489 setAttribute(Qt::WA_SetFont, font.resolve() != 0); |
|
4490 |
|
4491 // Determine which font is inherited from this widget's ancestors and |
|
4492 // QApplication::font, resolve this against \a font (attributes from the |
|
4493 // inherited font are copied over). Then propagate this font to this |
|
4494 // widget's children. |
|
4495 QFont naturalFont = d->naturalWidgetFont(d->inheritedFontResolveMask); |
|
4496 QFont resolvedFont = font.resolve(naturalFont); |
|
4497 d->setFont_helper(resolvedFont); |
|
4498 } |
|
4499 |
|
4500 /* |
|
4501 \internal |
|
4502 |
|
4503 Returns the font that the widget \a w inherits from its ancestors and |
|
4504 QApplication::font. \a inheritedMask is the combination of the widget's |
|
4505 ancestors font request masks (i.e., which attributes from the parent |
|
4506 widget's font are implicitly imposed on this widget by the user). Note |
|
4507 that this font does not take into account the font set on \a w itself. |
|
4508 |
|
4509 ### Stylesheet has a different font propagation mechanism. When a stylesheet |
|
4510 is applied, fonts are not propagated anymore |
|
4511 */ |
|
4512 QFont QWidgetPrivate::naturalWidgetFont(uint inheritedMask) const |
|
4513 { |
|
4514 Q_Q(const QWidget); |
|
4515 QFont naturalFont = QApplication::font(q); |
|
4516 if (!q->testAttribute(Qt::WA_StyleSheet) |
|
4517 && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) || (extra && extra->proxyWidget))) { |
|
4518 if (QWidget *p = q->parentWidget()) { |
|
4519 if (!p->testAttribute(Qt::WA_StyleSheet)) { |
|
4520 if (!naturalFont.isCopyOf(QApplication::font())) { |
|
4521 QFont inheritedFont = p->font(); |
|
4522 inheritedFont.resolve(inheritedMask); |
|
4523 naturalFont = inheritedFont.resolve(naturalFont); |
|
4524 } else { |
|
4525 naturalFont = p->font(); |
|
4526 } |
|
4527 } |
|
4528 } else if (extra && extra->proxyWidget) { |
|
4529 #ifndef QT_NO_GRAPHICSVIEW |
|
4530 QFont inheritedFont = extra->proxyWidget->font(); |
|
4531 inheritedFont.resolve(inheritedMask); |
|
4532 naturalFont = inheritedFont.resolve(naturalFont); |
|
4533 #endif //QT_NO_GRAPHICSVIEW |
|
4534 } |
|
4535 } |
|
4536 naturalFont.resolve(0); |
|
4537 return naturalFont; |
|
4538 } |
|
4539 |
|
4540 /*! |
|
4541 \internal |
|
4542 |
|
4543 Determine which font is implicitly imposed on this widget by its ancestors |
|
4544 and QApplication::font, resolve this against its own font (attributes from |
|
4545 the implicit font are copied over). Then propagate this font to this |
|
4546 widget's children. |
|
4547 */ |
|
4548 void QWidgetPrivate::resolveFont() |
|
4549 { |
|
4550 QFont naturalFont = naturalWidgetFont(inheritedFontResolveMask); |
|
4551 QFont resolvedFont = data.fnt.resolve(naturalFont); |
|
4552 setFont_helper(resolvedFont); |
|
4553 } |
|
4554 |
|
4555 /*! |
|
4556 \internal |
|
4557 |
|
4558 Assign \a font to this widget, and propagate it to all children, except |
|
4559 style sheet widgets (handled differently) and windows that don't enable |
|
4560 window propagation. \a implicitMask is the union of all ancestor widgets' |
|
4561 font request masks, and determines which attributes from this widget's |
|
4562 font should propagate. |
|
4563 */ |
|
4564 void QWidgetPrivate::updateFont(const QFont &font) |
|
4565 { |
|
4566 Q_Q(QWidget); |
|
4567 #ifndef QT_NO_STYLE_STYLESHEET |
|
4568 const QStyleSheetStyle* cssStyle; |
|
4569 cssStyle = extra ? qobject_cast<const QStyleSheetStyle*>(extra->style) : 0; |
|
4570 #endif |
|
4571 |
|
4572 #ifdef QT3_SUPPORT |
|
4573 QFont old = data.fnt; |
|
4574 #endif |
|
4575 data.fnt = QFont(font, q); |
|
4576 #if defined(Q_WS_X11) |
|
4577 // make sure the font set on this widget is associated with the correct screen |
|
4578 data.fnt.x11SetScreen(xinfo.screen()); |
|
4579 #endif |
|
4580 // Combine new mask with natural mask and propagate to children. |
|
4581 if (!q->parentWidget() && extra && extra->proxyWidget) { |
|
4582 #ifndef QT_NO_GRAPHICSVIEW |
|
4583 QGraphicsProxyWidget *p = extra->proxyWidget; |
|
4584 inheritedFontResolveMask = p->d_func()->inheritedFontResolveMask | p->font().resolve(); |
|
4585 #endif //QT_NO_GRAPHICSVIEW |
|
4586 } else if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) { |
|
4587 inheritedFontResolveMask = 0; |
|
4588 } |
|
4589 uint newMask = data.fnt.resolve() | inheritedFontResolveMask; |
|
4590 |
|
4591 for (int i = 0; i < children.size(); ++i) { |
|
4592 QWidget *w = qobject_cast<QWidget*>(children.at(i)); |
|
4593 if (w) { |
|
4594 if (0) { |
|
4595 #ifndef QT_NO_STYLE_STYLESHEET |
|
4596 } else if (w->testAttribute(Qt::WA_StyleSheet)) { |
|
4597 // Style sheets follow a different font propagation scheme. |
|
4598 if (cssStyle) |
|
4599 cssStyle->updateStyleSheetFont(w); |
|
4600 #endif |
|
4601 } else if ((!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) { |
|
4602 // Propagate font changes. |
|
4603 QWidgetPrivate *wd = w->d_func(); |
|
4604 wd->inheritedFontResolveMask = newMask; |
|
4605 wd->resolveFont(); |
|
4606 } |
|
4607 } |
|
4608 } |
|
4609 |
|
4610 #ifndef QT_NO_STYLE_STYLESHEET |
|
4611 if (cssStyle) { |
|
4612 cssStyle->updateStyleSheetFont(q); |
|
4613 } |
|
4614 #endif |
|
4615 |
|
4616 QEvent e(QEvent::FontChange); |
|
4617 QApplication::sendEvent(q, &e); |
|
4618 #ifdef QT3_SUPPORT |
|
4619 q->fontChange(old); |
|
4620 #endif |
|
4621 } |
|
4622 |
|
4623 void QWidgetPrivate::setLayoutDirection_helper(Qt::LayoutDirection direction) |
|
4624 { |
|
4625 Q_Q(QWidget); |
|
4626 |
|
4627 if ( (direction == Qt::RightToLeft) == q->testAttribute(Qt::WA_RightToLeft)) |
|
4628 return; |
|
4629 q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft)); |
|
4630 if (!children.isEmpty()) { |
|
4631 for (int i = 0; i < children.size(); ++i) { |
|
4632 QWidget *w = qobject_cast<QWidget*>(children.at(i)); |
|
4633 if (w && !w->isWindow() && !w->testAttribute(Qt::WA_SetLayoutDirection)) |
|
4634 w->d_func()->setLayoutDirection_helper(direction); |
|
4635 } |
|
4636 } |
|
4637 QEvent e(QEvent::LayoutDirectionChange); |
|
4638 QApplication::sendEvent(q, &e); |
|
4639 } |
|
4640 |
|
4641 void QWidgetPrivate::resolveLayoutDirection() |
|
4642 { |
|
4643 Q_Q(const QWidget); |
|
4644 if (!q->testAttribute(Qt::WA_SetLayoutDirection)) |
|
4645 setLayoutDirection_helper(q->isWindow() ? QApplication::layoutDirection() : q->parentWidget()->layoutDirection()); |
|
4646 } |
|
4647 |
|
4648 /*! |
|
4649 \property QWidget::layoutDirection |
|
4650 |
|
4651 \brief the layout direction for this widget |
|
4652 |
|
4653 By default, this property is set to Qt::LeftToRight. |
|
4654 |
|
4655 When the layout direction is set on a widget, it will propagate to |
|
4656 the widget's children. Children added after the call to \c |
|
4657 setLayoutDirection() will not inherit the parent's layout |
|
4658 direction. |
|
4659 |
|
4660 \sa QApplication::layoutDirection |
|
4661 */ |
|
4662 void QWidget::setLayoutDirection(Qt::LayoutDirection direction) |
|
4663 { |
|
4664 Q_D(QWidget); |
|
4665 |
|
4666 setAttribute(Qt::WA_SetLayoutDirection); |
|
4667 d->setLayoutDirection_helper(direction); |
|
4668 } |
|
4669 |
|
4670 Qt::LayoutDirection QWidget::layoutDirection() const |
|
4671 { |
|
4672 return testAttribute(Qt::WA_RightToLeft) ? Qt::RightToLeft : Qt::LeftToRight; |
|
4673 } |
|
4674 |
|
4675 void QWidget::unsetLayoutDirection() |
|
4676 { |
|
4677 Q_D(QWidget); |
|
4678 setAttribute(Qt::WA_SetLayoutDirection, false); |
|
4679 d->resolveLayoutDirection(); |
|
4680 } |
|
4681 |
|
4682 /*! |
|
4683 \fn QFontMetrics QWidget::fontMetrics() const |
|
4684 |
|
4685 Returns the font metrics for the widget's current font. |
|
4686 Equivalent to QFontMetrics(widget->font()). |
|
4687 |
|
4688 \sa font(), fontInfo(), setFont() |
|
4689 */ |
|
4690 |
|
4691 /*! |
|
4692 \fn QFontInfo QWidget::fontInfo() const |
|
4693 |
|
4694 Returns the font info for the widget's current font. |
|
4695 Equivalent to QFontInto(widget->font()). |
|
4696 |
|
4697 \sa font(), fontMetrics(), setFont() |
|
4698 */ |
|
4699 |
|
4700 |
|
4701 /*! |
|
4702 \property QWidget::cursor |
|
4703 \brief the cursor shape for this widget |
|
4704 |
|
4705 The mouse cursor will assume this shape when it's over this |
|
4706 widget. See the \link Qt::CursorShape list of predefined cursor |
|
4707 objects\endlink for a range of useful shapes. |
|
4708 |
|
4709 An editor widget might use an I-beam cursor: |
|
4710 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 6 |
|
4711 |
|
4712 If no cursor has been set, or after a call to unsetCursor(), the |
|
4713 parent's cursor is used. |
|
4714 |
|
4715 By default, this property contains a cursor with the Qt::ArrowCursor |
|
4716 shape. |
|
4717 |
|
4718 Some underlying window implementations will reset the cursor if it |
|
4719 leaves a widget even if the mouse is grabbed. If you want to have |
|
4720 a cursor set for all widgets, even when outside the window, consider |
|
4721 QApplication::setOverrideCursor(). |
|
4722 |
|
4723 \sa QApplication::setOverrideCursor() |
|
4724 */ |
|
4725 |
|
4726 #ifndef QT_NO_CURSOR |
|
4727 QCursor QWidget::cursor() const |
|
4728 { |
|
4729 Q_D(const QWidget); |
|
4730 if (testAttribute(Qt::WA_SetCursor)) |
|
4731 return (d->extra && d->extra->curs) |
|
4732 ? *d->extra->curs |
|
4733 : QCursor(Qt::ArrowCursor); |
|
4734 if (isWindow() || !parentWidget()) |
|
4735 return QCursor(Qt::ArrowCursor); |
|
4736 return parentWidget()->cursor(); |
|
4737 } |
|
4738 |
|
4739 void QWidget::setCursor(const QCursor &cursor) |
|
4740 { |
|
4741 Q_D(QWidget); |
|
4742 // On Mac we must set the cursor even if it is the ArrowCursor. |
|
4743 #if !defined(Q_WS_MAC) && !defined(Q_WS_QWS) |
|
4744 if (cursor.shape() != Qt::ArrowCursor |
|
4745 || (d->extra && d->extra->curs)) |
|
4746 #endif |
|
4747 { |
|
4748 d->createExtra(); |
|
4749 QCursor *newCursor = new QCursor(cursor); |
|
4750 delete d->extra->curs; |
|
4751 d->extra->curs = newCursor; |
|
4752 } |
|
4753 setAttribute(Qt::WA_SetCursor); |
|
4754 d->setCursor_sys(cursor); |
|
4755 |
|
4756 QEvent event(QEvent::CursorChange); |
|
4757 QApplication::sendEvent(this, &event); |
|
4758 } |
|
4759 |
|
4760 void QWidget::unsetCursor() |
|
4761 { |
|
4762 Q_D(QWidget); |
|
4763 if (d->extra) { |
|
4764 delete d->extra->curs; |
|
4765 d->extra->curs = 0; |
|
4766 } |
|
4767 if (!isWindow()) |
|
4768 setAttribute(Qt::WA_SetCursor, false); |
|
4769 d->unsetCursor_sys(); |
|
4770 |
|
4771 QEvent event(QEvent::CursorChange); |
|
4772 QApplication::sendEvent(this, &event); |
|
4773 } |
|
4774 |
|
4775 #endif |
|
4776 |
|
4777 /*! |
|
4778 \enum QWidget::RenderFlag |
|
4779 |
|
4780 This enum describes how to render the widget when calling QWidget::render(). |
|
4781 |
|
4782 \value DrawWindowBackground If you enable this option, the widget's background |
|
4783 is rendered into the target even if autoFillBackground is not set. By default, |
|
4784 this option is enabled. |
|
4785 |
|
4786 \value DrawChildren If you enable this option, the widget's children |
|
4787 are rendered recursively into the target. By default, this option is enabled. |
|
4788 |
|
4789 \value IgnoreMask If you enable this option, the widget's QWidget::mask() |
|
4790 is ignored when rendering into the target. By default, this option is disabled. |
|
4791 |
|
4792 \since 4.3 |
|
4793 */ |
|
4794 |
|
4795 /*! |
|
4796 \since 4.3 |
|
4797 |
|
4798 Renders the \a sourceRegion of this widget into the \a target |
|
4799 using \a renderFlags to determine how to render. Rendering |
|
4800 starts at \a targetOffset in the \a target. For example: |
|
4801 |
|
4802 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 7 |
|
4803 |
|
4804 If \a sourceRegion is a null region, this function will use QWidget::rect() as |
|
4805 the region, i.e. the entire widget. |
|
4806 |
|
4807 Ensure that you call QPainter::end() for the \a target device's |
|
4808 active painter (if any) before rendering. For example: |
|
4809 |
|
4810 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 8 |
|
4811 |
|
4812 \note To obtain the contents of an OpenGL widget, use QGLWidget::grabFrameBuffer() |
|
4813 or QGLWidget::renderPixmap() instead. |
|
4814 */ |
|
4815 void QWidget::render(QPaintDevice *target, const QPoint &targetOffset, |
|
4816 const QRegion &sourceRegion, RenderFlags renderFlags) |
|
4817 { |
|
4818 Q_D(QWidget); |
|
4819 if (!target) { |
|
4820 qWarning("QWidget::render: null pointer to paint device"); |
|
4821 return; |
|
4822 } |
|
4823 |
|
4824 const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter; |
|
4825 QRegion paintRegion = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags) |
|
4826 : sourceRegion; |
|
4827 if (paintRegion.isEmpty()) |
|
4828 return; |
|
4829 |
|
4830 #ifndef Q_WS_MAC |
|
4831 QPainter *oldSharedPainter = inRenderWithPainter ? d->sharedPainter() : 0; |
|
4832 |
|
4833 // Use the target's shared painter if set (typically set when doing |
|
4834 // "other->render(widget);" in the widget's paintEvent. |
|
4835 if (target->devType() == QInternal::Widget) { |
|
4836 QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func(); |
|
4837 if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) { |
|
4838 QPainter *targetPainter = targetPrivate->sharedPainter(); |
|
4839 if (targetPainter && targetPainter->isActive()) |
|
4840 d->setSharedPainter(targetPainter); |
|
4841 } |
|
4842 } |
|
4843 #endif |
|
4844 |
|
4845 // Use the target's redirected device if set and adjust offset and paint |
|
4846 // region accordingly. This is typically the case when people call render |
|
4847 // from the paintEvent. |
|
4848 QPoint offset = targetOffset; |
|
4849 offset -= paintRegion.boundingRect().topLeft(); |
|
4850 QPoint redirectionOffset; |
|
4851 QPaintDevice *redirected = 0; |
|
4852 |
|
4853 if (target->devType() == QInternal::Widget) |
|
4854 redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset); |
|
4855 if (!redirected) |
|
4856 redirected = QPainter::redirected(target, &redirectionOffset); |
|
4857 |
|
4858 if (redirected) { |
|
4859 target = redirected; |
|
4860 offset -= redirectionOffset; |
|
4861 } |
|
4862 |
|
4863 if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp). |
|
4864 if (QPaintEngine *targetEngine = target->paintEngine()) { |
|
4865 const QRegion targetSystemClip = targetEngine->systemClip(); |
|
4866 if (!targetSystemClip.isEmpty()) |
|
4867 paintRegion &= targetSystemClip.translated(-offset); |
|
4868 } |
|
4869 } |
|
4870 |
|
4871 // Set backingstore flags. |
|
4872 int flags = QWidgetPrivate::DrawPaintOnScreen | QWidgetPrivate::DrawInvisible; |
|
4873 if (renderFlags & DrawWindowBackground) |
|
4874 flags |= QWidgetPrivate::DrawAsRoot; |
|
4875 |
|
4876 if (renderFlags & DrawChildren) |
|
4877 flags |= QWidgetPrivate::DrawRecursive; |
|
4878 else |
|
4879 flags |= QWidgetPrivate::DontSubtractOpaqueChildren; |
|
4880 |
|
4881 #ifdef Q_WS_QWS |
|
4882 flags |= QWidgetPrivate::DontSetCompositionMode; |
|
4883 #endif |
|
4884 |
|
4885 if (target->devType() == QInternal::Printer) { |
|
4886 QPainter p(target); |
|
4887 d->render_helper(&p, targetOffset, paintRegion, renderFlags); |
|
4888 return; |
|
4889 } |
|
4890 |
|
4891 #ifndef Q_WS_MAC |
|
4892 // Render via backingstore. |
|
4893 d->drawWidget(target, paintRegion, offset, flags, d->sharedPainter()); |
|
4894 |
|
4895 // Restore shared painter. |
|
4896 if (oldSharedPainter) |
|
4897 d->setSharedPainter(oldSharedPainter); |
|
4898 #else |
|
4899 // Render via backingstore (no shared painter). |
|
4900 d->drawWidget(target, paintRegion, offset, flags, 0); |
|
4901 #endif |
|
4902 } |
|
4903 |
|
4904 /*! |
|
4905 \overload |
|
4906 |
|
4907 Renders the widget into the \a painter's QPainter::device(). |
|
4908 |
|
4909 Transformations and settings applied to the \a painter will be used |
|
4910 when rendering. |
|
4911 |
|
4912 \note The \a painter must be active. On Mac OS X the widget will be |
|
4913 rendered into a QPixmap and then drawn by the \a painter. |
|
4914 |
|
4915 \sa QPainter::device() |
|
4916 */ |
|
4917 void QWidget::render(QPainter *painter, const QPoint &targetOffset, |
|
4918 const QRegion &sourceRegion, RenderFlags renderFlags) |
|
4919 { |
|
4920 if (!painter) { |
|
4921 qWarning("QWidget::render: Null pointer to painter"); |
|
4922 return; |
|
4923 } |
|
4924 |
|
4925 if (!painter->isActive()) { |
|
4926 qWarning("QWidget::render: Cannot render with an inactive painter"); |
|
4927 return; |
|
4928 } |
|
4929 |
|
4930 const qreal opacity = painter->opacity(); |
|
4931 if (qFuzzyIsNull(opacity)) |
|
4932 return; // Fully transparent. |
|
4933 |
|
4934 Q_D(QWidget); |
|
4935 const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter; |
|
4936 const QRegion toBePainted = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags) |
|
4937 : sourceRegion; |
|
4938 if (toBePainted.isEmpty()) |
|
4939 return; |
|
4940 |
|
4941 if (!d->extra) |
|
4942 d->createExtra(); |
|
4943 d->extra->inRenderWithPainter = true; |
|
4944 |
|
4945 #ifdef Q_WS_MAC |
|
4946 d->render_helper(painter, targetOffset, toBePainted, renderFlags); |
|
4947 #else |
|
4948 QPaintEngine *engine = painter->paintEngine(); |
|
4949 Q_ASSERT(engine); |
|
4950 QPaintEnginePrivate *enginePriv = engine->d_func(); |
|
4951 Q_ASSERT(enginePriv); |
|
4952 QPaintDevice *target = engine->paintDevice(); |
|
4953 Q_ASSERT(target); |
|
4954 |
|
4955 // Render via a pixmap when dealing with non-opaque painters or printers. |
|
4956 if (!inRenderWithPainter && (opacity < 1.0 || (target->devType() == QInternal::Printer))) { |
|
4957 d->render_helper(painter, targetOffset, toBePainted, renderFlags); |
|
4958 d->extra->inRenderWithPainter = false; |
|
4959 return; |
|
4960 } |
|
4961 |
|
4962 // Set new shared painter. |
|
4963 QPainter *oldPainter = d->sharedPainter(); |
|
4964 d->setSharedPainter(painter); |
|
4965 |
|
4966 // Save current system clip, viewport and transform, |
|
4967 const QTransform oldTransform = enginePriv->systemTransform; |
|
4968 const QRegion oldSystemClip = enginePriv->systemClip; |
|
4969 const QRegion oldSystemViewport = enginePriv->systemViewport; |
|
4970 |
|
4971 // This ensures that all painting triggered by render() is clipped to the current engine clip. |
|
4972 if (painter->hasClipping()) { |
|
4973 const QRegion painterClip = painter->deviceTransform().map(painter->clipRegion()); |
|
4974 enginePriv->setSystemViewport(oldSystemClip.isEmpty() ? painterClip : oldSystemClip & painterClip); |
|
4975 } else { |
|
4976 enginePriv->setSystemViewport(oldSystemClip); |
|
4977 } |
|
4978 |
|
4979 render(target, targetOffset, toBePainted, renderFlags); |
|
4980 |
|
4981 // Restore system clip, viewport and transform. |
|
4982 enginePriv->systemClip = oldSystemClip; |
|
4983 enginePriv->setSystemViewport(oldSystemViewport); |
|
4984 enginePriv->setSystemTransform(oldTransform); |
|
4985 |
|
4986 // Restore shared painter. |
|
4987 d->setSharedPainter(oldPainter); |
|
4988 #endif |
|
4989 |
|
4990 d->extra->inRenderWithPainter = false; |
|
4991 } |
|
4992 |
|
4993 /*! |
|
4994 \brief The graphicsEffect function returns a pointer to the |
|
4995 widget's graphics effect. |
|
4996 |
|
4997 If the widget has no graphics effect, 0 is returned. |
|
4998 |
|
4999 \since 4.6 |
|
5000 |
|
5001 \sa setGraphicsEffect() |
|
5002 */ |
|
5003 QGraphicsEffect *QWidget::graphicsEffect() const |
|
5004 { |
|
5005 Q_D(const QWidget); |
|
5006 return d->graphicsEffect; |
|
5007 } |
|
5008 |
|
5009 /*! |
|
5010 |
|
5011 \brief The setGraphicsEffect function is for setting the widget's graphics effect. |
|
5012 |
|
5013 Sets \a effect as the widget's effect. If there already is an effect installed |
|
5014 on this widget, QWidget will delete the existing effect before installing |
|
5015 the new \a effect. |
|
5016 |
|
5017 If \a effect is the installed on a different widget, setGraphicsEffect() will remove |
|
5018 the effect from the widget and install it on this widget. |
|
5019 |
|
5020 \note This function will apply the effect on itself and all its children. |
|
5021 |
|
5022 \since 4.6 |
|
5023 |
|
5024 \sa graphicsEffect() |
|
5025 */ |
|
5026 void QWidget::setGraphicsEffect(QGraphicsEffect *effect) |
|
5027 { |
|
5028 Q_D(QWidget); |
|
5029 if (d->graphicsEffect == effect) |
|
5030 return; |
|
5031 |
|
5032 if (d->graphicsEffect && effect) { |
|
5033 delete d->graphicsEffect; |
|
5034 d->graphicsEffect = 0; |
|
5035 } |
|
5036 |
|
5037 if (!effect) { |
|
5038 // Unset current effect. |
|
5039 QGraphicsEffectPrivate *oldEffectPrivate = d->graphicsEffect->d_func(); |
|
5040 d->graphicsEffect = 0; |
|
5041 if (oldEffectPrivate) { |
|
5042 oldEffectPrivate->setGraphicsEffectSource(0); // deletes the current source. |
|
5043 } |
|
5044 } else { |
|
5045 // Set new effect. |
|
5046 QGraphicsEffectSourcePrivate *sourced = new QWidgetEffectSourcePrivate(this); |
|
5047 QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced); |
|
5048 d->graphicsEffect = effect; |
|
5049 effect->d_func()->setGraphicsEffectSource(source); |
|
5050 } |
|
5051 |
|
5052 d->updateIsOpaque(); |
|
5053 update(); |
|
5054 } |
|
5055 |
|
5056 bool QWidgetPrivate::isAboutToShow() const |
|
5057 { |
|
5058 if (data.in_show) |
|
5059 return true; |
|
5060 |
|
5061 Q_Q(const QWidget); |
|
5062 if (q->isHidden()) |
|
5063 return false; |
|
5064 |
|
5065 // The widget will be shown if any of its ancestors are about to show. |
|
5066 QWidget *parent = q->parentWidget(); |
|
5067 return parent ? parent->d_func()->isAboutToShow() : false; |
|
5068 } |
|
5069 |
|
5070 QRegion QWidgetPrivate::prepareToRender(const QRegion ®ion, QWidget::RenderFlags renderFlags) |
|
5071 { |
|
5072 Q_Q(QWidget); |
|
5073 const bool isVisible = q->isVisible(); |
|
5074 |
|
5075 // Make sure the widget is laid out correctly. |
|
5076 if (!isVisible && !isAboutToShow()) { |
|
5077 QWidget *topLevel = q->window(); |
|
5078 (void)topLevel->d_func()->topData(); // Make sure we at least have top-data. |
|
5079 topLevel->ensurePolished(); |
|
5080 |
|
5081 // Invalidate the layout of hidden ancestors (incl. myself) and pretend |
|
5082 // they're not explicitly hidden. |
|
5083 QWidget *widget = q; |
|
5084 QWidgetList hiddenWidgets; |
|
5085 while (widget) { |
|
5086 if (widget->isHidden()) { |
|
5087 widget->setAttribute(Qt::WA_WState_Hidden, false); |
|
5088 hiddenWidgets.append(widget); |
|
5089 if (!widget->isWindow() && widget->parentWidget()->d_func()->layout) |
|
5090 widget->d_func()->updateGeometry_helper(true); |
|
5091 } |
|
5092 widget = widget->parentWidget(); |
|
5093 } |
|
5094 |
|
5095 // Activate top-level layout. |
|
5096 if (topLevel->d_func()->layout) |
|
5097 topLevel->d_func()->layout->activate(); |
|
5098 |
|
5099 // Adjust size if necessary. |
|
5100 QTLWExtra *topLevelExtra = topLevel->d_func()->maybeTopData(); |
|
5101 if (topLevelExtra && !topLevelExtra->sizeAdjusted |
|
5102 && !topLevel->testAttribute(Qt::WA_Resized)) { |
|
5103 topLevel->adjustSize(); |
|
5104 topLevel->setAttribute(Qt::WA_Resized, false); |
|
5105 } |
|
5106 |
|
5107 // Activate child layouts. |
|
5108 topLevel->d_func()->activateChildLayoutsRecursively(); |
|
5109 |
|
5110 // We're not cheating with WA_WState_Hidden anymore. |
|
5111 for (int i = 0; i < hiddenWidgets.size(); ++i) { |
|
5112 QWidget *widget = hiddenWidgets.at(i); |
|
5113 widget->setAttribute(Qt::WA_WState_Hidden); |
|
5114 if (!widget->isWindow() && widget->parentWidget()->d_func()->layout) |
|
5115 widget->parentWidget()->d_func()->layout->invalidate(); |
|
5116 } |
|
5117 } else if (isVisible) { |
|
5118 q->window()->d_func()->sendPendingMoveAndResizeEvents(true, true); |
|
5119 } |
|
5120 |
|
5121 // Calculate the region to be painted. |
|
5122 QRegion toBePainted = !region.isEmpty() ? region : QRegion(q->rect()); |
|
5123 if (!(renderFlags & QWidget::IgnoreMask) && extra && extra->hasMask) |
|
5124 toBePainted &= extra->mask; |
|
5125 return toBePainted; |
|
5126 } |
|
5127 |
|
5128 void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &toBePainted, |
|
5129 QWidget::RenderFlags renderFlags) |
|
5130 { |
|
5131 Q_ASSERT(painter); |
|
5132 Q_ASSERT(!toBePainted.isEmpty()); |
|
5133 |
|
5134 Q_Q(QWidget); |
|
5135 #ifndef Q_WS_MAC |
|
5136 const QTransform originalTransform = painter->worldTransform(); |
|
5137 const bool useDeviceCoordinates = originalTransform.isScaling(); |
|
5138 if (!useDeviceCoordinates) { |
|
5139 #endif |
|
5140 // Render via a pixmap. |
|
5141 const QRect rect = toBePainted.boundingRect(); |
|
5142 const QSize size = rect.size(); |
|
5143 if (size.isNull()) |
|
5144 return; |
|
5145 |
|
5146 QPixmap pixmap(size); |
|
5147 if (!(renderFlags & QWidget::DrawWindowBackground) |
|
5148 || !q->palette().brush(q->backgroundRole()).isOpaque()) |
|
5149 pixmap.fill(Qt::transparent); |
|
5150 q->render(&pixmap, QPoint(), toBePainted, renderFlags); |
|
5151 |
|
5152 const bool restore = !(painter->renderHints() & QPainter::SmoothPixmapTransform); |
|
5153 painter->setRenderHints(QPainter::SmoothPixmapTransform, true); |
|
5154 |
|
5155 painter->drawPixmap(targetOffset, pixmap); |
|
5156 |
|
5157 if (restore) |
|
5158 painter->setRenderHints(QPainter::SmoothPixmapTransform, false); |
|
5159 |
|
5160 #ifndef Q_WS_MAC |
|
5161 } else { |
|
5162 // Render via a pixmap in device coordinates (to avoid pixmap scaling). |
|
5163 QTransform transform = originalTransform; |
|
5164 transform.translate(targetOffset.x(), targetOffset.y()); |
|
5165 |
|
5166 QPaintDevice *device = painter->device(); |
|
5167 Q_ASSERT(device); |
|
5168 |
|
5169 // Calculate device rect. |
|
5170 const QRectF rect(toBePainted.boundingRect()); |
|
5171 QRect deviceRect = transform.mapRect(QRectF(0, 0, rect.width(), rect.height())).toAlignedRect(); |
|
5172 deviceRect &= QRect(0, 0, device->width(), device->height()); |
|
5173 |
|
5174 QPixmap pixmap(deviceRect.size()); |
|
5175 pixmap.fill(Qt::transparent); |
|
5176 |
|
5177 // Create a pixmap device coordinate painter. |
|
5178 QPainter pixmapPainter(&pixmap); |
|
5179 pixmapPainter.setRenderHints(painter->renderHints()); |
|
5180 transform *= QTransform::fromTranslate(-deviceRect.x(), -deviceRect.y()); |
|
5181 pixmapPainter.setTransform(transform); |
|
5182 |
|
5183 q->render(&pixmapPainter, QPoint(), toBePainted, renderFlags); |
|
5184 pixmapPainter.end(); |
|
5185 |
|
5186 // And then draw the pixmap. |
|
5187 painter->setTransform(QTransform()); |
|
5188 painter->drawPixmap(deviceRect.topLeft(), pixmap); |
|
5189 painter->setTransform(originalTransform); |
|
5190 } |
|
5191 #endif |
|
5192 } |
|
5193 |
|
5194 void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, |
|
5195 QPainter *sharedPainter, QWidgetBackingStore *backingStore) |
|
5196 { |
|
5197 if (rgn.isEmpty()) |
|
5198 return; |
|
5199 |
|
5200 Q_Q(QWidget); |
|
5201 if (graphicsEffect && graphicsEffect->isEnabled()) { |
|
5202 QGraphicsEffectSource *source = graphicsEffect->d_func()->source; |
|
5203 QWidgetEffectSourcePrivate *sourced = static_cast<QWidgetEffectSourcePrivate *> |
|
5204 (source->d_func()); |
|
5205 if (!sourced->context) { |
|
5206 QWidgetPaintContext context(pdev, rgn, offset, flags, sharedPainter, backingStore); |
|
5207 sourced->context = &context; |
|
5208 if (!sharedPainter) { |
|
5209 QPaintEngine *paintEngine = pdev->paintEngine(); |
|
5210 paintEngine->d_func()->systemClip = rgn.translated(offset); |
|
5211 QPainter p(pdev); |
|
5212 p.translate(offset); |
|
5213 context.painter = &p; |
|
5214 graphicsEffect->draw(&p, source); |
|
5215 paintEngine->d_func()->systemClip = QRegion(); |
|
5216 } else { |
|
5217 context.painter = sharedPainter; |
|
5218 if (sharedPainter->worldTransform() != sourced->lastEffectTransform) { |
|
5219 sourced->invalidateCache(); |
|
5220 sourced->lastEffectTransform = sharedPainter->worldTransform(); |
|
5221 } |
|
5222 sharedPainter->save(); |
|
5223 sharedPainter->translate(offset); |
|
5224 graphicsEffect->draw(sharedPainter, source); |
|
5225 sharedPainter->restore(); |
|
5226 } |
|
5227 sourced->context = 0; |
|
5228 return; |
|
5229 } |
|
5230 } |
|
5231 |
|
5232 const bool asRoot = flags & DrawAsRoot; |
|
5233 const bool alsoOnScreen = flags & DrawPaintOnScreen; |
|
5234 const bool recursive = flags & DrawRecursive; |
|
5235 const bool alsoInvisible = flags & DrawInvisible; |
|
5236 |
|
5237 Q_ASSERT(sharedPainter ? sharedPainter->isActive() : true); |
|
5238 |
|
5239 QRegion toBePainted(rgn); |
|
5240 if (asRoot && !alsoInvisible) |
|
5241 toBePainted &= clipRect(); //(rgn & visibleRegion()); |
|
5242 if (!(flags & DontSubtractOpaqueChildren)) |
|
5243 subtractOpaqueChildren(toBePainted, q->rect()); |
|
5244 |
|
5245 if (!toBePainted.isEmpty()) { |
|
5246 bool onScreen = paintOnScreen(); |
|
5247 if (!onScreen || alsoOnScreen) { |
|
5248 //update the "in paint event" flag |
|
5249 if (q->testAttribute(Qt::WA_WState_InPaintEvent)) |
|
5250 qWarning("QWidget::repaint: Recursive repaint detected"); |
|
5251 q->setAttribute(Qt::WA_WState_InPaintEvent); |
|
5252 |
|
5253 //clip away the new area |
|
5254 #ifndef QT_NO_PAINT_DEBUG |
|
5255 bool flushed = QWidgetBackingStore::flushPaint(q, toBePainted); |
|
5256 #endif |
|
5257 QPaintEngine *paintEngine = pdev->paintEngine(); |
|
5258 if (paintEngine) { |
|
5259 setRedirected(pdev, -offset); |
|
5260 |
|
5261 if (sharedPainter) |
|
5262 paintEngine->d_func()->systemClip = toBePainted; |
|
5263 else |
|
5264 paintEngine->d_func()->systemRect = q->data->crect; |
|
5265 |
|
5266 //paint the background |
|
5267 if ((asRoot || q->autoFillBackground() || onScreen || q->testAttribute(Qt::WA_StyledBackground)) |
|
5268 && !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) { |
|
5269 |
|
5270 QPainter p(q); |
|
5271 paintBackground(&p, toBePainted, (asRoot || onScreen) ? flags | DrawAsRoot : 0); |
|
5272 } |
|
5273 |
|
5274 if (!sharedPainter) |
|
5275 paintEngine->d_func()->systemClip = toBePainted.translated(offset); |
|
5276 |
|
5277 if (!onScreen && !asRoot && !isOpaque && q->testAttribute(Qt::WA_TintedBackground)) { |
|
5278 QPainter p(q); |
|
5279 QColor tint = q->palette().window().color(); |
|
5280 tint.setAlphaF(qreal(.6)); |
|
5281 p.fillRect(toBePainted.boundingRect(), tint); |
|
5282 } |
|
5283 } |
|
5284 |
|
5285 #if 0 |
|
5286 qDebug() << "painting" << q << "opaque ==" << isOpaque(); |
|
5287 qDebug() << "clipping to" << toBePainted << "location == " << offset |
|
5288 << "geometry ==" << QRect(q->mapTo(q->window(), QPoint(0, 0)), q->size()); |
|
5289 #endif |
|
5290 |
|
5291 //actually send the paint event |
|
5292 QPaintEvent e(toBePainted); |
|
5293 QCoreApplication::sendSpontaneousEvent(q, &e); |
|
5294 #if !defined(Q_WS_MAC) && !defined(Q_WS_QWS) |
|
5295 if (backingStore && !onScreen && !asRoot && (q->internalWinId() || !q->nativeParentWidget()->isWindow())) |
|
5296 backingStore->markDirtyOnScreen(toBePainted, q, offset); |
|
5297 #endif |
|
5298 |
|
5299 //restore |
|
5300 if (paintEngine) { |
|
5301 restoreRedirected(); |
|
5302 if (!sharedPainter) |
|
5303 paintEngine->d_func()->systemRect = QRect(); |
|
5304 else |
|
5305 paintEngine->d_func()->currentClipWidget = 0; |
|
5306 paintEngine->d_func()->systemClip = QRegion(); |
|
5307 } |
|
5308 q->setAttribute(Qt::WA_WState_InPaintEvent, false); |
|
5309 if (q->paintingActive() && !q->testAttribute(Qt::WA_PaintOutsidePaintEvent)) |
|
5310 qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent"); |
|
5311 |
|
5312 if (paintEngine && paintEngine->autoDestruct()) { |
|
5313 delete paintEngine; |
|
5314 } |
|
5315 |
|
5316 #ifndef QT_NO_PAINT_DEBUG |
|
5317 if (flushed) |
|
5318 QWidgetBackingStore::unflushPaint(q, toBePainted); |
|
5319 #endif |
|
5320 } else if (q->isWindow()) { |
|
5321 QPaintEngine *engine = pdev->paintEngine(); |
|
5322 if (engine) { |
|
5323 QPainter p(pdev); |
|
5324 p.setClipRegion(toBePainted); |
|
5325 const QBrush bg = q->palette().brush(QPalette::Window); |
|
5326 if (bg.style() == Qt::TexturePattern) |
|
5327 p.drawTiledPixmap(q->rect(), bg.texture()); |
|
5328 else |
|
5329 p.fillRect(q->rect(), bg); |
|
5330 |
|
5331 if (engine->autoDestruct()) |
|
5332 delete engine; |
|
5333 } |
|
5334 } |
|
5335 } |
|
5336 |
|
5337 if (recursive && !children.isEmpty()) { |
|
5338 paintSiblingsRecursive(pdev, children, children.size() - 1, rgn, offset, flags & ~DrawAsRoot |
|
5339 #ifdef Q_BACKINGSTORE_SUBSURFACES |
|
5340 , q->windowSurface() |
|
5341 #endif |
|
5342 , sharedPainter, backingStore); |
|
5343 } |
|
5344 } |
|
5345 |
|
5346 void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn, |
|
5347 const QPoint &offset, int flags |
|
5348 #ifdef Q_BACKINGSTORE_SUBSURFACES |
|
5349 , const QWindowSurface *currentSurface |
|
5350 #endif |
|
5351 , QPainter *sharedPainter, QWidgetBackingStore *backingStore) |
|
5352 { |
|
5353 QWidget *w = 0; |
|
5354 QRect boundingRect; |
|
5355 bool dirtyBoundingRect = true; |
|
5356 const bool exludeOpaqueChildren = (flags & DontDrawOpaqueChildren); |
|
5357 |
|
5358 do { |
|
5359 QWidget *x = qobject_cast<QWidget*>(siblings.at(index)); |
|
5360 if (x && !(exludeOpaqueChildren && x->d_func()->isOpaque) && !x->isHidden() && !x->isWindow()) { |
|
5361 if (dirtyBoundingRect) { |
|
5362 boundingRect = rgn.boundingRect(); |
|
5363 dirtyBoundingRect = false; |
|
5364 } |
|
5365 |
|
5366 if (qRectIntersects(boundingRect, x->d_func()->effectiveRectFor(x->data->crect))) { |
|
5367 #ifdef Q_BACKINGSTORE_SUBSURFACES |
|
5368 if (x->windowSurface() == currentSurface) |
|
5369 #endif |
|
5370 { |
|
5371 w = x; |
|
5372 break; |
|
5373 } |
|
5374 } |
|
5375 } |
|
5376 --index; |
|
5377 } while (index >= 0); |
|
5378 |
|
5379 if (!w) |
|
5380 return; |
|
5381 |
|
5382 QWidgetPrivate *wd = w->d_func(); |
|
5383 const QPoint widgetPos(w->data->crect.topLeft()); |
|
5384 const bool hasMask = wd->extra && wd->extra->hasMask && !wd->graphicsEffect; |
|
5385 |
|
5386 if (index > 0) { |
|
5387 QRegion wr(rgn); |
|
5388 if (wd->isOpaque) |
|
5389 wr -= hasMask ? wd->extra->mask.translated(widgetPos) : w->data->crect; |
|
5390 paintSiblingsRecursive(pdev, siblings, --index, wr, offset, flags |
|
5391 #ifdef Q_BACKINGSTORE_SUBSURFACES |
|
5392 , currentSurface |
|
5393 #endif |
|
5394 , sharedPainter, backingStore); |
|
5395 } |
|
5396 |
|
5397 if (w->updatesEnabled() && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget)) { |
|
5398 QRegion wRegion(rgn); |
|
5399 wRegion &= wd->effectiveRectFor(w->data->crect); |
|
5400 wRegion.translate(-widgetPos); |
|
5401 if (hasMask) |
|
5402 wRegion &= wd->extra->mask; |
|
5403 wd->drawWidget(pdev, wRegion, offset + widgetPos, flags, sharedPainter, backingStore); |
|
5404 } |
|
5405 } |
|
5406 |
|
5407 QRectF QWidgetEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const |
|
5408 { |
|
5409 if (system != Qt::DeviceCoordinates) |
|
5410 return m_widget->rect(); |
|
5411 |
|
5412 if (!context) { |
|
5413 // Device coordinates without context not yet supported. |
|
5414 qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context"); |
|
5415 return QRectF(); |
|
5416 } |
|
5417 |
|
5418 return context->painter->worldTransform().mapRect(m_widget->rect()); |
|
5419 } |
|
5420 |
|
5421 void QWidgetEffectSourcePrivate::draw(QPainter *painter) |
|
5422 { |
|
5423 if (!context || context->painter != painter) { |
|
5424 m_widget->render(painter); |
|
5425 return; |
|
5426 } |
|
5427 |
|
5428 // The region saved in the context is neither clipped to the rect |
|
5429 // nor the mask, so we have to clip it here before calling drawWidget. |
|
5430 QRegion toBePainted = context->rgn; |
|
5431 toBePainted &= m_widget->rect(); |
|
5432 QWidgetPrivate *wd = qt_widget_private(m_widget); |
|
5433 if (wd->extra && wd->extra->hasMask) |
|
5434 toBePainted &= wd->extra->mask; |
|
5435 |
|
5436 wd->drawWidget(context->pdev, toBePainted, context->offset, context->flags, |
|
5437 context->sharedPainter, context->backingStore); |
|
5438 } |
|
5439 |
|
5440 QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset) const |
|
5441 { |
|
5442 const bool deviceCoordinates = (system == Qt::DeviceCoordinates); |
|
5443 if (!context && deviceCoordinates) { |
|
5444 // Device coordinates without context not yet supported. |
|
5445 qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context"); |
|
5446 return QPixmap(); |
|
5447 } |
|
5448 |
|
5449 QPoint pixmapOffset; |
|
5450 QRectF sourceRect = m_widget->rect(); |
|
5451 |
|
5452 if (deviceCoordinates) { |
|
5453 const QTransform &painterTransform = context->painter->worldTransform(); |
|
5454 sourceRect = painterTransform.mapRect(sourceRect); |
|
5455 pixmapOffset = painterTransform.map(pixmapOffset); |
|
5456 } |
|
5457 |
|
5458 QRect effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect(); |
|
5459 if (offset) |
|
5460 *offset = effectRect.topLeft(); |
|
5461 |
|
5462 if (deviceCoordinates) { |
|
5463 // Clip to device rect. |
|
5464 int left, top, right, bottom; |
|
5465 effectRect.getCoords(&left, &top, &right, &bottom); |
|
5466 if (left < 0) { |
|
5467 if (offset) |
|
5468 offset->rx() += -left; |
|
5469 effectRect.setX(0); |
|
5470 } |
|
5471 if (top < 0) { |
|
5472 if (offset) |
|
5473 offset->ry() += -top; |
|
5474 effectRect.setY(0); |
|
5475 } |
|
5476 // NB! We use +-1 for historical reasons (see QRect documentation). |
|
5477 QPaintDevice *device = context->painter->device(); |
|
5478 const int deviceWidth = device->width(); |
|
5479 const int deviceHeight = device->height(); |
|
5480 if (right + 1 > deviceWidth) |
|
5481 effectRect.setRight(deviceWidth - 1); |
|
5482 if (bottom + 1 > deviceHeight) |
|
5483 effectRect.setBottom(deviceHeight -1); |
|
5484 } |
|
5485 |
|
5486 pixmapOffset -= effectRect.topLeft(); |
|
5487 |
|
5488 QPixmap pixmap(effectRect.size()); |
|
5489 pixmap.fill(Qt::transparent); |
|
5490 m_widget->render(&pixmap, pixmapOffset); |
|
5491 return pixmap; |
|
5492 } |
|
5493 |
|
5494 #ifndef QT_NO_GRAPHICSVIEW |
|
5495 /*! |
|
5496 \internal |
|
5497 |
|
5498 Finds the nearest widget embedded in a graphics proxy widget along the chain formed by this |
|
5499 widget and its ancestors. The search starts at \a origin (inclusive). |
|
5500 If successful, the function returns the proxy that embeds the widget, or 0 if no embedded |
|
5501 widget was found. |
|
5502 */ |
|
5503 QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin) |
|
5504 { |
|
5505 if (origin) { |
|
5506 QWExtra *extra = origin->d_func()->extra; |
|
5507 if (extra && extra->proxyWidget) |
|
5508 return extra->proxyWidget; |
|
5509 return nearestGraphicsProxyWidget(origin->parentWidget()); |
|
5510 } |
|
5511 return 0; |
|
5512 } |
|
5513 #endif |
|
5514 |
|
5515 /*! |
|
5516 \property QWidget::locale |
|
5517 \brief the widget's locale |
|
5518 \since 4.3 |
|
5519 |
|
5520 As long as no special locale has been set, this is either |
|
5521 the parent's locale or (if this widget is a top level widget), |
|
5522 the default locale. |
|
5523 |
|
5524 If the widget displays dates or numbers, these should be formatted |
|
5525 using the widget's locale. |
|
5526 |
|
5527 \sa QLocale QLocale::setDefault() |
|
5528 */ |
|
5529 |
|
5530 void QWidgetPrivate::setLocale_helper(const QLocale &loc, bool forceUpdate) |
|
5531 { |
|
5532 Q_Q(QWidget); |
|
5533 if (locale == loc && !forceUpdate) |
|
5534 return; |
|
5535 |
|
5536 locale = loc; |
|
5537 |
|
5538 if (!children.isEmpty()) { |
|
5539 for (int i = 0; i < children.size(); ++i) { |
|
5540 QWidget *w = qobject_cast<QWidget*>(children.at(i)); |
|
5541 if (!w) |
|
5542 continue; |
|
5543 if (w->testAttribute(Qt::WA_SetLocale)) |
|
5544 continue; |
|
5545 if (w->isWindow() && !w->testAttribute(Qt::WA_WindowPropagation)) |
|
5546 continue; |
|
5547 w->d_func()->setLocale_helper(loc, forceUpdate); |
|
5548 } |
|
5549 } |
|
5550 QEvent e(QEvent::LocaleChange); |
|
5551 QApplication::sendEvent(q, &e); |
|
5552 } |
|
5553 |
|
5554 void QWidget::setLocale(const QLocale &locale) |
|
5555 { |
|
5556 Q_D(QWidget); |
|
5557 |
|
5558 setAttribute(Qt::WA_SetLocale); |
|
5559 d->setLocale_helper(locale); |
|
5560 } |
|
5561 |
|
5562 QLocale QWidget::locale() const |
|
5563 { |
|
5564 Q_D(const QWidget); |
|
5565 |
|
5566 return d->locale; |
|
5567 } |
|
5568 |
|
5569 void QWidgetPrivate::resolveLocale() |
|
5570 { |
|
5571 Q_Q(const QWidget); |
|
5572 |
|
5573 if (!q->testAttribute(Qt::WA_SetLocale)) { |
|
5574 setLocale_helper(q->isWindow() |
|
5575 ? QLocale() |
|
5576 : q->parentWidget()->locale()); |
|
5577 } |
|
5578 } |
|
5579 |
|
5580 void QWidget::unsetLocale() |
|
5581 { |
|
5582 Q_D(QWidget); |
|
5583 setAttribute(Qt::WA_SetLocale, false); |
|
5584 d->resolveLocale(); |
|
5585 } |
|
5586 |
|
5587 static QString constructWindowTitleFromFilePath(const QString &filePath) |
|
5588 { |
|
5589 QFileInfo fi(filePath); |
|
5590 QString windowTitle = fi.fileName() + QLatin1String("[*]"); |
|
5591 #ifndef Q_WS_MAC |
|
5592 QString appName = QApplication::applicationName(); |
|
5593 if (!appName.isEmpty()) |
|
5594 windowTitle += QLatin1Char(' ') + QChar(0x2014) + QLatin1Char(' ') + appName; |
|
5595 #endif |
|
5596 return windowTitle; |
|
5597 } |
|
5598 |
|
5599 /*! |
|
5600 \property QWidget::windowTitle |
|
5601 \brief the window title (caption) |
|
5602 |
|
5603 This property only makes sense for top-level widgets, such as |
|
5604 windows and dialogs. If no caption has been set, the title is based of the |
|
5605 \l windowFilePath. If neither of these is set, then the title is |
|
5606 an empty string. |
|
5607 |
|
5608 If you use the \l windowModified mechanism, the window title must |
|
5609 contain a "[*]" placeholder, which indicates where the '*' should |
|
5610 appear. Normally, it should appear right after the file name |
|
5611 (e.g., "document1.txt[*] - Text Editor"). If the \l |
|
5612 windowModified property is false (the default), the placeholder |
|
5613 is simply removed. |
|
5614 |
|
5615 \sa windowIcon, windowIconText, windowModified, windowFilePath |
|
5616 */ |
|
5617 QString QWidget::windowTitle() const |
|
5618 { |
|
5619 Q_D(const QWidget); |
|
5620 if (d->extra && d->extra->topextra) { |
|
5621 if (!d->extra->topextra->caption.isEmpty()) |
|
5622 return d->extra->topextra->caption; |
|
5623 if (!d->extra->topextra->filePath.isEmpty()) |
|
5624 return constructWindowTitleFromFilePath(d->extra->topextra->filePath); |
|
5625 } |
|
5626 return QString(); |
|
5627 } |
|
5628 |
|
5629 /*! |
|
5630 Returns a modified window title with the [*] place holder |
|
5631 replaced according to the rules described in QWidget::setWindowTitle |
|
5632 |
|
5633 This function assumes that "[*]" can be quoted by another |
|
5634 "[*]", so it will replace two place holders by one and |
|
5635 a single last one by either "*" or nothing depending on |
|
5636 the modified flag. |
|
5637 |
|
5638 \internal |
|
5639 */ |
|
5640 QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widget) |
|
5641 { |
|
5642 Q_ASSERT(widget); |
|
5643 |
|
5644 #ifdef QT_EVAL |
|
5645 extern QString qt_eval_adapt_window_title(const QString &title); |
|
5646 QString cap = qt_eval_adapt_window_title(title); |
|
5647 #else |
|
5648 QString cap = title; |
|
5649 #endif |
|
5650 |
|
5651 if (cap.isEmpty()) |
|
5652 return cap; |
|
5653 |
|
5654 QLatin1String placeHolder("[*]"); |
|
5655 int placeHolderLength = 3; // QLatin1String doesn't have length() |
|
5656 |
|
5657 int index = cap.indexOf(placeHolder); |
|
5658 |
|
5659 // here the magic begins |
|
5660 while (index != -1) { |
|
5661 index += placeHolderLength; |
|
5662 int count = 1; |
|
5663 while (cap.indexOf(placeHolder, index) == index) { |
|
5664 ++count; |
|
5665 index += placeHolderLength; |
|
5666 } |
|
5667 |
|
5668 if (count%2) { // odd number of [*] -> replace last one |
|
5669 int lastIndex = cap.lastIndexOf(placeHolder, index - 1); |
|
5670 if (widget->isWindowModified() |
|
5671 && widget->style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, widget)) |
|
5672 cap.replace(lastIndex, 3, QWidget::tr("*")); |
|
5673 else |
|
5674 cap.remove(lastIndex, 3); |
|
5675 } |
|
5676 |
|
5677 index = cap.indexOf(placeHolder, index); |
|
5678 } |
|
5679 |
|
5680 cap.replace(QLatin1String("[*][*]"), placeHolder); |
|
5681 |
|
5682 return cap; |
|
5683 } |
|
5684 |
|
5685 void QWidgetPrivate::setWindowTitle_helper(const QString &title) |
|
5686 { |
|
5687 Q_Q(QWidget); |
|
5688 if (q->testAttribute(Qt::WA_WState_Created)) |
|
5689 setWindowTitle_sys(qt_setWindowTitle_helperHelper(title, q)); |
|
5690 } |
|
5691 |
|
5692 void QWidgetPrivate::setWindowIconText_helper(const QString &title) |
|
5693 { |
|
5694 Q_Q(QWidget); |
|
5695 if (q->testAttribute(Qt::WA_WState_Created)) |
|
5696 setWindowIconText_sys(qt_setWindowTitle_helperHelper(title, q)); |
|
5697 } |
|
5698 |
|
5699 void QWidget::setWindowIconText(const QString &iconText) |
|
5700 { |
|
5701 if (QWidget::windowIconText() == iconText) |
|
5702 return; |
|
5703 |
|
5704 Q_D(QWidget); |
|
5705 d->topData()->iconText = iconText; |
|
5706 d->setWindowIconText_helper(iconText); |
|
5707 |
|
5708 QEvent e(QEvent::IconTextChange); |
|
5709 QApplication::sendEvent(this, &e); |
|
5710 } |
|
5711 |
|
5712 void QWidget::setWindowTitle(const QString &title) |
|
5713 { |
|
5714 if (QWidget::windowTitle() == title && !title.isEmpty() && !title.isNull()) |
|
5715 return; |
|
5716 |
|
5717 Q_D(QWidget); |
|
5718 d->topData()->caption = title; |
|
5719 d->setWindowTitle_helper(title); |
|
5720 |
|
5721 QEvent e(QEvent::WindowTitleChange); |
|
5722 QApplication::sendEvent(this, &e); |
|
5723 } |
|
5724 |
|
5725 |
|
5726 /*! |
|
5727 \property QWidget::windowIcon |
|
5728 \brief the widget's icon |
|
5729 |
|
5730 This property only makes sense for windows. If no icon |
|
5731 has been set, windowIcon() returns the application icon |
|
5732 (QApplication::windowIcon()). |
|
5733 |
|
5734 \sa windowIconText, windowTitle |
|
5735 */ |
|
5736 QIcon QWidget::windowIcon() const |
|
5737 { |
|
5738 const QWidget *w = this; |
|
5739 while (w) { |
|
5740 const QWidgetPrivate *d = w->d_func(); |
|
5741 if (d->extra && d->extra->topextra && d->extra->topextra->icon) |
|
5742 return *d->extra->topextra->icon; |
|
5743 w = w->parentWidget(); |
|
5744 } |
|
5745 return QApplication::windowIcon(); |
|
5746 } |
|
5747 |
|
5748 void QWidgetPrivate::setWindowIcon_helper() |
|
5749 { |
|
5750 QEvent e(QEvent::WindowIconChange); |
|
5751 QApplication::sendEvent(q_func(), &e); |
|
5752 for (int i = 0; i < children.size(); ++i) { |
|
5753 QWidget *w = qobject_cast<QWidget *>(children.at(i)); |
|
5754 if (w && !w->isWindow()) |
|
5755 QApplication::sendEvent(w, &e); |
|
5756 } |
|
5757 } |
|
5758 |
|
5759 void QWidget::setWindowIcon(const QIcon &icon) |
|
5760 { |
|
5761 Q_D(QWidget); |
|
5762 |
|
5763 setAttribute(Qt::WA_SetWindowIcon, !icon.isNull()); |
|
5764 d->createTLExtra(); |
|
5765 |
|
5766 if (!d->extra->topextra->icon) |
|
5767 d->extra->topextra->icon = new QIcon(); |
|
5768 *d->extra->topextra->icon = icon; |
|
5769 |
|
5770 delete d->extra->topextra->iconPixmap; |
|
5771 d->extra->topextra->iconPixmap = 0; |
|
5772 |
|
5773 d->setWindowIcon_sys(); |
|
5774 d->setWindowIcon_helper(); |
|
5775 } |
|
5776 |
|
5777 |
|
5778 /*! |
|
5779 \property QWidget::windowIconText |
|
5780 \brief the widget's icon text |
|
5781 |
|
5782 This property only makes sense for windows. If no icon |
|
5783 text has been set, this functions returns an empty string. |
|
5784 |
|
5785 \sa windowIcon, windowTitle |
|
5786 */ |
|
5787 |
|
5788 QString QWidget::windowIconText() const |
|
5789 { |
|
5790 Q_D(const QWidget); |
|
5791 return (d->extra && d->extra->topextra) ? d->extra->topextra->iconText : QString(); |
|
5792 } |
|
5793 |
|
5794 /*! |
|
5795 \property QWidget::windowFilePath |
|
5796 \since 4.4 |
|
5797 \brief the file path associated with a widget |
|
5798 |
|
5799 This property only makes sense for windows. It associates a file path with |
|
5800 a window. If you set the file path, but have not set the window title, Qt |
|
5801 sets the window title to contain a string created using the following |
|
5802 components. |
|
5803 |
|
5804 On Mac OS X: |
|
5805 |
|
5806 \list |
|
5807 \o The file name of the specified path, obtained using QFileInfo::fileName(). |
|
5808 \endlist |
|
5809 |
|
5810 On Windows and X11: |
|
5811 |
|
5812 \list |
|
5813 \o The file name of the specified path, obtained using QFileInfo::fileName(). |
|
5814 \o An optional \c{*} character, if the \l windowModified property is set. |
|
5815 \o The \c{0x2014} unicode character, padded either side by spaces. |
|
5816 \o The application name, obtained from the application's |
|
5817 \l{QCoreApplication::}{applicationName} property. |
|
5818 \endlist |
|
5819 |
|
5820 If the window title is set at any point, then the window title takes precedence and |
|
5821 will be shown instead of the file path string. |
|
5822 |
|
5823 Additionally, on Mac OS X, this has an added benefit that it sets the |
|
5824 \l{http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGWindows/chapter_17_section_3.html}{proxy icon} |
|
5825 for the window, assuming that the file path exists. |
|
5826 |
|
5827 If no file path is set, this property contains an empty string. |
|
5828 |
|
5829 By default, this property contains an empty string. |
|
5830 |
|
5831 \sa windowTitle, windowIcon |
|
5832 */ |
|
5833 |
|
5834 QString QWidget::windowFilePath() const |
|
5835 { |
|
5836 Q_D(const QWidget); |
|
5837 return (d->extra && d->extra->topextra) ? d->extra->topextra->filePath : QString(); |
|
5838 } |
|
5839 |
|
5840 void QWidget::setWindowFilePath(const QString &filePath) |
|
5841 { |
|
5842 if (filePath == windowFilePath()) |
|
5843 return; |
|
5844 |
|
5845 Q_D(QWidget); |
|
5846 |
|
5847 d->createTLExtra(); |
|
5848 d->extra->topextra->filePath = filePath; |
|
5849 d->setWindowFilePath_helper(filePath); |
|
5850 } |
|
5851 |
|
5852 void QWidgetPrivate::setWindowFilePath_helper(const QString &filePath) |
|
5853 { |
|
5854 if (extra->topextra && extra->topextra->caption.isEmpty()) { |
|
5855 #ifdef Q_WS_MAC |
|
5856 setWindowTitle_helper(QFileInfo(filePath).fileName()); |
|
5857 #else |
|
5858 Q_Q(QWidget); |
|
5859 Q_UNUSED(filePath); |
|
5860 setWindowTitle_helper(q->windowTitle()); |
|
5861 #endif |
|
5862 } |
|
5863 #ifdef Q_WS_MAC |
|
5864 setWindowFilePath_sys(filePath); |
|
5865 #endif |
|
5866 } |
|
5867 |
|
5868 /*! |
|
5869 Returns the window's role, or an empty string. |
|
5870 |
|
5871 \sa windowIcon, windowTitle |
|
5872 */ |
|
5873 |
|
5874 QString QWidget::windowRole() const |
|
5875 { |
|
5876 Q_D(const QWidget); |
|
5877 return (d->extra && d->extra->topextra) ? d->extra->topextra->role : QString(); |
|
5878 } |
|
5879 |
|
5880 /*! |
|
5881 Sets the window's role to \a role. This only makes sense for |
|
5882 windows on X11. |
|
5883 */ |
|
5884 void QWidget::setWindowRole(const QString &role) |
|
5885 { |
|
5886 #if defined(Q_WS_X11) |
|
5887 Q_D(QWidget); |
|
5888 d->topData()->role = role; |
|
5889 d->setWindowRole(); |
|
5890 #else |
|
5891 Q_UNUSED(role) |
|
5892 #endif |
|
5893 } |
|
5894 |
|
5895 /*! |
|
5896 \property QWidget::mouseTracking |
|
5897 \brief whether mouse tracking is enabled for the widget |
|
5898 |
|
5899 If mouse tracking is disabled (the default), the widget only |
|
5900 receives mouse move events when at least one mouse button is |
|
5901 pressed while the mouse is being moved. |
|
5902 |
|
5903 If mouse tracking is enabled, the widget receives mouse move |
|
5904 events even if no buttons are pressed. |
|
5905 |
|
5906 \sa mouseMoveEvent() |
|
5907 */ |
|
5908 |
|
5909 |
|
5910 /*! |
|
5911 Sets the widget's focus proxy to widget \a w. If \a w is 0, the |
|
5912 function resets this widget to have no focus proxy. |
|
5913 |
|
5914 Some widgets can "have focus", but create a child widget, such as |
|
5915 QLineEdit, to actually handle the focus. In this case, the widget |
|
5916 can set the line edit to be its focus proxy. |
|
5917 |
|
5918 setFocusProxy() sets the widget which will actually get focus when |
|
5919 "this widget" gets it. If there is a focus proxy, setFocus() and |
|
5920 hasFocus() operate on the focus proxy. |
|
5921 |
|
5922 \sa focusProxy() |
|
5923 */ |
|
5924 |
|
5925 void QWidget::setFocusProxy(QWidget * w) |
|
5926 { |
|
5927 Q_D(QWidget); |
|
5928 if (!w && !d->extra) |
|
5929 return; |
|
5930 |
|
5931 for (QWidget* fp = w; fp; fp = fp->focusProxy()) { |
|
5932 if (fp == this) { |
|
5933 qWarning("QWidget: %s (%s) already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData()); |
|
5934 return; |
|
5935 } |
|
5936 } |
|
5937 |
|
5938 d->createExtra(); |
|
5939 d->extra->focus_proxy = w; |
|
5940 } |
|
5941 |
|
5942 |
|
5943 /*! |
|
5944 Returns the focus proxy, or 0 if there is no focus proxy. |
|
5945 |
|
5946 \sa setFocusProxy() |
|
5947 */ |
|
5948 |
|
5949 QWidget * QWidget::focusProxy() const |
|
5950 { |
|
5951 Q_D(const QWidget); |
|
5952 return d->extra ? (QWidget *)d->extra->focus_proxy : 0; |
|
5953 } |
|
5954 |
|
5955 |
|
5956 /*! |
|
5957 \property QWidget::focus |
|
5958 \brief whether this widget (or its focus proxy) has the keyboard |
|
5959 input focus |
|
5960 |
|
5961 By default, this property is false. |
|
5962 |
|
5963 \note Obtaining the value of this property for a widget is effectively equivalent |
|
5964 to checking whether QApplication::focusWidget() refers to the widget. |
|
5965 |
|
5966 \sa setFocus(), clearFocus(), setFocusPolicy(), QApplication::focusWidget() |
|
5967 */ |
|
5968 bool QWidget::hasFocus() const |
|
5969 { |
|
5970 const QWidget* w = this; |
|
5971 while (w->d_func()->extra && w->d_func()->extra->focus_proxy) |
|
5972 w = w->d_func()->extra->focus_proxy; |
|
5973 if (QWidget *window = w->window()) { |
|
5974 #ifndef QT_NO_GRAPHICSVIEW |
|
5975 QWExtra *e = window->d_func()->extra; |
|
5976 if (e && e->proxyWidget && e->proxyWidget->hasFocus() && window->focusWidget() == w) |
|
5977 return true; |
|
5978 #endif |
|
5979 } |
|
5980 return (QApplication::focusWidget() == w); |
|
5981 } |
|
5982 |
|
5983 /*! |
|
5984 Gives the keyboard input focus to this widget (or its focus |
|
5985 proxy) if this widget or one of its parents is the \link |
|
5986 isActiveWindow() active window\endlink. The \a reason argument will |
|
5987 be passed into any focus event sent from this function, it is used |
|
5988 to give an explanation of what caused the widget to get focus. |
|
5989 If the window is not active, the widget will be given the focus when |
|
5990 the window becomes active. |
|
5991 |
|
5992 First, a focus out event is sent to the focus widget (if any) to |
|
5993 tell it that it is about to lose the focus. Then a focus in event |
|
5994 is sent to this widget to tell it that it just received the focus. |
|
5995 (Nothing happens if the focus in and focus out widgets are the |
|
5996 same.) |
|
5997 |
|
5998 setFocus() gives focus to a widget regardless of its focus policy, |
|
5999 but does not clear any keyboard grab (see grabKeyboard()). |
|
6000 |
|
6001 Be aware that if the widget is hidden, it will not accept focus |
|
6002 until it is shown. |
|
6003 |
|
6004 \warning If you call setFocus() in a function which may itself be |
|
6005 called from focusOutEvent() or focusInEvent(), you may get an |
|
6006 infinite recursion. |
|
6007 |
|
6008 \sa hasFocus(), clearFocus(), focusInEvent(), focusOutEvent(), |
|
6009 setFocusPolicy(), focusWidget(), QApplication::focusWidget(), grabKeyboard(), |
|
6010 grabMouse(), {Keyboard Focus} |
|
6011 */ |
|
6012 |
|
6013 void QWidget::setFocus(Qt::FocusReason reason) |
|
6014 { |
|
6015 if (!isEnabled()) |
|
6016 return; |
|
6017 |
|
6018 QWidget *f = this; |
|
6019 while (f->d_func()->extra && f->d_func()->extra->focus_proxy) |
|
6020 f = f->d_func()->extra->focus_proxy; |
|
6021 |
|
6022 if (QApplication::focusWidget() == f |
|
6023 #if defined(Q_WS_WIN) |
|
6024 && GetFocus() == f->internalWinId() |
|
6025 #endif |
|
6026 ) |
|
6027 return; |
|
6028 |
|
6029 #ifndef QT_NO_GRAPHICSVIEW |
|
6030 QWidget *previousProxyFocus = 0; |
|
6031 if (QWExtra *topData = window()->d_func()->extra) { |
|
6032 if (topData->proxyWidget && topData->proxyWidget->hasFocus()) { |
|
6033 previousProxyFocus = topData->proxyWidget->widget()->focusWidget(); |
|
6034 if (previousProxyFocus && previousProxyFocus->focusProxy()) |
|
6035 previousProxyFocus = previousProxyFocus->focusProxy(); |
|
6036 } |
|
6037 } |
|
6038 #endif |
|
6039 |
|
6040 QWidget *w = f; |
|
6041 if (isHidden()) { |
|
6042 while (w && w->isHidden()) { |
|
6043 w->d_func()->focus_child = f; |
|
6044 w = w->isWindow() ? 0 : w->parentWidget(); |
|
6045 } |
|
6046 } else { |
|
6047 while (w) { |
|
6048 w->d_func()->focus_child = f; |
|
6049 w = w->isWindow() ? 0 : w->parentWidget(); |
|
6050 } |
|
6051 } |
|
6052 |
|
6053 #ifndef QT_NO_GRAPHICSVIEW |
|
6054 // Update proxy state |
|
6055 if (QWExtra *topData = window()->d_func()->extra) { |
|
6056 if (topData->proxyWidget && !topData->proxyWidget->hasFocus()) { |
|
6057 topData->proxyWidget->d_func()->focusFromWidgetToProxy = 1; |
|
6058 topData->proxyWidget->setFocus(reason); |
|
6059 topData->proxyWidget->d_func()->focusFromWidgetToProxy = 0; |
|
6060 } |
|
6061 } |
|
6062 #endif |
|
6063 |
|
6064 if (f->isActiveWindow()) { |
|
6065 QApplicationPrivate::setFocusWidget(f, reason); |
|
6066 #ifndef QT_NO_ACCESSIBILITY |
|
6067 # ifdef Q_OS_WIN |
|
6068 // The negation of the condition in setFocus_sys |
|
6069 if (!(testAttribute(Qt::WA_WState_Created) && window()->windowType() != Qt::Popup && internalWinId())) |
|
6070 //setFocusWidget will already post a focus event for us (that the AT client receives) on Windows |
|
6071 # endif |
|
6072 QAccessible::updateAccessibility(f, 0, QAccessible::Focus); |
|
6073 #endif |
|
6074 #ifndef QT_NO_GRAPHICSVIEW |
|
6075 if (QWExtra *topData = window()->d_func()->extra) { |
|
6076 if (topData->proxyWidget) { |
|
6077 if (previousProxyFocus && previousProxyFocus != f) { |
|
6078 // Send event to self |
|
6079 QFocusEvent event(QEvent::FocusOut, reason); |
|
6080 QPointer<QWidget> that = previousProxyFocus; |
|
6081 QApplication::sendEvent(previousProxyFocus, &event); |
|
6082 if (that) |
|
6083 QApplication::sendEvent(that->style(), &event); |
|
6084 } |
|
6085 if (!isHidden()) { |
|
6086 // Send event to self |
|
6087 QFocusEvent event(QEvent::FocusIn, reason); |
|
6088 QPointer<QWidget> that = f; |
|
6089 QApplication::sendEvent(f, &event); |
|
6090 if (that) |
|
6091 QApplication::sendEvent(that->style(), &event); |
|
6092 } |
|
6093 } |
|
6094 } |
|
6095 #endif |
|
6096 } |
|
6097 } |
|
6098 |
|
6099 /*! |
|
6100 \fn void QWidget::setFocus() |
|
6101 \overload |
|
6102 |
|
6103 Gives the keyboard input focus to this widget (or its focus |
|
6104 proxy) if this widget or one of its parents is the |
|
6105 \l{isActiveWindow()}{active window}. |
|
6106 */ |
|
6107 |
|
6108 /*! |
|
6109 Takes keyboard input focus from the widget. |
|
6110 |
|
6111 If the widget has active focus, a \link focusOutEvent() focus out |
|
6112 event\endlink is sent to this widget to tell it that it is about |
|
6113 to lose the focus. |
|
6114 |
|
6115 This widget must enable focus setting in order to get the keyboard |
|
6116 input focus, i.e. it must call setFocusPolicy(). |
|
6117 |
|
6118 \sa hasFocus(), setFocus(), focusInEvent(), focusOutEvent(), |
|
6119 setFocusPolicy(), QApplication::focusWidget() |
|
6120 */ |
|
6121 |
|
6122 void QWidget::clearFocus() |
|
6123 { |
|
6124 QWidget *w = this; |
|
6125 while (w) { |
|
6126 if (w->d_func()->focus_child == this) |
|
6127 w->d_func()->focus_child = 0; |
|
6128 w = w->parentWidget(); |
|
6129 } |
|
6130 #ifndef QT_NO_GRAPHICSVIEW |
|
6131 QWExtra *topData = d_func()->extra; |
|
6132 if (topData && topData->proxyWidget) |
|
6133 topData->proxyWidget->clearFocus(); |
|
6134 #endif |
|
6135 |
|
6136 if (hasFocus()) { |
|
6137 // Update proxy state |
|
6138 QApplicationPrivate::setFocusWidget(0, Qt::OtherFocusReason); |
|
6139 #if defined(Q_WS_WIN) |
|
6140 if (!(windowType() == Qt::Popup) && GetFocus() == internalWinId()) |
|
6141 SetFocus(0); |
|
6142 else |
|
6143 #endif |
|
6144 { |
|
6145 #ifndef QT_NO_ACCESSIBILITY |
|
6146 QAccessible::updateAccessibility(this, 0, QAccessible::Focus); |
|
6147 #endif |
|
6148 } |
|
6149 } |
|
6150 } |
|
6151 |
|
6152 |
|
6153 /*! |
|
6154 \fn bool QWidget::focusNextChild() |
|
6155 |
|
6156 Finds a new widget to give the keyboard focus to, as appropriate |
|
6157 for \key Tab, and returns true if it can find a new widget, or |
|
6158 false if it can't. |
|
6159 |
|
6160 \sa focusPreviousChild() |
|
6161 */ |
|
6162 |
|
6163 /*! |
|
6164 \fn bool QWidget::focusPreviousChild() |
|
6165 |
|
6166 Finds a new widget to give the keyboard focus to, as appropriate |
|
6167 for \key Shift+Tab, and returns true if it can find a new widget, |
|
6168 or false if it can't. |
|
6169 |
|
6170 \sa focusNextChild() |
|
6171 */ |
|
6172 |
|
6173 /*! |
|
6174 Finds a new widget to give the keyboard focus to, as appropriate |
|
6175 for Tab and Shift+Tab, and returns true if it can find a new |
|
6176 widget, or false if it can't. |
|
6177 |
|
6178 If \a next is true, this function searches forward, if \a next |
|
6179 is false, it searches backward. |
|
6180 |
|
6181 Sometimes, you will want to reimplement this function. For |
|
6182 example, a web browser might reimplement it to move its "current |
|
6183 active link" forward or backward, and call |
|
6184 focusNextPrevChild() only when it reaches the last or |
|
6185 first link on the "page". |
|
6186 |
|
6187 Child widgets call focusNextPrevChild() on their parent widgets, |
|
6188 but only the window that contains the child widgets decides where |
|
6189 to redirect focus. By reimplementing this function for an object, |
|
6190 you thus gain control of focus traversal for all child widgets. |
|
6191 |
|
6192 \sa focusNextChild(), focusPreviousChild() |
|
6193 */ |
|
6194 |
|
6195 bool QWidget::focusNextPrevChild(bool next) |
|
6196 { |
|
6197 Q_D(QWidget); |
|
6198 QWidget* p = parentWidget(); |
|
6199 bool isSubWindow = (windowType() == Qt::SubWindow); |
|
6200 if (!isWindow() && !isSubWindow && p) |
|
6201 return p->focusNextPrevChild(next); |
|
6202 #ifndef QT_NO_GRAPHICSVIEW |
|
6203 if (d->extra && d->extra->proxyWidget) |
|
6204 return d->extra->proxyWidget->focusNextPrevChild(next); |
|
6205 #endif |
|
6206 QWidget *w = QApplicationPrivate::focusNextPrevChild_helper(this, next); |
|
6207 if (!w) return false; |
|
6208 |
|
6209 w->setFocus(next ? Qt::TabFocusReason : Qt::BacktabFocusReason); |
|
6210 return true; |
|
6211 } |
|
6212 |
|
6213 /*! |
|
6214 Returns the last child of this widget that setFocus had been |
|
6215 called on. For top level widgets this is the widget that will get |
|
6216 focus in case this window gets activated |
|
6217 |
|
6218 This is not the same as QApplication::focusWidget(), which returns |
|
6219 the focus widget in the currently active window. |
|
6220 */ |
|
6221 |
|
6222 QWidget *QWidget::focusWidget() const |
|
6223 { |
|
6224 return const_cast<QWidget *>(d_func()->focus_child); |
|
6225 } |
|
6226 |
|
6227 /*! |
|
6228 Returns the next widget in this widget's focus chain. |
|
6229 |
|
6230 \sa previousInFocusChain() |
|
6231 */ |
|
6232 QWidget *QWidget::nextInFocusChain() const |
|
6233 { |
|
6234 return const_cast<QWidget *>(d_func()->focus_next); |
|
6235 } |
|
6236 |
|
6237 /*! |
|
6238 \brief The previousInFocusChain function returns the previous |
|
6239 widget in this widget's focus chain. |
|
6240 |
|
6241 \sa nextInFocusChain() |
|
6242 |
|
6243 \since 4.6 |
|
6244 */ |
|
6245 QWidget *QWidget::previousInFocusChain() const |
|
6246 { |
|
6247 return const_cast<QWidget *>(d_func()->focus_prev); |
|
6248 } |
|
6249 |
|
6250 /*! |
|
6251 \property QWidget::isActiveWindow |
|
6252 \brief whether this widget's window is the active window |
|
6253 |
|
6254 The active window is the window that contains the widget that has |
|
6255 keyboard focus (The window may still have focus if it has no |
|
6256 widgets or none of its widgets accepts keyboard focus). |
|
6257 |
|
6258 When popup windows are visible, this property is true for both the |
|
6259 active window \e and for the popup. |
|
6260 |
|
6261 By default, this property is false. |
|
6262 |
|
6263 \sa activateWindow(), QApplication::activeWindow() |
|
6264 */ |
|
6265 bool QWidget::isActiveWindow() const |
|
6266 { |
|
6267 QWidget *tlw = window(); |
|
6268 if(tlw == QApplication::activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup))) |
|
6269 return true; |
|
6270 |
|
6271 #ifndef QT_NO_GRAPHICSVIEW |
|
6272 if (QWExtra *tlwExtra = tlw->d_func()->extra) { |
|
6273 if (isVisible() && tlwExtra->proxyWidget) |
|
6274 return tlwExtra->proxyWidget->isActiveWindow(); |
|
6275 } |
|
6276 #endif |
|
6277 |
|
6278 #ifdef Q_WS_MAC |
|
6279 extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp |
|
6280 if(qt_mac_is_macdrawer(tlw) && |
|
6281 tlw->parentWidget() && tlw->parentWidget()->isActiveWindow()) |
|
6282 return true; |
|
6283 |
|
6284 extern bool qt_mac_insideKeyWindow(const QWidget *); //qwidget_mac.cpp |
|
6285 if (QApplication::testAttribute(Qt::AA_MacPluginApplication) && qt_mac_insideKeyWindow(tlw)) |
|
6286 return true; |
|
6287 #endif |
|
6288 if(style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, this)) { |
|
6289 if(tlw->windowType() == Qt::Tool && |
|
6290 !tlw->isModal() && |
|
6291 (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow())) |
|
6292 return true; |
|
6293 QWidget *w = QApplication::activeWindow(); |
|
6294 while(w && tlw->windowType() == Qt::Tool && |
|
6295 !w->isModal() && w->parentWidget()) { |
|
6296 w = w->parentWidget()->window(); |
|
6297 if(w == tlw) |
|
6298 return true; |
|
6299 } |
|
6300 } |
|
6301 #if defined(Q_WS_WIN32) |
|
6302 HWND active = GetActiveWindow(); |
|
6303 if (!tlw->testAttribute(Qt::WA_WState_Created)) |
|
6304 return false; |
|
6305 return active == tlw->internalWinId() || ::IsChild(active, tlw->internalWinId()); |
|
6306 #else |
|
6307 return false; |
|
6308 #endif |
|
6309 } |
|
6310 |
|
6311 /*! |
|
6312 Puts the \a second widget after the \a first widget in the focus order. |
|
6313 |
|
6314 Note that since the tab order of the \a second widget is changed, you |
|
6315 should order a chain like this: |
|
6316 |
|
6317 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 9 |
|
6318 |
|
6319 \e not like this: |
|
6320 |
|
6321 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 10 |
|
6322 |
|
6323 If \a first or \a second has a focus proxy, setTabOrder() |
|
6324 correctly substitutes the proxy. |
|
6325 |
|
6326 \sa setFocusPolicy(), setFocusProxy(), {Keyboard Focus} |
|
6327 */ |
|
6328 void QWidget::setTabOrder(QWidget* first, QWidget *second) |
|
6329 { |
|
6330 if (!first || !second || first->focusPolicy() == Qt::NoFocus || second->focusPolicy() == Qt::NoFocus) |
|
6331 return; |
|
6332 |
|
6333 if (first->window() != second->window()) { |
|
6334 qWarning("QWidget::setTabOrder: 'first' and 'second' must be in the same window"); |
|
6335 return; |
|
6336 } |
|
6337 |
|
6338 QWidget *fp = first->focusProxy(); |
|
6339 if (fp) { |
|
6340 // If first is redirected, set first to the last child of first |
|
6341 // that can take keyboard focus so that second is inserted after |
|
6342 // that last child, and the focus order within first is (more |
|
6343 // likely to be) preserved. |
|
6344 QList<QWidget *> l = qFindChildren<QWidget *>(first); |
|
6345 for (int i = l.size()-1; i >= 0; --i) { |
|
6346 QWidget * next = l.at(i); |
|
6347 if (next->window() == fp->window()) { |
|
6348 fp = next; |
|
6349 if (fp->focusPolicy() != Qt::NoFocus) |
|
6350 break; |
|
6351 } |
|
6352 } |
|
6353 first = fp; |
|
6354 } |
|
6355 |
|
6356 |
|
6357 if (QWidget *sp = second->focusProxy()) |
|
6358 second = sp; |
|
6359 |
|
6360 // QWidget *fp = first->d_func()->focus_prev; |
|
6361 QWidget *fn = first->d_func()->focus_next; |
|
6362 |
|
6363 if (fn == second) |
|
6364 return; |
|
6365 |
|
6366 QWidget *sp = second->d_func()->focus_prev; |
|
6367 QWidget *sn = second->d_func()->focus_next; |
|
6368 |
|
6369 fn->d_func()->focus_prev = second; |
|
6370 first->d_func()->focus_next = second; |
|
6371 |
|
6372 second->d_func()->focus_next = fn; |
|
6373 second->d_func()->focus_prev = first; |
|
6374 |
|
6375 sp->d_func()->focus_next = sn; |
|
6376 sn->d_func()->focus_prev = sp; |
|
6377 |
|
6378 |
|
6379 Q_ASSERT(first->d_func()->focus_next->d_func()->focus_prev == first); |
|
6380 Q_ASSERT(first->d_func()->focus_prev->d_func()->focus_next == first); |
|
6381 |
|
6382 Q_ASSERT(second->d_func()->focus_next->d_func()->focus_prev == second); |
|
6383 Q_ASSERT(second->d_func()->focus_prev->d_func()->focus_next == second); |
|
6384 } |
|
6385 |
|
6386 /*!\internal |
|
6387 |
|
6388 Moves the relevant subwidgets of this widget from the \a oldtlw's |
|
6389 tab chain to that of the new parent, if there's anything to move and |
|
6390 we're really moving |
|
6391 |
|
6392 This function is called from QWidget::reparent() *after* the widget |
|
6393 has been reparented. |
|
6394 |
|
6395 \sa reparent() |
|
6396 */ |
|
6397 |
|
6398 void QWidgetPrivate::reparentFocusWidgets(QWidget * oldtlw) |
|
6399 { |
|
6400 Q_Q(QWidget); |
|
6401 if (oldtlw == q->window()) |
|
6402 return; // nothing to do |
|
6403 |
|
6404 if(focus_child) |
|
6405 focus_child->clearFocus(); |
|
6406 |
|
6407 // separate the focus chain into new (children of myself) and old (the rest) |
|
6408 QWidget *firstOld = 0; |
|
6409 //QWidget *firstNew = q; //invariant |
|
6410 QWidget *o = 0; // last in the old list |
|
6411 QWidget *n = q; // last in the new list |
|
6412 |
|
6413 bool prevWasNew = true; |
|
6414 QWidget *w = focus_next; |
|
6415 |
|
6416 //Note: for efficiency, we do not maintain the list invariant inside the loop |
|
6417 //we append items to the relevant list, and we optimize by not changing pointers |
|
6418 //when subsequent items are going into the same list. |
|
6419 while (w != q) { |
|
6420 bool currentIsNew = q->isAncestorOf(w); |
|
6421 if (currentIsNew) { |
|
6422 if (!prevWasNew) { |
|
6423 //prev was old -- append to new list |
|
6424 n->d_func()->focus_next = w; |
|
6425 w->d_func()->focus_prev = n; |
|
6426 } |
|
6427 n = w; |
|
6428 } else { |
|
6429 if (prevWasNew) { |
|
6430 //prev was new -- append to old list, if there is one |
|
6431 if (o) { |
|
6432 o->d_func()->focus_next = w; |
|
6433 w->d_func()->focus_prev = o; |
|
6434 } else { |
|
6435 // "create" the old list |
|
6436 firstOld = w; |
|
6437 } |
|
6438 } |
|
6439 o = w; |
|
6440 } |
|
6441 w = w->d_func()->focus_next; |
|
6442 prevWasNew = currentIsNew; |
|
6443 } |
|
6444 |
|
6445 //repair the old list: |
|
6446 if (firstOld) { |
|
6447 o->d_func()->focus_next = firstOld; |
|
6448 firstOld->d_func()->focus_prev = o; |
|
6449 } |
|
6450 |
|
6451 if (!q->isWindow()) { |
|
6452 QWidget *topLevel = q->window(); |
|
6453 //insert new chain into toplevel's chain |
|
6454 |
|
6455 QWidget *prev = topLevel->d_func()->focus_prev; |
|
6456 |
|
6457 topLevel->d_func()->focus_prev = n; |
|
6458 prev->d_func()->focus_next = q; |
|
6459 |
|
6460 focus_prev = prev; |
|
6461 n->d_func()->focus_next = topLevel; |
|
6462 } else { |
|
6463 //repair the new list |
|
6464 n->d_func()->focus_next = q; |
|
6465 focus_prev = n; |
|
6466 } |
|
6467 |
|
6468 } |
|
6469 |
|
6470 /*!\internal |
|
6471 |
|
6472 Measures the shortest distance from a point to a rect. |
|
6473 |
|
6474 This function is called from QDesktopwidget::screen(QPoint) to find the |
|
6475 closest screen for a point. |
|
6476 In directional KeypadNavigation, it is called to find the closest |
|
6477 widget to the current focus widget center. |
|
6478 */ |
|
6479 int QWidgetPrivate::pointToRect(const QPoint &p, const QRect &r) |
|
6480 { |
|
6481 int dx = 0; |
|
6482 int dy = 0; |
|
6483 if (p.x() < r.left()) |
|
6484 dx = r.left() - p.x(); |
|
6485 else if (p.x() > r.right()) |
|
6486 dx = p.x() - r.right(); |
|
6487 if (p.y() < r.top()) |
|
6488 dy = r.top() - p.y(); |
|
6489 else if (p.y() > r.bottom()) |
|
6490 dy = p.y() - r.bottom(); |
|
6491 return dx + dy; |
|
6492 } |
|
6493 |
|
6494 /*! |
|
6495 \property QWidget::frameSize |
|
6496 \brief the size of the widget including any window frame |
|
6497 |
|
6498 By default, this property contains a value that depends on the user's |
|
6499 platform and screen geometry. |
|
6500 */ |
|
6501 QSize QWidget::frameSize() const |
|
6502 { |
|
6503 Q_D(const QWidget); |
|
6504 if (isWindow() && !(windowType() == Qt::Popup)) { |
|
6505 QRect fs = d->frameStrut(); |
|
6506 return QSize(data->crect.width() + fs.left() + fs.right(), |
|
6507 data->crect.height() + fs.top() + fs.bottom()); |
|
6508 } |
|
6509 return data->crect.size(); |
|
6510 } |
|
6511 |
|
6512 /*! \fn void QWidget::move(int x, int y) |
|
6513 |
|
6514 \overload |
|
6515 |
|
6516 This corresponds to move(QPoint(\a x, \a y)). |
|
6517 */ |
|
6518 |
|
6519 void QWidget::move(const QPoint &p) |
|
6520 { |
|
6521 Q_D(QWidget); |
|
6522 setAttribute(Qt::WA_Moved); |
|
6523 if (isWindow()) |
|
6524 d->topData()->posFromMove = true; |
|
6525 if (testAttribute(Qt::WA_WState_Created)) { |
|
6526 d->setGeometry_sys(p.x() + geometry().x() - QWidget::x(), |
|
6527 p.y() + geometry().y() - QWidget::y(), |
|
6528 width(), height(), true); |
|
6529 d->setDirtyOpaqueRegion(); |
|
6530 } else { |
|
6531 data->crect.moveTopLeft(p); // no frame yet |
|
6532 setAttribute(Qt::WA_PendingMoveEvent); |
|
6533 } |
|
6534 } |
|
6535 |
|
6536 /*! \fn void QWidget::resize(int w, int h) |
|
6537 \overload |
|
6538 |
|
6539 This corresponds to resize(QSize(\a w, \a h)). |
|
6540 */ |
|
6541 |
|
6542 void QWidget::resize(const QSize &s) |
|
6543 { |
|
6544 Q_D(QWidget); |
|
6545 setAttribute(Qt::WA_Resized); |
|
6546 if (testAttribute(Qt::WA_WState_Created)) { |
|
6547 d->setGeometry_sys(geometry().x(), geometry().y(), s.width(), s.height(), false); |
|
6548 d->setDirtyOpaqueRegion(); |
|
6549 } else { |
|
6550 data->crect.setSize(s.boundedTo(maximumSize()).expandedTo(minimumSize())); |
|
6551 setAttribute(Qt::WA_PendingResizeEvent); |
|
6552 } |
|
6553 } |
|
6554 |
|
6555 void QWidget::setGeometry(const QRect &r) |
|
6556 { |
|
6557 Q_D(QWidget); |
|
6558 setAttribute(Qt::WA_Resized); |
|
6559 setAttribute(Qt::WA_Moved); |
|
6560 if (isWindow()) |
|
6561 d->topData()->posFromMove = false; |
|
6562 if (testAttribute(Qt::WA_WState_Created)) { |
|
6563 d->setGeometry_sys(r.x(), r.y(), r.width(), r.height(), true); |
|
6564 d->setDirtyOpaqueRegion(); |
|
6565 } else { |
|
6566 data->crect.setTopLeft(r.topLeft()); |
|
6567 data->crect.setSize(r.size().boundedTo(maximumSize()).expandedTo(minimumSize())); |
|
6568 setAttribute(Qt::WA_PendingMoveEvent); |
|
6569 setAttribute(Qt::WA_PendingResizeEvent); |
|
6570 } |
|
6571 } |
|
6572 |
|
6573 /*! |
|
6574 \since 4.2 |
|
6575 Saves the current geometry and state for top-level widgets. |
|
6576 |
|
6577 To save the geometry when the window closes, you can |
|
6578 implement a close event like this: |
|
6579 |
|
6580 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 11 |
|
6581 |
|
6582 See the \l{Window Geometry} documentation for an overview of geometry |
|
6583 issues with windows. |
|
6584 |
|
6585 Use QMainWindow::saveState() to save the geometry and the state of |
|
6586 toolbars and dock widgets. |
|
6587 |
|
6588 \sa restoreGeometry(), QMainWindow::saveState(), QMainWindow::restoreState() |
|
6589 */ |
|
6590 QByteArray QWidget::saveGeometry() const |
|
6591 { |
|
6592 QByteArray array; |
|
6593 QDataStream stream(&array, QIODevice::WriteOnly); |
|
6594 stream.setVersion(QDataStream::Qt_4_0); |
|
6595 const quint32 magicNumber = 0x1D9D0CB; |
|
6596 quint16 majorVersion = 1; |
|
6597 quint16 minorVersion = 0; |
|
6598 stream << magicNumber |
|
6599 << majorVersion |
|
6600 << minorVersion |
|
6601 << frameGeometry() |
|
6602 << normalGeometry() |
|
6603 << qint32(QApplication::desktop()->screenNumber(this)) |
|
6604 << quint8(windowState() & Qt::WindowMaximized) |
|
6605 << quint8(windowState() & Qt::WindowFullScreen); |
|
6606 return array; |
|
6607 } |
|
6608 |
|
6609 /*! |
|
6610 \since 4.2 |
|
6611 |
|
6612 Restores the geometry and state top-level widgets stored in the |
|
6613 byte array \a geometry. Returns true on success; otherwise |
|
6614 returns false. |
|
6615 |
|
6616 If the restored geometry is off-screen, it will be modified to be |
|
6617 inside the available screen geometry. |
|
6618 |
|
6619 To restore geometry saved using QSettings, you can use code like |
|
6620 this: |
|
6621 |
|
6622 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 12 |
|
6623 |
|
6624 See the \l{Window Geometry} documentation for an overview of geometry |
|
6625 issues with windows. |
|
6626 |
|
6627 Use QMainWindow::restoreState() to restore the geometry and the |
|
6628 state of toolbars and dock widgets. |
|
6629 |
|
6630 \sa saveGeometry(), QSettings, QMainWindow::saveState(), QMainWindow::restoreState() |
|
6631 */ |
|
6632 bool QWidget::restoreGeometry(const QByteArray &geometry) |
|
6633 { |
|
6634 if (geometry.size() < 4) |
|
6635 return false; |
|
6636 QDataStream stream(geometry); |
|
6637 stream.setVersion(QDataStream::Qt_4_0); |
|
6638 |
|
6639 const quint32 magicNumber = 0x1D9D0CB; |
|
6640 quint32 storedMagicNumber; |
|
6641 stream >> storedMagicNumber; |
|
6642 if (storedMagicNumber != magicNumber) |
|
6643 return false; |
|
6644 |
|
6645 const quint16 currentMajorVersion = 1; |
|
6646 quint16 majorVersion = 0; |
|
6647 quint16 minorVersion = 0; |
|
6648 |
|
6649 stream >> majorVersion >> minorVersion; |
|
6650 |
|
6651 if (majorVersion != currentMajorVersion) |
|
6652 return false; |
|
6653 // (Allow all minor versions.) |
|
6654 |
|
6655 QRect restoredFrameGeometry; |
|
6656 QRect restoredNormalGeometry; |
|
6657 qint32 restoredScreenNumber; |
|
6658 quint8 maximized; |
|
6659 quint8 fullScreen; |
|
6660 |
|
6661 stream >> restoredFrameGeometry |
|
6662 >> restoredNormalGeometry |
|
6663 >> restoredScreenNumber |
|
6664 >> maximized |
|
6665 >> fullScreen; |
|
6666 |
|
6667 const int frameHeight = 20; |
|
6668 if (!restoredFrameGeometry.isValid()) |
|
6669 restoredFrameGeometry = QRect(QPoint(0,0), sizeHint()); |
|
6670 |
|
6671 if (!restoredNormalGeometry.isValid()) |
|
6672 restoredNormalGeometry = QRect(QPoint(0, frameHeight), sizeHint()); |
|
6673 if (!restoredNormalGeometry.isValid()) { |
|
6674 // use the widget's adjustedSize if the sizeHint() doesn't help |
|
6675 restoredNormalGeometry.setSize(restoredNormalGeometry |
|
6676 .size() |
|
6677 .expandedTo(d_func()->adjustedSize())); |
|
6678 } |
|
6679 |
|
6680 const QDesktopWidget * const desktop = QApplication::desktop(); |
|
6681 if (restoredScreenNumber >= desktop->numScreens()) |
|
6682 restoredScreenNumber = desktop->primaryScreen(); |
|
6683 |
|
6684 const QRect availableGeometry = desktop->availableGeometry(restoredScreenNumber); |
|
6685 |
|
6686 // Modify the restored geometry if we are about to restore to coordinates |
|
6687 // that would make the window "lost". This happens if: |
|
6688 // - The restored geometry is completely oustside the available geometry |
|
6689 // - The title bar is outside the available geometry. |
|
6690 // - (Mac only) The window is higher than the available geometry. It must |
|
6691 // be possible to bring the size grip on screen by moving the window. |
|
6692 #ifdef Q_WS_MAC |
|
6693 restoredFrameGeometry.setHeight(qMin(restoredFrameGeometry.height(), availableGeometry.height())); |
|
6694 restoredNormalGeometry.setHeight(qMin(restoredNormalGeometry.height(), availableGeometry.height() - frameHeight)); |
|
6695 #endif |
|
6696 |
|
6697 if (!restoredFrameGeometry.intersects(availableGeometry)) { |
|
6698 restoredFrameGeometry.moveBottom(qMin(restoredFrameGeometry.bottom(), availableGeometry.bottom())); |
|
6699 restoredFrameGeometry.moveLeft(qMax(restoredFrameGeometry.left(), availableGeometry.left())); |
|
6700 restoredFrameGeometry.moveRight(qMin(restoredFrameGeometry.right(), availableGeometry.right())); |
|
6701 } |
|
6702 restoredFrameGeometry.moveTop(qMax(restoredFrameGeometry.top(), availableGeometry.top())); |
|
6703 |
|
6704 if (!restoredNormalGeometry.intersects(availableGeometry)) { |
|
6705 restoredNormalGeometry.moveBottom(qMin(restoredNormalGeometry.bottom(), availableGeometry.bottom())); |
|
6706 restoredNormalGeometry.moveLeft(qMax(restoredNormalGeometry.left(), availableGeometry.left())); |
|
6707 restoredNormalGeometry.moveRight(qMin(restoredNormalGeometry.right(), availableGeometry.right())); |
|
6708 } |
|
6709 restoredNormalGeometry.moveTop(qMax(restoredNormalGeometry.top(), availableGeometry.top() + frameHeight)); |
|
6710 |
|
6711 if (maximized || fullScreen) { |
|
6712 // set geomerty before setting the window state to make |
|
6713 // sure the window is maximized to the right screen. |
|
6714 setGeometry(restoredNormalGeometry); |
|
6715 Qt::WindowStates ws = windowState(); |
|
6716 if (maximized) |
|
6717 ws |= Qt::WindowMaximized; |
|
6718 if (fullScreen) |
|
6719 ws |= Qt::WindowFullScreen; |
|
6720 setWindowState(ws); |
|
6721 d_func()->topData()->normalGeometry = restoredNormalGeometry; |
|
6722 } else { |
|
6723 QPoint offset; |
|
6724 #ifdef Q_WS_X11 |
|
6725 if (isFullScreen()) |
|
6726 offset = d_func()->topData()->fullScreenOffset; |
|
6727 #endif |
|
6728 setWindowState(windowState() & ~(Qt::WindowMaximized | Qt::WindowFullScreen)); |
|
6729 move(restoredFrameGeometry.topLeft() + offset); |
|
6730 resize(restoredNormalGeometry.size()); |
|
6731 } |
|
6732 return true; |
|
6733 } |
|
6734 |
|
6735 /*!\fn void QWidget::setGeometry(int x, int y, int w, int h) |
|
6736 \overload |
|
6737 |
|
6738 This corresponds to setGeometry(QRect(\a x, \a y, \a w, \a h)). |
|
6739 */ |
|
6740 |
|
6741 /*! |
|
6742 Sets the margins around the contents of the widget to have the sizes |
|
6743 \a left, \a top, \a right, and \a bottom. The margins are used by |
|
6744 the layout system, and may be used by subclasses to specify the area |
|
6745 to draw in (e.g. excluding the frame). |
|
6746 |
|
6747 Changing the margins will trigger a resizeEvent(). |
|
6748 |
|
6749 \sa contentsRect(), getContentsMargins() |
|
6750 */ |
|
6751 void QWidget::setContentsMargins(int left, int top, int right, int bottom) |
|
6752 { |
|
6753 Q_D(QWidget); |
|
6754 if (left == d->leftmargin && top == d->topmargin |
|
6755 && right == d->rightmargin && bottom == d->bottommargin) |
|
6756 return; |
|
6757 d->leftmargin = left; |
|
6758 d->topmargin = top; |
|
6759 d->rightmargin = right; |
|
6760 d->bottommargin = bottom; |
|
6761 |
|
6762 if (QLayout *l=d->layout) |
|
6763 l->update(); //force activate; will do updateGeometry |
|
6764 else |
|
6765 updateGeometry(); |
|
6766 |
|
6767 // ### Qt 5: compat, remove |
|
6768 if (isVisible()) { |
|
6769 update(); |
|
6770 QResizeEvent e(data->crect.size(), data->crect.size()); |
|
6771 QApplication::sendEvent(this, &e); |
|
6772 } else { |
|
6773 setAttribute(Qt::WA_PendingResizeEvent, true); |
|
6774 } |
|
6775 |
|
6776 QEvent e(QEvent::ContentsRectChange); |
|
6777 QApplication::sendEvent(this, &e); |
|
6778 } |
|
6779 |
|
6780 /*! |
|
6781 \overload |
|
6782 \since 4.6 |
|
6783 |
|
6784 \brief The setContentsMargins function sets the margins around the |
|
6785 widget's contents. |
|
6786 |
|
6787 Sets the margins around the contents of the widget to have the |
|
6788 sizes determined by \a margins. The margins are |
|
6789 used by the layout system, and may be used by subclasses to |
|
6790 specify the area to draw in (e.g. excluding the frame). |
|
6791 |
|
6792 Changing the margins will trigger a resizeEvent(). |
|
6793 |
|
6794 \sa contentsRect(), getContentsMargins() |
|
6795 */ |
|
6796 void QWidget::setContentsMargins(const QMargins &margins) |
|
6797 { |
|
6798 setContentsMargins(margins.left(), margins.top(), |
|
6799 margins.right(), margins.bottom()); |
|
6800 } |
|
6801 |
|
6802 /*! |
|
6803 Returns the widget's contents margins for \a left, \a top, \a |
|
6804 right, and \a bottom. |
|
6805 |
|
6806 \sa setContentsMargins(), contentsRect() |
|
6807 */ |
|
6808 void QWidget::getContentsMargins(int *left, int *top, int *right, int *bottom) const |
|
6809 { |
|
6810 Q_D(const QWidget); |
|
6811 if (left) |
|
6812 *left = d->leftmargin; |
|
6813 if (top) |
|
6814 *top = d->topmargin; |
|
6815 if (right) |
|
6816 *right = d->rightmargin; |
|
6817 if (bottom) |
|
6818 *bottom = d->bottommargin; |
|
6819 } |
|
6820 |
|
6821 /*! |
|
6822 \since 4.6 |
|
6823 |
|
6824 \brief The contentsMargins function returns the widget's contents margins. |
|
6825 |
|
6826 \sa getContentsMargins(), setContentsMargins(), contentsRect() |
|
6827 */ |
|
6828 QMargins QWidget::contentsMargins() const |
|
6829 { |
|
6830 Q_D(const QWidget); |
|
6831 return QMargins(d->leftmargin, d->topmargin, d->rightmargin, d->bottommargin); |
|
6832 } |
|
6833 |
|
6834 |
|
6835 /*! |
|
6836 Returns the area inside the widget's margins. |
|
6837 |
|
6838 \sa setContentsMargins(), getContentsMargins() |
|
6839 */ |
|
6840 QRect QWidget::contentsRect() const |
|
6841 { |
|
6842 Q_D(const QWidget); |
|
6843 return QRect(QPoint(d->leftmargin, d->topmargin), |
|
6844 QPoint(data->crect.width() - 1 - d->rightmargin, |
|
6845 data->crect.height() - 1 - d->bottommargin)); |
|
6846 |
|
6847 } |
|
6848 |
|
6849 |
|
6850 |
|
6851 /*! |
|
6852 \fn void QWidget::customContextMenuRequested(const QPoint &pos) |
|
6853 |
|
6854 This signal is emitted when the widget's \l contextMenuPolicy is |
|
6855 Qt::CustomContextMenu, and the user has requested a context menu on |
|
6856 the widget. The position \a pos is the position of the context menu |
|
6857 event that the widget receives. Normally this is in widget |
|
6858 coordinates. The exception to this rule is QAbstractScrollArea and |
|
6859 its subclasses that map the context menu event to coordinates of the |
|
6860 \link QAbstractScrollArea::viewport() viewport() \endlink . |
|
6861 |
|
6862 |
|
6863 \sa mapToGlobal() QMenu contextMenuPolicy |
|
6864 */ |
|
6865 |
|
6866 |
|
6867 /*! |
|
6868 \property QWidget::contextMenuPolicy |
|
6869 \brief how the widget shows a context menu |
|
6870 |
|
6871 The default value of this property is Qt::DefaultContextMenu, |
|
6872 which means the contextMenuEvent() handler is called. Other values |
|
6873 are Qt::NoContextMenu, Qt::PreventContextMenu, |
|
6874 Qt::ActionsContextMenu, and Qt::CustomContextMenu. With |
|
6875 Qt::CustomContextMenu, the signal customContextMenuRequested() is |
|
6876 emitted. |
|
6877 |
|
6878 \sa contextMenuEvent(), customContextMenuRequested(), actions() |
|
6879 */ |
|
6880 |
|
6881 Qt::ContextMenuPolicy QWidget::contextMenuPolicy() const |
|
6882 { |
|
6883 return (Qt::ContextMenuPolicy)data->context_menu_policy; |
|
6884 } |
|
6885 |
|
6886 void QWidget::setContextMenuPolicy(Qt::ContextMenuPolicy policy) |
|
6887 { |
|
6888 data->context_menu_policy = (uint) policy; |
|
6889 } |
|
6890 |
|
6891 /*! |
|
6892 \property QWidget::focusPolicy |
|
6893 \brief the way the widget accepts keyboard focus |
|
6894 |
|
6895 The policy is Qt::TabFocus if the widget accepts keyboard |
|
6896 focus by tabbing, Qt::ClickFocus if the widget accepts |
|
6897 focus by clicking, Qt::StrongFocus if it accepts both, and |
|
6898 Qt::NoFocus (the default) if it does not accept focus at |
|
6899 all. |
|
6900 |
|
6901 You must enable keyboard focus for a widget if it processes |
|
6902 keyboard events. This is normally done from the widget's |
|
6903 constructor. For instance, the QLineEdit constructor calls |
|
6904 setFocusPolicy(Qt::StrongFocus). |
|
6905 |
|
6906 If the widget has a focus proxy, then the focus policy will |
|
6907 be propagated to it. |
|
6908 |
|
6909 \sa focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), enabled |
|
6910 */ |
|
6911 |
|
6912 |
|
6913 Qt::FocusPolicy QWidget::focusPolicy() const |
|
6914 { |
|
6915 return (Qt::FocusPolicy)data->focus_policy; |
|
6916 } |
|
6917 |
|
6918 void QWidget::setFocusPolicy(Qt::FocusPolicy policy) |
|
6919 { |
|
6920 data->focus_policy = (uint) policy; |
|
6921 Q_D(QWidget); |
|
6922 if (d->extra && d->extra->focus_proxy) |
|
6923 d->extra->focus_proxy->setFocusPolicy(policy); |
|
6924 } |
|
6925 |
|
6926 /*! |
|
6927 \property QWidget::updatesEnabled |
|
6928 \brief whether updates are enabled |
|
6929 |
|
6930 An updates enabled widget receives paint events and has a system |
|
6931 background; a disabled widget does not. This also implies that |
|
6932 calling update() and repaint() has no effect if updates are |
|
6933 disabled. |
|
6934 |
|
6935 By default, this property is true. |
|
6936 |
|
6937 setUpdatesEnabled() is normally used to disable updates for a |
|
6938 short period of time, for instance to avoid screen flicker during |
|
6939 large changes. In Qt, widgets normally do not generate screen |
|
6940 flicker, but on X11 the server might erase regions on the screen |
|
6941 when widgets get hidden before they can be replaced by other |
|
6942 widgets. Disabling updates solves this. |
|
6943 |
|
6944 Example: |
|
6945 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 13 |
|
6946 |
|
6947 Disabling a widget implicitly disables all its children. Enabling a widget |
|
6948 enables all child widgets \e except top-level widgets or those that |
|
6949 have been explicitly disabled. Re-enabling updates implicitly calls |
|
6950 update() on the widget. |
|
6951 |
|
6952 \sa paintEvent() |
|
6953 */ |
|
6954 void QWidget::setUpdatesEnabled(bool enable) |
|
6955 { |
|
6956 Q_D(QWidget); |
|
6957 setAttribute(Qt::WA_ForceUpdatesDisabled, !enable); |
|
6958 d->setUpdatesEnabled_helper(enable); |
|
6959 } |
|
6960 |
|
6961 /*! \fn void QWidget::show() |
|
6962 |
|
6963 Shows the widget and its child widgets. This function is |
|
6964 equivalent to setVisible(true). |
|
6965 |
|
6966 \sa raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(), |
|
6967 showNormal(), isVisible() |
|
6968 */ |
|
6969 |
|
6970 |
|
6971 /*! \internal |
|
6972 |
|
6973 Makes the widget visible in the isVisible() meaning of the word. |
|
6974 It is only called for toplevels or widgets with visible parents. |
|
6975 */ |
|
6976 void QWidgetPrivate::show_recursive() |
|
6977 { |
|
6978 Q_Q(QWidget); |
|
6979 // polish if necessary |
|
6980 |
|
6981 if (!q->testAttribute(Qt::WA_WState_Created)) |
|
6982 createRecursively(); |
|
6983 q->ensurePolished(); |
|
6984 |
|
6985 #ifdef QT3_SUPPORT |
|
6986 if(sendChildEvents) |
|
6987 QApplication::sendPostedEvents(q, QEvent::ChildInserted); |
|
6988 #endif |
|
6989 if (!q->isWindow() && q->parentWidget()->d_func()->layout && !q->parentWidget()->data->in_show) |
|
6990 q->parentWidget()->d_func()->layout->activate(); |
|
6991 // activate our layout before we and our children become visible |
|
6992 if (layout) |
|
6993 layout->activate(); |
|
6994 |
|
6995 show_helper(); |
|
6996 } |
|
6997 |
|
6998 void QWidgetPrivate::sendPendingMoveAndResizeEvents(bool recursive, bool disableUpdates) |
|
6999 { |
|
7000 Q_Q(QWidget); |
|
7001 |
|
7002 disableUpdates = disableUpdates && q->updatesEnabled(); |
|
7003 if (disableUpdates) |
|
7004 q->setAttribute(Qt::WA_UpdatesDisabled); |
|
7005 |
|
7006 if (q->testAttribute(Qt::WA_PendingMoveEvent)) { |
|
7007 QMoveEvent e(data.crect.topLeft(), data.crect.topLeft()); |
|
7008 QApplication::sendEvent(q, &e); |
|
7009 q->setAttribute(Qt::WA_PendingMoveEvent, false); |
|
7010 } |
|
7011 |
|
7012 if (q->testAttribute(Qt::WA_PendingResizeEvent)) { |
|
7013 QResizeEvent e(data.crect.size(), QSize()); |
|
7014 QApplication::sendEvent(q, &e); |
|
7015 q->setAttribute(Qt::WA_PendingResizeEvent, false); |
|
7016 } |
|
7017 |
|
7018 if (disableUpdates) |
|
7019 q->setAttribute(Qt::WA_UpdatesDisabled, false); |
|
7020 |
|
7021 if (!recursive) |
|
7022 return; |
|
7023 |
|
7024 for (int i = 0; i < children.size(); ++i) { |
|
7025 if (QWidget *child = qobject_cast<QWidget *>(children.at(i))) |
|
7026 child->d_func()->sendPendingMoveAndResizeEvents(recursive, disableUpdates); |
|
7027 } |
|
7028 } |
|
7029 |
|
7030 void QWidgetPrivate::activateChildLayoutsRecursively() |
|
7031 { |
|
7032 sendPendingMoveAndResizeEvents(false, true); |
|
7033 |
|
7034 for (int i = 0; i < children.size(); ++i) { |
|
7035 QWidget *child = qobject_cast<QWidget *>(children.at(i)); |
|
7036 if (!child || child->isHidden() || child->isWindow()) |
|
7037 continue; |
|
7038 |
|
7039 child->ensurePolished(); |
|
7040 |
|
7041 // Activate child's layout |
|
7042 QWidgetPrivate *childPrivate = child->d_func(); |
|
7043 if (childPrivate->layout) |
|
7044 childPrivate->layout->activate(); |
|
7045 |
|
7046 // Pretend we're visible. |
|
7047 const bool wasVisible = child->isVisible(); |
|
7048 if (!wasVisible) |
|
7049 child->setAttribute(Qt::WA_WState_Visible); |
|
7050 |
|
7051 // Do the same for all my children. |
|
7052 childPrivate->activateChildLayoutsRecursively(); |
|
7053 |
|
7054 // We're not cheating anymore. |
|
7055 if (!wasVisible) |
|
7056 child->setAttribute(Qt::WA_WState_Visible, false); |
|
7057 } |
|
7058 } |
|
7059 |
|
7060 void QWidgetPrivate::show_helper() |
|
7061 { |
|
7062 Q_Q(QWidget); |
|
7063 data.in_show = true; // qws optimization |
|
7064 // make sure we receive pending move and resize events |
|
7065 sendPendingMoveAndResizeEvents(); |
|
7066 |
|
7067 // become visible before showing all children |
|
7068 q->setAttribute(Qt::WA_WState_Visible); |
|
7069 |
|
7070 // finally show all children recursively |
|
7071 showChildren(false); |
|
7072 |
|
7073 #ifdef QT3_SUPPORT |
|
7074 if (q->parentWidget() && sendChildEvents) |
|
7075 QApplication::sendPostedEvents(q->parentWidget(), |
|
7076 QEvent::ChildInserted); |
|
7077 #endif |
|
7078 |
|
7079 |
|
7080 // popup handling: new popups and tools need to be raised, and |
|
7081 // existing popups must be closed. Also propagate the current |
|
7082 // windows's KeyboardFocusChange status. |
|
7083 if (q->isWindow()) { |
|
7084 if ((q->windowType() == Qt::Tool) || (q->windowType() == Qt::Popup) || q->windowType() == Qt::ToolTip) { |
|
7085 q->raise(); |
|
7086 if (q->parentWidget() && q->parentWidget()->window()->testAttribute(Qt::WA_KeyboardFocusChange)) |
|
7087 q->setAttribute(Qt::WA_KeyboardFocusChange); |
|
7088 } else { |
|
7089 while (QApplication::activePopupWidget()) { |
|
7090 if (!QApplication::activePopupWidget()->close()) |
|
7091 break; |
|
7092 } |
|
7093 } |
|
7094 } |
|
7095 |
|
7096 // Automatic embedding of child windows of widgets already embedded into |
|
7097 // QGraphicsProxyWidget when they are shown the first time. |
|
7098 bool isEmbedded = false; |
|
7099 #ifndef QT_NO_GRAPHICSVIEW |
|
7100 if (q->isWindow()) { |
|
7101 isEmbedded = q->graphicsProxyWidget() ? true : false; |
|
7102 if (!isEmbedded && !bypassGraphicsProxyWidget(q)) { |
|
7103 QGraphicsProxyWidget *ancestorProxy = nearestGraphicsProxyWidget(q->parentWidget()); |
|
7104 if (ancestorProxy) { |
|
7105 isEmbedded = true; |
|
7106 ancestorProxy->d_func()->embedSubWindow(q); |
|
7107 } |
|
7108 } |
|
7109 } |
|
7110 #else |
|
7111 Q_UNUSED(isEmbedded); |
|
7112 #endif |
|
7113 |
|
7114 // On Windows, show the popup now so that our own focus handling |
|
7115 // stores the correct old focus widget even if it's stolen in the |
|
7116 // showevent |
|
7117 #if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_OS_SYMBIAN) |
|
7118 if (!isEmbedded && q->windowType() == Qt::Popup) |
|
7119 qApp->d_func()->openPopup(q); |
|
7120 #endif |
|
7121 |
|
7122 // send the show event before showing the window |
|
7123 QShowEvent showEvent; |
|
7124 QApplication::sendEvent(q, &showEvent); |
|
7125 |
|
7126 if (!isEmbedded && q->isModal() && q->isWindow()) |
|
7127 // QApplicationPrivate::enterModal *before* show, otherwise the initial |
|
7128 // stacking might be wrong |
|
7129 QApplicationPrivate::enterModal(q); |
|
7130 |
|
7131 |
|
7132 show_sys(); |
|
7133 |
|
7134 #if !defined(Q_WS_WIN) && !defined(Q_WS_MAC) && !defined(Q_OS_SYMBIAN) |
|
7135 if (!isEmbedded && q->windowType() == Qt::Popup) |
|
7136 qApp->d_func()->openPopup(q); |
|
7137 #endif |
|
7138 |
|
7139 #ifndef QT_NO_ACCESSIBILITY |
|
7140 if (q->windowType() != Qt::ToolTip) // Tooltips are read aloud twice in MS narrator. |
|
7141 QAccessible::updateAccessibility(q, 0, QAccessible::ObjectShow); |
|
7142 #endif |
|
7143 |
|
7144 if (QApplicationPrivate::hidden_focus_widget == q) { |
|
7145 QApplicationPrivate::hidden_focus_widget = 0; |
|
7146 q->setFocus(Qt::OtherFocusReason); |
|
7147 } |
|
7148 |
|
7149 // Process events when showing a Qt::SplashScreen widget before the event loop |
|
7150 // is spinnning; otherwise it might not show up on particular platforms. |
|
7151 // This makes QSplashScreen behave the same on all platforms. |
|
7152 if (!qApp->d_func()->in_exec && q->windowType() == Qt::SplashScreen) |
|
7153 QApplication::processEvents(); |
|
7154 |
|
7155 data.in_show = false; // reset qws optimization |
|
7156 } |
|
7157 |
|
7158 /*! \fn void QWidget::hide() |
|
7159 |
|
7160 Hides the widget. This function is equivalent to |
|
7161 setVisible(false). |
|
7162 |
|
7163 |
|
7164 \note If you are working with QDialog or its subclasses and you invoke |
|
7165 the show() function after this function, the dialog will be displayed in |
|
7166 its original position. |
|
7167 |
|
7168 \sa hideEvent(), isHidden(), show(), setVisible(), isVisible(), close() |
|
7169 */ |
|
7170 |
|
7171 /*!\internal |
|
7172 */ |
|
7173 void QWidgetPrivate::hide_helper() |
|
7174 { |
|
7175 Q_Q(QWidget); |
|
7176 |
|
7177 bool isEmbedded = false; |
|
7178 #if !defined QT_NO_GRAPHICSVIEW |
|
7179 isEmbedded = q->isWindow() && nearestGraphicsProxyWidget(q->parentWidget()) != 0; |
|
7180 #else |
|
7181 Q_UNUSED(isEmbedded); |
|
7182 #endif |
|
7183 |
|
7184 if (!isEmbedded && (q->windowType() == Qt::Popup)) |
|
7185 qApp->d_func()->closePopup(q); |
|
7186 |
|
7187 // Move test modal here. Otherwise, a modal dialog could get |
|
7188 // destroyed and we lose all access to its parent because we haven't |
|
7189 // left modality. (Eg. modal Progress Dialog) |
|
7190 if (!isEmbedded && q->isModal() && q->isWindow()) |
|
7191 QApplicationPrivate::leaveModal(q); |
|
7192 |
|
7193 #if defined(Q_WS_WIN) |
|
7194 if (q->isWindow() && !(q->windowType() == Qt::Popup) && q->parentWidget() |
|
7195 && !q->parentWidget()->isHidden() && q->isActiveWindow()) |
|
7196 q->parentWidget()->activateWindow(); // Activate parent |
|
7197 #endif |
|
7198 |
|
7199 q->setAttribute(Qt::WA_Mapped, false); |
|
7200 hide_sys(); |
|
7201 |
|
7202 bool wasVisible = q->testAttribute(Qt::WA_WState_Visible); |
|
7203 |
|
7204 if (wasVisible) { |
|
7205 q->setAttribute(Qt::WA_WState_Visible, false); |
|
7206 |
|
7207 } |
|
7208 |
|
7209 QHideEvent hideEvent; |
|
7210 QApplication::sendEvent(q, &hideEvent); |
|
7211 hideChildren(false); |
|
7212 |
|
7213 // next bit tries to move the focus if the focus widget is now |
|
7214 // hidden. |
|
7215 if (wasVisible) { |
|
7216 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) |
|
7217 qApp->d_func()->sendSyntheticEnterLeave(q); |
|
7218 #endif |
|
7219 |
|
7220 QWidget *fw = QApplication::focusWidget(); |
|
7221 while (fw && !fw->isWindow()) { |
|
7222 if (fw == q) { |
|
7223 q->focusNextPrevChild(true); |
|
7224 break; |
|
7225 } |
|
7226 fw = fw->parentWidget(); |
|
7227 } |
|
7228 } |
|
7229 |
|
7230 if (QWidgetBackingStore *bs = maybeBackingStore()) |
|
7231 bs->removeDirtyWidget(q); |
|
7232 |
|
7233 #ifndef QT_NO_ACCESSIBILITY |
|
7234 if (wasVisible) |
|
7235 QAccessible::updateAccessibility(q, 0, QAccessible::ObjectHide); |
|
7236 #endif |
|
7237 } |
|
7238 |
|
7239 /*! |
|
7240 \fn bool QWidget::isHidden() const |
|
7241 |
|
7242 Returns true if the widget is hidden, otherwise returns false. |
|
7243 |
|
7244 A hidden widget will only become visible when show() is called on |
|
7245 it. It will not be automatically shown when the parent is shown. |
|
7246 |
|
7247 To check visiblity, use !isVisible() instead (notice the exclamation mark). |
|
7248 |
|
7249 isHidden() implies !isVisible(), but a widget can be not visible |
|
7250 and not hidden at the same time. This is the case for widgets that are children of |
|
7251 widgets that are not visible. |
|
7252 |
|
7253 |
|
7254 Widgets are hidden if: |
|
7255 \list |
|
7256 \o they were created as independent windows, |
|
7257 \o they were created as children of visible widgets, |
|
7258 \o hide() or setVisible(false) was called. |
|
7259 \endlist |
|
7260 */ |
|
7261 |
|
7262 |
|
7263 void QWidget::setVisible(bool visible) |
|
7264 { |
|
7265 if (visible) { // show |
|
7266 if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) |
|
7267 return; |
|
7268 |
|
7269 Q_D(QWidget); |
|
7270 |
|
7271 // Designer uses a trick to make grabWidget work without showing |
|
7272 if (!isWindow() && parentWidget() && parentWidget()->isVisible() |
|
7273 && !parentWidget()->testAttribute(Qt::WA_WState_Created)) |
|
7274 parentWidget()->window()->d_func()->createRecursively(); |
|
7275 |
|
7276 //we have to at least create toplevels before applyX11SpecificCommandLineArguments |
|
7277 //but not children of non-visible parents |
|
7278 QWidget *pw = parentWidget(); |
|
7279 if (!testAttribute(Qt::WA_WState_Created) |
|
7280 && (isWindow() || pw->testAttribute(Qt::WA_WState_Created))) { |
|
7281 create(); |
|
7282 } |
|
7283 |
|
7284 #if defined(Q_WS_X11) |
|
7285 if (windowType() == Qt::Window) |
|
7286 QApplicationPrivate::applyX11SpecificCommandLineArguments(this); |
|
7287 #elif defined(Q_WS_QWS) |
|
7288 if (windowType() == Qt::Window) |
|
7289 QApplicationPrivate::applyQWSSpecificCommandLineArguments(this); |
|
7290 #endif |
|
7291 |
|
7292 bool wasResized = testAttribute(Qt::WA_Resized); |
|
7293 Qt::WindowStates initialWindowState = windowState(); |
|
7294 |
|
7295 // polish if necessary |
|
7296 ensurePolished(); |
|
7297 |
|
7298 // remember that show was called explicitly |
|
7299 setAttribute(Qt::WA_WState_ExplicitShowHide); |
|
7300 // whether we need to inform the parent widget immediately |
|
7301 bool needUpdateGeometry = !isWindow() && testAttribute(Qt::WA_WState_Hidden); |
|
7302 // we are no longer hidden |
|
7303 setAttribute(Qt::WA_WState_Hidden, false); |
|
7304 |
|
7305 if (needUpdateGeometry) |
|
7306 d->updateGeometry_helper(true); |
|
7307 |
|
7308 #ifdef QT3_SUPPORT |
|
7309 QApplication::sendPostedEvents(this, QEvent::ChildInserted); |
|
7310 #endif |
|
7311 // activate our layout before we and our children become visible |
|
7312 if (d->layout) |
|
7313 d->layout->activate(); |
|
7314 |
|
7315 if (!isWindow()) { |
|
7316 QWidget *parent = parentWidget(); |
|
7317 while (parent && parent->isVisible() && parent->d_func()->layout && !parent->data->in_show) { |
|
7318 parent->d_func()->layout->activate(); |
|
7319 if (parent->isWindow()) |
|
7320 break; |
|
7321 parent = parent->parentWidget(); |
|
7322 } |
|
7323 if (parent && !d->getOpaqueRegion().isEmpty()) |
|
7324 parent->d_func()->setDirtyOpaqueRegion(); |
|
7325 } |
|
7326 |
|
7327 // adjust size if necessary |
|
7328 if (!wasResized |
|
7329 && (isWindow() || !parentWidget()->d_func()->layout)) { |
|
7330 if (isWindow()) { |
|
7331 adjustSize(); |
|
7332 if (windowState() != initialWindowState) |
|
7333 setWindowState(initialWindowState); |
|
7334 } else { |
|
7335 adjustSize(); |
|
7336 } |
|
7337 setAttribute(Qt::WA_Resized, false); |
|
7338 } |
|
7339 |
|
7340 setAttribute(Qt::WA_KeyboardFocusChange, false); |
|
7341 |
|
7342 if (isWindow() || parentWidget()->isVisible()) { |
|
7343 // remove posted quit events when showing a new window |
|
7344 QCoreApplication::removePostedEvents(qApp, QEvent::Quit); |
|
7345 |
|
7346 d->show_helper(); |
|
7347 |
|
7348 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) |
|
7349 qApp->d_func()->sendSyntheticEnterLeave(this); |
|
7350 #endif |
|
7351 } |
|
7352 |
|
7353 QEvent showToParentEvent(QEvent::ShowToParent); |
|
7354 QApplication::sendEvent(this, &showToParentEvent); |
|
7355 } else { // hide |
|
7356 if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) |
|
7357 return; |
|
7358 #if defined(Q_WS_WIN) |
|
7359 // reset WS_DISABLED style in a Blocked window |
|
7360 if(isWindow() && testAttribute(Qt::WA_WState_Created) |
|
7361 && QApplicationPrivate::isBlockedByModal(this)) |
|
7362 { |
|
7363 LONG dwStyle = GetWindowLong(winId(), GWL_STYLE); |
|
7364 dwStyle &= ~WS_DISABLED; |
|
7365 SetWindowLong(winId(), GWL_STYLE, dwStyle); |
|
7366 } |
|
7367 #endif |
|
7368 if (QApplicationPrivate::hidden_focus_widget == this) |
|
7369 QApplicationPrivate::hidden_focus_widget = 0; |
|
7370 |
|
7371 Q_D(QWidget); |
|
7372 |
|
7373 // hw: The test on getOpaqueRegion() needs to be more intelligent |
|
7374 // currently it doesn't work if the widget is hidden (the region will |
|
7375 // be clipped). The real check should be testing the cached region |
|
7376 // (and dirty flag) directly. |
|
7377 if (!isWindow() && parentWidget()) // && !d->getOpaqueRegion().isEmpty()) |
|
7378 parentWidget()->d_func()->setDirtyOpaqueRegion(); |
|
7379 |
|
7380 setAttribute(Qt::WA_WState_Hidden); |
|
7381 setAttribute(Qt::WA_WState_ExplicitShowHide); |
|
7382 if (testAttribute(Qt::WA_WState_Created)) |
|
7383 d->hide_helper(); |
|
7384 |
|
7385 // invalidate layout similar to updateGeometry() |
|
7386 if (!isWindow() && parentWidget()) { |
|
7387 if (parentWidget()->d_func()->layout) |
|
7388 parentWidget()->d_func()->layout->invalidate(); |
|
7389 else if (parentWidget()->isVisible()) |
|
7390 QApplication::postEvent(parentWidget(), new QEvent(QEvent::LayoutRequest)); |
|
7391 } |
|
7392 |
|
7393 QEvent hideToParentEvent(QEvent::HideToParent); |
|
7394 QApplication::sendEvent(this, &hideToParentEvent); |
|
7395 } |
|
7396 } |
|
7397 |
|
7398 /*!\fn void QWidget::setHidden(bool hidden) |
|
7399 |
|
7400 Convenience function, equivalent to setVisible(!\a hidden). |
|
7401 */ |
|
7402 |
|
7403 /*!\fn void QWidget::setShown(bool shown) |
|
7404 |
|
7405 Use setVisible(\a shown) instead. |
|
7406 */ |
|
7407 |
|
7408 |
|
7409 void QWidgetPrivate::_q_showIfNotHidden() |
|
7410 { |
|
7411 Q_Q(QWidget); |
|
7412 if ( !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide)) ) |
|
7413 q->setVisible(true); |
|
7414 } |
|
7415 |
|
7416 void QWidgetPrivate::showChildren(bool spontaneous) |
|
7417 { |
|
7418 QList<QObject*> childList = children; |
|
7419 for (int i = 0; i < childList.size(); ++i) { |
|
7420 QWidget *widget = qobject_cast<QWidget*>(childList.at(i)); |
|
7421 if (!widget |
|
7422 || widget->isWindow() |
|
7423 || widget->testAttribute(Qt::WA_WState_Hidden)) |
|
7424 continue; |
|
7425 if (spontaneous) { |
|
7426 widget->setAttribute(Qt::WA_Mapped); |
|
7427 widget->d_func()->showChildren(true); |
|
7428 QShowEvent e; |
|
7429 QApplication::sendSpontaneousEvent(widget, &e); |
|
7430 } else { |
|
7431 if (widget->testAttribute(Qt::WA_WState_ExplicitShowHide)) |
|
7432 widget->d_func()->show_recursive(); |
|
7433 else |
|
7434 widget->show(); |
|
7435 } |
|
7436 } |
|
7437 } |
|
7438 |
|
7439 void QWidgetPrivate::hideChildren(bool spontaneous) |
|
7440 { |
|
7441 QList<QObject*> childList = children; |
|
7442 for (int i = 0; i < childList.size(); ++i) { |
|
7443 QWidget *widget = qobject_cast<QWidget*>(childList.at(i)); |
|
7444 if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden)) |
|
7445 continue; |
|
7446 if (spontaneous) |
|
7447 widget->setAttribute(Qt::WA_Mapped, false); |
|
7448 else |
|
7449 widget->setAttribute(Qt::WA_WState_Visible, false); |
|
7450 widget->d_func()->hideChildren(spontaneous); |
|
7451 QHideEvent e; |
|
7452 if (spontaneous) { |
|
7453 QApplication::sendSpontaneousEvent(widget, &e); |
|
7454 } else { |
|
7455 QApplication::sendEvent(widget, &e); |
|
7456 if (widget->internalWinId() |
|
7457 && widget->testAttribute(Qt::WA_DontCreateNativeAncestors)) { |
|
7458 // hide_sys() on an ancestor won't have any affect on this |
|
7459 // widget, so it needs an explicit hide_sys() of its own |
|
7460 widget->d_func()->hide_sys(); |
|
7461 } |
|
7462 } |
|
7463 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) |
|
7464 qApp->d_func()->sendSyntheticEnterLeave(widget); |
|
7465 #endif |
|
7466 #ifndef QT_NO_ACCESSIBILITY |
|
7467 if (!spontaneous) |
|
7468 QAccessible::updateAccessibility(widget, 0, QAccessible::ObjectHide); |
|
7469 #endif |
|
7470 } |
|
7471 } |
|
7472 |
|
7473 bool QWidgetPrivate::close_helper(CloseMode mode) |
|
7474 { |
|
7475 if (data.is_closing) |
|
7476 return true; |
|
7477 |
|
7478 Q_Q(QWidget); |
|
7479 data.is_closing = 1; |
|
7480 |
|
7481 QPointer<QWidget> that = q; |
|
7482 QPointer<QWidget> parentWidget = q->parentWidget(); |
|
7483 |
|
7484 #ifdef QT3_SUPPORT |
|
7485 bool isMain = (QApplicationPrivate::main_widget == q); |
|
7486 #endif |
|
7487 bool quitOnClose = q->testAttribute(Qt::WA_QuitOnClose); |
|
7488 if (mode != CloseNoEvent) { |
|
7489 QCloseEvent e; |
|
7490 if (mode == CloseWithSpontaneousEvent) |
|
7491 QApplication::sendSpontaneousEvent(q, &e); |
|
7492 else |
|
7493 QApplication::sendEvent(q, &e); |
|
7494 if (!that.isNull() && !e.isAccepted()) { |
|
7495 data.is_closing = 0; |
|
7496 return false; |
|
7497 } |
|
7498 } |
|
7499 |
|
7500 if (!that.isNull() && !q->isHidden()) |
|
7501 q->hide(); |
|
7502 |
|
7503 #ifdef QT3_SUPPORT |
|
7504 if (isMain) |
|
7505 QApplication::quit(); |
|
7506 #endif |
|
7507 // Attempt to close the application only if this widget has the |
|
7508 // WA_QuitOnClose flag set set and has a non-visible parent |
|
7509 quitOnClose = quitOnClose && (parentWidget.isNull() || !parentWidget->isVisible() || parentWidget->testAttribute(Qt::WA_DontShowOnScreen)); |
|
7510 |
|
7511 if (quitOnClose) { |
|
7512 // If there is no non-withdrawn primary window left (except |
|
7513 // the ones without QuitOnClose or with WA_DontShowOnScreen), |
|
7514 // we emit the lastWindowClosed signal |
|
7515 QWidgetList list = QApplication::topLevelWidgets(); |
|
7516 bool lastWindowClosed = true; |
|
7517 for (int i = 0; i < list.size(); ++i) { |
|
7518 QWidget *w = list.at(i); |
|
7519 if ((w->isVisible() && !w->testAttribute(Qt::WA_DontShowOnScreen)) |
|
7520 && !w->parentWidget() && w->testAttribute(Qt::WA_QuitOnClose)) { |
|
7521 lastWindowClosed = false; |
|
7522 break; |
|
7523 } |
|
7524 } |
|
7525 if (lastWindowClosed) |
|
7526 QApplicationPrivate::emitLastWindowClosed(); |
|
7527 } |
|
7528 |
|
7529 if (!that.isNull()) { |
|
7530 data.is_closing = 0; |
|
7531 if (q->testAttribute(Qt::WA_DeleteOnClose)) { |
|
7532 q->setAttribute(Qt::WA_DeleteOnClose, false); |
|
7533 q->deleteLater(); |
|
7534 } |
|
7535 } |
|
7536 return true; |
|
7537 } |
|
7538 |
|
7539 |
|
7540 /*! |
|
7541 Closes this widget. Returns true if the widget was closed; |
|
7542 otherwise returns false. |
|
7543 |
|
7544 First it sends the widget a QCloseEvent. The widget is \link |
|
7545 hide() hidden\endlink if it \link QCloseEvent::accept() |
|
7546 accepts\endlink the close event. If it \link QCloseEvent::ignore() |
|
7547 ignores\endlink the event, nothing happens. The default |
|
7548 implementation of QWidget::closeEvent() accepts the close event. |
|
7549 |
|
7550 If the widget has the Qt::WA_DeleteOnClose flag, the widget |
|
7551 is also deleted. A close events is delivered to the widget no |
|
7552 matter if the widget is visible or not. |
|
7553 |
|
7554 The \l QApplication::lastWindowClosed() signal is emitted when the |
|
7555 last visible primary window (i.e. window with no parent) with the |
|
7556 Qt::WA_QuitOnClose attribute set is closed. By default this |
|
7557 attribute is set for all widgets except transient windows such as |
|
7558 splash screens, tool windows, and popup menus. |
|
7559 |
|
7560 */ |
|
7561 |
|
7562 bool QWidget::close() |
|
7563 { |
|
7564 return d_func()->close_helper(QWidgetPrivate::CloseWithEvent); |
|
7565 } |
|
7566 |
|
7567 /*! |
|
7568 \property QWidget::visible |
|
7569 \brief whether the widget is visible |
|
7570 |
|
7571 Calling setVisible(true) or show() sets the widget to visible |
|
7572 status if all its parent widgets up to the window are visible. If |
|
7573 an ancestor is not visible, the widget won't become visible until |
|
7574 all its ancestors are shown. If its size or position has changed, |
|
7575 Qt guarantees that a widget gets move and resize events just |
|
7576 before it is shown. If the widget has not been resized yet, Qt |
|
7577 will adjust the widget's size to a useful default using |
|
7578 adjustSize(). |
|
7579 |
|
7580 Calling setVisible(false) or hide() hides a widget explicitly. An |
|
7581 explicitly hidden widget will never become visible, even if all |
|
7582 its ancestors become visible, unless you show it. |
|
7583 |
|
7584 A widget receives show and hide events when its visibility status |
|
7585 changes. Between a hide and a show event, there is no need to |
|
7586 waste CPU cycles preparing or displaying information to the user. |
|
7587 A video application, for example, might simply stop generating new |
|
7588 frames. |
|
7589 |
|
7590 A widget that happens to be obscured by other windows on the |
|
7591 screen is considered to be visible. The same applies to iconified |
|
7592 windows and windows that exist on another virtual |
|
7593 desktop (on platforms that support this concept). A widget |
|
7594 receives spontaneous show and hide events when its mapping status |
|
7595 is changed by the window system, e.g. a spontaneous hide event |
|
7596 when the user minimizes the window, and a spontaneous show event |
|
7597 when the window is restored again. |
|
7598 |
|
7599 You almost never have to reimplement the setVisible() function. If |
|
7600 you need to change some settings before a widget is shown, use |
|
7601 showEvent() instead. If you need to do some delayed initialization |
|
7602 use the Polish event delivered to the event() function. |
|
7603 |
|
7604 \sa show(), hide(), isHidden(), isVisibleTo(), isMinimized(), |
|
7605 showEvent(), hideEvent() |
|
7606 */ |
|
7607 |
|
7608 |
|
7609 /*! |
|
7610 Returns true if this widget would become visible if \a ancestor is |
|
7611 shown; otherwise returns false. |
|
7612 |
|
7613 The true case occurs if neither the widget itself nor any parent |
|
7614 up to but excluding \a ancestor has been explicitly hidden. |
|
7615 |
|
7616 This function will still return true if the widget is obscured by |
|
7617 other windows on the screen, but could be physically visible if it |
|
7618 or they were to be moved. |
|
7619 |
|
7620 isVisibleTo(0) is identical to isVisible(). |
|
7621 |
|
7622 \sa show() hide() isVisible() |
|
7623 */ |
|
7624 |
|
7625 bool QWidget::isVisibleTo(QWidget* ancestor) const |
|
7626 { |
|
7627 if (!ancestor) |
|
7628 return isVisible(); |
|
7629 const QWidget * w = this; |
|
7630 while (!w->isHidden() |
|
7631 && !w->isWindow() |
|
7632 && w->parentWidget() |
|
7633 && w->parentWidget() != ancestor) |
|
7634 w = w->parentWidget(); |
|
7635 return !w->isHidden(); |
|
7636 } |
|
7637 |
|
7638 #ifdef QT3_SUPPORT |
|
7639 /*! |
|
7640 Use visibleRegion() instead. |
|
7641 */ |
|
7642 QRect QWidget::visibleRect() const |
|
7643 { |
|
7644 return d_func()->clipRect(); |
|
7645 } |
|
7646 #endif |
|
7647 |
|
7648 /*! |
|
7649 Returns the unobscured region where paint events can occur. |
|
7650 |
|
7651 For visible widgets, this is an approximation of the area not |
|
7652 covered by other widgets; otherwise, this is an empty region. |
|
7653 |
|
7654 The repaint() function calls this function if necessary, so in |
|
7655 general you do not need to call it. |
|
7656 |
|
7657 */ |
|
7658 QRegion QWidget::visibleRegion() const |
|
7659 { |
|
7660 Q_D(const QWidget); |
|
7661 |
|
7662 QRect clipRect = d->clipRect(); |
|
7663 if (clipRect.isEmpty()) |
|
7664 return QRegion(); |
|
7665 QRegion r(clipRect); |
|
7666 d->subtractOpaqueChildren(r, clipRect); |
|
7667 d->subtractOpaqueSiblings(r); |
|
7668 #ifdef Q_WS_QWS |
|
7669 const QWSWindowSurface *surface = static_cast<const QWSWindowSurface*>(windowSurface()); |
|
7670 if (surface) { |
|
7671 const QPoint offset = mapTo(surface->window(), QPoint()); |
|
7672 r &= surface->clipRegion().translated(-offset); |
|
7673 } |
|
7674 #endif |
|
7675 return r; |
|
7676 } |
|
7677 |
|
7678 |
|
7679 QSize QWidgetPrivate::adjustedSize() const |
|
7680 { |
|
7681 Q_Q(const QWidget); |
|
7682 |
|
7683 QSize s = q->sizeHint(); |
|
7684 |
|
7685 if (q->isWindow()) { |
|
7686 Qt::Orientations exp; |
|
7687 if (layout) { |
|
7688 if (layout->hasHeightForWidth()) |
|
7689 s.setHeight(layout->totalHeightForWidth(s.width())); |
|
7690 exp = layout->expandingDirections(); |
|
7691 } else |
|
7692 { |
|
7693 if (q->sizePolicy().hasHeightForWidth()) |
|
7694 s.setHeight(q->heightForWidth(s.width())); |
|
7695 exp = q->sizePolicy().expandingDirections(); |
|
7696 } |
|
7697 if (exp & Qt::Horizontal) |
|
7698 s.setWidth(qMax(s.width(), 200)); |
|
7699 if (exp & Qt::Vertical) |
|
7700 s.setHeight(qMax(s.height(), 100)); |
|
7701 #if defined(Q_WS_X11) |
|
7702 QRect screen = QApplication::desktop()->screenGeometry(q->x11Info().screen()); |
|
7703 #else // all others |
|
7704 QRect screen = QApplication::desktop()->screenGeometry(q->pos()); |
|
7705 #endif |
|
7706 #if defined (Q_WS_WINCE) || defined (Q_OS_SYMBIAN) |
|
7707 s.setWidth(qMin(s.width(), screen.width())); |
|
7708 s.setHeight(qMin(s.height(), screen.height())); |
|
7709 #else |
|
7710 s.setWidth(qMin(s.width(), screen.width()*2/3)); |
|
7711 s.setHeight(qMin(s.height(), screen.height()*2/3)); |
|
7712 #endif |
|
7713 if (QTLWExtra *extra = maybeTopData()) |
|
7714 extra->sizeAdjusted = true; |
|
7715 } |
|
7716 |
|
7717 if (!s.isValid()) { |
|
7718 QRect r = q->childrenRect(); // get children rectangle |
|
7719 if (r.isNull()) |
|
7720 return s; |
|
7721 s = r.size() + QSize(2 * r.x(), 2 * r.y()); |
|
7722 } |
|
7723 |
|
7724 return s; |
|
7725 } |
|
7726 |
|
7727 /*! |
|
7728 Adjusts the size of the widget to fit its contents. |
|
7729 |
|
7730 This function uses sizeHint() if it is valid, i.e., the size hint's width |
|
7731 and height are \>= 0. Otherwise, it sets the size to the children |
|
7732 rectangle that covers all child widgets (the union of all child widget |
|
7733 rectangles). |
|
7734 |
|
7735 For windows, the screen size is also taken into account. If the sizeHint() |
|
7736 is less than (200, 100) and the size policy is \l{QSizePolicy::Expanding} |
|
7737 {expanding}, the window will be at least (200, 100). The maximum size of |
|
7738 a window is 2/3 of the screen's width and height. |
|
7739 |
|
7740 \sa sizeHint(), childrenRect() |
|
7741 */ |
|
7742 |
|
7743 void QWidget::adjustSize() |
|
7744 { |
|
7745 Q_D(QWidget); |
|
7746 ensurePolished(); |
|
7747 QSize s = d->adjustedSize(); |
|
7748 |
|
7749 if (d->layout) |
|
7750 d->layout->activate(); |
|
7751 |
|
7752 if (s.isValid()) |
|
7753 resize(s); |
|
7754 } |
|
7755 |
|
7756 |
|
7757 /*! |
|
7758 \property QWidget::sizeHint |
|
7759 \brief the recommended size for the widget |
|
7760 |
|
7761 If the value of this property is an invalid size, no size is |
|
7762 recommended. |
|
7763 |
|
7764 The default implementation of sizeHint() returns an invalid size |
|
7765 if there is no layout for this widget, and returns the layout's |
|
7766 preferred size otherwise. |
|
7767 |
|
7768 \sa QSize::isValid(), minimumSizeHint(), sizePolicy(), |
|
7769 setMinimumSize(), updateGeometry() |
|
7770 */ |
|
7771 |
|
7772 QSize QWidget::sizeHint() const |
|
7773 { |
|
7774 Q_D(const QWidget); |
|
7775 if (d->layout) |
|
7776 return d->layout->totalSizeHint(); |
|
7777 return QSize(-1, -1); |
|
7778 } |
|
7779 |
|
7780 /*! |
|
7781 \property QWidget::minimumSizeHint |
|
7782 \brief the recommended minimum size for the widget |
|
7783 |
|
7784 If the value of this property is an invalid size, no minimum size |
|
7785 is recommended. |
|
7786 |
|
7787 The default implementation of minimumSizeHint() returns an invalid |
|
7788 size if there is no layout for this widget, and returns the |
|
7789 layout's minimum size otherwise. Most built-in widgets reimplement |
|
7790 minimumSizeHint(). |
|
7791 |
|
7792 \l QLayout will never resize a widget to a size smaller than the |
|
7793 minimum size hint unless minimumSize() is set or the size policy is |
|
7794 set to QSizePolicy::Ignore. If minimumSize() is set, the minimum |
|
7795 size hint will be ignored. |
|
7796 |
|
7797 \sa QSize::isValid(), resize(), setMinimumSize(), sizePolicy() |
|
7798 */ |
|
7799 QSize QWidget::minimumSizeHint() const |
|
7800 { |
|
7801 Q_D(const QWidget); |
|
7802 if (d->layout) |
|
7803 return d->layout->totalMinimumSize(); |
|
7804 return QSize(-1, -1); |
|
7805 } |
|
7806 |
|
7807 |
|
7808 /*! |
|
7809 \fn QWidget *QWidget::parentWidget() const |
|
7810 |
|
7811 Returns the parent of this widget, or 0 if it does not have any |
|
7812 parent widget. |
|
7813 */ |
|
7814 |
|
7815 |
|
7816 /*! |
|
7817 Returns true if this widget is a parent, (or grandparent and so on |
|
7818 to any level), of the given \a child, and both widgets are within |
|
7819 the same window; otherwise returns false. |
|
7820 */ |
|
7821 |
|
7822 bool QWidget::isAncestorOf(const QWidget *child) const |
|
7823 { |
|
7824 while (child) { |
|
7825 if (child == this) |
|
7826 return true; |
|
7827 if (child->isWindow()) |
|
7828 return false; |
|
7829 child = child->parentWidget(); |
|
7830 } |
|
7831 return false; |
|
7832 } |
|
7833 |
|
7834 #if defined(Q_WS_WIN) |
|
7835 inline void setDisabledStyle(QWidget *w, bool setStyle) |
|
7836 { |
|
7837 // set/reset WS_DISABLED style. |
|
7838 if(w && w->isWindow() && w->isVisible() && w->isEnabled()) { |
|
7839 LONG dwStyle = GetWindowLong(w->winId(), GWL_STYLE); |
|
7840 if (setStyle) |
|
7841 dwStyle |= WS_DISABLED; |
|
7842 else |
|
7843 dwStyle &= ~WS_DISABLED; |
|
7844 SetWindowLong(w->winId(), GWL_STYLE, dwStyle); |
|
7845 // we might need to repaint in some situations (eg. menu) |
|
7846 w->repaint(); |
|
7847 } |
|
7848 } |
|
7849 #endif |
|
7850 |
|
7851 /***************************************************************************** |
|
7852 QWidget event handling |
|
7853 *****************************************************************************/ |
|
7854 |
|
7855 /*! |
|
7856 This is the main event handler; it handles event \a event. You can |
|
7857 reimplement this function in a subclass, but we recommend using |
|
7858 one of the specialized event handlers instead. |
|
7859 |
|
7860 Key press and release events are treated differently from other |
|
7861 events. event() checks for Tab and Shift+Tab and tries to move the |
|
7862 focus appropriately. If there is no widget to move the focus to |
|
7863 (or the key press is not Tab or Shift+Tab), event() calls |
|
7864 keyPressEvent(). |
|
7865 |
|
7866 Mouse and tablet event handling is also slightly special: only |
|
7867 when the widget is \l enabled, event() will call the specialized |
|
7868 handlers such as mousePressEvent(); otherwise it will discard the |
|
7869 event. |
|
7870 |
|
7871 This function returns true if the event was recognized, otherwise |
|
7872 it returns false. If the recognized event was accepted (see \l |
|
7873 QEvent::accepted), any further processing such as event |
|
7874 propagation to the parent widget stops. |
|
7875 |
|
7876 \sa closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(), |
|
7877 keyPressEvent(), keyReleaseEvent(), leaveEvent(), |
|
7878 mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), |
|
7879 mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(), |
|
7880 QObject::event(), QObject::timerEvent() |
|
7881 */ |
|
7882 |
|
7883 bool QWidget::event(QEvent *event) |
|
7884 { |
|
7885 Q_D(QWidget); |
|
7886 |
|
7887 // ignore mouse events when disabled |
|
7888 if (!isEnabled()) { |
|
7889 switch(event->type()) { |
|
7890 case QEvent::TabletPress: |
|
7891 case QEvent::TabletRelease: |
|
7892 case QEvent::TabletMove: |
|
7893 case QEvent::MouseButtonPress: |
|
7894 case QEvent::MouseButtonRelease: |
|
7895 case QEvent::MouseButtonDblClick: |
|
7896 case QEvent::MouseMove: |
|
7897 case QEvent::TouchBegin: |
|
7898 case QEvent::TouchUpdate: |
|
7899 case QEvent::TouchEnd: |
|
7900 case QEvent::ContextMenu: |
|
7901 #ifndef QT_NO_WHEELEVENT |
|
7902 case QEvent::Wheel: |
|
7903 #endif |
|
7904 return false; |
|
7905 default: |
|
7906 break; |
|
7907 } |
|
7908 } |
|
7909 switch (event->type()) { |
|
7910 case QEvent::MouseMove: |
|
7911 mouseMoveEvent((QMouseEvent*)event); |
|
7912 break; |
|
7913 |
|
7914 case QEvent::MouseButtonPress: |
|
7915 // Don't reset input context here. Whether reset or not is |
|
7916 // a responsibility of input method. reset() will be |
|
7917 // called by mouseHandler() of input method if necessary |
|
7918 // via mousePressEvent() of text widgets. |
|
7919 #if 0 |
|
7920 resetInputContext(); |
|
7921 #endif |
|
7922 mousePressEvent((QMouseEvent*)event); |
|
7923 break; |
|
7924 |
|
7925 case QEvent::MouseButtonRelease: |
|
7926 mouseReleaseEvent((QMouseEvent*)event); |
|
7927 break; |
|
7928 |
|
7929 case QEvent::MouseButtonDblClick: |
|
7930 mouseDoubleClickEvent((QMouseEvent*)event); |
|
7931 break; |
|
7932 #ifndef QT_NO_WHEELEVENT |
|
7933 case QEvent::Wheel: |
|
7934 wheelEvent((QWheelEvent*)event); |
|
7935 break; |
|
7936 #endif |
|
7937 #ifndef QT_NO_TABLETEVENT |
|
7938 case QEvent::TabletMove: |
|
7939 case QEvent::TabletPress: |
|
7940 case QEvent::TabletRelease: |
|
7941 tabletEvent((QTabletEvent*)event); |
|
7942 break; |
|
7943 #endif |
|
7944 #ifdef QT3_SUPPORT |
|
7945 case QEvent::Accel: |
|
7946 event->ignore(); |
|
7947 return false; |
|
7948 #endif |
|
7949 case QEvent::KeyPress: { |
|
7950 QKeyEvent *k = (QKeyEvent *)event; |
|
7951 bool res = false; |
|
7952 if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? |
|
7953 if (k->key() == Qt::Key_Backtab |
|
7954 || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) |
|
7955 res = focusNextPrevChild(false); |
|
7956 else if (k->key() == Qt::Key_Tab) |
|
7957 res = focusNextPrevChild(true); |
|
7958 if (res) |
|
7959 break; |
|
7960 } |
|
7961 keyPressEvent(k); |
|
7962 #ifdef QT_KEYPAD_NAVIGATION |
|
7963 if (!k->isAccepted() && QApplication::keypadNavigationEnabled() |
|
7964 && !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::ShiftModifier))) { |
|
7965 if (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder) { |
|
7966 if (k->key() == Qt::Key_Up) |
|
7967 res = focusNextPrevChild(false); |
|
7968 else if (k->key() == Qt::Key_Down) |
|
7969 res = focusNextPrevChild(true); |
|
7970 } else if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { |
|
7971 if (k->key() == Qt::Key_Up) |
|
7972 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionNorth); |
|
7973 else if (k->key() == Qt::Key_Right) |
|
7974 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionEast); |
|
7975 else if (k->key() == Qt::Key_Down) |
|
7976 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionSouth); |
|
7977 else if (k->key() == Qt::Key_Left) |
|
7978 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionWest); |
|
7979 } |
|
7980 if (res) { |
|
7981 k->accept(); |
|
7982 break; |
|
7983 } |
|
7984 } |
|
7985 #endif |
|
7986 #ifndef QT_NO_WHATSTHIS |
|
7987 if (!k->isAccepted() |
|
7988 && k->modifiers() & Qt::ShiftModifier && k->key() == Qt::Key_F1 |
|
7989 && d->whatsThis.size()) { |
|
7990 QWhatsThis::showText(mapToGlobal(inputMethodQuery(Qt::ImMicroFocus).toRect().center()), d->whatsThis, this); |
|
7991 k->accept(); |
|
7992 } |
|
7993 #endif |
|
7994 } |
|
7995 break; |
|
7996 |
|
7997 case QEvent::KeyRelease: |
|
7998 keyReleaseEvent((QKeyEvent*)event); |
|
7999 // fall through |
|
8000 case QEvent::ShortcutOverride: |
|
8001 break; |
|
8002 |
|
8003 case QEvent::InputMethod: |
|
8004 inputMethodEvent((QInputMethodEvent *) event); |
|
8005 break; |
|
8006 |
|
8007 case QEvent::PolishRequest: |
|
8008 ensurePolished(); |
|
8009 break; |
|
8010 |
|
8011 case QEvent::Polish: { |
|
8012 style()->polish(this); |
|
8013 setAttribute(Qt::WA_WState_Polished); |
|
8014 if (!QApplication::font(this).isCopyOf(QApplication::font())) |
|
8015 d->resolveFont(); |
|
8016 if (!QApplication::palette(this).isCopyOf(QApplication::palette())) |
|
8017 d->resolvePalette(); |
|
8018 #ifdef QT3_SUPPORT |
|
8019 if(d->sendChildEvents) |
|
8020 QApplication::sendPostedEvents(this, QEvent::ChildInserted); |
|
8021 #endif |
|
8022 } |
|
8023 break; |
|
8024 |
|
8025 case QEvent::ApplicationWindowIconChange: |
|
8026 if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon)) { |
|
8027 d->setWindowIcon_sys(); |
|
8028 d->setWindowIcon_helper(); |
|
8029 } |
|
8030 break; |
|
8031 case QEvent::FocusIn: |
|
8032 #ifdef QT_SOFTKEYS_ENABLED |
|
8033 QSoftKeyManager::updateSoftKeys(); |
|
8034 #endif |
|
8035 focusInEvent((QFocusEvent*)event); |
|
8036 break; |
|
8037 |
|
8038 case QEvent::FocusOut: |
|
8039 focusOutEvent((QFocusEvent*)event); |
|
8040 break; |
|
8041 |
|
8042 case QEvent::Enter: |
|
8043 #ifndef QT_NO_STATUSTIP |
|
8044 if (d->statusTip.size()) { |
|
8045 QStatusTipEvent tip(d->statusTip); |
|
8046 QApplication::sendEvent(const_cast<QWidget *>(this), &tip); |
|
8047 } |
|
8048 #endif |
|
8049 enterEvent(event); |
|
8050 break; |
|
8051 |
|
8052 case QEvent::Leave: |
|
8053 #ifndef QT_NO_STATUSTIP |
|
8054 if (d->statusTip.size()) { |
|
8055 QString empty; |
|
8056 QStatusTipEvent tip(empty); |
|
8057 QApplication::sendEvent(const_cast<QWidget *>(this), &tip); |
|
8058 } |
|
8059 #endif |
|
8060 leaveEvent(event); |
|
8061 break; |
|
8062 |
|
8063 case QEvent::HoverEnter: |
|
8064 case QEvent::HoverLeave: |
|
8065 update(); |
|
8066 break; |
|
8067 |
|
8068 case QEvent::Paint: |
|
8069 // At this point the event has to be delivered, regardless |
|
8070 // whether the widget isVisible() or not because it |
|
8071 // already went through the filters |
|
8072 paintEvent((QPaintEvent*)event); |
|
8073 break; |
|
8074 |
|
8075 case QEvent::Move: |
|
8076 moveEvent((QMoveEvent*)event); |
|
8077 break; |
|
8078 |
|
8079 case QEvent::Resize: |
|
8080 resizeEvent((QResizeEvent*)event); |
|
8081 break; |
|
8082 |
|
8083 case QEvent::Close: |
|
8084 closeEvent((QCloseEvent *)event); |
|
8085 break; |
|
8086 |
|
8087 #ifndef QT_NO_CONTEXTMENU |
|
8088 case QEvent::ContextMenu: |
|
8089 switch (data->context_menu_policy) { |
|
8090 case Qt::PreventContextMenu: |
|
8091 break; |
|
8092 case Qt::DefaultContextMenu: |
|
8093 contextMenuEvent(static_cast<QContextMenuEvent *>(event)); |
|
8094 break; |
|
8095 case Qt::CustomContextMenu: |
|
8096 emit customContextMenuRequested(static_cast<QContextMenuEvent *>(event)->pos()); |
|
8097 break; |
|
8098 #ifndef QT_NO_MENU |
|
8099 case Qt::ActionsContextMenu: |
|
8100 if (d->actions.count()) { |
|
8101 QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos(), |
|
8102 0, this); |
|
8103 break; |
|
8104 } |
|
8105 // fall through |
|
8106 #endif |
|
8107 default: |
|
8108 event->ignore(); |
|
8109 break; |
|
8110 } |
|
8111 break; |
|
8112 #endif // QT_NO_CONTEXTMENU |
|
8113 |
|
8114 #ifndef QT_NO_DRAGANDDROP |
|
8115 case QEvent::Drop: |
|
8116 dropEvent((QDropEvent*) event); |
|
8117 break; |
|
8118 |
|
8119 case QEvent::DragEnter: |
|
8120 dragEnterEvent((QDragEnterEvent*) event); |
|
8121 break; |
|
8122 |
|
8123 case QEvent::DragMove: |
|
8124 dragMoveEvent((QDragMoveEvent*) event); |
|
8125 break; |
|
8126 |
|
8127 case QEvent::DragLeave: |
|
8128 dragLeaveEvent((QDragLeaveEvent*) event); |
|
8129 break; |
|
8130 #endif |
|
8131 |
|
8132 case QEvent::Show: |
|
8133 showEvent((QShowEvent*) event); |
|
8134 break; |
|
8135 |
|
8136 case QEvent::Hide: |
|
8137 hideEvent((QHideEvent*) event); |
|
8138 break; |
|
8139 |
|
8140 case QEvent::ShowWindowRequest: |
|
8141 if (!isHidden()) |
|
8142 d->show_sys(); |
|
8143 break; |
|
8144 |
|
8145 case QEvent::ApplicationFontChange: |
|
8146 d->resolveFont(); |
|
8147 break; |
|
8148 case QEvent::ApplicationPaletteChange: |
|
8149 if (!(windowType() == Qt::Desktop)) |
|
8150 d->resolvePalette(); |
|
8151 break; |
|
8152 |
|
8153 case QEvent::ToolBarChange: |
|
8154 case QEvent::ActivationChange: |
|
8155 case QEvent::EnabledChange: |
|
8156 case QEvent::FontChange: |
|
8157 case QEvent::StyleChange: |
|
8158 case QEvent::PaletteChange: |
|
8159 case QEvent::WindowTitleChange: |
|
8160 case QEvent::IconTextChange: |
|
8161 case QEvent::ModifiedChange: |
|
8162 case QEvent::MouseTrackingChange: |
|
8163 case QEvent::ParentChange: |
|
8164 case QEvent::WindowStateChange: |
|
8165 case QEvent::LocaleChange: |
|
8166 case QEvent::MacSizeChange: |
|
8167 case QEvent::ContentsRectChange: |
|
8168 changeEvent(event); |
|
8169 break; |
|
8170 |
|
8171 case QEvent::WindowActivate: |
|
8172 case QEvent::WindowDeactivate: { |
|
8173 #ifdef QT3_SUPPORT |
|
8174 windowActivationChange(event->type() != QEvent::WindowActivate); |
|
8175 #endif |
|
8176 if (isVisible() && !palette().isEqual(QPalette::Active, QPalette::Inactive)) |
|
8177 update(); |
|
8178 QList<QObject*> childList = d->children; |
|
8179 for (int i = 0; i < childList.size(); ++i) { |
|
8180 QWidget *w = qobject_cast<QWidget *>(childList.at(i)); |
|
8181 if (w && w->isVisible() && !w->isWindow()) |
|
8182 QApplication::sendEvent(w, event); |
|
8183 } |
|
8184 |
|
8185 #ifdef QT_SOFTKEYS_ENABLED |
|
8186 if (isWindow() && isActiveWindow()) |
|
8187 QSoftKeyManager::updateSoftKeys(); |
|
8188 #endif |
|
8189 |
|
8190 break; } |
|
8191 |
|
8192 case QEvent::LanguageChange: |
|
8193 #ifdef QT3_SUPPORT |
|
8194 languageChange(); |
|
8195 #endif |
|
8196 changeEvent(event); |
|
8197 { |
|
8198 QList<QObject*> childList = d->children; |
|
8199 for (int i = 0; i < childList.size(); ++i) { |
|
8200 QObject *o = childList.at(i); |
|
8201 QApplication::sendEvent(o, event); |
|
8202 } |
|
8203 } |
|
8204 update(); |
|
8205 break; |
|
8206 |
|
8207 case QEvent::ApplicationLayoutDirectionChange: |
|
8208 d->resolveLayoutDirection(); |
|
8209 break; |
|
8210 |
|
8211 case QEvent::LayoutDirectionChange: |
|
8212 if (d->layout) |
|
8213 d->layout->invalidate(); |
|
8214 update(); |
|
8215 changeEvent(event); |
|
8216 break; |
|
8217 case QEvent::UpdateRequest: |
|
8218 d->syncBackingStore(); |
|
8219 break; |
|
8220 case QEvent::UpdateLater: |
|
8221 update(static_cast<QUpdateLaterEvent*>(event)->region()); |
|
8222 break; |
|
8223 |
|
8224 case QEvent::WindowBlocked: |
|
8225 case QEvent::WindowUnblocked: |
|
8226 { |
|
8227 QList<QObject*> childList = d->children; |
|
8228 for (int i = 0; i < childList.size(); ++i) { |
|
8229 QObject *o = childList.at(i); |
|
8230 if (o != QApplication::activeModalWidget()) { |
|
8231 if (qobject_cast<QWidget *>(o) && static_cast<QWidget *>(o)->isWindow()) { |
|
8232 // do not forward the event to child windows, |
|
8233 // QApplication does this for us |
|
8234 continue; |
|
8235 } |
|
8236 QApplication::sendEvent(o, event); |
|
8237 } |
|
8238 } |
|
8239 #if defined(Q_WS_WIN) |
|
8240 setDisabledStyle(this, (event->type() == QEvent::WindowBlocked)); |
|
8241 #endif |
|
8242 } |
|
8243 break; |
|
8244 #ifndef QT_NO_TOOLTIP |
|
8245 case QEvent::ToolTip: |
|
8246 if (!d->toolTip.isEmpty()) |
|
8247 QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), d->toolTip, this); |
|
8248 else |
|
8249 event->ignore(); |
|
8250 break; |
|
8251 #endif |
|
8252 #ifndef QT_NO_WHATSTHIS |
|
8253 case QEvent::WhatsThis: |
|
8254 if (d->whatsThis.size()) |
|
8255 QWhatsThis::showText(static_cast<QHelpEvent *>(event)->globalPos(), d->whatsThis, this); |
|
8256 else |
|
8257 event->ignore(); |
|
8258 break; |
|
8259 case QEvent::QueryWhatsThis: |
|
8260 if (d->whatsThis.isEmpty()) |
|
8261 event->ignore(); |
|
8262 break; |
|
8263 #endif |
|
8264 #ifndef QT_NO_ACCESSIBILITY |
|
8265 case QEvent::AccessibilityDescription: |
|
8266 case QEvent::AccessibilityHelp: { |
|
8267 QAccessibleEvent *ev = static_cast<QAccessibleEvent *>(event); |
|
8268 if (ev->child()) |
|
8269 return false; |
|
8270 switch (ev->type()) { |
|
8271 #ifndef QT_NO_TOOLTIP |
|
8272 case QEvent::AccessibilityDescription: |
|
8273 ev->setValue(d->toolTip); |
|
8274 break; |
|
8275 #endif |
|
8276 #ifndef QT_NO_WHATSTHIS |
|
8277 case QEvent::AccessibilityHelp: |
|
8278 ev->setValue(d->whatsThis); |
|
8279 break; |
|
8280 #endif |
|
8281 default: |
|
8282 return false; |
|
8283 } |
|
8284 break; } |
|
8285 #endif |
|
8286 case QEvent::EmbeddingControl: |
|
8287 d->topData()->frameStrut.setCoords(0 ,0, 0, 0); |
|
8288 data->fstrut_dirty = false; |
|
8289 #if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
8290 d->topData()->embedded = 1; |
|
8291 #endif |
|
8292 break; |
|
8293 #ifndef QT_NO_ACTION |
|
8294 case QEvent::ActionAdded: |
|
8295 case QEvent::ActionRemoved: |
|
8296 case QEvent::ActionChanged: |
|
8297 #ifdef QT_SOFTKEYS_ENABLED |
|
8298 QSoftKeyManager::updateSoftKeys(); |
|
8299 #endif |
|
8300 actionEvent((QActionEvent*)event); |
|
8301 break; |
|
8302 #endif |
|
8303 |
|
8304 case QEvent::KeyboardLayoutChange: |
|
8305 { |
|
8306 changeEvent(event); |
|
8307 |
|
8308 // inform children of the change |
|
8309 QList<QObject*> childList = d->children; |
|
8310 for (int i = 0; i < childList.size(); ++i) { |
|
8311 QWidget *w = qobject_cast<QWidget *>(childList.at(i)); |
|
8312 if (w && w->isVisible() && !w->isWindow()) |
|
8313 QApplication::sendEvent(w, event); |
|
8314 } |
|
8315 break; |
|
8316 } |
|
8317 #ifdef Q_WS_MAC |
|
8318 case QEvent::MacGLWindowChange: |
|
8319 d->needWindowChange = false; |
|
8320 break; |
|
8321 #endif |
|
8322 case QEvent::TouchBegin: |
|
8323 case QEvent::TouchUpdate: |
|
8324 case QEvent::TouchEnd: |
|
8325 { |
|
8326 QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); |
|
8327 const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first(); |
|
8328 if (touchPoint.isPrimary()) |
|
8329 break; |
|
8330 |
|
8331 // fake a mouse event! |
|
8332 QEvent::Type eventType = QEvent::None; |
|
8333 switch (touchEvent->type()) { |
|
8334 case QEvent::TouchBegin: |
|
8335 eventType = QEvent::MouseButtonPress; |
|
8336 break; |
|
8337 case QEvent::TouchUpdate: |
|
8338 eventType = QEvent::MouseMove; |
|
8339 break; |
|
8340 case QEvent::TouchEnd: |
|
8341 eventType = QEvent::MouseButtonRelease; |
|
8342 break; |
|
8343 default: |
|
8344 Q_ASSERT(!true); |
|
8345 break; |
|
8346 } |
|
8347 if (eventType == QEvent::None) |
|
8348 break; |
|
8349 |
|
8350 QMouseEvent mouseEvent(eventType, |
|
8351 touchPoint.pos().toPoint(), |
|
8352 touchPoint.screenPos().toPoint(), |
|
8353 Qt::LeftButton, |
|
8354 Qt::LeftButton, |
|
8355 touchEvent->modifiers()); |
|
8356 (void) QApplication::sendEvent(this, &mouseEvent); |
|
8357 break; |
|
8358 } |
|
8359 case QEvent::Gesture: |
|
8360 event->ignore(); |
|
8361 break; |
|
8362 #ifndef QT_NO_PROPERTIES |
|
8363 case QEvent::DynamicPropertyChange: { |
|
8364 const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName(); |
|
8365 if (!qstrncmp(propName, "_q_customDpi", 12) && propName.length() == 13) { |
|
8366 uint value = property(propName.constData()).toUInt(); |
|
8367 if (!d->extra) |
|
8368 d->createExtra(); |
|
8369 const char axis = propName.at(12); |
|
8370 if (axis == 'X') |
|
8371 d->extra->customDpiX = value; |
|
8372 else if (axis == 'Y') |
|
8373 d->extra->customDpiY = value; |
|
8374 d->updateFont(d->data.fnt); |
|
8375 } |
|
8376 // fall through |
|
8377 } |
|
8378 #endif |
|
8379 default: |
|
8380 return QObject::event(event); |
|
8381 } |
|
8382 return true; |
|
8383 } |
|
8384 |
|
8385 /*! |
|
8386 This event handler can be reimplemented to handle state changes. |
|
8387 |
|
8388 The state being changed in this event can be retrieved through event \a |
|
8389 event. |
|
8390 |
|
8391 Change events include: QEvent::ToolBarChange, |
|
8392 QEvent::ActivationChange, QEvent::EnabledChange, QEvent::FontChange, |
|
8393 QEvent::StyleChange, QEvent::PaletteChange, |
|
8394 QEvent::WindowTitleChange, QEvent::IconTextChange, |
|
8395 QEvent::ModifiedChange, QEvent::MouseTrackingChange, |
|
8396 QEvent::ParentChange, QEvent::WindowStateChange, |
|
8397 QEvent::LanguageChange, QEvent::LocaleChange, |
|
8398 QEvent::LayoutDirectionChange. |
|
8399 |
|
8400 */ |
|
8401 void QWidget::changeEvent(QEvent * event) |
|
8402 { |
|
8403 switch(event->type()) { |
|
8404 case QEvent::EnabledChange: |
|
8405 update(); |
|
8406 #ifndef QT_NO_ACCESSIBILITY |
|
8407 QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged); |
|
8408 #endif |
|
8409 break; |
|
8410 |
|
8411 case QEvent::FontChange: |
|
8412 case QEvent::StyleChange: { |
|
8413 Q_D(QWidget); |
|
8414 update(); |
|
8415 updateGeometry(); |
|
8416 if (d->layout) |
|
8417 d->layout->invalidate(); |
|
8418 #ifdef Q_WS_QWS |
|
8419 if (isWindow()) |
|
8420 d->data.fstrut_dirty = true; |
|
8421 #endif |
|
8422 break; |
|
8423 } |
|
8424 |
|
8425 case QEvent::PaletteChange: |
|
8426 update(); |
|
8427 break; |
|
8428 |
|
8429 #ifdef Q_WS_MAC |
|
8430 case QEvent::MacSizeChange: |
|
8431 updateGeometry(); |
|
8432 break; |
|
8433 case QEvent::ToolTipChange: |
|
8434 case QEvent::MouseTrackingChange: |
|
8435 qt_mac_update_mouseTracking(this); |
|
8436 break; |
|
8437 #endif |
|
8438 |
|
8439 default: |
|
8440 break; |
|
8441 } |
|
8442 } |
|
8443 |
|
8444 /*! |
|
8445 This event handler, for event \a event, can be reimplemented in a |
|
8446 subclass to receive mouse move events for the widget. |
|
8447 |
|
8448 If mouse tracking is switched off, mouse move events only occur if |
|
8449 a mouse button is pressed while the mouse is being moved. If mouse |
|
8450 tracking is switched on, mouse move events occur even if no mouse |
|
8451 button is pressed. |
|
8452 |
|
8453 QMouseEvent::pos() reports the position of the mouse cursor, |
|
8454 relative to this widget. For press and release events, the |
|
8455 position is usually the same as the position of the last mouse |
|
8456 move event, but it might be different if the user's hand shakes. |
|
8457 This is a feature of the underlying window system, not Qt. |
|
8458 |
|
8459 If you want to show a tooltip immediately, while the mouse is |
|
8460 moving (e.g., to get the mouse coordinates with QMouseEvent::pos() |
|
8461 and show them as a tooltip), you must first enable mouse tracking |
|
8462 as described above. Then, to ensure that the tooltip is updated |
|
8463 immediately, you must call QToolTip::showText() instead of |
|
8464 setToolTip() in your implementation of mouseMoveEvent(). |
|
8465 |
|
8466 \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(), |
|
8467 mouseDoubleClickEvent(), event(), QMouseEvent, {Scribble Example} |
|
8468 */ |
|
8469 |
|
8470 void QWidget::mouseMoveEvent(QMouseEvent *event) |
|
8471 { |
|
8472 event->ignore(); |
|
8473 } |
|
8474 |
|
8475 /*! |
|
8476 This event handler, for event \a event, can be reimplemented in a |
|
8477 subclass to receive mouse press events for the widget. |
|
8478 |
|
8479 If you create new widgets in the mousePressEvent() the |
|
8480 mouseReleaseEvent() may not end up where you expect, depending on |
|
8481 the underlying window system (or X11 window manager), the widgets' |
|
8482 location and maybe more. |
|
8483 |
|
8484 The default implementation implements the closing of popup widgets |
|
8485 when you click outside the window. For other widget types it does |
|
8486 nothing. |
|
8487 |
|
8488 \sa mouseReleaseEvent(), mouseDoubleClickEvent(), |
|
8489 mouseMoveEvent(), event(), QMouseEvent, {Scribble Example} |
|
8490 */ |
|
8491 |
|
8492 void QWidget::mousePressEvent(QMouseEvent *event) |
|
8493 { |
|
8494 event->ignore(); |
|
8495 if ((windowType() == Qt::Popup)) { |
|
8496 event->accept(); |
|
8497 QWidget* w; |
|
8498 while ((w = QApplication::activePopupWidget()) && w != this){ |
|
8499 w->close(); |
|
8500 if (QApplication::activePopupWidget() == w) // widget does not want to dissappear |
|
8501 w->hide(); // hide at least |
|
8502 } |
|
8503 if (!rect().contains(event->pos())){ |
|
8504 close(); |
|
8505 } |
|
8506 } |
|
8507 } |
|
8508 |
|
8509 /*! |
|
8510 This event handler, for event \a event, can be reimplemented in a |
|
8511 subclass to receive mouse release events for the widget. |
|
8512 |
|
8513 \sa mousePressEvent(), mouseDoubleClickEvent(), |
|
8514 mouseMoveEvent(), event(), QMouseEvent, {Scribble Example} |
|
8515 */ |
|
8516 |
|
8517 void QWidget::mouseReleaseEvent(QMouseEvent *event) |
|
8518 { |
|
8519 event->ignore(); |
|
8520 } |
|
8521 |
|
8522 /*! |
|
8523 This event handler, for event \a event, can be reimplemented in a |
|
8524 subclass to receive mouse double click events for the widget. |
|
8525 |
|
8526 The default implementation generates a normal mouse press event. |
|
8527 |
|
8528 \note The widget will also receive mouse press and mouse release |
|
8529 events in addition to the double click event. It is up to the |
|
8530 developer to ensure that the application interprets these events |
|
8531 correctly. |
|
8532 |
|
8533 \sa mousePressEvent(), mouseReleaseEvent() mouseMoveEvent(), |
|
8534 event(), QMouseEvent |
|
8535 */ |
|
8536 |
|
8537 void QWidget::mouseDoubleClickEvent(QMouseEvent *event) |
|
8538 { |
|
8539 mousePressEvent(event); // try mouse press event |
|
8540 } |
|
8541 |
|
8542 #ifndef QT_NO_WHEELEVENT |
|
8543 /*! |
|
8544 This event handler, for event \a event, can be reimplemented in a |
|
8545 subclass to receive wheel events for the widget. |
|
8546 |
|
8547 If you reimplement this handler, it is very important that you |
|
8548 \link QWheelEvent ignore()\endlink the event if you do not handle |
|
8549 it, so that the widget's parent can interpret it. |
|
8550 |
|
8551 The default implementation ignores the event. |
|
8552 |
|
8553 \sa QWheelEvent::ignore(), QWheelEvent::accept(), event(), |
|
8554 QWheelEvent |
|
8555 */ |
|
8556 |
|
8557 void QWidget::wheelEvent(QWheelEvent *event) |
|
8558 { |
|
8559 event->ignore(); |
|
8560 } |
|
8561 #endif // QT_NO_WHEELEVENT |
|
8562 |
|
8563 #ifndef QT_NO_TABLETEVENT |
|
8564 /*! |
|
8565 This event handler, for event \a event, can be reimplemented in a |
|
8566 subclass to receive tablet events for the widget. |
|
8567 |
|
8568 If you reimplement this handler, it is very important that you |
|
8569 \link QTabletEvent ignore()\endlink the event if you do not handle |
|
8570 it, so that the widget's parent can interpret it. |
|
8571 |
|
8572 The default implementation ignores the event. |
|
8573 |
|
8574 \sa QTabletEvent::ignore(), QTabletEvent::accept(), event(), |
|
8575 QTabletEvent |
|
8576 */ |
|
8577 |
|
8578 void QWidget::tabletEvent(QTabletEvent *event) |
|
8579 { |
|
8580 event->ignore(); |
|
8581 } |
|
8582 #endif // QT_NO_TABLETEVENT |
|
8583 |
|
8584 /*! |
|
8585 This event handler, for event \a event, can be reimplemented in a |
|
8586 subclass to receive key press events for the widget. |
|
8587 |
|
8588 A widget must call setFocusPolicy() to accept focus initially and |
|
8589 have focus in order to receive a key press event. |
|
8590 |
|
8591 If you reimplement this handler, it is very important that you |
|
8592 call the base class implementation if you do not act upon the key. |
|
8593 |
|
8594 The default implementation closes popup widgets if the user |
|
8595 presses Esc. Otherwise the event is ignored, so that the widget's |
|
8596 parent can interpret it. |
|
8597 |
|
8598 Note that QKeyEvent starts with isAccepted() == true, so you do not |
|
8599 need to call QKeyEvent::accept() - just do not call the base class |
|
8600 implementation if you act upon the key. |
|
8601 |
|
8602 \sa keyReleaseEvent(), setFocusPolicy(), |
|
8603 focusInEvent(), focusOutEvent(), event(), QKeyEvent, {Tetrix Example} |
|
8604 */ |
|
8605 |
|
8606 void QWidget::keyPressEvent(QKeyEvent *event) |
|
8607 { |
|
8608 if ((windowType() == Qt::Popup) && event->key() == Qt::Key_Escape) { |
|
8609 event->accept(); |
|
8610 close(); |
|
8611 } else { |
|
8612 event->ignore(); |
|
8613 } |
|
8614 } |
|
8615 |
|
8616 /*! |
|
8617 This event handler, for event \a event, can be reimplemented in a |
|
8618 subclass to receive key release events for the widget. |
|
8619 |
|
8620 A widget must \link setFocusPolicy() accept focus\endlink |
|
8621 initially and \link hasFocus() have focus\endlink in order to |
|
8622 receive a key release event. |
|
8623 |
|
8624 If you reimplement this handler, it is very important that you |
|
8625 call the base class implementation if you do not act upon the key. |
|
8626 |
|
8627 The default implementation ignores the event, so that the widget's |
|
8628 parent can interpret it. |
|
8629 |
|
8630 Note that QKeyEvent starts with isAccepted() == true, so you do not |
|
8631 need to call QKeyEvent::accept() - just do not call the base class |
|
8632 implementation if you act upon the key. |
|
8633 |
|
8634 \sa keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(), |
|
8635 focusInEvent(), focusOutEvent(), event(), QKeyEvent |
|
8636 */ |
|
8637 |
|
8638 void QWidget::keyReleaseEvent(QKeyEvent *event) |
|
8639 { |
|
8640 event->ignore(); |
|
8641 } |
|
8642 |
|
8643 /*! |
|
8644 \fn void QWidget::focusInEvent(QFocusEvent *event) |
|
8645 |
|
8646 This event handler can be reimplemented in a subclass to receive |
|
8647 keyboard focus events (focus received) for the widget. The event |
|
8648 is passed in the \a event parameter |
|
8649 |
|
8650 A widget normally must setFocusPolicy() to something other than |
|
8651 Qt::NoFocus in order to receive focus events. (Note that the |
|
8652 application programmer can call setFocus() on any widget, even |
|
8653 those that do not normally accept focus.) |
|
8654 |
|
8655 The default implementation updates the widget (except for windows |
|
8656 that do not specify a focusPolicy()). |
|
8657 |
|
8658 \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(), |
|
8659 keyReleaseEvent(), event(), QFocusEvent |
|
8660 */ |
|
8661 |
|
8662 void QWidget::focusInEvent(QFocusEvent *) |
|
8663 { |
|
8664 if (focusPolicy() != Qt::NoFocus || !isWindow()) { |
|
8665 update(); |
|
8666 } |
|
8667 } |
|
8668 |
|
8669 /*! |
|
8670 \fn void QWidget::focusOutEvent(QFocusEvent *event) |
|
8671 |
|
8672 This event handler can be reimplemented in a subclass to receive |
|
8673 keyboard focus events (focus lost) for the widget. The events is |
|
8674 passed in the \a event parameter. |
|
8675 |
|
8676 A widget normally must setFocusPolicy() to something other than |
|
8677 Qt::NoFocus in order to receive focus events. (Note that the |
|
8678 application programmer can call setFocus() on any widget, even |
|
8679 those that do not normally accept focus.) |
|
8680 |
|
8681 The default implementation updates the widget (except for windows |
|
8682 that do not specify a focusPolicy()). |
|
8683 |
|
8684 \sa focusInEvent(), setFocusPolicy(), keyPressEvent(), |
|
8685 keyReleaseEvent(), event(), QFocusEvent |
|
8686 */ |
|
8687 |
|
8688 void QWidget::focusOutEvent(QFocusEvent *) |
|
8689 { |
|
8690 if (focusPolicy() != Qt::NoFocus || !isWindow()) |
|
8691 update(); |
|
8692 } |
|
8693 |
|
8694 /*! |
|
8695 \fn void QWidget::enterEvent(QEvent *event) |
|
8696 |
|
8697 This event handler can be reimplemented in a subclass to receive |
|
8698 widget enter events which are passed in the \a event parameter. |
|
8699 |
|
8700 An event is sent to the widget when the mouse cursor enters the |
|
8701 widget. |
|
8702 |
|
8703 \sa leaveEvent(), mouseMoveEvent(), event() |
|
8704 */ |
|
8705 |
|
8706 void QWidget::enterEvent(QEvent *) |
|
8707 { |
|
8708 } |
|
8709 |
|
8710 /*! |
|
8711 \fn void QWidget::leaveEvent(QEvent *event) |
|
8712 |
|
8713 This event handler can be reimplemented in a subclass to receive |
|
8714 widget leave events which are passed in the \a event parameter. |
|
8715 |
|
8716 A leave event is sent to the widget when the mouse cursor leaves |
|
8717 the widget. |
|
8718 |
|
8719 \sa enterEvent(), mouseMoveEvent(), event() |
|
8720 */ |
|
8721 |
|
8722 void QWidget::leaveEvent(QEvent *) |
|
8723 { |
|
8724 } |
|
8725 |
|
8726 /*! |
|
8727 \fn void QWidget::paintEvent(QPaintEvent *event) |
|
8728 |
|
8729 This event handler can be reimplemented in a subclass to receive paint |
|
8730 events passed in \a event. |
|
8731 |
|
8732 A paint event is a request to repaint all or part of a widget. It can |
|
8733 happen for one of the following reasons: |
|
8734 |
|
8735 \list |
|
8736 \o repaint() or update() was invoked, |
|
8737 \o the widget was obscured and has now been uncovered, or |
|
8738 \o many other reasons. |
|
8739 \endlist |
|
8740 |
|
8741 Many widgets can simply repaint their entire surface when asked to, but |
|
8742 some slow widgets need to optimize by painting only the requested region: |
|
8743 QPaintEvent::region(). This speed optimization does not change the result, |
|
8744 as painting is clipped to that region during event processing. QListView |
|
8745 and QTableView do this, for example. |
|
8746 |
|
8747 Qt also tries to speed up painting by merging multiple paint events into |
|
8748 one. When update() is called several times or the window system sends |
|
8749 several paint events, Qt merges these events into one event with a larger |
|
8750 region (see QRegion::united()). The repaint() function does not permit this |
|
8751 optimization, so we suggest using update() whenever possible. |
|
8752 |
|
8753 When the paint event occurs, the update region has normally been erased, so |
|
8754 you are painting on the widget's background. |
|
8755 |
|
8756 The background can be set using setBackgroundRole() and setPalette(). |
|
8757 |
|
8758 Since Qt 4.0, QWidget automatically double-buffers its painting, so there |
|
8759 is no need to write double-buffering code in paintEvent() to avoid flicker. |
|
8760 |
|
8761 \bold{Note for the X11 platform}: It is possible to toggle global double |
|
8762 buffering by calling \c qt_x11_set_global_double_buffer(). For example, |
|
8763 |
|
8764 \snippet doc/src/snippets/code/src_gui_kernel_qwidget.cpp 14 |
|
8765 |
|
8766 \note Generally, you should refrain from calling update() or repaint() |
|
8767 \bold{inside} a paintEvent(). For example, calling update() or repaint() on |
|
8768 children inside a paintevent() results in undefined behavior; the child may |
|
8769 or may not get a paint event. |
|
8770 |
|
8771 \warning If you are using a custom paint engine without Qt's backingstore, |
|
8772 Qt::WA_PaintOnScreen must be set. Otherwise, QWidget::paintEngine() will |
|
8773 never be called; the backingstore will be used instead. |
|
8774 |
|
8775 \sa event(), repaint(), update(), QPainter, QPixmap, QPaintEvent, |
|
8776 {Analog Clock Example} |
|
8777 */ |
|
8778 |
|
8779 void QWidget::paintEvent(QPaintEvent *) |
|
8780 { |
|
8781 } |
|
8782 |
|
8783 |
|
8784 /*! |
|
8785 \fn void QWidget::moveEvent(QMoveEvent *event) |
|
8786 |
|
8787 This event handler can be reimplemented in a subclass to receive |
|
8788 widget move events which are passed in the \a event parameter. |
|
8789 When the widget receives this event, it is already at the new |
|
8790 position. |
|
8791 |
|
8792 The old position is accessible through QMoveEvent::oldPos(). |
|
8793 |
|
8794 \sa resizeEvent(), event(), move(), QMoveEvent |
|
8795 */ |
|
8796 |
|
8797 void QWidget::moveEvent(QMoveEvent *) |
|
8798 { |
|
8799 } |
|
8800 |
|
8801 |
|
8802 /*! |
|
8803 This event handler can be reimplemented in a subclass to receive |
|
8804 widget resize events which are passed in the \a event parameter. |
|
8805 When resizeEvent() is called, the widget already has its new |
|
8806 geometry. The old size is accessible through |
|
8807 QResizeEvent::oldSize(). |
|
8808 |
|
8809 The widget will be erased and receive a paint event immediately |
|
8810 after processing the resize event. No drawing need be (or should |
|
8811 be) done inside this handler. |
|
8812 |
|
8813 |
|
8814 \sa moveEvent(), event(), resize(), QResizeEvent, paintEvent(), |
|
8815 {Scribble Example} |
|
8816 */ |
|
8817 |
|
8818 void QWidget::resizeEvent(QResizeEvent * /* event */) |
|
8819 { |
|
8820 } |
|
8821 |
|
8822 #ifndef QT_NO_ACTION |
|
8823 /*! |
|
8824 \fn void QWidget::actionEvent(QActionEvent *event) |
|
8825 |
|
8826 This event handler is called with the given \a event whenever the |
|
8827 widget's actions are changed. |
|
8828 |
|
8829 \sa addAction(), insertAction(), removeAction(), actions(), QActionEvent |
|
8830 */ |
|
8831 void QWidget::actionEvent(QActionEvent *) |
|
8832 { |
|
8833 |
|
8834 } |
|
8835 #endif |
|
8836 |
|
8837 /*! |
|
8838 This event handler is called with the given \a event when Qt receives a window |
|
8839 close request for a top-level widget from the window system. |
|
8840 |
|
8841 By default, the event is accepted and the widget is closed. You can reimplement |
|
8842 this function to change the way the widget responds to window close requests. |
|
8843 For example, you can prevent the window from closing by calling \l{QEvent::}{ignore()} |
|
8844 on all events. |
|
8845 |
|
8846 Main window applications typically use reimplementations of this function to check |
|
8847 whether the user's work has been saved and ask for permission before closing. |
|
8848 For example, the \l{Application Example} uses a helper function to determine whether |
|
8849 or not to close the window: |
|
8850 |
|
8851 \snippet mainwindows/application/mainwindow.cpp 3 |
|
8852 \snippet mainwindows/application/mainwindow.cpp 4 |
|
8853 |
|
8854 \sa event(), hide(), close(), QCloseEvent, {Application Example} |
|
8855 */ |
|
8856 |
|
8857 void QWidget::closeEvent(QCloseEvent *event) |
|
8858 { |
|
8859 event->accept(); |
|
8860 } |
|
8861 |
|
8862 #ifndef QT_NO_CONTEXTMENU |
|
8863 /*! |
|
8864 This event handler, for event \a event, can be reimplemented in a |
|
8865 subclass to receive widget context menu events. |
|
8866 |
|
8867 The handler is called when the widget's \l contextMenuPolicy is |
|
8868 Qt::DefaultContextMenu. |
|
8869 |
|
8870 The default implementation ignores the context event. |
|
8871 See the \l QContextMenuEvent documentation for more details. |
|
8872 |
|
8873 \sa event(), QContextMenuEvent customContextMenuRequested() |
|
8874 */ |
|
8875 |
|
8876 void QWidget::contextMenuEvent(QContextMenuEvent *event) |
|
8877 { |
|
8878 event->ignore(); |
|
8879 } |
|
8880 #endif // QT_NO_CONTEXTMENU |
|
8881 |
|
8882 |
|
8883 /*! |
|
8884 This event handler, for event \a event, can be reimplemented in a |
|
8885 subclass to receive Input Method composition events. This handler |
|
8886 is called when the state of the input method changes. |
|
8887 |
|
8888 Note that when creating custom text editing widgets, the |
|
8889 Qt::WA_InputMethodEnabled window attribute must be set explicitly |
|
8890 (using the setAttribute() function) in order to receive input |
|
8891 method events. |
|
8892 |
|
8893 The default implementation calls event->ignore(), which rejects the |
|
8894 Input Method event. See the \l QInputMethodEvent documentation for more |
|
8895 details. |
|
8896 |
|
8897 \sa event(), QInputMethodEvent |
|
8898 */ |
|
8899 void QWidget::inputMethodEvent(QInputMethodEvent *event) |
|
8900 { |
|
8901 event->ignore(); |
|
8902 } |
|
8903 |
|
8904 /*! |
|
8905 This method is only relevant for input widgets. It is used by the |
|
8906 input method to query a set of properties of the widget to be |
|
8907 able to support complex input method operations as support for |
|
8908 surrounding text and reconversions. |
|
8909 |
|
8910 \a query specifies which property is queried. |
|
8911 |
|
8912 \sa inputMethodEvent(), QInputMethodEvent, QInputContext, inputMethodHints |
|
8913 */ |
|
8914 QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const |
|
8915 { |
|
8916 switch(query) { |
|
8917 case Qt::ImMicroFocus: |
|
8918 return QRect(width()/2, 0, 1, height()); |
|
8919 case Qt::ImFont: |
|
8920 return font(); |
|
8921 case Qt::ImAnchorPosition: |
|
8922 // Fallback. |
|
8923 return inputMethodQuery(Qt::ImCursorPosition); |
|
8924 default: |
|
8925 return QVariant(); |
|
8926 } |
|
8927 } |
|
8928 |
|
8929 /*! |
|
8930 \property QWidget::inputMethodHints |
|
8931 \brief What input method specific hints the widget has. |
|
8932 |
|
8933 This is only relevant for input widgets. It is used by |
|
8934 the input method to retrieve hints as to how the input method |
|
8935 should operate. For example, if the Qt::ImhFormattedNumbersOnly flag |
|
8936 is set, the input method may change its visual components to reflect |
|
8937 that only numbers can be entered. |
|
8938 |
|
8939 \note The flags are only hints, so the particular input method |
|
8940 implementation is free to ignore them. If you want to be |
|
8941 sure that a certain type of characters are entered, |
|
8942 you should also set a QValidator on the widget. |
|
8943 |
|
8944 The default value is Qt::ImhNone. |
|
8945 |
|
8946 \since 4.6 |
|
8947 |
|
8948 \sa inputMethodQuery(), QInputContext |
|
8949 */ |
|
8950 Qt::InputMethodHints QWidget::inputMethodHints() const |
|
8951 { |
|
8952 Q_D(const QWidget); |
|
8953 return d->imHints; |
|
8954 } |
|
8955 |
|
8956 void QWidget::setInputMethodHints(Qt::InputMethodHints hints) |
|
8957 { |
|
8958 Q_D(QWidget); |
|
8959 d->imHints = hints; |
|
8960 // Optimisation to update input context only it has already been created. |
|
8961 if (d->ic || qApp->d_func()->inputContext) { |
|
8962 QInputContext *ic = inputContext(); |
|
8963 if (ic) |
|
8964 ic->update(); |
|
8965 } |
|
8966 } |
|
8967 |
|
8968 |
|
8969 #ifndef QT_NO_DRAGANDDROP |
|
8970 |
|
8971 /*! |
|
8972 \fn void QWidget::dragEnterEvent(QDragEnterEvent *event) |
|
8973 |
|
8974 This event handler is called when a drag is in progress and the |
|
8975 mouse enters this widget. The event is passed in the \a event parameter. |
|
8976 |
|
8977 If the event is ignored, the widget won't receive any \l{dragMoveEvent()}{drag |
|
8978 move events}. |
|
8979 |
|
8980 See the \link dnd.html Drag-and-drop documentation\endlink for an |
|
8981 overview of how to provide drag-and-drop in your application. |
|
8982 |
|
8983 \sa QDrag, QDragEnterEvent |
|
8984 */ |
|
8985 void QWidget::dragEnterEvent(QDragEnterEvent *) |
|
8986 { |
|
8987 } |
|
8988 |
|
8989 /*! |
|
8990 \fn void QWidget::dragMoveEvent(QDragMoveEvent *event) |
|
8991 |
|
8992 This event handler is called if a drag is in progress, and when |
|
8993 any of the following conditions occur: the cursor enters this widget, |
|
8994 the cursor moves within this widget, or a modifier key is pressed on |
|
8995 the keyboard while this widget has the focus. The event is passed |
|
8996 in the \a event parameter. |
|
8997 |
|
8998 See the \link dnd.html Drag-and-drop documentation\endlink for an |
|
8999 overview of how to provide drag-and-drop in your application. |
|
9000 |
|
9001 \sa QDrag, QDragMoveEvent |
|
9002 */ |
|
9003 void QWidget::dragMoveEvent(QDragMoveEvent *) |
|
9004 { |
|
9005 } |
|
9006 |
|
9007 /*! |
|
9008 \fn void QWidget::dragLeaveEvent(QDragLeaveEvent *event) |
|
9009 |
|
9010 This event handler is called when a drag is in progress and the |
|
9011 mouse leaves this widget. The event is passed in the \a event |
|
9012 parameter. |
|
9013 |
|
9014 See the \link dnd.html Drag-and-drop documentation\endlink for an |
|
9015 overview of how to provide drag-and-drop in your application. |
|
9016 |
|
9017 \sa QDrag, QDragLeaveEvent |
|
9018 */ |
|
9019 void QWidget::dragLeaveEvent(QDragLeaveEvent *) |
|
9020 { |
|
9021 } |
|
9022 |
|
9023 /*! |
|
9024 \fn void QWidget::dropEvent(QDropEvent *event) |
|
9025 |
|
9026 This event handler is called when the drag is dropped on this |
|
9027 widget. The event is passed in the \a event parameter. |
|
9028 |
|
9029 See the \link dnd.html Drag-and-drop documentation\endlink for an |
|
9030 overview of how to provide drag-and-drop in your application. |
|
9031 |
|
9032 \sa QDrag, QDropEvent |
|
9033 */ |
|
9034 void QWidget::dropEvent(QDropEvent *) |
|
9035 { |
|
9036 } |
|
9037 |
|
9038 #endif // QT_NO_DRAGANDDROP |
|
9039 |
|
9040 /*! |
|
9041 \fn void QWidget::showEvent(QShowEvent *event) |
|
9042 |
|
9043 This event handler can be reimplemented in a subclass to receive |
|
9044 widget show events which are passed in the \a event parameter. |
|
9045 |
|
9046 Non-spontaneous show events are sent to widgets immediately |
|
9047 before they are shown. The spontaneous show events of windows are |
|
9048 delivered afterwards. |
|
9049 |
|
9050 Note: A widget receives spontaneous show and hide events when its |
|
9051 mapping status is changed by the window system, e.g. a spontaneous |
|
9052 hide event when the user minimizes the window, and a spontaneous |
|
9053 show event when the window is restored again. After receiving a |
|
9054 spontaneous hide event, a widget is still considered visible in |
|
9055 the sense of isVisible(). |
|
9056 |
|
9057 \sa visible, event(), QShowEvent |
|
9058 */ |
|
9059 void QWidget::showEvent(QShowEvent *) |
|
9060 { |
|
9061 } |
|
9062 |
|
9063 /*! |
|
9064 \fn void QWidget::hideEvent(QHideEvent *event) |
|
9065 |
|
9066 This event handler can be reimplemented in a subclass to receive |
|
9067 widget hide events. The event is passed in the \a event parameter. |
|
9068 |
|
9069 Hide events are sent to widgets immediately after they have been |
|
9070 hidden. |
|
9071 |
|
9072 Note: A widget receives spontaneous show and hide events when its |
|
9073 mapping status is changed by the window system, e.g. a spontaneous |
|
9074 hide event when the user minimizes the window, and a spontaneous |
|
9075 show event when the window is restored again. After receiving a |
|
9076 spontaneous hide event, a widget is still considered visible in |
|
9077 the sense of isVisible(). |
|
9078 |
|
9079 \sa visible, event(), QHideEvent |
|
9080 */ |
|
9081 void QWidget::hideEvent(QHideEvent *) |
|
9082 { |
|
9083 } |
|
9084 |
|
9085 /* |
|
9086 \fn QWidget::x11Event(MSG *) |
|
9087 |
|
9088 This special event handler can be reimplemented in a subclass to receive |
|
9089 native X11 events. |
|
9090 |
|
9091 In your reimplementation of this function, if you want to stop Qt from |
|
9092 handling the event, return true. If you return false, this native event |
|
9093 is passed back to Qt, which translates it into a Qt event and sends it to |
|
9094 the widget. |
|
9095 |
|
9096 \note Events are only delivered to this event handler if the widget is |
|
9097 native. |
|
9098 |
|
9099 \warning This function is not portable. |
|
9100 |
|
9101 \sa QApplication::x11EventFilter(), QWidget::winId() |
|
9102 */ |
|
9103 |
|
9104 |
|
9105 #if defined(Q_WS_MAC) |
|
9106 |
|
9107 /*! |
|
9108 \fn bool QWidget::macEvent(EventHandlerCallRef caller, EventRef event) |
|
9109 |
|
9110 This special event handler can be reimplemented in a subclass to |
|
9111 receive native Macintosh events. |
|
9112 |
|
9113 The parameters are a bit different depending if Qt is build against Carbon |
|
9114 or Cocoa. In Carbon, \a caller and \a event are the corresponding |
|
9115 EventHandlerCallRef and EventRef that correspond to the Carbon event |
|
9116 handlers that are installed. In Cocoa, \a caller is always 0 and the |
|
9117 EventRef is the EventRef generated from the NSEvent. |
|
9118 |
|
9119 In your reimplementation of this function, if you want to stop the |
|
9120 event being handled by Qt, return true. If you return false, this |
|
9121 native event is passed back to Qt, which translates the event into |
|
9122 a Qt event and sends it to the widget. |
|
9123 |
|
9124 \warning This function is not portable. |
|
9125 |
|
9126 \warning This function was not called inside of Qt until Qt 4.4. |
|
9127 If you need compatibility with earlier versions of Qt, consider QApplication::macEventFilter() instead. |
|
9128 |
|
9129 \sa QApplication::macEventFilter() |
|
9130 */ |
|
9131 |
|
9132 bool QWidget::macEvent(EventHandlerCallRef, EventRef) |
|
9133 { |
|
9134 return false; |
|
9135 } |
|
9136 |
|
9137 #endif |
|
9138 #if defined(Q_WS_WIN) |
|
9139 |
|
9140 /*! |
|
9141 This special event handler can be reimplemented in a subclass to |
|
9142 receive native Windows events which are passed in the \a message |
|
9143 parameter. |
|
9144 |
|
9145 In your reimplementation of this function, if you want to stop the |
|
9146 event being handled by Qt, return true and set \a result to the value |
|
9147 that the window procedure should return. If you return false, this |
|
9148 native event is passed back to Qt, which translates the event into |
|
9149 a Qt event and sends it to the widget. |
|
9150 |
|
9151 \warning This function is not portable. |
|
9152 |
|
9153 \sa QApplication::winEventFilter() |
|
9154 */ |
|
9155 bool QWidget::winEvent(MSG *message, long *result) |
|
9156 { |
|
9157 Q_UNUSED(message); |
|
9158 Q_UNUSED(result); |
|
9159 return false; |
|
9160 } |
|
9161 |
|
9162 #endif |
|
9163 #if defined(Q_WS_X11) |
|
9164 |
|
9165 /*! |
|
9166 \fn bool QWidget::x11Event(XEvent *event) |
|
9167 |
|
9168 This special event handler can be reimplemented in a subclass to receive |
|
9169 native X11 events passed in the \a event parameter. |
|
9170 |
|
9171 In your reimplementation of this function, if you want to stop Qt from |
|
9172 handling the event, return true. If you return false, this native event |
|
9173 is passed back to Qt, which translates it into a Qt event and sends it to |
|
9174 the widget. |
|
9175 |
|
9176 \note Events are only delivered to this event handler if the widget is |
|
9177 native. |
|
9178 |
|
9179 \warning This function is not portable. |
|
9180 |
|
9181 \sa QApplication::x11EventFilter(), QWidget::winId() |
|
9182 */ |
|
9183 bool QWidget::x11Event(XEvent *) |
|
9184 { |
|
9185 return false; |
|
9186 } |
|
9187 |
|
9188 #endif |
|
9189 #if defined(Q_WS_QWS) |
|
9190 |
|
9191 /*! |
|
9192 \fn bool QWidget::qwsEvent(QWSEvent *event) |
|
9193 |
|
9194 This special event handler can be reimplemented in a subclass to |
|
9195 receive native Qt for Embedded Linux events which are passed in the |
|
9196 \a event parameter. |
|
9197 |
|
9198 In your reimplementation of this function, if you want to stop the |
|
9199 event being handled by Qt, return true. If you return false, this |
|
9200 native event is passed back to Qt, which translates the event into |
|
9201 a Qt event and sends it to the widget. |
|
9202 |
|
9203 \warning This function is not portable. |
|
9204 |
|
9205 \sa QApplication::qwsEventFilter() |
|
9206 */ |
|
9207 bool QWidget::qwsEvent(QWSEvent *) |
|
9208 { |
|
9209 return false; |
|
9210 } |
|
9211 |
|
9212 #endif |
|
9213 |
|
9214 |
|
9215 /*! |
|
9216 Ensures that the widget has been polished by QStyle (i.e., has a |
|
9217 proper font and palette). |
|
9218 |
|
9219 QWidget calls this function after it has been fully constructed |
|
9220 but before it is shown the very first time. You can call this |
|
9221 function if you want to ensure that the widget is polished before |
|
9222 doing an operation, e.g., the correct font size might be needed in |
|
9223 the widget's sizeHint() reimplementation. Note that this function |
|
9224 \e is called from the default implementation of sizeHint(). |
|
9225 |
|
9226 Polishing is useful for final initialization that must happen after |
|
9227 all constructors (from base classes as well as from subclasses) |
|
9228 have been called. |
|
9229 |
|
9230 If you need to change some settings when a widget is polished, |
|
9231 reimplement event() and handle the QEvent::Polish event type. |
|
9232 |
|
9233 \bold{Note:} The function is declared const so that it can be called from |
|
9234 other const functions (e.g., sizeHint()). |
|
9235 |
|
9236 \sa event() |
|
9237 */ |
|
9238 void QWidget::ensurePolished() const |
|
9239 { |
|
9240 Q_D(const QWidget); |
|
9241 |
|
9242 const QMetaObject *m = metaObject(); |
|
9243 if (m == d->polished) |
|
9244 return; |
|
9245 d->polished = m; |
|
9246 |
|
9247 QEvent e(QEvent::Polish); |
|
9248 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &e); |
|
9249 |
|
9250 // polish children after 'this' |
|
9251 QList<QObject*> children = d->children; |
|
9252 for (int i = 0; i < children.size(); ++i) { |
|
9253 QObject *o = children.at(i); |
|
9254 if(!o->isWidgetType()) |
|
9255 continue; |
|
9256 if (QWidget *w = qobject_cast<QWidget *>(o)) |
|
9257 w->ensurePolished(); |
|
9258 } |
|
9259 |
|
9260 if (d->parent && d->sendChildEvents) { |
|
9261 QChildEvent e(QEvent::ChildPolished, const_cast<QWidget *>(this)); |
|
9262 QCoreApplication::sendEvent(d->parent, &e); |
|
9263 } |
|
9264 } |
|
9265 |
|
9266 /*! |
|
9267 Returns the mask currently set on a widget. If no mask is set the |
|
9268 return value will be an empty region. |
|
9269 |
|
9270 \sa setMask(), clearMask(), QRegion::isEmpty(), {Shaped Clock Example} |
|
9271 */ |
|
9272 QRegion QWidget::mask() const |
|
9273 { |
|
9274 Q_D(const QWidget); |
|
9275 return d->extra ? d->extra->mask : QRegion(); |
|
9276 } |
|
9277 |
|
9278 /*! |
|
9279 Returns the layout manager that is installed on this widget, or 0 |
|
9280 if no layout manager is installed. |
|
9281 |
|
9282 The layout manager sets the geometry of the widget's children |
|
9283 that have been added to the layout. |
|
9284 |
|
9285 \sa setLayout(), sizePolicy(), {Layout Management} |
|
9286 */ |
|
9287 QLayout *QWidget::layout() const |
|
9288 { |
|
9289 return d_func()->layout; |
|
9290 } |
|
9291 |
|
9292 |
|
9293 /*! |
|
9294 \fn void QWidget::setLayout(QLayout *layout) |
|
9295 |
|
9296 Sets the layout manager for this widget to \a layout. |
|
9297 |
|
9298 If there already is a layout manager installed on this widget, |
|
9299 QWidget won't let you install another. You must first delete the |
|
9300 existing layout manager (returned by layout()) before you can |
|
9301 call setLayout() with the new layout. |
|
9302 |
|
9303 If \a layout is the layout manger on a different widget, setLayout() |
|
9304 will reparent the layout and make it the layout manager for this widget. |
|
9305 |
|
9306 Example: |
|
9307 |
|
9308 \snippet examples/uitools/textfinder/textfinder.cpp 3b |
|
9309 |
|
9310 An alternative to calling this function is to pass this widget to |
|
9311 the layout's constructor. |
|
9312 |
|
9313 The QWidget will take ownership of \a layout. |
|
9314 |
|
9315 \sa layout(), {Layout Management} |
|
9316 */ |
|
9317 |
|
9318 void QWidget::setLayout(QLayout *l) |
|
9319 { |
|
9320 if (!l) { |
|
9321 qWarning("QWidget::setLayout: Cannot set layout to 0"); |
|
9322 return; |
|
9323 } |
|
9324 if (layout()) { |
|
9325 if (layout() != l) |
|
9326 qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", which already has a" |
|
9327 " layout", l->objectName().toLocal8Bit().data(), metaObject()->className(), |
|
9328 objectName().toLocal8Bit().data()); |
|
9329 return; |
|
9330 } |
|
9331 |
|
9332 QObject *oldParent = l->parent(); |
|
9333 if (oldParent && oldParent != this) { |
|
9334 if (oldParent->isWidgetType()) { |
|
9335 // Steal the layout off a widget parent. Takes effect when |
|
9336 // morphing laid-out container widgets in Designer. |
|
9337 QWidget *oldParentWidget = static_cast<QWidget *>(oldParent); |
|
9338 oldParentWidget->takeLayout(); |
|
9339 } else { |
|
9340 qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent", |
|
9341 l->objectName().toLocal8Bit().data(), metaObject()->className(), |
|
9342 objectName().toLocal8Bit().data()); |
|
9343 return; |
|
9344 } |
|
9345 } |
|
9346 |
|
9347 Q_D(QWidget); |
|
9348 l->d_func()->topLevel = true; |
|
9349 d->layout = l; |
|
9350 if (oldParent != this) { |
|
9351 l->setParent(this); |
|
9352 l->d_func()->reparentChildWidgets(this); |
|
9353 l->invalidate(); |
|
9354 } |
|
9355 |
|
9356 if (isWindow() && d->maybeTopData()) |
|
9357 d->topData()->sizeAdjusted = false; |
|
9358 } |
|
9359 |
|
9360 /*! |
|
9361 \fn QLayout *QWidget::takeLayout() |
|
9362 |
|
9363 Remove the layout from the widget. |
|
9364 \since 4.5 |
|
9365 */ |
|
9366 |
|
9367 QLayout *QWidget::takeLayout() |
|
9368 { |
|
9369 Q_D(QWidget); |
|
9370 QLayout *l = layout(); |
|
9371 if (!l) |
|
9372 return 0; |
|
9373 d->layout = 0; |
|
9374 l->setParent(0); |
|
9375 return l; |
|
9376 } |
|
9377 |
|
9378 /*! |
|
9379 \property QWidget::sizePolicy |
|
9380 \brief the default layout behavior of the widget |
|
9381 |
|
9382 If there is a QLayout that manages this widget's children, the |
|
9383 size policy specified by that layout is used. If there is no such |
|
9384 QLayout, the result of this function is used. |
|
9385 |
|
9386 The default policy is Preferred/Preferred, which means that the |
|
9387 widget can be freely resized, but prefers to be the size |
|
9388 sizeHint() returns. Button-like widgets set the size policy to |
|
9389 specify that they may stretch horizontally, but are fixed |
|
9390 vertically. The same applies to lineedit controls (such as |
|
9391 QLineEdit, QSpinBox or an editable QComboBox) and other |
|
9392 horizontally orientated widgets (such as QProgressBar). |
|
9393 QToolButton's are normally square, so they allow growth in both |
|
9394 directions. Widgets that support different directions (such as |
|
9395 QSlider, QScrollBar or QHeader) specify stretching in the |
|
9396 respective direction only. Widgets that can provide scroll bars |
|
9397 (usually subclasses of QScrollArea) tend to specify that they can |
|
9398 use additional space, and that they can make do with less than |
|
9399 sizeHint(). |
|
9400 |
|
9401 \sa sizeHint() QLayout QSizePolicy updateGeometry() |
|
9402 */ |
|
9403 QSizePolicy QWidget::sizePolicy() const |
|
9404 { |
|
9405 Q_D(const QWidget); |
|
9406 return d->size_policy; |
|
9407 } |
|
9408 |
|
9409 void QWidget::setSizePolicy(QSizePolicy policy) |
|
9410 { |
|
9411 Q_D(QWidget); |
|
9412 setAttribute(Qt::WA_WState_OwnSizePolicy); |
|
9413 if (policy == d->size_policy) |
|
9414 return; |
|
9415 d->size_policy = policy; |
|
9416 |
|
9417 #ifndef QT_NO_GRAPHICSVIEW |
|
9418 if (QWExtra *extra = d->extra) { |
|
9419 if (extra->proxyWidget) |
|
9420 extra->proxyWidget->setSizePolicy(policy); |
|
9421 } |
|
9422 #endif |
|
9423 |
|
9424 updateGeometry(); |
|
9425 |
|
9426 if (isWindow() && d->maybeTopData()) |
|
9427 d->topData()->sizeAdjusted = false; |
|
9428 } |
|
9429 |
|
9430 /*! |
|
9431 \fn void QWidget::setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical) |
|
9432 \overload |
|
9433 |
|
9434 Sets the size policy of the widget to \a horizontal and \a |
|
9435 vertical, with standard stretch and no height-for-width. |
|
9436 |
|
9437 \sa QSizePolicy::QSizePolicy() |
|
9438 */ |
|
9439 |
|
9440 /*! |
|
9441 Returns the preferred height for this widget, given the width \a w. |
|
9442 |
|
9443 If this widget has a layout, the default implementation returns |
|
9444 the layout's preferred height. if there is no layout, the default |
|
9445 implementation returns -1 indicating that the preferred height |
|
9446 does not depend on the width. |
|
9447 */ |
|
9448 |
|
9449 int QWidget::heightForWidth(int w) const |
|
9450 { |
|
9451 if (layout() && layout()->hasHeightForWidth()) |
|
9452 return layout()->totalHeightForWidth(w); |
|
9453 return -1; |
|
9454 } |
|
9455 |
|
9456 /*! |
|
9457 \fn QWidget *QWidget::childAt(int x, int y) const |
|
9458 |
|
9459 Returns the visible child widget at the position (\a{x}, \a{y}) |
|
9460 in the widget's coordinate system. If there is no visible child |
|
9461 widget at the specified position, the function returns 0. |
|
9462 */ |
|
9463 |
|
9464 /*! |
|
9465 \overload |
|
9466 |
|
9467 Returns the visible child widget at point \a p in the widget's own |
|
9468 coordinate system. |
|
9469 */ |
|
9470 |
|
9471 QWidget *QWidget::childAt(const QPoint &p) const |
|
9472 { |
|
9473 return d_func()->childAt_helper(p, false); |
|
9474 } |
|
9475 |
|
9476 QWidget *QWidgetPrivate::childAt_helper(const QPoint &p, bool ignoreChildrenInDestructor) const |
|
9477 { |
|
9478 Q_Q(const QWidget); |
|
9479 #ifdef Q_WS_MAC |
|
9480 bool includeFrame = q->isWindow() && qobject_cast<const QMainWindow *>(q) |
|
9481 && static_cast<const QMainWindow *>(q)->unifiedTitleAndToolBarOnMac(); |
|
9482 #endif |
|
9483 |
|
9484 if ( |
|
9485 #ifdef Q_WS_MAC |
|
9486 !includeFrame && |
|
9487 #endif |
|
9488 !q->rect().contains(p)) |
|
9489 return 0; |
|
9490 |
|
9491 for (int i = children.size(); i > 0 ;) { |
|
9492 --i; |
|
9493 QWidget *w = qobject_cast<QWidget *>(children.at(i)); |
|
9494 if (w && !w->isWindow() && !w->isHidden() |
|
9495 && (w->geometry().contains(p) |
|
9496 #ifdef Q_WS_MAC |
|
9497 || (includeFrame && w->geometry().contains(qt_mac_nativeMapFromParent(w, p))) |
|
9498 #endif |
|
9499 )) { |
|
9500 if (ignoreChildrenInDestructor && w->data->in_destructor) |
|
9501 continue; |
|
9502 if (w->testAttribute(Qt::WA_TransparentForMouseEvents)) |
|
9503 continue; |
|
9504 QPoint childPoint = w->mapFromParent(p); |
|
9505 #ifdef Q_WS_MAC |
|
9506 if (includeFrame && !w->geometry().contains(p)) |
|
9507 childPoint = qt_mac_nativeMapFromParent(w, p); |
|
9508 #endif |
|
9509 if (QWidget *t = w->d_func()->childAt_helper(childPoint, ignoreChildrenInDestructor)) |
|
9510 return t; |
|
9511 // if WMouseNoMask is set the widget mask is ignored, if |
|
9512 // the widget has no mask then the WMouseNoMask flag has no |
|
9513 // effect |
|
9514 if (w->testAttribute(Qt::WA_MouseNoMask) || w->mask().contains(childPoint) |
|
9515 || w->mask().isEmpty()) |
|
9516 return w; |
|
9517 } |
|
9518 } |
|
9519 return 0; |
|
9520 } |
|
9521 |
|
9522 void QWidgetPrivate::updateGeometry_helper(bool forceUpdate) |
|
9523 { |
|
9524 Q_Q(QWidget); |
|
9525 if (widgetItem) |
|
9526 widgetItem->invalidateSizeCache(); |
|
9527 QWidget *parent; |
|
9528 if (forceUpdate || !extra || extra->minw != extra->maxw || extra->minh != extra->maxh) { |
|
9529 if (!q->isWindow() && !q->isHidden() && (parent = q->parentWidget())) { |
|
9530 if (parent->d_func()->layout) |
|
9531 parent->d_func()->layout->invalidate(); |
|
9532 else if (parent->isVisible()) |
|
9533 QApplication::postEvent(parent, new QEvent(QEvent::LayoutRequest)); |
|
9534 } |
|
9535 } |
|
9536 } |
|
9537 |
|
9538 /*! |
|
9539 Notifies the layout system that this widget has changed and may |
|
9540 need to change geometry. |
|
9541 |
|
9542 Call this function if the sizeHint() or sizePolicy() have changed. |
|
9543 |
|
9544 For explicitly hidden widgets, updateGeometry() is a no-op. The |
|
9545 layout system will be notified as soon as the widget is shown. |
|
9546 */ |
|
9547 |
|
9548 void QWidget::updateGeometry() |
|
9549 { |
|
9550 Q_D(QWidget); |
|
9551 d->updateGeometry_helper(false); |
|
9552 } |
|
9553 |
|
9554 /*! \property QWidget::windowFlags |
|
9555 |
|
9556 Window flags are a combination of a type (e.g. Qt::Dialog) and |
|
9557 zero or more hints to the window system (e.g. |
|
9558 Qt::FramelessWindowHint). |
|
9559 |
|
9560 If the widget had type Qt::Widget or Qt::SubWindow and becomes a |
|
9561 window (Qt::Window, Qt::Dialog, etc.), it is put at position (0, |
|
9562 0) on the desktop. If the widget is a window and becomes a |
|
9563 Qt::Widget or Qt::SubWindow, it is put at position (0, 0) |
|
9564 relative to its parent widget. |
|
9565 |
|
9566 \note This function calls setParent() when changing the flags for |
|
9567 a window, causing the widget to be hidden. You must call show() to make |
|
9568 the widget visible again.. |
|
9569 |
|
9570 \sa windowType(), {Window Flags Example} |
|
9571 */ |
|
9572 void QWidget::setWindowFlags(Qt::WindowFlags flags) |
|
9573 { |
|
9574 if (data->window_flags == flags) |
|
9575 return; |
|
9576 |
|
9577 Q_D(QWidget); |
|
9578 |
|
9579 if ((data->window_flags | flags) & Qt::Window) { |
|
9580 // the old type was a window and/or the new type is a window |
|
9581 QPoint oldPos = pos(); |
|
9582 bool visible = isVisible(); |
|
9583 setParent(parentWidget(), flags); |
|
9584 |
|
9585 // if both types are windows or neither of them are, we restore |
|
9586 // the old position |
|
9587 if (!((data->window_flags ^ flags) & Qt::Window) |
|
9588 && (visible || testAttribute(Qt::WA_Moved))) { |
|
9589 move(oldPos); |
|
9590 } |
|
9591 // for backward-compatibility we change Qt::WA_QuitOnClose attribute value only when the window was recreated. |
|
9592 d->adjustQuitOnCloseAttribute(); |
|
9593 } else { |
|
9594 data->window_flags = flags; |
|
9595 } |
|
9596 } |
|
9597 |
|
9598 /*! |
|
9599 Sets the window flags for the widget to \a flags, |
|
9600 \e without telling the window system. |
|
9601 |
|
9602 \warning Do not call this function unless you really know what |
|
9603 you're doing. |
|
9604 |
|
9605 \sa setWindowFlags() |
|
9606 */ |
|
9607 void QWidget::overrideWindowFlags(Qt::WindowFlags flags) |
|
9608 { |
|
9609 data->window_flags = flags; |
|
9610 } |
|
9611 |
|
9612 /*! |
|
9613 \fn Qt::WindowType QWidget::windowType() const |
|
9614 |
|
9615 Returns the window type of this widget. This is identical to |
|
9616 windowFlags() & Qt::WindowType_Mask. |
|
9617 |
|
9618 \sa windowFlags |
|
9619 */ |
|
9620 |
|
9621 /*! |
|
9622 Sets the parent of the widget to \a parent, and resets the window |
|
9623 flags. The widget is moved to position (0, 0) in its new parent. |
|
9624 |
|
9625 If the new parent widget is in a different window, the |
|
9626 reparented widget and its children are appended to the end of the |
|
9627 \l{setFocusPolicy()}{tab chain} of the new parent |
|
9628 widget, in the same internal order as before. If one of the moved |
|
9629 widgets had keyboard focus, setParent() calls clearFocus() for that |
|
9630 widget. |
|
9631 |
|
9632 If the new parent widget is in the same window as the |
|
9633 old parent, setting the parent doesn't change the tab order or |
|
9634 keyboard focus. |
|
9635 |
|
9636 If the "new" parent widget is the old parent widget, this function |
|
9637 does nothing. |
|
9638 |
|
9639 \note The widget becomes invisible as part of changing its parent, |
|
9640 even if it was previously visible. You must call show() to make the |
|
9641 widget visible again. |
|
9642 |
|
9643 \warning It is very unlikely that you will ever need this |
|
9644 function. If you have a widget that changes its content |
|
9645 dynamically, it is far easier to use \l QStackedWidget. |
|
9646 |
|
9647 \sa setWindowFlags() |
|
9648 */ |
|
9649 void QWidget::setParent(QWidget *parent) |
|
9650 { |
|
9651 if (parent == parentWidget()) |
|
9652 return; |
|
9653 setParent((QWidget*)parent, windowFlags() & ~Qt::WindowType_Mask); |
|
9654 } |
|
9655 |
|
9656 /*! |
|
9657 \overload |
|
9658 |
|
9659 This function also takes widget flags, \a f as an argument. |
|
9660 */ |
|
9661 |
|
9662 void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) |
|
9663 { |
|
9664 Q_D(QWidget); |
|
9665 bool resized = testAttribute(Qt::WA_Resized); |
|
9666 bool wasCreated = testAttribute(Qt::WA_WState_Created); |
|
9667 QWidget *oldtlw = window(); |
|
9668 |
|
9669 QWidget *desktopWidget = 0; |
|
9670 if (parent && parent->windowType() == Qt::Desktop) |
|
9671 desktopWidget = parent; |
|
9672 bool newParent = (parent != parentWidget()) || !wasCreated || desktopWidget; |
|
9673 |
|
9674 #if defined(Q_WS_X11) || defined(Q_WS_WIN) |
|
9675 if (newParent && parent && !desktopWidget) { |
|
9676 if (testAttribute(Qt::WA_NativeWindow) && !qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings)) |
|
9677 parent->d_func()->enforceNativeChildren(); |
|
9678 else if (parent->d_func()->nativeChildrenForced() || parent->testAttribute(Qt::WA_PaintOnScreen)) |
|
9679 setAttribute(Qt::WA_NativeWindow); |
|
9680 } |
|
9681 #endif |
|
9682 |
|
9683 if (wasCreated) { |
|
9684 if (!testAttribute(Qt::WA_WState_Hidden)) { |
|
9685 hide(); |
|
9686 setAttribute(Qt::WA_WState_ExplicitShowHide, false); |
|
9687 } |
|
9688 if (newParent) { |
|
9689 QEvent e(QEvent::ParentAboutToChange); |
|
9690 QApplication::sendEvent(this, &e); |
|
9691 } |
|
9692 } |
|
9693 if (newParent && isAncestorOf(focusWidget())) |
|
9694 focusWidget()->clearFocus(); |
|
9695 |
|
9696 d->setParent_sys(parent, f); |
|
9697 if (desktopWidget) |
|
9698 parent = 0; |
|
9699 |
|
9700 #ifdef Q_BACKINGSTORE_SUBSURFACES |
|
9701 QTLWExtra *extra = d->maybeTopData(); |
|
9702 QWindowSurface *windowSurface = (extra ? extra->windowSurface : 0); |
|
9703 if (newParent && windowSurface) { |
|
9704 QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore(); |
|
9705 if (oldBs) |
|
9706 oldBs->subSurfaces.removeAll(windowSurface); |
|
9707 |
|
9708 if (parent) { |
|
9709 QWidgetBackingStore *newBs = parent->d_func()->maybeBackingStore(); |
|
9710 if (newBs) |
|
9711 newBs->subSurfaces.append(windowSurface); |
|
9712 } |
|
9713 } |
|
9714 #endif |
|
9715 |
|
9716 if (newParent) { |
|
9717 if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) { |
|
9718 oldBs->removeDirtyWidget(this); |
|
9719 // Move the widget and all its static children from |
|
9720 // the old backing store to the new one. |
|
9721 oldBs->moveStaticWidgets(this); |
|
9722 } |
|
9723 } |
|
9724 |
|
9725 if ((QApplicationPrivate::app_compile_version < 0x040200 |
|
9726 || QApplicationPrivate::testAttribute(Qt::AA_ImmediateWidgetCreation)) |
|
9727 && !testAttribute(Qt::WA_WState_Created)) |
|
9728 create(); |
|
9729 |
|
9730 d->reparentFocusWidgets(oldtlw); |
|
9731 setAttribute(Qt::WA_Resized, resized); |
|
9732 if (!testAttribute(Qt::WA_StyleSheet) |
|
9733 && (!parent || !parent->testAttribute(Qt::WA_StyleSheet))) { |
|
9734 d->resolveFont(); |
|
9735 d->resolvePalette(); |
|
9736 } |
|
9737 d->resolveLayoutDirection(); |
|
9738 d->resolveLocale(); |
|
9739 |
|
9740 // Note: GL widgets under WGL or EGL will always need a ParentChange |
|
9741 // event to handle recreation/rebinding of the GL context, hence the |
|
9742 // (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all |
|
9743 // platforms). |
|
9744 if (newParent |
|
9745 #if defined(Q_WS_WIN) || defined(QT_OPENGL_ES) |
|
9746 || (f & Qt::MSWindowsOwnDC) |
|
9747 #endif |
|
9748 ) { |
|
9749 // propagate enabled updates enabled state to non-windows |
|
9750 if (!isWindow()) { |
|
9751 if (!testAttribute(Qt::WA_ForceDisabled)) |
|
9752 d->setEnabled_helper(parent ? parent->isEnabled() : true); |
|
9753 if (!testAttribute(Qt::WA_ForceUpdatesDisabled)) |
|
9754 d->setUpdatesEnabled_helper(parent ? parent->updatesEnabled() : true); |
|
9755 } |
|
9756 d->inheritStyle(); |
|
9757 |
|
9758 // send and post remaining QObject events |
|
9759 if (parent && d->sendChildEvents) { |
|
9760 QChildEvent e(QEvent::ChildAdded, this); |
|
9761 QApplication::sendEvent(parent, &e); |
|
9762 #ifdef QT3_SUPPORT |
|
9763 if (parent->d_func()->pendingChildInsertedEvents.isEmpty()) { |
|
9764 QApplication::postEvent(parent, |
|
9765 new QEvent(QEvent::ChildInsertedRequest), |
|
9766 Qt::HighEventPriority); |
|
9767 } |
|
9768 parent->d_func()->pendingChildInsertedEvents.append(this); |
|
9769 #endif |
|
9770 } |
|
9771 |
|
9772 //### already hidden above ---> must probably do something smart on the mac |
|
9773 // #ifdef Q_WS_MAC |
|
9774 // extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp |
|
9775 // if(!qt_mac_is_macdrawer(q)) //special case |
|
9776 // q->setAttribute(Qt::WA_WState_Hidden); |
|
9777 // #else |
|
9778 // q->setAttribute(Qt::WA_WState_Hidden); |
|
9779 //#endif |
|
9780 |
|
9781 if (parent && d->sendChildEvents && d->polished) { |
|
9782 QChildEvent e(QEvent::ChildPolished, this); |
|
9783 QCoreApplication::sendEvent(parent, &e); |
|
9784 } |
|
9785 |
|
9786 QEvent e(QEvent::ParentChange); |
|
9787 QApplication::sendEvent(this, &e); |
|
9788 } |
|
9789 |
|
9790 if (!wasCreated) { |
|
9791 if (isWindow() || parentWidget()->isVisible()) |
|
9792 setAttribute(Qt::WA_WState_Hidden, true); |
|
9793 else if (!testAttribute(Qt::WA_WState_ExplicitShowHide)) |
|
9794 setAttribute(Qt::WA_WState_Hidden, false); |
|
9795 } |
|
9796 |
|
9797 d->updateIsOpaque(); |
|
9798 |
|
9799 #ifndef QT_NO_GRAPHICSVIEW |
|
9800 // Embed the widget into a proxy if the parent is embedded. |
|
9801 // ### Doesn't handle reparenting out of an embedded widget. |
|
9802 if (oldtlw->graphicsProxyWidget()) { |
|
9803 if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(oldtlw)) |
|
9804 ancestorProxy->d_func()->unembedSubWindow(this); |
|
9805 } |
|
9806 if (isWindow() && parent && !graphicsProxyWidget() && !bypassGraphicsProxyWidget(this)) { |
|
9807 if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(parent)) |
|
9808 ancestorProxy->d_func()->embedSubWindow(this); |
|
9809 } |
|
9810 #endif |
|
9811 } |
|
9812 |
|
9813 /*! |
|
9814 Scrolls the widget including its children \a dx pixels to the |
|
9815 right and \a dy downward. Both \a dx and \a dy may be negative. |
|
9816 |
|
9817 After scrolling, the widgets will receive paint events for |
|
9818 the areas that need to be repainted. For widgets that Qt knows to |
|
9819 be opaque, this is only the newly exposed parts. |
|
9820 For example, if an opaque widget is scrolled 8 pixels to the left, |
|
9821 only an 8-pixel wide stripe at the right edge needs updating. |
|
9822 |
|
9823 Since widgets propagate the contents of their parents by default, |
|
9824 you need to set the \l autoFillBackground property, or use |
|
9825 setAttribute() to set the Qt::WA_OpaquePaintEvent attribute, to make |
|
9826 a widget opaque. |
|
9827 |
|
9828 For widgets that use contents propagation, a scroll will cause an |
|
9829 update of the entire scroll area. |
|
9830 |
|
9831 \sa {Transparency and Double Buffering} |
|
9832 */ |
|
9833 |
|
9834 void QWidget::scroll(int dx, int dy) |
|
9835 { |
|
9836 if ((!updatesEnabled() && children().size() == 0) || !isVisible()) |
|
9837 return; |
|
9838 if (dx == 0 && dy == 0) |
|
9839 return; |
|
9840 Q_D(QWidget); |
|
9841 #ifndef QT_NO_GRAPHICSVIEW |
|
9842 if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) { |
|
9843 // Graphics View maintains its own dirty region as a list of rects; |
|
9844 // until we can connect item updates directly to the view, we must |
|
9845 // separately add a translated dirty region. |
|
9846 if (!d->dirty.isEmpty()) { |
|
9847 foreach (const QRect &rect, (d->dirty.translated(dx, dy)).rects()) |
|
9848 proxy->update(rect); |
|
9849 } |
|
9850 proxy->scroll(dx, dy, proxy->subWidgetRect(this)); |
|
9851 return; |
|
9852 } |
|
9853 #endif |
|
9854 d->setDirtyOpaqueRegion(); |
|
9855 d->scroll_sys(dx, dy); |
|
9856 } |
|
9857 |
|
9858 /*! |
|
9859 \overload |
|
9860 |
|
9861 This version only scrolls \a r and does not move the children of |
|
9862 the widget. |
|
9863 |
|
9864 If \a r is empty or invalid, the result is undefined. |
|
9865 |
|
9866 \sa QScrollArea |
|
9867 */ |
|
9868 void QWidget::scroll(int dx, int dy, const QRect &r) |
|
9869 { |
|
9870 |
|
9871 if ((!updatesEnabled() && children().size() == 0) || !isVisible()) |
|
9872 return; |
|
9873 if (dx == 0 && dy == 0) |
|
9874 return; |
|
9875 Q_D(QWidget); |
|
9876 #ifndef QT_NO_GRAPHICSVIEW |
|
9877 if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) { |
|
9878 // Graphics View maintains its own dirty region as a list of rects; |
|
9879 // until we can connect item updates directly to the view, we must |
|
9880 // separately add a translated dirty region. |
|
9881 if (!d->dirty.isEmpty()) { |
|
9882 foreach (const QRect &rect, (d->dirty.translated(dx, dy) & r).rects()) |
|
9883 proxy->update(rect); |
|
9884 } |
|
9885 proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint())); |
|
9886 return; |
|
9887 } |
|
9888 #endif |
|
9889 d->scroll_sys(dx, dy, r); |
|
9890 } |
|
9891 |
|
9892 /*! |
|
9893 Repaints the widget directly by calling paintEvent() immediately, |
|
9894 unless updates are disabled or the widget is hidden. |
|
9895 |
|
9896 We suggest only using repaint() if you need an immediate repaint, |
|
9897 for example during animation. In almost all circumstances update() |
|
9898 is better, as it permits Qt to optimize for speed and minimize |
|
9899 flicker. |
|
9900 |
|
9901 \warning If you call repaint() in a function which may itself be |
|
9902 called from paintEvent(), you may get infinite recursion. The |
|
9903 update() function never causes recursion. |
|
9904 |
|
9905 \sa update(), paintEvent(), setUpdatesEnabled() |
|
9906 */ |
|
9907 |
|
9908 void QWidget::repaint() |
|
9909 { |
|
9910 repaint(rect()); |
|
9911 } |
|
9912 |
|
9913 /*! \overload |
|
9914 |
|
9915 This version repaints a rectangle (\a x, \a y, \a w, \a h) inside |
|
9916 the widget. |
|
9917 |
|
9918 If \a w is negative, it is replaced with \c{width() - x}, and if |
|
9919 \a h is negative, it is replaced width \c{height() - y}. |
|
9920 */ |
|
9921 void QWidget::repaint(int x, int y, int w, int h) |
|
9922 { |
|
9923 if (x > data->crect.width() || y > data->crect.height()) |
|
9924 return; |
|
9925 |
|
9926 if (w < 0) |
|
9927 w = data->crect.width() - x; |
|
9928 if (h < 0) |
|
9929 h = data->crect.height() - y; |
|
9930 |
|
9931 repaint(QRect(x, y, w, h)); |
|
9932 } |
|
9933 |
|
9934 /*! \overload |
|
9935 |
|
9936 This version repaints a rectangle \a rect inside the widget. |
|
9937 */ |
|
9938 void QWidget::repaint(const QRect &rect) |
|
9939 { |
|
9940 Q_D(QWidget); |
|
9941 |
|
9942 if (testAttribute(Qt::WA_WState_ConfigPending)) { |
|
9943 update(rect); |
|
9944 return; |
|
9945 } |
|
9946 |
|
9947 if (!isVisible() || !updatesEnabled() || rect.isEmpty()) |
|
9948 return; |
|
9949 |
|
9950 if (hasBackingStoreSupport()) { |
|
9951 QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); |
|
9952 if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) { |
|
9953 tlwExtra->inRepaint = true; |
|
9954 tlwExtra->backingStore->markDirty(rect, this, true); |
|
9955 tlwExtra->inRepaint = false; |
|
9956 } |
|
9957 } else { |
|
9958 d->repaint_sys(rect); |
|
9959 } |
|
9960 } |
|
9961 |
|
9962 /*! |
|
9963 \overload |
|
9964 |
|
9965 This version repaints a region \a rgn inside the widget. |
|
9966 */ |
|
9967 void QWidget::repaint(const QRegion &rgn) |
|
9968 { |
|
9969 Q_D(QWidget); |
|
9970 |
|
9971 if (testAttribute(Qt::WA_WState_ConfigPending)) { |
|
9972 update(rgn); |
|
9973 return; |
|
9974 } |
|
9975 |
|
9976 if (!isVisible() || !updatesEnabled() || rgn.isEmpty()) |
|
9977 return; |
|
9978 |
|
9979 if (hasBackingStoreSupport()) { |
|
9980 QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); |
|
9981 if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) { |
|
9982 tlwExtra->inRepaint = true; |
|
9983 tlwExtra->backingStore->markDirty(rgn, this, true); |
|
9984 tlwExtra->inRepaint = false; |
|
9985 } |
|
9986 } else { |
|
9987 d->repaint_sys(rgn); |
|
9988 } |
|
9989 } |
|
9990 |
|
9991 /*! |
|
9992 Updates the widget unless updates are disabled or the widget is |
|
9993 hidden. |
|
9994 |
|
9995 This function does not cause an immediate repaint; instead it |
|
9996 schedules a paint event for processing when Qt returns to the main |
|
9997 event loop. This permits Qt to optimize for more speed and less |
|
9998 flicker than a call to repaint() does. |
|
9999 |
|
10000 Calling update() several times normally results in just one |
|
10001 paintEvent() call. |
|
10002 |
|
10003 Qt normally erases the widget's area before the paintEvent() call. |
|
10004 If the Qt::WA_OpaquePaintEvent widget attribute is set, the widget is |
|
10005 responsible for painting all its pixels with an opaque color. |
|
10006 |
|
10007 \sa repaint() paintEvent(), setUpdatesEnabled(), {Analog Clock Example} |
|
10008 */ |
|
10009 void QWidget::update() |
|
10010 { |
|
10011 update(rect()); |
|
10012 } |
|
10013 |
|
10014 /*! \fn void QWidget::update(int x, int y, int w, int h) |
|
10015 \overload |
|
10016 |
|
10017 This version updates a rectangle (\a x, \a y, \a w, \a h) inside |
|
10018 the widget. |
|
10019 */ |
|
10020 |
|
10021 /*! |
|
10022 \overload |
|
10023 |
|
10024 This version updates a rectangle \a rect inside the widget. |
|
10025 */ |
|
10026 void QWidget::update(const QRect &rect) |
|
10027 { |
|
10028 if (!isVisible() || !updatesEnabled() || rect.isEmpty()) |
|
10029 return; |
|
10030 |
|
10031 if (testAttribute(Qt::WA_WState_InPaintEvent)) { |
|
10032 QApplication::postEvent(this, new QUpdateLaterEvent(rect)); |
|
10033 return; |
|
10034 } |
|
10035 |
|
10036 if (hasBackingStoreSupport()) { |
|
10037 QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); |
|
10038 if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) |
|
10039 tlwExtra->backingStore->markDirty(rect, this); |
|
10040 } else { |
|
10041 d_func()->repaint_sys(rect); |
|
10042 } |
|
10043 } |
|
10044 |
|
10045 /*! |
|
10046 \overload |
|
10047 |
|
10048 This version repaints a region \a rgn inside the widget. |
|
10049 */ |
|
10050 void QWidget::update(const QRegion &rgn) |
|
10051 { |
|
10052 if (!isVisible() || !updatesEnabled() || rgn.isEmpty()) |
|
10053 return; |
|
10054 |
|
10055 if (testAttribute(Qt::WA_WState_InPaintEvent)) { |
|
10056 QApplication::postEvent(this, new QUpdateLaterEvent(rgn)); |
|
10057 return; |
|
10058 } |
|
10059 |
|
10060 if (hasBackingStoreSupport()) { |
|
10061 QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); |
|
10062 if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) |
|
10063 tlwExtra->backingStore->markDirty(rgn, this); |
|
10064 } else { |
|
10065 d_func()->repaint_sys(rgn); |
|
10066 } |
|
10067 } |
|
10068 |
|
10069 #ifdef QT3_SUPPORT |
|
10070 /*! |
|
10071 Clear the rectangle at point (\a x, \a y) of width \a w and height |
|
10072 \a h. |
|
10073 |
|
10074 \warning This is best done in a paintEvent(). |
|
10075 */ |
|
10076 void QWidget::erase_helper(int x, int y, int w, int h) |
|
10077 { |
|
10078 if (testAttribute(Qt::WA_NoSystemBackground) || testAttribute(Qt::WA_UpdatesDisabled) || !testAttribute(Qt::WA_WState_Visible)) |
|
10079 return; |
|
10080 if (w < 0) |
|
10081 w = data->crect.width() - x; |
|
10082 if (h < 0) |
|
10083 h = data->crect.height() - y; |
|
10084 if (w != 0 && h != 0) { |
|
10085 QPainter p(this); |
|
10086 p.eraseRect(QRect(x, y, w, h)); |
|
10087 } |
|
10088 } |
|
10089 |
|
10090 /*! |
|
10091 \overload |
|
10092 |
|
10093 Clear the given region, \a rgn. |
|
10094 |
|
10095 Drawing may only take place in a QPaintEvent. Overload |
|
10096 paintEvent() to do your erasing and call update() to schedule a |
|
10097 replaint whenever necessary. See also QPainter. |
|
10098 */ |
|
10099 void QWidget::erase(const QRegion& rgn) |
|
10100 { |
|
10101 if (testAttribute(Qt::WA_NoSystemBackground) || testAttribute(Qt::WA_UpdatesDisabled) || !testAttribute(Qt::WA_WState_Visible)) |
|
10102 return; |
|
10103 |
|
10104 QPainter p(this); |
|
10105 p.setClipRegion(rgn); |
|
10106 p.eraseRect(rgn.boundingRect()); |
|
10107 } |
|
10108 |
|
10109 void QWidget::drawText_helper(int x, int y, const QString &str) |
|
10110 { |
|
10111 if(!testAttribute(Qt::WA_WState_Visible)) |
|
10112 return; |
|
10113 QPainter paint(this); |
|
10114 paint.drawText(x, y, str); |
|
10115 } |
|
10116 |
|
10117 |
|
10118 /*! |
|
10119 Closes the widget. |
|
10120 |
|
10121 Use the no-argument overload instead. |
|
10122 */ |
|
10123 bool QWidget::close(bool alsoDelete) |
|
10124 { |
|
10125 QPointer<QWidget> that = this; |
|
10126 bool accepted = close(); |
|
10127 if (alsoDelete && accepted && that) |
|
10128 deleteLater(); |
|
10129 return accepted; |
|
10130 } |
|
10131 |
|
10132 void QWidget::setIcon(const QPixmap &i) |
|
10133 { |
|
10134 setWindowIcon(i); |
|
10135 } |
|
10136 |
|
10137 /*! |
|
10138 Return's the widget's icon. |
|
10139 |
|
10140 Use windowIcon() instead. |
|
10141 */ |
|
10142 const QPixmap *QWidget::icon() const |
|
10143 { |
|
10144 Q_D(const QWidget); |
|
10145 return (d->extra && d->extra->topextra) ? d->extra->topextra->iconPixmap : 0; |
|
10146 } |
|
10147 |
|
10148 #endif // QT3_SUPPORT |
|
10149 |
|
10150 /*! |
|
10151 Sets the attribute \a attribute on this widget if \a on is true; |
|
10152 otherwise clears the attribute. |
|
10153 |
|
10154 \sa testAttribute() |
|
10155 */ |
|
10156 void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) |
|
10157 { |
|
10158 if (testAttribute(attribute) == on) |
|
10159 return; |
|
10160 |
|
10161 Q_D(QWidget); |
|
10162 Q_ASSERT_X(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8), |
|
10163 "QWidget::setAttribute(WidgetAttribute, bool)", |
|
10164 "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute"); |
|
10165 |
|
10166 #ifdef Q_WS_WIN |
|
10167 // ### Don't use PaintOnScreen+paintEngine() to do native painting in 5.0 |
|
10168 if (attribute == Qt::WA_PaintOnScreen && on && !inherits("QGLWidget")) { |
|
10169 // see qwidget_win.cpp, ::paintEngine for details |
|
10170 paintEngine(); |
|
10171 if (d->noPaintOnScreen) |
|
10172 return; |
|
10173 } |
|
10174 #endif |
|
10175 |
|
10176 if (attribute < int(8*sizeof(uint))) { |
|
10177 if (on) |
|
10178 data->widget_attributes |= (1<<attribute); |
|
10179 else |
|
10180 data->widget_attributes &= ~(1<<attribute); |
|
10181 } else { |
|
10182 const int x = attribute - 8*sizeof(uint); |
|
10183 const int int_off = x / (8*sizeof(uint)); |
|
10184 if (on) |
|
10185 d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint)))); |
|
10186 else |
|
10187 d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint)))); |
|
10188 } |
|
10189 |
|
10190 switch (attribute) { |
|
10191 |
|
10192 #ifndef QT_NO_DRAGANDDROP |
|
10193 case Qt::WA_AcceptDrops: { |
|
10194 if (on && !testAttribute(Qt::WA_DropSiteRegistered)) |
|
10195 setAttribute(Qt::WA_DropSiteRegistered, true); |
|
10196 else if (!on && (isWindow() || !parentWidget() || !parentWidget()->testAttribute(Qt::WA_DropSiteRegistered))) |
|
10197 setAttribute(Qt::WA_DropSiteRegistered, false); |
|
10198 QEvent e(QEvent::AcceptDropsChange); |
|
10199 QApplication::sendEvent(this, &e); |
|
10200 break; |
|
10201 } |
|
10202 case Qt::WA_DropSiteRegistered: { |
|
10203 d->registerDropSite(on); |
|
10204 for (int i = 0; i < d->children.size(); ++i) { |
|
10205 QWidget *w = qobject_cast<QWidget *>(d->children.at(i)); |
|
10206 if (w && !w->isWindow() && !w->testAttribute(Qt::WA_AcceptDrops) && w->testAttribute(Qt::WA_DropSiteRegistered) != on) |
|
10207 w->setAttribute(Qt::WA_DropSiteRegistered, on); |
|
10208 } |
|
10209 break; |
|
10210 } |
|
10211 #endif |
|
10212 |
|
10213 case Qt::WA_NoChildEventsForParent: |
|
10214 d->sendChildEvents = !on; |
|
10215 break; |
|
10216 case Qt::WA_NoChildEventsFromChildren: |
|
10217 d->receiveChildEvents = !on; |
|
10218 break; |
|
10219 case Qt::WA_MacBrushedMetal: |
|
10220 #ifdef Q_WS_MAC |
|
10221 d->setStyle_helper(style(), false, true); // Make sure things get unpolished/polished correctly. |
|
10222 // fall through since changing the metal attribute affects the opaque size grip. |
|
10223 case Qt::WA_MacOpaqueSizeGrip: |
|
10224 d->macUpdateOpaqueSizeGrip(); |
|
10225 break; |
|
10226 case Qt::WA_MacShowFocusRect: |
|
10227 if (hasFocus()) { |
|
10228 clearFocus(); |
|
10229 setFocus(); |
|
10230 } |
|
10231 break; |
|
10232 case Qt::WA_Hover: |
|
10233 qt_mac_update_mouseTracking(this); |
|
10234 break; |
|
10235 #endif |
|
10236 case Qt::WA_MacAlwaysShowToolWindow: |
|
10237 #ifdef Q_WS_MAC |
|
10238 d->macUpdateHideOnSuspend(); |
|
10239 #endif |
|
10240 break; |
|
10241 case Qt::WA_MacNormalSize: |
|
10242 case Qt::WA_MacSmallSize: |
|
10243 case Qt::WA_MacMiniSize: |
|
10244 #ifdef Q_WS_MAC |
|
10245 { |
|
10246 // We can only have one of these set at a time |
|
10247 static const int MacSizes[] = { Qt::WA_MacNormalSize, Qt::WA_MacSmallSize, |
|
10248 Qt::WA_MacMiniSize, 0 }; |
|
10249 for (int i = 0; MacSizes[i] != 0; ++i) { |
|
10250 if (MacSizes[i] == attribute) |
|
10251 continue; |
|
10252 int macsize_x = MacSizes[i] - 8*sizeof(uint); |
|
10253 int macsize_int_off = macsize_x / (8*sizeof(uint)); |
|
10254 d->high_attributes[macsize_int_off] &= ~(1<<(macsize_x-(macsize_int_off*8*sizeof(uint)))); |
|
10255 } |
|
10256 d->macUpdateSizeAttribute(); |
|
10257 } |
|
10258 #endif |
|
10259 break; |
|
10260 case Qt::WA_ShowModal: |
|
10261 if (!on) { |
|
10262 if (isVisible()) |
|
10263 QApplicationPrivate::leaveModal(this); |
|
10264 // reset modality type to Modeless when clearing WA_ShowModal |
|
10265 data->window_modality = Qt::NonModal; |
|
10266 } else if (data->window_modality == Qt::NonModal) { |
|
10267 // determine the modality type if it hasn't been set prior |
|
10268 // to setting WA_ShowModal. set the default to WindowModal |
|
10269 // if we are the child of a group leader; otherwise use |
|
10270 // ApplicationModal. |
|
10271 QWidget *w = parentWidget(); |
|
10272 if (w) |
|
10273 w = w->window(); |
|
10274 while (w && !w->testAttribute(Qt::WA_GroupLeader)) { |
|
10275 w = w->parentWidget(); |
|
10276 if (w) |
|
10277 w = w->window(); |
|
10278 } |
|
10279 data->window_modality = (w && w->testAttribute(Qt::WA_GroupLeader)) |
|
10280 ? Qt::WindowModal |
|
10281 : Qt::ApplicationModal; |
|
10282 // Some window managers does not allow us to enter modal after the |
|
10283 // window is showing. Therefore, to be consistent, we cannot call |
|
10284 // QApplicationPrivate::enterModal(this) here. The window must be |
|
10285 // hidden before changing modality. |
|
10286 } |
|
10287 if (testAttribute(Qt::WA_WState_Created)) { |
|
10288 // don't call setModal_sys() before create_sys() |
|
10289 d->setModal_sys(); |
|
10290 } |
|
10291 break; |
|
10292 case Qt::WA_MouseTracking: { |
|
10293 QEvent e(QEvent::MouseTrackingChange); |
|
10294 QApplication::sendEvent(this, &e); |
|
10295 break; } |
|
10296 case Qt::WA_NativeWindow: { |
|
10297 QInputContext *ic = 0; |
|
10298 if (on && !internalWinId() && testAttribute(Qt::WA_InputMethodEnabled) && hasFocus()) { |
|
10299 ic = d->inputContext(); |
|
10300 ic->reset(); |
|
10301 ic->setFocusWidget(0); |
|
10302 } |
|
10303 if (!qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) && parentWidget()) |
|
10304 parentWidget()->d_func()->enforceNativeChildren(); |
|
10305 if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created)) |
|
10306 d->createWinId(); |
|
10307 if (ic && isEnabled()) |
|
10308 ic->setFocusWidget(this); |
|
10309 break; |
|
10310 } |
|
10311 case Qt::WA_PaintOnScreen: |
|
10312 d->updateIsOpaque(); |
|
10313 #if defined(Q_WS_WIN) || defined(Q_WS_X11) |
|
10314 // Recreate the widget if it's already created as an alien widget and |
|
10315 // WA_PaintOnScreen is enabled. Paint on screen widgets must have win id. |
|
10316 // So must their children. |
|
10317 if (on) { |
|
10318 setAttribute(Qt::WA_NativeWindow); |
|
10319 d->enforceNativeChildren(); |
|
10320 } |
|
10321 #endif |
|
10322 // fall through |
|
10323 case Qt::WA_OpaquePaintEvent: |
|
10324 d->updateIsOpaque(); |
|
10325 break; |
|
10326 case Qt::WA_NoSystemBackground: |
|
10327 d->updateIsOpaque(); |
|
10328 // fall through... |
|
10329 case Qt::WA_UpdatesDisabled: |
|
10330 d->updateSystemBackground(); |
|
10331 break; |
|
10332 case Qt::WA_TransparentForMouseEvents: |
|
10333 #ifdef Q_WS_MAC |
|
10334 d->macUpdateIgnoreMouseEvents(); |
|
10335 #endif |
|
10336 break; |
|
10337 case Qt::WA_InputMethodEnabled: { |
|
10338 QInputContext *ic = d->ic; |
|
10339 if (!ic && (!on || hasFocus())) |
|
10340 ic = d->inputContext(); |
|
10341 if (ic) { |
|
10342 if (on && hasFocus() && ic->focusWidget() != this && isEnabled()) { |
|
10343 ic->setFocusWidget(this); |
|
10344 } else if (!on && ic->focusWidget() == this) { |
|
10345 ic->reset(); |
|
10346 ic->setFocusWidget(0); |
|
10347 } |
|
10348 } |
|
10349 break; |
|
10350 } |
|
10351 case Qt::WA_WindowPropagation: |
|
10352 d->resolvePalette(); |
|
10353 d->resolveFont(); |
|
10354 d->resolveLocale(); |
|
10355 break; |
|
10356 #ifdef Q_WS_X11 |
|
10357 case Qt::WA_NoX11EventCompression: |
|
10358 if (!d->extra) |
|
10359 d->createExtra(); |
|
10360 d->extra->compress_events = on; |
|
10361 break; |
|
10362 case Qt::WA_X11OpenGLOverlay: |
|
10363 d->updateIsOpaque(); |
|
10364 break; |
|
10365 #endif |
|
10366 case Qt::WA_DontShowOnScreen: { |
|
10367 if (on && isVisible()) { |
|
10368 // Make sure we keep the current state and only hide the widget |
|
10369 // from the desktop. show_sys will only update platform specific |
|
10370 // attributes at this point. |
|
10371 d->hide_sys(); |
|
10372 #ifdef Q_WS_QWS |
|
10373 // Release the region for this window from qws if the widget has |
|
10374 // been shown before the attribute was set. |
|
10375 if (QWSWindowSurface *surface = static_cast<QWSWindowSurface *>(windowSurface())) { |
|
10376 QWidget::qwsDisplay()->requestRegion(surface->winId(), surface->key(), |
|
10377 surface->permanentState(), QRegion()); |
|
10378 } |
|
10379 #endif |
|
10380 d->show_sys(); |
|
10381 } |
|
10382 break; |
|
10383 } |
|
10384 |
|
10385 #ifdef Q_WS_X11 |
|
10386 case Qt::WA_X11NetWmWindowTypeDesktop: |
|
10387 case Qt::WA_X11NetWmWindowTypeDock: |
|
10388 case Qt::WA_X11NetWmWindowTypeToolBar: |
|
10389 case Qt::WA_X11NetWmWindowTypeMenu: |
|
10390 case Qt::WA_X11NetWmWindowTypeUtility: |
|
10391 case Qt::WA_X11NetWmWindowTypeSplash: |
|
10392 case Qt::WA_X11NetWmWindowTypeDialog: |
|
10393 case Qt::WA_X11NetWmWindowTypeDropDownMenu: |
|
10394 case Qt::WA_X11NetWmWindowTypePopupMenu: |
|
10395 case Qt::WA_X11NetWmWindowTypeToolTip: |
|
10396 case Qt::WA_X11NetWmWindowTypeNotification: |
|
10397 case Qt::WA_X11NetWmWindowTypeCombo: |
|
10398 case Qt::WA_X11NetWmWindowTypeDND: |
|
10399 if (testAttribute(Qt::WA_WState_Created)) |
|
10400 d->setNetWmWindowTypes(); |
|
10401 break; |
|
10402 #endif |
|
10403 |
|
10404 case Qt::WA_StaticContents: |
|
10405 if (QWidgetBackingStore *bs = d->maybeBackingStore()) { |
|
10406 if (on) |
|
10407 bs->addStaticWidget(this); |
|
10408 else |
|
10409 bs->removeStaticWidget(this); |
|
10410 } |
|
10411 break; |
|
10412 case Qt::WA_TranslucentBackground: |
|
10413 if (on) { |
|
10414 setAttribute(Qt::WA_NoSystemBackground); |
|
10415 d->updateIsTranslucent(); |
|
10416 } |
|
10417 |
|
10418 break; |
|
10419 case Qt::WA_AcceptTouchEvents: |
|
10420 #if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_WS_S60) |
|
10421 if (on) |
|
10422 d->registerTouchWindow(); |
|
10423 #endif |
|
10424 break; |
|
10425 default: |
|
10426 break; |
|
10427 } |
|
10428 } |
|
10429 |
|
10430 /*! \fn bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const |
|
10431 |
|
10432 Returns true if attribute \a attribute is set on this widget; |
|
10433 otherwise returns false. |
|
10434 |
|
10435 \sa setAttribute() |
|
10436 */ |
|
10437 bool QWidget::testAttribute_helper(Qt::WidgetAttribute attribute) const |
|
10438 { |
|
10439 Q_D(const QWidget); |
|
10440 const int x = attribute - 8*sizeof(uint); |
|
10441 const int int_off = x / (8*sizeof(uint)); |
|
10442 return (d->high_attributes[int_off] & (1<<(x-(int_off*8*sizeof(uint))))); |
|
10443 } |
|
10444 |
|
10445 /*! |
|
10446 \property QWidget::windowOpacity |
|
10447 |
|
10448 \brief The level of opacity for the window. |
|
10449 |
|
10450 The valid range of opacity is from 1.0 (completely opaque) to |
|
10451 0.0 (completely transparent). |
|
10452 |
|
10453 By default the value of this property is 1.0. |
|
10454 |
|
10455 This feature is available on Embedded Linux, Mac OS X, Windows, |
|
10456 and X11 platforms that support the Composite extension. |
|
10457 |
|
10458 This feature is not available on Windows CE. |
|
10459 |
|
10460 Note that under X11 you need to have a composite manager running, |
|
10461 and the X11 specific _NET_WM_WINDOW_OPACITY atom needs to be |
|
10462 supported by the window manager you are using. |
|
10463 |
|
10464 \warning Changing this property from opaque to transparent might issue a |
|
10465 paint event that needs to be processed before the window is displayed |
|
10466 correctly. This affects mainly the use of QPixmap::grabWindow(). Also note |
|
10467 that semi-transparent windows update and resize significantly slower than |
|
10468 opaque windows. |
|
10469 |
|
10470 \sa setMask() |
|
10471 */ |
|
10472 qreal QWidget::windowOpacity() const |
|
10473 { |
|
10474 Q_D(const QWidget); |
|
10475 return (isWindow() && d->maybeTopData()) ? d->maybeTopData()->opacity / 255. : 1.0; |
|
10476 } |
|
10477 |
|
10478 void QWidget::setWindowOpacity(qreal opacity) |
|
10479 { |
|
10480 Q_D(QWidget); |
|
10481 if (!isWindow()) |
|
10482 return; |
|
10483 |
|
10484 opacity = qBound(qreal(0.0), opacity, qreal(1.0)); |
|
10485 QTLWExtra *extra = d->topData(); |
|
10486 extra->opacity = uint(opacity * 255); |
|
10487 setAttribute(Qt::WA_WState_WindowOpacitySet); |
|
10488 |
|
10489 #ifndef Q_WS_QWS |
|
10490 if (!testAttribute(Qt::WA_WState_Created)) |
|
10491 return; |
|
10492 #endif |
|
10493 |
|
10494 #ifndef QT_NO_GRAPHICSVIEW |
|
10495 if (QGraphicsProxyWidget *proxy = graphicsProxyWidget()) { |
|
10496 // Avoid invalidating the cache if set. |
|
10497 if (proxy->cacheMode() == QGraphicsItem::NoCache) |
|
10498 proxy->update(); |
|
10499 else if (QGraphicsScene *scene = proxy->scene()) |
|
10500 scene->update(proxy->sceneBoundingRect()); |
|
10501 return; |
|
10502 } |
|
10503 #endif |
|
10504 |
|
10505 d->setWindowOpacity_sys(opacity); |
|
10506 } |
|
10507 |
|
10508 /*! |
|
10509 \property QWidget::windowModified |
|
10510 \brief whether the document shown in the window has unsaved changes |
|
10511 |
|
10512 A modified window is a window whose content has changed but has |
|
10513 not been saved to disk. This flag will have different effects |
|
10514 varied by the platform. On Mac OS X the close button will have a |
|
10515 modified look; on other platforms, the window title will have an |
|
10516 '*' (asterisk). |
|
10517 |
|
10518 The window title must contain a "[*]" placeholder, which |
|
10519 indicates where the '*' should appear. Normally, it should appear |
|
10520 right after the file name (e.g., "document1.txt[*] - Text |
|
10521 Editor"). If the window isn't modified, the placeholder is simply |
|
10522 removed. |
|
10523 |
|
10524 Note that if a widget is set as modified, all its ancestors will |
|
10525 also be set as modified. However, if you call \c |
|
10526 {setWindowModified(false)} on a widget, this will not propagate to |
|
10527 its parent because other children of the parent might have been |
|
10528 modified. |
|
10529 |
|
10530 \sa windowTitle, {Application Example}, {SDI Example}, {MDI Example} |
|
10531 */ |
|
10532 bool QWidget::isWindowModified() const |
|
10533 { |
|
10534 return testAttribute(Qt::WA_WindowModified); |
|
10535 } |
|
10536 |
|
10537 void QWidget::setWindowModified(bool mod) |
|
10538 { |
|
10539 Q_D(QWidget); |
|
10540 setAttribute(Qt::WA_WindowModified, mod); |
|
10541 |
|
10542 #ifndef Q_WS_MAC |
|
10543 if (!windowTitle().contains(QLatin1String("[*]")) && mod) |
|
10544 qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder"); |
|
10545 #endif |
|
10546 d->setWindowTitle_helper(windowTitle()); |
|
10547 d->setWindowIconText_helper(windowIconText()); |
|
10548 #ifdef Q_WS_MAC |
|
10549 d->setWindowModified_sys(mod); |
|
10550 #endif |
|
10551 |
|
10552 QEvent e(QEvent::ModifiedChange); |
|
10553 QApplication::sendEvent(this, &e); |
|
10554 } |
|
10555 |
|
10556 #ifndef QT_NO_TOOLTIP |
|
10557 /*! |
|
10558 \property QWidget::toolTip |
|
10559 |
|
10560 \brief the widget's tooltip |
|
10561 |
|
10562 Note that by default tooltips are only shown for widgets that are |
|
10563 children of the active window. You can change this behavior by |
|
10564 setting the attribute Qt::WA_AlwaysShowToolTips on the \e window, |
|
10565 not on the widget with the tooltip. |
|
10566 |
|
10567 If you want to control a tooltip's behavior, you can intercept the |
|
10568 event() function and catch the QEvent::ToolTip event (e.g., if you |
|
10569 want to customize the area for which the tooltip should be shown). |
|
10570 |
|
10571 By default, this property contains an empty string. |
|
10572 |
|
10573 \sa QToolTip statusTip whatsThis |
|
10574 */ |
|
10575 void QWidget::setToolTip(const QString &s) |
|
10576 { |
|
10577 Q_D(QWidget); |
|
10578 d->toolTip = s; |
|
10579 |
|
10580 QEvent event(QEvent::ToolTipChange); |
|
10581 QApplication::sendEvent(this, &event); |
|
10582 } |
|
10583 |
|
10584 QString QWidget::toolTip() const |
|
10585 { |
|
10586 Q_D(const QWidget); |
|
10587 return d->toolTip; |
|
10588 } |
|
10589 #endif // QT_NO_TOOLTIP |
|
10590 |
|
10591 |
|
10592 #ifndef QT_NO_STATUSTIP |
|
10593 /*! |
|
10594 \property QWidget::statusTip |
|
10595 \brief the widget's status tip |
|
10596 |
|
10597 By default, this property contains an empty string. |
|
10598 |
|
10599 \sa toolTip whatsThis |
|
10600 */ |
|
10601 void QWidget::setStatusTip(const QString &s) |
|
10602 { |
|
10603 Q_D(QWidget); |
|
10604 d->statusTip = s; |
|
10605 } |
|
10606 |
|
10607 QString QWidget::statusTip() const |
|
10608 { |
|
10609 Q_D(const QWidget); |
|
10610 return d->statusTip; |
|
10611 } |
|
10612 #endif // QT_NO_STATUSTIP |
|
10613 |
|
10614 #ifndef QT_NO_WHATSTHIS |
|
10615 /*! |
|
10616 \property QWidget::whatsThis |
|
10617 |
|
10618 \brief the widget's What's This help text. |
|
10619 |
|
10620 By default, this property contains an empty string. |
|
10621 |
|
10622 \sa QWhatsThis QWidget::toolTip QWidget::statusTip |
|
10623 */ |
|
10624 void QWidget::setWhatsThis(const QString &s) |
|
10625 { |
|
10626 Q_D(QWidget); |
|
10627 d->whatsThis = s; |
|
10628 } |
|
10629 |
|
10630 QString QWidget::whatsThis() const |
|
10631 { |
|
10632 Q_D(const QWidget); |
|
10633 return d->whatsThis; |
|
10634 } |
|
10635 #endif // QT_NO_WHATSTHIS |
|
10636 |
|
10637 #ifndef QT_NO_ACCESSIBILITY |
|
10638 /*! |
|
10639 \property QWidget::accessibleName |
|
10640 |
|
10641 \brief the widget's name as seen by assistive technologies |
|
10642 |
|
10643 This property is used by accessible clients to identify, find, or announce |
|
10644 the widget for accessible clients. |
|
10645 |
|
10646 By default, this property contains an empty string. |
|
10647 |
|
10648 \sa QAccessibleInterface::text() |
|
10649 */ |
|
10650 void QWidget::setAccessibleName(const QString &name) |
|
10651 { |
|
10652 Q_D(QWidget); |
|
10653 d->accessibleName = name; |
|
10654 } |
|
10655 |
|
10656 QString QWidget::accessibleName() const |
|
10657 { |
|
10658 Q_D(const QWidget); |
|
10659 return d->accessibleName; |
|
10660 } |
|
10661 |
|
10662 /*! |
|
10663 \property QWidget::accessibleDescription |
|
10664 |
|
10665 \brief the widget's description as seen by assistive technologies |
|
10666 |
|
10667 By default, this property contains an empty string. |
|
10668 |
|
10669 \sa QAccessibleInterface::text() |
|
10670 */ |
|
10671 void QWidget::setAccessibleDescription(const QString &description) |
|
10672 { |
|
10673 Q_D(QWidget); |
|
10674 d->accessibleDescription = description; |
|
10675 } |
|
10676 |
|
10677 QString QWidget::accessibleDescription() const |
|
10678 { |
|
10679 Q_D(const QWidget); |
|
10680 return d->accessibleDescription; |
|
10681 } |
|
10682 #endif // QT_NO_ACCESSIBILITY |
|
10683 |
|
10684 #ifndef QT_NO_SHORTCUT |
|
10685 /*! |
|
10686 Adds a shortcut to Qt's shortcut system that watches for the given |
|
10687 \a key sequence in the given \a context. If the \a context is |
|
10688 Qt::ApplicationShortcut, the shortcut applies to the application as a |
|
10689 whole. Otherwise, it is either local to this widget, Qt::WidgetShortcut, |
|
10690 or to the window itself, Qt::WindowShortcut. |
|
10691 |
|
10692 If the same \a key sequence has been grabbed by several widgets, |
|
10693 when the \a key sequence occurs a QEvent::Shortcut event is sent |
|
10694 to all the widgets to which it applies in a non-deterministic |
|
10695 order, but with the ``ambiguous'' flag set to true. |
|
10696 |
|
10697 \warning You should not normally need to use this function; |
|
10698 instead create \l{QAction}s with the shortcut key sequences you |
|
10699 require (if you also want equivalent menu options and toolbar |
|
10700 buttons), or create \l{QShortcut}s if you just need key sequences. |
|
10701 Both QAction and QShortcut handle all the event filtering for you, |
|
10702 and provide signals which are triggered when the user triggers the |
|
10703 key sequence, so are much easier to use than this low-level |
|
10704 function. |
|
10705 |
|
10706 \sa releaseShortcut() setShortcutEnabled() |
|
10707 */ |
|
10708 int QWidget::grabShortcut(const QKeySequence &key, Qt::ShortcutContext context) |
|
10709 { |
|
10710 Q_ASSERT(qApp); |
|
10711 if (key.isEmpty()) |
|
10712 return 0; |
|
10713 setAttribute(Qt::WA_GrabbedShortcut); |
|
10714 return qApp->d_func()->shortcutMap.addShortcut(this, key, context); |
|
10715 } |
|
10716 |
|
10717 /*! |
|
10718 Removes the shortcut with the given \a id from Qt's shortcut |
|
10719 system. The widget will no longer receive QEvent::Shortcut events |
|
10720 for the shortcut's key sequence (unless it has other shortcuts |
|
10721 with the same key sequence). |
|
10722 |
|
10723 \warning You should not normally need to use this function since |
|
10724 Qt's shortcut system removes shortcuts automatically when their |
|
10725 parent widget is destroyed. It is best to use QAction or |
|
10726 QShortcut to handle shortcuts, since they are easier to use than |
|
10727 this low-level function. Note also that this is an expensive |
|
10728 operation. |
|
10729 |
|
10730 \sa grabShortcut() setShortcutEnabled() |
|
10731 */ |
|
10732 void QWidget::releaseShortcut(int id) |
|
10733 { |
|
10734 Q_ASSERT(qApp); |
|
10735 if (id) |
|
10736 qApp->d_func()->shortcutMap.removeShortcut(id, this, 0); |
|
10737 } |
|
10738 |
|
10739 /*! |
|
10740 If \a enable is true, the shortcut with the given \a id is |
|
10741 enabled; otherwise the shortcut is disabled. |
|
10742 |
|
10743 \warning You should not normally need to use this function since |
|
10744 Qt's shortcut system enables/disables shortcuts automatically as |
|
10745 widgets become hidden/visible and gain or lose focus. It is best |
|
10746 to use QAction or QShortcut to handle shortcuts, since they are |
|
10747 easier to use than this low-level function. |
|
10748 |
|
10749 \sa grabShortcut() releaseShortcut() |
|
10750 */ |
|
10751 void QWidget::setShortcutEnabled(int id, bool enable) |
|
10752 { |
|
10753 Q_ASSERT(qApp); |
|
10754 if (id) |
|
10755 qApp->d_func()->shortcutMap.setShortcutEnabled(enable, id, this, 0); |
|
10756 } |
|
10757 |
|
10758 /*! |
|
10759 \since 4.2 |
|
10760 |
|
10761 If \a enable is true, auto repeat of the shortcut with the |
|
10762 given \a id is enabled; otherwise it is disabled. |
|
10763 |
|
10764 \sa grabShortcut() releaseShortcut() |
|
10765 */ |
|
10766 void QWidget::setShortcutAutoRepeat(int id, bool enable) |
|
10767 { |
|
10768 Q_ASSERT(qApp); |
|
10769 if (id) |
|
10770 qApp->d_func()->shortcutMap.setShortcutAutoRepeat(enable, id, this, 0); |
|
10771 } |
|
10772 #endif // QT_NO_SHORTCUT |
|
10773 /*! |
|
10774 Updates the widget's micro focus. |
|
10775 |
|
10776 \sa QInputContext |
|
10777 */ |
|
10778 void QWidget::updateMicroFocus() |
|
10779 { |
|
10780 #if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)) |
|
10781 Q_D(QWidget); |
|
10782 // and optimisation to update input context only it has already been created. |
|
10783 if (d->ic || qApp->d_func()->inputContext) { |
|
10784 QInputContext *ic = inputContext(); |
|
10785 if (ic) |
|
10786 ic->update(); |
|
10787 } |
|
10788 #endif |
|
10789 #ifndef QT_NO_ACCESSIBILITY |
|
10790 // ##### is this correct |
|
10791 QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged); |
|
10792 #endif |
|
10793 } |
|
10794 |
|
10795 |
|
10796 #if defined (Q_WS_WIN) |
|
10797 /*! |
|
10798 Returns the window system handle of the widget, for low-level |
|
10799 access. Using this function is not portable. |
|
10800 |
|
10801 An HDC acquired with getDC() has to be released with releaseDC(). |
|
10802 |
|
10803 \warning Using this function is not portable. |
|
10804 */ |
|
10805 HDC QWidget::getDC() const |
|
10806 { |
|
10807 Q_D(const QWidget); |
|
10808 if (d->hd) |
|
10809 return (HDC) d->hd; |
|
10810 return GetDC(winId()); |
|
10811 } |
|
10812 |
|
10813 /*! |
|
10814 Releases the HDC \a hdc acquired by a previous call to getDC(). |
|
10815 |
|
10816 \warning Using this function is not portable. |
|
10817 */ |
|
10818 void QWidget::releaseDC(HDC hdc) const |
|
10819 { |
|
10820 Q_D(const QWidget); |
|
10821 // If its the widgets own dc, it will be released elsewhere. If |
|
10822 // its a different HDC we release it and issue a warning if it |
|
10823 // fails. |
|
10824 if (hdc != d->hd && !ReleaseDC(winId(), hdc)) |
|
10825 qErrnoWarning("QWidget::releaseDC(): failed to release HDC"); |
|
10826 } |
|
10827 #else |
|
10828 /*! |
|
10829 Returns the window system handle of the widget, for low-level |
|
10830 access. Using this function is not portable. |
|
10831 |
|
10832 The HANDLE type varies with platform; see \c qwindowdefs.h for |
|
10833 details. |
|
10834 */ |
|
10835 Qt::HANDLE QWidget::handle() const |
|
10836 { |
|
10837 Q_D(const QWidget); |
|
10838 if (!internalWinId() && testAttribute(Qt::WA_WState_Created)) |
|
10839 (void)winId(); // enforce native window |
|
10840 return d->hd; |
|
10841 } |
|
10842 #endif |
|
10843 |
|
10844 |
|
10845 /*! |
|
10846 Raises this widget to the top of the parent widget's stack. |
|
10847 |
|
10848 After this call the widget will be visually in front of any |
|
10849 overlapping sibling widgets. |
|
10850 |
|
10851 \note When using activateWindow(), you can call this function to |
|
10852 ensure that the window is stacked on top. |
|
10853 |
|
10854 \sa lower(), stackUnder() |
|
10855 */ |
|
10856 |
|
10857 void QWidget::raise() |
|
10858 { |
|
10859 Q_D(QWidget); |
|
10860 if (!isWindow()) { |
|
10861 QWidget *p = parentWidget(); |
|
10862 const int parentChildCount = p->d_func()->children.size(); |
|
10863 if (parentChildCount < 2) |
|
10864 return; |
|
10865 const int from = p->d_func()->children.indexOf(this); |
|
10866 Q_ASSERT(from >= 0); |
|
10867 // Do nothing if the widget is already in correct stacking order _and_ created. |
|
10868 if (from != parentChildCount -1) |
|
10869 p->d_func()->children.move(from, parentChildCount - 1); |
|
10870 if (!testAttribute(Qt::WA_WState_Created) && p->testAttribute(Qt::WA_WState_Created)) |
|
10871 create(); |
|
10872 else if (from == parentChildCount - 1) |
|
10873 return; |
|
10874 |
|
10875 QRegion region(rect()); |
|
10876 d->subtractOpaqueSiblings(region); |
|
10877 d->invalidateBuffer(region); |
|
10878 } |
|
10879 if (testAttribute(Qt::WA_WState_Created)) |
|
10880 d->raise_sys(); |
|
10881 |
|
10882 QEvent e(QEvent::ZOrderChange); |
|
10883 QApplication::sendEvent(this, &e); |
|
10884 } |
|
10885 |
|
10886 /*! |
|
10887 Lowers the widget to the bottom of the parent widget's stack. |
|
10888 |
|
10889 After this call the widget will be visually behind (and therefore |
|
10890 obscured by) any overlapping sibling widgets. |
|
10891 |
|
10892 \sa raise(), stackUnder() |
|
10893 */ |
|
10894 |
|
10895 void QWidget::lower() |
|
10896 { |
|
10897 Q_D(QWidget); |
|
10898 if (!isWindow()) { |
|
10899 QWidget *p = parentWidget(); |
|
10900 const int parentChildCount = p->d_func()->children.size(); |
|
10901 if (parentChildCount < 2) |
|
10902 return; |
|
10903 const int from = p->d_func()->children.indexOf(this); |
|
10904 Q_ASSERT(from >= 0); |
|
10905 // Do nothing if the widget is already in correct stacking order _and_ created. |
|
10906 if (from != 0) |
|
10907 p->d_func()->children.move(from, 0); |
|
10908 if (!testAttribute(Qt::WA_WState_Created) && p->testAttribute(Qt::WA_WState_Created)) |
|
10909 create(); |
|
10910 else if (from == 0) |
|
10911 return; |
|
10912 } |
|
10913 if (testAttribute(Qt::WA_WState_Created)) |
|
10914 d->lower_sys(); |
|
10915 |
|
10916 QEvent e(QEvent::ZOrderChange); |
|
10917 QApplication::sendEvent(this, &e); |
|
10918 } |
|
10919 |
|
10920 |
|
10921 /*! |
|
10922 Places the widget under \a w in the parent widget's stack. |
|
10923 |
|
10924 To make this work, the widget itself and \a w must be siblings. |
|
10925 |
|
10926 \sa raise(), lower() |
|
10927 */ |
|
10928 void QWidget::stackUnder(QWidget* w) |
|
10929 { |
|
10930 Q_D(QWidget); |
|
10931 QWidget *p = parentWidget(); |
|
10932 if (!w || isWindow() || p != w->parentWidget() || this == w) |
|
10933 return; |
|
10934 if (p) { |
|
10935 int from = p->d_func()->children.indexOf(this); |
|
10936 int to = p->d_func()->children.indexOf(w); |
|
10937 Q_ASSERT(from >= 0); |
|
10938 Q_ASSERT(to >= 0); |
|
10939 if (from < to) |
|
10940 --to; |
|
10941 // Do nothing if the widget is already in correct stacking order _and_ created. |
|
10942 if (from != to) |
|
10943 p->d_func()->children.move(from, to); |
|
10944 if (!testAttribute(Qt::WA_WState_Created) && p->testAttribute(Qt::WA_WState_Created)) |
|
10945 create(); |
|
10946 else if (from == to) |
|
10947 return; |
|
10948 } |
|
10949 if (testAttribute(Qt::WA_WState_Created)) |
|
10950 d->stackUnder_sys(w); |
|
10951 |
|
10952 QEvent e(QEvent::ZOrderChange); |
|
10953 QApplication::sendEvent(this, &e); |
|
10954 } |
|
10955 |
|
10956 void QWidget::styleChange(QStyle&) { } |
|
10957 void QWidget::enabledChange(bool) { } // compat |
|
10958 void QWidget::paletteChange(const QPalette &) { } // compat |
|
10959 void QWidget::fontChange(const QFont &) { } // compat |
|
10960 void QWidget::windowActivationChange(bool) { } // compat |
|
10961 void QWidget::languageChange() { } // compat |
|
10962 |
|
10963 |
|
10964 /*! |
|
10965 \enum QWidget::BackgroundOrigin |
|
10966 |
|
10967 \compat |
|
10968 |
|
10969 \value WidgetOrigin |
|
10970 \value ParentOrigin |
|
10971 \value WindowOrigin |
|
10972 \value AncestorOrigin |
|
10973 |
|
10974 */ |
|
10975 |
|
10976 /*! |
|
10977 \fn bool QWidget::isVisibleToTLW() const |
|
10978 |
|
10979 Use isVisible() instead. |
|
10980 */ |
|
10981 |
|
10982 /*! |
|
10983 \fn void QWidget::iconify() |
|
10984 |
|
10985 Use showMinimized() instead. |
|
10986 */ |
|
10987 |
|
10988 /*! |
|
10989 \fn void QWidget::constPolish() const |
|
10990 |
|
10991 Use ensurePolished() instead. |
|
10992 */ |
|
10993 |
|
10994 /*! |
|
10995 \fn void QWidget::reparent(QWidget *parent, Qt::WindowFlags f, const QPoint &p, bool showIt) |
|
10996 |
|
10997 Use setParent() to change the parent or the widget's widget flags; |
|
10998 use move() to move the widget, and use show() to show the widget. |
|
10999 */ |
|
11000 |
|
11001 /*! |
|
11002 \fn void QWidget::reparent(QWidget *parent, const QPoint &p, bool showIt) |
|
11003 |
|
11004 Use setParent() to change the parent; use move() to move the |
|
11005 widget, and use show() to show the widget. |
|
11006 */ |
|
11007 |
|
11008 /*! |
|
11009 \fn void QWidget::recreate(QWidget *parent, Qt::WindowFlags f, const QPoint & p, bool showIt) |
|
11010 |
|
11011 Use setParent() to change the parent or the widget's widget flags; |
|
11012 use move() to move the widget, and use show() to show the widget. |
|
11013 */ |
|
11014 |
|
11015 /*! |
|
11016 \fn bool QWidget::hasMouse() const |
|
11017 |
|
11018 Use testAttribute(Qt::WA_UnderMouse) instead. |
|
11019 */ |
|
11020 |
|
11021 /*! |
|
11022 \fn bool QWidget::ownCursor() const |
|
11023 |
|
11024 Use testAttribute(Qt::WA_SetCursor) instead. |
|
11025 */ |
|
11026 |
|
11027 /*! |
|
11028 \fn bool QWidget::ownFont() const |
|
11029 |
|
11030 Use testAttribute(Qt::WA_SetFont) instead. |
|
11031 */ |
|
11032 |
|
11033 /*! |
|
11034 \fn void QWidget::unsetFont() |
|
11035 |
|
11036 Use setFont(QFont()) instead. |
|
11037 */ |
|
11038 |
|
11039 /*! |
|
11040 \fn bool QWidget::ownPalette() const |
|
11041 |
|
11042 Use testAttribute(Qt::WA_SetPalette) instead. |
|
11043 */ |
|
11044 |
|
11045 /*! |
|
11046 \fn void QWidget::unsetPalette() |
|
11047 |
|
11048 Use setPalette(QPalette()) instead. |
|
11049 */ |
|
11050 |
|
11051 /*! |
|
11052 \fn void QWidget::setEraseColor(const QColor &color) |
|
11053 |
|
11054 Use the palette instead. |
|
11055 |
|
11056 \oldcode |
|
11057 widget->setEraseColor(color); |
|
11058 \newcode |
|
11059 QPalette palette; |
|
11060 palette.setColor(widget->backgroundRole(), color); |
|
11061 widget->setPalette(palette); |
|
11062 \endcode |
|
11063 */ |
|
11064 |
|
11065 /*! |
|
11066 \fn void QWidget::setErasePixmap(const QPixmap &pixmap) |
|
11067 |
|
11068 Use the palette instead. |
|
11069 |
|
11070 \oldcode |
|
11071 widget->setErasePixmap(pixmap); |
|
11072 \newcode |
|
11073 QPalette palette; |
|
11074 palette.setBrush(widget->backgroundRole(), QBrush(pixmap)); |
|
11075 widget->setPalette(palette); |
|
11076 \endcode |
|
11077 */ |
|
11078 |
|
11079 /*! |
|
11080 \fn void QWidget::setPaletteForegroundColor(const QColor &color) |
|
11081 |
|
11082 Use the palette directly. |
|
11083 |
|
11084 \oldcode |
|
11085 widget->setPaletteForegroundColor(color); |
|
11086 \newcode |
|
11087 QPalette palette; |
|
11088 palette.setColor(widget->foregroundRole(), color); |
|
11089 widget->setPalette(palette); |
|
11090 \endcode |
|
11091 */ |
|
11092 |
|
11093 /*! |
|
11094 \fn void QWidget::setPaletteBackgroundColor(const QColor &color) |
|
11095 |
|
11096 Use the palette directly. |
|
11097 |
|
11098 \oldcode |
|
11099 widget->setPaletteBackgroundColor(color); |
|
11100 \newcode |
|
11101 QPalette palette; |
|
11102 palette.setColor(widget->backgroundRole(), color); |
|
11103 widget->setPalette(palette); |
|
11104 \endcode |
|
11105 */ |
|
11106 |
|
11107 /*! |
|
11108 \fn void QWidget::setPaletteBackgroundPixmap(const QPixmap &pixmap) |
|
11109 |
|
11110 Use the palette directly. |
|
11111 |
|
11112 \oldcode |
|
11113 widget->setPaletteBackgroundPixmap(pixmap); |
|
11114 \newcode |
|
11115 QPalette palette; |
|
11116 palette.setBrush(widget->backgroundRole(), QBrush(pixmap)); |
|
11117 widget->setPalette(palette); |
|
11118 \endcode |
|
11119 */ |
|
11120 |
|
11121 /*! |
|
11122 \fn void QWidget::setBackgroundPixmap(const QPixmap &pixmap) |
|
11123 |
|
11124 Use the palette instead. |
|
11125 |
|
11126 \oldcode |
|
11127 widget->setBackgroundPixmap(pixmap); |
|
11128 \newcode |
|
11129 QPalette palette; |
|
11130 palette.setBrush(widget->backgroundRole(), QBrush(pixmap)); |
|
11131 widget->setPalette(palette); |
|
11132 \endcode |
|
11133 */ |
|
11134 |
|
11135 /*! |
|
11136 \fn void QWidget::setBackgroundColor(const QColor &color) |
|
11137 |
|
11138 Use the palette instead. |
|
11139 |
|
11140 \oldcode |
|
11141 widget->setBackgroundColor(color); |
|
11142 \newcode |
|
11143 QPalette palette; |
|
11144 palette.setColor(widget->backgroundRole(), color); |
|
11145 widget->setPalette(palette); |
|
11146 \endcode |
|
11147 */ |
|
11148 |
|
11149 /*! |
|
11150 \fn QColorGroup QWidget::colorGroup() const |
|
11151 |
|
11152 Use QColorGroup(palette()) instead. |
|
11153 */ |
|
11154 |
|
11155 /*! |
|
11156 \fn QWidget *QWidget::parentWidget(bool sameWindow) const |
|
11157 |
|
11158 Use the no-argument overload instead. |
|
11159 */ |
|
11160 |
|
11161 /*! |
|
11162 \fn void QWidget::setKeyCompression(bool b) |
|
11163 |
|
11164 Use setAttribute(Qt::WA_KeyCompression, b) instead. |
|
11165 */ |
|
11166 |
|
11167 /*! |
|
11168 \fn void QWidget::setFont(const QFont &f, bool b) |
|
11169 |
|
11170 Use the single-argument overload instead. |
|
11171 */ |
|
11172 |
|
11173 /*! |
|
11174 \fn void QWidget::setPalette(const QPalette &p, bool b) |
|
11175 |
|
11176 Use the single-argument overload instead. |
|
11177 */ |
|
11178 |
|
11179 /*! |
|
11180 \fn void QWidget::setBackgroundOrigin(BackgroundOrigin background) |
|
11181 |
|
11182 \obsolete |
|
11183 */ |
|
11184 |
|
11185 /*! |
|
11186 \fn BackgroundOrigin QWidget::backgroundOrigin() const |
|
11187 |
|
11188 \obsolete |
|
11189 |
|
11190 Always returns \c WindowOrigin. |
|
11191 */ |
|
11192 |
|
11193 /*! |
|
11194 \fn QPoint QWidget::backgroundOffset() const |
|
11195 |
|
11196 \obsolete |
|
11197 |
|
11198 Always returns QPoint(). |
|
11199 */ |
|
11200 |
|
11201 /*! |
|
11202 \fn void QWidget::repaint(bool b) |
|
11203 |
|
11204 The boolean parameter \a b is ignored. Use the no-argument overload instead. |
|
11205 */ |
|
11206 |
|
11207 /*! |
|
11208 \fn void QWidget::repaint(int x, int y, int w, int h, bool b) |
|
11209 |
|
11210 The boolean parameter \a b is ignored. Use the four-argument overload instead. |
|
11211 */ |
|
11212 |
|
11213 /*! |
|
11214 \fn void QWidget::repaint(const QRect &r, bool b) |
|
11215 |
|
11216 The boolean parameter \a b is ignored. Use the single rect-argument overload instead. |
|
11217 */ |
|
11218 |
|
11219 /*! |
|
11220 \fn void QWidget::repaint(const QRegion &rgn, bool b) |
|
11221 |
|
11222 The boolean parameter \a b is ignored. Use the single region-argument overload instead. |
|
11223 */ |
|
11224 |
|
11225 /*! |
|
11226 \fn void QWidget::erase() |
|
11227 |
|
11228 Drawing may only take place in a QPaintEvent. Overload |
|
11229 paintEvent() to do your erasing and call update() to schedule a |
|
11230 replaint whenever necessary. See also QPainter. |
|
11231 */ |
|
11232 |
|
11233 /*! |
|
11234 \fn void QWidget::erase(int x, int y, int w, int h) |
|
11235 |
|
11236 Drawing may only take place in a QPaintEvent. Overload |
|
11237 paintEvent() to do your erasing and call update() to schedule a |
|
11238 replaint whenever necessary. See also QPainter. |
|
11239 */ |
|
11240 |
|
11241 /*! |
|
11242 \fn void QWidget::erase(const QRect &rect) |
|
11243 |
|
11244 Drawing may only take place in a QPaintEvent. Overload |
|
11245 paintEvent() to do your erasing and call update() to schedule a |
|
11246 replaint whenever necessary. See also QPainter. |
|
11247 */ |
|
11248 |
|
11249 /*! |
|
11250 \fn void QWidget::drawText(const QPoint &p, const QString &s) |
|
11251 |
|
11252 Drawing may only take place in a QPaintEvent. Overload |
|
11253 paintEvent() to do your drawing and call update() to schedule a |
|
11254 replaint whenever necessary. See also QPainter. |
|
11255 */ |
|
11256 |
|
11257 /*! |
|
11258 \fn void QWidget::drawText(int x, int y, const QString &s) |
|
11259 |
|
11260 Drawing may only take place in a QPaintEvent. Overload |
|
11261 paintEvent() to do your drawing and call update() to schedule a |
|
11262 replaint whenever necessary. See also QPainter. |
|
11263 */ |
|
11264 |
|
11265 /*! |
|
11266 \fn QWidget *QWidget::childAt(const QPoint &p, bool includeThis) const |
|
11267 |
|
11268 Use the single point argument overload instead. |
|
11269 */ |
|
11270 |
|
11271 /*! |
|
11272 \fn void QWidget::setCaption(const QString &c) |
|
11273 |
|
11274 Use setWindowTitle() instead. |
|
11275 */ |
|
11276 |
|
11277 /*! |
|
11278 \fn void QWidget::setIcon(const QPixmap &i) |
|
11279 |
|
11280 Use setWindowIcon() instead. |
|
11281 */ |
|
11282 |
|
11283 /*! |
|
11284 \fn void QWidget::setIconText(const QString &it) |
|
11285 |
|
11286 Use setWindowIconText() instead. |
|
11287 */ |
|
11288 |
|
11289 /*! |
|
11290 \fn QString QWidget::caption() const |
|
11291 |
|
11292 Use windowTitle() instead. |
|
11293 */ |
|
11294 |
|
11295 /*! |
|
11296 \fn QString QWidget::iconText() const |
|
11297 |
|
11298 Use windowIconText() instead. |
|
11299 */ |
|
11300 |
|
11301 /*! |
|
11302 \fn bool QWidget::isTopLevel() const |
|
11303 \obsolete |
|
11304 |
|
11305 Use isWindow() instead. |
|
11306 */ |
|
11307 |
|
11308 /*! |
|
11309 \fn bool QWidget::isRightToLeft() const |
|
11310 \internal |
|
11311 */ |
|
11312 |
|
11313 /*! |
|
11314 \fn bool QWidget::isLeftToRight() const |
|
11315 \internal |
|
11316 */ |
|
11317 |
|
11318 /*! |
|
11319 \fn void QWidget::setInputMethodEnabled(bool enabled) |
|
11320 |
|
11321 Use setAttribute(Qt::WA_InputMethodEnabled, \a enabled) instead. |
|
11322 */ |
|
11323 |
|
11324 /*! |
|
11325 \fn bool QWidget::isInputMethodEnabled() const |
|
11326 |
|
11327 Use testAttribute(Qt::WA_InputMethodEnabled) instead. |
|
11328 */ |
|
11329 |
|
11330 /*! |
|
11331 \fn void QWidget::setActiveWindow() |
|
11332 |
|
11333 Use activateWindow() instead. |
|
11334 */ |
|
11335 |
|
11336 /*! |
|
11337 \fn bool QWidget::isShown() const |
|
11338 |
|
11339 Use !isHidden() instead (notice the exclamation mark), or use isVisible() to check whether the widget is visible. |
|
11340 */ |
|
11341 |
|
11342 /*! |
|
11343 \fn bool QWidget::isDialog() const |
|
11344 |
|
11345 Use windowType() == Qt::Dialog instead. |
|
11346 */ |
|
11347 |
|
11348 /*! |
|
11349 \fn bool QWidget::isPopup() const |
|
11350 |
|
11351 Use windowType() == Qt::Popup instead. |
|
11352 */ |
|
11353 |
|
11354 /*! |
|
11355 \fn bool QWidget::isDesktop() const |
|
11356 |
|
11357 Use windowType() == Qt::Desktop instead. |
|
11358 */ |
|
11359 |
|
11360 /*! |
|
11361 \fn void QWidget::polish() |
|
11362 |
|
11363 Use ensurePolished() instead. |
|
11364 */ |
|
11365 |
|
11366 /*! |
|
11367 \fn QWidget *QWidget::childAt(int x, int y, bool includeThis) const |
|
11368 |
|
11369 Use the childAt() overload that doesn't have an \a includeThis parameter. |
|
11370 |
|
11371 \oldcode |
|
11372 return widget->childAt(x, y, true); |
|
11373 \newcode |
|
11374 QWidget *child = widget->childAt(x, y, true); |
|
11375 if (child) |
|
11376 return child; |
|
11377 if (widget->rect().contains(x, y)) |
|
11378 return widget; |
|
11379 \endcode |
|
11380 */ |
|
11381 |
|
11382 /*! |
|
11383 \fn void QWidget::setSizePolicy(QSizePolicy::Policy hor, QSizePolicy::Policy ver, bool hfw) |
|
11384 \compat |
|
11385 |
|
11386 Use the \l sizePolicy property and heightForWidth() function instead. |
|
11387 */ |
|
11388 |
|
11389 /*! |
|
11390 \fn bool QWidget::isUpdatesEnabled() const |
|
11391 \compat |
|
11392 |
|
11393 Use the \l updatesEnabled property instead. |
|
11394 */ |
|
11395 |
|
11396 /*! |
|
11397 \macro QWIDGETSIZE_MAX |
|
11398 \relates QWidget |
|
11399 |
|
11400 Defines the maximum size for a QWidget object. |
|
11401 |
|
11402 The largest allowed size for a widget is QSize(QWIDGETSIZE_MAX, |
|
11403 QWIDGETSIZE_MAX), i.e. QSize (16777215,16777215). |
|
11404 |
|
11405 \sa QWidget::setMaximumSize() |
|
11406 */ |
|
11407 |
|
11408 QRect QWidgetPrivate::frameStrut() const |
|
11409 { |
|
11410 Q_Q(const QWidget); |
|
11411 if (!q->isWindow() || (q->windowType() == Qt::Desktop) || q->testAttribute(Qt::WA_DontShowOnScreen)) { |
|
11412 // x2 = x1 + w - 1, so w/h = 1 |
|
11413 return QRect(0, 0, 1, 1); |
|
11414 } |
|
11415 |
|
11416 if (data.fstrut_dirty |
|
11417 #ifndef Q_WS_WIN |
|
11418 // ### Fix properly for 4.3 |
|
11419 && q->isVisible() |
|
11420 #endif |
|
11421 && q->testAttribute(Qt::WA_WState_Created)) |
|
11422 const_cast<QWidgetPrivate *>(this)->updateFrameStrut(); |
|
11423 |
|
11424 return maybeTopData() ? maybeTopData()->frameStrut : QRect(); |
|
11425 } |
|
11426 |
|
11427 #ifdef QT_KEYPAD_NAVIGATION |
|
11428 /*! |
|
11429 \internal |
|
11430 |
|
11431 Changes the focus from the current focusWidget to a widget in |
|
11432 the \a direction. |
|
11433 |
|
11434 Returns true, if there was a widget in that direction |
|
11435 */ |
|
11436 bool QWidgetPrivate::navigateToDirection(Direction direction) |
|
11437 { |
|
11438 QWidget *targetWidget = widgetInNavigationDirection(direction); |
|
11439 if (targetWidget) |
|
11440 targetWidget->setFocus(); |
|
11441 return (targetWidget != 0); |
|
11442 } |
|
11443 |
|
11444 /*! |
|
11445 \internal |
|
11446 |
|
11447 Searches for a widget that is positioned in the \a direction, starting |
|
11448 from the current focusWidget. |
|
11449 |
|
11450 Returns the pointer to a found widget or 0, if there was no widget in |
|
11451 that direction. |
|
11452 */ |
|
11453 QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction) |
|
11454 { |
|
11455 const QWidget *sourceWidget = QApplication::focusWidget(); |
|
11456 if (!sourceWidget) |
|
11457 return 0; |
|
11458 const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint())); |
|
11459 const int sourceX = |
|
11460 (direction == DirectionNorth || direction == DirectionSouth) ? |
|
11461 (sourceRect.left() + (sourceRect.right() - sourceRect.left()) / 2) |
|
11462 :(direction == DirectionEast ? sourceRect.right() : sourceRect.left()); |
|
11463 const int sourceY = |
|
11464 (direction == DirectionEast || direction == DirectionWest) ? |
|
11465 (sourceRect.top() + (sourceRect.bottom() - sourceRect.top()) / 2) |
|
11466 :(direction == DirectionSouth ? sourceRect.bottom() : sourceRect.top()); |
|
11467 const QPoint sourcePoint(sourceX, sourceY); |
|
11468 const QPoint sourceCenter = sourceRect.center(); |
|
11469 const QWidget *sourceWindow = sourceWidget->window(); |
|
11470 |
|
11471 QWidget *targetWidget = 0; |
|
11472 int shortestDistance = INT_MAX; |
|
11473 foreach(QWidget *targetCandidate, QApplication::allWidgets()) { |
|
11474 |
|
11475 const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint())); |
|
11476 |
|
11477 // For focus proxies, the child widget handling the focus can have keypad navigation focus, |
|
11478 // but the owner of the proxy cannot. |
|
11479 // Additionally, empty widgets should be ignored. |
|
11480 if (targetCandidate->focusProxy() || targetCandidateRect.isEmpty()) |
|
11481 continue; |
|
11482 |
|
11483 // Only navigate to a target widget that... |
|
11484 if ( targetCandidate != sourceWidget |
|
11485 // ...takes the focus, |
|
11486 && targetCandidate->focusPolicy() & Qt::TabFocus |
|
11487 // ...is above if DirectionNorth, |
|
11488 && !(direction == DirectionNorth && targetCandidateRect.bottom() > sourceRect.top()) |
|
11489 // ...is on the right if DirectionEast, |
|
11490 && !(direction == DirectionEast && targetCandidateRect.left() < sourceRect.right()) |
|
11491 // ...is below if DirectionSouth, |
|
11492 && !(direction == DirectionSouth && targetCandidateRect.top() < sourceRect.bottom()) |
|
11493 // ...is on the left if DirectionWest, |
|
11494 && !(direction == DirectionWest && targetCandidateRect.right() > sourceRect.left()) |
|
11495 // ...is enabled, |
|
11496 && targetCandidate->isEnabled() |
|
11497 // ...is visible, |
|
11498 && targetCandidate->isVisible() |
|
11499 // ...is in the same window, |
|
11500 && targetCandidate->window() == sourceWindow) { |
|
11501 const int targetCandidateDistance = pointToRect(sourcePoint, targetCandidateRect); |
|
11502 if (targetCandidateDistance < shortestDistance) { |
|
11503 shortestDistance = targetCandidateDistance; |
|
11504 targetWidget = targetCandidate; |
|
11505 } |
|
11506 } |
|
11507 } |
|
11508 return targetWidget; |
|
11509 } |
|
11510 #endif |
|
11511 |
|
11512 /*! |
|
11513 \preliminary |
|
11514 \since 4.2 |
|
11515 \obsolete |
|
11516 |
|
11517 Sets the window surface to be the \a surface specified. |
|
11518 The QWidget takes will ownership of the \a surface. |
|
11519 widget itself is deleted. |
|
11520 */ |
|
11521 void QWidget::setWindowSurface(QWindowSurface *surface) |
|
11522 { |
|
11523 // ### createWinId() ?? |
|
11524 |
|
11525 #ifndef Q_BACKINGSTORE_SUBSURFACES |
|
11526 if (!isTopLevel()) |
|
11527 return; |
|
11528 #endif |
|
11529 |
|
11530 Q_D(QWidget); |
|
11531 |
|
11532 QTLWExtra *topData = d->topData(); |
|
11533 if (topData->windowSurface == surface) |
|
11534 return; |
|
11535 |
|
11536 QWindowSurface *oldSurface = topData->windowSurface; |
|
11537 delete topData->windowSurface; |
|
11538 topData->windowSurface = surface; |
|
11539 |
|
11540 QWidgetBackingStore *bs = d->maybeBackingStore(); |
|
11541 if (!bs) |
|
11542 return; |
|
11543 |
|
11544 if (isTopLevel()) { |
|
11545 if (bs->windowSurface != oldSurface && bs->windowSurface != surface) |
|
11546 delete bs->windowSurface; |
|
11547 bs->windowSurface = surface; |
|
11548 } |
|
11549 #ifdef Q_BACKINGSTORE_SUBSURFACES |
|
11550 else { |
|
11551 bs->subSurfaces.append(surface); |
|
11552 } |
|
11553 bs->subSurfaces.removeOne(oldSurface); |
|
11554 #endif |
|
11555 } |
|
11556 |
|
11557 /*! |
|
11558 \preliminary |
|
11559 \since 4.2 |
|
11560 |
|
11561 Returns the QWindowSurface this widget will be drawn into. |
|
11562 */ |
|
11563 QWindowSurface *QWidget::windowSurface() const |
|
11564 { |
|
11565 Q_D(const QWidget); |
|
11566 QTLWExtra *extra = d->maybeTopData(); |
|
11567 if (extra && extra->windowSurface) |
|
11568 return extra->windowSurface; |
|
11569 |
|
11570 QWidgetBackingStore *bs = d->maybeBackingStore(); |
|
11571 |
|
11572 #ifdef Q_BACKINGSTORE_SUBSURFACES |
|
11573 if (bs && bs->subSurfaces.isEmpty()) |
|
11574 return bs->windowSurface; |
|
11575 |
|
11576 if (!isTopLevel()) { |
|
11577 const QWidget *w = parentWidget(); |
|
11578 while (w) { |
|
11579 QTLWExtra *extra = w->d_func()->maybeTopData(); |
|
11580 if (extra && extra->windowSurface) |
|
11581 return extra->windowSurface; |
|
11582 if (w->isTopLevel()) |
|
11583 break; |
|
11584 w = w->parentWidget(); |
|
11585 } |
|
11586 } |
|
11587 #endif // Q_BACKINGSTORE_SUBSURFACES |
|
11588 |
|
11589 return bs ? bs->windowSurface : 0; |
|
11590 } |
|
11591 |
|
11592 void QWidgetPrivate::getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const |
|
11593 { |
|
11594 if (left) |
|
11595 *left = (int)leftLayoutItemMargin; |
|
11596 if (top) |
|
11597 *top = (int)topLayoutItemMargin; |
|
11598 if (right) |
|
11599 *right = (int)rightLayoutItemMargin; |
|
11600 if (bottom) |
|
11601 *bottom = (int)bottomLayoutItemMargin; |
|
11602 } |
|
11603 |
|
11604 void QWidgetPrivate::setLayoutItemMargins(int left, int top, int right, int bottom) |
|
11605 { |
|
11606 if (leftLayoutItemMargin == left |
|
11607 && topLayoutItemMargin == top |
|
11608 && rightLayoutItemMargin == right |
|
11609 && bottomLayoutItemMargin == bottom) |
|
11610 return; |
|
11611 |
|
11612 Q_Q(QWidget); |
|
11613 leftLayoutItemMargin = (signed char)left; |
|
11614 topLayoutItemMargin = (signed char)top; |
|
11615 rightLayoutItemMargin = (signed char)right; |
|
11616 bottomLayoutItemMargin = (signed char)bottom; |
|
11617 q->updateGeometry(); |
|
11618 } |
|
11619 |
|
11620 void QWidgetPrivate::setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt) |
|
11621 { |
|
11622 Q_Q(QWidget); |
|
11623 QStyleOption myOpt; |
|
11624 if (!opt) { |
|
11625 myOpt.initFrom(q); |
|
11626 myOpt.rect.setRect(0, 0, 32768, 32768); // arbitrary |
|
11627 opt = &myOpt; |
|
11628 } |
|
11629 |
|
11630 QRect liRect = q->style()->subElementRect(element, opt, q); |
|
11631 if (liRect.isValid()) { |
|
11632 leftLayoutItemMargin = (signed char)(opt->rect.left() - liRect.left()); |
|
11633 topLayoutItemMargin = (signed char)(opt->rect.top() - liRect.top()); |
|
11634 rightLayoutItemMargin = (signed char)(liRect.right() - opt->rect.right()); |
|
11635 bottomLayoutItemMargin = (signed char)(liRect.bottom() - opt->rect.bottom()); |
|
11636 } else { |
|
11637 leftLayoutItemMargin = 0; |
|
11638 topLayoutItemMargin = 0; |
|
11639 rightLayoutItemMargin = 0; |
|
11640 bottomLayoutItemMargin = 0; |
|
11641 } |
|
11642 } |
|
11643 // resets the Qt::WA_QuitOnClose attribute to the default value for transient widgets. |
|
11644 void QWidgetPrivate::adjustQuitOnCloseAttribute() |
|
11645 { |
|
11646 Q_Q(QWidget); |
|
11647 |
|
11648 if (!q->parentWidget()) { |
|
11649 Qt::WindowType type = q->windowType(); |
|
11650 if (type == Qt::Widget || type == Qt::SubWindow) |
|
11651 type = Qt::Window; |
|
11652 if (type != Qt::Widget && type != Qt::Window && type != Qt::Dialog) |
|
11653 q->setAttribute(Qt::WA_QuitOnClose, false); |
|
11654 } |
|
11655 } |
|
11656 |
|
11657 |
|
11658 |
|
11659 Q_GUI_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget) |
|
11660 { |
|
11661 return widget->data; |
|
11662 } |
|
11663 |
|
11664 Q_GUI_EXPORT QWidgetPrivate *qt_widget_private(QWidget *widget) |
|
11665 { |
|
11666 return widget->d_func(); |
|
11667 } |
|
11668 |
|
11669 |
|
11670 #ifndef QT_NO_GRAPHICSVIEW |
|
11671 /*! |
|
11672 \since 4.5 |
|
11673 |
|
11674 Returns the proxy widget for the corresponding embedded widget in a graphics |
|
11675 view; otherwise returns 0. |
|
11676 |
|
11677 \sa QGraphicsProxyWidget::createProxyForChildWidget(), |
|
11678 QGraphicsScene::addWidget() |
|
11679 */ |
|
11680 QGraphicsProxyWidget *QWidget::graphicsProxyWidget() const |
|
11681 { |
|
11682 Q_D(const QWidget); |
|
11683 if (d->extra) { |
|
11684 return d->extra->proxyWidget; |
|
11685 } |
|
11686 return 0; |
|
11687 } |
|
11688 #endif |
|
11689 |
|
11690 |
|
11691 /*! |
|
11692 \typedef QWidgetList |
|
11693 \relates QWidget |
|
11694 |
|
11695 Synonym for QList<QWidget *>. |
|
11696 */ |
|
11697 |
|
11698 /*! |
|
11699 Subscribes the widget to a given \a gesture with a \a context. |
|
11700 |
|
11701 \sa QGestureEvent |
|
11702 \since 4.6 |
|
11703 */ |
|
11704 void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureContext context) |
|
11705 { |
|
11706 Q_D(QWidget); |
|
11707 d->gestureContext.insert(gesture, context); |
|
11708 (void)QGestureManager::instance(); // create a gesture manager |
|
11709 } |
|
11710 |
|
11711 QT_END_NAMESPACE |
|
11712 |
|
11713 #include "moc_qwidget.cpp" |
|
11714 |
|
11715 /*! |
|
11716 \typedef WId |
|
11717 \relates QWidget |
|
11718 |
|
11719 Platform dependent window identifier. |
|
11720 */ |
|
11721 |
|
11722 /*! |
|
11723 \fn void QWidget::destroy(bool destroyWindow, bool destroySubWindows) |
|
11724 |
|
11725 Frees up window system resources. Destroys the widget window if \a |
|
11726 destroyWindow is true. |
|
11727 |
|
11728 destroy() calls itself recursively for all the child widgets, |
|
11729 passing \a destroySubWindows for the \a destroyWindow parameter. |
|
11730 To have more control over destruction of subwidgets, destroy |
|
11731 subwidgets selectively first. |
|
11732 |
|
11733 This function is usually called from the QWidget destructor. |
|
11734 */ |
|
11735 |
|
11736 /*! |
|
11737 \fn QPaintEngine *QWidget::paintEngine() const |
|
11738 |
|
11739 Returns the widget's paint engine. |
|
11740 |
|
11741 Note that this function should not be called explicitly by the |
|
11742 user, since it's meant for reimplementation purposes only. The |
|
11743 function is called by Qt internally, and the default |
|
11744 implementation may not always return a valid pointer. |
|
11745 */ |
|
11746 |
|
11747 /*! |
|
11748 \fn QPoint QWidget::mapToGlobal(const QPoint &pos) const |
|
11749 |
|
11750 Translates the widget coordinate \a pos to global screen |
|
11751 coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give |
|
11752 the global coordinates of the top-left pixel of the widget. |
|
11753 |
|
11754 \sa mapFromGlobal() mapTo() mapToParent() |
|
11755 */ |
|
11756 |
|
11757 /*! |
|
11758 \fn QPoint QWidget::mapFromGlobal(const QPoint &pos) const |
|
11759 |
|
11760 Translates the global screen coordinate \a pos to widget |
|
11761 coordinates. |
|
11762 |
|
11763 \sa mapToGlobal() mapFrom() mapFromParent() |
|
11764 */ |
|
11765 |
|
11766 /*! |
|
11767 \fn void QWidget::grabMouse() |
|
11768 |
|
11769 Grabs the mouse input. |
|
11770 |
|
11771 This widget receives all mouse events until releaseMouse() is |
|
11772 called; other widgets get no mouse events at all. Keyboard |
|
11773 events are not affected. Use grabKeyboard() if you want to grab |
|
11774 that. |
|
11775 |
|
11776 \warning Bugs in mouse-grabbing applications very often lock the |
|
11777 terminal. Use this function with extreme caution, and consider |
|
11778 using the \c -nograb command line option while debugging. |
|
11779 |
|
11780 It is almost never necessary to grab the mouse when using Qt, as |
|
11781 Qt grabs and releases it sensibly. In particular, Qt grabs the |
|
11782 mouse when a mouse button is pressed and keeps it until the last |
|
11783 button is released. |
|
11784 |
|
11785 Note that only visible widgets can grab mouse input. If |
|
11786 isVisible() returns false for a widget, that widget cannot call |
|
11787 grabMouse(). |
|
11788 |
|
11789 \sa releaseMouse() grabKeyboard() releaseKeyboard() grabKeyboard() |
|
11790 focusWidget() |
|
11791 */ |
|
11792 |
|
11793 /*! |
|
11794 \fn void QWidget::grabMouse(const QCursor &cursor) |
|
11795 \overload |
|
11796 |
|
11797 Grabs the mouse input and changes the cursor shape. |
|
11798 |
|
11799 The cursor will assume shape \a cursor (for as long as the mouse |
|
11800 focus is grabbed) and this widget will be the only one to receive |
|
11801 mouse events until releaseMouse() is called(). |
|
11802 |
|
11803 \warning Grabbing the mouse might lock the terminal. |
|
11804 |
|
11805 \sa releaseMouse(), grabKeyboard(), releaseKeyboard(), setCursor() |
|
11806 */ |
|
11807 |
|
11808 /*! |
|
11809 \fn void QWidget::releaseMouse() |
|
11810 |
|
11811 Releases the mouse grab. |
|
11812 |
|
11813 \sa grabMouse(), grabKeyboard(), releaseKeyboard() |
|
11814 */ |
|
11815 |
|
11816 /*! |
|
11817 \fn void QWidget::grabKeyboard() |
|
11818 |
|
11819 Grabs the keyboard input. |
|
11820 |
|
11821 This widget receives all keyboard events until releaseKeyboard() |
|
11822 is called; other widgets get no keyboard events at all. Mouse |
|
11823 events are not affected. Use grabMouse() if you want to grab that. |
|
11824 |
|
11825 The focus widget is not affected, except that it doesn't receive |
|
11826 any keyboard events. setFocus() moves the focus as usual, but the |
|
11827 new focus widget receives keyboard events only after |
|
11828 releaseKeyboard() is called. |
|
11829 |
|
11830 If a different widget is currently grabbing keyboard input, that |
|
11831 widget's grab is released first. |
|
11832 |
|
11833 \sa releaseKeyboard() grabMouse() releaseMouse() focusWidget() |
|
11834 */ |
|
11835 |
|
11836 /*! |
|
11837 \fn void QWidget::releaseKeyboard() |
|
11838 |
|
11839 Releases the keyboard grab. |
|
11840 |
|
11841 \sa grabKeyboard(), grabMouse(), releaseMouse() |
|
11842 */ |
|
11843 |
|
11844 /*! |
|
11845 \fn QWidget *QWidget::mouseGrabber() |
|
11846 |
|
11847 Returns the widget that is currently grabbing the mouse input. |
|
11848 |
|
11849 If no widget in this application is currently grabbing the mouse, |
|
11850 0 is returned. |
|
11851 |
|
11852 \sa grabMouse(), keyboardGrabber() |
|
11853 */ |
|
11854 |
|
11855 /*! |
|
11856 \fn QWidget *QWidget::keyboardGrabber() |
|
11857 |
|
11858 Returns the widget that is currently grabbing the keyboard input. |
|
11859 |
|
11860 If no widget in this application is currently grabbing the |
|
11861 keyboard, 0 is returned. |
|
11862 |
|
11863 \sa grabMouse(), mouseGrabber() |
|
11864 */ |
|
11865 |
|
11866 /*! |
|
11867 \fn void QWidget::activateWindow() |
|
11868 |
|
11869 Sets the top-level widget containing this widget to be the active |
|
11870 window. |
|
11871 |
|
11872 An active window is a visible top-level window that has the |
|
11873 keyboard input focus. |
|
11874 |
|
11875 This function performs the same operation as clicking the mouse on |
|
11876 the title bar of a top-level window. On X11, the result depends on |
|
11877 the Window Manager. If you want to ensure that the window is |
|
11878 stacked on top as well you should also call raise(). Note that the |
|
11879 window must be visible, otherwise activateWindow() has no effect. |
|
11880 |
|
11881 On Windows, if you are calling this when the application is not |
|
11882 currently the active one then it will not make it the active |
|
11883 window. It will change the color of the taskbar entry to indicate |
|
11884 that the window has changed in some way. This is because Microsoft |
|
11885 does not allow an application to interrupt what the user is currently |
|
11886 doing in another application. |
|
11887 |
|
11888 \sa isActiveWindow(), window(), show() |
|
11889 */ |
|
11890 |
|
11891 /*! |
|
11892 \fn int QWidget::metric(PaintDeviceMetric m) const |
|
11893 |
|
11894 Internal implementation of the virtual QPaintDevice::metric() |
|
11895 function. |
|
11896 |
|
11897 \a m is the metric to get. |
|
11898 */ |
|
11899 |
|
11900 /*! |
|
11901 \fn void QWidget::setMask(const QRegion ®ion) |
|
11902 \overload |
|
11903 |
|
11904 Causes only the parts of the widget which overlap \a region to be |
|
11905 visible. If the region includes pixels outside the rect() of the |
|
11906 widget, window system controls in that area may or may not be |
|
11907 visible, depending on the platform. |
|
11908 |
|
11909 Note that this effect can be slow if the region is particularly |
|
11910 complex. |
|
11911 |
|
11912 \sa windowOpacity |
|
11913 */ |
|
11914 void QWidget::setMask(const QRegion &newMask) |
|
11915 { |
|
11916 Q_D(QWidget); |
|
11917 |
|
11918 d->createExtra(); |
|
11919 if (newMask == d->extra->mask) |
|
11920 return; |
|
11921 |
|
11922 #ifndef QT_NO_BACKINGSTORE |
|
11923 const QRegion oldMask(d->extra->mask); |
|
11924 #endif |
|
11925 |
|
11926 d->extra->mask = newMask; |
|
11927 d->extra->hasMask = !newMask.isEmpty(); |
|
11928 |
|
11929 #ifndef QT_MAC_USE_COCOA |
|
11930 if (!testAttribute(Qt::WA_WState_Created)) |
|
11931 return; |
|
11932 #endif |
|
11933 |
|
11934 d->setMask_sys(newMask); |
|
11935 |
|
11936 #ifndef QT_NO_BACKINGSTORE |
|
11937 if (!isVisible()) |
|
11938 return; |
|
11939 |
|
11940 if (!d->extra->hasMask) { |
|
11941 // Mask was cleared; update newly exposed area. |
|
11942 QRegion expose(rect()); |
|
11943 expose -= oldMask; |
|
11944 if (!expose.isEmpty()) { |
|
11945 d->setDirtyOpaqueRegion(); |
|
11946 update(expose); |
|
11947 } |
|
11948 return; |
|
11949 } |
|
11950 |
|
11951 if (!isWindow()) { |
|
11952 // Update newly exposed area on the parent widget. |
|
11953 QRegion parentExpose(rect()); |
|
11954 parentExpose -= newMask; |
|
11955 if (!parentExpose.isEmpty()) { |
|
11956 d->setDirtyOpaqueRegion(); |
|
11957 parentExpose.translate(data->crect.topLeft()); |
|
11958 parentWidget()->update(parentExpose); |
|
11959 } |
|
11960 |
|
11961 // Update newly exposed area on this widget |
|
11962 if (!oldMask.isEmpty()) |
|
11963 update(newMask - oldMask); |
|
11964 } |
|
11965 #endif |
|
11966 } |
|
11967 |
|
11968 /*! |
|
11969 \fn void QWidget::setMask(const QBitmap &bitmap) |
|
11970 |
|
11971 Causes only the pixels of the widget for which \a bitmap has a |
|
11972 corresponding 1 bit to be visible. If the region includes pixels |
|
11973 outside the rect() of the widget, window system controls in that |
|
11974 area may or may not be visible, depending on the platform. |
|
11975 |
|
11976 Note that this effect can be slow if the region is particularly |
|
11977 complex. |
|
11978 |
|
11979 The following code shows how an image with an alpha channel can be |
|
11980 used to generate a mask for a widget: |
|
11981 |
|
11982 \snippet doc/src/snippets/widget-mask/main.cpp 0 |
|
11983 |
|
11984 The label shown by this code is masked using the image it contains, |
|
11985 giving the appearance that an irregularly-shaped image is being drawn |
|
11986 directly onto the screen. |
|
11987 |
|
11988 Masked widgets receive mouse events only on their visible |
|
11989 portions. |
|
11990 |
|
11991 \sa clearMask(), windowOpacity(), {Shaped Clock Example} |
|
11992 */ |
|
11993 void QWidget::setMask(const QBitmap &bitmap) |
|
11994 { |
|
11995 setMask(QRegion(bitmap)); |
|
11996 } |
|
11997 |
|
11998 /*! |
|
11999 \fn void QWidget::clearMask() |
|
12000 |
|
12001 Removes any mask set by setMask(). |
|
12002 |
|
12003 \sa setMask() |
|
12004 */ |
|
12005 void QWidget::clearMask() |
|
12006 { |
|
12007 setMask(QRegion()); |
|
12008 } |
|
12009 |
|
12010 /*! \fn const QX11Info &QWidget::x11Info() const |
|
12011 Returns information about the configuration of the X display used to display |
|
12012 the widget. |
|
12013 |
|
12014 \warning This function is only available on X11. |
|
12015 */ |
|
12016 |
|
12017 /*! \fn Qt::HANDLE QWidget::x11PictureHandle() const |
|
12018 Returns the X11 Picture handle of the widget for XRender |
|
12019 support. Use of this function is not portable. This function will |
|
12020 return 0 if XRender support is not compiled into Qt, if the |
|
12021 XRender extension is not supported on the X11 display, or if the |
|
12022 handle could not be created. |
|
12023 */ |
|
12024 |
|
12025 #ifdef Q_OS_SYMBIAN |
|
12026 void QWidgetPrivate::_q_delayedDestroy(WId winId) |
|
12027 { |
|
12028 delete winId; |
|
12029 } |
|
12030 #endif |