diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-06-15 17:49:04 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-06-16 13:22:18 +0200 |
commit | 6ce44c53c7aa802b817b72d49de88e4da0181488 (patch) | |
tree | e673aa0bdbdc1f7d3f42ed0366bd4baa0331cccf /src | |
parent | dc1efcfc931a149c8ce65abab452f516d4ffc035 (diff) |
Windows: Read page size and orientation from setup dialog
PAGESETUPDLG's hDevMode reports the page size and orientation selection
of the user, so read that data to get accurate results.
Otherwise, the page size of a landscape page wouldn't match any known
page format, and we'd end up with a custom size that would not be valid
for the preview, breaking the preview UI's orientation state.
Reuse the helper from QPageSize to map Windows page size ID to our own
enum.
Fixes: QTBUG-93764
Pick-to: 6.2 6.1 5.15
Change-Id: Ib9a848619e3ba8780264ad76ed43c4fffae6b07f
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/printsupport/dialogs/qpagesetupdialog_win.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/printsupport/dialogs/qpagesetupdialog_win.cpp b/src/printsupport/dialogs/qpagesetupdialog_win.cpp index 2e2b41b372..6d51473d52 100644 --- a/src/printsupport/dialogs/qpagesetupdialog_win.cpp +++ b/src/printsupport/dialogs/qpagesetupdialog_win.cpp @@ -134,10 +134,35 @@ int QPageSetupDialog::exec() QDialog::setVisible(false); if (result) { engine->setGlobalDevMode(psd.hDevNames, psd.hDevMode); - d->printer->setPageSize(QPageSize(QSizeF(psd.ptPaperSize.x / multiplier, psd.ptPaperSize.y / multiplier), - layout.units() == QPageLayout::Inch ? QPageSize::Inch : QPageSize::Millimeter)); + QPageSize pageSize; + // try to read orientation and paper size ID from the dialog's devmode struct + if (psd.hDevMode) { + DEVMODE *rDevmode = reinterpret_cast<DEVMODE*>(GlobalLock(psd.hDevMode)); + if (rDevmode->dmFields & DM_ORIENTATION) { + layout.setOrientation(rDevmode->dmOrientation == DMORIENT_PORTRAIT + ? QPageLayout::Portrait : QPageLayout::Landscape); + } + if (rDevmode->dmFields & DM_PAPERSIZE) + pageSize = QPageSize::id(rDevmode->dmPaperSize); + GlobalUnlock(rDevmode); + } + // fall back to use our own matching, and assume that paper that's wider than long means landscape + if (!pageSize.isValid() || pageSize.id() == QPageSize::Custom) { + QSizeF unitSize(psd.ptPaperSize.x / multiplier, psd.ptPaperSize.y / multiplier); + if (unitSize.width() > unitSize.height()) { + layout.setOrientation(QPageLayout::Landscape); + unitSize.transpose(); + } else { + layout.setOrientation(QPageLayout::Portrait); + } + pageSize = QPageSize(unitSize, layout.units() == QPageLayout::Inch + ? QPageSize::Inch : QPageSize::Millimeter); + } + layout.setPageSize(pageSize); + const QMarginsF margins(psd.rtMargin.left, psd.rtMargin.top, psd.rtMargin.right, psd.rtMargin.bottom); - d->printer->setPageMargins(margins / multiplier, layout.units()); + layout.setMargins(margins / multiplier); + d->printer->setPageLayout(layout); // copy from our temp DEVMODE struct if (!engine->globalDevMode() && hDevMode) { |