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) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://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 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include "qpagesetupdialog.h"-
35-
36#ifndef QT_NO_PRINTDIALOG-
37#include "qpagesetupdialog_unix_p.h"-
38-
39#include <private/qpagesetupdialog_p.h>-
40#include <private/qprintdevice_p.h>-
41#include <private/qcups_p.h>-
42-
43#include "qpainter.h"-
44#include "qprintdialog.h"-
45#include "qdialogbuttonbox.h"-
46#include <ui_qpagesetupwidget.h>-
47-
48#include <QtPrintSupport/qprinter.h>-
49-
50#include <qpa/qplatformprintplugin.h>-
51#include <qpa/qplatformprintersupport.h>-
52-
53QT_BEGIN_NAMESPACE-
54-
55// Disabled until we have support for papersources on unix-
56// #define PSD_ENABLE_PAPERSOURCE-
57-
58#ifdef PSD_ENABLE_PAPERSOURCE-
59static const char *paperSourceNames[] = {-
60 "Only One",-
61 "Lower",-
62 "Middle",-
63 "Manual",-
64 "Envelope",-
65 "Envelope manual",-
66 "Auto",-
67 "Tractor",-
68 "Small format",-
69 "Large format",-
70 "Large capacity",-
71 "Cassette",-
72 "Form source",-
73 0-
74};-
75-
76struct PaperSourceNames-
77{-
78 PaperSourceNames(const char *nam, QPrinter::PaperSource ps)-
79 : paperSource(ps), name(nam) {}-
80 QPrinter::PaperSource paperSource;-
81 const char *name;-
82};-
83#endif-
84-
85-
86// QPagePreview-
87// - Private widget to display preview of page layout-
88// - Embedded in QPageSetupWidget-
89-
90class QPagePreview : public QWidget-
91{-
92public:-
93 QPagePreview(QWidget *parent) : QWidget(parent)-
94 {-
95 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);-
96 setMinimumSize(50, 50);-
97 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
98-
99 void setPageLayout(const QPageLayout &layout)-
100 {-
101 m_pageLayout = layout;-
102 update();-
103 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
104-
105 void setPagePreviewLayout(int columns, int rows)-
106 {-
107 m_pagePreviewColumns = columns;-
108 m_pagePreviewRows = rows;-
109 update();-
110 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
111-
112protected:-
113 void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE-
114 {-
115 QSize pageSize = m_pageLayout.fullRectPoints().size();-
116 QSizeF scaledSize = pageSize.scaled(width() - 10, height() - 10, Qt::KeepAspectRatio);-
117 QRect pageRect = QRect(QPoint(0,0), scaledSize.toSize());-
118 pageRect.moveCenter(rect().center());-
119 qreal width_factor = scaledSize.width() / pageSize.width();-
120 qreal height_factor = scaledSize.height() / pageSize.height();-
121 QMarginsF margins = m_pageLayout.margins(QPageLayout::Point);-
122 int left = qRound(margins.left() * width_factor);-
123 int top = qRound(margins.top() * height_factor);-
124 int right = qRound(margins.right() * width_factor);-
125 int bottom = qRound(margins.bottom() * height_factor);-
126 QRect marginRect(pageRect.x() + left, pageRect.y() + top,-
127 pageRect.width() - (left + right + 1), pageRect.height() - (top + bottom + 1));-
128-
129 QPainter p(this);-
130 QColor shadow(palette().mid().color());-
131 for (int i=1; i<6; ++i) {
i<6Description
TRUEnever evaluated
FALSEnever evaluated
0
132 shadow.setAlpha(180-i*30);-
133 QRect offset(pageRect.adjusted(i, i, i, i));-
134 p.setPen(shadow);-
135 p.drawLine(offset.left(), offset.bottom(), offset.right(), offset.bottom());-
136 p.drawLine(offset.right(), offset.top(), offset.right(), offset.bottom()-1);-
137 }
never executed: end of block
0
138 p.fillRect(pageRect, palette().light());-
139-
140 if (marginRect.isValid()) {
marginRect.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
141 p.setPen(QPen(palette().color(QPalette::Dark), 0, Qt::DotLine));-
142 p.drawRect(marginRect);-
143-
144 marginRect.adjust(2, 2, -1, -1);-
145 p.setClipRect(marginRect);-
146 QFont font;-
147 font.setPointSizeF(font.pointSizeF()*0.25);-
148 p.setFont(font);-
149 p.setPen(palette().color(QPalette::Dark));-
150 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."));-
151 for (int i=0; i<3; ++i)
i<3Description
TRUEnever evaluated
FALSEnever evaluated
0
152 text += text;
never executed: text += text;
0
153-
154 const int spacing = pageRect.width() * 0.1;-
155 const int textWidth = (marginRect.width() - (spacing * (m_pagePreviewColumns-1))) / m_pagePreviewColumns;-
156 const int textHeight = (marginRect.height() - (spacing * (m_pagePreviewRows-1))) / m_pagePreviewRows;-
157-
158 for (int x = 0 ; x < m_pagePreviewColumns; ++x) {
x < m_pagePreviewColumnsDescription
TRUEnever evaluated
FALSEnever evaluated
0
159 for (int y = 0 ; y < m_pagePreviewRows; ++y) {
y < m_pagePreviewRowsDescription
TRUEnever evaluated
FALSEnever evaluated
0
160 QRect textRect(marginRect.left() + x * (textWidth + spacing),-
161 marginRect.top() + y * (textHeight + spacing),-
162 textWidth, textHeight);-
163 p.drawText(textRect, Qt::TextWordWrap|Qt::AlignVCenter, text);-
164 }
never executed: end of block
0
165 }
never executed: end of block
0
166 }
never executed: end of block
0
167 }
never executed: end of block
0
168-
169private:-
170 // Page Layout-
171 QPageLayout m_pageLayout;-
172 // Pages Per Sheet / n-up layout-
173 int m_pagePreviewColumns, m_pagePreviewRows;-
174};-
175-
176-
177// QUnixPageSetupDialogPrivate-
178// - Linux / Cups implementation of QPageSetupDialogPrivate-
179// - Embeds QPageSetupWidget-
180-
181class QUnixPageSetupDialogPrivate : public QPageSetupDialogPrivate-
182{-
183 Q_DECLARE_PUBLIC(QPageSetupDialog)-
184-
185public:-
186 QUnixPageSetupDialogPrivate(QPrinter *printer);-
187 ~QUnixPageSetupDialogPrivate();-
188 void init();-
189-
190 QPageSetupWidget *widget;-
191};-
192-
193QUnixPageSetupDialogPrivate::QUnixPageSetupDialogPrivate(QPrinter *printer) : QPageSetupDialogPrivate(printer)-
194{-
195}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
196-
197QUnixPageSetupDialogPrivate::~QUnixPageSetupDialogPrivate()-
198{-
199}-
200-
201void QUnixPageSetupDialogPrivate::init()-
202{-
203 Q_Q(QPageSetupDialog);-
204-
205 widget = new QPageSetupWidget(q);-
206 widget->setPrinter(printer);-
207-
208 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok-
209 | QDialogButtonBox::Cancel,-
210 Qt::Horizontal, q);-
211 QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(accept()));-
212 QObject::connect(buttons, SIGNAL(rejected()), q, SLOT(reject()));-
213-
214 QVBoxLayout *lay = new QVBoxLayout(q);-
215 lay->addWidget(widget);-
216 lay->addWidget(buttons);-
217}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
218-
219// QPageSetupWidget-
220// - Private widget implementation for Linux / CUPS-
221// - Embeds QPagePreview-
222// - TODO Could be made public as a stand-alone widget?-
223-
224QPageSetupWidget::QPageSetupWidget(QWidget *parent)-
225 : QWidget(parent),-
226 m_pagePreview(0),-
227 m_printer(0),-
228 m_outputFormat(QPrinter::PdfFormat),-
229 m_units(QPageLayout::Point),-
230 m_blockSignals(false)-
231{-
232 m_ui.setupUi(this);-
233-
234 QVBoxLayout *lay = new QVBoxLayout(m_ui.preview);-
235 m_ui.preview->setLayout(lay);-
236 m_pagePreview = new QPagePreview(m_ui.preview);-
237 m_pagePreview->setPagePreviewLayout(1, 1);-
238-
239 lay->addWidget(m_pagePreview);-
240-
241 setAttribute(Qt::WA_WState_Polished, false);-
242-
243#ifdef PSD_ENABLE_PAPERSOURCE-
244 for (int i=0; paperSourceNames[i]; ++i)-
245 m_ui.paperSource->insertItem(paperSourceNames[i]);-
246#else-
247 m_ui.paperSourceLabel->setVisible(false);-
248 m_ui.paperSource->setVisible(false);-
249#endif-
250-
251 m_ui.reverseLandscape->setVisible(false);-
252 m_ui.reversePortrait->setVisible(false);-
253-
254 initUnits();-
255 initPagesPerSheet();-
256-
257 connect(m_ui.unitCombo, SIGNAL(activated(int)), this, SLOT(unitChanged()));-
258-
259 connect(m_ui.pageSizeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(pageSizeChanged()));-
260 connect(m_ui.pageWidth, SIGNAL(valueChanged(double)), this, SLOT(pageSizeChanged()));-
261 connect(m_ui.pageHeight, SIGNAL(valueChanged(double)), this, SLOT(pageSizeChanged()));-
262-
263 connect(m_ui.leftMargin, SIGNAL(valueChanged(double)), this, SLOT(leftMarginChanged(double)));-
264 connect(m_ui.topMargin, SIGNAL(valueChanged(double)), this, SLOT(topMarginChanged(double)));-
265 connect(m_ui.rightMargin, SIGNAL(valueChanged(double)), this, SLOT(rightMarginChanged(double)));-
266 connect(m_ui.bottomMargin, SIGNAL(valueChanged(double)), this, SLOT(bottomMarginChanged(double)));-
267-
268 connect(m_ui.portrait, SIGNAL(clicked()), this, SLOT(pageOrientationChanged()));-
269 connect(m_ui.landscape, SIGNAL(clicked()), this, SLOT(pageOrientationChanged()));-
270-
271 connect(m_ui.pagesPerSheetCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(pagesPerSheetChanged()));-
272}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
273-
274// Init the Units combo box-
275void QPageSetupWidget::initUnits()-
276{-
277 m_ui.unitCombo->addItem(tr("Millimeters (mm)"), QVariant::fromValue(QPageLayout::Millimeter));-
278 m_ui.unitCombo->addItem(tr("Inches (in)"), QVariant::fromValue(QPageLayout::Inch));-
279 m_ui.unitCombo->addItem(tr("Points (pt)"), QVariant::fromValue(QPageLayout::Point));-
280 m_ui.unitCombo->addItem(tr("Pica (P̸)"), QVariant::fromValue(QPageLayout::Pica));-
281 m_ui.unitCombo->addItem(tr("Didot (DD)"), QVariant::fromValue(QPageLayout::Didot));-
282 m_ui.unitCombo->addItem(tr("Cicero (CC)"), QVariant::fromValue(QPageLayout::Cicero));-
283-
284 // Initailly default to locale measurement system, mm if metric, in otherwise-
285 m_ui.unitCombo->setCurrentIndex(QLocale().measurementSystem() != QLocale::MetricSystem);-
286}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
287-
288// Init the Pages Per Sheet (n-up) combo boxes if using CUPS-
289void QPageSetupWidget::initPagesPerSheet()-
290{-
291#if !defined(QT_NO_CUPS)-
292 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Left to Right, Top to Bottom"),-
293 QVariant::fromValue(QCUPSSupport::LeftToRightTopToBottom));-
294 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Left to Right, Bottom to Top"),-
295 QVariant::fromValue(QCUPSSupport::LeftToRightBottomToTop));-
296 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Right to Left, Bottom to Top"),-
297 QVariant::fromValue(QCUPSSupport::RightToLeftBottomToTop));-
298 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Right to Left, Top to Bottom"),-
299 QVariant::fromValue(QCUPSSupport::RightToLeftTopToBottom));-
300 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Bottom to Top, Left to Right"),-
301 QVariant::fromValue(QCUPSSupport::BottomToTopLeftToRight));-
302 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Bottom to Top, Right to Left"),-
303 QVariant::fromValue(QCUPSSupport::BottomToTopRightToLeft));-
304 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Top to Bottom, Left to Right"),-
305 QVariant::fromValue(QCUPSSupport::TopToBottomLeftToRight));-
306 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Top to Bottom, Right to Left"),-
307 QVariant::fromValue(QCUPSSupport::TopToBottomRightToLeft));-
308-
309 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("1 (1x1)"),-
310 QVariant::fromValue(QCUPSSupport::OnePagePerSheet));-
311 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("2 (2x1)"),-
312 QVariant::fromValue(QCUPSSupport::TwoPagesPerSheet));-
313 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("4 (2x2)"),-
314 QVariant::fromValue(QCUPSSupport::FourPagesPerSheet));-
315 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("6 (2x3)"),-
316 QVariant::fromValue(QCUPSSupport::SixPagesPerSheet));-
317 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("9 (3x3)"),-
318 QVariant::fromValue(QCUPSSupport::NinePagesPerSheet));-
319 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("16 (4x4)"),-
320 QVariant::fromValue(QCUPSSupport::SixteenPagesPerSheet));-
321-
322 // Set to QCUPSSupport::OnePagePerSheet-
323 m_ui.pagesPerSheetCombo->setCurrentIndex(0);-
324 // Set to QCUPSSupport::LeftToRightTopToBottom-
325 m_ui.pagesPerSheetLayoutCombo->setCurrentIndex(0);-
326#else-
327 // Disable if CUPS wasn't found-
328 m_ui.pagesPerSheetButtonGroup->hide();-
329#endif-
330}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
331-
332void QPageSetupWidget::initPageSizes()-
333{-
334 m_blockSignals = true;-
335-
336 m_ui.pageSizeCombo->clear();-
337-
338 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
339 QPlatformPrinterSupport *ps = QPlatformPrinterSupportPlugin::get();-
340 if (ps) {
psDescription
TRUEnever evaluated
FALSEnever evaluated
0
341 QPrintDevice printDevice = ps->createPrintDevice(m_printerName);-
342 foreach (const QPageSize &pageSize, printDevice.supportedPageSizes()) {-
343 m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize.id()));-
344 }
never executed: end of block
0
345 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
346 m_ui.pageSizeCombo->addItem(tr("Custom"), QVariant::fromValue(QPageSize::Custom));-
347 m_blockSignals = false;-
348 return;
never executed: return;
0
349 }-
350 }
never executed: end of block
0
351 }
never executed: end of block
0
352-
353 // If PdfFormat or no available printer page sizes, populate with all page sizes-
354 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
355 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
356 m_ui.pageSizeCombo->addItem(tr("Custom"), QVariant::fromValue(QPageSize::Custom));-
357 } else {
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
358 QPageSize pageSize = QPageSize(QPageSize::PageSizeId(id));-
359 m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize.id()));-
360 }
executed 117 times by 1 test: end of block
Executed by:
  • tst_QPrinter
117
361 }-
362-
363 m_blockSignals = false;-
364}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
365-
366// Set the dialog to use the given QPrinter-
367// Usually only called on first creation-
368void QPageSetupWidget::setPrinter(QPrinter *printer)-
369{-
370 m_printer = printer;-
371-
372 // Initialize the layout to the current QPrinter layout-
373 m_pageLayout = m_printer->pageLayout();-
374 // Assume if margins are Points then is by default, so set to locale default units-
375 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
376 if (QLocale().measurementSystem() == QLocale::MetricSystem)
QLocale().meas...::MetricSystemDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
0-1
377 m_pageLayout.setUnits(QPageLayout::Millimeter);
never executed: m_pageLayout.setUnits(QPageLayout::Millimeter);
0
378 else-
379 m_pageLayout.setUnits(QPageLayout::Inch);
executed 1 time by 1 test: m_pageLayout.setUnits(QPageLayout::Inch);
Executed by:
  • tst_QPrinter
1
380 }-
381 m_units = m_pageLayout.units();-
382 m_pagePreview->setPageLayout(m_pageLayout);-
383-
384 // Then update the widget with the current printer details-
385 selectPrinter(m_printer->outputFormat(), m_printer->printerName());-
386}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
387-
388// The printer selected in the QPrintDialog has been changed, update the widget to reflect this-
389// Note the QPrinter is not updated at this time in case the user presses the Cancel button in QPrintDialog-
390void QPageSetupWidget::selectPrinter(QPrinter::OutputFormat outputFormat, const QString &printerName)-
391{-
392 m_outputFormat = outputFormat;-
393 m_printerName = printerName;-
394 initPageSizes();-
395 updateWidget();-
396}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
397-
398// Update the widget with the current settings-
399// TODO Break up into more intelligent chunks?-
400void QPageSetupWidget::updateWidget()-
401{-
402 m_blockSignals = true;-
403-
404 QString suffix;-
405 switch (m_units) {-
406 case QPageLayout::Millimeter:
never executed: case QPageLayout::Millimeter:
0
407 //: Unit 'Millimeter'-
408 suffix = tr("mm");-
409 break;
never executed: break;
0
410 case QPageLayout::Point:
never executed: case QPageLayout::Point:
0
411 //: Unit 'Points'-
412 suffix = tr("pt");-
413 break;
never executed: break;
0
414 case QPageLayout::Inch:
executed 1 time by 1 test: case QPageLayout::Inch:
Executed by:
  • tst_QPrinter
1
415 //: Unit 'Inch'-
416 suffix = tr("in");-
417 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_QPrinter
1
418 case QPageLayout::Pica:
never executed: case QPageLayout::Pica:
0
419 //: Unit 'Pica'-
420 suffix = tr("P̸");-
421 break;
never executed: break;
0
422 case QPageLayout::Didot:
never executed: case QPageLayout::Didot:
0
423 //: Unit 'Didot'-
424 suffix = tr("DD");-
425 break;
never executed: break;
0
426 case QPageLayout::Cicero:
never executed: case QPageLayout::Cicero:
0
427 //: Unit 'Cicero'-
428 suffix = tr("CC");-
429 break;
never executed: break;
0
430 }-
431-
432 m_ui.unitCombo->setCurrentIndex(m_ui.unitCombo->findData(QVariant::fromValue(m_units)));-
433-
434 m_ui.pageSizeCombo->setCurrentIndex(m_ui.pageSizeCombo->findData(QVariant::fromValue(m_pageLayout.pageSize().id())));-
435-
436 QMarginsF min;-
437 QMarginsF max;-
438-
439 if (m_pageLayout.mode() == QPageLayout::FullPageMode) {
m_pageLayout.m...::FullPageModeDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
0-1
440 min = QMarginsF(0.0, 0.0, 0.0, 0.0);-
441 max = QMarginsF(9999.9999, 9999.9999, 9999.9999, 9999.9999);-
442 } else {
never executed: end of block
0
443 min = m_pageLayout.minimumMargins();-
444 max = m_pageLayout.maximumMargins();-
445 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
446-
447 m_ui.leftMargin->setSuffix(suffix);-
448 m_ui.leftMargin->setMinimum(min.left());-
449 m_ui.leftMargin->setMaximum(max.left());-
450 m_ui.leftMargin->setValue(m_pageLayout.margins().left());-
451-
452 m_ui.rightMargin->setSuffix(suffix);-
453 m_ui.rightMargin->setMinimum(min.right());-
454 m_ui.rightMargin->setMaximum(max.right());-
455 m_ui.rightMargin->setValue(m_pageLayout.margins().right());-
456-
457 m_ui.topMargin->setSuffix(suffix);-
458 m_ui.topMargin->setMinimum(min.top());-
459 m_ui.topMargin->setMaximum(max.top());-
460 m_ui.topMargin->setValue(m_pageLayout.margins().top());-
461-
462 m_ui.bottomMargin->setSuffix(suffix);-
463 m_ui.bottomMargin->setMinimum(min.bottom());-
464 m_ui.bottomMargin->setMaximum(max.bottom());-
465 m_ui.bottomMargin->setValue(m_pageLayout.margins().bottom());-
466-
467 bool isCustom = m_ui.pageSizeCombo->currentData().value<QPageSize::PageSizeId>() == QPageSize::Custom;-
468-
469 m_ui.pageWidth->setSuffix(suffix);-
470 m_ui.pageWidth->setValue(m_pageLayout.fullRect(m_units).width());-
471 m_ui.pageWidth->setEnabled(isCustom);-
472 m_ui.widthLabel->setEnabled(isCustom);-
473-
474 m_ui.pageHeight->setSuffix(suffix);-
475 m_ui.pageHeight->setValue(m_pageLayout.fullRect(m_units).height());-
476 m_ui.pageHeight->setEnabled(isCustom);-
477 m_ui.heightLabel->setEnabled(isCustom);-
478-
479 m_ui.landscape->setChecked(m_pageLayout.orientation() == QPageLayout::Landscape);-
480-
481 m_ui.pagesPerSheetButtonGroup->setEnabled(m_outputFormat == QPrinter::NativeFormat);-
482-
483#ifdef PSD_ENABLE_PAPERSOURCE-
484 m_ui.paperSource->setCurrentItem(printer->paperSource());-
485#endif-
486-
487 m_blockSignals = false;-
488}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
489-
490// Set the dialog chosen options on the QPrinter-
491// Normally only called when the QPrintDialog or QPageSetupDialog OK button is pressed-
492void QPageSetupWidget::setupPrinter() const-
493{-
494 m_printer->setPageLayout(m_pageLayout);-
495#if !defined(QT_NO_CUPS)-
496 QCUPSSupport::PagesPerSheet pagesPerSheet = m_ui.pagesPerSheetCombo->currentData()-
497 .value<QCUPSSupport::PagesPerSheet>();-
498 QCUPSSupport::PagesPerSheetLayout pagesPerSheetLayout = m_ui.pagesPerSheetLayoutCombo->currentData()-
499 .value<QCUPSSupport::PagesPerSheetLayout>();-
500 QCUPSSupport::setPagesPerSheetLayout(m_printer, pagesPerSheet, pagesPerSheetLayout);-
501#endif-
502#ifdef PSD_ENABLE_PAPERSOURCE-
503 m_printer->setPaperSource((QPrinter::PaperSource)m_ui.paperSource->currentIndex());-
504#endif-
505}
never executed: end of block
0
506-
507// Updates size/preview after the combobox has been changed.-
508void QPageSetupWidget::pageSizeChanged()-
509{-
510 if (m_blockSignals)
m_blockSignalsDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-3
511 return;
executed 3 times by 1 test: return;
Executed by:
  • tst_QPrinter
3
512-
513 QPageSize::PageSizeId id = m_ui.pageSizeCombo->currentData().value<QPageSize::PageSizeId>();-
514 if (id != QPageSize::Custom) {
id != QPageSize::CustomDescription
TRUEnever evaluated
FALSEnever evaluated
0
515 // TODO Set layout margin min/max to printer custom min/max-
516 m_pageLayout.setPageSize(QPageSize(id));-
517 } else {
never executed: end of block
0
518 QSizeF customSize;-
519 if (m_pageLayout.orientation() == QPageLayout::Landscape)
m_pageLayout.o...out::LandscapeDescription
TRUEnever evaluated
FALSEnever evaluated
0
520 customSize = QSizeF(m_ui.pageHeight->value(), m_ui.pageWidth->value());
never executed: customSize = QSizeF(m_ui.pageHeight->value(), m_ui.pageWidth->value());
0
521 else-
522 customSize = QSizeF(m_ui.pageWidth->value(), m_ui.pageHeight->value());
never executed: customSize = QSizeF(m_ui.pageWidth->value(), m_ui.pageHeight->value());
0
523 // TODO Set layout margin min/max to printer min/max for page size-
524 m_pageLayout.setPageSize(QPageSize(customSize, QPageSize::Unit(m_units)));-
525 }
never executed: end of block
0
526 m_pagePreview->setPageLayout(m_pageLayout);-
527-
528 updateWidget();-
529}
never executed: end of block
0
530-
531void QPageSetupWidget::pageOrientationChanged()-
532{-
533 if (m_blockSignals)
m_blockSignalsDescription
TRUEnever evaluated
FALSEnever evaluated
0
534 return;
never executed: return;
0
535 m_pageLayout.setOrientation(m_ui.portrait->isChecked() ? QPageLayout::Portrait : QPageLayout::Landscape);-
536 m_pagePreview->setPageLayout(m_pageLayout);-
537 updateWidget();-
538}
never executed: end of block
0
539-
540void QPageSetupWidget::pagesPerSheetChanged()-
541{-
542#if !defined(QT_NO_CUPS)-
543 switch (m_ui.pagesPerSheetCombo->currentData().toInt()) {-
544 case QCUPSSupport::OnePagePerSheet:
never executed: case QCUPSSupport::OnePagePerSheet:
0
545 m_pagePreview->setPagePreviewLayout(1, 1);-
546 break;
never executed: break;
0
547 case QCUPSSupport::TwoPagesPerSheet:
never executed: case QCUPSSupport::TwoPagesPerSheet:
0
548 m_pagePreview->setPagePreviewLayout(1, 2);-
549 break;
never executed: break;
0
550 case QCUPSSupport::FourPagesPerSheet:
never executed: case QCUPSSupport::FourPagesPerSheet:
0
551 m_pagePreview->setPagePreviewLayout(2, 2);-
552 break;
never executed: break;
0
553 case QCUPSSupport::SixPagesPerSheet:
never executed: case QCUPSSupport::SixPagesPerSheet:
0
554 m_pagePreview->setPagePreviewLayout(3, 2);-
555 break;
never executed: break;
0
556 case QCUPSSupport::NinePagesPerSheet:
never executed: case QCUPSSupport::NinePagesPerSheet:
0
557 m_pagePreview->setPagePreviewLayout(3, 3);-
558 break;
never executed: break;
0
559 case QCUPSSupport::SixteenPagesPerSheet:
never executed: case QCUPSSupport::SixteenPagesPerSheet:
0
560 m_pagePreview->setPagePreviewLayout(4, 4);-
561 break;
never executed: break;
0
562 }-
563#endif-
564}
never executed: end of block
0
565-
566void QPageSetupWidget::unitChanged()-
567{-
568 if (m_blockSignals)
m_blockSignalsDescription
TRUEnever evaluated
FALSEnever evaluated
0
569 return;
never executed: return;
0
570 m_units = m_ui.unitCombo->currentData().value<QPageLayout::Unit>();-
571 m_pageLayout.setUnits(m_units);-
572 updateWidget();-
573}
never executed: end of block
0
574-
575void QPageSetupWidget::topMarginChanged(double newValue)-
576{-
577 if (m_blockSignals)
m_blockSignalsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-1
578 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QPrinter
1
579 m_pageLayout.setTopMargin(newValue);-
580 m_pagePreview->setPageLayout(m_pageLayout);-
581}
never executed: end of block
0
582-
583void QPageSetupWidget::bottomMarginChanged(double newValue)-
584{-
585 if (m_blockSignals)
m_blockSignalsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-1
586 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QPrinter
1
587 m_pageLayout.setBottomMargin(newValue);-
588 m_pagePreview->setPageLayout(m_pageLayout);-
589}
never executed: end of block
0
590-
591void QPageSetupWidget::leftMarginChanged(double newValue)-
592{-
593 if (m_blockSignals)
m_blockSignalsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-1
594 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QPrinter
1
595 m_pageLayout.setLeftMargin(newValue);-
596 m_pagePreview->setPageLayout(m_pageLayout);-
597}
never executed: end of block
0
598-
599void QPageSetupWidget::rightMarginChanged(double newValue)-
600{-
601 if (m_blockSignals)
m_blockSignalsDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QPrinter
FALSEnever evaluated
0-1
602 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QPrinter
1
603 m_pageLayout.setRightMargin(newValue);-
604 m_pagePreview->setPageLayout(m_pageLayout);-
605}
never executed: end of block
0
606-
607// QPageSetupDialog-
608// - Public Linux / CUPS class implementation-
609-
610QPageSetupDialog::QPageSetupDialog(QPrinter *printer, QWidget *parent)-
611 : QDialog(*(new QUnixPageSetupDialogPrivate(printer)), parent)-
612{-
613 Q_D(QPageSetupDialog);-
614 setWindowTitle(QCoreApplication::translate("QPrintPreviewDialog", "Page Setup"));-
615 static_cast<QUnixPageSetupDialogPrivate *>(d)->init();-
616}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QPrinter
1
617-
618QPageSetupDialog::QPageSetupDialog(QWidget *parent)-
619 : QDialog(*(new QUnixPageSetupDialogPrivate(0)), parent)-
620{-
621 Q_D(QPageSetupDialog);-
622 setWindowTitle(QCoreApplication::translate("QPrintPreviewDialog", "Page Setup"));-
623 static_cast<QUnixPageSetupDialogPrivate *>(d)->init();-
624}
never executed: end of block
0
625-
626int QPageSetupDialog::exec()-
627{-
628 Q_D(QPageSetupDialog);-
629-
630 int ret = QDialog::exec();-
631 if (ret == Accepted)
ret == AcceptedDescription
TRUEnever evaluated
FALSEnever evaluated
0
632 static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->setupPrinter();
never executed: static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->setupPrinter();
0
633 return ret;
never executed: return ret;
0
634}-
635-
636QT_END_NAMESPACE-
637-
638#include "moc_qpagesetupdialog.cpp"-
639-
640#endif // QT_NO_PRINTDIALOG-
Source codeSwitch to Preprocessed file

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