From 9a2dbcab7e820c63aac55ba08dc120a56986efac Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 13 May 2014 14:08:05 +0200 Subject: QPrinter/Windows: Fix handling of native paper source ids. On Windows, it is possible to pass native Windows paper source ids >= DMBIN_USER to QPrinter::setPaperSource() and they are listed by supportedPaperSources(). Task-number: QTBUG-38897 Task-number: QTBUG-38888 Change-Id: I8f1264e80ce5bdddd3873602200b24eabee00502 Reviewed-by: Lars Knoll Reviewed-by: Andy Shaw --- src/printsupport/kernel/qprintengine_win.cpp | 48 ++++++++++++++++++---------- 1 file changed, 32 insertions(+), 16 deletions(-) (limited to 'src/printsupport/kernel') diff --git a/src/printsupport/kernel/qprintengine_win.cpp b/src/printsupport/kernel/qprintengine_win.cpp index 52b67d162b..427af13edf 100644 --- a/src/printsupport/kernel/qprintengine_win.cpp +++ b/src/printsupport/kernel/qprintengine_win.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -972,6 +972,24 @@ void QWin32PrintEnginePrivate::doReinit() } } +static int indexOfId(const QList &inputSlots, QPrint::InputSlotId id) +{ + for (int i = 0; i < inputSlots.size(); ++i) { + if (inputSlots.at(i).id == id) + return i; + } + return -1; +} + +static int indexOfWindowsId(const QList &inputSlots, int windowsId) +{ + for (int i = 0; i < inputSlots.size(); ++i) { + if (inputSlots.at(i).windowsId == windowsId) + return i; + } + return -1; +} + void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value) { Q_D(QWin32PrintEngine); @@ -1114,14 +1132,12 @@ void QWin32PrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant & case PPK_PaperSource: { if (!d->devMode) break; - QPrint::InputSlotId inputSlotId = QPrint::InputSlotId(value.toInt()); - foreach (const QPrint::InputSlot &inputSlot, d->m_printDevice.supportedInputSlots()) { - if (inputSlot.id == inputSlotId) { - d->devMode->dmDefaultSource = inputSlot.windowsId; - d->doReinit(); - break; - } - } + const QList inputSlots = d->m_printDevice.supportedInputSlots(); + const int paperSource = value.toInt(); + const int index = paperSource >= DMBIN_USER ? + indexOfWindowsId(inputSlots, paperSource) : indexOfId(inputSlots, QPrint::InputSlotId(paperSource)); + d->devMode->dmDefaultSource = index >= 0 ? inputSlots.at(index).windowsId : DMBIN_AUTO; + d->doReinit(); break; } @@ -1337,12 +1353,12 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const if (!d->devMode) { value = d->m_printDevice.defaultInputSlot().id; } else { - value = QPrint::Auto; - foreach (const QPrint::InputSlot inputSlot, d->m_printDevice.supportedInputSlots()) { - if (inputSlot.windowsId == d->devMode->dmDefaultSource) { - value = inputSlot.id; - break; - } + if (d->devMode->dmDefaultSource >= DMBIN_USER) { + value = int(d->devMode->dmDefaultSource); + } else { + const QList inputSlots = d->m_printDevice.supportedInputSlots(); + const int index = indexOfWindowsId(inputSlots, d->devMode->dmDefaultSource); + value = index >= 0 ? inputSlots.at(index).id : QPrint::Auto; } } break; @@ -1371,7 +1387,7 @@ QVariant QWin32PrintEngine::property(PrintEnginePropertyKey key) const case PPK_PaperSources: { QList out; foreach (const QPrint::InputSlot inputSlot, d->m_printDevice.supportedInputSlots()) - out << inputSlot.id; + out << QVariant(inputSlot.id == QPrint::CustomInputSlot ? inputSlot.windowsId : int(inputSlot.id)); value = out; break; } -- cgit v1.2.3