summaryrefslogtreecommitdiffstats
path: root/src/printsupport
diff options
context:
space:
mode:
Diffstat (limited to 'src/printsupport')
-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
-rw-r--r--src/printsupport/kernel/kernel.pri5
-rw-r--r--src/printsupport/kernel/qcups.cpp481
-rw-r--r--src/printsupport/kernel/qcups_p.h68
-rw-r--r--src/printsupport/kernel/qpaintengine_alpha.cpp1
-rw-r--r--src/printsupport/kernel/qplatformprintdevice.cpp393
-rw-r--r--src/printsupport/kernel/qplatformprintdevice.h182
-rw-r--r--src/printsupport/kernel/qplatformprintersupport.cpp85
-rw-r--r--src/printsupport/kernel/qplatformprintersupport.h26
-rw-r--r--src/printsupport/kernel/qprint_p.h304
-rw-r--r--src/printsupport/kernel/qprintdevice.cpp255
-rw-r--r--src/printsupport/kernel/qprintdevice_p.h149
-rw-r--r--src/printsupport/kernel/qprintengine.h5
-rw-r--r--src/printsupport/kernel/qprintengine_pdf.cpp164
-rw-r--r--src/printsupport/kernel/qprintengine_pdf_p.h18
-rw-r--r--src/printsupport/kernel/qprintengine_win.cpp993
-rw-r--r--src/printsupport/kernel/qprintengine_win_p.h60
-rw-r--r--src/printsupport/kernel/qprinter.cpp713
-rw-r--r--src/printsupport/kernel/qprinter.h167
-rw-r--r--src/printsupport/kernel/qprinter_p.h5
-rw-r--r--src/printsupport/kernel/qprinterinfo.cpp255
-rw-r--r--src/printsupport/kernel/qprinterinfo.h27
-rw-r--r--src/printsupport/kernel/qprinterinfo_p.h23
-rw-r--r--src/printsupport/widgets/qcupsjobwidget.cpp4
-rw-r--r--src/printsupport/widgets/qcupsjobwidget_p.h4
30 files changed, 3097 insertions, 2316 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()
diff --git a/src/printsupport/kernel/kernel.pri b/src/printsupport/kernel/kernel.pri
index 67fcc8597c..cbbb14342a 100644
--- a/src/printsupport/kernel/kernel.pri
+++ b/src/printsupport/kernel/kernel.pri
@@ -1,11 +1,14 @@
HEADERS += \
$$PWD/qpaintengine_alpha_p.h \
$$PWD/qpaintengine_preview_p.h \
+ $$PWD/qprint_p.h \
+ $$PWD/qprintdevice_p.h \
$$PWD/qprintengine.h \
$$PWD/qprinter.h \
$$PWD/qprinter_p.h \
$$PWD/qprinterinfo.h \
$$PWD/qprinterinfo_p.h \
+ $$PWD/qplatformprintdevice.h \
$$PWD/qplatformprintplugin.h \
$$PWD/qplatformprintersupport.h \
$$PWD/qtprintsupportglobal.h
@@ -13,9 +16,11 @@ HEADERS += \
SOURCES += \
$$PWD/qpaintengine_alpha.cpp \
$$PWD/qpaintengine_preview.cpp \
+ $$PWD/qprintdevice.cpp \
$$PWD/qprintengine_pdf.cpp \
$$PWD/qprinter.cpp \
$$PWD/qprinterinfo.cpp \
+ $$PWD/qplatformprintdevice.cpp \
$$PWD/qplatformprintplugin.cpp \
$$PWD/qplatformprintersupport.cpp
diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp
index e237d44dcd..a1c657eda4 100644
--- a/src/printsupport/kernel/qcups.cpp
+++ b/src/printsupport/kernel/qcups.cpp
@@ -41,322 +41,12 @@
#include "qcups_p.h"
-#include <qdebug.h>
+#include "qprintengine.h"
#ifndef QT_NO_CUPS
-#ifndef QT_LINUXBASE // LSB merges everything into cups.h
-# include <cups/language.h>
-#endif
-#include <qtextcodec.h>
-
-#include <algorithm>
-
QT_BEGIN_NAMESPACE
-extern double qt_multiplierForUnit(QPrinter::Unit unit, int resolution);
-
-typedef int (*CupsGetDests)(cups_dest_t **dests);
-typedef void (*CupsFreeDests)(int num_dests, cups_dest_t *dests);
-typedef const char* (*CupsGetPPD)(const char *printer);
-typedef int (*CupsMarkOptions)(ppd_file_t *ppd, int num_options, cups_option_t *options);
-typedef ppd_file_t* (*PPDOpenFile)(const char *filename);
-typedef void (*PPDMarkDefaults)(ppd_file_t *ppd);
-typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option);
-typedef void (*PPDClose)(ppd_file_t *ppd);
-typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option);
-typedef void (*CupsFreeOptions)(int num_options, cups_option_t *options);
-typedef void (*CupsSetDests)(int num_dests, cups_dest_t *dests);
-typedef cups_lang_t* (*CupsLangGet)(const char *language);
-typedef const char* (*CupsLangEncoding)(cups_lang_t *language);
-typedef int (*CupsAddOption)(const char *name, const char *value, int num_options, cups_option_t **options);
-typedef int (*CupsTempFd)(char *name, int len);
-typedef int (*CupsPrintFile)(const char * name, const char * filename, const char * title, int num_options, cups_option_t * options);
-
-static bool cupsLoaded = false;
-static int qt_cups_num_printers = 0;
-static CupsGetDests _cupsGetDests = 0;
-static CupsFreeDests _cupsFreeDests = 0;
-static CupsGetPPD _cupsGetPPD = 0;
-static PPDOpenFile _ppdOpenFile = 0;
-static PPDMarkDefaults _ppdMarkDefaults = 0;
-static PPDClose _ppdClose = 0;
-static CupsMarkOptions _cupsMarkOptions = 0;
-static PPDMarkOption _ppdMarkOption = 0;
-static CupsFreeOptions _cupsFreeOptions = 0;
-static CupsSetDests _cupsSetDests = 0;
-static CupsLangGet _cupsLangGet = 0;
-static CupsLangEncoding _cupsLangEncoding = 0;
-static CupsAddOption _cupsAddOption = 0;
-static CupsTempFd _cupsTempFd = 0;
-static CupsPrintFile _cupsPrintFile = 0;
-
-static void resolveCups()
-{
- QLibrary cupsLib(QLatin1String("cups"), 2);
- if(cupsLib.load()) {
- _cupsGetDests = (CupsGetDests) cupsLib.resolve("cupsGetDests");
- _cupsFreeDests = (CupsFreeDests) cupsLib.resolve("cupsFreeDests");
- _cupsGetPPD = (CupsGetPPD) cupsLib.resolve("cupsGetPPD");
- _cupsLangGet = (CupsLangGet) cupsLib.resolve("cupsLangGet");
- _cupsLangEncoding = (CupsLangEncoding) cupsLib.resolve("cupsLangEncoding");
- _ppdOpenFile = (PPDOpenFile) cupsLib.resolve("ppdOpenFile");
- _ppdMarkDefaults = (PPDMarkDefaults) cupsLib.resolve("ppdMarkDefaults");
- _ppdClose = (PPDClose) cupsLib.resolve("ppdClose");
- _cupsMarkOptions = (CupsMarkOptions) cupsLib.resolve("cupsMarkOptions");
- _ppdMarkOption = (PPDMarkOption) cupsLib.resolve("ppdMarkOption");
- _cupsFreeOptions = (CupsFreeOptions) cupsLib.resolve("cupsFreeOptions");
- _cupsSetDests = (CupsSetDests) cupsLib.resolve("cupsSetDests");
- _cupsAddOption = (CupsAddOption) cupsLib.resolve("cupsAddOption");
- _cupsTempFd = (CupsTempFd) cupsLib.resolve("cupsTempFd");
- _cupsPrintFile = (CupsPrintFile) cupsLib.resolve("cupsPrintFile");
-
- if (_cupsGetDests && _cupsFreeDests) {
- cups_dest_t *printers;
- int num_printers = _cupsGetDests(&printers);
- if (num_printers)
- _cupsFreeDests(num_printers, printers);
- qt_cups_num_printers = num_printers;
- }
- }
- cupsLoaded = true;
-}
-
-// ================ CUPS Support class ========================
-
-QCUPSSupport::QCUPSSupport()
- :
- prnCount(0),
- printers(0),
- page_sizes(0),
- currPrinterIndex(0),
- currPPD(0)
-{
- if (!cupsLoaded)
- resolveCups();
-
- // getting all available printers
- if (!isAvailable())
- return;
-
- qt_cups_num_printers = prnCount = _cupsGetDests(&printers);
-
- for (int i = 0; i < prnCount; ++i) {
- if (printers[i].is_default) {
- currPrinterIndex = i;
- break;
- }
- }
-
- if (prnCount > 0)
- setCurrentPrinter(currPrinterIndex);
-
-#ifndef QT_NO_TEXTCODEC
- cups_lang_t *cupsLang = _cupsLangGet(0);
- codec = QTextCodec::codecForName(_cupsLangEncoding(cupsLang));
- if (!codec)
- codec = QTextCodec::codecForLocale();
-#endif
-}
-
-QCUPSSupport::~QCUPSSupport()
-{
- if (currPPD)
- _ppdClose(currPPD);
- if (prnCount)
- _cupsFreeDests(prnCount, printers);
-}
-
-int QCUPSSupport::availablePrintersCount() const
-{
- return prnCount;
-}
-
-const cups_dest_t* QCUPSSupport::availablePrinters() const
-{
- return printers;
-}
-
-const ppd_file_t* QCUPSSupport::currentPPD() const
-{
- return currPPD;
-}
-
-const ppd_file_t* QCUPSSupport::setCurrentPrinter(int index)
-{
- Q_ASSERT(index >= 0 && index <= prnCount);
- if (index == prnCount)
- return 0;
-
- currPrinterIndex = index;
-
- if (currPPD)
- _ppdClose(currPPD);
- currPPD = 0;
- page_sizes = 0;
-
- const char *ppdFile = _cupsGetPPD(printers[index].name);
-
- if (!ppdFile)
- return 0;
-
- currPPD = _ppdOpenFile(ppdFile);
- unlink(ppdFile);
-
- // marking default options
- _ppdMarkDefaults(currPPD);
-
- // marking options explicitly set
- _cupsMarkOptions(currPPD, printers[currPrinterIndex].num_options, printers[currPrinterIndex].options);
-
- // getting pointer to page sizes
- page_sizes = ppdOption("PageSize");
-
- return currPPD;
-}
-
-const ppd_file_t* QCUPSSupport::setCurrentPrinter(const QString &printerName)
-{
- Q_FOREACH (const QCUPSSupport::Printer &printer, QCUPSSupport::availableUnixPrinters()) {
- if (printer.name == printerName) {
- return setCurrentPrinter(printer.cupsPrinterIndex);
- }
- }
-
- return 0;
-}
-
-int QCUPSSupport::currentPrinterIndex() const
-{
- return currPrinterIndex;
-}
-
-bool QCUPSSupport::isAvailable()
-{
- if(!cupsLoaded)
- resolveCups();
-
- return _cupsGetDests &&
- _cupsFreeDests &&
- _cupsGetPPD &&
- _ppdOpenFile &&
- _ppdMarkDefaults &&
- _ppdClose &&
- _cupsMarkOptions &&
- _ppdMarkOption &&
- _cupsFreeOptions &&
- _cupsSetDests &&
- _cupsLangGet &&
- _cupsLangEncoding &&
- _cupsAddOption &&
- (qt_cups_num_printers > 0);
-}
-
-const ppd_option_t* QCUPSSupport::ppdOption(const char *key) const
-{
- if (currPPD) {
- for (int gr = 0; gr < currPPD->num_groups; ++gr) {
- for (int opt = 0; opt < currPPD->groups[gr].num_options; ++opt) {
- if (qstrcmp(currPPD->groups[gr].options[opt].keyword, key) == 0)
- return &currPPD->groups[gr].options[opt];
- }
- }
- }
- return 0;
-}
-
-const cups_option_t* QCUPSSupport::printerOption(const QString &key) const
-{
- for (int i = 0; i < printers[currPrinterIndex].num_options; ++i) {
- if (QLatin1String(printers[currPrinterIndex].options[i].name) == key)
- return &printers[currPrinterIndex].options[i];
- }
- return 0;
-}
-
-const ppd_option_t* QCUPSSupport::pageSizes() const
-{
- return page_sizes;
-}
-
-int QCUPSSupport::markOption(const char* name, const char* value)
-{
- return _ppdMarkOption(currPPD, name, value);
-}
-
-void QCUPSSupport::saveOptions(QList<const ppd_option_t*> options, QList<const char*> markedOptions)
-{
- int oldOptionCount = printers[currPrinterIndex].num_options;
- cups_option_t* oldOptions = printers[currPrinterIndex].options;
-
- int newOptionCount = 0;
- cups_option_t* newOptions = 0;
-
- // copying old options that are not on the new list
- for (int i = 0; i < oldOptionCount; ++i) {
- bool contains = false;
- for (int j = 0; j < options.count(); ++j) {
- if (qstrcmp(options.at(j)->keyword, oldOptions[i].name) == 0) {
- contains = true;
- break;
- }
- }
-
- if (!contains) {
- newOptionCount = _cupsAddOption(oldOptions[i].name, oldOptions[i].value, newOptionCount, &newOptions);
- }
- }
-
- // we can release old option list
- _cupsFreeOptions(oldOptionCount, oldOptions);
-
- // adding marked options
- for (int i = 0; i < markedOptions.count(); ++i) {
- const char* name = markedOptions.at(i);
- ++i;
- newOptionCount = _cupsAddOption(name, markedOptions.at(i), newOptionCount, &newOptions);
- }
-
- // placing the new option list
- printers[currPrinterIndex].num_options = newOptionCount;
- printers[currPrinterIndex].options = newOptions;
-
- // saving new default values
- _cupsSetDests(prnCount, printers);
-}
-
-QRect QCUPSSupport::paperRect(const char *choice) const
-{
- if (!currPPD)
- return QRect();
- for (int i = 0; i < currPPD->num_sizes; ++i) {
- if (qstrcmp(currPPD->sizes[i].name, choice) == 0)
- return QRect(0, 0, qRound(currPPD->sizes[i].width), qRound(currPPD->sizes[i].length));
- }
- return QRect();
-}
-
-QRect QCUPSSupport::pageRect(const char *choice) const
-{
- if (!currPPD)
- return QRect();
- for (int i = 0; i < currPPD->num_sizes; ++i) {
- if (qstrcmp(currPPD->sizes[i].name, choice) == 0)
- return QRect(qRound(currPPD->sizes[i].left),
- qRound(currPPD->sizes[i].length - currPPD->sizes[i].top),
- qRound(currPPD->sizes[i].right - currPPD->sizes[i].left),
- qRound(currPPD->sizes[i].top - currPPD->sizes[i].bottom));
- }
- return QRect();
-}
-
-QStringList QCUPSSupport::options() const
-{
- QStringList list;
- collectMarkedOptions(list);
- return list;
-}
-
QStringList QCUPSSupport::cupsOptionsList(QPrinter *printer)
{
return printer->printEngine()->property(PPK_CupsOptions).toStringList();
@@ -544,175 +234,6 @@ void QCUPSSupport::setPageRange(QPrinter *printer, int pageFrom, int pageTo)
setCupsOptions(printer, cupsOptions);
}
-bool QCUPSSupport::printerHasPPD(const char *printerName)
-{
- if (!isAvailable())
- return false;
- const char *ppdFile = _cupsGetPPD(printerName);
- if (ppdFile)
- unlink(ppdFile);
- return (ppdFile != 0);
-}
-
-QString QCUPSSupport::unicodeString(const char *s)
-{
-#ifndef QT_NO_TEXTCODEC
- return codec->toUnicode(s);
-#else
- return QLatin1String(s);
-#endif
-}
-
-void QCUPSSupport::collectMarkedOptions(QStringList& list, const ppd_group_t* group) const
-{
- if (group == 0) {
- if (!currPPD)
- return;
- for (int i = 0; i < currPPD->num_groups; ++i) {
- collectMarkedOptions(list, &currPPD->groups[i]);
- collectMarkedOptionsHelper(list, &currPPD->groups[i]);
- }
- } else {
- for (int i = 0; i < group->num_subgroups; ++i)
- collectMarkedOptionsHelper(list, &group->subgroups[i]);
- }
-}
-
-void QCUPSSupport::collectMarkedOptionsHelper(QStringList& list, const ppd_group_t* group) const
-{
- for (int i = 0; i < group->num_options; ++i) {
- for (int j = 0; j < group->options[i].num_choices; ++j) {
- if (group->options[i].choices[j].marked == 1 && qstrcmp(group->options[i].choices[j].choice, group->options[i].defchoice) != 0)
- list << QString::fromLocal8Bit(group->options[i].keyword) << QString::fromLocal8Bit(group->options[i].choices[j].choice);
- }
- }
-}
-
-QPair<int, QString> QCUPSSupport::tempFd()
-{
- char filename[512];
- int fd = _cupsTempFd(filename, 512);
- return QPair<int, QString>(fd, QString::fromLocal8Bit(filename));
-}
-
-// Prints the given file and returns a job id.
-int QCUPSSupport::printFile(const char * printerName, const char * filename, const char * title,
- int num_options, cups_option_t * options)
-{
- return _cupsPrintFile(printerName, filename, title, num_options, options);
-}
-
-QCUPSSupport::Printer::Printer(const QString &n) : name(n), isDefault(false), cupsPrinterIndex(-1)
-{
-}
-
-QList<QCUPSSupport::Printer> QCUPSSupport::availableUnixPrinters()
-{
- QList<Printer> printers;
-
- if (QCUPSSupport::isAvailable()) {
- QCUPSSupport cups;
- int cupsPrinterCount = cups.availablePrintersCount();
- const cups_dest_t* cupsPrinters = cups.availablePrinters();
- for (int i = 0; i < cupsPrinterCount; ++i) {
- QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
- if (cupsPrinters[i].instance)
- printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
-
- Printer p(printerName);
- if (cupsPrinters[i].is_default)
- p.isDefault = true;
- p.cupsPrinterIndex = i;
- printers.append(p);
- }
- }
-
- return printers;
-}
-
-// preserve names in ascending order for the binary search
-static const struct NamedPaperSize {
- const char *const name;
- QPrinter::PaperSize size;
-} named_sizes_map[QPrinter::NPageSize] = {
- { "A0", QPrinter::A0 },
- { "A1", QPrinter::A1 },
- { "A2", QPrinter::A2 },
- { "A3", QPrinter::A3 },
- { "A4", QPrinter::A4 },
- { "A5", QPrinter::A5 },
- { "A6", QPrinter::A6 },
- { "A7", QPrinter::A7 },
- { "A8", QPrinter::A8 },
- { "A9", QPrinter::A9 },
- { "B0", QPrinter::B0 },
- { "B1", QPrinter::B1 },
- { "B10", QPrinter::B10 },
- { "B2", QPrinter::B2 },
- { "B4", QPrinter::B4 },
- { "B5", QPrinter::B5 },
- { "B6", QPrinter::B6 },
- { "B7", QPrinter::B7 },
- { "B8", QPrinter::B8 },
- { "B9", QPrinter::B9 },
- { "C5E", QPrinter::C5E },
- { "Comm10E", QPrinter::Comm10E },
- { "Custom", QPrinter::Custom },
- { "DLE", QPrinter::DLE },
- { "Executive", QPrinter::Executive },
- { "Folio", QPrinter::Folio },
- { "Ledger", QPrinter::Ledger },
- { "Legal", QPrinter::Legal },
- { "Letter", QPrinter::Letter },
- { "Tabloid", QPrinter::Tabloid }
-};
-
-inline bool operator<(const char *name, const NamedPaperSize &data)
-{ return qstrcmp(name, data.name) < 0; }
-inline bool operator<(const NamedPaperSize &data, const char *name)
-{ return qstrcmp(data.name, name) < 0; }
-
-static inline QPrinter::PaperSize string2PaperSize(const char *name)
-{
- const NamedPaperSize *r = std::lower_bound(named_sizes_map, named_sizes_map + QPrinter::NPageSize, name);
- if ((r != named_sizes_map + QPrinter::NPageSize) && !(name < *r))
- return r->size;
- return QPrinter::Custom;
-}
-
-QList<QPrinter::PaperSize> QCUPSSupport::getCupsPrinterPaperSizes(int cupsPrinterIndex)
-{
- QList<QPrinter::PaperSize> result;
- if (!QCUPSSupport::isAvailable() || cupsPrinterIndex < 0)
- return result;
- // Find paper sizes from CUPS.
- QCUPSSupport cups;
- cups.setCurrentPrinter(cupsPrinterIndex);
- if (const ppd_option_t* size = cups.pageSizes()) {
- for (int j = 0; j < size->num_choices; ++j)
- result.append(string2PaperSize(size->choices[j].choice));
- }
- return result;
-}
-
-QList<QPair<QString, QSizeF> > QCUPSSupport::getCupsPrinterPaperSizesWithNames(int cupsPrinterIndex)
-{
- QList<QPair<QString, QSizeF> > result;
- if (!QCUPSSupport::isAvailable() || cupsPrinterIndex < 0)
- return result;
- // Find paper sizes from CUPS.
- QCUPSSupport cups;
- cups.setCurrentPrinter(cupsPrinterIndex);
- if (const ppd_option_t* size = cups.pageSizes()) {
- for (int j = 0; j < size->num_choices; ++j) {
- double multiplier = qt_multiplierForUnit(QPrinter::Millimeter, 0); // resolution is not needed here
- QSize sz = cups.paperRect(size->choices[j].choice).size();
- result.append(qMakePair(QString::fromUtf8(size->choices[j].text), QSizeF(sz.width() / multiplier, sz.height() / multiplier)));
- }
- }
- return result;
-}
-
QT_END_NAMESPACE
#endif // QT_NO_CUPS
diff --git a/src/printsupport/kernel/qcups_p.h b/src/printsupport/kernel/qcups_p.h
index 95ca323c22..0b327d4228 100644
--- a/src/printsupport/kernel/qcups_p.h
+++ b/src/printsupport/kernel/qcups_p.h
@@ -54,15 +54,10 @@
//
#include "QtCore/qstring.h"
#include "QtCore/qstringlist.h"
-#include "QtCore/qpair.h"
#include "QtPrintSupport/qprinter.h"
#include "QtCore/qdatetime.h"
#ifndef QT_NO_CUPS
-#include <QtCore/qlibrary.h>
-#include <cups/cups.h>
-#include <cups/ppd.h>
-#include "qprintengine.h"
QT_BEGIN_NAMESPACE
@@ -71,26 +66,10 @@ QT_BEGIN_NAMESPACE
// Move back to qcupsprintengine_p.h in the plugin once all usage
// removed from the dialogs.
#define PPK_CupsOptions QPrintEngine::PrintEnginePropertyKey(0xfe00)
-#define PPK_CupsPageRect QPrintEngine::PrintEnginePropertyKey(0xfe01)
-#define PPK_CupsPaperRect QPrintEngine::PrintEnginePropertyKey(0xfe02)
-#define PPK_CupsStringPageSize QPrintEngine::PrintEnginePropertyKey(0xfe03)
-
-Q_DECLARE_TYPEINFO(cups_option_t, Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE);
class Q_PRINTSUPPORT_EXPORT QCUPSSupport
{
public:
- struct Printer
- {
- Printer(const QString &name = QString());
-
- QString name;
- bool isDefault;
- int cupsPrinterIndex;
- };
- QCUPSSupport();
- ~QCUPSSupport();
-
// Enum for values of job-hold-until option
enum JobHoldUntil {
NoHold = 0, //CUPS Default
@@ -143,28 +122,6 @@ public:
TopToBottomRightToLeft
};
- static bool isAvailable();
- static int cupsVersion() { return isAvailable() ? CUPS_VERSION_MAJOR*10000+CUPS_VERSION_MINOR*100+CUPS_VERSION_PATCH : 0; }
- int availablePrintersCount() const;
- const cups_dest_t* availablePrinters() const;
- int currentPrinterIndex() const;
- const ppd_file_t* setCurrentPrinter(int index);
- const ppd_file_t* setCurrentPrinter(const QString &printerName);
-
- const ppd_file_t* currentPPD() const;
- const ppd_option_t* ppdOption(const char *key) const;
-
- const cups_option_t* printerOption(const QString &key) const;
- const ppd_option_t* pageSizes() const;
-
- int markOption(const char* name, const char* value);
- void saveOptions(QList<const ppd_option_t*> options, QList<const char*> markedOptions);
-
- QRect paperRect(const char *choice) const;
- QRect pageRect(const char *choice) const;
-
- QStringList options() const;
-
static QStringList cupsOptionsList(QPrinter *printer);
static void setCupsOptions(QPrinter *printer, const QStringList &cupsOptions);
static void setCupsOption(QStringList &cupsOptions, const QString &option, const QString &value);
@@ -177,31 +134,6 @@ public:
static void setPagesPerSheetLayout(QPrinter *printer, const PagesPerSheet pagesPerSheet,
const PagesPerSheetLayout pagesPerSheetLayout);
static void setPageRange(QPrinter *printer, int pageFrom, int pageTo);
-
- static bool printerHasPPD(const char *printerName);
-
- QString unicodeString(const char *s);
-
- QPair<int, QString> tempFd();
- int printFile(const char * printerName, const char * filename, const char * title,
- int num_options, cups_option_t * options);
-
- static QList<Printer> availableUnixPrinters();
- static QList<QPrinter::PaperSize> getCupsPrinterPaperSizes(int cupsPrinterIndex);
- static QList<QPair<QString, QSizeF> > getCupsPrinterPaperSizesWithNames(int cupsPrinterIndex);
-
-private:
- void collectMarkedOptions(QStringList& list, const ppd_group_t* group = 0) const;
- void collectMarkedOptionsHelper(QStringList& list, const ppd_group_t* group) const;
-
- int prnCount;
- cups_dest_t *printers;
- const ppd_option_t* page_sizes;
- int currPrinterIndex;
- ppd_file_t *currPPD;
-#ifndef QT_NO_TEXTCODEC
- QTextCodec *codec;
-#endif
};
QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qpaintengine_alpha.cpp b/src/printsupport/kernel/qpaintengine_alpha.cpp
index 298bb8d218..7d4dc18111 100644
--- a/src/printsupport/kernel/qpaintengine_alpha.cpp
+++ b/src/printsupport/kernel/qpaintengine_alpha.cpp
@@ -345,6 +345,7 @@ void QAlphaPaintEngine::flushAndInit(bool init)
d->m_picpainter->setFont(painter()->font());
d->m_picpainter->setOpacity(painter()->opacity());
d->m_picpainter->setTransform(painter()->combinedTransform());
+ *d->m_picpainter->d_func()->state = *painter()->d_func()->state;
d->m_picengine->syncState();
}
}
diff --git a/src/printsupport/kernel/qplatformprintdevice.cpp b/src/printsupport/kernel/qplatformprintdevice.cpp
new file mode 100644
index 0000000000..4932bf1d04
--- /dev/null
+++ b/src/printsupport/kernel/qplatformprintdevice.cpp
@@ -0,0 +1,393 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 John Layt <jlayt@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtPrintSupport module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplatformprintdevice.h"
+
+#include "qprintdevice_p.h"
+#include "qprintdialog.h"
+
+#include <QtGui/qpagelayout.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PRINTER
+
+QPlatformPrintDevice::QPlatformPrintDevice()
+ : m_isRemote(false),
+ m_supportsMultipleCopies(false),
+ m_supportsCollateCopies(false),
+ m_havePageSizes(false),
+ m_supportsCustomPageSizes(false),
+ m_haveResolutions(false),
+ m_haveInputSlots(false),
+ m_haveOutputBins(false),
+ m_haveDuplexModes(false),
+ m_haveColorModes(false)
+{
+}
+
+QPlatformPrintDevice::QPlatformPrintDevice(const QString &id)
+ : m_id(id),
+ m_isRemote(false),
+ m_supportsMultipleCopies(false),
+ m_supportsCollateCopies(false),
+ m_havePageSizes(false),
+ m_supportsCustomPageSizes(false),
+ m_haveResolutions(false),
+ m_haveInputSlots(false),
+ m_haveOutputBins(false),
+ m_haveDuplexModes(false),
+ m_haveColorModes(false)
+{
+}
+
+QPlatformPrintDevice::~QPlatformPrintDevice()
+{
+}
+
+bool QPlatformPrintDevice::operator==(const QPlatformPrintDevice &other) const
+{
+ return m_id == other.m_id;
+}
+
+QString QPlatformPrintDevice::id() const
+{
+ return m_id;
+}
+
+QString QPlatformPrintDevice::name() const
+{
+ return m_name;
+}
+
+QString QPlatformPrintDevice::location() const
+{
+ return m_location;
+}
+
+QString QPlatformPrintDevice::makeAndModel() const
+{
+ return m_makeAndModel;
+}
+
+bool QPlatformPrintDevice::isValid() const
+{
+ return false;
+}
+
+bool QPlatformPrintDevice::isDefault() const
+{
+ return false;
+}
+
+bool QPlatformPrintDevice::isRemote() const
+{
+ return m_isRemote;
+}
+
+bool QPlatformPrintDevice::isValidPageLayout(const QPageLayout &layout, int resolution) const
+{
+ // Check the page size is supported
+ if (!supportedPageSize(layout.pageSize()).isValid())
+ return false;
+
+ // Check the margins are valid
+ QMarginsF pointMargins = layout.margins(QPageLayout::Point);
+ QMarginsF printMargins = printableMargins(layout.pageSize(), layout.orientation(), resolution);
+ return pointMargins.left() >= printMargins.left()
+ && pointMargins.right() >= printMargins.right()
+ && pointMargins.top() >= printMargins.top()
+ && pointMargins.bottom() >= printMargins.bottom();
+}
+
+QPrint::DeviceState QPlatformPrintDevice::state() const
+{
+ return QPrint::Error;
+}
+
+bool QPlatformPrintDevice::supportsMultipleCopies() const
+{
+ return m_supportsMultipleCopies;
+}
+
+bool QPlatformPrintDevice::supportsCollateCopies() const
+{
+ return m_supportsCollateCopies;
+}
+
+void QPlatformPrintDevice::loadPageSizes() const
+{
+}
+
+QPageSize QPlatformPrintDevice::defaultPageSize() const
+{
+ return QPageSize();
+}
+
+QList<QPageSize> QPlatformPrintDevice::supportedPageSizes() const
+{
+ if (!m_havePageSizes)
+ loadPageSizes();
+ return m_pageSizes.toList();
+}
+
+QPageSize QPlatformPrintDevice::supportedPageSize(const QPageSize &pageSize) const
+{
+ if (!pageSize.isValid())
+ return QPageSize();
+
+ if (!m_havePageSizes)
+ loadPageSizes();
+
+ // First try match on name and id for case where printer defines same size twice with different names
+ // e.g. Windows defines DMPAPER_11X17 and DMPAPER_TABLOID with names "11x17" and "Tabloid", but both
+ // map to QPageSize::Tabloid / PPD Key "Tabloid" / ANSI B Tabloid
+ if (pageSize.id() != QPageSize::Custom) {
+ foreach (const QPageSize &ps, m_pageSizes) {
+ if (ps.id() == pageSize.id() && ps.name() == pageSize.name())
+ return ps;
+ }
+ }
+
+ // Next try match on id only if not custom
+ if (pageSize.id() != QPageSize::Custom) {
+ foreach (const QPageSize &ps, m_pageSizes) {
+ if (ps.id() == pageSize.id())
+ return ps;
+ }
+ }
+
+ // Next try a match on size, in case it's a custom with a different name
+ return supportedPageSizeMatch(pageSize);
+}
+
+QPageSize QPlatformPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSizeId) const
+{
+ if (!m_havePageSizes)
+ loadPageSizes();
+
+ foreach (const QPageSize &ps, m_pageSizes) {
+ if (ps.id() == pageSizeId)
+ return ps;
+ }
+
+ // If no supported page size found, try use a custom size instead if supported
+ return supportedPageSizeMatch(QPageSize(pageSizeId));
+}
+
+QPageSize QPlatformPrintDevice::supportedPageSize(const QString &pageName) const
+{
+ if (!m_havePageSizes)
+ loadPageSizes();
+
+ foreach (const QPageSize &ps, m_pageSizes) {
+ if (ps.name() == pageName)
+ return ps;
+ }
+
+ return QPageSize();
+}
+
+QPageSize QPlatformPrintDevice::supportedPageSize(const QSize &sizePoints) const
+{
+ if (!m_havePageSizes)
+ loadPageSizes();
+
+ // Try to find a supported page size based on fuzzy-matched point size
+ return supportedPageSizeMatch(QPageSize(sizePoints));
+}
+
+QPageSize QPlatformPrintDevice::supportedPageSize(const QSizeF &size, QPageSize::Unit units) const
+{
+ if (!m_havePageSizes)
+ loadPageSizes();
+
+ // Try to find a supported page size based on fuzzy-matched unit size
+ return supportedPageSizeMatch(QPageSize(size, units));
+}
+
+QPageSize QPlatformPrintDevice::supportedPageSizeMatch(const QPageSize &pageSize) const
+{
+ // Try to find a supported page size based on point size
+ foreach (const QPageSize &ps, m_pageSizes) {
+ if (ps.sizePoints() == pageSize.sizePoints())
+ return ps;
+ }
+ return QPageSize();
+}
+
+bool QPlatformPrintDevice::supportsCustomPageSizes() const
+{
+ return m_supportsCustomPageSizes;
+}
+
+QSize QPlatformPrintDevice::minimumPhysicalPageSize() const
+{
+ return m_minimumPhysicalPageSize;
+}
+
+QSize QPlatformPrintDevice::maximumPhysicalPageSize() const
+{
+ return m_maximumPhysicalPageSize;
+}
+
+QMarginsF QPlatformPrintDevice::printableMargins(const QPageSize &pageSize,
+ QPageLayout::Orientation orientation,
+ int resolution) const
+{
+ Q_UNUSED(pageSize)
+ Q_UNUSED(orientation)
+ Q_UNUSED(resolution)
+ return QMarginsF(0, 0, 0, 0);
+}
+
+void QPlatformPrintDevice::loadResolutions() const
+{
+}
+
+int QPlatformPrintDevice::defaultResolution() const
+{
+ return 0;
+}
+
+QList<int> QPlatformPrintDevice::supportedResolutions() const
+{
+ if (!m_haveResolutions)
+ loadResolutions();
+ return m_resolutions.toList();
+}
+
+void QPlatformPrintDevice::loadInputSlots() const
+{
+}
+
+QPrint::InputSlot QPlatformPrintDevice::defaultInputSlot() const
+{
+ QPrint::InputSlot input;
+ input.key = QByteArrayLiteral("Auto");
+ input.name = QPrintDialog::tr("Automatic");
+ input.id = QPrint::Auto;
+ return input;
+}
+
+QList<QPrint::InputSlot> QPlatformPrintDevice::supportedInputSlots() const
+{
+ if (!m_haveInputSlots)
+ loadInputSlots();
+ return m_inputSlots.toList();
+}
+
+void QPlatformPrintDevice::loadOutputBins() const
+{
+}
+
+QPrint::OutputBin QPlatformPrintDevice::defaultOutputBin() const
+{
+ QPrint::OutputBin output;
+ output.key = QByteArrayLiteral("Auto");
+ output.name = QPrintDialog::tr("Automatic");
+ output.id = QPrint::AutoOutputBin;
+ return output;
+}
+
+QList<QPrint::OutputBin> QPlatformPrintDevice::supportedOutputBins() const
+{
+ if (!m_haveOutputBins)
+ loadOutputBins();
+ return m_outputBins.toList();
+}
+
+void QPlatformPrintDevice::loadDuplexModes() const
+{
+}
+
+QPrint::DuplexMode QPlatformPrintDevice::defaultDuplexMode() const
+{
+ return QPrint::DuplexNone;
+}
+
+QList<QPrint::DuplexMode> QPlatformPrintDevice::supportedDuplexModes() const
+{
+ if (!m_haveDuplexModes)
+ loadDuplexModes();
+ return m_duplexModes.toList();
+}
+
+void QPlatformPrintDevice::loadColorModes() const
+{
+}
+
+QPrint::ColorMode QPlatformPrintDevice::defaultColorMode() const
+{
+ return QPrint::GrayScale;
+}
+
+QList<QPrint::ColorMode> QPlatformPrintDevice::supportedColorModes() const
+{
+ if (!m_haveColorModes)
+ loadColorModes();
+ return m_colorModes.toList();
+}
+
+void QPlatformPrintDevice::loadMimeTypes() const
+{
+}
+
+QList<QMimeType> QPlatformPrintDevice::supportedMimeTypes() const
+{
+ if (!m_haveMimeTypes)
+ loadMimeTypes();
+ return m_mimeTypes.toList();
+}
+
+QPageSize QPlatformPrintDevice::createPageSize(const QString &key, const QSize &size, const QString &localizedName)
+{
+ return QPageSize(key, size, localizedName);
+}
+
+QPageSize QPlatformPrintDevice::createPageSize(int windowsId, const QSize &size, const QString &localizedName)
+{
+ return QPageSize(windowsId, size, localizedName);
+}
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qplatformprintdevice.h b/src/printsupport/kernel/qplatformprintdevice.h
new file mode 100644
index 0000000000..7674c50c2f
--- /dev/null
+++ b/src/printsupport/kernel/qplatformprintdevice.h
@@ -0,0 +1,182 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 John Layt <jlayt@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtPrintSupport module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPLATFORMPRINTDEVICE_H
+#define QPLATFORMPRINTDEVICE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qprint_p.h>
+
+#include <QtCore/qvector.h>
+#include <QtCore/qmimetype.h>
+#include <QtGui/qpagelayout.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PRINTER
+
+class Q_PRINTSUPPORT_EXPORT QPlatformPrintDevice : public QSharedData
+{
+public:
+ QPlatformPrintDevice();
+ explicit QPlatformPrintDevice(const QString &id);
+ virtual ~QPlatformPrintDevice();
+
+ QPlatformPrintDevice *clone();
+
+ bool operator==(const QPlatformPrintDevice &other) const;
+
+ virtual QString id() const;
+ virtual QString name() const;
+ virtual QString location() const;
+ virtual QString makeAndModel() const;
+
+ virtual bool isValid() const;
+ virtual bool isDefault() const;
+ virtual bool isRemote() const;
+
+ virtual QPrint::DeviceState state() const;
+
+ virtual bool isValidPageLayout(const QPageLayout &layout, int resolution) const;
+
+ virtual bool supportsMultipleCopies() const;
+ virtual bool supportsCollateCopies() const;
+
+ virtual QPageSize defaultPageSize() const;
+ virtual QList<QPageSize> supportedPageSizes() const;
+
+ virtual QPageSize supportedPageSize(const QPageSize &pageSize) const;
+ virtual QPageSize supportedPageSize(QPageSize::PageSizeId pageSizeId) const;
+ virtual QPageSize supportedPageSize(const QString &pageName) const;
+ virtual QPageSize supportedPageSize(const QSize &pointSize) const;
+ virtual QPageSize supportedPageSize(const QSizeF &size, QPageSize::Unit units) const;
+
+ virtual bool supportsCustomPageSizes() const;
+
+ virtual QSize minimumPhysicalPageSize() const;
+ virtual QSize maximumPhysicalPageSize() const;
+
+ virtual QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation,
+ int resolution) const;
+
+ virtual int defaultResolution() const;
+ virtual QList<int> supportedResolutions() const;
+
+ virtual QPrint::InputSlot defaultInputSlot() const;
+ virtual QList<QPrint::InputSlot> supportedInputSlots() const;
+
+ virtual QPrint::OutputBin defaultOutputBin() const;
+ virtual QList<QPrint::OutputBin> supportedOutputBins() const;
+
+ virtual QPrint::DuplexMode defaultDuplexMode() const;
+ virtual QList<QPrint::DuplexMode> supportedDuplexModes() const;
+
+ virtual QPrint::ColorMode defaultColorMode() const;
+ virtual QList<QPrint::ColorMode> supportedColorModes() const;
+
+ virtual QList<QMimeType> supportedMimeTypes() const;
+
+ static QPageSize createPageSize(const QString &key, const QSize &size, const QString &localizedName);
+ static QPageSize createPageSize(int windowsId, const QSize &size, const QString &localizedName);
+
+protected:
+ virtual void loadPageSizes() const;
+ virtual void loadResolutions() const;
+ virtual void loadInputSlots() const;
+ virtual void loadOutputBins() const;
+ virtual void loadDuplexModes() const;
+ virtual void loadColorModes() const;
+ virtual void loadMimeTypes() const;
+
+ QPageSize supportedPageSizeMatch(const QPageSize &pageSize) const;
+
+ QString m_id;
+ QString m_name;
+ QString m_location;
+ QString m_makeAndModel;
+
+ bool m_isRemote;
+
+ bool m_supportsMultipleCopies;
+ bool m_supportsCollateCopies;
+
+ mutable bool m_havePageSizes;
+ mutable QVector<QPageSize> m_pageSizes;
+
+ bool m_supportsCustomPageSizes;
+
+ QSize m_minimumPhysicalPageSize;
+ QSize m_maximumPhysicalPageSize;
+
+ mutable bool m_haveResolutions;
+ mutable QVector<int> m_resolutions;
+
+ mutable bool m_haveInputSlots;
+ mutable QVector<QPrint::InputSlot> m_inputSlots;
+
+ mutable bool m_haveOutputBins;
+ mutable QVector<QPrint::OutputBin> m_outputBins;
+
+ mutable bool m_haveDuplexModes;
+ mutable QVector<QPrint::DuplexMode> m_duplexModes;
+
+ mutable bool m_haveColorModes;
+ mutable QVector<QPrint::ColorMode> m_colorModes;
+
+ mutable bool m_haveMimeTypes;
+ mutable QVector<QMimeType> m_mimeTypes;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
+
+#endif // QPLATFORMPRINTDEVICE_H
diff --git a/src/printsupport/kernel/qplatformprintersupport.cpp b/src/printsupport/kernel/qplatformprintersupport.cpp
index 4d80e55ab6..1494155302 100644
--- a/src/printsupport/kernel/qplatformprintersupport.cpp
+++ b/src/printsupport/kernel/qplatformprintersupport.cpp
@@ -40,10 +40,13 @@
****************************************************************************/
#include "qplatformprintersupport.h"
+#include "qplatformprintdevice.h"
+#include <QtGui/qpagesize.h>
#include <QtPrintSupport/qprinterinfo.h>
#include <private/qprinterinfo_p.h>
+#include <private/qprintdevice_p.h>
#ifndef QT_NO_PRINTER
@@ -77,90 +80,38 @@ QPaintEngine *QPlatformPrinterSupport::createPaintEngine(QPrintEngine *, QPrinte
return 0;
}
-QList<QPrinter::PaperSize> QPlatformPrinterSupport::supportedPaperSizes(const QPrinterInfo &) const
+QPrintDevice QPlatformPrinterSupport::createPrintDevice(QPlatformPrintDevice *device)
{
- return QList<QPrinter::PaperSize>();
+ return QPrintDevice(device);
}
-QList<QPair<QString, QSizeF> > QPlatformPrinterSupport::supportedSizesWithNames(const QPrinterInfo &) const
+QPrintDevice QPlatformPrinterSupport::createPrintDevice(const QString &id)
{
- return QList<QPair<QString, QSizeF> >();
+ Q_UNUSED(id)
+ return QPrintDevice();
}
-QList<QPrinterInfo> QPlatformPrinterSupport::availablePrinters()
+QPrintDevice QPlatformPrinterSupport::createDefaultPrintDevice()
{
- return m_printers;
+ return createPrintDevice(defaultPrintDeviceId());
}
-QPrinterInfo QPlatformPrinterSupport::defaultPrinter()
+QStringList QPlatformPrinterSupport::availablePrintDeviceIds() const
{
- const QList<QPrinterInfo> printers = availablePrinters();
- foreach (const QPrinterInfo &printerInfo, printers) {
- if (printerInfo.isDefault())
- return printerInfo;
- }
- return QPrinterInfo();
+ return QStringList();
}
-QPrinterInfo QPlatformPrinterSupport::printerInfo(const QString &printerName)
+QString QPlatformPrinterSupport::defaultPrintDeviceId() const
{
- const QList<QPrinterInfo> printers = availablePrinters();
- foreach (const QPrinterInfo &printerInfo, printers) {
- if (printerInfo.printerName() == printerName)
- return printerInfo;
- }
- return QPrinterInfo();
-}
-
-QString QPlatformPrinterSupport::printerOption(const QPrinterInfo &printer, const QString &key) const
-{
- Q_UNUSED(printer)
- Q_UNUSED(key)
return QString();
}
-PrinterOptions QPlatformPrinterSupport::printerOptions(const QPrinterInfo &printer) const
-{
- Q_UNUSED(printer)
- return PrinterOptions();
-}
-
-int QPlatformPrinterSupport::printerIndex(const QPrinterInfo &printer)
-{
- return printer.d_func()->index;
-}
-
-QPrinterInfo QPlatformPrinterSupport::createPrinterInfo(const QString &name, const QString &description,
- const QString &location, const QString &makeAndModel,
- bool isDefault, int index)
-{
- QPrinterInfo printer(name);
- printer.d_func()->description = description;
- printer.d_func()->location = location;
- printer.d_func()->makeAndModel = makeAndModel;
- printer.d_func()->isDefault = isDefault;
- printer.d_func()->index = index;
- return printer;
-}
-
-/*
- Converts QSizeF in millimeters to a predefined PaperSize (returns Custom if
- the size isn't a standard size)
-*/
-extern QPrinter::PaperSize qSizeFTopaperSize(const QSizeF &);
-QPrinter::PaperSize QPlatformPrinterSupport::convertQSizeFToPaperSize(const QSizeF &sizef)
-{
- return qSizeFTopaperSize(sizef);
-}
-
-/*
- Converts a predefined PaperSize to a QSizeF in millimeters (returns
- QSizeF(0.0, 0.0) if PaperSize is Custom)
-*/
-extern QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size);
-QSizeF QPlatformPrinterSupport::convertPaperSizeToQSizeF(QPrinter::PaperSize paperSize)
+QPageSize QPlatformPrinterSupport::createPageSize(const QString &id, QSize size, const QString &localizedName)
{
- return qt_paperSizeToQSizeF(paperSize);
+ Q_UNUSED(id)
+ Q_UNUSED(size)
+ Q_UNUSED(localizedName)
+ return QPageSize();
}
QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qplatformprintersupport.h b/src/printsupport/kernel/qplatformprintersupport.h
index c4ffcffd1e..0efec08f64 100644
--- a/src/printsupport/kernel/qplatformprintersupport.h
+++ b/src/printsupport/kernel/qplatformprintersupport.h
@@ -52,6 +52,7 @@
#include <QtPrintSupport/qprinter.h>
+#include <QtCore/qstringlist.h>
#include <QtCore/qlist.h>
#include <QtCore/qhash.h>
@@ -61,6 +62,9 @@ QT_BEGIN_NAMESPACE
typedef QHash<QString, QString> PrinterOptions;
+class QPageSize;
+class QPlatformPrintDevice;
+class QPrintDevice;
class QPrintEngine;
class Q_PRINTSUPPORT_EXPORT QPlatformPrinterSupport
@@ -71,25 +75,15 @@ public:
virtual QPrintEngine *createNativePrintEngine(QPrinter::PrinterMode printerMode);
virtual QPaintEngine *createPaintEngine(QPrintEngine *, QPrinter::PrinterMode printerMode);
- virtual QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &) const;
- virtual QList<QPair<QString, QSizeF> > supportedSizesWithNames(const QPrinterInfo &printerInfo) const;
- virtual QList<QPrinterInfo> availablePrinters();
- virtual QPrinterInfo defaultPrinter();
- virtual QPrinterInfo printerInfo(const QString &printerName);
- virtual QString printerOption(const QPrinterInfo &printer, const QString &key) const;
- virtual PrinterOptions printerOptions(const QPrinterInfo &printer) const;
-
- static QPrinter::PaperSize convertQSizeFToPaperSize(const QSizeF &sizef);
- static QSizeF convertPaperSizeToQSizeF(QPrinter::PaperSize paperSize);
+ virtual QPrintDevice createPrintDevice(const QString &id);
+ virtual QPrintDevice createDefaultPrintDevice();
+ virtual QStringList availablePrintDeviceIds() const;
+ virtual QString defaultPrintDeviceId() const;
protected:
- static int printerIndex(const QPrinterInfo &printer);
- static QPrinterInfo createPrinterInfo(const QString &name, const QString &description,
- const QString &location, const QString &makeAndModel,
- bool isDefault, int index);
-
- QList<QPrinterInfo> m_printers;
+ static QPrintDevice createPrintDevice(QPlatformPrintDevice *device);
+ static QPageSize createPageSize(const QString &id, QSize size, const QString &localizedName);
};
#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprint_p.h b/src/printsupport/kernel/qprint_p.h
new file mode 100644
index 0000000000..30f7c4a65e
--- /dev/null
+++ b/src/printsupport/kernel/qprint_p.h
@@ -0,0 +1,304 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 John Layt <jlayt@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtPrintSupport module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINT_P_H
+#define QPRINT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtPrintSupport/qprinter.h>
+
+#include <QtCore/qstring.h>
+#include <QtCore/qlist.h>
+
+#if (defined Q_OS_MAC && !defined Q_OS_IOS) || (defined Q_OS_UNIX && !defined QT_NO_CUPS)
+#include <cups/ppd.h> // Use for type defs only, don't want to actually link in main module
+#endif
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PRINTER
+
+// From windgdi.h
+#define DMBIN_UPPER 1
+#define DMBIN_ONLYONE 1
+#define DMBIN_LOWER 2
+#define DMBIN_MIDDLE 3
+#define DMBIN_MANUAL 4
+#define DMBIN_ENVELOPE 5
+#define DMBIN_ENVMANUAL 6
+#define DMBIN_AUTO 7
+#define DMBIN_TRACTOR 8
+#define DMBIN_SMALLFMT 9
+#define DMBIN_LARGEFMT 10
+#define DMBIN_LARGECAPACITY 11
+#define DMBIN_CASSETTE 14
+#define DMBIN_FORMSOURCE 15
+#define DMBIN_USER 256
+
+namespace QPrint {
+
+ // Note: Keep in sync with QPrinter::PrinterState for now
+ // Replace later with more detailed status reporting
+ enum DeviceState {
+ Idle,
+ Active,
+ Aborted,
+ Error
+ };
+
+ // Note: Keep in sync with QPrinter::DuplexMode
+ enum DuplexMode {
+ DuplexNone = 0,
+ DuplexAuto,
+ DuplexLongSide,
+ DuplexShortSide
+ };
+
+ enum ColorMode {
+ GrayScale,
+ Color
+ };
+
+ // Note: Keep in sync with QPrinter::PaperSource for now
+ // If/when made public, rearrange and rename
+ enum InputSlotId {
+ Upper,
+ Lower,
+ Middle,
+ Manual,
+ Envelope,
+ EnvelopeManual,
+ Auto,
+ Tractor,
+ SmallFormat,
+ LargeFormat,
+ LargeCapacity,
+ Cassette,
+ FormSource,
+ MaxPageSource, // Deprecated, kept for compatibility to QPrinter
+ CustomInputSlot,
+ LastInputSlot = CustomInputSlot,
+ OnlyOne = Upper
+ };
+
+ struct InputSlot {
+ QByteArray key;
+ QString name;
+ QPrint::InputSlotId id;
+ int windowsId;
+ };
+
+ enum OutputBinId {
+ AutoOutputBin,
+ UpperBin,
+ LowerBin,
+ RearBin,
+ CustomOutputBin,
+ LastOutputBin = CustomOutputBin
+ };
+
+ struct OutputBin {
+ QByteArray key;
+ QString name;
+ QPrint::OutputBinId id;
+ };
+
+};
+
+struct InputSlotMap {
+ QPrint::InputSlotId id;
+ int windowsId;
+ const char *key;
+};
+
+// Note: PPD standard does not define a standard set of InputSlot keywords,
+// it is a free form text field left to the PPD writer to decide,
+// but it does suggest some names for consistency with the Windows enum.
+static const InputSlotMap inputSlotMap[] = {
+ { QPrint::Upper, DMBIN_UPPER, "Upper" },
+ { QPrint::Lower, DMBIN_LOWER, "Lower" },
+ { QPrint::Middle, DMBIN_MIDDLE, "Middle" },
+ { QPrint::Manual, DMBIN_MANUAL, "Manual" },
+ { QPrint::Envelope, DMBIN_ENVELOPE, "Envelope" },
+ { QPrint::EnvelopeManual, DMBIN_ENVMANUAL, "EnvelopeManual" },
+ { QPrint::Auto, DMBIN_AUTO, "Auto" },
+ { QPrint::Tractor, DMBIN_TRACTOR, "Tractor" },
+ { QPrint::SmallFormat, DMBIN_SMALLFMT, "AnySmallFormat" },
+ { QPrint::LargeFormat, DMBIN_LARGEFMT, "AnyLargeFormat" },
+ { QPrint::LargeCapacity, DMBIN_LARGECAPACITY, "LargeCapacity" },
+ { QPrint::Cassette, DMBIN_CASSETTE, "Cassette" },
+ { QPrint::FormSource, DMBIN_FORMSOURCE, "FormSource" },
+ { QPrint::Manual, DMBIN_MANUAL, "ManualFeed" },
+ { QPrint::OnlyOne, DMBIN_ONLYONE, "OnlyOne" }, // = QPrint::Upper
+ { QPrint::CustomInputSlot, DMBIN_USER, "" } // Must always be last row
+};
+
+struct OutputBinMap {
+ QPrint::OutputBinId id;
+ const char *key;
+};
+
+static const OutputBinMap outputBinMap[] = {
+ { QPrint::AutoOutputBin, "" }, // Not a PPD defined value, internal use only
+ { QPrint::UpperBin, "Upper" },
+ { QPrint::LowerBin, "Lower" },
+ { QPrint::RearBin, "Rear" },
+ { QPrint::CustomOutputBin, "" } // Must always be last row
+};
+
+// Print utilities shared by print plugins
+
+class QPrintUtils
+{
+
+public:
+
+ static QPrint::InputSlotId inputSlotKeyToInputSlotId(const QByteArray &key)
+ {
+ for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].key == key)
+ return inputSlotMap[i].id;
+ }
+ return QPrint::CustomInputSlot;
+ }
+
+ static QByteArray inputSlotIdToInputSlotKey(QPrint::InputSlotId id)
+ {
+ for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].id == id)
+ return QByteArray(inputSlotMap[i].key);
+ }
+ return QByteArray();
+ }
+
+ static int inputSlotIdToWindowsId(QPrint::InputSlotId id)
+ {
+ for (int i = 0; inputSlotMap[i].id != QPrint::CustomInputSlot; ++i) {
+ if (inputSlotMap[i].id == id)
+ return inputSlotMap[i].windowsId;
+ }
+ return 0;
+ }
+
+ static QPrint::OutputBinId outputBinKeyToOutputBinId(const QByteArray &key)
+ {
+ for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
+ if (outputBinMap[i].key == key)
+ return outputBinMap[i].id;
+ }
+ return QPrint::CustomOutputBin;
+ }
+
+ static QByteArray outputBinIdToOutputBinKey(QPrint::OutputBinId id)
+ {
+ for (int i = 0; outputBinMap[i].id != QPrint::CustomOutputBin; ++i) {
+ if (outputBinMap[i].id == id)
+ return QByteArray(outputBinMap[i].key);
+ }
+ return QByteArray();
+ }
+
+#if (defined Q_OS_MAC && !defined Q_OS_IOS) || (defined Q_OS_UNIX && !defined QT_NO_CUPS)
+
+ // PPD utilities shared by CUPS and Mac plugins requiring CUPS headers
+ // May turn into a proper internal QPpd class if enough shared between Mac and CUPS,
+ // but where would it live? Not in base module as don't want to link to CUPS.
+ // May have to have two copies in plugins to keep in sync.
+
+ static QPrint::InputSlot ppdChoiceToInputSlot(ppd_choice_t choice)
+ {
+ QPrint::InputSlot input;
+ input.key = choice.choice;
+ input.name = QString::fromUtf8(choice.text);
+ input.id = inputSlotKeyToInputSlotId(input.key);
+ input.windowsId = inputSlotMap[input.id].windowsId;
+ return input;
+ }
+
+ static QPrint::OutputBin ppdChoiceToOutputBin(ppd_choice_t choice)
+ {
+ QPrint::OutputBin output;
+ output.key = choice.choice;
+ output.name = QString::fromUtf8(choice.text);
+ output.id = outputBinKeyToOutputBinId(output.key);
+ return output;
+ }
+
+ static int parsePpdResolution(const QByteArray &value)
+ {
+ if (value.isEmpty())
+ return -1;
+ // value can be in form 600dpi or 600x600dpi
+ QByteArray result = value.split('x').at(0);
+ if (result.endsWith("dpi"))
+ result.chop(3);
+ return result.toInt();
+ }
+
+ static QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice)
+ {
+ if (choice == QByteArrayLiteral("DuplexTumble"))
+ return QPrint::DuplexShortSide;
+ else if (choice == QByteArrayLiteral("DuplexNoTumble"))
+ return QPrint::DuplexLongSide;
+ else // None or SimplexTumble or SimplexNoTumble
+ return QPrint::DuplexNone;
+ }
+
+#endif // Mac and CUPS PPD Utilities
+
+};
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
+
+#endif // QPRINT_P_H
diff --git a/src/printsupport/kernel/qprintdevice.cpp b/src/printsupport/kernel/qprintdevice.cpp
new file mode 100644
index 0000000000..eb0af455ee
--- /dev/null
+++ b/src/printsupport/kernel/qprintdevice.cpp
@@ -0,0 +1,255 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 John Layt <jlayt@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtPrintSupport module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qprintdevice_p.h"
+#include "qplatformprintdevice.h"
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PRINTER
+
+QPrintDevice::QPrintDevice()
+ : d(new QPlatformPrintDevice())
+{
+}
+
+QPrintDevice::QPrintDevice(const QString &id)
+ : d(new QPlatformPrintDevice(id))
+{
+}
+
+QPrintDevice::QPrintDevice(QPlatformPrintDevice *dd)
+ : d(dd)
+{
+}
+
+QPrintDevice::QPrintDevice(const QPrintDevice &other)
+ : d(other.d)
+{
+}
+
+QPrintDevice::~QPrintDevice()
+{
+}
+
+QPrintDevice &QPrintDevice::operator=(const QPrintDevice &other)
+{
+ d = other.d;
+ return *this;
+}
+
+bool QPrintDevice::operator==(const QPrintDevice &other) const
+{
+ if (d && other.d)
+ return *d == *other.d;
+ return d == other.d;
+}
+
+QString QPrintDevice::id() const
+{
+ return isValid() ? d->id() : QString();
+}
+
+QString QPrintDevice::name() const
+{
+ return isValid() ? d->name() : QString();
+}
+
+QString QPrintDevice::location() const
+{
+ return isValid() ? d->location() : QString();
+}
+
+QString QPrintDevice::makeAndModel() const
+{
+ return isValid() ? d->makeAndModel() : QString();
+}
+
+bool QPrintDevice::isValid() const
+{
+ return d && d->isValid();
+}
+
+bool QPrintDevice::isDefault() const
+{
+ return isValid() && d->isDefault();
+}
+
+bool QPrintDevice::isRemote() const
+{
+ return isValid() && d->isRemote();
+}
+
+QPrint::DeviceState QPrintDevice::state() const
+{
+ return isValid() ? d->state() : QPrint::Error;
+}
+
+bool QPrintDevice::isValidPageLayout(const QPageLayout &layout, int resolution) const
+{
+ return isValid() && d->isValidPageLayout(layout, resolution);
+}
+
+bool QPrintDevice::supportsMultipleCopies() const
+{
+ return isValid() && d->supportsMultipleCopies();
+}
+
+bool QPrintDevice::supportsCollateCopies() const
+{
+ return isValid() && d->supportsCollateCopies();
+}
+
+QPageSize QPrintDevice::defaultPageSize() const
+{
+ return isValid() ? d->defaultPageSize() : QPageSize();
+}
+
+QList<QPageSize> QPrintDevice::supportedPageSizes() const
+{
+ return isValid() ? d->supportedPageSizes() : QList<QPageSize>();
+}
+
+QPageSize QPrintDevice::supportedPageSize(const QPageSize &pageSize) const
+{
+ return isValid() ? d->supportedPageSize(pageSize) : QPageSize();
+}
+
+QPageSize QPrintDevice::supportedPageSize(QPageSize::PageSizeId pageSizeId) const
+{
+ return isValid() ? d->supportedPageSize(pageSizeId) : QPageSize();
+}
+
+QPageSize QPrintDevice::supportedPageSize(const QString &pageName) const
+{
+ return isValid() ? d->supportedPageSize(pageName) : QPageSize();
+}
+
+QPageSize QPrintDevice::supportedPageSize(const QSize &pointSize) const
+{
+ return isValid() ? d->supportedPageSize(pointSize) : QPageSize();
+}
+
+QPageSize QPrintDevice::supportedPageSize(const QSizeF &size, QPageSize::Unit units) const
+{
+ return isValid() ? d->supportedPageSize(size, units) : QPageSize();
+}
+
+bool QPrintDevice::supportsCustomPageSizes() const
+{
+ return isValid() && d->supportsCustomPageSizes();
+}
+
+QSize QPrintDevice::minimumPhysicalPageSize() const
+{
+ return isValid() ? d->minimumPhysicalPageSize() : QSize();
+}
+
+QSize QPrintDevice::maximumPhysicalPageSize() const
+{
+ return isValid() ? d->maximumPhysicalPageSize() : QSize();
+}
+
+QMarginsF QPrintDevice::printableMargins(const QPageSize &pageSize,
+ QPageLayout::Orientation orientation,
+ int resolution) const
+{
+ return isValid() ? d->printableMargins(pageSize, orientation, resolution) : QMarginsF();
+}
+
+int QPrintDevice::defaultResolution() const
+{
+ return isValid() ? d->defaultResolution() : 0;
+}
+
+QList<int> QPrintDevice::supportedResolutions() const
+{
+ return isValid() ? d->supportedResolutions() : QList<int>();
+}
+
+QPrint::InputSlot QPrintDevice::defaultInputSlot() const
+{
+ return isValid() ? d->defaultInputSlot() : QPrint::InputSlot();
+}
+
+QList<QPrint::InputSlot> QPrintDevice::supportedInputSlots() const
+{
+ return isValid() ? d->supportedInputSlots() : QList<QPrint::InputSlot>();
+}
+
+QPrint::OutputBin QPrintDevice::defaultOutputBin() const
+{
+ return isValid() ? d->defaultOutputBin() : QPrint::OutputBin();
+}
+
+QList<QPrint::OutputBin> QPrintDevice::supportedOutputBins() const
+{
+ return isValid() ? d->supportedOutputBins() : QList<QPrint::OutputBin>();
+}
+
+QPrint::DuplexMode QPrintDevice::defaultDuplexMode() const
+{
+ return isValid() ? d->defaultDuplexMode() : QPrint::DuplexNone;
+}
+
+QList<QPrint::DuplexMode> QPrintDevice::supportedDuplexModes() const
+{
+ return isValid() ? d->supportedDuplexModes() : QList<QPrint::DuplexMode>();
+}
+
+QPrint::ColorMode QPrintDevice::defaultColorMode() const
+{
+ return isValid() ? d->defaultColorMode() : QPrint::GrayScale;
+}
+
+QList<QPrint::ColorMode> QPrintDevice::supportedColorModes() const
+{
+ return isValid() ? d->supportedColorModes() : QList<QPrint::ColorMode>();
+}
+
+QList<QMimeType> QPrintDevice::supportedMimeTypes() const
+{
+ return isValid() ? d->supportedMimeTypes() : QList<QMimeType>();
+}
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qprintdevice_p.h b/src/printsupport/kernel/qprintdevice_p.h
new file mode 100644
index 0000000000..4d63d46aeb
--- /dev/null
+++ b/src/printsupport/kernel/qprintdevice_p.h
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 John Layt <jlayt@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtPrintSupport module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTDEVICE_H
+#define QPRINTDEVICE_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of internal files. This header file may change from version to version
+// without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qprint_p.h"
+
+#include <QtCore/qsharedpointer.h>
+#include <QtGui/qpagelayout.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PRINTER
+
+class QPlatformPrintDevice;
+class QMarginsF;
+class QMimeType;
+
+class Q_PRINTSUPPORT_EXPORT QPrintDevice
+{
+public:
+
+ QPrintDevice();
+ QPrintDevice(const QString & id);
+ QPrintDevice(const QPrintDevice &other);
+ ~QPrintDevice();
+
+ QPrintDevice &operator=(const QPrintDevice &other);
+ #ifdef Q_COMPILER_RVALUE_REFS
+ QPrintDevice &operator=(QPrintDevice &&other) { swap(other); return *this; }
+#endif
+
+ void swap(QPrintDevice &other) { d.swap(other.d); }
+
+ bool operator==(const QPrintDevice &other) const;
+
+ QString id() const;
+ QString name() const;
+ QString location() const;
+ QString makeAndModel() const;
+
+ bool isValid() const;
+ bool isDefault() const;
+ bool isRemote() const;
+
+ QPrint::DeviceState state() const;
+
+ bool isValidPageLayout(const QPageLayout &layout, int resolution) const;
+
+ bool supportsMultipleCopies() const;
+ bool supportsCollateCopies() const;
+
+ QPageSize defaultPageSize() const;
+ QList<QPageSize> supportedPageSizes() const;
+
+ QPageSize supportedPageSize(const QPageSize &pageSize) const;
+ QPageSize supportedPageSize(QPageSize::PageSizeId pageSizeId) const;
+ QPageSize supportedPageSize(const QString &pageName) const;
+ QPageSize supportedPageSize(const QSize &pointSize) const;
+ QPageSize supportedPageSize(const QSizeF &size, QPageSize::Unit units = QPageSize::Point) const;
+
+ bool supportsCustomPageSizes() const;
+
+ QSize minimumPhysicalPageSize() const;
+ QSize maximumPhysicalPageSize() const;
+
+ QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation, int resolution) const;
+
+ int defaultResolution() const;
+ QList<int> supportedResolutions() const;
+
+ QPrint::InputSlot defaultInputSlot() const;
+ QList<QPrint::InputSlot> supportedInputSlots() const;
+
+ QPrint::OutputBin defaultOutputBin() const;
+ QList<QPrint::OutputBin> supportedOutputBins() const;
+
+ QPrint::DuplexMode defaultDuplexMode() const;
+ QList<QPrint::DuplexMode> supportedDuplexModes() const;
+
+ QPrint::ColorMode defaultColorMode() const;
+ QList<QPrint::ColorMode> supportedColorModes() const;
+
+ QList<QMimeType> supportedMimeTypes() const;
+
+private:
+ friend class QPlatformPrinterSupport;
+ friend class QPlatformPrintDevice;
+ QPrintDevice(QPlatformPrintDevice *dd);
+ QSharedDataPointer<QPlatformPrintDevice> d;
+};
+
+Q_DECLARE_SHARED(QPrintDevice)
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
+
+#endif // QPLATFORMPRINTDEVICE_H
diff --git a/src/printsupport/kernel/qprintengine.h b/src/printsupport/kernel/qprintengine.h
index 3993a22bef..a69fe01fd4 100644
--- a/src/printsupport/kernel/qprintengine.h
+++ b/src/printsupport/kernel/qprintengine.h
@@ -45,6 +45,8 @@
#include <QtCore/qvariant.h>
#include <QtPrintSupport/qprinter.h>
+Q_DECLARE_METATYPE(QMarginsF)
+
QT_BEGIN_NAMESPACE
@@ -85,6 +87,9 @@ public:
PPK_CopyCount,
PPK_SupportsMultipleCopies,
PPK_PaperName,
+ PPK_QPageSize,
+ PPK_QPageMargins,
+ PPK_QPageLayout,
PPK_PaperSize = PPK_PageSize,
PPK_CustomBase = 0xff00
diff --git a/src/printsupport/kernel/qprintengine_pdf.cpp b/src/printsupport/kernel/qprintengine_pdf.cpp
index 6c65300462..a2ab68a96d 100644
--- a/src/printsupport/kernel/qprintengine_pdf.cpp
+++ b/src/printsupport/kernel/qprintengine_pdf.cpp
@@ -48,6 +48,7 @@
#include <qdebug.h>
#include <qbuffer.h>
#include "qprinterinfo.h"
+#include <QtGui/qpagelayout.h>
#include <limits.h>
#include <math.h>
@@ -63,34 +64,6 @@
QT_BEGIN_NAMESPACE
-//#define FONT_DUMP
-
-extern QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size);
-
-#define Q_MM(n) int((n * 720 + 127) / 254)
-#define Q_IN(n) int(n * 72)
-
-static const char * const psToStr[QPrinter::NPageSize+1] =
-{
- "A4", "B5", "Letter", "Legal", "Executive",
- "A0", "A1", "A2", "A3", "A5", "A6", "A7", "A8", "A9", "B0", "B1",
- "B10", "B2", "B3", "B4", "B6", "B7", "B8", "B9", "C5E", "Comm10E",
- "DLE", "Folio", "Ledger", "Tabloid", 0
-};
-
-QPdf::PaperSize QPdf::paperSize(QPrinter::PaperSize paperSize)
-{
- QSizeF s = qt_paperSizeToQSizeF(paperSize);
- PaperSize p = { Q_MM(s.width()), Q_MM(s.height()) };
- return p;
-}
-
-const char *QPdf::paperSizeToString(QPrinter::PaperSize paperSize)
-{
- return psToStr[paperSize];
-}
-
-
QPdfPrintEngine::QPdfPrintEngine(QPrinter::PrinterMode m)
: QPdfEngine(*new QPdfPrintEnginePrivate(m))
{
@@ -163,10 +136,6 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
// The following keys are settings that are unsupported by the PDF PrintEngine
case PPK_CustomBase:
break;
- case PPK_PaperName:
- break;
- case PPK_WindowsPageSize:
- break;
// The following keys are properties and settings that are supported by the PDF PrintEngine
case PPK_CollateCopies:
@@ -182,14 +151,17 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
d->title = value.toString();
break;
case PPK_FullPage:
- d->fullPage = value.toBool();
+ if (value.toBool())
+ d->m_pageLayout.setMode(QPageLayout::FullPageMode);
+ else
+ d->m_pageLayout.setMode(QPageLayout::StandardMode);
break;
case PPK_CopyCount: // fallthrough
case PPK_NumberOfCopies:
d->copies = value.toInt();
break;
case PPK_Orientation:
- d->landscape = (QPrinter::Orientation(value.toInt()) == QPrinter::Landscape);
+ d->m_pageLayout.setOrientation(QPageLayout::Orientation(value.toInt()));
break;
case PPK_OutputFileName:
d->outputFileName = value.toString();
@@ -197,9 +169,25 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
case PPK_PageOrder:
d->pageOrder = QPrinter::PageOrder(value.toInt());
break;
- case PPK_PaperSize:
- d->printerPaperSize = QPrinter::PaperSize(value.toInt());
- d->updatePaperSize();
+ case PPK_PageSize: {
+ QPageSize pageSize = QPageSize(QPageSize::PageSizeId(value.toInt()));
+ if (pageSize.isValid())
+ d->m_pageLayout.setPageSize(pageSize);
+ break;
+ }
+ case PPK_PaperName: {
+ QString name = value.toString();
+ for (int i = 0; i <= QPageSize::LastPageSize; ++i) {
+ QPageSize pageSize = QPageSize(QPageSize::PageSizeId(i));
+ if (name == pageSize.name()) {
+ d->m_pageLayout.setPageSize(pageSize);
+ break;
+ }
+ }
+ break;
+ }
+ case PPK_WindowsPageSize:
+ d->m_pageLayout.setPageSize(QPageSize(QPageSize::id(value.toInt())));
break;
case PPK_PaperSource:
d->paperSource = QPrinter::PaperSource(value.toInt());
@@ -220,22 +208,35 @@ void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va
d->embedFonts = value.toBool();
break;
case PPK_Duplex:
- d->duplex = static_cast<QPrinter::DuplexMode> (value.toInt());
+ d->duplex = static_cast<QPrint::DuplexMode>(value.toInt());
break;
case PPK_CustomPaperSize:
- d->printerPaperSize = QPrinter::Custom;
- d->customPaperSize = value.toSizeF();
- d->updatePaperSize();
+ d->m_pageLayout.setPageSize(QPageSize(value.toSizeF(), QPageSize::Point));
break;
- case PPK_PageMargins:
- {
+ case PPK_PageMargins: {
QList<QVariant> margins(value.toList());
Q_ASSERT(margins.size() == 4);
- d->leftMargin = margins.at(0).toReal();
- d->topMargin = margins.at(1).toReal();
- d->rightMargin = margins.at(2).toReal();
- d->bottomMargin = margins.at(3).toReal();
- d->pageMarginsSet = true;
+ d->m_pageLayout.setUnits(QPageLayout::Point);
+ d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
+ margins.at(2).toReal(), margins.at(3).toReal()));
+ break;
+ }
+ case PPK_QPageSize: {
+ QPageSize pageSize = value.value<QPageSize>();
+ if (pageSize.isValid())
+ d->m_pageLayout.setPageSize(pageSize);
+ break;
+ }
+ case PPK_QPageMargins: {
+ QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >();
+ d->m_pageLayout.setUnits(pair.second);
+ d->m_pageLayout.setMargins(pair.first);
+ break;
+ }
+ case PPK_QPageLayout: {
+ QPageLayout pageLayout = value.value<QPageLayout>();
+ if (pageLayout.isValid())
+ d->m_pageLayout = pageLayout;
break;
}
// No default so that compiler will complain if new keys added and not handled in this engine
@@ -254,12 +255,6 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
case PPK_CustomBase:
// Special case, leave null
break;
- case PPK_PaperName:
- ret = QString();
- break;
- case PPK_WindowsPageSize:
- // Special case, leave null
- break;
// The following keys are properties and settings that are supported by the PDF PrintEngine
case PPK_CollateCopies:
@@ -275,7 +270,7 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
ret = d->title;
break;
case PPK_FullPage:
- ret = d->fullPage;
+ ret = d->m_pageLayout.mode() == QPageLayout::FullPageMode;
break;
case PPK_CopyCount:
ret = d->copies;
@@ -287,7 +282,7 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
ret = d->copies;
break;
case PPK_Orientation:
- ret = d->landscape ? QPrinter::Landscape : QPrinter::Portrait;
+ ret = d->m_pageLayout.orientation();
break;
case PPK_OutputFileName:
ret = d->outputFileName;
@@ -295,8 +290,14 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
case PPK_PageOrder:
ret = d->pageOrder;
break;
- case PPK_PaperSize:
- ret = d->printerPaperSize;
+ case PPK_PageSize:
+ ret = d->m_pageLayout.pageSize().id();
+ break;
+ case PPK_PaperName:
+ ret = d->m_pageLayout.pageSize().name();
+ break;
+ case PPK_WindowsPageSize:
+ ret = d->m_pageLayout.pageSize().windowsId();
break;
case PPK_PaperSource:
ret = d->paperSource;
@@ -314,10 +315,10 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
ret = QList<QVariant>() << 72;
break;
case PPK_PaperRect:
- ret = d->paperRect();
+ ret = d->m_pageLayout.fullRectPixels(d->resolution);
break;
case PPK_PageRect:
- ret = d->pageRect();
+ ret = d->m_pageLayout.paintRectPixels(d->resolution);
break;
case PPK_SelectionOption:
ret = d->selectionOption;
@@ -329,19 +330,26 @@ QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
ret = d->duplex;
break;
case PPK_CustomPaperSize:
- ret = d->customPaperSize;
+ ret = d->m_pageLayout.fullRectPoints().size();
break;
- case PPK_PageMargins:
- {
- QList<QVariant> margins;
- if (d->printerPaperSize == QPrinter::Custom && !d->pageMarginsSet)
- margins << 0 << 0 << 0 << 0;
- else
- margins << d->leftMargin << d->topMargin
- << d->rightMargin << d->bottomMargin;
- ret = margins;
+ case PPK_PageMargins: {
+ QList<QVariant> list;
+ QMarginsF margins = d->m_pageLayout.margins(QPageLayout::Point);
+ list << margins.left() << margins.top() << margins.right() << margins.bottom();
+ ret = list;
+ break;
+ }
+ case PPK_QPageSize:
+ ret.setValue(d->m_pageLayout.pageSize());
+ break;
+ case PPK_QPageMargins: {
+ QPair<QMarginsF, QPageLayout::Unit> pair = qMakePair(d->m_pageLayout.margins(), d->m_pageLayout.units());
+ ret.setValue(pair);
break;
}
+ case PPK_QPageLayout:
+ ret.setValue(d->m_pageLayout);
+ break;
// No default so that compiler will complain if new keys added and not handled in this engine
}
return ret;
@@ -385,13 +393,11 @@ void QPdfPrintEnginePrivate::closePrintDevice()
QPdfPrintEnginePrivate::QPdfPrintEnginePrivate(QPrinter::PrinterMode m)
: QPdfEnginePrivate(),
- duplex(QPrinter::DuplexNone),
+ duplex(QPrint::DuplexNone),
collate(true),
copies(1),
pageOrder(QPrinter::FirstPageFirst),
paperSource(QPrinter::Auto),
- printerPaperSize(QPrinter::A4),
- pageMarginsSet(false),
fd(-1)
{
resolution = 72;
@@ -405,18 +411,6 @@ QPdfPrintEnginePrivate::~QPdfPrintEnginePrivate()
{
}
-
-void QPdfPrintEnginePrivate::updatePaperSize()
-{
- if (printerPaperSize == QPrinter::Custom) {
- paperSize = customPaperSize;
- } else {
- QPdf::PaperSize s = QPdf::paperSize(printerPaperSize);
- paperSize = QSize(s.width, s.height);
- }
-}
-
-
QT_END_NAMESPACE
#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprintengine_pdf_p.h b/src/printsupport/kernel/qprintengine_pdf_p.h
index eec6d48181..80d81b4ed3 100644
--- a/src/printsupport/kernel/qprintengine_pdf_p.h
+++ b/src/printsupport/kernel/qprintengine_pdf_p.h
@@ -68,6 +68,7 @@
#include "private/qpdf_p.h"
#include "private/qpaintengine_p.h"
#include "qprintengine.h"
+#include "qprint_p.h"
QT_BEGIN_NAMESPACE
@@ -77,16 +78,6 @@ class QPen;
class QPointF;
class QRegion;
class QFile;
-class QPdfPrintEngine;
-
-namespace QPdf {
-
- struct PaperSize {
- int width, height; // in postscript points
- };
- Q_PRINTSUPPORT_EXPORT PaperSize paperSize(QPrinter::PaperSize paperSize);
- Q_PRINTSUPPORT_EXPORT const char *paperSizeToString(QPrinter::PaperSize paperSize);
-}
class QPdfPrintEnginePrivate;
@@ -131,8 +122,6 @@ public:
virtual bool openPrintDevice();
virtual void closePrintDevice();
- virtual void updatePaperSize();
-
private:
Q_DISABLE_COPY(QPdfPrintEnginePrivate)
@@ -143,15 +132,12 @@ private:
QString printProgram;
QString selectionOption;
- QPrinter::DuplexMode duplex;
+ QPrint::DuplexMode duplex;
bool collate;
int copies;
QPrinter::PageOrder pageOrder;
QPrinter::PaperSource paperSource;
- QPrinter::PaperSize printerPaperSize;
- QSizeF customPaperSize; // in postscript points
- bool pageMarginsSet;
int fd;
};
diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp
index 02b5d824f4..52b67d162b 100644
--- a/src/printsupport/kernel/qprintengine_win.cpp
+++ b/src/printsupport/kernel/qprintengine_win.cpp
@@ -50,6 +50,9 @@
#include <private/qfontengine_p.h>
#include <private/qpainter_p.h>
+#include <qpa/qplatformprintplugin.h>
+#include <qpa/qplatformprintersupport.h>
+
#include <qbitmap.h>
#include <qdebug.h>
#include <qvector.h>
@@ -59,6 +62,7 @@
#include <private/qpixmap_raster_p.h>
#include <QtCore/QMetaType>
#include <QtCore/qt_windows.h>
+#include <QtGui/qpagelayout.h>
Q_DECLARE_METATYPE(HFONT)
Q_DECLARE_METATYPE(LOGFONT)
@@ -67,164 +71,14 @@ QT_BEGIN_NAMESPACE
Q_GUI_EXPORT HBITMAP qt_pixmapToWinHBITMAP(const QPixmap &p, int hbitmapFormat = 0);
extern QPainterPath qt_regionToPath(const QRegion &region);
-Q_PRINTSUPPORT_EXPORT QSizeF qt_SizeFromUnitToMillimeter(const QSizeF &, QPrinter::Unit, double);
-Q_PRINTSUPPORT_EXPORT double qt_multiplierForUnit(QPrinter::Unit unit, int resolution);
+extern QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits);
// #define QT_DEBUG_DRAW
+// #define QT_DEBUG_METRICS
static void draw_text_item_win(const QPointF &_pos, const QTextItemInt &ti, HDC hdc,
bool convertToText, const QTransform &xform, const QPointF &topLeft);
-static const struct {
- int winSizeName;
- QPrinter::PaperSize qtSizeName;
-} dmMapping[] = {
- { DMPAPER_LETTER, QPrinter::Letter },
- { DMPAPER_LETTERSMALL, QPrinter::Letter },
- { DMPAPER_TABLOID, QPrinter::Tabloid },
- { DMPAPER_LEDGER, QPrinter::Ledger },
- { DMPAPER_LEGAL, QPrinter::Legal },
- { DMPAPER_EXECUTIVE, QPrinter::Executive },
- { DMPAPER_A3, QPrinter::A3 },
- { DMPAPER_A4, QPrinter::A4 },
- { DMPAPER_A4SMALL, QPrinter::A4 },
- { DMPAPER_A5, QPrinter::A5 },
- { DMPAPER_B4, QPrinter::B4 },
- { DMPAPER_B5, QPrinter::B5 },
- { DMPAPER_A4_PLUS, QPrinter::Folio },
- { DMPAPER_ENV_10, QPrinter::Comm10E },
- { DMPAPER_ENV_DL, QPrinter::DLE },
- { DMPAPER_ENV_C3, QPrinter::C5E },
- { DMPAPER_LETTER_EXTRA, QPrinter::Letter },
- { DMPAPER_LEGAL_EXTRA, QPrinter::Legal },
- { DMPAPER_TABLOID_EXTRA, QPrinter::Tabloid },
- { DMPAPER_A4_EXTRA, QPrinter::A4},
- { DMPAPER_LETTER_TRANSVERSE, QPrinter::Letter},
- { DMPAPER_A4_TRANSVERSE, QPrinter::A4},
- { DMPAPER_LETTER_EXTRA_TRANSVERSE, QPrinter::Letter },
- { DMPAPER_A_PLUS, QPrinter::A4 },
- { DMPAPER_B_PLUS, QPrinter::A3 },
- { DMPAPER_LETTER_PLUS, QPrinter::Letter },
- { DMPAPER_A5_TRANSVERSE, QPrinter::A5 },
- { DMPAPER_B5_TRANSVERSE, QPrinter::B5 },
- { DMPAPER_A3_EXTRA, QPrinter::A3 },
- { DMPAPER_A5_EXTRA, QPrinter::A5 },
- { DMPAPER_B5_EXTRA, QPrinter::B5 },
- { DMPAPER_A2, QPrinter::A2 },
- { DMPAPER_A3_TRANSVERSE, QPrinter::A3 },
- { DMPAPER_A3_EXTRA_TRANSVERSE,QPrinter::A3 },
- { 0, QPrinter::Custom }
-};
-
-// Return a list of printer paper sizes in millimeters with the corresponding dmPaperSize value
-static QList<QPair<QSizeF, int> > printerPaperSizes(const QString &printerName)
-{
- QList<QPair<QSizeF, int> > result;
- const wchar_t *name = reinterpret_cast<const wchar_t*>(printerName.utf16());
- DWORD paperNameCount = DeviceCapabilities(name, NULL, DC_PAPERS, NULL, NULL);
- if ((int)paperNameCount > 0) {
- // If they are not equal, then there seems to be a problem with the driver
- if (paperNameCount != DeviceCapabilities(name, NULL, DC_PAPERSIZE, NULL, NULL))
- return result;
- QScopedArrayPointer<wchar_t> papersNames(new wchar_t[paperNameCount]);
- paperNameCount = DeviceCapabilities(name, NULL, DC_PAPERS, papersNames.data(), NULL);
- result.reserve(paperNameCount);
- QScopedArrayPointer<POINT> paperSizes(new POINT[paperNameCount]);
- paperNameCount = DeviceCapabilities(name, NULL, DC_PAPERSIZE, (wchar_t *)paperSizes.data(), NULL);
- for (int i=0; i <(int)paperNameCount; i++)
- result.push_back(qMakePair(QSizeF(paperSizes[i].x / 10, paperSizes[i].y / 10), papersNames[i]));
- }
- return result;
-}
-
-// Find the best-matching printer paper for size in millimeters.
-static inline int findCustomPaperSize(const QSizeF &needlePt, const QString &printerName)
-{
- const QList<QPair<QSizeF, int> > sizes = printerPaperSizes(printerName);
- const qreal nw = needlePt.width();
- const qreal nh = needlePt.height();
- for (int i = 0; i < sizes.size(); ++i) {
- if (qAbs(nw - sizes.at(i).first.width()) <= 1 && qAbs(nh - sizes.at(i).first.height()) <= 1)
- return sizes.at(i).second;
- }
- return -1;
-}
-
-static inline void setDevModePaperFlags(DEVMODE *devMode, bool custom)
-{
- if (custom) {
- devMode->dmPaperSize = DMPAPER_USER;
- devMode->dmFields |= DM_PAPERLENGTH | DM_PAPERWIDTH;
- } else {
- devMode->dmFields &= ~(DM_PAPERLENGTH | DM_PAPERWIDTH);
- devMode->dmPaperLength = 0;
- devMode->dmPaperWidth = 0;
- }
-}
-
-QPrinter::PaperSize mapDevmodePaperSize(int s)
-{
- int i = 0;
- while ((dmMapping[i].winSizeName > 0) && (dmMapping[i].winSizeName != s))
- i++;
- return dmMapping[i].qtSizeName;
-}
-
-static int mapPaperSizeDevmode(QPrinter::PaperSize s)
-{
- int i = 0;
- while ((dmMapping[i].winSizeName > 0) && (dmMapping[i].qtSizeName != s))
- i++;
- return dmMapping[i].winSizeName;
-}
-
-static const struct {
- int winSourceName;
- QPrinter::PaperSource qtSourceName;
-} sources[] = {
- { DMBIN_UPPER, QPrinter::Upper }, // = DBMIN_ONLYONE
- { DMBIN_LOWER, QPrinter::Lower },
- { DMBIN_MIDDLE, QPrinter::Middle },
- { DMBIN_MANUAL, QPrinter::Manual },
- { DMBIN_ENVELOPE, QPrinter::Envelope },
- { DMBIN_ENVMANUAL, QPrinter::EnvelopeManual },
- { DMBIN_AUTO, QPrinter::Auto },
- { DMBIN_TRACTOR, QPrinter::Tractor },
- { DMBIN_SMALLFMT, QPrinter::SmallFormat },
- { DMBIN_LARGEFMT, QPrinter::LargeFormat },
- { DMBIN_LARGECAPACITY, QPrinter::LargeCapacity },
- { DMBIN_CASSETTE, QPrinter::Cassette },
- { DMBIN_FORMSOURCE, QPrinter::FormSource },
- { DMBIN_USER, QPrinter::CustomSource },
- { 0, (QPrinter::PaperSource) -1 }
-};
-
-static QPrinter::PaperSource mapDevmodePaperSource(int s)
-{
- int i = 0;
- while ((sources[i].winSourceName > 0) && (sources[i].winSourceName != s))
- i++;
- return sources[i].winSourceName ? sources[i].qtSourceName : (QPrinter::PaperSource) s;
-}
-
-static int mapPaperSourceDevmode(QPrinter::PaperSource s)
-{
- int i = 0;
- while ((sources[i].qtSourceName >= 0) && (sources[i].qtSourceName != s))
- i++;
- return sources[i].winSourceName ? sources[i].winSourceName : s;
-}
-
-static inline uint qwcsnlen(const wchar_t *str, uint maxlen)
-{
- uint length = 0;
- if (str) {
- while (length < maxlen && *str++)
- length++;
- }
- return length;
-}
-
QWin32PrintEngine::QWin32PrintEngine(QPrinter::PrinterMode mode)
: QAlphaPaintEngine(*(new QWin32PrintEnginePrivate),
PaintEngineFeatures(PrimitiveTransform
@@ -236,7 +90,10 @@ QWin32PrintEngine::QWin32PrintEngine(QPrinter::PrinterMode mode)
{
Q_D(QWin32PrintEngine);
d->mode = mode;
- d->queryDefault();
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps)
+ d->m_printDevice = ps->createDefaultPrintDevice();
+ d->m_pageLayout.setPageSize(d->m_printDevice.defaultPageSize());
d->initialize();
}
@@ -301,6 +158,11 @@ bool QWin32PrintEngine::begin(QPaintDevice *pdev)
if (!ok)
cleanUp();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::begin()";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
+
return ok;
}
@@ -363,6 +225,11 @@ bool QWin32PrintEngine::newPage()
if (transparent)
SetBkMode(d->hdc, TRANSPARENT);
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::newPage()";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
+
// ###
return true;
@@ -456,21 +323,11 @@ void QWin32PrintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem
SelectObject(d->hdc, CreatePen(PS_SOLID, 1, cf));
SetTextColor(d->hdc, cf);
- draw_text_item_win(p, ti, d->hdc, convertToText, d->matrix, d->devPaperRect.topLeft());
+ draw_text_item_win(p, ti, d->hdc, convertToText, d->matrix, QPointF(0.0, 0.0));
DeleteObject(SelectObject(d->hdc,GetStockObject(HOLLOW_BRUSH)));
DeleteObject(SelectObject(d->hdc,GetStockObject(BLACK_PEN)));
}
-static inline qreal mmToInches(double mm)
-{
- return mm*0.039370147;
-}
-
-static inline qreal inchesToMM(double in)
-{
- return in/0.039370147;
-}
-
int QWin32PrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const
{
Q_D(const QWin32PrintEngine);
@@ -483,40 +340,18 @@ int QWin32PrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const
switch (m) {
case QPaintDevice::PdmWidth:
- if (d->has_custom_paper_size) {
- val = qRound(d->paper_size.width() * res / 72.0);
- } else {
- int logPixelsX = GetDeviceCaps(d->hdc, LOGPIXELSX);
- if (logPixelsX == 0) {
- qWarning("QWin32PrintEngine::metric: GetDeviceCaps() failed, "
- "might be a driver problem");
- logPixelsX = 600; // Reasonable default
- }
- val = res
- * GetDeviceCaps(d->hdc, d->fullPage ? PHYSICALWIDTH : HORZRES)
- / logPixelsX;
- }
- if (d->pageMarginsSet)
- val -= int(mmToInches((d->previousDialogMargins.left() +
- d->previousDialogMargins.width()) / 100.0) * res);
+ val = d->m_paintRectPixels.width();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::metric(PdmWidth) = " << val;
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
break;
case QPaintDevice::PdmHeight:
- if (d->has_custom_paper_size) {
- val = qRound(d->paper_size.height() * res / 72.0);
- } else {
- int logPixelsY = GetDeviceCaps(d->hdc, LOGPIXELSY);
- if (logPixelsY == 0) {
- qWarning("QWin32PrintEngine::metric: GetDeviceCaps() failed, "
- "might be a driver problem");
- logPixelsY = 600; // Reasonable default
- }
- val = res
- * GetDeviceCaps(d->hdc, d->fullPage ? PHYSICALHEIGHT : VERTRES)
- / logPixelsY;
- }
- if (d->pageMarginsSet)
- val -= int(mmToInches((d->previousDialogMargins.top() +
- d->previousDialogMargins.height()) / 100.0) * res);
+ val = d->m_paintRectPixels.height();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::metric(PdmHeight) = " << val;
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
break;
case QPaintDevice::PdmDpiX:
val = res;
@@ -531,46 +366,18 @@ int QWin32PrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const
val = GetDeviceCaps(d->hdc, LOGPIXELSY);
break;
case QPaintDevice::PdmWidthMM:
- if (d->has_custom_paper_size) {
- val = qRound(d->paper_size.width()*25.4/72);
- } else {
- if (!d->fullPage) {
- val = GetDeviceCaps(d->hdc, HORZSIZE);
- } else {
- float wi = 25.4 * GetDeviceCaps(d->hdc, PHYSICALWIDTH);
- int logPixelsX = GetDeviceCaps(d->hdc, LOGPIXELSX);
- if (logPixelsX == 0) {
- qWarning("QWin32PrintEngine::metric: GetDeviceCaps() failed, "
- "might be a driver problem");
- logPixelsX = 600; // Reasonable default
- }
- val = qRound(wi / logPixelsX);
- }
- }
- if (d->pageMarginsSet)
- val -= (d->previousDialogMargins.left() +
- d->previousDialogMargins.width()) / 100.0;
+ val = d->m_paintSizeMM.width();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::metric(PdmWidthMM) = " << val;
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
break;
case QPaintDevice::PdmHeightMM:
- if (d->has_custom_paper_size) {
- val = qRound(d->paper_size.height()*25.4/72);
- } else {
- if (!d->fullPage) {
- val = GetDeviceCaps(d->hdc, VERTSIZE);
- } else {
- float hi = 25.4 * GetDeviceCaps(d->hdc, PHYSICALHEIGHT);
- int logPixelsY = GetDeviceCaps(d->hdc, LOGPIXELSY);
- if (logPixelsY == 0) {
- qWarning("QWin32PrintEngine::metric: GetDeviceCaps() failed, "
- "might be a driver problem");
- logPixelsY = 600; // Reasonable default
- }
- val = qRound(hi / logPixelsY);
- }
- }
- if (d->pageMarginsSet)
- val -= (d->previousDialogMargins.top() +
- d->previousDialogMargins.height()) / 100.0;
+ val = d->m_paintSizeMM.height();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::metric(PdmHeightMM) = " << val;
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
break;
case QPaintDevice::PdmNumColors:
{
@@ -1035,11 +842,6 @@ void QWin32PrintEngine::drawPolygon(const QPointF *points, int pointCount, Polyg
d->has_brush = has_brush;
}
-void QWin32PrintEnginePrivate::queryDefault()
-{
- QWin32PrintEngine::queryDefaultPrinter(name);
-}
-
QWin32PrintEnginePrivate::~QWin32PrintEnginePrivate()
{
if (hdc)
@@ -1055,12 +857,12 @@ void QWin32PrintEnginePrivate::initialize()
Q_ASSERT(!devMode);
Q_ASSERT(!pInfo);
- if (name.isEmpty())
+ if (!m_printDevice.isValid())
return;
txop = QTransform::TxNone;
- bool ok = OpenPrinter((LPWSTR)name.utf16(), (LPHANDLE)&hPrinter, 0);
+ bool ok = OpenPrinter((LPWSTR)m_printDevice.id().utf16(), (LPHANDLE)&hPrinter, 0);
if (!ok) {
qErrnoWarning("QWin32PrintEngine::initialize: OpenPrinter failed");
return;
@@ -1086,7 +888,7 @@ void QWin32PrintEnginePrivate::initialize()
}
devMode = pInfo->pDevMode;
- hdc = CreateDC(NULL, reinterpret_cast<const wchar_t *>(name.utf16()), 0, devMode);
+ hdc = CreateDC(NULL, reinterpret_cast<const wchar_t *>(m_printDevice.id().utf16()), 0, devMode);
Q_ASSERT(hPrinter);
Q_ASSERT(pInfo);
@@ -1094,19 +896,15 @@ void QWin32PrintEnginePrivate::initialize()
if (devMode) {
num_copies = devMode->dmCopies;
devMode->dmCollate = DMCOLLATE_TRUE;
+ updatePageLayout();
}
initHDC();
-#ifdef QT_DEBUG_DRAW
- qDebug() << "QWin32PrintEngine::initialize()" << endl
- << " - paperRect" << devPaperRect << endl
- << " - pageRect" << devPageRect << endl
- << " - stretch_x" << stretch_x << endl
- << " - stretch_y" << stretch_y << endl
- << " - origin_x" << origin_x << endl
- << " - origin_y" << origin_y << endl;
-#endif
+#if defined QT_DEBUG_DRAW || defined QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::initialize()";
+ debugMetrics();
+#endif // QT_DEBUG_DRAW || QT_DEBUG_METRICS
}
void QWin32PrintEnginePrivate::initHDC()
@@ -1139,50 +937,6 @@ void QWin32PrintEnginePrivate::initHDC()
default:
break;
}
-
- initDevRects();
-}
-
-void QWin32PrintEnginePrivate::initDevRects()
-{
- devPaperRect = QRect(0, 0,
- GetDeviceCaps(hdc, PHYSICALWIDTH),
- GetDeviceCaps(hdc, PHYSICALHEIGHT));
- devPhysicalPageRect = QRect(GetDeviceCaps(hdc, PHYSICALOFFSETX),
- GetDeviceCaps(hdc, PHYSICALOFFSETY),
- GetDeviceCaps(hdc, HORZRES),
- GetDeviceCaps(hdc, VERTRES));
- if (!pageMarginsSet)
- devPageRect = devPhysicalPageRect;
- else
- devPageRect = devPaperRect.adjusted(qRound(mmToInches(previousDialogMargins.left() / 100.0) * dpi_x),
- qRound(mmToInches(previousDialogMargins.top() / 100.0) * dpi_y),
- -qRound(mmToInches(previousDialogMargins.width() / 100.0) * dpi_x),
- -qRound(mmToInches(previousDialogMargins.height() / 100.0) * dpi_y));
- updateOrigin();
-}
-
-void QWin32PrintEnginePrivate::setPageMargins(int marginLeft, int marginTop, int marginRight, int marginBottom)
-{
- pageMarginsSet = true;
- previousDialogMargins = QRect(marginLeft, marginTop, marginRight, marginBottom);
-
- devPageRect = devPaperRect.adjusted(qRound(mmToInches(marginLeft / 100.0) * dpi_x),
- qRound(mmToInches(marginTop / 100.0) * dpi_y),
- - qRound(mmToInches(marginRight / 100.0) * dpi_x),
- - qRound(mmToInches(marginBottom / 100.0) * dpi_y));
- updateOrigin();
-}
-
-QRect QWin32PrintEnginePrivate::getPageMargins() const
-{
- if (pageMarginsSet)
- return previousDialogMargins;
- else
- return QRect(qRound(inchesToMM(devPhysicalPageRect.left()) * 100.0 / dpi_x),
- qRound(inchesToMM(devPhysicalPageRect.top()) * 100.0 / dpi_y),
- qRound(inchesToMM(devPaperRect.right() - devPhysicalPageRect.right()) * 100.0 / dpi_x),
- qRound(inchesToMM(devPaperRect.bottom() - devPhysicalPageRect.bottom()) * 100.0 / dpi_y));
}
void QWin32PrintEnginePrivate::release()
@@ -1208,63 +962,16 @@ void QWin32PrintEnginePrivate::release()
devMode = 0;
}
-QList<QVariant> QWin32PrintEnginePrivate::queryResolutions() const
-{
- // Read the supported resolutions of the printer.
- QList<QVariant> list;
-
- DWORD numRes = DeviceCapabilities(reinterpret_cast<const wchar_t *>(name.utf16()), NULL,
- DC_ENUMRESOLUTIONS, 0, 0);
- if (numRes == (DWORD)-1)
- return list;
-
- LONG *enumRes = (LONG*)malloc(numRes * 2 * sizeof(LONG));
- DWORD errRes = DeviceCapabilities(reinterpret_cast<const wchar_t *>(name.utf16()), NULL,
- DC_ENUMRESOLUTIONS, (LPWSTR)enumRes, 0);
-
- if (errRes == (DWORD)-1) {
- qErrnoWarning("QWin32PrintEngine::queryResolutions: DeviceCapabilities failed");
- return list;
- }
-
- for (uint i=0; i<numRes; ++i)
- list.append(int(enumRes[i * 2]));
-
- return list;
-}
-
void QWin32PrintEnginePrivate::doReinit()
{
if (state == QPrinter::Active) {
reinit = true;
} else {
resetDC();
- initDevRects();
reinit = false;
}
}
-void QWin32PrintEnginePrivate::updateOrigin()
-{
- if (fullPage) {
- // subtract physical margins to make (0,0) absolute top corner of paper
- // then add user defined margins
- origin_x = -devPhysicalPageRect.x();
- origin_y = -devPhysicalPageRect.y();
- if (pageMarginsSet) {
- origin_x += devPageRect.left();
- origin_y += devPageRect.top();
- }
- } else {
- origin_x = 0;
- origin_y = 0;
- if (pageMarginsSet) {
- origin_x = devPageRect.left() - devPhysicalPageRect.x();
- origin_y = devPageRect.top() - devPhysicalPageRect.y();
- }
- }
-}
-
void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value)
{
Q_D(QWin32PrintEngine);
@@ -1329,8 +1036,15 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
break;
case PPK_FullPage:
- d->fullPage = value.toBool();
- d->updateOrigin();
+ if (value.toBool())
+ d->m_pageLayout.setMode(QPageLayout::FullPageMode);
+ else
+ d->m_pageLayout.setMode(QPageLayout::StandardMode);
+ d->updateMetrics();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_FullPage," << value.toBool() << + ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
break;
case PPK_CopyCount: // fallthrough
@@ -1342,18 +1056,20 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
d->doReinit();
break;
- case PPK_Orientation:
- {
- if (!d->devMode)
- break;
- int orientation = value.toInt() == QPrinter::Landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
- int old_orientation = d->devMode->dmOrientation;
- d->devMode->dmOrientation = orientation;
- if (d->has_custom_paper_size && old_orientation != orientation)
- d->paper_size = QSizeF(d->paper_size.height(), d->paper_size.width());
- d->doReinit();
- }
+ case PPK_Orientation: {
+ if (!d->devMode)
+ break;
+ QPageLayout::Orientation orientation = QPageLayout::Orientation(value.toInt());
+ d->devMode->dmOrientation = orientation == QPageLayout::Landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;
+ d->m_pageLayout.setOrientation(orientation);
+ d->updateMetrics();
+ d->doReinit();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_Orientation," << orientation << ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
break;
+ }
case PPK_OutputFileName:
if (isActive()) {
@@ -1364,130 +1080,166 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
}
break;
- case PPK_PaperSize:
+ case PPK_PageSize: {
if (!d->devMode)
break;
- d->devMode->dmPaperSize = mapPaperSizeDevmode(QPrinter::PaperSize(value.toInt()));
- d->has_custom_paper_size = (QPrinter::PaperSize(value.toInt()) == QPrinter::Custom);
- setDevModePaperFlags(d->devMode, d->has_custom_paper_size);
- d->doReinit();
- break;
-
- case PPK_PaperName:
- {
- if (!d->devMode)
- break;
- const wchar_t *name = reinterpret_cast<const wchar_t*>(d->name.utf16());
- DWORD size = DeviceCapabilities(name, NULL, DC_PAPERNAMES, NULL, NULL);
- if ((int)size > 0) {
- QScopedArrayPointer<wchar_t> paperNames(new wchar_t[size*64]);
- if (size != DeviceCapabilities(name, NULL, DC_PAPERNAMES, paperNames.data(), NULL))
- break;
- int paperPos = -1;
- for (int i = 0; i < (int)size; ++i) {
- wchar_t *copyOfPaper = paperNames.data() + (i * 64);
- if (value.toString() == QString::fromWCharArray(copyOfPaper, qwcsnlen(copyOfPaper, 64))) {
- paperPos = i;
- break;
- }
- }
- size = DeviceCapabilities(name, NULL, DC_PAPERS, NULL, NULL);
- if ((int)size > 0) {
- QScopedArrayPointer<wchar_t> papers(new wchar_t[size]);
- size = DeviceCapabilities(name, NULL, DC_PAPERS, papers.data(), NULL);
- QScopedArrayPointer<POINT> paperSizes(new POINT[size]);
- DWORD paperNameCount = DeviceCapabilities(name, NULL, DC_PAPERSIZE, (wchar_t *)paperSizes.data(), NULL);
- if (paperNameCount == size) {
- const double multiplier = qt_multiplierForUnit(QPrinter::Millimeter, d->resolution);
- d->paper_size = QSizeF((paperSizes[paperPos].x / 10.0) * multiplier, (paperSizes[paperPos].y / 10.0) * multiplier);
- // Our sizes may not match the paper name's size exactly
- // So we treat it as custom so we know the paper size is correct
- d->has_custom_paper_size = true;
- d->devMode->dmPaperSize = papers[paperPos];
- setDevModePaperFlags(d->devMode, false);
- d->doReinit();
- }
- }
- }
+ const QPageSize pageSize = QPageSize(QPageSize::PageSizeId(value.toInt()));
+ if (pageSize.isValid()) {
+ d->setPageSize(pageSize);
+ d->doReinit();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_PageSize," << value.toInt() << ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
}
break;
- case PPK_PaperSource:
- {
- if (!d->devMode)
- break;
- int dmMapped = DMBIN_AUTO;
-
- QList<QVariant> v = property(PPK_PaperSources).toList();
- if (v.contains(value))
- dmMapped = mapPaperSourceDevmode(QPrinter::PaperSource(value.toInt()));
+ }
- d->devMode->dmDefaultSource = dmMapped;
+ case PPK_PaperName: {
+ if (!d->devMode)
+ break;
+ // Get the named page size from the printer if supported
+ const QPageSize pageSize = d->m_printDevice.supportedPageSize(value.toString());
+ if (pageSize.isValid()) {
+ d->setPageSize(pageSize);
d->doReinit();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_PaperName," << value.toString() << ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
}
break;
+ }
- case PPK_PrinterName:
- d->name = value.toString();
- if (d->name.isEmpty())
- d->queryDefault();
- d->initialize();
+ case PPK_PaperSource: {
+ if (!d->devMode)
+ break;
+ QPrint::InputSlotId inputSlotId = QPrint::InputSlotId(value.toInt());
+ foreach (const QPrint::InputSlot &inputSlot, d->m_printDevice.supportedInputSlots()) {
+ if (inputSlot.id == inputSlotId) {
+ d->devMode->dmDefaultSource = inputSlot.windowsId;
+ d->doReinit();
+ break;
+ }
+ }
break;
+ }
- case PPK_Resolution:
- {
- d->resolution = value.toInt();
-
- d->stretch_x = d->dpi_x / double(d->resolution);
- d->stretch_y = d->dpi_y / double(d->resolution);
+ case PPK_PrinterName: {
+ QString id = value.toString();
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (!ps)
+ return;
+ QPrintDevice printDevice = ps->createPrintDevice(id.isEmpty() ? ps->defaultPrintDeviceId() : id);
+ if (printDevice.isValid()) {
+ d->m_printDevice = printDevice;
+ // TODO Do we need to check if the page size is valid on new printer?
+ d->initialize();
}
break;
+ }
- case PPK_WindowsPageSize:
+ case PPK_Resolution: {
+ d->resolution = value.toInt();
+ d->stretch_x = d->dpi_x / double(d->resolution);
+ d->stretch_y = d->dpi_y / double(d->resolution);
+ d->updateMetrics();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_Resolution," << value.toInt() << ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
+ break;
+ }
+
+ case PPK_WindowsPageSize: {
if (!d->devMode)
break;
- d->has_custom_paper_size = false;
- d->devMode->dmPaperSize = value.toInt();
- setDevModePaperFlags(d->devMode, d->has_custom_paper_size);
- d->doReinit();
+ const QPageSize pageSize = QPageSize(QPageSize::id(value.toInt()));
+ if (pageSize.isValid()) {
+ d->setPageSize(pageSize);
+ d->doReinit();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_WindowsPageSize," << value.toInt() << ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
+ break;
+ }
break;
+ }
- case PPK_CustomPaperSize:
- {
- d->has_custom_paper_size = true;
- d->paper_size = value.toSizeF();
+ case PPK_CustomPaperSize: {
if (!d->devMode)
break;
- const QSizeF sizeMM = qt_SizeFromUnitToMillimeter(d->paper_size, QPrinter::Point, d->resolution);
- const int match = findCustomPaperSize(sizeMM, d->name);
- setDevModePaperFlags(d->devMode, (match >= 0) ? false : true);
- if (match >= 0) {
- d->devMode->dmPaperSize = match;
- if (d->devMode->dmOrientation != DMORIENT_PORTRAIT)
- qSwap(d->paper_size.rwidth(), d->paper_size.rheight());
- } else {
- d->devMode->dmPaperLength = qRound(sizeMM.height() * 10.0);
- d->devMode->dmPaperWidth = qRound(sizeMM.width() * 10.0);
+ const QPageSize pageSize = QPageSize(value.toSizeF(), QPageSize::Point);
+ if (pageSize.isValid()) {
+ d->setPageSize(pageSize);
+ d->doReinit();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_CustomPaperSize," << value.toSizeF() << ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
}
- d->doReinit();
break;
}
- case PPK_PageMargins:
- {
+ case PPK_PageMargins: {
QList<QVariant> margins(value.toList());
Q_ASSERT(margins.size() == 4);
- int left, top, right, bottom;
- // specified in 1/100 mm
- left = (margins.at(0).toReal()*25.4/72.0) * 100;
- top = (margins.at(1).toReal()*25.4/72.0) * 100;
- right = (margins.at(2).toReal()*25.4/72.0) * 100;
- bottom = (margins.at(3).toReal()*25.4/72.0) * 100;
- d->setPageMargins(left, top, right, bottom);
+ d->m_pageLayout.setUnits(QPageLayout::Point);
+ d->m_pageLayout.setMargins(QMarginsF(margins.at(0).toReal(), margins.at(1).toReal(),
+ margins.at(2).toReal(), margins.at(3).toReal()));
+ d->updateMetrics();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_PageMargins," << margins << ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
break;
}
- // No default so that compiler will complain if new keys added and not handled in this engine
+ case PPK_QPageSize: {
+ // Get the page size from the printer if supported
+ const QPageSize pageSize = value.value<QPageSize>();
+ if (pageSize.isValid()) {
+ d->setPageSize(pageSize);
+ d->doReinit();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_QPageSize," << pageSize << ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
+ }
+ break;
+ }
+ case PPK_QPageMargins: {
+ QPair<QMarginsF, QPageLayout::Unit> pair = value.value<QPair<QMarginsF, QPageLayout::Unit> >();
+ d->m_pageLayout.setUnits(pair.second);
+ d->m_pageLayout.setMargins(pair.first);
+ d->updateMetrics();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_QPageMargins," << pair.first << pair.second << ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
+ break;
+ }
+
+ case PPK_QPageLayout: {
+ QPageLayout pageLayout = value.value<QPageLayout>();
+ if (pageLayout.isValid() && d->m_printDevice.isValidPageLayout(pageLayout, d->resolution)) {
+ setProperty(PPK_QPageSize, QVariant::fromValue(pageLayout.pageSize()));
+ setProperty(PPK_FullPage, pageLayout.mode() == QPageLayout::FullPageMode);
+ setProperty(PPK_Orientation, QVariant::fromValue(pageLayout.orientation()));
+ d->m_pageLayout.setUnits(pageLayout.units());
+ d->m_pageLayout.setMargins(pageLayout.margins());
+ d->updateMetrics();
+#ifdef QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setProperty(PPK_QPageLayout," << pageLayout << ")";
+ d->debugMetrics();
+#endif // QT_DEBUG_METRICS
+ }
+ break;
+ }
+
+ // No default so that compiler will complain if new keys added and not handled in this engine
}
}
@@ -1540,7 +1292,7 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const
break;
case PPK_FullPage:
- value = d->fullPage;
+ value = d->m_pageLayout.mode() == QPageLayout::FullPageMode;
break;
case PPK_CopyCount:
@@ -1556,13 +1308,7 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const
break;
case PPK_Orientation:
- {
- if (!d->devMode) {
- value = QPrinter::Portrait;
- } else {
- value = (d->devMode->dmOrientation == DMORIENT_LANDSCAPE) ? QPrinter::Landscape : QPrinter::Portrait;
- }
- }
+ value = d->m_pageLayout.orientation();
break;
case PPK_OutputFileName:
@@ -1570,150 +1316,93 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const
break;
case PPK_PageRect:
- if (d->has_custom_paper_size) {
- QRect rect(0, 0,
- qRound(d->paper_size.width() * d->resolution / 72.0),
- qRound(d->paper_size.height() * d->resolution / 72.0));
- if (d->pageMarginsSet) {
- rect = rect.adjusted(qRound(mmToInches(d->previousDialogMargins.left()/100.0) * d->resolution),
- qRound(mmToInches(d->previousDialogMargins.top()/100.0) * d->resolution),
- -qRound(mmToInches(d->previousDialogMargins.width()/100.0) * d->resolution),
- -qRound(mmToInches(d->previousDialogMargins.height()/100.0) * d->resolution));
- }
- value = rect;
- } else {
- value = QTransform(1/d->stretch_x, 0, 0, 1/d->stretch_y, 0, 0)
- .mapRect(d->fullPage ? d->devPhysicalPageRect : d->devPageRect);
- }
+ // PageRect is returned in device pixels
+ value = d->m_pageLayout.paintRectPixels(d->resolution);
break;
- case PPK_PaperSize:
- if (d->has_custom_paper_size) {
- value = QPrinter::Custom;
- } else {
- if (!d->devMode) {
- value = QPrinter::A4;
- } else {
- value = mapDevmodePaperSize(d->devMode->dmPaperSize);
- }
- }
+ case PPK_PageSize:
+ value = d->m_pageLayout.pageSize().id();
break;
case PPK_PaperRect:
- if (d->has_custom_paper_size) {
- value = QRect(0, 0,
- qRound(d->paper_size.width() * d->resolution / 72.0),
- qRound(d->paper_size.height() * d->resolution / 72.0));
- } else {
- value = QTransform(1/d->stretch_x, 0, 0, 1/d->stretch_y, 0, 0).mapRect(d->devPaperRect);
- }
+ // PaperRect is returned in device pixels
+ value = d->m_pageLayout.fullRectPixels(d->resolution);
break;
case PPK_PaperName:
- if (!d->devMode) {
- value = QLatin1String("A4");
- } else {
- const wchar_t *name = reinterpret_cast<const wchar_t*>(d->name.utf16());
- DWORD size = DeviceCapabilities(name, NULL, DC_PAPERS, NULL, NULL);
- int paperSizePos = -1;
- if ((int)size > 0) {
- QScopedArrayPointer<wchar_t> papers(new wchar_t[size]);
- if (size != DeviceCapabilities(name, NULL, DC_PAPERS, papers.data(), NULL))
- break;
- for (int i=0;i<(int)size;i++) {
- if (papers[i] == d->devMode->dmPaperSize) {
- paperSizePos = i;
- break;
- }
- }
- }
- if (paperSizePos != -1) {
- size = DeviceCapabilities(name, NULL, DC_PAPERNAMES, NULL, NULL);
- if ((int)size > 0) {
- QScopedArrayPointer<wchar_t> paperNames(new wchar_t[size*64]);
- size = DeviceCapabilities(name, NULL, DC_PAPERNAMES, paperNames.data(), NULL);
- wchar_t *copyOfPaper = paperNames.data() + (paperSizePos * 64);
- value = QString::fromWCharArray(copyOfPaper, qwcsnlen(copyOfPaper, 64));
- }
- }
- }
+ value = d->m_pageLayout.pageSize().name();
break;
case PPK_PaperSource:
if (!d->devMode) {
- value = QPrinter::Auto;
+ value = d->m_printDevice.defaultInputSlot().id;
} else {
- value = mapDevmodePaperSource(d->devMode->dmDefaultSource);
+ value = QPrint::Auto;
+ foreach (const QPrint::InputSlot inputSlot, d->m_printDevice.supportedInputSlots()) {
+ if (inputSlot.windowsId == d->devMode->dmDefaultSource) {
+ value = inputSlot.id;
+ break;
+ }
+ }
}
break;
case PPK_PrinterName:
- value = d->name;
+ value = d->m_printDevice.id();
break;
case PPK_Resolution:
- if (d->resolution || !d->name.isEmpty())
+ if (d->resolution || d->m_printDevice.isValid())
value = d->resolution;
break;
- case PPK_SupportedResolutions:
- value = d->queryResolutions();
+ case PPK_SupportedResolutions: {
+ QList<QVariant> list;
+ foreach (int resolution, d->m_printDevice.supportedResolutions())
+ list << resolution;
+ value = list;
break;
+ }
case PPK_WindowsPageSize:
- if (!d->devMode) {
- value = -1;
- } else {
- value = d->devMode->dmPaperSize;
- }
+ value = d->m_pageLayout.pageSize().windowsId();
break;
- case PPK_PaperSources:
- {
- int available = DeviceCapabilities((const wchar_t *)d->name.utf16(), NULL, DC_BINS, 0, d->devMode);
-
- if (available <= 0)
- break;
-
- wchar_t *data = new wchar_t[available];
- int count = DeviceCapabilities((const wchar_t *)d->name.utf16(), NULL, DC_BINS, data, d->devMode);
-
- QList<QVariant> out;
- for (int i=0; i<count; ++i) {
- QPrinter::PaperSource src = mapDevmodePaperSource(data[i]);
- if (src != -1)
- out << (int) src;
- }
- value = out;
-
- delete [] data;
- }
+ case PPK_PaperSources: {
+ QList<QVariant> out;
+ foreach (const QPrint::InputSlot inputSlot, d->m_printDevice.supportedInputSlots())
+ out << inputSlot.id;
+ value = out;
break;
+ }
case PPK_CustomPaperSize:
- value = d->paper_size;
+ value = d->m_pageLayout.fullRectPoints().size();
break;
- case PPK_PageMargins:
- {
- QList<QVariant> margins;
- if (d->has_custom_paper_size && !d->pageMarginsSet) {
- margins << 0 << 0 << 0 << 0;
- } else {
- QRect pageMargins(d->getPageMargins());
+ case PPK_PageMargins: {
+ QList<QVariant> list;
+ QMarginsF margins = d->m_pageLayout.margins(QPageLayout::Point);
+ list << margins.left() << margins.top() << margins.right() << margins.bottom();
+ value = list;
+ break;
+ }
- // specified in 1/100 mm
- margins << (mmToInches(pageMargins.left()/100.0) * 72)
- << (mmToInches(pageMargins.top()/100.0) * 72)
- << (mmToInches(pageMargins.width()/100.0) * 72)
- << (mmToInches(pageMargins.height()/100.0) * 72);
- }
- value = margins;
+ case PPK_QPageSize:
+ value.setValue(d->m_pageLayout.pageSize());
+ break;
+
+ case PPK_QPageMargins: {
+ QPair<QMarginsF, QPageLayout::Unit> pair = qMakePair(d->m_pageLayout.margins(), d->m_pageLayout.units());
+ value.setValue(pair);
break;
}
- // No default so that compiler will complain if new keys added and not handled in this engine
+ case PPK_QPageLayout:
+ value.setValue(d->m_pageLayout);
+ break;
+ // No default so that compiler will complain if new keys added and not handled in this engine
}
return value;
}
@@ -1733,76 +1422,11 @@ void QWin32PrintEngine::releaseDC(HDC) const
}
-QList<QPrinter::PaperSize> QWin32PrintEngine::supportedPaperSizes(const QPrinterInfo &printerInfo)
-{
- QList<QPrinter::PaperSize> returnList;
-
- if (printerInfo.isNull())
- return returnList;
- const wchar_t *name = reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16());
- DWORD size = DeviceCapabilities(name, NULL, DC_PAPERS, NULL, NULL);
- if ((int)size != -1) {
- QScopedArrayPointer<wchar_t> papers(new wchar_t[size]);
- if (size != DeviceCapabilities(name, NULL, DC_PAPERS, papers.data(), NULL))
- return returnList;
- for (int c = 0; c < (int)size; ++c)
- returnList.append(mapDevmodePaperSize(papers[c]));
- }
- return returnList;
-}
-
-QList<QPair<QString, QSizeF> > QWin32PrintEngine::supportedSizesWithNames(const QPrinterInfo &printerInfo)
-{
- QList<QPair<QString, QSizeF> > paperSizes;
- if (printerInfo.isNull())
- return paperSizes;
- const wchar_t *name = reinterpret_cast<const wchar_t*>(printerInfo.printerName().utf16());
- DWORD size = DeviceCapabilities(name, NULL, DC_PAPERNAMES, NULL, NULL);
- if ((int)size > 0) {
- QScopedArrayPointer<wchar_t> papers(new wchar_t[size*64]);
- if (size != DeviceCapabilities(name, NULL, DC_PAPERNAMES, papers.data(), NULL))
- return paperSizes;
- if (size != DeviceCapabilities(name, NULL, DC_PAPERSIZE, NULL, NULL))
- return paperSizes;
- QScopedArrayPointer<POINT> points(new POINT[size*sizeof(POINT)]);
- if (size != DeviceCapabilities(name, NULL, DC_PAPERSIZE, (wchar_t *)points.data(), NULL))
- return paperSizes;
- for (int i = 0; i < (int)size; ++i) {
- wchar_t *paper = papers.data() + (i * 64);
- QString str = QString::fromWCharArray(paper, qwcsnlen(paper, 64));
- paperSizes << qMakePair(str, QSizeF(points[i].x / 10.0, points[i].y / 10.0));
- }
- }
- return paperSizes;
-}
-
-void QWin32PrintEngine::queryDefaultPrinter(QString &name)
-{
- /* Read the default printer name, driver and port with the intuitive function
- * Strings "windows" and "device" are specified in the MSDN under EnumPrinters()
- */
- QString noPrinters(QLatin1String("qt_no_printers"));
- wchar_t buffer[256];
- GetProfileString(L"windows", L"device",
- reinterpret_cast<const wchar_t *>(noPrinters.utf16()),
- buffer, 256);
- QString output = QString::fromWCharArray(buffer);
- if (output.isEmpty() || output == noPrinters) // no printers
- return;
-
- QStringList info = output.split(QLatin1Char(','));
- int infoSize = info.size();
- if (infoSize > 0) {
- if (name.isEmpty())
- name = info.at(0);
- }
-}
-
HGLOBAL *QWin32PrintEngine::createGlobalDevNames()
{
Q_D(QWin32PrintEngine);
- int size = sizeof(DEVNAMES) + d->name.length() * 2 + 2;
+ int size = sizeof(DEVNAMES) + d->m_printDevice.id().length() * 2 + 2;
HGLOBAL *hGlobal = (HGLOBAL *) GlobalAlloc(GMEM_MOVEABLE, size);
DEVNAMES *dn = (DEVNAMES*) GlobalLock(hGlobal);
@@ -1810,7 +1434,7 @@ HGLOBAL *QWin32PrintEngine::createGlobalDevNames()
dn->wDeviceOffset = sizeof(DEVNAMES) / sizeof(wchar_t);
dn->wOutputOffset = 0;
- memcpy((ushort*)dn + dn->wDeviceOffset, d->name.utf16(), d->name.length() * 2 + 2);
+ memcpy((ushort*)dn + dn->wDeviceOffset, d->m_printDevice.id().utf16(), d->m_printDevice.id().length() * 2 + 2);
dn->wDefault = 0;
GlobalUnlock(hGlobal);
@@ -1822,7 +1446,10 @@ void QWin32PrintEngine::setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalD
Q_D(QWin32PrintEngine);
if (globalDevNames) {
DEVNAMES *dn = (DEVNAMES*) GlobalLock(globalDevNames);
- d->name = QString::fromWCharArray((wchar_t*)(dn) + dn->wDeviceOffset);
+ QString id = QString::fromWCharArray((wchar_t*)(dn) + dn->wDeviceOffset);
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps)
+ d->m_printDevice = ps->createPrintDevice(id.isEmpty() ? ps->defaultPrintDeviceId() : id);
GlobalUnlock(globalDevNames);
}
@@ -1831,17 +1458,22 @@ void QWin32PrintEngine::setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalD
d->release();
d->globalDevMode = globalDevMode;
d->devMode = dm;
- d->hdc = CreateDC(NULL, reinterpret_cast<const wchar_t *>(d->name.utf16()), 0, dm);
+ d->hdc = CreateDC(NULL, reinterpret_cast<const wchar_t *>(d->m_printDevice.id().utf16()), 0, dm);
d->num_copies = d->devMode->dmCopies;
- d->updateCustomPaperSize();
+ d->updatePageLayout();
- if (!OpenPrinter((wchar_t*)d->name.utf16(), &d->hPrinter, 0))
+ if (!OpenPrinter((wchar_t*)d->m_printDevice.id().utf16(), &d->hPrinter, 0))
qWarning("QPrinter: OpenPrinter() failed after reading DEVMODE.");
}
if (d->hdc)
d->initHDC();
+
+#if defined QT_DEBUG_DRAW || defined QT_DEBUG_METRICS
+ qDebug() << "QWin32PrintEngine::setGlobalDevMode()";
+ debugMetrics();
+#endif // QT_DEBUG_DRAW || QT_DEBUG_METRICS
}
HGLOBAL QWin32PrintEngine::globalDevMode()
@@ -1850,6 +1482,78 @@ HGLOBAL QWin32PrintEngine::globalDevMode()
return d->globalDevMode;
}
+void QWin32PrintEnginePrivate::setPageSize(const QPageSize &pageSize)
+{
+ if (!pageSize.isValid())
+ return;
+
+ // Use the printer page size if supported
+ const QPageSize printerPageSize = m_printDevice.supportedPageSize(pageSize);
+ const QPageSize usePageSize = printerPageSize.isValid() ? printerPageSize : pageSize;
+
+ const QMarginsF printable = m_printDevice.printableMargins(usePageSize, m_pageLayout.orientation(), resolution);
+ m_pageLayout.setPageSize(usePageSize, qt_convertMargins(printable, QPageLayout::Point, m_pageLayout.units()));
+
+ // Setup if Windows custom size, i.e. not a known Windows ID
+ if (printerPageSize.isValid()) {
+ has_custom_paper_size = false;
+ devMode->dmPaperSize = m_pageLayout.pageSize().windowsId();
+ devMode->dmFields &= ~(DM_PAPERLENGTH | DM_PAPERWIDTH);
+ devMode->dmPaperWidth = 0;
+ devMode->dmPaperLength = 0;
+ } else {
+ devMode->dmPaperSize = DMPAPER_USER;
+ devMode->dmFields |= DM_PAPERLENGTH | DM_PAPERWIDTH;
+ // Size in tenths of a millimeter
+ const QSizeF sizeMM = m_pageLayout.pageSize().size(QPageSize::Millimeter);
+ devMode->dmPaperWidth = qRound(sizeMM.width() * 10.0);
+ devMode->dmPaperLength = qRound(sizeMM.height() * 10.0);
+ }
+ updateMetrics();
+}
+
+// Update the page layout after any changes made to devMode
+void QWin32PrintEnginePrivate::updatePageLayout()
+{
+ // Update orientation first as is needed to obtain printable margins when changing page size
+ m_pageLayout.setOrientation(devMode->dmOrientation == DMORIENT_LANDSCAPE ? QPageLayout::Landscape : QPageLayout::Portrait);
+ if (devMode->dmPaperSize >= DMPAPER_USER) {
+ // Is a custom size
+ QPageSize pageSize = QPageSize(QSizeF(devMode->dmPaperWidth / 10.0f, devMode->dmPaperLength / 10.0f),
+ QPageSize::Millimeter);
+ setPageSize(pageSize);
+ } else {
+ // Is a supported size
+ setPageSize(QPageSize(QPageSize::id(devMode->dmPaperSize)));
+ }
+ updateMetrics();
+}
+
+// Update the cached page paint metrics whenever page layout is changed
+void QWin32PrintEnginePrivate::updateMetrics()
+{
+ m_paintRectPixels = m_pageLayout.paintRectPixels(resolution);
+ QSizeF sizeMM = m_pageLayout.paintRect(QPageLayout::Millimeter).size();
+ m_paintSizeMM = QSize(qRound(sizeMM.width()), qRound(sizeMM.height()));
+ // Calculate the origin using the physical device pixels, not our paint pixels
+ // Origin is defined as User Margins - Device Margins
+ QMarginsF margins = m_pageLayout.margins(QPageLayout::Millimeter) / 25.4;
+ origin_x = qRound(margins.left() * dpi_x) - GetDeviceCaps(hdc, PHYSICALOFFSETX);
+ origin_y = qRound(margins.top() * dpi_y) - GetDeviceCaps(hdc, PHYSICALOFFSETY);
+}
+
+void QWin32PrintEnginePrivate::debugMetrics() const
+{
+ qDebug() << " " << "m_pageLayout = " << m_pageLayout;
+ qDebug() << " " << "m_paintRectPixels = " << m_paintRectPixels;
+ qDebug() << " " << "m_paintSizeMM = " << m_paintSizeMM;
+ qDebug() << " " << "resolution = " << resolution;
+ qDebug() << " " << "stretch = " << stretch_x << stretch_y;
+ qDebug() << " " << "origin = " << origin_x << origin_y;
+ qDebug() << " " << "dpi = " << dpi_x << dpi_y;
+ qDebug() << "";
+}
+
static void draw_text_item_win(const QPointF &pos, const QTextItemInt &ti, HDC hdc,
bool convertToText, const QTransform &xform, const QPointF &topLeft)
{
@@ -1965,27 +1669,6 @@ static void draw_text_item_win(const QPointF &pos, const QTextItemInt &ti, HDC h
SelectObject(hdc, old_font);
}
-void QWin32PrintEnginePrivate::updateCustomPaperSize()
-{
- const uint paperSize = devMode->dmPaperSize;
- const double multiplier = qt_multiplierForUnit(QPrinter::Millimeter, resolution);
- has_custom_paper_size = false;
- if (paperSize == DMPAPER_USER) {
- has_custom_paper_size = true;
- paper_size = QSizeF((devMode->dmPaperWidth / 10.0) * multiplier, (devMode->dmPaperLength / 10.0) * multiplier);
- } else if (mapDevmodePaperSize(paperSize) == QPrinter::Custom) {
- has_custom_paper_size = true;
- const QList<QPair<QSizeF, int> > paperSizes = printerPaperSizes(name);
- for (int i=0; i<paperSizes.size(); i++) {
- if ((uint)paperSizes.at(i).second == paperSize) {
- paper_size = paperSizes.at(i).first * multiplier;
- has_custom_paper_size = false;
- break;
- }
- }
- }
-}
-
QT_END_NAMESPACE
#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprintengine_win_p.h b/src/printsupport/kernel/qprintengine_win_p.h
index d720561c2a..9b944d5921 100644
--- a/src/printsupport/kernel/qprintengine_win_p.h
+++ b/src/printsupport/kernel/qprintengine_win_p.h
@@ -58,10 +58,11 @@
#ifndef QT_NO_PRINTER
#include <QtGui/qpaintengine.h>
+#include <QtGui/qpagelayout.h>
#include <QtPrintSupport/QPrintEngine>
#include <QtPrintSupport/QPrinter>
-#include <QtPrintSupport/QPrinterInfo>
#include <private/qpaintengine_alpha_p.h>
+#include <private/qprintdevice_p.h>
#include <QtCore/qt_windows.h>
QT_BEGIN_NAMESPACE
@@ -105,16 +106,11 @@ public:
HDC getDC() const;
void releaseDC(HDC) const;
- static QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &printerInfo);
- static QList<QPair<QString, QSizeF> > supportedSizesWithNames(const QPrinterInfo &printerInfo);
-
/* Used by print/page setup dialogs */
void setGlobalDevMode(HGLOBAL globalDevNames, HGLOBAL globalDevMode);
HGLOBAL *createGlobalDevNames();
HGLOBAL globalDevMode();
- static void queryDefaultPrinter(QString &name);
-
private:
friend class QPrintDialog;
friend class QPageSetupDialog;
@@ -133,22 +129,16 @@ public:
mode(QPrinter::ScreenResolution),
state(QPrinter::Idle),
resolution(0),
- pageMarginsSet(false),
+ m_pageLayout(QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0, 0, 0, 0))),
num_copies(1),
printToFile(false),
- fullPage(false),
- reinit(false),
- has_custom_paper_size(false)
+ reinit(false)
{
}
~QWin32PrintEnginePrivate();
- /* Reads the default printer name and its driver (printerProgram) into
- the engines private data. */
- void queryDefault();
-
/* Initializes the printer data based on the current printer name. This
function creates a DEVMODE struct, HDC and a printer handle. If these
structures are already in use, they are freed using release
@@ -163,10 +153,6 @@ public:
etc and resets the corresponding members to 0. */
void release();
- /* Queries the resolutions for the current printer, and returns them
- in a list. */
- QList<QVariant> queryResolutions() const;
-
/* Resets the DC with changes in devmode. If the printer is active
this function only sets the reinit variable to true so it
is handled in the next begin or newpage. */
@@ -184,12 +170,10 @@ public:
void fillPath_dev(const QPainterPath &path, const QColor &color);
void strokePath_dev(const QPainterPath &path, const QColor &color, qreal width);
- void updateOrigin();
-
- void initDevRects();
- void setPageMargins(int margin_left, int margin_top, int margin_right, int margin_bottom);
- QRect getPageMargins() const;
- void updateCustomPaperSize();
+ void setPageSize(const QPageSize &pageSize);
+ void updatePageLayout();
+ void updateMetrics();
+ void debugMetrics() const;
// Windows GDI printer references.
HANDLE hPrinter;
@@ -203,8 +187,8 @@ public:
QPrinter::PrinterMode mode;
- // Printer info
- QString name;
+ // Print Device
+ QPrintDevice m_printDevice;
// Document info
QString docName;
@@ -214,19 +198,14 @@ public:
QPrinter::PrinterState state;
int resolution;
- // This QRect is used to store the exact values
- // entered into the PageSetup Dialog because those are
- // entered in mm but are since converted to device coordinates.
- // If they were to be converted back when displaying the dialog
- // again, there would be inaccuracies so when the user entered 10
- // it may show up as 9.99 the next time the dialog is opened.
- // We don't want that confusion.
- QRect previousDialogMargins;
-
- bool pageMarginsSet;
- QRect devPageRect;
- QRect devPhysicalPageRect;
- QRect devPaperRect;
+ // Page Layout
+ QPageLayout m_pageLayout;
+
+ // Page metrics cache
+ QRect m_paintRectPixels;
+ QSize m_paintSizeMM;
+
+ // Windows painting
qreal stretch_x;
qreal stretch_y;
int origin_x;
@@ -238,7 +217,6 @@ public:
int num_copies;
uint printToFile : 1;
- uint fullPage : 1;
uint reinit : 1;
uint complex_xform : 1;
@@ -251,7 +229,7 @@ public:
QColor brush_color;
QPen pen;
QColor pen_color;
- QSizeF paper_size;
+ QSizeF paper_size; // In points
QTransform painterMatrix;
QTransform matrix;
diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp
index 496883f44b..153fb23d36 100644
--- a/src/printsupport/kernel/qprinter.cpp
+++ b/src/printsupport/kernel/qprinter.cpp
@@ -67,39 +67,14 @@ QT_BEGIN_NAMESPACE
return; \
}
-// NB! This table needs to be in sync with QPrinter::PaperSize
-static const float qt_paperSizes[][2] = {
- {210, 297}, // A4
- {176, 250}, // B5
- {215.9f, 279.4f}, // Letter
- {215.9f, 355.6f}, // Legal
- {190.5f, 254}, // Executive
- {841, 1189}, // A0
- {594, 841}, // A1
- {420, 594}, // A2
- {297, 420}, // A3
- {148, 210}, // A5
- {105, 148}, // A6
- {74, 105}, // A7
- {52, 74}, // A8
- {37, 52}, // A8
- {1000, 1414}, // B0
- {707, 1000}, // B1
- {31, 44}, // B10
- {500, 707}, // B2
- {353, 500}, // B3
- {250, 353}, // B4
- {125, 176}, // B6
- {88, 125}, // B7
- {62, 88}, // B8
- {44, 62}, // B9
- {163, 229}, // C5E
- {105, 241}, // US Common
- {110, 220}, // DLE
- {210, 330}, // Folio
- {431.8f, 279.4f}, // Ledger
- {279.4f, 431.8f} // Tabloid
-};
+#define ABORT_IF_ACTIVE_RETURN(location, retValue) \
+ if (d->printEngine->printerState() == QPrinter::Active) { \
+ qWarning("%s: Cannot be changed while printer is active", location); \
+ return retValue; \
+ }
+
+extern qreal qt_pixelMultiplier(int resolution);
+extern QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits);
/// return the multiplier of converting from the unit value to postscript-points.
Q_PRINTSUPPORT_EXPORT double qt_multiplierForUnit(QPrinter::Unit unit, int resolution)
@@ -123,43 +98,19 @@ Q_PRINTSUPPORT_EXPORT double qt_multiplierForUnit(QPrinter::Unit unit, int resol
return 1.0;
}
-/// return the QSize from the specified in unit as millimeters
-Q_PRINTSUPPORT_EXPORT QSizeF qt_SizeFromUnitToMillimeter(const QSizeF &size, QPrinter::Unit unit, double resolution)
-{
- switch (unit) {
- case QPrinter::Millimeter:
- return size;
- case QPrinter::Point:
- return size * 0.352777778;
- case QPrinter::Inch:
- return size * 25.4;
- case QPrinter::Pica:
- return size * 4.23333333334;
- case QPrinter::Didot:
- return size * 0.377;
- case QPrinter::Cicero:
- return size * 4.511666667;
- case QPrinter::DevicePixel:
- return size * (0.352777778 * 72.0 / resolution);
- }
- return size;
-}
-
// not static: it's needed in qpagesetupdialog_unix.cpp
Q_PRINTSUPPORT_EXPORT QSizeF qt_printerPaperSize(QPrinter::Orientation orientation,
QPrinter::PaperSize paperSize,
QPrinter::Unit unit,
int resolution)
{
- int width_index = 0;
- int height_index = 1;
- if (orientation == QPrinter::Landscape) {
- width_index = 1;
- height_index = 0;
- }
- const qreal multiplier = qt_multiplierForUnit(unit, resolution);
- return QSizeF((qt_paperSizes[paperSize][width_index] * 72 / 25.4) / multiplier,
- (qt_paperSizes[paperSize][height_index] * 72 / 25.4) / multiplier);
+ QPageSize pageSize = QPageSize(QPageSize::PageSizeId(paperSize));
+ QSizeF sizef;
+ if (unit == QPrinter::DevicePixel)
+ sizef = pageSize.size(QPageSize::Point) * qt_multiplierForUnit(unit, resolution);
+ else
+ sizef = pageSize.size(QPageSize::Unit(unit));
+ return orientation == QPrinter::Landscape ? sizef.transposed() : sizef;
}
QPrinterInfo QPrinterPrivate::findValidPrinter(const QPrinterInfo &printer)
@@ -414,61 +365,157 @@ void QPrinterPrivate::setProperty(QPrintEngine::PrintEnginePropertyKey key, cons
\value PageRange The specified page range should be printed.
\value CurrentPage Only the current page should be printed.
- \sa QAbstractPrintDialog::PrintRange
+ \sa setPrintRange(), printRange(), QAbstractPrintDialog::PrintRange
*/
/*!
- \enum QPrinter::PaperSize
- \since 4.4
+ \enum QPrinter::PaperSize
+ \since 4.4
- This enum type specifies what paper size QPrinter should use.
- QPrinter does not check that the paper size is available; it just
- uses this information, together with QPrinter::Orientation and
- QPrinter::setFullPage(), to determine the printable area.
-
- The defined sizes (with setFullPage(true)) are:
-
- \value A0 841 x 1189 mm
- \value A1 594 x 841 mm
- \value A2 420 x 594 mm
- \value A3 297 x 420 mm
- \value A4 210 x 297 mm, 8.26 x 11.69 inches
- \value A5 148 x 210 mm
- \value A6 105 x 148 mm
- \value A7 74 x 105 mm
- \value A8 52 x 74 mm
- \value A9 37 x 52 mm
- \value B0 1000 x 1414 mm
- \value B1 707 x 1000 mm
- \value B2 500 x 707 mm
- \value B3 353 x 500 mm
- \value B4 250 x 353 mm
- \value B5 176 x 250 mm, 6.93 x 9.84 inches
- \value B6 125 x 176 mm
- \value B7 88 x 125 mm
- \value B8 62 x 88 mm
- \value B9 44 x 62 mm
- \value B10 31 x 44 mm
- \value C5E 163 x 229 mm
- \value Comm10E 105 x 241 mm, U.S. Common 10 Envelope
- \value DLE 110 x 220 mm
- \value Executive 7.5 x 10 inches, 190.5 x 254 mm
- \value Folio 210 x 330 mm
- \value Ledger 431.8 x 279.4 mm
- \value Legal 8.5 x 14 inches, 215.9 x 355.6 mm
- \value Letter 8.5 x 11 inches, 215.9 x 279.4 mm
- \value Tabloid 279.4 x 431.8 mm
- \value Custom Unknown, or a user defined size.
-
- With setFullPage(false) (the default), the metrics will be a bit
- smaller; how much depends on the printer in use.
-
- \note QPrinter::Folio is the Adobe specification for the Folio size.
- On Windows if you want to use the same as DMPAPER_FOLIO then you should use
- setPaperSize(QSizeF(8.5, 13), QPrinter::Inch).
-
- \omitvalue NPageSize
- \omitvalue NPaperSize
+ This enum type specifies what paper size QPrinter should use.
+ QPrinter does not check that the paper size is available; it just
+ uses this information, together with QPrinter::Orientation and
+ QPrinter::setFullPage(), to determine the printable area.
+
+ The defined sizes (with setFullPage(true)) are:
+
+ \value A0 841 x 1189 mm
+ \value A1 594 x 841 mm
+ \value A2 420 x 594 mm
+ \value A3 297 x 420 mm
+ \value A4 210 x 297 mm, 8.26 x 11.69 inches
+ \value A5 148 x 210 mm
+ \value A6 105 x 148 mm
+ \value A7 74 x 105 mm
+ \value A8 52 x 74 mm
+ \value A9 37 x 52 mm
+ \value B0 1000 x 1414 mm
+ \value B1 707 x 1000 mm
+ \value B2 500 x 707 mm
+ \value B3 353 x 500 mm
+ \value B4 250 x 353 mm
+ \value B5 176 x 250 mm, 6.93 x 9.84 inches
+ \value B6 125 x 176 mm
+ \value B7 88 x 125 mm
+ \value B8 62 x 88 mm
+ \value B9 33 x 62 mm
+ \value B10 31 x 44 mm
+ \value C5E 163 x 229 mm
+ \value Comm10E 105 x 241 mm, U.S. Common 10 Envelope
+ \value DLE 110 x 220 mm
+ \value Executive 7.5 x 10 inches, 190.5 x 254 mm
+ \value Folio 210 x 330 mm
+ \value Ledger 431.8 x 279.4 mm
+ \value Legal 8.5 x 14 inches, 215.9 x 355.6 mm
+ \value Letter 8.5 x 11 inches, 215.9 x 279.4 mm
+ \value Tabloid 279.4 x 431.8 mm
+ \value Custom Unknown, or a user defined size.
+ \value A10
+ \value A3Extra
+ \value A4Extra
+ \value A4Plus
+ \value A4Small
+ \value A5Extra
+ \value B5Extra
+ \value JisB0
+ \value JisB1
+ \value JisB2
+ \value JisB3
+ \value JisB4
+ \value JisB5
+ \value JisB6,
+ \value JisB7
+ \value JisB8
+ \value JisB9
+ \value JisB10
+ \value AnsiA = Letter
+ \value AnsiB = Ledger
+ \value AnsiC
+ \value AnsiD
+ \value AnsiE
+ \value LegalExtra
+ \value LetterExtra
+ \value LetterPlus
+ \value LetterSmall
+ \value TabloidExtra
+ \value ArchA
+ \value ArchB
+ \value ArchC
+ \value ArchD
+ \value ArchE
+ \value Imperial7x9
+ \value Imperial8x10
+ \value Imperial9x11
+ \value Imperial9x12
+ \value Imperial10x11
+ \value Imperial10x13
+ \value Imperial10x14
+ \value Imperial12x11
+ \value Imperial15x11
+ \value ExecutiveStandard
+ \value Note
+ \value Quarto
+ \value Statement
+ \value SuperA
+ \value SuperB
+ \value Postcard
+ \value DoublePostcard
+ \value Prc16K
+ \value Prc32K
+ \value Prc32KBig
+ \value FanFoldUS
+ \value FanFoldGerman
+ \value FanFoldGermanLegal
+ \value EnvelopeB4
+ \value EnvelopeB5
+ \value EnvelopeB6
+ \value EnvelopeC0
+ \value EnvelopeC1
+ \value EnvelopeC2
+ \value EnvelopeC3
+ \value EnvelopeC4
+ \value EnvelopeC5 = C5E
+ \value EnvelopeC6
+ \value EnvelopeC65
+ \value EnvelopeC7
+ \value EnvelopeDL = DLE
+ \value Envelope9
+ \value Envelope10 = Comm10E
+ \value Envelope11
+ \value Envelope12
+ \value Envelope14
+ \value EnvelopeMonarch
+ \value EnvelopePersonal
+ \value EnvelopeChou3
+ \value EnvelopeChou4
+ \value EnvelopeInvite
+ \value EnvelopeItalian
+ \value EnvelopeKaku2
+ \value EnvelopeKaku3
+ \value EnvelopePrc1
+ \value EnvelopePrc2
+ \value EnvelopePrc3
+ \value EnvelopePrc4
+ \value EnvelopePrc5
+ \value EnvelopePrc6
+ \value EnvelopePrc7
+ \value EnvelopePrc8
+ \value EnvelopePrc9
+ \value EnvelopePrc10
+ \value EnvelopeYou4
+ \value LastPageSize = EnvelopeYou4
+ \omitvalue NPageSize
+ \omitvalue NPaperSize
+
+ With setFullPage(false) (the default), the metrics will be a bit
+ smaller; how much depends on the printer in use.
+
+ Due to historic reasons QPageSize::Executive is not the same as the standard
+ Postscript and Windows Executive size, use QPageSize::ExecutiveStandard instead.
+
+ The Postscript standard size QPageSize::Folio is different to the Windows
+ DMPAPER_FOLIO size, use the Postscript standard size QPageSize::FanFoldGermanLegal
+ if needed.
*/
@@ -547,21 +594,6 @@ void QPrinterPrivate::setProperty(QPrintEngine::PrintEnginePropertyKey key, cons
the printer.
*/
-
-/*
- \enum QPrinter::PrintRange
-
- This enum is used to specify which print range the application
- should use to print.
-
- \value AllPages All the pages should be printed.
- \value Selection Only the selection should be printed.
- \value PageRange Print according to the from page and to page options.
- \value CurrentPage Only the current page should be printed.
-
- \sa setPrintRange(), printRange()
-*/
-
/*!
Creates a new printer object with the given \a mode.
*/
@@ -915,21 +947,165 @@ void QPrinter::setCreator(const QString &creator)
d->setProperty(QPrintEngine::PPK_Creator, creator);
}
+/*!
+ \since 5.3
+
+ Sets the page layout to \a newLayout.
+
+ If the \a newLayout is not valid for the current printer then the page
+ layout will not be changed. For example, if the page size is not supported
+ by the printer, or if the margins fall outside the printable area.
+
+ Returns true if the page layout was successfully set to \a newLayout.
+
+ \sa pageLayout(), setPageSize(), setPageOrientation(), setPageMargins()
+*/
+
+bool QPrinter::setPageLayout(const QPageLayout &newLayout)
+{
+ Q_D(QPrinter);
+
+ if (d->paintEngine->type() != QPaintEngine::Pdf)
+ ABORT_IF_ACTIVE_RETURN("QPrinter::setPageLayout", false);
+
+ // Try to set the print engine page layout
+ d->setProperty(QPrintEngine::PPK_QPageLayout, QVariant::fromValue(newLayout));
+
+ // Set QPagedPaintDevice layout to match the current print engine value
+ devicePageLayout() = pageLayout();
+
+ return pageLayout().isEquivalentTo(newLayout);
+}
+
+/*!
+ \since 5.3
+
+ Sets the page size to \a pageSize.
+
+ If the \a pageSize is not valid for the current printer then the page
+ size will not be changed.
+
+ Changing the page size may affect the current page margins if they fall
+ outside the printable margins for the new page size on the current printer.
+
+ To obtain the current QPageSize use pageLayout().pageSize().
+
+ Returns true if the page size was successfully set to \a pageSize.
+
+ \sa pageLayout(), setPageLayout()
+*/
+
+bool QPrinter::setPageSize(const QPageSize &pageSize)
+{
+ Q_D(QPrinter);
+
+ if (d->paintEngine->type() != QPaintEngine::Pdf)
+ ABORT_IF_ACTIVE_RETURN("QPrinter::setPageSize", false);
+
+ // Try to set the print engine page size
+ d->setProperty(QPrintEngine::PPK_QPageSize, QVariant::fromValue(pageSize));
+
+ // Set QPagedPaintDevice layout to match the current print engine value
+ devicePageLayout() = pageLayout();
+
+ return pageLayout().pageSize().isEquivalentTo(pageSize);
+}
+
+/*!
+ \since 5.3
+
+ Sets the page \a orientation to QPageLayout::Portrait or QPageLayout::Landscape.
+
+ The printer driver reads this setting and prints the page using the
+ specified orientation.
+
+ On Windows and Mac, this option can be changed while printing and will
+ take effect from the next call to newPage().
+
+ To obtain the current QPageLayout::Orientation use pageLayout().pageOrientation().
+
+ Returns true if the page orientation was successfully set to \a orientation.
+
+ \sa pageLayout(), setPageLayout()
+*/
+
+bool QPrinter::setPageOrientation(QPageLayout::Orientation orientation)
+{
+ Q_D(QPrinter);
+
+ // Set the print engine value
+ d->setProperty(QPrintEngine::PPK_Orientation, orientation);
+
+ // Set QPagedPaintDevice layout to match the current print engine value
+ devicePageLayout() = pageLayout();
+
+ return pageLayout().orientation() == orientation;
+}
+
+/*!
+ \since 5.3
+
+ Set the page margins to \a margins in the given \a units. If \a units are
+ not provided then the current units are used.
+
+ If in Full Page mode then no check is performed on the \a margins set,
+ otherwise the \a margins must fall within the printable area for the page
+ size on the current printer.
+
+ To obtain the current page margins use pageLayout().pageMargins().
+
+ Returns true if the page margins was successfully set to \a margins.
+
+ \sa pageLayout(), setPageLayout()
+*/
+
+bool QPrinter::setPageMargins(const QMarginsF &margins, QPageLayout::Unit units)
+{
+ Q_D(QPrinter);
+
+ // Try to set print engine margins
+ QPair<QMarginsF, QPageLayout::Unit> pair = qMakePair(margins, units);
+ d->setProperty(QPrintEngine::PPK_QPageMargins, QVariant::fromValue(pair));
+
+ // Set QPagedPaintDevice layout to match the current print engine value
+ devicePageLayout() = pageLayout();
+
+ return pageLayout().margins() == margins && pageLayout().units() == units;
+}
/*!
+ Returns the current page layout. Use this method to access the current
+ QPageSize, QPageLayout::Orientation, QMarginsF, fullPageRect() and paintRect().
+
+ Note that you cannot use the setters on the returned object, you must either
+ call the QPrinter methods or setPageLayout().
+
+ \sa setPageLayout(), setPageSize(), setPageOrientation(), setPageMargins()
+*/
+
+QPageLayout QPrinter::pageLayout() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_QPageLayout).value<QPageLayout>();
+}
+
+/*!
+ \obsolete Use pageLayout().pageOrientation() instead.
+
Returns the orientation setting. This is driver-dependent, but is usually
QPrinter::Portrait.
- \sa setOrientation()
+ \sa pageLayout()
*/
QPrinter::Orientation QPrinter::orientation() const
{
- Q_D(const QPrinter);
- return QPrinter::Orientation(d->printEngine->property(QPrintEngine::PPK_Orientation).toInt());
+ return QPrinter::Orientation(pageLayout().orientation());
}
/*!
+ \obsolete Use setPageOrientation() instead.
+
Sets the print orientation to \a orientation.
The orientation can be either QPrinter::Portrait or
@@ -941,32 +1117,34 @@ QPrinter::Orientation QPrinter::orientation() const
On Windows and Mac, this option can be changed while printing and will
take effect from the next call to newPage().
- \sa orientation()
+ \sa setPageOrientation()
*/
void QPrinter::setOrientation(Orientation orientation)
{
- Q_D(QPrinter);
- d->setProperty(QPrintEngine::PPK_Orientation, orientation);
+ setPageOrientation(QPageLayout::Orientation(orientation));
}
-
/*!
\since 4.4
+
+ \obsolete Use pageLayout().pageSize().id() instead.
+
Returns the printer paper size. The default value is driver-dependent.
- \sa setPaperSize(), pageRect(), paperRect()
+ \sa pageLayout()
*/
QPrinter::PaperSize QPrinter::paperSize() const
{
- Q_D(const QPrinter);
- return QPrinter::PaperSize(d->printEngine->property(QPrintEngine::PPK_PaperSize).toInt());
+ return pageSize();
}
/*!
\since 4.4
+ \obsolete Use setPageSize(QPageSize) instead.
+
Sets the printer paper size to \a newPaperSize if that size is
supported. The result is undefined if \a newPaperSize is not
supported.
@@ -976,108 +1154,103 @@ QPrinter::PaperSize QPrinter::paperSize() const
This function is useful mostly for setting a default value that
the user can override in the print dialog.
- \sa paperSize(), PaperSize, setFullPage(), setResolution(), pageRect(), paperRect()
+ \sa setPageSize()
*/
void QPrinter::setPaperSize(PaperSize newPaperSize)
{
- setPageSize(newPaperSize);
+ setPageSize(QPageSize(QPageSize::PageSizeId(newPaperSize)));
}
/*!
- \obsolete
+ \obsolete Use pageLayout().pageSize().id() instead.
Returns the printer page size. The default value is driver-dependent.
- Use paperSize() instead.
+ \sa pageLayout()
*/
QPrinter::PageSize QPrinter::pageSize() const
{
- return paperSize();
+ return QPrinter::PaperSize(pageLayout().pageSize().id());
}
/*!
- \obsolete
+ \obsolete Use setPageSize(QPageSize) instead.
Sets the printer page size based on \a newPageSize.
- Use setPaperSize() instead.
+ \sa setPageSize()
*/
void QPrinter::setPageSize(PageSize newPageSize)
{
- QPagedPaintDevice::setPageSize(newPageSize);
-
- Q_D(QPrinter);
- if (d->paintEngine->type() != QPaintEngine::Pdf)
- ABORT_IF_ACTIVE("QPrinter::setPaperSize");
- if (newPageSize < 0 || newPageSize >= NPageSize) {
- qWarning("QPrinter::setPaperSize: Illegal paper size %d", newPageSize);
- return;
- }
- d->setProperty(QPrintEngine::PPK_PaperSize, newPageSize);
- d->hasUserSetPageSize = true;
+ setPageSize(QPageSize(QPageSize::PageSizeId(newPageSize)));
}
/*!
\since 4.4
+ \obsolete Use setPageSize(QPageSize) instead.
+
Sets the paper size based on \a paperSize in \a unit.
- \sa paperSize()
+ Note that the paper size is defined in a portrait layout, regardless of
+ what the current printer orientation is set to.
+
+ \sa setPageSize()
*/
void QPrinter::setPaperSize(const QSizeF &paperSize, QPrinter::Unit unit)
{
- Q_D(QPrinter);
- if (d->paintEngine->type() != QPaintEngine::Pdf)
- ABORT_IF_ACTIVE("QPrinter::setPaperSize");
- setPageSizeMM(qt_SizeFromUnitToMillimeter(paperSize, unit, resolution()));
+ setPageSize(QPageSize(paperSize, QPageSize::Unit(unit)));
}
/*!
- \reimp
- */
-void QPrinter::setPageSizeMM(const QSizeF &size)
-{
- Q_D(QPrinter);
+ \reimp
- QPagedPaintDevice::setPageSizeMM(size);
+ \obsolete Use setPageSize(QPageSize) instead.
- QSizeF s = size * 72./25.4;
- d->setProperty(QPrintEngine::PPK_CustomPaperSize, s);
- d->hasUserSetPageSize = true;
+ Use setPageSize(QPageSize) instead.
+
+ Note that the page size is defined in a portrait layout, regardless of
+ what the current printer orientation is set to.
+
+ \sa setPageSize()
+*/
+void QPrinter::setPageSizeMM(const QSizeF &size)
+{
+ setPageSize(QPageSize(size, QPageSize::Millimeter));
}
/*!
\since 4.4
+ \obsolete Use pageLayout().pageSize().size() or
+ pageLayout().fullPageSize() instead.
+
Returns the paper size in \a unit.
- \sa setPaperSize()
+ Note that the returned size reflects the current paper orientation.
+
+ \sa pageLayout()
*/
QSizeF QPrinter::paperSize(Unit unit) const
{
- Q_D(const QPrinter);
- int res = resolution();
- const qreal multiplier = qt_multiplierForUnit(unit, res);
- PaperSize paperType = paperSize();
- if (paperType == Custom) {
- QSizeF size = d->printEngine->property(QPrintEngine::PPK_CustomPaperSize).toSizeF();
- return QSizeF(size.width() / multiplier, size.height() / multiplier);
- }
- else {
- return qt_printerPaperSize(orientation(), paperType, unit, res);
- }
+ if (unit == QPrinter::DevicePixel)
+ return pageLayout().fullRectPixels(resolution()).size();
+ else
+ return pageLayout().fullRect(QPageLayout::Unit(unit)).size();
}
/*!
\since 5.1
+ \obsolete Use setPageSize(QPageSize) instead.
+
Sets the paper used by the printer to \a paperName.
- \sa paperName()
+ \sa setPageSize()
*/
void QPrinter::setPaperName(const QString &paperName)
@@ -1091,9 +1264,13 @@ void QPrinter::setPaperName(const QString &paperName)
/*!
\since 5.1
+ \obsolete Use pageLayout().pageSize().name() instead.
+
Returns the paper name of the paper set on the printer.
The default value for this is driver-dependent.
+
+ \sa pageLayout()
*/
QString QPrinter::paperName() const
@@ -1338,13 +1515,16 @@ void QPrinter::setCollateCopies(bool collate)
printer's margins, so the application must account for the margins
itself.
- \sa fullPage(), setPaperSize(), width(), height()
+ \sa fullPage(), pageLayout(), setPageSize(), width(), height()
*/
void QPrinter::setFullPage(bool fp)
{
Q_D(QPrinter);
+ // Set the print engine
d->setProperty(QPrintEngine::PPK_FullPage, fp);
+ // Set QPagedPaintDevice layout to match the current print engine value
+ devicePageLayout() = pageLayout();
}
@@ -1355,7 +1535,7 @@ void QPrinter::setFullPage(bool fp)
See setFullPage() for details and caveats.
- \sa setFullPage(), PaperSize
+ \sa setFullPage(), pageLayout()
*/
bool QPrinter::fullPage() const
@@ -1535,19 +1715,10 @@ QPrinter::DuplexMode QPrinter::duplex() const
*/
QRectF QPrinter::pageRect(Unit unit) const
{
- Q_D(const QPrinter);
- int res = resolution();
- const qreal multiplier = qt_multiplierForUnit(unit, res);
- // the page rect is in device pixels
- QRect devRect(d->printEngine->property(QPrintEngine::PPK_PageRect).toRect());
- if (unit == DevicePixel)
- return devRect;
- QRectF diRect(devRect.x()*72.0/res,
- devRect.y()*72.0/res,
- devRect.width()*72.0/res,
- devRect.height()*72.0/res);
- return QRectF(diRect.x()/multiplier, diRect.y()/multiplier,
- diRect.width()/multiplier, diRect.height()/multiplier);
+ if (unit == QPrinter::DevicePixel)
+ return pageLayout().paintRectPixels(resolution());
+ else
+ return pageLayout().paintRect(QPageLayout::Unit(unit));
}
@@ -1561,29 +1732,22 @@ QRectF QPrinter::pageRect(Unit unit) const
*/
QRectF QPrinter::paperRect(Unit unit) const
{
- Q_D(const QPrinter);
- int res = resolution();
- const qreal multiplier = qt_multiplierForUnit(unit, resolution());
- // the page rect is in device pixels
- QRect devRect(d->printEngine->property(QPrintEngine::PPK_PaperRect).toRect());
- if (unit == DevicePixel)
- return devRect;
- QRectF diRect(devRect.x()*72.0/res,
- devRect.y()*72.0/res,
- devRect.width()*72.0/res,
- devRect.height()*72.0/res);
- return QRectF(diRect.x()/multiplier, diRect.y()/multiplier,
- diRect.width()/multiplier, diRect.height()/multiplier);
+ if (unit == QPrinter::DevicePixel)
+ return pageLayout().fullRectPixels(resolution());
+ else
+ return pageLayout().fullRect(QPageLayout::Unit(unit));
}
/*!
+ \obsolete Use pageLayout().paintRect() instead.
+
Returns the page's rectangle; this is usually smaller than the
paperRect() since the page normally has margins between its
borders and the paper.
The unit of the returned rectangle is DevicePixel.
- \sa paperSize()
+ \sa pageLayout()
*/
QRect QPrinter::pageRect() const
{
@@ -1592,12 +1756,14 @@ QRect QPrinter::pageRect() const
}
/*!
+ \obsolete Use pageLayout().fullPageRect() instead.
+
Returns the paper's rectangle; this is usually larger than the
pageRect().
The unit of the returned rectangle is DevicePixel.
- \sa pageRect()
+ \sa pageLayout()
*/
QRect QPrinter::paperRect() const
{
@@ -1605,61 +1771,69 @@ QRect QPrinter::paperRect() const
return d->printEngine->property(QPrintEngine::PPK_PaperRect).toRect();
}
-
/*!
\since 4.4
+ \obsolete Use setPageMargins(QMarginsF, QPageLayout::Unit) instead.
+
This function sets the \a left, \a top, \a right and \a bottom
page margins for this printer. The unit of the margins are
specified with the \a unit parameter.
- \sa getPageMargins()
+ \sa setPageMargins()
*/
void QPrinter::setPageMargins(qreal left, qreal top, qreal right, qreal bottom, QPrinter::Unit unit)
{
- const qreal multiplier = qt_multiplierForUnit(unit, resolution()) * 25.4/72.;
- Margins m = { left*multiplier, right*multiplier, top*multiplier, bottom*multiplier };
- setMargins(m);
+ if (unit == QPrinter::DevicePixel) {
+ QMarginsF margins = QMarginsF(left, top, right, bottom);
+ margins *= qt_pixelMultiplier(resolution());
+ margins = qt_convertMargins(margins, QPageLayout::Point, pageLayout().units());
+ setPageMargins(margins, pageLayout().units());
+ } else {
+ setPageMargins(QMarginsF(left, top, right, bottom), QPageLayout::Unit(unit));
+ }
}
/*!
- \reimp
+ \reimp
+
+ \obsolete Use setPageMargins(QMarginsF, QPageLayout::Unit) instead.
+
+ \sa setPageMargins()
*/
void QPrinter::setMargins(const Margins &m)
{
- Q_D(QPrinter);
-
- // set margins also to super class
- QPagedPaintDevice::setMargins(m);
-
- const qreal multiplier = 72./25.4;
- QList<QVariant> margins;
- margins << (m.left * multiplier) << (m.top * multiplier)
- << (m.right * multiplier) << (m.bottom * multiplier);
- d->setProperty(QPrintEngine::PPK_PageMargins, margins);
- d->hasCustomPageMargins = true;
+ setPageMargins(QMarginsF(m.left, m.top, m.right, m.bottom), QPageLayout::Millimeter);
}
-
/*!
\since 4.4
+ \obsolete Use pageLayout().pageMargins() instead.
+
Returns the page margins for this printer in \a left, \a top, \a
right, \a bottom. The unit of the returned margins are specified
with the \a unit parameter.
- \sa setPageMargins()
+ \sa pageLayout(), setPageMargins()
*/
void QPrinter::getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, QPrinter::Unit unit) const
{
- Q_D(const QPrinter);
- Q_ASSERT(left && top && right && bottom);
- const qreal multiplier = qt_multiplierForUnit(unit, resolution());
- QList<QVariant> margins(d->printEngine->property(QPrintEngine::PPK_PageMargins).toList());
- *left = margins.at(0).toReal() / multiplier;
- *top = margins.at(1).toReal() / multiplier;
- *right = margins.at(2).toReal() / multiplier;
- *bottom = margins.at(3).toReal() / multiplier;
+ QMarginsF margins;
+ if (unit == QPrinter::DevicePixel) {
+ QMargins tmp = pageLayout().marginsPixels(resolution());
+ margins = QMarginsF(tmp.left(), tmp.top(), tmp.right(), tmp.bottom());
+ } else {
+ margins = pageLayout().margins(QPageLayout::Unit(unit));
+ }
+ if (left)
+ *left = margins.left();
+ if (right)
+ *right = margins.right();
+ if (top)
+ *top = margins.top();
+ if (bottom)
+ *bottom = margins.bottom();
}
/*!
@@ -1693,15 +1867,13 @@ QPrintEngine *QPrinter::printEngine() const
return d->printEngine;
}
-#if defined (Q_OS_WIN)
/*!
+ \obsolete Use QPageSize::id(windowsId) and setPageLayout(QPageSize) instead.
+
Sets the page size to be used by the printer under Windows to \a
pageSize.
- \warning This function is not portable so you may prefer to use
- setPaperSize() instead.
-
- \sa winPageSize()
+ \sa pageLayout()
*/
void QPrinter::setWinPageSize(int pageSize)
{
@@ -1711,19 +1883,17 @@ void QPrinter::setWinPageSize(int pageSize)
}
/*!
- Returns the page size used by the printer under Windows.
+ \obsolete Use pageLayout.pageSize().windowsId() instead.
- \warning This function is not portable so you may prefer to use
- paperSize() instead.
+ Returns the page size used by the printer under Windows.
- \sa setWinPageSize()
+ \sa pageLayout()
*/
int QPrinter::winPageSize() const
{
Q_D(const QPrinter);
return d->printEngine->property(QPrintEngine::PPK_WindowsPageSize).toInt();
}
-#endif // Q_OS_WIN
/*!
Returns a list of the resolutions (a list of dots-per-inch
@@ -2048,13 +2218,19 @@ QPrinter::PrintRange QPrinter::printRange() const
in the QPrinter::Point unit.
\value PPK_PageMargins A QList<QVariant> containing the left, top,
- right and bottom margin values.
+ right and bottom margin values in the QPrinter::Point unit.
\value PPK_CopyCount An integer specifying the number of copies to print.
\value PPK_SupportsMultipleCopies A boolean value indicating whether or not
the printer supports printing multiple copies in one job.
+ \value PPK_QPageSize Set the page size using a QPageSize object.
+
+ \value PPK_QPageMargins Set the page margins using a QPair of QMarginsF and QPageLayout::Unit.
+
+ \value PPK_QPageLayout Set the page layout using a QPageLayout object.
+
\value PPK_CustomBase Basis for extension.
*/
@@ -2106,37 +2282,6 @@ QPrinter::PrintRange QPrinter::printRange() const
Returns the current state of the printer being used by the print engine.
*/
-/*
- Returns the dimensions for the given paper size, \a size, in millimeters.
-*/
-QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size)
-{
- if (size == QPrinter::Custom) return QSizeF(0, 0);
- return QSizeF(qt_paperSizes[size][0], qt_paperSizes[size][1]);
-}
-
-/*
- Returns the PaperSize type that matches \a size, where \a size
- is in millimeters.
-
- Because dimensions may not always be completely accurate (for
- example when converting between units), a particular PaperSize
- will be returned if it matches within -1/+1 millimeters.
-*/
-QPrinter::PaperSize qSizeFTopaperSize(const QSizeF& size)
-{
- for (int i = 0; i < static_cast<int>(QPrinter::NPageSize); ++i) {
- if (qt_paperSizes[i][0] >= size.width() - 1 &&
- qt_paperSizes[i][0] <= size.width() + 1 &&
- qt_paperSizes[i][1] >= size.height() - 1 &&
- qt_paperSizes[i][1] <= size.height() + 1) {
- return QPrinter::PaperSize(i);
- }
- }
-
- return QPrinter::Custom;
-}
-
QT_END_NAMESPACE
#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprinter.h b/src/printsupport/kernel/qprinter.h
index 679f3af043..1f0639d81f 100644
--- a/src/printsupport/kernel/qprinter.h
+++ b/src/printsupport/kernel/qprinter.h
@@ -45,6 +45,7 @@
#include <QtCore/qstring.h>
#include <QtCore/qscopedpointer.h>
#include <QtGui/qpagedpaintdevice.h>
+#include <QtGui/qpagelayout.h>
#include <QtPrintSupport/qtprintsupportglobal.h>
QT_BEGIN_NAMESPACE
@@ -60,6 +61,8 @@ class QPrinterPrivate;
class QPaintEngine;
class QPrintEngine;
class QPrinterInfo;
+class QPageSize;
+class QPageMargins;
class Q_PRINTSUPPORT_EXPORT QPrinter : public QPagedPaintDevice
{
@@ -75,13 +78,161 @@ public:
enum Orientation { Portrait, Landscape };
+ // ### Qt6 Remove in favor of QPage::PageSize
+ // NOTE: Must keep in sync with QPageSize and QPagedPaintDevice
#ifndef Q_QDOC
typedef PageSize PaperSize;
#else
- enum PaperSize { A4, B5, Letter, Legal, Executive,
- A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
- B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
- DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom, NPaperSize = Custom };
+ enum PaperSize {
+ // Existing Qt sizes
+ A4,
+ B5,
+ Letter,
+ Legal,
+ Executive,
+ A0,
+ A1,
+ A2,
+ A3,
+ A5,
+ A6,
+ A7,
+ A8,
+ A9,
+ B0,
+ B1,
+ B10,
+ B2,
+ B3,
+ B4,
+ B6,
+ B7,
+ B8,
+ B9,
+ C5E,
+ Comm10E,
+ DLE,
+ Folio,
+ Ledger,
+ Tabloid,
+ Custom,
+
+ // New values derived from PPD standard
+ A10,
+ A3Extra,
+ A4Extra,
+ A4Plus,
+ A4Small,
+ A5Extra,
+ B5Extra,
+
+ JisB0,
+ JisB1,
+ JisB2,
+ JisB3,
+ JisB4,
+ JisB5,
+ JisB6,
+ JisB7,
+ JisB8,
+ JisB9,
+ JisB10,
+
+ // AnsiA = Letter,
+ // AnsiB = Ledger,
+ AnsiC,
+ AnsiD,
+ AnsiE,
+ LegalExtra,
+ LetterExtra,
+ LetterPlus,
+ LetterSmall,
+ TabloidExtra,
+
+ ArchA,
+ ArchB,
+ ArchC,
+ ArchD,
+ ArchE,
+
+ Imperial7x9,
+ Imperial8x10,
+ Imperial9x11,
+ Imperial9x12,
+ Imperial10x11,
+ Imperial10x13,
+ Imperial10x14,
+ Imperial12x11,
+ Imperial15x11,
+
+ ExecutiveStandard,
+ Note,
+ Quarto,
+ Statement,
+ SuperA,
+ SuperB,
+ Postcard,
+ DoublePostcard,
+ Prc16K,
+ Prc32K,
+ Prc32KBig,
+
+ FanFoldUS,
+ FanFoldGerman,
+ FanFoldGermanLegal,
+
+ EnvelopeB4,
+ EnvelopeB5,
+ EnvelopeB6,
+ EnvelopeC0,
+ EnvelopeC1,
+ EnvelopeC2,
+ EnvelopeC3,
+ EnvelopeC4,
+ // EnvelopeC5 = C5E,
+ EnvelopeC6,
+ EnvelopeC65,
+ EnvelopeC7,
+ // EnvelopeDL = DLE,
+
+ Envelope9,
+ // Envelope10 = Comm10E,
+ Envelope11,
+ Envelope12,
+ Envelope14,
+ EnvelopeMonarch,
+ EnvelopePersonal,
+
+ EnvelopeChou3,
+ EnvelopeChou4,
+ EnvelopeInvite,
+ EnvelopeItalian,
+ EnvelopeKaku2,
+ EnvelopeKaku3,
+ EnvelopePrc1,
+ EnvelopePrc2,
+ EnvelopePrc3,
+ EnvelopePrc4,
+ EnvelopePrc5,
+ EnvelopePrc6,
+ EnvelopePrc7,
+ EnvelopePrc8,
+ EnvelopePrc9,
+ EnvelopePrc10,
+ EnvelopeYou4,
+
+ // Last item, with commonly used synynoms from QPagedPrintEngine / QPrinter
+ LastPageSize = EnvelopeYou4,
+ NPageSize = LastPageSize,
+ NPaperSize = LastPageSize,
+
+ // Convenience overloads for naming consistency
+ AnsiA = Letter,
+ AnsiB = Ledger,
+ EnvelopeC5 = C5E,
+ EnvelopeDL = DLE,
+ Envelope10 = Comm10E
+ };
#endif
enum PageOrder { FirstPageFirst,
@@ -156,6 +307,12 @@ public:
void setCreator(const QString &);
QString creator() const;
+ bool setPageLayout(const QPageLayout &pageLayout);
+ bool setPageSize(const QPageSize &pageSize);
+ bool setPageOrientation(QPageLayout::Orientation orientation);
+ bool setPageMargins(const QMarginsF &margins, QPageLayout::Unit units);
+ QPageLayout pageLayout() const;
+
void setOrientation(Orientation);
Orientation orientation() const;
@@ -215,10 +372,8 @@ public:
void setDoubleSidedPrinting(bool enable);
bool doubleSidedPrinting() const;
-#ifdef Q_OS_WIN
void setWinPageSize(int winPageSize);
int winPageSize() const;
-#endif
QRect paperRect() const;
QRect pageRect() const;
diff --git a/src/printsupport/kernel/qprinter_p.h b/src/printsupport/kernel/qprinter_p.h
index 2357b9e944..ddc2dad413 100644
--- a/src/printsupport/kernel/qprinter_p.h
+++ b/src/printsupport/kernel/qprinter_p.h
@@ -87,9 +87,7 @@ public:
q_ptr(printer),
printRange(QPrinter::AllPages),
use_default_engine(true),
- validPrinter(false),
- hasCustomPageMargins(false),
- hasUserSetPageSize(false)
+ validPrinter(false)
{
}
@@ -129,7 +127,6 @@ public:
uint validPrinter : 1;
uint hasCustomPageMargins : 1;
- uint hasUserSetPageSize : 1;
// Used to remember which properties have been manually set by the user.
QSet<QPrintEngine::PrintEnginePropertyKey> m_properties;
diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp
index e02617fe93..b1321bf57a 100644
--- a/src/printsupport/kernel/qprinterinfo.cpp
+++ b/src/printsupport/kernel/qprinterinfo.cpp
@@ -27,6 +27,7 @@
#include "qprinterinfo.h"
#include "qprinterinfo_p.h"
+#include "qprintdevice_p.h"
#ifndef QT_NO_PRINTER
@@ -47,6 +48,19 @@ public:
}
};
+QPrinterInfoPrivate::QPrinterInfoPrivate(const QString &id)
+{
+ if (!id.isEmpty()) {
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps)
+ m_printDevice = ps->createPrintDevice(id);
+ }
+}
+
+QPrinterInfoPrivate::~QPrinterInfoPrivate()
+{
+}
+
/*!
\class QPrinterInfo
@@ -65,28 +79,6 @@ public:
*/
/*!
- \fn QList<QPrinterInfo> QPrinterInfo::availablePrinters()
-
- Returns a list of available printers on the system.
-*/
-
-/*!
- \fn QPrinterInfo QPrinterInfo::defaultPrinter()
-
- Returns the default printer on the system.
-
- The return value should be checked using isNull() before being
- used, in case there is no default printer.
-
- On some systems it is possible for there to be available printers
- but none of them set to be the default printer.
-
- \sa isNull()
- \sa isDefault()
- \sa availablePrinters()
-*/
-
-/*!
Constructs an empty QPrinterInfo object.
\sa isNull()
@@ -112,7 +104,7 @@ QPrinterInfo::QPrinterInfo(const QPrinter &printer)
{
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
if (ps) {
- QPrinterInfo pi = ps->printerInfo(printer.printerName());
+ QPrinterInfo pi(printer.printerName());
if (pi.d_ptr.data() == shared_null)
d_ptr.reset(shared_null);
else
@@ -160,7 +152,7 @@ QPrinterInfo &QPrinterInfo::operator=(const QPrinterInfo &other)
QString QPrinterInfo::printerName() const
{
const Q_D(QPrinterInfo);
- return d->name;
+ return d->m_printDevice.id();
}
/*!
@@ -172,7 +164,7 @@ QString QPrinterInfo::printerName() const
QString QPrinterInfo::description() const
{
const Q_D(QPrinterInfo);
- return d->description;
+ return d->m_printDevice.name();
}
/*!
@@ -183,7 +175,7 @@ QString QPrinterInfo::description() const
QString QPrinterInfo::location() const
{
const Q_D(QPrinterInfo);
- return d->location;
+ return d->m_printDevice.location();
}
/*!
@@ -194,7 +186,7 @@ QString QPrinterInfo::location() const
QString QPrinterInfo::makeAndModel() const
{
const Q_D(QPrinterInfo);
- return d->makeAndModel;
+ return d->m_printDevice.makeAndModel();
}
/*!
@@ -206,23 +198,114 @@ QString QPrinterInfo::makeAndModel() const
bool QPrinterInfo::isNull() const
{
Q_D(const QPrinterInfo);
- return d == shared_null || d->name.isEmpty();
+ return d == shared_null || !d->m_printDevice.isValid();
}
/*!
- Returns whether this printer is the default printer.
+ Returns whether this printer is currently the default printer.
*/
bool QPrinterInfo::isDefault() const
{
Q_D(const QPrinterInfo);
- return d->isDefault;
+ return d->m_printDevice.isDefault();
+}
+
+/*!
+ Returns whether this printer is a remote network printer.
+
+ \since 5.3
+*/
+bool QPrinterInfo::isRemote() const
+{
+ Q_D(const QPrinterInfo);
+ return d->m_printDevice.isRemote();
+}
+
+/*!
+ Returns the current state of this printer.
+
+ This state may not always be accurate, depending on the platform, printer
+ driver, or printer itself.
+
+ \since 5.3
+*/
+QPrinter::PrinterState QPrinterInfo::state() const
+{
+ Q_D(const QPrinterInfo);
+ return QPrinter::PrinterState(d->m_printDevice.state());
+}
+
+/*!
+ Returns a list of Page Sizes supported by this printer.
+
+ \since 5.3
+*/
+
+QList<QPageSize> QPrinterInfo::supportedPageSizes() const
+{
+ Q_D(const QPrinterInfo);
+ return d->m_printDevice.supportedPageSizes();
+}
+
+/*!
+ Returns the current default Page Size for this printer.
+
+ \since 5.3
+*/
+
+QPageSize QPrinterInfo::defaultPageSize() const
+{
+ Q_D(const QPrinterInfo);
+ return d->m_printDevice.defaultPageSize();
+}
+
+/*!
+ Returns whether this printer supports custom page sizes.
+
+ \since 5.3
+*/
+
+bool QPrinterInfo::supportsCustomPageSizes() const
+{
+ Q_D(const QPrinterInfo);
+ return d->m_printDevice.supportsCustomPageSizes();
}
/*!
+ Returns the minimum physical page size supported by this printer.
+
+ \sa maximumPhysicalPageSize()
+
+ \since 5.3
+*/
+
+QPageSize QPrinterInfo::minimumPhysicalPageSize() const
+{
+ Q_D(const QPrinterInfo);
+ return QPageSize(d->m_printDevice.minimumPhysicalPageSize(), QString(), QPageSize::ExactMatch);
+}
+
+/*!
+ Returns the maximum physical page size supported by this printer.
+
+ \sa minimumPhysicalPageSize()
+
+ \since 5.3
+*/
+
+QPageSize QPrinterInfo::maximumPhysicalPageSize() const
+{
+ Q_D(const QPrinterInfo);
+ return QPageSize(d->m_printDevice.maximumPhysicalPageSize(), QString(), QPageSize::ExactMatch);
+}
+
+#if QT_DEPRECATED_SINCE(5,3)
+/*!
+ \obsolete Use supportedPageSizes() instead.
+
Returns a list of supported paper sizes by the printer.
Not all printer drivers support this query, so the list may be empty.
- On Mac OS X 10.3, this function always returns an empty list.
\since 4.4
*/
@@ -230,14 +313,15 @@ bool QPrinterInfo::isDefault() const
QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
{
Q_D(const QPrinterInfo);
- if (!isNull() && !d->hasPaperSizes) {
- d->paperSizes = QPlatformPrinterSupportPlugin::get()->supportedPaperSizes(*this);
- d->hasPaperSizes = true;
- }
- return d->paperSizes;
+ QList<QPrinter::PaperSize> list;
+ foreach (const QPageSize &pageSize, d->m_printDevice.supportedPageSizes())
+ list.append(QPrinter::PaperSize(pageSize.id()));
+ return list;
}
/*!
+ \obsolete Use supportedPageSizes() instead.
+
Returns a list of all the paper names supported by the driver with the
corresponding size in millimeters.
@@ -249,27 +333,99 @@ QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
QList<QPair<QString, QSizeF> > QPrinterInfo::supportedSizesWithNames() const
{
Q_D(const QPrinterInfo);
- if (!isNull() && !d->hasPaperNames) {
- d->paperNames = QPlatformPrinterSupportPlugin::get()->supportedSizesWithNames(*this);
- d->hasPaperNames = true;
- }
- return d->paperNames;
+ QList<QPair<QString, QSizeF> > list;
+ foreach (const QPageSize &pageSize, d->m_printDevice.supportedPageSizes())
+ list.append(qMakePair(pageSize.name(), pageSize.size(QPageSize::Millimeter)));
+ return list;
+}
+#endif // QT_DEPRECATED_SINCE(5,3)
+
+/*!
+ Returns a list of resolutions supported by this printer.
+
+ \since 5.3
+*/
+
+QList<int> QPrinterInfo::supportedResolutions() const
+{
+ Q_D(const QPrinterInfo);
+ return d->m_printDevice.supportedResolutions();
}
+/*!
+ Returns a list of all the available Printer Names on this system.
+
+ It is recommended to use this instead of availablePrinters() as
+ it will be faster on most systems.
+
+ Note that the list may become outdated if changes are made on the local
+ system or remote print server. Only instantiate required QPrinterInfo
+ instances when needed, and always check for validity before calling.
+
+ \since 5.3
+*/
+QStringList QPrinterInfo::availablePrinterNames()
+{
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps)
+ return ps->availablePrintDeviceIds();
+ return QStringList();
+}
+
+/*!
+ Returns a list of QPrinterInfo objects for all the available printers
+ on this system.
+
+ It is NOT recommended to use this as creating each printer instance may
+ take a long time, especially if there are remote networked printers, and
+ retained instances may become outdated if changes are made on the local
+ system or remote print server. Use availablePrinterNames() instead and
+ only instantiate printer instances as you need them.
+*/
QList<QPrinterInfo> QPrinterInfo::availablePrinters()
{
+ QList<QPrinterInfo> list;
+ QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
+ if (ps) {
+ foreach (const QString &id, ps->availablePrintDeviceIds())
+ list.append(QPrinterInfo(id));
+ }
+ return list;
+}
+
+/*!
+ Returns the current default printer name.
+
+ \since 5.3
+*/
+QString QPrinterInfo::defaultPrinterName()
+{
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
- if (!ps)
- return QList<QPrinterInfo>();
- return ps->availablePrinters();
+ if (ps)
+ return ps->defaultPrintDeviceId();
+ return QString();
}
+/*!
+ Returns the default printer on the system.
+
+ The return value should be checked using isNull() before being
+ used, in case there is no default printer.
+
+ On some systems it is possible for there to be available printers
+ but none of them set to be the default printer.
+
+ \sa isNull()
+ \sa isDefault()
+ \sa availablePrinters()
+*/
+
QPrinterInfo QPrinterInfo::defaultPrinter()
{
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
- if (!ps)
- return QPrinterInfo();
- return ps->defaultPrinter();
+ if (ps)
+ return QPrinterInfo(ps->defaultPrintDeviceId());
+ return QPrinterInfo();
}
/*!
@@ -283,10 +439,7 @@ QPrinterInfo QPrinterInfo::defaultPrinter()
*/
QPrinterInfo QPrinterInfo::printerInfo(const QString &printerName)
{
- QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
- if (!ps)
- return QPrinterInfo();
- return ps->printerInfo(printerName);
+ return QPrinterInfo(printerName);
}
QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qprinterinfo.h b/src/printsupport/kernel/qprinterinfo.h
index 0dc19c1da7..73ec48dfe7 100644
--- a/src/printsupport/kernel/qprinterinfo.h
+++ b/src/printsupport/kernel/qprinterinfo.h
@@ -42,9 +42,11 @@
#ifndef QPRINTERINFO_H
#define QPRINTERINFO_H
+#include <QtPrintSupport/qprinter.h>
+
#include <QtCore/QList>
#include <QtCore/QPair>
-#include <QtPrintSupport/QPrinter>
+#include <QtGui/qpagesize.h>
QT_BEGIN_NAMESPACE
@@ -69,12 +71,31 @@ public:
bool isNull() const;
bool isDefault() const;
+ bool isRemote() const;
+
+ QPrinter::PrinterState state() const;
+
+ QList<QPageSize> supportedPageSizes() const;
+ QPageSize defaultPageSize() const;
+
+ bool supportsCustomPageSizes() const;
- QList<QPrinter::PaperSize> supportedPaperSizes() const;
- QList<QPair<QString, QSizeF> > supportedSizesWithNames() const;
+ QPageSize minimumPhysicalPageSize() const;
+ QPageSize maximumPhysicalPageSize() const;
+#if QT_DEPRECATED_SINCE(5,3)
+ QT_DEPRECATED QList<QPrinter::PaperSize> supportedPaperSizes() const;
+ QT_DEPRECATED QList<QPair<QString, QSizeF> > supportedSizesWithNames() const;
+#endif // QT_DEPRECATED_SINCE(5,3)
+
+ QList<int> supportedResolutions() const;
+
+ static QStringList availablePrinterNames();
static QList<QPrinterInfo> availablePrinters();
+
+ static QString defaultPrinterName();
static QPrinterInfo defaultPrinter();
+
static QPrinterInfo printerInfo(const QString &printerName);
private:
diff --git a/src/printsupport/kernel/qprinterinfo_p.h b/src/printsupport/kernel/qprinterinfo_p.h
index 6ae64b5653..7083356e1c 100644
--- a/src/printsupport/kernel/qprinterinfo_p.h
+++ b/src/printsupport/kernel/qprinterinfo_p.h
@@ -57,32 +57,17 @@
#ifndef QT_NO_PRINTER
-#include "QtCore/qlist.h"
-#include "QtCore/qpair.h"
+#include "qprintdevice_p.h"
QT_BEGIN_NAMESPACE
class QPrinterInfoPrivate
{
public:
- QPrinterInfoPrivate(const QString& name = QString()) :
- name(name), isDefault(false), index(-1), hasPaperSizes(false),
- hasPaperNames(false)
- {}
- ~QPrinterInfoPrivate()
- {}
+ QPrinterInfoPrivate(const QString& id = QString());
+ ~QPrinterInfoPrivate();
- QString name;
- QString description;
- QString location;
- QString makeAndModel;
- bool isDefault;
- int index; // Internal printer plugin use only
-
- mutable bool hasPaperSizes;
- mutable QList<QPrinter::PaperSize> paperSizes;
- mutable bool hasPaperNames;
- mutable QList<QPair<QString, QSizeF> > paperNames;
+ QPrintDevice m_printDevice;
};
QT_END_NAMESPACE
diff --git a/src/printsupport/widgets/qcupsjobwidget.cpp b/src/printsupport/widgets/qcupsjobwidget.cpp
index 9940e6a1af..7fd3e0105d 100644
--- a/src/printsupport/widgets/qcupsjobwidget.cpp
+++ b/src/printsupport/widgets/qcupsjobwidget.cpp
@@ -56,6 +56,8 @@
QT_BEGIN_NAMESPACE
+#ifndef QT_NO_PRINTER
+
/*!
\internal
\class QCupsJobWidget
@@ -212,4 +214,6 @@ QCUPSSupport::BannerPage QCupsJobWidget::endBannerPage() const
return m_ui.endBannerPageCombo->itemData(m_ui.endBannerPageCombo->currentIndex()).value<QCUPSSupport::BannerPage>();
}
+#endif // QT_NO_PRINTER
+
QT_END_NAMESPACE
diff --git a/src/printsupport/widgets/qcupsjobwidget_p.h b/src/printsupport/widgets/qcupsjobwidget_p.h
index a5e2bf8083..2a50a12b89 100644
--- a/src/printsupport/widgets/qcupsjobwidget_p.h
+++ b/src/printsupport/widgets/qcupsjobwidget_p.h
@@ -60,6 +60,8 @@
QT_BEGIN_NAMESPACE
+#ifndef QT_NO_PRINTER
+
class QString;
class QTime;
class QPrinter;
@@ -106,6 +108,8 @@ private:
Q_DISABLE_COPY(QCupsJobWidget)
};
+#endif // QT_NO_PRINTER
+
QT_END_NAMESPACE
#endif // QCUPSJOBWIDGET_P_H