OpenCoverage

qpagesetupdialog_unix.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/printsupport/dialogs/qpagesetupdialog_unix.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 "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-
59QT_BEGIN_NAMESPACE-
60-
61// Disabled until we have support for papersources on unix-
62// #define PSD_ENABLE_PAPERSOURCE-
63-
64#ifdef PSD_ENABLE_PAPERSOURCE-
65static 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-
82struct 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// QPagePreview-
93// - Private widget to display preview of page layout-
94// - Embedded in QPageSetupWidget-
95-
96class QPagePreview : public QWidget-
97{-
98public:-
99 QPagePreview(QWidget *parent) : QWidget(parent)-
100 {-
101 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);-
102 setMinimumSize(50, 50);-
103 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
104-
105 void setPageLayout(const QPageLayout &layout)-
106 {-
107 m_pageLayout = layout;-
108 update();-
109 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
110-
111 void setPagePreviewLayout(int columns, int rows)-
112 {-
113 m_pagePreviewColumns = columns;-
114 m_pagePreviewRows = rows;-
115 update();-
116 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
117-
118protected:-
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) {
i<6Description
TRUEnever evaluated
FALSEnever evaluated
0
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 }
never executed: end of block
0
144 p.fillRect(pageRect, palette().light());-
145-
146 if (marginRect.isValid()) {
marginRect.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
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)
i<3Description
TRUEnever evaluated
FALSEnever evaluated
0
158 text += text;
never executed: text += text;
0
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) {
x < m_pagePreviewColumnsDescription
TRUEnever evaluated
FALSEnever evaluated
0
165 for (int y = 0 ; y < m_pagePreviewRows; ++y) {
y < m_pagePreviewRowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
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 }
never executed: end of block
0
171 }
never executed: end of block
0
172 }
never executed: end of block
0
173 }
never executed: end of block
0
174-
175private:-
176 // Page Layout-
177 QPageLayout m_pageLayout;-
178 // Pages Per Sheet / n-up layout-
179 int m_pagePreviewColumns, m_pagePreviewRows;-
180};-
181-
182-
183// QUnixPageSetupDialogPrivate-
184// - Linux / Cups implementation of QPageSetupDialogPrivate-
185// - Embeds QPageSetupWidget-
186-
187class QUnixPageSetupDialogPrivate : public QPageSetupDialogPrivate-
188{-
189 Q_DECLARE_PUBLIC(QPageSetupDialog)-
190-
191public:-
192 QUnixPageSetupDialogPrivate(QPrinter *printer);-
193 ~QUnixPageSetupDialogPrivate();-
194 void init();-
195-
196 QPageSetupWidget *widget;-
197};-
198-
199QUnixPageSetupDialogPrivate::QUnixPageSetupDialogPrivate(QPrinter *printer) : QPageSetupDialogPrivate(printer)-
200{-
201}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
202-
203QUnixPageSetupDialogPrivate::~QUnixPageSetupDialogPrivate()-
204{-
205}-
206-
207void 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}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
224-
225// QPageSetupWidget-
226// - Private widget implementation for Linux / CUPS-
227// - Embeds QPagePreview-
228// - TODO Could be made public as a stand-alone widget?-
229-
230QPageSetupWidget::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}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
279-
280// Init the Units combo box-
281void 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 // Initailly default to locale measurement system, mm if metric, in otherwise-
291 m_ui.unitCombo->setCurrentIndex(QLocale().measurementSystem() != QLocale::MetricSystem);-
292}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
293-
294// Init the Pages Per Sheet (n-up) combo boxes if using CUPS-
295void 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 // Set to QCUPSSupport::OnePagePerSheet-
329 m_ui.pagesPerSheetCombo->setCurrentIndex(0);-
330 // Set to QCUPSSupport::LeftToRightTopToBottom-
331 m_ui.pagesPerSheetLayoutCombo->setCurrentIndex(0);-
332#else-
333 // Disable if CUPS wasn't found-
334 m_ui.pagesPerSheetButtonGroup->hide();-
335#endif-
336}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
337-
338void QPageSetupWidget::initPageSizes()-
339{-
340 m_blockSignals = true;-
341-
342 m_ui.pageSizeCombo->clear();-
343-
344 if (m_outputFormat == QPrinter::NativeFormat && !m_printerName.isEmpty()) {
m_outputFormat...::NativeFormatDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
!m_printerName.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0-1
345 QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();-
346 if (ps) {
psDescription
TRUEnever evaluated
FALSEnever evaluated
0
347 QPrintDevice printDevice = ps->createPrintDevice(m_printerName);-
348 const 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()) {
m_ui.pageSizeC...o->count() > 0Description
TRUEnever evaluated
FALSEnever evaluated
printDevice.su...tomPageSizes()Description
TRUEnever evaluated
FALSEnever 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 // If PdfFormat or no available printer page sizes, populate with all page sizes-
360 for (int id = 0; id < QPageSize::LastPageSize; ++id) {
id < QPageSize::LastPageSizeDescription
TRUEevaluated 118 times by 1 test
Evaluated by:
  • tst_QPrinter
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
1-118
361 if (QPageSize::PageSizeId(id) == QPageSize::Custom) {
QPageSize::Pag...geSize::CustomDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEevaluated 117 times by 1 test
Evaluated by:
  • tst_QPrinter
1-117
362 m_ui.pageSizeCombo->addItem(tr("Custom"), QVariant::fromValue(QPageSize::Custom));-
363 } else {
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
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
Executed by:
  • tst_QPrinter
117
367 }-
368-
369 m_blockSignals = false;-
370}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
371-
372// Set the dialog to use the given QPrinter-
373// Usually only called on first creation-
374void QPageSetupWidget::setPrinter(QPrinter *printer)-
375{-
376 m_printer = printer;-
377-
378 // Initialize the layout to the current QPrinter layout-
379 m_pageLayout = m_printer->pageLayout();-
380 // Assume if margins are Points then is by default, so set to locale default units-
381 if (m_pageLayout.units() == QPageLayout::Point) {
m_pageLayout.u...eLayout::PointDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-1
382 if (QLocale().measurementSystem() == QLocale::MetricSystem)
QLocale().meas...::MetricSystemDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
0-1
383 m_pageLayout.setUnits(QPageLayout::Millimeter);
never executed: m_pageLayout.setUnits(QPageLayout::Millimeter);
0
384 else-
385 m_pageLayout.setUnits(QPageLayout::Inch);
executed 1 time by 1 test: m_pageLayout.setUnits(QPageLayout::Inch);
Executed by:
  • tst_QPrinter
1
386 }-
387 m_units = m_pageLayout.units();-
388 m_pagePreview->setPageLayout(m_pageLayout);-
389-
390 // Then update the widget with the current printer details-
391 selectPrinter(m_printer->outputFormat(), m_printer->printerName());-
392}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
393-
394// The printer selected in the QPrintDialog has been changed, update the widget to reflect this-
395// Note the QPrinter is not updated at this time in case the user presses the Cancel button in QPrintDialog-
396void QPageSetupWidget::selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName)-
397{-
398 m_outputFormat = outputFormat;-
399 m_printerName = printerName;-
400 initPageSizes();-
401 updateWidget();-
402}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
403-
404// Update the widget with the current settings-
405// TODO Break up into more intelligent chunks?-
406void QPageSetupWidget::updateWidget()-
407{-
408 m_blockSignals = true;-
409-
410 QString suffix;-
411 switch (m_units) {-
412 case QPageLayout::Millimeter:
never executed: case QPageLayout::Millimeter:
0
413 //: Unit 'Millimeter'-
414 suffix = tr("mm");-
415 break;
never executed: break;
0
416 case QPageLayout::Point:
never executed: case QPageLayout::Point:
0
417 //: Unit 'Points'-
418 suffix = tr("pt");-
419 break;
never executed: break;
0
420 case QPageLayout::Inch:
executed 1 time by 1 test: case QPageLayout::Inch:
Executed by:
  • tst_QPrinter
1
421 //: Unit 'Inch'-
422 suffix = tr("in");-
423 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_QPrinter
1
424 case QPageLayout::Pica:
never executed: case QPageLayout::Pica:
0
425 //: Unit 'Pica'-
426 suffix = tr("P̸");-
427 break;
never executed: break;
0
428 case QPageLayout::Didot:
never executed: case QPageLayout::Didot:
0
429 //: Unit 'Didot'-
430 suffix = tr("DD");-
431 break;
never executed: break;
0
432 case QPageLayout::Cicero:
never executed: case QPageLayout::Cicero:
0
433 //: Unit 'Cicero'-
434 suffix = tr("CC");-
435 break;
never executed: break;
0
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) {
m_pageLayout.m...::FullPageModeDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
0-1
446 min = QMarginsF(0.0, 0.0, 0.0, 0.0);-
447 max = QMarginsF(9999.9999, 9999.9999, 9999.9999, 9999.9999);-
448 } else {
never executed: end of block
0
449 min = m_pageLayout.minimumMargins();-
450 max = m_pageLayout.maximumMargins();-
451 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
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}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
495-
496// Set the dialog chosen options on the QPrinter-
497// Normally only called when the QPrintDialog or QPageSetupDialog OK button is pressed-
498void 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}
never executed: end of block
0
512-
513// Updates size/preview after the combobox has been changed.-
514void QPageSetupWidget::pageSizeChanged()-
515{-
516 if (m_blockSignals)
m_blockSignalsDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-3
517 return;
executed 3 times by 1 test: return;
Executed by:
  • tst_QPrinter
3
518-
519 QPageSize::PageSizeId id = m_ui.pageSizeCombo->currentData().value<QPageSize::PageSizeId>();-
520 if (id != QPageSize::Custom) {
id != QPageSize::CustomDescription
TRUEnever evaluated
FALSEnever evaluated
0
521 // TODO Set layout margin min/max to printer custom min/max-
522 m_pageLayout.setPageSize(QPageSize(id));-
523 } else {
never executed: end of block
0
524 QSizeF customSize;-
525 if (m_pageLayout.orientation() == QPageLayout::Landscape)
m_pageLayout.o...out::LandscapeDescription
TRUEnever evaluated
FALSEnever evaluated
0
526 customSize = QSizeF(m_ui.pageHeight->value(), m_ui.pageWidth->value());
never executed: customSize = QSizeF(m_ui.pageHeight->value(), m_ui.pageWidth->value());
0
527 else-
528 customSize = QSizeF(m_ui.pageWidth->value(), m_ui.pageHeight->value());
never executed: customSize = QSizeF(m_ui.pageWidth->value(), m_ui.pageHeight->value());
0
529 // TODO Set layout margin min/max to printer min/max for page size-
530 m_pageLayout.setPageSize(QPageSize(customSize, QPageSize::Unit(m_units)));-
531 }
never executed: end of block
0
532 m_pagePreview->setPageLayout(m_pageLayout);-
533-
534 updateWidget();-
535}
never executed: end of block
0
536-
537void QPageSetupWidget::pageOrientationChanged()-
538{-
539 if (m_blockSignals)
m_blockSignalsDescription
TRUEnever evaluated
FALSEnever evaluated
0
540 return;
never executed: return;
0
541 m_pageLayout.setOrientation(m_ui.portrait->isChecked() ? QPageLayout::Portrait : QPageLayout::Landscape);-
542 m_pagePreview->setPageLayout(m_pageLayout);-
543 updateWidget();-
544}
never executed: end of block
0
545-
546void QPageSetupWidget::pagesPerSheetChanged()-
547{-
548#if !defined(QT_NO_CUPS)-
549 switch (m_ui.pagesPerSheetCombo->currentData().toInt()) {-
550 case QCUPSSupport::OnePagePerSheet:
never executed: case QCUPSSupport::OnePagePerSheet:
0
551 m_pagePreview->setPagePreviewLayout(1, 1);-
552 break;
never executed: break;
0
553 case QCUPSSupport::TwoPagesPerSheet:
never executed: case QCUPSSupport::TwoPagesPerSheet:
0
554 m_pagePreview->setPagePreviewLayout(1, 2);-
555 break;
never executed: break;
0
556 case QCUPSSupport::FourPagesPerSheet:
never executed: case QCUPSSupport::FourPagesPerSheet:
0
557 m_pagePreview->setPagePreviewLayout(2, 2);-
558 break;
never executed: break;
0
559 case QCUPSSupport::SixPagesPerSheet:
never executed: case QCUPSSupport::SixPagesPerSheet:
0
560 m_pagePreview->setPagePreviewLayout(3, 2);-
561 break;
never executed: break;
0
562 case QCUPSSupport::NinePagesPerSheet:
never executed: case QCUPSSupport::NinePagesPerSheet:
0
563 m_pagePreview->setPagePreviewLayout(3, 3);-
564 break;
never executed: break;
0
565 case QCUPSSupport::SixteenPagesPerSheet:
never executed: case QCUPSSupport::SixteenPagesPerSheet:
0
566 m_pagePreview->setPagePreviewLayout(4, 4);-
567 break;
never executed: break;
0
568 }-
569#endif-
570}
never executed: end of block
0
571-
572void QPageSetupWidget::unitChanged()-
573{-
574 if (m_blockSignals)
m_blockSignalsDescription
TRUEnever evaluated
FALSEnever evaluated
0
575 return;
never executed: return;
0
576 m_units = m_ui.unitCombo->currentData().value<QPageLayout::Unit>();-
577 m_pageLayout.setUnits(m_units);-
578 updateWidget();-
579}
never executed: end of block
0
580-
581void QPageSetupWidget::topMarginChanged(double newValue)-
582{-
583 if (m_blockSignals)
m_blockSignalsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-1
584 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QPrinter
1
585 m_pageLayout.setTopMargin(newValue);-
586 m_pagePreview->setPageLayout(m_pageLayout);-
587}
never executed: end of block
0
588-
589void QPageSetupWidget::bottomMarginChanged(double newValue)-
590{-
591 if (m_blockSignals)
m_blockSignalsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-1
592 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QPrinter
1
593 m_pageLayout.setBottomMargin(newValue);-
594 m_pagePreview->setPageLayout(m_pageLayout);-
595}
never executed: end of block
0
596-
597void QPageSetupWidget::leftMarginChanged(double newValue)-
598{-
599 if (m_blockSignals)
m_blockSignalsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-1
600 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QPrinter
1
601 m_pageLayout.setLeftMargin(newValue);-
602 m_pagePreview->setPageLayout(m_pageLayout);-
603}
never executed: end of block
0
604-
605void QPageSetupWidget::rightMarginChanged(double newValue)-
606{-
607 if (m_blockSignals)
m_blockSignalsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-1
608 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QPrinter
1
609 m_pageLayout.setRightMargin(newValue);-
610 m_pagePreview->setPageLayout(m_pageLayout);-
611}
never executed: end of block
0
612-
613// QPageSetupDialog-
614// - Public Linux / CUPS class implementation-
615-
616QPageSetupDialog::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}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
623-
624QPageSetupDialog::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}
never executed: end of block
0
631-
632int QPageSetupDialog::exec()-
633{-
634 Q_D(QPageSetupDialog);-
635-
636 int ret = QDialog::exec();-
637 if (ret == Accepted)
ret == AcceptedDescription
TRUEnever evaluated
FALSEnever evaluated
0
638 static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->setupPrinter();
never executed: static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->setupPrinter();
0
639 return ret;
never executed: return ret;
0
640}-
641-
642QT_END_NAMESPACE-
643-
644#include "moc_qpagesetupdialog.cpp"-
645-
646#endif // QT_NO_PRINTDIALOG-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9