summaryrefslogtreecommitdiffstats
path: root/src/printsupport/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'src/printsupport/dialogs')
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_unix.cpp701
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_unix_p.h48
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_win.cpp52
-rw-r--r--src/printsupport/dialogs/qpagesetupwidget.ui14
-rw-r--r--src/printsupport/dialogs/qprintdialog_mac.mm44
-rw-r--r--src/printsupport/dialogs/qprintdialog_unix.cpp167
6 files changed, 505 insertions, 521 deletions
diff --git a/src/printsupport/dialogs/qpagesetupdialog_unix.cpp b/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
index 6801863a3a..b9041bb242 100644
--- a/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
+++ b/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
@@ -44,68 +44,25 @@
#ifndef QT_NO_PRINTDIALOG
#include "qpagesetupdialog_unix_p.h"
+#include <private/qpagesetupdialog_p.h>
+#include <private/qprintdevice_p.h>
+#include <private/qcups_p.h>
+
#include "qpainter.h"
#include "qprintdialog.h"
#include "qdialogbuttonbox.h"
#include <ui_qpagesetupwidget.h>
#include <QtPrintSupport/qprinter.h>
-#include <private/qpagesetupdialog_p.h>
-#include <private/qprinter_p.h>
-#include <private/qprintengine_pdf_p.h>
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
-# include <private/qcups_p.h>
-#endif
+#include <qpa/qplatformprintplugin.h>
+#include <qpa/qplatformprintersupport.h>
QT_BEGIN_NAMESPACE
-QSizeF qt_printerPaperSize(QPrinter::Orientation, QPrinter::PaperSize, QPrinter::Unit, int);
-
// Disabled until we have support for papersources on unix
// #define PSD_ENABLE_PAPERSOURCE
-static void populatePaperSizes(QComboBox* cb)
-{
- cb->addItem(QPrintDialog::tr("A0"), QPrinter::A0);
- cb->addItem(QPrintDialog::tr("A1"), QPrinter::A1);
- cb->addItem(QPrintDialog::tr("A2"), QPrinter::A2);
- cb->addItem(QPrintDialog::tr("A3"), QPrinter::A3);
- cb->addItem(QPrintDialog::tr("A4"), QPrinter::A4);
- cb->addItem(QPrintDialog::tr("A5"), QPrinter::A5);
- cb->addItem(QPrintDialog::tr("A6"), QPrinter::A6);
- cb->addItem(QPrintDialog::tr("A7"), QPrinter::A7);
- cb->addItem(QPrintDialog::tr("A8"), QPrinter::A8);
- cb->addItem(QPrintDialog::tr("A9"), QPrinter::A9);
- cb->addItem(QPrintDialog::tr("B0"), QPrinter::B0);
- cb->addItem(QPrintDialog::tr("B1"), QPrinter::B1);
- cb->addItem(QPrintDialog::tr("B2"), QPrinter::B2);
- cb->addItem(QPrintDialog::tr("B3"), QPrinter::B3);
- cb->addItem(QPrintDialog::tr("B4"), QPrinter::B4);
- cb->addItem(QPrintDialog::tr("B5"), QPrinter::B5);
- cb->addItem(QPrintDialog::tr("B6"), QPrinter::B6);
- cb->addItem(QPrintDialog::tr("B7"), QPrinter::B7);
- cb->addItem(QPrintDialog::tr("B8"), QPrinter::B8);
- cb->addItem(QPrintDialog::tr("B9"), QPrinter::B9);
- cb->addItem(QPrintDialog::tr("B10"), QPrinter::B10);
- cb->addItem(QPrintDialog::tr("C5E"), QPrinter::C5E);
- cb->addItem(QPrintDialog::tr("DLE"), QPrinter::DLE);
- cb->addItem(QPrintDialog::tr("Executive"), QPrinter::Executive);
- cb->addItem(QPrintDialog::tr("Folio"), QPrinter::Folio);
- cb->addItem(QPrintDialog::tr("Ledger"), QPrinter::Ledger);
- cb->addItem(QPrintDialog::tr("Legal"), QPrinter::Legal);
- cb->addItem(QPrintDialog::tr("Letter"), QPrinter::Letter);
- cb->addItem(QPrintDialog::tr("Tabloid"), QPrinter::Tabloid);
- cb->addItem(QPrintDialog::tr("US Common #10 Envelope"), QPrinter::Comm10E);
- cb->addItem(QPrintDialog::tr("Custom"), QPrinter::Custom);
-}
-
-
-static QSizeF sizeForOrientation(QPrinter::Orientation orientation, const QSizeF &size)
-{
- return (orientation == QPrinter::Portrait) ? size : QSizeF(size.height(), size.width());
-}
-
#ifdef PSD_ENABLE_PAPERSOURCE
static const char *paperSourceNames[] = {
"Only One",
@@ -134,6 +91,10 @@ struct PaperSourceNames
#endif
+// QPagePreview
+// - Private widget to display preview of page layout
+// - Embedded in QPageSetupWidget
+
class QPagePreview : public QWidget
{
public:
@@ -143,18 +104,9 @@ public:
setMinimumSize(50, 50);
}
- void setPaperSize(const QSizeF& size)
- {
- m_size = size;
- update();
- }
-
- void setMargins(qreal left, qreal top, qreal right, qreal bottom)
+ void setPageLayout(const QPageLayout &layout)
{
- m_left = left;
- m_top = top;
- m_right = right;
- m_bottom = bottom;
+ m_pageLayout = layout;
update();
}
@@ -168,22 +120,19 @@ public:
protected:
void paintEvent(QPaintEvent *)
{
- QRect pageRect;
- QSizeF adjustedSize(m_size);
- adjustedSize.scale(width()-10, height()-10, Qt::KeepAspectRatio);
- pageRect = QRect(QPoint(0,0), adjustedSize.toSize());
+ QSize pageSize = m_pageLayout.fullRectPoints().size();
+ QSizeF scaledSize = pageSize.scaled(width() - 10, height() - 10, Qt::KeepAspectRatio);
+ QRect pageRect = QRect(QPoint(0,0), scaledSize.toSize());
pageRect.moveCenter(rect().center());
-
- qreal width_factor = pageRect.width() / m_size.width();
- qreal height_factor = pageRect.height() / m_size.height();
- int leftSize = qRound(m_left*width_factor);
- int topSize = qRound(m_top*height_factor);
- int rightSize = qRound(m_right*width_factor);
- int bottomSize = qRound(m_bottom * height_factor);
- QRect marginRect(pageRect.x()+leftSize,
- pageRect.y()+topSize,
- pageRect.width() - (leftSize+rightSize+1),
- pageRect.height() - (topSize+bottomSize+1));
+ qreal width_factor = scaledSize.width() / pageSize.width();
+ qreal height_factor = scaledSize.height() / pageSize.height();
+ QMarginsF margins = m_pageLayout.margins(QPageLayout::Point);
+ int left = qRound(margins.left() * width_factor);
+ int top = qRound(margins.top() * height_factor);
+ int right = qRound(margins.right() * width_factor);
+ int bottom = qRound(margins.bottom() * height_factor);
+ QRect marginRect(pageRect.x() + left, pageRect.y() + top,
+ pageRect.width() - (left + right + 1), pageRect.height() - (top + bottom + 1));
QPainter p(this);
QColor shadow(palette().mid().color());
@@ -226,14 +175,17 @@ protected:
}
private:
- // all these are in points
- qreal m_left, m_top, m_right, m_bottom;
- // specify width / height of one page in preview
+ // Page Layout
+ QPageLayout m_pageLayout;
+ // Pages Per Sheet / n-up layout
int m_pagePreviewColumns, m_pagePreviewRows;
- QSizeF m_size;
};
+// QUnixPageSetupDialogPrivate
+// - Linux / Cups implementation of QPageSetupDialogPrivate
+// - Embeds QPageSetupWidget
+
class QUnixPageSetupDialogPrivate : public QPageSetupDialogPrivate
{
Q_DECLARE_PUBLIC(QPageSetupDialog)
@@ -272,27 +224,24 @@ void QUnixPageSetupDialogPrivate::init()
lay->addWidget(buttons);
}
+// QPageSetupWidget
+// - Private widget implementation for Linux / CUPS
+// - Embeds QPagePreview
+// - TODO Could be made public as a stand-alone widget?
+
QPageSetupWidget::QPageSetupWidget(QWidget *parent)
: QWidget(parent),
- m_printer(0),
- m_blockSignals(false),
- m_cups(false)
+ m_pagePreview(0),
+ m_printer(0),
+ m_outputFormat(QPrinter::PdfFormat),
+ m_units(QPageLayout::Point),
+ m_blockSignals(false)
{
- widget.setupUi(this);
-
- QString suffix = (QLocale::system().measurementSystem() == QLocale::ImperialSystem)
- ? QString::fromLatin1(" in")
- : QString::fromLatin1(" mm");
- widget.topMargin->setSuffix(suffix);
- widget.bottomMargin->setSuffix(suffix);
- widget.leftMargin->setSuffix(suffix);
- widget.rightMargin->setSuffix(suffix);
- widget.paperWidth->setSuffix(suffix);
- widget.paperHeight->setSuffix(suffix);
-
- QVBoxLayout *lay = new QVBoxLayout(widget.preview);
- widget.preview->setLayout(lay);
- m_pagePreview = new QPagePreview(widget.preview);
+ m_ui.setupUi(this);
+
+ QVBoxLayout *lay = new QVBoxLayout(m_ui.preview);
+ m_ui.preview->setLayout(lay);
+ m_pagePreview = new QPagePreview(m_ui.preview);
m_pagePreview->setPagePreviewLayout(1, 1);
lay->addWidget(m_pagePreview);
@@ -301,253 +250,308 @@ QPageSetupWidget::QPageSetupWidget(QWidget *parent)
#ifdef PSD_ENABLE_PAPERSOURCE
for (int i=0; paperSourceNames[i]; ++i)
- widget.paperSource->insertItem(paperSourceNames[i]);
+ m_ui.paperSource->insertItem(paperSourceNames[i]);
#else
- widget.paperSourceLabel->setVisible(false);
- widget.paperSource->setVisible(false);
+ m_ui.paperSourceLabel->setVisible(false);
+ m_ui.paperSource->setVisible(false);
#endif
- widget.reverseLandscape->setVisible(false);
- widget.reversePortrait->setVisible(false);
+ m_ui.reverseLandscape->setVisible(false);
+ m_ui.reversePortrait->setVisible(false);
- populatePaperSizes(widget.paperSize);
+ initUnits();
initPagesPerSheet();
- QStringList units;
- units << tr("Centimeters (cm)") << tr("Millimeters (mm)") << tr("Inches (in)") << tr("Points (pt)");
- widget.unit->addItems(units);
- connect(widget.unit, SIGNAL(activated(int)), this, SLOT(unitChanged(int)));
- widget.unit->setCurrentIndex((QLocale::system().measurementSystem() == QLocale::ImperialSystem) ? 2 : 1);
- connect(widget.paperSize, SIGNAL(currentIndexChanged(int)), this, SLOT(_q_paperSizeChanged()));
- connect(widget.paperWidth, SIGNAL(valueChanged(double)), this, SLOT(_q_paperSizeChanged()));
- connect(widget.paperHeight, SIGNAL(valueChanged(double)), this, SLOT(_q_paperSizeChanged()));
+ connect(m_ui.unitCombo, SIGNAL(activated(int)), this, SLOT(unitChanged()));
- connect(widget.leftMargin, SIGNAL(valueChanged(double)), this, SLOT(setLeftMargin(double)));
- connect(widget.topMargin, SIGNAL(valueChanged(double)), this, SLOT(setTopMargin(double)));
- connect(widget.rightMargin, SIGNAL(valueChanged(double)), this, SLOT(setRightMargin(double)));
- connect(widget.bottomMargin, SIGNAL(valueChanged(double)), this, SLOT(setBottomMargin(double)));
+ connect(m_ui.pageSizeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(pageSizeChanged()));
+ connect(m_ui.pageWidth, SIGNAL(valueChanged(double)), this, SLOT(pageSizeChanged()));
+ connect(m_ui.pageHeight, SIGNAL(valueChanged(double)), this, SLOT(pageSizeChanged()));
- connect(widget.portrait, SIGNAL(clicked()), this, SLOT(_q_pageOrientationChanged()));
- connect(widget.landscape, SIGNAL(clicked()), this, SLOT(_q_pageOrientationChanged()));
- connect(widget.pagesPerSheetCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(_q_pagesPerSheetChanged()));
+ connect(m_ui.leftMargin, SIGNAL(valueChanged(double)), this, SLOT(leftMarginChanged(double)));
+ connect(m_ui.topMargin, SIGNAL(valueChanged(double)), this, SLOT(topMarginChanged(double)));
+ connect(m_ui.rightMargin, SIGNAL(valueChanged(double)), this, SLOT(rightMarginChanged(double)));
+ connect(m_ui.bottomMargin, SIGNAL(valueChanged(double)), this, SLOT(bottomMarginChanged(double)));
+ connect(m_ui.portrait, SIGNAL(clicked()), this, SLOT(pageOrientationChanged()));
+ connect(m_ui.landscape, SIGNAL(clicked()), this, SLOT(pageOrientationChanged()));
+
+ connect(m_ui.pagesPerSheetCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(pagesPerSheetChanged()));
}
-void QPageSetupWidget::setPrinter(QPrinter *printer)
+// Init the Units combo box
+void QPageSetupWidget::initUnits()
{
- m_printer = printer;
- m_blockSignals = true;
- selectPdfPsPrinter(printer);
- printer->getPageMargins(&m_leftMargin, &m_topMargin, &m_rightMargin, &m_bottomMargin, QPrinter::Point);
- unitChanged(widget.unit->currentIndex());
- m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
- m_paperSize = printer->paperSize(QPrinter::Point);
- widget.paperWidth->setValue(m_paperSize.width() / m_currentMultiplier);
- widget.paperHeight->setValue(m_paperSize.height() / m_currentMultiplier);
-
- widget.landscape->setChecked(printer->orientation() == QPrinter::Landscape);
+ m_ui.unitCombo->addItem(tr("Millimeters (mm)"), QVariant::fromValue(QPageLayout::Millimeter));
+ m_ui.unitCombo->addItem(tr("Inches (in)"), QVariant::fromValue(QPageLayout::Inch));
+ m_ui.unitCombo->addItem(tr("Points (pt)"), QVariant::fromValue(QPageLayout::Point));
+ m_ui.unitCombo->addItem(tr("Pica (P̸)"), QVariant::fromValue(QPageLayout::Pica));
+ m_ui.unitCombo->addItem(tr("Didot (DD)"), QVariant::fromValue(QPageLayout::Didot));
+ m_ui.unitCombo->addItem(tr("Cicero (CC)"), QVariant::fromValue(QPageLayout::Cicero));
+
+ // Initailly default to locale measurement system, mm if metric, in otherwise
+ m_ui.unitCombo->setCurrentIndex(QLocale().measurementSystem() != QLocale::MetricSystem);
+}
-#ifdef PSD_ENABLE_PAPERSOURCE
- widget.paperSource->setCurrentItem(printer->paperSource());
+// Init the Pages Per Sheet (n-up) combo boxes if using CUPS
+void QPageSetupWidget::initPagesPerSheet()
+{
+#if !defined(QT_NO_CUPS)
+ m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Left to Right, Top to Bottom"),
+ QVariant::fromValue(QCUPSSupport::LeftToRightTopToBottom));
+ m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Left to Right, Bottom to Top"),
+ QVariant::fromValue(QCUPSSupport::LeftToRightBottomToTop));
+ m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Right to Left, Bottom to Top"),
+ QVariant::fromValue(QCUPSSupport::RightToLeftBottomToTop));
+ m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Right to Left, Top to Bottom"),
+ QVariant::fromValue(QCUPSSupport::RightToLeftTopToBottom));
+ m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Bottom to Top, Left to Right"),
+ QVariant::fromValue(QCUPSSupport::BottomToTopLeftToRight));
+ m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Bottom to Top, Right to Left"),
+ QVariant::fromValue(QCUPSSupport::BottomToTopRightToLeft));
+ m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Top to Bottom, Left to Right"),
+ QVariant::fromValue(QCUPSSupport::TopToBottomLeftToRight));
+ m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Top to Bottom, Right to Left"),
+ QVariant::fromValue(QCUPSSupport::TopToBottomRightToLeft));
+
+ m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("1 (1x1)"),
+ QVariant::fromValue(QCUPSSupport::OnePagePerSheet));
+ m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("2 (2x1)"),
+ QVariant::fromValue(QCUPSSupport::TwoPagesPerSheet));
+ m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("4 (2x2)"),
+ QVariant::fromValue(QCUPSSupport::FourPagesPerSheet));
+ m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("6 (2x3)"),
+ QVariant::fromValue(QCUPSSupport::SixPagesPerSheet));
+ m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("9 (3x3)"),
+ QVariant::fromValue(QCUPSSupport::NinePagesPerSheet));
+ m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("16 (4x4)"),
+ QVariant::fromValue(QCUPSSupport::SixteenPagesPerSheet));
+
+ // Set to QCUPSSupport::OnePagePerSheet
+ m_ui.pagesPerSheetCombo->setCurrentIndex(0);
+ // Set to QCUPSSupport::LeftToRightTopToBottom
+ m_ui.pagesPerSheetLayoutCombo->setCurrentIndex(0);
+#else
+ // Disable if CUPS wasn't found
+ m_ui.pagesPerSheetButtonGroup->hide();
#endif
- Q_ASSERT(m_blockSignals);
- m_blockSignals = false;
- _q_paperSizeChanged();
}
-// set gui data on printer
-void QPageSetupWidget::setupPrinter() const
+void QPageSetupWidget::initPageSizes()
{
- QPrinter::Orientation orientation = widget.portrait->isChecked()
- ? QPrinter::Portrait
- : QPrinter::Landscape;
- m_printer->setOrientation(orientation);
- // paper format
- QVariant val = widget.paperSize->itemData(widget.paperSize->currentIndex());
- int ps = m_printer->pageSize();
- if (val.type() == QVariant::Int) {
- ps = val.toInt();
- }
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- else if (val.type() == QVariant::ByteArray) {
- for (int papersize = 0; papersize < QPrinter::NPageSize; ++papersize) {
- QPdf::PaperSize size = QPdf::paperSize(QPrinter::PaperSize(papersize));
- if (size.width == m_paperSize.width() && size.height == m_paperSize.height()) {
- ps = static_cast<QPrinter::PaperSize>(papersize);
- break;
+ m_blockSignals = true;
+
+ m_ui.pageSizeCombo->clear();
+
+ if (m_outputFormat == QPrinter::NativeFormat && !m_printerName.isEmpty()) {
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps) {
+ QPrintDevice printDevice = ps->createPrintDevice(m_printerName);
+ foreach (const QPageSize &pageSize, printDevice.supportedPageSizes()) {
+ m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize.id()));
+ }
+ if (m_ui.pageSizeCombo->count() > 0 && printDevice.supportsCustomPageSizes()) {
+ m_ui.pageSizeCombo->addItem(tr("Custom"), QVariant::fromValue(QPageSize::Custom));
+ m_blockSignals = false;
+ return;
}
}
}
-#endif
- if (ps == QPrinter::Custom) {
- m_printer->setPaperSize(sizeForOrientation(orientation, m_paperSize), QPrinter::Point);
- }
- else {
- m_printer->setPaperSize(static_cast<QPrinter::PaperSize>(ps));
- }
- m_printer->setPaperName(widget.paperSize->currentText());
-#ifdef PSD_ENABLE_PAPERSOURCE
- m_printer->setPaperSource((QPrinter::PaperSource)widget.paperSource->currentIndex());
-#endif
- m_printer->setPageMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin, QPrinter::Point);
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- QCUPSSupport::PagesPerSheet pagesPerSheet = widget.pagesPerSheetCombo->currentData()
- .value<QCUPSSupport::PagesPerSheet>();
- QCUPSSupport::PagesPerSheetLayout pagesPerSheetLayout = widget.pagesPerSheetLayoutCombo->currentData()
- .value<QCUPSSupport::PagesPerSheetLayout>();
+ // If PdfFormat or no available printer page sizes, populate with all page sizes
+ for (int id = 0; id < QPageSize::LastPageSize; ++id) {
+ if (QPageSize::PageSizeId(id) == QPageSize::Custom) {
+ m_ui.pageSizeCombo->addItem(tr("Custom"), id);
+ } else {
+ QPageSize pageSize = QPageSize(QPageSize::PageSizeId(id));
+ m_ui.pageSizeCombo->addItem(pageSize.name(), id);
+ }
+ }
- QCUPSSupport::setPagesPerSheetLayout(m_printer, pagesPerSheet, pagesPerSheetLayout);
-#endif
+ m_blockSignals = false;
}
-void QPageSetupWidget::selectPrinter()
+// Set the dialog to use the given QPrinter
+// Usually only called on first creation
+void QPageSetupWidget::setPrinter(QPrinter *printer)
{
- widget.paperSize->clear();
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- if (QCUPSSupport::isAvailable()) {
- m_cups = true;
- QCUPSSupport cups;
- cups.setCurrentPrinter(m_printer->printerName());
- const ppd_option_t* pageSizes = cups.pageSizes();
- const int numChoices = pageSizes ? pageSizes->num_choices : 0;
-
- int cupsDefaultSize = 0;
- QSize qtPreferredSize = m_printer->paperSize(QPrinter::Point).toSize();
- QString qtPaperName = m_printer->paperName();
- bool preferredSizeMatched = false;
- for (int i = 0; i < numChoices; ++i) {
- widget.paperSize->addItem(QString::fromLocal8Bit(pageSizes->choices[i].text), QByteArray(pageSizes->choices[i].choice));
- if (static_cast<int>(pageSizes->choices[i].marked) == 1)
- cupsDefaultSize = i;
- if (qtPaperName == QString::fromLocal8Bit(pageSizes->choices[i].text)) {
- widget.paperSize->setCurrentIndex(i);
- preferredSizeMatched = true;
- } else {
- QRect cupsPaperSize = cups.paperRect(pageSizes->choices[i].choice);
- QSize diff = cupsPaperSize.size() - qtPreferredSize;
- if (qAbs(diff.width()) < 5 && qAbs(diff.height()) < 5) {
- widget.paperSize->setCurrentIndex(i);
- preferredSizeMatched = true;
- }
- }
- }
- 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();
- }
- } else
- m_cups = false;
-#endif
- if (widget.paperSize->count() == 0) {
- populatePaperSizes(widget.paperSize);
- widget.paperSize->setCurrentIndex(widget.paperSize->findData(
- QLocale::system().measurementSystem() == QLocale::ImperialSystem ? QPrinter::Letter : QPrinter::A4));
+ m_printer = printer;
+
+ // Initialize the layout to the current QPrinter layout
+ m_pageLayout = m_printer->pageLayout();
+ // Assume if margins are Points then is by default, so set to locale default units
+ if (m_pageLayout.units() == QPageLayout::Point) {
+ if (QLocale().measurementSystem() == QLocale::MetricSystem)
+ m_pageLayout.setUnits(QPageLayout::Millimeter);
+ else
+ m_pageLayout.setUnits(QPageLayout::Inch);
}
+ m_units = m_pageLayout.units();
+ m_pagePreview->setPageLayout(m_pageLayout);
- unitChanged(widget.unit->currentIndex());
- m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+ // Then update the widget with the current printer details
+ selectPrinter(m_printer->outputFormat(), m_printer->printerName());
}
-void QPageSetupWidget::selectPdfPsPrinter(const QPrinter *p)
+// The printer selected in the QPrintDialog has been changed, update the widget to reflect this
+// Note the QPrinter is not updated at this time in case the user presses the Cancel button in QPrintDialog
+void QPageSetupWidget::selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName)
{
- m_cups = false;
- widget.paperSize->clear();
- populatePaperSizes(widget.paperSize);
- widget.paperSize->setCurrentIndex(widget.paperSize->findData(p->paperSize()));
- unitChanged(widget.unit->currentIndex());
- m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+ m_outputFormat = outputFormat;
+ m_printerName = printerName;
+ initPageSizes();
+ updateWidget();
}
-// Updates size/preview after the combobox has been changed.
-void QPageSetupWidget::_q_paperSizeChanged()
+// Update the widget with the current settings
+// TODO Break up into more intelligent chunks?
+void QPageSetupWidget::updateWidget()
{
- if (m_blockSignals) return;
m_blockSignals = true;
- bool custom = false;
- QVariant val = widget.paperSize->itemData(widget.paperSize->currentIndex());
- QPrinter::Orientation orientation = widget.portrait->isChecked() ? QPrinter::Portrait : QPrinter::Landscape;
-
- if (m_cups) {
- // OutputFormat == NativeFormat, data is QString Cups paper name
- QByteArray cupsPageSize = val.toByteArray();
- custom = (cupsPageSize == QByteArrayLiteral("Custom"));
-#ifndef QT_NO_CUPS
- if (!custom) {
- QCUPSSupport cups;
- cups.setCurrentPrinter(m_printer->printerName());
- m_paperSize = sizeForOrientation(orientation, cups.paperRect(cupsPageSize).size());
- }
-#endif
- } else {
- // OutputFormat == PdfFormat, data is QPrinter::PageSize
- QPrinter::PaperSize size = QPrinter::PaperSize(val.toInt());
- custom = size == QPrinter::Custom;
- if (!custom)
- m_paperSize = qt_printerPaperSize(orientation, size, QPrinter::Point, 1);
+ QString suffix;
+ switch (m_units) {
+ case QPageLayout::Millimeter:
+ //: Unit 'Millimeter'
+ suffix = tr("mm");
+ break;
+ case QPageLayout::Point:
+ //: Unit 'Points'
+ suffix = tr("pt");
+ break;
+ case QPageLayout::Inch:
+ //: Unit 'Inch'
+ suffix = tr("in");
+ break;
+ case QPageLayout::Pica:
+ //: Unit 'Pica'
+ suffix = tr("P̸");
+ break;
+ case QPageLayout::Didot:
+ //: Unit 'Didot'
+ suffix = tr("DD");
+ break;
+ case QPageLayout::Cicero:
+ //: Unit 'Cicero'
+ suffix = tr("CC");
+ break;
}
- if (custom) {
- // Convert input custom size Units to Points
- m_paperSize = QSizeF(widget.paperWidth->value() * m_currentMultiplier,
- widget.paperHeight->value() * m_currentMultiplier);
+ m_ui.unitCombo->setCurrentIndex(m_ui.unitCombo->findData(QVariant::fromValue(m_units)));
+
+ m_ui.pageSizeCombo->setCurrentIndex(m_ui.pageSizeCombo->findData(QVariant::fromValue(m_pageLayout.pageSize().id())));
+
+ QMarginsF min;
+ QMarginsF max;
+
+ if (m_pageLayout.mode() == QPageLayout::FullPageMode) {
+ min = QMarginsF(0.0, 0.0, 0.0, 0.0);
+ max = QMarginsF(9999.9999, 9999.9999, 9999.9999, 9999.9999);
} else {
- // Display standard size Points as Units
- widget.paperWidth->setValue(m_paperSize.width() / m_currentMultiplier);
- widget.paperHeight->setValue(m_paperSize.height() / m_currentMultiplier);
+ min = m_pageLayout.minimumMargins();
+ max = m_pageLayout.maximumMargins();
}
- m_pagePreview->setPaperSize(m_paperSize);
+ m_ui.leftMargin->setSuffix(suffix);
+ m_ui.leftMargin->setMinimum(min.left());
+ m_ui.leftMargin->setMaximum(max.left());
+ m_ui.leftMargin->setValue(m_pageLayout.margins().left());
+
+ m_ui.rightMargin->setSuffix(suffix);
+ m_ui.rightMargin->setMinimum(min.right());
+ m_ui.rightMargin->setMaximum(max.right());
+ m_ui.rightMargin->setValue(m_pageLayout.margins().right());
- widget.paperWidth->setEnabled(custom);
- widget.paperHeight->setEnabled(custom);
- widget.widthLabel->setEnabled(custom);
- widget.heightLabel->setEnabled(custom);
+ m_ui.topMargin->setSuffix(suffix);
+ m_ui.topMargin->setMinimum(min.top());
+ m_ui.topMargin->setMaximum(max.top());
+ m_ui.topMargin->setValue(m_pageLayout.margins().top());
+
+ m_ui.bottomMargin->setSuffix(suffix);
+ m_ui.bottomMargin->setMinimum(min.bottom());
+ m_ui.bottomMargin->setMaximum(max.bottom());
+ m_ui.bottomMargin->setValue(m_pageLayout.margins().bottom());
+
+ bool isCustom = m_ui.pageSizeCombo->currentData().value<QPageSize::PageSizeId>() == QPageSize::Custom;
+
+ m_ui.pageWidth->setSuffix(suffix);
+ m_ui.pageWidth->setValue(m_pageLayout.fullRect(m_units).width());
+ m_ui.pageWidth->setEnabled(isCustom);
+ m_ui.widthLabel->setEnabled(isCustom);
+
+ m_ui.pageHeight->setSuffix(suffix);
+ m_ui.pageHeight->setValue(m_pageLayout.fullRect(m_units).height());
+ m_ui.pageHeight->setEnabled(isCustom);
+ m_ui.heightLabel->setEnabled(isCustom);
+
+ m_ui.landscape->setChecked(m_pageLayout.orientation() == QPageLayout::Landscape);
+
+ m_ui.pagesPerSheetButtonGroup->setEnabled(m_outputFormat == QPrinter::NativeFormat);
+
+#ifdef PSD_ENABLE_PAPERSOURCE
+ m_ui.paperSource->setCurrentItem(printer->paperSource());
+#endif
m_blockSignals = false;
}
-void QPageSetupWidget::_q_pageOrientationChanged()
+// Set the dialog chosen options on the QPrinter
+// Normally only called when the QPrintDialog or QPageSetupDialog OK button is pressed
+void QPageSetupWidget::setupPrinter() const
{
- bool custom = false;
- QVariant val = widget.paperSize->itemData(widget.paperSize->currentIndex());
+ m_printer->setPageLayout(m_pageLayout);
+#if !defined(QT_NO_CUPS)
+ QCUPSSupport::PagesPerSheet pagesPerSheet = m_ui.pagesPerSheetCombo->currentData()
+ .value<QCUPSSupport::PagesPerSheet>();
+ QCUPSSupport::PagesPerSheetLayout pagesPerSheetLayout = m_ui.pagesPerSheetLayoutCombo->currentData()
+ .value<QCUPSSupport::PagesPerSheetLayout>();
+ QCUPSSupport::setPagesPerSheetLayout(m_printer, pagesPerSheet, pagesPerSheetLayout);
+#endif
+#ifdef PSD_ENABLE_PAPERSOURCE
+ m_printer->setPaperSource((QPrinter::PaperSource)m_ui.paperSource->currentIndex());
+#endif
+}
- if (m_cups) {
- // OutputFormat == NativeFormat, data is QString Cups paper name
- QByteArray cupsPageSize = val.toByteArray();
- custom = (cupsPageSize == QByteArrayLiteral("Custom"));
+// Updates size/preview after the combobox has been changed.
+void QPageSetupWidget::pageSizeChanged()
+{
+ if (m_blockSignals)
+ return;
+
+ QPageSize::PageSizeId id = m_ui.pageSizeCombo->currentData().value<QPageSize::PageSizeId>();
+ if (id != QPageSize::Custom) {
+ // TODO Set layout margin min/max to printer custom min/max
+ m_pageLayout.setPageSize(QPageSize(id));
} else {
- // OutputFormat == PdfFormat, data is QPrinter::PageSize
- QPrinter::PaperSize size = QPrinter::PaperSize(val.toInt());
- custom = size == QPrinter::Custom;
+ QSizeF customSize;
+ if (m_pageLayout.orientation() == QPageLayout::Landscape)
+ customSize = QSizeF(m_ui.pageHeight->value(), m_ui.pageWidth->value());
+ else
+ customSize = QSizeF(m_ui.pageWidth->value(), m_ui.pageHeight->value());
+ // TODO Set layout margin min/max to printer min/max for page size
+ m_pageLayout.setPageSize(QPageSize(customSize, QPageSize::Unit(m_units)));
}
+ m_pagePreview->setPageLayout(m_pageLayout);
- if (custom) {
- double tmp = widget.paperWidth->value();
- widget.paperWidth->setValue(widget.paperHeight->value());
- widget.paperHeight->setValue(tmp);
- }
- _q_paperSizeChanged();
+ updateWidget();
}
-void QPageSetupWidget::_q_pagesPerSheetChanged()
+void QPageSetupWidget::pageOrientationChanged()
{
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- QCUPSSupport::PagesPerSheet pagesPerSheet = widget.pagesPerSheetCombo->currentData()
- .value<QCUPSSupport::PagesPerSheet>();
+ if (m_blockSignals)
+ return;
+ m_pageLayout.setOrientation(m_ui.portrait->isChecked() ? QPageLayout::Portrait : QPageLayout::Landscape);
+ m_pagePreview->setPageLayout(m_pageLayout);
+ updateWidget();
+}
- switch (pagesPerSheet) {
+void QPageSetupWidget::pagesPerSheetChanged()
+{
+#if !defined(QT_NO_CUPS)
+ switch (m_ui.pagesPerSheetCombo->currentData().toInt()) {
+ case QCUPSSupport::OnePagePerSheet:
+ m_pagePreview->setPagePreviewLayout(1, 1);
+ break;
case QCUPSSupport::TwoPagesPerSheet:
m_pagePreview->setPagePreviewLayout(1, 2);
break;
@@ -563,84 +567,53 @@ void QPageSetupWidget::_q_pagesPerSheetChanged()
case QCUPSSupport::SixteenPagesPerSheet:
m_pagePreview->setPagePreviewLayout(4, 4);
break;
- case QCUPSSupport::OnePagePerSheet:
- default:
- m_pagePreview->setPagePreviewLayout(1, 1);
- break;
}
#endif
}
-extern double qt_multiplierForUnit(QPrinter::Unit unit, int resolution);
-
-void QPageSetupWidget::unitChanged(int item)
+void QPageSetupWidget::unitChanged()
{
- QString suffix;
- switch(item) {
- case 0:
- m_currentMultiplier = 10 * qt_multiplierForUnit(QPrinter::Millimeter, 1);
- suffix = QString::fromLatin1(" cm");
- break;
- case 2:
- m_currentMultiplier = qt_multiplierForUnit(QPrinter::Inch, 1);
- suffix = QString::fromLatin1(" in");
- break;
- case 3:
- m_currentMultiplier = qt_multiplierForUnit(QPrinter::Point, 1);
- suffix = QString::fromLatin1(" pt");
- break;
- case 1:
- default:
- m_currentMultiplier = qt_multiplierForUnit(QPrinter::Millimeter, 1);
- suffix = QString::fromLatin1(" mm");
- break;
- }
- const bool old = m_blockSignals;
- m_blockSignals = true;
- widget.topMargin->setSuffix(suffix);
- widget.leftMargin->setSuffix(suffix);
- widget.rightMargin->setSuffix(suffix);
- widget.bottomMargin->setSuffix(suffix);
- widget.paperWidth->setSuffix(suffix);
- widget.paperHeight->setSuffix(suffix);
- widget.topMargin->setValue(m_topMargin / m_currentMultiplier);
- widget.leftMargin->setValue(m_leftMargin / m_currentMultiplier);
- widget.rightMargin->setValue(m_rightMargin / m_currentMultiplier);
- widget.bottomMargin->setValue(m_bottomMargin / m_currentMultiplier);
- widget.paperWidth->setValue(m_paperSize.width() / m_currentMultiplier);
- widget.paperHeight->setValue(m_paperSize.height() / m_currentMultiplier);
- m_blockSignals = old;
+ if (m_blockSignals)
+ return;
+ m_units = m_ui.unitCombo->currentData().value<QPageLayout::Unit>();
+ m_pageLayout.setUnits(m_units);
+ updateWidget();
}
-void QPageSetupWidget::setTopMargin(double newValue)
+void QPageSetupWidget::topMarginChanged(double newValue)
{
- if (m_blockSignals) return;
- m_topMargin = newValue * m_currentMultiplier;
- m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+ if (m_blockSignals)
+ return;
+ m_pageLayout.setTopMargin(newValue);
+ m_pagePreview->setPageLayout(m_pageLayout);
}
-void QPageSetupWidget::setBottomMargin(double newValue)
+void QPageSetupWidget::bottomMarginChanged(double newValue)
{
- if (m_blockSignals) return;
- m_bottomMargin = newValue * m_currentMultiplier;
- m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+ if (m_blockSignals)
+ return;
+ m_pageLayout.setBottomMargin(newValue);
+ m_pagePreview->setPageLayout(m_pageLayout);
}
-void QPageSetupWidget::setLeftMargin(double newValue)
+void QPageSetupWidget::leftMarginChanged(double newValue)
{
- if (m_blockSignals) return;
- m_leftMargin = newValue * m_currentMultiplier;
- m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+ if (m_blockSignals)
+ return;
+ m_pageLayout.setLeftMargin(newValue);
+ m_pagePreview->setPageLayout(m_pageLayout);
}
-void QPageSetupWidget::setRightMargin(double newValue)
+void QPageSetupWidget::rightMarginChanged(double newValue)
{
- if (m_blockSignals) return;
- m_rightMargin = newValue * m_currentMultiplier;
- m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+ if (m_blockSignals)
+ return;
+ m_pageLayout.setRightMargin(newValue);
+ m_pagePreview->setPageLayout(m_pageLayout);
}
-
+// QPageSetupDialog
+// - Public Linux / CUPS class implementation
QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
: QDialog(*(new QUnixPageSetupDialogPrivate(printer)), parent)
@@ -650,7 +623,6 @@ QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
static_cast<QUnixPageSetupDialogPrivate *>(d)->init();
}
-
QPageSetupDialog::QPageSetupDialog(QWidget *parent)
: QDialog(*(new QUnixPageSetupDialogPrivate(0)), parent)
{
@@ -669,35 +641,6 @@ int QPageSetupDialog::exec()
return ret;
}
-void QPageSetupWidget::initPagesPerSheet()
-{
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- widget.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Left to Right, Top to Bottom"), QVariant::fromValue(QCUPSSupport::LeftToRightTopToBottom));
- widget.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Left to Right, Bottom to Top"), QVariant::fromValue(QCUPSSupport::LeftToRightBottomToTop));
- widget.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Right to Left, Bottom to Top"), QVariant::fromValue(QCUPSSupport::RightToLeftBottomToTop));
- widget.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Right to Left, Top to Bottom"), QVariant::fromValue(QCUPSSupport::RightToLeftTopToBottom));
- widget.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Bottom to Top, Left to Right"), QVariant::fromValue(QCUPSSupport::BottomToTopLeftToRight));
- widget.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Bottom to Top, Right to Left"), QVariant::fromValue(QCUPSSupport::BottomToTopRightToLeft));
- widget.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Top to Bottom, Left to Right"), QVariant::fromValue(QCUPSSupport::TopToBottomLeftToRight));
- widget.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Top to Bottom, Right to Left"), QVariant::fromValue(QCUPSSupport::TopToBottomRightToLeft));
-
- widget.pagesPerSheetCombo->addItem(QPrintDialog::tr("1 (1x1)"), QVariant::fromValue(QCUPSSupport::OnePagePerSheet));
- widget.pagesPerSheetCombo->addItem(QPrintDialog::tr("2 (2x1)"), QVariant::fromValue(QCUPSSupport::TwoPagesPerSheet));
- widget.pagesPerSheetCombo->addItem(QPrintDialog::tr("4 (2x2)"), QVariant::fromValue(QCUPSSupport::FourPagesPerSheet));
- widget.pagesPerSheetCombo->addItem(QPrintDialog::tr("6 (2x3)"), QVariant::fromValue(QCUPSSupport::SixPagesPerSheet));
- widget.pagesPerSheetCombo->addItem(QPrintDialog::tr("9 (3x3)"), QVariant::fromValue(QCUPSSupport::NinePagesPerSheet));
- widget.pagesPerSheetCombo->addItem(QPrintDialog::tr("16 (4x4)"), QVariant::fromValue(QCUPSSupport::SixteenPagesPerSheet));
-
- // Set the combo to "1 (1x1)" -- QCUPSSupport::OnePagePerSheet
- widget.pagesPerSheetCombo->setCurrentIndex(0);
- // Set the layout combo to QCUPSSupport::LeftToRightTopToBottom
- widget.pagesPerSheetLayoutCombo->setCurrentIndex(0);
-#else
- // Disable if CUPS wasn't found
- widget.pagesPerSheetButtonGroup->hide();
-#endif
-}
-
QT_END_NAMESPACE
#include "moc_qpagesetupdialog.cpp"
diff --git a/src/printsupport/dialogs/qpagesetupdialog_unix_p.h b/src/printsupport/dialogs/qpagesetupdialog_unix_p.h
index 4245c3ae5f..2a359a8118 100644
--- a/src/printsupport/dialogs/qpagesetupdialog_unix_p.h
+++ b/src/printsupport/dialogs/qpagesetupdialog_unix_p.h
@@ -57,6 +57,10 @@
#ifndef QT_NO_PRINTDIALOG
+#include "qprinter.h"
+
+#include <QtGui/qpagelayout.h>
+
#include <ui_qpagesetupwidget.h>
QT_BEGIN_NAMESPACE
@@ -69,37 +73,37 @@ class QPageSetupWidget : public QWidget {
public:
explicit QPageSetupWidget(QWidget *parent = 0);
explicit QPageSetupWidget(QPrinter *printer, QWidget *parent = 0);
+
void setPrinter(QPrinter *printer);
- /// copy information from the widget and apply that to the printer.
+ void selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName);
void setupPrinter() const;
- void selectPrinter();
- void selectPdfPsPrinter(const QPrinter *p);
private slots:
- void _q_pageOrientationChanged();
- void _q_paperSizeChanged();
- void _q_pagesPerSheetChanged();
- void unitChanged(int item);
- void setTopMargin(double newValue);
- void setBottomMargin(double newValue);
- void setLeftMargin(double newValue);
- void setRightMargin(double newValue);
+ void pageSizeChanged();
+ void pageOrientationChanged();
+ void pagesPerSheetChanged();
+ void unitChanged();
+ void topMarginChanged(double newValue);
+ void bottomMarginChanged(double newValue);
+ void leftMarginChanged(double newValue);
+ void rightMarginChanged(double newValue);
private:
- friend class QUnixPrintWidgetPrivate;
- Ui::QPageSetupWidget widget;
+ friend class QUnixPrintWidgetPrivate; // Needed by checkFields()
+
+ void updateWidget();
+ void initUnits();
+ void initPagesPerSheet();
+ void initPageSizes();
+
+ Ui::QPageSetupWidget m_ui;
QPagePreview *m_pagePreview;
QPrinter *m_printer;
- qreal m_leftMargin;
- qreal m_topMargin;
- qreal m_rightMargin;
- qreal m_bottomMargin;
- QSizeF m_paperSize; // In QPrinter::Point
- qreal m_currentMultiplier;
+ QPrinter::OutputFormat m_outputFormat;
+ QString m_printerName;
+ QPageLayout m_pageLayout;
+ QPageLayout::Unit m_units;
bool m_blockSignals;
- bool m_cups;
-
- void initPagesPerSheet();
};
QT_END_NAMESPACE
diff --git a/src/printsupport/dialogs/qpagesetupdialog_win.cpp b/src/printsupport/dialogs/qpagesetupdialog_win.cpp
index 345e698b82..5da87cce18 100644
--- a/src/printsupport/dialogs/qpagesetupdialog_win.cpp
+++ b/src/printsupport/dialogs/qpagesetupdialog_win.cpp
@@ -106,42 +106,40 @@ int QPageSetupDialog::exec()
psd.hwndOwner = parentWindow ? (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow) : 0;
psd.Flags = PSD_MARGINS;
- double multiplier = 1;
- switch (QLocale::system().measurementSystem()) {
- case QLocale::MetricSystem:
- psd.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
- multiplier = 1;
+ QPageLayout layout = d->printer->pageLayout();
+ switch (layout.units()) {
+ case QPageLayout::Millimeter:
+ case QPageLayout::Inch:
break;
- case QLocale::ImperialSystem:
- case QLocale::ImperialUKSystem:
- psd.Flags |= PSD_INTHOUSANDTHSOFINCHES;
- multiplier = 25.4/10;
+ case QPageLayout::Point:
+ case QPageLayout::Pica:
+ case QPageLayout::Didot:
+ case QPageLayout::Cicero:
+ layout.setUnits(QLocale::system().measurementSystem() == QLocale::MetricSystem ? QPageLayout::Millimeter
+ : QPageLayout::Inch);
break;
}
-
- QRect marginRect = ep->getPageMargins();
- psd.rtMargin.left = marginRect.left() / multiplier;
- psd.rtMargin.top = marginRect.top() / multiplier;
- psd.rtMargin.right = marginRect.width() / multiplier;;
- psd.rtMargin.bottom = marginRect.height() / multiplier;;
+ qreal multiplier = 1.0;
+ if (layout.units() == QPageLayout::Millimeter) {
+ psd.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
+ multiplier = 100.0;
+ } else { // QPageLayout::Inch)
+ psd.Flags |= PSD_INTHOUSANDTHSOFINCHES;
+ multiplier = 1000.0;
+ }
+ psd.rtMargin.left = layout.margins().left() * multiplier;
+ psd.rtMargin.top = layout.margins().top() * multiplier;
+ psd.rtMargin.right = layout.margins().right() * multiplier;
+ psd.rtMargin.bottom = layout.margins().bottom() * multiplier;
QDialog::setVisible(true);
bool result = PageSetupDlg(&psd);
QDialog::setVisible(false);
if (result) {
engine->setGlobalDevMode(psd.hDevNames, psd.hDevMode);
-
- QRect theseMargins = QRect(psd.rtMargin.left * multiplier,
- psd.rtMargin.top * multiplier,
- psd.rtMargin.right * multiplier,
- psd.rtMargin.bottom * multiplier);
-
- if (theseMargins != marginRect) {
- ep->setPageMargins(psd.rtMargin.left * multiplier,
- psd.rtMargin.top * multiplier,
- psd.rtMargin.right * multiplier,
- psd.rtMargin.bottom * multiplier);
- }
+ d->printer->setPageMargins(QMarginsF(psd.rtMargin.left / multiplier, psd.rtMargin.right / multiplier,
+ psd.rtMargin.top / multiplier, psd.rtMargin.bottom / multiplier),
+ layout.units());
// copy from our temp DEVMODE struct
if (!engine->globalDevMode() && hDevMode) {
diff --git a/src/printsupport/dialogs/qpagesetupwidget.ui b/src/printsupport/dialogs/qpagesetupwidget.ui
index ffd2650f4c..960a9dac17 100644
--- a/src/printsupport/dialogs/qpagesetupwidget.ui
+++ b/src/printsupport/dialogs/qpagesetupwidget.ui
@@ -28,12 +28,12 @@
<string>Page size:</string>
</property>
<property name="buddy">
- <cstring>paperSize</cstring>
+ <cstring>pageSizeCombo</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
- <widget class="QComboBox" name="paperSize" />
+ <widget class="QComboBox" name="pageSizeCombo" />
</item>
<item row="1" column="0" >
<widget class="QLabel" name="widthLabel" >
@@ -41,14 +41,14 @@
<string>Width:</string>
</property>
<property name="buddy" >
- <cstring>paperWidth</cstring>
+ <cstring>pageWidth</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<layout class="QHBoxLayout" name="horizontalLayout_3" >
<item>
- <widget class="QDoubleSpinBox" name="paperWidth" >
+ <widget class="QDoubleSpinBox" name="pageWidth" >
<property name="maximum" >
<double>9999.989999999999782</double>
</property>
@@ -60,12 +60,12 @@
<string>Height:</string>
</property>
<property name="buddy" >
- <cstring>paperHeight</cstring>
+ <cstring>pageHeight</cstring>
</property>
</widget>
</item>
<item>
- <widget class="QDoubleSpinBox" name="paperHeight" >
+ <widget class="QDoubleSpinBox" name="pageHeight" >
<property name="maximum" >
<double>9999.989999999999782</double>
</property>
@@ -105,7 +105,7 @@
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
- <widget class="QComboBox" name="unit"/>
+ <widget class="QComboBox" name="unitCombo"/>
</item>
<item>
<spacer name="horizontalSpacer_3">
diff --git a/src/printsupport/dialogs/qprintdialog_mac.mm b/src/printsupport/dialogs/qprintdialog_mac.mm
index bf1617065b..9ff7c4766a 100644
--- a/src/printsupport/dialogs/qprintdialog_mac.mm
+++ b/src/printsupport/dialogs/qprintdialog_mac.mm
@@ -49,11 +49,14 @@
#include <QtWidgets/private/qapplication_p.h>
#include <QtPrintSupport/qprinter.h>
#include <QtPrintSupport/qprintengine.h>
+#include <qpa/qplatformprintdevice.h>
#ifndef QT_NO_PRINTDIALOG
QT_BEGIN_NAMESPACE
+extern qreal qt_pointMultiplier(QPageLayout::Unit unit);
+
class QPrintDialogPrivate : public QAbstractPrintDialogPrivate
{
Q_DECLARE_PUBLIC(QPrintDialog)
@@ -148,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
diff --git a/src/printsupport/dialogs/qprintdialog_unix.cpp b/src/printsupport/dialogs/qprintdialog_unix.cpp
index 2ec1088bb4..ab31db76aa 100644
--- a/src/printsupport/dialogs/qprintdialog_unix.cpp
+++ b/src/printsupport/dialogs/qprintdialog_unix.cpp
@@ -52,8 +52,11 @@
#include <QtWidgets/qfilesystemmodel.h>
#include <QtWidgets/qstyleditemdelegate.h>
#include <QtPrintSupport/qprinter.h>
-#include <QtPrintSupport/qprinterinfo.h>
-#include <private/qprintengine_pdf_p.h>
+
+#include <qpa/qplatformprintplugin.h>
+#include <qpa/qplatformprintersupport.h>
+
+#include <private/qprintdevice_p.h>
#include <QtWidgets/qdialogbuttonbox.h>
@@ -62,12 +65,9 @@
#include "ui_qprintsettingsoutput.h"
#include "ui_qprintwidget.h"
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
-# include <private/qcups_p.h>
-# include "qcupsjobwidget_p.h"
-#else
-# include <QtCore/qlibrary.h>
-# include <private/qprintengine_pdf_p.h>
+#ifndef QT_NO_CUPS
+#include <private/qcups_p.h>
+#include "qcupsjobwidget_p.h"
#endif
/*
@@ -120,8 +120,7 @@ public:
QPrintPropertiesDialog(QAbstractPrintDialog *parent = 0);
~QPrintPropertiesDialog();
- void selectPrinter();
- void selectPdfPsPrinter(const QPrinter *p);
+ void selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName);
/// copy printer properties to the widget
void applyPrinterProperties(QPrinter *p);
@@ -134,7 +133,7 @@ private:
friend class QUnixPrintWidgetPrivate;
Ui::QPrintPropertiesWidget widget;
QDialogButtonBox *m_buttons;
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+#ifndef QT_NO_CUPS
QCupsJobWidget *m_jobOptions;
#endif
};
@@ -181,6 +180,8 @@ public:
Ui::QPrintWidget widget;
QAbstractPrintDialog * q;
QPrinter *printer;
+ QPrintDevice m_currentPrintDevice;
+
void updateWidget();
private:
@@ -249,11 +250,9 @@ QPrintPropertiesDialog::QPrintPropertiesDialog(QAbstractPrintDialog *parent)
connect(m_buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept()));
connect(m_buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- if (QCUPSSupport::isAvailable()) {
- m_jobOptions = new QCupsJobWidget();
- widget.tabs->addTab(m_jobOptions, tr("Job Options"));
- }
+#ifndef QT_NO_CUPS
+ m_jobOptions = new QCupsJobWidget();
+ widget.tabs->addTab(m_jobOptions, tr("Job Options"));
#endif
}
@@ -264,31 +263,22 @@ QPrintPropertiesDialog::~QPrintPropertiesDialog()
void QPrintPropertiesDialog::applyPrinterProperties(QPrinter *p)
{
widget.pageSetup->setPrinter(p);
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- if (QCUPSSupport::isAvailable()) {
- m_jobOptions->setPrinter(p);
- }
+#ifndef QT_NO_CUPS
+ m_jobOptions->setPrinter(p);
#endif
}
void QPrintPropertiesDialog::setupPrinter() const
{
widget.pageSetup->setupPrinter();
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- if (QCUPSSupport::isAvailable()) {
- m_jobOptions->setupPrinter();
- }
+#ifndef QT_NO_CUPS
+ m_jobOptions->setupPrinter();
#endif
}
-void QPrintPropertiesDialog::selectPrinter()
+void QPrintPropertiesDialog::selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName)
{
- widget.pageSetup->selectPrinter();
-}
-
-void QPrintPropertiesDialog::selectPdfPsPrinter(const QPrinter *p)
-{
- widget.pageSetup->selectPdfPsPrinter(p);
+ widget.pageSetup->selectPrinter(outputFormat, printerName);
}
void QPrintPropertiesDialog::showEvent(QShowEvent* event)
@@ -329,13 +319,11 @@ void QPrintDialogPrivate::init()
options.grayscale->setIconSize(QSize(32, 32));
options.grayscale->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-gray-scale.png")));
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+#ifndef QT_NO_CUPS
// Add Page Set widget if CUPS is available
- if (QCUPSSupport::isAvailable()) {
- options.pageSetCombo->addItem(tr("All Pages"), QVariant::fromValue(QCUPSSupport::AllPages));
- options.pageSetCombo->addItem(tr("Odd Pages"), QVariant::fromValue(QCUPSSupport::OddPages));
- options.pageSetCombo->addItem(tr("Even Pages"), QVariant::fromValue(QCUPSSupport::EvenPages));
- }
+ options.pageSetCombo->addItem(tr("All Pages"), QVariant::fromValue(QCUPSSupport::AllPages));
+ options.pageSetCombo->addItem(tr("Odd Pages"), QVariant::fromValue(QCUPSSupport::OddPages));
+ options.pageSetCombo->addItem(tr("Even Pages"), QVariant::fromValue(QCUPSSupport::EvenPages));
#endif
top->d->setOptionsPane(this);
@@ -453,24 +441,27 @@ void QPrintDialogPrivate::setupPrinter()
}
}
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+#ifndef QT_NO_CUPS
// page set
- if (QCUPSSupport::isAvailable()) {
- if (p->printRange() == QPrinter::AllPages || p->printRange() == QPrinter::PageRange) {
- //If the application is selecting pages and the first page number is even then need to adjust the odd-even accordingly
- QCUPSSupport::PageSet pageSet = options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()).value<QCUPSSupport::PageSet>();
- if (q->isOptionEnabled(QPrintDialog::PrintPageRange)
- && p->printRange() == QPrinter::PageRange
- && (q->fromPage() % 2 == 0)) {
-
- if (pageSet == QCUPSSupport::OddPages)
- QCUPSSupport::setPageSet(p, QCUPSSupport::EvenPages);
- else if (pageSet == QCUPSSupport::EvenPages)
- QCUPSSupport::setPageSet(p, QCUPSSupport::OddPages);
- } else if (pageSet != QCUPSSupport::AllPages) {
- QCUPSSupport::setPageSet(p, pageSet);
+ if (p->printRange() == QPrinter::AllPages || p->printRange() == QPrinter::PageRange) {
+ //If the application is selecting pages and the first page number is even then need to adjust the odd-even accordingly
+ QCUPSSupport::PageSet pageSet = options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()).value<QCUPSSupport::PageSet>();
+ if (q->isOptionEnabled(QPrintDialog::PrintPageRange)
+ && p->printRange() == QPrinter::PageRange
+ && (q->fromPage() % 2 == 0)) {
+
+ switch (pageSet) {
+ case QCUPSSupport::AllPages:
+ break;
+ case QCUPSSupport::OddPages:
+ QCUPSSupport::setPageSet(p, QCUPSSupport::EvenPages);
+ break;
+ case QCUPSSupport::EvenPages:
+ QCUPSSupport::setPageSet(p, QCUPSSupport::OddPages);
+ break;
}
-
+ } else if (pageSet != QCUPSSupport::AllPages) {
+ QCUPSSupport::setPageSet(p, pageSet);
}
// server-side page range, since we set the page range on the printer to 0-0/AllPages above,
@@ -533,26 +524,22 @@ void QPrintDialogPrivate::updateWidgets()
options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage));
options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies));
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
- if (QCUPSSupport::isAvailable()) {
- // Don't display Page Set if only Selection or Current Page are enabled
- if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) && (
- q->isOptionEnabled(QPrintDialog::PrintSelection) ||
- q->isOptionEnabled(QPrintDialog::PrintCurrentPage))) {
-
- options.pageSetCombo->setVisible(false);
- options.pageSetLabel->setVisible(false);
- } else {
- options.pageSetCombo->setVisible(true);
- options.pageSetLabel->setVisible(true);
- }
+#ifndef QT_NO_CUPS
+ // Don't display Page Set if only Selection or Current Page are enabled
+ if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)
+ && (q->isOptionEnabled(QPrintDialog::PrintSelection) || q->isOptionEnabled(QPrintDialog::PrintCurrentPage))) {
+ options.pageSetCombo->setVisible(false);
+ options.pageSetLabel->setVisible(false);
+ } else {
+ options.pageSetCombo->setVisible(true);
+ options.pageSetLabel->setVisible(true);
+ }
- if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)) {
- // If we can do CUPS server side pages selection,
- // display the page range widgets
- options.gbPrintRange->setVisible(true);
- options.printRange->setEnabled(true);
- }
+ if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)) {
+ // If we can do CUPS server side pages selection,
+ // display the page range widgets
+ options.gbPrintRange->setVisible(true);
+ options.printRange->setEnabled(true);
}
#endif
@@ -681,12 +668,17 @@ QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p, QPrinter *
widget.setupUi(parent);
int currentPrinterIndex = 0;
- QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
+ QStringList printers;
+ QString defaultPrinter;
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps) {
+ printers = ps->availablePrintDeviceIds();
+ defaultPrinter = ps->defaultPrintDeviceId();
+ }
for (int i = 0; i < printers.size(); ++i) {
- QPrinterInfo pInfo = printers.at(i);
- widget.printers->addItem(pInfo.printerName());
- if (pInfo.isDefault())
+ widget.printers->addItem(printers.at(i));
+ if (printers.at(i) == defaultPrinter)
currentPrinterIndex = i;
}
widget.properties->setEnabled(true);
@@ -775,12 +767,14 @@ void QUnixPrintWidgetPrivate::_q_printerChanged(int index)
}
if (printer) {
- QString printerName = widget.printers->itemText(index);
- printer->setPrinterName(printerName);
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps)
+ m_currentPrintDevice = ps->createPrintDevice(widget.printers->itemText(index));
+
+ printer->setPrinterName(m_currentPrintDevice.id());
- QPrinterInfo printerInfo = QPrinterInfo::printerInfo(printer->printerName());
- widget.location->setText(printerInfo.location());
- widget.type->setText(printerInfo.makeAndModel());
+ widget.location->setText(m_currentPrintDevice.location());
+ widget.type->setText(m_currentPrintDevice.makeAndModel());
if (optionsPane)
optionsPane->selectPrinter(QPrinter::NativeFormat);
}
@@ -847,7 +841,7 @@ void QUnixPrintWidgetPrivate::applyPrinterProperties()
}
}
}
- // PDF and PS printers are not added to the dialog yet, we'll handle those cases in QUnixPrintWidgetPrivate::updateWidget
+ // PDF printer not added to the dialog yet, we'll handle those cases in QUnixPrintWidgetPrivate::updateWidget
if (propertiesDialog)
propertiesDialog->applyPrinterProperties(printer);
@@ -884,9 +878,10 @@ bool QUnixPrintWidgetPrivate::checkFields()
}
}
-#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+#ifndef QT_NO_CUPS
if (propertiesDialogShown) {
- QCUPSSupport::PagesPerSheet pagesPerSheet = propertiesDialog->widget.pageSetup->widget.pagesPerSheetCombo->currentData().value<QCUPSSupport::PagesPerSheet>();
+ QCUPSSupport::PagesPerSheet pagesPerSheet = propertiesDialog->widget.pageSetup->m_ui.pagesPerSheetCombo
+ ->currentData().value<QCUPSSupport::PagesPerSheet>();
QCUPSSupport::PageSet pageSet = optionsPane->options.pageSetCombo->currentData().value<QCUPSSupport::PageSet>();
@@ -918,10 +913,10 @@ void QUnixPrintWidgetPrivate::setupPrinterProperties()
if (q->isOptionEnabled(QPrintDialog::PrintToFile)
&& (widget.printers->currentIndex() == widget.printers->count() - 1)) {// PDF
- propertiesDialog->selectPdfPsPrinter(q->printer());
+ propertiesDialog->selectPrinter(QPrinter::PdfFormat, QString());
}
else
- propertiesDialog->selectPrinter();
+ propertiesDialog->selectPrinter(QPrinter::NativeFormat, widget.printers->currentText());
}
void QUnixPrintWidgetPrivate::_q_btnPropertiesClicked()