Set default printing color mode.

Known issue: program doesn't print in grayscale color mode.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-11-04 17:22:49 +02:00
parent 8d6c007217
commit 6b54c5bb7d
3 changed files with 29 additions and 9 deletions

View File

@ -705,7 +705,7 @@ void MainWindowsNoGUI::DxfFile(const QString &name, int i) const
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QImage> MainWindowsNoGUI::AllSheets()
QVector<QImage> MainWindowsNoGUI::AllSheets() const
{
QVector<QImage> images;
for (int i=0; i < scenes.size(); ++i)
@ -842,14 +842,14 @@ void MainWindowsNoGUI::LayoutPrint()
void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer)
{
SCASSERT(printer != nullptr)
printer->setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
printer->setCreator(qApp->applicationDisplayName()+" "+qApp->applicationVersion());
// Set orientation
if (papers.size() > 0)
{
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
SCASSERT(paper != nullptr)
if (paper->rect().height()>= paper->rect().width())
if (paper->rect().height()>= paper->rect().width())
{
printer->setOrientation(QPrinter::Portrait);
}
@ -863,11 +863,30 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer)
{
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(paper->rect().width(), Unit::Mm),
FromPixel(paper->rect().height(), Unit::Mm)), QPrinter::Millimeter );
}
printer->setOutputFileName(QDir::homePath() + QDir::separator() + FileName() + QLatin1Literal(".pdf"));
printer->setDocName(FileName());
IsLayoutGrayscale() ? printer->setColorMode(QPrinter::GrayScale) : printer->setColorMode(QPrinter::Color);
}
//---------------------------------------------------------------------------------------------------------------------
bool MainWindowsNoGUI::IsLayoutGrayscale() const
{
const QVector<QImage> images = AllSheets();
for(int i=0; i < images.size(); ++i)
{
if (not images.at(i).isGrayscale())
{
return false;
}
}
return true;
}
//---------------------------------------------------------------------------------------------------------------------
@ -881,11 +900,11 @@ bool MainWindowsNoGUI::isPagesUniform() const
{
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
SCASSERT(paper != nullptr)
for (int i=1; i < papers.size(); ++i)
for (int i=1; i < papers.size(); ++i)
{
QGraphicsRectItem *p = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
SCASSERT(p != nullptr)
if (paper->rect() != p->rect())
if (paper->rect() != p->rect())
{
return false;
}

View File

@ -104,7 +104,6 @@ private:
void CreateShadows();
void CreateScenes();
void SvgFile(const QString &name, int i)const;
void PngFile(const QString &name, int i)const;
void PdfFile(const QString &name, int i)const;
@ -114,13 +113,14 @@ private:
void ObjFile(const QString &name, int i)const;
void DxfFile(const QString &name, int i)const;
QVector<QImage> AllSheets();
QVector<QImage> AllSheets() const;
void SaveLayoutAs();
void PrintPreview();
void LayoutPrint();
void SetPrinterSettings(QPrinter *printer);
bool IsLayoutGrayscale() const;
bool isPagesUniform() const;
QString FileName() const;

View File

@ -33,6 +33,7 @@
#include "../ifc/ifcdef.h"
#include <QStringList>
#include <QMap>
class VMeasurementData;
class VContainer;