From 2f717fd3659827941b4b7fca49b38c2e1b458455 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 3 Jan 2019 19:35:04 +0200 Subject: [PATCH] Fix uniting and cropping pages. Code missed handling landscape orienation. --HG-- branch : develop --- src/libs/vlayout/vcontour.h | 4 +- src/libs/vlayout/vlayoutgenerator.cpp | 137 +++++++++++++++++++------- src/libs/vlayout/vlayoutpaper.cpp | 24 ++++- 3 files changed, 122 insertions(+), 43 deletions(-) diff --git a/src/libs/vlayout/vcontour.h b/src/libs/vlayout/vcontour.h index f8e5cbc4c..8b6c388f0 100644 --- a/src/libs/vlayout/vcontour.h +++ b/src/libs/vlayout/vcontour.h @@ -73,6 +73,8 @@ public: int GetWidth() const; void SetWidth(int width); + bool IsPortrait() const; + QSizeF GetSize() const; QVector UniteWithContour(const VLayoutPiece &detail, int globalI, int detJ, BestFrom type) const; @@ -93,8 +95,6 @@ private: QSharedDataPointer d; void AppendWhole(QVector &contour, const VLayoutPiece &detail, int detJ) const; - - bool IsPortrait() const; }; Q_DECLARE_TYPEINFO(VContour, Q_MOVABLE_TYPE); diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index bd09cbe07..5a8c3715e 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -331,24 +331,49 @@ void VLayoutGenerator::GatherPages() for (int i = 0; i < papers.size(); ++i) { - int paperHeight = qRound(papers.at(i).DetailsBoundingRect().height()); - - if (i != papers.size()-1) + if (IsPortrait()) { - paperHeight += qRound(bank->GetLayoutWidth()*2); - } + int paperHeight = qRound(papers.at(i).DetailsBoundingRect().height()); - if (length + paperHeight <= PageHeight()) - { - UniteDetails(j, nDetails, length, i); - length += paperHeight; + if (i != papers.size()-1) + { + paperHeight += qRound(bank->GetLayoutWidth()*2); + } + + if (length + paperHeight <= PageHeight()) + { + UniteDetails(j, nDetails, length, i); + length += paperHeight; + } + else + { + length = 0; // Start new paper + ++j;// New paper + UniteDetails(j, nDetails, length, i); + length += paperHeight; + } } else { - length = 0; // Start new paper - ++j;// New paper - UniteDetails(j, nDetails, length, i); - length += paperHeight; + 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; + } } } @@ -387,41 +412,79 @@ void VLayoutGenerator::UnitePages() for (int i = 0; i < papers.size(); ++i) { - int paperHeight = 0; - if (autoCrop) + if (IsPortrait()) { - paperHeight = qRound(papers.at(i).DetailsBoundingRect().height()); + int paperHeight = 0; + if (autoCrop) + { + paperHeight = qRound(papers.at(i).DetailsBoundingRect().height()); + } + else + { + paperHeight = papers.at(i).GetHeight(); + } + + if (i != papers.size()-1) + { + paperHeight = qRound(paperHeight + bank->GetLayoutWidth()*2); + } + + if (length + paperHeight <= QIMAGE_MAX) + { + UniteDetails(j, nDetails, length, i); + length += paperHeight; + UnitePapers(j, papersLength, length); + } + else + { + length = 0; // Start new paper + ++j;// New paper + UniteDetails(j, nDetails, length, i); + length += paperHeight; + UnitePapers(j, papersLength, length); + } } else { - paperHeight = papers.at(i).GetHeight(); - } + int paperWidth = 0; + if (autoCrop) + { + paperWidth = qRound(papers.at(i).DetailsBoundingRect().width()); + } + else + { + paperWidth = papers.at(i).GetWidth(); + } - if (i != papers.size()-1) - { - paperHeight = qRound(paperHeight + bank->GetLayoutWidth()*2); - } + if (i != papers.size()-1) + { + paperWidth = qRound(paperWidth + bank->GetLayoutWidth()*2); + } - if (length + paperHeight <= QIMAGE_MAX) - { - UniteDetails(j, nDetails, length, i); - length += paperHeight; - UnitePapers(j, papersLength, length); - } - else - { - length = 0; // Start new paper - ++j;// New paper - UniteDetails(j, nDetails, length, i); - length += paperHeight; - UnitePapers(j, papersLength, length); + 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 nPapers; 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.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetPaperIndex(static_cast(i)); @@ -475,7 +538,7 @@ QList VLayoutGenerator::MoveDetails(qreal length, const QVector newDetails; for (auto d : details) { - d.Translate(0, length); + IsPortrait() ? d.Translate(0, length) : d.Translate(length, 0); newDetails.append(d); } diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 1bc2a70d0..e88ba6e5b 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -337,14 +337,30 @@ QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop, bool textAsPaths) c { scene->addItem(item); } - const int height = scene->itemsBoundingRect().toRect().height(); - if (d->globalContour.GetHeight() > height) //-V807 + + if (d->globalContour.IsPortrait()) { - paper = new QGraphicsRectItem(QRectF(0, 0, d->globalContour.GetWidth(), height)); + const int height = scene->itemsBoundingRect().toRect().height(); + if (d->globalContour.GetHeight() > height) //-V807 + { + paper = new QGraphicsRectItem(QRectF(0, 0, d->globalContour.GetWidth(), height)); + } + 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())); + 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