summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview/qgraphicsitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/graphicsview/qgraphicsitem.cpp')
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp143
1 files changed, 87 insertions, 56 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 9fc3fa1..4fead4b 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -91,30 +91,33 @@
\snippet doc/src/snippets/code/src_gui_graphicsview_qgraphicsitem.cpp 0
- The boundingRect() function has many different purposes. QGraphicsScene
- bases its item index on boundingRect(), and QGraphicsView uses it both for
- culling invisible items, and for determining the area that needs to be
- recomposed when drawing overlapping items. In addition, QGraphicsItem's
- collision detection mechanisms use boundingRect() to provide an efficient
- cut-off. The fine grained collision algorithm in collidesWithItem() is based
- on calling shape(), which returns an accurate outline of the item's shape
- as a QPainterPath.
-
- QGraphicsScene expects all items boundingRect() and shape() to remain
- unchanged unless it is notified. If you want to change an item's geometry
- in any way, you must first call prepareGeometryChange() to allow
- QGraphicsScene to update its bookkeeping.
+ The boundingRect() function has many different purposes.
+ QGraphicsScene bases its item index on boundingRect(), and
+ QGraphicsView uses it both for culling invisible items, and for
+ determining the area that needs to be recomposed when drawing
+ overlapping items. In addition, QGraphicsItem's collision
+ detection mechanisms use boundingRect() to provide an efficient
+ cut-off. The fine grained collision algorithm in
+ collidesWithItem() is based on calling shape(), which returns an
+ accurate outline of the item's shape as a QPainterPath.
+
+ QGraphicsScene expects all items boundingRect() and shape() to
+ remain unchanged unless it is notified. If you want to change an
+ item's geometry in any way, you must first call
+ prepareGeometryChange() to allow QGraphicsScene to update its
+ bookkeeping.
Collision detection can be done in two ways:
\list 1
- \o Reimplement shape() to return an accurate shape for your item, and rely
- on the default implementation of collidesWithItem() to do shape-shape
- intersection. This can be rather expensive if the shapes are complex.
+ \o Reimplement shape() to return an accurate shape for your item,
+ and rely on the default implementation of collidesWithItem() to do
+ shape-shape intersection. This can be rather expensive if the
+ shapes are complex.
- \o Reimplement collidesWithItem() to provide your own custom item and shape
- collision algorithm.
+ \o Reimplement collidesWithItem() to provide your own custom item
+ and shape collision algorithm.
\endlist
@@ -136,24 +139,28 @@
position, pos(). To change the item's transformation, you can pass
a transformation matrix to setTransform()
- Item transformations accumulate from parent to child, so if both a parent and child
- item are rotated 90 degrees, the child's total transformation will be 180 degrees.
- Similarly, if the item's parent is scaled to 2x its original size, its
- children will also be twice as large. An item's transformation does not
- affect its own local geometry; all geometry functions (e.g., contains(),
+ Item transformations accumulate from parent to child, so if both a
+ parent and child item are rotated 90 degrees, the child's total
+ transformation will be 180 degrees. Similarly, if the item's
+ parent is scaled to 2x its original size, its children will also
+ be twice as large. An item's transformation does not affect its
+ own local geometry; all geometry functions (e.g., contains(),
update(), and all the mapping functions) still operate in local
coordinates. For convenience, QGraphicsItem provides the functions
- sceneTransform(), which returns the item's total transformation matrix
- (including its position and all parents' positions and transformations),
- and scenePos(), which returns its position in scene coordinates. To reset
- an item's matrix, call resetTransform().
+ sceneTransform(), which returns the item's total transformation
+ matrix (including its position and all parents' positions and
+ transformations), and scenePos(), which returns its position in
+ scene coordinates. To reset an item's matrix, call
+ resetTransform().
- Another way to apply transformation to an item is to use the , or set the
- different transformation properties (transformOrigin, x/y/zRotation, x/yScale,
- horizontal/verticalShear). Those properties come in addition to the base transformation
+ Another way to apply transformation to an item is to use the , or
+ set the different transformation properties (transformOrigin,
+ x/y/zRotation, x/yScale, horizontal/verticalShear). Those
+ properties come in addition to the base transformation
- The order you set the transformation properties does not affect the resulting transformation
- The resulting transformation is always computed in the following order
+ The order you set the transformation properties does not affect
+ the resulting transformation The resulting transformation is
+ always computed in the following order
\code
[Origin] [Base] [RotateX] [RotateY] [RotateZ] [Shear] [Scale] [-Origin]
@@ -820,7 +827,7 @@ void QGraphicsItemPrivate::combineTransformFromParent(QTransform *x, const QTran
} else {
x->translate(pos.x(), pos.y());
if (transformData)
- *x = transformData->computedFullTransform() * *x;
+ *x = transformData->computedFullTransform(x);
}
}
@@ -2572,8 +2579,8 @@ QPointF QGraphicsItem::pos() const
\sa y()
*/
-/*
- Set's the x coordinate of the item's position. Equivalent to
+/*!
+ Set's the \a x coordinate of the item's position. Equivalent to
calling setPos(x, y()).
\sa x(), setPos()
@@ -2591,8 +2598,8 @@ void QGraphicsItem::setX(qreal x)
\sa x()
*/
-/*
- Set's the y coordinate of the item's position. Equivalent to
+/*!
+ Set's the \a y coordinate of the item's position. Equivalent to
calling setPos(x(), y).
\sa x(), setPos()
@@ -2777,7 +2784,8 @@ QTransform QGraphicsItem::transform() const
The default is 0
- \warning The value doesn't take in account any rotation set with the setTransform() method.
+ \warning The value doesn't take in account any rotation set with
+ the setTransform() method.
\sa setXRotation(), {Transformations}
*/
@@ -2803,6 +2811,7 @@ void QGraphicsItem::setXRotation(qreal angle)
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->xRotation = angle;
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
@@ -2839,6 +2848,7 @@ void QGraphicsItem::setYRotation(qreal angle)
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->yRotation = angle;
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
@@ -2875,6 +2885,7 @@ void QGraphicsItem::setZRotation(qreal angle)
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->zRotation = angle;
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
@@ -2894,6 +2905,7 @@ void QGraphicsItem::setRotation(qreal x, qreal y, qreal z)
d_ptr->transformData->xRotation = x;
d_ptr->transformData->yRotation = y;
d_ptr->transformData->zRotation = z;
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
@@ -2930,6 +2942,7 @@ void QGraphicsItem::setXScale(qreal factor)
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->xScale = factor;
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
@@ -2966,6 +2979,7 @@ void QGraphicsItem::setYScale(qreal factor)
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->yScale = factor;
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
@@ -2985,6 +2999,7 @@ void QGraphicsItem::setScale(qreal sx, qreal sy)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->xScale = sx;
d_ptr->transformData->yScale = sy;
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
@@ -3021,6 +3036,7 @@ void QGraphicsItem::setHorizontalShear(qreal shear)
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->horizontalShear = shear;
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
@@ -3057,6 +3073,7 @@ void QGraphicsItem::setVerticalShear(qreal shear)
if (!d_ptr->transformData)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->verticalShear = shear;
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
@@ -3076,13 +3093,14 @@ void QGraphicsItem::setShear(qreal sh, qreal sv)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->horizontalShear = sh;
d_ptr->transformData->verticalShear = sv;
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
/*!
\since 4.6
- Returns the origin point using for transformation in item coordinate.
+ Returns the origin point used for transformation in item coordinate.
The default is QPointF(0,0).
@@ -3109,6 +3127,7 @@ void QGraphicsItem::setTransformOrigin(const QPointF &origin)
d_ptr->transformData = new QGraphicsItemPrivate::TransformData;
d_ptr->transformData->xOrigin = origin.x();
d_ptr->transformData->yOrigin = origin.y();
+ d_ptr->transformData->onlyTransform = false;
d_ptr->dirtySceneTransform = 1;
}
@@ -3222,7 +3241,7 @@ QTransform QGraphicsItem::deviceTransform(const QTransform &viewportTransform) c
QTransform matrix;
matrix.translate(mappedPoint.x(), mappedPoint.y());
if (untransformedAncestor->d_ptr->transformData)
- matrix = untransformedAncestor->d_ptr->transformData->computedFullTransform() * matrix;
+ matrix = untransformedAncestor->d_ptr->transformData->computedFullTransform(&matrix);
// Then transform and translate all children.
for (int i = 0; i < parents.size(); ++i) {
@@ -4398,9 +4417,9 @@ void QGraphicsItemPrivate::updateCachedClipPathFromSetPosHelper(const QPointF &n
// Find closest clip ancestor and transform.
Q_Q(QGraphicsItem);
// COMBINE
- QTransform thisToParentTransform = transformData
- ? transformData->computedFullTransform() * QTransform::fromTranslate(newPos.x(), newPos.y())
- : QTransform::fromTranslate(newPos.x(), newPos.y());
+ QTransform thisToParentTransform = QTransform::fromTranslate(newPos.x(), newPos.y());
+ if (transformData)
+ thisToParentTransform = transformData->computedFullTransform(&thisToParentTransform);
QGraphicsItem *clipParent = parent;
while (clipParent && !(clipParent->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape)) {
thisToParentTransform *= clipParent->d_ptr->transformToParent();
@@ -6587,15 +6606,21 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
\property QGraphicsObject::parent
\brief the parent of the item
- \sa QGraphicsItem::setParentItem, QGraphicsItem::parentObject
+ \sa QGraphicsItem::setParentItem(), QGraphicsItem::parentObject()
*/
+/*!
+ \property QGraphicsObject::id
+ \brief the id of of the item
+
+ \sa QGraphicsItem::opacity(), QGraphicsItem::setOpacity()
+*/
/*!
\property QGraphicsObject::opacity
\brief the opacity of the item
- \sa QGraphicsItem::setOpacity, QGraphicsItem::opacity
+ \sa QGraphicsItem::setOpacity(), QGraphicsItem::opacity()
*/
/*!
@@ -6603,7 +6628,13 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
This signal gets emitted whenever the opacity of the item changes
- \sa opacity
+ \sa QGraphicsItem::opacity()
+*/
+
+/*!
+ \fn QGraphicsObject::parentChanged()
+
+ This signal gets emitted whenever the parent of the item changes
*/
/*!
@@ -6612,7 +6643,7 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
Describes the items position.
- \sa QGraphicsItem::setPos, QGraphicsItem::pos, positionChanged
+ \sa QGraphicsItem::setPos(), QGraphicsItem::pos()
*/
/*!
@@ -6621,7 +6652,7 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
Describes the items x position.
- \sa QGraphicsItem::setX, setPos, xChanged
+ \sa QGraphicsItem::setX(), setPos(), xChanged()
*/
/*!
@@ -6629,7 +6660,7 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
This signal gets emitted whenever the x position of the item changes
- \sa pos
+ \sa pos()
*/
/*!
@@ -6638,15 +6669,15 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
Describes the items y position.
- \sa QGraphicsItem::setY, setPos, yChanged
+ \sa QGraphicsItem::setY(), setPos(), yChanged()
*/
/*!
\fn QGraphicsObject::yChanged()
- This signal gets emitted whenever the y position of the item changes
+ This signal gets emitted whenever the y position of the item changes.
- \sa pos
+ \sa pos()
*/
/*!
@@ -6655,15 +6686,15 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
Describes the items z value.
- \sa QGraphicsItem::setZValue, zValue, zChanged
+ \sa QGraphicsItem::setZValue(), zValue(), zChanged()
*/
/*!
\fn QGraphicsObject::zChanged()
- This signal gets emitted whenever the z value of the item changes
+ This signal gets emitted whenever the z value of the item changes.
- \sa pos
+ \sa pos()
*/
@@ -6683,7 +6714,7 @@ QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent
This signal gets emitted whenever the item get's enabled or disabled.
- \sa enabled
+ \sa isEnabled()
*/
/*!