QWidget::mapTo/FromGlobal(): Fix transformation in case of QGraphicsItem::ItemIgnoresTransformations
Extract a helper returning the transform from QGraphicsViewPrivate::mapToViewRect() and use that. Fixes: QTBUG-128913 Change-Id: Idc31f653c23cd7d0e5bbb8af560f010f01ac4d4b Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit deb4e08c1212aa3d43f62f9e7211bf69d3be0ada) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
5f3e64235e
commit
5d612a72ad
@ -885,16 +885,14 @@ void QGraphicsViewPrivate::populateSceneDragDropEvent(QGraphicsSceneDragDropEven
|
|||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
QRect QGraphicsViewPrivate::mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const
|
QTransform QGraphicsViewPrivate::mapToViewTransform(const QGraphicsItem *item) const
|
||||||
{
|
{
|
||||||
Q_Q(const QGraphicsView);
|
Q_Q(const QGraphicsView);
|
||||||
if (dirtyScroll)
|
if (dirtyScroll)
|
||||||
const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
|
const_cast<QGraphicsViewPrivate *>(this)->updateScroll();
|
||||||
|
|
||||||
if (item->d_ptr->itemIsUntransformable()) {
|
if (item->d_ptr->itemIsUntransformable())
|
||||||
QTransform itv = item->deviceTransform(q->viewportTransform());
|
return item->deviceTransform(q->viewportTransform());
|
||||||
return itv.mapRect(rect).toAlignedRect();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Translate-only
|
// Translate-only
|
||||||
// COMBINE
|
// COMBINE
|
||||||
@ -908,21 +906,20 @@ QRect QGraphicsViewPrivate::mapToViewRect(const QGraphicsItem *item, const QRect
|
|||||||
offset += itemd->pos;
|
offset += itemd->pos;
|
||||||
} while ((parentItem = itemd->parent));
|
} while ((parentItem = itemd->parent));
|
||||||
|
|
||||||
QRectF baseRect = rect.translated(offset.x(), offset.y());
|
QTransform move = QTransform::fromTranslate(offset.x(), offset.y());
|
||||||
if (!parentItem) {
|
if (!parentItem) {
|
||||||
if (identityMatrix) {
|
move.translate(-scrollX, -scrollY);
|
||||||
baseRect.translate(-scrollX, -scrollY);
|
return identityMatrix ? move : matrix * move;
|
||||||
return baseRect.toAlignedRect();
|
|
||||||
}
|
|
||||||
return matrix.mapRect(baseRect).translated(-scrollX, -scrollY).toAlignedRect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QTransform tr = parentItem->sceneTransform();
|
QTransform tr = parentItem->sceneTransform();
|
||||||
if (!identityMatrix)
|
if (!identityMatrix)
|
||||||
tr *= matrix;
|
tr *= matrix;
|
||||||
QRectF r = tr.mapRect(baseRect);
|
return move * tr * QTransform::fromTranslate(-scrollX, -scrollY);
|
||||||
r.translate(-scrollX, -scrollY);
|
}
|
||||||
return r.toAlignedRect();
|
|
||||||
|
QRect QGraphicsViewPrivate::mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const
|
||||||
|
{
|
||||||
|
return mapToViewTransform(item).mapRect(rect).toAlignedRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -139,6 +139,7 @@ public:
|
|||||||
void populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
|
void populateSceneDragDropEvent(QGraphicsSceneDragDropEvent *dest,
|
||||||
QDropEvent *source);
|
QDropEvent *source);
|
||||||
|
|
||||||
|
QTransform mapToViewTransform(const QGraphicsItem *item) const;
|
||||||
QRect mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const;
|
QRect mapToViewRect(const QGraphicsItem *item, const QRectF &rect) const;
|
||||||
QRegion mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const;
|
QRegion mapToViewRegion(const QGraphicsItem *item, const QRectF &rect) const;
|
||||||
QRegion dirtyRegion;
|
QRegion dirtyRegion;
|
||||||
|
@ -60,6 +60,7 @@
|
|||||||
#include "QtWidgets/qgraphicsproxywidget.h"
|
#include "QtWidgets/qgraphicsproxywidget.h"
|
||||||
#include "QtWidgets/qgraphicsscene.h"
|
#include "QtWidgets/qgraphicsscene.h"
|
||||||
#include "private/qgraphicsproxywidget_p.h"
|
#include "private/qgraphicsproxywidget_p.h"
|
||||||
|
#include "private/qgraphicsview_p.h"
|
||||||
#endif
|
#endif
|
||||||
#include "QtWidgets/qabstractscrollarea.h"
|
#include "QtWidgets/qabstractscrollarea.h"
|
||||||
#include "private/qabstractscrollarea_p.h"
|
#include "private/qabstractscrollarea_p.h"
|
||||||
@ -12644,8 +12645,8 @@ static MapToGlobalTransformResult mapToGlobalTransform(const QWidget *w)
|
|||||||
if (const QGraphicsScene *scene = qgpw->scene()) {
|
if (const QGraphicsScene *scene = qgpw->scene()) {
|
||||||
const QList <QGraphicsView *> views = scene->views();
|
const QList <QGraphicsView *> views = scene->views();
|
||||||
if (!views.isEmpty()) {
|
if (!views.isEmpty()) {
|
||||||
result.transform *= qgpw->sceneTransform();
|
auto *viewP = static_cast<QGraphicsViewPrivate *>(qt_widget_private(views.constFirst()));
|
||||||
result.transform *= views.first()->viewportTransform();
|
result.transform *= viewP->mapToViewTransform(qgpw);
|
||||||
w = views.first()->viewport();
|
w = views.first()->viewport();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,7 @@ private slots:
|
|||||||
void QTBUG_6986_sendMouseEventToAlienWidget();
|
void QTBUG_6986_sendMouseEventToAlienWidget();
|
||||||
void mapToGlobal();
|
void mapToGlobal();
|
||||||
void mapToGlobalWithoutScene();
|
void mapToGlobalWithoutScene();
|
||||||
|
void mapToGlobalIgnoreTranformation();
|
||||||
void QTBUG_43780_visibility();
|
void QTBUG_43780_visibility();
|
||||||
#if QT_CONFIG(wheelevent)
|
#if QT_CONFIG(wheelevent)
|
||||||
void wheelEventPropagation();
|
void wheelEventPropagation();
|
||||||
@ -3552,6 +3553,55 @@ void tst_QGraphicsProxyWidget::mapToGlobalWithoutScene() // QTBUG-44509
|
|||||||
QCOMPARE(embeddedWidget->mapFromGlobal(globalPos), localPos);
|
QCOMPARE(embeddedWidget->mapFromGlobal(globalPos), localPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QTBUG-128913, QGraphicsProxyWidget with ItemIgnoresTransformations
|
||||||
|
void tst_QGraphicsProxyWidget::mapToGlobalIgnoreTranformation()
|
||||||
|
{
|
||||||
|
const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
|
||||||
|
const QSize size = availableGeometry.size() / 2;
|
||||||
|
QGraphicsScene scene;
|
||||||
|
QGraphicsView view(&scene);
|
||||||
|
view.setWindowTitle(QLatin1StringView(QTest::currentTestFunction()));
|
||||||
|
view.setAlignment(Qt::AlignLeft | Qt::AlignTop);
|
||||||
|
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
view.setTransform(QTransform::fromScale(2, 2));
|
||||||
|
view.resize(size);
|
||||||
|
view.move(availableGeometry.bottomRight() - QPoint(size.width(), size.height())
|
||||||
|
- QPoint(100, 100));
|
||||||
|
|
||||||
|
static constexpr int labelWidth = 200;
|
||||||
|
static constexpr int labelHeight = 50;
|
||||||
|
auto *transforming = new QGraphicsProxyWidget();
|
||||||
|
auto *transformingLabel = new QLabel("Transforming"_L1);
|
||||||
|
transformingLabel->resize(labelWidth, labelHeight);
|
||||||
|
transforming->setWidget(transformingLabel);
|
||||||
|
transforming->setPos(0, 0);
|
||||||
|
scene.addItem(transforming);
|
||||||
|
|
||||||
|
auto *nonTransforming = new QGraphicsProxyWidget();
|
||||||
|
nonTransforming->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||||
|
auto *nonTransformingLabel = new QLabel("NonTransforming"_L1);
|
||||||
|
nonTransformingLabel->resize(labelWidth, labelHeight);
|
||||||
|
nonTransforming->setWidget(nonTransformingLabel);
|
||||||
|
nonTransforming->setPos(labelWidth, 0);
|
||||||
|
scene.addItem(nonTransforming);
|
||||||
|
|
||||||
|
view.show();
|
||||||
|
QVERIFY(QTest::qWaitForWindowExposed(&view));
|
||||||
|
|
||||||
|
const QPoint labelCenter{ labelWidth / 2, labelHeight / 2 };
|
||||||
|
const QPoint topPos = view.geometry().topLeft() + view.viewport()->geometry().topLeft();
|
||||||
|
const QPoint transformingGlobal = transformingLabel->mapToGlobal(labelCenter);
|
||||||
|
const QPoint nonTransformingGlobal = nonTransformingLabel->mapToGlobal(labelCenter);
|
||||||
|
|
||||||
|
// Center of label at 0,0 scaled by 2 should match size
|
||||||
|
QCOMPARE(transformingGlobal - topPos, QPoint(labelWidth, labelHeight));
|
||||||
|
|
||||||
|
// Center of non-transforming label at 200 (scaled by 2), 0
|
||||||
|
QCOMPARE(nonTransformingGlobal - topPos,
|
||||||
|
QPoint(labelWidth * 2 + labelWidth / 2, labelHeight / 2));
|
||||||
|
}
|
||||||
|
|
||||||
// QTBUG_43780: Embedded widgets have isWindow()==true but showing them should not
|
// QTBUG_43780: Embedded widgets have isWindow()==true but showing them should not
|
||||||
// trigger the top-level widget code path of show() that closes all popups
|
// trigger the top-level widget code path of show() that closes all popups
|
||||||
// (for example combo popups).
|
// (for example combo popups).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user