Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | #include "qpagesetupdialog.h" | - |
41 | | - |
42 | #ifndef QT_NO_PRINTDIALOG | - |
43 | #include "qpagesetupdialog_unix_p.h" | - |
44 | | - |
45 | #include <private/qpagesetupdialog_p.h> | - |
46 | #include <private/qprintdevice_p.h> | - |
47 | #include <private/qcups_p.h> | - |
48 | | - |
49 | #include "qpainter.h" | - |
50 | #include "qprintdialog.h" | - |
51 | #include "qdialogbuttonbox.h" | - |
52 | #include <ui_qpagesetupwidget.h> | - |
53 | | - |
54 | #include <QtPrintSupport/qprinter.h> | - |
55 | | - |
56 | #include <qpa/qplatformprintplugin.h> | - |
57 | #include <qpa/qplatformprintersupport.h> | - |
58 | | - |
59 | QT_BEGIN_NAMESPACE | - |
60 | | - |
61 | | - |
62 | | - |
63 | | - |
64 | #ifdef PSD_ENABLE_PAPERSOURCE | - |
65 | static const char *paperSourceNames[] = { | - |
66 | "Only One", | - |
67 | "Lower", | - |
68 | "Middle", | - |
69 | "Manual", | - |
70 | "Envelope", | - |
71 | "Envelope manual", | - |
72 | "Auto", | - |
73 | "Tractor", | - |
74 | "Small format", | - |
75 | "Large format", | - |
76 | "Large capacity", | - |
77 | "Cassette", | - |
78 | "Form source", | - |
79 | 0 | - |
80 | }; | - |
81 | | - |
82 | struct PaperSourceNames | - |
83 | { | - |
84 | PaperSourceNames(const char *nam, QPrinter::PaperSource ps) | - |
85 | : paperSource(ps), name(nam) {} | - |
86 | QPrinter::PaperSource paperSource; | - |
87 | const char *name; | - |
88 | }; | - |
89 | #endif | - |
90 | | - |
91 | | - |
92 | | - |
93 | | - |
94 | | - |
95 | | - |
96 | class QPagePreview : public QWidget | - |
97 | { | - |
98 | public: | - |
99 | QPagePreview(QWidget *parent) : QWidget(parent) | - |
100 | { | - |
101 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | - |
102 | setMinimumSize(50, 50); | - |
103 | } | - |
104 | | - |
105 | void setPageLayout(const QPageLayout &layout) | - |
106 | { | - |
107 | m_pageLayout = layout; | - |
108 | update(); | - |
109 | } | - |
110 | | - |
111 | void setPagePreviewLayout(int columns, int rows) | - |
112 | { | - |
113 | m_pagePreviewColumns = columns; | - |
114 | m_pagePreviewRows = rows; | - |
115 | update(); | - |
116 | } | - |
117 | | - |
118 | protected: | - |
119 | void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE | - |
120 | { | - |
121 | QSize pageSize = m_pageLayout.fullRectPoints().size(); | - |
122 | QSizeF scaledSize = pageSize.scaled(width() - 10, height() - 10, Qt::KeepAspectRatio); | - |
123 | QRect pageRect = QRect(QPoint(0,0), scaledSize.toSize()); | - |
124 | pageRect.moveCenter(rect().center()); | - |
125 | qreal width_factor = scaledSize.width() / pageSize.width(); | - |
126 | qreal height_factor = scaledSize.height() / pageSize.height(); | - |
127 | QMarginsF margins = m_pageLayout.margins(QPageLayout::Point); | - |
128 | int left = qRound(margins.left() * width_factor); | - |
129 | int top = qRound(margins.top() * height_factor); | - |
130 | int right = qRound(margins.right() * width_factor); | - |
131 | int bottom = qRound(margins.bottom() * height_factor); | - |
132 | QRect marginRect(pageRect.x() + left, pageRect.y() + top, | - |
133 | pageRect.width() - (left + right + 1), pageRect.height() - (top + bottom + 1)); | - |
134 | | - |
135 | QPainter p(this); | - |
136 | QColor shadow(palette().mid().color()); | - |
137 | for (int i=1; i<6; ++i) { | - |
138 | shadow.setAlpha(180-i*30); | - |
139 | QRect offset(pageRect.adjusted(i, i, i, i)); | - |
140 | p.setPen(shadow); | - |
141 | p.drawLine(offset.left(), offset.bottom(), offset.right(), offset.bottom()); | - |
142 | p.drawLine(offset.right(), offset.top(), offset.right(), offset.bottom()-1); | - |
143 | } | - |
144 | p.fillRect(pageRect, palette().light()); | - |
145 | | - |
146 | if (marginRect.isValid()) { | - |
147 | p.setPen(QPen(palette().color(QPalette::Dark), 0, Qt::DotLine)); | - |
148 | p.drawRect(marginRect); | - |
149 | | - |
150 | marginRect.adjust(2, 2, -1, -1); | - |
151 | p.setClipRect(marginRect); | - |
152 | QFont font; | - |
153 | font.setPointSizeF(font.pointSizeF()*0.25); | - |
154 | p.setFont(font); | - |
155 | p.setPen(palette().color(QPalette::Dark)); | - |
156 | QString text(QLatin1String("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.")); | - |
157 | for (int i=0; i<3; ++i) | - |
158 | text += text; | - |
159 | | - |
160 | const int spacing = pageRect.width() * 0.1; | - |
161 | const int textWidth = (marginRect.width() - (spacing * (m_pagePreviewColumns-1))) / m_pagePreviewColumns; | - |
162 | const int textHeight = (marginRect.height() - (spacing * (m_pagePreviewRows-1))) / m_pagePreviewRows; | - |
163 | | - |
164 | for (int x = 0 ; x < m_pagePreviewColumns; ++x) { | - |
165 | for (int y = 0 ; y < m_pagePreviewRows; ++y) { | - |
166 | QRect textRect(marginRect.left() + x * (textWidth + spacing), | - |
167 | marginRect.top() + y * (textHeight + spacing), | - |
168 | textWidth, textHeight); | - |
169 | p.drawText(textRect, Qt::TextWordWrap|Qt::AlignVCenter, text); | - |
170 | } | - |
171 | } | - |
172 | } | - |
173 | } | - |
174 | | - |
175 | private: | - |
176 | | - |
177 | QPageLayout m_pageLayout; | - |
178 | | - |
179 | int m_pagePreviewColumns, m_pagePreviewRows; | - |
180 | }; | - |
181 | | - |
182 | | - |
183 | | - |
184 | | - |
185 | | - |
186 | | - |
187 | class QUnixPageSetupDialogPrivate : public QPageSetupDialogPrivate | - |
188 | { | - |
189 | Q_DECLARE_PUBLIC(QPageSetupDialog) | - |
190 | | - |
191 | public: | - |
192 | QUnixPageSetupDialogPrivate(QPrinter *printer); | - |
193 | ~QUnixPageSetupDialogPrivate(); | - |
194 | void init(); | - |
195 | | - |
196 | QPageSetupWidget *widget; | - |
197 | }; | - |
198 | | - |
199 | QUnixPageSetupDialogPrivate::QUnixPageSetupDialogPrivate(QPrinter *printer) : QPageSetupDialogPrivate(printer) | - |
200 | { | - |
201 | } | - |
202 | | - |
203 | QUnixPageSetupDialogPrivate::~QUnixPageSetupDialogPrivate() | - |
204 | { | - |
205 | } | - |
206 | | - |
207 | void QUnixPageSetupDialogPrivate::init() | - |
208 | { | - |
209 | Q_Q(QPageSetupDialog); | - |
210 | | - |
211 | widget = new QPageSetupWidget(q); | - |
212 | widget->setPrinter(printer); | - |
213 | | - |
214 | QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | - |
215 | | QDialogButtonBox::Cancel, | - |
216 | Qt::Horizontal, q); | - |
217 | QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(accept())); | - |
218 | QObject::connect(buttons, SIGNAL(rejected()), q, SLOT(reject())); | - |
219 | | - |
220 | QVBoxLayout *lay = new QVBoxLayout(q); | - |
221 | lay->addWidget(widget); | - |
222 | lay->addWidget(buttons); | - |
223 | } | - |
224 | | - |
225 | | - |
226 | | - |
227 | | - |
228 | | - |
229 | | - |
230 | QPageSetupWidget::QPageSetupWidget(QWidget *parent) | - |
231 | : QWidget(parent), | - |
232 | m_pagePreview(0), | - |
233 | m_printer(0), | - |
234 | m_outputFormat(QPrinter::PdfFormat), | - |
235 | m_units(QPageLayout::Point), | - |
236 | m_blockSignals(false) | - |
237 | { | - |
238 | m_ui.setupUi(this); | - |
239 | | - |
240 | QVBoxLayout *lay = new QVBoxLayout(m_ui.preview); | - |
241 | m_ui.preview->setLayout(lay); | - |
242 | m_pagePreview = new QPagePreview(m_ui.preview); | - |
243 | m_pagePreview->setPagePreviewLayout(1, 1); | - |
244 | | - |
245 | lay->addWidget(m_pagePreview); | - |
246 | | - |
247 | setAttribute(Qt::WA_WState_Polished, false); | - |
248 | | - |
249 | #ifdef PSD_ENABLE_PAPERSOURCE | - |
250 | for (int i=0; paperSourceNames[i]; ++i) | - |
251 | m_ui.paperSource->insertItem(paperSourceNames[i]); | - |
252 | #else | - |
253 | m_ui.paperSourceLabel->setVisible(false); | - |
254 | m_ui.paperSource->setVisible(false); | - |
255 | #endif | - |
256 | | - |
257 | m_ui.reverseLandscape->setVisible(false); | - |
258 | m_ui.reversePortrait->setVisible(false); | - |
259 | | - |
260 | initUnits(); | - |
261 | initPagesPerSheet(); | - |
262 | | - |
263 | connect(m_ui.unitCombo, SIGNAL(activated(int)), this, SLOT(unitChanged())); | - |
264 | | - |
265 | connect(m_ui.pageSizeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(pageSizeChanged())); | - |
266 | connect(m_ui.pageWidth, SIGNAL(valueChanged(double)), this, SLOT(pageSizeChanged())); | - |
267 | connect(m_ui.pageHeight, SIGNAL(valueChanged(double)), this, SLOT(pageSizeChanged())); | - |
268 | | - |
269 | connect(m_ui.leftMargin, SIGNAL(valueChanged(double)), this, SLOT(leftMarginChanged(double))); | - |
270 | connect(m_ui.topMargin, SIGNAL(valueChanged(double)), this, SLOT(topMarginChanged(double))); | - |
271 | connect(m_ui.rightMargin, SIGNAL(valueChanged(double)), this, SLOT(rightMarginChanged(double))); | - |
272 | connect(m_ui.bottomMargin, SIGNAL(valueChanged(double)), this, SLOT(bottomMarginChanged(double))); | - |
273 | | - |
274 | connect(m_ui.portrait, SIGNAL(clicked()), this, SLOT(pageOrientationChanged())); | - |
275 | connect(m_ui.landscape, SIGNAL(clicked()), this, SLOT(pageOrientationChanged())); | - |
276 | | - |
277 | connect(m_ui.pagesPerSheetCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(pagesPerSheetChanged())); | - |
278 | } | - |
279 | | - |
280 | | - |
281 | void QPageSetupWidget::initUnits() | - |
282 | { | - |
283 | m_ui.unitCombo->addItem(tr("Millimeters (mm)"), QVariant::fromValue(QPageLayout::Millimeter)); | - |
284 | m_ui.unitCombo->addItem(tr("Inches (in)"), QVariant::fromValue(QPageLayout::Inch)); | - |
285 | m_ui.unitCombo->addItem(tr("Points (pt)"), QVariant::fromValue(QPageLayout::Point)); | - |
286 | m_ui.unitCombo->addItem(tr("Pica (P̸)"), QVariant::fromValue(QPageLayout::Pica)); | - |
287 | m_ui.unitCombo->addItem(tr("Didot (DD)"), QVariant::fromValue(QPageLayout::Didot)); | - |
288 | m_ui.unitCombo->addItem(tr("Cicero (CC)"), QVariant::fromValue(QPageLayout::Cicero)); | - |
289 | | - |
290 | | - |
291 | m_ui.unitCombo->setCurrentIndex(QLocale().measurementSystem() != QLocale::MetricSystem); | - |
292 | } | - |
293 | | - |
294 | | - |
295 | void QPageSetupWidget::initPagesPerSheet() | - |
296 | { | - |
297 | #if !defined(QT_NO_CUPS) | - |
298 | m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Left to Right, Top to Bottom"), | - |
299 | QVariant::fromValue(QCUPSSupport::LeftToRightTopToBottom)); | - |
300 | m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Left to Right, Bottom to Top"), | - |
301 | QVariant::fromValue(QCUPSSupport::LeftToRightBottomToTop)); | - |
302 | m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Right to Left, Bottom to Top"), | - |
303 | QVariant::fromValue(QCUPSSupport::RightToLeftBottomToTop)); | - |
304 | m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Right to Left, Top to Bottom"), | - |
305 | QVariant::fromValue(QCUPSSupport::RightToLeftTopToBottom)); | - |
306 | m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Bottom to Top, Left to Right"), | - |
307 | QVariant::fromValue(QCUPSSupport::BottomToTopLeftToRight)); | - |
308 | m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Bottom to Top, Right to Left"), | - |
309 | QVariant::fromValue(QCUPSSupport::BottomToTopRightToLeft)); | - |
310 | m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Top to Bottom, Left to Right"), | - |
311 | QVariant::fromValue(QCUPSSupport::TopToBottomLeftToRight)); | - |
312 | m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Top to Bottom, Right to Left"), | - |
313 | QVariant::fromValue(QCUPSSupport::TopToBottomRightToLeft)); | - |
314 | | - |
315 | m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("1 (1x1)"), | - |
316 | QVariant::fromValue(QCUPSSupport::OnePagePerSheet)); | - |
317 | m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("2 (2x1)"), | - |
318 | QVariant::fromValue(QCUPSSupport::TwoPagesPerSheet)); | - |
319 | m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("4 (2x2)"), | - |
320 | QVariant::fromValue(QCUPSSupport::FourPagesPerSheet)); | - |
321 | m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("6 (2x3)"), | - |
322 | QVariant::fromValue(QCUPSSupport::SixPagesPerSheet)); | - |
323 | m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("9 (3x3)"), | - |
324 | QVariant::fromValue(QCUPSSupport::NinePagesPerSheet)); | - |
325 | m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("16 (4x4)"), | - |
326 | QVariant::fromValue(QCUPSSupport::SixteenPagesPerSheet)); | - |
327 | | - |
328 | | - |
329 | m_ui.pagesPerSheetCombo->setCurrentIndex(0); | - |
330 | | - |
331 | m_ui.pagesPerSheetLayoutCombo->setCurrentIndex(0); | - |
332 | #else | - |
333 | | - |
334 | m_ui.pagesPerSheetButtonGroup->hide(); | - |
335 | #endif | - |
336 | } | - |
337 | | - |
338 | void QPageSetupWidget::initPageSizes() | - |
339 | { | - |
340 | m_blockSignals = true; | - |
341 | | - |
342 | m_ui.pageSizeCombo->clear(); | - |
343 | | - |
344 | if (m_outputFormat == QPrinter::NativeFormat && !m_printerName.isEmpty()) {TRUE | never evaluated | FALSE | evaluated 1 time by 1 test |
TRUE | never evaluated | FALSE | never evaluated |
| 0-1 |
345 | QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get(); | - |
346 | if (ps) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
347 | QPrintDevice printDevice = ps->createPrintDevice(m_printerName); | - |
348 | foreach (const QPageSize &pageSize,auto pageSizes = printDevice.supportedPageSizes()) {(); | - |
349 | for (const QPageSize &pageSize : pageSizes) | - |
350 | m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize.id()));} never executed: m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize.id())); | 0 |
351 | if (m_ui.pageSizeCombo->count() > 0 && printDevice.supportsCustomPageSizes()) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
352 | m_ui.pageSizeCombo->addItem(tr("Custom"), QVariant::fromValue(QPageSize::Custom)); | - |
353 | m_blockSignals = false; | - |
354 | return; never executed: return; | 0 |
355 | } | - |
356 | } never executed: end of block | 0 |
357 | } never executed: end of block | 0 |
358 | | - |
359 | | - |
360 | for (int id = 0; id < QPageSize::LastPageSize; ++id) {TRUE | evaluated 118 times by 1 test | FALSE | evaluated 1 time by 1 test |
| 1-118 |
361 | if (QPageSize::PageSizeId(id) == QPageSize::Custom) {TRUE | evaluated 1 time by 1 test | FALSE | evaluated 117 times by 1 test |
| 1-117 |
362 | m_ui.pageSizeCombo->addItem(tr("Custom"), QVariant::fromValue(QPageSize::Custom)); | - |
363 | } else {executed 1 time by 1 test: end of block | 1 |
364 | QPageSize pageSize = QPageSize(QPageSize::PageSizeId(id)); | - |
365 | m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize.id())); | - |
366 | }executed 117 times by 1 test: end of block | 117 |
367 | } | - |
368 | | - |
369 | m_blockSignals = false; | - |
370 | }executed 1 time by 1 test: end of block | 1 |
371 | | - |
372 | | - |
373 | | - |
374 | void QPageSetupWidget::setPrinter(QPrinter *printer) | - |
375 | { | - |
376 | m_printer = printer; | - |
377 | | - |
378 | | - |
379 | m_pageLayout = m_printer->pageLayout(); | - |
380 | | - |
381 | if (m_pageLayout.units() == QPageLayout::Point) { | - |
382 | if (QLocale().measurementSystem() == QLocale::MetricSystem) | - |
383 | m_pageLayout.setUnits(QPageLayout::Millimeter); | - |
384 | else | - |
385 | m_pageLayout.setUnits(QPageLayout::Inch); | - |
386 | } | - |
387 | m_units = m_pageLayout.units(); | - |
388 | m_pagePreview->setPageLayout(m_pageLayout); | - |
389 | | - |
390 | | - |
391 | selectPrinter(m_printer->outputFormat(), m_printer->printerName()); | - |
392 | } | - |
393 | | - |
394 | | - |
395 | | - |
396 | void QPageSetupWidget::selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName) | - |
397 | { | - |
398 | m_outputFormat = outputFormat; | - |
399 | m_printerName = printerName; | - |
400 | initPageSizes(); | - |
401 | updateWidget(); | - |
402 | } | - |
403 | | - |
404 | | - |
405 | | - |
406 | void QPageSetupWidget::updateWidget() | - |
407 | { | - |
408 | m_blockSignals = true; | - |
409 | | - |
410 | QString suffix; | - |
411 | switch (m_units) { | - |
412 | case QPageLayout::Millimeter: | - |
413 | | - |
414 | suffix = tr("mm"); | - |
415 | break; | - |
416 | case QPageLayout::Point: | - |
417 | | - |
418 | suffix = tr("pt"); | - |
419 | break; | - |
420 | case QPageLayout::Inch: | - |
421 | | - |
422 | suffix = tr("in"); | - |
423 | break; | - |
424 | case QPageLayout::Pica: | - |
425 | | - |
426 | suffix = tr("P̸"); | - |
427 | break; | - |
428 | case QPageLayout::Didot: | - |
429 | | - |
430 | suffix = tr("DD"); | - |
431 | break; | - |
432 | case QPageLayout::Cicero: | - |
433 | | - |
434 | suffix = tr("CC"); | - |
435 | break; | - |
436 | } | - |
437 | | - |
438 | m_ui.unitCombo->setCurrentIndex(m_ui.unitCombo->findData(QVariant::fromValue(m_units))); | - |
439 | | - |
440 | m_ui.pageSizeCombo->setCurrentIndex(m_ui.pageSizeCombo->findData(QVariant::fromValue(m_pageLayout.pageSize().id()))); | - |
441 | | - |
442 | QMarginsF min; | - |
443 | QMarginsF max; | - |
444 | | - |
445 | if (m_pageLayout.mode() == QPageLayout::FullPageMode) { | - |
446 | min = QMarginsF(0.0, 0.0, 0.0, 0.0); | - |
447 | max = QMarginsF(9999.9999, 9999.9999, 9999.9999, 9999.9999); | - |
448 | } else { | - |
449 | min = m_pageLayout.minimumMargins(); | - |
450 | max = m_pageLayout.maximumMargins(); | - |
451 | } | - |
452 | | - |
453 | m_ui.leftMargin->setSuffix(suffix); | - |
454 | m_ui.leftMargin->setMinimum(min.left()); | - |
455 | m_ui.leftMargin->setMaximum(max.left()); | - |
456 | m_ui.leftMargin->setValue(m_pageLayout.margins().left()); | - |
457 | | - |
458 | m_ui.rightMargin->setSuffix(suffix); | - |
459 | m_ui.rightMargin->setMinimum(min.right()); | - |
460 | m_ui.rightMargin->setMaximum(max.right()); | - |
461 | m_ui.rightMargin->setValue(m_pageLayout.margins().right()); | - |
462 | | - |
463 | m_ui.topMargin->setSuffix(suffix); | - |
464 | m_ui.topMargin->setMinimum(min.top()); | - |
465 | m_ui.topMargin->setMaximum(max.top()); | - |
466 | m_ui.topMargin->setValue(m_pageLayout.margins().top()); | - |
467 | | - |
468 | m_ui.bottomMargin->setSuffix(suffix); | - |
469 | m_ui.bottomMargin->setMinimum(min.bottom()); | - |
470 | m_ui.bottomMargin->setMaximum(max.bottom()); | - |
471 | m_ui.bottomMargin->setValue(m_pageLayout.margins().bottom()); | - |
472 | | - |
473 | bool isCustom = m_ui.pageSizeCombo->currentData().value<QPageSize::PageSizeId>() == QPageSize::Custom; | - |
474 | | - |
475 | m_ui.pageWidth->setSuffix(suffix); | - |
476 | m_ui.pageWidth->setValue(m_pageLayout.fullRect(m_units).width()); | - |
477 | m_ui.pageWidth->setEnabled(isCustom); | - |
478 | m_ui.widthLabel->setEnabled(isCustom); | - |
479 | | - |
480 | m_ui.pageHeight->setSuffix(suffix); | - |
481 | m_ui.pageHeight->setValue(m_pageLayout.fullRect(m_units).height()); | - |
482 | m_ui.pageHeight->setEnabled(isCustom); | - |
483 | m_ui.heightLabel->setEnabled(isCustom); | - |
484 | | - |
485 | m_ui.landscape->setChecked(m_pageLayout.orientation() == QPageLayout::Landscape); | - |
486 | | - |
487 | m_ui.pagesPerSheetButtonGroup->setEnabled(m_outputFormat == QPrinter::NativeFormat); | - |
488 | | - |
489 | #ifdef PSD_ENABLE_PAPERSOURCE | - |
490 | m_ui.paperSource->setCurrentItem(printer->paperSource()); | - |
491 | #endif | - |
492 | | - |
493 | m_blockSignals = false; | - |
494 | } | - |
495 | | - |
496 | | - |
497 | | - |
498 | void QPageSetupWidget::setupPrinter() const | - |
499 | { | - |
500 | m_printer->setPageLayout(m_pageLayout); | - |
501 | #if !defined(QT_NO_CUPS) | - |
502 | QCUPSSupport::PagesPerSheet pagesPerSheet = m_ui.pagesPerSheetCombo->currentData() | - |
503 | .value<QCUPSSupport::PagesPerSheet>(); | - |
504 | QCUPSSupport::PagesPerSheetLayout pagesPerSheetLayout = m_ui.pagesPerSheetLayoutCombo->currentData() | - |
505 | .value<QCUPSSupport::PagesPerSheetLayout>(); | - |
506 | QCUPSSupport::setPagesPerSheetLayout(m_printer, pagesPerSheet, pagesPerSheetLayout); | - |
507 | #endif | - |
508 | #ifdef PSD_ENABLE_PAPERSOURCE | - |
509 | m_printer->setPaperSource((QPrinter::PaperSource)m_ui.paperSource->currentIndex()); | - |
510 | #endif | - |
511 | } | - |
512 | | - |
513 | | - |
514 | void QPageSetupWidget::pageSizeChanged() | - |
515 | { | - |
516 | if (m_blockSignals) | - |
517 | return; | - |
518 | | - |
519 | QPageSize::PageSizeId id = m_ui.pageSizeCombo->currentData().value<QPageSize::PageSizeId>(); | - |
520 | if (id != QPageSize::Custom) { | - |
521 | | - |
522 | m_pageLayout.setPageSize(QPageSize(id)); | - |
523 | } else { | - |
524 | QSizeF customSize; | - |
525 | if (m_pageLayout.orientation() == QPageLayout::Landscape) | - |
526 | customSize = QSizeF(m_ui.pageHeight->value(), m_ui.pageWidth->value()); | - |
527 | else | - |
528 | customSize = QSizeF(m_ui.pageWidth->value(), m_ui.pageHeight->value()); | - |
529 | | - |
530 | m_pageLayout.setPageSize(QPageSize(customSize, QPageSize::Unit(m_units))); | - |
531 | } | - |
532 | m_pagePreview->setPageLayout(m_pageLayout); | - |
533 | | - |
534 | updateWidget(); | - |
535 | } | - |
536 | | - |
537 | void QPageSetupWidget::pageOrientationChanged() | - |
538 | { | - |
539 | if (m_blockSignals) | - |
540 | return; | - |
541 | m_pageLayout.setOrientation(m_ui.portrait->isChecked() ? QPageLayout::Portrait : QPageLayout::Landscape); | - |
542 | m_pagePreview->setPageLayout(m_pageLayout); | - |
543 | updateWidget(); | - |
544 | } | - |
545 | | - |
546 | void QPageSetupWidget::pagesPerSheetChanged() | - |
547 | { | - |
548 | #if !defined(QT_NO_CUPS) | - |
549 | switch (m_ui.pagesPerSheetCombo->currentData().toInt()) { | - |
550 | case QCUPSSupport::OnePagePerSheet: | - |
551 | m_pagePreview->setPagePreviewLayout(1, 1); | - |
552 | break; | - |
553 | case QCUPSSupport::TwoPagesPerSheet: | - |
554 | m_pagePreview->setPagePreviewLayout(1, 2); | - |
555 | break; | - |
556 | case QCUPSSupport::FourPagesPerSheet: | - |
557 | m_pagePreview->setPagePreviewLayout(2, 2); | - |
558 | break; | - |
559 | case QCUPSSupport::SixPagesPerSheet: | - |
560 | m_pagePreview->setPagePreviewLayout(3, 2); | - |
561 | break; | - |
562 | case QCUPSSupport::NinePagesPerSheet: | - |
563 | m_pagePreview->setPagePreviewLayout(3, 3); | - |
564 | break; | - |
565 | case QCUPSSupport::SixteenPagesPerSheet: | - |
566 | m_pagePreview->setPagePreviewLayout(4, 4); | - |
567 | break; | - |
568 | } | - |
569 | #endif | - |
570 | } | - |
571 | | - |
572 | void QPageSetupWidget::unitChanged() | - |
573 | { | - |
574 | if (m_blockSignals) | - |
575 | return; | - |
576 | m_units = m_ui.unitCombo->currentData().value<QPageLayout::Unit>(); | - |
577 | m_pageLayout.setUnits(m_units); | - |
578 | updateWidget(); | - |
579 | } | - |
580 | | - |
581 | void QPageSetupWidget::topMarginChanged(double newValue) | - |
582 | { | - |
583 | if (m_blockSignals) | - |
584 | return; | - |
585 | m_pageLayout.setTopMargin(newValue); | - |
586 | m_pagePreview->setPageLayout(m_pageLayout); | - |
587 | } | - |
588 | | - |
589 | void QPageSetupWidget::bottomMarginChanged(double newValue) | - |
590 | { | - |
591 | if (m_blockSignals) | - |
592 | return; | - |
593 | m_pageLayout.setBottomMargin(newValue); | - |
594 | m_pagePreview->setPageLayout(m_pageLayout); | - |
595 | } | - |
596 | | - |
597 | void QPageSetupWidget::leftMarginChanged(double newValue) | - |
598 | { | - |
599 | if (m_blockSignals) | - |
600 | return; | - |
601 | m_pageLayout.setLeftMargin(newValue); | - |
602 | m_pagePreview->setPageLayout(m_pageLayout); | - |
603 | } | - |
604 | | - |
605 | void QPageSetupWidget::rightMarginChanged(double newValue) | - |
606 | { | - |
607 | if (m_blockSignals) | - |
608 | return; | - |
609 | m_pageLayout.setRightMargin(newValue); | - |
610 | m_pagePreview->setPageLayout(m_pageLayout); | - |
611 | } | - |
612 | | - |
613 | | - |
614 | | - |
615 | | - |
616 | QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent) | - |
617 | : QDialog(*(new QUnixPageSetupDialogPrivate(printer)), parent) | - |
618 | { | - |
619 | Q_D(QPageSetupDialog); | - |
620 | setWindowTitle(QCoreApplication::translate("QPrintPreviewDialog", "Page Setup")); | - |
621 | static_cast<QUnixPageSetupDialogPrivate *>(d)->init(); | - |
622 | } | - |
623 | | - |
624 | QPageSetupDialog::QPageSetupDialog(QWidget *parent) | - |
625 | : QDialog(*(new QUnixPageSetupDialogPrivate(0)), parent) | - |
626 | { | - |
627 | Q_D(QPageSetupDialog); | - |
628 | setWindowTitle(QCoreApplication::translate("QPrintPreviewDialog", "Page Setup")); | - |
629 | static_cast<QUnixPageSetupDialogPrivate *>(d)->init(); | - |
630 | } | - |
631 | | - |
632 | int QPageSetupDialog::exec() | - |
633 | { | - |
634 | Q_D(QPageSetupDialog); | - |
635 | | - |
636 | int ret = QDialog::exec(); | - |
637 | if (ret == Accepted) | - |
638 | static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->setupPrinter(); | - |
639 | return ret; | - |
640 | } | - |
641 | | - |
642 | QT_END_NAMESPACE | - |
643 | | - |
644 | #include "moc_qpagesetupdialog.cpp" | - |
645 | | - |
646 | #endif // QT_NO_PRINTDIALOG | - |
| | |