diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index e5acc963f..172c41fa4 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -3153,7 +3153,6 @@ void MainWindow::SetLayoutModeActions(bool enable) ui->actionExportAs->setEnabled(value); ui->actionPrintPreview->setEnabled(value); ui->actionPrintPreviewTiled->setEnabled(value); - ui->actionSaveAsPDF->setEnabled(value); ui->actionSaveAsTiledPDF->setEnabled(value); ui->actionPrint->setEnabled(value); ui->actionPrintTiled->setEnabled(value); @@ -3645,7 +3644,6 @@ void MainWindow::CreateActions() connect(ui->actionExportAs, &QAction::triggered, this, &MainWindow::ExportLayoutAs); connect(ui->actionPrintPreview, &QAction::triggered, this, &MainWindow::PrintPreviewOrigin); connect(ui->actionPrintPreviewTiled, &QAction::triggered, this, &MainWindow::PrintPreviewTiled); - connect(ui->actionSaveAsPDF, &QAction::triggered, this, &MainWindow::SaveAsPDF); connect(ui->actionSaveAsTiledPDF, &QAction::triggered, this, &MainWindow::SaveAsTiledPDF); connect(ui->actionPrint, &QAction::triggered, this, &MainWindow::PrintOrigin); connect(ui->actionPrintTiled, &QAction::triggered, this, &MainWindow::PrintTiled); diff --git a/src/app/valentina/mainwindow.ui b/src/app/valentina/mainwindow.ui index b3b5d5ff7..1da863969 100644 --- a/src/app/valentina/mainwindow.ui +++ b/src/app/valentina/mainwindow.ui @@ -1189,7 +1189,6 @@ Layout - @@ -2048,24 +2047,6 @@ QAction::NoRole - - - false - - - - :/icon/32x32/pdf.png:/icon/32x32/pdf.png - - - Save as PDF - - - Save original layout - - - - - false diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 0bdb5196e..129dae53a 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -266,19 +266,6 @@ void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) } } -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::SaveAsPDF() -{ - if (not isPagesUniform()) - { - qCritical()< images = AllSheets(printer); - - QVector poster; - if (isTiled) - { - VPoster posterazor(printer); - for (int i=0; i < images.size(); i++) - { - poster += posterazor.Generate(images.at(i), i+1, images.size()); - } - } - else - { - poster = images; - } + // Here we try understand difference between printer's dpi and our. + // Get printer rect acording to our dpi. + const QRectF printerPageRect(0, 0, ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm), + ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm)); + const double xscale = printer->pageRect().width() / printerPageRect.width(); + const double yscale = printer->pageRect().height() / printerPageRect.height(); + const double scale = qMin(xscale, yscale); QPainter painter; if (not painter.begin(printer)) @@ -317,9 +291,40 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) return; } + painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, + Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + + int count = 0; + QSharedPointer> poster; + QSharedPointer posterazor; + + if (isTiled) + { + poster = QSharedPointer>(new QVector()); + posterazor = QSharedPointer(new VPoster(printer)); + + for (int i=0; i < scenes.size(); ++i) + { + auto *paper = qgraphicsitem_cast(papers.at(i)); + if (paper) + { + *poster += posterazor->Calc(paper->rect().toRect(), i); + } + } + + count = poster->size(); + } + else + { + count = scenes.size(); + } + // Handle the fromPage(), toPage(), supportsMultipleCopies(), and numCopies() values from QPrinter. int firstPage = printer->fromPage() - 1; - if (firstPage >= poster.size()) + if (firstPage >= count) { return; } @@ -329,9 +334,9 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) } int lastPage = printer->toPage() - 1; - if (lastPage == -1 || lastPage >= poster.size()) + if (lastPage == -1 || lastPage >= count) { - lastPage = poster.size() - 1; + lastPage = count - 1; } const int numPages = lastPage - firstPage + 1; @@ -362,7 +367,38 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) { index = lastPage - j; } - painter.drawImage(QPointF(), poster.at(index)); + + int paperIndex = -1; + isTiled ? paperIndex = poster->at(index).index : paperIndex = index; + + auto *paper = qgraphicsitem_cast(papers.at(paperIndex)); + if (paper) + { + QVector posterData; + if (isTiled) + { + // Draw borders + posterData = posterazor->Borders(paper, poster->at(index), scenes.size()); + } + + PreparePaper(paperIndex); + + // Render + QRectF source; + isTiled ? source = poster->at(index).rect : source = paper->rect(); + QRectF target(0, 0, source.width() * scale, source.height() * scale); + + scenes.at(paperIndex)->render(&painter, target, source, Qt::IgnoreAspectRatio); + + if (isTiled) + { + // Remove borders + qDeleteAll(posterData); + } + + // Restore + RestorePaper(paperIndex); + } } } @@ -738,62 +774,31 @@ void MainWindowsNoGUI::DxfFile(const QString &name, int i) const #endif //--------------------------------------------------------------------------------------------------------------------- -QVector MainWindowsNoGUI::AllSheets(const QPrinter *printer) const +void MainWindowsNoGUI::PreparePaper(int index) const { - QVector images; - for (int i=0; i < scenes.size(); ++i) + auto *paper = qgraphicsitem_cast(papers.at(index)); + if (paper) { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) - { - // Hide shadow and paper border - QBrush *brush = new QBrush(); - brush->setColor( QColor( Qt::white ) ); - scenes[i]->setBackgroundBrush( *brush ); - shadows[i]->setVisible(false); - paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));// border - - // Render png - const QRectF source = paper->rect(); - QRectF target = source; - - if (printer) - { - // Here we try understand difference between printer's dpi and our. - // Get printer rect acording to our dpi. - const QRectF printerPageRect(0, 0, ToPixel(printer->pageSizeMM().width(), Unit::Mm), - ToPixel(printer->pageSizeMM().height(), Unit::Mm)); - const double xscale = printer->pageRect().width() / printerPageRect.width(); - const double yscale = printer->pageRect().height() / printerPageRect.height(); - const double scale = qMin(xscale, yscale); - target.setWidth(target.width() * scale); - target.setHeight(target.height() * scale); - } - - // Create the image with the exact size of the shrunk scene - QImage image(QSize(static_cast(target.width()), static_cast(target.height())), - QImage::Format_RGB32); - image.fill(Qt::white); - QPainter painter(&image); - painter.setFont( QFont( "Arial", 8, QFont::Normal ) ); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, - Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - scenes.at(i)->render(&painter, target, source, Qt::IgnoreAspectRatio); - painter.end(); - images.append(image); - - // Restore - paper->setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())))); - brush->setColor( QColor( Qt::gray ) ); - brush->setStyle( Qt::SolidPattern ); - scenes[i]->setBackgroundBrush( *brush ); - shadows[i]->setVisible(true); - delete brush; - } + QBrush brush(Qt::white); + scenes.at(index)->setBackgroundBrush(brush); + shadows.at(index)->setVisible(false); + paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));// border + } + +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::RestorePaper(int index) const +{ + auto *paper = qgraphicsitem_cast(papers.at(index)); + if (paper) + { + // Restore + paper->setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())))); + QBrush brush(Qt::gray); + scenes.at(index)->setBackgroundBrush(brush); + shadows.at(index)->setVisible(true); } - return images; } //--------------------------------------------------------------------------------------------------------------------- @@ -855,7 +860,7 @@ void MainWindowsNoGUI::PrintPreview() SetPrinterSettings(printer.data(), PrintType::PrintPreview); printer->setResolution(static_cast(PrintDPI)); // display print preview dialog - QPrintPreviewDialog preview(printer.data()); + QPrintPreviewDialog preview(printer.data()); connect(&preview, &QPrintPreviewDialog::paintRequested, this, &MainWindowsNoGUI::PrintPages); preview.exec(); } @@ -897,21 +902,16 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr printer->setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion()); // Set orientation - if (papers.size() > 0) + if (paperSize.height() >= paperSize.width()) { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(0)); - SCASSERT(paper != nullptr) - if (paper->rect().height()>= paper->rect().width()) - { - printer->setOrientation(QPrinter::Portrait); - } - else - { - printer->setOrientation(QPrinter::Landscape); - } + printer->setOrientation(QPrinter::Portrait); + } + else + { + printer->setOrientation(QPrinter::Landscape); } - if (not isTiled && papers.size() > 0) + if (not isTiled) { const QSizeF size = QSizeF(FromPixel(paperSize.width(), Unit::Mm), FromPixel(paperSize.height(), Unit::Mm)); const QPrinter::PageSize pSZ = FindTemplate(size); @@ -968,13 +968,33 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr //--------------------------------------------------------------------------------------------------------------------- bool MainWindowsNoGUI::IsLayoutGrayscale() const { - const QVector images = AllSheets(); + const QRect target = QRect(0, 0, 100, 100);//Small image less memory need - for(int i=0; i < images.size(); ++i) + for (int i=0; i < scenes.size(); ++i) { - if (not images.at(i).isGrayscale()) + auto *paper = qgraphicsitem_cast(papers.at(i)); + if (paper) { - return false; + // Hide shadow and paper border + PreparePaper(i); + + // Render png + QImage image(target.size(), QImage::Format_RGB32); + image.fill(Qt::white); + QPainter painter(&image); + painter.setPen(QPen(Qt::black, qApp->toPixel(WidthMainLine(*pattern->GetPatternUnit())), Qt::SolidLine, + Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + scenes.at(i)->render(&painter, target, paper->rect(), Qt::KeepAspectRatio); + painter.end(); + + // Restore + RestorePaper(i); + + if (not image.isGrayscale()) + { + return false; + } } } @@ -1031,11 +1051,11 @@ bool MainWindowsNoGUI::isPagesUniform() const } else { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(0)); + auto *paper = qgraphicsitem_cast(papers.at(0)); SCASSERT(paper != nullptr) for (int i=1; i < papers.size(); ++i) { - QGraphicsRectItem *p = qgraphicsitem_cast(papers.at(i)); + auto *p = qgraphicsitem_cast(papers.at(i)); SCASSERT(p != nullptr) if (paper->rect() != p->rect()) { diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 5e020d259..fa37d740d 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -41,7 +41,7 @@ class QGraphicsScene; class QPrinter; - +class PosterData; class MainWindowsNoGUI : public QMainWindow { @@ -53,7 +53,6 @@ public: public slots: void ToolLayoutSettings(bool checked); void ExportLayoutAs(); - void SaveAsPDF(); void SaveAsTiledPDF(); void PrintPages (QPrinter *printer); void PrintPreviewOrigin(); @@ -117,7 +116,8 @@ private: void ObjFile(const QString &name, int i)const; void DxfFile(const QString &name, int i)const; - QVector AllSheets(const QPrinter *printer = nullptr) const; + void PreparePaper(int index) const; + void RestorePaper(int index) const; void SaveLayoutAs(); void PrintPreview(); diff --git a/src/libs/vlayout/vposter.cpp b/src/libs/vlayout/vposter.cpp index 54ebd61d4..6347e58e4 100644 --- a/src/libs/vlayout/vposter.cpp +++ b/src/libs/vlayout/vposter.cpp @@ -27,8 +27,9 @@ *************************************************************************/ #include "vposter.h" -#include #include +#include +#include #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../vmisc/vmath.h" @@ -40,36 +41,126 @@ //--------------------------------------------------------------------------------------------------------------------- VPoster::VPoster(const QPrinter *printer) - :printer(printer), allowence(static_cast(qRound(10./25.4*printer->resolution())))//1 cm + :printer(printer), allowence(static_cast(qRound(10./25.4*PrintDPI)))//1 cm { } //--------------------------------------------------------------------------------------------------------------------- -QVector VPoster::Generate(const QImage &image, int page, int sheets) const +QVector VPoster::Calc(const QRect &imageRect, int page) const { - QVector poster; + QVector poster; if (printer == nullptr) { return poster; } - const int rows = CountRows(image.rect().height()); - const int columns = CountColumns(image.rect().width()); + const int rows = CountRows(imageRect.height()); + const int columns = CountColumns(imageRect.width()); for (int i=0; i < rows; i++) { for (int j=0; j< columns; j++) { - QImage img = Cut(i, j, image); - img = Borders(rows, columns, i, j, img, page, sheets); - poster.append(img); + PosterData data = Cut(i, j, imageRect); + data.index = page; + data.rows = rows; + data.columns = columns; + poster.append(data); } } return poster; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VPoster::Borders(QGraphicsItem *parent, const PosterData &img, int sheets) const +{ + QVector data; + QPen pen(Qt::NoBrush, 1, Qt::DashLine); + pen.setColor(Qt::black); + + const QRect rec = img.rect; + if (img.column != 0) + {// Left border + auto *line = new QGraphicsLineItem(parent); + line->setPen(pen); + line->setLine(rec.x(), rec.y(), rec.x(), rec.y() + rec.height()); + data.append(line); + + auto *scissors = new QGraphicsPixmapItem(QPixmap("://scissors_vertical.png"), parent); + scissors->setPos(rec.x(), rec.y() + rec.height()-static_cast(allowence)); + data.append(scissors); + } + + if (img.column != img.columns-1) + {// Right border + auto *line = new QGraphicsLineItem(parent); + line->setPen(pen); + line->setLine(rec.x() + rec.width()-static_cast(allowence), rec.y(), + rec.x() + rec.width()-static_cast(allowence), rec.y() + rec.height()); + data.append(line); + } + + if (img.row != 0) + {// Top border + auto *line = new QGraphicsLineItem(parent); + line->setPen(pen); + line->setLine(rec.x(), rec.y(), rec.x() + rec.width(), rec.y()); + data.append(line); + + auto *scissors = new QGraphicsPixmapItem(QPixmap("://scissors_horizontal.png"), parent); + scissors->setPos(rec.x() + rec.width()-static_cast(allowence), rec.y()); + data.append(scissors); + } + + if (img.rows*img.columns > 1) + { // Don't show bottom border if only one page need + // Bottom border (mandatory) + auto *line = new QGraphicsLineItem(parent); + line->setPen(pen); + line->setLine(rec.x(), rec.y() + rec.height()-static_cast(allowence), + rec.x() + rec.width(), rec.y() + rec.height()-static_cast(allowence)); + data.append(line); + + if (img.row == img.rows-1) + { + auto *scissors = new QGraphicsPixmapItem(QPixmap("://scissors_horizontal.png"), parent); + scissors->setPos(rec.x() + rec.width()-static_cast(allowence), + rec.y() + rec.height()-static_cast(allowence)); + data.append(scissors); + } + } + + // Labels + auto *labels = new QGraphicsTextItem(parent); + + const int layoutX = 15; + const int layoutY = 5; + labels->setPos(rec.x() + layoutX, rec.y() + rec.height()-static_cast(allowence)+layoutY); + labels->setTextWidth(rec.width()-(static_cast(allowence)+layoutX)); + + const QString grid = tr("Grid ( %1 , %2 )").arg(img.row+1).arg(img.column+1); + const QString page = tr("Page %1 of %2").arg(img.row*(img.columns)+img.column+1).arg(img.rows*img.columns); + + QString sheet; + if (sheets > 1) + { + sheet = tr("Sheet %1 of %2").arg(img.index+1).arg(sheets); + } + + labels->setHtml(QString("" + "" + "" + "" + "
%1%2%3
") + .arg(grid, page, sheet)); + + data.append(labels); + + return data; +} + //--------------------------------------------------------------------------------------------------------------------- int VPoster::CountRows(int height) const { @@ -148,96 +239,20 @@ int VPoster::CountColumns(int width) const } //--------------------------------------------------------------------------------------------------------------------- -QImage VPoster::Cut(int i, int j, const QImage &image) const +PosterData VPoster::Cut(int i, int j, const QRect &imageRect) const { const int x = j*PageRect().width() - j*static_cast(allowence); const int y = i*PageRect().height() - i*static_cast(allowence); - SCASSERT(x <= image.rect().width()); - SCASSERT(y <= image.rect().height()); + SCASSERT(x <= imageRect.width()); + SCASSERT(y <= imageRect.height()); - QRect copyRect(x, y, PageRect().width(), PageRect().height()); + PosterData data; + data.row = i; + data.column = j; + data.rect = QRect(x, y, PageRect().width(), PageRect().height()); - if (not image.rect().contains(copyRect)) - { - // Create full page with white background - QImage fullPage(copyRect.size(), image.format()); - fullPage.fill(Qt::white); - - // Real size that we can copy from image. - // Because in areas beyond the image, pixels are set to 0 by copy() method. - // For 32-bit RGB images, this means black. - copyRect = image.rect().intersected(copyRect); - - QPainter painter(&fullPage); - painter.drawImage(QPointF(), image.copy( copyRect)); - painter.end(); - - return fullPage; - } - else - { - return image.copy(copyRect); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -QImage VPoster::Borders(int rows, int columns, int i, int j, QImage &image, int page, int sheets) const -{ - QPainter painter(&image); - - QPen pen = QPen(Qt::NoBrush, 1, Qt::DashLine); - pen.setColor(Qt::black); - painter.setPen(pen); - - const QRect rec = image.rect(); - if (j != 0 && PageRect().x() > 0) - {// Left border - painter.drawLine(QLine(0, 0, 0, rec.height())); - painter.drawImage(QPoint(0, rec.height()-static_cast(allowence)), - QImage("://scissors_vertical.png")); - } - - if (j != columns-1) - {// Right border - painter.drawLine(QLine(rec.width()-static_cast(allowence), 0, - rec.width()-static_cast(allowence), rec.height())); - } - - if (i != 0 && PageRect().y() > 0) - {// Top border - painter.drawLine(QLine(0, 0, rec.width(), 0)); - painter.drawImage(QPoint(rec.width()-static_cast(allowence), 0), - QImage("://scissors_horizontal.png")); - } - - if (rows*columns > 1) - { // Don't show bottom border if only one page need - // Bottom border (mandatory) - painter.drawLine(QLine(0, rec.height()-static_cast(allowence), - rec.width(), rec.height()-static_cast(allowence))); - if (i == rows-1) - { - painter.drawImage(QPoint(rec.width()-static_cast(allowence), - rec.height()-static_cast(allowence)), - QImage("://scissors_horizontal.png")); - } - } - - // Labels - const int layoutX = 15; - const int layoutY = 5; - QRect labels(layoutX, rec.height()-static_cast(allowence)+layoutY, - rec.width()-(static_cast(allowence)+layoutX), static_cast(allowence)-layoutY); - painter.drawText(labels, Qt::AlignLeft, tr("Grid ( %1 , %2 )").arg(i+1).arg(j+1)); - painter.drawText(labels, Qt::AlignHCenter, tr("Page %1 of %2").arg(i*(columns)+j+1).arg(rows*columns)); - if (sheets > 1) - { - painter.drawText(labels, Qt::AlignRight, tr("Sheet %1 of %2").arg(page).arg(sheets)); - } - - painter.end(); - return image; + return data; } //--------------------------------------------------------------------------------------------------------------------- @@ -247,13 +262,12 @@ QRect VPoster::PageRect() const // we can't use method pageRect(QPrinter::Point). Our dpi value can be different. // We convert value yourself to pixels. const QRectF rect = printer->pageRect(QPrinter::Millimeter); - const QRect pageRect(qFloor(ToPixel(rect.x())), qFloor(ToPixel(rect.y())), qFloor(ToPixel(rect.width())), - qFloor(ToPixel(rect.height()))); + const QRect pageRect(0, 0, qFloor(ToPixel(rect.width())), qFloor(ToPixel(rect.height()))); return pageRect; } //--------------------------------------------------------------------------------------------------------------------- -qreal VPoster::ToPixel(qreal val) const +qreal VPoster::ToPixel(qreal val) { - return val / 25.4 * printer->resolution(); // Mm to pixels with current dpi. + return val / 25.4 * PrintDPI; // Mm to pixels with current dpi. } diff --git a/src/libs/vlayout/vposter.h b/src/libs/vlayout/vposter.h index 37925ccc7..cec5de387 100644 --- a/src/libs/vlayout/vposter.h +++ b/src/libs/vlayout/vposter.h @@ -29,11 +29,29 @@ #ifndef VPOSTER_H #define VPOSTER_H -#include #include #include class QPrinter; +class QGraphicsItem; + +struct PosterData +{ + PosterData() + : index(0), + row(0), + column(0), + rows(0), + columns(0), + rect(){} + + quint32 index; // paper index + quint32 row; // positions in the greed + quint32 column; + quint32 rows; + quint32 columns; + QRect rect; // rect section +}; class VPoster { @@ -41,7 +59,9 @@ class VPoster public: explicit VPoster(const QPrinter *printer); - QVector Generate(const QImage &image, int page, int sheets = 1) const; + QVector Calc(const QRect &imageRect, int page) const; + + QVector Borders(QGraphicsItem *parent, const PosterData &img, int sheets) const; private: const QPrinter *printer; quint32 allowence; @@ -49,12 +69,12 @@ private: int CountRows(int height) const; int CountColumns(int width) const; - QImage Cut(int i, int j, const QImage &image) const; + PosterData Cut(int i, int j, const QRect &imageRect) const; QImage Borders(int rows, int columns, int i, int j, QImage &image, int page, int sheets) const; QRect PageRect() const; - qreal ToPixel(qreal val) const; + static qreal ToPixel(qreal val); }; #endif // VPOSTER_H diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 7810ed974..4111f8a6c 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -1767,7 +1767,7 @@ QSharedPointer DefaultPrinter(QPrinter::PrinterMode mode) } } - QSharedPointer printer = QSharedPointer(new QPrinter(def, mode)); + auto printer = QSharedPointer(new QPrinter(def, mode)); printer->setResolution(static_cast(PrintDPI)); return printer; } diff --git a/src/test/ValentinaTest/tst_vposter.cpp b/src/test/ValentinaTest/tst_vposter.cpp index e5f8c6cc3..b2c4ccaa1 100644 --- a/src/test/ValentinaTest/tst_vposter.cpp +++ b/src/test/ValentinaTest/tst_vposter.cpp @@ -28,6 +28,7 @@ #include "tst_vposter.h" #include "../vlayout/vposter.h" +#include "../vmisc/def.h" #include #include @@ -49,15 +50,15 @@ void TST_VPoster::BigPoster() printer.setFullPage(true); // We need to set full page because otherwise QPrinter->pageRect returns different values in Windows and Linux - const QImage image(2622, 3178, QImage::Format_RGB32); // Little bit bigger than A1 + const QRect image(0, 0, 2622, 3178); // Little bit bigger than A1 VPoster posterazor(&printer); - const QVector poster = posterazor.Generate(image, 1, 1); + const QVector poster = posterazor.Calc(image, 0); QCOMPARE(poster.size(), 12); for (int i=0; i < poster.size(); i++) { - QCOMPARE(poster.at(i).rect().size(), PageRect(printer).size()); + QCOMPARE(poster.at(i).rect.size(), PageRect(printer).size()); } } @@ -69,13 +70,13 @@ void TST_VPoster::SmallPoster() printer.setResolution(96);// By default printer.setPaperSize(QPrinter::A4); - const QImage image(700, 1000, QImage::Format_RGB32); // Little bit less than A4 + const QRect image(0, 0, 700, 1000); // Little bit less than A4 VPoster posterazor(&printer); - const QVector poster = posterazor.Generate(image, 1, 1); + const QVector poster = posterazor.Calc(image, 0); QCOMPARE(poster.size(), 1); - QCOMPARE(poster.at(0).rect().size(), PageRect(printer).size()); + QCOMPARE(poster.at(0).rect.size(), PageRect(printer).size()); } //--------------------------------------------------------------------------------------------------------------------- @@ -85,13 +86,13 @@ QRect TST_VPoster::PageRect(const QPrinter &printer) const // we can't use method pageRect(QPrinter::Point). Our dpi different can be different. // We convert value yourself to pixels. const QRectF rect = printer.pageRect(QPrinter::Millimeter); - QRect pageRect(qFloor(ToPixel(rect.x(), printer)), qFloor(ToPixel(rect.y(), printer)), - qFloor(ToPixel(rect.width(), printer)), qFloor(ToPixel(rect.height(), printer))); + QRect pageRect(qFloor(ToPixel(rect.x())), qFloor(ToPixel(rect.y())), + qFloor(ToPixel(rect.width())), qFloor(ToPixel(rect.height()))); return pageRect; } //--------------------------------------------------------------------------------------------------------------------- -qreal TST_VPoster::ToPixel(qreal val, const QPrinter &printer) const +qreal TST_VPoster::ToPixel(qreal val) const { - return val / 25.4 * printer.resolution(); // Mm to pixels with current dpi. + return val / 25.4 * PrintDPI; // Mm to pixels with current dpi. } diff --git a/src/test/ValentinaTest/tst_vposter.h b/src/test/ValentinaTest/tst_vposter.h index bb403da84..826273597 100644 --- a/src/test/ValentinaTest/tst_vposter.h +++ b/src/test/ValentinaTest/tst_vposter.h @@ -47,7 +47,7 @@ private slots: void SmallPoster(); private: - qreal ToPixel(qreal val, const QPrinter &printer) const; + qreal ToPixel(qreal val) const; QRect PageRect(const QPrinter &printer) const; };