Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/printsupport/dialogs/qprintdialog_unix.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
24 | ** | - | ||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
35 | ** | - | ||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||
37 | ** | - | ||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||
39 | - | |||||||||||||
40 | #include "qplatformdefs.h" | - | ||||||||||||
41 | - | |||||||||||||
42 | #ifndef QT_NO_PRINTDIALOG | - | ||||||||||||
43 | - | |||||||||||||
44 | #include "private/qabstractprintdialog_p.h" | - | ||||||||||||
45 | #include <QtWidgets/qmessagebox.h> | - | ||||||||||||
46 | #include "qprintdialog.h" | - | ||||||||||||
47 | #include "qfiledialog.h" | - | ||||||||||||
48 | #include <QtCore/qdir.h> | - | ||||||||||||
49 | #include <QtGui/qevent.h> | - | ||||||||||||
50 | #include <QtWidgets/qfilesystemmodel.h> | - | ||||||||||||
51 | #include <QtWidgets/qstyleditemdelegate.h> | - | ||||||||||||
52 | #include <QtPrintSupport/qprinter.h> | - | ||||||||||||
53 | - | |||||||||||||
54 | #include <qpa/qplatformprintplugin.h> | - | ||||||||||||
55 | #include <qpa/qplatformprintersupport.h> | - | ||||||||||||
56 | - | |||||||||||||
57 | #include <private/qprintdevice_p.h> | - | ||||||||||||
58 | - | |||||||||||||
59 | #include <QtWidgets/qdialogbuttonbox.h> | - | ||||||||||||
60 | - | |||||||||||||
61 | #include "private/qfscompleter_p.h" | - | ||||||||||||
62 | #include "ui_qprintpropertieswidget.h" | - | ||||||||||||
63 | #include "ui_qprintsettingsoutput.h" | - | ||||||||||||
64 | #include "ui_qprintwidget.h" | - | ||||||||||||
65 | - | |||||||||||||
66 | #ifndef QT_NO_CUPS | - | ||||||||||||
67 | #include <private/qcups_p.h> | - | ||||||||||||
68 | #include "qcupsjobwidget_p.h" | - | ||||||||||||
69 | #endif | - | ||||||||||||
70 | - | |||||||||||||
71 | /* | - | ||||||||||||
72 | - | |||||||||||||
73 | Print dialog class declarations | - | ||||||||||||
74 | - | |||||||||||||
75 | QPrintDialog: The main Print Dialog, nothing really held here. | - | ||||||||||||
76 | - | |||||||||||||
77 | QUnixPrintWidget: | - | ||||||||||||
78 | QUnixPrintWidgetPrivate: The real Unix Print Dialog implementation. | - | ||||||||||||
79 | - | |||||||||||||
80 | Directly includes the upper half of the Print Dialog | - | ||||||||||||
81 | containing the Printer Selection widgets and | - | ||||||||||||
82 | Properties button. | - | ||||||||||||
83 | - | |||||||||||||
84 | Embeds the Properties pop-up dialog from | - | ||||||||||||
85 | QPrintPropertiesDialog | - | ||||||||||||
86 | - | |||||||||||||
87 | Embeds the lower half from separate widget class | - | ||||||||||||
88 | QPrintDialogPrivate | - | ||||||||||||
89 | - | |||||||||||||
90 | Layout in qprintwidget.ui | - | ||||||||||||
91 | - | |||||||||||||
92 | QPrintDialogPrivate: The lower half of the Print Dialog containing the | - | ||||||||||||
93 | Copies and Options tabs that expands when the | - | ||||||||||||
94 | Options button is selected. | - | ||||||||||||
95 | - | |||||||||||||
96 | Layout in qprintsettingsoutput.ui | - | ||||||||||||
97 | - | |||||||||||||
98 | QPrintPropertiesDialog: Dialog displayed when clicking on Properties button to | - | ||||||||||||
99 | allow editing of Page and Advanced tabs. | - | ||||||||||||
100 | - | |||||||||||||
101 | Layout in qprintpropertieswidget.ui | - | ||||||||||||
102 | */ | - | ||||||||||||
103 | - | |||||||||||||
104 | static void initResources() | - | ||||||||||||
105 | { | - | ||||||||||||
106 | Q_INIT_RESOURCE(qprintdialog); | - | ||||||||||||
107 | } | - | ||||||||||||
108 | - | |||||||||||||
109 | QT_BEGIN_NAMESPACE | - | ||||||||||||
110 | - | |||||||||||||
111 | class QOptionTreeItem; | - | ||||||||||||
112 | class QPPDOptionsModel; | - | ||||||||||||
113 | - | |||||||||||||
114 | class QPrintPropertiesDialog : public QDialog | - | ||||||||||||
115 | { | - | ||||||||||||
116 | Q_OBJECT | - | ||||||||||||
117 | public: | - | ||||||||||||
118 | QPrintPropertiesDialog(QAbstractPrintDialog *parent = 0); | - | ||||||||||||
119 | ~QPrintPropertiesDialog(); | - | ||||||||||||
120 | - | |||||||||||||
121 | void selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName); | - | ||||||||||||
122 | - | |||||||||||||
123 | /// copy printer properties to the widget | - | ||||||||||||
124 | void applyPrinterProperties(QPrinter *p); | - | ||||||||||||
125 | void setupPrinter() const; | - | ||||||||||||
126 | - | |||||||||||||
127 | private: | - | ||||||||||||
128 | friend class QUnixPrintWidgetPrivate; | - | ||||||||||||
129 | Ui::QPrintPropertiesWidget widget; | - | ||||||||||||
130 | QDialogButtonBox *m_buttons; | - | ||||||||||||
131 | #ifndef QT_NO_CUPS | - | ||||||||||||
132 | QCupsJobWidget *m_jobOptions; | - | ||||||||||||
133 | #endif | - | ||||||||||||
134 | }; | - | ||||||||||||
135 | - | |||||||||||||
136 | class QUnixPrintWidgetPrivate; | - | ||||||||||||
137 | - | |||||||||||||
138 | class QUnixPrintWidget : public QWidget | - | ||||||||||||
139 | { | - | ||||||||||||
140 | Q_OBJECT | - | ||||||||||||
141 | - | |||||||||||||
142 | public: | - | ||||||||||||
143 | explicit QUnixPrintWidget(QPrinter *printer, QWidget *parent = 0); | - | ||||||||||||
144 | ~QUnixPrintWidget(); | - | ||||||||||||
145 | void updatePrinter(); | - | ||||||||||||
146 | - | |||||||||||||
147 | private: | - | ||||||||||||
148 | friend class QPrintDialogPrivate; | - | ||||||||||||
149 | friend class QUnixPrintWidgetPrivate; | - | ||||||||||||
150 | QUnixPrintWidgetPrivate *d; | - | ||||||||||||
151 | Q_PRIVATE_SLOT(d, void _q_printerChanged(int)) | - | ||||||||||||
152 | Q_PRIVATE_SLOT(d, void _q_btnBrowseClicked()) | - | ||||||||||||
153 | Q_PRIVATE_SLOT(d, void _q_btnPropertiesClicked()) | - | ||||||||||||
154 | }; | - | ||||||||||||
155 | - | |||||||||||||
156 | class QUnixPrintWidgetPrivate | - | ||||||||||||
157 | { | - | ||||||||||||
158 | public: | - | ||||||||||||
159 | QUnixPrintWidgetPrivate(QUnixPrintWidget *q, QPrinter *prn); | - | ||||||||||||
160 | ~QUnixPrintWidgetPrivate(); | - | ||||||||||||
161 | - | |||||||||||||
162 | /// copy printer properties to the widget | - | ||||||||||||
163 | void applyPrinterProperties(); | - | ||||||||||||
164 | bool checkFields(); | - | ||||||||||||
165 | void setupPrinter(); | - | ||||||||||||
166 | void setOptionsPane(QPrintDialogPrivate *pane); | - | ||||||||||||
167 | void setupPrinterProperties(); | - | ||||||||||||
168 | // slots | - | ||||||||||||
169 | void _q_printerChanged(int index); | - | ||||||||||||
170 | void _q_btnPropertiesClicked(); | - | ||||||||||||
171 | void _q_btnBrowseClicked(); | - | ||||||||||||
172 | - | |||||||||||||
173 | QUnixPrintWidget * const parent; | - | ||||||||||||
174 | QPrintPropertiesDialog *propertiesDialog; | - | ||||||||||||
175 | Ui::QPrintWidget widget; | - | ||||||||||||
176 | QAbstractPrintDialog * q; | - | ||||||||||||
177 | QPrinter *printer; | - | ||||||||||||
178 | QPrintDevice m_currentPrintDevice; | - | ||||||||||||
179 | - | |||||||||||||
180 | void updateWidget(); | - | ||||||||||||
181 | - | |||||||||||||
182 | private: | - | ||||||||||||
183 | QPrintDialogPrivate *optionsPane; | - | ||||||||||||
184 | bool filePrintersAdded; | - | ||||||||||||
185 | bool propertiesDialogShown; | - | ||||||||||||
186 | }; | - | ||||||||||||
187 | - | |||||||||||||
188 | class QPrintDialogPrivate : public QAbstractPrintDialogPrivate | - | ||||||||||||
189 | { | - | ||||||||||||
190 | Q_DECLARE_PUBLIC(QPrintDialog) | - | ||||||||||||
191 | Q_DECLARE_TR_FUNCTIONS(QPrintDialog) | - | ||||||||||||
192 | public: | - | ||||||||||||
193 | QPrintDialogPrivate(); | - | ||||||||||||
194 | ~QPrintDialogPrivate(); | - | ||||||||||||
195 | - | |||||||||||||
196 | void init(); | - | ||||||||||||
197 | /// copy printer properties to the widget | - | ||||||||||||
198 | void applyPrinterProperties(); | - | ||||||||||||
199 | - | |||||||||||||
200 | void selectPrinter(const QPrinter::OutputFormat outputFormat); | - | ||||||||||||
201 | - | |||||||||||||
202 | void _q_togglePageSetCombo(bool); | - | ||||||||||||
203 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||
204 | void _q_checkFields(); | - | ||||||||||||
205 | #endif | - | ||||||||||||
206 | void _q_collapseOrExpandDialog(); | - | ||||||||||||
207 | - | |||||||||||||
208 | void setupPrinter(); | - | ||||||||||||
209 | void updateWidgets(); | - | ||||||||||||
210 | - | |||||||||||||
211 | virtual void setTabs(const QList<QWidget*> &tabs) Q_DECL_OVERRIDE; | - | ||||||||||||
212 | - | |||||||||||||
213 | Ui::QPrintSettingsOutput options; | - | ||||||||||||
214 | QUnixPrintWidget *top; | - | ||||||||||||
215 | QWidget *bottom; | - | ||||||||||||
216 | QDialogButtonBox *buttons; | - | ||||||||||||
217 | QPushButton *collapseButton; | - | ||||||||||||
218 | QPrinter::OutputFormat printerOutputFormat; | - | ||||||||||||
219 | }; | - | ||||||||||||
220 | - | |||||||||||||
221 | - | |||||||||||||
222 | //////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
223 | //////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
224 | - | |||||||||||||
225 | /* | - | ||||||||||||
226 | - | |||||||||||||
227 | QPrintPropertiesDialog | - | ||||||||||||
228 | - | |||||||||||||
229 | Dialog displayed when clicking on Properties button to allow editing of Page | - | ||||||||||||
230 | and Advanced tabs. | - | ||||||||||||
231 | - | |||||||||||||
232 | */ | - | ||||||||||||
233 | - | |||||||||||||
234 | QPrintPropertiesDialog::QPrintPropertiesDialog(QAbstractPrintDialog *parent) | - | ||||||||||||
235 | : QDialog(parent) | - | ||||||||||||
236 | { | - | ||||||||||||
237 | setWindowTitle(tr("Printer Properties")); | - | ||||||||||||
238 | QVBoxLayout *lay = new QVBoxLayout(this); | - | ||||||||||||
239 | this->setLayout(lay); | - | ||||||||||||
240 | QWidget *content = new QWidget(this); | - | ||||||||||||
241 | widget.setupUi(content); | - | ||||||||||||
242 | m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); | - | ||||||||||||
243 | lay->addWidget(content); | - | ||||||||||||
244 | lay->addWidget(m_buttons); | - | ||||||||||||
245 | - | |||||||||||||
246 | connect(m_buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(accept())); | - | ||||||||||||
247 | connect(m_buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); | - | ||||||||||||
248 | - | |||||||||||||
249 | #ifndef QT_NO_CUPS | - | ||||||||||||
250 | m_jobOptions = new QCupsJobWidget(); | - | ||||||||||||
251 | widget.tabs->addTab(m_jobOptions, tr("Job Options")); | - | ||||||||||||
252 | #endif | - | ||||||||||||
253 | } | - | ||||||||||||
254 | - | |||||||||||||
255 | QPrintPropertiesDialog::~QPrintPropertiesDialog() | - | ||||||||||||
256 | { | - | ||||||||||||
257 | } | - | ||||||||||||
258 | - | |||||||||||||
259 | void QPrintPropertiesDialog::applyPrinterProperties(QPrinter *p) | - | ||||||||||||
260 | { | - | ||||||||||||
261 | widget.pageSetup->setPrinter(p); | - | ||||||||||||
262 | #ifndef QT_NO_CUPS | - | ||||||||||||
263 | m_jobOptions->setPrinter(p); | - | ||||||||||||
264 | #endif | - | ||||||||||||
265 | } | - | ||||||||||||
266 | - | |||||||||||||
267 | void QPrintPropertiesDialog::setupPrinter() const | - | ||||||||||||
268 | { | - | ||||||||||||
269 | widget.pageSetup->setupPrinter(); | - | ||||||||||||
270 | #ifndef QT_NO_CUPS | - | ||||||||||||
271 | m_jobOptions->setupPrinter(); | - | ||||||||||||
272 | #endif | - | ||||||||||||
273 | } | - | ||||||||||||
274 | - | |||||||||||||
275 | void QPrintPropertiesDialog::selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName) | - | ||||||||||||
276 | { | - | ||||||||||||
277 | widget.pageSetup->selectPrinter(outputFormat, printerName); | - | ||||||||||||
278 | } | - | ||||||||||||
279 | - | |||||||||||||
280 | //////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
281 | //////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
282 | - | |||||||||||||
283 | /* | - | ||||||||||||
284 | - | |||||||||||||
285 | QPrintDialogPrivate | - | ||||||||||||
286 | - | |||||||||||||
287 | The lower half of the Print Dialog containing the Copies and Options | - | ||||||||||||
288 | tabs that expands when the Options button is selected. | - | ||||||||||||
289 | - | |||||||||||||
290 | */ | - | ||||||||||||
291 | QPrintDialogPrivate::QPrintDialogPrivate() | - | ||||||||||||
292 | : top(0), bottom(0), buttons(0), collapseButton(0) | - | ||||||||||||
293 | { | - | ||||||||||||
294 | initResources(); | - | ||||||||||||
295 | } | - | ||||||||||||
296 | - | |||||||||||||
297 | QPrintDialogPrivate::~QPrintDialogPrivate() | - | ||||||||||||
298 | { | - | ||||||||||||
299 | } | - | ||||||||||||
300 | - | |||||||||||||
301 | void QPrintDialogPrivate::init() | - | ||||||||||||
302 | { | - | ||||||||||||
303 | Q_Q(QPrintDialog); | - | ||||||||||||
304 | - | |||||||||||||
305 | top = new QUnixPrintWidget(q->printer(), q); | - | ||||||||||||
306 | bottom = new QWidget(q); | - | ||||||||||||
307 | options.setupUi(bottom); | - | ||||||||||||
308 | options.color->setIconSize(QSize(32, 32)); | - | ||||||||||||
309 | options.color->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-color.png"))); | - | ||||||||||||
310 | options.grayscale->setIconSize(QSize(32, 32)); | - | ||||||||||||
311 | options.grayscale->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-gray-scale.png"))); | - | ||||||||||||
312 | - | |||||||||||||
313 | #ifndef QT_NO_CUPS | - | ||||||||||||
314 | // Add Page Set widget if CUPS is available | - | ||||||||||||
315 | options.pageSetCombo->addItem(tr("All Pages"), QVariant::fromValue(QCUPSSupport::AllPages)); | - | ||||||||||||
316 | options.pageSetCombo->addItem(tr("Odd Pages"), QVariant::fromValue(QCUPSSupport::OddPages)); | - | ||||||||||||
317 | options.pageSetCombo->addItem(tr("Even Pages"), QVariant::fromValue(QCUPSSupport::EvenPages)); | - | ||||||||||||
318 | #endif | - | ||||||||||||
319 | - | |||||||||||||
320 | top->d->setOptionsPane(this); | - | ||||||||||||
321 | - | |||||||||||||
322 | buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q); | - | ||||||||||||
323 | collapseButton = new QPushButton(QPrintDialog::tr("&Options >>"), buttons); | - | ||||||||||||
324 | buttons->addButton(collapseButton, QDialogButtonBox::ResetRole); | - | ||||||||||||
325 | bottom->setVisible(false); | - | ||||||||||||
326 | - | |||||||||||||
327 | QPushButton *printButton = buttons->button(QDialogButtonBox::Ok); | - | ||||||||||||
328 | printButton->setText(QPrintDialog::tr("&Print")); | - | ||||||||||||
329 | printButton->setDefault(true); | - | ||||||||||||
330 | - | |||||||||||||
331 | QVBoxLayout *lay = new QVBoxLayout(q); | - | ||||||||||||
332 | q->setLayout(lay); | - | ||||||||||||
333 | lay->addWidget(top); | - | ||||||||||||
334 | lay->addWidget(bottom); | - | ||||||||||||
335 | lay->addWidget(buttons); | - | ||||||||||||
336 | - | |||||||||||||
337 | #ifdef QT_NO_MESSAGEBOX | - | ||||||||||||
338 | QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(accept())); | - | ||||||||||||
339 | #else | - | ||||||||||||
340 | QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(_q_checkFields())); | - | ||||||||||||
341 | #endif | - | ||||||||||||
342 | QObject::connect(buttons, SIGNAL(rejected()), q, SLOT(reject())); | - | ||||||||||||
343 | - | |||||||||||||
344 | QObject::connect(options.printSelection, SIGNAL(toggled(bool)), | - | ||||||||||||
345 | q, SLOT(_q_togglePageSetCombo(bool))); | - | ||||||||||||
346 | - | |||||||||||||
347 | QObject::connect(options.printCurrentPage, SIGNAL(toggled(bool)), | - | ||||||||||||
348 | q, SLOT(_q_togglePageSetCombo(bool))); | - | ||||||||||||
349 | - | |||||||||||||
350 | QObject::connect(collapseButton, SIGNAL(released()), q, SLOT(_q_collapseOrExpandDialog())); | - | ||||||||||||
351 | } | - | ||||||||||||
352 | - | |||||||||||||
353 | // initialize printer options | - | ||||||||||||
354 | void QPrintDialogPrivate::selectPrinter(const QPrinter::OutputFormat outputFormat) | - | ||||||||||||
355 | { | - | ||||||||||||
356 | Q_Q(QPrintDialog); | - | ||||||||||||
357 | QPrinter *p = q->printer(); | - | ||||||||||||
358 | printerOutputFormat = outputFormat; | - | ||||||||||||
359 | - | |||||||||||||
360 | if (p->colorMode() == QPrinter::Color) | - | ||||||||||||
361 | options.color->setChecked(true); | - | ||||||||||||
362 | else | - | ||||||||||||
363 | options.grayscale->setChecked(true); | - | ||||||||||||
364 | - | |||||||||||||
365 | switch (p->duplex()) { | - | ||||||||||||
366 | case QPrinter::DuplexNone: | - | ||||||||||||
367 | options.noDuplex->setChecked(true); break; | - | ||||||||||||
368 | case QPrinter::DuplexLongSide: | - | ||||||||||||
369 | case QPrinter::DuplexAuto: | - | ||||||||||||
370 | options.duplexLong->setChecked(true); break; | - | ||||||||||||
371 | case QPrinter::DuplexShortSide: | - | ||||||||||||
372 | options.duplexShort->setChecked(true); break; | - | ||||||||||||
373 | } | - | ||||||||||||
374 | options.copies->setValue(p->copyCount()); | - | ||||||||||||
375 | options.collate->setChecked(p->collateCopies()); | - | ||||||||||||
376 | options.reverse->setChecked(p->pageOrder() == QPrinter::LastPageFirst); | - | ||||||||||||
377 | - | |||||||||||||
378 | if (outputFormat == QPrinter::PdfFormat || options.printSelection->isChecked() | - | ||||||||||||
379 | || options.printCurrentPage->isChecked()) | - | ||||||||||||
380 | - | |||||||||||||
381 | options.pageSetCombo->setEnabled(false); | - | ||||||||||||
382 | else | - | ||||||||||||
383 | options.pageSetCombo->setEnabled(true); | - | ||||||||||||
384 | } | - | ||||||||||||
385 | - | |||||||||||||
386 | void QPrintDialogPrivate::applyPrinterProperties() | - | ||||||||||||
387 | { | - | ||||||||||||
388 | // apply printer options to property dialog | - | ||||||||||||
389 | top->d->applyPrinterProperties(); | - | ||||||||||||
390 | } | - | ||||||||||||
391 | - | |||||||||||||
392 | void QPrintDialogPrivate::setupPrinter() | - | ||||||||||||
393 | { | - | ||||||||||||
394 | // First setup the requested OutputFormat, Printer and Page Size first | - | ||||||||||||
395 | top->d->setupPrinter(); | - | ||||||||||||
396 | - | |||||||||||||
397 | // Then setup Print Job options | - | ||||||||||||
398 | Q_Q(QPrintDialog); | - | ||||||||||||
399 | QPrinter* p = q->printer(); | - | ||||||||||||
400 | - | |||||||||||||
401 | if (options.duplex->isEnabled()) { | - | ||||||||||||
402 | if (options.noDuplex->isChecked()) | - | ||||||||||||
403 | p->setDuplex(QPrinter::DuplexNone); | - | ||||||||||||
404 | else if (options.duplexLong->isChecked()) | - | ||||||||||||
405 | p->setDuplex(QPrinter::DuplexLongSide); | - | ||||||||||||
406 | else | - | ||||||||||||
407 | p->setDuplex(QPrinter::DuplexShortSide); | - | ||||||||||||
408 | } | - | ||||||||||||
409 | - | |||||||||||||
410 | p->setColorMode(options.color->isChecked() ? QPrinter::Color : QPrinter::GrayScale); | - | ||||||||||||
411 | p->setPageOrder(options.reverse->isChecked() ? QPrinter::LastPageFirst : QPrinter::FirstPageFirst); | - | ||||||||||||
412 | - | |||||||||||||
413 | // print range | - | ||||||||||||
414 | if (options.printAll->isChecked()) { | - | ||||||||||||
415 | p->setPrintRange(QPrinter::AllPages); | - | ||||||||||||
416 | p->setFromTo(0,0); | - | ||||||||||||
417 | } else if (options.printSelection->isChecked()) { | - | ||||||||||||
418 | p->setPrintRange(QPrinter::Selection); | - | ||||||||||||
419 | p->setFromTo(0,0); | - | ||||||||||||
420 | } else if (options.printCurrentPage->isChecked()) { | - | ||||||||||||
421 | p->setPrintRange(QPrinter::CurrentPage); | - | ||||||||||||
422 | p->setFromTo(0,0); | - | ||||||||||||
423 | } else if (options.printRange->isChecked()) { | - | ||||||||||||
424 | if (q->isOptionEnabled(QPrintDialog::PrintPageRange)) { | - | ||||||||||||
425 | p->setPrintRange(QPrinter::PageRange); | - | ||||||||||||
426 | p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value())); | - | ||||||||||||
427 | } else { | - | ||||||||||||
428 | // This case happens when CUPS server-side page range is enabled | - | ||||||||||||
429 | // Setting the range to the printer occurs below | - | ||||||||||||
430 | p->setPrintRange(QPrinter::AllPages); | - | ||||||||||||
431 | p->setFromTo(0,0); | - | ||||||||||||
432 | } | - | ||||||||||||
433 | } | - | ||||||||||||
434 | - | |||||||||||||
435 | #ifndef QT_NO_CUPS | - | ||||||||||||
436 | // page set | - | ||||||||||||
437 | if (p->printRange() == QPrinter::AllPages || p->printRange() == QPrinter::PageRange) { | - | ||||||||||||
438 | //If the application is selecting pages and the first page number is even then need to adjust the odd-even accordingly | - | ||||||||||||
439 | QCUPSSupport::PageSet pageSet = options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()).value<QCUPSSupport::PageSet>(); | - | ||||||||||||
440 | if (q->isOptionEnabled(QPrintDialog::PrintPageRange) | - | ||||||||||||
441 | && p->printRange() == QPrinter::PageRange | - | ||||||||||||
442 | && (q->fromPage() % 2 == 0)) { | - | ||||||||||||
443 | - | |||||||||||||
444 | switch (pageSet) { | - | ||||||||||||
445 | case QCUPSSupport::AllPages: | - | ||||||||||||
446 | break; | - | ||||||||||||
447 | case QCUPSSupport::OddPages: | - | ||||||||||||
448 | QCUPSSupport::setPageSet(p, QCUPSSupport::EvenPages); | - | ||||||||||||
449 | break; | - | ||||||||||||
450 | case QCUPSSupport::EvenPages: | - | ||||||||||||
451 | QCUPSSupport::setPageSet(p, QCUPSSupport::OddPages); | - | ||||||||||||
452 | break; | - | ||||||||||||
453 | } | - | ||||||||||||
454 | } else if (pageSet != QCUPSSupport::AllPages) { | - | ||||||||||||
455 | QCUPSSupport::setPageSet(p, pageSet); | - | ||||||||||||
456 | } | - | ||||||||||||
457 | - | |||||||||||||
458 | // server-side page range, since we set the page range on the printer to 0-0/AllPages above, | - | ||||||||||||
459 | // we need to take the values directly from the widget as q->fromPage() will return 0 | - | ||||||||||||
460 | if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) && options.printRange->isChecked()) | - | ||||||||||||
461 | QCUPSSupport::setPageRange(p, options.from->value(), qMax(options.from->value(), options.to->value())); | - | ||||||||||||
462 | } | - | ||||||||||||
463 | #endif | - | ||||||||||||
464 | - | |||||||||||||
465 | // copies | - | ||||||||||||
466 | p->setCopyCount(options.copies->value()); | - | ||||||||||||
467 | p->setCollateCopies(options.collate->isChecked()); | - | ||||||||||||
468 | } | - | ||||||||||||
469 | - | |||||||||||||
470 | void QPrintDialogPrivate::_q_togglePageSetCombo(bool checked) | - | ||||||||||||
471 | { | - | ||||||||||||
472 | if (printerOutputFormat == QPrinter::PdfFormat) | - | ||||||||||||
473 | return; | - | ||||||||||||
474 | - | |||||||||||||
475 | options.pageSetCombo->setDisabled(checked); | - | ||||||||||||
476 | } | - | ||||||||||||
477 | - | |||||||||||||
478 | void QPrintDialogPrivate::_q_collapseOrExpandDialog() | - | ||||||||||||
479 | { | - | ||||||||||||
480 | int collapseHeight = 0; | - | ||||||||||||
481 | Q_Q(QPrintDialog); | - | ||||||||||||
482 | QWidget *widgetToHide = bottom; | - | ||||||||||||
483 | if (widgetToHide->isVisible()) { | - | ||||||||||||
484 | collapseButton->setText(QPrintDialog::tr("&Options >>")); | - | ||||||||||||
485 | collapseHeight = widgetToHide->y() + widgetToHide->height() - (top->y() + top->height()); | - | ||||||||||||
486 | } | - | ||||||||||||
487 | else | - | ||||||||||||
488 | collapseButton->setText(QPrintDialog::tr("&Options <<")); | - | ||||||||||||
489 | widgetToHide->setVisible(! widgetToHide->isVisible()); | - | ||||||||||||
490 | if (! widgetToHide->isVisible()) { // make it shrink | - | ||||||||||||
491 | q->layout()->activate(); | - | ||||||||||||
492 | q->resize( QSize(q->width(), q->height() - collapseHeight) ); | - | ||||||||||||
493 | } | - | ||||||||||||
494 | } | - | ||||||||||||
495 | - | |||||||||||||
496 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||
497 | void QPrintDialogPrivate::_q_checkFields() | - | ||||||||||||
498 | { | - | ||||||||||||
499 | Q_Q(QPrintDialog); | - | ||||||||||||
500 | if (top->d->checkFields()) | - | ||||||||||||
501 | q->accept(); | - | ||||||||||||
502 | } | - | ||||||||||||
503 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||
504 | - | |||||||||||||
505 | - | |||||||||||||
506 | void QPrintDialogPrivate::updateWidgets() | - | ||||||||||||
507 | { | - | ||||||||||||
508 | Q_Q(QPrintDialog); | - | ||||||||||||
509 | options.gbPrintRange->setVisible(q->isOptionEnabled(QPrintDialog::PrintPageRange) || | - | ||||||||||||
510 | q->isOptionEnabled(QPrintDialog::PrintSelection) || | - | ||||||||||||
511 | q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); | - | ||||||||||||
512 | - | |||||||||||||
513 | options.printRange->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange)); | - | ||||||||||||
514 | options.printSelection->setVisible(q->isOptionEnabled(QPrintDialog::PrintSelection)); | - | ||||||||||||
515 | options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); | - | ||||||||||||
516 | options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies)); | - | ||||||||||||
517 | - | |||||||||||||
518 | #ifndef QT_NO_CUPS | - | ||||||||||||
519 | // Don't display Page Set if only Selection or Current Page are enabled | - | ||||||||||||
520 | if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) | - | ||||||||||||
521 | && (q->isOptionEnabled(QPrintDialog::PrintSelection) || q->isOptionEnabled(QPrintDialog::PrintCurrentPage))) { | - | ||||||||||||
522 | options.pageSetCombo->setVisible(false); | - | ||||||||||||
523 | options.pageSetLabel->setVisible(false); | - | ||||||||||||
524 | } else { | - | ||||||||||||
525 | options.pageSetCombo->setVisible(true); | - | ||||||||||||
526 | options.pageSetLabel->setVisible(true); | - | ||||||||||||
527 | } | - | ||||||||||||
528 | - | |||||||||||||
529 | if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)) { | - | ||||||||||||
530 | // If we can do CUPS server side pages selection, | - | ||||||||||||
531 | // display the page range widgets | - | ||||||||||||
532 | options.gbPrintRange->setVisible(true); | - | ||||||||||||
533 | options.printRange->setEnabled(true); | - | ||||||||||||
534 | } | - | ||||||||||||
535 | #endif | - | ||||||||||||
536 | - | |||||||||||||
537 | switch (q->printRange()) { | - | ||||||||||||
538 | case QPrintDialog::AllPages: | - | ||||||||||||
539 | options.printAll->setChecked(true); | - | ||||||||||||
540 | options.pageSetCombo->setEnabled(true); | - | ||||||||||||
541 | break; | - | ||||||||||||
542 | case QPrintDialog::Selection: | - | ||||||||||||
543 | options.printSelection->setChecked(true); | - | ||||||||||||
544 | options.pageSetCombo->setEnabled(false); | - | ||||||||||||
545 | break; | - | ||||||||||||
546 | case QPrintDialog::PageRange: | - | ||||||||||||
547 | options.printRange->setChecked(true); | - | ||||||||||||
548 | options.pageSetCombo->setEnabled(true); | - | ||||||||||||
549 | break; | - | ||||||||||||
550 | case QPrintDialog::CurrentPage: | - | ||||||||||||
551 | if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage)) { | - | ||||||||||||
552 | options.printCurrentPage->setChecked(true); | - | ||||||||||||
553 | options.pageSetCombo->setEnabled(false); | - | ||||||||||||
554 | } | - | ||||||||||||
555 | break; | - | ||||||||||||
556 | default: | - | ||||||||||||
557 | break; | - | ||||||||||||
558 | } | - | ||||||||||||
559 | const int minPage = qMax(1, qMin(q->minPage() , q->maxPage())); | - | ||||||||||||
560 | const int maxPage = qMax(1, q->maxPage() == INT_MAX ? 9999 : q->maxPage()); | - | ||||||||||||
561 | - | |||||||||||||
562 | options.from->setMinimum(minPage); | - | ||||||||||||
563 | options.to->setMinimum(minPage); | - | ||||||||||||
564 | options.from->setMaximum(maxPage); | - | ||||||||||||
565 | options.to->setMaximum(maxPage); | - | ||||||||||||
566 | - | |||||||||||||
567 | options.from->setValue(q->fromPage()); | - | ||||||||||||
568 | options.to->setValue(q->toPage()); | - | ||||||||||||
569 | top->d->updateWidget(); | - | ||||||||||||
570 | } | - | ||||||||||||
571 | - | |||||||||||||
572 | void QPrintDialogPrivate::setTabs(const QList<QWidget*> &tabWidgets) | - | ||||||||||||
573 | { | - | ||||||||||||
574 | QList<QWidget*>::ConstIterator iter = tabWidgets.begin(); | - | ||||||||||||
575 | while(iter != tabWidgets.constEnd()) { | - | ||||||||||||
576 | QWidget *tab = *iter; | - | ||||||||||||
577 | options.tabs->addTab(tab, tab->windowTitle()); | - | ||||||||||||
578 | ++iter; | - | ||||||||||||
579 | } | - | ||||||||||||
580 | } | - | ||||||||||||
581 | - | |||||||||||||
582 | //////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
583 | //////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
584 | - | |||||||||||||
585 | /* | - | ||||||||||||
586 | - | |||||||||||||
587 | QPrintDialog | - | ||||||||||||
588 | - | |||||||||||||
589 | The main Print Dialog. | - | ||||||||||||
590 | - | |||||||||||||
591 | */ | - | ||||||||||||
592 | - | |||||||||||||
593 | QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent) | - | ||||||||||||
594 | : QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent) | - | ||||||||||||
595 | { | - | ||||||||||||
596 | Q_D(QPrintDialog); | - | ||||||||||||
597 | d->init(); | - | ||||||||||||
598 | } | - | ||||||||||||
599 | - | |||||||||||||
600 | /*! | - | ||||||||||||
601 | Constructs a print dialog with the given \a parent. | - | ||||||||||||
602 | */ | - | ||||||||||||
603 | QPrintDialog::QPrintDialog(QWidget *parent) | - | ||||||||||||
604 | : QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent) | - | ||||||||||||
605 | { | - | ||||||||||||
606 | Q_D(QPrintDialog); | - | ||||||||||||
607 | d->init(); | - | ||||||||||||
608 | } | - | ||||||||||||
609 | - | |||||||||||||
610 | QPrintDialog::~QPrintDialog() | - | ||||||||||||
611 | { | - | ||||||||||||
612 | } | - | ||||||||||||
613 | - | |||||||||||||
614 | void QPrintDialog::setVisible(bool visible) | - | ||||||||||||
615 | { | - | ||||||||||||
616 | Q_D(QPrintDialog); | - | ||||||||||||
617 | - | |||||||||||||
618 | if (visible) | - | ||||||||||||
619 | d->updateWidgets(); | - | ||||||||||||
620 | - | |||||||||||||
621 | QAbstractPrintDialog::setVisible(visible); | - | ||||||||||||
622 | } | - | ||||||||||||
623 | - | |||||||||||||
624 | int QPrintDialog::exec() | - | ||||||||||||
625 | { | - | ||||||||||||
626 | return QDialog::exec(); | - | ||||||||||||
627 | } | - | ||||||||||||
628 | - | |||||||||||||
629 | void QPrintDialog::accept() | - | ||||||||||||
630 | { | - | ||||||||||||
631 | Q_D(QPrintDialog); | - | ||||||||||||
632 | d->setupPrinter(); | - | ||||||||||||
633 | QDialog::accept(); | - | ||||||||||||
634 | } | - | ||||||||||||
635 | - | |||||||||||||
636 | //////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
637 | //////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
638 | - | |||||||||||||
639 | /* | - | ||||||||||||
640 | - | |||||||||||||
641 | QUnixPrintWidget && QUnixPrintWidgetPrivate | - | ||||||||||||
642 | - | |||||||||||||
643 | The upper half of the Print Dialog containing the Printer Selection widgets | - | ||||||||||||
644 | - | |||||||||||||
645 | */ | - | ||||||||||||
646 | - | |||||||||||||
647 | #if defined (Q_OS_UNIX) | - | ||||||||||||
648 | - | |||||||||||||
649 | /*! \internal | - | ||||||||||||
650 | */ | - | ||||||||||||
651 | QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p, QPrinter *prn) | - | ||||||||||||
652 | : parent(p), propertiesDialog(0), printer(prn), optionsPane(0), | - | ||||||||||||
653 | filePrintersAdded(false), propertiesDialogShown(false) | - | ||||||||||||
654 | { | - | ||||||||||||
655 | q = 0; | - | ||||||||||||
656 | if (parent)
| 0-3 | ||||||||||||
657 | q = qobject_cast<QAbstractPrintDialog*> (parent->parent()); executed 3 times by 1 test: q = qobject_cast<QAbstractPrintDialog*> (parent->parent()); Executed by:
| 3 | ||||||||||||
658 | - | |||||||||||||
659 | widget.setupUi(parent); | - | ||||||||||||
660 | - | |||||||||||||
661 | int currentPrinterIndex = 0; | - | ||||||||||||
QStringList printers; | ||||||||||||||
QString defaultPrinter; | ||||||||||||||
662 | QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get(); | - | ||||||||||||
663 | if (ps) {
| 0-3 | ||||||||||||
664 | const QStringList printers = ps->availablePrintDeviceIds(); | - | ||||||||||||
665 | const QString defaultPrinter = ps->defaultPrintDeviceId(); | - | ||||||||||||
} | ||||||||||||||
for (int i = 0; i < printers.size(); | ||||||||||||||
666 | - | |||||||||||||
667 | ++i) {widget.printers->addItemaddItems(printers.at(i)); | - | ||||||||||||
if (); | ||||||||||||||
668 | - | |||||||||||||
669 | const int idx = printers.atindexOf(i) ==defaultPrinter); | - | ||||||||||||
670 | if (idx >= 0
| 0-3 | ||||||||||||
671 | currentPrinterIndex = iidx; never executed: currentPrinterIndex = idx; | 0 | ||||||||||||
672 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
673 | widget.properties->setEnabled(true); | - | ||||||||||||
674 | - | |||||||||||||
675 | #if !defined(QT_NO_FILESYSTEMMODEL) && !defined(QT_NO_COMPLETER) | - | ||||||||||||
676 | QFileSystemModel *fsm = new QFileSystemModel(widget.filename); | - | ||||||||||||
677 | fsm->setRootPath(QDir::homePath()); | - | ||||||||||||
678 | widget.filename->setCompleter(new QCompleter(fsm, widget.filename)); | - | ||||||||||||
679 | #endif | - | ||||||||||||
680 | _q_printerChanged(currentPrinterIndex); | - | ||||||||||||
681 | - | |||||||||||||
682 | QObject::connect(widget.printers, SIGNAL(currentIndexChanged(int)), | - | ||||||||||||
683 | parent, SLOT(_q_printerChanged(int))); | - | ||||||||||||
684 | QObject::connect(widget.fileBrowser, SIGNAL(clicked()), parent, SLOT(_q_btnBrowseClicked())); | - | ||||||||||||
685 | QObject::connect(widget.properties, SIGNAL(clicked()), parent, SLOT(_q_btnPropertiesClicked())); | - | ||||||||||||
686 | - | |||||||||||||
687 | // disable features that QPrinter does not yet support. | - | ||||||||||||
688 | widget.preview->setVisible(false); | - | ||||||||||||
689 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
690 | - | |||||||||||||
691 | void QUnixPrintWidgetPrivate::updateWidget() | - | ||||||||||||
692 | { | - | ||||||||||||
693 | const bool printToFile = q == 0 || q->isOptionEnabled(QPrintDialog::PrintToFile); | - | ||||||||||||
694 | if (printToFile && !filePrintersAdded) { | - | ||||||||||||
695 | if (widget.printers->count()) | - | ||||||||||||
696 | widget.printers->insertSeparator(widget.printers->count()); | - | ||||||||||||
697 | widget.printers->addItem(QPrintDialog::tr("Print to File (PDF)")); | - | ||||||||||||
698 | filePrintersAdded = true; | - | ||||||||||||
699 | } | - | ||||||||||||
700 | if (!printToFile && filePrintersAdded) { | - | ||||||||||||
701 | widget.printers->removeItem(widget.printers->count()-1); | - | ||||||||||||
702 | widget.printers->removeItem(widget.printers->count()-1); | - | ||||||||||||
703 | if (widget.printers->count()) | - | ||||||||||||
704 | widget.printers->removeItem(widget.printers->count()-1); // remove separator | - | ||||||||||||
705 | filePrintersAdded = false; | - | ||||||||||||
706 | } | - | ||||||||||||
707 | if (printer && filePrintersAdded && (printer->outputFormat() != QPrinter::NativeFormat | - | ||||||||||||
708 | || printer->printerName().isEmpty())) | - | ||||||||||||
709 | { | - | ||||||||||||
710 | if (printer->outputFormat() == QPrinter::PdfFormat) | - | ||||||||||||
711 | widget.printers->setCurrentIndex(widget.printers->count() - 1); | - | ||||||||||||
712 | widget.filename->setEnabled(true); | - | ||||||||||||
713 | widget.lOutput->setEnabled(true); | - | ||||||||||||
714 | } | - | ||||||||||||
715 | - | |||||||||||||
716 | widget.filename->setVisible(printToFile); | - | ||||||||||||
717 | widget.lOutput->setVisible(printToFile); | - | ||||||||||||
718 | widget.fileBrowser->setVisible(printToFile); | - | ||||||||||||
719 | - | |||||||||||||
720 | widget.properties->setVisible(q->isOptionEnabled(QAbstractPrintDialog::PrintShowPageSize)); | - | ||||||||||||
721 | } | - | ||||||||||||
722 | - | |||||||||||||
723 | QUnixPrintWidgetPrivate::~QUnixPrintWidgetPrivate() | - | ||||||||||||
724 | { | - | ||||||||||||
725 | } | - | ||||||||||||
726 | - | |||||||||||||
727 | void QUnixPrintWidgetPrivate::_q_printerChanged(int index) | - | ||||||||||||
728 | { | - | ||||||||||||
729 | if (index < 0) | - | ||||||||||||
730 | return; | - | ||||||||||||
731 | const int printerCount = widget.printers->count(); | - | ||||||||||||
732 | widget.filename->setEnabled(false); | - | ||||||||||||
733 | widget.lOutput->setEnabled(false); | - | ||||||||||||
734 | - | |||||||||||||
735 | // Reset properties dialog when printer is changed | - | ||||||||||||
736 | if (propertiesDialog){ | - | ||||||||||||
737 | delete propertiesDialog; | - | ||||||||||||
738 | propertiesDialog = 0; | - | ||||||||||||
739 | propertiesDialogShown = false; | - | ||||||||||||
740 | } | - | ||||||||||||
741 | - | |||||||||||||
742 | if (filePrintersAdded) { | - | ||||||||||||
743 | Q_ASSERT(index != printerCount - 2); // separator | - | ||||||||||||
744 | if (index == printerCount - 1) { // PDF | - | ||||||||||||
745 | widget.location->setText(QPrintDialog::tr("Local file")); | - | ||||||||||||
746 | widget.type->setText(QPrintDialog::tr("Write PDF file")); | - | ||||||||||||
747 | widget.properties->setEnabled(true); | - | ||||||||||||
748 | widget.filename->setEnabled(true); | - | ||||||||||||
749 | QString filename = widget.filename->text(); | - | ||||||||||||
750 | widget.filename->setText(filename); | - | ||||||||||||
751 | widget.lOutput->setEnabled(true); | - | ||||||||||||
752 | if (optionsPane) | - | ||||||||||||
753 | optionsPane->selectPrinter(QPrinter::PdfFormat); | - | ||||||||||||
754 | return; | - | ||||||||||||
755 | } | - | ||||||||||||
756 | } | - | ||||||||||||
757 | - | |||||||||||||
758 | if (printer) { | - | ||||||||||||
759 | QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get(); | - | ||||||||||||
760 | if (ps) | - | ||||||||||||
761 | m_currentPrintDevice = ps->createPrintDevice(widget.printers->itemText(index)); | - | ||||||||||||
762 | - | |||||||||||||
763 | printer->setPrinterName(m_currentPrintDevice.id()); | - | ||||||||||||
764 | - | |||||||||||||
765 | widget.location->setText(m_currentPrintDevice.location()); | - | ||||||||||||
766 | widget.type->setText(m_currentPrintDevice.makeAndModel()); | - | ||||||||||||
767 | if (optionsPane) | - | ||||||||||||
768 | optionsPane->selectPrinter(QPrinter::NativeFormat); | - | ||||||||||||
769 | } | - | ||||||||||||
770 | } | - | ||||||||||||
771 | - | |||||||||||||
772 | void QUnixPrintWidgetPrivate::setOptionsPane(QPrintDialogPrivate *pane) | - | ||||||||||||
773 | { | - | ||||||||||||
774 | optionsPane = pane; | - | ||||||||||||
775 | if (optionsPane) | - | ||||||||||||
776 | optionsPane->selectPrinter(QPrinter::NativeFormat); | - | ||||||||||||
777 | } | - | ||||||||||||
778 | - | |||||||||||||
779 | void QUnixPrintWidgetPrivate::_q_btnBrowseClicked() | - | ||||||||||||
780 | { | - | ||||||||||||
781 | QString filename = widget.filename->text(); | - | ||||||||||||
782 | #ifndef QT_NO_FILEDIALOG | - | ||||||||||||
783 | filename = QFileDialog::getSaveFileName(parent, QPrintDialog::tr("Print To File ..."), filename, | - | ||||||||||||
784 | QString(), 0, QFileDialog::DontConfirmOverwrite); | - | ||||||||||||
785 | #else | - | ||||||||||||
786 | filename.clear(); | - | ||||||||||||
787 | #endif | - | ||||||||||||
788 | if (!filename.isEmpty()) { | - | ||||||||||||
789 | widget.filename->setText(filename); | - | ||||||||||||
790 | widget.printers->setCurrentIndex(widget.printers->count() - 1); // the pdf one | - | ||||||||||||
791 | } | - | ||||||||||||
792 | } | - | ||||||||||||
793 | - | |||||||||||||
794 | void QUnixPrintWidgetPrivate::applyPrinterProperties() | - | ||||||||||||
795 | { | - | ||||||||||||
796 | if (printer == 0)
| 0-3 | ||||||||||||
797 | return; never executed: return; | 0 | ||||||||||||
798 | if (printer->outputFileName().isEmpty()) {
| 0-3 | ||||||||||||
799 | QString home = QDir::homePath(); | - | ||||||||||||
800 | QString cur = QDir::currentPath(); | - | ||||||||||||
801 | if (home.at(home.length()-1) != QLatin1Char('/'))
| 0-3 | ||||||||||||
802 | home += QLatin1Char('/'); executed 3 times by 1 test: home += QLatin1Char('/'); Executed by:
| 3 | ||||||||||||
803 | if (!cur.isEmpty() && cur.at(cur.length()-1) != QLatin1Char('/'))
| 0-3 | ||||||||||||
804 | cur += QLatin1Char('/'); executed 3 times by 1 test: cur += QLatin1Char('/'); Executed by:
| 3 | ||||||||||||
805 | if (!cur.startsWith(home))
| 0-3 | ||||||||||||
806 | cur = home; never executed: cur = home; | 0 | ||||||||||||
807 | if (QGuiApplication::platformName() == QLatin1String("xcb")) {
| 0-3 | ||||||||||||
808 | if (printer->docName().isEmpty()) {
| 0-3 | ||||||||||||
809 | cur += QLatin1String("print.pdf"); | - | ||||||||||||
810 | } else { executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
811 | QRegExp re(QString::fromLatin1("(.*)\\.\\S+")); | - | ||||||||||||
812 | if (re.exactMatch(printer->docName()))
| 0 | ||||||||||||
813 | cur += re.cap(1); never executed: cur += re.cap(1); | 0 | ||||||||||||
814 | else | - | ||||||||||||
815 | cur += printer->docName(); never executed: cur += printer->docName(); | 0 | ||||||||||||
816 | cur += QLatin1String(".pdf"); | - | ||||||||||||
817 | } never executed: end of block | 0 | ||||||||||||
818 | } // xcb | - | ||||||||||||
819 | - | |||||||||||||
820 | widget.filename->setText(cur); | - | ||||||||||||
821 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
822 | else | - | ||||||||||||
823 | widget.filename->setText( printer->outputFileName() ); never executed: widget.filename->setText( printer->outputFileName() ); | 0 | ||||||||||||
824 | QString printerName = printer->printerName(); | - | ||||||||||||
825 | if (!printerName.isEmpty()) {
| 0-3 | ||||||||||||
826 | for (const int i = 0; i <widget.printers->count(); ++i) { | - | ||||||||||||
iffindText(widget.printers->itemTextprinterName); | ||||||||||||||
827 | if
| 0 | ||||||||||||
828 | {widget.printers->setCurrentIndex(i);break; never executed: widget.printers->setCurrentIndex(i); | 0 | ||||||||||||
} never executed: widget.printers->setCurrentIndex(i); | ||||||||||||||
} never executed: widget.printers->setCurrentIndex(i); | ||||||||||||||
829 | } never executed: end of block | 0 | ||||||||||||
830 | // PDF printer not added to the dialog yet, we'll handle those cases in QUnixPrintWidgetPrivate::updateWidget | - | ||||||||||||
831 | - | |||||||||||||
832 | if (propertiesDialog)
| 0-3 | ||||||||||||
833 | propertiesDialog->applyPrinterProperties(printer); never executed: propertiesDialog->applyPrinterProperties(printer); | 0 | ||||||||||||
834 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
835 | - | |||||||||||||
836 | #ifndef QT_NO_MESSAGEBOX | - | ||||||||||||
837 | bool QUnixPrintWidgetPrivate::checkFields() | - | ||||||||||||
838 | { | - | ||||||||||||
839 | if (widget.filename->isEnabled()) { | - | ||||||||||||
840 | QString file = widget.filename->text(); | - | ||||||||||||
841 | QFile f(file); | - | ||||||||||||
842 | QFileInfo fi(f); | - | ||||||||||||
843 | bool exists = fi.exists(); | - | ||||||||||||
844 | bool opened = false; | - | ||||||||||||
845 | if (exists && fi.isDir()) { | - | ||||||||||||
846 | QMessageBox::warning(q, q->windowTitle(), | - | ||||||||||||
847 | QPrintDialog::tr("%1 is a directory.\nPlease choose a different file name.").arg(file)); | - | ||||||||||||
848 | return false; | - | ||||||||||||
849 | } else if ((exists && !fi.isWritable()) || !(opened = f.open(QFile::Append))) { | - | ||||||||||||
850 | QMessageBox::warning(q, q->windowTitle(), | - | ||||||||||||
851 | QPrintDialog::tr("File %1 is not writable.\nPlease choose a different file name.").arg(file)); | - | ||||||||||||
852 | return false; | - | ||||||||||||
853 | } else if (exists) { | - | ||||||||||||
854 | int ret = QMessageBox::question(q, q->windowTitle(), | - | ||||||||||||
855 | QPrintDialog::tr("%1 already exists.\nDo you want to overwrite it?").arg(file), | - | ||||||||||||
856 | QMessageBox::Yes|QMessageBox::No, QMessageBox::No); | - | ||||||||||||
857 | if (ret == QMessageBox::No) | - | ||||||||||||
858 | return false; | - | ||||||||||||
859 | } | - | ||||||||||||
860 | if (opened) { | - | ||||||||||||
861 | f.close(); | - | ||||||||||||
862 | if (!exists) | - | ||||||||||||
863 | f.remove(); | - | ||||||||||||
864 | } | - | ||||||||||||
865 | } | - | ||||||||||||
866 | - | |||||||||||||
867 | #ifndef QT_NO_CUPS | - | ||||||||||||
868 | if (propertiesDialogShown) { | - | ||||||||||||
869 | QCUPSSupport::PagesPerSheet pagesPerSheet = propertiesDialog->widget.pageSetup->m_ui.pagesPerSheetCombo | - | ||||||||||||
870 | ->currentData().value<QCUPSSupport::PagesPerSheet>(); | - | ||||||||||||
871 | - | |||||||||||||
872 | QCUPSSupport::PageSet pageSet = optionsPane->options.pageSetCombo->currentData().value<QCUPSSupport::PageSet>(); | - | ||||||||||||
873 | - | |||||||||||||
874 | - | |||||||||||||
875 | if (pagesPerSheet != QCUPSSupport::OnePagePerSheet | - | ||||||||||||
876 | && pageSet != QCUPSSupport::AllPages) { | - | ||||||||||||
877 | QMessageBox::warning(q, q->windowTitle(), | - | ||||||||||||
878 | QPrintDialog::tr("Options 'Pages Per Sheet' and 'Page Set' cannot be used together.\nPlease turn one of those options off.")); | - | ||||||||||||
879 | return false; | - | ||||||||||||
880 | } | - | ||||||||||||
881 | } | - | ||||||||||||
882 | #endif | - | ||||||||||||
883 | - | |||||||||||||
884 | // Every test passed. Accept the dialog. | - | ||||||||||||
885 | return true; | - | ||||||||||||
886 | } | - | ||||||||||||
887 | #endif // QT_NO_MESSAGEBOX | - | ||||||||||||
888 | - | |||||||||||||
889 | void QUnixPrintWidgetPrivate::setupPrinterProperties() | - | ||||||||||||
890 | { | - | ||||||||||||
891 | if (propertiesDialog) | - | ||||||||||||
892 | delete propertiesDialog; | - | ||||||||||||
893 | - | |||||||||||||
894 | propertiesDialog = new QPrintPropertiesDialog(q); | - | ||||||||||||
895 | propertiesDialog->setResult(QDialog::Rejected); | - | ||||||||||||
896 | propertiesDialogShown = false; | - | ||||||||||||
897 | - | |||||||||||||
898 | propertiesDialog->applyPrinterProperties(q->printer()); | - | ||||||||||||
899 | - | |||||||||||||
900 | if (q->isOptionEnabled(QPrintDialog::PrintToFile) | - | ||||||||||||
901 | && (widget.printers->currentIndex() == widget.printers->count() - 1)) {// PDF | - | ||||||||||||
902 | propertiesDialog->selectPrinter(QPrinter::PdfFormat, QString()); | - | ||||||||||||
903 | } | - | ||||||||||||
904 | else | - | ||||||||||||
905 | propertiesDialog->selectPrinter(QPrinter::NativeFormat, widget.printers->currentText()); | - | ||||||||||||
906 | } | - | ||||||||||||
907 | - | |||||||||||||
908 | void QUnixPrintWidgetPrivate::_q_btnPropertiesClicked() | - | ||||||||||||
909 | { | - | ||||||||||||
910 | if (!propertiesDialog) | - | ||||||||||||
911 | setupPrinterProperties(); | - | ||||||||||||
912 | propertiesDialog->exec(); | - | ||||||||||||
913 | if (!propertiesDialogShown && propertiesDialog->result() == QDialog::Rejected) { | - | ||||||||||||
914 | // If properties dialog was rejected the dialog is deleted and | - | ||||||||||||
915 | // the properties are set to defaults when printer is setup | - | ||||||||||||
916 | delete propertiesDialog; | - | ||||||||||||
917 | propertiesDialog = 0; | - | ||||||||||||
918 | propertiesDialogShown = false; | - | ||||||||||||
919 | } else | - | ||||||||||||
920 | // properties dialog was shown and accepted | - | ||||||||||||
921 | propertiesDialogShown = true; | - | ||||||||||||
922 | } | - | ||||||||||||
923 | - | |||||||||||||
924 | void QUnixPrintWidgetPrivate::setupPrinter() | - | ||||||||||||
925 | { | - | ||||||||||||
926 | const int printerCount = widget.printers->count(); | - | ||||||||||||
927 | const int index = widget.printers->currentIndex(); | - | ||||||||||||
928 | - | |||||||||||||
929 | if (filePrintersAdded && index == printerCount - 1) { // PDF | - | ||||||||||||
930 | printer->setPrinterName(QString()); | - | ||||||||||||
931 | Q_ASSERT(index != printerCount - 2); // separator | - | ||||||||||||
932 | printer->setOutputFormat(QPrinter::PdfFormat); | - | ||||||||||||
933 | QString path = widget.filename->text(); | - | ||||||||||||
934 | if (QDir::isRelativePath(path)) | - | ||||||||||||
935 | path = QDir::homePath() + QDir::separator() + path; | - | ||||||||||||
936 | printer->setOutputFileName(path); | - | ||||||||||||
937 | } | - | ||||||||||||
938 | else { | - | ||||||||||||
939 | printer->setPrinterName(widget.printers->currentText()); | - | ||||||||||||
940 | printer->setOutputFileName(QString()); | - | ||||||||||||
941 | } | - | ||||||||||||
942 | - | |||||||||||||
943 | if (!propertiesDialog) | - | ||||||||||||
944 | setupPrinterProperties(); | - | ||||||||||||
945 | - | |||||||||||||
946 | if (propertiesDialog->result() == QDialog::Accepted || !propertiesDialogShown) | - | ||||||||||||
947 | propertiesDialog->setupPrinter(); | - | ||||||||||||
948 | } | - | ||||||||||||
949 | - | |||||||||||||
950 | /*! \internal | - | ||||||||||||
951 | */ | - | ||||||||||||
952 | QUnixPrintWidget::QUnixPrintWidget(QPrinter *printer, QWidget *parent) | - | ||||||||||||
953 | : QWidget(parent), d(new QUnixPrintWidgetPrivate(this, printer)) | - | ||||||||||||
954 | { | - | ||||||||||||
955 | d->applyPrinterProperties(); | - | ||||||||||||
956 | } | - | ||||||||||||
957 | - | |||||||||||||
958 | /*! \internal | - | ||||||||||||
959 | */ | - | ||||||||||||
960 | QUnixPrintWidget::~QUnixPrintWidget() | - | ||||||||||||
961 | { | - | ||||||||||||
962 | delete d; | - | ||||||||||||
963 | } | - | ||||||||||||
964 | - | |||||||||||||
965 | /*! \internal | - | ||||||||||||
966 | - | |||||||||||||
967 | Updates the printer with the states held in the QUnixPrintWidget. | - | ||||||||||||
968 | */ | - | ||||||||||||
969 | void QUnixPrintWidget::updatePrinter() | - | ||||||||||||
970 | { | - | ||||||||||||
971 | d->setupPrinter(); | - | ||||||||||||
972 | } | - | ||||||||||||
973 | - | |||||||||||||
974 | //////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
975 | //////////////////////////////////////////////////////////////////////////////// | - | ||||||||||||
976 | - | |||||||||||||
977 | #endif // defined (Q_OS_UNIX) | - | ||||||||||||
978 | - | |||||||||||||
979 | QT_END_NAMESPACE | - | ||||||||||||
980 | - | |||||||||||||
981 | #include "moc_qprintdialog.cpp" | - | ||||||||||||
982 | #include "qprintdialog_unix.moc" | - | ||||||||||||
983 | - | |||||||||||||
984 | #endif // QT_NO_PRINTDIALOG | - | ||||||||||||
985 | - | |||||||||||||
Source code | Switch to Preprocessed file |