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
This commit is contained in:
Albert Astals Cid 2020-05-26 00:20:54 +02:00
parent a0d6a377cb
commit 040e11c52b
2 changed files with 25 additions and 1 deletions

View file

@ -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<QAction*>(QStringLiteral("view_render_mode_facing"));
KSelectAction *zoomSelectAction = part.m_pageView->findChild<KSelectAction*>(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[])

View file

@ -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<double>(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;