Resolved issue #657. Improve feature: Allow more paper formats for printing

tiled PDF.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-10-10 12:22:59 +03:00
parent 0fb0763191
commit 67b01c0337
20 changed files with 885 additions and 287 deletions

View File

@ -25,6 +25,7 @@
- New math parser function "r2cm". Round to up to 1 decimal. - New math parser function "r2cm". Round to up to 1 decimal.
- Two new shortcut sequences: Ctrl+PgDown and Ctrl+PgUp to switch to next and previous pattern piece. - Two new shortcut sequences: Ctrl+PgDown and Ctrl+PgUp to switch to next and previous pattern piece.
- [#765] New feature. Free curve mode. - [#765] New feature. Free curve mode.
- [#657] Improve feature: Allow more paper formats for printing tiled PDF
# Version 0.5.1 # Version 0.5.1
- [#683] Tool Seam allowance's dialog is off screen on small resolutions. - [#683] Tool Seam allowance's dialog is off screen on small resolutions.

View File

@ -92,7 +92,8 @@ void DialogLayoutProgress::Error(const LayoutErrors &state)
qCritical() << tr("Couldn't prepare data for creation layout"); qCritical() << tr("Couldn't prepare data for creation layout");
break; break;
case LayoutErrors::EmptyPaperError: case LayoutErrors::EmptyPaperError:
qCritical() << tr("Several workpieces left not arranged, but none of them match for paper"); qCritical() << tr("One or more pattern pieces are bigger than the paper format you selected. Please, "
"select a bigger paper format.");
break; break;
case LayoutErrors::ProcessStoped: case LayoutErrors::ProcessStoped:
default: default:

View File

@ -38,25 +38,12 @@
#include <QPushButton> #include <QPushButton>
#include <QPrinterInfo> #include <QPrinterInfo>
//must be the same order as PaperSizeTemplate constants
const DialogLayoutSettings::FormatsVector DialogLayoutSettings::pageFormatNames =
DialogLayoutSettings::FormatsVector () << QLatin1String("A0")
<< QLatin1String("A1")
<< QLatin1String("A2")
<< QLatin1String("A3")
<< QLatin1String("A4")
<< QApplication::translate("DialogLayoutSettings", "Letter")
<< QApplication::translate("DialogLayoutSettings", "Legal")
<< QApplication::translate("DialogLayoutSettings", "Roll 24in")
<< QApplication::translate("DialogLayoutSettings", "Roll 30in")
<< QApplication::translate("DialogLayoutSettings", "Roll 36in")
<< QApplication::translate("DialogLayoutSettings", "Roll 42in")
<< QApplication::translate("DialogLayoutSettings", "Roll 44in")
<< QApplication::translate("DialogLayoutSettings", "Custom");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent, bool disableSettings) DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent, bool disableSettings)
: QDialog(parent), disableSettings(disableSettings), ui(new Ui::DialogLayoutSettings), oldPaperUnit(Unit::Mm), : VAbstractLayoutDialog(parent),
disableSettings(disableSettings),
ui(new Ui::DialogLayoutSettings),
oldPaperUnit(Unit::Mm),
oldLayoutUnit(Unit::Mm), generator(generator), isInitialized(false) oldLayoutUnit(Unit::Mm), generator(generator), isInitialized(false)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -67,7 +54,7 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget
//even cleanse lists before adding //even cleanse lists before adding
InitPaperUnits(); InitPaperUnits();
InitLayoutUnits(); InitLayoutUnits();
InitTemplates(); InitTemplates(ui->comboBoxTemplates);
MinimumPaperSize(); MinimumPaperSize();
MinimumLayoutSize(); MinimumLayoutSize();
InitPrinter(); InitPrinter();
@ -107,7 +94,7 @@ DialogLayoutSettings::DialogLayoutSettings(VLayoutGenerator *generator, QWidget
connect(ui->checkBoxIgnoreFileds, &QCheckBox::stateChanged, this, &DialogLayoutSettings::IgnoreAllFields); connect(ui->checkBoxIgnoreFileds, &QCheckBox::stateChanged, this, &DialogLayoutSettings::IgnoreAllFields);
connect(ui->toolButtonPortrate, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); connect(ui->toolButtonPortrait, &QToolButton::toggled, this, &DialogLayoutSettings::Swap);
connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogLayoutSettings::Swap); connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogLayoutSettings::Swap);
connect(ui->comboBoxLayoutUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(ui->comboBoxLayoutUnit, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogLayoutSettings::ConvertLayoutSize); this, &DialogLayoutSettings::ConvertLayoutSize);
@ -368,10 +355,12 @@ void DialogLayoutSettings::FindTemplate()
const qreal height = ui->doubleSpinBoxPaperHeight->value(); const qreal height = ui->doubleSpinBoxPaperHeight->value();
QSizeF size(width, height); QSizeF size(width, height);
const Unit paperUnit = PaperUnit();
const int max = static_cast<int>(PaperSizeTemplate::Custom); const int max = static_cast<int>(PaperSizeTemplate::Custom);
for (int i=0; i < max; ++i) for (int i=0; i < max; ++i)
{ {
const QSizeF tmplSize = TemplateSize(static_cast<PaperSizeTemplate>(i)); const QSizeF tmplSize = GetTemplateSize(static_cast<PaperSizeTemplate>(i), paperUnit);
if (size == tmplSize) if (size == tmplSize)
{ {
ui->comboBoxTemplates->blockSignals(true); ui->comboBoxTemplates->blockSignals(true);
@ -522,9 +511,9 @@ void DialogLayoutSettings::PaperSizeChanged()
{ {
if (ui->doubleSpinBoxPaperHeight->value() > ui->doubleSpinBoxPaperWidth->value()) if (ui->doubleSpinBoxPaperHeight->value() > ui->doubleSpinBoxPaperWidth->value())
{ {
ui->toolButtonPortrate->blockSignals(true); ui->toolButtonPortrait->blockSignals(true);
ui->toolButtonPortrate->setChecked(true); ui->toolButtonPortrait->setChecked(true);
ui->toolButtonPortrate->blockSignals(false); ui->toolButtonPortrait->blockSignals(false);
} }
else else
{ {
@ -602,7 +591,7 @@ void DialogLayoutSettings::DialogAccepted()
{ {
QMessageBox::StandardButton answer; QMessageBox::StandardButton answer;
answer = QMessageBox::question(this, tr("Wrong fields."), answer = QMessageBox::question(this, tr("Wrong fields."),
tr("Fields go beyond printing. \n\nApply settings anyway?"), tr("Margins go beyond printing. \n\nApply settings anyway?"),
QMessageBox::Yes|QMessageBox::No, QMessageBox::No); QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
if (answer == QMessageBox::No) if (answer == QMessageBox::No)
{ {
@ -748,31 +737,6 @@ void DialogLayoutSettings::InitLayoutUnits()
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::InitTemplates()
{
const QIcon icoPaper("://icon/16x16/template.png");
const QIcon icoRoll("://icon/16x16/roll.png");
const QString pdi = QString("(%1ppi)").arg(PrintDPI);
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
foreach(const auto& v, pageFormatNames)
{
if (cntr <= static_cast<int>(PaperSizeTemplate::Legal))
{
ui->comboBoxTemplates->addItem(icoPaper, v+" "+pdi, QVariant(cntr++));
}
else if (cntr <= static_cast<int>(PaperSizeTemplate::Roll44in))
{
ui->comboBoxTemplates->addItem(icoRoll, v+" "+pdi, QVariant(cntr++));
}
else
{
ui->comboBoxTemplates->addItem(v+" "+pdi, QVariant(cntr++));
}
}
ui->comboBoxTemplates->setCurrentIndex(-1);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::InitPrinter() void DialogLayoutSettings::InitPrinter()
@ -825,13 +789,13 @@ QString DialogLayoutSettings::MakeHelpTemplateList()
QString out = "\n"; QString out = "\n";
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0); auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
for (int i = 0; i < pageFormatNames.size(); ++i) for (int i = 0; i < VAbstractLayoutDialog::pageFormatNames.size(); ++i)
{ {
if (cntr <= static_cast<int>(PaperSizeTemplate::Roll44in))// Don't include custom template if (cntr <= static_cast<int>(PaperSizeTemplate::Roll44in))// Don't include custom template
{ {
out += "\t* "+pageFormatNames.at(i)+" = "+ QString::number(cntr++); out += "\t* "+VAbstractLayoutDialog::pageFormatNames.at(i)+" = "+ QString::number(cntr++);
if (i < pageFormatNames.size() - 1) if (i < VAbstractLayoutDialog::pageFormatNames.size() - 1)
{ {
out += ",\n"; out += ",\n";
} }
@ -850,6 +814,8 @@ QSizeF DialogLayoutSettings::Template()
PaperSizeTemplate temp; PaperSizeTemplate temp;
temp = static_cast<PaperSizeTemplate>(ui->comboBoxTemplates->currentData().toInt()); temp = static_cast<PaperSizeTemplate>(ui->comboBoxTemplates->currentData().toInt());
const Unit paperUnit = PaperUnit();
switch (temp) switch (temp)
{ {
case PaperSizeTemplate::A0: case PaperSizeTemplate::A0:
@ -859,7 +825,7 @@ QSizeF DialogLayoutSettings::Template()
case PaperSizeTemplate::A4: case PaperSizeTemplate::A4:
case PaperSizeTemplate::Letter: case PaperSizeTemplate::Letter:
SetAdditionalOptions(false); SetAdditionalOptions(false);
return TemplateSize(temp); return GetTemplateSize(temp, paperUnit);
case PaperSizeTemplate::Legal: case PaperSizeTemplate::Legal:
case PaperSizeTemplate::Roll24in: case PaperSizeTemplate::Roll24in:
case PaperSizeTemplate::Roll30in: case PaperSizeTemplate::Roll30in:
@ -867,9 +833,9 @@ QSizeF DialogLayoutSettings::Template()
case PaperSizeTemplate::Roll42in: case PaperSizeTemplate::Roll42in:
case PaperSizeTemplate::Roll44in: case PaperSizeTemplate::Roll44in:
SetAdditionalOptions(true); SetAdditionalOptions(true);
return TemplateSize(temp); return GetTemplateSize(temp, paperUnit);
case PaperSizeTemplate::Custom: case PaperSizeTemplate::Custom:
return TemplateSize(temp); return GetTemplateSize(temp, paperUnit);
default: default:
break; break;
} }
@ -877,96 +843,24 @@ QSizeF DialogLayoutSettings::Template()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QSizeF DialogLayoutSettings::TemplateSize(const PaperSizeTemplate &tmpl) const QSizeF DialogLayoutSettings::GetTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const
{ {
const Unit paperUnit = PaperUnit();
qreal width = 0; qreal width = 0;
qreal height = 0; qreal height = 0;
switch (tmpl) switch (tmpl)
{ {
case PaperSizeTemplate::A0:
width = UnitConvertor(841, Unit::Mm, paperUnit);
height = UnitConvertor(1189, Unit::Mm, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::A1:
width = UnitConvertor(594, Unit::Mm, paperUnit);
height = UnitConvertor(841, Unit::Mm, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::A2:
width = UnitConvertor(420, Unit::Mm, paperUnit);
height = UnitConvertor(594, Unit::Mm, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::A3:
width = UnitConvertor(297, Unit::Mm, paperUnit);
height = UnitConvertor(420, Unit::Mm, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::A4:
width = UnitConvertor(210, Unit::Mm, paperUnit);
height = UnitConvertor(297, Unit::Mm, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Letter:
width = UnitConvertor(8.5, Unit::Inch, paperUnit);
height = UnitConvertor(11, Unit::Inch, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Legal:
width = UnitConvertor(8.5, Unit::Inch, paperUnit);
height = UnitConvertor(14, Unit::Inch, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Roll24in:
width = UnitConvertor(24, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Roll30in:
width = UnitConvertor(30, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Roll36in:
width = UnitConvertor(36, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Roll42in:
width = UnitConvertor(42, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Roll44in:
width = UnitConvertor(44, Unit::Inch, paperUnit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit);
return RoundTemplateSize(width, height);
case PaperSizeTemplate::Custom: case PaperSizeTemplate::Custom:
width = ui->doubleSpinBoxPaperWidth->value(); width = ui->doubleSpinBoxPaperWidth->value();
height = ui->doubleSpinBoxPaperHeight->value(); height = ui->doubleSpinBoxPaperHeight->value();
return RoundTemplateSize(width, height); return RoundTemplateSize(width, height, unit);
default: default:
break; return VAbstractLayoutDialog::GetTemplateSize(tmpl, unit);
} }
return QSizeF();
} }
//---------------------------------------------------------------------------------------------------------------------
QSizeF DialogLayoutSettings::RoundTemplateSize(qreal width, qreal height) const
{
qreal w = 0;
qreal h = 0;
switch (PaperUnit())
{
case Unit::Cm:
case Unit::Mm:
case Unit::Px:
w = qRound(width * 100.0) / 100.0;
h = qRound(height * 100.0) / 100.0;
return QSizeF(w, h);
case Unit::Inch:
w = qRound(width * 100000.0) / 100000.0;
h = qRound(height * 100000.0) / 100000.0;
return QSizeF(w, h);
default:
break;
}
return QSizeF(width, height);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QMarginsF DialogLayoutSettings::MinPrinterFields() const QMarginsF DialogLayoutSettings::MinPrinterFields() const

View File

@ -30,7 +30,7 @@
#define DIALOGLAYOUTSETTINGS_H #define DIALOGLAYOUTSETTINGS_H
#include <QCloseEvent> #include <QCloseEvent>
#include <QDialog> #include "vabstractlayoutdialog.h"
#include "../vlayout/vbank.h" #include "../vlayout/vbank.h"
#include "../ifc/ifcdef.h" #include "../ifc/ifcdef.h"
@ -48,23 +48,10 @@ namespace Ui
class VLayoutGenerator; class VLayoutGenerator;
class DialogLayoutSettings : public QDialog class DialogLayoutSettings : public VAbstractLayoutDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
enum class PaperSizeTemplate : char { A0 = 0,
A1,
A2,
A3,
A4,
Letter,
Legal,
Roll24in = 7, // Be carefull when change order roll type
Roll30in, // Used also for showing icon
Roll36in,
Roll42in,
Roll44in = 11,
Custom = 12};
explicit DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent = nullptr, bool disableSettings = false); explicit DialogLayoutSettings(VLayoutGenerator *generator, QWidget *parent = nullptr, bool disableSettings = false);
virtual ~DialogLayoutSettings(); virtual ~DialogLayoutSettings();
@ -125,6 +112,8 @@ public:
static QString MakeGroupsHelp(); static QString MakeGroupsHelp();
protected: protected:
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
QSizeF GetTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const;
public slots: public slots:
void DialogAccepted(); void DialogAccepted();
private slots: private slots:
@ -155,11 +144,9 @@ private:
void InitPaperUnits(); void InitPaperUnits();
void InitLayoutUnits(); void InitLayoutUnits();
void InitTemplates();
void InitPrinter(); void InitPrinter();
QSizeF Template(); QSizeF Template();
QSizeF TemplateSize(const PaperSizeTemplate &tmpl) const;
QSizeF RoundTemplateSize(qreal width, qreal height) const;
QMarginsF MinPrinterFields() const; QMarginsF MinPrinterFields() const;
QMarginsF GetDefPrinterFields() const; QMarginsF GetDefPrinterFields() const;

View File

@ -75,7 +75,7 @@
<item row="2" column="0"> <item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QToolButton" name="toolButtonPortrate"> <widget class="QToolButton" name="toolButtonPortrait">
<property name="text"> <property name="text">
<string notr="true">...</string> <string notr="true">...</string>
</property> </property>

View File

@ -20,7 +20,8 @@ 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 \
@ -40,7 +41,8 @@ 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 \

View File

@ -39,6 +39,7 @@
#include <QProcess> #include <QProcess>
#include <QtDebug> #include <QtDebug>
#include <QRegularExpression> #include <QRegularExpression>
#include <QtDebug>
const QString baseFilenameRegExp = QStringLiteral("^[\\p{L}\\p{Nd}\\-. _]+$"); const QString baseFilenameRegExp = QStringLiteral("^[\\p{L}\\p{Nd}\\-. _]+$");
@ -47,7 +48,7 @@ bool DialogSaveLayout::tested = false;
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
DialogSaveLayout::DialogSaveLayout(int count, Draw mode, const QString &fileName, QWidget *parent) DialogSaveLayout::DialogSaveLayout(int count, Draw mode, const QString &fileName, QWidget *parent)
: QDialog(parent), : VAbstractLayoutDialog(parent),
ui(new Ui::DialogSaveLAyout), ui(new Ui::DialogSaveLAyout),
count(count), count(count),
isInitialized(false), isInitialized(false),
@ -133,8 +134,44 @@ DialogSaveLayout::DialogSaveLayout(int count, Draw mode, const QString &fileName
connect(ui->lineEditPath, &QLineEdit::textChanged, this, &DialogSaveLayout::PathChanged); connect(ui->lineEditPath, &QLineEdit::textChanged, this, &DialogSaveLayout::PathChanged);
ui->lineEditPath->setText(qApp->ValentinaSettings()->GetPathLayout()); ui->lineEditPath->setText(qApp->ValentinaSettings()->GetPathLayout());
InitTemplates(ui->comboBoxTemplates);
ReadSettings();
// connect for the template drop down box of the tiled pds
connect(ui->comboBoxTemplates, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &DialogSaveLayout::WriteSettings);
// connects for the margins of the tiled pdf
connect(ui->doubleSpinBoxLeftField, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSaveLayout::WriteSettings);
connect(ui->doubleSpinBoxTopField, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSaveLayout::WriteSettings);
connect(ui->doubleSpinBoxRightField, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSaveLayout::WriteSettings);
connect(ui->doubleSpinBoxBottomField, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
this, &DialogSaveLayout::WriteSettings);
// connects for the orientation buttons for the tiled pdf
connect(ui->toolButtonPortrait, &QToolButton::toggled, this, &DialogSaveLayout::WriteSettings);
connect(ui->toolButtonLandscape, &QToolButton::toggled, this, &DialogSaveLayout::WriteSettings);
ShowExample();//Show example for current format. ShowExample();//Show example for current format.
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogSaveLayout::InitTemplates(QComboBox *comboBoxTemplates)
{
SCASSERT(comboBoxTemplates != nullptr)
VAbstractLayoutDialog::InitTemplates(comboBoxTemplates);
// remove the custom format,
comboBoxTemplates->removeItem(comboBoxTemplates->findData(static_cast<int>(PaperSizeTemplate::Custom)));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void DialogSaveLayout::SelectFormat(LayoutExportFormats format) void DialogSaveLayout::SelectFormat(LayoutExportFormats format)
@ -513,6 +550,10 @@ void DialogSaveLayout::ShowExample()
const LayoutExportFormats currentFormat = Format(); const LayoutExportFormats currentFormat = Format();
ui->labelExample->setText(tr("Example:") + FileName() + QLatin1String("1") + ExportFromatSuffix(currentFormat)); ui->labelExample->setText(tr("Example:") + FileName() + QLatin1String("1") + ExportFromatSuffix(currentFormat));
ui->checkBoxBinaryDXF->setEnabled(false);
ui->groupBoxPaperFormat->setEnabled(false);
ui->groupBoxMargins->setEnabled(false);
switch(currentFormat) switch(currentFormat)
{ {
case LayoutExportFormats::DXF_AC1006_Flat: case LayoutExportFormats::DXF_AC1006_Flat:
@ -544,15 +585,17 @@ void DialogSaveLayout::ShowExample()
case LayoutExportFormats::DXF_AC1027_ASTM: case LayoutExportFormats::DXF_AC1027_ASTM:
ui->checkBoxBinaryDXF->setEnabled(true); ui->checkBoxBinaryDXF->setEnabled(true);
break; break;
case LayoutExportFormats::PDFTiled:
ui->groupBoxPaperFormat->setEnabled(true);
ui->groupBoxMargins->setEnabled(true);
break;
case LayoutExportFormats::SVG: case LayoutExportFormats::SVG:
case LayoutExportFormats::PDF: case LayoutExportFormats::PDF:
case LayoutExportFormats::PDFTiled:
case LayoutExportFormats::PNG: case LayoutExportFormats::PNG:
case LayoutExportFormats::OBJ: case LayoutExportFormats::OBJ:
case LayoutExportFormats::PS: case LayoutExportFormats::PS:
case LayoutExportFormats::EPS: case LayoutExportFormats::EPS:
default: default:
ui->checkBoxBinaryDXF->setEnabled(false);
break; break;
} }
} }
@ -691,3 +734,87 @@ void DialogSaveLayout::RemoveFormatFromList(LayoutExportFormats format)
ui->comboBoxFormat->removeItem(index); ui->comboBoxFormat->removeItem(index);
} }
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ReadSettings reads the values of the variables needed for the save layout dialog, for instance
* the margins, teamplte and orientation of tiled pdf. Then sets the corresponding
* elements of the dialog to these values.
*/
void DialogSaveLayout::ReadSettings()
{
VSettings *settings = qApp->ValentinaSettings();
const Unit unit = qApp->patternUnit();
// read Margins top, right, bottom, left
const QMarginsF margins = settings->GetTiledPDFMargins(unit);
ui->doubleSpinBoxLeftField->setValue(margins.left());
ui->doubleSpinBoxTopField->setValue(margins.top());
ui->doubleSpinBoxRightField->setValue(margins.right());
ui->doubleSpinBoxBottomField->setValue(margins.bottom());
// read Template
const QSizeF size = QSizeF(settings->GetTiledPDFPaperWidth(Unit::Mm), settings->GetTiledPDFPaperHeight(Unit::Mm));
const int max = static_cast<int>(PaperSizeTemplate::Custom);
for (int i=0; i < max; ++i)
{
const QSizeF tmplSize = GetTemplateSize(static_cast<PaperSizeTemplate>(i), Unit::Mm);
if (size == tmplSize)
{
ui->comboBoxTemplates->setCurrentIndex(i);
break;
}
}
// read Orientation
if(settings->GetTiledPDFOrientation() == PageOrientation::Portrait)
{
ui->toolButtonPortrait->setChecked(true);
}
else
{
ui->toolButtonLandscape->setChecked(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief WriteSettings writes the values of some variables (like the margins, template and orientation of tiled pdf)
* of the save layout dialog into the settings.
*/
void DialogSaveLayout::WriteSettings() const
{
VSettings *settings = qApp->ValentinaSettings();
const Unit unit = qApp->patternUnit();
// write Margins top, right, bottom, left
QMarginsF margins = QMarginsF(
ui->doubleSpinBoxLeftField->value(),
ui->doubleSpinBoxTopField->value(),
ui->doubleSpinBoxRightField->value(),
ui->doubleSpinBoxBottomField->value()
);
settings->SetTiledPDFMargins(margins,unit);
// write Template
const PaperSizeTemplate temp = static_cast<PaperSizeTemplate>(ui->comboBoxTemplates->currentData().toInt());
const QSizeF size = GetTemplateSize(temp, Unit::Mm);
settings->SetTiledPDFPaperHeight(size.height(), Unit::Mm);
settings->SetTiledPDFPaperWidth(size.width(), Unit::Mm);
// write Orientation
if(ui->toolButtonPortrait->isChecked())
{
settings->SetTiledPDFOrientation(PageOrientation::Portrait);
}
else
{
settings->SetTiledPDFOrientation(PageOrientation::Landscape);
}
}

View File

@ -29,8 +29,8 @@
#ifndef DIALOGSAVELAYOUT_H #ifndef DIALOGSAVELAYOUT_H
#define DIALOGSAVELAYOUT_H #define DIALOGSAVELAYOUT_H
#include <QDialog>
#include "../vgeometry/vgeometrydef.h" #include "../vgeometry/vgeometrydef.h"
#include "vabstractlayoutdialog.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
# define PDFTOPS "pdftops.exe" # define PDFTOPS "pdftops.exe"
@ -82,7 +82,7 @@ enum class LayoutExportFormats : char
COUNT /*Use only for validation*/ COUNT /*Use only for validation*/
}; };
class DialogSaveLayout : public QDialog class DialogSaveLayout : public VAbstractLayoutDialog
{ {
Q_OBJECT Q_OBJECT
@ -113,6 +113,8 @@ public:
protected: protected:
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
void InitTemplates(QComboBox *comboBoxTemplates);
private slots: private slots:
void Save(); void Save();
void PathChanged(const QString &text); void PathChanged(const QString &text);
@ -131,6 +133,9 @@ private:
static QVector<std::pair<QString, LayoutExportFormats> > InitFormats(); static QVector<std::pair<QString, LayoutExportFormats> > InitFormats();
void RemoveFormatFromList(LayoutExportFormats format); void RemoveFormatFromList(LayoutExportFormats format);
void ReadSettings();
void WriteSettings() const;
}; };
#endif // DIALOGSAVELAYOUT_H #endif // DIALOGSAVELAYOUT_H

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>748</width> <width>601</width>
<height>206</height> <height>325</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -20,18 +20,6 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
@ -69,7 +57,7 @@
<string>Select path to destination folder</string> <string>Select path to destination folder</string>
</property> </property>
<property name="text"> <property name="text">
<string>Browse</string> <string>Browse...</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -92,13 +80,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QCheckBox" name="checkBoxBinaryDXF"> <widget class="QCheckBox" name="checkBoxBinaryDXF">
<property name="enabled"> <property name="enabled">
@ -109,14 +90,188 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="3" column="1">
<widget class="QCheckBox" name="checkBoxTextAsPaths">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Text as paths</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QGroupBox" name="groupBoxMargins">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Margins</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="labelRightField">
<property name="text">
<string>Right:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxRightField"/>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLeftField">
<property name="minimumSize">
<size>
<width>71</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelLeftField">
<property name="text">
<string>Left:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="labelTopField">
<property name="text">
<string>Top:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxTopField"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelBottomField">
<property name="text">
<string>Bottom:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxBottomField"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxPaperFormat">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Paper format</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout_4">
<item row="1" column="0">
<widget class="QLabel" name="labelTemplates">
<property name="text">
<string>Templates: </string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBoxTemplates"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Orientation: </string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QToolButton" name="toolButtonPortrait">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../libs/vmisc/share/resources/icon.qrc">
<normaloff>:/icon/16x16/portrait.png</normaloff>:/icon/16x16/portrait.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonLandscape">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../libs/vmisc/share/resources/icon.qrc">
<normaloff>:/icon/16x16/landscape.png</normaloff>:/icon/16x16/landscape.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>File name:</string> <string>File name:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QLineEdit" name="lineEditFileName"> <widget class="QLineEdit" name="lineEditFileName">
@ -152,16 +307,6 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="1">
<widget class="QCheckBox" name="checkBoxTextAsPaths">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Text as paths</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -176,6 +321,20 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>lineEditPath</tabstop>
<tabstop>pushButtonBrowse</tabstop>
<tabstop>checkBoxBinaryDXF</tabstop>
<tabstop>checkBoxTextAsPaths</tabstop>
<tabstop>doubleSpinBoxLeftField</tabstop>
<tabstop>doubleSpinBoxTopField</tabstop>
<tabstop>doubleSpinBoxRightField</tabstop>
<tabstop>doubleSpinBoxBottomField</tabstop>
<tabstop>comboBoxTemplates</tabstop>
<tabstop>toolButtonPortrait</tabstop>
<tabstop>toolButtonLandscape</tabstop>
<tabstop>lineEditFileName</tabstop>
</tabstops>
<resources> <resources>
<include location="../../../libs/vmisc/share/resources/icon.qrc"/> <include location="../../../libs/vmisc/share/resources/icon.qrc"/>
</resources> </resources>

View File

@ -0,0 +1,172 @@
/************************************************************************
**
** @file dialogsavelayout.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 9 10, 2017
**
** @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) 2013-2017 Valentina project
** <https://bitbucket.org/dismine/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 "vabstractlayoutdialog.h"
#include "../core/vapplication.h"
//must be the same order as PaperSizeTemplate constants
const VAbstractLayoutDialog::FormatsVector VAbstractLayoutDialog::pageFormatNames =
VAbstractLayoutDialog::FormatsVector () << QLatin1String("A0")
<< QLatin1String("A1")
<< QLatin1String("A2")
<< QLatin1String("A3")
<< QLatin1String("A4")
<< QApplication::translate("VAbstractLayoutDialog", "Letter")
<< QApplication::translate("VAbstractLayoutDialog", "Legal")
<< QApplication::translate("VAbstractLayoutDialog", "Roll 24in")
<< QApplication::translate("VAbstractLayoutDialog", "Roll 30in")
<< QApplication::translate("VAbstractLayoutDialog", "Roll 36in")
<< QApplication::translate("VAbstractLayoutDialog", "Roll 42in")
<< QApplication::translate("VAbstractLayoutDialog", "Roll 44in")
<< QApplication::translate("VAbstractLayoutDialog", "Custom");
//---------------------------------------------------------------------------------------------------------------------
VAbstractLayoutDialog::VAbstractLayoutDialog(QWidget *parent)
: QDialog(parent)
{
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractLayoutDialog::InitTemplates(QComboBox *comboBoxTemplates)
{
SCASSERT(comboBoxTemplates != nullptr)
const QIcon icoPaper("://icon/16x16/template.png");
const QIcon icoRoll("://icon/16x16/roll.png");
const QString pdi = QString("(%1ppi)").arg(PrintDPI);
auto cntr = static_cast<VIndexType>(PaperSizeTemplate::A0);
foreach(const auto& v, pageFormatNames)
{
if (cntr <= static_cast<int>(PaperSizeTemplate::Legal))
{
comboBoxTemplates->addItem(icoPaper, v+" "+pdi, QVariant(cntr++));
}
else if (cntr <= static_cast<int>(PaperSizeTemplate::Roll44in))
{
comboBoxTemplates->addItem(icoRoll, v+" "+pdi, QVariant(cntr++));
}
else
{
comboBoxTemplates->addItem(v+" "+pdi, QVariant(cntr++));
}
}
comboBoxTemplates->setCurrentIndex(-1);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogLayoutSettings::TemplateSize
* @param tmpl
* @param unit
* @return
*/
QSizeF VAbstractLayoutDialog::GetTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const
{
qreal width = 0;
qreal height = 0;
switch (tmpl)
{
case PaperSizeTemplate::A0:
width = UnitConvertor(841, Unit::Mm, unit);
height = UnitConvertor(1189, Unit::Mm, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::A1:
width = UnitConvertor(594, Unit::Mm, unit);
height = UnitConvertor(841, Unit::Mm, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::A2:
width = UnitConvertor(420, Unit::Mm, unit);
height = UnitConvertor(594, Unit::Mm, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::A3:
width = UnitConvertor(297, Unit::Mm, unit);
height = UnitConvertor(420, Unit::Mm, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::A4:
width = UnitConvertor(210, Unit::Mm, unit);
height = UnitConvertor(297, Unit::Mm, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::Letter:
width = UnitConvertor(8.5, Unit::Inch, unit);
height = UnitConvertor(11, Unit::Inch, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::Legal:
width = UnitConvertor(8.5, Unit::Inch, unit);
height = UnitConvertor(14, Unit::Inch, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::Roll24in:
width = UnitConvertor(24, Unit::Inch, unit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::Roll30in:
width = UnitConvertor(30, Unit::Inch, unit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::Roll36in:
width = UnitConvertor(36, Unit::Inch, unit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::Roll42in:
width = UnitConvertor(42, Unit::Inch, unit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit);
return RoundTemplateSize(width, height, unit);
case PaperSizeTemplate::Roll44in:
width = UnitConvertor(44, Unit::Inch, unit);
height = UnitConvertor(QIMAGE_MAX, Unit::Px, unit);
return RoundTemplateSize(width, height, unit);
default:
break;
}
return QSizeF();
}
//---------------------------------------------------------------------------------------------------------------------
QSizeF VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit unit) const
{
qreal w = 0;
qreal h = 0;
switch (unit)
{
case Unit::Cm:
case Unit::Mm:
case Unit::Px:
w = qRound(width * 100.0) / 100.0;
h = qRound(height * 100.0) / 100.0;
return QSizeF(w, h);
case Unit::Inch:
w = qRound(width * 100000.0) / 100000.0;
h = qRound(height * 100000.0) / 100000.0;
return QSizeF(w, h);
default:
break;
}
return QSizeF(width, height);
}

View File

@ -0,0 +1,69 @@
/************************************************************************
**
** @file dialogsavelayout.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 9 10, 2017
**
** @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) 2013-2017 Valentina project
** <https://bitbucket.org/dismine/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 VABSTRACTLAYOUTDIALOG_H
#define VABSTRACTLAYOUTDIALOG_H
#include "../ifc/ifcdef.h"
#include <QComboBox>
#include <QDialog>
class VAbstractLayoutDialog : public QDialog
{
public:
enum class PaperSizeTemplate : char { A0 = 0,
A1,
A2,
A3,
A4,
Letter,
Legal,
Roll24in = 7, // Be carefull when change order roll type
Roll30in, // Used also for showing icon
Roll36in,
Roll42in,
Roll44in = 11,
Custom = 12};
explicit VAbstractLayoutDialog(QWidget *parent = nullptr);
protected:
typedef QStringList FormatsVector;
const static FormatsVector pageFormatNames;
typedef int VIndexType;
QSizeF GetTemplateSize(const PaperSizeTemplate &tmpl, const Unit &unit) const;
QSizeF RoundTemplateSize(qreal width, qreal height, Unit unit) const;
void InitTemplates(QComboBox *comboBoxTemplates);
private:
Q_DISABLE_COPY(VAbstractLayoutDialog)
};
#endif // VABSTRACTDIALOG_H

View File

@ -217,7 +217,8 @@ void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state)
qCritical() << tr("Couldn't prepare data for creation layout"); qCritical() << tr("Couldn't prepare data for creation layout");
break; break;
case LayoutErrors::EmptyPaperError: case LayoutErrors::EmptyPaperError:
qCritical() << tr("Several workpieces left not arranged, but none of them match for paper"); qCritical() << tr("One or more pattern pieces are bigger than the paper format you selected. Please, "
"select a bigger paper format.");
break; break;
case LayoutErrors::ProcessStoped: case LayoutErrors::ProcessStoped:
default: default:
@ -533,6 +534,15 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer)
if (isTiled) if (isTiled)
{ {
VSettings *settings = qApp->ValentinaSettings();
// when isTiled, the landscape tiles have to be rotated, because the pages
// stay portrait in the pdf
if(settings->GetTiledPDFOrientation() == PageOrientation::Landscape)
{
painter.rotate(-90);
painter.translate(-ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm), 0);
}
poster = QSharedPointer<QVector<PosterData>>(new QVector<PosterData>()); poster = QSharedPointer<QVector<PosterData>>(new QVector<PosterData>());
posterazor = QSharedPointer<VPoster>(new VPoster(printer)); posterazor = QSharedPointer<VPoster>(new VPoster(printer));
@ -541,7 +551,7 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer)
auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i)); auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (paper) if (paper)
{ {
*poster += posterazor->Calc(paper->rect().toRect(), i); *poster += posterazor->Calc(paper->rect().toRect(), i, settings->GetTiledPDFOrientation());
} }
} }
@ -933,7 +943,6 @@ void MainWindowsNoGUI::PdfTiledFile(const QString &name)
} }
QPrinter printer; QPrinter printer;
SetPrinterSettings(&printer, PrintType::PrintPDF); SetPrinterSettings(&printer, PrintType::PrintPDF);
printer.setPageSize(QPrinter::A4);// Want to be sure that page size is correct.
// Call IsPagesFit after setting a printer settings and check if pages is not bigger than printer's paper size // Call IsPagesFit after setting a printer settings and check if pages is not bigger than printer's paper size
if (not isTiled && not IsPagesFit(printer.paperRect().size())) if (not isTiled && not IsPagesFit(printer.paperRect().size()))
@ -1238,10 +1247,11 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr
{ {
SCASSERT(printer != nullptr) SCASSERT(printer != nullptr)
printer->setCreator(QGuiApplication::applicationDisplayName()+" "+QCoreApplication::applicationVersion()); printer->setCreator(QGuiApplication::applicationDisplayName()+" "+QCoreApplication::applicationVersion());
printer->setOrientation(QPrinter::Portrait);
if (not isTiled) if (not isTiled)
{ {
printer->setOrientation(QPrinter::Portrait);
QSizeF size = QSizeF(FromPixel(paperSize.width(), Unit::Mm), FromPixel(paperSize.height(), Unit::Mm)); QSizeF size = QSizeF(FromPixel(paperSize.width(), Unit::Mm), FromPixel(paperSize.height(), Unit::Mm));
if (isAutoCrop || isUnitePages) if (isAutoCrop || isUnitePages)
{ {
@ -1253,7 +1263,7 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr
} }
} }
const QPrinter::PageSize pSZ = FindTemplate(size); const QPrinter::PageSize pSZ = FindQPrinterPageSize(size);
if (pSZ == QPrinter::Custom) if (pSZ == QPrinter::Custom)
{ {
printer->setPaperSize (size, QPrinter::Millimeter ); printer->setPaperSize (size, QPrinter::Millimeter );
@ -1265,15 +1275,50 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr
} }
else else
{ {
printer->setPaperSize(QPrinter::A4); VSettings *settings = qApp->ValentinaSettings();
if(settings->GetTiledPDFOrientation() == PageOrientation::Landscape)
{
printer->setOrientation(QPrinter::Landscape);
}
else
{
printer->setOrientation(QPrinter::Portrait);
}
} }
printer->setFullPage(ignorePrinterFields); printer->setFullPage(ignorePrinterFields);
const qreal left = FromPixel(margins.left(), Unit::Mm); qreal left, top, right, bottom;
const qreal top = FromPixel(margins.top(), Unit::Mm);
const qreal right = FromPixel(margins.right(), Unit::Mm); if (not isTiled)
const qreal bottom = FromPixel(margins.bottom(), Unit::Mm); {
QMarginsF pageMargin = QMarginsF(UnitConvertor(margins, Unit::Px, Unit::Mm));
left = pageMargin.left();
top = pageMargin.top();
right = pageMargin.right();
bottom = pageMargin.bottom();
}
else
{
VSettings *settings = qApp->ValentinaSettings();
QMarginsF pageMargin = QMarginsF(settings->GetTiledPDFMargins(Unit::Mm));
if(settings->GetTiledPDFOrientation() == PageOrientation::Landscape)
{
// because when painting we have a -90rotation in landscape modus,
// see function PrintPages.
left = pageMargin.bottom();
top = pageMargin.left();
right = pageMargin.top();
bottom = pageMargin.right();
}
else
{
left = pageMargin.left();
top = pageMargin.top();
right = pageMargin.right();
bottom = pageMargin.bottom();
}
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
const bool success = printer->setPageMargins(QMarginsF(left, top, right, bottom), QPageLayout::Millimeter); const bool success = printer->setPageMargins(QMarginsF(left, top, right, bottom), QPageLayout::Millimeter);
@ -1353,39 +1398,39 @@ bool MainWindowsNoGUI::IsLayoutGrayscale() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPrinter::PaperSize MainWindowsNoGUI::FindTemplate(const QSizeF &size) const QPrinter::PaperSize MainWindowsNoGUI::FindQPrinterPageSize(const QSizeF &size) const
{ {
if (size == QSizeF(841, 1189)) if (size == QSizeF(841, 1189) || size == QSizeF(1189, 841))
{ {
return QPrinter::A0; return QPrinter::A0;
} }
if (size == QSizeF(594, 841)) if (size == QSizeF(594, 841) || size == QSizeF(841, 594))
{ {
return QPrinter::A1; return QPrinter::A1;
} }
if (size == QSizeF(420, 594)) if (size == QSizeF(420, 594) || size == QSizeF(594, 420))
{ {
return QPrinter::A2; return QPrinter::A2;
} }
if (size == QSizeF(297, 420)) if (size == QSizeF(297, 420) || size == QSizeF(420, 297))
{ {
return QPrinter::A3; return QPrinter::A3;
} }
if (size == QSizeF(210, 297)) if (size == QSizeF(210, 297) || size == QSizeF(297, 210))
{ {
return QPrinter::A4; return QPrinter::A4;
} }
if (size == QSizeF(215.9, 355.6)) if (size == QSizeF(215.9, 355.6) || size == QSizeF(355.6, 215.9))
{ {
return QPrinter::Legal; return QPrinter::Legal;
} }
if (size == QSizeF(215.9, 279.4)) if (size == QSizeF(215.9, 279.4) || size == QSizeF(279.4, 215.9))
{ {
return QPrinter::Letter; return QPrinter::Letter;
} }

View File

@ -151,7 +151,7 @@ private:
void SetPrinterSettings(QPrinter *printer, const PrintType &printType); void SetPrinterSettings(QPrinter *printer, const PrintType &printType);
bool IsLayoutGrayscale() const; bool IsLayoutGrayscale() const;
QPrinter::PaperSize FindTemplate(const QSizeF &size) const; QPrinter::PaperSize FindQPrinterPageSize(const QSizeF &size) const;
bool isPagesUniform() const; bool isPagesUniform() const;
bool IsPagesFit(const QSizeF &printPaper) const; bool IsPagesFit(const QSizeF &printPaper) const;

View File

@ -38,6 +38,7 @@
#include <QString> #include <QString>
#include <QVector> #include <QVector>
#include <Qt> #include <Qt>
#include <QDebug>
#include "../vmisc/vmath.h" #include "../vmisc/vmath.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
@ -49,7 +50,7 @@ VPoster::VPoster(const QPrinter *printer)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<PosterData> VPoster::Calc(const QRect &imageRect, int page) const QVector<PosterData> VPoster::Calc(const QRect &imageRect, int page, PageOrientation orientation) const
{ {
QVector<PosterData> poster; QVector<PosterData> poster;
@ -58,14 +59,14 @@ QVector<PosterData> VPoster::Calc(const QRect &imageRect, int page) const
return poster; return poster;
} }
const int rows = CountRows(imageRect.height()); const int rows = CountRows(imageRect.height(), orientation);
const int columns = CountColumns(imageRect.width()); const int columns = CountColumns(imageRect.width(), orientation);
for (int i=0; i < rows; i++) for (int i=0; i < rows; i++)
{ {
for (int j=0; j< columns; j++) for (int j=0; j< columns; j++)
{ {
PosterData data = Cut(i, j, imageRect); PosterData data = Cut(i, j, imageRect, orientation);
data.index = static_cast<quint32>(page); data.index = static_cast<quint32>(page);
data.rows = static_cast<quint32>(rows); data.rows = static_cast<quint32>(rows);
data.columns = static_cast<quint32>(columns); data.columns = static_cast<quint32>(columns);
@ -165,89 +166,61 @@ QVector<QGraphicsItem *> VPoster::Borders(QGraphicsItem *parent, const PosterDat
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VPoster::CountRows(int height) const int VPoster::CountRows(int height, PageOrientation orientation) const
{ {
const qreal imgLength = height; const qreal imgLength = height;
const qreal pageLength = PageRect().height(); qreal pageLength = 0;
// Example if(orientation == PageOrientation::Landscape)
// ― ― {
// * * pageLength = PageRect().width();
// * * }
// * * else
// * * ― {
// ― ― * pageLength = PageRect().height();
// * * }
// * *
// * * ―
// * ― *
// — *
// * *
// * * ―
// * ― *
// * *
// — *
// * * ―
// * ― * <-(2)
// * + *
// * + *
// — + * ― <-(4)
// ^ ^ ― *
//(3) (1) *
// *
// *
// ―
const int pCount = qCeil(imgLength/pageLength);// Pages count without allowance (or allowance = 0) (3) return qCeil(imgLength/(pageLength - static_cast<int>(allowance)));
// Calculate how many pages will be after using allowance.
// We know start pages count. This number not enought because
// each n-1 pages add (n-1)*allowance length to page (1).
const qreal addionalLength = (pCount-1)*static_cast<int>(allowance); //-V636
// Calculate additional length form pages that will cover this length (2).
// In the end add page length (3).
// Bottom page have mandatory border (4)
return qCeil((addionalLength +
qCeil(addionalLength/pageLength)*static_cast<int>(allowance) + static_cast<int>(allowance) +
imgLength)/pageLength);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VPoster::CountColumns(int width) const int VPoster::CountColumns(int width, PageOrientation orientation) const
{ {
const qreal imgLength = width; const qreal imgLength = width;
const qreal pageLength = PageRect().width(); qreal pageLength = 0;
// Example if(orientation == PageOrientation::Landscape)
// |----|----|----|----| <- (3) {
// |----|+++++++++++++++ pageLength = PageRect().height();
// |----|+++++++++++ }
// |----|+++++++ else
// |----|+++ <- (1) {
// |----| pageLength = PageRect().width();
// ^ }
// (2)
const int pCount = qCeil(imgLength/pageLength);// Pages count without allowance (or allowance = 0) (3)
// Calculate how many pages will be after using allowance. return qCeil(imgLength/(pageLength-static_cast<int>(allowance)));
// We know start pages count. This number not enought because
// each n-1 pages add (n-1)*allowance length to page (1).
const qreal addionalLength = (pCount-1)*static_cast<int>(allowance); //-V636
// Calculate additional length form pages that will cover this length (2).
// In the end add page length (3).
return qCeil((addionalLength + qCeil(addionalLength/pageLength)*static_cast<int>(allowance) +
imgLength)/pageLength);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
PosterData VPoster::Cut(int i, int j, const QRect &imageRect) const PosterData VPoster::Cut(int i, int j, const QRect &imageRect, PageOrientation orientation) const
{ {
Q_UNUSED(imageRect) Q_UNUSED(imageRect)
const int x = j*PageRect().width() - j*static_cast<int>(allowance); int pageLengthX, pageLengthY;
const int y = i*PageRect().height() - i*static_cast<int>(allowance);
if(orientation == PageOrientation::Landscape)
{
pageLengthX = PageRect().height();
pageLengthY = PageRect().width();
}
else
{
pageLengthX = PageRect().width();
pageLengthY = PageRect().height();
}
const int x = j*pageLengthX - j*static_cast<int>(allowance);
const int y = i*pageLengthY - i*static_cast<int>(allowance);
SCASSERT(x <= imageRect.width()) SCASSERT(x <= imageRect.width())
SCASSERT(y <= imageRect.height()) SCASSERT(y <= imageRect.height())
@ -255,7 +228,7 @@ PosterData VPoster::Cut(int i, int j, const QRect &imageRect) const
PosterData data; PosterData data;
data.row = static_cast<quint32>(i); data.row = static_cast<quint32>(i);
data.column = static_cast<quint32>(j); data.column = static_cast<quint32>(j);
data.rect = QRect(x, y, PageRect().width(), PageRect().height()); data.rect = QRect(x, y, pageLengthX, pageLengthY);
return data; return data;
} }

View File

@ -33,6 +33,8 @@
#include <QRect> #include <QRect>
#include <QtGlobal> #include <QtGlobal>
#include "../vmisc/def.h"
class QGraphicsItem; class QGraphicsItem;
class QPrinter; class QPrinter;
template <class T> class QVector; template <class T> class QVector;
@ -62,17 +64,21 @@ class VPoster
public: public:
explicit VPoster(const QPrinter *printer); explicit VPoster(const QPrinter *printer);
QVector<PosterData> Calc(const QRect &imageRect, int page) const; QVector<PosterData> Calc(const QRect &imageRect, int page, PageOrientation orientation) const;
QVector<QGraphicsItem *> Borders(QGraphicsItem *parent, const PosterData &img, int sheets) const; QVector<QGraphicsItem *> Borders(QGraphicsItem *parent, const PosterData &img, int sheets) const;
private: private:
const QPrinter *printer; const QPrinter *printer;
/**
* @brief allowance is the width of the strip that holds the tiled
* grid information and that is used for the gluing.
*/
quint32 allowance; quint32 allowance;
int CountRows(int height) const; int CountRows(int height, PageOrientation orientation) const;
int CountColumns(int width) const; int CountColumns(int width, PageOrientation orientation) const;
PosterData Cut(int i, int j, const QRect &imageRect) const; PosterData Cut(int i, int j, const QRect &imageRect, PageOrientation orientation) const;
QRect PageRect() const; QRect PageRect() const;

View File

@ -342,6 +342,27 @@ qreal UnitConvertor(qreal value, const Unit &from, const Unit &to)
return 0; return 0;
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief UnitConvertor Converts the values of the given margin from given unit to the new unit.
* returns a new instand of QMarginsF.
*
* @param margin
* @param from
* @param to
* @return
*/
QMarginsF UnitConvertor(const QMarginsF &margins, const Unit &from, const Unit &to)
{
const qreal left = UnitConvertor(margins.left(), from, to);
const qreal top = UnitConvertor(margins.top(), from, to);
const qreal right = UnitConvertor(margins.right(), from, to);
const qreal bottom = UnitConvertor(margins.bottom(), from, to);
return QMarginsF(left, top, right, bottom);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList SupportedLocales() QStringList SupportedLocales()
{ {

View File

@ -62,6 +62,7 @@ enum class Unit : char { Mm = 0, Cm, Inch, Px, LAST_UNIT_DO_NOT_USE};
enum class Source : char { FromGui, FromFile, FromTool }; enum class Source : char { FromGui, FromFile, FromTool };
enum class NodeUsage : bool {NotInUse = false, InUse = true}; enum class NodeUsage : bool {NotInUse = false, InUse = true};
enum class SelectionType : bool {ByMousePress, ByMouseRelease}; enum class SelectionType : bool {ByMousePress, ByMouseRelease};
enum class PageOrientation : bool {Portrait = true, Landscape = false};
enum class PieceNodeAngle : unsigned char enum class PieceNodeAngle : unsigned char
{ {
@ -416,6 +417,7 @@ Q_REQUIRED_RESULT double ToPixel(double val, const Unit &unit);
Q_REQUIRED_RESULT double FromPixel(double pix, const Unit &unit); Q_REQUIRED_RESULT double FromPixel(double pix, const Unit &unit);
Q_REQUIRED_RESULT qreal UnitConvertor(qreal value, const Unit &from, const Unit &to); Q_REQUIRED_RESULT qreal UnitConvertor(qreal value, const Unit &from, const Unit &to);
Q_REQUIRED_RESULT QMarginsF UnitConvertor(const QMarginsF &margins, const Unit &from, const Unit &to);
void InitLanguages(QComboBox *combobox); void InitLanguages(QComboBox *combobox);
Q_REQUIRED_RESULT QStringList SupportedLocales(); Q_REQUIRED_RESULT QStringList SupportedLocales();

View File

@ -38,6 +38,7 @@
#include <QStringDataPtr> #include <QStringDataPtr>
#include <QVariant> #include <QVariant>
#include <QPrinterInfo> #include <QPrinterInfo>
#include <QtDebug>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/vmath.h" #include "../vmisc/vmath.h"
@ -70,6 +71,11 @@ const QString settingIgnoreFields = QStringLiteral("layout/ignoreField
const QString settingStripOptimization = QStringLiteral("layout/stripOptimization"); const QString settingStripOptimization = QStringLiteral("layout/stripOptimization");
const QString settingMultiplier = QStringLiteral("layout/multiplier"); const QString settingMultiplier = QStringLiteral("layout/multiplier");
const QString settingTextAsPaths = QStringLiteral("layout/textAsPaths"); const QString settingTextAsPaths = QStringLiteral("layout/textAsPaths");
const QString settingTiledPDFMargins = QStringLiteral("tiledPDF/margins");
const QString settingTiledPDFPaperHeight = QStringLiteral("tiledPDF/paperHeight");
const QString settingTiledPDFPaperWidth = QStringLiteral("tiledPDF/paperWidth");
const QString settingTiledPDFOrientation = QStringLiteral("tiledPDF/orientation");
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -500,3 +506,117 @@ void VSettings::SetRememberPatternMaterials(bool value)
{ {
setValue(settingPatternRememberMaterials, value); setValue(settingPatternRememberMaterials, value);
} }
// 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
* @return
*/
QMarginsF VSettings::GetTiledPDFMargins(const Unit &unit) const
{
// default value is 10mm. We save the margins in mm in the setting.
const QMarginsF def = QMarginsF(10, 10, 10, 10);
const QVariant val = value(settingTiledPDFMargins, QVariant::fromValue(def));
if (val.canConvert<QMarginsF>())
{
return UnitConvertor(val.value<QMarginsF>(), Unit::Mm, unit);
}
return UnitConvertor(def, 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.
* @param unit the unit to return the value to (internally it's saved as mm)
* @return
*/
qreal VSettings::GetTiledPDFPaperHeight(const Unit &unit) const
{
const qreal def = 297 /*A4*/;
bool ok = false;
const qreal height = value(settingTiledPDFPaperHeight, def).toDouble(&ok);
if (ok)
{
return UnitConvertor(height, Unit::Mm, unit);
}
else
{
return UnitConvertor(def, Unit::Mm, unit);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetTiledPDFPaperHeight sets the tiled pdf paper height
* @param value in Mm
* @param unit unit of the given value
*/
void VSettings::SetTiledPDFPaperHeight(qreal value, const Unit &unit)
{
setValue(settingTiledPDFPaperHeight, UnitConvertor(value, unit, Unit::Mm));
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetTiledPDFPaperWidth returns the paper height of tiled pdf in the desired unit.
* @param unit the unit to return the value to (internally it's saved as mm)
* @return
*/
qreal VSettings::GetTiledPDFPaperWidth(const Unit &unit) const
{
const qreal def = 210 /*A4*/;
bool ok = false;
const qreal width = value(settingTiledPDFPaperWidth, def).toDouble(&ok);
if (ok)
{
return UnitConvertor(width, Unit::Mm, unit);
}
else
{
return UnitConvertor(def, Unit::Mm, unit);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetTiledPDFPaperWidth sets the tiled pdf paper width
* @param unit unit of the given value
* @param value in Mm
*/
void VSettings::SetTiledPDFPaperWidth(qreal value, const Unit &unit)
{
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));
}

View File

@ -35,6 +35,7 @@
#include <QString> #include <QString>
#include <QtGlobal> #include <QtGlobal>
#include "../vmisc/def.h"
#include "../vlayout/vbank.h" #include "../vlayout/vbank.h"
#include "vcommonsettings.h" #include "vcommonsettings.h"
@ -131,6 +132,19 @@ public:
bool IsRememberPatternMaterials() const; bool IsRememberPatternMaterials() const;
void SetRememberPatternMaterials(bool value); void SetRememberPatternMaterials(bool value);
// 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;
void SetTiledPDFPaperHeight(qreal value, const Unit &unit);
qreal GetTiledPDFPaperWidth(const Unit &unit) const;
void SetTiledPDFPaperWidth(qreal value, const Unit &unit);
PageOrientation GetTiledPDFOrientation() const;
void SetTiledPDFOrientation(PageOrientation value);
private: private:
Q_DISABLE_COPY(VSettings) Q_DISABLE_COPY(VSettings)
}; };

View File

@ -61,7 +61,7 @@ void TST_VPoster::BigPoster()
const QRect image(0, 0, 2622, 3178); // Little bit bigger than A1 const QRect image(0, 0, 2622, 3178); // Little bit bigger than A1
VPoster posterazor(&printer); VPoster posterazor(&printer);
const QVector<PosterData> poster = posterazor.Calc(image, 0); const QVector<PosterData> poster = posterazor.Calc(image, 0, PageOrientation::Portrait);
QCOMPARE(poster.size(), 12); QCOMPARE(poster.size(), 12);
@ -81,7 +81,7 @@ void TST_VPoster::SmallPoster()
const QRect image(0, 0, 700, 1000); // Little bit less than A4 const QRect image(0, 0, 700, 1000); // Little bit less than A4
VPoster posterazor(&printer); VPoster posterazor(&printer);
const QVector<PosterData> poster = posterazor.Calc(image, 0); const QVector<PosterData> poster = posterazor.Calc(image, 0, PageOrientation::Portrait);
QCOMPARE(poster.size(), 1); QCOMPARE(poster.size(), 1);