summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp')
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp367
1 files changed, 285 insertions, 82 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
index e666ac24c9..7ed1f28b0a 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -50,6 +25,7 @@
#include <QtWidgets/QBoxLayout>
#include <QtWidgets/QStyle>
#include <QtWidgets/QPushButton>
+#include <QtWidgets/QScroller>
#if QT_CONFIG(opengl)
#include <QtOpenGLWidgets/QOpenGLWidget>
#endif
@@ -64,6 +40,8 @@
#include <QtTest/private/qtesthelpers_p.h>
+#include <QtWidgets/private/qapplication_p.h>
+
using namespace QTestPrivate;
Q_DECLARE_METATYPE(ExpectedValueDescription)
@@ -101,6 +79,12 @@ static void sendMouseRelease(QWidget *widget, const QPoint &point, Qt::MouseButt
QApplication::sendEvent(widget, &event);
}
+static bool isPlatformEGLFS()
+{
+ static const bool isEGLFS = !QGuiApplication::platformName().compare(QLatin1String("eglfs"), Qt::CaseInsensitive);
+ return isEGLFS;
+}
+
class EventSpy : public QObject
{
Q_OBJECT
@@ -225,6 +209,7 @@ private slots:
void replayMouseMove();
void itemsUnderMouse();
void embeddedViews();
+ void embeddedViewsWithFocus();
void scrollAfterResize_data();
void scrollAfterResize();
void moveItemWhileScrolling_data();
@@ -265,9 +250,12 @@ private slots:
void QTBUG_5859_exposedRect();
void hoverLeave();
void QTBUG_16063_microFocusRect();
+ void QTBUG_70255_scrollTo();
#ifndef QT_NO_CURSOR
void QTBUG_7438_cursor();
#endif
+ void resizeContentsOnItemDrag_data();
+ void resizeContentsOnItemDrag();
public slots:
void dummySlot() {}
@@ -666,6 +654,8 @@ void tst_QGraphicsView::openGLViewport()
{
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL))
QSKIP("QOpenGL is not supported on this platform.");
+ if (isPlatformEGLFS())
+ QSKIP("", "Resizing does not work on EGLFS on top level window", Continue);
QGraphicsScene scene;
scene.setBackgroundBrush(Qt::white);
@@ -687,16 +677,16 @@ void tst_QGraphicsView::openGLViewport()
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QTRY_VERIFY(spy1.count() > 0);
- QTRY_VERIFY(spy2.count() >= spy1.count());
+ QTRY_VERIFY(spy1.size() > 0);
+ QTRY_VERIFY(spy2.size() >= spy1.size());
spy1.clear();
spy2.clear();
// Now test for resize (QTBUG-52419). This is special when the viewport is
// a QOpenGLWidget since the underlying FBO must also be maintained.
view.resize(300, 300);
- QTRY_VERIFY(spy1.count() > 0);
- QTRY_VERIFY(spy2.count() >= spy1.count());
+ QTRY_VERIFY(spy1.size() > 0);
+ QTRY_VERIFY(spy2.size() >= spy1.size());
// There is no sane way to check if the framebuffer contents got updated
// (grabFramebuffer is no good for the viewport case as that does not go
// through paintGL). So skip the actual verification.
@@ -740,8 +730,9 @@ void tst_QGraphicsView::dragMode_scrollHand()
int verticalScrollBarValue = view.verticalScrollBar()->value();
{
// Press
- QMouseEvent event(QEvent::MouseButtonPress,
- view.viewport()->rect().center(),
+ auto pos = view.viewport()->rect().center();
+ QMouseEvent event(QEvent::MouseButtonPress, pos,
+ view.viewport()->mapToGlobal(pos),
Qt::LeftButton, Qt::LeftButton, {});
event.setAccepted(true);
QApplication::sendEvent(view.viewport(), &event);
@@ -757,8 +748,9 @@ void tst_QGraphicsView::dragMode_scrollHand()
#endif
{
// Move
- QMouseEvent event(QEvent::MouseMove,
- view.viewport()->rect().center() + QPoint(10, 0),
+ auto pos = view.viewport()->rect().center() + QPoint(10, 0);
+ QMouseEvent event(QEvent::MouseMove, pos,
+ view.viewport()->mapToGlobal(pos),
Qt::LeftButton, Qt::LeftButton, {});
event.setAccepted(true);
QApplication::sendEvent(view.viewport(), &event);
@@ -769,8 +761,9 @@ void tst_QGraphicsView::dragMode_scrollHand()
QCOMPARE(view.verticalScrollBar()->value(), verticalScrollBarValue);
{
// Move
- QMouseEvent event(QEvent::MouseMove,
- view.viewport()->rect().center() + QPoint(10, 10),
+ auto pos = view.viewport()->rect().center() + QPoint(10, 10);
+ QMouseEvent event(QEvent::MouseMove, pos,
+ view.viewport()->mapToGlobal(pos),
Qt::LeftButton, Qt::LeftButton, {});
event.setAccepted(true);
QApplication::sendEvent(view.viewport(), &event);
@@ -783,8 +776,9 @@ void tst_QGraphicsView::dragMode_scrollHand()
{
// Release
- QMouseEvent event(QEvent::MouseButtonRelease,
- view.viewport()->rect().center() + QPoint(10, 10),
+ auto pos = view.viewport()->rect().center() + QPoint(10, 10);
+ QMouseEvent event(QEvent::MouseButtonRelease, pos,
+ view.viewport()->mapToGlobal(pos),
Qt::LeftButton, Qt::LeftButton, {});
event.setAccepted(true);
QApplication::sendEvent(view.viewport(), &event);
@@ -805,15 +799,17 @@ void tst_QGraphicsView::dragMode_scrollHand()
// Check that a click will still unselect the item.
{
// Press
- QMouseEvent event(QEvent::MouseButtonPress,
- view.viewport()->rect().center() + QPoint(10, 10),
+ auto pos = view.viewport()->rect().center() + QPoint(10, 10);
+ QMouseEvent event(QEvent::MouseButtonPress, pos,
+ view.viewport()->mapToGlobal(pos),
Qt::LeftButton, Qt::LeftButton, {});
QApplication::sendEvent(view.viewport(), &event);
}
{
// Release
- QMouseEvent event(QEvent::MouseButtonRelease,
- view.viewport()->rect().center() + QPoint(10, 10),
+ auto pos = view.viewport()->rect().center() + QPoint(10, 10);
+ QMouseEvent event(QEvent::MouseButtonRelease, pos,
+ view.viewport()->mapToGlobal(pos),
Qt::LeftButton, Qt::LeftButton, {});
QApplication::sendEvent(view.viewport(), &event);
}
@@ -862,8 +858,9 @@ void tst_QGraphicsView::dragMode_rubberBand()
int verticalScrollBarValue = view.verticalScrollBar()->value();
{
// Press
- QMouseEvent event(QEvent::MouseButtonPress,
- view.viewport()->rect().center(),
+ auto pos = view.viewport()->rect().center();
+ QMouseEvent event(QEvent::MouseButtonPress, pos,
+ view.viewport()->mapToGlobal(pos),
Qt::LeftButton, Qt::LeftButton, {});
event.setAccepted(true);
QApplication::sendEvent(view.viewport(), &event);
@@ -877,8 +874,9 @@ void tst_QGraphicsView::dragMode_rubberBand()
{
// Move
- QMouseEvent event(QEvent::MouseMove,
- view.viewport()->rect().center() + QPoint(100, 0),
+ auto pos = view.viewport()->rect().center() + QPoint(100, 0);
+ QMouseEvent event(QEvent::MouseMove, pos,
+ view.viewport()->mapToGlobal(pos),
Qt::LeftButton, Qt::LeftButton, {});
event.setAccepted(true);
QApplication::sendEvent(view.viewport(), &event);
@@ -892,8 +890,9 @@ void tst_QGraphicsView::dragMode_rubberBand()
{
// Move
- QMouseEvent event(QEvent::MouseMove,
- view.viewport()->rect().center() + QPoint(100, 100),
+ auto pos = view.viewport()->rect().center() + QPoint(100, 100);
+ QMouseEvent event(QEvent::MouseMove, pos,
+ view.viewport()->mapToGlobal(pos),
Qt::LeftButton, Qt::LeftButton, {});
event.setAccepted(true);
QApplication::sendEvent(view.viewport(), &event);
@@ -904,8 +903,9 @@ void tst_QGraphicsView::dragMode_rubberBand()
{
// Release
- QMouseEvent event(QEvent::MouseButtonRelease,
- view.viewport()->rect().center() + QPoint(100, 100),
+ auto pos = view.viewport()->rect().center() + QPoint(100, 100);
+ QMouseEvent event(QEvent::MouseButtonRelease, pos,
+ view.viewport()->mapToGlobal(pos),
Qt::LeftButton, Qt::LeftButton, {});
event.setAccepted(true);
QApplication::sendEvent(view.viewport(), &event);
@@ -1056,10 +1056,10 @@ void tst_QGraphicsView::rotated_rubberBand()
sendMousePress(view.viewport(), QPoint(midWidth - 2, 0), Qt::LeftButton);
sendMouseMove(view.viewport(), QPoint(midWidth + 2, view.viewport()->height()),
Qt::LeftButton, Qt::LeftButton);
- QCOMPARE(scene.selectedItems().count(), dim);
- foreach (const QGraphicsItem *item, scene.items()) {
+ QCOMPARE(scene.selectedItems().size(), dim);
+ const auto items = scene.items();
+ for (const QGraphicsItem *item : items)
QCOMPARE(item->isSelected(), item->data(0).toBool());
- }
sendMouseRelease(view.viewport(), QPoint(), Qt::LeftButton);
}
@@ -1637,6 +1637,9 @@ void tst_QGraphicsView::itemsInRect_cosmeticAdjust_data()
void tst_QGraphicsView::itemsInRect_cosmeticAdjust()
{
+ if (isPlatformEGLFS())
+ QSKIP("", "Resizing does not work on EGLFS on top level window", Continue);
+
QFETCH(QRect, updateRect);
QFETCH(int, numPaints);
QFETCH(bool, adjustForAntialiasing);
@@ -1930,6 +1933,9 @@ void tst_QGraphicsView::mapToSceneRect_data()
void tst_QGraphicsView::mapToSceneRect()
{
+ if (isPlatformEGLFS())
+ QSKIP("", "Resizing does not work on EGLFS on top level window", Continue);
+
QFETCH(QRect, viewRect);
QFETCH(QPolygonF, scenePoly);
QFETCH(qreal, rotation);
@@ -2147,7 +2153,6 @@ void tst_QGraphicsView::sendEvent()
QGraphicsView view(&scene);
view.show();
- QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
@@ -2215,7 +2220,6 @@ void tst_QGraphicsView::wheelEvent()
// Assign a view.
QGraphicsView view(&scene);
view.show();
- QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
@@ -2452,7 +2456,6 @@ void tst_QGraphicsView::viewportUpdateMode()
// Show the view, and initialize our test.
view.show();
- qApp->setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QTRY_VERIFY(!view.lastUpdateRegions.isEmpty());
@@ -2535,7 +2538,6 @@ void tst_QGraphicsView::viewportUpdateMode2()
const QMargins margins = view.contentsMargins();
view.resize(200 + margins.left() + margins.right(), 200 + margins.top() + margins.bottom());
toplevel.show();
- qApp->setActiveWindow(&toplevel);
QVERIFY(QTest::qWaitForWindowExposed(&toplevel));
QVERIFY(QTest::qWaitForWindowActive(&toplevel));
QTRY_VERIFY(view.painted);
@@ -2747,7 +2749,8 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState2()
rectB->setTransform(QTransform::fromTranslate(200, 200));
rectB->setPen(QPen(Qt::black, 0));
- foreach (QGraphicsItem *item, scene.items())
+ const auto items = scene.items();
+ for (QGraphicsItem *item : items)
item->setOpacity(0.6);
CustomView view(&scene);
@@ -2884,6 +2887,9 @@ public:
void tst_QGraphicsView::scrollBarRanges()
{
+ if (isPlatformEGLFS())
+ QSKIP("", "Resizing does not work on EGLFS on top level window", Continue);
+
QFETCH(QByteArray, style);
QFETCH(QSize, viewportSize);
QFETCH(QRectF, sceneRect);
@@ -3179,7 +3185,6 @@ void tst_QGraphicsView::task172231_untransformableItems()
view.scale(2, 1);
view.show();
- QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
@@ -3241,7 +3246,6 @@ void tst_QGraphicsView::task187791_setSceneCausesUpdate()
QGraphicsScene scene(0, 0, 200, 200);
QGraphicsView view(&scene);
view.show();
- qApp->setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
EventSpy updateSpy(view.viewport(), QEvent::Paint);
@@ -3266,7 +3270,8 @@ protected:
{
++mouseMoves;
QGraphicsView::mouseMoveEvent(event);
- foreach (QGraphicsItem *item, scene()->items()) {
+ const auto items = scene()->items();
+ for (QGraphicsItem *item : items) {
scene()->removeItem(item);
delete item;
}
@@ -3292,7 +3297,8 @@ void tst_QGraphicsView::task186827_deleteReplayedItem()
QCOMPARE(view.mouseMoves, 0);
{
- QMouseEvent event(QEvent::MouseMove, view.mapFromScene(25, 25), Qt::NoButton, {}, {});
+ auto pos = view.mapFromScene(25, 25);
+ QMouseEvent event(QEvent::MouseMove, pos, view.viewport()->mapToGlobal(pos), Qt::NoButton, {}, {});
QApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.mouseMoves, 1);
@@ -3300,7 +3306,8 @@ void tst_QGraphicsView::task186827_deleteReplayedItem()
QTRY_COMPARE(view.mouseMoves, 1);
QTest::qWait(25);
{
- QMouseEvent event(QEvent::MouseMove, view.mapFromScene(25, 25), Qt::NoButton, {}, {});
+ auto pos = view.mapFromScene(25, 25);
+ QMouseEvent event(QEvent::MouseMove, pos, view.viewport()->mapToGlobal(pos), Qt::NoButton, {}, {});
QApplication::sendEvent(view.viewport(), &event);
}
QCOMPARE(view.mouseMoves, 2);
@@ -3325,7 +3332,6 @@ void tst_QGraphicsView::task207546_focusCrash()
widget.layout()->addWidget(gr2);
widget.show();
widget.activateWindow();
- QApplication::setActiveWindow(&widget);
QVERIFY(QTest::qWaitForWindowActive(&widget));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&widget));
widget.focusNextPrevChild(true);
@@ -3346,8 +3352,10 @@ void tst_QGraphicsView::task210599_unsetDragWhileDragging()
// Enable and do a drag
{
view.setDragMode(QGraphicsView::ScrollHandDrag);
- QMouseEvent press(QEvent::MouseButtonPress, origPos, Qt::LeftButton, {}, {});
- QMouseEvent move(QEvent::MouseMove, step1Pos, Qt::LeftButton, {}, {});
+ QMouseEvent press(QEvent::MouseButtonPress, origPos,
+ view.viewport()->mapToGlobal(origPos), Qt::LeftButton, {}, {});
+ QMouseEvent move(QEvent::MouseMove, step1Pos,
+ view.viewport()->mapToGlobal(step1Pos), Qt::LeftButton, {}, {});
QApplication::sendEvent(view.viewport(), &press);
QApplication::sendEvent(view.viewport(), &move);
}
@@ -3355,7 +3363,8 @@ void tst_QGraphicsView::task210599_unsetDragWhileDragging()
// unset drag and release mouse, inverse order
{
view.setDragMode(QGraphicsView::NoDrag);
- QMouseEvent release(QEvent::MouseButtonRelease, step1Pos, Qt::LeftButton, {}, {});
+ QMouseEvent release(QEvent::MouseButtonRelease, step1Pos,
+ view.viewport()->mapToGlobal(step1Pos), Qt::LeftButton, {}, {});
QApplication::sendEvent(view.viewport(), &release);
}
@@ -3364,7 +3373,8 @@ void tst_QGraphicsView::task210599_unsetDragWhileDragging()
// reset drag, and move mouse without holding button down.
{
view.setDragMode(QGraphicsView::ScrollHandDrag);
- QMouseEvent move(QEvent::MouseMove, step2Pos, Qt::LeftButton, {}, {});
+ QMouseEvent move(QEvent::MouseMove, step2Pos,
+ view.viewport()->mapToGlobal(step2Pos), Qt::LeftButton, {}, {});
QApplication::sendEvent(view.viewport(), &move);
}
@@ -3413,7 +3423,6 @@ void tst_QGraphicsView::task239729_noViewUpdate()
QCOMPARE(spy.count(), 0);
view->show();
- qApp->setActiveWindow(view);
QVERIFY(QTest::qWaitForWindowActive(view));
QTRY_VERIFY(spy.count() >= 1);
@@ -3524,6 +3533,63 @@ void tst_QGraphicsView::embeddedViews()
delete v1;
}
+/*!
+ Verify that a nested graphics view and embedded widgets receive window
+ activation and focus correctly.
+
+ See QTBUG-94091.
+*/
+void tst_QGraphicsView::embeddedViewsWithFocus()
+{
+ class FocusWidget : public QWidget
+ {
+ public:
+ FocusWidget() { setFocusPolicy(Qt::StrongFocus); }
+ QSize sizeHint() const override { return QSize(100, 100); }
+
+ int focusCount = 0;
+ protected:
+ void mousePressEvent(QMouseEvent *) override {} // accept event to avoid warning
+ void focusInEvent(QFocusEvent *) override { ++focusCount; }
+ void focusOutEvent(QFocusEvent *) override { --focusCount; }
+ };
+
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
+ QSKIP("QWindow::requestActivate() is not supported.");
+
+ QGraphicsScene innerScene;
+ FocusWidget *innerWidget = new FocusWidget;
+ innerScene.addWidget(innerWidget);
+ QGraphicsView *innerView = new QGraphicsView(&innerScene);
+
+ QGraphicsScene outerScene;
+ FocusWidget *outerWidget = new FocusWidget;
+ QGraphicsProxyWidget *outerProxy = outerScene.addWidget(outerWidget);
+ QGraphicsProxyWidget *nestedProxy = outerScene.addWidget(innerView);
+ outerProxy->setPos(0, 0);
+ nestedProxy->setPos(0, outerWidget->sizeHint().height());
+ QGraphicsView outerView(&outerScene);
+ outerView.show();
+ outerView.activateWindow();
+ QVERIFY(QTest::qWaitForWindowActive(&outerView));
+ const QPoint outerCenter(QPoint(innerWidget->sizeHint().width() / 2,
+ innerWidget->sizeHint().height() / 2));
+ const QPoint innerCenter(outerCenter + QPoint(0, innerWidget->sizeHint().height()));
+ QCOMPARE(outerView.itemAt(outerCenter), outerProxy);
+ QCOMPARE(outerView.itemAt(innerCenter), nestedProxy);
+ QVERIFY(outerScene.isActive());
+ QVERIFY(innerScene.isActive());
+
+ QCOMPARE(outerWidget->focusCount, 0);
+ QCOMPARE(innerWidget->focusCount, 0);
+ QTest::mouseClick(outerView.viewport(), Qt::LeftButton, {}, outerCenter);
+ QCOMPARE(outerWidget->focusCount, 1);
+ QCOMPARE(innerWidget->focusCount, 0);
+ QTest::mouseClick(outerView.viewport(), Qt::LeftButton, {}, innerCenter);
+ QCOMPARE(outerWidget->focusCount, 0);
+ QCOMPARE(innerWidget->focusCount, 1);
+}
+
void tst_QGraphicsView::scrollAfterResize_data()
{
QTest::addColumn<bool>("reverse");
@@ -3592,6 +3658,9 @@ void tst_QGraphicsView::moveItemWhileScrolling_data()
void tst_QGraphicsView::moveItemWhileScrolling()
{
+ if (isPlatformEGLFS())
+ QSKIP("", "Resizing does not work on EGLFS on top level window", Continue);
+
QFETCH(bool, adjustForAntialiasing);
QFETCH(bool, changedConnected);
@@ -3814,8 +3883,9 @@ void tst_QGraphicsView::mouseTracking2()
EventSpy spy(&scene, QEvent::GraphicsSceneMouseMove);
QCOMPARE(spy.count(), 0);
- QMouseEvent event(QEvent::MouseMove,view.viewport()->rect().center(), Qt::NoButton,
- Qt::MouseButtons(Qt::NoButton), {});
+ auto pos = view.viewport()->rect().center();
+ QMouseEvent event(QEvent::MouseMove, pos, view.viewport()->mapToGlobal(pos),
+ Qt::NoButton, Qt::MouseButtons(Qt::NoButton), {});
QApplication::sendEvent(view.viewport(), &event);
QCOMPARE(spy.count(), 1);
}
@@ -3983,7 +4053,7 @@ void tst_QGraphicsView::exposeRegion()
CustomView view;
view.setScene(&scene);
view.show();
- qApp->setActiveWindow(&view);
+ QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -4057,7 +4127,6 @@ void tst_QGraphicsView::update()
QVERIFY(QTest::qWaitForWindowExposed(&toplevel));
- QApplication::setActiveWindow(&toplevel);
QApplication::processEvents();
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&toplevel));
@@ -4114,6 +4183,9 @@ void tst_QGraphicsView::update2_data()
void tst_QGraphicsView::update2()
{
+ if (isPlatformEGLFS())
+ QSKIP("", "Resizing does not work on EGLFS on top level window", Continue);
+
QFETCH(qreal, penWidth);
QFETCH(bool, antialiasing);
QFETCH(bool, changedConnected);
@@ -4139,7 +4211,7 @@ void tst_QGraphicsView::update2()
view.setFrameStyle(0);
view.resize(200, 200);
view.show();
- qApp->setActiveWindow(&view);
+ QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QTRY_VERIFY(rect->numPaints > 0);
@@ -4209,7 +4281,7 @@ void tst_QGraphicsView::update_ancestorClipsChildrenToShape()
CustomView view(&scene);
view.show();
- qApp->setActiveWindow(&view);
+ QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QTRY_VERIFY(view.painted);
@@ -4263,7 +4335,7 @@ void tst_QGraphicsView::update_ancestorClipsChildrenToShape2()
CustomView view(&scene);
view.show();
- qApp->setActiveWindow(&view);
+ QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QTRY_VERIFY(view.painted);
@@ -4324,7 +4396,6 @@ void tst_QGraphicsView::inputMethodSensitivity()
QGraphicsScene scene;
QGraphicsView view(&scene);
view.show();
- QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
@@ -4422,7 +4493,6 @@ void tst_QGraphicsView::inputContextReset()
QVERIFY(view.testAttribute(Qt::WA_InputMethodEnabled));
view.show();
- QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
@@ -4570,7 +4640,6 @@ void tst_QGraphicsView::task255529_transformationAnchorMouseAndViewportMargins()
VpGraphicsView view(&scene);
view.setWindowFlags(Qt::X11BypassWindowManagerHint);
view.show();
- qApp->setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
const bool isActiveWindow = QTest::qWaitForWindowActive(&view);
if (!isActiveWindow)
@@ -4713,6 +4782,9 @@ void tst_QGraphicsView::QTBUG_4151_clipAndIgnore()
void tst_QGraphicsView::QTBUG_5859_exposedRect()
{
+ if (isPlatformEGLFS())
+ QSKIP("", "Resizing does not work on EGLFS on top level window", Continue);
+
class CustomScene : public QGraphicsScene
{
public:
@@ -4741,7 +4813,6 @@ void tst_QGraphicsView::QTBUG_5859_exposedRect()
QGraphicsView view(&scene);
view.scale(4.15, 4.15);
view.showNormal();
- QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -4813,7 +4884,6 @@ void tst_QGraphicsView::hoverLeave()
scene.addItem(item);
view.showNormal();
- qApp->setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QWindow *viewWindow = view.window()->windowHandle();
@@ -4878,5 +4948,138 @@ void tst_QGraphicsView::QTBUG_16063_microFocusRect()
QCOMPARE(mfv, IMItem::mf.translated(-view.mapToScene(view.sceneRect().toRect()).boundingRect().topLeft()));
}
+void tst_QGraphicsView::QTBUG_70255_scrollTo()
+{
+ QGraphicsView view;
+ QGraphicsScene scene;
+ view.setFixedSize(200, 200);
+ scene.setSceneRect(0, 0, 1000, 1000);
+ QGraphicsRectItem item;
+ item.setRect(-20, -20, 40, 40);
+ item.setFlag(QGraphicsItem::ItemIsMovable, true);
+ scene.addItem(&item);
+ view.setScene(&scene);
+ view.centerOn(0, 0);
+
+ view.show();
+ if (!QTest::qWaitForWindowExposed(&view) || !QTest::qWaitForWindowActive(&view))
+ QSKIP("Failed to show and activate window");
+
+ QPoint point = view.mapFromScene(0, 0);
+ QCOMPARE(point, QPoint(0, 0));
+
+ QScroller::scroller(&view)->scrollTo(QPointF(0, 500), 100);
+ QTest::qWait(200);
+
+ point = view.mapFromScene(0, 0);
+ QCOMPARE(point, QPoint(0, -500));
+}
+
+void tst_QGraphicsView::resizeContentsOnItemDrag_data()
+{
+ QTest::addColumn<Qt::Alignment>("alignment");
+ QTest::addColumn<Qt::Orientation>("orientation");
+ QTest::addRow("Center right") << Qt::Alignment(Qt::AlignCenter) << Qt::Horizontal;
+ QTest::addRow("Center down") << Qt::Alignment(Qt::AlignCenter) << Qt::Vertical;
+ QTest::addRow("BottomLeft right") << (Qt::AlignBottom | Qt::AlignLeft) << Qt::Horizontal;
+ QTest::addRow("TopRight down") << (Qt::AlignTop | Qt::AlignRight) << Qt::Vertical;
+}
+
+void tst_QGraphicsView::resizeContentsOnItemDrag()
+{
+ QFETCH(Qt::Alignment, alignment);
+ QFETCH(Qt::Orientation, orientation);
+
+ QGraphicsView view;
+ QGraphicsScene scene;
+ view.setFixedSize(200, 200);
+ view.setScene(&scene);
+
+ view.setAlignment(alignment);
+
+ class MovableItem : public QGraphicsEllipseItem
+ {
+ public:
+ using QGraphicsEllipseItem::QGraphicsEllipseItem;
+
+ QList<QPointF> scenePositions;
+
+ protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event) override
+ {
+ scenePositions << event->scenePos();
+ }
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override
+ {
+ scenePositions << event->scenePos();
+ QGraphicsEllipseItem::mouseMoveEvent(event);
+ }
+ };
+
+ MovableItem item(-10, -10, 20, 20);
+ item.setFlags(QGraphicsItem::ItemIsMovable);
+ scene.addItem(&item);
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
+ // Position the item near the relevant edge of the view, with a few pixels
+ // to go until the scrollbars should be showing.
+ if (orientation == Qt::Horizontal)
+ item.setPos(view.width() - item.rect().width() - 5, 0);
+ else
+ item.setPos(0, view.height() - item.rect().height() - 5);
+ QApplication::processEvents(); // queued connection used to trigger recalculateContentSize
+ QPoint mousePos = view.mapFromScene(item.pos());
+
+ QTest::mousePress(view.viewport(), Qt::LeftButton, {}, mousePos);
+ QCOMPARE(item.scenePositions.count(), 1);
+ QCOMPARE(item.scenePositions.takeLast(), view.mapToScene(mousePos));
+
+ auto lastItemPos = item.pos();
+ auto lastScenePos = view.mapToScene(mousePos);
+ int overshoot = 0;
+ const QScrollBar *scrollBar = orientation == Qt::Horizontal
+ ? view.horizontalScrollBar()
+ : view.verticalScrollBar();
+ // Drag the item until the scroll bars become visible, and then for a few more pixels.
+ // Verify that the item doesn't jump when the scrollbar shows.
+ while (overshoot < 10) {
+ if (orientation == Qt::Horizontal)
+ mousePos.rx() += 1;
+ else
+ mousePos.ry() += 1;
+ QTest::mouseMove(view.viewport(), mousePos);
+ QApplication::processEvents(); // queued connection used to trigger recalculateContentSize
+ const bool scrollbarAvailable = scrollBar->maximum() > scrollBar->minimum();
+ bool allowMoreEvents = false;
+ if (scrollbarAvailable) {
+ if (!overshoot) {
+ QTRY_VERIFY(scrollBar->isVisible());
+ // scrollbar becoming visible triggers event replay, so we get more than one
+ allowMoreEvents = true;
+ }
+ ++overshoot;
+ }
+ if (allowMoreEvents)
+ QCOMPARE_GE(item.scenePositions.count(), 1);
+ else
+ QCOMPARE(item.scenePositions.count(), 1);
+ const auto scenePos = item.scenePositions.takeLast();
+ item.scenePositions.clear();
+
+ const auto same = orientation == Qt::Horizontal ? &QPointF::y : &QPointF::x;
+ const auto moved = orientation == Qt::Horizontal ? &QPointF::x : &QPointF::y;
+ QCOMPARE((item.pos().*same)(), (lastItemPos.*same)());
+ QCOMPARE_GE((item.pos().*moved)() - (lastItemPos.*moved)(), 1);
+ QCOMPARE_LE((item.pos().*moved)() - (lastItemPos.*moved)(), 2);
+ lastItemPos = item.pos();
+
+ QCOMPARE((scenePos.*same)(), (lastScenePos.*same)());
+ QCOMPARE_GE((scenePos.*moved)() - (lastScenePos.*moved)(), 1);
+ QCOMPARE_LE((scenePos.*moved)() - (lastScenePos.*moved)(), 2);
+ lastScenePos = scenePos;
+ }
+}
+
QTEST_MAIN(tst_QGraphicsView)
#include "tst_qgraphicsview.moc"