kernel/qwidget.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/****************************************************************************-
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/****************************************************************************
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
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#include "qstylehints.h" -
61#ifndef QT_NO_ACCESSIBILITY -
62# include "qaccessible.h" -
63#endif -
64#ifdef Q_WS_MAC -
65# include "qt_mac_p.h" -
66# include "qt_cocoa_helpers_mac_p.h" -
67# include "qmainwindow.h" -
68# include "qtoolbar.h" -
69# include <private/qmainwindowlayout_p.h> -
70#endif -
71#include <qpa/qplatformwindow.h> -
72#include "private/qwidgetwindow_qpa_p.h" -
73#include "qpainter.h" -
74#include "qtooltip.h" -
75#include "qwhatsthis.h" -
76#include "qdebug.h" -
77#include "private/qstylesheetstyle_p.h" -
78#include "private/qstyle_p.h" -
79#include "qfileinfo.h" -
80#include <QtGui/qinputmethod.h> -
81 -
82#include <private/qgraphicseffect_p.h> -
83#include <qbackingstore.h> -
84#include <private/qwidgetbackingstore_p.h> -
85#ifdef Q_WS_MAC -
86# include <private/qpaintengine_mac_p.h> -
87#endif -
88#include <private/qpaintengine_raster_p.h> -
89 -
90#include "qwidget_p.h" -
91#include <QtGui/private/qwindow_p.h> -
92#include "qaction_p.h" -
93#include "qlayout_p.h" -
94#include "QtWidgets/qgraphicsproxywidget.h" -
95#include "QtWidgets/qgraphicsscene.h" -
96#include "private/qgraphicsproxywidget_p.h" -
97#include "QtWidgets/qabstractscrollarea.h" -
98#include "private/qabstractscrollarea_p.h" -
99#include "private/qevent_p.h" -
100 -
101#include "private/qgesturemanager_p.h" -
102 -
103#ifdef QT_KEYPAD_NAVIGATION -
104#include "qtabwidget.h" // Needed in inTabWidget() -
105#endif // QT_KEYPAD_NAVIGATION -
106 -
107 -
108// widget/widget data creation count -
109//#define QWIDGET_EXTRA_DEBUG -
110//#define ALIEN_DEBUG -
111 -
112QT_BEGIN_NAMESPACE -
113 -
114static bool qt_enable_backingstore = true; -
115#ifdef Q_WS_X11 -
116// for compatibility with Qt 4.0 -
117Q_WIDGETS_EXPORT void qt_x11_set_global_double_buffer(bool enable) -
118{ -
119 qt_enable_backingstore = enable; -
120} -
121#endif -
122 -
123#ifdef Q_WS_MAC -
124bool qt_mac_clearDirtyOnWidgetInsideDrawWidget = false; -
125#endif -
126 -
127static inline bool qRectIntersects(const QRect &r1, const QRect &r2) -
128{ -
129 return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right()) && -
130 qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom())); -
131} -
132 -
133static inline bool hasBackingStoreSupport() -
134{ -
135 return true; -
136} -
137 -
138#ifdef Q_WS_MAC -
139# define QT_NO_PAINT_DEBUG -
140#endif -
141 -
142extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp -
143extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp -
144 -
145/*! -
146 \internal -
147 \class QWidgetBackingStoreTracker -
148 \brief Class which allows tracking of which widgets are using a given backing store -
149 -
150 QWidgetBackingStoreTracker is a thin wrapper around a QWidgetBackingStore pointer, -
151 which maintains a list of the QWidgets which are currently using the backing -
152 store. This list is modified via the registerWidget and unregisterWidget functions. -
153 */ -
154 -
155QWidgetBackingStoreTracker::QWidgetBackingStoreTracker() -
156 : m_ptr(0) -
157{ -
158 -
159} -
160 -
161QWidgetBackingStoreTracker::~QWidgetBackingStoreTracker() -
162{ -
163 delete m_ptr; -
164} -
165 -
166/*! -
167 \internal -
168 Destroy the contained QWidgetBackingStore, if not null, and clear the list of -
169 widgets using the backing store, then create a new QWidgetBackingStore, providing -
170 the QWidget. -
171 */ -
172void QWidgetBackingStoreTracker::create(QWidget *widget) -
173{ -
174 destroy(); -
175 m_ptr = new QWidgetBackingStore(widget); -
176} -
177 -
178/*! -
179 \internal -
180 Destroy the contained QWidgetBackingStore, if not null, and clear the list of -
181 widgets using the backing store. -
182 */ -
183void QWidgetBackingStoreTracker::destroy() -
184{ -
185 delete m_ptr; -
186 m_ptr = 0; -
187 m_widgets.clear(); -
188} -
189 -
190/*! -
191 \internal -
192 Add the widget to the list of widgets currently using the backing store. -
193 If the widget was already in the list, this function is a no-op. -
194 */ -
195void QWidgetBackingStoreTracker::registerWidget(QWidget *w) -
196{ -
197 Q_ASSERT(m_ptr); -
198 Q_ASSERT(w->internalWinId()); -
199 Q_ASSERT(qt_widget_private(w)->maybeBackingStore() == m_ptr); -
200 m_widgets.insert(w); -
201} -
202 -
203/*! -
204 \internal -
205 Remove the widget from the list of widgets currently using the backing store. -
206 If the widget was in the list, and removing it causes the list to be empty, -
207 the backing store is deleted. -
208 If the widget was not in the list, this function is a no-op. -
209 */ -
210void QWidgetBackingStoreTracker::unregisterWidget(QWidget *w) -
211{ -
212 if (m_widgets.remove(w) && m_widgets.isEmpty()) { -
213 delete m_ptr; -
214 m_ptr = 0; -
215 } -
216} -
217 -
218/*! -
219 \internal -
220 Recursively remove widget and all of its descendents. -
221 */ -
222void QWidgetBackingStoreTracker::unregisterWidgetSubtree(QWidget *widget) -
223{ -
224 unregisterWidget(widget); -
225 foreach (QObject *child, widget->children()) -
226 if (QWidget *childWidget = qobject_cast<QWidget *>(child)) -
227 unregisterWidgetSubtree(childWidget); -
228} -
229 -
230QWidgetPrivate::QWidgetPrivate(int version) -
231 : QObjectPrivate(version) -
232 , extra(0) -
233 , focus_next(0) -
234 , focus_prev(0) -
235 , focus_child(0) -
236 , layout(0) -
237 , needsFlush(0) -
238 , redirectDev(0) -
239 , widgetItem(0) -
240 , extraPaintEngine(0) -
241 , polished(0) -
242 , graphicsEffect(0) -
243#if !defined(QT_NO_IM) -
244 , imHints(Qt::ImhNone) -
245#endif -
246 , inheritedFontResolveMask(0) -
247 , inheritedPaletteResolveMask(0) -
248 , leftmargin(0) -
249 , topmargin(0) -
250 , rightmargin(0) -
251 , bottommargin(0) -
252 , leftLayoutItemMargin(0) -
253 , topLayoutItemMargin(0) -
254 , rightLayoutItemMargin(0) -
255 , bottomLayoutItemMargin(0) -
256 , hd(0) -
257 , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred) -
258 , fg_role(QPalette::NoRole) -
259 , bg_role(QPalette::NoRole) -
260 , dirtyOpaqueChildren(1) -
261 , isOpaque(0) -
262 , inDirtyList(0) -
263 , isScrolled(0) -
264 , isMoved(0) -
265 , usesDoubleBufferedGLContext(0) -
266#ifndef QT_NO_IM -
267 , inheritsInputMethodHints(0) -
268#endif -
269#if defined(Q_OS_WIN) -
270 , noPaintOnScreen(0) -
271#endif -
272#if defined(Q_WS_X11) -
273 , picture(0) -
274#elif defined(Q_WS_WIN) -
275 #ifndef QT_NO_GESTURES -
276 , nativeGesturePanEnabled(0) -
277 #endif -
278#elif defined(Q_WS_MAC) -
279 , needWindowChange(0) -
280 , window_event(0) -
281 , qd_hd(0) -
282#endif -
283{ -
284 if (!qApp) { -
285 qFatal("QWidget: Must construct a QApplication before a QPaintDevice"); -
286 return; -
287 } -
288 -
289 if (version != QObjectPrivateVersion) -
290 qFatal("Cannot mix incompatible Qt libraries"); -
291 -
292 isWidget = true; -
293 memset(high_attributes, 0, sizeof(high_attributes)); -
294#ifdef Q_WS_MAC -
295 drawRectOriginalAdded = false; -
296 originalDrawMethod = true; -
297 changeMethods = false; -
298 isInUnifiedToolbar = false; -
299 unifiedSurface = 0; -
300 toolbar_ancestor = 0; -
301 flushRequested = false; -
302 touchEventsEnabled = false; -
303#endif // Q_WS_MAC -
304#ifdef QWIDGET_EXTRA_DEBUG -
305 static int count = 0; -
306 qDebug() << "widgets" << ++count; -
307#endif -
308} -
309 -
310 -
311QWidgetPrivate::~QWidgetPrivate() -
312{ -
313 if (widgetItem) -
314 widgetItem->wid = 0; -
315 -
316 if (extra) -
317 deleteExtra(); -
318 -
319#ifndef QT_NO_GRAPHICSEFFECT -
320 delete graphicsEffect; -
321#endif //QT_NO_GRAPHICSEFFECT -
322} -
323 -
324/*! -
325 \internal -
326*/ -
327void QWidgetPrivate::scrollChildren(int dx, int dy) -
328{ -
329 Q_Q(QWidget); -
330 if (q->children().size() > 0) { // scroll children -
331 QPoint pd(dx, dy); -
332 QObjectList childObjects = q->children(); -
333 for (int i = 0; i < childObjects.size(); ++i) { // move all children -
334 QWidget *w = qobject_cast<QWidget*>(childObjects.at(i)); -
335 if (w && !w->isWindow()) { -
336 QPoint oldp = w->pos(); -
337 QRect r(w->pos() + pd, w->size()); -
338 w->data->crect = r; -
339 if (w->testAttribute(Qt::WA_WState_Created)) -
340 w->d_func()->setWSGeometry(); -
341 w->d_func()->setDirtyOpaqueRegion(); -
342 QMoveEvent e(r.topLeft(), oldp); -
343 QApplication::sendEvent(w, &e); -
344 } -
345 } -
346 } -
347} -
348 -
349void QWidgetPrivate::updateWidgetTransform() -
350{ -
351 Q_Q(QWidget); -
352 if (q == qGuiApp->focusObject()) { -
353 QTransform t; -
354 QPoint p = q->mapTo(q->topLevelWidget(), QPoint(0,0)); -
355 t.translate(p.x(), p.y()); -
356 qApp->inputMethod()->setInputItemTransform(t); -
357 } -
358} -
359 -
360#ifdef QT_KEYPAD_NAVIGATION -
361QPointer<QWidget> QWidgetPrivate::editingWidget; -
362 -
363/*! -
364 Returns true if this widget currently has edit focus; otherwise false. -
365 -
366 This feature is only available in Qt for Embedded Linux. -
367 -
368 \sa setEditFocus(), QApplication::keypadNavigationEnabled() -
369*/ -
370bool QWidget::hasEditFocus() const -
371{ -
372 const QWidget* w = this; -
373 while (w->d_func()->extra && w->d_func()->extra->focus_proxy) -
374 w = w->d_func()->extra->focus_proxy; -
375 return QWidgetPrivate::editingWidget == w; -
376} -
377 -
378/*! -
379 \fn void QWidget::setEditFocus(bool enable) -
380 -
381 If \a enable is true, make this widget have edit focus, in which -
382 case Qt::Key_Up and Qt::Key_Down will be delivered to the widget -
383 normally; otherwise, Qt::Key_Up and Qt::Key_Down are used to -
384 change focus. -
385 -
386 This feature is only available in Qt for Embedded Linux. -
387 -
388 \sa hasEditFocus(), QApplication::keypadNavigationEnabled() -
389*/ -
390void QWidget::setEditFocus(bool on) -
391{ -
392 QWidget *f = this; -
393 while (f->d_func()->extra && f->d_func()->extra->focus_proxy) -
394 f = f->d_func()->extra->focus_proxy; -
395 -
396 if (QWidgetPrivate::editingWidget && QWidgetPrivate::editingWidget != f) -
397 QWidgetPrivate::editingWidget->setEditFocus(false); -
398 -
399 if (on && !f->hasFocus()) -
400 f->setFocus(); -
401 -
402 if ((!on && !QWidgetPrivate::editingWidget) -
403 || (on && QWidgetPrivate::editingWidget == f)) { -
404 return; -
405 } -
406 -
407 if (!on && QWidgetPrivate::editingWidget == f) { -
408 QWidgetPrivate::editingWidget = 0; -
409 QEvent event(QEvent::LeaveEditFocus); -
410 QApplication::sendEvent(f, &event); -
411 QApplication::sendEvent(f->style(), &event); -
412 } else if (on) { -
413 QWidgetPrivate::editingWidget = f; -
414 QEvent event(QEvent::EnterEditFocus); -
415 QApplication::sendEvent(f, &event); -
416 QApplication::sendEvent(f->style(), &event); -
417 } -
418} -
419#endif -
420 -
421/*! -
422 \property QWidget::autoFillBackground -
423 \brief whether the widget background is filled automatically -
424 \since 4.1 -
425 -
426 If enabled, this property will cause Qt to fill the background of the -
427 widget before invoking the paint event. The color used is defined by the -
428 QPalette::Window color role from the widget's \l{QPalette}{palette}. -
429 -
430 In addition, Windows are always filled with QPalette::Window, unless the -
431 WA_OpaquePaintEvent or WA_NoSystemBackground attributes are set. -
432 -
433 This property cannot be turned off (i.e., set to false) if a widget's -
434 parent has a static gradient for its background. -
435 -
436 \warning Use this property with caution in conjunction with -
437 \l{Qt Style Sheets}. When a widget has a style sheet with a valid -
438 background or a border-image, this property is automatically disabled. -
439 -
440 By default, this property is false. -
441 -
442 \sa Qt::WA_OpaquePaintEvent, Qt::WA_NoSystemBackground, -
443 {QWidget#Transparency and Double Buffering}{Transparency and Double Buffering} -
444*/ -
445bool QWidget::autoFillBackground() const -
446{ -
447 Q_D(const QWidget); -
448 return d->extra && d->extra->autoFillBackground; -
449} -
450 -
451void QWidget::setAutoFillBackground(bool enabled) -
452{ -
453 Q_D(QWidget); -
454 if (!d->extra) -
455 d->createExtra(); -
456 if (d->extra->autoFillBackground == enabled) -
457 return; -
458 -
459 d->extra->autoFillBackground = enabled; -
460 d->updateIsOpaque(); -
461 update(); -
462 d->updateIsOpaque(); -
463} -
464 -
465/*! -
466 \class QWidget -
467 \brief The QWidget class is the base class of all user interface objects. -
468 -
469 \ingroup basicwidgets -
470 \inmodule QtWidgets -
471 -
472 The widget is the atom of the user interface: it receives mouse, keyboard -
473 and other events from the window system, and paints a representation of -
474 itself on the screen. Every widget is rectangular, and they are sorted in a -
475 Z-order. A widget is clipped by its parent and by the widgets in front of -
476 it. -
477 -
478 A widget that is not embedded in a parent widget is called a window. -
479 Usually, windows have a frame and a title bar, although it is also possible -
480 to create windows without such decoration using suitable -
481 \l{Qt::WindowFlags}{window flags}). In Qt, QMainWindow and the various -
482 subclasses of QDialog are the most common window types. -
483 -
484 Every widget's constructor accepts one or two standard arguments: -
485 -
486 \list 1 -
487 \li \c{QWidget *parent = 0} is the parent of the new widget. If it is 0 -
488 (the default), the new widget will be a window. If not, it will be -
489 a child of \e parent, and be constrained by \e parent's geometry -
490 (unless you specify Qt::Window as window flag). -
491 \li \c{Qt::WindowFlags f = 0} (where available) sets the window flags; -
492 the default is suitable for almost all widgets, but to get, for -
493 example, a window without a window system frame, you must use -
494 special flags. -
495 \endlist -
496 -
497 QWidget has many member functions, but some of them have little direct -
498 functionality; for example, QWidget has a font property, but never uses -
499 this itself. There are many subclasses which provide real functionality, -
500 such as QLabel, QPushButton, QListWidget, and QTabWidget. -
501 -
502 -
503 \section1 Top-Level and Child Widgets -
504 -
505 A widget without a parent widget is always an independent window (top-level -
506 widget). For these widgets, setWindowTitle() and setWindowIcon() set the -
507 title bar and icon respectively. -
508 -
509 Non-window widgets are child widgets, displayed within their parent -
510 widgets. Most widgets in Qt are mainly useful as child widgets. For -
511 example, it is possible to display a button as a top-level window, but most -
512 people prefer to put their buttons inside other widgets, such as QDialog. -
513 -
514 \image parent-child-widgets.png A parent widget containing various child widgets. -
515 -
516 The diagram above shows a QGroupBox widget being used to hold various child -
517 widgets in a layout provided by QGridLayout. The QLabel child widgets have -
518 been outlined to indicate their full sizes. -
519 -
520 If you want to use a QWidget to hold child widgets you will usually want to -
521 add a layout to the parent QWidget. See \l{Layout Management} for more -
522 information. -
523 -
524 -
525 \section1 Composite Widgets -
526 -
527 When a widget is used as a container to group a number of child widgets, it -
528 is known as a composite widget. These can be created by constructing a -
529 widget with the required visual properties - a QFrame, for example - and -
530 adding child widgets to it, usually managed by a layout. The above diagram -
531 shows such a composite widget that was created using Qt Designer. -
532 -
533 Composite widgets can also be created by subclassing a standard widget, -
534 such as QWidget or QFrame, and adding the necessary layout and child -
535 widgets in the constructor of the subclass. Many of the \l{Qt Examples} -
536 {examples provided with Qt} use this approach, and it is also covered in -
537 the Qt \l{Tutorials}. -
538 -
539 -
540 \section1 Custom Widgets and Painting -
541 -
542 Since QWidget is a subclass of QPaintDevice, subclasses can be used to -
543 display custom content that is composed using a series of painting -
544 operations with an instance of the QPainter class. This approach contrasts -
545 with the canvas-style approach used by the \l{Graphics View} -
546 {Graphics View Framework} where items are added to a scene by the -
547 application and are rendered by the framework itself. -
548 -
549 Each widget performs all painting operations from within its paintEvent() -
550 function. This is called whenever the widget needs to be redrawn, either -
551 as a result of some external change or when requested by the application. -
552 -
553 The \l{widgets/analogclock}{Analog Clock example} shows how a simple widget -
554 can handle paint events. -
555 -
556 -
557 \section1 Size Hints and Size Policies -
558 -
559 When implementing a new widget, it is almost always useful to reimplement -
560 sizeHint() to provide a reasonable default size for the widget and to set -
561 the correct size policy with setSizePolicy(). -
562 -
563 By default, composite widgets which do not provide a size hint will be -
564 sized according to the space requirements of their child widgets. -
565 -
566 The size policy lets you supply good default behavior for the layout -
567 management system, so that other widgets can contain and manage yours -
568 easily. The default size policy indicates that the size hint represents -
569 the preferred size of the widget, and this is often good enough for many -
570 widgets. -
571 -
572 \note The size of top-level widgets are constrained to 2/3 of the desktop's -
573 height and width. You can resize() the widget manually if these bounds are -
574 inadequate. -
575 -
576 -
577 \section1 Events -
578 -
579 Widgets respond to events that are typically caused by user actions. Qt -
580 delivers events to widgets by calling specific event handler functions with -
581 instances of QEvent subclasses containing information about each event. -
582 -
583 If your widget only contains child widgets, you probably do not need to -
584 implement any event handlers. If you want to detect a mouse click in a -
585 child widget call the child's underMouse() function inside the widget's -
586 mousePressEvent(). -
587 -
588 The \l{widgets/scribble}{Scribble example} implements a wider set of -
589 events to handle mouse movement, button presses, and window resizing. -
590 -
591 You will need to supply the behavior and content for your own widgets, but -
592 here is a brief overview of the events that are relevant to QWidget, -
593 starting with the most common ones: -
594 -
595 \list -
596 \li paintEvent() is called whenever the widget needs to be repainted. -
597 Every widget displaying custom content must implement it. Painting -
598 using a QPainter can only take place in a paintEvent() or a -
599 function called by a paintEvent(). -
600 \li resizeEvent() is called when the widget has been resized. -
601 \li mousePressEvent() is called when a mouse button is pressed while -
602 the mouse cursor is inside the widget, or when the widget has -
603 grabbed the mouse using grabMouse(). Pressing the mouse without -
604 releasing it is effectively the same as calling grabMouse(). -
605 \li mouseReleaseEvent() is called when a mouse button is released. A -
606 widget receives mouse release events when it has received the -
607 corresponding mouse press event. This means that if the user -
608 presses the mouse inside \e your widget, then drags the mouse -
609 somewhere else before releasing the mouse button, \e your widget -
610 receives the release event. There is one exception: if a popup menu -
611 appears while the mouse button is held down, this popup immediately -
612 steals the mouse events. -
613 \li mouseDoubleClickEvent() is called when the user double-clicks in -
614 the widget. If the user double-clicks, the widget receives a mouse -
615 press event, a mouse release event, (a mouse click event,) a second -
616 mouse press, this event and finally a second mouse release event. -
617 (Some mouse move events may also be -
618 received if the mouse is not held steady during this operation.) It -
619 is \e{not possible} to distinguish a click from a double-click -
620 until the second click arrives. (This is one reason why most GUI -
621 books recommend that double-clicks be an extension of -
622 single-clicks, rather than trigger a different action.) -
623 \endlist -
624 -
625 Widgets that accept keyboard input need to reimplement a few more event -
626 handlers: -
627 -
628 \list -
629 \li keyPressEvent() is called whenever a key is pressed, and again when -
630 a key has been held down long enough for it to auto-repeat. The -
631 \uicontrol Tab and \uicontrol Shift+Tab keys are only passed to the widget if -
632 they are not used by the focus-change mechanisms. To force those -
633 keys to be processed by your widget, you must reimplement -
634 QWidget::event(). -
635 \li focusInEvent() is called when the widget gains keyboard focus -
636 (assuming you have called setFocusPolicy()). Well-behaved widgets -
637 indicate that they own the keyboard focus in a clear but discreet -
638 way. -
639 \li focusOutEvent() is called when the widget loses keyboard focus. -
640 \endlist -
641 -
642 You may be required to also reimplement some of the less common event -
643 handlers: -
644 -
645 \list -
646 \li mouseMoveEvent() is called whenever the mouse moves while a mouse -
647 button is held down. This can be useful during drag and drop -
648 operations. If you call \l{setMouseTracking()}{setMouseTracking}(true), -
649 you get mouse move events even when no buttons are held down. -
650 (See also the \l{Drag and Drop} guide.) -
651 \li keyReleaseEvent() is called whenever a key is released and while it -
652 is held down (if the key is auto-repeating). In that case, the -
653 widget will receive a pair of key release and key press event for -
654 every repeat. The \uicontrol Tab and \uicontrol Shift+Tab keys are only passed -
655 to the widget if they are not used by the focus-change mechanisms. -
656 To force those keys to be processed by your widget, you must -
657 reimplement QWidget::event(). -
658 \li wheelEvent() is called whenever the user turns the mouse wheel -
659 while the widget has the focus. -
660 \li enterEvent() is called when the mouse enters the widget's screen -
661 space. (This excludes screen space owned by any of the widget's -
662 children.) -
663 \li leaveEvent() is called when the mouse leaves the widget's screen -
664 space. If the mouse enters a child widget it will not cause a -
665 leaveEvent(). -
666 \li moveEvent() is called when the widget has been moved relative to -
667 its parent. -
668 \li closeEvent() is called when the user closes the widget (or when -
669 close() is called). -
670 \endlist -
671 -
672 There are also some rather obscure events described in the documentation -
673 for QEvent::Type. To handle these events, you need to reimplement event() -
674 directly. -
675 -
676 The default implementation of event() handles \uicontrol Tab and \uicontrol Shift+Tab -
677 (to move the keyboard focus), and passes on most of the other events to -
678 one of the more specialized handlers above. -
679 -
680 Events and the mechanism used to deliver them are covered in -
681 \l{The Event System}. -
682 -
683 \section1 Groups of Functions and Properties -
684 -
685 \table -
686 \header \li Context \li Functions and Properties -
687 -
688 \row \li Window functions \li -
689 show(), -
690 hide(), -
691 raise(), -
692 lower(), -
693 close(). -
694 -
695 \row \li Top-level windows \li -
696 \l windowModified, \l windowTitle, \l windowIcon, \l windowIconText, -
697 \l isActiveWindow, activateWindow(), \l minimized, showMinimized(), -
698 \l maximized, showMaximized(), \l fullScreen, showFullScreen(), -
699 showNormal(). -
700 -
701 \row \li Window contents \li -
702 update(), -
703 repaint(), -
704 scroll(). -
705 -
706 \row \li Geometry \li -
707 \l pos, x(), y(), \l rect, \l size, width(), height(), move(), resize(), -
708 \l sizePolicy, sizeHint(), minimumSizeHint(), -
709 updateGeometry(), layout(), -
710 \l frameGeometry, \l geometry, \l childrenRect, \l childrenRegion, -
711 adjustSize(), -
712 mapFromGlobal(), mapToGlobal(), -
713 mapFromParent(), mapToParent(), -
714 \l maximumSize, \l minimumSize, \l sizeIncrement, -
715 \l baseSize, setFixedSize() -
716 -
717 \row \li Mode \li -
718 \l visible, isVisibleTo(), -
719 \l enabled, isEnabledTo(), -
720 \l modal, -
721 isWindow(), -
722 \l mouseTracking, -
723 \l updatesEnabled, -
724 visibleRegion(). -
725 -
726 \row \li Look and feel \li -
727 style(), -
728 setStyle(), -
729 \l styleSheet, -
730 \l cursor, -
731 \l font, -
732 \l palette, -
733 backgroundRole(), setBackgroundRole(), -
734 fontInfo(), fontMetrics(). -
735 -
736 \row \li Keyboard focus functions \li -
737 \l focus, \l focusPolicy, -
738 setFocus(), clearFocus(), setTabOrder(), setFocusProxy(), -
739 focusNextChild(), focusPreviousChild(). -
740 -
741 \row \li Mouse and keyboard grabbing \li -
742 grabMouse(), releaseMouse(), -
743 grabKeyboard(), releaseKeyboard(), -
744 mouseGrabber(), keyboardGrabber(). -
745 -
746 \row \li Event handlers \li -
747 event(), -
748 mousePressEvent(), -
749 mouseReleaseEvent(), -
750 mouseDoubleClickEvent(), -
751 mouseMoveEvent(), -
752 keyPressEvent(), -
753 keyReleaseEvent(), -
754 focusInEvent(), -
755 focusOutEvent(), -
756 wheelEvent(), -
757 enterEvent(), -
758 leaveEvent(), -
759 paintEvent(), -
760 moveEvent(), -
761 resizeEvent(), -
762 closeEvent(), -
763 dragEnterEvent(), -
764 dragMoveEvent(), -
765 dragLeaveEvent(), -
766 dropEvent(), -
767 childEvent(), -
768 showEvent(), -
769 hideEvent(), -
770 customEvent(). -
771 changeEvent(), -
772 -
773 \row \li System functions \li -
774 parentWidget(), window(), setParent(), winId(), -
775 find(), metric(). -
776 -
777 \row \li Interactive help \li -
778 setToolTip(), setWhatsThis() -
779 -
780 \endtable -
781 -
782 -
783 \section1 Widget Style Sheets -
784 -
785 In addition to the standard widget styles for each platform, widgets can -
786 also be styled according to rules specified in a \l{styleSheet} -
787 {style sheet}. This feature enables you to customize the appearance of -
788 specific widgets to provide visual cues to users about their purpose. For -
789 example, a button could be styled in a particular way to indicate that it -
790 performs a destructive action. -
791 -
792 The use of widget style sheets is described in more detail in the -
793 \l{Qt Style Sheets} document. -
794 -
795 -
796 \section1 Transparency and Double Buffering -
797 -
798 Since Qt 4.0, QWidget automatically double-buffers its painting, so there -
799 is no need to write double-buffering code in paintEvent() to avoid -
800 flicker. -
801 -
802 Since Qt 4.1, the Qt::WA_ContentsPropagated widget attribute has been -
803 deprecated. Instead, the contents of parent widgets are propagated by -
804 default to each of their children as long as Qt::WA_PaintOnScreen is not -
805 set. Custom widgets can be written to take advantage of this feature by -
806 updating irregular regions (to create non-rectangular child widgets), or -
807 painting with colors that have less than full alpha component. The -
808 following diagram shows how attributes and properties of a custom widget -
809 can be fine-tuned to achieve different effects. -
810 -
811 \image propagation-custom.png -
812 -
813 In the above diagram, a semi-transparent rectangular child widget with an -
814 area removed is constructed and added to a parent widget (a QLabel showing -
815 a pixmap). Then, different properties and widget attributes are set to -
816 achieve different effects: -
817 -
818 \list -
819 \li The left widget has no additional properties or widget attributes -
820 set. This default state suits most custom widgets using -
821 transparency, are irregularly-shaped, or do not paint over their -
822 entire area with an opaque brush. -
823 \li The center widget has the \l autoFillBackground property set. This -
824 property is used with custom widgets that rely on the widget to -
825 supply a default background, and do not paint over their entire -
826 area with an opaque brush. -
827 \li The right widget has the Qt::WA_OpaquePaintEvent widget attribute -
828 set. This indicates that the widget will paint over its entire area -
829 with opaque colors. The widget's area will initially be -
830 \e{uninitialized}, represented in the diagram with a red diagonal -
831 grid pattern that shines through the overpainted area. The -
832 Qt::WA_OpaquePaintArea attribute is useful for widgets that need to -
833 paint their own specialized contents quickly and do not need a -
834 default filled background. -
835 \endlist -
836 -
837 To rapidly update custom widgets with simple background colors, such as -
838 real-time plotting or graphing widgets, it is better to define a suitable -
839 background color (using setBackgroundRole() with the -
840 QPalette::Window role), set the \l autoFillBackground property, and only -
841 implement the necessary drawing functionality in the widget's paintEvent(). -
842 -
843 To rapidly update custom widgets that constantly paint over their entire -
844 areas with opaque content, e.g., video streaming widgets, it is better to -
845 set the widget's Qt::WA_OpaquePaintEvent, avoiding any unnecessary overhead -
846 associated with repainting the widget's background. -
847 -
848 If a widget has both the Qt::WA_OpaquePaintEvent widget attribute \e{and} -
849 the \l autoFillBackground property set, the Qt::WA_OpaquePaintEvent -
850 attribute takes precedence. Depending on your requirements, you should -
851 choose either one of them. -
852 -
853 Since Qt 4.1, the contents of parent widgets are also propagated to -
854 standard Qt widgets. This can lead to some unexpected results if the -
855 parent widget is decorated in a non-standard way, as shown in the diagram -
856 below. -
857 -
858 \image propagation-standard.png -
859 -
860 The scope for customizing the painting behavior of standard Qt widgets, -
861 without resorting to subclassing, is slightly less than that possible for -
862 custom widgets. Usually, the desired appearance of a standard widget can be -
863 achieved by setting its \l autoFillBackground property. -
864 -
865 -
866 \section1 Creating Translucent Windows -
867 -
868 Since Qt 4.5, it has been possible to create windows with translucent regions -
869 on window systems that support compositing. -
870 -
871 To enable this feature in a top-level widget, set its Qt::WA_TranslucentBackground -
872 attribute with setAttribute() and ensure that its background is painted with -
873 non-opaque colors in the regions you want to be partially transparent. -
874 -
875 Platform notes: -
876 -
877 \list -
878 \li X11: This feature relies on the use of an X server that supports ARGB visuals -
879 and a compositing window manager. -
880 \li Windows: The widget needs to have the Qt::FramelessWindowHint window flag set -
881 for the translucency to work. -
882 \endlist -
883 -
884 -
885 \section1 Native Widgets vs Alien Widgets -
886 -
887 Introduced in Qt 4.4, alien widgets are widgets unknown to the windowing -
888 system. They do not have a native window handle associated with them. This -
889 feature significantly speeds up widget painting, resizing, and removes flicker. -
890 -
891 Should you require the old behavior with native windows, you can choose -
892 one of the following options: -
893 -
894 \list 1 -
895 \li Use the \c{QT_USE_NATIVE_WINDOWS=1} in your environment. -
896 \li Set the Qt::AA_NativeWindows attribute on your application. All -
897 widgets will be native widgets. -
898 \li Set the Qt::WA_NativeWindow attribute on widgets: The widget itself -
899 and all of its ancestors will become native (unless -
900 Qt::WA_DontCreateNativeAncestors is set). -
901 \li Call QWidget::winId to enforce a native window (this implies 3). -
902 \li Set the Qt::WA_PaintOnScreen attribute to enforce a native window -
903 (this implies 3). -
904 \endlist -
905 -
906 \sa QEvent, QPainter, QGridLayout, QBoxLayout -
907 -
908*/ -
909 -
910QWidgetMapper *QWidgetPrivate::mapper = 0; // widget with wid -
911QWidgetSet *QWidgetPrivate::allWidgets = 0; // widgets with no wid -
912 -
913 -
914/***************************************************************************** -
915 QWidget utility functions -
916 *****************************************************************************/ -
917 -
918QRegion qt_dirtyRegion(QWidget *widget) -
919{ -
920 if (!widget) -
921 return QRegion(); -
922 -
923 QWidgetBackingStore *bs = qt_widget_private(widget)->maybeBackingStore(); -
924 if (!bs) -
925 return QRegion(); -
926 -
927 return bs->dirtyRegion(widget); -
928} -
929 -
930/***************************************************************************** -
931 QWidget member functions -
932 *****************************************************************************/ -
933 -
934/* -
935 Widget state flags: -
936 \list -
937 \li Qt::WA_WState_Created The widget has a valid winId(). -
938 \li Qt::WA_WState_Visible The widget is currently visible. -
939 \li Qt::WA_WState_Hidden The widget is hidden, i.e. it won't -
940 become visible unless you call show() on it. Qt::WA_WState_Hidden -
941 implies !Qt::WA_WState_Visible. -
942 \li Qt::WA_WState_CompressKeys Compress keyboard events. -
943 \li Qt::WA_WState_BlockUpdates Repaints and updates are disabled. -
944 \li Qt::WA_WState_InPaintEvent Currently processing a paint event. -
945 \li Qt::WA_WState_Reparented The widget has been reparented. -
946 \li Qt::WA_WState_ConfigPending A configuration (resize/move) event is pending. -
947 \li Qt::WA_WState_DND (Deprecated) The widget supports drag and drop, see setAcceptDrops(). -
948 \endlist -
949*/ -
950 -
951struct QWidgetExceptionCleaner -
952{ -
953 /* this cleans up when the constructor throws an exception */ -
954 static inline void cleanup(QWidget *that, QWidgetPrivate *d) -
955 { -
956#ifdef QT_NO_EXCEPTIONS -
957 Q_UNUSED(that); -
958 Q_UNUSED(d); -
959#else -
960 QWidgetPrivate::allWidgets->remove(that); -
961 if (d->focus_next != that) { -
962 if (d->focus_next) -
963 d->focus_next->d_func()->focus_prev = d->focus_prev; -
964 if (d->focus_prev) -
965 d->focus_prev->d_func()->focus_next = d->focus_next; -
966 } -
967#endif -
968 } -
969}; -
970 -
971/*! -
972 Constructs a widget which is a child of \a parent, with widget -
973 flags set to \a f. -
974 -
975 If \a parent is 0, the new widget becomes a window. If -
976 \a parent is another widget, this widget becomes a child window -
977 inside \a parent. The new widget is deleted when its \a parent is -
978 deleted. -
979 -
980 The widget flags argument, \a f, is normally 0, but it can be set -
981 to customize the frame of a window (i.e. \a -
982 parent must be 0). To customize the frame, use a value composed -
983 from the bitwise OR of any of the \l{Qt::WindowFlags}{window flags}. -
984 -
985 If you add a child widget to an already visible widget you must -
986 explicitly show the child to make it visible. -
987 -
988 Note that the X11 version of Qt may not be able to deliver all -
989 combinations of style flags on all systems. This is because on -
990 X11, Qt can only ask the window manager, and the window manager -
991 can override the application's settings. On Windows, Qt can set -
992 whatever flags you want. -
993 -
994 \sa windowFlags -
995*/ -
996QWidget::QWidget(QWidget *parent, Qt::WindowFlags f) -
997 : QObject(*new QWidgetPrivate, 0), QPaintDevice() -
998{ -
999 QT_TRY { -
1000 d_func()->init(parent, f); -
1001 } QT_CATCH(...) { -
1002 QWidgetExceptionCleaner::cleanup(this, d_func()); -
1003 QT_RETHROW; -
1004 } -
1005} -
1006 -
1007 -
1008/*! \internal -
1009*/ -
1010QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f) -
1011 : QObject(dd, 0), QPaintDevice() -
1012{ -
1013 Q_D(QWidget); -
1014 QT_TRY { -
1015 d->init(parent, f); -
1016 } QT_CATCH(...) { -
1017 QWidgetExceptionCleaner::cleanup(this, d_func()); -
1018 QT_RETHROW; -
1019 } -
1020} -
1021 -
1022/*! -
1023 \internal -
1024*/ -
1025int QWidget::devType() const -
1026{ -
1027 return QInternal::Widget; -
1028} -
1029 -
1030 -
1031//### w is a "this" ptr, passed as a param because QWorkspace needs special logic -
1032void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w) -
1033{ -
1034 bool customize = (flags & (Qt::CustomizeWindowHint -
1035 | Qt::FramelessWindowHint -
1036 | Qt::WindowTitleHint -
1037 | Qt::WindowSystemMenuHint -
1038 | Qt::WindowMinimizeButtonHint -
1039 | Qt::WindowMaximizeButtonHint -
1040 | Qt::WindowCloseButtonHint -
1041 | Qt::WindowContextHelpButtonHint)); -
1042 -
1043 uint type = (flags & Qt::WindowType_Mask); -
1044 -
1045 if ((type == Qt::Widget || type == Qt::SubWindow) && w && !w->parent()) { -
1046 type = Qt::Window; -
1047 flags |= Qt::Window; -
1048 } -
1049 -
1050 if (flags & Qt::CustomizeWindowHint) { -
1051 // modify window flags to make them consistent. -
1052 // Only enable this on non-Mac platforms. Since the old way of doing this would -
1053 // interpret WindowSystemMenuHint as a close button and we can't change that behavior -
1054 // we can't just add this in. -
1055#ifndef Q_WS_MAC -
1056 if (flags & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint)) { -
1057 flags |= Qt::WindowSystemMenuHint; -
1058#else -
1059 if (flags & (Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint -
1060 | Qt::WindowSystemMenuHint)) { -
1061#endif -
1062 flags |= Qt::WindowTitleHint; -
1063 flags &= ~Qt::FramelessWindowHint; -
1064 } -
1065 } else if (customize && !(flags & Qt::FramelessWindowHint)) { -
1066 // if any of the window hints that affect the titlebar are set -
1067 // and the window is supposed to have frame, we add a titlebar -
1068 // and system menu by default. -
1069 flags |= Qt::WindowSystemMenuHint; -
1070 flags |= Qt::WindowTitleHint; -
1071 } -
1072 if (customize) -
1073 ; // don't modify window flags if the user explicitly set them. -
1074 else if (type == Qt::Dialog || type == Qt::Sheet) -
1075#ifndef Q_OS_WINCE -
1076 flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint | Qt::WindowCloseButtonHint; -
1077#else -
1078 flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; -
1079#endif -
1080 else if (type == Qt::Tool) -
1081 flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; -
1082 else -
1083 flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | -
1084 Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint | Qt::WindowFullscreenButtonHint; -
1085 -
1086} -
1087 -
1088void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f) -
1089{ -
1090 Q_Q(QWidget); -
1091 if (!qobject_cast<QApplication *>(QCoreApplication::instance())) -
1092 qFatal("QWidget: Cannot create a QWidget without QApplication"); -
1093 -
1094 Q_ASSERT(allWidgets); -
1095 if (allWidgets) -
1096 allWidgets->insert(q); -
1097 -
1098 QWidget *desktopWidget = 0; -
1099 if (parentWidget && parentWidget->windowType() == Qt::Desktop) { -
1100 desktopWidget = parentWidget; -
1101 parentWidget = 0; -
1102 } -
1103 -
1104 q->data = &data; -
1105 -
1106#ifndef QT_NO_THREAD -
1107 if (!parent) { -
1108 Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget", -
1109 "Widgets must be created in the GUI thread."); -
1110 } -
1111#endif -
1112 -
1113#if defined(Q_WS_X11) -
1114 if (desktopWidget) { -
1115 // make sure the widget is created on the same screen as the -
1116 // programmer specified desktop widget -
1117 xinfo = desktopWidget->d_func()->xinfo; -
1118 } -
1119#endif -
1120 if (desktopWidget) { -
1121 const int screen = desktopWidget->d_func()->topData()->screenIndex; -
1122 if (QWindow *window = q->windowHandle()) -
1123 window->setScreen(QGuiApplication::screens().value(screen, 0)); -
1124 } -
1125 -
1126 data.fstrut_dirty = true; -
1127 -
1128 data.winid = 0; -
1129 data.widget_attributes = 0; -
1130 data.window_flags = f; -
1131 data.window_state = 0; -
1132 data.focus_policy = 0; -
1133 data.context_menu_policy = Qt::DefaultContextMenu; -
1134 data.window_modality = Qt::NonModal; -
1135 -
1136 data.sizehint_forced = 0; -
1137 data.is_closing = 0; -
1138 data.in_show = 0; -
1139 data.in_set_window_state = 0; -
1140 data.in_destructor = false; -
1141 -
1142 // Widgets with Qt::MSWindowsOwnDC (typically QGLWidget) must have a window handle. -
1143 if (f & Qt::MSWindowsOwnDC) -
1144 q->setAttribute(Qt::WA_NativeWindow); -
1145 -
1146//#ifdef Q_WS_MAC -
1147// q->setAttribute(Qt::WA_NativeWindow); -
1148//#endif -
1149 -
1150 q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute() -
1151 adjustQuitOnCloseAttribute(); -
1152 -
1153 q->setAttribute(Qt::WA_WState_Hidden); -
1154 -
1155 //give potential windows a bigger "pre-initial" size; create_sys() will give them a new size later -
1156 data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,640,480); -
1157 focus_next = focus_prev = q; -
1158 -
1159 if ((f & Qt::WindowType_Mask) == Qt::Desktop) -
1160 q->create(); -
1161 else if (parentWidget) -
1162 q->setParent(parentWidget, data.window_flags); -
1163 else { -
1164 adjustFlags(data.window_flags, q); -
1165 resolveLayoutDirection(); -
1166 // opaque system background? -
1167 const QBrush &background = q->palette().brush(QPalette::Window); -
1168 setOpaque(q->isWindow() && background.style() != Qt::NoBrush && background.isOpaque()); -
1169 } -
1170 data.fnt = QFont(data.fnt, q); -
1171#if defined(Q_WS_X11) -
1172 data.fnt.x11SetScreen(xinfo.screen()); -
1173#endif // Q_WS_X11 -
1174 -
1175 q->setAttribute(Qt::WA_PendingMoveEvent); -
1176 q->setAttribute(Qt::WA_PendingResizeEvent); -
1177 -
1178 if (++QWidgetPrivate::instanceCounter > QWidgetPrivate::maxInstances) -
1179 QWidgetPrivate::maxInstances = QWidgetPrivate::instanceCounter; -
1180 -
1181 if (QApplicationPrivate::testAttribute(Qt::AA_ImmediateWidgetCreation)) -
1182 q->create(); -
1183 -
1184 QEvent e(QEvent::Create); -
1185 QApplication::sendEvent(q, &e); -
1186 QApplication::postEvent(q, new QEvent(QEvent::PolishRequest)); -
1187 -
1188 extraPaintEngine = 0; -
1189 -
1190#ifdef Q_WS_MAC -
1191 // If we add a child to the unified toolbar, we have to redirect the painting. -
1192 if (parentWidget && parentWidget->d_func() && parentWidget->d_func()->isInUnifiedToolbar) { -
1193 if (parentWidget->d_func()->unifiedSurface) { -
1194 QWidget *toolbar = parentWidget->d_func()->toolbar_ancestor; -
1195 parentWidget->d_func()->unifiedSurface->recursiveRedirect(toolbar, toolbar, toolbar->d_func()->toolbar_offset); -
1196 } -
1197 } -
1198#endif // Q_WS_MAC -
1199} -
1200 -
1201 -
1202 -
1203void QWidgetPrivate::createRecursively() -
1204{ -
1205 Q_Q(QWidget); -
1206 q->create(0, true, true); -
1207 for (int i = 0; i < children.size(); ++i) { -
1208 QWidget *child = qobject_cast<QWidget *>(children.at(i)); -
1209 if (child && !child->isHidden() && !child->isWindow() && !child->testAttribute(Qt::WA_WState_Created)) -
1210 child->d_func()->createRecursively(); -
1211 } -
1212} -
1213 -
1214 -
1215 -
1216 -
1217/*! -
1218 Creates a new widget window if \a window is 0, otherwise sets the -
1219 widget's window to \a window. -
1220 -
1221 Initializes the window (sets the geometry etc.) if \a -
1222 initializeWindow is true. If \a initializeWindow is false, no -
1223 initialization is performed. This parameter only makes sense if \a -
1224 window is a valid window. -
1225 -
1226 Destroys the old window if \a destroyOldWindow is true. If \a -
1227 destroyOldWindow is false, you are responsible for destroying the -
1228 window yourself (using platform native code). -
1229 -
1230 The QWidget constructor calls create(0,true,true) to create a -
1231 window for this widget. -
1232*/ -
1233 -
1234void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow) -
1235{ -
1236 Q_D(QWidget); -
1237 if (testAttribute(Qt::WA_WState_Created) && window == 0 && internalWinId()) -
1238 return; -
1239 -
1240 if (d->data.in_destructor) -
1241 return; -
1242 -
1243 Qt::WindowType type = windowType(); -
1244 Qt::WindowFlags &flags = data->window_flags; -
1245 -
1246 if ((type == Qt::Widget || type == Qt::SubWindow) && !parentWidget()) { -
1247 type = Qt::Window; -
1248 flags |= Qt::Window; -
1249 } -
1250 -
1251 if (QWidget *parent = parentWidget()) { -
1252 if (type & Qt::Window) { -
1253 if (!parent->testAttribute(Qt::WA_WState_Created)) -
1254 parent->createWinId(); -
1255 } else if (testAttribute(Qt::WA_NativeWindow) && !parent->internalWinId() -
1256 && !testAttribute(Qt::WA_DontCreateNativeAncestors)) { -
1257 // We're about to create a native child widget that doesn't have a native parent; -
1258 // enforce a native handle for the parent unless the Qt::WA_DontCreateNativeAncestors -
1259 // attribute is set. -
1260 d->createWinId(window); -
1261 // Nothing more to do. -
1262 Q_ASSERT(testAttribute(Qt::WA_WState_Created)); -
1263 Q_ASSERT(internalWinId()); -
1264 return; -
1265 } -
1266 } -
1267 -
1268 -
1269 static int paintOnScreenEnv = -1; -
1270 if (paintOnScreenEnv == -1) -
1271 paintOnScreenEnv = qgetenv("QT_ONSCREEN_PAINT").toInt() > 0 ? 1 : 0; -
1272 if (paintOnScreenEnv == 1) -
1273 setAttribute(Qt::WA_PaintOnScreen); -
1274 -
1275 if (QApplicationPrivate::testAttribute(Qt::AA_NativeWindows)) -
1276 setAttribute(Qt::WA_NativeWindow); -
1277 -
1278#ifdef ALIEN_DEBUG -
1279 qDebug() << "QWidget::create:" << this << "parent:" << parentWidget() -
1280 << "Alien?" << !testAttribute(Qt::WA_NativeWindow); -
1281#endif -
1282 -
1283#if defined (Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP) -
1284 // Unregister the dropsite (if already registered) before we -
1285 // re-create the widget with a native window. -
1286 if (testAttribute(Qt::WA_WState_Created) && !internalWinId() && testAttribute(Qt::WA_NativeWindow) -
1287 && d->extra && d->extra->dropTarget) { -
1288 d->registerDropSite(false); -
1289 } -
1290#endif // defined (Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP) -
1291 -
1292 d->updateIsOpaque(); -
1293 -
1294 setAttribute(Qt::WA_WState_Created); // set created flag -
1295 d->create_sys(window, initializeWindow, destroyOldWindow); -
1296 -
1297 // a real toplevel window needs a backing store -
1298 if (isWindow() && windowType() != Qt::Desktop) { -
1299 d->topData()->backingStoreTracker.destroy(); -
1300 if (hasBackingStoreSupport()) -
1301 d->topData()->backingStoreTracker.create(this); -
1302 } -
1303 -
1304 d->setModal_sys(); -
1305 -
1306 if (!isWindow() && parentWidget() && parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)) -
1307 setAttribute(Qt::WA_DropSiteRegistered, true); -
1308 -
1309#ifdef QT_EVAL -
1310 extern void qt_eval_init_widget(QWidget *w); -
1311 qt_eval_init_widget(this); -
1312#endif -
1313 -
1314 // need to force the resting of the icon after changing parents -
1315 if (testAttribute(Qt::WA_SetWindowIcon)) -
1316 d->setWindowIcon_sys(); -
1317 -
1318 if (isWindow() && !d->topData()->iconText.isEmpty()) -
1319 d->setWindowIconText_helper(d->topData()->iconText); -
1320 if (isWindow() && !d->topData()->caption.isEmpty()) -
1321 d->setWindowTitle_helper(d->topData()->caption); -
1322 if (windowType() != Qt::Desktop) { -
1323 d->updateSystemBackground(); -
1324 -
1325 if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon)) -
1326 d->setWindowIcon_sys(); -
1327 } -
1328 -
1329 // Frame strut update needed in cases where there are native widgets such as QGLWidget, -
1330 // as those force native window creation on their ancestors before they are shown. -
1331 // If the strut is not updated, any subsequent move of the top level window before show -
1332 // will cause window frame to be ignored when positioning the window. -
1333 // Note that this only helps on platforms that handle window creation synchronously. -
1334 d->updateFrameStrut(); -
1335} -
1336 -
1337/*! -
1338 Destroys the widget. -
1339 -
1340 All this widget's children are deleted first. The application -
1341 exits if this widget is the main widget. -
1342*/ -
1343 -
1344QWidget::~QWidget() -
1345{ -
1346 Q_D(QWidget);
executed (the execution status of this line is deduced): QWidgetPrivate * const d = d_func();
-
1347 d->data.in_destructor = true;
executed (the execution status of this line is deduced): d->data.in_destructor = true;
-
1348 -
1349#if defined (QT_CHECK_STATE) -
1350 if (paintingActive()) -
1351 qWarning("QWidget: %s (%s) deleted while being painted", className(), name()); -
1352#endif -
1353 -
1354#ifndef QT_NO_GESTURES -
1355 foreach (Qt::GestureType type, d->gestureContext.keys())
executed (the execution status of this line is deduced): for (QForeachContainer<__typeof__(d->gestureContext.keys())> _container_(d->gestureContext.keys()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (Qt::GestureType type = *_container_.i;; __extension__ ({--_container_.brk; break;}))
-
1356 ungrabGesture(type);
executed: ungrabGesture(type);
Execution Count:5414
5414
1357#endif -
1358 -
1359 // force acceptDrops false before winId is destroyed. -
1360 d->registerDropSite(false);
executed (the execution status of this line is deduced): d->registerDropSite(false);
-
1361 -
1362#ifndef QT_NO_ACTION -
1363 // remove all actions from this widget -
1364 for (int i = 0; i < d->actions.size(); ++i) {
evaluated: i < d->actions.size()
TRUEFALSE
yes
Evaluation Count:3290
yes
Evaluation Count:41486
3290-41486
1365 QActionPrivate *apriv = d->actions.at(i)->d_func();
executed (the execution status of this line is deduced): QActionPrivate *apriv = d->actions.at(i)->d_func();
-
1366 apriv->widgets.removeAll(this);
executed (the execution status of this line is deduced): apriv->widgets.removeAll(this);
-
1367 }
executed: }
Execution Count:3290
3290
1368 d->actions.clear();
executed (the execution status of this line is deduced): d->actions.clear();
-
1369#endif -
1370 -
1371#ifndef QT_NO_SHORTCUT -
1372 // Remove all shortcuts grabbed by this -
1373 // widget, unless application is closing -
1374 if (!QApplicationPrivate::is_app_closing && testAttribute(Qt::WA_GrabbedShortcut))
evaluated: !QApplicationPrivate::is_app_closing
TRUEFALSE
yes
Evaluation Count:41270
yes
Evaluation Count:216
evaluated: testAttribute(Qt::WA_GrabbedShortcut)
TRUEFALSE
yes
Evaluation Count:1479
yes
Evaluation Count:39791
216-41270
1375 qApp->d_func()->shortcutMap.removeShortcut(0, this, QKeySequence());
executed: (static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->shortcutMap.removeShortcut(0, this, QKeySequence());
Execution Count:1479
1479
1376#endif -
1377 -
1378 // delete layout while we still are a valid widget -
1379 delete d->layout;
executed (the execution status of this line is deduced): delete d->layout;
-
1380 d->layout = 0;
executed (the execution status of this line is deduced): d->layout = 0;
-
1381 // Remove myself from focus list -
1382 -
1383 Q_ASSERT(d->focus_next->d_func()->focus_prev == this);
executed (the execution status of this line is deduced): qt_noop();
-
1384 Q_ASSERT(d->focus_prev->d_func()->focus_next == this);
executed (the execution status of this line is deduced): qt_noop();
-
1385 -
1386 if (d->focus_next != this) {
evaluated: d->focus_next != this
TRUEFALSE
yes
Evaluation Count:36280
yes
Evaluation Count:5206
5206-36280
1387 d->focus_next->d_func()->focus_prev = d->focus_prev;
executed (the execution status of this line is deduced): d->focus_next->d_func()->focus_prev = d->focus_prev;
-
1388 d->focus_prev->d_func()->focus_next = d->focus_next;
executed (the execution status of this line is deduced): d->focus_prev->d_func()->focus_next = d->focus_next;
-
1389 d->focus_next = d->focus_prev = 0;
executed (the execution status of this line is deduced): d->focus_next = d->focus_prev = 0;
-
1390 }
executed: }
Execution Count:36280
36280
1391 -
1392 -
1393 QT_TRY {
partially evaluated: true
TRUEFALSE
yes
Evaluation Count:41486
no
Evaluation Count:0
0-41486
1394#ifndef QT_NO_GRAPHICSVIEW -
1395 const QWidget* w = this;
executed (the execution status of this line is deduced): const QWidget* w = this;
-
1396 while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
evaluated: w->d_func()->extra
TRUEFALSE
yes
Evaluation Count:18077
yes
Evaluation Count:29703
evaluated: w->d_func()->extra->focus_proxy
TRUEFALSE
yes
Evaluation Count:6294
yes
Evaluation Count:11783
6294-29703
1397 w = w->d_func()->extra->focus_proxy;
executed: w = w->d_func()->extra->focus_proxy;
Execution Count:6294
6294
1398 QWidget *window = w->window();
executed (the execution status of this line is deduced): QWidget *window = w->window();
-
1399 QWExtra *e = window ? window->d_func()->extra : 0;
partially evaluated: window
TRUEFALSE
yes
Evaluation Count:41486
no
Evaluation Count:0
0-41486
1400 if (!e || !e->proxyWidget)
evaluated: !e
TRUEFALSE
yes
Evaluation Count:10225
yes
Evaluation Count:31261
evaluated: !e->proxyWidget
TRUEFALSE
yes
Evaluation Count:31257
yes
Evaluation Count:4
4-31261
1401#endif -
1402 clearFocus();
executed: clearFocus();
Execution Count:41482
41482
1403 } QT_CATCH(...) {
executed: }
Execution Count:41486
41486
1404 // swallow this problem because we are in a destructor -
1405 }
never executed: }
0
1406 -
1407 d->setDirtyOpaqueRegion();
executed (the execution status of this line is deduced): d->setDirtyOpaqueRegion();
-
1408 -
1409 if (isWindow() && isVisible() && internalWinId()) {
evaluated: isWindow()
TRUEFALSE
yes
Evaluation Count:5206
yes
Evaluation Count:36280
evaluated: isVisible()
TRUEFALSE
yes
Evaluation Count:2096
yes
Evaluation Count:3110
partially evaluated: internalWinId()
TRUEFALSE
yes
Evaluation Count:2096
no
Evaluation Count:0
0-36280
1410 QT_TRY {
partially evaluated: true
TRUEFALSE
yes
Evaluation Count:2096
no
Evaluation Count:0
0-2096
1411 d->close_helper(QWidgetPrivate::CloseNoEvent);
executed (the execution status of this line is deduced): d->close_helper(QWidgetPrivate::CloseNoEvent);
-
1412 } QT_CATCH(...) {
executed: }
Execution Count:2096
2096
1413 // if we're out of memory, at least hide the window. -
1414 QT_TRY {
never evaluated: true
0
1415 hide();
never executed (the execution status of this line is deduced): hide();
-
1416 } QT_CATCH(...) {
never executed: }
0
1417 // and if that also doesn't work, then give up -
1418 }
never executed: }
0
1419 } -
1420 } -
1421 -
1422#if defined(Q_WS_WIN) || defined(Q_WS_X11)|| defined(Q_WS_MAC) -
1423 else if (!internalWinId() && isVisible()) { -
1424 qApp->d_func()->sendSyntheticEnterLeave(this); -
1425 } -
1426#endif -
1427 else if (isVisible()) {
evaluated: isVisible()
TRUEFALSE
yes
Evaluation Count:619
yes
Evaluation Count:38771
619-38771
1428 qApp->d_func()->sendSyntheticEnterLeave(this);
executed (the execution status of this line is deduced): (static_cast<QApplication *>(QCoreApplication::instance()))->d_func()->sendSyntheticEnterLeave(this);
-
1429 }
executed: }
Execution Count:619
619
1430 -
1431 if (QWidgetBackingStore *bs = d->maybeBackingStore()) {
evaluated: QWidgetBackingStore *bs = d->maybeBackingStore()
TRUEFALSE
yes
Evaluation Count:19169
yes
Evaluation Count:22317
19169-22317
1432 bs->removeDirtyWidget(this);
executed (the execution status of this line is deduced): bs->removeDirtyWidget(this);
-
1433 if (testAttribute(Qt::WA_StaticContents))
evaluated: testAttribute(Qt::WA_StaticContents)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:19166
3-19166
1434 bs->removeStaticWidget(this);
executed: bs->removeStaticWidget(this);
Execution Count:3
3
1435 }
executed: }
Execution Count:19169
19169
1436 -
1437 delete d->needsFlush;
executed (the execution status of this line is deduced): delete d->needsFlush;
-
1438 d->needsFlush = 0;
executed (the execution status of this line is deduced): d->needsFlush = 0;
-
1439 -
1440 // The next 20 lines are duplicated from QObject, but required here -
1441 // since QWidget deletes is children itself -
1442 bool blocked = d->blockSig;
executed (the execution status of this line is deduced): bool blocked = d->blockSig;
-
1443 d->blockSig = 0; // unblock signals so we always emit destroyed()
executed (the execution status of this line is deduced): d->blockSig = 0;
-
1444 -
1445 if (d->isSignalConnected(0)) {
evaluated: d->isSignalConnected(0)
TRUEFALSE
yes
Evaluation Count:3688
yes
Evaluation Count:37798
3688-37798
1446 QT_TRY {
partially evaluated: true
TRUEFALSE
yes
Evaluation Count:3688
no
Evaluation Count:0
0-3688
1447 emit destroyed(this);
executed (the execution status of this line is deduced): destroyed(this);
-
1448 } QT_CATCH(...) {
executed: }
Execution Count:3688
3688
1449 // all the signal/slots connections are still in place - if we don't -
1450 // quit now, we will crash pretty soon. -
1451 qWarning("Detected an unexpected exception in ~QWidget while emitting destroyed().");
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qwidget.cpp", 1451, __PRETTY_FUNCTION__).warning("Detected an unexpected exception in ~QWidget while emitting destroyed().");
-
1452 QT_RETHROW;
never executed (the execution status of this line is deduced): qt_noop();
-
1453 }
never executed: }
0
1454 } -
1455 -
1456 if (d->declarativeData) {
partially evaluated: d->declarativeData
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:41486
0-41486
1457 QAbstractDeclarativeData::destroyed(d->declarativeData, this);
never executed (the execution status of this line is deduced): QAbstractDeclarativeData::destroyed(d->declarativeData, this);
-
1458 d->declarativeData = 0; // don't activate again in ~QObject
never executed (the execution status of this line is deduced): d->declarativeData = 0;
-
1459 }
never executed: }
0
1460 -
1461 d->blockSig = blocked;
executed (the execution status of this line is deduced): d->blockSig = blocked;
-
1462 -
1463#ifdef Q_WS_MAC -
1464 // QCocoaView holds a pointer back to this widget. Clear it now -
1465 // to make sure it's not followed later on. The lifetime of the -
1466 // QCocoaView might exceed the lifetime of this widget in cases -
1467 // where Cocoa itself holds references to it. -
1468 extern void qt_mac_clearCocoaViewQWidgetPointers(QWidget *); -
1469 qt_mac_clearCocoaViewQWidgetPointers(this); -
1470#endif -
1471 -
1472 if (!d->children.isEmpty())
evaluated: !d->children.isEmpty()
TRUEFALSE
yes
Evaluation Count:18909
yes
Evaluation Count:22577
18909-22577
1473 d->deleteChildren();
executed: d->deleteChildren();
Execution Count:18909
18909
1474 -
1475 QApplication::removePostedEvents(this);
executed (the execution status of this line is deduced): QApplication::removePostedEvents(this);
-
1476 -
1477 QT_TRY {
partially evaluated: true
TRUEFALSE
yes
Evaluation Count:41486
no
Evaluation Count:0
0-41486
1478 destroy(); // platform-dependent cleanup
executed (the execution status of this line is deduced): destroy();
-
1479 } QT_CATCH(...) {
executed: }
Execution Count:41486
41486
1480 // if this fails we can't do anything about it but at least we are not allowed to throw. -
1481 }
never executed: }
0
1482 --QWidgetPrivate::instanceCounter;
executed (the execution status of this line is deduced): --QWidgetPrivate::instanceCounter;
-
1483 -
1484 if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication
evaluated: QWidgetPrivate::allWidgets
TRUEFALSE
yes
Evaluation Count:41270
yes
Evaluation Count:216
216-41270
1485 QWidgetPrivate::allWidgets->remove(this);
executed: QWidgetPrivate::allWidgets->remove(this);
Execution Count:41270
41270
1486 -
1487 QT_TRY {
partially evaluated: true
TRUEFALSE
yes
Evaluation Count:41486
no
Evaluation Count:0
0-41486
1488 QEvent e(QEvent::Destroy);
executed (the execution status of this line is deduced): QEvent e(QEvent::Destroy);
-
1489 QCoreApplication::sendEvent(this, &e);
executed (the execution status of this line is deduced): QCoreApplication::sendEvent(this, &e);
-
1490 } QT_CATCH(const std::exception&) {
executed: }
Execution Count:41486
41486
1491 // if this fails we can't do anything about it but at least we are not allowed to throw. -
1492 }
never executed: }
0
1493} -
1494 -
1495int QWidgetPrivate::instanceCounter = 0; // Current number of widget instances -
1496int QWidgetPrivate::maxInstances = 0; // Maximum number of widget instances -
1497 -
1498void QWidgetPrivate::setWinId(WId id) // set widget identifier -
1499{ -
1500 Q_Q(QWidget); -
1501 // the user might create a widget with Qt::Desktop window -
1502 // attribute (or create another QDesktopWidget instance), which -
1503 // will have the same windowid (the root window id) as the -
1504 // qt_desktopWidget. We should not add the second desktop widget -
1505 // to the mapper. -
1506 bool userDesktopWidget = qt_desktopWidget != 0 && qt_desktopWidget != q && q->windowType() == Qt::Desktop; -
1507 if (mapper && data.winid && !userDesktopWidget) { -
1508 mapper->remove(data.winid); -
1509 } -
1510 -
1511 const WId oldWinId = data.winid; -
1512 -
1513 data.winid = id; -
1514#if defined(Q_WS_X11) -
1515 hd = id; // X11: hd == ident -
1516#endif -
1517 if (mapper && id && !userDesktopWidget) { -
1518 mapper->insert(data.winid, q); -
1519 } -
1520 -
1521 if(oldWinId != id) { -
1522 QEvent e(QEvent::WinIdChange); -
1523 QCoreApplication::sendEvent(q, &e); -
1524 } -
1525} -
1526 -
1527void QWidgetPrivate::createTLExtra() -
1528{ -
1529 if (!extra) -
1530 createExtra(); -
1531 if (!extra->topextra) { -
1532 QTLWExtra* x = extra->topextra = new QTLWExtra; -
1533 x->icon = 0; -
1534 x->backingStore = 0; -
1535 x->sharedPainter = 0; -
1536 x->incw = x->inch = 0; -
1537 x->basew = x->baseh = 0; -
1538 x->frameStrut.setCoords(0, 0, 0, 0); -
1539 x->normalGeometry = QRect(0,0,-1,-1); -
1540 x->savedFlags = 0; -
1541 x->opacity = 255; -
1542 x->posIncludesFrame = 0; -
1543 x->sizeAdjusted = false; -
1544 x->inTopLevelResize = false; -
1545 x->inRepaint = false; -
1546 x->embedded = 0; -
1547#ifdef Q_WS_MAC -
1548 x->wasMaximized = false; -
1549#endif // Q_WS_MAC -
1550 createTLSysExtra(); -
1551#ifdef QWIDGET_EXTRA_DEBUG -
1552 static int count = 0; -
1553 qDebug() << "tlextra" << ++count; -
1554#endif -
1555 } -
1556} -
1557 -
1558/*! -
1559 \internal -
1560 Creates the widget extra data. -
1561*/ -
1562 -
1563void QWidgetPrivate::createExtra() -
1564{ -
1565 if (!extra) { // if not exists -
1566 extra = new QWExtra; -
1567 extra->glContext = 0; -
1568 extra->topextra = 0; -
1569#ifndef QT_NO_GRAPHICSVIEW -
1570 extra->proxyWidget = 0; -
1571#endif -
1572#ifndef QT_NO_CURSOR -
1573 extra->curs = 0; -
1574#endif -
1575 extra->minw = 0; -
1576 extra->minh = 0; -
1577 extra->maxw = QWIDGETSIZE_MAX; -
1578 extra->maxh = QWIDGETSIZE_MAX; -
1579 extra->customDpiX = 0; -
1580 extra->customDpiY = 0; -
1581 extra->explicitMinSize = 0; -
1582 extra->explicitMaxSize = 0; -
1583 extra->autoFillBackground = 0; -
1584 extra->nativeChildrenForced = 0; -
1585 extra->inRenderWithPainter = 0; -
1586 extra->hasMask = 0; -
1587 createSysExtra(); -
1588#ifdef QWIDGET_EXTRA_DEBUG -
1589 static int count = 0; -
1590 qDebug() << "extra" << ++count; -
1591#endif -
1592 } -
1593} -
1594 -
1595 -
1596/*! -
1597 \internal -
1598 Deletes the widget extra data. -
1599*/ -
1600 -
1601void QWidgetPrivate::deleteExtra() -
1602{ -
1603 if (extra) { // if exists -
1604#ifndef QT_NO_CURSOR -
1605 delete extra->curs; -
1606#endif -
1607 deleteSysExtra(); -
1608#ifndef QT_NO_STYLE_STYLESHEET -
1609 // dereference the stylesheet style -
1610 if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(extra->style)) -
1611 proxy->deref(); -
1612#endif -
1613 if (extra->topextra) { -
1614 deleteTLSysExtra(); -
1615 // extra->topextra->backingStore destroyed in QWidgetPrivate::deleteTLSysExtra() -
1616 delete extra->topextra->icon; -
1617 delete extra->topextra; -
1618 } -
1619 delete extra; -
1620 // extra->xic destroyed in QWidget::destroy() -
1621 extra = 0; -
1622 } -
1623} -
1624 -
1625/* -
1626 Returns true if there are widgets above this which overlap with -
1627 \a rect, which is in parent's coordinate system (same as crect). -
1628*/ -
1629 -
1630bool QWidgetPrivate::isOverlapped(const QRect &rect) const -
1631{ -
1632 Q_Q(const QWidget); -
1633 -
1634 const QWidget *w = q; -
1635 QRect r = rect; -
1636 while (w) { -
1637 if (w->isWindow()) -
1638 return false; -
1639 QWidgetPrivate *pd = w->parentWidget()->d_func(); -
1640 bool above = false; -
1641 for (int i = 0; i < pd->children.size(); ++i) { -
1642 QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i)); -
1643 if (!sibling || !sibling->isVisible() || sibling->isWindow()) -
1644 continue; -
1645 if (!above) { -
1646 above = (sibling == w); -
1647 continue; -
1648 } -
1649 -
1650 if (qRectIntersects(sibling->d_func()->effectiveRectFor(sibling->data->crect), r)) { -
1651 const QWExtra *siblingExtra = sibling->d_func()->extra; -
1652 if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect -
1653 && !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) { -
1654 continue; -
1655 } -
1656 return true; -
1657 } -
1658 } -
1659 w = w->parentWidget(); -
1660 r.translate(pd->data.crect.topLeft()); -
1661 } -
1662 return false; -
1663} -
1664 -
1665void QWidgetPrivate::syncBackingStore() -
1666{ -
1667 if (paintOnScreen()) { -
1668 repaint_sys(dirty); -
1669 dirty = QRegion(); -
1670 } else if (QWidgetBackingStore *bs = maybeBackingStore()) { -
1671 bs->sync(); -
1672 } -
1673} -
1674 -
1675void QWidgetPrivate::syncBackingStore(const QRegion &region) -
1676{ -
1677 if (paintOnScreen()) -
1678 repaint_sys(region); -
1679 else if (QWidgetBackingStore *bs = maybeBackingStore()) { -
1680 bs->sync(q_func(), region); -
1681 } -
1682} -
1683 -
1684void QWidgetPrivate::setUpdatesEnabled_helper(bool enable) -
1685{ -
1686 Q_Q(QWidget); -
1687 -
1688 if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->updatesEnabled()) -
1689 return; // nothing we can do -
1690 -
1691 if (enable != q->testAttribute(Qt::WA_UpdatesDisabled)) -
1692 return; // nothing to do -
1693 -
1694 q->setAttribute(Qt::WA_UpdatesDisabled, !enable); -
1695 if (enable) -
1696 q->update(); -
1697 -
1698 Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceUpdatesDisabled : Qt::WA_UpdatesDisabled; -
1699 for (int i = 0; i < children.size(); ++i) { -
1700 QWidget *w = qobject_cast<QWidget *>(children.at(i)); -
1701 if (w && !w->isWindow() && !w->testAttribute(attribute)) -
1702 w->d_func()->setUpdatesEnabled_helper(enable); -
1703 } -
1704} -
1705 -
1706/*! -
1707 \internal -
1708 -
1709 Propagate this widget's palette to all children, except style sheet -
1710 widgets, and windows that don't enable window propagation (palettes don't -
1711 normally propagate to windows). -
1712*/ -
1713void QWidgetPrivate::propagatePaletteChange() -
1714{ -
1715 Q_Q(QWidget); -
1716 // Propagate a new inherited mask to all children. -
1717#ifndef QT_NO_GRAPHICSVIEW -
1718 if (!q->parentWidget() && extra && extra->proxyWidget) { -
1719 QGraphicsProxyWidget *p = extra->proxyWidget; -
1720 inheritedPaletteResolveMask = p->d_func()->inheritedPaletteResolveMask | p->palette().resolve(); -
1721 } else -
1722#endif //QT_NO_GRAPHICSVIEW -
1723 if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) { -
1724 inheritedPaletteResolveMask = 0; -
1725 } -
1726 int mask = data.pal.resolve() | inheritedPaletteResolveMask; -
1727 -
1728 QEvent pc(QEvent::PaletteChange); -
1729 QApplication::sendEvent(q, &pc); -
1730 for (int i = 0; i < children.size(); ++i) { -
1731 QWidget *w = qobject_cast<QWidget*>(children.at(i)); -
1732 if (w && !w->testAttribute(Qt::WA_StyleSheet) -
1733 && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) { -
1734 QWidgetPrivate *wd = w->d_func(); -
1735 wd->inheritedPaletteResolveMask = mask; -
1736 wd->resolvePalette(); -
1737 } -
1738 } -
1739} -
1740 -
1741/* -
1742 Returns the widget's clipping rectangle. -
1743*/ -
1744QRect QWidgetPrivate::clipRect() const -
1745{ -
1746 Q_Q(const QWidget); -
1747 const QWidget * w = q; -
1748 if (!w->isVisible()) -
1749 return QRect(); -
1750 QRect r = effectiveRectFor(q->rect()); -
1751 int ox = 0; -
1752 int oy = 0; -
1753 while (w -
1754 && w->isVisible() -
1755 && !w->isWindow() -
1756 && w->parentWidget()) { -
1757 ox -= w->x(); -
1758 oy -= w->y(); -
1759 w = w->parentWidget(); -
1760 r &= QRect(ox, oy, w->width(), w->height()); -
1761 } -
1762 return r; -
1763} -
1764 -
1765/* -
1766 Returns the widget's clipping region (without siblings). -
1767*/ -
1768QRegion QWidgetPrivate::clipRegion() const -
1769{ -
1770 Q_Q(const QWidget); -
1771 if (!q->isVisible()) -
1772 return QRegion(); -
1773 QRegion r(q->rect()); -
1774 const QWidget * w = q; -
1775 const QWidget *ignoreUpTo; -
1776 int ox = 0; -
1777 int oy = 0; -
1778 while (w -
1779 && w->isVisible() -
1780 && !w->isWindow() -
1781 && w->parentWidget()) { -
1782 ox -= w->x(); -
1783 oy -= w->y(); -
1784 ignoreUpTo = w; -
1785 w = w->parentWidget(); -
1786 r &= QRegion(ox, oy, w->width(), w->height()); -
1787 -
1788 int i = 0; -
1789 while(w->d_func()->children.at(i++) != static_cast<const QObject *>(ignoreUpTo)) -
1790 ; -
1791 for ( ; i < w->d_func()->children.size(); ++i) { -
1792 if(QWidget *sibling = qobject_cast<QWidget *>(w->d_func()->children.at(i))) { -
1793 if(sibling->isVisible() && !sibling->isWindow()) { -
1794 QRect siblingRect(ox+sibling->x(), oy+sibling->y(), -
1795 sibling->width(), sibling->height()); -
1796 if (qRectIntersects(siblingRect, q->rect())) -
1797 r -= QRegion(siblingRect); -
1798 } -
1799 } -
1800 } -
1801 } -
1802 return r; -
1803} -
1804 -
1805void QWidgetPrivate::setSystemClip(QPaintDevice *paintDevice, const QRegion &region) -
1806{ -
1807// Transform the system clip region from device-independent pixels to device pixels -
1808// Qt 5.0.0: This is a Mac-only code path for now, can be made cross-platform once -
1809// it has been tested. -
1810 QPaintEngine *paintEngine = paintDevice->paintEngine(); -
1811#ifdef Q_OS_MAC -
1812 const qreal devicePixelRatio = (paintDevice->physicalDpiX() == 0 || paintDevice->logicalDpiX() == 0) ? -
1813 1.0 : (paintDevice->physicalDpiX() / paintDevice->logicalDpiX()); -
1814 QTransform scaleTransform; -
1815 scaleTransform.scale(devicePixelRatio, devicePixelRatio); -
1816 paintEngine->d_func()->systemClip = scaleTransform.map(region); -
1817#else -
1818 paintEngine->d_func()->systemClip = region; -
1819#endif -
1820} -
1821 -
1822#ifndef QT_NO_GRAPHICSEFFECT -
1823void QWidgetPrivate::invalidateGraphicsEffectsRecursively() -
1824{ -
1825 Q_Q(QWidget); -
1826 QWidget *w = q; -
1827 do { -
1828 if (w->graphicsEffect()) { -
1829 QWidgetEffectSourcePrivate *sourced = -
1830 static_cast<QWidgetEffectSourcePrivate *>(w->graphicsEffect()->source()->d_func()); -
1831 if (!sourced->updateDueToGraphicsEffect) -
1832 w->graphicsEffect()->source()->d_func()->invalidateCache(); -
1833 } -
1834 w = w->parentWidget(); -
1835 } while (w); -
1836} -
1837#endif //QT_NO_GRAPHICSEFFECT -
1838 -
1839void QWidgetPrivate::setDirtyOpaqueRegion() -
1840{ -
1841 Q_Q(QWidget); -
1842 -
1843 dirtyOpaqueChildren = true; -
1844 -
1845#ifndef QT_NO_GRAPHICSEFFECT -
1846 invalidateGraphicsEffectsRecursively(); -
1847#endif //QT_NO_GRAPHICSEFFECT -
1848 -
1849 if (q->isWindow()) -
1850 return; -
1851 -
1852 QWidget *parent = q->parentWidget(); -
1853 if (!parent) -
1854 return; -
1855 -
1856 // TODO: instead of setting dirtyflag, manipulate the dirtyregion directly? -
1857 QWidgetPrivate *pd = parent->d_func(); -
1858 if (!pd->dirtyOpaqueChildren) -
1859 pd->setDirtyOpaqueRegion(); -
1860} -
1861 -
1862const QRegion &QWidgetPrivate::getOpaqueChildren() const -
1863{ -
1864 if (!dirtyOpaqueChildren) -
1865 return opaqueChildren; -
1866 -
1867 QWidgetPrivate *that = const_cast<QWidgetPrivate*>(this); -
1868 that->opaqueChildren = QRegion(); -
1869 -
1870 for (int i = 0; i < children.size(); ++i) { -
1871 QWidget *child = qobject_cast<QWidget *>(children.at(i)); -
1872 if (!child || !child->isVisible() || child->isWindow()) -
1873 continue; -
1874 -
1875 const QPoint offset = child->geometry().topLeft(); -
1876 QWidgetPrivate *childd = child->d_func(); -
1877 QRegion r = childd->isOpaque ? child->rect() : childd->getOpaqueChildren(); -
1878 if (childd->extra && childd->extra->hasMask) -
1879 r &= childd->extra->mask; -
1880 if (r.isEmpty()) -
1881 continue; -
1882 r.translate(offset); -
1883 that->opaqueChildren += r; -
1884 } -
1885 -
1886 that->opaqueChildren &= q_func()->rect(); -
1887 that->dirtyOpaqueChildren = false; -
1888 -
1889 return that->opaqueChildren; -
1890} -
1891 -
1892void QWidgetPrivate::subtractOpaqueChildren(QRegion &source, const QRect &clipRect) const -
1893{ -
1894 if (children.isEmpty() || clipRect.isEmpty()) -
1895 return; -
1896 -
1897 const QRegion &r = getOpaqueChildren(); -
1898 if (!r.isEmpty()) -
1899 source -= (r & clipRect); -
1900} -
1901 -
1902//subtract any relatives that are higher up than me --- this is too expensive !!! -
1903void QWidgetPrivate::subtractOpaqueSiblings(QRegion &sourceRegion, bool *hasDirtySiblingsAbove, -
1904 bool alsoNonOpaque) const -
1905{ -
1906 Q_Q(const QWidget); -
1907 static int disableSubtractOpaqueSiblings = qgetenv("QT_NO_SUBTRACTOPAQUESIBLINGS").toInt(); -
1908 if (disableSubtractOpaqueSiblings || q->isWindow()) -
1909 return; -
1910 -
1911#ifdef Q_WS_MAC -
1912 if (q->d_func()->isInUnifiedToolbar) -
1913 return; -
1914#endif // Q_WS_MAC -
1915 -
1916 QRect clipBoundingRect; -
1917 bool dirtyClipBoundingRect = true; -
1918 -
1919 QRegion parentClip; -
1920 bool dirtyParentClip = true; -
1921 -
1922 QPoint parentOffset = data.crect.topLeft(); -
1923 -
1924 const QWidget *w = q; -
1925 -
1926 while (w) { -
1927 if (w->isWindow()) -
1928 break; -
1929 QWidgetPrivate *pd = w->parentWidget()->d_func(); -
1930 const int myIndex = pd->children.indexOf(const_cast<QWidget *>(w)); -
1931 const QRect widgetGeometry = w->d_func()->effectiveRectFor(w->data->crect); -
1932 for (int i = myIndex + 1; i < pd->children.size(); ++i) { -
1933 QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i)); -
1934 if (!sibling || !sibling->isVisible() || sibling->isWindow()) -
1935 continue; -
1936 -
1937 const QRect siblingGeometry = sibling->d_func()->effectiveRectFor(sibling->data->crect); -
1938 if (!qRectIntersects(siblingGeometry, widgetGeometry)) -
1939 continue; -
1940 -
1941 if (dirtyClipBoundingRect) { -
1942 clipBoundingRect = sourceRegion.boundingRect(); -
1943 dirtyClipBoundingRect = false; -
1944 } -
1945 -
1946 if (!qRectIntersects(siblingGeometry, clipBoundingRect.translated(parentOffset))) -
1947 continue; -
1948 -
1949 if (dirtyParentClip) { -
1950 parentClip = sourceRegion.translated(parentOffset); -
1951 dirtyParentClip = false; -
1952 } -
1953 -
1954 const QPoint siblingPos(sibling->data->crect.topLeft()); -
1955 const QRect siblingClipRect(sibling->d_func()->clipRect()); -
1956 QRegion siblingDirty(parentClip); -
1957 siblingDirty &= (siblingClipRect.translated(siblingPos)); -
1958 const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask -
1959 && !sibling->d_func()->graphicsEffect; -
1960 if (hasMask) -
1961 siblingDirty &= sibling->d_func()->extra->mask.translated(siblingPos); -
1962 if (siblingDirty.isEmpty()) -
1963 continue; -
1964 -
1965 if (sibling->d_func()->isOpaque || alsoNonOpaque) { -
1966 if (hasMask) { -
1967 siblingDirty.translate(-parentOffset); -
1968 sourceRegion -= siblingDirty; -
1969 } else { -
1970 sourceRegion -= siblingGeometry.translated(-parentOffset); -
1971 } -
1972 } else { -
1973 if (hasDirtySiblingsAbove) -
1974 *hasDirtySiblingsAbove = true; -
1975 if (sibling->d_func()->children.isEmpty()) -
1976 continue; -
1977 QRegion opaqueSiblingChildren(sibling->d_func()->getOpaqueChildren()); -
1978 opaqueSiblingChildren.translate(-parentOffset + siblingPos); -
1979 sourceRegion -= opaqueSiblingChildren; -
1980 } -
1981 if (sourceRegion.isEmpty()) -
1982 return; -
1983 -
1984 dirtyClipBoundingRect = true; -
1985 dirtyParentClip = true; -
1986 } -
1987 -
1988 w = w->parentWidget(); -
1989 parentOffset += pd->data.crect.topLeft(); -
1990 dirtyParentClip = true; -
1991 } -
1992} -
1993 -
1994void QWidgetPrivate::clipToEffectiveMask(QRegion &region) const -
1995{ -
1996 Q_Q(const QWidget); -
1997 -
1998 const QWidget *w = q; -
1999 QPoint offset; -
2000 -
2001#ifndef QT_NO_GRAPHICSEFFECT -
2002 if (graphicsEffect) { -
2003 w = q->parentWidget(); -
2004 offset -= data.crect.topLeft(); -
2005 } -
2006#endif //QT_NO_GRAPHICSEFFECT -
2007 -
2008 while (w) { -
2009 const QWidgetPrivate *wd = w->d_func(); -
2010 if (wd->extra && wd->extra->hasMask) -
2011 region &= (w != q) ? wd->extra->mask.translated(offset) : wd->extra->mask; -
2012 if (w->isWindow()) -
2013 return; -
2014 offset -= wd->data.crect.topLeft(); -
2015 w = w->parentWidget(); -
2016 } -
2017} -
2018 -
2019bool QWidgetPrivate::paintOnScreen() const -
2020{ -
2021#if defined(QT_NO_BACKINGSTORE) -
2022 return true; -
2023#else -
2024 Q_Q(const QWidget); -
2025 if (q->testAttribute(Qt::WA_PaintOnScreen) -
2026 || (!q->isWindow() && q->window()->testAttribute(Qt::WA_PaintOnScreen))) { -
2027 return true; -
2028 } -
2029 -
2030 return !qt_enable_backingstore; -
2031#endif -
2032} -
2033 -
2034void QWidgetPrivate::updateIsOpaque() -
2035{ -
2036 // hw: todo: only needed if opacity actually changed -
2037 setDirtyOpaqueRegion(); -
2038 -
2039#ifndef QT_NO_GRAPHICSEFFECT -
2040 if (graphicsEffect) { -
2041 // ### We should probably add QGraphicsEffect::isOpaque at some point. -
2042 setOpaque(false); -
2043 return; -
2044 } -
2045#endif //QT_NO_GRAPHICSEFFECT -
2046 -
2047 Q_Q(QWidget); -
2048#ifdef Q_WS_X11 -
2049 if (q->testAttribute(Qt::WA_X11OpenGLOverlay)) { -
2050 setOpaque(false); -
2051 return; -
2052 } -
2053#endif -
2054 -
2055 if (q->testAttribute(Qt::WA_OpaquePaintEvent) || q->testAttribute(Qt::WA_PaintOnScreen)) { -
2056 setOpaque(true); -
2057 return; -
2058 } -
2059 -
2060 const QPalette &pal = q->palette(); -
2061 -
2062 if (q->autoFillBackground()) { -
2063 const QBrush &autoFillBrush = pal.brush(q->backgroundRole()); -
2064 if (autoFillBrush.style() != Qt::NoBrush && autoFillBrush.isOpaque()) { -
2065 setOpaque(true); -
2066 return; -
2067 } -
2068 } -
2069 -
2070 if (q->isWindow() && !q->testAttribute(Qt::WA_NoSystemBackground)) { -
2071 const QBrush &windowBrush = q->palette().brush(QPalette::Window); -
2072 if (windowBrush.style() != Qt::NoBrush && windowBrush.isOpaque()) { -
2073 setOpaque(true); -
2074 return; -
2075 } -
2076 } -
2077 setOpaque(false); -
2078} -
2079 -
2080void QWidgetPrivate::setOpaque(bool opaque) -
2081{ -
2082 if (isOpaque != opaque) { -
2083 isOpaque = opaque; -
2084 updateIsTranslucent(); -
2085 } -
2086} -
2087 -
2088void QWidgetPrivate::updateIsTranslucent() -
2089{ -
2090 Q_Q(QWidget);
executed (the execution status of this line is deduced): QWidget * const q = q_func();
-
2091 if (QWindow *window = q->windowHandle()) {
evaluated: QWindow *window = q->windowHandle()
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:28357
10-28357
2092 QSurfaceFormat format = window->setOpacity(isOpaque ? qreal(1format();
executed (the execution status of this line is deduced): QSurfaceFormat format = window->format();
-
2093 const int oldAlpha = format.0) : qrealalphaBufferSize();
executed (the execution status of this line is deduced): const int oldAlpha = format.alphaBufferSize();
-
2094 const int newAlpha = q->testAttribute(Qt::WA_TranslucentBackground)? 8 : 0;
partially evaluated: q->testAttribute(Qt::WA_TranslucentBackground)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10
0-10
2095 if (oldAlpha != newAlpha) {
partially evaluated: oldAlpha != newAlpha
TRUEFALSE
yes
Evaluation Count:10
no
Evaluation Count:0
0-10
2096 format.0));setAlphaBufferSize(newAlpha);
executed (the execution status of this line is deduced): format.setAlphaBufferSize(newAlpha);
-
2097 window->setFormat(format);
executed (the execution status of this line is deduced): window->setFormat(format);
-
2098 }
executed: }
Execution Count:10
10
2099 }
executed: }
Execution Count:10
10
2100}
executed: }
Execution Count:28367
28367
2101 -
2102static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush) -
2103{ -
2104 Q_ASSERT(painter); -
2105 -
2106 if (brush.style() == Qt::TexturePattern) { -
2107#ifdef Q_WS_MAC -
2108 // Optimize pattern filling on mac by using HITheme directly -
2109 // when filling with the standard widget background. -
2110 // Defined in qmacstyle_mac.cpp -
2111 extern void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush); -
2112 qt_mac_fill_background(painter, rgn, brush); -
2113#else -
2114 { -
2115 const QRect rect(rgn.boundingRect()); -
2116 painter->setClipRegion(rgn); -
2117 painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft()); -
2118 } -
2119#endif // Q_WS_MAC -
2120 -
2121 } else if (brush.gradient() -
2122 && brush.gradient()->coordinateMode() == QGradient::ObjectBoundingMode) { -
2123 painter->save(); -
2124 painter->setClipRegion(rgn); -
2125 painter->fillRect(0, 0, painter->device()->width(), painter->device()->height(), brush); -
2126 painter->restore(); -
2127 } else { -
2128 const QVector<QRect> &rects = rgn.rects(); -
2129 for (int i = 0; i < rects.size(); ++i) -
2130 painter->fillRect(rects.at(i), brush); -
2131 } -
2132} -
2133 -
2134void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const -
2135{ -
2136 Q_Q(const QWidget); -
2137 -
2138#ifndef QT_NO_SCROLLAREA -
2139 bool resetBrushOrigin = false; -
2140 QPointF oldBrushOrigin; -
2141 //If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture -
2142 QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(parent); -
2143 if (scrollArea && scrollArea->viewport() == q) { -
2144 QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data(); -
2145 QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate); -
2146 oldBrushOrigin = painter->brushOrigin(); -
2147 resetBrushOrigin = true; -
2148 painter->setBrushOrigin(-priv->contentsOffset()); -
2149 -
2150 } -
2151#endif // QT_NO_SCROLLAREA -
2152 -
2153 const QBrush autoFillBrush = q->palette().brush(q->backgroundRole()); -
2154 -
2155 if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) { -
2156 const QBrush bg = q->palette().brush(QPalette::Window); -
2157 if (!(flags & DontSetCompositionMode)) { -
2158 //copy alpha straight in -
2159 QPainter::CompositionMode oldMode = painter->compositionMode(); -
2160 painter->setCompositionMode(QPainter::CompositionMode_Source); -
2161 fillRegion(painter, rgn, bg); -
2162 painter->setCompositionMode(oldMode); -
2163 } else { -
2164 fillRegion(painter, rgn, bg); -
2165 } -
2166 } -
2167 -
2168 if (q->autoFillBackground()) -
2169 fillRegion(painter, rgn, autoFillBrush); -
2170 -
2171 if (q->testAttribute(Qt::WA_StyledBackground)) { -
2172 painter->setClipRegion(rgn); -
2173 QStyleOption opt; -
2174 opt.initFrom(q); -
2175 q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q); -
2176 } -
2177 -
2178#ifndef QT_NO_SCROLLAREA -
2179 if (resetBrushOrigin) -
2180 painter->setBrushOrigin(oldBrushOrigin); -
2181#endif // QT_NO_SCROLLAREA -
2182} -
2183 -
2184/* -
2185 \internal -
2186 This function is called when a widget is hidden or destroyed. -
2187 It resets some application global pointers that should only refer active, -
2188 visible widgets. -
2189*/ -
2190 -
2191#ifdef Q_WS_MAC -
2192 extern QPointer<QWidget> qt_button_down; -
2193#else -
2194 extern QWidget *qt_button_down; -
2195#endif -
2196 -
2197void QWidgetPrivate::deactivateWidgetCleanup() -
2198{ -
2199 Q_Q(QWidget); -
2200 // If this was the active application window, reset it -
2201 if (QApplication::activeWindow() == q) -
2202 QApplication::setActiveWindow(0); -
2203 // If the is the active mouse press widget, reset it -
2204 if (q == qt_button_down) -
2205 qt_button_down = 0; -
2206} -
2207 -
2208 -
2209/*! -
2210 Returns a pointer to the widget with window identifer/handle \a -
2211 id. -
2212 -
2213 The window identifier type depends on the underlying window -
2214 system, see \c qwindowdefs.h for the actual definition. If there -
2215 is no widget with this identifier, 0 is returned. -
2216*/ -
2217 -
2218QWidget *QWidget::find(WId id) -
2219{ -
2220 return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0; -
2221} -
2222 -
2223 -
2224 -
2225/*! -
2226 \fn WId QWidget::internalWinId() const -
2227 \internal -
2228 Returns the window system identifier of the widget, or 0 if the widget is not created yet. -
2229 -
2230*/ -
2231 -
2232/*! -
2233 \fn WId QWidget::winId() const -
2234 -
2235 Returns the window system identifier of the widget. -
2236 -
2237 Portable in principle, but if you use it you are probably about to -
2238 do something non-portable. Be careful. -
2239 -
2240 If a widget is non-native (alien) and winId() is invoked on it, that widget -
2241 will be provided a native handle. -
2242 -
2243 On Mac OS X, the type returned depends on which framework Qt was linked -
2244 against. If Qt is using Carbon, the {WId} is actually an HIViewRef. If Qt -
2245 is using Cocoa, {WId} is a pointer to an NSView. -
2246 -
2247 This value may change at run-time. An event with type QEvent::WinIdChange -
2248 will be sent to the widget following a change in window system identifier. -
2249 -
2250 \sa find() -
2251*/ -
2252WId QWidget::winId() const -
2253{ -
2254 if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) { -
2255#ifdef ALIEN_DEBUG -
2256 qDebug() << "QWidget::winId: creating native window for" << this; -
2257#endif -
2258 QWidget *that = const_cast<QWidget*>(this); -
2259 that->setAttribute(Qt::WA_NativeWindow); -
2260 that->d_func()->createWinId(); -
2261 return that->data->winid; -
2262 } -
2263 return data->winid; -
2264} -
2265 -
2266 -
2267void QWidgetPrivate::createWinId(WId winid) -
2268{ -
2269 Q_Q(QWidget); -
2270 -
2271#ifdef ALIEN_DEBUG -
2272 qDebug() << "QWidgetPrivate::createWinId for" << q << winid; -
2273#endif -
2274 const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow); -
2275 if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) { -
2276 if (!q->isWindow()) { -
2277 QWidget *parent = q->parentWidget(); -
2278 QWidgetPrivate *pd = parent->d_func(); -
2279 if (forceNativeWindow && !q->testAttribute(Qt::WA_DontCreateNativeAncestors)) -
2280 parent->setAttribute(Qt::WA_NativeWindow); -
2281 if (!parent->internalWinId()) { -
2282 pd->createWinId(); -
2283 } -
2284 -
2285 for (int i = 0; i < pd->children.size(); ++i) { -
2286 QWidget *w = qobject_cast<QWidget *>(pd->children.at(i)); -
2287 if (w && !w->isWindow() && (!w->testAttribute(Qt::WA_WState_Created) -
2288 || (!w->internalWinId() && w->testAttribute(Qt::WA_NativeWindow)))) { -
2289 if (w!=q) { -
2290 w->create(); -
2291 } else { -
2292 w->create(winid); -
2293 // if the window has already been created, we -
2294 // need to raise it to its proper stacking position -
2295 if (winid) -
2296 w->raise(); -
2297 } -
2298 } -
2299 } -
2300 } else { -
2301 q->create(); -
2302 } -
2303 } -
2304} -
2305 -
2306 -
2307/*! -
2308\internal -
2309Ensures that the widget has a window system identifier, i.e. that it is known to the windowing system. -
2310 -
2311*/ -
2312 -
2313void QWidget::createWinId() -
2314{ -
2315 Q_D(QWidget); -
2316#ifdef ALIEN_DEBUG -
2317 qDebug() << "QWidget::createWinId" << this; -
2318#endif -
2319// qWarning("QWidget::createWinId is obsolete, please fix your code."); -
2320 d->createWinId(); -
2321} -
2322 -
2323/*! -
2324 \since 4.4 -
2325 -
2326 Returns the effective window system identifier of the widget, i.e. the -
2327 native parent's window system identifier. -
2328 -
2329 If the widget is native, this function returns the native widget ID. -
2330 Otherwise, the window ID of the first native parent widget, i.e., the -
2331 top-level widget that contains this widget, is returned. -
2332 -
2333 \note We recommend that you do not store this value as it is likely to -
2334 change at run-time. -
2335 -
2336 \sa nativeParentWidget() -
2337*/ -
2338WId QWidget::effectiveWinId() const -
2339{ -
2340 const WId id = internalWinId(); -
2341 if (id || !testAttribute(Qt::WA_WState_Created)) -
2342 return id; -
2343 if (const QWidget *realParent = nativeParentWidget()) -
2344 return realParent->internalWinId(); -
2345 return 0; -
2346} -
2347 -
2348#ifndef QT_NO_STYLE_STYLESHEET -
2349 -
2350/*! -
2351 \property QWidget::styleSheet -
2352 \brief the widget's style sheet -
2353 \since 4.2 -
2354 -
2355 The style sheet contains a textual description of customizations to the -
2356 widget's style, as described in the \l{Qt Style Sheets} document. -
2357 -
2358 Since Qt 4.5, Qt style sheets fully supports Mac OS X. -
2359 -
2360 \warning Qt style sheets are currently not supported for custom QStyle -
2361 subclasses. We plan to address this in some future release. -
2362 -
2363 \sa setStyle(), QApplication::styleSheet, {Qt Style Sheets} -
2364*/ -
2365QString QWidget::styleSheet() const -
2366{ -
2367 Q_D(const QWidget); -
2368 if (!d->extra) -
2369 return QString(); -
2370 return d->extra->styleSheet; -
2371} -
2372 -
2373void QWidget::setStyleSheet(const QString& styleSheet) -
2374{ -
2375 Q_D(QWidget); -
2376 d->createExtra(); -
2377 -
2378 QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(d->extra->style); -
2379 d->extra->styleSheet = styleSheet; -
2380 if (styleSheet.isEmpty()) { // stylesheet removed -
2381 if (!proxy) -
2382 return; -
2383 -
2384 d->inheritStyle(); -
2385 return; -
2386 } -
2387 -
2388 if (proxy) { // style sheet update -
2389 proxy->repolish(this); -
2390 return; -
2391 } -
2392 -
2393 if (testAttribute(Qt::WA_SetStyle)) { -
2394 d->setStyle_helper(new QStyleSheetStyle(d->extra->style), true); -
2395 } else { -
2396 d->setStyle_helper(new QStyleSheetStyle(0), true); -
2397 } -
2398} -
2399 -
2400#endif // QT_NO_STYLE_STYLESHEET -
2401 -
2402/*! -
2403 \sa QWidget::setStyle(), QApplication::setStyle(), QApplication::style() -
2404*/ -
2405 -
2406QStyle *QWidget::style() const -
2407{ -
2408 Q_D(const QWidget); -
2409 -
2410 if (d->extra && d->extra->style) -
2411 return d->extra->style; -
2412 return QApplication::style(); -
2413} -
2414 -
2415/*! -
2416 Sets the widget's GUI style to \a style. The ownership of the style -
2417 object is not transferred. -
2418 -
2419 If no style is set, the widget uses the application's style, -
2420 QApplication::style() instead. -
2421 -
2422 Setting a widget's style has no effect on existing or future child -
2423 widgets. -
2424 -
2425 \warning This function is particularly useful for demonstration -
2426 purposes, where you want to show Qt's styling capabilities. Real -
2427 applications should avoid it and use one consistent GUI style -
2428 instead. -
2429 -
2430 \warning Qt style sheets are currently not supported for custom QStyle -
2431 subclasses. We plan to address this in some future release. -
2432 -
2433 \sa style(), QStyle, QApplication::style(), QApplication::setStyle() -
2434*/ -
2435 -
2436void QWidget::setStyle(QStyle *style) -
2437{ -
2438 Q_D(QWidget); -
2439 setAttribute(Qt::WA_SetStyle, style != 0); -
2440 d->createExtra(); -
2441#ifndef QT_NO_STYLE_STYLESHEET -
2442 if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(style)) { -
2443 //if for some reason someone try to set a QStyleSheetStyle, ref it -
2444 //(this may happen for exemple in QButtonDialogBox which propagates its style) -
2445 proxy->ref(); -
2446 d->setStyle_helper(style, false); -
2447 } else if (qobject_cast<QStyleSheetStyle *>(d->extra->style) || !qApp->styleSheet().isEmpty()) { -
2448 // if we have an application stylesheet or have a proxy already, propagate -
2449 d->setStyle_helper(new QStyleSheetStyle(style), true); -
2450 } else -
2451#endif -
2452 d->setStyle_helper(style, false); -
2453} -
2454 -
2455void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate, bool -
2456#ifdef Q_WS_MAC -
2457 metalHack -
2458#endif -
2459 ) -
2460{ -
2461 Q_Q(QWidget); -
2462 QStyle *oldStyle = q->style(); -
2463#ifndef QT_NO_STYLE_STYLESHEET -
2464 QPointer<QStyle> origStyle; -
2465#endif -
2466 -
2467#ifdef Q_WS_MAC -
2468 // the metalhack boolean allows Qt/Mac to do a proper re-polish depending -
2469 // on how the Qt::WA_MacBrushedMetal attribute is set. It is only ever -
2470 // set when changing that attribute and passes the widget's CURRENT style. -
2471 // therefore no need to do a reassignment. -
2472 if (!metalHack) -
2473#endif -
2474 { -
2475 createExtra(); -
2476 -
2477#ifndef QT_NO_STYLE_STYLESHEET -
2478 origStyle = extra->style.data(); -
2479#endif -
2480 extra->style = newStyle; -
2481 } -
2482 -
2483 // repolish -
2484 if (q->windowType() != Qt::Desktop) { -
2485 if (polished) { -
2486 oldStyle->unpolish(q); -
2487#ifdef Q_WS_MAC -
2488 if (metalHack) -
2489 macUpdateMetalAttribute(); -
2490#endif -
2491 q->style()->polish(q); -
2492#ifdef Q_WS_MAC -
2493 } else if (metalHack) { -
2494 macUpdateMetalAttribute(); -
2495#endif -
2496 } -
2497 } -
2498 -
2499 if (propagate) { -
2500 // We copy the list because the order may be modified -
2501 const QObjectList childrenList = children; -
2502 for (int i = 0; i < childrenList.size(); ++i) { -
2503 QWidget *c = qobject_cast<QWidget*>(childrenList.at(i)); -
2504 if (c) -
2505 c->d_func()->inheritStyle(); -
2506 } -
2507 } -
2508 -
2509#ifndef QT_NO_STYLE_STYLESHEET -
2510 if (!qobject_cast<QStyleSheetStyle*>(newStyle)) { -
2511 if (const QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(origStyle.data())) { -
2512 cssStyle->clearWidgetFont(q); -
2513 } -
2514 } -
2515#endif -
2516 -
2517 QEvent e(QEvent::StyleChange); -
2518 QApplication::sendEvent(q, &e); -
2519 -
2520#ifndef QT_NO_STYLE_STYLESHEET -
2521 // dereference the old stylesheet style -
2522 if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(origStyle.data())) -
2523 proxy->deref(); -
2524#endif -
2525} -
2526 -
2527// Inherits style from the current parent and propagates it as necessary -
2528void QWidgetPrivate::inheritStyle() -
2529{ -
2530#ifndef QT_NO_STYLE_STYLESHEET -
2531 Q_Q(QWidget); -
2532 -
2533 QStyleSheetStyle *proxy = extra ? qobject_cast<QStyleSheetStyle *>(extra->style) : 0; -
2534 -
2535 if (!q->styleSheet().isEmpty()) { -
2536 Q_ASSERT(proxy); -
2537 proxy->repolish(q); -
2538 return; -
2539 } -
2540 -
2541 QStyle *origStyle = proxy ? proxy->base : (extra ? (QStyle*)extra->style : 0); -
2542 QWidget *parent = q->parentWidget(); -
2543 QStyle *parentStyle = (parent && parent->d_func()->extra) ? (QStyle*)parent->d_func()->extra->style : 0; -
2544 // If we have stylesheet on app or parent has stylesheet style, we need -
2545 // to be running a proxy -
2546 if (!qApp->styleSheet().isEmpty() || qobject_cast<QStyleSheetStyle *>(parentStyle)) { -
2547 QStyle *newStyle = parentStyle; -
2548 if (q->testAttribute(Qt::WA_SetStyle)) -
2549 newStyle = new QStyleSheetStyle(origStyle); -
2550 else if (QStyleSheetStyle *newProxy = qobject_cast<QStyleSheetStyle *>(parentStyle)) -
2551 newProxy->ref(); -
2552 -
2553 setStyle_helper(newStyle, true); -
2554 return; -
2555 } -
2556 -
2557 // So, we have no stylesheet on parent/app and we have an empty stylesheet -
2558 // we just need our original style back -
2559 if (origStyle == (extra ? (QStyle*)extra->style : 0)) // is it any different? -
2560 return; -
2561 -
2562 // We could have inherited the proxy from our parent (which has a custom style) -
2563 // In such a case we need to start following the application style (i.e revert -
2564 // the propagation behavior of QStyleSheetStyle) -
2565 if (!q->testAttribute(Qt::WA_SetStyle)) -
2566 origStyle = 0; -
2567 -
2568 setStyle_helper(origStyle, true); -
2569#endif // QT_NO_STYLE_STYLESHEET -
2570} -
2571 -
2572 -
2573/*! -
2574 \fn bool QWidget::isWindow() const -
2575 -
2576 Returns true if the widget is an independent window, otherwise -
2577 returns false. -
2578 -
2579 A window is a widget that isn't visually the child of any other -
2580 widget and that usually has a frame and a -
2581 \l{QWidget::setWindowTitle()}{window title}. -
2582 -
2583 A window can have a \l{QWidget::parentWidget()}{parent widget}. -
2584 It will then be grouped with its parent and deleted when the -
2585 parent is deleted, minimized when the parent is minimized etc. If -
2586 supported by the window manager, it will also have a common -
2587 taskbar entry with its parent. -
2588 -
2589 QDialog and QMainWindow widgets are by default windows, even if a -
2590 parent widget is specified in the constructor. This behavior is -
2591 specified by the Qt::Window flag. -
2592 -
2593 \sa window(), isModal(), parentWidget() -
2594*/ -
2595 -
2596/*! -
2597 \property QWidget::modal -
2598 \brief whether the widget is a modal widget -
2599 -
2600 This property only makes sense for windows. A modal widget -
2601 prevents widgets in all other windows from getting any input. -
2602 -
2603 By default, this property is false. -
2604 -
2605 \sa isWindow(), windowModality, QDialog -
2606*/ -
2607 -
2608/*! -
2609 \property QWidget::windowModality -
2610 \brief which windows are blocked by the modal widget -
2611 \since 4.1 -
2612 -
2613 This property only makes sense for windows. A modal widget -
2614 prevents widgets in other windows from getting input. The value of -
2615 this property controls which windows are blocked when the widget -
2616 is visible. Changing this property while the window is visible has -
2617 no effect; you must hide() the widget first, then show() it again. -
2618 -
2619 By default, this property is Qt::NonModal. -
2620 -
2621 \sa isWindow(), QWidget::modal, QDialog -
2622*/ -
2623 -
2624Qt::WindowModality QWidget::windowModality() const -
2625{ -
2626 return static_cast<Qt::WindowModality>(data->window_modality); -
2627} -
2628 -
2629void QWidget::setWindowModality(Qt::WindowModality windowModality) -
2630{ -
2631 data->window_modality = windowModality; -
2632 // setModal_sys() will be called by setAttribute() -
2633 setAttribute(Qt::WA_ShowModal, (data->window_modality != Qt::NonModal)); -
2634 setAttribute(Qt::WA_SetWindowModality, true); -
2635} -
2636 -
2637/*! -
2638 \fn bool QWidget::underMouse() const -
2639 -
2640 Returns true if the widget is under the mouse cursor; otherwise -
2641 returns false. -
2642 -
2643 This value is not updated properly during drag and drop -
2644 operations. -
2645 -
2646 \sa enterEvent(), leaveEvent() -
2647*/ -
2648 -
2649/*! -
2650 \property QWidget::minimized -
2651 \brief whether this widget is minimized (iconified) -
2652 -
2653 This property is only relevant for windows. -
2654 -
2655 By default, this property is false. -
2656 -
2657 \sa showMinimized(), visible, show(), hide(), showNormal(), maximized -
2658*/ -
2659bool QWidget::isMinimized() const -
2660{ return data->window_state & Qt::WindowMinimized; } -
2661 -
2662/*! -
2663 Shows the widget minimized, as an icon. -
2664 -
2665 Calling this function only affects \l{isWindow()}{windows}. -
2666 -
2667 \sa showNormal(), showMaximized(), show(), hide(), isVisible(), -
2668 isMinimized() -
2669*/ -
2670void QWidget::showMinimized() -
2671{ -
2672 bool isMin = isMinimized(); -
2673 if (isMin && isVisible()) -
2674 return; -
2675 -
2676 ensurePolished(); -
2677 -
2678 if (!isMin) -
2679 setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized); -
2680 setVisible(true); -
2681} -
2682 -
2683/*! -
2684 \property QWidget::maximized -
2685 \brief whether this widget is maximized -
2686 -
2687 This property is only relevant for windows. -
2688 -
2689 \note Due to limitations on some window systems, this does not always -
2690 report the expected results (e.g., if the user on X11 maximizes the -
2691 window via the window manager, Qt has no way of distinguishing this -
2692 from any other resize). This is expected to improve as window manager -
2693 protocols evolve. -
2694 -
2695 By default, this property is false. -
2696 -
2697 \sa windowState(), showMaximized(), visible, show(), hide(), showNormal(), minimized -
2698*/ -
2699bool QWidget::isMaximized() const -
2700{ return data->window_state & Qt::WindowMaximized; } -
2701 -
2702 -
2703 -
2704/*! -
2705 Returns the current window state. The window state is a OR'ed -
2706 combination of Qt::WindowState: Qt::WindowMinimized, -
2707 Qt::WindowMaximized, Qt::WindowFullScreen, and Qt::WindowActive. -
2708 -
2709 \sa Qt::WindowState, setWindowState() -
2710 */ -
2711Qt::WindowStates QWidget::windowState() const -
2712{ -
2713 return Qt::WindowStates(data->window_state); -
2714} -
2715 -
2716/*!\internal -
2717 -
2718 The function sets the window state on child widgets similar to -
2719 setWindowState(). The difference is that the window state changed -
2720 event has the isOverride() flag set. It exists mainly to keep -
2721 QWorkspace working. -
2722 */ -
2723void QWidget::overrideWindowState(Qt::WindowStates newstate) -
2724{ -
2725 QWindowStateChangeEvent e(Qt::WindowStates(data->window_state), true); -
2726 data->window_state = newstate; -
2727 QApplication::sendEvent(this, &e); -
2728} -
2729 -
2730/*! -
2731 \fn void QWidget::setWindowState(Qt::WindowStates windowState) -
2732 -
2733 Sets the window state to \a windowState. The window state is a OR'ed -
2734 combination of Qt::WindowState: Qt::WindowMinimized, -
2735 Qt::WindowMaximized, Qt::WindowFullScreen, and Qt::WindowActive. -
2736 -
2737 If the window is not visible (i.e. isVisible() returns false), the -
2738 window state will take effect when show() is called. For visible -
2739 windows, the change is immediate. For example, to toggle between -
2740 full-screen and normal mode, use the following code: -
2741 -
2742 \snippet code/src_gui_kernel_qwidget.cpp 0 -
2743 -
2744 In order to restore and activate a minimized window (while -
2745 preserving its maximized and/or full-screen state), use the following: -
2746 -
2747 \snippet code/src_gui_kernel_qwidget.cpp 1 -
2748 -
2749 Calling this function will hide the widget. You must call show() to make -
2750 the widget visible again. -
2751 -
2752 \note On some window systems Qt::WindowActive is not immediate, and may be -
2753 ignored in certain cases. -
2754 -
2755 When the window state changes, the widget receives a changeEvent() -
2756 of type QEvent::WindowStateChange. -
2757 -
2758 \sa Qt::WindowState, windowState() -
2759*/ -
2760 -
2761/*! -
2762 \property QWidget::fullScreen -
2763 \brief whether the widget is shown in full screen mode -
2764 -
2765 A widget in full screen mode occupies the whole screen area and does not -
2766 display window decorations, such as a title bar. -
2767 -
2768 By default, this property is false. -
2769 -
2770 \sa windowState(), minimized, maximized -
2771*/ -
2772bool QWidget::isFullScreen() const -
2773{ return data->window_state & Qt::WindowFullScreen; } -
2774 -
2775/*! -
2776 Shows the widget in full-screen mode. -
2777 -
2778 Calling this function only affects \l{isWindow()}{windows}. -
2779 -
2780 To return from full-screen mode, call showNormal(). -
2781 -
2782 Full-screen mode works fine under Windows, but has certain -
2783 problems under X. These problems are due to limitations of the -
2784 ICCCM protocol that specifies the communication between X11 -
2785 clients and the window manager. ICCCM simply does not understand -
2786 the concept of non-decorated full-screen windows. Therefore, the -
2787 best we can do is to request a borderless window and place and -
2788 resize it to fill the entire screen. Depending on the window -
2789 manager, this may or may not work. The borderless window is -
2790 requested using MOTIF hints, which are at least partially -
2791 supported by virtually all modern window managers. -
2792 -
2793 An alternative would be to bypass the window manager entirely and -
2794 create a window with the Qt::X11BypassWindowManagerHint flag. This -
2795 has other severe problems though, like totally broken keyboard focus -
2796 and very strange effects on desktop changes or when the user raises -
2797 other windows. -
2798 -
2799 X11 window managers that follow modern post-ICCCM specifications -
2800 support full-screen mode properly. -
2801 -
2802 \sa showNormal(), showMaximized(), show(), hide(), isVisible() -
2803*/ -
2804void QWidget::showFullScreen() -
2805{ -
2806#ifdef Q_WS_MAC -
2807 // If the unified toolbar is enabled, we have to disable it before going fullscreen. -
2808 QMainWindow *mainWindow = qobject_cast<QMainWindow*>(this); -
2809 if (mainWindow && mainWindow->unifiedTitleAndToolBarOnMac()) { -
2810 mainWindow->setUnifiedTitleAndToolBarOnMac(false); -
2811 QMainWindowLayout *mainLayout = qobject_cast<QMainWindowLayout*>(mainWindow->layout()); -
2812 mainLayout->activateUnifiedToolbarAfterFullScreen = true; -
2813 } -
2814#endif // Q_WS_MAC -
2815 ensurePolished(); -
2816 -
2817 setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowMaximized)) -
2818 | Qt::WindowFullScreen); -
2819 setVisible(true); -
2820 activateWindow(); -
2821} -
2822 -
2823/*! -
2824 Shows the widget maximized. -
2825 -
2826 Calling this function only affects \l{isWindow()}{windows}. -
2827 -
2828 On X11, this function may not work properly with certain window -
2829 managers. See the \l{Window Geometry} documentation for an explanation. -
2830 -
2831 \sa setWindowState(), showNormal(), showMinimized(), show(), hide(), isVisible() -
2832*/ -
2833void QWidget::showMaximized() -
2834{ -
2835 ensurePolished(); -
2836 -
2837 setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen)) -
2838 | Qt::WindowMaximized); -
2839#ifdef Q_WS_MAC -
2840 // If the unified toolbar was enabled before going fullscreen, we have to enable it back. -
2841 QMainWindow *mainWindow = qobject_cast<QMainWindow*>(this); -
2842 if (mainWindow) -
2843 { -
2844 QMainWindowLayout *mainLayout = qobject_cast<QMainWindowLayout*>(mainWindow->layout()); -
2845 if (mainLayout->activateUnifiedToolbarAfterFullScreen) { -
2846 mainWindow->setUnifiedTitleAndToolBarOnMac(true); -
2847 mainLayout->activateUnifiedToolbarAfterFullScreen = false; -
2848 } -
2849 } -
2850#endif // Q_WS_MAC -
2851 setVisible(true); -
2852} -
2853 -
2854/*! -
2855 Restores the widget after it has been maximized or minimized. -
2856 -
2857 Calling this function only affects \l{isWindow()}{windows}. -
2858 -
2859 \sa setWindowState(), showMinimized(), showMaximized(), show(), hide(), isVisible() -
2860*/ -
2861void QWidget::showNormal() -
2862{ -
2863 ensurePolished(); -
2864 -
2865 setWindowState(windowState() & ~(Qt::WindowMinimized -
2866 | Qt::WindowMaximized -
2867 | Qt::WindowFullScreen)); -
2868#ifdef Q_WS_MAC -
2869 // If the unified toolbar was enabled before going fullscreen, we have to enable it back. -
2870 QMainWindow *mainWindow = qobject_cast<QMainWindow*>(this); -
2871 if (mainWindow) -
2872 { -
2873 QMainWindowLayout *mainLayout = qobject_cast<QMainWindowLayout*>(mainWindow->layout()); -
2874 if (mainLayout->activateUnifiedToolbarAfterFullScreen) { -
2875 mainWindow->setUnifiedTitleAndToolBarOnMac(true); -
2876 mainLayout->activateUnifiedToolbarAfterFullScreen = false; -
2877 } -
2878 } -
2879#endif // Q_WS_MAC -
2880 setVisible(true); -
2881} -
2882 -
2883/*! -
2884 Returns true if this widget would become enabled if \a ancestor is -
2885 enabled; otherwise returns false. -
2886 -
2887 -
2888 -
2889 This is the case if neither the widget itself nor every parent up -
2890 to but excluding \a ancestor has been explicitly disabled. -
2891 -
2892 isEnabledTo(0) is equivalent to isEnabled(). -
2893 -
2894 \sa setEnabled(), enabled -
2895*/ -
2896 -
2897bool QWidget::isEnabledTo(const QWidget *ancestor) const -
2898{ -
2899 const QWidget * w = this; -
2900 while (!w->testAttribute(Qt::WA_ForceDisabled) -
2901 && !w->isWindow() -
2902 && w->parentWidget() -
2903 && w->parentWidget() != ancestor) -
2904 w = w->parentWidget(); -
2905 return !w->testAttribute(Qt::WA_ForceDisabled); -
2906} -
2907 -
2908#ifndef QT_NO_ACTION -
2909/*! -
2910 Appends the action \a action to this widget's list of actions. -
2911 -
2912 All QWidgets have a list of \l{QAction}s, however they can be -
2913 represented graphically in many different ways. The default use of -
2914 the QAction list (as returned by actions()) is to create a context -
2915 QMenu. -
2916 -
2917 A QWidget should only have one of each action and adding an action -
2918 it already has will not cause the same action to be in the widget twice. -
2919 -
2920 The ownership of \a action is not transferred to this QWidget. -
2921 -
2922 \sa removeAction(), insertAction(), actions(), QMenu -
2923*/ -
2924void QWidget::addAction(QAction *action) -
2925{ -
2926 insertAction(0, action); -
2927} -
2928 -
2929/*! -
2930 Appends the actions \a actions to this widget's list of actions. -
2931 -
2932 \sa removeAction(), QMenu, addAction() -
2933*/ -
2934void QWidget::addActions(QList<QAction*> actions) -
2935{ -
2936 for(int i = 0; i < actions.count(); i++) -
2937 insertAction(0, actions.at(i)); -
2938} -
2939 -
2940/*! -
2941 Inserts the action \a action to this widget's list of actions, -
2942 before the action \a before. It appends the action if \a before is 0 or -
2943 \a before is not a valid action for this widget. -
2944 -
2945 A QWidget should only have one of each action. -
2946 -
2947 \sa removeAction(), addAction(), QMenu, contextMenuPolicy, actions() -
2948*/ -
2949void QWidget::insertAction(QAction *before, QAction *action) -
2950{ -
2951 if(!action) { -
2952 qWarning("QWidget::insertAction: Attempt to insert null action"); -
2953 return; -
2954 } -
2955 -
2956 Q_D(QWidget); -
2957 if(d->actions.contains(action)) -
2958 removeAction(action); -
2959 -
2960 int pos = d->actions.indexOf(before); -
2961 if (pos < 0) { -
2962 before = 0; -
2963 pos = d->actions.size(); -
2964 } -
2965 d->actions.insert(pos, action); -
2966 -
2967 QActionPrivate *apriv = action->d_func(); -
2968 apriv->widgets.append(this); -
2969 -
2970 QActionEvent e(QEvent::ActionAdded, action, before); -
2971 QApplication::sendEvent(this, &e); -
2972} -
2973 -
2974/*! -
2975 Inserts the actions \a actions to this widget's list of actions, -
2976 before the action \a before. It appends the action if \a before is 0 or -
2977 \a before is not a valid action for this widget. -
2978 -
2979 A QWidget can have at most one of each action. -
2980 -
2981 \sa removeAction(), QMenu, insertAction(), contextMenuPolicy -
2982*/ -
2983void QWidget::insertActions(QAction *before, QList<QAction*> actions) -
2984{ -
2985 for(int i = 0; i < actions.count(); ++i) -
2986 insertAction(before, actions.at(i)); -
2987} -
2988 -
2989/*! -
2990 Removes the action \a action from this widget's list of actions. -
2991 \sa insertAction(), actions(), insertAction() -
2992*/ -
2993void QWidget::removeAction(QAction *action) -
2994{ -
2995 if (!action) -
2996 return; -
2997 -
2998 Q_D(QWidget); -
2999 -
3000 QActionPrivate *apriv = action->d_func(); -
3001 apriv->widgets.removeAll(this); -
3002 -
3003 if (d->actions.removeAll(action)) { -
3004 QActionEvent e(QEvent::ActionRemoved, action); -
3005 QApplication::sendEvent(this, &e); -
3006 } -
3007} -
3008 -
3009/*! -
3010 Returns the (possibly empty) list of this widget's actions. -
3011 -
3012 \sa contextMenuPolicy, insertAction(), removeAction() -
3013*/ -
3014QList<QAction*> QWidget::actions() const -
3015{ -
3016 Q_D(const QWidget); -
3017 return d->actions; -
3018} -
3019#endif // QT_NO_ACTION -
3020 -
3021/*! -
3022 \fn bool QWidget::isEnabledToTLW() const -
3023 \obsolete -
3024 -
3025 This function is deprecated. It is equivalent to isEnabled() -
3026*/ -
3027 -
3028/*! -
3029 \property QWidget::enabled -
3030 \brief whether the widget is enabled -
3031 -
3032 In general an enabled widget handles keyboard and mouse events; a disabled -
3033 widget does not. An exception is made with \l{QAbstractButton}. -
3034 -
3035 Some widgets display themselves differently when they are -
3036 disabled. For example a button might draw its label grayed out. If -
3037 your widget needs to know when it becomes enabled or disabled, you -
3038 can use the changeEvent() with type QEvent::EnabledChange. -
3039 -
3040 Disabling a widget implicitly disables all its children. Enabling -
3041 respectively enables all child widgets unless they have been -
3042 explicitly disabled. -
3043 -
3044 By default, this property is true. -
3045 -
3046 \sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent() -
3047*/ -
3048void QWidget::setEnabled(bool enable) -
3049{ -
3050 Q_D(QWidget); -
3051 setAttribute(Qt::WA_ForceDisabled, !enable); -
3052 d->setEnabled_helper(enable); -
3053} -
3054 -
3055void QWidgetPrivate::setEnabled_helper(bool enable) -
3056{ -
3057 Q_Q(QWidget); -
3058 -
3059 if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->isEnabled()) -
3060 return; // nothing we can do -
3061 -
3062 if (enable != q->testAttribute(Qt::WA_Disabled)) -
3063 return; // nothing to do -
3064 -
3065 q->setAttribute(Qt::WA_Disabled, !enable); -
3066 updateSystemBackground(); -
3067 -
3068 if (!enable && q->window()->focusWidget() == q) { -
3069 bool parentIsEnabled = (!q->parentWidget() || q->parentWidget()->isEnabled()); -
3070 if (!parentIsEnabled || !q->focusNextChild()) -
3071 q->clearFocus(); -
3072 } -
3073 -
3074 Qt::WidgetAttribute attribute = enable ? Qt::WA_ForceDisabled : Qt::WA_Disabled; -
3075 for (int i = 0; i < children.size(); ++i) { -
3076 QWidget *w = qobject_cast<QWidget *>(children.at(i)); -
3077 if (w && !w->testAttribute(attribute)) -
3078 w->d_func()->setEnabled_helper(enable); -
3079 } -
3080#if defined(Q_WS_X11) -
3081 if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) { -
3082 // enforce the windows behavior of clearing the cursor on -
3083 // disabled widgets -
3084 qt_x11_enforce_cursor(q); -
3085 } -
3086#endif -
3087#ifndef QT_NO_CURSOR -
3088 if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) { -
3089 // enforce the windows behavior of clearing the cursor on -
3090 // disabled widgets -
3091 qt_qpa_set_cursor(q, false); -
3092 } -
3093#endif -
3094#if defined(Q_WS_MAC) -
3095 setEnabled_helper_sys(enable); -
3096#endif -
3097#ifndef QT_NO_IM -
3098 if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) { -
3099 QWidget *focusWidget = effectiveFocusWidget(); -
3100 -
3101 if (enable) { -
3102 if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) -
3103 qApp->inputMethod()->update(Qt::ImEnabled); -
3104 } else { -
3105 qApp->inputMethod()->commit(); -
3106 qApp->inputMethod()->update(Qt::ImEnabled); -
3107 } -
3108 } -
3109#endif //QT_NO_IM -
3110 QEvent e(QEvent::EnabledChange); -
3111 QApplication::sendEvent(q, &e); -
3112} -
3113 -
3114/*! -
3115 \property QWidget::acceptDrops -
3116 \brief whether drop events are enabled for this widget -
3117 -
3118 Setting this property to true announces to the system that this -
3119 widget \e may be able to accept drop events. -
3120 -
3121 If the widget is the desktop (windowType() == Qt::Desktop), this may -
3122 fail if another application is using the desktop; you can call -
3123 acceptDrops() to test if this occurs. -
3124 -
3125 \warning Do not modify this property in a drag and drop event handler. -
3126 -
3127 By default, this property is false. -
3128 -
3129 \sa {Drag and Drop} -
3130*/ -
3131bool QWidget::acceptDrops() const -
3132{ -
3133 return testAttribute(Qt::WA_AcceptDrops); -
3134} -
3135 -
3136void QWidget::setAcceptDrops(bool on) -
3137{ -
3138 setAttribute(Qt::WA_AcceptDrops, on); -
3139 -
3140} -
3141 -
3142 -
3143/*! -
3144 Disables widget input events if \a disable is true; otherwise -
3145 enables input events. -
3146 -
3147 See the \l enabled documentation for more information. -
3148 -
3149 \sa isEnabledTo(), QKeyEvent, QMouseEvent, changeEvent() -
3150*/ -
3151void QWidget::setDisabled(bool disable) -
3152{ -
3153 setEnabled(!disable); -
3154} -
3155 -
3156/*! -
3157 \property QWidget::frameGeometry -
3158 \brief geometry of the widget relative to its parent including any -
3159 window frame -
3160 -
3161 See the \l{Window Geometry} documentation for an overview of geometry -
3162 issues with windows. -
3163 -
3164 By default, this property contains a value that depends on the user's -
3165 platform and screen geometry. -
3166 -
3167 \sa geometry(), x(), y(), pos() -
3168*/ -
3169QRect QWidget::frameGeometry() const -
3170{ -
3171 Q_D(const QWidget); -
3172 if (isWindow() && ! (windowType() == Qt::Popup)) { -
3173 QRect fs = d->frameStrut(); -
3174 return QRect(data->crect.x() - fs.left(), -
3175 data->crect.y() - fs.top(), -
3176 data->crect.width() + fs.left() + fs.right(), -
3177 data->crect.height() + fs.top() + fs.bottom()); -
3178 } -
3179 return data->crect; -
3180} -
3181 -
3182/*! -
3183 \property QWidget::x -
3184 -
3185 \brief the x coordinate of the widget relative to its parent including -
3186 any window frame -
3187 -
3188 See the \l{Window Geometry} documentation for an overview of geometry -
3189 issues with windows. -
3190 -
3191 By default, this property has a value of 0. -
3192 -
3193 \sa frameGeometry, y, pos -
3194*/ -
3195int QWidget::x() const -
3196{ -
3197 Q_D(const QWidget); -
3198 if (isWindow() && ! (windowType() == Qt::Popup)) -
3199 return data->crect.x() - d->frameStrut().left(); -
3200 return data->crect.x(); -
3201} -
3202 -
3203/*! -
3204 \property QWidget::y -
3205 \brief the y coordinate of the widget relative to its parent and -
3206 including any window frame -
3207 -
3208 See the \l{Window Geometry} documentation for an overview of geometry -
3209 issues with windows. -
3210 -
3211 By default, this property has a value of 0. -
3212 -
3213 \sa frameGeometry, x, pos -
3214*/ -
3215int QWidget::y() const -
3216{ -
3217 Q_D(const QWidget); -
3218 if (isWindow() && ! (windowType() == Qt::Popup)) -
3219 return data->crect.y() - d->frameStrut().top(); -
3220 return data->crect.y(); -
3221} -
3222 -
3223/*! -
3224 \property QWidget::pos -
3225 \brief the position of the widget within its parent widget -
3226 -
3227 If the widget is a window, the position is that of the widget on -
3228 the desktop, including its frame. -
3229 -
3230 When changing the position, the widget, if visible, receives a -
3231 move event (moveEvent()) immediately. If the widget is not -
3232 currently visible, it is guaranteed to receive an event before it -
3233 is shown. -
3234 -
3235 By default, this property contains a position that refers to the -
3236 origin. -
3237 -
3238 \warning Calling move() or setGeometry() inside moveEvent() can -
3239 lead to infinite recursion. -
3240 -
3241 See the \l{Window Geometry} documentation for an overview of geometry -
3242 issues with windows. -
3243 -
3244 \sa frameGeometry, size, x(), y() -
3245*/ -
3246QPoint QWidget::pos() const -
3247{ -
3248 Q_D(const QWidget); -
3249 QPoint result = data->crect.topLeft(); -
3250 if (isWindow() && ! (windowType() == Qt::Popup)) -
3251 if (!d->maybeTopData() || !d->maybeTopData()->posIncludesFrame) -
3252 result -= d->frameStrut().topLeft(); -
3253 return result; -
3254} -
3255 -
3256/*! -
3257 \property QWidget::geometry -
3258 \brief the geometry of the widget relative to its parent and -
3259 excluding the window frame -
3260 -
3261 When changing the geometry, the widget, if visible, receives a -
3262 move event (moveEvent()) and/or a resize event (resizeEvent()) -
3263 immediately. If the widget is not currently visible, it is -
3264 guaranteed to receive appropriate events before it is shown. -
3265 -
3266 The size component is adjusted if it lies outside the range -
3267 defined by minimumSize() and maximumSize(). -
3268 -
3269 \warning Calling setGeometry() inside resizeEvent() or moveEvent() -
3270 can lead to infinite recursion. -
3271 -
3272 See the \l{Window Geometry} documentation for an overview of geometry -
3273 issues with windows. -
3274 -
3275 By default, this property contains a value that depends on the user's -
3276 platform and screen geometry. -
3277 -
3278 \sa frameGeometry(), rect(), move(), resize(), moveEvent(), -
3279 resizeEvent(), minimumSize(), maximumSize() -
3280*/ -
3281 -
3282/*! -
3283 \property QWidget::normalGeometry -
3284 -
3285 \brief the geometry of the widget as it will appear when shown as -
3286 a normal (not maximized or full screen) top-level widget -
3287 -
3288 For child widgets this property always holds an empty rectangle. -
3289 -
3290 By default, this property contains an empty rectangle. -
3291 -
3292 \sa QWidget::windowState(), QWidget::geometry -
3293*/ -
3294 -
3295/*! -
3296 \property QWidget::size -
3297 \brief the size of the widget excluding any window frame -
3298 -
3299 If the widget is visible when it is being resized, it receives a resize event -
3300 (resizeEvent()) immediately. If the widget is not currently -
3301 visible, it is guaranteed to receive an event before it is shown. -
3302 -
3303 The size is adjusted if it lies outside the range defined by -
3304 minimumSize() and maximumSize(). -
3305 -
3306 By default, this property contains a value that depends on the user's -
3307 platform and screen geometry. -
3308 -
3309 \warning Calling resize() or setGeometry() inside resizeEvent() can -
3310 lead to infinite recursion. -
3311 -
3312 \note Setting the size to \c{QSize(0, 0)} will cause the widget to not -
3313 appear on screen. This also applies to windows. -
3314 -
3315 \sa pos, geometry, minimumSize, maximumSize, resizeEvent(), adjustSize() -
3316*/ -
3317 -
3318/*! -
3319 \property QWidget::width -
3320 \brief the width of the widget excluding any window frame -
3321 -
3322 See the \l{Window Geometry} documentation for an overview of geometry -
3323 issues with windows. -
3324 -
3325 \note Do not use this function to find the width of a screen on -
3326 a \l{QDesktopWidget}{multiple screen desktop}. Read -
3327 \l{QDesktopWidget#Screen Geometry}{this note} for details. -
3328 -
3329 By default, this property contains a value that depends on the user's -
3330 platform and screen geometry. -
3331 -
3332 \sa geometry, height, size -
3333*/ -
3334 -
3335/*! -
3336 \property QWidget::height -
3337 \brief the height 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 height of a screen -
3343 on 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, width, size -
3350*/ -
3351 -
3352/*! -
3353 \property QWidget::rect -
3354 \brief the internal geometry of the widget excluding any window -
3355 frame -
3356 -
3357 The rect property equals QRect(0, 0, width(), height()). -
3358 -
3359 See the \l{Window Geometry} documentation for an overview of geometry -
3360 issues with windows. -
3361 -
3362 By default, this property contains a value that depends on the user's -
3363 platform and screen geometry. -
3364 -
3365 \sa size -
3366*/ -
3367 -
3368 -
3369QRect QWidget::normalGeometry() const -
3370{ -
3371 Q_D(const QWidget); -
3372 if (!d->extra || !d->extra->topextra) -
3373 return QRect(); -
3374 -
3375 if (!isMaximized() && !isFullScreen()) -
3376 return geometry(); -
3377 -
3378 return d->topData()->normalGeometry; -
3379} -
3380 -
3381 -
3382/*! -
3383 \property QWidget::childrenRect -
3384 \brief the bounding rectangle of the widget's children -
3385 -
3386 Hidden children are excluded. -
3387 -
3388 By default, for a widget with no children, this property contains a -
3389 rectangle with zero width and height located at the origin. -
3390 -
3391 \sa childrenRegion(), geometry() -
3392*/ -
3393 -
3394QRect QWidget::childrenRect() const -
3395{ -
3396 Q_D(const QWidget); -
3397 QRect r(0, 0, 0, 0); -
3398 for (int i = 0; i < d->children.size(); ++i) { -
3399 QWidget *w = qobject_cast<QWidget *>(d->children.at(i)); -
3400 if (w && !w->isWindow() && !w->isHidden()) -
3401 r |= w->geometry(); -
3402 } -
3403 return r; -
3404} -
3405 -
3406/*! -
3407 \property QWidget::childrenRegion -
3408 \brief the combined region occupied by the widget's children -
3409 -
3410 Hidden children are excluded. -
3411 -
3412 By default, for a widget with no children, this property contains an -
3413 empty region. -
3414 -
3415 \sa childrenRect(), geometry(), mask() -
3416*/ -
3417 -
3418QRegion QWidget::childrenRegion() const -
3419{ -
3420 Q_D(const QWidget); -
3421 QRegion r; -
3422 for (int i = 0; i < d->children.size(); ++i) { -
3423 QWidget *w = qobject_cast<QWidget *>(d->children.at(i)); -
3424 if (w && !w->isWindow() && !w->isHidden()) { -
3425 QRegion mask = w->mask(); -
3426 if (mask.isEmpty()) -
3427 r |= w->geometry(); -
3428 else -
3429 r |= mask.translated(w->pos()); -
3430 } -
3431 } -
3432 return r; -
3433} -
3434 -
3435 -
3436/*! -
3437 \property QWidget::minimumSize -
3438 \brief the widget's minimum size -
3439 -
3440 The widget cannot be resized to a smaller size than the minimum -
3441 widget size. The widget's size is forced to the minimum size if -
3442 the current size is smaller. -
3443 -
3444 The minimum size set by this function will override the minimum size -
3445 defined by QLayout. In order to unset the minimum size, use a -
3446 value of \c{QSize(0, 0)}. -
3447 -
3448 By default, this property contains a size with zero width and height. -
3449 -
3450 \sa minimumWidth, minimumHeight, maximumSize, sizeIncrement -
3451*/ -
3452 -
3453QSize QWidget::minimumSize() const -
3454{ -
3455 Q_D(const QWidget); -
3456 return d->extra ? QSize(d->extra->minw, d->extra->minh) : QSize(0, 0); -
3457} -
3458 -
3459/*! -
3460 \property QWidget::maximumSize -
3461 \brief the widget's maximum size in pixels -
3462 -
3463 The widget cannot be resized to a larger size than the maximum -
3464 widget size. -
3465 -
3466 By default, this property contains a size in which both width and height -
3467 have values of 16777215. -
3468 -
3469 \note The definition of the \c QWIDGETSIZE_MAX macro limits the maximum size -
3470 of widgets. -
3471 -
3472 \sa maximumWidth, maximumHeight, minimumSize, sizeIncrement -
3473*/ -
3474 -
3475QSize QWidget::maximumSize() const -
3476{ -
3477 Q_D(const QWidget); -
3478 return d->extra ? QSize(d->extra->maxw, d->extra->maxh) -
3479 : QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); -
3480} -
3481 -
3482 -
3483/*! -
3484 \property QWidget::minimumWidth -
3485 \brief the widget's minimum width in pixels -
3486 -
3487 This property corresponds to the width held by the \l minimumSize property. -
3488 -
3489 By default, this property has a value of 0. -
3490 -
3491 \sa minimumSize, minimumHeight -
3492*/ -
3493 -
3494/*! -
3495 \property QWidget::minimumHeight -
3496 \brief the widget's minimum height in pixels -
3497 -
3498 This property corresponds to the height held by the \l minimumSize property. -
3499 -
3500 By default, this property has a value of 0. -
3501 -
3502 \sa minimumSize, minimumWidth -
3503*/ -
3504 -
3505/*! -
3506 \property QWidget::maximumWidth -
3507 \brief the widget's maximum width in pixels -
3508 -
3509 This property corresponds to the width held by the \l maximumSize property. -
3510 -
3511 By default, this property contains a value of 16777215. -
3512 -
3513 \note The definition of the \c QWIDGETSIZE_MAX macro limits the maximum size -
3514 of widgets. -
3515 -
3516 \sa maximumSize, maximumHeight -
3517*/ -
3518 -
3519/*! -
3520 \property QWidget::maximumHeight -
3521 \brief the widget's maximum height in pixels -
3522 -
3523 This property corresponds to the height held by the \l maximumSize property. -
3524 -
3525 By default, this property contains a value of 16777215. -
3526 -
3527 \note The definition of the \c QWIDGETSIZE_MAX macro limits the maximum size -
3528 of widgets. -
3529 -
3530 \sa maximumSize, maximumWidth -
3531*/ -
3532 -
3533/*! -
3534 \property QWidget::sizeIncrement -
3535 \brief the size increment of the widget -
3536 -
3537 When the user resizes the window, the size will move in steps of -
3538 sizeIncrement().width() pixels horizontally and -
3539 sizeIncrement.height() pixels vertically, with baseSize() as the -
3540 basis. Preferred widget sizes are for non-negative integers \e i -
3541 and \e j: -
3542 \snippet code/src_gui_kernel_qwidget.cpp 2 -
3543 -
3544 Note that while you can set the size increment for all widgets, it -
3545 only affects windows. -
3546 -
3547 By default, this property contains a size with zero width and height. -
3548 -
3549 \warning The size increment has no effect under Windows, and may -
3550 be disregarded by the window manager on X11. -
3551 -
3552 \sa size, minimumSize, maximumSize -
3553*/ -
3554QSize QWidget::sizeIncrement() const -
3555{ -
3556 Q_D(const QWidget); -
3557 return (d->extra && d->extra->topextra) -
3558 ? QSize(d->extra->topextra->incw, d->extra->topextra->inch) -
3559 : QSize(0, 0); -
3560} -
3561 -
3562/*! -
3563 \property QWidget::baseSize -
3564 \brief the base size of the widget -
3565 -
3566 The base size is used to calculate a proper widget size if the -
3567 widget defines sizeIncrement(). -
3568 -
3569 By default, for a newly-created widget, this property contains a size with -
3570 zero width and height. -
3571 -
3572 \sa setSizeIncrement() -
3573*/ -
3574 -
3575QSize QWidget::baseSize() const -
3576{ -
3577 Q_D(const QWidget); -
3578 return (d->extra != 0 && d->extra->topextra != 0) -
3579 ? QSize(d->extra->topextra->basew, d->extra->topextra->baseh) -
3580 : QSize(0, 0); -
3581} -
3582 -
3583bool QWidgetPrivate::setMinimumSize_helper(int &minw, int &minh) -
3584{ -
3585 Q_Q(QWidget); -
3586 -
3587 int mw = minw, mh = minh; -
3588 if (mw == QWIDGETSIZE_MAX) -
3589 mw = 0; -
3590 if (mh == QWIDGETSIZE_MAX) -
3591 mh = 0; -
3592 if (minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX) { -
3593 qWarning("QWidget::setMinimumSize: (%s/%s) " -
3594 "The largest allowed size is (%d,%d)", -
3595 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX, -
3596 QWIDGETSIZE_MAX); -
3597 minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX); -
3598 minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX); -
3599 } -
3600 if (minw < 0 || minh < 0) { -
3601 qWarning("QWidget::setMinimumSize: (%s/%s) Negative sizes (%d,%d) " -
3602 "are not possible", -
3603 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh); -
3604 minw = mw = qMax(minw, 0); -
3605 minh = mh = qMax(minh, 0); -
3606 } -
3607 createExtra(); -
3608 if (extra->minw == mw && extra->minh == mh) -
3609 return false; -
3610 extra->minw = mw; -
3611 extra->minh = mh; -
3612 extra->explicitMinSize = (mw ? Qt::Horizontal : 0) | (mh ? Qt::Vertical : 0); -
3613 return true; -
3614} -
3615 -
3616/*! -
3617 \overload -
3618 -
3619 This function corresponds to setMinimumSize(QSize(minw, minh)). -
3620 Sets the minimum width to \a minw and the minimum height to \a -
3621 minh. -
3622*/ -
3623 -
3624void QWidget::setMinimumSize(int minw, int minh) -
3625{ -
3626 Q_D(QWidget); -
3627 if (!d->setMinimumSize_helper(minw, minh)) -
3628 return; -
3629 -
3630 if (isWindow()) -
3631 d->setConstraints_sys(); -
3632 if (minw > width() || minh > height()) { -
3633 bool resized = testAttribute(Qt::WA_Resized); -
3634 bool maximized = isMaximized(); -
3635 resize(qMax(minw,width()), qMax(minh,height())); -
3636 setAttribute(Qt::WA_Resized, resized); //not a user resize -
3637 if (maximized) -
3638 data->window_state = data->window_state | Qt::WindowMaximized; -
3639 } -
3640#ifndef QT_NO_GRAPHICSVIEW -
3641 if (d->extra) { -
3642 if (d->extra->proxyWidget) -
3643 d->extra->proxyWidget->setMinimumSize(minw, minh); -
3644 } -
3645#endif -
3646 d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh); -
3647} -
3648 -
3649bool QWidgetPrivate::setMaximumSize_helper(int &maxw, int &maxh) -
3650{ -
3651 Q_Q(QWidget); -
3652 if (maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX) { -
3653 qWarning("QWidget::setMaximumSize: (%s/%s) " -
3654 "The largest allowed size is (%d,%d)", -
3655 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX, -
3656 QWIDGETSIZE_MAX); -
3657 maxw = qMin<int>(maxw, QWIDGETSIZE_MAX); -
3658 maxh = qMin<int>(maxh, QWIDGETSIZE_MAX); -
3659 } -
3660 if (maxw < 0 || maxh < 0) { -
3661 qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) " -
3662 "are not possible", -
3663 q->objectName().toLocal8Bit().data(), q->metaObject()->className(), maxw, maxh); -
3664 maxw = qMax(maxw, 0); -
3665 maxh = qMax(maxh, 0); -
3666 } -
3667 createExtra(); -
3668 if (extra->maxw == maxw && extra->maxh == maxh) -
3669 return false; -
3670 extra->maxw = maxw; -
3671 extra->maxh = maxh; -
3672 extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) | -
3673 (maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0); -
3674 return true; -
3675} -
3676 -
3677/*! -
3678 \overload -
3679 -
3680 This function corresponds to setMaximumSize(QSize(\a maxw, \a -
3681 maxh)). Sets the maximum width to \a maxw and the maximum height -
3682 to \a maxh. -
3683*/ -
3684void QWidget::setMaximumSize(int maxw, int maxh) -
3685{ -
3686 Q_D(QWidget); -
3687 if (!d->setMaximumSize_helper(maxw, maxh)) -
3688 return; -
3689 -
3690 if (isWindow()) -
3691 d->setConstraints_sys(); -
3692 if (maxw < width() || maxh < height()) { -
3693 bool resized = testAttribute(Qt::WA_Resized); -
3694 resize(qMin(maxw,width()), qMin(maxh,height())); -
3695 setAttribute(Qt::WA_Resized, resized); //not a user resize -
3696 } -
3697 -
3698#ifndef QT_NO_GRAPHICSVIEW -
3699 if (d->extra) { -
3700 if (d->extra->proxyWidget) -
3701 d->extra->proxyWidget->setMaximumSize(maxw, maxh); -
3702 } -
3703#endif -
3704 -
3705 d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh); -
3706} -
3707 -
3708/*! -
3709 \overload -
3710 -
3711 Sets the x (width) size increment to \a w and the y (height) size -
3712 increment to \a h. -
3713*/ -
3714void QWidget::setSizeIncrement(int w, int h) -
3715{ -
3716 Q_D(QWidget); -
3717 d->createTLExtra(); -
3718 QTLWExtra* x = d->topData(); -
3719 if (x->incw == w && x->inch == h) -
3720 return; -
3721 x->incw = w; -
3722 x->inch = h; -
3723 if (isWindow()) -
3724 d->setConstraints_sys(); -
3725} -
3726 -
3727/*! -
3728 \overload -
3729 -
3730 This corresponds to setBaseSize(QSize(\a basew, \a baseh)). Sets -
3731 the widgets base size to width \a basew and height \a baseh. -
3732*/ -
3733void QWidget::setBaseSize(int basew, int baseh) -
3734{ -
3735 Q_D(QWidget); -
3736 d->createTLExtra(); -
3737 QTLWExtra* x = d->topData(); -
3738 if (x->basew == basew && x->baseh == baseh) -
3739 return; -
3740 x->basew = basew; -
3741 x->baseh = baseh; -
3742 if (isWindow()) -
3743 d->setConstraints_sys(); -
3744} -
3745 -
3746/*! -
3747 Sets both the minimum and maximum sizes of the widget to \a s, -
3748 thereby preventing it from ever growing or shrinking. -
3749 -
3750 This will override the default size constraints set by QLayout. -
3751 -
3752 To remove constraints, set the size to QWIDGETSIZE_MAX. -
3753 -
3754 Alternatively, if you want the widget to have a -
3755 fixed size based on its contents, you can call -
3756 QLayout::setSizeConstraint(QLayout::SetFixedSize); -
3757 -
3758 \sa maximumSize, minimumSize -
3759*/ -
3760 -
3761void QWidget::setFixedSize(const QSize & s) -
3762{ -
3763 setFixedSize(s.width(), s.height()); -
3764} -
3765 -
3766 -
3767/*! -
3768 \fn void QWidget::setFixedSize(int w, int h) -
3769 \overload -
3770 -
3771 Sets the width of the widget to \a w and the height to \a h. -
3772*/ -
3773 -
3774void QWidget::setFixedSize(int w, int h) -
3775{ -
3776 Q_D(QWidget); -
3777 bool minSizeSet = d->setMinimumSize_helper(w, h); -
3778 bool maxSizeSet = d->setMaximumSize_helper(w, h); -
3779 if (!minSizeSet && !maxSizeSet) -
3780 return; -
3781 -
3782 if (isWindow()) -
3783 d->setConstraints_sys(); -
3784 else -
3785 d->updateGeometry_helper(true); -
3786 -
3787 if (w != QWIDGETSIZE_MAX || h != QWIDGETSIZE_MAX) -
3788 resize(w, h); -
3789} -
3790 -
3791void QWidget::setMinimumWidth(int w) -
3792{ -
3793 Q_D(QWidget); -
3794 d->createExtra(); -
3795 uint expl = d->extra->explicitMinSize | (w ? Qt::Horizontal : 0); -
3796 setMinimumSize(w, minimumSize().height()); -
3797 d->extra->explicitMinSize = expl; -
3798} -
3799 -
3800void QWidget::setMinimumHeight(int h) -
3801{ -
3802 Q_D(QWidget); -
3803 d->createExtra(); -
3804 uint expl = d->extra->explicitMinSize | (h ? Qt::Vertical : 0); -
3805 setMinimumSize(minimumSize().width(), h); -
3806 d->extra->explicitMinSize = expl; -
3807} -
3808 -
3809void QWidget::setMaximumWidth(int w) -
3810{ -
3811 Q_D(QWidget); -
3812 d->createExtra(); -
3813 uint expl = d->extra->explicitMaxSize | (w == QWIDGETSIZE_MAX ? 0 : Qt::Horizontal); -
3814 setMaximumSize(w, maximumSize().height()); -
3815 d->extra->explicitMaxSize = expl; -
3816} -
3817 -
3818void QWidget::setMaximumHeight(int h) -
3819{ -
3820 Q_D(QWidget); -
3821 d->createExtra(); -
3822 uint expl = d->extra->explicitMaxSize | (h == QWIDGETSIZE_MAX ? 0 : Qt::Vertical); -
3823 setMaximumSize(maximumSize().width(), h); -
3824 d->extra->explicitMaxSize = expl; -
3825} -
3826 -
3827/*! -
3828 Sets both the minimum and maximum width of the widget to \a w -
3829 without changing the heights. Provided for convenience. -
3830 -
3831 \sa sizeHint(), minimumSize(), maximumSize(), setFixedSize() -
3832*/ -
3833 -
3834void QWidget::setFixedWidth(int w) -
3835{ -
3836 Q_D(QWidget); -
3837 d->createExtra(); -
3838 uint explMin = d->extra->explicitMinSize | Qt::Horizontal; -
3839 uint explMax = d->extra->explicitMaxSize | Qt::Horizontal; -
3840 setMinimumSize(w, minimumSize().height()); -
3841 setMaximumSize(w, maximumSize().height()); -
3842 d->extra->explicitMinSize = explMin; -
3843 d->extra->explicitMaxSize = explMax; -
3844} -
3845 -
3846 -
3847/*! -
3848 Sets both the minimum and maximum heights of the widget to \a h -
3849 without changing the widths. Provided for convenience. -
3850 -
3851 \sa sizeHint(), minimumSize(), maximumSize(), setFixedSize() -
3852*/ -
3853 -
3854void QWidget::setFixedHeight(int h) -
3855{ -
3856 Q_D(QWidget); -
3857 d->createExtra(); -
3858 uint explMin = d->extra->explicitMinSize | Qt::Vertical; -
3859 uint explMax = d->extra->explicitMaxSize | Qt::Vertical; -
3860 setMinimumSize(minimumSize().width(), h); -
3861 setMaximumSize(maximumSize().width(), h); -
3862 d->extra->explicitMinSize = explMin; -
3863 d->extra->explicitMaxSize = explMax; -
3864} -
3865 -
3866 -
3867/*! -
3868 Translates the widget coordinate \a pos to the coordinate system -
3869 of \a parent. The \a parent must not be 0 and must be a parent -
3870 of the calling widget. -
3871 -
3872 \sa mapFrom(), mapToParent(), mapToGlobal(), underMouse() -
3873*/ -
3874 -
3875QPoint QWidget::mapTo(const QWidget * parent, const QPoint & pos) const -
3876{ -
3877 QPoint p = pos; -
3878 if (parent) { -
3879 const QWidget * w = this; -
3880 while (w != parent) { -
3881 Q_ASSERT_X(w, "QWidget::mapTo(const QWidget *parent, const QPoint &pos)", -
3882 "parent must be in parent hierarchy"); -
3883 p = w->mapToParent(p); -
3884 w = w->parentWidget(); -
3885 } -
3886 } -
3887 return p; -
3888} -
3889 -
3890 -
3891/*! -
3892 Translates the widget coordinate \a pos from the coordinate system -
3893 of \a parent to this widget's coordinate system. The \a parent -
3894 must not be 0 and must be a parent of the calling widget. -
3895 -
3896 \sa mapTo(), mapFromParent(), mapFromGlobal(), underMouse() -
3897*/ -
3898 -
3899QPoint QWidget::mapFrom(const QWidget * parent, const QPoint & pos) const -
3900{ -
3901 QPoint p(pos); -
3902 if (parent) { -
3903 const QWidget * w = this; -
3904 while (w != parent) { -
3905 Q_ASSERT_X(w, "QWidget::mapFrom(const QWidget *parent, const QPoint &pos)", -
3906 "parent must be in parent hierarchy"); -
3907 -
3908 p = w->mapFromParent(p); -
3909 w = w->parentWidget(); -
3910 } -
3911 } -
3912 return p; -
3913} -
3914 -
3915 -
3916/*! -
3917 Translates the widget coordinate \a pos to a coordinate in the -
3918 parent widget. -
3919 -
3920 Same as mapToGlobal() if the widget has no parent. -
3921 -
3922 \sa mapFromParent(), mapTo(), mapToGlobal(), underMouse() -
3923*/ -
3924 -
3925QPoint QWidget::mapToParent(const QPoint &pos) const -
3926{ -
3927 return pos + data->crect.topLeft(); -
3928} -
3929 -
3930/*! -
3931 Translates the parent widget coordinate \a pos to widget -
3932 coordinates. -
3933 -
3934 Same as mapFromGlobal() if the widget has no parent. -
3935 -
3936 \sa mapToParent(), mapFrom(), mapFromGlobal(), underMouse() -
3937*/ -
3938 -
3939QPoint QWidget::mapFromParent(const QPoint &pos) const -
3940{ -
3941 return pos - data->crect.topLeft(); -
3942} -
3943 -
3944 -
3945/*! -
3946 Returns the window for this widget, i.e. the next ancestor widget -
3947 that has (or could have) a window-system frame. -
3948 -
3949 If the widget is a window, the widget itself is returned. -
3950 -
3951 Typical usage is changing the window title: -
3952 -
3953 \snippet code/src_gui_kernel_qwidget.cpp 3 -
3954 -
3955 \sa isWindow() -
3956*/ -
3957 -
3958QWidget *QWidget::window() const -
3959{ -
3960 QWidget *w = (QWidget *)this; -
3961 QWidget *p = w->parentWidget(); -
3962 while (!w->isWindow() && p) { -
3963 w = p; -
3964 p = p->parentWidget(); -
3965 } -
3966 return w; -
3967} -
3968 -
3969/*! -
3970 \since 4.4 -
3971 -
3972 Returns the native parent for this widget, i.e. the next ancestor widget -
3973 that has a system identifier, or 0 if it does not have any native parent. -
3974 -
3975 \sa effectiveWinId() -
3976*/ -
3977QWidget *QWidget::nativeParentWidget() const -
3978{ -
3979 QWidget *parent = parentWidget(); -
3980 while (parent && !parent->internalWinId()) -
3981 parent = parent->parentWidget(); -
3982 return parent; -
3983} -
3984 -
3985/*! \fn QWidget *QWidget::topLevelWidget() const -
3986 \obsolete -
3987 -
3988 Use window() instead. -
3989*/ -
3990 -
3991 -
3992 -
3993/*! -
3994 Returns the background role of the widget. -
3995 -
3996 The background role defines the brush from the widget's \l palette that -
3997 is used to render the background. -
3998 -
3999 If no explicit background role is set, the widget inherts its parent -
4000 widget's background role. -
4001 -
4002 \sa setBackgroundRole(), foregroundRole() -
4003 */ -
4004QPalette::ColorRole QWidget::backgroundRole() const -
4005{ -
4006 -
4007 const QWidget *w = this; -
4008 do { -
4009 QPalette::ColorRole role = w->d_func()->bg_role; -
4010 if (role != QPalette::NoRole) -
4011 return role; -
4012 if (w->isWindow() || w->windowType() == Qt::SubWindow) -
4013 break; -
4014 w = w->parentWidget(); -
4015 } while (w); -
4016 return QPalette::Window; -
4017} -
4018 -
4019/*! -
4020 Sets the background role of the widget to \a role. -
4021 -
4022 The background role defines the brush from the widget's \l palette that -
4023 is used to render the background. -
4024 -
4025 If \a role is QPalette::NoRole, then the widget inherits its -
4026 parent's background role. -
4027 -
4028 Note that styles are free to choose any color from the palette. -
4029 You can modify the palette or set a style sheet if you don't -
4030 achieve the result you want with setBackgroundRole(). -
4031 -
4032 \sa backgroundRole(), foregroundRole() -
4033 */ -
4034 -
4035void QWidget::setBackgroundRole(QPalette::ColorRole role) -
4036{ -
4037 Q_D(QWidget); -
4038 d->bg_role = role; -
4039 d->updateSystemBackground(); -
4040 d->propagatePaletteChange(); -
4041 d->updateIsOpaque(); -
4042} -
4043 -
4044/*! -
4045 Returns the foreground role. -
4046 -
4047 The foreground role defines the color from the widget's \l palette that -
4048 is used to draw the foreground. -
4049 -
4050 If no explicit foreground role is set, the function returns a role -
4051 that contrasts with the background role. -
4052 -
4053 \sa setForegroundRole(), backgroundRole() -
4054 */ -
4055QPalette::ColorRole QWidget::foregroundRole() const -
4056{ -
4057 Q_D(const QWidget); -
4058 QPalette::ColorRole rl = QPalette::ColorRole(d->fg_role); -
4059 if (rl != QPalette::NoRole) -
4060 return rl; -
4061 QPalette::ColorRole role = QPalette::WindowText; -
4062 switch (backgroundRole()) { -
4063 case QPalette::Button: -
4064 role = QPalette::ButtonText; -
4065 break; -
4066 case QPalette::Base: -
4067 role = QPalette::Text; -
4068 break; -
4069 case QPalette::Dark: -
4070 case QPalette::Shadow: -
4071 role = QPalette::Light; -
4072 break; -
4073 case QPalette::Highlight: -
4074 role = QPalette::HighlightedText; -
4075 break; -
4076 case QPalette::ToolTipBase: -
4077 role = QPalette::ToolTipText; -
4078 break; -
4079 default: -
4080 ; -
4081 } -
4082 return role; -
4083} -
4084 -
4085/*! -
4086 Sets the foreground role of the widget to \a role. -
4087 -
4088 The foreground role defines the color from the widget's \l palette that -
4089 is used to draw the foreground. -
4090 -
4091 If \a role is QPalette::NoRole, the widget uses a foreground role -
4092 that contrasts with the background role. -
4093 -
4094 Note that styles are free to choose any color from the palette. -
4095 You can modify the palette or set a style sheet if you don't -
4096 achieve the result you want with setForegroundRole(). -
4097 -
4098 \sa foregroundRole(), backgroundRole() -
4099 */ -
4100void QWidget::setForegroundRole(QPalette::ColorRole role) -
4101{ -
4102 Q_D(QWidget); -
4103 d->fg_role = role; -
4104 d->updateSystemBackground(); -
4105 d->propagatePaletteChange(); -
4106} -
4107 -
4108/*! -
4109 \property QWidget::palette -
4110 \brief the widget's palette -
4111 -
4112 This property describes the widget's palette. The palette is used by the -
4113 widget's style when rendering standard components, and is available as a -
4114 means to ensure that custom widgets can maintain consistency with the -
4115 native platform's look and feel. It's common that different platforms, or -
4116 different styles, have different palettes. -
4117 -
4118 When you assign a new palette to a widget, the color roles from this -
4119 palette are combined with the widget's default palette to form the -
4120 widget's final palette. The palette entry for the widget's background role -
4121 is used to fill the widget's background (see QWidget::autoFillBackground), -
4122 and the foreground role initializes QPainter's pen. -
4123 -
4124 The default depends on the system environment. QApplication maintains a -
4125 system/theme palette which serves as a default for all widgets. There may -
4126 also be special palette defaults for certain types of widgets (e.g., on -
4127 Windows XP and Vista, all classes that derive from QMenuBar have a special -
4128 default palette). You can also define default palettes for widgets -
4129 yourself by passing a custom palette and the name of a widget to -
4130 QApplication::setPalette(). Finally, the style always has the option of -
4131 polishing the palette as it's assigned (see QStyle::polish()). -
4132 -
4133 QWidget propagates explicit palette roles from parent to child. If you -
4134 assign a brush or color to a specific role on a palette and assign that -
4135 palette to a widget, that role will propagate to all the widget's -
4136 children, overriding any system defaults for that role. Note that palettes -
4137 by default don't propagate to windows (see isWindow()) unless the -
4138 Qt::WA_WindowPropagation attribute is enabled. -
4139 -
4140 QWidget's palette propagation is similar to its font propagation. -
4141 -
4142 The current style, which is used to render the content of all standard Qt -
4143 widgets, is free to choose colors and brushes from the widget palette, or -
4144 in some cases, to ignore the palette (partially, or completely). In -
4145 particular, certain styles like GTK style, Mac style, Windows XP, and -
4146 Vista style, depend on third party APIs to render the content of widgets, -
4147 and these styles typically do not follow the palette. Because of this, -
4148 assigning roles to a widget's palette is not guaranteed to change the -
4149 appearance of the widget. Instead, you may choose to apply a \l -
4150 styleSheet. You can refer to our Knowledge Base article -
4151 \l{http://qt.nokia.com/developer/knowledgebase/22}{here} for more -
4152 information. -
4153 -
4154 \warning Do not use this function in conjunction with \l{Qt Style Sheets}. -
4155 When using style sheets, the palette of a widget can be customized using -
4156 the "color", "background-color", "selection-color", -
4157 "selection-background-color" and "alternate-background-color". -
4158 -
4159 \sa QApplication::palette(), QWidget::font() -
4160*/ -
4161const QPalette &QWidget::palette() const -
4162{ -
4163 if (!isEnabled()) { -
4164 data->pal.setCurrentColorGroup(QPalette::Disabled); -
4165 } else if ((!isVisible() || isActiveWindow()) -
4166#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) -
4167 && !QApplicationPrivate::isBlockedByModal(const_cast<QWidget *>(this)) -
4168#endif -
4169 ) { -
4170 data->pal.setCurrentColorGroup(QPalette::Active); -
4171 } else { -
4172#ifdef Q_WS_MAC -
4173 extern bool qt_mac_can_clickThrough(const QWidget *); //qwidget_mac.cpp -
4174 if (qt_mac_can_clickThrough(this)) -
4175 data->pal.setCurrentColorGroup(QPalette::Active); -
4176 else -
4177#endif -
4178 data->pal.setCurrentColorGroup(QPalette::Inactive); -
4179 } -
4180 return data->pal; -
4181} -
4182 -
4183void QWidget::setPalette(const QPalette &palette) -
4184{ -
4185 Q_D(QWidget); -
4186 setAttribute(Qt::WA_SetPalette, palette.resolve() != 0); -
4187 -
4188 // Determine which palette is inherited from this widget's ancestors and -
4189 // QApplication::palette, resolve this against \a palette (attributes from -
4190 // the inherited palette are copied over this widget's palette). Then -
4191 // propagate this palette to this widget's children. -
4192 QPalette naturalPalette = d->naturalWidgetPalette(d->inheritedPaletteResolveMask); -
4193 QPalette resolvedPalette = palette.resolve(naturalPalette); -
4194 d->setPalette_helper(resolvedPalette); -
4195} -
4196 -
4197/*! -
4198 \internal -
4199 -
4200 Returns the palette that the widget \a w inherits from its ancestors and -
4201 QApplication::palette. \a inheritedMask is the combination of the widget's -
4202 ancestors palette request masks (i.e., which attributes from the parent -
4203 widget's palette are implicitly imposed on this widget by the user). Note -
4204 that this font does not take into account the palette set on \a w itself. -
4205*/ -
4206QPalette QWidgetPrivate::naturalWidgetPalette(uint inheritedMask) const -
4207{ -
4208 Q_Q(const QWidget); -
4209 QPalette naturalPalette = QApplication::palette(q); -
4210 if (!q->testAttribute(Qt::WA_StyleSheet) -
4211 && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) -
4212#ifndef QT_NO_GRAPHICSVIEW -
4213 || (extra && extra->proxyWidget) -
4214#endif //QT_NO_GRAPHICSVIEW -
4215 )) { -
4216 if (QWidget *p = q->parentWidget()) { -
4217 if (!p->testAttribute(Qt::WA_StyleSheet)) { -
4218 if (!naturalPalette.isCopyOf(QApplication::palette())) { -
4219 QPalette inheritedPalette = p->palette(); -
4220 inheritedPalette.resolve(inheritedMask); -
4221 naturalPalette = inheritedPalette.resolve(naturalPalette); -
4222 } else { -
4223 naturalPalette = p->palette(); -
4224 } -
4225 } -
4226 } -
4227#ifndef QT_NO_GRAPHICSVIEW -
4228 else if (extra && extra->proxyWidget) { -
4229 QPalette inheritedPalette = extra->proxyWidget->palette(); -
4230 inheritedPalette.resolve(inheritedMask); -
4231 naturalPalette = inheritedPalette.resolve(naturalPalette); -
4232 } -
4233#endif //QT_NO_GRAPHICSVIEW -
4234 } -
4235 naturalPalette.resolve(0); -
4236 return naturalPalette; -
4237} -
4238/*! -
4239 \internal -
4240 -
4241 Determine which palette is inherited from this widget's ancestors and -
4242 QApplication::palette, resolve this against this widget's palette -
4243 (attributes from the inherited palette are copied over this widget's -
4244 palette). Then propagate this palette to this widget's children. -
4245*/ -
4246void QWidgetPrivate::resolvePalette() -
4247{ -
4248 QPalette naturalPalette = naturalWidgetPalette(inheritedPaletteResolveMask); -
4249 QPalette resolvedPalette = data.pal.resolve(naturalPalette); -
4250 setPalette_helper(resolvedPalette); -
4251} -
4252 -
4253void QWidgetPrivate::setPalette_helper(const QPalette &palette) -
4254{ -
4255 Q_Q(QWidget); -
4256 if (data.pal == palette && data.pal.resolve() == palette.resolve()) -
4257 return; -
4258 data.pal = palette; -
4259 updateSystemBackground(); -
4260 propagatePaletteChange(); -
4261 updateIsOpaque(); -
4262 q->update(); -
4263 updateIsOpaque(); -
4264} -
4265 -
4266/*! -
4267 \property QWidget::font -
4268 \brief the font currently set for the widget -
4269 -
4270 This property describes the widget's requested font. The font is used by -
4271 the widget's style when rendering standard components, and is available as -
4272 a means to ensure that custom widgets can maintain consistency with the -
4273 native platform's look and feel. It's common that different platforms, or -
4274 different styles, define different fonts for an application. -
4275 -
4276 When you assign a new font to a widget, the properties from this font are -
4277 combined with the widget's default font to form the widget's final -
4278 font. You can call fontInfo() to get a copy of the widget's final -
4279 font. The final font is also used to initialize QPainter's font. -
4280 -
4281 The default depends on the system environment. QApplication maintains a -
4282 system/theme font which serves as a default for all widgets. There may -
4283 also be special font defaults for certain types of widgets. You can also -
4284 define default fonts for widgets yourself by passing a custom font and the -
4285 name of a widget to QApplication::setFont(). Finally, the font is matched -
4286 against Qt's font database to find the best match. -
4287 -
4288 QWidget propagates explicit font properties from parent to child. If you -
4289 change a specific property on a font and assign that font to a widget, -
4290 that property will propagate to all the widget's children, overriding any -
4291 system defaults for that property. Note that fonts by default don't -
4292 propagate to windows (see isWindow()) unless the Qt::WA_WindowPropagation -
4293 attribute is enabled. -
4294 -
4295 QWidget's font propagation is similar to its palette propagation. -
4296 -
4297 The current style, which is used to render the content of all standard Qt -
4298 widgets, is free to choose to use the widget font, or in some cases, to -
4299 ignore it (partially, or completely). In particular, certain styles like -
4300 GTK style, Mac style, Windows XP, and Vista style, apply special -
4301 modifications to the widget font to match the platform's native look and -
4302 feel. Because of this, assigning properties to a widget's font is not -
4303 guaranteed to change the appearance of the widget. Instead, you may choose -
4304 to apply a \l styleSheet. -
4305 -
4306 \note If \l{Qt Style Sheets} are used on the same widget as setFont(), -
4307 style sheets will take precedence if the settings conflict. -
4308 -
4309 \sa fontInfo(), fontMetrics() -
4310*/ -
4311 -
4312void QWidget::setFont(const QFont &font) -
4313{ -
4314 Q_D(QWidget); -
4315 -
4316#ifndef QT_NO_STYLE_STYLESHEET -
4317 const QStyleSheetStyle* style; -
4318 if (d->extra && (style = qobject_cast<const QStyleSheetStyle*>(d->extra->style))) { -
4319 style->saveWidgetFont(this, font); -
4320 } -
4321#endif -
4322 -
4323 setAttribute(Qt::WA_SetFont, font.resolve() != 0); -
4324 -
4325 // Determine which font is inherited from this widget's ancestors and -
4326 // QApplication::font, resolve this against \a font (attributes from the -
4327 // inherited font are copied over). Then propagate this font to this -
4328 // widget's children. -
4329 QFont naturalFont = d->naturalWidgetFont(d->inheritedFontResolveMask); -
4330 QFont resolvedFont = font.resolve(naturalFont); -
4331 d->setFont_helper(resolvedFont); -
4332} -
4333 -
4334/* -
4335 \internal -
4336 -
4337 Returns the font that the widget \a w inherits from its ancestors and -
4338 QApplication::font. \a inheritedMask is the combination of the widget's -
4339 ancestors font request masks (i.e., which attributes from the parent -
4340 widget's font are implicitly imposed on this widget by the user). Note -
4341 that this font does not take into account the font set on \a w itself. -
4342 -
4343 ### Stylesheet has a different font propagation mechanism. When a stylesheet -
4344 is applied, fonts are not propagated anymore -
4345*/ -
4346QFont QWidgetPrivate::naturalWidgetFont(uint inheritedMask) const -
4347{ -
4348 Q_Q(const QWidget); -
4349 QFont naturalFont = QApplication::font(q); -
4350 if (!q->testAttribute(Qt::WA_StyleSheet) -
4351 && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation) -
4352#ifndef QT_NO_GRAPHICSVIEW -
4353 || (extra && extra->proxyWidget) -
4354#endif //QT_NO_GRAPHICSVIEW -
4355 )) { -
4356 if (QWidget *p = q->parentWidget()) { -
4357 if (!p->testAttribute(Qt::WA_StyleSheet)) { -
4358 if (!naturalFont.isCopyOf(QApplication::font())) { -
4359 QFont inheritedFont = p->font(); -
4360 inheritedFont.resolve(inheritedMask); -
4361 naturalFont = inheritedFont.resolve(naturalFont); -
4362 } else { -
4363 naturalFont = p->font(); -
4364 } -
4365 } -
4366 } -
4367#ifndef QT_NO_GRAPHICSVIEW -
4368 else if (extra && extra->proxyWidget) { -
4369 QFont inheritedFont = extra->proxyWidget->font(); -
4370 inheritedFont.resolve(inheritedMask); -
4371 naturalFont = inheritedFont.resolve(naturalFont); -
4372 } -
4373#endif //QT_NO_GRAPHICSVIEW -
4374 } -
4375 naturalFont.resolve(0); -
4376 return naturalFont; -
4377} -
4378 -
4379/*! -
4380 \internal -
4381 -
4382 Determine which font is implicitly imposed on this widget by its ancestors -
4383 and QApplication::font, resolve this against its own font (attributes from -
4384 the implicit font are copied over). Then propagate this font to this -
4385 widget's children. -
4386*/ -
4387void QWidgetPrivate::resolveFont() -
4388{ -
4389 QFont naturalFont = naturalWidgetFont(inheritedFontResolveMask); -
4390 QFont resolvedFont = data.fnt.resolve(naturalFont); -
4391 setFont_helper(resolvedFont); -
4392} -
4393 -
4394/*! -
4395 \internal -
4396 -
4397 Assign \a font to this widget, and propagate it to all children, except -
4398 style sheet widgets (handled differently) and windows that don't enable -
4399 window propagation. \a implicitMask is the union of all ancestor widgets' -
4400 font request masks, and determines which attributes from this widget's -
4401 font should propagate. -
4402*/ -
4403void QWidgetPrivate::updateFont(const QFont &font) -
4404{ -
4405 Q_Q(QWidget); -
4406#ifndef QT_NO_STYLE_STYLESHEET -
4407 const QStyleSheetStyle* cssStyle; -
4408 cssStyle = extra ? qobject_cast<const QStyleSheetStyle*>(extra->style) : 0; -
4409#endif -
4410 -
4411 data.fnt = QFont(font, q); -
4412#if defined(Q_WS_X11) -
4413 // make sure the font set on this widget is associated with the correct screen -
4414 data.fnt.x11SetScreen(xinfo.screen()); -
4415#endif -
4416 // Combine new mask with natural mask and propagate to children. -
4417#ifndef QT_NO_GRAPHICSVIEW -
4418 if (!q->parentWidget() && extra && extra->proxyWidget) { -
4419 QGraphicsProxyWidget *p = extra->proxyWidget; -
4420 inheritedFontResolveMask = p->d_func()->inheritedFontResolveMask | p->font().resolve(); -
4421 } else -
4422#endif //QT_NO_GRAPHICSVIEW -
4423 if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) { -
4424 inheritedFontResolveMask = 0; -
4425 } -
4426 uint newMask = data.fnt.resolve() | inheritedFontResolveMask; -
4427 -
4428 for (int i = 0; i < children.size(); ++i) { -
4429 QWidget *w = qobject_cast<QWidget*>(children.at(i)); -
4430 if (w) { -
4431 if (0) { -
4432#ifndef QT_NO_STYLE_STYLESHEET -
4433 } else if (w->testAttribute(Qt::WA_StyleSheet)) { -
4434 // Style sheets follow a different font propagation scheme. -
4435 if (cssStyle) -
4436 cssStyle->updateStyleSheetFont(w); -
4437#endif -
4438 } else if ((!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) { -
4439 // Propagate font changes. -
4440 QWidgetPrivate *wd = w->d_func(); -
4441 wd->inheritedFontResolveMask = newMask; -
4442 wd->resolveFont(); -
4443 } -
4444 } -
4445 } -
4446 -
4447#ifndef QT_NO_STYLE_STYLESHEET -
4448 if (cssStyle) { -
4449 cssStyle->updateStyleSheetFont(q); -
4450 } -
4451#endif -
4452 -
4453 QEvent e(QEvent::FontChange); -
4454 QApplication::sendEvent(q, &e); -
4455} -
4456 -
4457void QWidgetPrivate::setLayoutDirection_helper(Qt::LayoutDirection direction) -
4458{ -
4459 Q_Q(QWidget); -
4460 -
4461 if ( (direction == Qt::RightToLeft) == q->testAttribute(Qt::WA_RightToLeft)) -
4462 return; -
4463 q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft)); -
4464 if (!children.isEmpty()) { -
4465 for (int i = 0; i < children.size(); ++i) { -
4466 QWidget *w = qobject_cast<QWidget*>(children.at(i)); -
4467 if (w && !w->isWindow() && !w->testAttribute(Qt::WA_SetLayoutDirection)) -
4468 w->d_func()->setLayoutDirection_helper(direction); -
4469 } -
4470 } -
4471 QEvent e(QEvent::LayoutDirectionChange); -
4472 QApplication::sendEvent(q, &e); -
4473} -
4474 -
4475void QWidgetPrivate::resolveLayoutDirection() -
4476{ -
4477 Q_Q(const QWidget); -
4478 if (!q->testAttribute(Qt::WA_SetLayoutDirection)) -
4479 setLayoutDirection_helper(q->isWindow() ? QApplication::layoutDirection() : q->parentWidget()->layoutDirection()); -
4480} -
4481 -
4482/*! -
4483 \property QWidget::layoutDirection -
4484 -
4485 \brief the layout direction for this widget -
4486 -
4487 By default, this property is set to Qt::LeftToRight. -
4488 -
4489 When the layout direction is set on a widget, it will propagate to -
4490 the widget's children, but not to a child that is a window and not -
4491 to a child for which setLayoutDirection() has been explicitly -
4492 called. Also, child widgets added \e after setLayoutDirection() -
4493 has been called for the parent do not inherit the parent's layout -
4494 direction. -
4495 -
4496 This method no longer affects text layout direction since Qt 4.7. -
4497 -
4498 \sa QApplication::layoutDirection -
4499*/ -
4500void QWidget::setLayoutDirection(Qt::LayoutDirection direction) -
4501{ -
4502 Q_D(QWidget); -
4503 -
4504 if (direction == Qt::LayoutDirectionAuto) { -
4505 unsetLayoutDirection(); -
4506 return; -
4507 } -
4508 -
4509 setAttribute(Qt::WA_SetLayoutDirection); -
4510 d->setLayoutDirection_helper(direction); -
4511} -
4512 -
4513Qt::LayoutDirection QWidget::layoutDirection() const -
4514{ -
4515 return testAttribute(Qt::WA_RightToLeft) ? Qt::RightToLeft : Qt::LeftToRight; -
4516} -
4517 -
4518void QWidget::unsetLayoutDirection() -
4519{ -
4520 Q_D(QWidget); -
4521 setAttribute(Qt::WA_SetLayoutDirection, false); -
4522 d->resolveLayoutDirection(); -
4523} -
4524 -
4525/*! -
4526 \fn QFontMetrics QWidget::fontMetrics() const -
4527 -
4528 Returns the font metrics for the widget's current font. -
4529 Equivalent to QFontMetrics(widget->font()). -
4530 -
4531 \sa font(), fontInfo(), setFont() -
4532*/ -
4533 -
4534/*! -
4535 \fn QFontInfo QWidget::fontInfo() const -
4536 -
4537 Returns the font info for the widget's current font. -
4538 Equivalent to QFontInto(widget->font()). -
4539 -
4540 \sa font(), fontMetrics(), setFont() -
4541*/ -
4542 -
4543 -
4544/*! -
4545 \property QWidget::cursor -
4546 \brief the cursor shape for this widget -
4547 -
4548 The mouse cursor will assume this shape when it's over this -
4549 widget. See the \l{Qt::CursorShape}{list of predefined cursor objects} for a range of useful shapes. -
4550 -
4551 An editor widget might use an I-beam cursor: -
4552 \snippet code/src_gui_kernel_qwidget.cpp 6 -
4553 -
4554 If no cursor has been set, or after a call to unsetCursor(), the -
4555 parent's cursor is used. -
4556 -
4557 By default, this property contains a cursor with the Qt::ArrowCursor -
4558 shape. -
4559 -
4560 Some underlying window implementations will reset the cursor if it -
4561 leaves a widget even if the mouse is grabbed. If you want to have -
4562 a cursor set for all widgets, even when outside the window, consider -
4563 QApplication::setOverrideCursor(). -
4564 -
4565 \sa QApplication::setOverrideCursor() -
4566*/ -
4567 -
4568#ifndef QT_NO_CURSOR -
4569QCursor QWidget::cursor() const -
4570{ -
4571 Q_D(const QWidget); -
4572 if (testAttribute(Qt::WA_SetCursor)) -
4573 return (d->extra && d->extra->curs) -
4574 ? *d->extra->curs -
4575 : QCursor(Qt::ArrowCursor); -
4576 if (isWindow() || !parentWidget()) -
4577 return QCursor(Qt::ArrowCursor); -
4578 return parentWidget()->cursor(); -
4579} -
4580 -
4581void QWidget::setCursor(const QCursor &cursor) -
4582{ -
4583 Q_D(QWidget); -
4584// On Mac we must set the cursor even if it is the ArrowCursor. -
4585#if !defined(Q_WS_MAC) -
4586 if (cursor.shape() != Qt::ArrowCursor -
4587 || (d->extra && d->extra->curs)) -
4588#endif -
4589 { -
4590 d->createExtra(); -
4591 QCursor *newCursor = new QCursor(cursor); -
4592 delete d->extra->curs; -
4593 d->extra->curs = newCursor; -
4594 } -
4595 setAttribute(Qt::WA_SetCursor); -
4596 d->setCursor_sys(cursor); -
4597 -
4598 QEvent event(QEvent::CursorChange); -
4599 QApplication::sendEvent(this, &event); -
4600} -
4601 -
4602void QWidget::unsetCursor() -
4603{ -
4604 Q_D(QWidget); -
4605 if (d->extra) { -
4606 delete d->extra->curs; -
4607 d->extra->curs = 0; -
4608 } -
4609 if (!isWindow()) -
4610 setAttribute(Qt::WA_SetCursor, false); -
4611 d->unsetCursor_sys(); -
4612 -
4613 QEvent event(QEvent::CursorChange); -
4614 QApplication::sendEvent(this, &event); -
4615} -
4616 -
4617#endif -
4618 -
4619/*! -
4620 \enum QWidget::RenderFlag -
4621 -
4622 This enum describes how to render the widget when calling QWidget::render(). -
4623 -
4624 \value DrawWindowBackground If you enable this option, the widget's background -
4625 is rendered into the target even if autoFillBackground is not set. By default, -
4626 this option is enabled. -
4627 -
4628 \value DrawChildren If you enable this option, the widget's children -
4629 are rendered recursively into the target. By default, this option is enabled. -
4630 -
4631 \value IgnoreMask If you enable this option, the widget's QWidget::mask() -
4632 is ignored when rendering into the target. By default, this option is disabled. -
4633 -
4634 \since 4.3 -
4635*/ -
4636 -
4637/*! -
4638 \since 4.3 -
4639 -
4640 Renders the \a sourceRegion of this widget into the \a target -
4641 using \a renderFlags to determine how to render. Rendering -
4642 starts at \a targetOffset in the \a target. For example: -
4643 -
4644 \snippet code/src_gui_kernel_qwidget.cpp 7 -
4645 -
4646 If \a sourceRegion is a null region, this function will use QWidget::rect() as -
4647 the region, i.e. the entire widget. -
4648 -
4649 Ensure that you call QPainter::end() for the \a target device's -
4650 active painter (if any) before rendering. For example: -
4651 -
4652 \snippet code/src_gui_kernel_qwidget.cpp 8 -
4653 -
4654 \note To obtain the contents of an OpenGL widget, use QGLWidget::grabFrameBuffer() -
4655 or QGLWidget::renderPixmap() instead. -
4656*/ -
4657void QWidget::render(QPaintDevice *target, const QPoint &targetOffset, -
4658 const QRegion &sourceRegion, RenderFlags renderFlags) -
4659{ -
4660 d_func()->render(target, targetOffset, sourceRegion, renderFlags, false); -
4661} -
4662 -
4663/*! -
4664 \overload -
4665 -
4666 Renders the widget into the \a painter's QPainter::device(). -
4667 -
4668 Transformations and settings applied to the \a painter will be used -
4669 when rendering. -
4670 -
4671 \note The \a painter must be active. On Mac OS X the widget will be -
4672 rendered into a QPixmap and then drawn by the \a painter. -
4673 -
4674 \sa QPainter::device() -
4675*/ -
4676void QWidget::render(QPainter *painter, const QPoint &targetOffset, -
4677 const QRegion &sourceRegion, RenderFlags renderFlags) -
4678{ -
4679 if (!painter) { -
4680 qWarning("QWidget::render: Null pointer to painter"); -
4681 return; -
4682 } -
4683 -
4684 if (!painter->isActive()) { -
4685 qWarning("QWidget::render: Cannot render with an inactive painter"); -
4686 return; -
4687 } -
4688 -
4689 const qreal opacity = painter->opacity(); -
4690 if (qFuzzyIsNull(opacity)) -
4691 return; // Fully transparent. -
4692 -
4693 Q_D(QWidget); -
4694 const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter; -
4695 const QRegion toBePainted = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags) -
4696 : sourceRegion; -
4697 if (toBePainted.isEmpty()) -
4698 return; -
4699 -
4700 if (!d->extra) -
4701 d->createExtra(); -
4702 d->extra->inRenderWithPainter = true; -
4703 -
4704#ifdef Q_WS_MAC -
4705 d->render_helper(painter, targetOffset, toBePainted, renderFlags); -
4706#else -
4707 QPaintEngine *engine = painter->paintEngine(); -
4708 Q_ASSERT(engine); -
4709 QPaintEnginePrivate *enginePriv = engine->d_func(); -
4710 Q_ASSERT(enginePriv); -
4711 QPaintDevice *target = engine->paintDevice(); -
4712 Q_ASSERT(target); -
4713 -
4714 // Render via a pixmap when dealing with non-opaque painters or printers. -
4715 if (!inRenderWithPainter && (opacity < 1.0 || (target->devType() == QInternal::Printer))) { -
4716 d->render_helper(painter, targetOffset, toBePainted, renderFlags); -
4717 d->extra->inRenderWithPainter = false; -
4718 return; -
4719 } -
4720 -
4721 // Set new shared painter. -
4722 QPainter *oldPainter = d->sharedPainter(); -
4723 d->setSharedPainter(painter); -
4724 -
4725 // Save current system clip, viewport and transform, -
4726 const QTransform oldTransform = enginePriv->systemTransform; -
4727 const QRegion oldSystemClip = enginePriv->systemClip; -
4728 const QRegion oldSystemViewport = enginePriv->systemViewport; -
4729 -
4730 // This ensures that all painting triggered by render() is clipped to the current engine clip. -
4731 if (painter->hasClipping()) { -
4732 const QRegion painterClip = painter->deviceTransform().map(painter->clipRegion()); -
4733 enginePriv->setSystemViewport(oldSystemClip.isEmpty() ? painterClip : oldSystemClip & painterClip); -
4734 } else { -
4735 enginePriv->setSystemViewport(oldSystemClip); -
4736 } -
4737 -
4738 render(target, targetOffset, toBePainted, renderFlags); -
4739 -
4740 // Restore system clip, viewport and transform. -
4741 enginePriv->systemClip = oldSystemClip; -
4742 enginePriv->setSystemViewport(oldSystemViewport); -
4743 enginePriv->setSystemTransform(oldTransform); -
4744 -
4745 // Restore shared painter. -
4746 d->setSharedPainter(oldPainter); -
4747#endif -
4748 -
4749 d->extra->inRenderWithPainter = false; -
4750} -
4751 -
4752static void sendResizeEvents(QWidget *target) -
4753{ -
4754 QResizeEvent e(target->size(), QSize()); -
4755 QApplication::sendEvent(target, &e); -
4756 -
4757 const QObjectList children = target->children(); -
4758 for (int i = 0; i < children.size(); ++i) { -
4759 QWidget *child = static_cast<QWidget*>(children.at(i)); -
4760 if (child->isWidgetType() && !child->isWindow() && child->testAttribute(Qt::WA_PendingResizeEvent)) -
4761 sendResizeEvents(child); -
4762 } -
4763} -
4764 -
4765/*! -
4766 \since 5.0 -
4767 -
4768 Renders the widget into a pixmap restricted by the -
4769 given \a rectangle. If the widget has any children, then -
4770 they are also painted in the appropriate positions. -
4771 -
4772 If a rectangle with an invalid size is specified (the default), -
4773 the entire widget is painted. -
4774 -
4775 \sa render(), QPixmap -
4776*/ -
4777 -
4778/* INVOKABLE since used by QPixmap::grabWidget(). */ -
4779QPixmap QWidget::grab(const QRect &rectangle) -
4780{ -
4781 Q_D(QWidget); -
4782 if (testAttribute(Qt::WA_PendingResizeEvent) || !testAttribute(Qt::WA_WState_Created)) -
4783 sendResizeEvents(this); -
4784 -
4785 const QWidget::RenderFlags renderFlags = QWidget::DrawWindowBackground | QWidget::DrawChildren | QWidget::IgnoreMask; -
4786 -
4787 const bool oldDirtyOpaqueChildren = d->dirtyOpaqueChildren; -
4788 QRect r(rectangle); -
4789 if (r.width() < 0 || r.height() < 0) { -
4790 // For grabbing widgets that haven't been shown yet, -
4791 // we trigger the layouting mechanism to determine the widget's size. -
4792 r = d->prepareToRender(QRegion(), renderFlags).boundingRect(); -
4793 r.setTopLeft(rectangle.topLeft()); -
4794 } -
4795 -
4796 if (!r.intersects(rect())) -
4797 return QPixmap(); -
4798 -
4799 QPixmap res(r.size()); -
4800 if (!d->isOpaque) -
4801 res.fill(Qt::transparent); -
4802 render(&res, QPoint(), QRegion(r), renderFlags); -
4803 -
4804 d->dirtyOpaqueChildren = oldDirtyOpaqueChildren; -
4805 return res; -
4806} -
4807 -
4808/*! -
4809 \brief The graphicsEffect function returns a pointer to the -
4810 widget's graphics effect. -
4811 -
4812 If the widget has no graphics effect, 0 is returned. -
4813 -
4814 \since 4.6 -
4815 -
4816 \sa setGraphicsEffect() -
4817*/ -
4818#ifndef QT_NO_GRAPHICSEFFECT -
4819QGraphicsEffect *QWidget::graphicsEffect() const -
4820{ -
4821 Q_D(const QWidget); -
4822 return d->graphicsEffect; -
4823} -
4824#endif //QT_NO_GRAPHICSEFFECT -
4825 -
4826/*! -
4827 -
4828 \brief The setGraphicsEffect function is for setting the widget's graphics effect. -
4829 -
4830 Sets \a effect as the widget's effect. If there already is an effect installed -
4831 on this widget, QWidget will delete the existing effect before installing -
4832 the new \a effect. -
4833 -
4834 If \a effect is the installed on a different widget, setGraphicsEffect() will remove -
4835 the effect from the widget and install it on this widget. -
4836 -
4837 QWidget takes ownership of \a effect. -
4838 -
4839 \note This function will apply the effect on itself and all its children. -
4840 -
4841 \since 4.6 -
4842 -
4843 \sa graphicsEffect() -
4844*/ -
4845#ifndef QT_NO_GRAPHICSEFFECT -
4846void QWidget::setGraphicsEffect(QGraphicsEffect *effect) -
4847{ -
4848 Q_D(QWidget); -
4849 if (d->graphicsEffect == effect) -
4850 return; -
4851 -
4852 if (d->graphicsEffect) { -
4853 d->invalidateBuffer(rect()); -
4854 delete d->graphicsEffect; -
4855 d->graphicsEffect = 0; -
4856 } -
4857 -
4858 if (effect) { -
4859 // Set new effect. -
4860 QGraphicsEffectSourcePrivate *sourced = new QWidgetEffectSourcePrivate(this); -
4861 QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced); -
4862 d->graphicsEffect = effect; -
4863 effect->d_func()->setGraphicsEffectSource(source); -
4864 update(); -
4865 } -
4866 -
4867 d->updateIsOpaque(); -
4868} -
4869#endif //QT_NO_GRAPHICSEFFECT -
4870 -
4871bool QWidgetPrivate::isAboutToShow() const -
4872{ -
4873 if (data.in_show) -
4874 return true; -
4875 -
4876 Q_Q(const QWidget); -
4877 if (q->isHidden()) -
4878 return false; -
4879 -
4880 // The widget will be shown if any of its ancestors are about to show. -
4881 QWidget *parent = q->parentWidget(); -
4882 return parent ? parent->d_func()->isAboutToShow() : false; -
4883} -
4884 -
4885QRegion QWidgetPrivate::prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags) -
4886{ -
4887 Q_Q(QWidget); -
4888 const bool isVisible = q->isVisible(); -
4889 -
4890 // Make sure the widget is laid out correctly. -
4891 if (!isVisible && !isAboutToShow()) { -
4892 QWidget *topLevel = q->window(); -
4893 (void)topLevel->d_func()->topData(); // Make sure we at least have top-data. -
4894 topLevel->ensurePolished(); -
4895 -
4896 // Invalidate the layout of hidden ancestors (incl. myself) and pretend -
4897 // they're not explicitly hidden. -
4898 QWidget *widget = q; -
4899 QWidgetList hiddenWidgets; -
4900 while (widget) { -
4901 if (widget->isHidden()) { -
4902 widget->setAttribute(Qt::WA_WState_Hidden, false); -
4903 hiddenWidgets.append(widget); -
4904 if (!widget->isWindow() && widget->parentWidget()->d_func()->layout) -
4905 widget->d_func()->updateGeometry_helper(true); -
4906 } -
4907 widget = widget->parentWidget(); -
4908 } -
4909 -
4910 // Activate top-level layout. -
4911 if (topLevel->d_func()->layout) -
4912 topLevel->d_func()->layout->activate(); -
4913 -
4914 // Adjust size if necessary. -
4915 QTLWExtra *topLevelExtra = topLevel->d_func()->maybeTopData(); -
4916 if (topLevelExtra && !topLevelExtra->sizeAdjusted -
4917 && !topLevel->testAttribute(Qt::WA_Resized)) { -
4918 topLevel->adjustSize(); -
4919 topLevel->setAttribute(Qt::WA_Resized, false); -
4920 } -
4921 -
4922 // Activate child layouts. -
4923 topLevel->d_func()->activateChildLayoutsRecursively(); -
4924 -
4925 // We're not cheating with WA_WState_Hidden anymore. -
4926 for (int i = 0; i < hiddenWidgets.size(); ++i) { -
4927 QWidget *widget = hiddenWidgets.at(i); -
4928 widget->setAttribute(Qt::WA_WState_Hidden); -
4929 if (!widget->isWindow() && widget->parentWidget()->d_func()->layout) -
4930 widget->parentWidget()->d_func()->layout->invalidate(); -
4931 } -
4932 } else if (isVisible) { -
4933 q->window()->d_func()->sendPendingMoveAndResizeEvents(true, true); -
4934 } -
4935 -
4936 // Calculate the region to be painted. -
4937 QRegion toBePainted = !region.isEmpty() ? region : QRegion(q->rect()); -
4938 if (!(renderFlags & QWidget::IgnoreMask) && extra && extra->hasMask) -
4939 toBePainted &= extra->mask; -
4940 return toBePainted; -
4941} -
4942 -
4943void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &toBePainted, -
4944 QWidget::RenderFlags renderFlags) -
4945{ -
4946 Q_ASSERT(painter); -
4947 Q_ASSERT(!toBePainted.isEmpty()); -
4948 -
4949 Q_Q(QWidget); -
4950#ifndef Q_WS_MAC -
4951 const QTransform originalTransform = painter->worldTransform(); -
4952 const bool useDeviceCoordinates = originalTransform.isScaling(); -
4953 if (!useDeviceCoordinates) { -
4954#endif -
4955 // Render via a pixmap. -
4956 const QRect rect = toBePainted.boundingRect(); -
4957 const QSize size = rect.size(); -
4958 if (size.isNull()) -
4959 return; -
4960 -
4961 QPixmap pixmap(size); -
4962 if (!(renderFlags & QWidget::DrawWindowBackground) || !isOpaque) -
4963 pixmap.fill(Qt::transparent); -
4964 q->render(&pixmap, QPoint(), toBePainted, renderFlags); -
4965 -
4966 const bool restore = !(painter->renderHints() & QPainter::SmoothPixmapTransform); -
4967 painter->setRenderHints(QPainter::SmoothPixmapTransform, true); -
4968 -
4969 painter->drawPixmap(targetOffset, pixmap); -
4970 -
4971 if (restore) -
4972 painter->setRenderHints(QPainter::SmoothPixmapTransform, false); -
4973 -
4974#ifndef Q_WS_MAC -
4975 } else { -
4976 // Render via a pixmap in device coordinates (to avoid pixmap scaling). -
4977 QTransform transform = originalTransform; -
4978 transform.translate(targetOffset.x(), targetOffset.y()); -
4979 -
4980 QPaintDevice *device = painter->device(); -
4981 Q_ASSERT(device); -
4982 -
4983 // Calculate device rect. -
4984 const QRectF rect(toBePainted.boundingRect()); -
4985 QRect deviceRect = transform.mapRect(QRectF(0, 0, rect.width(), rect.height())).toAlignedRect(); -
4986 deviceRect &= QRect(0, 0, device->width(), device->height()); -
4987 -
4988 QPixmap pixmap(deviceRect.size()); -
4989 pixmap.fill(Qt::transparent); -
4990 -
4991 // Create a pixmap device coordinate painter. -
4992 QPainter pixmapPainter(&pixmap); -
4993 pixmapPainter.setRenderHints(painter->renderHints()); -
4994 transform *= QTransform::fromTranslate(-deviceRect.x(), -deviceRect.y()); -
4995 pixmapPainter.setTransform(transform); -
4996 -
4997 q->render(&pixmapPainter, QPoint(), toBePainted, renderFlags); -
4998 pixmapPainter.end(); -
4999 -
5000 // And then draw the pixmap. -
5001 painter->setTransform(QTransform()); -
5002 painter->drawPixmap(deviceRect.topLeft(), pixmap); -
5003 painter->setTransform(originalTransform); -
5004 } -
5005#endif -
5006} -
5007 -
5008void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, -
5009 QPainter *sharedPainter, QWidgetBackingStore *backingStore) -
5010{ -
5011 if (rgn.isEmpty()) -
5012 return; -
5013 -
5014#ifdef Q_WS_MAC -
5015 if (qt_mac_clearDirtyOnWidgetInsideDrawWidget) -
5016 dirtyOnWidget = QRegion(); -
5017 -
5018 // We disable the rendering of QToolBar in the backingStore if -
5019 // it's supposed to be in the unified toolbar on Mac OS X. -
5020 if (backingStore && isInUnifiedToolbar) -
5021 return; -
5022#endif // Q_WS_MAC -
5023 -
5024 -
5025 Q_Q(QWidget); -
5026#ifndef QT_NO_GRAPHICSEFFECT -
5027 if (graphicsEffect && graphicsEffect->isEnabled()) { -
5028 QGraphicsEffectSource *source = graphicsEffect->d_func()->source; -
5029 QWidgetEffectSourcePrivate *sourced = static_cast<QWidgetEffectSourcePrivate *> -
5030 (source->d_func()); -
5031 if (!sourced->context) { -
5032 QWidgetPaintContext context(pdev, rgn, offset, flags, sharedPainter, backingStore); -
5033 sourced->context = &context; -
5034 if (!sharedPainter) { -
5035 setSystemClip(pdev, rgn.translated(offset)); -
5036 QPainter p(pdev); -
5037 p.translate(offset); -
5038 context.painter = &p; -
5039 graphicsEffect->draw(&p); -
5040 setSystemClip(pdev, QRegion()); -
5041 } else { -
5042 context.painter = sharedPainter; -
5043 if (sharedPainter->worldTransform() != sourced->lastEffectTransform) { -
5044 sourced->invalidateCache(); -
5045 sourced->lastEffectTransform = sharedPainter->worldTransform(); -
5046 } -
5047 sharedPainter->save(); -
5048 sharedPainter->translate(offset); -
5049 graphicsEffect->draw(sharedPainter); -
5050 sharedPainter->restore(); -
5051 } -
5052 sourced->context = 0; -
5053 return; -
5054 } -
5055 } -
5056#endif //QT_NO_GRAFFICSEFFECT -
5057 -
5058 const bool asRoot = flags & DrawAsRoot; -
5059 const bool alsoOnScreen = flags & DrawPaintOnScreen; -
5060 const bool recursive = flags & DrawRecursive; -
5061 const bool alsoInvisible = flags & DrawInvisible; -
5062 -
5063 Q_ASSERT(sharedPainter ? sharedPainter->isActive() : true); -
5064 -
5065 QRegion toBePainted(rgn); -
5066 if (asRoot && !alsoInvisible) -
5067 toBePainted &= clipRect(); //(rgn & visibleRegion()); -
5068 if (!(flags & DontSubtractOpaqueChildren)) -
5069 subtractOpaqueChildren(toBePainted, q->rect()); -
5070 -
5071 if (!toBePainted.isEmpty()) { -
5072 bool onScreen = paintOnScreen(); -
5073 if (!onScreen || alsoOnScreen) { -
5074 //update the "in paint event" flag -
5075 if (q->testAttribute(Qt::WA_WState_InPaintEvent)) -
5076 qWarning("QWidget::repaint: Recursive repaint detected"); -
5077 q->setAttribute(Qt::WA_WState_InPaintEvent); -
5078 -
5079 //clip away the new area -
5080#ifndef QT_NO_PAINT_DEBUG -
5081 bool flushed = QWidgetBackingStore::flushPaint(q, toBePainted); -
5082#endif -
5083 QPaintEngine *paintEngine = pdev->paintEngine(); -
5084 if (paintEngine) { -
5085 setRedirected(pdev, -offset); -
5086 -
5087#ifdef Q_WS_MAC -
5088 // (Alien support) Special case for Mac when redirecting: If the paint device -
5089 // is of the Widget type we need to set WA_WState_InPaintEvent since painting -
5090 // outside the paint event is not supported on QWidgets. The attributeis -
5091 // restored further down. -
5092 if (pdev->devType() == QInternal::Widget) -
5093 static_cast<QWidget *>(pdev)->setAttribute(Qt::WA_WState_InPaintEvent); -
5094 -
5095#endif -
5096 if (sharedPainter) -
5097 setSystemClip(pdev, toBePainted); -
5098 else -
5099 paintEngine->d_func()->systemRect = q->data->crect; -
5100 -
5101 //paint the background -
5102 if ((asRoot || q->autoFillBackground() || onScreen || q->testAttribute(Qt::WA_StyledBackground)) -
5103 && !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) { -
5104 QPainter p(q); -
5105 paintBackground(&p, toBePainted, (asRoot || onScreen) ? flags | DrawAsRoot : 0); -
5106 } -
5107 -
5108 if (!sharedPainter) -
5109 setSystemClip(pdev, toBePainted.translated(offset)); -
5110 -
5111 if (!onScreen && !asRoot && !isOpaque && q->testAttribute(Qt::WA_TintedBackground)) { -
5112 QPainter p(q); -
5113 QColor tint = q->palette().window().color(); -
5114 tint.setAlphaF(qreal(.6)); -
5115 p.fillRect(toBePainted.boundingRect(), tint); -
5116 } -
5117 } -
5118 -
5119#if 0 -
5120 qDebug() << "painting" << q << "opaque ==" << isOpaque(); -
5121 qDebug() << "clipping to" << toBePainted << "location == " << offset -
5122 << "geometry ==" << QRect(q->mapTo(q->window(), QPoint(0, 0)), q->size()); -
5123#endif -
5124 -
5125 //actually send the paint event -
5126 QPaintEvent e(toBePainted); -
5127 QCoreApplication::sendSpontaneousEvent(q, &e); -
5128 -
5129 // Native widgets need to be marked dirty on screen so painting will be done in correct context -
5130 if (backingStore && !onScreen && !asRoot && (q->internalWinId() || !q->nativeParentWidget()->isWindow())) -
5131 backingStore->markDirtyOnScreen(toBePainted, q, offset); -
5132 -
5133 //restore -
5134 if (paintEngine) { -
5135#ifdef Q_WS_MAC -
5136 if (pdev->devType() == QInternal::Widget) -
5137 static_cast<QWidget *>(pdev)->setAttribute(Qt::WA_WState_InPaintEvent, false); -
5138#endif -
5139 restoreRedirected(); -
5140 if (!sharedPainter) -
5141 paintEngine->d_func()->systemRect = QRect(); -
5142 else -
5143 paintEngine->d_func()->currentClipDevice = 0; -
5144 -
5145 setSystemClip(pdev, QRegion()); -
5146 } -
5147 q->setAttribute(Qt::WA_WState_InPaintEvent, false); -
5148 if (q->paintingActive()) -
5149 qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent"); -
5150 -
5151 if (paintEngine && paintEngine->autoDestruct()) { -
5152 delete paintEngine; -
5153 } -
5154 -
5155#ifndef QT_NO_PAINT_DEBUG -
5156 if (flushed) -
5157 QWidgetBackingStore::unflushPaint(q, toBePainted); -
5158#endif -
5159 } else if (q->isWindow()) { -
5160 QPaintEngine *engine = pdev->paintEngine(); -
5161 if (engine) { -
5162 QPainter p(pdev); -
5163 p.setClipRegion(toBePainted); -
5164 const QBrush bg = q->palette().brush(QPalette::Window); -
5165 if (bg.style() == Qt::TexturePattern) -
5166 p.drawTiledPixmap(q->rect(), bg.texture()); -
5167 else -
5168 p.fillRect(q->rect(), bg); -
5169 -
5170 if (engine->autoDestruct()) -
5171 delete engine; -
5172 } -
5173 } -
5174 } -
5175 -
5176 if (recursive && !children.isEmpty()) { -
5177 paintSiblingsRecursive(pdev, children, children.size() - 1, rgn, offset, flags & ~DrawAsRoot -
5178 , sharedPainter, backingStore); -
5179 } -
5180} -
5181 -
5182void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset, -
5183 const QRegion &sourceRegion, QWidget::RenderFlags renderFlags, -
5184 bool readyToRender) -
5185{ -
5186 if (!target) { -
5187 qWarning("QWidget::render: null pointer to paint device"); -
5188 return; -
5189 } -
5190 -
5191 const bool inRenderWithPainter = extra && extra->inRenderWithPainter; -
5192 QRegion paintRegion = !inRenderWithPainter && !readyToRender -
5193 ? prepareToRender(sourceRegion, renderFlags) -
5194 : sourceRegion; -
5195 if (paintRegion.isEmpty()) -
5196 return; -
5197 -
5198#ifndef Q_WS_MAC -
5199 QPainter *oldSharedPainter = inRenderWithPainter ? sharedPainter() : 0; -
5200 -
5201 // Use the target's shared painter if set (typically set when doing -
5202 // "other->render(widget);" in the widget's paintEvent. -
5203 if (target->devType() == QInternal::Widget) { -
5204 QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func(); -
5205 if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) { -
5206 QPainter *targetPainter = targetPrivate->sharedPainter(); -
5207 if (targetPainter && targetPainter->isActive()) -
5208 setSharedPainter(targetPainter); -
5209 } -
5210 } -
5211#endif -
5212 -
5213 // Use the target's redirected device if set and adjust offset and paint -
5214 // region accordingly. This is typically the case when people call render -
5215 // from the paintEvent. -
5216 QPoint offset = targetOffset; -
5217 offset -= paintRegion.boundingRect().topLeft(); -
5218 QPoint redirectionOffset; -
5219 QPaintDevice *redirected = 0; -
5220 -
5221 if (target->devType() == QInternal::Widget) -
5222 redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset); -
5223 if (!redirected) -
5224 redirected = QPainter::redirected(target, &redirectionOffset); -
5225 -
5226 if (redirected) { -
5227 target = redirected; -
5228 offset -= redirectionOffset; -
5229 } -
5230 -
5231 if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp). -
5232 if (QPaintEngine *targetEngine = target->paintEngine()) { -
5233 const QRegion targetSystemClip = targetEngine->systemClip(); -
5234 if (!targetSystemClip.isEmpty()) -
5235 paintRegion &= targetSystemClip.translated(-offset); -
5236 } -
5237 } -
5238 -
5239 // Set backingstore flags. -
5240 int flags = DrawPaintOnScreen | DrawInvisible; -
5241 if (renderFlags & QWidget::DrawWindowBackground) -
5242 flags |= DrawAsRoot; -
5243 -
5244 if (renderFlags & QWidget::DrawChildren) -
5245 flags |= DrawRecursive; -
5246 else -
5247 flags |= DontSubtractOpaqueChildren; -
5248 -
5249 flags |= DontSetCompositionMode; -
5250 -
5251 if (target->devType() == QInternal::Printer) { -
5252 QPainter p(target); -
5253 render_helper(&p, targetOffset, paintRegion, renderFlags); -
5254 return; -
5255 } -
5256 -
5257#ifndef Q_WS_MAC -
5258 // Render via backingstore. -
5259 drawWidget(target, paintRegion, offset, flags, sharedPainter()); -
5260 -
5261 // Restore shared painter. -
5262 if (oldSharedPainter) -
5263 setSharedPainter(oldSharedPainter); -
5264#else -
5265 // Render via backingstore (no shared painter). -
5266 drawWidget(target, paintRegion, offset, flags, 0); -
5267#endif -
5268} -
5269 -
5270void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn, -
5271 const QPoint &offset, int flags -
5272 , QPainter *sharedPainter, QWidgetBackingStore *backingStore) -
5273{ -
5274 QWidget *w = 0; -
5275 QRect boundingRect; -
5276 bool dirtyBoundingRect = true; -
5277 const bool exludeOpaqueChildren = (flags & DontDrawOpaqueChildren); -
5278 const bool excludeNativeChildren = (flags & DontDrawNativeChildren); -
5279 -
5280 do { -
5281 QWidget *x = qobject_cast<QWidget*>(siblings.at(index)); -
5282 if (x && !(exludeOpaqueChildren && x->d_func()->isOpaque) && !x->isHidden() && !x->isWindow() -
5283 && !(excludeNativeChildren && x->internalWinId())) { -
5284 if (dirtyBoundingRect) { -
5285 boundingRect = rgn.boundingRect(); -
5286 dirtyBoundingRect = false; -
5287 } -
5288 -
5289 if (qRectIntersects(boundingRect, x->d_func()->effectiveRectFor(x->data->crect))) { -
5290 w = x; -
5291 break; -
5292 } -
5293 } -
5294 --index; -
5295 } while (index >= 0); -
5296 -
5297 if (!w) -
5298 return; -
5299 -
5300 QWidgetPrivate *wd = w->d_func(); -
5301 const QPoint widgetPos(w->data->crect.topLeft()); -
5302 const bool hasMask = wd->extra && wd->extra->hasMask && !wd->graphicsEffect; -
5303 if (index > 0) { -
5304 QRegion wr(rgn); -
5305 if (wd->isOpaque) -
5306 wr -= hasMask ? wd->extra->mask.translated(widgetPos) : w->data->crect; -
5307 paintSiblingsRecursive(pdev, siblings, --index, wr, offset, flags -
5308 , sharedPainter, backingStore); -
5309 } -
5310 -
5311 if (w->updatesEnabled() -
5312#ifndef QT_NO_GRAPHICSVIEW -
5313 && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget) -
5314#endif //QT_NO_GRAPHICSVIEW -
5315 ) { -
5316 QRegion wRegion(rgn); -
5317 wRegion &= wd->effectiveRectFor(w->data->crect); -
5318 wRegion.translate(-widgetPos); -
5319 if (hasMask) -
5320 wRegion &= wd->extra->mask; -
5321 wd->drawWidget(pdev, wRegion, offset + widgetPos, flags, sharedPainter, backingStore); -
5322 } -
5323} -
5324 -
5325#ifndef QT_NO_GRAPHICSEFFECT -
5326QRectF QWidgetEffectSourcePrivate::boundingRect(Qt::CoordinateSystem system) const -
5327{ -
5328 if (system != Qt::DeviceCoordinates) -
5329 return m_widget->rect(); -
5330 -
5331 if (!context) { -
5332 // Device coordinates without context not yet supported. -
5333 qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context"); -
5334 return QRectF(); -
5335 } -
5336 -
5337 return context->painter->worldTransform().mapRect(m_widget->rect()); -
5338} -
5339 -
5340void QWidgetEffectSourcePrivate::draw(QPainter *painter) -
5341{ -
5342 if (!context || context->painter != painter) { -
5343 m_widget->render(painter); -
5344 return; -
5345 } -
5346 -
5347 // The region saved in the context is neither clipped to the rect -
5348 // nor the mask, so we have to clip it here before calling drawWidget. -
5349 QRegion toBePainted = context->rgn; -
5350 toBePainted &= m_widget->rect(); -
5351 QWidgetPrivate *wd = qt_widget_private(m_widget); -
5352 if (wd->extra && wd->extra->hasMask) -
5353 toBePainted &= wd->extra->mask; -
5354 -
5355 wd->drawWidget(context->pdev, toBePainted, context->offset, context->flags, -
5356 context->sharedPainter, context->backingStore); -
5357} -
5358 -
5359QPixmap QWidgetEffectSourcePrivate::pixmap(Qt::CoordinateSystem system, QPoint *offset, -
5360 QGraphicsEffect::PixmapPadMode mode) const -
5361{ -
5362 const bool deviceCoordinates = (system == Qt::DeviceCoordinates); -
5363 if (!context && deviceCoordinates) { -
5364 // Device coordinates without context not yet supported. -
5365 qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context"); -
5366 return QPixmap(); -
5367 } -
5368 -
5369 QPoint pixmapOffset; -
5370 QRectF sourceRect = m_widget->rect(); -
5371 -
5372 if (deviceCoordinates) { -
5373 const QTransform &painterTransform = context->painter->worldTransform(); -
5374 sourceRect = painterTransform.mapRect(sourceRect); -
5375 pixmapOffset = painterTransform.map(pixmapOffset); -
5376 } -
5377 -
5378 QRect effectRect; -
5379 -
5380 if (mode == QGraphicsEffect::PadToEffectiveBoundingRect) -
5381 effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect(); -
5382 else if (mode == QGraphicsEffect::PadToTransparentBorder) -
5383 effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect(); -
5384 else -
5385 effectRect = sourceRect.toAlignedRect(); -
5386 -
5387 if (offset) -
5388 *offset = effectRect.topLeft(); -
5389 -
5390 pixmapOffset -= effectRect.topLeft(); -
5391 -
5392 QPixmap pixmap(effectRect.size()); -
5393 pixmap.fill(Qt::transparent); -
5394 m_widget->render(&pixmap, pixmapOffset, QRegion(), QWidget::DrawChildren); -
5395 return pixmap; -
5396} -
5397#endif //QT_NO_GRAPHICSEFFECT -
5398 -
5399#ifndef QT_NO_GRAPHICSVIEW -
5400/*! -
5401 \internal -
5402 -
5403 Finds the nearest widget embedded in a graphics proxy widget along the chain formed by this -
5404 widget and its ancestors. The search starts at \a origin (inclusive). -
5405 If successful, the function returns the proxy that embeds the widget, or 0 if no embedded -
5406 widget was found. -
5407*/ -
5408QGraphicsProxyWidget * QWidgetPrivate::nearestGraphicsProxyWidget(const QWidget *origin) -
5409{ -
5410 if (origin) { -
5411 QWExtra *extra = origin->d_func()->extra; -
5412 if (extra && extra->proxyWidget) -
5413 return extra->proxyWidget; -
5414 return nearestGraphicsProxyWidget(origin->parentWidget()); -
5415 } -
5416 return 0; -
5417} -
5418#endif -
5419 -
5420/*! -
5421 \property QWidget::locale -
5422 \brief the widget's locale -
5423 \since 4.3 -
5424 -
5425 As long as no special locale has been set, this is either -
5426 the parent's locale or (if this widget is a top level widget), -
5427 the default locale. -
5428 -
5429 If the widget displays dates or numbers, these should be formatted -
5430 using the widget's locale. -
5431 -
5432 \sa QLocale, QLocale::setDefault() -
5433*/ -
5434 -
5435void QWidgetPrivate::setLocale_helper(const QLocale &loc, bool forceUpdate) -
5436{ -
5437 Q_Q(QWidget); -
5438 if (locale == loc && !forceUpdate) -
5439 return; -
5440 -
5441 locale = loc; -
5442 -
5443 if (!children.isEmpty()) { -
5444 for (int i = 0; i < children.size(); ++i) { -
5445 QWidget *w = qobject_cast<QWidget*>(children.at(i)); -
5446 if (!w) -
5447 continue; -
5448 if (w->testAttribute(Qt::WA_SetLocale)) -
5449 continue; -
5450 if (w->isWindow() && !w->testAttribute(Qt::WA_WindowPropagation)) -
5451 continue; -
5452 w->d_func()->setLocale_helper(loc, forceUpdate); -
5453 } -
5454 } -
5455 QEvent e(QEvent::LocaleChange); -
5456 QApplication::sendEvent(q, &e); -
5457} -
5458 -
5459void QWidget::setLocale(const QLocale &locale) -
5460{ -
5461 Q_D(QWidget); -
5462 -
5463 setAttribute(Qt::WA_SetLocale); -
5464 d->setLocale_helper(locale); -
5465} -
5466 -
5467QLocale QWidget::locale() const -
5468{ -
5469 Q_D(const QWidget); -
5470 -
5471 return d->locale; -
5472} -
5473 -
5474void QWidgetPrivate::resolveLocale() -
5475{ -
5476 Q_Q(const QWidget); -
5477 -
5478 if (!q->testAttribute(Qt::WA_SetLocale)) { -
5479 setLocale_helper(q->isWindow() -
5480 ? QLocale() -
5481 : q->parentWidget()->locale()); -
5482 } -
5483} -
5484 -
5485void QWidget::unsetLocale() -
5486{ -
5487 Q_D(QWidget); -
5488 setAttribute(Qt::WA_SetLocale, false); -
5489 d->resolveLocale(); -
5490} -
5491 -
5492/*! -
5493 \property QWidget::windowTitle -
5494 \brief the window title (caption) -
5495 -
5496 This property only makes sense for top-level widgets, such as -
5497 windows and dialogs. If no caption has been set, the title is based of the -
5498 \l windowFilePath. If neither of these is set, then the title is -
5499 an empty string. -
5500 -
5501 If you use the \l windowModified mechanism, the window title must -
5502 contain a "[*]" placeholder, which indicates where the '*' should -
5503 appear. Normally, it should appear right after the file name -
5504 (e.g., "document1.txt[*] - Text Editor"). If the \l -
5505 windowModified property is false (the default), the placeholder -
5506 is simply removed. -
5507 -
5508 On some desktop platforms (including Windows and Unix), the application name -
5509 (from QGuiApplication::applicationDisplayName) is added at the end of the -
5510 window title, if set. This is done by the QPA plugin, so it is shown to the -
5511 user, but isn't part of the \l windowTitle string. -
5512 -
5513 \sa windowIcon, windowIconText, windowModified, windowFilePath -
5514*/ -
5515QString QWidget::windowTitle() const -
5516{ -
5517 Q_D(const QWidget); -
5518 if (d->extra && d->extra->topextra) { -
5519 if (!d->extra->topextra->caption.isEmpty()) -
5520 return d->extra->topextra->caption; -
5521 if (!d->extra->topextra->filePath.isEmpty()) -
5522 return QFileInfo(d->extra->topextra->filePath).fileName() + QLatin1String("[*]"); -
5523 } -
5524 return QString(); -
5525} -
5526 -
5527/*! -
5528 Returns a modified window title with the [*] place holder -
5529 replaced according to the rules described in QWidget::setWindowTitle -
5530 -
5531 This function assumes that "[*]" can be quoted by another -
5532 "[*]", so it will replace two place holders by one and -
5533 a single last one by either "*" or nothing depending on -
5534 the modified flag. -
5535 -
5536 \internal -
5537*/ -
5538QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widget) -
5539{ -
5540 Q_ASSERT(widget); -
5541 -
5542#ifdef QT_EVAL -
5543 extern QString qt_eval_adapt_window_title(const QString &title); -
5544 QString cap = qt_eval_adapt_window_title(title); -
5545#else -
5546 QString cap = title; -
5547#endif -
5548 -
5549 if (cap.isEmpty()) -
5550 return cap; -
5551 -
5552 QLatin1String placeHolder("[*]"); -
5553 int index = cap.indexOf(placeHolder); -
5554 -
5555 // here the magic begins -
5556 while (index != -1) { -
5557 index += placeHolder.size(); -
5558 int count = 1; -
5559 while (cap.indexOf(placeHolder, index) == index) { -
5560 ++count; -
5561 index += placeHolder.size(); -
5562 } -
5563 -
5564 if (count%2) { // odd number of [*] -> replace last one -
5565 int lastIndex = cap.lastIndexOf(placeHolder, index - 1); -
5566 if (widget->isWindowModified() -
5567 && widget->style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, widget)) -
5568 cap.replace(lastIndex, 3, QWidget::tr("*")); -
5569 else -
5570 cap.remove(lastIndex, 3); -
5571 } -
5572 -
5573 index = cap.indexOf(placeHolder, index); -
5574 } -
5575 -
5576 cap.replace(QLatin1String("[*][*]"), placeHolder); -
5577 -
5578 return cap; -
5579} -
5580 -
5581void QWidgetPrivate::setWindowTitle_helper(const QString &title) -
5582{ -
5583 Q_Q(QWidget); -
5584 if (q->testAttribute(Qt::WA_WState_Created)) -
5585 setWindowTitle_sys(qt_setWindowTitle_helperHelper(title, q)); -
5586} -
5587 -
5588void QWidgetPrivate::setWindowIconText_helper(const QString &title) -
5589{ -
5590 Q_Q(QWidget); -
5591 if (q->testAttribute(Qt::WA_WState_Created)) -
5592 setWindowIconText_sys(qt_setWindowTitle_helperHelper(title, q)); -
5593} -
5594 -
5595void QWidget::setWindowIconText(const QString &iconText) -
5596{ -
5597 if (QWidget::windowIconText() == iconText) -
5598 return; -
5599 -
5600 Q_D(QWidget); -
5601 d->topData()->iconText = iconText; -
5602 d->setWindowIconText_helper(iconText); -
5603 -
5604 QEvent e(QEvent::IconTextChange); -
5605 QApplication::sendEvent(this, &e); -
5606} -
5607 -
5608void QWidget::setWindowTitle(const QString &title) -
5609{ -
5610 if (QWidget::windowTitle() == title && !title.isEmpty() && !title.isNull()) -
5611 return; -
5612 -
5613 Q_D(QWidget); -
5614 d->topData()->caption = title; -
5615 d->setWindowTitle_helper(title); -
5616 -
5617 QEvent e(QEvent::WindowTitleChange); -
5618 QApplication::sendEvent(this, &e); -
5619} -
5620 -
5621 -
5622/*! -
5623 \property QWidget::windowIcon -
5624 \brief the widget's icon -
5625 -
5626 This property only makes sense for windows. If no icon -
5627 has been set, windowIcon() returns the application icon -
5628 (QApplication::windowIcon()). -
5629 -
5630 \sa windowIconText, windowTitle -
5631*/ -
5632QIcon QWidget::windowIcon() const -
5633{ -
5634 const QWidget *w = this; -
5635 while (w) { -
5636 const QWidgetPrivate *d = w->d_func(); -
5637 if (d->extra && d->extra->topextra && d->extra->topextra->icon) -
5638 return *d->extra->topextra->icon; -
5639 w = w->parentWidget(); -
5640 } -
5641 return QApplication::windowIcon(); -
5642} -
5643 -
5644void QWidgetPrivate::setWindowIcon_helper() -
5645{ -
5646 QEvent e(QEvent::WindowIconChange); -
5647 QApplication::sendEvent(q_func(), &e); -
5648 for (int i = 0; i < children.size(); ++i) { -
5649 QWidget *w = qobject_cast<QWidget *>(children.at(i)); -
5650 if (w && !w->isWindow()) -
5651 QApplication::sendEvent(w, &e); -
5652 } -
5653} -
5654 -
5655void QWidget::setWindowIcon(const QIcon &icon) -
5656{ -
5657 Q_D(QWidget); -
5658 -
5659 setAttribute(Qt::WA_SetWindowIcon, !icon.isNull()); -
5660 d->createTLExtra(); -
5661 -
5662 if (!d->extra->topextra->icon) -
5663 d->extra->topextra->icon = new QIcon(); -
5664 *d->extra->topextra->icon = icon; -
5665 -
5666 d->setWindowIcon_sys(); -
5667 d->setWindowIcon_helper(); -
5668} -
5669 -
5670 -
5671/*! -
5672 \property QWidget::windowIconText -
5673 \brief the widget's icon text -
5674 -
5675 This property only makes sense for windows. If no icon -
5676 text has been set, this functions returns an empty string. -
5677 -
5678 \sa windowIcon, windowTitle -
5679*/ -
5680 -
5681QString QWidget::windowIconText() const -
5682{ -
5683 Q_D(const QWidget); -
5684 return (d->extra && d->extra->topextra) ? d->extra->topextra->iconText : QString(); -
5685} -
5686 -
5687/*! -
5688 \property QWidget::windowFilePath -
5689 \since 4.4 -
5690 \brief the file path associated with a widget -
5691 -
5692 This property only makes sense for windows. It associates a file path with -
5693 a window. If you set the file path, but have not set the window title, Qt -
5694 sets the window title to the file name of the specified path, obtained using -
5695 QFileInfo::fileName(). -
5696 -
5697 If the window title is set at any point, then the window title takes precedence and -
5698 will be shown instead of the file path string. -
5699 -
5700 Additionally, on Mac OS X, this has an added benefit that it sets the -
5701 \l{http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/XHIGWindows/chapter_17_section_3.html}{proxy icon} -
5702 for the window, assuming that the file path exists. -
5703 -
5704 If no file path is set, this property contains an empty string. -
5705 -
5706 By default, this property contains an empty string. -
5707 -
5708 \sa windowTitle, windowIcon -
5709*/ -
5710 -
5711QString QWidget::windowFilePath() const -
5712{ -
5713 Q_D(const QWidget); -
5714 return (d->extra && d->extra->topextra) ? d->extra->topextra->filePath : QString(); -
5715} -
5716 -
5717void QWidget::setWindowFilePath(const QString &filePath) -
5718{ -
5719 if (filePath == windowFilePath()) -
5720 return; -
5721 -
5722 Q_D(QWidget); -
5723 -
5724 d->createTLExtra(); -
5725 d->extra->topextra->filePath = filePath; -
5726 d->setWindowFilePath_helper(filePath); -
5727} -
5728 -
5729void QWidgetPrivate::setWindowFilePath_helper(const QString &filePath) -
5730{ -
5731 if (extra->topextra && extra->topextra->caption.isEmpty()) { -
5732#ifdef Q_OS_MAC -
5733 setWindowTitle_helper(QFileInfo(filePath).fileName()); -
5734#else -
5735 Q_Q(QWidget); -
5736 Q_UNUSED(filePath); -
5737 setWindowTitle_helper(q->windowTitle()); -
5738#endif -
5739 } -
5740#ifdef Q_OS_MAC -
5741 setWindowFilePath_sys(filePath); -
5742#endif -
5743} -
5744 -
5745/*! -
5746 Returns the window's role, or an empty string. -
5747 -
5748 \sa windowIcon, windowTitle -
5749*/ -
5750 -
5751QString QWidget::windowRole() const -
5752{ -
5753 Q_D(const QWidget); -
5754 return (d->extra && d->extra->topextra) ? d->extra->topextra->role : QString(); -
5755} -
5756 -
5757/*! -
5758 Sets the window's role to \a role. This only makes sense for -
5759 windows on X11. -
5760*/ -
5761void QWidget::setWindowRole(const QString &role) -
5762{ -
5763#if defined(Q_WS_X11) -
5764 Q_D(QWidget); -
5765 d->topData()->role = role; -
5766 d->setWindowRole(); -
5767#else -
5768 Q_UNUSED(role) -
5769#endif -
5770} -
5771 -
5772/*! -
5773 \property QWidget::mouseTracking -
5774 \brief whether mouse tracking is enabled for the widget -
5775 -
5776 If mouse tracking is disabled (the default), the widget only -
5777 receives mouse move events when at least one mouse button is -
5778 pressed while the mouse is being moved. -
5779 -
5780 If mouse tracking is enabled, the widget receives mouse move -
5781 events even if no buttons are pressed. -
5782 -
5783 \sa mouseMoveEvent() -
5784*/ -
5785 -
5786 -
5787/*! -
5788 Sets the widget's focus proxy to widget \a w. If \a w is 0, the -
5789 function resets this widget to have no focus proxy. -
5790 -
5791 Some widgets can "have focus", but create a child widget, such as -
5792 QLineEdit, to actually handle the focus. In this case, the widget -
5793 can set the line edit to be its focus proxy. -
5794 -
5795 setFocusProxy() sets the widget which will actually get focus when -
5796 "this widget" gets it. If there is a focus proxy, setFocus() and -
5797 hasFocus() operate on the focus proxy. -
5798 -
5799 \sa focusProxy() -
5800*/ -
5801 -
5802void QWidget::setFocusProxy(QWidget * w) -
5803{ -
5804 Q_D(QWidget); -
5805 if (!w && !d->extra) -
5806 return; -
5807 -
5808 for (QWidget* fp = w; fp; fp = fp->focusProxy()) { -
5809 if (fp == this) { -
5810 qWarning("QWidget: %s (%s) already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData()); -
5811 return; -
5812 } -
5813 } -
5814 -
5815 d->createExtra(); -
5816 d->extra->focus_proxy = w; -
5817} -
5818 -
5819 -
5820/*! -
5821 Returns the focus proxy, or 0 if there is no focus proxy. -
5822 -
5823 \sa setFocusProxy() -
5824*/ -
5825 -
5826QWidget * QWidget::focusProxy() const -
5827{ -
5828 Q_D(const QWidget); -
5829 return d->extra ? (QWidget *)d->extra->focus_proxy : 0; -
5830} -
5831 -
5832 -
5833/*! -
5834 \property QWidget::focus -
5835 \brief whether this widget (or its focus proxy) has the keyboard -
5836 input focus -
5837 -
5838 By default, this property is false. -
5839 -
5840 \note Obtaining the value of this property for a widget is effectively equivalent -
5841 to checking whether QApplication::focusWidget() refers to the widget. -
5842 -
5843 \sa setFocus(), clearFocus(), setFocusPolicy(), QApplication::focusWidget() -
5844*/ -
5845bool QWidget::hasFocus() const -
5846{ -
5847 const QWidget* w = this; -
5848 while (w->d_func()->extra && w->d_func()->extra->focus_proxy) -
5849 w = w->d_func()->extra->focus_proxy; -
5850 if (QWidget *window = w->window()) { -
5851#ifndef QT_NO_GRAPHICSVIEW -
5852 QWExtra *e = window->d_func()->extra; -
5853 if (e && e->proxyWidget && e->proxyWidget->hasFocus() && window->focusWidget() == w) -
5854 return true; -
5855#endif -
5856 } -
5857 return (QApplication::focusWidget() == w); -
5858} -
5859 -
5860/*! -
5861 Gives the keyboard input focus to this widget (or its focus -
5862 proxy) if this widget or one of its parents is the \l{isActiveWindow()}{active window}. The \a reason argument will -
5863 be passed into any focus event sent from this function, it is used -
5864 to give an explanation of what caused the widget to get focus. -
5865 If the window is not active, the widget will be given the focus when -
5866 the window becomes active. -
5867 -
5868 First, a focus about to change event is sent to the focus widget (if any) to -
5869 tell it that it is about to lose the focus. Then focus is changed, a -
5870 focus out event is sent to the previous focus item and a focus in event is sent -
5871 to the new item to tell it that it just received the focus. -
5872 (Nothing happens if the focus in and focus out widgets are the -
5873 same.) -
5874 -
5875 \note On embedded platforms, setFocus() will not cause an input panel -
5876 to be opened by the input method. If you want this to happen, you -
5877 have to send a QEvent::RequestSoftwareInputPanel event to the -
5878 widget yourself. -
5879 -
5880 setFocus() gives focus to a widget regardless of its focus policy, -
5881 but does not clear any keyboard grab (see grabKeyboard()). -
5882 -
5883 Be aware that if the widget is hidden, it will not accept focus -
5884 until it is shown. -
5885 -
5886 \warning If you call setFocus() in a function which may itself be -
5887 called from focusOutEvent() or focusInEvent(), you may get an -
5888 infinite recursion. -
5889 -
5890 \sa hasFocus(), clearFocus(), focusInEvent(), focusOutEvent(), -
5891 setFocusPolicy(), focusWidget(), QApplication::focusWidget(), grabKeyboard(), -
5892 grabMouse(), {Keyboard Focus in Widgets}, QEvent::RequestSoftwareInputPanel -
5893*/ -
5894 -
5895void QWidget::setFocus(Qt::FocusReason reason) -
5896{ -
5897 if (!isEnabled()) -
5898 return; -
5899 -
5900 QWidget *f = this; -
5901 while (f->d_func()->extra && f->d_func()->extra->focus_proxy) -
5902 f = f->d_func()->extra->focus_proxy; -
5903 -
5904 if (QApplication::focusWidget() == f -
5905#if defined(Q_WS_WIN) -
5906 && GetFocus() == f->internalWinId() -
5907#endif -
5908 ) -
5909 return; -
5910 -
5911#ifndef QT_NO_GRAPHICSVIEW -
5912 QWidget *previousProxyFocus = 0; -
5913 if (QWExtra *topData = window()->d_func()->extra) { -
5914 if (topData->proxyWidget && topData->proxyWidget->hasFocus()) { -
5915 previousProxyFocus = topData->proxyWidget->widget()->focusWidget(); -
5916 if (previousProxyFocus && previousProxyFocus->focusProxy()) -
5917 previousProxyFocus = previousProxyFocus->focusProxy(); -
5918 if (previousProxyFocus == this && !topData->proxyWidget->d_func()->proxyIsGivingFocus) -
5919 return; -
5920 } -
5921 } -
5922#endif -
5923 -
5924#ifndef QT_NO_GRAPHICSVIEW -
5925 // Update proxy state -
5926 if (QWExtra *topData = window()->d_func()->extra) { -
5927 if (topData->proxyWidget && !topData->proxyWidget->hasFocus()) { -
5928 f->d_func()->updateFocusChild(); -
5929 topData->proxyWidget->d_func()->focusFromWidgetToProxy = 1; -
5930 topData->proxyWidget->setFocus(reason); -
5931 topData->proxyWidget->d_func()->focusFromWidgetToProxy = 0; -
5932 } -
5933 } -
5934#endif -
5935 -
5936 if (f->isActiveWindow()) { -
5937 QWidget *prev = QApplicationPrivate::focus_widget; -
5938 if (prev) { -
5939 if (reason != Qt::PopupFocusReason && reason != Qt::MenuBarFocusReason -
5940 && prev->testAttribute(Qt::WA_InputMethodEnabled)) { -
5941 qApp->inputMethod()->commit(); -
5942 } -
5943 -
5944 if (reason != Qt::NoFocusReason) { -
5945 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange, reason); -
5946 QApplication::sendEvent(prev, &focusAboutToChange); -
5947 } -
5948 } -
5949 -
5950 f->d_func()->updateFocusChild(); -
5951 -
5952 QApplicationPrivate::setFocusWidget(f, reason); -
5953#ifndef QT_NO_ACCESSIBILITY -
5954# ifdef Q_OS_WIN -
5955 // The negation of the condition in setFocus_sys -
5956 if (!(testAttribute(Qt::WA_WState_Created) && window()->windowType() != Qt::Popup && internalWinId())) -
5957 //setFocusWidget will already post a focus event for us (that the AT client receives) on Windows -
5958# endif -
5959# ifdef Q_OS_UNIX -
5960 // menus update the focus manually and this would create bogus events -
5961 if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem"))) -
5962# endif -
5963 { -
5964 QAccessibleEvent event(f, QAccessible::Focus); -
5965 QAccessible::updateAccessibility(&event); -
5966 } -
5967#endif -
5968#ifndef QT_NO_GRAPHICSVIEW -
5969 if (QWExtra *topData = window()->d_func()->extra) { -
5970 if (topData->proxyWidget) { -
5971 if (previousProxyFocus && previousProxyFocus != f) { -
5972 // Send event to self -
5973 QFocusEvent event(QEvent::FocusOut, reason); -
5974 QPointer<QWidget> that = previousProxyFocus; -
5975 QApplication::sendEvent(previousProxyFocus, &event); -
5976 if (that) -
5977 QApplication::sendEvent(that->style(), &event); -
5978 } -
5979 if (!isHidden()) { -
5980#ifndef QT_NO_GRAPHICSVIEW -
5981 // Update proxy state -
5982 if (QWExtra *topData = window()->d_func()->extra) -
5983 if (topData->proxyWidget && topData->proxyWidget->hasFocus()) -
5984 topData->proxyWidget->d_func()->updateProxyInputMethodAcceptanceFromWidget(); -
5985#endif -
5986 // Send event to self -
5987 QFocusEvent event(QEvent::FocusIn, reason); -
5988 QPointer<QWidget> that = f; -
5989 QApplication::sendEvent(f, &event); -
5990 if (that) -
5991 QApplication::sendEvent(that->style(), &event); -
5992 } -
5993 } -
5994 } -
5995#endif -
5996 } else { -
5997 f->d_func()->updateFocusChild(); -
5998 } -
5999 -
6000 if (QTLWExtra *extra = f->window()->d_func()->maybeTopData()) { -
6001 if (extra->window) -
6002 emit extra->window->focusObjectChanged(f); -
6003 } -
6004} -
6005 -
6006// updates focus_child on parent widgets to point into this widget -
6007void QWidgetPrivate::updateFocusChild() -
6008{ -
6009 Q_Q(QWidget); -
6010 -
6011 QWidget *w = q; -
6012 if (q->isHidden()) { -
6013 while (w && w->isHidden()) { -
6014 w->d_func()->focus_child = q; -
6015 w = w->isWindow() ? 0 : w->parentWidget(); -
6016 } -
6017 } else { -
6018 while (w) { -
6019 w->d_func()->focus_child = q; -
6020 w = w->isWindow() ? 0 : w->parentWidget(); -
6021 } -
6022 } -
6023} -
6024 -
6025/*! -
6026 \fn void QWidget::setFocus() -
6027 \overload -
6028 -
6029 Gives the keyboard input focus to this widget (or its focus -
6030 proxy) if this widget or one of its parents is the -
6031 \l{isActiveWindow()}{active window}. -
6032*/ -
6033 -
6034/*! -
6035 Takes keyboard input focus from the widget. -
6036 -
6037 If the widget has active focus, a \l{focusOutEvent()}{focus out event} is sent to this widget to tell it that it has -
6038 lost the focus. -
6039 -
6040 This widget must enable focus setting in order to get the keyboard -
6041 input focus, i.e. it must call setFocusPolicy(). -
6042 -
6043 \sa hasFocus(), setFocus(), focusInEvent(), focusOutEvent(), -
6044 setFocusPolicy(), QApplication::focusWidget() -
6045*/ -
6046 -
6047void QWidget::clearFocus() -
6048{ -
6049 if (hasFocus()) { -
6050 if (testAttribute(Qt::WA_InputMethodEnabled)) -
6051 qApp->inputMethod()->commit(); -
6052 -
6053 QFocusEvent focusAboutToChange(QEvent::FocusAboutToChange); -
6054 QApplication::sendEvent(this, &focusAboutToChange); -
6055 } -
6056 -
6057 QWidget *w = this; -
6058 while (w) { -
6059 if (w->d_func()->focus_child == this) -
6060 w->d_func()->focus_child = 0; -
6061 w = w->parentWidget(); -
6062 } -
6063#ifndef QT_NO_GRAPHICSVIEW -
6064 QWExtra *topData = d_func()->extra; -
6065 if (topData && topData->proxyWidget) -
6066 topData->proxyWidget->clearFocus(); -
6067#endif -
6068 -
6069 if (hasFocus()) { -
6070 // Update proxy state -
6071 QApplicationPrivate::setFocusWidget(0, Qt::OtherFocusReason); -
6072#if defined(Q_WS_WIN) -
6073 if (!(windowType() == Qt::Popup) && GetFocus() == internalWinId()) -
6074 SetFocus(0); -
6075 else -
6076#endif -
6077 { -
6078#ifndef QT_NO_ACCESSIBILITY -
6079 QAccessibleEvent event(this, QAccessible::Focus); -
6080 QAccessible::updateAccessibility(&event); -
6081#endif -
6082 } -
6083 } -
6084} -
6085 -
6086 -
6087/*! -
6088 \fn bool QWidget::focusNextChild() -
6089 -
6090 Finds a new widget to give the keyboard focus to, as appropriate -
6091 for \uicontrol Tab, and returns true if it can find a new widget, or -
6092 false if it can't. -
6093 -
6094 \sa focusPreviousChild() -
6095*/ -
6096 -
6097/*! -
6098 \fn bool QWidget::focusPreviousChild() -
6099 -
6100 Finds a new widget to give the keyboard focus to, as appropriate -
6101 for \uicontrol Shift+Tab, and returns true if it can find a new widget, -
6102 or false if it can't. -
6103 -
6104 \sa focusNextChild() -
6105*/ -
6106 -
6107/*! -
6108 Finds a new widget to give the keyboard focus to, as appropriate -
6109 for Tab and Shift+Tab, and returns true if it can find a new -
6110 widget, or false if it can't. -
6111 -
6112 If \a next is true, this function searches forward, if \a next -
6113 is false, it searches backward. -
6114 -
6115 Sometimes, you will want to reimplement this function. For -
6116 example, a web browser might reimplement it to move its "current -
6117 active link" forward or backward, and call -
6118 focusNextPrevChild() only when it reaches the last or -
6119 first link on the "page". -
6120 -
6121 Child widgets call focusNextPrevChild() on their parent widgets, -
6122 but only the window that contains the child widgets decides where -
6123 to redirect focus. By reimplementing this function for an object, -
6124 you thus gain control of focus traversal for all child widgets. -
6125 -
6126 \sa focusNextChild(), focusPreviousChild() -
6127*/ -
6128 -
6129bool QWidget::focusNextPrevChild(bool next) -
6130{ -
6131 Q_D(QWidget); -
6132 QWidget* p = parentWidget(); -
6133 bool isSubWindow = (windowType() == Qt::SubWindow); -
6134 if (!isWindow() && !isSubWindow && p) -
6135 return p->focusNextPrevChild(next); -
6136#ifndef QT_NO_GRAPHICSVIEW -
6137 if (d->extra && d->extra->proxyWidget) -
6138 return d->extra->proxyWidget->focusNextPrevChild(next); -
6139#endif -
6140 QWidget *w = QApplicationPrivate::focusNextPrevChild_helper(this, next); -
6141 if (!w) return false; -
6142 -
6143 w->setFocus(next ? Qt::TabFocusReason : Qt::BacktabFocusReason); -
6144 return true; -
6145} -
6146 -
6147/*! -
6148 Returns the last child of this widget that setFocus had been -
6149 called on. For top level widgets this is the widget that will get -
6150 focus in case this window gets activated -
6151 -
6152 This is not the same as QApplication::focusWidget(), which returns -
6153 the focus widget in the currently active window. -
6154*/ -
6155 -
6156QWidget *QWidget::focusWidget() const -
6157{ -
6158 return const_cast<QWidget *>(d_func()->focus_child); -
6159} -
6160 -
6161/*! -
6162 Returns the next widget in this widget's focus chain. -
6163 -
6164 \sa previousInFocusChain() -
6165*/ -
6166QWidget *QWidget::nextInFocusChain() const -
6167{ -
6168 return const_cast<QWidget *>(d_func()->focus_next); -
6169} -
6170 -
6171/*! -
6172 \brief The previousInFocusChain function returns the previous -
6173 widget in this widget's focus chain. -
6174 -
6175 \sa nextInFocusChain() -
6176 -
6177 \since 4.6 -
6178*/ -
6179QWidget *QWidget::previousInFocusChain() const -
6180{ -
6181 return const_cast<QWidget *>(d_func()->focus_prev); -
6182} -
6183 -
6184/*! -
6185 \property QWidget::isActiveWindow -
6186 \brief whether this widget's window is the active window -
6187 -
6188 The active window is the window that contains the widget that has -
6189 keyboard focus (The window may still have focus if it has no -
6190 widgets or none of its widgets accepts keyboard focus). -
6191 -
6192 When popup windows are visible, this property is true for both the -
6193 active window \e and for the popup. -
6194 -
6195 By default, this property is false. -
6196 -
6197 \sa activateWindow(), QApplication::activeWindow() -
6198*/ -
6199bool QWidget::isActiveWindow() const -
6200{ -
6201 QWidget *tlw = window(); -
6202 if(tlw == QApplication::activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup))) -
6203 return true; -
6204 -
6205#ifndef QT_NO_GRAPHICSVIEW -
6206 if (QWExtra *tlwExtra = tlw->d_func()->extra) { -
6207 if (isVisible() && tlwExtra->proxyWidget) -
6208 return tlwExtra->proxyWidget->isActiveWindow(); -
6209 } -
6210#endif -
6211 -
6212 if(style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, this)) { -
6213 if(tlw->windowType() == Qt::Tool && -
6214 !tlw->isModal() && -
6215 (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow())) -
6216 return true; -
6217 QWidget *w = QApplication::activeWindow(); -
6218 while(w && tlw->windowType() == Qt::Tool && -
6219 !w->isModal() && w->parentWidget()) { -
6220 w = w->parentWidget()->window(); -
6221 if(w == tlw) -
6222 return true; -
6223 } -
6224 } -
6225 -
6226 // Check if platform adaptation thinks the window is active. This is necessary for -
6227 // example in case of ActiveQt servers that are embedded into another application. -
6228 // Those are separate processes that are not part of the parent application Qt window/widget -
6229 // hierarchy, so they need to rely on native methods to determine if they are part of the -
6230 // active window. -
6231 if (const QWindow *w = tlw->windowHandle()) { -
6232 if (w->handle()) -
6233 return w->handle()->isActive(); -
6234 } -
6235 -
6236 return false; -
6237} -
6238 -
6239/*! -
6240 Puts the \a second widget after the \a first widget in the focus order. -
6241 -
6242 Note that since the tab order of the \a second widget is changed, you -
6243 should order a chain like this: -
6244 -
6245 \snippet code/src_gui_kernel_qwidget.cpp 9 -
6246 -
6247 \e not like this: -
6248 -
6249 \snippet code/src_gui_kernel_qwidget.cpp 10 -
6250 -
6251 If \a first or \a second has a focus proxy, setTabOrder() -
6252 correctly substitutes the proxy. -
6253 -
6254 \sa setFocusPolicy(), setFocusProxy(), {Keyboard Focus in Widgets} -
6255*/ -
6256void QWidget::setTabOrder(QWidget* first, QWidget *second) -
6257{ -
6258 if (!first || !second || first->focusPolicy() == Qt::NoFocus || second->focusPolicy() == Qt::NoFocus) -
6259 return; -
6260 -
6261 if (first->window() != second->window()) { -
6262 qWarning("QWidget::setTabOrder: 'first' and 'second' must be in the same window"); -
6263 return; -
6264 } -
6265 -
6266 QWidget *fp = first->focusProxy(); -
6267 if (fp) { -
6268 // If first is redirected, set first to the last child of first -
6269 // that can take keyboard focus so that second is inserted after -
6270 // that last child, and the focus order within first is (more -
6271 // likely to be) preserved. -
6272 QList<QWidget *> l = first->findChildren<QWidget *>(); -
6273 for (int i = l.size()-1; i >= 0; --i) { -
6274 QWidget * next = l.at(i); -
6275 if (next->window() == fp->window()) { -
6276 fp = next; -
6277 if (fp->focusPolicy() != Qt::NoFocus) -
6278 break; -
6279 } -
6280 } -
6281 first = fp; -
6282 } -
6283 -
6284 if (fp == second) -
6285 return; -
6286 -
6287 if (QWidget *sp = second->focusProxy()) -
6288 second = sp; -
6289 -
6290// QWidget *fp = first->d_func()->focus_prev; -
6291 QWidget *fn = first->d_func()->focus_next; -
6292 -
6293 if (fn == second || first == second) -
6294 return; -
6295 -
6296 QWidget *sp = second->d_func()->focus_prev; -
6297 QWidget *sn = second->d_func()->focus_next; -
6298 -
6299 fn->d_func()->focus_prev = second; -
6300 first->d_func()->focus_next = second; -
6301 -
6302 second->d_func()->focus_next = fn; -
6303 second->d_func()->focus_prev = first; -
6304 -
6305 sp->d_func()->focus_next = sn; -
6306 sn->d_func()->focus_prev = sp; -
6307 -
6308 -
6309 Q_ASSERT(first->d_func()->focus_next->d_func()->focus_prev == first); -
6310 Q_ASSERT(first->d_func()->focus_prev->d_func()->focus_next == first); -
6311 -
6312 Q_ASSERT(second->d_func()->focus_next->d_func()->focus_prev == second); -
6313 Q_ASSERT(second->d_func()->focus_prev->d_func()->focus_next == second); -
6314} -
6315 -
6316/*!\internal -
6317 -
6318 Moves the relevant subwidgets of this widget from the \a oldtlw's -
6319 tab chain to that of the new parent, if there's anything to move and -
6320 we're really moving -
6321 -
6322 This function is called from QWidget::reparent() *after* the widget -
6323 has been reparented. -
6324 -
6325 \sa reparent() -
6326*/ -
6327 -
6328void QWidgetPrivate::reparentFocusWidgets(QWidget * oldtlw) -
6329{ -
6330 Q_Q(QWidget); -
6331 if (oldtlw == q->window()) -
6332 return; // nothing to do -
6333 -
6334 if(focus_child) -
6335 focus_child->clearFocus(); -
6336 -
6337 // separate the focus chain into new (children of myself) and old (the rest) -
6338 QWidget *firstOld = 0; -
6339 //QWidget *firstNew = q; //invariant -
6340 QWidget *o = 0; // last in the old list -
6341 QWidget *n = q; // last in the new list -
6342 -
6343 bool prevWasNew = true; -
6344 QWidget *w = focus_next; -
6345 -
6346 //Note: for efficiency, we do not maintain the list invariant inside the loop -
6347 //we append items to the relevant list, and we optimize by not changing pointers -
6348 //when subsequent items are going into the same list. -
6349 while (w != q) { -
6350 bool currentIsNew = q->isAncestorOf(w); -
6351 if (currentIsNew) { -
6352 if (!prevWasNew) { -
6353 //prev was old -- append to new list -
6354 n->d_func()->focus_next = w; -
6355 w->d_func()->focus_prev = n; -
6356 } -
6357 n = w; -
6358 } else { -
6359 if (prevWasNew) { -
6360 //prev was new -- append to old list, if there is one -
6361 if (o) { -
6362 o->d_func()->focus_next = w; -
6363 w->d_func()->focus_prev = o; -
6364 } else { -
6365 // "create" the old list -
6366 firstOld = w; -
6367 } -
6368 } -
6369 o = w; -
6370 } -
6371 w = w->d_func()->focus_next; -
6372 prevWasNew = currentIsNew; -
6373 } -
6374 -
6375 //repair the old list: -
6376 if (firstOld) { -
6377 o->d_func()->focus_next = firstOld; -
6378 firstOld->d_func()->focus_prev = o; -
6379 } -
6380 -
6381 if (!q->isWindow()) { -
6382 QWidget *topLevel = q->window(); -
6383 //insert new chain into toplevel's chain -
6384 -
6385 QWidget *prev = topLevel->d_func()->focus_prev; -
6386 -
6387 topLevel->d_func()->focus_prev = n; -
6388 prev->d_func()->focus_next = q; -
6389 -
6390 focus_prev = prev; -
6391 n->d_func()->focus_next = topLevel; -
6392 } else { -
6393 //repair the new list -
6394 n->d_func()->focus_next = q; -
6395 focus_prev = n; -
6396 } -
6397 -
6398} -
6399 -
6400/*!\internal -
6401 -
6402 Measures the shortest distance from a point to a rect. -
6403 -
6404 This function is called from QDesktopwidget::screen(QPoint) to find the -
6405 closest screen for a point. -
6406 In directional KeypadNavigation, it is called to find the closest -
6407 widget to the current focus widget center. -
6408*/ -
6409int QWidgetPrivate::pointToRect(const QPoint &p, const QRect &r) -
6410{ -
6411 int dx = 0; -
6412 int dy = 0; -
6413 if (p.x() < r.left()) -
6414 dx = r.left() - p.x(); -
6415 else if (p.x() > r.right()) -
6416 dx = p.x() - r.right(); -
6417 if (p.y() < r.top()) -
6418 dy = r.top() - p.y(); -
6419 else if (p.y() > r.bottom()) -
6420 dy = p.y() - r.bottom(); -
6421 return dx + dy; -
6422} -
6423 -
6424/*! -
6425 \property QWidget::frameSize -
6426 \brief the size of the widget including any window frame -
6427 -
6428 By default, this property contains a value that depends on the user's -
6429 platform and screen geometry. -
6430*/ -
6431QSize QWidget::frameSize() const -
6432{ -
6433 Q_D(const QWidget); -
6434 if (isWindow() && !(windowType() == Qt::Popup)) { -
6435 QRect fs = d->frameStrut(); -
6436 return QSize(data->crect.width() + fs.left() + fs.right(), -
6437 data->crect.height() + fs.top() + fs.bottom()); -
6438 } -
6439 return data->crect.size(); -
6440} -
6441 -
6442/*! \fn void QWidget::move(int x, int y) -
6443 -
6444 \overload -
6445 -
6446 This corresponds to move(QPoint(\a x, \a y)). -
6447*/ -
6448 -
6449void QWidget::move(const QPoint &p) -
6450{ -
6451 Q_D(QWidget); -
6452 setAttribute(Qt::WA_Moved); -
6453 if (testAttribute(Qt::WA_WState_Created)) { -
6454 if (isWindow()) -
6455 d->topData()->posIncludesFrame = false; -
6456 d->setGeometry_sys(p.x() + geometry().x() - QWidget::x(), -
6457 p.y() + geometry().y() - QWidget::y(), -
6458 width(), height(), true); -
6459 d->setDirtyOpaqueRegion(); -
6460 } else { -
6461 // no frame yet: see also QWidgetPrivate::fixPosIncludesFrame(), QWindowPrivate::PositionPolicy. -
6462 if (isWindow()) -
6463 d->topData()->posIncludesFrame = true; -
6464 data->crect.moveTopLeft(p); // no frame yet -
6465 setAttribute(Qt::WA_PendingMoveEvent); -
6466 } -
6467} -
6468 -
6469/*! \fn void QWidget::resize(int w, int h) -
6470 \overload -
6471 -
6472 This corresponds to resize(QSize(\a w, \a h)). -
6473*/ -
6474 -
6475void QWidget::resize(const QSize &s) -
6476{ -
6477 Q_D(QWidget); -
6478 setAttribute(Qt::WA_Resized); -
6479 if (testAttribute(Qt::WA_WState_Created)) { -
6480 d->fixPosIncludesFrame(); -
6481 d->setGeometry_sys(geometry().x(), geometry().y(), s.width(), s.height(), false); -
6482 d->setDirtyOpaqueRegion(); -
6483 } else { -
6484 data->crect.setSize(s.boundedTo(maximumSize()).expandedTo(minimumSize())); -
6485 setAttribute(Qt::WA_PendingResizeEvent); -
6486 } -
6487} -
6488 -
6489void QWidget::setGeometry(const QRect &r) -
6490{ -
6491 Q_D(QWidget); -
6492 setAttribute(Qt::WA_Resized); -
6493 setAttribute(Qt::WA_Moved); -
6494 if (isWindow()) -
6495 d->topData()->posIncludesFrame = 0; -
6496 if (testAttribute(Qt::WA_WState_Created)) { -
6497 d->setGeometry_sys(r.x(), r.y(), r.width(), r.height(), true); -
6498 d->setDirtyOpaqueRegion(); -
6499 } else { -
6500 data->crect.setTopLeft(r.topLeft()); -
6501 data->crect.setSize(r.size().boundedTo(maximumSize()).expandedTo(minimumSize())); -
6502 setAttribute(Qt::WA_PendingMoveEvent); -
6503 setAttribute(Qt::WA_PendingResizeEvent); -
6504 } -
6505} -
6506 -
6507/*! -
6508 \since 4.2 -
6509 Saves the current geometry and state for top-level widgets. -
6510 -
6511 To save the geometry when the window closes, you can -
6512 implement a close event like this: -
6513 -
6514 \snippet code/src_gui_kernel_qwidget.cpp 11 -
6515 -
6516 See the \l{Window Geometry} documentation for an overview of geometry -
6517 issues with windows. -
6518 -
6519 Use QMainWindow::saveState() to save the geometry and the state of -
6520 toolbars and dock widgets. -
6521 -
6522 \sa restoreGeometry(), QMainWindow::saveState(), QMainWindow::restoreState() -
6523*/ -
6524QByteArray QWidget::saveGeometry() const -
6525{ -
6526#ifdef Q_WS_MAC -
6527 // We check if the window was maximized during this invocation. If so, we need to record the -
6528 // starting position as 0,0. -
6529 Q_D(const QWidget); -
6530 QRect newFramePosition = frameGeometry(); -
6531 QRect newNormalPosition = normalGeometry(); -
6532 if(d->topData()->wasMaximized && !(windowState() & Qt::WindowMaximized)) { -
6533 // Change the starting position -
6534 newFramePosition.moveTo(0, 0); -
6535 newNormalPosition.moveTo(0, 0); -
6536 } -
6537#endif // Q_WS_MAC -
6538 QByteArray array; -
6539 QDataStream stream(&array, QIODevice::WriteOnly); -
6540 stream.setVersion(QDataStream::Qt_4_0); -
6541 const quint32 magicNumber = 0x1D9D0CB; -
6542 quint16 majorVersion = 1; -
6543 quint16 minorVersion = 0; -
6544 stream << magicNumber -
6545 << majorVersion -
6546 << minorVersion -
6547#ifdef Q_WS_MAC -
6548 << newFramePosition -
6549 << newNormalPosition -
6550#else -
6551 << frameGeometry() -
6552 << normalGeometry() -
6553#endif // Q_WS_MAC -
6554 << qint32(QApplication::desktop()->screenNumber(this)) -
6555 << quint8(windowState() & Qt::WindowMaximized) -
6556 << quint8(windowState() & Qt::WindowFullScreen); -
6557 return array; -
6558} -
6559 -
6560/*! -
6561 \since 4.2 -
6562 -
6563 Restores the geometry and state top-level widgets stored in the -
6564 byte array \a geometry. Returns true on success; otherwise -
6565 returns false. -
6566 -
6567 If the restored geometry is off-screen, it will be modified to be -
6568 inside the available screen geometry. -
6569 -
6570 To restore geometry saved using QSettings, you can use code like -
6571 this: -
6572 -
6573 \snippet code/src_gui_kernel_qwidget.cpp 12 -
6574 -
6575 See the \l{Window Geometry} documentation for an overview of geometry -
6576 issues with windows. -
6577 -
6578 Use QMainWindow::restoreState() to restore the geometry and the -
6579 state of toolbars and dock widgets. -
6580 -
6581 \sa saveGeometry(), QSettings, QMainWindow::saveState(), QMainWindow::restoreState() -
6582*/ -
6583bool QWidget::restoreGeometry(const QByteArray &geometry) -
6584{ -
6585 if (geometry.size() < 4) -
6586 return false; -
6587 QDataStream stream(geometry); -
6588 stream.setVersion(QDataStream::Qt_4_0); -
6589 -
6590 const quint32 magicNumber = 0x1D9D0CB; -
6591 quint32 storedMagicNumber; -
6592 stream >> storedMagicNumber; -
6593 if (storedMagicNumber != magicNumber) -
6594 return false; -
6595 -
6596 const quint16 currentMajorVersion = 1; -
6597 quint16 majorVersion = 0; -
6598 quint16 minorVersion = 0; -
6599 -
6600 stream >> majorVersion >> minorVersion; -
6601 -
6602 if (majorVersion != currentMajorVersion) -
6603 return false; -
6604 // (Allow all minor versions.) -
6605 -
6606 QRect restoredFrameGeometry; -
6607 QRect restoredNormalGeometry; -
6608 qint32 restoredScreenNumber; -
6609 quint8 maximized; -
6610 quint8 fullScreen; -
6611 -
6612 stream >> restoredFrameGeometry -
6613 >> restoredNormalGeometry -
6614 >> restoredScreenNumber -
6615 >> maximized -
6616 >> fullScreen; -
6617 -
6618 const int frameHeight = 20; -
6619 if (!restoredFrameGeometry.isValid()) -
6620 restoredFrameGeometry = QRect(QPoint(0,0), sizeHint()); -
6621 -
6622 if (!restoredNormalGeometry.isValid()) -
6623 restoredNormalGeometry = QRect(QPoint(0, frameHeight), sizeHint()); -
6624 if (!restoredNormalGeometry.isValid()) { -
6625 // use the widget's adjustedSize if the sizeHint() doesn't help -
6626 restoredNormalGeometry.setSize(restoredNormalGeometry -
6627 .size() -
6628 .expandedTo(d_func()->adjustedSize())); -
6629 } -
6630 -
6631 const QDesktopWidget * const desktop = QApplication::desktop(); -
6632 if (restoredScreenNumber >= desktop->numScreens()) -
6633 restoredScreenNumber = desktop->primaryScreen(); -
6634 -
6635 const QRect availableGeometry = desktop->availableGeometry(restoredScreenNumber); -
6636 -
6637 // Modify the restored geometry if we are about to restore to coordinates -
6638 // that would make the window "lost". This happens if: -
6639 // - The restored geometry is completely oustside the available geometry -
6640 // - The title bar is outside the available geometry. -
6641 // - (Mac only) The window is higher than the available geometry. It must -
6642 // be possible to bring the size grip on screen by moving the window. -
6643#ifdef Q_WS_MAC -
6644 restoredFrameGeometry.setHeight(qMin(restoredFrameGeometry.height(), availableGeometry.height())); -
6645 restoredNormalGeometry.setHeight(qMin(restoredNormalGeometry.height(), availableGeometry.height() - frameHeight)); -
6646#endif -
6647 -
6648 if (!restoredFrameGeometry.intersects(availableGeometry)) { -
6649 restoredFrameGeometry.moveBottom(qMin(restoredFrameGeometry.bottom(), availableGeometry.bottom())); -
6650 restoredFrameGeometry.moveLeft(qMax(restoredFrameGeometry.left(), availableGeometry.left())); -
6651 restoredFrameGeometry.moveRight(qMin(restoredFrameGeometry.right(), availableGeometry.right())); -
6652 } -
6653 restoredFrameGeometry.moveTop(qMax(restoredFrameGeometry.top(), availableGeometry.top())); -
6654 -
6655 if (!restoredNormalGeometry.intersects(availableGeometry)) { -
6656 restoredNormalGeometry.moveBottom(qMin(restoredNormalGeometry.bottom(), availableGeometry.bottom())); -
6657 restoredNormalGeometry.moveLeft(qMax(restoredNormalGeometry.left(), availableGeometry.left())); -
6658 restoredNormalGeometry.moveRight(qMin(restoredNormalGeometry.right(), availableGeometry.right())); -
6659 } -
6660 restoredNormalGeometry.moveTop(qMax(restoredNormalGeometry.top(), availableGeometry.top() + frameHeight)); -
6661 -
6662 if (maximized || fullScreen) { -
6663 // set geometry before setting the window state to make -
6664 // sure the window is maximized to the right screen. -
6665 // Skip on windows: the window is restored into a broken -
6666 // half-maximized state. -
6667#ifndef Q_OS_WIN -
6668 setGeometry(restoredNormalGeometry); -
6669#endif -
6670 Qt::WindowStates ws = windowState(); -
6671 if (maximized) -
6672 ws |= Qt::WindowMaximized; -
6673 if (fullScreen) -
6674 ws |= Qt::WindowFullScreen; -
6675 setWindowState(ws); -
6676 d_func()->topData()->normalGeometry = restoredNormalGeometry; -
6677 } else { -
6678 QPoint offset; -
6679#ifdef Q_WS_X11 -
6680 if (isFullScreen()) -
6681 offset = d_func()->topData()->fullScreenOffset; -
6682#endif -
6683 setWindowState(windowState() & ~(Qt::WindowMaximized | Qt::WindowFullScreen)); -
6684 move(restoredFrameGeometry.topLeft() + offset); -
6685 resize(restoredNormalGeometry.size()); -
6686 } -
6687 return true; -
6688} -
6689 -
6690/*!\fn void QWidget::setGeometry(int x, int y, int w, int h) -
6691 \overload -
6692 -
6693 This corresponds to setGeometry(QRect(\a x, \a y, \a w, \a h)). -
6694*/ -
6695 -
6696/*! -
6697 Sets the margins around the contents of the widget to have the sizes -
6698 \a left, \a top, \a right, and \a bottom. The margins are used by -
6699 the layout system, and may be used by subclasses to specify the area -
6700 to draw in (e.g. excluding the frame). -
6701 -
6702 Changing the margins will trigger a resizeEvent(). -
6703 -
6704 \sa contentsRect(), getContentsMargins() -
6705*/ -
6706void QWidget::setContentsMargins(int left, int top, int right, int bottom) -
6707{ -
6708 Q_D(QWidget); -
6709 if (left == d->leftmargin && top == d->topmargin -
6710 && right == d->rightmargin && bottom == d->bottommargin) -
6711 return; -
6712 d->leftmargin = left; -
6713 d->topmargin = top; -
6714 d->rightmargin = right; -
6715 d->bottommargin = bottom; -
6716 -
6717 if (QLayout *l=d->layout) -
6718 l->update(); //force activate; will do updateGeometry -
6719 else -
6720 updateGeometry(); -
6721 -
6722 if (isVisible()) { -
6723 update(); -
6724 QResizeEvent e(data->crect.size(), data->crect.size()); -
6725 QApplication::sendEvent(this, &e); -
6726 } else { -
6727 setAttribute(Qt::WA_PendingResizeEvent, true); -
6728 } -
6729 -
6730 QEvent e(QEvent::ContentsRectChange); -
6731 QApplication::sendEvent(this, &e); -
6732} -
6733 -
6734/*! -
6735 \overload -
6736 \since 4.6 -
6737 -
6738 \brief The setContentsMargins function sets the margins around the -
6739 widget's contents. -
6740 -
6741 Sets the margins around the contents of the widget to have the -
6742 sizes determined by \a margins. The margins are -
6743 used by the layout system, and may be used by subclasses to -
6744 specify the area to draw in (e.g. excluding the frame). -
6745 -
6746 Changing the margins will trigger a resizeEvent(). -
6747 -
6748 \sa contentsRect(), getContentsMargins() -
6749*/ -
6750void QWidget::setContentsMargins(const QMargins &margins) -
6751{ -
6752 setContentsMargins(margins.left(), margins.top(), -
6753 margins.right(), margins.bottom()); -
6754} -
6755 -
6756/*! -
6757 Returns the widget's contents margins for \a left, \a top, \a -
6758 right, and \a bottom. -
6759 -
6760 \sa setContentsMargins(), contentsRect() -
6761 */ -
6762void QWidget::getContentsMargins(int *left, int *top, int *right, int *bottom) const -
6763{ -
6764 Q_D(const QWidget); -
6765 if (left) -
6766 *left = d->leftmargin; -
6767 if (top) -
6768 *top = d->topmargin; -
6769 if (right) -
6770 *right = d->rightmargin; -
6771 if (bottom) -
6772 *bottom = d->bottommargin; -
6773} -
6774 -
6775/*! -
6776 \since 4.6 -
6777 -
6778 \brief The contentsMargins function returns the widget's contents margins. -
6779 -
6780 \sa getContentsMargins(), setContentsMargins(), contentsRect() -
6781 */ -
6782QMargins QWidget::contentsMargins() const -
6783{ -
6784 Q_D(const QWidget); -
6785 return QMargins(d->leftmargin, d->topmargin, d->rightmargin, d->bottommargin); -
6786} -
6787 -
6788 -
6789/*! -
6790 Returns the area inside the widget's margins. -
6791 -
6792 \sa setContentsMargins(), getContentsMargins() -
6793*/ -
6794QRect QWidget::contentsRect() const -
6795{ -
6796 Q_D(const QWidget); -
6797 return QRect(QPoint(d->leftmargin, d->topmargin), -
6798 QPoint(data->crect.width() - 1 - d->rightmargin, -
6799 data->crect.height() - 1 - d->bottommargin)); -
6800 -
6801} -
6802 -
6803 -
6804 -
6805/*! -
6806 \fn void QWidget::customContextMenuRequested(const QPoint &pos) -
6807 -
6808 This signal is emitted when the widget's \l contextMenuPolicy is -
6809 Qt::CustomContextMenu, and the user has requested a context menu on -
6810 the widget. The position \a pos is the position of the context menu -
6811 event that the widget receives. Normally this is in widget -
6812 coordinates. The exception to this rule is QAbstractScrollArea and -
6813 its subclasses that map the context menu event to coordinates of the -
6814 \l{QAbstractScrollArea::viewport()}{viewport()}. -
6815 -
6816 -
6817 \sa mapToGlobal(), QMenu, contextMenuPolicy -
6818*/ -
6819 -
6820 -
6821/*! -
6822 \property QWidget::contextMenuPolicy -
6823 \brief how the widget shows a context menu -
6824 -
6825 The default value of this property is Qt::DefaultContextMenu, -
6826 which means the contextMenuEvent() handler is called. Other values -
6827 are Qt::NoContextMenu, Qt::PreventContextMenu, -
6828 Qt::ActionsContextMenu, and Qt::CustomContextMenu. With -
6829 Qt::CustomContextMenu, the signal customContextMenuRequested() is -
6830 emitted. -
6831 -
6832 \sa contextMenuEvent(), customContextMenuRequested(), actions() -
6833*/ -
6834 -
6835Qt::ContextMenuPolicy QWidget::contextMenuPolicy() const -
6836{ -
6837 return (Qt::ContextMenuPolicy)data->context_menu_policy; -
6838} -
6839 -
6840void QWidget::setContextMenuPolicy(Qt::ContextMenuPolicy policy) -
6841{ -
6842 data->context_menu_policy = (uint) policy; -
6843} -
6844 -
6845/*! -
6846 \property QWidget::focusPolicy -
6847 \brief the way the widget accepts keyboard focus -
6848 -
6849 The policy is Qt::TabFocus if the widget accepts keyboard -
6850 focus by tabbing, Qt::ClickFocus if the widget accepts -
6851 focus by clicking, Qt::StrongFocus if it accepts both, and -
6852 Qt::NoFocus (the default) if it does not accept focus at -
6853 all. -
6854 -
6855 You must enable keyboard focus for a widget if it processes -
6856 keyboard events. This is normally done from the widget's -
6857 constructor. For instance, the QLineEdit constructor calls -
6858 setFocusPolicy(Qt::StrongFocus). -
6859 -
6860 If the widget has a focus proxy, then the focus policy will -
6861 be propagated to it. -
6862 -
6863 \sa focusInEvent(), focusOutEvent(), keyPressEvent(), keyReleaseEvent(), enabled -
6864*/ -
6865 -
6866 -
6867Qt::FocusPolicy QWidget::focusPolicy() const -
6868{ -
6869 return (Qt::FocusPolicy)data->focus_policy; -
6870} -
6871 -
6872void QWidget::setFocusPolicy(Qt::FocusPolicy policy) -
6873{ -
6874 data->focus_policy = (uint) policy; -
6875 Q_D(QWidget); -
6876 if (d->extra && d->extra->focus_proxy) -
6877 d->extra->focus_proxy->setFocusPolicy(policy); -
6878} -
6879 -
6880/*! -
6881 \property QWidget::updatesEnabled -
6882 \brief whether updates are enabled -
6883 -
6884 An updates enabled widget receives paint events and has a system -
6885 background; a disabled widget does not. This also implies that -
6886 calling update() and repaint() has no effect if updates are -
6887 disabled. -
6888 -
6889 By default, this property is true. -
6890 -
6891 setUpdatesEnabled() is normally used to disable updates for a -
6892 short period of time, for instance to avoid screen flicker during -
6893 large changes. In Qt, widgets normally do not generate screen -
6894 flicker, but on X11 the server might erase regions on the screen -
6895 when widgets get hidden before they can be replaced by other -
6896 widgets. Disabling updates solves this. -
6897 -
6898 Example: -
6899 \snippet code/src_gui_kernel_qwidget.cpp 13 -
6900 -
6901 Disabling a widget implicitly disables all its children. Enabling a widget -
6902 enables all child widgets \e except top-level widgets or those that -
6903 have been explicitly disabled. Re-enabling updates implicitly calls -
6904 update() on the widget. -
6905 -
6906 \sa paintEvent() -
6907*/ -
6908void QWidget::setUpdatesEnabled(bool enable) -
6909{ -
6910 Q_D(QWidget); -
6911 setAttribute(Qt::WA_ForceUpdatesDisabled, !enable); -
6912 d->setUpdatesEnabled_helper(enable); -
6913} -
6914 -
6915/*! -
6916 Shows the widget and its child widgets. This function is -
6917 equivalent to setVisible(true) in the normal case, and equivalent -
6918 to showFullScreen() if the QStyleHints::showIsFullScreen() hint -
6919 is true. -
6920 -
6921 \sa raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(), -
6922 showNormal(), isVisible() -
6923*/ -
6924void QWidget::show() -
6925{ -
6926 if (isWindow() && qApp->styleHints()->showIsFullScreen()) -
6927 showFullScreen(); -
6928 else -
6929 setVisible(true); -
6930} -
6931 -
6932/*! \internal -
6933 -
6934 Makes the widget visible in the isVisible() meaning of the word. -
6935 It is only called for toplevels or widgets with visible parents. -
6936 */ -
6937void QWidgetPrivate::show_recursive() -
6938{ -
6939 Q_Q(QWidget); -
6940 // polish if necessary -
6941 -
6942 if (!q->testAttribute(Qt::WA_WState_Created)) -
6943 createRecursively(); -
6944 q->ensurePolished(); -
6945 -
6946 if (!q->isWindow() && q->parentWidget()->d_func()->layout && !q->parentWidget()->data->in_show) -
6947 q->parentWidget()->d_func()->layout->activate(); -
6948 // activate our layout before we and our children become visible -
6949 if (layout) -
6950 layout->activate(); -
6951 -
6952 show_helper(); -
6953} -
6954 -
6955void QWidgetPrivate::sendPendingMoveAndResizeEvents(bool recursive, bool disableUpdates) -
6956{ -
6957 Q_Q(QWidget); -
6958 -
6959 disableUpdates = disableUpdates && q->updatesEnabled(); -
6960 if (disableUpdates) -
6961 q->setAttribute(Qt::WA_UpdatesDisabled); -
6962 -
6963 if (q->testAttribute(Qt::WA_PendingMoveEvent)) { -
6964 QMoveEvent e(data.crect.topLeft(), data.crect.topLeft()); -
6965 QApplication::sendEvent(q, &e); -
6966 q->setAttribute(Qt::WA_PendingMoveEvent, false); -
6967 } -
6968 -
6969 if (q->testAttribute(Qt::WA_PendingResizeEvent)) { -
6970 QResizeEvent e(data.crect.size(), QSize()); -
6971 QApplication::sendEvent(q, &e); -
6972 q->setAttribute(Qt::WA_PendingResizeEvent, false); -
6973 } -
6974 -
6975 if (disableUpdates) -
6976 q->setAttribute(Qt::WA_UpdatesDisabled, false); -
6977 -
6978 if (!recursive) -
6979 return; -
6980 -
6981 for (int i = 0; i < children.size(); ++i) { -
6982 if (QWidget *child = qobject_cast<QWidget *>(children.at(i))) -
6983 child->d_func()->sendPendingMoveAndResizeEvents(recursive, disableUpdates); -
6984 } -
6985} -
6986 -
6987void QWidgetPrivate::activateChildLayoutsRecursively() -
6988{ -
6989 sendPendingMoveAndResizeEvents(false, true); -
6990 -
6991 for (int i = 0; i < children.size(); ++i) { -
6992 QWidget *child = qobject_cast<QWidget *>(children.at(i)); -
6993 if (!child || child->isHidden() || child->isWindow()) -
6994 continue; -
6995 -
6996 child->ensurePolished(); -
6997 -
6998 // Activate child's layout -
6999 QWidgetPrivate *childPrivate = child->d_func(); -
7000 if (childPrivate->layout) -
7001 childPrivate->layout->activate(); -
7002 -
7003 // Pretend we're visible. -
7004 const bool wasVisible = child->isVisible(); -
7005 if (!wasVisible) -
7006 child->setAttribute(Qt::WA_WState_Visible); -
7007 -
7008 // Do the same for all my children. -
7009 childPrivate->activateChildLayoutsRecursively(); -
7010 -
7011 // We're not cheating anymore. -
7012 if (!wasVisible) -
7013 child->setAttribute(Qt::WA_WState_Visible, false); -
7014 } -
7015} -
7016 -
7017void QWidgetPrivate::show_helper() -
7018{ -
7019 Q_Q(QWidget); -
7020 data.in_show = true; // qws optimization -
7021 // make sure we receive pending move and resize events -
7022 sendPendingMoveAndResizeEvents(); -
7023 -
7024 // become visible before showing all children -
7025 q->setAttribute(Qt::WA_WState_Visible); -
7026 -
7027 // finally show all children recursively -
7028 showChildren(false); -
7029 -
7030 -
7031 -
7032 // popup handling: new popups and tools need to be raised, and -
7033 // existing popups must be closed. Also propagate the current -
7034 // windows's KeyboardFocusChange status. -
7035 if (q->isWindow()) { -
7036 if ((q->windowType() == Qt::Tool) || (q->windowType() == Qt::Popup) || q->windowType() == Qt::ToolTip) { -
7037 q->raise(); -
7038 if (q->parentWidget() && q->parentWidget()->window()->testAttribute(Qt::WA_KeyboardFocusChange)) -
7039 q->setAttribute(Qt::WA_KeyboardFocusChange); -
7040 } else { -
7041 while (QApplication::activePopupWidget()) { -
7042 if (!QApplication::activePopupWidget()->close()) -
7043 break; -
7044 } -
7045 } -
7046 } -
7047 -
7048 // Automatic embedding of child windows of widgets already embedded into -
7049 // QGraphicsProxyWidget when they are shown the first time. -
7050 bool isEmbedded = false; -
7051#ifndef QT_NO_GRAPHICSVIEW -
7052 if (q->isWindow()) { -
7053 isEmbedded = q->graphicsProxyWidget() ? true : false; -
7054 if (!isEmbedded && !bypassGraphicsProxyWidget(q)) { -
7055 QGraphicsProxyWidget *ancestorProxy = nearestGraphicsProxyWidget(q->parentWidget()); -
7056 if (ancestorProxy) { -
7057 isEmbedded = true; -
7058 ancestorProxy->d_func()->embedSubWindow(q); -
7059 } -
7060 } -
7061 } -
7062#else -
7063 Q_UNUSED(isEmbedded); -
7064#endif -
7065 -
7066 // On Windows, show the popup now so that our own focus handling -
7067 // stores the correct old focus widget even if it's stolen in the -
7068 // showevent -
7069#if defined(Q_WS_WIN) || defined(Q_WS_MAC) -
7070 if (!isEmbedded && q->windowType() == Qt::Popup) -
7071 qApp->d_func()->openPopup(q); -
7072#endif -
7073 -
7074 // send the show event before showing the window -
7075 QShowEvent showEvent; -
7076 QApplication::sendEvent(q, &showEvent); -
7077 -
7078 show_sys(); -
7079 -
7080 if (!isEmbedded && q->windowType() == Qt::Popup) -
7081 qApp->d_func()->openPopup(q); -
7082 -
7083#ifndef QT_NO_ACCESSIBILITY -
7084 if (q->windowType() != Qt::ToolTip) { // Tooltips are read aloud twice in MS narrator. -
7085 QAccessibleEvent event(q, QAccessible::ObjectShow); -
7086 QAccessible::updateAccessibility(&event); -
7087 } -
7088#endif -
7089 -
7090 if (QApplicationPrivate::hidden_focus_widget == q) { -
7091 QApplicationPrivate::hidden_focus_widget = 0; -
7092 q->setFocus(Qt::OtherFocusReason); -
7093 } -
7094 -
7095 // Process events when showing a Qt::SplashScreen widget before the event loop -
7096 // is spinnning; otherwise it might not show up on particular platforms. -
7097 // This makes QSplashScreen behave the same on all platforms. -
7098 if (!qApp->d_func()->in_exec && q->windowType() == Qt::SplashScreen) -
7099 QApplication::processEvents(); -
7100 -
7101 data.in_show = false; // reset qws optimization -
7102} -
7103 -
7104/*! -
7105 Hides the widget. This function is equivalent to -
7106 setVisible(false). -
7107 -
7108 -
7109 \note If you are working with QDialog or its subclasses and you invoke -
7110 the show() function after this function, the dialog will be displayed in -
7111 its original position. -
7112 -
7113 \sa hideEvent(), isHidden(), show(), setVisible(), isVisible(), close() -
7114*/ -
7115void QWidget::hide() -
7116{ -
7117 setVisible(false); -
7118} -
7119 -
7120/*!\internal -
7121 */ -
7122void QWidgetPrivate::hide_helper() -
7123{ -
7124 Q_Q(QWidget); -
7125 -
7126 bool isEmbedded = false; -
7127#if !defined QT_NO_GRAPHICSVIEW -
7128 isEmbedded = q->isWindow() && !bypassGraphicsProxyWidget(q) && nearestGraphicsProxyWidget(q->parentWidget()) != 0; -
7129#else -
7130 Q_UNUSED(isEmbedded); -
7131#endif -
7132 -
7133 if (!isEmbedded && (q->windowType() == Qt::Popup)) -
7134 qApp->d_func()->closePopup(q); -
7135 -
7136#if defined(Q_WS_WIN) -
7137 if (q->isWindow() && !(q->windowType() == Qt::Popup) && q->parentWidget() -
7138 && !q->parentWidget()->isHidden() && q->isActiveWindow()) -
7139 q->parentWidget()->activateWindow(); // Activate parent -
7140#endif -
7141 -
7142 q->setAttribute(Qt::WA_Mapped, false); -
7143 hide_sys(); -
7144 -
7145 bool wasVisible = q->testAttribute(Qt::WA_WState_Visible); -
7146 -
7147 if (wasVisible) { -
7148 q->setAttribute(Qt::WA_WState_Visible, false); -
7149 -
7150 } -
7151 -
7152 QHideEvent hideEvent; -
7153 QApplication::sendEvent(q, &hideEvent); -
7154 hideChildren(false); -
7155 -
7156 // next bit tries to move the focus if the focus widget is now -
7157 // hidden. -
7158 if (wasVisible) { -
7159 qApp->d_func()->sendSyntheticEnterLeave(q); -
7160 QWidget *fw = QApplication::focusWidget(); -
7161 while (fw && !fw->isWindow()) { -
7162 if (fw == q) { -
7163 q->focusNextPrevChild(true); -
7164 break; -
7165 } -
7166 fw = fw->parentWidget(); -
7167 } -
7168 } -
7169 -
7170 if (QWidgetBackingStore *bs = maybeBackingStore()) -
7171 bs->removeDirtyWidget(q); -
7172 -
7173#ifndef QT_NO_ACCESSIBILITY -
7174 if (wasVisible) { -
7175 QAccessibleEvent event(q, QAccessible::ObjectHide); -
7176 QAccessible::updateAccessibility(&event); -
7177 } -
7178#endif -
7179} -
7180 -
7181/*! -
7182 \fn bool QWidget::isHidden() const -
7183 -
7184 Returns true if the widget is hidden, otherwise returns false. -
7185 -
7186 A hidden widget will only become visible when show() is called on -
7187 it. It will not be automatically shown when the parent is shown. -
7188 -
7189 To check visibility, use !isVisible() instead (notice the exclamation mark). -
7190 -
7191 isHidden() implies !isVisible(), but a widget can be not visible -
7192 and not hidden at the same time. This is the case for widgets that are children of -
7193 widgets that are not visible. -
7194 -
7195 -
7196 Widgets are hidden if: -
7197 \list -
7198 \li they were created as independent windows, -
7199 \li they were created as children of visible widgets, -
7200 \li hide() or setVisible(false) was called. -
7201 \endlist -
7202*/ -
7203 -
7204 -
7205void QWidget::setVisible(bool visible) -
7206{ -
7207 if (visible) { // show -
7208 if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) -
7209 return; -
7210 -
7211 Q_D(QWidget); -
7212 -
7213 // Designer uses a trick to make grabWidget work without showing -
7214 if (!isWindow() && parentWidget() && parentWidget()->isVisible() -
7215 && !parentWidget()->testAttribute(Qt::WA_WState_Created)) -
7216 parentWidget()->window()->d_func()->createRecursively(); -
7217 -
7218 //we have to at least create toplevels before applyX11SpecificCommandLineArguments -
7219 //but not children of non-visible parents -
7220 QWidget *pw = parentWidget(); -
7221 if (!testAttribute(Qt::WA_WState_Created) -
7222 && (isWindow() || pw->testAttribute(Qt::WA_WState_Created))) { -
7223 create(); -
7224 } -
7225 -
7226#if defined(Q_WS_X11) -
7227 if (windowType() == Qt::Window) -
7228 QApplicationPrivate::applyX11SpecificCommandLineArguments(this); -
7229#endif -
7230 -
7231 bool wasResized = testAttribute(Qt::WA_Resized); -
7232 Qt::WindowStates initialWindowState = windowState(); -
7233 -
7234 // polish if necessary -
7235 ensurePolished(); -
7236 -
7237 // remember that show was called explicitly -
7238 setAttribute(Qt::WA_WState_ExplicitShowHide); -
7239 // whether we need to inform the parent widget immediately -
7240 bool needUpdateGeometry = !isWindow() && testAttribute(Qt::WA_WState_Hidden); -
7241 // we are no longer hidden -
7242 setAttribute(Qt::WA_WState_Hidden, false); -
7243 -
7244 if (needUpdateGeometry) -
7245 d->updateGeometry_helper(true); -
7246 -
7247 // activate our layout before we and our children become visible -
7248 if (d->layout) -
7249 d->layout->activate(); -
7250 -
7251 if (!isWindow()) { -
7252 QWidget *parent = parentWidget(); -
7253 while (parent && parent->isVisible() && parent->d_func()->layout && !parent->data->in_show) { -
7254 parent->d_func()->layout->activate(); -
7255 if (parent->isWindow()) -
7256 break; -
7257 parent = parent->parentWidget(); -
7258 } -
7259 if (parent) -
7260 parent->d_func()->setDirtyOpaqueRegion(); -
7261 } -
7262 -
7263 // adjust size if necessary -
7264 if (!wasResized -
7265 && (isWindow() || !parentWidget()->d_func()->layout)) { -
7266 if (isWindow()) { -
7267 adjustSize(); -
7268 if (windowState() != initialWindowState) -
7269 setWindowState(initialWindowState); -
7270 } else { -
7271 adjustSize(); -
7272 } -
7273 setAttribute(Qt::WA_Resized, false); -
7274 } -
7275 -
7276 setAttribute(Qt::WA_KeyboardFocusChange, false); -
7277 -
7278 if (isWindow() || parentWidget()->isVisible()) { -
7279 d->show_helper(); -
7280 -
7281 qApp->d_func()->sendSyntheticEnterLeave(this); -
7282 } -
7283 -
7284 QEvent showToParentEvent(QEvent::ShowToParent); -
7285 QApplication::sendEvent(this, &showToParentEvent); -
7286 } else { // hide -
7287 if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) -
7288 return; -
7289#if defined(Q_WS_WIN) -
7290 // reset WS_DISABLED style in a Blocked window -
7291 if(isWindow() && testAttribute(Qt::WA_WState_Created) -
7292 && QApplicationPrivate::isBlockedByModal(this)) -
7293 { -
7294 LONG dwStyle = GetWindowLong(winId(), GWL_STYLE); -
7295 dwStyle &= ~WS_DISABLED; -
7296 SetWindowLong(winId(), GWL_STYLE, dwStyle); -
7297 } -
7298#endif -
7299 if (QApplicationPrivate::hidden_focus_widget == this) -
7300 QApplicationPrivate::hidden_focus_widget = 0; -
7301 -
7302 Q_D(QWidget); -
7303 -
7304 // hw: The test on getOpaqueRegion() needs to be more intelligent -
7305 // currently it doesn't work if the widget is hidden (the region will -
7306 // be clipped). The real check should be testing the cached region -
7307 // (and dirty flag) directly. -
7308 if (!isWindow() && parentWidget()) // && !d->getOpaqueRegion().isEmpty()) -
7309 parentWidget()->d_func()->setDirtyOpaqueRegion(); -
7310 -
7311 setAttribute(Qt::WA_WState_Hidden); -
7312 setAttribute(Qt::WA_WState_ExplicitShowHide); -
7313 if (testAttribute(Qt::WA_WState_Created)) -
7314 d->hide_helper(); -
7315 -
7316 // invalidate layout similar to updateGeometry() -
7317 if (!isWindow() && parentWidget()) { -
7318 if (parentWidget()->d_func()->layout) -
7319 parentWidget()->d_func()->layout->invalidate(); -
7320 else if (parentWidget()->isVisible()) -
7321 QApplication::postEvent(parentWidget(), new QEvent(QEvent::LayoutRequest)); -
7322 } -
7323 -
7324 QEvent hideToParentEvent(QEvent::HideToParent); -
7325 QApplication::sendEvent(this, &hideToParentEvent); -
7326 } -
7327} -
7328 -
7329/*! -
7330 Convenience function, equivalent to setVisible(!\a hidden). -
7331*/ -
7332void QWidget::setHidden(bool hidden) -
7333{ -
7334 setVisible(!hidden); -
7335} -
7336 -
7337void QWidgetPrivate::_q_showIfNotHidden() -
7338{ -
7339 Q_Q(QWidget); -
7340 if ( !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide)) ) -
7341 q->setVisible(true); -
7342} -
7343 -
7344void QWidgetPrivate::showChildren(bool spontaneous) -
7345{ -
7346 QList<QObject*> childList = children; -
7347 for (int i = 0; i < childList.size(); ++i) { -
7348 QWidget *widget = qobject_cast<QWidget*>(childList.at(i)); -
7349 if (!widget -
7350 || widget->isWindow() -
7351 || widget->testAttribute(Qt::WA_WState_Hidden)) -
7352 continue; -
7353 if (spontaneous) { -
7354 widget->setAttribute(Qt::WA_Mapped); -
7355 widget->d_func()->showChildren(true); -
7356 QShowEvent e; -
7357 QApplication::sendSpontaneousEvent(widget, &e); -
7358 } else { -
7359 if (widget->testAttribute(Qt::WA_WState_ExplicitShowHide)) -
7360 widget->d_func()->show_recursive(); -
7361 else -
7362 widget->show(); -
7363 } -
7364 } -
7365} -
7366 -
7367void QWidgetPrivate::hideChildren(bool spontaneous) -
7368{ -
7369 QList<QObject*> childList = children; -
7370 for (int i = 0; i < childList.size(); ++i) { -
7371 QWidget *widget = qobject_cast<QWidget*>(childList.at(i)); -
7372 if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden)) -
7373 continue; -
7374#ifdef Q_WS_MAC -
7375 // Before doing anything we need to make sure that we don't leave anything in a non-consistent state. -
7376 // When hiding a widget we need to make sure that no mouse_down events are active, because -
7377 // the mouse_up event will never be received by a hidden widget or one of its descendants. -
7378 // The solution is simple, before going through with this we check if there are any mouse_down events in -
7379 // progress, if so we check if it is related to this widget or not. If so, we just reset the mouse_down and -
7380 // then we continue. -
7381 // In X11 and Windows we send a mouse_release event, however we don't do that here because we were already -
7382 // ignoring that from before. I.e. Carbon did not send the mouse release event, so we will not send the -
7383 // mouse release event. There are two ways to interpret this: -
7384 // 1. If we don't send the mouse release event, the widget might get into an inconsistent state, i.e. it -
7385 // might be waiting for a release event that will never arrive. -
7386 // 2. If we send the mouse release event, then the widget might decide to trigger an action that is not -
7387 // supposed to trigger because it is not visible. -
7388 if(widget == qt_button_down) -
7389 qt_button_down = 0; -
7390#endif // Q_WS_MAC -
7391 if (spontaneous) -
7392 widget->setAttribute(Qt::WA_Mapped, false); -
7393 else -
7394 widget->setAttribute(Qt::WA_WState_Visible, false); -
7395 widget->d_func()->hideChildren(spontaneous); -
7396 QHideEvent e; -
7397 if (spontaneous) { -
7398 QApplication::sendSpontaneousEvent(widget, &e); -
7399 } else { -
7400 QApplication::sendEvent(widget, &e); -
7401 if (widget->internalWinId() -
7402 && widget->testAttribute(Qt::WA_DontCreateNativeAncestors)) { -
7403 // hide_sys() on an ancestor won't have any affect on this -
7404 // widget, so it needs an explicit hide_sys() of its own -
7405 widget->d_func()->hide_sys(); -
7406 } -
7407 } -
7408 qApp->d_func()->sendSyntheticEnterLeave(widget); -
7409#ifndef QT_NO_ACCESSIBILITY -
7410 if (!spontaneous) { -
7411 QAccessibleEvent event(widget, QAccessible::ObjectHide); -
7412 QAccessible::updateAccessibility(&event); -
7413 } -
7414#endif -
7415 } -
7416} -
7417 -
7418bool QWidgetPrivate::close_helper(CloseMode mode) -
7419{ -
7420 if (data.is_closing) -
7421 return true; -
7422 -
7423 Q_Q(QWidget); -
7424 data.is_closing = 1; -
7425 -
7426 QPointer<QWidget> that = q; -
7427 QPointer<QWidget> parentWidget = q->parentWidget(); -
7428 -
7429 bool quitOnClose = q->testAttribute(Qt::WA_QuitOnClose); -
7430 if (mode != CloseNoEvent) { -
7431 QCloseEvent e; -
7432 if (mode == CloseWithSpontaneousEvent) -
7433 QApplication::sendSpontaneousEvent(q, &e); -
7434 else -
7435 QApplication::sendEvent(q, &e); -
7436 if (!that.isNull() && !e.isAccepted()) { -
7437 data.is_closing = 0; -
7438 return false; -
7439 } -
7440 } -
7441 -
7442 if (!that.isNull() && !q->isHidden()) -
7443 q->hide(); -
7444 -
7445 // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent -
7446 quitOnClose = quitOnClose && (parentWidget.isNull() || !parentWidget->isVisible()); -
7447 -
7448 if (quitOnClose) { -
7449 /* if there is no non-withdrawn primary window left (except -
7450 the ones without QuitOnClose), we emit the lastWindowClosed -
7451 signal */ -
7452 QWidgetList list = QApplication::topLevelWidgets(); -
7453 bool lastWindowClosed = true; -
7454 for (int i = 0; i < list.size(); ++i) { -
7455 QWidget *w = list.at(i); -
7456 if (!w->isVisible() || w->parentWidget() || !w->testAttribute(Qt::WA_QuitOnClose)) -
7457 continue; -
7458 lastWindowClosed = false; -
7459 break; -
7460 } -
7461 if (lastWindowClosed) { -
7462 QGuiApplicationPrivate::emitLastWindowClosed(); -
7463 QCoreApplicationPrivate *applicationPrivate = static_cast<QCoreApplicationPrivate*>(QObjectPrivate::get(QCoreApplication::instance())); -
7464 applicationPrivate->maybeQuit(); -
7465 } -
7466 } -
7467 -
7468 -
7469 if (!that.isNull()) { -
7470 data.is_closing = 0; -
7471 if (q->testAttribute(Qt::WA_DeleteOnClose)) { -
7472 q->setAttribute(Qt::WA_DeleteOnClose, false); -
7473 q->deleteLater(); -
7474 } -
7475 } -
7476 return true; -
7477} -
7478 -
7479 -
7480/*! -
7481 Closes this widget. Returns true if the widget was closed; -
7482 otherwise returns false. -
7483 -
7484 First it sends the widget a QCloseEvent. The widget is -
7485 \l{hide()}{hidden} if it \l{QCloseEvent::accept()}{accepts} -
7486 the close event. If it \l{QCloseEvent::ignore()}{ignores} -
7487 the event, nothing happens. The default -
7488 implementation of QWidget::closeEvent() accepts the close event. -
7489 -
7490 If the widget has the Qt::WA_DeleteOnClose flag, the widget -
7491 is also deleted. A close events is delivered to the widget no -
7492 matter if the widget is visible or not. -
7493 -
7494 The \l QApplication::lastWindowClosed() signal is emitted when the -
7495 last visible primary window (i.e. window with no parent) with the -
7496 Qt::WA_QuitOnClose attribute set is closed. By default this -
7497 attribute is set for all widgets except transient windows such as -
7498 splash screens, tool windows, and popup menus. -
7499 -
7500*/ -
7501 -
7502bool QWidget::close() -
7503{ -
7504 return d_func()->close_helper(QWidgetPrivate::CloseWithEvent); -
7505} -
7506 -
7507/*! -
7508 \property QWidget::visible -
7509 \brief whether the widget is visible -
7510 -
7511 Calling setVisible(true) or show() sets the widget to visible -
7512 status if all its parent widgets up to the window are visible. If -
7513 an ancestor is not visible, the widget won't become visible until -
7514 all its ancestors are shown. If its size or position has changed, -
7515 Qt guarantees that a widget gets move and resize events just -
7516 before it is shown. If the widget has not been resized yet, Qt -
7517 will adjust the widget's size to a useful default using -
7518 adjustSize(). -
7519 -
7520 Calling setVisible(false) or hide() hides a widget explicitly. An -
7521 explicitly hidden widget will never become visible, even if all -
7522 its ancestors become visible, unless you show it. -
7523 -
7524 A widget receives show and hide events when its visibility status -
7525 changes. Between a hide and a show event, there is no need to -
7526 waste CPU cycles preparing or displaying information to the user. -
7527 A video application, for example, might simply stop generating new -
7528 frames. -
7529 -
7530 A widget that happens to be obscured by other windows on the -
7531 screen is considered to be visible. The same applies to iconified -
7532 windows and windows that exist on another virtual -
7533 desktop (on platforms that support this concept). A widget -
7534 receives spontaneous show and hide events when its mapping status -
7535 is changed by the window system, e.g. a spontaneous hide event -
7536 when the user minimizes the window, and a spontaneous show event -
7537 when the window is restored again. -
7538 -
7539 You almost never have to reimplement the setVisible() function. If -
7540 you need to change some settings before a widget is shown, use -
7541 showEvent() instead. If you need to do some delayed initialization -
7542 use the Polish event delivered to the event() function. -
7543 -
7544 \sa show(), hide(), isHidden(), isVisibleTo(), isMinimized(), -
7545 showEvent(), hideEvent() -
7546*/ -
7547 -
7548 -
7549/*! -
7550 Returns true if this widget would become visible if \a ancestor is -
7551 shown; otherwise returns false. -
7552 -
7553 The true case occurs if neither the widget itself nor any parent -
7554 up to but excluding \a ancestor has been explicitly hidden. -
7555 -
7556 This function will still return true if the widget is obscured by -
7557 other windows on the screen, but could be physically visible if it -
7558 or they were to be moved. -
7559 -
7560 isVisibleTo(0) is identical to isVisible(). -
7561 -
7562 \sa show(), hide(), isVisible() -
7563*/ -
7564 -
7565bool QWidget::isVisibleTo(const QWidget *ancestor) const -
7566{ -
7567 if (!ancestor) -
7568 return isVisible(); -
7569 const QWidget * w = this; -
7570 while (!w->isHidden() -
7571 && !w->isWindow() -
7572 && w->parentWidget() -
7573 && w->parentWidget() != ancestor) -
7574 w = w->parentWidget(); -
7575 return !w->isHidden(); -
7576} -
7577 -
7578 -
7579/*! -
7580 Returns the unobscured region where paint events can occur. -
7581 -
7582 For visible widgets, this is an approximation of the area not -
7583 covered by other widgets; otherwise, this is an empty region. -
7584 -
7585 The repaint() function calls this function if necessary, so in -
7586 general you do not need to call it. -
7587 -
7588*/ -
7589QRegion QWidget::visibleRegion() const -
7590{ -
7591 Q_D(const QWidget); -
7592 -
7593 QRect clipRect = d->clipRect(); -
7594 if (clipRect.isEmpty()) -
7595 return QRegion(); -
7596 QRegion r(clipRect); -
7597 d->subtractOpaqueChildren(r, clipRect); -
7598 d->subtractOpaqueSiblings(r); -
7599 return r; -
7600} -
7601 -
7602 -
7603QSize QWidgetPrivate::adjustedSize() const -
7604{ -
7605 Q_Q(const QWidget); -
7606 -
7607 QSize s = q->sizeHint(); -
7608 -
7609 if (q->isWindow()) { -
7610 Qt::Orientations exp; -
7611 if (layout) { -
7612 if (layout->hasHeightForWidth()) -
7613 s.setHeight(layout->totalHeightForWidth(s.width())); -
7614 exp = layout->expandingDirections(); -
7615 } else -
7616 { -
7617 if (q->sizePolicy().hasHeightForWidth()) -
7618 s.setHeight(q->heightForWidth(s.width())); -
7619 exp = q->sizePolicy().expandingDirections(); -
7620 } -
7621 if (exp & Qt::Horizontal) -
7622 s.setWidth(qMax(s.width(), 200)); -
7623 if (exp & Qt::Vertical) -
7624 s.setHeight(qMax(s.height(), 100)); -
7625#if defined(Q_WS_X11) -
7626 QRect screen = QApplication::desktop()->screenGeometry(q->x11Info().screen()); -
7627#else // all others -
7628 QRect screen = QApplication::desktop()->screenGeometry(q->pos()); -
7629#endif -
7630#if defined (Q_OS_WINCE) -
7631 s.setWidth(qMin(s.width(), screen.width())); -
7632 s.setHeight(qMin(s.height(), screen.height())); -
7633#else -
7634 s.setWidth(qMin(s.width(), screen.width()*2/3)); -
7635 s.setHeight(qMin(s.height(), screen.height()*2/3)); -
7636#endif -
7637 if (QTLWExtra *extra = maybeTopData()) -
7638 extra->sizeAdjusted = true; -
7639 } -
7640 -
7641 if (!s.isValid()) { -
7642 QRect r = q->childrenRect(); // get children rectangle -
7643 if (r.isNull()) -
7644 return s; -
7645 s = r.size() + QSize(2 * r.x(), 2 * r.y()); -
7646 } -
7647 -
7648 return s; -
7649} -
7650 -
7651/*! -
7652 Adjusts the size of the widget to fit its contents. -
7653 -
7654 This function uses sizeHint() if it is valid, i.e., the size hint's width -
7655 and height are \>= 0. Otherwise, it sets the size to the children -
7656 rectangle that covers all child widgets (the union of all child widget -
7657 rectangles). -
7658 -
7659 For windows, the screen size is also taken into account. If the sizeHint() -
7660 is less than (200, 100) and the size policy is \l{QSizePolicy::Expanding} -
7661 {expanding}, the window will be at least (200, 100). The maximum size of -
7662 a window is 2/3 of the screen's width and height. -
7663 -
7664 \sa sizeHint(), childrenRect() -
7665*/ -
7666 -
7667void QWidget::adjustSize() -
7668{ -
7669 Q_D(QWidget); -
7670 ensurePolished(); -
7671 QSize s = d->adjustedSize(); -
7672 -
7673 if (d->layout) -
7674 d->layout->activate(); -
7675 -
7676 if (s.isValid()) -
7677 resize(s); -
7678} -
7679 -
7680 -
7681/*! -
7682 \property QWidget::sizeHint -
7683 \brief the recommended size for the widget -
7684 -
7685 If the value of this property is an invalid size, no size is -
7686 recommended. -
7687 -
7688 The default implementation of sizeHint() returns an invalid size -
7689 if there is no layout for this widget, and returns the layout's -
7690 preferred size otherwise. -
7691 -
7692 \sa QSize::isValid(), minimumSizeHint(), sizePolicy(), -
7693 setMinimumSize(), updateGeometry() -
7694*/ -
7695 -
7696QSize QWidget::sizeHint() const -
7697{ -
7698 Q_D(const QWidget); -
7699 if (d->layout) -
7700 return d->layout->totalSizeHint(); -
7701 return QSize(-1, -1); -
7702} -
7703 -
7704/*! -
7705 \property QWidget::minimumSizeHint -
7706 \brief the recommended minimum size for the widget -
7707 -
7708 If the value of this property is an invalid size, no minimum size -
7709 is recommended. -
7710 -
7711 The default implementation of minimumSizeHint() returns an invalid -
7712 size if there is no layout for this widget, and returns the -
7713 layout's minimum size otherwise. Most built-in widgets reimplement -
7714 minimumSizeHint(). -
7715 -
7716 \l QLayout will never resize a widget to a size smaller than the -
7717 minimum size hint unless minimumSize() is set or the size policy is -
7718 set to QSizePolicy::Ignore. If minimumSize() is set, the minimum -
7719 size hint will be ignored. -
7720 -
7721 \sa QSize::isValid(), resize(), setMinimumSize(), sizePolicy() -
7722*/ -
7723QSize QWidget::minimumSizeHint() const -
7724{ -
7725 Q_D(const QWidget); -
7726 if (d->layout) -
7727 return d->layout->totalMinimumSize(); -
7728 return QSize(-1, -1); -
7729} -
7730 -
7731 -
7732/*! -
7733 \fn QWidget *QWidget::parentWidget() const -
7734 -
7735 Returns the parent of this widget, or 0 if it does not have any -
7736 parent widget. -
7737*/ -
7738 -
7739 -
7740/*! -
7741 Returns true if this widget is a parent, (or grandparent and so on -
7742 to any level), of the given \a child, and both widgets are within -
7743 the same window; otherwise returns false. -
7744*/ -
7745 -
7746bool QWidget::isAncestorOf(const QWidget *child) const -
7747{ -
7748 while (child) { -
7749 if (child == this) -
7750 return true; -
7751 if (child->isWindow()) -
7752 return false; -
7753 child = child->parentWidget(); -
7754 } -
7755 return false; -
7756} -
7757 -
7758#if defined(Q_WS_WIN) -
7759inline void setDisabledStyle(QWidget *w, bool setStyle) -
7760{ -
7761 // set/reset WS_DISABLED style. -
7762 if(w && w->isWindow() && w->isVisible() && w->isEnabled()) { -
7763 LONG dwStyle = GetWindowLong(w->winId(), GWL_STYLE); -
7764 LONG newStyle = dwStyle; -
7765 if (setStyle) -
7766 newStyle |= WS_DISABLED; -
7767 else -
7768 newStyle &= ~WS_DISABLED; -
7769 if (newStyle != dwStyle) { -
7770 SetWindowLong(w->winId(), GWL_STYLE, newStyle); -
7771 // we might need to repaint in some situations (eg. menu) -
7772 w->repaint(); -
7773 } -
7774 } -
7775} -
7776#endif -
7777 -
7778/***************************************************************************** -
7779 QWidget event handling -
7780 *****************************************************************************/ -
7781 -
7782/*! -
7783 This is the main event handler; it handles event \a event. You can -
7784 reimplement this function in a subclass, but we recommend using -
7785 one of the specialized event handlers instead. -
7786 -
7787 Key press and release events are treated differently from other -
7788 events. event() checks for Tab and Shift+Tab and tries to move the -
7789 focus appropriately. If there is no widget to move the focus to -
7790 (or the key press is not Tab or Shift+Tab), event() calls -
7791 keyPressEvent(). -
7792 -
7793 Mouse and tablet event handling is also slightly special: only -
7794 when the widget is \l enabled, event() will call the specialized -
7795 handlers such as mousePressEvent(); otherwise it will discard the -
7796 event. -
7797 -
7798 This function returns true if the event was recognized, otherwise -
7799 it returns false. If the recognized event was accepted (see \l -
7800 QEvent::accepted), any further processing such as event -
7801 propagation to the parent widget stops. -
7802 -
7803 \sa closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(), -
7804 keyPressEvent(), keyReleaseEvent(), leaveEvent(), -
7805 mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), -
7806 mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(), -
7807 QObject::event(), QObject::timerEvent() -
7808*/ -
7809 -
7810bool QWidget::event(QEvent *event) -
7811{ -
7812 Q_D(QWidget); -
7813 -
7814 // ignore mouse and key events when disabled -
7815 if (!isEnabled()) { -
7816 switch(event->type()) { -
7817 case QEvent::TabletPress: -
7818 case QEvent::TabletRelease: -
7819 case QEvent::TabletMove: -
7820 case QEvent::MouseButtonPress: -
7821 case QEvent::MouseButtonRelease: -
7822 case QEvent::MouseButtonDblClick: -
7823 case QEvent::MouseMove: -
7824 case QEvent::TouchBegin: -
7825 case QEvent::TouchUpdate: -
7826 case QEvent::TouchEnd: -
7827 case QEvent::TouchCancel: -
7828 case QEvent::ContextMenu: -
7829 case QEvent::KeyPress: -
7830 case QEvent::KeyRelease: -
7831#ifndef QT_NO_WHEELEVENT -
7832 case QEvent::Wheel: -
7833#endif -
7834 return false; -
7835 default: -
7836 break; -
7837 } -
7838 } -
7839 switch (event->type()) { -
7840 case QEvent::MouseMove: -
7841 mouseMoveEvent((QMouseEvent*)event); -
7842 break; -
7843 -
7844 case QEvent::MouseButtonPress: -
7845 mousePressEvent((QMouseEvent*)event); -
7846 break; -
7847 -
7848 case QEvent::MouseButtonRelease: -
7849 mouseReleaseEvent((QMouseEvent*)event); -
7850 break; -
7851 -
7852 case QEvent::MouseButtonDblClick: -
7853 mouseDoubleClickEvent((QMouseEvent*)event); -
7854 break; -
7855#ifndef QT_NO_WHEELEVENT -
7856 case QEvent::Wheel: -
7857 wheelEvent((QWheelEvent*)event); -
7858 break; -
7859#endif -
7860#ifndef QT_NO_TABLETEVENT -
7861 case QEvent::TabletMove: -
7862 case QEvent::TabletPress: -
7863 case QEvent::TabletRelease: -
7864 tabletEvent((QTabletEvent*)event); -
7865 break; -
7866#endif -
7867 case QEvent::KeyPress: { -
7868 QKeyEvent *k = (QKeyEvent *)event; -
7869 bool res = false; -
7870 if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier? -
7871 if (k->key() == Qt::Key_Backtab -
7872 || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) -
7873 res = focusNextPrevChild(false); -
7874 else if (k->key() == Qt::Key_Tab) -
7875 res = focusNextPrevChild(true); -
7876 if (res) -
7877 break; -
7878 } -
7879 keyPressEvent(k); -
7880#ifdef QT_KEYPAD_NAVIGATION -
7881 if (!k->isAccepted() && QApplication::keypadNavigationEnabled() -
7882 && !(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::ShiftModifier))) { -
7883 if (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder) { -
7884 if (k->key() == Qt::Key_Up) -
7885 res = focusNextPrevChild(false); -
7886 else if (k->key() == Qt::Key_Down) -
7887 res = focusNextPrevChild(true); -
7888 } else if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { -
7889 if (k->key() == Qt::Key_Up) -
7890 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionNorth); -
7891 else if (k->key() == Qt::Key_Right) -
7892 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionEast); -
7893 else if (k->key() == Qt::Key_Down) -
7894 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionSouth); -
7895 else if (k->key() == Qt::Key_Left) -
7896 res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionWest); -
7897 } -
7898 if (res) { -
7899 k->accept(); -
7900 break; -
7901 } -
7902 } -
7903#endif -
7904#ifndef QT_NO_WHATSTHIS -
7905 if (!k->isAccepted() -
7906 && k->modifiers() & Qt::ShiftModifier && k->key() == Qt::Key_F1 -
7907 && d->whatsThis.size()) { -
7908 QWhatsThis::showText(mapToGlobal(inputMethodQuery(Qt::ImCursorRectangle).toRect().center()), d->whatsThis, this); -
7909 k->accept(); -
7910 } -
7911#endif -
7912 } -
7913 break; -
7914 -
7915 case QEvent::KeyRelease: -
7916 keyReleaseEvent((QKeyEvent*)event); -
7917 // fall through -
7918 case QEvent::ShortcutOverride: -
7919 break; -
7920 -
7921 case QEvent::InputMethod: -
7922 inputMethodEvent((QInputMethodEvent *) event); -
7923 break; -
7924 -
7925 case QEvent::InputMethodQuery: -
7926 if (testAttribute(Qt::WA_InputMethodEnabled)) { -
7927 QInputMethodQueryEvent *query = static_cast<QInputMethodQueryEvent *>(event); -
7928 Qt::InputMethodQueries queries = query->queries(); -
7929 for (uint i = 0; i < 32; ++i) { -
7930 Qt::InputMethodQuery q = (Qt::InputMethodQuery)(int)(queries & (1<<i)); -
7931 if (q) { -
7932 QVariant v = inputMethodQuery(q); -
7933 if (q == Qt::ImEnabled && !v.isValid() && isEnabled()) -
7934 v = QVariant(true); // special case for Qt4 compatibility -
7935 query->setValue(q, v); -
7936 } -
7937 } -
7938 query->accept(); -
7939 } -
7940 break; -
7941 -
7942 case QEvent::PolishRequest: -
7943 ensurePolished(); -
7944 break; -
7945 -
7946 case QEvent::Polish: { -
7947 style()->polish(this); -
7948 setAttribute(Qt::WA_WState_Polished); -
7949 if (!QApplication::font(this).isCopyOf(QApplication::font())) -
7950 d->resolveFont(); -
7951 if (!QApplication::palette(this).isCopyOf(QApplication::palette())) -
7952 d->resolvePalette(); -
7953 } -
7954 break; -
7955 -
7956 case QEvent::ApplicationWindowIconChange: -
7957 if (isWindow() && !testAttribute(Qt::WA_SetWindowIcon)) { -
7958 d->setWindowIcon_sys(); -
7959 d->setWindowIcon_helper(); -
7960 } -
7961 break; -
7962 case QEvent::FocusIn: -
7963 focusInEvent((QFocusEvent*)event); -
7964 d->updateWidgetTransform(); -
7965 break; -
7966 -
7967 case QEvent::FocusOut: -
7968 focusOutEvent((QFocusEvent*)event); -
7969 break; -
7970 -
7971 case QEvent::Enter: -
7972#ifndef QT_NO_STATUSTIP -
7973 if (d->statusTip.size()) { -
7974 QStatusTipEvent tip(d->statusTip); -
7975 QApplication::sendEvent(const_cast<QWidget *>(this), &tip); -
7976 } -
7977#endif -
7978 enterEvent(event); -
7979 break; -
7980 -
7981 case QEvent::Leave: -
7982#ifndef QT_NO_STATUSTIP -
7983 if (d->statusTip.size()) { -
7984 QString empty; -
7985 QStatusTipEvent tip(empty); -
7986 QApplication::sendEvent(const_cast<QWidget *>(this), &tip); -
7987 } -
7988#endif -
7989 leaveEvent(event); -
7990 break; -
7991 -
7992 case QEvent::HoverEnter: -
7993 case QEvent::HoverLeave: -
7994 update(); -
7995 break; -
7996 -
7997 case QEvent::Paint: -
7998 // At this point the event has to be delivered, regardless -
7999 // whether the widget isVisible() or not because it -
8000 // already went through the filters -
8001 paintEvent((QPaintEvent*)event); -
8002 break; -
8003 -
8004 case QEvent::Move: -
8005 moveEvent((QMoveEvent*)event); -
8006 d->updateWidgetTransform(); -
8007 break; -
8008 -
8009 case QEvent::Resize: -
8010 resizeEvent((QResizeEvent*)event); -
8011 d->updateWidgetTransform(); -
8012 break; -
8013 -
8014 case QEvent::Close: -
8015 closeEvent((QCloseEvent *)event); -
8016 break; -
8017 -
8018#ifndef QT_NO_CONTEXTMENU -
8019 case QEvent::ContextMenu: -
8020 switch (data->context_menu_policy) { -
8021 case Qt::PreventContextMenu: -
8022 break; -
8023 case Qt::DefaultContextMenu: -
8024 contextMenuEvent(static_cast<QContextMenuEvent *>(event)); -
8025 break; -
8026 case Qt::CustomContextMenu: -
8027 emit customContextMenuRequested(static_cast<QContextMenuEvent *>(event)->pos()); -
8028 break; -
8029#ifndef QT_NO_MENU -
8030 case Qt::ActionsContextMenu: -
8031 if (d->actions.count()) { -
8032 QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos(), -
8033 0, this); -
8034 break; -
8035 } -
8036 // fall through -
8037#endif -
8038 default: -
8039 event->ignore(); -
8040 break; -
8041 } -
8042 break; -
8043#endif // QT_NO_CONTEXTMENU -
8044 -
8045#ifndef QT_NO_DRAGANDDROP -
8046 case QEvent::Drop: -
8047 dropEvent((QDropEvent*) event); -
8048 break; -
8049 -
8050 case QEvent::DragEnter: -
8051 dragEnterEvent((QDragEnterEvent*) event); -
8052 break; -
8053 -
8054 case QEvent::DragMove: -
8055 dragMoveEvent((QDragMoveEvent*) event); -
8056 break; -
8057 -
8058 case QEvent::DragLeave: -
8059 dragLeaveEvent((QDragLeaveEvent*) event); -
8060 break; -
8061#endif -
8062 -
8063 case QEvent::Show: -
8064 showEvent((QShowEvent*) event); -
8065 break; -
8066 -
8067 case QEvent::Hide: -
8068 hideEvent((QHideEvent*) event); -
8069 break; -
8070 -
8071 case QEvent::ShowWindowRequest: -
8072 if (!isHidden()) -
8073 d->show_sys(); -
8074 break; -
8075 -
8076 case QEvent::ApplicationFontChange: -
8077 d->resolveFont(); -
8078 break; -
8079 case QEvent::ApplicationPaletteChange: -
8080 if (!(windowType() == Qt::Desktop)) -
8081 d->resolvePalette(); -
8082 break; -
8083 -
8084 case QEvent::ToolBarChange: -
8085 case QEvent::ActivationChange: -
8086 case QEvent::EnabledChange: -
8087 case QEvent::FontChange: -
8088 case QEvent::StyleChange: -
8089 case QEvent::PaletteChange: -
8090 case QEvent::WindowTitleChange: -
8091 case QEvent::IconTextChange: -
8092 case QEvent::ModifiedChange: -
8093 case QEvent::MouseTrackingChange: -
8094 case QEvent::ParentChange: -
8095 case QEvent::WindowStateChange: -
8096 case QEvent::LocaleChange: -
8097 case QEvent::MacSizeChange: -
8098 case QEvent::ContentsRectChange: -
8099 case QEvent::ThemeChange: -
8100 changeEvent(event); -
8101 break; -
8102 -
8103 case QEvent::WindowActivate: -
8104 case QEvent::WindowDeactivate: { -
8105 if (isVisible() && !palette().isEqual(QPalette::Active, QPalette::Inactive)) -
8106 update(); -
8107 QList<QObject*> childList = d->children; -
8108 for (int i = 0; i < childList.size(); ++i) { -
8109 QWidget *w = qobject_cast<QWidget *>(childList.at(i)); -
8110 if (w && w->isVisible() && !w->isWindow()) -
8111 QApplication::sendEvent(w, event); -
8112 } -
8113 break; } -
8114 -
8115 case QEvent::LanguageChange: -
8116 changeEvent(event); -
8117 { -
8118 QList<QObject*> childList = d->children; -
8119 for (int i = 0; i < childList.size(); ++i) { -
8120 QObject *o = childList.at(i); -
8121 if (o) -
8122 QApplication::sendEvent(o, event); -
8123 } -
8124 } -
8125 update(); -
8126 break; -
8127 -
8128 case QEvent::ApplicationLayoutDirectionChange: -
8129 d->resolveLayoutDirection(); -
8130 break; -
8131 -
8132 case QEvent::LayoutDirectionChange: -
8133 if (d->layout) -
8134 d->layout->invalidate(); -
8135 update(); -
8136 changeEvent(event); -
8137 break; -
8138 case QEvent::UpdateRequest: -
8139 d->syncBackingStore(); -
8140 break; -
8141 case QEvent::UpdateLater: -
8142 update(static_cast<QUpdateLaterEvent*>(event)->region()); -
8143 break; -
8144 case QEvent::StyleAnimationUpdate: -
8145 update(); -
8146 break; -
8147 -
8148 case QEvent::WindowBlocked: -
8149 case QEvent::WindowUnblocked: -
8150 if (!d->children.isEmpty()) { -
8151 QWidget *modalWidget = QApplication::activeModalWidget(); -
8152 for (int i = 0; i < d->children.size(); ++i) { -
8153 QObject *o = d->children.at(i); -
8154 if (o && o != modalWidget && o->isWidgetType()) { -
8155 QWidget *w = static_cast<QWidget *>(o); -
8156 // do not forward the event to child windows; QApplication does this for us -
8157 if (!w->isWindow()) -
8158 QApplication::sendEvent(w, event); -
8159 } -
8160 } -
8161 } -
8162#if defined(Q_WS_WIN) -
8163 setDisabledStyle(this, (event->type() == QEvent::WindowBlocked)); -
8164#endif -
8165 break; -
8166#ifndef QT_NO_TOOLTIP -
8167 case QEvent::ToolTip: -
8168 if (!d->toolTip.isEmpty()) -
8169 QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), d->toolTip, this); -
8170 else -
8171 event->ignore(); -
8172 break; -
8173#endif -
8174#ifndef QT_NO_WHATSTHIS -
8175 case QEvent::WhatsThis: -
8176 if (d->whatsThis.size()) -
8177 QWhatsThis::showText(static_cast<QHelpEvent *>(event)->globalPos(), d->whatsThis, this); -
8178 else -
8179 event->ignore(); -
8180 break; -
8181 case QEvent::QueryWhatsThis: -
8182 if (d->whatsThis.isEmpty()) -
8183 event->ignore(); -
8184 break; -
8185#endif -
8186 case QEvent::EmbeddingControl: -
8187 d->topData()->frameStrut.setCoords(0 ,0, 0, 0); -
8188 data->fstrut_dirty = false; -
8189#if defined(Q_WS_WIN) || defined(Q_WS_X11) -
8190 d->topData()->embedded = 1; -
8191#endif -
8192 break; -
8193#ifndef QT_NO_ACTION -
8194 case QEvent::ActionAdded: -
8195 case QEvent::ActionRemoved: -
8196 case QEvent::ActionChanged: -
8197 actionEvent((QActionEvent*)event); -
8198 break; -
8199#endif -
8200 -
8201 case QEvent::KeyboardLayoutChange: -
8202 { -
8203 changeEvent(event); -
8204 -
8205 // inform children of the change -
8206 QList<QObject*> childList = d->children; -
8207 for (int i = 0; i < childList.size(); ++i) { -
8208 QWidget *w = qobject_cast<QWidget *>(childList.at(i)); -
8209 if (w && w->isVisible() && !w->isWindow()) -
8210 QApplication::sendEvent(w, event); -
8211 } -
8212 break; -
8213 } -
8214#ifdef Q_WS_MAC -
8215 case QEvent::MacGLWindowChange: -
8216 d->needWindowChange = false; -
8217 break; -
8218#endif -
8219 case QEvent::TouchBegin: -
8220 case QEvent::TouchUpdate: -
8221 case QEvent::TouchEnd: -
8222 case QEvent::TouchCancel: -
8223 { -
8224 event->ignore(); -
8225 break; -
8226 } -
8227#ifndef QT_NO_GESTURES -
8228 case QEvent::Gesture: -
8229 event->ignore(); -
8230 break; -
8231#endif -
8232#ifndef QT_NO_PROPERTIES -
8233 case QEvent::DynamicPropertyChange: { -
8234 const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName(); -
8235 if (!qstrncmp(propName, "_q_customDpi", 12) && propName.length() == 13) { -
8236 uint value = property(propName.constData()).toUInt(); -
8237 if (!d->extra) -
8238 d->createExtra(); -
8239 const char axis = propName.at(12); -
8240 if (axis == 'X') -
8241 d->extra->customDpiX = value; -
8242 else if (axis == 'Y') -
8243 d->extra->customDpiY = value; -
8244 d->updateFont(d->data.fnt); -
8245 } -
8246 // fall through -
8247 } -
8248#endif -
8249 default: -
8250 return QObject::event(event); -
8251 } -
8252 return true; -
8253} -
8254 -
8255/*! -
8256 This event handler can be reimplemented to handle state changes. -
8257 -
8258 The state being changed in this event can be retrieved through the \a event -
8259 supplied. -
8260 -
8261 Change events include: QEvent::ToolBarChange, -
8262 QEvent::ActivationChange, QEvent::EnabledChange, QEvent::FontChange, -
8263 QEvent::StyleChange, QEvent::PaletteChange, -
8264 QEvent::WindowTitleChange, QEvent::IconTextChange, -
8265 QEvent::ModifiedChange, QEvent::MouseTrackingChange, -
8266 QEvent::ParentChange, QEvent::WindowStateChange, -
8267 QEvent::LanguageChange, QEvent::LocaleChange, -
8268 QEvent::LayoutDirectionChange. -
8269 -
8270*/ -
8271void QWidget::changeEvent(QEvent * event) -
8272{ -
8273 switch(event->type()) { -
8274 case QEvent::EnabledChange: { -
8275 update(); -
8276#ifndef QT_NO_ACCESSIBILITY -
8277 QAccessible::State s; -
8278 s.disabled = true; -
8279 QAccessibleStateChangeEvent event(this, s); -
8280 QAccessible::updateAccessibility(&event); -
8281#endif -
8282 break; -
8283 } -
8284 -
8285 case QEvent::FontChange: -
8286 case QEvent::StyleChange: { -
8287 Q_D(QWidget); -
8288 update(); -
8289 updateGeometry(); -
8290 if (d->layout) -
8291 d->layout->invalidate(); -
8292 break; -
8293 } -
8294 -
8295 case QEvent::PaletteChange: -
8296 update(); -
8297 break; -
8298 -
8299 case QEvent::ThemeChange: -
8300 if (QApplication::desktopSettingsAware() && windowType() != Qt::Desktop -
8301 && qApp && !QApplication::closingDown()) { -
8302 if (testAttribute(Qt::WA_WState_Polished)) -
8303 QApplication::style()->unpolish(this); -
8304 if (testAttribute(Qt::WA_WState_Polished)) -
8305 QApplication::style()->polish(this); -
8306 QEvent styleChangedEvent(QEvent::StyleChange); -
8307 QCoreApplication::sendEvent(this, &styleChangedEvent); -
8308 if (isVisible()) -
8309 update(); -
8310 } -
8311 break; -
8312 -
8313#ifdef Q_OS_MAC -
8314 case QEvent::MacSizeChange: -
8315 updateGeometry(); -
8316 break; -
8317#elif defined Q_WS_MAC -
8318 case QEvent::ToolTipChange: -
8319 case QEvent::MouseTrackingChange: -
8320 qt_mac_update_mouseTracking(this); -
8321 break; -
8322#endif -
8323 -
8324 default: -
8325 break; -
8326 } -
8327} -
8328 -
8329/*! -
8330 This event handler, for event \a event, can be reimplemented in a -
8331 subclass to receive mouse move events for the widget. -
8332 -
8333 If mouse tracking is switched off, mouse move events only occur if -
8334 a mouse button is pressed while the mouse is being moved. If mouse -
8335 tracking is switched on, mouse move events occur even if no mouse -
8336 button is pressed. -
8337 -
8338 QMouseEvent::pos() reports the position of the mouse cursor, -
8339 relative to this widget. For press and release events, the -
8340 position is usually the same as the position of the last mouse -
8341 move event, but it might be different if the user's hand shakes. -
8342 This is a feature of the underlying window system, not Qt. -
8343 -
8344 If you want to show a tooltip immediately, while the mouse is -
8345 moving (e.g., to get the mouse coordinates with QMouseEvent::pos() -
8346 and show them as a tooltip), you must first enable mouse tracking -
8347 as described above. Then, to ensure that the tooltip is updated -
8348 immediately, you must call QToolTip::showText() instead of -
8349 setToolTip() in your implementation of mouseMoveEvent(). -
8350 -
8351 \sa setMouseTracking(), mousePressEvent(), mouseReleaseEvent(), -
8352 mouseDoubleClickEvent(), event(), QMouseEvent, {Scribble Example} -
8353*/ -
8354 -
8355void QWidget::mouseMoveEvent(QMouseEvent *event) -
8356{ -
8357 event->ignore(); -
8358} -
8359 -
8360/*! -
8361 This event handler, for event \a event, can be reimplemented in a -
8362 subclass to receive mouse press events for the widget. -
8363 -
8364 If you create new widgets in the mousePressEvent() the -
8365 mouseReleaseEvent() may not end up where you expect, depending on -
8366 the underlying window system (or X11 window manager), the widgets' -
8367 location and maybe more. -
8368 -
8369 The default implementation implements the closing of popup widgets -
8370 when you click outside the window. For other widget types it does -
8371 nothing. -
8372 -
8373 \sa mouseReleaseEvent(), mouseDoubleClickEvent(), -
8374 mouseMoveEvent(), event(), QMouseEvent, {Scribble Example} -
8375*/ -
8376 -
8377void QWidget::mousePressEvent(QMouseEvent *event) -
8378{ -
8379 event->ignore(); -
8380 if ((windowType() == Qt::Popup)) { -
8381 event->accept(); -
8382 QWidget* w; -
8383 while ((w = QApplication::activePopupWidget()) && w != this){ -
8384 w->close(); -
8385 if (QApplication::activePopupWidget() == w) // widget does not want to disappear -
8386 w->hide(); // hide at least -
8387 } -
8388 if (!rect().contains(event->pos())){ -
8389 close(); -
8390 } -
8391 } -
8392} -
8393 -
8394/*! -
8395 This event handler, for event \a event, can be reimplemented in a -
8396 subclass to receive mouse release events for the widget. -
8397 -
8398 \sa mousePressEvent(), mouseDoubleClickEvent(), -
8399 mouseMoveEvent(), event(), QMouseEvent, {Scribble Example} -
8400*/ -
8401 -
8402void QWidget::mouseReleaseEvent(QMouseEvent *event) -
8403{ -
8404 event->ignore(); -
8405} -
8406 -
8407/*! -
8408 This event handler, for event \a event, can be reimplemented in a -
8409 subclass to receive mouse double click events for the widget. -
8410 -
8411 The default implementation generates a normal mouse press event. -
8412 -
8413 \note The widget will also receive mouse press and mouse release -
8414 events in addition to the double click event. It is up to the -
8415 developer to ensure that the application interprets these events -
8416 correctly. -
8417 -
8418 \sa mousePressEvent(), mouseReleaseEvent(), mouseMoveEvent(), -
8419 event(), QMouseEvent -
8420*/ -
8421 -
8422void QWidget::mouseDoubleClickEvent(QMouseEvent *event) -
8423{ -
8424 Q_UNUSED(event);->ignore();
executed (the execution status of this line is deduced): event->ignore();
-
8425}
executed: }
Execution Count:12
12
8426 -
8427#ifndef QT_NO_WHEELEVENT -
8428/*! -
8429 This event handler, for event \a event, can be reimplemented in a -
8430 subclass to receive wheel events for the widget. -
8431 -
8432 If you reimplement this handler, it is very important that you -
8433 \l{QWheelEvent}{ignore()} the event if you do not handle -
8434 it, so that the widget's parent can interpret it. -
8435 -
8436 The default implementation ignores the event. -
8437 -
8438 \sa QWheelEvent::ignore(), QWheelEvent::accept(), event(), -
8439 QWheelEvent -
8440*/ -
8441 -
8442void QWidget::wheelEvent(QWheelEvent *event) -
8443{ -
8444 event->ignore(); -
8445} -
8446#endif // QT_NO_WHEELEVENT -
8447 -
8448#ifndef QT_NO_TABLETEVENT -
8449/*! -
8450 This event handler, for event \a event, can be reimplemented in a -
8451 subclass to receive tablet events for the widget. -
8452 -
8453 If you reimplement this handler, it is very important that you -
8454 \l{QTabletEvent}{ignore()} the event if you do not handle -
8455 it, so that the widget's parent can interpret it. -
8456 -
8457 The default implementation ignores the event. -
8458 -
8459 \sa QTabletEvent::ignore(), QTabletEvent::accept(), event(), -
8460 QTabletEvent -
8461*/ -
8462 -
8463void QWidget::tabletEvent(QTabletEvent *event) -
8464{ -
8465 event->ignore(); -
8466} -
8467#endif // QT_NO_TABLETEVENT -
8468 -
8469/*! -
8470 This event handler, for event \a event, can be reimplemented in a -
8471 subclass to receive key press events for the widget. -
8472 -
8473 A widget must call setFocusPolicy() to accept focus initially and -
8474 have focus in order to receive a key press event. -
8475 -
8476 If you reimplement this handler, it is very important that you -
8477 call the base class implementation if you do not act upon the key. -
8478 -
8479 The default implementation closes popup widgets if the user -
8480 presses Esc. Otherwise the event is ignored, so that the widget's -
8481 parent can interpret it. -
8482 -
8483 Note that QKeyEvent starts with isAccepted() == true, so you do not -
8484 need to call QKeyEvent::accept() - just do not call the base class -
8485 implementation if you act upon the key. -
8486 -
8487 \sa keyReleaseEvent(), setFocusPolicy(), -
8488 focusInEvent(), focusOutEvent(), event(), QKeyEvent, {Tetrix Example} -
8489*/ -
8490 -
8491void QWidget::keyPressEvent(QKeyEvent *event) -
8492{ -
8493 if ((windowType() == Qt::Popup) && event->key() == Qt::Key_Escape) { -
8494 event->accept(); -
8495 close(); -
8496 } else { -
8497 event->ignore(); -
8498 } -
8499} -
8500 -
8501/*! -
8502 This event handler, for event \a event, can be reimplemented in a -
8503 subclass to receive key release events for the widget. -
8504 -
8505 A widget must \l{setFocusPolicy()}{accept focus} -
8506 initially and \l{hasFocus()}{have focus} in order to -
8507 receive a key release event. -
8508 -
8509 If you reimplement this handler, it is very important that you -
8510 call the base class implementation if you do not act upon the key. -
8511 -
8512 The default implementation ignores the event, so that the widget's -
8513 parent can interpret it. -
8514 -
8515 Note that QKeyEvent starts with isAccepted() == true, so you do not -
8516 need to call QKeyEvent::accept() - just do not call the base class -
8517 implementation if you act upon the key. -
8518 -
8519 \sa keyPressEvent(), QKeyEvent::ignore(), setFocusPolicy(), -
8520 focusInEvent(), focusOutEvent(), event(), QKeyEvent -
8521*/ -
8522 -
8523void QWidget::keyReleaseEvent(QKeyEvent *event) -
8524{ -
8525 event->ignore(); -
8526} -
8527 -
8528/*! -
8529 \fn void QWidget::focusInEvent(QFocusEvent *event) -
8530 -
8531 This event handler can be reimplemented in a subclass to receive -
8532 keyboard focus events (focus received) for the widget. The event -
8533 is passed in the \a event parameter -
8534 -
8535 A widget normally must setFocusPolicy() to something other than -
8536 Qt::NoFocus in order to receive focus events. (Note that the -
8537 application programmer can call setFocus() on any widget, even -
8538 those that do not normally accept focus.) -
8539 -
8540 The default implementation updates the widget (except for windows -
8541 that do not specify a focusPolicy()). -
8542 -
8543 \sa focusOutEvent(), setFocusPolicy(), keyPressEvent(), -
8544 keyReleaseEvent(), event(), QFocusEvent -
8545*/ -
8546 -
8547void QWidget::focusInEvent(QFocusEvent *) -
8548{ -
8549 if (focusPolicy() != Qt::NoFocus || !isWindow()) { -
8550 update(); -
8551 } -
8552} -
8553 -
8554/*! -
8555 \fn void QWidget::focusOutEvent(QFocusEvent *event) -
8556 -
8557 This event handler can be reimplemented in a subclass to receive -
8558 keyboard focus events (focus lost) for the widget. The events is -
8559 passed in the \a event parameter. -
8560 -
8561 A widget normally must setFocusPolicy() to something other than -
8562 Qt::NoFocus in order to receive focus events. (Note that the -
8563 application programmer can call setFocus() on any widget, even -
8564 those that do not normally accept focus.) -
8565 -
8566 The default implementation updates the widget (except for windows -
8567 that do not specify a focusPolicy()). -
8568 -
8569 \sa focusInEvent(), setFocusPolicy(), keyPressEvent(), -
8570 keyReleaseEvent(), event(), QFocusEvent -
8571*/ -
8572 -
8573void QWidget::focusOutEvent(QFocusEvent *) -
8574{ -
8575 if (focusPolicy() != Qt::NoFocus || !isWindow()) -
8576 update(); -
8577} -
8578 -
8579/*! -
8580 \fn void QWidget::enterEvent(QEvent *event) -
8581 -
8582 This event handler can be reimplemented in a subclass to receive -
8583 widget enter events which are passed in the \a event parameter. -
8584 -
8585 An event is sent to the widget when the mouse cursor enters the -
8586 widget. -
8587 -
8588 \sa leaveEvent(), mouseMoveEvent(), event() -
8589*/ -
8590 -
8591void QWidget::enterEvent(QEvent *) -
8592{ -
8593} -
8594 -
8595// ### Qt 6: void QWidget::enterEvent(QEnterEvent *). -
8596 -
8597/*! -
8598 \fn void QWidget::leaveEvent(QEvent *event) -
8599 -
8600 This event handler can be reimplemented in a subclass to receive -
8601 widget leave events which are passed in the \a event parameter. -
8602 -
8603 A leave event is sent to the widget when the mouse cursor leaves -
8604 the widget. -
8605 -
8606 \sa enterEvent(), mouseMoveEvent(), event() -
8607*/ -
8608 -
8609void QWidget::leaveEvent(QEvent *) -
8610{ -
8611} -
8612 -
8613/*! -
8614 \fn void QWidget::paintEvent(QPaintEvent *event) -
8615 -
8616 This event handler can be reimplemented in a subclass to receive paint -
8617 events passed in \a event. -
8618 -
8619 A paint event is a request to repaint all or part of a widget. It can -
8620 happen for one of the following reasons: -
8621 -
8622 \list -
8623 \li repaint() or update() was invoked, -
8624 \li the widget was obscured and has now been uncovered, or -
8625 \li many other reasons. -
8626 \endlist -
8627 -
8628 Many widgets can simply repaint their entire surface when asked to, but -
8629 some slow widgets need to optimize by painting only the requested region: -
8630 QPaintEvent::region(). This speed optimization does not change the result, -
8631 as painting is clipped to that region during event processing. QListView -
8632 and QTableView do this, for example. -
8633 -
8634 Qt also tries to speed up painting by merging multiple paint events into -
8635 one. When update() is called several times or the window system sends -
8636 several paint events, Qt merges these events into one event with a larger -
8637 region (see QRegion::united()). The repaint() function does not permit this -
8638 optimization, so we suggest using update() whenever possible. -
8639 -
8640 When the paint event occurs, the update region has normally been erased, so -
8641 you are painting on the widget's background. -
8642 -
8643 The background can be set using setBackgroundRole() and setPalette(). -
8644 -
8645 Since Qt 4.0, QWidget automatically double-buffers its painting, so there -
8646 is no need to write double-buffering code in paintEvent() to avoid flicker. -
8647 -
8648 \b{Note for the X11 platform}: It is possible to toggle global double -
8649 buffering by calling \c qt_x11_set_global_double_buffer(). For example, -
8650 -
8651 \snippet code/src_gui_kernel_qwidget.cpp 14 -
8652 -
8653 \note Generally, you should refrain from calling update() or repaint() -
8654 \b{inside} a paintEvent(). For example, calling update() or repaint() on -
8655 children inside a paintevent() results in undefined behavior; the child may -
8656 or may not get a paint event. -
8657 -
8658 \warning If you are using a custom paint engine without Qt's backingstore, -
8659 Qt::WA_PaintOnScreen must be set. Otherwise, QWidget::paintEngine() will -
8660 never be called; the backingstore will be used instead. -
8661 -
8662 \sa event(), repaint(), update(), QPainter, QPixmap, QPaintEvent, -
8663 {Analog Clock Example} -
8664*/ -
8665 -
8666void QWidget::paintEvent(QPaintEvent *) -
8667{ -
8668} -
8669 -
8670 -
8671/*! -
8672 \fn void QWidget::moveEvent(QMoveEvent *event) -
8673 -
8674 This event handler can be reimplemented in a subclass to receive -
8675 widget move events which are passed in the \a event parameter. -
8676 When the widget receives this event, it is already at the new -
8677 position. -
8678 -
8679 The old position is accessible through QMoveEvent::oldPos(). -
8680 -
8681 \sa resizeEvent(), event(), move(), QMoveEvent -
8682*/ -
8683 -
8684void QWidget::moveEvent(QMoveEvent *) -
8685{ -
8686} -
8687 -
8688 -
8689/*! -
8690 This event handler can be reimplemented in a subclass to receive -
8691 widget resize events which are passed in the \a event parameter. -
8692 When resizeEvent() is called, the widget already has its new -
8693 geometry. The old size is accessible through -
8694 QResizeEvent::oldSize(). -
8695 -
8696 The widget will be erased and receive a paint event immediately -
8697 after processing the resize event. No drawing need be (or should -
8698 be) done inside this handler. -
8699 -
8700 -
8701 \sa moveEvent(), event(), resize(), QResizeEvent, paintEvent(), -
8702 {Scribble Example} -
8703*/ -
8704 -
8705void QWidget::resizeEvent(QResizeEvent * /* event */) -
8706{ -
8707} -
8708 -
8709#ifndef QT_NO_ACTION -
8710/*! -
8711 \fn void QWidget::actionEvent(QActionEvent *event) -
8712 -
8713 This event handler is called with the given \a event whenever the -
8714 widget's actions are changed. -
8715 -
8716 \sa addAction(), insertAction(), removeAction(), actions(), QActionEvent -
8717*/ -
8718void QWidget::actionEvent(QActionEvent *) -
8719{ -
8720 -
8721} -
8722#endif -
8723 -
8724/*! -
8725 This event handler is called with the given \a event when Qt receives a window -
8726 close request for a top-level widget from the window system. -
8727 -
8728 By default, the event is accepted and the widget is closed. You can reimplement -
8729 this function to change the way the widget responds to window close requests. -
8730 For example, you can prevent the window from closing by calling \l{QEvent::}{ignore()} -
8731 on all events. -
8732 -
8733 Main window applications typically use reimplementations of this function to check -
8734 whether the user's work has been saved and ask for permission before closing. -
8735 For example, the \l{Application Example} uses a helper function to determine whether -
8736 or not to close the window: -
8737 -
8738 \snippet mainwindows/application/mainwindow.cpp 3 -
8739 \snippet mainwindows/application/mainwindow.cpp 4 -
8740 -
8741 \sa event(), hide(), close(), QCloseEvent, {Application Example} -
8742*/ -
8743 -
8744void QWidget::closeEvent(QCloseEvent *event) -
8745{ -
8746 event->accept(); -
8747} -
8748 -
8749#ifndef QT_NO_CONTEXTMENU -
8750/*! -
8751 This event handler, for event \a event, can be reimplemented in a -
8752 subclass to receive widget context menu events. -
8753 -
8754 The handler is called when the widget's \l contextMenuPolicy is -
8755 Qt::DefaultContextMenu. -
8756 -
8757 The default implementation ignores the context event. -
8758 See the \l QContextMenuEvent documentation for more details. -
8759 -
8760 \sa event(), QContextMenuEvent, customContextMenuRequested() -
8761*/ -
8762 -
8763void QWidget::contextMenuEvent(QContextMenuEvent *event) -
8764{ -
8765 event->ignore(); -
8766} -
8767#endif // QT_NO_CONTEXTMENU -
8768 -
8769 -
8770/*! -
8771 This event handler, for event \a event, can be reimplemented in a -
8772 subclass to receive Input Method composition events. This handler -
8773 is called when the state of the input method changes. -
8774 -
8775 Note that when creating custom text editing widgets, the -
8776 Qt::WA_InputMethodEnabled window attribute must be set explicitly -
8777 (using the setAttribute() function) in order to receive input -
8778 method events. -
8779 -
8780 The default implementation calls event->ignore(), which rejects the -
8781 Input Method event. See the \l QInputMethodEvent documentation for more -
8782 details. -
8783 -
8784 \sa event(), QInputMethodEvent -
8785*/ -
8786void QWidget::inputMethodEvent(QInputMethodEvent *event) -
8787{ -
8788 event->ignore(); -
8789} -
8790 -
8791/*! -
8792 This method is only relevant for input widgets. It is used by the -
8793 input method to query a set of properties of the widget to be -
8794 able to support complex input method operations as support for -
8795 surrounding text and reconversions. -
8796 -
8797 \a query specifies which property is queried. -
8798 -
8799 \sa inputMethodEvent(), QInputMethodEven, inputMethodHints -
8800*/ -
8801QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const -
8802{ -
8803 switch(query) { -
8804 case Qt::ImCursorRectangle: -
8805 return QRect(width()/2, 0, 1, height()); -
8806 case Qt::ImFont: -
8807 return font(); -
8808 case Qt::ImAnchorPosition: -
8809 // Fallback. -
8810 return inputMethodQuery(Qt::ImCursorPosition); -
8811 case Qt::ImHints: -
8812 return (int)inputMethodHints(); -
8813 default: -
8814 return QVariant(); -
8815 } -
8816} -
8817 -
8818/*! -
8819 \property QWidget::inputMethodHints -
8820 \brief What input method specific hints the widget has. -
8821 -
8822 This is only relevant for input widgets. It is used by -
8823 the input method to retrieve hints as to how the input method -
8824 should operate. For example, if the Qt::ImhFormattedNumbersOnly flag -
8825 is set, the input method may change its visual components to reflect -
8826 that only numbers can be entered. -
8827 -
8828 \note The flags are only hints, so the particular input method -
8829 implementation is free to ignore them. If you want to be -
8830 sure that a certain type of characters are entered, -
8831 you should also set a QValidator on the widget. -
8832 -
8833 The default value is Qt::ImhNone. -
8834 -
8835 \since 4.6 -
8836 -
8837 \sa inputMethodQuery() -
8838*/ -
8839Qt::InputMethodHints QWidget::inputMethodHints() const -
8840{ -
8841#ifndef QT_NO_IM -
8842 const QWidgetPrivate *priv = d_func(); -
8843 while (priv->inheritsInputMethodHints) { -
8844 priv = priv->q_func()->parentWidget()->d_func(); -
8845 Q_ASSERT(priv); -
8846 } -
8847 return priv->imHints; -
8848#else //QT_NO_IM -
8849 return 0; -
8850#endif //QT_NO_IM -
8851} -
8852 -
8853void QWidget::setInputMethodHints(Qt::InputMethodHints hints) -
8854{ -
8855#ifndef QT_NO_IM -
8856 Q_D(QWidget);
executed (the execution status of this line is deduced): QWidgetPrivate * const d = d_func();
-
8857 if (d->imHints == hints)
evaluated: d->imHints == hints
TRUEFALSE
yes
Evaluation Count:2782
yes
Evaluation Count:461
461-2782
8858 return;
executed: return;
Execution Count:2782
2782
8859 d->imHints = hints;
executed (the execution status of this line is deduced): d->imHints = hints;
-
8860 qApp->inputMethod()->update(Qt::ImHints);
executed (the execution status of this line is deduced): (static_cast<QApplication *>(QCoreApplication::instance()))->inputMethod()->update(Qt::ImHints);
-
8861#endif //QT_NO_IM -
8862}
executed: }
Execution Count:461
461
8863 -
8864 -
8865#ifndef QT_NO_DRAGANDDROP -
8866 -
8867/*! -
8868 \fn void QWidget::dragEnterEvent(QDragEnterEvent *event) -
8869 -
8870 This event handler is called when a drag is in progress and the -
8871 mouse enters this widget. The event is passed in the \a event parameter. -
8872 -
8873 If the event is ignored, the widget won't receive any \l{dragMoveEvent()}{drag -
8874 move events}. -
8875 -
8876 See the \l{dnd.html}{Drag-and-drop documentation} for an -
8877 overview of how to provide drag-and-drop in your application. -
8878 -
8879 \sa QDrag, QDragEnterEvent -
8880*/ -
8881void QWidget::dragEnterEvent(QDragEnterEvent *) -
8882{ -
8883} -
8884 -
8885/*! -
8886 \fn void QWidget::dragMoveEvent(QDragMoveEvent *event) -
8887 -
8888 This event handler is called if a drag is in progress, and when -
8889 any of the following conditions occur: the cursor enters this widget, -
8890 the cursor moves within this widget, or a modifier key is pressed on -
8891 the keyboard while this widget has the focus. The event is passed -
8892 in the \a event parameter. -
8893 -
8894 See the \l{dnd.html}{Drag-and-drop documentation} for an -
8895 overview of how to provide drag-and-drop in your application. -
8896 -
8897 \sa QDrag, QDragMoveEvent -
8898*/ -
8899void QWidget::dragMoveEvent(QDragMoveEvent *) -
8900{ -
8901} -
8902 -
8903/*! -
8904 \fn void QWidget::dragLeaveEvent(QDragLeaveEvent *event) -
8905 -
8906 This event handler is called when a drag is in progress and the -
8907 mouse leaves this widget. The event is passed in the \a event -
8908 parameter. -
8909 -
8910 See the \l{dnd.html}{Drag-and-drop documentation} for an -
8911 overview of how to provide drag-and-drop in your application. -
8912 -
8913 \sa QDrag, QDragLeaveEvent -
8914*/ -
8915void QWidget::dragLeaveEvent(QDragLeaveEvent *) -
8916{ -
8917} -
8918 -
8919/*! -
8920 \fn void QWidget::dropEvent(QDropEvent *event) -
8921 -
8922 This event handler is called when the drag is dropped on this -
8923 widget. The event is passed in the \a event parameter. -
8924 -
8925 See the \l{dnd.html}{Drag-and-drop documentation} for an -
8926 overview of how to provide drag-and-drop in your application. -
8927 -
8928 \sa QDrag, QDropEvent -
8929*/ -
8930void QWidget::dropEvent(QDropEvent *) -
8931{ -
8932} -
8933 -
8934#endif // QT_NO_DRAGANDDROP -
8935 -
8936/*! -
8937 \fn void QWidget::showEvent(QShowEvent *event) -
8938 -
8939 This event handler can be reimplemented in a subclass to receive -
8940 widget show events which are passed in the \a event parameter. -
8941 -
8942 Non-spontaneous show events are sent to widgets immediately -
8943 before they are shown. The spontaneous show events of windows are -
8944 delivered afterwards. -
8945 -
8946 Note: A widget receives spontaneous show and hide events when its -
8947 mapping status is changed by the window system, e.g. a spontaneous -
8948 hide event when the user minimizes the window, and a spontaneous -
8949 show event when the window is restored again. After receiving a -
8950 spontaneous hide event, a widget is still considered visible in -
8951 the sense of isVisible(). -
8952 -
8953 \sa visible, event(), QShowEvent -
8954*/ -
8955void QWidget::showEvent(QShowEvent *) -
8956{ -
8957} -
8958 -
8959/*! -
8960 \fn void QWidget::hideEvent(QHideEvent *event) -
8961 -
8962 This event handler can be reimplemented in a subclass to receive -
8963 widget hide events. The event is passed in the \a event parameter. -
8964 -
8965 Hide events are sent to widgets immediately after they have been -
8966 hidden. -
8967 -
8968 Note: A widget receives spontaneous show and hide events when its -
8969 mapping status is changed by the window system, e.g. a spontaneous -
8970 hide event when the user minimizes the window, and a spontaneous -
8971 show event when the window is restored again. After receiving a -
8972 spontaneous hide event, a widget is still considered visible in -
8973 the sense of isVisible(). -
8974 -
8975 \sa visible, event(), QHideEvent -
8976*/ -
8977void QWidget::hideEvent(QHideEvent *) -
8978{ -
8979} -
8980 -
8981/*! -
8982 This special event handler can be reimplemented in a subclass to -
8983 receive native platform events identified by \a eventType -
8984 which are passed in the \a message parameter. -
8985 -
8986 In your reimplementation of this function, if you want to stop the -
8987 event being handled by Qt, return true and set \a result. -
8988 If you return false, this native event is passed back to Qt, -
8989 which translates the event into a Qt event and sends it to the widget. -
8990 -
8991 \note Events are only delivered to this event handler if the widget is -
8992 has a native Window handle. -
8993 -
8994 \note This function superseedes the event filter functions -
8995 x11Event(), winEvent() and macEvent() of Qt 4. -
8996 -
8997 \table -
8998 \header \li Platform \li Event Type Identifier \li Message Type \li Result Type -
8999 \row \li Windows \li "windows_generic_MSG" \li MSG * \li LRESULT -
9000 \endtable -
9001*/ -
9002 -
9003bool QWidget::nativeEvent(const QByteArray &eventType, void *message, long *result) -
9004{ -
9005 Q_UNUSED(eventType); -
9006 Q_UNUSED(message); -
9007 Q_UNUSED(result); -
9008 return false; -
9009} -
9010 -
9011/*! -
9012 Ensures that the widget has been polished by QStyle (i.e., has a -
9013 proper font and palette). -
9014 -
9015 QWidget calls this function after it has been fully constructed -
9016 but before it is shown the very first time. You can call this -
9017 function if you want to ensure that the widget is polished before -
9018 doing an operation, e.g., the correct font size might be needed in -
9019 the widget's sizeHint() reimplementation. Note that this function -
9020 \e is called from the default implementation of sizeHint(). -
9021 -
9022 Polishing is useful for final initialization that must happen after -
9023 all constructors (from base classes as well as from subclasses) -
9024 have been called. -
9025 -
9026 If you need to change some settings when a widget is polished, -
9027 reimplement event() and handle the QEvent::Polish event type. -
9028 -
9029 \b{Note:} The function is declared const so that it can be called from -
9030 other const functions (e.g., sizeHint()). -
9031 -
9032 \sa event() -
9033*/ -
9034void QWidget::ensurePolished() const -
9035{ -
9036 Q_D(const QWidget); -
9037 -
9038 const QMetaObject *m = metaObject(); -
9039 if (m == d->polished) -
9040 return; -
9041 d->polished = m; -
9042 -
9043 QEvent e(QEvent::Polish); -
9044 QCoreApplication::sendEvent(const_cast<QWidget *>(this), &e); -
9045 -
9046 // polish children after 'this' -
9047 QList<QObject*> children = d->children; -
9048 for (int i = 0; i < children.size(); ++i) { -
9049 QObject *o = children.at(i); -
9050 if(!o->isWidgetType()) -
9051 continue; -
9052 if (QWidget *w = qobject_cast<QWidget *>(o)) -
9053 w->ensurePolished(); -
9054 } -
9055 -
9056 if (d->parent && d->sendChildEvents) { -
9057 QChildEvent e(QEvent::ChildPolished, const_cast<QWidget *>(this)); -
9058 QCoreApplication::sendEvent(d->parent, &e); -
9059 } -
9060} -
9061 -
9062/*! -
9063 Returns the mask currently set on a widget. If no mask is set the -
9064 return value will be an empty region. -
9065 -
9066 \sa setMask(), clearMask(), QRegion::isEmpty(), {Shaped Clock Example} -
9067*/ -
9068QRegion QWidget::mask() const -
9069{ -
9070 Q_D(const QWidget); -
9071 return d->extra ? d->extra->mask : QRegion(); -
9072} -
9073 -
9074/*! -
9075 Returns the layout manager that is installed on this widget, or 0 -
9076 if no layout manager is installed. -
9077 -
9078 The layout manager sets the geometry of the widget's children -
9079 that have been added to the layout. -
9080 -
9081 \sa setLayout(), sizePolicy(), {Layout Management} -
9082*/ -
9083QLayout *QWidget::layout() const -
9084{ -
9085 return d_func()->layout; -
9086} -
9087 -
9088 -
9089/*! -
9090 \fn void QWidget::setLayout(QLayout *layout) -
9091 -
9092 Sets the layout manager for this widget to \a layout. -
9093 -
9094 If there already is a layout manager installed on this widget, -
9095 QWidget won't let you install another. You must first delete the -
9096 existing layout manager (returned by layout()) before you can -
9097 call setLayout() with the new layout. -
9098 -
9099 If \a layout is the layout manger on a different widget, setLayout() -
9100 will reparent the layout and make it the layout manager for this widget. -
9101 -
9102 Example: -
9103 -
9104 \snippet layouts/layouts.cpp 24 -
9105 -
9106 An alternative to calling this function is to pass this widget to -
9107 the layout's constructor. -
9108 -
9109 The QWidget will take ownership of \a layout. -
9110 -
9111 \sa layout(), {Layout Management} -
9112*/ -
9113 -
9114void QWidget::setLayout(QLayout *l) -
9115{ -
9116 if (!l) { -
9117 qWarning("QWidget::setLayout: Cannot set layout to 0"); -
9118 return; -
9119 } -
9120 if (layout()) { -
9121 if (layout() != l) -
9122 qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", which already has a" -
9123 " layout", l->objectName().toLocal8Bit().data(), metaObject()->className(), -
9124 objectName().toLocal8Bit().data()); -
9125 return; -
9126 } -
9127 -
9128 QObject *oldParent = l->parent(); -
9129 if (oldParent && oldParent != this) { -
9130 if (oldParent->isWidgetType()) { -
9131 // Steal the layout off a widget parent. Takes effect when -
9132 // morphing laid-out container widgets in Designer. -
9133 QWidget *oldParentWidget = static_cast<QWidget *>(oldParent); -
9134 oldParentWidget->takeLayout(); -
9135 } else { -
9136 qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent", -
9137 l->objectName().toLocal8Bit().data(), metaObject()->className(), -
9138 objectName().toLocal8Bit().data()); -
9139 return; -
9140 } -
9141 } -
9142 -
9143 Q_D(QWidget); -
9144 l->d_func()->topLevel = true; -
9145 d->layout = l; -
9146 if (oldParent != this) { -
9147 l->setParent(this); -
9148 l->d_func()->reparentChildWidgets(this); -
9149 l->invalidate(); -
9150 } -
9151 -
9152 if (isWindow() && d->maybeTopData()) -
9153 d->topData()->sizeAdjusted = false; -
9154} -
9155 -
9156/*! -
9157 \fn QLayout *QWidget::takeLayout() -
9158 -
9159 Remove the layout from the widget. -
9160 \since 4.5 -
9161*/ -
9162 -
9163QLayout *QWidget::takeLayout() -
9164{ -
9165 Q_D(QWidget); -
9166 QLayout *l = layout(); -
9167 if (!l) -
9168 return 0; -
9169 d->layout = 0; -
9170 l->setParent(0); -
9171 return l; -
9172} -
9173 -
9174/*! -
9175 \property QWidget::sizePolicy -
9176 \brief the default layout behavior of the widget -
9177 -
9178 If there is a QLayout that manages this widget's children, the -
9179 size policy specified by that layout is used. If there is no such -
9180 QLayout, the result of this function is used. -
9181 -
9182 The default policy is Preferred/Preferred, which means that the -
9183 widget can be freely resized, but prefers to be the size -
9184 sizeHint() returns. Button-like widgets set the size policy to -
9185 specify that they may stretch horizontally, but are fixed -
9186 vertically. The same applies to lineedit controls (such as -
9187 QLineEdit, QSpinBox or an editable QComboBox) and other -
9188 horizontally orientated widgets (such as QProgressBar). -
9189 QToolButton's are normally square, so they allow growth in both -
9190 directions. Widgets that support different directions (such as -
9191 QSlider, QScrollBar or QHeader) specify stretching in the -
9192 respective direction only. Widgets that can provide scroll bars -
9193 (usually subclasses of QScrollArea) tend to specify that they can -
9194 use additional space, and that they can make do with less than -
9195 sizeHint(). -
9196 -
9197 \sa sizeHint(), QLayout, QSizePolicy, updateGeometry() -
9198*/ -
9199QSizePolicy QWidget::sizePolicy() const -
9200{ -
9201 Q_D(const QWidget); -
9202 return d->size_policy; -
9203} -
9204 -
9205void QWidget::setSizePolicy(QSizePolicy policy) -
9206{ -
9207 Q_D(QWidget); -
9208 setAttribute(Qt::WA_WState_OwnSizePolicy); -
9209 if (policy == d->size_policy) -
9210 return; -
9211 d->size_policy = policy; -
9212 -
9213#ifndef QT_NO_GRAPHICSVIEW -
9214 if (QWExtra *extra = d->extra) { -
9215 if (extra->proxyWidget) -
9216 extra->proxyWidget->setSizePolicy(policy); -
9217 } -
9218#endif -
9219 -
9220 updateGeometry(); -
9221 -
9222 if (isWindow() && d->maybeTopData()) -
9223 d->topData()->sizeAdjusted = false; -
9224} -
9225 -
9226/*! -
9227 \fn void QWidget::setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical) -
9228 \overload -
9229 -
9230 Sets the size policy of the widget to \a horizontal and \a -
9231 vertical, with standard stretch and no height-for-width. -
9232 -
9233 \sa QSizePolicy::QSizePolicy() -
9234*/ -
9235 -
9236/*! -
9237 Returns the preferred height for this widget, given the width \a w. -
9238 -
9239 If this widget has a layout, the default implementation returns -
9240 the layout's preferred height. if there is no layout, the default -
9241 implementation returns -1 indicating that the preferred height -
9242 does not depend on the width. -
9243*/ -
9244 -
9245int QWidget::heightForWidth(int w) const -
9246{ -
9247 if (layout() && layout()->hasHeightForWidth()) -
9248 return layout()->totalHeightForWidth(w); -
9249 return -1; -
9250} -
9251 -
9252 -
9253/*! -
9254 \since 5.0 -
9255 -
9256 Returns true if the widget's preferred height depends on its width; otherwise returns false. -
9257*/ -
9258bool QWidget::hasHeightForWidth() const -
9259{ -
9260 Q_D(const QWidget); -
9261 return d->layout ? d->layout->hasHeightForWidth() : d->size_policy.hasHeightForWidth(); -
9262} -
9263 -
9264/*! -
9265 \fn QWidget *QWidget::childAt(int x, int y) const -
9266 -
9267 Returns the visible child widget at the position (\a{x}, \a{y}) -
9268 in the widget's coordinate system. If there is no visible child -
9269 widget at the specified position, the function returns 0. -
9270*/ -
9271 -
9272/*! -
9273 \overload -
9274 -
9275 Returns the visible child widget at point \a p in the widget's own -
9276 coordinate system. -
9277*/ -
9278 -
9279QWidget *QWidget::childAt(const QPoint &p) const -
9280{ -
9281 return d_func()->childAt_helper(p, false); -
9282} -
9283 -
9284QWidget *QWidgetPrivate::childAt_helper(const QPoint &p, bool ignoreChildrenInDestructor) const -
9285{ -
9286 if (children.isEmpty()) -
9287 return 0; -
9288 -
9289#ifdef Q_WS_MAC -
9290 Q_Q(const QWidget); -
9291 // Unified tool bars on the Mac require special handling since they live outside -
9292 // QMainWindow's geometry(). See commit: 35667fd45ada49269a5987c235fdedfc43e92bb8 -
9293 bool includeFrame = q->isWindow() && qobject_cast<const QMainWindow *>(q) -
9294 && static_cast<const QMainWindow *>(q)->unifiedTitleAndToolBarOnMac(); -
9295 if (includeFrame) -
9296 return childAtRecursiveHelper(p, ignoreChildrenInDestructor, includeFrame); -
9297#endif -
9298 -
9299 if (!pointInsideRectAndMask(p)) -
9300 return 0; -
9301 return childAtRecursiveHelper(p, ignoreChildrenInDestructor); -
9302} -
9303 -
9304QWidget *QWidgetPrivate::childAtRecursiveHelper(const QPoint &p, bool ignoreChildrenInDestructor, bool includeFrame) const -
9305{ -
9306#ifndef Q_WS_MAC -
9307 Q_UNUSED(includeFrame); -
9308#endif -
9309 for (int i = children.size() - 1; i >= 0; --i) { -
9310 QWidget *child = qobject_cast<QWidget *>(children.at(i)); -
9311 if (!child || child->isWindow() || child->isHidden() || child->testAttribute(Qt::WA_TransparentForMouseEvents) -
9312 || (ignoreChildrenInDestructor && child->data->in_destructor)) { -
9313 continue; -
9314 } -
9315 -
9316 // Map the point 'p' from parent coordinates to child coordinates. -
9317 QPoint childPoint = p; -
9318#ifdef Q_WS_MAC -
9319 // 'includeFrame' is true if the child's parent is a top-level QMainWindow with an unified tool bar. -
9320 // An unified tool bar on the Mac lives outside QMainWindow's geometry(), so a normal -
9321 // QWidget::mapFromParent won't do the trick. -
9322 if (includeFrame && qobject_cast<QToolBar *>(child)) -
9323 childPoint = qt_mac_nativeMapFromParent(child, p); -
9324 else -
9325#endif -
9326 childPoint -= child->data->crect.topLeft(); -
9327 -
9328 // Check if the point hits the child. -
9329 if (!child->d_func()->pointInsideRectAndMask(childPoint)) -
9330 continue; -
9331 -
9332 // Do the same for the child's descendants. -
9333 if (QWidget *w = child->d_func()->childAtRecursiveHelper(childPoint, ignoreChildrenInDestructor)) -
9334 return w; -
9335 -
9336 // We have found our target; namely the child at position 'p'. -
9337 return child; -
9338 } -
9339 return 0; -
9340} -
9341 -
9342void QWidgetPrivate::updateGeometry_helper(bool forceUpdate) -
9343{ -
9344 Q_Q(QWidget); -
9345 if (widgetItem) -
9346 widgetItem->invalidateSizeCache(); -
9347 QWidget *parent; -
9348 if (forceUpdate || !extra || extra->minw != extra->maxw || extra->minh != extra->maxh) { -
9349 if (!q->isWindow() && !q->isHidden() && (parent = q->parentWidget())) { -
9350 if (parent->d_func()->layout) -
9351 parent->d_func()->layout->invalidate(); -
9352 else if (parent->isVisible()) -
9353 QApplication::postEvent(parent, new QEvent(QEvent::LayoutRequest)); -
9354 } -
9355 } -
9356} -
9357 -
9358/*! -
9359 Notifies the layout system that this widget has changed and may -
9360 need to change geometry. -
9361 -
9362 Call this function if the sizeHint() or sizePolicy() have changed. -
9363 -
9364 For explicitly hidden widgets, updateGeometry() is a no-op. The -
9365 layout system will be notified as soon as the widget is shown. -
9366*/ -
9367 -
9368void QWidget::updateGeometry() -
9369{ -
9370 Q_D(QWidget); -
9371 d->updateGeometry_helper(false); -
9372} -
9373 -
9374/*! \property QWidget::windowFlags -
9375 -
9376 Window flags are a combination of a type (e.g. Qt::Dialog) and -
9377 zero or more hints to the window system (e.g. -
9378 Qt::FramelessWindowHint). -
9379 -
9380 If the widget had type Qt::Widget or Qt::SubWindow and becomes a -
9381 window (Qt::Window, Qt::Dialog, etc.), it is put at position (0, -
9382 0) on the desktop. If the widget is a window and becomes a -
9383 Qt::Widget or Qt::SubWindow, it is put at position (0, 0) -
9384 relative to its parent widget. -
9385 -
9386 \note This function calls setParent() when changing the flags for -
9387 a window, causing the widget to be hidden. You must call show() to make -
9388 the widget visible again.. -
9389 -
9390 \sa windowType(), {Window Flags Example} -
9391*/ -
9392void QWidget::setWindowFlags(Qt::WindowFlags flags) -
9393{ -
9394 if (data->window_flags == flags) -
9395 return; -
9396 -
9397 Q_D(QWidget); -
9398 -
9399 if ((data->window_flags | flags) & Qt::Window) { -
9400 // the old type was a window and/or the new type is a window -
9401 QPoint oldPos = pos(); -
9402 bool visible = isVisible(); -
9403 setParent(parentWidget(), flags); -
9404 -
9405 // if both types are windows or neither of them are, we restore -
9406 // the old position -
9407 if (!((data->window_flags ^ flags) & Qt::Window) -
9408 && (visible || testAttribute(Qt::WA_Moved))) { -
9409 move(oldPos); -
9410 } -
9411 // for backward-compatibility we change Qt::WA_QuitOnClose attribute value only when the window was recreated. -
9412 d->adjustQuitOnCloseAttribute(); -
9413 } else { -
9414 data->window_flags = flags; -
9415 } -
9416} -
9417 -
9418/*! -
9419 Sets the window flags for the widget to \a flags, -
9420 \e without telling the window system. -
9421 -
9422 \warning Do not call this function unless you really know what -
9423 you're doing. -
9424 -
9425 \sa setWindowFlags() -
9426*/ -
9427void QWidget::overrideWindowFlags(Qt::WindowFlags flags) -
9428{ -
9429 data->window_flags = flags; -
9430} -
9431 -
9432/*! -
9433 \fn Qt::WindowType QWidget::windowType() const -
9434 -
9435 Returns the window type of this widget. This is identical to -
9436 windowFlags() & Qt::WindowType_Mask. -
9437 -
9438 \sa windowFlags -
9439*/ -
9440 -
9441/*! -
9442 Sets the parent of the widget to \a parent, and resets the window -
9443 flags. The widget is moved to position (0, 0) in its new parent. -
9444 -
9445 If the new parent widget is in a different window, the -
9446 reparented widget and its children are appended to the end of the -
9447 \l{setFocusPolicy()}{tab chain} of the new parent -
9448 widget, in the same internal order as before. If one of the moved -
9449 widgets had keyboard focus, setParent() calls clearFocus() for that -
9450 widget. -
9451 -
9452 If the new parent widget is in the same window as the -
9453 old parent, setting the parent doesn't change the tab order or -
9454 keyboard focus. -
9455 -
9456 If the "new" parent widget is the old parent widget, this function -
9457 does nothing. -
9458 -
9459 \note The widget becomes invisible as part of changing its parent, -
9460 even if it was previously visible. You must call show() to make the -
9461 widget visible again. -
9462 -
9463 \warning It is very unlikely that you will ever need this -
9464 function. If you have a widget that changes its content -
9465 dynamically, it is far easier to use \l QStackedWidget. -
9466 -
9467 \sa setWindowFlags() -
9468*/ -
9469void QWidget::setParent(QWidget *parent) -
9470{ -
9471 if (parent == parentWidget()) -
9472 return; -
9473 setParent((QWidget*)parent, windowFlags() & ~Qt::WindowType_Mask); -
9474} -
9475 -
9476/*! -
9477 \overload -
9478 -
9479 This function also takes widget flags, \a f as an argument. -
9480*/ -
9481 -
9482void QWidget::setParent(QWidget *parent, Qt::WindowFlags f) -
9483{ -
9484 Q_D(QWidget); -
9485 bool resized = testAttribute(Qt::WA_Resized); -
9486 bool wasCreated = testAttribute(Qt::WA_WState_Created); -
9487 QWidget *oldtlw = window(); -
9488 -
9489 QWidget *desktopWidget = 0; -
9490 if (parent && parent->windowType() == Qt::Desktop) -
9491 desktopWidget = parent; -
9492 bool newParent = (parent != parentWidget()) || !wasCreated || desktopWidget; -
9493 -
9494 if (newParent && parent && !desktopWidget) { -
9495 if (testAttribute(Qt::WA_NativeWindow) && !qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) -
9496#ifdef Q_WS_MAC -
9497 // On Mac, toolbars inside the unified title bar will never overlap with -
9498 // siblings in the content view. So we skip enforce native siblings in that case -
9499 && !d->isInUnifiedToolbar && parentWidget() && parentWidget()->isWindow() -
9500#endif // Q_WS_MAC -
9501 ) -
9502 parent->d_func()->enforceNativeChildren(); -
9503 else if (parent->d_func()->nativeChildrenForced() || parent->testAttribute(Qt::WA_PaintOnScreen)) -
9504 setAttribute(Qt::WA_NativeWindow); -
9505 } -
9506 -
9507 if (wasCreated) { -
9508 if (!testAttribute(Qt::WA_WState_Hidden)) { -
9509 hide(); -
9510 setAttribute(Qt::WA_WState_ExplicitShowHide, false); -
9511 } -
9512 if (newParent) { -
9513 QEvent e(QEvent::ParentAboutToChange); -
9514 QApplication::sendEvent(this, &e); -
9515 } -
9516 } -
9517 if (newParent && isAncestorOf(focusWidget())) -
9518 focusWidget()->clearFocus(); -
9519 -
9520 QTLWExtra *oldTopExtra = window()->d_func()->maybeTopData(); -
9521 QWidgetBackingStoreTracker *oldBsTracker = oldTopExtra ? &oldTopExtra->backingStoreTracker : 0; -
9522 -
9523 d->setParent_sys(parent, f); -
9524 -
9525 QTLWExtra *topExtra = window()->d_func()->maybeTopData(); -
9526 QWidgetBackingStoreTracker *bsTracker = topExtra ? &topExtra->backingStoreTracker : 0; -
9527 if (oldBsTracker && oldBsTracker != bsTracker) -
9528 oldBsTracker->unregisterWidgetSubtree(this); -
9529 -
9530 if (desktopWidget) -
9531 parent = 0; -
9532 -
9533 if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) { -
9534 if (newParent) -
9535 oldBs->removeDirtyWidget(this); -
9536 // Move the widget and all its static children from -
9537 // the old backing store to the new one. -
9538 oldBs->moveStaticWidgets(this); -
9539 } -
9540 -
9541 if (QApplicationPrivate::testAttribute(Qt::AA_ImmediateWidgetCreation) && !testAttribute(Qt::WA_WState_Created)) -
9542 create(); -
9543 -
9544 d->reparentFocusWidgets(oldtlw); -
9545 setAttribute(Qt::WA_Resized, resized); -
9546 if (!testAttribute(Qt::WA_StyleSheet) -
9547 && (!parent || !parent->testAttribute(Qt::WA_StyleSheet))) { -
9548 d->resolveFont(); -
9549 d->resolvePalette(); -
9550 } -
9551 d->resolveLayoutDirection(); -
9552 d->resolveLocale(); -
9553 -
9554 // Note: GL widgets under WGL or EGL will always need a ParentChange -
9555 // event to handle recreation/rebinding of the GL context, hence the -
9556 // (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all -
9557 // platforms). -
9558 if (newParent -
9559#if defined(Q_WS_WIN) || defined(QT_OPENGL_ES) -
9560 || (f & Qt::MSWindowsOwnDC) -
9561#endif -
9562 ) { -
9563 // propagate enabled updates enabled state to non-windows -
9564 if (!isWindow()) { -
9565 if (!testAttribute(Qt::WA_ForceDisabled)) -
9566 d->setEnabled_helper(parent ? parent->isEnabled() : true); -
9567 if (!testAttribute(Qt::WA_ForceUpdatesDisabled)) -
9568 d->setUpdatesEnabled_helper(parent ? parent->updatesEnabled() : true); -
9569 } -
9570 d->inheritStyle(); -
9571 -
9572 // send and post remaining QObject events -
9573 if (parent && d->sendChildEvents) { -
9574 QChildEvent e(QEvent::ChildAdded, this); -
9575 QApplication::sendEvent(parent, &e); -
9576 } -
9577 -
9578//### already hidden above ---> must probably do something smart on the mac -
9579// #ifdef Q_WS_MAC -
9580// extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp -
9581// if(!qt_mac_is_macdrawer(q)) //special case -
9582// q->setAttribute(Qt::WA_WState_Hidden); -
9583// #else -
9584// q->setAttribute(Qt::WA_WState_Hidden); -
9585//#endif -
9586 -
9587 if (parent && d->sendChildEvents && d->polished) { -
9588 QChildEvent e(QEvent::ChildPolished, this); -
9589 QCoreApplication::sendEvent(parent, &e); -
9590 } -
9591 -
9592 QEvent e(QEvent::ParentChange); -
9593 QApplication::sendEvent(this, &e); -
9594 } -
9595 -
9596 if (!wasCreated) { -
9597 if (isWindow() || parentWidget()->isVisible()) -
9598 setAttribute(Qt::WA_WState_Hidden, true); -
9599 else if (!testAttribute(Qt::WA_WState_ExplicitShowHide)) -
9600 setAttribute(Qt::WA_WState_Hidden, false); -
9601 } -
9602 -
9603 d->updateIsOpaque(); -
9604 -
9605#ifndef QT_NO_GRAPHICSVIEW -
9606 // Embed the widget into a proxy if the parent is embedded. -
9607 // ### Doesn't handle reparenting out of an embedded widget. -
9608 if (oldtlw->graphicsProxyWidget()) { -
9609 if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(oldtlw)) -
9610 ancestorProxy->d_func()->unembedSubWindow(this); -
9611 } -
9612 if (isWindow() && parent && !graphicsProxyWidget() && !bypassGraphicsProxyWidget(this)) { -
9613 if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(parent)) -
9614 ancestorProxy->d_func()->embedSubWindow(this); -
9615 } -
9616#endif -
9617} -
9618 -
9619/*! -
9620 Scrolls the widget including its children \a dx pixels to the -
9621 right and \a dy downward. Both \a dx and \a dy may be negative. -
9622 -
9623 After scrolling, the widgets will receive paint events for -
9624 the areas that need to be repainted. For widgets that Qt knows to -
9625 be opaque, this is only the newly exposed parts. -
9626 For example, if an opaque widget is scrolled 8 pixels to the left, -
9627 only an 8-pixel wide stripe at the right edge needs updating. -
9628 -
9629 Since widgets propagate the contents of their parents by default, -
9630 you need to set the \l autoFillBackground property, or use -
9631 setAttribute() to set the Qt::WA_OpaquePaintEvent attribute, to make -
9632 a widget opaque. -
9633 -
9634 For widgets that use contents propagation, a scroll will cause an -
9635 update of the entire scroll area. -
9636 -
9637 \sa {Transparency and Double Buffering} -
9638*/ -
9639 -
9640void QWidget::scroll(int dx, int dy) -
9641{ -
9642 if ((!updatesEnabled() && children().size() == 0) || !isVisible()) -
9643 return; -
9644 if (dx == 0 && dy == 0) -
9645 return; -
9646 Q_D(QWidget); -
9647#ifndef QT_NO_GRAPHICSVIEW -
9648 if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) { -
9649 // Graphics View maintains its own dirty region as a list of rects; -
9650 // until we can connect item updates directly to the view, we must -
9651 // separately add a translated dirty region. -
9652 if (!d->dirty.isEmpty()) { -
9653 foreach (const QRect &rect, (d->dirty.translated(dx, dy)).rects()) -
9654 proxy->update(rect); -
9655 } -
9656 proxy->scroll(dx, dy, proxy->subWidgetRect(this)); -
9657 return; -
9658 } -
9659#endif -
9660 d->setDirtyOpaqueRegion(); -
9661 d->scroll_sys(dx, dy); -
9662} -
9663 -
9664/*! -
9665 \overload -
9666 -
9667 This version only scrolls \a r and does not move the children of -
9668 the widget. -
9669 -
9670 If \a r is empty or invalid, the result is undefined. -
9671 -
9672 \sa QScrollArea -
9673*/ -
9674void QWidget::scroll(int dx, int dy, const QRect &r) -
9675{ -
9676 -
9677 if ((!updatesEnabled() && children().size() == 0) || !isVisible()) -
9678 return; -
9679 if (dx == 0 && dy == 0) -
9680 return; -
9681 Q_D(QWidget); -
9682#ifndef QT_NO_GRAPHICSVIEW -
9683 if (QGraphicsProxyWidget *proxy = QWidgetPrivate::nearestGraphicsProxyWidget(this)) { -
9684 // Graphics View maintains its own dirty region as a list of rects; -
9685 // until we can connect item updates directly to the view, we must -
9686 // separately add a translated dirty region. -
9687 if (!d->dirty.isEmpty()) { -
9688 foreach (const QRect &rect, (d->dirty.translated(dx, dy) & r).rects()) -
9689 proxy->update(rect); -
9690 } -
9691 proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint())); -
9692 return; -
9693 } -
9694#endif -
9695 d->scroll_sys(dx, dy, r); -
9696} -
9697 -
9698/*! -
9699 Repaints the widget directly by calling paintEvent() immediately, -
9700 unless updates are disabled or the widget is hidden. -
9701 -
9702 We suggest only using repaint() if you need an immediate repaint, -
9703 for example during animation. In almost all circumstances update() -
9704 is better, as it permits Qt to optimize for speed and minimize -
9705 flicker. -
9706 -
9707 \warning If you call repaint() in a function which may itself be -
9708 called from paintEvent(), you may get infinite recursion. The -
9709 update() function never causes recursion. -
9710 -
9711 \sa update(), paintEvent(), setUpdatesEnabled() -
9712*/ -
9713 -
9714void QWidget::repaint() -
9715{ -
9716 repaint(rect()); -
9717} -
9718 -
9719/*! \overload -
9720 -
9721 This version repaints a rectangle (\a x, \a y, \a w, \a h) inside -
9722 the widget. -
9723 -
9724 If \a w is negative, it is replaced with \c{width() - x}, and if -
9725 \a h is negative, it is replaced width \c{height() - y}. -
9726*/ -
9727void QWidget::repaint(int x, int y, int w, int h) -
9728{ -
9729 if (x > data->crect.width() || y > data->crect.height()) -
9730 return; -
9731 -
9732 if (w < 0) -
9733 w = data->crect.width() - x; -
9734 if (h < 0) -
9735 h = data->crect.height() - y; -
9736 -
9737 repaint(QRect(x, y, w, h)); -
9738} -
9739 -
9740/*! \overload -
9741 -
9742 This version repaints a rectangle \a rect inside the widget. -
9743*/ -
9744void QWidget::repaint(const QRect &rect) -
9745{ -
9746 Q_D(QWidget); -
9747 -
9748 if (testAttribute(Qt::WA_WState_ConfigPending)) { -
9749 update(rect); -
9750 return; -
9751 } -
9752 -
9753 if (!isVisible() || !updatesEnabled() || rect.isEmpty()) -
9754 return; -
9755 -
9756 if (hasBackingStoreSupport()) { -
9757#ifdef Q_WS_MAC -
9758 if (qt_widget_private(this)->isInUnifiedToolbar) { -
9759 qt_widget_private(this)->unifiedSurface->renderToolbar(this, true); -
9760 return; -
9761 } -
9762#endif // Q_WS_MAC -
9763 QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); -
9764 if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) { -
9765 tlwExtra->inRepaint = true; -
9766 tlwExtra->backingStoreTracker->markDirty(rect, this, true); -
9767 tlwExtra->inRepaint = false; -
9768 } -
9769 } else { -
9770 d->repaint_sys(rect); -
9771 } -
9772} -
9773 -
9774/*! -
9775 \overload -
9776 -
9777 This version repaints a region \a rgn inside the widget. -
9778*/ -
9779void QWidget::repaint(const QRegion &rgn) -
9780{ -
9781 Q_D(QWidget); -
9782 -
9783 if (testAttribute(Qt::WA_WState_ConfigPending)) { -
9784 update(rgn); -
9785 return; -
9786 } -
9787 -
9788 if (!isVisible() || !updatesEnabled() || rgn.isEmpty()) -
9789 return; -
9790 -
9791 if (hasBackingStoreSupport()) { -
9792#ifdef Q_WS_MAC -
9793 if (qt_widget_private(this)->isInUnifiedToolbar) { -
9794 qt_widget_private(this)->unifiedSurface->renderToolbar(this, true); -
9795 return; -
9796 } -
9797#endif // Q_WS_MAC -
9798 QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); -
9799 if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) { -
9800 tlwExtra->inRepaint = true; -
9801 tlwExtra->backingStoreTracker->markDirty(rgn, this, true); -
9802 tlwExtra->inRepaint = false; -
9803 } -
9804 } else { -
9805 d->repaint_sys(rgn); -
9806 } -
9807} -
9808 -
9809/*! -
9810 Updates the widget unless updates are disabled or the widget is -
9811 hidden. -
9812 -
9813 This function does not cause an immediate repaint; instead it -
9814 schedules a paint event for processing when Qt returns to the main -
9815 event loop. This permits Qt to optimize for more speed and less -
9816 flicker than a call to repaint() does. -
9817 -
9818 Calling update() several times normally results in just one -
9819 paintEvent() call. -
9820 -
9821 Qt normally erases the widget's area before the paintEvent() call. -
9822 If the Qt::WA_OpaquePaintEvent widget attribute is set, the widget is -
9823 responsible for painting all its pixels with an opaque color. -
9824 -
9825 \sa repaint(), paintEvent(), setUpdatesEnabled(), {Analog Clock Example} -
9826*/ -
9827void QWidget::update() -
9828{ -
9829 update(rect()); -
9830} -
9831 -
9832/*! \fn void QWidget::update(int x, int y, int w, int h) -
9833 \overload -
9834 -
9835 This version updates a rectangle (\a x, \a y, \a w, \a h) inside -
9836 the widget. -
9837*/ -
9838 -
9839/*! -
9840 \overload -
9841 -
9842 This version updates a rectangle \a rect inside the widget. -
9843*/ -
9844void QWidget::update(const QRect &rect) -
9845{ -
9846 if (!isVisible() || !updatesEnabled() || rect.isEmpty()) -
9847 return; -
9848 -
9849 if (testAttribute(Qt::WA_WState_InPaintEvent)) { -
9850 QApplication::postEvent(this, new QUpdateLaterEvent(rect)); -
9851 return; -
9852 } -
9853 -
9854 if (hasBackingStoreSupport()) { -
9855#ifdef Q_WS_MAC -
9856 if (qt_widget_private(this)->isInUnifiedToolbar) { -
9857 qt_widget_private(this)->unifiedSurface->renderToolbar(this, true); -
9858 return; -
9859 } -
9860#endif // Q_WS_MAC -
9861 QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); -
9862 if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) -
9863 tlwExtra->backingStoreTracker->markDirty(rect, this); -
9864 } else { -
9865 d_func()->repaint_sys(rect); -
9866 } -
9867} -
9868 -
9869/*! -
9870 \overload -
9871 -
9872 This version repaints a region \a rgn inside the widget. -
9873*/ -
9874void QWidget::update(const QRegion &rgn) -
9875{ -
9876 if (!isVisible() || !updatesEnabled() || rgn.isEmpty()) -
9877 return; -
9878 -
9879 if (testAttribute(Qt::WA_WState_InPaintEvent)) { -
9880 QApplication::postEvent(this, new QUpdateLaterEvent(rgn)); -
9881 return; -
9882 } -
9883 -
9884 if (hasBackingStoreSupport()) { -
9885#ifdef Q_WS_MAC -
9886 if (qt_widget_private(this)->isInUnifiedToolbar) { -
9887 qt_widget_private(this)->unifiedSurface->renderToolbar(this, true); -
9888 return; -
9889 } -
9890#endif // Q_WS_MAC -
9891 QTLWExtra *tlwExtra = window()->d_func()->maybeTopData(); -
9892 if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) -
9893 tlwExtra->backingStoreTracker->markDirty(rgn, this); -
9894 } else { -
9895 d_func()->repaint_sys(rgn); -
9896 } -
9897} -
9898 -
9899 -
9900 /*! -
9901 \internal -
9902 -
9903 This just sets the corresponding attribute bit to 1 or 0 -
9904 */ -
9905static void setAttribute_internal(Qt::WidgetAttribute attribute, bool on, QWidgetData *data, -
9906 QWidgetPrivate *d) -
9907{ -
9908 if (attribute < int(8*sizeof(uint))) { -
9909 if (on) -
9910 data->widget_attributes |= (1<<attribute); -
9911 else -
9912 data->widget_attributes &= ~(1<<attribute); -
9913 } else { -
9914 const int x = attribute - 8*sizeof(uint); -
9915 const int int_off = x / (8*sizeof(uint)); -
9916 if (on) -
9917 d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint)))); -
9918 else -
9919 d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint)))); -
9920 } -
9921} -
9922 -
9923#ifdef Q_OS_MAC -
9924void QWidgetPrivate::macUpdateSizeAttribute() -
9925{ -
9926 Q_Q(QWidget); -
9927 QEvent event(QEvent::MacSizeChange); -
9928 QApplication::sendEvent(q, &event); -
9929 for (int i = 0; i < children.size(); ++i) { -
9930 QWidget *w = qobject_cast<QWidget *>(children.at(i)); -
9931 if (w && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation)) -
9932 && !q->testAttribute(Qt::WA_MacMiniSize) // no attribute set? inherit from parent -
9933 && !w->testAttribute(Qt::WA_MacSmallSize) -
9934 && !w->testAttribute(Qt::WA_MacNormalSize)) -
9935 w->d_func()->macUpdateSizeAttribute(); -
9936 } -
9937 resolveFont(); -
9938} -
9939#endif -
9940 -
9941/*! -
9942 Sets the attribute \a attribute on this widget if \a on is true; -
9943 otherwise clears the attribute. -
9944 -
9945 \sa testAttribute() -
9946*/ -
9947void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on) -
9948{ -
9949 if (testAttribute(attribute) == on) -
9950 return; -
9951 -
9952 Q_D(QWidget); -
9953 Q_ASSERT_X(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8), -
9954 "QWidget::setAttribute(WidgetAttribute, bool)", -
9955 "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute"); -
9956#ifdef Q_OS_WIN -
9957 // ### Don't use PaintOnScreen+paintEngine() to do native painting in some future release -
9958 if (attribute == Qt::WA_PaintOnScreen && on && windowType() != Qt::Desktop && !inherits("QGLWidget")) { -
9959 // see qwidget_qpa.cpp, ::paintEngine for details -
9960 paintEngine(); -
9961 if (d->noPaintOnScreen) -
9962 return; -
9963 } -
9964#endif -
9965 -
9966 setAttribute_internal(attribute, on, data, d); -
9967 -
9968 switch (attribute) { -
9969 -
9970#ifndef QT_NO_DRAGANDDROP -
9971 case Qt::WA_AcceptDrops: { -
9972 if (on && !testAttribute(Qt::WA_DropSiteRegistered)) -
9973 setAttribute(Qt::WA_DropSiteRegistered, true); -
9974 else if (!on && (isWindow() || !parentWidget() || !parentWidget()->testAttribute(Qt::WA_DropSiteRegistered))) -
9975 setAttribute(Qt::WA_DropSiteRegistered, false); -
9976 QEvent e(QEvent::AcceptDropsChange); -
9977 QApplication::sendEvent(this, &e); -
9978 break; -
9979 } -
9980 case Qt::WA_DropSiteRegistered: { -
9981 d->registerDropSite(on); -
9982 for (int i = 0; i < d->children.size(); ++i) { -
9983 QWidget *w = qobject_cast<QWidget *>(d->children.at(i)); -
9984 if (w && !w->isWindow() && !w->testAttribute(Qt::WA_AcceptDrops) && w->testAttribute(Qt::WA_DropSiteRegistered) != on) -
9985 w->setAttribute(Qt::WA_DropSiteRegistered, on); -
9986 } -
9987 break; -
9988 } -
9989#endif -
9990 -
9991 case Qt::WA_NoChildEventsForParent: -
9992 d->sendChildEvents = !on; -
9993 break; -
9994 case Qt::WA_NoChildEventsFromChildren: -
9995 d->receiveChildEvents = !on; -
9996 break; -
9997 case Qt::WA_MacBrushedMetal: -
9998#ifdef Q_WS_MAC -
9999 d->setStyle_helper(style(), false, true); // Make sure things get unpolished/polished correctly. -
10000 // fall through since changing the metal attribute affects the opaque size grip. -
10001 case Qt::WA_MacOpaqueSizeGrip: -
10002 d->macUpdateOpaqueSizeGrip(); -
10003 break; -
10004 case Qt::WA_MacShowFocusRect: -
10005 if (hasFocus()) { -
10006 clearFocus(); -
10007 setFocus(); -
10008 } -
10009 break; -
10010 case Qt::WA_Hover: -
10011 qt_mac_update_mouseTracking(this); -
10012 break; -
10013#endif -
10014 case Qt::WA_MacAlwaysShowToolWindow: -
10015#ifdef Q_WS_MAC -
10016 d->macUpdateHideOnSuspend(); -
10017#endif -
10018 break; -
10019 case Qt::WA_MacNormalSize: -
10020 case Qt::WA_MacSmallSize: -
10021 case Qt::WA_MacMiniSize: -
10022#ifdef Q_OS_MAC -
10023 { -
10024 // We can only have one of these set at a time -
10025 const Qt::WidgetAttribute MacSizes[] = { Qt::WA_MacNormalSize, Qt::WA_MacSmallSize, -
10026 Qt::WA_MacMiniSize }; -
10027 for (int i = 0; i < 3; ++i) { -
10028 if (MacSizes[i] != attribute) -
10029 setAttribute_internal(MacSizes[i], false, data, d); -
10030 } -
10031 d->macUpdateSizeAttribute(); -
10032 } -
10033#endif -
10034 break; -
10035 case Qt::WA_ShowModal: -
10036 if (!on) { -
10037 // reset modality type to NonModal when clearing WA_ShowModal -
10038 data->window_modality = Qt::NonModal; -
10039 } else if (data->window_modality == Qt::NonModal) { -
10040 // determine the modality type if it hasn't been set prior -
10041 // to setting WA_ShowModal. set the default to WindowModal -
10042 // if we are the child of a group leader; otherwise use -
10043 // ApplicationModal. -
10044 QWidget *w = parentWidget(); -
10045 if (w) -
10046 w = w->window(); -
10047 while (w && !w->testAttribute(Qt::WA_GroupLeader)) { -
10048 w = w->parentWidget(); -
10049 if (w) -
10050 w = w->window(); -
10051 } -
10052 data->window_modality = (w && w->testAttribute(Qt::WA_GroupLeader)) -
10053 ? Qt::WindowModal -
10054 : Qt::ApplicationModal; -
10055 // Some window managers do not allow us to enter modality after the -
10056 // window is visible.The window must be hidden before changing the -
10057 // windowModality property and then reshown. -
10058 } -
10059 if (testAttribute(Qt::WA_WState_Created)) { -
10060 // don't call setModal_sys() before create_sys() -
10061 d->setModal_sys(); -
10062 } -
10063 break; -
10064 case Qt::WA_MouseTracking: { -
10065 QEvent e(QEvent::MouseTrackingChange); -
10066 QApplication::sendEvent(this, &e); -
10067 break; } -
10068 case Qt::WA_NativeWindow: { -
10069 d->createTLExtra(); -
10070#ifndef QT_NO_IM -
10071 QWidget *focusWidget = d->effectiveFocusWidget(); -
10072 if (on && !internalWinId() && hasFocus() -
10073 && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) { -
10074 qApp->inputMethod()->commit(); -
10075 qApp->inputMethod()->update(Qt::ImEnabled); -
10076 } -
10077 if (!qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) && parentWidget() -
10078#ifdef Q_WS_MAC -
10079 // On Mac, toolbars inside the unified title bar will never overlap with -
10080 // siblings in the content view. So we skip enforce native siblings in that case -
10081 && !d->isInUnifiedToolbar && parentWidget()->isWindow() -
10082#endif // Q_WS_MAC -
10083 ) -
10084 parentWidget()->d_func()->enforceNativeChildren(); -
10085 if (on && !internalWinId() && testAttribute(Qt::WA_WState_Created)) -
10086 d->createWinId(); -
10087 if (isEnabled() && focusWidget->isEnabled() -
10088 && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) { -
10089 qApp->inputMethod()->update(Qt::ImEnabled); -
10090 } -
10091#endif //QT_NO_IM -
10092 break; -
10093 } -
10094 case Qt::WA_PaintOnScreen: -
10095 d->updateIsOpaque(); -
10096#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_MAC) -
10097 // Recreate the widget if it's already created as an alien widget and -
10098 // WA_PaintOnScreen is enabled. Paint on screen widgets must have win id. -
10099 // So must their children. -
10100 if (on) { -
10101 setAttribute(Qt::WA_NativeWindow); -
10102 d->enforceNativeChildren(); -
10103 } -
10104#endif -
10105 // fall through -
10106 case Qt::WA_OpaquePaintEvent: -
10107 d->updateIsOpaque(); -
10108 break; -
10109 case Qt::WA_NoSystemBackground: -
10110 d->updateIsOpaque(); -
10111 // fall through... -
10112 case Qt::WA_UpdatesDisabled: -
10113 d->updateSystemBackground(); -
10114 break; -
10115 case Qt::WA_TransparentForMouseEvents: -
10116#ifdef Q_WS_MAC -
10117 d->macUpdateIgnoreMouseEvents(); -
10118#endif -
10119 break; -
10120 case Qt::WA_InputMethodEnabled: { -
10121#ifndef QT_NO_IM -
10122 if (qApp->focusObject() == this) { -
10123 if (!on) -
10124 qApp->inputMethod()->commit(); -
10125 qApp->inputMethod()->update(Qt::ImEnabled); -
10126 } -
10127#endif //QT_NO_IM -
10128 break; -
10129 } -
10130 case Qt::WA_WindowPropagation: -
10131 d->resolvePalette(); -
10132 d->resolveFont(); -
10133 d->resolveLocale(); -
10134 break; -
10135#ifdef Q_WS_X11 -
10136 case Qt::WA_NoX11EventCompression: -
10137 if (!d->extra) -
10138 d->createExtra(); -
10139 d->extra->compress_events = on; -
10140 break; -
10141 case Qt::WA_X11OpenGLOverlay: -
10142 d->updateIsOpaque(); -
10143 break; -
10144 case Qt::WA_X11DoNotAcceptFocus: -
10145 if (testAttribute(Qt::WA_WState_Created)) -
10146 d->updateX11AcceptFocus(); -
10147 break; -
10148#endif -
10149 case Qt::WA_DontShowOnScreen: { -
10150 if (on && isVisible()) { -
10151 // Make sure we keep the current state and only hide the widget -
10152 // from the desktop. show_sys will only update platform specific -
10153 // attributes at this point. -
10154 d->hide_sys(); -
10155 d->show_sys(); -
10156 } -
10157 break; -
10158 } -
10159 -
10160#ifdef Q_WS_X11 -
10161 case Qt::WA_X11NetWmWindowTypeDesktop: -
10162 case Qt::WA_X11NetWmWindowTypeDock: -
10163 case Qt::WA_X11NetWmWindowTypeToolBar: -
10164 case Qt::WA_X11NetWmWindowTypeMenu: -
10165 case Qt::WA_X11NetWmWindowTypeUtility: -
10166 case Qt::WA_X11NetWmWindowTypeSplash: -
10167 case Qt::WA_X11NetWmWindowTypeDialog: -
10168 case Qt::WA_X11NetWmWindowTypeDropDownMenu: -
10169 case Qt::WA_X11NetWmWindowTypePopupMenu: -
10170 case Qt::WA_X11NetWmWindowTypeToolTip: -
10171 case Qt::WA_X11NetWmWindowTypeNotification: -
10172 case Qt::WA_X11NetWmWindowTypeCombo: -
10173 case Qt::WA_X11NetWmWindowTypeDND: -
10174 if (testAttribute(Qt::WA_WState_Created)) -
10175 d->setNetWmWindowTypes(); -
10176 break; -
10177#endif -
10178 -
10179 case Qt::WA_StaticContents: -
10180 if (QWidgetBackingStore *bs = d->maybeBackingStore()) { -
10181 if (on) -
10182 bs->addStaticWidget(this); -
10183 else -
10184 bs->removeStaticWidget(this); -
10185 } -
10186 break; -
10187 case Qt::WA_TranslucentBackground: -
10188 if (on) { -
10189 setAttribute(Qt::WA_NoSystemBackground); -
10190 d->updateIsTranslucent(); -
10191 } -
10192 -
10193 break; -
10194 case Qt::WA_AcceptTouchEvents: -
10195#if defined(Q_WS_WIN) || defined(Q_WS_MAC) -
10196 if (on) -
10197 d->registerTouchWindow(); -
10198#endif -
10199 break; -
10200 default: -
10201 break; -
10202 } -
10203} -
10204 -
10205/*! \fn bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const -
10206 -
10207 Returns true if attribute \a attribute is set on this widget; -
10208 otherwise returns false. -
10209 -
10210 \sa setAttribute() -
10211 */ -
10212bool QWidget::testAttribute_helper(Qt::WidgetAttribute attribute) const -
10213{ -
10214 Q_D(const QWidget); -
10215 const int x = attribute - 8*sizeof(uint); -
10216 const int int_off = x / (8*sizeof(uint)); -
10217 return (d->high_attributes[int_off] & (1<<(x-(int_off*8*sizeof(uint))))); -
10218} -
10219 -
10220/*! -
10221 \property QWidget::windowOpacity -
10222 -
10223 \brief The level of opacity for the window. -
10224 -
10225 The valid range of opacity is from 1.0 (completely opaque) to -
10226 0.0 (completely transparent). -
10227 -
10228 By default the value of this property is 1.0. -
10229 -
10230 This feature is available on Embedded Linux, Mac OS X, Windows, -
10231 and X11 platforms that support the Composite extension. -
10232 -
10233 This feature is not available on Windows CE. -
10234 -
10235 Note that under X11 you need to have a composite manager running, -
10236 and the X11 specific _NET_WM_WINDOW_OPACITY atom needs to be -
10237 supported by the window manager you are using. -
10238 -
10239 \warning Changing this property from opaque to transparent might issue a -
10240 paint event that needs to be processed before the window is displayed -
10241 correctly. This affects mainly the use of QPixmap::grabWindow(). Also note -
10242 that semi-transparent windows update and resize significantly slower than -
10243 opaque windows. -
10244 -
10245 \sa setMask() -
10246*/ -
10247qreal QWidget::windowOpacity() const -
10248{ -
10249 Q_D(const QWidget); -
10250 return (isWindow() && d->maybeTopData()) ? d->maybeTopData()->opacity / 255. : 1.0; -
10251} -
10252 -
10253void QWidget::setWindowOpacity(qreal opacity) -
10254{ -
10255 Q_D(QWidget); -
10256 if (!isWindow()) -
10257 return; -
10258 -
10259 opacity = qBound(qreal(0.0), opacity, qreal(1.0)); -
10260 QTLWExtra *extra = d->topData(); -
10261 extra->opacity = uint(opacity * 255); -
10262 setAttribute(Qt::WA_WState_WindowOpacitySet); -
10263 d->setWindowOpacity_sys(opacity); -
10264 -
10265 if (!testAttribute(Qt::WA_WState_Created)) -
10266 return; -
10267 -
10268#ifndef QT_NO_GRAPHICSVIEW -
10269 if (QGraphicsProxyWidget *proxy = graphicsProxyWidget()) { -
10270 // Avoid invalidating the cache if set. -
10271 if (proxy->cacheMode() == QGraphicsItem::NoCache) -
10272 proxy->update(); -
10273 else if (QGraphicsScene *scene = proxy->scene()) -
10274 scene->update(proxy->sceneBoundingRect()); -
10275 return; -
10276 } -
10277#endif -
10278} -
10279 -
10280/*! -
10281 \property QWidget::windowModified -
10282 \brief whether the document shown in the window has unsaved changes -
10283 -
10284 A modified window is a window whose content has changed but has -
10285 not been saved to disk. This flag will have different effects -
10286 varied by the platform. On Mac OS X the close button will have a -
10287 modified look; on other platforms, the window title will have an -
10288 '*' (asterisk). -
10289 -
10290 The window title must contain a "[*]" placeholder, which -
10291 indicates where the '*' should appear. Normally, it should appear -
10292 right after the file name (e.g., "document1.txt[*] - Text -
10293 Editor"). If the window isn't modified, the placeholder is simply -
10294 removed. -
10295 -
10296 Note that if a widget is set as modified, all its ancestors will -
10297 also be set as modified. However, if you call \c -
10298 {setWindowModified(false)} on a widget, this will not propagate to -
10299 its parent because other children of the parent might have been -
10300 modified. -
10301 -
10302 \sa windowTitle, {Application Example}, {SDI Example}, {MDI Example} -
10303*/ -
10304bool QWidget::isWindowModified() const -
10305{ -
10306 return testAttribute(Qt::WA_WindowModified); -
10307} -
10308 -
10309void QWidget::setWindowModified(bool mod) -
10310{ -
10311 Q_D(QWidget); -
10312 setAttribute(Qt::WA_WindowModified, mod); -
10313 -
10314 d->setWindowModified_helper(); -
10315 -
10316 QEvent e(QEvent::ModifiedChange); -
10317 QApplication::sendEvent(this, &e); -
10318} -
10319 -
10320void QWidgetPrivate::setWindowModified_helper() -
10321{ -
10322 Q_Q(QWidget); -
10323 QWindow *window = q->windowHandle(); -
10324 if (!window) -
10325 return; -
10326 QPlatformWindow *platformWindow = window->handle(); -
10327 if (!platformWindow) -
10328 return; -
10329 bool on = q->testAttribute(Qt::WA_WindowModified); -
10330 if (!platformWindow->setWindowModified(on)) { -
10331 if (!q->windowTitle().contains(QLatin1String("[*]")) && on) -
10332 qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder"); -
10333 setWindowTitle_helper(q->windowTitle()); -
10334 setWindowIconText_helper(q->windowIconText()); -
10335 } -
10336} -
10337 -
10338#ifndef QT_NO_TOOLTIP -
10339/*! -
10340 \property QWidget::toolTip -
10341 -
10342 \brief the widget's tooltip -
10343 -
10344 Note that by default tooltips are only shown for widgets that are -
10345 children of the active window. You can change this behavior by -
10346 setting the attribute Qt::WA_AlwaysShowToolTips on the \e window, -
10347 not on the widget with the tooltip. -
10348 -
10349 If you want to control a tooltip's behavior, you can intercept the -
10350 event() function and catch the QEvent::ToolTip event (e.g., if you -
10351 want to customize the area for which the tooltip should be shown). -
10352 -
10353 By default, this property contains an empty string. -
10354 -
10355 \sa QToolTip, statusTip, whatsThis -
10356*/ -
10357void QWidget::setToolTip(const QString &s) -
10358{ -
10359 Q_D(QWidget); -
10360 d->toolTip = s; -
10361 -
10362 QEvent event(QEvent::ToolTipChange); -
10363 QApplication::sendEvent(this, &event); -
10364} -
10365 -
10366QString QWidget::toolTip() const -
10367{ -
10368 Q_D(const QWidget); -
10369 return d->toolTip; -
10370} -
10371#endif // QT_NO_TOOLTIP -
10372 -
10373 -
10374#ifndef QT_NO_STATUSTIP -
10375/*! -
10376 \property QWidget::statusTip -
10377 \brief the widget's status tip -
10378 -
10379 By default, this property contains an empty string. -
10380 -
10381 \sa toolTip, whatsThis -
10382*/ -
10383void QWidget::setStatusTip(const QString &s) -
10384{ -
10385 Q_D(QWidget); -
10386 d->statusTip = s; -
10387} -
10388 -
10389QString QWidget::statusTip() const -
10390{ -
10391 Q_D(const QWidget); -
10392 return d->statusTip; -
10393} -
10394#endif // QT_NO_STATUSTIP -
10395 -
10396#ifndef QT_NO_WHATSTHIS -
10397/*! -
10398 \property QWidget::whatsThis -
10399 -
10400 \brief the widget's What's This help text. -
10401 -
10402 By default, this property contains an empty string. -
10403 -
10404 \sa QWhatsThis, QWidget::toolTip, QWidget::statusTip -
10405*/ -
10406void QWidget::setWhatsThis(const QString &s) -
10407{ -
10408 Q_D(QWidget); -
10409 d->whatsThis = s; -
10410} -
10411 -
10412QString QWidget::whatsThis() const -
10413{ -
10414 Q_D(const QWidget); -
10415 return d->whatsThis; -
10416} -
10417#endif // QT_NO_WHATSTHIS -
10418 -
10419#ifndef QT_NO_ACCESSIBILITY -
10420/*! -
10421 \property QWidget::accessibleName -
10422 -
10423 \brief the widget's name as seen by assistive technologies -
10424 -
10425 This property is used by accessible clients to identify, find, or announce -
10426 the widget for accessible clients. -
10427 -
10428 By default, this property contains an empty string. -
10429 -
10430 \sa QAccessibleInterface::text() -
10431*/ -
10432void QWidget::setAccessibleName(const QString &name) -
10433{ -
10434 Q_D(QWidget); -
10435 d->accessibleName = name; -
10436 QAccessibleEvent event(this, QAccessible::NameChanged); -
10437 QAccessible::updateAccessibility(&event); -
10438} -
10439 -
10440QString QWidget::accessibleName() const -
10441{ -
10442 Q_D(const QWidget); -
10443 return d->accessibleName; -
10444} -
10445 -
10446/*! -
10447 \property QWidget::accessibleDescription -
10448 -
10449 \brief the widget's description as seen by assistive technologies -
10450 -
10451 By default, this property contains an empty string. -
10452 -
10453 \sa QAccessibleInterface::text() -
10454*/ -
10455void QWidget::setAccessibleDescription(const QString &description) -
10456{ -
10457 Q_D(QWidget); -
10458 d->accessibleDescription = description; -
10459 QAccessibleEvent event(this, QAccessible::DescriptionChanged); -
10460 QAccessible::updateAccessibility(&event); -
10461} -
10462 -
10463QString QWidget::accessibleDescription() const -
10464{ -
10465 Q_D(const QWidget); -
10466 return d->accessibleDescription; -
10467} -
10468#endif // QT_NO_ACCESSIBILITY -
10469 -
10470#ifndef QT_NO_SHORTCUT -
10471/*! -
10472 Adds a shortcut to Qt's shortcut system that watches for the given -
10473 \a key sequence in the given \a context. If the \a context is -
10474 Qt::ApplicationShortcut, the shortcut applies to the application as a -
10475 whole. Otherwise, it is either local to this widget, Qt::WidgetShortcut, -
10476 or to the window itself, Qt::WindowShortcut. -
10477 -
10478 If the same \a key sequence has been grabbed by several widgets, -
10479 when the \a key sequence occurs a QEvent::Shortcut event is sent -
10480 to all the widgets to which it applies in a non-deterministic -
10481 order, but with the ``ambiguous'' flag set to true. -
10482 -
10483 \warning You should not normally need to use this function; -
10484 instead create \l{QAction}s with the shortcut key sequences you -
10485 require (if you also want equivalent menu options and toolbar -
10486 buttons), or create \l{QShortcut}s if you just need key sequences. -
10487 Both QAction and QShortcut handle all the event filtering for you, -
10488 and provide signals which are triggered when the user triggers the -
10489 key sequence, so are much easier to use than this low-level -
10490 function. -
10491 -
10492 \sa releaseShortcut(), setShortcutEnabled() -
10493*/ -
10494int QWidget::grabShortcut(const QKeySequence &key, Qt::ShortcutContext context) -
10495{ -
10496 Q_ASSERT(qApp); -
10497 if (key.isEmpty()) -
10498 return 0; -
10499 setAttribute(Qt::WA_GrabbedShortcut); -
10500 return qApp->d_func()->shortcutMap.addShortcut(this, key, context, qWidgetShortcutContextMatcher); -
10501} -
10502 -
10503/*! -
10504 Removes the shortcut with the given \a id from Qt's shortcut -
10505 system. The widget will no longer receive QEvent::Shortcut events -
10506 for the shortcut's key sequence (unless it has other shortcuts -
10507 with the same key sequence). -
10508 -
10509 \warning You should not normally need to use this function since -
10510 Qt's shortcut system removes shortcuts automatically when their -
10511 parent widget is destroyed. It is best to use QAction or -
10512 QShortcut to handle shortcuts, since they are easier to use than -
10513 this low-level function. Note also that this is an expensive -
10514 operation. -
10515 -
10516 \sa grabShortcut(), setShortcutEnabled() -
10517*/ -
10518void QWidget::releaseShortcut(int id) -
10519{ -
10520 Q_ASSERT(qApp); -
10521 if (id) -
10522 qApp->d_func()->shortcutMap.removeShortcut(id, this, 0); -
10523} -
10524 -
10525/*! -
10526 If \a enable is true, the shortcut with the given \a id is -
10527 enabled; otherwise the shortcut is disabled. -
10528 -
10529 \warning You should not normally need to use this function since -
10530 Qt's shortcut system enables/disables shortcuts automatically as -
10531 widgets become hidden/visible and gain or lose focus. It is best -
10532 to use QAction or QShortcut to handle shortcuts, since they are -
10533 easier to use than this low-level function. -
10534 -
10535 \sa grabShortcut(), releaseShortcut() -
10536*/ -
10537void QWidget::setShortcutEnabled(int id, bool enable) -
10538{ -
10539 Q_ASSERT(qApp); -
10540 if (id) -
10541 qApp->d_func()->shortcutMap.setShortcutEnabled(enable, id, this, 0); -
10542} -
10543 -
10544/*! -
10545 \since 4.2 -
10546 -
10547 If \a enable is true, auto repeat of the shortcut with the -
10548 given \a id is enabled; otherwise it is disabled. -
10549 -
10550 \sa grabShortcut(), releaseShortcut() -
10551*/ -
10552void QWidget::setShortcutAutoRepeat(int id, bool enable) -
10553{ -
10554 Q_ASSERT(qApp); -
10555 if (id) -
10556 qApp->d_func()->shortcutMap.setShortcutAutoRepeat(enable, id, this, 0); -
10557} -
10558#endif // QT_NO_SHORTCUT -
10559 -
10560/*! -
10561 Updates the widget's micro focus. -
10562*/ -
10563void QWidget::updateMicroFocus() -
10564{ -
10565 // updating everything since this is currently called for any kind of state change -
10566 qApp->inputMethod()->update(Qt::ImQueryAll); -
10567} -
10568 -
10569/*! -
10570 Raises this widget to the top of the parent widget's stack. -
10571 -
10572 After this call the widget will be visually in front of any -
10573 overlapping sibling widgets. -
10574 -
10575 \note When using activateWindow(), you can call this function to -
10576 ensure that the window is stacked on top. -
10577 -
10578 \sa lower(), stackUnder() -
10579*/ -
10580 -
10581void QWidget::raise() -
10582{ -
10583 Q_D(QWidget); -
10584 if (!isWindow()) { -
10585 QWidget *p = parentWidget(); -
10586 const int parentChildCount = p->d_func()->children.size(); -
10587 if (parentChildCount < 2) -
10588 return; -
10589 const int from = p->d_func()->children.indexOf(this); -
10590 Q_ASSERT(from >= 0); -
10591 // Do nothing if the widget is already in correct stacking order _and_ created. -
10592 if (from != parentChildCount -1) -
10593 p->d_func()->children.move(from, parentChildCount - 1); -
10594 if (!testAttribute(Qt::WA_WState_Created) && p->testAttribute(Qt::WA_WState_Created)) -
10595 create(); -
10596 else if (from == parentChildCount - 1) -
10597 return; -
10598 -
10599 QRegion region(rect()); -
10600 d->subtractOpaqueSiblings(region); -
10601 d->invalidateBuffer(region); -
10602 } -
10603 if (testAttribute(Qt::WA_WState_Created)) -
10604 d->raise_sys(); -
10605 -
10606 QEvent e(QEvent::ZOrderChange); -
10607 QApplication::sendEvent(this, &e); -
10608} -
10609 -
10610/*! -
10611 Lowers the widget to the bottom of the parent widget's stack. -
10612 -
10613 After this call the widget will be visually behind (and therefore -
10614 obscured by) any overlapping sibling widgets. -
10615 -
10616 \sa raise(), stackUnder() -
10617*/ -
10618 -
10619void QWidget::lower() -
10620{ -
10621 Q_D(QWidget); -
10622 if (!isWindow()) { -
10623 QWidget *p = parentWidget(); -
10624 const int parentChildCount = p->d_func()->children.size(); -
10625 if (parentChildCount < 2) -
10626 return; -
10627 const int from = p->d_func()->children.indexOf(this); -
10628 Q_ASSERT(from >= 0); -
10629 // Do nothing if the widget is already in correct stacking order _and_ created. -
10630 if (from != 0) -
10631 p->d_func()->children.move(from, 0); -
10632 if (!testAttribute(Qt::WA_WState_Created) && p->testAttribute(Qt::WA_WState_Created)) -
10633 create(); -
10634 else if (from == 0) -
10635 return; -
10636 } -
10637 if (testAttribute(Qt::WA_WState_Created)) -
10638 d->lower_sys(); -
10639 -
10640 QEvent e(QEvent::ZOrderChange); -
10641 QApplication::sendEvent(this, &e); -
10642} -
10643 -
10644 -
10645/*! -
10646 Places the widget under \a w in the parent widget's stack. -
10647 -
10648 To make this work, the widget itself and \a w must be siblings. -
10649 -
10650 \sa raise(), lower() -
10651*/ -
10652void QWidget::stackUnder(QWidget* w) -
10653{ -
10654 Q_D(QWidget); -
10655 QWidget *p = parentWidget(); -
10656 if (!w || isWindow() || p != w->parentWidget() || this == w) -
10657 return; -
10658 if (p) { -
10659 int from = p->d_func()->children.indexOf(this); -
10660 int to = p->d_func()->children.indexOf(w); -
10661 Q_ASSERT(from >= 0); -
10662 Q_ASSERT(to >= 0); -
10663 if (from < to) -
10664 --to; -
10665 // Do nothing if the widget is already in correct stacking order _and_ created. -
10666 if (from != to) -
10667 p->d_func()->children.move(from, to); -
10668 if (!testAttribute(Qt::WA_WState_Created) && p->testAttribute(Qt::WA_WState_Created)) -
10669 create(); -
10670 else if (from == to) -
10671 return; -
10672 } -
10673 if (testAttribute(Qt::WA_WState_Created)) -
10674 d->stackUnder_sys(w); -
10675 -
10676 QEvent e(QEvent::ZOrderChange); -
10677 QApplication::sendEvent(this, &e); -
10678} -
10679 -
10680 -
10681/*! -
10682 \fn bool QWidget::isTopLevel() const -
10683 \obsolete -
10684 -
10685 Use isWindow() instead. -
10686*/ -
10687 -
10688/*! -
10689 \fn bool QWidget::isRightToLeft() const -
10690 \internal -
10691*/ -
10692 -
10693/*! -
10694 \fn bool QWidget::isLeftToRight() const -
10695 \internal -
10696*/ -
10697 -
10698/*! -
10699 \macro QWIDGETSIZE_MAX -
10700 \relates QWidget -
10701 -
10702 Defines the maximum size for a QWidget object. -
10703 -
10704 The largest allowed size for a widget is QSize(QWIDGETSIZE_MAX, -
10705 QWIDGETSIZE_MAX), i.e. QSize (16777215,16777215). -
10706 -
10707 \sa QWidget::setMaximumSize() -
10708*/ -
10709 -
10710/*! -
10711 \fn QWidget::setupUi(QWidget *widget) -
10712 -
10713 Sets up the user interface for the specified \a widget. -
10714 -
10715 \note This function is available with widgets that derive from user -
10716 interface descriptions created using \l{uic}. -
10717 -
10718 \sa {Using a Designer UI File in Your Application} -
10719*/ -
10720 -
10721QRect QWidgetPrivate::frameStrut() const -
10722{ -
10723 Q_Q(const QWidget); -
10724 if (!q->isWindow() || (q->windowType() == Qt::Desktop) || q->testAttribute(Qt::WA_DontShowOnScreen)) { -
10725 // x2 = x1 + w - 1, so w/h = 1 -
10726 return QRect(0, 0, 1, 1); -
10727 } -
10728 -
10729 if (data.fstrut_dirty -
10730#ifndef Q_WS_WIN -
10731 // ### Fix properly for 4.3 -
10732 && q->isVisible() -
10733#endif -
10734 && q->testAttribute(Qt::WA_WState_Created)) -
10735 const_cast<QWidgetPrivate *>(this)->updateFrameStrut(); -
10736 -
10737 return maybeTopData() ? maybeTopData()->frameStrut : QRect(); -
10738} -
10739 -
10740#ifdef QT_KEYPAD_NAVIGATION -
10741/*! -
10742 \internal -
10743 -
10744 Changes the focus from the current focusWidget to a widget in -
10745 the \a direction. -
10746 -
10747 Returns true, if there was a widget in that direction -
10748*/ -
10749bool QWidgetPrivate::navigateToDirection(Direction direction) -
10750{ -
10751 QWidget *targetWidget = widgetInNavigationDirection(direction); -
10752 if (targetWidget) -
10753 targetWidget->setFocus(); -
10754 return (targetWidget != 0); -
10755} -
10756 -
10757/*! -
10758 \internal -
10759 -
10760 Searches for a widget that is positioned in the \a direction, starting -
10761 from the current focusWidget. -
10762 -
10763 Returns the pointer to a found widget or 0, if there was no widget in -
10764 that direction. -
10765*/ -
10766QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction) -
10767{ -
10768 const QWidget *sourceWidget = QApplication::focusWidget(); -
10769 if (!sourceWidget) -
10770 return 0; -
10771 const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint())); -
10772 const int sourceX = -
10773 (direction == DirectionNorth || direction == DirectionSouth) ? -
10774 (sourceRect.left() + (sourceRect.right() - sourceRect.left()) / 2) -
10775 :(direction == DirectionEast ? sourceRect.right() : sourceRect.left()); -
10776 const int sourceY = -
10777 (direction == DirectionEast || direction == DirectionWest) ? -
10778 (sourceRect.top() + (sourceRect.bottom() - sourceRect.top()) / 2) -
10779 :(direction == DirectionSouth ? sourceRect.bottom() : sourceRect.top()); -
10780 const QPoint sourcePoint(sourceX, sourceY); -
10781 const QPoint sourceCenter = sourceRect.center(); -
10782 const QWidget *sourceWindow = sourceWidget->window(); -
10783 -
10784 QWidget *targetWidget = 0; -
10785 int shortestDistance = INT_MAX; -
10786 foreach(QWidget *targetCandidate, QApplication::allWidgets()) { -
10787 -
10788 const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint())); -
10789 -
10790 // For focus proxies, the child widget handling the focus can have keypad navigation focus, -
10791 // but the owner of the proxy cannot. -
10792 // Additionally, empty widgets should be ignored. -
10793 if (targetCandidate->focusProxy() || targetCandidateRect.isEmpty()) -
10794 continue; -
10795 -
10796 // Only navigate to a target widget that... -
10797 if ( targetCandidate != sourceWidget -
10798 // ...takes the focus, -
10799 && targetCandidate->focusPolicy() & Qt::TabFocus -
10800 // ...is above if DirectionNorth, -
10801 && !(direction == DirectionNorth && targetCandidateRect.bottom() > sourceRect.top()) -
10802 // ...is on the right if DirectionEast, -
10803 && !(direction == DirectionEast && targetCandidateRect.left() < sourceRect.right()) -
10804 // ...is below if DirectionSouth, -
10805 && !(direction == DirectionSouth && targetCandidateRect.top() < sourceRect.bottom()) -
10806 // ...is on the left if DirectionWest, -
10807 && !(direction == DirectionWest && targetCandidateRect.right() > sourceRect.left()) -
10808 // ...is enabled, -
10809 && targetCandidate->isEnabled() -
10810 // ...is visible, -
10811 && targetCandidate->isVisible() -
10812 // ...is in the same window, -
10813 && targetCandidate->window() == sourceWindow) { -
10814 const int targetCandidateDistance = pointToRect(sourcePoint, targetCandidateRect); -
10815 if (targetCandidateDistance < shortestDistance) { -
10816 shortestDistance = targetCandidateDistance; -
10817 targetWidget = targetCandidate; -
10818 } -
10819 } -
10820 } -
10821 return targetWidget; -
10822} -
10823 -
10824/*! -
10825 \internal -
10826 -
10827 Tells us if it there is currently a reachable widget by keypad navigation in -
10828 a certain \a orientation. -
10829 If no navigation is possible, occurring key events in that \a orientation may -
10830 be used to interact with the value in the focused widget, even though it -
10831 currently has not the editFocus. -
10832 -
10833 \sa QWidgetPrivate::widgetInNavigationDirection(), QWidget::hasEditFocus() -
10834*/ -
10835bool QWidgetPrivate::canKeypadNavigate(Qt::Orientation orientation) -
10836{ -
10837 return orientation == Qt::Horizontal? -
10838 (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast) -
10839 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest)) -
10840 :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth) -
10841 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth)); -
10842} -
10843/*! -
10844 \internal -
10845 -
10846 Checks, if the \a widget is inside a QTabWidget. If is is inside -
10847 one, left/right key events will be used to switch between tabs in keypad -
10848 navigation. If there is no QTabWidget, the horizontal key events can be used -
10849to -
10850 interact with the value in the focused widget, even though it currently has -
10851 not the editFocus. -
10852 -
10853 \sa QWidget::hasEditFocus() -
10854*/ -
10855bool QWidgetPrivate::inTabWidget(QWidget *widget) -
10856{ -
10857 for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget()) -
10858 if (qobject_cast<const QTabWidget*>(tabWidget)) -
10859 return true; -
10860 return false; -
10861} -
10862#endif -
10863 -
10864/*! -
10865 \since 5.0 -
10866 \internal -
10867 -
10868 Sets the backing store to be the \a store specified. -
10869 The QWidget will take ownership of the \a store. -
10870*/ -
10871void QWidget::setBackingStore(QBackingStore *store) -
10872{ -
10873 // ### createWinId() ?? -
10874 -
10875 if (!isTopLevel()) -
10876 return; -
10877 -
10878 Q_D(QWidget); -
10879 -
10880 QTLWExtra *topData = d->topData(); -
10881 if (topData->backingStore == store) -
10882 return; -
10883 -
10884 QBackingStore *oldStore = topData->backingStore; -
10885 delete topData->backingStore; -
10886 topData->backingStore = store; -
10887 -
10888 QWidgetBackingStore *bs = d->maybeBackingStore(); -
10889 if (!bs) -
10890 return; -
10891 -
10892 if (isTopLevel()) { -
10893 if (bs->store != oldStore && bs->store != store) -
10894 delete bs->store; -
10895 bs->store = store; -
10896 } -
10897} -
10898 -
10899/*! -
10900 \since 5.0 -
10901 -
10902 Returns the QBackingStore this widget will be drawn into. -
10903*/ -
10904QBackingStore *QWidget::backingStore() const -
10905{ -
10906 Q_D(const QWidget); -
10907 QTLWExtra *extra = d->maybeTopData(); -
10908 if (extra && extra->backingStore) -
10909 return extra->backingStore; -
10910 -
10911 QWidgetBackingStore *bs = d->maybeBackingStore(); -
10912 -
10913 return bs ? bs->store : 0; -
10914} -
10915 -
10916void QWidgetPrivate::getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const -
10917{ -
10918 if (left) -
10919 *left = (int)leftLayoutItemMargin; -
10920 if (top) -
10921 *top = (int)topLayoutItemMargin; -
10922 if (right) -
10923 *right = (int)rightLayoutItemMargin; -
10924 if (bottom) -
10925 *bottom = (int)bottomLayoutItemMargin; -
10926} -
10927 -
10928void QWidgetPrivate::setLayoutItemMargins(int left, int top, int right, int bottom) -
10929{ -
10930 if (leftLayoutItemMargin == left -
10931 && topLayoutItemMargin == top -
10932 && rightLayoutItemMargin == right -
10933 && bottomLayoutItemMargin == bottom) -
10934 return; -
10935 -
10936 Q_Q(QWidget); -
10937 leftLayoutItemMargin = (signed char)left; -
10938 topLayoutItemMargin = (signed char)top; -
10939 rightLayoutItemMargin = (signed char)right; -
10940 bottomLayoutItemMargin = (signed char)bottom; -
10941 q->updateGeometry(); -
10942} -
10943 -
10944void QWidgetPrivate::setLayoutItemMargins(QStyle::SubElement element, const QStyleOption *opt) -
10945{ -
10946 Q_Q(QWidget); -
10947 QStyleOption myOpt; -
10948 if (!opt) { -
10949 myOpt.initFrom(q); -
10950 myOpt.rect.setRect(0, 0, 32768, 32768); // arbitrary -
10951 opt = &myOpt; -
10952 } -
10953 -
10954 QRect liRect = q->style()->subElementRect(element, opt, q); -
10955 if (liRect.isValid()) { -
10956 leftLayoutItemMargin = (signed char)(opt->rect.left() - liRect.left()); -
10957 topLayoutItemMargin = (signed char)(opt->rect.top() - liRect.top()); -
10958 rightLayoutItemMargin = (signed char)(liRect.right() - opt->rect.right()); -
10959 bottomLayoutItemMargin = (signed char)(liRect.bottom() - opt->rect.bottom()); -
10960 } else { -
10961 leftLayoutItemMargin = 0; -
10962 topLayoutItemMargin = 0; -
10963 rightLayoutItemMargin = 0; -
10964 bottomLayoutItemMargin = 0; -
10965 } -
10966} -
10967// resets the Qt::WA_QuitOnClose attribute to the default value for transient widgets. -
10968void QWidgetPrivate::adjustQuitOnCloseAttribute() -
10969{ -
10970 Q_Q(QWidget); -
10971 -
10972 if (!q->parentWidget()) { -
10973 Qt::WindowType type = q->windowType(); -
10974 if (type == Qt::Widget || type == Qt::SubWindow) -
10975 type = Qt::Window; -
10976 if (type != Qt::Widget && type != Qt::Window && type != Qt::Dialog) -
10977 q->setAttribute(Qt::WA_QuitOnClose, false); -
10978 } -
10979} -
10980 -
10981 -
10982 -
10983Q_WIDGETS_EXPORT QWidgetData *qt_qwidget_data(QWidget *widget) -
10984{ -
10985 return widget->data; -
10986} -
10987 -
10988Q_WIDGETS_EXPORT QWidgetPrivate *qt_widget_private(QWidget *widget) -
10989{ -
10990 return widget->d_func(); -
10991} -
10992 -
10993 -
10994#ifndef QT_NO_GRAPHICSVIEW -
10995/*! -
10996 \since 4.5 -
10997 -
10998 Returns the proxy widget for the corresponding embedded widget in a graphics -
10999 view; otherwise returns 0. -
11000 -
11001 \sa QGraphicsProxyWidget::createProxyForChildWidget(), -
11002 QGraphicsScene::addWidget() -
11003 */ -
11004QGraphicsProxyWidget *QWidget::graphicsProxyWidget() const -
11005{ -
11006 Q_D(const QWidget); -
11007 if (d->extra) { -
11008 return d->extra->proxyWidget; -
11009 } -
11010 return 0; -
11011} -
11012#endif -
11013 -
11014#ifndef QT_NO_GESTURES -
11015/*! -
11016 Subscribes the widget to a given \a gesture with specific \a flags. -
11017 -
11018 \sa ungrabGesture(), QGestureEvent -
11019 \since 4.6 -
11020*/ -
11021void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags) -
11022{ -
11023 Q_D(QWidget); -
11024 d->gestureContext.insert(gesture, flags); -
11025 (void)QGestureManager::instance(); // create a gesture manager -
11026} -
11027 -
11028/*! -
11029 Unsubscribes the widget from a given \a gesture type -
11030 -
11031 \sa grabGesture(), QGestureEvent -
11032 \since 4.6 -
11033*/ -
11034void QWidget::ungrabGesture(Qt::GestureType gesture) -
11035{ -
11036 Q_D(QWidget); -
11037 if (d->gestureContext.remove(gesture)) { -
11038 if (QGestureManager *manager = QGestureManager::instance()) -
11039 manager->cleanupCachedGestures(this, gesture); -
11040 } -
11041} -
11042#endif // QT_NO_GESTURES -
11043 -
11044/*! -
11045 \fn void QWidget::destroy(bool destroyWindow, bool destroySubWindows) -
11046 -
11047 Frees up window system resources. Destroys the widget window if \a -
11048 destroyWindow is true. -
11049 -
11050 destroy() calls itself recursively for all the child widgets, -
11051 passing \a destroySubWindows for the \a destroyWindow parameter. -
11052 To have more control over destruction of subwidgets, destroy -
11053 subwidgets selectively first. -
11054 -
11055 This function is usually called from the QWidget destructor. -
11056*/ -
11057 -
11058/*! -
11059 \fn QPaintEngine *QWidget::paintEngine() const -
11060 -
11061 Returns the widget's paint engine. -
11062 -
11063 Note that this function should not be called explicitly by the -
11064 user, since it's meant for reimplementation purposes only. The -
11065 function is called by Qt internally, and the default -
11066 implementation may not always return a valid pointer. -
11067*/ -
11068 -
11069/*! -
11070 \fn QPoint QWidget::mapToGlobal(const QPoint &pos) const -
11071 -
11072 Translates the widget coordinate \a pos to global screen -
11073 coordinates. For example, \c{mapToGlobal(QPoint(0,0))} would give -
11074 the global coordinates of the top-left pixel of the widget. -
11075 -
11076 \sa mapFromGlobal(), mapTo(), mapToParent() -
11077*/ -
11078 -
11079/*! -
11080 \fn QPoint QWidget::mapFromGlobal(const QPoint &pos) const -
11081 -
11082 Translates the global screen coordinate \a pos to widget -
11083 coordinates. -
11084 -
11085 \sa mapToGlobal(), mapFrom(), mapFromParent() -
11086*/ -
11087 -
11088/*! -
11089 \fn void QWidget::grabMouse() -
11090 -
11091 Grabs the mouse input. -
11092 -
11093 This widget receives all mouse events until releaseMouse() is -
11094 called; other widgets get no mouse events at all. Keyboard -
11095 events are not affected. Use grabKeyboard() if you want to grab -
11096 that. -
11097 -
11098 \warning Bugs in mouse-grabbing applications very often lock the -
11099 terminal. Use this function with extreme caution, and consider -
11100 using the \c -nograb command line option while debugging. -
11101 -
11102 It is almost never necessary to grab the mouse when using Qt, as -
11103 Qt grabs and releases it sensibly. In particular, Qt grabs the -
11104 mouse when a mouse button is pressed and keeps it until the last -
11105 button is released. -
11106 -
11107 \note Only visible widgets can grab mouse input. If isVisible() -
11108 returns false for a widget, that widget cannot call grabMouse(). -
11109 -
11110 \note \b{(Mac OS X developers)} For \e Cocoa, calling -
11111 grabMouse() on a widget only works when the mouse is inside the -
11112 frame of that widget. For \e Carbon, it works outside the widget's -
11113 frame as well, like for Windows and X11. -
11114 -
11115 \sa releaseMouse(), grabKeyboard(), releaseKeyboard() -
11116*/ -
11117 -
11118/*! -
11119 \fn void QWidget::grabMouse(const QCursor &cursor) -
11120 \overload grabMouse() -
11121 -
11122 Grabs the mouse input and changes the cursor shape. -
11123 -
11124 The cursor will assume shape \a cursor (for as long as the mouse -
11125 focus is grabbed) and this widget will be the only one to receive -
11126 mouse events until releaseMouse() is called(). -
11127 -
11128 \warning Grabbing the mouse might lock the terminal. -
11129 -
11130 \note \b{(Mac OS X developers)} See the note in QWidget::grabMouse(). -
11131 -
11132 \sa releaseMouse(), grabKeyboard(), releaseKeyboard(), setCursor() -
11133*/ -
11134 -
11135/*! -
11136 \fn void QWidget::releaseMouse() -
11137 -
11138 Releases the mouse grab. -
11139 -
11140 \sa grabMouse(), grabKeyboard(), releaseKeyboard() -
11141*/ -
11142 -
11143/*! -
11144 \fn void QWidget::grabKeyboard() -
11145 -
11146 Grabs the keyboard input. -
11147 -
11148 This widget receives all keyboard events until releaseKeyboard() -
11149 is called; other widgets get no keyboard events at all. Mouse -
11150 events are not affected. Use grabMouse() if you want to grab that. -
11151 -
11152 The focus widget is not affected, except that it doesn't receive -
11153 any keyboard events. setFocus() moves the focus as usual, but the -
11154 new focus widget receives keyboard events only after -
11155 releaseKeyboard() is called. -
11156 -
11157 If a different widget is currently grabbing keyboard input, that -
11158 widget's grab is released first. -
11159 -
11160 \sa releaseKeyboard(), grabMouse(), releaseMouse(), focusWidget() -
11161*/ -
11162 -
11163/*! -
11164 \fn void QWidget::releaseKeyboard() -
11165 -
11166 Releases the keyboard grab. -
11167 -
11168 \sa grabKeyboard(), grabMouse(), releaseMouse() -
11169*/ -
11170 -
11171/*! -
11172 \fn QWidget *QWidget::mouseGrabber() -
11173 -
11174 Returns the widget that is currently grabbing the mouse input. -
11175 -
11176 If no widget in this application is currently grabbing the mouse, -
11177 0 is returned. -
11178 -
11179 \sa grabMouse(), keyboardGrabber() -
11180*/ -
11181 -
11182/*! -
11183 \fn QWidget *QWidget::keyboardGrabber() -
11184 -
11185 Returns the widget that is currently grabbing the keyboard input. -
11186 -
11187 If no widget in this application is currently grabbing the -
11188 keyboard, 0 is returned. -
11189 -
11190 \sa grabMouse(), mouseGrabber() -
11191*/ -
11192 -
11193/*! -
11194 \fn void QWidget::activateWindow() -
11195 -
11196 Sets the top-level widget containing this widget to be the active -
11197 window. -
11198 -
11199 An active window is a visible top-level window that has the -
11200 keyboard input focus. -
11201 -
11202 This function performs the same operation as clicking the mouse on -
11203 the title bar of a top-level window. On X11, the result depends on -
11204 the Window Manager. If you want to ensure that the window is -
11205 stacked on top as well you should also call raise(). Note that the -
11206 window must be visible, otherwise activateWindow() has no effect. -
11207 -
11208 On Windows, if you are calling this when the application is not -
11209 currently the active one then it will not make it the active -
11210 window. It will change the color of the taskbar entry to indicate -
11211 that the window has changed in some way. This is because Microsoft -
11212 does not allow an application to interrupt what the user is currently -
11213 doing in another application. -
11214 -
11215 \sa isActiveWindow(), window(), show() -
11216*/ -
11217 -
11218/*! -
11219 \fn int QWidget::metric(PaintDeviceMetric m) const -
11220 -
11221 Internal implementation of the virtual QPaintDevice::metric() -
11222 function. -
11223 -
11224 \a m is the metric to get. -
11225*/ -
11226 -
11227/*! -
11228 Initializes the \a painter pen, background and font to the same as -
11229 the given widget's. This function is called automatically when the -
11230 painter is opened on a QWidget. -
11231*/ -
11232void QWidget::initPainter(QPainter *painter) const -
11233{ -
11234 const QPalette &pal = palette(); -
11235 painter->d_func()->state->pen = QPen(pal.brush(foregroundRole()), 1); -
11236 painter->d_func()->state->bgBrush = pal.brush(backgroundRole()); -
11237 QFont f(font(), const_cast<QWidget *>(this)); -
11238 painter->d_func()->state->deviceFont = f; -
11239 painter->d_func()->state->font = f; -
11240} -
11241 -
11242QPaintDevice *QWidget::redirected(QPoint *offset) const -
11243{ -
11244 return d_func()->redirected(offset); -
11245} -
11246 -
11247QPainter *QWidget::sharedPainter() const -
11248{ -
11249 // Someone sent a paint event directly to the widget -
11250 if (!d_func()->redirectDev) -
11251 return 0; -
11252 -
11253 QPainter *sp = d_func()->sharedPainter(); -
11254 if (!sp || !sp->isActive()) -
11255 return 0; -
11256 -
11257 if (sp->paintEngine()->paintDevice() != d_func()->redirectDev) -
11258 return 0; -
11259 -
11260 return sp; -
11261} -
11262 -
11263/*! -
11264 \fn void QWidget::setMask(const QRegion &region) -
11265 \overload -
11266 -
11267 Causes only the parts of the widget which overlap \a region to be -
11268 visible. If the region includes pixels outside the rect() of the -
11269 widget, window system controls in that area may or may not be -
11270 visible, depending on the platform. -
11271 -
11272 Note that this effect can be slow if the region is particularly -
11273 complex. -
11274 -
11275 \sa windowOpacity -
11276*/ -
11277void QWidget::setMask(const QRegion &newMask) -
11278{ -
11279 Q_D(QWidget); -
11280 -
11281 d->createExtra(); -
11282 if (newMask == d->extra->mask) -
11283 return; -
11284 -
11285#ifndef QT_NO_BACKINGSTORE -
11286 const QRegion oldMask(d->extra->mask); -
11287#endif -
11288 -
11289 d->extra->mask = newMask; -
11290 d->extra->hasMask = !newMask.isEmpty(); -
11291 -
11292#ifndef Q_WS_MAC -
11293 if (!testAttribute(Qt::WA_WState_Created)) -
11294 return; -
11295#endif -
11296 -
11297 d->setMask_sys(newMask); -
11298 -
11299#ifndef QT_NO_BACKINGSTORE -
11300 if (!isVisible()) -
11301 return; -
11302 -
11303 if (!d->extra->hasMask) { -
11304 // Mask was cleared; update newly exposed area. -
11305 QRegion expose(rect()); -
11306 expose -= oldMask; -
11307 if (!expose.isEmpty()) { -
11308 d->setDirtyOpaqueRegion(); -
11309 update(expose); -
11310 } -
11311 return; -
11312 } -
11313 -
11314 if (!isWindow()) { -
11315 // Update newly exposed area on the parent widget. -
11316 QRegion parentExpose(rect()); -
11317 parentExpose -= newMask; -
11318 if (!parentExpose.isEmpty()) { -
11319 d->setDirtyOpaqueRegion(); -
11320 parentExpose.translate(data->crect.topLeft()); -
11321 parentWidget()->update(parentExpose); -
11322 } -
11323 -
11324 // Update newly exposed area on this widget -
11325 if (!oldMask.isEmpty()) -
11326 update(newMask - oldMask); -
11327 } -
11328#endif -
11329} -
11330 -
11331/*! -
11332 \fn void QWidget::setMask(const QBitmap &bitmap) -
11333 -
11334 Causes only the pixels of the widget for which \a bitmap has a -
11335 corresponding 1 bit to be visible. If the region includes pixels -
11336 outside the rect() of the widget, window system controls in that -
11337 area may or may not be visible, depending on the platform. -
11338 -
11339 Note that this effect can be slow if the region is particularly -
11340 complex. -
11341 -
11342 The following code shows how an image with an alpha channel can be -
11343 used to generate a mask for a widget: -
11344 -
11345 \snippet widget-mask/main.cpp 0 -
11346 -
11347 The label shown by this code is masked using the image it contains, -
11348 giving the appearance that an irregularly-shaped image is being drawn -
11349 directly onto the screen. -
11350 -
11351 Masked widgets receive mouse events only on their visible -
11352 portions. -
11353 -
11354 \sa clearMask(), windowOpacity(), {Shaped Clock Example} -
11355*/ -
11356void QWidget::setMask(const QBitmap &bitmap) -
11357{ -
11358 setMask(QRegion(bitmap)); -
11359} -
11360 -
11361/*! -
11362 \fn void QWidget::clearMask() -
11363 -
11364 Removes any mask set by setMask(). -
11365 -
11366 \sa setMask() -
11367*/ -
11368void QWidget::clearMask() -
11369{ -
11370 setMask(QRegion()); -
11371} -
11372 -
11373#ifdef Q_WS_MAC -
11374void QWidgetPrivate::syncUnifiedMode() { -
11375 // The whole purpose of this method is to keep the unifiedToolbar in sync. -
11376 // That means making sure we either exchange the drawing methods or we let -
11377 // the toolbar know that it does not require to draw the baseline. -
11378 Q_Q(QWidget); -
11379 // This function makes sense only if this is a top level -
11380 if(!q->isWindow()) -
11381 return; -
11382 OSWindowRef window = qt_mac_window_for(q); -
11383 if(changeMethods) { -
11384 // Ok, we are in documentMode. -
11385 if(originalDrawMethod) -
11386 qt_mac_replaceDrawRect(window, this); -
11387 } else { -
11388 if(!originalDrawMethod) -
11389 qt_mac_replaceDrawRectOriginal(window, this); -
11390 } -
11391} -
11392 -
11393#endif // Q_WS_MAC -
11394 -
11395QT_END_NAMESPACE -
11396 -
11397#include "moc_qwidget.cpp" -
11398 -
11399 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial