Unix: Fix page size margins when changing page size

Change-Id: I55435cf500c656eeec61e6c61bbf195df356ffeb
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Albert Astals Cid 2018-01-12 15:02:31 +01:00 committed by Frederik Gladhorn
parent f56f47bc64
commit e0b769eeda
2 changed files with 9 additions and 5 deletions

View File

@ -234,6 +234,7 @@ QPageSetupWidget::QPageSetupWidget(QWidget *parent)
: QWidget(parent), : QWidget(parent),
m_pagePreview(nullptr), m_pagePreview(nullptr),
m_printer(nullptr), m_printer(nullptr),
m_printDevice(nullptr),
m_outputFormat(QPrinter::PdfFormat), m_outputFormat(QPrinter::PdfFormat),
m_units(QPageLayout::Point), m_units(QPageLayout::Point),
m_savedUnits(QPageLayout::Point), m_savedUnits(QPageLayout::Point),
@ -388,6 +389,7 @@ void QPageSetupWidget::setPrinter(QPrinter *printer, QPrintDevice *printDevice,
QPrinter::OutputFormat outputFormat, const QString &printerName) QPrinter::OutputFormat outputFormat, const QString &printerName)
{ {
m_printer = printer; m_printer = printer;
m_printDevice = printDevice;
// Initialize the layout to the current QPrinter layout // Initialize the layout to the current QPrinter layout
m_pageLayout = m_printer->pageLayout(); m_pageLayout = m_printer->pageLayout();
@ -551,19 +553,20 @@ void QPageSetupWidget::pageSizeChanged()
if (m_blockSignals) if (m_blockSignals)
return; return;
QPageSize pageSize;
if (m_ui.pageSizeCombo->currentIndex() != m_realCustomPageSizeIndex) { if (m_ui.pageSizeCombo->currentIndex() != m_realCustomPageSizeIndex) {
const QPageSize pageSize = m_ui.pageSizeCombo->currentData().value<QPageSize>(); pageSize = m_ui.pageSizeCombo->currentData().value<QPageSize>();
// TODO Set layout margin min/max to printer custom min/max
m_pageLayout.setPageSize(pageSize);
} else { } else {
QSizeF customSize; QSizeF customSize;
if (m_pageLayout.orientation() == QPageLayout::Landscape) if (m_pageLayout.orientation() == QPageLayout::Landscape)
customSize = QSizeF(m_ui.pageHeight->value(), m_ui.pageWidth->value()); customSize = QSizeF(m_ui.pageHeight->value(), m_ui.pageWidth->value());
else else
customSize = QSizeF(m_ui.pageWidth->value(), m_ui.pageHeight->value()); customSize = QSizeF(m_ui.pageWidth->value(), m_ui.pageHeight->value());
// TODO Set layout margin min/max to printer min/max for page size pageSize = QPageSize(customSize, QPageSize::Unit(m_units));
m_pageLayout.setPageSize(QPageSize(customSize, QPageSize::Unit(m_units)));
} }
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()));
m_pagePreview->setPageLayout(m_pageLayout); m_pagePreview->setPageLayout(m_pageLayout);
updateWidget(); updateWidget();

View File

@ -99,6 +99,7 @@ private:
Ui::QPageSetupWidget m_ui; Ui::QPageSetupWidget m_ui;
QPagePreview *m_pagePreview; QPagePreview *m_pagePreview;
QPrinter *m_printer; QPrinter *m_printer;
QPrintDevice *m_printDevice;
QPrinter::OutputFormat m_outputFormat; QPrinter::OutputFormat m_outputFormat;
QString m_printerName; QString m_printerName;
QPageLayout m_pageLayout; QPageLayout m_pageLayout;