Qt 4.8
qgraphicswidget.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 "qglobal.h"
43 
44 #ifndef QT_NO_GRAPHICSVIEW
45 
46 #include "qgraphicswidget.h"
47 #include "qgraphicswidget_p.h"
48 #include "qgraphicslayout.h"
49 #include "qgraphicslayout_p.h"
50 #include "qgraphicsscene.h"
51 #include "qgraphicssceneevent.h"
52 
53 #ifndef QT_NO_ACTION
54 #include <private/qaction_p.h>
55 #endif
56 #include <private/qapplication_p.h>
57 #include <private/qgraphicsscene_p.h>
58 #ifndef QT_NO_SHORTCUT
59 #include <private/qshortcutmap_p.h>
60 #endif
61 #include <QtCore/qmutex.h>
62 #include <QtGui/qapplication.h>
63 #include <QtGui/qgraphicsview.h>
64 #include <QtGui/qgraphicsproxywidget.h>
65 #include <QtGui/qpalette.h>
66 #include <QtGui/qstyleoption.h>
67 
68 #include <qdebug.h>
69 
71 
178 QGraphicsWidget::QGraphicsWidget(QGraphicsItem *parent, Qt::WindowFlags wFlags)
180 {
182  d->init(parent, wFlags);
183 }
184 
194  : QGraphicsObject(dd, 0, scene), QGraphicsLayoutItem(0, false)
195 {
197  d->init(parent, wFlags);
198 }
199 
200 /*
201  \internal
202  \class QGraphicsWidgetStyles
203 
204  We use this thread-safe class to maintain a hash of styles for widgets
205  styles. Note that QApplication::style() itself isn't thread-safe, QStyle
206  isn't thread-safe, and we don't have a thread-safe factory for creating
207  the default style, nor cloning a style.
208 */
210 {
211 public:
213  {
214  QMutexLocker locker(&mutex);
215  return styles.value(widget, 0);
216  }
217 
219  {
220  QMutexLocker locker(&mutex);
221  if (style)
222  styles[widget] = style;
223  else
224  styles.remove(widget);
225  }
226 
227 private:
229  mutable QMutex mutex;
230 };
232 
233 
237 {
238  Q_D(QGraphicsWidget);
239 #ifndef QT_NO_ACTION
240  // Remove all actions from this widget
241  for (int i = 0; i < d->actions.size(); ++i) {
242  QActionPrivate *apriv = d->actions.at(i)->d_func();
243  apriv->graphicsWidgets.removeAll(this);
244  }
245  d->actions.clear();
246 #endif
247 
248  if (QGraphicsScene *scn = scene()) {
249  QGraphicsScenePrivate *sceneD = scn->d_func();
250  if (sceneD->tabFocusFirst == this)
251  sceneD->tabFocusFirst = (d->focusNext == this ? 0 : d->focusNext);
252  }
253  d->focusPrev->d_func()->focusNext = d->focusNext;
254  d->focusNext->d_func()->focusPrev = d->focusPrev;
255 
256  // Play it really safe
257  d->focusNext = this;
258  d->focusPrev = this;
259 
260  clearFocus();
261 
262  //we check if we have a layout previously
263  if (d->layout) {
264  QGraphicsLayout *temp = d->layout;
265  foreach (QGraphicsItem * item, childItems()) {
266  // In case of a custom layout which doesn't remove and delete items, we ensure that
267  // the parent layout item does not point to the deleted layout. This code is here to
268  // avoid regression from 4.4 to 4.5, because according to 4.5 docs it is not really needed.
269  if (item->isWidget()) {
270  QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item);
271  if (widget->parentLayoutItem() == d->layout)
272  widget->setParentLayoutItem(0);
273  }
274  }
275  d->layout = 0;
276  delete temp;
277  }
278 
279  // Remove this graphics widget from widgetStyles
280  widgetStyles()->setStyleForWidget(this, 0);
281 }
282 
310 {
312 }
313 
315 {
316  setGeometry(QRectF(pos(), size));
317 }
318 
366 {
367  QGraphicsWidgetPrivate *wd = QGraphicsWidget::d_func();
369  QRectF newGeom = rect;
370  QPointF oldPos = d->geom.topLeft();
371  if (!wd->inSetPos) {
375 
376  if (newGeom == d->geom) {
377  goto relayoutChildrenAndReturn;
378  }
379 
380  // setPos triggers ItemPositionChange, which can adjust position
381  wd->inSetGeometry = 1;
382  setPos(newGeom.topLeft());
383  wd->inSetGeometry = 0;
384  newGeom.moveTopLeft(pos());
385 
386  if (newGeom == d->geom) {
387  goto relayoutChildrenAndReturn;
388  }
389 
390  // Update and prepare to change the geometry (remove from index) if the size has changed.
391  if (wd->scene) {
392  if (rect.topLeft() == d->geom.topLeft()) {
394  }
395  }
396  }
397 
398  // Update the layout item geometry
399  {
400  bool moved = oldPos != pos();
401  if (moved) {
402  // Send move event.
404  event.setOldPos(oldPos);
405  event.setNewPos(pos());
406  QApplication::sendEvent(this, &event);
407  if (wd->inSetPos) {
408  //set the new pos
409  d->geom.moveTopLeft(pos());
411  goto relayoutChildrenAndReturn;
412  }
413  }
414  QSizeF oldSize = size();
416  // Send resize event
417  bool resized = newGeom.size() != oldSize;
418  if (resized) {
420  re.setOldSize(oldSize);
421  re.setNewSize(newGeom.size());
422  if (oldSize.width() != newGeom.size().width())
423  emit widthChanged();
424  if (oldSize.height() != newGeom.size().height())
426  QApplication::sendEvent(this, &re);
427  }
428  }
429 
431 relayoutChildrenAndReturn:
433  if (QGraphicsLayout *lay = wd->layout) {
434  if (!lay->isActivated()) {
435  QEvent layoutRequest(QEvent::LayoutRequest);
436  QApplication::sendEvent(this, &layoutRequest);
437  }
438  }
439  }
440 }
441 
513 {
515 
516  if (!d->margins && left == 0 && top == 0 && right == 0 && bottom == 0)
517  return;
518  d->ensureMargins();
519  if (left == d->margins[d->Left]
520  && top == d->margins[d->Top]
521  && right == d->margins[d->Right]
522  && bottom == d->margins[d->Bottom])
523  return;
524 
525  d->margins[d->Left] = left;
526  d->margins[d->Top] = top;
527  d->margins[d->Right] = right;
528  d->margins[d->Bottom] = bottom;
529 
530  if (QGraphicsLayout *l = d->layout)
531  l->invalidate();
532  else
533  updateGeometry();
534 
536  QApplication::sendEvent(this, &e);
537 }
538 
547 {
548  Q_D(const QGraphicsWidget);
549  if (left || top || right || bottom)
550  d->ensureMargins();
551  if (left)
552  *left = d->margins[d->Left];
553  if (top)
554  *top = d->margins[d->Top];
555  if (right)
556  *right = d->margins[d->Right];
557  if (bottom)
558  *bottom = d->margins[d->Bottom];
559 }
560 
572 {
574 
575  if (!d->windowFrameMargins && left == 0 && top == 0 && right == 0 && bottom == 0)
576  return;
577  d->ensureWindowFrameMargins();
578  bool unchanged =
579  d->windowFrameMargins[d->Left] == left
580  && d->windowFrameMargins[d->Top] == top
581  && d->windowFrameMargins[d->Right] == right
582  && d->windowFrameMargins[d->Bottom] == bottom;
583  if (d->setWindowFrameMargins && unchanged)
584  return;
585  if (!unchanged)
587  d->windowFrameMargins[d->Left] = left;
588  d->windowFrameMargins[d->Top] = top;
589  d->windowFrameMargins[d->Right] = right;
590  d->windowFrameMargins[d->Bottom] = bottom;
591  d->setWindowFrameMargins = true;
592 }
593 
602 {
603  Q_D(const QGraphicsWidget);
604  if (left || top || right || bottom)
605  d->ensureWindowFrameMargins();
606  if (left)
607  *left = d->windowFrameMargins[d->Left];
608  if (top)
609  *top = d->windowFrameMargins[d->Top];
610  if (right)
611  *right = d->windowFrameMargins[d->Right];
612  if (bottom)
613  *bottom = d->windowFrameMargins[d->Bottom];
614 }
615 
622 {
624  if ((d->windowFlags & Qt::Window) && (d->windowFlags & Qt::WindowType_Mask) != Qt::Popup &&
625  (d->windowFlags & Qt::WindowType_Mask) != Qt::ToolTip && !(d->windowFlags & Qt::FramelessWindowHint)) {
627  d->initStyleOptionTitleBar(&bar);
628  QStyle *style = this->style();
630  qreal titleBarHeight = d->titleBarHeight(bar);
631  setWindowFrameMargins(margin, titleBarHeight, margin, margin);
632  } else {
633  setWindowFrameMargins(0, 0, 0, 0);
634  }
635  d->setWindowFrameMargins = false;
636 }
637 
645 {
646  Q_D(const QGraphicsWidget);
647  return d->windowFrameMargins
648  ? geometry().adjusted(-d->windowFrameMargins[d->Left], -d->windowFrameMargins[d->Top],
649  d->windowFrameMargins[d->Right], d->windowFrameMargins[d->Bottom])
650  : geometry();
651 }
652 
659 {
660  Q_D(const QGraphicsWidget);
661  return d->windowFrameMargins
662  ? rect().adjusted(-d->windowFrameMargins[d->Left], -d->windowFrameMargins[d->Top],
663  d->windowFrameMargins[d->Right], d->windowFrameMargins[d->Bottom])
664  : rect();
665 }
666 
710 {
711  Q_ASSERT(option);
712 
713  option->state = QStyle::State_None;
714  if (isEnabled())
715  option->state |= QStyle::State_Enabled;
716  if (hasFocus())
717  option->state |= QStyle::State_HasFocus;
718  // if (window->testAttribute(Qt::WA_KeyboardFocusChange)) // ### Window
719  // option->state |= QStyle::State_KeyboardFocusChange;
720  if (isUnderMouse())
721  option->state |= QStyle::State_MouseOver;
722  if (QGraphicsWidget *w = window()) {
723  if (w->isActiveWindow())
724  option->state |= QStyle::State_Active;
725  }
726  if (isWindow())
727  option->state |= QStyle::State_Window;
728  /*
729  ###
730 #ifdef Q_WS_MAC
731  extern bool qt_mac_can_clickThrough(const QGraphicsWidget *w); //qwidget_mac.cpp
732  if (!(option->state & QStyle::State_Active) && !qt_mac_can_clickThrough(widget))
733  option->state &= ~QStyle::State_Enabled;
734 
735  switch (QMacStyle::widgetSizePolicy(widget)) {
736  case QMacStyle::SizeSmall:
737  option->state |= QStyle::State_Small;
738  break;
739  case QMacStyle::SizeMini:
740  option->state |= QStyle::State_Mini;
741  break;
742  default:
743  ;
744  }
745 #endif
746 #ifdef QT_KEYPAD_NAVIGATION
747  if (widget->hasEditFocus())
748  state |= QStyle::State_HasEditFocus;
749 #endif
750  */
751  option->direction = layoutDirection();
752  option->rect = rect().toRect(); // ### truncation!
753  option->palette = palette();
754  if (!isEnabled()) {
756  } else if (isActiveWindow()) {
758  } else {
760  }
761  option->fontMetrics = QFontMetrics(font());
762 }
763 
767 QSizeF QGraphicsWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
768 {
769  Q_D(const QGraphicsWidget);
770  QSizeF sh;
771  if (d->layout) {
772  QSizeF marginSize(0,0);
773  if (d->margins) {
774  marginSize = QSizeF(d->margins[d->Left] + d->margins[d->Right],
775  d->margins[d->Top] + d->margins[d->Bottom]);
776  }
777  sh = d->layout->effectiveSizeHint(which, constraint - marginSize);
778  sh += marginSize;
779  } else {
780  switch (which) {
781  case Qt::MinimumSize:
782  sh = QSizeF(0, 0);
783  break;
784  case Qt::PreferredSize:
785  sh = QSizeF(50, 50); //rather arbitrary
786  break;
787  case Qt::MaximumSize:
789  break;
790  default:
791  qWarning("QGraphicsWidget::sizeHint(): Don't know how to handle the value of 'which'");
792  break;
793  }
794  }
795  return sh;
796 }
797 
835 {
836  Q_D(const QGraphicsWidget);
837  return d->layout;
838 }
839 
860 {
862  if (d->layout == l)
863  return;
864  d->setLayout_helper(l);
865  if (!l)
866  return;
867 
868  // Prevent assigning a layout that is already assigned to another widget.
869  QGraphicsLayoutItem *oldParent = l->parentLayoutItem();
870  if (oldParent && oldParent != this) {
871  qWarning("QGraphicsWidget::setLayout: Attempting to set a layout on %s"
872  " \"%s\", when the layout already has a parent",
874  return;
875  }
876 
877  // Install and activate the layout.
878  l->setParentLayoutItem(this);
879  l->d_func()->reparentChildItems(this);
880  l->invalidate();
882 }
883 
893 {
895  // What if sz is not valid?!
896  if (sz.isValid())
897  resize(sz);
898 }
899 
930 {
932 }
934 {
937  d->setLayoutDirection_helper(direction);
938 }
940 {
943  d->resolveLayoutDirection();
944 }
945 
955 {
956  if (QStyle *style = widgetStyles()->styleForWidget(this))
957  return style;
958  // ### This is not thread-safe. QApplication::style() is not thread-safe.
959  return scene() ? scene()->style() : QApplication::style();
960 }
961 
976 {
977  setAttribute(Qt::WA_SetStyle, style != 0);
978  widgetStyles()->setStyleForWidget(this, style);
979 
980  // Deliver StyleChange to the widget itself (doesn't propagate).
982  QApplication::sendEvent(this, &event);
983 }
984 
1011 {
1012  Q_D(const QGraphicsWidget);
1013  QFont fnt = d->font;
1014  fnt.resolve(fnt.resolve() | d->inheritedFontResolveMask);
1015  return fnt;
1016 }
1018 {
1020  setAttribute(Qt::WA_SetFont, font.resolve() != 0);
1021 
1022  QFont naturalFont = d->naturalWidgetFont();
1023  QFont resolvedFont = font.resolve(naturalFont);
1024  d->setFont_helper(resolvedFont);
1025 }
1026 
1056 {
1057  Q_D(const QGraphicsWidget);
1058  return d->palette;
1059 }
1061 {
1063  setAttribute(Qt::WA_SetPalette, palette.resolve() != 0);
1064 
1065  QPalette naturalPalette = d->naturalWidgetPalette();
1066  QPalette resolvedPalette = palette.resolve(naturalPalette);
1067  d->setPalette_helper(resolvedPalette);
1068 }
1069 
1090 {
1091  Q_D(const QGraphicsWidget);
1092  return d->autoFillBackground;
1093 }
1095 {
1097  if (d->autoFillBackground != enabled) {
1098  d->autoFillBackground = enabled;
1099  update();
1100  }
1101 }
1102 
1113 {
1116 
1117  if (parentItem && parentItem->isLayout()) {
1119  static_cast<QGraphicsLayout *>(parentItem)->invalidate();
1120  } else {
1121  parentItem->updateGeometry();
1122  }
1123  } else {
1124  if (parentItem) {
1125  // This is for custom layouting
1126  QGraphicsWidget *parentWid = parentWidget(); //###
1127  if (parentWid->isVisible())
1129  } else {
1137  ++d->refCountInvokeRelayout;
1138  QMetaObject::invokeMethod(this, "_q_relayout", Qt::QueuedConnection);
1139  }
1140  }
1142  bool wasResized = testAttribute(Qt::WA_Resized);
1143  resize(size()); // this will restrict the size
1144  setAttribute(Qt::WA_Resized, wasResized);
1145  }
1146  }
1147 }
1148 
1172 {
1174  switch (change) {
1175  case ItemEnabledHasChanged: {
1176  // Send EnabledChange after the enabled state has changed.
1178  QApplication::sendEvent(this, &event);
1179  break;
1180  }
1181  case ItemVisibleChange:
1182  if (value.toBool()) {
1183  // Send Show event before the item has been shown.
1184  QShowEvent event;
1185  QApplication::sendEvent(this, &event);
1186  bool resized = testAttribute(Qt::WA_Resized);
1187  if (!resized) {
1188  adjustSize();
1189  setAttribute(Qt::WA_Resized, false);
1190  }
1191  }
1192  break;
1193  case ItemVisibleHasChanged:
1194  if (!value.toBool()) {
1195  // Send Hide event after the item has been hidden.
1196  QHideEvent event;
1197  QApplication::sendEvent(this, &event);
1198  }
1199  break;
1201  d->setGeometryFromSetPos();
1202  break;
1203  case ItemParentChange: {
1204  // Deliver ParentAboutToChange.
1206  QApplication::sendEvent(this, &event);
1207  break;
1208  }
1209  case ItemParentHasChanged: {
1210  // Deliver ParentChange.
1212  QApplication::sendEvent(this, &event);
1213  break;
1214  }
1215  case ItemCursorHasChanged: {
1216  // Deliver CursorChange.
1218  QApplication::sendEvent(this, &event);
1219  break;
1220  }
1221  case ItemToolTipHasChanged: {
1222  // Deliver ToolTipChange.
1224  QApplication::sendEvent(this, &event);
1225  break;
1226  }
1227  case ItemChildAddedChange: {
1228  QGraphicsItem *child = qVariantValue<QGraphicsItem *>(value);
1229  if (child->isWidget())
1230  static_cast<QGraphicsWidget *>(child)->d_func()->resolveLayoutDirection();
1231  break;
1232  }
1233  default:
1234  break;
1235  }
1236  return QGraphicsItem::itemChange(change, value);
1237 }
1238 
1259 QVariant QGraphicsWidget::propertyChange(const QString &propertyName, const QVariant &value)
1260 {
1261  Q_UNUSED(propertyName);
1262  return value;
1263 }
1264 
1274 {
1275  return QGraphicsItem::sceneEvent(event);
1276 }
1277 
1292 {
1294  switch (event->type()) {
1296  d->windowFrameMousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
1297  break;
1299  d->ensureWindowData();
1300  if (d->windowData->grabbedSection != Qt::NoSection) {
1301  d->windowFrameMouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
1302  event->accept();
1303  }
1304  break;
1306  d->windowFrameMouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
1307  break;
1309  d->windowFrameHoverMoveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
1310  break;
1312  d->windowFrameHoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
1313  break;
1314  default:
1315  break;
1316  }
1317  return event->isAccepted();
1318 }
1319 
1342 {
1343  Q_D(const QGraphicsWidget);
1344 
1345  const QRectF r = windowFrameRect();
1346  if (!r.contains(pos))
1347  return Qt::NoSection;
1348 
1349  const qreal left = r.left();
1350  const qreal top = r.top();
1351  const qreal right = r.right();
1352  const qreal bottom = r.bottom();
1353  const qreal x = pos.x();
1354  const qreal y = pos.y();
1355 
1356  const qreal cornerMargin = 20;
1357  //### Not sure of this one, it should be the same value for all edges.
1358  const qreal windowFrameWidth = d->windowFrameMargins
1359  ? d->windowFrameMargins[d->Left] : 0;
1360 
1362  if (x <= left + cornerMargin) {
1363  if (y <= top + windowFrameWidth || (x <= left + windowFrameWidth && y <= top + cornerMargin)) {
1364  s = Qt::TopLeftSection;
1365  } else if (y >= bottom - windowFrameWidth || (x <= left + windowFrameWidth && y >= bottom - windowFrameWidth)) {
1367  } else if (x <= left + windowFrameWidth) {
1368  s = Qt::LeftSection;
1369  }
1370  } else if (x >= right - cornerMargin) {
1371  if (y <= top + windowFrameWidth || (x >= right - windowFrameWidth && y <= top + cornerMargin)) {
1372  s = Qt::TopRightSection;
1373  } else if (y >= bottom - windowFrameWidth || (x >= right - windowFrameWidth && y >= bottom - windowFrameWidth)) {
1375  } else if (x >= right - windowFrameWidth) {
1376  s = Qt::RightSection;
1377  }
1378  } else if (y <= top + windowFrameWidth) {
1379  s = Qt::TopSection;
1380  } else if (y >= bottom - windowFrameWidth) {
1381  s = Qt::BottomSection;
1382  }
1383  if (s == Qt::NoSection) {
1384  QRectF r1 = r;
1385  r1.setHeight(d->windowFrameMargins
1386  ? d->windowFrameMargins[d->Top] : 0);
1387  if (r1.contains(pos))
1388  s = Qt::TitleBarArea;
1389  }
1390  return s;
1391 }
1392 
1433 {
1435  // Forward the event to the layout first.
1436  if (d->layout)
1437  d->layout->widgetEvent(event);
1438 
1439  // Handle the event itself.
1440  switch (event->type()) {
1442  moveEvent(static_cast<QGraphicsSceneMoveEvent *>(event));
1443  break;
1445  resizeEvent(static_cast<QGraphicsSceneResizeEvent *>(event));
1446  break;
1447  case QEvent::Show:
1448  showEvent(static_cast<QShowEvent *>(event));
1449  break;
1450  case QEvent::Hide:
1451  hideEvent(static_cast<QHideEvent *>(event));
1452  break;
1453  case QEvent::Polish:
1454  polishEvent();
1455  d->polished = true;
1456  if (!d->font.isCopyOf(QApplication::font()))
1457  d->updateFont(d->font);
1458  break;
1461  update();
1462  break;
1463  // Taken from QWidget::event
1465  case QEvent::EnabledChange:
1466  case QEvent::FontChange:
1467  case QEvent::StyleChange:
1468  case QEvent::PaletteChange:
1469  case QEvent::ParentChange:
1472  changeEvent(event);
1473  break;
1474  case QEvent::Close:
1475  closeEvent((QCloseEvent *)event);
1476  break;
1477  case QEvent::GrabMouse:
1478  grabMouseEvent(event);
1479  break;
1480  case QEvent::UngrabMouse:
1481  ungrabMouseEvent(event);
1482  break;
1483  case QEvent::GrabKeyboard:
1484  grabKeyboardEvent(event);
1485  break;
1487  ungrabKeyboardEvent(event);
1488  break;
1490  if (d->hasDecoration() && windowFrameEvent(event))
1491  return true;
1495  d->ensureWindowData();
1496  if (d->hasDecoration() && d->windowData->grabbedSection != Qt::NoSection)
1497  return windowFrameEvent(event);
1498  break;
1502  if (d->hasDecoration()) {
1503  windowFrameEvent(event);
1504  // Filter out hover events if they were sent to us only because of the
1505  // decoration (special case in QGraphicsScenePrivate::dispatchHoverEvent).
1506  if (!acceptsHoverEvents())
1507  return true;
1508  }
1509  break;
1510  default:
1511  break;
1512  }
1513  return QObject::event(event);
1514 }
1515 
1527 {
1529  switch (event->type()) {
1530  case QEvent::StyleChange:
1531  // ### Don't unset if the margins are explicitly set.
1533  if (d->layout)
1534  d->layout->invalidate();
1535  case QEvent::FontChange:
1536  update();
1537  updateGeometry();
1538  break;
1539  case QEvent::PaletteChange:
1540  update();
1541  break;
1542  case QEvent::ParentChange:
1543  d->resolveFont(d->inheritedFontResolveMask);
1544  d->resolvePalette(d->inheritedPaletteResolveMask);
1545  break;
1546  default:
1547  break;
1548  }
1549 }
1550 
1559 {
1560  event->accept();
1561 }
1562 
1567 {
1568  Q_UNUSED(event);
1569  if (focusPolicy() != Qt::NoFocus)
1570  update();
1571 }
1572 
1593 {
1595  // Let the parent's focusNextPrevChild implementation decide what to do.
1596  QGraphicsWidget *parent = 0;
1597  if (!isWindow() && (parent = parentWidget()))
1598  return parent->focusNextPrevChild(next);
1599  if (!d->scene)
1600  return false;
1601  if (d->scene->focusNextPrevChild(next))
1602  return true;
1603  if (isWindow()) {
1605  if (hasFocus())
1606  return true;
1607  }
1608  return false;
1609 }
1610 
1615 {
1616  Q_UNUSED(event);
1617  if (focusPolicy() != Qt::NoFocus)
1618  update();
1619 }
1620 
1634 {
1636  // is hidden.
1637  Q_UNUSED(event);
1638 }
1639 
1656 {
1657  // ### Last position is always == current position
1658  Q_UNUSED(event);
1659 }
1660 
1670 {
1671 }
1672 
1690 {
1691  Q_UNUSED(event);
1692 }
1693 
1707 {
1708  Q_UNUSED(event);
1709 }
1710 
1715 {
1716  Q_UNUSED(event);
1717 }
1718 
1723 {
1724  Q_UNUSED(event);
1725 }
1726 
1734 {
1735  Q_UNUSED(event);
1736 }
1737 
1745 {
1746  Q_UNUSED(event);
1747 }
1748 
1756 {
1757  Q_UNUSED(event);
1758 }
1759 
1767 {
1768  Q_UNUSED(event);
1769 }
1770 
1777 {
1779 }
1780 
1801 Qt::WindowFlags QGraphicsWidget::windowFlags() const
1802 {
1803  Q_D(const QGraphicsWidget);
1804  return d->windowFlags;
1805 }
1806 void QGraphicsWidget::setWindowFlags(Qt::WindowFlags wFlags)
1807 {
1809  if (d->windowFlags == wFlags)
1810  return;
1811  bool wasPopup = (d->windowFlags & Qt::WindowType_Mask) == Qt::Popup;
1812 
1813  d->adjustWindowFlags(&wFlags);
1814  d->windowFlags = wFlags;
1815  if (!d->setWindowFrameMargins)
1817 
1818  setFlag(ItemIsPanel, d->windowFlags & Qt::Window);
1819 
1820  bool isPopup = (d->windowFlags & Qt::WindowType_Mask) == Qt::Popup;
1821  if (d->scene && isVisible() && wasPopup != isPopup) {
1822  // Popup state changed; update implicit mouse grab.
1823  if (!isPopup)
1824  d->scene->d_func()->removePopup(this);
1825  else
1826  d->scene->d_func()->addPopup(this);
1827  }
1828 
1829  if (d->scene && d->scene->d_func()->allItemsIgnoreHoverEvents && d->hasDecoration()) {
1830  d->scene->d_func()->allItemsIgnoreHoverEvents = false;
1831  d->scene->d_func()->enableMouseTrackingOnViews();
1832  }
1833 }
1834 
1846 {
1847  return isActive();
1848 }
1849 
1863 {
1865  d->ensureWindowData();
1866  d->windowData->windowTitle = title;
1867 }
1869 {
1870  Q_D(const QGraphicsWidget);
1871  return d->windowData ? d->windowData->windowTitle : QString();
1872 }
1873 
1898 {
1899  Q_D(const QGraphicsWidget);
1900  return d->focusPolicy;
1901 }
1903 {
1905  if (d->focusPolicy == policy)
1906  return;
1907  d->focusPolicy = policy;
1908  if (hasFocus() && policy == Qt::NoFocus)
1909  clearFocus();
1910  setFlag(ItemIsFocusable, policy != Qt::NoFocus);
1911 }
1912 
1921 {
1922  Q_D(const QGraphicsWidget);
1923  if (d->subFocusItem && d->subFocusItem->d_ptr->isWidget)
1924  return static_cast<QGraphicsWidget *>(d->subFocusItem);
1925  return 0;
1926 }
1927 
1928 #ifndef QT_NO_SHORTCUT
1929 
1960 {
1961  Q_ASSERT(qApp);
1962  if (sequence.isEmpty())
1963  return 0;
1964  // ### setAttribute(Qt::WA_GrabbedShortcut);
1965  return qApp->d_func()->shortcutMap.addShortcut(this, sequence, context);
1966 }
1967 
1989 {
1990  Q_ASSERT(qApp);
1991  if (id)
1992  qApp->d_func()->shortcutMap.removeShortcut(id, this, 0);
1993 }
1994 
2013 {
2014  Q_ASSERT(qApp);
2015  if (id)
2016  qApp->d_func()->shortcutMap.setShortcutEnabled(enabled, id, this, 0);
2017 }
2018 
2031 {
2032  Q_ASSERT(qApp);
2033  if (id)
2034  qApp->d_func()->shortcutMap.setShortcutAutoRepeat(enabled, id, this, 0);
2035 }
2036 #endif
2037 
2038 #ifndef QT_NO_ACTION
2039 
2057 {
2058  insertAction(0, action);
2059 }
2060 
2072 {
2073  for (int i = 0; i < actions.count(); ++i)
2074  insertAction(0, actions.at(i));
2075 }
2076 
2093 {
2094  if (!action) {
2095  qWarning("QWidget::insertAction: Attempt to insert null action");
2096  return;
2097  }
2098 
2100  int index = d->actions.indexOf(action);
2101  if (index != -1)
2102  d->actions.removeAt(index);
2103 
2104  int pos = d->actions.indexOf(before);
2105  if (pos < 0) {
2106  before = 0;
2107  pos = d->actions.size();
2108  }
2109  d->actions.insert(pos, action);
2110 
2111  if (index == -1) {
2112  QActionPrivate *apriv = action->d_func();
2113  apriv->graphicsWidgets.append(this);
2114  }
2115 
2116  QActionEvent e(QEvent::ActionAdded, action, before);
2117  QApplication::sendEvent(this, &e);
2118 }
2119 
2135 {
2136  for (int i = 0; i < actions.count(); ++i)
2137  insertAction(before, actions.at(i));
2138 }
2139 
2151 {
2152  if (!action)
2153  return;
2154 
2156 
2157  QActionPrivate *apriv = action->d_func();
2158  apriv->graphicsWidgets.removeAll(this);
2159 
2160  if (d->actions.removeAll(action)) {
2162  QApplication::sendEvent(this, &e);
2163  }
2164 }
2165 
2178 {
2179  Q_D(const QGraphicsWidget);
2180  return d->actions;
2181 }
2182 #endif
2183 
2209 {
2210  if (!first && !second) {
2211  qWarning("QGraphicsWidget::setTabOrder(0, 0) is undefined");
2212  return;
2213  }
2214  if ((first && second) && first->scene() != second->scene()) {
2215  qWarning("QGraphicsWidget::setTabOrder: scenes %p and %p are different",
2216  first->scene(), second->scene());
2217  return;
2218  }
2219  QGraphicsScene *scene = first ? first->scene() : second->scene();
2220  if (!scene && (!first || !second)) {
2221  qWarning("QGraphicsWidget::setTabOrder: assigning tab order from/to the"
2222  " scene requires the item to be in a scene.");
2223  return;
2224  }
2225 
2226  // If either first or second are 0, the scene's tabFocusFirst is updated
2227  // to point to the first item in the scene's focus chain. Then first or
2228  // second are set to point to tabFocusFirst.
2229  QGraphicsScenePrivate *sceneD = scene->d_func();
2230  if (!first) {
2231  sceneD->tabFocusFirst = second;
2232  return;
2233  }
2234  if (!second) {
2235  sceneD->tabFocusFirst = first->d_func()->focusNext;
2236  return;
2237  }
2238 
2239  // Both first and second are != 0.
2240  QGraphicsWidget *firstFocusNext = first->d_func()->focusNext;
2241  if (firstFocusNext == second) {
2242  // Nothing to do.
2243  return;
2244  }
2245 
2246  // Update the focus chain.
2247  QGraphicsWidget *secondFocusPrev = second->d_func()->focusPrev;
2248  QGraphicsWidget *secondFocusNext = second->d_func()->focusNext;
2249  firstFocusNext->d_func()->focusPrev = second;
2250  first->d_func()->focusNext = second;
2251  second->d_func()->focusNext = firstFocusNext;
2252  second->d_func()->focusPrev = first;
2253  secondFocusPrev->d_func()->focusNext = secondFocusNext;
2254  secondFocusNext->d_func()->focusPrev = secondFocusPrev;
2255 
2256  Q_ASSERT(first->d_func()->focusNext->d_func()->focusPrev == first);
2257  Q_ASSERT(first->d_func()->focusPrev->d_func()->focusNext == first);
2258 
2259  Q_ASSERT(second->d_func()->focusNext->d_func()->focusPrev == second);
2260  Q_ASSERT(second->d_func()->focusPrev->d_func()->focusNext == second);
2261 
2262 }
2263 
2274 {
2276  // ### most flags require some immediate action
2277  // ### we might want to qWarn use of unsupported attributes
2278  // ### we might want to not use Qt::WidgetAttribute, but roll our own instead
2279  d->setAttribute(attribute, on);
2280 }
2281 
2289 {
2290  Q_D(const QGraphicsWidget);
2291  return d->testAttribute(attribute);
2292 }
2293 
2298 {
2299  return Type;
2300 }
2301 
2306 {
2307  Q_UNUSED(painter);
2308  Q_UNUSED(option);
2309  Q_UNUSED(widget);
2310 }
2311 
2324  QWidget *widget)
2325 {
2329  const bool embeddedWidgetFillsOwnBackground = proxy && proxy->widget();
2330 
2331  if (rect().contains(option->exposedRect)) {
2332  if (fillBackground && !embeddedWidgetFillsOwnBackground)
2333  painter->fillRect(option->exposedRect, palette().window());
2334  return;
2335  }
2336 
2338 
2341  bar.QStyleOption::operator=(*option);
2342  d->initStyleOptionTitleBar(&bar); // this clear flags in bar.state
2343  d->ensureWindowData();
2344  if (d->windowData->buttonMouseOver)
2346  else
2347  bar.state &= ~QStyle::State_MouseOver;
2348  if (d->windowData->buttonSunken)
2349  bar.state |= QStyle::State_Sunken;
2350  else
2351  bar.state &= ~QStyle::State_Sunken;
2352 
2353  bar.rect = windowFrameRect;
2354 
2355  // translate painter to make the style happy
2356  const QPointF styleOrigin = this->windowFrameRect().topLeft();
2357  painter->translate(styleOrigin);
2358 
2359 #ifdef Q_WS_MAC
2360  const QSize pixmapSize = windowFrameRect.size();
2361  if (pixmapSize.width() <= 0 || pixmapSize.height() <= 0)
2362  return;
2363  QPainter *realPainter = painter;
2364  QPixmap pm(pixmapSize);
2365  painter = new QPainter(&pm);
2366 #endif
2367 
2368  // Fill background
2369  QStyleHintReturnMask mask;
2370  bool setMask = style()->styleHint(QStyle::SH_WindowFrame_Mask, &bar, widget, &mask) && !mask.region.isEmpty();
2371  bool hasBorder = !style()->styleHint(QStyle::SH_TitleBar_NoBorder, &bar, widget);
2372  int frameWidth = style()->pixelMetric(QStyle::PM_MDIFrameWidth, &bar, widget);
2373  if (setMask) {
2374  painter->save();
2375  painter->setClipRegion(mask.region, Qt::IntersectClip);
2376  }
2377  if (fillBackground) {
2378  if (embeddedWidgetFillsOwnBackground) {
2379  // Don't fill the background twice.
2380  QPainterPath windowFrameBackground;
2381  windowFrameBackground.addRect(windowFrameRect);
2382  // Adjust with 0.5 to avoid border artifacts between
2383  // widget background and frame background.
2384  windowFrameBackground.addRect(rect().translated(-styleOrigin).adjusted(0.5, 0.5, -0.5, -0.5));
2385  painter->fillPath(windowFrameBackground, palette().window());
2386  } else {
2387  painter->fillRect(windowFrameRect, palette().window());
2388  }
2389  }
2391 
2392  // Draw title
2393  int height = (int)d->titleBarHeight(bar);
2394  bar.rect.setHeight(height);
2395  if (hasBorder) // Frame is painted by PE_FrameWindow
2396  bar.rect.adjust(frameWidth, frameWidth, -frameWidth, 0);
2397 
2398  painter->save();
2399  painter->setFont(QApplication::font("QWorkspaceTitleBar"));
2400  style()->drawComplexControl(QStyle::CC_TitleBar, &bar, painter, widget);
2401  painter->restore();
2402  if (setMask)
2403  painter->restore();
2404  // Draw window frame
2405  QStyleOptionFrame frameOptions;
2406  frameOptions.QStyleOption::operator=(*option);
2407  initStyleOption(&frameOptions);
2408  if (!hasBorder)
2409  painter->setClipRect(windowFrameRect.adjusted(0, +height, 0, 0), Qt::IntersectClip);
2410  if (hasFocus()) {
2411  frameOptions.state |= QStyle::State_HasFocus;
2412  } else {
2413  frameOptions.state &= ~QStyle::State_HasFocus;
2414  }
2415  bool isActive = isActiveWindow();
2416  if (isActive) {
2417  frameOptions.state |= QStyle::State_Active;
2418  } else {
2419  frameOptions.state &= ~QStyle::State_Active;
2420  }
2421 
2423  frameOptions.rect = windowFrameRect;
2424  frameOptions.lineWidth = style()->pixelMetric(QStyle::PM_MdiSubWindowFrameWidth, 0, widget);
2425  frameOptions.midLineWidth = 1;
2426  style()->drawPrimitive(QStyle::PE_FrameWindow, &frameOptions, painter, widget);
2427 
2428 #ifdef Q_WS_MAC
2429  realPainter->drawPixmap(QPoint(), pm);
2430  delete painter;
2431 #endif
2432 }
2433 
2438 {
2439  return windowFrameRect();
2440 }
2441 
2446 {
2447  QPainterPath path;
2448  path.addRect(rect());
2449  return path;
2450 }
2451 
2464 {
2466  QApplication::sendEvent(this, &closeEvent);
2467  if (!closeEvent.isAccepted()) {
2468  return false;
2469  }
2470  // hide
2471  if (isVisible()) {
2472  hide();
2473  }
2475  deleteLater();
2476  }
2477  return true;
2478 }
2479 
2480 #ifdef Q_NO_USING_KEYWORD
2481 
2493 #endif
2494 
2495 #if 0
2496 void QGraphicsWidget::dumpFocusChain()
2497 {
2498  qDebug() << "=========== Dumping focus chain ==============";
2499  int i = 0;
2500  QGraphicsWidget *next = this;
2501  QSet<QGraphicsWidget*> visited;
2502  do {
2503  if (!next) {
2504  qWarning("Found a focus chain that is not circular, (next == 0)");
2505  break;
2506  }
2507  qDebug() << i++ << QString::number(uint(next), 16) << next->className() << next->data(0) << QString::fromAscii("focusItem:%1").arg(next->hasFocus() ? '1' : '0') << QLatin1String("next:") << next->d_func()->focusNext->data(0) << QLatin1String("prev:") << next->d_func()->focusPrev->data(0);
2508  if (visited.contains(next)) {
2509  qWarning("Already visited this node. However, I expected to dump until I found myself.");
2510  break;
2511  }
2512  visited << next;
2513  next = next->d_func()->focusNext;
2514  } while (next != this);
2515 }
2516 #endif
2517 
2519 
2520 #endif //QT_NO_GRAPHICSVIEW
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QStyle * styleForWidget(const QGraphicsWidget *widget) const
double d
Definition: qnumeric_p.h:62
QGraphicsWidget * focusWidget() const
If this widget, a child or descendant of this widget currently has input focus, this function will re...
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Returns the effective size hint for this QGraphicsLayoutItem.
int type() const
Reimplemented Function
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
virtual void setGeometry(const QRectF &rect)
This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordi...
virtual void ungrabMouseEvent(QEvent *event)
This event handler, for event, can be reimplemented in a subclass to receive notifications for QEvent...
bool hasFocus() const
Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise...
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
virtual bool sceneEvent(QEvent *event)
This virtual function receives events to this item.
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
QString windowTitle() const
void setNewSize(const QSizeF &size)
double qreal
Definition: qglobal.h:1193
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Reimplemented Function
void setHeight(qreal h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:787
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
QGraphicsWidget * parentWidget() const
Returns a pointer to the item&#39;s parent widget.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
bool isWindow() const
Returns true if the item is a QGraphicsWidget window, otherwise returns false.
QScopedPointer< QGraphicsLayoutItemPrivate > d_ptr
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
QList< QGraphicsItem * > childItems() const
Returns a list of this item&#39;s children.
void setWindowTitle(const QString &title)
void setStyle(QStyle *style)
Sets the widget&#39;s style to style.
bool isPopup
Use windowType() == Qt::Popup instead.
void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
Gets the widget&#39;s contents margins.
T * data() const
Returns the value of the pointer referenced by this object.
virtual void polishEvent()
This event is delivered to the item by the scene at some point after it has been constructed, but before it is shown or otherwise accessed through the scene.
QMap< const QGraphicsWidget *, QStyle * > styles
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
void heightChanged()
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QList< QAction * > actions() const
Returns the (possibly empty) list of this widget&#39;s actions.
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...
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
qreal width() const
Returns the width.
Definition: qsize.h:284
void clearFocus()
Takes keyboard input focus from the item.
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
qreal height() const
Returns the height.
Definition: qsize.h:287
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
This virtual function is called by QGraphicsItem to notify custom items that some part of the item&#39;s ...
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
void setLayoutDirection(Qt::LayoutDirection direction)
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
virtual void initStyleOption(QStyleOption *option) const
Populates a style option object for this widget based on its current state, and stores the output in ...
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QGraphicsScene * scene
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...
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
void releaseShortcut(int id)
Removes the shortcut with the given id from Qt&#39;s shortcut system.
The QGraphicsSceneResizeEvent class provides events for widget resizing in the graphics view framewor...
QPointF pos() const
Returns the position of the item in parent coordinates.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
void setParentLayoutItem(QGraphicsLayoutItem *parent)
Sets the parent of this QGraphicsLayoutItem to parent.
static QStyle * style()
Returns the application&#39;s style object.
The QActionEvent class provides an event that is generated when a QAction is added, removed, or changed.
Definition: qevent.h:632
void setOldSize(const QSizeF &size)
bool sceneEvent(QEvent *event)
QGraphicsWidget&#39;s implementation of sceneEvent() simply passes event to QGraphicsWidget::event().
QGraphicsLayout * layout
void removeAction(QAction *action)
Removes the action action from this widget&#39;s list of actions.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
The QGraphicsSceneMoveEvent class provides events for widget moving in the graphics view framework...
T * qobject_cast(QObject *object)
Definition: qobject.h:375
bool isValid() const
Returns true if both the width and height is equal to or greater than 0; otherwise returns false...
Definition: qsize.h:281
bool isEnabled() const
Returns true if the item is enabled; otherwise, false is returned.
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
QRectF rect() const
Returns the item&#39;s local rect as a QRectF.
WindowType
Definition: qnamespace.h:270
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void setPos(const QPointF &pos)
Sets the position of the item to pos, which is in parent coordinates.
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
#define Q_D(Class)
Definition: qglobal.h:2482
void focusOutEvent(QFocusEvent *event)
Reimplemented Function
virtual bool windowFrameEvent(QEvent *e)
This event handler, for event, receives events for the window frame if this widget is a window...
WidgetAttribute
Definition: qnamespace.h:376
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
Qt::WindowType windowType() const
Returns the widgets window type.
void geometryChanged()
This signal gets emitted whenever the geometry is changed in setGeometry().
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
virtual void closeEvent(QCloseEvent *event)
This event handler, for event, can be reimplemented in a subclass to receive widget close events...
QPainterPath shape() const
Reimplemented Function
const char * className
Definition: qwizard.cpp:137
void getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
Gets the widget&#39;s window frame margins.
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
virtual void invalidate()
Clears any cached geometry and size hint information in the layout, and posts a LayoutRequest event t...
bool close()
Call this function to close the widget.
static QFont font()
Returns the default application font.
virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
This virtual function is called by QGraphicsScene to draw the window frame for windows using painter...
Q_CORE_EXPORT void qDebug(const char *,...)
bool contains(const QPointF &p) const
Returns true if the given point is inside or on the edge of the rectangle; otherwise returns false...
Definition: qrect.cpp:2349
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; returns false otherwise.
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
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
int lineWidth
the line width for drawing the frame
Definition: qstyleoption.h:124
int width() const
Returns the width.
Definition: qsize.h:126
QRectF geometry() const
Returns the item&#39;s geometry (e.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented Function
QPalette palette() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
Sets the widget&#39;s contents margins to left, top, right and bottom.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isAccepted() const
Definition: qcoreevent.h:307
virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF &pos) const
Returns the window frame section at position pos, or Qt::NoSection if there is no window frame sectio...
void setShortcutEnabled(int id, bool enabled=true)
If enabled is true, the shortcut with the given id is enabled; otherwise the shortcut is disabled...
bool isUnderMouse() const
Returns true if this item is currently under the mouse cursor in one of the views; otherwise...
void fillPath(const QPainterPath &path, const QBrush &brush)
Fills the given path using the given brush.
Definition: qpainter.cpp:3456
void setFont(const QFont &font)
bool contains(const T &value) const
Definition: qset.h:91
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
QGraphicsWidget(QGraphicsItem *parent=0, Qt::WindowFlags wFlags=0)
Constructs a QGraphicsWidget instance.
QStyle * style() const
Returns the scene&#39;s style, or the same as QApplication::style() if the scene has not been explicitly ...
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
QVariant data(int key) const
Returns this item&#39;s custom data for the key key as a QVariant.
#define qApp
void unsetWindowFrameMargins()
Resets the window frame margins to the default value, provided by the style.
void setGeometry(const QRectF &rect)
This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordi...
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
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
void focusInEvent(QFocusEvent *event)
Reimplemented Function
#define emit
Definition: qobjectdefs.h:76
QList< QGraphicsWidget * > graphicsWidgets
Definition: qaction_p.h:123
QRectF boundingRect() const
Reimplemented Function
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
QSizeF size() const
LayoutDirection
Definition: qnamespace.h:1580
void setLayout(QGraphicsLayout *layout)
Sets the layout for this widget to layout.
virtual void resizeEvent(QGraphicsSceneResizeEvent *event)
This event handler, for GraphicsSceneResize events, is delivered after the widget has been resized (i...
virtual void changeEvent(QEvent *event)
This event handler can be reimplemented to handle state changes.
virtual void grabKeyboardEvent(QEvent *event)
This event handler, for event, can be reimplemented in a subclass to receive notifications for QEvent...
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
QGraphicsWidget uses the base implementation of this function to catch and deliver events related to ...
void moveTopLeft(const QPointF &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:697
virtual void updateGeometry()
This virtual function discards any cached size hint information.
Q_CORE_EXPORT void qWarning(const char *,...)
The QStyleOptionFrame class is used to describe the parameters for drawing a frame.
Definition: qstyleoption.h:118
unsigned int uint
Definition: qglobal.h:996
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
bool isActive() const
Returns true if this item is active; otherwise returns false.
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
QFont font() const
virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget=0) const =0
Draws the given control using the provided painter with the style options specified by option...
static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, const QPointF &origin, QRectF gradientRect=QRectF())
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
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
static bool instantInvalidatePropagation()
bool isEmpty() const
Returns true if the key sequence is empty; otherwise returns false.
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
void setSize(const QSizeF &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:790
virtual void moveEvent(QGraphicsSceneMoveEvent *event)
This event handler, for GraphicsSceneMove events, is delivered after the widget has moved (e...
void setAttribute(Qt::WidgetAttribute attribute, bool on=true)
If on is true, this function enables attribute; otherwise attribute is disabled.
The QGraphicsProxyWidget class provides a proxy layer for embedding a QWidget in a QGraphicsScene...
void setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom)
Sets the widget&#39;s window frame margins to left, top, right and bottom.
bool testAttribute(Qt::WidgetAttribute attribute) const
Returns true if attribute is enabled for this widget; otherwise, returns false.
bool isLayout() const
Returns true if this QGraphicsLayoutItem is a layout (e.g., is inherited by an object that arranges o...
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
QGraphicsWidget * tabFocusFirst
SizeHint
Definition: qnamespace.h:1708
The QStyleHintReturnMask class provides style hints that return a QRegion.
Definition: qstyleoption.h:923
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
Reimplemented Function
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
virtual void grabMouseEvent(QEvent *event)
This event handler, for event, can be reimplemented in a subclass to receive notifications for QEvent...
QRectF windowFrameGeometry() const
Returns the widget&#39;s geometry in parent coordinates including any window frame.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
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
qreal y() const
This convenience function is equivalent to calling pos().
void setAutoFillBackground(bool enabled)
Qt::FocusPolicy focusPolicy() const
bool event(QEvent *event)
Handles the event.
void prepareGeometryChange()
Prepares the item for a geometry change.
void addActions(QList< QAction *> actions)
Appends the actions actions to this widget&#39;s list of actions.
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QSizeF boundedTo(const QSizeF &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:350
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Reimplemented Function
virtual void ungrabKeyboardEvent(QEvent *event)
This event handler, for event, can be reimplemented in a subclass to receive notifications for QEvent...
QSizeF expandedTo(const QSizeF &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:345
QGraphicsLayoutItem * parentLayoutItem() const
Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, or if the parent does not...
int midLineWidth
the mid-line width for drawing the frame
Definition: qstyleoption.h:125
void insertAction(QAction *before, QAction *action)
Inserts the action action to this widget&#39;s list of actions, before the action before.
void insertActions(QAction *before, QList< QAction *> actions)
Inserts the actions actions to this widget&#39;s list of actions, before the action before.
bool isActiveWindow() const
Returns true if this widget&#39;s window is in the active window, or if the widget does not have a window...
int grabShortcut(const QKeySequence &sequence, 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...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
qreal x() const
This convenience function is equivalent to calling pos().
void setWindowFlags(Qt::WindowFlags wFlags)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void hide()
Hides the item.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
FocusPolicy
Definition: qnamespace.h:181
virtual QVariant propertyChange(const QString &propertyName, const QVariant &value)
This virtual function is used to notify changes to any property (both dynamic properties, and registered with e.g., "size";, and value is the (proposed) new value of the property.
Qt::LayoutDirection layoutDirection() const
QGraphicsWidget * window() const
Returns the item&#39;s window, or 0 if this item does not have a window.
QString objectName() const
int height() const
Returns the height.
Definition: qsize.h:129
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
bool acceptsHoverEvents() const
Call acceptHoverEvents() instead.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isWidget() const
Returns true if this item is a widget (i.
QFactoryLoader * l
virtual bool contains(const QPointF &point) const
Returns true if this item contains point, which is in local coordinates; otherwise, false is returned.
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713
void setStyleForWidget(QGraphicsWidget *widget, QStyle *style)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
quint16 index
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void setPalette(const QPalette &palette)
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
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
bool enabled
whether the item is enabled or not
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setFont(const QFont &f)
Sets the painter&#39;s font to the given font.
Definition: qpainter.cpp:4288
QStyle * style() const
Returns a pointer to the widget&#39;s style.
void addAction(QAction *action)
Appends the action action to this widget&#39;s list of actions.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
Qt::WindowFlags windowFlags() const
static void setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second)
Moves the second widget around the ring of focus widgets so that keyboard focus moves from the first ...
QRectF windowFrameRect() const
Returns the widget&#39;s local rect including any window frame.
ShortcutContext
Definition: qnamespace.h:1478
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
QRegion region
the region for style hints that return a QRegion
Definition: qstyleoption.h:930
QRectF exposedRect
the exposed rectangle, in item coordinates
Definition: qstyleoption.h:873
virtual void hideEvent(QHideEvent *event)
This event handler, for Hide events, is delivered after the widget has been hidden, for example, setVisible(false) has been called for the widget or one of its ancestors when the widget was previously shown.
WindowFrameSection
Definition: qnamespace.h:1716
void setShortcutAutoRepeat(int id, bool enabled=true)
If enabled is true, auto repeat of the shortcut with the given id is enabled; otherwise it is disable...
The QGraphicsObject class provides a base class for all graphics items that require signals...
void setFlag(GraphicsItemFlag flag, bool enabled=true)
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
#define qPrintable(string)
Definition: qglobal.h:1750
void updateGeometry()
If this widget is currently managed by a layout, this function notifies the layout that the widget&#39;s ...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
QGraphicsLayout * layout() const
bool autoFillBackground() const
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
#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
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
The QCloseEvent class contains parameters that describe a close event.
Definition: qevent.h:364
void resize(const QSizeF &size)
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
QWidget * widget() const
Returns a pointer to the embedded widget.
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
void adjustSize()
Adjusts the size of the widget to its effective preferred size hint.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
QPalette resolve(const QPalette &) const
Returns a new QPalette that has attributes copied from other.
Definition: qpalette.cpp:1101
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
void layoutChanged()
This signal gets emitted whenever the layout of the item changes.
virtual void showEvent(QShowEvent *event)
This event handler, for Show events, is delivered before the widget has been shown, for example, setVisible(true) has been called for the widget or one of its ancestors when the widget was previously hidden.
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
void setFocus(Qt::FocusReason focusReason=Qt::OtherFocusReason)
Gives keyboard input focus to this item.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
void setFocusPolicy(Qt::FocusPolicy policy)