summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp143
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h22
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp11
-rw-r--r--src/gui/graphicsview/qgraphicsview.cpp2
-rw-r--r--src/gui/graphicsview/qgraphicswidget.cpp35
5 files changed, 146 insertions, 67 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()
*/
/*!
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index b8b947d..12b6fe0 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -461,23 +461,35 @@ struct QGraphicsItemPrivate::TransformData {
qreal verticalShear;
qreal xOrigin;
qreal yOrigin;
+ bool onlyTransform;
TransformData() :
xScale(1.0), yScale(1.0), xRotation(0.0), yRotation(0.0), zRotation(0.0),
- horizontalShear(0.0), verticalShear(0.0), xOrigin(0.0), yOrigin(0.0)
+ horizontalShear(0.0), verticalShear(0.0), xOrigin(0.0), yOrigin(0.0),
+ onlyTransform(true)
{}
- QTransform computedFullTransform() const
+ QTransform computedFullTransform(QTransform *postmultiplyTransform = 0) const
{
- QTransform x;
- x.translate(xOrigin, yOrigin);
- x = transform * x;
+ if (onlyTransform) {
+ if (!postmultiplyTransform)
+ return transform;
+ QTransform x(transform);
+ x *= *postmultiplyTransform;
+ return x;
+ }
+
+ QTransform x(transform);
+ if (xOrigin != 0 || yOrigin != 0)
+ x *= QTransform::fromTranslate(xOrigin, yOrigin);
x.rotate(xRotation, Qt::XAxis);
x.rotate(yRotation, Qt::YAxis);
x.rotate(zRotation, Qt::ZAxis);
x.shear(horizontalShear, verticalShear);
x.scale(xScale, yScale);
x.translate(-xOrigin, -yOrigin);
+ if (postmultiplyTransform)
+ x *= *postmultiplyTransform;
return x;
}
};
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index c142dfc..494eab2 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -5198,8 +5198,8 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
}
// Calculate the full transform for this item.
- QRect viewBoundingRect;
bool wasDirtyParentSceneTransform = false;
+ bool dontDrawItem = true;
QTransform transform;
if (item) {
if (item->d_ptr->itemIsUntransformable()) {
@@ -5215,15 +5215,17 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
transform = item->d_ptr->sceneTransform;
transform *= viewTransform;
}
-
+
QRectF brect = item->boundingRect();
// ### This does not take the clip into account.
_q_adjustRect(&brect);
- viewBoundingRect = transform.mapRect(brect).toRect();
+ QRect viewBoundingRect = transform.mapRect(brect).toRect();
item->d_ptr->paintedViewBoundingRects.insert(widget, viewBoundingRect);
viewBoundingRect.adjust(-1, -1, 1, 1);
if (exposedRegion)
- viewBoundingRect &= exposedRegion->boundingRect();
+ dontDrawItem = !exposedRegion->intersects(viewBoundingRect);
+ else
+ dontDrawItem = viewBoundingRect.isEmpty();
}
// Find and sort children.
@@ -5278,7 +5280,6 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
}
bool childClip = (item && (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape));
- bool dontDrawItem = !item || viewBoundingRect.isEmpty();
bool dontDrawChildren = item && dontDrawItem && childClip;
childClip &= !dontDrawChildren && !children->isEmpty();
if (item && ((item->d_ptr->flags & QGraphicsItem::ItemHasNoContents) || invisibleButChildIgnoresParentOpacity))
diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp
index 0abfb56..fb46180 100644
--- a/src/gui/graphicsview/qgraphicsview.cpp
+++ b/src/gui/graphicsview/qgraphicsview.cpp
@@ -217,6 +217,8 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime <
minimizing the areas that require redrawing, which improves performance. A
common side effect is that items that do draw with antialiasing can leave
painting traces behind on the scene as they are moved.
+
+ \omitvalue IndirectPainting
*/
/*!
diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp
index 419277d..78bd062 100644
--- a/src/gui/graphicsview/qgraphicswidget.cpp
+++ b/src/gui/graphicsview/qgraphicswidget.cpp
@@ -1658,7 +1658,8 @@ bool QGraphicsWidget::isActiveWindow() const
This property is only used for windows.
- By default, if no title has been set, this property contains an empty string.
+ By default, if no title has been set, this property contains an
+ empty string.
*/
void QGraphicsWidget::setWindowTitle(const QString &title)
{
@@ -1721,6 +1722,38 @@ QGraphicsWidget *QGraphicsWidget::focusWidget() const
return d->focusChild;
}
+/*! \property QGraphicsWidget::horizontalShear
+ \brief This property holds the horizontal shear value for the item.
+ */
+
+/*! \property QGraphicsWidget::transformOrigin
+ \brief This property holds the origin point used for transformations
+ in item coordinates.
+ */
+
+/*! \property QGraphicsWidget::verticalShear
+ \brief This property holds the vertical shear value for the item.
+ */
+
+/*! \property QGraphicsWidget::xRotation
+ \brief This property holds the value for rotation around the x axis.
+ */
+
+/*! \property QGraphicsWidget::xScale
+ \brief This property holds the scale factor for the x axis.
+ */
+
+/*! \property QGraphicsWidget::yRotation
+ \brief This property holds the value for rotation around the y axis.
+ */
+
+/*! \property QGraphicsWidget::yScale
+ \brief This property holds the scale factor for the y axis.
+ */
+
+/*! \property QGraphicsWidget::zRotation
+ \brief This property holds the value for rotation around the z axis.
+ */
#ifndef QT_NO_SHORTCUT
/*!