cups: Support raw printers

They don't have a ppd but we don't *really* need a ppd to just print

Change-Id: Idf6b6dafc19420a511b057194488e2170cae4d70
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
bb10
Albert Astals Cid 2018-02-05 09:20:20 +01:00
parent 40a15ecaad
commit 84cc8d0bad
3 changed files with 19 additions and 14 deletions

View File

@ -104,7 +104,11 @@ void QCupsPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &v
break;
case PPK_QPageLayout: {
QPageLayout pageLayout = value.value<QPageLayout>();
if (pageLayout.isValid() && (d->m_printDevice.isValidPageLayout(pageLayout, d->resolution) || d->m_printDevice.supportsCustomPageSizes())) {
if (pageLayout.isValid() && (d->m_printDevice.isValidPageLayout(pageLayout, d->resolution)
|| d->m_printDevice.supportsCustomPageSizes()
|| d->m_printDevice.supportedPageSizes().isEmpty())) {
// supportedPageSizes().isEmpty() because QPageSetupWidget::initPageSizes says
// "If no available printer page sizes, populate with all page sizes"
d->m_pageLayout = pageLayout;
d->setPageSize(pageLayout.pageSize());
}

View File

@ -75,14 +75,13 @@ QPpdPrintDevice::QPpdPrintDevice(const QString &id)
ppdMarkDefaults(m_ppd);
cupsMarkOptions(m_ppd, m_cupsDest->num_options, m_cupsDest->options);
ppdLocalize(m_ppd);
} else {
cupsFreeDests(1, m_cupsDest);
m_cupsDest = nullptr;
m_ppd = nullptr;
}
}
if (m_cupsDest && m_ppd) {
m_minimumPhysicalPageSize = QSize(m_ppd->custom_min[0], m_ppd->custom_min[1]);
m_maximumPhysicalPageSize = QSize(m_ppd->custom_max[0], m_ppd->custom_max[1]);
m_customMargins = QMarginsF(m_ppd->custom_margins[0], m_ppd->custom_margins[3],
m_ppd->custom_margins[2], m_ppd->custom_margins[1]);
}
m_name = printerOption("printer-info");
m_location = printerOption("printer-location");
m_makeAndModel = printerOption("printer-make-and-model");
@ -98,10 +97,6 @@ QPpdPrintDevice::QPpdPrintDevice(const QString &id)
// Cups ppd_file_t variable_sizes custom_min custom_max
// PPD MaxMediaWidth MaxMediaHeight
m_supportsCustomPageSizes = type & CUPS_PRINTER_VARIABLE;
m_minimumPhysicalPageSize = QSize(m_ppd->custom_min[0], m_ppd->custom_min[1]);
m_maximumPhysicalPageSize = QSize(m_ppd->custom_max[0], m_ppd->custom_max[1]);
m_customMargins = QMarginsF(m_ppd->custom_margins[0], m_ppd->custom_margins[3],
m_ppd->custom_margins[2], m_ppd->custom_margins[1]);
}
}
}
@ -118,7 +113,7 @@ QPpdPrintDevice::~QPpdPrintDevice()
bool QPpdPrintDevice::isValid() const
{
return m_cupsDest && m_ppd;
return m_cupsDest;
}
bool QPpdPrintDevice::isDefault() const
@ -163,8 +158,8 @@ void QPpdPrintDevice::loadPageSizes() const
}
}
}
m_havePageSizes = true;
}
m_havePageSizes = true;
}
QPageSize QPpdPrintDevice::defaultPageSize() const

View File

@ -424,6 +424,12 @@ void QPageSetupWidget::setPrinter(QPrinter *printer, QPrintDevice *printDevice,
initPageSizes();
updateWidget();
updateSavedValues();
if (m_ui.pageSizeCombo->currentIndex() == -1) {
// This can happen in raw printers that since they don't have a default
// page size none will get selected so just default to the first size (A4)
m_ui.pageSizeCombo->setCurrentIndex(0);
}
}
// Update the widget with the current settings