diff options
Diffstat (limited to 'src/printsupport/dialogs/qpagesetupdialog_unix.cpp')
-rw-r--r-- | src/printsupport/dialogs/qpagesetupdialog_unix.cpp | 69 |
1 files changed, 66 insertions, 3 deletions
diff --git a/src/printsupport/dialogs/qpagesetupdialog_unix.cpp b/src/printsupport/dialogs/qpagesetupdialog_unix.cpp index 7e32f9aa57..d9b4a84aa9 100644 --- a/src/printsupport/dialogs/qpagesetupdialog_unix.cpp +++ b/src/printsupport/dialogs/qpagesetupdialog_unix.cpp @@ -49,6 +49,7 @@ #include "qpainter.h" #include "qprintdialog.h" +#include "qtextcodec.h" #include "qdialogbuttonbox.h" #include <ui_qpagesetupwidget.h> @@ -235,6 +236,9 @@ QPageSetupWidget::QPageSetupWidget(QWidget *parent) m_pagePreview(nullptr), m_printer(nullptr), m_printDevice(nullptr), +#if QT_CONFIG(cups) + m_pageSizePpdOption(nullptr), +#endif m_outputFormat(QPrinter::PdfFormat), m_units(QPageLayout::Point), m_savedUnits(QPageLayout::Point), @@ -391,6 +395,11 @@ void QPageSetupWidget::setPrinter(QPrinter *printer, QPrintDevice *printDevice, m_printer = printer; m_printDevice = printDevice; +#if QT_CONFIG(cups) + // find the PageSize cups option + m_pageSizePpdOption = m_printDevice ? QCUPSSupport::findPpdOption("PageSize", m_printDevice) : nullptr; +#endif + // Initialize the layout to the current QPrinter layout m_pageLayout = m_printer->pageLayout(); @@ -415,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 @@ -547,15 +562,48 @@ void QPageSetupWidget::revertToSavedValues() m_ui.pagesPerSheetLayoutCombo->setCurrentIndex(m_savedPagesPerSheetLayout); } +#if QT_CONFIG(cups) +bool QPageSetupWidget::hasPpdConflict() const +{ + if (m_pageSizePpdOption) { + if (m_pageSizePpdOption->conflicted) { + const QIcon warning = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning, nullptr, nullptr); + const int pixmap_size = m_ui.pageSizeCombo->sizeHint().height() * .75; + m_ui.pageSizeWarningLabel->setPixmap(warning.pixmap(pixmap_size, pixmap_size)); + } else { + m_ui.pageSizeWarningLabel->setPixmap(QPixmap()); + } + return m_pageSizePpdOption->conflicted; + } + + return false; +} +#endif + // Updates size/preview after the combobox has been changed. void QPageSetupWidget::pageSizeChanged() { - if (m_blockSignals) - return; - QPageSize pageSize; if (m_ui.pageSizeCombo->currentIndex() != m_realCustomPageSizeIndex) { pageSize = m_ui.pageSizeCombo->currentData().value<QPageSize>(); + +#if QT_CONFIG(cups) + if (m_pageSizePpdOption) { + ppd_file_t *ppd = m_printDevice->property(PDPK_PpdFile).value<ppd_file_t*>(); + QTextCodec *cupsCodec = QTextCodec::codecForName(ppd->lang_encoding); + for (int i = 0; i < m_pageSizePpdOption->num_choices; ++i) { + const ppd_choice_t *choice = &m_pageSizePpdOption->choices[i]; + if (cupsCodec->toUnicode(choice->text) == m_ui.pageSizeCombo->currentText()) { + const auto values = QStringList{} << QString::fromLatin1(m_pageSizePpdOption->keyword) + << QString::fromLatin1(choice->choice); + m_printDevice->setProperty(PDPK_PpdOption, values); + emit ppdOptionChanged(); + break; + } + } + } +#endif + } else { QSizeF customSize; if (m_pageLayout.orientation() == QPageLayout::Landscape) @@ -563,7 +611,22 @@ void QPageSetupWidget::pageSizeChanged() else customSize = QSizeF(m_ui.pageWidth->value(), m_ui.pageHeight->value()); pageSize = QPageSize(customSize, QPageSize::Unit(m_units)); + +#if QT_CONFIG(cups) + if (m_pageSizePpdOption) { + const auto values = QStringList{} << QString::fromLatin1(m_pageSizePpdOption->keyword) + << QStringLiteral("Custom"); + m_printDevice->setProperty(PDPK_PpdOption, values); + emit ppdOptionChanged(); + } +#endif } + + // We always need to update the m_pageSizePpdOption when the page size changes + // even if it's from inside updateWidget, so do not move up + if (m_blockSignals) + return; + const QMarginsF printable = m_printDevice ? m_printDevice->printableMargins(pageSize, m_pageLayout.orientation(), m_printer->resolution()) : QMarginsF(); m_pageLayout.setPageSize(pageSize, qt_convertMargins(printable, QPageLayout::Point, m_pageLayout.units())); |