Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/printsupport/dialogs/qprintdialog_unix.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | - | |||||||||||||
10 | static void initResources() | - | ||||||||||||
11 | { | - | ||||||||||||
12 | do { extern int qInitResources_qprintdialog (); qInitResources_qprintdialog (); } while (0); | - | ||||||||||||
13 | } | - | ||||||||||||
14 | - | |||||||||||||
15 | - | |||||||||||||
16 | - | |||||||||||||
17 | class QOptionTreeItem; | - | ||||||||||||
18 | class QPPDOptionsModel; | - | ||||||||||||
19 | - | |||||||||||||
20 | class QPrintPropertiesDialog : public QDialog | - | ||||||||||||
21 | { | - | ||||||||||||
22 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||
23 | #pragma GCC diagnostic push | - | ||||||||||||
24 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||
25 | #pragma GCC diagnostic pop | - | ||||||||||||
26 | struct QPrivateSignal {}; | - | ||||||||||||
27 | public: | - | ||||||||||||
28 | QPrintPropertiesDialog(QAbstractPrintDialog *parent = 0); | - | ||||||||||||
29 | ~QPrintPropertiesDialog(); | - | ||||||||||||
30 | - | |||||||||||||
31 | void selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName); | - | ||||||||||||
32 | - | |||||||||||||
33 | - | |||||||||||||
34 | void applyPrinterProperties(QPrinter *p); | - | ||||||||||||
35 | void setupPrinter() const; | - | ||||||||||||
36 | - | |||||||||||||
37 | private: | - | ||||||||||||
38 | friend class QUnixPrintWidgetPrivate; | - | ||||||||||||
39 | Ui::QPrintPropertiesWidget widget; | - | ||||||||||||
40 | QDialogButtonBox *m_buttons; | - | ||||||||||||
41 | - | |||||||||||||
42 | QCupsJobWidget *m_jobOptions; | - | ||||||||||||
43 | - | |||||||||||||
44 | }; | - | ||||||||||||
45 | - | |||||||||||||
46 | class QUnixPrintWidgetPrivate; | - | ||||||||||||
47 | - | |||||||||||||
48 | class QUnixPrintWidget : public QWidget | - | ||||||||||||
49 | { | - | ||||||||||||
50 | public: template <typename ThisObject> inline void qt_check_for_QOBJECT_macro(const ThisObject &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } | - | ||||||||||||
51 | #pragma GCC diagnostic push | - | ||||||||||||
52 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||||||||
53 | #pragma GCC diagnostic pop | - | ||||||||||||
54 | struct QPrivateSignal {}; | - | ||||||||||||
55 | - | |||||||||||||
56 | public: | - | ||||||||||||
57 | explicit QUnixPrintWidget(QPrinter *printer, QWidget *parent = 0); | - | ||||||||||||
58 | ~QUnixPrintWidget(); | - | ||||||||||||
59 | void updatePrinter(); | - | ||||||||||||
60 | - | |||||||||||||
61 | private: | - | ||||||||||||
62 | friend class QPrintDialogPrivate; | - | ||||||||||||
63 | friend class QUnixPrintWidgetPrivate; | - | ||||||||||||
64 | QUnixPrintWidgetPrivate *d; | - | ||||||||||||
65 | - | |||||||||||||
66 | - | |||||||||||||
67 | - | |||||||||||||
68 | }; | - | ||||||||||||
69 | - | |||||||||||||
70 | class QUnixPrintWidgetPrivate | - | ||||||||||||
71 | { | - | ||||||||||||
72 | public: | - | ||||||||||||
73 | QUnixPrintWidgetPrivate(QUnixPrintWidget *q, QPrinter *prn); | - | ||||||||||||
74 | ~QUnixPrintWidgetPrivate(); | - | ||||||||||||
75 | - | |||||||||||||
76 | - | |||||||||||||
77 | void applyPrinterProperties(); | - | ||||||||||||
78 | bool checkFields(); | - | ||||||||||||
79 | void setupPrinter(); | - | ||||||||||||
80 | void setOptionsPane(QPrintDialogPrivate *pane); | - | ||||||||||||
81 | void setupPrinterProperties(); | - | ||||||||||||
82 | - | |||||||||||||
83 | void _q_printerChanged(int index); | - | ||||||||||||
84 | void _q_btnPropertiesClicked(); | - | ||||||||||||
85 | void _q_btnBrowseClicked(); | - | ||||||||||||
86 | - | |||||||||||||
87 | QUnixPrintWidget * const parent; | - | ||||||||||||
88 | QPrintPropertiesDialog *propertiesDialog; | - | ||||||||||||
89 | Ui::QPrintWidget widget; | - | ||||||||||||
90 | QAbstractPrintDialog * q; | - | ||||||||||||
91 | QPrinter *printer; | - | ||||||||||||
92 | QPrintDevice m_currentPrintDevice; | - | ||||||||||||
93 | - | |||||||||||||
94 | void updateWidget(); | - | ||||||||||||
95 | - | |||||||||||||
96 | private: | - | ||||||||||||
97 | QPrintDialogPrivate *optionsPane; | - | ||||||||||||
98 | bool filePrintersAdded; | - | ||||||||||||
99 | bool propertiesDialogShown; | - | ||||||||||||
100 | }; | - | ||||||||||||
101 | - | |||||||||||||
102 | class QPrintDialogPrivate : public QAbstractPrintDialogPrivate | - | ||||||||||||
103 | { | - | ||||||||||||
104 | inline QPrintDialog* q_func() { return static_cast<QPrintDialog *>(q_ptr); } inline const QPrintDialog* q_func() const { return static_cast<const QPrintDialog *>(q_ptr); } friend class QPrintDialog; | - | ||||||||||||
105 | public: static inline QString tr(const char *sourceText, const char *disambiguation = nullptr, int n = -1) { return QCoreApplication::translate("QPrintDialog", sourceText, disambiguation, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *sourceText, const char *disambiguation = nullptr, int n = -1) { return QCoreApplication::translate("QPrintDialog", sourceText, disambiguation, n); } private: | - | ||||||||||||
106 | public: | - | ||||||||||||
107 | QPrintDialogPrivate(); | - | ||||||||||||
108 | ~QPrintDialogPrivate(); | - | ||||||||||||
109 | - | |||||||||||||
110 | void init(); | - | ||||||||||||
111 | - | |||||||||||||
112 | void applyPrinterProperties(); | - | ||||||||||||
113 | - | |||||||||||||
114 | void selectPrinter(const QPrinter::OutputFormat outputFormat); | - | ||||||||||||
115 | - | |||||||||||||
116 | void _q_togglePageSetCombo(bool); | - | ||||||||||||
117 | - | |||||||||||||
118 | void _q_checkFields(); | - | ||||||||||||
119 | - | |||||||||||||
120 | void _q_collapseOrExpandDialog(); | - | ||||||||||||
121 | - | |||||||||||||
122 | void setupPrinter(); | - | ||||||||||||
123 | void updateWidgets(); | - | ||||||||||||
124 | - | |||||||||||||
125 | virtual void setTabs(const QList<QWidget*> &tabs) override; | - | ||||||||||||
126 | - | |||||||||||||
127 | Ui::QPrintSettingsOutput options; | - | ||||||||||||
128 | QUnixPrintWidget *top; | - | ||||||||||||
129 | QWidget *bottom; | - | ||||||||||||
130 | QDialogButtonBox *buttons; | - | ||||||||||||
131 | QPushButton *collapseButton; | - | ||||||||||||
132 | QPrinter::OutputFormat printerOutputFormat; | - | ||||||||||||
133 | }; | - | ||||||||||||
134 | QPrintPropertiesDialog::QPrintPropertiesDialog(QAbstractPrintDialog *parent) | - | ||||||||||||
135 | : QDialog(parent) | - | ||||||||||||
136 | { | - | ||||||||||||
137 | setWindowTitle(tr("Printer Properties")); | - | ||||||||||||
138 | QVBoxLayout *lay = new QVBoxLayout(this); | - | ||||||||||||
139 | this->setLayout(lay); | - | ||||||||||||
140 | QWidget *content = new QWidget(this); | - | ||||||||||||
141 | widget.setupUi(content); | - | ||||||||||||
142 | m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); | - | ||||||||||||
143 | lay->addWidget(content); | - | ||||||||||||
144 | lay->addWidget(m_buttons); | - | ||||||||||||
145 | - | |||||||||||||
146 | connect(m_buttons->button(QDialogButtonBox::Ok), qFlagLocation("2""clicked()" "\0" __FILE__ ":" "240""246"), this, qFlagLocation("1""accept()" "\0" __FILE__ ":" "240""246")); | - | ||||||||||||
147 | connect(m_buttons->button(QDialogButtonBox::Cancel), qFlagLocation("2""clicked()" "\0" __FILE__ ":" "241""247"), this, qFlagLocation("1""reject()" "\0" __FILE__ ":" "241""247")); | - | ||||||||||||
148 | - | |||||||||||||
149 | - | |||||||||||||
150 | m_jobOptions = new QCupsJobWidget(); | - | ||||||||||||
151 | widget.tabs->addTab(m_jobOptions, tr("Job Options")); | - | ||||||||||||
152 | - | |||||||||||||
153 | } | - | ||||||||||||
154 | - | |||||||||||||
155 | QPrintPropertiesDialog::~QPrintPropertiesDialog() | - | ||||||||||||
156 | { | - | ||||||||||||
157 | } | - | ||||||||||||
158 | - | |||||||||||||
159 | void QPrintPropertiesDialog::applyPrinterProperties(QPrinter *p) | - | ||||||||||||
160 | { | - | ||||||||||||
161 | widget.pageSetup->setPrinter(p); | - | ||||||||||||
162 | - | |||||||||||||
163 | m_jobOptions->setPrinter(p); | - | ||||||||||||
164 | - | |||||||||||||
165 | } | - | ||||||||||||
166 | - | |||||||||||||
167 | void QPrintPropertiesDialog::setupPrinter() const | - | ||||||||||||
168 | { | - | ||||||||||||
169 | widget.pageSetup->setupPrinter(); | - | ||||||||||||
170 | - | |||||||||||||
171 | m_jobOptions->setupPrinter(); | - | ||||||||||||
172 | - | |||||||||||||
173 | } | - | ||||||||||||
174 | - | |||||||||||||
175 | void QPrintPropertiesDialog::selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName) | - | ||||||||||||
176 | { | - | ||||||||||||
177 | widget.pageSetup->selectPrinter(outputFormat, printerName); | - | ||||||||||||
178 | } | - | ||||||||||||
179 | QPrintDialogPrivate::QPrintDialogPrivate() | - | ||||||||||||
180 | : top(0), bottom(0), buttons(0), collapseButton(0) | - | ||||||||||||
181 | { | - | ||||||||||||
182 | initResources(); | - | ||||||||||||
183 | } | - | ||||||||||||
184 | - | |||||||||||||
185 | QPrintDialogPrivate::~QPrintDialogPrivate() | - | ||||||||||||
186 | { | - | ||||||||||||
187 | } | - | ||||||||||||
188 | - | |||||||||||||
189 | void QPrintDialogPrivate::init() | - | ||||||||||||
190 | { | - | ||||||||||||
191 | QPrintDialog * const q = q_func(); | - | ||||||||||||
192 | - | |||||||||||||
193 | top = new QUnixPrintWidget(q->printer(), q); | - | ||||||||||||
194 | bottom = new QWidget(q); | - | ||||||||||||
195 | options.setupUi(bottom); | - | ||||||||||||
196 | options.color->setIconSize(QSize(32, 32)); | - | ||||||||||||
197 | options.color->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-color.png"))); | - | ||||||||||||
198 | options.grayscale->setIconSize(QSize(32, 32)); | - | ||||||||||||
199 | options.grayscale->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-gray-scale.png"))); | - | ||||||||||||
200 | - | |||||||||||||
201 | - | |||||||||||||
202 | - | |||||||||||||
203 | options.pageSetCombo->addItem(tr("All Pages"), QVariant::fromValue(QCUPSSupport::AllPages)); | - | ||||||||||||
204 | options.pageSetCombo->addItem(tr("Odd Pages"), QVariant::fromValue(QCUPSSupport::OddPages)); | - | ||||||||||||
205 | options.pageSetCombo->addItem(tr("Even Pages"), QVariant::fromValue(QCUPSSupport::EvenPages)); | - | ||||||||||||
206 | - | |||||||||||||
207 | - | |||||||||||||
208 | top->d->setOptionsPane(this); | - | ||||||||||||
209 | - | |||||||||||||
210 | buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, q); | - | ||||||||||||
211 | collapseButton = new QPushButton(QPrintDialog::tr("&Options >>"), buttons); | - | ||||||||||||
212 | buttons->addButton(collapseButton, QDialogButtonBox::ResetRole); | - | ||||||||||||
213 | bottom->setVisible(false); | - | ||||||||||||
214 | - | |||||||||||||
215 | QPushButton *printButton = buttons->button(QDialogButtonBox::Ok); | - | ||||||||||||
216 | printButton->setText(QPrintDialog::tr("&Print")); | - | ||||||||||||
217 | printButton->setDefault(true); | - | ||||||||||||
218 | - | |||||||||||||
219 | QVBoxLayout *lay = new QVBoxLayout(q); | - | ||||||||||||
220 | q->setLayout(lay); | - | ||||||||||||
221 | lay->addWidget(top); | - | ||||||||||||
222 | lay->addWidget(bottom); | - | ||||||||||||
223 | lay->addWidget(buttons); | - | ||||||||||||
224 | - | |||||||||||||
225 | - | |||||||||||||
226 | - | |||||||||||||
227 | - | |||||||||||||
228 | QObject::connect(buttons, qFlagLocation("2""accepted()" "\0" __FILE__ ":" "334""340"), q, qFlagLocation("1""_q_checkFields()" "\0" __FILE__ ":" "334""340")); | - | ||||||||||||
229 | - | |||||||||||||
230 | QObject::connect(buttons, qFlagLocation("2""rejected()" "\0" __FILE__ ":" "336""342"), q, qFlagLocation("1""reject()" "\0" __FILE__ ":" "336""342")); | - | ||||||||||||
231 | - | |||||||||||||
232 | QObject::connect(options.printSelection, qFlagLocation("2""toggled(bool)" "\0" __FILE__ ":" "338""344"), | - | ||||||||||||
233 | q, qFlagLocation("1""_q_togglePageSetCombo(bool)" "\0" __FILE__ ":" "339""345")); | - | ||||||||||||
234 | - | |||||||||||||
235 | QObject::connect(options.printCurrentPage, qFlagLocation("2""toggled(bool)" "\0" __FILE__ ":" "341""347"), | - | ||||||||||||
236 | q, qFlagLocation("1""_q_togglePageSetCombo(bool)" "\0" __FILE__ ":" "342""348")); | - | ||||||||||||
237 | - | |||||||||||||
238 | QObject::connect(collapseButton, qFlagLocation("2""released()" "\0" __FILE__ ":" "344""350"), q, qFlagLocation("1""_q_collapseOrExpandDialog()" "\0" __FILE__ ":" "344""350")); | - | ||||||||||||
239 | } | - | ||||||||||||
240 | - | |||||||||||||
241 | - | |||||||||||||
242 | void QPrintDialogPrivate::selectPrinter(const QPrinter::OutputFormat outputFormat) | - | ||||||||||||
243 | { | - | ||||||||||||
244 | QPrintDialog * const q = q_func(); | - | ||||||||||||
245 | QPrinter *p = q->printer(); | - | ||||||||||||
246 | printerOutputFormat = outputFormat; | - | ||||||||||||
247 | - | |||||||||||||
248 | if (p->colorMode() == QPrinter::Color) | - | ||||||||||||
249 | options.color->setChecked(true); | - | ||||||||||||
250 | else | - | ||||||||||||
251 | options.grayscale->setChecked(true); | - | ||||||||||||
252 | - | |||||||||||||
253 | switch (p->duplex()) { | - | ||||||||||||
254 | case QPrinter::DuplexNone: | - | ||||||||||||
255 | options.noDuplex->setChecked(true); break; | - | ||||||||||||
256 | case QPrinter::DuplexLongSide: | - | ||||||||||||
257 | case QPrinter::DuplexAuto: | - | ||||||||||||
258 | options.duplexLong->setChecked(true); break; | - | ||||||||||||
259 | case QPrinter::DuplexShortSide: | - | ||||||||||||
260 | options.duplexShort->setChecked(true); break; | - | ||||||||||||
261 | } | - | ||||||||||||
262 | options.copies->setValue(p->copyCount()); | - | ||||||||||||
263 | options.collate->setChecked(p->collateCopies()); | - | ||||||||||||
264 | options.reverse->setChecked(p->pageOrder() == QPrinter::LastPageFirst); | - | ||||||||||||
265 | - | |||||||||||||
266 | if (outputFormat == QPrinter::PdfFormat || options.printSelection->isChecked() | - | ||||||||||||
267 | || options.printCurrentPage->isChecked()) | - | ||||||||||||
268 | - | |||||||||||||
269 | options.pageSetCombo->setEnabled(false); | - | ||||||||||||
270 | else | - | ||||||||||||
271 | options.pageSetCombo->setEnabled(true); | - | ||||||||||||
272 | } | - | ||||||||||||
273 | - | |||||||||||||
274 | void QPrintDialogPrivate::applyPrinterProperties() | - | ||||||||||||
275 | { | - | ||||||||||||
276 | - | |||||||||||||
277 | top->d->applyPrinterProperties(); | - | ||||||||||||
278 | } | - | ||||||||||||
279 | - | |||||||||||||
280 | void QPrintDialogPrivate::setupPrinter() | - | ||||||||||||
281 | { | - | ||||||||||||
282 | - | |||||||||||||
283 | top->d->setupPrinter(); | - | ||||||||||||
284 | - | |||||||||||||
285 | - | |||||||||||||
286 | QPrintDialog * const q = q_func(); | - | ||||||||||||
287 | QPrinter* p = q->printer(); | - | ||||||||||||
288 | - | |||||||||||||
289 | if (options.duplex->isEnabled()) { | - | ||||||||||||
290 | if (options.noDuplex->isChecked()) | - | ||||||||||||
291 | p->setDuplex(QPrinter::DuplexNone); | - | ||||||||||||
292 | else if (options.duplexLong->isChecked()) | - | ||||||||||||
293 | p->setDuplex(QPrinter::DuplexLongSide); | - | ||||||||||||
294 | else | - | ||||||||||||
295 | p->setDuplex(QPrinter::DuplexShortSide); | - | ||||||||||||
296 | } | - | ||||||||||||
297 | - | |||||||||||||
298 | p->setColorMode(options.color->isChecked() ? QPrinter::Color : QPrinter::GrayScale); | - | ||||||||||||
299 | p->setPageOrder(options.reverse->isChecked() ? QPrinter::LastPageFirst : QPrinter::FirstPageFirst); | - | ||||||||||||
300 | - | |||||||||||||
301 | - | |||||||||||||
302 | if (options.printAll->isChecked()) { | - | ||||||||||||
303 | p->setPrintRange(QPrinter::AllPages); | - | ||||||||||||
304 | p->setFromTo(0,0); | - | ||||||||||||
305 | } else if (options.printSelection->isChecked()) { | - | ||||||||||||
306 | p->setPrintRange(QPrinter::Selection); | - | ||||||||||||
307 | p->setFromTo(0,0); | - | ||||||||||||
308 | } else if (options.printCurrentPage->isChecked()) { | - | ||||||||||||
309 | p->setPrintRange(QPrinter::CurrentPage); | - | ||||||||||||
310 | p->setFromTo(0,0); | - | ||||||||||||
311 | } else if (options.printRange->isChecked()) { | - | ||||||||||||
312 | if (q->isOptionEnabled(QPrintDialog::PrintPageRange)) { | - | ||||||||||||
313 | p->setPrintRange(QPrinter::PageRange); | - | ||||||||||||
314 | p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value())); | - | ||||||||||||
315 | } else { | - | ||||||||||||
316 | - | |||||||||||||
317 | - | |||||||||||||
318 | p->setPrintRange(QPrinter::AllPages); | - | ||||||||||||
319 | p->setFromTo(0,0); | - | ||||||||||||
320 | } | - | ||||||||||||
321 | } | - | ||||||||||||
322 | - | |||||||||||||
323 | - | |||||||||||||
324 | - | |||||||||||||
325 | if (p->printRange() == QPrinter::AllPages || p->printRange() == QPrinter::PageRange) { | - | ||||||||||||
326 | - | |||||||||||||
327 | QCUPSSupport::PageSet pageSet = options.pageSetCombo->itemData(options.pageSetCombo->currentIndex()).value<QCUPSSupport::PageSet>(); | - | ||||||||||||
328 | if (q->isOptionEnabled(QPrintDialog::PrintPageRange) | - | ||||||||||||
329 | && p->printRange() == QPrinter::PageRange | - | ||||||||||||
330 | && (q->fromPage() % 2 == 0)) { | - | ||||||||||||
331 | - | |||||||||||||
332 | switch (pageSet) { | - | ||||||||||||
333 | case QCUPSSupport::AllPages: | - | ||||||||||||
334 | break; | - | ||||||||||||
335 | case QCUPSSupport::OddPages: | - | ||||||||||||
336 | QCUPSSupport::setPageSet(p, QCUPSSupport::EvenPages); | - | ||||||||||||
337 | break; | - | ||||||||||||
338 | case QCUPSSupport::EvenPages: | - | ||||||||||||
339 | QCUPSSupport::setPageSet(p, QCUPSSupport::OddPages); | - | ||||||||||||
340 | break; | - | ||||||||||||
341 | } | - | ||||||||||||
342 | } else if (pageSet != QCUPSSupport::AllPages) { | - | ||||||||||||
343 | QCUPSSupport::setPageSet(p, pageSet); | - | ||||||||||||
344 | } | - | ||||||||||||
345 | - | |||||||||||||
346 | - | |||||||||||||
347 | - | |||||||||||||
348 | if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) && options.printRange->isChecked()) | - | ||||||||||||
349 | QCUPSSupport::setPageRange(p, options.from->value(), qMax(options.from->value(), options.to->value())); | - | ||||||||||||
350 | } | - | ||||||||||||
351 | - | |||||||||||||
352 | - | |||||||||||||
353 | - | |||||||||||||
354 | p->setCopyCount(options.copies->value()); | - | ||||||||||||
355 | p->setCollateCopies(options.collate->isChecked()); | - | ||||||||||||
356 | } | - | ||||||||||||
357 | - | |||||||||||||
358 | void QPrintDialogPrivate::_q_togglePageSetCombo(bool checked) | - | ||||||||||||
359 | { | - | ||||||||||||
360 | if (printerOutputFormat == QPrinter::PdfFormat) | - | ||||||||||||
361 | return; | - | ||||||||||||
362 | - | |||||||||||||
363 | options.pageSetCombo->setDisabled(checked); | - | ||||||||||||
364 | } | - | ||||||||||||
365 | - | |||||||||||||
366 | void QPrintDialogPrivate::_q_collapseOrExpandDialog() | - | ||||||||||||
367 | { | - | ||||||||||||
368 | int collapseHeight = 0; | - | ||||||||||||
369 | QPrintDialog * const q = q_func(); | - | ||||||||||||
370 | QWidget *widgetToHide = bottom; | - | ||||||||||||
371 | if (widgetToHide->isVisible()) { | - | ||||||||||||
372 | collapseButton->setText(QPrintDialog::tr("&Options >>")); | - | ||||||||||||
373 | collapseHeight = widgetToHide->y() + widgetToHide->height() - (top->y() + top->height()); | - | ||||||||||||
374 | } | - | ||||||||||||
375 | else | - | ||||||||||||
376 | collapseButton->setText(QPrintDialog::tr("&Options <<")); | - | ||||||||||||
377 | widgetToHide->setVisible(! widgetToHide->isVisible()); | - | ||||||||||||
378 | if (! widgetToHide->isVisible()) { | - | ||||||||||||
379 | q->layout()->activate(); | - | ||||||||||||
380 | q->resize( QSize(q->width(), q->height() - collapseHeight) ); | - | ||||||||||||
381 | } | - | ||||||||||||
382 | } | - | ||||||||||||
383 | - | |||||||||||||
384 | - | |||||||||||||
385 | void QPrintDialogPrivate::_q_checkFields() | - | ||||||||||||
386 | { | - | ||||||||||||
387 | QPrintDialog * const q = q_func(); | - | ||||||||||||
388 | if (top->d->checkFields()) | - | ||||||||||||
389 | q->accept(); | - | ||||||||||||
390 | } | - | ||||||||||||
391 | - | |||||||||||||
392 | - | |||||||||||||
393 | - | |||||||||||||
394 | void QPrintDialogPrivate::updateWidgets() | - | ||||||||||||
395 | { | - | ||||||||||||
396 | QPrintDialog * const q = q_func(); | - | ||||||||||||
397 | options.gbPrintRange->setVisible(q->isOptionEnabled(QPrintDialog::PrintPageRange) || | - | ||||||||||||
398 | q->isOptionEnabled(QPrintDialog::PrintSelection) || | - | ||||||||||||
399 | q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); | - | ||||||||||||
400 | - | |||||||||||||
401 | options.printRange->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange)); | - | ||||||||||||
402 | options.printSelection->setVisible(q->isOptionEnabled(QPrintDialog::PrintSelection)); | - | ||||||||||||
403 | options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); | - | ||||||||||||
404 | options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies)); | - | ||||||||||||
405 | - | |||||||||||||
406 | - | |||||||||||||
407 | - | |||||||||||||
408 | if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) | - | ||||||||||||
409 | && (q->isOptionEnabled(QPrintDialog::PrintSelection) || q->isOptionEnabled(QPrintDialog::PrintCurrentPage))) { | - | ||||||||||||
410 | options.pageSetCombo->setVisible(false); | - | ||||||||||||
411 | options.pageSetLabel->setVisible(false); | - | ||||||||||||
412 | } else { | - | ||||||||||||
413 | options.pageSetCombo->setVisible(true); | - | ||||||||||||
414 | options.pageSetLabel->setVisible(true); | - | ||||||||||||
415 | } | - | ||||||||||||
416 | - | |||||||||||||
417 | if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)) { | - | ||||||||||||
418 | - | |||||||||||||
419 | - | |||||||||||||
420 | options.gbPrintRange->setVisible(true); | - | ||||||||||||
421 | options.printRange->setEnabled(true); | - | ||||||||||||
422 | } | - | ||||||||||||
423 | - | |||||||||||||
424 | - | |||||||||||||
425 | switch (q->printRange()) { | - | ||||||||||||
426 | case QPrintDialog::AllPages: | - | ||||||||||||
427 | options.printAll->setChecked(true); | - | ||||||||||||
428 | options.pageSetCombo->setEnabled(true); | - | ||||||||||||
429 | break; | - | ||||||||||||
430 | case QPrintDialog::Selection: | - | ||||||||||||
431 | options.printSelection->setChecked(true); | - | ||||||||||||
432 | options.pageSetCombo->setEnabled(false); | - | ||||||||||||
433 | break; | - | ||||||||||||
434 | case QPrintDialog::PageRange: | - | ||||||||||||
435 | options.printRange->setChecked(true); | - | ||||||||||||
436 | options.pageSetCombo->setEnabled(true); | - | ||||||||||||
437 | break; | - | ||||||||||||
438 | case QPrintDialog::CurrentPage: | - | ||||||||||||
439 | if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage)) { | - | ||||||||||||
440 | options.printCurrentPage->setChecked(true); | - | ||||||||||||
441 | options.pageSetCombo->setEnabled(false); | - | ||||||||||||
442 | } | - | ||||||||||||
443 | break; | - | ||||||||||||
444 | default: | - | ||||||||||||
445 | break; | - | ||||||||||||
446 | } | - | ||||||||||||
447 | const int minPage = qMax(1, qMin(q->minPage() , q->maxPage())); | - | ||||||||||||
448 | const int maxPage = qMax(1, q->maxPage() == 2147483647 ? 9999 : q->maxPage()); | - | ||||||||||||
449 | - | |||||||||||||
450 | options.from->setMinimum(minPage); | - | ||||||||||||
451 | options.to->setMinimum(minPage); | - | ||||||||||||
452 | options.from->setMaximum(maxPage); | - | ||||||||||||
453 | options.to->setMaximum(maxPage); | - | ||||||||||||
454 | - | |||||||||||||
455 | options.from->setValue(q->fromPage()); | - | ||||||||||||
456 | options.to->setValue(q->toPage()); | - | ||||||||||||
457 | top->d->updateWidget(); | - | ||||||||||||
458 | } | - | ||||||||||||
459 | - | |||||||||||||
460 | void QPrintDialogPrivate::setTabs(const QList<QWidget*> &tabWidgets) | - | ||||||||||||
461 | { | - | ||||||||||||
462 | QList<QWidget*>::ConstIterator iter = tabWidgets.begin(); | - | ||||||||||||
463 | while(iter != tabWidgets.constEnd()) { | - | ||||||||||||
464 | QWidget *tab = *iter; | - | ||||||||||||
465 | options.tabs->addTab(tab, tab->windowTitle()); | - | ||||||||||||
466 | ++iter; | - | ||||||||||||
467 | } | - | ||||||||||||
468 | } | - | ||||||||||||
469 | QPrintDialog::QPrintDialog(QPrinter *printer, QWidget *parent) | - | ||||||||||||
470 | : QAbstractPrintDialog(*(new QPrintDialogPrivate), printer, parent) | - | ||||||||||||
471 | { | - | ||||||||||||
472 | QPrintDialogPrivate * const d = d_func(); | - | ||||||||||||
473 | d->init(); | - | ||||||||||||
474 | } | - | ||||||||||||
475 | - | |||||||||||||
476 | - | |||||||||||||
477 | - | |||||||||||||
478 | - | |||||||||||||
479 | QPrintDialog::QPrintDialog(QWidget *parent) | - | ||||||||||||
480 | : QAbstractPrintDialog(*(new QPrintDialogPrivate), 0, parent) | - | ||||||||||||
481 | { | - | ||||||||||||
482 | QPrintDialogPrivate * const d = d_func(); | - | ||||||||||||
483 | d->init(); | - | ||||||||||||
484 | } | - | ||||||||||||
485 | - | |||||||||||||
486 | QPrintDialog::~QPrintDialog() | - | ||||||||||||
487 | { | - | ||||||||||||
488 | } | - | ||||||||||||
489 | - | |||||||||||||
490 | void QPrintDialog::setVisible(bool visible) | - | ||||||||||||
491 | { | - | ||||||||||||
492 | QPrintDialogPrivate * const d = d_func(); | - | ||||||||||||
493 | - | |||||||||||||
494 | if (visible) | - | ||||||||||||
495 | d->updateWidgets(); | - | ||||||||||||
496 | - | |||||||||||||
497 | QAbstractPrintDialog::setVisible(visible); | - | ||||||||||||
498 | } | - | ||||||||||||
499 | - | |||||||||||||
500 | int QPrintDialog::exec() | - | ||||||||||||
501 | { | - | ||||||||||||
502 | return QDialog::exec(); | - | ||||||||||||
503 | } | - | ||||||||||||
504 | - | |||||||||||||
505 | void QPrintDialog::accept() | - | ||||||||||||
506 | { | - | ||||||||||||
507 | QPrintDialogPrivate * const d = d_func(); | - | ||||||||||||
508 | d->setupPrinter(); | - | ||||||||||||
509 | QDialog::accept(); | - | ||||||||||||
510 | } | - | ||||||||||||
511 | QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p, QPrinter *prn) | - | ||||||||||||
512 | : parent(p), propertiesDialog(0), printer(prn), optionsPane(0), | - | ||||||||||||
513 | filePrintersAdded(false), propertiesDialogShown(false) | - | ||||||||||||
514 | { | - | ||||||||||||
515 | q = 0; | - | ||||||||||||
516 | if (parent
| 0-3 | ||||||||||||
517 | q = qobject_cast<QAbstractPrintDialog*> (parent->parent()); executed 3 times by 1 test: q = qobject_cast<QAbstractPrintDialog*> (parent->parent()); Executed by:
| 3 | ||||||||||||
518 | - | |||||||||||||
519 | widget.setupUi(parent); | - | ||||||||||||
520 | - | |||||||||||||
521 | int currentPrinterIndex = 0; | - | ||||||||||||
QStringList printers; | ||||||||||||||
QString defaultPrinter; | ||||||||||||||
522 | QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get(); | - | ||||||||||||
523 | if (ps
| 0-3 | ||||||||||||
524 | const QStringList printers = ps->availablePrintDeviceIds(); | - | ||||||||||||
525 | const QString defaultPrinter = ps->defaultPrintDeviceId(); | - | ||||||||||||
} | ||||||||||||||
for (int i = 0; i < printers.size(); | ||||||||||||||
526 | - | |||||||||||||
527 | ++i) {widget.printers->addItemaddItems(printers.at(i)); | - | ||||||||||||
if (); | ||||||||||||||
528 | - | |||||||||||||
529 | const int idx = printers.atindexOf(i) ==defaultPrinter); | - | ||||||||||||
530 | if (idx >= 0
| 0-3 | ||||||||||||
531 | currentPrinterIndex = iidx; never executed: currentPrinterIndex = idx; | 0 | ||||||||||||
532 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
533 | widget.properties->setEnabled(true); | - | ||||||||||||
534 | - | |||||||||||||
535 | - | |||||||||||||
536 | QFileSystemModel *fsm = new QFileSystemModel(widget.filename); | - | ||||||||||||
537 | fsm->setRootPath(QDir::homePath()); | - | ||||||||||||
538 | widget.filename->setCompleter(new QCompleter(fsm, widget.filename)); | - | ||||||||||||
539 | - | |||||||||||||
540 | _q_printerChanged(currentPrinterIndex); | - | ||||||||||||
541 | - | |||||||||||||
542 | QObject::connect(widget.printers, qFlagLocation("2""currentIndexChanged(int)" "\0" __FILE__ ":" "678""682"), | - | ||||||||||||
543 | parent, qFlagLocation("1""_q_printerChanged(int)" "\0" __FILE__ ":" "679""683")); | - | ||||||||||||
544 | QObject::connect(widget.fileBrowser, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "680""684"), parent, qFlagLocation("1""_q_btnBrowseClicked()" "\0" __FILE__ ":" "680""684")); | - | ||||||||||||
545 | QObject::connect(widget.properties, qFlagLocation("2""clicked()" "\0" __FILE__ ":" "681""685"), parent, qFlagLocation("1""_q_btnPropertiesClicked()" "\0" __FILE__ ":" "681""685")); | - | ||||||||||||
546 | - | |||||||||||||
547 | - | |||||||||||||
548 | widget.preview->setVisible(false); | - | ||||||||||||
549 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
550 | - | |||||||||||||
551 | void QUnixPrintWidgetPrivate::updateWidget() | - | ||||||||||||
552 | { | - | ||||||||||||
553 | const bool printToFile = q == 0 || q->isOptionEnabled(QPrintDialog::PrintToFile); | - | ||||||||||||
554 | if (printToFile && !filePrintersAdded) { | - | ||||||||||||
555 | if (widget.printers->count()) | - | ||||||||||||
556 | widget.printers->insertSeparator(widget.printers->count()); | - | ||||||||||||
557 | widget.printers->addItem(QPrintDialog::tr("Print to File (PDF)")); | - | ||||||||||||
558 | filePrintersAdded = true; | - | ||||||||||||
559 | } | - | ||||||||||||
560 | if (!printToFile && filePrintersAdded) { | - | ||||||||||||
561 | widget.printers->removeItem(widget.printers->count()-1); | - | ||||||||||||
562 | widget.printers->removeItem(widget.printers->count()-1); | - | ||||||||||||
563 | if (widget.printers->count()) | - | ||||||||||||
564 | widget.printers->removeItem(widget.printers->count()-1); | - | ||||||||||||
565 | filePrintersAdded = false; | - | ||||||||||||
566 | } | - | ||||||||||||
567 | if (printer && filePrintersAdded && (printer->outputFormat() != QPrinter::NativeFormat | - | ||||||||||||
568 | || printer->printerName().isEmpty())) | - | ||||||||||||
569 | { | - | ||||||||||||
570 | if (printer->outputFormat() == QPrinter::PdfFormat) | - | ||||||||||||
571 | widget.printers->setCurrentIndex(widget.printers->count() - 1); | - | ||||||||||||
572 | widget.filename->setEnabled(true); | - | ||||||||||||
573 | widget.lOutput->setEnabled(true); | - | ||||||||||||
574 | } | - | ||||||||||||
575 | - | |||||||||||||
576 | widget.filename->setVisible(printToFile); | - | ||||||||||||
577 | widget.lOutput->setVisible(printToFile); | - | ||||||||||||
578 | widget.fileBrowser->setVisible(printToFile); | - | ||||||||||||
579 | - | |||||||||||||
580 | widget.properties->setVisible(q->isOptionEnabled(QAbstractPrintDialog::PrintShowPageSize)); | - | ||||||||||||
581 | } | - | ||||||||||||
582 | - | |||||||||||||
583 | QUnixPrintWidgetPrivate::~QUnixPrintWidgetPrivate() | - | ||||||||||||
584 | { | - | ||||||||||||
585 | } | - | ||||||||||||
586 | - | |||||||||||||
587 | void QUnixPrintWidgetPrivate::_q_printerChanged(int index) | - | ||||||||||||
588 | { | - | ||||||||||||
589 | if (index < 0) | - | ||||||||||||
590 | return; | - | ||||||||||||
591 | const int printerCount = widget.printers->count(); | - | ||||||||||||
592 | widget.filename->setEnabled(false); | - | ||||||||||||
593 | widget.lOutput->setEnabled(false); | - | ||||||||||||
594 | - | |||||||||||||
595 | - | |||||||||||||
596 | if (propertiesDialog){ | - | ||||||||||||
597 | delete propertiesDialog; | - | ||||||||||||
598 | propertiesDialog = 0; | - | ||||||||||||
599 | propertiesDialogShown = false; | - | ||||||||||||
600 | } | - | ||||||||||||
601 | - | |||||||||||||
602 | if (filePrintersAdded) { | - | ||||||||||||
603 | ((!(index != printerCount - 2)) ? qt_assert("index != printerCount - 2",__FILE__,739743) : qt_noop()); | - | ||||||||||||
604 | if (index == printerCount - 1) { | - | ||||||||||||
605 | widget.location->setText(QPrintDialog::tr("Local file")); | - | ||||||||||||
606 | widget.type->setText(QPrintDialog::tr("Write PDF file")); | - | ||||||||||||
607 | widget.properties->setEnabled(true); | - | ||||||||||||
608 | widget.filename->setEnabled(true); | - | ||||||||||||
609 | QString filename = widget.filename->text(); | - | ||||||||||||
610 | widget.filename->setText(filename); | - | ||||||||||||
611 | widget.lOutput->setEnabled(true); | - | ||||||||||||
612 | if (optionsPane) | - | ||||||||||||
613 | optionsPane->selectPrinter(QPrinter::PdfFormat); | - | ||||||||||||
614 | return; | - | ||||||||||||
615 | } | - | ||||||||||||
616 | } | - | ||||||||||||
617 | - | |||||||||||||
618 | if (printer) { | - | ||||||||||||
619 | QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get(); | - | ||||||||||||
620 | if (ps) | - | ||||||||||||
621 | m_currentPrintDevice = ps->createPrintDevice(widget.printers->itemText(index)); | - | ||||||||||||
622 | - | |||||||||||||
623 | printer->setPrinterName(m_currentPrintDevice.id()); | - | ||||||||||||
624 | - | |||||||||||||
625 | widget.location->setText(m_currentPrintDevice.location()); | - | ||||||||||||
626 | widget.type->setText(m_currentPrintDevice.makeAndModel()); | - | ||||||||||||
627 | if (optionsPane) | - | ||||||||||||
628 | optionsPane->selectPrinter(QPrinter::NativeFormat); | - | ||||||||||||
629 | } | - | ||||||||||||
630 | } | - | ||||||||||||
631 | - | |||||||||||||
632 | void QUnixPrintWidgetPrivate::setOptionsPane(QPrintDialogPrivate *pane) | - | ||||||||||||
633 | { | - | ||||||||||||
634 | optionsPane = pane; | - | ||||||||||||
635 | if (optionsPane) | - | ||||||||||||
636 | optionsPane->selectPrinter(QPrinter::NativeFormat); | - | ||||||||||||
637 | } | - | ||||||||||||
638 | - | |||||||||||||
639 | void QUnixPrintWidgetPrivate::_q_btnBrowseClicked() | - | ||||||||||||
640 | { | - | ||||||||||||
641 | QString filename = widget.filename->text(); | - | ||||||||||||
642 | - | |||||||||||||
643 | filename = QFileDialog::getSaveFileName(parent, QPrintDialog::tr("Print To File ..."), filename, | - | ||||||||||||
644 | QString(), 0, QFileDialog::DontConfirmOverwrite); | - | ||||||||||||
645 | - | |||||||||||||
646 | - | |||||||||||||
647 | - | |||||||||||||
648 | if (!filename.isEmpty()) { | - | ||||||||||||
649 | widget.filename->setText(filename); | - | ||||||||||||
650 | widget.printers->setCurrentIndex(widget.printers->count() - 1); | - | ||||||||||||
651 | } | - | ||||||||||||
652 | } | - | ||||||||||||
653 | - | |||||||||||||
654 | void QUnixPrintWidgetPrivate::applyPrinterProperties() | - | ||||||||||||
655 | { | - | ||||||||||||
656 | if (printer == 0
| 0-3 | ||||||||||||
657 | return; never executed: return; | 0 | ||||||||||||
658 | if (printer->outputFileName().isEmpty()
| 0-3 | ||||||||||||
659 | QString home = QDir::homePath(); | - | ||||||||||||
660 | QString cur = QDir::currentPath(); | - | ||||||||||||
661 | if (home.at(home.length()-1) != QLatin1Char('/')
| 0-3 | ||||||||||||
662 | home += QLatin1Char('/'); executed 3 times by 1 test: home += QLatin1Char('/'); Executed by:
| 3 | ||||||||||||
663 | if (!cur.isEmpty()
| 0-3 | ||||||||||||
664 | cur += QLatin1Char('/'); executed 3 times by 1 test: cur += QLatin1Char('/'); Executed by:
| 3 | ||||||||||||
665 | if (!cur.startsWith(home)
| 0-3 | ||||||||||||
666 | cur = home; never executed: cur = home; | 0 | ||||||||||||
667 | if (QGuiApplication::platformName() == QLatin1String("xcb")
| 0-3 | ||||||||||||
668 | if (printer->docName().isEmpty()
| 0-3 | ||||||||||||
669 | cur += QLatin1String("print.pdf"); | - | ||||||||||||
670 | } executed 3 times by 1 test: else {end of block Executed by:
| 3 | ||||||||||||
671 | QRegExp re(QString::fromLatin1("(.*)\\.\\S+")); | - | ||||||||||||
672 | if (re.exactMatch(printer->docName())
| 0 | ||||||||||||
673 | cur += re.cap(1); never executed: cur += re.cap(1); | 0 | ||||||||||||
674 | else | - | ||||||||||||
675 | cur += printer->docName(); never executed: cur += printer->docName(); | 0 | ||||||||||||
676 | cur += QLatin1String(".pdf"); | - | ||||||||||||
677 | } never executed: end of block | 0 | ||||||||||||
678 | } | - | ||||||||||||
679 | - | |||||||||||||
680 | widget.filename->setText(cur); | - | ||||||||||||
681 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
682 | else | - | ||||||||||||
683 | widget.filename->setText( printer->outputFileName() ); never executed: widget.filename->setText( printer->outputFileName() ); | 0 | ||||||||||||
684 | QString printerName = printer->printerName(); | - | ||||||||||||
685 | if (!printerName.isEmpty()
| 0-3 | ||||||||||||
686 | for (const int i = 0; i <widget.printers->count(); ++i) { | - | ||||||||||||
iffindText(widget.printers->itemTextprinterName); | ||||||||||||||
687 | if (i ) == printerName>= 0
| 0 | ||||||||||||
688 | {widget.printers->setCurrentIndex(i); never executed: widget.printers->setCurrentIndex(i); | 0 | ||||||||||||
689 | break; | 0 | ||||||||||||
} | ||||||||||||||
}} never executed: end of block | ||||||||||||||
690 | - | |||||||||||||
691 | - | |||||||||||||
692 | if (propertiesDialog
| 0-3 | ||||||||||||
693 | propertiesDialog->applyPrinterProperties(printer); never executed: propertiesDialog->applyPrinterProperties(printer); | 0 | ||||||||||||
694 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||
695 | - | |||||||||||||
696 | - | |||||||||||||
697 | bool QUnixPrintWidgetPrivate::checkFields() | - | ||||||||||||
698 | { | - | ||||||||||||
699 | if (widget.filename->isEnabled()) { | - | ||||||||||||
700 | QString file = widget.filename->text(); | - | ||||||||||||
701 | QFile f(file); | - | ||||||||||||
702 | QFileInfo fi(f); | - | ||||||||||||
703 | bool exists = fi.exists(); | - | ||||||||||||
704 | bool opened = false; | - | ||||||||||||
705 | if (exists && fi.isDir()) { | - | ||||||||||||
706 | QMessageBox::warning(q, q->windowTitle(), | - | ||||||||||||
707 | QPrintDialog::tr("%1 is a directory.\nPlease choose a different file name.").arg(file)); | - | ||||||||||||
708 | return false; | - | ||||||||||||
709 | } else if ((exists && !fi.isWritable()) || !(opened = f.open(QFile::Append))) { | - | ||||||||||||
710 | QMessageBox::warning(q, q->windowTitle(), | - | ||||||||||||
711 | QPrintDialog::tr("File %1 is not writable.\nPlease choose a different file name.").arg(file)); | - | ||||||||||||
712 | return false; | - | ||||||||||||
713 | } else if (exists) { | - | ||||||||||||
714 | int ret = QMessageBox::question(q, q->windowTitle(), | - | ||||||||||||
715 | QPrintDialog::tr("%1 already exists.\nDo you want to overwrite it?").arg(file), | - | ||||||||||||
716 | QMessageBox::Yes|QMessageBox::No, QMessageBox::No); | - | ||||||||||||
717 | if (ret == QMessageBox::No) | - | ||||||||||||
718 | return false; | - | ||||||||||||
719 | } | - | ||||||||||||
720 | if (opened) { | - | ||||||||||||
721 | f.close(); | - | ||||||||||||
722 | if (!exists) | - | ||||||||||||
723 | f.remove(); | - | ||||||||||||
724 | } | - | ||||||||||||
725 | } | - | ||||||||||||
726 | - | |||||||||||||
727 | - | |||||||||||||
728 | if (propertiesDialogShown) { | - | ||||||||||||
729 | QCUPSSupport::PagesPerSheet pagesPerSheet = propertiesDialog->widget.pageSetup->m_ui.pagesPerSheetCombo | - | ||||||||||||
730 | ->currentData().value<QCUPSSupport::PagesPerSheet>(); | - | ||||||||||||
731 | - | |||||||||||||
732 | QCUPSSupport::PageSet pageSet = optionsPane->options.pageSetCombo->currentData().value<QCUPSSupport::PageSet>(); | - | ||||||||||||
733 | - | |||||||||||||
734 | - | |||||||||||||
735 | if (pagesPerSheet != QCUPSSupport::OnePagePerSheet | - | ||||||||||||
736 | && pageSet != QCUPSSupport::AllPages) { | - | ||||||||||||
737 | QMessageBox::warning(q, q->windowTitle(), | - | ||||||||||||
738 | QPrintDialog::tr("Options 'Pages Per Sheet' and 'Page Set' cannot be used together.\nPlease turn one of those options off.")); | - | ||||||||||||
739 | return false; | - | ||||||||||||
740 | } | - | ||||||||||||
741 | } | - | ||||||||||||
742 | - | |||||||||||||
743 | - | |||||||||||||
744 | - | |||||||||||||
745 | return true; | - | ||||||||||||
746 | } | - | ||||||||||||
747 | - | |||||||||||||
748 | - | |||||||||||||
749 | void QUnixPrintWidgetPrivate::setupPrinterProperties() | - | ||||||||||||
750 | { | - | ||||||||||||
751 | if (propertiesDialog) | - | ||||||||||||
752 | delete propertiesDialog; | - | ||||||||||||
753 | - | |||||||||||||
754 | propertiesDialog = new QPrintPropertiesDialog(q); | - | ||||||||||||
755 | propertiesDialog->setResult(QDialog::Rejected); | - | ||||||||||||
756 | propertiesDialogShown = false; | - | ||||||||||||
757 | - | |||||||||||||
758 | propertiesDialog->applyPrinterProperties(q->printer()); | - | ||||||||||||
759 | - | |||||||||||||
760 | if (q->isOptionEnabled(QPrintDialog::PrintToFile) | - | ||||||||||||
761 | && (widget.printers->currentIndex() == widget.printers->count() - 1)) { | - | ||||||||||||
762 | propertiesDialog->selectPrinter(QPrinter::PdfFormat, QString()); | - | ||||||||||||
763 | } | - | ||||||||||||
764 | else | - | ||||||||||||
765 | propertiesDialog->selectPrinter(QPrinter::NativeFormat, widget.printers->currentText()); | - | ||||||||||||
766 | } | - | ||||||||||||
767 | - | |||||||||||||
768 | void QUnixPrintWidgetPrivate::_q_btnPropertiesClicked() | - | ||||||||||||
769 | { | - | ||||||||||||
770 | if (!propertiesDialog) | - | ||||||||||||
771 | setupPrinterProperties(); | - | ||||||||||||
772 | propertiesDialog->exec(); | - | ||||||||||||
773 | if (!propertiesDialogShown && propertiesDialog->result() == QDialog::Rejected) { | - | ||||||||||||
774 | - | |||||||||||||
775 | - | |||||||||||||
776 | delete propertiesDialog; | - | ||||||||||||
777 | propertiesDialog = 0; | - | ||||||||||||
778 | propertiesDialogShown = false; | - | ||||||||||||
779 | } else | - | ||||||||||||
780 | - | |||||||||||||
781 | propertiesDialogShown = true; | - | ||||||||||||
782 | } | - | ||||||||||||
783 | - | |||||||||||||
784 | void QUnixPrintWidgetPrivate::setupPrinter() | - | ||||||||||||
785 | { | - | ||||||||||||
786 | const int printerCount = widget.printers->count(); | - | ||||||||||||
787 | const int index = widget.printers->currentIndex(); | - | ||||||||||||
788 | - | |||||||||||||
789 | if (filePrintersAdded && index == printerCount - 1) { | - | ||||||||||||
790 | printer->setPrinterName(QString()); | - | ||||||||||||
791 | ((!(index != printerCount - 2)) ? qt_assert("index != printerCount - 2",__FILE__,930931) : qt_noop()); | - | ||||||||||||
792 | printer->setOutputFormat(QPrinter::PdfFormat); | - | ||||||||||||
793 | QString path = widget.filename->text(); | - | ||||||||||||
794 | if (QDir::isRelativePath(path)) | - | ||||||||||||
795 | path = QDir::homePath() + QDir::separator() + path; | - | ||||||||||||
796 | printer->setOutputFileName(path); | - | ||||||||||||
797 | } | - | ||||||||||||
798 | else { | - | ||||||||||||
799 | printer->setPrinterName(widget.printers->currentText()); | - | ||||||||||||
800 | printer->setOutputFileName(QString()); | - | ||||||||||||
801 | } | - | ||||||||||||
802 | - | |||||||||||||
803 | if (!propertiesDialog) | - | ||||||||||||
804 | setupPrinterProperties(); | - | ||||||||||||
805 | - | |||||||||||||
806 | if (propertiesDialog->result() == QDialog::Accepted || !propertiesDialogShown) | - | ||||||||||||
807 | propertiesDialog->setupPrinter(); | - | ||||||||||||
808 | } | - | ||||||||||||
809 | - | |||||||||||||
810 | - | |||||||||||||
811 | - | |||||||||||||
812 | QUnixPrintWidget::QUnixPrintWidget(QPrinter *printer, QWidget *parent) | - | ||||||||||||
813 | : QWidget(parent), d(new QUnixPrintWidgetPrivate(this, printer)) | - | ||||||||||||
814 | { | - | ||||||||||||
815 | d->applyPrinterProperties(); | - | ||||||||||||
816 | } | - | ||||||||||||
817 | - | |||||||||||||
818 | - | |||||||||||||
819 | - | |||||||||||||
820 | QUnixPrintWidget::~QUnixPrintWidget() | - | ||||||||||||
821 | { | - | ||||||||||||
822 | delete d; | - | ||||||||||||
823 | } | - | ||||||||||||
824 | - | |||||||||||||
825 | - | |||||||||||||
826 | - | |||||||||||||
827 | - | |||||||||||||
828 | - | |||||||||||||
829 | void QUnixPrintWidget::updatePrinter() | - | ||||||||||||
830 | { | - | ||||||||||||
831 | d->setupPrinter(); | - | ||||||||||||
832 | } | - | ||||||||||||
833 | - | |||||||||||||
834 | - | |||||||||||||
835 | - | |||||||||||||
836 | - | |||||||||||||
837 | - | |||||||||||||
838 | - | |||||||||||||
839 | - | |||||||||||||
840 | - | |||||||||||||
Switch to Source code | Preprocessed file |