Merge branch '83-export-drawing' into develop
This commit is contained in:
commit
2412dbd6dd
|
@ -41,7 +41,7 @@ class VApplication;// use in define
|
||||||
#if defined(qApp)
|
#if defined(qApp)
|
||||||
#undef qApp
|
#undef qApp
|
||||||
#endif
|
#endif
|
||||||
#define qApp (static_cast<VApplication*>(VAbstractApplication::instance()))
|
#define qApp (qobject_cast<VApplication*>(VAbstractApplication::instance()))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The VApplication class reimplamentation QApplication class.
|
* @brief The VApplication class reimplamentation QApplication class.
|
||||||
|
|
|
@ -909,9 +909,6 @@ QSizeF DialogLayoutSettings::GetTemplateSize(const PaperSizeTemplate &tmpl, cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QMarginsF DialogLayoutSettings::MinPrinterFields() const
|
QMarginsF DialogLayoutSettings::MinPrinterFields() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include <QCloseEvent>
|
#include <QCloseEvent>
|
||||||
#include <QMargins>
|
#include <QMargins>
|
||||||
|
|
||||||
#include "vabstractlayoutdialog.h"
|
#include "../vlayout/dialogs/vabstractlayoutdialog.h"
|
||||||
#include "../vlayout/vbank.h"
|
#include "../vlayout/vbank.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
|
|
|
@ -36,6 +36,5 @@
|
||||||
#include "dialogaboutapp.h"
|
#include "dialogaboutapp.h"
|
||||||
#include "dialogpreferences.h"
|
#include "dialogpreferences.h"
|
||||||
#include "dialogfinalmeasurements.h"
|
#include "dialogfinalmeasurements.h"
|
||||||
#include "dialoglayoutscale.h"
|
|
||||||
|
|
||||||
#endif // DIALOGS_H
|
#endif // DIALOGS_H
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# This need for corect working file translations.pro
|
# This need for corect working file translations.pro
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/dialoglayoutscale.h \
|
|
||||||
$$PWD/dialogs.h \
|
$$PWD/dialogs.h \
|
||||||
$$PWD/dialogincrements.h \
|
$$PWD/dialogincrements.h \
|
||||||
$$PWD/dialoghistory.h \
|
$$PWD/dialoghistory.h \
|
||||||
|
@ -21,13 +20,11 @@ HEADERS += \
|
||||||
$$PWD/dialogdatetimeformats.h \
|
$$PWD/dialogdatetimeformats.h \
|
||||||
$$PWD/dialogknownmaterials.h \
|
$$PWD/dialogknownmaterials.h \
|
||||||
$$PWD/dialogpatternmaterials.h \
|
$$PWD/dialogpatternmaterials.h \
|
||||||
$$PWD/dialogfinalmeasurements.h \
|
$$PWD/dialogfinalmeasurements.h
|
||||||
$$PWD/vabstractlayoutdialog.h
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/dialogincrements.cpp \
|
$$PWD/dialogincrements.cpp \
|
||||||
$$PWD/dialoghistory.cpp \
|
$$PWD/dialoghistory.cpp \
|
||||||
$$PWD/dialoglayoutscale.cpp \
|
|
||||||
$$PWD/dialogpatternproperties.cpp \
|
$$PWD/dialogpatternproperties.cpp \
|
||||||
$$PWD/dialognewpattern.cpp \
|
$$PWD/dialognewpattern.cpp \
|
||||||
$$PWD/dialogaboutapp.cpp \
|
$$PWD/dialogaboutapp.cpp \
|
||||||
|
@ -43,13 +40,11 @@ SOURCES += \
|
||||||
$$PWD/dialogdatetimeformats.cpp \
|
$$PWD/dialogdatetimeformats.cpp \
|
||||||
$$PWD/dialogknownmaterials.cpp \
|
$$PWD/dialogknownmaterials.cpp \
|
||||||
$$PWD/dialogpatternmaterials.cpp \
|
$$PWD/dialogpatternmaterials.cpp \
|
||||||
$$PWD/dialogfinalmeasurements.cpp \
|
$$PWD/dialogfinalmeasurements.cpp
|
||||||
$$PWD/vabstractlayoutdialog.cpp
|
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
$$PWD/dialogincrements.ui \
|
$$PWD/dialogincrements.ui \
|
||||||
$$PWD/dialoghistory.ui \
|
$$PWD/dialoghistory.ui \
|
||||||
$$PWD/dialoglayoutscale.ui \
|
|
||||||
$$PWD/dialogpatternproperties.ui \
|
$$PWD/dialogpatternproperties.ui \
|
||||||
$$PWD/dialognewpattern.ui \
|
$$PWD/dialognewpattern.ui \
|
||||||
$$PWD/dialogaboutapp.ui \
|
$$PWD/dialogaboutapp.ui \
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "../core/vapplication.h"
|
#include "../core/vapplication.h"
|
||||||
#include "../vmisc/vsettings.h"
|
#include "../vmisc/vsettings.h"
|
||||||
#include "../ifc/exception/vexception.h"
|
#include "../ifc/exception/vexception.h"
|
||||||
|
#include "../vlayout/vlayoutexporter.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
@ -788,35 +789,12 @@ bool DialogSaveLayout::SupportPSTest()
|
||||||
{
|
{
|
||||||
if (!tested)
|
if (!tested)
|
||||||
{
|
{
|
||||||
havePdf = TestPdf();
|
havePdf = VLayoutExporter::SupportPDFConversion();
|
||||||
tested = true;
|
tested = true;
|
||||||
}
|
}
|
||||||
return havePdf;
|
return havePdf;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
bool DialogSaveLayout::TestPdf()
|
|
||||||
{
|
|
||||||
bool res = false;
|
|
||||||
|
|
||||||
QProcess proc;
|
|
||||||
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
|
||||||
// Seek pdftops in app bundle or near valentin.exe
|
|
||||||
proc.start(qApp->applicationDirPath() + QLatin1String("/")+ PDFTOPS, QStringList());
|
|
||||||
#else
|
|
||||||
proc.start(PDFTOPS, QStringList()); // Seek pdftops in standard path
|
|
||||||
#endif
|
|
||||||
if (proc.waitForStarted(15000) && (proc.waitForFinished(15000) || proc.state() == QProcess::NotRunning))
|
|
||||||
{
|
|
||||||
res = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug()<<PDFTOPS<<"error"<<proc.error()<<proc.errorString();
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QVector<std::pair<QString, LayoutExportFormats> > DialogSaveLayout::InitFormats()
|
QVector<std::pair<QString, LayoutExportFormats> > DialogSaveLayout::InitFormats()
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,17 +30,9 @@
|
||||||
#define DIALOGSAVELAYOUT_H
|
#define DIALOGSAVELAYOUT_H
|
||||||
|
|
||||||
#include "../vgeometry/vgeometrydef.h"
|
#include "../vgeometry/vgeometrydef.h"
|
||||||
#include "vabstractlayoutdialog.h"
|
#include "../vlayout/dialogs/vabstractlayoutdialog.h"
|
||||||
#include "../vlayout/vlayoutdef.h"
|
#include "../vlayout/vlayoutdef.h"
|
||||||
|
|
||||||
#ifndef PDFTOPS
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
# define PDFTOPS QStringLiteral("pdftops.exe")
|
|
||||||
#else
|
|
||||||
# define PDFTOPS QStringLiteral("pdftops")
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class DialogSaveLAyout;
|
class DialogSaveLAyout;
|
||||||
|
@ -115,7 +107,6 @@ private:
|
||||||
static bool havePdf;
|
static bool havePdf;
|
||||||
static bool tested;
|
static bool tested;
|
||||||
static bool SupportPSTest();
|
static bool SupportPSTest();
|
||||||
static bool TestPdf();
|
|
||||||
static QVector<std::pair<QString, LayoutExportFormats> > InitFormats();
|
static QVector<std::pair<QString, LayoutExportFormats> > InitFormats();
|
||||||
|
|
||||||
void RemoveFormatFromList(LayoutExportFormats format);
|
void RemoveFormatFromList(LayoutExportFormats format);
|
||||||
|
|
|
@ -1641,10 +1641,7 @@ void MainWindow::customEvent(QEvent *event)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void MainWindow::CleanLayout()
|
void MainWindow::CleanLayout()
|
||||||
{
|
{
|
||||||
qDeleteAll (scenes);
|
m_layoutSettings->CleanLayout();
|
||||||
scenes.clear();
|
|
||||||
shadows.clear();
|
|
||||||
papers.clear();
|
|
||||||
gcontours.clear();
|
gcontours.clear();
|
||||||
ui->listWidget->clear();
|
ui->listWidget->clear();
|
||||||
SetLayoutModeActions();
|
SetLayoutModeActions();
|
||||||
|
@ -1654,14 +1651,14 @@ void MainWindow::CleanLayout()
|
||||||
void MainWindow::PrepareSceneList(PreviewQuatilty quality)
|
void MainWindow::PrepareSceneList(PreviewQuatilty quality)
|
||||||
{
|
{
|
||||||
ui->listWidget->clear();
|
ui->listWidget->clear();
|
||||||
for (int i=1; i<=scenes.size(); ++i)
|
for (int i=1; i<=m_layoutSettings->LayoutScenes().size(); ++i)
|
||||||
{
|
{
|
||||||
QListWidgetItem *item = new QListWidgetItem(ScenePreview(i-1, ui->listWidget->iconSize(), quality),
|
QListWidgetItem *item = new QListWidgetItem(ScenePreview(i-1, ui->listWidget->iconSize(), quality),
|
||||||
QString::number(i));
|
QString::number(i));
|
||||||
ui->listWidget->addItem(item);
|
ui->listWidget->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not scenes.isEmpty())
|
if (not m_layoutSettings->LayoutScenes().isEmpty())
|
||||||
{
|
{
|
||||||
ui->listWidget->setCurrentRow(0);
|
ui->listWidget->setCurrentRow(0);
|
||||||
SetLayoutModeActions();
|
SetLayoutModeActions();
|
||||||
|
@ -3062,7 +3059,7 @@ void MainWindow::ActionLayout(bool checked)
|
||||||
|
|
||||||
ShowPaper(ui->listWidget->currentRow());
|
ShowPaper(ui->listWidget->currentRow());
|
||||||
|
|
||||||
if (scenes.isEmpty() || isLayoutStale)
|
if (m_layoutSettings->LayoutScenes().isEmpty() || m_layoutSettings->IsLayoutStale())
|
||||||
{
|
{
|
||||||
ui->toolButtonLayoutSettings->click();
|
ui->toolButtonLayoutSettings->click();
|
||||||
}
|
}
|
||||||
|
@ -3817,7 +3814,7 @@ void MainWindow::PatternChangesWereSaved(bool saved)
|
||||||
const bool state = doc->IsModified() || !saved;
|
const bool state = doc->IsModified() || !saved;
|
||||||
setWindowModified(state);
|
setWindowModified(state);
|
||||||
not patternReadOnly ? ui->actionSave->setEnabled(state): ui->actionSave->setEnabled(false);
|
not patternReadOnly ? ui->actionSave->setEnabled(state): ui->actionSave->setEnabled(false);
|
||||||
isLayoutStale = true;
|
m_layoutSettings->SetLayoutStale(true);
|
||||||
isNeedAutosave = not saved;
|
isNeedAutosave = not saved;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4177,7 +4174,7 @@ QT_WARNING_POP
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void MainWindow::SetLayoutModeActions()
|
void MainWindow::SetLayoutModeActions()
|
||||||
{
|
{
|
||||||
const bool enabled = not scenes.isEmpty();
|
const bool enabled = not m_layoutSettings->LayoutScenes().isEmpty();
|
||||||
|
|
||||||
ui->toolButtonLayoutExportAs->setEnabled(enabled);
|
ui->toolButtonLayoutExportAs->setEnabled(enabled);
|
||||||
ui->actionExportAs->setEnabled(enabled);
|
ui->actionExportAs->setEnabled(enabled);
|
||||||
|
@ -5011,7 +5008,6 @@ bool MainWindow::PatternPieceName(QString &name)
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
CancelTool();
|
CancelTool();
|
||||||
qDeleteAll (scenes);
|
|
||||||
|
|
||||||
delete doc;
|
delete doc;
|
||||||
delete ui;
|
delete ui;
|
||||||
|
@ -5337,13 +5333,13 @@ void MainWindow::ToolBoxSizePolicy()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void MainWindow::ShowPaper(int index)
|
void MainWindow::ShowPaper(int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= scenes.size())
|
if (index < 0 || index >= m_layoutSettings->LayoutScenes().size())
|
||||||
{
|
{
|
||||||
ui->view->setScene(tempSceneLayout);
|
ui->view->setScene(tempSceneLayout);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui->view->setScene(scenes.at(index));
|
ui->view->setScene(m_layoutSettings->LayoutScenes().at(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
|
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
|
||||||
|
@ -5400,9 +5396,9 @@ void MainWindow::ExportLayoutAs()
|
||||||
{
|
{
|
||||||
auto Uncheck = qScopeGuard([this] {ui->toolButtonLayoutExportAs->setChecked(false);});
|
auto Uncheck = qScopeGuard([this] {ui->toolButtonLayoutExportAs->setChecked(false);});
|
||||||
|
|
||||||
if (isLayoutStale)
|
if (m_layoutSettings->IsLayoutStale())
|
||||||
{
|
{
|
||||||
if (ContinueIfLayoutStale() == QMessageBox::No)
|
if (VPrintLayout::ContinueIfLayoutStale(this) == QMessageBox::No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5410,8 +5406,8 @@ void MainWindow::ExportLayoutAs()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_dialogSaveLayout = QSharedPointer<DialogSaveLayout>(new DialogSaveLayout(scenes.size(), Draw::Layout,
|
m_dialogSaveLayout = QSharedPointer<DialogSaveLayout>(
|
||||||
FileName(), this));
|
new DialogSaveLayout(m_layoutSettings->LayoutScenes().size(), Draw::Layout, FileName(), this));
|
||||||
|
|
||||||
if (m_dialogSaveLayout->exec() == QDialog::Rejected)
|
if (m_dialogSaveLayout->exec() == QDialog::Rejected)
|
||||||
{
|
{
|
||||||
|
@ -5829,9 +5825,9 @@ bool MainWindow::DoExport(const VCommandLinePtr &expParams)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_dialogSaveLayout = QSharedPointer<DialogSaveLayout>(new DialogSaveLayout(scenes.size(), Draw::Layout,
|
m_dialogSaveLayout = QSharedPointer<DialogSaveLayout>(
|
||||||
expParams->OptBaseName(),
|
new DialogSaveLayout(m_layoutSettings->LayoutScenes().size(),
|
||||||
this));
|
Draw::Layout, expParams->OptBaseName(), this));
|
||||||
m_dialogSaveLayout->SetDestinationPath(expParams->OptDestinationPath());
|
m_dialogSaveLayout->SetDestinationPath(expParams->OptDestinationPath());
|
||||||
m_dialogSaveLayout->SelectFormat(static_cast<LayoutExportFormats>(expParams->OptExportType()));
|
m_dialogSaveLayout->SelectFormat(static_cast<LayoutExportFormats>(expParams->OptExportType()));
|
||||||
m_dialogSaveLayout->SetBinaryDXFFormat(expParams->IsBinaryDXF());
|
m_dialogSaveLayout->SetBinaryDXFFormat(expParams->IsBinaryDXF());
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -40,6 +40,7 @@
|
||||||
#include "../vlayout/vlayoutgenerator.h"
|
#include "../vlayout/vlayoutgenerator.h"
|
||||||
#include "../vwidgets/vabstractmainwindow.h"
|
#include "../vwidgets/vabstractmainwindow.h"
|
||||||
#include "../vlayout/vtextmanager.h"
|
#include "../vlayout/vtextmanager.h"
|
||||||
|
#include "../vlayout/vprintlayout.h"
|
||||||
|
|
||||||
class QGraphicsScene;
|
class QGraphicsScene;
|
||||||
struct PosterData;
|
struct PosterData;
|
||||||
|
@ -98,13 +99,9 @@ protected:
|
||||||
/** @brief doc dom document container */
|
/** @brief doc dom document container */
|
||||||
VPattern *doc;
|
VPattern *doc;
|
||||||
|
|
||||||
QList<QGraphicsItem *> papers;
|
QList<QGraphicsItem *> gcontours{};
|
||||||
QList<QGraphicsItem *> shadows;
|
|
||||||
QList<QGraphicsScene *> scenes;
|
|
||||||
QList<QList<QGraphicsItem *> > details;
|
|
||||||
QList<QGraphicsItem *> gcontours;
|
|
||||||
|
|
||||||
QVector<QVector<VLayoutPiece> > detailsOnLayout;
|
QVector<QVector<VLayoutPiece> > detailsOnLayout{};
|
||||||
|
|
||||||
QAction *undoAction;
|
QAction *undoAction;
|
||||||
QAction *redoAction;
|
QAction *redoAction;
|
||||||
|
@ -112,12 +109,8 @@ protected:
|
||||||
QAction *actionDockWidgetGroups;
|
QAction *actionDockWidgetGroups;
|
||||||
|
|
||||||
bool isNoScaling;
|
bool isNoScaling;
|
||||||
bool isLayoutStale;
|
|
||||||
bool isNeedAutosave;
|
bool isNeedAutosave;
|
||||||
bool ignorePrinterFields;
|
VPrintLayout *m_layoutSettings{new VPrintLayout(this)};
|
||||||
bool isLayoutPortrait{true};
|
|
||||||
QMarginsF margins;
|
|
||||||
QSizeF paperSize;
|
|
||||||
|
|
||||||
QSharedPointer<DialogSaveLayout> m_dialogSaveLayout;
|
QSharedPointer<DialogSaveLayout> m_dialogSaveLayout;
|
||||||
|
|
||||||
|
@ -140,7 +133,6 @@ protected:
|
||||||
virtual QStringList RecentFileList() const override;
|
virtual QStringList RecentFileList() const override;
|
||||||
QIcon ScenePreview(int i, QSize iconSize, PreviewQuatilty quality) const;
|
QIcon ScenePreview(int i, QSize iconSize, PreviewQuatilty quality) const;
|
||||||
bool GenerateLayout(VLayoutGenerator& lGenerator);
|
bool GenerateLayout(VLayoutGenerator& lGenerator);
|
||||||
int ContinueIfLayoutStale();
|
|
||||||
QString FileName() const;
|
QString FileName() const;
|
||||||
|
|
||||||
bool ExportFMeasurementsToCSVData(const QString &fileName,
|
bool ExportFMeasurementsToCSVData(const QString &fileName,
|
||||||
|
@ -149,60 +141,15 @@ protected:
|
||||||
QSharedPointer<VMeasurements> OpenMeasurementFile(const QString &path) const;
|
QSharedPointer<VMeasurements> OpenMeasurementFile(const QString &path) const;
|
||||||
|
|
||||||
void CheckRequiredMeasurements(const VMeasurements *m) const;
|
void CheckRequiredMeasurements(const VMeasurements *m) const;
|
||||||
private slots:
|
|
||||||
void PrintPages (QPrinter *printer);
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(MainWindowsNoGUI)
|
Q_DISABLE_COPY(MainWindowsNoGUI)
|
||||||
|
|
||||||
bool isTiled;
|
|
||||||
bool isAutoCropLength;
|
|
||||||
bool isAutoCropWidth;
|
|
||||||
bool isUnitePages;
|
|
||||||
|
|
||||||
QString layoutPrinterName;
|
|
||||||
|
|
||||||
qreal m_xscale{1};
|
|
||||||
qreal m_yscale{1};
|
|
||||||
|
|
||||||
static QList<QGraphicsItem *> CreateShadows(const QList<QGraphicsItem *> &papers);
|
static QList<QGraphicsItem *> CreateShadows(const QList<QGraphicsItem *> &papers);
|
||||||
static QList<QGraphicsScene *> CreateScenes(const QList<QGraphicsItem *> &papers,
|
static QList<QGraphicsScene *> CreateScenes(const QList<QGraphicsItem *> &papers,
|
||||||
const QList<QGraphicsItem *> &shadows,
|
const QList<QGraphicsItem *> &shadows,
|
||||||
const QList<QList<QGraphicsItem *> > &details);
|
const QList<QList<QGraphicsItem *> > &details);
|
||||||
|
|
||||||
void SvgFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, const QMarginsF &margins)const;
|
|
||||||
void PngFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, const QMarginsF &margins)const;
|
|
||||||
void PdfFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool ignorePrinterFields,
|
|
||||||
const QMarginsF &margins)const;
|
|
||||||
void PdfTiledFile(const QString &name);
|
void PdfTiledFile(const QString &name);
|
||||||
void EpsFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool ignorePrinterFields,
|
|
||||||
const QMarginsF &margins)const;
|
|
||||||
void PsFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool ignorePrinterFields,
|
|
||||||
const QMarginsF &margins)const;
|
|
||||||
void PdfToPs(const QStringList ¶ms)const;
|
|
||||||
void ObjFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene)const;
|
|
||||||
void FlatDxfFile(const QString &name, int version, bool binary, QGraphicsRectItem *paper, QGraphicsScene *scene,
|
|
||||||
const QList<QList<QGraphicsItem *> > &details)const;
|
|
||||||
void AAMADxfFile(const QString &name, int version, bool binary, const QSize &size,
|
|
||||||
const QVector<VLayoutPiece> &details) const;
|
|
||||||
void ASTMDxfFile(const QString &name, int version, bool binary, const QSize &size,
|
|
||||||
const QVector<VLayoutPiece> &details) const;
|
|
||||||
|
|
||||||
void PreparePaper(int index) const;
|
|
||||||
void RestorePaper(int index) const;
|
|
||||||
|
|
||||||
void PrepareTextForDXF(const QString &placeholder, const QList<QList<QGraphicsItem *> > &details) const;
|
|
||||||
void RestoreTextAfterDXF(const QString &placeholder, const QList<QList<QGraphicsItem *> > &details) const;
|
|
||||||
|
|
||||||
void PrintPreview();
|
|
||||||
void LayoutPrint();
|
|
||||||
|
|
||||||
enum class PrintType : qint8 {PrintPDF, PrintPreview, PrintNative};
|
|
||||||
|
|
||||||
void SetPrinterSettings(QPrinter *printer, const PrintType &printType);
|
|
||||||
QPageSize::PageSizeId FindPageSizeId(const QSizeF &size) const;
|
|
||||||
|
|
||||||
bool isPagesUniform() const;
|
|
||||||
bool IsPagesFit(const QSizeF &printPaper) const;
|
|
||||||
|
|
||||||
void ExportScene(const QList<QGraphicsScene *> &scenes,
|
void ExportScene(const QList<QGraphicsScene *> &scenes,
|
||||||
const QList<QGraphicsItem *> &papers,
|
const QList<QGraphicsItem *> &papers,
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "dialoglayoutscale.h"
|
#include "dialoglayoutscale.h"
|
||||||
#include "ui_dialoglayoutscale.h"
|
#include "ui_dialoglayoutscale.h"
|
||||||
#include "../core/vapplication.h"
|
#include "../vmisc/vabstractvalapplication.h"
|
||||||
#include "../vmisc/vsettings.h"
|
#include "../vmisc/vsettings.h"
|
||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
@ -40,7 +40,7 @@ DialogLayoutScale::DialogLayoutScale(bool printTiled, QWidget *parent)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
|
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
|
||||||
|
|
||||||
QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||||
SCASSERT(bOk != nullptr)
|
SCASSERT(bOk != nullptr)
|
||||||
|
@ -180,7 +180,7 @@ void DialogLayoutScale::VerticalScaleChanged(double d)
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DialogLayoutScale::ReadSettings()
|
void DialogLayoutScale::ReadSettings()
|
||||||
{
|
{
|
||||||
VSettings *settings = qApp->ValentinaSettings();
|
VCommonSettings *settings = qApp->Settings();
|
||||||
const Unit unit = qApp->patternUnits();
|
const Unit unit = qApp->patternUnits();
|
||||||
|
|
||||||
// read Margins top, right, bottom, left
|
// read Margins top, right, bottom, left
|
||||||
|
@ -200,7 +200,7 @@ void DialogLayoutScale::ReadSettings()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void DialogLayoutScale::WriteSettings() const
|
void DialogLayoutScale::WriteSettings() const
|
||||||
{
|
{
|
||||||
VSettings *settings = qApp->ValentinaSettings();
|
VCommonSettings *settings = qApp->Settings();
|
||||||
const Unit unit = qApp->patternUnits();
|
const Unit unit = qApp->patternUnits();
|
||||||
|
|
||||||
// write Margins top, right, bottom, left
|
// write Margins top, right, bottom, left
|
13
src/libs/vlayout/dialogs/dialogs.pri
Normal file
13
src/libs/vlayout/dialogs/dialogs.pri
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# ADD TO EACH PATH $$PWD VARIABLE!!!!!!
|
||||||
|
# This need for corect working file translations.pro
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/dialoglayoutscale.h \
|
||||||
|
$$PWD/vabstractlayoutdialog.h
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/dialoglayoutscale.cpp \
|
||||||
|
$$PWD/vabstractlayoutdialog.cpp
|
||||||
|
|
||||||
|
FORMS += \
|
||||||
|
$$PWD/dialoglayoutscale.ui
|
|
@ -27,7 +27,7 @@
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#include "vabstractlayoutdialog.h"
|
#include "vabstractlayoutdialog.h"
|
||||||
#include "../core/vapplication.h"
|
#include "../vmisc/vabstractapplication.h"
|
||||||
#include "../vmisc/vmath.h"
|
#include "../vmisc/vmath.h"
|
||||||
|
|
||||||
//must be the same order as PaperSizeTemplate constants
|
//must be the same order as PaperSizeTemplate constants
|
||||||
|
@ -61,8 +61,8 @@ VAbstractLayoutDialog::VAbstractLayoutDialog(QWidget *parent)
|
||||||
void VAbstractLayoutDialog::InitTemplates(QComboBox *comboBoxTemplates)
|
void VAbstractLayoutDialog::InitTemplates(QComboBox *comboBoxTemplates)
|
||||||
{
|
{
|
||||||
SCASSERT(comboBoxTemplates != nullptr)
|
SCASSERT(comboBoxTemplates != nullptr)
|
||||||
const QIcon icoPaper("://icon/16x16/template.png");
|
const QIcon icoPaper(QLatin1String("://icon/16x16/template.png"));
|
||||||
const QIcon icoRoll("://icon/16x16/roll.png");
|
const QIcon icoRoll(QLatin1String("://icon/16x16/roll.png"));
|
||||||
const QString pdi = QStringLiteral("(%1ppi)").arg(PrintDPI);
|
const QString pdi = QStringLiteral("(%1ppi)").arg(PrintDPI);
|
||||||
|
|
||||||
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
|
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
|
||||||
|
@ -85,7 +85,7 @@ void VAbstractLayoutDialog::InitTemplates(QComboBox *comboBoxTemplates)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QSizeF VAbstractLayoutDialog::GetTemplateSize(PaperSizeTemplate tmpl, Unit unit)
|
auto VAbstractLayoutDialog::GetTemplateSize(PaperSizeTemplate tmpl, Unit unit) -> QSizeF
|
||||||
{
|
{
|
||||||
qreal width = 0;
|
qreal width = 0;
|
||||||
qreal height = 0;
|
qreal height = 0;
|
||||||
|
@ -159,11 +159,11 @@ QSizeF VAbstractLayoutDialog::GetTemplateSize(PaperSizeTemplate tmpl, Unit unit)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return QSizeF();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QSizeF VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit unit)
|
auto VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit unit) -> QSizeF
|
||||||
{
|
{
|
||||||
qreal w = 0;
|
qreal w = 0;
|
||||||
qreal h = 0;
|
qreal h = 0;
|
||||||
|
@ -175,14 +175,14 @@ QSizeF VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit
|
||||||
case Unit::Px:
|
case Unit::Px:
|
||||||
w = vRound(width, 2);
|
w = vRound(width, 2);
|
||||||
h = vRound(height, 2);
|
h = vRound(height, 2);
|
||||||
return QSizeF(w, h);
|
return {w, h};
|
||||||
case Unit::Inch:
|
case Unit::Inch:
|
||||||
w = vRound(width, 5);
|
w = vRound(width, 5);
|
||||||
h = vRound(height, 5);
|
h = vRound(height, 5);
|
||||||
return QSizeF(w, h);
|
return {w, h};
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QSizeF(width, height);
|
return {width, height};
|
||||||
}
|
}
|
|
@ -59,16 +59,16 @@ public:
|
||||||
|
|
||||||
explicit VAbstractLayoutDialog(QWidget *parent = nullptr);
|
explicit VAbstractLayoutDialog(QWidget *parent = nullptr);
|
||||||
|
|
||||||
static QSizeF GetTemplateSize(PaperSizeTemplate tmpl, Unit unit);
|
static auto GetTemplateSize(PaperSizeTemplate tmpl, Unit unit) -> QSizeF;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef QStringList FormatsVector;
|
typedef QStringList FormatsVector;
|
||||||
const static FormatsVector pageFormatNames;
|
const static FormatsVector pageFormatNames;
|
||||||
typedef int VIndexType;
|
typedef int VIndexType;
|
||||||
|
|
||||||
static QSizeF RoundTemplateSize(qreal width, qreal height, Unit unit);
|
static auto RoundTemplateSize(qreal width, qreal height, Unit unit) -> QSizeF;
|
||||||
|
|
||||||
void InitTemplates(QComboBox *comboBoxTemplates);
|
static void InitTemplates(QComboBox *comboBoxTemplates);
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VAbstractLayoutDialog)
|
Q_DISABLE_COPY(VAbstractLayoutDialog)
|
||||||
};
|
};
|
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
#include "../vmisc/typedef.h"
|
#include "../vmisc/typedef.h"
|
||||||
#include "vlayoutpiece.h"
|
#include "vlayoutpiece.h"
|
||||||
|
#include "vlayoutdef.h"
|
||||||
|
|
||||||
// An annoying char define, from the Windows team in <rpcndr.h>
|
// An annoying char define, from the Windows team in <rpcndr.h>
|
||||||
// #define small char
|
// #define small char
|
||||||
|
@ -49,8 +50,6 @@
|
||||||
|
|
||||||
Q_DECLARE_LOGGING_CATEGORY(lBank)
|
Q_DECLARE_LOGGING_CATEGORY(lBank)
|
||||||
|
|
||||||
enum class Cases : qint8 { CaseThreeGroup = 0, CaseTwoGroup, CaseDesc, UnknownCase};
|
|
||||||
|
|
||||||
class VBank
|
class VBank
|
||||||
{
|
{
|
||||||
Q_DECLARE_TR_FUNCTIONS(VBank)
|
Q_DECLARE_TR_FUNCTIONS(VBank)
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
# ADD TO EACH PATH $$PWD VARIABLE!!!!!!
|
# ADD TO EACH PATH $$PWD VARIABLE!!!!!!
|
||||||
# This need for corect working file translations.pro
|
# This need for corect working file translations.pro
|
||||||
|
|
||||||
|
# Suport subdirectories. Just better project code tree.
|
||||||
|
include(dialogs/dialogs.pri)
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/stable.h \
|
$$PWD/stable.h \
|
||||||
$$PWD/testpath.h \
|
$$PWD/testpath.h \
|
||||||
|
$$PWD/vlayoutexporter.h \
|
||||||
$$PWD/vlayoutgenerator.h \
|
$$PWD/vlayoutgenerator.h \
|
||||||
$$PWD/vlayoutdef.h \
|
$$PWD/vlayoutdef.h \
|
||||||
$$PWD/vlayoutpaper.h \
|
$$PWD/vlayoutpaper.h \
|
||||||
|
@ -13,6 +17,7 @@ HEADERS += \
|
||||||
$$PWD/vcontour_p.h \
|
$$PWD/vcontour_p.h \
|
||||||
$$PWD/vbestsquare.h \
|
$$PWD/vbestsquare.h \
|
||||||
$$PWD/vposition.h \
|
$$PWD/vposition.h \
|
||||||
|
$$PWD/vprintlayout.h \
|
||||||
$$PWD/vsapoint.h \
|
$$PWD/vsapoint.h \
|
||||||
$$PWD/vtextmanager.h \
|
$$PWD/vtextmanager.h \
|
||||||
$$PWD/vposter.h \
|
$$PWD/vposter.h \
|
||||||
|
@ -28,12 +33,14 @@ HEADERS += \
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/testpath.cpp \
|
$$PWD/testpath.cpp \
|
||||||
|
$$PWD/vlayoutexporter.cpp \
|
||||||
$$PWD/vlayoutgenerator.cpp \
|
$$PWD/vlayoutgenerator.cpp \
|
||||||
$$PWD/vlayoutpaper.cpp \
|
$$PWD/vlayoutpaper.cpp \
|
||||||
$$PWD/vbank.cpp \
|
$$PWD/vbank.cpp \
|
||||||
$$PWD/vcontour.cpp \
|
$$PWD/vcontour.cpp \
|
||||||
$$PWD/vbestsquare.cpp \
|
$$PWD/vbestsquare.cpp \
|
||||||
$$PWD/vposition.cpp \
|
$$PWD/vposition.cpp \
|
||||||
|
$$PWD/vprintlayout.cpp \
|
||||||
$$PWD/vtextmanager.cpp \
|
$$PWD/vtextmanager.cpp \
|
||||||
$$PWD/vposter.cpp \
|
$$PWD/vposter.cpp \
|
||||||
$$PWD/vgraphicsfillitem.cpp \
|
$$PWD/vgraphicsfillitem.cpp \
|
||||||
|
|
|
@ -115,6 +115,8 @@ struct VCachedPositions
|
||||||
QPainterPath layoutAllowancePath{};
|
QPainterPath layoutAllowancePath{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class Cases : qint8 { CaseThreeGroup = 0, CaseTwoGroup, CaseDesc, UnknownCase};
|
||||||
|
|
||||||
/* Warning! Debugging doesn't work stable in debug mode. If you need big allocation use release mode. Or disable
|
/* Warning! Debugging doesn't work stable in debug mode. If you need big allocation use release mode. Or disable
|
||||||
* Address Sanitizer. See page https://bitbucket.org/dismine/valentina/wiki/developers/Address_Sanitizer
|
* Address Sanitizer. See page https://bitbucket.org/dismine/valentina/wiki/developers/Address_Sanitizer
|
||||||
*/
|
*/
|
||||||
|
|
368
src/libs/vlayout/vlayoutexporter.cpp
Normal file
368
src/libs/vlayout/vlayoutexporter.cpp
Normal file
|
@ -0,0 +1,368 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vlayoutexporter.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 19 12, 2020
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentina project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2020 Valentina project
|
||||||
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
#include "vlayoutexporter.h"
|
||||||
|
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPrinter>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QSvgGenerator>
|
||||||
|
#include <QTemporaryFile>
|
||||||
|
#include <QtDebug>
|
||||||
|
#include <QCursor>
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
|
||||||
|
#include "../vmisc/vmath.h"
|
||||||
|
#include "../vmisc/defglobal.h"
|
||||||
|
#include "../vmisc/def.h"
|
||||||
|
#include "../vobj/vobjpaintdevice.h"
|
||||||
|
#include "../vdxf/vdxfpaintdevice.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, PDFTOPS, (QLatin1String("pdftops.exe")))
|
||||||
|
#else
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, PDFTOPS, (QLatin1String("pdftops")))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief PrepareTextForDXF prepare QGraphicsSimpleTextItem items for export to flat dxf.
|
||||||
|
*
|
||||||
|
* Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding special
|
||||||
|
* placholder. This method append it.
|
||||||
|
*
|
||||||
|
* @param placeholder placeholder that will be appended to each QGraphicsSimpleTextItem item's text string.
|
||||||
|
*/
|
||||||
|
void PrepareTextForDXF(const QString &placeholder, const QList<QList<QGraphicsItem *> > &details)
|
||||||
|
{
|
||||||
|
for (const auto &paperItems : details)
|
||||||
|
{
|
||||||
|
for (auto *item : paperItems)
|
||||||
|
{
|
||||||
|
QList<QGraphicsItem *> pieceChildren = item->childItems();
|
||||||
|
for (auto *child : qAsConst(pieceChildren))
|
||||||
|
{
|
||||||
|
if (child->type() == QGraphicsSimpleTextItem::Type)
|
||||||
|
{
|
||||||
|
if(auto *textItem = qgraphicsitem_cast<QGraphicsSimpleTextItem *>(child))
|
||||||
|
{
|
||||||
|
textItem->setText(textItem->text() + placeholder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief RestoreTextAfterDXF restore QGraphicsSimpleTextItem items after export to flat dxf.
|
||||||
|
*
|
||||||
|
* Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding special
|
||||||
|
* placholder. This method remove it.
|
||||||
|
*
|
||||||
|
* @param placeholder placeholder that will be removed from each QGraphicsSimpleTextItem item's text string.
|
||||||
|
*/
|
||||||
|
void RestoreTextAfterDXF(const QString &placeholder, const QList<QList<QGraphicsItem *> > &details)
|
||||||
|
{
|
||||||
|
for (const auto &paperItems : details)
|
||||||
|
{
|
||||||
|
for (auto *item : paperItems)
|
||||||
|
{
|
||||||
|
QList<QGraphicsItem *> pieceChildren = item->childItems();
|
||||||
|
for (auto *child : qAsConst(pieceChildren))
|
||||||
|
{
|
||||||
|
if (child->type() == QGraphicsSimpleTextItem::Type)
|
||||||
|
{
|
||||||
|
if(auto *textItem = qgraphicsitem_cast<QGraphicsSimpleTextItem *>(child))
|
||||||
|
{
|
||||||
|
QString text = textItem->text();
|
||||||
|
text.replace(placeholder, QString());
|
||||||
|
textItem->setText(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutExporter::ExportToSVG(QGraphicsScene *scene) const
|
||||||
|
{
|
||||||
|
QSvgGenerator generator;
|
||||||
|
generator.setFileName(m_fileName);
|
||||||
|
|
||||||
|
QSize drawingSize;
|
||||||
|
drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right()));
|
||||||
|
drawingSize.setHeight(qFloor(m_imageRect.height() * m_yScale + m_margins.top() + m_margins.bottom()));
|
||||||
|
generator.setSize(drawingSize);
|
||||||
|
|
||||||
|
QRectF viewBoxRect;
|
||||||
|
viewBoxRect.setWidth(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right());
|
||||||
|
viewBoxRect.setHeight(m_imageRect.height() * m_yScale + m_margins.top() + m_margins.bottom());
|
||||||
|
generator.setViewBox(viewBoxRect);
|
||||||
|
|
||||||
|
generator.setTitle(m_title);
|
||||||
|
generator.setDescription(m_description);
|
||||||
|
generator.setResolution(static_cast<int>(PrintDPI));
|
||||||
|
|
||||||
|
QPainter painter;
|
||||||
|
painter.begin(&generator);
|
||||||
|
painter.translate(m_margins.left(), m_margins.top());
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
painter.setPen(m_pen);
|
||||||
|
painter.setBrush(QBrush(Qt::NoBrush));
|
||||||
|
painter.scale(m_xScale, m_yScale);
|
||||||
|
scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio);
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutExporter::ExportToPNG(QGraphicsScene *scene) const
|
||||||
|
{
|
||||||
|
// Create the image with the exact size of the shrunk scene
|
||||||
|
QSize drawingSize;
|
||||||
|
drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right()));
|
||||||
|
drawingSize.setHeight(qFloor(m_imageRect.height() * m_yScale + m_margins.top() + m_margins.bottom()));
|
||||||
|
|
||||||
|
QImage image(drawingSize, QImage::Format_ARGB32);
|
||||||
|
image.fill(Qt::white);
|
||||||
|
|
||||||
|
QPainter painter(&image);
|
||||||
|
painter.translate(m_margins.left(), m_margins.top());
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
painter.setPen(m_pen);
|
||||||
|
painter.setBrush(QBrush(Qt::NoBrush));
|
||||||
|
painter.scale(m_xScale, m_yScale);
|
||||||
|
|
||||||
|
scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio);
|
||||||
|
image.save(m_fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutExporter::ExportToPDF(QGraphicsScene *scene) const
|
||||||
|
{
|
||||||
|
QPrinter printer;
|
||||||
|
printer.setCreator(QGuiApplication::applicationDisplayName() + QChar(QChar::Space) +
|
||||||
|
QCoreApplication::applicationVersion());
|
||||||
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
||||||
|
printer.setOutputFileName(m_fileName);
|
||||||
|
printer.setDocName(QFileInfo(m_fileName).fileName());
|
||||||
|
printer.setResolution(static_cast<int>(PrintDPI));
|
||||||
|
printer.setOrientation(QPrinter::Portrait);
|
||||||
|
printer.setFullPage(m_ignorePrinterMargins);
|
||||||
|
|
||||||
|
qreal width = FromPixel(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right(), Unit::Mm);
|
||||||
|
qreal height = FromPixel(m_imageRect.height() * m_yScale + m_margins.top() + m_margins.bottom(), Unit::Mm);
|
||||||
|
|
||||||
|
if (not printer.setPageSize(QPageSize(QSizeF(width, height), QPageSize::Millimeter)))
|
||||||
|
{
|
||||||
|
qWarning() << tr("Cannot set printer page size");
|
||||||
|
}
|
||||||
|
|
||||||
|
const qreal left = FromPixel(m_margins.left(), Unit::Mm);
|
||||||
|
const qreal top = FromPixel(m_margins.top(), Unit::Mm);
|
||||||
|
const qreal right = FromPixel(m_margins.right(), Unit::Mm);
|
||||||
|
const qreal bottom = FromPixel(m_margins.bottom(), Unit::Mm);
|
||||||
|
|
||||||
|
if (not printer.setPageMargins(QMarginsF(left, top, right, bottom), QPageLayout::Millimeter))
|
||||||
|
{
|
||||||
|
qWarning() << tr("Cannot set printer margins");
|
||||||
|
}
|
||||||
|
|
||||||
|
QPainter painter;
|
||||||
|
if (not painter.begin(&printer))
|
||||||
|
{ // failed to open file
|
||||||
|
qCritical() << qUtf8Printable(tr("Can't open file '%1'").arg(m_fileName));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
painter.setPen(m_pen);
|
||||||
|
painter.setBrush(QBrush(Qt::NoBrush));
|
||||||
|
painter.scale(m_xScale, m_yScale);
|
||||||
|
scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio);
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutExporter::ExportToOBJ(QGraphicsScene *scene) const
|
||||||
|
{
|
||||||
|
VObjPaintDevice generator;
|
||||||
|
generator.setFileName(m_fileName);
|
||||||
|
generator.setSize(m_imageRect.size().toSize());
|
||||||
|
generator.setResolution(static_cast<int>(PrintDPI));
|
||||||
|
|
||||||
|
QPainter painter;
|
||||||
|
painter.begin(&generator);
|
||||||
|
scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio);
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutExporter::ExportToPS(QGraphicsScene *scene) const
|
||||||
|
{
|
||||||
|
QTemporaryFile tmp;
|
||||||
|
if (tmp.open())
|
||||||
|
{
|
||||||
|
ExportToPDF(scene);
|
||||||
|
PdfToPs(QStringList{tmp.fileName(), m_fileName});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutExporter::ExportToEPS(QGraphicsScene *scene) const
|
||||||
|
{
|
||||||
|
QTemporaryFile tmp;
|
||||||
|
if (tmp.open())
|
||||||
|
{
|
||||||
|
ExportToPDF(scene);
|
||||||
|
PdfToPs(QStringList{QStringLiteral("-eps"), tmp.fileName(), m_fileName});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList<QList<QGraphicsItem *> > &details) const
|
||||||
|
{
|
||||||
|
PrepareTextForDXF(endStringPlaceholder, details);
|
||||||
|
|
||||||
|
VDxfPaintDevice generator;
|
||||||
|
generator.setFileName(m_fileName);
|
||||||
|
generator.setSize(QSize(qFloor(m_imageRect.width() * m_xScale), qFloor(m_imageRect.height() * m_yScale)));
|
||||||
|
generator.setResolution(PrintDPI);
|
||||||
|
generator.SetVersion(static_cast<DRW::Version>(m_dxfVersion));
|
||||||
|
generator.SetBinaryFormat(m_binaryDxfFormat);
|
||||||
|
generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
|
||||||
|
|
||||||
|
QPainter painter;
|
||||||
|
if (painter.begin(&generator))
|
||||||
|
{
|
||||||
|
painter.scale(m_xScale, m_yScale);
|
||||||
|
scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio);
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
RestoreTextAfterDXF(endStringPlaceholder, details);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutExporter::ExportToAAMADXF(const QVector<VLayoutPiece> &details) const
|
||||||
|
{
|
||||||
|
VDxfPaintDevice generator;
|
||||||
|
generator.setFileName(m_fileName);
|
||||||
|
generator.setSize(QSize(qCeil(m_imageRect.width() * m_xScale), qCeil(m_imageRect.height() * m_yScale)));
|
||||||
|
generator.setResolution(PrintDPI);
|
||||||
|
generator.SetVersion(static_cast<DRW::Version>(m_dxfVersion));
|
||||||
|
generator.SetBinaryFormat(m_binaryDxfFormat);
|
||||||
|
generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
|
||||||
|
generator.SetXScale(m_xScale);
|
||||||
|
generator.SetYScale(m_yScale);
|
||||||
|
generator.ExportToAAMA(details);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutExporter::ExportToASTMDXF(const QVector<VLayoutPiece> &details) const
|
||||||
|
{
|
||||||
|
VDxfPaintDevice generator;
|
||||||
|
generator.setFileName(m_fileName);
|
||||||
|
generator.setSize(QSize(qCeil(m_imageRect.width() * m_xScale), qCeil(m_imageRect.height() * m_yScale)));
|
||||||
|
generator.setResolution(PrintDPI);
|
||||||
|
generator.SetVersion(static_cast<DRW::Version>(m_dxfVersion));
|
||||||
|
generator.SetBinaryFormat(m_binaryDxfFormat);
|
||||||
|
generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745
|
||||||
|
generator.SetXScale(m_xScale);
|
||||||
|
generator.SetYScale(m_yScale);
|
||||||
|
generator.ExportToASTM(details);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VLayoutExporter::SupportPDFConversion() -> bool
|
||||||
|
{
|
||||||
|
bool res = false;
|
||||||
|
|
||||||
|
QProcess proc;
|
||||||
|
#if defined(Q_OS_WIN) || defined(Q_OS_OSX)
|
||||||
|
// Seek pdftops in app bundle or near valentina.exe
|
||||||
|
proc.start(qApp->applicationDirPath() + QLatin1String("/")+ *PDFTOPS, QStringList());
|
||||||
|
#else
|
||||||
|
proc.start(*PDFTOPS, QStringList()); // Seek pdftops in standard path
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const int timeout = 15000;
|
||||||
|
if (proc.waitForStarted(timeout) && (proc.waitForFinished(timeout) || proc.state() == QProcess::NotRunning))
|
||||||
|
{
|
||||||
|
res = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << *PDFTOPS << "error" << proc.error() << proc.errorString();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief PdfToPs use external tool "pdftops" for converting pdf too eps or ps format.
|
||||||
|
* @param params string with parameter for tool. Parameters have format: "-eps input_file out_file". Use -eps when
|
||||||
|
* need create eps file.
|
||||||
|
*/
|
||||||
|
void VLayoutExporter::PdfToPs(const QStringList ¶ms)
|
||||||
|
{
|
||||||
|
#ifndef QT_NO_CURSOR
|
||||||
|
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QProcess proc;
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
// Fix issue #594. Broken export on Mac.
|
||||||
|
proc.setWorkingDirectory(qApp->applicationDirPath());
|
||||||
|
proc.start(QLatin1String("./") + *PDFTOPS, params);
|
||||||
|
#else
|
||||||
|
proc.start(*PDFTOPS, params);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const int timeout = 15000;
|
||||||
|
if (proc.waitForStarted(timeout))
|
||||||
|
{
|
||||||
|
proc.waitForFinished(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef QT_NO_CURSOR
|
||||||
|
QGuiApplication::restoreOverrideCursor();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QFile f(params.last());
|
||||||
|
if (not f.exists())
|
||||||
|
{
|
||||||
|
qCritical() << qUtf8Printable(tr("Creating file '%1' failed! %2").arg(params.last(), proc.errorString()));
|
||||||
|
}
|
||||||
|
}
|
240
src/libs/vlayout/vlayoutexporter.h
Normal file
240
src/libs/vlayout/vlayoutexporter.h
Normal file
|
@ -0,0 +1,240 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vlayoutexporter.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 19 12, 2020
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentina project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2020 Valentina project
|
||||||
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
#ifndef VLAYOUTEXPORTER_H
|
||||||
|
#define VLAYOUTEXPORTER_H
|
||||||
|
|
||||||
|
#include <QMargins>
|
||||||
|
#include <QPen>
|
||||||
|
#include <QRectF>
|
||||||
|
#include <QString>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
class QGraphicsScene;
|
||||||
|
class QGraphicsItem;
|
||||||
|
class VLayoutPiece;
|
||||||
|
|
||||||
|
class VLayoutExporter
|
||||||
|
{
|
||||||
|
Q_DECLARE_TR_FUNCTIONS(VLayoutExporter)
|
||||||
|
public:
|
||||||
|
VLayoutExporter() = default;
|
||||||
|
|
||||||
|
auto FileName() const -> QString;
|
||||||
|
void SetFileName(const QString &fileName);
|
||||||
|
|
||||||
|
auto Margins() const -> QMarginsF;
|
||||||
|
void SetMargins(const QMarginsF &margins);
|
||||||
|
|
||||||
|
auto ImageRect() const -> QRectF;
|
||||||
|
void SetImageRect(const QRectF &imageRect);
|
||||||
|
|
||||||
|
auto XScale() const -> qreal;
|
||||||
|
void SetXScale(qreal xScale);
|
||||||
|
|
||||||
|
auto YScale() const -> qreal;
|
||||||
|
void SetYScale(qreal yScale);
|
||||||
|
|
||||||
|
auto Title() const -> QString;
|
||||||
|
void SetTitle(const QString &title);
|
||||||
|
|
||||||
|
auto Description() const -> QString;
|
||||||
|
void SetDescription(const QString &description);
|
||||||
|
|
||||||
|
auto Pen() const -> QPen;
|
||||||
|
void SetPen(const QPen &pen);
|
||||||
|
|
||||||
|
auto IgnorePrinterMargins() const -> bool;
|
||||||
|
void SetIgnorePrinterMargins(bool ignorePrinterMargins);
|
||||||
|
|
||||||
|
auto BinaryDxfFormat() const -> bool;
|
||||||
|
void SetBinaryDxfFormat(bool binaryFormat);
|
||||||
|
|
||||||
|
auto DxfVersion() const -> int;
|
||||||
|
void SetDxfVersion(int dxfVersion);
|
||||||
|
|
||||||
|
void ExportToSVG(QGraphicsScene *scene) const;
|
||||||
|
void ExportToPNG(QGraphicsScene *scene) const;
|
||||||
|
void ExportToPDF(QGraphicsScene *scene) const;
|
||||||
|
void ExportToOBJ(QGraphicsScene *scene) const;
|
||||||
|
void ExportToPS(QGraphicsScene *scene) const;
|
||||||
|
void ExportToEPS(QGraphicsScene *scene) const;
|
||||||
|
void ExportToFlatDXF(QGraphicsScene *scene, const QList<QList<QGraphicsItem *> > &details) const;
|
||||||
|
void ExportToAAMADXF(const QVector<VLayoutPiece> &details) const;
|
||||||
|
void ExportToASTMDXF(const QVector<VLayoutPiece> &details) const;
|
||||||
|
|
||||||
|
static auto SupportPDFConversion() -> bool;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_fileName{};
|
||||||
|
QMarginsF m_margins{};
|
||||||
|
QRectF m_imageRect{};
|
||||||
|
qreal m_xScale{1.0};
|
||||||
|
qreal m_yScale{1.0};
|
||||||
|
QString m_title{};
|
||||||
|
QString m_description{};
|
||||||
|
QPen m_pen{};
|
||||||
|
bool m_ignorePrinterMargins{false};
|
||||||
|
bool m_binaryDxfFormat{false};
|
||||||
|
int m_dxfVersion{0};
|
||||||
|
|
||||||
|
static void PdfToPs(const QStringList ¶ms);
|
||||||
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::FileName() const -> QString
|
||||||
|
{
|
||||||
|
return m_fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetFileName(const QString &fileName)
|
||||||
|
{
|
||||||
|
m_fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::Margins() const -> QMarginsF
|
||||||
|
{
|
||||||
|
return m_margins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetMargins(const QMarginsF &margins)
|
||||||
|
{
|
||||||
|
m_margins = margins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::ImageRect() const -> QRectF
|
||||||
|
{
|
||||||
|
return m_imageRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetImageRect(const QRectF &imageRect)
|
||||||
|
{
|
||||||
|
m_imageRect = imageRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::XScale() const -> qreal
|
||||||
|
{
|
||||||
|
return m_xScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetXScale(qreal xScale)
|
||||||
|
{
|
||||||
|
m_xScale = xScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::YScale() const -> qreal
|
||||||
|
{
|
||||||
|
return m_yScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetYScale(qreal yScale)
|
||||||
|
{
|
||||||
|
m_yScale = yScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::Title() const -> QString
|
||||||
|
{
|
||||||
|
return m_title;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetTitle(const QString &title)
|
||||||
|
{
|
||||||
|
m_title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::Description() const -> QString
|
||||||
|
{
|
||||||
|
return m_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetDescription(const QString &description)
|
||||||
|
{
|
||||||
|
m_description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::Pen() const -> QPen
|
||||||
|
{
|
||||||
|
return m_pen;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetPen(const QPen &pen)
|
||||||
|
{
|
||||||
|
m_pen = pen;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::IgnorePrinterMargins() const -> bool
|
||||||
|
{
|
||||||
|
return m_ignorePrinterMargins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetIgnorePrinterMargins(bool ignorePrinterMargins)
|
||||||
|
{
|
||||||
|
m_ignorePrinterMargins = ignorePrinterMargins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::BinaryDxfFormat() const -> bool
|
||||||
|
{
|
||||||
|
return m_binaryDxfFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetBinaryDxfFormat(bool binaryFormat)
|
||||||
|
{
|
||||||
|
m_binaryDxfFormat = binaryFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VLayoutExporter::DxfVersion() const -> int
|
||||||
|
{
|
||||||
|
return m_dxfVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VLayoutExporter::SetDxfVersion(int dxfVersion)
|
||||||
|
{
|
||||||
|
m_dxfVersion = dxfVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // VLAYOUTEXPORTER_H
|
762
src/libs/vlayout/vprintlayout.cpp
Normal file
762
src/libs/vlayout/vprintlayout.cpp
Normal file
|
@ -0,0 +1,762 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vprintlayout.cpp
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 22 12, 2020
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentina project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2020 Valentina project
|
||||||
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
#include "vprintlayout.h"
|
||||||
|
|
||||||
|
#include <QPrinterInfo>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QSpacerItem>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QPrintDialog>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QGraphicsRectItem>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPixmapCache>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QPrintPreviewDialog>
|
||||||
|
#include <QPageSize>
|
||||||
|
|
||||||
|
#include "dialogs/dialoglayoutscale.h"
|
||||||
|
#include "../vmisc/vabstractvalapplication.h"
|
||||||
|
#include "dialogs/vabstractlayoutdialog.h"
|
||||||
|
#include "vposter.h"
|
||||||
|
#include "../vformat/vwatermark.h"
|
||||||
|
#include "../ifc/xml/vwatermarkconverter.h"
|
||||||
|
#include "../ifc/exception/vexception.h"
|
||||||
|
#include "../vmisc/vmath.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto FindPageSizeId(QSizeF size) -> QPageSize::PageSizeId
|
||||||
|
{
|
||||||
|
auto TestSize = [size](float width, float height)
|
||||||
|
{
|
||||||
|
return size == QSizeF(width, height) || size == QSizeF(height, width);
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr int A0Width = 841;
|
||||||
|
constexpr int A0Height = 1189;
|
||||||
|
if (TestSize(A0Width, A0Height))
|
||||||
|
{
|
||||||
|
return QPageSize::A0;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr int A1Width = 594;
|
||||||
|
constexpr int A1Height = 841;
|
||||||
|
if (TestSize(A1Width, A1Height))
|
||||||
|
{
|
||||||
|
return QPageSize::A1;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr int A2Width = 420;
|
||||||
|
constexpr int A2Height = 594;
|
||||||
|
if (TestSize(A2Width, A2Height))
|
||||||
|
{
|
||||||
|
return QPageSize::A2;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr int A3Width = 297;
|
||||||
|
constexpr int A3Height = 420;
|
||||||
|
if (TestSize(A3Width, A3Height))
|
||||||
|
{
|
||||||
|
return QPageSize::A3;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr int A4Width = 210;
|
||||||
|
constexpr int A4Height = 297;
|
||||||
|
if (TestSize(A4Width, A4Height))
|
||||||
|
{
|
||||||
|
return QPageSize::A4;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr float LegalWidth = 215.9F;
|
||||||
|
constexpr float LegalHeight = 355.6F;
|
||||||
|
if (TestSize(LegalWidth, LegalHeight))
|
||||||
|
{
|
||||||
|
return QPageSize::Legal;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr float LetterWidth = 215.9F;
|
||||||
|
constexpr float LetterHeight = 279.4F;
|
||||||
|
if (TestSize(LetterWidth, LetterHeight))
|
||||||
|
{
|
||||||
|
return QPageSize::Letter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QPageSize::Custom;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
Q_REQUIRED_RESULT auto PreparePrinter(
|
||||||
|
const QPrinterInfo &info, QPrinter::PrinterMode mode = QPrinter::ScreenResolution) -> QSharedPointer<QPrinter>;
|
||||||
|
auto PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode) -> QSharedPointer<QPrinter>
|
||||||
|
{
|
||||||
|
QPrinterInfo tmpInfo = info;
|
||||||
|
if(tmpInfo.isNull() || tmpInfo.printerName().isEmpty())
|
||||||
|
{
|
||||||
|
const QStringList list = QPrinterInfo::availablePrinterNames();
|
||||||
|
if(list.isEmpty())
|
||||||
|
{
|
||||||
|
return QSharedPointer<QPrinter>();
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpInfo = QPrinterInfo::printerInfo(list.first());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto printer = QSharedPointer<QPrinter>(new QPrinter(tmpInfo, mode));
|
||||||
|
printer->setResolution(static_cast<int>(PrintDPI));
|
||||||
|
return printer;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPrintLayout::VPrintLayout(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
VPrintLayout::~VPrintLayout()
|
||||||
|
{
|
||||||
|
qDeleteAll(m_layoutScenes);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::PrintTiled()
|
||||||
|
{
|
||||||
|
m_isTiled = true;
|
||||||
|
PrintLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::PrintOrigin()
|
||||||
|
{
|
||||||
|
if (not IsPagesUniform())
|
||||||
|
{
|
||||||
|
qCritical()<<tr("For printing multipages document all sheet should have the same size.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_isTiled = false;
|
||||||
|
PrintLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::PrintPreviewTiled()
|
||||||
|
{
|
||||||
|
m_isTiled = true;
|
||||||
|
PrintPreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::PrintPreviewOrigin()
|
||||||
|
{
|
||||||
|
if (not IsPagesUniform())
|
||||||
|
{
|
||||||
|
qCritical()<<tr("For previewing multipage document all sheet should have the same size.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_isTiled = false;
|
||||||
|
PrintPreview();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::PdfTiledFile(const QString &name)
|
||||||
|
{
|
||||||
|
m_isTiled = true;
|
||||||
|
|
||||||
|
if (m_isLayoutStale)
|
||||||
|
{
|
||||||
|
if (ContinueIfLayoutStale(m_parentWidget) == QMessageBox::No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QPrinter printer;
|
||||||
|
SetPrinterSettings(&printer, PrintType::PrintPDF, name);
|
||||||
|
|
||||||
|
// Call IsPagesFit after setting a printer settings and check if pages is not bigger than printer's paper size
|
||||||
|
if (not m_isTiled && not IsPagesFit(printer.pageLayout().paintRectPixels(printer.resolution()).size()))
|
||||||
|
{
|
||||||
|
qWarning()<<tr("Pages will be cropped because they do not fit printer paper size.");
|
||||||
|
}
|
||||||
|
|
||||||
|
printer.setResolution(static_cast<int>(PrintDPI));
|
||||||
|
PrintPages(&printer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::CleanLayout()
|
||||||
|
{
|
||||||
|
qDeleteAll(m_layoutScenes);
|
||||||
|
m_layoutScenes.clear();
|
||||||
|
m_layoutPapers.clear();
|
||||||
|
m_layoutShadows.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::PrintLayout()
|
||||||
|
{
|
||||||
|
if (m_isLayoutStale)
|
||||||
|
{
|
||||||
|
if (ContinueIfLayoutStale(m_parentWidget) == QMessageBox::No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// display print dialog and if accepted print
|
||||||
|
QPrinterInfo info = QPrinterInfo::printerInfo(m_layoutPrinterName);
|
||||||
|
if(info.isNull() || info.printerName().isEmpty())
|
||||||
|
{
|
||||||
|
info = QPrinterInfo::defaultPrinter();
|
||||||
|
}
|
||||||
|
QSharedPointer<QPrinter> printer = PreparePrinter(info, QPrinter::HighResolution);
|
||||||
|
if (printer.isNull())
|
||||||
|
{
|
||||||
|
qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")),
|
||||||
|
qUtf8Printable(tr("Cannot proceed because there are no available printers in your system.")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
DialogLayoutScale layoutScale(m_isTiled, m_parentWidget);
|
||||||
|
layoutScale.SetXScale(1);
|
||||||
|
layoutScale.SetYScale(1);
|
||||||
|
layoutScale.exec();
|
||||||
|
|
||||||
|
m_xscale = layoutScale.GetXScale();
|
||||||
|
m_yscale = layoutScale.GetYScale();
|
||||||
|
}
|
||||||
|
|
||||||
|
SetPrinterSettings(printer.data(), PrintType::PrintNative);
|
||||||
|
QPrintDialog dialog(printer.data(), m_parentWidget);
|
||||||
|
// If only user couldn't change page margins we could use method setMinMax();
|
||||||
|
dialog.setOption(QPrintDialog::PrintCurrentPage, false);
|
||||||
|
if (dialog.exec() == QDialog::Accepted)
|
||||||
|
{
|
||||||
|
printer->setResolution(static_cast<int>(PrintDPI));
|
||||||
|
PrintPages(printer.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::PrintPreview()
|
||||||
|
{
|
||||||
|
if (m_isLayoutStale)
|
||||||
|
{
|
||||||
|
if (ContinueIfLayoutStale(m_parentWidget) == QMessageBox::No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QPrinterInfo info = QPrinterInfo::printerInfo(m_layoutPrinterName);
|
||||||
|
if(info.isNull() || info.printerName().isEmpty())
|
||||||
|
{
|
||||||
|
info = QPrinterInfo::defaultPrinter();
|
||||||
|
}
|
||||||
|
QSharedPointer<QPrinter> printer = PreparePrinter(info);
|
||||||
|
if (printer.isNull())
|
||||||
|
{
|
||||||
|
qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")),
|
||||||
|
qUtf8Printable(tr("Cannot proceed because there are no available printers in your system.")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
DialogLayoutScale layoutScale(m_isTiled, m_parentWidget);
|
||||||
|
layoutScale.SetXScale(1);
|
||||||
|
layoutScale.SetYScale(1);
|
||||||
|
layoutScale.exec();
|
||||||
|
|
||||||
|
m_xscale = layoutScale.GetXScale();
|
||||||
|
m_yscale = layoutScale.GetYScale();
|
||||||
|
}
|
||||||
|
|
||||||
|
SetPrinterSettings(printer.data(), PrintType::PrintPreview);
|
||||||
|
printer->setResolution(static_cast<int>(PrintDPI));
|
||||||
|
|
||||||
|
// display print preview dialog
|
||||||
|
QPrintPreviewDialog preview(printer.data());
|
||||||
|
connect(&preview, &QPrintPreviewDialog::paintRequested, this, &VPrintLayout::PrintPages);
|
||||||
|
preview.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::PrintPages(QPrinter *printer)
|
||||||
|
{
|
||||||
|
QPainter painter;
|
||||||
|
if (not painter.begin(printer))
|
||||||
|
{ // failed to open file
|
||||||
|
qCritical() << tr("Failed to open file, is it writable?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||||
|
painter.setBrush ( QBrush ( Qt::NoBrush ) );
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
QSharedPointer<QVector<PosterData>> poster;
|
||||||
|
QSharedPointer<VPoster> posterazor;
|
||||||
|
|
||||||
|
if (m_isTiled)
|
||||||
|
{
|
||||||
|
// when isTiled, the landscape tiles have to be rotated, because the pages
|
||||||
|
// stay portrait in the pdf
|
||||||
|
if(m_tiledPDFOrientation == PageOrientation::Landscape)
|
||||||
|
{
|
||||||
|
const int angle = -90;
|
||||||
|
painter.rotate(angle);
|
||||||
|
painter.translate(-ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
poster = QSharedPointer<QVector<PosterData>>(new QVector<PosterData>());
|
||||||
|
posterazor = QSharedPointer<VPoster>(new VPoster(printer));
|
||||||
|
|
||||||
|
for (int i=0; i < m_layoutScenes.size(); ++i)
|
||||||
|
{
|
||||||
|
auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(m_layoutPapers.at(i));
|
||||||
|
if (paper != nullptr)
|
||||||
|
{
|
||||||
|
QRectF paperRect = paper->rect();
|
||||||
|
QSizeF image(paperRect.width() * m_xscale, paperRect.height() * m_yscale);
|
||||||
|
*poster += posterazor->Calc(image.toSize(), i, m_tiledPDFOrientation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
count = poster->size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
count = m_layoutScenes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the fromPage(), toPage(), supportsMultipleCopies(), and numCopies() values from QPrinter.
|
||||||
|
int firstPage = printer->fromPage() - 1;
|
||||||
|
if (firstPage >= count)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (firstPage == -1)
|
||||||
|
{
|
||||||
|
firstPage = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lastPage = printer->toPage() - 1;
|
||||||
|
if (lastPage == -1 || lastPage >= count)
|
||||||
|
{
|
||||||
|
lastPage = count - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int numPages = lastPage - firstPage + 1;
|
||||||
|
int copyCount = 1;
|
||||||
|
if (not printer->supportsMultipleCopies())
|
||||||
|
{
|
||||||
|
copyCount = printer->copyCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
VWatermarkData data = WatermarkData();
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
for (int i = 0; i < copyCount; ++i)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < numPages; ++j)
|
||||||
|
{
|
||||||
|
if (i != 0 || j != 0)
|
||||||
|
{
|
||||||
|
if (not printer->newPage())
|
||||||
|
{
|
||||||
|
qCritical() << tr("Failed in flushing page to disk, disk full?");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int index;
|
||||||
|
if (printer->pageOrder() == QPrinter::FirstPageFirst)
|
||||||
|
{
|
||||||
|
index = firstPage + j;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index = lastPage - j;
|
||||||
|
}
|
||||||
|
|
||||||
|
int paperIndex = -1;
|
||||||
|
m_isTiled ? paperIndex = static_cast<int>(poster->at(index).index) : paperIndex = index;
|
||||||
|
|
||||||
|
auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(m_layoutPapers.at(paperIndex));
|
||||||
|
if (paper != nullptr)
|
||||||
|
{
|
||||||
|
QVector<QGraphicsItem *> posterData;
|
||||||
|
|
||||||
|
if (m_isTiled)
|
||||||
|
{
|
||||||
|
// Draw tile
|
||||||
|
posterData = posterazor->Tile(paper, poster->at(index), m_layoutScenes.size(), data,
|
||||||
|
m_watermarkPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
PreparePaper(paperIndex);
|
||||||
|
|
||||||
|
// Render
|
||||||
|
QRectF source;
|
||||||
|
m_isTiled ? source = poster->at(index).rect : source = paper->rect();
|
||||||
|
|
||||||
|
qreal x;
|
||||||
|
qreal y;
|
||||||
|
if(printer->fullPage())
|
||||||
|
{
|
||||||
|
QPageLayout layout = printer->pageLayout();
|
||||||
|
layout.setUnits(QPageLayout::Millimeter);
|
||||||
|
QMarginsF printerMargins = layout.margins();
|
||||||
|
x = qFloor(ToPixel(printerMargins.left(), Unit::Mm));
|
||||||
|
y = qFloor(ToPixel(printerMargins.top(), Unit::Mm));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
x = 0; y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF target(x * xscale, y * yscale, source.width() * xscale, source.height() * yscale);
|
||||||
|
|
||||||
|
m_layoutScenes.at(paperIndex)->render(&painter, target, source, Qt::IgnoreAspectRatio);
|
||||||
|
|
||||||
|
if (m_isTiled)
|
||||||
|
{
|
||||||
|
// Remove borders
|
||||||
|
qDeleteAll(posterData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore
|
||||||
|
RestorePaper(paperIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::SetPrinterSettings(QPrinter *printer, PrintType printType, const QString &filePath)
|
||||||
|
{
|
||||||
|
SCASSERT(printer != nullptr)
|
||||||
|
printer->setCreator(QGuiApplication::applicationDisplayName() + QChar(QChar::Space) +
|
||||||
|
QCoreApplication::applicationVersion());
|
||||||
|
printer->setPageOrientation(m_isLayoutPortrait ? QPageLayout::Portrait : QPageLayout::Landscape);
|
||||||
|
SetPrinterPageSize(printer);
|
||||||
|
printer->setFullPage(m_ignorePrinterMargins);
|
||||||
|
SetPrinterPrinterMargins(printer);
|
||||||
|
SetPrinterOutputFileName(printer, printType, filePath);
|
||||||
|
printer->setDocName(filePath.isEmpty() ? DocName() : QFileInfo(filePath).baseName());
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::SetPrinterPrinterMargins(QPrinter *printer)
|
||||||
|
{
|
||||||
|
SCASSERT(printer != nullptr)
|
||||||
|
QMarginsF printerMargins;
|
||||||
|
|
||||||
|
if (not m_isTiled)
|
||||||
|
{
|
||||||
|
printerMargins = QMarginsF(UnitConvertor(m_layoutMargins, Unit::Px, Unit::Mm));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(m_tiledPDFOrientation == PageOrientation::Landscape)
|
||||||
|
{
|
||||||
|
// because when painting we have a -90rotation in landscape mode,
|
||||||
|
// see function PrintPages.
|
||||||
|
printerMargins = QMarginsF(m_tiledMargins.bottom(), m_tiledMargins.left(), m_tiledMargins.top(),
|
||||||
|
m_tiledMargins.right());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printerMargins = m_tiledMargins;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool success = printer->setPageMargins(printerMargins, QPageLayout::Millimeter);
|
||||||
|
if (not success)
|
||||||
|
{
|
||||||
|
qWarning() << tr("Cannot set printer margins");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::SetPrinterOutputFileName(QPrinter *printer, PrintType printType, const QString &filePath)
|
||||||
|
{
|
||||||
|
SCASSERT(printer != nullptr)
|
||||||
|
|
||||||
|
switch(printType)
|
||||||
|
{
|
||||||
|
case PrintType::PrintPDF:
|
||||||
|
{
|
||||||
|
const QString outputFileName = filePath.isEmpty() ? QDir::homePath() + QDir::separator() + DocName()
|
||||||
|
: filePath;
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
printer->setOutputFileName(outputFileName);
|
||||||
|
#else
|
||||||
|
printer->setOutputFileName(outputFileName + QStringLiteral(".pdf"));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
printer->setOutputFormat(QPrinter::NativeFormat);
|
||||||
|
#else
|
||||||
|
printer->setOutputFormat(QPrinter::PdfFormat);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PrintType::PrintNative:
|
||||||
|
printer->setOutputFileName(QString());//Disable printing to file if was enabled.
|
||||||
|
printer->setOutputFormat(QPrinter::NativeFormat);
|
||||||
|
break;
|
||||||
|
case PrintType::PrintPreview: /*do nothing*/
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::SetPrinterPageSize(QPrinter *printer)
|
||||||
|
{
|
||||||
|
SCASSERT(printer != nullptr)
|
||||||
|
|
||||||
|
if (not m_isTiled)
|
||||||
|
{
|
||||||
|
qreal width = FromPixel(m_layoutPaperSize.width(), Unit::Mm);
|
||||||
|
qreal height = FromPixel(m_layoutPaperSize.height(), Unit::Mm);
|
||||||
|
|
||||||
|
if (m_isAutoCropLength || m_isUnitePages)
|
||||||
|
{
|
||||||
|
auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(m_layoutPapers.at(0));
|
||||||
|
if (paper != nullptr)
|
||||||
|
{
|
||||||
|
if (m_isLayoutPortrait)
|
||||||
|
{
|
||||||
|
height = FromPixel(paper->rect().height() + m_layoutMargins.top() + m_layoutMargins.bottom(),
|
||||||
|
Unit::Mm);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
width = FromPixel(paper->rect().width() + m_layoutMargins.left() + m_layoutMargins.right(),
|
||||||
|
Unit::Mm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_isAutoCropWidth)
|
||||||
|
{
|
||||||
|
auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(m_layoutPapers.at(0));
|
||||||
|
if (paper != nullptr)
|
||||||
|
{
|
||||||
|
if (m_isLayoutPortrait)
|
||||||
|
{
|
||||||
|
width = FromPixel(paper->rect().width() + m_layoutMargins.left() + m_layoutMargins.right(),
|
||||||
|
Unit::Mm);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
height = FromPixel(paper->rect().height() + m_layoutMargins.top() + m_layoutMargins.bottom(),
|
||||||
|
Unit::Mm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QSizeF size = QSizeF(width, height);
|
||||||
|
|
||||||
|
if (not m_isLayoutPortrait)
|
||||||
|
{
|
||||||
|
size.transpose(); // QPrinter reverse this for landscape orientation
|
||||||
|
}
|
||||||
|
|
||||||
|
const QPageSize::PageSizeId pSZ = FindPageSizeId(size);
|
||||||
|
if (pSZ == QPageSize::Custom)
|
||||||
|
{
|
||||||
|
if (not printer->setPageSize(QPageSize(size, QPageSize::Millimeter)))
|
||||||
|
{
|
||||||
|
qWarning() << tr("Cannot set custom printer page size");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (not printer->setPageSize(QPageSize(pSZ)))
|
||||||
|
{
|
||||||
|
qWarning() << tr("Cannot set printer page size");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (not printer->setPageSize(QPageSize(m_tiledPDFPaperSize, QPageSize::Millimeter)))
|
||||||
|
{
|
||||||
|
qWarning() << tr("Cannot set printer tiled page size");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VPrintLayout::DocName() const -> QString
|
||||||
|
{
|
||||||
|
return not m_fileName.isEmpty() ? m_fileName : tr("unamed");
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::PreparePaper(int index) const
|
||||||
|
{
|
||||||
|
auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(m_layoutPapers.at(index));
|
||||||
|
if (paper != nullptr)
|
||||||
|
{
|
||||||
|
QBrush brush(Qt::white);
|
||||||
|
m_layoutScenes.at(index)->setBackgroundBrush(brush);
|
||||||
|
m_layoutShadows.at(index)->setVisible(false);
|
||||||
|
const float thinPen = 0.1F;
|
||||||
|
paper->setPen(QPen(Qt::white, thinPen, Qt::NoPen));// border
|
||||||
|
}
|
||||||
|
|
||||||
|
QTransform matrix;
|
||||||
|
matrix.scale(m_xscale, m_yscale);
|
||||||
|
|
||||||
|
QList<QGraphicsItem *> paperDetails = m_layoutDetails.at(index);
|
||||||
|
for (auto *detail : paperDetails)
|
||||||
|
{
|
||||||
|
QTransform m = detail->transform();
|
||||||
|
m *= matrix;
|
||||||
|
detail->setTransform(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VPrintLayout::RestorePaper(int index) const
|
||||||
|
{
|
||||||
|
auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(m_layoutPapers.at(index));
|
||||||
|
if (paper != nullptr)
|
||||||
|
{
|
||||||
|
// Restore
|
||||||
|
paper->setPen(QPen(Qt::black, 1));
|
||||||
|
QBrush brush(Qt::gray);
|
||||||
|
m_layoutScenes.at(index)->setBackgroundBrush(brush);
|
||||||
|
m_layoutShadows.at(index)->setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTransform matrix;
|
||||||
|
matrix.scale(1./m_xscale, 1./m_yscale);
|
||||||
|
|
||||||
|
QList<QGraphicsItem *> paperDetails = m_layoutDetails.at(index);
|
||||||
|
for (auto *detail : paperDetails)
|
||||||
|
{
|
||||||
|
QTransform m = detail->transform();
|
||||||
|
m *= matrix;
|
||||||
|
detail->setTransform(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VPrintLayout::IsPagesUniform() const -> bool
|
||||||
|
{
|
||||||
|
if (m_layoutPapers.size() < 2)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(m_layoutPapers.at(0));
|
||||||
|
SCASSERT(paper != nullptr)
|
||||||
|
|
||||||
|
return std::all_of(m_layoutPapers.begin(), m_layoutPapers.end(), [paper](QGraphicsItem *paperItem)
|
||||||
|
{
|
||||||
|
auto *p = qgraphicsitem_cast<QGraphicsRectItem *>(paperItem);
|
||||||
|
SCASSERT(p != nullptr)
|
||||||
|
return paper->rect() == p->rect();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VPrintLayout::IsPagesFit(QSizeF printPaper) const -> bool
|
||||||
|
{
|
||||||
|
// On previous stage already was checked if pages have uniform size
|
||||||
|
// Enough will be to check only one page
|
||||||
|
auto *p = qgraphicsitem_cast<QGraphicsRectItem *>(m_layoutPapers.at(0));
|
||||||
|
SCASSERT(p != nullptr)
|
||||||
|
const QSizeF pSize = p->rect().size();
|
||||||
|
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
|
||||||
|
{
|
||||||
|
QMessageBox msgBox(parent);
|
||||||
|
msgBox.setIcon(QMessageBox::Question);
|
||||||
|
msgBox.setWindowTitle(tr("The layout is stale."));
|
||||||
|
msgBox.setText(tr("The layout was not updated since last pattern modification. Do you want to continue?"));
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
|
||||||
|
msgBox.setDefaultButton(QMessageBox::No);
|
||||||
|
const int width = 500;
|
||||||
|
auto* horizontalSpacer = new QSpacerItem(width, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
||||||
|
auto* layout = qobject_cast<QGridLayout*>(msgBox.layout());
|
||||||
|
SCASSERT(layout != nullptr)
|
||||||
|
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
|
||||||
|
return msgBox.exec();
|
||||||
|
}
|
427
src/libs/vlayout/vprintlayout.h
Normal file
427
src/libs/vlayout/vprintlayout.h
Normal file
|
@ -0,0 +1,427 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vprintlayout.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 22 12, 2020
|
||||||
|
**
|
||||||
|
** @brief
|
||||||
|
** @copyright
|
||||||
|
** This source code is part of the Valentina project, a pattern making
|
||||||
|
** program, whose allow create and modeling patterns of clothing.
|
||||||
|
** Copyright (C) 2020 Valentina project
|
||||||
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
||||||
|
**
|
||||||
|
** Valentina is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 3 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** Valentina is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
#ifndef VPRINTLAYOUT_H
|
||||||
|
#define VPRINTLAYOUT_H
|
||||||
|
|
||||||
|
#include <QMargins>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QSizeF>
|
||||||
|
|
||||||
|
#include "../vmisc/def.h"
|
||||||
|
|
||||||
|
enum class PrintType : qint8 {PrintPDF, PrintPreview, PrintNative};
|
||||||
|
|
||||||
|
class QPrinter;
|
||||||
|
class QGraphicsScene;
|
||||||
|
struct VWatermarkData;
|
||||||
|
|
||||||
|
class VPrintLayout : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
VPrintLayout(QObject *parent = nullptr);
|
||||||
|
~VPrintLayout();
|
||||||
|
|
||||||
|
auto FileName() const -> QString;
|
||||||
|
void SetFileName(const QString &fileName);
|
||||||
|
|
||||||
|
auto LayoutPaperSize() const -> QSizeF;
|
||||||
|
void SetLayoutPaperSize(const QSizeF &paperSize);
|
||||||
|
|
||||||
|
auto LayoutMargins() const -> QMarginsF;
|
||||||
|
void SetLayoutMargins(const QMarginsF &layoutMargins);
|
||||||
|
|
||||||
|
auto ParentWidget() const -> QWidget *;
|
||||||
|
void SetParentWidget(QWidget *parentWidget);
|
||||||
|
|
||||||
|
auto IsLayoutPortrait() const -> bool;
|
||||||
|
void SetLayoutPortrait(bool isLayoutPortrait);
|
||||||
|
|
||||||
|
auto IgnorePrinterMargins() const -> bool;
|
||||||
|
void SetIgnorePrinterMargins(bool ignorePrinterFields);
|
||||||
|
|
||||||
|
auto IsAutoCropLength() const -> bool;
|
||||||
|
void SetAutoCropLength(bool isAutoCropLength);
|
||||||
|
|
||||||
|
auto IsAutoCropWidth() const -> bool;
|
||||||
|
void SetAutoCropWidth(bool isAutoCropWidth);
|
||||||
|
|
||||||
|
auto IsUnitePages() const -> bool;
|
||||||
|
void SetUnitePages(bool isUnitePages);
|
||||||
|
|
||||||
|
auto LayoutPrinterName() const -> QString;
|
||||||
|
void SetLayoutPrinterName(const QString &layoutPrinterName);
|
||||||
|
|
||||||
|
auto IsLayoutStale() const -> bool;
|
||||||
|
void SetLayoutStale(bool isLayoutStale);
|
||||||
|
|
||||||
|
auto TiledMargins() const -> QMarginsF;
|
||||||
|
void SetTiledMargins(const QMarginsF &tiledMargins);
|
||||||
|
|
||||||
|
auto TiledPDFOrientation() const -> PageOrientation;
|
||||||
|
void SetTiledPDFOrientation(const PageOrientation &tiledPDFOrientation);
|
||||||
|
|
||||||
|
auto TiledPDFPaperSize() const -> QSizeF;
|
||||||
|
void SetTiledPDFPaperSize(const QSizeF &tiledPDFPaperSize);
|
||||||
|
|
||||||
|
auto XScale() const -> qreal;
|
||||||
|
void SetXScale(const qreal &xscale);
|
||||||
|
|
||||||
|
auto YScale() const -> qreal;
|
||||||
|
void SetYScale(const qreal &yscale);
|
||||||
|
|
||||||
|
auto WatermarkPath() const -> QString;
|
||||||
|
void SetWatermarkPath(const QString &watermarkPath);
|
||||||
|
|
||||||
|
auto LayoutPapers() const -> QList<QGraphicsItem *>;
|
||||||
|
void SetLayoutPapers(const QList<QGraphicsItem *> &layoutPapers);
|
||||||
|
|
||||||
|
auto LayoutScenes() const -> QList<QGraphicsScene *>;
|
||||||
|
void SetLayoutScenes(const QList<QGraphicsScene *> &layoutScenes);
|
||||||
|
|
||||||
|
auto LayoutShadows() const -> QList<QGraphicsItem *>;
|
||||||
|
void SetLayoutShadows(const QList<QGraphicsItem *> &layoutShadows);
|
||||||
|
|
||||||
|
auto LayoutDetails() const -> QList<QList<QGraphicsItem *> >;
|
||||||
|
void SetLayoutDetails(const QList<QList<QGraphicsItem *> > &layoutDetails);
|
||||||
|
|
||||||
|
void PrintTiled();
|
||||||
|
void PrintOrigin();
|
||||||
|
|
||||||
|
void PrintPreviewTiled();
|
||||||
|
void PrintPreviewOrigin();
|
||||||
|
|
||||||
|
void PdfTiledFile(const QString &name);
|
||||||
|
|
||||||
|
void CleanLayout();
|
||||||
|
|
||||||
|
static auto ContinueIfLayoutStale(QWidget *parent) -> int;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void PrintPages (QPrinter *printer);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(VPrintLayout)
|
||||||
|
|
||||||
|
QString m_fileName{};
|
||||||
|
QSizeF m_layoutPaperSize{};
|
||||||
|
QMarginsF m_layoutMargins{};
|
||||||
|
QWidget *m_parentWidget{nullptr};
|
||||||
|
bool m_isLayoutPortrait{true};
|
||||||
|
bool m_ignorePrinterMargins{false};
|
||||||
|
bool m_isAutoCropLength{false};
|
||||||
|
bool m_isAutoCropWidth{false};
|
||||||
|
bool m_isUnitePages{false};
|
||||||
|
QString m_layoutPrinterName{};
|
||||||
|
bool m_isLayoutStale{true};
|
||||||
|
QMarginsF m_tiledMargins{};
|
||||||
|
PageOrientation m_tiledPDFOrientation{PageOrientation::Portrait};
|
||||||
|
QSizeF m_tiledPDFPaperSize{};
|
||||||
|
QString m_watermarkPath{};
|
||||||
|
|
||||||
|
|
||||||
|
QList<QGraphicsItem *> m_layoutPapers{};
|
||||||
|
QList<QGraphicsScene *> m_layoutScenes{};
|
||||||
|
QList<QGraphicsItem *> m_layoutShadows{};
|
||||||
|
QList<QList<QGraphicsItem *> > m_layoutDetails{};
|
||||||
|
|
||||||
|
bool m_isTiled{false};
|
||||||
|
qreal m_xscale{1};
|
||||||
|
qreal m_yscale{1};
|
||||||
|
|
||||||
|
void PrintLayout();
|
||||||
|
void PrintPreview();
|
||||||
|
|
||||||
|
void SetPrinterSettings(QPrinter *printer, PrintType printType, const QString &filePath = QString());
|
||||||
|
void SetPrinterPrinterMargins(QPrinter *printer);
|
||||||
|
void SetPrinterOutputFileName(QPrinter *printer, PrintType printType, const QString &filePath = QString());
|
||||||
|
void SetPrinterPageSize(QPrinter *printer);
|
||||||
|
|
||||||
|
QString DocName() const;
|
||||||
|
|
||||||
|
void PreparePaper(int index) const;
|
||||||
|
void RestorePaper(int index) const;
|
||||||
|
|
||||||
|
bool IsPagesUniform() const;
|
||||||
|
bool IsPagesFit(QSizeF printPaper) const;
|
||||||
|
|
||||||
|
auto WatermarkData() const -> VWatermarkData;
|
||||||
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::FileName() const -> QString
|
||||||
|
{
|
||||||
|
return m_fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetFileName(const QString &fileName)
|
||||||
|
{
|
||||||
|
m_fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::LayoutPaperSize() const -> QSizeF
|
||||||
|
{
|
||||||
|
return m_layoutPaperSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetLayoutPaperSize(const QSizeF &paperSize)
|
||||||
|
{
|
||||||
|
m_layoutPaperSize = paperSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::LayoutMargins() const -> QMarginsF
|
||||||
|
{
|
||||||
|
return m_layoutMargins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetLayoutMargins(const QMarginsF &layoutMargins)
|
||||||
|
{
|
||||||
|
m_layoutMargins = layoutMargins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::ParentWidget() const -> QWidget *
|
||||||
|
{
|
||||||
|
return m_parentWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetParentWidget(QWidget *parentWidget)
|
||||||
|
{
|
||||||
|
m_parentWidget = parentWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::IsLayoutPortrait() const -> bool
|
||||||
|
{
|
||||||
|
return m_isLayoutPortrait;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetLayoutPortrait(bool isLayoutPortrait)
|
||||||
|
{
|
||||||
|
m_isLayoutPortrait = isLayoutPortrait;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::IgnorePrinterMargins() const -> bool
|
||||||
|
{
|
||||||
|
return m_ignorePrinterMargins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetIgnorePrinterMargins(bool ignorePrinterFields)
|
||||||
|
{
|
||||||
|
m_ignorePrinterMargins = ignorePrinterFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::IsAutoCropLength() const -> bool
|
||||||
|
{
|
||||||
|
return m_isAutoCropLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetAutoCropLength(bool isAutoCropLength)
|
||||||
|
{
|
||||||
|
m_isAutoCropLength = isAutoCropLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline bool VPrintLayout::IsAutoCropWidth() const
|
||||||
|
{
|
||||||
|
return m_isAutoCropWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetAutoCropWidth(bool isAutoCropWidth)
|
||||||
|
{
|
||||||
|
m_isAutoCropWidth = isAutoCropWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::IsUnitePages() const -> bool
|
||||||
|
{
|
||||||
|
return m_isUnitePages;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetUnitePages(bool isUnitePages)
|
||||||
|
{
|
||||||
|
m_isUnitePages = isUnitePages;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::LayoutPrinterName() const -> QString
|
||||||
|
{
|
||||||
|
return m_layoutPrinterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetLayoutPrinterName(const QString &layoutPrinterName)
|
||||||
|
{
|
||||||
|
m_layoutPrinterName = layoutPrinterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::IsLayoutStale() const -> bool
|
||||||
|
{
|
||||||
|
return m_isLayoutStale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetLayoutStale(bool isLayoutStale)
|
||||||
|
{
|
||||||
|
m_isLayoutStale = isLayoutStale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::TiledMargins() const -> QMarginsF
|
||||||
|
{
|
||||||
|
return m_tiledMargins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetTiledMargins(const QMarginsF &tiledMargins)
|
||||||
|
{
|
||||||
|
m_tiledMargins = tiledMargins;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::TiledPDFOrientation() const -> PageOrientation
|
||||||
|
{
|
||||||
|
return m_tiledPDFOrientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetTiledPDFOrientation(const PageOrientation &tiledPDFOrientation)
|
||||||
|
{
|
||||||
|
m_tiledPDFOrientation = tiledPDFOrientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::TiledPDFPaperSize() const -> QSizeF
|
||||||
|
{
|
||||||
|
return m_tiledPDFPaperSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetTiledPDFPaperSize(const QSizeF &tiledPDFPaperSize)
|
||||||
|
{
|
||||||
|
m_tiledPDFPaperSize = tiledPDFPaperSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::LayoutPapers() const -> QList<QGraphicsItem *>
|
||||||
|
{
|
||||||
|
return m_layoutPapers;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetLayoutPapers(const QList<QGraphicsItem *> &layoutPapers)
|
||||||
|
{
|
||||||
|
m_layoutPapers = layoutPapers;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::LayoutScenes() const -> QList<QGraphicsScene *>
|
||||||
|
{
|
||||||
|
return m_layoutScenes;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetLayoutScenes(const QList<QGraphicsScene *> &layoutScenes)
|
||||||
|
{
|
||||||
|
m_layoutScenes = layoutScenes;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::LayoutShadows() const -> QList<QGraphicsItem *>
|
||||||
|
{
|
||||||
|
return m_layoutShadows;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetLayoutShadows(const QList<QGraphicsItem *> &layoutShadows)
|
||||||
|
{
|
||||||
|
m_layoutShadows = layoutShadows;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::LayoutDetails() const -> QList<QList<QGraphicsItem *> >
|
||||||
|
{
|
||||||
|
return m_layoutDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetLayoutDetails(const QList<QList<QGraphicsItem *> > &layoutDetails)
|
||||||
|
{
|
||||||
|
m_layoutDetails = layoutDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::YScale() const -> qreal
|
||||||
|
{
|
||||||
|
return m_yscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetYScale(const qreal &yscale)
|
||||||
|
{
|
||||||
|
m_yscale = yscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::XScale() const -> qreal
|
||||||
|
{
|
||||||
|
return m_xscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetXScale(const qreal &xscale)
|
||||||
|
{
|
||||||
|
m_xscale = xscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline auto VPrintLayout::WatermarkPath() const -> QString
|
||||||
|
{
|
||||||
|
return m_watermarkPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
inline void VPrintLayout::SetWatermarkPath(const QString &watermarkPath)
|
||||||
|
{
|
||||||
|
m_watermarkPath = watermarkPath;
|
||||||
|
}
|
||||||
|
#endif // VPRINTLAYOUT_H
|
|
@ -277,28 +277,6 @@ QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath)
|
||||||
return QFileInfo(QFileInfo(patternPath).absoluteDir(), relativeMPath).absoluteFilePath();
|
return QFileInfo(QFileInfo(patternPath).absoluteDir(), relativeMPath).absoluteFilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QSharedPointer<QPrinter> PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode)
|
|
||||||
{
|
|
||||||
QPrinterInfo tmpInfo = info;
|
|
||||||
if(tmpInfo.isNull() || tmpInfo.printerName().isEmpty())
|
|
||||||
{
|
|
||||||
const QStringList list = QPrinterInfo::availablePrinterNames();
|
|
||||||
if(list.isEmpty())
|
|
||||||
{
|
|
||||||
return QSharedPointer<QPrinter>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
tmpInfo = QPrinterInfo::printerInfo(list.first());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto printer = QSharedPointer<QPrinter>(new QPrinter(tmpInfo, mode));
|
|
||||||
printer->setResolution(static_cast<int>(PrintDPI));
|
|
||||||
return printer;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QMarginsF GetMinPrinterFields(const QSharedPointer<QPrinter> &printer)
|
QMarginsF GetMinPrinterFields(const QSharedPointer<QPrinter> &printer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -602,9 +602,6 @@ Q_REQUIRED_RESULT QString AbsoluteMPath(const QString &patternPath, const QStrin
|
||||||
|
|
||||||
QStringList SplitFilePaths(const QString &path);
|
QStringList SplitFilePaths(const QString &path);
|
||||||
|
|
||||||
Q_REQUIRED_RESULT QSharedPointer<QPrinter> PreparePrinter(const QPrinterInfo &info,
|
|
||||||
QPrinter::PrinterMode mode = QPrinter::ScreenResolution);
|
|
||||||
|
|
||||||
QMarginsF GetMinPrinterFields(const QSharedPointer<QPrinter> &printer);
|
QMarginsF GetMinPrinterFields(const QSharedPointer<QPrinter> &printer);
|
||||||
QMarginsF GetPrinterFields(const QSharedPointer<QPrinter> &printer);
|
QMarginsF GetPrinterFields(const QSharedPointer<QPrinter> &printer);
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ class VCommonSettings;
|
||||||
#if defined(qApp)
|
#if defined(qApp)
|
||||||
#undef qApp
|
#undef qApp
|
||||||
#endif
|
#endif
|
||||||
#define qApp (static_cast<VAbstractApplication*>(QCoreApplication::instance()))
|
#define qApp (qobject_cast<VAbstractApplication*>(QCoreApplication::instance()))
|
||||||
|
|
||||||
class VAbstractApplication : public QApplication
|
class VAbstractApplication : public QApplication
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ class QGraphicsScene;
|
||||||
#if defined(qApp)
|
#if defined(qApp)
|
||||||
#undef qApp
|
#undef qApp
|
||||||
#endif
|
#endif
|
||||||
#define qApp (static_cast<VAbstractValApplication*>(QCoreApplication::instance()))
|
#define qApp (qobject_cast<VAbstractValApplication*>(QCoreApplication::instance()))
|
||||||
|
|
||||||
class VAbstractValApplication : public VAbstractApplication
|
class VAbstractValApplication : public VAbstractApplication
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,6 +47,8 @@
|
||||||
#include "../vmisc/compatibility.h"
|
#include "../vmisc/compatibility.h"
|
||||||
#include "../vpatterndb/pmsystems.h"
|
#include "../vpatterndb/pmsystems.h"
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(QMarginsF)
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsIndividualMeasurements, (QLatin1String("paths/individual_measurements")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsIndividualMeasurements, (QLatin1String("paths/individual_measurements")))
|
||||||
|
@ -105,6 +107,9 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserDateFormats, (QLatin1St
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelTimeFormat, (QLatin1String("label/timeFormat")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelTimeFormat, (QLatin1String("label/timeFormat")))
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserTimeFormats, (QLatin1String("label/userTimeFormats")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserTimeFormats, (QLatin1String("label/userTimeFormats")))
|
||||||
|
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFMargins, (QLatin1String("tiledPDF/margins")))
|
||||||
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFOrientation, (QLatin1String("tiledPDF/orientation")))
|
||||||
|
|
||||||
// Reading settings file is very expensive, cache curve approximation to speed up getting value
|
// Reading settings file is very expensive, cache curve approximation to speed up getting value
|
||||||
qreal curveApproximationCached = -1;
|
qreal curveApproximationCached = -1;
|
||||||
Q_GLOBAL_STATIC(QString, localeCached)
|
Q_GLOBAL_STATIC(QString, localeCached)
|
||||||
|
@ -1216,3 +1221,43 @@ qreal VCommonSettings::WidthHairLine() const
|
||||||
{
|
{
|
||||||
return WidthMainLine()/3.0;
|
return WidthMainLine()/3.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetTiledPDFMargins returns the tiled pdf margins in the given unit. When the setting is
|
||||||
|
* called for the first time, the 4 default margins are 10mm.
|
||||||
|
* @param unit the unit in which are the value. Necessary because we save the values
|
||||||
|
* internaly as mm so there is conversion beeing made.
|
||||||
|
* @return tiled pdf margins
|
||||||
|
*/
|
||||||
|
auto VCommonSettings::GetTiledPDFMargins(const Unit &unit) const -> QMarginsF
|
||||||
|
{
|
||||||
|
// default value is 10mm. We save the margins in mm in the setting.
|
||||||
|
return UnitConvertor(ValueOrDef<QMarginsF>(*settingTiledPDFMargins, QMarginsF(10, 10, 10, 10)), Unit::Mm, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief SetTiledPDFMargins sets the setting tiled pdf margins to the given value.
|
||||||
|
* @param value the margins to save
|
||||||
|
* @param unit the unit in which are the value. Necessary because we save the values
|
||||||
|
* internaly as mm so there is conversion beeing made.
|
||||||
|
*/
|
||||||
|
void VCommonSettings::SetTiledPDFMargins(const QMarginsF &value, const Unit &unit)
|
||||||
|
{
|
||||||
|
setValue(*settingTiledPDFMargins, QVariant::fromValue(UnitConvertor(value, unit, Unit::Mm)));
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
auto VCommonSettings::GetTiledPDFOrientation() const -> PageOrientation
|
||||||
|
{
|
||||||
|
bool defaultValue = static_cast<bool>(PageOrientation::Portrait);
|
||||||
|
bool result = value(*settingTiledPDFOrientation, defaultValue).toBool();
|
||||||
|
return static_cast<PageOrientation>(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VCommonSettings::SetTiledPDFOrientation(PageOrientation value)
|
||||||
|
{
|
||||||
|
setValue(*settingTiledPDFOrientation, static_cast<bool> (value));
|
||||||
|
}
|
||||||
|
|
|
@ -38,6 +38,11 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#include "../vmisc/def.h"
|
||||||
|
#include "../vlayout/vlayoutdef.h"
|
||||||
|
|
||||||
|
class QMarginsF;
|
||||||
|
|
||||||
class VCommonSettings : public QSettings
|
class VCommonSettings : public QSettings
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -224,6 +229,18 @@ public:
|
||||||
void SetLineWidth(qreal width);
|
void SetLineWidth(qreal width);
|
||||||
qreal WidthMainLine() const;
|
qreal WidthMainLine() const;
|
||||||
qreal WidthHairLine() const;
|
qreal WidthHairLine() const;
|
||||||
|
|
||||||
|
// settings for the tiled PDFs
|
||||||
|
auto GetTiledPDFMargins(const Unit &unit) const -> QMarginsF;
|
||||||
|
void SetTiledPDFMargins(const QMarginsF &value, const Unit &unit);
|
||||||
|
|
||||||
|
auto GetTiledPDFOrientation() const -> PageOrientation;
|
||||||
|
void SetTiledPDFOrientation(PageOrientation value);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
template <class T>
|
||||||
|
T ValueOrDef(const QString &setting, const T &defValue) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(VCommonSettings)
|
Q_DISABLE_COPY(VCommonSettings)
|
||||||
};
|
};
|
||||||
|
@ -246,4 +263,28 @@ inline qreal VCommonSettings::MaximalLineWidth()
|
||||||
return 5.0; // mm
|
return 5.0; // mm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <class T>
|
||||||
|
inline T VCommonSettings::ValueOrDef(const QString &setting, const T &defValue) const
|
||||||
|
{
|
||||||
|
const QVariant val = value(setting, QVariant::fromValue(defValue));
|
||||||
|
return val.canConvert<T>() ? val.value<T>() : defValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
template <>
|
||||||
|
inline Cases VCommonSettings::ValueOrDef<Cases>(const QString &setting, const Cases &defValue) const
|
||||||
|
{
|
||||||
|
const QVariant val = value(setting, QVariant::fromValue(static_cast<int>(defValue)));
|
||||||
|
const int g = val.canConvert<int>() ? val.value<int>() : static_cast<int>(defValue);
|
||||||
|
if (g < static_cast<int>(Cases::CaseThreeGroup) || g >= static_cast<int>(Cases::UnknownCase))
|
||||||
|
{
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return static_cast<Cases>(g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // VCOMMONSETTINGS_H
|
#endif // VCOMMONSETTINGS_H
|
||||||
|
|
|
@ -104,10 +104,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTextAsPaths, (QLatin1String("lay
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingNestingTime, (QLatin1String("layout/time")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingNestingTime, (QLatin1String("layout/time")))
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingEfficiencyCoefficient, (QLatin1String("layout/efficiencyCoefficient")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingEfficiencyCoefficient, (QLatin1String("layout/efficiencyCoefficient")))
|
||||||
|
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFMargins, (QLatin1String("tiledPDF/margins")))
|
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFPaperHeight, (QLatin1String("tiledPDF/paperHeight")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFPaperHeight, (QLatin1String("tiledPDF/paperHeight")))
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFPaperWidth, (QLatin1String("tiledPDF/paperWidth")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFPaperWidth, (QLatin1String("tiledPDF/paperWidth")))
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFOrientation, (QLatin1String("tiledPDF/orientation")))
|
|
||||||
|
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingDuration, (QLatin1String("scrolling/duration")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingDuration, (QLatin1String("scrolling/duration")))
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingUpdateInterval, (QLatin1String("scrolling/updateInterval")))
|
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingUpdateInterval, (QLatin1String("scrolling/updateInterval")))
|
||||||
|
@ -148,30 +146,6 @@ VSettings::VSettings(const QString &fileName, QSettings::Format format, QObject
|
||||||
qRegisterMetaTypeStreamOperators<QMarginsF>("QMarginsF");
|
qRegisterMetaTypeStreamOperators<QMarginsF>("QMarginsF");
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <class T>
|
|
||||||
inline T VSettings::ValueOrDef(const QString &setting, const T &defValue) const
|
|
||||||
{
|
|
||||||
const QVariant val = value(setting, QVariant::fromValue(defValue));
|
|
||||||
return val.canConvert<T>() ? val.value<T>() : defValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
template <>
|
|
||||||
inline Cases VSettings::ValueOrDef<Cases>(const QString &setting, const Cases &defValue) const
|
|
||||||
{
|
|
||||||
const QVariant val = value(setting, QVariant::fromValue(static_cast<int>(defValue)));
|
|
||||||
const int g = val.canConvert<int>() ? val.value<int>() : static_cast<int>(defValue);
|
|
||||||
if (g < static_cast<int>(Cases::CaseThreeGroup) || g >= static_cast<int>(Cases::UnknownCase))
|
|
||||||
{
|
|
||||||
return defValue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return static_cast<Cases>(g);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VSettings::GetLabelLanguage() const
|
QString VSettings::GetLabelLanguage() const
|
||||||
{
|
{
|
||||||
|
@ -563,32 +537,6 @@ void VSettings::SetRememberPatternMaterials(bool value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// settings for the tiled PDFs
|
// settings for the tiled PDFs
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief GetTiledPDFMargins returns the tiled pdf margins in the given unit. When the setting is
|
|
||||||
* called for the first time, the 4 default margins are 10mm.
|
|
||||||
* @param unit the unit in which are the value. Necessary because we save the values
|
|
||||||
* internaly as mm so there is conversion beeing made.
|
|
||||||
* @return tiled pdf margins
|
|
||||||
*/
|
|
||||||
QMarginsF VSettings::GetTiledPDFMargins(const Unit &unit) const
|
|
||||||
{
|
|
||||||
// default value is 10mm. We save the margins in mm in the setting.
|
|
||||||
return UnitConvertor(ValueOrDef<QMarginsF>(*settingTiledPDFMargins, QMarginsF(10, 10, 10, 10)), Unit::Mm, unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief SetTiledPDFMargins sets the setting tiled pdf margins to the given value.
|
|
||||||
* @param value the margins to save
|
|
||||||
* @param unit the unit in which are the value. Necessary because we save the values
|
|
||||||
* internaly as mm so there is conversion beeing made.
|
|
||||||
*/
|
|
||||||
void VSettings::SetTiledPDFMargins(const QMarginsF &value, const Unit &unit)
|
|
||||||
{
|
|
||||||
setValue(*settingTiledPDFMargins, QVariant::fromValue(UnitConvertor(value, unit, Unit::Mm)));
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief GetTiledPDFPaperHeight returns the paper height of tiled pdf in the desired unit.
|
* @brief GetTiledPDFPaperHeight returns the paper height of tiled pdf in the desired unit.
|
||||||
|
@ -635,20 +583,6 @@ void VSettings::SetTiledPDFPaperWidth(qreal value, const Unit &unit)
|
||||||
setValue(*settingTiledPDFPaperWidth, UnitConvertor(value,unit, Unit::Mm));
|
setValue(*settingTiledPDFPaperWidth, UnitConvertor(value,unit, Unit::Mm));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
PageOrientation VSettings::GetTiledPDFOrientation() const
|
|
||||||
{
|
|
||||||
bool defaultValue = static_cast<bool>(PageOrientation::Portrait);
|
|
||||||
bool result = value(*settingTiledPDFOrientation, defaultValue).toBool();
|
|
||||||
return static_cast<PageOrientation>(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
void VSettings::SetTiledPDFOrientation(PageOrientation value)
|
|
||||||
{
|
|
||||||
setValue(*settingTiledPDFOrientation, static_cast<bool> (value));
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
int VSettings::GetScrollingDuration() const
|
int VSettings::GetScrollingDuration() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -141,18 +141,12 @@ public:
|
||||||
void SetRememberPatternMaterials(bool value);
|
void SetRememberPatternMaterials(bool value);
|
||||||
|
|
||||||
// settings for the tiled PDFs
|
// settings for the tiled PDFs
|
||||||
QMarginsF GetTiledPDFMargins(const Unit &unit) const;
|
|
||||||
void SetTiledPDFMargins(const QMarginsF &value, const Unit &unit);
|
|
||||||
|
|
||||||
qreal GetTiledPDFPaperHeight(const Unit &unit) const;
|
qreal GetTiledPDFPaperHeight(const Unit &unit) const;
|
||||||
void SetTiledPDFPaperHeight(qreal value, const Unit &unit);
|
void SetTiledPDFPaperHeight(qreal value, const Unit &unit);
|
||||||
|
|
||||||
qreal GetTiledPDFPaperWidth(const Unit &unit) const;
|
qreal GetTiledPDFPaperWidth(const Unit &unit) const;
|
||||||
void SetTiledPDFPaperWidth(qreal value, const Unit &unit);
|
void SetTiledPDFPaperWidth(qreal value, const Unit &unit);
|
||||||
|
|
||||||
PageOrientation GetTiledPDFOrientation() const;
|
|
||||||
void SetTiledPDFOrientation(PageOrientation value);
|
|
||||||
|
|
||||||
static const int defaultScrollingDuration;
|
static const int defaultScrollingDuration;
|
||||||
static const int scrollingDurationMin;
|
static const int scrollingDurationMin;
|
||||||
static const int scrollingDurationMax;
|
static const int scrollingDurationMax;
|
||||||
|
@ -214,9 +208,6 @@ private:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const;
|
T GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const;
|
||||||
|
|
||||||
template <class T>
|
|
||||||
T ValueOrDef(const QString &setting, const T &defValue) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VSETTINGS_H
|
#endif // VSETTINGS_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user