diff options
Diffstat (limited to 'src/printsupport/dialogs/qprintdialog_unix.cpp')
-rw-r--r-- | src/printsupport/dialogs/qprintdialog_unix.cpp | 142 |
1 files changed, 57 insertions, 85 deletions
diff --git a/src/printsupport/dialogs/qprintdialog_unix.cpp b/src/printsupport/dialogs/qprintdialog_unix.cpp index 6dcb613ff5..aab5e2c7f0 100644 --- a/src/printsupport/dialogs/qprintdialog_unix.cpp +++ b/src/printsupport/dialogs/qprintdialog_unix.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qplatformdefs.h" #include <QtPrintSupport/private/qtprintsupportglobal_p.h> @@ -54,12 +18,11 @@ #include <QtCore/qstringconverter.h> #include <QtGui/qevent.h> #if QT_CONFIG(filesystemmodel) -#include <QtWidgets/qfilesystemmodel.h> +#include <QtGui/qfilesystemmodel.h> #endif #include <QtWidgets/qstyleditemdelegate.h> #include <QtWidgets/qformlayout.h> #include <QtPrintSupport/qprinter.h> -#include <QtGui/qrangecollection.h> #include <qpa/qplatformprintplugin.h> #include <qpa/qplatformprintersupport.h> @@ -120,13 +83,15 @@ Print dialog class declarations Layout in qprintpropertieswidget.ui */ -static void initResources() +static void _q_pdu_initResources() { Q_INIT_RESOURCE(qprintdialog); } QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QPrintPropertiesDialog : public QDialog { Q_OBJECT @@ -209,7 +174,7 @@ public: QUnixPrintWidget * const parent; QPrintPropertiesDialog *propertiesDialog; Ui::QPrintWidget widget; - QAbstractPrintDialog * q; + QPrintDialog * q; QPrinter *printer; QPrintDevice m_currentPrintDevice; @@ -357,7 +322,7 @@ void QPrintPropertiesDialog::reject() void QPrintPropertiesDialog::accept() { -#if QT_CONFIG(cups) +#if QT_CONFIG(cups) && QT_CONFIG(messagebox) if (widget.pageSetup->hasPpdConflict()) { widget.tabs->setCurrentWidget(widget.tabPage); const QMessageBox::StandardButton answer = QMessageBox::warning(this, tr("Page Setup Conflicts"), @@ -619,7 +584,7 @@ QPrintDialogPrivate::QPrintDialogPrivate() : top(nullptr), bottom(nullptr), buttons(nullptr), collapseButton(nullptr), explicitDuplexMode(QPrint::DuplexAuto) { - initResources(); + _q_pdu_initResources(); } QPrintDialogPrivate::~QPrintDialogPrivate() @@ -634,9 +599,9 @@ void QPrintDialogPrivate::init() bottom = new QWidget(q); options.setupUi(bottom); options.color->setIconSize(QSize(32, 32)); - options.color->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-color.png"))); + options.color->setIcon(QIcon(":/qt-project.org/dialogs/qprintdialog/images/status-color.png"_L1)); options.grayscale->setIconSize(QSize(32, 32)); - options.grayscale->setIcon(QIcon(QLatin1String(":/qt-project.org/dialogs/qprintdialog/images/status-gray-scale.png"))); + options.grayscale->setIcon(QIcon(":/qt-project.org/dialogs/qprintdialog/images/status-gray-scale.png"_L1)); #if QT_CONFIG(cups) // Add Page Set widget if CUPS is available @@ -709,13 +674,14 @@ void QPrintDialogPrivate::selectPrinter(const QPrinter::OutputFormat outputForma else options.grayscale->setChecked(true); - // keep duplex value explicitly set by user, if any, and selected printer supports it; - // use device default otherwise + // duplex priorities to be as follows: + // 1) a user-selected duplex value in the dialog has highest priority + // 2) duplex value set in the QPrinter QPrint::DuplexMode duplex; if (explicitDuplexMode != QPrint::DuplexAuto && supportedDuplexMode.contains(explicitDuplexMode)) duplex = explicitDuplexMode; else - duplex = top->d->m_currentPrintDevice.defaultDuplexMode(); + duplex = static_cast<QPrint::DuplexMode>(p->duplex()); switch (duplex) { case QPrint::DuplexNone: options.noDuplex->setChecked(true); break; @@ -797,39 +763,42 @@ void QPrintDialogPrivate::setupPrinter() // print range if (options.printAll->isChecked()) { p->setPrintRange(QPrinter::AllPages); - p->setFromTo(0,0); + p->setPageRanges(QPageRanges()); } else if (options.printSelection->isChecked()) { p->setPrintRange(QPrinter::Selection); - p->setFromTo(0,0); + p->setPageRanges(QPageRanges()); } else if (options.printCurrentPage->isChecked()) { p->setPrintRange(QPrinter::CurrentPage); - p->setFromTo(0,0); + p->setPageRanges(QPageRanges()); } else if (options.printRange->isChecked()) { - if (q->isOptionEnabled(QPrintDialog::PrintPageRange)) { + if (q->testOption(QPrintDialog::PrintPageRange)) { p->setPrintRange(QPrinter::PageRange); p->setFromTo(options.from->value(), qMax(options.from->value(), options.to->value())); } else { // This case happens when CUPS server-side page range is enabled // Setting the range to the printer occurs below p->setPrintRange(QPrinter::AllPages); - p->setFromTo(0,0); + p->setPageRanges(QPageRanges()); } } #if QT_CONFIG(cups) if (options.pagesRadioButton->isChecked()) { - p->setPrintRange(QPrinter::PageRange); - p->rangeCollection()->parse(options.pagesLineEdit->text()); + const QPageRanges ranges = QPageRanges::fromString(options.pagesLineEdit->text()); + if (!ranges.isEmpty()) { + p->setPrintRange(QPrinter::PageRange); + p->setPageRanges(ranges); + } // server-side page filtering - QCUPSSupport::setPageRange(p, p->rangeCollection()->toString()); + QCUPSSupport::setPageRange(p, ranges.toString()); } // page set if (p->printRange() == QPrinter::AllPages || p->printRange() == QPrinter::PageRange) { //If the application is selecting pages and the first page number is even then need to adjust the odd-even accordingly QCUPSSupport::PageSet pageSet = qvariant_cast<QCUPSSupport::PageSet>(options.pageSetCombo->itemData(options.pageSetCombo->currentIndex())); - if (q->isOptionEnabled(QPrintDialog::PrintPageRange) + if (q->testOption(QPrintDialog::PrintPageRange) && p->printRange() == QPrinter::PageRange && (q->fromPage() % 2 == 0)) { @@ -849,7 +818,7 @@ void QPrintDialogPrivate::setupPrinter() // server-side page range, since we set the page range on the printer to 0-0/AllPages above, // we need to take the values directly from the widget as q->fromPage() will return 0 - if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) && options.printRange->isChecked()) + if (!q->testOption(QPrintDialog::PrintPageRange) && options.printRange->isChecked()) QCUPSSupport::setPageRange(p, options.from->value(), qMax(options.from->value(), options.to->value())); } #endif @@ -898,19 +867,19 @@ void QPrintDialogPrivate::_q_checkFields() void QPrintDialogPrivate::updateWidgets() { Q_Q(QPrintDialog); - options.gbPrintRange->setVisible(q->isOptionEnabled(QPrintDialog::PrintPageRange) || - q->isOptionEnabled(QPrintDialog::PrintSelection) || - q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); + options.gbPrintRange->setVisible(q->testOption(QPrintDialog::PrintPageRange) || + q->testOption(QPrintDialog::PrintSelection) || + q->testOption(QPrintDialog::PrintCurrentPage)); - options.printRange->setEnabled(q->isOptionEnabled(QPrintDialog::PrintPageRange)); - options.printSelection->setVisible(q->isOptionEnabled(QPrintDialog::PrintSelection)); - options.printCurrentPage->setVisible(q->isOptionEnabled(QPrintDialog::PrintCurrentPage)); - options.collate->setVisible(q->isOptionEnabled(QPrintDialog::PrintCollateCopies)); + options.printRange->setEnabled(q->testOption(QPrintDialog::PrintPageRange)); + options.printSelection->setVisible(q->testOption(QPrintDialog::PrintSelection)); + options.printCurrentPage->setVisible(q->testOption(QPrintDialog::PrintCurrentPage)); + options.collate->setVisible(q->testOption(QPrintDialog::PrintCollateCopies)); #if QT_CONFIG(cups) // Don't display Page Set if only Selection or Current Page are enabled - if (!q->isOptionEnabled(QPrintDialog::PrintPageRange) - && (q->isOptionEnabled(QPrintDialog::PrintSelection) || q->isOptionEnabled(QPrintDialog::PrintCurrentPage))) { + if (!q->testOption(QPrintDialog::PrintPageRange) + && (q->testOption(QPrintDialog::PrintSelection) || q->testOption(QPrintDialog::PrintCurrentPage))) { options.pageSetCombo->setVisible(false); options.pageSetLabel->setVisible(false); } else { @@ -918,7 +887,7 @@ void QPrintDialogPrivate::updateWidgets() options.pageSetLabel->setVisible(true); } - if (!q->isOptionEnabled(QPrintDialog::PrintPageRange)) { + if (!q->testOption(QPrintDialog::PrintPageRange)) { // If we can do CUPS server side pages selection, // display the page range widgets options.gbPrintRange->setVisible(true); @@ -940,7 +909,7 @@ void QPrintDialogPrivate::updateWidgets() options.pageSetCombo->setEnabled(true); break; case QPrintDialog::CurrentPage: - if (q->isOptionEnabled(QPrintDialog::PrintCurrentPage)) { + if (q->testOption(QPrintDialog::PrintCurrentPage)) { options.printCurrentPage->setChecked(true); options.pageSetCombo->setEnabled(false); } @@ -1021,8 +990,8 @@ int QPrintDialog::exec() void QPrintDialog::accept() { Q_D(QPrintDialog); -#if QT_CONFIG(cups) - if (d->options.pagesRadioButton->isChecked() && printer()->rangeCollection()->isEmpty()) { +#if QT_CONFIG(cups) && QT_CONFIG(messagebox) + if (d->options.pagesRadioButton->isChecked() && printer()->pageRanges().isEmpty()) { QMessageBox::critical(this, tr("Invalid Pages Definition"), tr("%1 does not follow the correct syntax. Please use ',' to separate " "ranges and pages, '-' to define ranges and make sure ranges do " @@ -1066,7 +1035,7 @@ QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p, QPrinter * { q = nullptr; if (parent) - q = qobject_cast<QAbstractPrintDialog*> (parent->parent()); + q = qobject_cast<QPrintDialog*> (parent->parent()); widget.setupUi(parent); @@ -1104,12 +1073,14 @@ QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(QUnixPrintWidget *p, QPrinter * void QUnixPrintWidgetPrivate::updateWidget() { - const bool printToFile = q == nullptr || q->isOptionEnabled(QPrintDialog::PrintToFile); + const bool printToFile = q == nullptr || q->testOption(QPrintDialog::PrintToFile); if (printToFile && !filePrintersAdded) { if (widget.printers->count()) widget.printers->insertSeparator(widget.printers->count()); widget.printers->addItem(QPrintDialog::tr("Print to File (PDF)")); filePrintersAdded = true; + if (widget.printers->count() == 1) + _q_printerChanged(0); } if (!printToFile && filePrintersAdded) { widget.printers->removeItem(widget.printers->count()-1); @@ -1131,7 +1102,8 @@ void QUnixPrintWidgetPrivate::updateWidget() widget.lOutput->setVisible(printToFile); widget.fileBrowser->setVisible(printToFile); - widget.properties->setVisible(q->isOptionEnabled(QAbstractPrintDialog::PrintShowPageSize)); + if (q) + widget.properties->setVisible(q->testOption(QAbstractPrintDialog::PrintShowPageSize)); } QUnixPrintWidgetPrivate::~QUnixPrintWidgetPrivate() @@ -1166,10 +1138,10 @@ void QUnixPrintWidgetPrivate::_q_printerChanged(int index) QString filename = widget.filename->text(); widget.filename->setText(filename); widget.lOutput->setEnabled(true); - if (optionsPane) - optionsPane->selectPrinter(QPrinter::PdfFormat); printer->setOutputFormat(QPrinter::PdfFormat); m_currentPrintDevice = QPrintDevice(); + if (optionsPane) + optionsPane->selectPrinter(QPrinter::PdfFormat); return; } } @@ -1278,7 +1250,7 @@ void QUnixPrintWidgetPrivate::setupPrinterProperties() QPrinter::OutputFormat outputFormat; QString printerName; - if (q->isOptionEnabled(QPrintDialog::PrintToFile) + if (q->testOption(QPrintDialog::PrintToFile) && (widget.printers->currentIndex() == widget.printers->count() - 1)) {// PDF outputFormat = QPrinter::PdfFormat; } else { @@ -1350,15 +1322,15 @@ QUnixPrintWidget::QUnixPrintWidget(QPrinter *printer, QWidget *parent) if (printer->outputFileName().isEmpty()) { QString home = QDir::homePath(); QString cur = QDir::currentPath(); - if (!home.endsWith(QLatin1Char('/'))) - home += QLatin1Char('/'); + if (!home.endsWith(u'/')) + home += u'/'; if (!cur.startsWith(home)) cur = home; - else if (!cur.endsWith(QLatin1Char('/'))) - cur += QLatin1Char('/'); - if (QGuiApplication::platformName() == QStringLiteral("xcb")) { + else if (!cur.endsWith(u'/')) + cur += u'/'; + if (QGuiApplication::platformName() == "xcb"_L1) { if (printer->docName().isEmpty()) { - cur += QStringLiteral("print.pdf"); + cur += "print.pdf"_L1; } else { #if QT_CONFIG(regularexpression) const QRegularExpression re(QStringLiteral("(.*)\\.\\S+")); @@ -1368,7 +1340,7 @@ QUnixPrintWidget::QUnixPrintWidget(QPrinter *printer, QWidget *parent) else #endif cur += printer->docName(); - cur += QStringLiteral(".pdf"); + cur += ".pdf"_L1; } } // xcb |