Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qpagesetupdialog_unix.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qpagesetupdialog.h"
5
7
8#include <private/qpagesetupdialog_p.h>
9#include <private/qprintdevice_p.h>
10#if QT_CONFIG(cups)
11#include <private/qcups_p.h>
12#endif
13
14#include "qpainter.h"
15#include "qprintdialog.h"
16#include "qstringconverter.h"
17#include "qdialogbuttonbox.h"
18#include <ui_qpagesetupwidget.h>
19
20#include <QtPrintSupport/qprinter.h>
21
22#include <qpa/qplatformprintplugin.h>
23#include <qpa/qplatformprintersupport.h>
24
26
27using namespace Qt::StringLiterals;
28
29extern QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits);
30
31// Disabled until we have support for papersources on unix
32// #define PSD_ENABLE_PAPERSOURCE
33
34#ifdef PSD_ENABLE_PAPERSOURCE
35static const char *paperSourceNames[] = {
36 "Only One",
37 "Lower",
38 "Middle",
39 "Manual",
40 "Envelope",
41 "Envelope manual",
42 "Auto",
43 "Tractor",
44 "Small format",
45 "Large format",
46 "Large capacity",
47 "Cassette",
48 "Form source",
49 0
50};
51
52struct PaperSourceNames
53{
54 PaperSourceNames(const char *nam, QPrinter::PaperSource ps)
55 : paperSource(ps), name(nam) {}
56 QPrinter::PaperSource paperSource;
57 const char *name;
58};
59#endif
60
61
62// QPagePreview
63// - Private widget to display preview of page layout
64// - Embedded in QPageSetupWidget
65
66class QPagePreview : public QWidget
67{
68public:
74
76 {
77 m_pageLayout = layout;
78 update();
79 }
80
81 void setPagePreviewLayout(int columns, int rows)
82 {
83 m_pagePreviewColumns = columns;
84 m_pagePreviewRows = rows;
85 update();
86 }
87
88protected:
89 void paintEvent(QPaintEvent *) override
90 {
91 QSize pageSize = m_pageLayout.fullRectPoints().size();
92 QSizeF scaledSize = pageSize.scaled(width() - 10, height() - 10, Qt::KeepAspectRatio);
93 QRect pageRect = QRect(QPoint(0,0), scaledSize.toSize());
94 pageRect.moveCenter(rect().center());
95 qreal width_factor = scaledSize.width() / pageSize.width();
96 qreal height_factor = scaledSize.height() / pageSize.height();
97 QMarginsF margins = m_pageLayout.margins(QPageLayout::Point);
98 int left = qRound(margins.left() * width_factor);
99 int top = qRound(margins.top() * height_factor);
100 int right = qRound(margins.right() * width_factor);
101 int bottom = qRound(margins.bottom() * height_factor);
102 QRect marginRect(pageRect.x() + left, pageRect.y() + top,
103 pageRect.width() - (left + right + 1), pageRect.height() - (top + bottom + 1));
104
105 QPainter p(this);
106 QColor shadow(palette().mid().color());
107 for (int i=1; i<6; ++i) {
108 shadow.setAlpha(180-i*30);
109 QRect offset(pageRect.adjusted(i, i, i, i));
110 p.setPen(shadow);
111 p.drawLine(offset.left(), offset.bottom(), offset.right(), offset.bottom());
112 p.drawLine(offset.right(), offset.top(), offset.right(), offset.bottom()-1);
113 }
114 p.fillRect(pageRect, palette().light());
115
116 if (marginRect.isValid()) {
118 p.drawRect(marginRect);
119
120 marginRect.adjust(2, 2, -1, -1);
121 p.setClipRect(marginRect);
122 QFont font;
124 p.setFont(font);
125 p.setPen(palette().color(QPalette::Dark));
126 QString text("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."_L1);
127 for (int i=0; i<3; ++i)
128 text += text;
129
130 const int spacing = pageRect.width() * 0.1;
131 const int textWidth = (marginRect.width() - (spacing * (m_pagePreviewColumns-1))) / m_pagePreviewColumns;
132 const int textHeight = (marginRect.height() - (spacing * (m_pagePreviewRows-1))) / m_pagePreviewRows;
133
134 for (int x = 0 ; x < m_pagePreviewColumns; ++x) {
135 for (int y = 0 ; y < m_pagePreviewRows; ++y) {
136 QRect textRect(marginRect.left() + x * (textWidth + spacing),
137 marginRect.top() + y * (textHeight + spacing),
138 textWidth, textHeight);
140 }
141 }
142 }
143 }
144
145private:
146 // Page Layout
147 QPageLayout m_pageLayout;
148 // Pages Per Sheet / n-up layout
149 int m_pagePreviewColumns, m_pagePreviewRows;
150};
151
152
153// QUnixPageSetupDialogPrivate
154// - Linux / Cups implementation of QPageSetupDialogPrivate
155// - Embeds QPageSetupWidget
156
168
172
176
178{
179 Q_Q(QPageSetupDialog);
180
183
187 QObject::connect(buttons, SIGNAL(accepted()), q, SLOT(accept()));
188 QObject::connect(buttons, SIGNAL(rejected()), q, SLOT(reject()));
189
190 QVBoxLayout *lay = new QVBoxLayout(q);
191 lay->addWidget(widget);
192 lay->addWidget(buttons);
193}
194
195// QPageSetupWidget
196// - Private widget implementation for Linux / CUPS
197// - Embeds QPagePreview
198// - TODO Could be made public as a stand-alone widget?
199
201 : QWidget(parent),
202 m_pagePreview(nullptr),
203 m_printer(nullptr),
204 m_printDevice(nullptr),
205#if QT_CONFIG(cups)
206 m_pageSizePpdOption(nullptr),
207#endif
208 m_outputFormat(QPrinter::PdfFormat),
209 m_units(QPageLayout::Point),
210 m_savedUnits(QPageLayout::Point),
211 m_savedPagesPerSheet(-1),
212 m_savedPagesPerSheetLayout(-1),
213 m_blockSignals(false),
214 m_realCustomPageSizeIndex(-1)
215{
216 m_ui.setupUi(this);
217
218 QVBoxLayout *lay = new QVBoxLayout(m_ui.preview);
219 m_pagePreview = new QPagePreview(m_ui.preview);
220 m_pagePreview->setPagePreviewLayout(1, 1);
221
222 lay->addWidget(m_pagePreview);
223
225
226#ifdef PSD_ENABLE_PAPERSOURCE
227 for (int i=0; paperSourceNames[i]; ++i)
228 m_ui.paperSource->insertItem(paperSourceNames[i]);
229#else
230 m_ui.paperSourceLabel->setVisible(false);
231 m_ui.paperSource->setVisible(false);
232#endif
233
234 m_ui.reverseLandscape->setVisible(false);
235 m_ui.reversePortrait->setVisible(false);
236
237 initUnits();
238 initPagesPerSheet();
239
240 connect(m_ui.unitCombo, &QComboBox::activated, this, &QPageSetupWidget::unitChanged);
241
242 connect(m_ui.pageSizeCombo, &QComboBox::currentIndexChanged, this, &QPageSetupWidget::pageSizeChanged);
243 connect(m_ui.pageWidth, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::pageSizeChanged);
244 connect(m_ui.pageHeight, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::pageSizeChanged);
245
246 connect(m_ui.leftMargin, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::leftMarginChanged);
247 connect(m_ui.topMargin, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::topMarginChanged);
248 connect(m_ui.rightMargin, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::rightMarginChanged);
249 connect(m_ui.bottomMargin, &QDoubleSpinBox::valueChanged, this, &QPageSetupWidget::bottomMarginChanged);
250
251 connect(m_ui.portrait, &QRadioButton::clicked, this, &QPageSetupWidget::pageOrientationChanged);
252 connect(m_ui.landscape, &QRadioButton::clicked, this, &QPageSetupWidget::pageOrientationChanged);
253
254 connect(m_ui.pagesPerSheetCombo, &QComboBox::currentIndexChanged, this, &QPageSetupWidget::pagesPerSheetChanged);
255}
256
257// Init the Units combo box
258void QPageSetupWidget::initUnits()
259{
260 m_ui.unitCombo->addItem(tr("Millimeters (mm)"), QVariant::fromValue(QPageLayout::Millimeter));
261 m_ui.unitCombo->addItem(tr("Inches (in)"), QVariant::fromValue(QPageLayout::Inch));
262 m_ui.unitCombo->addItem(tr("Points (pt)"), QVariant::fromValue(QPageLayout::Point));
263 m_ui.unitCombo->addItem(tr("Pica (P̸)"), QVariant::fromValue(QPageLayout::Pica));
264 m_ui.unitCombo->addItem(tr("Didot (DD)"), QVariant::fromValue(QPageLayout::Didot));
265 m_ui.unitCombo->addItem(tr("Cicero (CC)"), QVariant::fromValue(QPageLayout::Cicero));
266
267 // Initially default to locale measurement system, mm if metric, in otherwise
268 m_ui.unitCombo->setCurrentIndex(QLocale().measurementSystem() != QLocale::MetricSystem);
269}
270
271// Init the Pages Per Sheet (n-up) combo boxes if using CUPS
272void QPageSetupWidget::initPagesPerSheet()
273{
274#if QT_CONFIG(cups)
275 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Left to Right, Top to Bottom"),
277 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Left to Right, Bottom to Top"),
279 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Right to Left, Bottom to Top"),
281 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Right to Left, Top to Bottom"),
283 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Bottom to Top, Left to Right"),
285 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Bottom to Top, Right to Left"),
287 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Top to Bottom, Left to Right"),
289 m_ui.pagesPerSheetLayoutCombo->addItem(QPrintDialog::tr("Top to Bottom, Right to Left"),
291
292 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("1 (1x1)"),
294 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("2 (2x1)"),
296 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("4 (2x2)"),
298 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("6 (2x3)"),
300 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("9 (3x3)"),
302 m_ui.pagesPerSheetCombo->addItem(QPrintDialog::tr("16 (4x4)"),
304
305 // Set to QCUPSSupport::OnePagePerSheet
306 m_ui.pagesPerSheetCombo->setCurrentIndex(0);
307 // Set to QCUPSSupport::LeftToRightTopToBottom
308 m_ui.pagesPerSheetLayoutCombo->setCurrentIndex(0);
309#else
310 // Disable if CUPS wasn't found
311 m_ui.pagesPerSheetButtonGroup->hide();
312#endif
313}
314
315void QPageSetupWidget::initPageSizes()
316{
317 m_blockSignals = true;
318
319 m_ui.pageSizeCombo->clear();
320
321 m_realCustomPageSizeIndex = -1;
322
323 if (m_outputFormat == QPrinter::NativeFormat && !m_printerName.isEmpty()) {
325 if (ps) {
326 QPrintDevice printDevice = ps->createPrintDevice(m_printerName);
327 const QPageSize defaultSize = printDevice.defaultPageSize();
328 const auto pageSizes = printDevice.supportedPageSizes();
329 for (const QPageSize &pageSize : pageSizes)
330 m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize));
331 if (m_ui.pageSizeCombo->count() > 0) {
332 if (printDevice.supportsCustomPageSizes()) {
333 m_ui.pageSizeCombo->addItem(tr("Custom"));
334 m_realCustomPageSizeIndex = m_ui.pageSizeCombo->count() - 1;
335 }
336 m_blockSignals = false;
337
338 // If the defaultSize is index 0, setCurrentIndex won't emit the currentIndexChanged
339 // signal; workaround the issue by initially setting the currentIndex to -1
340 m_ui.pageSizeCombo->setCurrentIndex(-1);
341 m_ui.pageSizeCombo->setCurrentIndex(m_ui.pageSizeCombo->findData(QVariant::fromValue(defaultSize)));
342 return;
343 }
344 }
345 }
346
347 // If PdfFormat or no available printer page sizes, populate with all page sizes
348 for (int id = 0; id < QPageSize::LastPageSize; ++id) {
350 m_ui.pageSizeCombo->addItem(tr("Custom"));
351 m_realCustomPageSizeIndex = m_ui.pageSizeCombo->count() - 1;
352 } else {
354 m_ui.pageSizeCombo->addItem(pageSize.name(), QVariant::fromValue(pageSize));
355 }
356 }
357
358 m_blockSignals = false;
359}
360
361// Set the dialog to use the given QPrinter
362// Usually only called on first creation
364 QPrinter::OutputFormat outputFormat, const QString &printerName)
365{
366 m_printer = printer;
367 m_printDevice = printDevice;
368
369#if QT_CONFIG(cups)
370 // find the PageSize cups option
371 m_pageSizePpdOption = m_printDevice ? QCUPSSupport::findPpdOption("PageSize", m_printDevice) : nullptr;
372#endif
373
374 // Initialize the layout to the current QPrinter layout
375 m_pageLayout = m_printer->pageLayout();
376
377 // Assume if margins are Points then is by default, so set to locale default units
378 if (m_pageLayout.units() == QPageLayout::Point) {
379 if (QLocale().measurementSystem() == QLocale::MetricSystem)
380 m_pageLayout.setUnits(QPageLayout::Millimeter);
381 else
382 m_pageLayout.setUnits(QPageLayout::Inch);
383 }
384 m_units = m_pageLayout.units();
385 m_pagePreview->setPageLayout(m_pageLayout);
386
387 m_outputFormat = outputFormat;
388 m_printerName = printerName;
389 initPageSizes();
390 updateWidget();
392
393 if (m_ui.pageSizeCombo->currentIndex() == -1) {
394 // This can happen in raw printers that since they don't have a default
395 // page size none will get selected so just default to the first size (A4)
396 m_ui.pageSizeCombo->setCurrentIndex(0);
397 }
398}
399
400// Update the widget with the current settings
401// TODO Break up into more intelligent chunks?
402void QPageSetupWidget::updateWidget()
403{
404 m_blockSignals = true;
405
406 QString suffix;
407 switch (m_units) {
409 //: Unit 'Millimeter'
410 suffix = tr("mm");
411 break;
413 //: Unit 'Points'
414 suffix = tr("pt");
415 break;
417 //: Unit 'Inch'
418 suffix = tr("in");
419 break;
421 //: Unit 'Pica'
422 suffix = tr("P̸");
423 break;
425 //: Unit 'Didot'
426 suffix = tr("DD");
427 break;
429 //: Unit 'Cicero'
430 suffix = tr("CC");
431 break;
432 }
433
434 m_ui.unitCombo->setCurrentIndex(m_ui.unitCombo->findData(QVariant::fromValue(m_units)));
435
436 const bool isCustom = m_ui.pageSizeCombo->currentIndex() == m_realCustomPageSizeIndex && m_realCustomPageSizeIndex != -1;
437 if (!isCustom)
438 m_ui.pageSizeCombo->setCurrentIndex(m_ui.pageSizeCombo->findData(QVariant::fromValue(m_pageLayout.pageSize())));
439
441 QMarginsF max;
442
443 if (m_pageLayout.mode() == QPageLayout::FullPageMode) {
444 min = QMarginsF(0.0, 0.0, 0.0, 0.0);
445 max = QMarginsF(9999.9999, 9999.9999, 9999.9999, 9999.9999);
446 } else {
447 min = m_pageLayout.minimumMargins();
448 max = m_pageLayout.maximumMargins();
449 }
450
451 m_ui.leftMargin->setSuffix(suffix);
452 m_ui.leftMargin->setMinimum(min.left());
453 m_ui.leftMargin->setMaximum(max.left());
454 m_ui.leftMargin->setValue(m_pageLayout.margins().left());
455
456 m_ui.rightMargin->setSuffix(suffix);
457 m_ui.rightMargin->setMinimum(min.right());
458 m_ui.rightMargin->setMaximum(max.right());
459 m_ui.rightMargin->setValue(m_pageLayout.margins().right());
460
461 m_ui.topMargin->setSuffix(suffix);
462 m_ui.topMargin->setMinimum(min.top());
463 m_ui.topMargin->setMaximum(max.top());
464 m_ui.topMargin->setValue(m_pageLayout.margins().top());
465
466 m_ui.bottomMargin->setSuffix(suffix);
467 m_ui.bottomMargin->setMinimum(min.bottom());
468 m_ui.bottomMargin->setMaximum(max.bottom());
469 m_ui.bottomMargin->setValue(m_pageLayout.margins().bottom());
470
471 m_ui.pageWidth->setSuffix(suffix);
472 m_ui.pageWidth->setValue(m_pageLayout.fullRect(m_units).width());
473 m_ui.pageWidth->setEnabled(isCustom);
474 m_ui.widthLabel->setEnabled(isCustom);
475
476 m_ui.pageHeight->setSuffix(suffix);
477 m_ui.pageHeight->setValue(m_pageLayout.fullRect(m_units).height());
478 m_ui.pageHeight->setEnabled(isCustom);
479 m_ui.heightLabel->setEnabled(isCustom);
480
481 m_ui.portrait->setChecked(m_pageLayout.orientation() == QPageLayout::Portrait);
482 m_ui.landscape->setChecked(m_pageLayout.orientation() == QPageLayout::Landscape);
483
484 m_ui.pagesPerSheetButtonGroup->setEnabled(m_outputFormat == QPrinter::NativeFormat);
485
486#ifdef PSD_ENABLE_PAPERSOURCE
487 m_ui.paperSource->setCurrentItem(printer->paperSource());
488#endif
489
490 m_blockSignals = false;
491}
492
493// Set the dialog chosen options on the QPrinter
494// Normally only called when the QPrintDialog or QPageSetupDialog OK button is pressed
496{
497 m_printer->setPageLayout(m_pageLayout);
498 m_printer->setPageOrientation(m_pageLayout.orientation());
499#if QT_CONFIG(cups)
500 QCUPSSupport::PagesPerSheet pagesPerSheet = qvariant_cast<QCUPSSupport::PagesPerSheet>(m_ui.pagesPerSheetCombo->currentData()
501);
502 QCUPSSupport::PagesPerSheetLayout pagesPerSheetLayout = qvariant_cast<QCUPSSupport::PagesPerSheetLayout>(m_ui.pagesPerSheetLayoutCombo->currentData()
503);
504 QCUPSSupport::setPagesPerSheetLayout(m_printer, pagesPerSheet, pagesPerSheetLayout);
505#endif
506#ifdef PSD_ENABLE_PAPERSOURCE
507 m_printer->setPaperSource((QPrinter::PaperSource)m_ui.paperSource->currentIndex());
508#endif
509}
510
512{
513 m_savedUnits = m_units;
514 m_savedPageLayout = m_pageLayout;
515 m_savedPagesPerSheet = m_ui.pagesPerSheetCombo->currentIndex();
516 m_savedPagesPerSheetLayout = m_ui.pagesPerSheetLayoutCombo->currentIndex();
517}
518
520{
521 m_units = m_savedUnits;
522 m_pageLayout = m_savedPageLayout;
523 m_pagePreview->setPageLayout(m_pageLayout);
524
525 updateWidget();
526
527 m_ui.pagesPerSheetCombo->setCurrentIndex(m_savedPagesPerSheet);
528 m_ui.pagesPerSheetLayoutCombo->setCurrentIndex(m_savedPagesPerSheetLayout);
529}
530
531#if QT_CONFIG(cups)
532bool QPageSetupWidget::hasPpdConflict() const
533{
534 if (m_pageSizePpdOption) {
535 if (m_pageSizePpdOption->conflicted) {
536 const QIcon warning = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning, nullptr, nullptr);
537 const int pixmap_size = m_ui.pageSizeCombo->sizeHint().height() * .75;
538 m_ui.pageSizeWarningLabel->setPixmap(warning.pixmap(pixmap_size, pixmap_size));
539 } else {
540 m_ui.pageSizeWarningLabel->setPixmap(QPixmap());
541 }
542 return m_pageSizePpdOption->conflicted;
543 }
544
545 return false;
546}
547#endif
548
549// Updates size/preview after the combobox has been changed.
550void QPageSetupWidget::pageSizeChanged()
551{
552 QPageSize pageSize;
553 if (m_ui.pageSizeCombo->currentIndex() != m_realCustomPageSizeIndex) {
554 pageSize = qvariant_cast<QPageSize>(m_ui.pageSizeCombo->currentData());
555
556#if QT_CONFIG(cups)
557 if (m_pageSizePpdOption) {
558 ppd_file_t *ppd = qvariant_cast<ppd_file_t*>(m_printDevice->property(PDPK_PpdFile));
560 if (!toUtf16.isValid()) {
561 qWarning() << "QPrinSupport: Cups uses unsupported encoding" << ppd->lang_encoding;
563 }
564 for (int i = 0; i < m_pageSizePpdOption->num_choices; ++i) {
565 const ppd_choice_t *choice = &m_pageSizePpdOption->choices[i];
566 if (toUtf16(choice->text) == m_ui.pageSizeCombo->currentText()) {
567 const auto values = QStringList{} << QString::fromLatin1(m_pageSizePpdOption->keyword)
568 << QString::fromLatin1(choice->choice);
569 m_printDevice->setProperty(PDPK_PpdOption, values);
570 emit ppdOptionChanged();
571 break;
572 }
573 }
574 }
575#endif
576
577 } else {
578 QSizeF customSize;
579 if (m_pageLayout.orientation() == QPageLayout::Landscape)
580 customSize = QSizeF(m_ui.pageHeight->value(), m_ui.pageWidth->value());
581 else
582 customSize = QSizeF(m_ui.pageWidth->value(), m_ui.pageHeight->value());
583 pageSize = QPageSize(customSize, QPageSize::Unit(m_units));
584
585#if QT_CONFIG(cups)
586 if (m_pageSizePpdOption) {
587 const auto values = QStringList{} << QString::fromLatin1(m_pageSizePpdOption->keyword)
588 << QStringLiteral("Custom");
589 m_printDevice->setProperty(PDPK_PpdOption, values);
590 emit ppdOptionChanged();
591 }
592#endif
593 }
594
595 // We always need to update the m_pageSizePpdOption when the page size changes
596 // even if it's from inside updateWidget, so do not move up
597 if (m_blockSignals)
598 return;
599
600 const QMarginsF printable = m_printDevice ? m_printDevice->printableMargins(pageSize, m_pageLayout.orientation(), m_printer->resolution())
601 : QMarginsF();
602 m_pageLayout.setPageSize(pageSize, qt_convertMargins(printable, QPageLayout::Point, m_pageLayout.units()));
603 m_pagePreview->setPageLayout(m_pageLayout);
604
605 updateWidget();
606}
607
608void QPageSetupWidget::pageOrientationChanged()
609{
610 if (m_blockSignals)
611 return;
612 m_pageLayout.setOrientation(m_ui.portrait->isChecked() ? QPageLayout::Portrait : QPageLayout::Landscape);
613 m_pagePreview->setPageLayout(m_pageLayout);
614 updateWidget();
615}
616
617void QPageSetupWidget::pagesPerSheetChanged()
618{
619#if QT_CONFIG(cups)
620 switch (m_ui.pagesPerSheetCombo->currentData().toInt()) {
622 m_pagePreview->setPagePreviewLayout(1, 1);
623 break;
625 m_pagePreview->setPagePreviewLayout(1, 2);
626 break;
628 m_pagePreview->setPagePreviewLayout(2, 2);
629 break;
631 m_pagePreview->setPagePreviewLayout(3, 2);
632 break;
634 m_pagePreview->setPagePreviewLayout(3, 3);
635 break;
637 m_pagePreview->setPagePreviewLayout(4, 4);
638 break;
639 }
640#endif
641}
642
643void QPageSetupWidget::unitChanged()
644{
645 if (m_blockSignals)
646 return;
647 m_units = qvariant_cast<QPageLayout::Unit>(m_ui.unitCombo->currentData());
648 m_pageLayout.setUnits(m_units);
649 updateWidget();
650}
651
652void QPageSetupWidget::topMarginChanged(double newValue)
653{
654 if (m_blockSignals)
655 return;
656 m_pageLayout.setTopMargin(newValue);
657 m_pagePreview->setPageLayout(m_pageLayout);
658}
659
660void QPageSetupWidget::bottomMarginChanged(double newValue)
661{
662 if (m_blockSignals)
663 return;
664 m_pageLayout.setBottomMargin(newValue);
665 m_pagePreview->setPageLayout(m_pageLayout);
666}
667
668void QPageSetupWidget::leftMarginChanged(double newValue)
669{
670 if (m_blockSignals)
671 return;
672 m_pageLayout.setLeftMargin(newValue);
673 m_pagePreview->setPageLayout(m_pageLayout);
674}
675
676void QPageSetupWidget::rightMarginChanged(double newValue)
677{
678 if (m_blockSignals)
679 return;
680 m_pageLayout.setRightMargin(newValue);
681 m_pagePreview->setPageLayout(m_pageLayout);
682}
683
684// QPageSetupDialog
685// - Public Linux / CUPS class implementation
686
688 : QDialog(*(new QUnixPageSetupDialogPrivate(printer)), parent)
689{
690 Q_D(QPageSetupDialog);
691 setWindowTitle(QCoreApplication::translate("QPrintPreviewDialog", "Page Setup"));
692 static_cast<QUnixPageSetupDialogPrivate *>(d)->init();
693}
694
697{
698 Q_D(QPageSetupDialog);
699 setWindowTitle(QCoreApplication::translate("QPrintPreviewDialog", "Page Setup"));
700 static_cast<QUnixPageSetupDialogPrivate *>(d)->init();
701}
702
704{
705 Q_D(QPageSetupDialog);
706
707 int ret = QDialog::exec();
708 if (ret == Accepted) {
709 static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->setupPrinter();
710 static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->updateSavedValues();
711 } else {
712 static_cast <QUnixPageSetupDialogPrivate*>(d)->widget->revertToSavedValues();
713 }
714 return ret;
715}
716
718
719#include "moc_qpagesetupdialog_unix_p.cpp"
720
721#include "moc_qpagesetupdialog.cpp"
void clicked(bool checked=false)
This signal is emitted when the button is activated (i.e., pressed down then released while the mouse...
static QStyle * style()
Returns the application's style object.
@ OnePagePerSheet
Definition qcups_p.h:80
@ NinePagesPerSheet
Definition qcups_p.h:84
@ SixteenPagesPerSheet
Definition qcups_p.h:85
@ FourPagesPerSheet
Definition qcups_p.h:82
@ TwoPagesPerSheet
Definition qcups_p.h:81
@ SixPagesPerSheet
Definition qcups_p.h:83
PagesPerSheetLayout
Definition qcups_p.h:89
@ BottomToTopLeftToRight
Definition qcups_p.h:94
@ LeftToRightBottomToTop
Definition qcups_p.h:91
@ BottomToTopRightToLeft
Definition qcups_p.h:95
@ TopToBottomLeftToRight
Definition qcups_p.h:96
@ LeftToRightTopToBottom
Definition qcups_p.h:90
@ RightToLeftTopToBottom
Definition qcups_p.h:92
@ RightToLeftBottomToTop
Definition qcups_p.h:93
@ TopToBottomRightToLeft
Definition qcups_p.h:97
static ppd_option_t * findPpdOption(const char *optionName, QPrintDevice *printDevice)
Definition qcups.cpp:125
static void setPagesPerSheetLayout(QPrinter *printer, const PagesPerSheet pagesPerSheet, const PagesPerSheetLayout pagesPerSheetLayout)
Definition qcups.cpp:234
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
void setAlpha(int alpha)
Sets the alpha of this color to alpha.
Definition qcolor.cpp:1481
void activated(int index)
This signal is sent when the user chooses an item in the combobox.
void currentIndexChanged(int index)
static QString translate(const char *context, const char *key, const char *disambiguation=nullptr, int n=-1)
\threadsafe
The QDialogButtonBox class is a widget that presents buttons in a layout that is appropriate to the c...
The QDialog class is the base class of dialog windows.
Definition qdialog.h:19
virtual int exec()
Shows the dialog as a \l{QDialog::Modal Dialogs}{modal dialog}, blocking until the user closes it.
Definition qdialog.cpp:543
@ Accepted
Definition qdialog.h:30
void valueChanged(double)
This signal is emitted whenever the spin box's value is changed.
\reentrant
Definition qfont.h:22
qreal pointSizeF() const
Returns the point size of the font.
Definition qfont.cpp:1034
void setPointSizeF(qreal)
Sets the point size to pointSize.
Definition qfont.cpp:1010
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
@ MetricSystem
Definition qlocale.h:868
\inmodule QtCore
Definition qmargins.h:270
constexpr qreal right() const noexcept
Returns the right margin.
Definition qmargins.h:383
constexpr qreal left() const noexcept
Returns the left margin.
Definition qmargins.h:377
constexpr qreal top() const noexcept
Returns the top margin.
Definition qmargins.h:380
constexpr qreal bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:386
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\inmodule QtGui
Definition qpagelayout.h:20
QMarginsF minimumMargins() const
Returns the minimum margins of the page layout.
void setOrientation(Orientation orientation)
Sets the page orientation of the page layout to orientation.
QRect fullRectPoints() const
Returns the full page rectangle in Postscript Points (1/72 of an inch).
Mode mode() const
Returns the page layout mode.
QRectF fullRect() const
Returns the full page rectangle in the current layout units.
void setUnits(Unit units)
Sets the units used to define the page layout.
bool setTopMargin(qreal topMargin, OutOfBoundsPolicy outOfBoundsPolicy=OutOfBoundsPolicy::Reject)
Sets the top page margin of the page layout to topMargin.
Unit units() const
Returns the units the page layout is currently defined in.
bool setRightMargin(qreal rightMargin, OutOfBoundsPolicy outOfBoundsPolicy=OutOfBoundsPolicy::Reject)
Sets the right page margin of the page layout to rightMargin.
Unit
This enum type is used to specify the measurement unit for page layout and margins.
Definition qpagelayout.h:24
QMarginsF margins() const
Returns the margins of the page layout using the currently set units.
bool setBottomMargin(qreal bottomMargin, OutOfBoundsPolicy outOfBoundsPolicy=OutOfBoundsPolicy::Reject)
Sets the bottom page margin of the page layout to bottomMargin.
Orientation orientation() const
Returns the page orientation of the page layout.
QMarginsF maximumMargins() const
Returns the maximum margins that would be applied if the page layout was in StandardMode.
bool setLeftMargin(qreal leftMargin, OutOfBoundsPolicy outOfBoundsPolicy=OutOfBoundsPolicy::Reject)
Sets the left page margin of the page layout to leftMargin.
void setPageSize(const QPageSize &pageSize, const QMarginsF &minMargins=QMarginsF(0, 0, 0, 0))
Sets the page size of the page layout to pageSize.
QPageSize pageSize() const
Returns the page size of the page layout.
void setPageLayout(const QPageLayout &layout)
void setPagePreviewLayout(int columns, int rows)
QPagePreview(QWidget *parent)
void paintEvent(QPaintEvent *) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
The QPageSetupDialog class provides a configuration dialog for the page-related options on a printer.
QPageSetupDialog(QPrinter *printer, QWidget *parent=nullptr)
Constructs a page setup dialog that configures printer with parent as the parent widget.
int exec() override
This virtual function is called to pop up the dialog.
void setPrinter(QPrinter *printer, QPrintDevice *printDevice, QPrinter::OutputFormat outputFormat, const QString &printerName)
QPageSetupWidget(QWidget *parent=nullptr)
\inmodule QtGui
Definition qpagesize.h:22
Unit
This enum type is used to specify the measurement unit for page sizes.
Definition qpagesize.h:175
QString name() const
Returns a localized human-readable name for the page size.
PageSizeId
This enum type lists the available page sizes as defined in the Postscript PPD standard.
Definition qpagesize.h:25
virtual bool setPageOrientation(QPageLayout::Orientation orientation)
QPageLayout pageLayout() const
virtual bool setPageLayout(const QPageLayout &pageLayout)
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtGui
Definition qpen.h:28
static QPlatformPrinterSupport * get()
The QPlatformPrinterSupport class provides an abstraction for print support.
virtual QPrintDevice createPrintDevice(const QString &id)
\inmodule QtCore\reentrant
Definition qpoint.h:25
QVariant property(PrintDevicePropertyKey key) const
bool setProperty(PrintDevicePropertyKey key, const QVariant &value)
QMarginsF printableMargins(const QPageSize &pageSize, QPageLayout::Orientation orientation, int resolution) const
\reentrant
Definition qprinter.h:28
PaperSource
This enum type specifies what paper source QPrinter is to use.
Definition qprinter.h:45
void setPaperSource(PaperSource)
Sets the paper source setting to source.
OutputFormat
The OutputFormat enum is used to describe the format QPrinter should use for printing.
Definition qprinter.h:69
@ NativeFormat
Definition qprinter.h:69
int resolution() const
Returns the current assumed resolution of the printer, as set by setResolution() or by the printer dr...
QString printerName() const
Returns the printer name.
Definition qprinter.cpp:621
OutputFormat outputFormat() const
Definition qprinter.cpp:570
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void moveCenter(const QPoint &p) noexcept
Moves the rectangle, leaving the center point at the given position.
Definition qrect.h:328
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition qrect.h:370
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
\inmodule QtCore
Definition qsize.h:208
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
Definition qsize.h:401
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:332
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:335
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
QSize scaled(int w, int h, Qt::AspectRatioMode mode) const noexcept
Definition qsize.h:151
\inmodule QtCore
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
@ SP_MessageBoxWarning
Definition qstyle.h:727
QUnixPageSetupDialogPrivate(QPrinter *printer)
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
\inmodule QtCore
Definition qvariant.h:65
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:536
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
void setMinimumSize(const QSize &)
Definition qwidget.h:832
void setSizePolicy(QSizePolicy)
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
QPalette palette
the widget's palette
Definition qwidget.h:132
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
int y
the y coordinate of the widget relative to its parent and including any window frame
Definition qwidget.h:110
int x
the x coordinate of the widget relative to its parent including any window frame
Definition qwidget.h:109
void update()
Updates the widget unless updates are disabled or the widget is hidden.
friend class QPixmap
Definition qwidget.h:748
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
QFont font
the font currently set for the widget
Definition qwidget.h:133
QOpenGLWidget * widget
[1]
QString text
qreal spacing
QRect textRect
Combined button and popup list for selecting options.
constexpr const T & min(const T &a, const T &b)
Definition qnumeric.h:366
@ AlignVCenter
Definition qnamespace.h:155
@ WA_WState_Polished
Definition qnamespace.h:332
@ KeepAspectRatio
@ Horizontal
Definition qnamespace.h:99
@ TextWordWrap
Definition qnamespace.h:174
@ DotLine
#define PDPK_PpdFile
Definition qcups_p.h:37
#define PDPK_PpdOption
Definition qcups_p.h:38
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
#define qWarning
Definition qlogging.h:166
return ret
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLenum GLsizei GLsizei GLint * values
[15]
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint id
[7]
GLdouble GLdouble GLdouble GLdouble top
GLdouble GLdouble right
GLuint color
[2]
GLint left
GLint GLint bottom
GLenum GLuint GLintptr offset
GLuint name
GLint y
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
Q_GUI_EXPORT QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits)
QMarginsF qt_convertMargins(const QMarginsF &margins, QPageLayout::Unit fromUnits, QPageLayout::Unit toUnits)
QDebug warning(QAnyStringView fileName, int lineNumber)
#define QStringLiteral(str)
#define QT_CONFIG(feature)
#define tr(X)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define emit
double qreal
Definition qtypes.h:187
if(qFloatDistance(a, b)<(1<< 7))
[0]
QObject::connect nullptr
scene addItem(form)