summaryrefslogtreecommitdiffstats
path: root/src/printsupport
diff options
context:
space:
mode:
Diffstat (limited to 'src/printsupport')
-rw-r--r--src/printsupport/dialogs/dialogs.pri43
-rw-r--r--src/printsupport/dialogs/images/fit-page-24.pngbin0 -> 985 bytes
-rw-r--r--src/printsupport/dialogs/images/fit-page-32.pngbin0 -> 1330 bytes
-rw-r--r--src/printsupport/dialogs/images/fit-width-24.pngbin0 -> 706 bytes
-rw-r--r--src/printsupport/dialogs/images/fit-width-32.pngbin0 -> 1004 bytes
-rw-r--r--src/printsupport/dialogs/images/go-first-24.pngbin0 -> 796 bytes
-rw-r--r--src/printsupport/dialogs/images/go-first-32.pngbin0 -> 985 bytes
-rw-r--r--src/printsupport/dialogs/images/go-last-24.pngbin0 -> 792 bytes
-rw-r--r--src/printsupport/dialogs/images/go-last-32.pngbin0 -> 984 bytes
-rw-r--r--src/printsupport/dialogs/images/go-next-24.pngbin0 -> 782 bytes
-rw-r--r--src/printsupport/dialogs/images/go-next-32.pngbin0 -> 948 bytes
-rw-r--r--src/printsupport/dialogs/images/go-previous-24.pngbin0 -> 797 bytes
-rw-r--r--src/printsupport/dialogs/images/go-previous-32.pngbin0 -> 945 bytes
-rw-r--r--src/printsupport/dialogs/images/layout-landscape-24.pngbin0 -> 820 bytes
-rw-r--r--src/printsupport/dialogs/images/layout-landscape-32.pngbin0 -> 1353 bytes
-rw-r--r--src/printsupport/dialogs/images/layout-portrait-24.pngbin0 -> 817 bytes
-rw-r--r--src/printsupport/dialogs/images/layout-portrait-32.pngbin0 -> 1330 bytes
-rw-r--r--src/printsupport/dialogs/images/page-setup-24.pngbin0 -> 620 bytes
-rw-r--r--src/printsupport/dialogs/images/page-setup-32.pngbin0 -> 1154 bytes
-rw-r--r--src/printsupport/dialogs/images/print-24.pngbin0 -> 914 bytes
-rw-r--r--src/printsupport/dialogs/images/print-32.pngbin0 -> 1202 bytes
-rw-r--r--src/printsupport/dialogs/images/status-color.pngbin0 -> 1475 bytes
-rw-r--r--src/printsupport/dialogs/images/status-gray-scale.pngbin0 -> 1254 bytes
-rw-r--r--src/printsupport/dialogs/images/view-page-multi-24.pngbin0 -> 390 bytes
-rw-r--r--src/printsupport/dialogs/images/view-page-multi-32.pngbin0 -> 556 bytes
-rw-r--r--src/printsupport/dialogs/images/view-page-one-24.pngbin0 -> 662 bytes
-rw-r--r--src/printsupport/dialogs/images/view-page-one-32.pngbin0 -> 810 bytes
-rw-r--r--src/printsupport/dialogs/images/view-page-sided-24.pngbin0 -> 700 bytes
-rw-r--r--src/printsupport/dialogs/images/view-page-sided-32.pngbin0 -> 908 bytes
-rw-r--r--src/printsupport/dialogs/images/zoom-in-24.pngbin0 -> 1302 bytes
-rw-r--r--src/printsupport/dialogs/images/zoom-in-32.pngbin0 -> 1873 bytes
-rw-r--r--src/printsupport/dialogs/images/zoom-out-24.pngbin0 -> 1247 bytes
-rw-r--r--src/printsupport/dialogs/images/zoom-out-32.pngbin0 -> 1749 bytes
-rw-r--r--src/printsupport/dialogs/qabstractpagesetupdialog.cpp139
-rw-r--r--src/printsupport/dialogs/qabstractpagesetupdialog.h82
-rw-r--r--src/printsupport/dialogs/qabstractpagesetupdialog_p.h88
-rw-r--r--src/printsupport/dialogs/qabstractprintdialog.cpp499
-rw-r--r--src/printsupport/dialogs/qabstractprintdialog.h130
-rw-r--r--src/printsupport/dialogs/qabstractprintdialog_p.h99
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog.cpp240
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog.h112
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_mac.mm315
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_unix.cpp620
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_unix_p.h105
-rw-r--r--src/printsupport/dialogs/qpagesetupdialog_win.cpp168
-rw-r--r--src/printsupport/dialogs/qpagesetupwidget.ui353
-rw-r--r--src/printsupport/dialogs/qprintdialog.h174
-rw-r--r--src/printsupport/dialogs/qprintdialog.qdoc58
-rw-r--r--src/printsupport/dialogs/qprintdialog.qrc38
-rw-r--r--src/printsupport/dialogs/qprintdialog_mac.mm429
-rw-r--r--src/printsupport/dialogs/qprintdialog_unix.cpp1286
-rw-r--r--src/printsupport/dialogs/qprintdialog_win.cpp316
-rw-r--r--src/printsupport/dialogs/qprintpreviewdialog.cpp803
-rw-r--r--src/printsupport/dialogs/qprintpreviewdialog.h108
-rw-r--r--src/printsupport/dialogs/qprintpropertieswidget.ui70
-rw-r--r--src/printsupport/dialogs/qprintsettingsoutput.ui363
-rw-r--r--src/printsupport/dialogs/qprintwidget.ui116
-rw-r--r--src/printsupport/kernel/kernel.pri34
-rw-r--r--src/printsupport/kernel/qcups.cpp446
-rw-r--r--src/printsupport/kernel/qcups_p.h133
-rw-r--r--src/printsupport/kernel/qpaintengine_alpha.cpp516
-rw-r--r--src/printsupport/kernel/qpaintengine_alpha_p.h135
-rw-r--r--src/printsupport/kernel/qpaintengine_preview.cpp223
-rw-r--r--src/printsupport/kernel/qpaintengine_preview_p.h106
-rw-r--r--src/printsupport/kernel/qplatformprintersupport_qpa.cpp133
-rw-r--r--src/printsupport/kernel/qplatformprintersupport_qpa.h84
-rw-r--r--src/printsupport/kernel/qplatformprintplugin.cpp72
-rw-r--r--src/printsupport/kernel/qplatformprintplugin_qpa.h94
-rw-r--r--src/printsupport/kernel/qprintengine.h119
-rw-r--r--src/printsupport/kernel/qprintengine_pdf.cpp662
-rw-r--r--src/printsupport/kernel/qprintengine_pdf_p.h165
-rw-r--r--src/printsupport/kernel/qprinter.cpp2254
-rw-r--r--src/printsupport/kernel/qprinter.h277
-rw-r--r--src/printsupport/kernel/qprinter_p.h136
-rw-r--r--src/printsupport/kernel/qprinterinfo.cpp199
-rw-r--r--src/printsupport/kernel/qprinterinfo.h91
-rw-r--r--src/printsupport/kernel/qprinterinfo_p.h108
-rw-r--r--src/printsupport/kernel/qprinterinfo_unix.cpp857
-rw-r--r--src/printsupport/kernel/qprinterinfo_unix_p.h130
-rw-r--r--src/printsupport/printsupport.pro22
-rw-r--r--src/printsupport/widgets/qprintpreviewwidget.cpp844
-rw-r--r--src/printsupport/widgets/qprintpreviewwidget.h127
-rw-r--r--src/printsupport/widgets/widgets.pri2
83 files changed, 14723 insertions, 0 deletions
diff --git a/src/printsupport/dialogs/dialogs.pri b/src/printsupport/dialogs/dialogs.pri
new file mode 100644
index 0000000000..5dbaa9fec3
--- /dev/null
+++ b/src/printsupport/dialogs/dialogs.pri
@@ -0,0 +1,43 @@
+# Qt dialogs module
+
+HEADERS += \
+ dialogs/qabstractprintdialog.h \
+ dialogs/qabstractprintdialog_p.h \
+ dialogs/qabstractpagesetupdialog.h \
+ dialogs/qabstractpagesetupdialog_p.h \
+ dialogs/qpagesetupdialog.h \
+ dialogs/qprintdialog.h \
+ dialogs/qprintpreviewdialog.h
+
+!qpa:mac {
+ OBJECTIVE_SOURCES += dialogs/qpagesetupdialog_mac.mm \
+ dialogs/qprintdialog_mac.mm
+
+}
+
+win32 {
+ qpa:DEFINES += QT_NO_PRINTDIALOG
+
+ SOURCES += dialogs/qpagesetupdialog_win.cpp \
+ dialogs/qprintdialog_win.cpp
+}
+
+!mac:!symbian:unix|qpa:!win32 {
+ HEADERS += dialogs/qpagesetupdialog_unix_p.h
+ SOURCES += dialogs/qprintdialog_unix.cpp \
+ dialogs/qpagesetupdialog_unix.cpp
+ FORMS += dialogs/qprintsettingsoutput.ui \
+ dialogs/qprintwidget.ui \
+ dialogs/qprintpropertieswidget.ui
+}
+
+INCLUDEPATH += $$PWD
+
+SOURCES += \
+ dialogs/qabstractprintdialog.cpp \
+ dialogs/qabstractpagesetupdialog.cpp \
+ dialogs/qpagesetupdialog.cpp \
+ dialogs/qprintpreviewdialog.cpp
+
+FORMS += dialogs/qpagesetupwidget.ui
+RESOURCES += dialogs/qprintdialog.qrc
diff --git a/src/printsupport/dialogs/images/fit-page-24.png b/src/printsupport/dialogs/images/fit-page-24.png
new file mode 100644
index 0000000000..c7b39d8853
--- /dev/null
+++ b/src/printsupport/dialogs/images/fit-page-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/fit-page-32.png b/src/printsupport/dialogs/images/fit-page-32.png
new file mode 100644
index 0000000000..98bc12d3ed
--- /dev/null
+++ b/src/printsupport/dialogs/images/fit-page-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/fit-width-24.png b/src/printsupport/dialogs/images/fit-width-24.png
new file mode 100644
index 0000000000..a729ffda54
--- /dev/null
+++ b/src/printsupport/dialogs/images/fit-width-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/fit-width-32.png b/src/printsupport/dialogs/images/fit-width-32.png
new file mode 100644
index 0000000000..470a8b45d0
--- /dev/null
+++ b/src/printsupport/dialogs/images/fit-width-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/go-first-24.png b/src/printsupport/dialogs/images/go-first-24.png
new file mode 100644
index 0000000000..55315ffa38
--- /dev/null
+++ b/src/printsupport/dialogs/images/go-first-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/go-first-32.png b/src/printsupport/dialogs/images/go-first-32.png
new file mode 100644
index 0000000000..0fe6f94b77
--- /dev/null
+++ b/src/printsupport/dialogs/images/go-first-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/go-last-24.png b/src/printsupport/dialogs/images/go-last-24.png
new file mode 100644
index 0000000000..81061b80f2
--- /dev/null
+++ b/src/printsupport/dialogs/images/go-last-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/go-last-32.png b/src/printsupport/dialogs/images/go-last-32.png
new file mode 100644
index 0000000000..887506107e
--- /dev/null
+++ b/src/printsupport/dialogs/images/go-last-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/go-next-24.png b/src/printsupport/dialogs/images/go-next-24.png
new file mode 100644
index 0000000000..9a55ef3d86
--- /dev/null
+++ b/src/printsupport/dialogs/images/go-next-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/go-next-32.png b/src/printsupport/dialogs/images/go-next-32.png
new file mode 100644
index 0000000000..6d98f50f4f
--- /dev/null
+++ b/src/printsupport/dialogs/images/go-next-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/go-previous-24.png b/src/printsupport/dialogs/images/go-previous-24.png
new file mode 100644
index 0000000000..2ea769eb8d
--- /dev/null
+++ b/src/printsupport/dialogs/images/go-previous-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/go-previous-32.png b/src/printsupport/dialogs/images/go-previous-32.png
new file mode 100644
index 0000000000..37ba0c4e8d
--- /dev/null
+++ b/src/printsupport/dialogs/images/go-previous-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/layout-landscape-24.png b/src/printsupport/dialogs/images/layout-landscape-24.png
new file mode 100644
index 0000000000..6f89a31cb6
--- /dev/null
+++ b/src/printsupport/dialogs/images/layout-landscape-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/layout-landscape-32.png b/src/printsupport/dialogs/images/layout-landscape-32.png
new file mode 100644
index 0000000000..6a94946c36
--- /dev/null
+++ b/src/printsupport/dialogs/images/layout-landscape-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/layout-portrait-24.png b/src/printsupport/dialogs/images/layout-portrait-24.png
new file mode 100644
index 0000000000..e0dbabc83b
--- /dev/null
+++ b/src/printsupport/dialogs/images/layout-portrait-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/layout-portrait-32.png b/src/printsupport/dialogs/images/layout-portrait-32.png
new file mode 100644
index 0000000000..d17468c0a4
--- /dev/null
+++ b/src/printsupport/dialogs/images/layout-portrait-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/page-setup-24.png b/src/printsupport/dialogs/images/page-setup-24.png
new file mode 100644
index 0000000000..4bfafdace0
--- /dev/null
+++ b/src/printsupport/dialogs/images/page-setup-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/page-setup-32.png b/src/printsupport/dialogs/images/page-setup-32.png
new file mode 100644
index 0000000000..2313b8fe3b
--- /dev/null
+++ b/src/printsupport/dialogs/images/page-setup-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/print-24.png b/src/printsupport/dialogs/images/print-24.png
new file mode 100644
index 0000000000..c6bf3e8672
--- /dev/null
+++ b/src/printsupport/dialogs/images/print-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/print-32.png b/src/printsupport/dialogs/images/print-32.png
new file mode 100644
index 0000000000..5830888653
--- /dev/null
+++ b/src/printsupport/dialogs/images/print-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/status-color.png b/src/printsupport/dialogs/images/status-color.png
new file mode 100644
index 0000000000..af3cbfa31c
--- /dev/null
+++ b/src/printsupport/dialogs/images/status-color.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/status-gray-scale.png b/src/printsupport/dialogs/images/status-gray-scale.png
new file mode 100644
index 0000000000..4462588809
--- /dev/null
+++ b/src/printsupport/dialogs/images/status-gray-scale.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-multi-24.png b/src/printsupport/dialogs/images/view-page-multi-24.png
new file mode 100644
index 0000000000..87241472ae
--- /dev/null
+++ b/src/printsupport/dialogs/images/view-page-multi-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-multi-32.png b/src/printsupport/dialogs/images/view-page-multi-32.png
new file mode 100644
index 0000000000..130885a041
--- /dev/null
+++ b/src/printsupport/dialogs/images/view-page-multi-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-one-24.png b/src/printsupport/dialogs/images/view-page-one-24.png
new file mode 100644
index 0000000000..4c6457b892
--- /dev/null
+++ b/src/printsupport/dialogs/images/view-page-one-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-one-32.png b/src/printsupport/dialogs/images/view-page-one-32.png
new file mode 100644
index 0000000000..537193984e
--- /dev/null
+++ b/src/printsupport/dialogs/images/view-page-one-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-sided-24.png b/src/printsupport/dialogs/images/view-page-sided-24.png
new file mode 100644
index 0000000000..2131305c41
--- /dev/null
+++ b/src/printsupport/dialogs/images/view-page-sided-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/view-page-sided-32.png b/src/printsupport/dialogs/images/view-page-sided-32.png
new file mode 100644
index 0000000000..e4d63f9992
--- /dev/null
+++ b/src/printsupport/dialogs/images/view-page-sided-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/zoom-in-24.png b/src/printsupport/dialogs/images/zoom-in-24.png
new file mode 100644
index 0000000000..d29b142b6c
--- /dev/null
+++ b/src/printsupport/dialogs/images/zoom-in-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/zoom-in-32.png b/src/printsupport/dialogs/images/zoom-in-32.png
new file mode 100644
index 0000000000..34d70af37b
--- /dev/null
+++ b/src/printsupport/dialogs/images/zoom-in-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/zoom-out-24.png b/src/printsupport/dialogs/images/zoom-out-24.png
new file mode 100644
index 0000000000..19703474f8
--- /dev/null
+++ b/src/printsupport/dialogs/images/zoom-out-24.png
Binary files differ
diff --git a/src/printsupport/dialogs/images/zoom-out-32.png b/src/printsupport/dialogs/images/zoom-out-32.png
new file mode 100644
index 0000000000..b832206612
--- /dev/null
+++ b/src/printsupport/dialogs/images/zoom-out-32.png
Binary files differ
diff --git a/src/printsupport/dialogs/qabstractpagesetupdialog.cpp b/src/printsupport/dialogs/qabstractpagesetupdialog.cpp
new file mode 100644
index 0000000000..8268065bfd
--- /dev/null
+++ b/src/printsupport/dialogs/qabstractpagesetupdialog.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qabstractpagesetupdialog.h"
+#include "qabstractpagesetupdialog_p.h"
+
+#ifndef QT_NO_PRINTDIALOG
+
+#include <QtCore/qcoreapplication.h>
+#include <QtPrintSupport/qprinter.h>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \internal
+ \class QAbstractPageSetupDialog
+
+ \brief The QAbstractPageSetupDialog class provides a base for
+ implementations of page setup dialogs.
+*/
+
+/*!
+ Constructs the page setup dialog for the printer \a printer with
+ \a parent as parent widget.
+*/
+QAbstractPageSetupDialog::QAbstractPageSetupDialog(QPrinter *printer, QWidget *parent)
+ : QDialog(*(new QAbstractPageSetupDialogPrivate), parent)
+{
+ Q_D(QAbstractPageSetupDialog);
+ setWindowTitle(QCoreApplication::translate("QPrintPreviewDialog", "Page Setup"));
+ d->setPrinter(printer);
+}
+
+/*!
+ \internal
+*/
+QAbstractPageSetupDialog::QAbstractPageSetupDialog(QAbstractPageSetupDialogPrivate &ptr,
+ QPrinter *printer, QWidget *parent)
+ : QDialog(ptr, parent)
+{
+ Q_D(QAbstractPageSetupDialog);
+ setWindowTitle(QCoreApplication::translate("QPrintPreviewDialog", "Page Setup"));
+ d->setPrinter(printer);
+}
+
+QAbstractPageSetupDialog::~QAbstractPageSetupDialog()
+{
+ Q_D(QAbstractPageSetupDialog);
+ if (d->opts & QPageSetupDialog::OwnsPrinter)
+ delete d->printer;
+}
+
+/*!
+ Returns the printer that this page setup dialog is operating on.
+*/
+QPrinter *QAbstractPageSetupDialog::printer()
+{
+ Q_D(QAbstractPageSetupDialog);
+ return d->printer;
+}
+
+void QAbstractPageSetupDialogPrivate::setPrinter(QPrinter *newPrinter)
+{
+ if (newPrinter) {
+ printer = newPrinter;
+ } else {
+ printer = new QPrinter;
+ opts |= QPageSetupDialog::OwnsPrinter;
+ }
+#ifndef Q_WS_X11
+ if (printer->outputFormat() != QPrinter::NativeFormat)
+ qWarning("QPageSetupDialog: Cannot be used on non-native printers");
+#endif
+}
+
+/*!
+ \fn int QAbstractPageSetupDialog::exec()
+
+ This virtual function is called to pop up the dialog. It must be
+ reimplemented in subclasses.
+*/
+
+/*!
+ \reimp
+*/
+void QAbstractPageSetupDialog::done(int result)
+{
+ Q_D(QAbstractPageSetupDialog);
+ QDialog::done(result);
+ if (d->receiverToDisconnectOnClose) {
+ disconnect(this, SIGNAL(accepted()),
+ d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
+ d->receiverToDisconnectOnClose = 0;
+ }
+ d->memberToDisconnectOnClose.clear();
+
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTDIALOG
diff --git a/src/printsupport/dialogs/qabstractpagesetupdialog.h b/src/printsupport/dialogs/qabstractpagesetupdialog.h
new file mode 100644
index 0000000000..a867a8155b
--- /dev/null
+++ b/src/printsupport/dialogs/qabstractpagesetupdialog.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QABSTRACTPAGESETUPDIALOG_H
+#define QABSTRACTPAGESETUPDIALOG_H
+
+#include <QtWidgets/qdialog.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_PRINTDIALOG
+
+class QAbstractPageSetupDialogPrivate;
+class QPrinter;
+
+// ### Qt 5: Remove this class
+class Q_WIDGETS_EXPORT QAbstractPageSetupDialog : public QDialog
+{
+ Q_DECLARE_PRIVATE(QAbstractPageSetupDialog)
+ Q_OBJECT
+
+public:
+ explicit QAbstractPageSetupDialog(QPrinter *printer, QWidget *parent = 0);
+ QAbstractPageSetupDialog(QAbstractPageSetupDialogPrivate &ptr,
+ QPrinter *printer, QWidget *parent = 0);
+ ~QAbstractPageSetupDialog();
+
+ virtual int exec() = 0;
+ void done(int result);
+
+ QPrinter *printer();
+};
+
+#endif // QT_NO_PRINTDIALOG
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QABSTRACTPAGESETUPDIALOG_H
diff --git a/src/printsupport/dialogs/qabstractpagesetupdialog_p.h b/src/printsupport/dialogs/qabstractpagesetupdialog_p.h
new file mode 100644
index 0000000000..3a4711dd6b
--- /dev/null
+++ b/src/printsupport/dialogs/qabstractpagesetupdialog_p.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QABSTRACTPAGESETUPDIALOG_P_H
+#define QABSTRACTPAGESETUPDIALOG_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// to version without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#include "private/qdialog_p.h"
+
+#ifndef QT_NO_PRINTDIALOG
+
+#include "qbytearray.h"
+#include "qpagesetupdialog.h"
+#include "qpointer.h"
+
+QT_BEGIN_NAMESPACE
+
+class QPrinter;
+
+class QAbstractPageSetupDialogPrivate : public QDialogPrivate
+{
+ Q_DECLARE_PUBLIC(QAbstractPageSetupDialog)
+
+public:
+ QAbstractPageSetupDialogPrivate() : printer(0) {}
+
+ void setPrinter(QPrinter *newPrinter);
+
+ QPrinter *printer;
+ QPageSetupDialog::PageSetupDialogOptions opts;
+ QPointer<QObject> receiverToDisconnectOnClose;
+ QByteArray memberToDisconnectOnClose;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTDIALOG
+
+#endif // QABSTRACTPAGESETUPDIALOG_P_H
diff --git a/src/printsupport/dialogs/qabstractprintdialog.cpp b/src/printsupport/dialogs/qabstractprintdialog.cpp
new file mode 100644
index 0000000000..ff572dd9f3
--- /dev/null
+++ b/src/printsupport/dialogs/qabstractprintdialog.cpp
@@ -0,0 +1,499 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qabstractprintdialog_p.h"
+#include "qcoreapplication.h"
+#include "qprintdialog.h"
+#include "qprinter.h"
+#include "private/qprinter_p.h"
+
+#ifndef QT_NO_PRINTDIALOG
+
+QT_BEGIN_NAMESPACE
+
+// hack
+class QPrintDialogPrivate : public QAbstractPrintDialogPrivate
+{
+};
+
+/*!
+ \class QAbstractPrintDialog
+ \brief The QAbstractPrintDialog class provides a base implementation for
+ print dialogs used to configure printers.
+
+ \ingroup printing
+
+ This class implements getter and setter functions that are used to
+ customize settings shown in print dialogs, but it is not used directly.
+ Use QPrintDialog to display a print dialog in your application.
+
+ In Symbian, there is no support for printing. Hence, this dialog should not
+ be used in Symbian.
+
+ \sa QPrintDialog, QPrinter, {Printing with Qt}
+*/
+
+/*!
+ \enum QAbstractPrintDialog::PrintRange
+
+ Used to specify the print range selection option.
+
+ \value AllPages All pages should be printed.
+ \value Selection Only the selection should be printed.
+ \value PageRange The specified page range should be printed.
+ \value CurrentPage Only the currently visible page should be printed.
+
+ \sa QPrinter::PrintRange
+*/
+
+/*!
+ \enum QAbstractPrintDialog::PrintDialogOption
+
+ Used to specify which parts of the print dialog should be visible.
+
+ \value None None of the options are enabled.
+ \value PrintToFile The print to file option is enabled.
+ \value PrintSelection The print selection option is enabled.
+ \value PrintPageRange The page range selection option is enabled.
+ \value PrintShowPageSize Show the page size + margins page only if this is enabled.
+ \value PrintCollateCopies The collate copies option is enabled
+ \value PrintCurrentPage The print current page option is enabled
+
+ This value is obsolete and does nothing since Qt 4.5:
+
+ \value DontUseSheet In previous versions of Qt, exec() the print dialog
+ would create a sheet by default the dialog was given a parent.
+ This is no longer supported in Qt 4.5. If you want to use sheets, use
+ QPrintDialog::open() instead.
+*/
+
+/*!
+ Constructs an abstract print dialog for \a printer with \a parent
+ as parent widget.
+*/
+QAbstractPrintDialog::QAbstractPrintDialog(QPrinter *printer, QWidget *parent)
+ : QDialog(*(new QAbstractPrintDialogPrivate), parent)
+{
+ Q_D(QAbstractPrintDialog);
+ setWindowTitle(QCoreApplication::translate("QPrintDialog", "Print"));
+ d->setPrinter(printer);
+}
+
+/*!
+ \internal
+*/
+QAbstractPrintDialog::QAbstractPrintDialog(QAbstractPrintDialogPrivate &ptr,
+ QPrinter *printer,
+ QWidget *parent)
+ : QDialog(ptr, parent)
+{
+ Q_D(QAbstractPrintDialog);
+ setWindowTitle(QCoreApplication::translate("QPrintDialog", "Print"));
+ d->setPrinter(printer);
+}
+
+/*!
+ \internal
+*/
+QAbstractPrintDialog::~QAbstractPrintDialog()
+{
+ Q_D(QAbstractPrintDialog);
+ if (d->ownsPrinter)
+ delete d->printer;
+}
+
+/*!
+ Sets the given \a option to be enabled if \a on is true;
+ otherwise, clears the given \a option.
+
+ \sa options, testOption()
+*/
+void QPrintDialog::setOption(PrintDialogOption option, bool on)
+{
+ Q_D(QPrintDialog);
+ if (!(d->options & option) != !on)
+ setOptions(d->options ^ option);
+}
+
+/*!
+ Returns true if the given \a option is enabled; otherwise, returns
+ false.
+
+ \sa options, setOption()
+*/
+bool QPrintDialog::testOption(PrintDialogOption option) const
+{
+ Q_D(const QPrintDialog);
+ return (d->options & option) != 0;
+}
+
+/*!
+ \property QPrintDialog::options
+ \brief the various options that affect the look and feel of the dialog
+ \since 4.5
+
+ By default, all options are disabled.
+
+ Options should be set before showing the dialog. Setting them while the
+ dialog is visible is not guaranteed to have an immediate effect on the
+ dialog (depending on the option and on the platform).
+
+ \sa setOption(), testOption()
+*/
+void QPrintDialog::setOptions(PrintDialogOptions options)
+{
+ Q_D(QPrintDialog);
+
+ PrintDialogOptions changed = (options ^ d->options);
+ if (!changed)
+ return;
+
+ d->options = options;
+}
+
+QPrintDialog::PrintDialogOptions QPrintDialog::options() const
+{
+ Q_D(const QPrintDialog);
+ return d->options;
+}
+
+/*!
+ \obsolete
+
+ Use QPrintDialog::setOptions() instead.
+*/
+void QAbstractPrintDialog::setEnabledOptions(PrintDialogOptions options)
+{
+ Q_D(QAbstractPrintDialog);
+ d->options = options;
+}
+
+/*!
+ \obsolete
+
+ Use QPrintDialog::setOption(\a option, true) instead.
+*/
+void QAbstractPrintDialog::addEnabledOption(PrintDialogOption option)
+{
+ Q_D(QAbstractPrintDialog);
+ d->options |= option;
+}
+
+/*!
+ \obsolete
+
+ Use QPrintDialog::options() instead.
+*/
+QAbstractPrintDialog::PrintDialogOptions QAbstractPrintDialog::enabledOptions() const
+{
+ Q_D(const QAbstractPrintDialog);
+ return d->options;
+}
+
+/*!
+ \obsolete
+
+ Use QPrintDialog::testOption(\a option) instead.
+*/
+bool QAbstractPrintDialog::isOptionEnabled(PrintDialogOption option) const
+{
+ Q_D(const QAbstractPrintDialog);
+ return d->options & option;
+}
+
+/*!
+ Sets the print range option in to be \a range.
+ */
+void QAbstractPrintDialog::setPrintRange(PrintRange range)
+{
+ Q_D(QAbstractPrintDialog);
+ d->pd->printRange = QPrinter::PrintRange(range);
+}
+
+/*!
+ Returns the print range.
+*/
+QAbstractPrintDialog::PrintRange QAbstractPrintDialog::printRange() const
+{
+ Q_D(const QAbstractPrintDialog);
+ return QAbstractPrintDialog::PrintRange(d->pd->printRange);
+}
+
+/*!
+ Sets the page range in this dialog to be from \a min to \a max. This also
+ enables the PrintPageRange option.
+*/
+void QAbstractPrintDialog::setMinMax(int min, int max)
+{
+ Q_D(QAbstractPrintDialog);
+ Q_ASSERT_X(min <= max, "QAbstractPrintDialog::setMinMax",
+ "'min' must be less than or equal to 'max'");
+ d->pd->minPage = min;
+ d->pd->maxPage = max;
+ d->options |= PrintPageRange;
+}
+
+/*!
+ Returns the minimum page in the page range.
+ By default, this value is set to 1.
+*/
+int QAbstractPrintDialog::minPage() const
+{
+ Q_D(const QAbstractPrintDialog);
+ return d->pd->minPage;
+}
+
+/*!
+ Returns the maximum page in the page range. As of Qt 4.4, this
+ function returns INT_MAX by default. Previous versions returned 1
+ by default.
+*/
+int QAbstractPrintDialog::maxPage() const
+{
+ Q_D(const QAbstractPrintDialog);
+ return d->pd->maxPage;
+}
+
+/*!
+ Sets the range in the print dialog to be from \a from to \a to.
+*/
+void QAbstractPrintDialog::setFromTo(int from, int to)
+{
+ Q_D(QAbstractPrintDialog);
+ Q_ASSERT_X(from <= to, "QAbstractPrintDialog::setFromTo",
+ "'from' must be less than or equal to 'to'");
+ d->pd->fromPage = from;
+ d->pd->toPage = to;
+
+ if (d->pd->minPage == 0 && d->pd->maxPage == 0)
+ setMinMax(1, to);
+}
+
+/*!
+ Returns the first page to be printed
+ By default, this value is set to 0.
+*/
+int QAbstractPrintDialog::fromPage() const
+{
+ Q_D(const QAbstractPrintDialog);
+ return d->pd->fromPage;
+}
+
+/*!
+ Returns the last page to be printed.
+ By default, this value is set to 0.
+*/
+int QAbstractPrintDialog::toPage() const
+{
+ Q_D(const QAbstractPrintDialog);
+ return d->pd->toPage;
+}
+
+
+/*!
+ Returns the printer that this printer dialog operates
+ on.
+*/
+QPrinter *QAbstractPrintDialog::printer() const
+{
+ Q_D(const QAbstractPrintDialog);
+ return d->printer;
+}
+
+void QAbstractPrintDialogPrivate::setPrinter(QPrinter *newPrinter)
+{
+ if (newPrinter) {
+ printer = newPrinter;
+ ownsPrinter = false;
+ if (printer->fromPage() || printer->toPage())
+ options |= QAbstractPrintDialog::PrintPageRange;
+ } else {
+ printer = new QPrinter;
+ ownsPrinter = true;
+ }
+ pd = printer->d_func();
+}
+
+/*!
+ \fn int QAbstractPrintDialog::exec()
+
+ This virtual function is called to pop up the dialog. It must be
+ reimplemented in subclasses.
+*/
+
+/*!
+ \class QPrintDialog
+
+ \brief The QPrintDialog class provides a dialog for specifying
+ the printer's configuration.
+
+ \ingroup standard-dialogs
+ \ingroup printing
+
+ The dialog allows users to change document-related settings, such
+ as the paper size and orientation, type of print (color or
+ grayscale), range of pages, and number of copies to print.
+
+ Controls are also provided to enable users to choose from the
+ printers available, including any configured network printers.
+
+ Typically, QPrintDialog objects are constructed with a QPrinter
+ object, and executed using the exec() function.
+
+ \snippet doc/src/snippets/code/src_gui_dialogs_qabstractprintdialog.cpp 0
+
+ If the dialog is accepted by the user, the QPrinter object is
+ correctly configured for printing.
+
+ \table
+ \row
+ \o \inlineimage plastique-printdialog.png
+ \o \inlineimage plastique-printdialog-properties.png
+ \endtable
+
+ The printer dialog (shown above in Plastique style) enables access to common
+ printing properties. On X11 platforms that use the CUPS printing system, the
+ settings for each available printer can be modified via the dialog's
+ \gui{Properties} push button.
+
+ On Windows and Mac OS X, the native print dialog is used, which means that
+ some QWidget and QDialog properties set on the dialog won't be respected.
+ The native print dialog on Mac OS X does not support setting printer options,
+ i.e. setOptions() and setOption() have no effect.
+
+ In Qt 4.4, it was possible to use the static functions to show a sheet on
+ Mac OS X. This is no longer supported in Qt 4.5. If you want this
+ functionality, use QPrintDialog::open().
+
+ \sa QPageSetupDialog, QPrinter, {Pixelator Example}, {Order Form Example},
+ {Image Viewer Example}, {Scribble Example}
+*/
+
+/*!
+ \fn QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent)
+
+ Constructs a new modal printer dialog for the given \a printer
+ with the given \a parent.
+*/
+
+/*!
+ \fn QPrintDialog::~QPrintDialog()
+
+ Destroys the print dialog.
+*/
+
+/*!
+ \fn int QPrintDialog::exec()
+ \reimp
+*/
+
+/*!
+ \since 4.4
+
+ Set a list of widgets as \a tabs to be shown on the print dialog, if supported.
+
+ Currently this option is only supported on X11.
+
+ Setting the option tabs will transfer their ownership to the print dialog.
+*/
+void QAbstractPrintDialog::setOptionTabs(const QList<QWidget*> &tabs)
+{
+ Q_D(QAbstractPrintDialog);
+ d->setTabs(tabs);
+}
+
+/*!
+
+ \fn void QPrintDialog::accepted(QPrinter *printer)
+
+ This signal is emitted when the user accepts the values set in the print dialog.
+ The \a printer parameter includes the printer that the settings were applied to.
+*/
+
+/*!
+ \fn QPrinter *QPrintDialog::printer()
+
+ Returns the printer that this printer dialog operates
+ on. This can be useful when using the QPrintDialog::open() method.
+*/
+
+/*!
+ Closes the dialog and sets its result code to \a result. If this dialog
+ is shown with exec(), done() causes the local event loop to finish,
+ and exec() to return \a result.
+
+ \sa QDialog::done()
+*/
+void QPrintDialog::done(int result)
+{
+ Q_D(QPrintDialog);
+ QDialog::done(result);
+ if (result == Accepted)
+ emit accepted(printer());
+ if (d->receiverToDisconnectOnClose) {
+ disconnect(this, SIGNAL(accepted(QPrinter*)),
+ d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
+ d->receiverToDisconnectOnClose = 0;
+ }
+ d->memberToDisconnectOnClose.clear();
+}
+
+/*!
+ \since 4.5
+ \overload
+
+ Opens the dialog and connects its accepted() signal to the slot specified
+ by \a receiver and \a member.
+
+ The signal will be disconnected from the slot when the dialog is closed.
+*/
+void QPrintDialog::open(QObject *receiver, const char *member)
+{
+ Q_D(QPrintDialog);
+ connect(this, SIGNAL(accepted(QPrinter*)), receiver, member);
+ d->receiverToDisconnectOnClose = receiver;
+ d->memberToDisconnectOnClose = member;
+ QDialog::open();
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTDIALOG
diff --git a/src/printsupport/dialogs/qabstractprintdialog.h b/src/printsupport/dialogs/qabstractprintdialog.h
new file mode 100644
index 0000000000..29c05d544b
--- /dev/null
+++ b/src/printsupport/dialogs/qabstractprintdialog.h
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QABSTRACTPRINTDIALOG_H
+#define QABSTRACTPRINTDIALOG_H
+
+#include <QtWidgets/qdialog.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_PRINTER
+
+class QAbstractPrintDialogPrivate;
+class QPrinter;
+
+// ### Qt 5: remove this class
+class Q_WIDGETS_EXPORT QAbstractPrintDialog : public QDialog
+{
+ Q_DECLARE_PRIVATE(QAbstractPrintDialog)
+ Q_OBJECT
+
+public:
+ // Keep in sync with QPrinter::PrintRange
+ enum PrintRange {
+ AllPages,
+ Selection,
+ PageRange,
+ CurrentPage
+ };
+
+ enum PrintDialogOption {
+ None = 0x0000, // obsolete
+ PrintToFile = 0x0001,
+ PrintSelection = 0x0002,
+ PrintPageRange = 0x0004,
+ PrintShowPageSize = 0x0008,
+ PrintCollateCopies = 0x0010,
+ DontUseSheet = 0x0020,
+ PrintCurrentPage = 0x0040
+ };
+
+ Q_DECLARE_FLAGS(PrintDialogOptions, PrintDialogOption)
+
+#ifndef QT_NO_PRINTDIALOG
+ explicit QAbstractPrintDialog(QPrinter *printer, QWidget *parent = 0);
+ ~QAbstractPrintDialog();
+
+ virtual int exec() = 0;
+
+ // obsolete
+ void addEnabledOption(PrintDialogOption option);
+ void setEnabledOptions(PrintDialogOptions options);
+ PrintDialogOptions enabledOptions() const;
+ bool isOptionEnabled(PrintDialogOption option) const;
+
+ void setOptionTabs(const QList<QWidget*> &tabs);
+
+ void setPrintRange(PrintRange range);
+ PrintRange printRange() const;
+
+ void setMinMax(int min, int max);
+ int minPage() const;
+ int maxPage() const;
+
+ void setFromTo(int fromPage, int toPage);
+ int fromPage() const;
+ int toPage() const;
+
+ QPrinter *printer() const;
+
+protected:
+ QAbstractPrintDialog(QAbstractPrintDialogPrivate &ptr, QPrinter *printer, QWidget *parent = 0);
+
+private:
+ Q_DISABLE_COPY(QAbstractPrintDialog)
+
+#endif // QT_NO_PRINTDIALOG
+};
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractPrintDialog::PrintDialogOptions)
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QABSTRACTPRINTDIALOG_H
diff --git a/src/printsupport/dialogs/qabstractprintdialog_p.h b/src/printsupport/dialogs/qabstractprintdialog_p.h
new file mode 100644
index 0000000000..45dd7e1e6a
--- /dev/null
+++ b/src/printsupport/dialogs/qabstractprintdialog_p.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QABSTRACTPRINTDIALOG_P_H
+#define QABSTRACTPRINTDIALOG_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "private/qdialog_p.h"
+
+#ifndef QT_NO_PRINTDIALOG
+
+#include "QtPrintSupport/qabstractprintdialog.h"
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PRINTER
+
+class QPrinter;
+class QPrinterPrivate;
+
+class QAbstractPrintDialogPrivate : public QDialogPrivate
+{
+ Q_DECLARE_PUBLIC(QAbstractPrintDialog)
+
+public:
+ QAbstractPrintDialogPrivate()
+ : printer(0), pd(0), ownsPrinter(false)
+ , options(QAbstractPrintDialog::PrintToFile | QAbstractPrintDialog::PrintPageRange |
+ QAbstractPrintDialog::PrintCollateCopies | QAbstractPrintDialog::PrintShowPageSize)
+ {
+ }
+
+ QPrinter *printer;
+ QPrinterPrivate *pd;
+ bool ownsPrinter;
+ QPointer<QObject> receiverToDisconnectOnClose;
+ QByteArray memberToDisconnectOnClose;
+
+ QAbstractPrintDialog::PrintDialogOptions options;
+
+ virtual void setTabs(const QList<QWidget *> &) {}
+ void setPrinter(QPrinter *newPrinter);
+};
+
+#endif //QT_NO_PRINTER
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTDIALOG
+
+#endif // QABSTRACTPRINTDIALOG_P_H
diff --git a/src/printsupport/dialogs/qpagesetupdialog.cpp b/src/printsupport/dialogs/qpagesetupdialog.cpp
new file mode 100644
index 0000000000..658dfc1def
--- /dev/null
+++ b/src/printsupport/dialogs/qpagesetupdialog.cpp
@@ -0,0 +1,240 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <private/qabstractpagesetupdialog_p.h>
+
+#ifndef QT_NO_PRINTDIALOG
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \class QPageSetupDialog
+
+ \brief The QPageSetupDialog class provides a configuration dialog
+ for the page-related options on a printer.
+
+ \ingroup standard-dialogs
+ \ingroup printing
+
+ On Windows and Mac OS X the page setup dialog is implemented using
+ the native page setup dialogs.
+
+ Note that on Windows and Mac OS X custom paper sizes won't be
+ reflected in the native page setup dialogs. Additionally, custom
+ page margins set on a QPrinter won't show in the native Mac OS X
+ page setup dialog.
+
+ In Symbian, there is no support for printing. Hence, this dialog should not
+ be used in Symbian.
+
+ \sa QPrinter, QPrintDialog
+*/
+
+
+/*!
+ \fn QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
+
+ Constructs a page setup dialog that configures \a printer with \a
+ parent as the parent widget.
+*/
+
+/*!
+ \since 4.5
+
+ \fn QPageSetupDialog::QPageSetupDialog(QWidget *parent)
+
+ Constructs a page setup dialog that configures a default-constructed
+ QPrinter with \a parent as the parent widget.
+
+ \sa printer()
+*/
+
+/*!
+ \fn QPrinter *QPageSetupDialog::printer()
+
+ Returns the printer that was passed to the QPageSetupDialog
+ constructor.
+*/
+
+// hack
+class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate
+{
+};
+
+/*!
+ \enum QPageSetupDialog::PageSetupDialogOption
+ \since 4.4
+
+ Used to specify options to the page setup dialog
+
+ This value is obsolete and does nothing since Qt 4.5:
+
+ \value DontUseSheet In previous versions of QDialog::exec() the
+ page setup dialog would create a sheet by default if the dialog
+ was given a parent. This is no longer supported from Qt 4.5. If
+ you want to use sheets, use QPageSetupDialog::open() instead.
+
+ \omitvalue None
+ \omitvalue OwnsPrinter
+*/
+
+/*!
+ Sets the given \a option to be enabled if \a on is true;
+ otherwise, clears the given \a option.
+
+ \sa options, testOption()
+*/
+void QPageSetupDialog::setOption(PageSetupDialogOption option, bool on)
+{
+ Q_D(QPageSetupDialog);
+ if (!(d->opts & option) != !on)
+ setOptions(d->opts ^ option);
+}
+
+/*!
+ Returns true if the given \a option is enabled; otherwise, returns
+ false.
+
+ \sa options, setOption()
+*/
+bool QPageSetupDialog::testOption(PageSetupDialogOption option) const
+{
+ Q_D(const QPageSetupDialog);
+ return (d->opts & option) != 0;
+}
+
+/*!
+ \property QPageSetupDialog::options
+ \brief the various options that affect the look and feel of the dialog
+ \since 4.5
+
+ By default, all options are disabled.
+
+ Options should be set before showing the dialog. Setting them while the
+ dialog is visible is not guaranteed to have an immediate effect on the
+ dialog (depending on the option and on the platform).
+
+ \sa setOption(), testOption()
+*/
+void QPageSetupDialog::setOptions(PageSetupDialogOptions options)
+{
+ Q_D(QPageSetupDialog);
+
+ PageSetupDialogOptions changed = (options ^ d->opts);
+ if (!changed)
+ return;
+
+ d->opts = options;
+}
+
+QPageSetupDialog::PageSetupDialogOptions QPageSetupDialog::options() const
+{
+ Q_D(const QPageSetupDialog);
+ return d->opts;
+}
+
+/*!
+ \obsolete
+
+ Use setOption(\a option, true) instead.
+*/
+void QPageSetupDialog::addEnabledOption(PageSetupDialogOption option)
+{
+ setOption(option, true);
+}
+
+/*!
+ \obsolete
+
+ Use setOptions(\a options) instead.
+*/
+void QPageSetupDialog::setEnabledOptions(PageSetupDialogOptions options)
+{
+ setOptions(options);
+}
+
+/*!
+ \obsolete
+
+ Use options() instead.
+*/
+QPageSetupDialog::PageSetupDialogOptions QPageSetupDialog::enabledOptions() const
+{
+ return options();
+}
+
+/*!
+ \obsolete
+
+ Use testOption(\a option) instead.
+*/
+bool QPageSetupDialog::isOptionEnabled(PageSetupDialogOption option) const
+{
+ return testOption(option);
+}
+
+/*!
+ \overload
+ \since 4.5
+
+ Opens the dialog and connects its accepted() signal to the slot specified
+ by \a receiver and \a member.
+
+ The signal will be disconnected from the slot when the dialog is closed.
+*/
+void QPageSetupDialog::open(QObject *receiver, const char *member)
+{
+ Q_D(QPageSetupDialog);
+ connect(this, SIGNAL(accepted()), receiver, member);
+ d->receiverToDisconnectOnClose = receiver;
+ d->memberToDisconnectOnClose = member;
+ QDialog::open();
+}
+
+#if defined(Q_WS_MAC) || defined(Q_OS_WIN)
+/*! \fn void QPageSetupDialog::setVisible(bool visible)
+ \reimp
+*/
+#endif
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/printsupport/dialogs/qpagesetupdialog.h b/src/printsupport/dialogs/qpagesetupdialog.h
new file mode 100644
index 0000000000..3e983d3d95
--- /dev/null
+++ b/src/printsupport/dialogs/qpagesetupdialog.h
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPAGESETUPDIALOG_H
+#define QPAGESETUPDIALOG_H
+
+#include <QtPrintSupport/qabstractpagesetupdialog.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_PRINTDIALOG
+
+class QPageSetupDialogPrivate;
+
+class Q_WIDGETS_EXPORT QPageSetupDialog : public QAbstractPageSetupDialog
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QPageSetupDialog)
+ Q_ENUMS(PageSetupDialogOption)
+ Q_PROPERTY(PageSetupDialogOptions options READ options WRITE setOptions)
+
+public:
+ enum PageSetupDialogOption {
+ None = 0x00000000, // internal
+ DontUseSheet = 0x00000001,
+ OwnsPrinter = 0x80000000 // internal
+ };
+
+ Q_DECLARE_FLAGS(PageSetupDialogOptions, PageSetupDialogOption)
+
+ explicit QPageSetupDialog(QPrinter *printer, QWidget *parent = 0);
+ explicit QPageSetupDialog(QWidget *parent = 0);
+
+ // obsolete
+ void addEnabledOption(PageSetupDialogOption option);
+ void setEnabledOptions(PageSetupDialogOptions options);
+ PageSetupDialogOptions enabledOptions() const;
+ bool isOptionEnabled(PageSetupDialogOption option) const;
+
+ void setOption(PageSetupDialogOption option, bool on = true);
+ bool testOption(PageSetupDialogOption option) const;
+ void setOptions(PageSetupDialogOptions options);
+ PageSetupDialogOptions options() const;
+
+#if defined(Q_WS_MAC) || defined(Q_OS_WIN)
+ virtual void setVisible(bool visible);
+#endif
+ virtual int exec();
+
+#ifdef Q_NO_USING_KEYWORD
+#ifndef Q_QDOC
+ void open() { QDialog::open(); }
+#endif
+#else
+ using QDialog::open;
+#endif
+ void open(QObject *receiver, const char *member);
+
+#ifdef qdoc
+ QPrinter *printer();
+#endif
+};
+
+#endif // QT_NO_PRINTDIALOG
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPAGESETUPDIALOG_H
diff --git a/src/printsupport/dialogs/qpagesetupdialog_mac.mm b/src/printsupport/dialogs/qpagesetupdialog_mac.mm
new file mode 100644
index 0000000000..725520116a
--- /dev/null
+++ b/src/printsupport/dialogs/qpagesetupdialog_mac.mm
@@ -0,0 +1,315 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qpagesetupdialog.h"
+
+#include <qhash.h>
+#include <private/qapplication_p.h>
+#include <private/qprintengine_mac_p.h>
+#include <private/qabstractpagesetupdialog_p.h>
+
+#ifndef QT_NO_PRINTDIALOG
+
+QT_USE_NAMESPACE
+
+@class QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate);
+
+@interface QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) : NSObject {
+ QMacPrintEnginePrivate *pe;
+}
+- (id)initWithMacPrintEngine:(QMacPrintEnginePrivate *)printEngine;
+- (void)pageLayoutDidEnd:(NSPageLayout *)pageLayout
+ returnCode:(int)returnCode contextInfo:(void *)contextInfo;
+@end
+
+@implementation QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate)
+- (id)initWithMacPrintEngine:(QMacPrintEnginePrivate *)printEngine
+{
+ self = [super init];
+ if (self) {
+ pe = printEngine;
+ }
+ return self;
+
+}
+- (void)pageLayoutDidEnd:(NSPageLayout *)pageLayout
+ returnCode:(int)returnCode contextInfo:(void *)contextInfo
+{
+ Q_UNUSED(pageLayout);
+ QPageSetupDialog *dialog = static_cast<QPageSetupDialog *>(contextInfo);
+ if (returnCode == NSOKButton) {
+ PMRect paperRect;
+ PMGetUnadjustedPaperRect(pe->format, &paperRect);
+ pe->customSize = QSizeF(paperRect.right - paperRect.left,
+ paperRect.bottom - paperRect.top);
+ }
+ dialog->done((returnCode == NSOKButton) ? QDialog::Accepted : QDialog::Rejected);
+}
+@end
+
+QT_BEGIN_NAMESPACE
+
+extern void macStartInterceptWindowTitle(QWidget *window);
+extern void macStopInterceptWindowTitle();
+
+class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate
+{
+ Q_DECLARE_PUBLIC(QPageSetupDialog)
+
+public:
+ QPageSetupDialogPrivate() : ep(0)
+#ifndef QT_MAC_USE_COCOA
+ ,upp(0)
+#else
+ ,pageLayout(0)
+#endif
+ {}
+
+ ~QPageSetupDialogPrivate() {
+#ifndef QT_MAC_USE_COCOA
+ if (upp) {
+ DisposePMSheetDoneUPP(upp);
+ upp = 0;
+ }
+ QHash<PMPrintSession, QPageSetupDialogPrivate *>::iterator it = sheetCallbackMap.begin();
+ while (it != sheetCallbackMap.end()) {
+ if (it.value() == this) {
+ it = sheetCallbackMap.erase(it);
+ } else {
+ ++it;
+ }
+ }
+#endif
+ }
+
+#ifndef QT_MAC_USE_COCOA
+ void openCarbonPageLayout(Qt::WindowModality modality);
+ void closeCarbonPageLayout();
+ static void pageSetupDialogSheetDoneCallback(PMPrintSession printSession, WindowRef /*documentWindow*/, Boolean accepted) {
+ QPageSetupDialogPrivate *priv = sheetCallbackMap.value(printSession);
+ if (!priv) {
+ qWarning("%s:%d: QPageSetupDialog::exec: Could not retrieve data structure, "
+ "you most likely now have an infinite modal loop", __FILE__, __LINE__);
+ return;
+ }
+ priv->q_func()->done(accepted ? QDialog::Accepted : QDialog::Rejected);
+ }
+#else
+ void openCocoaPageLayout(Qt::WindowModality modality);
+ void closeCocoaPageLayout();
+#endif
+
+ QMacPrintEnginePrivate *ep;
+#ifndef QT_MAC_USE_COCOA
+ PMSheetDoneUPP upp;
+ static QHash<PMPrintSession, QPageSetupDialogPrivate*> sheetCallbackMap;
+#else
+ NSPageLayout *pageLayout;
+#endif
+};
+
+#ifndef QT_MAC_USE_COCOA
+QHash<PMPrintSession, QPageSetupDialogPrivate*> QPageSetupDialogPrivate::sheetCallbackMap;
+void QPageSetupDialogPrivate::openCarbonPageLayout(Qt::WindowModality modality)
+{
+ Q_Q(QPageSetupDialog);
+ // If someone is reusing a QPrinter object, the end released all our old
+ // information. In this case, we must reinitialize.
+ if (ep->session == 0)
+ ep->initialize();
+
+ sheetCallbackMap.insert(ep->session, this);
+ if (modality == Qt::ApplicationModal) {
+ QWidget modal_widg(0, Qt::Window);
+ modal_widg.setObjectName(QLatin1String(__FILE__ "__modal_dlg"));
+ modal_widg.createWinId();
+ QApplicationPrivate::enterModal(&modal_widg);
+ QApplicationPrivate::native_modal_dialog_active = true;
+ Boolean accepted;
+ PMSessionPageSetupDialog(ep->session, ep->format, &accepted);
+ QApplicationPrivate::leaveModal(&modal_widg);
+ QApplicationPrivate::native_modal_dialog_active = false;
+ pageSetupDialogSheetDoneCallback(ep->session, 0, accepted);
+ } else {
+ // Window Modal means that we use a sheet at the moment, there's no other way to do it correctly.
+ if (!upp)
+ upp = NewPMSheetDoneUPP(QPageSetupDialogPrivate::pageSetupDialogSheetDoneCallback);
+ PMSessionUseSheets(ep->session, qt_mac_window_for(q->parentWidget()), upp);
+ Boolean unused;
+ PMSessionPageSetupDialog(ep->session, ep->format, &unused);
+ }
+}
+
+void QPageSetupDialogPrivate::closeCarbonPageLayout()
+{
+ // if the margins have changed, we have to use the margins from the new
+ // PMFormat object
+ if (q_func()->result() == QDialog::Accepted) {
+ PMPaper paper;
+ PMPaperMargins margins;
+ PMGetPageFormatPaper(ep->format, &paper);
+ PMPaperGetMargins(paper, &margins);
+ ep->leftMargin = margins.left;
+ ep->topMargin = margins.top;
+ ep->rightMargin = margins.right;
+ ep->bottomMargin = margins.bottom;
+
+ PMRect paperRect;
+ PMGetUnadjustedPaperRect(ep->format, &paperRect);
+ ep->customSize = QSizeF(paperRect.right - paperRect.left,
+ paperRect.bottom - paperRect.top);
+ }
+ sheetCallbackMap.remove(ep->session);
+}
+#else
+void QPageSetupDialogPrivate::openCocoaPageLayout(Qt::WindowModality modality)
+{
+ Q_Q(QPageSetupDialog);
+
+ // If someone is reusing a QPrinter object, the end released all our old
+ // information. In this case, we must reinitialize.
+ if (ep->session == 0)
+ ep->initialize();
+
+ macStartInterceptWindowTitle(q);
+ pageLayout = [NSPageLayout pageLayout];
+ // Keep a copy to this since we plan on using it for a bit.
+ [pageLayout retain];
+ QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QCocoaPageLayoutDelegate) alloc] initWithMacPrintEngine:ep];
+
+ if (modality == Qt::ApplicationModal) {
+ int rval = [pageLayout runModalWithPrintInfo:ep->printInfo];
+ [delegate pageLayoutDidEnd:pageLayout returnCode:rval contextInfo:q];
+ } else {
+ Q_ASSERT(q->parentWidget());
+ [pageLayout beginSheetWithPrintInfo:ep->printInfo
+ modalForWindow:qt_mac_window_for(q->parentWidget())
+ delegate:delegate
+ didEndSelector:@selector(pageLayoutDidEnd:returnCode:contextInfo:)
+ contextInfo:q];
+ }
+
+ macStopInterceptWindowTitle();
+}
+
+void QPageSetupDialogPrivate::closeCocoaPageLayout()
+{
+ // NSPageLayout can change the session behind our back and then our
+ // d->ep->session object will become a dangling pointer. Update it
+ // based on the "current" session
+ ep->session = static_cast<PMPrintSession>([ep->printInfo PMPrintSession]);
+
+ [pageLayout release];
+ pageLayout = 0;
+}
+#endif
+
+QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
+ : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent)
+{
+ Q_D(QPageSetupDialog);
+ d->ep = static_cast<QMacPrintEngine *>(d->printer->paintEngine())->d_func();
+}
+
+QPageSetupDialog::QPageSetupDialog(QWidget *parent)
+ : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), 0, parent)
+{
+ Q_D(QPageSetupDialog);
+ d->ep = static_cast<QMacPrintEngine *>(d->printer->paintEngine())->d_func();
+}
+
+void QPageSetupDialog::setVisible(bool visible)
+{
+ Q_D(QPageSetupDialog);
+
+ if (d->printer->outputFormat() != QPrinter::NativeFormat)
+ return;
+
+#ifndef QT_MAC_USE_COCOA
+ bool isCurrentlyVisible = d->sheetCallbackMap.contains(d->ep->session);
+#else
+ bool isCurrentlyVisible = (d->pageLayout != 0);
+#endif
+ if (!visible == !isCurrentlyVisible)
+ return;
+
+ if (visible) {
+#ifndef QT_MAC_USE_COCOA
+ d->openCarbonPageLayout(parentWidget() ? Qt::WindowModal
+ : Qt::ApplicationModal);
+#else
+ d->openCocoaPageLayout(parentWidget() ? Qt::WindowModal
+ : Qt::ApplicationModal);
+#endif
+ return;
+ } else {
+#ifndef QT_MAC_USE_COCOA
+ d->closeCarbonPageLayout();
+#else
+ if (d->pageLayout) {
+ d->closeCocoaPageLayout();
+ return;
+ }
+#endif
+ }
+}
+
+int QPageSetupDialog::exec()
+{
+ Q_D(QPageSetupDialog);
+
+ if (d->printer->outputFormat() != QPrinter::NativeFormat)
+ return Rejected;
+
+#ifndef QT_MAC_USE_COCOA
+ d->openCarbonPageLayout(Qt::ApplicationModal);
+ d->closeCarbonPageLayout();
+#else
+ QMacCocoaAutoReleasePool pool;
+ d->openCocoaPageLayout(Qt::ApplicationModal);
+ d->closeCocoaPageLayout();
+#endif
+ return result();
+}
+
+QT_END_NAMESPACE
+
+#endif /* QT_NO_PRINTDIALOG */
diff --git a/src/printsupport/dialogs/qpagesetupdialog_unix.cpp b/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
new file mode 100644
index 0000000000..e5b12f8ba5
--- /dev/null
+++ b/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
@@ -0,0 +1,620 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qpagesetupdialog.h"
+
+#ifndef QT_NO_PRINTDIALOG
+#include "qpagesetupdialog_unix_p.h"
+
+#include "qpainter.h"
+#include "qprintdialog.h"
+#include "qdialogbuttonbox.h"
+#include <ui_qpagesetupwidget.h>
+
+#include <QtPrintSupport/qprinter.h>
+#include <private/qabstractpagesetupdialog_p.h>
+#include <private/qprinter_p.h>
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+# include <private/qcups_p.h>
+# include <cups/cups.h>
+# include <private/qprintengine_pdf_p.h>
+#endif
+
+
+QT_BEGIN_NAMESPACE
+
+QSizeF qt_printerPaperSize(QPrinter::Orientation, QPrinter::PaperSize, QPrinter::Unit, int);
+
+// Disabled until we have support for papersources on unix
+// #define PSD_ENABLE_PAPERSOURCE
+
+static void populatePaperSizes(QComboBox* cb)
+{
+ cb->addItem(QPrintDialog::tr("A0"), QPrinter::A0);
+ cb->addItem(QPrintDialog::tr("A1"), QPrinter::A1);
+ cb->addItem(QPrintDialog::tr("A2"), QPrinter::A2);
+ cb->addItem(QPrintDialog::tr("A3"), QPrinter::A3);
+ cb->addItem(QPrintDialog::tr("A4"), QPrinter::A4);
+ cb->addItem(QPrintDialog::tr("A5"), QPrinter::A5);
+ cb->addItem(QPrintDialog::tr("A6"), QPrinter::A6);
+ cb->addItem(QPrintDialog::tr("A7"), QPrinter::A7);
+ cb->addItem(QPrintDialog::tr("A8"), QPrinter::A8);
+ cb->addItem(QPrintDialog::tr("A9"), QPrinter::A9);
+ cb->addItem(QPrintDialog::tr("B0"), QPrinter::B0);
+ cb->addItem(QPrintDialog::tr("B1"), QPrinter::B1);
+ cb->addItem(QPrintDialog::tr("B2"), QPrinter::B2);
+ cb->addItem(QPrintDialog::tr("B3"), QPrinter::B3);
+ cb->addItem(QPrintDialog::tr("B4"), QPrinter::B4);
+ cb->addItem(QPrintDialog::tr("B5"), QPrinter::B5);
+ cb->addItem(QPrintDialog::tr("B6"), QPrinter::B6);
+ cb->addItem(QPrintDialog::tr("B7"), QPrinter::B7);
+ cb->addItem(QPrintDialog::tr("B8"), QPrinter::B8);
+ cb->addItem(QPrintDialog::tr("B9"), QPrinter::B9);
+ cb->addItem(QPrintDialog::tr("B10"), QPrinter::B10);
+ cb->addItem(QPrintDialog::tr("C5E"), QPrinter::C5E);
+ cb->addItem(QPrintDialog::tr("DLE"), QPrinter::DLE);
+ cb->addItem(QPrintDialog::tr("Executive"), QPrinter::Executive);
+ cb->addItem(QPrintDialog::tr("Folio"), QPrinter::Folio);
+ cb->addItem(QPrintDialog::tr("Ledger"), QPrinter::Ledger);
+ cb->addItem(QPrintDialog::tr("Legal"), QPrinter::Legal);
+ cb->addItem(QPrintDialog::tr("Letter"), QPrinter::Letter);
+ cb->addItem(QPrintDialog::tr("Tabloid"), QPrinter::Tabloid);
+ cb->addItem(QPrintDialog::tr("US Common #10 Envelope"), QPrinter::Comm10E);
+ cb->addItem(QPrintDialog::tr("Custom"), QPrinter::Custom);
+}
+
+
+static QSizeF sizeForOrientation(QPrinter::Orientation orientation, const QSizeF &size)
+{
+ return (orientation == QPrinter::Portrait) ? size : QSizeF(size.height(), size.width());
+}
+
+#ifdef PSD_ENABLE_PAPERSOURCE
+static const char *paperSourceNames[] = {
+ "Only One",
+ "Lower",
+ "Middle",
+ "Manual",
+ "Envelope",
+ "Envelope manual",
+ "Auto",
+ "Tractor",
+ "Small format",
+ "Large format",
+ "Large capacity",
+ "Cassette",
+ "Form source",
+ 0
+};
+
+struct PaperSourceNames
+{
+ PaperSourceNames(const char *nam, QPrinter::PaperSource ps)
+ : paperSource(ps), name(nam) {}
+ QPrinter::PaperSource paperSource;
+ const char *name;
+};
+#endif
+
+
+class QPagePreview : public QWidget
+{
+public:
+ QPagePreview(QWidget *parent) : QWidget(parent)
+ {
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ setMinimumSize(50, 50);
+ }
+
+ void setPaperSize(const QSizeF& size)
+ {
+ m_size = size;
+ update();
+ }
+
+ void setMargins(qreal left, qreal top, qreal right, qreal bottom)
+ {
+ m_left = left;
+ m_top = top;
+ m_right = right;
+ m_bottom = bottom;
+ update();
+ }
+
+protected:
+ void paintEvent(QPaintEvent *)
+ {
+ QRect pageRect;
+ QSizeF adjustedSize(m_size);
+ adjustedSize.scale(width()-10, height()-10, Qt::KeepAspectRatio);
+ pageRect = QRect(QPoint(0,0), adjustedSize.toSize());
+ pageRect.moveCenter(rect().center());
+
+ qreal width_factor = pageRect.width() / m_size.width();
+ qreal height_factor = pageRect.height() / m_size.height();
+ int leftSize = qRound(m_left*width_factor);
+ int topSize = qRound(m_top*height_factor);
+ int rightSize = qRound(m_right*width_factor);
+ int bottomSize = qRound(m_bottom * height_factor);
+ QRect marginRect(pageRect.x()+leftSize,
+ pageRect.y()+topSize,
+ pageRect.width() - (leftSize+rightSize+1),
+ pageRect.height() - (topSize+bottomSize+1));
+
+ QPainter p(this);
+ QColor shadow(palette().mid().color());
+ for (int i=1; i<6; ++i) {
+ shadow.setAlpha(180-i*30);
+ QRect offset(pageRect.adjusted(i, i, i, i));
+ p.setPen(shadow);
+ p.drawLine(offset.left(), offset.bottom(), offset.right(), offset.bottom());
+ p.drawLine(offset.right(), offset.top(), offset.right(), offset.bottom()-1);
+ }
+ p.fillRect(pageRect, palette().light());
+
+ if (marginRect.isValid()) {
+ p.setPen(QPen(palette().color(QPalette::Dark), 0, Qt::DotLine));
+ p.drawRect(marginRect);
+
+ marginRect.adjust(2, 2, -1, -1);
+ p.setClipRect(marginRect);
+ QFont font;
+ font.setPointSizeF(font.pointSizeF()*0.25);
+ p.setFont(font);
+ p.setPen(palette().color(QPalette::Dark));
+ QString text(QLatin1String("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."));
+ for (int i=0; i<3; ++i)
+ text += text;
+ p.drawText(marginRect, Qt::TextWordWrap|Qt::AlignVCenter, text);
+ }
+ }
+
+private:
+ // all these are in points
+ qreal m_left, m_top, m_right, m_bottom;
+ QSizeF m_size;
+};
+
+
+class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate
+{
+ Q_DECLARE_PUBLIC(QPageSetupDialog)
+
+public:
+ ~QPageSetupDialogPrivate();
+ void init();
+
+ QPageSetupWidget *widget;
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ QCUPSSupport *cups;
+#endif
+};
+
+QPageSetupDialogPrivate::~QPageSetupDialogPrivate()
+{
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ delete cups;
+#endif
+}
+
+void QPageSetupDialogPrivate::init()
+{
+ Q_Q(QPageSetupDialog);
+
+ widget = new QPageSetupWidget(q);
+ widget->setPrinter(printer);
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (printer->outputFormat() == QPrinter::NativeFormat && QCUPSSupport::isAvailable()) {
+ cups = new QCUPSSupport;
+ widget->selectPrinter(cups);
+ } else {
+ cups = 0;
+ }
+#endif
+
+ QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel,
+ Qt::Horizontal, q);
+ QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(accept()));
+ QObject::connect(buttons, SIGNAL(rejected()), q, SLOT(reject()));
+
+ QVBoxLayout *lay = new QVBoxLayout(q);
+ lay->addWidget(widget);
+ lay->addWidget(buttons);
+}
+
+QPageSetupWidget::QPageSetupWidget(QWidget *parent)
+ : QWidget(parent),
+ m_printer(0),
+ m_blockSignals(false),
+ m_cups(0)
+{
+ widget.setupUi(this);
+
+ QString suffix = (QLocale::system().measurementSystem() == QLocale::ImperialSystem)
+ ? QString::fromLatin1(" in")
+ : QString::fromLatin1(" mm");
+ widget.topMargin->setSuffix(suffix);
+ widget.bottomMargin->setSuffix(suffix);
+ widget.leftMargin->setSuffix(suffix);
+ widget.rightMargin->setSuffix(suffix);
+ widget.paperWidth->setSuffix(suffix);
+ widget.paperHeight->setSuffix(suffix);
+
+ QVBoxLayout *lay = new QVBoxLayout(widget.preview);
+ widget.preview->setLayout(lay);
+ m_pagePreview = new QPagePreview(widget.preview);
+ lay->addWidget(m_pagePreview);
+
+ setAttribute(Qt::WA_WState_Polished, false);
+
+#ifdef PSD_ENABLE_PAPERSOURCE
+ for (int i=0; paperSourceNames[i]; ++i)
+ widget.paperSource->insertItem(paperSourceNames[i]);
+#else
+ widget.paperSourceLabel->setVisible(false);
+ widget.paperSource->setVisible(false);
+#endif
+
+ widget.reverseLandscape->setVisible(false);
+ widget.reversePortrait->setVisible(false);
+
+ populatePaperSizes(widget.paperSize);
+
+ QStringList units;
+ units << tr("Centimeters (cm)") << tr("Millimeters (mm)") << tr("Inches (in)") << tr("Points (pt)");
+ widget.unit->addItems(units);
+ connect(widget.unit, SIGNAL(activated(int)), this, SLOT(unitChanged(int)));
+ widget.unit->setCurrentIndex((QLocale::system().measurementSystem() == QLocale::ImperialSystem) ? 2 : 1);
+
+ connect(widget.paperSize, SIGNAL(currentIndexChanged(int)), this, SLOT(_q_paperSizeChanged()));
+ connect(widget.paperWidth, SIGNAL(valueChanged(double)), this, SLOT(_q_paperSizeChanged()));
+ connect(widget.paperHeight, SIGNAL(valueChanged(double)), this, SLOT(_q_paperSizeChanged()));
+
+ connect(widget.leftMargin, SIGNAL(valueChanged(double)), this, SLOT(setLeftMargin(double)));
+ connect(widget.topMargin, SIGNAL(valueChanged(double)), this, SLOT(setTopMargin(double)));
+ connect(widget.rightMargin, SIGNAL(valueChanged(double)), this, SLOT(setRightMargin(double)));
+ connect(widget.bottomMargin, SIGNAL(valueChanged(double)), this, SLOT(setBottomMargin(double)));
+
+ connect(widget.portrait, SIGNAL(clicked()), this, SLOT(_q_pageOrientationChanged()));
+ connect(widget.landscape, SIGNAL(clicked()), this, SLOT(_q_pageOrientationChanged()));
+}
+
+void QPageSetupWidget::setPrinter(QPrinter *printer)
+{
+ m_printer = printer;
+ m_blockSignals = true;
+ selectPdfPsPrinter(printer);
+ printer->getPageMargins(&m_leftMargin, &m_topMargin, &m_rightMargin, &m_bottomMargin, QPrinter::Point);
+ unitChanged(widget.unit->currentIndex());
+ m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+ m_paperSize = printer->paperSize(QPrinter::Point);
+ widget.paperWidth->setValue(m_paperSize.width() / m_currentMultiplier);
+ widget.paperHeight->setValue(m_paperSize.height() / m_currentMultiplier);
+
+ widget.landscape->setChecked(printer->orientation() == QPrinter::Landscape);
+
+#ifdef PSD_ENABLE_PAPERSOURCE
+ widget.paperSource->setCurrentItem(printer->paperSource());
+#endif
+ Q_ASSERT(m_blockSignals);
+ m_blockSignals = false;
+ _q_paperSizeChanged();
+}
+
+// set gui data on printer
+void QPageSetupWidget::setupPrinter() const
+{
+ QPrinter::Orientation orientation = widget.portrait->isChecked()
+ ? QPrinter::Portrait
+ : QPrinter::Landscape;
+ m_printer->setOrientation(orientation);
+ // paper format
+ QVariant val = widget.paperSize->itemData(widget.paperSize->currentIndex());
+ int ps = m_printer->pageSize();
+ if (val.type() == QVariant::Int) {
+ ps = val.toInt();
+ }
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ else if (m_cups && QCUPSSupport::isAvailable() && m_cups->currentPPD()) {
+ QByteArray cupsPageSize = val.toByteArray();
+ QPrintEngine *engine = m_printer->printEngine();
+ engine->setProperty(PPK_CupsStringPageSize, QString::fromLatin1(cupsPageSize));
+ engine->setProperty(PPK_CupsOptions, m_cups->options());
+
+ QRect pageRect = m_cups->pageRect(cupsPageSize);
+ engine->setProperty(PPK_CupsPageRect, pageRect);
+
+ QRect paperRect = m_cups->paperRect(cupsPageSize);
+ engine->setProperty(PPK_CupsPaperRect, paperRect);
+
+ for(ps = 0; ps < QPrinter::NPageSize; ++ps) {
+ QPdf::PaperSize size = QPdf::paperSize(QPrinter::PaperSize(ps));
+ if (size.width == paperRect.width() && size.height == paperRect.height())
+ break;
+ }
+ }
+#endif
+ if (ps == QPrinter::Custom)
+ m_printer->setPaperSize(sizeForOrientation(orientation, m_paperSize), QPrinter::Point);
+ else
+ m_printer->setPaperSize(static_cast<QPrinter::PaperSize>(ps));
+
+#ifdef PSD_ENABLE_PAPERSOURCE
+ m_printer->setPaperSource((QPrinter::PaperSource)widget.paperSource->currentIndex());
+#endif
+ m_printer->setPageMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin, QPrinter::Point);
+
+}
+
+void QPageSetupWidget::selectPrinter(QCUPSSupport *cups)
+{
+ m_cups = cups;
+ widget.paperSize->clear();
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (m_cups && QCUPSSupport::isAvailable()) {
+ const ppd_option_t* pageSizes = m_cups->pageSizes();
+ const int numChoices = pageSizes ? pageSizes->num_choices : 0;
+
+ int cupsDefaultSize = 0;
+ QSize qtPreferredSize = m_printer->paperSize(QPrinter::Point).toSize();
+ bool preferredSizeMatched = false;
+ for (int i = 0; i < numChoices; ++i) {
+ widget.paperSize->addItem(QString::fromLocal8Bit(pageSizes->choices[i].text), QByteArray(pageSizes->choices[i].choice));
+ if (static_cast<int>(pageSizes->choices[i].marked) == 1)
+ cupsDefaultSize = i;
+ if (m_printer->d_func()->hasUserSetPageSize) {
+ QRect cupsPaperSize = m_cups->paperRect(pageSizes->choices[i].choice);
+ QSize diff = cupsPaperSize.size() - qtPreferredSize;
+ if (qAbs(diff.width()) < 5 && qAbs(diff.height()) < 5) {
+ widget.paperSize->setCurrentIndex(i);
+ preferredSizeMatched = true;
+ }
+ }
+ }
+ if (!preferredSizeMatched)
+ widget.paperSize->setCurrentIndex(cupsDefaultSize);
+ if (m_printer->d_func()->hasCustomPageMargins) {
+ m_printer->getPageMargins(&m_leftMargin, &m_topMargin, &m_rightMargin, &m_bottomMargin, QPrinter::Point);
+ } else {
+ QByteArray cupsPaperSizeChoice = widget.paperSize->itemData(widget.paperSize->currentIndex()).toByteArray();
+ QRect paper = m_cups->paperRect(cupsPaperSizeChoice);
+ QRect content = m_cups->pageRect(cupsPaperSizeChoice);
+
+ m_leftMargin = content.x() - paper.x();
+ m_topMargin = content.y() - paper.y();
+ m_rightMargin = paper.right() - content.right();
+ m_bottomMargin = paper.bottom() - content.bottom();
+ }
+ }
+#endif
+ if (widget.paperSize->count() == 0) {
+ populatePaperSizes(widget.paperSize);
+ widget.paperSize->setCurrentIndex(widget.paperSize->findData(
+ QLocale::system().measurementSystem() == QLocale::ImperialSystem ? QPrinter::Letter : QPrinter::A4));
+ }
+
+ unitChanged(widget.unit->currentIndex());
+ m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+}
+
+void QPageSetupWidget::selectPdfPsPrinter(const QPrinter *p)
+{
+ m_cups = 0;
+ widget.paperSize->clear();
+ populatePaperSizes(widget.paperSize);
+ widget.paperSize->setCurrentIndex(widget.paperSize->findData(p->paperSize()));
+
+ m_leftMargin = 90;
+ m_topMargin = 72;
+ m_bottomMargin = 72;
+ m_rightMargin = 90;
+ unitChanged(widget.unit->currentIndex());
+ m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+}
+
+// Updates size/preview after the combobox has been changed.
+void QPageSetupWidget::_q_paperSizeChanged()
+{
+ QVariant val = widget.paperSize->itemData(widget.paperSize->currentIndex());
+ int index = m_printer->pageSize();
+ if (val.type() == QVariant::Int) {
+ index = val.toInt();
+ }
+
+ if (m_blockSignals) return;
+ m_blockSignals = true;
+
+ QPrinter::PaperSize size = QPrinter::PaperSize(index);
+ QPrinter::Orientation orientation = widget.portrait->isChecked()
+ ? QPrinter::Portrait
+ : QPrinter::Landscape;
+
+ bool custom = size == QPrinter::Custom;
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ custom = custom ? !m_cups : custom;
+#endif
+
+ widget.paperWidth->setEnabled(custom);
+ widget.paperHeight->setEnabled(custom);
+ widget.widthLabel->setEnabled(custom);
+ widget.heightLabel->setEnabled(custom);
+ if (custom) {
+ m_paperSize.setWidth( widget.paperWidth->value() * m_currentMultiplier);
+ m_paperSize.setHeight( widget.paperHeight->value() * m_currentMultiplier);
+ m_pagePreview->setPaperSize(m_paperSize);
+ } else {
+ Q_ASSERT(m_printer);
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (m_cups) { // combobox is filled with cups based data
+ QByteArray cupsPageSize = widget.paperSize->itemData(widget.paperSize->currentIndex()).toByteArray();
+ m_paperSize = m_cups->paperRect(cupsPageSize).size();
+ if (orientation == QPrinter::Landscape)
+ m_paperSize = QSizeF(m_paperSize.height(), m_paperSize.width()); // swap
+ }
+ else
+#endif
+ m_paperSize = qt_printerPaperSize(orientation, size, QPrinter::Point, 1);
+
+ m_pagePreview->setPaperSize(m_paperSize);
+ widget.paperWidth->setValue(m_paperSize.width() / m_currentMultiplier);
+ widget.paperHeight->setValue(m_paperSize.height() / m_currentMultiplier);
+ }
+ m_blockSignals = false;
+}
+
+void QPageSetupWidget::_q_pageOrientationChanged()
+{
+ if (QPrinter::PaperSize(widget.paperSize->currentIndex()) == QPrinter::Custom) {
+ double tmp = widget.paperWidth->value();
+ widget.paperWidth->setValue(widget.paperHeight->value());
+ widget.paperHeight->setValue(tmp);
+ }
+ _q_paperSizeChanged();
+}
+
+extern double qt_multiplierForUnit(QPrinter::Unit unit, int resolution);
+
+void QPageSetupWidget::unitChanged(int item)
+{
+ QString suffix;
+ switch(item) {
+ case 0:
+ m_currentMultiplier = 10 * qt_multiplierForUnit(QPrinter::Millimeter, 1);
+ suffix = QString::fromLatin1(" cm");
+ break;
+ case 2:
+ m_currentMultiplier = qt_multiplierForUnit(QPrinter::Inch, 1);
+ suffix = QString::fromLatin1(" in");
+ break;
+ case 3:
+ m_currentMultiplier = qt_multiplierForUnit(QPrinter::Point, 1);
+ suffix = QString::fromLatin1(" pt");
+ break;
+ case 1:
+ default:
+ m_currentMultiplier = qt_multiplierForUnit(QPrinter::Millimeter, 1);
+ suffix = QString::fromLatin1(" mm");
+ break;
+ }
+ const bool old = m_blockSignals;
+ m_blockSignals = true;
+ widget.topMargin->setSuffix(suffix);
+ widget.leftMargin->setSuffix(suffix);
+ widget.rightMargin->setSuffix(suffix);
+ widget.bottomMargin->setSuffix(suffix);
+ widget.paperWidth->setSuffix(suffix);
+ widget.paperHeight->setSuffix(suffix);
+ widget.topMargin->setValue(m_topMargin / m_currentMultiplier);
+ widget.leftMargin->setValue(m_leftMargin / m_currentMultiplier);
+ widget.rightMargin->setValue(m_rightMargin / m_currentMultiplier);
+ widget.bottomMargin->setValue(m_bottomMargin / m_currentMultiplier);
+ widget.paperWidth->setValue(m_paperSize.width() / m_currentMultiplier);
+ widget.paperHeight->setValue(m_paperSize.height() / m_currentMultiplier);
+ m_blockSignals = old;
+}
+
+void QPageSetupWidget::setTopMargin(double newValue)
+{
+ if (m_blockSignals) return;
+ m_topMargin = newValue * m_currentMultiplier;
+ m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+}
+
+void QPageSetupWidget::setBottomMargin(double newValue)
+{
+ if (m_blockSignals) return;
+ m_bottomMargin = newValue * m_currentMultiplier;
+ m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+}
+
+void QPageSetupWidget::setLeftMargin(double newValue)
+{
+ if (m_blockSignals) return;
+ m_leftMargin = newValue * m_currentMultiplier;
+ m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+}
+
+void QPageSetupWidget::setRightMargin(double newValue)
+{
+ if (m_blockSignals) return;
+ m_rightMargin = newValue * m_currentMultiplier;
+ m_pagePreview->setMargins(m_leftMargin, m_topMargin, m_rightMargin, m_bottomMargin);
+}
+
+
+
+QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
+ : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent)
+{
+ Q_D(QPageSetupDialog);
+ d->init();
+}
+
+
+QPageSetupDialog::QPageSetupDialog(QWidget *parent)
+ : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), 0, parent)
+{
+ Q_D(QPageSetupDialog);
+ d->init();
+}
+
+/*!
+ \internal
+*/
+int QPageSetupDialog::exec()
+{
+ Q_D(QPageSetupDialog);
+
+ int ret = QDialog::exec();
+ if (ret == Accepted)
+ d->widget->setupPrinter();
+ return ret;
+}
+
+
+QT_END_NAMESPACE
+
+#include "moc_qpagesetupdialog.cpp"
+
+#endif // QT_NO_PRINTDIALOG
diff --git a/src/printsupport/dialogs/qpagesetupdialog_unix_p.h b/src/printsupport/dialogs/qpagesetupdialog_unix_p.h
new file mode 100644
index 0000000000..2303db9fe8
--- /dev/null
+++ b/src/printsupport/dialogs/qpagesetupdialog_unix_p.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QPAGESETUPWIDGET_H
+#define QPAGESETUPWIDGET_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// to version without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#include "qglobal.h"
+
+#ifndef QT_NO_PRINTDIALOG
+
+#include <ui_qpagesetupwidget.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPrinter;
+class QPagePreview;
+class QCUPSSupport;
+
+class QPageSetupWidget : public QWidget {
+ Q_OBJECT
+public:
+ QPageSetupWidget(QWidget *parent = 0);
+ QPageSetupWidget(QPrinter *printer, QWidget *parent = 0);
+ void setPrinter(QPrinter *printer);
+ /// copy information from the widget and apply that to the printer.
+ void setupPrinter() const;
+ void selectPrinter(QCUPSSupport *m_cups);
+ void selectPdfPsPrinter(const QPrinter *p);
+
+private slots:
+ void _q_pageOrientationChanged();
+ void _q_paperSizeChanged();
+ void unitChanged(int item);
+ void setTopMargin(double newValue);
+ void setBottomMargin(double newValue);
+ void setLeftMargin(double newValue);
+ void setRightMargin(double newValue);
+
+private:
+ Ui::QPageSetupWidget widget;
+ QPagePreview *m_pagePreview;
+ QPrinter *m_printer;
+ qreal m_leftMargin;
+ qreal m_topMargin;
+ qreal m_rightMargin;
+ qreal m_bottomMargin;
+ QSizeF m_paperSize;
+ qreal m_currentMultiplier;
+ bool m_blockSignals;
+ QCUPSSupport *m_cups;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTDIALOG
+#endif
diff --git a/src/printsupport/dialogs/qpagesetupdialog_win.cpp b/src/printsupport/dialogs/qpagesetupdialog_win.cpp
new file mode 100644
index 0000000000..2e7cf860fc
--- /dev/null
+++ b/src/printsupport/dialogs/qpagesetupdialog_win.cpp
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qpagesetupdialog.h"
+
+#ifndef QT_NO_PRINTDIALOG
+#include <qapplication.h>
+
+#include <private/qprintengine_win_p.h>
+#include <private/qabstractpagesetupdialog_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPageSetupDialogPrivate : public QAbstractPageSetupDialogPrivate
+{
+};
+
+QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)
+ : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), printer, parent)
+{
+}
+
+QPageSetupDialog::QPageSetupDialog(QWidget *parent)
+ : QAbstractPageSetupDialog(*(new QPageSetupDialogPrivate), 0, parent)
+{
+}
+
+int QPageSetupDialog::exec()
+{
+ Q_D(QPageSetupDialog);
+
+ if (d->printer->outputFormat() != QPrinter::NativeFormat)
+ return Rejected;
+
+ QWin32PrintEngine *engine = static_cast<QWin32PrintEngine*>(d->printer->paintEngine());
+ QWin32PrintEnginePrivate *ep = static_cast<QWin32PrintEnginePrivate *>(engine->d_ptr.data());
+
+ PAGESETUPDLG psd;
+ memset(&psd, 0, sizeof(PAGESETUPDLG));
+ psd.lStructSize = sizeof(PAGESETUPDLG);
+
+ // we need a temp DEVMODE struct if we don't have a global DEVMODE
+ HGLOBAL hDevMode = 0;
+ int devModeSize = 0;
+ if (!ep->globalDevMode) {
+ devModeSize = sizeof(DEVMODE) + ep->devMode->dmDriverExtra;
+ hDevMode = GlobalAlloc(GHND, devModeSize);
+ if (hDevMode) {
+ void *dest = GlobalLock(hDevMode);
+ memcpy(dest, ep->devMode, devModeSize);
+ GlobalUnlock(hDevMode);
+ }
+ psd.hDevMode = hDevMode;
+ } else {
+ psd.hDevMode = ep->devMode;
+ }
+
+ HGLOBAL *tempDevNames = ep->createDevNames();
+ psd.hDevNames = tempDevNames;
+
+ QWidget *parent = parentWidget();
+ parent = parent ? parent->window() : QApplication::activeWindow();
+ Q_ASSERT(!parent ||parent->testAttribute(Qt::WA_WState_Created));
+ psd.hwndOwner = parent ? parent->winId() : 0;
+
+ QRect paperRect = d->printer->paperRect();
+ QRect pageRect = d->printer->pageRect();
+
+ psd.Flags = PSD_MARGINS;
+ double multiplier = 1;
+ switch (QLocale::system().measurementSystem()) {
+ case QLocale::MetricSystem:
+ psd.Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
+ multiplier = 1;
+ break;
+ case QLocale::ImperialSystem:
+ psd.Flags |= PSD_INTHOUSANDTHSOFINCHES;
+ multiplier = 25.4/10;
+ break;
+ }
+
+ QRect marginRect = ep->getPageMargins();
+ psd.rtMargin.left = marginRect.left() / multiplier;
+ psd.rtMargin.top = marginRect.top() / multiplier;
+ psd.rtMargin.right = marginRect.width() / multiplier;;
+ psd.rtMargin.bottom = marginRect.height() / multiplier;;
+
+ bool result = PageSetupDlg(&psd);
+ if (result) {
+ ep->readDevnames(psd.hDevNames);
+ ep->readDevmode(psd.hDevMode);
+
+ QRect theseMargins = QRect(psd.rtMargin.left * multiplier,
+ psd.rtMargin.top * multiplier,
+ psd.rtMargin.right * multiplier,
+ psd.rtMargin.bottom * multiplier);
+
+ if (theseMargins != marginRect) {
+ ep->setPageMargins(psd.rtMargin.left * multiplier,
+ psd.rtMargin.top * multiplier,
+ psd.rtMargin.right * multiplier,
+ psd.rtMargin.bottom * multiplier);
+ }
+
+ ep->updateCustomPaperSize();
+
+ // copy from our temp DEVMODE struct
+ if (!ep->globalDevMode && hDevMode) {
+ void *src = GlobalLock(hDevMode);
+ memcpy(ep->devMode, src, devModeSize);
+ GlobalUnlock(hDevMode);
+ }
+ }
+
+ if (!ep->globalDevMode && hDevMode)
+ GlobalFree(hDevMode);
+ GlobalFree(tempDevNames);
+ done(result);
+ return result;
+}
+
+void QPageSetupDialog::setVisible(bool visible)
+{
+ if (!visible)
+ return;
+ exec();
+}
+
+QT_END_NAMESPACE
+#endif
diff --git a/src/printsupport/dialogs/qpagesetupwidget.ui b/src/printsupport/dialogs/qpagesetupwidget.ui
new file mode 100644
index 0000000000..ace2ab8f44
--- /dev/null
+++ b/src/printsupport/dialogs/qpagesetupwidget.ui
@@ -0,0 +1,353 @@
+<ui version="4.0" >
+ <class>QPageSetupWidget</class>
+ <widget class="QWidget" name="QPageSetupWidget" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>416</width>
+ <height>488</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_3" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <item row="0" column="0" colspan="2" >
+ <layout class="QHBoxLayout" name="horizontalLayout_4" >
+ <item>
+ <widget class="QComboBox" name="unit" />
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_3" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="0" colspan="2" >
+ <widget class="QGroupBox" name="groupBox_2" >
+ <property name="title" >
+ <string>Paper</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_2" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="pageSizeLabel" >
+ <property name="text" >
+ <string>Page size:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>paperSize</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QComboBox" name="paperSize" />
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="widthLabel" >
+ <property name="text" >
+ <string>Width:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>paperWidth</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <layout class="QHBoxLayout" name="horizontalLayout_3" >
+ <item>
+ <widget class="QDoubleSpinBox" name="paperWidth" >
+ <property name="maximum" >
+ <double>9999.989999999999782</double>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="heightLabel" >
+ <property name="text" >
+ <string>Height:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>paperHeight</cstring>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDoubleSpinBox" name="paperHeight" >
+ <property name="maximum" >
+ <double>9999.989999999999782</double>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="paperSourceLabel" >
+ <property name="text" >
+ <string>Paper source:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>paperSource</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QComboBox" name="paperSource" />
+ </item>
+ <item row="1" column="2" >
+ <spacer name="horizontalSpacer_4" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QGroupBox" name="groupBox_3" >
+ <property name="title" >
+ <string>Orientation</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout" >
+ <item>
+ <widget class="QRadioButton" name="portrait" >
+ <property name="text" >
+ <string>Portrait</string>
+ </property>
+ <property name="checked" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="landscape" >
+ <property name="text" >
+ <string>Landscape</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="reverseLandscape" >
+ <property name="text" >
+ <string>Reverse landscape</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="reversePortrait" >
+ <property name="text" >
+ <string>Reverse portrait</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_5" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item rowspan="2" row="2" column="1" >
+ <widget class="QWidget" native="1" name="preview" />
+ </item>
+ <item row="3" column="0" >
+ <widget class="QGroupBox" name="groupBox" >
+ <property name="title" >
+ <string>Margins</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_2" >
+ <item>
+ <layout class="QGridLayout" name="gridLayout" >
+ <item row="0" column="1" >
+ <widget class="QDoubleSpinBox" name="topMargin" >
+ <property name="toolTip" >
+ <string>top margin</string>
+ </property>
+ <property name="accessibleName" >
+ <string>top margin</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="maximum" >
+ <double>999.990000000000009</double>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" colspan="3" >
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <spacer name="horizontalSpacer_7" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>0</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QDoubleSpinBox" name="leftMargin" >
+ <property name="toolTip" >
+ <string>left margin</string>
+ </property>
+ <property name="accessibleName" >
+ <string>left margin</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="maximum" >
+ <double>999.990000000000009</double>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::MinimumExpanding</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QDoubleSpinBox" name="rightMargin" >
+ <property name="toolTip" >
+ <string>right margin</string>
+ </property>
+ <property name="accessibleName" >
+ <string>right margin</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="maximum" >
+ <double>999.990000000000009</double>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_8" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>0</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QDoubleSpinBox" name="bottomMargin" >
+ <property name="toolTip" >
+ <string>bottom margin</string>
+ </property>
+ <property name="accessibleName" >
+ <string>bottom margin</string>
+ </property>
+ <property name="alignment" >
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ <property name="maximum" >
+ <double>999.990000000000009</double>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2" >
+ <spacer name="horizontalSpacer_2" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::MinimumExpanding</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>0</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="0" >
+ <spacer name="horizontalSpacer_5" >
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType" >
+ <enum>QSizePolicy::MinimumExpanding</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>0</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="4" column="0" >
+ <spacer name="verticalSpacer" >
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>20</width>
+ <height>0</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/printsupport/dialogs/qprintdialog.h b/src/printsupport/dialogs/qprintdialog.h
new file mode 100644
index 0000000000..bb53ae6fd8
--- /dev/null
+++ b/src/printsupport/dialogs/qprintdialog.h
@@ -0,0 +1,174 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTDIALOG_H
+#define QPRINTDIALOG_H
+
+#include <QtPrintSupport/qabstractprintdialog.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_PRINTDIALOG
+
+class QPrintDialogPrivate;
+class QPushButton;
+class QPrinter;
+
+#if defined (Q_OS_UNIX) && !defined(QTOPIA_PRINTDIALOG) && !defined(Q_WS_MAC) && !defined(Q_OS_SYMBIAN)
+class QUnixPrintWidgetPrivate;
+
+class Q_WIDGETS_EXPORT QUnixPrintWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ QUnixPrintWidget(QPrinter *printer, QWidget *parent = 0);
+ ~QUnixPrintWidget();
+ void updatePrinter();
+
+private:
+ friend class QPrintDialogPrivate;
+ friend class QUnixPrintWidgetPrivate;
+ QUnixPrintWidgetPrivate *d;
+ Q_PRIVATE_SLOT(d, void _q_printerChanged(int))
+ Q_PRIVATE_SLOT(d, void _q_btnBrowseClicked())
+ Q_PRIVATE_SLOT(d, void _q_btnPropertiesClicked())
+};
+#endif
+
+class Q_WIDGETS_EXPORT QPrintDialog : public QAbstractPrintDialog
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QPrintDialog)
+ Q_ENUMS(PrintDialogOption)
+ Q_PROPERTY(PrintDialogOptions options READ options WRITE setOptions)
+
+public:
+ explicit QPrintDialog(QPrinter *printer, QWidget *parent = 0);
+ explicit QPrintDialog(QWidget *parent = 0);
+ ~QPrintDialog();
+
+ int exec();
+#if defined (Q_OS_UNIX) && !defined(QTOPIA_PRINTDIALOG) && !defined(Q_WS_MAC)
+ virtual void accept();
+#endif
+ void done(int result);
+
+#if defined (Q_OS_UNIX) && defined (QT3_SUPPORT)
+ QT3_SUPPORT void setPrinter(QPrinter *, bool = false);
+ QT3_SUPPORT QPrinter *printer() const;
+ QT3_SUPPORT void addButton(QPushButton *button);
+#endif
+
+ void setOption(PrintDialogOption option, bool on = true);
+ bool testOption(PrintDialogOption option) const;
+ void setOptions(PrintDialogOptions options);
+ PrintDialogOptions options() const;
+
+#if defined(Q_OS_UNIX) || defined(Q_WS_MAC) || defined(Q_OS_WIN)
+ void setVisible(bool visible);
+#endif
+
+#ifdef Q_NO_USING_KEYWORD
+#ifndef Q_QDOC
+ void open() { QDialog::open(); }
+#endif
+#else
+ using QDialog::open;
+#endif
+ void open(QObject *receiver, const char *member);
+
+#ifdef qdoc
+ QPrinter *printer();
+#endif
+
+#ifdef QTOPIA_PRINTDIALOG
+public:
+ bool eventFilter(QObject *, QEvent *);
+#endif
+
+#ifdef Q_NO_USING_KEYWORD
+#ifndef Q_QDOC
+ void accepted() { QDialog::accepted(); }
+#endif
+#else
+ using QDialog::accepted;
+#endif
+
+Q_SIGNALS:
+ void accepted(QPrinter *printer);
+
+private:
+#ifndef QTOPIA_PRINTDIALOG
+ Q_PRIVATE_SLOT(d_func(), void _q_chbPrintLastFirstToggled(bool))
+#if defined (Q_OS_UNIX) && !defined (Q_OS_MAC)
+ Q_PRIVATE_SLOT(d_func(), void _q_collapseOrExpandDialog())
+#endif
+# if defined(Q_OS_UNIX) && !defined (Q_OS_MAC) && !defined(QT_NO_MESSAGEBOX)
+ Q_PRIVATE_SLOT(d_func(), void _q_checkFields())
+# endif
+#else // QTOPIA_PRINTDIALOG
+ Q_PRIVATE_SLOT(d_func(), void _q_okClicked())
+ Q_PRIVATE_SLOT(d_func(),void _q_printerOrFileSelected(QAbstractButton *b))
+ Q_PRIVATE_SLOT(d_func(),void _q_paperSizeSelected(int))
+ Q_PRIVATE_SLOT(d_func(), void _q_orientSelected(int))
+ Q_PRIVATE_SLOT(d_func(), void _q_pageOrderSelected(int))
+ Q_PRIVATE_SLOT(d_func(), void _q_colorModeSelected(QAbstractButton *))
+ Q_PRIVATE_SLOT(d_func(), void _q_setNumCopies(int))
+ Q_PRIVATE_SLOT(d_func(), void _q_printRangeSelected(int))
+ Q_PRIVATE_SLOT(d_func(), void _q_setFirstPage(int))
+ Q_PRIVATE_SLOT(d_func(), void _q_setLastPage(int))
+ Q_PRIVATE_SLOT(d_func(), void _q_fileNameEditChanged(const QString &text))
+#endif // QTOPIA_PRINTDIALOG
+ friend class QUnixPrintWidget;
+};
+
+#endif // QT_NO_PRINTDIALOG
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPRINTDIALOG_H
diff --git a/src/printsupport/dialogs/qprintdialog.qdoc b/src/printsupport/dialogs/qprintdialog.qdoc
new file mode 100644
index 0000000000..53bbc9b490
--- /dev/null
+++ b/src/printsupport/dialogs/qprintdialog.qdoc
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifdef QT3_SUPPORT
+/*!
+ \fn QPrinter *QPrintDialog::printer() const
+
+ Returns a pointer to the printer this dialog configures, or 0 if
+ this dialog does not operate on any printer.
+
+ This function is available for Unix platforms only.
+*/
+
+/*!
+ \fn void QPrintDialog::setPrinter(QPrinter *printer, bool pickupSettings)
+
+ Sets this dialog to configure printer \a printer, or no printer if \a printer
+ is null. If \a pickupSettings is true, the dialog reads most of
+ its settings from \a printer. If \a pickupSettings is false (the
+ default) the dialog keeps its old settings.
+
+ This function is available for Unix platforms only.
+*/
+
+/*!
+ \fn void QPrintDialog::addButton(QPushButton *button)
+
+ Adds the \a button to the layout of the print dialog. The added
+ buttons are arranged from the left to the right below the
+ last groupbox of the printdialog.
+
+ This function is available for Unix platforms only.
+*/
+#endif
diff --git a/src/printsupport/dialogs/qprintdialog.qrc b/src/printsupport/dialogs/qprintdialog.qrc
new file mode 100644
index 0000000000..f54eb6b5ee
--- /dev/null
+++ b/src/printsupport/dialogs/qprintdialog.qrc
@@ -0,0 +1,38 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/trolltech/dialogs/qprintpreviewdialog">
+<file>images/fit-page-24.png</file>
+<file>images/fit-page-32.png</file>
+<file>images/fit-width-24.png</file>
+<file>images/fit-width-32.png</file>
+<file>images/go-first-24.png</file>
+<file>images/go-first-32.png</file>
+<file>images/go-last-24.png</file>
+<file>images/go-last-32.png</file>
+<file>images/go-next-24.png</file>
+<file>images/go-next-32.png</file>
+<file>images/go-previous-24.png</file>
+<file>images/go-previous-32.png</file>
+<file>images/layout-landscape-24.png</file>
+<file>images/layout-landscape-32.png</file>
+<file>images/layout-portrait-24.png</file>
+<file>images/layout-portrait-32.png</file>
+<file>images/page-setup-24.png</file>
+<file>images/page-setup-32.png</file>
+<file>images/print-24.png</file>
+<file>images/print-32.png</file>
+<file>images/view-page-multi-24.png</file>
+<file>images/view-page-multi-32.png</file>
+<file>images/view-page-one-24.png</file>
+<file>images/view-page-one-32.png</file>
+<file>images/view-page-sided-24.png</file>
+<file>images/view-page-sided-32.png</file>
+<file>images/zoom-in-24.png</file>
+<file>images/zoom-in-32.png</file>
+<file>images/zoom-out-24.png</file>
+<file>images/zoom-out-32.png</file>
+</qresource>
+<qresource prefix="/trolltech/dialogs/qprintdialog">
+<file>images/status-color.png</file>
+<file>images/status-gray-scale.png</file>
+</qresource>
+</RCC>
diff --git a/src/printsupport/dialogs/qprintdialog_mac.mm b/src/printsupport/dialogs/qprintdialog_mac.mm
new file mode 100644
index 0000000000..2e902e61ce
--- /dev/null
+++ b/src/printsupport/dialogs/qprintdialog_mac.mm
@@ -0,0 +1,429 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT_NO_PRINTDIALOG
+
+#include <private/qt_mac_p.h>
+
+#include <qhash.h>
+#include <qprintdialog.h>
+#include <private/qapplication_p.h>
+#include <private/qabstractprintdialog_p.h>
+#include <private/qprintengine_mac_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPrintDialogPrivate : public QAbstractPrintDialogPrivate
+{
+ Q_DECLARE_PUBLIC(QPrintDialog)
+
+public:
+ QPrintDialogPrivate() : ep(0), printPanel(0)
+#ifndef QT_MAC_USE_COCOA
+ ,upp(0)
+#endif
+ {}
+#ifndef QT_MAC_USE_COCOA
+ ~QPrintDialogPrivate() {
+ if (upp) {
+ DisposePMSheetDoneUPP(upp);
+ upp = 0;
+ }
+ QHash<PMPrintSession, QPrintDialogPrivate *>::iterator it = sheetCallbackMap.begin();
+ while (it != sheetCallbackMap.end()) {
+ if (it.value() == this) {
+ it = sheetCallbackMap.erase(it);
+ } else {
+ ++it;
+ }
+ }
+ }
+#endif
+
+#ifndef QT_MAC_USE_COCOA
+ void openCarbonPrintPanel(Qt::WindowModality modality);
+ void closeCarbonPrintPanel();
+ static void printDialogSheetDoneCallback(PMPrintSession printSession, WindowRef /*documentWindow*/, Boolean accepted) {
+ QPrintDialogPrivate *priv = sheetCallbackMap.value(printSession);
+ if (!priv) {
+ qWarning("%s:%d: QPrintDialog::exec: Could not retrieve data structure, "
+ "you most likely now have an infinite loop", __FILE__, __LINE__);
+ return;
+ }
+ priv->q_func()->done(accepted ? QDialog::Accepted : QDialog::Rejected);
+ priv->closeCarbonPrintPanel();
+ }
+#else
+ void openCocoaPrintPanel(Qt::WindowModality modality);
+ void closeCocoaPrintPanel();
+#endif
+ void initBeforeRun();
+
+ inline QPrintDialog *printDialog() { return q_func(); }
+
+ inline void _q_printToFileChanged(int) {}
+ inline void _q_rbPrintRangeToggled(bool) {}
+ inline void _q_printerChanged(int) {}
+#ifndef QT_NO_MESSAGEBOX
+ inline void _q_checkFields() {}
+#endif
+ inline void _q_chbPrintLastFirstToggled(bool) {}
+ inline void _q_paperSizeChanged(int) {}
+ inline void _q_btnBrowseClicked() {}
+ inline void _q_btnPropertiesClicked() {}
+
+ QMacPrintEnginePrivate *ep;
+ NSPrintPanel *printPanel;
+#ifndef QT_MAC_USE_COCOA
+ PMSheetDoneUPP upp;
+ static QHash<PMPrintSession, QPrintDialogPrivate *> sheetCallbackMap;
+#endif
+};
+
+QT_END_NAMESPACE
+
+QT_USE_NAMESPACE
+
+#ifdef QT_MAC_USE_COCOA
+
+@class QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate);
+
+@interface QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) : NSObject {
+}
+- (void)printPanelDidEnd:(NSPrintPanel *)printPanel
+ returnCode:(int)returnCode contextInfo:(void *)contextInfo;
+@end
+
+@implementation QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate)
+- (void)printPanelDidEnd:(NSPrintPanel *)printPanel
+ returnCode:(int)returnCode contextInfo:(void *)contextInfo
+{
+ Q_UNUSED(printPanel);
+
+ QPrintDialogPrivate *d = static_cast<QPrintDialogPrivate *>(contextInfo);
+ QPrintDialog *dialog = d->printDialog();
+
+ if (returnCode == NSOKButton) {
+ UInt32 frompage, topage;
+ PMGetFirstPage(d->ep->settings, &frompage);
+ PMGetLastPage(d->ep->settings, &topage);
+ topage = qMin(UInt32(INT_MAX), topage);
+ dialog->setFromTo(frompage, topage);
+
+ // OK, I need to map these values back let's see
+ // If from is 1 and to is INT_MAX, then print it all
+ // (Apologies to the folks with more than INT_MAX pages)
+ if (dialog->fromPage() == 1 && dialog->toPage() == INT_MAX) {
+ dialog->setPrintRange(QPrintDialog::AllPages);
+ dialog->setFromTo(0, 0);
+ } else {
+ dialog->setPrintRange(QPrintDialog::PageRange); // In a way a lie, but it shouldn't hurt.
+ // Carbon hands us back a very large number here even for ALL, set it to max
+ // in that case to follow the behavior of the other print dialogs.
+ if (dialog->maxPage() < dialog->toPage())
+ dialog->setFromTo(dialog->fromPage(), dialog->maxPage());
+ }
+ // Keep us in sync with file output
+ PMDestinationType dest;
+
+ // If the user selected print to file, the session has been
+ // changed behind our back and our d->ep->session object is a
+ // dangling pointer. Update it based on the "current" session
+ d->ep->session = static_cast<PMPrintSession>([d->ep->printInfo PMPrintSession]);
+
+ PMSessionGetDestinationType(d->ep->session, d->ep->settings, &dest);
+ if (dest == kPMDestinationFile) {
+ QCFType<CFURLRef> file;
+ PMSessionCopyDestinationLocation(d->ep->session, d->ep->settings, &file);
+ UInt8 localFile[2048]; // Assuming there's a POSIX file system here.
+ CFURLGetFileSystemRepresentation(file, true, localFile, sizeof(localFile));
+ d->ep->outputFilename
+ = QString::fromUtf8(reinterpret_cast<const char *>(localFile));
+ } else {
+ // Keep output format.
+ QPrinter::OutputFormat format;
+ format = d->printer->outputFormat();
+ d->printer->setOutputFileName(QString());
+ d->printer->setOutputFormat(format);
+ }
+ }
+
+ dialog->done((returnCode == NSOKButton) ? QDialog::Accepted : QDialog::Rejected);
+}
+@end
+
+#endif
+
+QT_BEGIN_NAMESPACE
+
+extern void macStartInterceptWindowTitle(QWidget *window);
+extern void macStopInterceptWindowTitle();
+
+
+void QPrintDialogPrivate::initBeforeRun()
+{
+ Q_Q(QPrintDialog);
+ // If someone is reusing a QPrinter object, the end released all our old
+ // information. In this case, we must reinitialize.
+ if (ep->session == 0)
+ ep->initialize();
+
+
+ // It seems the only way that PM lets you use all is if the minimum
+ // for the page range is 1. This _kind of_ makes sense if you think about
+ // it. However, calling PMSetFirstPage() or PMSetLastPage() always enforces
+ // the range.
+ PMSetPageRange(ep->settings, q->minPage(), q->maxPage());
+ if (q->printRange() == QAbstractPrintDialog::PageRange) {
+ PMSetFirstPage(ep->settings, q->fromPage(), false);
+ PMSetLastPage(ep->settings, q->toPage(), false);
+ }
+}
+
+#ifndef QT_MAC_USE_COCOA
+QHash<PMPrintSession, QPrintDialogPrivate *> QPrintDialogPrivate::sheetCallbackMap;
+void QPrintDialogPrivate::openCarbonPrintPanel(Qt::WindowModality modality)
+{
+ Q_Q(QPrintDialog);
+ initBeforeRun();
+ sheetCallbackMap.insert(ep->session, this);
+ if (modality == Qt::ApplicationModal) {
+ QWidget modal_widg(0, Qt::Window);
+ modal_widg.setObjectName(QLatin1String(__FILE__ "__modal_dlg"));
+ modal_widg.createWinId();
+ QApplicationPrivate::enterModal(&modal_widg);
+ QApplicationPrivate::native_modal_dialog_active = true;
+ Boolean acceptStatus;
+ PMSessionPrintDialog(ep->session, ep->settings, ep->format, &acceptStatus);
+ QApplicationPrivate::leaveModal(&modal_widg);
+ QApplicationPrivate::native_modal_dialog_active = false;
+ printDialogSheetDoneCallback(ep->session, 0, acceptStatus);
+ } else {
+ // Window Modal means that we use a sheet at the moment, there's no other way to do it correctly.
+ if (!upp)
+ upp = NewPMSheetDoneUPP(QPrintDialogPrivate::printDialogSheetDoneCallback);
+ PMSessionUseSheets(ep->session, qt_mac_window_for(q->parentWidget()), upp);
+ QApplicationPrivate::native_modal_dialog_active = true;
+ Boolean unused;
+ PMSessionPrintDialog(ep->session, ep->settings, ep->format, &unused);
+ }
+}
+
+void QPrintDialogPrivate::closeCarbonPrintPanel()
+{
+ Q_Q(QPrintDialog);
+ QApplicationPrivate::native_modal_dialog_active = false;
+ if (q->result() == QDialog::Accepted) {
+ UInt32 frompage, topage;
+ PMGetFirstPage(ep->settings, &frompage);
+ PMGetLastPage(ep->settings, &topage);
+ topage = qMin(UInt32(INT_MAX), topage);
+ q->setFromTo(frompage, topage);
+
+ // OK, I need to map these values back let's see
+ // If from is 1 and to is INT_MAX, then print it all
+ // (Apologies to the folks with more than INT_MAX pages)
+ // ...that's a joke.
+ if (q->fromPage() == 1 && q->toPage() == INT_MAX) {
+ q->setPrintRange(QAbstractPrintDialog::AllPages);
+ q->setFromTo(0,0);
+ } else {
+ q->setPrintRange(QAbstractPrintDialog::PageRange); // In a way a lie, but it shouldn't hurt.
+ // Carbon hands us back a very large number here even for ALL, set it to max
+ // in that case to follow the behavior of the other print dialogs.
+ if (q->maxPage() < q->toPage())
+ q->setFromTo(q->fromPage(), q->maxPage());
+ }
+ // Keep us in sync with file output
+ PMDestinationType dest;
+ PMSessionGetDestinationType(ep->session, ep->settings, &dest);
+ if (dest == kPMDestinationFile) {
+ QCFType<CFURLRef> file;
+ PMSessionCopyDestinationLocation(ep->session, ep->settings, &file);
+ UInt8 localFile[2048]; // Assuming there's a POSIX file system here.
+ CFURLGetFileSystemRepresentation(file, true, localFile, sizeof(localFile));
+ ep->outputFilename = QString::fromUtf8(reinterpret_cast<const char *>(localFile));
+ } else {
+ ep->outputFilename = QString();
+ }
+ }
+ sheetCallbackMap.remove(ep->session);
+}
+#else
+void QPrintDialogPrivate::openCocoaPrintPanel(Qt::WindowModality modality)
+{
+ Q_Q(QPrintDialog);
+
+ initBeforeRun();
+
+ QPrintDialog::PrintDialogOptions qtOptions = q->options();
+ NSPrintPanelOptions macOptions = NSPrintPanelShowsCopies;
+ if (qtOptions & QPrintDialog::PrintPageRange)
+ macOptions |= NSPrintPanelShowsPageRange;
+ if (qtOptions & QPrintDialog::PrintShowPageSize)
+ macOptions |= NSPrintPanelShowsPaperSize | NSPrintPanelShowsPageSetupAccessory
+ | NSPrintPanelShowsOrientation;
+
+ macStartInterceptWindowTitle(q);
+ printPanel = [NSPrintPanel printPanel];
+ QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QCocoaPrintPanelDelegate) alloc] init];
+ [printPanel setOptions:macOptions];
+
+ if (modality == Qt::ApplicationModal) {
+ int rval = [printPanel runModalWithPrintInfo:ep->printInfo];
+ [delegate printPanelDidEnd:printPanel returnCode:rval contextInfo:this];
+ } else {
+ Q_ASSERT(q->parentWidget());
+ NSWindow *windowRef = qt_mac_window_for(q->parentWidget());
+ [printPanel beginSheetWithPrintInfo:ep->printInfo
+ modalForWindow:windowRef
+ delegate:delegate
+ didEndSelector:@selector(printPanelDidEnd:returnCode:contextInfo:)
+ contextInfo:this];
+ }
+
+ macStopInterceptWindowTitle();
+}
+
+void QPrintDialogPrivate::closeCocoaPrintPanel()
+{
+ // ###
+}
+#endif
+
+static bool warnIfNotNative(QPrinter *printer)
+{
+ if (printer->outputFormat() != QPrinter::NativeFormat) {
+ qWarning("QPrintDialog: Cannot be used on non-native printers");
+ return false;
+ }
+ return true;
+}
+
+
+QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent)
+ : QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent)
+{
+ Q_D(QPrintDialog);
+ if (!warnIfNotNative(d->printer))
+ return;
+ d->ep = static_cast<QMacPrintEngine *>(d->printer->paintEngine())->d_func();
+}
+
+QPrintDialog::QPrintDialog(QWidget *parent)
+ : QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent)
+{
+ Q_D(QPrintDialog);
+ if (!warnIfNotNative(d->printer))
+ return;
+ d->ep = static_cast<QMacPrintEngine *>(d->printer->paintEngine())->d_func();
+}
+
+QPrintDialog::~QPrintDialog()
+{
+}
+
+int QPrintDialog::exec()
+{
+ Q_D(QPrintDialog);
+ if (!warnIfNotNative(d->printer))
+ return QDialog::Rejected;
+
+#ifndef QT_MAC_USE_COCOA
+ d->openCarbonPrintPanel(Qt::ApplicationModal);
+#else
+ QMacCocoaAutoReleasePool pool;
+
+ d->openCocoaPrintPanel(Qt::ApplicationModal);
+ d->closeCocoaPrintPanel();
+#endif
+ return result();
+}
+
+#ifdef QT3_SUPPORT
+QPrinter *QPrintDialog::printer() const
+{
+ Q_D(const QPrintDialog);
+ return d->printer;
+}
+#endif
+
+/*!
+ \reimp
+*/
+void QPrintDialog::setVisible(bool visible)
+{
+ Q_D(QPrintDialog);
+
+ bool isCurrentlyVisible = (d->printPanel != 0);
+
+ if (!visible == !isCurrentlyVisible)
+ return;
+
+ if (d->printer->outputFormat() != QPrinter::NativeFormat)
+ return;
+
+ if (visible) {
+#ifndef QT_MAC_USE_COCOA
+ d->openCarbonPrintPanel(parentWidget() ? Qt::WindowModal
+ : Qt::ApplicationModal);
+#else
+ d->openCocoaPrintPanel(parentWidget() ? Qt::WindowModal
+ : Qt::ApplicationModal);
+#endif
+ return;
+ } else {
+ if (d->printPanel) {
+#ifndef QT_MAC_USE_COCOA
+ d->closeCarbonPrintPanel();
+#else
+ d->closeCocoaPrintPanel();
+#endif
+ return;
+ }
+ }
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qprintdialog.cpp"
+
+#endif // QT_NO_PRINTDIALOG
diff --git a/src/printsupport/dialogs/qprintdialog_unix.cpp b/src/printsupport/dialogs/qprintdialog_unix.cpp
new file mode 100644
index 0000000000..8da3665d56
--- /dev/null
+++ b/src/printsupport/dialogs/qprintdialog_unix.cpp
@@ -0,0 +1,1286 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplatformdefs.h"
+
+#ifndef QT_NO_PRINTDIALOG
+
+#include "private/qabstractprintdialog_p.h"
+#include <QtWidgets/qmessagebox.h>
+#include "qprintdialog.h"
+#include "qfiledialog.h"
+#include <QtCore/qdir.h>
+#include <QtGui/qevent.h>
+#include <QtWidgets/qfilesystemmodel.h>
+#include <QtWidgets/qstyleditemdelegate.h>
+#include <QtPrintSupport/qprinter.h>
+
+#include <QtWidgets/qdialogbuttonbox.h>
+
+#include "private/qfscompleter_p.h"
+#include "ui_qprintpropertieswidget.h"
+#include "ui_qprintsettingsoutput.h"
+#include "ui_qprintwidget.h"
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+# include <private/qcups_p.h>
+# include <cups/cups.h>
+# include <private/qprintengine_pdf_p.h>
+#else
+# include <QtCore/qlibrary.h>
+#endif
+
+#include <private/qprinterinfo_unix_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QOptionTreeItem;
+class QPPDOptionsModel;
+
+class QPrintPropertiesDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ QPrintPropertiesDialog(QAbstractPrintDialog *parent = 0);
+ ~QPrintPropertiesDialog();
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ void setCups(QCUPSSupport *cups) { m_cups = cups; }
+ void addItemToOptions(QOptionTreeItem *parent, QList<const ppd_option_t*>& options, QList<const char*>& markedOptions) const;
+#endif
+
+ void selectPrinter();
+ void selectPdfPsPrinter(const QPrinter *p);
+
+ /// copy printer properties to the widget
+ void applyPrinterProperties(QPrinter *p);
+ void setupPrinter() const;
+
+protected:
+ void showEvent(QShowEvent* event);
+
+private:
+ Ui::QPrintPropertiesWidget widget;
+ QDialogButtonBox *m_buttons;
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ QCUPSSupport *m_cups;
+ QPPDOptionsModel *m_cupsOptionsModel;
+#endif
+};
+
+class QPrintDialogPrivate : public QAbstractPrintDialogPrivate
+{
+ Q_DECLARE_PUBLIC(QPrintDialog)
+ Q_DECLARE_TR_FUNCTIONS(QPrintDialog)
+public:
+ QPrintDialogPrivate();
+ ~QPrintDialogPrivate();
+
+ void init();
+ /// copy printer properties to the widget
+ void applyPrinterProperties(QPrinter *p);
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ void selectPrinter(QCUPSSupport *cups);
+#endif
+
+ void _q_chbPrintLastFirstToggled(bool);
+#ifndef QT_NO_MESSAGEBOX
+ void _q_checkFields();
+#endif
+ void _q_collapseOrExpandDialog();
+
+ void setupPrinter();
+ void updateWidgets();
+
+ virtual void setTabs(const QList<QWidget*> &tabs);
+
+ Ui::QPrintSettingsOutput options;
+ QUnixPrintWidget *top;
+ QWidget *bottom;
+ QDialogButtonBox *buttons;
+ QPushButton *collapseButton;
+};
+
+#if defined (Q_OS_UNIX)
+class QUnixPrintWidgetPrivate
+{
+public:
+ QUnixPrintWidgetPrivate(QUnixPrintWidget *q);
+ ~QUnixPrintWidgetPrivate();
+
+ /// copy printer properties to the widget
+ void applyPrinterProperties(QPrinter *p);
+ bool checkFields();
+ void setupPrinter();
+ void setOptionsPane(QPrintDialogPrivate *pane);
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ void setCupsProperties();
+#endif
+
+// slots
+ void _q_printerChanged(int index);
+ void _q_btnPropertiesClicked();
+ void _q_btnBrowseClicked();
+
+ QUnixPrintWidget * const parent;
+ QPrintPropertiesDialog *propertiesDialog;
+ Ui::QPrintWidget widget;
+ QAbstractPrintDialog * q;
+ QPrinter *printer;
+ QList<QPrinterDescription> lprPrinters;
+ void updateWidget();
+
+private:
+ QPrintDialogPrivate *optionsPane;
+ bool filePrintersAdded;
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ QCUPSSupport* cups;
+ int cupsPrinterCount;
+ const cups_dest_t* cupsPrinters;
+ const ppd_file_t* cupsPPD;
+#endif
+};
+#endif
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+class QOptionTreeItem
+{
+public:
+ enum ItemType { Root, Group, Option, Choice };
+
+ QOptionTreeItem(ItemType t, int i, const void* p, const char* desc, QOptionTreeItem* pi)
+ : type(t),
+ index(i),
+ ptr(p),
+ description(desc),
+ selected(-1),
+ selDescription(0),
+ parentItem(pi) {}
+
+ ~QOptionTreeItem() {
+ while (!childItems.isEmpty())
+ delete childItems.takeFirst();
+ }
+
+ ItemType type;
+ int index;
+ const void* ptr;
+ const char* description;
+ int selected;
+ const char* selDescription;
+ QOptionTreeItem* parentItem;
+ QList<QOptionTreeItem*> childItems;
+};
+
+class QPPDOptionsModel : public QAbstractItemModel
+{
+ friend class QPPDOptionsEditor;
+public:
+ QPPDOptionsModel(QCUPSSupport *cups, QObject *parent = 0);
+ ~QPPDOptionsModel();
+
+ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
+ QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
+ QModelIndex parent(const QModelIndex& index) const;
+ Qt::ItemFlags flags(const QModelIndex& index) const;
+ QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
+
+ QOptionTreeItem* rootItem;
+ QCUPSSupport *cups;
+ const ppd_file_t* ppd;
+ void parseItems();
+ void parseGroups(QOptionTreeItem* parent);
+ void parseOptions(QOptionTreeItem* parent);
+ void parseChoices(QOptionTreeItem* parent);
+};
+
+class QPPDOptionsEditor : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ QPPDOptionsEditor(QObject* parent = 0) : QStyledItemDelegate(parent) {}
+ ~QPPDOptionsEditor() {}
+
+ QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ void setEditorData(QWidget* editor, const QModelIndex& index) const;
+ void setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
+
+private slots:
+ void cbChanged(int index);
+
+};
+
+#endif
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+QPrintPropertiesDialog::QPrintPropertiesDialog(QAbstractPrintDialog *parent)
+ : QDialog(parent)
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ , m_cups(0), m_cupsOptionsModel(0)
+#endif
+{
+ QVBoxLayout *lay = new QVBoxLayout(this);
+ this->setLayout(lay);
+ QWidget *content = new QWidget(this);
+ widget.setupUi(content);
+ m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
+ lay->addWidget(content);
+ lay->addWidget(m_buttons);
+
+ connect(m_buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept()));
+ connect(m_buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
+}
+
+QPrintPropertiesDialog::~QPrintPropertiesDialog()
+{
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ delete m_cupsOptionsModel;
+#else
+ delete widget.cupsPropertiesPage;
+#endif
+}
+
+void QPrintPropertiesDialog::applyPrinterProperties(QPrinter *p)
+{
+ widget.pageSetup->setPrinter(p);
+}
+
+void QPrintPropertiesDialog::setupPrinter() const
+{
+ widget.pageSetup->setupPrinter();
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ QPPDOptionsModel* model = static_cast<QPPDOptionsModel*>(widget.treeView->model());
+ if (model) {
+ QOptionTreeItem* rootItem = model->rootItem;
+ QList<const ppd_option_t*> options;
+ QList<const char*> markedOptions;
+
+ addItemToOptions(rootItem, options, markedOptions);
+ model->cups->saveOptions(options, markedOptions);
+ }
+#endif
+}
+
+void QPrintPropertiesDialog::selectPrinter()
+{
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ widget.pageSetup->selectPrinter(m_cups);
+ widget.treeView->setModel(0);
+ if (m_cups && QCUPSSupport::isAvailable()) {
+
+ if (m_cupsOptionsModel == 0) {
+ m_cupsOptionsModel = new QPPDOptionsModel(m_cups);
+
+ widget.treeView->setItemDelegate(new QPPDOptionsEditor(this));
+ } else {
+ // update the model
+ m_cupsOptionsModel->parseItems();
+ }
+
+ if (m_cupsOptionsModel->rowCount() > 0) {
+ widget.treeView->setModel(m_cupsOptionsModel);
+
+ for (int i = 0; i < m_cupsOptionsModel->rowCount(); ++i)
+ widget.treeView->expand(m_cupsOptionsModel->index(i,0));
+
+ widget.tabs->setTabEnabled(1, true); // enable the advanced tab
+ } else {
+ widget.tabs->setTabEnabled(1, false);
+ }
+
+ } else
+#endif
+ {
+ widget.cupsPropertiesPage->setEnabled(false);
+ widget.pageSetup->selectPrinter(0);
+ }
+}
+
+void QPrintPropertiesDialog::selectPdfPsPrinter(const QPrinter *p)
+{
+ widget.treeView->setModel(0);
+ widget.pageSetup->selectPdfPsPrinter(p);
+ widget.tabs->setTabEnabled(1, false); // disable the advanced tab
+}
+
+void QPrintPropertiesDialog::showEvent(QShowEvent* event)
+{
+ widget.treeView->resizeColumnToContents(0);
+ event->accept();
+}
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+void QPrintPropertiesDialog::addItemToOptions(QOptionTreeItem *parent, QList<const ppd_option_t*>& options, QList<const char*>& markedOptions) const
+{
+ for (int i = 0; i < parent->childItems.count(); ++i) {
+ QOptionTreeItem *itm = parent->childItems.at(i);
+ if (itm->type == QOptionTreeItem::Option) {
+ const ppd_option_t* opt = reinterpret_cast<const ppd_option_t*>(itm->ptr);
+ options << opt;
+ if (qstrcmp(opt->defchoice, opt->choices[itm->selected].choice) != 0) {
+ markedOptions << opt->keyword << opt->choices[itm->selected].choice;
+ }
+ } else {
+ addItemToOptions(itm, options, markedOptions);
+ }
+ }
+}
+#endif
+
+QPrintDialogPrivate::QPrintDialogPrivate()
+ : top(0), bottom(0), buttons(0), collapseButton(0)
+{
+}
+
+QPrintDialogPrivate::~QPrintDialogPrivate()
+{
+}
+
+void QPrintDialogPrivate::init()
+{
+ Q_Q(QPrintDialog);
+
+ top = new QUnixPrintWidget(0, q);
+ bottom = new QWidget(q);
+ options.setupUi(bottom);
+ options.color->setIconSize(QSize(32, 32));
+ options.color->setIcon(QIcon(QLatin1String(":/trolltech/dialogs/qprintdialog/images/status-color.png")));
+ options.grayscale->setIconSize(QSize(32, 32));
+ options.grayscale->setIcon(QIcon(QLatin1String(":/trolltech/dialogs/qprintdialog/images/status-gray-scale.png")));
+ top->d->setOptionsPane(this);
+
+ buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q);
+ collapseButton = new QPushButton(QPrintDialog::tr("&Options >>"), buttons);
+ buttons->addButton(collapseButton, QDialogButtonBox::ResetRole);
+ bottom->setVisible(false);
+
+ QPushButton *printButton = buttons->button(QDialogButtonBox::Ok);
+ printButton->setText(QPrintDialog::tr("&Print"));
+ printButton->setDefault(true);
+
+ QVBoxLayout *lay = new QVBoxLayout(q);
+ q->setLayout(lay);
+ lay->addWidget(top);
+ lay->addWidget(bottom);
+ lay->addWidget(buttons);
+
+ QPrinter* p = q->printer();
+
+ applyPrinterProperties(p);
+
+#ifdef QT_NO_MESSAGEBOX
+ QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(accept()));
+#else
+ QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(_q_checkFields()));
+#endif
+ QObject::connect(buttons, SIGNAL(rejected()), q, SLOT(reject()));
+
+ QObject::connect(options.reverse, SIGNAL(toggled(bool)),
+ q, SLOT(_q_chbPrintLastFirstToggled(bool)));
+
+ QObject::connect(collapseButton, SIGNAL(released()), q, SLOT(_q_collapseOrExpandDialog()));
+}
+
+void QPrintDialogPrivate::applyPrinterProperties(QPrinter *p)
+{
+ if (p->colorMode() == QPrinter::Color)
+ options.color->setChecked(true);
+ else
+ options.grayscale->setChecked(true);
+
+ switch(p->duplex()) {
+ case QPrinter::DuplexNone:
+ options.noDuplex->setChecked(true); break;
+ case QPrinter::DuplexLongSide:
+ case QPrinter::DuplexAuto:
+ options.duplexLong->setChecked(true); break;
+ case QPrinter::DuplexShortSide:
+ options.duplexShort->setChecked(true); break;
+ }
+ options.copies->setValue(p->copyCount());
+ options.collate->setChecked(p->collateCopies());
+ options.reverse->setChecked(p->pageOrder() == QPrinter::LastPageFirst);
+ top->d->applyPrinterProperties(p);
+}
+
+void QPrintDialogPrivate::_q_chbPrintLastFirstToggled(bool checked)
+{
+ Q_Q(QPrintDialog);
+ if (checked)
+ q->printer()->setPageOrder(QPrinter::LastPageFirst);
+ else
+ q->printer()->setPageOrder(QPrinter::FirstPageFirst);
+}
+
+void QPrintDialogPrivate::_q_collapseOrExpandDialog()
+{
+ int collapseHeight = 0;
+ Q_Q(QPrintDialog);
+ QWidget *widgetToHide = bottom;
+ if (widgetToHide->isVisible()) {
+ collapseButton->setText(QPrintDialog::tr("&Options >>"));
+ collapseHeight = widgetToHide->y() + widgetToHide->height() - (top->y() + top->height());
+ }
+ else
+ collapseButton->setText(QPrintDialog::tr("&Options <<"));
+ widgetToHide->setVisible(! widgetToHide->isVisible());
+ if (! widgetToHide->isVisible()) { // make it shrink
+ q->layout()->activate();
+ q->resize( QSize(q->width(), q->height() - collapseHeight) );
+ }
+}
+
+#ifndef QT_NO_MESSAGEBOX
+void QPrintDialogPrivate::_q_checkFields()
+{
+ Q_Q(QPrintDialog);
+ if (top->d->checkFields())
+ q->accept();
+}
+#endif // QT_NO_MESSAGEBOX
+
+void QPrintDialogPrivate::setupPrinter()
+{
+ Q_Q(QPrintDialog);
+ QPrinter* p = q->printer();
+
+ if (options.duplex->isEnabled()) {
+ if (options.noDuplex->isChecked())
+ p->setDuplex(QPrinter::DuplexNone);
+ else if (options.duplexLong->isChecked())
+ p->setDuplex(QPrinter::DuplexLongSide);
+ else
+ p->setDuplex(QPrinter::DuplexShortSide);
+ }
+
+ p->setColorMode( options.color->isChecked() ? QPrinter::Color : QPrinter::GrayScale );
+
+ // print range
+ if (options.printAll->isChecked()) {
+ p->setPrintRange(QPrinter::AllPages);
+ p->setFromTo(0,0);
+ } else if (options.printSelection->isChecked()) {
+ p->setPrintRange(QPrinter::Selection);
+ p->setFromTo(0,0);
+ } else if (options.printCurrentPage->isChecked()) {
+ p->setPrintRange(QPrinter::CurrentPage);
+ p->setFromTo(0,0);
+ } else if (options.printRange->isChecked()) {
+ p->setPrintRange(QPrinter::PageRange);
+ p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value()));
+ }
+
+ // copies
+ p->setCopyCount(options.copies->value());
+ p->setCollateCopies(options.collate->isChecked());
+
+ top->d->setupPrinter();
+}
+
+void QPrintDialogPrivate::updateWidgets()
+{
+ Q_Q(QPrintDialog);
+ options.gbPrintRange->setVisible(q->isOptionEnabled(QPrintDialog::PrintPageRange) ||
+ q->isOptionEnabled(QPrintDialog::PrintSelection) ||
+ q->isOptionEnabled(QPrintDialog::PrintCurrentPage));
+
+ options.printRange->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange));
+ options.printSelection->setVisible(q->isOptionEnabled(QPrintDialog::PrintSelection));
+ options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage));
+ options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies));
+
+ switch (q->printRange()) {
+ case QPrintDialog::AllPages:
+ options.printAll->setChecked(true);
+ break;
+ case QPrintDialog::Selection:
+ options.printSelection->setChecked(true);
+ break;
+ case QPrintDialog::PageRange:
+ options.printRange->setChecked(true);
+ break;
+ case QPrintDialog::CurrentPage:
+ if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage))
+ options.printCurrentPage->setChecked(true);
+ break;
+ default:
+ break;
+ }
+ const int minPage = qMax(1, qMin(q->minPage() , q->maxPage()));
+ const int maxPage = qMax(1, q->maxPage() == INT_MAX ? 9999 : q->maxPage());
+
+ options.from->setMinimum(minPage);
+ options.to->setMinimum(minPage);
+ options.from->setMaximum(maxPage);
+ options.to->setMaximum(maxPage);
+
+ options.from->setValue(q->fromPage());
+ options.to->setValue(q->toPage());
+ top->d->updateWidget();
+}
+
+void QPrintDialogPrivate::setTabs(const QList<QWidget*> &tabWidgets)
+{
+ while(options.tabs->count() > 2)
+ delete options.tabs->widget(2);
+
+ QList<QWidget*>::ConstIterator iter = tabWidgets.begin();
+ while(iter != tabWidgets.constEnd()) {
+ QWidget *tab = *iter;
+ options.tabs->addTab(tab, tab->windowTitle());
+ ++iter;
+ }
+}
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+void QPrintDialogPrivate::selectPrinter(QCUPSSupport *cups)
+{
+ options.duplex->setEnabled(cups && cups->ppdOption("Duplex"));
+}
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent)
+ : QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent)
+{
+ Q_D(QPrintDialog);
+ d->init();
+}
+
+/*!
+ Constructs a print dialog with the given \a parent.
+*/
+QPrintDialog::QPrintDialog(QWidget *parent)
+ : QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent)
+{
+ Q_D(QPrintDialog);
+ d->init();
+}
+
+QPrintDialog::~QPrintDialog()
+{
+}
+
+void QPrintDialog::setVisible(bool visible)
+{
+ Q_D(QPrintDialog);
+
+ if (visible)
+ d->updateWidgets();
+
+ QAbstractPrintDialog::setVisible(visible);
+}
+
+int QPrintDialog::exec()
+{
+ return QDialog::exec();
+}
+
+void QPrintDialog::accept()
+{
+ Q_D(QPrintDialog);
+ d->setupPrinter();
+ QDialog::accept();
+}
+
+#ifdef QT3_SUPPORT
+QPrinter *QPrintDialog::printer() const
+{
+ Q_D(const QPrintDialog);
+ return d->printer;
+}
+
+void QPrintDialog::setPrinter(QPrinter *printer, bool pickupSettings)
+{
+ if (!printer)
+ return;
+
+ Q_D(QPrintDialog);
+ d->printer = printer;
+
+ if (pickupSettings)
+ d->applyPrinterProperties(printer);
+}
+
+void QPrintDialog::addButton(QPushButton *button)
+{
+ Q_D(QPrintDialog);
+ d->buttons->addButton(button, QDialogButtonBox::HelpRole);
+}
+#endif // QT3_SUPPORT
+
+#if defined (Q_OS_UNIX)
+
+/*! \internal
+*/
+QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p)
+ : parent(p), propertiesDialog(0), printer(0), optionsPane(0), filePrintersAdded(false)
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ , cups(0), cupsPrinterCount(0), cupsPrinters(0), cupsPPD(0)
+#endif
+{
+ q = 0;
+ if (parent)
+ q = qobject_cast<QAbstractPrintDialog*> (parent->parent());
+
+ widget.setupUi(parent);
+
+ int currentPrinterIndex = 0;
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ cups = new QCUPSSupport;
+ if (QCUPSSupport::isAvailable()) {
+ cupsPPD = cups->currentPPD();
+ cupsPrinterCount = cups->availablePrintersCount();
+ cupsPrinters = cups->availablePrinters();
+
+ for (int i = 0; i < cupsPrinterCount; ++i) {
+ QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
+ if (cupsPrinters[i].instance)
+ printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
+
+ widget.printers->addItem(printerName);
+ if (cupsPrinters[i].is_default)
+ widget.printers->setCurrentIndex(i);
+ }
+ // the model depends on valid ppd. so before enabling the
+ // properties button we make sure the ppd is in fact valid.
+ if (cupsPrinterCount && cups->currentPPD()) {
+ widget.properties->setEnabled(true);
+ }
+ currentPrinterIndex = cups->currentPrinterIndex();
+ } else {
+#endif
+ currentPrinterIndex = qt_getLprPrinters(lprPrinters);
+ // populating printer combo
+ QList<QPrinterDescription>::const_iterator i = lprPrinters.constBegin();
+ for(; i != lprPrinters.constEnd(); ++i)
+ widget.printers->addItem((*i).name);
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ }
+#endif
+
+#if !defined(QT_NO_FILESYSTEMMODEL) && !defined(QT_NO_COMPLETER)
+ QFileSystemModel *fsm = new QFileSystemModel(widget.filename);
+ fsm->setRootPath(QDir::homePath());
+ widget.filename->setCompleter(new QCompleter(fsm, widget.filename));
+#endif
+ _q_printerChanged(currentPrinterIndex);
+
+ QObject::connect(widget.printers, SIGNAL(currentIndexChanged(int)),
+ parent, SLOT(_q_printerChanged(int)));
+ QObject::connect(widget.fileBrowser, SIGNAL(clicked()), parent, SLOT(_q_btnBrowseClicked()));
+ QObject::connect(widget.properties, SIGNAL(clicked()), parent, SLOT(_q_btnPropertiesClicked()));
+
+ // disable features that QPrinter does not yet support.
+ widget.preview->setVisible(false);
+}
+
+void QUnixPrintWidgetPrivate::updateWidget()
+{
+ const bool printToFile = q == 0 || q->isOptionEnabled(QPrintDialog::PrintToFile);
+ if (printToFile && !filePrintersAdded) {
+ if (widget.printers->count())
+ widget.printers->insertSeparator(widget.printers->count());
+ widget.printers->addItem(QPrintDialog::tr("Print to File (PDF)"));
+ filePrintersAdded = true;
+ }
+ if (!printToFile && filePrintersAdded) {
+ widget.printers->removeItem(widget.printers->count()-1);
+ widget.printers->removeItem(widget.printers->count()-1);
+ if (widget.printers->count())
+ widget.printers->removeItem(widget.printers->count()-1); // remove separator
+ filePrintersAdded = false;
+ }
+ if (printer && filePrintersAdded && (printer->outputFormat() != QPrinter::NativeFormat
+ || printer->printerName().isEmpty()))
+ {
+ if (printer->outputFormat() == QPrinter::PdfFormat)
+ widget.printers->setCurrentIndex(widget.printers->count() - 1);
+ widget.filename->setEnabled(true);
+ widget.lOutput->setEnabled(true);
+ }
+
+ widget.filename->setVisible(printToFile);
+ widget.lOutput->setVisible(printToFile);
+ widget.fileBrowser->setVisible(printToFile);
+
+ widget.properties->setVisible(q->isOptionEnabled(QAbstractPrintDialog::PrintShowPageSize));
+}
+
+QUnixPrintWidgetPrivate::~QUnixPrintWidgetPrivate()
+{
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ delete cups;
+#endif
+}
+
+void QUnixPrintWidgetPrivate::_q_printerChanged(int index)
+{
+ if (index < 0)
+ return;
+ const int printerCount = widget.printers->count();
+ widget.filename->setEnabled(false);
+ widget.lOutput->setEnabled(false);
+
+ if (filePrintersAdded) {
+ Q_ASSERT(index != printerCount - 3); // separator
+ if (index == printerCount - 1) { // PDF
+ widget.location->setText(QPrintDialog::tr("Local file"));
+ widget.type->setText(QPrintDialog::tr("Write PDF file"));
+ widget.properties->setEnabled(true);
+ widget.filename->setEnabled(true);
+ QString filename = widget.filename->text();
+ QString suffix = QFileInfo(filename).suffix();
+ widget.filename->setText(filename);
+ widget.lOutput->setEnabled(true);
+ if (propertiesDialog)
+ propertiesDialog->selectPdfPsPrinter(printer);
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (optionsPane)
+ optionsPane->selectPrinter(0);
+#endif
+ return;
+ }
+ }
+
+ widget.location->setText(QString());
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (QCUPSSupport::isAvailable()) {
+ cups->setCurrentPrinter(index);
+
+ const cups_option_t *opt = cups->printerOption(QString::fromLatin1("printer-location"));
+ QString location;
+ if (opt)
+ location = QString::fromLocal8Bit(opt->value);
+ widget.location->setText(location);
+
+ cupsPPD = cups->currentPPD();
+ // set printer type line
+ QString type;
+ if (cupsPPD)
+ type = QString::fromLocal8Bit(cupsPPD->manufacturer) + QLatin1String(" - ") + QString::fromLocal8Bit(cupsPPD->modelname);
+ widget.type->setText(type);
+ if (propertiesDialog)
+ propertiesDialog->selectPrinter();
+ if (optionsPane)
+ optionsPane->selectPrinter(cups);
+ } else {
+ if (optionsPane)
+ optionsPane->selectPrinter(0);
+#endif
+ if (lprPrinters.count() > 0) {
+ QString type = lprPrinters.at(index).name + QLatin1Char('@') + lprPrinters.at(index).host;
+ if (!lprPrinters.at(index).comment.isEmpty())
+ type += QLatin1String(", ") + lprPrinters.at(index).comment;
+ widget.type->setText(type);
+ if (propertiesDialog)
+ propertiesDialog->selectPrinter();
+ }
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ }
+#endif
+}
+
+void QUnixPrintWidgetPrivate::setOptionsPane(QPrintDialogPrivate *pane)
+{
+ optionsPane = pane;
+ if (optionsPane)
+ _q_printerChanged(widget.printers->currentIndex());
+}
+
+void QUnixPrintWidgetPrivate::_q_btnBrowseClicked()
+{
+ QString filename = widget.filename->text();
+#ifndef QT_NO_FILEDIALOG
+ filename = QFileDialog::getSaveFileName(parent, QPrintDialog::tr("Print To File ..."), filename,
+ QString(), 0, QFileDialog::DontConfirmOverwrite);
+#else
+ filename.clear();
+#endif
+ if (!filename.isEmpty()) {
+ widget.filename->setText(filename);
+ widget.printers->setCurrentIndex(widget.printers->count() - 1); // the pdf one
+ }
+}
+
+void QUnixPrintWidgetPrivate::applyPrinterProperties(QPrinter *p)
+{
+ if (p == 0)
+ return;
+ printer = p;
+ if (p->outputFileName().isEmpty()) {
+ QString home = QString::fromLocal8Bit(qgetenv("HOME").constData());
+ QString cur = QDir::currentPath();
+ if (home.at(home.length()-1) != QLatin1Char('/'))
+ home += QLatin1Char('/');
+ if (cur.at(cur.length()-1) != QLatin1Char('/'))
+ cur += QLatin1Char('/');
+ if (cur.left(home.length()) != home)
+ cur = home;
+#ifdef Q_WS_X11
+ if (p->docName().isEmpty()) {
+ cur += QLatin1String("print.pdf");
+ } else {
+ QRegExp re(QString::fromLatin1("(.*)\\.\\S+"));
+ if (re.exactMatch(p->docName()))
+ cur += re.cap(1);
+ else
+ cur += p->docName();
+ cur += QLatin1String(".pdf");
+ }
+#endif
+ widget.filename->setText(cur);
+ }
+ else
+ widget.filename->setText( p->outputFileName() );
+ QString printer = p->printerName();
+ if (!printer.isEmpty()) {
+ for (int i = 0; i < widget.printers->count(); ++i) {
+ if (widget.printers->itemText(i) == printer) {
+ widget.printers->setCurrentIndex(i);
+ break;
+ }
+ }
+ }
+ // PDF and PS printers are not added to the dialog yet, we'll handle those cases in QUnixPrintWidgetPrivate::updateWidget
+
+ if (propertiesDialog)
+ propertiesDialog->applyPrinterProperties(p);
+}
+
+#ifndef QT_NO_MESSAGEBOX
+bool QUnixPrintWidgetPrivate::checkFields()
+{
+ if (widget.filename->isEnabled()) {
+ QString file = widget.filename->text();
+ QFile f(file);
+ QFileInfo fi(f);
+ bool exists = fi.exists();
+ bool opened = false;
+ if (exists && fi.isDir()) {
+ QMessageBox::warning(q, q->windowTitle(),
+ QPrintDialog::tr("%1 is a directory.\nPlease choose a different file name.").arg(file));
+ return false;
+ } else if ((exists && !fi.isWritable()) || !(opened = f.open(QFile::Append))) {
+ QMessageBox::warning(q, q->windowTitle(),
+ QPrintDialog::tr("File %1 is not writable.\nPlease choose a different file name.").arg(file));
+ return false;
+ } else if (exists) {
+ int ret = QMessageBox::question(q, q->windowTitle(),
+ QPrintDialog::tr("%1 already exists.\nDo you want to overwrite it?").arg(file),
+ QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
+ if (ret == QMessageBox::No)
+ return false;
+ }
+ if (opened) {
+ f.close();
+ if (!exists)
+ f.remove();
+ }
+ }
+
+ // Every test passed. Accept the dialog.
+ return true;
+}
+#endif // QT_NO_MESSAGEBOX
+
+void QUnixPrintWidgetPrivate::_q_btnPropertiesClicked()
+{
+ if (!propertiesDialog) {
+ propertiesDialog = new QPrintPropertiesDialog(q);
+ propertiesDialog->setResult(QDialog::Rejected);
+ }
+
+ if (propertiesDialog->result() == QDialog::Rejected) {
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ propertiesDialog->setCups(cups);
+#endif
+ propertiesDialog->applyPrinterProperties(q->printer());
+
+ if (q->isOptionEnabled(QPrintDialog::PrintToFile)
+ && (widget.printers->currentIndex() == widget.printers->count() - 1)) // PDF
+ propertiesDialog->selectPdfPsPrinter(q->printer());
+ else
+ propertiesDialog->selectPrinter();
+ }
+ propertiesDialog->exec();
+}
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+void QUnixPrintWidgetPrivate::setCupsProperties()
+{
+ if (cups && QCUPSSupport::isAvailable() && cups->pageSizes()) {
+ QPrintEngine *engine = printer->printEngine();
+ const ppd_option_t* pageSizes = cups->pageSizes();
+ QByteArray cupsPageSize;
+ for (int i = 0; i < pageSizes->num_choices; ++i) {
+ if (static_cast<int>(pageSizes->choices[i].marked) == 1)
+ cupsPageSize = pageSizes->choices[i].choice;
+ }
+ engine->setProperty(PPK_CupsStringPageSize, QString::fromLatin1(cupsPageSize));
+ engine->setProperty(PPK_CupsOptions, cups->options());
+
+ QRect pageRect = cups->pageRect(cupsPageSize);
+ engine->setProperty(PPK_CupsPageRect, pageRect);
+
+ QRect paperRect = cups->paperRect(cupsPageSize);
+ engine->setProperty(PPK_CupsPaperRect, paperRect);
+
+ for (int ps = 0; ps < QPrinter::NPageSize; ++ps) {
+ QPdf::PaperSize size = QPdf::paperSize(QPrinter::PaperSize(ps));
+ if (size.width == paperRect.width() && size.height == paperRect.height())
+ printer->setPaperSize(static_cast<QPrinter::PaperSize>(ps));
+ }
+ }
+}
+#endif
+
+void QUnixPrintWidgetPrivate::setupPrinter()
+{
+ const int printerCount = widget.printers->count();
+ const int index = widget.printers->currentIndex();
+
+ if (filePrintersAdded && index == printerCount - 1) { // PDF
+ printer->setPrinterName(QString());
+ Q_ASSERT(index != printerCount - 3); // separator
+ printer->setOutputFormat(QPrinter::PdfFormat);
+ QString path = widget.filename->text();
+ if (QDir::isRelativePath(path))
+ path = QDir::homePath() + QDir::separator() + path;
+ printer->setOutputFileName(path);
+ }
+ else {
+ printer->setPrinterName(widget.printers->currentText());
+ printer->setOutputFileName(QString());
+ }
+
+ if (propertiesDialog && propertiesDialog->result() == QDialog::Accepted)
+ propertiesDialog->setupPrinter();
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (!propertiesDialog)
+ setCupsProperties();
+#endif
+}
+
+
+/*! \internal
+*/
+QUnixPrintWidget::QUnixPrintWidget(QPrinter *printer, QWidget *parent)
+ : QWidget(parent), d(new QUnixPrintWidgetPrivate(this))
+{
+ d->applyPrinterProperties(printer);
+}
+
+/*! \internal
+*/
+QUnixPrintWidget::~QUnixPrintWidget()
+{
+ delete d;
+}
+
+/*! \internal
+
+ Updates the printer with the states held in the QUnixPrintWidget.
+*/
+void QUnixPrintWidget::updatePrinter()
+{
+ d->setupPrinter();
+}
+
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+
+QPPDOptionsModel::QPPDOptionsModel(QCUPSSupport *c, QObject *parent)
+ : QAbstractItemModel(parent), rootItem(0), cups(c), ppd(c->currentPPD())
+{
+ parseItems();
+}
+
+QPPDOptionsModel::~QPPDOptionsModel()
+{
+}
+
+int QPPDOptionsModel::columnCount(const QModelIndex&) const
+{
+ return 2;
+}
+
+int QPPDOptionsModel::rowCount(const QModelIndex& parent) const
+{
+ QOptionTreeItem* itm;
+ if (!parent.isValid())
+ itm = rootItem;
+ else
+ itm = reinterpret_cast<QOptionTreeItem*>(parent.internalPointer());
+
+ if (itm->type == QOptionTreeItem::Option)
+ return 0;
+
+ return itm->childItems.count();
+}
+
+QVariant QPPDOptionsModel::data(const QModelIndex& index, int role) const
+{
+ switch(role) {
+ case Qt::FontRole: {
+ QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
+ if (itm && itm->type == QOptionTreeItem::Group){
+ QFont font = QApplication::font();
+ font.setBold(true);
+ return QVariant(font);
+ }
+ return QVariant();
+ }
+ break;
+
+ case Qt::DisplayRole: {
+ QOptionTreeItem* itm;
+ if (!index.isValid())
+ itm = rootItem;
+ else
+ itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
+
+ if (index.column() == 0)
+ return cups->unicodeString(itm->description);
+ else if (itm->type == QOptionTreeItem::Option && itm->selected > -1)
+ return cups->unicodeString(itm->selDescription);
+ else
+ return QVariant();
+ }
+ break;
+
+ default:
+ return QVariant();
+ }
+ if (role != Qt::DisplayRole)
+ return QVariant();
+}
+
+QModelIndex QPPDOptionsModel::index(int row, int column, const QModelIndex& parent) const
+{
+ QOptionTreeItem* itm;
+ if (!parent.isValid())
+ itm = rootItem;
+ else
+ itm = reinterpret_cast<QOptionTreeItem*>(parent.internalPointer());
+
+ return createIndex(row, column, itm->childItems.at(row));
+}
+
+
+QModelIndex QPPDOptionsModel::parent(const QModelIndex& index) const
+{
+ if (!index.isValid())
+ return QModelIndex();
+
+ QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
+
+ if (itm->parentItem && itm->parentItem != rootItem)
+ return createIndex(itm->parentItem->index, 0, itm->parentItem);
+ else
+ return QModelIndex();
+}
+
+Qt::ItemFlags QPPDOptionsModel::flags(const QModelIndex& index) const
+{
+ if (!index.isValid() || reinterpret_cast<QOptionTreeItem*>(index.internalPointer())->type == QOptionTreeItem::Group)
+ return Qt::ItemIsEnabled;
+
+ if (index.column() == 1)
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
+
+ return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+}
+
+void QPPDOptionsModel::parseItems()
+{
+ emit layoutAboutToBeChanged();
+ ppd = cups->currentPPD();
+ delete rootItem;
+ rootItem = new QOptionTreeItem(QOptionTreeItem::Root, 0, ppd, "Root Item", 0);
+ parseGroups(rootItem);
+ emit layoutChanged();
+}
+
+void QPPDOptionsModel::parseGroups(QOptionTreeItem* parent)
+{
+ if (parent->type == QOptionTreeItem::Root) {
+
+ const ppd_file_t* ppdFile = reinterpret_cast<const ppd_file_t*>(parent->ptr);
+
+ if (ppdFile) {
+ for (int i = 0; i < ppdFile->num_groups; ++i) {
+ QOptionTreeItem* group = new QOptionTreeItem(QOptionTreeItem::Group, i, &ppdFile->groups[i], ppdFile->groups[i].text, parent);
+ parent->childItems.append(group);
+ parseGroups(group); // parse possible subgroups
+ parseOptions(group); // parse options
+ }
+ }
+ } else if (parent->type == QOptionTreeItem::Group) {
+
+ const ppd_group_t* group = reinterpret_cast<const ppd_group_t*>(parent->ptr);
+
+ if (group) {
+ for (int i = 0; i < group->num_subgroups; ++i) {
+ QOptionTreeItem* subgroup = new QOptionTreeItem(QOptionTreeItem::Group, i, &group->subgroups[i], group->subgroups[i].text, parent);
+ parent->childItems.append(subgroup);
+ parseGroups(subgroup); // parse possible subgroups
+ parseOptions(subgroup); // parse options
+ }
+ }
+ }
+}
+
+void QPPDOptionsModel::parseOptions(QOptionTreeItem* parent)
+{
+ const ppd_group_t* group = reinterpret_cast<const ppd_group_t*>(parent->ptr);
+ for (int i = 0; i < group->num_options; ++i) {
+ QOptionTreeItem* opt = new QOptionTreeItem(QOptionTreeItem::Option, i, &group->options[i], group->options[i].text, parent);
+ parent->childItems.append(opt);
+ parseChoices(opt);
+ }
+}
+
+void QPPDOptionsModel::parseChoices(QOptionTreeItem* parent)
+{
+ const ppd_option_t* option = reinterpret_cast<const ppd_option_t*>(parent->ptr);
+ bool marked = false;
+ for (int i = 0; i < option->num_choices; ++i) {
+ QOptionTreeItem* choice = new QOptionTreeItem(QOptionTreeItem::Choice, i, &option->choices[i], option->choices[i].text, parent);
+ if (static_cast<int>(option->choices[i].marked) == 1) {
+ parent->selected = i;
+ parent->selDescription = option->choices[i].text;
+ marked = true;
+ } else if (!marked && qstrcmp(option->choices[i].choice, option->defchoice) == 0) {
+ parent->selected = i;
+ parent->selDescription = option->choices[i].text;
+ }
+ parent->childItems.append(choice);
+ }
+}
+
+QVariant QPPDOptionsModel::headerData(int section, Qt::Orientation, int role) const
+{
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ switch(section){
+ case 0:
+ return QVariant(QApplication::translate("QPPDOptionsModel", "Name"));
+ case 1:
+ return QVariant(QApplication::translate("QPPDOptionsModel", "Value"));
+ default:
+ return QVariant();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+QWidget* QPPDOptionsEditor::createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex& index) const
+{
+ if (index.column() == 1 && reinterpret_cast<QOptionTreeItem*>(index.internalPointer())->type == QOptionTreeItem::Option)
+ return new QComboBox(parent);
+ else
+ return 0;
+}
+
+void QPPDOptionsEditor::setEditorData(QWidget* editor, const QModelIndex& index) const
+{
+ if (index.column() != 1)
+ return;
+
+ QComboBox* cb = static_cast<QComboBox*>(editor);
+ QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
+
+ if (itm->selected == -1)
+ cb->addItem(QString());
+
+ for (int i = 0; i < itm->childItems.count(); ++i)
+ cb->addItem(QString::fromLocal8Bit(itm->childItems.at(i)->description));
+
+ if (itm->selected > -1)
+ cb->setCurrentIndex(itm->selected);
+
+ connect(cb, SIGNAL(currentIndexChanged(int)), this, SLOT(cbChanged(int)));
+}
+
+void QPPDOptionsEditor::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
+{
+ QComboBox* cb = static_cast<QComboBox*>(editor);
+ QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
+
+ if (itm->selected == cb->currentIndex())
+ return;
+
+ const ppd_option_t* opt = reinterpret_cast<const ppd_option_t*>(itm->ptr);
+ QPPDOptionsModel* m = static_cast<QPPDOptionsModel*>(model);
+
+ if (m->cups->markOption(opt->keyword, opt->choices[cb->currentIndex()].choice) == 0) {
+ itm->selected = cb->currentIndex();
+ itm->selDescription = reinterpret_cast<const ppd_option_t*>(itm->ptr)->choices[itm->selected].text;
+ }
+}
+
+void QPPDOptionsEditor::cbChanged(int)
+{
+/*
+ emit commitData(static_cast<QWidget*>(sender()));
+*/
+}
+
+#endif
+
+QT_END_NAMESPACE
+
+#include "moc_qprintdialog.cpp"
+#include "qprintdialog_unix.moc"
+#include "qrc_qprintdialog.cpp"
+
+#endif // QT_NO_PRINTDIALOG
+
diff --git a/src/printsupport/dialogs/qprintdialog_win.cpp b/src/printsupport/dialogs/qprintdialog_win.cpp
new file mode 100644
index 0000000000..c8d92d45f2
--- /dev/null
+++ b/src/printsupport/dialogs/qprintdialog_win.cpp
@@ -0,0 +1,316 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT_NO_PRINTDIALOG
+
+#include "qprintdialog.h"
+
+#include <qwidget.h>
+#include <qapplication.h>
+#include <qmessagebox.h>
+#include <private/qapplication_p.h>
+
+#include <private/qabstractprintdialog_p.h>
+#include <private/qprintengine_win_p.h>
+#include <private/qprinter_p.h>
+
+#if !defined(PD_NOCURRENTPAGE)
+#define PD_NOCURRENTPAGE 0x00800000
+#define PD_RESULT_PRINT 1
+#define PD_RESULT_APPLY 2
+#define START_PAGE_GENERAL 0XFFFFFFFF
+#endif
+
+QT_BEGIN_NAMESPACE
+
+extern void qt_win_eatMouseMove();
+
+class QPrintDialogPrivate : public QAbstractPrintDialogPrivate
+{
+ Q_DECLARE_PUBLIC(QPrintDialog)
+public:
+ QPrintDialogPrivate()
+ : ep(0)
+ {
+ }
+
+ inline void _q_printToFileChanged(int) {}
+ inline void _q_rbPrintRangeToggled(bool) {}
+ inline void _q_printerChanged(int) {}
+ inline void _q_chbPrintLastFirstToggled(bool) {}
+ inline void _q_paperSizeChanged(int) {}
+ inline void _q_btnBrowseClicked() {}
+ inline void _q_btnPropertiesClicked() {}
+ int openWindowsPrintDialogModally();
+
+ QWin32PrintEnginePrivate *ep;
+};
+
+static void qt_win_setup_PRINTDLGEX(PRINTDLGEX *pd, QWidget *parent,
+ QPrintDialog *pdlg,
+ QPrintDialogPrivate *d, HGLOBAL *tempDevNames)
+{
+ DEVMODE *devMode = d->ep->devMode;
+
+ if (devMode) {
+ int size = sizeof(DEVMODE) + devMode->dmDriverExtra;
+ pd->hDevMode = GlobalAlloc(GHND, size);
+ {
+ void *dest = GlobalLock(pd->hDevMode);
+ memcpy(dest, devMode, size);
+ GlobalUnlock(pd->hDevMode);
+ }
+ } else {
+ pd->hDevMode = NULL;
+ }
+ pd->hDevNames = tempDevNames;
+
+ pd->Flags = PD_RETURNDC;
+ pd->Flags |= PD_USEDEVMODECOPIESANDCOLLATE;
+
+ if (!pdlg->isOptionEnabled(QPrintDialog::PrintSelection))
+ pd->Flags |= PD_NOSELECTION;
+ if (pdlg->isOptionEnabled(QPrintDialog::PrintPageRange)) {
+ pd->nMinPage = pdlg->minPage();
+ pd->nMaxPage = pdlg->maxPage();
+ }
+
+ if(!pdlg->isOptionEnabled(QPrintDialog::PrintToFile))
+ pd->Flags |= PD_DISABLEPRINTTOFILE;
+
+ if (pdlg->printRange() == QPrintDialog::Selection)
+ pd->Flags |= PD_SELECTION;
+ else if (pdlg->printRange() == QPrintDialog::PageRange)
+ pd->Flags |= PD_PAGENUMS;
+ else
+ pd->Flags |= PD_ALLPAGES;
+
+ // As stated by MSDN, to enable collate option when minpage==maxpage==0
+ // set the PD_NOPAGENUMS flag
+ if (pd->nMinPage==0 && pd->nMaxPage==0)
+ pd->Flags |= PD_NOPAGENUMS;
+
+ // Disable Current Page option if not required as default is Enabled
+ if (!pdlg->isOptionEnabled(QPrintDialog::PrintCurrentPage))
+ pd->Flags |= PD_NOCURRENTPAGE;
+
+ // Default to showing the General tab first
+ pd->nStartPage = START_PAGE_GENERAL;
+
+ // We don't support more than one page range in the QPrinter API yet.
+ pd->nPageRanges = 1;
+ pd->nMaxPageRanges = 1;
+
+ if (d->ep->printToFile)
+ pd->Flags |= PD_PRINTTOFILE;
+ Q_ASSERT(parent);
+ pd->hwndOwner = parent->window()->winId();
+ 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;
+}
+
+static void qt_win_read_back_PRINTDLGEX(PRINTDLGEX *pd, QPrintDialog *pdlg, QPrintDialogPrivate *d)
+{
+ if (pd->Flags & PD_SELECTION) {
+ pdlg->setPrintRange(QPrintDialog::Selection);
+ pdlg->setFromTo(0, 0);
+ } else if (pd->Flags & PD_PAGENUMS) {
+ pdlg->setPrintRange(QPrintDialog::PageRange);
+ pdlg->setFromTo(pd->lpPageRanges[0].nFromPage, pd->lpPageRanges[0].nToPage);
+ } else if (pd->Flags & PD_CURRENTPAGE) {
+ pdlg->setPrintRange(QPrintDialog::CurrentPage);
+ pdlg->setFromTo(0, 0);
+ } else { // PD_ALLPAGES
+ pdlg->setPrintRange(QPrintDialog::AllPages);
+ pdlg->setFromTo(0, 0);
+ }
+
+ d->ep->printToFile = (pd->Flags & PD_PRINTTOFILE) != 0;
+
+ d->ep->readDevnames(pd->hDevNames);
+ d->ep->readDevmode(pd->hDevMode);
+ d->ep->updateCustomPaperSize();
+
+ if (d->ep->printToFile && d->ep->fileName.isEmpty())
+ d->ep->fileName = d->ep->port;
+ else if (!d->ep->printToFile && d->ep->fileName == QLatin1String("FILE:"))
+ d->ep->fileName.clear();
+}
+
+static bool warnIfNotNative(QPrinter *printer)
+{
+ if (printer->outputFormat() != QPrinter::NativeFormat) {
+ qWarning("QPrintDialog: Cannot be used on non-native printers");
+ return false;
+ }
+ return true;
+}
+
+QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent)
+ : QAbstractPrintDialog( *(new QPrintDialogPrivate), printer, parent)
+{
+ Q_D(QPrintDialog);
+ if (!warnIfNotNative(d->printer))
+ return;
+ d->ep = static_cast<QWin32PrintEngine *>(d->printer->paintEngine())->d_func();
+}
+
+QPrintDialog::QPrintDialog(QWidget *parent)
+ : QAbstractPrintDialog( *(new QPrintDialogPrivate), 0, parent)
+{
+ Q_D(QPrintDialog);
+ if (!warnIfNotNative(d->printer))
+ return;
+ d->ep = static_cast<QWin32PrintEngine *>(d->printer->paintEngine())->d_func();
+}
+
+QPrintDialog::~QPrintDialog()
+{
+}
+
+int QPrintDialog::exec()
+{
+ if (!warnIfNotNative(printer()))
+ return 0;
+
+ Q_D(QPrintDialog);
+ return d->openWindowsPrintDialogModally();
+}
+
+int QPrintDialogPrivate::openWindowsPrintDialogModally()
+{
+ Q_Q(QPrintDialog);
+ QWidget *parent = q->parentWidget();
+ if (parent)
+ parent = parent->window();
+ else
+ parent = QApplication::activeWindow();
+
+ // If there is no window, fall back to the print dialog itself
+ if (parent == 0)
+ parent = q;
+
+ QWidget modal_widget;
+ modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
+ modal_widget.setParent(parent, Qt::Window);
+ QApplicationPrivate::enterModal(&modal_widget);
+
+ HGLOBAL *tempDevNames = ep->createDevNames();
+
+ bool done;
+ bool result;
+ bool doPrinting;
+
+ PRINTPAGERANGE pageRange;
+ PRINTDLGEX pd;
+ memset(&pd, 0, sizeof(PRINTDLGEX));
+ pd.lStructSize = sizeof(PRINTDLGEX);
+ pd.lpPageRanges = &pageRange;
+ qt_win_setup_PRINTDLGEX(&pd, parent, q, this, tempDevNames);
+
+ do {
+ done = true;
+ doPrinting = false;
+ result = (PrintDlgEx(&pd) == S_OK);
+ if (result && (pd.dwResultAction == PD_RESULT_PRINT
+ || pd.dwResultAction == PD_RESULT_APPLY))
+ {
+ doPrinting = (pd.dwResultAction == PD_RESULT_PRINT);
+ if ((pd.Flags & PD_PAGENUMS)
+ && (pd.lpPageRanges[0].nFromPage > pd.lpPageRanges[0].nToPage))
+ {
+ pd.lpPageRanges[0].nFromPage = 1;
+ pd.lpPageRanges[0].nToPage = 1;
+ done = false;
+ }
+ if (pd.hDC == 0)
+ result = false;
+ }
+
+ if (!done) {
+ QMessageBox::warning(0, QPrintDialog::tr("Print"),
+ QPrintDialog::tr("The 'From' value cannot be greater than the 'To' value."),
+ QPrintDialog::tr("OK"));
+ }
+ } while (!done);
+
+ QApplicationPrivate::leaveModal(&modal_widget);
+
+ qt_win_eatMouseMove();
+
+ // write values back...
+ if (result && (pd.dwResultAction == PD_RESULT_PRINT
+ || pd.dwResultAction == PD_RESULT_APPLY))
+ {
+ qt_win_read_back_PRINTDLGEX(&pd, q, this);
+ // update printer validity
+ printer->d_func()->validPrinter = !ep->name.isEmpty();
+ }
+
+ // Cleanup...
+ GlobalFree(tempDevNames);
+
+ q->done(result && doPrinting);
+
+ return result && doPrinting;
+}
+
+void QPrintDialog::setVisible(bool visible)
+{
+ Q_D(QPrintDialog);
+
+ // its always modal, so we cannot hide a native print dialog
+ if (!visible)
+ return;
+
+ if (!warnIfNotNative(d->printer))
+ return;
+
+ (void)d->openWindowsPrintDialogModally();
+ return;
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qprintdialog.cpp"
+
+#endif // QT_NO_PRINTDIALOG
diff --git a/src/printsupport/dialogs/qprintpreviewdialog.cpp b/src/printsupport/dialogs/qprintpreviewdialog.cpp
new file mode 100644
index 0000000000..55ebc194f2
--- /dev/null
+++ b/src/printsupport/dialogs/qprintpreviewdialog.cpp
@@ -0,0 +1,803 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qprintpreviewdialog.h"
+#include "qprintpreviewwidget.h"
+#include <private/qprinter_p.h>
+#include "private/qdialog_p.h"
+#include "qprintdialog.h"
+
+#include <QtWidgets/qaction.h>
+#include <QtWidgets/qboxlayout.h>
+#include <QtWidgets/qcombobox.h>
+#include <QtWidgets/qlabel.h>
+#include <QtWidgets/qlineedit.h>
+#include <QtPrintSupport/qpagesetupdialog.h>
+#include <QtPrintSupport/qprinter.h>
+#include <QtWidgets/qstyle.h>
+#include <QtWidgets/qtoolbutton.h>
+#include <QtGui/qvalidator.h>
+#include <QtWidgets/qfiledialog.h>
+#include <QtWidgets/qmainwindow.h>
+#include <QtWidgets/qtoolbar.h>
+#include <QtWidgets/qformlayout.h>
+#include <QtCore/QCoreApplication>
+
+#include <math.h>
+
+#ifndef QT_NO_PRINTPREVIEWDIALOG
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+class QPrintPreviewMainWindow : public QMainWindow
+{
+public:
+ QPrintPreviewMainWindow(QWidget *parent) : QMainWindow(parent) {}
+ QMenu *createPopupMenu() { return 0; }
+};
+
+class ZoomFactorValidator : public QDoubleValidator
+{
+public:
+ ZoomFactorValidator(QObject* parent)
+ : QDoubleValidator(parent) {}
+ ZoomFactorValidator(qreal bottom, qreal top, int decimals, QObject *parent)
+ : QDoubleValidator(bottom, top, decimals, parent) {}
+
+ State validate(QString &input, int &pos) const
+ {
+ bool replacePercent = false;
+ if (input.endsWith(QLatin1Char('%'))) {
+ input = input.left(input.length() - 1);
+ replacePercent = true;
+ }
+ State state = QDoubleValidator::validate(input, pos);
+ if (replacePercent)
+ input += QLatin1Char('%');
+ const int num_size = 4;
+ if (state == Intermediate) {
+ int i = input.indexOf(QLocale::system().decimalPoint());
+ if ((i == -1 && input.size() > num_size)
+ || (i != -1 && i > num_size))
+ return Invalid;
+ }
+ return state;
+ }
+};
+
+class LineEdit : public QLineEdit
+{
+ Q_OBJECT
+public:
+ LineEdit(QWidget* parent = 0)
+ : QLineEdit(parent)
+ {
+ setContextMenuPolicy(Qt::NoContextMenu);
+ connect(this, SIGNAL(returnPressed()), SLOT(handleReturnPressed()));
+ }
+
+protected:
+ void focusInEvent(QFocusEvent *e)
+ {
+ origText = text();
+ QLineEdit::focusInEvent(e);
+ }
+
+ void focusOutEvent(QFocusEvent *e)
+ {
+ if (isModified() && !hasAcceptableInput())
+ setText(origText);
+ QLineEdit::focusOutEvent(e);
+ }
+
+private slots:
+ void handleReturnPressed()
+ {
+ origText = text();
+ }
+
+private:
+ QString origText;
+};
+} // anonymous namespace
+
+class QPrintPreviewDialogPrivate : public QDialogPrivate
+{
+ Q_DECLARE_PUBLIC(QPrintPreviewDialog)
+public:
+ QPrintPreviewDialogPrivate()
+ : printDialog(0), ownPrinter(false),
+ initialized(false) {}
+
+ // private slots
+ void _q_fit(QAction *action);
+ void _q_zoomIn();
+ void _q_zoomOut();
+ void _q_navigate(QAction *action);
+ void _q_setMode(QAction *action);
+ void _q_pageNumEdited();
+ void _q_print();
+ void _q_pageSetup();
+ void _q_previewChanged();
+ void _q_zoomFactorChanged();
+
+ void init(QPrinter *printer = 0);
+ void populateScene();
+ void layoutPages();
+ void setupActions();
+ void updateNavActions();
+ void setFitting(bool on);
+ bool isFitting();
+ void updatePageNumLabel();
+ void updateZoomFactor();
+
+ QPrintDialog *printDialog;
+ QPrintPreviewWidget *preview;
+ QPrinter *printer;
+ bool ownPrinter;
+ bool initialized;
+
+ // widgets:
+ QLineEdit *pageNumEdit;
+ QLabel *pageNumLabel;
+ QComboBox *zoomFactor;
+
+ // actions:
+ QActionGroup* navGroup;
+ QAction *nextPageAction;
+ QAction *prevPageAction;
+ QAction *firstPageAction;
+ QAction *lastPageAction;
+
+ QActionGroup* fitGroup;
+ QAction *fitWidthAction;
+ QAction *fitPageAction;
+
+ QActionGroup* zoomGroup;
+ QAction *zoomInAction;
+ QAction *zoomOutAction;
+
+ QActionGroup* orientationGroup;
+ QAction *portraitAction;
+ QAction *landscapeAction;
+
+ QActionGroup* modeGroup;
+ QAction *singleModeAction;
+ QAction *facingModeAction;
+ QAction *overviewModeAction;
+
+ QActionGroup *printerGroup;
+ QAction *printAction;
+ QAction *pageSetupAction;
+#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
+ QAction *closeAction;
+#endif
+
+ QPointer<QObject> receiverToDisconnectOnClose;
+ QByteArray memberToDisconnectOnClose;
+};
+
+void QPrintPreviewDialogPrivate::init(QPrinter *_printer)
+{
+ Q_Q(QPrintPreviewDialog);
+
+ if (_printer) {
+ preview = new QPrintPreviewWidget(_printer, q);
+ printer = _printer;
+ } else {
+ ownPrinter = true;
+ printer = new QPrinter;
+ preview = new QPrintPreviewWidget(printer, q);
+ }
+ QObject::connect(preview, SIGNAL(paintRequested(QPrinter*)), q, SIGNAL(paintRequested(QPrinter*)));
+ QObject::connect(preview, SIGNAL(previewChanged()), q, SLOT(_q_previewChanged()));
+ setupActions();
+
+ pageNumEdit = new LineEdit;
+ pageNumEdit->setAlignment(Qt::AlignRight);
+ pageNumEdit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
+ pageNumLabel = new QLabel;
+ QObject::connect(pageNumEdit, SIGNAL(editingFinished()), q, SLOT(_q_pageNumEdited()));
+
+ zoomFactor = new QComboBox;
+ zoomFactor->setEditable(true);
+ zoomFactor->setMinimumContentsLength(7);
+ zoomFactor->setInsertPolicy(QComboBox::NoInsert);
+ LineEdit *zoomEditor = new LineEdit;
+ zoomEditor->setValidator(new ZoomFactorValidator(1, 1000, 1, zoomEditor));
+ zoomFactor->setLineEdit(zoomEditor);
+ static const short factorsX2[] = { 25, 50, 100, 200, 250, 300, 400, 800, 1600 };
+ for (int i = 0; i < int(sizeof(factorsX2) / sizeof(factorsX2[0])); ++i)
+ zoomFactor->addItem(QPrintPreviewDialog::tr("%1%").arg(factorsX2[i] / 2.0));
+ QObject::connect(zoomFactor->lineEdit(), SIGNAL(editingFinished()),
+ q, SLOT(_q_zoomFactorChanged()));
+ QObject::connect(zoomFactor, SIGNAL(currentIndexChanged(int)),
+ q, SLOT(_q_zoomFactorChanged()));
+
+ QPrintPreviewMainWindow *mw = new QPrintPreviewMainWindow(q);
+ QToolBar *toolbar = new QToolBar(mw);
+ toolbar->addAction(fitWidthAction);
+ toolbar->addAction(fitPageAction);
+ toolbar->addSeparator();
+ toolbar->addWidget(zoomFactor);
+ toolbar->addAction(zoomOutAction);
+ toolbar->addAction(zoomInAction);
+ toolbar->addSeparator();
+ toolbar->addAction(portraitAction);
+ toolbar->addAction(landscapeAction);
+ toolbar->addSeparator();
+ toolbar->addAction(firstPageAction);
+ toolbar->addAction(prevPageAction);
+
+ // this is to ensure the label text and the editor text are
+ // aligned in all styles - the extra QVBoxLayout is a workaround
+ // for bug in QFormLayout
+ QWidget *pageEdit = new QWidget(toolbar);
+ QVBoxLayout *vboxLayout = new QVBoxLayout;
+ vboxLayout->setContentsMargins(0, 0, 0, 0);
+#ifdef Q_WS_MAC
+ // We query the widgets about their size and then we fix the size.
+ // This should do the trick for the laying out part...
+ QSize pageNumEditSize, pageNumLabelSize;
+ pageNumEditSize = pageNumEdit->minimumSizeHint();
+ pageNumLabelSize = pageNumLabel->minimumSizeHint();
+ pageNumEdit->resize(pageNumEditSize);
+ pageNumLabel->resize(pageNumLabelSize);
+#endif
+ QFormLayout *formLayout = new QFormLayout;
+#ifdef Q_WS_MAC
+ // We have to change the growth policy in Mac.
+ formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
+#endif
+ formLayout->setWidget(0, QFormLayout::LabelRole, pageNumEdit);
+ formLayout->setWidget(0, QFormLayout::FieldRole, pageNumLabel);
+ vboxLayout->addLayout(formLayout);
+ vboxLayout->setAlignment(Qt::AlignVCenter);
+ pageEdit->setLayout(vboxLayout);
+ toolbar->addWidget(pageEdit);
+
+ toolbar->addAction(nextPageAction);
+ toolbar->addAction(lastPageAction);
+ toolbar->addSeparator();
+ toolbar->addAction(singleModeAction);
+ toolbar->addAction(facingModeAction);
+ toolbar->addAction(overviewModeAction);
+ toolbar->addSeparator();
+ toolbar->addAction(pageSetupAction);
+ toolbar->addAction(printAction);
+#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
+ toolbar->addAction(closeAction);
+#endif
+
+ // Cannot use the actions' triggered signal here, since it doesn't autorepeat
+ QToolButton *zoomInButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomInAction));
+ QToolButton *zoomOutButton = static_cast<QToolButton *>(toolbar->widgetForAction(zoomOutAction));
+ zoomInButton->setAutoRepeat(true);
+ zoomInButton->setAutoRepeatInterval(200);
+ zoomInButton->setAutoRepeatDelay(200);
+ zoomOutButton->setAutoRepeat(true);
+ zoomOutButton->setAutoRepeatInterval(200);
+ zoomOutButton->setAutoRepeatDelay(200);
+ QObject::connect(zoomInButton, SIGNAL(clicked()), q, SLOT(_q_zoomIn()));
+ QObject::connect(zoomOutButton, SIGNAL(clicked()), q, SLOT(_q_zoomOut()));
+
+ mw->addToolBar(toolbar);
+ mw->setCentralWidget(preview);
+ // QMainWindows are always created as top levels, force it to be a
+ // plain widget
+ mw->setParent(q, Qt::Widget);
+
+ QVBoxLayout *topLayout = new QVBoxLayout;
+ topLayout->addWidget(mw);
+ topLayout->setMargin(0);
+ q->setLayout(topLayout);
+
+ QString caption = QCoreApplication::translate("QPrintPreviewDialog", "Print Preview");
+ if (!printer->docName().isEmpty())
+ caption += QString::fromLatin1(": ") + printer->docName();
+ q->setWindowTitle(caption);
+
+ if (!printer->isValid()
+#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
+ || printer->outputFormat() != QPrinter::NativeFormat
+#endif
+ )
+ pageSetupAction->setEnabled(false);
+ preview->setFocus();
+}
+
+static inline void qt_setupActionIcon(QAction *action, const QLatin1String &name)
+{
+ QLatin1String imagePrefix(":/trolltech/dialogs/qprintpreviewdialog/images/");
+ QIcon icon;
+ icon.addFile(imagePrefix + name + QLatin1String("-24.png"), QSize(24, 24));
+ icon.addFile(imagePrefix + name + QLatin1String("-32.png"), QSize(32, 32));
+ action->setIcon(icon);
+}
+
+void QPrintPreviewDialogPrivate::setupActions()
+{
+ Q_Q(QPrintPreviewDialog);
+
+ // Navigation
+ navGroup = new QActionGroup(q);
+ navGroup->setExclusive(false);
+ nextPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Next page"));
+ prevPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Previous page"));
+ firstPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "First page"));
+ lastPageAction = navGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Last page"));
+ qt_setupActionIcon(nextPageAction, QLatin1String("go-next"));
+ qt_setupActionIcon(prevPageAction, QLatin1String("go-previous"));
+ qt_setupActionIcon(firstPageAction, QLatin1String("go-first"));
+ qt_setupActionIcon(lastPageAction, QLatin1String("go-last"));
+ QObject::connect(navGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_navigate(QAction*)));
+
+
+ fitGroup = new QActionGroup(q);
+ fitWidthAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit width"));
+ fitPageAction = fitGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Fit page"));
+ fitWidthAction->setObjectName(QLatin1String("fitWidthAction"));
+ fitPageAction->setObjectName(QLatin1String("fitPageAction"));
+ fitWidthAction->setCheckable(true);
+ fitPageAction->setCheckable(true);
+ qt_setupActionIcon(fitWidthAction, QLatin1String("fit-width"));
+ qt_setupActionIcon(fitPageAction, QLatin1String("fit-page"));
+ QObject::connect(fitGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_fit(QAction*)));
+
+ // Zoom
+ zoomGroup = new QActionGroup(q);
+ zoomInAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom in"));
+ zoomOutAction = zoomGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Zoom out"));
+ qt_setupActionIcon(zoomInAction, QLatin1String("zoom-in"));
+ qt_setupActionIcon(zoomOutAction, QLatin1String("zoom-out"));
+
+ // Portrait/Landscape
+ orientationGroup = new QActionGroup(q);
+ portraitAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Portrait"));
+ landscapeAction = orientationGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Landscape"));
+ portraitAction->setCheckable(true);
+ landscapeAction->setCheckable(true);
+ qt_setupActionIcon(portraitAction, QLatin1String("layout-portrait"));
+ qt_setupActionIcon(landscapeAction, QLatin1String("layout-landscape"));
+ QObject::connect(portraitAction, SIGNAL(triggered(bool)), preview, SLOT(setPortraitOrientation()));
+ QObject::connect(landscapeAction, SIGNAL(triggered(bool)), preview, SLOT(setLandscapeOrientation()));
+
+ // Display mode
+ modeGroup = new QActionGroup(q);
+ singleModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show single page"));
+ facingModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show facing pages"));
+ overviewModeAction = modeGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Show overview of all pages"));
+ qt_setupActionIcon(singleModeAction, QLatin1String("view-page-one"));
+ qt_setupActionIcon(facingModeAction, QLatin1String("view-page-sided"));
+ qt_setupActionIcon(overviewModeAction, QLatin1String("view-page-multi"));
+ singleModeAction->setObjectName(QLatin1String("singleModeAction"));
+ facingModeAction->setObjectName(QLatin1String("facingModeAction"));
+ overviewModeAction->setObjectName(QLatin1String("overviewModeAction"));
+
+ singleModeAction->setCheckable(true);
+ facingModeAction->setCheckable(true);
+ overviewModeAction->setCheckable(true);
+ QObject::connect(modeGroup, SIGNAL(triggered(QAction*)), q, SLOT(_q_setMode(QAction*)));
+
+ // Print
+ printerGroup = new QActionGroup(q);
+ printAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Print"));
+ pageSetupAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Page setup"));
+ qt_setupActionIcon(printAction, QLatin1String("print"));
+ qt_setupActionIcon(pageSetupAction, QLatin1String("page-setup"));
+ QObject::connect(printAction, SIGNAL(triggered(bool)), q, SLOT(_q_print()));
+ QObject::connect(pageSetupAction, SIGNAL(triggered(bool)), q, SLOT(_q_pageSetup()));
+#if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
+ closeAction = printerGroup->addAction(QCoreApplication::translate("QPrintPreviewDialog", "Close"));
+ QObject::connect(closeAction, SIGNAL(triggered(bool)), q, SLOT(reject()));
+#endif
+
+ // Initial state:
+ fitPageAction->setChecked(true);
+ singleModeAction->setChecked(true);
+ if (preview->orientation() == QPrinter::Portrait)
+ portraitAction->setChecked(true);
+ else
+ landscapeAction->setChecked(true);
+}
+
+
+bool QPrintPreviewDialogPrivate::isFitting()
+{
+ return (fitGroup->isExclusive()
+ && (fitWidthAction->isChecked() || fitPageAction->isChecked()));
+}
+
+
+void QPrintPreviewDialogPrivate::setFitting(bool on)
+{
+ if (isFitting() == on)
+ return;
+ fitGroup->setExclusive(on);
+ if (on) {
+ QAction* action = fitWidthAction->isChecked() ? fitWidthAction : fitPageAction;
+ action->setChecked(true);
+ if (fitGroup->checkedAction() != action) {
+ // work around exclusitivity problem
+ fitGroup->removeAction(action);
+ fitGroup->addAction(action);
+ }
+ } else {
+ fitWidthAction->setChecked(false);
+ fitPageAction->setChecked(false);
+ }
+}
+
+void QPrintPreviewDialogPrivate::updateNavActions()
+{
+ int curPage = preview->currentPage();
+ int numPages = preview->pageCount();
+ nextPageAction->setEnabled(curPage < numPages);
+ prevPageAction->setEnabled(curPage > 1);
+ firstPageAction->setEnabled(curPage > 1);
+ lastPageAction->setEnabled(curPage < numPages);
+ pageNumEdit->setText(QString::number(curPage));
+}
+
+void QPrintPreviewDialogPrivate::updatePageNumLabel()
+{
+ Q_Q(QPrintPreviewDialog);
+
+ int numPages = preview->pageCount();
+ int maxChars = QString::number(numPages).length();
+ pageNumLabel->setText(QString::fromLatin1("/ %1").arg(numPages));
+ int cyphersWidth = q->fontMetrics().width(QString().fill(QLatin1Char('8'), maxChars));
+ int maxWidth = pageNumEdit->minimumSizeHint().width() + cyphersWidth;
+ pageNumEdit->setMinimumWidth(maxWidth);
+ pageNumEdit->setMaximumWidth(maxWidth);
+ pageNumEdit->setValidator(new QIntValidator(1, numPages, pageNumEdit));
+ // any old one will be deleted later along with its parent pageNumEdit
+}
+
+void QPrintPreviewDialogPrivate::updateZoomFactor()
+{
+ zoomFactor->lineEdit()->setText(QString().sprintf("%.1f%%", preview->zoomFactor()*100));
+}
+
+void QPrintPreviewDialogPrivate::_q_fit(QAction* action)
+{
+ setFitting(true);
+ if (action == fitPageAction)
+ preview->fitInView();
+ else
+ preview->fitToWidth();
+}
+
+void QPrintPreviewDialogPrivate::_q_zoomIn()
+{
+ setFitting(false);
+ preview->zoomIn();
+ updateZoomFactor();
+}
+
+void QPrintPreviewDialogPrivate::_q_zoomOut()
+{
+ setFitting(false);
+ preview->zoomOut();
+ updateZoomFactor();
+}
+
+void QPrintPreviewDialogPrivate::_q_pageNumEdited()
+{
+ bool ok = false;
+ int res = pageNumEdit->text().toInt(&ok);
+ if (ok)
+ preview->setCurrentPage(res);
+}
+
+void QPrintPreviewDialogPrivate::_q_navigate(QAction* action)
+{
+ int curPage = preview->currentPage();
+ if (action == prevPageAction)
+ preview->setCurrentPage(curPage - 1);
+ else if (action == nextPageAction)
+ preview->setCurrentPage(curPage + 1);
+ else if (action == firstPageAction)
+ preview->setCurrentPage(1);
+ else if (action == lastPageAction)
+ preview->setCurrentPage(preview->pageCount());
+ updateNavActions();
+}
+
+void QPrintPreviewDialogPrivate::_q_setMode(QAction* action)
+{
+ if (action == overviewModeAction) {
+ preview->setViewMode(QPrintPreviewWidget::AllPagesView);
+ setFitting(false);
+ fitGroup->setEnabled(false);
+ navGroup->setEnabled(false);
+ pageNumEdit->setEnabled(false);
+ pageNumLabel->setEnabled(false);
+ } else if (action == facingModeAction) {
+ preview->setViewMode(QPrintPreviewWidget::FacingPagesView);
+ } else {
+ preview->setViewMode(QPrintPreviewWidget::SinglePageView);
+ }
+ if (action == facingModeAction || action == singleModeAction) {
+ fitGroup->setEnabled(true);
+ navGroup->setEnabled(true);
+ pageNumEdit->setEnabled(true);
+ pageNumLabel->setEnabled(true);
+ setFitting(true);
+ }
+}
+
+void QPrintPreviewDialogPrivate::_q_print()
+{
+ Q_Q(QPrintPreviewDialog);
+
+#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
+ if (printer->outputFormat() != QPrinter::NativeFormat) {
+ QString title;
+ QString suffix;
+ if (printer->outputFormat() == QPrinter::PdfFormat) {
+ title = QCoreApplication::translate("QPrintPreviewDialog", "Export to PDF");
+ suffix = QLatin1String(".pdf");
+ } else {
+ title = QCoreApplication::translate("QPrintPreviewDialog", "Export to PostScript");
+ suffix = QLatin1String(".ps");
+ }
+ QString fileName = QFileDialog::getSaveFileName(q, title, printer->outputFileName(),
+ QLatin1Char('*') + suffix);
+ if (!fileName.isEmpty()) {
+ if (QFileInfo(fileName).suffix().isEmpty())
+ fileName.append(suffix);
+ printer->setOutputFileName(fileName);
+ }
+ if (!printer->outputFileName().isEmpty())
+ preview->print();
+ q->accept();
+ return;
+ }
+#endif
+
+ if (!printDialog)
+ printDialog = new QPrintDialog(printer, q);
+ if (printDialog->exec() == QDialog::Accepted) {
+ preview->print();
+ q->accept();
+ }
+}
+
+void QPrintPreviewDialogPrivate::_q_pageSetup()
+{
+ Q_Q(QPrintPreviewDialog);
+
+ QPageSetupDialog pageSetup(printer, q);
+ if (pageSetup.exec() == QDialog::Accepted) {
+ // update possible orientation changes
+ if (preview->orientation() == QPrinter::Portrait) {
+ portraitAction->setChecked(true);
+ preview->setPortraitOrientation();
+ }else {
+ landscapeAction->setChecked(true);
+ preview->setLandscapeOrientation();
+ }
+ }
+}
+
+void QPrintPreviewDialogPrivate::_q_previewChanged()
+{
+ updateNavActions();
+ updatePageNumLabel();
+ updateZoomFactor();
+}
+
+void QPrintPreviewDialogPrivate::_q_zoomFactorChanged()
+{
+ QString text = zoomFactor->lineEdit()->text();
+ bool ok;
+ qreal factor = text.remove(QLatin1Char('%')).toFloat(&ok);
+ factor = qMax(qreal(1.0), qMin(qreal(1000.0), factor));
+ if (ok) {
+ preview->setZoomFactor(factor/100.0);
+ zoomFactor->setEditText(QString::fromLatin1("%1%").arg(factor));
+ setFitting(false);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+/*!
+ \class QPrintPreviewDialog
+ \since 4.4
+
+ \brief The QPrintPreviewDialog class provides a dialog for
+ previewing and configuring page layouts for printer output.
+
+ \ingroup standard-dialogs
+ \ingroup printing
+
+ Using QPrintPreviewDialog in your existing application is
+ straightforward:
+
+ \list 1
+ \o Create the QPrintPreviewDialog.
+
+ You can construct a QPrintPreviewDialog with an existing QPrinter
+ object, or you can have QPrintPreviewDialog create one for you,
+ which will be the system default printer.
+
+ \o Connect the paintRequested() signal to a slot.
+
+ When the dialog needs to generate a set of preview pages, the
+ paintRequested() signal will be emitted. You can use the exact
+ same code for the actual printing as for having the preview
+ generated, including calling QPrinter::newPage() to start a new
+ page in the preview. Connect a slot to the paintRequested()
+ signal, where you draw onto the QPrinter object that is passed
+ into the slot.
+
+ \o Call exec().
+
+ Call QPrintPreviewDialog::exec() to show the preview dialog.
+ \endlist
+
+ In Symbian, there is no support for printing. Hence, this dialog should not
+ be used in Symbian.
+
+ \sa QPrinter, QPrintDialog, QPageSetupDialog, QPrintPreviewWidget
+*/
+
+/*!
+ Constructs a QPrintPreviewDialog based on \a printer and with \a
+ parent as the parent widget. The widget flags \a flags are passed on
+ to the QWidget constructor.
+
+ \sa QWidget::setWindowFlags()
+*/
+QPrintPreviewDialog::QPrintPreviewDialog(QPrinter* printer, QWidget *parent, Qt::WindowFlags flags)
+ : QDialog(*new QPrintPreviewDialogPrivate, parent, flags)
+{
+ Q_D(QPrintPreviewDialog);
+ d->init(printer);
+}
+
+/*!
+ \overload
+ \fn QPrintPreviewDialog::QPrintPreviewDialog(QWidget *parent, Qt::WindowFlags flags)
+
+ This will create an internal QPrinter object, which will use the
+ system default printer.
+*/
+QPrintPreviewDialog::QPrintPreviewDialog(QWidget *parent, Qt::WindowFlags f)
+ : QDialog(*new QPrintPreviewDialogPrivate, parent, f)
+{
+ Q_D(QPrintPreviewDialog);
+ d->init();
+}
+
+/*!
+ Destroys the QPrintPreviewDialog.
+*/
+QPrintPreviewDialog::~QPrintPreviewDialog()
+{
+ Q_D(QPrintPreviewDialog);
+ if (d->ownPrinter)
+ delete d->printer;
+ delete d->printDialog;
+}
+
+/*!
+ \reimp
+*/
+void QPrintPreviewDialog::setVisible(bool visible)
+{
+ Q_D(QPrintPreviewDialog);
+ // this will make the dialog get a decent default size
+ if (visible && !d->initialized) {
+ d->preview->updatePreview();
+ d->initialized = true;
+ }
+ QDialog::setVisible(visible);
+}
+
+/*!
+ \reimp
+*/
+void QPrintPreviewDialog::done(int result)
+{
+ Q_D(QPrintPreviewDialog);
+ QDialog::done(result);
+ if (d->receiverToDisconnectOnClose) {
+ disconnect(this, SIGNAL(finished(int)),
+ d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose);
+ d->receiverToDisconnectOnClose = 0;
+ }
+ d->memberToDisconnectOnClose.clear();
+}
+
+/*!
+ \overload
+ \since 4.5
+
+ Opens the dialog and connects its finished(int) signal to the slot specified
+ by \a receiver and \a member.
+
+ The signal will be disconnected from the slot when the dialog is closed.
+*/
+void QPrintPreviewDialog::open(QObject *receiver, const char *member)
+{
+ Q_D(QPrintPreviewDialog);
+ // the int parameter isn't very useful here; we could just as well connect
+ // to reject(), but this feels less robust somehow
+ connect(this, SIGNAL(finished(int)), receiver, member);
+ d->receiverToDisconnectOnClose = receiver;
+ d->memberToDisconnectOnClose = member;
+ QDialog::open();
+}
+
+/*!
+ Returns a pointer to the QPrinter object this dialog is currently
+ operating on.
+*/
+QPrinter *QPrintPreviewDialog::printer()
+{
+ Q_D(QPrintPreviewDialog);
+ return d->printer;
+}
+
+/*!
+ \fn void QPrintPreviewDialog::paintRequested(QPrinter *printer)
+
+ This signal is emitted when the QPrintPreviewDialog needs to generate
+ a set of preview pages.
+
+ The \a printer instance supplied is the paint device onto which you should
+ paint the contents of each page, using the QPrinter instance in the same way
+ as you would when printing directly.
+*/
+
+
+QT_END_NAMESPACE
+
+#include "moc_qprintpreviewdialog.cpp"
+#include "qprintpreviewdialog.moc"
+
+#endif // QT_NO_PRINTPREVIEWDIALOG
+
+
diff --git a/src/printsupport/dialogs/qprintpreviewdialog.h b/src/printsupport/dialogs/qprintpreviewdialog.h
new file mode 100644
index 0000000000..fa67f02b93
--- /dev/null
+++ b/src/printsupport/dialogs/qprintpreviewdialog.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTPREVIEWDIALOG_H
+#define QPRINTPREVIEWDIALOG_H
+
+#include <QtWidgets/qdialog.h>
+
+#ifndef QT_NO_PRINTPREVIEWDIALOG
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+class QGraphicsView;
+class QPrintPreviewDialogPrivate;
+class QPrinter;
+
+class Q_WIDGETS_EXPORT QPrintPreviewDialog : public QDialog
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QPrintPreviewDialog)
+
+public:
+ explicit QPrintPreviewDialog(QWidget *parent = 0, Qt::WindowFlags flags = 0);
+ explicit QPrintPreviewDialog(QPrinter *printer, QWidget *parent = 0, Qt::WindowFlags flags = 0);
+ ~QPrintPreviewDialog();
+
+#ifdef Q_NO_USING_KEYWORD
+#ifndef Q_QDOC
+ void open() { QDialog::open(); }
+#endif
+#else
+ using QDialog::open;
+#endif
+ void open(QObject *receiver, const char *member);
+
+ QPrinter *printer();
+
+ void setVisible(bool visible);
+ void done(int result);
+
+Q_SIGNALS:
+ void paintRequested(QPrinter *printer);
+
+private:
+ Q_PRIVATE_SLOT(d_func(), void _q_fit(QAction *action))
+ Q_PRIVATE_SLOT(d_func(), void _q_zoomIn())
+ Q_PRIVATE_SLOT(d_func(), void _q_zoomOut())
+ Q_PRIVATE_SLOT(d_func(), void _q_navigate(QAction *action))
+ Q_PRIVATE_SLOT(d_func(), void _q_setMode(QAction *action))
+ Q_PRIVATE_SLOT(d_func(), void _q_pageNumEdited())
+ Q_PRIVATE_SLOT(d_func(), void _q_print())
+ Q_PRIVATE_SLOT(d_func(), void _q_pageSetup())
+ Q_PRIVATE_SLOT(d_func(), void _q_previewChanged())
+ Q_PRIVATE_SLOT(d_func(), void _q_zoomFactorChanged())
+
+ void *dummy; // ### Qt 5 - remove me
+};
+
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QT_NO_PRINTPREVIEWDIALOG
+
+#endif // QPRINTPREVIEWDIALOG_H
diff --git a/src/printsupport/dialogs/qprintpropertieswidget.ui b/src/printsupport/dialogs/qprintpropertieswidget.ui
new file mode 100644
index 0000000000..26fa09599e
--- /dev/null
+++ b/src/printsupport/dialogs/qprintpropertieswidget.ui
@@ -0,0 +1,70 @@
+<ui version="4.0" >
+ <class>QPrintPropertiesWidget</class>
+ <widget class="QWidget" name="QPrintPropertiesWidget" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>396</width>
+ <height>288</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTabWidget" name="tabs" >
+ <property name="currentIndex" >
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tabPage" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>392</width>
+ <height>261</height>
+ </rect>
+ </property>
+ <attribute name="title" >
+ <string>Page</string>
+ </attribute>
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QPageSetupWidget" native="1" name="pageSetup" />
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="cupsPropertiesPage" >
+ <attribute name="title" >
+ <string>Advanced</string>
+ </attribute>
+ <layout class="QHBoxLayout" name="horizontalLayout_2" >
+ <item>
+ <widget class="QTreeView" name="treeView" >
+ <property name="alternatingRowColors" >
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>QPageSetupWidget</class>
+ <extends>QWidget</extends>
+ <header>qpagesetupdialog_unix_p.h</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/printsupport/dialogs/qprintsettingsoutput.ui b/src/printsupport/dialogs/qprintsettingsoutput.ui
new file mode 100644
index 0000000000..be916790fb
--- /dev/null
+++ b/src/printsupport/dialogs/qprintsettingsoutput.ui
@@ -0,0 +1,363 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QPrintSettingsOutput</class>
+ <widget class="QWidget" name="QPrintSettingsOutput">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>426</width>
+ <height>171</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QTabWidget" name="tabs">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="copiesTab">
+ <attribute name="title">
+ <string>Copies</string>
+ </attribute>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QGroupBox" name="gbPrintRange">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="title">
+ <string>Print range</string>
+ </property>
+ <layout class="QVBoxLayout" name="_3">
+ <property name="spacing">
+ <number>4</number>
+ </property>
+ <property name="margin">
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QRadioButton" name="printAll">
+ <property name="text">
+ <string>Print all</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="_4">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QRadioButton" name="printRange">
+ <property name="text">
+ <string>Pages from</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="from">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>999</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>to</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSpinBox" name="to">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>999</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>0</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="printCurrentPage">
+ <property name="text">
+ <string>Current Page</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="printSelection">
+ <property name="text">
+ <string>Selection</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>1</width>
+ <height>1</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Output Settings</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Copies:</string>
+ </property>
+ <property name="buddy">
+ <cstring>copies</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" colspan="2">
+ <widget class="QSpinBox" name="copies">
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>999</number>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="3">
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>91</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QCheckBox" name="collate">
+ <property name="text">
+ <string>Collate</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" rowspan="2" colspan="2">
+ <widget class="QLabel" name="outputIcon">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Ignored" vsizetype="Ignored">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" colspan="2">
+ <widget class="QCheckBox" name="reverse">
+ <property name="text">
+ <string>Reverse</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" colspan="4">
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>0</width>
+ <height>1</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="optionsTab">
+ <attribute name="title">
+ <string>Options</string>
+ </attribute>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="1">
+ <widget class="QGroupBox" name="colorMode">
+ <property name="title">
+ <string>Color Mode</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_4">
+ <item row="2" column="0">
+ <spacer name="verticalSpacer_6">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>1</width>
+ <height>0</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="0">
+ <widget class="QRadioButton" name="color">
+ <property name="text">
+ <string>Color</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" rowspan="3">
+ <widget class="QLabel" name="colorIcon"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QRadioButton" name="grayscale">
+ <property name="text">
+ <string>Grayscale</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QGroupBox" name="duplex">
+ <property name="title">
+ <string>Duplex Printing</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QRadioButton" name="noDuplex">
+ <property name="text">
+ <string>None</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="duplexLong">
+ <property name="text">
+ <string>Long side</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="duplexShort">
+ <property name="text">
+ <string>Short side</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_42">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>1</width>
+ <height>0</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>printRange</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>from</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>76</x>
+ <y>59</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>122</x>
+ <y>57</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>printRange</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>to</receiver>
+ <slot>setEnabled(bool)</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>69</x>
+ <y>67</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>215</x>
+ <y>67</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/src/printsupport/dialogs/qprintwidget.ui b/src/printsupport/dialogs/qprintwidget.ui
new file mode 100644
index 0000000000..8a4f3bde0a
--- /dev/null
+++ b/src/printsupport/dialogs/qprintwidget.ui
@@ -0,0 +1,116 @@
+<ui version="4.0" >
+ <class>QPrintWidget</class>
+ <widget class="QWidget" name="QPrintWidget" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>443</width>
+ <height>175</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>Form</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_2" >
+ <property name="margin" >
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QGroupBox" name="printerGroup" >
+ <property name="title" >
+ <string>Printer</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" >
+ <item row="0" column="0" >
+ <widget class="QLabel" name="label" >
+ <property name="text" >
+ <string>&amp;Name:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>printers</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1" >
+ <widget class="QComboBox" name="printers" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <horstretch>3</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2" >
+ <widget class="QPushButton" name="properties" >
+ <property name="sizePolicy" >
+ <sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
+ <horstretch>1</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text" >
+ <string>P&amp;roperties</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_2" >
+ <property name="text" >
+ <string>Location:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QLabel" name="location" />
+ </item>
+ <item row="1" column="2" >
+ <widget class="QCheckBox" name="preview" >
+ <property name="text" >
+ <string>Preview</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0" >
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>Type:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1" >
+ <widget class="QLabel" name="type" />
+ </item>
+ <item row="3" column="0" >
+ <widget class="QLabel" name="lOutput" >
+ <property name="text" >
+ <string>Output &amp;file:</string>
+ </property>
+ <property name="buddy" >
+ <cstring>filename</cstring>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1" colspan="2" >
+ <layout class="QHBoxLayout" name="horizontalLayout" >
+ <item>
+ <widget class="QLineEdit" name="filename" />
+ </item>
+ <item>
+ <widget class="QToolButton" name="fileBrowser" >
+ <property name="text" >
+ <string>...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/printsupport/kernel/kernel.pri b/src/printsupport/kernel/kernel.pri
new file mode 100644
index 0000000000..3868d9e212
--- /dev/null
+++ b/src/printsupport/kernel/kernel.pri
@@ -0,0 +1,34 @@
+HEADERS += \
+ $$PWD/qpaintengine_alpha_p.h \
+ $$PWD/qpaintengine_preview_p.h \
+ $$PWD/qprintengine.h \
+ $$PWD/qprinter.h \
+ $$PWD/qprinter_p.h \
+ $$PWD/qprinterinfo.h \
+ $$PWD/qprinterinfo_p.h \
+ $$PWD/qplatformprintplugin_qpa.h \
+ $$PWD/qplatformprintersupport_qpa.h
+
+SOURCES += \
+ $$PWD/qpaintengine_alpha.cpp \
+ $$PWD/qpaintengine_preview.cpp \
+ $$PWD/qprintengine_pdf.cpp \
+ $$PWD/qprinter.cpp \
+ $$PWD/qprinterinfo.cpp \
+ $$PWD/qplatformprintplugin.cpp \
+ $$PWD/qplatformprintersupport_qpa.cpp
+
+unix:!symbian {
+ HEADERS += \
+ $$PWD/qprinterinfo_unix_p.h
+ SOURCES += \
+ $$PWD/qprinterinfo_unix.cpp
+}
+
+
+x11|qpa:!win32 {
+ SOURCES += $$PWD/qcups.cpp
+ HEADERS += $$PWD/qcups_p.h
+} else {
+ DEFINES += QT_NO_CUPS QT_NO_LPR
+}
diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp
new file mode 100644
index 0000000000..76050d9d71
--- /dev/null
+++ b/src/printsupport/kernel/qcups.cpp
@@ -0,0 +1,446 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qdebug.h>
+#include "qcups_p.h"
+#include "qprinterinfo_unix_p.h"
+
+#ifndef QT_NO_CUPS
+
+#ifndef QT_LINUXBASE // LSB merges everything into cups.h
+# include <cups/language.h>
+#endif
+#include <qtextcodec.h>
+
+QT_BEGIN_NAMESPACE
+
+typedef int (*CupsGetDests)(cups_dest_t **dests);
+typedef void (*CupsFreeDests)(int num_dests, cups_dest_t *dests);
+typedef const char* (*CupsGetPPD)(const char *printer);
+typedef int (*CupsMarkOptions)(ppd_file_t *ppd, int num_options, cups_option_t *options);
+typedef ppd_file_t* (*PPDOpenFile)(const char *filename);
+typedef void (*PPDMarkDefaults)(ppd_file_t *ppd);
+typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option);
+typedef void (*PPDClose)(ppd_file_t *ppd);
+typedef int (*PPDMarkOption)(ppd_file_t *ppd, const char *keyword, const char *option);
+typedef void (*CupsFreeOptions)(int num_options, cups_option_t *options);
+typedef void (*CupsSetDests)(int num_dests, cups_dest_t *dests);
+typedef cups_lang_t* (*CupsLangGet)(const char *language);
+typedef const char* (*CupsLangEncoding)(cups_lang_t *language);
+typedef int (*CupsAddOption)(const char *name, const char *value, int num_options, cups_option_t **options);
+typedef int (*CupsTempFd)(char *name, int len);
+typedef int (*CupsPrintFile)(const char * name, const char * filename, const char * title, int num_options, cups_option_t * options);
+
+static bool cupsLoaded = false;
+static int qt_cups_num_printers = 0;
+static CupsGetDests _cupsGetDests = 0;
+static CupsFreeDests _cupsFreeDests = 0;
+static CupsGetPPD _cupsGetPPD = 0;
+static PPDOpenFile _ppdOpenFile = 0;
+static PPDMarkDefaults _ppdMarkDefaults = 0;
+static PPDClose _ppdClose = 0;
+static CupsMarkOptions _cupsMarkOptions = 0;
+static PPDMarkOption _ppdMarkOption = 0;
+static CupsFreeOptions _cupsFreeOptions = 0;
+static CupsSetDests _cupsSetDests = 0;
+static CupsLangGet _cupsLangGet = 0;
+static CupsLangEncoding _cupsLangEncoding = 0;
+static CupsAddOption _cupsAddOption = 0;
+static CupsTempFd _cupsTempFd = 0;
+static CupsPrintFile _cupsPrintFile = 0;
+
+static void resolveCups()
+{
+ QLibrary cupsLib(QLatin1String("cups"), 2);
+ if(cupsLib.load()) {
+ _cupsGetDests = (CupsGetDests) cupsLib.resolve("cupsGetDests");
+ _cupsFreeDests = (CupsFreeDests) cupsLib.resolve("cupsFreeDests");
+ _cupsGetPPD = (CupsGetPPD) cupsLib.resolve("cupsGetPPD");
+ _cupsLangGet = (CupsLangGet) cupsLib.resolve("cupsLangGet");
+ _cupsLangEncoding = (CupsLangEncoding) cupsLib.resolve("cupsLangEncoding");
+ _ppdOpenFile = (PPDOpenFile) cupsLib.resolve("ppdOpenFile");
+ _ppdMarkDefaults = (PPDMarkDefaults) cupsLib.resolve("ppdMarkDefaults");
+ _ppdClose = (PPDClose) cupsLib.resolve("ppdClose");
+ _cupsMarkOptions = (CupsMarkOptions) cupsLib.resolve("cupsMarkOptions");
+ _ppdMarkOption = (PPDMarkOption) cupsLib.resolve("ppdMarkOption");
+ _cupsFreeOptions = (CupsFreeOptions) cupsLib.resolve("cupsFreeOptions");
+ _cupsSetDests = (CupsSetDests) cupsLib.resolve("cupsSetDests");
+ _cupsAddOption = (CupsAddOption) cupsLib.resolve("cupsAddOption");
+ _cupsTempFd = (CupsTempFd) cupsLib.resolve("cupsTempFd");
+ _cupsPrintFile = (CupsPrintFile) cupsLib.resolve("cupsPrintFile");
+
+ if (_cupsGetDests && _cupsFreeDests) {
+ cups_dest_t *printers;
+ int num_printers = _cupsGetDests(&printers);
+ if (num_printers)
+ _cupsFreeDests(num_printers, printers);
+ qt_cups_num_printers = num_printers;
+ }
+ }
+ cupsLoaded = true;
+}
+
+// ================ CUPS Support class ========================
+
+QCUPSSupport::QCUPSSupport()
+ :
+ prnCount(0),
+ printers(0),
+ page_sizes(0),
+ currPrinterIndex(0),
+ currPPD(0)
+{
+ if (!cupsLoaded)
+ resolveCups();
+
+ // getting all available printers
+ if (!isAvailable())
+ return;
+
+ prnCount = _cupsGetDests(&printers);
+
+ for (int i = 0; i < prnCount; ++i) {
+ if (printers[i].is_default) {
+ currPrinterIndex = i;
+ setCurrentPrinter(i);
+ break;
+ }
+ }
+
+#ifndef QT_NO_TEXTCODEC
+ cups_lang_t *cupsLang = _cupsLangGet(0);
+ codec = QTextCodec::codecForName(_cupsLangEncoding(cupsLang));
+ if (!codec)
+ codec = QTextCodec::codecForLocale();
+#endif
+}
+
+QCUPSSupport::~QCUPSSupport()
+{
+ if (currPPD)
+ _ppdClose(currPPD);
+ if (prnCount)
+ _cupsFreeDests(prnCount, printers);
+}
+
+int QCUPSSupport::availablePrintersCount() const
+{
+ return prnCount;
+}
+
+const cups_dest_t* QCUPSSupport::availablePrinters() const
+{
+ return printers;
+}
+
+const ppd_file_t* QCUPSSupport::currentPPD() const
+{
+ return currPPD;
+}
+
+const ppd_file_t* QCUPSSupport::setCurrentPrinter(int index)
+{
+ Q_ASSERT(index >= 0 && index <= prnCount);
+ if (index == prnCount)
+ return 0;
+
+ currPrinterIndex = index;
+
+ if (currPPD)
+ _ppdClose(currPPD);
+ currPPD = 0;
+ page_sizes = 0;
+
+ const char *ppdFile = _cupsGetPPD(printers[index].name);
+
+ if (!ppdFile)
+ return 0;
+
+ currPPD = _ppdOpenFile(ppdFile);
+ unlink(ppdFile);
+
+ // marking default options
+ _ppdMarkDefaults(currPPD);
+
+ // marking options explicitly set
+ _cupsMarkOptions(currPPD, printers[currPrinterIndex].num_options, printers[currPrinterIndex].options);
+
+ // getting pointer to page sizes
+ page_sizes = ppdOption("PageSize");
+
+ return currPPD;
+}
+
+int QCUPSSupport::currentPrinterIndex() const
+{
+ return currPrinterIndex;
+}
+
+bool QCUPSSupport::isAvailable()
+{
+ if(!cupsLoaded)
+ resolveCups();
+
+ return _cupsGetDests &&
+ _cupsFreeDests &&
+ _cupsGetPPD &&
+ _ppdOpenFile &&
+ _ppdMarkDefaults &&
+ _ppdClose &&
+ _cupsMarkOptions &&
+ _ppdMarkOption &&
+ _cupsFreeOptions &&
+ _cupsSetDests &&
+ _cupsLangGet &&
+ _cupsLangEncoding &&
+ _cupsAddOption &&
+ (qt_cups_num_printers > 0);
+}
+
+const ppd_option_t* QCUPSSupport::ppdOption(const char *key) const
+{
+ if (currPPD) {
+ for (int gr = 0; gr < currPPD->num_groups; ++gr) {
+ for (int opt = 0; opt < currPPD->groups[gr].num_options; ++opt) {
+ if (qstrcmp(currPPD->groups[gr].options[opt].keyword, key) == 0)
+ return &currPPD->groups[gr].options[opt];
+ }
+ }
+ }
+ return 0;
+}
+
+const cups_option_t* QCUPSSupport::printerOption(const QString &key) const
+{
+ for (int i = 0; i < printers[currPrinterIndex].num_options; ++i) {
+ if (QLatin1String(printers[currPrinterIndex].options[i].name) == key)
+ return &printers[currPrinterIndex].options[i];
+ }
+ return 0;
+}
+
+const ppd_option_t* QCUPSSupport::pageSizes() const
+{
+ return page_sizes;
+}
+
+int QCUPSSupport::markOption(const char* name, const char* value)
+{
+ return _ppdMarkOption(currPPD, name, value);
+}
+
+void QCUPSSupport::saveOptions(QList<const ppd_option_t*> options, QList<const char*> markedOptions)
+{
+ int oldOptionCount = printers[currPrinterIndex].num_options;
+ cups_option_t* oldOptions = printers[currPrinterIndex].options;
+
+ int newOptionCount = 0;
+ cups_option_t* newOptions = 0;
+
+ // copying old options that are not on the new list
+ for (int i = 0; i < oldOptionCount; ++i) {
+ bool contains = false;
+ for (int j = 0; j < options.count(); ++j) {
+ if (qstrcmp(options.at(j)->keyword, oldOptions[i].name) == 0) {
+ contains = true;
+ break;
+ }
+ }
+
+ if (!contains) {
+ newOptionCount = _cupsAddOption(oldOptions[i].name, oldOptions[i].value, newOptionCount, &newOptions);
+ }
+ }
+
+ // we can release old option list
+ _cupsFreeOptions(oldOptionCount, oldOptions);
+
+ // adding marked options
+ for (int i = 0; i < markedOptions.count(); ++i) {
+ const char* name = markedOptions.at(i);
+ ++i;
+ newOptionCount = _cupsAddOption(name, markedOptions.at(i), newOptionCount, &newOptions);
+ }
+
+ // placing the new option list
+ printers[currPrinterIndex].num_options = newOptionCount;
+ printers[currPrinterIndex].options = newOptions;
+
+ // saving new default values
+ _cupsSetDests(prnCount, printers);
+}
+
+QRect QCUPSSupport::paperRect(const char *choice) const
+{
+ if (!currPPD)
+ return QRect();
+ for (int i = 0; i < currPPD->num_sizes; ++i) {
+ if (qstrcmp(currPPD->sizes[i].name, choice) == 0)
+ return QRect(0, 0, qRound(currPPD->sizes[i].width), qRound(currPPD->sizes[i].length));
+ }
+ return QRect();
+}
+
+QRect QCUPSSupport::pageRect(const char *choice) const
+{
+ if (!currPPD)
+ return QRect();
+ for (int i = 0; i < currPPD->num_sizes; ++i) {
+ if (qstrcmp(currPPD->sizes[i].name, choice) == 0)
+ return QRect(qRound(currPPD->sizes[i].left),
+ qRound(currPPD->sizes[i].length - currPPD->sizes[i].top),
+ qRound(currPPD->sizes[i].right - currPPD->sizes[i].left),
+ qRound(currPPD->sizes[i].top - currPPD->sizes[i].bottom));
+ }
+ return QRect();
+}
+
+QStringList QCUPSSupport::options() const
+{
+ QStringList list;
+ collectMarkedOptions(list);
+ return list;
+}
+
+bool QCUPSSupport::printerHasPPD(const char *printerName)
+{
+ if (!isAvailable())
+ return false;
+ const char *ppdFile = _cupsGetPPD(printerName);
+ if (ppdFile)
+ unlink(ppdFile);
+ return (ppdFile != 0);
+}
+
+QString QCUPSSupport::unicodeString(const char *s)
+{
+#ifndef QT_NO_TEXTCODEC
+ return codec->toUnicode(s);
+#else
+ return QLatin1String(s);
+#endif
+}
+
+void QCUPSSupport::collectMarkedOptions(QStringList& list, const ppd_group_t* group) const
+{
+ if (group == 0) {
+ if (!currPPD)
+ return;
+ for (int i = 0; i < currPPD->num_groups; ++i) {
+ collectMarkedOptions(list, &currPPD->groups[i]);
+ collectMarkedOptionsHelper(list, &currPPD->groups[i]);
+ }
+ } else {
+ for (int i = 0; i < group->num_subgroups; ++i)
+ collectMarkedOptionsHelper(list, &group->subgroups[i]);
+ }
+}
+
+void QCUPSSupport::collectMarkedOptionsHelper(QStringList& list, const ppd_group_t* group) const
+{
+ for (int i = 0; i < group->num_options; ++i) {
+ for (int j = 0; j < group->options[i].num_choices; ++j) {
+ if (group->options[i].choices[j].marked == 1 && qstrcmp(group->options[i].choices[j].choice, group->options[i].defchoice) != 0)
+ list << QString::fromLocal8Bit(group->options[i].keyword) << QString::fromLocal8Bit(group->options[i].choices[j].choice);
+ }
+ }
+}
+
+QPair<int, QString> QCUPSSupport::tempFd()
+{
+ char filename[512];
+ int fd = _cupsTempFd(filename, 512);
+ return QPair<int, QString>(fd, QString::fromLocal8Bit(filename));
+}
+
+// Prints the given file and returns a job id.
+int QCUPSSupport::printFile(const char * printerName, const char * filename, const char * title,
+ int num_options, cups_option_t * options)
+{
+ return _cupsPrintFile(printerName, filename, title, num_options, options);
+}
+
+QCUPSSupport::Printer::Printer(const QString &n) : name(n), isDefault(false), cupsPrinterIndex(-1)
+{
+}
+
+QList<QCUPSSupport::Printer> QCUPSSupport::availableUnixPrinters()
+{
+ QList<Printer> printers;
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (QCUPSSupport::isAvailable()) {
+ QCUPSSupport cups;
+ int cupsPrinterCount = cups.availablePrintersCount();
+ const cups_dest_t* cupsPrinters = cups.availablePrinters();
+ for (int i = 0; i < cupsPrinterCount; ++i) {
+ QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
+ if (cupsPrinters[i].instance)
+ printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
+
+ Printer p(printerName);
+ if (cupsPrinters[i].is_default)
+ p.isDefault = true;
+ p.cupsPrinterIndex = i;
+ printers.append(p);
+ }
+ } else
+#endif
+ {
+ QList<QPrinterDescription> lprPrinters;
+ int defprn = qt_getLprPrinters(lprPrinters);
+ // populating printer combo
+ foreach (const QPrinterDescription &description, lprPrinters)
+ printers.append(Printer(description.name));
+ if (defprn >= 0 && defprn < printers.size())
+ printers[defprn].isDefault = true;
+ }
+
+ return printers;
+}
+
+QList<QPrinter::PaperSize> QCUPSSupport::getCupsPrinterPaperSizes(int cupsPrinterIndex)
+{
+ return qt_getCupsPrinterPaperSizes(cupsPrinterIndex);
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_CUPS
diff --git a/src/printsupport/kernel/qcups_p.h b/src/printsupport/kernel/qcups_p.h
new file mode 100644
index 0000000000..33a4e264d7
--- /dev/null
+++ b/src/printsupport/kernel/qcups_p.h
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCUPS_P_H
+#define QCUPS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+#include "QtCore/qstring.h"
+#include "QtCore/qstringlist.h"
+#include "QtCore/qpair.h"
+#include "QtPrintSupport/qprinter.h"
+
+#ifndef QT_NO_CUPS
+#include <QtCore/qlibrary.h>
+#include <cups/cups.h>
+#include <cups/ppd.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_TYPEINFO(cups_option_t, Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE);
+
+class Q_GUI_EXPORT QCUPSSupport
+{
+public:
+ struct Printer
+ {
+ Printer(const QString &name = QString());
+
+ QString name;
+ bool isDefault;
+ int cupsPrinterIndex;
+ };
+ QCUPSSupport();
+ ~QCUPSSupport();
+
+ static bool isAvailable();
+ static int cupsVersion() { return isAvailable() ? CUPS_VERSION_MAJOR*10000+CUPS_VERSION_MINOR*100+CUPS_VERSION_PATCH : 0; }
+ int availablePrintersCount() const;
+ const cups_dest_t* availablePrinters() const;
+ int currentPrinterIndex() const;
+ const ppd_file_t* setCurrentPrinter(int index);
+
+ const ppd_file_t* currentPPD() const;
+ const ppd_option_t* ppdOption(const char *key) const;
+
+ const cups_option_t* printerOption(const QString &key) const;
+ const ppd_option_t* pageSizes() const;
+
+ int markOption(const char* name, const char* value);
+ void saveOptions(QList<const ppd_option_t*> options, QList<const char*> markedOptions);
+
+ QRect paperRect(const char *choice) const;
+ QRect pageRect(const char *choice) const;
+
+ QStringList options() const;
+
+ static bool printerHasPPD(const char *printerName);
+
+ QString unicodeString(const char *s);
+
+ QPair<int, QString> tempFd();
+ int printFile(const char * printerName, const char * filename, const char * title,
+ int num_options, cups_option_t * options);
+
+ static QList<Printer> availableUnixPrinters();
+ static QList<QPrinter::PaperSize> getCupsPrinterPaperSizes(int cupsPrinterIndex);
+
+private:
+ void collectMarkedOptions(QStringList& list, const ppd_group_t* group = 0) const;
+ void collectMarkedOptionsHelper(QStringList& list, const ppd_group_t* group) const;
+
+ int prnCount;
+ cups_dest_t *printers;
+ const ppd_option_t* page_sizes;
+ int currPrinterIndex;
+ ppd_file_t *currPPD;
+#ifndef QT_NO_TEXTCODEC
+ QTextCodec *codec;
+#endif
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_CUPS
+
+#endif
diff --git a/src/printsupport/kernel/qpaintengine_alpha.cpp b/src/printsupport/kernel/qpaintengine_alpha.cpp
new file mode 100644
index 0000000000..beda2c7144
--- /dev/null
+++ b/src/printsupport/kernel/qpaintengine_alpha.cpp
@@ -0,0 +1,516 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qglobal.h>
+
+#ifndef QT_NO_PRINTER
+#include <qdebug.h>
+#include "private/qpaintengine_alpha_p.h"
+
+#include "private/qpicture_p.h"
+#include "private/qfont_p.h"
+#include "QtGui/qpicture.h"
+
+QT_BEGIN_NAMESPACE
+
+QAlphaPaintEngine::QAlphaPaintEngine(QAlphaPaintEnginePrivate &data, PaintEngineFeatures devcaps)
+ : QPaintEngine(data, devcaps)
+{
+
+}
+
+QAlphaPaintEngine::~QAlphaPaintEngine()
+{
+
+}
+
+bool QAlphaPaintEngine::begin(QPaintDevice *pdev)
+{
+ Q_D(QAlphaPaintEngine);
+
+ d->m_continueCall = true;
+ if (d->m_pass != 0) {
+ return true;
+ }
+
+ d->m_savedcaps = gccaps;
+ d->m_pdev = pdev;
+
+ d->m_alphaPen = false;
+ d->m_alphaBrush = false;
+ d->m_alphaOpacity = false;
+ d->m_hasalpha = false;
+ d->m_advancedPen = false;
+ d->m_advancedBrush = false;
+ d->m_complexTransform = false;
+ d->m_emulateProjectiveTransforms = false;
+
+ // clear alpha region
+ d->m_alphargn = QRegion();
+ d->m_cliprgn = QRegion();
+ d->m_pen = QPen();
+ d->m_transform = QTransform();
+
+ flushAndInit();
+
+ return true;
+}
+
+bool QAlphaPaintEngine::end()
+{
+ Q_D(QAlphaPaintEngine);
+
+ d->m_continueCall = true;
+ if (d->m_pass != 0) {
+ return true;
+ }
+
+ flushAndInit(false);
+ return true;
+}
+
+void QAlphaPaintEngine::updateState(const QPaintEngineState &state)
+{
+ Q_D(QAlphaPaintEngine);
+
+ DirtyFlags flags = state.state();
+ if (flags & QPaintEngine::DirtyTransform) {
+ d->m_transform = state.transform();
+ d->m_complexTransform = (d->m_transform.type() > QTransform::TxScale);
+ d->m_emulateProjectiveTransforms = !(d->m_savedcaps & QPaintEngine::PerspectiveTransform)
+ && !(d->m_savedcaps & QPaintEngine::AlphaBlend)
+ && (d->m_transform.type() >= QTransform::TxProject);
+ }
+ if (flags & QPaintEngine::DirtyPen) {
+ d->m_pen = state.pen();
+ if (d->m_pen.style() == Qt::NoPen) {
+ d->m_advancedPen = false;
+ d->m_alphaPen = false;
+ } else {
+ d->m_advancedPen = (d->m_pen.brush().style() != Qt::SolidPattern);
+ d->m_alphaPen = !d->m_pen.brush().isOpaque();
+ }
+ }
+
+ if (d->m_pass != 0) {
+ d->m_continueCall = true;
+ return;
+ }
+ d->m_continueCall = false;
+
+ if (flags & QPaintEngine::DirtyOpacity) {
+ d->m_alphaOpacity = (state.opacity() != 1.0f);
+ }
+
+ if (flags & QPaintEngine::DirtyBrush) {
+ if (state.brush().style() == Qt::NoBrush) {
+ d->m_advancedBrush = false;
+ d->m_alphaBrush = false;
+ } else {
+ d->m_advancedBrush = (state.brush().style() != Qt::SolidPattern);
+ d->m_alphaBrush = !state.brush().isOpaque();
+ }
+ }
+
+
+ d->m_hasalpha = d->m_alphaOpacity || d->m_alphaBrush || d->m_alphaPen;
+
+ if (d->m_picengine)
+ d->m_picengine->updateState(state);
+}
+
+void QAlphaPaintEngine::drawPath(const QPainterPath &path)
+{
+ Q_D(QAlphaPaintEngine);
+
+ QRectF tr = d->addPenWidth(path);
+
+ if (d->m_pass == 0) {
+ d->m_continueCall = false;
+ if (d->m_hasalpha || d->m_advancedPen || d->m_advancedBrush
+ || d->m_emulateProjectiveTransforms)
+ {
+ d->addAlphaRect(tr);
+ }
+ if (d->m_picengine)
+ d->m_picengine->drawPath(path);
+ } else {
+ d->m_continueCall = !d->fullyContained(tr);
+ }
+}
+
+void QAlphaPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
+{
+ Q_D(QAlphaPaintEngine);
+
+ QPolygonF poly;
+ for (int i=0; i<pointCount; ++i)
+ poly.append(points[i]);
+
+ QPainterPath path;
+ path.addPolygon(poly);
+ QRectF tr = d->addPenWidth(path);
+
+ if (d->m_pass == 0) {
+ d->m_continueCall = false;
+ if (d->m_hasalpha || d->m_advancedPen || d->m_advancedBrush
+ || d->m_emulateProjectiveTransforms)
+ {
+ d->addAlphaRect(tr);
+ }
+
+ if (d->m_picengine)
+ d->m_picengine->drawPolygon(points, pointCount, mode);
+ } else {
+ d->m_continueCall = !d->fullyContained(tr);
+ }
+}
+
+void QAlphaPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
+{
+ Q_D(QAlphaPaintEngine);
+
+ QRectF tr = d->m_transform.mapRect(r);
+ if (d->m_pass == 0) {
+ d->m_continueCall = false;
+ if (pm.hasAlpha() || d->m_alphaOpacity || d->m_complexTransform || pm.isQBitmap()) {
+ d->addAlphaRect(tr);
+ }
+
+ if (d->m_picengine)
+ d->m_picengine->drawPixmap(r, pm, sr);
+
+ } else {
+ d->m_continueCall = !d->fullyContained(tr);
+ }
+}
+
+void QAlphaPaintEngine::drawImage(const QRectF &r, const QImage &image, const QRectF &sr)
+{
+ Q_D(QAlphaPaintEngine);
+
+ QRectF tr = d->m_transform.mapRect(r);
+ if (d->m_pass == 0) {
+ d->m_continueCall = false;
+ if (image.hasAlphaChannel() || d->m_alphaOpacity || d->m_complexTransform) {
+ d->addAlphaRect(tr);
+ }
+
+ if (d->m_picengine)
+ d->m_picengine->drawImage(r, image, sr);
+
+ } else {
+ d->m_continueCall = !d->fullyContained(tr);
+ }
+}
+
+void QAlphaPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
+{
+ Q_D(QAlphaPaintEngine);
+
+ QRectF tr(p.x(), p.y() - textItem.ascent(), textItem.width() + 5, textItem.ascent() + textItem.descent() + 5);
+ tr = d->m_transform.mapRect(tr);
+
+ if (d->m_pass == 0) {
+ d->m_continueCall = false;
+ if (d->m_alphaPen || d->m_alphaOpacity || d->m_advancedPen) {
+ d->addAlphaRect(tr);
+ }
+ if (d->m_picengine) {
+ d->m_picengine->drawTextItem(p, textItem);
+ }
+ } else {
+ d->m_continueCall = !d->fullyContained(tr);
+ }
+}
+
+void QAlphaPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
+{
+ Q_D(QAlphaPaintEngine);
+
+ QRectF brect = d->m_transform.mapRect(r);
+
+ if (d->m_pass == 0) {
+ d->m_continueCall = false;
+ if (pixmap.hasAlpha() || d->m_alphaOpacity || d->m_complexTransform || pixmap.isQBitmap()) {
+ d->addAlphaRect(brect);
+ }
+ if (d->m_picengine)
+ d->m_picengine->drawTiledPixmap(r, pixmap, s);
+ } else {
+ d->m_continueCall = !d->fullyContained(brect);
+ }
+}
+
+QRegion QAlphaPaintEngine::alphaClipping() const
+{
+ Q_D(const QAlphaPaintEngine);
+ return d->m_cliprgn;
+}
+
+bool QAlphaPaintEngine::continueCall() const
+{
+ Q_D(const QAlphaPaintEngine);
+ return d->m_continueCall;
+}
+
+void QAlphaPaintEngine::flushAndInit(bool init)
+{
+ Q_D(QAlphaPaintEngine);
+ Q_ASSERT(d->m_pass == 0);
+
+ if (d->m_pic) {
+ d->m_picpainter->end();
+
+ // set clip region
+ d->m_alphargn = d->m_alphargn.intersected(QRect(0, 0, d->m_pdev->width(), d->m_pdev->height()));
+
+ // just use the bounding rect if it's a complex region..
+ QVector<QRect> rects = d->m_alphargn.rects();
+ if (rects.size() > 10) {
+ QRect br = d->m_alphargn.boundingRect();
+ d->m_alphargn = QRegion(br);
+ rects.clear();
+ rects.append(br);
+ }
+
+ d->m_cliprgn = d->m_alphargn;
+
+ // now replay the QPicture
+ ++d->m_pass; // we are now doing pass #2
+
+ // reset states
+ gccaps = d->m_savedcaps;
+
+ painter()->save();
+ d->resetState(painter());
+
+ // make sure the output from QPicture is unscaled
+ QTransform mtx;
+ mtx.scale(1.0f / (qreal(d->m_pdev->logicalDpiX()) / qreal(qt_defaultDpiX())),
+ 1.0f / (qreal(d->m_pdev->logicalDpiY()) / qreal(qt_defaultDpiY())));
+ painter()->setTransform(mtx);
+ painter()->drawPicture(0, 0, *d->m_pic);
+
+ d->m_cliprgn = QRegion();
+ d->resetState(painter());
+
+ // fill in the alpha images
+ for (int i=0; i<rects.size(); ++i)
+ d->drawAlphaImage(rects.at(i));
+
+ d->m_alphargn = QRegion();
+
+ painter()->restore();
+
+ --d->m_pass; // pass #2 finished
+
+ cleanUp();
+ }
+
+ if (init) {
+ gccaps = PaintEngineFeatures(AllFeatures & ~QPaintEngine::ObjectBoundingModeGradients);
+
+ d->m_pic = new QPicture();
+ d->m_pic->d_ptr->in_memory_only = true;
+ d->m_picpainter = new QPainter(d->m_pic);
+ d->m_picengine = d->m_picpainter->paintEngine();
+
+ // When newPage() is called and the m_picpainter is recreated
+ // we have to copy the current state of the original printer
+ // painter back to the m_picpainter
+ d->m_picpainter->setPen(painter()->pen());
+ d->m_picpainter->setBrush(painter()->brush());
+ d->m_picpainter->setBrushOrigin(painter()->brushOrigin());
+ d->m_picpainter->setFont(painter()->font());
+ d->m_picpainter->setOpacity(painter()->opacity());
+ d->m_picpainter->setTransform(painter()->combinedTransform());
+ d->m_picengine->syncState();
+ }
+}
+
+void QAlphaPaintEngine::cleanUp()
+{
+ Q_D(QAlphaPaintEngine);
+
+ delete d->m_picpainter;
+ delete d->m_pic;
+
+ d->m_picpainter = 0;
+ d->m_pic = 0;
+ d->m_picengine = 0;
+}
+
+QAlphaPaintEnginePrivate::QAlphaPaintEnginePrivate()
+ : m_pass(0),
+ m_pic(0),
+ m_picengine(0),
+ m_picpainter(0),
+ m_hasalpha(false),
+ m_alphaPen(false),
+ m_alphaBrush(false),
+ m_alphaOpacity(false),
+ m_advancedPen(false),
+ m_advancedBrush(false),
+ m_complexTransform(false)
+{
+
+}
+
+QAlphaPaintEnginePrivate::~QAlphaPaintEnginePrivate()
+{
+ delete m_picpainter;
+ delete m_pic;
+}
+
+QRectF QAlphaPaintEnginePrivate::addPenWidth(const QPainterPath &path)
+{
+ QPainterPath tmp = path;
+
+ if (m_pen.style() == Qt::NoPen)
+ return (path.controlPointRect() * m_transform).boundingRect();
+ if (m_pen.isCosmetic())
+ tmp = path * m_transform;
+
+ QPainterPathStroker stroker;
+ if (m_pen.widthF() == 0.0f)
+ stroker.setWidth(1.0);
+ else
+ stroker.setWidth(m_pen.widthF());
+ stroker.setJoinStyle(m_pen.joinStyle());
+ stroker.setCapStyle(m_pen.capStyle());
+ tmp = stroker.createStroke(tmp);
+ if (m_pen.isCosmetic())
+ return tmp.controlPointRect();
+
+ return (tmp.controlPointRect() * m_transform).boundingRect();
+}
+
+QRect QAlphaPaintEnginePrivate::toRect(const QRectF &rect) const
+{
+ QRect r;
+ r.setLeft(int(rect.left()));
+ r.setTop(int(rect.top()));
+ r.setRight(int(rect.right() + 1));
+ r.setBottom(int(rect.bottom() + 1));
+ return r;
+}
+
+void QAlphaPaintEnginePrivate::addAlphaRect(const QRectF &rect)
+{
+ m_alphargn |= toRect(rect);
+}
+
+void QAlphaPaintEnginePrivate::drawAlphaImage(const QRectF &rect)
+{
+ Q_Q(QAlphaPaintEngine);
+
+ qreal dpiX = qMax(m_pdev->logicalDpiX(), 300);
+ qreal dpiY = qMax(m_pdev->logicalDpiY(), 300);
+ qreal xscale = (dpiX / m_pdev->logicalDpiX());
+ qreal yscale = (dpiY / m_pdev->logicalDpiY());
+
+ QTransform picscale;
+ picscale.scale(xscale, yscale);
+
+ const int tileSize = 2048;
+ QSize size((int(rect.width() * xscale)), int(rect.height() * yscale));
+ int divw = (size.width() / tileSize);
+ int divh = (size.height() / tileSize);
+ divw += 1;
+ divh += 1;
+
+ int incx = int(rect.width() / divw);
+ int incy = int(rect.height() / divh);
+
+ for (int y=0; y<divh; ++y) {
+ int ypos = int((incy * y) + rect.y());
+ int height = int((y == (divh - 1)) ? (rect.height() - (incy * y)) : incy) + 1;
+
+ for (int x=0; x<divw; ++x) {
+ int xpos = int((incx * x) + rect.x());
+ int width = int((x == (divw - 1)) ? (rect.width() - (incx * x)) : incx) + 1;
+
+ QSize imgsize((int)(width * xscale), (int)(height * yscale));
+ QImage img(imgsize, QImage::Format_RGB32);
+ img.fill(0xffffffff);
+
+ QPainter imgpainter(&img);
+ imgpainter.setTransform(picscale);
+ QPointF picpos(qreal(-xpos), qreal(-ypos));
+ imgpainter.drawPicture(picpos, *m_pic);
+ imgpainter.end();
+
+ q->painter()->setTransform(QTransform());
+ QRect r(xpos, ypos, width, height);
+ q->painter()->drawImage(r, img);
+ }
+ }
+}
+
+bool QAlphaPaintEnginePrivate::fullyContained(const QRectF &rect) const
+{
+ QRegion r(toRect(rect));
+ return (m_cliprgn.intersected(r) == r);
+}
+
+void QAlphaPaintEnginePrivate::resetState(QPainter *p)
+{
+ p->setPen(QPen());
+ p->setBrush(QBrush());
+ p->setBrushOrigin(0,0);
+ p->setBackground(QBrush());
+ p->setFont(QFont());
+ p->setTransform(QTransform());
+ // The view transform is already recorded and included in the
+ // picture we're about to replay. If we don't turn if off,
+ // the view matrix will be applied twice.
+ p->setViewTransformEnabled(false);
+ p->setClipRegion(QRegion(), Qt::NoClip);
+ p->setClipPath(QPainterPath(), Qt::NoClip);
+ p->setClipping(false);
+ p->setOpacity(1.0f);
+}
+
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qpaintengine_alpha_p.h b/src/printsupport/kernel/qpaintengine_alpha_p.h
new file mode 100644
index 0000000000..5694e2a5bc
--- /dev/null
+++ b/src/printsupport/kernel/qpaintengine_alpha_p.h
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPAINTENGINE_ALPHA_P_H
+#define QPAINTENGINE_ALPHA_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QT_NO_PRINTER
+#include "private/qpaintengine_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QAlphaPaintEnginePrivate;
+
+class QAlphaPaintEngine : public QPaintEngine
+{
+ Q_DECLARE_PRIVATE(QAlphaPaintEngine)
+public:
+ ~QAlphaPaintEngine();
+
+ virtual bool begin(QPaintDevice *pdev);
+ virtual bool end();
+
+ virtual void updateState(const QPaintEngineState &state);
+
+ virtual void drawPath(const QPainterPath &path);
+
+ virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
+
+ virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
+ virtual void drawImage(const QRectF &r, const QImage &image, const QRectF &sr);
+ virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
+ virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
+
+protected:
+ QAlphaPaintEngine(QAlphaPaintEnginePrivate &data, PaintEngineFeatures devcaps = 0);
+ QRegion alphaClipping() const;
+ bool continueCall() const;
+ void flushAndInit(bool init = true);
+ void cleanUp();
+};
+
+class QAlphaPaintEnginePrivate : public QPaintEnginePrivate
+{
+ Q_DECLARE_PUBLIC(QAlphaPaintEngine)
+public:
+ QAlphaPaintEnginePrivate();
+ ~QAlphaPaintEnginePrivate();
+
+ int m_pass;
+ QPicture *m_pic;
+ QPaintEngine *m_picengine;
+ QPainter *m_picpainter;
+
+ QPaintEngine::PaintEngineFeatures m_savedcaps;
+ QPaintDevice *m_pdev;
+
+ QRegion m_alphargn;
+ QRegion m_cliprgn;
+
+ bool m_hasalpha;
+ bool m_alphaPen;
+ bool m_alphaBrush;
+ bool m_alphaOpacity;
+ bool m_advancedPen;
+ bool m_advancedBrush;
+ bool m_complexTransform;
+ bool m_emulateProjectiveTransforms;
+ bool m_continueCall;
+
+ QTransform m_transform;
+ QPen m_pen;
+
+ void addAlphaRect(const QRectF &rect);
+ QRectF addPenWidth(const QPainterPath &path);
+ void drawAlphaImage(const QRectF &rect);
+ QRect toRect(const QRectF &rect) const;
+ bool fullyContained(const QRectF &rect) const;
+
+ void resetState(QPainter *p);
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
+
+#endif // QPAINTENGINE_ALPHA_P_H
diff --git a/src/printsupport/kernel/qpaintengine_preview.cpp b/src/printsupport/kernel/qpaintengine_preview.cpp
new file mode 100644
index 0000000000..3cf06f5770
--- /dev/null
+++ b/src/printsupport/kernel/qpaintengine_preview.cpp
@@ -0,0 +1,223 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <private/qpaintengine_preview_p.h>
+#include <private/qpainter_p.h>
+#include <private/qpaintengine_p.h>
+#include <private/qpicture_p.h>
+
+#include <QtPrintSupport/qprintengine.h>
+#include <QtGui/qpainter.h>
+#include <QtGui/qpicture.h>
+
+#ifndef QT_NO_PRINTPREVIEWWIDGET
+QT_BEGIN_NAMESPACE
+
+class QPreviewPaintEnginePrivate : public QPaintEnginePrivate
+{
+ Q_DECLARE_PUBLIC(QPreviewPaintEngine)
+public:
+ QPreviewPaintEnginePrivate() : state(QPrinter::Idle) {}
+ ~QPreviewPaintEnginePrivate() {}
+
+ QList<const QPicture *> pages;
+ QPaintEngine *engine;
+ QPainter *painter;
+ QPrinter::PrinterState state;
+
+ QPaintEngine *proxy_paint_engine;
+ QPrintEngine *proxy_print_engine;
+};
+
+
+QPreviewPaintEngine::QPreviewPaintEngine()
+ : QPaintEngine(*(new QPreviewPaintEnginePrivate), PaintEngineFeatures(AllFeatures & ~ObjectBoundingModeGradients))
+{
+ Q_D(QPreviewPaintEngine);
+ d->proxy_print_engine = 0;
+ d->proxy_paint_engine = 0;
+}
+
+QPreviewPaintEngine::~QPreviewPaintEngine()
+{
+ Q_D(QPreviewPaintEngine);
+
+ qDeleteAll(d->pages);
+}
+
+bool QPreviewPaintEngine::begin(QPaintDevice *)
+{
+ Q_D(QPreviewPaintEngine);
+
+ qDeleteAll(d->pages);
+ d->pages.clear();
+
+ QPicture *page = new QPicture;
+ page->d_func()->in_memory_only = true;
+ d->painter = new QPainter(page);
+ d->engine = d->painter->paintEngine();
+ d->pages.append(page);
+ d->state = QPrinter::Active;
+ return true;
+}
+
+bool QPreviewPaintEngine::end()
+{
+ Q_D(QPreviewPaintEngine);
+
+ delete d->painter;
+ d->painter = 0;
+ d->engine = 0;
+ d->state = QPrinter::Idle;
+ return true;
+}
+
+void QPreviewPaintEngine::updateState(const QPaintEngineState &state)
+{
+ Q_D(QPreviewPaintEngine);
+ d->engine->updateState(state);
+}
+
+void QPreviewPaintEngine::drawPath(const QPainterPath &path)
+{
+ Q_D(QPreviewPaintEngine);
+ d->engine->drawPath(path);
+}
+
+void QPreviewPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
+{
+ Q_D(QPreviewPaintEngine);
+ d->engine->drawPolygon(points, pointCount, mode);
+}
+
+void QPreviewPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
+{
+ Q_D(QPreviewPaintEngine);
+ d->engine->drawTextItem(p, textItem);
+}
+
+void QPreviewPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
+{
+ Q_D(QPreviewPaintEngine);
+ d->engine->drawPixmap(r, pm, sr);
+}
+
+void QPreviewPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p)
+{
+ Q_D(QPreviewPaintEngine);
+ d->engine->drawTiledPixmap(r, pm, p);
+}
+
+bool QPreviewPaintEngine::newPage()
+{
+ Q_D(QPreviewPaintEngine);
+
+ QPicture *page = new QPicture;
+ page->d_func()->in_memory_only = true;
+ QPainter *tmp_painter = new QPainter(page);
+ QPaintEngine *tmp_engine = tmp_painter->paintEngine();
+
+ // copy the painter state from the original painter
+ Q_ASSERT(painter()->d_func()->state && tmp_painter->d_func()->state);
+ *tmp_painter->d_func()->state = *painter()->d_func()->state;
+
+ // composition modes aren't supported on a QPrinter and yields a
+ // warning, so ignore it for now
+ tmp_engine->setDirty(DirtyFlags(AllDirty & ~DirtyCompositionMode));
+ tmp_engine->syncState();
+
+ delete d->painter;
+ d->painter = tmp_painter;
+ d->pages.append(page);
+ d->engine = tmp_engine;
+ return true;
+}
+
+bool QPreviewPaintEngine::abort()
+{
+ Q_D(QPreviewPaintEngine);
+ end();
+ qDeleteAll(d->pages);
+ d->state = QPrinter::Aborted;
+
+ return true;
+}
+
+QList<const QPicture *> QPreviewPaintEngine::pages()
+{
+ Q_D(QPreviewPaintEngine);
+ return d->pages;
+}
+
+void QPreviewPaintEngine::setProxyEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine)
+{
+ Q_D(QPreviewPaintEngine);
+ d->proxy_print_engine = printEngine;
+ d->proxy_paint_engine = paintEngine;
+}
+
+void QPreviewPaintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value)
+{
+ Q_D(QPreviewPaintEngine);
+ d->proxy_print_engine->setProperty(key, value);
+}
+
+QVariant QPreviewPaintEngine::property(PrintEnginePropertyKey key) const
+{
+ Q_D(const QPreviewPaintEngine);
+ return d->proxy_print_engine->property(key);
+}
+
+int QPreviewPaintEngine::metric(QPaintDevice::PaintDeviceMetric id) const
+{
+ Q_D(const QPreviewPaintEngine);
+ return d->proxy_print_engine->metric(id);
+}
+
+QPrinter::PrinterState QPreviewPaintEngine::printerState() const
+{
+ Q_D(const QPreviewPaintEngine);
+ return d->state;
+}
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/printsupport/kernel/qpaintengine_preview_p.h b/src/printsupport/kernel/qpaintengine_preview_p.h
new file mode 100644
index 0000000000..c2e11313c2
--- /dev/null
+++ b/src/printsupport/kernel/qpaintengine_preview_p.h
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPREVIEWPAINTENGINE_P_H
+#define QPREVIEWPAINTENGINE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of QPreviewPrinter and friends. This header file may change from
+// version to version without notice, or even be removed.
+//
+// We mean it.
+//
+//
+
+#include <QtGui/qpaintengine.h>
+#include <QtPrintSupport/qprintengine.h>
+
+#ifndef QT_NO_PRINTPREVIEWWIDGET
+
+QT_BEGIN_NAMESPACE
+
+class QPreviewPaintEnginePrivate;
+
+class QPreviewPaintEngine : public QPaintEngine, public QPrintEngine
+{
+ Q_DECLARE_PRIVATE(QPreviewPaintEngine)
+public:
+ QPreviewPaintEngine();
+ ~QPreviewPaintEngine();
+
+ bool begin(QPaintDevice *dev);
+ bool end();
+
+ void updateState(const QPaintEngineState &state);
+
+ void drawPath(const QPainterPath &path);
+ void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
+ void drawTextItem(const QPointF &p, const QTextItem &textItem);
+
+ void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
+ void drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &p);
+
+ QList<const QPicture *> pages();
+
+ QPaintEngine::Type type() const { return Picture; }
+
+ void setProxyEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine);
+
+ void setProperty(PrintEnginePropertyKey key, const QVariant &value);
+ QVariant property(PrintEnginePropertyKey key) const;
+
+ bool newPage();
+ bool abort();
+
+ int metric(QPaintDevice::PaintDeviceMetric) const;
+
+ QPrinter::PrinterState printerState() const;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTPREVIEWWIDGET
+
+#endif
diff --git a/src/printsupport/kernel/qplatformprintersupport_qpa.cpp b/src/printsupport/kernel/qplatformprintersupport_qpa.cpp
new file mode 100644
index 0000000000..3c11b3304c
--- /dev/null
+++ b/src/printsupport/kernel/qplatformprintersupport_qpa.cpp
@@ -0,0 +1,133 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplatformprintersupport_qpa.h"
+
+#include <QtPrintSupport/qprinterinfo.h>
+
+#include <private/qprinterinfo_p.h>
+
+#ifndef QT_NO_PRINTER
+
+QT_BEGIN_NAMESPACE
+
+QPlatformPrinterSupport::QPlatformPrinterSupport()
+{
+}
+
+QPlatformPrinterSupport::~QPlatformPrinterSupport()
+{
+}
+
+QPrintEngine *QPlatformPrinterSupport::createNativePrintEngine(QPrinter::PrinterMode)
+{
+ return 0;
+}
+
+QPaintEngine *QPlatformPrinterSupport::createPaintEngine(QPrintEngine *, QPrinter::PrinterMode)
+{
+ return 0;
+}
+
+QList<QPrinter::PaperSize> QPlatformPrinterSupport::supportedPaperSizes(const QPrinterInfo &) const
+{
+ return QList<QPrinter::PaperSize>();
+}
+
+QList<QPrinterInfo> QPlatformPrinterSupport::availablePrinters()
+{
+ return QList<QPrinterInfo>();
+}
+
+QPrinterInfo QPlatformPrinterSupport::defaultPrinter()
+{
+ const QList<QPrinterInfo> printers = availablePrinters();
+ foreach (const QPrinterInfo &printerInfo, printers) {
+ if (printerInfo.isDefault())
+ return printerInfo;
+ }
+ return printers.isEmpty() ? QPrinterInfo() : printers.front();
+}
+
+QPrinterInfo QPlatformPrinterSupport::printerInfo(const QString &printerName, bool isDefault)
+{
+ QPrinterInfo pi = QPrinterInfo(printerName);
+ pi.d_func()->isDefault = isDefault;
+ return pi;
+}
+
+void QPlatformPrinterSupport::setPrinterInfoDefault(QPrinterInfo *p, bool isDefault)
+{
+ p->d_func()->isDefault = isDefault;
+}
+
+bool QPlatformPrinterSupport::printerInfoIsDefault(const QPrinterInfo &p)
+{
+ return p.d_func()->isDefault;
+}
+
+int QPlatformPrinterSupport::printerInfoCupsPrinterIndex(const QPrinterInfo &p)
+{
+ int i = -1;
+#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)) || defined(Q_WS_QPA)
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (!p.isNull())
+ return i = p.d_func()->cupsPrinterIndex;
+#endif
+#endif
+ Q_UNUSED(p)
+ return i;
+}
+
+void QPlatformPrinterSupport::setPrinterInfoCupsPrinterIndex(QPrinterInfo *p, int index)
+{
+#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)) || defined(Q_WS_QPA)
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ p->d_func()->cupsPrinterIndex = index;
+#endif
+#endif
+ Q_UNUSED(p)
+ Q_UNUSED(index)
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qplatformprintersupport_qpa.h b/src/printsupport/kernel/qplatformprintersupport_qpa.h
new file mode 100644
index 0000000000..3fe4ff04ee
--- /dev/null
+++ b/src/printsupport/kernel/qplatformprintersupport_qpa.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPLATFORMPRINTINGSUPPORT_H
+#define QPLATFORMPRINTINGSUPPORT_H
+
+#include <QtPrintSupport/qprinter.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_PRINTER
+
+class QPrintEngine;
+
+class Q_GUI_EXPORT QPlatformPrinterSupport
+{
+public:
+ QPlatformPrinterSupport();
+ virtual ~QPlatformPrinterSupport();
+
+ virtual QPrintEngine *createNativePrintEngine(QPrinter::PrinterMode printerMode);
+ virtual QPaintEngine *createPaintEngine(QPrintEngine *, QPrinter::PrinterMode printerMode);
+ virtual QList<QPrinter::PaperSize> supportedPaperSizes(const QPrinterInfo &) const;
+
+ virtual QList<QPrinterInfo> availablePrinters();
+ virtual QPrinterInfo defaultPrinter();
+
+protected:
+ static QPrinterInfo printerInfo(const QString &printerName, bool isDefault = false);
+ static void setPrinterInfoDefault(QPrinterInfo *p, bool isDefault);
+ static bool printerInfoIsDefault(const QPrinterInfo &p);
+ static int printerInfoCupsPrinterIndex(const QPrinterInfo &p);
+ static void setPrinterInfoCupsPrinterIndex(QPrinterInfo *p, int index);
+};
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPLATFORMPRINTINGSUPPORT_H
diff --git a/src/printsupport/kernel/qplatformprintplugin.cpp b/src/printsupport/kernel/qplatformprintplugin.cpp
new file mode 100644
index 0000000000..8b3c75127e
--- /dev/null
+++ b/src/printsupport/kernel/qplatformprintplugin.cpp
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplatformprintplugin_qpa.h"
+#include "private/qfactoryloader_p.h"
+
+QT_BEGIN_NAMESPACE
+
+#if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
+ (QPlatformPrinterSupportFactoryInterface_iid, QLatin1String("/printsupport"), Qt::CaseInsensitive))
+#endif
+
+QPlatformPrinterSupportPlugin::QPlatformPrinterSupportPlugin(QObject *parent)
+ : QObject(parent)
+{
+}
+
+QPlatformPrinterSupportPlugin::~QPlatformPrinterSupportPlugin()
+{
+}
+
+QPlatformPrinterSupport *QPlatformPrinterSupportPlugin::get()
+{
+ QStringList k = loader()->keys();
+ if (k.isEmpty())
+ return 0;
+ QPlatformPrinterSupportPlugin *plugin = qobject_cast<QPlatformPrinterSupportPlugin *>(loader()->instance(k.first()));
+ if (!plugin)
+ return 0;
+ return plugin->create(k.first());
+}
+
+QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qplatformprintplugin_qpa.h b/src/printsupport/kernel/qplatformprintplugin_qpa.h
new file mode 100644
index 0000000000..7c7e32994e
--- /dev/null
+++ b/src/printsupport/kernel/qplatformprintplugin_qpa.h
@@ -0,0 +1,94 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPLATFORMPRINTERSUPPORTPLUGIN_H
+#define QPLATFORMPRINTERSUPPORTPLUGIN_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/qplugin.h>
+#include <QtCore/qfactoryinterface.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+class QPlatformPrinterSupport;
+
+struct QPlatformPrinterSupportFactoryInterface : public QFactoryInterface
+{
+ virtual QPlatformPrinterSupport *create(const QString &key) = 0;
+};
+
+#define QPlatformPrinterSupportFactoryInterface_iid "org.qt-project.QPlatformPrinterSupportFactoryInterface"
+
+Q_DECLARE_INTERFACE(QPlatformPrinterSupportFactoryInterface, QPlatformPrinterSupportFactoryInterface_iid)
+
+class Q_GUI_EXPORT QPlatformPrinterSupportPlugin : public QObject, public QPlatformPrinterSupportFactoryInterface
+{
+ Q_OBJECT
+ Q_INTERFACES(QPlatformPrinterSupportFactoryInterface:QFactoryInterface)
+public:
+ explicit QPlatformPrinterSupportPlugin(QObject *parent = 0);
+ ~QPlatformPrinterSupportPlugin();
+
+ virtual QStringList keys() const = 0;
+ virtual QPlatformPrinterSupport *create(const QString &key) = 0;
+
+ static QPlatformPrinterSupport *get();
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPLATFORMPRINTERSUPPORTPLUGIN_H
diff --git a/src/printsupport/kernel/qprintengine.h b/src/printsupport/kernel/qprintengine.h
new file mode 100644
index 0000000000..550079defc
--- /dev/null
+++ b/src/printsupport/kernel/qprintengine.h
@@ -0,0 +1,119 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTENGINE_H
+#define QPRINTENGINE_H
+
+#include <QtCore/qvariant.h>
+#include <QtPrintSupport/qprinter.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_PRINTER
+
+class Q_GUI_EXPORT QPrintEngine
+{
+public:
+ virtual ~QPrintEngine() {}
+ enum PrintEnginePropertyKey {
+ PPK_CollateCopies,
+ PPK_ColorMode,
+ PPK_Creator,
+ PPK_DocumentName,
+ PPK_FullPage,
+ PPK_NumberOfCopies,
+ PPK_Orientation,
+ PPK_OutputFileName,
+ PPK_PageOrder,
+ PPK_PageRect,
+ PPK_PageSize,
+ PPK_PaperRect,
+ PPK_PaperSource,
+ PPK_PrinterName,
+ PPK_PrinterProgram,
+ PPK_Resolution,
+ PPK_SelectionOption,
+ PPK_SupportedResolutions,
+
+ PPK_WindowsPageSize,
+ PPK_FontEmbedding,
+ PPK_SuppressSystemPrintStatus,
+
+ PPK_Duplex,
+
+ PPK_PaperSources,
+ PPK_CustomPaperSize,
+ PPK_PageMargins,
+ PPK_CopyCount,
+ PPK_SupportsMultipleCopies,
+ PPK_PaperSize = PPK_PageSize,
+
+ PPK_CustomBase = 0xff00
+ };
+
+ virtual void setProperty(PrintEnginePropertyKey key, const QVariant &value) = 0;
+ virtual QVariant property(PrintEnginePropertyKey key) const = 0;
+
+ virtual bool newPage() = 0;
+ virtual bool abort() = 0;
+
+ virtual int metric(QPaintDevice::PaintDeviceMetric) const = 0;
+
+ virtual QPrinter::PrinterState printerState() const = 0;
+
+#ifdef Q_WS_WIN
+ virtual HDC getPrinterDC() const { return 0; }
+ virtual void releasePrinterDC(HDC) const { }
+#endif
+
+};
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPRINTENGINE_H
diff --git a/src/printsupport/kernel/qprintengine_pdf.cpp b/src/printsupport/kernel/qprintengine_pdf.cpp
new file mode 100644
index 0000000000..eb1bf163d3
--- /dev/null
+++ b/src/printsupport/kernel/qprintengine_pdf.cpp
@@ -0,0 +1,662 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtPrintSupport/qprintengine.h>
+
+#include <qiodevice.h>
+#include <qfile.h>
+#include <qdebug.h>
+#include <qbuffer.h>
+#include "private/qcups_p.h"
+#include "qprinterinfo.h"
+
+#ifndef QT_NO_PRINTER
+#include <limits.h>
+#include <math.h>
+
+#include "qprintengine_pdf_p.h"
+
+#ifdef Q_OS_UNIX
+#include "private/qcore_unix_p.h" // overrides QT_OPEN
+#endif
+
+QT_BEGIN_NAMESPACE
+
+//#define FONT_DUMP
+
+extern QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size);
+
+#define Q_MM(n) int((n * 720 + 127) / 254)
+#define Q_IN(n) int(n * 72)
+
+static const char * const psToStr[QPrinter::NPageSize+1] =
+{
+ "A4", "B5", "Letter", "Legal", "Executive",
+ "A0", "A1", "A2", "A3", "A5", "A6", "A7", "A8", "A9", "B0", "B1",
+ "B10", "B2", "B3", "B4", "B6", "B7", "B8", "B9", "C5E", "Comm10E",
+ "DLE", "Folio", "Ledger", "Tabloid", 0
+};
+
+QPdf::PaperSize QPdf::paperSize(QPrinter::PaperSize paperSize)
+{
+ QSizeF s = qt_paperSizeToQSizeF(paperSize);
+ PaperSize p = { Q_MM(s.width()), Q_MM(s.height()) };
+ return p;
+}
+
+const char *QPdf::paperSizeToString(QPrinter::PaperSize paperSize)
+{
+ return psToStr[paperSize];
+}
+
+
+QPdfPrintEngine::QPdfPrintEngine(QPrinter::PrinterMode m)
+ : QPdfEngine(*new QPdfPrintEnginePrivate(m))
+{
+ Q_D(QPdfPrintEngine);
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (QCUPSSupport::isAvailable()) {
+ QCUPSSupport cups;
+ const cups_dest_t* printers = cups.availablePrinters();
+ int prnCount = cups.availablePrintersCount();
+
+ for (int i = 0; i < prnCount; ++i) {
+ if (printers[i].is_default) {
+ d->printerName = QString::fromLocal8Bit(printers[i].name);
+ break;
+ }
+ }
+
+ } else
+#endif
+ {
+ d->printerName = QString::fromLocal8Bit(qgetenv("PRINTER"));
+ if (d->printerName.isEmpty())
+ d->printerName = QString::fromLocal8Bit(qgetenv("LPDEST"));
+ if (d->printerName.isEmpty())
+ d->printerName = QString::fromLocal8Bit(qgetenv("NPRINTER"));
+ if (d->printerName.isEmpty())
+ d->printerName = QString::fromLocal8Bit(qgetenv("NGPRINTER"));
+ }
+
+ state = QPrinter::Idle;
+}
+
+QPdfPrintEngine::~QPdfPrintEngine()
+{
+}
+
+bool QPdfPrintEngine::begin(QPaintDevice *pdev)
+{
+ Q_D(QPdfPrintEngine);
+
+ if (!d->openPrintDevice()) {
+ state = QPrinter::Error;
+ return false;
+ }
+ state = QPrinter::Active;
+
+ return QPdfEngine::begin(pdev);
+}
+
+bool QPdfPrintEngine::end()
+{
+ Q_D(QPdfPrintEngine);
+
+ QPdfEngine::end();
+
+ d->closePrintDevice();
+ state = QPrinter::Idle;
+
+ return true;
+}
+
+bool QPdfPrintEngine::newPage()
+{
+ return QPdfEngine::newPage();
+}
+
+int QPdfPrintEngine::metric(QPaintDevice::PaintDeviceMetric m) const
+{
+ return QPdfEngine::metric(m);
+}
+
+void QPdfPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value)
+{
+ Q_D(QPdfPrintEngine);
+
+ switch (int(key)) {
+ case PPK_CollateCopies:
+ d->collate = value.toBool();
+ break;
+ case PPK_ColorMode:
+ d->grayscale = (QPrinter::ColorMode(value.toInt()) == QPrinter::GrayScale);
+ break;
+ case PPK_Creator:
+ d->creator = value.toString();
+ break;
+ case PPK_DocumentName:
+ d->title = value.toString();
+ break;
+ case PPK_FullPage:
+ d->fullPage = value.toBool();
+ break;
+ case PPK_CopyCount: // fallthrough
+ case PPK_NumberOfCopies:
+ d->copies = value.toInt();
+ break;
+ case PPK_Orientation:
+ d->landscape = (QPrinter::Orientation(value.toInt()) == QPrinter::Landscape);
+ break;
+ case PPK_OutputFileName:
+ d->outputFileName = value.toString();
+ break;
+ case PPK_PageOrder:
+ d->pageOrder = QPrinter::PageOrder(value.toInt());
+ break;
+ case PPK_PaperSize:
+ d->printerPaperSize = QPrinter::PaperSize(value.toInt());
+ d->updatePaperSize();
+ break;
+ case PPK_PaperSource:
+ d->paperSource = QPrinter::PaperSource(value.toInt());
+ break;
+ case PPK_PrinterName:
+ d->printerName = value.toString();
+ break;
+ case PPK_PrinterProgram:
+ d->printProgram = value.toString();
+ break;
+ case PPK_Resolution:
+ d->resolution = value.toInt();
+ break;
+ case PPK_SelectionOption:
+ d->selectionOption = value.toString();
+ break;
+ case PPK_FontEmbedding:
+ d->embedFonts = value.toBool();
+ break;
+ case PPK_Duplex:
+ d->duplex = static_cast<QPrinter::DuplexMode> (value.toInt());
+ break;
+ case PPK_CupsPageRect:
+ d->cupsPageRect = value.toRect();
+ break;
+ case PPK_CupsPaperRect:
+ d->cupsPaperRect = value.toRect();
+ break;
+ case PPK_CupsOptions:
+ d->cupsOptions = value.toStringList();
+ break;
+ case PPK_CupsStringPageSize:
+ d->cupsStringPageSize = value.toString();
+ break;
+ case PPK_CustomPaperSize:
+ d->printerPaperSize = QPrinter::Custom;
+ d->customPaperSize = value.toSizeF();
+ d->updatePaperSize();
+ break;
+ case PPK_PageMargins:
+ {
+ QList<QVariant> margins(value.toList());
+ Q_ASSERT(margins.size() == 4);
+ d->leftMargin = margins.at(0).toReal();
+ d->topMargin = margins.at(1).toReal();
+ d->rightMargin = margins.at(2).toReal();
+ d->bottomMargin = margins.at(3).toReal();
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+QVariant QPdfPrintEngine::property(PrintEnginePropertyKey key) const
+{
+ Q_D(const QPdfPrintEngine);
+
+ QVariant ret;
+ switch (int(key)) {
+ case PPK_CollateCopies:
+ ret = d->collate;
+ break;
+ case PPK_ColorMode:
+ ret = d->grayscale ? QPrinter::GrayScale : QPrinter::Color;
+ break;
+ case PPK_Creator:
+ ret = d->creator;
+ break;
+ case PPK_DocumentName:
+ ret = d->title;
+ break;
+ case PPK_FullPage:
+ ret = d->fullPage;
+ break;
+ case PPK_CopyCount:
+ ret = d->copies;
+ break;
+ case PPK_SupportsMultipleCopies:
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (QCUPSSupport::isAvailable())
+ ret = true;
+ else
+#endif
+ ret = false;
+ break;
+ case PPK_NumberOfCopies:
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (QCUPSSupport::isAvailable())
+ ret = 1;
+ else
+#endif
+ ret = d->copies;
+ break;
+ case PPK_Orientation:
+ ret = d->landscape ? QPrinter::Landscape : QPrinter::Portrait;
+ break;
+ case PPK_OutputFileName:
+ ret = d->outputFileName;
+ break;
+ case PPK_PageOrder:
+ ret = d->pageOrder;
+ break;
+ case PPK_PaperSize:
+ ret = d->paperSize;
+ break;
+ case PPK_PaperSource:
+ ret = d->paperSource;
+ break;
+ case PPK_PrinterName:
+ ret = d->printerName;
+ break;
+ case PPK_PrinterProgram:
+ ret = d->printProgram;
+ break;
+ case PPK_Resolution:
+ ret = d->resolution;
+ break;
+ case PPK_SupportedResolutions:
+ ret = QList<QVariant>() << 72;
+ break;
+ case PPK_PaperRect:
+ ret = d->paperRect();
+ break;
+ case PPK_PageRect:
+ ret = d->pageRect();
+ break;
+ case PPK_SelectionOption:
+ ret = d->selectionOption;
+ break;
+ case PPK_FontEmbedding:
+ ret = d->embedFonts;
+ break;
+ case PPK_Duplex:
+ ret = d->duplex;
+ break;
+ case PPK_CupsPageRect:
+ ret = d->cupsPageRect;
+ break;
+ case PPK_CupsPaperRect:
+ ret = d->cupsPaperRect;
+ break;
+ case PPK_CupsOptions:
+ ret = d->cupsOptions;
+ break;
+ case PPK_CupsStringPageSize:
+ ret = d->cupsStringPageSize;
+ break;
+ case PPK_CustomPaperSize:
+ ret = d->customPaperSize;
+ break;
+ case PPK_PageMargins:
+ {
+ QList<QVariant> margins;
+ margins << d->leftMargin << d->topMargin
+ << d->rightMargin << d->bottomMargin;
+ ret = margins;
+ break;
+ }
+ default:
+ break;
+ }
+ return ret;
+}
+
+
+#ifndef QT_NO_LPR
+static void closeAllOpenFds()
+{
+ // hack time... getting the maximum number of open
+ // files, if possible. if not we assume it's the
+ // larger of 256 and the fd we got
+ int i;
+#if defined(_SC_OPEN_MAX)
+ i = (int)sysconf(_SC_OPEN_MAX);
+#elif defined(_POSIX_OPEN_MAX)
+ i = (int)_POSIX_OPEN_MAX;
+#elif defined(OPEN_MAX)
+ i = (int)OPEN_MAX;
+#else
+ i = 256;
+#endif
+ // leave stdin/out/err untouched
+ while(--i > 2)
+ QT_CLOSE(i);
+}
+#endif
+
+bool QPdfPrintEnginePrivate::openPrintDevice()
+{
+ if (outDevice)
+ return false;
+
+ if (!outputFileName.isEmpty()) {
+ QFile *file = new QFile(outputFileName);
+ if (! file->open(QFile::WriteOnly|QFile::Truncate)) {
+ delete file;
+ return false;
+ }
+ outDevice = file;
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ } else if (QCUPSSupport::isAvailable()) {
+ QCUPSSupport cups;
+ QPair<int, QString> ret = cups.tempFd();
+ if (ret.first < 0) {
+ qWarning("QPdfPrinter: Could not open temporary file to print");
+ return false;
+ }
+ cupsTempFile = ret.second;
+ outDevice = new QFile();
+ static_cast<QFile *>(outDevice)->open(ret.first, QIODevice::WriteOnly);
+#endif
+#ifndef QT_NO_LPR
+ } else {
+ QString pr;
+ if (!printerName.isEmpty())
+ pr = printerName;
+ int fds[2];
+ if (qt_safe_pipe(fds) != 0) {
+ qWarning("QPdfPrinter: Could not open pipe to print");
+ return false;
+ }
+
+ pid_t pid = fork();
+ if (pid == 0) { // child process
+ // if possible, exit quickly, so the actual lp/lpr
+ // becomes a child of init, and ::waitpid() is
+ // guaranteed not to wait.
+ if (fork() > 0) {
+ closeAllOpenFds();
+
+ // try to replace this process with "true" - this prevents
+ // global destructors from being called (that could possibly
+ // do wrong things to the parent process)
+ (void)execlp("true", "true", (char *)0);
+ (void)execl("/bin/true", "true", (char *)0);
+ (void)execl("/usr/bin/true", "true", (char *)0);
+ ::_exit(0);
+ }
+ qt_safe_dup2(fds[0], 0, 0);
+
+ closeAllOpenFds();
+
+ if (!printProgram.isEmpty()) {
+ if (!selectionOption.isEmpty())
+ pr.prepend(selectionOption);
+ else
+ pr.prepend(QLatin1String("-P"));
+ (void)execlp(printProgram.toLocal8Bit().data(), printProgram.toLocal8Bit().data(),
+ pr.toLocal8Bit().data(), (char *)0);
+ } else {
+ // if no print program has been specified, be smart
+ // about the option string too.
+ QList<QByteArray> lprhack;
+ QList<QByteArray> lphack;
+ QByteArray media;
+ if (!pr.isEmpty() || !selectionOption.isEmpty()) {
+ if (!selectionOption.isEmpty()) {
+ QStringList list = selectionOption.split(QLatin1Char(' '));
+ for (int i = 0; i < list.size(); ++i)
+ lprhack.append(list.at(i).toLocal8Bit());
+ lphack = lprhack;
+ } else {
+ lprhack.append("-P");
+ lphack.append("-d");
+ }
+ lprhack.append(pr.toLocal8Bit());
+ lphack.append(pr.toLocal8Bit());
+ }
+ lphack.append("-s");
+
+ char ** lpargs = new char *[lphack.size()+6];
+ char lp[] = "lp";
+ lpargs[0] = lp;
+ int i;
+ for (i = 0; i < lphack.size(); ++i)
+ lpargs[i+1] = (char *)lphack.at(i).constData();
+#ifndef Q_OS_OSF
+ if (QPdf::paperSizeToString(printerPaperSize)) {
+ char dash_o[] = "-o";
+ lpargs[++i] = dash_o;
+ lpargs[++i] = const_cast<char *>(QPdf::paperSizeToString(printerPaperSize));
+ lpargs[++i] = dash_o;
+ media = "media=";
+ media += QPdf::paperSizeToString(printerPaperSize);
+ lpargs[++i] = media.data();
+ }
+#endif
+ lpargs[++i] = 0;
+ char **lprargs = new char *[lprhack.size()+2];
+ char lpr[] = "lpr";
+ lprargs[0] = lpr;
+ for (int i = 0; i < lprhack.size(); ++i)
+ lprargs[i+1] = (char *)lprhack[i].constData();
+ lprargs[lprhack.size() + 1] = 0;
+ (void)execvp("lp", lpargs);
+ (void)execvp("lpr", lprargs);
+ (void)execv("/bin/lp", lpargs);
+ (void)execv("/bin/lpr", lprargs);
+ (void)execv("/usr/bin/lp", lpargs);
+ (void)execv("/usr/bin/lpr", lprargs);
+
+ delete []lpargs;
+ delete []lprargs;
+ }
+ // if we couldn't exec anything, close the fd,
+ // wait for a second so the parent process (the
+ // child of the GUI process) has exited. then
+ // exit.
+ QT_CLOSE(0);
+ (void)::sleep(1);
+ ::_exit(0);
+ }
+ // parent process
+ QT_CLOSE(fds[0]);
+ fd = fds[1];
+ (void)qt_safe_waitpid(pid, 0, 0);
+
+ if (fd < 0)
+ return false;
+
+ outDevice = new QFile();
+ static_cast<QFile *>(outDevice)->open(fd, QIODevice::WriteOnly);
+#endif
+ }
+
+ return true;
+}
+
+void QPdfPrintEnginePrivate::closePrintDevice()
+{
+ if (outDevice) {
+ outDevice->close();
+ if (fd >= 0)
+ #if defined(Q_OS_WIN) && defined(_MSC_VER) && _MSC_VER >= 1400
+ ::_close(fd);
+ #else
+ ::close(fd);
+ #endif
+ fd = -1;
+ delete outDevice;
+ outDevice = 0;
+ }
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (!cupsTempFile.isEmpty()) {
+ QString tempFile = cupsTempFile;
+ cupsTempFile.clear();
+ QCUPSSupport cups;
+
+ // Set up print options.
+ QByteArray prnName;
+ QList<QPair<QByteArray, QByteArray> > options;
+ QVector<cups_option_t> cupsOptStruct;
+
+ if (!printerName.isEmpty()) {
+ prnName = printerName.toLocal8Bit();
+ } else {
+ QPrinterInfo def = QPrinterInfo::defaultPrinter();
+ if (def.isNull()) {
+ qWarning("Could not determine printer to print to");
+ QFile::remove(tempFile);
+ return;
+ }
+ prnName = def.printerName().toLocal8Bit();
+ }
+
+ if (!cupsStringPageSize.isEmpty()) {
+ options.append(QPair<QByteArray, QByteArray>("media", cupsStringPageSize.toLocal8Bit()));
+ }
+
+ if (copies > 1) {
+ options.append(QPair<QByteArray, QByteArray>("copies", QString::number(copies).toLocal8Bit()));
+ }
+
+ if (collate) {
+ options.append(QPair<QByteArray, QByteArray>("Collate", "True"));
+ }
+
+ if (duplex != QPrinter::DuplexNone) {
+ switch(duplex) {
+ case QPrinter::DuplexNone: break;
+ case QPrinter::DuplexAuto:
+ if (!landscape)
+ options.append(QPair<QByteArray, QByteArray>("sides", "two-sided-long-edge"));
+ else
+ options.append(QPair<QByteArray, QByteArray>("sides", "two-sided-short-edge"));
+ break;
+ case QPrinter::DuplexLongSide:
+ options.append(QPair<QByteArray, QByteArray>("sides", "two-sided-long-edge"));
+ break;
+ case QPrinter::DuplexShortSide:
+ options.append(QPair<QByteArray, QByteArray>("sides", "two-sided-short-edge"));
+ break;
+ }
+ }
+
+ if (QCUPSSupport::cupsVersion() >= 10300 && landscape) {
+ options.append(QPair<QByteArray, QByteArray>("landscape", ""));
+ }
+
+ QStringList::const_iterator it = cupsOptions.constBegin();
+ while (it != cupsOptions.constEnd()) {
+ options.append(QPair<QByteArray, QByteArray>((*it).toLocal8Bit(), (*(it+1)).toLocal8Bit()));
+ it += 2;
+ }
+
+ for (int c = 0; c < options.size(); ++c) {
+ cups_option_t opt;
+ opt.name = options[c].first.data();
+ opt.value = options[c].second.data();
+ cupsOptStruct.append(opt);
+ }
+
+ // Print the file.
+ cups_option_t* optPtr = cupsOptStruct.size() ? &cupsOptStruct.first() : 0;
+ cups.printFile(prnName.constData(), tempFile.toLocal8Bit().constData(),
+ title.toLocal8Bit().constData(), cupsOptStruct.size(), optPtr);
+
+ QFile::remove(tempFile);
+ }
+#endif
+}
+
+
+
+QPdfPrintEnginePrivate::QPdfPrintEnginePrivate(QPrinter::PrinterMode m)
+ : QPdfEnginePrivate(),
+ duplex(QPrinter::DuplexNone),
+ collate(false),
+ copies(1),
+ pageOrder(QPrinter::FirstPageFirst),
+ paperSource(QPrinter::Auto),
+ printerPaperSize(QPrinter::A4),
+ fd(-1)
+{
+ resolution = 72;
+ if (m == QPrinter::HighResolution)
+ resolution = 1200;
+ else if (m == QPrinter::ScreenResolution)
+ resolution = qt_defaultDpi();
+}
+
+QPdfPrintEnginePrivate::~QPdfPrintEnginePrivate()
+{
+}
+
+
+void QPdfPrintEnginePrivate::updatePaperSize()
+{
+ if (printerPaperSize == QPrinter::Custom) {
+ paperSize = customPaperSize;
+ } else if (!cupsPaperRect.isNull()) {
+ QRect r = cupsPaperRect;
+ paperSize = r.size();
+ } else{
+ QPdf::PaperSize s = QPdf::paperSize(printerPaperSize);
+ paperSize = QSize(s.width, s.height);
+ }
+}
+
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprintengine_pdf_p.h b/src/printsupport/kernel/qprintengine_pdf_p.h
new file mode 100644
index 0000000000..e27adda7b3
--- /dev/null
+++ b/src/printsupport/kernel/qprintengine_pdf_p.h
@@ -0,0 +1,165 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTENGINE_PDF_P_H
+#define QPRINTENGINE_PDF_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtPrintSupport/qprintengine.h"
+
+#ifndef QT_NO_PRINTER
+#include "QtCore/qmap.h"
+#include "QtGui/qmatrix.h"
+#include "QtCore/qstring.h"
+#include "QtCore/qvector.h"
+#include "QtGui/qpaintengine.h"
+#include "QtGui/qpainterpath.h"
+#include "QtCore/qdatastream.h"
+
+#include "private/qfontengine_p.h"
+#include "private/qpdf_p.h"
+#include "private/qpaintengine_p.h"
+#include "qprintengine.h"
+
+QT_BEGIN_NAMESPACE
+
+class QImage;
+class QDataStream;
+class QPen;
+class QPointF;
+class QRegion;
+class QFile;
+class QPdfPrintEngine;
+
+#define PPK_CupsOptions QPrintEngine::PrintEnginePropertyKey(0xfe00)
+#define PPK_CupsPageRect QPrintEngine::PrintEnginePropertyKey(0xfe01)
+#define PPK_CupsPaperRect QPrintEngine::PrintEnginePropertyKey(0xfe02)
+#define PPK_CupsStringPageSize QPrintEngine::PrintEnginePropertyKey(0xfe03)
+
+namespace QPdf {
+
+ struct PaperSize {
+ int width, height; // in postscript points
+ };
+ Q_GUI_EXPORT PaperSize paperSize(QPrinter::PaperSize paperSize);
+ Q_GUI_EXPORT const char *paperSizeToString(QPrinter::PaperSize paperSize);
+}
+
+class QPdfPrintEnginePrivate;
+
+class QPdfPrintEngine : public QPdfEngine, public QPrintEngine
+{
+ Q_DECLARE_PRIVATE(QPdfPrintEngine)
+public:
+ QPdfPrintEngine(QPrinter::PrinterMode m);
+ virtual ~QPdfPrintEngine();
+
+ // reimplementations QPaintEngine
+ bool begin(QPaintDevice *pdev);
+ bool end();
+ // end reimplementations QPaintEngine
+
+ // reimplementations QPrintEngine
+ bool abort() {return false;}
+ QPrinter::PrinterState printerState() const {return state;}
+
+ bool newPage();
+ int metric(QPaintDevice::PaintDeviceMetric) const;
+ void setProperty(PrintEnginePropertyKey key, const QVariant &value);
+ QVariant property(PrintEnginePropertyKey key) const;
+ // end reimplementations QPrintEngine
+
+ QPrinter::PrinterState state;
+
+private:
+ Q_DISABLE_COPY(QPdfPrintEngine)
+};
+
+class QPdfPrintEnginePrivate : public QPdfEnginePrivate
+{
+ Q_DECLARE_PUBLIC(QPdfPrintEngine)
+public:
+ QPdfPrintEnginePrivate(QPrinter::PrinterMode m);
+ ~QPdfPrintEnginePrivate();
+
+ bool openPrintDevice();
+ void closePrintDevice();
+
+ void updatePaperSize();
+
+private:
+ Q_DISABLE_COPY(QPdfPrintEnginePrivate)
+
+ QString printerName;
+ QString printProgram;
+ QString selectionOption;
+ QStringList cupsOptions;
+ QString cupsStringPageSize;
+
+ QPrinter::DuplexMode duplex;
+ bool collate;
+ int copies;
+ QPrinter::PageOrder pageOrder;
+ QPrinter::PaperSource paperSource;
+
+ QPrinter::PaperSize printerPaperSize;
+ QRect cupsPaperRect;
+ QRect cupsPageRect;
+ QSizeF customPaperSize; // in postscript points
+
+ int fd;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
+
+#endif // QPRINTENGINE_PDF_P_H
diff --git a/src/printsupport/kernel/qprinter.cpp b/src/printsupport/kernel/qprinter.cpp
new file mode 100644
index 0000000000..72522b38c1
--- /dev/null
+++ b/src/printsupport/kernel/qprinter.cpp
@@ -0,0 +1,2254 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qprinter_p.h"
+#include "qprinter.h"
+#include "qprintengine.h"
+#include "qprinterinfo.h"
+#include "qlist.h"
+#include <qcoreapplication.h>
+#include <qfileinfo.h>
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+#include "private/qcups_p.h"
+#endif
+
+#ifndef QT_NO_PRINTER
+
+#include <private/qguiapplication_p.h>
+#include <QtPrintSupport/QPlatformPrinterSupport>
+
+#if defined (Q_WS_WIN)
+#include <private/qprintengine_win_p.h>
+#elif defined (Q_WS_MAC)
+#include <private/qprintengine_mac_p.h>
+#elif defined (QTOPIA_PRINTENGINE)
+#include <private/qprintengine_qws_p.h>
+#endif
+
+#if defined(Q_WS_X11)
+#include <private/qt_x11_p.h>
+#endif
+
+#ifndef QT_NO_PDF
+#include "qprintengine_pdf_p.h"
+#endif
+
+#include <qpicture.h>
+#include <private/qpaintengine_preview_p.h>
+
+QT_BEGIN_NAMESPACE
+
+#define ABORT_IF_ACTIVE(location) \
+ if (d->printEngine->printerState() == QPrinter::Active) { \
+ qWarning("%s: Cannot be changed while printer is active", location); \
+ return; \
+ }
+
+// NB! This table needs to be in sync with QPrinter::PaperSize
+static const float qt_paperSizes[][2] = {
+ {210, 297}, // A4
+ {176, 250}, // B5
+ {215.9f, 279.4f}, // Letter
+ {215.9f, 355.6f}, // Legal
+ {190.5f, 254}, // Executive
+ {841, 1189}, // A0
+ {594, 841}, // A1
+ {420, 594}, // A2
+ {297, 420}, // A3
+ {148, 210}, // A5
+ {105, 148}, // A6
+ {74, 105}, // A7
+ {52, 74}, // A8
+ {37, 52}, // A8
+ {1000, 1414}, // B0
+ {707, 1000}, // B1
+ {31, 44}, // B10
+ {500, 707}, // B2
+ {353, 500}, // B3
+ {250, 353}, // B4
+ {125, 176}, // B6
+ {88, 125}, // B7
+ {62, 88}, // B8
+ {33, 62}, // B9
+ {163, 229}, // C5E
+ {105, 241}, // US Common
+ {110, 220}, // DLE
+ {210, 330}, // Folio
+ {431.8f, 279.4f}, // Ledger
+ {279.4f, 431.8f} // Tabloid
+};
+
+/// return the multiplier of converting from the unit value to postscript-points.
+Q_GUI_EXPORT double qt_multiplierForUnit(QPrinter::Unit unit, int resolution)
+{
+ switch(unit) {
+ case QPrinter::Millimeter:
+ return 2.83464566929;
+ case QPrinter::Point:
+ return 1.0;
+ case QPrinter::Inch:
+ return 72.0;
+ case QPrinter::Pica:
+ return 12;
+ case QPrinter::Didot:
+ return 1.065826771;
+ case QPrinter::Cicero:
+ return 12.789921252;
+ case QPrinter::DevicePixel:
+ return 72.0/resolution;
+ }
+ return 1.0;
+}
+
+// not static: it's needed in qpagesetupdialog_unix.cpp
+Q_GUI_EXPORT QSizeF qt_printerPaperSize(QPrinter::Orientation orientation,
+ QPrinter::PaperSize paperSize,
+ QPrinter::Unit unit,
+ int resolution)
+{
+ int width_index = 0;
+ int height_index = 1;
+ if (orientation == QPrinter::Landscape) {
+ width_index = 1;
+ height_index = 0;
+ }
+ const qreal multiplier = qt_multiplierForUnit(unit, resolution);
+ return QSizeF((qt_paperSizes[paperSize][width_index] * 72 / 25.4) / multiplier,
+ (qt_paperSizes[paperSize][height_index] * 72 / 25.4) / multiplier);
+}
+
+void QPrinterPrivate::createDefaultEngines()
+{
+ QPrinter::OutputFormat realOutputFormat = outputFormat;
+#if !defined (QTOPIA_PRINTENGINE)
+#if defined (Q_OS_UNIX) && ! defined (Q_WS_MAC)
+ if(outputFormat == QPrinter::NativeFormat) {
+ realOutputFormat = QPrinter::PdfFormat;
+ }
+#endif
+#endif
+
+ switch (realOutputFormat) {
+ case QPrinter::NativeFormat: {
+#if defined (Q_WS_QPA)
+ printEngine = QGuiApplicationPrivate::platformIntegration()->printerSupport()->createNativePrintEngine(printerMode);
+ paintEngine = QGuiApplicationPrivate::platformIntegration()->printerSupport()->createPaintEngine(printEngine, printerMode);
+#elif defined (Q_WS_WIN)
+ QWin32PrintEngine *winEngine = new QWin32PrintEngine(printerMode);
+ paintEngine = winEngine;
+ printEngine = winEngine;
+#elif defined (Q_WS_MAC)
+ QMacPrintEngine *macEngine = new QMacPrintEngine(printerMode);
+ paintEngine = macEngine;
+ printEngine = macEngine;
+#elif defined (QTOPIA_PRINTENGINE)
+ QtopiaPrintEngine *qwsEngine = new QtopiaPrintEngine(printerMode);
+ paintEngine = qwsEngine;
+ printEngine = qwsEngine;
+#elif defined (Q_OS_UNIX)
+ Q_ASSERT(false);
+#endif
+ }
+ break;
+ case QPrinter::PdfFormat: {
+ QPdfPrintEngine *pdfEngine = new QPdfPrintEngine(printerMode);
+ paintEngine = pdfEngine;
+ printEngine = pdfEngine;
+ }
+ break;
+ }
+ use_default_engine = true;
+ had_default_engines = true;
+}
+
+#ifndef QT_NO_PRINTPREVIEWWIDGET
+QList<const QPicture *> QPrinterPrivate::previewPages() const
+{
+ if (previewEngine)
+ return previewEngine->pages();
+ return QList<const QPicture *>();
+}
+
+void QPrinterPrivate::setPreviewMode(bool enable)
+{
+ Q_Q(QPrinter);
+ if (enable) {
+ if (!previewEngine)
+ previewEngine = new QPreviewPaintEngine;
+ had_default_engines = use_default_engine;
+ use_default_engine = false;
+ realPrintEngine = printEngine;
+ realPaintEngine = paintEngine;
+ q->setEngines(previewEngine, previewEngine);
+ previewEngine->setProxyEngines(realPrintEngine, realPaintEngine);
+ } else {
+ q->setEngines(realPrintEngine, realPaintEngine);
+ use_default_engine = had_default_engines;
+ }
+}
+#endif // QT_NO_PRINTPREVIEWWIDGET
+
+void QPrinterPrivate::addToManualSetList(QPrintEngine::PrintEnginePropertyKey key)
+{
+ for (int c = 0; c < manualSetList.size(); ++c) {
+ if (manualSetList[c] == key) return;
+ }
+ manualSetList.append(key);
+}
+
+
+/*!
+ \class QPrinter
+ \reentrant
+
+ \brief The QPrinter class is a paint device that paints on a printer.
+
+ \ingroup printing
+
+
+ This device represents a series of pages of printed output, and is
+ used in almost exactly the same way as other paint devices such as
+ QWidget and QPixmap.
+ A set of additional functions are provided to manage device-specific
+ features, such as orientation and resolution, and to step through
+ the pages in a document as it is generated.
+
+ When printing directly to a printer on Windows or Mac OS X, QPrinter uses
+ the built-in printer drivers. On X11, QPrinter uses the
+ \l{Common Unix Printing System (CUPS)} or the standard Unix \l lpr utility
+ to send PDF output to the printer. As an alternative,
+ the printProgram() function can be used to specify the command or utility
+ to use instead of the system default.
+
+ Note that setting parameters like paper size and resolution on an
+ invalid printer is undefined. You can use QPrinter::isValid() to
+ verify this before changing any parameters.
+
+ QPrinter supports a number of parameters, most of which can be
+ changed by the end user through a \l{QPrintDialog}{print dialog}. In
+ general, QPrinter passes these functions onto the underlying QPrintEngine.
+
+ The most important parameters are:
+ \list
+ \i setOrientation() tells QPrinter which page orientation to use.
+ \i setPaperSize() tells QPrinter what paper size to expect from the
+ printer.
+ \i setResolution() tells QPrinter what resolution you wish the
+ printer to provide, in dots per inch (DPI).
+ \i setFullPage() tells QPrinter whether you want to deal with the
+ full page or just with the part the printer can draw on.
+ \i setCopyCount() tells QPrinter how many copies of the document
+ it should print.
+ \endlist
+
+ Many of these functions can only be called before the actual printing
+ begins (i.e., before QPainter::begin() is called). This usually makes
+ sense because, for example, it's not possible to change the number of
+ copies when you are halfway through printing. There are also some
+ settings that the user sets (through the printer dialog) and that
+ applications are expected to obey. See QAbstractPrintDialog's
+ documentation for more details.
+
+ When QPainter::begin() is called, the QPrinter it operates on is prepared for
+ a new page, enabling the QPainter to be used immediately to paint the first
+ page in a document. Once the first page has been painted, newPage() can be
+ called to request a new blank page to paint on, or QPainter::end() can be
+ called to finish printing. The second page and all following pages are
+ prepared using a call to newPage() before they are painted.
+
+ The first page in a document does not need to be preceded by a call to
+ newPage(). You only need to calling newPage() after QPainter::begin() if you
+ need to insert a blank page at the beginning of a printed document.
+ Similarly, calling newPage() after the last page in a document is painted will
+ result in a trailing blank page appended to the end of the printed document.
+
+ If you want to abort the print job, abort() will try its best to
+ stop printing. It may cancel the entire job or just part of it.
+
+ Since QPrinter can print to any QPrintEngine subclass, it is possible to
+ extend printing support to cover new types of printing subsystem by
+ subclassing QPrintEngine and reimplementing its interface.
+
+ \sa QPrintDialog, {Printing with Qt}
+*/
+
+/*!
+ \enum QPrinter::PrinterState
+
+ \value Idle
+ \value Active
+ \value Aborted
+ \value Error
+*/
+
+/*!
+ \enum QPrinter::PrinterMode
+
+ This enum describes the mode the printer should work in. It
+ basically presets a certain resolution and working mode.
+
+ \value ScreenResolution Sets the resolution of the print device to
+ the screen resolution. This has the big advantage that the results
+ obtained when painting on the printer will match more or less
+ exactly the visible output on the screen. It is the easiest to
+ use, as font metrics on the screen and on the printer are the
+ same. This is the default value. ScreenResolution will produce a
+ lower quality output than HighResolution and should only be used
+ for drafts.
+
+ \value PrinterResolution This value is deprecated. Is is
+ equivalent to ScreenResolution on Unix and HighResolution on
+ Windows and Mac. Due do the difference between ScreenResolution
+ and HighResolution, use of this value may lead to non-portable
+ printer code.
+
+ \value HighResolution On Windows, sets the printer resolution to that
+ defined for the printer in use. For PDF printing, sets the
+ resolution of the PDF driver to 1200 dpi.
+
+ \note When rendering text on a QPrinter device, it is important
+ to realize that the size of text, when specified in points, is
+ independent of the resolution specified for the device itself.
+ Therefore, it may be useful to specify the font size in pixels
+ when combining text with graphics to ensure that their relative
+ sizes are what you expect.
+*/
+
+/*!
+ \enum QPrinter::Orientation
+
+ This enum type (not to be confused with \c Orientation) is used
+ to specify each page's orientation.
+
+ \value Portrait the page's height is greater than its width.
+
+ \value Landscape the page's width is greater than its height.
+
+ This type interacts with \l QPrinter::PaperSize and
+ QPrinter::setFullPage() to determine the final size of the page
+ available to the application.
+*/
+
+
+/*!
+ \enum QPrinter::PrintRange
+
+ Used to specify the print range selection option.
+
+ \value AllPages All pages should be printed.
+ \value Selection Only the selection should be printed.
+ \value PageRange The specified page range should be printed.
+ \value CurrentPage Only the current page should be printed.
+
+ \sa QAbstractPrintDialog::PrintRange
+*/
+
+/*!
+ \enum QPrinter::PrinterOption
+ \compat
+
+ Use QAbstractPrintDialog::PrintDialogOption instead.
+
+ \value PrintToFile
+ \value PrintSelection
+ \value PrintPageRange
+*/
+
+/*!
+ \enum QPrinter::PaperSize
+ \since 4.4
+
+ This enum type specifies what paper size QPrinter should use.
+ QPrinter does not check that the paper size is available; it just
+ uses this information, together with QPrinter::Orientation and
+ QPrinter::setFullPage(), to determine the printable area.
+
+ The defined sizes (with setFullPage(true)) are:
+
+ \value A0 841 x 1189 mm
+ \value A1 594 x 841 mm
+ \value A2 420 x 594 mm
+ \value A3 297 x 420 mm
+ \value A4 210 x 297 mm, 8.26 x 11.69 inches
+ \value A5 148 x 210 mm
+ \value A6 105 x 148 mm
+ \value A7 74 x 105 mm
+ \value A8 52 x 74 mm
+ \value A9 37 x 52 mm
+ \value B0 1000 x 1414 mm
+ \value B1 707 x 1000 mm
+ \value B2 500 x 707 mm
+ \value B3 353 x 500 mm
+ \value B4 250 x 353 mm
+ \value B5 176 x 250 mm, 6.93 x 9.84 inches
+ \value B6 125 x 176 mm
+ \value B7 88 x 125 mm
+ \value B8 62 x 88 mm
+ \value B9 33 x 62 mm
+ \value B10 31 x 44 mm
+ \value C5E 163 x 229 mm
+ \value Comm10E 105 x 241 mm, U.S. Common 10 Envelope
+ \value DLE 110 x 220 mm
+ \value Executive 7.5 x 10 inches, 190.5 x 254 mm
+ \value Folio 210 x 330 mm
+ \value Ledger 431.8 x 279.4 mm
+ \value Legal 8.5 x 14 inches, 215.9 x 355.6 mm
+ \value Letter 8.5 x 11 inches, 215.9 x 279.4 mm
+ \value Tabloid 279.4 x 431.8 mm
+ \value Custom Unknown, or a user defined size.
+
+ With setFullPage(false) (the default), the metrics will be a bit
+ smaller; how much depends on the printer in use.
+
+ \omitvalue NPageSize
+ \omitvalue NPaperSize
+*/
+
+
+/*!
+ \enum QPrinter::PageOrder
+
+ This enum type is used by QPrinter to tell the application program
+ how to print.
+
+ \value FirstPageFirst the lowest-numbered page should be printed
+ first.
+
+ \value LastPageFirst the highest-numbered page should be printed
+ first.
+*/
+
+/*!
+ \enum QPrinter::ColorMode
+
+ This enum type is used to indicate whether QPrinter should print
+ in color or not.
+
+ \value Color print in color if available, otherwise in grayscale.
+
+ \value GrayScale print in grayscale, even on color printers.
+*/
+
+/*!
+ \enum QPrinter::PaperSource
+
+ This enum type specifies what paper source QPrinter is to use.
+ QPrinter does not check that the paper source is available; it
+ just uses this information to try and set the paper source.
+ Whether it will set the paper source depends on whether the
+ printer has that particular source.
+
+ \warning This is currently only implemented for Windows.
+
+ \value Auto
+ \value Cassette
+ \value Envelope
+ \value EnvelopeManual
+ \value FormSource
+ \value LargeCapacity
+ \value LargeFormat
+ \value Lower
+ \value MaxPageSource
+ \value Middle
+ \value Manual
+ \value OnlyOne
+ \value Tractor
+ \value SmallFormat
+*/
+
+/*!
+ \enum QPrinter::Unit
+ \since 4.4
+
+ This enum type is used to specify the measurement unit for page and
+ paper sizes.
+
+ \value Millimeter
+ \value Point
+ \value Inch
+ \value Pica
+ \value Didot
+ \value Cicero
+ \value DevicePixel
+
+ Note the difference between Point and DevicePixel. The Point unit is
+ defined to be 1/72th of an inch, while the DevicePixel unit is
+ resolution dependant and is based on the actual pixels, or dots, on
+ the printer.
+*/
+
+
+/*
+ \enum QPrinter::PrintRange
+
+ This enum is used to specify which print range the application
+ should use to print.
+
+ \value AllPages All the pages should be printed.
+ \value Selection Only the selection should be printed.
+ \value PageRange Print according to the from page and to page options.
+ \value CurrentPage Only the current page should be printed.
+
+ \sa setPrintRange(), printRange()
+*/
+
+/*
+ \enum QPrinter::PrinterOption
+
+ This enum describes various printer options that appear in the
+ printer setup dialog. It is used to enable and disable these
+ options in the setup dialog.
+
+ \value PrintToFile Describes if print to file should be enabled.
+ \value PrintSelection Describes if printing selections should be enabled.
+ \value PrintPageRange Describes if printing page ranges (from, to) should
+ be enabled
+ \value PrintCurrentPage if Print Current Page option should be enabled
+
+ \sa setOptionEnabled(), isOptionEnabled()
+*/
+
+/*!
+ Creates a new printer object with the given \a mode.
+*/
+QPrinter::QPrinter(PrinterMode mode)
+ : QPagedPaintDevice(),
+ d_ptr(new QPrinterPrivate(this))
+{
+ init(mode);
+ QPrinterInfo defPrn(QPrinterInfo::defaultPrinter());
+ if (!defPrn.isNull()) {
+ setPrinterName(defPrn.printerName());
+ } else if (QPrinterInfo::availablePrinters().isEmpty()
+ && d_ptr->paintEngine->type() != QPaintEngine::Windows
+ && d_ptr->paintEngine->type() != QPaintEngine::MacPrinter) {
+ setOutputFormat(QPrinter::PdfFormat);
+ }
+}
+
+/*!
+ \since 4.4
+
+ Creates a new printer object with the given \a printer and \a mode.
+*/
+QPrinter::QPrinter(const QPrinterInfo& printer, PrinterMode mode)
+ : QPagedPaintDevice(),
+ d_ptr(new QPrinterPrivate(this))
+{
+ init(mode);
+ setPrinterName(printer.printerName());
+}
+
+void QPrinter::init(PrinterMode mode)
+{
+#if !defined(Q_WS_X11)
+ if (!QCoreApplication::instance()) {
+#else
+ if (!QCoreApplication::instance() || !X11) {
+#endif
+ qFatal("QPrinter: Must construct a QApplication before a QPaintDevice");
+ return;
+ }
+ Q_D(QPrinter);
+
+ d->printerMode = mode;
+ d->outputFormat = QPrinter::NativeFormat;
+ d->createDefaultEngines();
+
+#ifndef QT_NO_PRINTPREVIEWWIDGET
+ d->previewEngine = 0;
+#endif
+ d->realPrintEngine = 0;
+ d->realPaintEngine = 0;
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (QCUPSSupport::cupsVersion() >= 10200 && QCUPSSupport().currentPPD()) {
+ setOutputFormat(QPrinter::PdfFormat);
+ d->outputFormat = QPrinter::NativeFormat;
+ }
+#endif
+}
+
+/*!
+ This function is used by subclasses of QPrinter to specify custom
+ print and paint engines (\a printEngine and \a paintEngine,
+ respectively).
+
+ QPrinter does not take ownership of the engines, so you need to
+ manage these engine instances yourself.
+
+ Note that changing the engines will reset the printer state and
+ all its properties.
+
+ \sa printEngine() paintEngine() setOutputFormat()
+
+ \since 4.1
+*/
+void QPrinter::setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine)
+{
+ Q_D(QPrinter);
+
+ if (d->use_default_engine)
+ delete d->printEngine;
+
+ d->printEngine = printEngine;
+ d->paintEngine = paintEngine;
+ d->use_default_engine = false;
+}
+
+/*!
+ Destroys the printer object and frees any allocated resources. If
+ the printer is destroyed while a print job is in progress this may
+ or may not affect the print job.
+*/
+QPrinter::~QPrinter()
+{
+ Q_D(QPrinter);
+ if (d->use_default_engine)
+ delete d->printEngine;
+#ifndef QT_NO_PRINTPREVIEWWIDGET
+ delete d->previewEngine;
+#endif
+}
+
+/*!
+ \enum QPrinter::OutputFormat
+
+ The OutputFormat enum is used to describe the format QPrinter should
+ use for printing.
+
+ \value NativeFormat QPrinter will print output using a method defined
+ by the platform it is running on. This mode is the default when printing
+ directly to a printer.
+
+ \value PdfFormat QPrinter will generate its output as a searchable PDF file.
+ This mode is the default when printing to a file.
+
+ \sa outputFormat(), setOutputFormat(), setOutputFileName()
+*/
+
+/*!
+ \since 4.1
+
+ Sets the output format for this printer to \a format.
+*/
+void QPrinter::setOutputFormat(OutputFormat format)
+{
+
+#ifndef QT_NO_PDF
+ Q_D(QPrinter);
+ if (d->validPrinter && d->outputFormat == format)
+ return;
+ d->outputFormat = format;
+
+ QPrintEngine *oldPrintEngine = d->printEngine;
+ const bool def_engine = d->use_default_engine;
+ d->printEngine = 0;
+
+ d->createDefaultEngines();
+
+ if (oldPrintEngine) {
+ for (int i = 0; i < d->manualSetList.size(); ++i) {
+ QPrintEngine::PrintEnginePropertyKey key = d->manualSetList[i];
+ QVariant prop;
+ // PPK_NumberOfCopies need special treatmeant since it in most cases
+ // will return 1, disregarding the actual value that was set
+ if (key == QPrintEngine::PPK_NumberOfCopies)
+ prop = QVariant(copyCount());
+ else
+ prop = oldPrintEngine->property(key);
+ if (prop.isValid())
+ d->printEngine->setProperty(key, prop);
+ }
+ }
+
+ if (def_engine)
+ delete oldPrintEngine;
+
+ if (d->outputFormat == QPrinter::PdfFormat)
+ d->validPrinter = true;
+#else
+ Q_UNUSED(format);
+#endif
+}
+
+/*!
+ \since 4.1
+
+ Returns the output format for this printer.
+*/
+QPrinter::OutputFormat QPrinter::outputFormat() const
+{
+ Q_D(const QPrinter);
+ return d->outputFormat;
+}
+
+
+
+/*! \internal
+*/
+int QPrinter::devType() const
+{
+ return QInternal::Printer;
+}
+
+/*!
+ Returns the printer name. This value is initially set to the name
+ of the default printer.
+
+ \sa setPrinterName()
+*/
+QString QPrinter::printerName() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_PrinterName).toString();
+}
+
+/*!
+ Sets the printer name to \a name.
+
+ \sa printerName(), isValid()
+*/
+void QPrinter::setPrinterName(const QString &name)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setPrinterName");
+
+#if defined(Q_OS_UNIX) && !defined(QT_NO_CUPS)
+ if(d->use_default_engine && d->outputFormat == QPrinter::NativeFormat) {
+ setOutputFormat(QPrinter::PdfFormat);
+ d->outputFormat = QPrinter::NativeFormat;
+ }
+#endif
+
+ QList<QPrinterInfo> prnList = QPrinterInfo::availablePrinters();
+ if (name.isEmpty()) {
+ d->validPrinter = d->outputFormat == QPrinter::PdfFormat;
+ } else {
+ d->validPrinter = false;
+ for (int i = 0; i < prnList.size(); ++i) {
+ if (prnList[i].printerName() == name) {
+ d->validPrinter = true;
+ break;
+ }
+ }
+ }
+
+ d->printEngine->setProperty(QPrintEngine::PPK_PrinterName, name);
+ d->addToManualSetList(QPrintEngine::PPK_PrinterName);
+}
+
+
+/*!
+ \since 4.4
+
+ Returns true if the printer currently selected is a valid printer
+ in the system, or a pure PDF printer; otherwise returns false.
+
+ To detect other failures check the output of QPainter::begin() or QPrinter::newPage().
+
+ \snippet doc/src/snippets/printing-qprinter/errors.cpp 0
+
+ \sa setPrinterName()
+*/
+bool QPrinter::isValid() const
+{
+ Q_D(const QPrinter);
+#if defined(Q_WS_X11)
+ if (!qApp || !X11) {
+ return false;
+ }
+#endif
+ return d->validPrinter;
+}
+
+
+/*!
+ \fn bool QPrinter::outputToFile() const
+
+ Returns true if the output should be written to a file, or false
+ if the output should be sent directly to the printer. The default
+ setting is false.
+
+ \sa setOutputToFile(), setOutputFileName()
+*/
+
+
+/*!
+ \fn void QPrinter::setOutputToFile(bool enable)
+
+ Specifies whether the output should be written to a file or sent
+ directly to the printer.
+
+ Will output to a file if \a enable is true, or will output
+ directly to the printer if \a enable is false.
+
+ \sa outputToFile(), setOutputFileName()
+*/
+
+
+/*!
+ \fn QString QPrinter::outputFileName() const
+
+ Returns the name of the output file. By default, this is an empty string
+ (indicating that the printer shouldn't print to file).
+
+ \sa QPrintEngine::PrintEnginePropertyKey
+
+*/
+
+QString QPrinter::outputFileName() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_OutputFileName).toString();
+}
+
+/*!
+ Sets the name of the output file to \a fileName.
+
+ Setting a null or empty name (0 or "") disables printing to a file.
+ Setting a non-empty name enables printing to a file.
+
+ This can change the value of outputFormat().
+ If the file name has the ".pdf" suffix PDF is generated. If the file name
+ has a suffix other than ".pdf", the output format used is the
+ one set with setOutputFormat().
+
+ QPrinter uses Qt's cross-platform PDF print engines
+ respectively. If you can produce this format natively, for example
+ Mac OS X can generate PDF's from its print engine, set the output format
+ back to NativeFormat.
+
+ \sa outputFileName() setOutputToFile() setOutputFormat()
+*/
+
+void QPrinter::setOutputFileName(const QString &fileName)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setOutputFileName");
+
+ QFileInfo fi(fileName);
+ if (!fi.suffix().compare(QLatin1String("pdf"), Qt::CaseInsensitive))
+ setOutputFormat(QPrinter::PdfFormat);
+ else if (fileName.isEmpty())
+ setOutputFormat(QPrinter::NativeFormat);
+
+ d->printEngine->setProperty(QPrintEngine::PPK_OutputFileName, fileName);
+ d->addToManualSetList(QPrintEngine::PPK_OutputFileName);
+}
+
+
+/*!
+ Returns the name of the program that sends the print output to the
+ printer.
+
+ The default is to return an empty string; meaning that QPrinter will try to
+ be smart in a system-dependent way. On X11 only, you can set it to something
+ different to use a specific print program. On the other platforms, this
+ returns an empty string.
+
+ \sa setPrintProgram(), setPrinterSelectionOption()
+*/
+QString QPrinter::printProgram() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_PrinterProgram).toString();
+}
+
+
+/*!
+ Sets the name of the program that should do the print job to \a
+ printProg.
+
+ On X11, this function sets the program to call with the PDF
+ output. On other platforms, it has no effect.
+
+ \sa printProgram()
+*/
+void QPrinter::setPrintProgram(const QString &printProg)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setPrintProgram");
+ d->printEngine->setProperty(QPrintEngine::PPK_PrinterProgram, printProg);
+ d->addToManualSetList(QPrintEngine::PPK_PrinterProgram);
+}
+
+
+/*!
+ Returns the document name.
+
+ \sa setDocName(), QPrintEngine::PrintEnginePropertyKey
+*/
+QString QPrinter::docName() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_DocumentName).toString();
+}
+
+
+/*!
+ Sets the document name to \a name.
+
+ On X11, the document name is for example used as the default
+ output filename in QPrintDialog. Note that the document name does
+ not affect the file name if the printer is printing to a file.
+ Use the setOutputFile() function for this.
+
+ \sa docName(), QPrintEngine::PrintEnginePropertyKey
+*/
+void QPrinter::setDocName(const QString &name)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setDocName");
+ d->printEngine->setProperty(QPrintEngine::PPK_DocumentName, name);
+ d->addToManualSetList(QPrintEngine::PPK_DocumentName);
+}
+
+
+/*!
+ Returns the name of the application that created the document.
+
+ \sa setCreator()
+*/
+QString QPrinter::creator() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_Creator).toString();
+}
+
+
+/*!
+ Sets the name of the application that created the document to \a
+ creator.
+
+ This function is only applicable to the X11 version of Qt. If no
+ creator name is specified, the creator will be set to "Qt"
+ followed by some version number.
+
+ \sa creator()
+*/
+void QPrinter::setCreator(const QString &creator)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setCreator");
+ d->printEngine->setProperty(QPrintEngine::PPK_Creator, creator);
+ d->addToManualSetList(QPrintEngine::PPK_Creator);
+}
+
+
+/*!
+ Returns the orientation setting. This is driver-dependent, but is usually
+ QPrinter::Portrait.
+
+ \sa setOrientation()
+*/
+QPrinter::Orientation QPrinter::orientation() const
+{
+ Q_D(const QPrinter);
+ return QPrinter::Orientation(d->printEngine->property(QPrintEngine::PPK_Orientation).toInt());
+}
+
+
+/*!
+ Sets the print orientation to \a orientation.
+
+ The orientation can be either QPrinter::Portrait or
+ QPrinter::Landscape.
+
+ The printer driver reads this setting and prints using the
+ specified orientation.
+
+ On Windows, this option can be changed while printing and will
+ take effect from the next call to newPage().
+
+ On Mac OS X, changing the orientation during a print job has no effect.
+
+ \sa orientation()
+*/
+
+void QPrinter::setOrientation(Orientation orientation)
+{
+ Q_D(QPrinter);
+ d->printEngine->setProperty(QPrintEngine::PPK_Orientation, orientation);
+ d->addToManualSetList(QPrintEngine::PPK_Orientation);
+}
+
+
+/*!
+ \since 4.4
+ Returns the printer paper size. The default value is driver-dependent.
+
+ \sa setPaperSize() pageRect() paperRect()
+*/
+
+QPrinter::PaperSize QPrinter::paperSize() const
+{
+ Q_D(const QPrinter);
+ return QPrinter::PaperSize(d->printEngine->property(QPrintEngine::PPK_PaperSize).toInt());
+}
+
+/*!
+ \since 4.4
+
+ Sets the printer paper size to \a newPaperSize if that size is
+ supported. The result is undefined if \a newPaperSize is not
+ supported.
+
+ The default paper size is driver-dependent.
+
+ This function is useful mostly for setting a default value that
+ the user can override in the print dialog.
+
+ \sa paperSize() PaperSize setFullPage() setResolution() pageRect() paperRect()
+*/
+void QPrinter::setPaperSize(PaperSize newPaperSize)
+{
+ setPageSize(newPaperSize);
+}
+
+/*!
+ \obsolete
+
+ Returns the printer page size. The default value is driver-dependent.
+
+ Use paperSize() instead.
+*/
+QPrinter::PageSize QPrinter::pageSize() const
+{
+ return paperSize();
+}
+
+
+/*!
+ \obsolete
+
+ Sets the printer page size based on \a newPageSize.
+
+ Use setPaperSize() instead.
+*/
+
+void QPrinter::setPageSize(PageSize newPageSize)
+{
+ QPagedPaintDevice::setPageSize(newPageSize);
+
+ Q_D(QPrinter);
+ if (d->paintEngine->type() != QPaintEngine::Pdf)
+ ABORT_IF_ACTIVE("QPrinter::setPaperSize");
+ if (newPageSize < 0 || newPageSize >= NPageSize) {
+ qWarning("QPrinter::setPaperSize: Illegal paper size %d", newPageSize);
+ return;
+ }
+ d->printEngine->setProperty(QPrintEngine::PPK_PaperSize, newPageSize);
+ d->addToManualSetList(QPrintEngine::PPK_PaperSize);
+ d->hasUserSetPageSize = true;
+}
+
+/*!
+ \since 4.4
+
+ Sets the paper size based on \a paperSize in \a unit.
+
+ \sa paperSize()
+*/
+
+void QPrinter::setPaperSize(const QSizeF &paperSize, QPrinter::Unit unit)
+{
+ Q_D(QPrinter);
+ if (d->paintEngine->type() != QPaintEngine::Pdf)
+ ABORT_IF_ACTIVE("QPrinter::setPaperSize");
+ const qreal multiplier = qt_multiplierForUnit(unit, resolution());
+ QSizeF size(paperSize.width() * multiplier * 25.4/72., paperSize.height() * multiplier * 25.4/72.);
+ setPageSizeMM(size);
+}
+
+/*!
+ \reimp
+ */
+void QPrinter::setPageSizeMM(const QSizeF &size)
+{
+ Q_D(QPrinter);
+
+ QPagedPaintDevice::setPageSizeMM(size);
+
+ QSizeF s = size * 72./25.4;
+ d->printEngine->setProperty(QPrintEngine::PPK_CustomPaperSize, s);
+ d->addToManualSetList(QPrintEngine::PPK_CustomPaperSize);
+ d->hasUserSetPageSize = true;
+}
+
+/*!
+ \since 4.4
+
+ Returns the paper size in \a unit.
+
+ \sa setPaperSize()
+*/
+
+QSizeF QPrinter::paperSize(Unit unit) const
+{
+ Q_D(const QPrinter);
+ int res = resolution();
+ const qreal multiplier = qt_multiplierForUnit(unit, res);
+ PaperSize paperType = paperSize();
+ if (paperType == Custom) {
+ QSizeF size = d->printEngine->property(QPrintEngine::PPK_CustomPaperSize).toSizeF();
+ return QSizeF(size.width() / multiplier, size.height() / multiplier);
+ }
+ else {
+ return qt_printerPaperSize(orientation(), paperType, unit, res);
+ }
+}
+
+/*!
+ Sets the page order to \a pageOrder.
+
+ The page order can be QPrinter::FirstPageFirst or
+ QPrinter::LastPageFirst. The application is responsible for
+ reading the page order and printing accordingly.
+
+ This function is mostly useful for setting a default value that
+ the user can override in the print dialog.
+
+ This function is only supported under X11.
+*/
+
+void QPrinter::setPageOrder(PageOrder pageOrder)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setPageOrder");
+ d->printEngine->setProperty(QPrintEngine::PPK_PageOrder, pageOrder);
+ d->addToManualSetList(QPrintEngine::PPK_PageOrder);
+}
+
+
+/*!
+ Returns the current page order.
+
+ The default page order is \c FirstPageFirst.
+*/
+
+QPrinter::PageOrder QPrinter::pageOrder() const
+{
+ Q_D(const QPrinter);
+ return QPrinter::PageOrder(d->printEngine->property(QPrintEngine::PPK_PageOrder).toInt());
+}
+
+
+/*!
+ Sets the printer's color mode to \a newColorMode, which can be
+ either \c Color or \c GrayScale.
+
+ \sa colorMode()
+*/
+
+void QPrinter::setColorMode(ColorMode newColorMode)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setColorMode");
+ d->printEngine->setProperty(QPrintEngine::PPK_ColorMode, newColorMode);
+ d->addToManualSetList(QPrintEngine::PPK_ColorMode);
+}
+
+
+/*!
+ Returns the current color mode.
+
+ \sa setColorMode()
+*/
+QPrinter::ColorMode QPrinter::colorMode() const
+{
+ Q_D(const QPrinter);
+ return QPrinter::ColorMode(d->printEngine->property(QPrintEngine::PPK_ColorMode).toInt());
+}
+
+
+/*!
+ \obsolete
+ Returns the number of copies to be printed. The default value is 1.
+
+ On Windows, Mac OS X and X11 systems that support CUPS, this will always
+ return 1 as these operating systems can internally handle the number
+ of copies.
+
+ On X11, this value will return the number of times the application is
+ required to print in order to match the number specified in the printer setup
+ dialog. This has been done since some printer drivers are not capable of
+ buffering up the copies and in those cases the application must make an
+ explicit call to the print code for each copy.
+
+ Use copyCount() in conjunction with supportsMultipleCopies() instead.
+
+ \sa setNumCopies(), actualNumCopies()
+*/
+
+int QPrinter::numCopies() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_NumberOfCopies).toInt();
+}
+
+
+/*!
+ \obsolete
+ \since 4.6
+
+ Returns the number of copies that will be printed. The default
+ value is 1.
+
+ This function always returns the actual value specified in the print
+ dialog or using setNumCopies().
+
+ Use copyCount() instead.
+
+ \sa setNumCopies(), numCopies()
+*/
+int QPrinter::actualNumCopies() const
+{
+ return copyCount();
+}
+
+
+
+/*!
+ \obsolete
+ Sets the number of copies to be printed to \a numCopies.
+
+ The printer driver reads this setting and prints the specified
+ number of copies.
+
+ Use setCopyCount() instead.
+
+ \sa numCopies()
+*/
+
+void QPrinter::setNumCopies(int numCopies)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setNumCopies");
+ d->printEngine->setProperty(QPrintEngine::PPK_NumberOfCopies, numCopies);
+ d->addToManualSetList(QPrintEngine::PPK_NumberOfCopies);
+}
+
+/*!
+ \since 4.7
+
+ Sets the number of copies to be printed to \a count.
+
+ The printer driver reads this setting and prints the specified number of
+ copies.
+
+ \sa copyCount(), supportsMultipleCopies()
+*/
+
+void QPrinter::setCopyCount(int count)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setCopyCount;");
+ d->printEngine->setProperty(QPrintEngine::PPK_CopyCount, count);
+ d->addToManualSetList(QPrintEngine::PPK_CopyCount);
+}
+
+/*!
+ \since 4.7
+
+ Returns the number of copies that will be printed. The default value is 1.
+
+ \sa setCopyCount(), supportsMultipleCopies()
+*/
+
+int QPrinter::copyCount() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_CopyCount).toInt();
+}
+
+/*!
+ \since 4.7
+
+ Returns true if the printer supports printing multiple copies of the same
+ document in one job; otherwise false is returned.
+
+ On most systems this function will return true. However, on X11 systems
+ that do not support CUPS, this function will return false. That means the
+ application has to handle the number of copies by printing the same
+ document the required number of times.
+
+ \sa setCopyCount(), copyCount()
+*/
+
+bool QPrinter::supportsMultipleCopies() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_SupportsMultipleCopies).toBool();
+}
+
+/*!
+ \since 4.1
+
+ Returns true if collation is turned on when multiple copies is selected.
+ Returns false if it is turned off when multiple copies is selected.
+ When collating is turned off the printing of each individual page will be repeated
+ the numCopies() amount before the next page is started. With collating turned on
+ all pages are printed before the next copy of those pages is started.
+
+ \sa setCollateCopies()
+*/
+bool QPrinter::collateCopies() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_CollateCopies).toBool();
+}
+
+
+/*!
+ \since 4.1
+
+ Sets the default value for collation checkbox when the print
+ dialog appears. If \a collate is true, it will enable
+ setCollateCopiesEnabled(). The default value is false. This value
+ will be changed by what the user presses in the print dialog.
+
+ \sa collateCopies()
+*/
+void QPrinter::setCollateCopies(bool collate)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setCollateCopies");
+ d->printEngine->setProperty(QPrintEngine::PPK_CollateCopies, collate);
+ d->addToManualSetList(QPrintEngine::PPK_CollateCopies);
+}
+
+
+
+/*!
+ If \a fp is true, enables support for painting over the entire page;
+ otherwise restricts painting to the printable area reported by the
+ device.
+
+ By default, full page printing is disabled. In this case, the origin
+ of the QPrinter's coordinate system coincides with the top-left
+ corner of the printable area.
+
+ If full page printing is enabled, the origin of the QPrinter's
+ coordinate system coincides with the top-left corner of the paper
+ itself. In this case, the
+ \l{QPaintDevice::PaintDeviceMetric}{device metrics} will report
+ the exact same dimensions as indicated by \l{PaperSize}. It may not
+ be possible to print on the entire physical page because of the
+ printer's margins, so the application must account for the margins
+ itself.
+
+ \sa fullPage(), setPaperSize(), width(), height(), {Printing with Qt}
+*/
+
+void QPrinter::setFullPage(bool fp)
+{
+ Q_D(QPrinter);
+ d->printEngine->setProperty(QPrintEngine::PPK_FullPage, fp);
+ d->addToManualSetList(QPrintEngine::PPK_FullPage);
+}
+
+
+/*!
+ Returns true if the origin of the printer's coordinate system is
+ at the corner of the page and false if it is at the edge of the
+ printable area.
+
+ See setFullPage() for details and caveats.
+
+ \sa setFullPage() PaperSize
+*/
+
+bool QPrinter::fullPage() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_FullPage).toBool();
+}
+
+
+/*!
+ Requests that the printer prints at \a dpi or as near to \a dpi as
+ possible.
+
+ This setting affects the coordinate system as returned by, for
+ example QPainter::viewport().
+
+ This function must be called before QPainter::begin() to have an effect on
+ all platforms.
+
+ \sa resolution() setPaperSize()
+*/
+
+void QPrinter::setResolution(int dpi)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setResolution");
+ d->printEngine->setProperty(QPrintEngine::PPK_Resolution, dpi);
+ d->addToManualSetList(QPrintEngine::PPK_Resolution);
+}
+
+
+/*!
+ Returns the current assumed resolution of the printer, as set by
+ setResolution() or by the printer driver.
+
+ \sa setResolution()
+*/
+
+int QPrinter::resolution() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_Resolution).toInt();
+}
+
+/*!
+ Sets the paper source setting to \a source.
+
+ Windows only: This option can be changed while printing and will
+ take effect from the next call to newPage()
+
+ \sa paperSource()
+*/
+
+void QPrinter::setPaperSource(PaperSource source)
+{
+ Q_D(QPrinter);
+ d->printEngine->setProperty(QPrintEngine::PPK_PaperSource, source);
+ d->addToManualSetList(QPrintEngine::PPK_PaperSource);
+}
+
+/*!
+ Returns the printer's paper source. This is \c Manual or a printer
+ tray or paper cassette.
+*/
+QPrinter::PaperSource QPrinter::paperSource() const
+{
+ Q_D(const QPrinter);
+ return QPrinter::PaperSource(d->printEngine->property(QPrintEngine::PPK_PaperSource).toInt());
+}
+
+
+/*!
+ \since 4.1
+
+ Enabled or disables font embedding depending on \a enable.
+
+ Currently this option is only supported on X11.
+
+ \sa fontEmbeddingEnabled()
+*/
+void QPrinter::setFontEmbeddingEnabled(bool enable)
+{
+ Q_D(QPrinter);
+ d->printEngine->setProperty(QPrintEngine::PPK_FontEmbedding, enable);
+ d->addToManualSetList(QPrintEngine::PPK_FontEmbedding);
+}
+
+/*!
+ \since 4.1
+
+ Returns true if font embedding is enabled.
+
+ Currently this option is only supported on X11.
+
+ \sa setFontEmbeddingEnabled()
+*/
+bool QPrinter::fontEmbeddingEnabled() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_FontEmbedding).toBool();
+}
+
+/*!
+ \enum QPrinter::DuplexMode
+ \since 4.4
+
+ This enum is used to indicate whether printing will occur on one or both sides
+ of each sheet of paper (simplex or duplex printing).
+
+ \value DuplexNone Single sided (simplex) printing only.
+ \value DuplexAuto The printer's default setting is used to determine whether
+ duplex printing is used.
+ \value DuplexLongSide Both sides of each sheet of paper are used for printing.
+ The paper is turned over its longest edge before the second
+ side is printed
+ \value DuplexShortSide Both sides of each sheet of paper are used for printing.
+ The paper is turned over its shortest edge before the second
+ side is printed
+*/
+
+/*!
+ \since 4.2
+
+ Enables double sided printing if \a doubleSided is true; otherwise disables it.
+
+ Currently this option is only supported on X11.
+*/
+void QPrinter::setDoubleSidedPrinting(bool doubleSided)
+{
+ setDuplex(doubleSided ? DuplexAuto : DuplexNone);
+}
+
+
+/*!
+ \since 4.2
+
+ Returns true if double side printing is enabled.
+
+ Currently this option is only supported on X11.
+*/
+bool QPrinter::doubleSidedPrinting() const
+{
+ return duplex() != DuplexNone;
+}
+
+/*!
+ \since 4.4
+
+ Enables double sided printing based on the \a duplex mode.
+
+ Currently this option is only supported on X11.
+*/
+void QPrinter::setDuplex(DuplexMode duplex)
+{
+ Q_D(QPrinter);
+ d->printEngine->setProperty(QPrintEngine::PPK_Duplex, duplex);
+ d->addToManualSetList(QPrintEngine::PPK_Duplex);
+}
+
+/*!
+ \since 4.4
+
+ Returns the current duplex mode.
+
+ Currently this option is only supported on X11.
+*/
+QPrinter::DuplexMode QPrinter::duplex() const
+{
+ Q_D(const QPrinter);
+ return static_cast <DuplexMode> (d->printEngine->property(QPrintEngine::PPK_Duplex).toInt());
+}
+
+/*!
+ \since 4.4
+
+ Returns the page's rectangle in \a unit; this is usually smaller
+ than the paperRect() since the page normally has margins between
+ its borders and the paper.
+
+ \sa paperSize()
+*/
+QRectF QPrinter::pageRect(Unit unit) const
+{
+ Q_D(const QPrinter);
+ int res = resolution();
+ const qreal multiplier = qt_multiplierForUnit(unit, res);
+ // the page rect is in device pixels
+ QRect devRect(d->printEngine->property(QPrintEngine::PPK_PageRect).toRect());
+ if (unit == DevicePixel)
+ return devRect;
+ QRectF diRect(devRect.x()*72.0/res,
+ devRect.y()*72.0/res,
+ devRect.width()*72.0/res,
+ devRect.height()*72.0/res);
+ return QRectF(diRect.x()/multiplier, diRect.y()/multiplier,
+ diRect.width()/multiplier, diRect.height()/multiplier);
+}
+
+
+/*!
+ \since 4.4
+
+ Returns the paper's rectangle in \a unit; this is usually larger
+ than the pageRect().
+
+ \sa pageRect()
+*/
+QRectF QPrinter::paperRect(Unit unit) const
+{
+ Q_D(const QPrinter);
+ int res = resolution();
+ const qreal multiplier = qt_multiplierForUnit(unit, resolution());
+ // the page rect is in device pixels
+ QRect devRect(d->printEngine->property(QPrintEngine::PPK_PaperRect).toRect());
+ if (unit == DevicePixel)
+ return devRect;
+ QRectF diRect(devRect.x()*72.0/res,
+ devRect.y()*72.0/res,
+ devRect.width()*72.0/res,
+ devRect.height()*72.0/res);
+ return QRectF(diRect.x()/multiplier, diRect.y()/multiplier,
+ diRect.width()/multiplier, diRect.height()/multiplier);
+}
+
+/*!
+ Returns the page's rectangle; this is usually smaller than the
+ paperRect() since the page normally has margins between its
+ borders and the paper.
+
+ The unit of the returned rectangle is DevicePixel.
+
+ \sa paperSize()
+*/
+QRect QPrinter::pageRect() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_PageRect).toRect();
+}
+
+/*!
+ Returns the paper's rectangle; this is usually larger than the
+ pageRect().
+
+ The unit of the returned rectangle is DevicePixel.
+
+ \sa pageRect()
+*/
+QRect QPrinter::paperRect() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_PaperRect).toRect();
+}
+
+
+/*!
+ \since 4.4
+
+ This function sets the \a left, \a top, \a right and \a bottom
+ page margins for this printer. The unit of the margins are
+ specified with the \a unit parameter.
+*/
+void QPrinter::setPageMargins(qreal left, qreal top, qreal right, qreal bottom, QPrinter::Unit unit)
+{
+ Q_D(QPrinter);
+ const qreal multiplier = qt_multiplierForUnit(unit, resolution());
+ QList<QVariant> margins;
+ margins << (left * multiplier) << (top * multiplier)
+ << (right * multiplier) << (bottom * multiplier);
+ d->printEngine->setProperty(QPrintEngine::PPK_PageMargins, margins);
+ d->addToManualSetList(QPrintEngine::PPK_PageMargins);
+ d->hasCustomPageMargins = true;
+}
+
+/*!
+ \since 4.4
+
+ Returns the page margins for this printer in \a left, \a top, \a
+ right, \a bottom. The unit of the returned margins are specified
+ with the \a unit parameter.
+*/
+void QPrinter::getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, QPrinter::Unit unit) const
+{
+ Q_D(const QPrinter);
+ Q_ASSERT(left && top && right && bottom);
+ const qreal multiplier = qt_multiplierForUnit(unit, resolution());
+ QList<QVariant> margins(d->printEngine->property(QPrintEngine::PPK_PageMargins).toList());
+ *left = margins.at(0).toReal() / multiplier;
+ *top = margins.at(1).toReal() / multiplier;
+ *right = margins.at(2).toReal() / multiplier;
+ *bottom = margins.at(3).toReal() / multiplier;
+}
+
+/*!
+ \internal
+
+ Returns the metric for the given \a id.
+*/
+int QPrinter::metric(PaintDeviceMetric id) const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->metric(id);
+}
+
+/*!
+ Returns the paint engine used by the printer.
+*/
+QPaintEngine *QPrinter::paintEngine() const
+{
+ Q_D(const QPrinter);
+ return d->paintEngine;
+}
+
+/*!
+ \since 4.1
+
+ Returns the print engine used by the printer.
+*/
+QPrintEngine *QPrinter::printEngine() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine;
+}
+
+#if defined (Q_WS_WIN)
+/*!
+ Sets the page size to be used by the printer under Windows to \a
+ pageSize.
+
+ \warning This function is not portable so you may prefer to use
+ setPaperSize() instead.
+
+ \sa winPageSize()
+*/
+void QPrinter::setWinPageSize(int pageSize)
+{
+ Q_D(QPrinter);
+ ABORT_IF_ACTIVE("QPrinter::setWinPageSize");
+ d->printEngine->setProperty(QPrintEngine::PPK_WindowsPageSize, pageSize);
+ d->addToManualSetList(QPrintEngine::PPK_WindowsPageSize);
+}
+
+/*!
+ Returns the page size used by the printer under Windows.
+
+ \warning This function is not portable so you may prefer to use
+ paperSize() instead.
+
+ \sa setWinPageSize()
+*/
+int QPrinter::winPageSize() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_WindowsPageSize).toInt();
+}
+#endif // Q_WS_WIN
+
+/*!
+ Returns a list of the resolutions (a list of dots-per-inch
+ integers) that the printer says it supports.
+
+ For X11 where all printing is directly to PDF, this
+ function will always return a one item list containing only the
+ PDF resolution, i.e., 72 (72 dpi -- but see PrinterMode).
+*/
+QList<int> QPrinter::supportedResolutions() const
+{
+ Q_D(const QPrinter);
+ QList<QVariant> varlist
+ = d->printEngine->property(QPrintEngine::PPK_SupportedResolutions).toList();
+ QList<int> intlist;
+ for (int i=0; i<varlist.size(); ++i)
+ intlist << varlist.at(i).toInt();
+ return intlist;
+}
+
+/*!
+ Tells the printer to eject the current page and to continue
+ printing on a new page. Returns true if this was successful;
+ otherwise returns false.
+
+ Calling newPage() on an inactive QPrinter object will always
+ fail.
+*/
+bool QPrinter::newPage()
+{
+ Q_D(QPrinter);
+ if (d->printEngine->printerState() != QPrinter::Active)
+ return false;
+ return d->printEngine->newPage();
+}
+
+/*!
+ Aborts the current print run. Returns true if the print run was
+ successfully aborted and printerState() will return QPrinter::Aborted; otherwise
+ returns false.
+
+ It is not always possible to abort a print job. For example,
+ all the data has gone to the printer but the printer cannot or
+ will not cancel the job when asked to.
+*/
+bool QPrinter::abort()
+{
+ Q_D(QPrinter);
+ return d->printEngine->abort();
+}
+
+/*!
+ Returns the current state of the printer. This may not always be
+ accurate (for example if the printer doesn't have the capability
+ of reporting its state to the operating system).
+*/
+QPrinter::PrinterState QPrinter::printerState() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->printerState();
+}
+
+
+/*! \fn void QPrinter::margins(uint *top, uint *left, uint *bottom, uint *right) const
+
+ Sets *\a top, *\a left, *\a bottom, *\a right to be the top,
+ left, bottom, and right margins.
+
+ This function has been superseded by paperRect() and pageRect().
+ Use paperRect().top() - pageRect().top() for the top margin,
+ paperRect().left() - pageRect().left() for the left margin,
+ paperRect().bottom() - pageRect().bottom() for the bottom margin,
+ and papaerRect().right() - pageRect().right() for the right
+ margin.
+
+ \oldcode
+ uint rightMargin;
+ uint bottomMargin;
+ printer->margins(0, 0, &bottomMargin, &rightMargin);
+ \newcode
+ int rightMargin = printer->paperRect().right() - printer->pageRect().right();
+ int bottomMargin = printer->paperRect().bottom() - printer->pageRect().bottom();
+ \endcode
+*/
+
+/*! \fn QSize QPrinter::margins() const
+
+ \overload
+
+ Returns a QSize containing the left margin and the top margin.
+
+ This function has been superseded by paperRect() and pageRect().
+ Use paperRect().left() - pageRect().left() for the left margin,
+ and paperRect().top() - pageRect().top() for the top margin.
+
+ \oldcode
+ QSize margins = printer->margins();
+ int leftMargin = margins.width();
+ int topMargin = margins.height();
+ \newcode
+ int leftMargin = printer->paperRect().left() - printer->pageRect().left();
+ int topMargin = printer->paperRect().top() - printer->pageRect().top();
+ \endcode
+*/
+
+/*! \fn bool QPrinter::aborted()
+
+ Use printerState() == QPrinter::Aborted instead.
+*/
+
+#ifdef Q_WS_WIN
+/*!
+ \internal
+*/
+HDC QPrinter::getDC() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->getPrinterDC();
+}
+
+/*!
+ \internal
+*/
+void QPrinter::releaseDC(HDC hdc) const
+{
+ Q_D(const QPrinter);
+ d->printEngine->releasePrinterDC(hdc);
+}
+
+/*!
+ Returns the supported paper sizes for this printer.
+
+ The values will be either a value that matches an entry in the
+ QPrinter::PaperSource enum or a driver spesific value. The driver
+ spesific values are greater than the constant DMBIN_USER declared
+ in wingdi.h.
+
+ \warning This function is only available in windows.
+*/
+
+QList<QPrinter::PaperSource> QPrinter::supportedPaperSources() const
+{
+ Q_D(const QPrinter);
+ QVariant v = d->printEngine->property(QPrintEngine::PPK_PaperSources);
+
+ QList<QVariant> variant_list = v.toList();
+ QList<QPrinter::PaperSource> int_list;
+ for (int i=0; i<variant_list.size(); ++i)
+ int_list << (QPrinter::PaperSource) variant_list.at(i).toInt();
+
+ return int_list;
+}
+
+#endif
+
+/*!
+ \fn QString QPrinter::printerSelectionOption() const
+
+ Returns the printer options selection string. This is useful only
+ if the print command has been explicitly set.
+
+ The default value (an empty string) implies that the printer should
+ be selected in a system-dependent manner.
+
+ Any other value implies that the given value should be used.
+
+ \warning This function is not available on Windows.
+
+ \sa setPrinterSelectionOption()
+*/
+
+/*!
+ \fn void QPrinter::setPrinterSelectionOption(const QString &option)
+
+ Sets the printer to use \a option to select the printer. \a option
+ is null by default (which implies that Qt should be smart enough
+ to guess correctly), but it can be set to other values to use a
+ specific printer selection option.
+
+ If the printer selection option is changed while the printer is
+ active, the current print job may or may not be affected.
+
+ \warning This function is not available on Windows.
+
+ \sa printerSelectionOption()
+*/
+
+#ifndef Q_WS_WIN
+QString QPrinter::printerSelectionOption() const
+{
+ Q_D(const QPrinter);
+ return d->printEngine->property(QPrintEngine::PPK_SelectionOption).toString();
+}
+
+void QPrinter::setPrinterSelectionOption(const QString &option)
+{
+ Q_D(QPrinter);
+ d->printEngine->setProperty(QPrintEngine::PPK_SelectionOption, option);
+ d->addToManualSetList(QPrintEngine::PPK_SelectionOption);
+}
+#endif
+
+/*!
+ \since 4.1
+ \fn int QPrinter::fromPage() const
+
+ Returns the number of the first page in a range of pages to be printed
+ (the "from page" setting). Pages in a document are numbered according to
+ the convention that the first page is page 1.
+
+ By default, this function returns a special value of 0, meaning that
+ the "from page" setting is unset.
+
+ \note If fromPage() and toPage() both return 0, this indicates that
+ \e{the whole document will be printed}.
+
+ \sa setFromTo(), toPage()
+*/
+
+int QPrinter::fromPage() const
+{
+ Q_D(const QPrinter);
+ return d->fromPage;
+}
+
+/*!
+ \since 4.1
+
+ Returns the number of the last page in a range of pages to be printed
+ (the "to page" setting). Pages in a document are numbered according to
+ the convention that the first page is page 1.
+
+ By default, this function returns a special value of 0, meaning that
+ the "to page" setting is unset.
+
+ \note If fromPage() and toPage() both return 0, this indicates that
+ \e{the whole document will be printed}.
+
+ The programmer is responsible for reading this setting and
+ printing accordingly.
+
+ \sa setFromTo(), fromPage()
+*/
+
+int QPrinter::toPage() const
+{
+ Q_D(const QPrinter);
+ return d->toPage;
+}
+
+/*!
+ \since 4.1
+
+ Sets the range of pages to be printed to cover the pages with numbers
+ specified by \a from and \a to, where \a from corresponds to the first
+ page in the range and \a to corresponds to the last.
+
+ \note Pages in a document are numbered according to the convention that
+ the first page is page 1. However, if \a from and \a to are both set to 0,
+ the \e{whole document will be printed}.
+
+ This function is mostly used to set a default value that the user can
+ override in the print dialog when you call setup().
+
+ \sa fromPage(), toPage()
+*/
+
+void QPrinter::setFromTo(int from, int to)
+{
+ Q_D(QPrinter);
+ if (from > to) {
+ qWarning() << "QPrinter::setFromTo: 'from' must be less than or equal to 'to'";
+ from = to;
+ }
+ d->fromPage = from;
+ d->toPage = to;
+
+ if (d->minPage == 0 && d->maxPage == 0) {
+ d->minPage = 1;
+ d->maxPage = to;
+ }
+}
+
+/*!
+ \since 4.1
+
+ Sets the print range option in to be \a range.
+*/
+void QPrinter::setPrintRange( PrintRange range )
+{
+ Q_D(QPrinter);
+ d->printRange = range;
+}
+
+/*!
+ \since 4.1
+
+ Returns the page range of the QPrinter. After the print setup
+ dialog has been opened, this function returns the value selected
+ by the user.
+
+ \sa setPrintRange()
+*/
+QPrinter::PrintRange QPrinter::printRange() const
+{
+ Q_D(const QPrinter);
+ return d->printRange;
+}
+
+
+/*!
+ \class QPrintEngine
+ \reentrant
+
+ \ingroup printing
+
+ \brief The QPrintEngine class defines an interface for how QPrinter
+ interacts with a given printing subsystem.
+
+ The common case when creating your own print engine is to derive from both
+ QPaintEngine and QPrintEngine. Various properties of a print engine are
+ given with property() and set with setProperty().
+
+ \sa QPaintEngine
+*/
+
+/*!
+ \enum QPrintEngine::PrintEnginePropertyKey
+
+ This enum is used to communicate properties between the print
+ engine and QPrinter. A property may or may not be supported by a
+ given print engine.
+
+ \value PPK_CollateCopies A boolean value indicating whether the
+ printout should be collated or not.
+
+ \value PPK_ColorMode Refers to QPrinter::ColorMode, either color or
+ monochrome.
+
+ \value PPK_Creator A string describing the document's creator.
+
+ \value PPK_Duplex A boolean value indicating whether both sides of
+ the printer paper should be used for the printout.
+
+ \value PPK_DocumentName A string describing the document name in
+ the spooler.
+
+ \value PPK_FontEmbedding A boolean value indicating whether data for
+ the document's fonts should be embedded in the data sent to the
+ printer.
+
+ \value PPK_FullPage A boolean describing if the printer should be
+ full page or not.
+
+ \value PPK_NumberOfCopies Obsolete. An integer specifying the number of
+ copies. Use PPK_CopyCount instead.
+
+ \value PPK_Orientation Specifies a QPrinter::Orientation value.
+
+ \value PPK_OutputFileName The output file name as a string. An
+ empty file name indicates that the printer should not print to a file.
+
+ \value PPK_PageOrder Specifies a QPrinter::PageOrder value.
+
+ \value PPK_PageRect A QRect specifying the page rectangle
+
+ \value PPK_PageSize Obsolete. Use PPK_PaperSize instead.
+
+ \value PPK_PaperRect A QRect specifying the paper rectangle.
+
+ \value PPK_PaperSource Specifies a QPrinter::PaperSource value.
+
+ \value PPK_PaperSources Specifies more than one QPrinter::PaperSource value.
+
+ \value PPK_PaperSize Specifies a QPrinter::PaperSize value.
+
+ \value PPK_PrinterName A string specifying the name of the printer.
+
+ \value PPK_PrinterProgram A string specifying the name of the
+ printer program used for printing,
+
+ \value PPK_Resolution An integer describing the dots per inch for
+ this printer.
+
+ \value PPK_SelectionOption
+
+ \value PPK_SupportedResolutions A list of integer QVariants
+ describing the set of supported resolutions that the printer has.
+
+ \value PPK_SuppressSystemPrintStatus Suppress the built-in dialog for showing
+ printing progress. As of 4.1 this only has effect on Mac OS X where, by default,
+ a status dialog is shown.
+
+ \value PPK_WindowsPageSize An integer specifying a DM_PAPER entry
+ on Windows.
+
+ \value PPK_CustomPaperSize A QSizeF specifying a custom paper size
+ in the QPrinter::Point unit.
+
+ \value PPK_PageMargins A QList<QVariant> containing the left, top,
+ right and bottom margin values.
+
+ \value PPK_CopyCount An integer specifying the number of copies to print.
+
+ \value PPK_SupportsMultipleCopies A boolean value indicating whether or not
+ the printer supports printing multiple copies in one job.
+
+ \value PPK_CustomBase Basis for extension.
+*/
+
+/*!
+ \fn QPrintEngine::~QPrintEngine()
+
+ Destroys the print engine.
+*/
+
+/*!
+ \fn void QPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &value)
+
+ Sets the print engine's property specified by \a key to the given \a value.
+
+ \sa property()
+*/
+
+/*!
+ \fn void QPrintEngine::property(PrintEnginePropertyKey key) const
+
+ Returns the print engine's property specified by \a key.
+
+ \sa setProperty()
+*/
+
+/*!
+ \fn bool QPrintEngine::newPage()
+
+ Instructs the print engine to start a new page. Returns true if
+ the printer was able to create the new page; otherwise returns false.
+*/
+
+/*!
+ \fn bool QPrintEngine::abort()
+
+ Instructs the print engine to abort the printing process. Returns
+ true if successful; otherwise returns false.
+*/
+
+/*!
+ \fn int QPrintEngine::metric(QPaintDevice::PaintDeviceMetric id) const
+
+ Returns the metric for the given \a id.
+*/
+
+/*!
+ \fn QPrinter::PrinterState QPrintEngine::printerState() const
+
+ Returns the current state of the printer being used by the print engine.
+*/
+
+/*!
+ \fn HDC QPrintEngine::getPrinterDC() const
+ \internal
+*/
+
+/*!
+ \fn void QPrintEngine::releasePrinterDC(HDC) const
+ \internal
+*/
+
+/*
+ Returns the dimensions for the given paper size, \a size, in millimeters.
+*/
+QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size)
+{
+ if (size == QPrinter::Custom) return QSizeF(0, 0);
+ return QSizeF(qt_paperSizes[size][0], qt_paperSizes[size][1]);
+}
+
+/*
+ Returns the PaperSize type that matches \a size, where \a size
+ is in millimeters.
+
+ Because dimensions may not always be completely accurate (for
+ example when converting between units), a particular PaperSize
+ will be returned if it matches within -1/+1 millimeters.
+*/
+QPrinter::PaperSize qSizeFTopaperSize(const QSizeF& size)
+{
+ for (int i = 0; i < static_cast<int>(QPrinter::NPageSize); ++i) {
+ if (qt_paperSizes[i][0] >= size.width() - 1 &&
+ qt_paperSizes[i][0] <= size.width() + 1 &&
+ qt_paperSizes[i][1] >= size.height() - 1 &&
+ qt_paperSizes[i][1] <= size.height() + 1) {
+ return QPrinter::PaperSize(i);
+ }
+ }
+
+ return QPrinter::Custom;
+}
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprinter.h b/src/printsupport/kernel/qprinter.h
new file mode 100644
index 0000000000..2f91c8b1e9
--- /dev/null
+++ b/src/printsupport/kernel/qprinter.h
@@ -0,0 +1,277 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTER_H
+#define QPRINTER_H
+
+#include <QtCore/qstring.h>
+#include <QtCore/qscopedpointer.h>
+#include <QtGui/qpagedpaintdevice.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_PRINTER
+
+#if defined(B0)
+#undef B0 // Terminal hang-up. We assume that you do not want that.
+#endif
+
+class QPrinterPrivate;
+class QPaintEngine;
+class QPrintEngine;
+class QPrinterInfo;
+
+class Q_GUI_EXPORT QPrinter : public QPagedPaintDevice
+{
+ Q_DECLARE_PRIVATE(QPrinter)
+public:
+ enum PrinterMode { ScreenResolution, PrinterResolution, HighResolution };
+
+ explicit QPrinter(PrinterMode mode = ScreenResolution);
+ explicit QPrinter(const QPrinterInfo& printer, PrinterMode mode = ScreenResolution);
+ ~QPrinter();
+
+ int devType() const;
+
+ enum Orientation { Portrait, Landscape };
+
+#ifndef Q_QDOC
+ typedef PageSize PaperSize;
+#else
+ enum PaperSize { A4, B5, Letter, Legal, Executive,
+ A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
+ B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
+ DLE, Folio, Ledger, Tabloid, Custom, NPageSize = Custom, NPaperSize = Custom };
+#endif
+
+ enum PageOrder { FirstPageFirst,
+ LastPageFirst };
+
+ enum ColorMode { GrayScale,
+ Color };
+
+ enum PaperSource { OnlyOne,
+ Lower,
+ Middle,
+ Manual,
+ Envelope,
+ EnvelopeManual,
+ Auto,
+ Tractor,
+ SmallFormat,
+ LargeFormat,
+ LargeCapacity,
+ Cassette,
+ FormSource,
+ MaxPageSource
+ };
+
+ enum PrinterState { Idle,
+ Active,
+ Aborted,
+ Error };
+
+ enum OutputFormat { NativeFormat, PdfFormat };
+
+ // Keep in sync with QAbstractPrintDialog::PrintRange
+ enum PrintRange { AllPages, Selection, PageRange, CurrentPage };
+
+ enum Unit {
+ Millimeter,
+ Point,
+ Inch,
+ Pica,
+ Didot,
+ Cicero,
+ DevicePixel
+ };
+
+ enum DuplexMode {
+ DuplexNone = 0,
+ DuplexAuto,
+ DuplexLongSide,
+ DuplexShortSide
+ };
+
+ void setOutputFormat(OutputFormat format);
+ OutputFormat outputFormat() const;
+
+ void setPrinterName(const QString &);
+ QString printerName() const;
+
+ bool isValid() const;
+
+ void setOutputFileName(const QString &);
+ QString outputFileName()const;
+
+ void setPrintProgram(const QString &);
+ QString printProgram() const;
+
+ void setDocName(const QString &);
+ QString docName() const;
+
+ void setCreator(const QString &);
+ QString creator() const;
+
+ void setOrientation(Orientation);
+ Orientation orientation() const;
+
+ void setPageSize(PageSize);
+ PageSize pageSize() const;
+
+ void setPageSizeMM(const QSizeF &size);
+
+ void setPaperSize(PaperSize);
+ PaperSize paperSize() const;
+
+ void setPaperSize(const QSizeF &paperSize, Unit unit);
+ QSizeF paperSize(Unit unit) const;
+
+ void setPageOrder(PageOrder);
+ PageOrder pageOrder() const;
+
+ void setResolution(int);
+ int resolution() const;
+
+ void setColorMode(ColorMode);
+ ColorMode colorMode() const;
+
+ void setCollateCopies(bool collate);
+ bool collateCopies() const;
+
+ void setFullPage(bool);
+ bool fullPage() const;
+
+ void setNumCopies(int);
+ int numCopies() const;
+
+ int actualNumCopies() const;
+
+ void setCopyCount(int);
+ int copyCount() const;
+ bool supportsMultipleCopies() const;
+
+ void setPaperSource(PaperSource);
+ PaperSource paperSource() const;
+
+ void setDuplex(DuplexMode duplex);
+ DuplexMode duplex() const;
+
+ QList<int> supportedResolutions() const;
+
+#ifdef Q_WS_WIN
+ QList<PaperSource> supportedPaperSources() const;
+#endif
+
+ void setFontEmbeddingEnabled(bool enable);
+ bool fontEmbeddingEnabled() const;
+
+ void setDoubleSidedPrinting(bool enable);
+ bool doubleSidedPrinting() const;
+
+#ifdef Q_WS_WIN
+ void setWinPageSize(int winPageSize);
+ int winPageSize() const;
+#endif
+
+ QRect paperRect() const;
+ QRect pageRect() const;
+ QRectF paperRect(Unit) const;
+ QRectF pageRect(Unit) const;
+
+#if !defined(Q_WS_WIN) || defined(qdoc)
+ QString printerSelectionOption() const;
+ void setPrinterSelectionOption(const QString &);
+#endif
+
+ bool newPage();
+ bool abort();
+
+ PrinterState printerState() const;
+
+ QPaintEngine *paintEngine() const;
+ QPrintEngine *printEngine() const;
+
+#ifdef Q_WS_WIN
+ HDC getDC() const;
+ void releaseDC(HDC hdc) const;
+#endif
+
+ void setFromTo(int fromPage, int toPage);
+ int fromPage() const;
+ int toPage() const;
+
+ void setPrintRange(PrintRange range);
+ PrintRange printRange() const;
+
+ void setPageMargins(qreal left, qreal top, qreal right, qreal bottom, Unit unit);
+ void getPageMargins(qreal *left, qreal *top, qreal *right, qreal *bottom, Unit unit) const;
+
+protected:
+ int metric(PaintDeviceMetric) const;
+ void setEngines(QPrintEngine *printEngine, QPaintEngine *paintEngine);
+
+private:
+ void init(PrinterMode mode);
+
+ Q_DISABLE_COPY(QPrinter)
+
+ QScopedPointer<QPrinterPrivate> d_ptr;
+
+ friend class QPrintDialogPrivate;
+ friend class QAbstractPrintDialog;
+ friend class QAbstractPrintDialogPrivate;
+ friend class QPrintPreviewWidgetPrivate;
+ friend class QTextDocument;
+ friend class QPageSetupWidget;
+};
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPRINTER_H
diff --git a/src/printsupport/kernel/qprinter_p.h b/src/printsupport/kernel/qprinter_p.h
new file mode 100644
index 0000000000..1d5660e4d7
--- /dev/null
+++ b/src/printsupport/kernel/qprinter_p.h
@@ -0,0 +1,136 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTER_P_H
+#define QPRINTER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+
+#include "QtCore/qglobal.h"
+
+#ifndef QT_NO_PRINTER
+
+#include "QtPrintSupport/qprinter.h"
+#include "QtPrintSupport/qprintengine.h"
+#include "QtCore/qpointer.h"
+
+#include <limits.h>
+
+QT_BEGIN_NAMESPACE
+
+class QPrintEngine;
+class QPreviewPaintEngine;
+class QPicture;
+
+class Q_GUI_EXPORT QPrinterPrivate
+{
+ Q_DECLARE_PUBLIC(QPrinter)
+public:
+ QPrinterPrivate(QPrinter *printer)
+ : printEngine(0)
+ , paintEngine(0)
+ , q_ptr(printer)
+ , printRange(QPrinter::AllPages)
+ , minPage(1)
+ , maxPage(INT_MAX)
+ , fromPage(0)
+ , toPage(0)
+ , use_default_engine(true)
+ , validPrinter(false)
+ , hasCustomPageMargins(false)
+ , hasUserSetPageSize(false)
+ {
+ }
+
+ ~QPrinterPrivate() {
+
+ }
+
+ void createDefaultEngines();
+#ifndef QT_NO_PRINTPREVIEWWIDGET
+ QList<const QPicture *> previewPages() const;
+ void setPreviewMode(bool);
+#endif
+
+ void addToManualSetList(QPrintEngine::PrintEnginePropertyKey key);
+
+ QPrinter::PrinterMode printerMode;
+ QPrinter::OutputFormat outputFormat;
+ QPrintEngine *printEngine;
+ QPaintEngine *paintEngine;
+
+ QPrintEngine *realPrintEngine;
+ QPaintEngine *realPaintEngine;
+#ifndef QT_NO_PRINTPREVIEWWIDGET
+ QPreviewPaintEngine *previewEngine;
+#endif
+
+ QPrinter *q_ptr;
+
+ QPrinter::PrintRange printRange;
+ int minPage, maxPage, fromPage, toPage;
+
+ uint use_default_engine : 1;
+ uint had_default_engines : 1;
+
+ uint validPrinter : 1;
+ uint hasCustomPageMargins : 1;
+ uint hasUserSetPageSize : 1;
+
+ // Used to remember which properties have been manually set by the user.
+ QList<QPrintEngine::PrintEnginePropertyKey> manualSetList;
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
+
+#endif // QPRINTER_P_H
diff --git a/src/printsupport/kernel/qprinterinfo.cpp b/src/printsupport/kernel/qprinterinfo.cpp
new file mode 100644
index 0000000000..e48db449b5
--- /dev/null
+++ b/src/printsupport/kernel/qprinterinfo.cpp
@@ -0,0 +1,199 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qprinterinfo.h"
+#include "qprinterinfo_p.h"
+
+#ifndef QT_NO_PRINTER
+
+#include <private/qguiapplication_p.h>
+#include <QtPrintSupport/QPlatformPrinterSupport>
+
+QT_BEGIN_NAMESPACE
+
+QPrinterInfoPrivate QPrinterInfoPrivate::shared_null;
+
+
+/*!
+ \class QPrinterInfo
+
+ \brief The QPrinterInfo class gives access to information about
+ existing printers.
+
+ \ingroup printing
+
+ Use the static functions to generate a list of QPrinterInfo
+ objects. Each QPrinterInfo object in the list represents a single
+ printer and can be queried for name, supported paper sizes, and
+ whether or not it is the default printer.
+
+ \since 4.4
+*/
+
+/*!
+ \fn QList<QPrinterInfo> QPrinterInfo::availablePrinters()
+
+ Returns a list of available printers on the system.
+*/
+
+/*!
+ \fn QPrinterInfo QPrinterInfo::defaultPrinter()
+
+ Returns the default printer on the system.
+
+ The return value should be checked using isNull() before being
+ used, in case there is no default printer.
+
+ \sa isNull()
+*/
+
+/*!
+ Constructs an empty QPrinterInfo object.
+
+ \sa isNull()
+*/
+QPrinterInfo::QPrinterInfo()
+ : d_ptr(&QPrinterInfoPrivate::shared_null)
+{
+}
+
+/*!
+ Constructs a copy of \a other.
+*/
+QPrinterInfo::QPrinterInfo(const QPrinterInfo &other)
+ : d_ptr(new QPrinterInfoPrivate(*other.d_ptr))
+{
+}
+
+/*!
+ Constructs a QPrinterInfo object from \a printer.
+*/
+QPrinterInfo::QPrinterInfo(const QPrinter &printer)
+ : d_ptr(&QPrinterInfoPrivate::shared_null)
+{
+ foreach (const QPrinterInfo &printerInfo, availablePrinters()) {
+ if (printerInfo.printerName() == printer.printerName()) {
+ d_ptr.reset(new QPrinterInfoPrivate(*printerInfo.d_ptr));
+ break;
+ }
+ }
+}
+
+/*!
+ \internal
+*/
+QPrinterInfo::QPrinterInfo(const QString &name)
+ : d_ptr(new QPrinterInfoPrivate(name))
+{
+}
+
+/*!
+ Destroys the QPrinterInfo object. References to the values in the
+ object become invalid.
+*/
+QPrinterInfo::~QPrinterInfo()
+{
+}
+
+/*!
+ Sets the QPrinterInfo object to be equal to \a other.
+*/
+QPrinterInfo &QPrinterInfo::operator=(const QPrinterInfo &other)
+{
+ Q_ASSERT(d_ptr);
+ d_ptr.reset(new QPrinterInfoPrivate(*other.d_ptr));
+ return *this;
+}
+
+/*!
+ Returns the name of the printer.
+
+ \sa QPrinter::setPrinterName()
+*/
+QString QPrinterInfo::printerName() const
+{
+ const Q_D(QPrinterInfo);
+ return d->name;
+}
+
+/*!
+ Returns whether this QPrinterInfo object holds a printer definition.
+
+ An empty QPrinterInfo object could result for example from calling
+ defaultPrinter() when there are no printers on the system.
+*/
+bool QPrinterInfo::isNull() const
+{
+ const Q_D(QPrinterInfo);
+ return d == &QPrinterInfoPrivate::shared_null;
+}
+
+/*!
+ Returns whether this printer is the default printer.
+*/
+bool QPrinterInfo::isDefault() const
+{
+ const Q_D(QPrinterInfo);
+ return d->isDefault;
+}
+
+/*!
+ \fn QList< QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
+ \since 4.4
+
+ Returns a list of supported paper sizes by the printer.
+
+ Not all printer drivers support this query, so the list may be empty.
+ On Mac OS X 10.3, this function always returns an empty list.
+*/
+
+#ifdef Q_WS_QPA
+QList<QPrinter::PaperSize> QPrinterInfo::supportedPaperSizes() const
+{
+ const Q_D(QPrinterInfo);
+ if (!isNull() && !d->hasPaperSizes) {
+ d->paperSizes = QGuiApplicationPrivate::platformIntegration()->printerSupport()->supportedPaperSizes(*this);
+ d->hasPaperSizes = true;
+ }
+ return d->paperSizes;
+}
+
+QList<QPrinterInfo> QPrinterInfo::availablePrinters()
+{
+ return QGuiApplicationPrivate::platformIntegration()->printerSupport()->availablePrinters();
+}
+
+QPrinterInfo QPrinterInfo::defaultPrinter()
+{
+ return QGuiApplicationPrivate::platformIntegration()->printerSupport()->defaultPrinter();
+}
+
+#endif //Q_WS_QPA
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
diff --git a/src/printsupport/kernel/qprinterinfo.h b/src/printsupport/kernel/qprinterinfo.h
new file mode 100644
index 0000000000..f00503f2c2
--- /dev/null
+++ b/src/printsupport/kernel/qprinterinfo.h
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTERINFO_H
+#define QPRINTERINFO_H
+
+#include <QtCore/QList>
+
+#include <QtPrintSupport/QPrinter>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+#ifndef QT_NO_PRINTER
+class QPrinterInfoPrivate;
+class QPrinterInfoPrivateDeleter;
+class Q_GUI_EXPORT QPrinterInfo
+{
+public:
+ QPrinterInfo();
+ QPrinterInfo(const QPrinterInfo &other);
+ QPrinterInfo(const QPrinter &printer);
+ ~QPrinterInfo();
+
+ QPrinterInfo &operator=(const QPrinterInfo &other);
+
+ QString printerName() const;
+ bool isNull() const;
+ bool isDefault() const;
+ QList<QPrinter::PaperSize> supportedPaperSizes() const;
+
+ static QList<QPrinterInfo> availablePrinters();
+ static QPrinterInfo defaultPrinter();
+
+private:
+ QPrinterInfo(const QString &name);
+
+private:
+ friend class QPlatformPrinterSupport;
+ Q_DECLARE_PRIVATE(QPrinterInfo)
+ QScopedPointer<QPrinterInfoPrivate, QPrinterInfoPrivateDeleter> d_ptr;
+};
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QPRINTERINFO_H
diff --git a/src/printsupport/kernel/qprinterinfo_p.h b/src/printsupport/kernel/qprinterinfo_p.h
new file mode 100644
index 0000000000..a3c654e7b7
--- /dev/null
+++ b/src/printsupport/kernel/qprinterinfo_p.h
@@ -0,0 +1,108 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTERINFO_P_H
+#define QPRINTERINFO_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "QtCore/qglobal.h"
+
+#ifndef QT_NO_PRINTER
+
+#include "QtCore/qlist.h"
+
+QT_BEGIN_NAMESPACE
+
+class QPrinterInfoPrivate
+{
+public:
+ QPrinterInfoPrivate(const QString& name = QString()) :
+ name(name), isDefault(false)
+#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)) || defined(Q_WS_QPA)
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ , cupsPrinterIndex(0)
+#endif
+#endif
+ , hasPaperSizes(false)
+ {}
+ ~QPrinterInfoPrivate()
+ {}
+
+ static QPrinterInfoPrivate shared_null;
+
+ QString name;
+ bool isDefault;
+
+#if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)) || defined(Q_WS_QPA)
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ int cupsPrinterIndex;
+#endif
+#endif
+ mutable bool hasPaperSizes;
+ mutable QList<QPrinter::PaperSize> paperSizes;
+};
+
+
+class QPrinterInfoPrivateDeleter
+{
+public:
+ static inline void cleanup(QPrinterInfoPrivate *d)
+ {
+ if (d != &QPrinterInfoPrivate::shared_null)
+ delete d;
+ }
+};
+
+QT_END_NAMESPACE
+
+#endif // QT_NO_PRINTER
+
+#endif // QPRINTERINFO_P_H
diff --git a/src/printsupport/kernel/qprinterinfo_unix.cpp b/src/printsupport/kernel/qprinterinfo_unix.cpp
new file mode 100644
index 0000000000..3c66481b4d
--- /dev/null
+++ b/src/printsupport/kernel/qprinterinfo_unix.cpp
@@ -0,0 +1,857 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qprinterinfo.h"
+#include "qprinterinfo_p.h"
+
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <qdir.h>
+#include <qlibrary.h>
+#include <qtextstream.h>
+#include <qcoreapplication.h>
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+# include <private/qcups_p.h>
+# include <cups/cups.h>
+# include <private/qpdf_p.h>
+#endif
+
+#include <private/qprinterinfo_unix_p.h>
+
+QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_PRINTER
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+// preserver names in ascending order for the binary search
+static const struct NamedPaperSize {
+ const char *const name;
+ QPrinter::PaperSize size;
+} named_sizes_map[QPrinter::NPageSize] = {
+ { "A0", QPrinter::A0 },
+ { "A1", QPrinter::A1 },
+ { "A2", QPrinter::A2 },
+ { "A3", QPrinter::A3 },
+ { "A4", QPrinter::A4 },
+ { "A5", QPrinter::A5 },
+ { "A6", QPrinter::A6 },
+ { "A7", QPrinter::A7 },
+ { "A8", QPrinter::A8 },
+ { "A9", QPrinter::A9 },
+ { "B0", QPrinter::B0 },
+ { "B1", QPrinter::B1 },
+ { "B10", QPrinter::B10 },
+ { "B2", QPrinter::B2 },
+ { "B4", QPrinter::B4 },
+ { "B5", QPrinter::B5 },
+ { "B6", QPrinter::B6 },
+ { "B7", QPrinter::B7 },
+ { "B8", QPrinter::B8 },
+ { "B9", QPrinter::B9 },
+ { "C5E", QPrinter::C5E },
+ { "Comm10E", QPrinter::Comm10E },
+ { "Custom", QPrinter::Custom },
+ { "DLE", QPrinter::DLE },
+ { "Executive", QPrinter::Executive },
+ { "Folio", QPrinter::Folio },
+ { "Ledger", QPrinter::Ledger },
+ { "Legal", QPrinter::Legal },
+ { "Letter", QPrinter::Letter },
+ { "Tabloid", QPrinter::Tabloid }
+};
+
+inline bool operator<(const char *name, const NamedPaperSize &data)
+{ return qstrcmp(name, data.name) < 0; }
+inline bool operator<(const NamedPaperSize &data, const char *name)
+{ return qstrcmp(data.name, name) < 0; }
+
+static inline QPrinter::PaperSize string2PaperSize(const char *name)
+{
+ const NamedPaperSize *r = qBinaryFind(named_sizes_map, named_sizes_map + QPrinter::NPageSize, name);
+ if (r - named_sizes_map != QPrinter::NPageSize)
+ return r->size;
+ return QPrinter::Custom;
+}
+
+static inline const char *paperSize2String(QPrinter::PaperSize size)
+{
+ for (int i = 0; i < QPrinter::NPageSize; ++i) {
+ if (size == named_sizes_map[i].size)
+ return named_sizes_map[i].name;
+ }
+ return 0;
+}
+#endif
+
+void qt_perhapsAddPrinter(QList<QPrinterDescription> *printers, const QString &name,
+ QString host, QString comment,
+ QStringList aliases)
+{
+ for (int i = 0; i < printers->size(); ++i)
+ if (printers->at(i).samePrinter(name))
+ return;
+
+ if (host.isEmpty())
+ host = QCoreApplication::translate("QPrinter", "locally connected");
+ printers->append(QPrinterDescription(name.simplified(), host.simplified(), comment.simplified(), aliases));
+}
+
+void qt_parsePrinterDesc(QString printerDesc, QList<QPrinterDescription> *printers)
+{
+ if (printerDesc.length() < 1)
+ return;
+
+ printerDesc = printerDesc.simplified();
+ int i = printerDesc.indexOf(QLatin1Char(':'));
+ QString printerName, printerComment, printerHost;
+ QStringList aliases;
+
+ if (i >= 0) {
+ // have ':' want '|'
+ int j = printerDesc.indexOf(QLatin1Char('|'));
+ if (j > 0 && j < i) {
+ printerName = printerDesc.left(j);
+ aliases = printerDesc.mid(j + 1, i - j - 1).split(QLatin1Char('|'));
+ // try extracting a comment from the aliases
+ printerComment = QCoreApplication::translate("QPrinter", "Aliases: %1")
+ .arg(aliases.join(QLatin1String(", ")));
+ } else {
+ printerName = printerDesc.left(i);
+ }
+ // look for lprng pseudo all printers entry
+ i = printerDesc.indexOf(QRegExp(QLatin1String(": *all *=")));
+ if (i >= 0)
+ printerName = QString();
+ // look for signs of this being a remote printer
+ i = printerDesc.indexOf(QRegExp(QLatin1String(": *rm *=")));
+ if (i >= 0) {
+ // point k at the end of remote host name
+ while (printerDesc[i] != QLatin1Char('='))
+ i++;
+ while (printerDesc[i] == QLatin1Char('=') || printerDesc[i].isSpace())
+ i++;
+ j = i;
+ while (j < (int)printerDesc.length() && printerDesc[j] != QLatin1Char(':'))
+ j++;
+
+ // and stuff that into the string
+ printerHost = printerDesc.mid(i, j - i);
+ }
+ }
+ if (printerName.length())
+ qt_perhapsAddPrinter(printers, printerName, printerHost, printerComment,
+ aliases);
+}
+
+int qt_parsePrintcap(QList<QPrinterDescription> *printers, const QString& fileName)
+{
+ QFile printcap(fileName);
+ if (!printcap.open(QIODevice::ReadOnly))
+ return NotFound;
+
+ char *line_ascii = new char[1025];
+ line_ascii[1024] = '\0';
+
+ QString printerDesc;
+ bool atEnd = false;
+
+ while (!atEnd) {
+ if (printcap.atEnd() || printcap.readLine(line_ascii, 1024) <= 0)
+ atEnd = true;
+ QString line = QString::fromLocal8Bit(line_ascii);
+ line = line.trimmed();
+ if (line.length() >= 1 && line[int(line.length()) - 1] == QLatin1Char('\\'))
+ line.chop(1);
+ if (line[0] == QLatin1Char('#')) {
+ if (!atEnd)
+ continue;
+ } else if (line[0] == QLatin1Char('|') || line[0] == QLatin1Char(':')
+ || line.isEmpty()) {
+ printerDesc += line;
+ if (!atEnd)
+ continue;
+ }
+
+ qt_parsePrinterDesc(printerDesc, printers);
+
+ // add the first line of the new printer definition
+ printerDesc = line;
+ }
+ delete[] line_ascii;
+ return Success;
+}
+
+/*!
+ \internal
+
+ Checks $HOME/.printers for a line matching '_default <name>' (where
+ <name> does not contain any white space). The first such match
+ results in <name> being returned.
+ If no lines match then an empty string is returned.
+*/
+QString qt_getDefaultFromHomePrinters()
+{
+ QFile file(QDir::homePath() + QLatin1String("/.printers"));
+ if (!file.open(QIODevice::ReadOnly))
+ return QString();
+ QString all(QLatin1String(file.readAll()));
+ QStringList words = all.split(QRegExp(QLatin1String("\\W+")), QString::SkipEmptyParts);
+ const int i = words.indexOf(QLatin1String("_default"));
+ if (i != -1 && i < words.size() - 1)
+ return words.at(i + 1);
+ return QString();
+}
+
+// solaris, not 2.6
+void qt_parseEtcLpPrinters(QList<QPrinterDescription> *printers)
+{
+ QDir lp(QLatin1String("/etc/lp/printers"));
+ QFileInfoList dirs = lp.entryInfoList();
+ if (dirs.isEmpty())
+ return;
+
+ QString tmp;
+ for (int i = 0; i < dirs.size(); ++i) {
+ QFileInfo printer = dirs.at(i);
+ if (printer.isDir()) {
+ tmp.sprintf("/etc/lp/printers/%s/configuration",
+ printer.fileName().toAscii().data());
+ QFile configuration(tmp);
+ char *line = new char[1025];
+ QString remote(QLatin1String("Remote:"));
+ QString contentType(QLatin1String("Content types:"));
+ QString printerHost;
+ bool canPrintPostscript = false;
+ if (configuration.open(QIODevice::ReadOnly)) {
+ while (!configuration.atEnd() &&
+ configuration.readLine(line, 1024) > 0) {
+ if (QString::fromLatin1(line).startsWith(remote)) {
+ const char *p = line;
+ while (*p != ':')
+ p++;
+ p++;
+ while (isspace((uchar) *p))
+ p++;
+ printerHost = QString::fromLocal8Bit(p);
+ printerHost = printerHost.simplified();
+ } else if (QString::fromLatin1(line).startsWith(contentType)) {
+ char *p = line;
+ while (*p != ':')
+ p++;
+ p++;
+ char *e;
+ while (*p) {
+ while (isspace((uchar) *p))
+ p++;
+ if (*p) {
+ char s;
+ e = p;
+ while (isalnum((uchar) *e))
+ e++;
+ s = *e;
+ *e = '\0';
+ if (!qstrcmp(p, "postscript") ||
+ !qstrcmp(p, "any"))
+ canPrintPostscript = true;
+ *e = s;
+ if (s == ',')
+ e++;
+ p = e;
+ }
+ }
+ }
+ }
+ if (canPrintPostscript)
+ qt_perhapsAddPrinter(printers, printer.fileName(),
+ printerHost, QLatin1String(""));
+ }
+ delete[] line;
+ }
+ }
+}
+
+// solaris 2.6
+char *qt_parsePrintersConf(QList<QPrinterDescription> *printers, bool *found)
+{
+ QFile pc(QLatin1String("/etc/printers.conf"));
+ if (!pc.open(QIODevice::ReadOnly)) {
+ if (found)
+ *found = false;
+ return 0;
+ }
+ if (found)
+ *found = true;
+
+ char *line = new char[1025];
+ line[1024] = '\0';
+
+ QString printerDesc;
+ int lineLength = 0;
+
+ char *defaultPrinter = 0;
+
+ while (!pc.atEnd() &&
+ (lineLength=pc.readLine(line, 1024)) > 0) {
+ if (*line == '#') {
+ *line = '\0';
+ lineLength = 0;
+ }
+ if (lineLength >= 2 && line[lineLength-2] == '\\') {
+ line[lineLength-2] = '\0';
+ printerDesc += QString::fromLocal8Bit(line);
+ } else {
+ printerDesc += QString::fromLocal8Bit(line);
+ printerDesc = printerDesc.simplified();
+ int i = printerDesc.indexOf(QLatin1Char(':'));
+ QString printerName, printerHost, printerComment;
+ QStringList aliases;
+ if (i >= 0) {
+ // have : want |
+ int j = printerDesc.indexOf(QLatin1Char('|'));
+ if (j >= i)
+ j = -1;
+ printerName = printerDesc.mid(0, j < 0 ? i : j);
+ if (printerName == QLatin1String("_default")) {
+ i = printerDesc.indexOf(
+ QRegExp(QLatin1String(": *use *=")));
+ while (printerDesc[i] != QLatin1Char('='))
+ i++;
+ while (printerDesc[i] == QLatin1Char('=') || printerDesc[i].isSpace())
+ i++;
+ j = i;
+ while (j < (int)printerDesc.length() &&
+ printerDesc[j] != QLatin1Char(':') && printerDesc[j] != QLatin1Char(','))
+ j++;
+ // that's our default printer
+ defaultPrinter =
+ qstrdup(printerDesc.mid(i, j-i).toAscii().data());
+ printerName = QString();
+ printerDesc = QString();
+ } else if (printerName == QLatin1String("_all")) {
+ // skip it.. any other cases we want to skip?
+ printerName = QString();
+ printerDesc = QString();
+ }
+
+ if (j > 0) {
+ // try extracting a comment from the aliases
+ aliases = printerDesc.mid(j + 1, i - j - 1).split(QLatin1Char('|'));
+ printerComment = QCoreApplication::translate("QPrinter", "Aliases: %1")
+ .arg(aliases.join(QLatin1String(", ")));
+ }
+ // look for signs of this being a remote printer
+ i = printerDesc.indexOf(
+ QRegExp(QLatin1String(": *bsdaddr *=")));
+ if (i >= 0) {
+ // point k at the end of remote host name
+ while (printerDesc[i] != QLatin1Char('='))
+ i++;
+ while (printerDesc[i] == QLatin1Char('=') || printerDesc[i].isSpace())
+ i++;
+ j = i;
+ while (j < (int)printerDesc.length() &&
+ printerDesc[j] != QLatin1Char(':') && printerDesc[j] != QLatin1Char(','))
+ j++;
+ // and stuff that into the string
+ printerHost = printerDesc.mid(i, j-i);
+ // maybe stick the remote printer name into the comment
+ if (printerDesc[j] == QLatin1Char(',')) {
+ i = ++j;
+ while (printerDesc[i].isSpace())
+ i++;
+ j = i;
+ while (j < (int)printerDesc.length() &&
+ printerDesc[j] != QLatin1Char(':') && printerDesc[j] != QLatin1Char(','))
+ j++;
+ if (printerName != printerDesc.mid(i, j-i)) {
+ printerComment =
+ QLatin1String("Remote name: ");
+ printerComment += printerDesc.mid(i, j-i);
+ }
+ }
+ }
+ }
+ if (printerComment == QLatin1String(":"))
+ printerComment = QString(); // for cups
+ if (printerName.length())
+ qt_perhapsAddPrinter(printers, printerName, printerHost,
+ printerComment, aliases);
+ // chop away the line, for processing the next one
+ printerDesc = QString();
+ }
+ }
+ delete[] line;
+ return defaultPrinter;
+}
+
+#ifndef QT_NO_NIS
+
+#if defined(Q_C_CALLBACKS)
+extern "C" {
+#endif
+
+int qt_pd_foreach(int /*status */, char * /*key */, int /*keyLen */,
+ char *val, int valLen, char *data)
+{
+ qt_parsePrinterDesc(QString::fromLatin1(val, valLen), (QList<QPrinterDescription> *)data);
+ return 0;
+}
+
+#if defined(Q_C_CALLBACKS)
+}
+#endif
+
+int qt_retrieveNisPrinters(QList<QPrinterDescription> *printers)
+{
+#ifndef QT_NO_LIBRARY
+ typedef int (*WildCast)(int, char *, int, char *, int, char *);
+ char printersConfByname[] = "printers.conf.byname";
+ char *domain;
+ int err;
+
+ QLibrary lib(QLatin1String("nsl"));
+ typedef int (*ypGetDefaultDomain)(char **);
+ ypGetDefaultDomain _ypGetDefaultDomain = (ypGetDefaultDomain)lib.resolve("yp_get_default_domain");
+ typedef int (*ypAll)(const char *, const char *, const struct ypall_callback *);
+ ypAll _ypAll = (ypAll)lib.resolve("yp_all");
+
+ if (_ypGetDefaultDomain && _ypAll) {
+ err = _ypGetDefaultDomain(&domain);
+ if (err == 0) {
+ ypall_callback cb;
+ // wild cast to support K&R-style system headers
+ (WildCast &) cb.foreach = (WildCast) qt_pd_foreach;
+ cb.data = (char *) printers;
+ err = _ypAll(domain, printersConfByname, &cb);
+ }
+ if (!err)
+ return Success;
+ }
+#endif //QT_NO_LIBRARY
+ return Unavail;
+}
+
+#endif // QT_NO_NIS
+
+char *qt_parseNsswitchPrintersEntry(QList<QPrinterDescription> *printers, char *line)
+{
+#define skipSpaces() \
+ while (line[k] != '\0' && isspace((uchar) line[k])) \
+ k++
+
+ char *defaultPrinter = 0;
+ bool stop = false;
+ int lastStatus = NotFound;
+
+ int k = 8;
+ skipSpaces();
+ if (line[k] != ':')
+ return 0;
+ k++;
+
+ char *cp = strchr(line, '#');
+ if (cp != 0)
+ *cp = '\0';
+
+ while (line[k] != '\0') {
+ if (isspace((uchar) line[k])) {
+ k++;
+ } else if (line[k] == '[') {
+ k++;
+ skipSpaces();
+ while (line[k] != '\0') {
+ char status = tolower(line[k]);
+ char action = '?';
+
+ while (line[k] != '=' && line[k] != ']' && line[k] != '\0')
+ k++;
+ if (line[k] == '=') {
+ k++;
+ skipSpaces();
+ action = tolower(line[k]);
+ while (line[k] != '\0' && !isspace((uchar) line[k]) && line[k] != ']')
+ k++;
+ } else if (line[k] == ']') {
+ k++;
+ break;
+ }
+ skipSpaces();
+
+ if (lastStatus == status)
+ stop = (action == (char) Return);
+ }
+ } else {
+ if (stop)
+ break;
+
+ QByteArray source;
+ while (line[k] != '\0' && !isspace((uchar) line[k]) && line[k] != '[') {
+ source += line[k];
+ k++;
+ }
+
+ if (source == "user") {
+ lastStatus = qt_parsePrintcap(printers,
+ QDir::homePath() + QLatin1String("/.printers"));
+ } else if (source == "files") {
+ bool found;
+ defaultPrinter = qt_parsePrintersConf(printers, &found);
+ if (found)
+ lastStatus = Success;
+#ifndef QT_NO_NIS
+ } else if (source == "nis") {
+ lastStatus = qt_retrieveNisPrinters(printers);
+#endif
+ } else {
+ // nisplus, dns, etc., are not implemented yet
+ lastStatus = NotFound;
+ }
+ stop = (lastStatus == Success);
+ }
+ }
+ return defaultPrinter;
+}
+
+char *qt_parseNsswitchConf(QList<QPrinterDescription> *printers)
+{
+ QFile nc(QLatin1String("/etc/nsswitch.conf"));
+ if (!nc.open(QIODevice::ReadOnly))
+ return 0;
+
+ char *defaultPrinter = 0;
+
+ char *line = new char[1025];
+ line[1024] = '\0';
+
+ while (!nc.atEnd() &&
+ nc.readLine(line, 1024) > 0) {
+ if (qstrncmp(line, "printers", 8) == 0) {
+ defaultPrinter = qt_parseNsswitchPrintersEntry(printers, line);
+ delete[] line;
+ return defaultPrinter;
+ }
+ }
+
+ strcpy(line, "printers: user files nis nisplus xfn");
+ defaultPrinter = qt_parseNsswitchPrintersEntry(printers, line);
+ delete[] line;
+ return defaultPrinter;
+}
+
+// HP-UX
+void qt_parseEtcLpMember(QList<QPrinterDescription> *printers)
+{
+ QDir lp(QLatin1String("/etc/lp/member"));
+ if (!lp.exists())
+ return;
+ QFileInfoList dirs = lp.entryInfoList();
+ if (dirs.isEmpty())
+ return;
+
+ QString tmp;
+ for (int i = 0; i < dirs.size(); ++i) {
+ QFileInfo printer = dirs.at(i);
+ // I haven't found any real documentation, so I'm guessing that
+ // since lpstat uses /etc/lp/member rather than one of the
+ // other directories, it's the one to use. I did not find a
+ // decent way to locate aliases and remote printers.
+ if (printer.isFile())
+ qt_perhapsAddPrinter(printers, printer.fileName(),
+ QCoreApplication::translate("QPrinter", "unknown"),
+ QLatin1String(""));
+ }
+}
+
+// IRIX 6.x
+void qt_parseSpoolInterface(QList<QPrinterDescription> *printers)
+{
+ QDir lp(QLatin1String("/usr/spool/lp/interface"));
+ if (!lp.exists())
+ return;
+ QFileInfoList files = lp.entryInfoList();
+ if(files.isEmpty())
+ return;
+
+ for (int i = 0; i < files.size(); ++i) {
+ QFileInfo printer = files.at(i);
+
+ if (!printer.isFile())
+ continue;
+
+ // parse out some information
+ QFile configFile(printer.filePath());
+ if (!configFile.open(QIODevice::ReadOnly))
+ continue;
+
+ QByteArray line;
+ line.resize(1025);
+ QString namePrinter;
+ QString hostName;
+ QString hostPrinter;
+ QString printerType;
+
+ QString nameKey(QLatin1String("NAME="));
+ QString typeKey(QLatin1String("TYPE="));
+ QString hostKey(QLatin1String("HOSTNAME="));
+ QString hostPrinterKey(QLatin1String("HOSTPRINTER="));
+
+ while (!configFile.atEnd() &&
+ (configFile.readLine(line.data(), 1024)) > 0) {
+ QString uline = QString::fromLocal8Bit(line);
+ if (uline.startsWith(typeKey) ) {
+ printerType = uline.mid(nameKey.length());
+ printerType = printerType.simplified();
+ } else if (uline.startsWith(hostKey)) {
+ hostName = uline.mid(hostKey.length());
+ hostName = hostName.simplified();
+ } else if (uline.startsWith(hostPrinterKey)) {
+ hostPrinter = uline.mid(hostPrinterKey.length());
+ hostPrinter = hostPrinter.simplified();
+ } else if (uline.startsWith(nameKey)) {
+ namePrinter = uline.mid(nameKey.length());
+ namePrinter = namePrinter.simplified();
+ }
+ }
+ configFile.close();
+
+ printerType = printerType.trimmed();
+ if (printerType.indexOf(QLatin1String("postscript"), 0, Qt::CaseInsensitive) < 0)
+ continue;
+
+ int ii = 0;
+ while ((ii = namePrinter.indexOf(QLatin1Char('"'), ii)) >= 0)
+ namePrinter.remove(ii, 1);
+
+ if (hostName.isEmpty() || hostPrinter.isEmpty()) {
+ qt_perhapsAddPrinter(printers, printer.fileName(),
+ QLatin1String(""), namePrinter);
+ } else {
+ QString comment;
+ comment = namePrinter;
+ comment += QLatin1String(" (");
+ comment += hostPrinter;
+ comment += QLatin1Char(')');
+ qt_perhapsAddPrinter(printers, printer.fileName(),
+ hostName, comment);
+ }
+ }
+}
+
+
+// Every unix must have its own. It's a standard. Here is AIX.
+void qt_parseQconfig(QList<QPrinterDescription> *printers)
+{
+ QFile qconfig(QLatin1String("/etc/qconfig"));
+ if (!qconfig.open(QIODevice::ReadOnly))
+ return;
+
+ QTextStream ts(&qconfig);
+ QString line;
+
+ QString stanzaName; // either a queue or a device name
+ bool up = true; // queue up? default true, can be false
+ QString remoteHost; // null if local
+ QString deviceName; // null if remote
+
+ QRegExp newStanza(QLatin1String("^[0-z\\-]*:$"));
+
+ // our basic strategy here is to process each line, detecting new
+ // stanzas. each time we see a new stanza, we check if the
+ // previous stanza was a valid queue for a) a remote printer or b)
+ // a local printer. if it wasn't, we assume that what we see is
+ // the start of the first stanza, or that the previous stanza was
+ // a device stanza, or that there is some syntax error (we don't
+ // report those).
+
+ do {
+ line = ts.readLine();
+ bool indented = line[0].isSpace();
+ line = line.simplified();
+
+ int i = line.indexOf(QLatin1Char('='));
+ if (indented && i != -1) { // line in stanza
+ QString variable = line.left(i).simplified();
+ QString value=line.mid(i+1, line.length()).simplified();
+ if (variable == QLatin1String("device"))
+ deviceName = value;
+ else if (variable == QLatin1String("host"))
+ remoteHost = value;
+ else if (variable == QLatin1String("up"))
+ up = !(value.toLower() == QLatin1String("false"));
+ } else if (line[0] == QLatin1Char('*')) { // comment
+ // nothing to do
+ } else if (ts.atEnd() || // end of file, or beginning of new stanza
+ (!indented && line.contains(newStanza))) {
+ if (up && stanzaName.length() > 0 && stanzaName.length() < 21) {
+ if (remoteHost.length()) // remote printer
+ qt_perhapsAddPrinter(printers, stanzaName, remoteHost,
+ QString());
+ else if (deviceName.length()) // local printer
+ qt_perhapsAddPrinter(printers, stanzaName, QString(),
+ QString());
+ }
+ line.chop(1);
+ if (line.length() >= 1 && line.length() <= 20)
+ stanzaName = line;
+ up = true;
+ remoteHost.clear();
+ deviceName.clear();
+ } else {
+ // syntax error? ignore.
+ }
+ } while (!ts.atEnd());
+}
+
+Q_GUI_EXPORT int qt_getLprPrinters(QList<QPrinterDescription>& printers)
+{
+ QByteArray etcLpDefault;
+ qt_parsePrintcap(&printers, QLatin1String("/etc/printcap"));
+ qt_parseEtcLpMember(&printers);
+ qt_parseSpoolInterface(&printers);
+ qt_parseQconfig(&printers);
+
+ QFileInfo f;
+ f.setFile(QLatin1String("/etc/lp/printers"));
+ if (f.isDir()) {
+ qt_parseEtcLpPrinters(&printers);
+ QFile def(QLatin1String("/etc/lp/default"));
+ if (def.open(QIODevice::ReadOnly)) {
+ etcLpDefault.resize(1025);
+ if (def.readLine(etcLpDefault.data(), 1024) > 0) {
+ QRegExp rx(QLatin1String("^(\\S+)"));
+ if (rx.indexIn(QString::fromLatin1(etcLpDefault)) != -1)
+ etcLpDefault = rx.cap(1).toAscii();
+ }
+ }
+ }
+
+ char *def = 0;
+ f.setFile(QLatin1String("/etc/nsswitch.conf"));
+ if (f.isFile()) {
+ def = qt_parseNsswitchConf(&printers);
+ } else {
+ f.setFile(QLatin1String("/etc/printers.conf"));
+ if (f.isFile())
+ def = qt_parsePrintersConf(&printers);
+ }
+
+ if (def) {
+ etcLpDefault = def;
+ delete [] def;
+ }
+
+ QString homePrintersDefault = qt_getDefaultFromHomePrinters();
+
+ // all printers hopefully known. try to find a good default
+ QString dollarPrinter;
+ {
+ dollarPrinter = QString::fromLocal8Bit(qgetenv("PRINTER"));
+ if (dollarPrinter.isEmpty())
+ dollarPrinter = QString::fromLocal8Bit(qgetenv("LPDEST"));
+ if (dollarPrinter.isEmpty())
+ dollarPrinter = QString::fromLocal8Bit(qgetenv("NPRINTER"));
+ if (dollarPrinter.isEmpty())
+ dollarPrinter = QString::fromLocal8Bit(qgetenv("NGPRINTER"));
+ if (!dollarPrinter.isEmpty())
+ qt_perhapsAddPrinter(&printers, dollarPrinter,
+ QCoreApplication::translate("QPrinter", "unknown"),
+ QLatin1String(""));
+ }
+
+ QRegExp ps(QLatin1String("[^a-z]ps(?:[^a-z]|$)"));
+ QRegExp lp(QLatin1String("[^a-z]lp(?:[^a-z]|$)"));
+
+ int quality = 0;
+ int best = 0;
+ for (int i = 0; i < printers.size(); ++i) {
+ QString name = printers.at(i).name;
+ QString comment = printers.at(i).comment;
+ if (quality < 5 && name == dollarPrinter) {
+ best = i;
+ quality = 5;
+ } else if (quality < 4 && !homePrintersDefault.isEmpty() &&
+ name == homePrintersDefault) {
+ best = i;
+ quality = 4;
+ } else if (quality < 3 && !etcLpDefault.isEmpty() &&
+ name == QLatin1String(etcLpDefault)) {
+ best = i;
+ quality = 3;
+ } else if (quality < 2 &&
+ (name == QLatin1String("ps") ||
+ ps.indexIn(comment) != -1)) {
+ best = i;
+ quality = 2;
+ } else if (quality < 1 &&
+ (name == QLatin1String("lp") ||
+ lp.indexIn(comment) > -1)) {
+ best = i;
+ quality = 1;
+ }
+ }
+
+ return best;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+QList<QPrinter::PaperSize> qt_getCupsPrinterPaperSizes(int cupsPrinterIndex)
+{
+ QList<QPrinter::PaperSize> result;
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (!QCUPSSupport::isAvailable() || cupsPrinterIndex < 0)
+ return result;
+ // Find paper sizes from CUPS.
+ QCUPSSupport cups;
+ cups.setCurrentPrinter(cupsPrinterIndex);
+ if (const ppd_option_t* size = cups.pageSizes()) {
+ for (int j = 0; j < size->num_choices; ++j)
+ result.append(string2PaperSize(size->choices[j].choice));
+ }
+ return result;
+#endif
+}
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
diff --git a/src/printsupport/kernel/qprinterinfo_unix_p.h b/src/printsupport/kernel/qprinterinfo_unix_p.h
new file mode 100644
index 0000000000..c12aa39556
--- /dev/null
+++ b/src/printsupport/kernel/qprinterinfo_unix_p.h
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTERINFO_UNIX_P_H
+#define QPRINTERINFO_UNIX_P_H
+
+#include <QtPrintSupport/qprinter.h>
+#include <QtCore/qstringlist.h>
+
+#ifndef QT_NO_NIS
+# ifndef BOOL_DEFINED
+# define BOOL_DEFINED
+# endif
+
+# include <sys/types.h>
+# include <rpc/rpc.h>
+# include <rpcsvc/ypclnt.h>
+# include <rpcsvc/yp_prot.h>
+#endif // QT_NO_NIS
+
+#ifdef Success
+# undef Success
+#endif
+
+#include <ctype.h>
+
+QT_BEGIN_NAMESPACE
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#ifndef QT_NO_PRINTER
+
+struct QPrinterDescription {
+ QPrinterDescription(const QString &n, const QString &h, const QString &c, const QStringList &a)
+ : name(n), host(h), comment(c), aliases(a) {}
+ QString name;
+ QString host;
+ QString comment;
+ QStringList aliases;
+ bool samePrinter(const QString& printer) const {
+ return name == printer || aliases.contains(printer);
+ }
+};
+
+enum { Success = 's', Unavail = 'u', NotFound = 'n', TryAgain = 't' };
+enum { Continue = 'c', Return = 'r' };
+
+void qt_perhapsAddPrinter(QList<QPrinterDescription> *printers, const QString &name,
+ QString host, QString comment,
+ QStringList aliases = QStringList());
+void qt_parsePrinterDesc(QString printerDesc, QList<QPrinterDescription> *printers);
+
+int qt_parsePrintcap(QList<QPrinterDescription> *printers, const QString& fileName);
+QString qt_getDefaultFromHomePrinters();
+void qt_parseEtcLpPrinters(QList<QPrinterDescription> *printers);
+char *qt_parsePrintersConf(QList<QPrinterDescription> *printers, bool *found = 0);
+
+#ifndef QT_NO_NIS
+#if defined(Q_C_CALLBACKS)
+extern "C" {
+#endif
+int qt_pd_foreach(int /*status */, char * /*key */, int /*keyLen */,
+ char *val, int valLen, char *data);
+
+#if defined(Q_C_CALLBACKS)
+}
+#endif
+int qt_retrieveNisPrinters(QList<QPrinterDescription> *printers);
+#endif // QT_NO_NIS
+char *qt_parseNsswitchPrintersEntry(QList<QPrinterDescription> *printers, char *line);
+char *qt_parseNsswitchConf(QList<QPrinterDescription> *printers);
+void qt_parseEtcLpMember(QList<QPrinterDescription> *printers);
+void qt_parseSpoolInterface(QList<QPrinterDescription> *printers);
+void qt_parseQconfig(QList<QPrinterDescription> *printers);
+int qt_getLprPrinters(QList<QPrinterDescription>& printers);
+
+QList<QPrinter::PaperSize> qt_getCupsPrinterPaperSizes(int cupsPrinterIndex);
+
+#endif // QT_NO_PRINTER
+
+QT_END_NAMESPACE
+
+#endif // QPRINTERINFO_UNIX_P_H
diff --git a/src/printsupport/printsupport.pro b/src/printsupport/printsupport.pro
new file mode 100644
index 0000000000..0aa92a95de
--- /dev/null
+++ b/src/printsupport/printsupport.pro
@@ -0,0 +1,22 @@
+load(qt_module)
+
+TARGET = QtPrintSupport
+QPRO_PWD = $$PWD
+QT = core-private gui-private widgets-private
+
+CONFIG += module
+MODULE_PRI = ../modules/qt_printsupport.pri
+
+DEFINES += QT_BUILD_PRINTSUPPORT_LIB QT_NO_USING_NAMESPACE
+
+unix|win32-g++*:QMAKE_PKGCONFIG_REQUIRES = QtCore QtGui
+
+load(qt_module_config)
+
+HEADERS += $$QT_SOURCE_TREE/src/printsupport/qtprintsupportversion.h
+
+QMAKE_LIBS += $$QMAKE_LIBS_PRINTSUPPORT
+
+include(kernel/kernel.pri)
+include(widgets/widgets.pri)
+include(dialogs/dialogs.pri)
diff --git a/src/printsupport/widgets/qprintpreviewwidget.cpp b/src/printsupport/widgets/qprintpreviewwidget.cpp
new file mode 100644
index 0000000000..96b009f8c1
--- /dev/null
+++ b/src/printsupport/widgets/qprintpreviewwidget.cpp
@@ -0,0 +1,844 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qprintpreviewwidget.h"
+#include "private/qwidget_p.h"
+#include <private/qprinter_p.h>
+
+#include <QtCore/qmath.h>
+#include <QtWidgets/qboxlayout.h>
+#include <QtWidgets/qgraphicsitem.h>
+#include <QtWidgets/qgraphicsview.h>
+#include <QtWidgets/qscrollbar.h>
+#include <QtWidgets/qstyleoption.h>
+
+#ifndef QT_NO_PRINTPREVIEWWIDGET
+
+QT_BEGIN_NAMESPACE
+
+namespace {
+class PageItem : public QGraphicsItem
+{
+public:
+ PageItem(int _pageNum, const QPicture* _pagePicture, QSize _paperSize, QRect _pageRect)
+ : pageNum(_pageNum), pagePicture(_pagePicture),
+ paperSize(_paperSize), pageRect(_pageRect)
+ {
+ qreal border = qMax(paperSize.height(), paperSize.width()) / 25;
+ brect = QRectF(QPointF(-border, -border),
+ QSizeF(paperSize)+QSizeF(2*border, 2*border));
+ setCacheMode(DeviceCoordinateCache);
+ }
+
+ inline QRectF boundingRect() const
+ { return brect; }
+
+ inline int pageNumber() const
+ { return pageNum; }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *item, QWidget *widget);
+
+private:
+ int pageNum;
+ const QPicture* pagePicture;
+ QSize paperSize;
+ QRect pageRect;
+ QRectF brect;
+};
+
+void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(widget);
+
+#if 0
+ // Draw item bounding rect, for debugging
+ painter->save();
+ painter->setPen(QPen(Qt::red, 0));
+ painter->setBrush(Qt::NoBrush);
+ painter->drawRect(QRectF(-border()+1.0, -border()+1.0, boundingRect().width()-2, boundingRect().height()-2));
+ painter->restore();
+#endif
+
+ QRectF paperRect(0,0, paperSize.width(), paperSize.height());
+
+ // Draw shadow
+ painter->setClipRect(option->exposedRect);
+ qreal shWidth = paperRect.width()/100;
+ QRectF rshadow(paperRect.topRight() + QPointF(0, shWidth),
+ paperRect.bottomRight() + QPointF(shWidth, 0));
+ QLinearGradient rgrad(rshadow.topLeft(), rshadow.topRight());
+ rgrad.setColorAt(0.0, QColor(0,0,0,255));
+ rgrad.setColorAt(1.0, QColor(0,0,0,0));
+ painter->fillRect(rshadow, QBrush(rgrad));
+ QRectF bshadow(paperRect.bottomLeft() + QPointF(shWidth, 0),
+ paperRect.bottomRight() + QPointF(0, shWidth));
+ QLinearGradient bgrad(bshadow.topLeft(), bshadow.bottomLeft());
+ bgrad.setColorAt(0.0, QColor(0,0,0,255));
+ bgrad.setColorAt(1.0, QColor(0,0,0,0));
+ painter->fillRect(bshadow, QBrush(bgrad));
+ QRectF cshadow(paperRect.bottomRight(),
+ paperRect.bottomRight() + QPointF(shWidth, shWidth));
+ QRadialGradient cgrad(cshadow.topLeft(), shWidth, cshadow.topLeft());
+ cgrad.setColorAt(0.0, QColor(0,0,0,255));
+ cgrad.setColorAt(1.0, QColor(0,0,0,0));
+ painter->fillRect(cshadow, QBrush(cgrad));
+
+ painter->setClipRect(paperRect & option->exposedRect);
+ painter->fillRect(paperRect, Qt::white);
+ if (!pagePicture)
+ return;
+ painter->drawPicture(pageRect.topLeft(), *pagePicture);
+
+ // Effect: make anything drawn in the margins look washed out.
+ QPainterPath path;
+ path.addRect(paperRect);
+ path.addRect(pageRect);
+ painter->setPen(QPen(Qt::NoPen));
+ painter->setBrush(QColor(255, 255, 255, 180));
+ painter->drawPath(path);
+
+#if 0
+ // Draw frame around paper.
+ painter->setPen(QPen(Qt::black, 0));
+ painter->setBrush(Qt::NoBrush);
+ painter->drawRect(paperRect);
+#endif
+
+ // todo: drawtext "Page N" below paper
+}
+
+class GraphicsView : public QGraphicsView
+{
+ Q_OBJECT
+public:
+ GraphicsView(QWidget* parent = 0)
+ : QGraphicsView(parent)
+ {
+#ifdef Q_WS_MAC
+ setFrameStyle(QFrame::NoFrame);
+#endif
+ }
+signals:
+ void resized();
+
+protected:
+ void resizeEvent(QResizeEvent* e)
+ {
+ QGraphicsView::resizeEvent(e);
+ emit resized();
+ }
+
+ void showEvent(QShowEvent* e)
+ {
+ QGraphicsView::showEvent(e);
+ emit resized();
+ }
+};
+
+} // anonymous namespace
+
+class QPrintPreviewWidgetPrivate : public QWidgetPrivate
+{
+ Q_DECLARE_PUBLIC(QPrintPreviewWidget)
+public:
+ QPrintPreviewWidgetPrivate()
+ : scene(0), curPage(1),
+ viewMode(QPrintPreviewWidget::SinglePageView),
+ zoomMode(QPrintPreviewWidget::FitInView),
+ zoomFactor(1), initialized(false), fitting(true)
+ {}
+
+ // private slots
+ void _q_fit(bool doFitting = false);
+ void _q_updateCurrentPage();
+
+ void init();
+ void populateScene();
+ void layoutPages();
+ void generatePreview();
+ void setCurrentPage(int pageNumber);
+ void zoom(qreal zoom);
+ void setZoomFactor(qreal zoomFactor);
+ int calcCurrentPage();
+
+ GraphicsView *graphicsView;
+ QGraphicsScene *scene;
+
+ int curPage;
+ QList<const QPicture *> pictures;
+ QList<QGraphicsItem *> pages;
+
+ QPrintPreviewWidget::ViewMode viewMode;
+ QPrintPreviewWidget::ZoomMode zoomMode;
+ qreal zoomFactor;
+ bool ownPrinter;
+ QPrinter* printer;
+ bool initialized;
+ bool fitting;
+};
+
+void QPrintPreviewWidgetPrivate::_q_fit(bool doFitting)
+{
+ Q_Q(QPrintPreviewWidget);
+
+ if (curPage < 1 || curPage > pages.count())
+ return;
+
+ if (!doFitting && !fitting)
+ return;
+
+ if (doFitting && fitting) {
+ QRect viewRect = graphicsView->viewport()->rect();
+ if (zoomMode == QPrintPreviewWidget::FitInView) {
+ QList<QGraphicsItem*> containedItems = graphicsView->items(viewRect, Qt::ContainsItemBoundingRect);
+ foreach(QGraphicsItem* item, containedItems) {
+ PageItem* pg = static_cast<PageItem*>(item);
+ if (pg->pageNumber() == curPage)
+ return;
+ }
+ }
+
+ int newPage = calcCurrentPage();
+ if (newPage != curPage)
+ curPage = newPage;
+ }
+
+ QRectF target = pages.at(curPage-1)->sceneBoundingRect();
+ if (viewMode == QPrintPreviewWidget::FacingPagesView) {
+ // fit two pages
+ if (curPage % 2)
+ target.setLeft(target.left() - target.width());
+ else
+ target.setRight(target.right() + target.width());
+ } else if (viewMode == QPrintPreviewWidget::AllPagesView) {
+ target = scene->itemsBoundingRect();
+ }
+
+ if (zoomMode == QPrintPreviewWidget::FitToWidth) {
+ QTransform t;
+ qreal scale = graphicsView->viewport()->width() / target.width();
+ t.scale(scale, scale);
+ graphicsView->setTransform(t);
+ if (doFitting && fitting) {
+ QRectF viewSceneRect = graphicsView->viewportTransform().mapRect(graphicsView->viewport()->rect());
+ viewSceneRect.moveTop(target.top());
+ graphicsView->ensureVisible(viewSceneRect); // Nah...
+ }
+ } else {
+ graphicsView->fitInView(target, Qt::KeepAspectRatio);
+ if (zoomMode == QPrintPreviewWidget::FitInView) {
+ int step = qRound(graphicsView->matrix().mapRect(target).height());
+ graphicsView->verticalScrollBar()->setSingleStep(step);
+ graphicsView->verticalScrollBar()->setPageStep(step);
+ }
+ }
+
+ zoomFactor = graphicsView->transform().m11() * (float(printer->logicalDpiY()) / q->logicalDpiY());
+ emit q->previewChanged();
+}
+
+void QPrintPreviewWidgetPrivate::_q_updateCurrentPage()
+{
+ Q_Q(QPrintPreviewWidget);
+
+ if (viewMode == QPrintPreviewWidget::AllPagesView)
+ return;
+
+ int newPage = calcCurrentPage();
+ if (newPage != curPage) {
+ curPage = newPage;
+ emit q->previewChanged();
+ }
+}
+
+int QPrintPreviewWidgetPrivate::calcCurrentPage()
+{
+ int maxArea = 0;
+ int newPage = curPage;
+ QRect viewRect = graphicsView->viewport()->rect();
+ QList<QGraphicsItem*> items = graphicsView->items(viewRect);
+ for (int i=0; i<items.size(); ++i) {
+ PageItem* pg = static_cast<PageItem*>(items.at(i));
+ QRect overlap = graphicsView->mapFromScene(pg->sceneBoundingRect()).boundingRect() & viewRect;
+ int area = overlap.width() * overlap.height();
+ if (area > maxArea) {
+ maxArea = area;
+ newPage = pg->pageNumber();
+ } else if (area == maxArea && pg->pageNumber() < newPage) {
+ newPage = pg->pageNumber();
+ }
+ }
+ return newPage;
+}
+
+void QPrintPreviewWidgetPrivate::init()
+{
+ Q_Q(QPrintPreviewWidget);
+
+ graphicsView = new GraphicsView;
+ graphicsView->setInteractive(false);
+ graphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
+ graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
+ QObject::connect(graphicsView->verticalScrollBar(), SIGNAL(valueChanged(int)),
+ q, SLOT(_q_updateCurrentPage()));
+ QObject::connect(graphicsView, SIGNAL(resized()), q, SLOT(_q_fit()));
+
+ scene = new QGraphicsScene(graphicsView);
+ scene->setBackgroundBrush(Qt::gray);
+ graphicsView->setScene(scene);
+
+ QVBoxLayout *layout = new QVBoxLayout;
+ q->setLayout(layout);
+ layout->setContentsMargins(0, 0, 0, 0);
+ layout->addWidget(graphicsView);
+}
+
+void QPrintPreviewWidgetPrivate::populateScene()
+{
+ // remove old pages
+ for (int i = 0; i < pages.size(); i++)
+ scene->removeItem(pages.at(i));
+ qDeleteAll(pages);
+ pages.clear();
+
+ int numPages = pictures.count();
+ QSize paperSize = printer->paperRect().size();
+ QRect pageRect = printer->pageRect();
+
+ for (int i = 0; i < numPages; i++) {
+ PageItem* item = new PageItem(i+1, pictures.at(i), paperSize, pageRect);
+ scene->addItem(item);
+ pages.append(item);
+ }
+}
+
+void QPrintPreviewWidgetPrivate::layoutPages()
+{
+ int numPages = pages.count();
+ if (numPages < 1)
+ return;
+
+ int numPagePlaces = numPages;
+ int cols = 1; // singleMode and default
+ if (viewMode == QPrintPreviewWidget::AllPagesView) {
+ if (printer->orientation() == QPrinter::Portrait)
+ cols = qCeil(qSqrt((float) numPages));
+ else
+ cols = qFloor(qSqrt((float) numPages));
+ cols += cols % 2; // Nicer with an even number of cols
+ }
+ else if (viewMode == QPrintPreviewWidget::FacingPagesView) {
+ cols = 2;
+ numPagePlaces += 1;
+ }
+ int rows = qCeil(qreal(numPagePlaces) / cols);
+
+ qreal itemWidth = pages.at(0)->boundingRect().width();
+ qreal itemHeight = pages.at(0)->boundingRect().height();
+ int pageNum = 1;
+ for (int i = 0; i < rows && pageNum <= numPages; i++) {
+ for (int j = 0; j < cols && pageNum <= numPages; j++) {
+ if (!i && !j && viewMode == QPrintPreviewWidget::FacingPagesView) {
+ // Front page doesn't have a facing page
+ continue;
+ } else {
+ pages.at(pageNum-1)->setPos(QPointF(j*itemWidth, i*itemHeight));
+ pageNum++;
+ }
+ }
+ }
+ scene->setSceneRect(scene->itemsBoundingRect());
+}
+
+void QPrintPreviewWidgetPrivate::generatePreview()
+{
+ //### If QPrinter::setPreviewMode() becomes public, handle the
+ //### case that we have been constructed with a printer that
+ //### _already_ has been preview-painted to, so we should
+ //### initially just show the pages it already contains, and not
+ //### emit paintRequested() until the user changes some parameter
+
+ Q_Q(QPrintPreviewWidget);
+ printer->d_func()->setPreviewMode(true);
+ emit q->paintRequested(printer);
+ printer->d_func()->setPreviewMode(false);
+ pictures = printer->d_func()->previewPages();
+ populateScene(); // i.e. setPreviewPrintedPictures() e.l.
+ layoutPages();
+ curPage = qBound(1, curPage, pages.count());
+ if (fitting)
+ _q_fit();
+ emit q->previewChanged();
+}
+
+void QPrintPreviewWidgetPrivate::setCurrentPage(int pageNumber)
+{
+ if (pageNumber < 1 || pageNumber > pages.count())
+ return;
+
+ int lastPage = curPage;
+ curPage = pageNumber;
+
+ if (lastPage != curPage && lastPage > 0 && lastPage <= pages.count()) {
+ if (zoomMode != QPrintPreviewWidget::FitInView) {
+ QScrollBar *hsc = graphicsView->horizontalScrollBar();
+ QScrollBar *vsc = graphicsView->verticalScrollBar();
+ QPointF pt = graphicsView->transform().map(pages.at(curPage-1)->pos());
+ vsc->setValue(int(pt.y()) - 10);
+ hsc->setValue(int(pt.x()) - 10);
+ } else {
+ graphicsView->centerOn(pages.at(curPage-1));
+ }
+ }
+}
+
+void QPrintPreviewWidgetPrivate::zoom(qreal zoom)
+{
+ zoomFactor *= zoom;
+ graphicsView->scale(zoom, zoom);
+}
+
+void QPrintPreviewWidgetPrivate::setZoomFactor(qreal _zoomFactor)
+{
+ Q_Q(QPrintPreviewWidget);
+ zoomFactor = _zoomFactor;
+ graphicsView->resetTransform();
+ int dpi_y = q->logicalDpiY();
+ int printer_dpi_y = printer->logicalDpiY();
+ graphicsView->scale(zoomFactor*(dpi_y/float(printer_dpi_y)),
+ zoomFactor*(dpi_y/float(printer_dpi_y)));
+}
+
+///////////////////////////////////////
+
+/*!
+ \class QPrintPreviewWidget
+ \since 4.4
+
+ \brief The QPrintPreviewWidget class provides a widget for
+ previewing page layouts for printer output.
+
+ \ingroup printing
+
+ QPrintPreviewDialog uses a QPrintPreviewWidget internally, and the
+ purpose of QPrintPreviewWidget is to make it possible to embed the
+ preview into other widgets. It also makes it possible to build a different
+ user interface around it than the default one provided with QPrintPreviewDialog.
+
+ Using QPrintPreviewWidget is straightforward:
+
+ \list 1
+ \o Create the QPrintPreviewWidget
+
+ Construct the QPrintPreviewWidget either by passing in an
+ existing QPrinter object, or have QPrintPreviewWidget create a
+ default constructed QPrinter object for you.
+
+ \o Connect the paintRequested() signal to a slot.
+
+ When the widget needs to generate a set of preview pages, a
+ paintRequested() signal will be emitted from the widget. Connect a
+ slot to this signal, and draw onto the QPrinter passed in as a
+ signal parameter. Call QPrinter::newPage(), to start a new
+ page in the preview.
+
+ \endlist
+
+ \sa QPrinter, QPrintDialog, QPageSetupDialog, QPrintPreviewDialog
+*/
+
+
+/*!
+ \enum QPrintPreviewWidget::ViewMode
+
+ This enum is used to describe the view mode of the preview widget.
+
+ \value SinglePageView A mode where single pages in the preview
+ is viewed.
+
+ \value FacingPagesView A mode where the facing pages in the preview
+ is viewed.
+
+ \value AllPagesView A view mode where all the pages in the preview
+ is viewed.
+*/
+
+/*!
+ \enum QPrintPreviewWidget::ZoomMode
+
+ This enum is used to describe zoom mode of the preview widget.
+
+ \value CustomZoom The zoom is set to a custom zoom value.
+
+ \value FitToWidth This mode fits the current page to the width of the view.
+
+ \value FitInView This mode fits the current page inside the view.
+
+*/
+
+/*!
+ Constructs a QPrintPreviewWidget based on \a printer and with \a
+ parent as the parent widget. The widget flags \a flags are passed on
+ to the QWidget constructor.
+
+ \sa QWidget::setWindowFlags()
+*/
+QPrintPreviewWidget::QPrintPreviewWidget(QPrinter *printer, QWidget *parent, Qt::WindowFlags flags)
+ : QWidget(*new QPrintPreviewWidgetPrivate, parent, flags)
+{
+ Q_D(QPrintPreviewWidget);
+ d->printer = printer;
+ d->ownPrinter = false;
+ d->init();
+}
+
+/*!
+ \overload
+
+ This will cause QPrintPreviewWidget to create an internal, default
+ constructed QPrinter object, which will be used to generate the
+ preview.
+*/
+QPrintPreviewWidget::QPrintPreviewWidget(QWidget *parent, Qt::WindowFlags flags)
+ : QWidget(*new QPrintPreviewWidgetPrivate, parent, flags)
+{
+ Q_D(QPrintPreviewWidget);
+ d->printer = new QPrinter;
+ d->ownPrinter = true;
+ d->init();
+}
+
+
+/*!
+ Destroys the QPrintPreviewWidget.
+*/
+QPrintPreviewWidget::~QPrintPreviewWidget()
+{
+ Q_D(QPrintPreviewWidget);
+ if (d->ownPrinter)
+ delete d->printer;
+}
+
+/*!
+ Returns the current view mode. The default view mode is SinglePageView.
+*/
+QPrintPreviewWidget::ViewMode QPrintPreviewWidget::viewMode() const
+{
+ Q_D(const QPrintPreviewWidget);
+ return d->viewMode;
+}
+
+/*!
+ Sets the view mode to \a mode. The default view mode is
+ SinglePageView.
+*/
+void QPrintPreviewWidget::setViewMode(ViewMode mode)
+{
+ Q_D(QPrintPreviewWidget);
+ d->viewMode = mode;
+ d->layoutPages();
+ if (d->viewMode == AllPagesView) {
+ d->graphicsView->fitInView(d->scene->itemsBoundingRect(), Qt::KeepAspectRatio);
+ d->fitting = false;
+ d->zoomMode = QPrintPreviewWidget::CustomZoom;
+ d->zoomFactor = d->graphicsView->transform().m11() * (float(d->printer->logicalDpiY()) / logicalDpiY());
+ emit previewChanged();
+ } else {
+ d->fitting = true;
+ d->_q_fit();
+ }
+}
+
+/*!
+ Returns the current orientation of the preview. This value is
+ obtained from the QPrinter object associated with the preview.
+*/
+QPrinter::Orientation QPrintPreviewWidget::orientation() const
+{
+ Q_D(const QPrintPreviewWidget);
+ return d->printer->orientation();
+}
+
+/*!
+ Sets the current orientation to \a orientation. This value will be
+ set on the QPrinter object associated with the preview.
+*/
+void QPrintPreviewWidget::setOrientation(QPrinter::Orientation orientation)
+{
+ Q_D(QPrintPreviewWidget);
+ d->printer->setOrientation(orientation);
+ d->generatePreview();
+}
+
+/*!
+ Prints the preview to the printer associated with the preview.
+*/
+void QPrintPreviewWidget::print()
+{
+ Q_D(QPrintPreviewWidget);
+ // ### make use of the generated pages
+ emit paintRequested(d->printer);
+}
+
+/*!
+ Zooms the current view in by \a factor. The default value for \a
+ factor is 1.1, which means the view will be scaled up by 10%.
+*/
+void QPrintPreviewWidget::zoomIn(qreal factor)
+{
+ Q_D(QPrintPreviewWidget);
+ d->fitting = false;
+ d->zoomMode = QPrintPreviewWidget::CustomZoom;
+ d->zoom(factor);
+}
+
+/*!
+ Zooms the current view out by \a factor. The default value for \a
+ factor is 1.1, which means the view will be scaled down by 10%.
+*/
+void QPrintPreviewWidget::zoomOut(qreal factor)
+{
+ Q_D(QPrintPreviewWidget);
+ d->fitting = false;
+ d->zoomMode = QPrintPreviewWidget::CustomZoom;
+ d->zoom(1/factor);
+}
+
+/*!
+ Returns the zoom factor of the view.
+*/
+qreal QPrintPreviewWidget::zoomFactor() const
+{
+ Q_D(const QPrintPreviewWidget);
+ return d->zoomFactor;
+}
+
+/*!
+ Sets the zoom factor of the view to \a factor. For example, a
+ value of 1.0 indicates an unscaled view, which is approximately
+ the size the view will have on paper. A value of 0.5 will halve
+ the size of the view, while a value of 2.0 will double the size of
+ the view.
+*/
+void QPrintPreviewWidget::setZoomFactor(qreal factor)
+{
+ Q_D(QPrintPreviewWidget);
+ d->fitting = false;
+ d->zoomMode = QPrintPreviewWidget::CustomZoom;
+ d->setZoomFactor(factor);
+}
+
+/*!
+ \obsolete
+ Returns the number of pages in the preview.
+ \sa pageCount()
+*/
+int QPrintPreviewWidget::numPages() const
+{
+ Q_D(const QPrintPreviewWidget);
+ return d->pages.size();
+}
+
+/*!
+ \since 4.6
+ Returns the number of pages in the preview.
+*/
+int QPrintPreviewWidget::pageCount() const
+{
+ Q_D(const QPrintPreviewWidget);
+ return d->pages.size();
+}
+
+/*!
+ Returns the currently viewed page in the preview.
+*/
+int QPrintPreviewWidget::currentPage() const
+{
+ Q_D(const QPrintPreviewWidget);
+ return d->curPage;
+}
+
+/*!
+ Sets the current page in the preview. This will cause the view to
+ skip to the beginning of \a page.
+*/
+void QPrintPreviewWidget::setCurrentPage(int page)
+{
+ Q_D(QPrintPreviewWidget);
+ d->setCurrentPage(page);
+}
+
+/*!
+ This is a convenience function and is the same as calling \c
+ {setZoomMode(QPrintPreviewWidget::FitToWidth)}.
+*/
+void QPrintPreviewWidget::fitToWidth()
+{
+ setZoomMode(FitToWidth);
+}
+
+/*!
+ This is a convenience function and is the same as calling \c
+ {setZoomMode(QPrintPreviewWidget::FitInView)}.
+*/
+void QPrintPreviewWidget::fitInView()
+{
+ setZoomMode(FitInView);
+}
+
+/*!
+ Sets the zoom mode to \a zoomMode. The default zoom mode is FitInView.
+
+ \sa zoomMode(), viewMode(), setViewMode()
+*/
+void QPrintPreviewWidget::setZoomMode(QPrintPreviewWidget::ZoomMode zoomMode)
+{
+ Q_D(QPrintPreviewWidget);
+ d->zoomMode = zoomMode;
+ if (d->zoomMode == FitInView || d->zoomMode == FitToWidth) {
+ d->fitting = true;
+ d->_q_fit(true);
+ } else {
+ d->fitting = false;
+ }
+}
+
+/*!
+ Returns the current zoom mode.
+
+ \sa setZoomMode(), viewMode(), setViewMode()
+*/
+QPrintPreviewWidget::ZoomMode QPrintPreviewWidget::zoomMode() const
+{
+ Q_D(const QPrintPreviewWidget);
+ return d->zoomMode;
+}
+
+/*!
+ This is a convenience function and is the same as calling \c
+ {setOrientation(QPrinter::Landscape)}.
+*/
+void QPrintPreviewWidget::setLandscapeOrientation()
+{
+ setOrientation(QPrinter::Landscape);
+}
+
+/*!
+ This is a convenience function and is the same as calling \c
+ {setOrientation(QPrinter::Portrait)}.
+*/
+void QPrintPreviewWidget::setPortraitOrientation()
+{
+ setOrientation(QPrinter::Portrait);
+}
+
+/*!
+ This is a convenience function and is the same as calling \c
+ {setViewMode(QPrintPreviewWidget::SinglePageView)}.
+*/
+void QPrintPreviewWidget::setSinglePageViewMode()
+{
+ setViewMode(SinglePageView);
+}
+
+/*!
+ This is a convenience function and is the same as calling \c
+ {setViewMode(QPrintPreviewWidget::FacingPagesView)}.
+*/
+void QPrintPreviewWidget::setFacingPagesViewMode()
+{
+ setViewMode(FacingPagesView);
+}
+
+/*!
+ This is a convenience function and is the same as calling \c
+ {setViewMode(QPrintPreviewWidget::AllPagesView)}.
+*/
+void QPrintPreviewWidget::setAllPagesViewMode()
+{
+ setViewMode(AllPagesView);
+}
+
+
+/*!
+ This function updates the preview, which causes the
+ paintRequested() signal to be emitted.
+*/
+void QPrintPreviewWidget::updatePreview()
+{
+ Q_D(QPrintPreviewWidget);
+ d->initialized = true;
+ d->generatePreview();
+ d->graphicsView->updateGeometry();
+}
+
+/*! \reimp
+*/
+void QPrintPreviewWidget::setVisible(bool visible)
+{
+ Q_D(QPrintPreviewWidget);
+ if (visible && !d->initialized)
+ updatePreview();
+ QWidget::setVisible(visible);
+}
+
+/*!
+ \fn void QPrintPreviewWidget::paintRequested(QPrinter *printer)
+
+ This signal is emitted when the preview widget needs to generate a
+ set of preview pages. \a printer is the printer associated with
+ this preview widget.
+*/
+
+/*!
+ \fn void QPrintPreviewWidget::previewChanged()
+
+ This signal is emitted whenever the preview widget has changed
+ some internal state, such as the orientation.
+*/
+
+
+QT_END_NAMESPACE
+
+#include "moc_qprintpreviewwidget.cpp"
+#include "qprintpreviewwidget.moc"
+
+#endif // QT_NO_PRINTPREVIEWWIDGET
diff --git a/src/printsupport/widgets/qprintpreviewwidget.h b/src/printsupport/widgets/qprintpreviewwidget.h
new file mode 100644
index 0000000000..6a90755813
--- /dev/null
+++ b/src/printsupport/widgets/qprintpreviewwidget.h
@@ -0,0 +1,127 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QPRINTPREVIEWWIDGET_H
+#define QPRINTPREVIEWWIDGET_H
+
+#include <QtWidgets/qwidget.h>
+#include <QtPrintSupport/qprinter.h>
+
+#ifndef QT_NO_PRINTPREVIEWWIDGET
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+class QPrintPreviewWidgetPrivate;
+
+class Q_WIDGETS_EXPORT QPrintPreviewWidget : public QWidget
+{
+ Q_OBJECT
+ Q_DECLARE_PRIVATE(QPrintPreviewWidget)
+public:
+
+ enum ViewMode {
+ SinglePageView,
+ FacingPagesView,
+ AllPagesView
+ };
+
+ enum ZoomMode {
+ CustomZoom,
+ FitToWidth,
+ FitInView
+ };
+
+ explicit QPrintPreviewWidget(QPrinter *printer, QWidget *parent = 0, Qt::WindowFlags flags = 0);
+ explicit QPrintPreviewWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0);
+ ~QPrintPreviewWidget();
+
+ qreal zoomFactor() const;
+ QPrinter::Orientation orientation() const;
+ ViewMode viewMode() const;
+ ZoomMode zoomMode() const;
+ int currentPage() const;
+#ifdef QT_DEPRECATED
+ QT_DEPRECATED int numPages() const;
+#endif
+ int pageCount() const;
+ void setVisible(bool visible);
+
+public Q_SLOTS:
+ void print();
+
+ void zoomIn(qreal zoom = 1.1);
+ void zoomOut(qreal zoom = 1.1);
+ void setZoomFactor(qreal zoomFactor);
+ void setOrientation(QPrinter::Orientation orientation);
+ void setViewMode(ViewMode viewMode);
+ void setZoomMode(ZoomMode zoomMode);
+ void setCurrentPage(int pageNumber);
+
+ void fitToWidth();
+ void fitInView();
+ void setLandscapeOrientation();
+ void setPortraitOrientation();
+ void setSinglePageViewMode();
+ void setFacingPagesViewMode();
+ void setAllPagesViewMode();
+
+ void updatePreview();
+
+Q_SIGNALS:
+ void paintRequested(QPrinter *printer);
+ void previewChanged();
+
+private:
+ void *dummy; // ### remove in Qt 5.0
+ Q_PRIVATE_SLOT(d_func(), void _q_fit())
+ Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentPage())
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QT_NO_PRINTPREVIEWWIDGET
+#endif // QPRINTPREVIEWWIDGET_H
diff --git a/src/printsupport/widgets/widgets.pri b/src/printsupport/widgets/widgets.pri
new file mode 100644
index 0000000000..40eb306623
--- /dev/null
+++ b/src/printsupport/widgets/widgets.pri
@@ -0,0 +1,2 @@
+HEADERS += widgets/qprintpreviewwidget.h
+SOURCES += widgets/qprintpreviewwidget.cpp