Qt 4.8
qwidget.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 #ifndef QT_NO_ACCESSIBILITY
61 # include "qaccessible.h"
62 #endif
63 #if defined(Q_WS_WIN)
64 # include "qt_windows.h"
65 #endif
66 #ifdef Q_WS_MAC
67 # include "qt_mac_p.h"
68 # include "qt_cocoa_helpers_mac_p.h"
69 # include "qmainwindow.h"
70 # include "qtoolbar.h"
71 # include <private/qmainwindowlayout_p.h>
72 #endif
73 #if defined(Q_WS_QWS)
74 # include "qwsdisplay_qws.h"
75 # include "qwsmanager_qws.h"
76 # include "qpaintengine.h" // for PorterDuff
77 # include "private/qwindowsurface_qws_p.h"
78 #endif
79 #if defined(Q_WS_QPA)
80 #include "qplatformwindow_qpa.h"
81 #endif
82 #include "qpainter.h"
83 #include "qtooltip.h"
84 #include "qwhatsthis.h"
85 #include "qdebug.h"
86 #include "private/qstylesheetstyle_p.h"
87 #include "private/qstyle_p.h"
88 #include "private/qinputcontext_p.h"
89 #include "qfileinfo.h"
90 #include "private/qsoftkeymanager_p.h"
91 
92 #if defined (Q_WS_WIN)
93 # include <private/qwininputcontext_p.h>
94 #endif
95 
96 #if defined(Q_WS_X11)
97 # include <private/qpaintengine_x11_p.h>
98 # include "qx11info_x11.h"
99 #endif
100 
101 #include <private/qgraphicseffect_p.h>
102 #include <private/qwindowsurface_p.h>
103 #include <private/qbackingstore_p.h>
104 #ifdef Q_WS_MAC
105 # include <private/qpaintengine_mac_p.h>
106 #endif
107 #include <private/qpaintengine_raster_p.h>
108 
109 #if defined(Q_OS_SYMBIAN)
110 #include "private/qt_s60_p.h"
111 #endif
112 
113 #include "qwidget_p.h"
114 #include "qaction_p.h"
115 #include "qlayout_p.h"
116 #include "QtGui/qgraphicsproxywidget.h"
117 #include "QtGui/qgraphicsscene.h"
118 #include "private/qgraphicsproxywidget_p.h"
119 #include "QtGui/qabstractscrollarea.h"
120 #include "private/qabstractscrollarea_p.h"
121 #include "private/qevent_p.h"
122 
123 #include "private/qgraphicssystem_p.h"
124 #include "private/qgesturemanager_p.h"
125 
126 #ifdef QT_KEYPAD_NAVIGATION
127 #include "qtabwidget.h" // Needed in inTabWidget()
128 #endif // QT_KEYPAD_NAVIGATION
129 
130 #ifdef Q_WS_S60
131 #include <aknappui.h>
132 #endif
133 
134 #ifdef Q_OS_BLACKBERRY
135 #include <bps/navigator.h>
136 #endif
137 
138 #ifdef Q_OS_BLACKBERRY_TABLET
139 #include <bps/orientation.h>
140 #endif
141 
142 // widget/widget data creation count
143 //#define QWIDGET_EXTRA_DEBUG
144 //#define ALIEN_DEBUG
145 
147 
148 #if !defined(Q_WS_QWS)
149 static bool qt_enable_backingstore = true;
150 #endif
151 #ifdef Q_WS_X11
152 // for compatibility with Qt 4.0
154 {
155  qt_enable_backingstore = enable;
156 }
157 #endif
158 
159 #if defined(QT_MAC_USE_COCOA)
160 bool qt_mac_clearDirtyOnWidgetInsideDrawWidget = false;
161 #endif
162 
163 static inline bool qRectIntersects(const QRect &r1, const QRect &r2)
164 {
165  return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right()) &&
166  qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom()));
167 }
168 
169 static inline bool hasBackingStoreSupport()
170 {
171 #ifdef Q_WS_MAC
173 #else
174  return true;
175 #endif
176 }
177 
178 #ifdef Q_WS_MAC
179 # define QT_NO_PAINT_DEBUG
180 #endif
181 
182 extern bool qt_sendSpontaneousEvent(QObject*, QEvent*); // qapplication.cpp
183 extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp
184 
199  : m_ptr(0)
200 {
201 
202 }
203 
205 {
206  delete m_ptr;
207 }
208 
219 {
220  destroy();
221  m_ptr = new QWidgetBackingStore(widget);
222 }
223 
233 {
234  delete m_ptr;
235  m_ptr = 0;
236  m_widgets.clear();
237 }
238 
248 {
249  Q_ASSERT(m_ptr);
250  Q_ASSERT(w->internalWinId());
251  Q_ASSERT(qt_widget_private(w)->maybeBackingStore() == m_ptr);
252  m_widgets.insert(w);
253 }
254 
266 {
267  if (m_widgets.remove(w) && m_widgets.isEmpty()) {
268  delete m_ptr;
269  m_ptr = 0;
270  }
271 }
272 
281 {
282  unregisterWidget(widget);
283  foreach (QObject *child, widget->children())
284  if (QWidget *childWidget = qobject_cast<QWidget *>(child))
285  unregisterWidgetSubtree(childWidget);
286 }
287 
289  : QObjectPrivate(version)
290  , extra(0)
291  , focus_next(0)
292  , focus_prev(0)
293  , focus_child(0)
294  , layout(0)
295  , needsFlush(0)
296  , redirectDev(0)
297  , widgetItem(0)
298  , extraPaintEngine(0)
299  , polished(0)
300  , graphicsEffect(0)
301 #if !defined(QT_NO_IM)
302  , imHints(Qt::ImhNone)
303 #endif
304  , inheritedFontResolveMask(0)
305  , inheritedPaletteResolveMask(0)
306  , leftmargin(0)
307  , topmargin(0)
308  , rightmargin(0)
309  , bottommargin(0)
310  , leftLayoutItemMargin(0)
311  , topLayoutItemMargin(0)
312  , rightLayoutItemMargin(0)
313  , bottomLayoutItemMargin(0)
314  , hd(0)
315  , size_policy(QSizePolicy::Preferred, QSizePolicy::Preferred)
316  , fg_role(QPalette::NoRole)
317  , bg_role(QPalette::NoRole)
318  , dirtyOpaqueChildren(1)
319  , isOpaque(0)
320  , inDirtyList(0)
321  , isScrolled(0)
322  , isMoved(0)
323  , isGLWidget(0)
324  , usesDoubleBufferedGLContext(0)
325 #ifndef QT_NO_IM
326  , inheritsInputMethodHints(0)
327 #endif
328  , inSetParent(0)
329 #if defined(Q_WS_X11)
330  , picture(0)
331 #elif defined(Q_WS_WIN)
332  , noPaintOnScreen(0)
333  #ifndef QT_NO_GESTURES
334  , nativeGesturePanEnabled(0)
335  #endif
336 #elif defined(Q_WS_MAC)
337  , needWindowChange(0)
338  , window_event(0)
339  , qd_hd(0)
340 #elif defined(Q_OS_SYMBIAN)
341  , symbianScreenNumber(0)
342  , fixNativeOrientationCalled(false)
343  , isGLGlobalShareWidget(0)
344 #endif
345 {
346  if (!qApp) {
347  qFatal("QWidget: Must construct a QApplication before a QPaintDevice");
348  return;
349  }
350 
351  if (version != QObjectPrivateVersion)
352  qFatal("Cannot mix incompatible Qt libraries");
353 
354  isWidget = true;
355  memset(high_attributes, 0, sizeof(high_attributes));
356 #if QT_MAC_USE_COCOA
357  drawRectOriginalAdded = false;
358  originalDrawMethod = true;
359  changeMethods = false;
360  isInUnifiedToolbar = false;
361  unifiedSurface = 0;
362  toolbar_ancestor = 0;
363  flushRequested = false;
364  touchEventsEnabled = false;
365 #endif // QT_MAC_USE_COCOA
366 #ifdef QWIDGET_EXTRA_DEBUG
367  static int count = 0;
368  qDebug() << "widgets" << ++count;
369 #endif
370 }
371 
372 
374 {
375 #ifdef Q_OS_SYMBIAN
376  _q_cleanupWinIds();
377 #endif
378 
379  if (widgetItem)
380  widgetItem->wid = 0;
381 
382  if (extra)
383  deleteExtra();
384 
385 #ifndef QT_NO_GRAPHICSEFFECT
386  delete graphicsEffect;
387 #endif //QT_NO_GRAPHICSEFFECT
388 }
389 
391 {
392 public:
394  QPaintDevice *paintDevice() { return window(); }
395  void flush(QWidget *, const QRegion &, const QPoint &) {}
396 };
397 
399 {
400  Q_Q(QWidget);
401 
402  QWindowSurface *surface;
403 #ifndef QT_NO_PROPERTIES
404  if (q->property("_q_DummyWindowSurface").toBool()) {
405  surface = new QDummyWindowSurface(q);
406  } else
407 #endif
408  {
411  else
412  surface = createDefaultWindowSurface_sys();
413  }
414 
415  return surface;
416 }
417 
421 void QWidgetPrivate::scrollChildren(int dx, int dy)
422 {
423  Q_Q(QWidget);
424  if (q->children().size() > 0) { // scroll children
425  QPoint pd(dx, dy);
426  QObjectList childObjects = q->children();
427  for (int i = 0; i < childObjects.size(); ++i) { // move all children
428  QWidget *w = qobject_cast<QWidget*>(childObjects.at(i));
429  if (w && !w->isWindow()) {
430  QPoint oldp = w->pos();
431  QRect r(w->pos() + pd, w->size());
432  w->data->crect = r;
433 #ifndef Q_WS_QWS
435  w->d_func()->setWSGeometry();
436 #endif
437  w->d_func()->setDirtyOpaqueRegion();
438  QMoveEvent e(r.topLeft(), oldp);
440  }
441  }
442  }
443 }
444 
445 #ifndef QT_NO_IM
447 {
448  const QWidget *widget = q_func();
449  while (widget) {
450  if (QInputContext *qic = widget->d_func()->ic)
451  return qic;
452  widget = widget->parentWidget();
453  }
454  return 0;
455 }
456 
458 {
459  if (QInputContext *qic = assignedInputContext())
460  return qic;
461  return qApp->inputContext();
462 }
463 
475 {
476  Q_D(QWidget);
477  if (!testAttribute(Qt::WA_InputMethodEnabled))
478  return 0;
479 
480  return d->inputContext();
481 }
482 
492 {
493  Q_D(QWidget);
494  if (!testAttribute(Qt::WA_InputMethodEnabled))
495  return;
496 
497  if (context == d->ic)
498  return;
499  if (d->ic)
500  delete d->ic;
501  d->ic = context;
502  if (d->ic)
503  d->ic->setParent(this);
504 }
505 #endif // QT_NO_IM
506 
523 {
524  if (!hasFocus())
525  return;
526 #ifndef QT_NO_IM
527  QInputContext *qic = this->inputContext();
528  if(qic)
529  qic->reset();
530 #endif // QT_NO_IM
531 }
532 
533 #ifdef QT_KEYPAD_NAVIGATION
534 QPointer<QWidget> QWidgetPrivate::editingWidget;
535 
543 bool QWidget::hasEditFocus() const
544 {
545  const QWidget* w = this;
546  while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
547  w = w->d_func()->extra->focus_proxy;
548  return QWidgetPrivate::editingWidget == w;
549 }
550 
567 void QWidget::setEditFocus(bool on)
568 {
569  QWidget *f = this;
570  while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
571  f = f->d_func()->extra->focus_proxy;
572 
573  if (QWidgetPrivate::editingWidget && QWidgetPrivate::editingWidget != f)
574  QWidgetPrivate::editingWidget->setEditFocus(false);
575 
576  if (on && !f->hasFocus())
577  f->setFocus();
578 
579  if ((!on && !QWidgetPrivate::editingWidget)
580  || (on && QWidgetPrivate::editingWidget == f)) {
581  return;
582  }
583 
584  if (!on && QWidgetPrivate::editingWidget == f) {
585  QWidgetPrivate::editingWidget = 0;
586  QEvent event(QEvent::LeaveEditFocus);
587  QApplication::sendEvent(f, &event);
589  } else if (on) {
590  QWidgetPrivate::editingWidget = f;
591  QEvent event(QEvent::EnterEditFocus);
592  QApplication::sendEvent(f, &event);
594  }
595 }
596 #endif
597 
625 bool QWidget::autoFillBackground() const
626 {
627  Q_D(const QWidget);
628  return d->extra && d->extra->autoFillBackground;
629 }
630 
632 {
633  Q_D(QWidget);
634  if (!d->extra)
635  d->createExtra();
636  if (d->extra->autoFillBackground == enabled)
637  return;
638 
639  d->extra->autoFillBackground = enabled;
640  d->updateIsOpaque();
641  update();
642  d->updateIsOpaque();
643 }
644 
1103 QWidgetMapper *QWidgetPrivate::mapper = 0; // widget with wid
1104 QWidgetSet *QWidgetPrivate::allWidgets = 0; // widgets with no wid
1105 
1106 
1107 /*****************************************************************************
1108  QWidget utility functions
1109  *****************************************************************************/
1110 
1112 {
1113  if (!widget)
1114  return QRegion();
1115 
1117  if (!bs)
1118  return QRegion();
1119 
1120  return bs->dirtyRegion(widget);
1121 }
1122 
1123 /*****************************************************************************
1124  QWidget member functions
1125  *****************************************************************************/
1126 
1127 /*
1128  Widget state flags:
1129  \list
1130  <li> Qt::WA_WState_Created The widget has a valid winId().
1131  <li> Qt::WA_WState_Visible The widget is currently visible.
1132  <li> Qt::WA_WState_Hidden The widget is hidden, i.e. it won't
1133  become visible unless you call show() on it. Qt::WA_WState_Hidden
1134  implies !Qt::WA_WState_Visible.
1135  <li> Qt::WA_WState_CompressKeys Compress keyboard events.
1136  <li> Qt::WA_WState_BlockUpdates Repaints and updates are disabled.
1137  <li> Qt::WA_WState_InPaintEvent Currently processing a paint event.
1138  <li> Qt::WA_WState_Reparented The widget has been reparented.
1139  <li> Qt::WA_WState_ConfigPending A configuration (resize/move) event is pending.
1140  <li> Qt::WA_WState_DND (Deprecated) The widget supports drag and drop, see setAcceptDrops().
1141  \endlist
1142 */
1143 
1145 {
1146  /* this cleans up when the constructor throws an exception */
1147  static inline void cleanup(QWidget *that, QWidgetPrivate *d)
1148  {
1149 #ifdef QT_NO_EXCEPTIONS
1150  Q_UNUSED(that);
1151  Q_UNUSED(d);
1152 #else
1153  QWidgetPrivate::allWidgets->remove(that);
1154  if (d->focus_next != that) {
1155  if (d->focus_next)
1156  d->focus_next->d_func()->focus_prev = d->focus_prev;
1157  if (d->focus_prev)
1158  d->focus_prev->d_func()->focus_next = d->focus_next;
1159  }
1160 #endif
1161  }
1162 };
1163 
1189 QWidget::QWidget(QWidget *parent, Qt::WindowFlags f)
1190  : QObject(*new QWidgetPrivate, 0), QPaintDevice()
1191 {
1192  QT_TRY {
1193  d_func()->init(parent, f);
1194  } QT_CATCH(...) {
1195  QWidgetExceptionCleaner::cleanup(this, d_func());
1196  QT_RETHROW;
1197  }
1198 }
1199 
1200 #ifdef QT3_SUPPORT
1201 
1205 QWidget::QWidget(QWidget *parent, const char *name, Qt::WindowFlags f)
1206  : QObject(*new QWidgetPrivate, 0), QPaintDevice()
1207 {
1208  QT_TRY {
1209  d_func()->init(parent , f);
1211  } QT_CATCH(...) {
1212  QWidgetExceptionCleaner::cleanup(this, d_func());
1213  QT_RETHROW;
1214  }
1215 }
1216 #endif
1217 
1220 QWidget::QWidget(QWidgetPrivate &dd, QWidget* parent, Qt::WindowFlags f)
1221  : QObject(dd, 0), QPaintDevice()
1222 {
1223  Q_D(QWidget);
1224  QT_TRY {
1225  d->init(parent, f);
1226  } QT_CATCH(...) {
1227  QWidgetExceptionCleaner::cleanup(this, d_func());
1228  QT_RETHROW;
1229  }
1230 }
1231 
1235 int QWidget::devType() const
1236 {
1237  return QInternal::Widget;
1238 }
1239 
1240 
1241 //### w is a "this" ptr, passed as a param because QWorkspace needs special logic
1242 void QWidgetPrivate::adjustFlags(Qt::WindowFlags &flags, QWidget *w)
1243 {
1244  bool customize = (flags & (Qt::CustomizeWindowHint
1252 
1253  uint type = (flags & Qt::WindowType_Mask);
1254 
1255  if ((type == Qt::Widget || type == Qt::SubWindow) && w && !w->parent()) {
1256  type = Qt::Window;
1257  flags |= Qt::Window;
1258  }
1259 
1260  if (flags & Qt::CustomizeWindowHint) {
1261  // modify window flags to make them consistent.
1262  // Only enable this on non-Mac platforms. Since the old way of doing this would
1263  // interpret WindowSystemMenuHint as a close button and we can't change that behavior
1264  // we can't just add this in.
1265 #ifndef Q_WS_MAC
1267  flags |= Qt::WindowSystemMenuHint;
1268 #else
1271 #endif
1272  flags |= Qt::WindowTitleHint;
1273  flags &= ~Qt::FramelessWindowHint;
1274  }
1275  } else if (customize && !(flags & Qt::FramelessWindowHint)) {
1276  // if any of the window hints that affect the titlebar are set
1277  // and the window is supposed to have frame, we add a titlebar
1278  // and system menu by default.
1279  flags |= Qt::WindowSystemMenuHint;
1280  flags |= Qt::WindowTitleHint;
1281  }
1282  if (customize)
1283  ; // don't modify window flags if the user explicitly set them.
1284  else if (type == Qt::Dialog || type == Qt::Sheet)
1285 #ifndef Q_WS_WINCE
1287 #else
1289 #endif
1290  else if (type == Qt::Tool)
1292  else
1294 
1295 
1296 }
1297 
1298 void QWidgetPrivate::init(QWidget *parentWidget, Qt::WindowFlags f)
1299 {
1300  Q_Q(QWidget);
1302  qFatal("QWidget: Cannot create a QWidget when no GUI is being used");
1303 
1304  Q_ASSERT(allWidgets);
1305  if (allWidgets)
1306  allWidgets->insert(q);
1307 
1308  QWidget *desktopWidget = 0;
1309  if (parentWidget && parentWidget->windowType() == Qt::Desktop) {
1310  desktopWidget = parentWidget;
1311  parentWidget = 0;
1312  }
1313 
1314  q->data = &data;
1315 
1316 #ifndef QT_NO_THREAD
1317  if (!parent) {
1318  Q_ASSERT_X(q->thread() == qApp->thread(), "QWidget",
1319  "Widgets must be created in the GUI thread.");
1320  }
1321 #endif
1322 
1323 #if defined(Q_WS_X11)
1324  if (desktopWidget) {
1325  // make sure the widget is created on the same screen as the
1326  // programmer specified desktop widget
1327  xinfo = desktopWidget->d_func()->xinfo;
1328  }
1329 #elif defined(Q_OS_SYMBIAN)
1330  if (desktopWidget) {
1331  symbianScreenNumber = qt_widget_private(desktopWidget)->symbianScreenNumber;
1332  }
1333 #elif defined(Q_WS_QPA)
1334  if (desktopWidget) {
1335  int screen = desktopWidget->d_func()->topData()->screenIndex;
1336  topData()->screenIndex = screen;
1337  QPlatformIntegration *platform = QApplicationPrivate::platformIntegration();
1338  platform->moveToScreen(q, screen);
1339  }
1340 #else
1341  Q_UNUSED(desktopWidget);
1342 #endif
1343 
1344  data.fstrut_dirty = true;
1345 
1346  data.winid = 0;
1347  data.widget_attributes = 0;
1348  data.window_flags = f;
1349  data.window_state = 0;
1350  data.focus_policy = 0;
1353 
1354  data.sizehint_forced = 0;
1355  data.is_closing = 0;
1356  data.in_show = 0;
1358  data.in_destructor = false;
1359 
1360  // Widgets with Qt::MSWindowsOwnDC (typically QGLWidget) must have a window handle.
1361  if (f & Qt::MSWindowsOwnDC)
1362  q->setAttribute(Qt::WA_NativeWindow);
1363 
1364 //#ifdef Q_WS_MAC
1365 // q->setAttribute(Qt::WA_NativeWindow);
1366 //#endif
1367 
1368  q->setAttribute(Qt::WA_QuitOnClose); // might be cleared in adjustQuitOnCloseAttribute()
1369  adjustQuitOnCloseAttribute();
1370 
1371  q->setAttribute(Qt::WA_WState_Hidden);
1372 
1373  //give potential windows a bigger "pre-initial" size; create_sys() will give them a new size later
1374 #ifdef Q_OS_SYMBIAN
1375  if (isGLWidget) {
1376  // Don't waste GPU mem for unnecessary large egl surface until resized by application
1377  data.crect = QRect(0,0,1,1);
1378  } else {
1379  data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,360,640);
1380  }
1381 #else
1382  data.crect = parentWidget ? QRect(0,0,100,30) : QRect(0,0,640,480);
1383 #endif
1384 
1385  focus_next = focus_prev = q;
1386 
1387  if ((f & Qt::WindowType_Mask) == Qt::Desktop)
1388  q->create();
1389  else if (parentWidget)
1390  q->setParent(parentWidget, data.window_flags);
1391  else {
1392  adjustFlags(data.window_flags, q);
1393  resolveLayoutDirection();
1394  // opaque system background?
1395  const QBrush &background = q->palette().brush(QPalette::Window);
1396  setOpaque(q->isWindow() && background.style() != Qt::NoBrush && background.isOpaque());
1397  }
1398  data.fnt = QFont(data.fnt, q);
1399 #if defined(Q_WS_X11)
1400  data.fnt.x11SetScreen(xinfo.screen());
1401 #endif // Q_WS_X11
1402 
1403  q->setAttribute(Qt::WA_PendingMoveEvent);
1404  q->setAttribute(Qt::WA_PendingResizeEvent);
1405 
1408 
1411  q->create();
1412 
1413 
1415  QApplication::sendEvent(q, &e);
1417 
1418  extraPaintEngine = 0;
1419 }
1420 
1421 
1422 
1424 {
1425  Q_Q(QWidget);
1426  q->create(0, true, true);
1427  for (int i = 0; i < children.size(); ++i) {
1428  QWidget *child = qobject_cast<QWidget *>(children.at(i));
1429  if (child && !child->isHidden() && !child->isWindow() && !child->testAttribute(Qt::WA_WState_Created))
1430  child->d_func()->createRecursively();
1431  }
1432 }
1433 
1434 
1435 
1436 
1454 void QWidget::create(WId window, bool initializeWindow, bool destroyOldWindow)
1455 {
1456  Q_D(QWidget);
1457  if (testAttribute(Qt::WA_WState_Created) && window == 0 && internalWinId())
1458  return;
1459 
1460  if (d->data.in_destructor)
1461  return;
1462 
1463  Qt::WindowType type = windowType();
1464  Qt::WindowFlags &flags = data->window_flags;
1465 
1466  if ((type == Qt::Widget || type == Qt::SubWindow) && !parentWidget()) {
1467  type = Qt::Window;
1468  flags |= Qt::Window;
1469  }
1470 
1471 #ifndef Q_WS_QPA
1472  if (QWidget *parent = parentWidget()) {
1473  if (type & Qt::Window) {
1474  if (!parent->testAttribute(Qt::WA_WState_Created))
1475  parent->createWinId();
1476  } else if (testAttribute(Qt::WA_NativeWindow) && !parent->internalWinId()
1478  // We're about to create a native child widget that doesn't have a native parent;
1479  // enforce a native handle for the parent unless the Qt::WA_DontCreateNativeAncestors
1480  // attribute is set.
1481  d->createWinId(window);
1482  // Nothing more to do.
1485  return;
1486  }
1487  }
1488 #endif //Q_WS_QPA
1489 
1490 #ifdef QT3_SUPPORT
1491  if (flags & Qt::WStaticContents)
1493  if (flags & Qt::WDestructiveClose)
1495  if (flags & Qt::WShowModal)
1497  if (flags & Qt::WMouseNoMask)
1499  if (flags & Qt::WGroupLeader)
1501  if (flags & Qt::WNoMousePropagation)
1503 #endif
1504 
1505  static int paintOnScreenEnv = -1;
1506  if (paintOnScreenEnv == -1)
1507  paintOnScreenEnv = qgetenv("QT_ONSCREEN_PAINT").toInt() > 0 ? 1 : 0;
1508  if (paintOnScreenEnv == 1)
1510 
1513 
1514 #ifdef ALIEN_DEBUG
1515  qDebug() << "QWidget::create:" << this << "parent:" << parentWidget()
1516  << "Alien?" << !testAttribute(Qt::WA_NativeWindow);
1517 #endif
1518 
1519 #if defined (Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP)
1520  // Unregister the dropsite (if already registered) before we
1521  // re-create the widget with a native window.
1523  && d->extra && d->extra->dropTarget) {
1524  d->registerDropSite(false);
1525  }
1526 #endif // defined (Q_WS_WIN) && !defined(QT_NO_DRAGANDDROP)
1527 
1528  d->updateIsOpaque();
1529 
1530  setAttribute(Qt::WA_WState_Created); // set created flag
1531  d->create_sys(window, initializeWindow, destroyOldWindow);
1532 
1533  // a real toplevel window needs a backing store
1534  if (isWindow() && windowType() != Qt::Desktop) {
1535  d->topData()->backingStore.destroy();
1536  if (hasBackingStoreSupport())
1537  d->topData()->backingStore.create(this);
1538  }
1539 
1540  d->setModal_sys();
1541 
1544 
1545 #ifdef QT_EVAL
1546  extern void qt_eval_init_widget(QWidget *w);
1547  qt_eval_init_widget(this);
1548 #endif
1549 
1550  // need to force the resting of the icon after changing parents
1552  d->setWindowIcon_sys(true);
1553  if (isWindow() && !d->topData()->iconText.isEmpty())
1554  d->setWindowIconText_helper(d->topData()->iconText);
1555  if (isWindow() && !d->topData()->caption.isEmpty())
1556  d->setWindowTitle_helper(d->topData()->caption);
1557  if (windowType() != Qt::Desktop) {
1558  d->updateSystemBackground();
1559 
1561  d->setWindowIcon_sys();
1562  }
1563 }
1564 
1573 {
1574  Q_D(QWidget);
1575  d->data.in_destructor = true;
1576 
1577 #if defined (QT_CHECK_STATE)
1578  if (paintingActive())
1579  qWarning("QWidget: %s (%s) deleted while being painted", className(), name());
1580 #endif
1581 
1582 #ifndef QT_NO_GESTURES
1583  foreach (Qt::GestureType type, d->gestureContext.keys())
1584  ungrabGesture(type);
1585 #endif
1586 
1587  // force acceptDrops false before winId is destroyed.
1588  d->registerDropSite(false);
1589 
1590 #ifndef QT_NO_ACTION
1591  // remove all actions from this widget
1592  for (int i = 0; i < d->actions.size(); ++i) {
1593  QActionPrivate *apriv = d->actions.at(i)->d_func();
1594  apriv->widgets.removeAll(this);
1595  }
1596  d->actions.clear();
1597 #endif
1598 
1599 #ifndef QT_NO_SHORTCUT
1600  // Remove all shortcuts grabbed by this
1601  // widget, unless application is closing
1603  qApp->d_func()->shortcutMap.removeShortcut(0, this, QKeySequence());
1604 #endif
1605 
1606  // delete layout while we still are a valid widget
1607  delete d->layout;
1608  d->layout = 0;
1609  // Remove myself from focus list
1610 
1611  Q_ASSERT(d->focus_next->d_func()->focus_prev == this);
1612  Q_ASSERT(d->focus_prev->d_func()->focus_next == this);
1613 
1614  if (d->focus_next != this) {
1615  d->focus_next->d_func()->focus_prev = d->focus_prev;
1616  d->focus_prev->d_func()->focus_next = d->focus_next;
1617  d->focus_next = d->focus_prev = 0;
1618  }
1619 
1620 #ifdef QT3_SUPPORT
1621  if (QApplicationPrivate::main_widget == this) { // reset main widget
1624  }
1625 #endif
1626 
1627  QT_TRY {
1628  clearFocus();
1629  } QT_CATCH(...) {
1630  // swallow this problem because we are in a destructor
1631  }
1632 
1633  d->setDirtyOpaqueRegion();
1634 
1635  if (isWindow() && isVisible() && internalWinId()) {
1636  QT_TRY {
1637  d->close_helper(QWidgetPrivate::CloseNoEvent);
1638  } QT_CATCH(...) {
1639  // if we're out of memory, at least hide the window.
1640  QT_TRY {
1641  hide();
1642  } QT_CATCH(...) {
1643  // and if that also doesn't work, then give up
1644  }
1645  }
1646  }
1647 
1648 #if defined(Q_WS_WIN) || defined(Q_WS_X11)|| defined(Q_WS_MAC)
1649  else if (!internalWinId() && isVisible()) {
1650  qApp->d_func()->sendSyntheticEnterLeave(this);
1651  }
1652 #elif defined(Q_WS_QWS) || defined(Q_WS_QPA)
1653  else if (isVisible()) {
1654  qApp->d_func()->sendSyntheticEnterLeave(this);
1655  }
1656 #endif
1657 
1658 #ifdef Q_OS_SYMBIAN
1659  if (d->extra && d->extra->topextra && d->extra->topextra->backingStore) {
1660  // Okay, we are about to destroy the top-level window that owns
1661  // the backing store. Make sure we delete the backing store right away
1662  // before the window handle is invalid. This is important because
1663  // the backing store will delete its window surface, which may or may
1664  // not have a reference to this widget that will be used later to
1665  // notify the window it no longer has a surface.
1666  d->extra->topextra->backingStore.destroy();
1667  }
1668 #endif
1669  if (QWidgetBackingStore *bs = d->maybeBackingStore()) {
1670  bs->removeDirtyWidget(this);
1672  bs->removeStaticWidget(this);
1673  }
1674 
1675  delete d->needsFlush;
1676  d->needsFlush = 0;
1677 
1678  // set all QPointers for this object to zero
1679  if (d->hasGuards)
1681 
1682  if (d->declarativeData) {
1683  QAbstractDeclarativeData::destroyed(d->declarativeData, this);
1684  d->declarativeData = 0; // don't activate again in ~QObject
1685  }
1686 
1687 #ifdef QT_MAC_USE_COCOA
1688  // QCocoaView holds a pointer back to this widget. Clear it now
1689  // to make sure it's not followed later on. The lifetime of the
1690  // QCocoaView might exceed the lifetime of this widget in cases
1691  // where Cocoa itself holds references to it.
1692  extern void qt_mac_clearCocoaViewQWidgetPointers(QWidget *);
1693  qt_mac_clearCocoaViewQWidgetPointers(this);
1694 #endif
1695 
1696  if (!d->children.isEmpty())
1697  d->deleteChildren();
1698 
1699 #ifndef QT_NO_ACCESSIBILITY
1701 #endif
1702 
1704 
1705  QT_TRY {
1706  destroy(); // platform-dependent cleanup
1707  } QT_CATCH(...) {
1708  // if this fails we can't do anything about it but at least we are not allowed to throw.
1709  }
1711 
1712  if (QWidgetPrivate::allWidgets) // might have been deleted by ~QApplication
1713  QWidgetPrivate::allWidgets->remove(this);
1714 
1715  QT_TRY {
1717  QCoreApplication::sendEvent(this, &e);
1718  } QT_CATCH(const std::exception&) {
1719  // if this fails we can't do anything about it but at least we are not allowed to throw.
1720  }
1721 }
1722 
1723 int QWidgetPrivate::instanceCounter = 0; // Current number of widget instances
1724 int QWidgetPrivate::maxInstances = 0; // Maximum number of widget instances
1725 
1726 void QWidgetPrivate::setWinId(WId id) // set widget identifier
1727 {
1728  Q_Q(QWidget);
1729  // the user might create a widget with Qt::Desktop window
1730  // attribute (or create another QDesktopWidget instance), which
1731  // will have the same windowid (the root window id) as the
1732  // qt_desktopWidget. We should not add the second desktop widget
1733  // to the mapper.
1734  bool userDesktopWidget = qt_desktopWidget != 0 && qt_desktopWidget != q && q->windowType() == Qt::Desktop;
1735  if (mapper && data.winid && !userDesktopWidget) {
1736  mapper->remove(data.winid);
1737  }
1738 
1739  const WId oldWinId = data.winid;
1740 
1741  data.winid = id;
1742 #if defined(Q_WS_X11)
1743  hd = id; // X11: hd == ident
1744 #endif
1745  if (mapper && id && !userDesktopWidget) {
1746  mapper->insert(data.winid, q);
1747  }
1748 
1749  if(oldWinId != id) {
1752  }
1753 }
1754 
1756 {
1757  if (!extra)
1758  createExtra();
1759  if (!extra->topextra) {
1760  QTLWExtra* x = extra->topextra = new QTLWExtra;
1761  x->icon = 0;
1762  x->iconPixmap = 0;
1763  x->windowSurface = 0;
1764  x->sharedPainter = 0;
1765  x->incw = x->inch = 0;
1766  x->basew = x->baseh = 0;
1767  x->frameStrut.setCoords(0, 0, 0, 0);
1768  x->normalGeometry = QRect(0,0,-1,-1);
1769  x->savedFlags = 0;
1770  x->opacity = 255;
1771  x->posFromMove = false;
1772  x->sizeAdjusted = false;
1773  x->inTopLevelResize = false;
1774  x->inRepaint = false;
1775  x->embedded = 0;
1776 #ifdef Q_WS_MAC
1777 #ifdef QT_MAC_USE_COCOA
1778  x->wasMaximized = false;
1779 #endif // QT_MAC_USE_COCOA
1780 #endif // Q_WS_MAC
1781  createTLSysExtra();
1782 #ifdef QWIDGET_EXTRA_DEBUG
1783  static int count = 0;
1784  qDebug() << "tlextra" << ++count;
1785 #endif
1786 #if defined(Q_WS_QPA)
1787  x->platformWindow = 0;
1788  x->platformWindowFormat = QPlatformWindowFormat::defaultFormat();
1789  x->screenIndex = 0;
1790 #endif
1791  }
1792 }
1793 
1803 {
1804  if (!extra) { // if not exists
1805  extra = new QWExtra;
1806  extra->glContext = 0;
1807  extra->topextra = 0;
1808 #ifndef QT_NO_GRAPHICSVIEW
1809  extra->proxyWidget = 0;
1810 #endif
1811 #ifndef QT_NO_CURSOR
1812  extra->curs = 0;
1813 #endif
1814  extra->minw = 0;
1815  extra->minh = 0;
1816  extra->maxw = QWIDGETSIZE_MAX;
1817  extra->maxh = QWIDGETSIZE_MAX;
1818  extra->customDpiX = 0;
1819  extra->customDpiY = 0;
1820  extra->explicitMinSize = 0;
1821  extra->explicitMaxSize = 0;
1822  extra->autoFillBackground = 0;
1823  extra->nativeChildrenForced = 0;
1824  extra->inRenderWithPainter = 0;
1825  extra->hasMask = 0;
1826  createSysExtra();
1827 #ifdef QWIDGET_EXTRA_DEBUG
1828  static int count = 0;
1829  qDebug() << "extra" << ++count;
1830 #endif
1831  }
1832 }
1833 
1834 
1844 {
1845  if (extra) { // if exists
1846 #ifndef QT_NO_CURSOR
1847  delete extra->curs;
1848 #endif
1849  deleteSysExtra();
1850 #ifndef QT_NO_STYLE_STYLESHEET
1851  // dereference the stylesheet style
1852  if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(extra->style))
1853  proxy->deref();
1854 #endif
1855  if (extra->topextra) {
1856  deleteTLSysExtra();
1857  extra->topextra->backingStore.destroy();
1858  delete extra->topextra->icon;
1859  delete extra->topextra->iconPixmap;
1860 #if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
1861  delete extra->topextra->qwsManager;
1862 #endif
1863  delete extra->topextra->windowSurface;
1864  delete extra->topextra;
1865  }
1866  delete extra;
1867  // extra->xic destroyed in QWidget::destroy()
1868  extra = 0;
1869  }
1870 }
1871 
1872 /*
1873  Returns true if there are widgets above this which overlap with
1874  \a rect, which is in parent's coordinate system (same as crect).
1875 */
1876 
1878 {
1879  Q_Q(const QWidget);
1880 
1881  const QWidget *w = q;
1882  QRect r = rect;
1883  while (w) {
1884  if (w->isWindow())
1885  return false;
1886  QWidgetPrivate *pd = w->parentWidget()->d_func();
1887  bool above = false;
1888  for (int i = 0; i < pd->children.size(); ++i) {
1889  QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
1890  if (!sibling || !sibling->isVisible() || sibling->isWindow())
1891  continue;
1892  if (!above) {
1893  above = (sibling == w);
1894  continue;
1895  }
1896 
1897  if (qRectIntersects(sibling->d_func()->effectiveRectFor(sibling->data->crect), r)) {
1898  const QWExtra *siblingExtra = sibling->d_func()->extra;
1899  if (siblingExtra && siblingExtra->hasMask && !sibling->d_func()->graphicsEffect
1900  && !siblingExtra->mask.translated(sibling->data->crect.topLeft()).intersects(r)) {
1901  continue;
1902  }
1903  return true;
1904  }
1905  }
1906  w = w->parentWidget();
1907  r.translate(pd->data.crect.topLeft());
1908  }
1909  return false;
1910 }
1911 
1913 {
1914  if (paintOnScreen()) {
1915  repaint_sys(dirty);
1916  dirty = QRegion();
1917  } else if (QWidgetBackingStore *bs = maybeBackingStore()) {
1918  bs->sync();
1919  }
1920 }
1921 
1923 {
1924  if (paintOnScreen())
1925  repaint_sys(region);
1926  else if (QWidgetBackingStore *bs = maybeBackingStore()) {
1927  bs->sync(q_func(), region);
1928  }
1929 }
1930 
1932 {
1933  Q_Q(QWidget);
1934 
1935  if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->updatesEnabled())
1936  return; // nothing we can do
1937 
1938  if (enable != q->testAttribute(Qt::WA_UpdatesDisabled))
1939  return; // nothing to do
1940 
1941  q->setAttribute(Qt::WA_UpdatesDisabled, !enable);
1942  if (enable)
1943  q->update();
1944 
1946  for (int i = 0; i < children.size(); ++i) {
1947  QWidget *w = qobject_cast<QWidget *>(children.at(i));
1948  if (w && !w->isWindow() && !w->testAttribute(attribute))
1949  w->d_func()->setUpdatesEnabled_helper(enable);
1950  }
1951 }
1952 
1964 {
1965  Q_Q(QWidget);
1966  // Propagate a new inherited mask to all children.
1967 #ifndef QT_NO_GRAPHICSVIEW
1968  if (!q->parentWidget() && extra && extra->proxyWidget) {
1969  QGraphicsProxyWidget *p = extra->proxyWidget;
1970  inheritedPaletteResolveMask = p->d_func()->inheritedPaletteResolveMask | p->palette().resolve();
1971  } else
1972 #endif //QT_NO_GRAPHICSVIEW
1973  if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
1974  inheritedPaletteResolveMask = 0;
1975  }
1976  int mask = data.pal.resolve() | inheritedPaletteResolveMask;
1977 
1979  QApplication::sendEvent(q, &pc);
1980  for (int i = 0; i < children.size(); ++i) {
1981  QWidget *w = qobject_cast<QWidget*>(children.at(i));
1982  if (w && !w->testAttribute(Qt::WA_StyleSheet)
1983  && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) {
1984  QWidgetPrivate *wd = w->d_func();
1986  wd->resolvePalette();
1987  }
1988  }
1989 #if defined(QT3_SUPPORT)
1990  q->paletteChange(q->palette()); // compatibility
1991 #endif
1992 }
1993 
1994 /*
1995  Returns the widget's clipping rectangle.
1996 */
1998 {
1999  Q_Q(const QWidget);
2000  const QWidget * w = q;
2001  if (!w->isVisible())
2002  return QRect();
2003  QRect r = effectiveRectFor(q->rect());
2004  int ox = 0;
2005  int oy = 0;
2006  while (w
2007  && w->isVisible()
2008  && !w->isWindow()
2009  && w->parentWidget()) {
2010  ox -= w->x();
2011  oy -= w->y();
2012  w = w->parentWidget();
2013  r &= QRect(ox, oy, w->width(), w->height());
2014  }
2015  return r;
2016 }
2017 
2018 /*
2019  Returns the widget's clipping region (without siblings).
2020 */
2022 {
2023  Q_Q(const QWidget);
2024  if (!q->isVisible())
2025  return QRegion();
2026  QRegion r(q->rect());
2027  const QWidget * w = q;
2028  const QWidget *ignoreUpTo;
2029  int ox = 0;
2030  int oy = 0;
2031  while (w
2032  && w->isVisible()
2033  && !w->isWindow()
2034  && w->parentWidget()) {
2035  ox -= w->x();
2036  oy -= w->y();
2037  ignoreUpTo = w;
2038  w = w->parentWidget();
2039  r &= QRegion(ox, oy, w->width(), w->height());
2040 
2041  int i = 0;
2042  while(w->d_func()->children.at(i++) != static_cast<const QObject *>(ignoreUpTo))
2043  ;
2044  for ( ; i < w->d_func()->children.size(); ++i) {
2045  if(QWidget *sibling = qobject_cast<QWidget *>(w->d_func()->children.at(i))) {
2046  if(sibling->isVisible() && !sibling->isWindow()) {
2047  QRect siblingRect(ox+sibling->x(), oy+sibling->y(),
2048  sibling->width(), sibling->height());
2049  if (qRectIntersects(siblingRect, q->rect()))
2050  r -= QRegion(siblingRect);
2051  }
2052  }
2053  }
2054  }
2055  return r;
2056 }
2057 
2058 #ifndef QT_NO_GRAPHICSEFFECT
2060 {
2061  Q_Q(QWidget);
2062  QWidget *w = q;
2063  do {
2064  if (w->graphicsEffect()) {
2065  QWidgetEffectSourcePrivate *sourced =
2066  static_cast<QWidgetEffectSourcePrivate *>(w->graphicsEffect()->source()->d_func());
2067  if (!sourced->updateDueToGraphicsEffect)
2068  w->graphicsEffect()->source()->d_func()->invalidateCache();
2069  }
2070  w = w->parentWidget();
2071  } while (w);
2072 }
2073 #endif //QT_NO_GRAPHICSEFFECT
2074 
2076 {
2077  Q_Q(QWidget);
2078 
2079  dirtyOpaqueChildren = true;
2080 
2081 #ifndef QT_NO_GRAPHICSEFFECT
2082  invalidateGraphicsEffectsRecursively();
2083 #endif //QT_NO_GRAPHICSEFFECT
2084 
2085  if (q->isWindow())
2086  return;
2087 
2088  QWidget *parent = q->parentWidget();
2089  if (!parent)
2090  return;
2091 
2092  // TODO: instead of setting dirtyflag, manipulate the dirtyregion directly?
2093  QWidgetPrivate *pd = parent->d_func();
2094  if (!pd->dirtyOpaqueChildren)
2095  pd->setDirtyOpaqueRegion();
2096 }
2097 
2099 {
2100  if (!dirtyOpaqueChildren)
2101  return opaqueChildren;
2102 
2103  QWidgetPrivate *that = const_cast<QWidgetPrivate*>(this);
2104  that->opaqueChildren = QRegion();
2105 
2106  for (int i = 0; i < children.size(); ++i) {
2107  QWidget *child = qobject_cast<QWidget *>(children.at(i));
2108  if (!child || !child->isVisible() || child->isWindow())
2109  continue;
2110 
2111  const QPoint offset = child->geometry().topLeft();
2112  QWidgetPrivate *childd = child->d_func();
2113  QRegion r = childd->isOpaque ? child->rect() : childd->getOpaqueChildren();
2114  if (childd->extra && childd->extra->hasMask)
2115  r &= childd->extra->mask;
2116  if (r.isEmpty())
2117  continue;
2118  r.translate(offset);
2119  that->opaqueChildren += r;
2120  }
2121 
2122  that->opaqueChildren &= q_func()->rect();
2123  that->dirtyOpaqueChildren = false;
2124 
2125  return that->opaqueChildren;
2126 }
2127 
2128 void QWidgetPrivate::subtractOpaqueChildren(QRegion &source, const QRect &clipRect) const
2129 {
2130  if (children.isEmpty() || clipRect.isEmpty())
2131  return;
2132 
2133  const QRegion &r = getOpaqueChildren();
2134  if (!r.isEmpty())
2135  source -= (r & clipRect);
2136 }
2137 
2138 //subtract any relatives that are higher up than me --- this is too expensive !!!
2139 void QWidgetPrivate::subtractOpaqueSiblings(QRegion &sourceRegion, bool *hasDirtySiblingsAbove,
2140  bool alsoNonOpaque) const
2141 {
2142  Q_Q(const QWidget);
2143  static int disableSubtractOpaqueSiblings = qgetenv("QT_NO_SUBTRACTOPAQUESIBLINGS").toInt();
2144  if (disableSubtractOpaqueSiblings || q->isWindow())
2145  return;
2146 
2147 #ifdef QT_MAC_USE_COCOA
2148  if (q->d_func()->isInUnifiedToolbar)
2149  return;
2150 #endif // QT_MAC_USE_COCOA
2151 
2152  QRect clipBoundingRect;
2153  bool dirtyClipBoundingRect = true;
2154 
2155  QRegion parentClip;
2156  bool dirtyParentClip = true;
2157 
2158  QPoint parentOffset = data.crect.topLeft();
2159 
2160  const QWidget *w = q;
2161 
2162  while (w) {
2163  if (w->isWindow())
2164  break;
2165  QWidgetPrivate *pd = w->parentWidget()->d_func();
2166  const int myIndex = pd->children.indexOf(const_cast<QWidget *>(w));
2167  const QRect widgetGeometry = w->d_func()->effectiveRectFor(w->data->crect);
2168  for (int i = myIndex + 1; i < pd->children.size(); ++i) {
2169  QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
2170  if (!sibling || !sibling->isVisible() || sibling->isWindow())
2171  continue;
2172 
2173  const QRect siblingGeometry = sibling->d_func()->effectiveRectFor(sibling->data->crect);
2174  if (!qRectIntersects(siblingGeometry, widgetGeometry))
2175  continue;
2176 
2177  if (dirtyClipBoundingRect) {
2178  clipBoundingRect = sourceRegion.boundingRect();
2179  dirtyClipBoundingRect = false;
2180  }
2181 
2182  if (!qRectIntersects(siblingGeometry, clipBoundingRect.translated(parentOffset)))
2183  continue;
2184 
2185  if (dirtyParentClip) {
2186  parentClip = sourceRegion.translated(parentOffset);
2187  dirtyParentClip = false;
2188  }
2189 
2190  const QPoint siblingPos(sibling->data->crect.topLeft());
2191  const QRect siblingClipRect(sibling->d_func()->clipRect());
2192  QRegion siblingDirty(parentClip);
2193  siblingDirty &= (siblingClipRect.translated(siblingPos));
2194  const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask
2195  && !sibling->d_func()->graphicsEffect;
2196  if (hasMask)
2197  siblingDirty &= sibling->d_func()->extra->mask.translated(siblingPos);
2198  if (siblingDirty.isEmpty())
2199  continue;
2200 
2201  if (sibling->d_func()->isOpaque || alsoNonOpaque) {
2202  if (hasMask) {
2203  siblingDirty.translate(-parentOffset);
2204  sourceRegion -= siblingDirty;
2205  } else {
2206  sourceRegion -= siblingGeometry.translated(-parentOffset);
2207  }
2208  } else {
2209  if (hasDirtySiblingsAbove)
2210  *hasDirtySiblingsAbove = true;
2211  if (sibling->d_func()->children.isEmpty())
2212  continue;
2213  QRegion opaqueSiblingChildren(sibling->d_func()->getOpaqueChildren());
2214  opaqueSiblingChildren.translate(-parentOffset + siblingPos);
2215  sourceRegion -= opaqueSiblingChildren;
2216  }
2217  if (sourceRegion.isEmpty())
2218  return;
2219 
2220  dirtyClipBoundingRect = true;
2221  dirtyParentClip = true;
2222  }
2223 
2224  w = w->parentWidget();
2225  parentOffset += pd->data.crect.topLeft();
2226  dirtyParentClip = true;
2227  }
2228 }
2229 
2231 {
2232  Q_Q(const QWidget);
2233 
2234  const QWidget *w = q;
2235  QPoint offset;
2236 
2237 #ifndef QT_NO_GRAPHICSEFFECT
2238  if (graphicsEffect) {
2239  w = q->parentWidget();
2240  offset -= data.crect.topLeft();
2241  }
2242 #endif //QT_NO_GRAPHICSEFFECT
2243 
2244  while (w) {
2245  const QWidgetPrivate *wd = w->d_func();
2246  if (wd->extra && wd->extra->hasMask)
2247  region &= (w != q) ? wd->extra->mask.translated(offset) : wd->extra->mask;
2248  if (w->isWindow())
2249  return;
2250  offset -= wd->data.crect.topLeft();
2251  w = w->parentWidget();
2252  }
2253 }
2254 
2256 {
2257 #if defined(Q_WS_QWS)
2258  return false;
2259 #elif defined(QT_NO_BACKINGSTORE)
2260  return true;
2261 #else
2262  Q_Q(const QWidget);
2263  if (q->testAttribute(Qt::WA_PaintOnScreen)
2264  || (!q->isWindow() && q->window()->testAttribute(Qt::WA_PaintOnScreen))) {
2265  return true;
2266  }
2267 
2268  return !qt_enable_backingstore;
2269 #endif
2270 }
2271 
2273 {
2274  // hw: todo: only needed if opacity actually changed
2275  setDirtyOpaqueRegion();
2276 
2277 #ifndef QT_NO_GRAPHICSEFFECT
2278  if (graphicsEffect) {
2279  // ### We should probably add QGraphicsEffect::isOpaque at some point.
2280  setOpaque(false);
2281  return;
2282  }
2283 #endif //QT_NO_GRAPHICSEFFECT
2284 
2285  Q_Q(QWidget);
2286 #ifdef Q_WS_X11
2287  if (q->testAttribute(Qt::WA_X11OpenGLOverlay)) {
2288  setOpaque(false);
2289  return;
2290  }
2291 #endif
2292 
2293 #ifdef Q_WS_S60
2294  if (q->testAttribute(Qt::WA_TranslucentBackground)) {
2295  if (q->windowType() & Qt::Dialog || q->windowType() & Qt::Popup) {
2296  if (S60->avkonComponentsSupportTransparency) {
2297  setOpaque(false);
2298  return;
2299  }
2300  } else {
2301  setOpaque(false);
2302  return;
2303  }
2304  }
2305 #endif
2306 
2307  if (q->testAttribute(Qt::WA_OpaquePaintEvent) || q->testAttribute(Qt::WA_PaintOnScreen)) {
2308  setOpaque(true);
2309  return;
2310  }
2311 
2312  const QPalette &pal = q->palette();
2313 
2314  if (q->autoFillBackground()) {
2315  const QBrush &autoFillBrush = pal.brush(q->backgroundRole());
2316  if (autoFillBrush.style() != Qt::NoBrush && autoFillBrush.isOpaque()) {
2317  setOpaque(true);
2318  return;
2319  }
2320  }
2321 
2322  if (q->isWindow() && !q->testAttribute(Qt::WA_NoSystemBackground)) {
2323 #ifdef Q_WS_S60
2324  setOpaque(true);
2325  return;
2326 #else
2327  const QBrush &windowBrush = q->palette().brush(QPalette::Window);
2328  if (windowBrush.style() != Qt::NoBrush && windowBrush.isOpaque()) {
2329  setOpaque(true);
2330  return;
2331  }
2332 #endif
2333  }
2334  setOpaque(false);
2335 }
2336 
2337 void QWidgetPrivate::setOpaque(bool opaque)
2338 {
2339  if (isOpaque == opaque)
2340  return;
2341  isOpaque = opaque;
2342 #ifdef Q_WS_MAC
2343  macUpdateIsOpaque();
2344 #endif
2345 #ifdef Q_WS_X11
2346  x11UpdateIsOpaque();
2347 #endif
2348 #ifdef Q_WS_WIN
2349  winUpdateIsOpaque();
2350 #endif
2351 #ifdef Q_OS_SYMBIAN
2352  s60UpdateIsOpaque();
2353 #endif
2354 }
2355 
2357 {
2358 #ifdef Q_WS_MAC
2359  macUpdateIsOpaque();
2360 #endif
2361 #ifdef Q_WS_X11
2362  x11UpdateIsOpaque();
2363 #endif
2364 #ifdef Q_WS_WIN
2365  winUpdateIsOpaque();
2366 #endif
2367 #ifdef Q_OS_SYMBIAN
2368  s60UpdateIsOpaque();
2369 #endif
2370 }
2371 
2385 void QPixmap::fill( const QWidget *widget, const QPoint &off )
2386 {
2387  QPainter p(this);
2388  p.translate(-off);
2389  widget->d_func()->paintBackground(&p, QRect(off, size()));
2390 }
2391 
2392 static inline void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush)
2393 {
2394  Q_ASSERT(painter);
2395 
2396  if (brush.style() == Qt::TexturePattern) {
2397 #ifdef Q_WS_MAC
2398  // Optimize pattern filling on mac by using HITheme directly
2399  // when filling with the standard widget background.
2400  // Defined in qmacstyle_mac.cpp
2401  extern void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush);
2402  qt_mac_fill_background(painter, rgn, brush);
2403 #else
2404 #if !defined(QT_NO_STYLE_S60)
2405  // Defined in qs60style.cpp
2406  extern bool qt_s60_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush);
2407  if (!qt_s60_fill_background(painter, rgn, brush))
2408 #endif // !defined(QT_NO_STYLE_S60)
2409  {
2410  const QRect rect(rgn.boundingRect());
2411  painter->setClipRegion(rgn);
2412  painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());
2413  }
2414 #endif // Q_WS_MAC
2415 
2416  } else if (brush.gradient()
2418  painter->save();
2419  painter->setClipRegion(rgn);
2420  painter->fillRect(0, 0, painter->device()->width(), painter->device()->height(), brush);
2421  painter->restore();
2422  } else {
2423  const QVector<QRect> &rects = rgn.rects();
2424  for (int i = 0; i < rects.size(); ++i)
2425  painter->fillRect(rects.at(i), brush);
2426  }
2427 }
2428 
2429 void QWidgetPrivate::paintBackground(QPainter *painter, const QRegion &rgn, int flags) const
2430 {
2431  Q_Q(const QWidget);
2432 
2433 #ifndef QT_NO_SCROLLAREA
2434  bool resetBrushOrigin = false;
2435  QPointF oldBrushOrigin;
2436  //If we are painting the viewport of a scrollarea, we must apply an offset to the brush in case we are drawing a texture
2438  if (scrollArea && scrollArea->viewport() == q) {
2439  QObjectData *scrollPrivate = static_cast<QWidget *>(scrollArea)->d_ptr.data();
2440  QAbstractScrollAreaPrivate *priv = static_cast<QAbstractScrollAreaPrivate *>(scrollPrivate);
2441  oldBrushOrigin = painter->brushOrigin();
2442  resetBrushOrigin = true;
2443  painter->setBrushOrigin(-priv->contentsOffset());
2444 
2445  }
2446 #endif // QT_NO_SCROLLAREA
2447 
2448  const QBrush autoFillBrush = q->palette().brush(q->backgroundRole());
2449 
2450  if ((flags & DrawAsRoot) && !(q->autoFillBackground() && autoFillBrush.isOpaque())) {
2451  const QBrush bg = q->palette().brush(QPalette::Window);
2452 #if defined(Q_WS_QWS) || defined(Q_WS_QPA)
2453  if (!(flags & DontSetCompositionMode)) {
2454  //copy alpha straight in
2455  QPainter::CompositionMode oldMode = painter->compositionMode();
2457  fillRegion(painter, rgn, bg);
2458  painter->setCompositionMode(oldMode);
2459  } else {
2460  fillRegion(painter, rgn, bg);
2461  }
2462 #else
2463  fillRegion(painter, rgn, bg);
2464 #endif
2465  }
2466 
2467  if (q->autoFillBackground())
2468  fillRegion(painter, rgn, autoFillBrush);
2469 
2470  if (q->testAttribute(Qt::WA_StyledBackground)) {
2471  painter->setClipRegion(rgn);
2472  QStyleOption opt;
2473  opt.initFrom(q);
2474  q->style()->drawPrimitive(QStyle::PE_Widget, &opt, painter, q);
2475  }
2476 
2477 #ifndef QT_NO_SCROLLAREA
2478  if (resetBrushOrigin)
2479  painter->setBrushOrigin(oldBrushOrigin);
2480 #endif // QT_NO_SCROLLAREA
2481 }
2482 
2483 /*
2484  \internal
2485  This function is called when a widget is hidden or destroyed.
2486  It resets some application global pointers that should only refer active,
2487  visible widgets.
2488 */
2489 
2490 #ifdef Q_WS_MAC
2492 #else
2493  extern QWidget *qt_button_down;
2494 #endif
2495 
2497 {
2498  Q_Q(QWidget);
2499  // If this was the active application window, reset it
2500  if (QApplication::activeWindow() == q)
2502  // If the is the active mouse press widget, reset it
2503  if (q == qt_button_down)
2504  qt_button_down = 0;
2505 }
2506 
2507 
2518 {
2519  return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0;
2520 }
2521 
2522 
2523 
2558 {
2560 #ifdef ALIEN_DEBUG
2561  qDebug() << "QWidget::winId: creating native window for" << this;
2562 #endif
2563  QWidget *that = const_cast<QWidget*>(this);
2564 #ifndef Q_WS_QPA
2566 #endif
2567  that->d_func()->createWinId();
2568  return that->data->winid;
2569  }
2570  return data->winid;
2571 }
2572 
2573 
2575 {
2576  Q_Q(QWidget);
2577 
2578 #ifdef ALIEN_DEBUG
2579  qDebug() << "QWidgetPrivate::createWinId for" << q << winid;
2580 #endif
2581  const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow);
2582  if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) {
2583 #ifndef Q_WS_QPA
2584  if (!q->isWindow()) {
2585  QWidget *parent = q->parentWidget();
2586  QWidgetPrivate *pd = parent->d_func();
2587  if (forceNativeWindow && !q->testAttribute(Qt::WA_DontCreateNativeAncestors))
2589  if (!parent->internalWinId()) {
2590  pd->createWinId();
2591  }
2592 
2593  for (int i = 0; i < pd->children.size(); ++i) {
2594  QWidget *w = qobject_cast<QWidget *>(pd->children.at(i));
2595  if (w && !w->isWindow() && (!w->testAttribute(Qt::WA_WState_Created)
2596  || (!w->internalWinId() && w->testAttribute(Qt::WA_NativeWindow)))) {
2597  if (w!=q) {
2598  w->create();
2599  } else {
2600  w->create(winid);
2601  // if the window has already been created, we
2602  // need to raise it to its proper stacking position
2603  if (winid)
2604  w->raise();
2605  }
2606  }
2607  }
2608  } else {
2609  q->create();
2610  }
2611 #else
2612  Q_UNUSED(winid);
2613  q->create();
2614 #endif //Q_WS_QPA
2615 
2616  }
2617 }
2618 
2619 
2627 {
2628  Q_D(QWidget);
2629 #ifdef ALIEN_DEBUG
2630  qDebug() << "QWidget::createWinId" << this;
2631 #endif
2632 // qWarning("QWidget::createWinId is obsolete, please fix your code.");
2633  d->createWinId();
2634 }
2635 
2655 {
2656  WId id = internalWinId();
2658  return id;
2659  QWidget *realParent = nativeParentWidget();
2660  if (!realParent && d_func()->inSetParent) {
2661  // In transitional state. This is really just a workaround. The real problem
2662  // is that QWidgetPrivate::setParent_sys (platform specific code) first sets
2663  // the window id to 0 (setWinId(0)) before it sets the Qt::WA_WState_Created
2664  // attribute to false. The correct way is to do it the other way around, and
2665  // in that case the Qt::WA_WState_Created logic above will kick in and
2666  // return 0 whenever the widget is in a transitional state. However, changing
2667  // the original logic for all platforms is far more intrusive and might
2668  // break existing applications.
2669  // Note: The widget can only be in a transitional state when changing its
2670  // parent -- everything else is an internal error -- hence explicitly checking
2671  // against 'inSetParent' rather than doing an unconditional return whenever
2672  // 'realParent' is 0 (which may cause strange artifacts and headache later).
2673  return 0;
2674  }
2675  // This widget *must* have a native parent widget.
2676  Q_ASSERT(realParent);
2677  Q_ASSERT(realParent->internalWinId());
2678  return realParent->internalWinId();
2679 }
2680 
2681 #ifndef QT_NO_STYLE_STYLESHEET
2682 
2702 {
2703  Q_D(const QWidget);
2704  if (!d->extra)
2705  return QString();
2706  return d->extra->styleSheet;
2707 }
2708 
2710 {
2711  Q_D(QWidget);
2712  d->createExtra();
2713 
2714  QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(d->extra->style);
2715  d->extra->styleSheet = styleSheet;
2716  if (styleSheet.isEmpty()) { // stylesheet removed
2717  if (!proxy)
2718  return;
2719 
2720  d->inheritStyle();
2721  return;
2722  }
2723 
2724  if (proxy) { // style sheet update
2725  proxy->repolish(this);
2726  return;
2727  }
2728 
2730  d->setStyle_helper(new QStyleSheetStyle(d->extra->style), true);
2731  } else {
2732  d->setStyle_helper(new QStyleSheetStyle(0), true);
2733  }
2734 }
2735 
2736 #endif // QT_NO_STYLE_STYLESHEET
2737 
2743 {
2744  Q_D(const QWidget);
2745 
2746  if (d->extra && d->extra->style)
2747  return d->extra->style;
2748  return QApplication::style();
2749 }
2750 
2773 {
2774  Q_D(QWidget);
2775  setAttribute(Qt::WA_SetStyle, style != 0);
2776  d->createExtra();
2777 #ifndef QT_NO_STYLE_STYLESHEET
2778  if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(style)) {
2779  //if for some reason someone try to set a QStyleSheetStyle, ref it
2780  //(this may happen for exemple in QButtonDialogBox which propagates its style)
2781  proxy->ref();
2782  d->setStyle_helper(style, false);
2783  } else if (qobject_cast<QStyleSheetStyle *>(d->extra->style) || !qApp->styleSheet().isEmpty()) {
2784  // if we have an application stylesheet or have a proxy already, propagate
2785  d->setStyle_helper(new QStyleSheetStyle(style), true);
2786  } else
2787 #endif
2788  d->setStyle_helper(style, false);
2789 }
2790 
2791 void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate, bool
2792 #ifdef Q_WS_MAC
2793  metalHack
2794 #endif
2795  )
2796 {
2797  Q_Q(QWidget);
2798  QStyle *oldStyle = q->style();
2799 #ifndef QT_NO_STYLE_STYLESHEET
2800  QWeakPointer<QStyle> origStyle;
2801 #endif
2802 
2803 #ifdef Q_WS_MAC
2804  // the metalhack boolean allows Qt/Mac to do a proper re-polish depending
2805  // on how the Qt::WA_MacBrushedMetal attribute is set. It is only ever
2806  // set when changing that attribute and passes the widget's CURRENT style.
2807  // therefore no need to do a reassignment.
2808  if (!metalHack)
2809 #endif
2810  {
2811  createExtra();
2812 
2813 #ifndef QT_NO_STYLE_STYLESHEET
2814  origStyle = extra->style.data();
2815 #endif
2816  extra->style = newStyle;
2817  }
2818 
2819  // repolish
2820  if (q->windowType() != Qt::Desktop) {
2821  if (polished) {
2822  oldStyle->unpolish(q);
2823 #ifdef Q_WS_MAC
2824  if (metalHack)
2825  macUpdateMetalAttribute();
2826 #endif
2827  q->style()->polish(q);
2828 #ifdef Q_WS_MAC
2829  } else if (metalHack) {
2830  macUpdateMetalAttribute();
2831 #endif
2832  }
2833  }
2834 
2835  if (propagate) {
2836  for (int i = 0; i < children.size(); ++i) {
2838  if (c)
2839  c->d_func()->inheritStyle();
2840  }
2841  }
2842 
2843 #ifndef QT_NO_STYLE_STYLESHEET
2844  if (!qobject_cast<QStyleSheetStyle*>(newStyle)) {
2845  if (const QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(origStyle.data())) {
2846  cssStyle->clearWidgetFont(q);
2847  }
2848  }
2849 #endif
2850 
2852  QApplication::sendEvent(q, &e);
2853 #ifdef QT3_SUPPORT
2854  q->styleChange(*oldStyle);
2855 #endif
2856 
2857 #ifndef QT_NO_STYLE_STYLESHEET
2858  // dereference the old stylesheet style
2859  if (QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle *>(origStyle.data()))
2860  proxy->deref();
2861 #endif
2862 }
2863 
2864 // Inherits style from the current parent and propagates it as necessary
2866 {
2867 #ifndef QT_NO_STYLE_STYLESHEET
2868  Q_Q(QWidget);
2869 
2870  QStyleSheetStyle *proxy = extra ? qobject_cast<QStyleSheetStyle *>(extra->style) : 0;
2871 
2872  if (!q->styleSheet().isEmpty()) {
2873  Q_ASSERT(proxy);
2874  proxy->repolish(q);
2875  return;
2876  }
2877 
2878  QStyle *origStyle = proxy ? proxy->base : (extra ? (QStyle*)extra->style : 0);
2879  QWidget *parent = q->parentWidget();
2880  QStyle *parentStyle = (parent && parent->d_func()->extra) ? (QStyle*)parent->d_func()->extra->style : 0;
2881  // If we have stylesheet on app or parent has stylesheet style, we need
2882  // to be running a proxy
2883  if (!qApp->styleSheet().isEmpty() || qobject_cast<QStyleSheetStyle *>(parentStyle)) {
2884  QStyle *newStyle = parentStyle;
2885  if (q->testAttribute(Qt::WA_SetStyle))
2886  newStyle = new QStyleSheetStyle(origStyle);
2887  else if (QStyleSheetStyle *newProxy = qobject_cast<QStyleSheetStyle *>(parentStyle))
2888  newProxy->ref();
2889 
2890  setStyle_helper(newStyle, true);
2891  return;
2892  }
2893 
2894  // So, we have no stylesheet on parent/app and we have an empty stylesheet
2895  // we just need our original style back
2896  if (origStyle == (extra ? (QStyle*)extra->style : 0)) // is it any different?
2897  return;
2898 
2899  // We could have inherited the proxy from our parent (which has a custom style)
2900  // In such a case we need to start following the application style (i.e revert
2901  // the propagation behavior of QStyleSheetStyle)
2902  if (!q->testAttribute(Qt::WA_SetStyle))
2903  origStyle = 0;
2904 
2905  setStyle_helper(origStyle, true);
2906 #endif // QT_NO_STYLE_STYLESHEET
2907 }
2908 
2909 #ifdef QT3_SUPPORT
2910 
2919 {
2920  QStyle *s = QStyleFactory::create(style);
2921  setStyle(s);
2922  return s;
2923 }
2924 #endif
2925 
2987 {
2988  return static_cast<Qt::WindowModality>(data->window_modality);
2989 }
2990 
2992 {
2994  // setModal_sys() will be called by setAttribute()
2997 }
2998 
3028 { return data->window_state & Qt::WindowMinimized; }
3029 
3039 {
3040  bool isMin = isMinimized();
3041  if (isMin && isVisible())
3042  return;
3043 
3044  ensurePolished();
3045 #ifdef QT3_SUPPORT
3046  if (parent())
3047  QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
3048 #endif
3049 
3050  if (!isMin)
3052  show();
3053 }
3054 
3075 { return data->window_state & Qt::WindowMaximized; }
3076 
3077 
3078 
3086 Qt::WindowStates QWidget::windowState() const
3087 {
3088  return Qt::WindowStates(data->window_state);
3089 }
3090 
3098 void QWidget::overrideWindowState(Qt::WindowStates newstate)
3099 {
3100  QWindowStateChangeEvent e(Qt::WindowStates(data->window_state), true);
3101  data->window_state = newstate;
3102  QApplication::sendEvent(this, &e);
3103 }
3104 
3154 { return data->window_state & Qt::WindowFullScreen; }
3155 
3186 {
3187 #ifdef Q_WS_MAC
3188  // If the unified toolbar is enabled, we have to disable it before going fullscreen.
3189  QMainWindow *mainWindow = qobject_cast<QMainWindow*>(this);
3190  if (mainWindow && mainWindow->unifiedTitleAndToolBarOnMac()) {
3191  mainWindow->setUnifiedTitleAndToolBarOnMac(false);
3192  QMainWindowLayout *mainLayout = qobject_cast<QMainWindowLayout*>(mainWindow->layout());
3193  mainLayout->activateUnifiedToolbarAfterFullScreen = true;
3194  }
3195 #endif // Q_WS_MAC
3196  ensurePolished();
3197 #ifdef QT3_SUPPORT
3198  if (parent())
3199  QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
3200 #endif
3201 
3204  show();
3205  activateWindow();
3206 }
3207 
3219 {
3220  ensurePolished();
3221 #ifdef QT3_SUPPORT
3222  if (parent())
3223  QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
3224 #endif
3225 
3228 #ifdef Q_WS_MAC
3229  // If the unified toolbar was enabled before going fullscreen, we have to enable it back.
3230  QMainWindow *mainWindow = qobject_cast<QMainWindow*>(this);
3231  if (mainWindow)
3232  {
3233  QMainWindowLayout *mainLayout = qobject_cast<QMainWindowLayout*>(mainWindow->layout());
3234  if (mainLayout->activateUnifiedToolbarAfterFullScreen) {
3235  mainWindow->setUnifiedTitleAndToolBarOnMac(true);
3236  mainLayout->activateUnifiedToolbarAfterFullScreen = false;
3237  }
3238  }
3239 #endif // Q_WS_MAC
3240  show();
3241 }
3242 
3251 {
3252  ensurePolished();
3253 #ifdef QT3_SUPPORT
3254  if (parent())
3255  QApplication::sendPostedEvents(parent(), QEvent::ChildInserted);
3256 #endif
3257 
3261 #ifdef Q_WS_MAC
3262  // If the unified toolbar was enabled before going fullscreen, we have to enable it back.
3263  QMainWindow *mainWindow = qobject_cast<QMainWindow*>(this);
3264  if (mainWindow)
3265  {
3266  QMainWindowLayout *mainLayout = qobject_cast<QMainWindowLayout*>(mainWindow->layout());
3267  if (mainLayout->activateUnifiedToolbarAfterFullScreen) {
3268  mainWindow->setUnifiedTitleAndToolBarOnMac(true);
3269  mainLayout->activateUnifiedToolbarAfterFullScreen = false;
3270  }
3271  }
3272 #endif // Q_WS_MAC
3273  show();
3274 }
3275 
3290 bool QWidget::isEnabledTo(QWidget* ancestor) const
3291 {
3292  const QWidget * w = this;
3294  && !w->isWindow()
3295  && w->parentWidget()
3296  && w->parentWidget() != ancestor)
3297  w = w->parentWidget();
3298  return !w->testAttribute(Qt::WA_ForceDisabled);
3299 }
3300 
3301 #ifndef QT_NO_ACTION
3302 
3318 {
3319  insertAction(0, action);
3320 }
3321 
3328 {
3329  for(int i = 0; i < actions.count(); i++)
3330  insertAction(0, actions.at(i));
3331 }
3332 
3342 void QWidget::insertAction(QAction *before, QAction *action)
3343 {
3344  if(!action) {
3345  qWarning("QWidget::insertAction: Attempt to insert null action");
3346  return;
3347  }
3348 
3349  Q_D(QWidget);
3350  if(d->actions.contains(action))
3351  removeAction(action);
3352 
3353  int pos = d->actions.indexOf(before);
3354  if (pos < 0) {
3355  before = 0;
3356  pos = d->actions.size();
3357  }
3358  d->actions.insert(pos, action);
3359 
3360  QActionPrivate *apriv = action->d_func();
3361  apriv->widgets.append(this);
3362 
3363  QActionEvent e(QEvent::ActionAdded, action, before);
3364  QApplication::sendEvent(this, &e);
3365 }
3366 
3377 {
3378  for(int i = 0; i < actions.count(); ++i)
3379  insertAction(before, actions.at(i));
3380 }
3381 
3387 {
3388  if (!action)
3389  return;
3390 
3391  Q_D(QWidget);
3392 
3393  QActionPrivate *apriv = action->d_func();
3394  apriv->widgets.removeAll(this);
3395 
3396  if (d->actions.removeAll(action)) {
3398  QApplication::sendEvent(this, &e);
3399  }
3400 }
3401 
3408 {
3409  Q_D(const QWidget);
3410  return d->actions;
3411 }
3412 #endif // QT_NO_ACTION
3413 
3447 void QWidget::setEnabled(bool enable)
3448 {
3449  Q_D(QWidget);
3451  d->setEnabled_helper(enable);
3452 }
3453 
3455 {
3456  Q_Q(QWidget);
3457 
3458  if (enable && !q->isWindow() && q->parentWidget() && !q->parentWidget()->isEnabled())
3459  return; // nothing we can do
3460 
3461  if (enable != q->testAttribute(Qt::WA_Disabled))
3462  return; // nothing to do
3463 
3464  q->setAttribute(Qt::WA_Disabled, !enable);
3465  updateSystemBackground();
3466 
3467  if (!enable && q->window()->focusWidget() == q) {
3468  bool parentIsEnabled = (!q->parentWidget() || q->parentWidget()->isEnabled());
3469  if (!parentIsEnabled || !q->focusNextChild())
3470  q->clearFocus();
3471  }
3472 
3474  for (int i = 0; i < children.size(); ++i) {
3475  QWidget *w = qobject_cast<QWidget *>(children.at(i));
3476  if (w && !w->testAttribute(attribute))
3477  w->d_func()->setEnabled_helper(enable);
3478  }
3479 #if defined(Q_WS_X11)
3480  if (q->testAttribute(Qt::WA_SetCursor) || q->isWindow()) {
3481  // enforce the windows behavior of clearing the cursor on
3482  // disabled widgets
3484  }
3485 #endif
3486 #if defined(Q_WS_MAC)
3487  setEnabled_helper_sys(enable);
3488 #endif
3489 #ifndef QT_NO_IM
3490  if (q->testAttribute(Qt::WA_InputMethodEnabled) && q->hasFocus()) {
3491  QWidget *focusWidget = effectiveFocusWidget();
3492  QInputContext *qic = focusWidget->d_func()->inputContext();
3493  if (enable) {
3494  if (focusWidget->testAttribute(Qt::WA_InputMethodEnabled))
3495  qic->setFocusWidget(focusWidget);
3496  } else {
3497  qic->reset();
3498  qic->setFocusWidget(0);
3499  }
3500  }
3501 #endif //QT_NO_IM
3503  QApplication::sendEvent(q, &e);
3504 #ifdef QT3_SUPPORT
3505  q->enabledChange(!enable); // compatibility
3506 #endif
3507 }
3508 
3529 bool QWidget::acceptDrops() const
3530 {
3532 }
3533 
3535 {
3537 
3538 }
3539 
3589 void QWidget::setDisabled(bool disable)
3590 {
3591  setEnabled(!disable);
3592 }
3593 
3611 {
3612  Q_D(const QWidget);
3613  if (isWindow() && ! (windowType() == Qt::Popup)) {
3614  QRect fs = d->frameStrut();
3615  return QRect(data->crect.x() - fs.left(),
3616  data->crect.y() - fs.top(),
3617  data->crect.width() + fs.left() + fs.right(),
3618  data->crect.height() + fs.top() + fs.bottom());
3619  }
3620  return data->crect;
3621 }
3622 
3639 int QWidget::x() const
3640 {
3641  Q_D(const QWidget);
3642  if (isWindow() && ! (windowType() == Qt::Popup))
3643  return data->crect.x() - d->frameStrut().left();
3644  return data->crect.x();
3645 }
3646 
3662 int QWidget::y() const
3663 {
3664  Q_D(const QWidget);
3665  if (isWindow() && ! (windowType() == Qt::Popup))
3666  return data->crect.y() - d->frameStrut().top();
3667  return data->crect.y();
3668 }
3669 
3696 QPoint QWidget::pos() const
3697 {
3698  Q_D(const QWidget);
3699  if (isWindow() && ! (windowType() == Qt::Popup)) {
3700  QRect fs = d->frameStrut();
3701  return QPoint(data->crect.x() - fs.left(), data->crect.y() - fs.top());
3702  }
3703  return data->crect.topLeft();
3704 }
3705 
3838 {
3839  Q_D(const QWidget);
3840  if (!d->extra || !d->extra->topextra)
3841  return QRect();
3842 
3843  if (!isMaximized() && !isFullScreen())
3844  return geometry();
3845 
3846  return d->topData()->normalGeometry;
3847 }
3848 
3849 
3866 {
3867  Q_D(const QWidget);
3868  QRect r(0, 0, 0, 0);
3869  for (int i = 0; i < d->children.size(); ++i) {
3870  QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
3871  if (w && !w->isWindow() && !w->isHidden())
3872  r |= w->geometry();
3873  }
3874  return r;
3875 }
3876 
3893 {
3894  Q_D(const QWidget);
3895  QRegion r;
3896  for (int i = 0; i < d->children.size(); ++i) {
3897  QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
3898  if (w && !w->isWindow() && !w->isHidden()) {
3899  QRegion mask = w->mask();
3900  if (mask.isEmpty())
3901  r |= w->geometry();
3902  else
3903  r |= mask.translated(w->pos());
3904  }
3905  }
3906  return r;
3907 }
3908 
3909 
3931 {
3932  Q_D(const QWidget);
3933  return d->extra ? QSize(d->extra->minw, d->extra->minh) : QSize(0, 0);
3934 }
3935 
3956 {
3957  Q_D(const QWidget);
3958  return d->extra ? QSize(d->extra->maxw, d->extra->maxh)
3960 }
3961 
3962 
4050 {
4051  Q_D(const QWidget);
4052  return (d->extra && d->extra->topextra)
4053  ? QSize(d->extra->topextra->incw, d->extra->topextra->inch)
4054  : QSize(0, 0);
4055 }
4056 
4073 QSize QWidget::baseSize() const
4074 {
4075  Q_D(const QWidget);
4076  return (d->extra != 0 && d->extra->topextra != 0)
4077  ? QSize(d->extra->topextra->basew, d->extra->topextra->baseh)
4078  : QSize(0, 0);
4079 }
4080 
4081 bool QWidgetPrivate::setMinimumSize_helper(int &minw, int &minh)
4082 {
4083  Q_Q(QWidget);
4084 
4085 #ifdef Q_WS_QWS
4086  if (q->isWindow()) {
4087  const QRect maxWindowRect = QApplication::desktop()->availableGeometry(QApplication::desktop()->screenNumber(q));
4088  if (!maxWindowRect.isEmpty()) {
4089  // ### This is really just a work-around. Layout shouldn't be
4090  // asking for minimum sizes bigger than the screen.
4091  if (minw > maxWindowRect.width())
4092  minw = maxWindowRect.width();
4093  if (minh > maxWindowRect.height())
4094  minh = maxWindowRect.height();
4095  }
4096  }
4097 #endif
4098  int mw = minw, mh = minh;
4099  if (mw == QWIDGETSIZE_MAX)
4100  mw = 0;
4101  if (mh == QWIDGETSIZE_MAX)
4102  mh = 0;
4103  if (minw > QWIDGETSIZE_MAX || minh > QWIDGETSIZE_MAX) {
4104  qWarning("QWidget::setMinimumSize: (%s/%s) "
4105  "The largest allowed size is (%d,%d)",
4106  q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
4107  QWIDGETSIZE_MAX);
4108  minw = mw = qMin<int>(minw, QWIDGETSIZE_MAX);
4109  minh = mh = qMin<int>(minh, QWIDGETSIZE_MAX);
4110  }
4111  if (minw < 0 || minh < 0) {
4112  qWarning("QWidget::setMinimumSize: (%s/%s) Negative sizes (%d,%d) "
4113  "are not possible",
4114  q->objectName().toLocal8Bit().data(), q->metaObject()->className(), minw, minh);
4115  minw = mw = qMax(minw, 0);
4116  minh = mh = qMax(minh, 0);
4117  }
4118  createExtra();
4119  if (extra->minw == mw && extra->minh == mh)
4120  return false;
4121  extra->minw = mw;
4122  extra->minh = mh;
4123  extra->explicitMinSize = (mw ? Qt::Horizontal : 0) | (mh ? Qt::Vertical : 0);
4124  return true;
4125 }
4126 
4138 void QWidget::setMinimumSize(int minw, int minh)
4139 {
4140  Q_D(QWidget);
4141  if (!d->setMinimumSize_helper(minw, minh))
4142  return;
4143 
4144  if (isWindow())
4145  d->setConstraints_sys();
4146  if (minw > width() || minh > height()) {
4147  bool resized = testAttribute(Qt::WA_Resized);
4148  bool maximized = isMaximized();
4149  resize(qMax(minw,width()), qMax(minh,height()));
4150  setAttribute(Qt::WA_Resized, resized); //not a user resize
4151  if (maximized)
4153  }
4154 #ifndef QT_NO_GRAPHICSVIEW
4155  if (d->extra) {
4156  if (d->extra->proxyWidget)
4157  d->extra->proxyWidget->setMinimumSize(minw, minh);
4158  }
4159 #endif
4160  d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh);
4161 }
4162 
4163 bool QWidgetPrivate::setMaximumSize_helper(int &maxw, int &maxh)
4164 {
4165  Q_Q(QWidget);
4166  if (maxw > QWIDGETSIZE_MAX || maxh > QWIDGETSIZE_MAX) {
4167  qWarning("QWidget::setMaximumSize: (%s/%s) "
4168  "The largest allowed size is (%d,%d)",
4169  q->objectName().toLocal8Bit().data(), q->metaObject()->className(), QWIDGETSIZE_MAX,
4170  QWIDGETSIZE_MAX);
4171  maxw = qMin<int>(maxw, QWIDGETSIZE_MAX);
4172  maxh = qMin<int>(maxh, QWIDGETSIZE_MAX);
4173  }
4174  if (maxw < 0 || maxh < 0) {
4175  qWarning("QWidget::setMaximumSize: (%s/%s) Negative sizes (%d,%d) "
4176  "are not possible",
4177  q->objectName().toLocal8Bit().data(), q->metaObject()->className(), maxw, maxh);
4178  maxw = qMax(maxw, 0);
4179  maxh = qMax(maxh, 0);
4180  }
4181  createExtra();
4182  if (extra->maxw == maxw && extra->maxh == maxh)
4183  return false;
4184  extra->maxw = maxw;
4185  extra->maxh = maxh;
4186  extra->explicitMaxSize = (maxw != QWIDGETSIZE_MAX ? Qt::Horizontal : 0) |
4187  (maxh != QWIDGETSIZE_MAX ? Qt::Vertical : 0);
4188  return true;
4189 }
4190 
4201 void QWidget::setMaximumSize(int maxw, int maxh)
4202 {
4203  Q_D(QWidget);
4204  if (!d->setMaximumSize_helper(maxw, maxh))
4205  return;
4206 
4207  if (isWindow())
4208  d->setConstraints_sys();
4209  if (maxw < width() || maxh < height()) {
4210  bool resized = testAttribute(Qt::WA_Resized);
4211  resize(qMin(maxw,width()), qMin(maxh,height()));
4212  setAttribute(Qt::WA_Resized, resized); //not a user resize
4213  }
4214 
4215 #ifndef QT_NO_GRAPHICSVIEW
4216  if (d->extra) {
4217  if (d->extra->proxyWidget)
4218  d->extra->proxyWidget->setMaximumSize(maxw, maxh);
4219  }
4220 #endif
4221 
4222  d->updateGeometry_helper(d->extra->minw == d->extra->maxw && d->extra->minh == d->extra->maxh);
4223 }
4224 
4234 void QWidget::setSizeIncrement(int w, int h)
4235 {
4236  Q_D(QWidget);
4237  d->createTLExtra();
4238  QTLWExtra* x = d->topData();
4239  if (x->incw == w && x->inch == h)
4240  return;
4241  x->incw = w;
4242  x->inch = h;
4243  if (isWindow())
4244  d->setConstraints_sys();
4245 }
4246 
4256 void QWidget::setBaseSize(int basew, int baseh)
4257 {
4258  Q_D(QWidget);
4259  d->createTLExtra();
4260  QTLWExtra* x = d->topData();
4261  if (x->basew == basew && x->baseh == baseh)
4262  return;
4263  x->basew = basew;
4264  x->baseh = baseh;
4265  if (isWindow())
4266  d->setConstraints_sys();
4267 }
4268 
4285 {
4286  setFixedSize(s.width(), s.height());
4287 }
4288 
4289 
4300 void QWidget::setFixedSize(int w, int h)
4301 {
4302  Q_D(QWidget);
4303 #ifdef Q_WS_QWS
4304  // temporary fix for 4.3.x.
4305  // Should move the embedded spesific contraints in setMinimumSize_helper into QLayout
4306  int tmpW = w;
4307  int tmpH = h;
4308  bool minSizeSet = d->setMinimumSize_helper(tmpW, tmpH);
4309 #else
4310  bool minSizeSet = d->setMinimumSize_helper(w, h);
4311 #endif
4312  bool maxSizeSet = d->setMaximumSize_helper(w, h);
4313  if (!minSizeSet && !maxSizeSet)
4314  return;
4315 
4316  if (isWindow())
4317  d->setConstraints_sys();
4318  else
4319  d->updateGeometry_helper(true);
4320 
4321  if (w != QWIDGETSIZE_MAX || h != QWIDGETSIZE_MAX)
4322  resize(w, h);
4323 }
4324 
4326 {
4327  Q_D(QWidget);
4328  d->createExtra();
4329  uint expl = d->extra->explicitMinSize | (w ? Qt::Horizontal : 0);
4331  d->extra->explicitMinSize = expl;
4332 }
4333 
4335 {
4336  Q_D(QWidget);
4337  d->createExtra();
4338  uint expl = d->extra->explicitMinSize | (h ? Qt::Vertical : 0);
4340  d->extra->explicitMinSize = expl;
4341 }
4342 
4344 {
4345  Q_D(QWidget);
4346  d->createExtra();
4347  uint expl = d->extra->explicitMaxSize | (w == QWIDGETSIZE_MAX ? 0 : Qt::Horizontal);
4349  d->extra->explicitMaxSize = expl;
4350 }
4351 
4353 {
4354  Q_D(QWidget);
4355  d->createExtra();
4356  uint expl = d->extra->explicitMaxSize | (h == QWIDGETSIZE_MAX ? 0 : Qt::Vertical);
4358  d->extra->explicitMaxSize = expl;
4359 }
4360 
4369 {
4370  Q_D(QWidget);
4371  d->createExtra();
4372  uint explMin = d->extra->explicitMinSize | Qt::Horizontal;
4373  uint explMax = d->extra->explicitMaxSize | Qt::Horizontal;
4376  d->extra->explicitMinSize = explMin;
4377  d->extra->explicitMaxSize = explMax;
4378 }
4379 
4380 
4389 {
4390  Q_D(QWidget);
4391  d->createExtra();
4392  uint explMin = d->extra->explicitMinSize | Qt::Vertical;
4393  uint explMax = d->extra->explicitMaxSize | Qt::Vertical;
4396  d->extra->explicitMinSize = explMin;
4397  d->extra->explicitMaxSize = explMax;
4398 }
4399 
4400 
4409 QPoint QWidget::mapTo(QWidget * parent, const QPoint & pos) const
4410 {
4411  QPoint p = pos;
4412  if (parent) {
4413  const QWidget * w = this;
4414  while (w != parent) {
4415  Q_ASSERT_X(w, "QWidget::mapTo(QWidget *parent, const QPoint &pos)",
4416  "parent must be in parent hierarchy");
4417  p = w->mapToParent(p);
4418  w = w->parentWidget();
4419  }
4420  }
4421  return p;
4422 }
4423 
4424 
4433 QPoint QWidget::mapFrom(QWidget * parent, const QPoint & pos) const
4434 {
4435  QPoint p(pos);
4436  if (parent) {
4437  const QWidget * w = this;
4438  while (w != parent) {
4439  Q_ASSERT_X(w, "QWidget::mapFrom(QWidget *parent, const QPoint &pos)",
4440  "parent must be in parent hierarchy");
4441 
4442  p = w->mapFromParent(p);
4443  w = w->parentWidget();
4444  }
4445  }
4446  return p;
4447 }
4448 
4449 
4460 {
4461  return pos + data->crect.topLeft();
4462 }
4463 
4474 {
4475  return pos - data->crect.topLeft();
4476 }
4477 
4478 
4493 {
4494  QWidget *w = (QWidget *)this;
4495  QWidget *p = w->parentWidget();
4496  while (!w->isWindow() && p) {
4497  w = p;
4498  p = p->parentWidget();
4499  }
4500  return w;
4501 }
4502 
4515 {
4516  QWidget *parent = parentWidget();
4517  while (parent && !parent->internalWinId())
4518  parent = parent->parentWidget();
4519  return parent;
4520 }
4521 
4528 #ifdef QT3_SUPPORT
4529 
4534 Qt::BackgroundMode QWidget::backgroundMode() const
4535 {
4537  return Qt::NoBackground;
4538  switch(backgroundRole()) {
4539  case QPalette::WindowText:
4540  return Qt::PaletteForeground;
4541  case QPalette::Button:
4542  return Qt::PaletteButton;
4543  case QPalette::Light:
4544  return Qt::PaletteLight;
4545  case QPalette::Midlight:
4546  return Qt::PaletteMidlight;
4547  case QPalette::Dark:
4548  return Qt::PaletteDark;
4549  case QPalette::Mid:
4550  return Qt::PaletteMid;
4551  case QPalette::Text:
4552  return Qt::PaletteText;
4553  case QPalette::BrightText:
4554  return Qt::PaletteBrightText;
4555  case QPalette::Base:
4556  return Qt::PaletteBase;
4557  case QPalette::Window:
4558  return Qt::PaletteBackground;
4559  case QPalette::Shadow:
4560  return Qt::PaletteShadow;
4561  case QPalette::Highlight:
4562  return Qt::PaletteHighlight;
4564  return Qt::PaletteHighlightedText;
4565  case QPalette::ButtonText:
4566  return Qt::PaletteButtonText;
4567  case QPalette::Link:
4568  return Qt::PaletteLink;
4569  case QPalette::LinkVisited:
4570  return Qt::PaletteLinkVisited;
4571  default:
4572  break;
4573  }
4574  return Qt::NoBackground;
4575 }
4576 
4588 void QWidget::setBackgroundMode(Qt::BackgroundMode m, Qt::BackgroundMode)
4589 {
4590  Q_D(QWidget);
4591  if(m == Qt::NoBackground) {
4593  return;
4594  }
4596  d->fg_role = QPalette::NoRole;
4597  QPalette::ColorRole role = d->bg_role;
4598  switch(m) {
4599  case Qt::FixedColor:
4600  case Qt::FixedPixmap:
4601  break;
4602  case Qt::PaletteForeground:
4603  role = QPalette::WindowText;
4604  break;
4605  case Qt::PaletteButton:
4606  role = QPalette::Button;
4607  break;
4608  case Qt::PaletteLight:
4609  role = QPalette::Light;
4610  break;
4611  case Qt::PaletteMidlight:
4612  role = QPalette::Midlight;
4613  break;
4614  case Qt::PaletteDark:
4615  role = QPalette::Dark;
4616  break;
4617  case Qt::PaletteMid:
4618  role = QPalette::Mid;
4619  break;
4620  case Qt::PaletteText:
4621  role = QPalette::Text;
4622  break;
4623  case Qt::PaletteBrightText:
4624  role = QPalette::BrightText;
4625  break;
4626  case Qt::PaletteBase:
4627  role = QPalette::Base;
4628  break;
4629  case Qt::PaletteBackground:
4630  role = QPalette::Window;
4631  break;
4632  case Qt::PaletteShadow:
4633  role = QPalette::Shadow;
4634  break;
4635  case Qt::PaletteHighlight:
4636  role = QPalette::Highlight;
4637  break;
4638  case Qt::PaletteHighlightedText:
4640  break;
4641  case Qt::PaletteButtonText:
4642  role = QPalette::ButtonText;
4643  break;
4644  case Qt::PaletteLink:
4645  role = QPalette::Link;
4646  break;
4647  case Qt::PaletteLinkVisited:
4648  role = QPalette::LinkVisited;
4649  break;
4650  case Qt::X11ParentRelative:
4651  d->fg_role = role = QPalette::NoRole;
4652  default:
4653  break;
4654  }
4655  setBackgroundRole(role);
4656 }
4657 
4661 QT3_SUPPORT QWidgetMapper *QWidget::wmapper() { return QWidgetPrivate::mapper; }
4662 
4663 #endif
4664 
4665 
4678 {
4679 
4680  const QWidget *w = this;
4681  do {
4682  QPalette::ColorRole role = w->d_func()->bg_role;
4683  if (role != QPalette::NoRole)
4684  return role;
4685  if (w->isWindow() || w->windowType() == Qt::SubWindow)
4686  break;
4687  w = w->parentWidget();
4688  } while (w);
4689  return QPalette::Window;
4690 }
4691 
4709 {
4710  Q_D(QWidget);
4711  d->bg_role = role;
4712  d->updateSystemBackground();
4713  d->propagatePaletteChange();
4714  d->updateIsOpaque();
4715 }
4716 
4729 {
4730  Q_D(const QWidget);
4731  QPalette::ColorRole rl = QPalette::ColorRole(d->fg_role);
4732  if (rl != QPalette::NoRole)
4733  return rl;
4735  switch (backgroundRole()) {
4736  case QPalette::Button:
4737  role = QPalette::ButtonText;
4738  break;
4739  case QPalette::Base:
4740  role = QPalette::Text;
4741  break;
4742  case QPalette::Dark:
4743  case QPalette::Shadow:
4744  role = QPalette::Light;
4745  break;
4746  case QPalette::Highlight:
4748  break;
4749  case QPalette::ToolTipBase:
4750  role = QPalette::ToolTipText;
4751  break;
4752  default:
4753  ;
4754  }
4755  return role;
4756 }
4757 
4774 {
4775  Q_D(QWidget);
4776  d->fg_role = role;
4777  d->updateSystemBackground();
4778  d->propagatePaletteChange();
4779 }
4780 
4836 const QPalette &QWidget::palette() const
4837 {
4838  if (!isEnabled()) {
4840  } else if ((!isVisible() || isActiveWindow())
4841 #if defined(Q_OS_WIN) && !defined(Q_WS_WINCE)
4842  && !QApplicationPrivate::isBlockedByModal(const_cast<QWidget *>(this))
4843 #endif
4844  ) {
4846  } else {
4847 #ifdef Q_WS_MAC
4848  extern bool qt_mac_can_clickThrough(const QWidget *); //qwidget_mac.cpp
4849  if (qt_mac_can_clickThrough(this))
4851  else
4852 #endif
4854  }
4855  return data->pal;
4856 }
4857 
4859 {
4860  Q_D(QWidget);
4861  setAttribute(Qt::WA_SetPalette, palette.resolve() != 0);
4862 
4863  // Determine which palette is inherited from this widget's ancestors and
4864  // QApplication::palette, resolve this against \a palette (attributes from
4865  // the inherited palette are copied over this widget's palette). Then
4866  // propagate this palette to this widget's children.
4867  QPalette naturalPalette = d->naturalWidgetPalette(d->inheritedPaletteResolveMask);
4868  QPalette resolvedPalette = palette.resolve(naturalPalette);
4869  d->setPalette_helper(resolvedPalette);
4870 }
4871 
4885 {
4886  Q_Q(const QWidget);
4887  QPalette naturalPalette = QApplication::palette(q);
4888  if (!q->testAttribute(Qt::WA_StyleSheet)
4889  && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation)
4890 #ifndef QT_NO_GRAPHICSVIEW
4891  || (extra && extra->proxyWidget)
4892 #endif //QT_NO_GRAPHICSVIEW
4893  )) {
4894  if (QWidget *p = q->parentWidget()) {
4895  if (!p->testAttribute(Qt::WA_StyleSheet)) {
4896  if (!naturalPalette.isCopyOf(QApplication::palette())) {
4897  QPalette inheritedPalette = p->palette();
4898  inheritedPalette.resolve(inheritedMask);
4899  naturalPalette = inheritedPalette.resolve(naturalPalette);
4900  } else {
4901  naturalPalette = p->palette();
4902  }
4903  }
4904  }
4905 #ifndef QT_NO_GRAPHICSVIEW
4906  else if (extra && extra->proxyWidget) {
4907  QPalette inheritedPalette = extra->proxyWidget->palette();
4908  inheritedPalette.resolve(inheritedMask);
4909  naturalPalette = inheritedPalette.resolve(naturalPalette);
4910  }
4911 #endif //QT_NO_GRAPHICSVIEW
4912  }
4913  naturalPalette.resolve(0);
4914  return naturalPalette;
4915 }
4928 {
4929  QPalette naturalPalette = naturalWidgetPalette(inheritedPaletteResolveMask);
4930  QPalette resolvedPalette = data.pal.resolve(naturalPalette);
4931  setPalette_helper(resolvedPalette);
4932 }
4933 
4935 {
4936  Q_Q(QWidget);
4937  if (data.pal == palette && data.pal.resolve() == palette.resolve())
4938  return;
4939  data.pal = palette;
4940  updateSystemBackground();
4941  propagatePaletteChange();
4942  updateIsOpaque();
4943  q->update();
4944  updateIsOpaque();
4945 }
4946 
4997 {
4998  Q_D(QWidget);
4999 
5000 #ifndef QT_NO_STYLE_STYLESHEET
5001  const QStyleSheetStyle* style;
5002  if (d->extra && (style = qobject_cast<const QStyleSheetStyle*>(d->extra->style))) {
5003  style->saveWidgetFont(this, font);
5004  }
5005 #endif
5006 
5007  setAttribute(Qt::WA_SetFont, font.resolve() != 0);
5008 
5009  // Determine which font is inherited from this widget's ancestors and
5010  // QApplication::font, resolve this against \a font (attributes from the
5011  // inherited font are copied over). Then propagate this font to this
5012  // widget's children.
5013  QFont naturalFont = d->naturalWidgetFont(d->inheritedFontResolveMask);
5014  QFont resolvedFont = font.resolve(naturalFont);
5015  d->setFont_helper(resolvedFont);
5016 }
5017 
5018 /*
5019  \internal
5020 
5021  Returns the font that the widget \a w inherits from its ancestors and
5022  QApplication::font. \a inheritedMask is the combination of the widget's
5023  ancestors font request masks (i.e., which attributes from the parent
5024  widget's font are implicitly imposed on this widget by the user). Note
5025  that this font does not take into account the font set on \a w itself.
5026 
5027  ### Stylesheet has a different font propagation mechanism. When a stylesheet
5028  is applied, fonts are not propagated anymore
5029 */
5031 {
5032  Q_Q(const QWidget);
5033  QFont naturalFont = QApplication::font(q);
5034  if (!q->testAttribute(Qt::WA_StyleSheet)
5035  && (!q->isWindow() || q->testAttribute(Qt::WA_WindowPropagation)
5036 #ifndef QT_NO_GRAPHICSVIEW
5037  || (extra && extra->proxyWidget)
5038 #endif //QT_NO_GRAPHICSVIEW
5039  )) {
5040  if (QWidget *p = q->parentWidget()) {
5041  if (!p->testAttribute(Qt::WA_StyleSheet)) {
5042  if (!naturalFont.isCopyOf(QApplication::font())) {
5043  QFont inheritedFont = p->font();
5044  inheritedFont.resolve(inheritedMask);
5045  naturalFont = inheritedFont.resolve(naturalFont);
5046  } else {
5047  naturalFont = p->font();
5048  }
5049  }
5050  }
5051 #ifndef QT_NO_GRAPHICSVIEW
5052  else if (extra && extra->proxyWidget) {
5053  QFont inheritedFont = extra->proxyWidget->font();
5054  inheritedFont.resolve(inheritedMask);
5055  naturalFont = inheritedFont.resolve(naturalFont);
5056  }
5057 #endif //QT_NO_GRAPHICSVIEW
5058  }
5059  naturalFont.resolve(0);
5060  return naturalFont;
5061 }
5062 
5075 {
5076  QFont naturalFont = naturalWidgetFont(inheritedFontResolveMask);
5077  QFont resolvedFont = data.fnt.resolve(naturalFont);
5078  setFont_helper(resolvedFont);
5079 }
5080 
5094 {
5095  Q_Q(QWidget);
5096 #ifndef QT_NO_STYLE_STYLESHEET
5097  const QStyleSheetStyle* cssStyle;
5098  cssStyle = extra ? qobject_cast<const QStyleSheetStyle*>(extra->style) : 0;
5099 #endif
5100 
5101 #ifdef QT3_SUPPORT
5102  QFont old = data.fnt;
5103 #endif
5104  data.fnt = QFont(font, q);
5105 #if defined(Q_WS_X11)
5106  // make sure the font set on this widget is associated with the correct screen
5107  data.fnt.x11SetScreen(xinfo.screen());
5108 #endif
5109  // Combine new mask with natural mask and propagate to children.
5110 #ifndef QT_NO_GRAPHICSVIEW
5111  if (!q->parentWidget() && extra && extra->proxyWidget) {
5112  QGraphicsProxyWidget *p = extra->proxyWidget;
5113  inheritedFontResolveMask = p->d_func()->inheritedFontResolveMask | p->font().resolve();
5114  } else
5115 #endif //QT_NO_GRAPHICSVIEW
5116  if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
5117  inheritedFontResolveMask = 0;
5118  }
5119  uint newMask = data.fnt.resolve() | inheritedFontResolveMask;
5120 
5121  for (int i = 0; i < children.size(); ++i) {
5122  QWidget *w = qobject_cast<QWidget*>(children.at(i));
5123  if (w) {
5124  if (0) {
5125 #ifndef QT_NO_STYLE_STYLESHEET
5126  } else if (w->testAttribute(Qt::WA_StyleSheet)) {
5127  // Style sheets follow a different font propagation scheme.
5128  if (cssStyle)
5129  cssStyle->updateStyleSheetFont(w);
5130 #endif
5131  } else if ((!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))) {
5132  // Propagate font changes.
5133  QWidgetPrivate *wd = w->d_func();
5134  wd->inheritedFontResolveMask = newMask;
5135  wd->resolveFont();
5136  }
5137  }
5138  }
5139 
5140 #ifndef QT_NO_STYLE_STYLESHEET
5141  if (cssStyle) {
5142  cssStyle->updateStyleSheetFont(q);
5143  }
5144 #endif
5145 
5147  QApplication::sendEvent(q, &e);
5148 #ifdef QT3_SUPPORT
5149  q->fontChange(old);
5150 #endif
5151 }
5152 
5154 {
5155  Q_Q(QWidget);
5156 
5157  if ( (direction == Qt::RightToLeft) == q->testAttribute(Qt::WA_RightToLeft))
5158  return;
5159  q->setAttribute(Qt::WA_RightToLeft, (direction == Qt::RightToLeft));
5160  if (!children.isEmpty()) {
5161  for (int i = 0; i < children.size(); ++i) {
5162  QWidget *w = qobject_cast<QWidget*>(children.at(i));
5163  if (w && !w->isWindow() && !w->testAttribute(Qt::WA_SetLayoutDirection))
5164  w->d_func()->setLayoutDirection_helper(direction);
5165  }
5166  }
5168  QApplication::sendEvent(q, &e);
5169 }
5170 
5172 {
5173  Q_Q(const QWidget);
5174  if (!q->testAttribute(Qt::WA_SetLayoutDirection))
5175  setLayoutDirection_helper(q->isWindow() ? QApplication::layoutDirection() : q->parentWidget()->layoutDirection());
5176 }
5177 
5200 {
5201  Q_D(QWidget);
5202 
5203  if (direction == Qt::LayoutDirectionAuto) {
5205  return;
5206  }
5207 
5209  d->setLayoutDirection_helper(direction);
5210 }
5211 
5213 {
5215 }
5216 
5218 {
5219  Q_D(QWidget);
5221  d->resolveLayoutDirection();
5222 }
5223 
5277 #ifndef QT_NO_CURSOR
5278 QCursor QWidget::cursor() const
5279 {
5280  Q_D(const QWidget);
5282  return (d->extra && d->extra->curs)
5283  ? *d->extra->curs
5285  if (isWindow() || !parentWidget())
5286  return QCursor(Qt::ArrowCursor);
5287  return parentWidget()->cursor();
5288 }
5289 
5291 {
5292  Q_D(QWidget);
5293 // On Mac we must set the cursor even if it is the ArrowCursor.
5294 #if !defined(Q_WS_MAC) && !defined(Q_WS_QWS)
5295  if (cursor.shape() != Qt::ArrowCursor
5296  || (d->extra && d->extra->curs))
5297 #endif
5298  {
5299  d->createExtra();
5300  QCursor *newCursor = new QCursor(cursor);
5301  delete d->extra->curs;
5302  d->extra->curs = newCursor;
5303  }
5305  d->setCursor_sys(cursor);
5306 
5308  QApplication::sendEvent(this, &event);
5309 }
5310 
5312 {
5313  Q_D(QWidget);
5314  if (d->extra) {
5315  delete d->extra->curs;
5316  d->extra->curs = 0;
5317  }
5318  if (!isWindow())
5320  d->unsetCursor_sys();
5321 
5323  QApplication::sendEvent(this, &event);
5324 }
5325 
5326 #endif
5327 
5372 void QWidget::render(QPaintDevice *target, const QPoint &targetOffset,
5373  const QRegion &sourceRegion, RenderFlags renderFlags)
5374 {
5375  d_func()->render(target, targetOffset, sourceRegion, renderFlags, false);
5376 }
5377 
5394 void QWidget::render(QPainter *painter, const QPoint &targetOffset,
5395  const QRegion &sourceRegion, RenderFlags renderFlags)
5396 {
5397  if (!painter) {
5398  qWarning("QWidget::render: Null pointer to painter");
5399  return;
5400  }
5401 
5402  if (!painter->isActive()) {
5403  qWarning("QWidget::render: Cannot render with an inactive painter");
5404  return;
5405  }
5406 
5407  const qreal opacity = painter->opacity();
5408  if (qFuzzyIsNull(opacity))
5409  return; // Fully transparent.
5410 
5411  Q_D(QWidget);
5412  const bool inRenderWithPainter = d->extra && d->extra->inRenderWithPainter;
5413  const QRegion toBePainted = !inRenderWithPainter ? d->prepareToRender(sourceRegion, renderFlags)
5414  : sourceRegion;
5415  if (toBePainted.isEmpty())
5416  return;
5417 
5418  if (!d->extra)
5419  d->createExtra();
5420  d->extra->inRenderWithPainter = true;
5421 
5422 #ifdef Q_WS_MAC
5423  d->render_helper(painter, targetOffset, toBePainted, renderFlags);
5424 #else
5425  QPaintEngine *engine = painter->paintEngine();
5426  Q_ASSERT(engine);
5427  QPaintEnginePrivate *enginePriv = engine->d_func();
5428  Q_ASSERT(enginePriv);
5429  QPaintDevice *target = engine->paintDevice();
5430  Q_ASSERT(target);
5431 
5432  // Render via a pixmap when dealing with non-opaque painters or printers.
5433  if (!inRenderWithPainter && (opacity < 1.0 || (target->devType() == QInternal::Printer))) {
5434  d->render_helper(painter, targetOffset, toBePainted, renderFlags);
5435  d->extra->inRenderWithPainter = false;
5436  return;
5437  }
5438 
5439  // Set new shared painter.
5440  QPainter *oldPainter = d->sharedPainter();
5441  d->setSharedPainter(painter);
5442 
5443  // Save current system clip, viewport and transform,
5444  const QTransform oldTransform = enginePriv->systemTransform;
5445  const QRegion oldSystemClip = enginePriv->systemClip;
5446  const QRegion oldSystemViewport = enginePriv->systemViewport;
5447 
5448  // This ensures that all painting triggered by render() is clipped to the current engine clip.
5449  if (painter->hasClipping()) {
5450  const QRegion painterClip = painter->deviceTransform().map(painter->clipRegion());
5451  enginePriv->setSystemViewport(oldSystemClip.isEmpty() ? painterClip : oldSystemClip & painterClip);
5452  } else {
5453  enginePriv->setSystemViewport(oldSystemClip);
5454  }
5455 
5456  render(target, targetOffset, toBePainted, renderFlags);
5457 
5458  // Restore system clip, viewport and transform.
5459  enginePriv->systemClip = oldSystemClip;
5460  enginePriv->setSystemViewport(oldSystemViewport);
5461  enginePriv->setSystemTransform(oldTransform);
5462 
5463  // Restore shared painter.
5464  d->setSharedPainter(oldPainter);
5465 #endif
5466 
5467  d->extra->inRenderWithPainter = false;
5468 }
5469 
5483 #ifndef QT_NO_GRAPHICSEFFECT
5485 {
5486  Q_D(const QWidget);
5487  return d->graphicsEffect;
5488 }
5489 #endif //QT_NO_GRAPHICSEFFECT
5490 
5516 #ifndef QT_NO_GRAPHICSEFFECT
5518 {
5519  Q_D(QWidget);
5520  if (d->graphicsEffect == effect)
5521  return;
5522 
5523  if (d->graphicsEffect) {
5524  d->invalidateBuffer(rect());
5525  delete d->graphicsEffect;
5526  d->graphicsEffect = 0;
5527  }
5528 
5529  if (effect) {
5530  // Set new effect.
5532  QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced);
5533  d->graphicsEffect = effect;
5534  effect->d_func()->setGraphicsEffectSource(source);
5535  update();
5536  }
5537 
5538  d->updateIsOpaque();
5539 }
5540 #endif //QT_NO_GRAPHICSEFFECT
5541 
5543 {
5544  if (data.in_show)
5545  return true;
5546 
5547  Q_Q(const QWidget);
5548  if (q->isHidden())
5549  return false;
5550 
5551  // The widget will be shown if any of its ancestors are about to show.
5552  QWidget *parent = q->parentWidget();
5553  return parent ? parent->d_func()->isAboutToShow() : false;
5554 }
5555 
5556 QRegion QWidgetPrivate::prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags)
5557 {
5558  Q_Q(QWidget);
5559  const bool isVisible = q->isVisible();
5560 
5561  // Make sure the widget is laid out correctly.
5562  if (!isVisible && !isAboutToShow()) {
5563  QWidget *topLevel = q->window();
5564  (void)topLevel->d_func()->topData(); // Make sure we at least have top-data.
5565  topLevel->ensurePolished();
5566 
5567  // Invalidate the layout of hidden ancestors (incl. myself) and pretend
5568  // they're not explicitly hidden.
5569  QWidget *widget = q;
5570  QWidgetList hiddenWidgets;
5571  while (widget) {
5572  if (widget->isHidden()) {
5573  widget->setAttribute(Qt::WA_WState_Hidden, false);
5574  hiddenWidgets.append(widget);
5575  if (!widget->isWindow() && widget->parentWidget()->d_func()->layout)
5576  widget->d_func()->updateGeometry_helper(true);
5577  }
5578  widget = widget->parentWidget();
5579  }
5580 
5581  // Activate top-level layout.
5582  if (topLevel->d_func()->layout)
5583  topLevel->d_func()->layout->activate();
5584 
5585  // Adjust size if necessary.
5586  QTLWExtra *topLevelExtra = topLevel->d_func()->maybeTopData();
5587  if (topLevelExtra && !topLevelExtra->sizeAdjusted
5588  && !topLevel->testAttribute(Qt::WA_Resized)) {
5589  topLevel->adjustSize();
5590  topLevel->setAttribute(Qt::WA_Resized, false);
5591  }
5592 
5593  // Activate child layouts.
5594  topLevel->d_func()->activateChildLayoutsRecursively();
5595 
5596  // We're not cheating with WA_WState_Hidden anymore.
5597  for (int i = 0; i < hiddenWidgets.size(); ++i) {
5598  QWidget *widget = hiddenWidgets.at(i);
5600  if (!widget->isWindow() && widget->parentWidget()->d_func()->layout)
5601  widget->parentWidget()->d_func()->layout->invalidate();
5602  }
5603  } else if (isVisible) {
5604  q->window()->d_func()->sendPendingMoveAndResizeEvents(true, true);
5605  }
5606 
5607  // Calculate the region to be painted.
5608  QRegion toBePainted = !region.isEmpty() ? region : QRegion(q->rect());
5609  if (!(renderFlags & QWidget::IgnoreMask) && extra && extra->hasMask)
5610  toBePainted &= extra->mask;
5611  return toBePainted;
5612 }
5613 
5614 void QWidgetPrivate::render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &toBePainted,
5615  QWidget::RenderFlags renderFlags)
5616 {
5617  Q_ASSERT(painter);
5618  Q_ASSERT(!toBePainted.isEmpty());
5619 
5620  Q_Q(QWidget);
5621 #ifndef Q_WS_MAC
5622  const QTransform originalTransform = painter->worldTransform();
5623  const bool useDeviceCoordinates = originalTransform.isScaling();
5624  if (!useDeviceCoordinates) {
5625 #endif
5626  // Render via a pixmap.
5627  const QRect rect = toBePainted.boundingRect();
5628  const QSize size = rect.size();
5629  if (size.isNull())
5630  return;
5631 
5632  QPixmap pixmap(size);
5633  if (!(renderFlags & QWidget::DrawWindowBackground) || !isOpaque)
5634  pixmap.fill(Qt::transparent);
5635  q->render(&pixmap, QPoint(), toBePainted, renderFlags);
5636 
5637  const bool restore = !(painter->renderHints() & QPainter::SmoothPixmapTransform);
5639 
5640  painter->drawPixmap(targetOffset, pixmap);
5641 
5642  if (restore)
5644 
5645 #ifndef Q_WS_MAC
5646  } else {
5647  // Render via a pixmap in device coordinates (to avoid pixmap scaling).
5648  QTransform transform = originalTransform;
5649  transform.translate(targetOffset.x(), targetOffset.y());
5650 
5651  QPaintDevice *device = painter->device();
5652  Q_ASSERT(device);
5653 
5654  // Calculate device rect.
5655  const QRectF rect(toBePainted.boundingRect());
5656  QRect deviceRect = transform.mapRect(QRectF(0, 0, rect.width(), rect.height())).toAlignedRect();
5657  deviceRect &= QRect(0, 0, device->width(), device->height());
5658 
5659  QPixmap pixmap(deviceRect.size());
5660  pixmap.fill(Qt::transparent);
5661 
5662  // Create a pixmap device coordinate painter.
5663  QPainter pixmapPainter(&pixmap);
5664  pixmapPainter.setRenderHints(painter->renderHints());
5665  transform *= QTransform::fromTranslate(-deviceRect.x(), -deviceRect.y());
5666  pixmapPainter.setTransform(transform);
5667 
5668  q->render(&pixmapPainter, QPoint(), toBePainted, renderFlags);
5669  pixmapPainter.end();
5670 
5671  // And then draw the pixmap.
5672  painter->setTransform(QTransform());
5673  painter->drawPixmap(deviceRect.topLeft(), pixmap);
5674  painter->setTransform(originalTransform);
5675  }
5676 #endif
5677 }
5678 
5679 void QWidgetPrivate::drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags,
5680  QPainter *sharedPainter, QWidgetBackingStore *backingStore)
5681 {
5682  if (rgn.isEmpty())
5683  return;
5684 
5685 #if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)
5686  if (qt_mac_clearDirtyOnWidgetInsideDrawWidget)
5687  dirtyOnWidget = QRegion();
5688 
5689  // We disable the rendering of QToolBar in the backingStore if
5690  // it's supposed to be in the unified toolbar on Mac OS X.
5691  if (backingStore && isInUnifiedToolbar)
5692  return;
5693 #endif // Q_WS_MAC && QT_MAC_USE_COCOA
5694 
5695 
5696  Q_Q(QWidget);
5697 #if !defined(QT_NO_GRAPHICSEFFECT) && !defined(Q_WS_MAC)
5699  QGraphicsEffectSource *source = graphicsEffect->d_func()->source;
5700  QWidgetEffectSourcePrivate *sourced = static_cast<QWidgetEffectSourcePrivate *>
5701  (source->d_func());
5702  if (!sourced->context) {
5703  QWidgetPaintContext context(pdev, rgn, offset, flags, sharedPainter, backingStore);
5704  sourced->context = &context;
5705  if (!sharedPainter) {
5707  paintEngine->d_func()->systemClip = rgn.translated(offset);
5708  QPainter p(pdev);
5709  p.translate(offset);
5710  context.painter = &p;
5711  graphicsEffect->draw(&p);
5712  paintEngine->d_func()->systemClip = QRegion();
5713  } else {
5714  context.painter = sharedPainter;
5715  if (sharedPainter->worldTransform() != sourced->lastEffectTransform) {
5716  sourced->invalidateCache();
5717  sourced->lastEffectTransform = sharedPainter->worldTransform();
5718  }
5719  sharedPainter->save();
5720  sharedPainter->translate(offset);
5721  graphicsEffect->draw(sharedPainter);
5722  sharedPainter->restore();
5723  }
5724  sourced->context = 0;
5725  return;
5726  }
5727  }
5728 #endif //QT_NO_GRAFFICSEFFECT
5729 
5730  const bool asRoot = flags & DrawAsRoot;
5731  const bool alsoOnScreen = flags & DrawPaintOnScreen;
5732  const bool recursive = flags & DrawRecursive;
5733  const bool alsoInvisible = flags & DrawInvisible;
5734 
5735  Q_ASSERT(sharedPainter ? sharedPainter->isActive() : true);
5736 
5737  QRegion toBePainted(rgn);
5738  if (asRoot && !alsoInvisible)
5739  toBePainted &= clipRect(); //(rgn & visibleRegion());
5740  if (!(flags & DontSubtractOpaqueChildren))
5741  subtractOpaqueChildren(toBePainted, q->rect());
5742 
5743  if (!toBePainted.isEmpty()) {
5744  bool onScreen = paintOnScreen();
5745  if (!onScreen || alsoOnScreen) {
5746  //update the "in paint event" flag
5747  if (q->testAttribute(Qt::WA_WState_InPaintEvent))
5748  qWarning("QWidget::repaint: Recursive repaint detected");
5749  q->setAttribute(Qt::WA_WState_InPaintEvent);
5750 
5751  //clip away the new area
5752 #ifndef QT_NO_PAINT_DEBUG
5753  bool flushed = QWidgetBackingStore::flushPaint(q, toBePainted);
5754 #endif
5756  if (paintEngine) {
5757  setRedirected(pdev, -offset);
5758 
5759 #ifdef Q_WS_MAC
5760  // (Alien support) Special case for Mac when redirecting: If the paint device
5761  // is of the Widget type we need to set WA_WState_InPaintEvent since painting
5762  // outside the paint event is not supported on QWidgets. The attributeis
5763  // restored further down.
5764  if (pdev->devType() == QInternal::Widget)
5765  static_cast<QWidget *>(pdev)->setAttribute(Qt::WA_WState_InPaintEvent);
5766 
5767 #endif
5768  if (sharedPainter)
5769  paintEngine->d_func()->systemClip = toBePainted;
5770  else
5771  paintEngine->d_func()->systemRect = q->data->crect;
5772 
5773  //paint the background
5774  if ((asRoot || q->autoFillBackground() || onScreen || q->testAttribute(Qt::WA_StyledBackground))
5775  && !q->testAttribute(Qt::WA_OpaquePaintEvent) && !q->testAttribute(Qt::WA_NoSystemBackground)) {
5776  QPainter p(q);
5777  paintBackground(&p, toBePainted, (asRoot || onScreen) ? flags | DrawAsRoot : 0);
5778  }
5779 
5780  if (!sharedPainter)
5781  paintEngine->d_func()->systemClip = toBePainted.translated(offset);
5782 
5783  if (!onScreen && !asRoot && !isOpaque && q->testAttribute(Qt::WA_TintedBackground)) {
5784  QPainter p(q);
5785  QColor tint = q->palette().window().color();
5786  tint.setAlphaF(qreal(.6));
5787  p.fillRect(toBePainted.boundingRect(), tint);
5788  }
5789  }
5790 
5791 #if 0
5792  qDebug() << "painting" << q << "opaque ==" << isOpaque();
5793  qDebug() << "clipping to" << toBePainted << "location == " << offset
5794  << "geometry ==" << QRect(q->mapTo(q->window(), QPoint(0, 0)), q->size());
5795 #endif
5796 
5797  //actually send the paint event
5798  QPaintEvent e(toBePainted);
5800 #if !defined(Q_WS_QWS) && !defined(Q_WS_QPA)
5801  if (backingStore && !onScreen && !asRoot && (q->internalWinId() || !q->nativeParentWidget()->isWindow()))
5802  backingStore->markDirtyOnScreen(toBePainted, q, offset);
5803 #endif
5804 
5805  //restore
5806  if (paintEngine) {
5807 #ifdef Q_WS_MAC
5808  if (pdev->devType() == QInternal::Widget)
5809  static_cast<QWidget *>(pdev)->setAttribute(Qt::WA_WState_InPaintEvent, false);
5810 #endif
5811  restoreRedirected();
5812  if (!sharedPainter)
5813  paintEngine->d_func()->systemRect = QRect();
5814  else
5815  paintEngine->d_func()->currentClipWidget = 0;
5816  paintEngine->d_func()->systemClip = QRegion();
5817  }
5818  q->setAttribute(Qt::WA_WState_InPaintEvent, false);
5819  if (q->paintingActive() && !q->testAttribute(Qt::WA_PaintOutsidePaintEvent))
5820  qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent");
5821 
5822  if (paintEngine && paintEngine->autoDestruct()) {
5823  delete paintEngine;
5824  }
5825 
5826 #ifndef QT_NO_PAINT_DEBUG
5827  if (flushed)
5828  QWidgetBackingStore::unflushPaint(q, toBePainted);
5829 #endif
5830  } else if (q->isWindow()) {
5831  QPaintEngine *engine = pdev->paintEngine();
5832  if (engine) {
5833  QPainter p(pdev);
5834  p.setClipRegion(toBePainted);
5835  const QBrush bg = q->palette().brush(QPalette::Window);
5836  if (bg.style() == Qt::TexturePattern)
5837  p.drawTiledPixmap(q->rect(), bg.texture());
5838  else
5839  p.fillRect(q->rect(), bg);
5840 
5841  if (engine->autoDestruct())
5842  delete engine;
5843  }
5844  }
5845  }
5846 
5847  if (recursive && !children.isEmpty()) {
5848  paintSiblingsRecursive(pdev, children, children.size() - 1, rgn, offset, flags & ~DrawAsRoot
5849 #ifdef Q_BACKINGSTORE_SUBSURFACES
5850  , q->windowSurface()
5851 #endif
5852  , sharedPainter, backingStore);
5853  }
5854 }
5855 
5856 void QWidgetPrivate::render(QPaintDevice *target, const QPoint &targetOffset,
5857  const QRegion &sourceRegion, QWidget::RenderFlags renderFlags,
5858  bool readyToRender)
5859 {
5860  if (!target) {
5861  qWarning("QWidget::render: null pointer to paint device");
5862  return;
5863  }
5864 
5865  const bool inRenderWithPainter = extra && extra->inRenderWithPainter;
5866  QRegion paintRegion = !inRenderWithPainter && !readyToRender
5867  ? prepareToRender(sourceRegion, renderFlags)
5868  : sourceRegion;
5869  if (paintRegion.isEmpty())
5870  return;
5871 
5872 #ifndef Q_WS_MAC
5873  QPainter *oldSharedPainter = inRenderWithPainter ? sharedPainter() : 0;
5874 
5875  // Use the target's shared painter if set (typically set when doing
5876  // "other->render(widget);" in the widget's paintEvent.
5877  if (target->devType() == QInternal::Widget) {
5878  QWidgetPrivate *targetPrivate = static_cast<QWidget *>(target)->d_func();
5879  if (targetPrivate->extra && targetPrivate->extra->inRenderWithPainter) {
5880  QPainter *targetPainter = targetPrivate->sharedPainter();
5881  if (targetPainter && targetPainter->isActive())
5882  setSharedPainter(targetPainter);
5883  }
5884  }
5885 #endif
5886 
5887  // Use the target's redirected device if set and adjust offset and paint
5888  // region accordingly. This is typically the case when people call render
5889  // from the paintEvent.
5890  QPoint offset = targetOffset;
5891  offset -= paintRegion.boundingRect().topLeft();
5892  QPoint redirectionOffset;
5893  QPaintDevice *redirected = 0;
5894 
5895  if (target->devType() == QInternal::Widget)
5896  redirected = static_cast<QWidget *>(target)->d_func()->redirected(&redirectionOffset);
5897  if (!redirected)
5898  redirected = QPainter::redirected(target, &redirectionOffset);
5899 
5900  if (redirected) {
5901  target = redirected;
5902  offset -= redirectionOffset;
5903  }
5904 
5905  if (!inRenderWithPainter) { // Clip handled by shared painter (in qpainter.cpp).
5906  if (QPaintEngine *targetEngine = target->paintEngine()) {
5907  const QRegion targetSystemClip = targetEngine->systemClip();
5908  if (!targetSystemClip.isEmpty())
5909  paintRegion &= targetSystemClip.translated(-offset);
5910  }
5911  }
5912 
5913  // Set backingstore flags.
5914  int flags = DrawPaintOnScreen | DrawInvisible;
5915  if (renderFlags & QWidget::DrawWindowBackground)
5916  flags |= DrawAsRoot;
5917 
5918  if (renderFlags & QWidget::DrawChildren)
5919  flags |= DrawRecursive;
5920  else
5921  flags |= DontSubtractOpaqueChildren;
5922 
5923 #if defined(Q_WS_QWS) || defined(Q_WS_QPA)
5924  flags |= DontSetCompositionMode;
5925 #endif
5926 
5927  if (target->devType() == QInternal::Printer) {
5928  QPainter p(target);
5929  render_helper(&p, targetOffset, paintRegion, renderFlags);
5930  return;
5931  }
5932 
5933 #ifndef Q_WS_MAC
5934  // Render via backingstore.
5935  drawWidget(target, paintRegion, offset, flags, sharedPainter());
5936 
5937  // Restore shared painter.
5938  if (oldSharedPainter)
5939  setSharedPainter(oldSharedPainter);
5940 #else
5941  // Render via backingstore (no shared painter).
5942  drawWidget(target, paintRegion, offset, flags, 0);
5943 #endif
5944 }
5945 
5946 void QWidgetPrivate::paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList& siblings, int index, const QRegion &rgn,
5947  const QPoint &offset, int flags
5948 #ifdef Q_BACKINGSTORE_SUBSURFACES
5949  , const QWindowSurface *currentSurface
5950 #endif
5951  , QPainter *sharedPainter, QWidgetBackingStore *backingStore)
5952 {
5953  QWidget *w = 0;
5955  bool dirtyBoundingRect = true;
5956  const bool exludeOpaqueChildren = (flags & DontDrawOpaqueChildren);
5957  const bool excludeNativeChildren = (flags & DontDrawNativeChildren);
5958 
5959  do {
5960  QWidget *x = qobject_cast<QWidget*>(siblings.at(index));
5961  if (x && !(exludeOpaqueChildren && x->d_func()->isOpaque) && !x->isHidden() && !x->isWindow()
5962  && !(excludeNativeChildren && x->internalWinId())) {
5963  if (dirtyBoundingRect) {
5964  boundingRect = rgn.boundingRect();
5965  dirtyBoundingRect = false;
5966  }
5967 
5968  if (qRectIntersects(boundingRect, x->d_func()->effectiveRectFor(x->data->crect))) {
5969 #ifdef Q_BACKINGSTORE_SUBSURFACES
5970  if (x->windowSurface() == currentSurface)
5971 #endif
5972  {
5973  w = x;
5974  break;
5975  }
5976  }
5977  }
5978  --index;
5979  } while (index >= 0);
5980 
5981  if (!w)
5982  return;
5983 
5984  QWidgetPrivate *wd = w->d_func();
5985  const QPoint widgetPos(w->data->crect.topLeft());
5986  const bool hasMask = wd->extra && wd->extra->hasMask && !wd->graphicsEffect;
5987  if (index > 0) {
5988  QRegion wr(rgn);
5989  if (wd->isOpaque)
5990  wr -= hasMask ? wd->extra->mask.translated(widgetPos) : w->data->crect;
5991  paintSiblingsRecursive(pdev, siblings, --index, wr, offset, flags
5992 #ifdef Q_BACKINGSTORE_SUBSURFACES
5993  , currentSurface
5994 #endif
5995  , sharedPainter, backingStore);
5996  }
5997 
5998  if (w->updatesEnabled()
5999 #ifndef QT_NO_GRAPHICSVIEW
6000  && (!w->d_func()->extra || !w->d_func()->extra->proxyWidget)
6001 #endif //QT_NO_GRAPHICSVIEW
6002  ) {
6003  QRegion wRegion(rgn);
6004  wRegion &= wd->effectiveRectFor(w->data->crect);
6005  wRegion.translate(-widgetPos);
6006  if (hasMask)
6007  wRegion &= wd->extra->mask;
6008  wd->drawWidget(pdev, wRegion, offset + widgetPos, flags, sharedPainter, backingStore);
6009  }
6010 }
6011 
6012 #ifndef QT_NO_GRAPHICSEFFECT
6014 {
6015  if (system != Qt::DeviceCoordinates)
6016  return m_widget->rect();
6017 
6018  if (!context) {
6019  // Device coordinates without context not yet supported.
6020  qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");
6021  return QRectF();
6022  }
6023 
6024  return context->painter->worldTransform().mapRect(m_widget->rect());
6025 }
6026 
6028 {
6029  if (!context || context->painter != painter) {
6030  m_widget->render(painter);
6031  return;
6032  }
6033 
6034  // The region saved in the context is neither clipped to the rect
6035  // nor the mask, so we have to clip it here before calling drawWidget.
6036  QRegion toBePainted = context->rgn;
6037  toBePainted &= m_widget->rect();
6038  QWidgetPrivate *wd = qt_widget_private(m_widget);
6039  if (wd->extra && wd->extra->hasMask)
6040  toBePainted &= wd->extra->mask;
6041 
6042  wd->drawWidget(context->pdev, toBePainted, context->offset, context->flags,
6043  context->sharedPainter, context->backingStore);
6044 }
6045 
6047  QGraphicsEffect::PixmapPadMode mode) const
6048 {
6049  const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
6050  if (!context && deviceCoordinates) {
6051  // Device coordinates without context not yet supported.
6052  qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
6053  return QPixmap();
6054  }
6055 
6056  QPoint pixmapOffset;
6057  QRectF sourceRect = m_widget->rect();
6058 
6059  if (deviceCoordinates) {
6060  const QTransform &painterTransform = context->painter->worldTransform();
6061  sourceRect = painterTransform.mapRect(sourceRect);
6062  pixmapOffset = painterTransform.map(pixmapOffset);
6063  }
6064 
6065  QRect effectRect;
6066 
6068  effectRect = m_widget->graphicsEffect()->boundingRectFor(sourceRect).toAlignedRect();
6069  else if (mode == QGraphicsEffect::PadToTransparentBorder)
6070  effectRect = sourceRect.adjusted(-1, -1, 1, 1).toAlignedRect();
6071  else
6072  effectRect = sourceRect.toAlignedRect();
6073 
6074  if (offset)
6075  *offset = effectRect.topLeft();
6076 
6077  pixmapOffset -= effectRect.topLeft();
6078 
6079  QPixmap pixmap(effectRect.size());
6080  pixmap.fill(Qt::transparent);
6081  m_widget->render(&pixmap, pixmapOffset, QRegion(), QWidget::DrawChildren);
6082  return pixmap;
6083 }
6084 #endif //QT_NO_GRAPHICSEFFECT
6085 
6086 #ifndef QT_NO_GRAPHICSVIEW
6087 
6099 {
6100  if (origin) {
6101  QWExtra *extra = origin->d_func()->extra;
6102  if (extra && extra->proxyWidget)
6103  return extra->proxyWidget;
6104  return nearestGraphicsProxyWidget(origin->parentWidget());
6105  }
6106  return 0;
6107 }
6108 #endif
6109 
6128 void QWidgetPrivate::setLocale_helper(const QLocale &loc, bool forceUpdate)
6129 {
6130  Q_Q(QWidget);
6131  if (locale == loc && !forceUpdate)
6132  return;
6133 
6134  locale = loc;
6135 
6136  if (!children.isEmpty()) {
6137  for (int i = 0; i < children.size(); ++i) {
6138  QWidget *w = qobject_cast<QWidget*>(children.at(i));
6139  if (!w)
6140  continue;
6142  continue;
6144  continue;
6145  w->d_func()->setLocale_helper(loc, forceUpdate);
6146  }
6147  }
6149  QApplication::sendEvent(q, &e);
6150 }
6151 
6153 {
6154  Q_D(QWidget);
6155 
6157  d->setLocale_helper(locale);
6158 }
6159 
6160 QLocale QWidget::locale() const
6161 {
6162  Q_D(const QWidget);
6163 
6164  return d->locale;
6165 }
6166 
6168 {
6169  Q_Q(const QWidget);
6170 
6171  if (!q->testAttribute(Qt::WA_SetLocale)) {
6172  setLocale_helper(q->isWindow()
6173  ? QLocale()
6174  : q->parentWidget()->locale());
6175  }
6176 }
6177 
6179 {
6180  Q_D(QWidget);
6182  d->resolveLocale();
6183 }
6184 
6186 {
6187  QFileInfo fi(filePath);
6188  QString windowTitle = fi.fileName() + QLatin1String("[*]");
6189 #ifndef Q_WS_MAC
6191  if (!appName.isEmpty())
6192  windowTitle += QLatin1Char(' ') + QChar(0x2014) + QLatin1Char(' ') + appName;
6193 #endif
6194  return windowTitle;
6195 }
6196 
6218 {
6219  Q_D(const QWidget);
6220  if (d->extra && d->extra->topextra) {
6221  if (!d->extra->topextra->caption.isEmpty())
6222  return d->extra->topextra->caption;
6223  if (!d->extra->topextra->filePath.isEmpty())
6224  return constructWindowTitleFromFilePath(d->extra->topextra->filePath);
6225  }
6226  return QString();
6227 }
6228 
6241 {
6242  Q_ASSERT(widget);
6243 
6244 #ifdef QT_EVAL
6245  extern QString qt_eval_adapt_window_title(const QString &title);
6246  QString cap = qt_eval_adapt_window_title(title);
6247 #else
6248  QString cap = title;
6249 #endif
6250 
6251  if (cap.isEmpty())
6252  return cap;
6253 
6254  QLatin1String placeHolder("[*]");
6255  int placeHolderLength = 3; // QLatin1String doesn't have length()
6256 
6257  int index = cap.indexOf(placeHolder);
6258 
6259  // here the magic begins
6260  while (index != -1) {
6261  index += placeHolderLength;
6262  int count = 1;
6263  while (cap.indexOf(placeHolder, index) == index) {
6264  ++count;
6265  index += placeHolderLength;
6266  }
6267 
6268  if (count%2) { // odd number of [*] -> replace last one
6269  int lastIndex = cap.lastIndexOf(placeHolder, index - 1);
6270  if (widget->isWindowModified()
6271  && widget->style()->styleHint(QStyle::SH_TitleBar_ModifyNotification, 0, widget))
6272  cap.replace(lastIndex, 3, QWidget::tr("*"));
6273  else
6274  cap.remove(lastIndex, 3);
6275  }
6276 
6277  index = cap.indexOf(placeHolder, index);
6278  }
6279 
6280  cap.replace(QLatin1String("[*][*]"), placeHolder);
6281 
6282  return cap;
6283 }
6284 
6286 {
6287  Q_Q(QWidget);
6288  if (q->testAttribute(Qt::WA_WState_Created))
6289  setWindowTitle_sys(qt_setWindowTitle_helperHelper(title, q));
6290 }
6291 
6293 {
6294  Q_Q(QWidget);
6295  if (q->testAttribute(Qt::WA_WState_Created))
6296  setWindowIconText_sys(qt_setWindowTitle_helperHelper(title, q));
6297 }
6298 
6300 {
6301  if (QWidget::windowIconText() == iconText)
6302  return;
6303 
6304  Q_D(QWidget);
6305  d->topData()->iconText = iconText;
6306  d->setWindowIconText_helper(iconText);
6307 
6309  QApplication::sendEvent(this, &e);
6310 }
6311 
6313 {
6314  if (QWidget::windowTitle() == title && !title.isEmpty() && !title.isNull())
6315  return;
6316 
6317  Q_D(QWidget);
6318  d->topData()->caption = title;
6319  d->setWindowTitle_helper(title);
6320 
6322  QApplication::sendEvent(this, &e);
6323 }
6324 
6325 
6339 QIcon QWidget::windowIcon() const
6340 {
6341  const QWidget *w = this;
6342  while (w) {
6343  const QWidgetPrivate *d = w->d_func();
6344  if (d->extra && d->extra->topextra && d->extra->topextra->icon)
6345  return *d->extra->topextra->icon;
6346  w = w->parentWidget();
6347  }
6348  return QApplication::windowIcon();
6349 }
6350 
6352 {
6354  QApplication::sendEvent(q_func(), &e);
6355  for (int i = 0; i < children.size(); ++i) {
6356  QWidget *w = qobject_cast<QWidget *>(children.at(i));
6357  if (w && !w->isWindow())
6358  QApplication::sendEvent(w, &e);
6359  }
6360 }
6361 
6363 {
6364  Q_D(QWidget);
6365 
6367  d->createTLExtra();
6368 
6369  if (!d->extra->topextra->icon)
6370  d->extra->topextra->icon = new QIcon();
6371  *d->extra->topextra->icon = icon;
6372 
6373  delete d->extra->topextra->iconPixmap;
6374  d->extra->topextra->iconPixmap = 0;
6375 
6376  d->setWindowIcon_sys();
6377  d->setWindowIcon_helper();
6378 }
6379 
6380 
6395 {
6396  Q_D(const QWidget);
6397  return (d->extra && d->extra->topextra) ? d->extra->topextra->iconText : QString();
6398 }
6399 
6444 {
6445  Q_D(const QWidget);
6446  return (d->extra && d->extra->topextra) ? d->extra->topextra->filePath : QString();
6447 }
6448 
6450 {
6451  if (filePath == windowFilePath())
6452  return;
6453 
6454  Q_D(QWidget);
6455 
6456  d->createTLExtra();
6457  d->extra->topextra->filePath = filePath;
6458  d->setWindowFilePath_helper(filePath);
6459 }
6460 
6462 {
6463  if (extra->topextra && extra->topextra->caption.isEmpty()) {
6464 #ifdef Q_WS_MAC
6465  setWindowTitle_helper(QFileInfo(filePath).fileName());
6466 #else
6467  Q_Q(QWidget);
6468  Q_UNUSED(filePath);
6469  setWindowTitle_helper(q->windowTitle());
6470 #endif
6471  }
6472 #ifdef Q_WS_MAC
6473  setWindowFilePath_sys(filePath);
6474 #endif
6475 }
6476 
6484 {
6485  Q_D(const QWidget);
6486  return (d->extra && d->extra->topextra) ? d->extra->topextra->role : QString();
6487 }
6488 
6494 {
6495 #if defined(Q_WS_X11)
6496  Q_D(QWidget);
6497  d->topData()->role = role;
6498  d->setWindowRole();
6499 #else
6500  Q_UNUSED(role)
6501 #endif
6502 }
6503 
6538 {
6539  Q_D(QWidget);
6540  if (!w && !d->extra)
6541  return;
6542 
6543  for (QWidget* fp = w; fp; fp = fp->focusProxy()) {
6544  if (fp == this) {
6545  qWarning("QWidget: %s (%s) already in focus proxy chain", metaObject()->className(), objectName().toLocal8Bit().constData());
6546  return;
6547  }
6548  }
6549 
6550  d->createExtra();
6551  d->extra->focus_proxy = w;
6552 }
6553 
6554 
6562 {
6563  Q_D(const QWidget);
6564  return d->extra ? (QWidget *)d->extra->focus_proxy : 0;
6565 }
6566 
6567 
6583 bool QWidget::hasFocus() const
6584 {
6585  const QWidget* w = this;
6586  while (w->d_func()->extra && w->d_func()->extra->focus_proxy)
6587  w = w->d_func()->extra->focus_proxy;
6588  if (QWidget *window = w->window()) {
6589 #ifndef QT_NO_GRAPHICSVIEW
6590  QWExtra *e = window->d_func()->extra;
6591  if (e && e->proxyWidget && e->proxyWidget->hasFocus() && window->focusWidget() == w)
6592  return true;
6593 #endif
6594  }
6595  return (QApplication::focusWidget() == w);
6596 }
6597 
6634 {
6635  if (!isEnabled())
6636  return;
6637 
6638  QWidget *f = this;
6639  while (f->d_func()->extra && f->d_func()->extra->focus_proxy)
6640  f = f->d_func()->extra->focus_proxy;
6641 
6642  if (QApplication::focusWidget() == f
6643 #if defined(Q_WS_WIN)
6644  && GetFocus() == f->internalWinId()
6645 #endif
6646  )
6647  return;
6648 
6649 #ifndef QT_NO_GRAPHICSVIEW
6650  QWidget *previousProxyFocus = 0;
6651  if (QWExtra *topData = window()->d_func()->extra) {
6652  if (topData->proxyWidget && topData->proxyWidget->hasFocus()) {
6653  previousProxyFocus = topData->proxyWidget->widget()->focusWidget();
6654  if (previousProxyFocus && previousProxyFocus->focusProxy())
6655  previousProxyFocus = previousProxyFocus->focusProxy();
6656  if (previousProxyFocus == this && !topData->proxyWidget->d_func()->proxyIsGivingFocus)
6657  return;
6658  }
6659  }
6660 #endif
6661 
6662  QWidget *w = f;
6663  if (isHidden()) {
6664  while (w && w->isHidden()) {
6665  w->d_func()->focus_child = f;
6666  w = w->isWindow() ? 0 : w->parentWidget();
6667  }
6668  } else {
6669  while (w) {
6670  w->d_func()->focus_child = f;
6671  w = w->isWindow() ? 0 : w->parentWidget();
6672  }
6673  }
6674 
6675 #ifndef QT_NO_GRAPHICSVIEW
6676  // Update proxy state
6677  if (QWExtra *topData = window()->d_func()->extra) {
6678  if (topData->proxyWidget && !topData->proxyWidget->hasFocus()) {
6679  topData->proxyWidget->d_func()->focusFromWidgetToProxy = 1;
6680  topData->proxyWidget->setFocus(reason);
6681  topData->proxyWidget->d_func()->focusFromWidgetToProxy = 0;
6682  }
6683  }
6684 #endif
6685 
6686  if (f->isActiveWindow()) {
6688 #ifndef QT_NO_ACCESSIBILITY
6689 # ifdef Q_OS_WIN
6690  // The negation of the condition in setFocus_sys
6692  //setFocusWidget will already post a focus event for us (that the AT client receives) on Windows
6693 # endif
6694 # ifdef Q_OS_UNIX
6695  // menus update the focus manually and this would create bogus events
6696  if (!(f->inherits("QMenuBar") || f->inherits("QMenu") || f->inherits("QMenuItem")))
6697 # endif
6699 #endif
6700 #ifndef QT_NO_GRAPHICSVIEW
6701  if (QWExtra *topData = window()->d_func()->extra) {
6702  if (topData->proxyWidget) {
6703  if (previousProxyFocus && previousProxyFocus != f) {
6704  // Send event to self
6706  QPointer<QWidget> that = previousProxyFocus;
6707  QApplication::sendEvent(previousProxyFocus, &event);
6708  if (that)
6709  QApplication::sendEvent(that->style(), &event);
6710  }
6711  if (!isHidden()) {
6712 #ifndef QT_NO_GRAPHICSVIEW
6713  // Update proxy state
6714  if (QWExtra *topData = window()->d_func()->extra)
6715  if (topData->proxyWidget && topData->proxyWidget->hasFocus())
6716  topData->proxyWidget->d_func()->updateProxyInputMethodAcceptanceFromWidget();
6717 #endif
6718  // Send event to self
6720  QPointer<QWidget> that = f;
6721  QApplication::sendEvent(f, &event);
6722  if (that)
6723  QApplication::sendEvent(that->style(), &event);
6724  }
6725  }
6726  }
6727 #endif
6728  }
6729 }
6730 
6758 {
6759  QWidget *w = this;
6760  while (w) {
6761  if (w->d_func()->focus_child == this)
6762  w->d_func()->focus_child = 0;
6763  w = w->parentWidget();
6764  }
6765 #ifndef QT_NO_GRAPHICSVIEW
6766  QWExtra *topData = d_func()->extra;
6767  if (topData && topData->proxyWidget)
6768  topData->proxyWidget->clearFocus();
6769 #endif
6770 
6771  if (hasFocus()) {
6772  // Update proxy state
6774 #if defined(Q_WS_WIN)
6775  if (!(windowType() == Qt::Popup) && GetFocus() == internalWinId())
6776  SetFocus(0);
6777  else
6778 #endif
6779  {
6780 #ifndef QT_NO_ACCESSIBILITY
6782 #endif
6783  }
6784  }
6785 }
6786 
6787 
6837 {
6838  Q_D(QWidget);
6839  QWidget* p = parentWidget();
6840  bool isSubWindow = (windowType() == Qt::SubWindow);
6841  if (!isWindow() && !isSubWindow && p)
6842  return p->focusNextPrevChild(next);
6843 #ifndef QT_NO_GRAPHICSVIEW
6844  if (d->extra && d->extra->proxyWidget)
6845  return d->extra->proxyWidget->focusNextPrevChild(next);
6846 #endif
6848  if (!w) return false;
6849 
6851  return true;
6852 }
6853 
6864 {
6865  return const_cast<QWidget *>(d_func()->focus_child);
6866 }
6867 
6874 {
6875  return const_cast<QWidget *>(d_func()->focus_next);
6876 }
6877 
6890 {
6891  return const_cast<QWidget *>(d_func()->focus_prev);
6892 }
6893 
6912 bool QWidget::isActiveWindow() const
6913 {
6914  QWidget *tlw = window();
6915  if(tlw == QApplication::activeWindow() || (isVisible() && (tlw->windowType() == Qt::Popup)))
6916  return true;
6917 
6918 #ifndef QT_NO_GRAPHICSVIEW
6919  if (QWExtra *tlwExtra = tlw->d_func()->extra) {
6920  if (isVisible() && tlwExtra->proxyWidget)
6921  return tlwExtra->proxyWidget->isActiveWindow();
6922  }
6923 #endif
6924 
6925 #ifdef Q_WS_MAC
6926  extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp
6927  if(qt_mac_is_macdrawer(tlw) &&
6928  tlw->parentWidget() && tlw->parentWidget()->isActiveWindow())
6929  return true;
6930 
6931  extern bool qt_mac_insideKeyWindow(const QWidget *); //qwidget_mac.cpp
6933  return true;
6934 #endif
6936  if(tlw->windowType() == Qt::Tool &&
6937  !tlw->isModal() &&
6938  (!tlw->parentWidget() || tlw->parentWidget()->isActiveWindow()))
6939  return true;
6941  while(w && tlw->windowType() == Qt::Tool &&
6942  !w->isModal() && w->parentWidget()) {
6943  w = w->parentWidget()->window();
6944  if(w == tlw)
6945  return true;
6946  }
6947  }
6948 #if defined(Q_WS_WIN32)
6949  HWND active = GetActiveWindow();
6951  return false;
6952  return active == tlw->internalWinId() || ::IsChild(active, tlw->internalWinId());
6953 #else
6954  return false;
6955 #endif
6956 }
6957 
6975 void QWidget::setTabOrder(QWidget* first, QWidget *second)
6976 {
6977  if (!first || !second || first->focusPolicy() == Qt::NoFocus || second->focusPolicy() == Qt::NoFocus)
6978  return;
6979 
6980  if (first->window() != second->window()) {
6981  qWarning("QWidget::setTabOrder: 'first' and 'second' must be in the same window");
6982  return;
6983  }
6984 
6985  QWidget *fp = first->focusProxy();
6986  if (fp) {
6987  // If first is redirected, set first to the last child of first
6988  // that can take keyboard focus so that second is inserted after
6989  // that last child, and the focus order within first is (more
6990  // likely to be) preserved.
6991  QList<QWidget *> l = first->findChildren<QWidget *>();
6992  for (int i = l.size()-1; i >= 0; --i) {
6993  QWidget * next = l.at(i);
6994  if (next->window() == fp->window()) {
6995  fp = next;
6996  if (fp->focusPolicy() != Qt::NoFocus)
6997  break;
6998  }
6999  }
7000  first = fp;
7001  }
7002 
7003  if (fp == second)
7004  return;
7005 
7006  if (QWidget *sp = second->focusProxy())
7007  second = sp;
7008 
7009 // QWidget *fp = first->d_func()->focus_prev;
7010  QWidget *fn = first->d_func()->focus_next;
7011 
7012  if (fn == second || first == second)
7013  return;
7014 
7015  QWidget *sp = second->d_func()->focus_prev;
7016  QWidget *sn = second->d_func()->focus_next;
7017 
7018  fn->d_func()->focus_prev = second;
7019  first->d_func()->focus_next = second;
7020 
7021  second->d_func()->focus_next = fn;
7022  second->d_func()->focus_prev = first;
7023 
7024  sp->d_func()->focus_next = sn;
7025  sn->d_func()->focus_prev = sp;
7026 
7027 
7028  Q_ASSERT(first->d_func()->focus_next->d_func()->focus_prev == first);
7029  Q_ASSERT(first->d_func()->focus_prev->d_func()->focus_next == first);
7030 
7031  Q_ASSERT(second->d_func()->focus_next->d_func()->focus_prev == second);
7032  Q_ASSERT(second->d_func()->focus_prev->d_func()->focus_next == second);
7033 }
7034 
7048 {
7049  Q_Q(QWidget);
7050  if (oldtlw == q->window())
7051  return; // nothing to do
7052 
7053  if(focus_child)
7054  focus_child->clearFocus();
7055 
7056  // separate the focus chain into new (children of myself) and old (the rest)
7057  QWidget *firstOld = 0;
7058  //QWidget *firstNew = q; //invariant
7059  QWidget *o = 0; // last in the old list
7060  QWidget *n = q; // last in the new list
7061 
7062  bool prevWasNew = true;
7063  QWidget *w = focus_next;
7064 
7065  //Note: for efficiency, we do not maintain the list invariant inside the loop
7066  //we append items to the relevant list, and we optimize by not changing pointers
7067  //when subsequent items are going into the same list.
7068  while (w != q) {
7069  bool currentIsNew = q->isAncestorOf(w);
7070  if (currentIsNew) {
7071  if (!prevWasNew) {
7072  //prev was old -- append to new list
7073  n->d_func()->focus_next = w;
7074  w->d_func()->focus_prev = n;
7075  }
7076  n = w;
7077  } else {
7078  if (prevWasNew) {
7079  //prev was new -- append to old list, if there is one
7080  if (o) {
7081  o->d_func()->focus_next = w;
7082  w->d_func()->focus_prev = o;
7083  } else {
7084  // "create" the old list
7085  firstOld = w;
7086  }
7087  }
7088  o = w;
7089  }
7090  w = w->d_func()->focus_next;
7091  prevWasNew = currentIsNew;
7092  }
7093 
7094  //repair the old list:
7095  if (firstOld) {
7096  o->d_func()->focus_next = firstOld;
7097  firstOld->d_func()->focus_prev = o;
7098  }
7099 
7100  if (!q->isWindow()) {
7101  QWidget *topLevel = q->window();
7102  //insert new chain into toplevel's chain
7103 
7104  QWidget *prev = topLevel->d_func()->focus_prev;
7105 
7106  topLevel->d_func()->focus_prev = n;
7107  prev->d_func()->focus_next = q;
7108 
7109  focus_prev = prev;
7110  n->d_func()->focus_next = topLevel;
7111  } else {
7112  //repair the new list
7113  n->d_func()->focus_next = q;
7114  focus_prev = n;
7115  }
7116 
7117 }
7118 
7129 {
7130  int dx = 0;
7131  int dy = 0;
7132  if (p.x() < r.left())
7133  dx = r.left() - p.x();
7134  else if (p.x() > r.right())
7135  dx = p.x() - r.right();
7136  if (p.y() < r.top())
7137  dy = r.top() - p.y();
7138  else if (p.y() > r.bottom())
7139  dy = p.y() - r.bottom();
7140  return dx + dy;
7141 }
7142 
7153 QSize QWidget::frameSize() const
7154 {
7155  Q_D(const QWidget);
7156  if (isWindow() && !(windowType() == Qt::Popup)) {
7157  QRect fs = d->frameStrut();
7158  return QSize(data->crect.width() + fs.left() + fs.right(),
7159  data->crect.height() + fs.top() + fs.bottom());
7160  }
7161  return data->crect.size();
7162 }
7163 
7174 void QWidget::move(const QPoint &p)
7175 {
7176  Q_D(QWidget);
7178  if (isWindow())
7179  d->topData()->posFromMove = true;
7181  d->setGeometry_sys(p.x() + geometry().x() - QWidget::x(),
7182  p.y() + geometry().y() - QWidget::y(),
7183  width(), height(), true);
7184  d->setDirtyOpaqueRegion();
7185  } else {
7186  data->crect.moveTopLeft(p); // no frame yet
7188  }
7189 }
7190 
7200 void QWidget::resize(const QSize &s)
7201 {
7202  Q_D(QWidget);
7205  d->setGeometry_sys(geometry().x(), geometry().y(), s.width(), s.height(), false);
7206  d->setDirtyOpaqueRegion();
7207  } else {
7210  }
7211 }
7212 
7214 {
7215  Q_D(QWidget);
7218  if (isWindow())
7219  d->topData()->posFromMove = false;
7221  d->setGeometry_sys(r.x(), r.y(), r.width(), r.height(), true);
7222  d->setDirtyOpaqueRegion();
7223  } else {
7224  data->crect.setTopLeft(r.topLeft());
7228  }
7229 }
7230 
7252 {
7253 #ifdef QT_MAC_USE_COCOA
7254  // We check if the window was maximized during this invocation. If so, we need to record the
7255  // starting position as 0,0.
7256  Q_D(const QWidget);
7257  QRect newFramePosition = frameGeometry();
7258  QRect newNormalPosition = normalGeometry();
7259  if(d->topData()->wasMaximized && !(windowState() & Qt::WindowMaximized)) {
7260  // Change the starting position
7261  newFramePosition.moveTo(0, 0);
7262  newNormalPosition.moveTo(0, 0);
7263  }
7264 #endif // QT_MAC_USE_COCOA
7265  QByteArray array;
7268  const quint32 magicNumber = 0x1D9D0CB;
7269  quint16 majorVersion = 1;
7270  quint16 minorVersion = 0;
7271  stream << magicNumber
7272  << majorVersion
7273  << minorVersion
7274 #ifdef QT_MAC_USE_COCOA
7275  << newFramePosition
7276  << newNormalPosition
7277 #else
7278  << frameGeometry()
7279  << normalGeometry()
7280 #endif // QT_MAC_USE_COCOA
7281  << qint32(QApplication::desktop()->screenNumber(this))
7284  return array;
7285 }
7286 
7314 {
7315  if (geometry.size() < 4)
7316  return false;
7317  QDataStream stream(geometry);
7319 
7320  const quint32 magicNumber = 0x1D9D0CB;
7321  quint32 storedMagicNumber;
7322  stream >> storedMagicNumber;
7323  if (storedMagicNumber != magicNumber)
7324  return false;
7325 
7326  const quint16 currentMajorVersion = 1;
7327  quint16 majorVersion = 0;
7328  quint16 minorVersion = 0;
7329 
7330  stream >> majorVersion >> minorVersion;
7331 
7332  if (majorVersion != currentMajorVersion)
7333  return false;
7334  // (Allow all minor versions.)
7335 
7336  QRect restoredFrameGeometry;
7337  QRect restoredNormalGeometry;
7338  qint32 restoredScreenNumber;
7339  quint8 maximized;
7341 
7342  stream >> restoredFrameGeometry
7343  >> restoredNormalGeometry
7344  >> restoredScreenNumber
7345  >> maximized
7346  >> fullScreen;
7347 
7348  const int frameHeight = 20;
7349  if (!restoredFrameGeometry.isValid())
7350  restoredFrameGeometry = QRect(QPoint(0,0), sizeHint());
7351 
7352  if (!restoredNormalGeometry.isValid())
7353  restoredNormalGeometry = QRect(QPoint(0, frameHeight), sizeHint());
7354  if (!restoredNormalGeometry.isValid()) {
7355  // use the widget's adjustedSize if the sizeHint() doesn't help
7356  restoredNormalGeometry.setSize(restoredNormalGeometry
7357  .size()
7358  .expandedTo(d_func()->adjustedSize()));
7359  }
7360 
7361  const QDesktopWidget * const desktop = QApplication::desktop();
7362  if (restoredScreenNumber >= desktop->numScreens())
7363  restoredScreenNumber = desktop->primaryScreen();
7364 
7365  const QRect availableGeometry = desktop->availableGeometry(restoredScreenNumber);
7366 
7367  // Modify the restored geometry if we are about to restore to coordinates
7368  // that would make the window "lost". This happens if:
7369  // - The restored geometry is completely oustside the available geometry
7370  // - The title bar is outside the available geometry.
7371  // - (Mac only) The window is higher than the available geometry. It must
7372  // be possible to bring the size grip on screen by moving the window.
7373 #ifdef Q_WS_MAC
7374  restoredFrameGeometry.setHeight(qMin(restoredFrameGeometry.height(), availableGeometry.height()));
7375  restoredNormalGeometry.setHeight(qMin(restoredNormalGeometry.height(), availableGeometry.height() - frameHeight));
7376 #endif
7377 
7378  if (!restoredFrameGeometry.intersects(availableGeometry)) {
7379  restoredFrameGeometry.moveBottom(qMin(restoredFrameGeometry.bottom(), availableGeometry.bottom()));
7380  restoredFrameGeometry.moveLeft(qMax(restoredFrameGeometry.left(), availableGeometry.left()));
7381  restoredFrameGeometry.moveRight(qMin(restoredFrameGeometry.right(), availableGeometry.right()));
7382  }
7383  restoredFrameGeometry.moveTop(qMax(restoredFrameGeometry.top(), availableGeometry.top()));
7384 
7385  if (!restoredNormalGeometry.intersects(availableGeometry)) {
7386  restoredNormalGeometry.moveBottom(qMin(restoredNormalGeometry.bottom(), availableGeometry.bottom()));
7387  restoredNormalGeometry.moveLeft(qMax(restoredNormalGeometry.left(), availableGeometry.left()));
7388  restoredNormalGeometry.moveRight(qMin(restoredNormalGeometry.right(), availableGeometry.right()));
7389  }
7390  restoredNormalGeometry.moveTop(qMax(restoredNormalGeometry.top(), availableGeometry.top() + frameHeight));
7391 
7392  if (maximized || fullScreen) {
7393  // set geomerty before setting the window state to make
7394  // sure the window is maximized to the right screen.
7395  Qt::WindowStates ws = windowState();
7396 #ifndef Q_WS_WIN
7397  setGeometry(restoredNormalGeometry);
7398 #else
7399  if (ws & Qt::WindowFullScreen) {
7400  // Full screen is not a real window state on Windows.
7401  move(availableGeometry.topLeft());
7402  } else if (ws & Qt::WindowMaximized) {
7403  // Setting a geometry on an already maximized window causes this to be
7404  // restored into a broken, half-maximized state, non-resizable state (QTBUG-4397).
7405  // Move the window in normal state if needed.
7406  if (restoredScreenNumber != desktop->screenNumber(this)) {
7408  setGeometry(restoredNormalGeometry);
7409  }
7410  } else {
7411  setGeometry(restoredNormalGeometry);
7412  }
7413 #endif // Q_WS_WIN
7414  if (maximized)
7415  ws |= Qt::WindowMaximized;
7416  if (fullScreen)
7417  ws |= Qt::WindowFullScreen;
7418  setWindowState(ws);
7419  d_func()->topData()->normalGeometry = restoredNormalGeometry;
7420  } else {
7421  QPoint offset;
7422 #ifdef Q_WS_X11
7423  if (isFullScreen())
7424  offset = d_func()->topData()->fullScreenOffset;
7425 #endif
7427  move(restoredFrameGeometry.topLeft() + offset);
7428  resize(restoredNormalGeometry.size());
7429  }
7430  return true;
7431 }
7432 
7449 void QWidget::setContentsMargins(int left, int top, int right, int bottom)
7450 {
7451  Q_D(QWidget);
7452  if (left == d->leftmargin && top == d->topmargin
7453  && right == d->rightmargin && bottom == d->bottommargin)
7454  return;
7455  d->leftmargin = left;
7456  d->topmargin = top;
7457  d->rightmargin = right;
7458  d->bottommargin = bottom;
7459 
7460  if (QLayout *l=d->layout)
7461  l->update(); //force activate; will do updateGeometry
7462  else
7463  updateGeometry();
7464 
7465  // ### Qt 5: compat, remove
7466  if (isVisible()) {
7467  update();
7469  QApplication::sendEvent(this, &e);
7470  } else {
7472  }
7473 
7475  QApplication::sendEvent(this, &e);
7476 }
7477 
7498 {
7499  setContentsMargins(margins.left(), margins.top(),
7500  margins.right(), margins.bottom());
7501 }
7502 
7509 void QWidget::getContentsMargins(int *left, int *top, int *right, int *bottom) const
7510 {
7511  Q_D(const QWidget);
7512  if (left)
7513  *left = d->leftmargin;
7514  if (top)
7515  *top = d->topmargin;
7516  if (right)
7517  *right = d->rightmargin;
7518  if (bottom)
7519  *bottom = d->bottommargin;
7520 }
7521 
7533 {
7534  Q_D(const QWidget);
7535  return QMargins(d->leftmargin, d->topmargin, d->rightmargin, d->bottommargin);
7536 }
7537 
7538 
7545 {
7546  Q_D(const QWidget);
7547  return QRect(QPoint(d->leftmargin, d->topmargin),
7548  QPoint(data->crect.width() - 1 - d->rightmargin,
7549  data->crect.height() - 1 - d->bottommargin));
7550 
7551 }
7552 
7553 
7554 
7592 {
7594 }
7595 
7597 {
7598  data->context_menu_policy = (uint) policy;
7599 }
7600 
7627 {
7629 }
7630 
7632 {
7633  data->focus_policy = (uint) policy;
7634  Q_D(QWidget);
7635  if (d->extra && d->extra->focus_proxy)
7636  d->extra->focus_proxy->setFocusPolicy(policy);
7637 }
7638 
7671 {
7672  Q_D(QWidget);
7674  d->setUpdatesEnabled_helper(enable);
7675 }
7676 
7699 {
7700  Q_Q(QWidget);
7701  // polish if necessary
7702 
7703  if (!q->testAttribute(Qt::WA_WState_Created))
7704  createRecursively();
7705  q->ensurePolished();
7706 
7707 #ifdef QT3_SUPPORT
7708  if(sendChildEvents)
7709  QApplication::sendPostedEvents(q, QEvent::ChildInserted);
7710 #endif
7711  if (!q->isWindow() && q->parentWidget()->d_func()->layout && !q->parentWidget()->data->in_show)
7712  q->parentWidget()->d_func()->layout->activate();
7713  // activate our layout before we and our children become visible
7714  if (layout)
7715  layout->activate();
7716 
7717  show_helper();
7718 }
7719 
7720 void QWidgetPrivate::sendPendingMoveAndResizeEvents(bool recursive, bool disableUpdates)
7721 {
7722  Q_Q(QWidget);
7723 
7724  disableUpdates = disableUpdates && q->updatesEnabled();
7725  if (disableUpdates)
7726  q->setAttribute(Qt::WA_UpdatesDisabled);
7727 
7728  if (q->testAttribute(Qt::WA_PendingMoveEvent)) {
7730  QApplication::sendEvent(q, &e);
7731  q->setAttribute(Qt::WA_PendingMoveEvent, false);
7732  }
7733 
7734  if (q->testAttribute(Qt::WA_PendingResizeEvent)) {
7735  QResizeEvent e(data.crect.size(), QSize());
7736  QApplication::sendEvent(q, &e);
7737  q->setAttribute(Qt::WA_PendingResizeEvent, false);
7738  }
7739 
7740  if (disableUpdates)
7741  q->setAttribute(Qt::WA_UpdatesDisabled, false);
7742 
7743  if (!recursive)
7744  return;
7745 
7746  for (int i = 0; i < children.size(); ++i) {
7747  if (QWidget *child = qobject_cast<QWidget *>(children.at(i)))
7748  child->d_func()->sendPendingMoveAndResizeEvents(recursive, disableUpdates);
7749  }
7750 }
7751 
7753 {
7754  sendPendingMoveAndResizeEvents(false, true);
7755 
7756  for (int i = 0; i < children.size(); ++i) {
7757  QWidget *child = qobject_cast<QWidget *>(children.at(i));
7758  if (!child || child->isHidden() || child->isWindow())
7759  continue;
7760 
7761  child->ensurePolished();
7762 
7763  // Activate child's layout
7764  QWidgetPrivate *childPrivate = child->d_func();
7765  if (childPrivate->layout)
7766  childPrivate->layout->activate();
7767 
7768  // Pretend we're visible.
7769  const bool wasVisible = child->isVisible();
7770  if (!wasVisible)
7772 
7773  // Do the same for all my children.
7774  childPrivate->activateChildLayoutsRecursively();
7775 
7776  // We're not cheating anymore.
7777  if (!wasVisible)
7778  child->setAttribute(Qt::WA_WState_Visible, false);
7779  }
7780 }
7781 
7783 {
7784  Q_Q(QWidget);
7785  data.in_show = true; // qws optimization
7786  // make sure we receive pending move and resize events
7787  sendPendingMoveAndResizeEvents();
7788 
7789  // become visible before showing all children
7790  q->setAttribute(Qt::WA_WState_Visible);
7791 
7792  // finally show all children recursively
7793  showChildren(false);
7794 
7795 #ifdef QT3_SUPPORT
7796  if (q->parentWidget() && sendChildEvents)
7797  QApplication::sendPostedEvents(q->parentWidget(),
7798  QEvent::ChildInserted);
7799 #endif
7800 
7801 
7802  // popup handling: new popups and tools need to be raised, and
7803  // existing popups must be closed. Also propagate the current
7804  // windows's KeyboardFocusChange status.
7805  if (q->isWindow()) {
7806  if ((q->windowType() == Qt::Tool) || (q->windowType() == Qt::Popup) || q->windowType() == Qt::ToolTip) {
7807  q->raise();
7808  if (q->parentWidget() && q->parentWidget()->window()->testAttribute(Qt::WA_KeyboardFocusChange))
7809  q->setAttribute(Qt::WA_KeyboardFocusChange);
7810  } else {
7813  break;
7814  }
7815  }
7816  }
7817 
7818  // Automatic embedding of child windows of widgets already embedded into
7819  // QGraphicsProxyWidget when they are shown the first time.
7820  bool isEmbedded = false;
7821 #ifndef QT_NO_GRAPHICSVIEW
7822  if (q->isWindow()) {
7823  isEmbedded = q->graphicsProxyWidget() ? true : false;
7824  if (!isEmbedded && !bypassGraphicsProxyWidget(q)) {
7825  QGraphicsProxyWidget *ancestorProxy = nearestGraphicsProxyWidget(q->parentWidget());
7826  if (ancestorProxy) {
7827  isEmbedded = true;
7828  ancestorProxy->d_func()->embedSubWindow(q);
7829  }
7830  }
7831  }
7832 #else
7833  Q_UNUSED(isEmbedded);
7834 #endif
7835 
7836  // On Windows, show the popup now so that our own focus handling
7837  // stores the correct old focus widget even if it's stolen in the
7838  // showevent
7839 #if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_OS_SYMBIAN)
7840  if (!isEmbedded && q->windowType() == Qt::Popup)
7841  qApp->d_func()->openPopup(q);
7842 #endif
7843 
7844  // send the show event before showing the window
7846  QApplication::sendEvent(q, &showEvent);
7847 
7848  if (!isEmbedded && q->isModal() && q->isWindow())
7849  // QApplicationPrivate::enterModal *before* show, otherwise the initial
7850  // stacking might be wrong
7852 
7853 
7854  show_sys();
7855 
7856 #if !defined(Q_WS_WIN) && !defined(Q_WS_MAC) && !defined(Q_OS_SYMBIAN)
7857  if (!isEmbedded && q->windowType() == Qt::Popup)
7858  qApp->d_func()->openPopup(q);
7859 #endif
7860 
7861 #ifndef QT_NO_ACCESSIBILITY
7862  if (q->windowType() != Qt::ToolTip) // Tooltips are read aloud twice in MS narrator.
7864 #endif
7865 
7869  }
7870 
7871  // Process events when showing a Qt::SplashScreen widget before the event loop
7872  // is spinnning; otherwise it might not show up on particular platforms.
7873  // This makes QSplashScreen behave the same on all platforms.
7874  if (!qApp->d_func()->in_exec && q->windowType() == Qt::SplashScreen)
7876 
7877  data.in_show = false; // reset qws optimization
7878 }
7879 
7899 {
7900  Q_Q(QWidget);
7901 
7902  bool isEmbedded = false;
7903 #if !defined QT_NO_GRAPHICSVIEW
7904  isEmbedded = q->isWindow() && !bypassGraphicsProxyWidget(q) && nearestGraphicsProxyWidget(q->parentWidget()) != 0;
7905 #else
7906  Q_UNUSED(isEmbedded);
7907 #endif
7908 
7909  if (!isEmbedded && (q->windowType() == Qt::Popup))
7910  qApp->d_func()->closePopup(q);
7911 
7912  // Move test modal here. Otherwise, a modal dialog could get
7913  // destroyed and we lose all access to its parent because we haven't
7914  // left modality. (Eg. modal Progress Dialog)
7915  if (!isEmbedded && q->isModal() && q->isWindow())
7917 
7918 #if defined(Q_WS_WIN)
7919  if (q->isWindow() && !(q->windowType() == Qt::Popup) && q->parentWidget()
7920  && !q->parentWidget()->isHidden() && q->isActiveWindow())
7921  q->parentWidget()->activateWindow(); // Activate parent
7922 #endif
7923 
7924  q->setAttribute(Qt::WA_Mapped, false);
7925  hide_sys();
7926 
7927  bool wasVisible = q->testAttribute(Qt::WA_WState_Visible);
7928 
7929  if (wasVisible) {
7930  q->setAttribute(Qt::WA_WState_Visible, false);
7931 
7932  }
7933 
7935  QApplication::sendEvent(q, &hideEvent);
7936  hideChildren(false);
7937 
7938  // next bit tries to move the focus if the focus widget is now
7939  // hidden.
7940  if (wasVisible) {
7941 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_MAC) || defined(Q_WS_QPA)
7942  qApp->d_func()->sendSyntheticEnterLeave(q);
7943 #endif
7944 
7946  while (fw && !fw->isWindow()) {
7947  if (fw == q) {
7948  q->focusNextPrevChild(true);
7949  break;
7950  }
7951  fw = fw->parentWidget();
7952  }
7953  }
7954 
7955  if (QWidgetBackingStore *bs = maybeBackingStore())
7956  bs->removeDirtyWidget(q);
7957 
7958 #ifndef QT_NO_ACCESSIBILITY
7959  if (wasVisible)
7961 #endif
7962 }
7963 
7992 {
7993  if (visible) { // show
7995  return;
7996 
7997  Q_D(QWidget);
7998 
7999  // Designer uses a trick to make grabWidget work without showing
8000  if (!isWindow() && parentWidget() && parentWidget()->isVisible()
8002  parentWidget()->window()->d_func()->createRecursively();
8003 
8004  //we have to at least create toplevels before applyX11SpecificCommandLineArguments
8005  //but not children of non-visible parents
8006  QWidget *pw = parentWidget();
8008  && (isWindow() || pw->testAttribute(Qt::WA_WState_Created))) {
8009  create();
8010  }
8011 
8012 #if defined(Q_WS_X11)
8013  if (windowType() == Qt::Window)
8015 #elif defined(Q_WS_QWS)
8016  if (windowType() == Qt::Window)
8017  QApplicationPrivate::applyQWSSpecificCommandLineArguments(this);
8018 #endif
8019 
8020  bool wasResized = testAttribute(Qt::WA_Resized);
8021  Qt::WindowStates initialWindowState = windowState();
8022 
8023  // polish if necessary
8024  ensurePolished();
8025 
8026  // remember that show was called explicitly
8028  // whether we need to inform the parent widget immediately
8029  bool needUpdateGeometry = !isWindow() && testAttribute(Qt::WA_WState_Hidden);
8030  // we are no longer hidden
8032 
8033  if (needUpdateGeometry)
8034  d->updateGeometry_helper(true);
8035 
8036 #ifdef QT3_SUPPORT
8037  QApplication::sendPostedEvents(this, QEvent::ChildInserted);
8038 #endif
8039  // activate our layout before we and our children become visible
8040  if (d->layout)
8041  d->layout->activate();
8042 
8043  if (!isWindow()) {
8044  QWidget *parent = parentWidget();
8045  while (parent && parent->isVisible() && parent->d_func()->layout && !parent->data->in_show) {
8046  parent->d_func()->layout->activate();
8047  if (parent->isWindow())
8048  break;
8049  parent = parent->parentWidget();
8050  }
8051  if (parent)
8052  parent->d_func()->setDirtyOpaqueRegion();
8053  }
8054 
8055  // adjust size if necessary
8056  if (!wasResized
8057  && (isWindow() || !parentWidget()->d_func()->layout)) {
8058  if (isWindow()) {
8059  adjustSize();
8060  if (windowState() != initialWindowState)
8061  setWindowState(initialWindowState);
8062  } else {
8063  adjustSize();
8064  }
8065  setAttribute(Qt::WA_Resized, false);
8066  }
8067 
8069 
8070  if (isWindow() || parentWidget()->isVisible()) {
8071  // remove posted quit events when showing a new window
8073 
8074  d->show_helper();
8075 
8076 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_MAC) || defined(Q_WS_QPA)
8077  qApp->d_func()->sendSyntheticEnterLeave(this);
8078 #endif
8079  }
8080 
8081  QEvent showToParentEvent(QEvent::ShowToParent);
8082  QApplication::sendEvent(this, &showToParentEvent);
8083  } else { // hide
8085  return;
8086 #if defined(Q_WS_WIN)
8087  // reset WS_DISABLED style in a Blocked window
8090  {
8091  LONG dwStyle = GetWindowLong(winId(), GWL_STYLE);
8092  dwStyle &= ~WS_DISABLED;
8093  SetWindowLong(winId(), GWL_STYLE, dwStyle);
8094  }
8095 #endif
8098 
8099  Q_D(QWidget);
8100 
8101  // hw: The test on getOpaqueRegion() needs to be more intelligent
8102  // currently it doesn't work if the widget is hidden (the region will
8103  // be clipped). The real check should be testing the cached region
8104  // (and dirty flag) directly.
8105  if (!isWindow() && parentWidget()) // && !d->getOpaqueRegion().isEmpty())
8106  parentWidget()->d_func()->setDirtyOpaqueRegion();
8107 
8111  d->hide_helper();
8112 
8113  // invalidate layout similar to updateGeometry()
8114  if (!isWindow() && parentWidget()) {
8115  if (parentWidget()->d_func()->layout)
8116  parentWidget()->d_func()->layout->invalidate();
8117  else if (parentWidget()->isVisible())
8119  }
8120 
8121  QEvent hideToParentEvent(QEvent::HideToParent);
8122  QApplication::sendEvent(this, &hideToParentEvent);
8123  }
8124 }
8125 
8138 {
8139  Q_Q(QWidget);
8140  if ( !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide)) )
8141  q->setVisible(true);
8142 }
8143 
8144 void QWidgetPrivate::showChildren(bool spontaneous)
8145 {
8146  QList<QObject*> childList = children;
8147  for (int i = 0; i < childList.size(); ++i) {
8148  QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
8149  if (!widget
8150  || widget->isWindow()
8151  || widget->testAttribute(Qt::WA_WState_Hidden))
8152  continue;
8153  if (spontaneous) {
8154  widget->setAttribute(Qt::WA_Mapped);
8155  widget->d_func()->showChildren(true);
8156  QShowEvent e;
8158  } else {
8160  widget->d_func()->show_recursive();
8161  else
8162  widget->show();
8163  }
8164  }
8165 }
8166 
8167 void QWidgetPrivate::hideChildren(bool spontaneous)
8168 {
8169  QList<QObject*> childList = children;
8170  for (int i = 0; i < childList.size(); ++i) {
8171  QWidget *widget = qobject_cast<QWidget*>(childList.at(i));
8172  if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_WState_Hidden))
8173  continue;
8174 #ifdef QT_MAC_USE_COCOA
8175  // Before doing anything we need to make sure that we don't leave anything in a non-consistent state.
8176  // When hiding a widget we need to make sure that no mouse_down events are active, because
8177  // the mouse_up event will never be received by a hidden widget or one of its descendants.
8178  // The solution is simple, before going through with this we check if there are any mouse_down events in
8179  // progress, if so we check if it is related to this widget or not. If so, we just reset the mouse_down and
8180  // then we continue.
8181  // In X11 and Windows we send a mouse_release event, however we don't do that here because we were already
8182  // ignoring that from before. I.e. Carbon did not send the mouse release event, so we will not send the
8183  // mouse release event. There are two ways to interpret this:
8184  // 1. If we don't send the mouse release event, the widget might get into an inconsistent state, i.e. it
8185  // might be waiting for a release event that will never arrive.
8186  // 2. If we send the mouse release event, then the widget might decide to trigger an action that is not
8187  // supposed to trigger because it is not visible.
8188  if(widget == qt_button_down)
8189  qt_button_down = 0;
8190 #endif // QT_MAC_USE_COCOA
8191  if (spontaneous)
8192  widget->setAttribute(Qt::WA_Mapped, false);
8193  else
8194  widget->setAttribute(Qt::WA_WState_Visible, false);
8195  widget->d_func()->hideChildren(spontaneous);
8196  QHideEvent e;
8197  if (spontaneous) {
8199  } else {
8200  QApplication::sendEvent(widget, &e);
8201  if (widget->internalWinId()
8203  // hide_sys() on an ancestor won't have any affect on this
8204  // widget, so it needs an explicit hide_sys() of its own
8205  widget->d_func()->hide_sys();
8206  }
8207  }
8208 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined (Q_WS_QWS) || defined(Q_WS_MAC) || defined(Q_WS_QPA)
8209  qApp->d_func()->sendSyntheticEnterLeave(widget);
8210 #endif
8211 #ifndef QT_NO_ACCESSIBILITY
8212  if (!spontaneous)
8214 #endif
8215  }
8216 }
8217 
8219 {
8220  if (data.is_closing)
8221  return true;
8222 
8223  Q_Q(QWidget);
8224  data.is_closing = 1;
8225 
8226  QPointer<QWidget> that = q;
8228 
8229 #ifdef QT3_SUPPORT
8230  bool isMain = (QApplicationPrivate::main_widget == q);
8231 #endif
8232  bool quitOnClose = q->testAttribute(Qt::WA_QuitOnClose);
8233  if (mode != CloseNoEvent) {
8234  QCloseEvent e;
8235  if (mode == CloseWithSpontaneousEvent)
8237  else
8238  QApplication::sendEvent(q, &e);
8239  if (!that.isNull() && !e.isAccepted()) {
8240  data.is_closing = 0;
8241  return false;
8242  }
8243  }
8244 
8245  if (!that.isNull() && !q->isHidden())
8246  q->hide();
8247 
8248 #ifdef QT3_SUPPORT
8249  if (isMain)
8251 #endif
8252  // Attempt to close the application only if this has WA_QuitOnClose set and a non-visible parent
8253  quitOnClose = quitOnClose && (parentWidget.isNull() || !parentWidget->isVisible());
8254 
8255  if (quitOnClose) {
8256  /* if there is no non-withdrawn primary window left (except
8257  the ones without QuitOnClose), we emit the lastWindowClosed
8258  signal */
8260  bool lastWindowClosed = true;
8261  for (int i = 0; i < list.size(); ++i) {
8262  QWidget *w = list.at(i);
8263  if (!w->isVisible() || w->parentWidget() || !w->testAttribute(Qt::WA_QuitOnClose))
8264  continue;
8265  lastWindowClosed = false;
8266  break;
8267  }
8268  if (lastWindowClosed)
8270  }
8271 
8272  if (!that.isNull()) {
8273  data.is_closing = 0;
8274  if (q->testAttribute(Qt::WA_DeleteOnClose)) {
8275  q->setAttribute(Qt::WA_DeleteOnClose, false);
8276  q->deleteLater();
8277  }
8278  }
8279  return true;
8280 }
8281 
8282 
8306 {
8307  return d_func()->close_helper(QWidgetPrivate::CloseWithEvent);
8308 }
8309 
8371 bool QWidget::isVisibleTo(QWidget* ancestor) const
8372 {
8373  if (!ancestor)
8374  return isVisible();
8375  const QWidget * w = this;
8376  while (!w->isHidden()
8377  && !w->isWindow()
8378  && w->parentWidget()
8379  && w->parentWidget() != ancestor)
8380  w = w->parentWidget();
8381  return !w->isHidden();
8382 }
8383 
8384 #ifdef QT3_SUPPORT
8385 
8388 QRect QWidget::visibleRect() const
8389 {
8390  return d_func()->clipRect();
8391 }
8392 #endif
8393 
8405 {
8406  Q_D(const QWidget);
8407 
8408  QRect clipRect = d->clipRect();
8409  if (clipRect.isEmpty())
8410  return QRegion();
8411  QRegion r(clipRect);
8412  d->subtractOpaqueChildren(r, clipRect);
8413  d->subtractOpaqueSiblings(r);
8414 #ifdef Q_WS_QWS
8415  const QWSWindowSurface *surface = static_cast<const QWSWindowSurface*>(windowSurface());
8416  if (surface) {
8417  const QPoint offset = mapTo(surface->window(), QPoint());
8418  r &= surface->clipRegion().translated(-offset);
8419  }
8420 #endif
8421  return r;
8422 }
8423 
8424 
8426 {
8427  Q_Q(const QWidget);
8428 
8429  QSize s = q->sizeHint();
8430 
8431  if (q->isWindow()) {
8432  Qt::Orientations exp;
8433  if (layout) {
8434  if (layout->hasHeightForWidth())
8436  exp = layout->expandingDirections();
8437  } else
8438  {
8439  if (q->sizePolicy().hasHeightForWidth())
8440  s.setHeight(q->heightForWidth(s.width()));
8441  exp = q->sizePolicy().expandingDirections();
8442  }
8443  if (exp & Qt::Horizontal)
8444  s.setWidth(qMax(s.width(), 200));
8445  if (exp & Qt::Vertical)
8446  s.setHeight(qMax(s.height(), 100));
8447 #if defined(Q_WS_X11)
8448  QRect screen = QApplication::desktop()->screenGeometry(q->x11Info().screen());
8449 #else // all others
8450  QRect screen = QApplication::desktop()->screenGeometry(q->pos());
8451 #endif
8452 #if defined (Q_WS_WINCE) || defined (Q_OS_SYMBIAN)
8453  s.setWidth(qMin(s.width(), screen.width()));
8454  s.setHeight(qMin(s.height(), screen.height()));
8455 #else
8456  s.setWidth(qMin(s.width(), screen.width()*2/3));
8457  s.setHeight(qMin(s.height(), screen.height()*2/3));
8458 #endif
8459  if (QTLWExtra *extra = maybeTopData())
8460  extra->sizeAdjusted = true;
8461  }
8462 
8463  if (!s.isValid()) {
8464  QRect r = q->childrenRect(); // get children rectangle
8465  if (r.isNull())
8466  return s;
8467  s = r.size() + QSize(2 * r.x(), 2 * r.y());
8468  }
8469 
8470  return s;
8471 }
8472 
8489 {
8490  Q_D(QWidget);
8491  ensurePolished();
8492  QSize s = d->adjustedSize();
8493 
8494  if (d->layout)
8495  d->layout->activate();
8496 
8497  if (s.isValid())
8498  resize(s);
8499 }
8500 
8501 
8520 QSize QWidget::sizeHint() const
8521 {
8522  Q_D(const QWidget);
8523  if (d->layout)
8524  return d->layout->totalSizeHint();
8525  return QSize(-1, -1);
8526 }
8527 
8551 {
8552  Q_D(const QWidget);
8553  if (d->layout)
8554  return d->layout->totalMinimumSize();
8555  return QSize(-1, -1);
8556 }
8557 
8558 
8573 bool QWidget::isAncestorOf(const QWidget *child) const
8574 {
8575  while (child) {
8576  if (child == this)
8577  return true;
8578  if (child->isWindow())
8579  return false;
8580  child = child->parentWidget();
8581  }
8582  return false;
8583 }
8584 
8585 #if defined(Q_WS_WIN)
8586 inline void setDisabledStyle(QWidget *w, bool setStyle)
8587 {
8588  // set/reset WS_DISABLED style.
8589  if(w && w->isWindow() && w->isVisible() && w->isEnabled()) {
8590  LONG dwStyle = GetWindowLong(w->winId(), GWL_STYLE);
8591  LONG newStyle = dwStyle;
8592  if (setStyle)
8593  newStyle |= WS_DISABLED;
8594  else
8595  newStyle &= ~WS_DISABLED;
8596  if (newStyle != dwStyle) {
8597  SetWindowLong(w->winId(), GWL_STYLE, newStyle);
8598  // we might need to repaint in some situations (eg. menu)
8599  w->repaint();
8600  }
8601  }
8602 }
8603 #endif
8604 
8605 /*****************************************************************************
8606  QWidget event handling
8607  *****************************************************************************/
8608 
8637 {
8638  Q_D(QWidget);
8639 
8640  // ignore mouse events when disabled
8641  if (!isEnabled()) {
8642  switch(event->type()) {
8643  case QEvent::TabletPress:
8644  case QEvent::TabletRelease:
8645  case QEvent::TabletMove:
8649  case QEvent::MouseMove:
8650  case QEvent::TouchBegin:
8651  case QEvent::TouchUpdate:
8652  case QEvent::TouchEnd:
8653  case QEvent::ContextMenu:
8654 #ifndef QT_NO_WHEELEVENT
8655  case QEvent::Wheel:
8656 #endif
8657  return false;
8658  default:
8659  break;
8660  }
8661  }
8662  switch (event->type()) {
8663  case QEvent::MouseMove:
8664  mouseMoveEvent((QMouseEvent*)event);
8665  break;
8666 
8668  // Don't reset input context here. Whether reset or not is
8669  // a responsibility of input method. reset() will be
8670  // called by mouseHandler() of input method if necessary
8671  // via mousePressEvent() of text widgets.
8672 #if 0
8674 #endif
8675  mousePressEvent((QMouseEvent*)event);
8676  break;
8677 
8679  mouseReleaseEvent((QMouseEvent*)event);
8680  break;
8681 
8684  break;
8685 
8687  QWidget* w;
8688  while ((w = QApplication::activePopupWidget()) && w != this) {
8689  w->close();
8690  if (QApplication::activePopupWidget() == w) // widget does not want to disappear
8691  w->hide(); // hide at least
8692  }
8693  break;
8694  }
8695 
8696 #ifndef QT_NO_WHEELEVENT
8697  case QEvent::Wheel:
8698  wheelEvent((QWheelEvent*)event);
8699  break;
8700 #endif
8701 #ifndef QT_NO_TABLETEVENT
8702  case QEvent::TabletMove:
8703  case QEvent::TabletPress:
8704  case QEvent::TabletRelease:
8705  tabletEvent((QTabletEvent*)event);
8706  break;
8707 #endif
8708 #ifdef QT3_SUPPORT
8709  case QEvent::Accel:
8710  event->ignore();
8711  return false;
8712 #endif
8713  case QEvent::KeyPress: {
8714  QKeyEvent *k = (QKeyEvent *)event;
8715  bool res = false;
8716  if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
8717  if (k->key() == Qt::Key_Backtab
8718  || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier)))
8719  res = focusNextPrevChild(false);
8720  else if (k->key() == Qt::Key_Tab)
8721  res = focusNextPrevChild(true);
8722  if (res)
8723  break;
8724  }
8725  keyPressEvent(k);
8726 #ifdef QT_KEYPAD_NAVIGATION
8727  if (!k->isAccepted() && QApplication::keypadNavigationEnabled()
8729  if (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder) {
8730  if (k->key() == Qt::Key_Up)
8731  res = focusNextPrevChild(false);
8732  else if (k->key() == Qt::Key_Down)
8733  res = focusNextPrevChild(true);
8734  } else if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
8735  if (k->key() == Qt::Key_Up)
8736  res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionNorth);
8737  else if (k->key() == Qt::Key_Right)
8738  res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionEast);
8739  else if (k->key() == Qt::Key_Down)
8740  res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionSouth);
8741  else if (k->key() == Qt::Key_Left)
8742  res = QWidgetPrivate::navigateToDirection(QWidgetPrivate::DirectionWest);
8743  }
8744  if (res) {
8745  k->accept();
8746  break;
8747  }
8748  }
8749 #endif
8750 #ifndef QT_NO_WHATSTHIS
8751  if (!k->isAccepted()
8752  && k->modifiers() & Qt::ShiftModifier && k->key() == Qt::Key_F1
8753  && d->whatsThis.size()) {
8755  k->accept();
8756  }
8757 #endif
8758  }
8759  break;
8760 
8761  case QEvent::KeyRelease:
8762  keyReleaseEvent((QKeyEvent*)event);
8763  // fall through
8765  break;
8766 
8767  case QEvent::InputMethod:
8769  break;
8770 
8771  case QEvent::PolishRequest:
8772  ensurePolished();
8773  break;
8774 
8775  case QEvent::Polish: {
8776  style()->polish(this);
8778  if (!QApplication::font(this).isCopyOf(QApplication::font()))
8779  d->resolveFont();
8780  if (!QApplication::palette(this).isCopyOf(QApplication::palette()))
8781  d->resolvePalette();
8782 #ifdef QT3_SUPPORT
8783  if(d->sendChildEvents)
8784  QApplication::sendPostedEvents(this, QEvent::ChildInserted);
8785 #endif
8786  }
8787  break;
8788 
8791  d->setWindowIcon_sys();
8792  d->setWindowIcon_helper();
8793  }
8794  break;
8795  case QEvent::FocusIn:
8796 #ifdef QT_SOFTKEYS_ENABLED
8798 #endif
8799  focusInEvent((QFocusEvent*)event);
8800  break;
8801 
8802  case QEvent::FocusOut:
8803  focusOutEvent((QFocusEvent*)event);
8804  break;
8805 
8806  case QEvent::Enter:
8807 #ifndef QT_NO_STATUSTIP
8808  if (d->statusTip.size()) {
8809  QStatusTipEvent tip(d->statusTip);
8810  QApplication::sendEvent(const_cast<QWidget *>(this), &tip);
8811  }
8812 #endif
8813  enterEvent(event);
8814  break;
8815 
8816  case QEvent::Leave:
8817 #ifndef QT_NO_STATUSTIP
8818  if (d->statusTip.size()) {
8819  QString empty;
8820  QStatusTipEvent tip(empty);
8821  QApplication::sendEvent(const_cast<QWidget *>(this), &tip);
8822  }
8823 #endif
8824  leaveEvent(event);
8825  break;
8826 
8827  case QEvent::HoverEnter:
8828  case QEvent::HoverLeave:
8829  update();
8830  break;
8831 
8832  case QEvent::Paint:
8833  // At this point the event has to be delivered, regardless
8834  // whether the widget isVisible() or not because it
8835  // already went through the filters
8836  paintEvent((QPaintEvent*)event);
8837  break;
8838 
8839  case QEvent::Move:
8840  moveEvent((QMoveEvent*)event);
8841  break;
8842 
8843  case QEvent::Resize:
8844  resizeEvent((QResizeEvent*)event);
8845  break;
8846 
8847  case QEvent::Close:
8848  closeEvent((QCloseEvent *)event);
8849  break;
8850 
8851 #ifndef QT_NO_CONTEXTMENU
8852  case QEvent::ContextMenu:
8853  switch (data->context_menu_policy) {
8855  break;
8857  contextMenuEvent(static_cast<QContextMenuEvent *>(event));
8858  break;
8859  case Qt::CustomContextMenu:
8860  emit customContextMenuRequested(static_cast<QContextMenuEvent *>(event)->pos());
8861  break;
8862 #ifndef QT_NO_MENU
8864  if (d->actions.count()) {
8865  QMenu::exec(d->actions, static_cast<QContextMenuEvent *>(event)->globalPos(),
8866  0, this);
8867  break;
8868  }
8869  // fall through
8870 #endif
8871  default:
8872  event->ignore();
8873  break;
8874  }
8875  break;
8876 #endif // QT_NO_CONTEXTMENU
8877 
8878 #ifndef QT_NO_DRAGANDDROP
8879  case QEvent::Drop:
8880  dropEvent((QDropEvent*) event);
8881  break;
8882 
8883  case QEvent::DragEnter:
8884  dragEnterEvent((QDragEnterEvent*) event);
8885  break;
8886 
8887  case QEvent::DragMove:
8888  dragMoveEvent((QDragMoveEvent*) event);
8889  break;
8890 
8891  case QEvent::DragLeave:
8892  dragLeaveEvent((QDragLeaveEvent*) event);
8893  break;
8894 #endif
8895 
8896  case QEvent::Show:
8897  showEvent((QShowEvent*) event);
8898  break;
8899 
8900  case QEvent::Hide:
8901  hideEvent((QHideEvent*) event);
8902  break;
8903 
8905  if (!isHidden())
8906  d->show_sys();
8907  break;
8908 
8910  d->resolveFont();
8911  break;
8913  if (!(windowType() == Qt::Desktop))
8914  d->resolvePalette();
8915  break;
8916 
8917  case QEvent::ToolBarChange:
8919  case QEvent::EnabledChange:
8920  case QEvent::FontChange:
8921  case QEvent::StyleChange:
8922  case QEvent::PaletteChange:
8927  case QEvent::ParentChange:
8929  case QEvent::LocaleChange:
8930  case QEvent::MacSizeChange:
8932  changeEvent(event);
8933  break;
8934 
8936  case QEvent::WindowDeactivate: {
8937 #ifdef QT3_SUPPORT
8939 #endif
8941  update();
8942  QList<QObject*> childList = d->children;
8943  for (int i = 0; i < childList.size(); ++i) {
8944  QWidget *w = qobject_cast<QWidget *>(childList.at(i));
8945  if (w && w->isVisible() && !w->isWindow())
8946  QApplication::sendEvent(w, event);
8947  }
8948 
8949 #ifdef QT_SOFTKEYS_ENABLED
8950  if (isWindow())
8952 #endif
8953 
8954  break; }
8955 
8957 #ifdef QT3_SUPPORT
8958  languageChange();
8959 #endif
8960  changeEvent(event);
8961  {
8962  QList<QObject*> childList = d->children;
8963  for (int i = 0; i < childList.size(); ++i) {
8964  QObject *o = childList.at(i);
8965  if (o)
8966  QApplication::sendEvent(o, event);
8967  }
8968  }
8969  update();
8970  break;
8971 
8973  d->resolveLayoutDirection();
8974  break;
8975 
8977  if (d->layout)
8978  d->layout->invalidate();
8979  update();
8980  changeEvent(event);
8981  break;
8982  case QEvent::UpdateRequest:
8983  d->syncBackingStore();
8984  break;
8985  case QEvent::UpdateLater:
8986  update(static_cast<QUpdateLaterEvent*>(event)->region());
8987  break;
8988 
8989  case QEvent::WindowBlocked:
8991  {
8992  QList<QObject*> childList = d->children;
8993  for (int i = 0; i < childList.size(); ++i) {
8994  QObject *o = childList.at(i);
8995  if (o && o != QApplication::activeModalWidget()) {
8996  if (qobject_cast<QWidget *>(o) && static_cast<QWidget *>(o)->isWindow()) {
8997  // do not forward the event to child windows,
8998  // QApplication does this for us
8999  continue;
9000  }
9001  QApplication::sendEvent(o, event);
9002  }
9003  }
9004 #if defined(Q_WS_WIN)
9005  setDisabledStyle(this, (event->type() == QEvent::WindowBlocked));
9006 #endif
9007  }
9008  break;
9009 #ifndef QT_NO_TOOLTIP
9010  case QEvent::ToolTip:
9011  if (!d->toolTip.isEmpty())
9012  QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), d->toolTip, this);
9013  else
9014  event->ignore();
9015  break;
9016 #endif
9017 #ifndef QT_NO_WHATSTHIS
9018  case QEvent::WhatsThis:
9019  if (d->whatsThis.size())
9020  QWhatsThis::showText(static_cast<QHelpEvent *>(event)->globalPos(), d->whatsThis, this);
9021  else
9022  event->ignore();
9023  break;
9025  if (d->whatsThis.isEmpty())
9026  event->ignore();
9027  break;
9028 #endif
9029 #ifndef QT_NO_ACCESSIBILITY
9032  QAccessibleEvent *ev = static_cast<QAccessibleEvent *>(event);
9033  if (ev->child())
9034  return false;
9035  switch (ev->type()) {
9036 #ifndef QT_NO_TOOLTIP
9038  ev->setValue(d->toolTip);
9039  break;
9040 #endif
9041 #ifndef QT_NO_WHATSTHIS
9043  ev->setValue(d->whatsThis);
9044  break;
9045 #endif
9046  default:
9047  return false;
9048  }
9049  break; }
9050 #endif
9052  d->topData()->frameStrut.setCoords(0 ,0, 0, 0);
9053  data->fstrut_dirty = false;
9054 #if defined(Q_WS_WIN) || defined(Q_WS_X11)
9055  d->topData()->embedded = 1;
9056 #endif
9057  break;
9058 #ifndef QT_NO_ACTION
9059  case QEvent::ActionAdded:
9060  case QEvent::ActionRemoved:
9061  case QEvent::ActionChanged:
9062 #ifdef QT_SOFTKEYS_ENABLED
9064 #endif
9065  actionEvent((QActionEvent*)event);
9066  break;
9067 #endif
9068 
9070  {
9071  changeEvent(event);
9072 
9073  // inform children of the change
9074  QList<QObject*> childList = d->children;
9075  for (int i = 0; i < childList.size(); ++i) {
9076  QWidget *w = qobject_cast<QWidget *>(childList.at(i));
9077  if (w && w->isVisible() && !w->isWindow())
9078  QApplication::sendEvent(w, event);
9079  }
9080  break;
9081  }
9082 #ifdef Q_WS_MAC
9084  d->needWindowChange = false;
9085  break;
9086 #endif
9087  case QEvent::TouchBegin:
9088  case QEvent::TouchUpdate:
9089  case QEvent::TouchEnd:
9090  {
9091 #ifndef Q_WS_MAC
9092  QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
9093  const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first();
9094  if (touchPoint.isPrimary() || touchEvent->deviceType() == QTouchEvent::TouchPad)
9095  break;
9096 
9097  // fake a mouse event!
9098  QEvent::Type eventType = QEvent::None;
9099  switch (touchEvent->type()) {
9100  case QEvent::TouchBegin:
9101  eventType = QEvent::MouseButtonPress;
9102  break;
9103  case QEvent::TouchUpdate:
9104  eventType = QEvent::MouseMove;
9105  break;
9106  case QEvent::TouchEnd:
9107  eventType = QEvent::MouseButtonRelease;
9108  break;
9109  default:
9110  Q_ASSERT(!true);
9111  break;
9112  }
9113  if (eventType == QEvent::None)
9114  break;
9115 
9116  QMouseEvent mouseEvent(eventType,
9117  touchPoint.pos().toPoint(),
9118  touchPoint.screenPos().toPoint(),
9121  touchEvent->modifiers());
9122  (void) QApplication::sendEvent(this, &mouseEvent);
9123 #endif // Q_WS_MAC
9124  break;
9125  }
9126 #ifndef QT_NO_GESTURES
9127  case QEvent::Gesture:
9128  event->ignore();
9129  break;
9130 #endif
9131 #ifndef QT_NO_PROPERTIES
9133  const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
9134  if (!qstrncmp(propName, "_q_customDpi", 12) && propName.length() == 13) {
9135  uint value = property(propName.constData()).toUInt();
9136  if (!d->extra)
9137  d->createExtra();
9138  const char axis = propName.at(12);
9139  if (axis == 'X')
9140  d->extra->customDpiX = value;
9141  else if (axis == 'Y')
9142  d->extra->customDpiY = value;
9143  d->updateFont(d->data.fnt);
9144  }
9145  // fall through
9146  }
9147 #endif
9148  default:
9149  return QObject::event(event);
9150  }
9151  return true;
9152 }
9153 
9171 {
9172  switch(event->type()) {
9173  case QEvent::EnabledChange:
9174  update();
9175 #ifndef QT_NO_ACCESSIBILITY
9177 #endif
9178  break;
9179 
9180  case QEvent::FontChange:
9181  case QEvent::StyleChange: {
9182  Q_D(QWidget);
9183  update();
9184  updateGeometry();
9185  if (d->layout)
9186  d->layout->invalidate();
9187 #ifdef Q_WS_QWS
9188  if (isWindow())
9189  d->data.fstrut_dirty = true;
9190 #endif
9191  break;
9192  }
9193 
9194  case QEvent::PaletteChange:
9195  update();
9196  break;
9197 
9198 #ifdef Q_WS_MAC
9199  case QEvent::MacSizeChange:
9200  updateGeometry();
9201  break;
9202  case QEvent::ToolTipChange:
9205  break;
9206 #endif
9207 
9208  default:
9209  break;
9210  }
9211 }
9212 
9240 {
9241  event->ignore();
9242 }
9243 
9262 {
9263  event->ignore();
9264  if ((windowType() == Qt::Popup)) {
9265  event->accept();
9266  QWidget* w;
9267  while ((w = QApplication::activePopupWidget()) && w != this){
9268  w->close();
9269  if (QApplication::activePopupWidget() == w) // widget does not want to disappear
9270  w->hide(); // hide at least
9271  }
9272  if (!rect().contains(event->pos())){
9273  close();
9274  }
9275  }
9276 }
9277 
9287 {
9288  event->ignore();
9289 }
9290 
9307 {
9308  mousePressEvent(event); // try mouse press event
9309 }
9310 
9311 #ifndef QT_NO_WHEELEVENT
9312 
9327 {
9328  event->ignore();
9329 }
9330 #endif // QT_NO_WHEELEVENT
9331 
9332 #ifndef QT_NO_TABLETEVENT
9333 
9348 {
9349  event->ignore();
9350 }
9351 #endif // QT_NO_TABLETEVENT
9352 
9376 {
9377  if ((windowType() == Qt::Popup) && event->key() == Qt::Key_Escape) {
9378  event->accept();
9379  close();
9380  } else {
9381  event->ignore();
9382  }
9383 }
9384 
9408 {
9409  event->ignore();
9410 }
9411 
9432 {
9433  if (focusPolicy() != Qt::NoFocus || !isWindow()) {
9434  update();
9435  }
9436 }
9437 
9458 {
9459  if (focusPolicy() != Qt::NoFocus || !isWindow())
9460  update();
9461 }
9462 
9476 {
9477 }
9478 
9492 {
9493 }
9494 
9549 {
9550 }
9551 
9552 
9567 {
9568 }
9569 
9570 
9588 {
9589 }
9590 
9591 #ifndef QT_NO_ACTION
9592 
9601 {
9602 
9603 }
9604 #endif
9605 
9627 {
9628  event->accept();
9629 }
9630 
9631 #ifndef QT_NO_CONTEXTMENU
9632 
9646 {
9647  event->ignore();
9648 }
9649 #endif // QT_NO_CONTEXTMENU
9650 
9651 
9669 {
9670  event->ignore();
9671 }
9672 
9684 {
9685  switch(query) {
9686  case Qt::ImMicroFocus:
9687  return QRect(width()/2, 0, 1, height());
9688  case Qt::ImFont:
9689  return font();
9690  case Qt::ImAnchorPosition:
9691  // Fallback.
9693  default:
9694  return QVariant();
9695  }
9696 }
9697 
9722 Qt::InputMethodHints QWidget::inputMethodHints() const
9723 {
9724 #ifndef QT_NO_IM
9725  const QWidgetPrivate *priv = d_func();
9726  while (priv->inheritsInputMethodHints) {
9727  priv = priv->q_func()->parentWidget()->d_func();
9728  Q_ASSERT(priv);
9729  }
9730  return priv->imHints;
9731 #else //QT_NO_IM
9732  return 0;
9733 #endif //QT_NO_IM
9734 }
9735 
9736 void QWidget::setInputMethodHints(Qt::InputMethodHints hints)
9737 {
9738 #ifndef QT_NO_IM
9739  Q_D(QWidget);
9740  if (d->imHints == hints)
9741  return;
9742  d->imHints = hints;
9743  // Optimization to update input context only it has already been created.
9744  if (d->ic || qApp->d_func()->inputContext) {
9745  QInputContext *ic = inputContext();
9746  if (ic)
9747  ic->update();
9748  }
9749 #endif //QT_NO_IM
9750 }
9751 
9752 
9753 #ifndef QT_NO_DRAGANDDROP
9754 
9769 {
9770 }
9771 
9787 {
9788 }
9789 
9803 {
9804 }
9805 
9818 {
9819 }
9820 
9821 #endif // QT_NO_DRAGANDDROP
9822 
9843 {
9844 }
9845 
9865 {
9866 }
9867 
9868 /*
9869  \fn QWidget::x11Event(MSG *)
9870 
9871  This special event handler can be reimplemented in a subclass to receive
9872  native X11 events.
9873 
9874  In your reimplementation of this function, if you want to stop Qt from
9875  handling the event, return true. If you return false, this native event
9876  is passed back to Qt, which translates it into a Qt event and sends it to
9877  the widget.
9878 
9879  \note Events are only delivered to this event handler if the widget is
9880  native.
9881 
9882  \warning This function is not portable.
9883 
9884  \sa QApplication::x11EventFilter(), QWidget::winId()
9885 */
9886 
9887 
9888 #if defined(Q_WS_MAC)
9889 
9919 {
9920  return false;
9921 }
9922 
9923 #endif
9924 #if defined(Q_WS_WIN)
9925 
9941 bool QWidget::winEvent(MSG *message, long *result)
9942 {
9943  Q_UNUSED(message);
9944  Q_UNUSED(result);
9945  return false;
9946 }
9947 
9948 #endif
9949 #if defined(Q_WS_X11)
9950 
9970 {
9971  return false;
9972 }
9973 
9974 #endif
9975 #if defined(Q_WS_QWS)
9976 
9994 {
9995  return false;
9996 }
9997 
9998 #endif
9999 
10000 
10025 {
10026  Q_D(const QWidget);
10027 
10028  const QMetaObject *m = metaObject();
10029  if (m == d->polished)
10030  return;
10031  d->polished = m;
10032 
10034  QCoreApplication::sendEvent(const_cast<QWidget *>(this), &e);
10035 
10036  // polish children after 'this'
10037  QList<QObject*> children = d->children;
10038  for (int i = 0; i < children.size(); ++i) {
10039  QObject *o = children.at(i);
10040  if(!o->isWidgetType())
10041  continue;
10042  if (QWidget *w = qobject_cast<QWidget *>(o))
10043  w->ensurePolished();
10044  }
10045 
10046  if (d->parent && d->sendChildEvents) {
10047  QChildEvent e(QEvent::ChildPolished, const_cast<QWidget *>(this));
10048  QCoreApplication::sendEvent(d->parent, &e);
10049  }
10050 }
10051 
10059 {
10060  Q_D(const QWidget);
10061  return d->extra ? d->extra->mask : QRegion();
10062 }
10063 
10074 {
10075  return d_func()->layout;
10076 }
10077 
10078 
10105 {
10106  if (!l) {
10107  qWarning("QWidget::setLayout: Cannot set layout to 0");
10108  return;
10109  }
10110  if (layout()) {
10111  if (layout() != l)
10112  qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", which already has a"
10113  " layout", l->objectName().toLocal8Bit().data(), metaObject()->className(),
10114  objectName().toLocal8Bit().data());
10115  return;
10116  }
10117 
10118  QObject *oldParent = l->parent();
10119  if (oldParent && oldParent != this) {
10120  if (oldParent->isWidgetType()) {
10121  // Steal the layout off a widget parent. Takes effect when
10122  // morphing laid-out container widgets in Designer.
10123  QWidget *oldParentWidget = static_cast<QWidget *>(oldParent);
10124  oldParentWidget->takeLayout();
10125  } else {
10126  qWarning("QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent",
10128  objectName().toLocal8Bit().data());
10129  return;
10130  }
10131  }
10132 
10133  Q_D(QWidget);
10134  l->d_func()->topLevel = true;
10135  d->layout = l;
10136  if (oldParent != this) {
10137  l->setParent(this);
10138  l->d_func()->reparentChildWidgets(this);
10139  l->invalidate();
10140  }
10141 
10142  if (isWindow() && d->maybeTopData())
10143  d->topData()->sizeAdjusted = false;
10144 }
10145 
10154 {
10155  Q_D(QWidget);
10156  QLayout *l = layout();
10157  if (!l)
10158  return 0;
10159  d->layout = 0;
10160  l->setParent(0);
10161  return l;
10162 }
10163 
10193 {
10194  Q_D(const QWidget);
10195  return d->size_policy;
10196 }
10197 
10199 {
10200  Q_D(QWidget);
10202  if (policy == d->size_policy)
10203  return;
10204  d->size_policy = policy;
10205 
10206 #ifndef QT_NO_GRAPHICSVIEW
10207  if (QWExtra *extra = d->extra) {
10208  if (extra->proxyWidget)
10209  extra->proxyWidget->setSizePolicy(policy);
10210  }
10211 #endif
10212 
10213  updateGeometry();
10214 
10215  if (isWindow() && d->maybeTopData())
10216  d->topData()->sizeAdjusted = false;
10217 }
10218 
10241 int QWidget::heightForWidth(int w) const
10242 {
10243  if (layout() && layout()->hasHeightForWidth())
10244  return layout()->totalHeightForWidth(w);
10245  return -1;
10246 }
10247 
10248 
10261 {
10262  return layout ? layout->hasHeightForWidth() : size_policy.hasHeightForWidth();
10263 }
10264 
10284 {
10285  return d_func()->childAt_helper(p, false);
10286 }
10287 
10288 QWidget *QWidgetPrivate::childAt_helper(const QPoint &p, bool ignoreChildrenInDestructor) const
10289 {
10290  if (children.isEmpty())
10291  return 0;
10292 
10293 #ifdef Q_WS_MAC
10294  Q_Q(const QWidget);
10295  // Unified tool bars on the Mac require special handling since they live outside
10296  // QMainWindow's geometry(). See commit: 35667fd45ada49269a5987c235fdedfc43e92bb8
10297  bool includeFrame = q->isWindow() && qobject_cast<const QMainWindow *>(q)
10298  && static_cast<const QMainWindow *>(q)->unifiedTitleAndToolBarOnMac();
10299  if (includeFrame)
10300  return childAtRecursiveHelper(p, ignoreChildrenInDestructor, includeFrame);
10301 #endif
10302 
10303  if (!pointInsideRectAndMask(p))
10304  return 0;
10305  return childAtRecursiveHelper(p, ignoreChildrenInDestructor);
10306 }
10307 
10308 QWidget *QWidgetPrivate::childAtRecursiveHelper(const QPoint &p, bool ignoreChildrenInDestructor, bool includeFrame) const
10309 {
10310 #ifndef Q_WS_MAC
10311  Q_UNUSED(includeFrame);
10312 #endif
10313  for (int i = children.size() - 1; i >= 0; --i) {
10314  QWidget *child = qobject_cast<QWidget *>(children.at(i));
10315  if (!child || child->isWindow() || child->isHidden() || child->testAttribute(Qt::WA_TransparentForMouseEvents)
10316  || (ignoreChildrenInDestructor && child->data->in_destructor)) {
10317  continue;
10318  }
10319 
10320  // Map the point 'p' from parent coordinates to child coordinates.
10321  QPoint childPoint = p;
10322 #ifdef Q_WS_MAC
10323  // 'includeFrame' is true if the child's parent is a top-level QMainWindow with an unified tool bar.
10324  // An unified tool bar on the Mac lives outside QMainWindow's geometry(), so a normal
10325  // QWidget::mapFromParent won't do the trick.
10326  if (includeFrame && qobject_cast<QToolBar *>(child))
10327  childPoint = qt_mac_nativeMapFromParent(child, p);
10328  else
10329 #endif
10330  childPoint -= child->data->crect.topLeft();
10331 
10332  // Check if the point hits the child.
10333  if (!child->d_func()->pointInsideRectAndMask(childPoint))
10334  continue;
10335 
10336  // Do the same for the child's descendants.
10337  if (QWidget *w = child->d_func()->childAtRecursiveHelper(childPoint, ignoreChildrenInDestructor))
10338  return w;
10339 
10340  // We have found our target; namely the child at position 'p'.
10341  return child;
10342  }
10343  return 0;
10344 }
10345 
10347 {
10348  Q_Q(QWidget);
10349  if (widgetItem)
10350  widgetItem->invalidateSizeCache();
10351  QWidget *parent;
10352  if (forceUpdate || !extra || extra->minw != extra->maxw || extra->minh != extra->maxh) {
10353  if (!q->isWindow() && !q->isHidden() && (parent = q->parentWidget())) {
10354  if (parent->d_func()->layout)
10355  parent->d_func()->layout->invalidate();
10356  else if (parent->isVisible())
10358  }
10359  }
10360 }
10361 
10373 {
10374  Q_D(QWidget);
10375  d->updateGeometry_helper(false);
10376 }
10377 
10399 void QWidget::setWindowFlags(Qt::WindowFlags flags)
10400 {
10401  if (data->window_flags == flags)
10402  return;
10403 
10404  Q_D(QWidget);
10405 
10406  if ((data->window_flags | flags) & Qt::Window) {
10407  // the old type was a window and/or the new type is a window
10408  QPoint oldPos = pos();
10409  bool visible = isVisible();
10410  setParent(parentWidget(), flags);
10411 
10412  // if both types are windows or neither of them are, we restore
10413  // the old position
10414  if (!((data->window_flags ^ flags) & Qt::Window)
10415  && (visible || testAttribute(Qt::WA_Moved))) {
10416  move(oldPos);
10417  }
10418  // for backward-compatibility we change Qt::WA_QuitOnClose attribute value only when the window was recreated.
10419  d->adjustQuitOnCloseAttribute();
10420  } else {
10421  data->window_flags = flags;
10422  }
10423 }
10424 
10434 void QWidget::overrideWindowFlags(Qt::WindowFlags flags)
10435 {
10436  data->window_flags = flags;
10437 }
10438 
10480 {
10481  if (parent == parentWidget())
10482  return;
10484 }
10485 
10495 void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
10496 {
10497  Q_D(QWidget);
10498  d->inSetParent = true;
10499  bool resized = testAttribute(Qt::WA_Resized);
10500  bool wasCreated = testAttribute(Qt::WA_WState_Created);
10501  QWidget *oldtlw = window();
10502 
10503  QWidget *desktopWidget = 0;
10504  if (parent && parent->windowType() == Qt::Desktop)
10505  desktopWidget = parent;
10506  bool newParent = (parent != parentWidget()) || !wasCreated || desktopWidget;
10507 
10508 #if defined(Q_WS_X11) || defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_OS_SYMBIAN)
10509  if (newParent && parent && !desktopWidget) {
10511 #if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)
10512  // On Mac, toolbars inside the unified title bar will never overlap with
10513  // siblings in the content view. So we skip enforce native siblings in that case
10514  && !d->isInUnifiedToolbar && parentWidget() && parentWidget()->isWindow()
10515 #endif // Q_WS_MAC && QT_MAC_USE_COCOA
10516  )
10517  parent->d_func()->enforceNativeChildren();
10518  else if (parent->d_func()->nativeChildrenForced() || parent->testAttribute(Qt::WA_PaintOnScreen))
10520  }
10521 #endif
10522 
10523  if (wasCreated) {
10525  hide();
10527  }
10528  if (newParent) {
10530  QApplication::sendEvent(this, &e);
10531  }
10532  }
10533  if (newParent && isAncestorOf(focusWidget()))
10534  focusWidget()->clearFocus();
10535 
10536  QTLWExtra *oldTopExtra = window()->d_func()->maybeTopData();
10537  QWidgetBackingStoreTracker *oldBsTracker = oldTopExtra ? &oldTopExtra->backingStore : 0;
10538 
10539  d->setParent_sys(parent, f);
10540 
10541  QTLWExtra *topExtra = window()->d_func()->maybeTopData();
10542  QWidgetBackingStoreTracker *bsTracker = topExtra ? &topExtra->backingStore : 0;
10543  if (oldBsTracker && oldBsTracker != bsTracker)
10544  oldBsTracker->unregisterWidgetSubtree(this);
10545 
10546  if (desktopWidget)
10547  parent = 0;
10548 
10549 #ifdef Q_BACKINGSTORE_SUBSURFACES
10550  QTLWExtra *extra = d->maybeTopData();
10551  QWindowSurface *windowSurface = (extra ? extra->windowSurface : 0);
10552  if (newParent && windowSurface) {
10553  QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore();
10554  if (oldBs)
10555  oldBs->subSurfaces.removeAll(windowSurface);
10556 
10557  if (parent) {
10558  QWidgetBackingStore *newBs = parent->d_func()->maybeBackingStore();
10559  if (newBs)
10560  newBs->subSurfaces.append(windowSurface);
10561  }
10562  }
10563 #endif
10564 
10565  if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) {
10566  if (newParent)
10567  oldBs->removeDirtyWidget(this);
10568  // Move the widget and all its static children from
10569  // the old backing store to the new one.
10570  oldBs->moveStaticWidgets(this);
10571  }
10572 
10576  create();
10577 
10578  d->reparentFocusWidgets(oldtlw);
10579  setAttribute(Qt::WA_Resized, resized);
10581  && (!parent || !parent->testAttribute(Qt::WA_StyleSheet))) {
10582  d->resolveFont();
10583  d->resolvePalette();
10584  }
10585  d->resolveLayoutDirection();
10586  d->resolveLocale();
10587 
10588  // Note: GL widgets under WGL or EGL will always need a ParentChange
10589  // event to handle recreation/rebinding of the GL context, hence the
10590  // (f & Qt::MSWindowsOwnDC) clause (which is set on QGLWidgets on all
10591  // platforms).
10592  if (newParent
10593 #if defined(Q_WS_WIN) || defined(QT_OPENGL_ES)
10594  || (f & Qt::MSWindowsOwnDC)
10595 #endif
10596  ) {
10597  // propagate enabled updates enabled state to non-windows
10598  if (!isWindow()) {
10600  d->setEnabled_helper(parent ? parent->isEnabled() : true);
10602  d->setUpdatesEnabled_helper(parent ? parent->updatesEnabled() : true);
10603  }
10604  d->inheritStyle();
10605 
10606  // send and post remaining QObject events
10607  if (parent && d->sendChildEvents) {
10609  QApplication::sendEvent(parent, &e);
10610 #ifdef QT3_SUPPORT
10611  if (parent->d_func()->pendingChildInsertedEvents.isEmpty()) {
10612  QApplication::postEvent(parent,
10613  new QEvent(QEvent::ChildInsertedRequest),
10615  }
10616  parent->d_func()->pendingChildInsertedEvents.append(this);
10617 #endif
10618  }
10619 
10620 //### already hidden above ---> must probably do something smart on the mac
10621 // #ifdef Q_WS_MAC
10622 // extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp
10623 // if(!qt_mac_is_macdrawer(q)) //special case
10624 // q->setAttribute(Qt::WA_WState_Hidden);
10625 // #else
10626 // q->setAttribute(Qt::WA_WState_Hidden);
10627 //#endif
10628 
10629  if (parent && d->sendChildEvents && d->polished) {
10631  QCoreApplication::sendEvent(parent, &e);
10632  }
10633 
10635  QApplication::sendEvent(this, &e);
10636  }
10637 
10638  if (!wasCreated) {
10639  if (isWindow() || parentWidget()->isVisible())
10643  }
10644 
10645  d->updateIsOpaque();
10646 
10647 #ifndef QT_NO_GRAPHICSVIEW
10648  // Embed the widget into a proxy if the parent is embedded.
10649  // ### Doesn't handle reparenting out of an embedded widget.
10650  if (oldtlw->graphicsProxyWidget()) {
10651  if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(oldtlw))
10652  ancestorProxy->d_func()->unembedSubWindow(this);
10653  }
10654  if (isWindow() && parent && !graphicsProxyWidget() && !bypassGraphicsProxyWidget(this)) {
10655  if (QGraphicsProxyWidget *ancestorProxy = d->nearestGraphicsProxyWidget(parent))
10656  ancestorProxy->d_func()->embedSubWindow(this);
10657  }
10658 #endif
10659 
10660  d->inSetParent = false;
10661 }
10662 
10684 void QWidget::scroll(int dx, int dy)
10685 {
10686  if ((!updatesEnabled() && children().size() == 0) || !isVisible())
10687  return;
10688  if (dx == 0 && dy == 0)
10689  return;
10690  Q_D(QWidget);
10691 #ifndef QT_NO_GRAPHICSVIEW
10693  // Graphics View maintains its own dirty region as a list of rects;
10694  // until we can connect item updates directly to the view, we must
10695  // separately add a translated dirty region.
10696  if (!d->dirty.isEmpty()) {
10697  foreach (const QRect &rect, (d->dirty.translated(dx, dy)).rects())
10698  proxy->update(rect);
10699  }
10700  proxy->scroll(dx, dy, proxy->subWidgetRect(this));
10701  return;
10702  }
10703 #endif
10704  d->setDirtyOpaqueRegion();
10705  d->scroll_sys(dx, dy);
10706 }
10707 
10721 void QWidget::scroll(int dx, int dy, const QRect &r)
10722 {
10723 
10724  if ((!updatesEnabled() && children().size() == 0) || !isVisible())
10725  return;
10726  if (dx == 0 && dy == 0)
10727  return;
10728  Q_D(QWidget);
10729 #ifndef QT_NO_GRAPHICSVIEW
10731  // Graphics View maintains its own dirty region as a list of rects;
10732  // until we can connect item updates directly to the view, we must
10733  // separately add a translated dirty region.
10734  if (!d->dirty.isEmpty()) {
10735  foreach (const QRect &rect, (d->dirty.translated(dx, dy) & r).rects())
10736  proxy->update(rect);
10737  }
10738  proxy->scroll(dx, dy, r.translated(proxy->subWidgetRect(this).topLeft().toPoint()));
10739  return;
10740  }
10741 #endif
10742  d->scroll_sys(dx, dy, r);
10743 }
10744 
10762 {
10763  repaint(rect());
10764 }
10765 
10777 void QWidget::repaint(int x, int y, int w, int h)
10778 {
10779  if (x > data->crect.width() || y > data->crect.height())
10780  return;
10781 
10782  if (w < 0)
10783  w = data->crect.width() - x;
10784  if (h < 0)
10785  h = data->crect.height() - y;
10786 
10787  repaint(QRect(x, y, w, h));
10788 }
10789 
10798 {
10799  Q_D(QWidget);
10800 
10802  update(rect);
10803  return;
10804  }
10805 
10806  if (!isVisible() || !updatesEnabled() || rect.isEmpty())
10807  return;
10808 
10809  if (hasBackingStoreSupport()) {
10810 #ifdef QT_MAC_USE_COCOA
10811  if (qt_widget_private(this)->isInUnifiedToolbar) {
10812  qt_widget_private(this)->unifiedSurface->renderToolbar(this, true);
10813  return;
10814  }
10815 #endif // QT_MAC_USE_COCOA
10816  QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
10817  if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) {
10818  tlwExtra->inRepaint = true;
10819  tlwExtra->backingStore->markDirty(rect, this, true);
10820  tlwExtra->inRepaint = false;
10821  }
10822  } else {
10823  d->repaint_sys(rect);
10824  }
10825 }
10826 
10835 void QWidget::repaint(const QRegion &rgn)
10836 {
10837  Q_D(QWidget);
10838 
10840  update(rgn);
10841  return;
10842  }
10843 
10844  if (!isVisible() || !updatesEnabled() || rgn.isEmpty())
10845  return;
10846 
10847  if (hasBackingStoreSupport()) {
10848 #ifdef QT_MAC_USE_COCOA
10849  if (qt_widget_private(this)->isInUnifiedToolbar) {
10850  qt_widget_private(this)->unifiedSurface->renderToolbar(this, true);
10851  return;
10852  }
10853 #endif // QT_MAC_USE_COCOA
10854  QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
10855  if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore) {
10856  tlwExtra->inRepaint = true;
10857  tlwExtra->backingStore->markDirty(rgn, this, true);
10858  tlwExtra->inRepaint = false;
10859  }
10860  } else {
10861  d->repaint_sys(rgn);
10862  }
10863 }
10864 
10884 {
10885  update(rect());
10886 }
10887 
10907 {
10908  if (!isVisible() || !updatesEnabled())
10909  return;
10910 
10911  QRect r = rect & QWidget::rect();
10912 
10913  if (r.isEmpty())
10914  return;
10915 
10918  return;
10919  }
10920 
10921  if (hasBackingStoreSupport()) {
10922 #ifdef QT_MAC_USE_COCOA
10923  if (qt_widget_private(this)->isInUnifiedToolbar) {
10924  qt_widget_private(this)->unifiedSurface->renderToolbar(this, true);
10925  return;
10926  }
10927 #endif // QT_MAC_USE_COCOA
10928  QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
10929  if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore)
10930  tlwExtra->backingStore->markDirty(r, this);
10931  } else {
10932  d_func()->repaint_sys(r);
10933  }
10934 }
10935 
10944 void QWidget::update(const QRegion &rgn)
10945 {
10946  if (!isVisible() || !updatesEnabled() || rgn.isEmpty())
10947  return;
10948 
10949  QRegion r = rgn & QWidget::rect();
10950 
10951  if (r.isEmpty())
10952  return;
10953 
10956  return;
10957  }
10958 
10959  if (hasBackingStoreSupport()) {
10960 #ifdef QT_MAC_USE_COCOA
10961  if (qt_widget_private(this)->isInUnifiedToolbar) {
10962  qt_widget_private(this)->unifiedSurface->renderToolbar(this, true);
10963  return;
10964  }
10965 #endif // QT_MAC_USE_COCOA
10966  QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
10967  if (tlwExtra && !tlwExtra->inTopLevelResize && tlwExtra->backingStore)
10968  tlwExtra->backingStore->markDirty(r, this);
10969  } else {
10970  d_func()->repaint_sys(r);
10971  }
10972 }
10973 
10974 #ifdef QT3_SUPPORT
10975 
10981 void QWidget::erase_helper(int x, int y, int w, int h)
10982 {
10984  return;
10985  if (w < 0)
10986  w = data->crect.width() - x;
10987  if (h < 0)
10988  h = data->crect.height() - y;
10989  if (w != 0 && h != 0) {
10990  QPainter p(this);
10991  p.eraseRect(QRect(x, y, w, h));
10992  }
10993 }
10994 
11007 void QWidget::erase(const QRegion& rgn)
11008 {
11010  return;
11011 
11012  QPainter p(this);
11013  p.setClipRegion(rgn);
11014  p.eraseRect(rgn.boundingRect());
11015 }
11016 
11017 void QWidget::drawText_helper(int x, int y, const QString &str)
11018 {
11020  return;
11021  QPainter paint(this);
11022  paint.drawText(x, y, str);
11023 }
11024 
11025 
11031 bool QWidget::close(bool alsoDelete)
11032 {
11033  QPointer<QWidget> that = this;
11034  bool accepted = close();
11035  if (alsoDelete && accepted && that)
11036  deleteLater();
11037  return accepted;
11038 }
11039 
11040 void QWidget::setIcon(const QPixmap &i)
11041 {
11042  setWindowIcon(i);
11043 }
11044 
11050 const QPixmap *QWidget::icon() const
11051 {
11052  Q_D(const QWidget);
11053  return (d->extra && d->extra->topextra) ? d->extra->topextra->iconPixmap : 0;
11054 }
11055 
11056 #endif // QT3_SUPPORT
11057 
11064  QWidgetPrivate *d)
11065 {
11066  if (attribute < int(8*sizeof(uint))) {
11067  if (on)
11068  data->widget_attributes |= (1<<attribute);
11069  else
11070  data->widget_attributes &= ~(1<<attribute);
11071  } else {
11072  const int x = attribute - 8*sizeof(uint);
11073  const int int_off = x / (8*sizeof(uint));
11074  if (on)
11075  d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
11076  else
11077  d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
11078  }
11079 }
11080 
11088 {
11089  if (testAttribute(attribute) == on)
11090  return;
11091 
11092  Q_D(QWidget);
11093  Q_ASSERT_X(sizeof(d->high_attributes)*8 >= (Qt::WA_AttributeCount - sizeof(uint)*8),
11094  "QWidget::setAttribute(WidgetAttribute, bool)",
11095  "QWidgetPrivate::high_attributes[] too small to contain all attributes in WidgetAttribute");
11096 #ifdef Q_WS_WIN
11097  // ### Don't use PaintOnScreen+paintEngine() to do native painting in 5.0
11098  if (attribute == Qt::WA_PaintOnScreen && on && !inherits("QGLWidget")) {
11099  // see qwidget_win.cpp, ::paintEngine for details
11100  paintEngine();
11101  if (d->noPaintOnScreen)
11102  return;
11103  }
11104 #endif
11105 
11106  setAttribute_internal(attribute, on, data, d);
11107 
11108  switch (attribute) {
11109 
11110 #ifndef QT_NO_DRAGANDDROP
11111  case Qt::WA_AcceptDrops: {
11114  else if (!on && (isWindow() || !parentWidget() || !parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)))
11117  QApplication::sendEvent(this, &e);
11118  break;
11119  }
11121  d->registerDropSite(on);
11122  for (int i = 0; i < d->children.size(); ++i) {
11123  QWidget *w = qobject_cast<QWidget *>(d->children.at(i));
11126  }
11127  break;
11128  }
11129 #endif
11130 
11132  d->sendChildEvents = !on;
11133  break;
11135  d->receiveChildEvents = !on;
11136  break;
11138 #ifdef Q_WS_MAC
11139  d->setStyle_helper(style(), false, true); // Make sure things get unpolished/polished correctly.
11140  // fall through since changing the metal attribute affects the opaque size grip.
11142  d->macUpdateOpaqueSizeGrip();
11143  break;
11145  if (hasFocus()) {
11146  clearFocus();
11147  setFocus();
11148  }
11149  break;
11150  case Qt::WA_Hover:
11152  break;
11153 #endif
11155 #ifdef Q_WS_MAC
11156  d->macUpdateHideOnSuspend();
11157 #endif
11158  break;
11159  case Qt::WA_MacNormalSize:
11160  case Qt::WA_MacSmallSize:
11161  case Qt::WA_MacMiniSize:
11162 #ifdef Q_WS_MAC
11163  {
11164  // We can only have one of these set at a time
11167  for (int i = 0; i < 3; ++i) {
11168  if (MacSizes[i] != attribute)
11169  setAttribute_internal(MacSizes[i], false, data, d);
11170  }
11171  d->macUpdateSizeAttribute();
11172  }
11173 #endif
11174  break;
11175  case Qt::WA_ShowModal:
11176  if (!on) {
11177  if (isVisible())
11179  // reset modality type to Modeless when clearing WA_ShowModal
11181  } else if (data->window_modality == Qt::NonModal) {
11182  // determine the modality type if it hasn't been set prior
11183  // to setting WA_ShowModal. set the default to WindowModal
11184  // if we are the child of a group leader; otherwise use
11185  // ApplicationModal.
11186  QWidget *w = parentWidget();
11187  if (w)
11188  w = w->window();
11189  while (w && !w->testAttribute(Qt::WA_GroupLeader)) {
11190  w = w->parentWidget();
11191  if (w)
11192  w = w->window();
11193  }
11195  ? Qt::WindowModal
11197  // Some window managers does not allow us to enter modal after the
11198  // window is showing. Therefore, to be consistent, we cannot call
11199  // QApplicationPrivate::enterModal(this) here. The window must be
11200  // hidden before changing modality.
11201  }
11203  // don't call setModal_sys() before create_sys()
11204  d->setModal_sys();
11205  }
11206  break;
11207  case Qt::WA_MouseTracking: {
11209  QApplication::sendEvent(this, &e);
11210  break; }
11211  case Qt::WA_NativeWindow: {
11212 #ifndef QT_NO_IM
11213  QWidget *focusWidget = d->effectiveFocusWidget();
11214  QInputContext *ic = 0;
11215  if (on && !internalWinId() && hasFocus()
11216  && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
11217  ic = focusWidget->d_func()->inputContext();
11218  if (ic) {
11219  ic->reset();
11220  ic->setFocusWidget(0);
11221  }
11222  }
11223  if (!qApp->testAttribute(Qt::AA_DontCreateNativeWidgetSiblings) && parentWidget()
11224 #if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA)
11225  // On Mac, toolbars inside the unified title bar will never overlap with
11226  // siblings in the content view. So we skip enforce native siblings in that case
11227  && !d->isInUnifiedToolbar && parentWidget()->isWindow()
11228 #endif // Q_WS_MAC && QT_MAC_USE_COCOA
11229  )
11230  parentWidget()->d_func()->enforceNativeChildren();
11232  d->createWinId();
11233  if (ic && isEnabled() && focusWidget->isEnabled()
11234  && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
11235  ic->setFocusWidget(focusWidget);
11236  }
11237 #endif //QT_NO_IM
11238  break;
11239  }
11240  case Qt::WA_PaintOnScreen:
11241  d->updateIsOpaque();
11242 #if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_OS_SYMBIAN)
11243  // Recreate the widget if it's already created as an alien widget and
11244  // WA_PaintOnScreen is enabled. Paint on screen widgets must have win id.
11245  // So must their children.
11246  if (on) {
11248  d->enforceNativeChildren();
11249  }
11250 #endif
11251  // fall through
11253  d->updateIsOpaque();
11254  break;
11256  d->updateIsOpaque();
11257  // fall through...
11259  d->updateSystemBackground();
11260  break;
11262 #ifdef Q_WS_MAC
11263  d->macUpdateIgnoreMouseEvents();
11264 #endif
11265  break;
11267 #ifndef QT_NO_IM
11268  QWidget *focusWidget = d->effectiveFocusWidget();
11269  QInputContext *ic = focusWidget->d_func()->assignedInputContext();
11270  if (!ic && (!on || hasFocus()))
11271  ic = focusWidget->d_func()->inputContext();
11272  if (ic) {
11273  if (on && hasFocus() && ic->focusWidget() != focusWidget && isEnabled()
11274  && focusWidget->testAttribute(Qt::WA_InputMethodEnabled)) {
11275  ic->setFocusWidget(focusWidget);
11276  } else if (!on && ic->focusWidget() == focusWidget) {
11277  ic->reset();
11278  ic->setFocusWidget(0);
11279  }
11280  }
11281 #endif //QT_NO_IM
11282  break;
11283  }
11285  d->resolvePalette();
11286  d->resolveFont();
11287  d->resolveLocale();
11288  break;
11289 #ifdef Q_WS_X11
11291  if (!d->extra)
11292  d->createExtra();
11293  d->extra->compress_events = on;
11294  break;
11296  d->updateIsOpaque();
11297  break;
11300  d->updateX11AcceptFocus();
11301  break;
11302 #endif
11303  case Qt::WA_DontShowOnScreen: {
11304  if (on && isVisible()) {
11305  // Make sure we keep the current state and only hide the widget
11306  // from the desktop. show_sys will only update platform specific
11307  // attributes at this point.
11308  d->hide_sys();
11309 #ifdef Q_WS_QWS
11310  // Release the region for this window from qws if the widget has
11311  // been shown before the attribute was set.
11312  if (QWSWindowSurface *surface = static_cast<QWSWindowSurface *>(windowSurface())) {
11313  QWidget::qwsDisplay()->requestRegion(surface->winId(), surface->key(),
11314  surface->permanentState(), QRegion());
11315  }
11316 #endif
11317  d->show_sys();
11318  }
11319  break;
11320  }
11321 
11322 #ifdef Q_WS_X11
11337  d->setNetWmWindowTypes();
11338  break;
11339 #endif
11340 
11341  case Qt::WA_StaticContents:
11342  if (QWidgetBackingStore *bs = d->maybeBackingStore()) {
11343  if (on)
11344  bs->addStaticWidget(this);
11345  else
11346  bs->removeStaticWidget(this);
11347  }
11348  break;
11350 #if defined(Q_OS_SYMBIAN)
11352 #else
11353  if (on) {
11355  d->updateIsTranslucent();
11356  }
11357 #endif
11358  break;
11360 #if defined(Q_WS_WIN) || defined(Q_WS_MAC) || defined(Q_OS_SYMBIAN)
11361  if (on)
11362  d->registerTouchWindow();
11363 #endif
11364  break;
11367  case Qt::WA_AutoOrientation: {
11368  const Qt::WidgetAttribute orientations[3] = {
11372  };
11373 
11374  if (on) {
11375  // We can only have one of these set at a time
11376  for (int i = 0; i < 3; ++i) {
11377  if (orientations[i] != attribute)
11378  setAttribute_internal(orientations[i], false, data, d);
11379  }
11380  }
11381 
11382 #ifdef Q_OS_BLACKBERRY
11383  if (testAttribute(Qt::WA_AutoOrientation)) {
11384  navigator_rotation_lock(false);
11385  } else {
11386 #ifdef Q_OS_BLACKBERRY_TABLET
11387  const bool portraitLocked = testAttribute(Qt::WA_LockPortraitOrientation);
11388 
11389  orientation_direction_t direction;
11390  orientation_get(&direction, 0);
11391 
11392  int rotation = 0;
11393 
11394  switch (direction) {
11395  case ORIENTATION_TOP_UP:
11396  case ORIENTATION_RIGHT_UP:
11397  rotation = portraitLocked ? 90 : 0;
11398  break;
11399  case ORIENTATION_BOTTOM_UP:
11400  case ORIENTATION_LEFT_UP:
11401  rotation = portraitLocked ? 270 : 180;
11402  break;
11403  default:
11404  break;
11405  }
11406 
11407  navigator_set_orientation(rotation, 0);
11408 #else
11409  navigator_set_orientation_mode((testAttribute(Qt::WA_LockPortraitOrientation) ?
11410  NAVIGATOR_PORTRAIT : NAVIGATOR_LANDSCAPE), 0);
11411 #endif // Q_OS_BLACKBERRY_TABLET
11412  navigator_rotation_lock(true);
11413  }
11414 #endif // Q_OS_BLACKBERRY
11415 
11416 #ifdef Q_WS_S60
11417  CAknAppUiBase* appUi = static_cast<CAknAppUiBase*>(CEikonEnv::Static()->EikAppUi());
11418  const CAknAppUiBase::TAppUiOrientation s60orientations[] = {
11419  CAknAppUiBase::EAppUiOrientationPortrait,
11420  CAknAppUiBase::EAppUiOrientationLandscape,
11421  CAknAppUiBase::EAppUiOrientationAutomatic
11422  };
11423  CAknAppUiBase::TAppUiOrientation s60orientation = CAknAppUiBase::EAppUiOrientationUnspecified;
11424  for (int i = 0; i < 3; ++i) {
11425  if (testAttribute(orientations[i])) {
11426  s60orientation = s60orientations[i];
11427  break;
11428  }
11429  }
11430  QT_TRAP_THROWING(appUi->SetOrientationL(s60orientation));
11431  S60->orientationSet = true;
11432  QSymbianControl *window = static_cast<QSymbianControl *>(internalWinId());
11433  if (window)
11434  window->ensureFixNativeOrientation();
11435 #endif
11436  break;
11437  }
11438  default:
11439  break;
11440  }
11441 }
11442 
11454 {
11455  Q_D(const QWidget);
11456  const int x = attribute - 8*sizeof(uint);
11457  const int int_off = x / (8*sizeof(uint));
11458  return (d->high_attributes[int_off] & (1<<(x-(int_off*8*sizeof(uint)))));
11459 }
11460 
11492 {
11493  Q_D(const QWidget);
11494  return (isWindow() && d->maybeTopData()) ? d->maybeTopData()->opacity / qreal(255.) : qreal(1.0);
11495 }
11496 
11498 {
11499  Q_D(QWidget);
11500  if (!isWindow())
11501  return;
11502 
11503  opacity = qBound(qreal(0.0), opacity, qreal(1.0));
11504  QTLWExtra *extra = d->topData();
11505  extra->opacity = uint(opacity * 255);
11507 
11508 #ifndef Q_WS_QWS
11510  return;
11511 #endif
11512 
11513 #ifndef QT_NO_GRAPHICSVIEW
11514  if (QGraphicsProxyWidget *proxy = graphicsProxyWidget()) {
11515  // Avoid invalidating the cache if set.
11516  if (proxy->cacheMode() == QGraphicsItem::NoCache)
11517  proxy->update();
11518  else if (QGraphicsScene *scene = proxy->scene())
11519  scene->update(proxy->sceneBoundingRect());
11520  return;
11521  }
11522 #endif
11523 
11524  d->setWindowOpacity_sys(opacity);
11525 }
11526 
11555 {
11557 }
11558 
11560 {
11561  Q_D(QWidget);
11563 
11564 #ifndef Q_WS_MAC
11565  if (!windowTitle().contains(QLatin1String("[*]")) && mod)
11566  qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder");
11567 #endif
11568  d->setWindowTitle_helper(windowTitle());
11569  d->setWindowIconText_helper(windowIconText());
11570 #ifdef Q_WS_MAC
11571  d->setWindowModified_sys(mod);
11572 #endif
11573 
11575  QApplication::sendEvent(this, &e);
11576 }
11577 
11578 #ifndef QT_NO_TOOLTIP
11579 
11601 {
11602  Q_D(QWidget);
11603  d->toolTip = s;
11604 
11606  QApplication::sendEvent(this, &event);
11607 }
11608 
11609 QString QWidget::toolTip() const
11610 {
11611  Q_D(const QWidget);
11612  return d->toolTip;
11613 }
11614 #endif // QT_NO_TOOLTIP
11615 
11616 
11617 #ifndef QT_NO_STATUSTIP
11618 
11630 {
11631  Q_D(QWidget);
11632  d->statusTip = s;
11633 }
11634 
11636 {
11637  Q_D(const QWidget);
11638  return d->statusTip;
11639 }
11640 #endif // QT_NO_STATUSTIP
11641 
11642 #ifndef QT_NO_WHATSTHIS
11643 
11656 {
11657  Q_D(QWidget);
11658  d->whatsThis = s;
11659 }
11660 
11662 {
11663  Q_D(const QWidget);
11664  return d->whatsThis;
11665 }
11666 #endif // QT_NO_WHATSTHIS
11667 
11668 #ifndef QT_NO_ACCESSIBILITY
11669 
11685 {
11686  Q_D(QWidget);
11687  d->accessibleName = name;
11689 }
11690 
11692 {
11693  Q_D(const QWidget);
11694  return d->accessibleName;
11695 }
11696 
11710 {
11711  Q_D(QWidget);
11712  d->accessibleDescription = description;
11714 }
11715 
11717 {
11718  Q_D(const QWidget);
11719  return d->accessibleDescription;
11720 }
11721 #endif // QT_NO_ACCESSIBILITY
11722 
11723 #ifndef QT_NO_SHORTCUT
11724 
11748 {
11749  Q_ASSERT(qApp);
11750  if (key.isEmpty())
11751  return 0;
11753  return qApp->d_func()->shortcutMap.addShortcut(this, key, context);
11754 }
11755 
11772 {
11773  Q_ASSERT(qApp);
11774  if (id)
11775  qApp->d_func()->shortcutMap.removeShortcut(id, this, 0);
11776 }
11777 
11790 void QWidget::setShortcutEnabled(int id, bool enable)
11791 {
11792  Q_ASSERT(qApp);
11793  if (id)
11794  qApp->d_func()->shortcutMap.setShortcutEnabled(enable, id, this, 0);
11795 }
11796 
11808 void QWidget::setShortcutAutoRepeat(int id, bool enable)
11809 {
11810  Q_ASSERT(qApp);
11811  if (id)
11812  qApp->d_func()->shortcutMap.setShortcutAutoRepeat(enable, id, this, 0);
11813 }
11814 #endif // QT_NO_SHORTCUT
11815 
11821 {
11822 #if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
11823  Q_D(QWidget);
11824  // and optimization to update input context only it has already been created.
11825  if (d->assignedInputContext() || qApp->d_func()->inputContext) {
11826  QInputContext *ic = inputContext();
11827  if (ic)
11828  ic->update();
11829  }
11830 #endif
11831 #ifndef QT_NO_ACCESSIBILITY
11832  if (isVisible()) {
11833  // ##### is this correct
11835  }
11836 #endif
11837 }
11838 
11839 
11840 #if defined (Q_WS_WIN)
11841 
11849 HDC QWidget::getDC() const
11850 {
11851  Q_D(const QWidget);
11852  if (d->hd)
11853  return (HDC) d->hd;
11854  return GetDC(winId());
11855 }
11856 
11862 void QWidget::releaseDC(HDC hdc) const
11863 {
11864  Q_D(const QWidget);
11865  // If its the widgets own dc, it will be released elsewhere. If
11866  // its a different HDC we release it and issue a warning if it
11867  // fails.
11868  if (hdc != d->hd && !ReleaseDC(winId(), hdc))
11869  qErrnoWarning("QWidget::releaseDC(): failed to release HDC");
11870 }
11871 #else
11872 
11879 Qt::HANDLE QWidget::handle() const
11880 {
11881  Q_D(const QWidget);
11883  (void)winId(); // enforce native window
11884  return d->hd;
11885 }
11886 #endif
11887 
11888 
11902 {
11903  Q_D(QWidget);
11904  if (!isWindow()) {
11905  QWidget *p = parentWidget();
11906  const int parentChildCount = p->d_func()->children.size();
11907  if (parentChildCount < 2)
11908  return;
11909  const int from = p->d_func()->children.indexOf(this);
11910  Q_ASSERT(from >= 0);
11911  // Do nothing if the widget is already in correct stacking order _and_ created.
11912  if (from != parentChildCount -1)
11913  p->d_func()->children.move(from, parentChildCount - 1);
11915  create();
11916  else if (from == parentChildCount - 1)
11917  return;
11918 
11919  QRegion region(rect());
11920  d->subtractOpaqueSiblings(region);
11921  d->invalidateBuffer(region);
11922  }
11924  d->raise_sys();
11925 
11927  QApplication::sendEvent(this, &e);
11928 }
11929 
11940 {
11941  Q_D(QWidget);
11942  if (!isWindow()) {
11943  QWidget *p = parentWidget();
11944  const int parentChildCount = p->d_func()->children.size();
11945  if (parentChildCount < 2)
11946  return;
11947  const int from = p->d_func()->children.indexOf(this);
11948  Q_ASSERT(from >= 0);
11949  // Do nothing if the widget is already in correct stacking order _and_ created.
11950  if (from != 0)
11951  p->d_func()->children.move(from, 0);
11953  create();
11954  else if (from == 0)
11955  return;
11956  }
11958  d->lower_sys();
11959 
11961  QApplication::sendEvent(this, &e);
11962 }
11963 
11964 
11973 {
11974  Q_D(QWidget);
11975  QWidget *p = parentWidget();
11976  if (!w || isWindow() || p != w->parentWidget() || this == w)
11977  return;
11978  if (p) {
11979  int from = p->d_func()->children.indexOf(this);
11980  int to = p->d_func()->children.indexOf(w);
11981  Q_ASSERT(from >= 0);
11982  Q_ASSERT(to >= 0);
11983  if (from < to)
11984  --to;
11985  // Do nothing if the widget is already in correct stacking order _and_ created.
11986  if (from != to)
11987  p->d_func()->children.move(from, to);
11989  create();
11990  else if (from == to)
11991  return;
11992  }
11994  d->stackUnder_sys(w);
11995 
11997  QApplication::sendEvent(this, &e);
11998 }
11999 
12001 void QWidget::enabledChange(bool) { } // compat
12002 void QWidget::paletteChange(const QPalette &) { } // compat
12003 void QWidget::fontChange(const QFont &) { } // compat
12004 void QWidget::windowActivationChange(bool) { } // compat
12005 void QWidget::languageChange() { } // compat
12006 
12007 
12608 {
12609  Q_Q(const QWidget);
12610  if (!q->isWindow() || (q->windowType() == Qt::Desktop) || q->testAttribute(Qt::WA_DontShowOnScreen)) {
12611  // x2 = x1 + w - 1, so w/h = 1
12612  return QRect(0, 0, 1, 1);
12613  }
12614 
12615  if (data.fstrut_dirty
12616 #ifndef Q_WS_WIN
12617  // ### Fix properly for 4.3
12618  && q->isVisible()
12619 #endif
12620  && q->testAttribute(Qt::WA_WState_Created))
12621  const_cast<QWidgetPrivate *>(this)->updateFrameStrut();
12622 
12623  return maybeTopData() ? maybeTopData()->frameStrut : QRect();
12624 }
12625 
12626 #ifdef QT_KEYPAD_NAVIGATION
12627 
12638 bool QWidgetPrivate::navigateToDirection(Direction direction)
12639 {
12640  QWidget *targetWidget = widgetInNavigationDirection(direction);
12641  if (targetWidget)
12642  targetWidget->setFocus();
12643  return (targetWidget != 0);
12644 }
12645 
12658 QWidget *QWidgetPrivate::widgetInNavigationDirection(Direction direction)
12659 {
12660  const QWidget *sourceWidget = QApplication::focusWidget();
12661  if (!sourceWidget)
12662  return 0;
12663  const QRect sourceRect = sourceWidget->rect().translated(sourceWidget->mapToGlobal(QPoint()));
12664  const int sourceX =
12665  (direction == DirectionNorth || direction == DirectionSouth) ?
12666  (sourceRect.left() + (sourceRect.right() - sourceRect.left()) / 2)
12667  :(direction == DirectionEast ? sourceRect.right() : sourceRect.left());
12668  const int sourceY =
12669  (direction == DirectionEast || direction == DirectionWest) ?
12670  (sourceRect.top() + (sourceRect.bottom() - sourceRect.top()) / 2)
12671  :(direction == DirectionSouth ? sourceRect.bottom() : sourceRect.top());
12672  const QPoint sourcePoint(sourceX, sourceY);
12673  const QPoint sourceCenter = sourceRect.center();
12674  const QWidget *sourceWindow = sourceWidget->window();
12675 
12676  QWidget *targetWidget = 0;
12677  int shortestDistance = INT_MAX;
12678  foreach(QWidget *targetCandidate, QApplication::allWidgets()) {
12679 
12680  const QRect targetCandidateRect = targetCandidate->rect().translated(targetCandidate->mapToGlobal(QPoint()));
12681 
12682  // For focus proxies, the child widget handling the focus can have keypad navigation focus,
12683  // but the owner of the proxy cannot.
12684  // Additionally, empty widgets should be ignored.
12685  if (targetCandidate->focusProxy() || targetCandidateRect.isEmpty())
12686  continue;
12687 
12688  // Only navigate to a target widget that...
12689  if ( targetCandidate != sourceWidget
12690  // ...takes the focus,
12691  && targetCandidate->focusPolicy() & Qt::TabFocus
12692  // ...is above if DirectionNorth,
12693  && !(direction == DirectionNorth && targetCandidateRect.bottom() > sourceRect.top())
12694  // ...is on the right if DirectionEast,
12695  && !(direction == DirectionEast && targetCandidateRect.left() < sourceRect.right())
12696  // ...is below if DirectionSouth,
12697  && !(direction == DirectionSouth && targetCandidateRect.top() < sourceRect.bottom())
12698  // ...is on the left if DirectionWest,
12699  && !(direction == DirectionWest && targetCandidateRect.right() > sourceRect.left())
12700  // ...is enabled,
12701  && targetCandidate->isEnabled()
12702  // ...is visible,
12703  && targetCandidate->isVisible()
12704  // ...is in the same window,
12705  && targetCandidate->window() == sourceWindow) {
12706  const int targetCandidateDistance = pointToRect(sourcePoint, targetCandidateRect);
12707  if (targetCandidateDistance < shortestDistance) {
12708  shortestDistance = targetCandidateDistance;
12709  targetWidget = targetCandidate;
12710  }
12711  }
12712  }
12713  return targetWidget;
12714 }
12715 
12730 bool QWidgetPrivate::canKeypadNavigate(Qt::Orientation orientation)
12731 {
12732  return orientation == Qt::Horizontal?
12733  (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast)
12734  || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest))
12735  :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth)
12736  || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth));
12737 }
12753 bool QWidgetPrivate::inTabWidget(QWidget *widget)
12754 {
12755  for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget())
12756  if (qobject_cast<const QTabWidget*>(tabWidget))
12757  return true;
12758  return false;
12759 }
12760 #endif
12761 
12775 {
12776  // ### createWinId() ??
12777 
12778 #ifndef Q_BACKINGSTORE_SUBSURFACES
12779  if (!isTopLevel())
12780  return;
12781 #endif
12782 
12783  Q_D(QWidget);
12784 
12785  QTLWExtra *topData = d->topData();
12786  if (topData->windowSurface == surface)
12787  return;
12788 
12789  QWindowSurface *oldSurface = topData->windowSurface;
12790  delete topData->windowSurface;
12791  topData->windowSurface = surface;
12792 
12793  QWidgetBackingStore *bs = d->maybeBackingStore();
12794  if (!bs)
12795  return;
12796 
12797  if (isTopLevel()) {
12798  if (bs->windowSurface != oldSurface && bs->windowSurface != surface)
12799  delete bs->windowSurface;
12800  bs->windowSurface = surface;
12801  }
12802 #ifdef Q_BACKINGSTORE_SUBSURFACES
12803  else {
12804  bs->subSurfaces.append(surface);
12805  }
12806  bs->subSurfaces.removeOne(oldSurface);
12807 #endif
12808 }
12809 
12820 {
12821  Q_D(const QWidget);
12822  QTLWExtra *extra = d->maybeTopData();
12823  if (extra && extra->windowSurface)
12824  return extra->windowSurface;
12825 
12826  QWidgetBackingStore *bs = d->maybeBackingStore();
12827 
12828 #ifdef Q_BACKINGSTORE_SUBSURFACES
12829  if (bs && bs->subSurfaces.isEmpty())
12830  return bs->windowSurface;
12831 
12832  if (!isTopLevel()) {
12833  const QWidget *w = parentWidget();
12834  while (w) {
12835  QTLWExtra *extra = w->d_func()->maybeTopData();
12836  if (extra && extra->windowSurface)
12837  return extra->windowSurface;
12838  if (w->isTopLevel())
12839  break;
12840  w = w->parentWidget();
12841  }
12842  }
12843 #endif // Q_BACKINGSTORE_SUBSURFACES
12844 
12845  return bs ? bs->windowSurface : 0;
12846 }
12847 
12848 void QWidgetPrivate::getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const
12849 {
12850  if (left)
12851  *left = (int)leftLayoutItemMargin;
12852  if (top)
12853  *top = (int)topLayoutItemMargin;
12854  if (right)
12855  *right = (int)rightLayoutItemMargin;
12856  if (bottom)
12857  *bottom = (int)bottomLayoutItemMargin;
12858 }
12859 
12860 void QWidgetPrivate::setLayoutItemMargins(int left, int top, int right, int bottom)
12861 {
12862  if (leftLayoutItemMargin == left
12863  && topLayoutItemMargin == top
12864  && rightLayoutItemMargin == right
12865  && bottomLayoutItemMargin == bottom)
12866  return;
12867 
12868  Q_Q(QWidget);
12869  leftLayoutItemMargin = (signed char)left;
12870  topLayoutItemMargin = (signed char)top;
12871  rightLayoutItemMargin = (signed char)right;
12872  bottomLayoutItemMargin = (signed char)bottom;
12873  q->updateGeometry();
12874 }
12875 
12877 {
12878  Q_Q(QWidget);
12879  QStyleOption myOpt;
12880  if (!opt) {
12881  myOpt.initFrom(q);
12882  myOpt.rect.setRect(0, 0, 32768, 32768); // arbitrary
12883  opt = &myOpt;
12884  }
12885 
12886  QRect liRect = q->style()->subElementRect(element, opt, q);
12887  if (liRect.isValid()) {
12888  leftLayoutItemMargin = (signed char)(opt->rect.left() - liRect.left());
12889  topLayoutItemMargin = (signed char)(opt->rect.top() - liRect.top());
12890  rightLayoutItemMargin = (signed char)(liRect.right() - opt->rect.right());
12891  bottomLayoutItemMargin = (signed char)(liRect.bottom() - opt->rect.bottom());
12892  } else {
12893  leftLayoutItemMargin = 0;
12894  topLayoutItemMargin = 0;
12895  rightLayoutItemMargin = 0;
12896  bottomLayoutItemMargin = 0;
12897  }
12898 }
12899 // resets the Qt::WA_QuitOnClose attribute to the default value for transient widgets.
12901 {
12902  Q_Q(QWidget);
12903 
12904  if (!q->parentWidget()) {
12905  Qt::WindowType type = q->windowType();
12906  if (type == Qt::Widget || type == Qt::SubWindow)
12907  type = Qt::Window;
12908  if (type != Qt::Widget && type != Qt::Window && type != Qt::Dialog)
12909  q->setAttribute(Qt::WA_QuitOnClose, false);
12910  }
12911 }
12912 
12913 
12914 
12916 {
12917  return widget->data;
12918 }
12919 
12921 {
12922  return widget->d_func();
12923 }
12924 
12925 
12926 #ifndef QT_NO_GRAPHICSVIEW
12927 
12940 {
12941  Q_D(const QWidget);
12942  if (d->extra) {
12943  return d->extra->proxyWidget;
12944  }
12945  return 0;
12946 }
12947 #endif
12948 
12949 
12957 #ifndef QT_NO_GESTURES
12958 
12964 void QWidget::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags)
12965 {
12966  Q_D(QWidget);
12967  d->gestureContext.insert(gesture, flags);
12968  (void)QGestureManager::instance(); // create a gesture manager
12969 }
12970 
12978 {
12979  Q_D(QWidget);
12980  if (d->gestureContext.remove(gesture)) {
12981  if (QGestureManager *manager = QGestureManager::instance())
12982  manager->cleanupCachedGestures(this, gesture);
12983  }
12984 }
12985 #endif // QT_NO_GESTURES
12986 
13227 void QWidget::setMask(const QRegion &newMask)
13228 {
13229  Q_D(QWidget);
13230 
13231  d->createExtra();
13232  if (newMask == d->extra->mask)
13233  return;
13234 
13235 #ifndef QT_NO_BACKINGSTORE
13236  const QRegion oldMask(d->extra->mask);
13237 #endif
13238 
13239  d->extra->mask = newMask;
13240  d->extra->hasMask = !newMask.isEmpty();
13241 
13242 #ifndef QT_MAC_USE_COCOA
13244  return;
13245 #endif
13246 
13247  d->setMask_sys(newMask);
13248 
13249 #ifndef QT_NO_BACKINGSTORE
13250  if (!isVisible())
13251  return;
13252 
13253  if (!d->extra->hasMask) {
13254  // Mask was cleared; update newly exposed area.
13255  QRegion expose(rect());
13256  expose -= oldMask;
13257  if (!expose.isEmpty()) {
13258  d->setDirtyOpaqueRegion();
13259  update(expose);
13260  }
13261  return;
13262  }
13263 
13264  if (!isWindow()) {
13265  // Update newly exposed area on the parent widget.
13266  QRegion parentExpose(rect());
13267  parentExpose -= newMask;
13268  if (!parentExpose.isEmpty()) {
13269  d->setDirtyOpaqueRegion();
13270  parentExpose.translate(data->crect.topLeft());
13271  parentWidget()->update(parentExpose);
13272  }
13273 
13274  // Update newly exposed area on this widget
13275  if (!oldMask.isEmpty())
13276  update(newMask - oldMask);
13277  }
13278 #endif
13279 }
13280 
13309 void QWidget::setMask(const QBitmap &bitmap)
13310 {
13311  setMask(QRegion(bitmap));
13312 }
13313 
13325 {
13326  setMask(QRegion());
13327 }
13328 
13350 #ifdef Q_OS_SYMBIAN
13351 void QWidgetPrivate::_q_cleanupWinIds()
13352 {
13353  foreach (WId wid, widCleanupList)
13354  delete wid;
13355  widCleanupList.clear();
13356 }
13357 #endif
13358 
13359 #if QT_MAC_USE_COCOA
13360 void QWidgetPrivate::syncUnifiedMode() {
13361  // The whole purpose of this method is to keep the unifiedToolbar in sync.
13362  // That means making sure we either exchange the drawing methods or we let
13363  // the toolbar know that it does not require to draw the baseline.
13364  Q_Q(QWidget);
13365  // This function makes sense only if this is a top level
13366  if(!q->isWindow())
13367  return;
13369  if(changeMethods) {
13370  // Ok, we are in documentMode.
13371  if(originalDrawMethod)
13372  qt_mac_replaceDrawRect(window, this);
13373  } else {
13374  if(!originalDrawMethod)
13375  qt_mac_replaceDrawRectOriginal(window, this);
13376  }
13377 }
13378 
13379 #endif // QT_MAC_USE_COCOA
13380 
13382 
13383 #include "moc_qwidget.cpp"
13384 
void scroll(int dx, int dy)
Scrolls the widget including its children dx pixels to the right and dy downward. ...
Definition: qwidget.cpp:10684
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void setSystemViewport(const QRegion &region)
bool isModal() const
Definition: qwidget.h:951
static void clearGuards(QObject *)
Definition: qobject.cpp:467
QPoint pos() const
T qobject_cast(QObject *object)
Definition: qobject.h:375
void setTransform(const QTransform &transform, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9547
QSize baseSize() const
void showMaximized()
Shows the widget maximized.
Definition: qwidget.cpp:3218
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
Definition: qpainter.cpp:1530
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
Definition: qrect.cpp:2817
void resolveLayoutDirection()
Definition: qwidget.cpp:5171
bool isEnabledTo(QWidget *) const
Returns true if this widget would become enabled if ancestor is enabled; otherwise returns false...
Definition: qwidget.cpp:3290
virtual void unpolish(QWidget *)
Uninitialize the given {widget}&#39;s appearance.
Definition: qstyle.cpp:409
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
void stackUnder(QWidget *)
Places the widget under w in the parent widget&#39;s stack.
Definition: qwidget.cpp:11972
static QWidget * main_widget
static Qt::LayoutDirection layoutDirection()
CoordinateSystem
Definition: qnamespace.h:1733
#define QT_NO_GESTURES
QPointer< QWidget > qt_button_down
virtual bool macEvent(EventHandlerCallRef, EventRef)
This special event handler can be reimplemented in a subclass to receive native Macintosh events...
Definition: qwidget.cpp:9918
void setWindowSurface(QWindowSurface *surface)
Sets the window surface to be the surface specified.
Definition: qwidget.cpp:12774
The QWSWindowSurface class provides the drawing area for top-level windows in Qt for Embedded Linux...
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
static QWidgetList allWidgets()
Returns a list of all the widgets in the application.
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
void setFont(const QFont &)
Use the single-argument overload instead.
Definition: qwidget.cpp:4996
QPainter * painter
Definition: qwidget_p.h:941
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
bool hasFocus() const
Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise...
int totalHeightForWidth(int w) const
Also takes contentsMargins and menu bar into account.
Definition: qlayout.cpp:823
QString windowRole() const
Returns the window&#39;s role, or an empty string.
Definition: qwidget.cpp:6483
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
The QKeyEvent class describes a key event.
Definition: qevent.h:224
QSize adjustedSize() const
Definition: qwidget.cpp:8425
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition: qwidget.cpp:6863
unsigned long WId
Definition: qwindowdefs.h:119
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
void setInputMethodHints(Qt::InputMethodHints hints)
Definition: qwidget.cpp:9736
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
virtual void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qwidget.cpp:9842
int type
Definition: qmetatype.cpp:239
void adjustQuitOnCloseAttribute()
Definition: qwidget.cpp:12900
double qreal
Definition: qglobal.h:1193
virtual int heightForWidth(int) const
Returns the preferred height for this widget, given the width w.
Definition: qwidget.cpp:10241
int y() const
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
void init(QWidget *desktopWidget, Qt::WindowFlags f)
Definition: qwidget.cpp:1298
qreal opacity() const
Returns the opacity of the painter.
Definition: qpainter.cpp:2115
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int qint32
Definition: qglobal.h:937
void setSizeIncrement(const QSize &)
Definition: qwidget.h:975
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
const QRegion clipRegion() const
Returns the region currently visible on the screen.
Q_CORE_EXPORT QTextStream & ws(QTextStream &s)
QSize size() const
EventRef event
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns 0...
QPointer< QWidget > widget
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
QLocale locale() const
QRect frameStrut
Definition: qwidget_p.h:180
virtual void inputMethodEvent(QInputMethodEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive Input Method compo...
Definition: qwidget.cpp:9668
QCursor cursor() const
ColorRole
The ColorRole enum defines the different symbolic color roles used in current GUIs.
Definition: qpalette.h:93
Qt::WindowStates windowState() const
Returns the current window state.
Definition: qwidget.cpp:3086
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
void setWindowModified(bool)
Definition: qwidget.cpp:11559
QInputContext * assignedInputContext() const
Definition: qwidget.cpp:446
CompositionMode
Defines the modes supported for digital image compositing.
Definition: qpainter.h:138
bool fullScreen
whether the widget is shown in full screen mode
Definition: qwidget.h:194
void setWindowState(Qt::WindowStates state)
Sets the window state to windowState.
void resetInputContext()
This function can be called on the widget that currently has focus to reset the input method operatin...
Definition: qwidget.cpp:522
Qt::InputMethodHints imHints
Definition: qwidget_p.h:718
void moveLeft(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s left edge at the given x coordinate...
Definition: qrect.h:350
bool qt_sendSpontaneousEvent(QObject *, QEvent *)
int width
the width of the widget excluding any window frame
Definition: qwidget.h:166
bool isActiveWindow
whether this widget&#39;s window is the active window
Definition: qwidget.h:186
QWidget * childAtRecursiveHelper(const QPoint &p, bool, bool includeFrame=false) const
Definition: qwidget.cpp:10308
virtual QSize minimumSizeHint() const
void unsetCursor()
Definition: qwidget.cpp:5311
QRect crect
Definition: qwidget.h:131
bool acceptDrops() const
T * data() const
Returns the value of the pointer referenced by this object.
QPoint mapTo(QWidget *, const QPoint &) const
Translates the widget coordinate pos to the coordinate system of parent.
Definition: qwidget.cpp:4409
static QWSDisplay * qwsDisplay()
QWindowSurface * windowSurface
void setWindowIconText_helper(const QString &cap)
Definition: qwidget.cpp:6292
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
void setLocale(const QLocale &locale)
Definition: qwidget.cpp:6152
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
static bool hasBackingStoreSupport()
Definition: qwidget.cpp:169
void unsetLayoutDirection()
Definition: qwidget.cpp:5217
QRect contentsRect() const
Returns the area inside the widget&#39;s margins.
Definition: qwidget.cpp:7544
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Definition: qpointer.h:70
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
void releaseDC(HDC) const
Releases the HDC hdc acquired by a previous call to getDC().
Definition: qwidget.cpp:11862
The QWheelEvent class contains parameters that describe a wheel event.
Definition: qevent.h:139
QRectF boundingRect(Qt::CoordinateSystem system) const
Definition: qwidget.cpp:6013
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
WId effectiveWinId() const
Returns the effective window system identifier of the widget, i.
Definition: qwidget.cpp:2654
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
void setSystemTransform(const QTransform &xform)
void setLayout(QLayout *)
Sets the layout manager for this widget to layout.
Definition: qwidget.cpp:10104
QLayout * layout
Definition: qwidget_p.h:704
bool isVisible() const
Definition: qwidget.h:1005
void setDisabled(bool)
Disables widget input events if disable is true; otherwise enables input events.
Definition: qwidget.cpp:3589
bool isVisibleTo(QWidget *) const
Returns true if this widget would become visible if ancestor is shown; otherwise returns false...
Definition: qwidget.cpp:8371
QString styleSheet() const
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
bool isEnabled() const
void paintSiblingsRecursive(QPaintDevice *pdev, const QObjectList &children, int index, const QRegion &rgn, const QPoint &offset, int flags, QPainter *sharedPainter, QWidgetBackingStore *backingStore)
Definition: qwidget.cpp:5946
virtual void styleChange(QStyle &)
Definition: qwidget.cpp:12000
const QRegion & getOpaqueChildren() const
Definition: qwidget.cpp:2098
virtual void mouseReleaseEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition: qwidget.cpp:9286
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
bool paintOnScreen() const
Definition: qwidget.cpp:2255
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
virtual void dragEnterEvent(QDragEnterEvent *)
This event handler is called when a drag is in progress and the mouse enters this widget...
Definition: qwidget.cpp:9768
QFont fnt
Definition: qwidget.h:133
int height() const
Definition: qpaintdevice.h:92
void clearFocus()
Takes keyboard input focus from the item.
bool remove(const T &value)
Definition: qset.h:89
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool isEmpty() const
Definition: qset.h:77
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or 0 if no application wi...
QWindowSurface * windowSurface
Definition: qwidget_p.h:167
static void adjustFlags(Qt::WindowFlags &flags, QWidget *w=0)
Definition: qwidget.cpp:1242
void setBaseSize(const QSize &)
Definition: qwidget.h:978
static QPlatformWindowFormat defaultFormat()
Returns the default QPlatformWindowFormat for the application.
QRect clipRect() const
Definition: qwidget.cpp:1997
#define Q_WS_WIN
Defined on Windows.
Definition: qglobal.h:921
QList< QWidget * > widgets
Definition: qaction_p.h:121
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
virtual void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qwidget.cpp:9261
QString windowIconText() const
virtual void leaveEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive widget leave events which are passed...
Definition: qwidget.cpp:9491
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
Definition: qwidget.h:187
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
uint window_state
Definition: qwidget.h:120
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
static QStyle * create(const QString &)
void syncBackingStore()
Definition: qwidget.cpp:1912
void setLocale_helper(const QLocale &l, bool forceUpdate=false)
Definition: qwidget.cpp:6128
void moveRight(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s right edge at the given x coordinate...
Definition: qrect.h:356
void destroy()
Destroy the contained QWidgetBackingStore, if not null, and clear the list of widgets using the backi...
Definition: qwidget.cpp:232
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
void setMaximumSize(const QSize &)
Definition: qwidget.h:972
QWindowSurface * createDefaultWindowSurface()
Definition: qwidget.cpp:398
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
void setLayoutDirection_helper(Qt::LayoutDirection)
Definition: qwidget.cpp:5153
void invalidateGraphicsEffectsRecursively()
Definition: qwidget.cpp:2059
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
uint inheritsInputMethodHints
Definition: qwidget_p.h:778
uint inTopLevelResize
Definition: qwidget_p.h:188
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
static bool testAttribute(uint flag)
static QString constructWindowTitleFromFilePath(const QString &filePath)
Definition: qwidget.cpp:6185
void markDirtyOnScreen(const QRegion &dirtyOnScreen, QWidget *widget, const QPoint &topLevelOffset)
Marks the region of the widget as dirty on screen.
void removeDirtyWidget(QWidget *w)
The QDynamicPropertyChangeEvent class contains event parameters for dynamic property change events...
Definition: qcoreevent.h:380
virtual void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition: qwidget.cpp:9587
The QGraphicsEffectSource class represents the source on which a QGraphicsEffect is installed on...
QPalette::ColorRole backgroundRole() const
Returns the background role of the widget.
Definition: qwidget.cpp:4677
void resolvePalette()
Determine which palette is inherited from this widget&#39;s ancestors and QApplication::palette, resolve this against this widget&#39;s palette (attributes from the inherited palette are copied over this widget&#39;s palette).
Definition: qwidget.cpp:4927
void paintBackground(QPainter *, const QRegion &, int flags=DrawAsRoot) const
Definition: qwidget.cpp:2429
bool activate()
Redoes the layout for parentWidget() if necessary.
Definition: qlayout.cpp:1249
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QWidget * nextInFocusChain() const
Returns the next widget in this widget&#39;s focus chain.
Definition: qwidget.cpp:6873
virtual void moveEvent(QMoveEvent *)
This event handler can be reimplemented in a subclass to receive widget move events which are passed ...
Definition: qwidget.cpp:9566
bool updatesEnabled() const
uint isWidget
Definition: qobject.h:95
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setPalette_helper(const QPalette &)
Definition: qwidget.cpp:4934
void flush(QWidget *, const QRegion &, const QPoint &)
Flushes the given region from the specified widget onto the screen.
Definition: qwidget.cpp:395
virtual void keyReleaseEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key release events...
Definition: qwidget.cpp:9407
void setMinimumSize(const QSize &)
Definition: qwidget.h:969
void qt_mac_update_mouseTracking(QWidget *widget)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static QPalette palette()
Returns the application palette.
QGraphicsProxyWidget * graphicsProxyWidget() const
Returns the proxy widget for the corresponding embedded widget in a graphics view; otherwise returns ...
Definition: qwidget.cpp:12939
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
bool autoFillBackground() const
static bool bypassGraphicsProxyWidget(const QWidget *p)
Returns true if p or any of its parents enable the Qt::BypassGraphicsProxyWidget window flag...
Definition: qwidget_p.h:353
static QStyle * style()
Returns the application&#39;s style object.
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
unsigned char quint8
Definition: qglobal.h:934
The QActionEvent class provides an event that is generated when a QAction is added, removed, or changed.
Definition: qevent.h:632
short baseh
Definition: qwidget_p.h:178
friend OSWindowRef qt_mac_window_for(const QWidget *w)
Definition: qwidget_mac.mm:484
QString accessibleDescription() const
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
virtual QVariant inputMethodQuery(Qt::InputMethodQuery) const
This method is only relevant for input widgets.
Definition: qwidget.cpp:9683
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qwidget.h:1017
void invalidate()
Reimplemented Function
Definition: qlayout.cpp:673
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QWidget * focusWidget() const
Returns the widget that has an input focus for this input context.
bool isActiveWindow() const
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
void overrideWindowState(Qt::WindowStates state)
Definition: qwidget.cpp:3098
bool hasFocus() const
Definition: qwidget.cpp:6583
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
T * qobject_cast(QObject *object)
Definition: qobject.h:375
virtual QWindowSurface * createWindowSurface(QWidget *widget) const =0
void setForegroundRole(QPalette::ColorRole)
Sets the foreground role of the widget to role.
Definition: qwidget.cpp:4773
virtual bool hasHeightForWidth() const
Returns true if this layout&#39;s preferred height depends on its width; otherwise returns false...
void customContextMenuRequested(const QPoint &pos)
This signal is emitted when the widget&#39;s contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget.
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress...
Definition: qevent.h:530
WindowType
Definition: qnamespace.h:270
virtual bool hasHeightForWidth() const
Definition: qwidget.cpp:10260
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isCopyOf(const QFont &) const
Returns true if this font and f are copies of each other, i.e.
Definition: qfont.cpp:1963
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
bool activateUnifiedToolbarAfterFullScreen
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
QSize sizeIncrement() const
bool maximized
whether this widget is maximized
Definition: qwidget.h:193
void setContextMenuPolicy(Qt::ContextMenuPolicy policy)
Definition: qwidget.cpp:7596
void setLayoutItemMargins(int left, int top, int right, int bottom)
Definition: qwidget.cpp:12860
void setUpdatesEnabled(bool enable)
Definition: qwidget.cpp:7670
QPalette naturalWidgetPalette(uint inheritedMask) const
Returns the palette that the widget w inherits from its ancestors and QApplication::palette.
Definition: qwidget.cpp:4884
void setAccessibleDescription(const QString &description)
Definition: qwidget.cpp:11709
void moveBottom(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s bottom edge at the given y coordinate...
Definition: qrect.h:362
void setStyle_helper(QStyle *newStyle, bool propagate, bool metalHack=false)
Definition: qwidget.cpp:2791
#define Q_D(Class)
Definition: qglobal.h:2482
int x
the x coordinate of the widget relative to its parent including any window frame
Definition: qwidget.h:161
uint sizehint_forced
Definition: qwidget.h:122
void qt_x11_enforce_cursor(QWidget *w, bool force)
Update the X11 cursor of the widget w.
int height() const
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
WidgetAttribute
Definition: qnamespace.h:376
T * data() const
void scrollChildren(int dx, int dy)
Definition: qwidget.cpp:421
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:192
virtual int devType() const
Definition: qpaintdevice.h:167
void reparentFocusWidgets(QWidget *oldtlw)
Definition: qwidget.cpp:7047
void addAction(QAction *action)
Appends the action action to this widget&#39;s list of actions.
Definition: qwidget.cpp:3317
void setMinimumHeight(int minh)
Definition: qwidget.cpp:4334
QObjectList children
Definition: qobject.h:93
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
uint in_set_window_state
Definition: qwidget.h:125
QWidget * focusProxy() const
Returns the focus proxy, or 0 if there is no focus proxy.
Definition: qwidget.cpp:6561
static QGestureManager * instance()
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Qt::FocusPolicy focusPolicy() const
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
void setLayoutDirection(Qt::LayoutDirection direction)
Definition: qwidget.cpp:5199
void showNormal()
Restores the widget after it has been maximized or minimized.
Definition: qwidget.cpp:3250
const char * className
Definition: qwizard.cpp:137
void releaseShortcut(int id)
Removes the shortcut with the given id from Qt&#39;s shortcut system.
Definition: qwidget.cpp:11771
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setFixedWidth(int w)
Sets both the minimum and maximum width of the widget to w without changing the heights.
Definition: qwidget.cpp:4368
void setStyle(QStyle *)
Sets the widget&#39;s GUI style to style.
Definition: qwidget.cpp:2772
virtual QSize sizeHint() const
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are ...
bool paintingActive() const
Definition: qpaintdevice.h:170
uint embedded
Definition: qwidget_p.h:190
const QPoint & pos() const
Returns the position of the mouse cursor, relative to the widget that received the event...
Definition: qevent.h:95
void grabGesture(Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
Subscribes the widget to a given gesture with specific flags.
Definition: qwidget.cpp:12964
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void setWindowIcon_helper()
Definition: qwidget.cpp:6351
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
QStyle * style() const
Definition: qwidget.cpp:2742
Qt::Orientations expandingDirections() const
Returns whether this layout can make use of more space than sizeHint().
Definition: qlayout.cpp:1198
bool qt_mac_can_clickThrough(const QWidget *)
Definition: qwidget_mac.mm:280
Class which allows tracking of which widgets are using a given backing store.
Definition: qwidget_p.h:118
void setVersion(int)
Sets the version number of the data serialization format to v.
Definition: qdatastream.h:215
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
uint window_modality
Definition: qwidget.h:128
static QFont font()
Returns the default application font.
void setWindowFilePath_helper(const QString &filePath)
Definition: qwidget.cpp:6461
virtual void languageChange()
Definition: qwidget.cpp:12005
void updateIsTranslucent()
Definition: qwidget.cpp:2356
int top() const
Returns the top margin.
Definition: qmargins.h:99
union _XEvent XEvent
Definition: qwindowdefs.h:116
The QWSEvent class encapsulates an event in Qt for Embedded Linux.
Definition: qwsevent_qws.h:59
bool isHidden() const
Returns true if the widget is hidden, otherwise returns false.
Definition: qwidget.h:1008
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
QRegion childrenRegion() const
void setWhatsThis(const QString &)
Definition: qwidget.cpp:11655
QWidgetData data
Definition: qwidget_p.h:755
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
static const QRectF boundingRect(const QPointF *points, int pointCount)
QGraphicsProxyWidget * proxyWidget
Definition: qwidget_p.h:251
void deactivateWidgetCleanup()
Definition: qwidget.cpp:2496
QInputContext * inputContext() const
Definition: qwidget.cpp:457
void clearFocus()
Takes keyboard input focus from the widget.
Definition: qwidget.cpp:6757
QSizePolicy sizePolicy() const
QWidget * viewport() const
Returns the viewport widget.
void move(int from, int to)
Moves the item at index position from to index position to.
Definition: qlist.h:628
static int pointToRect(const QPoint &p, const QRect &r)
Definition: qwidget.cpp:7128
Q_CORE_EXPORT void qDebug(const char *,...)
static void quit()
Tells the application to exit with return code 0 (success).
void markDirty(const QRegion &rgn, QWidget *widget, bool updateImmediately=false, bool invalidateBuffer=false)
Marks the region of the widget as dirty (if not already marked as dirty) and posts an UpdateRequest e...
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
bool isWindowModified() const
Definition: qwidget.cpp:11554
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
virtual void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
Definition: qwidget.cpp:9548
QRect systemRect() const
Retrieves the rect for drawing within the backing store.
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
QIcon windowIcon() const
void invalidateCache(InvalidateReason reason=SourceChanged) const
void updateGeometry_helper(bool forceUpdate)
Definition: qwidget.cpp:10346
QFont resolve(const QFont &) const
Returns a new QFont that has attributes copied from other that have not been previously set on this f...
Definition: qfont.cpp:1983
#define QT_RETHROW
Definition: qglobal.h:1539
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
void setWindowTitle(const QString &)
Definition: qwidget.cpp:6312
Qt::ContextMenuPolicy contextMenuPolicy() const
NSWindow * window
int width() const
Returns the width.
Definition: qsize.h:126
static QIcon windowIcon()
QSize frameSize() const
static QWidget * activeModalWidget()
Returns the active modal widget.
void show_recursive()
Makes the widget visible in the isVisible() meaning of the word.
Definition: qwidget.cpp:7698
QRegion clipRegion() const
Returns the currently set clip region.
Definition: qpainter.cpp:2562
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition: qwidget.cpp:4708
void createExtra()
Creates the widget extra data.
Definition: qwidget.cpp:1802
friend Q_GUI_EXPORT QWidgetData * qt_qwidget_data(QWidget *widget)
Definition: qwidget.cpp:12915
qreal windowOpacity() const
void clearMask()
Removes any mask set by setMask().
Definition: qwidget.cpp:13324
QGraphicsEffect * graphicsEffect
Definition: qwidget_p.h:710
void requestRegion(int winId, const QString &surfacekey, const QByteArray &surfaceData, const QRegion &region)
QPalette palette() const
void inheritStyle()
Definition: qwidget.cpp:2865
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setDisabledStyle(QWidget *w, bool setStyle)
Definition: qwidget.cpp:8586
QRect normalGeometry
Definition: qwidget_p.h:181
QWidget * nativeParentWidget() const
Returns the native parent for this widget, i.
Definition: qwidget.cpp:4514
void insertActions(QAction *before, QList< QAction *> actions)
Inserts the actions actions to this widget&#39;s list of actions, before the action before.
Definition: qwidget.cpp:3376
int width() const
Definition: qpaintdevice.h:91
void setWindowFilePath(const QString &filePath)
Definition: qwidget.cpp:6449
The QMoveEvent class contains event parameters for move events.
Definition: qevent.h:334
void createTLExtra()
Definition: qwidget.cpp:1755
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isCopyOf(const QPalette &p) const
Returns true if this palette and p are copies of each other, i.e.
Definition: qpalette.cpp:1233
void setWindowIconText(const QString &)
Definition: qwidget.cpp:6299
short inch
Definition: qwidget_p.h:177
QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt)
bool isAccepted() const
Definition: qcoreevent.h:307
void lower()
Lowers the widget to the bottom of the parent widget&#39;s stack.
Definition: qwidget.cpp:11939
void render_helper(QPainter *painter, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
Definition: qwidget.cpp:5614
static FILE * stream
void destroy(bool destroyWindow=true, bool destroySubWindows=true)
Frees up window system resources.
QPoint brushOrigin() const
Returns the currently set brush origin.
Definition: qpainter.cpp:2168
void setDirtyOpaqueRegion()
Definition: qwidget.cpp:2075
QMargins contentsMargins() const
The contentsMargins function returns the widget&#39;s contents margins.
Definition: qwidget.cpp:7532
void qt_mac_replaceDrawRectOriginal(void *window, QWidgetPrivate *widget)
void setMaximumWidth(int maxw)
Definition: qwidget.cpp:4343
bool updatesEnabled
whether updates are enabled
Definition: qwidget.h:190
bool visible
whether the widget is visible
Definition: qwidget.h:191
The QAccessibleEvent class is used to query addition accessibility information about complex widgets...
Definition: qaccessible.h:449
void showChildren(bool spontaneous)
Definition: qwidget.cpp:8144
Qt::WindowModality windowModality() const
virtual void update()
This virtual function is called when a state in the focus widget has changed.
ContextMenuPolicy
Definition: qnamespace.h:1533
static void fillRegion(QPainter *painter, const QRegion &rgn, const QBrush &brush)
Definition: qwidget.cpp:2392
friend class QPixmap
Definition: qwidget.h:748
WindowRef OSWindowRef
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Returns the widget&#39;s contents margins for left, top, right, and bottom.
Definition: qwidget.cpp:7509
static void setFocusWidget(QWidget *focus, Qt::FocusReason reason)
bool hasClipping() const
Returns true if clipping has been set; otherwise returns false.
Definition: qpainter.cpp:2499
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
QPalette::ColorRole foregroundRole() const
Returns the foreground role.
Definition: qwidget.cpp:4728
uint widget_attributes
Definition: qwidget.h:118
QTouchEvent::DeviceType deviceType() const
Returns the touch device Type, which is of type QTouchEvent::DeviceType {DeviceType}.
Definition: qevent.h:818
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition: qwidget.h:1041
void raise()
Raises this widget to the top of the parent widget&#39;s stack.
Definition: qwidget.cpp:11901
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
#define qApp
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
friend class QWidgetEffectSourcePrivate
Definition: qwidget.h:771
QRect frameStrut() const
Definition: qwidget.cpp:12607
int width() const
void setContentsMargins(int left, int top, int right, int bottom)
Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom.
Definition: qwidget.cpp:7449
QDummyWindowSurface(QWidget *window)
Definition: qwidget.cpp:393
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
void adjustSize()
Adjusts the size of the widget to fit its contents.
Definition: qwidget.cpp:8488
Qt::WindowFlags window_flags
Definition: qwidget.h:119
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
const char * name
QWidget * childAt(int x, int y) const
Returns the visible child widget at the position ({x}, {y}) in the widget&#39;s coordinate system...
Definition: qwidget.h:934
void drawWidget(QPaintDevice *pdev, const QRegion &rgn, const QPoint &offset, int flags, QPainter *sharedPainter=0, QWidgetBackingStore *backingStore=0)
Definition: qwidget.cpp:5679
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false...
Definition: qpainter.cpp:1545
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition: qicon.cpp:769
const char * layout
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
void setStatusTip(const QString &)
Definition: qwidget.cpp:11629
void setWindowRole(const QString &)
Sets the window&#39;s role to role.
Definition: qwidget.cpp:6493
void setWindowFlags(Qt::WindowFlags type)
Definition: qwidget.cpp:10399
virtual bool x11Event(XEvent *)
This special event handler can be reimplemented in a subclass to receive native X11 events passed in ...
Definition: qwidget.cpp:9969
static QWidget * find(WId)
Returns a pointer to the widget with window identifer/handle id.
Definition: qwidget.cpp:2517
const QPalette & palette() const
LayoutDirection
Definition: qnamespace.h:1580
virtual void mouseDoubleClickEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse double click...
Definition: qwidget.cpp:9306
QWidgetData * data
Definition: qwidget.h:815
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event)
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
CompositionMode compositionMode() const
Returns the current composition mode.
Definition: qpainter.cpp:2466
const char * styleHint(const QFontDef &request)
unsigned short quint16
Definition: qglobal.h:936
static QWidget * hidden_focus_widget
Q_CORE_EXPORT void qWarning(const char *,...)
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
const_iterator insert(const T &value)
Definition: qset.h:179
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QPaintDevice * paintDevice()
Implement this function to return the appropriate paint device.
Definition: qwidget.cpp:394
uint inRepaint
Definition: qwidget_p.h:189
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void setTopLeft(const QPoint &p)
Set the top-left corner of the rectangle to the given position.
Definition: qrect.h:270
const QTransform & deviceTransform() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
Definition: qpainter.cpp:9579
void clear()
Definition: qset.h:87
uint inRenderWithPainter
Definition: qwidget_p.h:277
QFont naturalWidgetFont(uint inheritedMask) const
Definition: qwidget.cpp:5030
QWindowSurface * windowSurface() const
Returns the QWindowSurface this widget will be drawn into.
Definition: qwidget.cpp:12819
void setShortcutAutoRepeat(int id, bool enable=true)
If enable is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disabled...
Definition: qwidget.cpp:11808
QString windowTitle() const
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
QString accessibleName() const
virtual void actionEvent(QActionEvent *)
This event handler is called with the given event whenever the widget&#39;s actions are changed...
Definition: qwidget.cpp:9600
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
QString windowFilePath() const
QString statusTip() const
void setCursor(const QCursor &)
Definition: qwidget.cpp:5290
void setShortcutEnabled(int id, bool enable=true)
If enable is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled...
Definition: qwidget.cpp:11790
QPointF screenPos() const
Returns the screen position of this touch point.
Definition: qevent.cpp:4498
void setValue(const QString &aText)
Set the description or help text for the given child() to text, thereby answering the request...
Definition: qaccessible.h:455
static void sendPostedEvents()
QFont font() const
The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leav...
Definition: qevent.h:577
void create(WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
Creates a new widget window if window is 0, otherwise sets the widget&#39;s window to window...
Definition: qwidget.cpp:1454
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QTransform systemTransform
int numScreens() const
QCursor cursor
the cursor shape for this widget
Definition: qwidget.h:183
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
bool close_helper(CloseMode mode)
Definition: qwidget.cpp:8218
void updateMicroFocus()
Updates the widget&#39;s micro focus.
Definition: qwidget.cpp:11820
Qt::WindowFlags savedFlags
Definition: qwidget_p.h:182
uint is_closing
Definition: qwidget.h:123
void * HANDLE
Definition: qnamespace.h:1671
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
void setWindowIcon(const QIcon &icon)
Definition: qwidget.cpp:6362
void setCoords(int x1, int y1, int x2, int y2)
Sets the coordinates of the rectangle&#39;s top-left corner to (x1, y1), and the coordinates of its botto...
Definition: qrect.h:416
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
void setWindowModality(Qt::WindowModality windowModality)
Definition: qwidget.cpp:2991
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set...
Definition: qbrush.cpp:785
static bool qRectIntersects(const QRect &r1, const QRect &r2)
Definition: qwidget.cpp:163
void setWindowTitle_helper(const QString &cap)
Definition: qwidget.cpp:6285
void show()
Shows the widget and its child widgets.
bool isOpaque() const
Returns true if the brush is fully opaque otherwise false.
Definition: qbrush.cpp:910
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
PixmapPadMode
This enum describes how the pixmap returned from sourcePixmap should be padded.
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
static void setActiveWindow(QWidget *act)
Sets the active window to the active widget in response to a system event.
virtual void keyPressEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition: qwidget.cpp:9375
void addActions(QList< QAction *> actions)
Appends the actions actions to this widget&#39;s list of actions.
Definition: qwidget.cpp:3327
#define QT_CATCH(A)
Definition: qglobal.h:1537
static QWidgetSet * allWidgets
Definition: qwidget_p.h:715
bool isEmpty() const
Returns true if the key sequence is empty; otherwise returns false.
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition: qobject.h:275
void setMask(const QBitmap &)
Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible...
Definition: qwidget.cpp:13309
bool setMaximumSize_helper(int &maxw, int &maxh)
Definition: qwidget.cpp:4163
static QWidgetList topLevelWidgets()
Returns a list of the top-level widgets (windows) in the application.
short incw
Definition: qwidget_p.h:177
GestureType
Definition: qnamespace.h:1759
QRect rect() const
void resolveLocale()
Definition: qwidget.cpp:6167
QRegion mask() const
Returns the mask currently set on a widget.
Definition: qwidget.cpp:10058
void showMinimized()
Shows the widget minimized, as an icon.
Definition: qwidget.cpp:3038
void setEnabled(bool)
Definition: qwidget.cpp:3447
void setGraphicsEffect(QGraphicsEffect *effect)
The setGraphicsEffect function is for setting the widget&#39;s graphics effect.
Definition: qwidget.cpp:5517
QInputContext * inputContext()
This function returns the QInputContext for this widget.
Definition: qwidget.cpp:474
void hideChildren(bool spontaneous)
Definition: qwidget.cpp:8167
The QWindowSurface class provides the drawing area for top-level windows.
struct OpaqueEventRef * EventRef
bool isEqual(ColorGroup cr1, ColorGroup cr2) const
Returns true (usually quickly) if color group cg1 is equal to cg2; otherwise returns false...
Definition: qpalette.cpp:1035
bool isEnabled() const
Definition: qwidget.h:948
virtual void setVisible(bool visible)
Definition: qwidget.cpp:7991
The QTabletEvent class contains parameters that describe a Tablet event.
Definition: qevent.h:179
void hide()
Hides the widget.
Definition: qwidget.h:501
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:368
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
void getLayoutItemMargins(int *left, int *top, int *right, int *bottom) const
Definition: qwidget.cpp:12848
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QGraphicsEffect * graphicsEffect() const
The graphicsEffect function returns a pointer to the widget&#39;s graphics effect.
Definition: qwidget.cpp:5484
QPainter * sharedPainter
Definition: qwidget_p.h:168
bool isMaximized() const
Definition: qwidget.cpp:3074
QWidget * focus_next
Definition: qwidget_p.h:701
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene...
void setToolTip(const QString &)
Definition: qwidget.cpp:11600
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
The QPlatformIntegration class is the entry for WindowSystem specific functionality.
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
void setAutoFillBackground(bool enabled)
Definition: qwidget.cpp:631
void repaint()
Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the ...
Definition: qwidget.cpp:10761
int length() const
Same as size().
Definition: qbytearray.h:356
void qt_mac_replaceDrawRect(void *window, QWidgetPrivate *widget)
uint dirtyOpaqueChildren
Definition: qwidget_p.h:770
The QChildEvent class contains event parameters for child object events.
Definition: qcoreevent.h:353
int grabShortcut(const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
Adds a shortcut to Qt&#39;s shortcut system that watches for the given key sequence in the given context...
Definition: qwidget.cpp:11747
void drawTiledPixmap(const QRectF &rect, const QPixmap &pm, const QPointF &offset=QPointF())
Draws a tiled pixmap, inside the given rectangle with its origin at the given position.
Definition: qpainter.cpp:7146
uint high_attributes[4]
Definition: qwidget_p.h:767
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QAction * exec()
Executes this menu synchronously.
Definition: qmenu.cpp:2101
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
void create(QWidget *tlw)
Destroy the contained QWidgetBackingStore, if not null, and clear the list of widgets using the backi...
Definition: qwidget.cpp:218
uint inheritedPaletteResolveMask
Definition: qwidget_p.h:743
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
virtual void contextMenuEvent(QContextMenuEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive widget context men...
Definition: qwidget.cpp:9645
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
InputMethodQuery
Definition: qnamespace.h:1541
void setRenderHints(RenderHints hints, bool on=true)
Sets the given render hints on the painter if on is true; otherwise clears the render hints...
Definition: qpainter.cpp:7649
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
Q_GUI_EXPORT void qt_x11_set_global_double_buffer(bool enable)
Definition: qwidget.cpp:153
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
void setAccessibleName(const QString &name)
Definition: qwidget.cpp:11684
QWidget * childAt_helper(const QPoint &, bool) const
Definition: qwidget.cpp:10288
virtual void tabletEvent(QTabletEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive tablet events for ...
Definition: qwidget.cpp:9347
bool unifiedTitleAndToolBarOnMac
whether the window uses the unified title and toolbar look on Mac OS X
Definition: qmainwindow.h:83
virtual void dragMoveEvent(QDragMoveEvent *)
This event handler is called if a drag is in progress, and when any of the following conditions occur...
Definition: qwidget.cpp:9786
static void updateSoftKeys()
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
virtual QPaintEngine * paintEngine() const =0
static QWidget * focusNextPrevChild_helper(QWidget *toplevel, bool next)
internal Helper function that returns the new focus widget, but does not set the focus reason...
Q_CORE_EXPORT void qFatal(const char *,...)
void setFocusProxy(QWidget *)
Sets the widget&#39;s focus proxy to widget w.
Definition: qwidget.cpp:6537
struct tagMSG MSG
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags, bool readyToRender)
Definition: qwidget.cpp:5856
bool isWidgetType() const
Returns true if the object is a widget; otherwise returns false.
Definition: qobject.h:146
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int devType() const
Definition: qwidget.cpp:1235
bool setMinimumSize_helper(int &minw, int &minh)
Definition: qwidget.cpp:4081
virtual void enabledChange(bool)
Definition: qwidget.cpp:12001
QRegion mask
Definition: qwidget_p.h:260
QString toolTip() const
const QRect screenGeometry(int screen=-1) const
QPoint mapFromParent(const QPoint &) const
Translates the parent widget coordinate pos to widget coordinates.
Definition: qwidget.cpp:4473
The QDropEvent class provides an event which is sent when a drag and drop action is completed...
Definition: qevent.h:476
void setAcceptDrops(bool on)
Definition: qwidget.cpp:3534
static QWidget * activePopupWidget()
Returns the active popup widget.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
The QWindowStateChangeEvent class provides the window state before a window state change...
Definition: qevent.h:705
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
Definition: qpainter.cpp:2917
virtual void wheelEvent(QWheelEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive wheel events for t...
Definition: qwidget.cpp:9326
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
QTLWExtra * topextra
Definition: qwidget_p.h:249
const QTransform & worldTransform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9652
QWindowSurface * createDefaultWindowSurface_sys()
int x() const
void resize(int w, int h)
This corresponds to resize(QSize(w, h)).
Definition: qwidget.h:1014
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
Definition: qpainter.cpp:2422
Qt::LayoutDirection layoutDirection() const
QWidget * focus_prev
Definition: qwidget_p.h:702
void setAlphaF(qreal alpha)
Sets the alpha of this color to alpha.
Definition: qcolor.cpp:1117
FocusReason
Definition: qnamespace.h:1521
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
static bool isBlockedByModal(QWidget *widget)
Returns true if widget is blocked by a modal window.
QPoint pos
the position of the widget within its parent widget
Definition: qwidget.h:163
virtual bool winEvent(MSG *message, long *result)
This special event handler can be reimplemented in a subclass to receive native Windows events which ...
Definition: qwidget.cpp:9941
QWidgetItemV2 * widgetItem
Definition: qwidget_p.h:707
static void cleanup(QWidget *that, QWidgetPrivate *d)
Definition: qwidget.cpp:1147
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
virtual void hideEvent(QHideEvent *)
This event handler can be reimplemented in a subclass to receive widget hide events.
Definition: qwidget.cpp:9864
void setFixedSize(const QSize &)
Sets both the minimum and maximum sizes of the widget to s, thereby preventing it from ever growing o...
Definition: qwidget.cpp:4284
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
QPaintEngine * paintEngine() const
Returns the widget&#39;s paint engine.
void setOpaque(bool opaque)
Definition: qwidget.cpp:2337
virtual void dropEvent(QDropEvent *)
This event handler is called when the drag is dropped on this widget.
Definition: qwidget.cpp:9817
bool isScaling() const
Returns true if the matrix represents a scaling transformation, otherwise returns false...
Definition: qtransform.h:214
The QStatusTipEvent class provides an event that is used to show messages in a status bar...
Definition: qevent.h:606
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition: qpoint.h:376
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
void unsetLocale()
Definition: qwidget.cpp:6178
void createWinId(WId id=0)
Definition: qwidget.cpp:2574
bool isAboutToShow() const
Definition: qwidget.cpp:5542
QPointF pos() const
Returns the position of this touch point, relative to the widget or QGraphicsItem that received the e...
Definition: qevent.cpp:4473
int y
the y coordinate of the widget relative to its parent and including any window frame ...
Definition: qwidget.h:162
QRect frameGeometry() const
void setUpdatesEnabled_helper(bool)
Definition: qwidget.cpp:1931
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
QString qt_setWindowTitle_helperHelper(const QString &title, const QWidget *widget)
Returns a modified window title with the [*] place holder replaced according to the rules described i...
Definition: qwidget.cpp:6240
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
void eraseRect(const QRectF &)
Erases the area inside the given rectangle.
Definition: qpainter.cpp:7332
void hide_helper()
Definition: qwidget.cpp:7898
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
Definition: qwidget.cpp:3386
The QDragEnterEvent class provides an event which is sent to a widget when a drag and drop action ent...
Definition: qevent.h:555
uint focus_policy
Definition: qwidget.h:121
int key
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
virtual void closeEvent(QCloseEvent *)
This event handler is called with the given event when Qt receives a window close request for a top-l...
Definition: qwidget.cpp:9626
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
bool isFullScreen() const
Definition: qwidget.cpp:3153
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
QSize maximumSize() const
QPoint mapToParent(const QPoint &) const
Translates the widget coordinate pos to a coordinate in the parent widget.
Definition: qwidget.cpp:4459
QPainter * sharedPainter() const
Definition: qwidget_p.h:1015
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can&#39;t.
Definition: qwidget.cpp:6836
QRegion dirtyRegion(QWidget *widget=0) const
Returns the region (in top-level coordinates) that needs repaint and/or flush.
void subtractOpaqueChildren(QRegion &rgn, const QRect &clipRect) const
Definition: qwidget.cpp:2128
const QList< QTouchEvent::TouchPoint > & touchPoints() const
Returns the list of touch points contained in the touch event.
Definition: qevent.h:820
unsigned int quint32
Definition: qglobal.h:938
The QMainWindow class provides a main application window.
Definition: qmainwindow.h:63
void * glContext
Definition: qwidget_p.h:248
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
uint opacity
Definition: qwidget_p.h:185
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget&#39;s actions.
Definition: qwidget.cpp:3407
void insertAction(QAction *before, QAction *action)
Inserts the action action to this widget&#39;s list of actions, before the action before.
Definition: qwidget.cpp:3342
FocusPolicy
Definition: qnamespace.h:181
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
static const QMetaObjectPrivate * priv(const uint *data)
int qstrncmp(const char *str1, const char *str2, uint len)
Definition: qbytearray.h:101
static void(* destroyed)(QAbstractDeclarativeData *, QObject *)
Definition: qobject_p.h:93
void setMaximumHeight(int maxh)
Definition: qwidget.cpp:4352
bool isTopLevel() const
Use isWindow() instead.
Definition: qwidget.h:942
bool isAncestorOf(const QWidget *child) const
Returns true if this widget is a parent, (or grandparent and so on to any level), of the given child...
Definition: qwidget.cpp:8573
QString objectName() const
int height() const
Returns the height.
Definition: qsize.h:129
~QWidget()
Destroys the widget.
Definition: qwidget.cpp:1572
void qt_mac_fill_background(QPainter *painter, const QRegion &rgn, const QBrush &brush)
QWidgetPaintContext * context
Definition: qwidget_p.h:993
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void setMinimumWidth(int minw)
Definition: qwidget.cpp:4325
void activateChildLayoutsRecursively()
Definition: qwidget.cpp:7752
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:123
Definition: qnamespace.h:54
virtual void reset()=0
This function can be reimplemented in a subclass to reset the state of the input method.
uint inheritedFontResolveMask
Definition: qwidget_p.h:742
QFactoryLoader * l
QPixmap * iconPixmap
Definition: qwidget_p.h:165
QSize minimumSize() const
void saveWidgetFont(QWidget *w, const QFont &font) const
virtual void windowActivationChange(bool)
Definition: qwidget.cpp:12004
QWExtra * extra
Definition: qwidget_p.h:700
bool qt_mac_insideKeyWindow(const QWidget *w)
Definition: qwidget_mac.mm:311
virtual bool qwsEvent(QWSEvent *)
This special event handler can be reimplemented in a subclass to receive native Qt for Embedded Linux...
Definition: qwidget.cpp:9993
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
uint hasMask
Definition: qwidget_p.h:278
WId internalWinId() const
Returns the window system identifier of the widget, or 0 if the widget is not created yet...
Definition: qwidget.h:244
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
void resolveFont()
Determine which font is implicitly imposed on this widget by its ancestors and QApplication::font, resolve this against its own font (attributes from the implicit font are copied over).
Definition: qwidget.cpp:5074
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
void activateWindow()
Sets the top-level widget containing this widget to be the active window.
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
static void setAttribute_internal(Qt::WidgetAttribute attribute, bool on, QWidgetData *data, QWidgetPrivate *d)
Definition: qwidget.cpp:11063
void draw(QPainter *p)
Definition: qwidget.cpp:6027
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
void createRecursively()
Definition: qwidget.cpp:1423
void unregisterWidgetSubtree(QWidget *w)
Recursively remove widget and all of its descendents.
Definition: qwidget.cpp:280
static void applyX11SpecificCommandLineArguments(QWidget *main_widget)
quint16 index
bool isPrimary() const
Returns true if this touch point is the primary touch point.
Definition: qevent.cpp:4462
QVariant property(const char *name) const
Returns the value of the object&#39;s name property.
Definition: qobject.cpp:3807
bool isMinimized() const
Definition: qwidget.cpp:3027
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QObject * parent
Definition: qobject.h:92
#define Q_OS_WIN
Definition: qglobal.h:270
The TouchPoint class provides information about a touch point in a QTouchEvent.
Definition: qevent.h:744
QTransform lastEffectTransform
Definition: qwidget_p.h:994
virtual void polish(QWidget *)
Initializes the appearance of the given widget.
Definition: qstyle.cpp:390
void show_helper()
Definition: qwidget.cpp:7782
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320
static void emitLastWindowClosed()
static QString appName
friend class QStyleSheetStyle
Definition: qwidget.h:765
friend Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
static QWidgetMapper * mapper
Definition: qwidget_p.h:714
bool isNull() const
Returns true if both the width and height is 0; otherwise returns false.
Definition: qsize.h:117
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
int left() const
Returns the left margin.
Definition: qmargins.h:96
void createWinId()
Definition: qwidget.cpp:2626
bool autoDestruct() const
Definition: qpaintengine.h:250
short basew
Definition: qwidget_p.h:178
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
uint posFromMove
Definition: qwidget_p.h:186
void setEnabled_helper(bool)
Definition: qwidget.cpp:3454
QWidgetPrivate(int version=QObjectPrivateVersion)
Definition: qwidget.cpp:288
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
void translate(int dx, int dy)
Translates (moves) the region dx along the X axis and dy along the Y axis.
Definition: qregion.cpp:4116
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
HDC getDC() const
Returns the window system handle of the widget, for low-level access.
Definition: qwidget.cpp:11849
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
QRegion clipRegion() const
Definition: qwidget.cpp:2021
The QTouchEvent class contains parameters that describe a touch event.
Definition: qevent.h:741
uint in_destructor
Definition: qwidget.h:129
const QFont & font() const
void setWinId(WId)
Definition: qwidget.cpp:1726
void subtractOpaqueSiblings(QRegion &source, bool *hasDirtySiblingsAbove=0, bool alsoNonOpaque=false) const
Definition: qwidget.cpp:2139
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
int screenNumber(const QWidget *widget=0) const
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
struct OpaqueEventHandlerCallRef * EventHandlerCallRef
virtual void moveToScreen(QWidget *window, int screen)
This function is called when a QWidget is displayed on screen, or the QWidget is to be displayed on a...
void updateIsOpaque()
Definition: qwidget.cpp:2272
Qt::WindowType windowType() const
Returns the window type of this widget.
Definition: qwidget.h:937
QRegion translated(int dx, int dy) const
Returns a copy of the region that is translated dx along the x axis and dy along the y axis...
Definition: qregion.cpp:743
WId winId() const
Returns the window system identifier of the widget.
Definition: qwidget.cpp:2557
uint fstrut_dirty
Definition: qwidget.h:126
#define Q_WS_WINCE
Definition: qglobal.h:895
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
bool close()
Closes this widget.
Definition: qwidget.cpp:8305
QWidget * previousInFocusChain() const
The previousInFocusChain function returns the previous widget in this widget&#39;s focus chain...
Definition: qwidget.cpp:6889
removePostedEvents
Removes all events of the given eventType that were posted using postEvent() for receiver.
QWidget * wid
Definition: qlayoutitem.h:141
void ungrabGesture(Qt::GestureType type)
Unsubscribes the widget from a given gesture type.
Definition: qwidget.cpp:12977
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
QSet< QWidget * > m_widgets
Definition: qwidget_p.h:157
QPalette pal
Definition: qwidget.h:132
static QGraphicsProxyWidget * nearestGraphicsProxyWidget(const QWidget *origin)
Finds the nearest widget embedded in a graphics proxy widget along the chain formed by this widget an...
Definition: qwidget.cpp:6098
void registerWidget(QWidget *w)
Add the widget to the list of widgets currently using the backing store.
Definition: qwidget.cpp:247
const QRect availableGeometry(int screen=-1) const
ShortcutContext
Definition: qnamespace.h:1478
Qt::WindowFlags windowFlags() const
Window flags are a combination of a type (e.
Definition: qwidget.h:939
void showFullScreen()
Shows the widget in full-screen mode.
Definition: qwidget.cpp:3185
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
bool testAttribute_helper(Qt::WidgetAttribute) const
Definition: qwidget.cpp:11453
QTouchEventSequence touchEvent(QWidget *widget=0, QTouchEvent::DeviceType deviceType=QTouchEvent::TouchScreen)
Creates and returns a QTouchEventSequence for the device deviceType to simulate events for widget...
Definition: qtesttouch.h:141
void setInputContext(QInputContext *)
This function sets the input context context on this widget.
Definition: qwidget.cpp:491
virtual void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition: qwidget.cpp:9239
static QString applicationName()
QRegion qt_dirtyRegion(QWidget *widget)
Definition: qwidget.cpp:1111
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
static Window sourceWindow
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:53
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
QLayout * takeLayout()
Remove the layout from the widget.
Definition: qwidget.cpp:10153
QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset, QGraphicsEffect::PixmapPadMode mode) const
Definition: qwidget.cpp:6046
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
QWidgetBackingStoreTracker backingStore
Definition: qwidget_p.h:166
QLayout * layout()
Reimplemented Function
static QGraphicsSystem * graphicsSystem()
QIcon * icon
Definition: qwidget_p.h:164
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
QPoint mapFrom(QWidget *, const QPoint &) const
Translates the widget coordinate pos from the coordinate system of parent to this widget&#39;s coordinate...
Definition: qwidget.cpp:4433
const QRect & geometry() const
QWidgetBackingStore * maybeBackingStore() const
Definition: qwidget_p.h:1036
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
Shows text as a "What&#39;s This?" window, at global position pos.
Definition: qwhatsthis.cpp:754
virtual void dragLeaveEvent(QDragLeaveEvent *)
This event handler is called when a drag is in progress and the mouse leaves this widget...
Definition: qwidget.cpp:9802
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
void setStyleSheet(const QString &styleSheet)
Definition: qwidget.cpp:2709
static void setTabOrder(QWidget *, QWidget *)
Puts the second widget after the first widget in the focus order.
Definition: qwidget.cpp:6975
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately before the event occurred.
Definition: qevent.h:79
void setUnifiedTitleAndToolBarOnMac(bool set)
void sendPendingMoveAndResizeEvents(bool recursive=false, bool disableUpdates=false)
Definition: qwidget.cpp:7720
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
void setSizePolicy(QSizePolicy)
Definition: qwidget.cpp:10198
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
bool isOverlapped(const QRect &) const
Definition: qwidget.cpp:1877
void propagatePaletteChange()
Propagate this widget&#39;s palette to all children, except style sheet widgets, and windows that don&#39;t e...
Definition: qwidget.cpp:1963
virtual void setFocusWidget(QWidget *w)
Sets the widget that has an input focus for this input context.
Orientation
Definition: qnamespace.h:174
static int instanceCounter
Definition: qwidget_p.h:752
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
QString whatsThis() const
Qt::InputMethodHints inputMethodHints() const
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void overrideWindowFlags(Qt::WindowFlags type)
Sets the window flags for the widget to flags, without telling the window system. ...
Definition: qwidget.cpp:10434
QRegion opaqueChildren
Definition: qwidget_p.h:725
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
void render(QPaintDevice *target, const QPoint &targetOffset=QPoint(), const QRegion &sourceRegion=QRegion(), RenderFlags renderFlags=RenderFlags(DrawWindowBackground|DrawChildren))
Renders the sourceRegion of this widget into the target using renderFlags to determine how to render...
Definition: qwidget.cpp:5372
QGraphicsEffectSource * source() const
Returns a pointer to the source, which provides extra context information that can be useful for the ...
QRect childrenRect() const
void clipToEffectiveMask(QRegion &region) const
Definition: qwidget.cpp:2230
virtual void fontChange(const QFont &)
Definition: qwidget.cpp:12003
QWidgetBackingStore * m_ptr
Definition: qwidget_p.h:156
static Type type()
Returns the type of application (Tty , GuiClient, or GuiServer).
int bottom() const
Returns the bottom margin.
Definition: qmargins.h:105
static void leaveModal(QWidget *)
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...
bool qt_mac_is_macdrawer(const QWidget *w)
Definition: qwidget_mac.mm:306
QRegion systemClip() const
Returns the system clip.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QString fileName(const QString &fileUrl)
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
void setWindowOpacity(qreal level)
Definition: qwidget.cpp:11497
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
uint sizeAdjusted
Definition: qwidget_p.h:187
void repolish(QWidget *widget)
#define QT_TRY
Definition: qglobal.h:1536
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431
bool restoreGeometry(const QByteArray &geometry)
Restores the geometry and state top-level widgets stored in the byte array geometry.
Definition: qwidget.cpp:7313
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
QList< T > findChildren(const QString &aName=QString()) const
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
Definition: qobject.h:162
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
QByteArray saveGeometry() const
Saves the current geometry and state for top-level widgets.
Definition: qwidget.cpp:7251
int right() const
Returns the right margin.
Definition: qmargins.h:102
virtual QPoint contentsOffset() const
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
WindowModality
Definition: qnamespace.h:1683
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
#define INT_MAX
QDesktopWidget * qt_desktopWidget
void unregisterWidget(QWidget *w)
Remove the widget from the list of widgets currently using the backing store.
Definition: qwidget.cpp:265
void updateStyleSheetFont(QWidget *w) const
The QCloseEvent class contains parameters that describe a close event.
Definition: qevent.h:364
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
static bool flushPaint(QWidget *widget, const QRegion &rgn)
QRegion visibleRegion() const
Returns the unobscured region where paint events can occur.
Definition: qwidget.cpp:8404
#define enabled
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
static QPaintDevice * redirected(const QPaintDevice *device, QPoint *offset=0)
Using QWidget::render() obsoletes the use of this function.
Definition: qpainter.cpp:8391
uint context_menu_policy
Definition: qwidget.h:127
static void unflushPaint(QWidget *widget, const QRegion &rgn)
static void enterModal(QWidget *)
QRect effectiveRectFor(const QRect &rect) const
Definition: qwidget_p.h:658
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
void setPalette(const QPalette &)
Use the single-argument overload instead.
Definition: qwidget.cpp:4858
virtual void enterEvent(QEvent *)
This event handler can be reimplemented in a subclass to receive widget enter events which are passed...
Definition: qwidget.cpp:9475
WId winid
Definition: qwidget.h:117
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
bool end()
Ends painting.
Definition: qpainter.cpp:1929
virtual void draw(QPainter *painter)=0
This pure virtual function draws the effect and is called whenever the source needs to be drawn...
QRect normalGeometry() const
void updateFont(const QFont &)
Assign font to this widget, and propagate it to all children, except style sheet widgets (handled dif...
Definition: qwidget.cpp:5093
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
void move(int x, int y)
This corresponds to move(QPoint(x, y)).
Definition: qwidget.h:1011
QRegion prepareToRender(const QRegion &region, QWidget::RenderFlags renderFlags)
Definition: qwidget.cpp:5556
int child() const
Returns the (1-based) index of the child to which the request applies.
Definition: qaccessible.h:453
The QWeakPointer class holds a weak reference to a shared pointer.
uint in_show
Definition: qwidget.h:124
The QGraphicsEffect class is the base class for all graphics effects.
SubElement
This enum represents a sub-area of a widget.
Definition: qstyle.h:289
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
void _q_showIfNotHidden()
Definition: qwidget.cpp:8137
virtual void paletteChange(const QPalette &)
Definition: qwidget.cpp:12002
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Definition: qcursor.cpp:469
void deleteExtra()
Deletes the widget extra data.
Definition: qwidget.cpp:1843
QPalette resolve(const QPalette &) const
Returns a new QPalette that has attributes copied from other.
Definition: qpalette.cpp:1101
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770
Qt::LayoutDirection direction
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtooltip.cpp:497
void setFixedHeight(int h)
Sets both the minimum and maximum heights of the widget to h without changing the widths...
Definition: qwidget.cpp:4388
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311
static int maxInstances
Definition: qwidget_p.h:753
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60