From c476d4b96ac68c6b73212c8e8e10b8d53824536f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 28 Nov 2020 09:10:56 +0200 Subject: [PATCH 01/21] Clean status message after load of a pattern. --- src/app/valentina/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index d883cf8f6..43aef027d 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -5279,6 +5279,7 @@ bool MainWindow::LoadPattern(QString fileName, const QString& customMeasureFile) ActionDraw(true); qApp->setOpeningPattern();// End opening file + m_statusLabel->setText(QString()); return true; } else From 40fb6e69007a4830e71dbcaa57a9e5b89587945a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 4 Dec 2020 09:24:31 +0200 Subject: [PATCH 02/21] New option Reset label position. --- ChangeLog.txt | 1 + src/app/valentina/xml/vpattern.cpp | 16 ++++++++-------- .../drawTools/operation/vabstractoperation.h | 2 +- .../toolpoint/tooldoublepoint/vtooltruedarts.h | 4 ++-- .../toolpoint/toolsinglepoint/vtoolbasepoint.h | 4 ++-- .../toolpoint/toolsinglepoint/vtoolsinglepoint.h | 4 ++-- .../tools/drawTools/toolpoint/vabstractpoint.h | 2 -- src/libs/vtools/tools/drawTools/vdrawtool.cpp | 7 +++++++ src/libs/vtools/tools/drawTools/vdrawtool.h | 9 +++++++++ src/libs/vtools/tools/toolsdef.h | 4 ++++ 10 files changed, 36 insertions(+), 17 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 045473ba3..012787a6f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -4,6 +4,7 @@ - Fix incorrect nesting status for valid cases. - Improve crossing check for the layout algorithm. - Fix crash after creating an elliptical arc. +- New option Reset label position. # Version 0.7.40 Nov 23, 2020 - New function Warning. diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 072fa2379..ebb976f53 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -1175,8 +1175,8 @@ void VPattern::PointsCommonAttributes(const QDomElement &domElement, VToolSingle void VPattern::PointsCommonAttributes(const QDomElement &domElement, quint32 &id, qreal &mx, qreal &my) { ToolsCommonAttributes(domElement, id); - mx = qApp->toPixel(GetParametrDouble(domElement, AttrMx, QStringLiteral("10.0"))); - my = qApp->toPixel(GetParametrDouble(domElement, AttrMy, QStringLiteral("15.0"))); + mx = qApp->toPixel(GetParametrDouble(domElement, AttrMx, QString::number(labelMX))); + my = qApp->toPixel(GetParametrDouble(domElement, AttrMy, QString::number(labelMY))); } //--------------------------------------------------------------------------------------------------------------------- @@ -1184,8 +1184,8 @@ void VPattern::DrawPointsCommonAttributes(const QDomElement &domElement, quint32 QString ¬es) { DrawToolsCommonAttributes(domElement, id, notes); - mx = qApp->toPixel(GetParametrDouble(domElement, AttrMx, QStringLiteral("10.0"))); - my = qApp->toPixel(GetParametrDouble(domElement, AttrMy, QStringLiteral("15.0"))); + mx = qApp->toPixel(GetParametrDouble(domElement, AttrMx, QString::number(labelMX))); + my = qApp->toPixel(GetParametrDouble(domElement, AttrMy, QString::number(labelMY))); } //--------------------------------------------------------------------------------------------------------------------- @@ -2459,13 +2459,13 @@ void VPattern::ParseToolTrueDarts(VMainGraphicsScene *scene, const QDomElement & initData.dartP3Id = GetParametrUInt(domElement, AttrDartP3, NULL_ID_STR); initData.name1 = GetParametrString(domElement, AttrName1, QChar('A')); - initData.mx1 = qApp->toPixel(GetParametrDouble(domElement, AttrMx1, QStringLiteral("10.0"))); - initData.my1 = qApp->toPixel(GetParametrDouble(domElement, AttrMy1, QStringLiteral("15.0"))); + initData.mx1 = qApp->toPixel(GetParametrDouble(domElement, AttrMx1, QString::number(labelMX))); + initData.my1 = qApp->toPixel(GetParametrDouble(domElement, AttrMy1, QString::number(labelMY))); initData.showLabel1 = GetParametrBool(domElement, AttrShowLabel1, trueStr); initData.name2 = GetParametrString(domElement, AttrName2, QChar('A')); - initData.mx2 = qApp->toPixel(GetParametrDouble(domElement, AttrMx2, QStringLiteral("10.0"))); - initData.my2 = qApp->toPixel(GetParametrDouble(domElement, AttrMy2, QStringLiteral("15.0"))); + initData.mx2 = qApp->toPixel(GetParametrDouble(domElement, AttrMx2, QString::number(labelMX))); + initData.my2 = qApp->toPixel(GetParametrDouble(domElement, AttrMy2, QString::number(labelMY))); initData.showLabel2 = GetParametrBool(domElement, AttrShowLabel2, trueStr); VToolTrueDarts::Create(initData); diff --git a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h index 87c897fda..addd73c68 100644 --- a/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h +++ b/src/libs/vtools/tools/drawTools/operation/vabstractoperation.h @@ -152,7 +152,7 @@ protected: virtual void ReadToolAttributes(const QDomElement &domElement) override; virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj) override; - void UpdateNamePosition(quint32 id, const QPointF &pos); + virtual void UpdateNamePosition(quint32 id, const QPointF &pos) override; void SaveSourceDestination(QDomElement &tag); template diff --git a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h index 0d97b7505..5d62bf281 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/tooldoublepoint/vtooltruedarts.h @@ -56,8 +56,8 @@ struct VToolTrueDartsInitData : VDrawToolInitData dartP2Id(NULL_ID), dartP3Id(NULL_ID), name1(), - mx1(10), - my1(15), + mx1(labelMX), + my1(labelMY), showLabel1(true), name2(), mx2(10), diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h index 1b8bfbffe..5a778b7a6 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolbasepoint.h @@ -50,8 +50,8 @@ struct VToolBasePointInitData : VToolSinglePointInitData VToolBasePointInitData() : VToolSinglePointInitData(), nameActivPP(), - x(10), - y(10) + x(labelMX), + y(labelMY) {} QString nameActivPP; diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h index 8a14e8cb0..926a0b20e 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/vtoolsinglepoint.h @@ -49,8 +49,8 @@ struct VToolSinglePointInitData : VDrawToolInitData VToolSinglePointInitData() : VDrawToolInitData(), name(), - mx(5), - my(10), + mx(labelMX), + my(labelMY), showLabel(true) {} diff --git a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h index e78ac1799..50b8f47c8 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h +++ b/src/libs/vtools/tools/drawTools/toolpoint/vabstractpoint.h @@ -68,8 +68,6 @@ public slots: protected: void SetPointName(quint32 id, const QString &name); - virtual void UpdateNamePosition(quint32 id, const QPointF &pos)=0; - template static void InitToolConnections(VMainGraphicsScene *scene, T *tool); diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.cpp b/src/libs/vtools/tools/drawTools/vdrawtool.cpp index 9da4faddb..e0bcde203 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.cpp +++ b/src/libs/vtools/tools/drawTools/vdrawtool.cpp @@ -185,6 +185,13 @@ QString VDrawTool::MakeToolTip() const return QString(); } +//--------------------------------------------------------------------------------------------------------------------- +void VDrawTool::UpdateNamePosition(quint32 id, const QPointF &pos) +{ + Q_UNUSED(id) + Q_UNUSED(pos) +} + //--------------------------------------------------------------------------------------------------------------------- bool VDrawTool::CorrectDisable(bool disable, const QString &namePP) const { diff --git a/src/libs/vtools/tools/drawTools/vdrawtool.h b/src/libs/vtools/tools/drawTools/vdrawtool.h index b64576135..37d943bdd 100644 --- a/src/libs/vtools/tools/drawTools/vdrawtool.h +++ b/src/libs/vtools/tools/drawTools/vdrawtool.h @@ -52,6 +52,7 @@ #include "../vdatatool.h" #include "../vgeometry/vpointf.h" #include "../vtools/undocommands/undogroup.h" +#include "../toolsdef.h" struct VDrawToolInitData : VAbstractToolInitData { @@ -120,6 +121,7 @@ protected: void SaveOption(QSharedPointer &obj); virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); virtual QString MakeToolTip() const; + virtual void UpdateNamePosition(quint32 id, const QPointF &pos); bool CorrectDisable(bool disable, const QString &namePP) const; @@ -241,6 +243,9 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI actionShowLabel->setVisible(false); } + QAction *actionRestoreLabelPosition = menu.addAction(VDrawTool::tr("Restore label position")); + actionRestoreLabelPosition->setVisible(itemType == GOType::Point); + QAction *actionRemove = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), VDrawTool::tr("Delete")); if (showRemove == RemoveOption::Enable) { @@ -299,6 +304,10 @@ void VDrawTool::ContextMenu(QGraphicsSceneContextMenuEvent *event, quint32 itemI { ChangeLabelVisibility(itemId, selectedAction->isChecked()); } + else if (selectedAction == actionRestoreLabelPosition) + { + UpdateNamePosition(itemId, QPointF(labelMX, labelMY)); + } else if (selectedAction->actionGroup() == actionsAddToGroup) { quint32 groupId = selectedAction->data().toUInt(); diff --git a/src/libs/vtools/tools/toolsdef.h b/src/libs/vtools/tools/toolsdef.h index cf144504b..52a849942 100644 --- a/src/libs/vtools/tools/toolsdef.h +++ b/src/libs/vtools/tools/toolsdef.h @@ -47,6 +47,10 @@ struct SourceItem Q_DECLARE_METATYPE(SourceItem) Q_DECLARE_TYPEINFO(SourceItem, Q_MOVABLE_TYPE); +// Default label position +const int labelMX = 10; +const int labelMY = 15; + QVector SourceToObjects(const QVector &source); QString OriginAlias(quint32 id, const QVector &source, const QSharedPointer &obj); From 5222a53bb1a7dcb8887695d6cff844a0f846050a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 4 Dec 2020 09:29:50 +0200 Subject: [PATCH 03/21] Lupdate. --- share/translations/valentina.ts | 4 ++ share/translations/valentina_cs_CZ.ts | 6 ++- share/translations/valentina_de_DE.ts | 6 ++- share/translations/valentina_el_GR.ts | 4 ++ share/translations/valentina_en_CA.ts | 4 ++ share/translations/valentina_en_IN.ts | 4 ++ share/translations/valentina_en_US.ts | 4 ++ share/translations/valentina_es_ES.ts | 6 ++- share/translations/valentina_fi_FI.ts | 4 ++ share/translations/valentina_fr_FR.ts | 4 ++ share/translations/valentina_he_IL.ts | 4 ++ share/translations/valentina_id_ID.ts | 4 ++ share/translations/valentina_it_IT.ts | 4 ++ share/translations/valentina_nl_NL.ts | 6 ++- share/translations/valentina_pl_PL.ts | 56 ++++++++++++++++++++------- share/translations/valentina_pt_BR.ts | 4 ++ share/translations/valentina_ro_RO.ts | 4 ++ share/translations/valentina_ru_RU.ts | 8 +++- share/translations/valentina_uk_UA.ts | 4 ++ share/translations/valentina_zh_CN.ts | 4 ++ 20 files changed, 124 insertions(+), 20 deletions(-) diff --git a/share/translations/valentina.ts b/share/translations/valentina.ts index e66163bea..f50db270e 100644 --- a/share/translations/valentina.ts +++ b/share/translations/valentina.ts @@ -14009,6 +14009,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_cs_CZ.ts b/share/translations/valentina_cs_CZ.ts index f3474211d..0a7e5e089 100644 --- a/share/translations/valentina_cs_CZ.ts +++ b/share/translations/valentina_cs_CZ.ts @@ -13585,6 +13585,10 @@ Chcete uložit změny? Show label Ukázat popis + + Restore label position + + VException @@ -15132,7 +15136,7 @@ Chcete uložit změny? Point of intersection circle and segment - Průsečík kruhu a části + Průsečík kruhu a části diff --git a/share/translations/valentina_de_DE.ts b/share/translations/valentina_de_DE.ts index ff79e4dd5..616fdb532 100644 --- a/share/translations/valentina_de_DE.ts +++ b/share/translations/valentina_de_DE.ts @@ -13579,6 +13579,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException @@ -15090,7 +15094,7 @@ Do you want to save your changes? Point of intersection circle and segment - Punkt am Schnittpunkt von Kreis und Abschnitt + Punkt am Schnittpunkt von Kreis und Abschnitt diff --git a/share/translations/valentina_el_GR.ts b/share/translations/valentina_el_GR.ts index 7f861a189..d57afdb9f 100644 --- a/share/translations/valentina_el_GR.ts +++ b/share/translations/valentina_el_GR.ts @@ -13124,6 +13124,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_en_CA.ts b/share/translations/valentina_en_CA.ts index 11fba5c88..d1d49ad6c 100644 --- a/share/translations/valentina_en_CA.ts +++ b/share/translations/valentina_en_CA.ts @@ -13576,6 +13576,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_en_IN.ts b/share/translations/valentina_en_IN.ts index 421016a01..46b24791b 100644 --- a/share/translations/valentina_en_IN.ts +++ b/share/translations/valentina_en_IN.ts @@ -13576,6 +13576,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_en_US.ts b/share/translations/valentina_en_US.ts index bae286416..cb76688d8 100644 --- a/share/translations/valentina_en_US.ts +++ b/share/translations/valentina_en_US.ts @@ -13576,6 +13576,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_es_ES.ts b/share/translations/valentina_es_ES.ts index b4aaf5c7c..60ea871d4 100644 --- a/share/translations/valentina_es_ES.ts +++ b/share/translations/valentina_es_ES.ts @@ -13583,6 +13583,10 @@ Quieres guardar los cambios? Show label Mostrar estiqueta + + Restore label position + + VException @@ -15130,7 +15134,7 @@ Quieres guardar los cambios? Point of intersection circle and segment - Punto de intersección circulo y segmento + Punto de intersección circulo y segmento diff --git a/share/translations/valentina_fi_FI.ts b/share/translations/valentina_fi_FI.ts index 0557f20cf..c91ffc702 100644 --- a/share/translations/valentina_fi_FI.ts +++ b/share/translations/valentina_fi_FI.ts @@ -12093,6 +12093,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_fr_FR.ts b/share/translations/valentina_fr_FR.ts index 4260f879d..3171357e6 100644 --- a/share/translations/valentina_fr_FR.ts +++ b/share/translations/valentina_fr_FR.ts @@ -13547,6 +13547,10 @@ Voulez-vous enregistrer les changements? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_he_IL.ts b/share/translations/valentina_he_IL.ts index 61912f7eb..eeba92571 100644 --- a/share/translations/valentina_he_IL.ts +++ b/share/translations/valentina_he_IL.ts @@ -10826,6 +10826,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_id_ID.ts b/share/translations/valentina_id_ID.ts index 6ff38ce7a..6274d4f30 100644 --- a/share/translations/valentina_id_ID.ts +++ b/share/translations/valentina_id_ID.ts @@ -11210,6 +11210,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_it_IT.ts b/share/translations/valentina_it_IT.ts index 50133b77f..b37c32b59 100644 --- a/share/translations/valentina_it_IT.ts +++ b/share/translations/valentina_it_IT.ts @@ -13492,6 +13492,10 @@ Vuoi salvare le tue modifiche? Show label Mostra etichetta + + Restore label position + + VException diff --git a/share/translations/valentina_nl_NL.ts b/share/translations/valentina_nl_NL.ts index 5c95733b9..689efecaa 100644 --- a/share/translations/valentina_nl_NL.ts +++ b/share/translations/valentina_nl_NL.ts @@ -13582,6 +13582,10 @@ Wil je deze veranderingen opslaan? Show label Vertoon label + + Restore label position + + VException @@ -15129,7 +15133,7 @@ Wil je deze veranderingen opslaan? Point of intersection circle and segment - Kruispunt van cirkel en segment + Kruispunt van cirkel en segment diff --git a/share/translations/valentina_pl_PL.ts b/share/translations/valentina_pl_PL.ts index 78c410684..efb897cfe 100644 --- a/share/translations/valentina_pl_PL.ts +++ b/share/translations/valentina_pl_PL.ts @@ -12254,6 +12254,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException @@ -15264,27 +15268,27 @@ Do you want to save your changes? Select all - + Zaznaczono wszystko Select none - + Zaznaczenie jest puste select all details - + wybrano wszystkie szczegóły select none details - + nie wybrano szczegółów Invert selection - + Odwróć zaznaczenie invert selection - + Odwróć zaznaczenie Hide not in layout @@ -15655,7 +15659,19 @@ Do you want to save your changes? INFO: - + INFORMACJA: + + + Warning. + Ostrzeżenie. + + + Critical error. + Błąd krytyczny. + + + Fatal error. + Błąd krytyczny. Information. @@ -15663,15 +15679,15 @@ Do you want to save your changes? Warning - + Ostrzeżenie Critical error - + Błąd krytyczny Fatal error - + Błąd krytyczny Information @@ -15698,7 +15714,19 @@ Do you want to save your changes? INFO: - + INFORMACJA: + + + Warning. + Ostrzeżenie. + + + Critical error. + Błąd krytyczny. + + + Fatal error. + Błąd krytyczny. Information. @@ -15706,15 +15734,15 @@ Do you want to save your changes? Warning - + Ostrzeżenie Critical error - + Błąd krytyczny Fatal error - + Błąd krytyczny Information diff --git a/share/translations/valentina_pt_BR.ts b/share/translations/valentina_pt_BR.ts index 9238ec4a2..6f0c1d5dd 100644 --- a/share/translations/valentina_pt_BR.ts +++ b/share/translations/valentina_pt_BR.ts @@ -13507,6 +13507,10 @@ Deseja salvar suas mudanças? Show label Mostrar rótulo + + Restore label position + + VException diff --git a/share/translations/valentina_ro_RO.ts b/share/translations/valentina_ro_RO.ts index 9ee276396..5b62254d1 100644 --- a/share/translations/valentina_ro_RO.ts +++ b/share/translations/valentina_ro_RO.ts @@ -11975,6 +11975,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_ru_RU.ts b/share/translations/valentina_ru_RU.ts index a260eacc1..44ac34199 100644 --- a/share/translations/valentina_ru_RU.ts +++ b/share/translations/valentina_ru_RU.ts @@ -8870,7 +8870,7 @@ Do you want to save your changes? The measurements file <br/><br/> <b>%1</b> <br/><br/> could not be found. Do you want to update the file location? - Файл меток <br/><br/> <b>%1</b> <br/><br/> не найден. Вы хотите обновить данные о местоположении файла? + Файл мерок <br/><br/> <b>%1</b> <br/><br/> не найден. Вы хотите обновить данные о местоположении файла? Flipping objects by line @@ -13584,6 +13584,10 @@ Do you want to save your changes? Show label Показать метку + + Restore label position + + VException @@ -15131,7 +15135,7 @@ Do you want to save your changes? Point of intersection circle and segment - Точка пересечения окружности и отрезка + Точка пересечения окружности и отрезка diff --git a/share/translations/valentina_uk_UA.ts b/share/translations/valentina_uk_UA.ts index c2c4c9580..8bb0bc332 100644 --- a/share/translations/valentina_uk_UA.ts +++ b/share/translations/valentina_uk_UA.ts @@ -13575,6 +13575,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException diff --git a/share/translations/valentina_zh_CN.ts b/share/translations/valentina_zh_CN.ts index f14ac728d..2e85744ca 100644 --- a/share/translations/valentina_zh_CN.ts +++ b/share/translations/valentina_zh_CN.ts @@ -11039,6 +11039,10 @@ Do you want to save your changes? Show label + + Restore label position + + VException From 700209736295535b7be24e9974238b1aa5f3309b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 4 Dec 2020 09:39:13 +0200 Subject: [PATCH 04/21] Bump version. --- ChangeLog.txt | 2 +- appveyor.yml | 2 +- dist/OBS_debian/debian.changelog | 4 ++-- dist/debian/changelog | 4 ++-- dist/macx/tape/Info.plist | 4 ++-- dist/macx/valentina/Info.plist | 4 ++-- dist/rpm/_service | 2 +- dist/rpm/valentina.spec | 2 +- dist/valentina.dsc | 8 ++++---- share/bintray.json | 4 ++-- src/libs/vmisc/projectversion.cpp | 2 +- src/libs/vmisc/projectversion.h | 4 ++-- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 012787a6f..84076e2d2 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,4 @@ -# Version 0.7.41 (unreleased) +# Version 0.7.41 Dec 4, 2020 - Bug fixes. - Improve canceling nesting. - Fix incorrect nesting status for valid cases. diff --git a/appveyor.yml b/appveyor.yml index 1bb07c3f5..19870dbc7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -258,7 +258,7 @@ deploy: package: valentina-win_auto-upload publish: true override: true - version: 0.7.40 + version: 0.7.41 on: DEPLOY: true artifact: valentina-win-$(QT_VERSION)-$(APPVEYOR_REPO_BRANCH)-$(APPVEYOR_REPO_COMMIT) diff --git a/dist/OBS_debian/debian.changelog b/dist/OBS_debian/debian.changelog index edd174349..79acafc8a 100644 --- a/dist/OBS_debian/debian.changelog +++ b/dist/OBS_debian/debian.changelog @@ -1,5 +1,5 @@ -valentina (0.7.40) trusty; urgency=low +valentina (0.7.41) trusty; urgency=low * Auto build. - -- dismine Mon, 23 Nov 2020 16:30:00 +0300 + -- dismine Fri, 4 Dec 2020 16:30:00 +0300 diff --git a/dist/debian/changelog b/dist/debian/changelog index edd174349..79acafc8a 100644 --- a/dist/debian/changelog +++ b/dist/debian/changelog @@ -1,5 +1,5 @@ -valentina (0.7.40) trusty; urgency=low +valentina (0.7.41) trusty; urgency=low * Auto build. - -- dismine Mon, 23 Nov 2020 16:30:00 +0300 + -- dismine Fri, 4 Dec 2020 16:30:00 +0300 diff --git a/dist/macx/tape/Info.plist b/dist/macx/tape/Info.plist index c1d416b42..ea104b019 100755 --- a/dist/macx/tape/Info.plist +++ b/dist/macx/tape/Info.plist @@ -19,9 +19,9 @@ CFBundleIdentifier io.bitbucket.valentinaproject.@EXECUTABLE@ CFBundleShortVersionString - 0.7.40 + 0.7.41 CFBundleVersion - 0.7.40.0 + 0.7.41.0 CFBundleInfoDictionaryVersion 6.0 CFBundleDocumentTypes diff --git a/dist/macx/valentina/Info.plist b/dist/macx/valentina/Info.plist index ec361f021..338d86d41 100755 --- a/dist/macx/valentina/Info.plist +++ b/dist/macx/valentina/Info.plist @@ -19,9 +19,9 @@ CFBundleIdentifier io.bitbucket.valentinaproject.@EXECUTABLE@ CFBundleShortVersionString - 0.7.40 + 0.7.41 CFBundleVersion - 0.7.40.0 + 0.7.41.0 CFBundleInfoDictionaryVersion 6.0 CFBundleDocumentTypes diff --git a/dist/rpm/_service b/dist/rpm/_service index e371343cc..27989e6e9 100644 --- a/dist/rpm/_service +++ b/dist/rpm/_service @@ -1,7 +1,7 @@ git://github.com/dismine/Valentina_git.git - 0.7.40 + 0.7.41 valentina git .git diff --git a/dist/rpm/valentina.spec b/dist/rpm/valentina.spec index 82cb728b0..459fb1125 100644 --- a/dist/rpm/valentina.spec +++ b/dist/rpm/valentina.spec @@ -91,7 +91,7 @@ Requires: poppler-tools Requires: poppler-utils %endif -Version: 0.7.40 +Version: 0.7.41 Release: 0 URL: https://gitlab.com/smart-pattern/valentina License: GPL-3.0+ diff --git a/dist/valentina.dsc b/dist/valentina.dsc index ea0093594..e99e6fba8 100644 --- a/dist/valentina.dsc +++ b/dist/valentina.dsc @@ -2,7 +2,7 @@ Format: 3.0 (native) Source: valentina Binary: valentina Architecture: i386 amd64 -Version: 0.7.40 +Version: 0.7.41 Maintainer: Roman Telezhynskyi Homepage: https://valentinaproject.bitbucket.io Standards-Version: 3.9.5 @@ -18,8 +18,8 @@ Build-Depends: debhelper (>= 8.0.0), Package-List: valentina deb graphics optional Checksums-Sha1: - 581eb1bf36b4ab7126b5983d809130f15396859e 24838101 valentina_0.7.40.tar + 581eb1bf36b4ab7126b5983d809130f15396859e 24838101 valentina_0.7.41.tar Checksums-Sha256: - 9b156c7120a69b90373efb8ca9998c3e0563a60ad337210166cfd41b00b0f13c 24838101 valentina_0.7.40.tar + 9b156c7120a69b90373efb8ca9998c3e0563a60ad337210166cfd41b00b0f13c 24838101 valentina_0.7.41.tar Files: - 95677e29d3a59cf5b064f7be236a4b78 24838101 valentina_0.7.40.tar + 95677e29d3a59cf5b064f7be236a4b78 24838101 valentina_0.7.41.tar diff --git a/share/bintray.json b/share/bintray.json index 95e7731a9..c9d992a46 100644 --- a/share/bintray.json +++ b/share/bintray.json @@ -17,8 +17,8 @@ "version": { "name": "0.7.40", "desc": "Test branch release", - "released": "2020-11-23", - "vcs_tag": "v0.7.40", + "released": "2020-12-4", + "vcs_tag": "v0.7.41", "gpgSign": false }, diff --git a/src/libs/vmisc/projectversion.cpp b/src/libs/vmisc/projectversion.cpp index 448a121c3..724d471a7 100644 --- a/src/libs/vmisc/projectversion.cpp +++ b/src/libs/vmisc/projectversion.cpp @@ -42,7 +42,7 @@ extern const int MAJOR_VERSION = 0; extern const int MINOR_VERSION = 7; -extern const int DEBUG_VERSION = 40; +extern const int DEBUG_VERSION = 41; extern const QString APP_VERSION_STR(QStringLiteral("%1.%2.%3.%4").arg(MAJOR_VERSION).arg(MINOR_VERSION) .arg(DEBUG_VERSION).arg(LATEST_TAG_DISTANCE)); diff --git a/src/libs/vmisc/projectversion.h b/src/libs/vmisc/projectversion.h index eb6e33253..1913b929d 100644 --- a/src/libs/vmisc/projectversion.h +++ b/src/libs/vmisc/projectversion.h @@ -49,8 +49,8 @@ extern const QString APP_VERSION_STR; // Change version number in projectversion.cpp too. // Synchronize valentina.nsi -#define VER_FILEVERSION 0,7,40 -#define VER_FILEVERSION_STR "0.7.40\0" +#define VER_FILEVERSION 0,7,41 +#define VER_FILEVERSION_STR "0.7.41\0" #define V_PRERELEASE // Mark prerelease builds From 8d36b8329a65ac70ba2a0f3f98a18518a8bf846b Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 5 Dec 2020 12:34:57 +0200 Subject: [PATCH 05/21] Correct version for bintray. --- share/bintray.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/bintray.json b/share/bintray.json index c9d992a46..ffedeee9e 100644 --- a/share/bintray.json +++ b/share/bintray.json @@ -15,7 +15,7 @@ }, "version": { - "name": "0.7.40", + "name": "0.7.41", "desc": "Test branch release", "released": "2020-12-4", "vcs_tag": "v0.7.41", From dc350ae0e217939a918cac7990fe0e9f387d7950 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 5 Dec 2020 12:36:40 +0200 Subject: [PATCH 06/21] Fix export of pattern recipe. --- ChangeLog.txt | 3 + src/app/valentina/mainwindow.cpp | 2 +- src/app/valentina/xml/vpattern.cpp | 41 ++++++++++++ src/app/valentina/xml/vpattern.h | 5 +- src/libs/ifc/xml/vabstractpattern.cpp | 13 ++++ src/libs/ifc/xml/vabstractpattern.h | 3 + src/libs/vformat/vpatternrecipe.cpp | 95 +++++++++++++++++---------- src/libs/vformat/vpatternrecipe.h | 17 +++-- 8 files changed, 135 insertions(+), 44 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 84076e2d2..33c1ada6c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,6 @@ +# Version 0.7.42 (unreleased) +- Fix export of pattern recipe. + # Version 0.7.41 Dec 4, 2020 - Bug fixes. - Improve canceling nesting. diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 43aef027d..f18988a76 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4768,7 +4768,7 @@ void MainWindow::CreateActions() return; } - VPatternRecipe recipe(pattern, doc); + VPatternRecipe recipe(doc); QString error; if (not recipe.SaveDocument(fileName, error)) { diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index ebb976f53..ac8a880db 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -347,6 +347,41 @@ VContainer VPattern::GetCompleteData() const return lastData; } +//--------------------------------------------------------------------------------------------------------------------- +VContainer VPattern::GetCompletePPData(const QString &name) const +{ + const int countPP = CountPP(); + if (countPP <= 0 || history.isEmpty() || tools.isEmpty()) + { + return (data != nullptr ? *data : VContainer(nullptr, nullptr, VContainer::UniqueNamespace())); + } + + const quint32 id = (countPP == 1 ? history.last().getId() : PPLastToolId(name)); + + if (id == NULL_ID) + { + return (data != nullptr ? *data : VContainer(nullptr, nullptr, VContainer::UniqueNamespace())); + } + + try + { + ToolExists(id); + } + catch (VExceptionBadId &e) + { + Q_UNUSED(e) + return (data != nullptr ? *data : VContainer(nullptr, nullptr, VContainer::UniqueNamespace())); + } + + const VDataTool *vTool = tools.value(id); + SCASSERT(vTool != nullptr) + VContainer lastData = vTool->getData(); + //Delete special variables if exist + lastData.RemoveVariable(currentLength); + lastData.RemoveVariable(currentSeamAllowance); + return lastData; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SPointActiveDraw return id base point current pattern peace. @@ -3615,6 +3650,12 @@ quint32 VPattern::LastToolId() const return NULL_ID; } + return PPLastToolId(name); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VPattern::PPLastToolId(const QString &name) const +{ const QVector localHistory = getLocalHistory(name); return (not localHistory.isEmpty() ? localHistory.last().getId() : NULL_ID); diff --git a/src/app/valentina/xml/vpattern.h b/src/app/valentina/xml/vpattern.h index 2045d8964..51cc84c9b 100644 --- a/src/app/valentina/xml/vpattern.h +++ b/src/app/valentina/xml/vpattern.h @@ -58,7 +58,9 @@ public: void setCurrentData(); virtual void UpdateToolData(const quint32 &id, VContainer *data) override; - VContainer GetCompleteData() const; + + virtual VContainer GetCompleteData() const override; + virtual VContainer GetCompletePPData(const QString &name) const override; virtual void IncrementReferens(quint32 id) const override; virtual void DecrementReferens(quint32 id) const override; @@ -256,6 +258,7 @@ private: QString LastDrawName() const; quint32 LastToolId() const; + quint32 PPLastToolId(const QString &name) const; }; #endif // VPATTERN_H diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 4037bb40f..0ec819e8a 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -2442,6 +2442,19 @@ QString VAbstractPattern::PieceDrawName(quint32 id) return draw.attribute(VAbstractPattern::AttrName); } +//--------------------------------------------------------------------------------------------------------------------- +VContainer VAbstractPattern::GetCompleteData() const +{ + return VContainer(nullptr, nullptr, VContainer::UniqueNamespace()); +} + +//--------------------------------------------------------------------------------------------------------------------- +VContainer VAbstractPattern::GetCompletePPData(const QString &name) const +{ + Q_UNUSED(name) + return VContainer(nullptr, nullptr, VContainer::UniqueNamespace()); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VAbstractPattern::FilterGroupTags(const QString &tags) { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 7c008fe82..668b35c98 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -230,6 +230,9 @@ public: QString PieceDrawName(quint32 id); + virtual VContainer GetCompleteData() const; + virtual VContainer GetCompletePPData(const QString &name) const; + static const QString TagPattern; static const QString TagCalculation; static const QString TagModeling; diff --git a/src/libs/vformat/vpatternrecipe.cpp b/src/libs/vformat/vpatternrecipe.cpp index c8f9304b9..3e86d3080 100644 --- a/src/libs/vformat/vpatternrecipe.cpp +++ b/src/libs/vformat/vpatternrecipe.cpp @@ -79,12 +79,10 @@ T *GetPatternTool(quint32 id) } // namespace //--------------------------------------------------------------------------------------------------------------------- -VPatternRecipe::VPatternRecipe(VContainer *data, VAbstractPattern *pattern, QObject *parent) +VPatternRecipe::VPatternRecipe(VAbstractPattern *pattern, QObject *parent) : VDomDocument(parent), - m_data(data), m_pattern(pattern) { - SCASSERT(data != nullptr) SCASSERT(pattern != nullptr) QDomElement recipeElement = createElement(QStringLiteral("recipe")); @@ -135,7 +133,8 @@ QDomElement VPatternRecipe::Measurements() { QDomElement measurements = createElement(QStringLiteral("measurements")); - QList> patternMeasurements = m_data->DataMeasurements().values(); + VContainer data = m_pattern->GetCompleteData(); + QList> patternMeasurements = data.DataMeasurements().values(); // Resore order std::sort(patternMeasurements.begin(), patternMeasurements.end(), @@ -174,7 +173,8 @@ QDomElement VPatternRecipe::Increments() { QDomElement increments = createElement(QStringLiteral("increments")); - QList> patternIncrements = m_data->DataIncrements().values(); + VContainer data = m_pattern->GetCompleteData(); + QList> patternIncrements = data.DataIncrements().values(); // Resore order std::sort(patternIncrements.begin(), patternIncrements.end(), @@ -197,7 +197,8 @@ QDomElement VPatternRecipe::PreviewCalculations() { QDomElement previewCalculations = createElement(QStringLiteral("previewCalculations")); - QList> patternIncrements = m_data->DataIncrements().values(); + VContainer data = m_pattern->GetCompleteData(); + QList> patternIncrements = data.DataIncrements().values(); // Resore order std::sort(patternIncrements.begin(), patternIncrements.end(), @@ -266,12 +267,14 @@ QDomElement VPatternRecipe::Draft(const QDomElement &draft) const QString draftName = draft.attribute(QStringLiteral("name")); SetAttribute(recipeDraft, QStringLiteral("name"), draftName); + VContainer data = m_pattern->GetCompletePPData(draftName); + QVector *history = m_pattern->getHistory(); for (auto &record : *history) { if (record.getNameDraw() == draftName) { - QDomElement step = Step(record); + QDomElement step = Step(record, data); if (not step.isNull()) { recipeDraft.appendChild(step); @@ -283,7 +286,7 @@ QDomElement VPatternRecipe::Draft(const QDomElement &draft) } //--------------------------------------------------------------------------------------------------------------------- -QDomElement VPatternRecipe::Step(const VToolRecord &tool) +QDomElement VPatternRecipe::Step(const VToolRecord &tool, const VContainer &data) { // This check helps to find missed tools in the switch Q_STATIC_ASSERT_X(static_cast(Tool::LAST_ONE_DO_NOT_USE) == 55, "Not all tools were used in history."); @@ -371,13 +374,13 @@ QT_WARNING_DISABLE_GCC("-Wswitch-default") case Tool::EllipticalArc: return EllipticalArc(tool); case Tool::Rotation: - return Rotation(tool); + return Rotation(tool, data); case Tool::FlippingByLine: - return FlippingByLine(tool); + return FlippingByLine(tool, data); case Tool::FlippingByAxis: - return FlippingByAxis(tool); + return FlippingByAxis(tool, data); case Tool::Move: - return Move(tool); + return Move(tool, data); //Because "history" not only show history of pattern, but help restore current data for each pattern's //piece, we need add record about details and nodes, but don't show them. case Tool::Piece: @@ -411,17 +414,18 @@ QDomElement VPatternRecipe::FinalMeasurements() QDomElement recipeFinalMeasurements = createElement(QStringLiteral("finalMeasurements")); const QVector measurements = m_pattern->GetFinalMeasurements(); + VContainer data = m_pattern->GetCompleteData(); for (auto &m : measurements) { - recipeFinalMeasurements.appendChild(FinalMeasurement(m)); + recipeFinalMeasurements.appendChild(FinalMeasurement(m, data)); } return recipeFinalMeasurements; } //--------------------------------------------------------------------------------------------------------------------- -QDomElement VPatternRecipe::FinalMeasurement(const VFinalMeasurement &fm) +QDomElement VPatternRecipe::FinalMeasurement(const VFinalMeasurement &fm, const VContainer &data) { QDomElement recipeFinalMeasurement = createElement(QStringLiteral("finalMeasurement")); @@ -430,7 +434,7 @@ QDomElement VPatternRecipe::FinalMeasurement(const VFinalMeasurement &fm) SetAttribute(recipeFinalMeasurement, QStringLiteral("formula"), fm.formula); // TODO: localize QScopedPointer cal(new Calculator()); - const qreal result = cal->EvalFormula(m_data->DataVariables(), fm.formula); + const qreal result = cal->EvalFormula(data.DataVariables(), fm.formula); if (qIsInf(result) || qIsNaN(result)) { const QString errorMsg = QString("%1\n\n%1").arg(tr("Reading final measurements error."), @@ -1002,7 +1006,7 @@ QDomElement VPatternRecipe::EllipticalArc(const VToolRecord &record) } //--------------------------------------------------------------------------------------------------------------------- -QDomElement VPatternRecipe::Rotation(const VToolRecord &record) +QDomElement VPatternRecipe::Rotation(const VToolRecord &record, const VContainer &data) { auto *tool = GetPatternTool(record.getId()); @@ -1013,13 +1017,13 @@ QDomElement VPatternRecipe::Rotation(const VToolRecord &record) Formula(step, tool->GetFormulaAngle(), AttrAngle, AttrAngleValue); SetAttribute(step, AttrSuffix, tool->Suffix()); - step.appendChild(GroupOperationSource(tool, record.getId())); + step.appendChild(GroupOperationSource(tool, record.getId(), data)); return step; } //--------------------------------------------------------------------------------------------------------------------- -QDomElement VPatternRecipe::FlippingByLine(const VToolRecord &record) +QDomElement VPatternRecipe::FlippingByLine(const VToolRecord &record, const VContainer &data) { auto *tool = GetPatternTool(record.getId()); @@ -1030,13 +1034,13 @@ QDomElement VPatternRecipe::FlippingByLine(const VToolRecord &record) SetAttribute(step, AttrP2Line, tool->SecondLinePointName()); SetAttribute(step, AttrSuffix, tool->Suffix()); - step.appendChild(GroupOperationSource(tool, record.getId())); + step.appendChild(GroupOperationSource(tool, record.getId(), data)); return step; } //--------------------------------------------------------------------------------------------------------------------- -QDomElement VPatternRecipe::FlippingByAxis(const VToolRecord &record) +QDomElement VPatternRecipe::FlippingByAxis(const VToolRecord &record, const VContainer &data) { auto *tool = GetPatternTool(record.getId()); @@ -1047,13 +1051,13 @@ QDomElement VPatternRecipe::FlippingByAxis(const VToolRecord &record) SetAttribute(step, AttrAxisType, static_cast(tool->GetAxisType())); SetAttribute(step, AttrSuffix, tool->Suffix()); - step.appendChild(GroupOperationSource(tool, record.getId())); + step.appendChild(GroupOperationSource(tool, record.getId(), data)); return step; } //--------------------------------------------------------------------------------------------------------------------- -QDomElement VPatternRecipe::Move(const VToolRecord &record) +QDomElement VPatternRecipe::Move(const VToolRecord &record, const VContainer &data) { auto *tool = GetPatternTool(record.getId()); @@ -1066,7 +1070,7 @@ QDomElement VPatternRecipe::Move(const VToolRecord &record) SetAttribute(step, AttrCenter, tool->OriginPointName()); SetAttribute(step, AttrSuffix, tool->Suffix()); - step.appendChild(GroupOperationSource(tool, record.getId())); + step.appendChild(GroupOperationSource(tool, record.getId(), data)); return step; } @@ -1103,7 +1107,7 @@ void VPatternRecipe::CurveAttributes(QDomElement &step, T *tool) SetAttribute(step, AttrPenStyle, tool->GetPenStyle()); SetAttribute(step, AttrAScale, tool->GetApproximationScale()); SetAttribute(step, AttrDuplicate, tool->GetDuplicate()); - SetAttribute(step, AttrAlias, tool->GetAliasSuffix()); + SetAttributeOrRemoveIf(step, AttrAlias, tool->GetAliasSuffix(), tool->GetAliasSuffix().isEmpty()); } @@ -1111,8 +1115,8 @@ void VPatternRecipe::CurveAttributes(QDomElement &step, T *tool) template void VPatternRecipe::CutCurveAttributes(QDomElement &step, T *tool) { - SetAttribute(step, AttrAlias1, tool->GetAliasSuffix1()); - SetAttribute(step, AttrAlias2, tool->GetAliasSuffix2()); + SetAttributeOrRemoveIf(step, AttrAlias1, tool->GetAliasSuffix1(), tool->GetAliasSuffix1().isEmpty()); + SetAttributeOrRemoveIf(step, AttrAlias2, tool->GetAliasSuffix2(), tool->GetAliasSuffix2().isEmpty()); } //--------------------------------------------------------------------------------------------------------------------- @@ -1125,7 +1129,7 @@ inline void VPatternRecipe::ToolAttributes(QDomElement &step, T *tool) } //--------------------------------------------------------------------------------------------------------------------- -QDomElement VPatternRecipe::GroupOperationSource(VAbstractOperation *tool, quint32 id) +QDomElement VPatternRecipe::GroupOperationSource(VAbstractOperation *tool, quint32 id, const VContainer &data) { SCASSERT(tool) @@ -1145,7 +1149,7 @@ QDomElement VPatternRecipe::GroupOperationSource(VAbstractOperation *tool, quint try { - obj = m_data->GetGObject(item.id); + obj = data.GetGObject(item.id); } catch (const VExceptionBadId &e) { @@ -1153,11 +1157,8 @@ QDomElement VPatternRecipe::GroupOperationSource(VAbstractOperation *tool, quint continue; } - SetAttribute(node, AttrItem, obj->name()); - if (not obj->GetAlias().isEmpty()) - { - SetAttribute(node, AttrAlias, obj->GetAlias()); - } + SetAttribute(node, AttrItem, obj->ObjectName()); + SetAttributeOrRemoveIf(node, AttrAlias, item.alias, item.alias.isEmpty()); if (obj->getType() != GOType::Point) { @@ -1172,6 +1173,34 @@ QDomElement VPatternRecipe::GroupOperationSource(VAbstractOperation *tool, quint } } + QT_WARNING_PUSH + QT_WARNING_DISABLE_GCC("-Wswitch-default") + switch(static_cast(obj->getType())) + { + case GOType::Point: + SetAttribute(node, AttrType, QStringLiteral("point")); + break; + case GOType::Arc: + SetAttribute(node, AttrType, QStringLiteral("arc")); + break; + case GOType::EllipticalArc: + SetAttribute(node, AttrType, QStringLiteral("elArc")); + break; + case GOType::Spline: + case GOType::CubicBezier: + SetAttribute(node, AttrType, QStringLiteral("spline")); + break; + case GOType::SplinePath: + case GOType::CubicBezierPath: + SetAttribute(node, AttrType, QStringLiteral("splinePath")); + break; + case GOType::Unknown: + case GOType::PlaceLabel: + Q_UNREACHABLE(); + break; + } + QT_WARNING_POP + nodes.appendChild(node); } diff --git a/src/libs/vformat/vpatternrecipe.h b/src/libs/vformat/vpatternrecipe.h index 890dfe144..8361dd612 100644 --- a/src/libs/vformat/vpatternrecipe.h +++ b/src/libs/vformat/vpatternrecipe.h @@ -43,13 +43,12 @@ class VPatternRecipe : public VDomDocument { Q_DECLARE_TR_FUNCTIONS(VPatternRecipe) public: - VPatternRecipe(VContainer *data, VAbstractPattern *pattern, QObject *parent = nullptr); + explicit VPatternRecipe(VAbstractPattern *pattern, QObject *parent = nullptr); virtual ~VPatternRecipe() Q_DECL_EQ_DEFAULT; private: Q_DISABLE_COPY(VPatternRecipe) - VContainer *m_data; VAbstractPattern *m_pattern; QDomElement Prerequisite(); @@ -64,10 +63,10 @@ private: QDomElement Content(); QDomElement Draft(const QDomElement &draft); - QDomElement Step(const VToolRecord &tool); + QDomElement Step(const VToolRecord &tool, const VContainer &data); QDomElement FinalMeasurements(); - QDomElement FinalMeasurement(const VFinalMeasurement &fm); + QDomElement FinalMeasurement(const VFinalMeasurement &fm, const VContainer &data); QDomElement BasePoint(const VToolRecord &record); QDomElement EndLine(const VToolRecord &record); @@ -99,10 +98,10 @@ private: QDomElement PointFromArcAndTangent(const VToolRecord &record); QDomElement TrueDarts(const VToolRecord &record); QDomElement EllipticalArc(const VToolRecord &record); - QDomElement Rotation(const VToolRecord &record); - QDomElement FlippingByLine(const VToolRecord &record); - QDomElement FlippingByAxis(const VToolRecord &record); - QDomElement Move(const VToolRecord &record); + QDomElement Rotation(const VToolRecord &record, const VContainer &data); + QDomElement FlippingByLine(const VToolRecord &record, const VContainer &data); + QDomElement FlippingByAxis(const VToolRecord &record, const VContainer &data); + QDomElement Move(const VToolRecord &record, const VContainer &data); void Formula(QDomElement &step, const VFormula &formula, const QString &formulaStr, const QString &formulaValue); @@ -118,7 +117,7 @@ private: template void CutCurveAttributes(QDomElement &step, T* tool); - QDomElement GroupOperationSource(VAbstractOperation *tool, quint32 id); + QDomElement GroupOperationSource(VAbstractOperation *tool, quint32 id, const VContainer &data); }; #endif // VPATTERNRECIPE_H From bb3cde292b9c73a04e2949e6e27674f78632e5f8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 5 Dec 2020 12:40:45 +0200 Subject: [PATCH 07/21] Lupdate. --- ChangeLog.txt | 1 + share/translations/valentina_nl_NL.ts | 2 +- share/translations/valentina_ru_RU.ts | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 33c1ada6c..7d2f9ba34 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,6 @@ # Version 0.7.42 (unreleased) - Fix export of pattern recipe. +- Update translations. # Version 0.7.41 Dec 4, 2020 - Bug fixes. diff --git a/share/translations/valentina_nl_NL.ts b/share/translations/valentina_nl_NL.ts index 689efecaa..fc7209421 100644 --- a/share/translations/valentina_nl_NL.ts +++ b/share/translations/valentina_nl_NL.ts @@ -13584,7 +13584,7 @@ Wil je deze veranderingen opslaan? Restore label position - + Herstel label positie diff --git a/share/translations/valentina_ru_RU.ts b/share/translations/valentina_ru_RU.ts index 44ac34199..c8d4b9ebf 100644 --- a/share/translations/valentina_ru_RU.ts +++ b/share/translations/valentina_ru_RU.ts @@ -3369,7 +3369,7 @@ Insert nodes - + Вставить узлы Delete @@ -13586,7 +13586,7 @@ Do you want to save your changes? Restore label position - + Восстановить положение метки @@ -16773,12 +16773,12 @@ Do you want to save your changes? warning Calculation warning - + предупреждение Show a warning in calculations function warning - + Показывать предупреждение в расчетах From 7eb99f7a2f31d5531c0b89064d81fa0644fad181 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 5 Dec 2020 14:50:55 +0200 Subject: [PATCH 08/21] Improve export of increments into a pattern recipe. Add support for separators. --- src/libs/vformat/vpatternrecipe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/vformat/vpatternrecipe.cpp b/src/libs/vformat/vpatternrecipe.cpp index 3e86d3080..368f7b578 100644 --- a/src/libs/vformat/vpatternrecipe.cpp +++ b/src/libs/vformat/vpatternrecipe.cpp @@ -174,7 +174,7 @@ QDomElement VPatternRecipe::Increments() QDomElement increments = createElement(QStringLiteral("increments")); VContainer data = m_pattern->GetCompleteData(); - QList> patternIncrements = data.DataIncrements().values(); + QList> patternIncrements = data.DataIncrementsWithSeparators().values(); // Resore order std::sort(patternIncrements.begin(), patternIncrements.end(), @@ -198,7 +198,7 @@ QDomElement VPatternRecipe::PreviewCalculations() QDomElement previewCalculations = createElement(QStringLiteral("previewCalculations")); VContainer data = m_pattern->GetCompleteData(); - QList> patternIncrements = data.DataIncrements().values(); + QList> patternIncrements = data.DataIncrementsWithSeparators().values(); // Resore order std::sort(patternIncrements.begin(), patternIncrements.end(), From 4166e8f635da849c44adbca2a74fbf7c9ea7169e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 7 Dec 2020 10:05:46 +0200 Subject: [PATCH 09/21] Fix a regression in tool Segment a spline path. Dialog must forbids a user to save an invalid point name. --- ChangeLog.txt | 1 + src/libs/vtools/dialogs/tools/dialogcutsplinepath.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 7d2f9ba34..c1e0895c8 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,7 @@ # Version 0.7.42 (unreleased) - Fix export of pattern recipe. - Update translations. +- Fix a regression in tool Segment a spline path. # Version 0.7.41 Dec 4, 2020 - Bug fixes. diff --git a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h index 41e132e31..c9c100073 100644 --- a/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h +++ b/src/libs/vtools/dialogs/tools/dialogcutsplinepath.h @@ -116,7 +116,7 @@ private: //--------------------------------------------------------------------------------------------------------------------- inline bool DialogCutSplinePath::IsValid() const { - return flagFormula && flagAlias1 && flagAlias2; + return flagFormula && flagAlias1 && flagAlias2 && flagName; } #endif // DIALOGCUTSPLINEPATH_H From f40c06b6fc0e2fac7deda5bfd8e51d95de369f88 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 8 Dec 2020 11:20:44 +0200 Subject: [PATCH 10/21] Fix invalid visualization for tool Point of intersection circles. --- ChangeLog.txt | 1 + .../vtools/dialogs/tools/dialogpointofintersectioncircles.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c1e0895c8..2d298cb35 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -2,6 +2,7 @@ - Fix export of pattern recipe. - Update translations. - Fix a regression in tool Segment a spline path. +- Fix invalid visualization for tool Point of intersection circles. # Version 0.7.41 Dec 4, 2020 - Bug fixes. diff --git a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp index 22abed150..494962b78 100644 --- a/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp +++ b/src/libs/vtools/dialogs/tools/dialogpointofintersectioncircles.cpp @@ -410,7 +410,7 @@ void DialogPointOfIntersectionCircles::SaveData() point->setObject1Id(GetFirstCircleCenterId()); point->setObject2Id(GetSecondCircleCenterId()); - point->setC1Radius(ui->plainTextEditCircle2Radius->toPlainText()); + point->setC1Radius(ui->plainTextEditCircle1Radius->toPlainText()); point->setC2Radius(ui->plainTextEditCircle2Radius->toPlainText()); point->setCrossPoint(GetCrossCirclesPoint()); point->RefreshGeometry(); From 0ab76dd6b9736cca7954fe68c59acd3266087ca5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 17 Dec 2020 17:42:37 +0200 Subject: [PATCH 11/21] New warning. Warn about empty measurements dimension value when preparing placeholders. --- ChangeLog.txt | 1 + src/libs/vlayout/vtextmanager.cpp | 15 +++++++++++++++ .../vtools/dialogs/support/dialogeditlabel.cpp | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 2d298cb35..a8bbf3420 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,7 @@ - Update translations. - Fix a regression in tool Segment a spline path. - Fix invalid visualization for tool Point of intersection circles. +- New warning. Warn about empty measurements dimension value when preparing placeholders. # Version 0.7.41 Dec 4, 2020 - Bug fixes. diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 66753588f..28e9f36c7 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -284,6 +284,21 @@ void InitPiecePlaceholders(QMap &placeholders, const QString & QString ReplacePlaceholders(const QMap &placeholders, QString line) { QChar per('%'); + + auto TestDimension = [per, placeholders, line](const QString &placeholder, const QString &errorMsg) + { + if (line.contains(per+placeholder+per) && placeholders.value(placeholder) == QChar('0')) + { + qApp->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + } + }; + + TestDimension(pl_height, QObject::tr("No data for the height dimension.")); + TestDimension(pl_size, QObject::tr("No data for the size dimension.")); + TestDimension(pl_hip, QObject::tr("No data for the hip dimension.")); + TestDimension(pl_waist, QObject::tr("No data for the waist dimension.")); + auto i = placeholders.constBegin(); while (i != placeholders.constEnd()) { diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index 162fa10ea..cead64f07 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -586,10 +586,26 @@ void DialogEditLabel::InitPlaceholders() //--------------------------------------------------------------------------------------------------------------------- QString DialogEditLabel::ReplacePlaceholders(QString line) const { + QChar per('%'); + + auto TestDimension = [per, this, line](const QString &placeholder, const QString &errorMsg) + { + if (line.contains(per+placeholder+per) && m_placeholders.value(placeholder).second == QChar('0')) + { + qApp->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + } + }; + + TestDimension(pl_height, tr("No data for the height dimension.")); + TestDimension(pl_size, tr("No data for the size dimension.")); + TestDimension(pl_hip, tr("No data for the hip dimension.")); + TestDimension(pl_waist, tr("No data for the waist dimension.")); + auto i = m_placeholders.constBegin(); while (i != m_placeholders.constEnd()) { - line.replace(QChar('%')+i.key()+QChar('%'), i.value().second); + line.replace(per+i.key()+per, i.value().second); ++i; } return line; From 58cae6f66cf78721207244718af4f52f29cf6e39 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Thu, 17 Dec 2020 18:43:15 +0200 Subject: [PATCH 12/21] New option "Don't use the native file dialog". --- ChangeLog.txt | 1 + .../tapepreferencesconfigurationpage.cpp | 10 +++++- .../tapepreferencesconfigurationpage.ui | 29 ++++++++-------- .../configpages/tapepreferencespathpage.cpp | 5 +-- src/app/tape/tmainwindow.cpp | 21 ++++++------ .../preferencesconfigurationpage.cpp | 8 +++++ .../preferencesconfigurationpage.ui | 11 +++++-- .../configpages/preferencespathpage.cpp | 10 ++---- .../dialogs/dialogpatternproperties.cpp | 14 +++----- .../valentina/dialogs/dialogsavelayout.cpp | 10 ++---- src/app/valentina/mainwindow.cpp | 33 +++++++------------ src/app/valentina/watermarkwindow.cpp | 7 ++-- src/libs/vmisc/vabstractapplication.cpp | 11 +++++++ src/libs/vmisc/vabstractapplication.h | 3 ++ src/libs/vmisc/vcommonsettings.cpp | 16 +++++++++ src/libs/vmisc/vcommonsettings.h | 3 ++ .../dialogs/support/dialogeditlabel.cpp | 13 ++------ src/libs/vwidgets/vabstractmainwindow.cpp | 7 ++-- 18 files changed, 120 insertions(+), 92 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index a8bbf3420..d24cf08bc 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -4,6 +4,7 @@ - Fix a regression in tool Segment a spline path. - Fix invalid visualization for tool Point of intersection circles. - New warning. Warn about empty measurements dimension value when preparing placeholders. +- New option "Don't use the native file dialog". # Version 0.7.41 Dec 4, 2020 - Bug fixes. diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp index b0854aa25..0525e3d29 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.cpp @@ -53,7 +53,10 @@ TapePreferencesConfigurationPage::TapePreferencesConfigurationPage(QWidget *pare ui->osOptionCheck->setChecked(qApp->TapeSettings()->GetOsSeparator()); // Theme - ui->darkModeCheck->setChecked(qApp->TapeSettings()->GetDarkMode()); + ui->darkModeCheck->setChecked(qApp->TapeSettings()->GetDarkMode()); + + // Native dialogs + ui->checkBoxDontUseNativeDialog->setChecked(qApp->TapeSettings()->IsDontUseNativeDialog()); //---------------------- Pattern making system ui->systemBookValueLabel->setFixedHeight(4 * QFontMetrics(ui->systemBookValueLabel->font()).lineSpacing()); @@ -106,6 +109,11 @@ QStringList TapePreferencesConfigurationPage::Apply() preferences.append(tr("dark mode")); } + if (settings->IsDontUseNativeDialog() != ui->checkBoxDontUseNativeDialog->isChecked()) + { + settings->SetDontUseNativeDialog(ui->checkBoxDontUseNativeDialog->isChecked()); + } + if (m_langChanged || m_systemChanged) { const QString locale = qvariant_cast(ui->langCombo->currentData()); diff --git a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui index 55a8f6328..659ca5168 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui +++ b/src/app/tape/dialogs/configpages/tapepreferencesconfigurationpage.ui @@ -170,19 +170,22 @@ User Interface - - - - 20 - 30 - 351 - 20 - - - - Activate dark mode - - + + + + + Activate dark mode + + + + + + + Don't use the native file dialog + + + + diff --git a/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp b/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp index be64952b3..15d964d22 100644 --- a/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp +++ b/src/app/tape/dialogs/configpages/tapepreferencespathpage.cpp @@ -149,8 +149,9 @@ void TapePreferencesPathPage::EditPath() usedNotExistedDir = directory.mkpath(QChar('.')); } - const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), path, - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + const QString dir = QFileDialog::getExistingDirectory( + this, tr("Open Directory"), path, + qApp->NativeFileDialog(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks)); if (dir.isEmpty()) { if (usedNotExistedDir) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 2733fb09b..c8b404b52 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -520,7 +520,8 @@ void TMainWindow::CreateFromExisting() usedNotExistedDir = directory.mkpath(QChar('.')); } - const QString mPath = QFileDialog::getOpenFileName(this, tr("Select file"), pathTo, filter); + const QString mPath = QFileDialog::getOpenFileName(this, tr("Select file"), pathTo, filter, nullptr, + qApp->NativeFileDialog()); if (not mPath.isEmpty()) { @@ -889,7 +890,8 @@ bool TMainWindow::FileSaveAs() usedNotExistedDir = directory.mkpath(QChar('.')); } - QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir + QChar('/') + fName, filters); + QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir + QChar('/') + fName, filters, nullptr, + qApp->NativeFileDialog()); auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]() { @@ -997,11 +999,8 @@ void TMainWindow::ImportDataFromCSV() const QString filters = tr("Comma-Separated Values") + QStringLiteral(" (*.csv)"); const QString suffix = QStringLiteral("csv"); - QString fileName = QFileDialog::getOpenFileName(this, tr("Import from CSV"), QDir::homePath(), filters, nullptr -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); + QString fileName = QFileDialog::getOpenFileName(this, tr("Import from CSV"), QDir::homePath(), filters, nullptr, + qApp->NativeFileDialog()); if (fileName.isEmpty()) { @@ -1471,7 +1470,8 @@ void TMainWindow::ImportFromPattern() //Use standard path to individual measurements QString pathTo = qApp->TapeSettings()->GetPathPattern(); - const QString mPath = QFileDialog::getOpenFileName(this, tr("Import from a pattern"), pathTo, filter); + const QString mPath = QFileDialog::getOpenFileName(this, tr("Import from a pattern"), pathTo, filter, nullptr, + qApp->NativeFileDialog()); if (mPath.isEmpty()) { return; @@ -2189,7 +2189,7 @@ void TMainWindow::ExportToIndividual() QString filters = tr("Individual measurements") + QStringLiteral(" (*.vit)"); QString fName = tr("measurements.vit"); QString fileName = QFileDialog::getSaveFileName(this, tr("Export to individual"), dir + QChar('/') + fName, - filters); + filters, nullptr, qApp->NativeFileDialog()); auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]() { @@ -3358,7 +3358,8 @@ bool TMainWindow::EvalFormula(const QString &formula, bool fromUser, VContainer //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::Open(const QString &pathTo, const QString &filter) { - const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), pathTo, filter); + const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), pathTo, filter, nullptr, + qApp->NativeFileDialog()); if (not mPath.isEmpty()) { diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp index 27757cb39..9a35dbc0d 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.cpp @@ -130,6 +130,9 @@ PreferencesConfigurationPage::PreferencesConfigurationPage(QWidget *parent) // Tool panel ui->checkBoxToolPanelScaling->setChecked(settings->GetToolPanelScaling()); + // Native dialogs + ui->checkBoxDontUseNativeDialog->setChecked(settings->IsDontUseNativeDialog()); + // Tab Scrolling ui->spinBoxDuration->setMinimum(VSettings::scrollingDurationMin); ui->spinBoxDuration->setMaximum(VSettings::scrollingDurationMax); @@ -186,6 +189,11 @@ QStringList PreferencesConfigurationPage::Apply() settings->SetToolPanelScaling(ui->checkBoxToolPanelScaling->isChecked()); } + if (settings->IsDontUseNativeDialog() != ui->checkBoxDontUseNativeDialog->isChecked()) + { + settings->SetDontUseNativeDialog(ui->checkBoxDontUseNativeDialog->isChecked()); + } + settings->SetFreeCurveMode(ui->checkBoxFreeCurve->isChecked()); settings->SetDoubleClickZoomFitBestCurrentPP(ui->checkBoxZoomFitBestCurrentPP->isChecked()); diff --git a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui index 2433eb5b2..5004dcd15 100644 --- a/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui +++ b/src/app/valentina/dialogs/configpages/preferencesconfigurationpage.ui @@ -33,9 +33,9 @@ 0 - -161 + -189 624 - 717 + 745 @@ -283,6 +283,13 @@ + + + + Don't use the native file dialog + + + diff --git a/src/app/valentina/dialogs/configpages/preferencespathpage.cpp b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp index 9d9195630..c700941e3 100644 --- a/src/app/valentina/dialogs/configpages/preferencespathpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespathpage.cpp @@ -166,13 +166,9 @@ void PreferencesPathPage::EditPath() usedNotExistedDir = directory.mkpath(QChar('.')); } - const QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), path, - QFileDialog::ShowDirsOnly - | QFileDialog::DontResolveSymlinks -#ifdef Q_OS_LINUX - | QFileDialog::DontUseNativeDialog -#endif - ); + const QString dir = QFileDialog::getExistingDirectory( + this, tr("Open Directory"), path, + qApp->NativeFileDialog(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks)); if (dir.isEmpty()) { if (usedNotExistedDir) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 61b949bbe..8bfd1e708 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -411,11 +411,8 @@ void DialogPatternProperties::InitImage() void DialogPatternProperties::ChangeImage() { const QString filter = tr("Images") + QLatin1String(" (*.png *.jpg *.jpeg *.bmp)"); - const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), filter, nullptr -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); + const QString fileName = QFileDialog::getOpenFileName(this, tr("Image for pattern"), QString(), filter, nullptr, + qApp->NativeFileDialog()); if (not fileName.isEmpty()) { QImage image; @@ -456,11 +453,8 @@ void DialogPatternProperties::SaveImage() QByteArray ba = QByteArray::fromBase64(byteArray); const QString extension = doc->GetImageExtension().prepend(QChar('.')); QString filter = tr("Images") + QStringLiteral(" (*") + extension + QChar(')'); - QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), tr("untitled"), filter, &filter -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); + QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), tr("untitled"), filter, &filter, + qApp->NativeFileDialog()); if (not filename.isEmpty()) { if (not filename.endsWith(extension.toUpper())) diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index af2a962c9..55b1490c5 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -127,13 +127,9 @@ DialogSaveLayout::DialogSaveLayout(int count, Draw mode, const QString &fileName usedNotExistedDir = directory.mkpath(QChar('.')); } - const QString dir = QFileDialog::getExistingDirectory(this, tr("Select folder"), dirPath, - QFileDialog::ShowDirsOnly - | QFileDialog::DontResolveSymlinks -#ifdef Q_OS_LINUX - | QFileDialog::DontUseNativeDialog -#endif - ); + const QString dir = QFileDialog::getExistingDirectory( + this, tr("Select folder"), dirPath, + qApp->NativeFileDialog(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks)); if (not dir.isEmpty()) {// If paths equal the signal will not be called, we will do this manually dir == ui->lineEditPath->text() ? PathChanged(dir) : ui->lineEditPath->setText(dir); diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index f18988a76..8b9292c46 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1769,11 +1769,8 @@ void MainWindow::LoadIndividual() usedNotExistedDir = directory.mkpath(QChar('.')); } - const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); + const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr, + qApp->NativeFileDialog()); if (not mPath.isEmpty()) { @@ -1810,11 +1807,8 @@ void MainWindow::LoadMultisize() //Use standard path to multisize measurements QString path = qApp->ValentinaSettings()->GetPathMultisizeMeasurements(); path = VCommonSettings::PrepareMultisizeTables(path); - const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); + const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter, nullptr, + qApp->NativeFileDialog()); if (not mPath.isEmpty()) { @@ -2034,7 +2028,8 @@ void MainWindow::LoadWatermark() const QString filter(tr("Watermark files") + QLatin1String(" (*.vwm)")); QString dir = QDir::homePath(); qDebug("Run QFileDialog::getOpenFileName: dir = %s.", qUtf8Printable(dir)); - const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr); + const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr, + qApp->NativeFileDialog()); if (filePath.isEmpty()) { return; @@ -3108,11 +3103,7 @@ bool MainWindow::on_actionSaveAs_triggered() QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir + QLatin1String("/") + tr("pattern") + QLatin1String(".val"), - filters, nullptr -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); + filters, nullptr, qApp->NativeFileDialog()); auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]() { @@ -3305,11 +3296,8 @@ void MainWindow::on_actionOpen_triggered() dir = QFileInfo(files.first()).absolutePath(); } qCDebug(vMainWindow, "Run QFileDialog::getOpenFileName: dir = %s.", qUtf8Printable(dir)); - const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); + const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr, + qApp->NativeFileDialog()); if (filePath.isEmpty()) { return; @@ -4762,7 +4750,7 @@ void MainWindow::CreateActions() QString fileName = QFileDialog::getSaveFileName(this, tr("Export recipe"), QDir::homePath() + '/' + tr("recipe") + QStringLiteral(".vpr"), - filters, nullptr); + filters, nullptr, qApp->NativeFileDialog()); if (fileName.isEmpty()) { return; @@ -5569,6 +5557,7 @@ QString MainWindow::CheckPathToMeasurements(const QString &patternPath, const QS QFileDialog dialog(this, tr("Open file"), dirPath, filter); dialog.selectFile(selectedName); dialog.setFileMode(QFileDialog::ExistingFile); + dialog.setOption(QFileDialog::DontUseNativeDialog, qApp->Settings()->IsDontUseNativeDialog()); if (dialog.exec() == QDialog::Accepted) { mPath = dialog.selectedFiles().value(0); diff --git a/src/app/valentina/watermarkwindow.cpp b/src/app/valentina/watermarkwindow.cpp index 484009b50..d29c487c3 100644 --- a/src/app/valentina/watermarkwindow.cpp +++ b/src/app/valentina/watermarkwindow.cpp @@ -93,7 +93,7 @@ WatermarkWindow::WatermarkWindow(const QString &patternPath, QWidget *parent) : { const QString filter = tr("Images") + QLatin1String(" (*.png *.jpg *.jpeg *.bmp)"); const QString fileName = QFileDialog::getOpenFileName(this, tr("Watermark image"), QString(), filter, - nullptr); + nullptr, qApp->NativeFileDialog()); if (not fileName.isEmpty()) { ui->lineEditPath->setText(fileName); @@ -284,7 +284,7 @@ bool WatermarkWindow::on_actionSaveAs_triggered() QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir + QLatin1String("/") + tr("watermark") + QLatin1String(".vwm"), - filters, nullptr); + filters, nullptr, qApp->NativeFileDialog()); if (fileName.isEmpty()) { @@ -426,7 +426,8 @@ void WatermarkWindow::on_actionOpen_triggered() const QString filter(tr("Watermark files") + QLatin1String(" (*.vwm)")); QString dir = QDir::homePath(); qDebug("Run QFileDialog::getOpenFileName: dir = %s.", qUtf8Printable(dir)); - const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr); + const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr, + qApp->NativeFileDialog()); if (filePath.isEmpty()) { return; diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp index 9c185d0e6..6e9359cd4 100644 --- a/src/libs/vmisc/vabstractapplication.cpp +++ b/src/libs/vmisc/vabstractapplication.cpp @@ -313,3 +313,14 @@ bool VAbstractApplication::IsWarningMessage(const QString &message) const { return VAbstractApplication::ClearMessage(message).startsWith(warningMessageSignature); } + +//--------------------------------------------------------------------------------------------------------------------- +QFileDialog::Options VAbstractApplication::NativeFileDialog(QFileDialog::Options options) const +{ + if (settings->IsDontUseNativeDialog()) + { + options |= QFileDialog::DontUseNativeDialog; + } + + return options; +} diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h index 6afaf899d..907627c59 100644 --- a/src/libs/vmisc/vabstractapplication.h +++ b/src/libs/vmisc/vabstractapplication.h @@ -39,6 +39,7 @@ #include #include #include +#include #include "../vmisc/def.h" #include "../vpatterndb/vtranslatevars.h" @@ -82,6 +83,8 @@ public: static const QString warningMessageSignature; bool IsWarningMessage(const QString &message) const; + QFileDialog::Options NativeFileDialog(QFileDialog::Options options = QFileDialog::Options()) const; + #if defined(Q_OS_WIN) static void WinAttachConsole(); #endif diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 53597647d..c751b1783 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -66,6 +66,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationConfirmFormatRewrit Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationToolBarStyle, (QLatin1String("configuration/tool_bar_style"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationFreeCurveMode, (QLatin1String("configuration/freeCurveMode"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDoubleClickZoomFitBestCurrentPP, (QLatin1String("configuration/doubleClickZoomFitBestCurrentPP"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingConfigurationDontUseNativeDialog, (QLatin1String("configuration/dontUseNativeDialog"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternUndo, (QLatin1String("pattern/undo"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternForbidFlipping, (QLatin1String("pattern/forbidFlipping"))) @@ -1170,6 +1171,21 @@ void VCommonSettings::SetPieceShowMainPath(bool value) setValue(*settingPatternPieceShowMainPath, pieceShowMainPath); } +//--------------------------------------------------------------------------------------------------------------------- +bool VCommonSettings::IsDontUseNativeDialog() const +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + return settings.value(*settingConfigurationDontUseNativeDialog, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetDontUseNativeDialog(bool value) +{ + QSettings settings(this->format(), this->scope(), this->organizationName(), *commonIniFilename); + settings.setValue(*settingConfigurationDontUseNativeDialog, value); + settings.sync(); +} + //--------------------------------------------------------------------------------------------------------------------- qreal VCommonSettings::GetLineWidth() const { diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index 26f5acd17..dcaf01daf 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -214,6 +214,9 @@ public: bool IsPieceShowMainPath() const; void SetPieceShowMainPath(bool value); + bool IsDontUseNativeDialog() const; + void SetDontUseNativeDialog(bool value); + static qreal DefaultLineWidth(); static qreal MinimalLineWidth(); static qreal MaximalLineWidth(); diff --git a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp index cead64f07..264180196 100644 --- a/src/libs/vtools/dialogs/support/dialogeditlabel.cpp +++ b/src/libs/vtools/dialogs/support/dialogeditlabel.cpp @@ -300,11 +300,7 @@ void DialogEditLabel::ExportTemplate() QString fileName = QFileDialog::getSaveFileName(this, tr("Export label template"), path + QLatin1String("/") + tr("template") + QLatin1String(".xml"), - filters, nullptr -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); + filters, nullptr, qApp->NativeFileDialog()); if (fileName.isEmpty()) { @@ -353,11 +349,8 @@ void DialogEditLabel::ImportTemplate() QString filter(tr("Label template") + QLatin1String(" (*.xml)")); //Use standard path to label templates const QString path = VCommonSettings::PrepareLabelTemplates(qApp->Settings()->GetPathLabelTemplate()); - const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"), path, filter, nullptr -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); + const QString fileName = QFileDialog::getOpenFileName(this, tr("Import template"), path, filter, nullptr, + qApp->NativeFileDialog()); if (fileName.isEmpty()) { return; diff --git a/src/libs/vwidgets/vabstractmainwindow.cpp b/src/libs/vwidgets/vabstractmainwindow.cpp index 6f59a2958..73ae710fa 100644 --- a/src/libs/vwidgets/vabstractmainwindow.cpp +++ b/src/libs/vwidgets/vabstractmainwindow.cpp @@ -180,11 +180,8 @@ QString VAbstractMainWindow::CSVFilePath() const QString suffix("csv"); const QString path = QDir::homePath() + QChar('/') + tr("values") + QChar('.') + suffix; - QString fileName = QFileDialog::getSaveFileName(this, tr("Export to CSV"), path, filters, nullptr -#ifdef Q_OS_LINUX - , QFileDialog::DontUseNativeDialog -#endif - ); + QString fileName = QFileDialog::getSaveFileName(this, tr("Export to CSV"), path, filters, nullptr, + qApp->NativeFileDialog()); if (fileName.isEmpty()) { From e70e998dc568b8a7ad28f63f6dd3cf93ccd2b468 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 18 Dec 2020 17:01:58 +0200 Subject: [PATCH 13/21] Improve the layout option "Auto crop unused width". --- ChangeLog.txt | 1 + src/libs/vlayout/vlayoutgenerator.cpp | 27 +++++++++++++++++++++++++++ src/libs/vlayout/vlayoutgenerator.h | 1 + src/libs/vlayout/vlayoutpaper.cpp | 6 ++++++ src/libs/vlayout/vlayoutpaper.h | 1 + 5 files changed, 36 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index d24cf08bc..6649ca4e3 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,7 @@ - Fix invalid visualization for tool Point of intersection circles. - New warning. Warn about empty measurements dimension value when preparing placeholders. - New option "Don't use the native file dialog". +- Improve the layout option "Auto crop unused width". # Version 0.7.41 Dec 4, 2020 - Bug fixes. diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index a2e0efe86..2810a953b 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -263,6 +263,11 @@ void VLayoutGenerator::Generate(const QElapsedTimer &timer, qint64 timeout, Layo GatherPages(); } + if (autoCropWidth) + { + OptimizeWidth(); + } + if (IsUnitePages()) { UnitePages(); @@ -506,6 +511,27 @@ void VLayoutGenerator::GatherPages() papers = nPapers; } +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::OptimizeWidth() +{ + QVector newDetails; + for (auto &paper : papers) + { + const QRectF rec = paper.DetailsBoundingRect(); + QVector 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() { @@ -785,6 +811,7 @@ void VLayoutGenerator::SetAutoCropLength(bool value) autoCropLength = value; } +//--------------------------------------------------------------------------------------------------------------------- bool VLayoutGenerator::GetAutoCropWidth() const { return autoCropWidth; diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index e7c4d011b..8c0519be3 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -169,6 +169,7 @@ private: int PageHeight() const; int PageWidth() const; + void OptimizeWidth(); void GatherPages(); void UnitePages(); void UniteDetails(int j, QList > &nDetails, qreal length, int i) const; diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 59761af8e..9a77ccd7b 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -435,6 +435,12 @@ QVector VLayoutPaper::GetDetails() const return d->details; } +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPaper::SetDetails(const QVector &details) +{ + d->details = details; +} + //--------------------------------------------------------------------------------------------------------------------- void VLayoutPaper::SetDetails(const QList &details) { diff --git a/src/libs/vlayout/vlayoutpaper.h b/src/libs/vlayout/vlayoutpaper.h index 1e77ee890..fa0ea88dd 100644 --- a/src/libs/vlayout/vlayoutpaper.h +++ b/src/libs/vlayout/vlayoutpaper.h @@ -99,6 +99,7 @@ public: Q_REQUIRED_RESULT QList GetItemDetails(bool textAsPaths) const; QVector GetDetails() const; + void SetDetails(const QVector& details); void SetDetails(const QList& details); QRectF DetailsBoundingRect() const; From c3142b8b07b52ed48beffe20413805659e71ab0c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 19 Dec 2020 13:13:03 +0200 Subject: [PATCH 14/21] Remove deprecated QPrinter methods. --- src/app/valentina/mainwindowsnogui.cpp | 2 +- src/libs/vmisc/def.cpp | 19 ++++++++----------- src/test/ValentinaTest/tst_vposter.cpp | 6 ++---- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 1dd20d403..6218ace49 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -1308,7 +1308,7 @@ void MainWindowsNoGUI::PdfFile(const QString &name, QGraphicsRectItem *paper, QG } QPainter painter; - if (painter.begin( &printer ) == false) + if (not painter.begin( &printer )) { // failed to open file qCritical("%s", qUtf8Printable(tr("Can't open printer %1").arg(name))); return; diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 9da9d89e4..dfb1bc9ba 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -315,24 +315,21 @@ QMarginsF GetMinPrinterFields(const QSharedPointer &printer) } //--------------------------------------------------------------------------------------------------------------------- -QMarginsF GetPrinterFields(const QSharedPointer &printer) +auto GetPrinterFields(const QSharedPointer &printer) -> QMarginsF { if (printer.isNull()) { - return QMarginsF(); + return {}; } - qreal left = 0; - qreal top = 0; - qreal right = 0; - qreal bottom = 0; - printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter); // We can't use Unit::Px because our dpi in most cases is different + const QMarginsF m = printer->pageLayout().margins(QPageLayout::Millimeter); + QMarginsF def; - def.setLeft(UnitConvertor(left, Unit::Mm, Unit::Px)); - def.setRight(UnitConvertor(right, Unit::Mm, Unit::Px)); - def.setTop(UnitConvertor(top, Unit::Mm, Unit::Px)); - def.setBottom(UnitConvertor(bottom, Unit::Mm, Unit::Px)); + def.setLeft(UnitConvertor(m.left(), Unit::Mm, Unit::Px)); + def.setRight(UnitConvertor(m.right(), Unit::Mm, Unit::Px)); + def.setTop(UnitConvertor(m.top(), Unit::Mm, Unit::Px)); + def.setBottom(UnitConvertor(m.bottom(), Unit::Mm, Unit::Px)); return def; } diff --git a/src/test/ValentinaTest/tst_vposter.cpp b/src/test/ValentinaTest/tst_vposter.cpp index 6f7ae25e6..6e6f6ec2d 100644 --- a/src/test/ValentinaTest/tst_vposter.cpp +++ b/src/test/ValentinaTest/tst_vposter.cpp @@ -45,15 +45,13 @@ TST_VPoster::TST_VPoster(QObject *parent) : void TST_VPoster::BigPoster() { QPrinter printer; - printer.setResolution(96);// By default + printer.setResolution(static_cast(PrintDPI));// By default printer.setPageSize(QPageSize(QPageSize::A4)); printer.setFullPage(true); // We need to set full page because otherwise QPrinter->pageRect returns different values in Windows and Linux //sets the margins to 0 to perform the test. - const qreal left = 0, top = 0, right = 0, bottom = 0; - printer.setPageMargins(QMarginsF(left, top, right, bottom), QPageLayout::Millimeter); - + printer.setPageMargins(QMarginsF(), QPageLayout::Millimeter); const QSize image(2622, 3178); // Little bit bigger than A1 VPoster posterazor(&printer); From 4b2e8c0c8240dd355e37fe35a22a3fdf4bbc9ffd Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 19 Dec 2020 17:15:28 +0200 Subject: [PATCH 15/21] Don't use static_cast for downcast. --- src/app/valentina/core/vapplication.h | 2 +- src/libs/vmisc/vabstractapplication.h | 2 +- src/libs/vmisc/vabstractvalapplication.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/valentina/core/vapplication.h b/src/app/valentina/core/vapplication.h index b025e82b3..a6e20721c 100644 --- a/src/app/valentina/core/vapplication.h +++ b/src/app/valentina/core/vapplication.h @@ -41,7 +41,7 @@ class VApplication;// use in define #if defined(qApp) #undef qApp #endif -#define qApp (static_cast(VAbstractApplication::instance())) +#define qApp (qobject_cast(VAbstractApplication::instance())) /** * @brief The VApplication class reimplamentation QApplication class. diff --git a/src/libs/vmisc/vabstractapplication.h b/src/libs/vmisc/vabstractapplication.h index 907627c59..7bc0ef3ab 100644 --- a/src/libs/vmisc/vabstractapplication.h +++ b/src/libs/vmisc/vabstractapplication.h @@ -52,7 +52,7 @@ class VCommonSettings; #if defined(qApp) #undef qApp #endif -#define qApp (static_cast(QCoreApplication::instance())) +#define qApp (qobject_cast(QCoreApplication::instance())) class VAbstractApplication : public QApplication { diff --git a/src/libs/vmisc/vabstractvalapplication.h b/src/libs/vmisc/vabstractvalapplication.h index a188388c8..e0aed0122 100644 --- a/src/libs/vmisc/vabstractvalapplication.h +++ b/src/libs/vmisc/vabstractvalapplication.h @@ -40,7 +40,7 @@ class QGraphicsScene; #if defined(qApp) #undef qApp #endif -#define qApp (static_cast(QCoreApplication::instance())) +#define qApp (qobject_cast(QCoreApplication::instance())) class VAbstractValApplication : public VAbstractApplication { From 03ec38f2c388a79699ccbd521d632c0e7e063ee0 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 19 Dec 2020 19:10:55 +0200 Subject: [PATCH 16/21] Introducing new class VLayoutExporter. Move all export code outside of the main window class. --- .../valentina/dialogs/dialogsavelayout.cpp | 26 +- src/app/valentina/dialogs/dialogsavelayout.h | 9 - src/app/valentina/mainwindowsnogui.cpp | 457 ++++-------------- src/app/valentina/mainwindowsnogui.h | 19 - src/libs/vlayout/vlayout.pri | 2 + src/libs/vlayout/vlayoutexporter.cpp | 368 ++++++++++++++ src/libs/vlayout/vlayoutexporter.h | 240 +++++++++ 7 files changed, 707 insertions(+), 414 deletions(-) create mode 100644 src/libs/vlayout/vlayoutexporter.cpp create mode 100644 src/libs/vlayout/vlayoutexporter.h diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index 55b1490c5..79685bb4b 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -31,6 +31,7 @@ #include "../core/vapplication.h" #include "../vmisc/vsettings.h" #include "../ifc/exception/vexception.h" +#include "../vlayout/vlayoutexporter.h" #include #include @@ -788,35 +789,12 @@ bool DialogSaveLayout::SupportPSTest() { if (!tested) { - havePdf = TestPdf(); + havePdf = VLayoutExporter::SupportPDFConversion(); tested = true; } return havePdf; } -//--------------------------------------------------------------------------------------------------------------------- -bool DialogSaveLayout::TestPdf() -{ - bool res = false; - - QProcess proc; -#if defined(Q_OS_WIN) || defined(Q_OS_OSX) - // Seek pdftops in app bundle or near valentin.exe - proc.start(qApp->applicationDirPath() + QLatin1String("/")+ PDFTOPS, QStringList()); -#else - proc.start(PDFTOPS, QStringList()); // Seek pdftops in standard path -#endif - if (proc.waitForStarted(15000) && (proc.waitForFinished(15000) || proc.state() == QProcess::NotRunning)) - { - res = true; - } - else - { - qDebug()< > DialogSaveLayout::InitFormats() { diff --git a/src/app/valentina/dialogs/dialogsavelayout.h b/src/app/valentina/dialogs/dialogsavelayout.h index 8f6d480f7..ac724be5d 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.h +++ b/src/app/valentina/dialogs/dialogsavelayout.h @@ -33,14 +33,6 @@ #include "vabstractlayoutdialog.h" #include "../vlayout/vlayoutdef.h" -#ifndef PDFTOPS -#ifdef Q_OS_WIN -# define PDFTOPS QStringLiteral("pdftops.exe") -#else -# define PDFTOPS QStringLiteral("pdftops") -#endif -#endif - namespace Ui { class DialogSaveLAyout; @@ -115,7 +107,6 @@ private: static bool havePdf; static bool tested; static bool SupportPSTest(); - static bool TestPdf(); static QVector > InitFormats(); void RemoveFormatFromList(LayoutExportFormats format); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 6218ace49..1aab3c703 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -43,6 +43,7 @@ #include "dialogs/dialogsavelayout.h" #include "dialogs/dialoglayoutscale.h" #include "../vlayout/vposter.h" +#include "../vlayout/vlayoutexporter.h" #include "../vpatterndb/floatItemData/vpiecelabeldata.h" #include "../vpatterndb/floatItemData/vpatternlabeldata.h" #include "../vpatterndb/floatItemData/vgrainlinedata.h" @@ -82,14 +83,6 @@ Q_LOGGING_CATEGORY(vMainNoGUIWindow, "v.mainnoguiwindow") QT_WARNING_POP -#ifndef PDFTOPS -#ifdef Q_OS_WIN -# define PDFTOPS QStringLiteral("pdftops.exe") -#else -# define PDFTOPS QStringLiteral("pdftops") -#endif -#endif - namespace { //--------------------------------------------------------------------------------------------------------------------- @@ -684,61 +677,86 @@ void MainWindowsNoGUI::ExportApparelLayout(const QVector &details, qApp->ValentinaSettings()->SetPathLayout(path); const LayoutExportFormats format = m_dialogSaveLayout->Format(); + VLayoutExporter exporter; + exporter.SetFileName(name); + exporter.SetImageRect(QRectF(0, 0, size.width(), size.height())); + exporter.SetXScale(m_dialogSaveLayout->GetXScale()); + exporter.SetYScale(m_dialogSaveLayout->GetYScale()); + exporter.SetBinaryDxfFormat(m_dialogSaveLayout->IsBinaryDXFFormat()); + switch (format) { case LayoutExportFormats::DXF_AC1006_ASTM: - ASTMDxfFile(name, DRW::AC1006, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1006); + exporter.ExportToASTMDXF(details); break; case LayoutExportFormats::DXF_AC1009_ASTM: - ASTMDxfFile(name, DRW::AC1009, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1009); + exporter.ExportToASTMDXF(details); break; case LayoutExportFormats::DXF_AC1012_ASTM: - ASTMDxfFile(name, DRW::AC1012, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1012); + exporter.ExportToASTMDXF(details); break; case LayoutExportFormats::DXF_AC1014_ASTM: - ASTMDxfFile(name, DRW::AC1014, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1014); + exporter.ExportToASTMDXF(details); break; case LayoutExportFormats::DXF_AC1015_ASTM: - ASTMDxfFile(name, DRW::AC1015, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1015); + exporter.ExportToASTMDXF(details); break; case LayoutExportFormats::DXF_AC1018_ASTM: - ASTMDxfFile(name, DRW::AC1018, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1018); + exporter.ExportToASTMDXF(details); break; case LayoutExportFormats::DXF_AC1021_ASTM: - ASTMDxfFile(name, DRW::AC1021, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1021); + exporter.ExportToASTMDXF(details); break; case LayoutExportFormats::DXF_AC1024_ASTM: - ASTMDxfFile(name, DRW::AC1024, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1024); + exporter.ExportToASTMDXF(details); break; case LayoutExportFormats::DXF_AC1027_ASTM: - ASTMDxfFile(name, DRW::AC1027, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1027); + exporter.ExportToASTMDXF(details); break; case LayoutExportFormats::DXF_AC1006_AAMA: - AAMADxfFile(name, DRW::AC1006, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1006); + exporter.ExportToAAMADXF(details); break; case LayoutExportFormats::DXF_AC1009_AAMA: - AAMADxfFile(name, DRW::AC1009, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1009); + exporter.ExportToAAMADXF(details); break; case LayoutExportFormats::DXF_AC1012_AAMA: - AAMADxfFile(name, DRW::AC1012, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1012); + exporter.ExportToAAMADXF(details); break; case LayoutExportFormats::DXF_AC1014_AAMA: - AAMADxfFile(name, DRW::AC1014, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1014); + exporter.ExportToAAMADXF(details); break; case LayoutExportFormats::DXF_AC1015_AAMA: - AAMADxfFile(name, DRW::AC1015, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1015); + exporter.ExportToAAMADXF(details); break; case LayoutExportFormats::DXF_AC1018_AAMA: - AAMADxfFile(name, DRW::AC1018, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1018); + exporter.ExportToAAMADXF(details); break; case LayoutExportFormats::DXF_AC1021_AAMA: - AAMADxfFile(name, DRW::AC1021, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1021); + exporter.ExportToAAMADXF(details); break; case LayoutExportFormats::DXF_AC1024_AAMA: - AAMADxfFile(name, DRW::AC1024, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1024); + exporter.ExportToAAMADXF(details); break; case LayoutExportFormats::DXF_AC1027_AAMA: - AAMADxfFile(name, DRW::AC1027, m_dialogSaveLayout->IsBinaryDXFFormat(), size, details); + exporter.SetDxfVersion(DRW::AC1027); + exporter.ExportToAAMADXF(details); break; default: qDebug() << "Can't recognize file type." << Q_FUNC_INFO; @@ -1217,111 +1235,6 @@ QList MainWindowsNoGUI::CreateScenes(const QListrect(); - QSvgGenerator generator; - generator.setFileName(name); - generator.setSize(QSize(qFloor(r.width() * m_dialogSaveLayout->GetXScale() + margins.left() + margins.right()), - qFloor(r.height() * m_dialogSaveLayout->GetYScale() + margins.top() + margins.bottom()))); - generator.setViewBox(QRectF(0, 0, r.width() * m_dialogSaveLayout->GetXScale() + margins.left() + margins.right(), - r.height() * m_dialogSaveLayout->GetYScale() + margins.top() + margins.bottom())); - generator.setTitle(tr("Pattern")); - generator.setDescription(doc->GetDescription().toHtmlEscaped()); - generator.setResolution(static_cast(PrintDPI)); - QPainter painter; - painter.begin(&generator); - painter.translate(margins.left(), margins.top()); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - painter.scale(m_dialogSaveLayout->GetXScale(), m_dialogSaveLayout->GetYScale()); - scene->render(&painter, r, r, Qt::IgnoreAspectRatio); - painter.end(); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief PngFile save layout to png file. - * @param name name layout file. - */ -void MainWindowsNoGUI::PngFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, - const QMarginsF &margins) const -{ - const QRectF r = paper->rect(); - // Create the image with the exact size of the shrunk scene - QImage image(QSize(qFloor(r.width() * m_dialogSaveLayout->GetXScale() + margins.left() + margins.right()), - qFloor(r.height() * m_dialogSaveLayout->GetYScale() + margins.top() + margins.bottom())), - QImage::Format_ARGB32); - image.fill(Qt::white); - QPainter painter(&image); - painter.translate(margins.left(), margins.top()); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - painter.scale(m_dialogSaveLayout->GetXScale(), m_dialogSaveLayout->GetYScale()); - scene->render(&painter, r, r, Qt::IgnoreAspectRatio); - image.save(name); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief PdfFile save layout to pdf file. - * @param name name layout file. - */ -void MainWindowsNoGUI::PdfFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, - bool ignorePrinterFields, const QMarginsF &margins) const -{ - QPrinter printer; - printer.setCreator(QGuiApplication::applicationDisplayName()+QChar(QChar::Space)+ - QCoreApplication::applicationVersion()); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setOutputFileName(name); - printer.setDocName(FileName()); - const QRectF r = paper->rect(); - printer.setResolution(static_cast(PrintDPI)); - printer.setOrientation(QPrinter::Portrait); - printer.setFullPage(ignorePrinterFields); - - qreal width = FromPixel(r.width() * m_dialogSaveLayout->GetXScale() + margins.left() + margins.right(), Unit::Mm); - qreal height = FromPixel(r.height() * m_dialogSaveLayout->GetYScale() + margins.top() + margins.bottom(), Unit::Mm); - - if (not printer.setPageSize(QPageSize(QSizeF(width, height), QPageSize::Millimeter))) - { - qWarning() << tr("Cannot set printer page size"); - } - - const qreal left = FromPixel(margins.left(), Unit::Mm); - const qreal top = FromPixel(margins.top(), Unit::Mm); - const qreal right = FromPixel(margins.right(), Unit::Mm); - const qreal bottom = FromPixel(margins.bottom(), Unit::Mm); - - if (not printer.setPageMargins(QMarginsF(left, top, right, bottom), QPageLayout::Millimeter)) - { - qWarning() << tr("Cannot set printer margins"); - } - - QPainter painter; - if (not painter.begin( &printer )) - { // failed to open file - qCritical("%s", qUtf8Printable(tr("Can't open printer %1").arg(name))); - return; - } - painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) ); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - painter.scale(m_dialogSaveLayout->GetXScale(), m_dialogSaveLayout->GetYScale()); - scene->render(&painter, r, r, Qt::IgnoreAspectRatio); - painter.end(); -} - //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::PdfTiledFile(const QString &name) { @@ -1351,154 +1264,6 @@ void MainWindowsNoGUI::PdfTiledFile(const QString &name) PrintPages(&printer); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief EpsFile save layout to eps file. - * @param name name layout file. - */ -void MainWindowsNoGUI::EpsFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, - bool ignorePrinterFields, const QMarginsF &margins) const -{ - QTemporaryFile tmp; - if (tmp.open()) - { - PdfFile(tmp.fileName(), paper, scene, ignorePrinterFields, margins); - QStringList params = QStringList() << QStringLiteral("-eps") << tmp.fileName() << name; - PdfToPs(params); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief PsFile save layout to ps file. - * @param name name layout file. - */ -void MainWindowsNoGUI::PsFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool - ignorePrinterFields, const QMarginsF &margins) const -{ - QTemporaryFile tmp; - if (tmp.open()) - { - PdfFile(tmp.fileName(), paper, scene, ignorePrinterFields, margins); - QStringList params = QStringList() << tmp.fileName() << name; - PdfToPs(params); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief PdfToPs use external tool "pdftops" for converting pdf too eps or ps format. - * @param params string with parameter for tool. Parameters have format: "-eps input_file out_file". Use -eps when - * need create eps file. - */ -void MainWindowsNoGUI::PdfToPs(const QStringList ¶ms) const -{ -#ifndef QT_NO_CURSOR - QGuiApplication::setOverrideCursor(Qt::WaitCursor); -#endif - QProcess proc; -#if defined(Q_OS_MAC) - // Fix issue #594. Broken export on Mac. - proc.setWorkingDirectory(qApp->applicationDirPath()); - proc.start(QLatin1String("./") + PDFTOPS, params); -#else - proc.start(PDFTOPS, params); -#endif - if (proc.waitForStarted(15000)) - { - proc.waitForFinished(15000); - } -#ifndef QT_NO_CURSOR - QGuiApplication::restoreOverrideCursor(); -#endif - - QFile f(params.last()); - if (f.exists() == false) - { - const QString msg = tr("Creating file '%1' failed! %2").arg(params.last(), proc.errorString()); - QMessageBox msgBox(QMessageBox::Critical, tr("Critical error!"), msg, QMessageBox::Ok | QMessageBox::Default); - msgBox.exec(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::ObjFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene) const -{ - VObjPaintDevice generator; - generator.setFileName(name); - generator.setSize(paper->rect().size().toSize()); - generator.setResolution(static_cast(PrintDPI)); - QPainter painter; - painter.begin(&generator); - scene->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); - painter.end(); -} - -//--------------------------------------------------------------------------------------------------------------------- -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wswitch-default") - -void MainWindowsNoGUI::FlatDxfFile(const QString &name, int version, bool binary, QGraphicsRectItem *paper, - QGraphicsScene *scene, const QList > &details) const -{ - PrepareTextForDXF(endStringPlaceholder, details); - VDxfPaintDevice generator; - generator.setFileName(name); - - const QRectF r = paper->rect(); - generator.setSize(QSize(qFloor(r.width() * m_dialogSaveLayout->GetXScale()), - qFloor(r.height() * m_dialogSaveLayout->GetYScale()))); - - generator.setResolution(PrintDPI); - generator.SetVersion(static_cast(version)); - generator.SetBinaryFormat(binary); - generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745 - - QPainter painter; - if (painter.begin(&generator)) - { - painter.scale(m_dialogSaveLayout->GetXScale(), m_dialogSaveLayout->GetYScale()); - scene->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); - painter.end(); - } - RestoreTextAfterDXF(endStringPlaceholder, details); -} - -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::AAMADxfFile(const QString &name, int version, bool binary, const QSize &size, - const QVector &details) const -{ - VDxfPaintDevice generator; - generator.setFileName(name); - generator.setSize(QSize(qCeil(size.width() * m_dialogSaveLayout->GetXScale()), - qCeil(size.height() * m_dialogSaveLayout->GetYScale()))); - generator.setResolution(PrintDPI); - generator.SetVersion(static_cast(version)); - generator.SetBinaryFormat(binary); - generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745 - generator.SetXScale(m_dialogSaveLayout->GetXScale()); - generator.SetYScale(m_dialogSaveLayout->GetYScale()); - generator.ExportToAAMA(details); -} - -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::ASTMDxfFile(const QString &name, int version, bool binary, const QSize &size, - const QVector &details) const -{ - VDxfPaintDevice generator; - generator.setFileName(name); - generator.setSize(size); - generator.setResolution(PrintDPI); - generator.SetVersion(static_cast(version)); - generator.SetBinaryFormat(binary); - generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745 - generator.SetXScale(m_dialogSaveLayout->GetXScale()); - generator.SetYScale(m_dialogSaveLayout->GetYScale()); - generator.ExportToASTM(details); -} - -QT_WARNING_POP - //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::PreparePaper(int index) const { @@ -1548,70 +1313,6 @@ void MainWindowsNoGUI::RestorePaper(int index) const } } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief PrepareTextForDXF prepare QGraphicsSimpleTextItem items for export to flat dxf. - * - * Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding special - * placholder. This method append it. - * - * @param placeholder placeholder that will be appended to each QGraphicsSimpleTextItem item's text string. - */ -void MainWindowsNoGUI::PrepareTextForDXF(const QString &placeholder, - const QList > &details) const -{ - for (auto &paperItems : details) - { - for (auto item : paperItems) - { - QList pieceChildren = item->childItems(); - for (auto child : pieceChildren) - { - if (child->type() == QGraphicsSimpleTextItem::Type) - { - if(QGraphicsSimpleTextItem *textItem = qgraphicsitem_cast(child)) - { - textItem->setText(textItem->text() + placeholder); - } - } - } - } - } -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief MainWindowsNoGUI::RestoreTextAfterDXF restore QGraphicsSimpleTextItem items after export to flat dxf. - * - * Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding special - * placholder. This method remove it. - * - * @param placeholder placeholder that will be removed from each QGraphicsSimpleTextItem item's text string. - */ -void MainWindowsNoGUI::RestoreTextAfterDXF(const QString &placeholder, - const QList > &details) const -{ - for (auto &paperItems : details) - { - for (auto item : paperItems) - { - QList pieceChildren = item->childItems(); - for (auto child : pieceChildren) - { - if (child->type() == QGraphicsSimpleTextItem::Type) - { - if(QGraphicsSimpleTextItem *textItem = qgraphicsitem_cast(child)) - { - QString text = textItem->text(); - text.replace(placeholder, QString()); - textItem->setText(text); - } - } - } - } - } -} - //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::PrintPreview() { @@ -1951,87 +1652,119 @@ void MainWindowsNoGUI::ExportScene(const QList &scenes, const QList > &details, bool ignorePrinterFields, const QMarginsF &margins) const { + VLayoutExporter exporter; + exporter.SetMargins(margins); + exporter.SetXScale(m_dialogSaveLayout->GetXScale()); + exporter.SetYScale(m_dialogSaveLayout->GetYScale()); + exporter.SetTitle(tr("Pattern")); + exporter.SetDescription(doc->GetDescription().toHtmlEscaped()); + exporter.SetIgnorePrinterMargins(ignorePrinterFields); + exporter.SetBinaryDxfFormat(m_dialogSaveLayout->IsBinaryDXFFormat()); + for (int i=0; i < scenes.size(); ++i) { - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) + auto *paper = qgraphicsitem_cast(papers.at(i)); + if (paper != nullptr) { const QString name = m_dialogSaveLayout->Path() + '/' + m_dialogSaveLayout->FileName() + QString::number(i+1) + DialogSaveLayout::ExportFormatSuffix(m_dialogSaveLayout->Format()); - QBrush *brush = new QBrush(); + auto *brush = new QBrush(); brush->setColor( QColor( Qt::white ) ); QGraphicsScene *scene = scenes.at(i); scene->setBackgroundBrush( *brush ); shadows[i]->setVisible(false); - paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), 0.1, Qt::NoPen)); + const qreal thinPen = 0.1; + paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), thinPen, Qt::NoPen)); + + exporter.SetFileName(name); + exporter.SetImageRect(paper->rect()); switch (m_dialogSaveLayout->Format()) { case LayoutExportFormats::SVG: paper->setVisible(false); - SvgFile(name, paper, scene, margins); + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthHairLine(), Qt::SolidLine, Qt::RoundCap, + Qt::RoundJoin)); + exporter.ExportToSVG(scene); paper->setVisible(true); break; case LayoutExportFormats::PDF: - PdfFile(name, paper, scene, ignorePrinterFields, margins); + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, + Qt::RoundJoin)); + exporter.ExportToPDF(scene); break; case LayoutExportFormats::PNG: - PngFile(name, paper, scene, margins); + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, + Qt::RoundJoin)); + exporter.ExportToPNG(scene); break; case LayoutExportFormats::OBJ: paper->setVisible(false); - ObjFile(name, paper, scene); + exporter.ExportToOBJ(scene); paper->setVisible(true); break; case LayoutExportFormats::PS: - PsFile(name, paper, scene, ignorePrinterFields, margins); + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, + Qt::RoundJoin)); + exporter.ExportToPS(scene); break; case LayoutExportFormats::EPS: - EpsFile(name, paper, scene, ignorePrinterFields, margins); + exporter.SetPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, + Qt::RoundJoin)); + exporter.ExportToEPS(scene); break; case LayoutExportFormats::DXF_AC1006_Flat: paper->setVisible(false); - FlatDxfFile(name, DRW::AC1006, m_dialogSaveLayout->IsBinaryDXFFormat(), paper, scene, details); + exporter.SetDxfVersion(DRW::AC1006); + exporter.ExportToFlatDXF(scene, details); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1009_Flat: paper->setVisible(false); - FlatDxfFile(name, DRW::AC1009, m_dialogSaveLayout->IsBinaryDXFFormat(), paper, scene, details); + exporter.SetDxfVersion(DRW::AC1009); + exporter.ExportToFlatDXF(scene, details); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1012_Flat: paper->setVisible(false); - FlatDxfFile(name, DRW::AC1012, m_dialogSaveLayout->IsBinaryDXFFormat(), paper, scene, details); + exporter.SetDxfVersion(DRW::AC1012); + exporter.ExportToFlatDXF(scene, details); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1014_Flat: paper->setVisible(false); - FlatDxfFile(name, DRW::AC1014, m_dialogSaveLayout->IsBinaryDXFFormat(), paper, scene, details); + exporter.SetDxfVersion(DRW::AC1014); + exporter.ExportToFlatDXF(scene, details); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1015_Flat: paper->setVisible(false); - FlatDxfFile(name, DRW::AC1015, m_dialogSaveLayout->IsBinaryDXFFormat(), paper, scene, details); + exporter.SetDxfVersion(DRW::AC1015); + exporter.ExportToFlatDXF(scene, details); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1018_Flat: paper->setVisible(false); - FlatDxfFile(name, DRW::AC1018, m_dialogSaveLayout->IsBinaryDXFFormat(), paper, scene, details); + exporter.SetDxfVersion(DRW::AC1018); + exporter.ExportToFlatDXF(scene, details); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1021_Flat: paper->setVisible(false); - FlatDxfFile(name, DRW::AC1021, m_dialogSaveLayout->IsBinaryDXFFormat(), paper, scene, details); + exporter.SetDxfVersion(DRW::AC1021); + exporter.ExportToFlatDXF(scene, details); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1024_Flat: paper->setVisible(false); - FlatDxfFile(name, DRW::AC1024, m_dialogSaveLayout->IsBinaryDXFFormat(), paper, scene, details); + exporter.SetDxfVersion(DRW::AC1024); + exporter.ExportToFlatDXF(scene, details); paper->setVisible(true); break; case LayoutExportFormats::DXF_AC1027_Flat: paper->setVisible(false); - FlatDxfFile(name, DRW::AC1027, m_dialogSaveLayout->IsBinaryDXFFormat(), paper, scene, details); + exporter.SetDxfVersion(DRW::AC1027); + exporter.ExportToFlatDXF(scene, details); paper->setVisible(true); break; default: diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 409398df6..a2342a125 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -169,30 +169,11 @@ private: const QList &shadows, const QList > &details); - void SvgFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, const QMarginsF &margins)const; - void PngFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, const QMarginsF &margins)const; - void PdfFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool ignorePrinterFields, - const QMarginsF &margins)const; void PdfTiledFile(const QString &name); - void EpsFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool ignorePrinterFields, - const QMarginsF &margins)const; - void PsFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene, bool ignorePrinterFields, - const QMarginsF &margins)const; - void PdfToPs(const QStringList ¶ms)const; - void ObjFile(const QString &name, QGraphicsRectItem *paper, QGraphicsScene *scene)const; - void FlatDxfFile(const QString &name, int version, bool binary, QGraphicsRectItem *paper, QGraphicsScene *scene, - const QList > &details)const; - void AAMADxfFile(const QString &name, int version, bool binary, const QSize &size, - const QVector &details) const; - void ASTMDxfFile(const QString &name, int version, bool binary, const QSize &size, - const QVector &details) const; void PreparePaper(int index) const; void RestorePaper(int index) const; - void PrepareTextForDXF(const QString &placeholder, const QList > &details) const; - void RestoreTextAfterDXF(const QString &placeholder, const QList > &details) const; - void PrintPreview(); void LayoutPrint(); diff --git a/src/libs/vlayout/vlayout.pri b/src/libs/vlayout/vlayout.pri index fe16ecc40..e9bca6559 100644 --- a/src/libs/vlayout/vlayout.pri +++ b/src/libs/vlayout/vlayout.pri @@ -4,6 +4,7 @@ HEADERS += \ $$PWD/stable.h \ $$PWD/testpath.h \ + $$PWD/vlayoutexporter.h \ $$PWD/vlayoutgenerator.h \ $$PWD/vlayoutdef.h \ $$PWD/vlayoutpaper.h \ @@ -28,6 +29,7 @@ HEADERS += \ SOURCES += \ $$PWD/testpath.cpp \ + $$PWD/vlayoutexporter.cpp \ $$PWD/vlayoutgenerator.cpp \ $$PWD/vlayoutpaper.cpp \ $$PWD/vbank.cpp \ diff --git a/src/libs/vlayout/vlayoutexporter.cpp b/src/libs/vlayout/vlayoutexporter.cpp new file mode 100644 index 000000000..c085dc5bb --- /dev/null +++ b/src/libs/vlayout/vlayoutexporter.cpp @@ -0,0 +1,368 @@ +/************************************************************************ + ** + ** @file vlayoutexporter.cpp + ** @author Roman Telezhynskyi + ** @date 19 12, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#include "vlayoutexporter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../vmisc/vmath.h" +#include "../vmisc/defglobal.h" +#include "../vmisc/def.h" +#include "../vobj/vobjpaintdevice.h" +#include "../vdxf/vdxfpaintdevice.h" + +namespace +{ +#ifdef Q_OS_WIN +Q_GLOBAL_STATIC_WITH_ARGS(const QString, PDFTOPS, (QLatin1String("pdftops.exe"))) +#else +Q_GLOBAL_STATIC_WITH_ARGS(const QString, PDFTOPS, (QLatin1String("pdftops"))) +#endif + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief PrepareTextForDXF prepare QGraphicsSimpleTextItem items for export to flat dxf. + * + * Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding special + * placholder. This method append it. + * + * @param placeholder placeholder that will be appended to each QGraphicsSimpleTextItem item's text string. + */ +void PrepareTextForDXF(const QString &placeholder, const QList > &details) +{ + for (const auto &paperItems : details) + { + for (auto *item : paperItems) + { + QList pieceChildren = item->childItems(); + for (auto *child : qAsConst(pieceChildren)) + { + if (child->type() == QGraphicsSimpleTextItem::Type) + { + if(auto *textItem = qgraphicsitem_cast(child)) + { + textItem->setText(textItem->text() + placeholder); + } + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief RestoreTextAfterDXF restore QGraphicsSimpleTextItem items after export to flat dxf. + * + * Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding special + * placholder. This method remove it. + * + * @param placeholder placeholder that will be removed from each QGraphicsSimpleTextItem item's text string. + */ +void RestoreTextAfterDXF(const QString &placeholder, const QList > &details) +{ + for (const auto &paperItems : details) + { + for (auto *item : paperItems) + { + QList pieceChildren = item->childItems(); + for (auto *child : qAsConst(pieceChildren)) + { + if (child->type() == QGraphicsSimpleTextItem::Type) + { + if(auto *textItem = qgraphicsitem_cast(child)) + { + QString text = textItem->text(); + text.replace(placeholder, QString()); + textItem->setText(text); + } + } + } + } + } +} +} // namespace + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToSVG(QGraphicsScene *scene) const +{ + QSvgGenerator generator; + generator.setFileName(m_fileName); + + QSize drawingSize; + drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right())); + drawingSize.setHeight(qFloor(m_imageRect.height() * m_yScale + m_margins.top() + m_margins.bottom())); + generator.setSize(drawingSize); + + QRectF viewBoxRect; + viewBoxRect.setWidth(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right()); + viewBoxRect.setHeight(m_imageRect.height() * m_yScale + m_margins.top() + m_margins.bottom()); + generator.setViewBox(viewBoxRect); + + generator.setTitle(m_title); + generator.setDescription(m_description); + generator.setResolution(static_cast(PrintDPI)); + + QPainter painter; + painter.begin(&generator); + painter.translate(m_margins.left(), m_margins.top()); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(m_pen); + painter.setBrush(QBrush(Qt::NoBrush)); + painter.scale(m_xScale, m_yScale); + scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio); + painter.end(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToPNG(QGraphicsScene *scene) const +{ + // Create the image with the exact size of the shrunk scene + QSize drawingSize; + drawingSize.setWidth(qFloor(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right())); + drawingSize.setHeight(qFloor(m_imageRect.height() * m_yScale + m_margins.top() + m_margins.bottom())); + + QImage image(drawingSize, QImage::Format_ARGB32); + image.fill(Qt::white); + + QPainter painter(&image); + painter.translate(m_margins.left(), m_margins.top()); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(m_pen); + painter.setBrush(QBrush(Qt::NoBrush)); + painter.scale(m_xScale, m_yScale); + + scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio); + image.save(m_fileName); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToPDF(QGraphicsScene *scene) const +{ + QPrinter printer; + printer.setCreator(QGuiApplication::applicationDisplayName() + QChar(QChar::Space) + + QCoreApplication::applicationVersion()); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setOutputFileName(m_fileName); + printer.setDocName(QFileInfo(m_fileName).fileName()); + printer.setResolution(static_cast(PrintDPI)); + printer.setOrientation(QPrinter::Portrait); + printer.setFullPage(m_ignorePrinterMargins); + + qreal width = FromPixel(m_imageRect.width() * m_xScale + m_margins.left() + m_margins.right(), Unit::Mm); + qreal height = FromPixel(m_imageRect.height() * m_yScale + m_margins.top() + m_margins.bottom(), Unit::Mm); + + if (not printer.setPageSize(QPageSize(QSizeF(width, height), QPageSize::Millimeter))) + { + qWarning() << tr("Cannot set printer page size"); + } + + const qreal left = FromPixel(m_margins.left(), Unit::Mm); + const qreal top = FromPixel(m_margins.top(), Unit::Mm); + const qreal right = FromPixel(m_margins.right(), Unit::Mm); + const qreal bottom = FromPixel(m_margins.bottom(), Unit::Mm); + + if (not printer.setPageMargins(QMarginsF(left, top, right, bottom), QPageLayout::Millimeter)) + { + qWarning() << tr("Cannot set printer margins"); + } + + QPainter painter; + if (not painter.begin(&printer)) + { // failed to open file + qCritical() << qUtf8Printable(tr("Can't open file '%1'").arg(m_fileName)); + return; + } + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(m_pen); + painter.setBrush(QBrush(Qt::NoBrush)); + painter.scale(m_xScale, m_yScale); + scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio); + painter.end(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToOBJ(QGraphicsScene *scene) const +{ + VObjPaintDevice generator; + generator.setFileName(m_fileName); + generator.setSize(m_imageRect.size().toSize()); + generator.setResolution(static_cast(PrintDPI)); + + QPainter painter; + painter.begin(&generator); + scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio); + painter.end(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToPS(QGraphicsScene *scene) const +{ + QTemporaryFile tmp; + if (tmp.open()) + { + ExportToPDF(scene); + PdfToPs(QStringList{tmp.fileName(), m_fileName}); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToEPS(QGraphicsScene *scene) const +{ + QTemporaryFile tmp; + if (tmp.open()) + { + ExportToPDF(scene); + PdfToPs(QStringList{QStringLiteral("-eps"), tmp.fileName(), m_fileName}); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToFlatDXF(QGraphicsScene *scene, const QList > &details) const +{ + PrepareTextForDXF(endStringPlaceholder, details); + + VDxfPaintDevice generator; + generator.setFileName(m_fileName); + generator.setSize(QSize(qFloor(m_imageRect.width() * m_xScale), qFloor(m_imageRect.height() * m_yScale))); + generator.setResolution(PrintDPI); + generator.SetVersion(static_cast(m_dxfVersion)); + generator.SetBinaryFormat(m_binaryDxfFormat); + generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745 + + QPainter painter; + if (painter.begin(&generator)) + { + painter.scale(m_xScale, m_yScale); + scene->render(&painter, m_imageRect, m_imageRect, Qt::IgnoreAspectRatio); + painter.end(); + } + + RestoreTextAfterDXF(endStringPlaceholder, details); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToAAMADXF(const QVector &details) const +{ + VDxfPaintDevice generator; + generator.setFileName(m_fileName); + generator.setSize(QSize(qCeil(m_imageRect.width() * m_xScale), qCeil(m_imageRect.height() * m_yScale))); + generator.setResolution(PrintDPI); + generator.SetVersion(static_cast(m_dxfVersion)); + generator.SetBinaryFormat(m_binaryDxfFormat); + generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745 + generator.SetXScale(m_xScale); + generator.SetYScale(m_yScale); + generator.ExportToAAMA(details); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutExporter::ExportToASTMDXF(const QVector &details) const +{ + VDxfPaintDevice generator; + generator.setFileName(m_fileName); + generator.setSize(QSize(qCeil(m_imageRect.width() * m_xScale), qCeil(m_imageRect.height() * m_yScale))); + generator.setResolution(PrintDPI); + generator.SetVersion(static_cast(m_dxfVersion)); + generator.SetBinaryFormat(m_binaryDxfFormat); + generator.setInsunits(VarInsunits::Millimeters);// Decided to always use mm. See issue #745 + generator.SetXScale(m_xScale); + generator.SetYScale(m_yScale); + generator.ExportToASTM(details); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VLayoutExporter::SupportPDFConversion() -> bool +{ + bool res = false; + + QProcess proc; +#if defined(Q_OS_WIN) || defined(Q_OS_OSX) + // Seek pdftops in app bundle or near valentina.exe + proc.start(qApp->applicationDirPath() + QLatin1String("/")+ *PDFTOPS, QStringList()); +#else + proc.start(*PDFTOPS, QStringList()); // Seek pdftops in standard path +#endif + + const int timeout = 15000; + if (proc.waitForStarted(timeout) && (proc.waitForFinished(timeout) || proc.state() == QProcess::NotRunning)) + { + res = true; + } + else + { + qDebug() << *PDFTOPS << "error" << proc.error() << proc.errorString(); + } + return res; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief PdfToPs use external tool "pdftops" for converting pdf too eps or ps format. + * @param params string with parameter for tool. Parameters have format: "-eps input_file out_file". Use -eps when + * need create eps file. + */ +void VLayoutExporter::PdfToPs(const QStringList ¶ms) +{ +#ifndef QT_NO_CURSOR + QGuiApplication::setOverrideCursor(Qt::WaitCursor); +#endif + + QProcess proc; +#if defined(Q_OS_MAC) + // Fix issue #594. Broken export on Mac. + proc.setWorkingDirectory(qApp->applicationDirPath()); + proc.start(QLatin1String("./") + *PDFTOPS, params); +#else + proc.start(*PDFTOPS, params); +#endif + + const int timeout = 15000; + if (proc.waitForStarted(timeout)) + { + proc.waitForFinished(timeout); + } + +#ifndef QT_NO_CURSOR + QGuiApplication::restoreOverrideCursor(); +#endif + + QFile f(params.last()); + if (not f.exists()) + { + qCritical() << qUtf8Printable(tr("Creating file '%1' failed! %2").arg(params.last(), proc.errorString())); + } +} diff --git a/src/libs/vlayout/vlayoutexporter.h b/src/libs/vlayout/vlayoutexporter.h new file mode 100644 index 000000000..182e216dd --- /dev/null +++ b/src/libs/vlayout/vlayoutexporter.h @@ -0,0 +1,240 @@ +/************************************************************************ + ** + ** @file vlayoutexporter.h + ** @author Roman Telezhynskyi + ** @date 19 12, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#ifndef VLAYOUTEXPORTER_H +#define VLAYOUTEXPORTER_H + +#include +#include +#include +#include +#include + +class QGraphicsScene; +class QGraphicsItem; +class VLayoutPiece; + +class VLayoutExporter +{ + Q_DECLARE_TR_FUNCTIONS(VLayoutExporter) +public: + VLayoutExporter() = default; + + auto FileName() const -> QString; + void SetFileName(const QString &fileName); + + auto Margins() const -> QMarginsF; + void SetMargins(const QMarginsF &margins); + + auto ImageRect() const -> QRectF; + void SetImageRect(const QRectF &imageRect); + + auto XScale() const -> qreal; + void SetXScale(qreal xScale); + + auto YScale() const -> qreal; + void SetYScale(qreal yScale); + + auto Title() const -> QString; + void SetTitle(const QString &title); + + auto Description() const -> QString; + void SetDescription(const QString &description); + + auto Pen() const -> QPen; + void SetPen(const QPen &pen); + + auto IgnorePrinterMargins() const -> bool; + void SetIgnorePrinterMargins(bool ignorePrinterMargins); + + auto BinaryDxfFormat() const -> bool; + void SetBinaryDxfFormat(bool binaryFormat); + + auto DxfVersion() const -> int; + void SetDxfVersion(int dxfVersion); + + void ExportToSVG(QGraphicsScene *scene) const; + void ExportToPNG(QGraphicsScene *scene) const; + void ExportToPDF(QGraphicsScene *scene) const; + void ExportToOBJ(QGraphicsScene *scene) const; + void ExportToPS(QGraphicsScene *scene) const; + void ExportToEPS(QGraphicsScene *scene) const; + void ExportToFlatDXF(QGraphicsScene *scene, const QList > &details) const; + void ExportToAAMADXF(const QVector &details) const; + void ExportToASTMDXF(const QVector &details) const; + + static auto SupportPDFConversion() -> bool; + +private: + QString m_fileName{}; + QMarginsF m_margins{}; + QRectF m_imageRect{}; + qreal m_xScale{1.0}; + qreal m_yScale{1.0}; + QString m_title{}; + QString m_description{}; + QPen m_pen{}; + bool m_ignorePrinterMargins{false}; + bool m_binaryDxfFormat{false}; + int m_dxfVersion{0}; + + static void PdfToPs(const QStringList ¶ms); +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::FileName() const -> QString +{ + return m_fileName; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetFileName(const QString &fileName) +{ + m_fileName = fileName; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::Margins() const -> QMarginsF +{ + return m_margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetMargins(const QMarginsF &margins) +{ + m_margins = margins; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::ImageRect() const -> QRectF +{ + return m_imageRect; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetImageRect(const QRectF &imageRect) +{ + m_imageRect = imageRect; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::XScale() const -> qreal +{ + return m_xScale; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetXScale(qreal xScale) +{ + m_xScale = xScale; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::YScale() const -> qreal +{ + return m_yScale; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetYScale(qreal yScale) +{ + m_yScale = yScale; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::Title() const -> QString +{ + return m_title; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetTitle(const QString &title) +{ + m_title = title; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::Description() const -> QString +{ + return m_description; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetDescription(const QString &description) +{ + m_description = description; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::Pen() const -> QPen +{ + return m_pen; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetPen(const QPen &pen) +{ + m_pen = pen; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::IgnorePrinterMargins() const -> bool +{ + return m_ignorePrinterMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetIgnorePrinterMargins(bool ignorePrinterMargins) +{ + m_ignorePrinterMargins = ignorePrinterMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::BinaryDxfFormat() const -> bool +{ + return m_binaryDxfFormat; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetBinaryDxfFormat(bool binaryFormat) +{ + m_binaryDxfFormat = binaryFormat; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VLayoutExporter::DxfVersion() const -> int +{ + return m_dxfVersion; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VLayoutExporter::SetDxfVersion(int dxfVersion) +{ + m_dxfVersion = dxfVersion; +} + +#endif // VLAYOUTEXPORTER_H From 9793d5e6a20584063e5b708501089a8bebb68e41 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 21 Dec 2020 15:52:34 +0200 Subject: [PATCH 17/21] Remove deprecated QPrinter methods. --- src/app/valentina/mainwindowsnogui.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 6218ace49..ad47d5acb 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -834,8 +834,9 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) // Get printer rect acording to our dpi. const QRectF printerPageRect(0, 0, ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm), ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm)); - const double xscale = printer->pageRect().width() / printerPageRect.width(); - const double yscale = printer->pageRect().height() / printerPageRect.height(); + const QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution()); + const double xscale = pageRect.width() / printerPageRect.width(); + const double yscale = pageRect.height() / printerPageRect.height(); QPainter painter; if (not painter.begin(printer)) @@ -1286,7 +1287,7 @@ void MainWindowsNoGUI::PdfFile(const QString &name, QGraphicsRectItem *paper, QG printer.setDocName(FileName()); const QRectF r = paper->rect(); printer.setResolution(static_cast(PrintDPI)); - printer.setOrientation(QPrinter::Portrait); + printer.setPageOrientation(QPageLayout::Portrait); printer.setFullPage(ignorePrinterFields); qreal width = FromPixel(r.width() * m_dialogSaveLayout->GetXScale() + margins.left() + margins.right(), Unit::Mm); @@ -1707,7 +1708,7 @@ void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &pr printer->setCreator(QGuiApplication::applicationDisplayName()+QChar(QChar::Space)+ QCoreApplication::applicationVersion()); - printer->setOrientation(isLayoutPortrait ? QPrinter::Portrait : QPrinter::Landscape); + printer->setPageOrientation(isLayoutPortrait ? QPageLayout::Portrait : QPageLayout::Landscape); if (not isTiled) { From 319a8ec48a8a901a223b60516663b0aaa80466d8 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 21 Dec 2020 16:21:42 +0200 Subject: [PATCH 18/21] Remove deprecated QPrinter methods. Missed one paperRect(). --- src/app/valentina/mainwindowsnogui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index ad47d5acb..c00960098 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -1339,7 +1339,7 @@ void MainWindowsNoGUI::PdfTiledFile(const QString &name) SetPrinterSettings(&printer, PrintType::PrintPDF); // Call IsPagesFit after setting a printer settings and check if pages is not bigger than printer's paper size - if (not isTiled && not IsPagesFit(printer.paperRect().size())) + if (not isTiled && not IsPagesFit(printer.pageLayout().paintRectPixels(printer.resolution()).size())) { qWarning()< Date: Tue, 22 Dec 2020 13:19:40 +0200 Subject: [PATCH 19/21] Merge branch 'develop' into 83-export-drawing --- src/app/valentina/mainwindowsnogui.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 1aab3c703..798676174 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -852,8 +852,9 @@ void MainWindowsNoGUI::PrintPages(QPrinter *printer) // Get printer rect acording to our dpi. const QRectF printerPageRect(0, 0, ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm), ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm)); - const double xscale = printer->pageRect().width() / printerPageRect.width(); - const double yscale = printer->pageRect().height() / printerPageRect.height(); + const QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution()); + const double xscale = pageRect.width() / printerPageRect.width(); + const double yscale = pageRect.height() / printerPageRect.height(); QPainter painter; if (not painter.begin(printer)) @@ -1251,7 +1252,7 @@ void MainWindowsNoGUI::PdfTiledFile(const QString &name) SetPrinterSettings(&printer, PrintType::PrintPDF); // Call IsPagesFit after setting a printer settings and check if pages is not bigger than printer's paper size - if (not isTiled && not IsPagesFit(printer.paperRect().size())) + if (not isTiled && not IsPagesFit(printer.pageLayout().paintRectPixels(printer.resolution()).size())) { qWarning()<setCreator(QGuiApplication::applicationDisplayName()+QChar(QChar::Space)+ QCoreApplication::applicationVersion()); - printer->setOrientation(isLayoutPortrait ? QPrinter::Portrait : QPrinter::Landscape); + printer->setPageOrientation(isLayoutPortrait ? QPageLayout::Portrait : QPageLayout::Landscape); if (not isTiled) { From abb43979016bacd4542e89839d27816b91c43425 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 23 Dec 2020 15:29:55 +0200 Subject: [PATCH 20/21] Introducing VPrintLayout class. Refactoring printing a layout. --- .../dialogs/dialoglayoutsettings.cpp | 3 - .../valentina/dialogs/dialoglayoutsettings.h | 2 +- src/app/valentina/dialogs/dialogs.h | 1 - src/app/valentina/dialogs/dialogs.pri | 9 +- src/app/valentina/dialogs/dialogsavelayout.h | 2 +- src/app/valentina/mainwindow.cpp | 34 +- src/app/valentina/mainwindowsnogui.cpp | 750 +++-------------- src/app/valentina/mainwindowsnogui.h | 42 +- .../vlayout}/dialogs/dialoglayoutscale.cpp | 8 +- .../vlayout}/dialogs/dialoglayoutscale.h | 0 .../vlayout}/dialogs/dialoglayoutscale.ui | 0 src/libs/vlayout/dialogs/dialogs.pri | 13 + .../dialogs/vabstractlayoutdialog.cpp | 18 +- .../vlayout}/dialogs/vabstractlayoutdialog.h | 6 +- src/libs/vlayout/vbank.h | 3 +- src/libs/vlayout/vlayout.pri | 5 + src/libs/vlayout/vlayoutdef.h | 2 + src/libs/vlayout/vprintlayout.cpp | 754 ++++++++++++++++++ src/libs/vlayout/vprintlayout.h | 424 ++++++++++ src/libs/vmisc/def.cpp | 22 - src/libs/vmisc/def.h | 3 - src/libs/vmisc/vcommonsettings.cpp | 45 ++ src/libs/vmisc/vcommonsettings.h | 41 + src/libs/vmisc/vsettings.cpp | 66 -- src/libs/vmisc/vsettings.h | 11 +- 25 files changed, 1414 insertions(+), 850 deletions(-) rename src/{app/valentina => libs/vlayout}/dialogs/dialoglayoutscale.cpp (96%) rename src/{app/valentina => libs/vlayout}/dialogs/dialoglayoutscale.h (100%) rename src/{app/valentina => libs/vlayout}/dialogs/dialoglayoutscale.ui (100%) create mode 100644 src/libs/vlayout/dialogs/dialogs.pri rename src/{app/valentina => libs/vlayout}/dialogs/vabstractlayoutdialog.cpp (94%) rename src/{app/valentina => libs/vlayout}/dialogs/vabstractlayoutdialog.h (90%) create mode 100644 src/libs/vlayout/vprintlayout.cpp create mode 100644 src/libs/vlayout/vprintlayout.h diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index 04549ef52..9087e3c2c 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -909,9 +909,6 @@ QSizeF DialogLayoutSettings::GetTemplateSize(const PaperSizeTemplate &tmpl, cons } } - - - //--------------------------------------------------------------------------------------------------------------------- QMarginsF DialogLayoutSettings::MinPrinterFields() const { diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.h b/src/app/valentina/dialogs/dialoglayoutsettings.h index bf6c9d8c7..69bfc50f1 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.h +++ b/src/app/valentina/dialogs/dialoglayoutsettings.h @@ -32,7 +32,7 @@ #include #include -#include "vabstractlayoutdialog.h" +#include "../vlayout/dialogs/vabstractlayoutdialog.h" #include "../vlayout/vbank.h" namespace Ui diff --git a/src/app/valentina/dialogs/dialogs.h b/src/app/valentina/dialogs/dialogs.h index 2ca4e9ca3..122665410 100644 --- a/src/app/valentina/dialogs/dialogs.h +++ b/src/app/valentina/dialogs/dialogs.h @@ -36,6 +36,5 @@ #include "dialogaboutapp.h" #include "dialogpreferences.h" #include "dialogfinalmeasurements.h" -#include "dialoglayoutscale.h" #endif // DIALOGS_H diff --git a/src/app/valentina/dialogs/dialogs.pri b/src/app/valentina/dialogs/dialogs.pri index af53d7952..61c91e73c 100644 --- a/src/app/valentina/dialogs/dialogs.pri +++ b/src/app/valentina/dialogs/dialogs.pri @@ -2,7 +2,6 @@ # This need for corect working file translations.pro HEADERS += \ - $$PWD/dialoglayoutscale.h \ $$PWD/dialogs.h \ $$PWD/dialogincrements.h \ $$PWD/dialoghistory.h \ @@ -21,13 +20,11 @@ HEADERS += \ $$PWD/dialogdatetimeformats.h \ $$PWD/dialogknownmaterials.h \ $$PWD/dialogpatternmaterials.h \ - $$PWD/dialogfinalmeasurements.h \ - $$PWD/vabstractlayoutdialog.h + $$PWD/dialogfinalmeasurements.h SOURCES += \ $$PWD/dialogincrements.cpp \ $$PWD/dialoghistory.cpp \ - $$PWD/dialoglayoutscale.cpp \ $$PWD/dialogpatternproperties.cpp \ $$PWD/dialognewpattern.cpp \ $$PWD/dialogaboutapp.cpp \ @@ -43,13 +40,11 @@ SOURCES += \ $$PWD/dialogdatetimeformats.cpp \ $$PWD/dialogknownmaterials.cpp \ $$PWD/dialogpatternmaterials.cpp \ - $$PWD/dialogfinalmeasurements.cpp \ - $$PWD/vabstractlayoutdialog.cpp + $$PWD/dialogfinalmeasurements.cpp FORMS += \ $$PWD/dialogincrements.ui \ $$PWD/dialoghistory.ui \ - $$PWD/dialoglayoutscale.ui \ $$PWD/dialogpatternproperties.ui \ $$PWD/dialognewpattern.ui \ $$PWD/dialogaboutapp.ui \ diff --git a/src/app/valentina/dialogs/dialogsavelayout.h b/src/app/valentina/dialogs/dialogsavelayout.h index ac724be5d..4eaafc775 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.h +++ b/src/app/valentina/dialogs/dialogsavelayout.h @@ -30,7 +30,7 @@ #define DIALOGSAVELAYOUT_H #include "../vgeometry/vgeometrydef.h" -#include "vabstractlayoutdialog.h" +#include "../vlayout/dialogs/vabstractlayoutdialog.h" #include "../vlayout/vlayoutdef.h" namespace Ui diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 8b9292c46..9677e92b3 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -1641,10 +1641,7 @@ void MainWindow::customEvent(QEvent *event) //--------------------------------------------------------------------------------------------------------------------- void MainWindow::CleanLayout() { - qDeleteAll (scenes); - scenes.clear(); - shadows.clear(); - papers.clear(); + m_layoutSettings->CleanLayout(); gcontours.clear(); ui->listWidget->clear(); SetLayoutModeActions(); @@ -1654,14 +1651,14 @@ void MainWindow::CleanLayout() void MainWindow::PrepareSceneList(PreviewQuatilty quality) { ui->listWidget->clear(); - for (int i=1; i<=scenes.size(); ++i) + for (int i=1; i<=m_layoutSettings->LayoutScenes().size(); ++i) { QListWidgetItem *item = new QListWidgetItem(ScenePreview(i-1, ui->listWidget->iconSize(), quality), QString::number(i)); ui->listWidget->addItem(item); } - if (not scenes.isEmpty()) + if (not m_layoutSettings->LayoutScenes().isEmpty()) { ui->listWidget->setCurrentRow(0); SetLayoutModeActions(); @@ -3062,7 +3059,7 @@ void MainWindow::ActionLayout(bool checked) ShowPaper(ui->listWidget->currentRow()); - if (scenes.isEmpty() || isLayoutStale) + if (m_layoutSettings->LayoutScenes().isEmpty() || m_layoutSettings->IsLayoutStale()) { ui->toolButtonLayoutSettings->click(); } @@ -3817,7 +3814,7 @@ void MainWindow::PatternChangesWereSaved(bool saved) const bool state = doc->IsModified() || !saved; setWindowModified(state); not patternReadOnly ? ui->actionSave->setEnabled(state): ui->actionSave->setEnabled(false); - isLayoutStale = true; + m_layoutSettings->SetLayoutStale(true); isNeedAutosave = not saved; } } @@ -4177,7 +4174,7 @@ QT_WARNING_POP //--------------------------------------------------------------------------------------------------------------------- void MainWindow::SetLayoutModeActions() { - const bool enabled = not scenes.isEmpty(); + const bool enabled = not m_layoutSettings->LayoutScenes().isEmpty(); ui->toolButtonLayoutExportAs->setEnabled(enabled); ui->actionExportAs->setEnabled(enabled); @@ -5011,7 +5008,6 @@ bool MainWindow::PatternPieceName(QString &name) MainWindow::~MainWindow() { CancelTool(); - qDeleteAll (scenes); delete doc; delete ui; @@ -5337,13 +5333,13 @@ void MainWindow::ToolBoxSizePolicy() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ShowPaper(int index) { - if (index < 0 || index >= scenes.size()) + if (index < 0 || index >= m_layoutSettings->LayoutScenes().size()) { ui->view->setScene(tempSceneLayout); } else { - ui->view->setScene(scenes.at(index)); + ui->view->setScene(m_layoutSettings->LayoutScenes().at(index)); } ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio); @@ -5400,9 +5396,9 @@ void MainWindow::ExportLayoutAs() { auto Uncheck = qScopeGuard([this] {ui->toolButtonLayoutExportAs->setChecked(false);}); - if (isLayoutStale) + if (m_layoutSettings->IsLayoutStale()) { - if (ContinueIfLayoutStale() == QMessageBox::No) + if (VPrintLayout::ContinueIfLayoutStale(this) == QMessageBox::No) { return; } @@ -5410,8 +5406,8 @@ void MainWindow::ExportLayoutAs() try { - m_dialogSaveLayout = QSharedPointer(new DialogSaveLayout(scenes.size(), Draw::Layout, - FileName(), this)); + m_dialogSaveLayout = QSharedPointer( + new DialogSaveLayout(m_layoutSettings->LayoutScenes().size(), Draw::Layout, FileName(), this)); if (m_dialogSaveLayout->exec() == QDialog::Rejected) { @@ -5829,9 +5825,9 @@ bool MainWindow::DoExport(const VCommandLinePtr &expParams) { try { - m_dialogSaveLayout = QSharedPointer(new DialogSaveLayout(scenes.size(), Draw::Layout, - expParams->OptBaseName(), - this)); + m_dialogSaveLayout = QSharedPointer( + new DialogSaveLayout(m_layoutSettings->LayoutScenes().size(), + Draw::Layout, expParams->OptBaseName(), this)); m_dialogSaveLayout->SetDestinationPath(expParams->OptDestinationPath()); m_dialogSaveLayout->SelectFormat(static_cast(expParams->OptExportType())); m_dialogSaveLayout->SetBinaryDXFFormat(expParams->IsBinaryDXF()); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 798676174..a90058f15 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -132,32 +132,17 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) tempSceneLayout(nullptr), pattern(new VContainer(qApp->TrVars(), qApp->patternUnitsP(), valentinaNamespace)), doc(nullptr), - papers(), - shadows(), - scenes(), - details(), - gcontours(), - detailsOnLayout(), undoAction(nullptr), redoAction(nullptr), actionDockWidgetToolOptions(nullptr), actionDockWidgetGroups(nullptr), isNoScaling(false), - isLayoutStale(true), isNeedAutosave(false), - ignorePrinterFields(false), - margins(), - paperSize(), - m_dialogSaveLayout(), #if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) m_taskbarButton(new QWinTaskbarButton(this)), m_taskbarProgress(nullptr), #endif - isTiled(false), - isAutoCropLength(false), - isAutoCropWidth(false), - isUnitePages(false), - layoutPrinterName() + m_dialogSaveLayout() { InitTempLayoutScene(); @@ -166,6 +151,8 @@ MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent) m_taskbarProgress = m_taskbarButton->progress(); m_taskbarProgress->setMinimum(0); #endif + + m_layoutSettings->SetParentWidget(this); } //--------------------------------------------------------------------------------------------------------------------- @@ -193,7 +180,7 @@ void MainWindowsNoGUI::ToolLayoutSettings(bool checked) tButton->setChecked(false); return; } - layoutPrinterName = layout.SelectedPrinter(); + m_layoutSettings->SetLayoutPrinterName(layout.SelectedPrinter()); GenerateLayout(lGenerator); tButton->setChecked(false); } @@ -324,12 +311,14 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator) } CleanLayout(); - papers = lGenerator.GetPapersItems();// Blank sheets - details = lGenerator.GetAllDetailsItems();// All details items + m_layoutSettings->SetLayoutPapers(lGenerator.GetPapersItems());// Blank sheets + m_layoutSettings->SetLayoutDetails(lGenerator.GetAllDetailsItems());// All details items detailsOnLayout = lGenerator.GetAllDetails();// All details items - shadows = CreateShadows(papers); - isLayoutPortrait = lGenerator.IsPortrait(); - scenes = CreateScenes(papers, shadows, details); + m_layoutSettings->SetLayoutShadows(CreateShadows(m_layoutSettings->LayoutPapers())); + m_layoutSettings->SetLayoutPortrait(lGenerator.IsPortrait()); + m_layoutSettings->SetLayoutScenes(CreateScenes(m_layoutSettings->LayoutPapers(), + m_layoutSettings->LayoutShadows(), + m_layoutSettings->LayoutDetails())); #if !defined(V_NO_ASSERT) //Uncomment to debug, shows global contour // gcontours = lGenerator.GetGlobalContours(); // uncomment for debugging @@ -339,13 +328,14 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator) { PrepareSceneList(PreviewQuatilty::Fast); } - ignorePrinterFields = not lGenerator.IsUsePrinterFields(); - margins = lGenerator.GetPrinterFields(); - paperSize = QSizeF(lGenerator.GetPaperWidth(), lGenerator.GetPaperHeight()); - isAutoCropLength = lGenerator.GetAutoCropLength(); - isAutoCropWidth = lGenerator.GetAutoCropWidth(); - isUnitePages = lGenerator.IsUnitePages(); - isLayoutStale = false; + m_layoutSettings->SetIgnorePrinterMargins(not lGenerator.IsUsePrinterFields()); + m_layoutSettings->SetLayoutMargins(lGenerator.GetPrinterFields()); + m_layoutSettings->SetLayoutPaperSize(QSizeF(lGenerator.GetPaperWidth(), + lGenerator.GetPaperHeight())); + m_layoutSettings->SetAutoCropLength(lGenerator.GetAutoCropLength()); + m_layoutSettings->SetAutoCropWidth(lGenerator.GetAutoCropWidth()); + m_layoutSettings->SetUnitePages(lGenerator.IsUnitePages()); + m_layoutSettings->SetLayoutStale(false); papersCount = lGenerator.PapersCount(); hasResult = true; qDebug() << "Layout efficiency: " << efficiency; @@ -534,7 +524,8 @@ void MainWindowsNoGUI::ExportData(const QVector &listDetails) const QString name = m_dialogSaveLayout->Path() + '/' + m_dialogSaveLayout->FileName() + QString::number(i+1) + DialogSaveLayout::ExportFormatSuffix(m_dialogSaveLayout->Format()); - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); + QGraphicsRectItem *paper = qgraphicsitem_cast( + m_layoutSettings->LayoutPapers().at(i)); SCASSERT(paper != nullptr) ExportApparelLayout(detailsOnLayout.at(i), name, paper->rect().size().toSize()); @@ -549,7 +540,9 @@ void MainWindowsNoGUI::ExportData(const QVector &listDetails) { if (m_dialogSaveLayout->Mode() == Draw::Layout) { - ExportFlatLayout(scenes, papers, shadows, details, ignorePrinterFields, margins); + ExportFlatLayout(m_layoutSettings->LayoutScenes(), m_layoutSettings->LayoutPapers(), + m_layoutSettings->LayoutShadows(), m_layoutSettings->LayoutDetails(), + m_layoutSettings->IgnorePrinterMargins(), m_layoutSettings->LayoutMargins()); } else { @@ -577,8 +570,7 @@ void MainWindowsNoGUI::ExportFlatLayout(const QList &scenes, if (format == LayoutExportFormats::PDFTiled && m_dialogSaveLayout->Mode() == Draw::Layout) { - const QString name = path + '/' + m_dialogSaveLayout->FileName() + QString::number(1) - + DialogSaveLayout::ExportFormatSuffix(m_dialogSaveLayout->Format()); + const QString name = path + '/' + m_dialogSaveLayout->FileName() + QChar('1'); PdfTiledFile(name); } else @@ -845,236 +837,70 @@ void MainWindowsNoGUI::ExportDetailsAsApparelLayout(QVector listDe ExportApparelLayout(listDetails, name, rect.size()); } -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::PrintPages(QPrinter *printer) -{ - // Here we try understand difference between printer's dpi and our. - // Get printer rect acording to our dpi. - const QRectF printerPageRect(0, 0, ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm), - ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm)); - const QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution()); - const double xscale = pageRect.width() / printerPageRect.width(); - const double yscale = pageRect.height() / printerPageRect.height(); - - QPainter painter; - if (not painter.begin(printer)) - { // failed to open file - qCritical() << tr("Failed to open file, is it writable?"); - return; - } - - painter.setFont( QFont( QStringLiteral("Arial"), 8, QFont::Normal ) ); - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - painter.setBrush ( QBrush ( Qt::NoBrush ) ); - - int count = 0; - QSharedPointer> poster; - QSharedPointer posterazor; - - if (isTiled) - { - PageOrientation orientation; - if (not m_dialogSaveLayout.isNull()) - { - orientation = m_dialogSaveLayout->GetTiledPageOrientation(); - } - else - { - orientation = qApp->ValentinaSettings()->GetTiledPDFOrientation(); - } - - // when isTiled, the landscape tiles have to be rotated, because the pages - // stay portrait in the pdf - if(orientation == PageOrientation::Landscape) - { - painter.rotate(-90); - painter.translate(-ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm), 0); - } - - poster = QSharedPointer>(new QVector()); - posterazor = QSharedPointer(new VPoster(printer)); - - for (int i=0; i < scenes.size(); ++i) - { - auto *paper = qgraphicsitem_cast(papers.at(i)); - if (paper) - { - QRectF paperRect = paper->rect(); - QSizeF image(paperRect.width() * m_xscale, paperRect.height() * m_yscale); - *poster += posterazor->Calc(image.toSize(), i, orientation); - } - } - - count = poster->size(); - } - else - { - count = scenes.size(); - } - - // Handle the fromPage(), toPage(), supportsMultipleCopies(), and numCopies() values from QPrinter. - int firstPage = printer->fromPage() - 1; - if (firstPage >= count) - { - return; - } - if (firstPage == -1) - { - firstPage = 0; - } - - int lastPage = printer->toPage() - 1; - if (lastPage == -1 || lastPage >= count) - { - lastPage = count - 1; - } - - const int numPages = lastPage - firstPage + 1; - int copyCount = 1; - if (not printer->supportsMultipleCopies()) - { - copyCount = printer->copyCount(); - } - - VWatermarkData data; - const QString watermarkPath = AbsoluteMPath(qApp->GetPatternPath(), doc->GetWatermarkPath()); - if (not watermarkPath.isEmpty()) - { - try - { - VWatermarkConverter converter(watermarkPath); - VWatermark watermark; - watermark.setXMLContent(converter.Convert()); - data = watermark.GetWatermark(); - - if (not data.path.isEmpty()) - { - // Clean previous cache - QPixmapCache::remove(AbsoluteMPath(watermarkPath, data.path)); - } - } - catch (VException &e) - { - const QString errorMsg = tr("File error.\n\n%1\n\n%2").arg(e.ErrorMessage(), e.DetailedInformation()); - qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; - } - } - - for (int i = 0; i < copyCount; ++i) - { - for (int j = 0; j < numPages; ++j) - { - if (i != 0 || j != 0) - { - if (not printer->newPage()) - { - qWarning("failed in flushing page to disk, disk full?"); - return; - } - } - int index; - if (printer->pageOrder() == QPrinter::FirstPageFirst) - { - index = firstPage + j; - } - else - { - index = lastPage - j; - } - - int paperIndex = -1; - isTiled ? paperIndex = static_cast(poster->at(index).index) : paperIndex = index; - - auto *paper = qgraphicsitem_cast(papers.at(paperIndex)); - if (paper) - { - QVector posterData; - - if (isTiled) - { - // Draw tile - posterData = posterazor->Tile(paper, poster->at(index), scenes.size(), data, watermarkPath); - } - - PreparePaper(paperIndex); - - // Render - QRectF source; - isTiled ? source = poster->at(index).rect : source = paper->rect(); - - qreal x,y; - if(printer->fullPage()) - { - QPageLayout layout = printer->pageLayout(); - layout.setUnits(QPageLayout::Millimeter); - QMarginsF printerMargins = layout.margins(); - x = qFloor(ToPixel(printerMargins.left(),Unit::Mm)); - y = qFloor(ToPixel(printerMargins.top(),Unit::Mm)); - } - else - { - x = 0; y = 0; - } - - QRectF target(x * xscale, y * yscale, source.width() * xscale, source.height() * yscale); - - scenes.at(paperIndex)->render(&painter, target, source, Qt::IgnoreAspectRatio); - - if (isTiled) - { - // Remove borders - qDeleteAll(posterData); - } - - // Restore - RestorePaper(paperIndex); - } - } - } - - painter.end(); -} - //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::PrintPreviewOrigin() { - if (not isPagesUniform()) - { - qCritical()<SetFileName(FileName()); + m_layoutSettings->PrintPreviewOrigin(); } //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::PrintPreviewTiled() { - isTiled = true; - PrintPreview(); + m_layoutSettings->SetFileName(FileName()); + + if (not m_dialogSaveLayout.isNull()) + { + m_layoutSettings->SetTiledMargins(m_dialogSaveLayout->GetTiledMargins()); + m_layoutSettings->SetTiledPDFOrientation(m_dialogSaveLayout->GetTiledPageOrientation()); + + VAbstractLayoutDialog::PaperSizeTemplate tiledFormat = m_dialogSaveLayout->GetTiledPageFormat(); + m_layoutSettings->SetTiledPDFPaperSize(VAbstractLayoutDialog::GetTemplateSize(tiledFormat, Unit::Mm)); + } + else + { + VSettings *settings = qApp->ValentinaSettings(); + m_layoutSettings->SetTiledMargins(QMarginsF(settings->GetTiledPDFMargins(Unit::Mm))); + m_layoutSettings->SetTiledPDFOrientation(settings->GetTiledPDFOrientation()); + m_layoutSettings->SetTiledPDFPaperSize(QSizeF(settings->GetTiledPDFPaperWidth(Unit::Mm), + settings->GetTiledPDFPaperHeight(Unit::Mm))); + } + + m_layoutSettings->SetWatermarkPath(AbsoluteMPath(qApp->GetPatternPath(), doc->GetWatermarkPath())); + m_layoutSettings->PrintPreviewTiled(); } //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::PrintOrigin() { - if (not isPagesUniform()) - { - qCritical()<SetFileName(FileName()); + m_layoutSettings->PrintOrigin(); } //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::PrintTiled() { - isTiled = true; - LayoutPrint(); + m_layoutSettings->SetFileName(FileName()); + + if (not m_dialogSaveLayout.isNull()) + { + m_layoutSettings->SetTiledMargins(m_dialogSaveLayout->GetTiledMargins()); + m_layoutSettings->SetTiledPDFOrientation(m_dialogSaveLayout->GetTiledPageOrientation()); + + VAbstractLayoutDialog::PaperSizeTemplate tiledFormat = m_dialogSaveLayout->GetTiledPageFormat(); + m_layoutSettings->SetTiledPDFPaperSize(VAbstractLayoutDialog::GetTemplateSize(tiledFormat, Unit::Mm)); + } + else + { + VSettings *settings = qApp->ValentinaSettings(); + m_layoutSettings->SetTiledMargins(QMarginsF(settings->GetTiledPDFMargins(Unit::Mm))); + m_layoutSettings->SetTiledPDFOrientation(settings->GetTiledPDFOrientation()); + m_layoutSettings->SetTiledPDFPaperSize(QSizeF(settings->GetTiledPDFPaperWidth(Unit::Mm), + settings->GetTiledPDFPaperHeight(Unit::Mm))); + } + + m_layoutSettings->SetWatermarkPath(AbsoluteMPath(qApp->GetPatternPath(), doc->GetWatermarkPath())); + m_layoutSettings->PrintTiled(); } //--------------------------------------------------------------------------------------------------------------------- @@ -1141,7 +967,7 @@ QStringList MainWindowsNoGUI::RecentFileList() const QIcon MainWindowsNoGUI::ScenePreview(int i, QSize iconSize, PreviewQuatilty quality) const { QImage image; - QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); + QGraphicsRectItem *paper = qgraphicsitem_cast(m_layoutSettings->LayoutPapers().at(i)); if (paper) { if (quality == PreviewQuatilty::Fast) @@ -1165,7 +991,7 @@ QIcon MainWindowsNoGUI::ScenePreview(int i, QSize iconSize, PreviewQuatilty qual painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter.setBrush ( QBrush ( Qt::NoBrush ) ); - scenes.at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio); + m_layoutSettings->LayoutScenes().at(i)->render(&painter, r, r, Qt::IgnoreAspectRatio); painter.end(); } else @@ -1239,412 +1065,30 @@ QList MainWindowsNoGUI::CreateScenes(const QListSetTiledMargins(m_dialogSaveLayout->GetTiledMargins()); + m_layoutSettings->SetTiledPDFOrientation(m_dialogSaveLayout->GetTiledPageOrientation()); - // Call IsPagesFit after setting a printer settings and check if pages is not bigger than printer's paper size - if (not isTiled && not IsPagesFit(printer.pageLayout().paintRectPixels(printer.resolution()).size())) - { - qWarning()<GetTiledPageFormat(); + m_layoutSettings->SetTiledPDFPaperSize(VAbstractLayoutDialog::GetTemplateSize(tiledFormat, Unit::Mm)); - m_xscale = m_dialogSaveLayout->GetXScale(); - m_yscale = m_dialogSaveLayout->GetYScale(); - - printer.setOutputFileName(name); - printer.setResolution(static_cast(PrintDPI)); - PrintPages(&printer); -} - -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::PreparePaper(int index) const -{ - auto *paper = qgraphicsitem_cast(papers.at(index)); - if (paper) - { - QBrush brush(Qt::white); - scenes.at(index)->setBackgroundBrush(brush); - shadows.at(index)->setVisible(false); - paper->setPen(QPen(Qt::white, 0.1, Qt::NoPen));// border - } - - QTransform matrix; - matrix.scale(m_xscale, m_yscale); - - QList paperDetails = details.at(index); - for (auto detail : paperDetails) - { - QTransform m = detail->transform(); - m *= matrix; - detail->setTransform(m); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::RestorePaper(int index) const -{ - auto *paper = qgraphicsitem_cast(papers.at(index)); - if (paper) - { - // Restore - paper->setPen(QPen(Qt::black, 1)); - QBrush brush(Qt::gray); - scenes.at(index)->setBackgroundBrush(brush); - shadows.at(index)->setVisible(true); - } - - QTransform matrix; - matrix.scale(1./m_xscale, 1./m_yscale); - - QList paperDetails = details.at(index); - for (auto detail : paperDetails) - { - QTransform m = detail->transform(); - m *= matrix; - detail->setTransform(m); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::PrintPreview() -{ - if (isLayoutStale) - { - if (ContinueIfLayoutStale() == QMessageBox::No) - { - return; - } - } - - QPrinterInfo info = QPrinterInfo::printerInfo(layoutPrinterName); - if(info.isNull() || info.printerName().isEmpty()) - { - info = QPrinterInfo::defaultPrinter(); - } - QSharedPointer printer = PreparePrinter(info); - if (printer.isNull()) - { - qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), - qUtf8Printable(tr("Cannot proceed because there are no available printers in your system."))); - return; - } - - { - DialogLayoutScale layoutScale(isTiled, this); - layoutScale.SetXScale(1); - layoutScale.SetYScale(1); - layoutScale.exec(); - - m_xscale = layoutScale.GetXScale(); - m_yscale = layoutScale.GetYScale(); - } - - SetPrinterSettings(printer.data(), PrintType::PrintPreview); - printer->setResolution(static_cast(PrintDPI)); - - // display print preview dialog - QPrintPreviewDialog preview(printer.data()); - connect(&preview, &QPrintPreviewDialog::paintRequested, this, &MainWindowsNoGUI::PrintPages); - preview.exec(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::LayoutPrint() -{ - if (isLayoutStale) - { - if (ContinueIfLayoutStale() == QMessageBox::No) - { - return; - } - } - // display print dialog and if accepted print - QPrinterInfo info = QPrinterInfo::printerInfo(layoutPrinterName); - if(info.isNull() || info.printerName().isEmpty()) - { - info = QPrinterInfo::defaultPrinter(); - } - QSharedPointer printer = PreparePrinter(info, QPrinter::HighResolution); - if (printer.isNull()) - { - qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), - qUtf8Printable(tr("Cannot proceed because there are no available printers in your system."))); - return; - } - - { - DialogLayoutScale layoutScale(isTiled, this); - layoutScale.SetXScale(1); - layoutScale.SetYScale(1); - layoutScale.exec(); - - m_xscale = layoutScale.GetXScale(); - m_yscale = layoutScale.GetYScale(); - } - - SetPrinterSettings(printer.data(), PrintType::PrintNative); - QPrintDialog dialog(printer.data(), this ); - // If only user couldn't change page margins we could use method setMinMax(); - dialog.setOption(QPrintDialog::PrintCurrentPage, false); - if ( dialog.exec() == QDialog::Accepted ) - { - printer->setResolution(static_cast(PrintDPI)); - PrintPages(printer.data()); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void MainWindowsNoGUI::SetPrinterSettings(QPrinter *printer, const PrintType &printType) -{ - SCASSERT(printer != nullptr) - printer->setCreator(QGuiApplication::applicationDisplayName()+QChar(QChar::Space)+ - QCoreApplication::applicationVersion()); - - printer->setPageOrientation(isLayoutPortrait ? QPageLayout::Portrait : QPageLayout::Landscape); - - if (not isTiled) - { - qreal width = FromPixel(paperSize.width(), Unit::Mm); - qreal height = FromPixel(paperSize.height(), Unit::Mm); - - if (isAutoCropLength || isUnitePages) - { - auto *paper = qgraphicsitem_cast(papers.at(0)); - if (paper) - { - if (isLayoutPortrait) - { - height = FromPixel(paper->rect().height() + margins.top() + margins.bottom(), Unit::Mm); - } - else - { - width = FromPixel(paper->rect().width() + margins.left() + margins.right(), Unit::Mm); - } - } - } - - if (isAutoCropWidth) - { - auto *paper = qgraphicsitem_cast(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 - } - - const QPageSize::PageSizeId pSZ = FindPageSizeId(size); - if (pSZ == QPageSize::Custom) - { - if (not printer->setPageSize(QPageSize(size, QPageSize::Millimeter))) - { - qWarning() << tr("Cannot set custom printer page size"); - } - } - else - { - if (not printer->setPageSize(QPageSize(pSZ))) - { - qWarning() << tr("Cannot set printer page size"); - } - } + m_layoutSettings->SetXScale(m_dialogSaveLayout->GetXScale()); + m_layoutSettings->SetYScale(m_dialogSaveLayout->GetYScale()); } else { - if (not m_dialogSaveLayout.isNull()) - { - VAbstractLayoutDialog::PaperSizeTemplate tiledFormat = m_dialogSaveLayout->GetTiledPageFormat(); - if (not printer->setPageSize(QPageSize(m_dialogSaveLayout->GetTemplateSize(tiledFormat, Unit::Mm), - QPageSize::Millimeter))) - { - qWarning() << tr("Cannot set printer page size"); - } - } + VSettings *settings = qApp->ValentinaSettings(); + m_layoutSettings->SetTiledMargins(QMarginsF(settings->GetTiledPDFMargins(Unit::Mm))); + m_layoutSettings->SetTiledPDFOrientation(settings->GetTiledPDFOrientation()); + m_layoutSettings->SetTiledPDFPaperSize(QSizeF(settings->GetTiledPDFPaperWidth(Unit::Mm), + settings->GetTiledPDFPaperHeight(Unit::Mm))); + m_layoutSettings->SetXScale(1); + m_layoutSettings->SetYScale(1); } - printer->setFullPage(ignorePrinterFields); - - qreal left, top, right, bottom; - - if (not isTiled) - { - QMarginsF pageMargin = QMarginsF(UnitConvertor(margins, Unit::Px, Unit::Mm)); - left = pageMargin.left(); - top = pageMargin.top(); - right = pageMargin.right(); - bottom = pageMargin.bottom(); - } - else - { - QMarginsF pageMargin; - PageOrientation orientation; - if (not m_dialogSaveLayout.isNull()) - { - pageMargin = m_dialogSaveLayout->GetTiledMargins(); - orientation = m_dialogSaveLayout->GetTiledPageOrientation(); - } - else - { - VSettings *settings = qApp->ValentinaSettings(); - pageMargin = QMarginsF(settings->GetTiledPDFMargins(Unit::Mm)); - orientation = settings->GetTiledPDFOrientation(); - } - - if(orientation == PageOrientation::Landscape) - { - // because when painting we have a -90rotation in landscape modus, - // see function PrintPages. - left = pageMargin.bottom(); - top = pageMargin.left(); - right = pageMargin.top(); - bottom = pageMargin.right(); - } - else - { - left = pageMargin.left(); - top = pageMargin.top(); - right = pageMargin.right(); - bottom = pageMargin.bottom(); - } - } - - const bool success = printer->setPageMargins(QMarginsF(left, top, right, bottom), QPageLayout::Millimeter); - if (not success) - { - qWarning() << tr("Cannot set printer margins"); - } - - switch(printType) - { - case PrintType::PrintPDF: - { - const QString outputFileName = QDir::homePath() + QDir::separator() + FileName(); - #ifdef Q_OS_WIN - printer->setOutputFileName(outputFileName); - #else - printer->setOutputFileName(outputFileName + QStringLiteral(".pdf")); - #endif - - #ifdef Q_OS_MAC - printer->setOutputFormat(QPrinter::NativeFormat); - #else - printer->setOutputFormat(QPrinter::PdfFormat); - #endif - break; - } - case PrintType::PrintNative: - printer->setOutputFileName(QString());//Disable printing to file if was enabled. - printer->setOutputFormat(QPrinter::NativeFormat); - break; - case PrintType::PrintPreview: /*do nothing*/ - default: - break; - } - - printer->setDocName(FileName()); -} - -//--------------------------------------------------------------------------------------------------------------------- -QPageSize::PageSizeId MainWindowsNoGUI::FindPageSizeId(const QSizeF &size) const -{ - if (size == QSizeF(841, 1189) || size == QSizeF(1189, 841)) - { - return QPageSize::A0; - } - - if (size == QSizeF(594, 841) || size == QSizeF(841, 594)) - { - return QPageSize::A1; - } - - if (size == QSizeF(420, 594) || size == QSizeF(594, 420)) - { - return QPageSize::A2; - } - - if (size == QSizeF(297, 420) || size == QSizeF(420, 297)) - { - return QPageSize::A3; - } - - if (size == QSizeF(210, 297) || size == QSizeF(297, 210)) - { - return QPageSize::A4; - } - - if (size == QSizeF(215.9, 355.6) || size == QSizeF(355.6, 215.9)) - { - return QPageSize::Legal; - } - - if (size == QSizeF(215.9, 279.4) || size == QSizeF(279.4, 215.9)) - { - return QPageSize::Letter; - } - - return QPageSize::Custom; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool MainWindowsNoGUI::isPagesUniform() const -{ - if (papers.size() < 2) - { - return true; - } - else - { - auto *paper = qgraphicsitem_cast(papers.at(0)); - SCASSERT(paper != nullptr) - for (auto paperItem : papers) - { - auto *p = qgraphicsitem_cast(paperItem); - SCASSERT(p != nullptr) - if (paper->rect() != p->rect()) - { - return false; - } - } - } - return true; -} - -//--------------------------------------------------------------------------------------------------------------------- -bool MainWindowsNoGUI::IsPagesFit(const QSizeF &printPaper) const -{ - // On previous stage already was checked if pages have uniform size - // Enough will be to check only one page - QGraphicsRectItem *p = qgraphicsitem_cast(papers.at(0)); - SCASSERT(p != nullptr) - const QSizeF pSize = p->rect().size(); - if (pSize.height() <= printPaper.height() && pSize.width() <= printPaper.width()) - { - return true; - } - - return false; + m_layoutSettings->SetWatermarkPath(AbsoluteMPath(qApp->GetPatternPath(), doc->GetWatermarkPath())); + m_layoutSettings->PdfTiledFile(name); } //--------------------------------------------------------------------------------------------------------------------- @@ -1941,19 +1385,3 @@ void MainWindowsNoGUI::CheckRequiredMeasurements(const VMeasurements *m) const throw e; } } - -//--------------------------------------------------------------------------------------------------------------------- -int MainWindowsNoGUI::ContinueIfLayoutStale() -{ - QMessageBox msgBox(this); - msgBox.setIcon(QMessageBox::Question); - msgBox.setWindowTitle(tr("The layout is stale.")); - msgBox.setText(tr("The layout was not updated since last pattern modification. Do you want to continue?")); - msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::No); - QSpacerItem* horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); - QGridLayout* layout = static_cast(msgBox.layout()); - SCASSERT(layout != nullptr) - layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); - return msgBox.exec(); -} diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index a2342a125..61e48b6b3 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -40,6 +40,7 @@ #include "../vlayout/vlayoutgenerator.h" #include "../vwidgets/vabstractmainwindow.h" #include "../vlayout/vtextmanager.h" +#include "../vlayout/vprintlayout.h" class QGraphicsScene; struct PosterData; @@ -98,13 +99,9 @@ protected: /** @brief doc dom document container */ VPattern *doc; - QList papers; - QList shadows; - QList scenes; - QList > details; - QList gcontours; + QList gcontours{}; - QVector > detailsOnLayout; + QVector > detailsOnLayout{}; QAction *undoAction; QAction *redoAction; @@ -112,12 +109,8 @@ protected: QAction *actionDockWidgetGroups; bool isNoScaling; - bool isLayoutStale; bool isNeedAutosave; - bool ignorePrinterFields; - bool isLayoutPortrait{true}; - QMarginsF margins; - QSizeF paperSize; + VPrintLayout *m_layoutSettings{new VPrintLayout(this)}; QSharedPointer m_dialogSaveLayout; @@ -140,7 +133,6 @@ protected: virtual QStringList RecentFileList() const override; QIcon ScenePreview(int i, QSize iconSize, PreviewQuatilty quality) const; bool GenerateLayout(VLayoutGenerator& lGenerator); - int ContinueIfLayoutStale(); QString FileName() const; bool ExportFMeasurementsToCSVData(const QString &fileName, @@ -149,21 +141,9 @@ protected: QSharedPointer OpenMeasurementFile(const QString &path) const; void CheckRequiredMeasurements(const VMeasurements *m) const; -private slots: - void PrintPages (QPrinter *printer); private: Q_DISABLE_COPY(MainWindowsNoGUI) - bool isTiled; - bool isAutoCropLength; - bool isAutoCropWidth; - bool isUnitePages; - - QString layoutPrinterName; - - qreal m_xscale{1}; - qreal m_yscale{1}; - static QList CreateShadows(const QList &papers); static QList CreateScenes(const QList &papers, const QList &shadows, @@ -171,20 +151,6 @@ private: void PdfTiledFile(const QString &name); - void PreparePaper(int index) const; - void RestorePaper(int index) const; - - void PrintPreview(); - void LayoutPrint(); - - enum class PrintType : qint8 {PrintPDF, PrintPreview, PrintNative}; - - void SetPrinterSettings(QPrinter *printer, const PrintType &printType); - QPageSize::PageSizeId FindPageSizeId(const QSizeF &size) const; - - bool isPagesUniform() const; - bool IsPagesFit(const QSizeF &printPaper) const; - void ExportScene(const QList &scenes, const QList &papers, const QList &shadows, diff --git a/src/app/valentina/dialogs/dialoglayoutscale.cpp b/src/libs/vlayout/dialogs/dialoglayoutscale.cpp similarity index 96% rename from src/app/valentina/dialogs/dialoglayoutscale.cpp rename to src/libs/vlayout/dialogs/dialoglayoutscale.cpp index e2d374a9b..04b705537 100644 --- a/src/app/valentina/dialogs/dialoglayoutscale.cpp +++ b/src/libs/vlayout/dialogs/dialoglayoutscale.cpp @@ -28,7 +28,7 @@ #include "dialoglayoutscale.h" #include "ui_dialoglayoutscale.h" -#include "../core/vapplication.h" +#include "../vmisc/vabstractvalapplication.h" #include "../vmisc/vsettings.h" #include @@ -40,7 +40,7 @@ DialogLayoutScale::DialogLayoutScale(bool printTiled, QWidget *parent) { ui->setupUi(this); - qApp->ValentinaSettings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); + qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); QPushButton *bOk = ui->buttonBox->button(QDialogButtonBox::Ok); SCASSERT(bOk != nullptr) @@ -180,7 +180,7 @@ void DialogLayoutScale::VerticalScaleChanged(double d) //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutScale::ReadSettings() { - VSettings *settings = qApp->ValentinaSettings(); + VCommonSettings *settings = qApp->Settings(); const Unit unit = qApp->patternUnits(); // read Margins top, right, bottom, left @@ -200,7 +200,7 @@ void DialogLayoutScale::ReadSettings() //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutScale::WriteSettings() const { - VSettings *settings = qApp->ValentinaSettings(); + VCommonSettings *settings = qApp->Settings(); const Unit unit = qApp->patternUnits(); // write Margins top, right, bottom, left diff --git a/src/app/valentina/dialogs/dialoglayoutscale.h b/src/libs/vlayout/dialogs/dialoglayoutscale.h similarity index 100% rename from src/app/valentina/dialogs/dialoglayoutscale.h rename to src/libs/vlayout/dialogs/dialoglayoutscale.h diff --git a/src/app/valentina/dialogs/dialoglayoutscale.ui b/src/libs/vlayout/dialogs/dialoglayoutscale.ui similarity index 100% rename from src/app/valentina/dialogs/dialoglayoutscale.ui rename to src/libs/vlayout/dialogs/dialoglayoutscale.ui diff --git a/src/libs/vlayout/dialogs/dialogs.pri b/src/libs/vlayout/dialogs/dialogs.pri new file mode 100644 index 000000000..98b4202d8 --- /dev/null +++ b/src/libs/vlayout/dialogs/dialogs.pri @@ -0,0 +1,13 @@ +# ADD TO EACH PATH $$PWD VARIABLE!!!!!! +# This need for corect working file translations.pro + +HEADERS += \ + $$PWD/dialoglayoutscale.h \ + $$PWD/vabstractlayoutdialog.h + +SOURCES += \ + $$PWD/dialoglayoutscale.cpp \ + $$PWD/vabstractlayoutdialog.cpp + +FORMS += \ + $$PWD/dialoglayoutscale.ui diff --git a/src/app/valentina/dialogs/vabstractlayoutdialog.cpp b/src/libs/vlayout/dialogs/vabstractlayoutdialog.cpp similarity index 94% rename from src/app/valentina/dialogs/vabstractlayoutdialog.cpp rename to src/libs/vlayout/dialogs/vabstractlayoutdialog.cpp index 494fa6f05..1df41c2cf 100644 --- a/src/app/valentina/dialogs/vabstractlayoutdialog.cpp +++ b/src/libs/vlayout/dialogs/vabstractlayoutdialog.cpp @@ -27,7 +27,7 @@ *************************************************************************/ #include "vabstractlayoutdialog.h" -#include "../core/vapplication.h" +#include "../vmisc/vabstractapplication.h" #include "../vmisc/vmath.h" //must be the same order as PaperSizeTemplate constants @@ -61,8 +61,8 @@ VAbstractLayoutDialog::VAbstractLayoutDialog(QWidget *parent) void VAbstractLayoutDialog::InitTemplates(QComboBox *comboBoxTemplates) { SCASSERT(comboBoxTemplates != nullptr) - const QIcon icoPaper("://icon/16x16/template.png"); - const QIcon icoRoll("://icon/16x16/roll.png"); + const QIcon icoPaper(QLatin1String("://icon/16x16/template.png")); + const QIcon icoRoll(QLatin1String("://icon/16x16/roll.png")); const QString pdi = QStringLiteral("(%1ppi)").arg(PrintDPI); auto cntr = static_cast(PaperSizeTemplate::A0); @@ -85,7 +85,7 @@ void VAbstractLayoutDialog::InitTemplates(QComboBox *comboBoxTemplates) } //--------------------------------------------------------------------------------------------------------------------- -QSizeF VAbstractLayoutDialog::GetTemplateSize(PaperSizeTemplate tmpl, Unit unit) +auto VAbstractLayoutDialog::GetTemplateSize(PaperSizeTemplate tmpl, Unit unit) -> QSizeF { qreal width = 0; qreal height = 0; @@ -159,11 +159,11 @@ QSizeF VAbstractLayoutDialog::GetTemplateSize(PaperSizeTemplate tmpl, Unit unit) default: break; } - return QSizeF(); + return {}; } //--------------------------------------------------------------------------------------------------------------------- -QSizeF VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit unit) +auto VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit unit) -> QSizeF { qreal w = 0; qreal h = 0; @@ -175,14 +175,14 @@ QSizeF VAbstractLayoutDialog::RoundTemplateSize(qreal width, qreal height, Unit case Unit::Px: w = vRound(width, 2); h = vRound(height, 2); - return QSizeF(w, h); + return {w, h}; case Unit::Inch: w = vRound(width, 5); h = vRound(height, 5); - return QSizeF(w, h); + return {w, h}; default: break; } - return QSizeF(width, height); + return {width, height}; } diff --git a/src/app/valentina/dialogs/vabstractlayoutdialog.h b/src/libs/vlayout/dialogs/vabstractlayoutdialog.h similarity index 90% rename from src/app/valentina/dialogs/vabstractlayoutdialog.h rename to src/libs/vlayout/dialogs/vabstractlayoutdialog.h index cc618b842..811f9a10a 100644 --- a/src/app/valentina/dialogs/vabstractlayoutdialog.h +++ b/src/libs/vlayout/dialogs/vabstractlayoutdialog.h @@ -59,16 +59,16 @@ public: explicit VAbstractLayoutDialog(QWidget *parent = nullptr); - static QSizeF GetTemplateSize(PaperSizeTemplate tmpl, Unit unit); + static auto GetTemplateSize(PaperSizeTemplate tmpl, Unit unit) -> QSizeF; protected: typedef QStringList FormatsVector; const static FormatsVector pageFormatNames; typedef int VIndexType; - static QSizeF RoundTemplateSize(qreal width, qreal height, Unit unit); + static auto RoundTemplateSize(qreal width, qreal height, Unit unit) -> QSizeF; - void InitTemplates(QComboBox *comboBoxTemplates); + static void InitTemplates(QComboBox *comboBoxTemplates); private: Q_DISABLE_COPY(VAbstractLayoutDialog) }; diff --git a/src/libs/vlayout/vbank.h b/src/libs/vlayout/vbank.h index 976c28f41..ad0deba1a 100644 --- a/src/libs/vlayout/vbank.h +++ b/src/libs/vlayout/vbank.h @@ -38,6 +38,7 @@ #include "../vmisc/typedef.h" #include "vlayoutpiece.h" +#include "vlayoutdef.h" // An annoying char define, from the Windows team in // #define small char @@ -49,8 +50,6 @@ Q_DECLARE_LOGGING_CATEGORY(lBank) -enum class Cases : qint8 { CaseThreeGroup = 0, CaseTwoGroup, CaseDesc, UnknownCase}; - class VBank { Q_DECLARE_TR_FUNCTIONS(VBank) diff --git a/src/libs/vlayout/vlayout.pri b/src/libs/vlayout/vlayout.pri index e9bca6559..81a129b99 100644 --- a/src/libs/vlayout/vlayout.pri +++ b/src/libs/vlayout/vlayout.pri @@ -1,6 +1,9 @@ # ADD TO EACH PATH $$PWD VARIABLE!!!!!! # This need for corect working file translations.pro +# Suport subdirectories. Just better project code tree. +include(dialogs/dialogs.pri) + HEADERS += \ $$PWD/stable.h \ $$PWD/testpath.h \ @@ -14,6 +17,7 @@ HEADERS += \ $$PWD/vcontour_p.h \ $$PWD/vbestsquare.h \ $$PWD/vposition.h \ + $$PWD/vprintlayout.h \ $$PWD/vsapoint.h \ $$PWD/vtextmanager.h \ $$PWD/vposter.h \ @@ -36,6 +40,7 @@ SOURCES += \ $$PWD/vcontour.cpp \ $$PWD/vbestsquare.cpp \ $$PWD/vposition.cpp \ + $$PWD/vprintlayout.cpp \ $$PWD/vtextmanager.cpp \ $$PWD/vposter.cpp \ $$PWD/vgraphicsfillitem.cpp \ diff --git a/src/libs/vlayout/vlayoutdef.h b/src/libs/vlayout/vlayoutdef.h index 81049cf3b..17db1fa6f 100644 --- a/src/libs/vlayout/vlayoutdef.h +++ b/src/libs/vlayout/vlayoutdef.h @@ -115,6 +115,8 @@ struct VCachedPositions QPainterPath layoutAllowancePath{}; }; +enum class Cases : qint8 { CaseThreeGroup = 0, CaseTwoGroup, CaseDesc, UnknownCase}; + /* Warning! Debugging doesn't work stable in debug mode. If you need big allocation use release mode. Or disable * Address Sanitizer. See page https://bitbucket.org/dismine/valentina/wiki/developers/Address_Sanitizer */ diff --git a/src/libs/vlayout/vprintlayout.cpp b/src/libs/vlayout/vprintlayout.cpp new file mode 100644 index 000000000..7e882edff --- /dev/null +++ b/src/libs/vlayout/vprintlayout.cpp @@ -0,0 +1,754 @@ +/************************************************************************ + ** + ** @file vprintlayout.cpp + ** @author Roman Telezhynskyi + ** @date 22 12, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#include "vprintlayout.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dialogs/dialoglayoutscale.h" +#include "../vmisc/vabstractvalapplication.h" +#include "dialogs/vabstractlayoutdialog.h" +#include "vposter.h" +#include "../vformat/vwatermark.h" +#include "../ifc/xml/vwatermarkconverter.h" +#include "../ifc/exception/vexception.h" +#include "../vmisc/vmath.h" + +namespace +{ +//--------------------------------------------------------------------------------------------------------------------- +auto FindPageSizeId(QSizeF size) -> QPageSize::PageSizeId +{ + auto TestSize = [size](float width, float height) + { + return size == QSizeF(width, height) || size == QSizeF(height, width); + }; + + constexpr int A0Width = 841; + constexpr int A0Height = 1189; + if (TestSize(A0Width, A0Height)) + { + return QPageSize::A0; + } + + constexpr int A1Width = 594; + constexpr int A1Height = 841; + if (TestSize(A1Width, A1Height)) + { + return QPageSize::A1; + } + + constexpr int A2Width = 420; + constexpr int A2Height = 594; + if (TestSize(A2Width, A2Height)) + { + return QPageSize::A2; + } + + constexpr int A3Width = 297; + constexpr int A3Height = 420; + if (TestSize(A3Width, A3Height)) + { + return QPageSize::A3; + } + + constexpr int A4Width = 210; + constexpr int A4Height = 297; + if (TestSize(A4Width, A4Height)) + { + return QPageSize::A4; + } + + constexpr float LegalWidth = 215.9F; + constexpr float LegalHeight = 355.6F; + if (TestSize(LegalWidth, LegalHeight)) + { + return QPageSize::Legal; + } + + constexpr float LetterWidth = 215.9F; + constexpr float LetterHeight = 279.4F; + if (TestSize(LetterWidth, LetterHeight)) + { + return QPageSize::Letter; + } + + return QPageSize::Custom; +} + +//--------------------------------------------------------------------------------------------------------------------- +Q_REQUIRED_RESULT auto PreparePrinter( + const QPrinterInfo &info, QPrinter::PrinterMode mode = QPrinter::ScreenResolution) -> QSharedPointer; +auto PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode) -> QSharedPointer +{ + QPrinterInfo tmpInfo = info; + if(tmpInfo.isNull() || tmpInfo.printerName().isEmpty()) + { + const QStringList list = QPrinterInfo::availablePrinterNames(); + if(list.isEmpty()) + { + return QSharedPointer(); + } + + tmpInfo = QPrinterInfo::printerInfo(list.first()); + } + + auto printer = QSharedPointer(new QPrinter(tmpInfo, mode)); + printer->setResolution(static_cast(PrintDPI)); + return printer; +} +} // namespace + +//--------------------------------------------------------------------------------------------------------------------- +VPrintLayout::VPrintLayout(QObject *parent) + : QObject(parent) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VPrintLayout::~VPrintLayout() +{ + qDeleteAll(m_layoutScenes); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::PrintTiled() +{ + m_isTiled = true; + PrintLayout(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::PrintOrigin() +{ + if (not IsPagesUniform()) + { + qCritical()<(PrintDPI)); + PrintPages(&printer); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::CleanLayout() +{ + qDeleteAll(m_layoutScenes); + m_layoutScenes.clear(); + m_layoutPapers.clear(); + m_layoutShadows.clear(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::PrintLayout() +{ + if (m_isLayoutStale) + { + if (ContinueIfLayoutStale(m_parentWidget) == QMessageBox::No) + { + return; + } + } + // display print dialog and if accepted print + QPrinterInfo info = QPrinterInfo::printerInfo(m_layoutPrinterName); + if(info.isNull() || info.printerName().isEmpty()) + { + info = QPrinterInfo::defaultPrinter(); + } + QSharedPointer printer = PreparePrinter(info, QPrinter::HighResolution); + if (printer.isNull()) + { + qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), + qUtf8Printable(tr("Cannot proceed because there are no available printers in your system."))); + return; + } + + { + DialogLayoutScale layoutScale(m_isTiled, m_parentWidget); + layoutScale.SetXScale(1); + layoutScale.SetYScale(1); + layoutScale.exec(); + + m_xscale = layoutScale.GetXScale(); + m_yscale = layoutScale.GetYScale(); + } + + SetPrinterSettings(printer.data(), PrintType::PrintNative); + QPrintDialog dialog(printer.data(), m_parentWidget); + // If only user couldn't change page margins we could use method setMinMax(); + dialog.setOption(QPrintDialog::PrintCurrentPage, false); + if (dialog.exec() == QDialog::Accepted) + { + printer->setResolution(static_cast(PrintDPI)); + PrintPages(printer.data()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::PrintPreview() +{ + if (m_isLayoutStale) + { + if (ContinueIfLayoutStale(m_parentWidget) == QMessageBox::No) + { + return; + } + } + + QPrinterInfo info = QPrinterInfo::printerInfo(m_layoutPrinterName); + if(info.isNull() || info.printerName().isEmpty()) + { + info = QPrinterInfo::defaultPrinter(); + } + QSharedPointer printer = PreparePrinter(info); + if (printer.isNull()) + { + qCritical("%s\n\n%s", qUtf8Printable(tr("Print error")), + qUtf8Printable(tr("Cannot proceed because there are no available printers in your system."))); + return; + } + + { + DialogLayoutScale layoutScale(m_isTiled, m_parentWidget); + layoutScale.SetXScale(1); + layoutScale.SetYScale(1); + layoutScale.exec(); + + m_xscale = layoutScale.GetXScale(); + m_yscale = layoutScale.GetYScale(); + } + + SetPrinterSettings(printer.data(), PrintType::PrintPreview); + printer->setResolution(static_cast(PrintDPI)); + + // display print preview dialog + QPrintPreviewDialog preview(printer.data()); + connect(&preview, &QPrintPreviewDialog::paintRequested, this, &VPrintLayout::PrintPages); + preview.exec(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::PrintPages(QPrinter *printer) +{ + // Here we try understand difference between printer's dpi and our. + // Get printer rect acording to our dpi. + const QRectF printerPageRect(0, 0, ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm), + ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm)); + const QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution()); + const double xscale = pageRect.width() / printerPageRect.width(); + const double yscale = pageRect.height() / printerPageRect.height(); + + QPainter painter; + if (not painter.begin(printer)) + { // failed to open file + qCritical() << tr("Failed to open file, is it writable?"); + return; + } + + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen(Qt::black, qApp->Settings()->WidthMainLine(), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + painter.setBrush ( QBrush ( Qt::NoBrush ) ); + + int count = 0; + QSharedPointer> poster; + QSharedPointer posterazor; + + if (m_isTiled) + { + // when isTiled, the landscape tiles have to be rotated, because the pages + // stay portrait in the pdf + if(m_tiledPDFOrientation == PageOrientation::Landscape) + { + const int angle = -90; + painter.rotate(angle); + painter.translate(-ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm), 0); + } + + poster = QSharedPointer>(new QVector()); + posterazor = QSharedPointer(new VPoster(printer)); + + for (int i=0; i < m_layoutScenes.size(); ++i) + { + auto *paper = qgraphicsitem_cast(m_layoutPapers.at(i)); + if (paper != nullptr) + { + QRectF paperRect = paper->rect(); + QSizeF image(paperRect.width() * m_xscale, paperRect.height() * m_yscale); + *poster += posterazor->Calc(image.toSize(), i, m_tiledPDFOrientation); + } + } + + count = poster->size(); + } + else + { + count = m_layoutScenes.size(); + } + + // Handle the fromPage(), toPage(), supportsMultipleCopies(), and numCopies() values from QPrinter. + int firstPage = printer->fromPage() - 1; + if (firstPage >= count) + { + return; + } + if (firstPage == -1) + { + firstPage = 0; + } + + int lastPage = printer->toPage() - 1; + if (lastPage == -1 || lastPage >= count) + { + lastPage = count - 1; + } + + const int numPages = lastPage - firstPage + 1; + int copyCount = 1; + if (not printer->supportsMultipleCopies()) + { + copyCount = printer->copyCount(); + } + + VWatermarkData data; + if (not m_watermarkPath.isEmpty()) + { + try + { + VWatermarkConverter converter(m_watermarkPath); + VWatermark watermark; + watermark.setXMLContent(converter.Convert()); + data = watermark.GetWatermark(); + + if (not data.path.isEmpty()) + { + // Clean previous cache + QPixmapCache::remove(AbsoluteMPath(m_watermarkPath, data.path)); + } + } + catch (VException &e) + { + const QString errorMsg = tr("File error.\n\n%1\n\n%2").arg(e.ErrorMessage(), e.DetailedInformation()); + qApp->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + } + } + + for (int i = 0; i < copyCount; ++i) + { + for (int j = 0; j < numPages; ++j) + { + if (i != 0 || j != 0) + { + if (not printer->newPage()) + { + qCritical() << tr("Failed in flushing page to disk, disk full?"); + return; + } + } + int index; + if (printer->pageOrder() == QPrinter::FirstPageFirst) + { + index = firstPage + j; + } + else + { + index = lastPage - j; + } + + int paperIndex = -1; + m_isTiled ? paperIndex = static_cast(poster->at(index).index) : paperIndex = index; + + auto *paper = qgraphicsitem_cast(m_layoutPapers.at(paperIndex)); + if (paper != nullptr) + { + QVector posterData; + + if (m_isTiled) + { + // Draw tile + posterData = posterazor->Tile(paper, poster->at(index), m_layoutScenes.size(), data, + m_watermarkPath); + } + + PreparePaper(paperIndex); + + // Render + QRectF source; + m_isTiled ? source = poster->at(index).rect : source = paper->rect(); + + qreal x; + qreal y; + if(printer->fullPage()) + { + QPageLayout layout = printer->pageLayout(); + layout.setUnits(QPageLayout::Millimeter); + QMarginsF printerMargins = layout.margins(); + x = qFloor(ToPixel(printerMargins.left(),Unit::Mm)); + y = qFloor(ToPixel(printerMargins.top(),Unit::Mm)); + } + else + { + x = 0; y = 0; + } + + QRectF target(x * xscale, y * yscale, source.width() * xscale, source.height() * yscale); + + m_layoutScenes.at(paperIndex)->render(&painter, target, source, Qt::IgnoreAspectRatio); + + if (m_isTiled) + { + // Remove borders + qDeleteAll(posterData); + } + + // Restore + RestorePaper(paperIndex); + } + } + } + + painter.end(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::SetPrinterSettings(QPrinter *printer, PrintType printType, const QString &filePath) +{ + SCASSERT(printer != nullptr) + printer->setCreator(QGuiApplication::applicationDisplayName() + QChar(QChar::Space) + + QCoreApplication::applicationVersion()); + printer->setPageOrientation(m_isLayoutPortrait ? QPageLayout::Portrait : QPageLayout::Landscape); + SetPrinterPageSize(printer); + printer->setFullPage(m_ignorePrinterMargins); + SetPrinterPrinterMargins(printer); + SetPrinterOutputFileName(printer, printType, filePath); + printer->setDocName(filePath.isEmpty() ? DocName() : QFileInfo(filePath).baseName()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::SetPrinterPrinterMargins(QPrinter *printer) +{ + SCASSERT(printer != nullptr) + QMarginsF printerMargins; + + if (not m_isTiled) + { + printerMargins = QMarginsF(UnitConvertor(m_layoutMargins, Unit::Px, Unit::Mm)); + } + else + { + if(m_tiledPDFOrientation == PageOrientation::Landscape) + { + // because when painting we have a -90rotation in landscape mode, + // see function PrintPages. + printerMargins = QMarginsF(m_tiledMargins.bottom(), m_tiledMargins.left(), m_tiledMargins.top(), + m_tiledMargins.right()); + } + else + { + printerMargins = m_tiledMargins; + } + } + + const bool success = printer->setPageMargins(printerMargins, QPageLayout::Millimeter); + if (not success) + { + qWarning() << tr("Cannot set printer margins"); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::SetPrinterOutputFileName(QPrinter *printer, PrintType printType, const QString &filePath) +{ + SCASSERT(printer != nullptr) + + switch(printType) + { + case PrintType::PrintPDF: + { + const QString outputFileName = filePath.isEmpty() ? QDir::homePath() + QDir::separator() + DocName() + : filePath; +#ifdef Q_OS_WIN + printer->setOutputFileName(outputFileName); +#else + printer->setOutputFileName(outputFileName + QStringLiteral(".pdf")); +#endif + +#ifdef Q_OS_MAC + printer->setOutputFormat(QPrinter::NativeFormat); +#else + printer->setOutputFormat(QPrinter::PdfFormat); +#endif + break; + } + case PrintType::PrintNative: + printer->setOutputFileName(QString());//Disable printing to file if was enabled. + printer->setOutputFormat(QPrinter::NativeFormat); + break; + case PrintType::PrintPreview: /*do nothing*/ + default: + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::SetPrinterPageSize(QPrinter *printer) +{ + SCASSERT(printer != nullptr) + + if (not m_isTiled) + { + qreal width = FromPixel(m_layoutPaperSize.width(), Unit::Mm); + qreal height = FromPixel(m_layoutPaperSize.height(), Unit::Mm); + + if (m_isAutoCropLength || m_isUnitePages) + { + auto *paper = qgraphicsitem_cast(m_layoutPapers.at(0)); + if (paper != nullptr) + { + if (m_isLayoutPortrait) + { + height = FromPixel(paper->rect().height() + m_layoutMargins.top() + m_layoutMargins.bottom(), + Unit::Mm); + } + else + { + width = FromPixel(paper->rect().width() + m_layoutMargins.left() + m_layoutMargins.right(), + Unit::Mm); + } + } + } + + if (m_isAutoCropWidth) + { + auto *paper = qgraphicsitem_cast(m_layoutPapers.at(0)); + if (paper != nullptr) + { + if (m_isLayoutPortrait) + { + width = FromPixel(paper->rect().width() + m_layoutMargins.left() + m_layoutMargins.right(), + Unit::Mm); + } + else + { + height = FromPixel(paper->rect().height() + m_layoutMargins.top() + m_layoutMargins.bottom(), + Unit::Mm); + } + } + } + + QSizeF size = QSizeF(width, height); + + if (not m_isLayoutPortrait) + { + size.transpose(); // QPrinter reverse this for landscape orientation + } + + const QPageSize::PageSizeId pSZ = FindPageSizeId(size); + if (pSZ == QPageSize::Custom) + { + if (not printer->setPageSize(QPageSize(size, QPageSize::Millimeter))) + { + qWarning() << tr("Cannot set custom printer page size"); + } + } + else + { + if (not printer->setPageSize(QPageSize(pSZ))) + { + qWarning() << tr("Cannot set printer page size"); + } + } + } + else + { + if (not printer->setPageSize(QPageSize(m_tiledPDFPaperSize, QPageSize::Millimeter))) + { + qWarning() << tr("Cannot set printer tiled page size"); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPrintLayout::DocName() const -> QString +{ + return not m_fileName.isEmpty() ? m_fileName : tr("unamed"); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::PreparePaper(int index) const +{ + auto *paper = qgraphicsitem_cast(m_layoutPapers.at(index)); + if (paper != nullptr) + { + QBrush brush(Qt::white); + m_layoutScenes.at(index)->setBackgroundBrush(brush); + m_layoutShadows.at(index)->setVisible(false); + const float thinPen = 0.1F; + paper->setPen(QPen(Qt::white, thinPen, Qt::NoPen));// border + } + + QTransform matrix; + matrix.scale(m_xscale, m_yscale); + + QList paperDetails = m_layoutDetails.at(index); + for (auto *detail : paperDetails) + { + QTransform m = detail->transform(); + m *= matrix; + detail->setTransform(m); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPrintLayout::RestorePaper(int index) const +{ + auto *paper = qgraphicsitem_cast(m_layoutPapers.at(index)); + if (paper != nullptr) + { + // Restore + paper->setPen(QPen(Qt::black, 1)); + QBrush brush(Qt::gray); + m_layoutScenes.at(index)->setBackgroundBrush(brush); + m_layoutShadows.at(index)->setVisible(true); + } + + QTransform matrix; + matrix.scale(1./m_xscale, 1./m_yscale); + + QList paperDetails = m_layoutDetails.at(index); + for (auto *detail : paperDetails) + { + QTransform m = detail->transform(); + m *= matrix; + detail->setTransform(m); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPrintLayout::IsPagesUniform() const -> bool +{ + if (m_layoutPapers.size() < 2) + { + return true; + } + + auto *paper = qgraphicsitem_cast(m_layoutPapers.at(0)); + SCASSERT(paper != nullptr) + + return std::all_of(m_layoutPapers.begin(), m_layoutPapers.end(), [paper](QGraphicsItem *paperItem) + { + auto *p = qgraphicsitem_cast(paperItem); + SCASSERT(p != nullptr) + return paper->rect() == p->rect(); + }); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPrintLayout::IsPagesFit(QSizeF printPaper) const -> bool +{ + // On previous stage already was checked if pages have uniform size + // Enough will be to check only one page + auto *p = qgraphicsitem_cast(m_layoutPapers.at(0)); + SCASSERT(p != nullptr) + const QSizeF pSize = p->rect().size(); + return pSize.height() <= printPaper.height() && pSize.width() <= printPaper.width(); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VPrintLayout::ContinueIfLayoutStale(QWidget *parent) -> int +{ + QMessageBox msgBox(parent); + msgBox.setIcon(QMessageBox::Question); + msgBox.setWindowTitle(tr("The layout is stale.")); + msgBox.setText(tr("The layout was not updated since last pattern modification. Do you want to continue?")); + msgBox.setStandardButtons(QMessageBox::Yes|QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::No); + const int width = 500; + auto* horizontalSpacer = new QSpacerItem(width, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + auto* layout = qobject_cast(msgBox.layout()); + SCASSERT(layout != nullptr) + layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); + return msgBox.exec(); +} diff --git a/src/libs/vlayout/vprintlayout.h b/src/libs/vlayout/vprintlayout.h new file mode 100644 index 000000000..2440de0cc --- /dev/null +++ b/src/libs/vlayout/vprintlayout.h @@ -0,0 +1,424 @@ +/************************************************************************ + ** + ** @file vprintlayout.h + ** @author Roman Telezhynskyi + ** @date 22 12, 2020 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2020 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ +#ifndef VPRINTLAYOUT_H +#define VPRINTLAYOUT_H + +#include +#include +#include + +#include "../vmisc/def.h" + +enum class PrintType : qint8 {PrintPDF, PrintPreview, PrintNative}; + +class QPrinter; +class QGraphicsScene; + +class VPrintLayout : public QObject +{ + Q_OBJECT +public: + VPrintLayout(QObject *parent = nullptr); + ~VPrintLayout(); + + auto FileName() const -> QString; + void SetFileName(const QString &fileName); + + auto LayoutPaperSize() const -> QSizeF; + void SetLayoutPaperSize(const QSizeF &paperSize); + + auto LayoutMargins() const -> QMarginsF; + void SetLayoutMargins(const QMarginsF &layoutMargins); + + auto ParentWidget() const -> QWidget *; + void SetParentWidget(QWidget *parentWidget); + + auto IsLayoutPortrait() const -> bool; + void SetLayoutPortrait(bool isLayoutPortrait); + + auto IgnorePrinterMargins() const -> bool; + void SetIgnorePrinterMargins(bool ignorePrinterFields); + + auto IsAutoCropLength() const -> bool; + void SetAutoCropLength(bool isAutoCropLength); + + auto IsAutoCropWidth() const -> bool; + void SetAutoCropWidth(bool isAutoCropWidth); + + auto IsUnitePages() const -> bool; + void SetUnitePages(bool isUnitePages); + + auto LayoutPrinterName() const -> QString; + void SetLayoutPrinterName(const QString &layoutPrinterName); + + auto IsLayoutStale() const -> bool; + void SetLayoutStale(bool isLayoutStale); + + auto TiledMargins() const -> QMarginsF; + void SetTiledMargins(const QMarginsF &tiledMargins); + + auto TiledPDFOrientation() const -> PageOrientation; + void SetTiledPDFOrientation(const PageOrientation &tiledPDFOrientation); + + auto TiledPDFPaperSize() const -> QSizeF; + void SetTiledPDFPaperSize(const QSizeF &tiledPDFPaperSize); + + auto XScale() const -> qreal; + void SetXScale(const qreal &xscale); + + auto YScale() const -> qreal; + void SetYScale(const qreal &yscale); + + auto WatermarkPath() const -> QString; + void SetWatermarkPath(const QString &watermarkPath); + + auto LayoutPapers() const -> QList; + void SetLayoutPapers(const QList &layoutPapers); + + auto LayoutScenes() const -> QList; + void SetLayoutScenes(const QList &layoutScenes); + + auto LayoutShadows() const -> QList; + void SetLayoutShadows(const QList &layoutShadows); + + auto LayoutDetails() const -> QList >; + void SetLayoutDetails(const QList > &layoutDetails); + + void PrintTiled(); + void PrintOrigin(); + + void PrintPreviewTiled(); + void PrintPreviewOrigin(); + + void PdfTiledFile(const QString &name); + + void CleanLayout(); + + static auto ContinueIfLayoutStale(QWidget *parent) -> int; + +private slots: + void PrintPages (QPrinter *printer); + +private: + Q_DISABLE_COPY(VPrintLayout) + + QString m_fileName{}; + QSizeF m_layoutPaperSize{}; + QMarginsF m_layoutMargins{}; + QWidget *m_parentWidget{nullptr}; + bool m_isLayoutPortrait{true}; + bool m_ignorePrinterMargins{false}; + bool m_isAutoCropLength{false}; + bool m_isAutoCropWidth{false}; + bool m_isUnitePages{false}; + QString m_layoutPrinterName{}; + bool m_isLayoutStale{true}; + QMarginsF m_tiledMargins{}; + PageOrientation m_tiledPDFOrientation{PageOrientation::Portrait}; + QSizeF m_tiledPDFPaperSize{}; + QString m_watermarkPath{}; + + + QList m_layoutPapers{}; + QList m_layoutScenes{}; + QList m_layoutShadows{}; + QList > m_layoutDetails{}; + + bool m_isTiled{false}; + qreal m_xscale{1}; + qreal m_yscale{1}; + + void PrintLayout(); + void PrintPreview(); + + void SetPrinterSettings(QPrinter *printer, PrintType printType, const QString &filePath = QString()); + void SetPrinterPrinterMargins(QPrinter *printer); + void SetPrinterOutputFileName(QPrinter *printer, PrintType printType, const QString &filePath = QString()); + void SetPrinterPageSize(QPrinter *printer); + + QString DocName() const; + + void PreparePaper(int index) const; + void RestorePaper(int index) const; + + bool IsPagesUniform() const; + bool IsPagesFit(QSizeF printPaper) const; +}; + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::FileName() const -> QString +{ + return m_fileName; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetFileName(const QString &fileName) +{ + m_fileName = fileName; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::LayoutPaperSize() const -> QSizeF +{ + return m_layoutPaperSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetLayoutPaperSize(const QSizeF &paperSize) +{ + m_layoutPaperSize = paperSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::LayoutMargins() const -> QMarginsF +{ + return m_layoutMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetLayoutMargins(const QMarginsF &layoutMargins) +{ + m_layoutMargins = layoutMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::ParentWidget() const -> QWidget * +{ + return m_parentWidget; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetParentWidget(QWidget *parentWidget) +{ + m_parentWidget = parentWidget; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::IsLayoutPortrait() const -> bool +{ + return m_isLayoutPortrait; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetLayoutPortrait(bool isLayoutPortrait) +{ + m_isLayoutPortrait = isLayoutPortrait; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::IgnorePrinterMargins() const -> bool +{ + return m_ignorePrinterMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetIgnorePrinterMargins(bool ignorePrinterFields) +{ + m_ignorePrinterMargins = ignorePrinterFields; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::IsAutoCropLength() const -> bool +{ + return m_isAutoCropLength; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetAutoCropLength(bool isAutoCropLength) +{ + m_isAutoCropLength = isAutoCropLength; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline bool VPrintLayout::IsAutoCropWidth() const +{ + return m_isAutoCropWidth; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetAutoCropWidth(bool isAutoCropWidth) +{ + m_isAutoCropWidth = isAutoCropWidth; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::IsUnitePages() const -> bool +{ + return m_isUnitePages; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetUnitePages(bool isUnitePages) +{ + m_isUnitePages = isUnitePages; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::LayoutPrinterName() const -> QString +{ + return m_layoutPrinterName; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetLayoutPrinterName(const QString &layoutPrinterName) +{ + m_layoutPrinterName = layoutPrinterName; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::IsLayoutStale() const -> bool +{ + return m_isLayoutStale; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetLayoutStale(bool isLayoutStale) +{ + m_isLayoutStale = isLayoutStale; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::TiledMargins() const -> QMarginsF +{ + return m_tiledMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetTiledMargins(const QMarginsF &tiledMargins) +{ + m_tiledMargins = tiledMargins; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::TiledPDFOrientation() const -> PageOrientation +{ + return m_tiledPDFOrientation; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetTiledPDFOrientation(const PageOrientation &tiledPDFOrientation) +{ + m_tiledPDFOrientation = tiledPDFOrientation; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::TiledPDFPaperSize() const -> QSizeF +{ + return m_tiledPDFPaperSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetTiledPDFPaperSize(const QSizeF &tiledPDFPaperSize) +{ + m_tiledPDFPaperSize = tiledPDFPaperSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::LayoutPapers() const -> QList +{ + return m_layoutPapers; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetLayoutPapers(const QList &layoutPapers) +{ + m_layoutPapers = layoutPapers; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::LayoutScenes() const -> QList +{ + return m_layoutScenes; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetLayoutScenes(const QList &layoutScenes) +{ + m_layoutScenes = layoutScenes; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::LayoutShadows() const -> QList +{ + return m_layoutShadows; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetLayoutShadows(const QList &layoutShadows) +{ + m_layoutShadows = layoutShadows; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::LayoutDetails() const -> QList > +{ + return m_layoutDetails; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetLayoutDetails(const QList > &layoutDetails) +{ + m_layoutDetails = layoutDetails; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::YScale() const -> qreal +{ + return m_yscale; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetYScale(const qreal &yscale) +{ + m_yscale = yscale; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::XScale() const -> qreal +{ + return m_xscale; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetXScale(const qreal &xscale) +{ + m_xscale = xscale; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline auto VPrintLayout::WatermarkPath() const -> QString +{ + return m_watermarkPath; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VPrintLayout::SetWatermarkPath(const QString &watermarkPath) +{ + m_watermarkPath = watermarkPath; +} +#endif // VPRINTLAYOUT_H diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index dfb1bc9ba..ae80816f6 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -277,28 +277,6 @@ QString AbsoluteMPath(const QString &patternPath, const QString &relativeMPath) return QFileInfo(QFileInfo(patternPath).absoluteDir(), relativeMPath).absoluteFilePath(); } -//--------------------------------------------------------------------------------------------------------------------- -QSharedPointer PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode) -{ - QPrinterInfo tmpInfo = info; - if(tmpInfo.isNull() || tmpInfo.printerName().isEmpty()) - { - const QStringList list = QPrinterInfo::availablePrinterNames(); - if(list.isEmpty()) - { - return QSharedPointer(); - } - else - { - tmpInfo = QPrinterInfo::printerInfo(list.first()); - } - } - - auto printer = QSharedPointer(new QPrinter(tmpInfo, mode)); - printer->setResolution(static_cast(PrintDPI)); - return printer; -} - //--------------------------------------------------------------------------------------------------------------------- QMarginsF GetMinPrinterFields(const QSharedPointer &printer) { diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 73f8f96ff..6df4b410b 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -602,9 +602,6 @@ Q_REQUIRED_RESULT QString AbsoluteMPath(const QString &patternPath, const QStrin QStringList SplitFilePaths(const QString &path); -Q_REQUIRED_RESULT QSharedPointer PreparePrinter(const QPrinterInfo &info, - QPrinter::PrinterMode mode = QPrinter::ScreenResolution); - QMarginsF GetMinPrinterFields(const QSharedPointer &printer); QMarginsF GetPrinterFields(const QSharedPointer &printer); diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index c751b1783..61ce7fab3 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -47,6 +47,8 @@ #include "../vmisc/compatibility.h" #include "../vpatterndb/pmsystems.h" +Q_DECLARE_METATYPE(QMarginsF) + namespace { Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPathsIndividualMeasurements, (QLatin1String("paths/individual_measurements"))) @@ -105,6 +107,9 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserDateFormats, (QLatin1St Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelTimeFormat, (QLatin1String("label/timeFormat"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingLabelUserTimeFormats, (QLatin1String("label/userTimeFormats"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFMargins, (QLatin1String("tiledPDF/margins"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFOrientation, (QLatin1String("tiledPDF/orientation"))) + // Reading settings file is very expensive, cache curve approximation to speed up getting value qreal curveApproximationCached = -1; Q_GLOBAL_STATIC(QString, localeCached) @@ -1216,3 +1221,43 @@ qreal VCommonSettings::WidthHairLine() const { return WidthMainLine()/3.0; } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetTiledPDFMargins returns the tiled pdf margins in the given unit. When the setting is + * called for the first time, the 4 default margins are 10mm. + * @param unit the unit in which are the value. Necessary because we save the values + * internaly as mm so there is conversion beeing made. + * @return tiled pdf margins + */ +auto VCommonSettings::GetTiledPDFMargins(const Unit &unit) const -> QMarginsF +{ + // default value is 10mm. We save the margins in mm in the setting. + return UnitConvertor(ValueOrDef(*settingTiledPDFMargins, QMarginsF(10, 10, 10, 10)), Unit::Mm, unit); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief SetTiledPDFMargins sets the setting tiled pdf margins to the given value. + * @param value the margins to save + * @param unit the unit in which are the value. Necessary because we save the values + * internaly as mm so there is conversion beeing made. + */ +void VCommonSettings::SetTiledPDFMargins(const QMarginsF &value, const Unit &unit) +{ + setValue(*settingTiledPDFMargins, QVariant::fromValue(UnitConvertor(value, unit, Unit::Mm))); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VCommonSettings::GetTiledPDFOrientation() const -> PageOrientation +{ + bool defaultValue = static_cast(PageOrientation::Portrait); + bool result = value(*settingTiledPDFOrientation, defaultValue).toBool(); + return static_cast(result); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetTiledPDFOrientation(PageOrientation value) +{ + setValue(*settingTiledPDFOrientation, static_cast (value)); +} diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index dcaf01daf..5d2be7c25 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -38,6 +38,11 @@ #include #include +#include "../vmisc/def.h" +#include "../vlayout/vlayoutdef.h" + +class QMarginsF; + class VCommonSettings : public QSettings { Q_OBJECT @@ -224,6 +229,18 @@ public: void SetLineWidth(qreal width); qreal WidthMainLine() const; qreal WidthHairLine() const; + + // settings for the tiled PDFs + auto GetTiledPDFMargins(const Unit &unit) const -> QMarginsF; + void SetTiledPDFMargins(const QMarginsF &value, const Unit &unit); + + auto GetTiledPDFOrientation() const -> PageOrientation; + void SetTiledPDFOrientation(PageOrientation value); + +protected: + template + T ValueOrDef(const QString &setting, const T &defValue) const; + private: Q_DISABLE_COPY(VCommonSettings) }; @@ -246,4 +263,28 @@ inline qreal VCommonSettings::MaximalLineWidth() return 5.0; // mm } +//--------------------------------------------------------------------------------------------------------------------- +template +inline T VCommonSettings::ValueOrDef(const QString &setting, const T &defValue) const +{ + const QVariant val = value(setting, QVariant::fromValue(defValue)); + return val.canConvert() ? val.value() : defValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +template <> +inline Cases VCommonSettings::ValueOrDef(const QString &setting, const Cases &defValue) const +{ + const QVariant val = value(setting, QVariant::fromValue(static_cast(defValue))); + const int g = val.canConvert() ? val.value() : static_cast(defValue); + if (g < static_cast(Cases::CaseThreeGroup) || g >= static_cast(Cases::UnknownCase)) + { + return defValue; + } + else + { + return static_cast(g); + } +} + #endif // VCOMMONSETTINGS_H diff --git a/src/libs/vmisc/vsettings.cpp b/src/libs/vmisc/vsettings.cpp index 4352bd70d..eb7686786 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/libs/vmisc/vsettings.cpp @@ -104,10 +104,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTextAsPaths, (QLatin1String("lay Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingNestingTime, (QLatin1String("layout/time"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingEfficiencyCoefficient, (QLatin1String("layout/efficiencyCoefficient"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFMargins, (QLatin1String("tiledPDF/margins"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFPaperHeight, (QLatin1String("tiledPDF/paperHeight"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFPaperWidth, (QLatin1String("tiledPDF/paperWidth"))) -Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingTiledPDFOrientation, (QLatin1String("tiledPDF/orientation"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingDuration, (QLatin1String("scrolling/duration"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingScrollingUpdateInterval, (QLatin1String("scrolling/updateInterval"))) @@ -148,30 +146,6 @@ VSettings::VSettings(const QString &fileName, QSettings::Format format, QObject qRegisterMetaTypeStreamOperators("QMarginsF"); } -//--------------------------------------------------------------------------------------------------------------------- -template -inline T VSettings::ValueOrDef(const QString &setting, const T &defValue) const -{ - const QVariant val = value(setting, QVariant::fromValue(defValue)); - return val.canConvert() ? val.value() : defValue; -} - -//--------------------------------------------------------------------------------------------------------------------- -template <> -inline Cases VSettings::ValueOrDef(const QString &setting, const Cases &defValue) const -{ - const QVariant val = value(setting, QVariant::fromValue(static_cast(defValue))); - const int g = val.canConvert() ? val.value() : static_cast(defValue); - if (g < static_cast(Cases::CaseThreeGroup) || g >= static_cast(Cases::UnknownCase)) - { - return defValue; - } - else - { - return static_cast(g); - } -} - //--------------------------------------------------------------------------------------------------------------------- QString VSettings::GetLabelLanguage() const { @@ -563,32 +537,6 @@ void VSettings::SetRememberPatternMaterials(bool value) } // settings for the tiled PDFs -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief GetTiledPDFMargins returns the tiled pdf margins in the given unit. When the setting is - * called for the first time, the 4 default margins are 10mm. - * @param unit the unit in which are the value. Necessary because we save the values - * internaly as mm so there is conversion beeing made. - * @return tiled pdf margins - */ -QMarginsF VSettings::GetTiledPDFMargins(const Unit &unit) const -{ - // default value is 10mm. We save the margins in mm in the setting. - return UnitConvertor(ValueOrDef(*settingTiledPDFMargins, QMarginsF(10, 10, 10, 10)), Unit::Mm, unit); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief SetTiledPDFMargins sets the setting tiled pdf margins to the given value. - * @param value the margins to save - * @param unit the unit in which are the value. Necessary because we save the values - * internaly as mm so there is conversion beeing made. - */ -void VSettings::SetTiledPDFMargins(const QMarginsF &value, const Unit &unit) -{ - setValue(*settingTiledPDFMargins, QVariant::fromValue(UnitConvertor(value, unit, Unit::Mm))); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetTiledPDFPaperHeight returns the paper height of tiled pdf in the desired unit. @@ -635,20 +583,6 @@ void VSettings::SetTiledPDFPaperWidth(qreal value, const Unit &unit) setValue(*settingTiledPDFPaperWidth, UnitConvertor(value,unit, Unit::Mm)); } -//--------------------------------------------------------------------------------------------------------------------- -PageOrientation VSettings::GetTiledPDFOrientation() const -{ - bool defaultValue = static_cast(PageOrientation::Portrait); - bool result = value(*settingTiledPDFOrientation, defaultValue).toBool(); - return static_cast(result); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VSettings::SetTiledPDFOrientation(PageOrientation value) -{ - setValue(*settingTiledPDFOrientation, static_cast (value)); -} - //--------------------------------------------------------------------------------------------------------------------- int VSettings::GetScrollingDuration() const { diff --git a/src/libs/vmisc/vsettings.h b/src/libs/vmisc/vsettings.h index f8a798569..3f9133426 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/libs/vmisc/vsettings.h @@ -141,18 +141,12 @@ public: void SetRememberPatternMaterials(bool value); // settings for the tiled PDFs - QMarginsF GetTiledPDFMargins(const Unit &unit) const; - void SetTiledPDFMargins(const QMarginsF &value, const Unit &unit); - qreal GetTiledPDFPaperHeight(const Unit &unit) const; void SetTiledPDFPaperHeight(qreal value, const Unit &unit); qreal GetTiledPDFPaperWidth(const Unit &unit) const; void SetTiledPDFPaperWidth(qreal value, const Unit &unit); - PageOrientation GetTiledPDFOrientation() const; - void SetTiledPDFOrientation(PageOrientation value); - static const int defaultScrollingDuration; static const int scrollingDurationMin; static const int scrollingDurationMax; @@ -213,10 +207,7 @@ private: Q_DISABLE_COPY(VSettings) template - T GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const; - - template - T ValueOrDef(const QString &setting, const T &defValue) const; + T GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const; }; #endif // VSETTINGS_H From 510a5ab6a71c4ad7166621c9adee7d9e5266e28e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 23 Dec 2020 15:42:30 +0200 Subject: [PATCH 21/21] Refactoring. --- src/libs/vlayout/vprintlayout.cpp | 72 +++++++++++++++++-------------- src/libs/vlayout/vprintlayout.h | 3 ++ 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/libs/vlayout/vprintlayout.cpp b/src/libs/vlayout/vprintlayout.cpp index 7e882edff..ecffcc46a 100644 --- a/src/libs/vlayout/vprintlayout.cpp +++ b/src/libs/vlayout/vprintlayout.cpp @@ -312,14 +312,6 @@ void VPrintLayout::PrintPreview() //--------------------------------------------------------------------------------------------------------------------- void VPrintLayout::PrintPages(QPrinter *printer) { - // Here we try understand difference between printer's dpi and our. - // Get printer rect acording to our dpi. - const QRectF printerPageRect(0, 0, ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm), - ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm)); - const QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution()); - const double xscale = pageRect.width() / printerPageRect.width(); - const double yscale = pageRect.height() / printerPageRect.height(); - QPainter painter; if (not painter.begin(printer)) { // failed to open file @@ -391,29 +383,15 @@ void VPrintLayout::PrintPages(QPrinter *printer) copyCount = printer->copyCount(); } - VWatermarkData data; - if (not m_watermarkPath.isEmpty()) - { - try - { - VWatermarkConverter converter(m_watermarkPath); - VWatermark watermark; - watermark.setXMLContent(converter.Convert()); - data = watermark.GetWatermark(); + VWatermarkData data = WatermarkData(); - if (not data.path.isEmpty()) - { - // Clean previous cache - QPixmapCache::remove(AbsoluteMPath(m_watermarkPath, data.path)); - } - } - catch (VException &e) - { - const QString errorMsg = tr("File error.\n\n%1\n\n%2").arg(e.ErrorMessage(), e.DetailedInformation()); - qApp->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; - } - } + // Here we try understand difference between printer's dpi and our. + // Get printer rect acording to our dpi. + const QRectF printerPageRect(0, 0, ToPixel(printer->pageRect(QPrinter::Millimeter).width(), Unit::Mm), + ToPixel(printer->pageRect(QPrinter::Millimeter).height(), Unit::Mm)); + const QRect pageRect = printer->pageLayout().paintRectPixels(printer->resolution()); + const double xscale = pageRect.width() / printerPageRect.width(); + const double yscale = pageRect.height() / printerPageRect.height(); for (int i = 0; i < copyCount; ++i) { @@ -465,8 +443,8 @@ void VPrintLayout::PrintPages(QPrinter *printer) QPageLayout layout = printer->pageLayout(); layout.setUnits(QPageLayout::Millimeter); QMarginsF printerMargins = layout.margins(); - x = qFloor(ToPixel(printerMargins.left(),Unit::Mm)); - y = qFloor(ToPixel(printerMargins.top(),Unit::Mm)); + x = qFloor(ToPixel(printerMargins.left(), Unit::Mm)); + y = qFloor(ToPixel(printerMargins.top(), Unit::Mm)); } else { @@ -736,6 +714,36 @@ auto VPrintLayout::IsPagesFit(QSizeF printPaper) const -> bool return pSize.height() <= printPaper.height() && pSize.width() <= printPaper.width(); } +//--------------------------------------------------------------------------------------------------------------------- +auto VPrintLayout::WatermarkData() const -> VWatermarkData +{ + VWatermarkData data; + if (m_isTiled && not m_watermarkPath.isEmpty()) + { + try + { + VWatermarkConverter converter(m_watermarkPath); + VWatermark watermark; + watermark.setXMLContent(converter.Convert()); + data = watermark.GetWatermark(); + + if (not data.path.isEmpty()) + { + // Clean previous cache + QPixmapCache::remove(AbsoluteMPath(m_watermarkPath, data.path)); + } + } + catch (VException &e) + { + const QString errorMsg = tr("File error.\n\n%1\n\n%2").arg(e.ErrorMessage(), e.DetailedInformation()); + qApp->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg; + } + } + + return data; +} + //--------------------------------------------------------------------------------------------------------------------- auto VPrintLayout::ContinueIfLayoutStale(QWidget *parent) -> int { diff --git a/src/libs/vlayout/vprintlayout.h b/src/libs/vlayout/vprintlayout.h index 2440de0cc..46e1033f2 100644 --- a/src/libs/vlayout/vprintlayout.h +++ b/src/libs/vlayout/vprintlayout.h @@ -38,6 +38,7 @@ enum class PrintType : qint8 {PrintPDF, PrintPreview, PrintNative}; class QPrinter; class QGraphicsScene; +struct VWatermarkData; class VPrintLayout : public QObject { @@ -168,6 +169,8 @@ private: bool IsPagesUniform() const; bool IsPagesFit(QSizeF printPaper) const; + + auto WatermarkData() const -> VWatermarkData; }; //---------------------------------------------------------------------------------------------------------------------