diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,6 +193,7 @@ core/utils.cpp core/view.cpp core/fileprinter.cpp + core/printoptionswidget.cpp core/script/event.cpp core/synctex/synctex_parser.c core/synctex/synctex_parser_utils.c @@ -225,6 +226,7 @@ core/tile.h core/utils.h core/fileprinter.h + core/printoptionswidget.h core/observer.h ${CMAKE_CURRENT_BINARY_DIR}/core/version.h ${CMAKE_CURRENT_BINARY_DIR}/core/okularcore_export.h diff --git a/core/document.h b/core/document.h --- a/core/document.h +++ b/core/document.h @@ -57,6 +57,7 @@ class MovieAction; class Page; class PixmapRequest; +class PrintOptionsWidget; class RenditionAction; class SourceReference; class View; @@ -718,7 +719,7 @@ * Returns a custom printer configuration page or 0 if no * custom printer configuration page is available. */ - QWidget* printConfigurationWidget() const; + PrintOptionsWidget* printConfigurationWidget() const; /** * Fill the KConfigDialog @p dialog with the setting pages of the diff --git a/core/document.cpp b/core/document.cpp --- a/core/document.cpp +++ b/core/document.cpp @@ -4438,7 +4438,7 @@ return QString(); } -QWidget* Document::printConfigurationWidget() const +PrintOptionsWidget* Document::printConfigurationWidget() const { if ( d->m_generator ) { diff --git a/core/fileprinter.cpp b/core/fileprinter.cpp --- a/core/fileprinter.cpp +++ b/core/fileprinter.cpp @@ -615,8 +615,10 @@ if (printer.printEngine()->property(QPrintEngine::PPK_PageMargins).isNull()) { return QStringList(); } else { - qreal l, t, r, b; - printer.getPageMargins( &l, &t, &r, &b, QPrinter::Point ); + qreal l(0), t(0), r(0), b(0); + if (!printer.fullPage()) { + printer.getPageMargins( &l, &t, &r, &b, QPrinter::Point ); + } return QStringList(QStringLiteral("-o")) << QStringLiteral("page-left=%1").arg(l) << QStringLiteral("-o") << QStringLiteral("page-top=%1").arg(t) << QStringLiteral("-o") << QStringLiteral("page-right=%1").arg(r) diff --git a/core/printoptionswidget.h b/core/printoptionswidget.h new file mode 100644 --- /dev/null +++ b/core/printoptionswidget.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2018 Michael Weghorn * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef PRINTOPTIONSWIDGET_H +#define PRINTOPTIONSWIDGET_H + +#include + +#include "okularcore_export.h" + +class QCheckBox; +class QVBoxLayout; + +namespace Okular { + +/** + * @short The default okular extra print options widget. + * + * If you want to provide extra options in your generator + * you can add them doing + * vLayout()->insertWidget(vLayout()->count() - 1, myWidget); + * since the last item of the layout is a stretch + */ +class OKULARCORE_EXPORT PrintOptionsWidget : public QWidget +{ + Q_OBJECT + + public: + explicit PrintOptionsWidget(QWidget *parent = nullptr); + + bool ignorePrintMargins() const; + + QVBoxLayout *vLayout() const; + + private: + QCheckBox *m_ignorePrintMargins; +}; + +} + +#endif diff --git a/core/printoptionswidget.cpp b/core/printoptionswidget.cpp new file mode 100644 --- /dev/null +++ b/core/printoptionswidget.cpp @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2018 Michael Weghorn * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include "printoptionswidget.h" + +#include +#include + +#include + +namespace Okular { + +PrintOptionsWidget::PrintOptionsWidget(QWidget *parent) + : QWidget(parent) +{ + setWindowTitle( i18n( "Print Options" ) ); + QVBoxLayout *layout = new QVBoxLayout(this); + m_ignorePrintMargins = new QCheckBox(i18n("Ignore print margins"), this); + m_ignorePrintMargins->setToolTip(i18n("Don't leave print margins blank when scaling the printout")); + m_ignorePrintMargins->setWhatsThis(i18n("Don't consider print margins when scaling the printout. This means that the margins set in the \"Properties\" dialog are not taken into account.")); + layout->addWidget(m_ignorePrintMargins); + layout->addStretch(1); + + m_ignorePrintMargins->setChecked( false ); +} + +bool PrintOptionsWidget::ignorePrintMargins() const +{ + return m_ignorePrintMargins->isChecked(); +} + +QVBoxLayout *PrintOptionsWidget::vLayout() const +{ + return static_cast(layout()); +} + +} diff --git a/generators/poppler/generator_pdf.h b/generators/poppler/generator_pdf.h --- a/generators/poppler/generator_pdf.h +++ b/generators/poppler/generator_pdf.h @@ -31,6 +31,7 @@ namespace Okular { class ObjectRect; class SourceReference; +class PrintOptionsWidget; } class PDFOptionsPage; @@ -94,7 +95,7 @@ bool exportTo( const QString &fileName, const Okular::ExportFormat &format ) override; // [INHERITED] print interface - QWidget* printConfigurationWidget() const override; + Okular::PrintOptionsWidget* printConfigurationWidget() const override; // [INHERITED] save interface bool supportsOption( SaveOption ) const override; diff --git a/generators/poppler/generator_pdf.cpp b/generators/poppler/generator_pdf.cpp --- a/generators/poppler/generator_pdf.cpp +++ b/generators/poppler/generator_pdf.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include "ui_pdfsettingswidget.h" @@ -70,24 +71,22 @@ static const int defaultPageWidth = 595; static const int defaultPageHeight = 842; -class PDFOptionsPage : public QWidget +class PDFOptionsPage : public Okular::PrintOptionsWidget { Q_OBJECT public: - PDFOptionsPage() + PDFOptionsPage() : PrintOptionsWidget() { setWindowTitle( i18n( "PDF Options" ) ); - QVBoxLayout *layout = new QVBoxLayout(this); m_printAnnots = new QCheckBox(i18n("Print annotations"), this); m_printAnnots->setToolTip(i18n("Include annotations in the printed document")); m_printAnnots->setWhatsThis(i18n("Includes annotations in the printed document. You can disable this if you want to print the original unannotated document.")); - layout->addWidget(m_printAnnots); + vLayout()->insertWidget(vLayout()->count() - 1, m_printAnnots); m_forceRaster = new QCheckBox(i18n("Force rasterization"), this); m_forceRaster->setToolTip(i18n("Rasterize into an image before printing")); m_forceRaster->setWhatsThis(i18n("Forces the rasterization of each page into an image before printing it. This usually gives somewhat worse results, but is useful when printing documents that appear to print incorrectly.")); - layout->addWidget(m_forceRaster); - layout->addStretch(1); + vLayout()->insertWidget(vLayout()->count() - 1, m_forceRaster); #if defined(Q_OS_WIN) && !defined HAVE_POPPLER_0_60 m_printAnnots->setVisible( false ); @@ -1875,7 +1874,7 @@ return lastPrintError; } -QWidget* PDFGenerator::printConfigurationWidget() const +Okular::PrintOptionsWidget* PDFGenerator::printConfigurationWidget() const { if ( !pdfOptionsPage ) { diff --git a/interfaces/printinterface.h b/interfaces/printinterface.h --- a/interfaces/printinterface.h +++ b/interfaces/printinterface.h @@ -14,10 +14,10 @@ #include -class QWidget; - namespace Okular { +class PrintOptionsWidget; + /** * @short Abstract interface for advanced printing control * @@ -50,7 +50,7 @@ * @note don't keep a pointer to the new constructed widget, as it * will be handled elsewhere (in the Okular KPart) */ - virtual QWidget* printConfigurationWidget() const = 0; + virtual PrintOptionsWidget* printConfigurationWidget() const = 0; }; } diff --git a/part.cpp b/part.cpp --- a/part.cpp +++ b/part.cpp @@ -115,6 +115,7 @@ #include "core/generator.h" #include "core/page.h" #include "core/fileprinter.h" +#include "core/printoptionswidget.h" #include #ifdef OKULAR_KEEP_FILE_OPEN @@ -3188,7 +3189,7 @@ QPrinter printer; #endif QPrintDialog *printDialog = nullptr; - QWidget *printConfigWidget = nullptr; + PrintOptionsWidget *printConfigWidget = nullptr; // Must do certain QPrinter setup before creating QPrintDialog setupPrint( printer ); @@ -3198,14 +3199,18 @@ { printConfigWidget = m_document->printConfigurationWidget(); } + else + { + printConfigWidget = new PrintOptionsWidget(); + } printDialog = new QPrintDialog(&printer, widget()); printDialog->setWindowTitle(i18nc("@title:window", "Print")); QList options; if (printConfigWidget) { options << printConfigWidget; } - printDialog->setOptionTabs(options); + printDialog->setOptionTabs(options); if ( printDialog ) { @@ -3235,7 +3240,10 @@ bool success = true; if ( printDialog->exec() ) + { + printer.setFullPage( printConfigWidget->ignorePrintMargins() ); success = doPrint( printer ); + } delete printDialog; if ( m_cliPrintAndExit ) exit ( success ? EXIT_SUCCESS : EXIT_FAILURE );