summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Klapetek <mklapetek@kde.org>2013-09-12 15:19:00 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-17 14:24:48 +0200
commit75ffb131ed13183ef65a04e12d7506dedc0f1aaa (patch)
treec0605c021e416ce2a3fc25716aca33a5cfcaa7c1 /src
parentf098148ebc04ac3297c72e2564853e80d43425b1 (diff)
Add CUPS Page Set options to print support
Adds combobox to select CUPS Page Set option (even/odd pages) into the Unix print dialog [ChangeLog][QtPrintSupport][QPrintDialog] Added support for setting CUPS Page Set (even/odd pages only) in the print dialog. Change-Id: I27dd846f58c164039fe2759064aafdf726a1287e Reviewed-by: John Layt <jlayt@kde.org>
Diffstat (limited to 'src')
-rw-r--r--src/printsupport/dialogs/qprintdialog.h1
-rw-r--r--src/printsupport/dialogs/qprintdialog_unix.cpp83
-rw-r--r--src/printsupport/dialogs/qprintsettingsoutput.ui29
-rw-r--r--src/printsupport/kernel/qcups.cpp21
-rw-r--r--src/printsupport/kernel/qcups_p.h9
5 files changed, 136 insertions, 7 deletions
diff --git a/src/printsupport/dialogs/qprintdialog.h b/src/printsupport/dialogs/qprintdialog.h
index 7d77c6af07..c822aa0533 100644
--- a/src/printsupport/dialogs/qprintdialog.h
+++ b/src/printsupport/dialogs/qprintdialog.h
@@ -107,6 +107,7 @@ Q_SIGNALS:
private:
#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
Q_PRIVATE_SLOT(d_func(), void _q_chbPrintLastFirstToggled(bool))
+ Q_PRIVATE_SLOT(d_func(), void _q_togglePageSetCombo(bool))
Q_PRIVATE_SLOT(d_func(), void _q_collapseOrExpandDialog())
# if !defined(QT_NO_MESSAGEBOX)
Q_PRIVATE_SLOT(d_func(), void _q_checkFields())
diff --git a/src/printsupport/dialogs/qprintdialog_unix.cpp b/src/printsupport/dialogs/qprintdialog_unix.cpp
index 3b45410e6f..eb4ce6840f 100644
--- a/src/printsupport/dialogs/qprintdialog_unix.cpp
+++ b/src/printsupport/dialogs/qprintdialog_unix.cpp
@@ -195,9 +195,10 @@ public:
/// copy printer properties to the widget
void applyPrinterProperties();
- void selectPrinter();
+ void selectPrinter(const QPrinter::OutputFormat outputFormat);
void _q_chbPrintLastFirstToggled(bool);
+ void _q_togglePageSetCombo(bool);
#ifndef QT_NO_MESSAGEBOX
void _q_checkFields();
#endif
@@ -213,6 +214,7 @@ public:
QWidget *bottom;
QDialogButtonBox *buttons;
QPushButton *collapseButton;
+ QPrinter::OutputFormat printerOutputFormat;
};
@@ -320,6 +322,16 @@ void QPrintDialogPrivate::init()
options.color->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-color.png")));
options.grayscale->setIconSize(QSize(32, 32));
options.grayscale->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-gray-scale.png")));
+
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ // Add Page Set widget if CUPS is available
+ if (QCUPSSupport::isAvailable()) {
+ options.pageSetCombo->addItem(tr("All Pages"), QVariant::fromValue(QCUPSSupport::AllPages));
+ options.pageSetCombo->addItem(tr("Odd Pages"), QVariant::fromValue(QCUPSSupport::OddPages));
+ options.pageSetCombo->addItem(tr("Even Pages"), QVariant::fromValue(QCUPSSupport::EvenPages));
+ }
+#endif
+
top->d->setOptionsPane(this);
buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q);
@@ -347,14 +359,21 @@ void QPrintDialogPrivate::init()
QObject::connect(options.reverse, SIGNAL(toggled(bool)),
q, SLOT(_q_chbPrintLastFirstToggled(bool)));
+ QObject::connect(options.printSelection, SIGNAL(toggled(bool)),
+ q, SLOT(_q_togglePageSetCombo(bool)));
+
+ QObject::connect(options.printCurrentPage, SIGNAL(toggled(bool)),
+ q, SLOT(_q_togglePageSetCombo(bool)));
+
QObject::connect(collapseButton, SIGNAL(released()), q, SLOT(_q_collapseOrExpandDialog()));
}
// initialize printer options
-void QPrintDialogPrivate::selectPrinter()
+void QPrintDialogPrivate::selectPrinter(const QPrinter::OutputFormat outputFormat)
{
Q_Q(QPrintDialog);
QPrinter *p = q->printer();
+ printerOutputFormat = outputFormat;
if (p->colorMode() == QPrinter::Color)
options.color->setChecked(true);
@@ -373,6 +392,13 @@ void QPrintDialogPrivate::selectPrinter()
options.copies->setValue(p->copyCount());
options.collate->setChecked(p->collateCopies());
options.reverse->setChecked(p->pageOrder() == QPrinter::LastPageFirst);
+
+ if (outputFormat == QPrinter::PdfFormat || options.printSelection->isChecked()
+ || options.printCurrentPage->isChecked())
+
+ options.pageSetCombo->setEnabled(false);
+ else
+ options.pageSetCombo->setEnabled(true);
}
void QPrintDialogPrivate::applyPrinterProperties()
@@ -412,6 +438,22 @@ void QPrintDialogPrivate::setupPrinter()
p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value()));
}
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ // page set
+ if (QCUPSSupport::isAvailable() && (p->printRange() == QPrinter::AllPages || p->printRange() == QPrinter::PageRange)) {
+ //If the application is selecting pages and the first page number is even then need to adjust the odd-even accordingly
+ QCUPSSupport::PageSet pageSet = options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()).value<QCUPSSupport::PageSet>();
+ if (p->printRange() == QPrinter::PageRange && (q->fromPage() % 2 == 0)) {
+ if (pageSet == QCUPSSupport::OddPages)
+ QCUPSSupport::setPageSet(p, QCUPSSupport::EvenPages);
+ else if (pageSet == QCUPSSupport::EvenPages)
+ QCUPSSupport::setPageSet(p, QCUPSSupport::OddPages);
+ } else if (pageSet != QCUPSSupport::AllPages) {
+ QCUPSSupport::setPageSet(p, pageSet);
+ }
+ }
+#endif
+
// copies
p->setCopyCount(options.copies->value());
p->setCollateCopies(options.collate->isChecked());
@@ -428,6 +470,14 @@ void QPrintDialogPrivate::_q_chbPrintLastFirstToggled(bool checked)
q->printer()->setPageOrder(QPrinter::FirstPageFirst);
}
+void QPrintDialogPrivate::_q_togglePageSetCombo(bool checked)
+{
+ if (printerOutputFormat == QPrinter::PdfFormat)
+ return;
+
+ options.pageSetCombo->setDisabled(checked);
+}
+
void QPrintDialogPrivate::_q_collapseOrExpandDialog()
{
int collapseHeight = 0;
@@ -468,19 +518,40 @@ void QPrintDialogPrivate::updateWidgets()
options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage));
options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies));
+#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
+ if (QCUPSSupport::isAvailable()) {
+ // Don't display Page Set if only Selection or Current Page are enabled
+ if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) && (
+ q->isOptionEnabled(QPrintDialog::PrintSelection) ||
+ q->isOptionEnabled(QPrintDialog::PrintCurrentPage))) {
+
+ options.pageSetCombo->setVisible(false);
+ options.pageSetLabel->setVisible(false);
+ } else {
+ options.pageSetCombo->setVisible(true);
+ options.pageSetLabel->setVisible(true);
+ }
+ }
+#endif
+
switch (q->printRange()) {
case QPrintDialog::AllPages:
options.printAll->setChecked(true);
+ options.pageSetCombo->setEnabled(true);
break;
case QPrintDialog::Selection:
options.printSelection->setChecked(true);
+ options.pageSetCombo->setEnabled(false);
break;
case QPrintDialog::PageRange:
options.printRange->setChecked(true);
+ options.pageSetCombo->setEnabled(true);
break;
case QPrintDialog::CurrentPage:
- if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage))
+ if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage)) {
options.printCurrentPage->setChecked(true);
+ options.pageSetCombo->setEnabled(false);
+ }
break;
default:
break;
@@ -676,7 +747,7 @@ void QUnixPrintWidgetPrivate::_q_printerChanged(int index)
widget.filename->setText(filename);
widget.lOutput->setEnabled(true);
if (optionsPane)
- optionsPane->selectPrinter();
+ optionsPane->selectPrinter(QPrinter::PdfFormat);
return;
}
}
@@ -689,7 +760,7 @@ void QUnixPrintWidgetPrivate::_q_printerChanged(int index)
widget.location->setText(printerInfo.location());
widget.type->setText(printerInfo.makeAndModel());
if (optionsPane)
- optionsPane->selectPrinter();
+ optionsPane->selectPrinter(QPrinter::NativeFormat);
}
}
@@ -697,7 +768,7 @@ void QUnixPrintWidgetPrivate::setOptionsPane(QPrintDialogPrivate *pane)
{
optionsPane = pane;
if (optionsPane)
- optionsPane->selectPrinter();
+ optionsPane->selectPrinter(QPrinter::NativeFormat);
}
void QUnixPrintWidgetPrivate::_q_btnBrowseClicked()
diff --git a/src/printsupport/dialogs/qprintsettingsoutput.ui b/src/printsupport/dialogs/qprintsettingsoutput.ui
index be916790fb..0fa34ab27f 100644
--- a/src/printsupport/dialogs/qprintsettingsoutput.ui
+++ b/src/printsupport/dialogs/qprintsettingsoutput.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>426</width>
- <height>171</height>
+ <height>187</height>
</rect>
</property>
<property name="windowTitle">
@@ -133,6 +133,33 @@
</widget>
</item>
<item>
+ <layout class="QHBoxLayout" name="_5">
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="pageSetLabel">
+ <property name="text">
+ <string>Page Set:</string>
+ </property>
+ <property name="visible">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QComboBox" name="pageSetCombo">
+ <property name="visible">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
diff --git a/src/printsupport/kernel/qcups.cpp b/src/printsupport/kernel/qcups.cpp
index cf71e92e95..a10baaa7fb 100644
--- a/src/printsupport/kernel/qcups.cpp
+++ b/src/printsupport/kernel/qcups.cpp
@@ -490,6 +490,27 @@ void QCUPSSupport::setBannerPages(QPrinter *printer, const BannerPage startBanne
setCupsOptions(printer, cupsOptions);
}
+void QCUPSSupport::setPageSet(QPrinter *printer, const PageSet pageSet)
+{
+ QStringList cupsOptions = cupsOptionsList(printer);
+ QString pageSetString;
+
+ switch (pageSet) {
+ case OddPages:
+ pageSetString = QStringLiteral("odd");
+ break;
+ case EvenPages:
+ pageSetString = QStringLiteral("even");
+ break;
+ case AllPages:
+ pageSetString = QStringLiteral("all");
+ break;
+ }
+
+ setCupsOption(cupsOptions, QStringLiteral("page-set"), pageSetString);
+ setCupsOptions(printer, cupsOptions);
+}
+
bool QCUPSSupport::printerHasPPD(const char *printerName)
{
if (!isAvailable())
diff --git a/src/printsupport/kernel/qcups_p.h b/src/printsupport/kernel/qcups_p.h
index 8e82b35e12..412c50cfac 100644
--- a/src/printsupport/kernel/qcups_p.h
+++ b/src/printsupport/kernel/qcups_p.h
@@ -114,6 +114,13 @@ public:
TopSecret
};
+ // Enum for valid page set
+ enum PageSet {
+ AllPages = 0, //CUPS Default
+ OddPages,
+ EvenPages
+ };
+
static bool isAvailable();
static int cupsVersion() { return isAvailable() ? CUPS_VERSION_MAJOR*10000+CUPS_VERSION_MINOR*100+CUPS_VERSION_PATCH : 0; }
int availablePrintersCount() const;
@@ -143,6 +150,7 @@ public:
static void setJobBilling(QPrinter *printer, const QString &jobBilling = QString());
static void setJobPriority(QPrinter *printer, int priority = 50);
static void setBannerPages(QPrinter *printer, const BannerPage startBannerPage, const BannerPage endBannerPage);
+ static void setPageSet(QPrinter *printer, const PageSet pageSet);
static bool printerHasPPD(const char *printerName);
@@ -174,6 +182,7 @@ QT_END_NAMESPACE
Q_DECLARE_METATYPE(QCUPSSupport::JobHoldUntil)
Q_DECLARE_METATYPE(QCUPSSupport::BannerPage)
+Q_DECLARE_METATYPE(QCUPSSupport::PageSet)
#endif // QT_NO_CUPS