@@ -66,6 +66,57 @@ private slots:
6666 QApplication::setFont (QFont (QFontDatabase::applicationFontFamilies (fontId).first (), 10 ));
6767 }
6868 void cleanupTestCase () { FPDF_DestroyLibrary (); }
69+ void documentDragScrolling () {
70+ QTemporaryDir directory;
71+ const auto path = directory.filePath (" drag.pdf" );
72+ {
73+ QPdfWriter writer (path);
74+ QPainter painter (&writer);
75+ painter.fillRect (QRect (0 , 0 , 100 , 100 ), Qt::red);
76+ }
77+ PdfView view;
78+ view.resize (700 , 450 );
79+ view.show ();
80+ QString error;
81+ QVERIFY2 (view.open (path, {}, &error), qPrintable (error));
82+ view.setZoom (1.0 );
83+ QTest::qWait (20 );
84+ auto bar = view.verticalScrollBar ();
85+ QVERIFY (bar->maximum () > 200 );
86+ bar->setValue (0 );
87+ const QPoint start (view.viewport ()->width () / 2 , 250 );
88+ QTest::mousePress (view.viewport (), Qt::LeftButton, Qt::NoModifier, start);
89+ QTest::mouseMove (view.viewport (), start - QPoint (0 , 2 ));
90+ QCOMPARE (bar->value (), 0 );
91+ QTest::mouseMove (view.viewport (), start + QPoint (30 , -100 ));
92+ QCOMPARE (bar->value (), 100 );
93+ QCOMPARE (view.horizontalScrollBar ()->value (), 0 );
94+ QCOMPARE (view.viewport ()->cursor ().shape (), Qt::ClosedHandCursor);
95+ QVERIFY (!view.hasSelection ());
96+ QTest::mouseMove (view.viewport (), start - QPoint (0 , 40 ));
97+ QCOMPARE (bar->value (), 40 );
98+ QTest::mouseRelease (view.viewport (), Qt::LeftButton, Qt::NoModifier, start - QPoint (0 , 40 ));
99+ QVERIFY (view.viewport ()->cursor ().shape () != Qt::ClosedHandCursor);
100+ QTest::mouseMove (view.viewport (), start);
101+ QCOMPARE (bar->value (), 40 );
102+
103+ // Background margins and right-button drags must not pan the document.
104+ for (const auto button : {Qt::LeftButton, Qt::RightButton}) {
105+ const QPoint origin = button == Qt::LeftButton ? QPoint (5 , 250 ) : start;
106+ QTest::mousePress (view.viewport (), button, Qt::NoModifier, origin);
107+ QTest::mouseMove (view.viewport (), origin - QPoint (0 , 80 ));
108+ QTest::mouseRelease (view.viewport (), button, Qt::NoModifier, origin - QPoint (0 , 80 ));
109+ QCOMPARE (bar->value (), 40 );
110+ }
111+ QTest::mousePress (view.viewport (), Qt::LeftButton, Qt::NoModifier, start);
112+ QTest::mouseMove (view.viewport (), start - QPoint (0 , 80 ));
113+ QCOMPARE (bar->value (), 120 );
114+ view.hide ();
115+ view.show ();
116+ QTest::mouseMove (view.viewport (), start);
117+ QCOMPARE (bar->value (), 120 );
118+ QTest::mouseRelease (view.viewport (), Qt::LeftButton, Qt::NoModifier, start);
119+ }
69120 void textSelection_data () {
70121 QTest::addColumn<int >(" rotation" );
71122 for (int rotation : {0 , 90 , 180 , 270 })
0 commit comments