author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 25 | e24348a560a6 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
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 |
||
73 |
QT_BEGIN_NAMESPACE |
|
74 |
||
75 |
class QOptionTreeItem; |
|
76 |
class QPPDOptionsModel; |
|
77 |
||
78 |
class QPrintPropertiesDialog : public QDialog |
|
79 |
{ |
|
80 |
Q_OBJECT |
|
81 |
public: |
|
82 |
QPrintPropertiesDialog(QAbstractPrintDialog *parent = 0); |
|
83 |
~QPrintPropertiesDialog(); |
|
84 |
||
85 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
86 |
void setCups(QCUPSSupport *cups) { m_cups = cups; } |
|
87 |
void addItemToOptions(QOptionTreeItem *parent, QList<const ppd_option_t*>& options, QList<const char*>& markedOptions) const; |
|
88 |
#endif |
|
89 |
||
90 |
void selectPrinter(); |
|
91 |
void selectPdfPsPrinter(const QPrinter *p); |
|
92 |
||
93 |
/// copy printer properties to the widget |
|
94 |
void applyPrinterProperties(QPrinter *p); |
|
95 |
void setupPrinter() const; |
|
96 |
||
97 |
protected: |
|
98 |
void showEvent(QShowEvent* event); |
|
99 |
||
100 |
private: |
|
101 |
Ui::QPrintPropertiesWidget widget; |
|
102 |
QDialogButtonBox *m_buttons; |
|
103 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
104 |
QCUPSSupport *m_cups; |
|
105 |
QPPDOptionsModel *m_cupsOptionsModel; |
|
106 |
#endif |
|
107 |
}; |
|
108 |
||
109 |
class QPrintDialogPrivate : public QAbstractPrintDialogPrivate |
|
110 |
{ |
|
111 |
Q_DECLARE_PUBLIC(QPrintDialog) |
|
112 |
Q_DECLARE_TR_FUNCTIONS(QPrintDialog) |
|
113 |
public: |
|
114 |
QPrintDialogPrivate(); |
|
115 |
~QPrintDialogPrivate(); |
|
116 |
||
117 |
void init(); |
|
118 |
/// copy printer properties to the widget |
|
119 |
void applyPrinterProperties(QPrinter *p); |
|
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; |
|
138 |
QWidget *bottom; |
|
139 |
QDialogButtonBox *buttons; |
|
140 |
QPushButton *collapseButton; |
|
141 |
}; |
|
142 |
||
143 |
#if defined (Q_OS_UNIX) |
|
144 |
class QUnixPrintWidgetPrivate |
|
145 |
{ |
|
146 |
public: |
|
147 |
QUnixPrintWidgetPrivate(QUnixPrintWidget *q); |
|
148 |
~QUnixPrintWidgetPrivate(); |
|
149 |
||
150 |
/// copy printer properties to the widget |
|
151 |
void applyPrinterProperties(QPrinter *p); |
|
152 |
bool checkFields(); |
|
153 |
void setupPrinter(); |
|
154 |
void setOptionsPane(QPrintDialogPrivate *pane); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
155 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
156 |
void setCupsProperties(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
157 |
#endif |
0 | 158 |
|
159 |
// slots |
|
160 |
void _q_printerChanged(int index); |
|
161 |
void _q_btnPropertiesClicked(); |
|
162 |
void _q_btnBrowseClicked(); |
|
163 |
||
164 |
QUnixPrintWidget * const parent; |
|
165 |
QPrintPropertiesDialog *propertiesDialog; |
|
166 |
Ui::QPrintWidget widget; |
|
167 |
QAbstractPrintDialog * q; |
|
168 |
QPrinter *printer; |
|
169 |
QList<QPrinterDescription> lprPrinters; |
|
170 |
void updateWidget(); |
|
171 |
||
172 |
private: |
|
173 |
QPrintDialogPrivate *optionsPane; |
|
174 |
bool filePrintersAdded; |
|
175 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
176 |
QCUPSSupport* cups; |
|
177 |
int cupsPrinterCount; |
|
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) |
|
185 |
class QOptionTreeItem |
|
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 |
||
199 |
~QOptionTreeItem() { |
|
200 |
while (!childItems.isEmpty()) |
|
201 |
delete childItems.takeFirst(); |
|
202 |
} |
|
203 |
||
204 |
ItemType type; |
|
205 |
int index; |
|
206 |
const void* ptr; |
|
207 |
const char* description; |
|
208 |
int selected; |
|
209 |
const char* selDescription; |
|
210 |
QOptionTreeItem* parentItem; |
|
211 |
QList<QOptionTreeItem*> childItems; |
|
212 |
}; |
|
213 |
||
214 |
class QPPDOptionsModel : public QAbstractItemModel |
|
215 |
{ |
|
216 |
friend class QPPDOptionsEditor; |
|
217 |
public: |
|
218 |
QPPDOptionsModel(QCUPSSupport *cups, QObject *parent = 0); |
|
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 |
||
229 |
QOptionTreeItem* rootItem; |
|
230 |
QCUPSSupport *cups; |
|
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 |
||
238 |
class QPPDOptionsEditor : public QStyledItemDelegate |
|
239 |
{ |
|
240 |
Q_OBJECT |
|
241 |
public: |
|
242 |
QPPDOptionsEditor(QObject* parent = 0) : QStyledItemDelegate(parent) {} |
|
243 |
~QPPDOptionsEditor() {} |
|
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 |
||
256 |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
257 |
||
258 |
QPrintPropertiesDialog::QPrintPropertiesDialog(QAbstractPrintDialog *parent) |
|
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); |
|
268 |
m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); |
|
269 |
lay->addWidget(content); |
|
270 |
lay->addWidget(m_buttons); |
|
271 |
||
272 |
connect(m_buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept())); |
|
273 |
connect(m_buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); |
|
274 |
} |
|
275 |
||
276 |
QPrintPropertiesDialog::~QPrintPropertiesDialog() |
|
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 |
||
285 |
void QPrintPropertiesDialog::applyPrinterProperties(QPrinter *p) |
|
286 |
{ |
|
287 |
widget.pageSetup->setPrinter(p); |
|
288 |
} |
|
289 |
||
290 |
void QPrintPropertiesDialog::setupPrinter() const |
|
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; |
|
298 |
QList<const ppd_option_t*> options; |
|
299 |
QList<const char*> markedOptions; |
|
300 |
||
301 |
addItemToOptions(rootItem, options, markedOptions); |
|
302 |
model->cups->saveOptions(options, markedOptions); |
|
303 |
} |
|
304 |
#endif |
|
305 |
} |
|
306 |
||
307 |
void QPrintPropertiesDialog::selectPrinter() |
|
308 |
{ |
|
309 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
310 |
widget.pageSetup->selectPrinter(m_cups); |
|
311 |
widget.treeView->setModel(0); |
|
312 |
if (m_cups && QCUPSSupport::isAvailable()) { |
|
313 |
||
314 |
if (m_cupsOptionsModel == 0) { |
|
315 |
m_cupsOptionsModel = new QPPDOptionsModel(m_cups); |
|
316 |
||
317 |
widget.treeView->setItemDelegate(new QPPDOptionsEditor(this)); |
|
318 |
} else { |
|
319 |
// update the model |
|
320 |
m_cupsOptionsModel->parseItems(); |
|
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 |
||
342 |
void QPrintPropertiesDialog::selectPdfPsPrinter(const QPrinter *p) |
|
343 |
{ |
|
344 |
widget.treeView->setModel(0); |
|
345 |
widget.pageSetup->selectPdfPsPrinter(p); |
|
346 |
widget.tabs->setTabEnabled(1, false); // disable the advanced tab |
|
347 |
} |
|
348 |
||
349 |
void QPrintPropertiesDialog::showEvent(QShowEvent* event) |
|
350 |
{ |
|
351 |
widget.treeView->resizeColumnToContents(0); |
|
352 |
event->accept(); |
|
353 |
} |
|
354 |
||
355 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
356 |
void QPrintPropertiesDialog::addItemToOptions(QOptionTreeItem *parent, QList<const ppd_option_t*>& options, QList<const char*>& markedOptions) const |
|
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 |
||
373 |
QPrintDialogPrivate::QPrintDialogPrivate() |
|
374 |
: top(0), bottom(0), buttons(0), collapseButton(0) |
|
375 |
{ |
|
376 |
} |
|
377 |
||
378 |
QPrintDialogPrivate::~QPrintDialogPrivate() |
|
379 |
{ |
|
380 |
} |
|
381 |
||
382 |
void QPrintDialogPrivate::init() |
|
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 |
||
395 |
buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q); |
|
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 |
||
412 |
applyPrinterProperties(p); |
|
413 |
||
414 |
#ifdef QT_NO_MESSAGEBOX |
|
415 |
QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(accept())); |
|
416 |
#else |
|
417 |
QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(_q_checkFields())); |
|
418 |
#endif |
|
419 |
QObject::connect(buttons, SIGNAL(rejected()), q, SLOT(reject())); |
|
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 |
||
427 |
void QPrintDialogPrivate::applyPrinterProperties(QPrinter *p) |
|
428 |
{ |
|
429 |
if (p->colorMode() == QPrinter::Color) |
|
430 |
options.color->setChecked(true); |
|
431 |
else |
|
432 |
options.grayscale->setChecked(true); |
|
433 |
||
434 |
switch(p->duplex()) { |
|
435 |
case QPrinter::DuplexNone: |
|
436 |
options.noDuplex->setChecked(true); break; |
|
437 |
case QPrinter::DuplexLongSide: |
|
438 |
case QPrinter::DuplexAuto: |
|
439 |
options.duplexLong->setChecked(true); break; |
|
440 |
case QPrinter::DuplexShortSide: |
|
441 |
options.duplexShort->setChecked(true); break; |
|
442 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
443 |
options.copies->setValue(p->copyCount()); |
0 | 444 |
options.collate->setChecked(p->collateCopies()); |
445 |
options.reverse->setChecked(p->pageOrder() == QPrinter::LastPageFirst); |
|
446 |
top->d->applyPrinterProperties(p); |
|
447 |
} |
|
448 |
||
449 |
void QPrintDialogPrivate::_q_chbPrintLastFirstToggled(bool checked) |
|
450 |
{ |
|
451 |
Q_Q(QPrintDialog); |
|
452 |
if (checked) |
|
453 |
q->printer()->setPageOrder(QPrinter::LastPageFirst); |
|
454 |
else |
|
455 |
q->printer()->setPageOrder(QPrinter::FirstPageFirst); |
|
456 |
} |
|
457 |
||
458 |
void QPrintDialogPrivate::_q_collapseOrExpandDialog() |
|
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 |
|
477 |
void QPrintDialogPrivate::_q_checkFields() |
|
478 |
{ |
|
479 |
Q_Q(QPrintDialog); |
|
480 |
if (top->d->checkFields()) |
|
481 |
q->accept(); |
|
482 |
} |
|
483 |
#endif // QT_NO_MESSAGEBOX |
|
484 |
||
485 |
void QPrintDialogPrivate::setupPrinter() |
|
486 |
{ |
|
487 |
Q_Q(QPrintDialog); |
|
488 |
QPrinter* p = q->printer(); |
|
489 |
||
490 |
if (options.duplex->isEnabled()) { |
|
491 |
if (options.noDuplex->isChecked()) |
|
492 |
p->setDuplex(QPrinter::DuplexNone); |
|
493 |
else if (options.duplexLong->isChecked()) |
|
494 |
p->setDuplex(QPrinter::DuplexLongSide); |
|
495 |
else |
|
496 |
p->setDuplex(QPrinter::DuplexShortSide); |
|
497 |
} |
|
498 |
||
499 |
p->setColorMode( options.color->isChecked() ? QPrinter::Color : QPrinter::GrayScale ); |
|
500 |
||
501 |
// print range |
|
502 |
if (options.printAll->isChecked()) { |
|
503 |
p->setPrintRange(QPrinter::AllPages); |
|
504 |
p->setFromTo(0,0); |
|
505 |
} else if (options.printSelection->isChecked()) { |
|
506 |
p->setPrintRange(QPrinter::Selection); |
|
507 |
p->setFromTo(0,0); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
508 |
} else if (options.printCurrentPage->isChecked()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
509 |
p->setPrintRange(QPrinter::CurrentPage); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
510 |
p->setFromTo(0,0); |
0 | 511 |
} else if (options.printRange->isChecked()) { |
512 |
p->setPrintRange(QPrinter::PageRange); |
|
513 |
p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value())); |
|
514 |
} |
|
515 |
||
516 |
// copies |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
517 |
p->setCopyCount(options.copies->value()); |
0 | 518 |
p->setCollateCopies(options.collate->isChecked()); |
519 |
||
520 |
top->d->setupPrinter(); |
|
521 |
} |
|
522 |
||
523 |
void QPrintDialogPrivate::updateWidgets() |
|
524 |
{ |
|
525 |
Q_Q(QPrintDialog); |
|
526 |
options.gbPrintRange->setVisible(q->isOptionEnabled(QPrintDialog::PrintPageRange) || |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
527 |
q->isOptionEnabled(QPrintDialog::PrintSelection) || |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
528 |
q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); |
0 | 529 |
|
530 |
options.printRange->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange)); |
|
531 |
options.printSelection->setVisible(q->isOptionEnabled(QPrintDialog::PrintSelection)); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
532 |
options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); |
0 | 533 |
options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies)); |
534 |
||
535 |
switch (q->printRange()) { |
|
536 |
case QPrintDialog::AllPages: |
|
537 |
options.printAll->setChecked(true); |
|
538 |
break; |
|
539 |
case QPrintDialog::Selection: |
|
540 |
options.printSelection->setChecked(true); |
|
541 |
break; |
|
542 |
case QPrintDialog::PageRange: |
|
543 |
options.printRange->setChecked(true); |
|
544 |
break; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
545 |
case QPrintDialog::CurrentPage: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
546 |
if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
547 |
options.printCurrentPage->setChecked(true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
548 |
break; |
0 | 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 |
||
565 |
void QPrintDialogPrivate::setTabs(const QList<QWidget*> &tabWidgets) |
|
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) |
|
579 |
void QPrintDialogPrivate::selectPrinter(QCUPSSupport *cups) |
|
580 |
{ |
|
581 |
options.duplex->setEnabled(cups && cups->ppdOption("Duplex")); |
|
582 |
} |
|
583 |
#endif |
|
584 |
||
585 |
//////////////////////////////////////////////////////////////////////////////// |
|
586 |
||
587 |
QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent) |
|
588 |
: QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent) |
|
589 |
{ |
|
590 |
Q_D(QPrintDialog); |
|
591 |
d->init(); |
|
592 |
} |
|
593 |
||
594 |
/*! |
|
595 |
Constructs a print dialog with the given \a parent. |
|
596 |
*/ |
|
597 |
QPrintDialog::QPrintDialog(QWidget *parent) |
|
598 |
: QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent) |
|
599 |
{ |
|
600 |
Q_D(QPrintDialog); |
|
601 |
d->init(); |
|
602 |
} |
|
603 |
||
604 |
QPrintDialog::~QPrintDialog() |
|
605 |
{ |
|
606 |
} |
|
607 |
||
608 |
void QPrintDialog::setVisible(bool visible) |
|
609 |
{ |
|
610 |
Q_D(QPrintDialog); |
|
611 |
||
612 |
if (visible) |
|
613 |
d->updateWidgets(); |
|
614 |
||
615 |
QAbstractPrintDialog::setVisible(visible); |
|
616 |
} |
|
617 |
||
618 |
int QPrintDialog::exec() |
|
619 |
{ |
|
620 |
return QDialog::exec(); |
|
621 |
} |
|
622 |
||
623 |
void QPrintDialog::accept() |
|
624 |
{ |
|
625 |
Q_D(QPrintDialog); |
|
626 |
d->setupPrinter(); |
|
627 |
QDialog::accept(); |
|
628 |
} |
|
629 |
||
630 |
#ifdef QT3_SUPPORT |
|
631 |
QPrinter *QPrintDialog::printer() const |
|
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 |
||
658 |
/*! \internal |
|
659 |
*/ |
|
660 |
QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p) |
|
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; |
|
675 |
if (QCUPSSupport::isAvailable()) { |
|
676 |
cupsPPD = cups->currentPPD(); |
|
677 |
cupsPrinterCount = cups->availablePrintersCount(); |
|
678 |
cupsPrinters = cups->availablePrinters(); |
|
679 |
||
680 |
for (int i = 0; i < cupsPrinterCount; ++i) { |
|
681 |
QString printerName(QString::fromLocal8Bit(cupsPrinters[i].name)); |
|
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 |
|
699 |
QList<QPrinterDescription>::const_iterator i = lprPrinters.constBegin(); |
|
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 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
706 |
#if !defined(QT_NO_FILESYSTEMMODEL) && !defined(QT_NO_COMPLETER) |
0 | 707 |
QFileSystemModel *fsm = new QFileSystemModel(widget.filename); |
708 |
fsm->setRootPath(QDir::homePath()); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
25
diff
changeset
|
709 |
widget.filename->setCompleter(new QCompleter(fsm, widget.filename)); |
0 | 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 |
||
722 |
void QUnixPrintWidgetPrivate::updateWidget() |
|
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 |
||
754 |
widget.properties->setVisible(q->isOptionEnabled(QAbstractPrintDialog::PrintShowPageSize)); |
|
755 |
} |
|
756 |
||
757 |
QUnixPrintWidgetPrivate::~QUnixPrintWidgetPrivate() |
|
758 |
{ |
|
759 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
760 |
delete cups; |
|
761 |
#endif |
|
762 |
} |
|
763 |
||
764 |
void QUnixPrintWidgetPrivate::_q_printerChanged(int index) |
|
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) |
|
790 |
propertiesDialog->selectPdfPsPrinter(printer); |
|
791 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
792 |
if (optionsPane) |
|
793 |
optionsPane->selectPrinter(0); |
|
794 |
#endif |
|
795 |
return; |
|
796 |
} |
|
797 |
} |
|
798 |
||
799 |
widget.location->setText(QString()); |
|
800 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
801 |
if (QCUPSSupport::isAvailable()) { |
|
802 |
cups->setCurrentPrinter(index); |
|
803 |
||
804 |
const cups_option_t *opt = cups->printerOption(QString::fromLatin1("printer-location")); |
|
805 |
QString 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) |
|
817 |
propertiesDialog->selectPrinter(); |
|
818 |
if (optionsPane) |
|
819 |
optionsPane->selectPrinter(cups); |
|
820 |
} else { |
|
821 |
if (optionsPane) |
|
822 |
optionsPane->selectPrinter(0); |
|
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) |
|
830 |
propertiesDialog->selectPrinter(); |
|
831 |
} |
|
832 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
833 |
} |
|
834 |
#endif |
|
835 |
} |
|
836 |
||
837 |
void QUnixPrintWidgetPrivate::setOptionsPane(QPrintDialogPrivate *pane) |
|
838 |
{ |
|
839 |
optionsPane = pane; |
|
840 |
if (optionsPane) |
|
841 |
_q_printerChanged(widget.printers->currentIndex()); |
|
842 |
} |
|
843 |
||
844 |
void QUnixPrintWidgetPrivate::_q_btnBrowseClicked() |
|
845 |
{ |
|
846 |
QString filename = widget.filename->text(); |
|
847 |
#ifndef QT_NO_FILEDIALOG |
|
848 |
filename = QFileDialog::getSaveFileName(parent, QPrintDialog::tr("Print To File ..."), filename, |
|
849 |
QString(), 0, QFileDialog::DontConfirmOverwrite); |
|
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 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
857 |
else if (filename.endsWith(QString::fromLatin1(".pdf"), Qt::CaseInsensitive)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
858 |
widget.printers->setCurrentIndex(widget.printers->count() - 2); // the pdf one |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
859 |
else if (widget.printers->currentIndex() != widget.printers->count() - 1) // if ps is not selected, pdf is default |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
860 |
widget.printers->setCurrentIndex(widget.printers->count() - 2); // the pdf one |
0 | 861 |
} |
862 |
} |
|
863 |
||
864 |
void QUnixPrintWidgetPrivate::applyPrinterProperties(QPrinter *p) |
|
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()) { |
|
880 |
if (p->outputFormat() == QPrinter::PostScriptFormat) |
|
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(); |
|
890 |
if (p->outputFormat() == QPrinter::PostScriptFormat) |
|
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) |
|
912 |
propertiesDialog->applyPrinterProperties(p); |
|
913 |
} |
|
914 |
||
915 |
#ifndef QT_NO_MESSAGEBOX |
|
916 |
bool QUnixPrintWidgetPrivate::checkFields() |
|
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()) { |
|
925 |
QMessageBox::warning(q, q->windowTitle(), |
|
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))) { |
|
929 |
QMessageBox::warning(q, q->windowTitle(), |
|
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), |
|
935 |
QMessageBox::Yes|QMessageBox::No, QMessageBox::No); |
|
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 |
||
951 |
void QUnixPrintWidgetPrivate::_q_btnPropertiesClicked() |
|
952 |
{ |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
953 |
if (!propertiesDialog) { |
0 | 954 |
propertiesDialog = new QPrintPropertiesDialog(q); |
955 |
propertiesDialog->setResult(QDialog::Rejected); |
|
956 |
} |
|
957 |
||
958 |
if (propertiesDialog->result() == QDialog::Rejected) { |
|
959 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
960 |
propertiesDialog->setCups(cups); |
|
961 |
#endif |
|
962 |
propertiesDialog->applyPrinterProperties(q->printer()); |
|
963 |
||
964 |
if (q->isOptionEnabled(QPrintDialog::PrintToFile) |
|
965 |
&& (widget.printers->currentIndex() > widget.printers->count() - 3)) // PDF or postscript |
|
966 |
propertiesDialog->selectPdfPsPrinter(q->printer()); |
|
967 |
else |
|
968 |
propertiesDialog->selectPrinter(); |
|
969 |
} |
|
970 |
propertiesDialog->exec(); |
|
971 |
} |
|
972 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
973 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
974 |
void QUnixPrintWidgetPrivate::setCupsProperties() |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
975 |
{ |
25
e24348a560a6
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
976 |
if (cups && QCUPSSupport::isAvailable() && cups->pageSizes()) { |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
977 |
QPrintEngine *engine = printer->printEngine(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
978 |
const ppd_option_t* pageSizes = cups->pageSizes(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
979 |
QByteArray cupsPageSize; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
980 |
for (int i = 0; i < pageSizes->num_choices; ++i) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
981 |
if (static_cast<int>(pageSizes->choices[i].marked) == 1) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
982 |
cupsPageSize = pageSizes->choices[i].choice; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
983 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
984 |
engine->setProperty(PPK_CupsStringPageSize, QString::fromLatin1(cupsPageSize)); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
985 |
engine->setProperty(PPK_CupsOptions, cups->options()); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
986 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
987 |
QRect pageRect = cups->pageRect(cupsPageSize); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
988 |
engine->setProperty(PPK_CupsPageRect, pageRect); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
989 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
990 |
QRect paperRect = cups->paperRect(cupsPageSize); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
991 |
engine->setProperty(PPK_CupsPaperRect, paperRect); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
992 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
993 |
for (int ps = 0; ps < QPrinter::NPaperSize; ++ps) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
994 |
QPdf::PaperSize size = QPdf::paperSize(QPrinter::PaperSize(ps)); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
995 |
if (size.width == paperRect.width() && size.height == paperRect.height()) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
996 |
printer->setPaperSize(static_cast<QPrinter::PaperSize>(ps)); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
997 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
998 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
999 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1000 |
#endif |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1001 |
|
0 | 1002 |
void QUnixPrintWidgetPrivate::setupPrinter() |
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) |
|
1011 |
printer->setOutputFormat(QPrinter::PdfFormat); |
|
1012 |
else |
|
1013 |
printer->setOutputFormat(QPrinter::PostScriptFormat); |
|
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 |
||
1024 |
if (propertiesDialog && propertiesDialog->result() == QDialog::Accepted) |
|
1025 |
propertiesDialog->setupPrinter(); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1026 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1027 |
if (!propertiesDialog) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1028 |
setCupsProperties(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1029 |
#endif |
0 | 1030 |
} |
1031 |
||
1032 |
||
1033 |
/*! \internal |
|
1034 |
*/ |
|
1035 |
QUnixPrintWidget::QUnixPrintWidget(QPrinter *printer, QWidget *parent) |
|
1036 |
: QWidget(parent), d(new QUnixPrintWidgetPrivate(this)) |
|
1037 |
{ |
|
1038 |
d->applyPrinterProperties(printer); |
|
1039 |
} |
|
1040 |
||
1041 |
/*! \internal |
|
1042 |
*/ |
|
1043 |
QUnixPrintWidget::~QUnixPrintWidget() |
|
1044 |
{ |
|
1045 |
delete d; |
|
1046 |
} |
|
1047 |
||
1048 |
/*! \internal |
|
1049 |
||
1050 |
Updates the printer with the states held in the QUnixPrintWidget. |
|
1051 |
*/ |
|
1052 |
void QUnixPrintWidget::updatePrinter() |
|
1053 |
{ |
|
1054 |
d->setupPrinter(); |
|
1055 |
} |
|
1056 |
||
1057 |
#endif |
|
1058 |
||
1059 |
//////////////////////////////////////////////////////////////////////////////// |
|
1060 |
#if !defined(QT_NO_CUPS) && !defined(QT_NO_LIBRARY) |
|
1061 |
||
1062 |
QPPDOptionsModel::QPPDOptionsModel(QCUPSSupport *c, QObject *parent) |
|
1063 |
: QAbstractItemModel(parent), rootItem(0), cups(c), ppd(c->currentPPD()) |
|
1064 |
{ |
|
1065 |
parseItems(); |
|
1066 |
} |
|
1067 |
||
1068 |
QPPDOptionsModel::~QPPDOptionsModel() |
|
1069 |
{ |
|
1070 |
} |
|
1071 |
||
1072 |
int QPPDOptionsModel::columnCount(const QModelIndex&) const |
|
1073 |
{ |
|
1074 |
return 2; |
|
1075 |
} |
|
1076 |
||
1077 |
int QPPDOptionsModel::rowCount(const QModelIndex& parent) const |
|
1078 |
{ |
|
1079 |
QOptionTreeItem* itm; |
|
1080 |
if (!parent.isValid()) |
|
1081 |
itm = rootItem; |
|
1082 |
else |
|
1083 |
itm = reinterpret_cast<QOptionTreeItem*>(parent.internalPointer()); |
|
1084 |
||
1085 |
if (itm->type == QOptionTreeItem::Option) |
|
1086 |
return 0; |
|
1087 |
||
1088 |
return itm->childItems.count(); |
|
1089 |
} |
|
1090 |
||
1091 |
QVariant QPPDOptionsModel::data(const QModelIndex& index, int role) const |
|
1092 |
{ |
|
1093 |
switch(role) { |
|
1094 |
case Qt::FontRole: { |
|
1095 |
QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer()); |
|
1096 |
if (itm && itm->type == QOptionTreeItem::Group){ |
|
1097 |
QFont font = QApplication::font(); |
|
1098 |
font.setBold(true); |
|
1099 |
return QVariant(font); |
|
1100 |
} |
|
1101 |
return QVariant(); |
|
1102 |
} |
|
1103 |
break; |
|
1104 |
||
1105 |
case Qt::DisplayRole: { |
|
1106 |
QOptionTreeItem* itm; |
|
1107 |
if (!index.isValid()) |
|
1108 |
itm = rootItem; |
|
1109 |
else |
|
1110 |
itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer()); |
|
1111 |
||
1112 |
if (index.column() == 0) |
|
1113 |
return cups->unicodeString(itm->description); |
|
1114 |
else if (itm->type == QOptionTreeItem::Option && itm->selected > -1) |
|
1115 |
return cups->unicodeString(itm->selDescription); |
|
1116 |
else |
|
1117 |
return QVariant(); |
|
1118 |
} |
|
1119 |
break; |
|
1120 |
||
1121 |
default: |
|
1122 |
return QVariant(); |
|
1123 |
} |
|
1124 |
if (role != Qt::DisplayRole) |
|
1125 |
return QVariant(); |
|
1126 |
} |
|
1127 |
||
1128 |
QModelIndex QPPDOptionsModel::index(int row, int column, const QModelIndex& parent) const |
|
1129 |
{ |
|
1130 |
QOptionTreeItem* itm; |
|
1131 |
if (!parent.isValid()) |
|
1132 |
itm = rootItem; |
|
1133 |
else |
|
1134 |
itm = reinterpret_cast<QOptionTreeItem*>(parent.internalPointer()); |
|
1135 |
||
1136 |
return createIndex(row, column, itm->childItems.at(row)); |
|
1137 |
} |
|
1138 |
||
1139 |
||
1140 |
QModelIndex QPPDOptionsModel::parent(const QModelIndex& index) const |
|
1141 |
{ |
|
1142 |
if (!index.isValid()) |
|
1143 |
return QModelIndex(); |
|
1144 |
||
1145 |
QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer()); |
|
1146 |
||
1147 |
if (itm->parentItem && itm->parentItem != rootItem) |
|
1148 |
return createIndex(itm->parentItem->index, 0, itm->parentItem); |
|
1149 |
else |
|
1150 |
return QModelIndex(); |
|
1151 |
} |
|
1152 |
||
1153 |
Qt::ItemFlags QPPDOptionsModel::flags(const QModelIndex& index) const |
|
1154 |
{ |
|
1155 |
if (!index.isValid() || reinterpret_cast<QOptionTreeItem*>(index.internalPointer())->type == QOptionTreeItem::Group) |
|
1156 |
return Qt::ItemIsEnabled; |
|
1157 |
||
1158 |
if (index.column() == 1) |
|
1159 |
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; |
|
1160 |
||
1161 |
return Qt::ItemIsEnabled | Qt::ItemIsSelectable; |
|
1162 |
} |
|
1163 |
||
1164 |
void QPPDOptionsModel::parseItems() |
|
1165 |
{ |
|
1166 |
emit layoutAboutToBeChanged(); |
|
1167 |
ppd = cups->currentPPD(); |
|
1168 |
delete rootItem; |
|
1169 |
rootItem = new QOptionTreeItem(QOptionTreeItem::Root, 0, ppd, "Root Item", 0); |
|
1170 |
parseGroups(rootItem); |
|
1171 |
emit layoutChanged(); |
|
1172 |
} |
|
1173 |
||
1174 |
void QPPDOptionsModel::parseGroups(QOptionTreeItem* parent) |
|
1175 |
{ |
|
1176 |
if (parent->type == QOptionTreeItem::Root) { |
|
1177 |
||
1178 |
const ppd_file_t* ppdFile = reinterpret_cast<const ppd_file_t*>(parent->ptr); |
|
1179 |
||
1180 |
if (ppdFile) { |
|
1181 |
for (int i = 0; i < ppdFile->num_groups; ++i) { |
|
1182 |
QOptionTreeItem* group = new QOptionTreeItem(QOptionTreeItem::Group, i, &ppdFile->groups[i], ppdFile->groups[i].text, parent); |
|
1183 |
parent->childItems.append(group); |
|
1184 |
parseGroups(group); // parse possible subgroups |
|
1185 |
parseOptions(group); // parse options |
|
1186 |
} |
|
1187 |
} |
|
1188 |
} else if (parent->type == QOptionTreeItem::Group) { |
|
1189 |
||
1190 |
const ppd_group_t* group = reinterpret_cast<const ppd_group_t*>(parent->ptr); |
|
1191 |
||
1192 |
if (group) { |
|
1193 |
for (int i = 0; i < group->num_subgroups; ++i) { |
|
1194 |
QOptionTreeItem* subgroup = new QOptionTreeItem(QOptionTreeItem::Group, i, &group->subgroups[i], group->subgroups[i].text, parent); |
|
1195 |
parent->childItems.append(subgroup); |
|
1196 |
parseGroups(subgroup); // parse possible subgroups |
|
1197 |
parseOptions(subgroup); // parse options |
|
1198 |
} |
|
1199 |
} |
|
1200 |
} |
|
1201 |
} |
|
1202 |
||
1203 |
void QPPDOptionsModel::parseOptions(QOptionTreeItem* parent) |
|
1204 |
{ |
|
1205 |
const ppd_group_t* group = reinterpret_cast<const ppd_group_t*>(parent->ptr); |
|
1206 |
for (int i = 0; i < group->num_options; ++i) { |
|
1207 |
QOptionTreeItem* opt = new QOptionTreeItem(QOptionTreeItem::Option, i, &group->options[i], group->options[i].text, parent); |
|
1208 |
parent->childItems.append(opt); |
|
1209 |
parseChoices(opt); |
|
1210 |
} |
|
1211 |
} |
|
1212 |
||
1213 |
void QPPDOptionsModel::parseChoices(QOptionTreeItem* parent) |
|
1214 |
{ |
|
1215 |
const ppd_option_t* option = reinterpret_cast<const ppd_option_t*>(parent->ptr); |
|
1216 |
bool marked = false; |
|
1217 |
for (int i = 0; i < option->num_choices; ++i) { |
|
1218 |
QOptionTreeItem* choice = new QOptionTreeItem(QOptionTreeItem::Choice, i, &option->choices[i], option->choices[i].text, parent); |
|
1219 |
if (static_cast<int>(option->choices[i].marked) == 1) { |
|
1220 |
parent->selected = i; |
|
1221 |
parent->selDescription = option->choices[i].text; |
|
1222 |
marked = true; |
|
1223 |
} else if (!marked && qstrcmp(option->choices[i].choice, option->defchoice) == 0) { |
|
1224 |
parent->selected = i; |
|
1225 |
parent->selDescription = option->choices[i].text; |
|
1226 |
} |
|
1227 |
parent->childItems.append(choice); |
|
1228 |
} |
|
1229 |
} |
|
1230 |
||
1231 |
QVariant QPPDOptionsModel::headerData(int section, Qt::Orientation, int role) const |
|
1232 |
{ |
|
1233 |
if (role != Qt::DisplayRole) |
|
1234 |
return QVariant(); |
|
1235 |
||
1236 |
switch(section){ |
|
1237 |
case 0: |
|
1238 |
return QVariant(QApplication::translate("QPPDOptionsModel", "Name")); |
|
1239 |
case 1: |
|
1240 |
return QVariant(QApplication::translate("QPPDOptionsModel", "Value")); |
|
1241 |
default: |
|
1242 |
return QVariant(); |
|
1243 |
} |
|
1244 |
} |
|
1245 |
||
1246 |
//////////////////////////////////////////////////////////////////////////////// |
|
1247 |
||
1248 |
QWidget* QPPDOptionsEditor::createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex& index) const |
|
1249 |
{ |
|
1250 |
if (index.column() == 1 && reinterpret_cast<QOptionTreeItem*>(index.internalPointer())->type == QOptionTreeItem::Option) |
|
1251 |
return new QComboBox(parent); |
|
1252 |
else |
|
1253 |
return 0; |
|
1254 |
} |
|
1255 |
||
1256 |
void QPPDOptionsEditor::setEditorData(QWidget* editor, const QModelIndex& index) const |
|
1257 |
{ |
|
1258 |
if (index.column() != 1) |
|
1259 |
return; |
|
1260 |
||
1261 |
QComboBox* cb = static_cast<QComboBox*>(editor); |
|
1262 |
QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer()); |
|
1263 |
||
1264 |
if (itm->selected == -1) |
|
1265 |
cb->addItem(QString()); |
|
1266 |
||
1267 |
for (int i = 0; i < itm->childItems.count(); ++i) |
|
1268 |
cb->addItem(QString::fromLocal8Bit(itm->childItems.at(i)->description)); |
|
1269 |
||
1270 |
if (itm->selected > -1) |
|
1271 |
cb->setCurrentIndex(itm->selected); |
|
1272 |
||
1273 |
connect(cb, SIGNAL(currentIndexChanged(int)), this, SLOT(cbChanged(int))); |
|
1274 |
} |
|
1275 |
||
1276 |
void QPPDOptionsEditor::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const |
|
1277 |
{ |
|
1278 |
QComboBox* cb = static_cast<QComboBox*>(editor); |
|
1279 |
QOptionTreeItem* itm = reinterpret_cast<QOptionTreeItem*>(index.internalPointer()); |
|
1280 |
||
1281 |
if (itm->selected == cb->currentIndex()) |
|
1282 |
return; |
|
1283 |
||
1284 |
const ppd_option_t* opt = reinterpret_cast<const ppd_option_t*>(itm->ptr); |
|
1285 |
QPPDOptionsModel* m = static_cast<QPPDOptionsModel*>(model); |
|
1286 |
||
1287 |
if (m->cups->markOption(opt->keyword, opt->choices[cb->currentIndex()].choice) == 0) { |
|
1288 |
itm->selected = cb->currentIndex(); |
|
1289 |
itm->selDescription = reinterpret_cast<const ppd_option_t*>(itm->ptr)->choices[itm->selected].text; |
|
1290 |
} |
|
1291 |
} |
|
1292 |
||
1293 |
void QPPDOptionsEditor::cbChanged(int) |
|
1294 |
{ |
|
1295 |
/* |
|
1296 |
emit commitData(static_cast<QWidget*>(sender())); |
|
1297 |
*/ |
|
1298 |
} |
|
1299 |
||
1300 |
#endif |
|
1301 |
||
1302 |
QT_END_NAMESPACE |
|
1303 |
||
1304 |
#include "moc_qprintdialog.cpp" |
|
1305 |
#include "qprintdialog_unix.moc" |
|
1306 |
#include "qrc_qprintdialog.cpp" |
|
1307 |
||
1308 |
#endif // QT_NO_PRINTDIALOG |
|
1309 |