From 8fce4e97ba8479a24bff167ce72ed43223076905 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Tue, 30 Jul 2013 18:08:10 +0200 Subject: Fix double transform for items ignoring parent transformations. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, the topmost untransformable's scene transform, which includes the item's position and local transformation, was used to determine the item's anchoring position. This position was then passed on to be multiplied by the item's transform again. This works fine for toplevel untransformable items that don't have any transform set at all, but those who do would have their transforms applied twice - one to determine the anchoring position, and again to transform the item itself. Since only translation transformations can affect the first operation (the anchoring pos), this bug only applies to items that set ItemIgnoresTransformations and use a local transform that includes translation. Task-number: QTBUG-21618 Change-Id: I772d52d59dfd9f242d0140632a87e9c68dfe0ea1 Reviewed-by: Jan Arve Sæther --- src/widgets/graphicsview/qgraphicsitem.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 1c15905ff0..db2b71f508 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -4199,9 +4199,14 @@ QTransform QGraphicsItem::deviceTransform(const QTransform &viewportTransform) c return QTransform(); } - // First translate the base untransformable item. - untransformedAncestor->d_ptr->ensureSceneTransform(); - QPointF mappedPoint = (untransformedAncestor->d_ptr->sceneTransform * viewportTransform).map(QPointF(0, 0)); + // Determine the inherited origin. Find the parent of the topmost untransformable. + // Use its scene transform to map the position of the untransformable. Then use + // that viewport position as the anchoring point for the untransformable subtree. + QGraphicsItem *parentOfUntransformedAncestor = untransformedAncestor->parentItem(); + QTransform inheritedMatrix; + if (parentOfUntransformedAncestor) + inheritedMatrix = parentOfUntransformedAncestor->sceneTransform(); + QPointF mappedPoint = (inheritedMatrix * viewportTransform).map(untransformedAncestor->pos()); // COMBINE QTransform matrix = QTransform::fromTranslate(mappedPoint.x(), mappedPoint.y()); -- cgit v1.2.3