source: trunk/src/gui/dialogs/qprintdialog_unix.cpp@ 578

Last change on this file since 578 was 578, checked in by Dmitry A. Kuminov, 15 years ago

configure.cmd: Added QT_NO_LPR (and made Qt sources additionally use it in a couple of places) since OS/2 doesn't support LPR-like printing for now.

File size: 42.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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) || defined (Q_WS_PM))
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
73QT_BEGIN_NAMESPACE
74
75extern int qt_printerRealNumCopies(QPaintEngine *);
76
77class QOptionTreeItem;
78class QPPDOptionsModel;
79
80class QPrintPropertiesDialog : public QDialog
81{
82 Q_OBJECT
83public:
84 QPrintPropertiesDialog(QAbstractPrintDialog *parent = 0);
85 ~QPrintPropertiesDialog();
86
87#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
88 void setCups(QCUPSSupport *cups) { m_cups = cups; }
89 void addItemToOptions(QOptionTreeItem *parent, QList<const ppd_option_t*>& options, QList<const char*>& markedOptions) const;
90#endif
91
92 void selectPrinter();
93 void selectPdfPsPrinter(const QPrinter *p);
94
95 /// copy printer properties to the widget
96 void applyPrinterProperties(QPrinter *p);
97 void setupPrinter() const;
98
99protected:
100 void showEvent(QShowEvent* event);
101
102private:
103 Ui::QPrintPropertiesWidget widget;
104 QDialogButtonBox *m_buttons;
105#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
106 QCUPSSupport *m_cups;
107 QPPDOptionsModel *m_cupsOptionsModel;
108#endif
109};
110
111class QPrintDialogPrivate : public QAbstractPrintDialogPrivate
112{
113 Q_DECLARE_PUBLIC(QPrintDialog)
114 Q_DECLARE_TR_FUNCTIONS(QPrintDialog)
115public:
116 QPrintDialogPrivate();
117 ~QPrintDialogPrivate();
118
119 void init();
120 /// copy printer properties to the widget
121 void applyPrinterProperties(QPrinter *p);
122
123#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
124 void selectPrinter(QCUPSSupport *cups);
125#endif
126
127 void _q_chbPrintLastFirstToggled(bool);
128#ifndef QT_NO_MESSAGEBOX
129 void _q_checkFields();
130#endif
131 void _q_collapseOrExpandDialog();
132
133 void setupPrinter();
134 void updateWidgets();
135
136 virtual void setTabs(const QList<QWidget*> &tabs);
137
138 Ui::QPrintSettingsOutput options;
139 QUnixPrintWidget *top;
140 QWidget *bottom;
141 QDialogButtonBox *buttons;
142 QPushButton *collapseButton;
143};
144
145#if defined (Q_OS_UNIX) || defined (Q_WS_PM)
146class QUnixPrintWidgetPrivate
147{
148public:
149 QUnixPrintWidgetPrivate(QUnixPrintWidget *q);
150 ~QUnixPrintWidgetPrivate();
151
152 /// copy printer properties to the widget
153 void applyPrinterProperties(QPrinter *p);
154 bool checkFields();
155 void setupPrinter();
156 void setOptionsPane(QPrintDialogPrivate *pane);
157
158// slots
159 void _q_printerChanged(int index);
160 void _q_btnPropertiesClicked();
161 void _q_btnBrowseClicked();
162
163 QUnixPrintWidget * const parent;
164 QPrintPropertiesDialog *propertiesDialog;
165 Ui::QPrintWidget widget;
166 QAbstractPrintDialog * q;
167 QPrinter *printer;
168 QList<QPrinterDescription> lprPrinters;
169 void updateWidget();
170
171private:
172 QPrintDialogPrivate *optionsPane;
173 bool filePrintersAdded;
174#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
175 QCUPSSupport* cups;
176 int cupsPrinterCount;
177 const cups_dest_t* cupsPrinters;
178 const ppd_file_t* cupsPPD;
179#endif
180};
181#endif
182
183#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
184class QOptionTreeItem
185{
186public:
187 enum ItemType { Root, Group, Option, Choice };
188
189 QOptionTreeItem(ItemType t, int i, const void* p, const char* desc, QOptionTreeItem* pi)
190 : type(t),
191 index(i),
192 ptr(p),
193 description(desc),
194 selected(-1),
195 selDescription(0),
196 parentItem(pi) {}
197
198 ~QOptionTreeItem() {
199 while (!childItems.isEmpty())
200 delete childItems.takeFirst();
201 }
202
203 ItemType type;
204 int index;
205 const void* ptr;
206 const char* description;
207 int selected;
208 const char* selDescription;
209 QOptionTreeItem* parentItem;
210 QList<QOptionTreeItem*> childItems;
211};
212
213class QPPDOptionsModel : public QAbstractItemModel
214{
215 friend class QPPDOptionsEditor;
216public:
217 QPPDOptionsModel(QCUPSSupport *cups, QObject *parent = 0);
218 ~QPPDOptionsModel();
219
220 int columnCount(const QModelIndex& parent = QModelIndex()) const;
221 int rowCount(const QModelIndex& parent = QModelIndex()) const;
222 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
223 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
224 QModelIndex parent(const QModelIndex& index) const;
225 Qt::ItemFlags flags(const QModelIndex& index) const;
226 QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
227
228 QOptionTreeItem* rootItem;
229 QCUPSSupport *cups;
230 const ppd_file_t* ppd;
231 void parseItems();
232 void parseGroups(QOptionTreeItem* parent);
233 void parseOptions(QOptionTreeItem* parent);
234 void parseChoices(QOptionTreeItem* parent);
235};
236
237class QPPDOptionsEditor : public QStyledItemDelegate
238{
239 Q_OBJECT
240public:
241 QPPDOptionsEditor(QObject* parent = 0) : QStyledItemDelegate(parent) {}
242 ~QPPDOptionsEditor() {}
243
244 QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
245 void setEditorData(QWidget* editor, const QModelIndex& index) const;
246 void setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
247
248private slots:
249 void cbChanged(int index);
250
251};
252
253#endif
254
255////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
256
257QPrintPropertiesDialog::QPrintPropertiesDialog(QAbstractPrintDialog *parent)
258 : QDialog(parent)
259#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
260 , m_cups(0), m_cupsOptionsModel(0)
261#endif
262{
263 QVBoxLayout *lay = new QVBoxLayout(this);
264 this->setLayout(lay);
265 QWidget *content = new QWidget(this);
266 widget.setupUi(content);
267 m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
268 lay->addWidget(content);
269 lay->addWidget(m_buttons);
270
271 connect(m_buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept()));
272 connect(m_buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
273}
274
275QPrintPropertiesDialog::~QPrintPropertiesDialog()
276{
277#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
278 delete m_cupsOptionsModel;
279#else
280 delete widget.cupsPropertiesPage;
281#endif
282}
283
284void QPrintPropertiesDialog::applyPrinterProperties(QPrinter *p)
285{
286 widget.pageSetup->setPrinter(p);
287}
288
289void QPrintPropertiesDialog::setupPrinter() const
290{
291 widget.pageSetup->setupPrinter();
292
293#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
294 QPPDOptionsModel* model = static_cast<QPPDOptionsModel*>(widget.treeView->model());
295 if (model) {
296 QOptionTreeItem* rootItem = model->rootItem;
297 QList<const ppd_option_t*> options;
298 QList<const char*> markedOptions;
299
300 addItemToOptions(rootItem, options, markedOptions);
301 model->cups->saveOptions(options, markedOptions);
302 }
303#endif
304}
305
306void QPrintPropertiesDialog::selectPrinter()
307{
308#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
309 widget.pageSetup->selectPrinter(m_cups);
310 widget.treeView->setModel(0);
311 if (m_cups && QCUPSSupport::isAvailable()) {
312
313 if (m_cupsOptionsModel == 0) {
314 m_cupsOptionsModel = new QPPDOptionsModel(m_cups);
315
316 widget.treeView->setItemDelegate(new QPPDOptionsEditor(this));
317 } else {
318 // update the model
319 m_cupsOptionsModel->parseItems();
320 }
321
322 if (m_cupsOptionsModel->rowCount() > 0) {
323 widget.treeView->setModel(m_cupsOptionsModel);
324
325 for (int i = 0; i < m_cupsOptionsModel->rowCount(); ++i)
326 widget.treeView->expand(m_cupsOptionsModel->index(i,0));
327
328 widget.tabs->setTabEnabled(1, true); // enable the advanced tab
329 } else {
330 widget.tabs->setTabEnabled(1, false);
331 }
332
333 } else
334#endif
335 {
336 widget.cupsPropertiesPage->setEnabled(false);
337 widget.pageSetup->selectPrinter(0);
338 }
339}
340
341void QPrintPropertiesDialog::selectPdfPsPrinter(const QPrinter *p)
342{
343 widget.treeView->setModel(0);
344 widget.pageSetup->selectPdfPsPrinter(p);
345 widget.tabs->setTabEnabled(1, false); // disable the advanced tab
346}
347
348void QPrintPropertiesDialog::showEvent(QShowEvent* event)
349{
350 widget.treeView->resizeColumnToContents(0);
351 event->accept();
352}
353
354#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
355void QPrintPropertiesDialog::addItemToOptions(QOptionTreeItem *parent, QList<const ppd_option_t*>& options, QList<const char*>& markedOptions) const
356{
357 for (int i = 0; i < parent->childItems.count(); ++i) {
358 QOptionTreeItem *itm = parent->childItems.at(i);
359 if (itm->type == QOptionTreeItem::Option) {
360 const ppd_option_t* opt = reinterpret_cast<const ppd_option_t*>(itm->ptr);
361 options << opt;
362 if (qstrcmp(opt->defchoice, opt->choices[itm->selected].choice) != 0) {
363 markedOptions << opt->keyword << opt->choices[itm->selected].choice;
364 }
365 } else {
366 addItemToOptions(itm, options, markedOptions);
367 }
368 }
369}
370#endif
371
372QPrintDialogPrivate::QPrintDialogPrivate()
373 : top(0), bottom(0), buttons(0), collapseButton(0)
374{
375}
376
377QPrintDialogPrivate::~QPrintDialogPrivate()
378{
379}
380
381void QPrintDialogPrivate::init()
382{
383 Q_Q(QPrintDialog);
384
385 top = new QUnixPrintWidget(0, q);
386 bottom = new QWidget(q);
387 options.setupUi(bottom);
388 options.color->setIconSize(QSize(32, 32));
389 options.color->setIcon(QIcon(QLatin1String(":/trolltech/dialogs/qprintdialog/images/status-color.png")));
390 options.grayscale->setIconSize(QSize(32, 32));
391 options.grayscale->setIcon(QIcon(QLatin1String(":/trolltech/dialogs/qprintdialog/images/status-gray-scale.png")));
392 top->d->setOptionsPane(this);
393
394 buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q);
395 collapseButton = new QPushButton(QPrintDialog::tr("&Options >>"), buttons);
396 buttons->addButton(collapseButton, QDialogButtonBox::ResetRole);
397 bottom->setVisible(false);
398
399 QPushButton *printButton = buttons->button(QDialogButtonBox::Ok);
400 printButton->setText(QPrintDialog::tr("&Print"));
401 printButton->setDefault(true);
402
403 QVBoxLayout *lay = new QVBoxLayout(q);
404 q->setLayout(lay);
405 lay->addWidget(top);
406 lay->addWidget(bottom);
407 lay->addWidget(buttons);
408
409 QPrinter* p = q->printer();
410
411 applyPrinterProperties(p);
412
413#ifdef QT_NO_MESSAGEBOX
414 QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(accept()));
415#else
416 QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(_q_checkFields()));
417#endif
418 QObject::connect(buttons, SIGNAL(rejected()), q, SLOT(reject()));
419
420 QObject::connect(options.reverse, SIGNAL(toggled(bool)),
421 q, SLOT(_q_chbPrintLastFirstToggled(bool)));
422
423 QObject::connect(collapseButton, SIGNAL(released()), q, SLOT(_q_collapseOrExpandDialog()));
424}
425
426void QPrintDialogPrivate::applyPrinterProperties(QPrinter *p)
427{
428 if (p->colorMode() == QPrinter::Color)
429 options.color->setChecked(true);
430 else
431 options.grayscale->setChecked(true);
432
433 switch(p->duplex()) {
434 case QPrinter::DuplexNone:
435 options.noDuplex->setChecked(true); break;
436 case QPrinter::DuplexLongSide:
437 case QPrinter::DuplexAuto:
438 options.duplexLong->setChecked(true); break;
439 case QPrinter::DuplexShortSide:
440 options.duplexShort->setChecked(true); break;
441 }
442 options.copies->setValue(qt_printerRealNumCopies(p->paintEngine()));
443 options.collate->setChecked(p->collateCopies());
444 options.reverse->setChecked(p->pageOrder() == QPrinter::LastPageFirst);
445 top->d->applyPrinterProperties(p);
446}
447
448void QPrintDialogPrivate::_q_chbPrintLastFirstToggled(bool checked)
449{
450 Q_Q(QPrintDialog);
451 if (checked)
452 q->printer()->setPageOrder(QPrinter::LastPageFirst);
453 else
454 q->printer()->setPageOrder(QPrinter::FirstPageFirst);
455}
456
457void QPrintDialogPrivate::_q_collapseOrExpandDialog()
458{
459 int collapseHeight = 0;
460 Q_Q(QPrintDialog);
461 QWidget *widgetToHide = bottom;
462 if (widgetToHide->isVisible()) {
463 collapseButton->setText(QPrintDialog::tr("&Options >>"));
464 collapseHeight = widgetToHide->y() + widgetToHide->height() - (top->y() + top->height());
465 }
466 else
467 collapseButton->setText(QPrintDialog::tr("&Options <<"));
468 widgetToHide->setVisible(! widgetToHide->isVisible());
469 if (! widgetToHide->isVisible()) { // make it shrink
470 q->layout()->activate();
471 q->resize( QSize(q->width(), q->height() - collapseHeight) );
472 }
473}
474
475#ifndef QT_NO_MESSAGEBOX
476void QPrintDialogPrivate::_q_checkFields()
477{
478 Q_Q(QPrintDialog);
479 if (top->d->checkFields())
480 q->accept();
481}
482#endif // QT_NO_MESSAGEBOX
483
484void QPrintDialogPrivate::setupPrinter()
485{
486 Q_Q(QPrintDialog);
487 QPrinter* p = q->printer();
488
489 if (options.duplex->isEnabled()) {
490 if (options.noDuplex->isChecked())
491 p->setDuplex(QPrinter::DuplexNone);
492 else if (options.duplexLong->isChecked())
493 p->setDuplex(QPrinter::DuplexLongSide);
494 else
495 p->setDuplex(QPrinter::DuplexShortSide);
496 }
497
498 p->setColorMode( options.color->isChecked() ? QPrinter::Color : QPrinter::GrayScale );
499
500 // print range
501 if (options.printAll->isChecked()) {
502 p->setPrintRange(QPrinter::AllPages);
503 p->setFromTo(0,0);
504 } else if (options.printSelection->isChecked()) {
505 p->setPrintRange(QPrinter::Selection);
506 p->setFromTo(0,0);
507 } else if (options.printRange->isChecked()) {
508 p->setPrintRange(QPrinter::PageRange);
509 p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value()));
510 }
511
512 // copies
513 p->setNumCopies(options.copies->value());
514 p->setCollateCopies(options.collate->isChecked());
515
516 top->d->setupPrinter();
517}
518
519void QPrintDialogPrivate::updateWidgets()
520{
521 Q_Q(QPrintDialog);
522 options.gbPrintRange->setVisible(q->isOptionEnabled(QPrintDialog::PrintPageRange) ||
523 q->isOptionEnabled(QPrintDialog::PrintSelection));
524
525 options.printRange->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange));
526 options.printSelection->setVisible(q->isOptionEnabled(QPrintDialog::PrintSelection));
527 options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies));
528
529 switch (q->printRange()) {
530 case QPrintDialog::AllPages:
531 options.printAll->setChecked(true);
532 break;
533 case QPrintDialog::Selection:
534 options.printSelection->setChecked(true);
535 break;
536 case QPrintDialog::PageRange:
537 options.printRange->setChecked(true);
538 break;
539 default:
540 break;
541 }
542 const int minPage = qMax(1, qMin(q->minPage() , q->maxPage()));
543 const int maxPage = qMax(1, q->maxPage() == INT_MAX ? 9999 : q->maxPage());
544
545 options.from->setMinimum(minPage);
546 options.to->setMinimum(minPage);
547 options.from->setMaximum(maxPage);
548 options.to->setMaximum(maxPage);
549
550 options.from->setValue(q->fromPage());
551 options.to->setValue(q->toPage());
552 top->d->updateWidget();
553}
554
555void QPrintDialogPrivate::setTabs(const QList<QWidget*> &tabWidgets)
556{
557 while(options.tabs->count() > 2)
558 delete options.tabs->widget(2);
559
560 QList<QWidget*>::ConstIterator iter = tabWidgets.begin();
561 while(iter != tabWidgets.constEnd()) {
562 QWidget *tab = *iter;
563 options.tabs->addTab(tab, tab->windowTitle());
564 ++iter;
565 }
566}
567
568#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
569void QPrintDialogPrivate::selectPrinter(QCUPSSupport *cups)
570{
571 options.duplex->setEnabled(cups && cups->ppdOption("Duplex"));
572}
573#endif
574
575////////////////////////////////////////////////////////////////////////////////
576
577QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent)
578 : QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent)
579{
580 Q_D(QPrintDialog);
581 d->init();
582}
583
584/*!
585 Constructs a print dialog with the given \a parent.
586*/
587QPrintDialog::QPrintDialog(QWidget *parent)
588 : QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent)
589{
590 Q_D(QPrintDialog);
591 d->init();
592}
593
594QPrintDialog::~QPrintDialog()
595{
596}
597
598void QPrintDialog::setVisible(bool visible)
599{
600 Q_D(QPrintDialog);
601
602 if (visible)
603 d->updateWidgets();
604
605 QAbstractPrintDialog::setVisible(visible);
606}
607
608int QPrintDialog::exec()
609{
610 return QDialog::exec();
611}
612
613void QPrintDialog::accept()
614{
615 Q_D(QPrintDialog);
616 d->setupPrinter();
617 QDialog::accept();
618}
619
620#ifdef QT3_SUPPORT
621QPrinter *QPrintDialog::printer() const
622{
623 Q_D(const QPrintDialog);
624 return d->printer;
625}
626
627void QPrintDialog::setPrinter(QPrinter *printer, bool pickupSettings)
628{
629 if (!printer)
630 return;
631
632 Q_D(QPrintDialog);
633 d->printer = printer;
634
635 if (pickupSettings)
636 d->applyPrinterProperties(printer);
637}
638
639void QPrintDialog::addButton(QPushButton *button)
640{
641 Q_D(QPrintDialog);
642 d->buttons->addButton(button, QDialogButtonBox::HelpRole);
643}
644#endif // QT3_SUPPORT
645
646#if defined (Q_OS_UNIX) || defined (Q_WS_PM)
647
648/*! \internal
649*/
650QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p)
651 : parent(p), propertiesDialog(0), printer(0), optionsPane(0), filePrintersAdded(false)
652#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
653 , cups(0), cupsPrinterCount(0), cupsPrinters(0), cupsPPD(0)
654#endif
655{
656 q = 0;
657 if (parent)
658 q = qobject_cast<QAbstractPrintDialog*> (parent->parent());
659
660 widget.setupUi(parent);
661
662 int currentPrinterIndex = 0;
663#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
664 cups = new QCUPSSupport;
665 if (QCUPSSupport::isAvailable()) {
666 cupsPPD = cups->currentPPD();
667 cupsPrinterCount = cups->availablePrintersCount();
668 cupsPrinters = cups->availablePrinters();
669
670 for (int i = 0; i < cupsPrinterCount; ++i) {
671 QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name));
672 if (cupsPrinters[i].instance)
673 printerName += QLatin1Char('/') + QString::fromLocal8Bit(cupsPrinters[i].instance);
674
675 widget.printers->addItem(printerName);
676 if (cupsPrinters[i].is_default)
677 widget.printers->setCurrentIndex(i);
678 }
679 // the model depends on valid ppd. so before enabling the
680 // properties button we make sure the ppd is in fact valid.
681 if (cupsPrinterCount && cups->currentPPD()) {
682 widget.properties->setEnabled(true);
683 }
684 currentPrinterIndex = cups->currentPrinterIndex();
685 } else {
686#endif
687#ifndef QT_NO_LPR
688 currentPrinterIndex = qt_getLprPrinters(lprPrinters);
689 // populating printer combo
690 QList<QPrinterDescription>::const_iterator i = lprPrinters.constBegin();
691 for(; i != lprPrinters.constEnd(); ++i)
692 widget.printers->addItem((*i).name);
693#endif
694#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
695 }
696#endif
697
698#ifndef QT_NO_FILESYSTEMMODEL
699 QFileSystemModel *fsm = new QFileSystemModel(widget.filename);
700 fsm->setRootPath(QDir::homePath());
701#if !defined(QT_NO_FSCOMPLETER) && !defined(QT_NO_FILEDIALOG)
702 widget.filename->setCompleter(new QFSCompleter(fsm, widget.filename));
703#endif
704#endif
705 _q_printerChanged(currentPrinterIndex);
706
707 QObject::connect(widget.printers, SIGNAL(currentIndexChanged(int)),
708 parent, SLOT(_q_printerChanged(int)));
709 QObject::connect(widget.fileBrowser, SIGNAL(clicked()), parent, SLOT(_q_btnBrowseClicked()));
710 QObject::connect(widget.properties, SIGNAL(clicked()), parent, SLOT(_q_btnPropertiesClicked()));
711
712 // disable features that QPrinter does not yet support.
713 widget.preview->setVisible(false);
714}
715
716void QUnixPrintWidgetPrivate::updateWidget()
717{
718 const bool printToFile = q == 0 || q->isOptionEnabled(QPrintDialog::PrintToFile);
719 if (printToFile && !filePrintersAdded) {
720 if (widget.printers->count())
721 widget.printers->insertSeparator(widget.printers->count());
722 widget.printers->addItem(QPrintDialog::tr("Print to File (PDF)"));
723 widget.printers->addItem(QPrintDialog::tr("Print to File (Postscript)"));
724 filePrintersAdded = true;
725 }
726 if (!printToFile && filePrintersAdded) {
727 widget.printers->removeItem(widget.printers->count()-1);
728 widget.printers->removeItem(widget.printers->count()-1);
729 if (widget.printers->count())
730 widget.printers->removeItem(widget.printers->count()-1); // remove separator
731 filePrintersAdded = false;
732 }
733 if (printer && filePrintersAdded && (printer->outputFormat() != QPrinter::NativeFormat
734 || printer->printerName().isEmpty()))
735 {
736 if (printer->outputFormat() == QPrinter::PdfFormat)
737 widget.printers->setCurrentIndex(widget.printers->count() - 2);
738 else if (printer->outputFormat() == QPrinter::PostScriptFormat)
739 widget.printers->setCurrentIndex(widget.printers->count() - 1);
740 widget.filename->setEnabled(true);
741 widget.lOutput->setEnabled(true);
742 widget.fileBrowser->setEnabled(true);
743 }
744
745 widget.filename->setVisible(printToFile);
746 widget.lOutput->setVisible(printToFile);
747 widget.fileBrowser->setVisible(printToFile);
748
749 widget.properties->setVisible(q->isOptionEnabled(QAbstractPrintDialog::PrintShowPageSize));
750}
751
752QUnixPrintWidgetPrivate::~QUnixPrintWidgetPrivate()
753{
754#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
755 delete cups;
756#endif
757}
758
759static QString defaultOutputFileName(const QString &docName, QPrinter::OutputFormat format)
760{
761 if (format == QPrinter::PostScriptFormat || format == QPrinter::PdfFormat) {
762 QString cur = QDir::currentPath();
763#ifndef Q_WS_PM
764 QString home = QDir::homePath();
765 if (home.at(home.length()-1) != QLatin1Char('/'))
766 home += QLatin1Char('/');
767 if (cur.at(cur.length()-1) != QLatin1Char('/'))
768 cur += QLatin1Char('/');
769 if (cur.left(home.length()) != home)
770 cur = home;
771#endif
772#if defined(Q_WS_X11) || defined(Q_WS_PM)
773 if (docName.isEmpty()) {
774 if (format == QPrinter::PostScriptFormat)
775 cur += QLatin1String("print.ps");
776 else
777 cur += QLatin1String("print.pdf");
778 } else {
779 QRegExp re(QString::fromLatin1("(.*)\\.\\S+"));
780 if (re.exactMatch(docName))
781 cur += re.cap(1);
782 else
783 cur += docName;
784 if (format == QPrinter::PostScriptFormat)
785 cur += QLatin1String(".ps");
786 else
787 cur += QLatin1String(".pdf");
788 }
789#endif
790 return cur;
791 }
792 return QString::null;
793}
794
795void QUnixPrintWidgetPrivate::_q_printerChanged(int index)
796{
797 if (index < 0)
798 return;
799 const int printerCount = widget.printers->count();
800 widget.filename->setEnabled(false);
801 widget.lOutput->setEnabled(false);
802 widget.fileBrowser->setEnabled(false);
803
804 if (filePrintersAdded) {
805 Q_ASSERT(index != printerCount - 3); // separator
806 if (index > printerCount - 3) { // PDF or postscript
807 bool pdfPrinter = (index == printerCount - 2);
808 widget.location->setText(QPrintDialog::tr("Local file"));
809 widget.type->setText(QPrintDialog::tr("Write %1 file").arg(pdfPrinter ? QString::fromLatin1("PDF")
810 : QString::fromLatin1("PostScript")));
811 widget.properties->setEnabled(true);
812 widget.filename->setEnabled(true);
813 QString filename = widget.filename->text();
814 if (filename.isEmpty())
815 filename = defaultOutputFileName(printer->docName(), pdfPrinter ? QPrinter::PdfFormat :
816 QPrinter::PostScriptFormat);
817 else {
818 QFileInfo fileInfo = QFileInfo(filename);
819 QString suffix = fileInfo.suffix();
820 if (pdfPrinter && suffix == QLatin1String("ps"))
821 filename = fileInfo.path() + QDir::separator() +
822 fileInfo.completeBaseName() + QLatin1String(".pdf");
823 if (!pdfPrinter && suffix == QLatin1String("pdf"))
824 filename = fileInfo.path() + QDir::separator() +
825 fileInfo.completeBaseName() + QLatin1String(".ps");
826 filename = QDir::cleanPath(filename);
827 }
828 widget.filename->setText(QDir::toNativeSeparators(filename));
829 widget.lOutput->setEnabled(true);
830 widget.fileBrowser->setEnabled(true);
831 if (propertiesDialog)
832 propertiesDialog->selectPdfPsPrinter(printer);
833#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
834 if (optionsPane)
835 optionsPane->selectPrinter(0);
836#endif
837 return;
838 }
839 }
840
841 widget.location->setText(QString());
842#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
843 if (QCUPSSupport::isAvailable()) {
844 cups->setCurrentPrinter(index);
845
846 const cups_option_t *opt = cups->printerOption(QString::fromLatin1("printer-location"));
847 QString location;
848 if (opt)
849 location = QString::fromLocal8Bit(opt->value);
850 widget.location->setText(location);
851
852 cupsPPD = cups->currentPPD();
853 // set printer type line
854 QString type;
855 if (cupsPPD)
856 type = QString::fromLocal8Bit(cupsPPD->manufacturer) + QLatin1String(" - ") + QString::fromLocal8Bit(cupsPPD->modelname);
857 widget.type->setText(type);
858 if (propertiesDialog)
859 propertiesDialog->selectPrinter();
860 if (optionsPane)
861 optionsPane->selectPrinter(cups);
862 } else {
863 if (optionsPane)
864 optionsPane->selectPrinter(0);
865#endif
866 if (lprPrinters.count() > 0) {
867 QString type = lprPrinters.at(index).name + QLatin1Char('@') + lprPrinters.at(index).host;
868 if (!lprPrinters.at(index).comment.isEmpty())
869 type += QLatin1String(", ") + lprPrinters.at(index).comment;
870 widget.type->setText(type);
871 if (propertiesDialog)
872 propertiesDialog->selectPrinter();
873 }
874#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
875 }
876#endif
877}
878
879void QUnixPrintWidgetPrivate::setOptionsPane(QPrintDialogPrivate *pane)
880{
881 optionsPane = pane;
882 if (optionsPane)
883 _q_printerChanged(widget.printers->currentIndex());
884}
885
886void QUnixPrintWidgetPrivate::_q_btnBrowseClicked()
887{
888 QString filename = widget.filename->text();
889#ifndef QT_NO_FILEDIALOG
890 filename = QFileDialog::getSaveFileName(parent, QPrintDialog::tr("Print To File ..."), filename,
891 QString(), 0, QFileDialog::DontConfirmOverwrite);
892#else
893 filename.clear();
894#endif
895 if (!filename.isEmpty()) {
896 widget.filename->setText(QDir::toNativeSeparators(filename));
897 if (filename.endsWith(QString::fromLatin1(".ps"), Qt::CaseInsensitive))
898 widget.printers->setCurrentIndex(widget.printers->count() - 1); // the postscript one
899 else if (filename.endsWith(QString::fromLatin1(".pdf"), Qt::CaseInsensitive))
900 widget.printers->setCurrentIndex(widget.printers->count() - 2); // the pdf one
901 else if (widget.printers->currentIndex() != widget.printers->count() - 1) // if ps is not selected, pdf is default
902 widget.printers->setCurrentIndex(widget.printers->count() - 2); // the pdf one
903 }
904}
905
906void QUnixPrintWidgetPrivate::applyPrinterProperties(QPrinter *p)
907{
908 if (p == 0)
909 return;
910 printer = p;
911 if (p->outputFileName().isEmpty())
912 widget.filename->setText(QDir::toNativeSeparators(
913 defaultOutputFileName(p->docName(), p->outputFormat())));
914 else
915 widget.filename->setText(QDir::toNativeSeparators(p->outputFileName()));
916 QString printerName = p->printerName();
917 if (!printerName.isEmpty()) {
918 for (int i = 0; i < widget.printers->count(); ++i) {
919 if (widget.printers->itemText(i) == printerName) {
920 widget.printers->setCurrentIndex(i);
921 break;
922 }
923 }
924 }
925 // PDF and PS printers are not added to the dialog yet, we'll handle those cases in QUnixPrintWidgetPrivate::updateWidget
926
927 if (propertiesDialog)
928 propertiesDialog->applyPrinterProperties(p);
929}
930
931#ifndef QT_NO_MESSAGEBOX
932bool QUnixPrintWidgetPrivate::checkFields()
933{
934 if (widget.filename->isEnabled()) {
935 QString file = widget.filename->text();
936 QFile f(file);
937 QFileInfo fi(f);
938 bool exists = fi.exists();
939 bool opened = false;
940 if (exists && fi.isDir()) {
941 QMessageBox::warning(q, q->windowTitle(),
942 QPrintDialog::tr("%1 is a directory.\nPlease choose a different file name.").arg(file));
943 return false;
944 } else if ((exists && !fi.isWritable()) || !(opened = f.open(QFile::Append))) {
945 QMessageBox::warning(q, q->windowTitle(),
946 QPrintDialog::tr("File %1 is not writable.\nPlease choose a different file name.").arg(file));
947 return false;
948 } else if (exists) {
949 int ret = QMessageBox::question(q, q->windowTitle(),
950 QPrintDialog::tr("%1 already exists.\nDo you want to overwrite it?").arg(file),
951 QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
952 if (ret == QMessageBox::No)
953 return false;
954 }
955 if (opened) {
956 f.close();
957 if (!exists)
958 f.remove();
959 }
960 }
961
962 // Every test passed. Accept the dialog.
963 return true;
964}
965#endif // QT_NO_MESSAGEBOX
966
967void QUnixPrintWidgetPrivate::_q_btnPropertiesClicked()
968{
969 if (propertiesDialog == 0) {
970 propertiesDialog = new QPrintPropertiesDialog(q);
971 propertiesDialog->setResult(QDialog::Rejected);
972 }
973
974 if (propertiesDialog->result() == QDialog::Rejected) {
975#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
976 propertiesDialog->setCups(cups);
977#endif
978 propertiesDialog->applyPrinterProperties(q->printer());
979
980 if (q->isOptionEnabled(QPrintDialog::PrintToFile)
981 && (widget.printers->currentIndex() > widget.printers->count() - 3)) // PDF or postscript
982 propertiesDialog->selectPdfPsPrinter(q->printer());
983 else
984 propertiesDialog->selectPrinter();
985 }
986 propertiesDialog->exec();
987}
988
989void QUnixPrintWidgetPrivate::setupPrinter()
990{
991 const int printerCount = widget.printers->count();
992 const int index = widget.printers->currentIndex();
993
994 if (filePrintersAdded && index > printerCount - 3) { // PDF or postscript
995 printer->setPrinterName(QString());
996 Q_ASSERT(index != printerCount - 3); // separator
997 if (index == printerCount - 2)
998 printer->setOutputFormat(QPrinter::PdfFormat);
999 else
1000 printer->setOutputFormat(QPrinter::PostScriptFormat);
1001 QString path = widget.filename->text();
1002 if (QDir::isRelativePath(path))
1003#ifndef Q_WS_PM
1004 path = QDir::homePath() + QDir::separator() + path;
1005#else
1006 path = QDir::currentPath() + QDir::separator() + path;
1007#endif
1008 printer->setOutputFileName(path);
1009 }
1010 else {
1011 printer->setPrinterName(widget.printers->currentText());
1012 printer->setOutputFileName(QString());
1013 }
1014
1015 if (propertiesDialog && propertiesDialog->result() == QDialog::Accepted)
1016 propertiesDialog->setupPrinter();
1017}
1018
1019
1020/*! \internal
1021*/
1022QUnixPrintWidget::QUnixPrintWidget(QPrinter *printer, QWidget *parent)
1023 : QWidget(parent), d(new QUnixPrintWidgetPrivate(this))
1024{
1025 d->applyPrinterProperties(printer);
1026}
1027
1028/*! \internal
1029*/
1030QUnixPrintWidget::~QUnixPrintWidget()
1031{
1032 delete d;
1033}
1034
1035/*! \internal
1036
1037 Updates the printer with the states held in the QUnixPrintWidget.
1038*/
1039void QUnixPrintWidget::updatePrinter()
1040{
1041 d->setupPrinter();
1042}
1043
1044#endif
1045
1046////////////////////////////////////////////////////////////////////////////////
1047
1048#if !defined(QT_NO_CUPS) && (!defined(QT_NO_LIBRARY) || defined (Q_WS_PM))
1049
1050QPPDOptionsModel::QPPDOptionsModel(QCUPSSupport *c, QObject *parent)
1051 : QAbstractItemModel(parent), rootItem(0), cups(c), ppd(c->currentPPD())
1052{
1053 parseItems();
1054}
1055
1056QPPDOptionsModel::~QPPDOptionsModel()
1057{
1058}
1059
1060int QPPDOptionsModel::columnCount(const QModelIndex&) const
1061{
1062 return 2;
1063}
1064
1065int QPPDOptionsModel::rowCount(const QModelIndex& parent) const
1066{
1067 QOptionTreeItem* itm;
1068 if (!parent.isValid())
1069 itm = rootItem;
1070 else
1071 itm = reinterpret_cast<QOptionTreeItem*>(parent.internalPointer());
1072
1073 if (itm->type == QOptionTreeItem::Option)
1074 return 0;
1075
1076 return itm->childItems.count();
1077}
1078
1079QVariant QPPDOptionsModel::data(const QModelIndex& index, int role) const
1080{
1081 switch(role) {
1082 case Qt::FontRole: {
1083 QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
1084 if (itm && itm->type == QOptionTreeItem::Group){
1085 QFont font = QApplication::font();
1086 font.setBold(true);
1087 return QVariant(font);
1088 }
1089 return QVariant();
1090 }
1091 break;
1092
1093 case Qt::DisplayRole: {
1094 QOptionTreeItem* itm;
1095 if (!index.isValid())
1096 itm = rootItem;
1097 else
1098 itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
1099
1100 if (index.column() == 0)
1101 return cups->unicodeString(itm->description);
1102 else if (itm->type == QOptionTreeItem::Option && itm->selected > -1)
1103 return cups->unicodeString(itm->selDescription);
1104 else
1105 return QVariant();
1106 }
1107 break;
1108
1109 default:
1110 return QVariant();
1111 }
1112 if (role != Qt::DisplayRole)
1113 return QVariant();
1114}
1115
1116QModelIndex QPPDOptionsModel::index(int row, int column, const QModelIndex& parent) const
1117{
1118 QOptionTreeItem* itm;
1119 if (!parent.isValid())
1120 itm = rootItem;
1121 else
1122 itm = reinterpret_cast<QOptionTreeItem*>(parent.internalPointer());
1123
1124 return createIndex(row, column, itm->childItems.at(row));
1125}
1126
1127
1128QModelIndex QPPDOptionsModel::parent(const QModelIndex& index) const
1129{
1130 if (!index.isValid())
1131 return QModelIndex();
1132
1133 QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
1134
1135 if (itm->parentItem && itm->parentItem != rootItem)
1136 return createIndex(itm->parentItem->index, 0, itm->parentItem);
1137 else
1138 return QModelIndex();
1139}
1140
1141Qt::ItemFlags QPPDOptionsModel::flags(const QModelIndex& index) const
1142{
1143 if (!index.isValid() || reinterpret_cast<QOptionTreeItem*>(index.internalPointer())->type == QOptionTreeItem::Group)
1144 return Qt::ItemIsEnabled;
1145
1146 if (index.column() == 1)
1147 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
1148
1149 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
1150}
1151
1152void QPPDOptionsModel::parseItems()
1153{
1154 emit layoutAboutToBeChanged();
1155 ppd = cups->currentPPD();
1156 delete rootItem;
1157 rootItem = new QOptionTreeItem(QOptionTreeItem::Root, 0, ppd, "Root Item", 0);
1158 parseGroups(rootItem);
1159 emit layoutChanged();
1160}
1161
1162void QPPDOptionsModel::parseGroups(QOptionTreeItem* parent)
1163{
1164 if (parent->type == QOptionTreeItem::Root) {
1165
1166 const ppd_file_t* ppdFile = reinterpret_cast<const ppd_file_t*>(parent->ptr);
1167
1168 if (ppdFile) {
1169 for (int i = 0; i < ppdFile->num_groups; ++i) {
1170 QOptionTreeItem* group = new QOptionTreeItem(QOptionTreeItem::Group, i, &ppdFile->groups[i], ppdFile->groups[i].text, parent);
1171 parent->childItems.append(group);
1172 parseGroups(group); // parse possible subgroups
1173 parseOptions(group); // parse options
1174 }
1175 }
1176 } else if (parent->type == QOptionTreeItem::Group) {
1177
1178 const ppd_group_t* group = reinterpret_cast<const ppd_group_t*>(parent->ptr);
1179
1180 if (group) {
1181 for (int i = 0; i < group->num_subgroups; ++i) {
1182 QOptionTreeItem* subgroup = new QOptionTreeItem(QOptionTreeItem::Group, i, &group->subgroups[i], group->subgroups[i].text, parent);
1183 parent->childItems.append(subgroup);
1184 parseGroups(subgroup); // parse possible subgroups
1185 parseOptions(subgroup); // parse options
1186 }
1187 }
1188 }
1189}
1190
1191void QPPDOptionsModel::parseOptions(QOptionTreeItem* parent)
1192{
1193 const ppd_group_t* group = reinterpret_cast<const ppd_group_t*>(parent->ptr);
1194 for (int i = 0; i < group->num_options; ++i) {
1195 QOptionTreeItem* opt = new QOptionTreeItem(QOptionTreeItem::Option, i, &group->options[i], group->options[i].text, parent);
1196 parent->childItems.append(opt);
1197 parseChoices(opt);
1198 }
1199}
1200
1201void QPPDOptionsModel::parseChoices(QOptionTreeItem* parent)
1202{
1203 const ppd_option_t* option = reinterpret_cast<const ppd_option_t*>(parent->ptr);
1204 bool marked = false;
1205 for (int i = 0; i < option->num_choices; ++i) {
1206 QOptionTreeItem* choice = new QOptionTreeItem(QOptionTreeItem::Choice, i, &option->choices[i], option->choices[i].text, parent);
1207 if (static_cast<int>(option->choices[i].marked) == 1) {
1208 parent->selected = i;
1209 parent->selDescription = option->choices[i].text;
1210 marked = true;
1211 } else if (!marked && qstrcmp(option->choices[i].choice, option->defchoice) == 0) {
1212 parent->selected = i;
1213 parent->selDescription = option->choices[i].text;
1214 }
1215 parent->childItems.append(choice);
1216 }
1217}
1218
1219QVariant QPPDOptionsModel::headerData(int section, Qt::Orientation, int role) const
1220{
1221 if (role != Qt::DisplayRole)
1222 return QVariant();
1223
1224 switch(section){
1225 case 0:
1226 return QVariant(QApplication::translate("QPPDOptionsModel", "Name"));
1227 case 1:
1228 return QVariant(QApplication::translate("QPPDOptionsModel", "Value"));
1229 default:
1230 return QVariant();
1231 }
1232}
1233
1234////////////////////////////////////////////////////////////////////////////////
1235
1236QWidget* QPPDOptionsEditor::createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex& index) const
1237{
1238 if (index.column() == 1 && reinterpret_cast<QOptionTreeItem*>(index.internalPointer())->type == QOptionTreeItem::Option)
1239 return new QComboBox(parent);
1240 else
1241 return 0;
1242}
1243
1244void QPPDOptionsEditor::setEditorData(QWidget* editor, const QModelIndex& index) const
1245{
1246 if (index.column() != 1)
1247 return;
1248
1249 QComboBox* cb = static_cast<QComboBox*>(editor);
1250 QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
1251
1252 if (itm->selected == -1)
1253 cb->addItem(QString());
1254
1255 for (int i = 0; i < itm->childItems.count(); ++i)
1256 cb->addItem(QString::fromLocal8Bit(itm->childItems.at(i)->description));
1257
1258 if (itm->selected > -1)
1259 cb->setCurrentIndex(itm->selected);
1260
1261 connect(cb, SIGNAL(currentIndexChanged(int)), this, SLOT(cbChanged(int)));
1262}
1263
1264void QPPDOptionsEditor::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
1265{
1266 QComboBox* cb = static_cast<QComboBox*>(editor);
1267 QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer());
1268
1269 if (itm->selected == cb->currentIndex())
1270 return;
1271
1272 const ppd_option_t* opt = reinterpret_cast<const ppd_option_t*>(itm->ptr);
1273 QPPDOptionsModel* m = static_cast<QPPDOptionsModel*>(model);
1274
1275 if (m->cups->markOption(opt->keyword, opt->choices[cb->currentIndex()].choice) == 0) {
1276 itm->selected = cb->currentIndex();
1277 itm->selDescription = reinterpret_cast<const ppd_option_t*>(itm->ptr)->choices[itm->selected].text;
1278 }
1279}
1280
1281void QPPDOptionsEditor::cbChanged(int)
1282{
1283/*
1284 emit commitData(static_cast<QWidget*>(sender()));
1285*/
1286}
1287
1288#endif
1289
1290QT_END_NAMESPACE
1291
1292#include "moc_qprintdialog.cpp"
1293#include "qprintdialog_unix.moc"
1294#include "qrc_qprintdialog.cpp"
1295
1296#endif // QT_NO_PRINTDIALOG
1297
Note: See TracBrowser for help on using the repository browser.