summaryrefslogtreecommitdiffstats
path: root/src/printsupport/dialogs
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2013-12-30 18:04:40 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-17 13:46:10 +0100
commitdbc50e06df8465e6de02ac0b4458e1a3f3f8568c (patch)
tree58375129a608575a7b99e6a3167baa668c9d7c25 /src/printsupport/dialogs
parent70081096a152d6973d85a1c1466bbc058fe0b24b (diff)
QPrinter - Use QPageSize and QPageLayout
Use QPageSize and QPageMargins to get/set values in the print engines, add api to directly set the values, and rewrite the docs to make the paper-based api obsolete instead of the page-based api. Add new PPK keys to pass QPageSize, QPageMargins and QPageLayout to the print engines to ensure no level of detail is lost, e.g. for custom sizes passed to QPrinter. [ChangeLog][QtPrintSupport][QPrinter] QPrinter can now use QPageSize and QPageLayout in the public api to control the page layout for a print job. Change-Id: Iee39a4042bcd6141d29b0a82b49066d7a7a78120 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/printsupport/dialogs')
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_unix.cpp13
-rw-r--r--src/printsupport/dialogs/qprintdialog_mac.mm41
2 files changed, 42 insertions, 12 deletions
diff --git a/src/printsupport/dialogs/qpagesetupdialog_unix.cpp b/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
index d2975ad9da..7b84d8b86f 100644
--- a/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
+++ b/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
@@ -434,18 +434,7 @@ void QPageSetupWidget::selectPrinter()
}
if (!preferredSizeMatched)
widget.paperSize->setCurrentIndex(cupsDefaultSize);
- if (m_printer->d_func()->hasCustomPageMargins) {
- m_printer->getPageMargins(&m_leftMargin, &m_topMargin, &m_rightMargin, &m_bottomMargin, QPrinter::Point);
- } else {
- QByteArray cupsPaperSizeChoice = widget.paperSize->itemData(widget.paperSize->currentIndex()).toByteArray();
- QRect paper = cups.paperRect(cupsPaperSizeChoice);
- QRect content = cups.pageRect(cupsPaperSizeChoice);
-
- m_leftMargin = content.x() - paper.x();
- m_topMargin = content.y() - paper.y();
- m_rightMargin = paper.right() - content.right();
- m_bottomMargin = paper.bottom() - content.bottom();
- }
+ m_printer->getPageMargins(&m_leftMargin, &m_topMargin, &m_rightMargin, &m_bottomMargin, QPrinter::Point);
} else
m_cups = false;
#endif
diff --git a/src/printsupport/dialogs/qprintdialog_mac.mm b/src/printsupport/dialogs/qprintdialog_mac.mm
index 67216f7f2a..7194aee22f 100644
--- a/src/printsupport/dialogs/qprintdialog_mac.mm
+++ b/src/printsupport/dialogs/qprintdialog_mac.mm
@@ -151,6 +151,47 @@ QT_USE_NAMESPACE
}
}
+ // Note this code should be in QCocoaPrintDevice, but that implementation is in the plugin,
+ // we need to move the dialog implementation into the plugin first to be able to access it.
+ // Need to tell QPrinter/QPageLayout if the page size or orientation has been changed
+ PMPageFormat pageFormat = static_cast<PMPageFormat>([printInfo PMPageFormat]);
+ PMPaper paper;
+ PMGetPageFormatPaper(pageFormat, &paper);
+ PMOrientation orientation;
+ PMGetOrientation(pageFormat, &orientation);
+ QPageSize pageSize;
+ QCFString key;
+ double width = 0;
+ double height = 0;
+ // If the PPD name is empty then is custom, for some reason PMPaperIsCustom doesn't work here
+ PMPaperGetPPDPaperName(paper, &key);
+ if (PMPaperGetWidth(paper, &width) == noErr && PMPaperGetHeight(paper, &height) == noErr) {
+ QString ppdKey = key;
+ if (ppdKey.isEmpty()) {
+ // Is using a custom page size as defined in the Print Dialog custom settings using mm or inches.
+ // We can't ask PMPaper what those units actually are, we can only get the point size which may return
+ // slightly wrong results due to rounding.
+ // Testing shows if using metric/mm then is rounded mm, if imperial/inch is rounded to 2 decimal places
+ // Even if we pass in our own custom size in mm with decimal places, the dialog will still round it!
+ // Suspect internal storage is in rounded mm?
+ if (QLocale().measurementSystem() == QLocale::MetricSystem) {
+ QSizeF sizef = QSizeF(width, height) / qt_pointMultiplier(QPageLayout::Millimeter);
+ // Round to 0 decimal places
+ pageSize = QPageSize(sizef.toSize(), QPageSize::Millimeter);
+ } else {
+ qreal multiplier = qt_pointMultiplier(QPageLayout::Inch);
+ const int w = qRound(width * 100 / multiplier);
+ const int h = qRound(height * 100 / multiplier);
+ pageSize = QPageSize(QSizeF(w / 100.0, h / 100.0), QPageSize::Inch);
+ }
+ } else {
+ pageSize = QPlatformPrintDevice::createPageSize(key, QSize(width, height), QString());
+ }
+ }
+ if (pageSize.isValid() && !pageSize.isEquivalentTo(printer->pageLayout().pageSize()))
+ printer->setPageSize(pageSize);
+ printer->setOrientation(orientation == kPMLandscape ? QPrinter::Landscape : QPrinter::Portrait);
+
dialog->done((returnCode == NSOKButton) ? QDialog::Accepted : QDialog::Rejected);
}
@end