From 040e11c52baa95566f3700cda784bd81772eae54 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 26 May 2020 00:20:54 +0200 Subject: [PATCH] Fix ZoomIn getting stuck when on facing pages We need to use int when calculating colWidth in zoomFactorFitMode since we also use int when calculating it in PageView::slotRelayoutPages, otherwise the calculated numbers are veeeeeeery similar but not the same and the algorithm gets all confused BUGS: 420824 --- autotests/parttest.cpp | 24 ++++++++++++++++++++++++ ui/pageview.cpp | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/autotests/parttest.cpp b/autotests/parttest.cpp index bdb6fbfec..822a69661 100644 --- a/autotests/parttest.cpp +++ b/autotests/parttest.cpp @@ -100,6 +100,7 @@ class PartTest void testTabletProximityBehavior(); void testOpenPrintPreview(); void testMouseModeMenu(); + void testZoomInFacingPages(); private: void simulateMouseSelection(double startX, double startY, double endX, double endY, QWidget *target); @@ -1992,6 +1993,29 @@ void PartTest::testMouseModeMenu() QCOMPARE(Okular::Settings::mouseMode(), (int)Okular::Settings::EnumMouseMode::TableSelect ); } +void PartTest::testZoomInFacingPages() +{ + QVariantList dummyArgs; + Okular::Part part(nullptr, nullptr, dummyArgs); + QVERIFY(openDocument(&part, QStringLiteral(KDESRCDIR "data/file2.pdf"))); + QAction *facingAction = part.m_pageView->findChild(QStringLiteral("view_render_mode_facing")); + KSelectAction *zoomSelectAction = part.m_pageView->findChild(QStringLiteral("zoom_to")); + part.widget()->resize(600, 400); + part.widget()->show(); + QVERIFY(QTest::qWaitForWindowExposed(part.widget())); + facingAction->trigger(); + while (zoomSelectAction->currentText() != "12%") { + QVERIFY(QMetaObject::invokeMethod(part.m_pageView, "slotZoomOut")); + } + QTRY_VERIFY( part.m_document->page( 0 )->hasPixmap( part.m_pageView ) ); + QVERIFY(QMetaObject::invokeMethod(part.m_pageView, "slotZoomIn")); + QVERIFY(QMetaObject::invokeMethod(part.m_pageView, "slotZoomIn")); + QVERIFY(QMetaObject::invokeMethod(part.m_pageView, "slotZoomIn")); + QVERIFY(QMetaObject::invokeMethod(part.m_pageView, "slotZoomIn")); + QVERIFY(QMetaObject::invokeMethod(part.m_pageView, "slotZoomIn")); + QTRY_COMPARE(zoomSelectAction->currentText(), QStringLiteral("66%")); +} + } // namespace Okular int main(int argc, char *argv[]) diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 1d5782c6f..93deb928b 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -4097,7 +4097,7 @@ double PageView::zoomFactorFitMode( ZoomMode mode ) const bool facingCentered = Okular::Settings::viewMode() == Okular::Settings::EnumViewMode::FacingFirstCentered || (Okular::Settings::viewMode() == Okular::Settings::EnumViewMode::Facing && pageCount == 1); const bool overrideCentering = facingCentered && pageCount < 3; const int nCols = overrideCentering ? 1 : viewColumns(); - const double colWidth = viewport()->width() / static_cast(nCols) - kcolWidthMargin; + const int colWidth = viewport()->width() / nCols - kcolWidthMargin; const double rowHeight = viewport()->height() - krowHeightMargin; const PageViewItem * currentItem = d->items[ qMax( 0, (int)d->document->currentPage()) ]; // prevent segmentation fault when opening a new document;