Qt 4.8
qprintdialog_unix.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qplatformdefs.h"
43 
44 #ifndef QT_NO_PRINTDIALOG
45 
46 #include "private/qabstractprintdialog_p.h"
47 #include <QtGui/qmessagebox.h>
48 #include "qprintdialog.h"
49 #include "qfiledialog.h"
50 #include <QtCore/qdir.h>
51 #include <QtGui/qevent.h>
52 #include <QtGui/qfilesystemmodel.h>
53 #include <QtGui/qstyleditemdelegate.h>
54 #include <QtGui/qprinter.h>
55 
56 #include <QtGui/qdialogbuttonbox.h>
57 
58 #include "qfscompleter_p.h"
59 #include "ui_qprintpropertieswidget.h"
60 #include "ui_qprintsettingsoutput.h"
61 #include "ui_qprintwidget.h"
62 
63 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
64 # include <private/qcups_p.h>
65 # include <cups/cups.h>
66 # include <private/qpdf_p.h>
67 #else
68 # include <QtCore/qlibrary.h>
69 #endif
70 
71 #include <private/qprinterinfo_unix_p.h>
72 
74 
75 class QOptionTreeItem;
76 class QPPDOptionsModel;
77 
79 {
80  Q_OBJECT
81 public:
84 
85 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
86  void setCups(QCUPSSupport *cups) { m_cups = cups; }
88 #endif
89 
90  void selectPrinter();
91  void selectPdfPsPrinter(const QPrinter *p);
92 
95  void setupPrinter() const;
96 
97 protected:
98  void showEvent(QShowEvent* event);
99 
100 private:
101  Ui::QPrintPropertiesWidget widget;
103 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
106 #endif
107 };
108 
110 {
113 public:
116 
117  void init();
120 
121 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
122  void selectPrinter(QCUPSSupport *cups);
123 #endif
124 
125  void _q_chbPrintLastFirstToggled(bool);
126 #ifndef QT_NO_MESSAGEBOX
127  void _q_checkFields();
128 #endif
129  void _q_collapseOrExpandDialog();
130 
131  void setupPrinter();
132  void updateWidgets();
133 
134  virtual void setTabs(const QList<QWidget*> &tabs);
135 
136  Ui::QPrintSettingsOutput options;
137  QUnixPrintWidget *top;
141 };
142 
143 #if defined (Q_OS_UNIX)
145 {
146 public:
147  QUnixPrintWidgetPrivate(QUnixPrintWidget *q);
149 
152  bool checkFields();
153  void setupPrinter();
154  void setOptionsPane(QPrintDialogPrivate *pane);
155 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
156  void setCupsProperties();
157 #endif
158 
159 // slots
160  void _q_printerChanged(int index);
161  void _q_btnPropertiesClicked();
162  void _q_btnBrowseClicked();
163 
164  QUnixPrintWidget * const parent;
166  Ui::QPrintWidget widget;
170  void updateWidget();
171 
172 private:
175 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
178  const cups_dest_t* cupsPrinters;
179  const ppd_file_t* cupsPPD;
180 #endif
181 };
182 #endif
183 
184 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
186 {
187 public:
188  enum ItemType { Root, Group, Option, Choice };
189 
190  QOptionTreeItem(ItemType t, int i, const void* p, const char* desc, QOptionTreeItem* pi)
191  : type(t),
192  index(i),
193  ptr(p),
194  description(desc),
195  selected(-1),
196  selDescription(0),
197  parentItem(pi) {}
198 
200  while (!childItems.isEmpty())
201  delete childItems.takeFirst();
202  }
203 
205  int index;
206  const void* ptr;
207  const char* description;
208  int selected;
209  const char* selDescription;
212 };
213 
215 {
216  friend class QPPDOptionsEditor;
217 public:
219  ~QPPDOptionsModel();
220 
221  int columnCount(const QModelIndex& parent = QModelIndex()) const;
222  int rowCount(const QModelIndex& parent = QModelIndex()) const;
223  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
224  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
225  QModelIndex parent(const QModelIndex& index) const;
226  Qt::ItemFlags flags(const QModelIndex& index) const;
227  QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
228 
231  const ppd_file_t* ppd;
232  void parseItems();
233  void parseGroups(QOptionTreeItem* parent);
234  void parseOptions(QOptionTreeItem* parent);
235  void parseChoices(QOptionTreeItem* parent);
236 };
237 
239 {
240  Q_OBJECT
241 public:
244 
245  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
246  void setEditorData(QWidget* editor, const QModelIndex& index) const;
247  void setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
248 
249 private slots:
250  void cbChanged(int index);
251 
252 };
253 
254 #endif
255 
257 
259  : QDialog(parent)
260 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
261  , m_cups(0), m_cupsOptionsModel(0)
262 #endif
263 {
264  QVBoxLayout *lay = new QVBoxLayout(this);
265  this->setLayout(lay);
266  QWidget *content = new QWidget(this);
267  widget.setupUi(content);
269  lay->addWidget(content);
270  lay->addWidget(m_buttons);
271 
272  connect(m_buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept()));
274 }
275 
277 {
278 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
279  delete m_cupsOptionsModel;
280 #else
281  delete widget.cupsPropertiesPage;
282 #endif
283 }
284 
286 {
287  widget.pageSetup->setPrinter(p);
288 }
289 
291 {
292  widget.pageSetup->setupPrinter();
293 
294 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
295  QPPDOptionsModel* model = static_cast<QPPDOptionsModel*>(widget.treeView->model());
296  if (model) {
297  QOptionTreeItem* rootItem = model->rootItem;
299  QList<const char*> markedOptions;
300 
301  addItemToOptions(rootItem, options, markedOptions);
302  model->cups->saveOptions(options, markedOptions);
303  }
304 #endif
305 }
306 
308 {
309 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
310  widget.pageSetup->selectPrinter(m_cups);
311  widget.treeView->setModel(0);
313 
314  if (m_cupsOptionsModel == 0) {
316 
317  widget.treeView->setItemDelegate(new QPPDOptionsEditor(this));
318  } else {
319  // update the model
321  }
322 
323  if (m_cupsOptionsModel->rowCount() > 0) {
324  widget.treeView->setModel(m_cupsOptionsModel);
325 
326  for (int i = 0; i < m_cupsOptionsModel->rowCount(); ++i)
327  widget.treeView->expand(m_cupsOptionsModel->index(i,0));
328 
329  widget.tabs->setTabEnabled(1, true); // enable the advanced tab
330  } else {
331  widget.tabs->setTabEnabled(1, false);
332  }
333 
334  } else
335 #endif
336  {
337  widget.cupsPropertiesPage->setEnabled(false);
338  widget.pageSetup->selectPrinter(0);
339  }
340 }
341 
343 {
344  widget.treeView->setModel(0);
345  widget.pageSetup->selectPdfPsPrinter(p);
346  widget.tabs->setTabEnabled(1, false); // disable the advanced tab
347 }
348 
350 {
351  widget.treeView->resizeColumnToContents(0);
352  event->accept();
353 }
354 
355 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
357 {
358  for (int i = 0; i < parent->childItems.count(); ++i) {
359  QOptionTreeItem *itm = parent->childItems.at(i);
360  if (itm->type == QOptionTreeItem::Option) {
361  const ppd_option_t* opt = reinterpret_cast<const ppd_option_t*>(itm->ptr);
362  options << opt;
363  if (qstrcmp(opt->defchoice, opt->choices[itm->selected].choice) != 0) {
364  markedOptions << opt->keyword << opt->choices[itm->selected].choice;
365  }
366  } else {
367  addItemToOptions(itm, options, markedOptions);
368  }
369  }
370 }
371 #endif
372 
374  : top(0), bottom(0), buttons(0), collapseButton(0)
375 {
376 }
377 
379 {
380 }
381 
383 {
384  Q_Q(QPrintDialog);
385 
386  top = new QUnixPrintWidget(0, q);
387  bottom = new QWidget(q);
388  options.setupUi(bottom);
389  options.color->setIconSize(QSize(32, 32));
390  options.color->setIcon(QIcon(QLatin1String(":/trolltech/dialogs/qprintdialog/images/status-color.png")));
391  options.grayscale->setIconSize(QSize(32, 32));
392  options.grayscale->setIcon(QIcon(QLatin1String(":/trolltech/dialogs/qprintdialog/images/status-gray-scale.png")));
393  top->d->setOptionsPane(this);
394 
396  collapseButton = new QPushButton(QPrintDialog::tr("&Options >>"), buttons);
397  buttons->addButton(collapseButton, QDialogButtonBox::ResetRole);
398  bottom->setVisible(false);
399 
400  QPushButton *printButton = buttons->button(QDialogButtonBox::Ok);
401  printButton->setText(QPrintDialog::tr("&Print"));
402  printButton->setDefault(true);
403 
404  QVBoxLayout *lay = new QVBoxLayout(q);
405  q->setLayout(lay);
406  lay->addWidget(top);
407  lay->addWidget(bottom);
408  lay->addWidget(buttons);
409 
410  QPrinter* p = q->printer();
411 
413 
414 #ifdef QT_NO_MESSAGEBOX
416 #else
417  QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(_q_checkFields()));
418 #endif
420 
421  QObject::connect(options.reverse, SIGNAL(toggled(bool)),
422  q, SLOT(_q_chbPrintLastFirstToggled(bool)));
423 
424  QObject::connect(collapseButton, SIGNAL(released()), q, SLOT(_q_collapseOrExpandDialog()));
425 }
426 
428 {
429  if (p->colorMode() == QPrinter::Color)
430  options.color->setChecked(true);
431  else
432  options.grayscale->setChecked(true);
433 
434  switch(p->duplex()) {
436  options.noDuplex->setChecked(true); break;
439  options.duplexLong->setChecked(true); break;
441  options.duplexShort->setChecked(true); break;
442  }
443  options.copies->setValue(p->copyCount());
444  options.collate->setChecked(p->collateCopies());
445  options.reverse->setChecked(p->pageOrder() == QPrinter::LastPageFirst);
446  top->d->applyPrinterProperties(p);
447 }
448 
450 {
451  Q_Q(QPrintDialog);
452  if (checked)
453  q->printer()->setPageOrder(QPrinter::LastPageFirst);
454  else
455  q->printer()->setPageOrder(QPrinter::FirstPageFirst);
456 }
457 
459 {
460  int collapseHeight = 0;
461  Q_Q(QPrintDialog);
462  QWidget *widgetToHide = bottom;
463  if (widgetToHide->isVisible()) {
464  collapseButton->setText(QPrintDialog::tr("&Options >>"));
465  collapseHeight = widgetToHide->y() + widgetToHide->height() - (top->y() + top->height());
466  }
467  else
468  collapseButton->setText(QPrintDialog::tr("&Options <<"));
469  widgetToHide->setVisible(! widgetToHide->isVisible());
470  if (! widgetToHide->isVisible()) { // make it shrink
471  q->layout()->activate();
472  q->resize( QSize(q->width(), q->height() - collapseHeight) );
473  }
474 }
475 
476 #ifndef QT_NO_MESSAGEBOX
478 {
479  Q_Q(QPrintDialog);
480  if (top->d->checkFields())
481  q->accept();
482 }
483 #endif // QT_NO_MESSAGEBOX
484 
486 {
487  Q_Q(QPrintDialog);
488  QPrinter* p = q->printer();
489 
490  if (options.duplex->isEnabled()) {
491  if (options.noDuplex->isChecked())
493  else if (options.duplexLong->isChecked())
495  else
497  }
498 
499  p->setColorMode( options.color->isChecked() ? QPrinter::Color : QPrinter::GrayScale );
500 
501  // print range
502  if (options.printAll->isChecked()) {
504  p->setFromTo(0,0);
505  } else if (options.printSelection->isChecked()) {
507  p->setFromTo(0,0);
508  } else if (options.printCurrentPage->isChecked()) {
510  p->setFromTo(0,0);
511  } else if (options.printRange->isChecked()) {
513  p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value()));
514  }
515 
516  // copies
517  p->setCopyCount(options.copies->value());
518  p->setCollateCopies(options.collate->isChecked());
519 
520  top->d->setupPrinter();
521 }
522 
524 {
525  Q_Q(QPrintDialog);
526  options.gbPrintRange->setVisible(q->isOptionEnabled(QPrintDialog::PrintPageRange) ||
527  q->isOptionEnabled(QPrintDialog::PrintSelection) ||
528  q->isOptionEnabled(QPrintDialog::PrintCurrentPage));
529 
530  options.printRange->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange));
531  options.printSelection->setVisible(q->isOptionEnabled(QPrintDialog::PrintSelection));
532  options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage));
533  options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies));
534 
535  switch (q->printRange()) {
537  options.printAll->setChecked(true);
538  break;
540  options.printSelection->setChecked(true);
541  break;
543  options.printRange->setChecked(true);
544  break;
546  if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage))
547  options.printCurrentPage->setChecked(true);
548  break;
549  default:
550  break;
551  }
552  const int minPage = qMax(1, qMin(q->minPage() , q->maxPage()));
553  const int maxPage = qMax(1, q->maxPage() == INT_MAX ? 9999 : q->maxPage());
554 
555  options.from->setMinimum(minPage);
556  options.to->setMinimum(minPage);
557  options.from->setMaximum(maxPage);
558  options.to->setMaximum(maxPage);
559 
560  options.from->setValue(q->fromPage());
561  options.to->setValue(q->toPage());
562  top->d->updateWidget();
563 }
564 
566 {
567  while(options.tabs->count() > 2)
568  delete options.tabs->widget(2);
569 
570  QList<QWidget*>::ConstIterator iter = tabWidgets.begin();
571  while(iter != tabWidgets.constEnd()) {
572  QWidget *tab = *iter;
573  options.tabs->addTab(tab, tab->windowTitle());
574  ++iter;
575  }
576 }
577 
578 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
580 {
581  options.duplex->setEnabled(cups && cups->ppdOption("Duplex"));
582 }
583 #endif
584 
586 
588  : QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent)
589 {
590  Q_D(QPrintDialog);
591  d->init();
592 }
593 
598  : QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent)
599 {
600  Q_D(QPrintDialog);
601  d->init();
602 }
603 
605 {
606 }
607 
609 {
610  Q_D(QPrintDialog);
611 
612  if (visible)
613  d->updateWidgets();
614 
616 }
617 
618 int QPrintDialog::exec()
619 {
620  return QDialog::exec();
621 }
622 
624 {
625  Q_D(QPrintDialog);
626  d->setupPrinter();
627  QDialog::accept();
628 }
629 
630 #ifdef QT3_SUPPORT
632 {
633  Q_D(const QPrintDialog);
634  return d->printer;
635 }
636 
637 void QPrintDialog::setPrinter(QPrinter *printer, bool pickupSettings)
638 {
639  if (!printer)
640  return;
641 
642  Q_D(QPrintDialog);
643  d->printer = printer;
644 
645  if (pickupSettings)
646  d->applyPrinterProperties(printer);
647 }
648 
649 void QPrintDialog::addButton(QPushButton *button)
650 {
651  Q_D(QPrintDialog);
652  d->buttons->addButton(button, QDialogButtonBox::HelpRole);
653 }
654 #endif // QT3_SUPPORT
655 
656 #if defined (Q_OS_UNIX)
657 
661  : parent(p), propertiesDialog(0), printer(0), optionsPane(0), filePrintersAdded(false)
662 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
663  , cups(0), cupsPrinterCount(0), cupsPrinters(0), cupsPPD(0)
664 #endif
665 {
666  q = 0;
667  if (parent)
668  q = qobject_cast<QAbstractPrintDialog*> (parent->parent());
669 
670  widget.setupUi(parent);
671 
672  int currentPrinterIndex = 0;
673 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
674  cups = new QCUPSSupport;
676  cupsPPD = cups->currentPPD();
679 
680  for (int i = 0; i < cupsPrinterCount; ++i) {
682  if (cupsPrinters[i].instance)
683  printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
684 
685  widget.printers->addItem(printerName);
686  if (cupsPrinters[i].is_default)
687  widget.printers->setCurrentIndex(i);
688  }
689  // the model depends on valid ppd. so before enabling the
690  // properties button we make sure the ppd is in fact valid.
691  if (cupsPrinterCount && cups->currentPPD()) {
692  widget.properties->setEnabled(true);
693  }
694  currentPrinterIndex = cups->currentPrinterIndex();
695  } else {
696 #endif
697  currentPrinterIndex = qt_getLprPrinters(lprPrinters);
698  // populating printer combo
700  for(; i != lprPrinters.constEnd(); ++i)
701  widget.printers->addItem((*i).name);
702 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
703  }
704 #endif
705 
706 #if !defined(QT_NO_FILESYSTEMMODEL) && !defined(QT_NO_COMPLETER)
707  QFileSystemModel *fsm = new QFileSystemModel(widget.filename);
708  fsm->setRootPath(QDir::homePath());
709  widget.filename->setCompleter(new QCompleter(fsm, widget.filename));
710 #endif
711  _q_printerChanged(currentPrinterIndex);
712 
713  QObject::connect(widget.printers, SIGNAL(currentIndexChanged(int)),
714  parent, SLOT(_q_printerChanged(int)));
715  QObject::connect(widget.fileBrowser, SIGNAL(clicked()), parent, SLOT(_q_btnBrowseClicked()));
716  QObject::connect(widget.properties, SIGNAL(clicked()), parent, SLOT(_q_btnPropertiesClicked()));
717 
718  // disable features that QPrinter does not yet support.
719  widget.preview->setVisible(false);
720 }
721 
723 {
724  const bool printToFile = q == 0 || q->isOptionEnabled(QPrintDialog::PrintToFile);
725  if (printToFile && !filePrintersAdded) {
726  if (widget.printers->count())
727  widget.printers->insertSeparator(widget.printers->count());
728  widget.printers->addItem(QPrintDialog::tr("Print to File (PDF)"));
729  widget.printers->addItem(QPrintDialog::tr("Print to File (Postscript)"));
730  filePrintersAdded = true;
731  }
732  if (!printToFile && filePrintersAdded) {
733  widget.printers->removeItem(widget.printers->count()-1);
734  widget.printers->removeItem(widget.printers->count()-1);
735  if (widget.printers->count())
736  widget.printers->removeItem(widget.printers->count()-1); // remove separator
737  filePrintersAdded = false;
738  }
739  if (printer && filePrintersAdded && (printer->outputFormat() != QPrinter::NativeFormat
740  || printer->printerName().isEmpty()))
741  {
742  if (printer->outputFormat() == QPrinter::PdfFormat)
743  widget.printers->setCurrentIndex(widget.printers->count() - 2);
744  else if (printer->outputFormat() == QPrinter::PostScriptFormat)
745  widget.printers->setCurrentIndex(widget.printers->count() - 1);
746  widget.filename->setEnabled(true);
747  widget.lOutput->setEnabled(true);
748  }
749 
750  widget.filename->setVisible(printToFile);
751  widget.lOutput->setVisible(printToFile);
752  widget.fileBrowser->setVisible(printToFile);
753 
755 }
756 
758 {
759 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
760  delete cups;
761 #endif
762 }
763 
765 {
766  if (index < 0)
767  return;
768  const int printerCount = widget.printers->count();
769  widget.filename->setEnabled(false);
770  widget.lOutput->setEnabled(false);
771 
772  if (filePrintersAdded) {
773  Q_ASSERT(index != printerCount - 3); // separator
774  if (index > printerCount - 3) { // PDF or postscript
775  bool pdfPrinter = (index == printerCount - 2);
776  widget.location->setText(QPrintDialog::tr("Local file"));
777  widget.type->setText(QPrintDialog::tr("Write %1 file").arg(pdfPrinter ? QString::fromLatin1("PDF")
778  : QString::fromLatin1("PostScript")));
779  widget.properties->setEnabled(true);
780  widget.filename->setEnabled(true);
781  QString filename = widget.filename->text();
782  QString suffix = QFileInfo(filename).suffix();
783  if (pdfPrinter && suffix == QLatin1String("ps"))
784  filename = filename.replace(QLatin1String(".ps"), QLatin1String(".pdf"));
785  if (!pdfPrinter && suffix == QLatin1String("pdf"))
786  filename = filename.replace(QLatin1String(".pdf"), QLatin1String(".ps"));
787  widget.filename->setText(filename);
788  widget.lOutput->setEnabled(true);
789  if (propertiesDialog)
791 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
792  if (optionsPane)
794 #endif
795  return;
796  }
797  }
798 
799  widget.location->setText(QString());
800 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
802  cups->setCurrentPrinter(index);
803 
804  const cups_option_t *opt = cups->printerOption(QString::fromLatin1("printer-location"));
806  if (opt)
807  location = QString::fromLocal8Bit(opt->value);
808  widget.location->setText(location);
809 
810  cupsPPD = cups->currentPPD();
811  // set printer type line
812  QString type;
813  if (cupsPPD)
814  type = QString::fromLocal8Bit(cupsPPD->manufacturer) + QLatin1String(" - ") + QString::fromLocal8Bit(cupsPPD->modelname);
815  widget.type->setText(type);
816  if (propertiesDialog)
818  if (optionsPane)
820  } else {
821  if (optionsPane)
823 #endif
824  if (lprPrinters.count() > 0) {
825  QString type = lprPrinters.at(index).name + QLatin1Char('@') + lprPrinters.at(index).host;
826  if (!lprPrinters.at(index).comment.isEmpty())
827  type += QLatin1String(", ") + lprPrinters.at(index).comment;
828  widget.type->setText(type);
829  if (propertiesDialog)
831  }
832 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
833  }
834 #endif
835 }
836 
838 {
839  optionsPane = pane;
840  if (optionsPane)
841  _q_printerChanged(widget.printers->currentIndex());
842 }
843 
845 {
846  QString filename = widget.filename->text();
847 #ifndef QT_NO_FILEDIALOG
848  filename = QFileDialog::getSaveFileName(parent, QPrintDialog::tr("Print To File ..."), filename,
850 #else
851  filename.clear();
852 #endif
853  if (!filename.isEmpty()) {
854  widget.filename->setText(filename);
855  if (filename.endsWith(QString::fromLatin1(".ps"), Qt::CaseInsensitive))
856  widget.printers->setCurrentIndex(widget.printers->count() - 1); // the postscript one
857  else if (filename.endsWith(QString::fromLatin1(".pdf"), Qt::CaseInsensitive))
858  widget.printers->setCurrentIndex(widget.printers->count() - 2); // the pdf one
859  else if (widget.printers->currentIndex() != widget.printers->count() - 1) // if ps is not selected, pdf is default
860  widget.printers->setCurrentIndex(widget.printers->count() - 2); // the pdf one
861  }
862 }
863 
865 {
866  if (p == 0)
867  return;
868  printer = p;
869  if (p->outputFileName().isEmpty()) {
870  QString home = QString::fromLocal8Bit(qgetenv("HOME").constData());
871  QString cur = QDir::currentPath();
872  if (home.at(home.length()-1) != QLatin1Char('/'))
873  home += QLatin1Char('/');
874  if (cur.at(cur.length()-1) != QLatin1Char('/'))
875  cur += QLatin1Char('/');
876  if (cur.left(home.length()) != home)
877  cur = home;
878 #ifdef Q_WS_X11
879  if (p->docName().isEmpty()) {
881  cur += QLatin1String("print.ps");
882  else
883  cur += QLatin1String("print.pdf");
884  } else {
885  QRegExp re(QString::fromLatin1("(.*)\\.\\S+"));
886  if (re.exactMatch(p->docName()))
887  cur += re.cap(1);
888  else
889  cur += p->docName();
891  cur += QLatin1String(".ps");
892  else
893  cur += QLatin1String(".pdf");
894  }
895 #endif
896  widget.filename->setText(cur);
897  }
898  else
899  widget.filename->setText( p->outputFileName() );
900  QString printer = p->printerName();
901  if (!printer.isEmpty()) {
902  for (int i = 0; i < widget.printers->count(); ++i) {
903  if (widget.printers->itemText(i) == printer) {
904  widget.printers->setCurrentIndex(i);
905  break;
906  }
907  }
908  }
909  // PDF and PS printers are not added to the dialog yet, we'll handle those cases in QUnixPrintWidgetPrivate::updateWidget
910 
911  if (propertiesDialog)
913 }
914 
915 #ifndef QT_NO_MESSAGEBOX
917 {
918  if (widget.filename->isEnabled()) {
919  QString file = widget.filename->text();
920  QFile f(file);
921  QFileInfo fi(f);
922  bool exists = fi.exists();
923  bool opened = false;
924  if (exists && fi.isDir()) {
926  QPrintDialog::tr("%1 is a directory.\nPlease choose a different file name.").arg(file));
927  return false;
928  } else if ((exists && !fi.isWritable()) || !(opened = f.open(QFile::Append))) {
930  QPrintDialog::tr("File %1 is not writable.\nPlease choose a different file name.").arg(file));
931  return false;
932  } else if (exists) {
933  int ret = QMessageBox::question(q, q->windowTitle(),
934  QPrintDialog::tr("%1 already exists.\nDo you want to overwrite it?").arg(file),
936  if (ret == QMessageBox::No)
937  return false;
938  }
939  if (opened) {
940  f.close();
941  if (!exists)
942  f.remove();
943  }
944  }
945 
946  // Every test passed. Accept the dialog.
947  return true;
948 }
949 #endif // QT_NO_MESSAGEBOX
950 
952 {
953  if (!propertiesDialog) {
956  }
957 
959 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
961 #endif
963 
965  && (widget.printers->currentIndex() > widget.printers->count() - 3)) // PDF or postscript
967  else
969  }
971 }
972 
973 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
975 {
976  if (cups && QCUPSSupport::isAvailable() && cups->pageSizes()) {
977  QPrintEngine *engine = printer->printEngine();
978  const ppd_option_t* pageSizes = cups->pageSizes();
979  QByteArray cupsPageSize;
980  for (int i = 0; i < pageSizes->num_choices; ++i) {
981  if (static_cast<int>(pageSizes->choices[i].marked) == 1)
982  cupsPageSize = pageSizes->choices[i].choice;
983  }
986 
987  QRect pageRect = cups->pageRect(cupsPageSize);
988  engine->setProperty(PPK_CupsPageRect, pageRect);
989 
990  QRect paperRect = cups->paperRect(cupsPageSize);
991  engine->setProperty(PPK_CupsPaperRect, paperRect);
992 
993  for (int ps = 0; ps < QPrinter::NPaperSize; ++ps) {
995  if (size.width == paperRect.width() && size.height == paperRect.height())
996  printer->setPaperSize(static_cast<QPrinter::PaperSize>(ps));
997  }
998  }
999 }
1000 #endif
1001 
1003 {
1004  const int printerCount = widget.printers->count();
1005  const int index = widget.printers->currentIndex();
1006 
1007  if (filePrintersAdded && index > printerCount - 3) { // PDF or postscript
1008  printer->setPrinterName(QString());
1009  Q_ASSERT(index != printerCount - 3); // separator
1010  if (index == printerCount - 2)
1012  else
1014  QString path = widget.filename->text();
1015  if (QDir::isRelativePath(path))
1016  path = QDir::homePath() + QDir::separator() + path;
1017  printer->setOutputFileName(path);
1018  }
1019  else {
1020  printer->setPrinterName(widget.printers->currentText());
1021  printer->setOutputFileName(QString());
1022  }
1023 
1026 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
1027  if (!propertiesDialog)
1029 #endif
1030 }
1031 
1032 
1035 QUnixPrintWidget::QUnixPrintWidget(QPrinter *printer, QWidget *parent)
1036  : QWidget(parent), d(new QUnixPrintWidgetPrivate(this))
1037 {
1038  d->applyPrinterProperties(printer);
1039 }
1040 
1043 QUnixPrintWidget::~QUnixPrintWidget()
1044 {
1045  delete d;
1046 }
1047 
1055 void QUnixPrintWidget::updatePrinter()
1056 {
1057  d->setupPrinter();
1058 }
1059 
1060 #endif
1061 
1063 #if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY)
1064 
1066  : QAbstractItemModel(parent), rootItem(0), cups(c), ppd(c->currentPPD())
1067 {
1068  parseItems();
1069 }
1070 
1072 {
1073 }
1074 
1076 {
1077  return 2;
1078 }
1079 
1080 int QPPDOptionsModel::rowCount(const QModelIndex& parent) const
1081 {
1082  QOptionTreeItem* itm;
1083  if (!parent.isValid())
1084  itm = rootItem;
1085  else
1086  itm = reinterpret_cast<QOptionTreeItem*>(parent.internalPointer());
1087 
1088  if (itm->type == QOptionTreeItem::Option)
1089  return 0;
1090 
1091  return itm->childItems.count();
1092 }
1093 
1095 {
1096  switch(role) {
1097  case Qt::FontRole: {
1098  QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
1099  if (itm && itm->type == QOptionTreeItem::Group){
1100  QFont font = QApplication::font();
1101  font.setBold(true);
1102  return QVariant(font);
1103  }
1104  return QVariant();
1105  }
1106  break;
1107 
1108  case Qt::DisplayRole: {
1109  QOptionTreeItem* itm;
1110  if (!index.isValid())
1111  itm = rootItem;
1112  else
1113  itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
1114 
1115  if (index.column() == 0)
1116  return cups->unicodeString(itm->description);
1117  else if (itm->type == QOptionTreeItem::Option && itm->selected > -1)
1118  return cups->unicodeString(itm->selDescription);
1119  else
1120  return QVariant();
1121  }
1122  break;
1123 
1124  default:
1125  return QVariant();
1126  }
1127  if (role != Qt::DisplayRole)
1128  return QVariant();
1129 }
1130 
1131 QModelIndex QPPDOptionsModel::index(int row, int column, const QModelIndex& parent) const
1132 {
1133  QOptionTreeItem* itm;
1134  if (!parent.isValid())
1135  itm = rootItem;
1136  else
1137  itm = reinterpret_cast<QOptionTreeItem*>(parent.internalPointer());
1138 
1139  return createIndex(row, column, itm->childItems.at(row));
1140 }
1141 
1142 
1144 {
1145  if (!index.isValid())
1146  return QModelIndex();
1147 
1148  QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
1149 
1150  if (itm->parentItem && itm->parentItem != rootItem)
1151  return createIndex(itm->parentItem->index, 0, itm->parentItem);
1152  else
1153  return QModelIndex();
1154 }
1155 
1156 Qt::ItemFlags QPPDOptionsModel::flags(const QModelIndex& index) const
1157 {
1158  if (!index.isValid() || reinterpret_cast<QOptionTreeItem*>(index.internalPointer())->type == QOptionTreeItem::Group)
1159  return Qt::ItemIsEnabled;
1160 
1161  if (index.column() == 1)
1163 
1165 }
1166 
1168 {
1170  ppd = cups->currentPPD();
1171  delete rootItem;
1172  rootItem = new QOptionTreeItem(QOptionTreeItem::Root, 0, ppd, "Root Item", 0);
1174  emit layoutChanged();
1175 }
1176 
1178 {
1179  if (parent->type == QOptionTreeItem::Root) {
1180 
1181  const ppd_file_t* ppdFile = reinterpret_cast<const ppd_file_t*>(parent->ptr);
1182 
1183  if (ppdFile) {
1184  for (int i = 0; i < ppdFile->num_groups; ++i) {
1185  QOptionTreeItem* group = new QOptionTreeItem(QOptionTreeItem::Group, i, &ppdFile->groups[i], ppdFile->groups[i].text, parent);
1186  parent->childItems.append(group);
1187  parseGroups(group); // parse possible subgroups
1188  parseOptions(group); // parse options
1189  }
1190  }
1191  } else if (parent->type == QOptionTreeItem::Group) {
1192 
1193  const ppd_group_t* group = reinterpret_cast<const ppd_group_t*>(parent->ptr);
1194 
1195  if (group) {
1196  for (int i = 0; i < group->num_subgroups; ++i) {
1197  QOptionTreeItem* subgroup = new QOptionTreeItem(QOptionTreeItem::Group, i, &group->subgroups[i], group->subgroups[i].text, parent);
1198  parent->childItems.append(subgroup);
1199  parseGroups(subgroup); // parse possible subgroups
1200  parseOptions(subgroup); // parse options
1201  }
1202  }
1203  }
1204 }
1205 
1207 {
1208  const ppd_group_t* group = reinterpret_cast<const ppd_group_t*>(parent->ptr);
1209  for (int i = 0; i < group->num_options; ++i) {
1210  QOptionTreeItem* opt = new QOptionTreeItem(QOptionTreeItem::Option, i, &group->options[i], group->options[i].text, parent);
1211  parent->childItems.append(opt);
1212  parseChoices(opt);
1213  }
1214 }
1215 
1217 {
1218  const ppd_option_t* option = reinterpret_cast<const ppd_option_t*>(parent->ptr);
1219  bool marked = false;
1220  for (int i = 0; i < option->num_choices; ++i) {
1221  QOptionTreeItem* choice = new QOptionTreeItem(QOptionTreeItem::Choice, i, &option->choices[i], option->choices[i].text, parent);
1222  if (static_cast<int>(option->choices[i].marked) == 1) {
1223  parent->selected = i;
1224  parent->selDescription = option->choices[i].text;
1225  marked = true;
1226  } else if (!marked && qstrcmp(option->choices[i].choice, option->defchoice) == 0) {
1227  parent->selected = i;
1228  parent->selDescription = option->choices[i].text;
1229  }
1230  parent->childItems.append(choice);
1231  }
1232 }
1233 
1235 {
1236  if (role != Qt::DisplayRole)
1237  return QVariant();
1238 
1239  switch(section){
1240  case 0:
1241  return QVariant(QApplication::translate("QPPDOptionsModel", "Name"));
1242  case 1:
1243  return QVariant(QApplication::translate("QPPDOptionsModel", "Value"));
1244  default:
1245  return QVariant();
1246  }
1247 }
1248 
1250 
1252 {
1253  if (index.column() == 1 && reinterpret_cast<QOptionTreeItem*>(index.internalPointer())->type == QOptionTreeItem::Option)
1254  return new QComboBox(parent);
1255  else
1256  return 0;
1257 }
1258 
1260 {
1261  if (index.column() != 1)
1262  return;
1263 
1264  QComboBox* cb = static_cast<QComboBox*>(editor);
1265  QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
1266 
1267  if (itm->selected == -1)
1268  cb->addItem(QString());
1269 
1270  for (int i = 0; i < itm->childItems.count(); ++i)
1272 
1273  if (itm->selected > -1)
1274  cb->setCurrentIndex(itm->selected);
1275 
1276  connect(cb, SIGNAL(currentIndexChanged(int)), this, SLOT(cbChanged(int)));
1277 }
1278 
1280 {
1281  QComboBox* cb = static_cast<QComboBox*>(editor);
1282  QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
1283 
1284  if (itm->selected == cb->currentIndex())
1285  return;
1286 
1287  const ppd_option_t* opt = reinterpret_cast<const ppd_option_t*>(itm->ptr);
1288  QPPDOptionsModel* m = static_cast<QPPDOptionsModel*>(model);
1289 
1290  if (m->cups->markOption(opt->keyword, opt->choices[cb->currentIndex()].choice) == 0) {
1291  itm->selected = cb->currentIndex();
1292  itm->selDescription = reinterpret_cast<const ppd_option_t*>(itm->ptr)->choices[itm->selected].text;
1293  }
1294 }
1295 
1297 {
1298 /*
1299  emit commitData(static_cast<QWidget*>(sender()));
1300 */
1301 }
1302 
1303 #endif
1304 
1306 
1307 #include "moc_qprintdialog.cpp"
1308 #include "qprintdialog_unix.moc"
1309 #include "qrc_qprintdialog.cpp"
1310 
1311 #endif // QT_NO_PRINTDIALOG
1312 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
DuplexMode duplex() const
Returns the current duplex mode.
Definition: qprinter.cpp:1727
T qobject_cast(QObject *object)
Definition: qobject.h:375
double d
Definition: qnumeric_p.h:62
void setDuplex(DuplexMode duplex)
Enables double sided printing based on the duplex mode.
Definition: qprinter.cpp:1710
void * internalPointer() const
Returns a void * pointer used by the model to associate the index with the internal data structure...
const ppd_option_t * ppdOption(const char *key) const
Definition: qcups.cpp:237
const ppd_file_t * currentPPD() const
Definition: qcups.cpp:173
int columnCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of columns for the children of the given parent.
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
#define QT_NO_LIBRARY
The QFileSystemModel class provides a data model for the local filesystem.
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
int type
Definition: qmetatype.cpp:239
int markOption(const char *name, const char *value)
Definition: qcups.cpp:264
PaperSize paperSize(QPrinter::PaperSize paperSize)
Definition: qpdf.cpp:905
QDialogButtonBox * buttons
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
QPrintPropertiesDialog(QAbstractPrintDialog *parent=0)
QString cap(int nth=0) const
Returns the text captured by the nth subexpression.
Definition: qregexp.cpp:4310
const char * description
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setText(const QString &text)
Ui::QPrintSettingsOutput options
static QString getSaveFileName(QWidget *parent=0, const QString &caption=QString(), const QString &dir=QString(), const QString &filter=QString(), QString *selectedFilter=0, Options options=0)
This is a convenience static function that will return a file name selected by the user...
int availablePrintersCount() const
Definition: qcups.cpp:163
QPPDOptionsModel(QCUPSSupport *cups, QObject *parent=0)
QString docName() const
Returns the document name.
Definition: qprinter.cpp:1035
Ui::QPrintPropertiesWidget widget
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
The QDialog class is the base class of dialog windows.
Definition: qdialog.h:56
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
bool isOptionEnabled(PrintDialogOption option) const
Use QPrintDialog::testOption(option) instead.
int exec()
Shows the dialog as a modal dialog, blocking until the user closes it.
Definition: qdialog.cpp:524
void setLayout(QLayout *)
Sets the layout manager for this widget to layout.
Definition: qwidget.cpp:10104
bool isVisible() const
Definition: qwidget.h:1005
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
#define SLOT(a)
Definition: qobjectdefs.h:226
static Qt::MouseButtons buttons
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual void accept()
Hides the modal dialog and sets the result code to Accepted.
Definition: qdialog.cpp:639
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
virtual void reject()
Hides the modal dialog and sets the result code to Rejected.
Definition: qdialog.cpp:650
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
void setDefault(bool)
QModelIndex createIndex(int row, int column, void *data=0) const
Creates a model index for the given row and column with the internal pointer ptr. ...
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
The QPushButton widget provides a command button.
Definition: qpushbutton.h:57
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Returns the data stored under the given role for the item referred to by the index.
The QCompleter class provides completions based on an item model.
Definition: qcompleter.h:64
QUnixPrintWidget * top
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool exists() const
Returns true if the file exists; otherwise returns false.
Definition: qfileinfo.cpp:675
void setCurrentIndex(int index)
Definition: qcombobox.cpp:2102
const ppd_file_t * cupsPPD
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QUnixPrintWidget *const parent
void setPaperSize(PaperSize)
Sets the printer paper size to newPaperSize if that size is supported.
Definition: qprinter.cpp:1163
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
Definition: qdir.cpp:2210
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875
void parseOptions(QOptionTreeItem *parent)
QRect pageRect(const char *choice) const
Definition: qcups.cpp:321
const cups_dest_t * availablePrinters() const
Definition: qcups.cpp:168
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QString outputFileName() const
Returns the name of the output file.
Definition: qprinter.cpp:950
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static bool isAvailable()
Definition: qcups.cpp:216
#define QT_NO_CUPS
void addItem(const QString &text, const QVariant &userData=QVariant())
Adds an item to the combobox with the given text, and containing the specified userData (stored in th...
Definition: qcombobox.h:323
#define Q_D(Class)
Definition: qglobal.h:2482
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=0)
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment...
The QStyledItemDelegate class provides display and editing facilities for data items from a model...
QPushButton * collapseButton
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
Opens a warning message box with the given title and text in front of the specified parent widget...
void setCollateCopies(bool collate)
Sets the default value for collation checkbox when the print dialog appears.
Definition: qprinter.cpp:1493
void applyPrinterProperties(QPrinter *p)
copy printer properties to the widget
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
Qt::ItemFlags flags(const QModelIndex &index) const
Returns the item flags for the given index.
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
QPrintEngine * printEngine() const
Returns the print engine used by the printer.
Definition: qprinter.cpp:1896
#define Q_Q(Class)
Definition: qglobal.h:2483
static QFont font()
Returns the default application font.
QList< QOptionTreeItem * > childItems
void setCopyCount(int)
Sets the number of copies to be printed to count.
Definition: qprinter.cpp:1411
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Returns the index of the item in the model specified by the given row, column and parent index...
QPushButton * button(StandardButton which) const
Returns the QPushButton corresponding to the standard button which, or 0 if the standard button doesn...
~QPrintDialog()
Destroys the print dialog.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QPrintDialog class provides a dialog for specifying the printer&#39;s configuration.
Definition: qprintdialog.h:81
void applyPrinterProperties(QPrinter *p)
copy printer properties to the widget
QPrinter * printer() const
Returns the printer that this printer dialog operates on.
QOptionTreeItem(ItemType t, int i, const void *p, const char *desc, QOptionTreeItem *pi)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void _q_printerChanged(int index)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
OutputFormat outputFormat() const
Returns the output format for this printer.
Definition: qprinter.cpp:813
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Returns the editor to be used for editing the data item with the given index.
void setBold(bool)
If enable is true sets the font&#39;s weight to QFont::Bold ; otherwise sets the weight to QFont::Normal...
Definition: qfont.h:352
QPrintPropertiesDialog * propertiesDialog
const ppd_option_t * pageSizes() const
Definition: qcups.cpp:259
bool visible
whether the widget is visible
Definition: qwidget.h:191
The QPrintEngine class defines an interface for how QPrinter interacts with a given printing subsyste...
Definition: qprintengine.h:56
bool isDir() const
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise ret...
Definition: qfileinfo.cpp:990
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
void layoutAboutToBeChanged()
This signal is emitted just before the layout of a model is changed.
int height
the height of the widget excluding any window frame
Definition: qwidget.h:167
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int qt_getLprPrinters(QList< QPrinterDescription > &printers)
QRect paperRect(const char *choice) const
Definition: qcups.cpp:310
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
static bool init
QStringList options() const
Definition: qcups.cpp:335
const char * name
The QPrinter class is a paint device that paints on a printer.
Definition: qprinter.h:66
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
void setPrintRange(PrintRange range)
Sets the print range option in to be range.
Definition: qprinter.cpp:2247
void _q_chbPrintLastFirstToggled(bool)
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
QWidgetData * data
Definition: qwidget.h:815
void saveOptions(QList< const ppd_option_t *> options, QList< const char *> markedOptions)
Definition: qcups.cpp:269
void parseChoices(QOptionTreeItem *parent)
void rejected()
This signal is emitted when the dialog has been rejected either by the user or by calling reject() or...
QOptionTreeItem * parentItem
void setCups(QCUPSSupport *cups)
void setOptionsPane(QPrintDialogPrivate *pane)
QString windowTitle
the window title (caption)
Definition: qwidget.h:198
QDialogButtonBox * m_buttons
QString windowTitle() const
void cbChanged(int index)
void setFromTo(int fromPage, int toPage)
Sets the range of pages to be printed to cover the pages with numbers specified by from and to...
Definition: qprinter.cpp:2222
const T * ptr(const T &t)
int exec()
Reimplemented Function
ColorMode colorMode() const
Returns the current color mode.
Definition: qprinter.cpp:1314
void layoutChanged()
This signal is emitted whenever the layout of items exposed by the model has changed; for example...
QPPDOptionsModel * m_cupsOptionsModel
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
void selectPrinter(QCUPSSupport *cups)
QModelIndex setRootPath(const QString &path)
Sets the directory that is being watched by the model to newPath by installing a file system watcher ...
int currentPrinterIndex() const
Definition: qcups.cpp:211
void setColorMode(ColorMode)
Sets the printer&#39;s color mode to newColorMode, which can be either Color or GrayScale.
Definition: qprinter.cpp:1300
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
#define Q_OBJECT
Definition: qobjectdefs.h:157
virtual void setVisible(bool visible)
Definition: qwidget.cpp:7991
The QAbstractItemModel class provides the abstract interface for item model classes.
QUnixPrintWidgetPrivate(QUnixPrintWidget *q)
void setResult(int r)
Sets the modal dialog&#39;s result code to i.
Definition: qdialog.cpp:475
const cups_option_t * printerOption(const QString &key) const
Definition: qcups.cpp:250
virtual void setProperty(PrintEnginePropertyKey key, const QVariant &value)=0
Sets the print engine&#39;s property specified by key to the given value.
void addItemToOptions(QOptionTreeItem *parent, QList< const ppd_option_t *> &options, QList< const char *> &markedOptions) const
The QAbstractPrintDialog class provides a base implementation for print dialogs used to configure pri...
QList< QPrinterDescription > lprPrinters
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
#define PPK_CupsStringPageSize
Definition: qpdf_p.h:73
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
const ppd_file_t * setCurrentPrinter(int index)
Definition: qcups.cpp:178
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
bool collateCopies() const
Returns true if collation is turned on when multiple copies is selected.
Definition: qprinter.cpp:1473
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
friend class QPushButton
Definition: qdialog.h:59
void showEvent(QShowEvent *event)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
PaperSize
This enum type specifies what paper size QPrinter should use.
Definition: qprinter.h:91
int y
the y coordinate of the widget relative to its parent and including any window frame ...
Definition: qwidget.h:162
The QDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the c...
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QString unicodeString(const char *s)
Definition: qcups.cpp:352
void parseGroups(QOptionTreeItem *parent)
QString suffix() const
Returns the suffix of the file.
Definition: qfileinfo.cpp:834
void selectPdfPsPrinter(const QPrinter *p)
static QTestResult::TestLocation location
Definition: qtestresult.cpp:63
int result() const
In general returns the modal dialog&#39;s result code, Accepted or Rejected.
Definition: qdialog.cpp:458
QByteArray suffix
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
Opens a question message box with the given title and text in front of the specified parent widget...
The QModelIndex class is used to locate data in a data model.
bool event(QEvent *e)
Reimplemented Function
Definition: qdialog.cpp:426
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QPrinter * printer()
Returns the printer that this printer dialog operates on.
void applyPrinterProperties(QPrinter *p)
copy printer properties to the widget
bool remove()
Removes the file specified by fileName().
Definition: qfile.cpp:715
quint16 index
QAbstractPrintDialog * q
int copyCount() const
Returns the number of copies that will be printed.
Definition: qprinter.cpp:1430
bool exactMatch(const QString &str) const
Returns true if str is matched exactly by this regular expression; otherwise returns false...
Definition: qregexp.cpp:4094
void setVisible(bool visible)
Reimplemented Function
int currentIndex
the index of the current item in the combobox.
Definition: qcombobox.h:71
void accepted()
This signal is emitted when the dialog has been accepted either by the user or by calling accept() or...
#define PPK_CupsPaperRect
Definition: qpdf_p.h:72
virtual void setTabs(const QList< QWidget *> &tabs)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define PPK_CupsPageRect
Definition: qpdf_p.h:71
void setOutputFormat(OutputFormat format)
Sets the output format for this printer to format.
Definition: qprinter.cpp:765
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
QPrintDialogPrivate * optionsPane
Qt::Orientation orientation() const
Returns the dialog&#39;s extension orientation.
Definition: qdialog.cpp:1035
const ppd_file_t * ppd
The QVBoxLayout class lines up widgets vertically.
Definition: qboxlayout.h:149
The QStyleOptionViewItem class is used to describe the parameters used to draw an item in a view widg...
Definition: qstyleoption.h:539
#define PPK_CupsOptions
Definition: qpdf_p.h:70
QOptionTreeItem * rootItem
#define slots
Definition: qobjectdefs.h:68
QPPDOptionsEditor(QObject *parent=0)
void setEditorData(QWidget *editor, const QModelIndex &index) const
Sets the contents of the given editor to the data for the item at the given index.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
static void updateWidgets(const QList< const QWidget *> &widgets)
virtual void close()
Calls QFile::flush() and closes the file.
Definition: qfile.cpp:1680
Orientation
Definition: qnamespace.h:174
QString printerName() const
Returns the printer name.
Definition: qprinter.cpp:834
void setVisible(bool visible)
Reimplemented Function
Definition: qdialog.cpp:756
bool isWritable() const
Returns true if the user can write to the file; otherwise returns false.
Definition: qfileinfo.cpp:914
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Sets the data for the item at the given index in the model to the contents of the given editor...
#define Q_DECLARE_TR_FUNCTIONS(context)
The Q_DECLARE_TR_FUNCTIONS() macro declares and implements two translation functions, tr() and trUtf8(), with these signatures:
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const cups_dest_t * cupsPrinters
#define INT_MAX
QPrintDialog(QPrinter *printer, QWidget *parent=0)
Constructs a new modal printer dialog for the given printer with the given parent.
const char * selDescription
PageOrder pageOrder() const
Returns the current page order.
Definition: qprinter.cpp:1286
void setPrinterName(const QString &)
Sets the printer name to name.
Definition: qprinter.cpp:845
int column() const
Returns the column this model index refers to.
int rowCount(const QModelIndex &parent=QModelIndex()) const
Returns the number of rows under the given parent.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272
void setOutputFileName(const QString &)
Sets the name of the output file to fileName.
Definition: qprinter.cpp:976
static QString homePath()
Returns the absolute path of the user&#39;s home directory.
Definition: qdir.cpp:1942
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60