New command line option --cropWidth. Helps to crop unused width of paper.

--HG--
branch : develop
This commit is contained in:
Andrey Ushakov 2019-10-16 11:16:16 +03:00
parent b3cc614789
commit ea75af2f46
16 changed files with 171 additions and 63 deletions

View File

@ -31,6 +31,7 @@
- [#558] New export: Export pattern as step-by-step text.
- Added options to control passmark angle type and passmark mark type.
- Improve for recent files list. Show duplicate file names with unique path section.
- New command line option --cropWidth. Helps to crop unused width of paper.
# Version 0.6.2 (unreleased)
- [#903] Bug in tool Cut Spline path.

View File

@ -1,6 +1,6 @@
.\" Manpage for valentina.
.\" Contact dismine@gmail.com to correct errors.
.TH valentina 1 "21 July, 2019" "valentina man page"
.TH valentina 1 "17 October, 2019" "valentina man page"
.SH NAME
Valentina \- Pattern making program.
.SH SYNOPSIS
@ -194,6 +194,8 @@ The path to output destination folder. By default the directory at which the app
.RB "Nest quantity copies of each piece (" "export mode" ").
.IP "-c, --crop"
.RB "Auto crop unused length (" "export mode" ")."
.IP "--cropWidth"
.RB "Auto crop unused width (" "export mode" ")."
.IP "-u, --unite"
.RB "Unite pages if possible (" "export mode" "). Maximum value limited by QImage that supports only a maximum of " "32768x32768 px" " images."
.IP "-S, --savelen"

View File

@ -200,7 +200,8 @@ VLayoutGeneratorPtr VCommandLine::DefaultGenerator() const
diag.SetLayoutWidth(Lo2Px(OptionValue(LONG_OPTION_GAPWIDTH), diag));
}
diag.SetAutoCrop(IsOptionSet(LONG_OPTION_CROP));
diag.SetAutoCropLength(IsOptionSet(LONG_OPTION_CROP_LENGTH));
diag.SetAutoCropWidth(IsOptionSet(LONG_OPTION_CROP_WIDTH));
diag.SetUnitePages(IsOptionSet(LONG_OPTION_UNITE));
diag.SetSaveLength(IsOptionSet(LONG_OPTION_SAVELENGTH));
diag.SetGroup(OptGroup());
@ -670,8 +671,10 @@ void VCommandLine::InitCommandLineOptions()
translate("VCommandLine", "Follow manual priority over priority by square (export mode).")},
{LONG_OPTION_NEST_QUANTITY,
translate("VCommandLine", "Nest quantity copies of each piece (export mode).")},
{{SINGLE_OPTION_CROP, LONG_OPTION_CROP},
{{SINGLE_OPTION_CROP_LENGTH, LONG_OPTION_CROP_LENGTH},
translate("VCommandLine", "Auto crop unused length (export mode).")},
{{LONG_OPTION_CROP_WIDTH},
translate("VCommandLine", "Auto crop unused width (export mode).")},
{{SINGLE_OPTION_UNITE, LONG_OPTION_UNITE},
translate("VCommandLine", "Unite pages if possible (export mode). Maximum value limited by QImage that "
"supports only a maximum of 32768x32768 px images.")},

View File

@ -257,15 +257,27 @@ void DialogLayoutSettings::SetManualPriority(bool state)
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogLayoutSettings::GetAutoCrop() const
bool DialogLayoutSettings::GetAutoCropLength() const
{
return ui->checkBoxAutoCrop->isChecked();
return ui->checkBoxAutoCropLength->isChecked();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetAutoCrop(bool autoCrop)
void DialogLayoutSettings::SetAutoCropLength(bool autoCropLength)
{
ui->checkBoxAutoCrop->setChecked(autoCrop);
ui->checkBoxAutoCropLength->setChecked(autoCropLength);
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogLayoutSettings::GetAutoCropWidth() const
{
return ui->checkBoxAutoCropWidth->isChecked();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetAutoCropWidth(bool autoCropWidth)
{
ui->checkBoxAutoCropWidth->setChecked(autoCropWidth);
}
//---------------------------------------------------------------------------------------------------------------------
@ -585,7 +597,8 @@ void DialogLayoutSettings::DialogAccepted()
generator->SetEfficiencyCoefficient(GetEfficiencyCoefficient());
generator->SetFollowGrainline(GetFollowGrainline());
generator->SetManualPriority(GetManualPriority());
generator->SetAutoCrop(GetAutoCrop());
generator->SetAutoCropLength(GetAutoCropLength());
generator->SetAutoCropWidth(GetAutoCropWidth());
generator->SetSaveLength(IsSaveLength());
generator->SetUnitePages(IsUnitePages());
generator->SetStripOptimization(IsStripOptimization());
@ -1003,7 +1016,8 @@ void DialogLayoutSettings::ReadSettings()
SetGroup(settings->GetLayoutGroup());
SetFollowGrainline(settings->GetLayoutFollowGrainline());
SetManualPriority(settings->GetLayoutManualPriority());
SetAutoCrop(settings->GetLayoutAutoCrop());
SetAutoCropLength(settings->GetLayoutAutoCropLength());
SetAutoCropWidth(settings->GetLayoutAutoCropWidth());
SetSaveLength(settings->GetLayoutSaveLength());
SetUnitePages(settings->GetLayoutUnitePages());
SetFields(settings->GetFields(GetDefPrinterFields()));
@ -1029,7 +1043,8 @@ void DialogLayoutSettings::WriteSettings() const
settings->SetLayoutPaperWidth(GetPaperWidth());
settings->SetLayoutFollowGrainline(GetFollowGrainline());
settings->SetLayoutManualPriority(GetManualPriority());
settings->SetLayoutAutoCrop(GetAutoCrop());
settings->SetLayoutAutoCropLength(GetAutoCropLength());
settings->SetLayoutAutoCropWidth(GetAutoCropWidth());
settings->SetLayoutSaveLength(IsSaveLength());
settings->SetLayoutUnitePages(IsUnitePages());
settings->SetFields(GetFields());
@ -1059,7 +1074,8 @@ void DialogLayoutSettings::SheetSize(const QSizeF &size)
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetAdditionalOptions(bool value)
{
SetAutoCrop(value);
SetAutoCropLength(value);
SetAutoCropWidth(value);
SetSaveLength(value);
SetUnitePages(value);
SetStripOptimization(value);

View File

@ -76,8 +76,11 @@ public:
bool GetManualPriority() const;
void SetManualPriority(bool state);
bool GetAutoCrop() const;
void SetAutoCrop(bool autoCrop);
bool GetAutoCropLength() const;
void SetAutoCropLength(bool autoCropLength);
bool GetAutoCropWidth() const;
void SetAutoCropWidth(bool autoCropWidth);
bool IsSaveLength() const;
void SetSaveLength(bool save);

View File

@ -543,12 +543,19 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxAutoCrop">
<widget class="QCheckBox" name="checkBoxAutoCropLength">
<property name="text">
<string>Auto crop unused length</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxAutoCropWidth">
<property name="text">
<string>Auto crop unused width</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxUnitePages">
<property name="text">

View File

@ -157,7 +157,8 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent)
m_taskbarProgress(nullptr),
#endif
isTiled(false),
isAutoCrop(false),
isAutoCropLength(false),
isAutoCropWidth(false),
isUnitePages(false),
layoutPrinterName()
{
@ -334,7 +335,8 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
ignorePrinterFields = not lGenerator.IsUsePrinterFields();
margins = lGenerator.GetPrinterFields();
paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight());
isAutoCrop = lGenerator.GetAutoCrop();
isAutoCropLength = lGenerator.GetAutoCropLength();
isAutoCropWidth = lGenerator.GetAutoCropWidth();
isUnitePages = lGenerator.IsUnitePages();
isLayoutStale = false;
papersCount = lGenerator.PapersCount();
@ -1563,25 +1565,43 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr
if (not isTiled)
{
QSizeF size = QSizeF(FromPixel(paperSize.width(), Unit::Mm), FromPixel(paperSize.height(), Unit::Mm));
if (isAutoCrop || isUnitePages)
qreal width = FromPixel(paperSize.width(), Unit::Mm);
qreal height = FromPixel(paperSize.height(), Unit::Mm);
if (isAutoCropLength || isUnitePages)
{
auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
if (paper)
{
if (isLayoutPortrait)
{
size = QSizeF(FromPixel(paperSize.width(), Unit::Mm),
FromPixel(paper->rect().height() + margins.top() + margins.bottom(), Unit::Mm));
height = FromPixel(paper->rect().height() + margins.top() + margins.bottom(), Unit::Mm);
}
else
{
size = QSizeF(FromPixel(paper->rect().width() + margins.left() + margins.right(), Unit::Mm),
FromPixel(paperSize.height(), Unit::Mm));
width = FromPixel(paper->rect().width() + margins.left() + margins.right(), Unit::Mm);
}
}
}
if (isAutoCropWidth)
{
auto *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(0));
if (paper)
{
if (isLayoutPortrait)
{
width = FromPixel(paper->rect().width() + margins.left() + margins.right(), Unit::Mm);
}
else
{
height = FromPixel(paper->rect().height() + margins.top() + margins.bottom(), Unit::Mm);
}
}
}
QSizeF size = QSizeF(width, height);
if (not isLayoutPortrait)
{
size.transpose(); // QPrinter reverse this for landscape orientation

View File

@ -154,7 +154,8 @@ private:
Q_DISABLE_COPY(MainWindowsNoGUI)
bool isTiled;
bool isAutoCrop;
bool isAutoCropLength;
bool isAutoCropWidth;
bool isUnitePages;
QString layoutPrinterName;

View File

@ -59,7 +59,8 @@ VLayoutGenerator::VLayoutGenerator(QObject *parent)
rotate(true),
followGrainline(false),
rotationNumber(2),
autoCrop(false),
autoCropLength(false),
autoCropWidth(false),
saveLength(false),
unitePages(false),
stripOptimizationEnabled(false),
@ -289,7 +290,7 @@ QList<QGraphicsItem *> VLayoutGenerator::GetPapersItems() const
QList<QGraphicsItem *> list;
for (auto &paper : papers)
{
list.append(paper.GetPaperItem(autoCrop, IsTestAsPaths()));
list.append(paper.GetPaperItem(autoCropLength, autoCropWidth, IsTestAsPaths()));
}
return list;
}
@ -518,7 +519,7 @@ void VLayoutGenerator::UnitePages()
if (IsPortrait())
{
int paperHeight = 0;
if (autoCrop)
if (autoCropLength)
{
const QRectF rec = papers.at(i).DetailsBoundingRect();
paperHeight = qRound(rec.y() + rec.height());
@ -551,7 +552,7 @@ void VLayoutGenerator::UnitePages()
else
{
int paperWidth = 0;
if (autoCrop)
if (autoCropLength)
{
const QRectF rec = papers.at(i).DetailsBoundingRect();
paperWidth = qRound(rec.x() + rec.width());
@ -675,15 +676,26 @@ void VLayoutGenerator::SetSaveLength(bool value)
}
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutGenerator::GetAutoCrop() const
bool VLayoutGenerator::GetAutoCropLength() const
{
return autoCrop;
return autoCropLength;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetAutoCrop(bool value)
void VLayoutGenerator::SetAutoCropLength(bool value)
{
autoCrop = value;
autoCropLength = value;
}
bool VLayoutGenerator::GetAutoCropWidth() const
{
return autoCropWidth;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetAutoCropWidth(bool value)
{
autoCropWidth = value;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -108,8 +108,11 @@ public:
int GetRotationNumber() const;
void SetRotationNumber(int value);
bool GetAutoCrop() const;
void SetAutoCrop(bool value);
bool GetAutoCropLength() const;
void SetAutoCropLength(bool value);
bool GetAutoCropWidth() const;
void SetAutoCropWidth(bool value);
bool IsSaveLength() const;
void SetSaveLength(bool value);
@ -148,7 +151,8 @@ private:
bool rotate;
bool followGrainline;
int rotationNumber;
bool autoCrop;
bool autoCropLength;
bool autoCropWidth;
bool saveLength;
bool unitePages;
bool stripOptimizationEnabled;

View File

@ -282,10 +282,12 @@ bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece
}
//---------------------------------------------------------------------------------------------------------------------
QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop, bool textAsPaths) const
QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCropLength, bool autoCropWidth, bool textAsPaths) const
{
QGraphicsRectItem *paper;
if (autoCrop)
int height = d->globalContour.GetHeight();
int width = d->globalContour.GetWidth();
if (autoCropLength || autoCropWidth)
{
QScopedPointer<QGraphicsScene> scene(new QGraphicsScene());
QList<QGraphicsItem *> list = GetItemDetails(textAsPaths);
@ -295,21 +297,33 @@ QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop, bool textAsPaths) c
}
const QRect boundingRect = scene->itemsBoundingRect().toRect();
if (autoCropLength)
{
if (d->globalContour.IsPortrait())
{
const int height = boundingRect.height() + boundingRect.y() + 1;
paper = new QGraphicsRectItem(QRectF(0, 0, d->globalContour.GetWidth(), height));
height = boundingRect.height() + boundingRect.y() + 1;
}
else
{
const int width = boundingRect.width() + boundingRect.x() + 1;
paper = new QGraphicsRectItem(QRectF(0, 0, width, d->globalContour.GetHeight()));
width = boundingRect.width() + boundingRect.x() + 1;
}
}
if (autoCropWidth)
{
if (d->globalContour.IsPortrait())
{
width = boundingRect.width() + boundingRect.x() + 1;
}
else
{
paper = new QGraphicsRectItem(QRectF(0, 0, d->globalContour.GetWidth(), d->globalContour.GetHeight()));
height = boundingRect.height() + boundingRect.y() + 1;
}
}
}
auto *paper = new QGraphicsRectItem(QRectF(0, 0, width, height));
paper->setPen(QPen(Qt::black, 1));
paper->setBrush(QBrush(Qt::white));
return paper;

View File

@ -95,7 +95,7 @@ public:
bool ArrangeDetail(const VLayoutPiece &detail, std::atomic_bool &stop);
int Count() const;
Q_REQUIRED_RESULT QGraphicsRectItem *GetPaperItem(bool autoCrop, bool textAsPaths) const;
Q_REQUIRED_RESULT QGraphicsRectItem *GetPaperItem(bool autoCropLength, bool autoCropWidth, bool textAsPaths) const;
Q_REQUIRED_RESULT QGraphicsPathItem *GetGlobalContour() const;
Q_REQUIRED_RESULT QList<QGraphicsItem *> GetItemDetails(bool textAsPaths) const;

View File

@ -54,8 +54,10 @@ const QString LONG_OPTION_TEXT2PATHS = QStringLiteral("text2paths");
const QString LONG_OPTION_EXPORTONLYDETAILS = QStringLiteral("exportOnlyDetails");
const QString LONG_OPTION_EXPORTSUCHDETAILS = QStringLiteral("exportSuchDetails");
const QString LONG_OPTION_CROP = QStringLiteral("crop");
const QString SINGLE_OPTION_CROP = QStringLiteral("c");
const QString LONG_OPTION_CROP_LENGTH = QStringLiteral("crop");
const QString SINGLE_OPTION_CROP_LENGTH = QStringLiteral("c");
const QString LONG_OPTION_CROP_WIDTH = QStringLiteral("cropWidth");
const QString LONG_OPTION_UNITE = QStringLiteral("unite");
const QString SINGLE_OPTION_UNITE = QStringLiteral("u");
@ -151,7 +153,8 @@ QStringList AllKeys()
LONG_OPTION_TEXT2PATHS,
LONG_OPTION_EXPORTONLYDETAILS,
LONG_OPTION_EXPORTSUCHDETAILS,
LONG_OPTION_CROP, SINGLE_OPTION_CROP,
LONG_OPTION_CROP_LENGTH, SINGLE_OPTION_CROP_LENGTH,
LONG_OPTION_CROP_WIDTH,
LONG_OPTION_UNITE, SINGLE_OPTION_UNITE,
LONG_OPTION_PAGEW, SINGLE_OPTION_PAGEW,
LONG_OPTION_PAGEH, SINGLE_OPTION_PAGEH,

View File

@ -51,8 +51,10 @@ extern const QString LONG_OPTION_TEXT2PATHS;
extern const QString LONG_OPTION_EXPORTONLYDETAILS;
extern const QString LONG_OPTION_EXPORTSUCHDETAILS;
extern const QString LONG_OPTION_CROP;
extern const QString SINGLE_OPTION_CROP;
extern const QString LONG_OPTION_CROP_LENGTH;
extern const QString SINGLE_OPTION_CROP_LENGTH;
extern const QString LONG_OPTION_CROP_WIDTH;
extern const QString LONG_OPTION_UNITE;
extern const QString SINGLE_OPTION_UNITE;

View File

@ -86,7 +86,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutPaperWidth, (QLatin1String
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutFollowGrainline, (QLatin1String("layout/followGrainline")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutManualPriority, (QLatin1String("layout/manualPriority")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutNestQuantity, (QLatin1String("layout/nestQuantity")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutAutoCrop, (QLatin1String("layout/autoCrop")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutAutoCropLength, (QLatin1String("layout/autoCropLength")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutAutoCropWidth, (QLatin1String("layout/autoCropWidth")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutSaveLength, (QLatin1String("layout/saveLength")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLayoutUnitePages, (QLatin1String("layout/unitePages")))
Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingFields, (QLatin1String("layout/fields")))
@ -356,23 +357,38 @@ void VSettings::SetLayoutNestQuantity(bool value)
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetLayoutAutoCrop() const
bool VSettings::GetLayoutAutoCropLength() const
{
return value(*settingLayoutAutoCrop, GetDefLayoutAutoCrop()).toBool();
return value(*settingLayoutAutoCropLength, GetDefLayoutAutoCropLength()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetDefLayoutAutoCrop()
bool VSettings::GetDefLayoutAutoCropLength()
{
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetLayoutAutoCropLength(bool value)
{
setValue(*settingLayoutAutoCropLength, value);
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetLayoutAutoCropWidth() const
{
return value(*settingLayoutAutoCropWidth, GetDefLayoutAutoCropWidth()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetDefLayoutAutoCropWidth()
{
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetLayoutAutoCrop(bool value)
void VSettings::SetLayoutAutoCropWidth(bool value)
{
setValue(*settingLayoutAutoCrop, value);
setValue(*settingLayoutAutoCropWidth, value);
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetLayoutSaveLength() const
{

View File

@ -97,9 +97,13 @@ public:
static bool GetDefLayoutNestQuantity();
void SetLayoutNestQuantity(bool value);
bool GetLayoutAutoCrop() const;
static bool GetDefLayoutAutoCrop();
void SetLayoutAutoCrop(bool value);
bool GetLayoutAutoCropLength() const;
static bool GetDefLayoutAutoCropLength();
void SetLayoutAutoCropLength(bool value);
bool GetLayoutAutoCropWidth() const;
static bool GetDefLayoutAutoCropWidth();
void SetLayoutAutoCropWidth(bool value);
bool GetLayoutSaveLength() const;
static bool GetDefLayoutSaveLength();