summaryrefslogtreecommitdiffstats
path: root/src/printsupport/kernel
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2014-03-17 17:59:55 +0100
committerAndy Shaw <andy.shaw@digia.com>2014-10-24 21:34:21 +0200
commit74a51d590f4acd189f8d0594a5a706cbf97c805b (patch)
tree7be62ff9cdf58e36851576f0a79493f2943abc0b /src/printsupport/kernel
parentddf3fc0deb906ee591fc01ecc2a74768a49950f8 (diff)
QPrinter - Fix DuplexMode on all platforms
Add support to get/set the DuplexMode on Windows and Mac, improve the CUPS duplex handling, ensure support is the same on all platforms. [ChangeLog][QtPrintSupport][QPrinter] Added duplex support for Windows and OS X. Task-number: QTBUG-11332 Change-Id: I9d61d63233d828c3b1fd6df54072c6049f3c6298 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/printsupport/kernel')
-rw-r--r--src/printsupport/kernel/qprintengine_win.cpp54
-rw-r--r--src/printsupport/kernel/qprinter.cpp12
-rw-r--r--src/printsupport/kernel/qprinterinfo.cpp27
-rw-r--r--src/printsupport/kernel/qprinterinfo.h3
4 files changed, 85 insertions, 11 deletions
diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp
index a1a2f97abe..90b204eb0c 100644
--- a/src/printsupport/kernel/qprintengine_win.cpp
+++ b/src/printsupport/kernel/qprintengine_win.cpp
@@ -1003,9 +1003,6 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
// The following keys are settings that are unsupported by the Windows PrintEngine
case PPK_CustomBase:
break;
- case PPK_Duplex:
- // TODO Add support using DEVMODE.dmDuplex
- break;
case PPK_FontEmbedding:
break;
case PPK_PageOrder:
@@ -1046,6 +1043,33 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &
d->docName = value.toString();
break;
+ case PPK_Duplex: {
+ if (!d->devMode)
+ break;
+ QPrint::DuplexMode mode = QPrint::DuplexMode(value.toInt());
+ if (mode == property(PPK_Duplex).toInt() || !d->m_printDevice.supportedDuplexModes().contains(mode))
+ break;
+ switch (mode) {
+ case QPrinter::DuplexNone:
+ d->devMode->dmDuplex = DMDUP_SIMPLEX;
+ break;
+ case QPrinter::DuplexAuto:
+ d->devMode->dmDuplex = d->m_pageLayout.orientation() == QPageLayout::Landscape ? DMDUP_HORIZONTAL : DMDUP_VERTICAL;
+ break;
+ case QPrinter::DuplexLongSide:
+ d->devMode->dmDuplex = DMDUP_VERTICAL;
+ break;
+ case QPrinter::DuplexShortSide:
+ d->devMode->dmDuplex = DMDUP_HORIZONTAL;
+ break;
+ default:
+ // Don't change
+ break;
+ }
+ d->doReinit();
+ break;
+ }
+
case PPK_FullPage:
if (value.toBool())
d->m_pageLayout.setMode(QPageLayout::FullPageMode);
@@ -1260,10 +1284,6 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const
// The following keys are settings that are unsupported by the Windows PrintEngine
// Return sensible default values to ensure consistent behavior across platforms
- case PPK_Duplex:
- // TODO Add support using DEVMODE.dmDuplex
- value = QPrinter::DuplexNone;
- break;
case PPK_FontEmbedding:
value = false;
break;
@@ -1300,6 +1320,26 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const
value = d->docName;
break;
+ case PPK_Duplex: {
+ if (!d->devMode) {
+ value = QPrinter::DuplexNone;
+ } else {
+ switch (d->devMode->dmDuplex) {
+ case DMDUP_VERTICAL:
+ value = QPrinter::DuplexLongSide;
+ break;
+ case DMDUP_HORIZONTAL:
+ value = QPrinter::DuplexShortSide;
+ break;
+ case DMDUP_SIMPLEX:
+ default:
+ value = QPrinter::DuplexNone;
+ break;
+ }
+ }
+ break;
+ }
+
case PPK_FullPage:
value = d->m_pageLayout.mode() == QPageLayout::FullPageMode;
break;
diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp
index 8d62580d67..c13b1574d0 100644
--- a/src/printsupport/kernel/qprinter.cpp
+++ b/src/printsupport/kernel/qprinter.cpp
@@ -1678,9 +1678,11 @@ bool QPrinter::fontEmbeddingEnabled() const
/*!
\since 4.2
+ \obsolete Use setDuplex() instead.
+
Enables double sided printing if \a doubleSided is true; otherwise disables it.
- Currently this option is only supported on X11.
+ \sa setDuplex()
*/
void QPrinter::setDoubleSidedPrinting(bool doubleSided)
{
@@ -1691,9 +1693,11 @@ void QPrinter::setDoubleSidedPrinting(bool doubleSided)
/*!
\since 4.2
+ \obsolete Use duplex() instead.
+
Returns \c true if double side printing is enabled.
- Currently this option is only supported on X11.
+ \sa duplex()
*/
bool QPrinter::doubleSidedPrinting() const
{
@@ -1705,7 +1709,7 @@ bool QPrinter::doubleSidedPrinting() const
Enables double sided printing based on the \a duplex mode.
- Currently this option is only supported on X11.
+ \sa duplex()
*/
void QPrinter::setDuplex(DuplexMode duplex)
{
@@ -1718,7 +1722,7 @@ void QPrinter::setDuplex(DuplexMode duplex)
Returns the current duplex mode.
- Currently this option is only supported on X11.
+ \sa setDuplex()
*/
QPrinter::DuplexMode QPrinter::duplex() const
{
diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp
index b1321bf57a..a17da3fdaa 100644
--- a/src/printsupport/kernel/qprinterinfo.cpp
+++ b/src/printsupport/kernel/qprinterinfo.cpp
@@ -353,6 +353,33 @@ QList<int> QPrinterInfo::supportedResolutions() const
}
/*!
+ Returns the default duplex mode of this printer.
+
+ \since 5.4
+*/
+
+QPrinter::DuplexMode QPrinterInfo::defaultDuplexMode() const
+{
+ Q_D(const QPrinterInfo);
+ return QPrinter::DuplexMode(d->m_printDevice.defaultDuplexMode());
+}
+
+/*!
+ Returns a list of duplex modes supported by this printer.
+
+ \since 5.4
+*/
+
+QList<QPrinter::DuplexMode> QPrinterInfo::supportedDuplexModes() const
+{
+ Q_D(const QPrinterInfo);
+ QList<QPrinter::DuplexMode> list;
+ foreach (QPrint::DuplexMode mode, d->m_printDevice.supportedDuplexModes())
+ list << QPrinter::DuplexMode(mode);
+ return list;
+}
+
+/*!
Returns a list of all the available Printer Names on this system.
It is recommended to use this instead of availablePrinters() as
diff --git a/src/printsupport/kernel/qprinterinfo.h b/src/printsupport/kernel/qprinterinfo.h
index a4754c48dc..58d3873492 100644
--- a/src/printsupport/kernel/qprinterinfo.h
+++ b/src/printsupport/kernel/qprinterinfo.h
@@ -82,6 +82,9 @@ public:
QList<int> supportedResolutions() const;
+ QPrinter::DuplexMode defaultDuplexMode() const;
+ QList<QPrinter::DuplexMode> supportedDuplexModes() const;
+
static QStringList availablePrinterNames();
static QList<QPrinterInfo> availablePrinters();