diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-12-22 17:15:57 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2016-01-05 08:18:18 +0000 |
commit | 38c8af7231823429ca6cb9ea6418e2dcef3691a0 (patch) | |
tree | 51ff210dadd4af1dd4c6260cece6e89830fdf741 /src/widgets/kernel | |
parent | 4829edfa4ec4829c25246c46d3fcf236e6e59657 (diff) |
Revert "Fix global coordinate mapping for child widgets in QGraphicsView."
This reverts commit 56aad2ad6074237537fecf10d0cda0f3872e7f71.
QWidget::mapFromGlobal() does not work correctly when the widget is
a child widget of another widget embedded into a QGraphicsView with a
transformation (scaling/rotation). It starts applying offsets going
up the widget tree (just as mapToGlobal) until it hits the embedded widget
not taking into account the transformation.
It would need to go in from to top to bottom or better be reimplemented
such that a QTransform for mapping coordinates from/to global is determined
which is then applied in reverse.
Task-number: QTBUG-50030
Task-number: QTBUG-50136
Change-Id: Iadeb891d793be1938c64942bfbf38d541a281c33
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 7c3c4fe8da..7136714d39 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -12305,21 +12305,20 @@ QPaintEngine *QWidget::paintEngine() const */ QPoint QWidget::mapToGlobal(const QPoint &pos) const { - int x = pos.x(), y = pos.y(); - const QWidget *w = this; - while (w) { #ifndef QT_NO_GRAPHICSVIEW - const QWidgetPrivate *d = w->d_func(); - if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) { - const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views(); - if (!views.isEmpty()) { - const QPointF scenePos = d->extra->proxyWidget->mapToScene(QPoint(x, y)); - const QPoint viewPortPos = views.first()->mapFromScene(scenePos); - return views.first()->viewport()->mapToGlobal(viewPortPos); - } + Q_D(const QWidget); + if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) { + const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views(); + if (!views.isEmpty()) { + const QPointF scenePos = d->extra->proxyWidget->mapToScene(pos); + const QPoint viewPortPos = views.first()->mapFromScene(scenePos); + return views.first()->viewport()->mapToGlobal(viewPortPos); } + } #endif // !QT_NO_GRAPHICSVIEW - + int x = pos.x(), y = pos.y(); + const QWidget *w = this; + while (w) { QWindow *window = w->windowHandle(); if (window && window->handle()) return window->mapToGlobal(QPoint(x, y)); @@ -12341,21 +12340,20 @@ QPoint QWidget::mapToGlobal(const QPoint &pos) const */ QPoint QWidget::mapFromGlobal(const QPoint &pos) const { - int x = pos.x(), y = pos.y(); - const QWidget *w = this; - while (w) { #ifndef QT_NO_GRAPHICSVIEW - const QWidgetPrivate *d = w->d_func(); - if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) { - const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views(); - if (!views.isEmpty()) { - const QPoint viewPortPos = views.first()->viewport()->mapFromGlobal(QPoint(x, y)); - const QPointF scenePos = views.first()->mapToScene(viewPortPos); - return d->extra->proxyWidget->mapFromScene(scenePos).toPoint(); - } + Q_D(const QWidget); + if (d->extra && d->extra->proxyWidget && d->extra->proxyWidget->scene()) { + const QList <QGraphicsView *> views = d->extra->proxyWidget->scene()->views(); + if (!views.isEmpty()) { + const QPoint viewPortPos = views.first()->viewport()->mapFromGlobal(pos); + const QPointF scenePos = views.first()->mapToScene(viewPortPos); + return d->extra->proxyWidget->mapFromScene(scenePos).toPoint(); } + } #endif // !QT_NO_GRAPHICSVIEW - + int x = pos.x(), y = pos.y(); + const QWidget *w = this; + while (w) { QWindow *window = w->windowHandle(); if (window && window->handle()) return window->mapFromGlobal(QPoint(x, y)); |