Unix: QPageSetupDialog: Use print device default paper size
When invoking QPageSetupDialog from QPrintPreviewDialog, don't construct a new QPageSetupDialog every time the pageSetup action is triggered, instead reuse the dialog if it's already been created. This way setPrinter is called only once. This matches how QPrintDialog invokes QPageSetupDialog. Set the default print device paper size in initPageSizes() instead of setPrinter(). Change-Id: Ic82e6dd47ee00ecdd942c5ba59dbf09fb18ef218 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io> Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
parent
c93670c5a0
commit
ac7f46dd91
@ -361,13 +361,21 @@ void QPageSetupWidget::initPageSizes()
|
||||
QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();
|
||||
if (ps) {
|
||||
QPrintDevice printDevice = ps->createPrintDevice(m_printerName);
|
||||
const QPageSize defaultSize = printDevice.defaultPageSize();
|
||||
const auto pageSizes = printDevice.supportedPageSizes();
|
||||
for (const QPageSize &pageSize : pageSizes)
|
||||
m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize));
|
||||
if (m_ui.pageSizeCombo->count() > 0 && printDevice.supportsCustomPageSizes()) {
|
||||
m_ui.pageSizeCombo->addItem(tr("Custom"));
|
||||
m_realCustomPageSizeIndex = m_ui.pageSizeCombo->count() - 1;
|
||||
if (m_ui.pageSizeCombo->count() > 0) {
|
||||
if (printDevice.supportsCustomPageSizes()) {
|
||||
m_ui.pageSizeCombo->addItem(tr("Custom"));
|
||||
m_realCustomPageSizeIndex = m_ui.pageSizeCombo->count() - 1;
|
||||
}
|
||||
m_blockSignals = false;
|
||||
|
||||
// If the defaultSize is index 0, setCurrentIndex won't emit the currentIndexChanged
|
||||
// signal; workaround the issue by initially setting the currentIndex to -1
|
||||
m_ui.pageSizeCombo->setCurrentIndex(-1);
|
||||
m_ui.pageSizeCombo->setCurrentIndex(m_ui.pageSizeCombo->findData(QVariant::fromValue(defaultSize)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -403,12 +411,6 @@ void QPageSetupWidget::setPrinter(QPrinter *printer, QPrintDevice *printDevice,
|
||||
// Initialize the layout to the current QPrinter layout
|
||||
m_pageLayout = m_printer->pageLayout();
|
||||
|
||||
if (printDevice) {
|
||||
const QPageSize pageSize = printDevice->defaultPageSize();
|
||||
const QMarginsF printable = printDevice->printableMargins(pageSize, m_pageLayout.orientation(), m_printer->resolution());
|
||||
m_pageLayout.setPageSize(pageSize, qt_convertMargins(printable, QPageLayout::Point, m_pageLayout.units()));
|
||||
}
|
||||
|
||||
// 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)
|
||||
@ -735,8 +737,12 @@ int QPageSetupDialog::exec()
|
||||
Q_D(QPageSetupDialog);
|
||||
|
||||
int ret = QDialog::exec();
|
||||
if (ret == Accepted)
|
||||
if (ret == Accepted) {
|
||||
static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->setupPrinter();
|
||||
static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->updateSavedValues();
|
||||
} else {
|
||||
static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->revertToSavedValues();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -152,8 +152,8 @@ class QPrintPreviewDialogPrivate : public QDialogPrivate
|
||||
Q_DECLARE_PUBLIC(QPrintPreviewDialog)
|
||||
public:
|
||||
QPrintPreviewDialogPrivate()
|
||||
: printDialog(nullptr), ownPrinter(false),
|
||||
initialized(false) {}
|
||||
: printDialog(nullptr), pageSetupDialog(nullptr),
|
||||
ownPrinter(false), initialized(false) {}
|
||||
|
||||
// private slots
|
||||
void _q_fit(QAction *action);
|
||||
@ -178,6 +178,7 @@ public:
|
||||
void updateZoomFactor();
|
||||
|
||||
QPrintDialog *printDialog;
|
||||
QPageSetupDialog *pageSetupDialog;
|
||||
QPrintPreviewWidget *preview;
|
||||
QPrinter *printer;
|
||||
bool ownPrinter;
|
||||
@ -602,8 +603,10 @@ void QPrintPreviewDialogPrivate::_q_pageSetup()
|
||||
{
|
||||
Q_Q(QPrintPreviewDialog);
|
||||
|
||||
QPageSetupDialog pageSetup(printer, q);
|
||||
if (pageSetup.exec() == QDialog::Accepted) {
|
||||
if (!pageSetupDialog)
|
||||
pageSetupDialog = new QPageSetupDialog(printer, q);
|
||||
|
||||
if (pageSetupDialog->exec() == QDialog::Accepted) {
|
||||
// update possible orientation changes
|
||||
if (preview->orientation() == QPrinter::Portrait) {
|
||||
portraitAction->setChecked(true);
|
||||
@ -713,6 +716,7 @@ QPrintPreviewDialog::~QPrintPreviewDialog()
|
||||
if (d->ownPrinter)
|
||||
delete d->printer;
|
||||
delete d->printDialog;
|
||||
delete d->pageSetupDialog;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
Reference in New Issue
Block a user