Improve the layout option "Auto crop unused width".

This commit is contained in:
Roman Telezhynskyi 2020-12-18 17:01:58 +02:00
parent 58cae6f66c
commit e70e998dc5
5 changed files with 36 additions and 0 deletions

View File

@ -5,6 +5,7 @@
- Fix invalid visualization for tool Point of intersection circles. - Fix invalid visualization for tool Point of intersection circles.
- New warning. Warn about empty measurements dimension value when preparing placeholders. - New warning. Warn about empty measurements dimension value when preparing placeholders.
- New option "Don't use the native file dialog". - New option "Don't use the native file dialog".
- Improve the layout option "Auto crop unused width".
# Version 0.7.41 Dec 4, 2020 # Version 0.7.41 Dec 4, 2020
- Bug fixes. - Bug fixes.

View File

@ -263,6 +263,11 @@ void VLayoutGenerator::Generate(const QElapsedTimer &timer, qint64 timeout, Layo
GatherPages(); GatherPages();
} }
if (autoCropWidth)
{
OptimizeWidth();
}
if (IsUnitePages()) if (IsUnitePages())
{ {
UnitePages(); UnitePages();
@ -506,6 +511,27 @@ void VLayoutGenerator::GatherPages()
papers = nPapers; papers = nPapers;
} }
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::OptimizeWidth()
{
QVector<VLayoutPiece> newDetails;
for (auto &paper : papers)
{
const QRectF rec = paper.DetailsBoundingRect();
QVector<VLayoutPiece> details = paper.GetDetails();
newDetails.resize(0); // resize(0) preserves capacity, unlike QVector::clear()
newDetails.reserve(details.size());
for (auto &d : details)
{
IsPortrait() ? d.Translate(-rec.x()+1, 0) : d.Translate(0, -rec.y()+1);
newDetails.append(d);
}
paper.SetDetails(newDetails);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::UnitePages() void VLayoutGenerator::UnitePages()
{ {
@ -785,6 +811,7 @@ void VLayoutGenerator::SetAutoCropLength(bool value)
autoCropLength = value; autoCropLength = value;
} }
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutGenerator::GetAutoCropWidth() const bool VLayoutGenerator::GetAutoCropWidth() const
{ {
return autoCropWidth; return autoCropWidth;

View File

@ -169,6 +169,7 @@ private:
int PageHeight() const; int PageHeight() const;
int PageWidth() const; int PageWidth() const;
void OptimizeWidth();
void GatherPages(); void GatherPages();
void UnitePages(); void UnitePages();
void UniteDetails(int j, QList<QList<VLayoutPiece> > &nDetails, qreal length, int i) const; void UniteDetails(int j, QList<QList<VLayoutPiece> > &nDetails, qreal length, int i) const;

View File

@ -435,6 +435,12 @@ QVector<VLayoutPiece> VLayoutPaper::GetDetails() const
return d->details; return d->details;
} }
//---------------------------------------------------------------------------------------------------------------------
void VLayoutPaper::SetDetails(const QVector<VLayoutPiece> &details)
{
d->details = details;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutPaper::SetDetails(const QList<VLayoutPiece> &details) void VLayoutPaper::SetDetails(const QList<VLayoutPiece> &details)
{ {

View File

@ -99,6 +99,7 @@ public:
Q_REQUIRED_RESULT QList<QGraphicsItem *> GetItemDetails(bool textAsPaths) const; Q_REQUIRED_RESULT QList<QGraphicsItem *> GetItemDetails(bool textAsPaths) const;
QVector<VLayoutPiece> GetDetails() const; QVector<VLayoutPiece> GetDetails() const;
void SetDetails(const QVector<VLayoutPiece>& details);
void SetDetails(const QList<VLayoutPiece>& details); void SetDetails(const QList<VLayoutPiece>& details);
QRectF DetailsBoundingRect() const; QRectF DetailsBoundingRect() const;