obsolescence QPrinter changes

This commit is contained in:
LoudSnorer 2023-02-17 17:09:18 -05:00
parent 93c58ccb52
commit 9fbe20b3a3
2 changed files with 13 additions and 8 deletions

View File

@ -7,12 +7,16 @@
* License. See the file COPYING in the main directory of the source code
* for more details. */
#define TEST_MACROS_ENABLEDoff
#include <test_macros.h>
#include <QMessageBox>
#include <QtPrintSupport/qprinter.h>
#include <QtPrintSupport/qprintdialog.h>
#include <QTextDocument>
#include <QApplication>
#include <cmath>
#include <QPageLayout>
#include "reports.h"
#include "mainwindow.h"
@ -31,6 +35,7 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
{
if (!gv) { return; }
Session *journal = nullptr;
//QDate d=QDate::currentDate();
@ -78,10 +83,10 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
printer->setOutputFileName(filename);
#endif
printer->setPrintRange(QPrinter::AllPages);
printer->setOrientation(QPrinter::Portrait);
printer->setPageOrientation(QPageLayout::Portrait);
printer->setFullPage(false); // This has nothing to do with scaling
printer->setNumCopies(1);
printer->setPageMargins(10, 10, 10, 10, QPrinter::Millimeter);
printer->setCopyCount(1);
printer->setPageMargins(QMarginsF(10, 10, 10, 10), QPageLayout::Millimeter);
QPrintDialog dialog(printer);
#ifdef Q_OS_MAC
// QTBUG-17913
@ -104,9 +109,8 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
GLint gw;
gw = 2048; // Rough guess.. No GL_MAX_RENDERBUFFER_SIZE in mingw.. :(
//QSizeF pxres=printer->paperSize(QPrinter::DevicePixel);
QRect prect = printer->pageRect();
QRect prect = printer->pageLayout().paintRectPixels( printer->resolution() ) ;
float ratio = float(prect.height()) / float(prect.width());
float virt_width = gw;
float virt_height = virt_width * ratio;

View File

@ -1325,12 +1325,13 @@ void Statistics::printReport(QWidget * parent) {
#endif
printer.setPrintRange(QPrinter::AllPages);
printer.setOrientation(QPrinter::Portrait);
printer.setPageOrientation(QPageLayout::Portrait);
printer.setFullPage(false); // Print only on printable area of page and not in non-printable margins
printer.setNumCopies(1);
printer.setCopyCount(1);
QMarginsF minMargins = printer.pageLayout().margins(QPageLayout::Millimeter);
printer.setPageMargins(fmax(10,minMargins.left()), fmax(10,minMargins.top()), fmax(10,minMargins.right()), fmax(12,minMargins.bottom()), QPrinter::Millimeter);
printer.setPageMargins( QMarginsF( fmax(10,minMargins.left()), fmax(10,minMargins.top()), fmax(10,minMargins.right()), fmax(12,minMargins.bottom())), QPageLayout::Millimeter);
QMarginsF setMargins = printer.pageLayout().margins(QPageLayout::Millimeter);
qDebug () << "Min margins" << minMargins << "Set margins" << setMargins << "millimeters";