summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-06-15 17:49:04 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-16 20:33:12 +0000
commit35ec4c011ca9ed12ceec0c088c0e815210b38c33 (patch)
tree081473b385d0a38756d0c232c7020a0af176f9ca
parentf1276c0d10e706ab02eb76eca9c2bd96b0b80656 (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 Change-Id: Ib9a848619e3ba8780264ad76ed43c4fffae6b07f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Andy Shaw <andy.shaw@qt.io> (cherry picked from commit 6ce44c53c7aa802b817b72d49de88e4da0181488) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_win.cpp31
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) {