Qt 4.8
qgraphicsitem.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 
743 #include "qgraphicsitem.h"
744 
745 #ifndef QT_NO_GRAPHICSVIEW
746 
747 #include "qgraphicsscene.h"
748 #include "qgraphicsscene_p.h"
749 #include "qgraphicssceneevent.h"
750 #include "qgraphicsview.h"
751 #include "qgraphicswidget.h"
752 #include "qgraphicsproxywidget.h"
754 #include <QtCore/qbitarray.h>
755 #include <QtCore/qdebug.h>
756 #include <QtCore/qpoint.h>
757 #include <QtCore/qstack.h>
758 #include <QtCore/qtimer.h>
759 #include <QtCore/qvariant.h>
760 #include <QtCore/qvarlengtharray.h>
761 #include <QtCore/qnumeric.h>
762 #include <QtGui/qapplication.h>
763 #include <QtGui/qbitmap.h>
764 #include <QtGui/qpainter.h>
765 #include <QtGui/qpainterpath.h>
766 #include <QtGui/qpixmapcache.h>
767 #include <QtGui/qstyleoption.h>
768 #include <QtGui/qevent.h>
769 #include <QtGui/qinputcontext.h>
770 #include <QtGui/qgraphicseffect.h>
771 #ifndef QT_NO_ACCESSIBILITY
772 # include "qaccessible.h"
773 #endif
774 
775 #include <private/qgraphicsitem_p.h>
776 #include <private/qgraphicswidget_p.h>
777 #include <private/qtextcontrol_p.h>
778 #include <private/qtextdocumentlayout_p.h>
779 #include <private/qtextengine_p.h>
780 #include <private/qwidget_p.h>
781 #include <private/qapplication_p.h>
782 
783 #ifdef Q_WS_X11
784 #include <private/qt_x11_p.h>
785 #include <private/qpixmap_x11_p.h>
786 #endif
787 
788 #include <private/qgesturemanager_p.h>
789 
790 #include <math.h>
791 
793 
794 static inline void _q_adjustRect(QRect *rect)
795 {
796  Q_ASSERT(rect);
797  if (!rect->width())
798  rect->adjust(0, 0, 1, 0);
799  if (!rect->height())
800  rect->adjust(0, 0, 0, 1);
801 }
802 
803 /*
804  ### Move this into QGraphicsItemPrivate
805  */
807 {
808 public:
810 };
812 
813 
823 {
824  // We unfortunately need this hack as QPainterPathStroker will set a width of 1.0
825  // if we pass a value of 0.0 to QPainterPathStroker::setWidth()
826  const qreal penWidthZero = qreal(0.00000001);
827 
828  if (path == QPainterPath())
829  return path;
831  ps.setCapStyle(pen.capStyle());
832  if (pen.widthF() <= 0.0)
833  ps.setWidth(penWidthZero);
834  else
835  ps.setWidth(pen.widthF());
836  ps.setJoinStyle(pen.joinStyle());
837  ps.setMiterLimit(pen.miterLimit());
838  QPainterPath p = ps.createStroke(path);
839  p.addPath(path);
840  return p;
841 }
842 
854  AncestorFlag flag, bool enabled, bool root)
855 {
857  if (root) {
858  // For root items only. This is the item that has either enabled or
859  // disabled \a childFlag, or has been reparented.
860  switch (int(childFlag)) {
861  case -2:
862  flag = AncestorFiltersChildEvents;
863  enabled = q->filtersChildEvents();
864  break;
865  case -1:
866  flag = AncestorHandlesChildEvents;
867  enabled = q->handlesChildEvents();
868  break;
870  flag = AncestorClipsChildren;
871  enabled = flags & QGraphicsItem::ItemClipsChildrenToShape;
872  break;
874  flag = AncestorIgnoresTransformations;
876  break;
877  default:
878  return;
879  }
880 
881  if (parent) {
882  // Inherit the enabled-state from our parents.
883  if ((parent->d_ptr->ancestorFlags & flag)
884  || (int(parent->d_ptr->flags & childFlag) == childFlag)
885  || (childFlag == -1 && parent->d_ptr->handlesChildEvents)
886  || (childFlag == -2 && parent->d_ptr->filtersDescendantEvents)) {
887  enabled = true;
888  ancestorFlags |= flag;
889  } else {
890  ancestorFlags &= ~flag;
891  }
892  } else {
893  // Top-level root items don't have any ancestors, so there are no
894  // ancestor flags either.
895  ancestorFlags = 0;
896  }
897  } else {
898  // Don't set or propagate the ancestor flag if it's already correct.
899  if (((ancestorFlags & flag) && enabled) || (!(ancestorFlags & flag) && !enabled))
900  return;
901 
902  // Set the flag.
903  if (enabled)
904  ancestorFlags |= flag;
905  else
906  ancestorFlags &= ~flag;
907 
908  // Don't process children if the item has the main flag set on itself.
909  if ((childFlag != -1 && int(flags & childFlag) == childFlag)
910  || (int(childFlag) == -1 && handlesChildEvents)
911  || (int(childFlag) == -2 && filtersDescendantEvents))
912  return;
913  }
914 
915  for (int i = 0; i < children.size(); ++i)
916  children.at(i)->d_ptr->updateAncestorFlag(childFlag, flag, enabled, false);
917 }
918 
920 {
921  int flags = 0;
922  if (parent) {
923  // Inherit the parent's ancestor flags.
924  QGraphicsItemPrivate *pd = parent->d_ptr.data();
925  flags = pd->ancestorFlags;
926 
927  // Add in flags from the parent.
928  if (pd->filtersDescendantEvents)
929  flags |= AncestorFiltersChildEvents;
930  if (pd->handlesChildEvents)
931  flags |= AncestorHandlesChildEvents;
933  flags |= AncestorClipsChildren;
935  flags |= AncestorIgnoresTransformations;
936  }
937 
938  if (ancestorFlags == flags)
939  return; // No change; stop propagation.
940  ancestorFlags = flags;
941 
942  // Propagate to children recursively.
943  for (int i = 0; i < children.size(); ++i)
944  children.at(i)->d_ptr->updateAncestorFlags();
945 }
946 
956 {
958  isMemberOfGroup = enabled;
959  if (!qgraphicsitem_cast<QGraphicsItemGroup *>(q)) {
960  foreach (QGraphicsItem *child, children)
961  child->d_func()->setIsMemberOfGroup(enabled);
962  }
963 }
964 
974 {
976  switch (event->type()) {
982  mouseEvent->setPos(item->mapFromItem(q, mouseEvent->pos()));
983  mouseEvent->setLastPos(item->mapFromItem(q, mouseEvent->pos()));
984  for (int i = 0x1; i <= 0x10; i <<= 1) {
985  if (mouseEvent->buttons() & i) {
986  Qt::MouseButton button = Qt::MouseButton(i);
987  mouseEvent->setButtonDownPos(button, item->mapFromItem(q, mouseEvent->buttonDownPos(button)));
988  }
989  }
990  break;
991  }
993  QGraphicsSceneWheelEvent *wheelEvent = static_cast<QGraphicsSceneWheelEvent *>(event);
994  wheelEvent->setPos(item->mapFromItem(q, wheelEvent->pos()));
995  break;
996  }
999  contextEvent->setPos(item->mapFromItem(q, contextEvent->pos()));
1000  break;
1001  }
1003  QGraphicsSceneHoverEvent *hoverEvent = static_cast<QGraphicsSceneHoverEvent *>(event);
1004  hoverEvent->setPos(item->mapFromItem(q, hoverEvent->pos()));
1005  break;
1006  }
1007  default:
1008  break;
1009  }
1010 }
1011 
1023  const QWidget *viewport) const
1024 {
1025  Q_Q(const QGraphicsItem);
1026  if (!itemIsUntransformable())
1027  return q->mapFromScene(pos);
1028  QGraphicsView *view = 0;
1029  if (viewport)
1030  view = qobject_cast<QGraphicsView *>(viewport->parentWidget());
1031  if (!view)
1032  return q->mapFromScene(pos);
1033  // ### More ping pong than needed.
1034  return q->deviceTransform(view->viewportTransform()).inverted().map(view->mapFromScene(pos));
1035 }
1036 
1049 {
1050  // COMBINE
1051  if (viewTransform && itemIsUntransformable()) {
1052  *x = q_ptr->deviceTransform(*viewTransform);
1053  } else {
1054  if (transformData)
1055  *x *= transformData->computedFullTransform();
1056  if (!pos.isNull())
1057  *x *= QTransform::fromTranslate(pos.x(), pos.y());
1058  }
1059 }
1060 
1074 {
1075  // COMBINE
1076  if (viewTransform && itemIsUntransformable()) {
1077  *x = q_ptr->deviceTransform(*viewTransform);
1078  } else {
1079  x->translate(pos.x(), pos.y());
1080  if (transformData)
1081  *x = transformData->computedFullTransform(x);
1082  }
1083 }
1084 
1086 {
1087  if (parent) {
1088  Q_ASSERT(!parent->d_ptr->dirtySceneTransform);
1089  if (parent->d_ptr->sceneTransformTranslateOnly) {
1090  sceneTransform = QTransform::fromTranslate(parent->d_ptr->sceneTransform.dx() + pos.x(),
1091  parent->d_ptr->sceneTransform.dy() + pos.y());
1092  } else {
1093  sceneTransform = parent->d_ptr->sceneTransform;
1094  sceneTransform.translate(pos.x(), pos.y());
1095  }
1096  if (transformData) {
1097  sceneTransform = transformData->computedFullTransform(&sceneTransform);
1098  sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
1099  } else {
1100  sceneTransformTranslateOnly = parent->d_ptr->sceneTransformTranslateOnly;
1101  }
1102  } else if (!transformData) {
1103  sceneTransform = QTransform::fromTranslate(pos.x(), pos.y());
1104  sceneTransformTranslateOnly = 1;
1105  } else if (transformData->onlyTransform) {
1106  sceneTransform = transformData->transform;
1107  if (!pos.isNull())
1108  sceneTransform *= QTransform::fromTranslate(pos.x(), pos.y());
1109  sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
1110  } else if (pos.isNull()) {
1111  sceneTransform = transformData->computedFullTransform();
1112  sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
1113  } else {
1114  sceneTransform = QTransform::fromTranslate(pos.x(), pos.y());
1115  sceneTransform = transformData->computedFullTransform(&sceneTransform);
1116  sceneTransformTranslateOnly = (sceneTransform.type() <= QTransform::TxTranslate);
1117  }
1118  dirtySceneTransform = 0;
1119 }
1120 
1135 {
1136  Q_UNUSED(query);
1137  return QVariant();
1138 }
1139 
1150 void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const QVariant *newParentVariant,
1151  const QVariant *thisPointerVariant)
1152 {
1153  Q_Q(QGraphicsItem);
1154  if (newParent == parent)
1155  return;
1156 
1157  if (isWidget)
1158  static_cast<QGraphicsWidgetPrivate *>(this)->fixFocusChainBeforeReparenting((newParent &&
1159  newParent->isWidget()) ? static_cast<QGraphicsWidget *>(newParent) : 0,
1160  scene);
1161  if (scene) {
1162  // Deliver the change to the index
1163  if (scene->d_func()->indexMethod != QGraphicsScene::NoIndex)
1164  scene->d_func()->index->itemChange(q, QGraphicsItem::ItemParentChange, newParent);
1165 
1166  // Disable scene pos notifications for old ancestors
1167  if (scenePosDescendants || (flags & QGraphicsItem::ItemSendsScenePositionChanges))
1168  scene->d_func()->setScenePosItemEnabled(q, false);
1169  }
1170 
1171  if (subFocusItem && parent) {
1172  // Make sure none of the old parents point to this guy.
1173  subFocusItem->d_ptr->clearSubFocus(parent);
1174  }
1175 
1176  // We anticipate geometry changes. If the item is deleted, it will be
1177  // removed from the index at a later stage, and the whole scene will be
1178  // updated.
1179  if (!inDestructor)
1180  q_ptr->prepareGeometryChange();
1181 
1182  if (parent) {
1183  // Remove from current parent
1184  parent->d_ptr->removeChild(q);
1185  if (thisPointerVariant)
1186  parent->itemChange(QGraphicsItem::ItemChildRemovedChange, *thisPointerVariant);
1187  }
1188 
1189  // Update toplevelitem list. If this item is being deleted, its parent
1190  // will be 0 but we don't want to register/unregister it in the TLI list.
1191  if (scene && !inDestructor) {
1192  if (parent && !newParent) {
1193  scene->d_func()->registerTopLevelItem(q);
1194  } else if (!parent && newParent) {
1195  scene->d_func()->unregisterTopLevelItem(q);
1196  }
1197  }
1198 
1199  // Ensure any last parent focus scope does not point to this item or any of
1200  // its descendents.
1201  QGraphicsItem *p = parent;
1202  QGraphicsItem *parentFocusScopeItem = 0;
1203  while (p) {
1205  // If this item's focus scope's focus scope item points
1206  // to this item or a descendent, then clear it.
1207  QGraphicsItem *fsi = p->d_ptr->focusScopeItem;
1208  if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) {
1209  parentFocusScopeItem = fsi;
1210  p->d_ptr->focusScopeItem = 0;
1211  }
1212  break;
1213  }
1214  p = p->d_ptr->parent;
1215  }
1216 
1217  // Update graphics effect optimization flag
1218  if (newParent && (graphicsEffect || mayHaveChildWithGraphicsEffect))
1220 
1221  // Update focus scope item ptr in new scope.
1222  QGraphicsItem *newFocusScopeItem = subFocusItem ? subFocusItem : parentFocusScopeItem;
1223  if (newFocusScopeItem && newParent) {
1224  QGraphicsItem *p = newParent;
1225  while (p) {
1227  if (subFocusItem && subFocusItem != q_ptr) {
1228  // Find the subFocusItem's topmost focus scope within the new parent's focusscope
1229  QGraphicsItem *ancestorScope = 0;
1230  QGraphicsItem *p2 = subFocusItem->d_ptr->parent;
1231  while (p2 && p2 != p) {
1233  ancestorScope = p2;
1235  break;
1236  if (p2 == q_ptr)
1237  break;
1238  p2 = p2->d_ptr->parent;
1239  }
1240  if (ancestorScope)
1241  newFocusScopeItem = ancestorScope;
1242  }
1243 
1244  p->d_ptr->focusScopeItem = newFocusScopeItem;
1245  newFocusScopeItem->d_ptr->focusScopeItemChange(true);
1246  // Ensure the new item is no longer the subFocusItem. The
1247  // only way to set focus on a child of a focus scope is
1248  // by setting focus on the scope itself.
1249  if (subFocusItem && !p->focusItem())
1250  subFocusItem->d_ptr->clearSubFocus();
1251  break;
1252  }
1253  p = p->d_ptr->parent;
1254  }
1255  }
1256 
1257  // Resolve depth.
1258  invalidateDepthRecursively();
1259 
1260  if ((parent = newParent)) {
1261  if (parent->d_func()->scene && parent->d_func()->scene != scene) {
1262  // Move this item to its new parent's scene
1263  parent->d_func()->scene->addItem(q);
1264  } else if (!parent->d_func()->scene && scene) {
1265  // Remove this item from its former scene
1266  scene->removeItem(q);
1267  }
1268 
1269  parent->d_ptr->addChild(q);
1270  if (thisPointerVariant)
1271  parent->itemChange(QGraphicsItem::ItemChildAddedChange, *thisPointerVariant);
1272  if (scene) {
1273  // Re-enable scene pos notifications for new ancestors
1274  if (scenePosDescendants || (flags & QGraphicsItem::ItemSendsScenePositionChanges))
1275  scene->d_func()->setScenePosItemEnabled(q, true);
1276  }
1277 
1278  // Propagate dirty flags to the new parent
1279  markParentDirty(/*updateBoundingRect=*/true);
1280 
1281  // Inherit ancestor flags from the new parent.
1282  updateAncestorFlags();
1283 
1284  // Update item visible / enabled.
1285  if (parent->d_ptr->visible != visible) {
1286  if (!parent->d_ptr->visible || !explicitlyHidden)
1287  setVisibleHelper(parent->d_ptr->visible, /* explicit = */ false, /* update = */ false);
1288  }
1289  if (parent->isEnabled() != enabled) {
1290  if (!parent->d_ptr->enabled || !explicitlyDisabled)
1291  setEnabledHelper(parent->d_ptr->enabled, /* explicit = */ false, /* update = */ false);
1292  }
1293 
1294  // Auto-activate if visible and the parent is active.
1295  if (visible && parent->isActive())
1296  q->setActive(true);
1297  } else {
1298  // Inherit ancestor flags from the new parent.
1299  updateAncestorFlags();
1300 
1301  if (!inDestructor) {
1302  // Update item visible / enabled.
1303  if (!visible && !explicitlyHidden)
1304  setVisibleHelper(true, /* explicit = */ false);
1305  if (!enabled && !explicitlyDisabled)
1306  setEnabledHelper(true, /* explicit = */ false);
1307  }
1308  }
1309 
1310  dirtySceneTransform = 1;
1311  if (!inDestructor && (transformData || (newParent && newParent->d_ptr->transformData)))
1312  transformChanged();
1313 
1314  // Reparenting is finished, now safe to notify the previous focusScopeItem about changes
1315  if (parentFocusScopeItem)
1316  parentFocusScopeItem->d_ptr->focusScopeItemChange(false);
1317 
1318  // Restore the sub focus chain.
1319  if (subFocusItem) {
1320  subFocusItem->d_ptr->setSubFocus(newParent);
1321  if (parent && parent->isActive())
1322  subFocusItem->setFocus();
1323  }
1324 
1325  // Deliver post-change notification
1326  if (newParentVariant)
1327  q->itemChange(QGraphicsItem::ItemParentHasChanged, *newParentVariant);
1328 
1329  if (isObject)
1330  emit static_cast<QGraphicsObject *>(q)->parentChanged();
1331 }
1332 
1342 {
1343  Q_Q(QGraphicsItem);
1344 
1345  QRectF childrenRect;
1346  QRectF *result = rect;
1347  rect = &childrenRect;
1348  const bool setTopMostEffectItem = !topMostEffectItem;
1349 
1350  for (int i = 0; i < children.size(); ++i) {
1351  QGraphicsItem *child = children.at(i);
1352  QGraphicsItemPrivate *childd = child->d_ptr.data();
1353  if (setTopMostEffectItem)
1354  topMostEffectItem = child;
1355  bool hasPos = !childd->pos.isNull();
1356  if (hasPos || childd->transformData) {
1357  // COMBINE
1358  QTransform matrix = childd->transformToParent();
1359  if (x)
1360  matrix *= *x;
1361  *rect |= matrix.mapRect(child->d_ptr->effectiveBoundingRect(topMostEffectItem));
1362  if (!childd->children.isEmpty())
1363  childd->childrenBoundingRectHelper(&matrix, rect, topMostEffectItem);
1364  } else {
1365  if (x)
1366  *rect |= x->mapRect(child->d_ptr->effectiveBoundingRect(topMostEffectItem));
1367  else
1368  *rect |= child->d_ptr->effectiveBoundingRect(topMostEffectItem);
1369  if (!childd->children.isEmpty())
1370  childd->childrenBoundingRectHelper(x, rect, topMostEffectItem);
1371  }
1372  }
1373 
1375  if (x)
1376  *rect &= x->mapRect(q->boundingRect());
1377  else
1378  *rect &= q->boundingRect();
1379  }
1380 
1381  *result |= *rect;
1382 }
1383 
1385  const QRegion &exposedRegion, bool allItems) const
1386 {
1387  Q_ASSERT(option);
1388  Q_Q(const QGraphicsItem);
1389 
1390  // Initialize standard QStyleOption values.
1391  const QRectF brect = q->boundingRect();
1392  option->state = QStyle::State_None;
1393  option->rect = brect.toRect();
1394  option->levelOfDetail = 1;
1395  option->exposedRect = brect;
1396  if (selected)
1397  option->state |= QStyle::State_Selected;
1398  if (enabled)
1399  option->state |= QStyle::State_Enabled;
1400  if (q->hasFocus())
1401  option->state |= QStyle::State_HasFocus;
1402  if (scene) {
1403  if (scene->d_func()->hoverItems.contains(q_ptr))
1404  option->state |= QStyle::State_MouseOver;
1405  if (q == scene->mouseGrabberItem())
1406  option->state |= QStyle::State_Sunken;
1407  }
1408 
1410  return;
1411 
1412  // Initialize QStyleOptionGraphicsItem specific values (matrix, exposedRect).
1413  option->matrix = worldTransform.toAffine(); //### discards perspective
1414 
1415  if (!allItems) {
1416  // Determine the item's exposed area
1417  option->exposedRect = QRectF();
1418  const QTransform reverseMap = worldTransform.inverted();
1419  const QVector<QRect> exposedRects(exposedRegion.rects());
1420  for (int i = 0; i < exposedRects.size(); ++i) {
1421  option->exposedRect |= reverseMap.mapRect(QRectF(exposedRects.at(i)));
1422  if (option->exposedRect.contains(brect))
1423  break;
1424  }
1425  option->exposedRect &= brect;
1426  }
1427 }
1428 
1438 {
1440  key = QPixmapCache::Key();
1441  QMutableMapIterator<QPaintDevice *, DeviceData> it(deviceData);
1442  while (it.hasNext()) {
1443  DeviceData &data = it.next().value();
1444  QPixmapCache::remove(data.key);
1445  data.cacheIndent = QPoint();
1446  }
1447  deviceData.clear();
1448  allExposed = true;
1449  exposed.clear();
1450 }
1451 
1462 #ifndef Q_QDOC
1463  // obsolete argument
1464  , QGraphicsScene *scene
1465 #endif
1466  )
1467  : d_ptr(new QGraphicsItemPrivate)
1468 {
1469  d_ptr->q_ptr = this;
1470  setParentItem(parent);
1471 
1472  if (scene && parent && parent->scene() != scene) {
1473  qWarning("QGraphicsItem::QGraphicsItem: ignoring scene (%p), which is"
1474  " different from parent's scene (%p)",
1475  scene, parent->scene());
1476  return;
1477  }
1478  if (scene && !parent)
1479  scene->addItem(this);
1480 }
1481 
1487  : d_ptr(&dd)
1488 {
1489  d_ptr->q_ptr = this;
1490  setParentItem(parent);
1491 
1492  if (scene && parent && parent->scene() != scene) {
1493  qWarning("QGraphicsItem::QGraphicsItem: ignoring scene (%p), which is"
1494  " different from parent's scene (%p)",
1495  scene, parent->scene());
1496  return;
1497  }
1498  if (scene && !parent)
1499  scene->addItem(this);
1500 }
1501 
1511 {
1512  if (d_ptr->isObject) {
1513  QGraphicsObject *o = static_cast<QGraphicsObject *>(this);
1515  p->wasDeleted = true;
1516  if (p->declarativeData) {
1518  p->declarativeData = 0;
1519  }
1520  }
1521 
1522  d_ptr->inDestructor = 1;
1524 
1525 #ifndef QT_NO_GESTURES
1526  if (d_ptr->isObject && !d_ptr->gestureContext.isEmpty()) {
1527  QGraphicsObject *o = static_cast<QGraphicsObject *>(this);
1528  if (QGestureManager *manager = QGestureManager::instance()) {
1530  manager->cleanupCachedGestures(o, type);
1531  }
1532  }
1533 #endif
1534 
1535  clearFocus();
1536 
1537  // Update focus scope item ptr.
1538  QGraphicsItem *p = d_ptr->parent;
1539  while (p) {
1540  if (p->flags() & ItemIsFocusScope) {
1541  if (p->d_ptr->focusScopeItem == this)
1542  p->d_ptr->focusScopeItem = 0;
1543  break;
1544  }
1545  p = p->d_ptr->parent;
1546  }
1547 
1548  if (!d_ptr->children.isEmpty()) {
1549  while (!d_ptr->children.isEmpty())
1550  delete d_ptr->children.first();
1552  }
1553 
1554  if (d_ptr->scene) {
1555  d_ptr->scene->d_func()->removeItemHelper(this);
1556  } else {
1558  setParentItem(0);
1559  }
1560 
1561 #ifndef QT_NO_GRAPHICSEFFECT
1562  delete d_ptr->graphicsEffect;
1563 #endif //QT_NO_GRAPHICSEFFECT
1564  if (d_ptr->transformData) {
1565  for(int i = 0; i < d_ptr->transformData->graphicsTransforms.size(); ++i) {
1567  static_cast<QGraphicsTransformPrivate *>(t->d_ptr.data())->item = 0;
1568  delete t;
1569  }
1570  }
1571  delete d_ptr->transformData;
1572 
1573  if (QGraphicsItemCustomDataStore *dataStore = qt_dataStore())
1574  dataStore->data.remove(this);
1575 }
1576 
1584 {
1585  return d_ptr->scene;
1586 }
1587 
1595 {
1596  if (!d_ptr->isMemberOfGroup)
1597  return 0;
1598  QGraphicsItem *parent = const_cast<QGraphicsItem *>(this);
1599  while ((parent = parent->d_ptr->parent)) {
1600  if (QGraphicsItemGroup *group = qgraphicsitem_cast<QGraphicsItemGroup *>(parent))
1601  return group;
1602  }
1603  // Unreachable; if d_ptr->isMemberOfGroup is != 0, then one parent of this
1604  // item is a group item.
1605  return 0;
1606 }
1607 
1616 {
1617  if (!group) {
1618  if (QGraphicsItemGroup *group = this->group())
1619  group->removeFromGroup(this);
1620  } else {
1621  group->addToGroup(this);
1622  }
1623 }
1624 
1632 {
1633  return d_ptr->parent;
1634 }
1635 
1644 {
1645  QGraphicsItem *parent = const_cast<QGraphicsItem *>(this);
1646  while (QGraphicsItem *grandPa = parent->parentItem())
1647  parent = grandPa;
1648  return parent;
1649 }
1650 
1663 {
1664  QGraphicsItem *p = d_ptr->parent;
1665  return (p && p->d_ptr->isObject) ? static_cast<QGraphicsObject *>(p) : 0;
1666 }
1667 
1680 {
1681  QGraphicsItem *p = parentItem();
1682  while (p && !p->isWidget())
1683  p = p->parentItem();
1684  return (p && p->isWidget()) ? static_cast<QGraphicsWidget *>(p) : 0;
1685 }
1686 
1699 {
1700  if (const QGraphicsWidget *p = parentWidget())
1701  return p->topLevelWidget();
1702  return isWidget() ? static_cast<QGraphicsWidget *>(const_cast<QGraphicsItem *>(this)) : 0;
1703 }
1704 
1718 {
1719  QGraphicsItem *p = panel();
1720  if (p && p->isWindow())
1721  return static_cast<QGraphicsWidget *>(p);
1722  return 0;
1723 }
1724 
1738 {
1739  if (d_ptr->flags & ItemIsPanel)
1740  return const_cast<QGraphicsItem *>(this);
1741  return d_ptr->parent ? d_ptr->parent->panel() : 0;
1742 }
1743 
1754 {
1755  return d_ptr->isObject ? static_cast<QGraphicsObject *>(this) : 0;
1756 }
1757 
1768 {
1769  return d_ptr->isObject ? static_cast<const QGraphicsObject *>(this) : 0;
1770 }
1771 
1787 {
1788  if (newParent == this) {
1789  qWarning("QGraphicsItem::setParentItem: cannot assign %p as a parent of itself", this);
1790  return;
1791  }
1792  if (newParent == d_ptr->parent)
1793  return;
1794 
1795  const QVariant newParentVariant(itemChange(QGraphicsItem::ItemParentChange,
1796  QVariant::fromValue<QGraphicsItem *>(newParent)));
1797  newParent = qvariant_cast<QGraphicsItem *>(newParentVariant);
1798  if (newParent == d_ptr->parent)
1799  return;
1800 
1801  const QVariant thisPointerVariant(QVariant::fromValue<QGraphicsItem *>(this));
1802  d_ptr->setParentItemHelper(newParent, &newParentVariant, &thisPointerVariant);
1803 }
1804 
1816 {
1817  return childItems();
1818 }
1819 
1834 {
1835  const_cast<QGraphicsItem *>(this)->d_ptr->ensureSortedChildren();
1836  return d_ptr->children;
1837 }
1838 
1848 {
1849  return d_ptr->isWidget;
1850 }
1851 
1863 {
1864  return d_ptr->isWidget && (static_cast<const QGraphicsWidget *>(this)->windowType() & Qt::Window);
1865 }
1866 
1877 {
1878  return d_ptr->flags & ItemIsPanel;
1879 }
1880 
1890 QGraphicsItem::GraphicsItemFlags QGraphicsItem::flags() const
1891 {
1892  return GraphicsItemFlags(d_ptr->flags);
1893 }
1894 
1902 {
1903  if (enabled)
1904  setFlags(GraphicsItemFlags(d_ptr->flags) | flag);
1905  else
1906  setFlags(GraphicsItemFlags(d_ptr->flags) & ~flag);
1907 }
1908 
1918  bool enabled)
1919 {
1920  if (item->flags() & flag) {
1921  // If this item already has the correct flag set, we don't have to
1922  // propagate it.
1923  return;
1924  }
1925  item->setFlag(flag, enabled);
1926  foreach (QGraphicsItem *child, item->children())
1927  _q_qgraphicsItemSetFlag(child, flag, enabled);
1928 }
1929 
1945 void QGraphicsItem::setFlags(GraphicsItemFlags flags)
1946 {
1947  // Notify change and check for adjustment.
1948  if (quint32(d_ptr->flags) == quint32(flags))
1949  return;
1950  flags = GraphicsItemFlags(itemChange(ItemFlagsChange, quint32(flags)).toUInt());
1951  if (quint32(d_ptr->flags) == quint32(flags))
1952  return;
1953  if (d_ptr->scene && d_ptr->scene->d_func()->indexMethod != QGraphicsScene::NoIndex)
1954  d_ptr->scene->d_func()->index->itemChange(this, ItemFlagsChange, &flags);
1955 
1956  // Flags that alter the geometry of the item (or its children).
1958  bool fullUpdate = (quint32(flags) & geomChangeFlagsMask) != (d_ptr->flags & geomChangeFlagsMask);
1959  if (fullUpdate)
1960  d_ptr->updatePaintedViewBoundingRects(/*children=*/true);
1961 
1962  // Keep the old flags to compare the diff.
1963  GraphicsItemFlags oldFlags = GraphicsItemFlags(d_ptr->flags);
1964 
1965  // Update flags.
1966  d_ptr->flags = flags;
1967 
1968  if (!(d_ptr->flags & ItemIsFocusable) && hasFocus()) {
1969  // Clear focus on the item if it has focus when the focusable flag
1970  // is unset.
1971  clearFocus();
1972  }
1973 
1974  if (!(d_ptr->flags & ItemIsSelectable) && isSelected()) {
1975  // Unselect the item if it is selected when the selectable flag is
1976  // unset.
1977  setSelected(false);
1978  }
1979 
1980  if ((flags & ItemClipsChildrenToShape) != (oldFlags & ItemClipsChildrenToShape)) {
1981  // Item children clipping changes. Propagate the ancestor flag to
1982  // all children.
1983  d_ptr->updateAncestorFlag(ItemClipsChildrenToShape);
1984  // The childrenBoundingRect is clipped to the boundingRect in case of ItemClipsChildrenToShape,
1985  // which means we have to invalidate the cached childrenBoundingRect whenever this flag changes.
1987  d_ptr->markParentDirty(true);
1988  }
1989 
1990  if ((flags & ItemIgnoresTransformations) != (oldFlags & ItemIgnoresTransformations)) {
1991  // Item children clipping changes. Propagate the ancestor flag to
1992  // all children.
1993  d_ptr->updateAncestorFlag(ItemIgnoresTransformations);
1994  }
1995 
1996  if ((flags & ItemNegativeZStacksBehindParent) != (oldFlags & ItemNegativeZStacksBehindParent)) {
1997  // NB! We change the flags directly here, so we must also update d_ptr->flags.
1998  // Note that this has do be done before the ItemStacksBehindParent check
1999  // below; otherwise we will loose the change.
2000 
2001  // Update stack-behind.
2002  if (d_ptr->z < qreal(0.0))
2003  flags |= ItemStacksBehindParent;
2004  else
2005  flags &= ~ItemStacksBehindParent;
2006  d_ptr->flags = flags;
2007  }
2008 
2009  if ((flags & ItemStacksBehindParent) != (oldFlags & ItemStacksBehindParent)) {
2010  // NB! This check has to come after the ItemNegativeZStacksBehindParent
2011  // check above. Be careful.
2012 
2013  // Ensure child item sorting is up to date when toggling this flag.
2014  if (d_ptr->parent)
2016  else if (d_ptr->scene)
2017  d_ptr->scene->d_func()->needSortTopLevelItems = 1;
2018  }
2019 
2020  if ((flags & ItemAcceptsInputMethod) != (oldFlags & ItemAcceptsInputMethod)) {
2021  // Update input method sensitivity in any views.
2022  if (d_ptr->scene)
2023  d_ptr->scene->d_func()->updateInputMethodSensitivityInViews();
2024  }
2025 
2026 
2027  if ((d_ptr->panelModality != NonModal)
2028  && d_ptr->scene
2029  && (flags & ItemIsPanel) != (oldFlags & ItemIsPanel)) {
2030  // update the panel's modal state
2031  if (flags & ItemIsPanel)
2032  d_ptr->scene->d_func()->enterModal(this);
2033  else
2034  d_ptr->scene->d_func()->leaveModal(this);
2035  }
2036 
2037  if (d_ptr->scene) {
2038  if ((flags & ItemSendsScenePositionChanges) != (oldFlags & ItemSendsScenePositionChanges)) {
2039  if (flags & ItemSendsScenePositionChanges)
2040  d_ptr->scene->d_func()->registerScenePosItem(this);
2041  else
2042  d_ptr->scene->d_func()->unregisterScenePosItem(this);
2043  }
2044  d_ptr->scene->d_func()->markDirty(this, QRectF(), /*invalidateChildren=*/true);
2045  }
2046 
2047  // Notify change.
2049 }
2050 
2062 {
2064 }
2065 
2098 void QGraphicsItem::setCacheMode(CacheMode mode, const QSize &logicalCacheSize)
2099 {
2100  CacheMode lastMode = CacheMode(d_ptr->cacheMode);
2101  d_ptr->cacheMode = mode;
2102  bool noVisualChange = (mode == NoCache && lastMode == NoCache)
2103  || (mode == NoCache && lastMode == DeviceCoordinateCache)
2104  || (mode == DeviceCoordinateCache && lastMode == NoCache)
2105  || (mode == DeviceCoordinateCache && lastMode == DeviceCoordinateCache);
2106  if (mode == NoCache) {
2108  } else {
2110 
2111  // Reset old cache
2112  cache->purge();
2113 
2114  if (mode == ItemCoordinateCache) {
2115  if (lastMode == mode && cache->fixedSize == logicalCacheSize)
2116  noVisualChange = true;
2117  cache->fixedSize = logicalCacheSize;
2118  }
2119  }
2120  if (!noVisualChange)
2121  update();
2122 }
2123 
2133 {
2134  return d_ptr->panelModality;
2135 }
2136 
2148 {
2149  if (d_ptr->panelModality == panelModality)
2150  return;
2151 
2152  PanelModality previousModality = d_ptr->panelModality;
2153  bool enterLeaveModal = (isPanel() && d_ptr->scene && isVisible());
2154  if (enterLeaveModal && panelModality == NonModal)
2155  d_ptr->scene->d_func()->leaveModal(this);
2157  if (enterLeaveModal && d_ptr->panelModality != NonModal)
2158  d_ptr->scene->d_func()->enterModal(this, previousModality);
2159 }
2160 
2176 {
2177  if (!d_ptr->scene)
2178  return false;
2179 
2180 
2181  QGraphicsItem *dummy = 0;
2182  if (!blockingPanel)
2183  blockingPanel = &dummy;
2184 
2185  QGraphicsScenePrivate *scene_d = d_ptr->scene->d_func();
2186  if (scene_d->modalPanels.isEmpty())
2187  return false;
2188 
2189  // ###
2190  if (!scene_d->popupWidgets.isEmpty() && scene_d->popupWidgets.first() == this)
2191  return false;
2192 
2193  for (int i = 0; i < scene_d->modalPanels.count(); ++i) {
2194  QGraphicsItem *modalPanel = scene_d->modalPanels.at(i);
2195  if (modalPanel->panelModality() == QGraphicsItem::SceneModal) {
2196  // Scene modal panels block all non-descendents.
2197  if (modalPanel != this && !modalPanel->isAncestorOf(this)) {
2198  *blockingPanel = modalPanel;
2199  return true;
2200  }
2201  } else {
2202  // Window modal panels block ancestors and siblings/cousins.
2203  if (modalPanel != this
2204  && !modalPanel->isAncestorOf(this)
2205  && commonAncestorItem(modalPanel)) {
2206  *blockingPanel = modalPanel;
2207  return true;
2208  }
2209  }
2210  }
2211  return false;
2212 }
2213 
2214 #ifndef QT_NO_TOOLTIP
2215 
2222 {
2224 }
2225 
2233 {
2234  const QVariant toolTipVariant(itemChange(ItemToolTipChange, toolTip));
2236  itemChange(ItemToolTipHasChanged, toolTipVariant);
2237 }
2238 #endif // QT_NO_TOOLTIP
2239 
2240 #ifndef QT_NO_CURSOR
2241 
2257 {
2259 }
2260 
2277 {
2278  const QVariant cursorVariant(itemChange(ItemCursorChange, QVariant::fromValue<QCursor>(cursor)));
2279  d_ptr->setExtra(QGraphicsItemPrivate::ExtraCursor, qvariant_cast<QCursor>(cursorVariant));
2280  d_ptr->hasCursor = 1;
2281  if (d_ptr->scene) {
2282  d_ptr->scene->d_func()->allItemsUseDefaultCursor = false;
2283  foreach (QGraphicsView *view, d_ptr->scene->views()) {
2284  view->viewport()->setMouseTracking(true);
2285  // Note: Some of this logic is duplicated in QGraphicsView's mouse events.
2286  if (view->underMouse()) {
2287  foreach (QGraphicsItem *itemUnderCursor, view->items(view->mapFromGlobal(QCursor::pos()))) {
2288  if (itemUnderCursor->hasCursor()) {
2289  QMetaObject::invokeMethod(view, "_q_setViewportCursor",
2290  Q_ARG(QCursor, itemUnderCursor->cursor()));
2291  break;
2292  }
2293  }
2294  break;
2295  }
2296  }
2297  }
2298  itemChange(ItemCursorHasChanged, cursorVariant);
2299 }
2300 
2310 {
2311  return d_ptr->hasCursor;
2312 }
2313 
2320 {
2322  d_ptr->hasCursor = 0;
2323  if (d_ptr->scene) {
2324  foreach (QGraphicsView *view, d_ptr->scene->views()) {
2325  if (view->underMouse() && view->itemAt(view->mapFromGlobal(QCursor::pos())) == this) {
2326  QMetaObject::invokeMethod(view, "_q_unsetViewportCursor");
2327  break;
2328  }
2329  }
2330  }
2331 }
2332 
2333 #endif // QT_NO_CURSOR
2334 
2344 {
2345  return d_ptr->visible;
2346 }
2347 
2365 {
2366  const QGraphicsItem *p = this;
2367  if (d_ptr->explicitlyHidden)
2368  return false;
2369  do {
2370  if (p == parent)
2371  return true;
2372  if (p->d_ptr->explicitlyHidden)
2373  return false;
2374  } while ((p = p->d_ptr->parent));
2375  return parent == 0;
2376 }
2377 
2387 void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bool update)
2388 {
2389  Q_Q(QGraphicsItem);
2390 
2391  // Update explicit bit.
2392  if (explicitly)
2393  explicitlyHidden = newVisible ? 0 : 1;
2394 
2395  // Check if there's nothing to do.
2396  if (visible == quint32(newVisible))
2397  return;
2398 
2399  // Don't show child if parent is not visible
2400  if (parent && newVisible && !parent->d_ptr->visible)
2401  return;
2402 
2403  // Modify the property.
2404  const QVariant newVisibleVariant(q_ptr->itemChange(QGraphicsItem::ItemVisibleChange,
2405  quint32(newVisible)));
2406  newVisible = newVisibleVariant.toBool();
2407  if (visible == quint32(newVisible))
2408  return;
2409  visible = newVisible;
2410 
2411  // Schedule redrawing
2412  if (update) {
2413  QGraphicsItemCache *c = (QGraphicsItemCache *)qvariant_cast<void *>(extra(ExtraCacheData));
2414  if (c)
2415  c->purge();
2416  if (scene) {
2417 #ifndef QT_NO_GRAPHICSEFFECT
2418  invalidateParentGraphicsEffectsRecursively();
2419 #endif //QT_NO_GRAPHICSEFFECT
2420  scene->d_func()->markDirty(q_ptr, QRectF(), /*invalidateChildren=*/false, /*force=*/true);
2421  }
2422  }
2423 
2424  // Certain properties are dropped as an item becomes invisible.
2425  bool hasFocus = q_ptr->hasFocus();
2426  if (!newVisible) {
2427  if (scene) {
2428  if (scene->d_func()->mouseGrabberItems.contains(q))
2429  q->ungrabMouse();
2430  if (scene->d_func()->keyboardGrabberItems.contains(q))
2431  q->ungrabKeyboard();
2432  if (q->isPanel() && panelModality != QGraphicsItem::NonModal)
2433  scene->d_func()->leaveModal(q_ptr);
2434  }
2435  if (hasFocus && scene) {
2436  // Hiding the closest non-panel ancestor of the focus item
2438  if (isWidget && !focusItem->isPanel()) {
2439  do {
2440  if (focusItem == q_ptr) {
2441  static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true);
2442  break;
2443  }
2444  } while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
2445  }
2446  // Clear focus if previous steps didn't move it to another widget
2447  if (q_ptr->hasFocus())
2448  clearFocusHelper(/* giveFocusToParent = */ false);
2449  }
2450  if (q_ptr->isSelected())
2451  q_ptr->setSelected(false);
2452  } else {
2453  geometryChanged = 1;
2454  paintedViewBoundingRectsNeedRepaint = 1;
2455  if (scene) {
2456  if (isWidget) {
2457  QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(q_ptr);
2458  if (widget->windowType() == Qt::Popup)
2459  scene->d_func()->addPopup(widget);
2460  }
2461  if (q->isPanel() && panelModality != QGraphicsItem::NonModal) {
2462  scene->d_func()->enterModal(q_ptr);
2463  }
2464  }
2465  }
2466 
2467  // Update children with explicitly = false.
2468  const bool updateChildren = update && !((flags & QGraphicsItem::ItemClipsChildrenToShape)
2470  foreach (QGraphicsItem *child, children) {
2471  if (!newVisible || !child->d_ptr->explicitlyHidden)
2472  child->d_ptr->setVisibleHelper(newVisible, false, updateChildren);
2473  }
2474 
2475  // Update activation
2476  if (scene && q->isPanel()) {
2477  if (newVisible) {
2478  if (parent && parent->isActive())
2479  q->setActive(true);
2480  } else {
2481  if (q->isActive())
2482  scene->setActivePanel(parent);
2483  }
2484  }
2485 
2486  // Enable subfocus
2487  if (scene) {
2488  if (newVisible) {
2489  // Item is shown
2490  QGraphicsItem *p = parent;
2491  bool done = false;
2492  while (p) {
2494  QGraphicsItem *fsi = p->d_ptr->focusScopeItem;
2495  if (q_ptr == fsi || q_ptr->isAncestorOf(fsi)) {
2496  done = true;
2497  while (fsi->d_ptr->focusScopeItem && fsi->d_ptr->focusScopeItem->isVisible())
2498  fsi = fsi->d_ptr->focusScopeItem;
2499  fsi->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ true,
2500  /* focusFromHide = */ false);
2501  }
2502  break;
2503  }
2504  p = p->d_ptr->parent;
2505  }
2506  if (!done) {
2507  QGraphicsItem *fi = subFocusItem;
2508  if (fi && fi != scene->focusItem()) {
2509  scene->setFocusItem(fi);
2510  } else if (flags & QGraphicsItem::ItemIsFocusScope &&
2511  !scene->focusItem() &&
2512  q->isAncestorOf(scene->d_func()->lastFocusItem)) {
2513  q_ptr->setFocus();
2514  }
2515  }
2516  } else {
2517  // Item is hidden
2518  if (hasFocus) {
2519  QGraphicsItem *p = parent;
2520  while (p) {
2522  if (p->d_ptr->visible) {
2523  p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ true,
2524  /* focusFromHide = */ true);
2525  }
2526  break;
2527  }
2528  p = p->d_ptr->parent;
2529  }
2530  }
2531  }
2532  }
2533 
2534  // Deliver post-change notification.
2535  q_ptr->itemChange(QGraphicsItem::ItemVisibleHasChanged, newVisibleVariant);
2536 
2537  if (isObject)
2538  emit static_cast<QGraphicsObject *>(q_ptr)->visibleChanged();
2539 }
2540 
2568 void QGraphicsItem::setVisible(bool visible)
2569 {
2570  d_ptr->setVisibleHelper(visible, /* explicit = */ true);
2571 }
2572 
2605 {
2606  return d_ptr->enabled;
2607 }
2608 
2618 void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bool update)
2619 {
2620  // Update explicit bit.
2621  if (explicitly)
2622  explicitlyDisabled = newEnabled ? 0 : 1;
2623 
2624  // Check if there's nothing to do.
2625  if (enabled == quint32(newEnabled))
2626  return;
2627 
2628  // Certain properties are dropped when an item is disabled.
2629  if (!newEnabled) {
2630  if (scene && scene->mouseGrabberItem() == q_ptr)
2631  q_ptr->ungrabMouse();
2632  if (q_ptr->hasFocus()) {
2633  // Disabling the closest non-panel ancestor of the focus item
2634  // causes focus to pop to the next item, otherwise it's cleared.
2636  if (isWidget && !focusItem->isPanel() && q_ptr->isAncestorOf(focusItem)) {
2637  do {
2638  if (focusItem == q_ptr) {
2639  static_cast<QGraphicsWidget *>(q_ptr)->focusNextPrevChild(true);
2640  break;
2641  }
2642  } while ((focusItem = focusItem->parentWidget()) && !focusItem->isPanel());
2643  }
2644  // Clear focus if previous steps didn't move it to another widget
2645  if (q_ptr->hasFocus())
2646  q_ptr->clearFocus();
2647  }
2648  if (q_ptr->isSelected())
2649  q_ptr->setSelected(false);
2650  }
2651 
2652  // Modify the property.
2653  const QVariant newEnabledVariant(q_ptr->itemChange(QGraphicsItem::ItemEnabledChange,
2654  quint32(newEnabled)));
2655  enabled = newEnabledVariant.toBool();
2656 
2657  // Schedule redraw.
2658  if (update)
2659  q_ptr->update();
2660 
2661  foreach (QGraphicsItem *child, children) {
2662  if (!newEnabled || !child->d_ptr->explicitlyDisabled)
2663  child->d_ptr->setEnabledHelper(newEnabled, /* explicitly = */ false);
2664  }
2665 
2666  // Deliver post-change notification.
2667  q_ptr->itemChange(QGraphicsItem::ItemEnabledHasChanged, newEnabledVariant);
2668 
2669  if (isObject)
2670  emit static_cast<QGraphicsObject *>(q_ptr)->enabledChanged();
2671 }
2672 
2701 {
2702  d_ptr->setEnabledHelper(enabled, /* explicitly = */ true);
2703 }
2704 
2715 {
2716  if (QGraphicsItemGroup *group = this->group())
2717  return group->isSelected();
2718  return d_ptr->selected;
2719 }
2720 
2745 void QGraphicsItem::setSelected(bool selected)
2746 {
2747  if (QGraphicsItemGroup *group = this->group()) {
2748  group->setSelected(selected);
2749  return;
2750  }
2751 
2752  if (!(d_ptr->flags & ItemIsSelectable) || !d_ptr->enabled || !d_ptr->visible)
2753  selected = false;
2754  if (d_ptr->selected == selected)
2755  return;
2756  const QVariant newSelectedVariant(itemChange(ItemSelectedChange, quint32(selected)));
2757  bool newSelected = newSelectedVariant.toBool();
2758  if (d_ptr->selected == newSelected)
2759  return;
2760  d_ptr->selected = newSelected;
2761 
2762  update();
2763  if (d_ptr->scene) {
2764  QGraphicsScenePrivate *sceneD = d_ptr->scene->d_func();
2765  if (selected) {
2766  sceneD->selectedItems << this;
2767  } else {
2768  // QGraphicsScene::selectedItems() lazily pulls out all items that are
2769  // no longer selected.
2770  }
2771  if (!sceneD->selectionChanging)
2773  }
2774 
2775  // Deliver post-change notification.
2777 }
2778 
2801 {
2802  return d_ptr->opacity;
2803 }
2804 
2820 {
2821  return d_ptr->effectiveOpacity();
2822 }
2823 
2850 {
2851  // Notify change.
2852  const QVariant newOpacityVariant(itemChange(ItemOpacityChange, opacity));
2853 
2854  // Normalized opacity
2855  qreal newOpacity = qBound(qreal(0), newOpacityVariant.toReal(), qreal(1));
2856 
2857  // No change? Done.
2858  if (newOpacity == d_ptr->opacity)
2859  return;
2860 
2861  bool wasFullyTransparent = d_ptr->isOpacityNull();
2862  d_ptr->opacity = newOpacity;
2863 
2864  // Notify change.
2865  itemChange(ItemOpacityHasChanged, newOpacityVariant);
2866 
2867  // Update.
2868  if (d_ptr->scene) {
2869 #ifndef QT_NO_GRAPHICSEFFECT
2873 #endif //QT_NO_GRAPHICSEFFECT
2874  d_ptr->scene->d_func()->markDirty(this, QRectF(),
2875  /*invalidateChildren=*/true,
2876  /*force=*/false,
2877  /*ignoreOpacity=*/d_ptr->isOpacityNull());
2878  if (wasFullyTransparent)
2880  }
2881 
2882  if (d_ptr->isObject)
2883  emit static_cast<QGraphicsObject *>(this)->opacityChanged();
2884 }
2885 
2891 #ifndef QT_NO_GRAPHICSEFFECT
2893 {
2894  return d_ptr->graphicsEffect;
2895 }
2896 
2912 {
2913  if (d_ptr->graphicsEffect == effect)
2914  return;
2915 
2916  if (d_ptr->graphicsEffect) {
2917  delete d_ptr->graphicsEffect;
2918  d_ptr->graphicsEffect = 0;
2919  } else if (d_ptr->parent) {
2921  }
2922 
2923  if (effect) {
2924  // Set new effect.
2926  QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced);
2927  d_ptr->graphicsEffect = effect;
2928  effect->d_func()->setGraphicsEffectSource(source);
2930  }
2931 }
2932 #endif //QT_NO_GRAPHICSEFFECT
2933 
2935 {
2936 #ifndef QT_NO_GRAPHICSEFFECT
2937  QGraphicsItemPrivate *itemPrivate = this;
2938  do {
2939  // parent chain already notified?
2940  if (itemPrivate->mayHaveChildWithGraphicsEffect)
2941  return;
2942  itemPrivate->mayHaveChildWithGraphicsEffect = 1;
2943  } while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0));
2944 #endif
2945 }
2946 
2961 {
2962 #ifndef QT_NO_GRAPHICSEFFECT
2963  Q_Q(const QGraphicsItem);
2964  QGraphicsEffect *effect = graphicsEffect;
2965  if (scene && effect && effect->isEnabled()) {
2966  if (scene->d_func()->views.isEmpty())
2967  return effect->boundingRectFor(rect);
2968  QRectF sceneRect = q->mapRectToScene(rect);
2969  QRectF sceneEffectRect;
2970  foreach (QGraphicsView *view, scene->views()) {
2971  QRectF deviceRect = view->d_func()->mapRectFromScene(sceneRect);
2972  QRect deviceEffectRect = effect->boundingRectFor(deviceRect).toAlignedRect();
2973  sceneEffectRect |= view->d_func()->mapRectToScene(deviceEffectRect);
2974  }
2975  return q->mapRectFromScene(sceneEffectRect);
2976  }
2977 #endif //QT_NO_GRAPHICSEFFECT
2978  return rect;
2979 }
2980 
2995 {
2996 #ifndef QT_NO_GRAPHICSEFFECT
2997  Q_Q(const QGraphicsItem);
2998  QRectF brect = effectiveBoundingRect(q_ptr->boundingRect());
2999  if (ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren || topMostEffectItem == q)
3000  return brect;
3001 
3002  const QGraphicsItem *effectParent = parent;
3003  while (effectParent) {
3004  QGraphicsEffect *effect = effectParent->d_ptr->graphicsEffect;
3005  if (scene && effect && effect->isEnabled()) {
3006  const QRectF brectInParentSpace = q->mapRectToItem(effectParent, brect);
3007  const QRectF effectRectInParentSpace = effectParent->d_ptr->effectiveBoundingRect(brectInParentSpace);
3008  brect = effectParent->mapRectToItem(q, effectRectInParentSpace);
3009  }
3011  || topMostEffectItem == effectParent) {
3012  return brect;
3013  }
3014  effectParent = effectParent->d_ptr->parent;
3015  }
3016 
3017  return brect;
3018 #else //QT_NO_GRAPHICSEFFECT
3019  return q_ptr->boundingRect();
3020 #endif //QT_NO_GRAPHICSEFFECT
3021 
3022 }
3023 
3039 {
3040  // Find translate-only offset
3041  // COMBINE
3042  QPointF offset;
3043  const QGraphicsItem *parentItem = q_ptr;
3044  const QGraphicsItemPrivate *itemd;
3045  do {
3046  itemd = parentItem->d_ptr.data();
3047  if (itemd->transformData)
3048  break;
3049  offset += itemd->pos;
3050  } while ((parentItem = itemd->parent));
3051 
3052  QRectF br = effectiveBoundingRect();
3053  br.translate(offset);
3054  return !parentItem ? br : parentItem->sceneTransform().mapRect(br);
3055 }
3056 
3065 {
3066  return d_ptr->acceptDrops;
3067 }
3068 
3077 {
3078  d_ptr->acceptDrops = on;
3079 }
3080 
3093 Qt::MouseButtons QGraphicsItem::acceptedMouseButtons() const
3094 {
3095  return Qt::MouseButtons(d_ptr->acceptedMouseButtons);
3096 }
3097 
3113 {
3114  if (Qt::MouseButtons(d_ptr->acceptedMouseButtons) != buttons) {
3115  if (buttons == 0 && d_ptr->scene && d_ptr->scene->mouseGrabberItem() == this
3116  && d_ptr->scene->d_func()->lastMouseGrabberItemHasImplicitMouseGrab) {
3117  ungrabMouse();
3118  }
3119  d_ptr->acceptedMouseButtons = quint32(buttons);
3120  }
3121 }
3122 
3136 {
3137  return d_ptr->acceptsHover;
3138 }
3139 
3149 {
3150  return d_ptr->acceptsHover;
3151 }
3152 
3188 {
3189  if (d_ptr->acceptsHover == quint32(enabled))
3190  return;
3191  d_ptr->acceptsHover = quint32(enabled);
3192  if (d_ptr->acceptsHover && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreHoverEvents) {
3193  d_ptr->scene->d_func()->allItemsIgnoreHoverEvents = false;
3194  d_ptr->scene->d_func()->enableMouseTrackingOnViews();
3195  }
3196 }
3197 
3207 {
3208  setAcceptHoverEvents(enabled);
3209 }
3210 
3222 {
3223  return d_ptr->acceptTouchEvents;
3224 }
3225 
3237 {
3238  if (d_ptr->acceptTouchEvents == quint32(enabled))
3239  return;
3240  d_ptr->acceptTouchEvents = quint32(enabled);
3241  if (d_ptr->acceptTouchEvents && d_ptr->scene && d_ptr->scene->d_func()->allItemsIgnoreTouchEvents) {
3242  d_ptr->scene->d_func()->allItemsIgnoreTouchEvents = false;
3243  d_ptr->scene->d_func()->enableTouchEventsOnViews();
3244  }
3245 }
3246 
3262 {
3264 }
3265 
3281 {
3282  if (d_ptr->filtersDescendantEvents == enabled)
3283  return;
3284 
3287 }
3288 
3310 {
3311  return d_ptr->handlesChildEvents;
3312 }
3313 
3338 {
3339  if (d_ptr->handlesChildEvents == enabled)
3340  return;
3341 
3344 }
3364 {
3365  if (!d_ptr->scene || !d_ptr->scene->isActive())
3366  return false;
3367  return panel() == d_ptr->scene->activePanel();
3368 }
3369 
3387 void QGraphicsItem::setActive(bool active)
3388 {
3389  d_ptr->explicitActivate = 1;
3390  d_ptr->wantsActive = active;
3391  if (d_ptr->scene) {
3392  if (active) {
3393  // Activate this item.
3394  d_ptr->scene->setActivePanel(this);
3395  } else {
3396  // Deactivate this item, and reactivate the last active item
3397  // (if any).
3398  QGraphicsItem *lastActive = d_ptr->scene->d_func()->lastActivePanel;
3399  d_ptr->scene->setActivePanel(lastActive != this ? lastActive : 0);
3400  }
3401  }
3402 }
3403 
3410 {
3411  if (!d_ptr->scene || !d_ptr->scene->isActive())
3412  return false;
3413 
3414  if (d_ptr->focusProxy)
3415  return d_ptr->focusProxy->hasFocus();
3416 
3417  if (d_ptr->scene->d_func()->focusItem != this)
3418  return false;
3419 
3420  return panel() == d_ptr->scene->d_func()->activePanel;
3421 }
3422 
3443 {
3444  d_ptr->setFocusHelper(focusReason, /* climb = */ true, /* focusFromHide = */ false);
3445 }
3446 
3450 void QGraphicsItemPrivate::setFocusHelper(Qt::FocusReason focusReason, bool climb, bool focusFromHide)
3451 {
3452  // Disabled / unfocusable items cannot accept focus.
3453  if (!q_ptr->isEnabled() || !(flags & QGraphicsItem::ItemIsFocusable))
3454  return;
3455 
3456  // Find focus proxy.
3457  QGraphicsItem *f = q_ptr;
3458  while (f->d_ptr->focusProxy)
3459  f = f->d_ptr->focusProxy;
3460 
3461  // Return if it already has focus.
3462  if (scene && scene->focusItem() == f)
3463  return;
3464 
3465  // Update focus scope item ptr.
3466  QGraphicsItem *p = parent;
3467  while (p) {
3469  QGraphicsItem *oldFocusScopeItem = p->d_ptr->focusScopeItem;
3470  p->d_ptr->focusScopeItem = q_ptr;
3471  if (oldFocusScopeItem)
3472  oldFocusScopeItem->d_ptr->focusScopeItemChange(false);
3473  focusScopeItemChange(true);
3474  if (!p->focusItem() && !focusFromHide) {
3475  // Calling setFocus() on a child of a focus scope that does
3476  // not have focus changes only the focus scope pointer,
3477  // so that focus is restored the next time the scope gains
3478  // focus.
3479  return;
3480  }
3481  break;
3482  }
3483  p = p->d_ptr->parent;
3484  }
3485 
3486  if (climb) {
3487  while (f->d_ptr->focusScopeItem && f->d_ptr->focusScopeItem->isVisible())
3488  f = f->d_ptr->focusScopeItem;
3489  }
3490 
3491  // Update the child focus chain.
3492  QGraphicsItem *commonAncestor = 0;
3493  if (scene && scene->focusItem()) {
3494  commonAncestor = scene->focusItem()->commonAncestorItem(f);
3495  scene->focusItem()->d_ptr->clearSubFocus(scene->focusItem(), commonAncestor);
3496  }
3497 
3498  f->d_ptr->setSubFocus(f, commonAncestor);
3499 
3500  // Update the scene's focus item.
3501  if (scene) {
3502  QGraphicsItem *p = q_ptr->panel();
3503  if ((!p && scene->isActive()) || (p && p->isActive())) {
3504  // Visible items immediately gain focus from scene.
3505  scene->d_func()->setFocusItemHelper(f, focusReason);
3506  }
3507  }
3508 }
3509 
3522 {
3523  d_ptr->clearFocusHelper(/* giveFocusToParent = */ true);
3524 }
3525 
3529 void QGraphicsItemPrivate::clearFocusHelper(bool giveFocusToParent)
3530 {
3531  QGraphicsItem *subFocusItem = q_ptr;
3533  while (subFocusItem->d_ptr->focusScopeItem)
3534  subFocusItem = subFocusItem->d_ptr->focusScopeItem;
3535  }
3536 
3537  if (giveFocusToParent) {
3538  // Pass focus to the closest parent focus scope
3539  if (!inDestructor) {
3540  QGraphicsItem *p = parent;
3541  while (p) {
3543  if (p->d_ptr->focusScopeItem == q_ptr) {
3544  p->d_ptr->focusScopeItem = 0;
3545  if (!subFocusItem->hasFocus()) //if it has focus, focusScopeItemChange is called elsewhere
3546  focusScopeItemChange(false);
3547  }
3548  if (subFocusItem->hasFocus())
3549  p->d_ptr->setFocusHelper(Qt::OtherFocusReason, /* climb = */ false,
3550  /* focusFromHide = */ false);
3551  return;
3552  }
3553  p = p->d_ptr->parent;
3554  }
3555  }
3556  }
3557 
3558  if (subFocusItem->hasFocus()) {
3559  // Invisible items with focus must explicitly clear subfocus.
3560  clearSubFocus(q_ptr);
3561 
3562  // If this item has the scene's input focus, clear it.
3563  scene->setFocusItem(0);
3564  }
3565 }
3566 
3579 {
3580  return d_ptr->focusProxy;
3581 }
3582 
3606 {
3607  if (item == d_ptr->focusProxy)
3608  return;
3609  if (item == this) {
3610  qWarning("QGraphicsItem::setFocusProxy: cannot assign self as focus proxy");
3611  return;
3612  }
3613  if (item) {
3614  if (item->d_ptr->scene != d_ptr->scene) {
3615  qWarning("QGraphicsItem::setFocusProxy: focus proxy must be in same scene");
3616  return;
3617  }
3618  for (QGraphicsItem *f = item->focusProxy(); f != 0; f = f->focusProxy()) {
3619  if (f == this) {
3620  qWarning("QGraphicsItem::setFocusProxy: %p is already in the focus proxy chain", item);
3621  return;
3622  }
3623  }
3624  }
3625 
3626  QGraphicsItem *lastFocusProxy = d_ptr->focusProxy;
3627  if (lastFocusProxy)
3628  lastFocusProxy->d_ptr->focusProxyRefs.removeOne(&d_ptr->focusProxy);
3629  d_ptr->focusProxy = item;
3630  if (item)
3631  item->d_ptr->focusProxyRefs << &d_ptr->focusProxy;
3632 }
3633 
3647 {
3648  return d_ptr->subFocusItem;
3649 }
3650 
3660 {
3661  return d_ptr->focusScopeItem;
3662 }
3663 
3702 {
3703  if (!d_ptr->scene) {
3704  qWarning("QGraphicsItem::grabMouse: cannot grab mouse without scene");
3705  return;
3706  }
3707  if (!d_ptr->visible) {
3708  qWarning("QGraphicsItem::grabMouse: cannot grab mouse while invisible");
3709  return;
3710  }
3711  d_ptr->scene->d_func()->grabMouse(this);
3712 }
3713 
3724 {
3725  if (!d_ptr->scene) {
3726  qWarning("QGraphicsItem::ungrabMouse: cannot ungrab mouse without scene");
3727  return;
3728  }
3729  d_ptr->scene->d_func()->ungrabMouse(this);
3730 }
3731 
3770 {
3771  if (!d_ptr->scene) {
3772  qWarning("QGraphicsItem::grabKeyboard: cannot grab keyboard without scene");
3773  return;
3774  }
3775  if (!d_ptr->visible) {
3776  qWarning("QGraphicsItem::grabKeyboard: cannot grab keyboard while invisible");
3777  return;
3778  }
3779  d_ptr->scene->d_func()->grabKeyboard(this);
3780 }
3781 
3792 {
3793  if (!d_ptr->scene) {
3794  qWarning("QGraphicsItem::ungrabKeyboard: cannot ungrab keyboard without scene");
3795  return;
3796  }
3797  d_ptr->scene->d_func()->ungrabKeyboard(this);
3798 }
3799 
3814 {
3815  return d_ptr->pos;
3816 }
3817 
3841 {
3842  if (d_ptr->inDestructor)
3843  return;
3844 
3845  if (qIsNaN(x))
3846  return;
3847 
3848  setPos(QPointF(x, d_ptr->pos.y()));
3849 }
3850 
3874 {
3875  if (d_ptr->inDestructor)
3876  return;
3877 
3878  if (qIsNaN(y))
3879  return;
3880 
3881  setPos(QPointF(d_ptr->pos.x(), y));
3882 }
3883 
3891 {
3892  return mapToScene(0, 0);
3893 }
3894 
3904 {
3905  Q_Q(QGraphicsItem);
3906  inSetPosHelper = 1;
3907  if (scene)
3908  q->prepareGeometryChange();
3909  QPointF oldPos = this->pos;
3910  this->pos = pos;
3911  dirtySceneTransform = 1;
3912  inSetPosHelper = 0;
3913  if (isObject) {
3914  if (pos.x() != oldPos.x())
3915  emit static_cast<QGraphicsObject *>(q_ptr)->xChanged();
3916  if (pos.y() != oldPos.y())
3917  emit static_cast<QGraphicsObject *>(q_ptr)->yChanged();
3918  }
3919 }
3920 
3930 {
3931  q_ptr->prepareGeometryChange();
3932  transformData->transform = transform;
3933  dirtySceneTransform = 1;
3934  transformChanged();
3935 }
3936 
3948 {
3949  if (d_ptr->pos == pos)
3950  return;
3951 
3952  if (d_ptr->inDestructor)
3953  return;
3954 
3955  // Update and repositition.
3957  d_ptr->setPosHelper(pos);
3958  if (d_ptr->isWidget)
3959  static_cast<QGraphicsWidget *>(this)->d_func()->setGeometryFromSetPos();
3962  return;
3963  }
3964 
3965  // Notify the item that the position is changing.
3966  const QVariant newPosVariant(itemChange(ItemPositionChange, QVariant::fromValue<QPointF>(pos)));
3967  QPointF newPos = newPosVariant.toPointF();
3968  if (newPos == d_ptr->pos)
3969  return;
3970 
3971  // Update and repositition.
3972  d_ptr->setPosHelper(newPos);
3973 
3974  // Send post-notification.
3977 }
3978 
4015 void QGraphicsItem::ensureVisible(const QRectF &rect, int xmargin, int ymargin)
4016 {
4017  if (d_ptr->scene) {
4018  QRectF sceneRect;
4019  if (!rect.isNull())
4020  sceneRect = sceneTransform().mapRect(rect);
4021  else
4022  sceneRect = sceneBoundingRect();
4023  foreach (QGraphicsView *view, d_ptr->scene->d_func()->views)
4024  view->ensureVisible(sceneRect, xmargin, ymargin);
4025  }
4026 }
4027 
4051 {
4052  return transform().toAffine();
4053 }
4054 
4071 {
4072  if (!d_ptr->transformData)
4073  return QTransform();
4074  return d_ptr->transformData->transform;
4075 }
4076 
4092 {
4093  if (!d_ptr->transformData)
4094  return 0;
4095  return d_ptr->transformData->rotation;
4096 }
4097 
4121 {
4123  qreal newRotation = angle;
4124 
4126  // Notify the item that the rotation is changing.
4127  const QVariant newRotationVariant(itemChange(ItemRotationChange, angle));
4128  newRotation = newRotationVariant.toReal();
4129  }
4130 
4131  if (!d_ptr->transformData)
4133 
4134  if (d_ptr->transformData->rotation == newRotation)
4135  return;
4136 
4137  d_ptr->transformData->rotation = newRotation;
4138  d_ptr->transformData->onlyTransform = false;
4140 
4141  // Send post-notification.
4143  itemChange(ItemRotationHasChanged, newRotation);
4144 
4145  if (d_ptr->isObject)
4146  emit static_cast<QGraphicsObject *>(this)->rotationChanged();
4147 
4149 }
4150 
4166 {
4167  if (!d_ptr->transformData)
4168  return 1.;
4169  return d_ptr->transformData->scale;
4170 }
4171 
4193 {
4195  qreal newScale = factor;
4196 
4198  // Notify the item that the scale is changing.
4199  const QVariant newScaleVariant(itemChange(ItemScaleChange, factor));
4200  newScale = newScaleVariant.toReal();
4201  }
4202 
4203  if (!d_ptr->transformData)
4205 
4206  if (d_ptr->transformData->scale == newScale)
4207  return;
4208 
4209  d_ptr->transformData->scale = newScale;
4210  d_ptr->transformData->onlyTransform = false;
4212 
4213  // Send post-notification.
4215  itemChange(ItemScaleHasChanged, newScale);
4216 
4217  if (d_ptr->isObject)
4218  emit static_cast<QGraphicsObject *>(this)->scaleChanged();
4219 
4221 }
4222 
4223 
4243 {
4244  if (!d_ptr->transformData)
4245  return QList<QGraphicsTransform *>();
4247 }
4248 
4273 {
4275  if (!d_ptr->transformData)
4278  for (int i = 0; i < transformations.size(); ++i)
4279  transformations.at(i)->d_func()->setItem(this);
4280  d_ptr->transformData->onlyTransform = false;
4283 }
4284 
4289 {
4290  if (!transformData)
4291  transformData = new QGraphicsItemPrivate::TransformData;
4292  if (!transformData->graphicsTransforms.contains(t))
4293  transformData->graphicsTransforms.prepend(t);
4294 
4295  Q_Q(QGraphicsItem);
4296  t->d_func()->setItem(q);
4297  transformData->onlyTransform = false;
4298  dirtySceneTransform = 1;
4299  transformChanged();
4300 }
4301 
4306 {
4307  if (!transformData)
4308  transformData = new QGraphicsItemPrivate::TransformData;
4309  if (!transformData->graphicsTransforms.contains(t))
4310  transformData->graphicsTransforms.append(t);
4311 
4312  Q_Q(QGraphicsItem);
4313  t->d_func()->setItem(q);
4314  transformData->onlyTransform = false;
4315  dirtySceneTransform = 1;
4316  transformChanged();
4317 }
4318 
4332 {
4333  if (!d_ptr->transformData)
4334  return QPointF(0,0);
4336 }
4337 
4349 {
4351  QPointF newOrigin = origin;
4352 
4354  // Notify the item that the origin point is changing.
4355  const QVariant newOriginVariant(itemChange(ItemTransformOriginPointChange,
4356  QVariant::fromValue<QPointF>(origin)));
4357  newOrigin = newOriginVariant.toPointF();
4358  }
4359 
4360  if (!d_ptr->transformData)
4362 
4363  if (d_ptr->transformData->xOrigin == newOrigin.x()
4364  && d_ptr->transformData->yOrigin == newOrigin.y()) {
4365  return;
4366  }
4367 
4368  d_ptr->transformData->xOrigin = newOrigin.x();
4369  d_ptr->transformData->yOrigin = newOrigin.y();
4370  d_ptr->transformData->onlyTransform = false;
4372 
4373  // Send post-notification.
4375  itemChange(ItemTransformOriginPointHasChanged, QVariant::fromValue<QPointF>(newOrigin));
4376 }
4377 
4405 {
4407  return d_ptr->sceneTransform.toAffine();
4408 }
4409 
4410 
4432 {
4434  return d_ptr->sceneTransform;
4435 }
4436 
4464 {
4465  // Ensure we return the standard transform if we're not untransformable.
4466  if (!d_ptr->itemIsUntransformable()) {
4468  return d_ptr->sceneTransform * viewportTransform;
4469  }
4470 
4471  // Find the topmost item that ignores view transformations.
4472  const QGraphicsItem *untransformedAncestor = this;
4474  while (untransformedAncestor && ((untransformedAncestor->d_ptr->ancestorFlags
4476  parents.prepend(untransformedAncestor);
4477  untransformedAncestor = untransformedAncestor->parentItem();
4478  }
4479 
4480  if (!untransformedAncestor) {
4481  // Assert in debug mode, continue in release.
4482  Q_ASSERT_X(untransformedAncestor, "QGraphicsItem::deviceTransform",
4483  "Invalid object structure!");
4484  return QTransform();
4485  }
4486 
4487  // Determine the inherited origin. Find the parent of the topmost untransformable.
4488  // Use its scene transform to map the position of the untransformable. Then use
4489  // that viewport position as the anchoring point for the untransformable subtree.
4490  QGraphicsItem *parentOfUntransformedAncestor = untransformedAncestor->parentItem();
4491  QTransform inheritedMatrix;
4492  if (parentOfUntransformedAncestor)
4493  inheritedMatrix = parentOfUntransformedAncestor->sceneTransform();
4494  QPointF mappedPoint = (inheritedMatrix * viewportTransform).map(untransformedAncestor->pos());
4495 
4496  // COMBINE
4497  QTransform matrix = QTransform::fromTranslate(mappedPoint.x(), mappedPoint.y());
4498  if (untransformedAncestor->d_ptr->transformData)
4499  matrix = untransformedAncestor->d_ptr->transformData->computedFullTransform(&matrix);
4500 
4501  // Then transform and translate all children.
4502  for (int i = 0; i < parents.size(); ++i) {
4503  const QGraphicsItem *parent = parents.at(i);
4504  parent->d_ptr->combineTransformFromParent(&matrix);
4505  }
4506 
4507  return matrix;
4508 }
4509 
4531 {
4532  // Catch simple cases first.
4533  if (other == 0) {
4534  qWarning("QGraphicsItem::itemTransform: null pointer passed");
4535  return QTransform();
4536  }
4537  if (other == this) {
4538  if (ok)
4539  *ok = true;
4540  return QTransform();
4541  }
4542 
4543  QGraphicsItem *parent = d_ptr->parent;
4544  const QGraphicsItem *otherParent = other->d_ptr->parent;
4545 
4546  // This is other's child
4547  if (parent == other) {
4548  if (ok)
4549  *ok = true;
4550  QTransform x;
4552  return x;
4553  }
4554 
4555  // This is other's parent
4556  if (otherParent == this) {
4557  const QPointF &otherPos = other->d_ptr->pos;
4558  if (other->d_ptr->transformData) {
4559  QTransform otherToParent;
4560  other->d_ptr->combineTransformFromParent(&otherToParent);
4561  return otherToParent.inverted(ok);
4562  }
4563  if (ok)
4564  *ok = true;
4565  return QTransform::fromTranslate(-otherPos.x(), -otherPos.y());
4566  }
4567 
4568  // Siblings
4569  if (parent == otherParent) {
4570  // COMBINE
4571  const QPointF &itemPos = d_ptr->pos;
4572  const QPointF &otherPos = other->d_ptr->pos;
4573  if (!d_ptr->transformData && !other->d_ptr->transformData) {
4574  QPointF delta = itemPos - otherPos;
4575  if (ok)
4576  *ok = true;
4577  return QTransform::fromTranslate(delta.x(), delta.y());
4578  }
4579 
4580  QTransform itemToParent;
4581  d_ptr->combineTransformFromParent(&itemToParent);
4582  QTransform otherToParent;
4583  other->d_ptr->combineTransformFromParent(&otherToParent);
4584  return itemToParent * otherToParent.inverted(ok);
4585  }
4586 
4587  // Find the closest common ancestor. If the two items don't share an
4588  // ancestor, then the only way is to combine their scene transforms.
4589  const QGraphicsItem *commonAncestor = commonAncestorItem(other);
4590  if (!commonAncestor) {
4592  other->d_ptr->ensureSceneTransform();
4593  return d_ptr->sceneTransform * other->d_ptr->sceneTransform.inverted(ok);
4594  }
4595 
4596  // If the two items are cousins (in sibling branches), map both to the
4597  // common ancestor, and combine the two transforms.
4598  bool cousins = other != commonAncestor && this != commonAncestor;
4599  if (cousins) {
4600  bool good = false;
4601  QTransform thisToScene = itemTransform(commonAncestor, &good);
4602  QTransform otherToScene(Qt::Uninitialized);
4603  if (good)
4604  otherToScene = other->itemTransform(commonAncestor, &good);
4605  if (!good) {
4606  if (ok)
4607  *ok = false;
4608  return QTransform();
4609  }
4610  return thisToScene * otherToScene.inverted(ok);
4611  }
4612 
4613  // One is an ancestor of the other; walk the chain.
4614  bool parentOfOther = isAncestorOf(other);
4615  const QGraphicsItem *child = parentOfOther ? other : this;
4616  const QGraphicsItem *root = parentOfOther ? this : other;
4617 
4618  QTransform x;
4619  const QGraphicsItem *p = child;
4620  do {
4622  } while ((p = p->d_ptr->parent) && p != root);
4623  if (parentOfOther)
4624  return x.inverted(ok);
4625  if (ok)
4626  *ok = true;
4627  return x;
4628 }
4629 
4644 void QGraphicsItem::setMatrix(const QMatrix &matrix, bool combine)
4645 {
4646  if (!d_ptr->transformData)
4648 
4649  QTransform newTransform(combine ? QTransform(matrix) * d_ptr->transformData->transform : QTransform(matrix));
4650  if (d_ptr->transformData->transform == newTransform)
4651  return;
4652 
4653  // Update and set the new transformation.
4654  if (!(d_ptr->flags & ItemSendsGeometryChanges)) {
4655  d_ptr->setTransformHelper(newTransform);
4656  return;
4657  }
4658 
4659  // Notify the item that the transformation matrix is changing.
4660  const QVariant newMatrixVariant = QVariant::fromValue<QMatrix>(newTransform.toAffine());
4661  newTransform = QTransform(qvariant_cast<QMatrix>(itemChange(ItemMatrixChange, newMatrixVariant)));
4662  if (d_ptr->transformData->transform == newTransform)
4663  return;
4664 
4665  // Update and set the new transformation.
4666  d_ptr->setTransformHelper(newTransform);
4667 
4668  // Send post-notification.
4669  itemChange(ItemTransformHasChanged, QVariant::fromValue<QTransform>(newTransform));
4670 }
4671 
4697 {
4698  if (!d_ptr->transformData)
4700 
4701  QTransform newTransform(combine ? matrix * d_ptr->transformData->transform : matrix);
4702  if (d_ptr->transformData->transform == newTransform)
4703  return;
4704 
4705  // Update and set the new transformation.
4707  d_ptr->setTransformHelper(newTransform);
4710  return;
4711  }
4712 
4713  // Notify the item that the transformation matrix is changing.
4714  const QVariant newTransformVariant(itemChange(ItemTransformChange,
4715  QVariant::fromValue<QTransform>(newTransform)));
4716  newTransform = qvariant_cast<QTransform>(newTransformVariant);
4717  if (d_ptr->transformData->transform == newTransform)
4718  return;
4719 
4720  // Update and set the new transformation.
4721  d_ptr->setTransformHelper(newTransform);
4722 
4723  // Send post-notification.
4724  itemChange(ItemTransformHasChanged, newTransformVariant);
4726 }
4727 
4737 {
4738  resetTransform();
4739 }
4740 
4754 {
4755  setTransform(QTransform(), false);
4756 }
4757 
4783 {
4784  setTransform(QTransform().rotate(angle), true);
4785 }
4786 
4812 {
4813  setTransform(QTransform::fromScale(sx, sy), true);
4814 }
4815 
4835 {
4836  setTransform(QTransform().shear(sh, sv), true);
4837 }
4838 
4861 {
4862  setTransform(QTransform::fromTranslate(dx, dy), true);
4863 }
4864 
4882 void QGraphicsItem::advance(int phase)
4883 {
4884  Q_UNUSED(phase);
4885 }
4886 
4896 {
4897  return d_ptr->z;
4898 }
4899 
4915 {
4916  const QVariant newZVariant(itemChange(ItemZValueChange, z));
4917  qreal newZ = newZVariant.toReal();
4918  if (newZ == d_ptr->z)
4919  return;
4920 
4921  if (d_ptr->scene && d_ptr->scene->d_func()->indexMethod != QGraphicsScene::NoIndex) {
4922  // Z Value has changed, we have to notify the index.
4923  d_ptr->scene->d_func()->index->itemChange(this, ItemZValueChange, &newZ);
4924  }
4925 
4926  d_ptr->z = newZ;
4927  if (d_ptr->parent)
4929  else if (d_ptr->scene)
4930  d_ptr->scene->d_func()->needSortTopLevelItems = 1;
4931 
4932  if (d_ptr->scene)
4933  d_ptr->scene->d_func()->markDirty(this, QRectF(), /*invalidateChildren=*/true);
4934 
4935  itemChange(ItemZValueHasChanged, newZVariant);
4936 
4939 
4940  if (d_ptr->isObject)
4941  emit static_cast<QGraphicsObject *>(this)->zChanged();
4942 }
4943 
4957 {
4958  if (!sequentialOrdering) {
4959  qSort(children.begin(), children.end(), insertionOrder);
4960  sequentialOrdering = 1;
4961  needSortChildren = 1;
4962  }
4963  if (holesInSiblingIndex) {
4964  holesInSiblingIndex = 0;
4965  for (int i = 0; i < children.size(); ++i)
4966  children[i]->d_ptr->siblingIndex = i;
4967  }
4968 }
4969 
4974 {
4975  Q_Q(QGraphicsItem);
4976  if (scene) {
4978  q->itemChange(QGraphicsItem::ItemScenePositionHasChanged, q->scenePos());
4979  if (scenePosDescendants) {
4980  foreach (QGraphicsItem *item, scene->d_func()->scenePosItems) {
4981  if (q->isAncestorOf(item))
4983  }
4984  }
4985  }
4986 }
4987 
5008 {
5009  if (sibling == this)
5010  return;
5011  if (!sibling || d_ptr->parent != sibling->parentItem()) {
5012  qWarning("QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling);
5013  return;
5014  }
5015  QList<QGraphicsItem *> *siblings = d_ptr->parent
5016  ? &d_ptr->parent->d_ptr->children
5017  : (d_ptr->scene ? &d_ptr->scene->d_func()->topLevelItems : 0);
5018  if (!siblings) {
5019  qWarning("QGraphicsItem::stackUnder: cannot stack under %p, which must be a sibling", sibling);
5020  return;
5021  }
5022 
5023  // First, make sure that the sibling indexes have no holes. This also
5024  // marks the children list for sorting.
5025  if (d_ptr->parent)
5027  else
5028  d_ptr->scene->d_func()->ensureSequentialTopLevelSiblingIndexes();
5029 
5030  // Only move items with the same Z value, and that need moving.
5031  int siblingIndex = sibling->d_ptr->siblingIndex;
5032  int myIndex = d_ptr->siblingIndex;
5033  if (myIndex >= siblingIndex) {
5034  siblings->move(myIndex, siblingIndex);
5035  // Fixup the insertion ordering.
5036  for (int i = 0; i < siblings->size(); ++i) {
5037  int &index = siblings->at(i)->d_ptr->siblingIndex;
5038  if (i != siblingIndex && index >= siblingIndex && index <= myIndex)
5039  ++index;
5040  }
5041  d_ptr->siblingIndex = siblingIndex;
5042  for (int i = 0; i < siblings->size(); ++i) {
5043  int &index = siblings->at(i)->d_ptr->siblingIndex;
5044  if (i != siblingIndex && index >= siblingIndex && index <= myIndex)
5045  siblings->at(i)->d_ptr->siblingOrderChange();
5046  }
5048  }
5049 }
5050 
5069 {
5071  return d_ptr->childrenBoundingRect;
5072 
5076  return d_ptr->childrenBoundingRect;
5077 }
5078 
5122 {
5123  // Find translate-only offset
5124  // COMBINE
5125  QPointF offset;
5126  const QGraphicsItem *parentItem = this;
5127  const QGraphicsItemPrivate *itemd;
5128  do {
5129  itemd = parentItem->d_ptr.data();
5130  if (itemd->transformData)
5131  break;
5132  offset += itemd->pos;
5133  } while ((parentItem = itemd->parent));
5134 
5135  QRectF br = boundingRect();
5136  br.translate(offset);
5137  if (!parentItem)
5138  return br;
5139  if (parentItem->d_ptr->hasTranslateOnlySceneTransform()) {
5140  br.translate(parentItem->d_ptr->sceneTransform.dx(), parentItem->d_ptr->sceneTransform.dy());
5141  return br;
5142  }
5143  return parentItem->d_ptr->sceneTransform.mapRect(br);
5144 }
5145 
5169 {
5170  QPainterPath path;
5171  path.addRect(boundingRect());
5172  return path;
5173 }
5174 
5186 {
5187  Q_D(const QGraphicsItem);
5188  return (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren)
5189  || (d->flags & QGraphicsItem::ItemClipsToShape);
5190 }
5191 
5216 {
5217  Q_D(const QGraphicsItem);
5218  if (!isClipped())
5219  return QPainterPath();
5220 
5221  const QRectF thisBoundingRect(boundingRect());
5222  if (thisBoundingRect.isEmpty())
5223  return QPainterPath();
5224 
5225  QPainterPath clip;
5226  // Start with the item's bounding rect.
5227  clip.addRect(thisBoundingRect);
5228 
5229  if (d->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren) {
5230  const QGraphicsItem *parent = this;
5231  const QGraphicsItem *lastParent = this;
5232 
5233  // Intersect any in-between clips starting at the top and moving downwards.
5234  while ((parent = parent->d_ptr->parent)) {
5235  if (parent->d_ptr->flags & ItemClipsChildrenToShape) {
5236  // Map clip to the current parent and intersect with its shape/clipPath
5237  clip = lastParent->itemTransform(parent).map(clip);
5238  clip = clip.intersected(parent->shape());
5239  if (clip.isEmpty())
5240  return clip;
5241  lastParent = parent;
5242  }
5243 
5245  break;
5246  }
5247 
5248  if (lastParent != this) {
5249  // Map clip back to the item's transform.
5250  // ### what if itemtransform fails
5251  clip = lastParent->itemTransform(this).map(clip);
5252  }
5253  }
5254 
5255  if (d->flags & ItemClipsToShape)
5256  clip = clip.intersected(shape());
5257 
5258  return clip;
5259 }
5260 
5273 bool QGraphicsItem::contains(const QPointF &point) const
5274 {
5275  return isClipped() ? clipPath().contains(point) : shape().contains(point);
5276 }
5277 
5308 {
5309  if (other == this)
5310  return true;
5311  if (!other)
5312  return false;
5313  // The items share the same clip if their closest clipper is the same, or
5314  // if one clips the other.
5316  bool otherClips = (other->d_ptr->ancestorFlags & QGraphicsItemPrivate::AncestorClipsChildren);
5317  if (clips || otherClips) {
5318  const QGraphicsItem *closestClipper = isAncestorOf(other) ? this : parentItem();
5319  while (closestClipper && !(closestClipper->flags() & ItemClipsChildrenToShape))
5320  closestClipper = closestClipper->parentItem();
5321  const QGraphicsItem *otherClosestClipper = other->isAncestorOf(this) ? other : other->parentItem();
5322  while (otherClosestClipper && !(otherClosestClipper->flags() & ItemClipsChildrenToShape))
5323  otherClosestClipper = otherClosestClipper->parentItem();
5324  if (closestClipper == otherClosestClipper) {
5326  bool res = collidesWithPath(mapFromItem(other, other->shape()), mode);
5328  return res;
5329  }
5330  }
5331 
5332  QPainterPath otherShape = other->isClipped() ? other->clipPath() : other->shape();
5333  return collidesWithPath(mapFromItem(other, otherShape), mode);
5334 }
5335 
5351 {
5352  if (path.isEmpty()) {
5353  // No collision with empty paths.
5354  return false;
5355  }
5356 
5357  QRectF rectA(boundingRect());
5358  _q_adjustRect(&rectA);
5359  QRectF rectB(path.controlPointRect());
5360  _q_adjustRect(&rectB);
5361  if (!rectA.intersects(rectB)) {
5362  // This we can determine efficiently. If the two rects neither
5363  // intersect nor contain eachother, then the two items do not collide.
5364  return false;
5365  }
5366 
5367  // For further testing, we need this item's shape or bounding rect.
5368  QPainterPath thisShape;
5369  if (mode == Qt::IntersectsItemShape || mode == Qt::ContainsItemShape)
5370  thisShape = (isClipped() && !d_ptr->localCollisionHack) ? clipPath() : shape();
5371  else
5372  thisShape.addRect(rectA);
5373 
5374  if (thisShape == QPainterPath()) {
5375  // Empty shape? No collision.
5376  return false;
5377  }
5378 
5379  // Use QPainterPath boolean operations to determine the collision, O(N*logN).
5381  return path.intersects(thisShape);
5382  return path.contains(thisShape);
5383 }
5384 
5396 {
5397  if (d_ptr->scene)
5398  return d_ptr->scene->collidingItems(this, mode);
5399  return QList<QGraphicsItem *>();
5400 }
5401 
5413 {
5414  return isObscured(QRectF());
5415 }
5416 
5431  const QGraphicsItem *other,
5432  const QRectF &rect)
5433 {
5434  return other->mapToItem(item, other->opaqueArea()).contains(rect);
5435 }
5436 
5452 bool QGraphicsItem::isObscured(const QRectF &rect) const
5453 {
5454  Q_D(const QGraphicsItem);
5455  if (!d->scene)
5456  return false;
5457 
5458  QRectF br = boundingRect();
5459  QRectF testRect = rect.isNull() ? br : rect;
5460 
5461  foreach (QGraphicsItem *item, d->scene->items(mapToScene(br), Qt::IntersectsItemBoundingRect)) {
5462  if (item == this)
5463  break;
5464  if (qt_QGraphicsItem_isObscured(this, item, testRect))
5465  return true;
5466  }
5467  return false;
5468 }
5469 
5494 {
5495  if (!item)
5496  return false;
5497  return qt_closestItemFirst(item, this)
5498  && qt_QGraphicsItem_isObscured(this, item, boundingRect());
5499 }
5500 
5515 {
5516  return QPainterPath();
5517 }
5518 
5545 QRegion QGraphicsItem::boundingRegion(const QTransform &itemToDeviceTransform) const
5546 {
5547  // ### Ideally we would have a better way to generate this region,
5548  // preferably something in the lines of QPainterPath::toRegion(QTransform)
5549  // coupled with a way to generate a painter path from a set of painter
5550  // operations (e.g., QPicture::toPainterPath() or so). The current
5551  // approach generates a bitmap with the size of the item's bounding rect
5552  // in device coordinates, scaled by b.r.granularity, then paints the item
5553  // into the bitmap, converts the result to a QRegion and scales the region
5554  // back to device space with inverse granularity.
5555  qreal granularity = boundingRegionGranularity();
5556  QRect deviceRect = itemToDeviceTransform.mapRect(boundingRect()).toRect();
5557  _q_adjustRect(&deviceRect);
5558  if (granularity == 0.0)
5559  return QRegion(deviceRect);
5560 
5561  int pad = 1;
5562  QSize bitmapSize(qMax(1, int(deviceRect.width() * granularity) + pad * 2),
5563  qMax(1, int(deviceRect.height() * granularity) + pad * 2));
5564  QImage mask(bitmapSize, QImage::Format_ARGB32_Premultiplied);
5565  mask.fill(0);
5566  QPainter p(&mask);
5568 
5569  // Transform painter (### this code is from QGraphicsScene::drawItemHelper
5570  // and doesn't work properly with perspective transformations).
5571  QPointF viewOrigo = itemToDeviceTransform.map(QPointF(0, 0));
5572  QPointF offset = viewOrigo - deviceRect.topLeft();
5573  p.scale(granularity, granularity);
5574  p.translate(offset);
5575  p.translate(pad, pad);
5576  p.setWorldTransform(itemToDeviceTransform, true);
5577  p.translate(itemToDeviceTransform.inverted().map(QPointF(0, 0)));
5578 
5579  // Render
5580  QStyleOptionGraphicsItem option;
5581  const_cast<QGraphicsItem *>(this)->paint(&p, &option, 0);
5582  p.end();
5583 
5584  // Transform QRegion back to device space
5585  QTransform unscale = QTransform::fromScale(1 / granularity, 1 / granularity);
5586  QRegion r;
5587  QBitmap colorMask = QBitmap::fromImage(mask.createMaskFromColor(0));
5588  foreach (const QRect &rect, QRegion( colorMask ).rects()) {
5589  QRect xrect = unscale.mapRect(rect).translated(deviceRect.topLeft() - QPoint(pad, pad));
5590  r += xrect.adjusted(-1, -1, 1, 1) & deviceRect;
5591  }
5592  return r;
5593 }
5594 
5612 {
5615  : 0;
5616 }
5617 
5641 {
5642  if (granularity < 0.0 || granularity > 1.0) {
5643  qWarning("QGraphicsItem::setBoundingRegionGranularity: invalid granularity %g", granularity);
5644  return;
5645  }
5646  if (granularity == 0.0) {
5649  return;
5650  }
5653  QVariant::fromValue<qreal>(granularity));
5654 }
5655 
5697 bool QGraphicsItemPrivate::discardUpdateRequest(bool ignoreVisibleBit, bool ignoreDirtyBit,
5698  bool ignoreOpacity) const
5699 {
5700  // No scene, or if the scene is updating everything, means we have nothing
5701  // to do. The only exception is if the scene tracks the growing scene rect.
5702  return !scene
5703  || (!visible && !ignoreVisibleBit && !this->ignoreVisible)
5704  || (!ignoreDirtyBit && fullUpdatePending)
5705  || (!ignoreOpacity && !this->ignoreOpacity && childrenCombineOpacity() && isFullyTransparent());
5706 }
5707 
5712 {
5713  if (itemDepth == -1)
5714  const_cast<QGraphicsItemPrivate *>(this)->resolveDepth();
5715 
5716  return itemDepth;
5717 }
5718 
5722 #ifndef QT_NO_GRAPHICSEFFECT
5724 {
5725  QGraphicsItemPrivate *itemPrivate = this;
5726  do {
5727  if (itemPrivate->graphicsEffect && !itemPrivate->updateDueToGraphicsEffect) {
5728  itemPrivate->notifyInvalidated = 1;
5729  static_cast<QGraphicsItemEffectSourcePrivate *>(itemPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache();
5730  }
5731  } while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0));
5732 }
5733 
5735 {
5736  if (!mayHaveChildWithGraphicsEffect)
5737  return;
5738 
5739  for (int i = 0; i < children.size(); ++i) {
5740  QGraphicsItemPrivate *childPrivate = children.at(i)->d_ptr.data();
5741  if (reason == OpacityChanged && (childPrivate->flags & QGraphicsItem::ItemIgnoresParentOpacity))
5742  continue;
5743  if (childPrivate->graphicsEffect) {
5744  childPrivate->notifyInvalidated = 1;
5745  static_cast<QGraphicsItemEffectSourcePrivate *>(childPrivate->graphicsEffect->d_func()->source->d_func())->invalidateCache();
5746  }
5747 
5748  childPrivate->invalidateChildGraphicsEffectsRecursively(reason);
5749  }
5750 }
5751 #endif //QT_NO_GRAPHICSEFFECT
5752 
5757 {
5758  if (itemDepth == -1)
5759  return;
5760 
5761  itemDepth = -1;
5762  for (int i = 0; i < children.size(); ++i)
5764 }
5765 
5775 {
5776  if (!parent)
5777  itemDepth = 0;
5778  else {
5779  if (parent->d_ptr->itemDepth == -1)
5780  parent->d_ptr->resolveDepth();
5781  itemDepth = parent->d_ptr->itemDepth + 1;
5782  }
5783 }
5784 
5795 {
5796  // Remove all holes from the sibling index list. Now the max index
5797  // number is equal to the size of the children list.
5798  ensureSequentialSiblingIndex();
5799  needSortChildren = 1; // ### maybe 0
5800  child->d_ptr->siblingIndex = children.size();
5801  children.append(child);
5802  if (isObject)
5803  emit static_cast<QGraphicsObject *>(q_ptr)->childrenChanged();
5804 }
5805 
5816 {
5817  // When removing elements in the middle of the children list,
5818  // there will be a "gap" in the list of sibling indexes (0,1,3,4).
5819  if (!holesInSiblingIndex)
5820  holesInSiblingIndex = child->d_ptr->siblingIndex != children.size() - 1;
5821  if (sequentialOrdering && !holesInSiblingIndex)
5823  else
5824  children.removeOne(child);
5825  // NB! Do not use children.removeAt(child->d_ptr->siblingIndex) because
5826  // the child is not guaranteed to be at the index after the list is sorted.
5827  // (see ensureSortedChildren()).
5828  child->d_ptr->siblingIndex = -1;
5829  if (isObject)
5830  emit static_cast<QGraphicsObject *>(q_ptr)->childrenChanged();
5831 }
5832 
5837 {
5838  return (QGraphicsItemCache *)qvariant_cast<void *>(extra(ExtraCacheData));
5839 }
5840 
5845 {
5846  QGraphicsItemCache *c = (QGraphicsItemCache *)qvariant_cast<void *>(extra(ExtraCacheData));
5847  if (!c) {
5848  QGraphicsItemPrivate *that = const_cast<QGraphicsItemPrivate *>(this);
5849  c = new QGraphicsItemCache;
5850  that->setExtra(ExtraCacheData, QVariant::fromValue<void *>(c));
5851  }
5852  return c;
5853 }
5854 
5859 {
5860  QGraphicsItemCache *c = (QGraphicsItemCache *)qvariant_cast<void *>(extra(ExtraCacheData));
5861  if (c) {
5862  c->purge();
5863  delete c;
5864  }
5865  unsetExtra(ExtraCacheData);
5866 }
5867 
5869 {
5870  if (!scene)
5871  return;
5872 
5873  for (int i = 0; i < scene->d_func()->views.size(); ++i) {
5874  QGraphicsViewPrivate *viewPrivate = scene->d_func()->views.at(i)->d_func();
5875  QRect rect = paintedViewBoundingRects.value(viewPrivate->viewport);
5876  rect.translate(viewPrivate->dirtyScrollOffset);
5877  viewPrivate->updateRect(rect);
5878  }
5879 
5880  if (updateChildren) {
5881  for (int i = 0; i < children.size(); ++i)
5883  }
5884 }
5885 
5886 // Traverses all the ancestors up to the top-level and updates the pointer to
5887 // always point to the top-most item that has a dirty scene transform.
5888 // It then backtracks to the top-most dirty item and start calculating the
5889 // scene transform by combining the item's transform (+pos) with the parent's
5890 // cached scene transform (which we at this point know for sure is valid).
5892 {
5893  Q_ASSERT(topMostDirtyItem);
5894 
5895  if (dirtySceneTransform)
5896  *topMostDirtyItem = q_ptr;
5897 
5898  if (parent)
5899  parent->d_ptr->ensureSceneTransformRecursive(topMostDirtyItem);
5900 
5901  if (*topMostDirtyItem == q_ptr) {
5902  if (!dirtySceneTransform)
5903  return; // OK, neither my ancestors nor I have dirty scene transforms.
5904  *topMostDirtyItem = 0;
5905  } else if (*topMostDirtyItem) {
5906  return; // Continue backtrack.
5907  }
5908 
5909  // This item and all its descendants have dirty scene transforms.
5910  // We're about to validate this item's scene transform, so we have to
5911  // invalidate all the children; otherwise there's no way for the descendants
5912  // to detect that the ancestor has changed.
5913  invalidateChildrenSceneTransform();
5914 
5915  // COMBINE my transform with the parent's scene transform.
5916  updateSceneTransformFromParent();
5917  Q_ASSERT(!dirtySceneTransform);
5918 }
5919 
5924 {
5925  // Update focus child chain. Stop at panels, or if this item
5926  // is hidden, stop at the first item with a visible parent.
5927  QGraphicsItem *parent = rootItem ? rootItem : q_ptr;
5928  if (parent->panel() != q_ptr->panel())
5929  return;
5930 
5931  do {
5932  // Clear any existing ancestor's subFocusItem.
5933  if (parent != q_ptr && parent->d_ptr->subFocusItem) {
5934  if (parent->d_ptr->subFocusItem == q_ptr)
5935  break;
5936  parent->d_ptr->subFocusItem->d_ptr->clearSubFocus(0, stopItem);
5937  }
5938  parent->d_ptr->subFocusItem = q_ptr;
5939  parent->d_ptr->subFocusItemChange();
5940  } while (!parent->isPanel() && (parent = parent->d_ptr->parent) && (visible || !parent->d_ptr->visible));
5941 
5942  if (scene && !scene->isActive()) {
5943  scene->d_func()->passiveFocusItem = subFocusItem;
5944  scene->d_func()->lastFocusItem = subFocusItem;
5945  }
5946 }
5947 
5952 {
5953  // Reset sub focus chain.
5954  QGraphicsItem *parent = rootItem ? rootItem : q_ptr;
5955  do {
5956  if (parent->d_ptr->subFocusItem != q_ptr)
5957  break;
5958  parent->d_ptr->subFocusItem = 0;
5959  if (parent != stopItem && !parent->isAncestorOf(stopItem))
5960  parent->d_ptr->subFocusItemChange();
5961  } while (!parent->isPanel() && (parent = parent->d_ptr->parent));
5962 }
5963 
5974 {
5975  for (int i = 0; i < focusProxyRefs.size(); ++i)
5976  *focusProxyRefs.at(i) = 0;
5977  focusProxyRefs.clear();
5978 }
5979 
5990 {
5991 }
5992 
6003 {
6004  Q_UNUSED(isSubFocusItem);
6005 }
6006 
6017 {
6018 }
6019 
6026 {
6027  return false;
6028 }
6029 
6049 {
6050  if (rect.isEmpty() && !rect.isNull())
6051  return;
6052 
6053  // Make sure we notify effects about invalidated source.
6054 #ifndef QT_NO_GRAPHICSEFFECT
6056 #endif //QT_NO_GRAPHICSEFFECT
6057 
6058 #ifndef QT_NO_GRAPHICSEFFECT
6060 #endif
6061  if (CacheMode(d_ptr->cacheMode) != NoCache) {
6062  // Invalidate cache.
6064  if (!cache->allExposed) {
6065  if (rect.isNull()) {
6066  cache->allExposed = true;
6067  cache->exposed.clear();
6068  } else {
6069  cache->exposed.append(rect);
6070  }
6071  }
6072  // Only invalidate cache; item is already dirty.
6073  if (d_ptr->fullUpdatePending)
6074  return;
6075  }
6076 #ifndef QT_NO_GRAPHICSEFFECT
6077  }
6078 #endif
6079 
6080  if (d_ptr->scene)
6081  d_ptr->scene->d_func()->markDirty(this, rect);
6082 }
6083 
6114 void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect)
6115 {
6116  Q_D(QGraphicsItem);
6117  if (dx == 0.0 && dy == 0.0)
6118  return;
6119  if (!d->scene)
6120  return;
6121 
6122  // Accelerated scrolling means moving pixels from one location to another
6123  // and only redraw the newly exposed area. The following requirements must
6124  // be fulfilled in order to do that:
6125  //
6126  // 1) Item is opaque.
6127  // 2) Item is not overlapped by other items.
6128  //
6129  // There's (yet) no way to detect whether an item is opaque or not, which means
6130  // we cannot do accelerated scrolling unless the cache is enabled. In case of using
6131  // DeviceCoordinate cache we also have to take the device transform into account in
6132  // order to determine whether we can do accelerated scrolling or not. That's left out
6133  // for simplicity here, but it is definitely something we can consider in the future
6134  // as a performance improvement.
6135  if (d->cacheMode != QGraphicsItem::ItemCoordinateCache
6136  || !qFuzzyIsNull(dx - int(dx)) || !qFuzzyIsNull(dy - int(dy))) {
6137  update(rect);
6138  return;
6139  }
6140 
6141  QGraphicsItemCache *cache = d->extraItemCache();
6142  if (cache->allExposed || cache->fixedSize.isValid()) {
6143  // Cache is either invalidated or item is scaled (see QGraphicsItem::setCacheMode).
6144  update(rect);
6145  return;
6146  }
6147 
6148  // Find pixmap in cache.
6149  QPixmap cachedPixmap;
6150  if (!QPixmapCache::find(cache->key, &cachedPixmap)) {
6151  update(rect);
6152  return;
6153  }
6154 
6155  QRect scrollRect = (rect.isNull() ? boundingRect() : rect).toAlignedRect();
6156  if (!scrollRect.intersects(cache->boundingRect))
6157  return; // Nothing to scroll.
6158 
6159  // Remove from cache to avoid deep copy when modifying.
6160  QPixmapCache::remove(cache->key);
6161 
6162  QRegion exposed;
6163  cachedPixmap.scroll(dx, dy, scrollRect.translated(-cache->boundingRect.topLeft()), &exposed);
6164 
6165  // Reinsert into cache.
6166  cache->key = QPixmapCache::insert(cachedPixmap);
6167 
6168  // Translate the existing expose.
6169  for (int i = 0; i < cache->exposed.size(); ++i) {
6170  QRectF &e = cache->exposed[i];
6171  if (!rect.isNull() && !e.intersects(rect))
6172  continue;
6173  e.translate(dx, dy);
6174  }
6175 
6176  // Append newly exposed areas. Note that the exposed region is currently
6177  // in pixmap coordinates, so we have to translate it to item coordinates.
6178  exposed.translate(cache->boundingRect.topLeft());
6179  const QVector<QRect> exposedRects = exposed.rects();
6180  for (int i = 0; i < exposedRects.size(); ++i)
6181  cache->exposed += exposedRects.at(i);
6182 
6183  // Trigger update. This will redraw the newly exposed area and make sure
6184  // the pixmap is re-blitted in case there are overlapping items.
6185  d->scene->d_func()->markDirty(this, rect);
6186 }
6187 
6208 QPointF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPointF &point) const
6209 {
6210  if (item)
6211  return itemTransform(item).map(point);
6212  return mapToScene(point);
6213 }
6214 
6232 {
6233  // COMBINE
6234  if (!d_ptr->transformData)
6235  return point + d_ptr->pos;
6236  return d_ptr->transformToParent().map(point);
6237 }
6238 
6258 {
6260  return QPointF(point.x() + d_ptr->sceneTransform.dx(), point.y() + d_ptr->sceneTransform.dy());
6261  return d_ptr->sceneTransform.map(point);
6262 }
6263 
6285 {
6286  if (item)
6287  return itemTransform(item).map(rect);
6288  return mapToScene(rect);
6289 }
6290 
6308 {
6309  // COMBINE
6310  if (!d_ptr->transformData)
6311  return rect.translated(d_ptr->pos);
6312  return d_ptr->transformToParent().map(rect);
6313 }
6314 
6333 {
6335  return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
6336  return d_ptr->sceneTransform.map(rect);
6337 }
6338 
6365 {
6366  if (item)
6367  return itemTransform(item).mapRect(rect);
6368  return mapRectToScene(rect);
6369 }
6370 
6392 {
6393  // COMBINE
6394  if (!d_ptr->transformData)
6395  return rect.translated(d_ptr->pos);
6396  return d_ptr->transformToParent().mapRect(rect);
6397 }
6398 
6423 {
6425  return rect.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
6426  return d_ptr->sceneTransform.mapRect(rect);
6427 }
6428 
6455 {
6456  if (item)
6457  return item->itemTransform(this).mapRect(rect);
6458  return mapRectFromScene(rect);
6459 }
6460 
6483 {
6484  // COMBINE
6485  if (!d_ptr->transformData)
6486  return rect.translated(-d_ptr->pos);
6487  return d_ptr->transformToParent().inverted().mapRect(rect);
6488 }
6489 
6514 {
6516  return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6517  return d_ptr->sceneTransform.inverted().mapRect(rect);
6518 }
6519 
6539 QPolygonF QGraphicsItem::mapToItem(const QGraphicsItem *item, const QPolygonF &polygon) const
6540 {
6541  if (item)
6542  return itemTransform(item).map(polygon);
6543  return mapToScene(polygon);
6544 }
6545 
6556 {
6557  // COMBINE
6558  if (!d_ptr->transformData)
6559  return polygon.translated(d_ptr->pos);
6560  return d_ptr->transformToParent().map(polygon);
6561 }
6562 
6571 {
6573  return polygon.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
6574  return d_ptr->sceneTransform.map(polygon);
6575 }
6576 
6587 {
6588  if (item)
6589  return itemTransform(item).map(path);
6590  return mapToScene(path);
6591 }
6592 
6603 {
6604  // COMBINE
6605  if (!d_ptr->transformData)
6606  return path.translated(d_ptr->pos);
6607  return d_ptr->transformToParent().map(path);
6608 }
6609 
6618 {
6620  return path.translated(d_ptr->sceneTransform.dx(), d_ptr->sceneTransform.dy());
6621  return d_ptr->sceneTransform.map(path);
6622 }
6623 
6634 {
6635  if (item)
6636  return item->itemTransform(this).map(point);
6637  return mapFromScene(point);
6638 }
6639 
6657 {
6658  // COMBINE
6659  if (d_ptr->transformData)
6660  return d_ptr->transformToParent().inverted().map(point);
6661  return point - d_ptr->pos;
6662 }
6663 
6684 {
6686  return QPointF(point.x() - d_ptr->sceneTransform.dx(), point.y() - d_ptr->sceneTransform.dy());
6687  return d_ptr->sceneTransform.inverted().map(point);
6688 }
6689 
6712 {
6713  if (item)
6714  return item->itemTransform(this).map(rect);
6715  return mapFromScene(rect);
6716 }
6717 
6734 {
6735  // COMBINE
6736  if (!d_ptr->transformData)
6737  return rect.translated(-d_ptr->pos);
6738  return d_ptr->transformToParent().inverted().map(rect);
6739 }
6740 
6760 {
6762  return rect.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6763  return d_ptr->sceneTransform.inverted().map(rect);
6764 }
6765 
6786 {
6787  if (item)
6788  return item->itemTransform(this).map(polygon);
6789  return mapFromScene(polygon);
6790 }
6791 
6800 {
6801  // COMBINE
6802  if (!d_ptr->transformData)
6803  return polygon.translated(-d_ptr->pos);
6804  return d_ptr->transformToParent().inverted().map(polygon);
6805 }
6806 
6815 {
6817  return polygon.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6818  return d_ptr->sceneTransform.inverted().map(polygon);
6819 }
6820 
6831 {
6832  if (item)
6833  return item->itemTransform(this).map(path);
6834  return mapFromScene(path);
6835 }
6836 
6845 {
6846  // COMBINE
6847  if (!d_ptr->transformData)
6848  return path.translated(-d_ptr->pos);
6849  return d_ptr->transformToParent().inverted().map(path);
6850 }
6851 
6860 {
6862  return path.translated(-d_ptr->sceneTransform.dx(), -d_ptr->sceneTransform.dy());
6863  return d_ptr->sceneTransform.inverted().map(path);
6864 }
6865 
6873 {
6874  if (!child || child == this)
6875  return false;
6876  if (child->d_ptr->depth() < d_ptr->depth())
6877  return false;
6878  const QGraphicsItem *ancestor = child;
6879  while ((ancestor = ancestor->d_ptr->parent)) {
6880  if (ancestor == this)
6881  return true;
6882  }
6883  return false;
6884 }
6885 
6898 {
6899  if (!other)
6900  return 0;
6901  if (other == this)
6902  return const_cast<QGraphicsItem *>(this);
6903  const QGraphicsItem *thisw = this;
6904  const QGraphicsItem *otherw = other;
6905  int thisDepth = d_ptr->depth();
6906  int otherDepth = other->d_ptr->depth();
6907  while (thisDepth > otherDepth) {
6908  thisw = thisw->d_ptr->parent;
6909  --thisDepth;
6910  }
6911  while (otherDepth > thisDepth) {
6912  otherw = otherw->d_ptr->parent;
6913  --otherDepth;
6914  }
6915  while (thisw && thisw != otherw) {
6916  thisw = thisw->d_ptr->parent;
6917  otherw = otherw->d_ptr->parent;
6918  }
6919  return const_cast<QGraphicsItem *>(thisw);
6920 }
6921 
6933 {
6934  Q_D(const QGraphicsItem);
6935  if (!d->scene)
6936  return false;
6937 
6938  QPoint cursorPos = QCursor::pos();
6939  foreach (QGraphicsView *view, d->scene->views()) {
6940  if (contains(mapFromScene(view->mapToScene(view->mapFromGlobal(cursorPos)))))
6941  return true;
6942  }
6943  return false;
6944 }
6945 
6960 {
6961  QGraphicsItemCustomDataStore *store = qt_dataStore();
6962  if (!store->data.contains(this))
6963  return QVariant();
6964  return store->data.value(this).value(key);
6965 }
6966 
6976 void QGraphicsItem::setData(int key, const QVariant &value)
6977 {
6978  qt_dataStore()->data[this][key] = value;
6979 }
6980 
7014 {
7015  return (int)UserType;
7016 }
7017 
7038 {
7039  if (!d_ptr->scene) {
7040  qWarning("QGraphicsItem::installSceneEventFilter: event filters can only be installed"
7041  " on items in a scene.");
7042  return;
7043  }
7044  if (d_ptr->scene != filterItem->scene()) {
7045  qWarning("QGraphicsItem::installSceneEventFilter: event filters can only be installed"
7046  " on items in the same scene.");
7047  return;
7048  }
7049  d_ptr->scene->d_func()->installSceneEventFilter(this, filterItem);
7050 }
7051 
7058 {
7059  if (!d_ptr->scene || d_ptr->scene != filterItem->scene())
7060  return;
7061  d_ptr->scene->d_func()->removeSceneEventFilter(this, filterItem);
7062 }
7063 
7081 {
7082  Q_UNUSED(watched);
7083  Q_UNUSED(event);
7084  return false;
7085 }
7086 
7102 {
7104  if (event->type() == QEvent::HoverEnter || event->type() == QEvent::HoverLeave
7105  || event->type() == QEvent::DragEnter || event->type() == QEvent::DragLeave) {
7106  // Hover enter and hover leave events for children are ignored;
7107  // hover move events are forwarded.
7108  return true;
7109  }
7110 
7111  QGraphicsItem *handler = this;
7112  do {
7113  handler = handler->d_ptr->parent;
7114  Q_ASSERT(handler);
7116  // Forward the event to the closest parent that handles child
7117  // events, mapping existing item-local coordinates to its
7118  // coordinate system.
7119  d_ptr->remapItemPos(event, handler);
7120  handler->sceneEvent(event);
7121  return true;
7122  }
7123 
7124  if (event->type() == QEvent::FocusOut) {
7125  focusOutEvent(static_cast<QFocusEvent *>(event));
7126  return true;
7127  }
7128 
7129  if (!d_ptr->visible) {
7130  // Eaten
7131  return true;
7132  }
7133 
7134  switch (event->type()) {
7135  case QEvent::FocusIn:
7136  focusInEvent(static_cast<QFocusEvent *>(event));
7137  break;
7139  contextMenuEvent(static_cast<QGraphicsSceneContextMenuEvent *>(event));
7140  break;
7142  dragEnterEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
7143  break;
7145  dragMoveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
7146  break;
7148  dragLeaveEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
7149  break;
7151  dropEvent(static_cast<QGraphicsSceneDragDropEvent *>(event));
7152  break;
7154  hoverEnterEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
7155  break;
7157  hoverMoveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
7158  break;
7160  hoverLeaveEvent(static_cast<QGraphicsSceneHoverEvent *>(event));
7161  break;
7163  mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
7164  break;
7166  mousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
7167  break;
7169  mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
7170  break;
7172  mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
7173  break;
7175  wheelEvent(static_cast<QGraphicsSceneWheelEvent *>(event));
7176  break;
7177  case QEvent::KeyPress: {
7178  QKeyEvent *k = static_cast<QKeyEvent *>(event);
7179  if (k->key() == Qt::Key_Tab || k->key() == Qt::Key_Backtab) {
7180  if (!(k->modifiers() & (Qt::ControlModifier | Qt::AltModifier))) { //### Add MetaModifier?
7181  bool res = false;
7182  if (k->key() == Qt::Key_Backtab
7183  || (k->key() == Qt::Key_Tab && (k->modifiers() & Qt::ShiftModifier))) {
7184  if (d_ptr->isWidget) {
7185  res = static_cast<QGraphicsWidget *>(this)->focusNextPrevChild(false);
7186  } else if (d_ptr->scene) {
7187  res = d_ptr->scene->focusNextPrevChild(false);
7188  }
7189  } else if (k->key() == Qt::Key_Tab) {
7190  if (d_ptr->isWidget) {
7191  res = static_cast<QGraphicsWidget *>(this)->focusNextPrevChild(true);
7192  } else if (d_ptr->scene) {
7193  res = d_ptr->scene->focusNextPrevChild(true);
7194  }
7195  }
7196  if (!res)
7197  event->ignore();
7198  return true;
7199  }
7200  }
7201  keyPressEvent(static_cast<QKeyEvent *>(event));
7202  break;
7203  }
7204  case QEvent::KeyRelease:
7205  keyReleaseEvent(static_cast<QKeyEvent *>(event));
7206  break;
7207  case QEvent::InputMethod:
7208  inputMethodEvent(static_cast<QInputMethodEvent *>(event));
7209  break;
7212  // Propagate panel activation.
7213  if (d_ptr->scene) {
7214  for (int i = 0; i < d_ptr->children.size(); ++i) {
7215  QGraphicsItem *child = d_ptr->children.at(i);
7216  if (child->isVisible() && !child->isPanel()) {
7218  d_ptr->scene->sendEvent(child, event);
7219  }
7220  }
7221  }
7222  break;
7223  default:
7224  return false;
7225  }
7226 
7227  return true;
7228 }
7229 
7249 {
7250  event->ignore();
7251 }
7252 
7277 {
7278  Q_D(QGraphicsItem);
7279  // binary compatibility workaround between 4.4 and 4.5
7280  if (d->isProxyWidget())
7281  static_cast<QGraphicsProxyWidget*>(this)->dragEnterEvent(event);
7282 }
7283 
7301 {
7302  Q_D(QGraphicsItem);
7303  // binary compatibility workaround between 4.4 and 4.5
7304  if (d->isProxyWidget())
7305  static_cast<QGraphicsProxyWidget*>(this)->dragLeaveEvent(event);
7306 }
7307 
7328 {
7329  Q_D(QGraphicsItem);
7330  // binary compatibility workaround between 4.4 and 4.5
7331  if (d->isProxyWidget())
7332  static_cast<QGraphicsProxyWidget*>(this)->dragMoveEvent(event);
7333 }
7334 
7350 {
7351  Q_D(QGraphicsItem);
7352  // binary compatibility workaround between 4.4 and 4.5
7353  if (d->isProxyWidget())
7354  static_cast<QGraphicsProxyWidget*>(this)->dropEvent(event);
7355 }
7356 
7365 {
7366  Q_UNUSED(event);
7367  update();
7368 }
7369 
7377 {
7378  Q_UNUSED(event);
7379  update();
7380 }
7381 
7392 {
7393  Q_UNUSED(event);
7394  update();
7395 }
7396 
7406 {
7407  Q_UNUSED(event);
7408 }
7409 
7420 {
7421  Q_UNUSED(event);
7422  update();
7423 }
7424 
7438 {
7439  event->ignore();
7440 }
7441 
7455 {
7456  event->ignore();
7457 }
7458 
7493 {
7494  if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {
7495  bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0;
7496  if (!multiSelect) {
7497  if (!d_ptr->selected) {
7498  if (QGraphicsScene *scene = d_ptr->scene) {
7499  ++scene->d_func()->selectionChanging;
7500  scene->clearSelection();
7501  --scene->d_func()->selectionChanging;
7502  }
7503  setSelected(true);
7504  }
7505  }
7506  } else if (!(flags() & ItemIsMovable)) {
7507  event->ignore();
7508  }
7509  if (d_ptr->isWidget) {
7510  // Qt::Popup closes when you click outside.
7511  QGraphicsWidget *w = static_cast<QGraphicsWidget *>(this);
7512  if ((w->windowFlags() & Qt::Popup) == Qt::Popup) {
7513  event->accept();
7514  if (!w->rect().contains(event->pos()))
7515  w->close();
7516  }
7517  }
7518 }
7519 
7524 {
7525  const QGraphicsItem *parent = item->parentItem();
7526  return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent));
7527 }
7528 
7530 {
7531  const QGraphicsItem *parent = item->d_ptr->parent;
7532  return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent));
7533 }
7534 
7557 {
7558  if ((event->buttons() & Qt::LeftButton) && (flags() & ItemIsMovable)) {
7559  // Determine the list of items that need to be moved.
7560  QList<QGraphicsItem *> selectedItems;
7561  QMap<QGraphicsItem *, QPointF> initialPositions;
7562  if (d_ptr->scene) {
7563  selectedItems = d_ptr->scene->selectedItems();
7564  initialPositions = d_ptr->scene->d_func()->movingItemsInitialPositions;
7565  if (initialPositions.isEmpty()) {
7566  foreach (QGraphicsItem *item, selectedItems)
7567  initialPositions[item] = item->pos();
7568  initialPositions[this] = pos();
7569  }
7570  d_ptr->scene->d_func()->movingItemsInitialPositions = initialPositions;
7571  }
7572 
7573  // Find the active view.
7574  QGraphicsView *view = 0;
7575  if (event->widget())
7576  view = qobject_cast<QGraphicsView *>(event->widget()->parentWidget());
7577 
7578  // Move all selected items
7579  int i = 0;
7580  bool movedMe = false;
7581  while (i <= selectedItems.size()) {
7582  QGraphicsItem *item = 0;
7583  if (i < selectedItems.size())
7584  item = selectedItems.at(i);
7585  else
7586  item = this;
7587  if (item == this) {
7588  // Slightly clumsy-looking way to ensure that "this" is part
7589  // of the list of items to move, this is to avoid allocations
7590  // (appending this item to the list of selected items causes a
7591  // detach).
7592  if (movedMe)
7593  break;
7594  movedMe = true;
7595  }
7596 
7598  QPointF currentParentPos;
7599  QPointF buttonDownParentPos;
7601  // Items whose ancestors ignore transformations need to
7602  // map screen coordinates to local coordinates, then map
7603  // those to the parent.
7604  QTransform viewToItemTransform = (item->deviceTransform(view->viewportTransform())).inverted();
7605  currentParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->screenPos()))));
7606  buttonDownParentPos = mapToParent(viewToItemTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton)))));
7607  } else if (item->flags() & ItemIgnoresTransformations) {
7608  // Root items that ignore transformations need to
7609  // calculate their diff by mapping viewport coordinates
7610  // directly to parent coordinates.
7611  // COMBINE
7613  if (item->d_ptr->transformData)
7614  itemTransform = item->d_ptr->transformData->computedFullTransform();
7615  itemTransform.translate(item->d_ptr->pos.x(), item->d_ptr->pos.y());
7616  QTransform viewToParentTransform = itemTransform
7617  * (item->sceneTransform() * view->viewportTransform()).inverted();
7618  currentParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->screenPos())));
7619  buttonDownParentPos = viewToParentTransform.map(QPointF(view->mapFromGlobal(event->buttonDownScreenPos(Qt::LeftButton))));
7620  } else {
7621  // All other items simply map from the scene.
7622  currentParentPos = item->mapToParent(item->mapFromScene(event->scenePos()));
7623  buttonDownParentPos = item->mapToParent(item->mapFromScene(event->buttonDownScenePos(Qt::LeftButton)));
7624  }
7625 
7626  item->setPos(initialPositions.value(item) + currentParentPos - buttonDownParentPos);
7627 
7628  if (item->flags() & ItemIsSelectable)
7629  item->setSelected(true);
7630  }
7631  ++i;
7632  }
7633 
7634  } else {
7635  event->ignore();
7636  }
7637 }
7638 
7659 {
7660  if (event->button() == Qt::LeftButton && (flags() & ItemIsSelectable)) {
7661  bool multiSelect = (event->modifiers() & Qt::ControlModifier) != 0;
7662  if (event->scenePos() == event->buttonDownScenePos(Qt::LeftButton)) {
7663  // The item didn't move
7664  if (multiSelect) {
7665  setSelected(!isSelected());
7666  } else {
7667  bool selectionChanged = false;
7668  if (QGraphicsScene *scene = d_ptr->scene) {
7669  ++scene->d_func()->selectionChanging;
7670  // Clear everything but this item. Bypass
7671  // QGraphicsScene::clearSelection()'s default behavior by
7672  // temporarily removing this item from the selection list.
7673  if (d_ptr->selected) {
7674  scene->d_func()->selectedItems.remove(this);
7675  foreach (QGraphicsItem *item, scene->d_func()->selectedItems) {
7676  if (item->isSelected()) {
7677  selectionChanged = true;
7678  break;
7679  }
7680  }
7681  }
7682  scene->clearSelection();
7683  if (d_ptr->selected)
7684  scene->d_func()->selectedItems.insert(this);
7685  --scene->d_func()->selectionChanging;
7686  if (selectionChanged)
7688  }
7689  setSelected(true);
7690  }
7691  }
7692  }
7693  if (d_ptr->scene && !event->buttons())
7694  d_ptr->scene->d_func()->movingItemsInitialPositions.clear();
7695 }
7696 
7722 {
7723  mousePressEvent(event);
7724 }
7725 
7741 {
7742  event->ignore();
7743 }
7744 
7753 {
7754  event->ignore();
7755 }
7756 
7767 {
7768  if (isWidget()) {
7769  // ### Qt 5: Remove. The reimplementation in
7770  // QGraphicsProxyWidget solves this problem (but requires a
7771  // recompile to take effect).
7772  return d_ptr->inputMethodQueryHelper(query);
7773  }
7774 
7775  Q_UNUSED(query);
7776  return QVariant();
7777 }
7778 
7793 Qt::InputMethodHints QGraphicsItem::inputMethodHints() const
7794 {
7795  Q_D(const QGraphicsItem);
7796  return d->imHints;
7797 }
7798 
7806 void QGraphicsItem::setInputMethodHints(Qt::InputMethodHints hints)
7807 {
7808  Q_D(QGraphicsItem);
7809  d->imHints = hints;
7810  if (!hasFocus())
7811  return;
7812  d->scene->d_func()->updateInputMethodSensitivityInViews();
7813 #if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
7815  if (!fw)
7816  return;
7817  for (int i = 0 ; i < scene()->views().count() ; ++i)
7818  if (scene()->views().at(i) == fw)
7819  if (QInputContext *inputContext = fw->inputContext())
7820  inputContext->update();
7821 #endif
7822 }
7823 
7832 {
7833 #if !defined(QT_NO_IM) && (defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN))
7834  if (QWidget *fw = QApplication::focusWidget()) {
7835  if (scene()) {
7836  for (int i = 0 ; i < scene()->views().count() ; ++i) {
7837  if (scene()->views().at(i) == fw) {
7838  if (QInputContext *inputContext = fw->inputContext()) {
7839  inputContext->update();
7840 #ifndef QT_NO_ACCESSIBILITY
7841  // ##### is this correct
7842  if (toGraphicsObject())
7844 #endif
7845  break;
7846  }
7847  }
7848  }
7849  }
7850  }
7851 #endif
7852 }
7853 
7876 {
7877  Q_UNUSED(change);
7878  return value;
7879 }
7880 
7891 {
7892  Q_UNUSED(extension);
7893  return false;
7894 }
7895 
7906 {
7907  Q_UNUSED(extension);
7908  Q_UNUSED(variant);
7909 }
7910 
7921 {
7922  Q_UNUSED(variant);
7923  return QVariant();
7924 }
7925 
7937 {
7939  // ### add to child index only if applicable
7940  return;
7941  }
7942  if (d_ptr->scene)
7943  d_ptr->scene->d_func()->index->addItem(this);
7944 }
7945 
7957 {
7959  // ### remove from child index only if applicable
7960  return;
7961  }
7962  if (d_ptr->scene)
7963  d_ptr->scene->d_func()->index->removeItem(this);
7964 }
7965 
7980 {
7981  if (d_ptr->inDestructor)
7982  return;
7983  if (d_ptr->scene) {
7984  d_ptr->scene->d_func()->dirtyGrowingItemsBoundingRect = true;
7985  d_ptr->geometryChanged = 1;
7988 
7989  QGraphicsScenePrivate *scenePrivate = d_ptr->scene->d_func();
7990  scenePrivate->index->prepareBoundingRectChange(this);
7991  scenePrivate->markDirty(this, QRectF(), /*invalidateChildren=*/true, /*force=*/false,
7992  /*ignoreOpacity=*/ false, /*removingItemFromScene=*/ false,
7993  /*updateBoundingRect=*/true);
7994 
7995  // For compatibility reasons, we have to update the item's old geometry
7996  // if someone is connected to the changed signal or the scene has no views.
7997  // Note that this has to be done *after* markDirty to ensure that
7998  // _q_processDirtyItems is called before _q_emitUpdated.
7999  if (scenePrivate->isSignalConnected(scenePrivate->changedSignalIndex)
8000  || scenePrivate->views.isEmpty()) {
8002  d_ptr->scene->update(boundingRect().translated(d_ptr->sceneTransform.dx(),
8003  d_ptr->sceneTransform.dy()));
8004  } else {
8006  }
8007  }
8008  }
8009 
8010  d_ptr->markParentDirty(/*updateBoundingRect=*/true);
8011 }
8012 
8025  QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option)
8026 {
8027  const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1));
8028  if (qFuzzyIsNull(qMax(murect.width(), murect.height())))
8029  return;
8030 
8031  const QRectF mbrect = painter->transform().mapRect(item->boundingRect());
8032  if (qMin(mbrect.width(), mbrect.height()) < qreal(1.0))
8033  return;
8034 
8035  qreal itemPenWidth;
8036  switch (item->type()) {
8038  itemPenWidth = static_cast<QGraphicsEllipseItem *>(item)->pen().widthF();
8039  break;
8041  itemPenWidth = static_cast<QGraphicsPathItem *>(item)->pen().widthF();
8042  break;
8044  itemPenWidth = static_cast<QGraphicsPolygonItem *>(item)->pen().widthF();
8045  break;
8047  itemPenWidth = static_cast<QGraphicsRectItem *>(item)->pen().widthF();
8048  break;
8050  itemPenWidth = static_cast<QGraphicsSimpleTextItem *>(item)->pen().widthF();
8051  break;
8053  itemPenWidth = static_cast<QGraphicsLineItem *>(item)->pen().widthF();
8054  break;
8055  default:
8056  itemPenWidth = 1.0;
8057  }
8058  const qreal pad = itemPenWidth / 2;
8059 
8060  const qreal penWidth = 0; // cosmetic pen
8061 
8062  const QColor fgcolor = option->palette.windowText().color();
8063  const QColor bgcolor( // ensure good contrast against fgcolor
8064  fgcolor.red() > 127 ? 0 : 255,
8065  fgcolor.green() > 127 ? 0 : 255,
8066  fgcolor.blue() > 127 ? 0 : 255);
8067 
8068  painter->setPen(QPen(bgcolor, penWidth, Qt::SolidLine));
8069  painter->setBrush(Qt::NoBrush);
8070  painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
8071 
8072  painter->setPen(QPen(option->palette.windowText(), 0, Qt::DashLine));
8073  painter->setBrush(Qt::NoBrush);
8074  painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
8075 }
8076 
8111  : QGraphicsItem(parent)
8112 {
8114 }
8115 
8120  : QGraphicsItem(dd, parent, scene)
8121 {
8123 }
8124 
8125 #ifndef QT_NO_GESTURES
8126 
8131 void QGraphicsObject::grabGesture(Qt::GestureType gesture, Qt::GestureFlags flags)
8132 {
8134  QGraphicsItem::d_ptr->gestureContext.insert(gesture, flags);
8135  if (!contains && QGraphicsItem::d_ptr->scene)
8136  QGraphicsItem::d_ptr->scene->d_func()->grabGesture(this, gesture);
8137 }
8138 
8145 {
8146  if (QGraphicsItem::d_ptr->gestureContext.remove(gesture) && QGraphicsItem::d_ptr->scene)
8147  QGraphicsItem::d_ptr->scene->d_func()->ungrabGesture(this, gesture);
8148 }
8149 #endif // QT_NO_GESTURES
8150 
8159 {
8161 }
8162 
8164 {
8165  if (item) {
8166  QGraphicsObject *graphicsObject = static_cast<QGraphicsObject *>(list->object);
8168  item->setParentItem(graphicsObject);
8169  } else {
8170  QGraphicsItemPrivate::get(item)->setParentItemHelper(graphicsObject, 0, 0);
8171  }
8172  }
8173 }
8174 
8176 {
8177  QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(list->object));
8178  return d->children.count();
8179 }
8180 
8182 {
8183  QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(list->object));
8184  if (index >= 0 && index < d->children.count())
8185  return d->children.at(index)->toGraphicsObject();
8186  else
8187  return 0;
8188 }
8189 
8191 {
8192  QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(static_cast<QGraphicsObject *>(list->object));
8193  int childCount = d->children.count();
8195  for (int index = 0; index < childCount; index++)
8196  d->children.at(0)->setParentItem(0);
8197  } else {
8198  for (int index = 0; index < childCount; index++)
8199  QGraphicsItemPrivate::get(d->children.at(0))->setParentItemHelper(0, 0, 0);
8200  }
8201 }
8202 
8211 {
8212  Q_Q(QGraphicsItem);
8213  if (isObject) {
8214  QGraphicsObject *that = static_cast<QGraphicsObject *>(q);
8215  return QDeclarativeListProperty<QGraphicsObject>(that, &children, children_append,
8216  children_count, children_at, children_clear);
8217  } else {
8218  //QGraphicsItem is not supported for this property
8220  }
8221 }
8222 
8229 {
8230  return 0;
8231 }
8232 
8239 {
8240  Q_UNUSED(w);
8241 }
8242 
8249 {
8250 }
8251 
8258 {
8259  return 0;
8260 }
8261 
8268 {
8269  Q_UNUSED(h);
8270 }
8271 
8278 {
8279 }
8280 
8588 {
8590 public:
8591 
8594 
8595  // Cached bounding rectangle
8597 };
8598 
8604 #ifndef Q_QDOC
8605  // obsolete argument
8607 #endif
8608  )
8610 {
8611 }
8612 
8617  QGraphicsItem *parent,
8619  : QGraphicsItem(dd, parent, scene)
8620 {
8621 }
8622 
8627 {
8628 }
8629 
8635 {
8637  return d->pen;
8638 }
8639 
8648 {
8650  if (d->pen == pen)
8651  return;
8653  d->pen = pen;
8654  d->boundingRect = QRectF();
8655  update();
8656 }
8657 
8664 {
8666  return d->brush;
8667 }
8668 
8680 {
8682  if (d->brush == brush)
8683  return;
8684  d->brush = brush;
8685  update();
8686 }
8687 
8692 {
8693  return QGraphicsItem::isObscuredBy(item);
8694 }
8695 
8700 {
8702  if (d->brush.isOpaque())
8703  return isClipped() ? clipPath() : shape();
8704  return QGraphicsItem::opaqueArea();
8705 }
8706 
8735 {
8737 public:
8739 };
8740 
8748  QGraphicsItem *parent
8749 #ifndef Q_QDOC
8750  // obsolete argument
8752 #endif
8753  )
8755 {
8756  if (!path.isEmpty())
8757  setPath(path);
8758 }
8759 
8767 #ifndef Q_QDOC
8768  // obsolete argument
8770 #endif
8771  )
8773 {
8774 }
8775 
8780 {
8781 }
8782 
8790 {
8791  Q_D(const QGraphicsPathItem);
8792  return d->path;
8793 }
8794 
8801 {
8803  if (d->path == path)
8804  return;
8806  d->path = path;
8807  d->boundingRect = QRectF();
8808  update();
8809 }
8810 
8815 {
8816  Q_D(const QGraphicsPathItem);
8817  if (d->boundingRect.isNull()) {
8818  qreal pw = pen().widthF();
8819  if (pw == 0.0)
8820  d->boundingRect = d->path.controlPointRect();
8821  else {
8822  d->boundingRect = shape().controlPointRect();
8823  }
8824  }
8825  return d->boundingRect;
8826 }
8827 
8832 {
8833  Q_D(const QGraphicsPathItem);
8834  return qt_graphicsItem_shapeFromPath(d->path, d->pen);
8835 }
8836 
8840 bool QGraphicsPathItem::contains(const QPointF &point) const
8841 {
8843 }
8844 
8849  QWidget *widget)
8850 {
8852  Q_UNUSED(widget);
8853  painter->setPen(d->pen);
8854  painter->setBrush(d->brush);
8855  painter->drawPath(d->path);
8856 
8857  if (option->state & QStyle::State_Selected)
8858  qt_graphicsItem_highlightSelected(this, painter, option);
8859 }
8860 
8865 {
8867 }
8868 
8873 {
8875 }
8876 
8881 {
8882  return Type;
8883 }
8884 
8889 {
8890  Q_UNUSED(extension);
8891  return false;
8892 }
8893 
8898 {
8899  Q_UNUSED(extension);
8900  Q_UNUSED(variant);
8901 }
8902 
8907 {
8908  Q_UNUSED(variant);
8909  return QVariant();
8910 }
8911 
8947 {
8949 public:
8951 };
8952 
8960 #ifndef Q_QDOC
8961  // obsolete argument
8963 #endif
8964  )
8966 {
8967  setRect(rect);
8968 }
8969 
8982  QGraphicsItem *parent
8983 #ifndef Q_QDOC
8984  // obsolete argument
8986 #endif
8987  )
8989 {
8990  setRect(QRectF(x, y, w, h));
8991 }
8992 
9000 #ifndef Q_QDOC
9001  // obsolete argument
9003 #endif
9004  )
9006 {
9007 }
9008 
9013 {
9014 }
9015 
9022 {
9023  Q_D(const QGraphicsRectItem);
9024  return d->rect;
9025 }
9026 
9038 {
9040  if (d->rect == rect)
9041  return;
9043  d->rect = rect;
9044  d->boundingRect = QRectF();
9045  update();
9046 }
9047 
9068 {
9069  Q_D(const QGraphicsRectItem);
9070  if (d->boundingRect.isNull()) {
9071  qreal halfpw = pen().widthF() / 2;
9072  d->boundingRect = d->rect;
9073  if (halfpw > 0.0)
9074  d->boundingRect.adjust(-halfpw, -halfpw, halfpw, halfpw);
9075  }
9076  return d->boundingRect;
9077 }
9078 
9083 {
9084  Q_D(const QGraphicsRectItem);
9085  QPainterPath path;
9086  path.addRect(d->rect);
9087  return qt_graphicsItem_shapeFromPath(path, d->pen);
9088 }
9089 
9093 bool QGraphicsRectItem::contains(const QPointF &point) const
9094 {
9096 }
9097 
9102  QWidget *widget)
9103 {
9105  Q_UNUSED(widget);
9106  painter->setPen(d->pen);
9107  painter->setBrush(d->brush);
9108  painter->drawRect(d->rect);
9109 
9110  if (option->state & QStyle::State_Selected)
9111  qt_graphicsItem_highlightSelected(this, painter, option);
9112 }
9113 
9118 {
9120 }
9121 
9126 {
9128 }
9129 
9134 {
9135  return Type;
9136 }
9137 
9142 {
9143  Q_UNUSED(extension);
9144  return false;
9145 }
9146 
9151 {
9152  Q_UNUSED(extension);
9153  Q_UNUSED(variant);
9154 }
9155 
9160 {
9161  Q_UNUSED(variant);
9162  return QVariant();
9163 }
9164 
9200 {
9202 public:
9204  : startAngle(0), spanAngle(360 * 16)
9205  { }
9206 
9210 };
9211 
9219 #ifndef Q_QDOC
9220  // obsolete argument
9222 #endif
9223  )
9225 {
9226  setRect(rect);
9227 }
9228 
9240  QGraphicsItem *parent
9241 #ifndef Q_QDOC
9242  // obsolete argument
9244 #endif
9245  )
9247 {
9248  setRect(x,y,w,h);
9249 }
9250 
9251 
9252 
9260 #ifndef Q_QDOC
9261  // obsolete argument
9263 #endif
9264  )
9266 {
9267 }
9268 
9273 {
9274 }
9275 
9282 {
9283  Q_D(const QGraphicsEllipseItem);
9284  return d->rect;
9285 }
9286 
9296 {
9298  if (d->rect == rect)
9299  return;
9301  d->rect = rect;
9302  d->boundingRect = QRectF();
9303  update();
9304 }
9305 
9314 {
9315  Q_D(const QGraphicsEllipseItem);
9316  return d->startAngle;
9317 }
9318 
9327 {
9329  if (angle != d->startAngle) {
9331  d->boundingRect = QRectF();
9332  d->startAngle = angle;
9333  update();
9334  }
9335 }
9336 
9346 {
9347  Q_D(const QGraphicsEllipseItem);
9348  return d->spanAngle;
9349 }
9350 
9360 {
9362  if (angle != d->spanAngle) {
9364  d->boundingRect = QRectF();
9365  d->spanAngle = angle;
9366  update();
9367  }
9368 }
9369 
9374 {
9375  Q_D(const QGraphicsEllipseItem);
9376  if (d->boundingRect.isNull()) {
9377  qreal pw = pen().widthF();
9378  if (pw == 0.0 && d->spanAngle == 360 * 16)
9379  d->boundingRect = d->rect;
9380  else
9381  d->boundingRect = shape().controlPointRect();
9382  }
9383  return d->boundingRect;
9384 }
9385 
9390 {
9391  Q_D(const QGraphicsEllipseItem);
9392  QPainterPath path;
9393  if (d->rect.isNull())
9394  return path;
9395  if (d->spanAngle != 360 * 16) {
9396  path.moveTo(d->rect.center());
9397  path.arcTo(d->rect, d->startAngle / qreal(16.0), d->spanAngle / qreal(16.0));
9398  } else {
9399  path.addEllipse(d->rect);
9400  }
9401 
9402  return qt_graphicsItem_shapeFromPath(path, d->pen);
9403 }
9404 
9408 bool QGraphicsEllipseItem::contains(const QPointF &point) const
9409 {
9411 }
9412 
9417  QWidget *widget)
9418 {
9420  Q_UNUSED(widget);
9421  painter->setPen(d->pen);
9422  painter->setBrush(d->brush);
9423  if ((d->spanAngle != 0) && (qAbs(d->spanAngle) % (360 * 16) == 0))
9424  painter->drawEllipse(d->rect);
9425  else
9426  painter->drawPie(d->rect, d->startAngle, d->spanAngle);
9427 
9428  if (option->state & QStyle::State_Selected)
9429  qt_graphicsItem_highlightSelected(this, painter, option);
9430 }
9431 
9436 {
9438 }
9439 
9444 {
9446 }
9447 
9452 {
9453  return Type;
9454 }
9455 
9456 
9461 {
9462  Q_UNUSED(extension);
9463  return false;
9464 }
9465 
9470 {
9471  Q_UNUSED(extension);
9472  Q_UNUSED(variant);
9473 }
9474 
9479 {
9480  Q_UNUSED(variant);
9481  return QVariant();
9482 }
9483 
9512 {
9514 public:
9516  : fillRule(Qt::OddEvenFill)
9517  { }
9518 
9521 };
9522 
9530  QGraphicsItem *parent
9531 #ifndef Q_QDOC
9532  // obsolete argument
9534 #endif
9535  )
9537 {
9538  setPolygon(polygon);
9539 }
9540 
9548 #ifndef Q_QDOC
9549  // obsolete argument
9551 #endif
9552  )
9554 {
9555 }
9556 
9561 {
9562 }
9563 
9571 {
9572  Q_D(const QGraphicsPolygonItem);
9573  return d->polygon;
9574 }
9575 
9582 {
9584  if (d->polygon == polygon)
9585  return;
9587  d->polygon = polygon;
9588  d->boundingRect = QRectF();
9589  update();
9590 }
9591 
9599 {
9600  Q_D(const QGraphicsPolygonItem);
9601  return d->fillRule;
9602 }
9603 
9611 {
9613  if (rule != d->fillRule) {
9614  d->fillRule = rule;
9615  update();
9616  }
9617 }
9618 
9623 {
9624  Q_D(const QGraphicsPolygonItem);
9625  if (d->boundingRect.isNull()) {
9626  qreal pw = pen().widthF();
9627  if (pw == 0.0)
9628  d->boundingRect = d->polygon.boundingRect();
9629  else
9630  d->boundingRect = shape().controlPointRect();
9631  }
9632  return d->boundingRect;
9633 }
9634 
9639 {
9640  Q_D(const QGraphicsPolygonItem);
9641  QPainterPath path;
9642  path.addPolygon(d->polygon);
9643  return qt_graphicsItem_shapeFromPath(path, d->pen);
9644 }
9645 
9649 bool QGraphicsPolygonItem::contains(const QPointF &point) const
9650 {
9652 }
9653 
9658 {
9660  Q_UNUSED(widget);
9661  painter->setPen(d->pen);
9662  painter->setBrush(d->brush);
9663  painter->drawPolygon(d->polygon, d->fillRule);
9664 
9665  if (option->state & QStyle::State_Selected)
9666  qt_graphicsItem_highlightSelected(this, painter, option);
9667 }
9668 
9673 {
9675 }
9676 
9681 {
9683 }
9684 
9689 {
9690  return Type;
9691 }
9692 
9697 {
9698  Q_UNUSED(extension);
9699  return false;
9700 }
9701 
9706 {
9707  Q_UNUSED(extension);
9708  Q_UNUSED(variant);
9709 }
9710 
9715 {
9716  Q_UNUSED(variant);
9717  return QVariant();
9718 }
9719 
9747 {
9749 public:
9752 };
9753 
9761 #ifndef Q_QDOC
9762  // obsolete argument
9764 #endif
9765  )
9767 {
9768  setLine(line);
9769 }
9770 
9779 #ifndef Q_QDOC
9780  // obsolete argument
9782 #endif
9783  )
9785 {
9786  setLine(x1, y1, x2, y2);
9787 }
9788 
9789 
9790 
9798 #ifndef Q_QDOC
9799  // obsolete argument
9801 #endif
9802  )
9804 {
9805 }
9806 
9811 {
9812 }
9813 
9821 {
9822  Q_D(const QGraphicsLineItem);
9823  return d->pen;
9824 }
9825 
9833 {
9835  if (d->pen == pen)
9836  return;
9838  d->pen = pen;
9839  update();
9840 }
9841 
9848 {
9849  Q_D(const QGraphicsLineItem);
9850  return d->line;
9851 }
9852 
9859 {
9861  if (d->line == line)
9862  return;
9864  d->line = line;
9865  update();
9866 }
9867 
9885 {
9886  Q_D(const QGraphicsLineItem);
9887  if (d->pen.widthF() == 0.0) {
9888  const qreal x1 = d->line.p1().x();
9889  const qreal x2 = d->line.p2().x();
9890  const qreal y1 = d->line.p1().y();
9891  const qreal y2 = d->line.p2().y();
9892  qreal lx = qMin(x1, x2);
9893  qreal rx = qMax(x1, x2);
9894  qreal ty = qMin(y1, y2);
9895  qreal by = qMax(y1, y2);
9896  return QRectF(lx, ty, rx - lx, by - ty);
9897  }
9898  return shape().controlPointRect();
9899 }
9900 
9905 {
9906  Q_D(const QGraphicsLineItem);
9907  QPainterPath path;
9908  if (d->line == QLineF())
9909  return path;
9910 
9911  path.moveTo(d->line.p1());
9912  path.lineTo(d->line.p2());
9913  return qt_graphicsItem_shapeFromPath(path, d->pen);
9914 }
9915 
9919 bool QGraphicsLineItem::contains(const QPointF &point) const
9920 {
9921  return QGraphicsItem::contains(point);
9922 }
9923 
9928 {
9930  Q_UNUSED(widget);
9931  painter->setPen(d->pen);
9932  painter->drawLine(d->line);
9933 
9934  if (option->state & QStyle::State_Selected)
9935  qt_graphicsItem_highlightSelected(this, painter, option);
9936 }
9937 
9942 {
9943  return QGraphicsItem::isObscuredBy(item);
9944 }
9945 
9950 {
9951  return QGraphicsItem::opaqueArea();
9952 }
9953 
9958 {
9959  return Type;
9960 }
9961 
9966 {
9967  Q_UNUSED(extension);
9968  return false;
9969 }
9970 
9975 {
9976  Q_UNUSED(extension);
9977  Q_UNUSED(variant);
9978 }
9979 
9984 {
9985  Q_UNUSED(variant);
9986  return QVariant();
9987 }
9988 
10049 
10051 {
10053 public:
10055  : transformationMode(Qt::FastTransformation),
10056  shapeMode(QGraphicsPixmapItem::MaskShape),
10057  hasShape(false)
10058  {}
10059 
10065  bool hasShape;
10066 
10068  {
10069  shape = QPainterPath();
10070  switch (shapeMode) {
10072  QBitmap mask = pixmap.mask();
10073  if (!mask.isNull()) {
10074  shape = qt_regionToPath(QRegion(mask).translated(offset.toPoint()));
10075  break;
10076  }
10077  // FALL THROUGH
10078  }
10080  shape.addRect(QRectF(offset.x(), offset.y(), pixmap.width(), pixmap.height()));
10081  break;
10083 #ifndef QT_NO_IMAGE_HEURISTIC_MASK
10084  shape = qt_regionToPath(QRegion(pixmap.createHeuristicMask()).translated(offset.toPoint()));
10085 #else
10086  shape.addRect(QRectF(offset.x(), offset.y(), pixmap.width(), pixmap.height()));
10087 #endif
10088  break;
10089  }
10090  }
10091 };
10092 
10100  QGraphicsItem *parent
10101 #ifndef Q_QDOC
10102  // obsolete argument
10104 #endif
10105  )
10107 {
10108  setPixmap(pixmap);
10109 }
10110 
10118 #ifndef Q_QDOC
10119  // obsolete argument
10121 #endif
10122  )
10124 {
10125 }
10126 
10131 {
10132 }
10133 
10140 {
10143  d->pixmap = pixmap;
10144  d->hasShape = false;
10145  update();
10146 }
10147 
10155 {
10156  Q_D(const QGraphicsPixmapItem);
10157  return d->pixmap;
10158 }
10159 
10168 {
10169  Q_D(const QGraphicsPixmapItem);
10170  return d->transformationMode;
10171 }
10172 
10185 {
10187  if (mode != d->transformationMode) {
10188  d->transformationMode = mode;
10189  update();
10190  }
10191 }
10192 
10200 {
10201  Q_D(const QGraphicsPixmapItem);
10202  return d->offset;
10203 }
10204 
10212 {
10214  if (d->offset == offset)
10215  return;
10217  d->offset = offset;
10218  d->hasShape = false;
10219  update();
10220 }
10221 
10236 {
10237  Q_D(const QGraphicsPixmapItem);
10238  if (d->pixmap.isNull())
10239  return QRectF();
10240  if (d->flags & ItemIsSelectable) {
10241  qreal pw = 1.0;
10242  return QRectF(d->offset, d->pixmap.size()).adjusted(-pw/2, -pw/2, pw/2, pw/2);
10243  } else {
10244  return QRectF(d->offset, d->pixmap.size());
10245  }
10246 }
10247 
10252 {
10253  Q_D(const QGraphicsPixmapItem);
10254  if (!d->hasShape) {
10256  thatD->updateShape();
10257  thatD->hasShape = true;
10258  }
10259  return d_func()->shape;
10260 }
10261 
10265 bool QGraphicsPixmapItem::contains(const QPointF &point) const
10266 {
10267  return QGraphicsItem::contains(point);
10268 }
10269 
10274  QWidget *widget)
10275 {
10277  Q_UNUSED(widget);
10278 
10280  (d->transformationMode == Qt::SmoothTransformation));
10281 
10282  painter->drawPixmap(d->offset, d->pixmap);
10283 
10284  if (option->state & QStyle::State_Selected)
10285  qt_graphicsItem_highlightSelected(this, painter, option);
10286 }
10287 
10292 {
10293  return QGraphicsItem::isObscuredBy(item);
10294 }
10295 
10300 {
10301  return shape();
10302 }
10303 
10308 {
10309  return Type;
10310 }
10311 
10319 {
10320  return d_func()->shapeMode;
10321 }
10322 
10330 {
10332  if (d->shapeMode == mode)
10333  return;
10334  d->shapeMode = mode;
10335  d->hasShape = false;
10336 }
10337 
10342 {
10343  Q_UNUSED(extension);
10344  return false;
10345 }
10346 
10351 {
10352  Q_UNUSED(extension);
10353  Q_UNUSED(variant);
10354 }
10355 
10360 {
10361  Q_UNUSED(variant);
10362  return QVariant();
10363 }
10364 
10404 {
10405 public:
10407  : control(0), pageNumber(0), useDefaultImpl(false), tabChangesFocus(false), clickCausedFocus(0)
10408  { }
10409 
10411  QTextControl *textControl() const;
10412 
10413  inline QPointF controlOffset() const
10414  { return QPointF(0., pageNumber * control->document()->pageSize().height()); }
10415  inline void sendControlEvent(QEvent *e)
10416  { if (control) control->processEvent(e, controlOffset()); }
10417 
10418  void _q_updateBoundingRect(const QSizeF &);
10419  void _q_update(QRectF);
10420  void _q_ensureVisible(QRectF);
10421  bool _q_mouseOnEdge(QGraphicsSceneMouseEvent *);
10422 
10427 
10429 
10431 };
10432 
10433 
10441 #ifndef Q_QDOC
10442  // obsolete argument
10444 #endif
10445  )
10447 {
10448  dd->qq = this;
10449  if (!text.isEmpty())
10450  setPlainText(text);
10451  setAcceptDrops(true);
10452  setAcceptHoverEvents(true);
10454 }
10455 
10463 #ifndef Q_QDOC
10464  // obsolete argument
10466 #endif
10467  )
10469 {
10470  dd->qq = this;
10471  setAcceptDrops(true);
10472  setAcceptHoverEvents(true);
10474 }
10475 
10480 {
10481  delete dd;
10482 }
10483 
10490 {
10491 #ifndef QT_NO_TEXTHTMLPARSER
10492  if (dd->control)
10493  return dd->control->toHtml();
10494 #endif
10495  return QString();
10496 }
10497 
10506 {
10507  dd->textControl()->setHtml(text);
10508 }
10509 
10516 {
10517  if (dd->control)
10518  return dd->control->toPlainText();
10519  return QString();
10520 }
10521 
10530 {
10531  dd->textControl()->setPlainText(text);
10532 }
10533 
10540 {
10541  if (!dd->control)
10542  return QFont();
10543  return dd->control->document()->defaultFont();
10544 }
10545 
10552 {
10553  dd->textControl()->document()->setDefaultFont(font);
10554 }
10555 
10560 {
10561  QTextControl *c = dd->textControl();
10562  QPalette pal = c->palette();
10563  QColor old = pal.color(QPalette::Text);
10564  pal.setColor(QPalette::Text, col);
10565  c->setPalette(pal);
10566  if (old != col)
10567  update();
10568 }
10569 
10574 {
10575  return dd->textControl()->palette().color(QPalette::Text);
10576 }
10577 
10582 {
10583  return dd->boundingRect;
10584 }
10585 
10590 {
10591  if (!dd->control)
10592  return QPainterPath();
10593  QPainterPath path;
10594  path.addRect(dd->boundingRect);
10595  return path;
10596 }
10597 
10601 bool QGraphicsTextItem::contains(const QPointF &point) const
10602 {
10603  return dd->boundingRect.contains(point);
10604 }
10605 
10610  QWidget *widget)
10611 {
10612  Q_UNUSED(widget);
10613  if (dd->control) {
10614  painter->save();
10615  QRectF r = option->exposedRect;
10616  painter->translate(-dd->controlOffset());
10617  r.translate(dd->controlOffset());
10618 
10619  QTextDocument *doc = dd->control->document();
10621 
10622  // the layout might need to expand the root frame to
10623  // the viewport if NoWrap is set
10624  if (layout)
10625  layout->setViewport(dd->boundingRect);
10626 
10627  dd->control->drawContents(painter, r);
10628 
10629  if (layout)
10630  layout->setViewport(QRect());
10631 
10632  painter->restore();
10633  }
10634 
10636  qt_graphicsItem_highlightSelected(this, painter, option);
10637 }
10638 
10643 {
10644  return QGraphicsItem::isObscuredBy(item);
10645 }
10646 
10651 {
10652  return QGraphicsItem::opaqueArea();
10653 }
10654 
10659 {
10660  return Type;
10661 }
10662 
10680 {
10681  dd->textControl()->setTextWidth(width);
10682 }
10683 
10693 {
10694  if (!dd->control)
10695  return -1;
10696  return dd->control->textWidth();
10697 }
10698 
10703 {
10704  if (dd->control)
10705  dd->control->adjustSize();
10706 }
10707 
10712 {
10713  dd->textControl()->setDocument(document);
10715 }
10716 
10721 {
10722  return dd->textControl()->document();
10723 }
10724 
10729 {
10730  QEvent::Type t = event->type();
10731  if (!dd->tabChangesFocus && (t == QEvent::KeyPress || t == QEvent::KeyRelease)) {
10732  int k = ((QKeyEvent *)event)->key();
10733  if (k == Qt::Key_Tab || k == Qt::Key_Backtab) {
10734  dd->sendControlEvent(event);
10735  return true;
10736  }
10737  }
10738  bool result = QGraphicsItem::sceneEvent(event);
10739 
10740  // Ensure input context is updated.
10741  switch (event->type()) {
10742  case QEvent::ContextMenu:
10743  case QEvent::FocusIn:
10744  case QEvent::FocusOut:
10756  case QEvent::KeyPress:
10757  case QEvent::KeyRelease:
10758  // Reset the focus widget's input context, regardless
10759  // of how this item gained or lost focus.
10760  if (QWidget *fw = qApp->focusWidget()) {
10761 #ifndef QT_NO_IM
10762  if (QInputContext *qic = fw->inputContext()) {
10763  if (event->type() == QEvent::FocusIn || event->type() == QEvent::FocusOut)
10764  qic->reset();
10765  else
10766  qic->update();
10767  }
10768 #endif //QT_NO_IM
10769  }
10770  break;
10772  dd->sendControlEvent(event);
10773  return true;
10774  default:
10775  break;
10776  }
10777 
10778  return result;
10779 }
10780 
10785 {
10787  && (event->buttons() & Qt::LeftButton) && dd->_q_mouseOnEdge(event)) {
10788  // User left-pressed on edge of selectable/movable item, use
10789  // base impl.
10790  dd->useDefaultImpl = true;
10791  } else if (event->buttons() == event->button()
10793  // User pressed first button on non-interactive item.
10794  dd->useDefaultImpl = true;
10795  }
10796  if (dd->useDefaultImpl) {
10798  if (!event->isAccepted())
10799  dd->useDefaultImpl = false;
10800  return;
10801  }
10802 
10803  dd->sendControlEvent(event);
10804 }
10805 
10810 {
10811  if (dd->useDefaultImpl) {
10813  return;
10814  }
10815 
10816  dd->sendControlEvent(event);
10817 }
10818 
10823 {
10824  if (dd->useDefaultImpl) {
10827  && !event->buttons()) {
10828  // User released last button on non-interactive item.
10829  dd->useDefaultImpl = false;
10830  } else if ((event->buttons() & Qt::LeftButton) == 0) {
10831  // User released the left button on an interactive item.
10832  dd->useDefaultImpl = false;
10833  }
10834  return;
10835  }
10836 
10837  QWidget *widget = event->widget();
10838  if (widget && (dd->control->textInteractionFlags() & Qt::TextEditable) && boundingRect().contains(event->pos())) {
10840  }
10841  dd->clickCausedFocus = 0;
10842  dd->sendControlEvent(event);
10843 }
10844 
10849 {
10850  if (dd->useDefaultImpl) {
10852  return;
10853  }
10854 
10855  if (!hasFocus()) {
10857  return;
10858  }
10859 
10860  dd->sendControlEvent(event);
10861 }
10862 
10867 {
10868  dd->sendControlEvent(event);
10869 }
10870 
10875 {
10876  dd->sendControlEvent(event);
10877 }
10878 
10883 {
10884  dd->sendControlEvent(event);
10885 }
10886 
10891 {
10892  dd->sendControlEvent(event);
10893  if (event->reason() == Qt::MouseFocusReason) {
10894  dd->clickCausedFocus = 1;
10895  }
10896  update();
10897 }
10898 
10903 {
10904  dd->sendControlEvent(event);
10905  update();
10906 }
10907 
10912 {
10913  dd->sendControlEvent(event);
10914 }
10915 
10920 {
10921  dd->sendControlEvent(event);
10922 }
10923 
10928 {
10929  dd->sendControlEvent(event);
10930 }
10931 
10936 {
10937  dd->sendControlEvent(event);
10938 }
10939 
10944 {
10945  dd->sendControlEvent(event);
10946 }
10947 
10952 {
10953  dd->sendControlEvent(event);
10954 }
10955 
10960 {
10961  dd->sendControlEvent(event);
10962 }
10963 
10968 {
10969  dd->sendControlEvent(event);
10970 }
10971 
10976 {
10977  QVariant v;
10978  if (dd->control)
10979  v = dd->control->inputMethodQuery(query);
10980  if (v.type() == QVariant::RectF)
10981  v = v.toRectF().translated(-dd->controlOffset());
10982  else if (v.type() == QVariant::PointF)
10983  v = v.toPointF() - dd->controlOffset();
10984  else if (v.type() == QVariant::Rect)
10985  v = v.toRect().translated(-dd->controlOffset().toPoint());
10986  else if (v.type() == QVariant::Point)
10987  v = v.toPoint() - dd->controlOffset().toPoint();
10988  return v;
10989 }
10990 
10995 {
10996  Q_UNUSED(extension);
10997  return false;
10998 }
10999 
11004 {
11005  Q_UNUSED(extension);
11006  Q_UNUSED(variant);
11007 }
11008 
11013 {
11014  Q_UNUSED(variant);
11015  return QVariant();
11016 }
11017 
11022 {
11023  if (rect.isValid()) {
11024  rect.translate(-controlOffset());
11025  } else {
11026  rect = boundingRect;
11027  }
11028  if (rect.intersects(boundingRect))
11029  qq->update(rect);
11030 }
11031 
11036 {
11037  if (!control) return; // can't happen
11038  const QSizeF pageSize = control->document()->pageSize();
11039  // paged items have a constant (page) size
11040  if (size == boundingRect.size() || pageSize.height() != -1)
11041  return;
11042  qq->prepareGeometryChange();
11043  boundingRect.setSize(size);
11044  qq->update();
11045 }
11046 
11051 {
11052  if (qq->hasFocus()) {
11053  rect.translate(-controlOffset());
11054  qq->ensureVisible(rect, /*xmargin=*/0, /*ymargin=*/0);
11055  }
11056 }
11057 
11059 {
11060  if (!control) {
11061  QGraphicsTextItem *that = const_cast<QGraphicsTextItem *>(qq);
11062  control = new QTextControl(that);
11063  control->setTextInteractionFlags(Qt::NoTextInteraction);
11064 
11065  QObject::connect(control, SIGNAL(updateRequest(QRectF)),
11066  qq, SLOT(_q_update(QRectF)));
11067  QObject::connect(control, SIGNAL(documentSizeChanged(QSizeF)),
11068  qq, SLOT(_q_updateBoundingRect(QSizeF)));
11069  QObject::connect(control, SIGNAL(visibilityRequest(QRectF)),
11070  qq, SLOT(_q_ensureVisible(QRectF)));
11072  qq, SIGNAL(linkActivated(QString)));
11074  qq, SIGNAL(linkHovered(QString)));
11075 
11076  const QSizeF pgSize = control->document()->pageSize();
11077  if (pgSize.height() != -1) {
11078  qq->prepareGeometryChange();
11079  that->dd->boundingRect.setSize(pgSize);
11080  qq->update();
11081  } else {
11082  that->dd->_q_updateBoundingRect(control->size());
11083  }
11084  }
11085  return control;
11086 }
11087 
11092 {
11093  QPainterPath path;
11094  path.addRect(qq->boundingRect());
11095 
11096  QPainterPath docPath;
11097  const QTextFrameFormat format = control->document()->rootFrame()->frameFormat();
11098  docPath.addRect(
11099  qq->boundingRect().adjusted(
11100  format.leftMargin(),
11101  format.topMargin(),
11102  -format.rightMargin(),
11103  -format.bottomMargin()));
11104 
11105  return path.subtracted(docPath).contains(event->pos());
11106 }
11107 
11146 {
11147  if (flags == Qt::NoTextInteraction)
11149  else
11151 
11153 }
11154 
11160 Qt::TextInteractionFlags QGraphicsTextItem::textInteractionFlags() const
11161 {
11162  if (!dd->control)
11163  return Qt::NoTextInteraction;
11164  return dd->control->textInteractionFlags();
11165 }
11166 
11183 {
11184  dd->tabChangesFocus = b;
11185 }
11186 
11201 {
11202  return dd->tabChangesFocus;
11203 }
11204 
11218 {
11220 }
11221 
11223 {
11224  if (!dd->control)
11225  return false;
11226  return dd->control->openExternalLinks();
11227 }
11228 
11243 {
11244  dd->textControl()->setTextCursor(cursor);
11245 }
11246 
11248 {
11249  if (!dd->control)
11250  return QTextCursor();
11251  return dd->control->textCursor();
11252 }
11253 
11255 {
11257 public:
11259  pen.setStyle(Qt::NoPen);
11260  brush.setStyle(Qt::SolidPattern);
11261  }
11265 
11266  void updateBoundingRect();
11267 };
11268 
11270 {
11271  layout->setCacheEnabled(true);
11272  layout->beginLayout();
11273  while (layout->createLine().isValid())
11274  ;
11275  layout->endLayout();
11276  qreal maxWidth = 0;
11277  qreal y = 0;
11278  for (int i = 0; i < layout->lineCount(); ++i) {
11279  QTextLine line = layout->lineAt(i);
11280  maxWidth = qMax(maxWidth, line.naturalTextWidth());
11281  line.setPosition(QPointF(0, y));
11282  y += line.height();
11283  }
11284  return QRectF(0, 0, maxWidth, y);
11285 }
11286 
11288 {
11290  QRectF br;
11291  if (text.isEmpty()) {
11292  br = QRectF();
11293  } else {
11294  QString tmp = text;
11296  QStackTextEngine engine(tmp, font);
11297  QTextLayout layout(&engine);
11298  br = setupTextLayout(&layout);
11299  }
11300  if (br != boundingRect) {
11301  q->prepareGeometryChange();
11302  boundingRect = br;
11303  q->update();
11304  }
11305 }
11306 
11350 #ifndef Q_QDOC
11351  // obsolete argument
11353 #endif
11354  )
11356 {
11357 }
11358 
11367 #ifndef Q_QDOC
11368  // obsolete argument
11370 #endif
11371  )
11373 {
11374  setText(text);
11375 }
11376 
11381 {
11382 }
11383 
11391 {
11393  if (d->text == text)
11394  return;
11395  d->text = text;
11396  d->updateBoundingRect();
11397  update();
11398 }
11399 
11404 {
11406  return d->text;
11407 }
11408 
11413 {
11415  d->font = font;
11416  d->updateBoundingRect();
11417 }
11418 
11423 {
11425  return d->font;
11426 }
11427 
11432 {
11434  return d->boundingRect;
11435 }
11436 
11441 {
11443  QPainterPath path;
11444  path.addRect(d->boundingRect);
11445  return path;
11446 }
11447 
11452 {
11454  return d->boundingRect.contains(point);
11455 }
11456 
11461 {
11462  Q_UNUSED(widget);
11464 
11465  painter->setFont(d->font);
11466 
11467  QString tmp = d->text;
11469  QStackTextEngine engine(tmp, d->font);
11470  QTextLayout layout(&engine);
11471  setupTextLayout(&layout);
11472 
11473  QPen p;
11474  p.setBrush(d->brush);
11475  painter->setPen(p);
11476  if (d->pen.style() == Qt::NoPen && d->brush.style() == Qt::SolidPattern) {
11477  painter->setBrush(Qt::NoBrush);
11478  } else {
11480  range.start = 0;
11481  range.length = layout.text().length();
11482  range.format.setTextOutline(d->pen);
11484  formats.append(range);
11485  layout.setAdditionalFormats(formats);
11486  }
11487 
11488  layout.draw(painter, QPointF(0, 0));
11489 
11491  qt_graphicsItem_highlightSelected(this, painter, option);
11492 }
11493 
11498 {
11500 }
11501 
11506 {
11508 }
11509 
11514 {
11515  return Type;
11516 }
11517 
11522 {
11523  Q_UNUSED(extension);
11524  return false;
11525 }
11526 
11531 {
11532  Q_UNUSED(extension);
11533  Q_UNUSED(variant);
11534 }
11535 
11540 {
11541  Q_UNUSED(variant);
11542  return QVariant();
11543 }
11544 
11607 {
11608 public:
11610 };
11611 
11619 #ifndef Q_QDOC
11620  // obsolete argument
11622 #endif
11623  )
11625 {
11626  setHandlesChildEvents(true);
11627 }
11628 
11633 {
11634 }
11635 
11644 {
11646  if (!item) {
11647  qWarning("QGraphicsItemGroup::addToGroup: cannot add null item");
11648  return;
11649  }
11650  if (item == this) {
11651  qWarning("QGraphicsItemGroup::addToGroup: cannot add a group to itself");
11652  return;
11653  }
11654 
11655  // COMBINE
11656  bool ok;
11657  QTransform itemTransform = item->itemTransform(this, &ok);
11658 
11659  if (!ok) {
11660  qWarning("QGraphicsItemGroup::addToGroup: could not find a valid transformation from item to group coordinates");
11661  return;
11662  }
11663 
11664  QTransform newItemTransform(itemTransform);
11665  item->setPos(mapFromItem(item, 0, 0));
11666  item->setParentItem(this);
11667 
11668  // removing position from translation component of the new transform
11669  if (!item->pos().isNull())
11670  newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y());
11671 
11672  // removing additional transformations properties applied with itemTransform()
11673  QPointF origin = item->transformOriginPoint();
11674  QMatrix4x4 m;
11675  QList<QGraphicsTransform*> transformList = item->transformations();
11676  for (int i = 0; i < transformList.size(); ++i)
11677  transformList.at(i)->applyTo(&m);
11678  newItemTransform *= m.toTransform().inverted();
11679  newItemTransform.translate(origin.x(), origin.y());
11680  newItemTransform.rotate(-item->rotation());
11681  newItemTransform.scale(1/item->scale(), 1/item->scale());
11682  newItemTransform.translate(-origin.x(), -origin.y());
11683 
11684  // ### Expensive, we could maybe use dirtySceneTransform bit for optimization
11685 
11686  item->setTransform(newItemTransform);
11687  item->d_func()->setIsMemberOfGroup(true);
11689  d->itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect());
11690  update();
11691 }
11692 
11702 {
11704  if (!item) {
11705  qWarning("QGraphicsItemGroup::removeFromGroup: cannot remove null item");
11706  return;
11707  }
11708 
11709  QGraphicsItem *newParent = d_ptr->parent;
11710 
11711  // COMBINE
11712  bool ok;
11714  if (newParent)
11715  itemTransform = item->itemTransform(newParent, &ok);
11716  else
11717  itemTransform = item->sceneTransform();
11718 
11719  QPointF oldPos = item->mapToItem(newParent, 0, 0);
11720  item->setParentItem(newParent);
11721  item->setPos(oldPos);
11722 
11723  // removing position from translation component of the new transform
11724  if (!item->pos().isNull())
11725  itemTransform *= QTransform::fromTranslate(-item->x(), -item->y());
11726 
11727  // removing additional transformations properties applied
11728  // with itemTransform() or sceneTransform()
11729  QPointF origin = item->transformOriginPoint();
11730  QMatrix4x4 m;
11731  QList<QGraphicsTransform*> transformList = item->transformations();
11732  for (int i = 0; i < transformList.size(); ++i)
11733  transformList.at(i)->applyTo(&m);
11734  itemTransform *= m.toTransform().inverted();
11735  itemTransform.translate(origin.x(), origin.y());
11736  itemTransform.rotate(-item->rotation());
11737  itemTransform.scale(1 / item->scale(), 1 / item->scale());
11738  itemTransform.translate(-origin.x(), -origin.y());
11739 
11740  // ### Expensive, we could maybe use dirtySceneTransform bit for optimization
11741 
11742  item->setTransform(itemTransform);
11743  item->d_func()->setIsMemberOfGroup(item->group() != 0);
11744 
11745  // ### Quite expensive. But removeFromGroup() isn't called very often.
11747  d->itemsBoundingRect = childrenBoundingRect();
11748 }
11749 
11759 {
11760  Q_D(const QGraphicsItemGroup);
11761  return d->itemsBoundingRect;
11762 }
11763 
11768  QWidget *widget)
11769 {
11770  Q_UNUSED(widget);
11771  if (option->state & QStyle::State_Selected) {
11773  painter->setBrush(Qt::NoBrush);
11774  painter->drawRect(d->itemsBoundingRect);
11775  }
11776 }
11777 
11782 {
11783  return QGraphicsItem::isObscuredBy(item);
11784 }
11785 
11790 {
11791  return QGraphicsItem::opaqueArea();
11792 }
11793 
11798 {
11799  return Type;
11800 }
11801 
11802 #ifndef QT_NO_GRAPHICSEFFECT
11804 {
11805  const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
11806  if (!info && deviceCoordinates) {
11807  // Device coordinates without info not yet supported.
11808  qWarning("QGraphicsEffectSource::boundingRect: Not yet implemented, lacking device context");
11809  return QRectF();
11810  }
11811 
11812  QRectF rect = item->boundingRect();
11813  if (!item->d_ptr->children.isEmpty())
11814  rect |= item->childrenBoundingRect();
11815 
11816  if (deviceCoordinates) {
11817  Q_ASSERT(info->painter);
11818  rect = info->painter->worldTransform().mapRect(rect);
11819  }
11820 
11821  return rect;
11822 }
11823 
11825 {
11826  if (!info) {
11827  qWarning("QGraphicsEffectSource::draw: Can only begin as a result of QGraphicsEffect::draw");
11828  return;
11829  }
11830 
11831  Q_ASSERT(item->d_ptr->scene);
11832  QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();
11833  if (painter == info->painter) {
11834  scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion,
11835  info->widget, info->opacity, info->effectTransform, info->wasDirtySceneTransform,
11836  info->drawItem);
11837  } else {
11838  QTransform effectTransform = info->painter->worldTransform().inverted();
11839  effectTransform *= painter->worldTransform();
11840  scened->draw(item, painter, info->viewTransform, info->transformPtr, info->exposedRegion,
11841  info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,
11842  info->drawItem);
11843  }
11844 }
11845 
11846 // sourceRect must be in the given coordinate system
11848 {
11849  QRectF effectRectF;
11850 
11851  if (unpadded)
11852  *unpadded = false;
11853 
11855  if (info) {
11856  QRectF deviceRect = system == Qt::DeviceCoordinates ? sourceRect : info->painter->worldTransform().mapRect(sourceRect);
11857  effectRectF = item->graphicsEffect()->boundingRectFor(deviceRect);
11858  if (unpadded)
11859  *unpadded = (effectRectF.size() == sourceRect.size());
11860  if (info && system == Qt::LogicalCoordinates)
11861  effectRectF = info->painter->worldTransform().inverted().mapRect(effectRectF);
11862  } else {
11863  // no choice but to send a logical coordinate bounding rect to boundingRectFor
11864  effectRectF = item->graphicsEffect()->boundingRectFor(sourceRect);
11865  }
11866  } else if (mode == QGraphicsEffect::PadToTransparentBorder) {
11867  // adjust by 1.5 to account for cosmetic pens
11868  effectRectF = sourceRect.adjusted(-1.5, -1.5, 1.5, 1.5);
11869  } else {
11870  effectRectF = sourceRect;
11871  if (unpadded)
11872  *unpadded = true;
11873  }
11874 
11875  return effectRectF.toAlignedRect();
11876 }
11877 
11879  QGraphicsEffect::PixmapPadMode mode) const
11880 {
11881  const bool deviceCoordinates = (system == Qt::DeviceCoordinates);
11882  if (!info && deviceCoordinates) {
11883  // Device coordinates without info not yet supported.
11884  qWarning("QGraphicsEffectSource::pixmap: Not yet implemented, lacking device context");
11885  return QPixmap();
11886  }
11887  if (!item->d_ptr->scene)
11888  return QPixmap();
11889  QGraphicsScenePrivate *scened = item->d_ptr->scene->d_func();
11890 
11891  bool unpadded;
11892  const QRectF sourceRect = boundingRect(system);
11893  QRect effectRect = paddedEffectRect(system, mode, sourceRect, &unpadded);
11894 
11895  if (offset)
11896  *offset = effectRect.topLeft();
11897 
11898  bool untransformed = !deviceCoordinates
11899  || info->painter->worldTransform().type() <= QTransform::TxTranslate;
11900  if (untransformed && unpadded && isPixmap()) {
11901  if (offset)
11902  *offset = boundingRect(system).topLeft().toPoint();
11903  return static_cast<QGraphicsPixmapItem *>(item)->pixmap();
11904  }
11905 
11906  if (effectRect.isEmpty())
11907  return QPixmap();
11908 
11909  QPixmap pixmap(effectRect.size());
11910  pixmap.fill(Qt::transparent);
11911  QPainter pixmapPainter(&pixmap);
11912  pixmapPainter.setRenderHints(info ? info->painter->renderHints() : QPainter::TextAntialiasing);
11913 
11914  QTransform effectTransform = QTransform::fromTranslate(-effectRect.x(), -effectRect.y());
11915  if (deviceCoordinates && info->effectTransform)
11916  effectTransform *= *info->effectTransform;
11917 
11918  if (!info) {
11919  // Logical coordinates without info.
11920  QTransform sceneTransform = item->sceneTransform();
11921  QTransform newEffectTransform = sceneTransform.inverted();
11922  newEffectTransform *= effectTransform;
11923  scened->draw(item, &pixmapPainter, 0, &sceneTransform, 0, 0, qreal(1.0),
11924  &newEffectTransform, false, true);
11925  } else if (deviceCoordinates) {
11926  // Device coordinates with info.
11927  scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, 0,
11928  info->widget, info->opacity, &effectTransform, info->wasDirtySceneTransform,
11929  info->drawItem);
11930  } else {
11931  // Item coordinates with info.
11932  QTransform newEffectTransform = info->transformPtr->inverted();
11933  newEffectTransform *= effectTransform;
11934  scened->draw(item, &pixmapPainter, info->viewTransform, info->transformPtr, 0,
11935  info->widget, info->opacity, &newEffectTransform, info->wasDirtySceneTransform,
11936  info->drawItem);
11937  }
11938 
11939  pixmapPainter.end();
11940 
11941  return pixmap;
11942 }
11943 #endif //QT_NO_GRAPHICSEFFECT
11944 
11945 #ifndef QT_NO_DEBUG_STREAM
11947 {
11948  if (!item) {
11949  debug << "QGraphicsItem(0)";
11950  return debug;
11951  }
11952 
11953  if (QGraphicsObject *o = item->toGraphicsObject())
11954  debug << o->metaObject()->className();
11955  else
11956  debug << "QGraphicsItem";
11957  debug << "(this =" << (void*)item
11958  << ", parent =" << (void*)item->parentItem()
11959  << ", pos =" << item->pos()
11960  << ", z =" << item->zValue() << ", flags = "
11961  << item->flags() << ")";
11962  return debug;
11963 }
11964 
11966 {
11967  if (!item) {
11968  debug << "QGraphicsObject(0)";
11969  return debug;
11970  }
11971 
11972  debug.nospace() << item->metaObject()->className() << '(' << (void*)item;
11973  if (!item->objectName().isEmpty())
11974  debug << ", name = " << item->objectName();
11975  debug.nospace() << ", parent = " << ((void*)item->parentItem())
11976  << ", pos = " << item->pos()
11977  << ", z = " << item->zValue() << ", flags = "
11978  << item->flags() << ')';
11979  return debug.space();
11980 }
11981 
11983 {
11984  const char *str = "UnknownChange";
11985  switch (change) {
11987  str = "ItemChildAddedChange";
11988  break;
11990  str = "ItemChildRemovedChange";
11991  break;
11993  str = "ItemCursorChange";
11994  break;
11996  str = "ItemCursorHasChanged";
11997  break;
11999  str = "ItemEnabledChange";
12000  break;
12002  str = "ItemEnabledHasChanged";
12003  break;
12005  str = "ItemFlagsChange";
12006  break;
12008  str = "ItemFlagsHaveChanged";
12009  break;
12011  str = "ItemMatrixChange";
12012  break;
12014  str = "ItemParentChange";
12015  break;
12017  str = "ItemParentHasChanged";
12018  break;
12020  str = "ItemPositionChange";
12021  break;
12023  str = "ItemPositionHasChanged";
12024  break;
12026  str = "ItemSceneChange";
12027  break;
12029  str = "ItemSceneHasChanged";
12030  break;
12032  str = "ItemSelectedChange";
12033  break;
12035  str = "ItemSelectedHasChanged";
12036  break;
12038  str = "ItemToolTipChange";
12039  break;
12041  str = "ItemToolTipHasChanged";
12042  break;
12044  str = "ItemTransformChange";
12045  break;
12047  str = "ItemTransformHasChanged";
12048  break;
12050  str = "ItemVisibleChange";
12051  break;
12053  str = "ItemVisibleHasChanged";
12054  break;
12056  str = "ItemZValueChange";
12057  break;
12059  str = "ItemZValueHasChanged";
12060  break;
12062  str = "ItemOpacityChange";
12063  break;
12065  str = "ItemOpacityHasChanged";
12066  break;
12068  str = "ItemScenePositionHasChanged";
12069  break;
12071  str = "ItemRotationChange";
12072  break;
12074  str = "ItemRotationHasChanged";
12075  break;
12077  str = "ItemScaleChange";
12078  break;
12080  str = "ItemScaleHasChanged";
12081  break;
12083  str = "ItemTransformOriginPointChange";
12084  break;
12086  str = "ItemTransformOriginPointHasChanged";
12087  break;
12088  }
12089  debug << str;
12090  return debug;
12091 }
12092 
12094 {
12095  const char *str = "UnknownFlag";
12096  switch (flag) {
12098  str = "ItemIsMovable";
12099  break;
12101  str = "ItemIsSelectable";
12102  break;
12104  str = "ItemIsFocusable";
12105  break;
12107  str = "ItemClipsToShape";
12108  break;
12110  str = "ItemClipsChildrenToShape";
12111  break;
12113  str = "ItemIgnoresTransformations";
12114  break;
12116  str = "ItemIgnoresParentOpacity";
12117  break;
12119  str = "ItemDoesntPropagateOpacityToChildren";
12120  break;
12122  str = "ItemStacksBehindParent";
12123  break;
12125  str = "ItemUsesExtendedStyleOption";
12126  break;
12128  str = "ItemHasNoContents";
12129  break;
12131  str = "ItemSendsGeometryChanges";
12132  break;
12134  str = "ItemAcceptsInputMethod";
12135  break;
12137  str = "ItemNegativeZStacksBehindParent";
12138  break;
12140  str = "ItemIsPanel";
12141  break;
12143  str = "ItemIsFocusScope";
12144  break;
12146  str = "ItemSendsScenePositionChanges";
12147  break;
12149  str = "ItemStopsClickFocusPropagation";
12150  break;
12152  str = "ItemStopsFocusHandling";
12153  break;
12154  }
12155  debug << str;
12156  return debug;
12157 }
12158 
12159 QDebug operator<<(QDebug debug, QGraphicsItem::GraphicsItemFlags flags)
12160 {
12161  debug << '(';
12162  bool f = false;
12163  for (int i = 0; i < 17; ++i) {
12164  if (flags & (1 << i)) {
12165  if (f)
12166  debug << '|';
12167  f = true;
12168  debug << QGraphicsItem::GraphicsItemFlag(int(flags & (1 << i)));
12169  }
12170  }
12171  debug << ')';
12172  return debug;
12173 }
12174 
12175 #endif
12176 
12178 
12179 #include "moc_qgraphicsitem.cpp"
12180 
12181 #endif // QT_NO_GRAPHICSVIEW
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
friend class QGraphicsItemEffectSourcePrivate
void unsetExtra(Extra type)
bool contains(const QPointF &point) const
Reimplemented Function
T qobject_cast(QObject *object)
Definition: qobject.h:375
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void updateMicroFocus()
Updates the item&#39;s micro focus.
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
bool filtersChildEvents() const
Returns true if this item filters child events (i.
double d
Definition: qnumeric_p.h:62
QSizeF pageSize
the page size that should be used for laying out the document
void setAdditionalFormats(const QList< FormatRange > &overrides)
Sets the additional formats supported by the text layout to formatList.
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
Definition: qrect.cpp:2817
bool isClipped() const
Returns true if this item is clipped.
void setFocusProxy(QGraphicsItem *item)
Sets the item&#39;s focus proxy to item.
void setFont(const QFont &font)
Sets the font that is used to draw the item&#39;s text to font.
QRectF effectiveBoundingRect(QGraphicsItem *topMostEffectItem=0) const
Returns the effective bounding rect of the item.
CoordinateSystem
Definition: qnamespace.h:1733
QGraphicsPixmapItem::ShapeMode shapeMode
void appendGraphicsTransform(QGraphicsTransform *t)
void clear()
Removes and deletes all items from the scene, but otherwise leaves the state of the scene unchanged...
QPointF transformOriginPoint() const
Returns the origin point for the transformation in item coordinates.
Qt::TextInteractionFlags textInteractionFlags() const
Returns the current text interaction flags.
bool isEmpty() const
Returns true if either there are no elements in this path, or if the only element is a MoveToElement;...
Definition: qpainterpath.h:392
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
void setShapeMode(ShapeMode mode)
Sets the item&#39;s shape mode to mode.
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
Qt::WindowFlags windowFlags
the widget&#39;s window flags
The QTextLayout::FormatRange structure is used to apply extra formatting information for a specified ...
Definition: qtextlayout.h:128
quint32 sendParentChangeNotification
void setParentItemHelper(QGraphicsItem *parent, const QVariant *newParentVariant, const QVariant *thisPointerVariant)
Make sure not to trigger any pure virtual function calls (e.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
QRectF sceneEffectiveBoundingRect() const
Returns the effective bounding rect of this item in scene coordinates, by combining sceneTransform() ...
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
void setPen(const QPen &pen)
Sets the item&#39;s pen to pen.
bool hasFocus() const
Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise...
QGraphicsItem * parent
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
void setExtension(Extension extension, const QVariant &variant)
void setStartAngle(int angle)
Sets the start angle for an ellipse segment to angle, which is in 16ths of a degree.
The QKeyEvent class describes a key event.
Definition: qevent.h:224
void addPath(const QPainterPath &path)
Adds the given path to this path as a closed subpath.
QTransform computedFullTransform(QTransform *postmultiplyTransform=0) const
void setTextOutline(const QPen &pen)
Sets the pen used to draw the outlines of characters to the given pen.
Definition: qtextformat.h:489
QGraphicsItem * subFocusItem
void setPlainText(const QString &text)
QPoint screenPos() const
Returns the mouse cursor position in screen coordinates.
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
QGraphicsItem * focusScopeItem() const
Returns this item&#39;s focus scope item.
void drawPie(const QRectF &rect, int a, int alen)
Draws a pie defined by the given rectangle, startAngle and and spanAngle.
Definition: qpainter.cpp:4670
void invalidateParentGraphicsEffectsRecursively()
void sendControlEvent(QEvent *e)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented Function
void setSpanAngle(int angle)
Sets the span angle for an ellipse segment to angle, which is in 16ths of a degree.
double qreal
Definition: qglobal.h:1193
QGraphicsItem * focusItem() const
If this item, a child or descendant of this item currently has input focus, this function will return...
The QCursor class provides a mouse cursor with an arbitrary shape.
Definition: qcursor.h:89
static mach_timebase_info_data_t info
QGraphicsItem * commonAncestorItem(const QGraphicsItem *other) const
Returns the closest common ancestor item of this item and other, or 0 if either other is 0...
static void children_clear(QDeclarativeListProperty< QGraphicsObject > *list)
unsigned char c[8]
Definition: qnumeric_p.h:62
QGraphicsPolygonItem(QGraphicsItem *parent=0)
Constructs a QGraphicsPolygonItem.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QPointF mapToScene(const QPoint &point) const
Returns the viewport coordinate point mapped to scene coordinates.
QGraphicsWidget * parentWidget() const
Returns a pointer to the item&#39;s parent widget.
const QTransform & transform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9558
QPainterPath shape() const
Reimplemented Function
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
~QGraphicsSimpleTextItem()
Destroys the QGraphicsSimpleTextItem.
QGraphicsEffect * graphicsEffect() const
Returns a pointer to this item&#39;s effect if it has one; otherwise 0.
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
QRectF childrenBoundingRect() const
Returns the bounding rect of this item&#39;s descendants (i.e., its children, their children, etc.) in local coordinates.
void resolveDepth()
Resolves the stacking depth of this object and all its ancestors.
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
Definition: qvariant.cpp:2509
void setLine(const QLineF &line)
Sets the item&#39;s line to be the given line.
void setBoundingRegionGranularity(qreal granularity)
Sets the bounding region granularity to granularity; a value between and including 0 and 1...
void setPosition(const QPointF &pos)
Moves the line to position pos.
void setExtension(Extension extension, const QVariant &variant)
bool acceptDrops() const
Returns true if this item can accept drag and drop events; otherwise, returns false.
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QGraphicsItem::PanelModality panelModality
EventRef event
bool isWindow() const
Returns true if the item is a QGraphicsWidget window, otherwise returns false.
QPointer< QWidget > widget
void setExtension(Extension extension, const QVariant &variant)
virtual void advance(int phase)
This virtual function is called twice for all items by the QGraphicsScene::advance() slot...
void removeFromGroup(QGraphicsItem *item)
Removes the specified item from this group.
void setBrush(const QBrush &brush)
Sets the brush used to fill strokes generated with this pen to the given brush.
Definition: qpen.cpp:808
QList< QGraphicsItem * > childItems() const
Returns a list of this item&#39;s children.
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:661
void resetFocusProxy()
Sets the focusProxy pointer to 0 for all items that have this item as their focusProxy.
void setExtension(Extension extension, const QVariant &variant)
QScopedPointer< QGraphicsItemPrivate > d_ptr
QPainterPath path() const
Returns the item&#39;s path as a QPainterPath.
void setLastPos(const QPointF &pos)
void setTextCursor(const QTextCursor &cursor)
void setSelected(bool selected)
If selected is true and this item is selectable, this item is selected; otherwise, it is unselected.
bool isObscuredBy(const QGraphicsItem *item) const
Reimplemented Function
void removeChild(QGraphicsItem *child)
QGraphicsScenePrivate::unregisterTopLevelItem().
T * data() const
Returns the value of the pointer referenced by this object.
QTransform itemTransform(const QGraphicsItem *other, bool *ok=0) const
Returns a QTransform that maps coordinates from this item to other.
int type() const
Reimplemented Function
int spanAngle() const
Returns the span angle of an ellipse segment in 16ths of a degree.
void setFont(const QFont &font)
Sets the font used to render the text item to font.
QPainterPath opaqueArea() const
Reimplemented Function
bool hasTranslateOnlySceneTransform()
The QMatrix class specifies 2D transformations of a coordinate system.
Definition: qmatrix.h:61
QRectF boundingRect() const
Reimplemented Function
QSizeF size() const
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
#define it(className, varName)
void setTransform(const QTransform &matrix, bool combine=false)
Sets the item&#39;s current transformation matrix to matrix.
QGraphicsLineItem(QGraphicsItem *parent=0)
Constructs a QGraphicsLineItem.
void setMatrix(const QMatrix &matrix, bool combine=false)
Sets the item&#39;s affine transformation matrix.
void scale(qreal sx, qreal sy)
Use.
void setTransformationMode(Qt::TransformationMode mode)
Sets the pixmap item&#39;s transformation mode to mode, and toggles an update of the item.
QTransform sceneTransform() const
Returns this item&#39;s scene transformation matrix.
virtual qreal height() const
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QFont font() const
Returns the font that is used to draw the item&#39;s text.
bool contains(const QPointF &point) const
Reimplemented Function
void setExtension(Extension extension, const QVariant &variant)
bool supportsExtension(Extension extension) const
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
~QAbstractGraphicsShapeItem()
Destroys a QAbstractGraphicsShapeItem.
void setActive(bool active)
If active is true, and the scene is active, this item&#39;s panel will be activated.
QGraphicsObject(QGraphicsItem *parent=0)
Constructs a QGraphicsObject with parent.
bool openExternalLinks() const
Specifies whether QGraphicsTextItem should automatically open links using QDesktopServices::openUrl()...
void setDocument(QTextDocument *document)
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
bool isEnabled() const
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
void remapItemPos(QEvent *event, QGraphicsItem *item)
Maps any item pos properties of event to item&#39;s coordinate system.
QPointF mapFromItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in item&#39;s coordinate system, to this item&#39;s coordinate system...
virtual void inputMethodEvent(QInputMethodEvent *event)
This event handler, for event event, can be reimplemented to receive input method events for this ite...
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QList< QGraphicsItem ** > focusProxyRefs
bool isObscuredBy(const QGraphicsItem *item) const
Reimplemented Function
QString text() const
Returns the item&#39;s text.
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Reimplemented Function
void clearFocus()
Takes keyboard input focus from the item.
void adjustSize()
Adjusts the text item to a reasonable size.
virtual void updateSceneTransformFromParent()
void setPalette(const QPalette &pal)
QTransform transform() const
Returns this item&#39;s transformation matrix.
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
void setParentItem(QGraphicsItem *parent)
Sets this item&#39;s parent item to newParent.
void setCapStyle(Qt::PenCapStyle style)
Sets the cap style of the generated outlines to style.
QGraphicsItemGroup * group() const
Returns a pointer to this item&#39;s item group, or 0 if this item is not member of a group...
virtual bool collidesWithPath(const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
Returns true if this item collides with path.
QGraphicsItem * q_ptr
#define SLOT(a)
Definition: qobjectdefs.h:226
void setToolTip(const QString &toolTip)
Sets the item&#39;s tool tip to toolTip.
The lowest permitted type value for custom items (subclasses of QGraphicsItem or any of the standard ...
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
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
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 ...
FillRule
Definition: qnamespace.h:1485
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
static Qt::MouseButtons buttons
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
QPainterPath subtracted(const QPainterPath &r) const
Returns a path which is p&#39;s fill area subtracted from this path&#39;s fill area.
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
Qt::TextInteractionFlags textInteractionFlags
QPainterPath intersected(const QPainterPath &r) const
Returns a path which is the intersection of this path&#39;s fill area and p&#39;s fill area.
QTextCursor textCursor() const
This property represents the visible text cursor in an editable text item.
void setTransformHelper(const QTransform &transform)
Sets the transform transform.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QGraphicsScene * scene
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QList< QGraphicsItem * > modalPanels
int type() const
Reimplemented Function
Qt::MouseButton button() const
Returns the mouse button (if any) that caused the event.
The QGraphicsEllipseItem class provides an ellipse item that you can add to a QGraphicsScene.
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
QRectF boundingRect() const
Reimplemented Function
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
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Reimplemented Function
uint wasDeleted
Definition: qobject.h:98
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QPointF genericMapFromScene(const QPointF &pos, const QWidget *viewport) const
Maps the point pos from scene to item coordinates.
bool isBlockedByModalPanel(QGraphicsItem **blockingPanel=0) const
Returns true if this item is blocked by a modal panel, false otherwise.
void insert(int i, const T &t)
Inserts value at index position i in the list.
Definition: qlist.h:575
QMatrix sceneMatrix() const
Use sceneTransform() instead.
virtual bool isObscuredBy(const QGraphicsItem *item) const
Returns true if this item&#39;s bounding rect is completely obscured by the opaque shape of item...
The QGraphicsEffectSource class represents the source on which a QGraphicsEffect is installed on...
void setButtonDownPos(Qt::MouseButton button, const QPointF &pos)
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Reimplemented Function
void updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag, AncestorFlag flag=NoFlag, bool enabled=false, bool root=true)
Propagates the ancestor flag flag with value enabled to all this item&#39;s children. ...
void linkHovered(const QString &)
This signal is emitted when the user hovers over a link on a text item that enables Qt::LinksAccessib...
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
GraphicsItemFlag
This enum describes different flags that you can set on an item to toggle different features in the i...
Definition: qgraphicsitem.h:92
QRectF rect() const
Returns the item&#39;s rectangle.
void setEnabledHelper(bool newEnabled, bool explicitly, bool update=true)
Sets this item&#39;s visibility to newEnabled.
QWidget * widget() const
Returns the widget where the event originated, or 0 if the event originates from another application...
QGraphicsItem * focusProxy() const
Returns this item&#39;s focus proxy, or 0 if this item has no focus proxy.
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
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Reimplemented Function
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
ItemSelectionMode
Definition: qnamespace.h:1503
bool contains(const QPointF &point) const
Reimplemented Function
bool intersects(const QRectF &rect) const
Returns true if any point in the given rectangle intersects the path; otherwise returns false...
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse doubleclick events for thi...
void setTabChangesFocus(bool b)
If b is true, the Tab key will cause the widget to change focus; otherwise, the tab key will insert a...
void addItem(QGraphicsItem *item)
Adds or moves the item and all its childen to this scene.
bool isOpacityNull() const
void addChild(QGraphicsItem *child)
QGraphicsScenePrivate::registerTopLevelItem().
qreal levelOfDetail
Use QStyleOptionGraphicsItem::levelOfDetailFromTransform() together with QPainter::worldTransform() i...
Definition: qstyleoption.h:875
void addPolygon(const QPolygonF &polygon)
Adds the given polygon to the path as an (unclosed) subpath.
bool underMouse() const
Returns true if the widget is under the mouse cursor; otherwise returns false.
Definition: qwidget.h:996
void dropEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented Function
QGraphicsSceneIndex * index
static QRectF setupTextLayout(QTextLayout *layout)
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
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition: qpainter.h:573
int start
Specifies the beginning of the format range within the text layout&#39;s text.
Definition: qtextlayout.h:129
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
void updateMicroFocus()
Updates the item&#39;s micro focus.
qreal leftMargin() const
Returns the width of the frame&#39;s left margin in pixels.
QGraphicsItem(QGraphicsItem *parent=0)
Constructs a QGraphicsItem with the given parent item.
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
bool intersects(const QRectF &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:2744
QRectF mapRectToScene(const QRectF &rect) const
Maps the rectangle rect, which is in this item&#39;s coordinate system, to the scene coordinate system...
void combineTransformToParent(QTransform *x, const QTransform *viewTransform=0) const
Combines this item&#39;s position and transform onto transform.
void _q_updateBoundingRect(const QSizeF &)
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
This method is only relevant for input items.
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool contains(const QPointF &pt) const
Returns true if the given point is inside the path, otherwise returns false.
T * qobject_cast(QObject *object)
Definition: qobject.h:375
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
Definition: qvariant.cpp:2463
QRectF boundingRect() const
Reimplemented Function
QRectF boundingRect() const
Reimplemented Function
void keyPressEvent(QKeyEvent *event)
Reimplemented Function
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
QGraphicsItem * mouseGrabberItem() const
Returns the current mouse grabber item, or 0 if no item is currently grabbing the mouse...
PanelModality panelModality() const
Returns the modality for this item.
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented to receive drag enter events for this item...
QString toHtml() const
Returns the item&#39;s text converted to HTML, or an empty QString if no text has been set...
QFont defaultFont
the default font used to display the document&#39;s text
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.
The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display form...
~QGraphicsLineItem()
Destroys the QGraphicsLineItem.
QRectF rect() const
Returns the item&#39;s local rect as a QRectF.
void setText(const QString &text)
Sets the item&#39;s text to text.
virtual void wheelEvent(QGraphicsSceneWheelEvent *event)
This event handler, for event event, can be reimplemented to receive wheel events for this item...
qreal effectiveOpacity() const
Returns this item&#39;s effective opacity, which is between 0.
ShapeMode shapeMode() const
Returns the item&#39;s shape mode.
QGraphicsItemCache * maybeExtraItemCache() const
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented Function
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
QPolygonF polygon() const
Returns the item&#39;s polygon, or an empty polygon if no polygon has been set.
bool isSelected() const
Returns true if this item is selected; otherwise, false is returned.
QVariant inputMethodQuery(Qt::InputMethodQuery query) const
Reimplemented Function
The QGraphicsPolygonItem class provides a polygon item that you can add to a QGraphicsScene.
void setTextCursor(const QTextCursor &cursor)
QTextControl * textControl() const
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 cannot.
#define Q_D(Class)
Definition: qglobal.h:2482
void shear(qreal sh, qreal sv)
Use.
virtual void keyPressEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented to receive key press events for this item...
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
void removeFromIndex()
Removes this item from the scene&#39;s index.
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
bool _q_mouseOnEdge(QGraphicsSceneMouseEvent *)
bool supportsExtension(Extension extension) const
void setAcceptDrops(bool on)
If on is true, this item will accept drag and drop events; otherwise, it is transparent for drag and ...
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
void focusInEvent(QFocusEvent *event)
Reimplemented Function
virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented Function
virtual void processEvent(QEvent *e, const QMatrix &matrix, QWidget *contextWidget=0)
void setVisible(bool visible)
If visible is true, the item is made visible.
void setMiterLimit(qreal length)
Sets the miter limit of the generated outlines to limit.
virtual void setPosHelper(const QPointF &pos)
Sets the position pos.
Qt::WindowType windowType() const
Returns the widgets window type.
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
static QGestureManager * instance()
virtual QPainterPath shape() const
Returns the shape of this item as a QPainterPath in local coordinates.
bool isObscuredBy(const QGraphicsItem *item) const
Reimplemented Function
QTextCursor textCursor() const
void focusOutEvent(QFocusEvent *event)
Reimplemented Function
void setFlags(GraphicsItemFlags flags)
Sets the item flags to flags.
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
bool sendEvent(QGraphicsItem *item, QEvent *event)
Sends event event to item item through possible event filters.
void ensureSceneTransformRecursive(QGraphicsItem **topMostDirtyItem)
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
~QGraphicsPathItem()
Destroys the QGraphicsPathItem.
QMap< const QGraphicsItem *, QMap< int, QVariant > > data
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QSet< QGraphicsItem * > selectedItems
static QPixmap * find(const QString &key)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
qreal scale() const
Returns the scale factor of the item.
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
void grabGesture(Qt::GestureType type, Qt::GestureFlags flags=Qt::GestureFlags())
Subscribes the graphics object to the given gesture with specific flags.
bool close()
Call this function to close the widget.
void setGraphicsEffect(QGraphicsEffect *effect)
Sets effect as the item&#39;s effect.
#define Q_Q(Class)
Definition: qglobal.h:2483
virtual void focusInEvent(QFocusEvent *event)
This event handler, for event event, can be reimplemented to receive focus in events for this item...
QPainterPath shape() const
Reimplemented Function
QTransform viewportTransform() const
Returns a matrix that maps viewport coordinates to scene coordinates.
void setAcceptTouchEvents(bool enabled)
If enabled is true, this item will accept touch events; otherwise, it will ignore them...
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
void keyReleaseEvent(QKeyEvent *event)
Reimplemented Function
QColor defaultTextColor() const
Returns the default text color that is used to for unformatted text.
QList< QGraphicsView * > views
qreal zValue() const
Returns the Z-value of the item.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover leave events for this item...
void ensureVisible(const QRectF &rect, int xmargin=50, int ymargin=50)
Scrolls the contents of the viewport so that the scene rectangle rect is visible, with margins specif...
QCursor cursor() const
Returns the current cursor shape for the item.
QVariant extension(const QVariant &variant) const
QPointF pos() const
Returns the position of the cursor in item coordinates when the wheel event occurred.
QVariant extension(const QVariant &variant) const
virtual void setWidth(qreal)
virtual ~QGraphicsItem()
Destroys the QGraphicsItem and all its children.
void ungrabKeyboard()
Releases the keyboard grab.
QRectF boundingRect() const
Reimplemented Function
QPointF buttonDownScenePos(Qt::MouseButton button) const
Returns the mouse cursor position in scene coordinates where the specified button was clicked...
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
QWidget * viewport() const
Returns the viewport widget.
bool isObscuredBy(const QGraphicsItem *item) const
Reimplemented Function
void move(int from, int to)
Moves the item at index position from to index position to.
Definition: qlist.h:628
QPolygonF translated(qreal dx, qreal dy) const
Returns a copy of the polygon that is translated by ({dx}, {dy}).
Definition: qpolygon.h:182
bool supportsExtension(Extension extension) const
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
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
QVariant extension(const QVariant &variant) const
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QMatrix matrix() const
Returns the item&#39;s affine transformation matrix.
quint32 hasBoundingRegionGranularity
void setFocusHelper(Qt::FocusReason focusReason, bool climb, bool focusFromHide)
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
QRectF boundingRect(Qt::CoordinateSystem system) const
~QGraphicsPolygonItem()
Destroys the QGraphicsPolygonItem.
int startAngle() const
Returns the start angle for an ellipse segment in 16ths of a degree.
static QPainterPath qt_graphicsItem_shapeFromPath(const QPainterPath &path, const QPen &pen)
Returns a QPainterPath of path when stroked with the pen.
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
void setCursor(const QCursor &cursor)
Sets the current cursor shape for the item to cursor.
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
static void _q_adjustRect(QRect *rect)
void setPos(const QPointF &pos)
Sets the position associated with the context menu to the given point in item coordinates.
void inputMethodEvent(QInputMethodEvent *event)
Reimplemented Function
void setPlainText(const QString &text)
Sets the item&#39;s text to text.
QFuture< void > map(Sequence &sequence, MapFunction function)
QString text() const
Returns the layout&#39;s text.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QPainterPath opaqueArea() const
Reimplemented Function
void setZValue(qreal z)
Sets the Z-value of the item to z.
QLineF line() const
Returns the item&#39;s line, or a null line if no line has been set.
const QMatrix & toAffine() const
Returns the QTransform as an affine matrix.
void drawEllipse(const QRectF &r)
Draws the ellipse defined by the given rectangle.
Definition: qpainter.cpp:4464
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
int type() const
Reimplemented Function
QPainterPath opaqueArea() const
Reimplemented Function
qreal topMargin() const
Returns the width of the frame&#39;s top margin in pixels.
void setFillRule(Qt::FillRule rule)
Sets the fill rule of the polygon to rule.
bool isAccepted() const
Definition: qcoreevent.h:307
qreal textWidth() const
void markDirty(QGraphicsItem *item, const QRectF &rect=QRectF(), bool invalidateChildren=false, bool force=false, bool ignoreOpacity=false, bool removingItemFromScene=false, bool updateBoundingRect=false)
QPainterPath createStroke(const QPainterPath &path) const
Generates a new path that is a fillable area representing the outline of the given path...
QGraphicsItem * focusItem() const
When the scene is active, this functions returns the scene&#39;s current focus item, or 0 if no item curr...
QRectF mapRectFromScene(const QRectF &rect) const
Maps the rectangle rect, which is in scene coordinates, to this item&#39;s coordinate system...
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Reimplemented Function
void setPos(const QPointF &pos)
bool isUnderMouse() const
Returns true if this item is currently under the mouse cursor in one of the views; otherwise...
qreal bottomMargin() const
Returns the width of the frame&#39;s bottom margin in pixels.
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Reimplemented Function
void setAcceptsHoverEvents(bool enabled)
Use setAcceptHoverEvents(enabled) instead.
void purge()
Empty all cached pixmaps from the pixmap cache.
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
void setCacheMode(CacheMode mode, const QSize &cacheSize=QSize())
Sets the item&#39;s cache mode to mode.
virtual bool isProxyWidget() const
void setFiltersChildEvents(bool enabled)
If enabled is true, this item is set to filter all events for all its children (i.
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QPointF scenePos() const
Returns the item&#39;s position in scene coordinates.
~QGraphicsTextItem()
Destroys the QGraphicsTextItem.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool contains(const QPointF &point) const
Reimplemented Function
void setHandlesChildEvents(bool enabled)
If enabled is true, this item is set to handle all events for all its children (i.
void removeItem(QGraphicsItem *item)
Removes the item item and all its children from the scene.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void resetMatrix()
Use resetTransform() instead.
~QGraphicsPixmapItem()
Destroys the QGraphicsPixmapItem.
~QGraphicsItemGroup()
Destroys the QGraphicsItemGroup.
QVariant data(int key) const
Returns this item&#39;s custom data for the key key as a QVariant.
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
#define qApp
bool itemIsUntransformable() const
QAbstractGraphicsShapeItem(QGraphicsItem *parent=0)
Constructs a QAbstractGraphicsShapeItem.
virtual void resetWidth()
QPalette palette() const
virtual void applyTo(QMatrix4x4 *matrix) const =0
This pure virtual method has to be reimplemented in derived classes.
QString toHtml() const
void initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform, const QRegion &exposedRegion, bool allItems=false) const
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
void setOpenExternalLinks(bool open)
quint32 paintedViewBoundingRectsNeedRepaint
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal textWidth() const
Returns the text width.
virtual bool collidesWithItem(const QGraphicsItem *other, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
Returns true if this item collides with other; otherwise returns false.
const T value(const Key &key) const
Returns the value associated with the key key.
Definition: qmap.h:499
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
static void children_append(QDeclarativeListProperty< QGraphicsObject > *list, QGraphicsObject *item)
QGraphicsItem * panel() const
Returns the item&#39;s panel, or 0 if this item does not have a panel.
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis)
Rotates the coordinate system counterclockwise by the given angle about the specified axis and return...
Definition: qtransform.cpp:615
void rotate(qreal angle)
Use.
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
QGraphicsObject * parentObject() const
Returns a pointer to the item&#39;s parent, cast to a QGraphicsObject.
static bool movableAncestorIsSelected(const QGraphicsItem *item)
bool isObscuredBy(const QGraphicsItem *item) const
Reimplemented Function
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
const char * layout
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
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover move events for this item...
void setPos(const QPointF &pos)
void scroll(int dx, int dy, int x, int y, int width, int height, QRegion *exposed=0)
Definition: qpixmap.h:307
void setHtml(const QString &text)
QPointF pos() const
Returns the position of the mouse cursor in item coordinates at the moment the context menu was reque...
QGraphicsEffect * graphicsEffect
QBrush brush() const
Returns the item&#39;s brush, or an empty brush if no brush has been set.
int type() const
Reimplemented Function
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
QRectF rect() const
Returns the item&#39;s ellipse geometry as a QRectF.
virtual int type() const
Returns the type of an item as an int.
void setData(int key, const QVariant &value)
Sets this item&#39;s custom data for the key key to value.
void setPen(const QPen &pen)
Sets the pen for this item to pen.
TransformationMode
Definition: qnamespace.h:1510
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
void setPath(const QPainterPath &path)
Sets the item&#39;s path to be the given path.
int type() const
Reimplemented Function
virtual void prepareBoundingRectChange(const QGraphicsItem *item)
Notify the index for a geometry change of an item.
QGraphicsItem * itemAt(const QPoint &pos) const
Returns the item at position pos, which is in viewport coordinates.
ShapeMode
This enum describes how QGraphicsPixmapItem calculates its shape and opaque area. ...
Q_CORE_EXPORT void qWarning(const char *,...)
bool supportsExtension(Extension extension) const
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...
QPen pen() const
Returns the item&#39;s pen, or a black solid 0-width pen if no pen has been set.
int type() const
Reimplemented Function
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition: qmatrix4x4.h:63
bool acceptTouchEvents() const
Returns true if an item accepts touch events; otherwise, returns false.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void setFocusItem(QGraphicsItem *item, Qt::FocusReason focusReason=Qt::OtherFocusReason)
Sets the scene&#39;s focus item to item, with the focus reason focusReason, after removing focus from any...
unsigned int uint
Definition: qglobal.h:996
void ensureVisible(const QRectF &rect=QRectF(), int xmargin=50, int ymargin=50)
If this item is part of a scene that is viewed by a QGraphicsView, this convenience function will att...
bool contains(const QPointF &point) const
Reimplemented Function
void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
Definition: qwidget_p.h:669
QList< QGraphicsTransform * > transformations() const
Returns a list of graphics transforms that currently apply to this item.
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.
bool supportsExtension(Extension extension) const
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QRectF mapRectToParent(const QRectF &rect) const
Maps the rectangle rect, which is in this item&#39;s coordinate system, to its parent&#39;s coordinate system...
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
Draws the polygon defined by the first pointCount points in the array points using the current pen an...
Definition: qpainter.cpp:5205
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QPainterPathStroker class is used to generate fillable outlines for a given painter path...
Definition: qpainterpath.h:264
qreal rotation() const
Returns the clockwise rotation, in degrees, around the Z axis.
QList< Key > keys() const
Returns a list containing all the keys in the map in ascending order.
Definition: qmap.h:818
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented Function
QGraphicsItem * topLevelItem() const
Returns this item&#39;s top-level item.
void clearFocusHelper(bool giveFocusToParent)
void setIsMemberOfGroup(bool enabled)
Propagates item group membership.
Qt::InputMethodHints inputMethodHints() const
Returns the current input method hints of this item.
void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented Function
QGraphicsPathItem(QGraphicsItem *parent=0)
Constructs a QGraphicsPath.
void draw(QPainter *p, const QPointF &pos, const QVector< FormatRange > &selections=QVector< FormatRange >(), const QRectF &clip=QRectF()) const
Draws the whole layout on the painter p at the position specified by pos.
virtual bool supportsExtension(Extension extension) const
Note: This is provided as a hook to avoid future problems related to adding virtual functions...
virtual void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented to receive drag leave events for this item...
QPainterPath opaqueArea() const
Reimplemented Function
void setDocument(QTextDocument *document)
Sets the text document document on the item.
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
QVariant extension(const QVariant &variant) const
void setX(qreal x)
Set&#39;s the x coordinate of the item&#39;s position.
QPainterPath opaqueArea() const
Reimplemented Function
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
This event handler can be reimplemented in a subclass to process context menu events.
bool contains(const QPointF &point) const
Reimplemented Function
QGraphicsItem * activePanel() const
Returns the current active panel, or 0 if no panel is currently active.
int type() const
Reimplemented Function
PixmapPadMode
This enum describes how the pixmap returned from sourcePixmap should be padded.
virtual QPainterPath opaqueArea() const
This virtual function returns a shape representing the area where this item is opaque.
bool openExternalLinks
QPainterPath opaqueArea() const
Reimplemented Function
QVariant extra(Extra type) const
QAbstractDeclarativeData * declarativeData
Definition: qobject_p.h:214
void translate(qreal dx, qreal dy)
Moves the rectangle dx along the x-axis and dy along the y-axis, relative to the current position...
Definition: qrect.h:716
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
QList< QGraphicsItem * > selectedItems() const
Returns a list of all currently selected items.
GestureType
Definition: qnamespace.h:1759
QPixmap pixmap() const
Returns the item&#39;s pixmap, or an invalid QPixmap if no pixmap has been set.
qreal boundingRegionGranularity() const
Returns the item&#39;s bounding region granularity; a value between and including 0 and 1...
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
void resetTransform()
Resets this item&#39;s transformation matrix to the identity matrix or all the transformation properties ...
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
QInputContext * inputContext()
This function returns the QInputContext for this widget.
Definition: qwidget.cpp:474
Q_CORE_EXPORT bool qIsNaN(double d)
Returns true if the double {d} is not a number (NaN).
Definition: qnumeric.cpp:55
quint32 mayHaveChildWithGraphicsEffect
void setSize(const QSizeF &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:790
QPen pen() const
Returns the item&#39;s pen.
QGraphicsWidget * topLevelWidget() const
Returns a pointer to the item&#39;s top level widget (i.
void clearSubFocus(QGraphicsItem *rootItem=0, QGraphicsItem *stopItem=0)
void setPixmap(const QPixmap &pixmap)
Sets the item&#39;s pixmap to pixmap.
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
void unsetCursor()
Clears the cursor from this item.
QTextDocument * document() const
QMap< Qt::GestureType, Qt::GestureFlags > gestureContext
QTransform toTransform() const
Returns the conventional Qt 2D transformation matrix that corresponds to this matrix.
void setTransformations(const QList< QGraphicsTransform *> &transformations)
Sets a list of graphics transformations (QGraphicsTransform) that currently apply to this item...
bool isAncestorOf(const QGraphicsItem *child) const
Returns true if this item is an ancestor of child (i.e., if this item is child&#39;s parent, or one of child&#39;s parent&#39;s ancestors).
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s scene&#39;s coordinate system, to this item&#39;s coordinate sy...
void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
Reimplemented Function
void setMouseTracking(bool enable)
Definition: qwidget.h:990
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented Function
void update(qreal x, qreal y, qreal w, qreal h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QTransform deviceTransform(const QTransform &viewportTransform) const
Returns this item&#39;s device transformation matrix, using viewportTransform to map from scene to device...
QFont font() const
Returns the item&#39;s font, which is used to render the text.
void setTransformOriginPoint(const QPointF &origin)
Sets the origin point for the transformation in item coordinates.
~QGraphicsEllipseItem()
Destroys the QGraphicsEllipseItem.
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
InputMethodQuery
Definition: qnamespace.h:1541
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
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
QRectF mapRectToItem(const QGraphicsItem *item, const QRectF &rect) const
Maps the rectangle rect, which is in this item&#39;s coordinate system, to item&#39;s coordinate system...
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
void installSceneEventFilter(QGraphicsItem *filterItem)
Installs an event filter for this item on filterItem, causing all events for this item to first pass ...
void setInputMethodHints(Qt::InputMethodHints hints)
Sets the current input method hints of this item to hints.
QPointF pos
the position of the item
QPoint mapFromScene(const QPointF &point) const
Returns the scene coordinate point to viewport coordinates.
bool isActive() const
Returns true if the scene is active (e.
const QBrush & windowText() const
Returns the window text (general foreground) brush of the current color group.
Definition: qpalette.h:124
void setActivePanel(QGraphicsItem *item)
Activates item, which must be an item in this scene.
void grabKeyboard()
Grabs the keyboard input.
void ensureSequentialSiblingIndex()
Ensures that the list of children is sorted by insertion order, and that the siblingIndexes are packe...
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
virtual void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented to receive drag move events for this item...
bool hasCursor() const
Returns true if this item has a cursor set; otherwise, false is returned.
The QGraphicsSimpleTextItem class provides a simple text path item that you can add to a QGraphicsSce...
QGraphicsRectItem(QGraphicsItem *parent=0)
Constructs a QGraphicsRectItem.
The QGraphicsLineItem class provides a line item that you can add to a QGraphicsScene.
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QGraphicsTextItem(QGraphicsItem *parent=0)
Constructs a QGraphicsTextItem.
QGraphicsItemGroup(QGraphicsItem *parent=0)
Constructs a QGraphicsItemGroup.
QPointF mapToItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to item&#39;s coordinate system...
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
bool isSignalConnected(uint signalIdx) const
Returns true if the signal with index signal_index from object sender is connected.
Definition: qobject_p.h:237
qreal angle(const QPointF &p1, const QPointF &p2)
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
void selectionChanged()
This signal is emitted by QGraphicsScene whenever the selection changes.
bool handlesChildEvents() const
Returns true if this item handles child events (i.
CacheMode
This enum describes QGraphicsItem&#39;s cache modes.
void setExtension(Extension extension, const QVariant &variant)
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QString toPlainText() const
QRegion boundingRegion(const QTransform &itemToDeviceTransform) const
Returns the bounding region for this item.
static bool qt_QGraphicsItem_isObscured(const QGraphicsItem *item, const QGraphicsItem *other, const QRectF &rect)
Item obscurity helper function.
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Reimplemented Function
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
QDeclarativeListProperty< QGraphicsObject > childrenList()
Returns a list of this item&#39;s children.
QPainterPath shape() const
Reimplemented Function
qreal y() const
This convenience function is equivalent to calling pos().
const QTransform & worldTransform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9652
The QAbstractGraphicsShapeItem class provides a common base for all path items.
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
Reimplemented Function
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover enter events for this item...
The QGraphicsSceneDragDropEvent class provides events for drag and drop in the graphics view framewor...
FocusReason
Definition: qnamespace.h:1521
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
QBitmap mask() const
Extracts a bitmap mask from the pixmap&#39;s alpha channel.
Definition: qpixmap.cpp:2077
virtual QVariant extension(const QVariant &variant) const
Note: This is provided as a hook to avoid future problems related to adding virtual functions...
QRectF controlPointRect() const
Returns the rectangle containing all the points and control points in this path.
void prepareGeometryChange()
Prepares the item for a geometry change.
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
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
void setVisibleHelper(bool newVisible, bool explicitly, bool update=true)
Sets this item&#39;s visibility to newVisible.
void stackBefore(const QGraphicsItem *sibling)
Stacks this item before sibling, which must be a sibling item (i.
QPixmapCache::Key key
bool isPanel() const
Returns true if the item is a panel; otherwise returns false.
QMatrix matrix
the complete transformation matrix for the item
Definition: qstyleoption.h:874
QRect toRect() const
Returns the variant as a QRect if the variant has type() Rect ; otherwise returns an invalid QRect...
Definition: qvariant.cpp:2416
virtual void dropEvent(QGraphicsSceneDragDropEvent *event)
This event handler, for event event, can be reimplemented to receive drop events for this item...
QList< QGraphicsTransform * > graphicsTransforms
#define store(x)
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
virtual qreal width() const
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
QString toolTip() const
Returns the item&#39;s tool tip, or an empty QString if no tool tip has been set.
virtual void transformChanged()
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
bool updateRect(const QRect &rect)
void arcTo(const QRectF &rect, qreal startAngle, qreal arcLength)
Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending...
void clearSelection()
Clears the current selection.
void prependGraphicsTransform(QGraphicsTransform *t)
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
bool isObscuredBy(const QGraphicsItem *item) const
Reimplemented Function
QGraphicsItem * focusScopeItem
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setPolygon(const QPolygonF &polygon)
Sets the item&#39;s polygon to be the given polygon.
void setAcceptHoverEvents(bool enabled)
If enabled is true, this item will accept hover events; otherwise, it will ignore them...
qreal x() const
This convenience function is equivalent to calling pos().
void setPanelModality(PanelModality panelModality)
Sets the modality for this item to panelModality.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented Function
void setY(qreal y)
Set&#39;s the y coordinate of the item&#39;s position.
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style of the generated outlines to style.
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
Reimplemented Function
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201
void setExtension(Extension extension, const QVariant &variant)
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
static int children_count(QDeclarativeListProperty< QGraphicsObject > *list)
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
qreal rightMargin() const
Returns the width of the frame&#39;s right margin in pixels.
void setGroup(QGraphicsItemGroup *group)
Adds this item to the item group group.
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
Definition: qtextformat.h:727
unsigned int quint32
Definition: qglobal.h:938
void setExtension(Extension extension, const QVariant &variant)
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
Qt::TransformationMode transformationMode() const
Returns the transformation mode of the pixmap.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented Function
bool isEmpty() const
Returns true if the map contains no items; otherwise returns false.
Definition: qmap.h:203
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Reimplemented Function
bool sceneEvent(QEvent *event)
Reimplemented Function
void setSubFocus(QGraphicsItem *rootItem=0, QGraphicsItem *stopItem=0)
QGraphicsPixmapItem(QGraphicsItem *parent=0)
Constructs a QGraphicsPixmapItem.
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
virtual QRectF boundingRectFor(const QRectF &sourceRect) const
Returns the effective bounding rectangle for this effect, given the provided rect in the device coord...
QGraphicsWidget * window() const
Returns the item&#39;s window, or 0 if this item does not have a window.
void addToGroup(QGraphicsItem *item)
Adds the given item and item&#39;s child items to this item group.
static void(* destroyed)(QAbstractDeclarativeData *, QObject *)
Definition: qobject_p.h:93
bool isObscuredBy(const QGraphicsItem *item) const
Reimplemented Function
QString objectName() const
void setExtra(Extra type, const QVariant &value)
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
if(void) toggleToolbarShown
QPointF pos() const
Returns the position of the mouse cursor in item coordinates at the moment the hover event was sent...
bool acceptsHoverEvents() const
Call acceptHoverEvents() instead.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void childrenBoundingRectHelper(QTransform *x, QRectF *rect, QGraphicsItem *topMostEffectItem)
Returns the bounding rect of this item&#39;s children (excluding itself).
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
Sets the flags flags to specify how the text item should react to user input.
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
QRect paddedEffectRect(Qt::CoordinateSystem system, QGraphicsEffect::PixmapPadMode mode, const QRectF &sourceRect, bool *unpadded=0) const
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
bool isWidget() const
Returns true if this item is a widget (i.
QPainterPath opaqueArea() const
Reimplemented Function
QPainterPath clipPath() const
Returns this item&#39;s clip path, or an empty QPainterPath if this item is not clipped.
QPoint buttonDownScreenPos(Qt::MouseButton button) const
Returns the mouse cursor position in screen coordinates where the specified button was clicked...
virtual bool contains(const QPointF &point) const
Returns true if this item contains point, which is in local coordinates; otherwise, false is returned.
bool isNull() const
Returns true if both the x and y coordinates are set to +0.
Definition: qpoint.h:277
void setRect(const QRectF &rect)
Sets the item&#39;s rectangle to be the given rectangle.
Qt::FocusReason reason()
Definition: qevent.cpp:1197
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
bool contains(const Key &key) const
Returns true if the map contains an item with key key; otherwise returns false.
Definition: qmap.h:553
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9630
virtual void subFocusItemChange()
Subclasses can reimplement this function to be notified when subFocusItem changes.
void setDefaultTextColor(const QColor &c)
Sets the color for unformatted text to col.
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QVector< QRectF > exposed
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
void setPos(const QPointF &pos)
Sets the position associated with the hover event to the given point in item coordinates.
QPainterPath opaqueArea() const
Reimplemented Function
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
QGraphicsEllipseItem(QGraphicsItem *parent=0)
Constructs a QGraphicsEllipseItem.
static const QGraphicsItemPrivate * get(const QGraphicsItem *item)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
The QGraphicsItemGroup class provides a container that treats a group of items as a single item...
void combineTransformFromParent(QTransform *x, const QTransform *viewTransform=0) const
Combines this item&#39;s position and transform onto transform.
quint16 index
QPoint mapFromGlobal(const QPoint &) const
Translates the global screen coordinate pos to widget coordinates.
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void scroll(qreal dx, qreal dy, const QRectF &rect=QRectF())
Scrolls the contents of rect by dx, dy.
QPainterPath shape() const
Reimplemented Function
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void drawContents(QPainter *painter, const QRectF &rect=QRectF(), QWidget *widget=0)
Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath(const QRegion &region)
Definition: qregion.cpp:1160
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
QVariant extension(const QVariant &variant) const
QPointF pos() const
Returns the mouse cursor position in item coordinates.
QPointF buttonDownPos(Qt::MouseButton button) const
Returns the mouse cursor position in item coordinates where the specified button was clicked...
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
Definition: qpainter.cpp:3234
QVariant extension(const QVariant &variant) const
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
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281
QPainterPath shape() const
Reimplemented Function
int length
Specifies the numer of characters the format range spans.
Definition: qtextlayout.h:130
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
Sets the mouse buttons that this item accepts mouse events for.
Qt::FillRule fillRule() const
Returns the fill rule of the polygon.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)=0
This function, which is usually called by QGraphicsView, paints the contents of an item in local coor...
TransformData * transformData
bool contains(const QPointF &point) const
Reimplemented Function
bool contains(const QPointF &point) const
Reimplemented Function
bool isVisibleTo(const QGraphicsItem *parent) const
Returns true if the item is visible to parent; otherwise, false is returned.
QPixmap pixmap(Qt::CoordinateSystem system, QPoint *offset, QGraphicsEffect::PixmapPadMode mode) const
friend bool qt_closestItemFirst(const QGraphicsItem *, const QGraphicsItem *)
Returns true if item1 is on top of item2.
QRectF mapRectFromItem(const QGraphicsItem *item, const QRectF &rect) const
Maps the rectangle rect, which is in item&#39;s coordinate system, to this item&#39;s coordinate system...
QTextCharFormat format
Specifies the format to apply.
Definition: qtextlayout.h:131
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
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 setScale(qreal scale)
Sets the scale factor of the item.
static void remove(const QString &key)
Removes the pixmap associated with key from the cache.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
void setTextWidth(qreal width)
Sets the preferred width for the item&#39;s text.
void setFont(const QFont &f)
Sets the painter&#39;s font to the given font.
Definition: qpainter.cpp:4288
bool isObscuredBy(const QGraphicsItem *item) const
Reimplemented Function
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
QTransform & scale(qreal sx, qreal sy)
Scales the coordinate system by sx horizontally and sy vertically, and returns a reference to the mat...
Definition: qtransform.cpp:485
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
void setEnabled(bool enabled)
If enabled is true, the item is enabled; otherwise, it is disabled.
static QTransform fromScale(qreal dx, qreal dy)
Creates a matrix which corresponds to a scaling of sx horizontally and sy vertically.
Definition: qtransform.cpp:528
bool intersects(const QRect &r) const
Returns true if this rectangle intersects with the given rectangle (i.
Definition: qrect.cpp:1429
void setCacheEnabled(bool enable)
Enables caching of the complete layout information if enable is true; otherwise disables layout cachi...
bool acceptHoverEvents() const
Returns true if an item accepts hover events (QGraphicsSceneHoverEvent); otherwise, returns false.
bool isObscuredBy(const QGraphicsItem *item) const
Reimplemented Function
void setTextWidth(qreal width)
virtual void setExtension(Extension extension, const QVariant &variant)
Note: This is provided as a hook to avoid future problems related to adding virtual functions...
qreal opacity() const
Returns this item&#39;s local opacity, which is between 0.
~QGraphicsRectItem()
Destroys the QGraphicsRectItem.
void ungrabMouse()
Releases the mouse grab.
bool _qt_movableAncestorIsSelected(const QGraphicsItem *item)
obsolete
QGraphicsItemCache * extraItemCache() const
void endLayout()
Ends the layout process.
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
const char * variant
QTransform transformToParent() const
virtual QVariant inputMethodQueryHelper(Qt::InputMethodQuery query) const
This helper function helped us add input method query support in Qt 4.
QRectF boundingRect() const
Reimplemented Function
The QGraphicsSceneWheelEvent class provides wheel events in the graphics view framework.
QList< QGraphicsItem * > items() const
Returns a list of all the items in the associated scene, in descending stacking order (i...
QRectF boundingRect() const
Reimplemented Function
Qt::TransformationMode transformationMode
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Reimplemented Function
Extension
Note: This is provided as a hook to avoid future problems related to adding virtual functions...
The QInputContext class abstracts the input method dependent data and composing state.
Definition: qinputcontext.h:83
static QGraphicsObject * children_at(QDeclarativeListProperty< QGraphicsObject > *list, int)
bool supportsExtension(Extension extension) const
void translate(qreal dx, qreal dy)
Use setPos() or setTransformOriginPoint() instead.
virtual void keyReleaseEvent(QKeyEvent *event)
This event handler, for event event, can be reimplemented to receive key release events for this item...
bool isObscuredBy(const QGraphicsItem *item) const
Reimplemented Function
QList< QGraphicsItem * > children
void setViewport(const QRectF &viewport)
QPointF mapFromParent(const QPointF &point) const
Maps the point point, which is in this item&#39;s parent&#39;s coordinate system, to this item&#39;s coordinate s...
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QRectF translated(qreal dx, qreal 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:740
void setRotation(qreal angle)
Sets the clockwise rotation angle, in degrees, around the Z axis.
void setOpacity(qreal opacity)
Sets this item&#39;s local opacity, between 0.
QString toPlainText() const
Returns the item&#39;s text converted to plain text, or an empty QString if no text has been set...
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
QDebug operator<<(QDebug debug, QGraphicsItem *item)
QRectF exposedRect
the exposed rectangle, in item coordinates
Definition: qstyleoption.h:873
virtual void siblingOrderChange()
Subclasses can reimplement this function to be notified when its siblingIndex order is changed...
QGraphicsSimpleTextItem(QGraphicsItem *parent=0)
Constructs a QGraphicsSimpleTextItem.
QGraphicsTextItemPrivate * dd
QGraphicsItem * focusProxy
QImageIOHandler * handler
QGraphicsTextItem * qq
PanelModality
This enum specifies the behavior of a modal panel.
QTextDocument * document() const
Returns the item&#39;s text document.
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
void ungrabGesture(Qt::GestureType type)
Unsubscribes the graphics object from the given gesture.
QPointF offset() const
Returns the pixmap item&#39;s offset, which defines the point of the top-left corner of the pixmap...
The QGraphicsObject class provides a base class for all graphics items that require signals...
void markParentDirty(bool updateBoundingRect=false)
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
QList< QGraphicsItem * > collidingItems(const QGraphicsItem *item, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
Returns a list of all items that collide with item.
QBitmap createHeuristicMask(bool clipTight=true) const
Creates and returns a heuristic mask for this pixmap.
Definition: qpixmap.cpp:864
void draw(QGraphicsItem *, QPainter *, const QTransform *const, const QTransform *const, QRegion *, QWidget *, qreal, const QTransform *const, bool, bool)
QPainterPath shape() const
Reimplemented Function
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
virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
Filters events for the item watched.
virtual void focusScopeItemChange(bool isSubFocusItem)
Subclasses can reimplement this function to be notified when an item becomes a focusScopeItem (or is ...
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
QGraphicsEffectSource * source() const
Returns a pointer to the source, which provides extra context information that can be useful for the ...
The QGraphicsPixmapItem class provides a pixmap item that you can add to a QGraphicsScene.
static void qt_graphicsItem_highlightSelected(QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option)
Highlights item as selected.
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to the scene&#39;s coordinate system...
void setOffset(const QPointF &offset)
Sets the pixmap item&#39;s offset to offset.
virtual void resetHeight()
virtual void focusOutEvent(QFocusEvent *event)
This event handler, for event event, can be reimplemented to receive focus out events for this item...
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...
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
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244
QRectF boundingRect() const
Reimplemented Function
void setRect(const QRectF &rect)
Sets the item&#39;s ellipse geometry to rect.
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
void updateChildWithGraphicsEffectFlagRecursively()
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
QRectF sceneBoundingRect() const
Returns the bounding rect of this item in scene coordinates, by combining sceneTransform() with bound...
static void _q_qgraphicsItemSetFlag(QGraphicsItem *item, QGraphicsItem::GraphicsItemFlag flag, bool enabled)
Sets the flag flag on item and all its children, to enabled.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QPainterPath opaqueArea() const
Reimplemented Function
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
QPainterPath shape() const
Reimplemented Function
qreal height() const
Returns the line&#39;s height.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse release events for this it...
void linkActivated(const QString &)
This signal is emitted when the user clicks on a link on a text item that enables Qt::LinksAccessible...
int type() const
Reimplemented Function
QRectF boundingRect() const
Returns the bounding rect of this group item, and all its children.
QVariant extension(const QVariant &variant) const
QList< QGraphicsItem * > children() const
Use childItems() instead.
The QGraphicsTransform class is an abstract base class for building advanced transformations on QGrap...
#define enabled
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
void updatePaintedViewBoundingRects(bool updateChildren)
void setBrush(const QBrush &brush)
Sets the item&#39;s brush to brush.
QPoint toPoint() const
Returns the variant as a QPoint if the variant has type() Point or PointF ; otherwise returns a null ...
Definition: qvariant.cpp:2400
bool supportsExtension(Extension extension) const
bool isObscured() const
Returns true if this item&#39;s bounding rect is completely obscured by the opaque shape of any of collid...
CacheMode cacheMode() const
Returns the cache mode for this item.
void beginLayout()
Begins the layout process.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
bool discardUpdateRequest(bool ignoreVisibleBit=false, bool ignoreDirtyBit=false, bool ignoreOpacity=false) const
Returns true if we can discard an update request; otherwise false.
bool end()
Ends painting.
Definition: qpainter.cpp:1929
virtual void setHeight(qreal)
int type() const
Reimplemented Function
The QMap class is a template class that provides a skip-list-based dictionary.
Definition: qdatastream.h:67
void removeSceneEventFilter(QGraphicsItem *filterItem)
Removes an event filter on this item from filterItem.
void grabMouse()
Grabs the mouse input.
void addEllipse(const QRectF &rect)
Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed...
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740
QPainterPath opaqueArea() const
Reimplemented Function
int open(const char *, int,...)
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
QVariant extension(const QVariant &variant) const
#define text
Definition: qobjectdefs.h:80
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
Definition: qcursor_mac.mm:310
int lineCount() const
Returns the number of lines in this text layout.
QPointF mapToParent(const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to its parent&#39;s coordinate system...
QPainterPath shape() const
Reimplemented Function
void invalidateChildGraphicsEffectsRecursively(InvalidateReason reason)
The QGraphicsEffect class is the base class for all graphics effects.
QRectF mapRectFromParent(const QRectF &rect) const
Maps the rectangle rect, which is in this item&#39;s parent&#39;s coordinate system, to this item&#39;s coordinat...
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
qreal effectiveOpacity() const
void addToIndex()
Adds this item to the scene&#39;s index.
void setWidth(qreal width)
Sets the width of the generated outline painter path to width.
The QGraphicsPathItem class provides a path item that you can add to a QGraphicsScene.
QList< QGraphicsWidget * > popupWidgets
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
void setHtml(const QString &html)
Sets the item&#39;s text to text, assuming that text is HTML formatted.
QPainterPath translated(qreal dx, qreal dy) const
Returns a copy of the path that is translated by ({dx}, {dy}).
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
Qt::MouseButtons acceptedMouseButtons() const
Returns the mouse buttons that this item accepts mouse events for.
MouseButton
Definition: qnamespace.h:150
bool tabChangesFocus() const
Returns true if the Tab key will cause the widget to change focus; otherwise, false is returned...
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 QGraphicsSceneContextMenuEvent class provides context menu events in the graphics view framework...
void setOpenExternalLinks(bool open)
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
QList< QGraphicsItem * > collidingItems(Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
Returns a list of all items that collide with this item.
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480
bool supportsExtension(Extension extension) const