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>bb10
parent
f098148ebc
commit
75ffb131ed
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>426</width>
|
||||
<height>171</height>
|
||||
<height>187</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
|
@ -132,6 +132,33 @@
|
|||
</property>
|
||||
</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">
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue