From 5ebcd1caba517a82657d4d1f2c4bc8570213222c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 18 May 2015 14:26:37 +0300 Subject: [PATCH] New option "Unite papers". --HG-- branch : develop --- src/app/core/vsettings.cpp | 13 +++ src/app/core/vsettings.h | 4 + src/app/dialogs/app/dialoglayoutsettings.cpp | 59 +++++++------ src/app/dialogs/app/dialoglayoutsettings.h | 4 + src/app/dialogs/app/dialoglayoutsettings.ui | 9 +- src/app/mainwindowsnogui.cpp | 91 ++++++++++++++++++++ src/app/mainwindowsnogui.h | 5 ++ src/libs/vlayout/vlayoutgenerator.cpp | 14 ++- src/libs/vlayout/vlayoutgenerator.h | 4 + 9 files changed, 177 insertions(+), 26 deletions(-) diff --git a/src/app/core/vsettings.cpp b/src/app/core/vsettings.cpp index e29acd826..a3b954983 100644 --- a/src/app/core/vsettings.cpp +++ b/src/app/core/vsettings.cpp @@ -87,6 +87,7 @@ const QString VSettings::SettingLayoutRotate = QStringLitera const QString VSettings::SettingLayoutRotationIncrease = QStringLiteral("layout/rotationIncrease"); const QString VSettings::SettingLayoutAutoCrop = QStringLiteral("layout/autoCrop"); const QString VSettings::SettingLayoutSaveLength = QStringLiteral("layout/saveLength"); +const QString VSettings::SettingLayoutUnitePages = QStringLiteral("layout/unitePages"); //--------------------------------------------------------------------------------------------------------------------- VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application, @@ -700,6 +701,18 @@ void VSettings::SetLayoutSaveLength(bool value) setValue(SettingLayoutSaveLength, value); } +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetLayoutUnitePages() const +{ + return value(SettingLayoutUnitePages, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSettings::SetLayoutUnitePages(bool value) +{ + setValue(SettingLayoutUnitePages, value); +} + //--------------------------------------------------------------------------------------------------------------------- QString VSettings::StandardTablesPath() { diff --git a/src/app/core/vsettings.h b/src/app/core/vsettings.h index 238bdc962..4ead8cfec 100644 --- a/src/app/core/vsettings.h +++ b/src/app/core/vsettings.h @@ -166,6 +166,9 @@ public: bool GetLayoutSaveLength() const; void SetLayoutSaveLength(bool value); + bool GetLayoutUnitePages() const; + void SetLayoutUnitePages(bool value); + private: Q_DISABLE_COPY(VSettings) static const QString SettingConfigurationOsSeparator; @@ -213,6 +216,7 @@ private: static const QString SettingLayoutRotationIncrease; static const QString SettingLayoutAutoCrop; static const QString SettingLayoutSaveLength; + static const QString SettingLayoutUnitePages; }; #endif // VSETTINGS_H diff --git a/src/app/dialogs/app/dialoglayoutsettings.cpp b/src/app/dialogs/app/dialoglayoutsettings.cpp index da34f5134..c4c1b6f93 100644 --- a/src/app/dialogs/app/dialoglayoutsettings.cpp +++ b/src/app/dialogs/app/dialoglayoutsettings.cpp @@ -225,6 +225,18 @@ void DialogLayoutSettings::SetSaveLength(bool save) ui->checkBoxSaveLength->setChecked(save); } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogLayoutSettings::IsUnitePages() const +{ + return ui->checkBoxUnitePages->isChecked(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::SetUnitePages(bool save) +{ + ui->checkBoxUnitePages->setChecked(save); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::TemplateSelected() { @@ -319,6 +331,7 @@ void DialogLayoutSettings::DialogAccepted() generator->SetRotationIncrease(GetIncrease()); generator->SetAutoCrop(GetAutoCrop()); generator->SetSaveLength(IsSaveLength()); + generator->SetUnitePages(IsUnitePages()); WriteSettings(); accepted(); @@ -415,85 +428,73 @@ QSizeF DialogLayoutSettings::Template() switch (temp) { case PaperSizeTemplate::A0: - SetAutoCrop(false); - SetSaveLength(false); + SetAdditionalOptions(false); width = VAbstractMeasurements::UnitConvertor(841, Unit::Mm, paperUnit); height = VAbstractMeasurements::UnitConvertor(1189, Unit::Mm, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::A1: - SetAutoCrop(false); - SetSaveLength(false); + SetAdditionalOptions(false); width = VAbstractMeasurements::UnitConvertor(594, Unit::Mm, paperUnit); height = VAbstractMeasurements::UnitConvertor(841, Unit::Mm, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::A2: - SetAutoCrop(false); - SetSaveLength(false); + SetAdditionalOptions(false); width = VAbstractMeasurements::UnitConvertor(420, Unit::Mm, paperUnit); height = VAbstractMeasurements::UnitConvertor(594, Unit::Mm, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::A3: - SetAutoCrop(false); - SetSaveLength(false); + SetAdditionalOptions(false); width = VAbstractMeasurements::UnitConvertor(297, Unit::Mm, paperUnit); height = VAbstractMeasurements::UnitConvertor(420, Unit::Mm, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::A4: - SetAutoCrop(false); - SetSaveLength(false); + SetAdditionalOptions(false); width = VAbstractMeasurements::UnitConvertor(210, Unit::Mm, paperUnit); height = VAbstractMeasurements::UnitConvertor(297, Unit::Mm, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Letter: - SetAutoCrop(false); - SetSaveLength(false); + SetAdditionalOptions(false); width = VAbstractMeasurements::UnitConvertor(8.5, Unit::Inch, paperUnit); height = VAbstractMeasurements::UnitConvertor(11, Unit::Inch, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Legal: - SetAutoCrop(false); - SetSaveLength(false); + SetAdditionalOptions(true); width = VAbstractMeasurements::UnitConvertor(11, Unit::Inch, paperUnit); height = VAbstractMeasurements::UnitConvertor(17, Unit::Inch, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Roll24in: - SetAutoCrop(true); - SetSaveLength(true); + SetAdditionalOptions(true); width = VAbstractMeasurements::UnitConvertor(24, Unit::Inch, paperUnit); height = VAbstractMeasurements::UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Roll30in: - SetAutoCrop(true); - SetSaveLength(true); + SetAdditionalOptions(true); width = VAbstractMeasurements::UnitConvertor(30, Unit::Inch, paperUnit); height = VAbstractMeasurements::UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Roll36in: - SetAutoCrop(true); - SetSaveLength(true); + SetAdditionalOptions(true); width = VAbstractMeasurements::UnitConvertor(36, Unit::Inch, paperUnit); height = VAbstractMeasurements::UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Roll42in: - SetAutoCrop(true); - SetSaveLength(true); + SetAdditionalOptions(true); width = VAbstractMeasurements::UnitConvertor(42, Unit::Inch, paperUnit); height = VAbstractMeasurements::UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); return QSizeF(width, height); case PaperSizeTemplate::Roll44in: - SetAutoCrop(true); - SetSaveLength(true); + SetAdditionalOptions(true); width = VAbstractMeasurements::UnitConvertor(44, Unit::Inch, paperUnit); height = VAbstractMeasurements::UnitConvertor(QIMAGE_MAX, Unit::Px, paperUnit); @@ -620,6 +621,7 @@ void DialogLayoutSettings::ReadSettings() SetIncrease(qApp->getSettings()->GetLayoutRotationIncrease()); SetAutoCrop(qApp->getSettings()->GetLayoutAutoCrop()); SetSaveLength(qApp->getSettings()->GetLayoutSaveLength()); + SetUnitePages(qApp->getSettings()->GetLayoutUnitePages()); } //--------------------------------------------------------------------------------------------------------------------- @@ -634,6 +636,7 @@ void DialogLayoutSettings::WriteSettings() const qApp->getSettings()->SetLayoutRotationIncrease(GetIncrease()); qApp->getSettings()->SetLayoutAutoCrop(GetAutoCrop()); qApp->getSettings()->SetLayoutSaveLength(IsSaveLength()); + qApp->getSettings()->SetLayoutUnitePages(IsUnitePages()); } //--------------------------------------------------------------------------------------------------------------------- @@ -649,3 +652,11 @@ void DialogLayoutSettings::SheetSize(const QSizeF &size) CorrectPaperDecimals(); PaperSizeChanged(); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::SetAdditionalOptions(bool value) +{ + SetAutoCrop(value); + SetSaveLength(value); + SetUnitePages(value); +} diff --git a/src/app/dialogs/app/dialoglayoutsettings.h b/src/app/dialogs/app/dialoglayoutsettings.h index 0eeebe5f5..4a90958ed 100644 --- a/src/app/dialogs/app/dialoglayoutsettings.h +++ b/src/app/dialogs/app/dialoglayoutsettings.h @@ -76,6 +76,9 @@ public: bool IsSaveLength() const; void SetSaveLength(bool save); + bool IsUnitePages() const; + void SetUnitePages(bool save); + public slots: void ConvertPaperSize(); void ConvertLayoutSize(); @@ -113,6 +116,7 @@ private: void WriteSettings() const; void SheetSize(const QSizeF &size); + void SetAdditionalOptions(bool value); }; #endif // DIALOGLAYOUTSETTINGS_H diff --git a/src/app/dialogs/app/dialoglayoutsettings.ui b/src/app/dialogs/app/dialoglayoutsettings.ui index 670e44e4a..04adfb2d3 100644 --- a/src/app/dialogs/app/dialoglayoutsettings.ui +++ b/src/app/dialogs/app/dialoglayoutsettings.ui @@ -7,7 +7,7 @@ 0 0 661 - 317 + 345 @@ -205,6 +205,13 @@ + + + + Unite pages (if possible) + + + diff --git a/src/app/mainwindowsnogui.cpp b/src/app/mainwindowsnogui.cpp index 4b543ac75..09d37b19b 100644 --- a/src/app/mainwindowsnogui.cpp +++ b/src/app/mainwindowsnogui.cpp @@ -104,6 +104,10 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked) CleanLayout(); papers = lGenerator.GetPapersItems();// Blank sheets details = lGenerator.GetAllDetails();// All details + if (lGenerator.IsUnitePages()) + { + UnitePages(); + } CreateShadows(); CreateScenes(); PrepareSceneList(); @@ -870,3 +874,90 @@ int MainWindowsNoGUI::ContinueIfLayoutStale() msgBox.exec(); return msgBox.result(); } + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::UnitePages() +{ + if (papers.size() < 2) + { + return; + } + + QList nPapers; + QList > nDetails; + qreal length = 0; + int j = 0; // papers count + + for (int i = 0; i < papers.size(); ++i) + { + QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); + SCASSERT(paper != nullptr) + if (length + paper->rect().height() <= QIMAGE_MAX) + { + UniteDetails(j, nDetails, length, i); + length += paper->rect().height(); + UnitePapers(j, nPapers, paper->rect().width(), length); + } + else + { + length = 0; // Strat new paper + ++j;// New paper + UniteDetails(j, nDetails, length, i); + length += paper->rect().height(); + UnitePapers(j, nPapers, paper->rect().width(), length); + } + } + + qDeleteAll (papers); + papers.clear(); + papers = nPapers; + + details.clear(); + details = nDetails; +} + +//--------------------------------------------------------------------------------------------------------------------- +QList MainWindowsNoGUI::MoveDetails(qreal length, const QList &details) +{ + if (qFuzzyCompare(length+1, 0+1)) + { + return details; + } + + for (int i = 0; i < details.size(); ++i) + { + details.at(i)->moveBy(0, length); + } + + return details; +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::UnitePapers(int j, QList &nPapers, qreal width, qreal length) +{ + if ((j == 0 && nPapers.isEmpty()) || j >= nPapers.size()) + {//First or new paper in list + QGraphicsRectItem *paper = new QGraphicsRectItem(0, 0, width, length); + paper->setPen(QPen(Qt::black, 1)); + paper->setBrush(QBrush(Qt::white)); + nPapers.insert(j, paper); + } + else + {// Avoid memory leak + QGraphicsRectItem *paper = qgraphicsitem_cast(nPapers.at(j)); + paper->setRect(0, 0, width, length); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindowsNoGUI::UniteDetails(int j, QList > &nDetails, qreal length, int i) +{ + if ((j == 0 && nDetails.isEmpty()) || j >= nDetails.size()) + {//First or new details in paper + nDetails.insert(j, MoveDetails(length, details.at(i))); + } + else + { + nDetails[j].append(MoveDetails(length, details.at(i))); + } +} diff --git a/src/app/mainwindowsnogui.h b/src/app/mainwindowsnogui.h index 9721041ca..9c5625642 100644 --- a/src/app/mainwindowsnogui.h +++ b/src/app/mainwindowsnogui.h @@ -121,6 +121,11 @@ private: QString FileName() const; int ContinueIfLayoutStale(); + + void UnitePages(); + QList MoveDetails(qreal length, const QList &details); + void UnitePapers(int j, QList &nPapers, qreal width, qreal length); + void UniteDetails(int j, QList > &nDetails, qreal length, int i); }; #endif // MAINWINDOWSNOGUI_H diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 1b9c350a5..894498570 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -40,7 +40,7 @@ VLayoutGenerator::VLayoutGenerator(QObject *parent) :QObject(parent), papers(QVector()), bank(new VBank()), paperHeight(0), paperWidth(0), stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true), rotationIncrease(180), - autoCrop(false), saveLength(false) + autoCrop(false), saveLength(false), unitePages(false) {} //--------------------------------------------------------------------------------------------------------------------- @@ -190,6 +190,18 @@ void VLayoutGenerator::Abort() #endif } +//--------------------------------------------------------------------------------------------------------------------- +bool VLayoutGenerator::IsUnitePages() const +{ + return unitePages; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::SetUnitePages(bool value) +{ + unitePages = value; +} + //--------------------------------------------------------------------------------------------------------------------- bool VLayoutGenerator::IsSaveLength() const { diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 93a6d681e..43c158818 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -79,6 +79,9 @@ public: bool IsSaveLength() const; void SetSaveLength(bool value); + bool IsUnitePages() const; + void SetUnitePages(bool value); + signals: void Start(); void Arranged(int count); @@ -101,6 +104,7 @@ private: int rotationIncrease; bool autoCrop; bool saveLength; + bool unitePages; void CheckDetailsSize(); };