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

View File

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

View File

@ -192,13 +192,13 @@ void VLayoutGenerator::Abort()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::PageHeight() const 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 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; return paperWidth;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetPaperWidth(int value) void VLayoutGenerator::SetPaperWidth(qreal value)
{ {
paperWidth = value; paperWidth = value;
} }
@ -304,13 +304,13 @@ void VLayoutGenerator::SetShift(quint32 shift)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::GetPaperHeight() const qreal VLayoutGenerator::GetPaperHeight() const
{ {
return paperHeight; return paperHeight;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetPaperHeight(int value) void VLayoutGenerator::SetPaperHeight(qreal value)
{ {
paperHeight = value; paperHeight = value;
} }

View File

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