Fix uniting and cropping pages.

Code missed handling landscape orienation.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-01-03 19:35:04 +02:00
parent a7332adc75
commit 2f717fd365
3 changed files with 122 additions and 43 deletions

View File

@ -73,6 +73,8 @@ public:
int GetWidth() const; int GetWidth() const;
void SetWidth(int width); void SetWidth(int width);
bool IsPortrait() const;
QSizeF GetSize() const; QSizeF GetSize() const;
QVector<QPointF> UniteWithContour(const VLayoutPiece &detail, int globalI, int detJ, BestFrom type) const; QVector<QPointF> UniteWithContour(const VLayoutPiece &detail, int globalI, int detJ, BestFrom type) const;
@ -93,8 +95,6 @@ private:
QSharedDataPointer<VContourData> d; QSharedDataPointer<VContourData> d;
void AppendWhole(QVector<QPointF> &contour, const VLayoutPiece &detail, int detJ) const; void AppendWhole(QVector<QPointF> &contour, const VLayoutPiece &detail, int detJ) const;
bool IsPortrait() const;
}; };
Q_DECLARE_TYPEINFO(VContour, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(VContour, Q_MOVABLE_TYPE);

View File

@ -330,6 +330,8 @@ void VLayoutGenerator::GatherPages()
int j = 0; // papers count int j = 0; // papers count
for (int i = 0; i < papers.size(); ++i) for (int i = 0; i < papers.size(); ++i)
{
if (IsPortrait())
{ {
int paperHeight = qRound(papers.at(i).DetailsBoundingRect().height()); int paperHeight = qRound(papers.at(i).DetailsBoundingRect().height());
@ -351,6 +353,29 @@ void VLayoutGenerator::GatherPages()
length += paperHeight; length += paperHeight;
} }
} }
else
{
int paperWidth = qRound(papers.at(i).DetailsBoundingRect().width());
if (i != papers.size()-1)
{
paperWidth += qRound(bank->GetLayoutWidth()*2);
}
if (length + paperWidth <= PageWidth())
{
UniteDetails(j, nDetails, length, i);
length += paperWidth;
}
else
{
length = 0; // Start new paper
++j;// New paper
UniteDetails(j, nDetails, length, i);
length += paperWidth;
}
}
}
QVector<VLayoutPaper> nPapers; QVector<VLayoutPaper> nPapers;
for (int i = 0; i < nDetails.size(); ++i) for (int i = 0; i < nDetails.size(); ++i)
@ -386,6 +411,8 @@ void VLayoutGenerator::UnitePages()
int j = 0; // papers count int j = 0; // papers count
for (int i = 0; i < papers.size(); ++i) for (int i = 0; i < papers.size(); ++i)
{
if (IsPortrait())
{ {
int paperHeight = 0; int paperHeight = 0;
if (autoCrop) if (autoCrop)
@ -417,11 +444,47 @@ void VLayoutGenerator::UnitePages()
UnitePapers(j, papersLength, length); UnitePapers(j, papersLength, length);
} }
} }
else
{
int paperWidth = 0;
if (autoCrop)
{
paperWidth = qRound(papers.at(i).DetailsBoundingRect().width());
}
else
{
paperWidth = papers.at(i).GetWidth();
}
if (i != papers.size()-1)
{
paperWidth = qRound(paperWidth + bank->GetLayoutWidth()*2);
}
if (length + paperWidth <= QIMAGE_MAX)
{
UniteDetails(j, nDetails, length, i);
length += paperWidth;
UnitePapers(j, papersLength, length);
}
else
{
length = 0; // Start new paper
++j;// New paper
UniteDetails(j, nDetails, length, i);
length += paperWidth;
UnitePapers(j, papersLength, length);
}
}
}
QVector<VLayoutPaper> nPapers; QVector<VLayoutPaper> nPapers;
for (int i = 0; i < nDetails.size(); ++i) for (int i = 0; i < nDetails.size(); ++i)
{ {
VLayoutPaper paper(qFloor(papersLength.at(i)), PageWidth()); const int height = IsPortrait() ? qFloor(papersLength.at(i)) : PageHeight();
const int width = IsPortrait() ? PageWidth() : qFloor(papersLength.at(i));
VLayoutPaper paper(height, width);
paper.SetShift(shift); paper.SetShift(shift);
paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(static_cast<quint32>(i)); paper.SetPaperIndex(static_cast<quint32>(i));
@ -475,7 +538,7 @@ QList<VLayoutPiece> VLayoutGenerator::MoveDetails(qreal length, const QVector<VL
QList<VLayoutPiece> newDetails; QList<VLayoutPiece> newDetails;
for (auto d : details) for (auto d : details)
{ {
d.Translate(0, length); IsPortrait() ? d.Translate(0, length) : d.Translate(length, 0);
newDetails.append(d); newDetails.append(d);
} }

View File

@ -337,6 +337,9 @@ QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop, bool textAsPaths) c
{ {
scene->addItem(item); scene->addItem(item);
} }
if (d->globalContour.IsPortrait())
{
const int height = scene->itemsBoundingRect().toRect().height(); const int height = scene->itemsBoundingRect().toRect().height();
if (d->globalContour.GetHeight() > height) //-V807 if (d->globalContour.GetHeight() > height) //-V807
{ {
@ -348,6 +351,19 @@ QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop, bool textAsPaths) c
} }
} }
else else
{
const int width = scene->itemsBoundingRect().toRect().width();
if (d->globalContour.GetWidth() > width) //-V807
{
paper = new QGraphicsRectItem(QRectF(0, 0, width, d->globalContour.GetHeight()));
}
else
{
paper = new QGraphicsRectItem(QRectF(0, 0, d->globalContour.GetWidth(), d->globalContour.GetHeight()));
}
}
}
else
{ {
paper = new QGraphicsRectItem(QRectF(0, 0, d->globalContour.GetWidth(), d->globalContour.GetHeight())); paper = new QGraphicsRectItem(QRectF(0, 0, d->globalContour.GetWidth(), d->globalContour.GetHeight()));
} }