From f05e48381b309447297a290f699a3389ac41af41 Mon Sep 17 00:00:00 2001 From: John Layt Date: Mon, 20 Jan 2014 15:40:23 +0100 Subject: QPrintEngine - Improve devMode handling Improve the sharing of the devMode between the QPrintEngine and the print dialogs, in particular start to change the dialogs from directly accessing the QPrintEngine internals. Change-Id: Ieb4649c19b936433c85207297a0b6e59356c3880 Reviewed-by: Lars Knoll --- src/printsupport/dialogs/qpagesetupdialog_win.cpp | 15 ++++++--------- src/printsupport/dialogs/qprintdialog_win.cpp | 15 ++++++++------- 2 files changed, 14 insertions(+), 16 deletions(-) (limited to 'src/printsupport/dialogs') diff --git a/src/printsupport/dialogs/qpagesetupdialog_win.cpp b/src/printsupport/dialogs/qpagesetupdialog_win.cpp index 688f4ac314..345e698b82 100644 --- a/src/printsupport/dialogs/qpagesetupdialog_win.cpp +++ b/src/printsupport/dialogs/qpagesetupdialog_win.cpp @@ -82,7 +82,7 @@ int QPageSetupDialog::exec() // we need a temp DEVMODE struct if we don't have a global DEVMODE HGLOBAL hDevMode = 0; int devModeSize = 0; - if (!ep->globalDevMode) { + if (!engine->globalDevMode()) { devModeSize = sizeof(DEVMODE) + ep->devMode->dmDriverExtra; hDevMode = GlobalAlloc(GHND, devModeSize); if (hDevMode) { @@ -92,10 +92,10 @@ int QPageSetupDialog::exec() } psd.hDevMode = hDevMode; } else { - psd.hDevMode = ep->devMode; + psd.hDevMode = engine->globalDevMode(); } - HGLOBAL *tempDevNames = ep->createDevNames(); + HGLOBAL *tempDevNames = engine->createGlobalDevNames(); psd.hDevNames = tempDevNames; QWidget *parent = parentWidget(); @@ -129,8 +129,7 @@ int QPageSetupDialog::exec() bool result = PageSetupDlg(&psd); QDialog::setVisible(false); if (result) { - ep->readDevnames(psd.hDevNames); - ep->readDevmode(psd.hDevMode); + engine->setGlobalDevMode(psd.hDevNames, psd.hDevMode); QRect theseMargins = QRect(psd.rtMargin.left * multiplier, psd.rtMargin.top * multiplier, @@ -144,17 +143,15 @@ int QPageSetupDialog::exec() psd.rtMargin.bottom * multiplier); } - ep->updateCustomPaperSize(); - // copy from our temp DEVMODE struct - if (!ep->globalDevMode && hDevMode) { + if (!engine->globalDevMode() && hDevMode) { void *src = GlobalLock(hDevMode); memcpy(ep->devMode, src, devModeSize); GlobalUnlock(hDevMode); } } - if (!ep->globalDevMode && hDevMode) + if (!engine->globalDevMode() && hDevMode) GlobalFree(hDevMode); GlobalFree(tempDevNames); done(result); diff --git a/src/printsupport/dialogs/qprintdialog_win.cpp b/src/printsupport/dialogs/qprintdialog_win.cpp index 9d972ef5c4..722f0e186f 100644 --- a/src/printsupport/dialogs/qprintdialog_win.cpp +++ b/src/printsupport/dialogs/qprintdialog_win.cpp @@ -68,12 +68,13 @@ class QPrintDialogPrivate : public QAbstractPrintDialogPrivate Q_DECLARE_PUBLIC(QPrintDialog) public: QPrintDialogPrivate() - : ep(0) + : engine(0), ep(0) { } int openWindowsPrintDialogModally(); + QWin32PrintEngine *engine; QWin32PrintEnginePrivate *ep; }; @@ -141,7 +142,7 @@ static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent, pd->hwndOwner = parentWindow ? (HWND)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", parentWindow) : 0; pd->lpPageRanges[0].nFromPage = qMax(pdlg->fromPage(), pdlg->minPage()); pd->lpPageRanges[0].nToPage = (pdlg->toPage() > 0) ? qMin(pdlg->toPage(), pdlg->maxPage()) : 1; - pd->nCopies = d->ep->num_copies; + pd->nCopies = d->printer->copyCount(); } static void qt_win_read_back_PRINTDLGEX(PRINTDLGEX *pd, QPrintDialog *pdlg, QPrintDialogPrivate *d) @@ -162,9 +163,7 @@ static void qt_win_read_back_PRINTDLGEX(PRINTDLGEX *pd, QPrintDialog *pdlg, QPri d->ep->printToFile = (pd->Flags & PD_PRINTTOFILE) != 0; - d->ep->readDevnames(pd->hDevNames); - d->ep->readDevmode(pd->hDevMode); - d->ep->updateCustomPaperSize(); + d->engine->setGlobalDevMode(pd->hDevNames, pd->hDevMode); if (d->ep->printToFile && d->ep->fileName.isEmpty()) d->ep->fileName = QLatin1String("FILE:"); @@ -187,6 +186,7 @@ QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent) Q_D(QPrintDialog); if (!warnIfNotNative(d->printer)) return; + d->engine = static_cast(d->printer->printEngine()); d->ep = static_cast(d->printer->printEngine())->d_func(); setAttribute(Qt::WA_DontShowOnScreen); } @@ -197,6 +197,7 @@ QPrintDialog::QPrintDialog(QWidget *parent) Q_D(QPrintDialog); if (!warnIfNotNative(d->printer)) return; + d->engine = static_cast(d->printer->printEngine()); d->ep = static_cast(d->printer->printEngine())->d_func(); setAttribute(Qt::WA_DontShowOnScreen); } @@ -229,7 +230,7 @@ int QPrintDialogPrivate::openWindowsPrintDialogModally() q->QDialog::setVisible(true); - HGLOBAL *tempDevNames = ep->createDevNames(); + HGLOBAL *tempDevNames = engine->createGlobalDevNames(); bool done; bool result; @@ -278,7 +279,7 @@ int QPrintDialogPrivate::openWindowsPrintDialogModally() { qt_win_read_back_PRINTDLGEX(&pd, q, this); // update printer validity - printer->d_func()->validPrinter = !ep->name.isEmpty(); + printer->d_func()->validPrinter = !printer->printerName().isEmpty(); } // Cleanup... -- cgit v1.2.3