Skip to content

Commit 4c07d35

Browse files
TinyTrebuchetabrarnasirjaffari
authored andcommitted
Add support for dynamically loading print plugins
Scraped out CUPS & CPDB specific code from print dialog frontend, and put it in their respective print plugin directories. This allows the print dialog to be able to dynamically select print backends at runtime instead of having to choose one at build time. Change-Id: I8ae53d19d91aa9689ec327fd8077558744e4768b
1 parent a4ff501 commit 4c07d35

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/printsupport/dialogs/qprintdialog_unix.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ private Q_SLOTS:
133133
bool anyAdvancedOptionConflict() const;
134134

135135

136+
Ui::QPrintPropertiesWidget widget;
137+
QDialogButtonBox *m_buttons;
138+
136139
Ui::QPrintPropertiesWidget widget;
137140
QDialogButtonBox *m_buttons;
138141
QPrintDevice *m_currentPrintDevice;
@@ -324,6 +327,24 @@ QPrintPropertiesDialog::QPrintPropertiesDialog(QPrinter *printer, QPrintDevice *
324327
widget.tabs->setTabEnabled(advancedTabIndex, false);
325328
}
326329

330+
if (currentPrintDevice->isFeatureAvailable(QPrintDevice::PDPK_JobHold, QVariant())
331+
|| currentPrintDevice->isFeatureAvailable(QPrintDevice::PDPK_JobBillingInfo, QVariant())
332+
|| currentPrintDevice->isFeatureAvailable(QPrintDevice::PDPK_JobPriority, QVariant())
333+
|| currentPrintDevice->isFeatureAvailable(QPrintDevice::PDPK_JobStartCoverPage, QVariant())
334+
|| currentPrintDevice->isFeatureAvailable(QPrintDevice::PDPK_JobEndCoverPage, QVariant()))
335+
{
336+
m_jobOptions = new QPrintJobWidget(printer, currentPrintDevice, this);
337+
widget.tabs->insertTab(1, m_jobOptions, tr("Job Options"));
338+
}
339+
340+
const int advancedTabIndex = widget.tabs->indexOf(widget.cupsPropertiesPage);
341+
if (currentPrintDevice->isFeatureAvailable(QPrintDevice::PDPK_AdvancedOptions, QVariant())) {
342+
widget.tabs->setTabEnabled(advancedTabIndex, true);
343+
widget.scrollArea->setWidget(createAdvancedOptionsWidget(currentPrintDevice));
344+
} else {
345+
widget.tabs->setTabEnabled(advancedTabIndex, false);
346+
}
347+
327348
widget.conflictsLabel->setVisible(anyAdvancedOptionConflict());
328349
}
329350

@@ -341,6 +362,9 @@ void QPrintPropertiesDialog::setupPrinter() const
341362
if (m_jobOptions)
342363
m_currentPrintDevice->setProperty(QPrintDevice::PDPK_AdvancedOptions, QVariant(QByteArray("#clear#")));
343364

365+
widget.pageSetup->setupPrinter();
366+
m_currentPrintDevice->setProperty(QPrintDevice::PDPK_AdvancedOptions, QVariant(QByteArray("#clear#")));
367+
344368
widget.pageSetup->setupPrinter();
345369

346370
if (m_jobOptions) {
@@ -533,6 +557,10 @@ static const char *ppdOptionProperty = "_q_ppd_option";
533557
QDialog::showEvent(event);
534558
}
535559

560+
widget.conflictsLabel->setVisible(anyAdvancedOptionConflict());
561+
QDialog::showEvent(event);
562+
}
563+
536564
// Used to store the option name for each QComboBox that represents an advanced option
537565
static const char *optionNameProperty = "_q_print_option_name";
538566

@@ -651,6 +679,9 @@ bool QPrintPropertiesDialog::createAdvancedOptionsWidget()
651679

652680
if (qstrcmp(option->defchoice, selectedChoice) != 0)
653681
void QPrintPropertiesDialog::setPrinterAdvancedOptions() const
682+
{
683+
for (const QComboBox *choicesCb : m_advancedOptionsCombos) {
684+
void QPrintPropertiesDialog::setPrinterAdvancedOptions() const
654685
{
655686
for (const QComboBox *choicesCb : m_advancedOptionsCombos) {
656687
QByteArray optionName = qvariant_cast<QByteArray>(choicesCb->property(optionNameProperty));
@@ -809,6 +840,7 @@ void QPrintDialogPrivate::selectPrinter(const QPrinter::OutputFormat outputForma
809840
options.duplexShort->setEnabled(supportedDuplexMode.contains(QPrint::DuplexShortSide));
810841

811842
// support feature PDPK_AdvancedColorMode if you want to display Color option separately
843+
// among other advanced options in QPrintProperties dialog (eg. CUPS)
812844
if (top->d->m_currentPrintDevice.isFeatureAvailable(QPrintDevice::PDPK_AdvancedColorMode, QVariant())) {
813845
options.colorMode->setEnabled(false);
814846
} else {
@@ -891,6 +923,10 @@ void QPrintDialogPrivate::updatePpdDuplexOption(QRadioButton *radio)
891923
&& top->d->m_currentPrintDevice.isFeatureAvailable(QPrintDevice::PDPK_PageRange, QVariant()));
892924
}
893925

926+
options.pagesRadioButton->setEnabled(outputFormat != QPrinter::PdfFormat
927+
&& top->d->m_currentPrintDevice.isFeatureAvailable(QPrintDevice::PDPK_PageRange, QVariant()));
928+
}
929+
894930
void QPrintDialogPrivate::setExplicitDuplexMode(QRadioButton *radio)
895931
{
896932
const bool checked = radio->isChecked();
@@ -1020,6 +1056,25 @@ void QPrintDialogPrivate::setupPrinter()
10201056
options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()));
10211057
}
10221058

1059+
if (options.pagesRadioButton->isEnabled() && options.pagesRadioButton->isChecked()) {
1060+
QString pageRange = options.pagesLineEdit->text();
1061+
const QPageRanges ranges = QPageRanges::fromString(pageRange);
1062+
if (!ranges.isEmpty()) {
1063+
p->setPrintRange(QPrinter::PageRange);
1064+
p->setPageRanges(ranges);
1065+
}
1066+
top->d->m_currentPrintDevice.setProperty(QPrintDevice::PDPK_PageRange, pageRange);
1067+
}
1068+
if (!q->testOption(QPrintDialog::PrintPageRange) && options.printRange->isChecked()) {
1069+
QString pageRange = tr("%1-%2").arg(options.from->value()).arg(qMax(options.from->value(),options.to->value()));
1070+
top->d->m_currentPrintDevice.setProperty(QPrintDevice::PDPK_PageRange, pageRange);
1071+
}
1072+
1073+
if (options.pageSetCombo->isEnabled()) {
1074+
top->d->m_currentPrintDevice.setProperty(QPrintDevice::PDPK_PageSet,
1075+
options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()));
1076+
}
1077+
10231078
if (options.colorMode->isEnabled()) {
10241079
p->setColorMode(options.color->isChecked() ? QPrinter::Color : QPrinter::GrayScale);
10251080
}

0 commit comments

Comments
 (0)