Calculate correct paper size. Print preview doesn't support non native

printers.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-11-09 13:58:45 +02:00
parent 9a865ab72d
commit 9327da7a2c
5 changed files with 30 additions and 27 deletions

View File

@ -528,8 +528,8 @@ void DialogLayoutSettings::DialogAccepted()
SCASSERT(generator != nullptr)
generator->SetLayoutWidth(GetLayoutWidth());
generator->SetCaseType(GetGroup());
generator->SetPaperHeight(qFloor(GetPaperHeight()));
generator->SetPaperWidth(qFloor(GetPaperWidth()));
generator->SetPaperHeight(GetPaperHeight());
generator->SetPaperWidth(GetPaperWidth());
generator->SetShift(qFloor(GetShift()));
generator->SetRotate(GetRotate());
generator->SetRotationIncrease(GetIncrease());

View File

@ -62,7 +62,7 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent)
pattern(new VContainer(qApp->TrVars(), qApp->patternUnitP())), doc(nullptr), papers(QList<QGraphicsItem *>()),
shadows(QList<QGraphicsItem *>()), scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >()),
undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), curFile(QString()),
isLayoutStale(true), margins(), isTiled(false)
isLayoutStale(true), margins(), paperSize(), isTiled(false)
{
InitTempLayoutScene();
}
@ -133,6 +133,7 @@ bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator)
CreateScenes();
PrepareSceneList();
margins = lGenerator.GetFields();
paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight());
isLayoutStale = false;
break;
case LayoutErrors::ProcessStoped:
@ -799,7 +800,7 @@ void MainWindowsNoGUI::PrintPreview()
return;
}
SetPrinterSettings(printer.data());
SetPrinterSettings(printer.data(), false);
// display print preview dialog
QPrintPreviewDialog preview(printer.data());
connect(&preview, &QPrintPreviewDialog::paintRequested, this, &MainWindowsNoGUI::PrintPages);
@ -830,7 +831,7 @@ void MainWindowsNoGUI::LayoutPrint()
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer)
void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, bool prepareForPrinting)
{
SCASSERT(printer != nullptr)
printer->setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
@ -852,10 +853,8 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer)
if (not isTiled && papers.size() > 0)
{
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
SCASSERT(paper != nullptr)
printer->setPaperSize ( QSizeF(FromPixel(paper->rect().width(), Unit::Mm),
FromPixel(paper->rect().height(), Unit::Mm)), QPrinter::Millimeter );
printer->setPaperSize ( QSizeF(FromPixel(paperSize.width(), Unit::Mm),
FromPixel(paperSize.height(), Unit::Mm)), QPrinter::Millimeter );
}
{
@ -866,11 +865,14 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer)
printer->setPageMargins(left, top, right, bottom, QPrinter::Millimeter);
}
#ifdef Q_OS_WIN
printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName());
#else
printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName() + QLatin1Literal(".pdf"));
#endif
if (prepareForPrinting)
{
#ifdef Q_OS_WIN
printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName());
#else
printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName() + QLatin1Literal(".pdf"));
#endif
}
printer->setDocName(FileName());
IsLayoutGrayscale() ? printer->setColorMode(QPrinter::GrayScale) : printer->setColorMode(QPrinter::Color);

View File

@ -88,6 +88,7 @@ protected:
bool isLayoutStale;
QMarginsF margins;
QSizeF paperSize;
void PrepareDetailsForLayout(const QHash<quint32, VDetail> *details);
void ExportLayout(const DialogSaveLayout &dialog);
@ -120,7 +121,7 @@ private:
void PrintPreview();
void LayoutPrint();
void SetPrinterSettings(QPrinter *printer);
void SetPrinterSettings(QPrinter *printer, bool prepareForPrinting = true);
bool IsLayoutGrayscale() const;
bool isPagesUniform() const;

View File

@ -192,13 +192,13 @@ void VLayoutGenerator::Abort()
//---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::PageHeight() const
{
return paperHeight - static_cast<int>(margins.top() + margins.bottom());
return static_cast<int>(paperHeight - (margins.top() + margins.bottom()));
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::PageWidth() const
{
return paperWidth - static_cast<int>(margins.left() + margins.right());
return static_cast<int>(paperWidth - (margins.left() + margins.right()));
}
//---------------------------------------------------------------------------------------------------------------------
@ -268,13 +268,13 @@ void VLayoutGenerator::SetRotate(bool value)
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::GetPaperWidth() const
qreal VLayoutGenerator::GetPaperWidth() const
{
return paperWidth;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetPaperWidth(int value)
void VLayoutGenerator::SetPaperWidth(qreal value)
{
paperWidth = value;
}
@ -304,13 +304,13 @@ void VLayoutGenerator::SetShift(quint32 shift)
}
//---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::GetPaperHeight() const
qreal VLayoutGenerator::GetPaperHeight() const
{
return paperHeight;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetPaperHeight(int value)
void VLayoutGenerator::SetPaperHeight(qreal value)
{
paperHeight = value;
}

View File

@ -53,11 +53,11 @@ public:
void SetCaseType(Cases caseType);
int DetailsCount();
int GetPaperHeight() const;
void SetPaperHeight(int value);
qreal GetPaperHeight() const;
void SetPaperHeight(qreal value);
int GetPaperWidth() const;
void SetPaperWidth(int value);
qreal GetPaperWidth() const;
void SetPaperWidth(qreal value);
QMarginsF GetFields() const;
void SetFields(const QMarginsF &value);
@ -100,8 +100,8 @@ private:
Q_DISABLE_COPY(VLayoutGenerator)
QVector<VLayoutPaper> papers;
VBank *bank;
int paperHeight;
int paperWidth;
qreal paperHeight;
qreal paperWidth;
QMarginsF margins;
volatile bool stopGeneration;
LayoutErrors state;