14.18 round 1: a starved PDF throws, an early zoom centres, inches round to even, tests tightened

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 09:38:52 -04:00
1 parent 9be01073df
commit cd31454815
13 files changed
+210 -15

No files matched your search

+30
View File
@@ -21,6 +21,7 @@ private slots:
void theUpdatingPlateSitsInTheMiddle();
void zoomKeepsTheMiddleAndDragsMoveIt();
void theSheetsButtonsAndKeysZoomIt();
void aZoomBeforeTheFirstImageCentresIt();
};
namespace {
@@ -303,5 +304,34 @@ void JPEGPreviewTests::theSheetsButtonsAndKeysZoomIt()
ShortcutSettings::shared().reload();
}
// Swift makes the preview with its first result, centred.
void JPEGPreviewTests::aZoomBeforeTheFirstImageCentresIt()
{
EditorSession session;
QImage red(1200, 800, QImage::Format_RGBA8888_Premultiplied);
red.fill(Qt::red);
const auto offsets = [&](bool early) {
ExportAsSheet sheet({red, 72}, session, ExportFormat::png, [](std::optional<ExportAsSheet::Chosen>) {});
sheet.show();
auto &exporting = *sheet.findChild<QPushButton *>(QStringLiteral("exportExport"));
if (early) {
if (!QTest::qWaitForWindowActive(&sheet) || exporting.isEnabled())
throw std::runtime_error("ready before the key");
QTest::keyClick(&sheet, Qt::Key_1, Qt::ControlModifier);
}
if (!QTest::qWaitFor([&] { return exporting.isEnabled(); }))
throw std::runtime_error("never ready");
auto &preview = *sheet.findChild<JPEGPreview *>();
if (!early)
preview.setZoom(1);
const QSize view = preview.viewport()->size();
return std::array<int, 4>{preview.horizontalScrollBar()->value(), preview.verticalScrollBar()->value(), view.width(), view.height()};
};
const std::array<int, 4> early = offsets(true), late = offsets(false);
QCOMPARE(early, late);
QVERIFY(early[0] == int(std::lround(600 - early[2] / 2.0)) && early[1] == int(std::lround(400 - early[3] / 2.0)));
QVERIFY(early[0] > 300 && early[1] > 200);
}
QTEST_MAIN(JPEGPreviewTests)
#include "JPEGPreviewTests.moc"