Refactoring.

This commit is contained in:
Roman Telezhynskyi 2020-12-23 15:42:30 +02:00
parent abb4397901
commit 510a5ab6a7
2 changed files with 43 additions and 32 deletions

View File

@ -312,14 +312,6 @@ void VPrintLayout::PrintPreview()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPrintLayout::PrintPages(QPrinter *printer) void VPrintLayout::PrintPages(QPrinter *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->pageRect(QPrinter::Millimeter).width(), Unit::Mm),
ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm));
const QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution());
const double xscale = pageRect.width() / printerPageRect.width();
const double yscale = pageRect.height() / printerPageRect.height();
QPainter painter; QPainter painter;
if (not painter.begin(printer)) if (not painter.begin(printer))
{ // failed to open file { // failed to open file
@ -391,29 +383,15 @@ void VPrintLayout::PrintPages(QPrinter *printer)
copyCount = printer->copyCount(); copyCount = printer->copyCount();
} }
VWatermarkData data; VWatermarkData data = WatermarkData();
if (not m_watermarkPath.isEmpty())
{
try
{
VWatermarkConverter converter(m_watermarkPath);
VWatermark watermark;
watermark.setXMLContent(converter.Convert());
data = watermark.GetWatermark();
if (not data.path.isEmpty()) // Here we try understand difference between printer's dpi and our.
{ // Get printer rect acording to our dpi.
// Clean previous cache const QRectF printerPageRect(0, 0, ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm),
QPixmapCache::remove(AbsoluteMPath(m_watermarkPath, data.path)); ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm));
} const QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution());
} const double xscale = pageRect.width() / printerPageRect.width();
catch (VException &e) const double yscale = pageRect.height() / printerPageRect.height();
{
const QString errorMsg = tr("File error.\n\n%1\n\n%2").arg(e.ErrorMessage(), e.DetailedInformation());
qApp->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
}
}
for (int i = 0; i < copyCount; ++i) for (int i = 0; i < copyCount; ++i)
{ {
@ -736,6 +714,36 @@ auto VPrintLayout::IsPagesFit(QSizeF printPaper) const -> bool
return pSize.height() <= printPaper.height() && pSize.width() <= printPaper.width(); return pSize.height() <= printPaper.height() && pSize.width() <= printPaper.width();
} }
//---------------------------------------------------------------------------------------------------------------------
auto VPrintLayout::WatermarkData() const -> VWatermarkData
{
VWatermarkData data;
if (m_isTiled && not m_watermarkPath.isEmpty())
{
try
{
VWatermarkConverter converter(m_watermarkPath);
VWatermark watermark;
watermark.setXMLContent(converter.Convert());
data = watermark.GetWatermark();
if (not data.path.isEmpty())
{
// Clean previous cache
QPixmapCache::remove(AbsoluteMPath(m_watermarkPath, data.path));
}
}
catch (VException &e)
{
const QString errorMsg = tr("File error.\n\n%1\n\n%2").arg(e.ErrorMessage(), e.DetailedInformation());
qApp->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
}
}
return data;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VPrintLayout::ContinueIfLayoutStale(QWidget *parent) -> int auto VPrintLayout::ContinueIfLayoutStale(QWidget *parent) -> int
{ {

View File

@ -38,6 +38,7 @@ enum class PrintType : qint8 {PrintPDF, PrintPreview, PrintNative};
class QPrinter; class QPrinter;
class QGraphicsScene; class QGraphicsScene;
struct VWatermarkData;
class VPrintLayout : public QObject class VPrintLayout : public QObject
{ {
@ -168,6 +169,8 @@ private:
bool IsPagesUniform() const; bool IsPagesUniform() const;
bool IsPagesFit(QSizeF printPaper) const; bool IsPagesFit(QSizeF printPaper) const;
auto WatermarkData() const -> VWatermarkData;
}; };
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------