From 05b094deece7f60906191b1973d5d30e23aee52d Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 17 Jun 2016 16:42:38 +0200 Subject: [PATCH 01/66] Added a class to hold pattern piece data --HG-- branch : feature --- src/app/share/collection/TestDart.val | 2 +- src/app/valentina/xml/vpattern.cpp | 14 +++ src/libs/ifc/schema/pattern/v0.3.1.xsd | 2 +- src/libs/ifc/xml/vabstractpattern.cpp | 2 + src/libs/ifc/xml/vabstractpattern.h | 2 + src/libs/ifc/xml/vpatternconverter.cpp | 3 +- src/libs/vpatterndb/vdetail.cpp | 11 +++ src/libs/vpatterndb/vdetail.h | 3 + src/libs/vpatterndb/vdetail_p.h | 4 + src/libs/vpatterndb/vpatterndb.pro | 6 ++ src/libs/vpatterndb/vpatternpiecedata.cpp | 111 ++++++++++++++++++++++ src/libs/vpatterndb/vpatternpiecedata.h | 94 ++++++++++++++++++ 12 files changed, 251 insertions(+), 3 deletions(-) create mode 100644 src/libs/vpatterndb/vpatternpiecedata.cpp create mode 100644 src/libs/vpatterndb/vpatternpiecedata.h diff --git a/src/app/share/collection/TestDart.val b/src/app/share/collection/TestDart.val index bc3d1d8c4..5808117af 100644 --- a/src/app/share/collection/TestDart.val +++ b/src/app/share/collection/TestDart.val @@ -1,7 +1,7 @@ - 0.2.4 + 0.3.1 cm diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index d6fd0c0c4..d188644db 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -629,6 +629,20 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document } detail.append(VNodeDetail(id, tool, nodeType, mx, my, reverse)); } + else if (element.tagName() == TagData) + { + try + { + QString qsName = GetParametrString(element, AttrName); + detail.GetPatternPieceData().SetName(qsName); + QString qsLetter = GetParametrString(element, AttrLetter); + detail.GetPatternPieceData().SetLetter(qsLetter); + qDebug() << "Data" << qsName << qsLetter; + } + catch(const VException& e) + { + } + } } } VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile); diff --git a/src/libs/ifc/schema/pattern/v0.3.1.xsd b/src/libs/ifc/schema/pattern/v0.3.1.xsd index d5af28adf..af3eaa1b6 100644 --- a/src/libs/ifc/schema/pattern/v0.3.1.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.1.xsd @@ -332,7 +332,7 @@ - + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index a8bc66609..534dc0110 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -60,12 +60,14 @@ const QString VAbstractPattern::TagGradation = QStringLiteral("gradation"); const QString VAbstractPattern::TagHeights = QStringLiteral("heights"); const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); const QString VAbstractPattern::TagUnit = QStringLiteral("unit"); +const QString VAbstractPattern::TagData = QStringLiteral("data"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); const QString VAbstractPattern::AttrObject = QStringLiteral("object"); const QString VAbstractPattern::AttrTool = QStringLiteral("tool"); const QString VAbstractPattern::AttrType = QStringLiteral("type"); +const QString VAbstractPattern::AttrLetter = QStringLiteral("letter"); const QString VAbstractPattern::AttrAll = QStringLiteral("all"); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 172f7cce3..5f97aed21 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -155,12 +155,14 @@ public: static const QString TagHeights; static const QString TagSizes; static const QString TagUnit; + static const QString TagData; static const QString AttrName; static const QString AttrVisible; static const QString AttrObject; static const QString AttrTool; static const QString AttrType; + static const QString AttrLetter; static const QString AttrAll; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 5068702ef..b4019754c 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -163,7 +163,8 @@ void VPatternConverter::ApplyPatches() V_FALLTHROUGH case (0x000203): ToV0_2_4(); - ValidateXML(XSDSchema(0x000204), fileName); + //ValidateXML(XSDSchema(0x000204), fileName); + ValidateXML(XSDSchema(0x000302), fileName); V_FALLTHROUGH case (0x000204): ToV0_2_5(); diff --git a/src/libs/vpatterndb/vdetail.cpp b/src/libs/vpatterndb/vdetail.cpp index d7a2e8db2..71e44b97e 100644 --- a/src/libs/vpatterndb/vdetail.cpp +++ b/src/libs/vpatterndb/vdetail.cpp @@ -512,6 +512,17 @@ QVector VDetail::listNodePoint() const return list; } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Returns the full access to the pattern piece data object + * @return pattern piece data object + */ +VPatternPieceData& VDetail::GetPatternPieceData() +{ + return d->m_ppData; +} + + //--------------------------------------------------------------------------------------------------------------------- /** * @brief indexOfNode return index in list node using id object. diff --git a/src/libs/vpatterndb/vdetail.h b/src/libs/vpatterndb/vdetail.h index fb57ab56e..8e84b1393 100644 --- a/src/libs/vpatterndb/vdetail.h +++ b/src/libs/vpatterndb/vdetail.h @@ -33,6 +33,7 @@ #include #include "../vlayout/vabstractdetail.h" +#include "vpatternpiecedata.h" class VDetailData; class VContainer; @@ -84,6 +85,8 @@ public: QPainterPath ContourPath(const VContainer *data) const; QPainterPath SeamAllowancePath(const VContainer *data) const; QVector listNodePoint()const; + VPatternPieceData& GetPatternPieceData(); + private: QSharedDataPointer d; diff --git a/src/libs/vpatterndb/vdetail_p.h b/src/libs/vpatterndb/vdetail_p.h index 72aff357a..bcb470238 100644 --- a/src/libs/vpatterndb/vdetail_p.h +++ b/src/libs/vpatterndb/vdetail_p.h @@ -31,6 +31,7 @@ #include #include "vnodedetail.h" +#include "vpatternpiecedata.h" #include "../ifc/ifcdef.h" #ifdef Q_CC_GNU @@ -67,6 +68,9 @@ public: /** @brief my bias y axis. */ qreal my; + /** @brief Pattern piece data */ + VPatternPieceData m_ppData; + private: VDetailData &operator=(const VDetailData &) Q_DECL_EQ_DELETE; }; diff --git a/src/libs/vpatterndb/vpatterndb.pro b/src/libs/vpatterndb/vpatterndb.pro index 28d254840..5b38b1dee 100644 --- a/src/libs/vpatterndb/vpatterndb.pro +++ b/src/libs/vpatterndb/vpatterndb.pro @@ -100,3 +100,9 @@ CONFIG(debug, debug|release){ } } } + +HEADERS += \ + vpatternpiecedata.h + +SOURCES += \ + vpatternpiecedata.cpp diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp new file mode 100644 index 000000000..e309202c5 --- /dev/null +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -0,0 +1,111 @@ +/************************************************************************ + ** + ** @file vpatternpiecedata.h + ** @author Bojan Kverh + ** @date June 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 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 "vpatternpiecedata.h" + +//--------------------------------------------------------------------------------------------------------------------- + +VPatternPieceData::VPatternPieceData() +{} + +//--------------------------------------------------------------------------------------------------------------------- + +VPatternPieceData::~VPatternPieceData() +{} + +//--------------------------------------------------------------------------------------------------------------------- + +void VPatternPieceData::Append(const MaterialCutPlacement& rMCP) +{ + m_conMCP.append(rMCP); +} + +//--------------------------------------------------------------------------------------------------------------------- + +void VPatternPieceData::Insert(int i, const MaterialCutPlacement& rMCP) +{ + Q_ASSERT(i >= 0); + Q_ASSERT(i <= GetMCPCount()); + m_conMCP.insert(i, rMCP); +} + +//--------------------------------------------------------------------------------------------------------------------- + +int VPatternPieceData::GetMCPCount() const +{ + return m_conMCP.count(); +} + +//--------------------------------------------------------------------------------------------------------------------- + +const MaterialCutPlacement& VPatternPieceData::GetMCP(int i) const +{ + Q_ASSERT(i >= 0); + Q_ASSERT(i < GetMCPCount()); + return m_conMCP[i]; +} + +//--------------------------------------------------------------------------------------------------------------------- + +void VPatternPieceData::RemoveMCP(int i) +{ + Q_ASSERT(i >= 0); + Q_ASSERT(i < GetMCPCount()); + m_conMCP.removeAt(i); +} + +//--------------------------------------------------------------------------------------------------------------------- + +QString VPatternPieceData::GetLetter() const +{ + return m_qsLetter; +} + +//--------------------------------------------------------------------------------------------------------------------- + +void VPatternPieceData::SetLetter(QString qsLetter) +{ + m_qsLetter = qsLetter.left(3); +} + +//--------------------------------------------------------------------------------------------------------------------- + +QString VPatternPieceData::GetName() const +{ + return m_qsName; +} + +//--------------------------------------------------------------------------------------------------------------------- + +void VPatternPieceData::SetName(QString qsName) +{ + m_qsName = qsName; +} + +//--------------------------------------------------------------------------------------------------------------------- + diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h new file mode 100644 index 000000000..287971b98 --- /dev/null +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -0,0 +1,94 @@ +#ifndef VPATTERNPIECEDATA_H +#define VPATTERNPIECEDATA_H + +/************************************************************************ + ** + ** @file vpatternpiecedata.h + ** @author Bojan Kverh + ** @date June 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 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 +#include + +enum class MaterialType : char +{ + mtFabric, + mtLining, + mtInterfacing, + mtInterlining, + mtUserDefined +}; + +enum class PlacementType : char { ptNone, ptCutOnFold }; + +/** + * @brief This structure holds a material, cut number and placement 3-tuple + */ +struct MaterialCutPlacement +{ + MaterialType m_eMaterial; + QString m_qsMaterialUserDef; + int m_iCutNumber; + PlacementType m_ePlacement; +}; + +typedef QList MCPContainer; + +/** + * @brief The VPatternPieceData class holds some information about a single + * piece like letter, name, material type, cut number and placement. + */ +class VPatternPieceData +{ +public: + VPatternPieceData(); + ~VPatternPieceData(); + + // methods, which operate on MaterialCutPlacement container + void Append(const MaterialCutPlacement& rMCP); + void Insert(int i, const MaterialCutPlacement& rMCP); + int GetMCPCount() const; + const MaterialCutPlacement& GetMCP(int i) const; + void RemoveMCP(int i); + + // methods, which operate on other members + QString GetLetter() const; + void SetLetter(QString qsLetter); + QString GetName() const; + void SetName(QString qsName); + +private: + /** @brief Pattern piece name + */ + QString m_qsName; + /** @brief Pattern piece letter (should be no more than 3 letters) + */ + QString m_qsLetter; + /** @brief List of material, cut number and placement 3-tuples + */ + MCPContainer m_conMCP; +}; + +#endif // VPATTERNPIECEDATA_H From 1899abc39e1480c95766a9e92014c293e59769d7 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 18 Jun 2016 16:00:01 +0200 Subject: [PATCH 02/66] Added pattern piece data dialog, which can be accessed with right mouse click in Detail mode --HG-- branch : feature --- src/app/share/collection/Keiko_skirt.val | 18 +- src/app/valentina/xml/vpattern.cpp | 4 +- src/libs/ifc/xml/vpatternconverter.cpp | 3 +- src/libs/vpatterndb/vdetail.cpp | 9 + src/libs/vpatterndb/vdetail.h | 3 +- src/libs/vpatterndb/vpatterndb.pri | 6 +- src/libs/vpatterndb/vpatterndb.pro | 5 - src/libs/vpatterndb/vpatternpiecedata.cpp | 21 +- src/libs/vpatterndb/vpatternpiecedata.h | 11 +- src/libs/vtools/dialogs/dialogs.pri | 7 +- .../dialogs/tools/dialogpatternpiecedata.cpp | 250 ++++++++++++++++++ .../dialogs/tools/dialogpatternpiecedata.h | 94 +++++++ src/libs/vtools/tools/vtooldetail.cpp | 34 ++- 13 files changed, 420 insertions(+), 45 deletions(-) create mode 100644 src/libs/vtools/dialogs/tools/dialogpatternpiecedata.cpp create mode 100644 src/libs/vtools/dialogs/tools/dialogpatternpiecedata.h diff --git a/src/app/share/collection/Keiko_skirt.val b/src/app/share/collection/Keiko_skirt.val index e097391eb..32ac3722d 100644 --- a/src/app/share/collection/Keiko_skirt.val +++ b/src/app/share/collection/Keiko_skirt.val @@ -1,7 +1,7 @@ - 0.2.4 + 0.3.1 cm @@ -26,14 +26,14 @@ - - - - - - - - + + + + + + + + diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index d188644db..05b1a8ffc 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -628,7 +628,7 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document throw e; } detail.append(VNodeDetail(id, tool, nodeType, mx, my, reverse)); - } + }/* else if (element.tagName() == TagData) { try @@ -642,7 +642,7 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document catch(const VException& e) { } - } + }*/ } } VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile); diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index b4019754c..5068702ef 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -163,8 +163,7 @@ void VPatternConverter::ApplyPatches() V_FALLTHROUGH case (0x000203): ToV0_2_4(); - //ValidateXML(XSDSchema(0x000204), fileName); - ValidateXML(XSDSchema(0x000302), fileName); + ValidateXML(XSDSchema(0x000204), fileName); V_FALLTHROUGH case (0x000204): ToV0_2_5(); diff --git a/src/libs/vpatterndb/vdetail.cpp b/src/libs/vpatterndb/vdetail.cpp index 71e44b97e..3f8bfea35 100644 --- a/src/libs/vpatterndb/vdetail.cpp +++ b/src/libs/vpatterndb/vdetail.cpp @@ -522,6 +522,15 @@ VPatternPieceData& VDetail::GetPatternPieceData() return d->m_ppData; } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Returns the read only reference to the pattern piece data object + * @return pattern piece data object + */ +const VPatternPieceData& VDetail::GetPatternPieceData() const +{ + return d->m_ppData; +} //--------------------------------------------------------------------------------------------------------------------- /** diff --git a/src/libs/vpatterndb/vdetail.h b/src/libs/vpatterndb/vdetail.h index 8e84b1393..55de6bd05 100644 --- a/src/libs/vpatterndb/vdetail.h +++ b/src/libs/vpatterndb/vdetail.h @@ -33,11 +33,11 @@ #include #include "../vlayout/vabstractdetail.h" -#include "vpatternpiecedata.h" class VDetailData; class VContainer; class QPainterPath; +class VPatternPieceData; /** * @brief The VDetail class for path of object (points, arcs, splines). @@ -86,6 +86,7 @@ public: QPainterPath SeamAllowancePath(const VContainer *data) const; QVector listNodePoint()const; VPatternPieceData& GetPatternPieceData(); + const VPatternPieceData& GetPatternPieceData() const; private: QSharedDataPointer d; diff --git a/src/libs/vpatterndb/vpatterndb.pri b/src/libs/vpatterndb/vpatterndb.pri index a9b035682..b0507d074 100644 --- a/src/libs/vpatterndb/vpatterndb.pri +++ b/src/libs/vpatterndb/vpatterndb.pri @@ -17,7 +17,8 @@ SOURCES += \ $$PWD/variables/vlinelength.cpp \ $$PWD/variables/vmeasurement.cpp \ $$PWD/variables/vvariable.cpp \ - $$PWD/vformula.cpp + $$PWD/vformula.cpp \ + $$PWD/vpatternpiecedata.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -49,4 +50,5 @@ HEADERS += \ $$PWD/variables/vmeasurement_p.h \ $$PWD/variables/vvariable.h \ $$PWD/variables/vvariable_p.h \ - $$PWD/vformula.h + $$PWD/vformula.h \ + $$PWD/vpatternpiecedata.h diff --git a/src/libs/vpatterndb/vpatterndb.pro b/src/libs/vpatterndb/vpatterndb.pro index 5b38b1dee..e796f437e 100644 --- a/src/libs/vpatterndb/vpatterndb.pro +++ b/src/libs/vpatterndb/vpatterndb.pro @@ -101,8 +101,3 @@ CONFIG(debug, debug|release){ } } -HEADERS += \ - vpatternpiecedata.h - -SOURCES += \ - vpatternpiecedata.cpp diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index e309202c5..618dd98db 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -29,24 +29,20 @@ #include "vpatternpiecedata.h" //--------------------------------------------------------------------------------------------------------------------- - VPatternPieceData::VPatternPieceData() {} //--------------------------------------------------------------------------------------------------------------------- - VPatternPieceData::~VPatternPieceData() {} //--------------------------------------------------------------------------------------------------------------------- - void VPatternPieceData::Append(const MaterialCutPlacement& rMCP) { m_conMCP.append(rMCP); } //--------------------------------------------------------------------------------------------------------------------- - void VPatternPieceData::Insert(int i, const MaterialCutPlacement& rMCP) { Q_ASSERT(i >= 0); @@ -55,14 +51,20 @@ void VPatternPieceData::Insert(int i, const MaterialCutPlacement& rMCP) } //--------------------------------------------------------------------------------------------------------------------- +void VPatternPieceData::Set(int i, const MaterialCutPlacement& rMCP) +{ + Q_ASSERT(i >= 0); + Q_ASSERT(i < GetMCPCount()); + m_conMCP[i] = rMCP; +} +//--------------------------------------------------------------------------------------------------------------------- int VPatternPieceData::GetMCPCount() const { return m_conMCP.count(); } //--------------------------------------------------------------------------------------------------------------------- - const MaterialCutPlacement& VPatternPieceData::GetMCP(int i) const { Q_ASSERT(i >= 0); @@ -71,7 +73,6 @@ const MaterialCutPlacement& VPatternPieceData::GetMCP(int i) const } //--------------------------------------------------------------------------------------------------------------------- - void VPatternPieceData::RemoveMCP(int i) { Q_ASSERT(i >= 0); @@ -80,28 +81,24 @@ void VPatternPieceData::RemoveMCP(int i) } //--------------------------------------------------------------------------------------------------------------------- - -QString VPatternPieceData::GetLetter() const +const QString& VPatternPieceData::GetLetter() const { return m_qsLetter; } //--------------------------------------------------------------------------------------------------------------------- - void VPatternPieceData::SetLetter(QString qsLetter) { m_qsLetter = qsLetter.left(3); } //--------------------------------------------------------------------------------------------------------------------- - -QString VPatternPieceData::GetName() const +const QString& VPatternPieceData::GetName() const { return m_qsName; } //--------------------------------------------------------------------------------------------------------------------- - void VPatternPieceData::SetName(QString qsName) { m_qsName = qsName; diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h index 287971b98..57622d6cf 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -1,6 +1,3 @@ -#ifndef VPATTERNPIECEDATA_H -#define VPATTERNPIECEDATA_H - /************************************************************************ ** ** @file vpatternpiecedata.h @@ -29,6 +26,9 @@ ** *************************************************************************/ +#ifndef VPATTERNPIECEDATA_H +#define VPATTERNPIECEDATA_H + #include #include @@ -69,14 +69,15 @@ public: // methods, which operate on MaterialCutPlacement container void Append(const MaterialCutPlacement& rMCP); void Insert(int i, const MaterialCutPlacement& rMCP); + void Set(int i, const MaterialCutPlacement& rMCP); int GetMCPCount() const; const MaterialCutPlacement& GetMCP(int i) const; void RemoveMCP(int i); // methods, which operate on other members - QString GetLetter() const; + const QString& GetLetter() const; void SetLetter(QString qsLetter); - QString GetName() const; + const QString& GetName() const; void SetName(QString qsName); private: diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index 1a358d539..e737ebe87 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -38,7 +38,9 @@ HEADERS += \ $$PWD/tools/dialogcubicbezier.h \ $$PWD/tools/dialogcubicbezierpath.h \ $$PWD/tools/dialoggroup.h \ - $$PWD/tools/dialogrotation.h + $$PWD/tools/dialogrotation.h \ + $$PWD/tools/dialogpatternpiecedata.h + SOURCES += \ $$PWD/tools/dialogalongline.cpp \ @@ -76,7 +78,8 @@ SOURCES += \ $$PWD/tools/dialogcubicbezier.cpp \ $$PWD/tools/dialogcubicbezierpath.cpp \ $$PWD/tools/dialoggroup.cpp \ - $$PWD/tools/dialogrotation.cpp + $$PWD/tools/dialogrotation.cpp \ + $$PWD/tools/dialogpatternpiecedata.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ diff --git a/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.cpp b/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.cpp new file mode 100644 index 000000000..3bdcc4b37 --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.cpp @@ -0,0 +1,250 @@ +/************************************************************************ + ** + ** @file vpatternconverter.cpp + ** @author Roman Telezhynskyi + ** @date 11 12, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 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 +#include +#include +#include +#include +#include + +#include "vpatternpiecedata.h" +#include "dialogpatternpiecedata.h" + +//--------------------------------------------------------------------------------------------------------------------- +DialogPatternPieceData::DialogPatternPieceData(const VContainer *data, const quint32 &toolId, QWidget *parent) : + DialogTool(data, toolId, parent) +{ + // main dialog layout + QVBoxLayout* pLayout = new QVBoxLayout(this); + + // widgets layout + QHBoxLayout* pWidgetsLayout = new QHBoxLayout; + + setWindowTitle(tr("Pattern piece data")); + QFormLayout* pFormLayout = new QFormLayout; + QLabel* plb; + + plb = new QLabel(tr("Letter") + ":"); + m_pleLetter = new QLineEdit; + m_pleLetter->setMaxLength(3); + pFormLayout->addRow(plb, m_pleLetter); + + plb = new QLabel(tr("Name") + ":"); + m_pleName = new QLineEdit; + m_pleName->setMaxLength(15); + pFormLayout->addRow(plb, m_pleName); + + pWidgetsLayout->addLayout(pFormLayout); + + QGroupBox* pgb = new QGroupBox(tr("Material/Cut number/Placement")); + QGridLayout* pLayoutGB = new QGridLayout(pgb); + + pFormLayout = new QFormLayout; + + plb = new QLabel(tr("Material type") + ":"); + m_pcbMaterial = new QComboBox; + m_pcbMaterial->setFixedWidth(200); + m_qslMaterials << tr("Fabric") << tr("Lining") << tr("Interfacing") << tr("Interlining"); + m_pcbMaterial->addItems(m_qslMaterials); + m_pcbMaterial->setEditable(true); + pFormLayout->addRow(plb, m_pcbMaterial); + + plb = new QLabel(tr("Cut number") + ":"); + m_psbCutNumber = new QSpinBox; + m_psbCutNumber->setRange(0, 1000); + pFormLayout->addRow(plb, m_psbCutNumber); + + plb = new QLabel(tr("Placement type") + ":"); + m_pcbPlacement = new QComboBox; + m_qslPlacements << tr("None") << tr("Cut on fold"); + m_pcbPlacement->addItems(m_qslPlacements); + pFormLayout->addRow(plb, m_pcbPlacement); + pLayoutGB->addLayout(pFormLayout, 0, 0); + + QHBoxLayout* pMCPButtonLayout = new QHBoxLayout; + m_pbOpAddUpdate = new QPushButton; + connect(m_pbOpAddUpdate, &QPushButton::clicked, this, &DialogPatternPieceData::AddUpdate); + pMCPButtonLayout->addStretch(1); + pMCPButtonLayout->addWidget(m_pbOpAddUpdate); + m_pbOpCancel = new QPushButton(tr("Cancel")); + connect(m_pbOpCancel, &QPushButton::clicked, this, &DialogPatternPieceData::Cancel); + pMCPButtonLayout->addWidget(m_pbOpCancel); + m_pbOpRemove = new QPushButton(tr("Remove")); + connect(m_pbOpRemove, &QPushButton::clicked, this, &DialogPatternPieceData::Remove); + pMCPButtonLayout->addWidget(m_pbOpRemove); + pLayoutGB->addLayout(pMCPButtonLayout, 1, 0); + + m_plwMCP = new QListWidget; + connect(m_plwMCP, &QListWidget::itemClicked, this, &DialogPatternPieceData::SetEditMode); + pLayoutGB->addWidget(m_plwMCP, 0, 1, 3, 1); + pLayoutGB->setRowStretch(2, 1); + pLayoutGB->setColumnStretch(2, 1); + + pWidgetsLayout->addWidget(pgb); + + pWidgetsLayout->setStretch(2, 1); + + pLayout->addLayout(pWidgetsLayout); + + QHBoxLayout* pButtonsLayout = new QHBoxLayout; + pButtonsLayout->addStretch(0); + bOk = new QPushButton(tr("OK")); + connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted); + QPushButton* pbCancel = new QPushButton(tr("Cancel")); + connect(pbCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected); + pButtonsLayout->addWidget(bOk); + pButtonsLayout->addWidget(pbCancel); + + pLayout->addLayout(pButtonsLayout); + pLayout->setStretch(0, 1); + + SetAddMode(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternPieceData::SetDetail(const VDetail& rDetail) +{ + m_detail = rDetail; + m_pleLetter->setText(m_detail.GetPatternPieceData().GetLetter()); + m_pleName->setText(m_detail.GetPatternPieceData().GetName()); + UpdateList(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternPieceData::SaveData() +{ + m_detail.GetPatternPieceData().SetLetter(m_pleLetter->text()); + m_detail.GetPatternPieceData().SetName(m_pleName->text()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternPieceData::UpdateList() +{ + m_plwMCP->clear(); + for (int i = 0; i < m_detail.GetPatternPieceData().GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = m_detail.GetPatternPieceData().GetMCP(i); + QString qsText = tr("Cut %1 of %2%3"); + qsText = qsText.arg(mcp.m_iCutNumber); + if (mcp.m_eMaterial < MaterialType::mtUserDefined) + qsText = qsText.arg(m_qslMaterials[int(mcp.m_eMaterial)]); + else + qsText = qsText.arg(mcp.m_qsMaterialUserDef); + if (mcp.m_ePlacement == PlacementType::ptCutOnFold) + qsText = qsText.arg(tr(" on Fold")); + else + qsText = qsText.arg(""); + + m_plwMCP->addItem(qsText); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternPieceData::AddUpdate() +{ + MaterialCutPlacement mcp; + mcp.m_qsMaterialUserDef = m_pcbMaterial->currentText(); + mcp.m_eMaterial = MaterialType::mtUserDefined; + for (int i = 0; i < m_qslMaterials.count(); ++i) + if (mcp.m_qsMaterialUserDef == m_qslMaterials[i]) + mcp.m_eMaterial = MaterialType(i); + + mcp.m_iCutNumber = m_psbCutNumber->value(); + mcp.m_ePlacement = PlacementType(m_pcbPlacement->currentIndex()); + + if (m_bAddMode == true) + { + m_detail.GetPatternPieceData().Append(mcp); + } + else + { + int iR = m_plwMCP->currentRow(); + SCASSERT(iR >= 0); + m_detail.GetPatternPieceData().Set(iR, mcp); + SetAddMode(); + } + UpdateList(); + ClearFields(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternPieceData::Cancel() +{ + ClearFields(); + SetAddMode(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternPieceData::Remove() +{ + int iR = m_plwMCP->currentRow(); + SCASSERT(iR >= 0); + m_detail.GetPatternPieceData().RemoveMCP(iR); + UpdateList(); + ClearFields(); + SetAddMode(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternPieceData::ClearFields() +{ + m_pcbMaterial->setCurrentIndex(0); + m_psbCutNumber->setValue(0); + m_pcbPlacement->setCurrentIndex(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternPieceData::SetAddMode() +{ + m_pbOpAddUpdate->setText(tr("Add")); + m_pbOpCancel->hide(); + m_pbOpRemove->hide(); + m_plwMCP->setCurrentRow(-1); + m_bAddMode = true; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternPieceData::SetEditMode() +{ + int iR = m_plwMCP->currentRow(); + // this method can be called by clicking on item or by update. In the latter case there is nothing else to do! + if (iR < 0 || iR >= m_detail.GetPatternPieceData().GetMCPCount()) + return; + + m_pbOpAddUpdate->setText(tr("Update")); + m_pbOpCancel->show(); + m_pbOpRemove->show(); + + MaterialCutPlacement mcp = m_detail.GetPatternPieceData().GetMCP(iR); + m_pcbMaterial->setCurrentText(mcp.m_qsMaterialUserDef); + m_psbCutNumber->setValue(mcp.m_iCutNumber); + m_pcbPlacement->setCurrentIndex(int(mcp.m_ePlacement)); + + m_bAddMode = false; +} diff --git a/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.h b/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.h new file mode 100644 index 000000000..ff2511c3a --- /dev/null +++ b/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.h @@ -0,0 +1,94 @@ +/************************************************************************ + ** + ** @file vpatternconverter.cpp + ** @author Roman Telezhynskyi + ** @date 11 12, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 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 DIALOGPATTERNPIECEDATA_H +#define DIALOGPATTERNPIECEDATA_H + +#include +#include +#include +#include +#include + +#include "vdetail.h" +#include "dialogtool.h" + +/** + * @brief This dialog allows user to edit pattern piece meta data + */ +class DialogPatternPieceData : public DialogTool +{ + Q_OBJECT + +public: + DialogPatternPieceData(const VContainer* data, const quint32& toolId, QWidget* parent = nullptr); + + VDetail GetDetail() const; + void SetDetail(const VDetail& rDetail); + + void SaveData(); + +protected slots: + void UpdateList(); + void AddUpdate(); + void Cancel(); + void Remove(); + +private: + VDetail m_detail; + + QLineEdit* m_pleName; + QLineEdit* m_pleLetter; + QComboBox* m_pcbMaterial; + QSpinBox* m_psbCutNumber; + QComboBox* m_pcbPlacement; + + QPushButton* m_pbOpAddUpdate; + QPushButton* m_pbOpCancel; + QPushButton* m_pbOpRemove; + + QListWidget* m_plwMCP; + + QStringList m_qslMaterials; + QStringList m_qslPlacements; + + bool m_bAddMode; + + void ClearFields(); + +private slots: + void SetAddMode(); + void SetEditMode(); +}; + +inline VDetail DialogPatternPieceData::GetDetail() const +{ + return m_detail; +} + +#endif // DIALOGPATTERNPIECEDATA_H diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index b6e311cf1..b2292b28a 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -36,10 +36,12 @@ #include "../vwidgets/vmaingraphicsview.h" #include "../dialogs/tools/dialogtool.h" #include "../dialogs/tools/dialogdetail.h" +#include "../dialogs/tools/dialogpatternpiecedata.h" #include "../undocommands/savedetailoptions.h" #include "../undocommands/movedetail.h" #include "../undocommands/adddet.h" #include "../undocommands/deletedetail.h" +#include "vpatternpiecedata.h" #include #include @@ -293,10 +295,21 @@ void VToolDetail::FullUpdateFromGuiOk(int result) if (result == QDialog::Accepted) { SCASSERT(dialog != nullptr); - DialogDetail *dialogTool = qobject_cast(dialog); - SCASSERT(dialogTool != nullptr); - VDetail newDet = dialogTool->getDetail(); + VDetail newDet; VDetail oldDet = VAbstractTool::data.GetDetail(id); + DialogDetail *dialogTool = qobject_cast(dialog); + //SCASSERT(dialogTool != nullptr); + + if (dialogTool != nullptr) + { + newDet = dialogTool->getDetail(); + } + else + { + DialogPatternPieceData* dialogPPD = qobject_cast(dialog); + SCASSERT(dialogPPD != nullptr); + newDet = dialogPPD->GetDetail(); + } SaveDetailOptions *saveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); connect(saveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); @@ -518,7 +531,7 @@ void VToolDetail::hoverEnterEvent(QGraphicsSceneHoverEvent *event) } } -////--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- void VToolDetail::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); @@ -538,6 +551,7 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { QMenu menu; QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options")); + QAction* actionData = menu.addAction(tr("Details info")); QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); if (_referens > 1) { @@ -558,7 +572,17 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) setDialog(); dialog->show(); } - if (selectedAction == actionRemove) + else if (selectedAction == actionData) + { + dialog = new DialogPatternPieceData(getData(), id, qApp->getMainWindow()); + dialog->setModal(true); + + connect(dialog, &DialogTool::DialogClosed, this, &VToolDetail::FullUpdateFromGuiOk); + VDetail detail = VAbstractTool::data.GetDetail(id); + qobject_cast(dialog)->SetDetail(detail); + dialog->show(); + } + else if (selectedAction == actionRemove) { try { From 8140647242210523a628d7d387f631ac0ed782c1 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 18 Jun 2016 22:14:35 +0200 Subject: [PATCH 03/66] Updated detail dialog with pattern piece data editing --HG-- branch : feature --- src/libs/vpatterndb/vdetail_p.h | 3 +- src/libs/vtools/dialogs/dialogs.pri | 6 +- .../vtools/dialogs/tools/dialogdetail.cpp | 133 +++ src/libs/vtools/dialogs/tools/dialogdetail.h | 19 + src/libs/vtools/dialogs/tools/dialogdetail.ui | 953 +++++++++++------- .../dialogs/tools/dialogpatternpiecedata.cpp | 250 ----- .../dialogs/tools/dialogpatternpiecedata.h | 94 -- src/libs/vtools/tools/vtooldetail.cpp | 34 +- 8 files changed, 746 insertions(+), 746 deletions(-) delete mode 100644 src/libs/vtools/dialogs/tools/dialogpatternpiecedata.cpp delete mode 100644 src/libs/vtools/dialogs/tools/dialogpatternpiecedata.h diff --git a/src/libs/vpatterndb/vdetail_p.h b/src/libs/vpatterndb/vdetail_p.h index bcb470238..1c7dcfce0 100644 --- a/src/libs/vpatterndb/vdetail_p.h +++ b/src/libs/vpatterndb/vdetail_p.h @@ -51,7 +51,8 @@ public: {} VDetailData(const VDetailData &detail) - :QSharedData(detail), _id(NULL_ID), nodes(detail.nodes), mx(detail.mx), my(detail.my) + :QSharedData(detail), _id(NULL_ID), nodes(detail.nodes), mx(detail.mx), my(detail.my), + m_ppData(detail.m_ppData) {} ~VDetailData() {} diff --git a/src/libs/vtools/dialogs/dialogs.pri b/src/libs/vtools/dialogs/dialogs.pri index e737ebe87..5c1cc848e 100644 --- a/src/libs/vtools/dialogs/dialogs.pri +++ b/src/libs/vtools/dialogs/dialogs.pri @@ -38,8 +38,7 @@ HEADERS += \ $$PWD/tools/dialogcubicbezier.h \ $$PWD/tools/dialogcubicbezierpath.h \ $$PWD/tools/dialoggroup.h \ - $$PWD/tools/dialogrotation.h \ - $$PWD/tools/dialogpatternpiecedata.h + $$PWD/tools/dialogrotation.h SOURCES += \ @@ -78,8 +77,7 @@ SOURCES += \ $$PWD/tools/dialogcubicbezier.cpp \ $$PWD/tools/dialogcubicbezierpath.cpp \ $$PWD/tools/dialoggroup.cpp \ - $$PWD/tools/dialogrotation.cpp \ - $$PWD/tools/dialogpatternpiecedata.cpp + $$PWD/tools/dialogrotation.cpp FORMS += \ $$PWD/tools/dialogalongline.ui \ diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index b81f76934..0fdb49ca4 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -36,6 +36,7 @@ #include "../../../vgeometry/vsplinepath.h" #include "../../../vpatterndb/vcontainer.h" #include "../../../ifc/xml/vdomdocument.h" +#include "vpatternpiecedata.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -90,6 +91,19 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge connect(ui.toolButtonDelete, &QToolButton::clicked, this, &DialogDetail::DeleteItem); connect(ui.toolButtonUp, &QToolButton::clicked, this, &DialogDetail::ScrollUp); connect(ui.toolButtonDown, &QToolButton::clicked, this, &DialogDetail::ScrollDown); + + m_qslMaterials << tr("Fabric") << tr("Lining") << tr("Interfacing") << tr("Interlining"); + ui.comboBoxMaterial->addItems(m_qslMaterials); + m_qslPlacements << tr("None") << tr("Cut on fold"); + ui.comboBoxPlacement->addItems(m_qslPlacements); + + connect(ui.pushButtonAdd, &QPushButton::clicked, this, &DialogDetail::AddUpdate); + connect(ui.pushButtonCancel, &QPushButton::clicked, this, &DialogDetail::Cancel); + connect(ui.pushButtonRemove, &QPushButton::clicked, this, &DialogDetail::Remove); + connect(ui.listWidgetMCP, &QListWidget::itemClicked, this, &DialogDetail::SetEditMode); + SetAddMode(); + + ui.tabWidget->setCurrentIndex(0); } //--------------------------------------------------------------------------------------------------------------------- @@ -153,6 +167,74 @@ void DialogDetail::CheckState() } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::UpdateList() +{ + ui.listWidgetMCP->clear(); + for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = detail.GetPatternPieceData().GetMCP(i); + QString qsText = tr("Cut %1 of %2%3"); + qsText = qsText.arg(mcp.m_iCutNumber); + if (mcp.m_eMaterial < MaterialType::mtUserDefined) + qsText = qsText.arg(m_qslMaterials[int(mcp.m_eMaterial)]); + else + qsText = qsText.arg(mcp.m_qsMaterialUserDef); + if (mcp.m_ePlacement == PlacementType::ptCutOnFold) + qsText = qsText.arg(tr(" on Fold")); + else + qsText = qsText.arg(""); + + ui.listWidgetMCP->addItem(qsText); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::AddUpdate() +{ + MaterialCutPlacement mcp; + mcp.m_qsMaterialUserDef = ui.comboBoxMaterial->currentText(); + mcp.m_eMaterial = MaterialType::mtUserDefined; + for (int i = 0; i < m_qslMaterials.count(); ++i) + if (mcp.m_qsMaterialUserDef == m_qslMaterials[i]) + mcp.m_eMaterial = MaterialType(i); + + mcp.m_iCutNumber = ui.spinBoxCutNumber->value(); + mcp.m_ePlacement = PlacementType(ui.comboBoxPlacement->currentIndex()); + + if (m_bAddMode == true) + { + detail.GetPatternPieceData().Append(mcp); + } + else + { + int iR = ui.listWidgetMCP->currentRow(); + SCASSERT(iR >= 0); + detail.GetPatternPieceData().Set(iR, mcp); + SetAddMode(); + } + UpdateList(); + ClearFields(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::Cancel() +{ + ClearFields(); + SetAddMode(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::Remove() +{ + int iR = ui.listWidgetMCP->currentRow(); + SCASSERT(iR >= 0); + detail.GetPatternPieceData().RemoveMCP(iR); + UpdateList(); + ClearFields(); + SetAddMode(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NewItem add new object (point, arc, spline or spline path) to list @@ -245,6 +327,14 @@ VDetail DialogDetail::CreateDetail() const detail.setName(ui.lineEditNameDetail->text()); detail.setSeamAllowance(supplement); detail.setClosed(closed); + + detail.GetPatternPieceData().SetLetter(ui.lineEditLetter->text()); + detail.GetPatternPieceData().SetName(ui.lineEditName->text()); + + qDebug() << "DD" << detail.GetPatternPieceData().GetLetter() + << detail.GetPatternPieceData().GetName() + << detail.GetPatternPieceData().GetMCPCount(); + return detail; } @@ -292,6 +382,11 @@ void DialogDetail::setDetail(const VDetail &value) ui.listWidget->setCurrentRow(0); ui.listWidget->setFocus(Qt::OtherFocusReason); ui.toolButtonDelete->setEnabled(true); + + ui.lineEditLetter->setText(detail.GetPatternPieceData().GetLetter()); + ui.lineEditName->setText(detail.GetPatternPieceData().GetName()); + UpdateList(); + ValidObjects(DetailIsValid()); } @@ -555,3 +650,41 @@ bool DialogDetail::DetailIsClockwise() const } return false; } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::ClearFields() +{ + ui.comboBoxMaterial->setCurrentIndex(0); + ui.spinBoxCutNumber->setValue(0); + ui.comboBoxPlacement->setCurrentIndex(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::SetAddMode() +{ + ui.pushButtonAdd->setText(tr("Add")); + ui.pushButtonCancel->hide(); + ui.pushButtonRemove->hide(); + ui.listWidgetMCP->setCurrentRow(-1); + m_bAddMode = true; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::SetEditMode() +{ + int iR = ui.listWidgetMCP->currentRow(); + // this method can be called by clicking on item or by update. In the latter case there is nothing else to do! + if (iR < 0 || iR >= detail.GetPatternPieceData().GetMCPCount()) + return; + + ui.pushButtonAdd->setText(tr("Update")); + ui.pushButtonCancel->show(); + ui.pushButtonRemove->show(); + + MaterialCutPlacement mcp = detail.GetPatternPieceData().GetMCP(iR); + ui.comboBoxMaterial->setCurrentText(mcp.m_qsMaterialUserDef); + ui.spinBoxCutNumber->setValue(mcp.m_iCutNumber); + ui.comboBoxPlacement->setCurrentIndex(int(mcp.m_ePlacement)); + + m_bAddMode = false; +} diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index 6dcd5c43e..4169696ae 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -62,6 +62,13 @@ protected: */ virtual void SaveData() Q_DECL_OVERRIDE; virtual void CheckState() Q_DECL_OVERRIDE; + +protected slots: + void UpdateList(); + void AddUpdate(); + void Cancel(); + void Remove(); + private: /** @brief ui keeps information about user interface */ @@ -85,6 +92,18 @@ private: VDetail CreateDetail() const; void ValidObjects(bool value); void EnableObjectGUI(bool value); + + bool m_bAddMode; + + QStringList m_qslMaterials; + QStringList m_qslPlacements; + + void ClearFields(); + + +private slots: + void SetAddMode(); + void SetEditMode(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index 29a7ae68b..8faa4a01f 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -7,7 +7,7 @@ 0 0 522 - 425 + 481 @@ -20,11 +20,422 @@ - - - - + + + + + 1 + + + + General + + + + + 59 + 468 + 504 + 15 + + + + Ready! + + + Qt::RichText + + + false + + + + + + 50 + 40 + 367 + 34 + + + + + + + + 0 + 30 + 561 + 361 + + + + + + + + + 6 + + + QLayout::SetDefaultConstraint + + + 0 + + + 0 + + + + + + 1 + 0 + + + + Bias X: + + + + + + + + 1 + 0 + + + + -900.990000000000009 + + + 900.990000000000009 + + + 0.100000000000000 + + + 0.000000000000000 + + + + + + + cm + + + + + + + + + + + + 1 + 0 + + + + Bias Y: + + + + + + + + 1 + 0 + + + + -900.990000000000009 + + + 900.990000000000009 + + + 0.100000000000000 + + + + + + + cm + + + + + + + + + + + Reverse + + + + + + + + + Options + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + + + + Name of detail: + + + + + + + + 0 + 0 + + + + Detail + + + + + + + + + Seam allowance + + + true + + + + + + + + + + 1 + 0 + + + + + + + Width: + + + + + + + + 1 + 0 + + + + 900.990000000000009 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + + 0 + 0 + + + + cm + + + + + + + + + Closed + + + true + + + + + + + QLayout::SetFixedSize + + + 10 + + + 10 + + + 10 + + + 10 + + + + + false + + + Delete + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Scroll down the list + + + ... + + + + + + + + + + + + Scroll up the list + + + ... + + + + + + + + + + + + + + + + + + + + + + + + 50 + 0 + 327 + 32 + + + + All objects in path should follow in clockwise direction. + + + + + 10 + 0 + 32 + 32 + + 0 @@ -38,376 +449,160 @@ :/icon/32x32/clockwise.png - - - - - All objects in path should follow in clockwise direction. - - - - - - - - - - - - - 6 - - - QLayout::SetDefaultConstraint - - - 0 - - - 0 - - - - - - 1 - 0 - - - - Bias X: - - - - - - - - 1 - 0 - - - - -900.990000000000009 - - - 900.990000000000009 - - - 0.100000000000000 - - - 0.000000000000000 - - - - - - - cm - - - - - - - - - - - - 1 - 0 - - - - Bias Y: - - - - - - - - 1 - 0 - - - - -900.990000000000009 - - - 900.990000000000009 - - - 0.100000000000000 - - - - - - - cm - - - - - - - - - - - Reverse - - - - - - - - - Options - - - - - - - - - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - - - - - - Name of detail: - - - - - - - - 0 - 0 - - - - Detail - - - - - - - - - Seam allowance - - - true - - - - - - - - - - 1 - 0 - - - - - - - Width: - - - - - - - - 1 - 0 - - - - 900.990000000000009 - - - 0.100000000000000 - - - 1.000000000000000 - - - - - - - - 0 - 0 - - - - cm - - - - - - - - - Closed - - - true - - - - - - - QLayout::SetFixedSize - - - 10 - - - 10 - - - 10 - - - 10 - - - - - false - - - Delete - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Scroll down the list - - - ... - - - - - - - - - - - - Scroll up the list - - - ... - - - - - - - - - - - + + + + Pattern piece data + + + + + + + + 9 + 38 + 40 + 16 + + + + Name: + + + + + + 55 + 38 + 125 + 23 + + + + 15 + + + + + + 280 + 0 + 201 + 381 + + + + Qt::ClickFocus + + + + + + 0 + 70 + 271 + 153 + + + + Material/Cut number/Placement + + + + + + Material type: + + + + + + + true + + + + + + + Cut number: + + + + + + + 1000 + + + + + + + Placement: + + + + + + + + + + Add + + + + + + + Cancel + + + + + + + Remove + + + + + + + + + 9 + 9 + 40 + 16 + + + + Letter: + + + + + + 55 + 9 + 125 + 23 + + + + 3 + + - - - - - - - - - - Ready! - - - Qt::RichText - - - false - + - + Qt::Horizontal @@ -420,14 +615,28 @@ + lineEditLetter + lineEditName + comboBoxMaterial + spinBoxCutNumber + comboBoxPlacement + pushButtonAdd + pushButtonCancel + pushButtonRemove + tabWidget + listWidgetMCP + buttonBox + toolButtonUp listWidget + checkBoxClosed + toolButtonDelete doubleSpinBoxBiasX doubleSpinBoxBiasY + checkBoxReverse lineEditNameDetail checkBoxSeams doubleSpinBoxSeams - checkBoxClosed - buttonBox + toolButtonDown diff --git a/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.cpp b/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.cpp deleted file mode 100644 index 3bdcc4b37..000000000 --- a/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.cpp +++ /dev/null @@ -1,250 +0,0 @@ -/************************************************************************ - ** - ** @file vpatternconverter.cpp - ** @author Roman Telezhynskyi - ** @date 11 12, 2014 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 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 -#include -#include -#include -#include -#include - -#include "vpatternpiecedata.h" -#include "dialogpatternpiecedata.h" - -//--------------------------------------------------------------------------------------------------------------------- -DialogPatternPieceData::DialogPatternPieceData(const VContainer *data, const quint32 &toolId, QWidget *parent) : - DialogTool(data, toolId, parent) -{ - // main dialog layout - QVBoxLayout* pLayout = new QVBoxLayout(this); - - // widgets layout - QHBoxLayout* pWidgetsLayout = new QHBoxLayout; - - setWindowTitle(tr("Pattern piece data")); - QFormLayout* pFormLayout = new QFormLayout; - QLabel* plb; - - plb = new QLabel(tr("Letter") + ":"); - m_pleLetter = new QLineEdit; - m_pleLetter->setMaxLength(3); - pFormLayout->addRow(plb, m_pleLetter); - - plb = new QLabel(tr("Name") + ":"); - m_pleName = new QLineEdit; - m_pleName->setMaxLength(15); - pFormLayout->addRow(plb, m_pleName); - - pWidgetsLayout->addLayout(pFormLayout); - - QGroupBox* pgb = new QGroupBox(tr("Material/Cut number/Placement")); - QGridLayout* pLayoutGB = new QGridLayout(pgb); - - pFormLayout = new QFormLayout; - - plb = new QLabel(tr("Material type") + ":"); - m_pcbMaterial = new QComboBox; - m_pcbMaterial->setFixedWidth(200); - m_qslMaterials << tr("Fabric") << tr("Lining") << tr("Interfacing") << tr("Interlining"); - m_pcbMaterial->addItems(m_qslMaterials); - m_pcbMaterial->setEditable(true); - pFormLayout->addRow(plb, m_pcbMaterial); - - plb = new QLabel(tr("Cut number") + ":"); - m_psbCutNumber = new QSpinBox; - m_psbCutNumber->setRange(0, 1000); - pFormLayout->addRow(plb, m_psbCutNumber); - - plb = new QLabel(tr("Placement type") + ":"); - m_pcbPlacement = new QComboBox; - m_qslPlacements << tr("None") << tr("Cut on fold"); - m_pcbPlacement->addItems(m_qslPlacements); - pFormLayout->addRow(plb, m_pcbPlacement); - pLayoutGB->addLayout(pFormLayout, 0, 0); - - QHBoxLayout* pMCPButtonLayout = new QHBoxLayout; - m_pbOpAddUpdate = new QPushButton; - connect(m_pbOpAddUpdate, &QPushButton::clicked, this, &DialogPatternPieceData::AddUpdate); - pMCPButtonLayout->addStretch(1); - pMCPButtonLayout->addWidget(m_pbOpAddUpdate); - m_pbOpCancel = new QPushButton(tr("Cancel")); - connect(m_pbOpCancel, &QPushButton::clicked, this, &DialogPatternPieceData::Cancel); - pMCPButtonLayout->addWidget(m_pbOpCancel); - m_pbOpRemove = new QPushButton(tr("Remove")); - connect(m_pbOpRemove, &QPushButton::clicked, this, &DialogPatternPieceData::Remove); - pMCPButtonLayout->addWidget(m_pbOpRemove); - pLayoutGB->addLayout(pMCPButtonLayout, 1, 0); - - m_plwMCP = new QListWidget; - connect(m_plwMCP, &QListWidget::itemClicked, this, &DialogPatternPieceData::SetEditMode); - pLayoutGB->addWidget(m_plwMCP, 0, 1, 3, 1); - pLayoutGB->setRowStretch(2, 1); - pLayoutGB->setColumnStretch(2, 1); - - pWidgetsLayout->addWidget(pgb); - - pWidgetsLayout->setStretch(2, 1); - - pLayout->addLayout(pWidgetsLayout); - - QHBoxLayout* pButtonsLayout = new QHBoxLayout; - pButtonsLayout->addStretch(0); - bOk = new QPushButton(tr("OK")); - connect(bOk, &QPushButton::clicked, this, &DialogTool::DialogAccepted); - QPushButton* pbCancel = new QPushButton(tr("Cancel")); - connect(pbCancel, &QPushButton::clicked, this, &DialogTool::DialogRejected); - pButtonsLayout->addWidget(bOk); - pButtonsLayout->addWidget(pbCancel); - - pLayout->addLayout(pButtonsLayout); - pLayout->setStretch(0, 1); - - SetAddMode(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternPieceData::SetDetail(const VDetail& rDetail) -{ - m_detail = rDetail; - m_pleLetter->setText(m_detail.GetPatternPieceData().GetLetter()); - m_pleName->setText(m_detail.GetPatternPieceData().GetName()); - UpdateList(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternPieceData::SaveData() -{ - m_detail.GetPatternPieceData().SetLetter(m_pleLetter->text()); - m_detail.GetPatternPieceData().SetName(m_pleName->text()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternPieceData::UpdateList() -{ - m_plwMCP->clear(); - for (int i = 0; i < m_detail.GetPatternPieceData().GetMCPCount(); ++i) - { - MaterialCutPlacement mcp = m_detail.GetPatternPieceData().GetMCP(i); - QString qsText = tr("Cut %1 of %2%3"); - qsText = qsText.arg(mcp.m_iCutNumber); - if (mcp.m_eMaterial < MaterialType::mtUserDefined) - qsText = qsText.arg(m_qslMaterials[int(mcp.m_eMaterial)]); - else - qsText = qsText.arg(mcp.m_qsMaterialUserDef); - if (mcp.m_ePlacement == PlacementType::ptCutOnFold) - qsText = qsText.arg(tr(" on Fold")); - else - qsText = qsText.arg(""); - - m_plwMCP->addItem(qsText); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternPieceData::AddUpdate() -{ - MaterialCutPlacement mcp; - mcp.m_qsMaterialUserDef = m_pcbMaterial->currentText(); - mcp.m_eMaterial = MaterialType::mtUserDefined; - for (int i = 0; i < m_qslMaterials.count(); ++i) - if (mcp.m_qsMaterialUserDef == m_qslMaterials[i]) - mcp.m_eMaterial = MaterialType(i); - - mcp.m_iCutNumber = m_psbCutNumber->value(); - mcp.m_ePlacement = PlacementType(m_pcbPlacement->currentIndex()); - - if (m_bAddMode == true) - { - m_detail.GetPatternPieceData().Append(mcp); - } - else - { - int iR = m_plwMCP->currentRow(); - SCASSERT(iR >= 0); - m_detail.GetPatternPieceData().Set(iR, mcp); - SetAddMode(); - } - UpdateList(); - ClearFields(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternPieceData::Cancel() -{ - ClearFields(); - SetAddMode(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternPieceData::Remove() -{ - int iR = m_plwMCP->currentRow(); - SCASSERT(iR >= 0); - m_detail.GetPatternPieceData().RemoveMCP(iR); - UpdateList(); - ClearFields(); - SetAddMode(); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternPieceData::ClearFields() -{ - m_pcbMaterial->setCurrentIndex(0); - m_psbCutNumber->setValue(0); - m_pcbPlacement->setCurrentIndex(0); -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternPieceData::SetAddMode() -{ - m_pbOpAddUpdate->setText(tr("Add")); - m_pbOpCancel->hide(); - m_pbOpRemove->hide(); - m_plwMCP->setCurrentRow(-1); - m_bAddMode = true; -} - -//--------------------------------------------------------------------------------------------------------------------- -void DialogPatternPieceData::SetEditMode() -{ - int iR = m_plwMCP->currentRow(); - // this method can be called by clicking on item or by update. In the latter case there is nothing else to do! - if (iR < 0 || iR >= m_detail.GetPatternPieceData().GetMCPCount()) - return; - - m_pbOpAddUpdate->setText(tr("Update")); - m_pbOpCancel->show(); - m_pbOpRemove->show(); - - MaterialCutPlacement mcp = m_detail.GetPatternPieceData().GetMCP(iR); - m_pcbMaterial->setCurrentText(mcp.m_qsMaterialUserDef); - m_psbCutNumber->setValue(mcp.m_iCutNumber); - m_pcbPlacement->setCurrentIndex(int(mcp.m_ePlacement)); - - m_bAddMode = false; -} diff --git a/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.h b/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.h deleted file mode 100644 index ff2511c3a..000000000 --- a/src/libs/vtools/dialogs/tools/dialogpatternpiecedata.h +++ /dev/null @@ -1,94 +0,0 @@ -/************************************************************************ - ** - ** @file vpatternconverter.cpp - ** @author Roman Telezhynskyi - ** @date 11 12, 2014 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2015 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 DIALOGPATTERNPIECEDATA_H -#define DIALOGPATTERNPIECEDATA_H - -#include -#include -#include -#include -#include - -#include "vdetail.h" -#include "dialogtool.h" - -/** - * @brief This dialog allows user to edit pattern piece meta data - */ -class DialogPatternPieceData : public DialogTool -{ - Q_OBJECT - -public: - DialogPatternPieceData(const VContainer* data, const quint32& toolId, QWidget* parent = nullptr); - - VDetail GetDetail() const; - void SetDetail(const VDetail& rDetail); - - void SaveData(); - -protected slots: - void UpdateList(); - void AddUpdate(); - void Cancel(); - void Remove(); - -private: - VDetail m_detail; - - QLineEdit* m_pleName; - QLineEdit* m_pleLetter; - QComboBox* m_pcbMaterial; - QSpinBox* m_psbCutNumber; - QComboBox* m_pcbPlacement; - - QPushButton* m_pbOpAddUpdate; - QPushButton* m_pbOpCancel; - QPushButton* m_pbOpRemove; - - QListWidget* m_plwMCP; - - QStringList m_qslMaterials; - QStringList m_qslPlacements; - - bool m_bAddMode; - - void ClearFields(); - -private slots: - void SetAddMode(); - void SetEditMode(); -}; - -inline VDetail DialogPatternPieceData::GetDetail() const -{ - return m_detail; -} - -#endif // DIALOGPATTERNPIECEDATA_H diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index b2292b28a..3f8f9ba7f 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -36,7 +36,6 @@ #include "../vwidgets/vmaingraphicsview.h" #include "../dialogs/tools/dialogtool.h" #include "../dialogs/tools/dialogdetail.h" -#include "../dialogs/tools/dialogpatternpiecedata.h" #include "../undocommands/savedetailoptions.h" #include "../undocommands/movedetail.h" #include "../undocommands/adddet.h" @@ -295,21 +294,17 @@ void VToolDetail::FullUpdateFromGuiOk(int result) if (result == QDialog::Accepted) { SCASSERT(dialog != nullptr); - VDetail newDet; - VDetail oldDet = VAbstractTool::data.GetDetail(id); DialogDetail *dialogTool = qobject_cast(dialog); - //SCASSERT(dialogTool != nullptr); + SCASSERT(dialogTool != nullptr); + + VDetail newDet = dialogTool->getDetail(); + VDetail oldDet = VAbstractTool::data.GetDetail(id); + + qDebug() << "VTOOL" << newDet.GetPatternPieceData().GetLetter() + << newDet.GetPatternPieceData().GetName() + << newDet.GetPatternPieceData().GetMCPCount() + << dialogTool->getDetail().GetPatternPieceData().GetName(); - if (dialogTool != nullptr) - { - newDet = dialogTool->getDetail(); - } - else - { - DialogPatternPieceData* dialogPPD = qobject_cast(dialog); - SCASSERT(dialogPPD != nullptr); - newDet = dialogPPD->GetDetail(); - } SaveDetailOptions *saveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); connect(saveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); @@ -551,7 +546,6 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { QMenu menu; QAction *actionOption = menu.addAction(QIcon::fromTheme("preferences-other"), tr("Options")); - QAction* actionData = menu.addAction(tr("Details info")); QAction *actionRemove = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete")); if (_referens > 1) { @@ -572,16 +566,6 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) setDialog(); dialog->show(); } - else if (selectedAction == actionData) - { - dialog = new DialogPatternPieceData(getData(), id, qApp->getMainWindow()); - dialog->setModal(true); - - connect(dialog, &DialogTool::DialogClosed, this, &VToolDetail::FullUpdateFromGuiOk); - VDetail detail = VAbstractTool::data.GetDetail(id); - qobject_cast(dialog)->SetDetail(detail); - dialog->show(); - } else if (selectedAction == actionRemove) { try From 9386ae2ff1c8114cd89f294e3b68d0370630a170 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 19 Jun 2016 13:46:19 +0200 Subject: [PATCH 04/66] Corrected code to satisfy code style specifications --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogdetail.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 0fdb49ca4..f5ec721aa 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -174,16 +174,23 @@ void DialogDetail::UpdateList() for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i) { MaterialCutPlacement mcp = detail.GetPatternPieceData().GetMCP(i); - QString qsText = tr("Cut %1 of %2%3"); - qsText = qsText.arg(mcp.m_iCutNumber); + QString qsText = tr("Cut %1 of %2%3").arg(mcp.m_iCutNumber); if (mcp.m_eMaterial < MaterialType::mtUserDefined) + { qsText = qsText.arg(m_qslMaterials[int(mcp.m_eMaterial)]); + } else + { qsText = qsText.arg(mcp.m_qsMaterialUserDef); + } if (mcp.m_ePlacement == PlacementType::ptCutOnFold) + { qsText = qsText.arg(tr(" on Fold")); + } else + { qsText = qsText.arg(""); + } ui.listWidgetMCP->addItem(qsText); } @@ -196,8 +203,12 @@ void DialogDetail::AddUpdate() mcp.m_qsMaterialUserDef = ui.comboBoxMaterial->currentText(); mcp.m_eMaterial = MaterialType::mtUserDefined; for (int i = 0; i < m_qslMaterials.count(); ++i) + { if (mcp.m_qsMaterialUserDef == m_qslMaterials[i]) + { mcp.m_eMaterial = MaterialType(i); + } + } mcp.m_iCutNumber = ui.spinBoxCutNumber->value(); mcp.m_ePlacement = PlacementType(ui.comboBoxPlacement->currentIndex()); @@ -675,7 +686,9 @@ void DialogDetail::SetEditMode() int iR = ui.listWidgetMCP->currentRow(); // this method can be called by clicking on item or by update. In the latter case there is nothing else to do! if (iR < 0 || iR >= detail.GetPatternPieceData().GetMCPCount()) + { return; + } ui.pushButtonAdd->setText(tr("Update")); ui.pushButtonCancel->show(); From c05c51e07868017502331c9956bc530c9dc7d95d Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 21 Jun 2016 00:49:22 +0200 Subject: [PATCH 05/66] Finished the detail dialog --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 33 ++++++++++++------- src/libs/ifc/xml/vabstractpattern.cpp | 7 +++- src/libs/ifc/xml/vabstractpattern.h | 5 +++ src/libs/vpatterndb/vdetail.cpp | 1 + src/libs/vpatterndb/vpatternpiecedata.cpp | 8 +++++ src/libs/vpatterndb/vpatternpiecedata.h | 1 + .../vtools/dialogs/tools/dialogdetail.cpp | 24 +++++++++----- src/libs/vtools/dialogs/tools/dialogdetail.h | 3 ++ src/libs/vtools/tools/vtooldetail.cpp | 31 +++++++++++++++++ .../vtools/undocommands/savedetailoptions.cpp | 18 ++++++++++ 10 files changed, 111 insertions(+), 20 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 05b1a8ffc..4332f78bb 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -47,6 +47,7 @@ #include "../vgeometry/vcubicbezierpath.h" #include "../core/vapplication.h" #include "../vpatterndb/calculator.h" +#include "vpatternpiecedata.h" #include #include @@ -580,6 +581,11 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); try { + QString qs; + QTextStream ts(&qs, QIODevice::WriteOnly); + domElement.save(ts, 2); + qDebug() << "Parse detail" << qs; + VDetail detail; const quint32 id = GetParametrId(domElement); detail.setName(GetParametrString(domElement, AttrName, "")); @@ -628,21 +634,26 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document throw e; } detail.append(VNodeDetail(id, tool, nodeType, mx, my, reverse)); - }/* + } else if (element.tagName() == TagData) { - try + QString qsName = element.attribute(AttrName, ""); + detail.GetPatternPieceData().SetName(qsName); + QString qsLetter = element.attribute(AttrLetter, ""); + detail.GetPatternPieceData().SetLetter(qsLetter); + + QDomNodeList nodeListMCP = element.childNodes(); + for (int iMCP = 0; iMCP < nodeListMCP.count(); ++iMCP) { - QString qsName = GetParametrString(element, AttrName); - detail.GetPatternPieceData().SetName(qsName); - QString qsLetter = GetParametrString(element, AttrLetter); - detail.GetPatternPieceData().SetLetter(qsLetter); - qDebug() << "Data" << qsName << qsLetter; + MaterialCutPlacement mcp; + QDomElement domMCP = nodeListMCP.at(iMCP).toElement(); + mcp.m_eMaterial = MaterialType(GetParametrUInt(domMCP, AttrMaterial, 0)); + mcp.m_qsMaterialUserDef = GetParametrString(domMCP, AttrUserDefined, ""); + mcp.m_iCutNumber = GetParametrUInt(domMCP, AttrCutNumber, 0); + mcp.m_ePlacement = PlacementType(GetParametrUInt(domMCP, AttrPlacement, 0)); + detail.GetPatternPieceData().Append(mcp); } - catch(const VException& e) - { - } - }*/ + } } } VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile); diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 534dc0110..ac62ce213 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -60,7 +60,8 @@ const QString VAbstractPattern::TagGradation = QStringLiteral("gradation"); const QString VAbstractPattern::TagHeights = QStringLiteral("heights"); const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); const QString VAbstractPattern::TagUnit = QStringLiteral("unit"); -const QString VAbstractPattern::TagData = QStringLiteral("data"); +const QString VAbstractPattern::TagData = QStringLiteral("data"); +const QString VAbstractPattern::TagMCP = QStringLiteral("mcp"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); @@ -68,6 +69,10 @@ const QString VAbstractPattern::AttrObject = QStringLiteral("object"); const QString VAbstractPattern::AttrTool = QStringLiteral("tool"); const QString VAbstractPattern::AttrType = QStringLiteral("type"); const QString VAbstractPattern::AttrLetter = QStringLiteral("letter"); +const QString VAbstractPattern::AttrMaterial = QStringLiteral("material"); +const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef"); +const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber"); +const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement"); const QString VAbstractPattern::AttrAll = QStringLiteral("all"); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 5f97aed21..568d37abd 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -156,6 +156,7 @@ public: static const QString TagSizes; static const QString TagUnit; static const QString TagData; + static const QString TagMCP; static const QString AttrName; static const QString AttrVisible; @@ -163,6 +164,10 @@ public: static const QString AttrTool; static const QString AttrType; static const QString AttrLetter; + static const QString AttrMaterial; + static const QString AttrUserDefined; + static const QString AttrCutNumber; + static const QString AttrPlacement; static const QString AttrAll; diff --git a/src/libs/vpatterndb/vdetail.cpp b/src/libs/vpatterndb/vdetail.cpp index 3f8bfea35..2546b7c68 100644 --- a/src/libs/vpatterndb/vdetail.cpp +++ b/src/libs/vpatterndb/vdetail.cpp @@ -92,6 +92,7 @@ void VDetail::Clear() d->nodes.clear(); d->mx = 0; d->my = 0; + GetPatternPieceData().Clear(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index 618dd98db..bb26f1644 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -80,6 +80,14 @@ void VPatternPieceData::RemoveMCP(int i) m_conMCP.removeAt(i); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternPieceData::Clear() +{ + m_qsLetter = ""; + m_qsName = ""; + m_conMCP.clear(); +} + //--------------------------------------------------------------------------------------------------------------------- const QString& VPatternPieceData::GetLetter() const { diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h index 57622d6cf..232425fa3 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -73,6 +73,7 @@ public: int GetMCPCount() const; const MaterialCutPlacement& GetMCP(int i) const; void RemoveMCP(int i); + void Clear(); // methods, which operate on other members const QString& GetLetter() const; diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index f5ec721aa..cfe14c8fe 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -171,9 +171,9 @@ void DialogDetail::CheckState() void DialogDetail::UpdateList() { ui.listWidgetMCP->clear(); - for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i) + for (int i = 0; i < m_conMCP.count(); ++i) { - MaterialCutPlacement mcp = detail.GetPatternPieceData().GetMCP(i); + MaterialCutPlacement mcp = m_conMCP[i]; QString qsText = tr("Cut %1 of %2%3").arg(mcp.m_iCutNumber); if (mcp.m_eMaterial < MaterialType::mtUserDefined) { @@ -215,13 +215,13 @@ void DialogDetail::AddUpdate() if (m_bAddMode == true) { - detail.GetPatternPieceData().Append(mcp); + m_conMCP << mcp; } else { int iR = ui.listWidgetMCP->currentRow(); SCASSERT(iR >= 0); - detail.GetPatternPieceData().Set(iR, mcp); + m_conMCP[iR] = mcp; SetAddMode(); } UpdateList(); @@ -240,7 +240,7 @@ void DialogDetail::Remove() { int iR = ui.listWidgetMCP->currentRow(); SCASSERT(iR >= 0); - detail.GetPatternPieceData().RemoveMCP(iR); + m_conMCP.removeAt(iR); UpdateList(); ClearFields(); SetAddMode(); @@ -342,9 +342,10 @@ VDetail DialogDetail::CreateDetail() const detail.GetPatternPieceData().SetLetter(ui.lineEditLetter->text()); detail.GetPatternPieceData().SetName(ui.lineEditName->text()); - qDebug() << "DD" << detail.GetPatternPieceData().GetLetter() - << detail.GetPatternPieceData().GetName() - << detail.GetPatternPieceData().GetMCPCount(); + for (int i = 0; i < m_conMCP.count(); ++i) + { + detail.GetPatternPieceData().Append(m_conMCP[i]); + } return detail; } @@ -396,6 +397,13 @@ void DialogDetail::setDetail(const VDetail &value) ui.lineEditLetter->setText(detail.GetPatternPieceData().GetLetter()); ui.lineEditName->setText(detail.GetPatternPieceData().GetName()); + + m_conMCP.clear(); + for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i) + { + m_conMCP << detail.GetPatternPieceData().GetMCP(i); + } + UpdateList(); ValidObjects(DetailIsValid()); diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index 4169696ae..85dda1627 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -32,6 +32,7 @@ #include "ui_dialogdetail.h" #include "dialogtool.h" #include "../vpatterndb/vdetail.h" +#include "vpatternpiecedata.h" /** * @brief The DialogDetail class dialog for ToolDetai. Help create detail and edit option. @@ -97,6 +98,8 @@ private: QStringList m_qslMaterials; QStringList m_qslPlacements; + // temporary container for Material/Cut/Placement 3-tuples + MCPContainer m_conMCP; void ClearFields(); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 3f8f9ba7f..376b1fa7e 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -331,6 +331,21 @@ void VToolDetail::AddToFile() doc->SetAttribute(domElement, AttrClosed, static_cast(detail.getClosed())); doc->SetAttribute(domElement, AttrWidth, detail.getWidth()); + QDomElement domData = doc->createElement(VAbstractPattern::TagData); + doc->SetAttribute(domData, VAbstractPattern::AttrLetter, detail.GetPatternPieceData().GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrName, detail.GetPatternPieceData().GetName()); + for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = detail.GetPatternPieceData().GetMCP(i); + QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); + doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); + doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); + doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber); + doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement)); + domData.appendChild(domMCP); + } + domElement.appendChild(domData); + for (int i = 0; i < detail.CountNode(); ++i) { AddNode(doc, domElement, detail.at(i)); @@ -356,6 +371,22 @@ void VToolDetail::RefreshDataInFile() doc->SetAttribute(domElement, AttrClosed, QString().setNum(static_cast(det.getClosed()))); doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth())); doc->RemoveAllChildren(domElement); + + QDomElement domData = doc->createElement(VAbstractPattern::TagData); + doc->SetAttribute(domData, VAbstractPattern::AttrLetter, det.GetPatternPieceData().GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrName, det.GetPatternPieceData().GetName()); + for (int i = 0; i < det.GetPatternPieceData().GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = det.GetPatternPieceData().GetMCP(i); + QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); + doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); + doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); + doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber); + doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement)); + domData.appendChild(domMCP); + } + domElement.appendChild(domData); + for (int i = 0; i < det.CountNode(); ++i) { AddNode(doc, domElement, det.at(i)); diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 5563bf530..005b87504 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -27,8 +27,10 @@ *************************************************************************/ #include "savedetailoptions.h" +#include "vpatternpiecedata.h" #include "../tools/nodeDetails/vabstractnode.h" #include "../../vwidgets/vmaingraphicsview.h" +#include "../ifc/xml/vabstractpattern.h" #include @@ -79,6 +81,22 @@ void SaveDetailOptions::redo() { SaveDet(domElement, newDet); doc->RemoveAllChildren(domElement); + + QDomElement domData = doc->createElement(VAbstractPattern::TagData); + doc->SetAttribute(domData, VAbstractPattern::AttrLetter, newDet.GetPatternPieceData().GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrName, newDet.GetPatternPieceData().GetName()); + for (int i = 0; i < newDet.GetPatternPieceData().GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = newDet.GetPatternPieceData().GetMCP(i); + QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); + doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); + doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); + doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber); + doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement)); + domData.appendChild(domMCP); + } + domElement.appendChild(domData); + for (int i = 0; i < newDet.CountNode(); ++i) { VToolDetail::AddNode(doc, domElement, newDet.at(i)); From b14a3c9551f3edf001557f1274b5d536565853a3 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 21 Jun 2016 19:53:15 +0200 Subject: [PATCH 06/66] Fixed the SaveDetailOption::undo method and few code style issues --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 2 +- src/libs/vpatterndb/vpatternpiecedata.cpp | 6 +-- .../vtools/dialogs/tools/dialogdetail.cpp | 3 +- src/libs/vtools/dialogs/tools/dialogdetail.h | 2 +- src/libs/vtools/tools/vtooldetail.cpp | 2 +- .../vtools/undocommands/savedetailoptions.cpp | 38 +++++++++++-------- .../vtools/undocommands/savedetailoptions.h | 1 + 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 4332f78bb..d0fe27435 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -47,7 +47,7 @@ #include "../vgeometry/vcubicbezierpath.h" #include "../core/vapplication.h" #include "../vpatterndb/calculator.h" -#include "vpatternpiecedata.h" +#include "../vpatterndb/vpatternpiecedata.h" #include #include diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index bb26f1644..72826edd1 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -69,7 +69,7 @@ const MaterialCutPlacement& VPatternPieceData::GetMCP(int i) const { Q_ASSERT(i >= 0); Q_ASSERT(i < GetMCPCount()); - return m_conMCP[i]; + return m_conMCP.at(i); } //--------------------------------------------------------------------------------------------------------------------- @@ -83,8 +83,8 @@ void VPatternPieceData::RemoveMCP(int i) //--------------------------------------------------------------------------------------------------------------------- void VPatternPieceData::Clear() { - m_qsLetter = ""; - m_qsName = ""; + m_qsLetter.clear(); + m_qsName.clear(); m_conMCP.clear(); } diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index cfe14c8fe..8c4cbba48 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -36,7 +36,6 @@ #include "../../../vgeometry/vsplinepath.h" #include "../../../vpatterndb/vcontainer.h" #include "../../../ifc/xml/vdomdocument.h" -#include "vpatternpiecedata.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -173,7 +172,7 @@ void DialogDetail::UpdateList() ui.listWidgetMCP->clear(); for (int i = 0; i < m_conMCP.count(); ++i) { - MaterialCutPlacement mcp = m_conMCP[i]; + MaterialCutPlacement mcp = m_conMCP.at(i); QString qsText = tr("Cut %1 of %2%3").arg(mcp.m_iCutNumber); if (mcp.m_eMaterial < MaterialType::mtUserDefined) { diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index 85dda1627..c03e33635 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -32,7 +32,7 @@ #include "ui_dialogdetail.h" #include "dialogtool.h" #include "../vpatterndb/vdetail.h" -#include "vpatternpiecedata.h" +#include "../vpatterndb/vpatternpiecedata.h" /** * @brief The DialogDetail class dialog for ToolDetai. Help create detail and edit option. diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 222126575..75c5c5864 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -40,7 +40,7 @@ #include "../undocommands/movedetail.h" #include "../undocommands/adddet.h" #include "../undocommands/deletedetail.h" -#include "vpatternpiecedata.h" +#include "../vpatterndb/vpatternpiecedata.h" #include #include diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 005b87504..0576c9700 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -27,10 +27,10 @@ *************************************************************************/ #include "savedetailoptions.h" -#include "vpatternpiecedata.h" #include "../tools/nodeDetails/vabstractnode.h" #include "../../vwidgets/vmaingraphicsview.h" #include "../ifc/xml/vabstractpattern.h" +#include "../vpatterndb/vpatternpiecedata.h" #include @@ -57,6 +57,7 @@ void SaveDetailOptions::undo() { SaveDet(domElement, oldDet); doc->RemoveAllChildren(domElement); + SavePatternPieceData(domElement, oldDet); for (int i = 0; i < oldDet.CountNode(); ++i) { VToolDetail::AddNode(doc, domElement, oldDet.at(i)); @@ -81,21 +82,7 @@ void SaveDetailOptions::redo() { SaveDet(domElement, newDet); doc->RemoveAllChildren(domElement); - - QDomElement domData = doc->createElement(VAbstractPattern::TagData); - doc->SetAttribute(domData, VAbstractPattern::AttrLetter, newDet.GetPatternPieceData().GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrName, newDet.GetPatternPieceData().GetName()); - for (int i = 0; i < newDet.GetPatternPieceData().GetMCPCount(); ++i) - { - MaterialCutPlacement mcp = newDet.GetPatternPieceData().GetMCP(i); - QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); - doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); - doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); - doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber); - doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement)); - domData.appendChild(domMCP); - } - domElement.appendChild(domData); + SavePatternPieceData(domElement, newDet); for (int i = 0; i < newDet.CountNode(); ++i) { @@ -142,3 +129,22 @@ void SaveDetailOptions::SaveDet(QDomElement &domElement, const VDetail &det) doc->SetAttribute(domElement, VToolDetail::AttrClosed, QString().setNum(det.getClosed())); doc->SetAttribute(domElement, VToolDetail::AttrWidth, QString().setNum(det.getWidth())); } + +//--------------------------------------------------------------------------------------------------------------------- +void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDetail &det) +{ + QDomElement domData = doc->createElement(VAbstractPattern::TagData); + doc->SetAttribute(domData, VAbstractPattern::AttrLetter, det.GetPatternPieceData().GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrName, det.GetPatternPieceData().GetName()); + for (int i = 0; i < det.GetPatternPieceData().GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = det.GetPatternPieceData().GetMCP(i); + QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); + doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); + doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); + doc->SetAttribute(domMCP, VAbstractPattern::AttrCutNumber, mcp.m_iCutNumber); + doc->SetAttribute(domMCP, VAbstractPattern::AttrPlacement, int(mcp.m_ePlacement)); + domData.appendChild(domMCP); + } + domElement.appendChild(domData); +} diff --git a/src/libs/vtools/undocommands/savedetailoptions.h b/src/libs/vtools/undocommands/savedetailoptions.h index 922a7a976..99d796ecb 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.h +++ b/src/libs/vtools/undocommands/savedetailoptions.h @@ -53,6 +53,7 @@ private: VDetail newDet; QGraphicsScene *scene; void SaveDet(QDomElement &domElement, const VDetail &det); + void SavePatternPieceData(QDomElement &domElement, const VDetail &det); }; //--------------------------------------------------------------------------------------------------------------------- From fc0b1dce9c8b01a497d0fbea773b846f2ab414b4 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 23 Jun 2016 00:59:45 +0200 Subject: [PATCH 07/66] Added label containing pattern piece information to vtooldetail, which can be moved/resized --HG-- branch : feature --- src/libs/vtools/tools/tools.pri | 6 +- src/libs/vtools/tools/vtextgraphicsitem.cpp | 187 ++++++++++++++++++++ src/libs/vtools/tools/vtextgraphicsitem.h | 73 ++++++++ src/libs/vtools/tools/vtooldetail.cpp | 41 ++++- src/libs/vtools/tools/vtooldetail.h | 3 + 5 files changed, 307 insertions(+), 3 deletions(-) create mode 100644 src/libs/vtools/tools/vtextgraphicsitem.cpp create mode 100644 src/libs/vtools/tools/vtextgraphicsitem.h diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 36b6f986c..0391ca475 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -50,7 +50,8 @@ HEADERS += \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \ - $$PWD/drawTools/operation/vtoolrotation.h + $$PWD/drawTools/operation/vtoolrotation.h \ + $$PWD/vtextgraphicsitem.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -98,4 +99,5 @@ SOURCES += \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.cpp \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \ - $$PWD/drawTools/operation/vtoolrotation.cpp + $$PWD/drawTools/operation/vtoolrotation.cpp \ + $$PWD/vtextgraphicsitem.cpp diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp new file mode 100644 index 000000000..318de0f27 --- /dev/null +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -0,0 +1,187 @@ +/************************************************************************ + ** + ** @file vtextgraphicsitem.h + ** @author Bojan Kverh + ** @date June 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 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 +#include +#include +#include + +#include "vtextgraphicsitem.h" + +#define RESIZE_SQUARE 30 + +//--------------------------------------------------------------------------------------------------------------------- +VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) + : QGraphicsTextItem(pParent) +{ + setFlag(QGraphicsItem::ItemIsMovable, true); + setFlag(QGraphicsItem::ItemIsSelectable, true); + m_eMode = mNormal; + m_iMinW = 100; +} + +//--------------------------------------------------------------------------------------------------------------------- +VTextGraphicsItem::~VTextGraphicsItem() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + painter->fillRect(option->rect, QColor(251, 251, 175)); + QGraphicsTextItem::paint(painter, option, widget); + + if (m_eMode != mNormal) + { + painter->setPen(QPen(Qt::black, 2, Qt::DashLine)); + painter->drawRect(boundingRect().adjusted(1, 1, -1, -1)); + + painter->setPen(Qt::black); + painter->setBrush(Qt::black); + SetResizeArea(); + painter->drawRect(m_rectResize); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::SetMinimalWidth(int iW) +{ + m_iMinW = iW; + setTextWidth(m_iMinW); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::Reset() +{ + m_eMode = mNormal; + Update(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::SetHTML(const QString& qsHTML) +{ + QGraphicsTextItem::setHtml(qsHTML); + m_iMinFontSize = font().pixelSize(); + m_iMinH = boundingRect().height(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) +{ + if ((pME->button() & Qt::LeftButton) > 0) + { + SetResizeArea(); + if (m_rectResize.contains(pME->pos()) == true) + { + m_eMode = mResize; + m_iCurrentH = boundingRect().height(); + } + else + { + m_eMode = mMove; + } + qDebug() << "MOUSEPRESS" << m_rectResize << pME->pos() << int(m_eMode); + Update(); + m_ptStart = pME->pos(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *pME) +{ + if (m_eMode == mMove) + { + m_eMode = mMove; + QPointF ptRel = pME->pos() - m_ptStart; + moveBy(ptRel.x(), ptRel.y()); + } + else if (m_eMode == mResize) + { + prepareGeometryChange(); + int iNewW = textWidth() + pME->pos().x() - m_ptStart.x(); + m_iCurrentH += pME->pos().y() - m_ptStart.y(); + if (iNewW >= m_iMinW) + { + setTextWidth(iNewW); + m_ptStart.setX(pME->pos().x()); + Update(); + } + + if (m_iCurrentH >= m_iMinH) + { + int iFontSize = m_iMinFontSize*m_iCurrentH/m_iMinH; + if (iFontSize > m_iMinFontSize*2) + { + // prevent too big letters + return; + } + QFont fnt = font(); + fnt.setPixelSize(iFontSize); + setFont(fnt); + m_ptStart.setY(pME->pos().y()); + Update(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *pME) +{ + if ((pME->button() & Qt::LeftButton) > 0) + { + if (m_eMode == mMove) + { + m_eMode = mActivated; + } + Update(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::Update() +{ + update(boundingRect()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::SetResizeArea() +{ + m_rectResize.setLeft(boundingRect().right() - RESIZE_SQUARE); + m_rectResize.setTop(boundingRect().bottom() - RESIZE_SQUARE); + m_rectResize.setWidth(RESIZE_SQUARE); + m_rectResize.setHeight(RESIZE_SQUARE); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::setHtml(const QString &qsHtml) +{ + Q_UNUSED(qsHtml); + // prevent using this method! Use SetHTML instead! +} + +//--------------------------------------------------------------------------------------------------------------------- + diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h new file mode 100644 index 000000000..b52d94abc --- /dev/null +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -0,0 +1,73 @@ +/************************************************************************ + ** + ** @file vtextgraphicsitem.h + ** @author Bojan Kverh + ** @date June 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 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 VTEXTGRAPHICSITEM_H +#define VTEXTGRAPHICSITEM_H + +#include + +class VTextGraphicsItem : public QGraphicsTextItem +{ + enum Mode { + mNormal, + mActivated, + mMove, + mResize + }; + +public: + VTextGraphicsItem(QGraphicsItem* pParent = 0); + ~VTextGraphicsItem(); + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + + void SetMinimalWidth(int iW); + + void Reset(); + void SetHTML(const QString& qsHTML); + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent* pME); + void mouseMoveEvent(QGraphicsSceneMouseEvent* pME); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME); + + void Update(); + void SetResizeArea(); + void setHtml(const QString& qsHtml); + +private: + int m_iMinW; + Mode m_eMode; + QPointF m_ptStart; + QRectF m_rectResize; + int m_iMinFontSize; + int m_iMinH; + int m_iCurrentH; +}; + +#endif // VTEXTGRAPHICSITEM_H diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 75c5c5864..7de05f214 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -77,7 +77,8 @@ const QString VToolDetail::NodeSplinePath = QStringLiteral("NodeSplinePath"); VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent) :VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene), - drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)) + drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)), + dataLabel(new VTextGraphicsItem(this)) { VDetail detail = data->GetDetail(id); for (int i = 0; i< detail.CountNode(); ++i) @@ -115,6 +116,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove); + connect(scene, &VMainGraphicsScene::MouseLeftPressed, this, &VToolDetail::ResetChild); if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) { AddToFile(); @@ -707,6 +709,37 @@ void VToolDetail::RefreshGeometry() } this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + + const VPatternPieceData& data = detail.GetPatternPieceData(); + if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0) + { + QString qsText = "Cut %1 on %2%3"; + QStringList qslPlace; + qslPlace << "" << " on Fold"; + QFont fnt = qApp->font(); + fnt.setPixelSize(24); + QFontMetrics fm(fnt); + dataLabel->setFont(fnt); + int iMinW = 200; + QString qsHTML = "" + data.GetLetter() + "
"; + qsHTML += "" + data.GetName() + "
"; + for (int i = 0; i < data.GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = data.GetMCP(i); + QString qsLine = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]); + if (fm.width(qsLine) > iMinW) + iMinW = fm.width(qsLine); + qsHTML += qsLine + "
"; + } + // also add some offset + dataLabel->SetMinimalWidth(iMinW + 10); + dataLabel->SetHTML(qsHTML); + dataLabel->show(); + } + else + { + dataLabel->hide(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -762,3 +795,9 @@ void VToolDetail::AllowSelecting(bool enabled) { setFlag(QGraphicsItem::ItemIsSelectable, enabled); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::ResetChild() +{ + dataLabel->Reset(); +} diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 18dba00c2..09bea8660 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -31,6 +31,7 @@ #include "vabstracttool.h" #include "../vwidgets/vnobrushscalepathitem.h" +#include "vtextgraphicsitem.h" class VMainGraphicsScene; class DialogTool; @@ -89,6 +90,7 @@ public slots: void EnableToolMove(bool move); virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; + virtual void ResetChild(); protected: virtual void AddToFile () Q_DECL_OVERRIDE; virtual void RefreshDataInFile() Q_DECL_OVERRIDE; @@ -111,6 +113,7 @@ private: QString drawName; VNoBrushScalePathItem *seamAllowance; + VTextGraphicsItem* dataLabel; VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr); From dab32731c0615bf620151eef9806b55dd2f1141c Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 23 Jun 2016 19:53:00 +0200 Subject: [PATCH 08/66] Fixed 0.3.1 schema file --HG-- branch : feature --- src/libs/ifc/schema/pattern/v0.3.1.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ifc/schema/pattern/v0.3.1.xsd b/src/libs/ifc/schema/pattern/v0.3.1.xsd index af3eaa1b6..6c1b41dde 100644 --- a/src/libs/ifc/schema/pattern/v0.3.1.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.1.xsd @@ -332,7 +332,7 @@ - + From fd47065ae2972ad73e51bfdf3406d8bcbbae8c2b Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 23 Jun 2016 19:57:07 +0200 Subject: [PATCH 09/66] Fixed 0.3.1 schema file again --HG-- branch : feature --- src/libs/ifc/schema/pattern/v0.3.1.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ifc/schema/pattern/v0.3.1.xsd b/src/libs/ifc/schema/pattern/v0.3.1.xsd index 6c1b41dde..d5af28adf 100644 --- a/src/libs/ifc/schema/pattern/v0.3.1.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.1.xsd @@ -332,7 +332,7 @@ - + From 6fbffd2834000df11366132491dcd2305b3a2f42 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 23 Jun 2016 22:35:32 +0200 Subject: [PATCH 10/66] Position, size and font size of the text label are now saved into VDetail DOM tree. Undo/Redo for moving and resizing the label works. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 8 ++ src/libs/vpatterndb/vpatternpiecedata.cpp | 48 +++++++++++- src/libs/vpatterndb/vpatternpiecedata.h | 20 +++++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 6 ++ src/libs/vtools/tools/vtextgraphicsitem.h | 6 ++ src/libs/vtools/tools/vtooldetail.cpp | 78 +++++++++++++++---- src/libs/vtools/tools/vtooldetail.h | 6 ++ .../vtools/undocommands/savedetailoptions.cpp | 15 ++-- 8 files changed, 165 insertions(+), 22 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index d0fe27435..f350fb6f5 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -641,6 +641,14 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document detail.GetPatternPieceData().SetName(qsName); QString qsLetter = element.attribute(AttrLetter, ""); detail.GetPatternPieceData().SetLetter(qsLetter); + QPointF ptPos; + ptPos.setX(element.attribute(AttrMx, "0").toDouble()); + ptPos.setY(element.attribute(AttrMy, "0").toDouble()); + detail.GetPatternPieceData().SetPos(ptPos); + qreal dLW = element.attribute(VToolDetail::AttrWidth, "0").toDouble(); + detail.GetPatternPieceData().SetLabelWidth(dLW); + int iFS = element.attribute(VToolDetail::AttrFont, "0").toInt(); + detail.GetPatternPieceData().SetFontSize(iFS); QDomNodeList nodeListMCP = element.childNodes(); for (int iMCP = 0; iMCP < nodeListMCP.count(); ++iMCP) diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index 72826edd1..560d776a6 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -29,8 +29,13 @@ #include "vpatternpiecedata.h" //--------------------------------------------------------------------------------------------------------------------- -VPatternPieceData::VPatternPieceData() -{} +VPatternPieceData::VPatternPieceData() : + m_ptPos(0, 0) +{ + m_iFontSize = MIN_FONT_SIZE; + // 0 means unknown width + m_dLabelWidth = 0; +} //--------------------------------------------------------------------------------------------------------------------- VPatternPieceData::~VPatternPieceData() @@ -113,4 +118,43 @@ void VPatternPieceData::SetName(QString qsName) } //--------------------------------------------------------------------------------------------------------------------- +QPointF VPatternPieceData::GetPos() const +{ + return m_ptPos; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternPieceData::SetPos(const QPointF& ptPos) +{ + m_ptPos = ptPos; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPatternPieceData::GetLabelWidth() const +{ + return m_dLabelWidth; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternPieceData::SetLabelWidth(qreal dLabelW) +{ + m_dLabelWidth = dLabelW; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VPatternPieceData::GetFontSize() const +{ + return m_iFontSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternPieceData::SetFontSize(int iSize) +{ + if (iSize >= MIN_FONT_SIZE) + m_iFontSize = iSize; + else + m_iFontSize = MIN_FONT_SIZE; +} + +//--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h index 232425fa3..0591a95ad 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -29,8 +29,11 @@ #ifndef VPATTERNPIECEDATA_H #define VPATTERNPIECEDATA_H +#define MIN_FONT_SIZE 24 + #include #include +#include enum class MaterialType : char { @@ -81,6 +84,14 @@ public: const QString& GetName() const; void SetName(QString qsName); + // methods, which set up label parameters + QPointF GetPos() const; + void SetPos(const QPointF& ptPos); + qreal GetLabelWidth() const; + void SetLabelWidth(qreal dLabelW); + int GetFontSize() const; + void SetFontSize(int iSize); + private: /** @brief Pattern piece name */ @@ -91,6 +102,15 @@ private: /** @brief List of material, cut number and placement 3-tuples */ MCPContainer m_conMCP; + /** @brief Location of the label + */ + QPointF m_ptPos; + /** @brief Label width + */ + qreal m_dLabelWidth; + /** @brief Label font size + */ + int m_iFontSize; }; #endif // VPATTERNPIECEDATA_H diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 318de0f27..f1c5a45c9 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -156,6 +156,12 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *pME) if (m_eMode == mMove) { m_eMode = mActivated; + emit SignalMoved(pos()); + } + else if (m_eMode == mResize) + { + m_eMode = mActivated; + emit SignalResized(textWidth(), font().pixelSize()); } Update(); } diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index b52d94abc..f9a0b21e9 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -33,6 +33,8 @@ class VTextGraphicsItem : public QGraphicsTextItem { + Q_OBJECT + enum Mode { mNormal, mActivated, @@ -51,6 +53,10 @@ public: void Reset(); void SetHTML(const QString& qsHTML); +signals: + void SignalMoved(QPointF ptPos); + void SignalResized(qreal dTW, int iFontSize); + protected: void mousePressEvent(QGraphicsSceneMouseEvent* pME); void mouseMoveEvent(QGraphicsSceneMouseEvent* pME); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 7de05f214..7008923ad 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -55,6 +55,7 @@ const QString VToolDetail::AttrClosed = QStringLiteral("closed"); const QString VToolDetail::AttrWidth = QStringLiteral("width"); const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType"); const QString VToolDetail::AttrReverse = QStringLiteral("reverse"); +const QString VToolDetail::AttrFont = QStringLiteral("fontSize"); const QString VToolDetail::NodeTypeContour = QStringLiteral("Contour"); const QString VToolDetail::NodeTypeModeling = QStringLiteral("Modeling"); @@ -126,6 +127,9 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 } } setAcceptHoverEvents(true); + + connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMove); + connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResize); } //--------------------------------------------------------------------------------------------------------------------- @@ -298,6 +302,7 @@ void VToolDetail::FullUpdateFromGuiOk(int result) { if (result == QDialog::Accepted) { + qDebug() << "FullUpdate" << qApp->getUndoStack()->count(); SCASSERT(dialog != nullptr); DialogDetail *dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); @@ -305,15 +310,10 @@ void VToolDetail::FullUpdateFromGuiOk(int result) VDetail newDet = dialogTool->getDetail(); VDetail oldDet = VAbstractTool::data.GetDetail(id); - qDebug() << "VTOOL" << newDet.GetPatternPieceData().GetLetter() - << newDet.GetPatternPieceData().GetName() - << newDet.GetPatternPieceData().GetMCPCount() - << dialogTool->getDetail().GetPatternPieceData().GetName(); - - SaveDetailOptions *saveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); connect(saveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); qApp->getUndoStack()->push(saveCommand); + qDebug() << "FullUpdate finished" << qApp->getUndoStack()->count(); } delete dialog; dialog = nullptr; @@ -337,11 +337,17 @@ void VToolDetail::AddToFile() doc->SetAttribute(domElement, AttrWidth, detail.getWidth()); QDomElement domData = doc->createElement(VAbstractPattern::TagData); - doc->SetAttribute(domData, VAbstractPattern::AttrLetter, detail.GetPatternPieceData().GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrName, detail.GetPatternPieceData().GetName()); - for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i) + const VPatternPieceData& data = detail.GetPatternPieceData(); + doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName()); + doc->SetAttribute(domData, AttrMx, data.GetPos().x()); + doc->SetAttribute(domData, AttrMy, data.GetPos().y()); + doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); + doc->SetAttribute(domData, AttrFont, data.GetFontSize()); + + for (int i = 0; i < data.GetMCPCount(); ++i) { - MaterialCutPlacement mcp = detail.GetPatternPieceData().GetMCP(i); + MaterialCutPlacement mcp = data.GetMCP(i); QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); @@ -378,11 +384,17 @@ void VToolDetail::RefreshDataInFile() doc->RemoveAllChildren(domElement); QDomElement domData = doc->createElement(VAbstractPattern::TagData); - doc->SetAttribute(domData, VAbstractPattern::AttrLetter, det.GetPatternPieceData().GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrName, det.GetPatternPieceData().GetName()); - for (int i = 0; i < det.GetPatternPieceData().GetMCPCount(); ++i) + const VPatternPieceData& data = det.GetPatternPieceData(); + doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName()); + doc->SetAttribute(domData, AttrMx, data.GetPos().x()); + doc->SetAttribute(domData, AttrMy, data.GetPos().y()); + doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); + doc->SetAttribute(domData, AttrFont, data.GetFontSize()); + + for (int i = 0; i < data.GetMCPCount(); ++i) { - MaterialCutPlacement mcp = det.GetPatternPieceData().GetMCP(i); + MaterialCutPlacement mcp = data.GetMCP(i); QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); @@ -617,6 +629,37 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief SaveMove saves the move operation to the undo stack + */ +void VToolDetail::SaveMove(QPointF ptPos) +{ + VDetail oldDet = VAbstractTool::data.GetDetail(id); + VDetail newDet = oldDet; + newDet.GetPatternPieceData().SetPos(ptPos); + SaveDetailOptions* moveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); + moveCommand->setText(tr("move pattern piece label")); + connect(moveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(moveCommand); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief: SaveResize save the resize label operation to the undo stack + */ +void VToolDetail::SaveResize(qreal dLabelW, int iFontSize) +{ + VDetail oldDet = VAbstractTool::data.GetDetail(id); + VDetail newDet = oldDet; + newDet.GetPatternPieceData().SetLabelWidth(dLabelW); + newDet.GetPatternPieceData().SetFontSize(iFontSize); + SaveDetailOptions* resizeCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); + resizeCommand->setText(tr("resize pattern piece label")); + connect(resizeCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(resizeCommand); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddNode add node to the file. @@ -717,7 +760,7 @@ void VToolDetail::RefreshGeometry() QStringList qslPlace; qslPlace << "" << " on Fold"; QFont fnt = qApp->font(); - fnt.setPixelSize(24); + fnt.setPixelSize(data.GetFontSize()); QFontMetrics fm(fnt); dataLabel->setFont(fnt); int iMinW = 200; @@ -733,7 +776,12 @@ void VToolDetail::RefreshGeometry() } // also add some offset dataLabel->SetMinimalWidth(iMinW + 10); + if (data.GetLabelWidth() > iMinW) + { + dataLabel->setTextWidth(data.GetLabelWidth()); + } dataLabel->SetHTML(qsHTML); + dataLabel->setPos(data.GetPos()); dataLabel->show(); } else diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 09bea8660..a71c72b01 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -71,6 +71,7 @@ public: static const QString AttrWidth; static const QString AttrNodeType; static const QString AttrReverse; + static const QString AttrFont; static const QString NodeTypeContour; static const QString NodeTypeModeling; static const QString NodeArc; @@ -103,6 +104,11 @@ protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE {} + +protected slots: + virtual void SaveMove(QPointF ptPos); + virtual void SaveResize(qreal dLabelW, int iFontSize); + private: Q_DISABLE_COPY(VToolDetail) /** @brief dialog dialog options. */ diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 0576c9700..47e94f147 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -106,7 +106,7 @@ bool SaveDetailOptions::mergeWith(const QUndoCommand *command) SCASSERT(saveCommand != nullptr); const quint32 id = saveCommand->getDetId(); - if (id != nodeId) + if (id != nodeId || text() != command->text()) { return false; } @@ -134,11 +134,16 @@ void SaveDetailOptions::SaveDet(QDomElement &domElement, const VDetail &det) void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDetail &det) { QDomElement domData = doc->createElement(VAbstractPattern::TagData); - doc->SetAttribute(domData, VAbstractPattern::AttrLetter, det.GetPatternPieceData().GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrName, det.GetPatternPieceData().GetName()); - for (int i = 0; i < det.GetPatternPieceData().GetMCPCount(); ++i) + const VPatternPieceData& data = det.GetPatternPieceData(); + doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName()); + doc->SetAttribute(domData, AttrMx, data.GetPos().x()); + doc->SetAttribute(domData, AttrMy, data.GetPos().y()); + doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth()); + doc->SetAttribute(domData, VToolDetail::AttrFont, data.GetFontSize()); + for (int i = 0; i < data.GetMCPCount(); ++i) { - MaterialCutPlacement mcp = det.GetPatternPieceData().GetMCP(i); + MaterialCutPlacement mcp = data.GetMCP(i); QDomElement domMCP = doc->createElement(VAbstractPattern::TagMCP); doc->SetAttribute(domMCP, VAbstractPattern::AttrMaterial, int(mcp.m_eMaterial)); doc->SetAttribute(domMCP, VAbstractPattern::AttrUserDefined, mcp.m_qsMaterialUserDef); From caa6b425b978aede08e2e870a4bd120bf13279bf Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 24 Jun 2016 17:57:08 +0200 Subject: [PATCH 11/66] Tried QGraphicsTextItem::boundingBox approach --HG-- branch : feature --- src/app/share/collection/Keiko_skirt.val | 18 ++-- src/libs/vpatterndb/vpatternpiecedata.h | 2 +- src/libs/vtools/tools/vtextgraphicsitem.cpp | 101 +++++++++++++------- src/libs/vtools/tools/vtextgraphicsitem.h | 13 ++- src/libs/vtools/tools/vtooldetail.cpp | 75 +++++++-------- src/libs/vtools/tools/vtooldetail.h | 1 + 6 files changed, 118 insertions(+), 92 deletions(-) diff --git a/src/app/share/collection/Keiko_skirt.val b/src/app/share/collection/Keiko_skirt.val index 32ac3722d..e097391eb 100644 --- a/src/app/share/collection/Keiko_skirt.val +++ b/src/app/share/collection/Keiko_skirt.val @@ -1,7 +1,7 @@ - 0.3.1 + 0.2.4 cm @@ -26,14 +26,14 @@ - - - - - - - - + + + + + + + + diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h index 0591a95ad..aee873fbb 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -29,7 +29,7 @@ #ifndef VPATTERNPIECEDATA_H #define VPATTERNPIECEDATA_H -#define MIN_FONT_SIZE 24 +#define MIN_FONT_SIZE 12 #include #include diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index f1c5a45c9..9f97f2702 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -29,11 +29,16 @@ #include #include #include +#include #include #include "vtextgraphicsitem.h" #define RESIZE_SQUARE 30 +#define MIN_W 120 +#define MIN_H 60 +#define MIN_FONT_SIZE 12 +#define MAX_FONT_SIZE 36 //--------------------------------------------------------------------------------------------------------------------- VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) @@ -42,7 +47,12 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); m_eMode = mNormal; - m_iMinW = 100; + m_rectBoundingBox.setTopLeft(QPointF(0, 0)); + setTextWidth(MIN_W); + m_rectBoundingBox.setWidth(MIN_W); + m_iMinH = MIN_H; + m_rectBoundingBox.setHeight(m_iMinH); + setZValue(2); } //--------------------------------------------------------------------------------------------------------------------- @@ -67,13 +77,6 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem } } -//--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::SetMinimalWidth(int iW) -{ - m_iMinW = iW; - setTextWidth(m_iMinW); -} - //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::Reset() { @@ -82,11 +85,21 @@ void VTextGraphicsItem::Reset() } //--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::SetHTML(const QString& qsHTML) +QRectF VTextGraphicsItem::boundingRect() const +{ return m_rectBoundingBox; } + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::SetHTML(const QString& qsHtml) { - QGraphicsTextItem::setHtml(qsHTML); - m_iMinFontSize = font().pixelSize(); - m_iMinH = boundingRect().height(); + QGraphicsTextItem::setHtml(qsHtml); + m_rectBoundingBox.setHeight(document()->size().height()); + + // calculate the minimal height + QScopedPointer pDoc(document()->clone()); + QFont fnt = font(); + fnt.setPixelSize(MIN_FONT_SIZE); + pDoc->setDefaultFont(fnt); + m_iMinH = pDoc->size().height(); } //--------------------------------------------------------------------------------------------------------------------- @@ -98,13 +111,11 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) if (m_rectResize.contains(pME->pos()) == true) { m_eMode = mResize; - m_iCurrentH = boundingRect().height(); } else { m_eMode = mMove; } - qDebug() << "MOUSEPRESS" << m_rectResize << pME->pos() << int(m_eMode); Update(); m_ptStart = pME->pos(); } @@ -122,29 +133,21 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *pME) else if (m_eMode == mResize) { prepareGeometryChange(); - int iNewW = textWidth() + pME->pos().x() - m_ptStart.x(); - m_iCurrentH += pME->pos().y() - m_ptStart.y(); - if (iNewW >= m_iMinW) - { - setTextWidth(iNewW); - m_ptStart.setX(pME->pos().x()); - Update(); - } + qreal fW = m_rectBoundingBox.width() + pME->pos().x() - m_ptStart.x(); + qreal fH = m_rectBoundingBox.height() + pME->pos().y() - m_ptStart.y(); - if (m_iCurrentH >= m_iMinH) + if (fW >= MIN_W) { - int iFontSize = m_iMinFontSize*m_iCurrentH/m_iMinH; - if (iFontSize > m_iMinFontSize*2) - { - // prevent too big letters - return; - } - QFont fnt = font(); - fnt.setPixelSize(iFontSize); - setFont(fnt); - m_ptStart.setY(pME->pos().y()); - Update(); + m_rectBoundingBox.setWidth(fW); + setTextWidth(fW); } + if (fH >= m_iMinH) + { + m_rectBoundingBox.setHeight(fH); + } + m_ptStart = pME->pos(); + + UpdateFont(); } } @@ -183,10 +186,34 @@ void VTextGraphicsItem::SetResizeArea() } //--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::setHtml(const QString &qsHtml) +void VTextGraphicsItem::UpdateFont() { - Q_UNUSED(qsHtml); - // prevent using this method! Use SetHTML instead! + QScopedPointer pDoc(document()->clone()); + pDoc->setTextWidth(m_rectBoundingBox.width()); + + QFont fnt = font(); + int iFS = fnt.pixelSize(); + QSizeF sz = pDoc->size(); + while (sz.width() < m_rectBoundingBox.width() && sz.height() < m_rectBoundingBox.height() && iFS < MAX_FONT_SIZE) + { + ++iFS; + fnt.setPixelSize(iFS); + pDoc->setDefaultFont(fnt); + sz = pDoc->size(); + } + + while ((sz.width() >= m_rectBoundingBox.width() || sz.height() >= m_rectBoundingBox.height()) && iFS > MIN_FONT_SIZE) + { + --iFS; + fnt.setPixelSize(iFS); + pDoc->setDefaultFont(fnt); + sz = pDoc->size(); + + } + + fnt.setPixelSize(iFS); + setFont(fnt); + Update(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index f9a0b21e9..9a840f526 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -48,10 +48,10 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - void SetMinimalWidth(int iW); - void Reset(); - void SetHTML(const QString& qsHTML); + + QRectF boundingRect() const; + void SetHTML(const QString& qsHtml); signals: void SignalMoved(QPointF ptPos); @@ -64,16 +64,15 @@ protected: void Update(); void SetResizeArea(); - void setHtml(const QString& qsHtml); + + void UpdateFont(); private: - int m_iMinW; Mode m_eMode; QPointF m_ptStart; QRectF m_rectResize; - int m_iMinFontSize; int m_iMinH; - int m_iCurrentH; + QRectF m_rectBoundingBox; }; #endif // VTEXTGRAPHICSITEM_H diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 7008923ad..c4a0f588c 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -130,6 +130,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMove); connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResize); + UpdateLabel(); } //--------------------------------------------------------------------------------------------------------------------- @@ -302,7 +303,6 @@ void VToolDetail::FullUpdateFromGuiOk(int result) { if (result == QDialog::Accepted) { - qDebug() << "FullUpdate" << qApp->getUndoStack()->count(); SCASSERT(dialog != nullptr); DialogDetail *dialogTool = qobject_cast(dialog); SCASSERT(dialogTool != nullptr); @@ -313,7 +313,7 @@ void VToolDetail::FullUpdateFromGuiOk(int result) SaveDetailOptions *saveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); connect(saveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); qApp->getUndoStack()->push(saveCommand); - qDebug() << "FullUpdate finished" << qApp->getUndoStack()->count(); + UpdateLabel(); } delete dialog; dialog = nullptr; @@ -629,6 +629,41 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief UpdateLabel updates the text label, making it just big enough for the text to fit it + */ +void VToolDetail::UpdateLabel() +{ + const VDetail detail = VAbstractTool::data.GetDetail(id); + + const VPatternPieceData& data = detail.GetPatternPieceData(); + if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0) + { + QString qsText = "Cut %1 on %2%3"; + QStringList qslPlace; + qslPlace << "" << " on Fold"; + QFont fnt = qApp->font(); + fnt.setPixelSize(data.GetFontSize()); + dataLabel->setFont(fnt); + QString qsHTML = "
" + data.GetLetter() + "

"; + qsHTML += "" + data.GetName() + "
"; + for (int i = 0; i < data.GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = data.GetMCP(i); + QString qsLine = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]); + qsHTML += qsLine + "
"; + } + dataLabel->SetHTML(qsHTML); + dataLabel->setPos(data.GetPos()); + dataLabel->show(); + } + else + { + dataLabel->hide(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveMove saves the move operation to the undo stack @@ -752,42 +787,6 @@ void VToolDetail::RefreshGeometry() } this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - - const VPatternPieceData& data = detail.GetPatternPieceData(); - if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0) - { - QString qsText = "Cut %1 on %2%3"; - QStringList qslPlace; - qslPlace << "" << " on Fold"; - QFont fnt = qApp->font(); - fnt.setPixelSize(data.GetFontSize()); - QFontMetrics fm(fnt); - dataLabel->setFont(fnt); - int iMinW = 200; - QString qsHTML = "" + data.GetLetter() + "
"; - qsHTML += "" + data.GetName() + "
"; - for (int i = 0; i < data.GetMCPCount(); ++i) - { - MaterialCutPlacement mcp = data.GetMCP(i); - QString qsLine = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]); - if (fm.width(qsLine) > iMinW) - iMinW = fm.width(qsLine); - qsHTML += qsLine + "
"; - } - // also add some offset - dataLabel->SetMinimalWidth(iMinW + 10); - if (data.GetLabelWidth() > iMinW) - { - dataLabel->setTextWidth(data.GetLabelWidth()); - } - dataLabel->SetHTML(qsHTML); - dataLabel->setPos(data.GetPos()); - dataLabel->show(); - } - else - { - dataLabel->hide(); - } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index a71c72b01..322129eac 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -104,6 +104,7 @@ protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE {} + virtual void UpdateLabel(); protected slots: virtual void SaveMove(QPointF ptPos); From 21debaf2491a327158f43a447459778b60028310 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 25 Jun 2016 17:19:44 +0200 Subject: [PATCH 12/66] Reimplemented QTextGraphicsItem class --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 285 ++++++++++++-------- src/libs/vtools/tools/vtextgraphicsitem.h | 38 ++- src/libs/vtools/tools/vtooldetail.cpp | 42 ++- src/libs/vtools/tools/vtooldetail.h | 1 + 4 files changed, 228 insertions(+), 138 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 9f97f2702..13ec56b12 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -38,20 +38,19 @@ #define MIN_W 120 #define MIN_H 60 #define MIN_FONT_SIZE 12 -#define MAX_FONT_SIZE 36 +#define MAX_FONT_SIZE 48 +#define SPACING 2 //--------------------------------------------------------------------------------------------------------------------- VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) - : QGraphicsTextItem(pParent) + : QGraphicsObject(pParent) { setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); m_eMode = mNormal; m_rectBoundingBox.setTopLeft(QPointF(0, 0)); - setTextWidth(MIN_W); - m_rectBoundingBox.setWidth(MIN_W); m_iMinH = MIN_H; - m_rectBoundingBox.setHeight(m_iMinH); + Resize(MIN_W, m_iMinH); setZValue(2); } @@ -59,11 +58,33 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) VTextGraphicsItem::~VTextGraphicsItem() {} +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::SetFont(const QFont& fnt) +{ + m_font = fnt; +} + //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter->fillRect(option->rect, QColor(251, 251, 175)); - QGraphicsTextItem::paint(painter, option, widget); + + // draw text lines + int iY = 0; + int iH; + painter->setPen(Qt::black); + QFont fnt = m_font; + for (int i = 0; i < m_liOutput.count(); ++i) + { + const TextLine& tl = m_liOutput.at(i); + iH = tl.m_iHeight; + fnt.setPixelSize(m_font.pixelSize() + tl.m_iFontSize); + fnt.setWeight(tl.m_eFontWeight); + painter->setFont(fnt); + painter->drawText(0, iY, boundingRect().width(), iH, tl.m_eAlign, tl.m_qsText); + iY += iH + SPACING; + } + if (m_eMode != mNormal) { @@ -72,149 +93,175 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->setPen(Qt::black); painter->setBrush(Qt::black); - SetResizeArea(); painter->drawRect(m_rectResize); + + if (m_eMode == mResize) + { + painter->drawLine(0, 0, m_rectBoundingBox.width(), m_rectBoundingBox.height()); + painter->drawLine(0, m_rectBoundingBox.height(), m_rectBoundingBox.width(), 0); + } } } +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::AddLine(const TextLine& tl) +{ + m_liLines << tl; + while (IsBigEnough(MIN_W, m_iMinH, MIN_FONT_SIZE) == false) + { + m_iMinH += 5; + } + if (m_rectBoundingBox.height() < m_iMinH) + { + Resize(m_rectBoundingBox.width(), m_iMinH); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::Clear() +{ + m_liLines.clear(); +} + //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::Reset() { m_eMode = mNormal; - Update(); + UpdateFont(); } //--------------------------------------------------------------------------------------------------------------------- QRectF VTextGraphicsItem::boundingRect() const -{ return m_rectBoundingBox; } - -//--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::SetHTML(const QString& qsHtml) { - QGraphicsTextItem::setHtml(qsHtml); - m_rectBoundingBox.setHeight(document()->size().height()); - - // calculate the minimal height - QScopedPointer pDoc(document()->clone()); - QFont fnt = font(); - fnt.setPixelSize(MIN_FONT_SIZE); - pDoc->setDefaultFont(fnt); - m_iMinH = pDoc->size().height(); + return m_rectBoundingBox; } //--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) +void VTextGraphicsItem::Resize(qreal fW, qreal fH) { - if ((pME->button() & Qt::LeftButton) > 0) - { - SetResizeArea(); - if (m_rectResize.contains(pME->pos()) == true) - { - m_eMode = mResize; - } - else - { - m_eMode = mMove; - } - Update(); - m_ptStart = pME->pos(); - } -} + // don't allow resize under specific size + if (fW < MIN_W || fH < m_iMinH) + return; -//--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *pME) -{ - if (m_eMode == mMove) - { - m_eMode = mMove; - QPointF ptRel = pME->pos() - m_ptStart; - moveBy(ptRel.x(), ptRel.y()); - } - else if (m_eMode == mResize) - { - prepareGeometryChange(); - qreal fW = m_rectBoundingBox.width() + pME->pos().x() - m_ptStart.x(); - qreal fH = m_rectBoundingBox.height() + pME->pos().y() - m_ptStart.y(); - - if (fW >= MIN_W) - { - m_rectBoundingBox.setWidth(fW); - setTextWidth(fW); - } - if (fH >= m_iMinH) - { - m_rectBoundingBox.setHeight(fH); - } - m_ptStart = pME->pos(); - - UpdateFont(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *pME) -{ - if ((pME->button() & Qt::LeftButton) > 0) - { - if (m_eMode == mMove) - { - m_eMode = mActivated; - emit SignalMoved(pos()); - } - else if (m_eMode == mResize) - { - m_eMode = mActivated; - emit SignalResized(textWidth(), font().pixelSize()); - } - Update(); - } -} - -//--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::Update() -{ - update(boundingRect()); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::SetResizeArea() -{ - m_rectResize.setLeft(boundingRect().right() - RESIZE_SQUARE); - m_rectResize.setTop(boundingRect().bottom() - RESIZE_SQUARE); + m_rectBoundingBox.setWidth(fW); + m_rectBoundingBox.setHeight(fH); + m_rectResize.setTopLeft(QPointF(fW - RESIZE_SQUARE, fH - RESIZE_SQUARE)); m_rectResize.setWidth(RESIZE_SQUARE); m_rectResize.setHeight(RESIZE_SQUARE); } //--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::UpdateFont() +void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { - QScopedPointer pDoc(document()->clone()); - pDoc->setTextWidth(m_rectBoundingBox.width()); - - QFont fnt = font(); - int iFS = fnt.pixelSize(); - QSizeF sz = pDoc->size(); - while (sz.width() < m_rectBoundingBox.width() && sz.height() < m_rectBoundingBox.height() && iFS < MAX_FONT_SIZE) + m_ptStart = pME->pos(); + m_szStart = m_rectBoundingBox.size(); + if (m_rectResize.contains(m_ptStart) == true) { - ++iFS; - fnt.setPixelSize(iFS); - pDoc->setDefaultFont(fnt); - sz = pDoc->size(); + m_eMode = mResize; } - - while ((sz.width() >= m_rectBoundingBox.width() || sz.height() >= m_rectBoundingBox.height()) && iFS > MIN_FONT_SIZE) + else { - --iFS; - fnt.setPixelSize(iFS); - pDoc->setDefaultFont(fnt); - sz = pDoc->size(); - + m_eMode = mMove; } - - fnt.setPixelSize(iFS); - setFont(fnt); Update(); } //--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) +{ + QPointF ptDiff = pME->pos() - m_ptStart; + if (m_eMode == mMove) + { + moveBy(ptDiff.x(), ptDiff.y()); + Update(); + } + else if (m_eMode == mResize) + { + Resize(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); + UpdateFont(); + emit SignalShrink(); + } +} +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) +{ + m_eMode = mActivated; + Update(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::Update() +{ + update(m_rectBoundingBox); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::UpdateFont() +{ + int iFS = m_font.pixelSize(); + + // increase the font size until the bounding rect is not big enough + while (iFS < MAX_FONT_SIZE && IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS) == true) + { + ++iFS; + } + // decrease the font size until the bounding rect is big enough + while (iFS >= MIN_FONT_SIZE && IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS) == false) + { + --iFS; + } + m_font.setPixelSize(iFS); + Update(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VTextGraphicsItem::IsBigEnough(qreal fW, qreal fH, int iFontSize) +{ + m_liOutput.clear(); + QFont fnt = m_font; + int iY = 0; + for (int i = 0; i < m_liLines.count(); ++i) + { + const TextLine& tl = m_liLines.at(i); + TextLine tlOut = tl; + fnt.setPixelSize(iFontSize + tl.m_iFontSize); + QFontMetrics fm(fnt); + tlOut.m_iHeight = fm.height(); + QStringList qslLines = SplitString(tlOut.m_qsText, fW, fm); + for (int i = 0; i < qslLines.count(); ++i) + { + tlOut.m_qsText = qslLines[i]; + m_liOutput << tlOut; + iY += tlOut.m_iHeight + SPACING; + } + } + return iY < fH; +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VTextGraphicsItem::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm) +{ + QRegExp reg("\\s+"); + QStringList qslWords = qs.split(reg); + QStringList qslLines; + QString qsCurrent; + for (int i = 0; i < qslWords.count(); ++i) + { + if (qsCurrent.length() > 0) + { + qsCurrent += " "; + } + if (fm.width(qsCurrent + qslWords[i]) > fW) + { + qslLines << qsCurrent; + qsCurrent = qslWords[i]; + } + else + { + qsCurrent += qslWords[i]; + } + } + qslLines << qsCurrent; + return qslLines; +} diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 9a840f526..165857d95 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -29,9 +29,20 @@ #ifndef VTEXTGRAPHICSITEM_H #define VTEXTGRAPHICSITEM_H -#include +#include +#include +#include -class VTextGraphicsItem : public QGraphicsTextItem +struct TextLine +{ + QString m_qsText; + int m_iFontSize; // 0 means default + QFont::Weight m_eFontWeight; + Qt::Alignment m_eAlign; + int m_iHeight; +}; + +class VTextGraphicsItem : public QGraphicsObject { Q_OBJECT @@ -46,33 +57,40 @@ public: VTextGraphicsItem(QGraphicsItem* pParent = 0); ~VTextGraphicsItem(); + void SetFont(const QFont& fnt); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void Reset(); QRectF boundingRect() const; - void SetHTML(const QString& qsHtml); - -signals: - void SignalMoved(QPointF ptPos); - void SignalResized(qreal dTW, int iFontSize); + void AddLine(const TextLine& tl); + void Clear(); protected: + void Resize(qreal fW, qreal fH); void mousePressEvent(QGraphicsSceneMouseEvent* pME); void mouseMoveEvent(QGraphicsSceneMouseEvent* pME); void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME); - void Update(); - void SetResizeArea(); - void UpdateFont(); + bool IsBigEnough(qreal fW, qreal fH, int iFontSize); + QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); + +signals: + void SignalMoved(QPointF ptPos); + void SignalResized(qreal iTW, int iFontSize); + void SignalShrink(); private: Mode m_eMode; QPointF m_ptStart; + QSizeF m_szStart; QRectF m_rectResize; int m_iMinH; QRectF m_rectBoundingBox; + QFont m_font; + QList m_liLines; + QList m_liOutput; }; #endif // VTEXTGRAPHICSITEM_H diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index c4a0f588c..47729189d 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -130,6 +130,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMove); connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResize); + connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); UpdateLabel(); } @@ -640,22 +641,38 @@ void VToolDetail::UpdateLabel() const VPatternPieceData& data = detail.GetPatternPieceData(); if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0) { - QString qsText = "Cut %1 on %2%3"; + QString qsText = "Cut %1 of %2%3"; QStringList qslPlace; qslPlace << "" << " on Fold"; QFont fnt = qApp->font(); fnt.setPixelSize(data.GetFontSize()); - dataLabel->setFont(fnt); - QString qsHTML = "
" + data.GetLetter() + "

"; - qsHTML += "" + data.GetName() + "
"; - for (int i = 0; i < data.GetMCPCount(); ++i) - { + dataLabel->SetFont(fnt); + dataLabel->Clear(); + TextLine tl; + // letter + tl.m_qsText = data.GetLetter(); + tl.m_eAlign = Qt::AlignCenter; + tl.m_eFontWeight = QFont::Bold; + tl.m_iFontSize = 4; + dataLabel->AddLine(tl); + tl.m_qsText = data.GetName(); + tl.m_eAlign = Qt::AlignCenter; + tl.m_eFontWeight = QFont::DemiBold; + tl.m_iFontSize = 2; + dataLabel->AddLine(tl); + + // MCP + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + tl.m_eFontWeight = QFont::Normal; + tl.m_iFontSize = 0; + for (int i = 0; i < data.GetMCPCount(); ++i) { MaterialCutPlacement mcp = data.GetMCP(i); - QString qsLine = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]); - qsHTML += qsLine + "
"; + tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]); + dataLabel->AddLine(tl); } - dataLabel->SetHTML(qsHTML); + dataLabel->setPos(data.GetPos()); + dataLabel->Reset(); dataLabel->show(); } else @@ -848,3 +865,10 @@ void VToolDetail::ResetChild() { dataLabel->Reset(); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::UpdateAll() +{ + sceneDetails->update(); + update(); +} diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 322129eac..f4fd7eba9 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -92,6 +92,7 @@ public slots: virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; virtual void ResetChild(); + virtual void UpdateAll(); protected: virtual void AddToFile () Q_DECL_OVERRIDE; virtual void RefreshDataInFile() Q_DECL_OVERRIDE; From e68fa3a0f32674183d1af4b2849afe20d92fdc5e Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 26 Jun 2016 14:21:06 +0200 Subject: [PATCH 13/66] Fixed few bugs: label position is preserved after editing detail, buttons for add/update/remove MCP are handled correcty. Added style to VTextGraphicsItem lines --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogdetail.cpp | 7 +++++-- src/libs/vtools/dialogs/tools/dialogdetail.h | 1 + src/libs/vtools/tools/vtextgraphicsitem.cpp | 13 +++++++++++-- src/libs/vtools/tools/vtextgraphicsitem.h | 1 + src/libs/vtools/tools/vtooldetail.cpp | 5 +++-- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 8c4cbba48..72513b0c9 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -346,6 +346,8 @@ VDetail DialogDetail::CreateDetail() const detail.GetPatternPieceData().Append(m_conMCP[i]); } + detail.GetPatternPieceData().SetPos(m_ptPos); + return detail; } @@ -404,6 +406,7 @@ void DialogDetail::setDetail(const VDetail &value) } UpdateList(); + m_ptPos = detail.GetPatternPieceData().GetPos(); ValidObjects(DetailIsValid()); } @@ -692,7 +695,7 @@ void DialogDetail::SetEditMode() { int iR = ui.listWidgetMCP->currentRow(); // this method can be called by clicking on item or by update. In the latter case there is nothing else to do! - if (iR < 0 || iR >= detail.GetPatternPieceData().GetMCPCount()) + if (iR < 0 || iR >= m_conMCP.count()) { return; } @@ -701,7 +704,7 @@ void DialogDetail::SetEditMode() ui.pushButtonCancel->show(); ui.pushButtonRemove->show(); - MaterialCutPlacement mcp = detail.GetPatternPieceData().GetMCP(iR); + MaterialCutPlacement mcp = m_conMCP.at(iR); ui.comboBoxMaterial->setCurrentText(mcp.m_qsMaterialUserDef); ui.spinBoxCutNumber->setValue(mcp.m_iCutNumber); ui.comboBoxPlacement->setCurrentIndex(int(mcp.m_ePlacement)); diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index c03e33635..e1333e327 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -100,6 +100,7 @@ private: QStringList m_qslPlacements; // temporary container for Material/Cut/Placement 3-tuples MCPContainer m_conMCP; + QPointF m_ptPos; void ClearFields(); diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 13ec56b12..02014e674 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -80,6 +80,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem iH = tl.m_iHeight; fnt.setPixelSize(m_font.pixelSize() + tl.m_iFontSize); fnt.setWeight(tl.m_eFontWeight); + fnt.setStyle(tl.m_eStyle); painter->setFont(fnt); painter->drawText(0, iY, boundingRect().width(), iH, tl.m_eAlign, tl.m_qsText); iY += iH + SPACING; @@ -186,6 +187,14 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { + if (m_eMode == mMove) + { + emit SignalMoved(pos()); + } + else + { + emit SignalResized(m_rectBoundingBox.width(), m_font.pixelSize()); + } m_eMode = mActivated; Update(); } @@ -229,9 +238,9 @@ bool VTextGraphicsItem::IsBigEnough(qreal fW, qreal fH, int iFontSize) QFontMetrics fm(fnt); tlOut.m_iHeight = fm.height(); QStringList qslLines = SplitString(tlOut.m_qsText, fW, fm); - for (int i = 0; i < qslLines.count(); ++i) + for (int iL = 0; iL < qslLines.count(); ++iL) { - tlOut.m_qsText = qslLines[i]; + tlOut.m_qsText = qslLines[iL]; m_liOutput << tlOut; iY += tlOut.m_iHeight + SPACING; } diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 165857d95..a9f62f3ae 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -38,6 +38,7 @@ struct TextLine QString m_qsText; int m_iFontSize; // 0 means default QFont::Weight m_eFontWeight; + QFont::Style m_eStyle; Qt::Alignment m_eAlign; int m_iHeight; }; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 47729189d..4be428f24 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -311,6 +311,7 @@ void VToolDetail::FullUpdateFromGuiOk(int result) VDetail newDet = dialogTool->getDetail(); VDetail oldDet = VAbstractTool::data.GetDetail(id); + qDebug() << "VToolDetail Position" << newDet.GetPatternPieceData().GetPos(); SaveDetailOptions *saveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); connect(saveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); qApp->getUndoStack()->push(saveCommand); @@ -653,14 +654,14 @@ void VToolDetail::UpdateLabel() tl.m_qsText = data.GetLetter(); tl.m_eAlign = Qt::AlignCenter; tl.m_eFontWeight = QFont::Bold; - tl.m_iFontSize = 4; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 6; dataLabel->AddLine(tl); tl.m_qsText = data.GetName(); tl.m_eAlign = Qt::AlignCenter; tl.m_eFontWeight = QFont::DemiBold; tl.m_iFontSize = 2; dataLabel->AddLine(tl); - // MCP tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; tl.m_eFontWeight = QFont::Normal; From 065621f8c2bf3f624893dca0f871cafe42c64743 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 26 Jun 2016 16:49:51 +0200 Subject: [PATCH 14/66] Added general info parameters to VPattern and updated pattern properties dialog accordingly --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 40 ++++++ .../dialogs/dialogpatternproperties.h | 3 + .../dialogs/dialogpatternproperties.ui | 76 +++++++++++- src/libs/ifc/xml/vabstractpattern.cpp | 117 +++++++++++++++++- src/libs/ifc/xml/vabstractpattern.h | 16 +++ 5 files changed, 250 insertions(+), 2 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index ed57b6819..85b96a291 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -55,6 +55,7 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte gradationChanged(false), defaultChanged(false), securityChanged(false), + generalInfoChanged(false), deleteAction(nullptr), changeImageAction(nullptr), saveImageAction(nullptr), @@ -159,6 +160,17 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte gradationChanged = false; defaultChanged = false; securityChanged = false; + + ui->lineEditPatternName->setText(doc->GetPatternName()); + ui->lineEditPatternNumber->setText(doc->GetPatternNumber()); + ui->lineEditCompanyName->setText(doc->GetCompanyName()); + ui->lineEditCustomerName->setText(doc->GetCustomerName()); + ui->labelCreationDate->setText(doc->GetCreationDate().toString(Qt::SystemLocaleLongDate)); + + connect(ui->lineEditPatternName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); + connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); + connect(ui->lineEditCompanyName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); + connect(ui->lineEditCustomerName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); } //--------------------------------------------------------------------------------------------------------------------- @@ -189,6 +201,12 @@ void DialogPatternProperties::Apply() securityChanged = false; emit doc->patternChanged(false); break; + case 3: + SaveGeneralInfo(); + generalInfoChanged = false; + emit doc->patternChanged(false); + break; + default: break; } @@ -225,6 +243,13 @@ void DialogPatternProperties::Ok() emit doc->patternChanged(false); } + if (generalInfoChanged == true) + { + SaveGeneralInfo(); + generalInfoChanged = false; + emit doc->patternChanged(false); + } + close(); } @@ -378,6 +403,12 @@ void DialogPatternProperties::SecurityValueChanged() securityChanged = true; } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::GeneralInfoChanged() +{ + generalInfoChanged = true; +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::SetHeightsChecked(bool enabled) { @@ -514,6 +545,15 @@ void DialogPatternProperties::SaveDefValues() defaultChanged = false; } +//--------------------------------------------------------------------------------------------------------------------- +void DialogPatternProperties::SaveGeneralInfo() +{ + doc->SetPatternName(ui->lineEditPatternName->text()); + doc->SetPatternNumber(ui->lineEditPatternNumber->text()); + doc->SetCompanyName(ui->lineEditCompanyName->text()); + doc->SetCustomerName(ui->lineEditCustomerName->text()); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogPatternProperties::SetDefaultHeight(const QString &def) { diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index 9cac4d3fc..a0a8faab2 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -64,6 +64,7 @@ private slots: void ToggleComboBox(); void DefValueChanged(); void SecurityValueChanged(); + void GeneralInfoChanged(); void DeleteImage(); void SaveImage(); void ShowImage(); @@ -81,6 +82,7 @@ private: bool gradationChanged; bool defaultChanged; bool securityChanged; + bool generalInfoChanged; QAction *deleteAction; QAction *changeImageAction; QAction *saveImageAction; @@ -101,6 +103,7 @@ private: void SaveDescription(); void SaveGradation(); void SaveDefValues(); + void SaveGeneralInfo(); void SetDefaultHeight(const QString &def); void SetDefaultSize(const QString &def); diff --git a/src/app/valentina/dialogs/dialogpatternproperties.ui b/src/app/valentina/dialogs/dialogpatternproperties.ui index a236c93fa..1d09d1a41 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.ui +++ b/src/app/valentina/dialogs/dialogpatternproperties.ui @@ -21,7 +21,7 @@ - 0 + 3 @@ -1043,6 +1043,80 @@
+ + + General info + + + + + 10 + 10 + 401 + 171 + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Pattern name: + + + + + + + + + + Pattern number: + + + + + + + + + + Company/Designer name: + + + + + + + + + + Customer name: + + + + + + + + + + Created: + + + + + + + + + + + + +
diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index fed645526..6fcd1eecc 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -62,6 +62,11 @@ const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); const QString VAbstractPattern::TagUnit = QStringLiteral("unit"); const QString VAbstractPattern::TagData = QStringLiteral("data"); const QString VAbstractPattern::TagMCP = QStringLiteral("mcp"); +const QString VAbstractPattern::TagPatternName = QStringLiteral("patternName"); +const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber"); +const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); +const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); +const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); @@ -985,6 +990,89 @@ void VAbstractPattern::SetNotes(const QString &text) emit patternChanged(false); } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractPattern::GetPatternName() const +{ + return UniqueTagText(TagPatternName); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetPatternName(QString qsName) +{ + CheckTagExists(TagPatternName); + setTagText(TagPatternName, qsName); + modified = true; + emit patternChanged(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractPattern::GetCompanyName() const +{ + return UniqueTagText(TagCompanyName); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetCompanyName(QString qsName) +{ + CheckTagExists(TagCompanyName); + setTagText(TagCompanyName, qsName); + modified = true; + emit patternChanged(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractPattern::GetPatternNumber() const +{ + return UniqueTagText(TagPatternNum); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetPatternNumber(QString qsNum) +{ + CheckTagExists(TagPatternNum); + setTagText(TagPatternNum, qsNum); + modified = true; + emit patternChanged(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractPattern::GetCustomerName() const +{ + return UniqueTagText(TagCustomerName); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetCustomerName(QString qsName) +{ + CheckTagExists(TagCustomerName); + setTagText(TagCustomerName, qsName); + modified = true; + emit patternChanged(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +QDate VAbstractPattern::GetCreationDate() const +{ + QStringList qsl = UniqueTagText(TagCreationDate).split("."); + if (qsl.count() == 3) + { + bool bDay; + bool bMonth; + bool bYear; + int iDay = qsl[0].toInt(&bDay); + int iMonth = qsl[1].toInt(&bMonth); + int iYear = qsl[2].toInt(&bYear); + + if (bDay == true && bMonth == true && bYear == true) + { + QDate date; + date.setDate(iYear, iMonth, iDay); + return date; + } + } + return QDate::currentDate(); +} + //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPattern::GetImage() const { @@ -1109,7 +1197,8 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) if (list.isEmpty()) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes - << TagGradation; + << TagGradation << TagPatternName << TagPatternNum << TagCompanyName + << TagCustomerName << TagCreationDate; switch (tags.indexOf(tag)) { case 0: //TagUnit @@ -1150,6 +1239,32 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) element.appendChild(sizes); break; } + case 6: // TagPatternName + { + element = createElement(TagPatternName); + break; + } + case 7: // TagPatternName + { + element = createElement(TagPatternNum); + break; + } + case 8: // TagPatternName + { + element = createElement(TagCompanyName); + break; + } + case 9: // TagPatternName + { + element = createElement(TagCustomerName); + break; + } + case 10: // TagPatternName + { + element = createElement(TagCreationDate); + break; + } + default: { return QDomElement(); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 568d37abd..4029f063a 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -33,6 +33,7 @@ #include "vtoolrecord.h" #include +#include enum class Document : char { LiteParse, LitePPParse, FullParse }; enum class LabelType : char {NewPatternPiece, NewLabel}; @@ -107,6 +108,16 @@ public: QString GetNotes() const; void SetNotes(const QString &text); + QString GetPatternName() const; + void SetPatternName(QString qsName); + QString GetCompanyName() const; + void SetCompanyName(QString qsName); + QString GetPatternNumber() const; + void SetPatternNumber(QString qsNum); + QString GetCustomerName() const; + void SetCustomerName(QString qsName); + QDate GetCreationDate() const; + QString GetImage() const; QString GetImageExtension() const; void SetImage(const QString &text, const QString &extension); @@ -157,6 +168,11 @@ public: static const QString TagUnit; static const QString TagData; static const QString TagMCP; + static const QString TagPatternName; + static const QString TagPatternNum; + static const QString TagCompanyName; + static const QString TagCustomerName; + static const QString TagCreationDate; static const QString AttrName; static const QString AttrVisible; From fa105537d2053d3d74c074c68773e65432c9479e Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Mon, 27 Jun 2016 01:17:27 +0200 Subject: [PATCH 15/66] Moving and resizing pattern info label (has few bugs still, probably just XML parsing) --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 24 +++++- src/libs/ifc/xml/vabstractpattern.cpp | 96 ++++++++++++++++++++- src/libs/ifc/xml/vabstractpattern.h | 11 +++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 10 +++ src/libs/vtools/tools/vtextgraphicsitem.h | 7 +- src/libs/vtools/tools/vtooldetail.cpp | 94 ++++++++++++++++++-- src/libs/vtools/tools/vtooldetail.h | 8 +- 7 files changed, 236 insertions(+), 14 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 74c58fb97..b90ec26c2 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -82,6 +82,11 @@ void VPattern::CreateEmptyFile() version.appendChild(newNodeText); patternElement.appendChild(version); + QDomElement domCreated = createElement(TagCreationDate); + QDomText domCreatedText = createTextNode(QDate::currentDate().toString("d.M.yyyy")); + domCreated.appendChild(domCreatedText); + patternElement.appendChild(domCreated); + QDomElement unit = createElement(TagUnit); newNodeText = createTextNode(UnitsToStr(qApp->patternUnit())); unit.appendChild(newNodeText); @@ -131,7 +136,9 @@ void VPattern::Parse(const Document &parse) SCASSERT(sceneDraw != nullptr); SCASSERT(sceneDetail != nullptr); QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes - << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit; + << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit + << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName + << TagCreationDate; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -191,6 +198,21 @@ void VPattern::Parse(const Document &parse) case 9: // TagUnit qCDebug(vXML, "Tag unit."); break; + case 10: // TagPatternName + qCDebug(vXML, "Pattern name."); + break; + case 11: // TagPatternNumber + qCDebug(vXML, "Pattern number."); + break; + case 12: // TagCompanyName + qCDebug(vXML, "Company name."); + break; + case 13: // TagCustomerName + qCDebug(vXML, "Customer name."); + break; + case 14: // TagCreationDate + qCDebug(vXML, "Creation date."); + break; default: qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); break; diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 5e9ba60ec..70915c8df 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -67,6 +67,7 @@ const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber" const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); +const QString VAbstractPattern::TagPatternLabel = QStringLiteral("patternLabel"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); @@ -78,6 +79,8 @@ const QString VAbstractPattern::AttrMaterial = QStringLiteral("material"); const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef"); const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber"); const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement"); +const QString VAbstractPattern::AttrWidth = QStringLiteral("width"); +const QString VAbstractPattern::AttrFont = QStringLiteral("font"); const QString VAbstractPattern::AttrAll = QStringLiteral("all"); @@ -1075,6 +1078,92 @@ QDate VAbstractPattern::GetCreationDate() const return QDate::currentDate(); } +//--------------------------------------------------------------------------------------------------------------------- +QPointF VAbstractPattern::GetLabelPosition() const +{ + QPointF ptPos(0.0, 0.0); + QDomNodeList li = elementsByTagName(TagPatternLabel); + if (li.count() == 0) + { + return ptPos; + } + + QDomNamedNodeMap attr = li.at(0).attributes(); + if (attr.contains(AttrMx) == true) + { + ptPos.setX(attr.namedItem(AttrMx).nodeValue().toDouble()); + } + if (attr.contains(AttrMy) == true) + { + ptPos.setY(attr.namedItem(AttrMy).nodeValue().toDouble()); + } + return ptPos; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetLabelPosition(const QPointF& ptPos) +{ + CheckTagExists(TagPatternLabel); + QDomNode node = elementsByTagName(TagPatternLabel).at(0); + node.toElement().setAttribute(AttrMx, ptPos.x()); + node.toElement().setAttribute(AttrMy, ptPos.y()); + emit patternChanged(false); + + qDebug() << "LABEL POSITION" << GetLabelPosition(); +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VAbstractPattern::GetLabelWidth() const +{ + qreal fW = 0.0; + QDomNodeList li = elementsByTagName(TagPatternLabel); + if (li.count() == 0) + { + return fW; + } + QDomNamedNodeMap attr = li.at(0).attributes(); + if (attr.contains(AttrWidth) == true) + { + fW = attr.namedItem(AttrWidth).nodeName().toDouble(); + } + return fW; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetLabelWidth(qreal fW) +{ + CheckTagExists(TagPatternLabel); + QDomNode node = elementsByTagName(TagPatternLabel).at(0); + node.toElement().setAttribute(AttrWidth, fW); + emit patternChanged(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VAbstractPattern::GetFontSize() const +{ + int iFS = 0; + QDomNodeList li = elementsByTagName(TagPatternLabel); + if (li.count() == 0) + { + return iFS; + } + QDomNamedNodeMap attr = li.at(0).attributes(); + if (attr.contains(AttrFont) == true) + { + iFS = attr.namedItem(AttrFont).nodeName().toInt(); + } + return iFS; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetFontSize(int iFS) +{ + CheckTagExists(TagPatternLabel); + QDomNode node = elementsByTagName(TagPatternLabel).at(0); + node.toElement().setAttribute(AttrWidth, iFS); + emit patternChanged(false); +} + //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPattern::GetImage() const { @@ -1200,7 +1289,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagCreationDate; + << TagCustomerName << TagCreationDate << TagPatternLabel; switch (tags.indexOf(tag)) { case 0: //TagUnit @@ -1266,6 +1355,11 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) element = createElement(TagCreationDate); break; } + case 11: + { + element = createElement(TagPatternLabel); + break; + } default: { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 4029f063a..11ccd3308 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -117,6 +117,12 @@ public: QString GetCustomerName() const; void SetCustomerName(QString qsName); QDate GetCreationDate() const; + QPointF GetLabelPosition() const; + void SetLabelPosition(const QPointF& ptPos); + qreal GetLabelWidth() const; + void SetLabelWidth(qreal fW); + int GetFontSize() const; + void SetFontSize(int iFS); QString GetImage() const; QString GetImageExtension() const; @@ -173,6 +179,7 @@ public: static const QString TagCompanyName; static const QString TagCustomerName; static const QString TagCreationDate; + static const QString TagPatternLabel; static const QString AttrName; static const QString AttrVisible; @@ -184,6 +191,8 @@ public: static const QString AttrUserDefined; static const QString AttrCutNumber; static const QString AttrPlacement; + static const QString AttrWidth; + static const QString AttrFont; static const QString AttrAll; @@ -308,6 +317,8 @@ protected: QDomElement CheckTagExists(const QString &tag); void InsertTag(const QStringList &tags, const QDomElement &element); + void SetChildTag(const QString& qsParent, const QString& qsChild, const QString& qsValue); + int GetIndexActivPP() const; private: Q_DISABLE_COPY(VAbstractPattern) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 02014e674..853d65039 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -124,6 +124,16 @@ void VTextGraphicsItem::Clear() m_liLines.clear(); } +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::SetWidth(qreal fW) +{ + if (fW < MIN_W) + { + fW = MIN_W; + } + m_rectBoundingBox.setWidth(fW); +} + //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::Reset() { diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index a9f62f3ae..caed2f7c8 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -66,6 +66,7 @@ public: QRectF boundingRect() const; void AddLine(const TextLine& tl); void Clear(); + void SetWidth(qreal fW); protected: void Resize(qreal fW, qreal fH); @@ -78,9 +79,9 @@ protected: QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); signals: - void SignalMoved(QPointF ptPos); - void SignalResized(qreal iTW, int iFontSize); - void SignalShrink(); + void SignalMoved(QPointF ptPos); + void SignalResized(qreal iTW, int iFontSize); + void SignalShrink(); private: Mode m_eMode; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 4be428f24..bc3f7e079 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -79,7 +79,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent) :VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene), drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)), - dataLabel(new VTextGraphicsItem(this)) + dataLabel(new VTextGraphicsItem(this)), patternInfo(new VTextGraphicsItem(this)) { VDetail detail = data->GetDetail(id); for (int i = 0; i< detail.CountNode(); ++i) @@ -128,10 +128,16 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 } setAcceptHoverEvents(true); - connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMove); - connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResize); + connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail); + connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail); connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); + + connect(patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMovePattern); + connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern); + connect(patternInfo, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); + connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); UpdateLabel(); + UpdatePatternInfo(); } //--------------------------------------------------------------------------------------------------------------------- @@ -684,9 +690,63 @@ void VToolDetail::UpdateLabel() //--------------------------------------------------------------------------------------------------------------------- /** - * @brief SaveMove saves the move operation to the undo stack + * @brief UpdatePatternInfo updates the pattern info label */ -void VToolDetail::SaveMove(QPointF ptPos) +void VToolDetail::UpdatePatternInfo() +{ + QFont fnt = qApp->font(); + int iFS = doc->GetFontSize(); + if (iFS < MIN_FONT_SIZE) + { + iFS = MIN_FONT_SIZE; + } + fnt.setPixelSize(iFS); + patternInfo->SetFont(fnt); + patternInfo->SetWidth(doc->GetLabelWidth()); + patternInfo->Clear(); + TextLine tl; + + // Company name + tl.m_qsText = doc->GetCompanyName(); + tl.m_eAlign = Qt::AlignCenter; + tl.m_eFontWeight = QFont::DemiBold; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 4; + patternInfo->AddLine(tl); + + // Pattern name + tl.m_qsText = doc->GetPatternName(); + tl.m_eFontWeight = QFont::Normal; + tl.m_iFontSize = 2; + patternInfo->AddLine(tl); + + // Pattern number + tl.m_qsText = doc->GetPatternNumber(); + tl.m_iFontSize = 0; + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + patternInfo->AddLine(tl); + + // Customer name + tl.m_qsText = doc->GetCustomerName(); + tl.m_eStyle = QFont::StyleItalic; + patternInfo->AddLine(tl); + + // Creation date + QStringList qslDate = doc->GetCreationDate().toString(Qt::SystemLocaleLongDate).split(", "); + tl.m_qsText = qslDate.last(); + patternInfo->AddLine(tl); + + qDebug() << "UpdatePatternInfo" << doc->GetLabelPosition() << sender(); + patternInfo->setPos(doc->GetLabelPosition()); + patternInfo->Reset(); +} + +//--------------------------------------------------------------------------------------------------------------------- + +/** + * @brief SaveMoveDetail saves the move detail operation to the undo stack + */ +void VToolDetail::SaveMoveDetail(QPointF ptPos) { VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail newDet = oldDet; @@ -699,9 +759,9 @@ void VToolDetail::SaveMove(QPointF ptPos) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief: SaveResize save the resize label operation to the undo stack + * @brief SaveResizeDetail saves the resize detail label operation to the undo stack */ -void VToolDetail::SaveResize(qreal dLabelW, int iFontSize) +void VToolDetail::SaveResizeDetail(qreal dLabelW, int iFontSize) { VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail newDet = oldDet; @@ -713,6 +773,26 @@ void VToolDetail::SaveResize(qreal dLabelW, int iFontSize) qApp->getUndoStack()->push(resizeCommand); } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief SaveMovePattern saves the pattern label position + */ +void VToolDetail::SaveMovePattern(QPointF ptPos) +{ + qDebug() << "Pattern moved to" << ptPos; + doc->SetLabelPosition(ptPos); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief: SaveResizePattern saves the pattern label width and font size + */ +void VToolDetail::SaveResizePattern(qreal dLabelW, int iFontSize) +{ + doc->SetLabelWidth(dLabelW); + doc->SetFontSize(iFontSize); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddNode add node to the file. diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index f4fd7eba9..9f5f2d1a7 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -106,10 +106,13 @@ protected: virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE {} virtual void UpdateLabel(); + virtual void UpdatePatternInfo(); protected slots: - virtual void SaveMove(QPointF ptPos); - virtual void SaveResize(qreal dLabelW, int iFontSize); + virtual void SaveMoveDetail(QPointF ptPos); + virtual void SaveResizeDetail(qreal dLabelW, int iFontSize); + virtual void SaveMovePattern(QPointF ptPos); + virtual void SaveResizePattern(qreal dLabelW, int iFontSize); private: Q_DISABLE_COPY(VToolDetail) @@ -122,6 +125,7 @@ private: VNoBrushScalePathItem *seamAllowance; VTextGraphicsItem* dataLabel; + VTextGraphicsItem* patternInfo; VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr); From 80fcf30776c7713993312ba938fc448cb355aac8 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Mon, 27 Jun 2016 11:06:51 +0200 Subject: [PATCH 16/66] Moving, resizing and editing both labels now works --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 11 ++- src/libs/ifc/xml/vabstractpattern.cpp | 94 ++++++++++----------- src/libs/ifc/xml/vabstractpattern.h | 6 +- src/libs/vtools/tools/vtextgraphicsitem.cpp | 2 + src/libs/vtools/tools/vtooldetail.cpp | 5 +- src/libs/vtools/tools/vtooldetail.h | 2 +- 6 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index b90ec26c2..fa5141149 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -138,7 +138,7 @@ void VPattern::Parse(const Document &parse) QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName - << TagCreationDate; + << TagCreationDate << TagLabelPos << TagLabelWidth << TagLabelFont; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -213,6 +213,15 @@ void VPattern::Parse(const Document &parse) case 14: // TagCreationDate qCDebug(vXML, "Creation date."); break; + case 15: // TagLabelPos + qCDebug(vXML, "Label position."); + break; + case 16: // TagLabelWidth + qCDebug(vXML, "Label width."); + break; + case 17: // TagLabelFont + qCDebug(vXML, "Label font size."); + break; default: qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); break; diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 70915c8df..fc9a8e0ae 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -67,7 +67,9 @@ const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber" const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); -const QString VAbstractPattern::TagPatternLabel = QStringLiteral("patternLabel"); +const QString VAbstractPattern::TagLabelPos = QStringLiteral("labelPosition"); +const QString VAbstractPattern::TagLabelWidth = QStringLiteral("labelWidth"); +const QString VAbstractPattern::TagLabelFont = QStringLiteral("fontSize"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); @@ -79,8 +81,6 @@ const QString VAbstractPattern::AttrMaterial = QStringLiteral("material"); const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef"); const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber"); const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement"); -const QString VAbstractPattern::AttrWidth = QStringLiteral("width"); -const QString VAbstractPattern::AttrFont = QStringLiteral("font"); const QString VAbstractPattern::AttrAll = QStringLiteral("all"); @@ -1081,21 +1081,19 @@ QDate VAbstractPattern::GetCreationDate() const //--------------------------------------------------------------------------------------------------------------------- QPointF VAbstractPattern::GetLabelPosition() const { - QPointF ptPos(0.0, 0.0); - QDomNodeList li = elementsByTagName(TagPatternLabel); - if (li.count() == 0) + QStringList qsl = UniqueTagText(TagLabelPos).split(","); + QPointF ptPos(0, 0); + if (qsl.count() == 2) { - return ptPos; - } - - QDomNamedNodeMap attr = li.at(0).attributes(); - if (attr.contains(AttrMx) == true) - { - ptPos.setX(attr.namedItem(AttrMx).nodeValue().toDouble()); - } - if (attr.contains(AttrMy) == true) - { - ptPos.setY(attr.namedItem(AttrMy).nodeValue().toDouble()); + bool bOKX; + bool bOKY; + double fX = qsl[0].toDouble(&bOKX); + double fY = qsl[1].toDouble(&bOKY); + if (bOKX == true && bOKY == true) + { + ptPos.setX(fX); + ptPos.setY(fY); + } } return ptPos; } @@ -1103,28 +1101,20 @@ QPointF VAbstractPattern::GetLabelPosition() const //--------------------------------------------------------------------------------------------------------------------- void VAbstractPattern::SetLabelPosition(const QPointF& ptPos) { - CheckTagExists(TagPatternLabel); - QDomNode node = elementsByTagName(TagPatternLabel).at(0); - node.toElement().setAttribute(AttrMx, ptPos.x()); - node.toElement().setAttribute(AttrMy, ptPos.y()); + CheckTagExists(TagLabelPos); + setTagText(TagLabelPos, QString::number(ptPos.x(), 'f', 3) + "," + QString::number(ptPos.y(), 'f', 3)); + modified = true; emit patternChanged(false); - - qDebug() << "LABEL POSITION" << GetLabelPosition(); } //--------------------------------------------------------------------------------------------------------------------- qreal VAbstractPattern::GetLabelWidth() const { - qreal fW = 0.0; - QDomNodeList li = elementsByTagName(TagPatternLabel); - if (li.count() == 0) + bool bOK; + qreal fW = UniqueTagText(TagLabelWidth).toDouble(&bOK); + if (bOK == false) { - return fW; - } - QDomNamedNodeMap attr = li.at(0).attributes(); - if (attr.contains(AttrWidth) == true) - { - fW = attr.namedItem(AttrWidth).nodeName().toDouble(); + fW = 0; } return fW; } @@ -1132,25 +1122,20 @@ qreal VAbstractPattern::GetLabelWidth() const //--------------------------------------------------------------------------------------------------------------------- void VAbstractPattern::SetLabelWidth(qreal fW) { - CheckTagExists(TagPatternLabel); - QDomNode node = elementsByTagName(TagPatternLabel).at(0); - node.toElement().setAttribute(AttrWidth, fW); + CheckTagExists(TagLabelWidth); + setTagText(TagLabelWidth, QString::number(fW, 'f', 3)); + modified = true; emit patternChanged(false); } //--------------------------------------------------------------------------------------------------------------------- int VAbstractPattern::GetFontSize() const { - int iFS = 0; - QDomNodeList li = elementsByTagName(TagPatternLabel); - if (li.count() == 0) + bool bOK; + int iFS = UniqueTagText(TagLabelFont).toInt(&bOK); + if (bOK == false) { - return iFS; - } - QDomNamedNodeMap attr = li.at(0).attributes(); - if (attr.contains(AttrFont) == true) - { - iFS = attr.namedItem(AttrFont).nodeName().toInt(); + iFS = 0; } return iFS; } @@ -1158,9 +1143,9 @@ int VAbstractPattern::GetFontSize() const //--------------------------------------------------------------------------------------------------------------------- void VAbstractPattern::SetFontSize(int iFS) { - CheckTagExists(TagPatternLabel); - QDomNode node = elementsByTagName(TagPatternLabel).at(0); - node.toElement().setAttribute(AttrWidth, iFS); + CheckTagExists(TagLabelFont); + setTagText(TagLabelFont, QString::number(iFS)); + modified = true; emit patternChanged(false); } @@ -1289,7 +1274,8 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagCreationDate << TagPatternLabel; + << TagCustomerName << TagCreationDate << TagLabelPos << TagLabelWidth + << TagLabelFont; switch (tags.indexOf(tag)) { case 0: //TagUnit @@ -1357,7 +1343,17 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) } case 11: { - element = createElement(TagPatternLabel); + element = createElement(TagLabelPos); + break; + } + case 12: + { + element = createElement(TagLabelWidth); + break; + } + case 13: + { + element = createElement(TagLabelFont); break; } diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 11ccd3308..fe6a44094 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -179,7 +179,9 @@ public: static const QString TagCompanyName; static const QString TagCustomerName; static const QString TagCreationDate; - static const QString TagPatternLabel; + static const QString TagLabelPos; + static const QString TagLabelWidth; + static const QString TagLabelFont; static const QString AttrName; static const QString AttrVisible; @@ -191,8 +193,6 @@ public: static const QString AttrUserDefined; static const QString AttrCutNumber; static const QString AttrPlacement; - static const QString AttrWidth; - static const QString AttrFont; static const QString AttrAll; diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 853d65039..1d27cc508 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -139,6 +139,7 @@ void VTextGraphicsItem::Reset() { m_eMode = mNormal; UpdateFont(); + setZValue(2); } //--------------------------------------------------------------------------------------------------------------------- @@ -174,6 +175,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { m_eMode = mMove; } + setZValue(3); Update(); } diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index bc3f7e079..f4430d494 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -117,7 +117,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove); - connect(scene, &VMainGraphicsScene::MouseLeftPressed, this, &VToolDetail::ResetChild); + connect(scene, &VMainGraphicsScene::MouseLeftPressed, this, &VToolDetail::ResetChildren); if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) { AddToFile(); @@ -942,9 +942,10 @@ void VToolDetail::AllowSelecting(bool enabled) } //--------------------------------------------------------------------------------------------------------------------- -void VToolDetail::ResetChild() +void VToolDetail::ResetChildren() { dataLabel->Reset(); + patternInfo->Reset(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 9f5f2d1a7..a68891276 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -91,7 +91,7 @@ public slots: void EnableToolMove(bool move); virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; - virtual void ResetChild(); + virtual void ResetChildren(); virtual void UpdateAll(); protected: virtual void AddToFile () Q_DECL_OVERRIDE; From 6577d82771db104d5960442169d9d2e96d18aa2b Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Mon, 27 Jun 2016 17:18:43 +0200 Subject: [PATCH 17/66] Added new schema to accomodate for new parameters and did some other minor changes. There is a bug with Undo on details label, will check that later --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 16 +- src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.3.3.xsd | 545 ++++++++++++++++++ src/libs/ifc/xml/vabstractpattern.cpp | 32 +- src/libs/ifc/xml/vabstractpattern.h | 6 +- src/libs/ifc/xml/vpatternconverter.cpp | 6 +- src/libs/vpatterndb/vpatternpiecedata.cpp | 12 + src/libs/vpatterndb/vpatternpiecedata.h | 5 + src/libs/vtools/tools/vtextgraphicsitem.cpp | 68 ++- src/libs/vtools/tools/vtextgraphicsitem.h | 6 +- src/libs/vtools/tools/vtooldetail.cpp | 18 +- src/libs/vtools/tools/vtooldetail.h | 1 + .../vtools/undocommands/savedetailoptions.cpp | 1 + 13 files changed, 649 insertions(+), 68 deletions(-) create mode 100644 src/libs/ifc/schema/pattern/v0.3.3.xsd diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index fa5141149..63e75885b 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -138,7 +138,7 @@ void VPattern::Parse(const Document &parse) QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName - << TagCreationDate << TagLabelPos << TagLabelWidth << TagLabelFont; + << TagCreationDate << TagLabelPos << TagLabelSize << TagLabelFont; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -216,8 +216,8 @@ void VPattern::Parse(const Document &parse) case 15: // TagLabelPos qCDebug(vXML, "Label position."); break; - case 16: // TagLabelWidth - qCDebug(vXML, "Label width."); + case 16: // TagLabelSize + qCDebug(vXML, "Label size."); break; case 17: // TagLabelFont qCDebug(vXML, "Label font size."); @@ -614,11 +614,6 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); try { - QString qs; - QTextStream ts(&qs, QIODevice::WriteOnly); - domElement.save(ts, 2); - qDebug() << "Parse detail" << qs; - VDetail detail; const quint32 id = GetParametrId(domElement); detail.setName(GetParametrString(domElement, AttrName, "")); @@ -681,6 +676,11 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document detail.GetPatternPieceData().SetPos(ptPos); qreal dLW = element.attribute(VToolDetail::AttrWidth, "0").toDouble(); detail.GetPatternPieceData().SetLabelWidth(dLW); + qreal dLH = element.attribute(VToolDetail::AttrHeight, "0").toDouble(); + detail.GetPatternPieceData().SetLabelHeight(dLH); + qDebug() << "HEIGHT" << + detail.GetPatternPieceData().GetPos() << + detail.GetPatternPieceData().GetLabelHeight(); int iFS = element.attribute(VToolDetail::AttrFont, "0").toInt(); detail.GetPatternPieceData().SetFontSize(iFS); diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index fe077d4dc..04fbb08f5 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -25,5 +25,6 @@ schema/individual_measurements/v0.3.1.xsd schema/individual_measurements/v0.3.2.xsd schema/individual_measurements/v0.3.3.xsd + schema/pattern/v0.3.3.xsd diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd new file mode 100644 index 000000000..64d1650d6 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -0,0 +1,545 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index fc9a8e0ae..ca24447e5 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -68,7 +68,7 @@ const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); const QString VAbstractPattern::TagLabelPos = QStringLiteral("labelPosition"); -const QString VAbstractPattern::TagLabelWidth = QStringLiteral("labelWidth"); +const QString VAbstractPattern::TagLabelSize = QStringLiteral("labelSize"); const QString VAbstractPattern::TagLabelFont = QStringLiteral("fontSize"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); @@ -1108,22 +1108,30 @@ void VAbstractPattern::SetLabelPosition(const QPointF& ptPos) } //--------------------------------------------------------------------------------------------------------------------- -qreal VAbstractPattern::GetLabelWidth() const +QSizeF VAbstractPattern::GetLabelSize() const { - bool bOK; - qreal fW = UniqueTagText(TagLabelWidth).toDouble(&bOK); - if (bOK == false) + QStringList qsl = UniqueTagText(TagLabelSize).split(","); + QSizeF sz(0, 0); + if (qsl.count() == 2) { - fW = 0; + bool bOKW; + bool bOKH; + double fW = qsl[0].toDouble(&bOKW); + double fH = qsl[1].toDouble(&bOKH); + if (bOKW == true && bOKH == true) + { + sz.setWidth(fW); + sz.setHeight(fH); + } } - return fW; + return sz; } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetLabelWidth(qreal fW) +void VAbstractPattern::SetLabelSize(QSizeF sz) { - CheckTagExists(TagLabelWidth); - setTagText(TagLabelWidth, QString::number(fW, 'f', 3)); + CheckTagExists(TagLabelSize); + setTagText(TagLabelSize, QString::number(sz.width(), 'f', 3) + "," + QString::number(sz.height(), 'f', 3)); modified = true; emit patternChanged(false); } @@ -1274,7 +1282,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagCreationDate << TagLabelPos << TagLabelWidth + << TagCustomerName << TagCreationDate << TagLabelPos << TagLabelSize << TagLabelFont; switch (tags.indexOf(tag)) { @@ -1348,7 +1356,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) } case 12: { - element = createElement(TagLabelWidth); + element = createElement(TagLabelSize); break; } case 13: diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index fe6a44094..f0dc2dcf0 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -119,8 +119,8 @@ public: QDate GetCreationDate() const; QPointF GetLabelPosition() const; void SetLabelPosition(const QPointF& ptPos); - qreal GetLabelWidth() const; - void SetLabelWidth(qreal fW); + QSizeF GetLabelSize() const; + void SetLabelSize(QSizeF sz); int GetFontSize() const; void SetFontSize(int iFS); @@ -180,7 +180,7 @@ public: static const QString TagCustomerName; static const QString TagCreationDate; static const QString TagLabelPos; - static const QString TagLabelWidth; + static const QString TagLabelSize; static const QString TagLabelFont; static const QString AttrName; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index cb16a65fc..2e9fe11d1 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -43,8 +43,8 @@ */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.2"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.2.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.3"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.3.xsd"); //--------------------------------------------------------------------------------------------------------------------- VPatternConverter::VPatternConverter(const QString &fileName) @@ -117,6 +117,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000301): return QStringLiteral("://schema/pattern/v0.3.1.xsd"); case (0x000302): + return QStringLiteral("://schema/pattern/v0.3.2.xsd"); + case (0x000303): return CurrentSchema; default: InvalidVersion(ver); diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index 560d776a6..7b939a770 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -141,6 +141,18 @@ void VPatternPieceData::SetLabelWidth(qreal dLabelW) m_dLabelWidth = dLabelW; } +//--------------------------------------------------------------------------------------------------------------------- +qreal VPatternPieceData::GetLabelHeight() const +{ + return m_dLabelHeight; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternPieceData::SetLabelHeight(qreal dLabelH) +{ + m_dLabelHeight = dLabelH; +} + //--------------------------------------------------------------------------------------------------------------------- int VPatternPieceData::GetFontSize() const { diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h index aee873fbb..ab0295d82 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -89,6 +89,8 @@ public: void SetPos(const QPointF& ptPos); qreal GetLabelWidth() const; void SetLabelWidth(qreal dLabelW); + qreal GetLabelHeight() const; + void SetLabelHeight(qreal dLabelH); int GetFontSize() const; void SetFontSize(int iSize); @@ -108,6 +110,9 @@ private: /** @brief Label width */ qreal m_dLabelWidth; + /** @brief Label height + */ + qreal m_dLabelHeight; /** @brief Label font size */ int m_iFontSize; diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 1d27cc508..121e6c6f5 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -50,7 +50,7 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) m_eMode = mNormal; m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_iMinH = MIN_H; - Resize(MIN_W, m_iMinH); + SetSize(MIN_W, m_iMinH); setZValue(2); } @@ -71,7 +71,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem // draw text lines int iY = 0; - int iH; + int iH = 0; painter->setPen(Qt::black); QFont fnt = m_font; for (int i = 0; i < m_liOutput.count(); ++i) @@ -104,6 +104,14 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem } } +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::Reset() +{ + m_eMode = mNormal; + Update(); + setZValue(2); +} + //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::AddLine(const TextLine& tl) { @@ -114,7 +122,7 @@ void VTextGraphicsItem::AddLine(const TextLine& tl) } if (m_rectBoundingBox.height() < m_iMinH) { - Resize(m_rectBoundingBox.width(), m_iMinH); + SetSize(m_rectBoundingBox.width(), m_iMinH); } } @@ -125,31 +133,7 @@ void VTextGraphicsItem::Clear() } //--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::SetWidth(qreal fW) -{ - if (fW < MIN_W) - { - fW = MIN_W; - } - m_rectBoundingBox.setWidth(fW); -} - -//--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::Reset() -{ - m_eMode = mNormal; - UpdateFont(); - setZValue(2); -} - -//--------------------------------------------------------------------------------------------------------------------- -QRectF VTextGraphicsItem::boundingRect() const -{ - return m_rectBoundingBox; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::Resize(qreal fW, qreal fH) +void VTextGraphicsItem::SetSize(qreal fW, qreal fH) { // don't allow resize under specific size if (fW < MIN_W || fH < m_iMinH) @@ -162,6 +146,19 @@ void VTextGraphicsItem::Resize(qreal fW, qreal fH) m_rectResize.setHeight(RESIZE_SQUARE); } +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::Update() +{ + UpdateFont(); + UpdateBox(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VTextGraphicsItem::boundingRect() const +{ + return m_rectBoundingBox; +} + //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { @@ -176,7 +173,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) m_eMode = mMove; } setZValue(3); - Update(); + UpdateBox(); } //--------------------------------------------------------------------------------------------------------------------- @@ -186,12 +183,12 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) if (m_eMode == mMove) { moveBy(ptDiff.x(), ptDiff.y()); - Update(); + UpdateBox(); } else if (m_eMode == mResize) { - Resize(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); - UpdateFont(); + SetSize(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); + Update(); emit SignalShrink(); } } @@ -202,17 +199,18 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) if (m_eMode == mMove) { emit SignalMoved(pos()); + UpdateBox(); } else { emit SignalResized(m_rectBoundingBox.width(), m_font.pixelSize()); + Update(); } m_eMode = mActivated; - Update(); } //--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::Update() +void VTextGraphicsItem::UpdateBox() { update(m_rectBoundingBox); } @@ -233,7 +231,7 @@ void VTextGraphicsItem::UpdateFont() --iFS; } m_font.setPixelSize(iFS); - Update(); + UpdateBox(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index caed2f7c8..62991aba4 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -66,14 +66,14 @@ public: QRectF boundingRect() const; void AddLine(const TextLine& tl); void Clear(); - void SetWidth(qreal fW); + void SetSize(qreal fW, qreal fH); + void Update(); protected: - void Resize(qreal fW, qreal fH); void mousePressEvent(QGraphicsSceneMouseEvent* pME); void mouseMoveEvent(QGraphicsSceneMouseEvent* pME); void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME); - void Update(); + void UpdateBox(); void UpdateFont(); bool IsBigEnough(qreal fW, qreal fH, int iFontSize); QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index f4430d494..cc80d74a4 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -53,6 +53,7 @@ const QString VToolDetail::TagNode = QStringLiteral("node"); const QString VToolDetail::AttrSupplement = QStringLiteral("supplement"); const QString VToolDetail::AttrClosed = QStringLiteral("closed"); const QString VToolDetail::AttrWidth = QStringLiteral("width"); +const QString VToolDetail::AttrHeight = QStringLiteral("height"); const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType"); const QString VToolDetail::AttrReverse = QStringLiteral("reverse"); const QString VToolDetail::AttrFont = QStringLiteral("fontSize"); @@ -351,6 +352,7 @@ void VToolDetail::AddToFile() doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); + doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight()); doc->SetAttribute(domData, AttrFont, data.GetFontSize()); for (int i = 0; i < data.GetMCPCount(); ++i) @@ -398,6 +400,7 @@ void VToolDetail::RefreshDataInFile() doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); + doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight()); doc->SetAttribute(domData, AttrFont, data.GetFontSize()); for (int i = 0; i < data.GetMCPCount(); ++i) @@ -648,12 +651,15 @@ void VToolDetail::UpdateLabel() const VPatternPieceData& data = detail.GetPatternPieceData(); if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0) { + dataLabel->Reset(); + QString qsText = "Cut %1 of %2%3"; QStringList qslPlace; qslPlace << "" << " on Fold"; QFont fnt = qApp->font(); fnt.setPixelSize(data.GetFontSize()); dataLabel->SetFont(fnt); + dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight()); dataLabel->Clear(); TextLine tl; // letter @@ -679,7 +685,7 @@ void VToolDetail::UpdateLabel() } dataLabel->setPos(data.GetPos()); - dataLabel->Reset(); + dataLabel->Update(); dataLabel->show(); } else @@ -694,6 +700,7 @@ void VToolDetail::UpdateLabel() */ void VToolDetail::UpdatePatternInfo() { + patternInfo->Reset(); QFont fnt = qApp->font(); int iFS = doc->GetFontSize(); if (iFS < MIN_FONT_SIZE) @@ -702,7 +709,8 @@ void VToolDetail::UpdatePatternInfo() } fnt.setPixelSize(iFS); patternInfo->SetFont(fnt); - patternInfo->SetWidth(doc->GetLabelWidth()); + QSizeF sz = doc->GetLabelSize(); + patternInfo->SetSize(sz.width(), sz.height()); patternInfo->Clear(); TextLine tl; @@ -736,9 +744,8 @@ void VToolDetail::UpdatePatternInfo() tl.m_qsText = qslDate.last(); patternInfo->AddLine(tl); - qDebug() << "UpdatePatternInfo" << doc->GetLabelPosition() << sender(); patternInfo->setPos(doc->GetLabelPosition()); - patternInfo->Reset(); + patternInfo->Update(); } //--------------------------------------------------------------------------------------------------------------------- @@ -766,6 +773,7 @@ void VToolDetail::SaveResizeDetail(qreal dLabelW, int iFontSize) VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail newDet = oldDet; newDet.GetPatternPieceData().SetLabelWidth(dLabelW); + newDet.GetPatternPieceData().SetLabelHeight(dataLabel->boundingRect().height()); newDet.GetPatternPieceData().SetFontSize(iFontSize); SaveDetailOptions* resizeCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); resizeCommand->setText(tr("resize pattern piece label")); @@ -789,7 +797,7 @@ void VToolDetail::SaveMovePattern(QPointF ptPos) */ void VToolDetail::SaveResizePattern(qreal dLabelW, int iFontSize) { - doc->SetLabelWidth(dLabelW); + doc->SetLabelSize(QSizeF(dLabelW, patternInfo->boundingRect().height())); doc->SetFontSize(iFontSize); } diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index a68891276..eed34865f 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -69,6 +69,7 @@ public: static const QString AttrSupplement; static const QString AttrClosed; static const QString AttrWidth; + static const QString AttrHeight; static const QString AttrNodeType; static const QString AttrReverse; static const QString AttrFont; diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 47e94f147..bc30cdca8 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -140,6 +140,7 @@ void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDet doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth()); + doc->SetAttribute(domData, VToolDetail::AttrHeight, data.GetLabelHeight()); doc->SetAttribute(domData, VToolDetail::AttrFont, data.GetFontSize()); for (int i = 0; i < data.GetMCPCount(); ++i) { From 2b7f0565668c8df8d92d107d7d49965f05fcfa22 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Mon, 27 Jun 2016 20:51:29 +0200 Subject: [PATCH 18/66] Fixed schema and undo bug --HG-- branch : feature --- src/libs/ifc/schema.qrc | 2 +- src/libs/vtools/tools/vtooldetail.cpp | 3 +++ src/libs/vtools/tools/vtooldetail.h | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 04fbb08f5..9b8a3e493 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -16,6 +16,7 @@ schema/pattern/v0.3.0.xsd schema/pattern/v0.3.1.xsd schema/pattern/v0.3.2.xsd + schema/pattern/v0.3.3.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd @@ -25,6 +26,5 @@ schema/individual_measurements/v0.3.1.xsd schema/individual_measurements/v0.3.2.xsd schema/individual_measurements/v0.3.3.xsd - schema/pattern/v0.3.3.xsd diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index cc80d74a4..d575367c5 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -137,6 +137,8 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern); connect(patternInfo, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); + + connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); UpdateLabel(); UpdatePatternInfo(); } @@ -648,6 +650,7 @@ void VToolDetail::UpdateLabel() { const VDetail detail = VAbstractTool::data.GetDetail(id); + qDebug() << "Update label"; const VPatternPieceData& data = detail.GetPatternPieceData(); if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0) { diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index eed34865f..edc0e193e 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -106,10 +106,10 @@ protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) Q_DECL_OVERRIDE; virtual void keyReleaseEvent(QKeyEvent * event) Q_DECL_OVERRIDE; virtual void SetVisualization() Q_DECL_OVERRIDE {} - virtual void UpdateLabel(); - virtual void UpdatePatternInfo(); protected slots: + virtual void UpdateLabel(); + virtual void UpdatePatternInfo(); virtual void SaveMoveDetail(QPointF ptPos); virtual void SaveResizeDetail(qreal dLabelW, int iFontSize); virtual void SaveMovePattern(QPointF ptPos); From 060411ef09a3fd51dbe4962ad12e8c4c6cd7a7b2 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 28 Jun 2016 01:02:42 +0200 Subject: [PATCH 19/66] Updated schema v0.3.3.xsd --HG-- branch : feature --- src/libs/ifc/schema/pattern/v0.3.3.xsd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd index 64d1650d6..f7c78c74f 100644 --- a/src/libs/ifc/schema/pattern/v0.3.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -341,10 +341,10 @@ - + - + From caa13f06ac10037b52ff4975fc70fe807f429307 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Wed, 29 Jun 2016 23:39:52 +0200 Subject: [PATCH 20/66] Corrected some warnings --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 45 ++++++++++++--------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 121e6c6f5..4b316a66b 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -67,6 +67,7 @@ void VTextGraphicsItem::SetFont(const QFont& fnt) //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { + Q_UNUSED(widget); painter->fillRect(option->rect, QColor(251, 251, 175)); // draw text lines @@ -162,18 +163,21 @@ QRectF VTextGraphicsItem::boundingRect() const //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { - m_ptStart = pME->pos(); - m_szStart = m_rectBoundingBox.size(); - if (m_rectResize.contains(m_ptStart) == true) + if ((pME->buttons() & Qt::LeftButton) > 0) { - m_eMode = mResize; + m_ptStart = pME->pos(); + m_szStart = m_rectBoundingBox.size(); + if (m_rectResize.contains(m_ptStart) == true) + { + m_eMode = mResize; + } + else + { + m_eMode = mMove; + } + setZValue(3); + UpdateBox(); } - else - { - m_eMode = mMove; - } - setZValue(3); - UpdateBox(); } //--------------------------------------------------------------------------------------------------------------------- @@ -196,17 +200,20 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { - if (m_eMode == mMove) + if ((pME->buttons() & Qt::LeftButton) > 0) { - emit SignalMoved(pos()); - UpdateBox(); + if (m_eMode == mMove) + { + emit SignalMoved(pos()); + UpdateBox(); + } + else + { + emit SignalResized(m_rectBoundingBox.width(), m_font.pixelSize()); + Update(); + } + m_eMode = mActivated; } - else - { - emit SignalResized(m_rectBoundingBox.width(), m_font.pixelSize()); - Update(); - } - m_eMode = mActivated; } //--------------------------------------------------------------------------------------------------------------------- From 0f90b6123513c5bca86fe6cce212ea563a6d9f8c Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Wed, 29 Jun 2016 23:52:48 +0200 Subject: [PATCH 21/66] Fixed the vtextgraphicsitem mouse events bug --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 4b316a66b..f64b7e162 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -163,7 +163,7 @@ QRectF VTextGraphicsItem::boundingRect() const //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { - if ((pME->buttons() & Qt::LeftButton) > 0) + if (pME->button() == Qt::LeftButton) { m_ptStart = pME->pos(); m_szStart = m_rectBoundingBox.size(); @@ -200,7 +200,7 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { - if ((pME->buttons() & Qt::LeftButton) > 0) + if (pME->button() == Qt::LeftButton) { if (m_eMode == mMove) { From 23a31b1fa925b002fa4eb7afec2797fc6220fe80 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 30 Jun 2016 18:04:25 +0200 Subject: [PATCH 22/66] Rotation of the labels. There are a couple of bugs still to fix --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 129 ++++++++++++++++---- src/libs/vtools/tools/vtextgraphicsitem.h | 11 +- 2 files changed, 113 insertions(+), 27 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index f64b7e162..dbf38e1df 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -29,12 +29,13 @@ #include #include #include -#include +#include #include #include "vtextgraphicsitem.h" #define RESIZE_SQUARE 30 +#define ROTATE_CIRCLE 20 #define MIN_W 120 #define MIN_H 60 #define MIN_FONT_SIZE 12 @@ -48,6 +49,7 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); m_eMode = mNormal; + m_bReleased = false; m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_iMinH = MIN_H; SetSize(MIN_W, m_iMinH); @@ -93,14 +95,28 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->setPen(QPen(Qt::black, 2, Qt::DashLine)); painter->drawRect(boundingRect().adjusted(1, 1, -1, -1)); - painter->setPen(Qt::black); - painter->setBrush(Qt::black); - painter->drawRect(m_rectResize); - - if (m_eMode == mResize) + if (m_eMode != mRotate) { - painter->drawLine(0, 0, m_rectBoundingBox.width(), m_rectBoundingBox.height()); - painter->drawLine(0, m_rectBoundingBox.height(), m_rectBoundingBox.width(), 0); + painter->setPen(Qt::black); + painter->setBrush(Qt::black); + painter->drawRect(m_rectResize); + + if (m_eMode == mResize) + { + painter->drawLine(0, 0, m_rectBoundingBox.width(), m_rectBoundingBox.height()); + painter->drawLine(0, m_rectBoundingBox.height(), m_rectBoundingBox.width(), 0); + } + } + else + { + painter->setPen(Qt::black); + painter->setBrush(Qt::black); + painter->drawEllipse( + m_rectBoundingBox.width()/2, + m_rectBoundingBox.height()/2, + ROTATE_CIRCLE, + ROTATE_CIRCLE + ); } } } @@ -108,7 +124,9 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::Reset() { + return; m_eMode = mNormal; + m_bReleased = false; Update(); setZValue(2); } @@ -165,28 +183,37 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { if (pME->button() == Qt::LeftButton) { - m_ptStart = pME->pos(); + qDebug() << "PRESS" << m_eMode; + m_ptStartPos = pos(); + m_ptStart = pME->scenePos(); m_szStart = m_rectBoundingBox.size(); - if (m_rectResize.contains(m_ptStart) == true) + m_dAngle = GetAngle(pME->scenePos()); + m_dRotation = rotation(); + if (m_eMode != mRotate) { - m_eMode = mResize; - } - else - { - m_eMode = mMove; + if (m_rectResize.contains(pME->pos()) == true) + { + m_eMode = mResize; + } + else + { + m_eMode = mMove; + } } setZValue(3); UpdateBox(); + qDebug() << "PRESS finished" << m_eMode; } } //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { - QPointF ptDiff = pME->pos() - m_ptStart; + QPointF ptDiff = pME->scenePos() - m_ptStart; if (m_eMode == mMove) { - moveBy(ptDiff.x(), ptDiff.y()); + //moveBy(ptDiff.x(), ptDiff.y()); + setPos(m_ptStartPos + ptDiff); UpdateBox(); } else if (m_eMode == mResize) @@ -195,6 +222,17 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) Update(); emit SignalShrink(); } + else if (m_eMode == mRotate) + { + if (fabs(m_dAngle) < 0.01) + { + m_dAngle = GetAngle(pME->scenePos()); + return; + } + double dAng = 180*(GetAngle(pME->scenePos()) - m_dAngle)/M_PI; + setRotation(m_dRotation + dAng); + Update(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -202,17 +240,46 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (pME->button() == Qt::LeftButton) { - if (m_eMode == mMove) - { - emit SignalMoved(pos()); - UpdateBox(); + double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y()); + bool bShort = (dDist < 2); + + qDebug() << "RELEASE" << m_eMode << dDist; + + if (m_eMode == mMove || m_eMode == mResize) + { // when released in mMove or mResize mode + if (bShort == true) + { + if (m_bReleased == true) + { + m_eMode = mRotate; + UpdateBox(); + } + } + else if (m_eMode == mMove) + { + emit SignalMoved(pos()); + UpdateBox(); + } + else + { + emit SignalResized(m_rectBoundingBox.width(), m_font.pixelSize()); + Update(); + } } else - { - emit SignalResized(m_rectBoundingBox.width(), m_font.pixelSize()); - Update(); + { // when released in mRotate mode + if (bShort == true) + { + m_eMode = mMove; + UpdateBox(); + } + else + { + emit SignalRotated(rotation()); + UpdateBox(); + } } - m_eMode = mActivated; + m_bReleased = true; } } @@ -291,3 +358,15 @@ QStringList VTextGraphicsItem::SplitString(const QString &qs, qreal fW, const QF qslLines << qsCurrent; return qslLines; } + +//--------------------------------------------------------------------------------------------------------------------- +double VTextGraphicsItem::GetAngle(QPointF pt) const +{ + double dX = pt.x() - m_ptStart.x(); + double dY = pt.y() - m_ptStart.y(); + + if (fabs(dX) < 1 && fabs(dY) < 1) + return 0; + else + return atan2(dY, dX); +} diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 62991aba4..a079c55d0 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -49,9 +49,9 @@ class VTextGraphicsItem : public QGraphicsObject enum Mode { mNormal, - mActivated, mMove, - mResize + mResize, + mRotate }; public: @@ -78,15 +78,22 @@ protected: bool IsBigEnough(qreal fW, qreal fH, int iFontSize); QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); + double GetAngle(QPointF pt) const; + signals: void SignalMoved(QPointF ptPos); void SignalResized(qreal iTW, int iFontSize); + void SignalRotated(qreal dAng); void SignalShrink(); private: Mode m_eMode; + bool m_bReleased; + QPointF m_ptStartPos; QPointF m_ptStart; QSizeF m_szStart; + double m_dRotation; + double m_dAngle; QRectF m_rectResize; int m_iMinH; QRectF m_rectBoundingBox; From 6effc2b5cddd9231e14f179f19f055095a4e27b4 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 1 Jul 2016 01:45:16 +0200 Subject: [PATCH 23/66] Rotation bugs fixed --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 5 +- src/libs/ifc/schema/pattern/v0.3.3.xsd | 2 + src/libs/ifc/xml/vabstractpattern.cpp | 32 +++++++++- src/libs/ifc/xml/vabstractpattern.h | 3 + src/libs/vpatterndb/vpatternpiecedata.cpp | 13 ++++ src/libs/vpatterndb/vpatternpiecedata.h | 5 ++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 30 +++++++-- src/libs/vtools/tools/vtextgraphicsitem.h | 1 + src/libs/vtools/tools/vtooldetail.cpp | 62 ++++++++++++++++--- src/libs/vtools/tools/vtooldetail.h | 5 +- .../vtools/undocommands/savedetailoptions.cpp | 2 + src/libs/vwidgets/vmaingraphicsscene.cpp | 4 ++ src/libs/vwidgets/vmaingraphicsscene.h | 1 + 13 files changed, 147 insertions(+), 18 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 07c23bedc..777a956d4 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -678,11 +678,10 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document detail.GetPatternPieceData().SetLabelWidth(dLW); qreal dLH = element.attribute(VToolDetail::AttrHeight, "0").toDouble(); detail.GetPatternPieceData().SetLabelHeight(dLH); - qDebug() << "HEIGHT" << - detail.GetPatternPieceData().GetPos() << - detail.GetPatternPieceData().GetLabelHeight(); int iFS = element.attribute(VToolDetail::AttrFont, "0").toInt(); detail.GetPatternPieceData().SetFontSize(iFS); + qreal dRot = element.attribute(VToolDetail::AttrRotation, "0").toDouble(); + detail.GetPatternPieceData().SetRotation(dRot); QDomNodeList nodeListMCP = element.childNodes(); for (int iMCP = 0; iMCP < nodeListMCP.count(); ++iMCP) diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd index f7c78c74f..ae4d72f3d 100644 --- a/src/libs/ifc/schema/pattern/v0.3.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -26,6 +26,7 @@ + @@ -360,6 +361,7 @@ + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index ca24447e5..4e92b299d 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -68,8 +68,9 @@ const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); const QString VAbstractPattern::TagLabelPos = QStringLiteral("labelPosition"); -const QString VAbstractPattern::TagLabelSize = QStringLiteral("labelSize"); +const QString VAbstractPattern::TagLabelSize = QStringLiteral("labelSize"); const QString VAbstractPattern::TagLabelFont = QStringLiteral("fontSize"); +const QString VAbstractPattern::TagLabelRot = QStringLiteral("rotation"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); @@ -1157,6 +1158,27 @@ void VAbstractPattern::SetFontSize(int iFS) emit patternChanged(false); } +//--------------------------------------------------------------------------------------------------------------------- +qreal VAbstractPattern::GetRotation() const +{ + bool bOK; + qreal dRot = UniqueTagText(TagLabelRot).toDouble(&bOK); + if (bOK == false) + { + dRot = 0; + } + return dRot; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetRotation(qreal dRot) +{ + CheckTagExists(TagLabelRot); + setTagText(TagLabelRot, QString::number(dRot, 'f', 3)); + modified = true; + emit patternChanged(false); +} + //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPattern::GetImage() const { @@ -1283,7 +1305,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName << TagCreationDate << TagLabelPos << TagLabelSize - << TagLabelFont; + << TagLabelFont << TagLabelRot; switch (tags.indexOf(tag)) { case 0: //TagUnit @@ -1365,6 +1387,12 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) break; } + case 14: + { + element = createElement(TagLabelRot); + break; + } + default: { return QDomElement(); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index f0dc2dcf0..806a0e166 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -123,6 +123,8 @@ public: void SetLabelSize(QSizeF sz); int GetFontSize() const; void SetFontSize(int iFS); + qreal GetRotation() const; + void SetRotation(qreal dRot); QString GetImage() const; QString GetImageExtension() const; @@ -182,6 +184,7 @@ public: static const QString TagLabelPos; static const QString TagLabelSize; static const QString TagLabelFont; + static const QString TagLabelRot; static const QString AttrName; static const QString AttrVisible; diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index 7b939a770..80d68bda5 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -35,6 +35,7 @@ VPatternPieceData::VPatternPieceData() : m_iFontSize = MIN_FONT_SIZE; // 0 means unknown width m_dLabelWidth = 0; + m_dRotation = 0; } //--------------------------------------------------------------------------------------------------------------------- @@ -169,4 +170,16 @@ void VPatternPieceData::SetFontSize(int iSize) } //--------------------------------------------------------------------------------------------------------------------- +qreal VPatternPieceData::GetRotation() const +{ + return m_dRotation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternPieceData::SetRotation(qreal dRot) +{ + m_dRotation = dRot; +} + +//--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h index ab0295d82..11997cc36 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -93,6 +93,8 @@ public: void SetLabelHeight(qreal dLabelH); int GetFontSize() const; void SetFontSize(int iSize); + qreal GetRotation() const; + void SetRotation(qreal dRot); private: /** @brief Pattern piece name @@ -116,6 +118,9 @@ private: /** @brief Label font size */ int m_iFontSize; + /** @brief Label rotation + */ + qreal m_dRotation; }; #endif // VPATTERNPIECEDATA_H diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index dbf38e1df..9e5e3f31c 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -36,6 +36,8 @@ #define RESIZE_SQUARE 30 #define ROTATE_CIRCLE 20 +#define ROTATE_RECT 60 +#define ROTATE_ARC 50 #define MIN_W 120 #define MIN_H 60 #define MIN_FONT_SIZE 12 @@ -71,6 +73,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem { Q_UNUSED(widget); painter->fillRect(option->rect, QColor(251, 251, 175)); + painter->setRenderHints(QPainter::Antialiasing); // draw text lines int iY = 0; @@ -117,6 +120,16 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem ROTATE_CIRCLE, ROTATE_CIRCLE ); + painter->setPen(QPen(Qt::black, 3)); + painter->setBrush(Qt::NoBrush); + int iTop = ROTATE_RECT - ROTATE_ARC; + int iLeft = ROTATE_RECT - ROTATE_ARC; + int iRight = m_rectBoundingBox.width() - ROTATE_RECT; + int iBottom = m_rectBoundingBox.height() - ROTATE_RECT; + painter->drawArc(iLeft, iTop, ROTATE_ARC, ROTATE_ARC, 180*16, -90*16); + painter->drawArc(iRight, iTop, ROTATE_ARC, ROTATE_ARC, 90*16, -90*16); + painter->drawArc(iLeft, iBottom, ROTATE_ARC, ROTATE_ARC, 270*16, -90*16); + painter->drawArc(iRight, iBottom, ROTATE_ARC, ROTATE_ARC, 0*16, -90*16); } } } @@ -124,7 +137,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::Reset() { - return; + qDebug() << "RESET" << m_eMode << m_liLines.count(); m_eMode = mNormal; m_bReleased = false; Update(); @@ -163,6 +176,7 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) m_rectResize.setTopLeft(QPointF(fW - RESIZE_SQUARE, fH - RESIZE_SQUARE)); m_rectResize.setWidth(RESIZE_SQUARE); m_rectResize.setHeight(RESIZE_SQUARE); + setTransformOriginPoint(m_rectBoundingBox.center()); } //--------------------------------------------------------------------------------------------------------------------- @@ -172,6 +186,12 @@ void VTextGraphicsItem::Update() UpdateBox(); } +//--------------------------------------------------------------------------------------------------------------------- +int VTextGraphicsItem::GetFontSize() const +{ + return m_font.pixelSize(); +} + //--------------------------------------------------------------------------------------------------------------------- QRectF VTextGraphicsItem::boundingRect() const { @@ -183,7 +203,6 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { if (pME->button() == Qt::LeftButton) { - qDebug() << "PRESS" << m_eMode; m_ptStartPos = pos(); m_ptStart = pME->scenePos(); m_szStart = m_rectBoundingBox.size(); @@ -202,7 +221,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) } setZValue(3); UpdateBox(); - qDebug() << "PRESS finished" << m_eMode; + qDebug() << "PRESS" << m_eMode << m_liLines.count(); } } @@ -212,7 +231,6 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) QPointF ptDiff = pME->scenePos() - m_ptStart; if (m_eMode == mMove) { - //moveBy(ptDiff.x(), ptDiff.y()); setPos(m_ptStartPos + ptDiff); UpdateBox(); } @@ -231,6 +249,7 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) } double dAng = 180*(GetAngle(pME->scenePos()) - m_dAngle)/M_PI; setRotation(m_dRotation + dAng); + emit SignalRotated(rotation()); Update(); } } @@ -243,7 +262,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y()); bool bShort = (dDist < 2); - qDebug() << "RELEASE" << m_eMode << dDist; + qDebug() << "RELEASE" << m_eMode << dDist << m_liLines.count(); if (m_eMode == mMove || m_eMode == mResize) { // when released in mMove or mResize mode @@ -280,6 +299,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } } m_bReleased = true; + qDebug() << "RELEASE finished" << m_eMode << m_liLines.count(); } } diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index a079c55d0..54d3725cb 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -63,6 +63,7 @@ public: void Reset(); + int GetFontSize() const; QRectF boundingRect() const; void AddLine(const TextLine& tl); void Clear(); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index d575367c5..a4150a033 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -57,6 +57,7 @@ const QString VToolDetail::AttrHeight = QStringLiteral("height"); const QString VToolDetail::AttrNodeType = QStringLiteral("nodeType"); const QString VToolDetail::AttrReverse = QStringLiteral("reverse"); const QString VToolDetail::AttrFont = QStringLiteral("fontSize"); +const QString VToolDetail::AttrRotation = QStringLiteral("rotation"); const QString VToolDetail::NodeTypeContour = QStringLiteral("Contour"); const QString VToolDetail::NodeTypeModeling = QStringLiteral("Modeling"); @@ -118,7 +119,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove); - connect(scene, &VMainGraphicsScene::MouseLeftPressed, this, &VToolDetail::ResetChildren); + connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolDetail::ResetChildren); if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) { AddToFile(); @@ -131,10 +132,12 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail); connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail); + connect(dataLabel, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationDetail); connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); connect(patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMovePattern); connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern); + connect(patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationPattern); connect(patternInfo, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); @@ -356,6 +359,7 @@ void VToolDetail::AddToFile() doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight()); doc->SetAttribute(domData, AttrFont, data.GetFontSize()); + doc->SetAttribute(domData, AttrRotation, data.GetRotation()); for (int i = 0; i < data.GetMCPCount(); ++i) { @@ -404,6 +408,7 @@ void VToolDetail::RefreshDataInFile() doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); doc->SetAttribute(domData, AttrHeight, data.GetLabelHeight()); doc->SetAttribute(domData, AttrFont, data.GetFontSize()); + doc->SetAttribute(domData, AttrRotation, data.GetRotation()); for (int i = 0; i < data.GetMCPCount(); ++i) { @@ -650,11 +655,10 @@ void VToolDetail::UpdateLabel() { const VDetail detail = VAbstractTool::data.GetDetail(id); - qDebug() << "Update label"; const VPatternPieceData& data = detail.GetPatternPieceData(); if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0) { - dataLabel->Reset(); + //dataLabel->Reset(); QString qsText = "Cut %1 of %2%3"; QStringList qslPlace; @@ -688,6 +692,7 @@ void VToolDetail::UpdateLabel() } dataLabel->setPos(data.GetPos()); + dataLabel->setRotation(data.GetRotation()); dataLabel->Update(); dataLabel->show(); } @@ -703,7 +708,7 @@ void VToolDetail::UpdateLabel() */ void VToolDetail::UpdatePatternInfo() { - patternInfo->Reset(); + //patternInfo->Reset(); QFont fnt = qApp->font(); int iFS = doc->GetFontSize(); if (iFS < MIN_FONT_SIZE) @@ -748,6 +753,7 @@ void VToolDetail::UpdatePatternInfo() patternInfo->AddLine(tl); patternInfo->setPos(doc->GetLabelPosition()); + patternInfo->setRotation(doc->GetRotation()); patternInfo->Update(); } @@ -761,6 +767,11 @@ void VToolDetail::SaveMoveDetail(QPointF ptPos) VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail newDet = oldDet; newDet.GetPatternPieceData().SetPos(ptPos); + newDet.GetPatternPieceData().SetLabelWidth(dataLabel->boundingRect().width()); + newDet.GetPatternPieceData().SetLabelHeight(dataLabel->boundingRect().height()); + newDet.GetPatternPieceData().SetFontSize(dataLabel->GetFontSize()); + newDet.GetPatternPieceData().SetRotation(dataLabel->rotation()); + SaveDetailOptions* moveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); moveCommand->setText(tr("move pattern piece label")); connect(moveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); @@ -778,12 +789,35 @@ void VToolDetail::SaveResizeDetail(qreal dLabelW, int iFontSize) newDet.GetPatternPieceData().SetLabelWidth(dLabelW); newDet.GetPatternPieceData().SetLabelHeight(dataLabel->boundingRect().height()); newDet.GetPatternPieceData().SetFontSize(iFontSize); + newDet.GetPatternPieceData().SetRotation(dataLabel->rotation()); SaveDetailOptions* resizeCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); resizeCommand->setText(tr("resize pattern piece label")); connect(resizeCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); qApp->getUndoStack()->push(resizeCommand); } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief SaveRotationDetail saves the rotation detail label operation to the undo stack + */ +void VToolDetail::SaveRotationDetail(qreal dRot) +{ + qDebug() << "SAVEROTATION" << dRot; + VDetail oldDet = VAbstractTool::data.GetDetail(id); + VDetail newDet = oldDet; + newDet.GetPatternPieceData().SetPos(dataLabel->pos()); + newDet.GetPatternPieceData().SetLabelWidth(dataLabel->boundingRect().width()); + newDet.GetPatternPieceData().SetLabelHeight(dataLabel->boundingRect().height()); + newDet.GetPatternPieceData().SetFontSize(dataLabel->GetFontSize()); + newDet.GetPatternPieceData().SetRotation(dRot); + + SaveDetailOptions* rotateCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); + rotateCommand->setText(tr("rotate pattern piece label")); + connect(rotateCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(rotateCommand); +} + + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveMovePattern saves the pattern label position @@ -804,6 +838,13 @@ void VToolDetail::SaveResizePattern(qreal dLabelW, int iFontSize) doc->SetFontSize(iFontSize); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::SaveRotationPattern(qreal dRot) +{ + doc->SetRotation(dRot); +} + + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddNode add node to the file. @@ -953,10 +994,17 @@ void VToolDetail::AllowSelecting(bool enabled) } //--------------------------------------------------------------------------------------------------------------------- -void VToolDetail::ResetChildren() +void VToolDetail::ResetChildren(QGraphicsItem *pItem) { - dataLabel->Reset(); - patternInfo->Reset(); + VTextGraphicsItem* pVGI = dynamic_cast(pItem); + if (pVGI != dataLabel) + { + dataLabel->Reset(); + } + if (pVGI != patternInfo) + { + patternInfo->Reset(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index edc0e193e..969805f7f 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -73,6 +73,7 @@ public: static const QString AttrNodeType; static const QString AttrReverse; static const QString AttrFont; + static const QString AttrRotation; static const QString NodeTypeContour; static const QString NodeTypeModeling; static const QString NodeArc; @@ -92,7 +93,7 @@ public slots: void EnableToolMove(bool move); virtual void AllowHover(bool enabled) Q_DECL_OVERRIDE; virtual void AllowSelecting(bool enabled) Q_DECL_OVERRIDE; - virtual void ResetChildren(); + virtual void ResetChildren(QGraphicsItem* pItem); virtual void UpdateAll(); protected: virtual void AddToFile () Q_DECL_OVERRIDE; @@ -112,8 +113,10 @@ protected slots: virtual void UpdatePatternInfo(); virtual void SaveMoveDetail(QPointF ptPos); virtual void SaveResizeDetail(qreal dLabelW, int iFontSize); + virtual void SaveRotationDetail(qreal dRot); virtual void SaveMovePattern(QPointF ptPos); virtual void SaveResizePattern(qreal dLabelW, int iFontSize); + virtual void SaveRotationPattern(qreal dRot); private: Q_DISABLE_COPY(VToolDetail) diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index bc30cdca8..1f1e83612 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -142,6 +142,8 @@ void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDet doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth()); doc->SetAttribute(domData, VToolDetail::AttrHeight, data.GetLabelHeight()); doc->SetAttribute(domData, VToolDetail::AttrFont, data.GetFontSize()); + doc->SetAttribute(domData, VToolDetail::AttrRotation, data.GetRotation()); + for (int i = 0; i < data.GetMCPCount(); ++i) { MaterialCutPlacement mcp = data.GetMCP(i); diff --git a/src/libs/vwidgets/vmaingraphicsscene.cpp b/src/libs/vwidgets/vmaingraphicsscene.cpp index 35fe577c8..791903482 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.cpp +++ b/src/libs/vwidgets/vmaingraphicsscene.cpp @@ -80,6 +80,10 @@ void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event) } QGraphicsScene::mousePressEvent(event); + + QTransform t; + QGraphicsItem* pItem = itemAt(event->scenePos(), t); + emit ItemClicked(pItem); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vwidgets/vmaingraphicsscene.h b/src/libs/vwidgets/vmaingraphicsscene.h index e65896965..6f86c46a3 100644 --- a/src/libs/vwidgets/vmaingraphicsscene.h +++ b/src/libs/vwidgets/vmaingraphicsscene.h @@ -93,6 +93,7 @@ signals: void MouseLeftPressed(); void MouseLeftReleased(); + void ItemClicked(QGraphicsItem* pItem); /** * @brief ChoosedObject send option choosed object. From f52f97740d07be33b17fd60688006870552535c6 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 2 Jul 2016 01:49:38 +0200 Subject: [PATCH 24/66] Moved pattern info geometry into VDetail class --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 27 ++-- src/libs/ifc/schema/pattern/v0.3.3.xsd | 16 ++- src/libs/ifc/xml/vabstractpattern.cpp | 129 +----------------- src/libs/ifc/xml/vabstractpattern.h | 13 +- src/libs/vpatterndb/vdetail.cpp | 22 ++- src/libs/vpatterndb/vdetail.h | 3 + src/libs/vpatterndb/vdetail_p.h | 5 +- src/libs/vpatterndb/vpatterndb.pro | 6 + src/libs/vpatterndb/vpatterninfogeometry.cpp | 108 +++++++++++++++ src/libs/vpatterndb/vpatterninfogeometry.h | 70 ++++++++++ src/libs/vpatterndb/vpatternpiecedata.cpp | 3 +- src/libs/vtools/tools/vtextgraphicsitem.cpp | 2 +- src/libs/vtools/tools/vtooldetail.cpp | 75 ++++++++-- .../vtools/undocommands/savedetailoptions.cpp | 18 +++ .../vtools/undocommands/savedetailoptions.h | 1 + 15 files changed, 329 insertions(+), 169 deletions(-) create mode 100644 src/libs/vpatterndb/vpatterninfogeometry.cpp create mode 100644 src/libs/vpatterndb/vpatterninfogeometry.h diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 777a956d4..acaccce79 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -48,6 +48,7 @@ #include "../core/vapplication.h" #include "../vpatterndb/calculator.h" #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vpatterninfogeometry.h" #include #include @@ -138,7 +139,7 @@ void VPattern::Parse(const Document &parse) QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName - << TagCreationDate << TagLabelPos << TagLabelSize << TagLabelFont; + << TagCreationDate; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -213,15 +214,6 @@ void VPattern::Parse(const Document &parse) case 14: // TagCreationDate qCDebug(vXML, "Creation date."); break; - case 15: // TagLabelPos - qCDebug(vXML, "Label position."); - break; - case 16: // TagLabelSize - qCDebug(vXML, "Label size."); - break; - case 17: // TagLabelFont - qCDebug(vXML, "Label font size."); - break; default: qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); break; @@ -695,6 +687,21 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document detail.GetPatternPieceData().Append(mcp); } } + else if (element.tagName() == TagPatternInfo) + { + QPointF ptPos; + ptPos.setX(element.attribute(AttrMx, "0").toDouble()); + ptPos.setY(element.attribute(AttrMy, "0").toDouble()); + detail.GetPatternInfo().SetPos(ptPos); + qreal dLW = element.attribute(VToolDetail::AttrWidth, "0").toDouble(); + detail.GetPatternInfo().SetLabelWidth(dLW); + qreal dLH = element.attribute(VToolDetail::AttrHeight, "0").toDouble(); + detail.GetPatternInfo().SetLabelHeight(dLH); + int iFS = element.attribute(VToolDetail::AttrFont, "0").toInt(); + detail.GetPatternInfo().SetFontSize(iFS); + qreal dRot = element.attribute(VToolDetail::AttrRotation, "0").toDouble(); + detail.GetPatternInfo().SetRotation(dRot); + } } } VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile); diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd index ae4d72f3d..3bdf8d2f3 100644 --- a/src/libs/ifc/schema/pattern/v0.3.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -23,10 +23,6 @@ - - - - @@ -364,7 +360,17 @@ - + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 4e92b299d..2d716491d 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -61,16 +61,13 @@ const QString VAbstractPattern::TagHeights = QStringLiteral("heights"); const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); const QString VAbstractPattern::TagUnit = QStringLiteral("unit"); const QString VAbstractPattern::TagData = QStringLiteral("data"); +const QString VAbstractPattern::TagPatternInfo = QStringLiteral("patternInfo"); const QString VAbstractPattern::TagMCP = QStringLiteral("mcp"); const QString VAbstractPattern::TagPatternName = QStringLiteral("patternName"); const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber"); const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); -const QString VAbstractPattern::TagLabelPos = QStringLiteral("labelPosition"); -const QString VAbstractPattern::TagLabelSize = QStringLiteral("labelSize"); -const QString VAbstractPattern::TagLabelFont = QStringLiteral("fontSize"); -const QString VAbstractPattern::TagLabelRot = QStringLiteral("rotation"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); @@ -1079,106 +1076,6 @@ QDate VAbstractPattern::GetCreationDate() const return QDate::currentDate(); } -//--------------------------------------------------------------------------------------------------------------------- -QPointF VAbstractPattern::GetLabelPosition() const -{ - QStringList qsl = UniqueTagText(TagLabelPos).split(","); - QPointF ptPos(0, 0); - if (qsl.count() == 2) - { - bool bOKX; - bool bOKY; - double fX = qsl[0].toDouble(&bOKX); - double fY = qsl[1].toDouble(&bOKY); - if (bOKX == true && bOKY == true) - { - ptPos.setX(fX); - ptPos.setY(fY); - } - } - return ptPos; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetLabelPosition(const QPointF& ptPos) -{ - CheckTagExists(TagLabelPos); - setTagText(TagLabelPos, QString::number(ptPos.x(), 'f', 3) + "," + QString::number(ptPos.y(), 'f', 3)); - modified = true; - emit patternChanged(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -QSizeF VAbstractPattern::GetLabelSize() const -{ - QStringList qsl = UniqueTagText(TagLabelSize).split(","); - QSizeF sz(0, 0); - if (qsl.count() == 2) - { - bool bOKW; - bool bOKH; - double fW = qsl[0].toDouble(&bOKW); - double fH = qsl[1].toDouble(&bOKH); - if (bOKW == true && bOKH == true) - { - sz.setWidth(fW); - sz.setHeight(fH); - } - } - return sz; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetLabelSize(QSizeF sz) -{ - CheckTagExists(TagLabelSize); - setTagText(TagLabelSize, QString::number(sz.width(), 'f', 3) + "," + QString::number(sz.height(), 'f', 3)); - modified = true; - emit patternChanged(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -int VAbstractPattern::GetFontSize() const -{ - bool bOK; - int iFS = UniqueTagText(TagLabelFont).toInt(&bOK); - if (bOK == false) - { - iFS = 0; - } - return iFS; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetFontSize(int iFS) -{ - CheckTagExists(TagLabelFont); - setTagText(TagLabelFont, QString::number(iFS)); - modified = true; - emit patternChanged(false); -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal VAbstractPattern::GetRotation() const -{ - bool bOK; - qreal dRot = UniqueTagText(TagLabelRot).toDouble(&bOK); - if (bOK == false) - { - dRot = 0; - } - return dRot; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetRotation(qreal dRot) -{ - CheckTagExists(TagLabelRot); - setTagText(TagLabelRot, QString::number(dRot, 'f', 3)); - modified = true; - emit patternChanged(false); -} - //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPattern::GetImage() const { @@ -1304,8 +1201,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagCreationDate << TagLabelPos << TagLabelSize - << TagLabelFont << TagLabelRot; + << TagCustomerName << TagCreationDate; switch (tags.indexOf(tag)) { case 0: //TagUnit @@ -1371,27 +1267,6 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) element = createElement(TagCreationDate); break; } - case 11: - { - element = createElement(TagLabelPos); - break; - } - case 12: - { - element = createElement(TagLabelSize); - break; - } - case 13: - { - element = createElement(TagLabelFont); - break; - } - - case 14: - { - element = createElement(TagLabelRot); - break; - } default: { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 806a0e166..0501d5ff6 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -117,14 +117,6 @@ public: QString GetCustomerName() const; void SetCustomerName(QString qsName); QDate GetCreationDate() const; - QPointF GetLabelPosition() const; - void SetLabelPosition(const QPointF& ptPos); - QSizeF GetLabelSize() const; - void SetLabelSize(QSizeF sz); - int GetFontSize() const; - void SetFontSize(int iFS); - qreal GetRotation() const; - void SetRotation(qreal dRot); QString GetImage() const; QString GetImageExtension() const; @@ -175,16 +167,13 @@ public: static const QString TagSizes; static const QString TagUnit; static const QString TagData; + static const QString TagPatternInfo; static const QString TagMCP; static const QString TagPatternName; static const QString TagPatternNum; static const QString TagCompanyName; static const QString TagCustomerName; static const QString TagCreationDate; - static const QString TagLabelPos; - static const QString TagLabelSize; - static const QString TagLabelFont; - static const QString TagLabelRot; static const QString AttrName; static const QString AttrVisible; diff --git a/src/libs/vpatterndb/vdetail.cpp b/src/libs/vpatterndb/vdetail.cpp index ec1da4de2..8f0d25092 100644 --- a/src/libs/vpatterndb/vdetail.cpp +++ b/src/libs/vpatterndb/vdetail.cpp @@ -527,7 +527,7 @@ QVector VDetail::listNodePoint() const //--------------------------------------------------------------------------------------------------------------------- /** - * @brief Returns the full access to the pattern piece data object + * @brief Returns full access to the pattern piece data object * @return pattern piece data object */ VPatternPieceData& VDetail::GetPatternPieceData() @@ -545,6 +545,26 @@ const VPatternPieceData& VDetail::GetPatternPieceData() const return d->m_ppData; } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Returns full access to the pattern info geometry object + * @return pattern info geometry object + */ +VPatternInfoGeometry& VDetail::GetPatternInfo() +{ + return d->m_piPatternInfo; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief Returns the read only reference to the pattern info geometry object + * @return pattern info geometry object + */ +const VPatternInfoGeometry& VDetail::GetPatternInfo() const +{ + return d->m_piPatternInfo; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief indexOfNode return index in list node using id object. diff --git a/src/libs/vpatterndb/vdetail.h b/src/libs/vpatterndb/vdetail.h index c6e7817df..976b885d7 100644 --- a/src/libs/vpatterndb/vdetail.h +++ b/src/libs/vpatterndb/vdetail.h @@ -38,6 +38,7 @@ class VDetailData; class VContainer; class QPainterPath; class VPatternPieceData; +class VPatternInfoGeometry; /** * @brief The VDetail class for path of object (points, arcs, splines). @@ -90,6 +91,8 @@ public: QVector listNodePoint()const; VPatternPieceData& GetPatternPieceData(); const VPatternPieceData& GetPatternPieceData() const; + VPatternInfoGeometry& GetPatternInfo(); + const VPatternInfoGeometry& GetPatternInfo() const; private: QSharedDataPointer d; diff --git a/src/libs/vpatterndb/vdetail_p.h b/src/libs/vpatterndb/vdetail_p.h index d7b9fa259..4092cec9a 100644 --- a/src/libs/vpatterndb/vdetail_p.h +++ b/src/libs/vpatterndb/vdetail_p.h @@ -32,6 +32,7 @@ #include #include "vnodedetail.h" #include "vpatternpiecedata.h" +#include "vpatterninfogeometry.h" #include "../ifc/ifcdef.h" #ifdef Q_CC_GNU @@ -52,7 +53,7 @@ public: VDetailData(const VDetailData &detail) :QSharedData(detail), _id(NULL_ID), nodes(detail.nodes), mx(detail.mx), my(detail.my), - m_ppData(detail.m_ppData), inLayout(detail.inLayout) + m_ppData(detail.m_ppData), m_piPatternInfo(detail.m_piPatternInfo), inLayout(detail.inLayout) {} ~VDetailData() {} @@ -71,6 +72,8 @@ public: /** @brief Pattern piece data */ VPatternPieceData m_ppData; + /** @brief Pattern info coordinates */ + VPatternInfoGeometry m_piPatternInfo; bool inLayout; diff --git a/src/libs/vpatterndb/vpatterndb.pro b/src/libs/vpatterndb/vpatterndb.pro index e796f437e..bb5d3d0bc 100644 --- a/src/libs/vpatterndb/vpatterndb.pro +++ b/src/libs/vpatterndb/vpatterndb.pro @@ -101,3 +101,9 @@ CONFIG(debug, debug|release){ } } +HEADERS += \ + vpatterninfogeometry.h + +SOURCES += \ + vpatterninfogeometry.cpp + diff --git a/src/libs/vpatterndb/vpatterninfogeometry.cpp b/src/libs/vpatterndb/vpatterninfogeometry.cpp new file mode 100644 index 000000000..cb0728454 --- /dev/null +++ b/src/libs/vpatterndb/vpatterninfogeometry.cpp @@ -0,0 +1,108 @@ +/************************************************************************ + ** + ** @file vpatterninfogeometry.cpp + ** @author Bojan Kverh + ** @date June 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 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 "vpatterninfogeometry.h" + +//--------------------------------------------------------------------------------------------------------------------- +VPatternInfoGeometry::VPatternInfoGeometry() : + m_ptPos(0, 0) +{ + m_iFontSize = MIN_FONT_SIZE; + // 0 means unknown width + m_dLabelWidth = 0; + m_dLabelHeight = 0; + m_dRotation = 0; +} + +//--------------------------------------------------------------------------------------------------------------------- +VPatternInfoGeometry::~VPatternInfoGeometry() +{} + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VPatternInfoGeometry::GetPos() const +{ + return m_ptPos; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternInfoGeometry::SetPos(const QPointF& ptPos) +{ + m_ptPos = ptPos; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPatternInfoGeometry::GetLabelWidth() const +{ + return m_dLabelWidth; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternInfoGeometry::SetLabelWidth(qreal dLabelW) +{ + m_dLabelWidth = dLabelW; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPatternInfoGeometry::GetLabelHeight() const +{ + return m_dLabelHeight; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternInfoGeometry::SetLabelHeight(qreal dLabelH) +{ + m_dLabelHeight = dLabelH; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VPatternInfoGeometry::GetFontSize() const +{ + return m_iFontSize; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternInfoGeometry::SetFontSize(int iSize) +{ + if (iSize >= MIN_FONT_SIZE) + m_iFontSize = iSize; + else + m_iFontSize = MIN_FONT_SIZE; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VPatternInfoGeometry::GetRotation() const +{ + return m_dRotation; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternInfoGeometry::SetRotation(qreal dRot) +{ + m_dRotation = dRot; +} + diff --git a/src/libs/vpatterndb/vpatterninfogeometry.h b/src/libs/vpatterndb/vpatterninfogeometry.h new file mode 100644 index 000000000..36c8217c7 --- /dev/null +++ b/src/libs/vpatterndb/vpatterninfogeometry.h @@ -0,0 +1,70 @@ +/************************************************************************ + ** + ** @file vpatterninfogeometry.h + ** @author Bojan Kverh + ** @date June 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 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 VPATTERNINFOGEOMETRY_H +#define VPATTERNINFOGEOMETRY_H + +#define MIN_FONT_SIZE 12 + +#include + +class VPatternInfoGeometry +{ +public: + VPatternInfoGeometry(); + ~VPatternInfoGeometry(); + + // methods, which set up label parameters + QPointF GetPos() const; + void SetPos(const QPointF& ptPos); + qreal GetLabelWidth() const; + void SetLabelWidth(qreal dLabelW); + qreal GetLabelHeight() const; + void SetLabelHeight(qreal dLabelH); + int GetFontSize() const; + void SetFontSize(int iSize); + qreal GetRotation() const; + void SetRotation(qreal dRot); + +private: + QPointF m_ptPos; + /** @brief Label width + */ + qreal m_dLabelWidth; + /** @brief Label height + */ + qreal m_dLabelHeight; + /** @brief Label font size + */ + int m_iFontSize; + /** @brief Label rotation + */ + qreal m_dRotation; +}; + +#endif // VPATTERNINFOGEOMETRY_H diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index 80d68bda5..afb44d731 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vpatternpiecedata.h + ** @file vpatternpiecedata.cpp ** @author Bojan Kverh ** @date June 16, 2016 ** @@ -35,6 +35,7 @@ VPatternPieceData::VPatternPieceData() : m_iFontSize = MIN_FONT_SIZE; // 0 means unknown width m_dLabelWidth = 0; + m_dLabelHeight = 0; m_dRotation = 0; } diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 9e5e3f31c..48c038cd5 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -249,7 +249,7 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) } double dAng = 180*(GetAngle(pME->scenePos()) - m_dAngle)/M_PI; setRotation(m_dRotation + dAng); - emit SignalRotated(rotation()); + //emit SignalRotated(rotation()); Update(); } } diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index a4150a033..8686e633b 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -41,6 +41,7 @@ #include "../undocommands/adddet.h" #include "../undocommands/deletedetail.h" #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vpatterninfogeometry.h" #include #include @@ -118,6 +119,8 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus + qDebug() << "VToolDetail" << patternInfo; + connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove); connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolDetail::ResetChildren); if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) @@ -142,6 +145,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); + connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdatePatternInfo); UpdateLabel(); UpdatePatternInfo(); } @@ -373,6 +377,15 @@ void VToolDetail::AddToFile() } domElement.appendChild(domData); + domData = doc->createElement(VAbstractPattern::TagPatternInfo); + const VPatternInfoGeometry& geom = detail.GetPatternInfo(); + doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); + doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); + doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth()); + doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight()); + doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); + doc->SetAttribute(domData, AttrRotation, geom.GetRotation()); + for (int i = 0; i < detail.CountNode(); ++i) { AddNode(doc, domElement, detail.at(i)); @@ -422,6 +435,15 @@ void VToolDetail::RefreshDataInFile() } domElement.appendChild(domData); + domData = doc->createElement(VAbstractPattern::TagPatternInfo); + const VPatternInfoGeometry& geom = det.GetPatternInfo(); + doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); + doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); + doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth()); + doc->SetAttribute(domData, AttrHeight, geom.GetLabelHeight()); + doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); + doc->SetAttribute(domData, AttrRotation, geom.GetRotation()); + for (int i = 0; i < det.CountNode(); ++i) { AddNode(doc, domElement, det.at(i)); @@ -708,17 +730,19 @@ void VToolDetail::UpdateLabel() */ void VToolDetail::UpdatePatternInfo() { + const VDetail detail = VAbstractTool::data.GetDetail(id); + const VPatternInfoGeometry& geom = detail.GetPatternInfo(); + //patternInfo->Reset(); QFont fnt = qApp->font(); - int iFS = doc->GetFontSize(); + int iFS = geom.GetFontSize(); if (iFS < MIN_FONT_SIZE) { iFS = MIN_FONT_SIZE; } fnt.setPixelSize(iFS); patternInfo->SetFont(fnt); - QSizeF sz = doc->GetLabelSize(); - patternInfo->SetSize(sz.width(), sz.height()); + patternInfo->SetSize(geom.GetLabelWidth(), geom.GetLabelHeight()); patternInfo->Clear(); TextLine tl; @@ -752,8 +776,8 @@ void VToolDetail::UpdatePatternInfo() tl.m_qsText = qslDate.last(); patternInfo->AddLine(tl); - patternInfo->setPos(doc->GetLabelPosition()); - patternInfo->setRotation(doc->GetRotation()); + patternInfo->setPos(geom.GetPos()); + patternInfo->setRotation(geom.GetRotation()); patternInfo->Update(); } @@ -802,7 +826,6 @@ void VToolDetail::SaveResizeDetail(qreal dLabelW, int iFontSize) */ void VToolDetail::SaveRotationDetail(qreal dRot) { - qDebug() << "SAVEROTATION" << dRot; VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail newDet = oldDet; newDet.GetPatternPieceData().SetPos(dataLabel->pos()); @@ -824,8 +847,19 @@ void VToolDetail::SaveRotationDetail(qreal dRot) */ void VToolDetail::SaveMovePattern(QPointF ptPos) { - qDebug() << "Pattern moved to" << ptPos; - doc->SetLabelPosition(ptPos); + VDetail oldDet = VAbstractTool::data.GetDetail(id); + VDetail newDet = oldDet; + newDet.GetPatternInfo().SetPos(ptPos); + newDet.GetPatternInfo().SetLabelWidth(patternInfo->boundingRect().width()); + newDet.GetPatternInfo().SetLabelHeight(patternInfo->boundingRect().height()); + newDet.GetPatternInfo().SetFontSize(patternInfo->GetFontSize()); + newDet.GetPatternInfo().SetRotation(patternInfo->rotation()); + + SaveDetailOptions* moveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); + moveCommand->setText(tr("move pattern info label")); + connect(moveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(moveCommand); + } //--------------------------------------------------------------------------------------------------------------------- @@ -834,14 +868,33 @@ void VToolDetail::SaveMovePattern(QPointF ptPos) */ void VToolDetail::SaveResizePattern(qreal dLabelW, int iFontSize) { - doc->SetLabelSize(QSizeF(dLabelW, patternInfo->boundingRect().height())); - doc->SetFontSize(iFontSize); + VDetail oldDet = VAbstractTool::data.GetDetail(id); + VDetail newDet = oldDet; + newDet.GetPatternInfo().SetLabelWidth(dLabelW); + newDet.GetPatternInfo().SetLabelHeight(patternInfo->boundingRect().height()); + newDet.GetPatternInfo().SetFontSize(iFontSize); + newDet.GetPatternInfo().SetRotation(patternInfo->rotation()); + SaveDetailOptions* resizeCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); + resizeCommand->setText(tr("resize pattern info label")); + connect(resizeCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(resizeCommand); } //--------------------------------------------------------------------------------------------------------------------- void VToolDetail::SaveRotationPattern(qreal dRot) { - doc->SetRotation(dRot); + VDetail oldDet = VAbstractTool::data.GetDetail(id); + VDetail newDet = oldDet; + newDet.GetPatternInfo().SetPos(patternInfo->pos()); + newDet.GetPatternInfo().SetLabelWidth(patternInfo->boundingRect().width()); + newDet.GetPatternInfo().SetLabelHeight(patternInfo->boundingRect().height()); + newDet.GetPatternInfo().SetFontSize(patternInfo->GetFontSize()); + newDet.GetPatternInfo().SetRotation(dRot); + + SaveDetailOptions* rotateCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); + rotateCommand->setText(tr("rotate pattern info label")); + connect(rotateCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(rotateCommand); } diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 1f1e83612..f6776638a 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -31,6 +31,7 @@ #include "../../vwidgets/vmaingraphicsview.h" #include "../ifc/xml/vabstractpattern.h" #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vpatterninfogeometry.h" #include @@ -58,6 +59,7 @@ void SaveDetailOptions::undo() SaveDet(domElement, oldDet); doc->RemoveAllChildren(domElement); SavePatternPieceData(domElement, oldDet); + SavePatternInfo(domElement, oldDet); for (int i = 0; i < oldDet.CountNode(); ++i) { VToolDetail::AddNode(doc, domElement, oldDet.at(i)); @@ -83,6 +85,7 @@ void SaveDetailOptions::redo() SaveDet(domElement, newDet); doc->RemoveAllChildren(domElement); SavePatternPieceData(domElement, newDet); + SavePatternInfo(domElement, newDet); for (int i = 0; i < newDet.CountNode(); ++i) { @@ -156,3 +159,18 @@ void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDet } domElement.appendChild(domData); } + +//--------------------------------------------------------------------------------------------------------------------- +void SaveDetailOptions::SavePatternInfo(QDomElement &domElement, const VDetail &det) +{ + QDomElement domData = doc->createElement(VAbstractPattern::TagPatternInfo); + const VPatternInfoGeometry& data = det.GetPatternInfo(); + doc->SetAttribute(domData, AttrMx, data.GetPos().x()); + doc->SetAttribute(domData, AttrMy, data.GetPos().y()); + doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth()); + doc->SetAttribute(domData, VToolDetail::AttrHeight, data.GetLabelHeight()); + doc->SetAttribute(domData, VToolDetail::AttrFont, data.GetFontSize()); + doc->SetAttribute(domData, VToolDetail::AttrRotation, data.GetRotation()); + + domElement.appendChild(domData); +} diff --git a/src/libs/vtools/undocommands/savedetailoptions.h b/src/libs/vtools/undocommands/savedetailoptions.h index 99d796ecb..58e1ba789 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.h +++ b/src/libs/vtools/undocommands/savedetailoptions.h @@ -54,6 +54,7 @@ private: QGraphicsScene *scene; void SaveDet(QDomElement &domElement, const VDetail &det); void SavePatternPieceData(QDomElement &domElement, const VDetail &det); + void SavePatternInfo(QDomElement &domElement, const VDetail &det); }; //--------------------------------------------------------------------------------------------------------------------- From 74a49662f66c00f974c2def1c6774295edfac160 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 2 Jul 2016 11:15:41 +0200 Subject: [PATCH 25/66] Fixed rotation --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 18 ++++++++---------- src/libs/vtools/tools/vtextgraphicsitem.h | 1 + src/libs/vtools/tools/vtooldetail.cpp | 7 +++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 48c038cd5..68c76a973 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,7 @@ #define MIN_FONT_SIZE 12 #define MAX_FONT_SIZE 48 #define SPACING 2 +#define TOP_Z 2 //--------------------------------------------------------------------------------------------------------------------- VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) @@ -55,7 +57,7 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_iMinH = MIN_H; SetSize(MIN_W, m_iMinH); - setZValue(2); + setZValue(TOP_Z); } //--------------------------------------------------------------------------------------------------------------------- @@ -137,11 +139,10 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::Reset() { - qDebug() << "RESET" << m_eMode << m_liLines.count(); m_eMode = mNormal; m_bReleased = false; Update(); - setZValue(2); + setZValue(TOP_Z); } //--------------------------------------------------------------------------------------------------------------------- @@ -206,6 +207,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) m_ptStartPos = pos(); m_ptStart = pME->scenePos(); m_szStart = m_rectBoundingBox.size(); + m_ptRotCenter = mapToScene(m_rectBoundingBox.center()); m_dAngle = GetAngle(pME->scenePos()); m_dRotation = rotation(); if (m_eMode != mRotate) @@ -219,9 +221,8 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) m_eMode = mMove; } } - setZValue(3); + setZValue(TOP_Z + 1); UpdateBox(); - qDebug() << "PRESS" << m_eMode << m_liLines.count(); } } @@ -262,8 +263,6 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y()); bool bShort = (dDist < 2); - qDebug() << "RELEASE" << m_eMode << dDist << m_liLines.count(); - if (m_eMode == mMove || m_eMode == mResize) { // when released in mMove or mResize mode if (bShort == true) @@ -299,7 +298,6 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } } m_bReleased = true; - qDebug() << "RELEASE finished" << m_eMode << m_liLines.count(); } } @@ -382,8 +380,8 @@ QStringList VTextGraphicsItem::SplitString(const QString &qs, qreal fW, const QF //--------------------------------------------------------------------------------------------------------------------- double VTextGraphicsItem::GetAngle(QPointF pt) const { - double dX = pt.x() - m_ptStart.x(); - double dY = pt.y() - m_ptStart.y(); + double dX = pt.x() - m_ptRotCenter.x(); + double dY = pt.y() - m_ptRotCenter.y(); if (fabs(dX) < 1 && fabs(dY) < 1) return 0; diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 54d3725cb..7f01e987c 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -92,6 +92,7 @@ private: bool m_bReleased; QPointF m_ptStartPos; QPointF m_ptStart; + QPointF m_ptRotCenter; QSizeF m_szStart; double m_dRotation; double m_dAngle; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 8686e633b..2c6a4cf3d 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -81,8 +81,7 @@ const QString VToolDetail::NodeSplinePath = QStringLiteral("NodeSplinePath"); VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent) :VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene), - drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)), - dataLabel(new VTextGraphicsItem(this)), patternInfo(new VTextGraphicsItem(this)) + drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)) { VDetail detail = data->GetDetail(id); for (int i = 0; i< detail.CountNode(); ++i) @@ -119,8 +118,6 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); this->setFlag(QGraphicsItem::ItemIsFocusable, true);// For keyboard input focus - qDebug() << "VToolDetail" << patternInfo; - connect(scene, &VMainGraphicsScene::EnableToolMove, this, &VToolDetail::EnableToolMove); connect(scene, &VMainGraphicsScene::ItemClicked, this, &VToolDetail::ResetChildren); if (typeCreation == Source::FromGui || typeCreation == Source::FromTool) @@ -133,11 +130,13 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 } setAcceptHoverEvents(true); + dataLabel = new VTextGraphicsItem(this); connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail); connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail); connect(dataLabel, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationDetail); connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); + patternInfo = new VTextGraphicsItem(this); connect(patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMovePattern); connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern); connect(patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationPattern); From 5e3daf416c3817e9b4da85494c947360a1e250ce Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 3 Jul 2016 10:17:59 +0200 Subject: [PATCH 26/66] Fixed initial positioning of the labels --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 6 ++--- src/libs/vtools/tools/vtooldetail.cpp | 30 +++++++++++++++++---- src/libs/vtools/tools/vtooldetail.h | 12 ++++----- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 68c76a973..025ba13af 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -42,7 +42,7 @@ #define MIN_W 120 #define MIN_H 60 #define MIN_FONT_SIZE 12 -#define MAX_FONT_SIZE 48 +#define MAX_FONT_SIZE 128 #define SPACING 2 #define TOP_Z 2 @@ -50,8 +50,6 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) : QGraphicsObject(pParent) { - setFlag(QGraphicsItem::ItemIsMovable, true); - setFlag(QGraphicsItem::ItemIsSelectable, true); m_eMode = mNormal; m_bReleased = false; m_rectBoundingBox.setTopLeft(QPointF(0, 0)); @@ -172,12 +170,14 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) if (fW < MIN_W || fH < m_iMinH) return; + m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setWidth(fW); m_rectBoundingBox.setHeight(fH); m_rectResize.setTopLeft(QPointF(fW - RESIZE_SQUARE, fH - RESIZE_SQUARE)); m_rectResize.setWidth(RESIZE_SQUARE); m_rectResize.setHeight(RESIZE_SQUARE); setTransformOriginPoint(m_rectBoundingBox.center()); + prepareGeometryChange(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 2c6a4cf3d..756248ec8 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -134,15 +134,15 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail); connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail); connect(dataLabel, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationDetail); - connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); + //connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); patternInfo = new VTextGraphicsItem(this); connect(patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMovePattern); connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern); connect(patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationPattern); - connect(patternInfo, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); - connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); + //connect(patternInfo, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); + connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdatePatternInfo); UpdateLabel(); @@ -712,7 +712,17 @@ void VToolDetail::UpdateLabel() dataLabel->AddLine(tl); } - dataLabel->setPos(data.GetPos()); + QPointF pt; + // check if center is inside + if (boundingRect().contains(data.GetPos() + QPointF(data.GetLabelWidth()/2, data.GetLabelHeight()/2)) == false) + { + pt = boundingRect().topLeft(); + } + else + { + pt = data.GetPos(); + } + dataLabel->setPos(pt); dataLabel->setRotation(data.GetRotation()); dataLabel->Update(); dataLabel->show(); @@ -775,7 +785,17 @@ void VToolDetail::UpdatePatternInfo() tl.m_qsText = qslDate.last(); patternInfo->AddLine(tl); - patternInfo->setPos(geom.GetPos()); + // check if center is inside + QPointF pt; + if (boundingRect().contains(geom.GetPos() + QPointF(geom.GetLabelWidth()/2, geom.GetLabelHeight()/2)) == false) + { + pt = boundingRect().topLeft(); + } + else + { + pt = geom.GetPos(); + } + patternInfo->setPos(pt); patternInfo->setRotation(geom.GetRotation()); patternInfo->Update(); } diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 969805f7f..d7086d5c2 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -121,15 +121,15 @@ protected slots: private: Q_DISABLE_COPY(VToolDetail) /** @brief dialog dialog options. */ - DialogTool *dialog; + DialogTool *dialog; /** @brief sceneDetails pointer to the scene. */ - VMainGraphicsScene *sceneDetails; - QString drawName; + VMainGraphicsScene *sceneDetails; + QString drawName; - VNoBrushScalePathItem *seamAllowance; - VTextGraphicsItem* dataLabel; - VTextGraphicsItem* patternInfo; + VNoBrushScalePathItem *seamAllowance; + VTextGraphicsItem *dataLabel; + VTextGraphicsItem *patternInfo; VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr); From 4829b28d25313b1e8f4d9e1deffbdf83f5b88e5a Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 3 Jul 2016 11:41:48 +0200 Subject: [PATCH 27/66] Fixed saving documents that were created before 0.3.3 schema. This change sets a new version right after the DOM tree from loaded document is created. --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index acaccce79..b6e3374cc 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -705,6 +705,7 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document } } VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile); + SetVersion(); } catch (const VExceptionBadId &e) { From aa1d1f8ce16a152f7f5313c646e45f0242e2a992 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Wed, 6 Jul 2016 20:49:36 +0200 Subject: [PATCH 28/66] Label cannot be moved outside of parent bounding box. Moving cursor is on when moving label. Name of detail moved to Pattern Piece Data tab. Hopefully all warnings removed --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 2 - src/libs/ifc/schema/pattern/v0.3.3.xsd | 1 - src/libs/vlayout/vposter.cpp | 2 + src/libs/vpatterndb/vpatternpiecedata.cpp | 31 ++----- src/libs/vpatterndb/vpatternpiecedata.h | 7 +- .../vtools/dialogs/tools/dialogdetail.cpp | 26 ++++-- src/libs/vtools/dialogs/tools/dialogdetail.h | 4 +- src/libs/vtools/dialogs/tools/dialogdetail.ui | 92 +++---------------- src/libs/vtools/tools/vtextgraphicsitem.cpp | 39 ++++++-- src/libs/vtools/tools/vtextgraphicsitem.h | 2 + src/libs/vtools/tools/vtooldetail.cpp | 12 +-- .../vtools/undocommands/savedetailoptions.cpp | 1 - 12 files changed, 80 insertions(+), 139 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index b6e3374cc..53493e5f8 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -658,8 +658,6 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document } else if (element.tagName() == TagData) { - QString qsName = element.attribute(AttrName, ""); - detail.GetPatternPieceData().SetName(qsName); QString qsLetter = element.attribute(AttrLetter, ""); detail.GetPatternPieceData().SetLetter(qsLetter); QPointF ptPos; diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd index 3bdf8d2f3..db2bb2d03 100644 --- a/src/libs/ifc/schema/pattern/v0.3.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -350,7 +350,6 @@ - diff --git a/src/libs/vlayout/vposter.cpp b/src/libs/vlayout/vposter.cpp index 6347e58e4..fab73e12a 100644 --- a/src/libs/vlayout/vposter.cpp +++ b/src/libs/vlayout/vposter.cpp @@ -241,6 +241,8 @@ int VPoster::CountColumns(int width) const //--------------------------------------------------------------------------------------------------------------------- PosterData VPoster::Cut(int i, int j, const QRect &imageRect) const { + Q_UNUSED(imageRect); + const int x = j*PageRect().width() - j*static_cast(allowence); const int y = i*PageRect().height() - i*static_cast(allowence); diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index afb44d731..3ae853501 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -29,15 +29,15 @@ #include "vpatternpiecedata.h" //--------------------------------------------------------------------------------------------------------------------- -VPatternPieceData::VPatternPieceData() : - m_ptPos(0, 0) -{ - m_iFontSize = MIN_FONT_SIZE; - // 0 means unknown width - m_dLabelWidth = 0; - m_dLabelHeight = 0; - m_dRotation = 0; -} +MaterialCutPlacement::MaterialCutPlacement() + :m_eMaterial(MaterialType::mtFabric), m_qsMaterialUserDef(), m_iCutNumber(0), m_ePlacement(PlacementType::ptNone) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VPatternPieceData::VPatternPieceData() + :m_qsLetter(), m_conMCP(), m_ptPos(0, 0), m_dLabelWidth(0), m_dLabelHeight(0), + m_iFontSize(MIN_FONT_SIZE), m_dRotation(0) +{} //--------------------------------------------------------------------------------------------------------------------- VPatternPieceData::~VPatternPieceData() @@ -91,7 +91,6 @@ void VPatternPieceData::RemoveMCP(int i) void VPatternPieceData::Clear() { m_qsLetter.clear(); - m_qsName.clear(); m_conMCP.clear(); } @@ -107,18 +106,6 @@ void VPatternPieceData::SetLetter(QString qsLetter) m_qsLetter = qsLetter.left(3); } -//--------------------------------------------------------------------------------------------------------------------- -const QString& VPatternPieceData::GetName() const -{ - return m_qsName; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VPatternPieceData::SetName(QString qsName) -{ - m_qsName = qsName; -} - //--------------------------------------------------------------------------------------------------------------------- QPointF VPatternPieceData::GetPos() const { diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h index 11997cc36..4ce3c22be 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -55,6 +55,8 @@ struct MaterialCutPlacement QString m_qsMaterialUserDef; int m_iCutNumber; PlacementType m_ePlacement; + + MaterialCutPlacement(); }; typedef QList MCPContainer; @@ -81,8 +83,6 @@ public: // methods, which operate on other members const QString& GetLetter() const; void SetLetter(QString qsLetter); - const QString& GetName() const; - void SetName(QString qsName); // methods, which set up label parameters QPointF GetPos() const; @@ -97,9 +97,6 @@ public: void SetRotation(qreal dRot); private: - /** @brief Pattern piece name - */ - QString m_qsName; /** @brief Pattern piece letter (should be no more than 3 letters) */ QString m_qsLetter; diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 44f25234d..a8ae201af 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -44,15 +44,16 @@ * @param parent parent widget */ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(), detail(VDetail()), supplement(true), closed(true), flagWidth(true) + :DialogTool(data, toolId, parent), ui(), detail(VDetail()), supplement(true), closed(true), flagWidth(true), + m_bAddMode(true), m_qslMaterials(), m_qslPlacements(), m_conMCP(), m_oldData(), m_oldGeom() { ui.setupUi(this); #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) - ui.lineEditNameDetail->setClearButtonEnabled(true); + ui.lineEditName->setClearButtonEnabled(true); #endif - labelEditNamePoint = ui.labelEditNameDetail; + labelEditNamePoint = ui.labelEditName; ui.labelUnit->setText( VDomDocument::UnitsToStr(qApp->patternUnit(), true)); ui.labelUnitX->setText(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); ui.labelUnitY->setText(VDomDocument::UnitsToStr(qApp->patternUnit(), true)); @@ -85,7 +86,7 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge connect(ui.checkBoxSeams, &QCheckBox::clicked, this, &DialogDetail::ClickedSeams); connect(ui.checkBoxClosed, &QCheckBox::clicked, this, &DialogDetail::ClickedClosed); connect(ui.checkBoxReverse, &QCheckBox::clicked, this, &DialogDetail::ClickedReverse); - connect(ui.lineEditNameDetail, &QLineEdit::textChanged, this, &DialogDetail::NameDetailChanged); + connect(ui.lineEditName, &QLineEdit::textChanged, this, &DialogDetail::NameDetailChanged); connect(ui.toolButtonDelete, &QToolButton::clicked, this, &DialogDetail::DeleteItem); connect(ui.toolButtonUp, &QToolButton::clicked, this, &DialogDetail::ScrollUp); @@ -355,19 +356,24 @@ VDetail DialogDetail::CreateDetail() const detail.append( qvariant_cast(item->data(Qt::UserRole))); } detail.setWidth(ui.doubleSpinBoxSeams->value()); - detail.setName(ui.lineEditNameDetail->text()); + detail.setName(ui.lineEditName->text()); detail.setSeamAllowance(supplement); detail.setClosed(closed); detail.GetPatternPieceData().SetLetter(ui.lineEditLetter->text()); - detail.GetPatternPieceData().SetName(ui.lineEditName->text()); for (int i = 0; i < m_conMCP.count(); ++i) { detail.GetPatternPieceData().Append(m_conMCP[i]); } - detail.GetPatternPieceData().SetPos(m_ptPos); + detail.GetPatternPieceData().SetPos(m_oldData.GetPos()); + detail.GetPatternPieceData().SetLabelWidth(m_oldData.GetLabelWidth()); + detail.GetPatternPieceData().SetLabelHeight(m_oldData.GetLabelHeight()); + detail.GetPatternPieceData().SetFontSize(m_oldData.GetFontSize()); + detail.GetPatternPieceData().SetRotation(m_oldData.GetRotation()); + + detail.GetPatternInfo() = m_oldGeom; return detail; } @@ -416,7 +422,7 @@ void DialogDetail::setDetail(const VDetail &value) NewItem(node.getId(), node.getTypeTool(), node.getTypeNode(), node.getMx(), node.getMy(), node.getReverse()); } - ui.lineEditNameDetail->setText(detail.getName()); + ui.lineEditName->setText(detail.getName()); ui.checkBoxSeams->setChecked(detail.getSeamAllowance()); ui.checkBoxClosed->setChecked(detail.getClosed()); ClickedClosed(detail.getClosed()); @@ -427,7 +433,6 @@ void DialogDetail::setDetail(const VDetail &value) ui.toolButtonDelete->setEnabled(true); ui.lineEditLetter->setText(detail.GetPatternPieceData().GetLetter()); - ui.lineEditName->setText(detail.GetPatternPieceData().GetName()); m_conMCP.clear(); for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i) @@ -436,7 +441,8 @@ void DialogDetail::setDetail(const VDetail &value) } UpdateList(); - m_ptPos = detail.GetPatternPieceData().GetPos(); + m_oldData = detail.GetPatternPieceData(); + m_oldGeom = detail.GetPatternInfo(); ValidObjects(DetailIsValid()); } diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index 6dd932ab8..482a5ee5d 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -33,6 +33,7 @@ #include "dialogtool.h" #include "../vpatterndb/vdetail.h" #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vpatterninfogeometry.h" /** * @brief The DialogDetail class dialog for ToolDetai. Help create detail and edit option. @@ -92,7 +93,8 @@ private: QStringList m_qslPlacements; // temporary container for Material/Cut/Placement 3-tuples MCPContainer m_conMCP; - QPointF m_ptPos; + VPatternPieceData m_oldData; + VPatternInfoGeometry m_oldGeom; bool DetailIsValid() const; diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index 8faa4a01f..3b220ca70 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -191,74 +191,7 @@
- - - - - - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - - - - - - Name of detail: - - - - - - - - 0 - 0 - - - - Detail - - - - + @@ -457,25 +390,25 @@ - + - 9 - 38 - 40 + 10 + 40 + 101 16 - Name: + Name of detail: - 55 - 38 - 125 + 110 + 40 + 151 23 @@ -586,9 +519,9 @@ - 55 - 9 - 125 + 110 + 10 + 151 23 @@ -633,7 +566,6 @@ doubleSpinBoxBiasX doubleSpinBoxBiasY checkBoxReverse - lineEditNameDetail checkBoxSeams doubleSpinBoxSeams toolButtonDown diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 025ba13af..2e3c2fe68 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -33,6 +33,7 @@ #include #include +#include "../vmisc/def.h" #include "vtextgraphicsitem.h" #define RESIZE_SQUARE 30 @@ -46,14 +47,20 @@ #define SPACING 2 #define TOP_Z 2 +//--------------------------------------------------------------------------------------------------------------------- +TextLine::TextLine() + :m_qsText(), m_iFontSize(MIN_FONT_SIZE), m_eFontWeight(QFont::Normal), m_eStyle(QFont::StyleNormal), + m_eAlign(Qt::AlignCenter), m_iHeight(0) +{} + //--------------------------------------------------------------------------------------------------------------------- VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) - : QGraphicsObject(pParent) + :QGraphicsObject(pParent), m_eMode(VTextGraphicsItem::mNormal), m_bReleased(false), + m_ptStartPos(), m_ptStart(), m_ptRotCenter(), m_szStart(), m_dRotation(0), m_dAngle(0), + m_rectResize(), m_iMinH(MIN_H), m_rectBoundingBox(), m_font(), m_liLines(), m_liOutput() + { - m_eMode = mNormal; - m_bReleased = false; m_rectBoundingBox.setTopLeft(QPointF(0, 0)); - m_iMinH = MIN_H; SetSize(MIN_W, m_iMinH); setZValue(TOP_Z); } @@ -219,6 +226,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) else { m_eMode = mMove; + SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } setZValue(TOP_Z + 1); @@ -232,14 +240,25 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) QPointF ptDiff = pME->scenePos() - m_ptStart; if (m_eMode == mMove) { - setPos(m_ptStartPos + ptDiff); - UpdateBox(); + QPointF pt = m_ptStartPos + ptDiff; + pt.setX(pt.x() + m_rectBoundingBox.width()/2); + pt.setY(pt.y() + m_rectBoundingBox.height()/2); + if (parentItem()->boundingRect().contains(pt) == true) + { + setPos(m_ptStartPos + ptDiff); + UpdateBox(); + } } else if (m_eMode == mResize) { - SetSize(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); - Update(); - emit SignalShrink(); + QPointF pt = m_ptStartPos; + pt.setX(pt.x() + (m_szStart.width() + ptDiff.x())/2); + pt.setY(pt.y() + (m_szStart.height() + ptDiff.y())/2); + if (parentItem()->boundingRect().contains(pt) == true) { + SetSize(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); + Update(); + emit SignalShrink(); + } } else if (m_eMode == mRotate) { @@ -260,6 +279,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (pME->button() == Qt::LeftButton) { + RestoreOverrideCursor(cursorArrowCloseHand); double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y()); bool bShort = (dDist < 2); @@ -289,6 +309,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) if (bShort == true) { m_eMode = mMove; + SetOverrideCursor(cursorArrowCloseHand, 1, 1); UpdateBox(); } else diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 7f01e987c..703ba289f 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -41,6 +41,8 @@ struct TextLine QFont::Style m_eStyle; Qt::Alignment m_eAlign; int m_iHeight; + + TextLine(); }; class VTextGraphicsItem : public QGraphicsObject diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 3df76dab0..cddf349c0 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -81,7 +81,8 @@ const QString VToolDetail::NodeSplinePath = QStringLiteral("NodeSplinePath"); VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent) :VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene), - drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)) + drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)), dataLabel(new VTextGraphicsItem(this)), + patternInfo(new VTextGraphicsItem(this)) { VDetail detail = data->GetDetail(id); for (int i = 0; i< detail.CountNode(); ++i) @@ -130,13 +131,11 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 } setAcceptHoverEvents(true); - dataLabel = new VTextGraphicsItem(this); connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail); connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail); connect(dataLabel, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationDetail); //connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); - patternInfo = new VTextGraphicsItem(this); connect(patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMovePattern); connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern); connect(patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationPattern); @@ -354,7 +353,6 @@ void VToolDetail::AddToFile() QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = detail.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName()); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); @@ -411,8 +409,6 @@ void VToolDetail::RefreshDataInFile() QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = det.GetPatternPieceData(); - doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName()); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); @@ -675,7 +671,7 @@ void VToolDetail::UpdateLabel() const VDetail detail = VAbstractTool::data.GetDetail(id); const VPatternPieceData& data = detail.GetPatternPieceData(); - if (data.GetLetter().isEmpty() == false || data.GetName().isEmpty() == false || data.GetMCPCount() > 0) + if (data.GetLetter().isEmpty() == false || detail.getName().isEmpty() == false || data.GetMCPCount() > 0) { //dataLabel->Reset(); @@ -695,7 +691,7 @@ void VToolDetail::UpdateLabel() tl.m_eStyle = QFont::StyleNormal; tl.m_iFontSize = 6; dataLabel->AddLine(tl); - tl.m_qsText = data.GetName(); + tl.m_qsText = detail.getName(); tl.m_eAlign = Qt::AlignCenter; tl.m_eFontWeight = QFont::DemiBold; tl.m_iFontSize = 2; diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index f6776638a..af6ec446b 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -139,7 +139,6 @@ void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDet QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = det.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrName, data.GetName()); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth()); From 192c4d33a7507e0aaa67051b555d31004676e5da Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Wed, 6 Jul 2016 21:56:52 +0200 Subject: [PATCH 29/66] Added possibility to hide both labels for each detail individually --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 3 + src/libs/ifc/schema/pattern/v0.3.3.xsd | 2 + src/libs/vpatterndb/vpatterninfogeometry.cpp | 18 ++- src/libs/vpatterndb/vpatterninfogeometry.h | 6 + src/libs/vpatterndb/vpatternpiecedata.cpp | 14 ++- src/libs/vpatterndb/vpatternpiecedata.h | 6 + .../vtools/dialogs/tools/dialogdetail.cpp | 6 + src/libs/vtools/dialogs/tools/dialogdetail.ui | 26 +++++ src/libs/vtools/tools/vtooldetail.cpp | 106 ++++++++++-------- .../vtools/undocommands/savedetailoptions.cpp | 2 + 10 files changed, 139 insertions(+), 50 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 53493e5f8..d83a82193 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -658,6 +658,8 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document } else if (element.tagName() == TagData) { + QString qsVisible = element.attribute(AttrVisible, "1"); + detail.GetPatternPieceData().SetVisible(qsVisible.toInt() != 0); QString qsLetter = element.attribute(AttrLetter, ""); detail.GetPatternPieceData().SetLetter(qsLetter); QPointF ptPos; @@ -687,6 +689,7 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document } else if (element.tagName() == TagPatternInfo) { + detail.GetPatternInfo().SetVisible(element.attribute(AttrVisible, "1").toInt() != 0); QPointF ptPos; ptPos.setX(element.attribute(AttrMx, "0").toDouble()); ptPos.setY(element.attribute(AttrMy, "0").toDouble()); diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd index db2bb2d03..9f622d42e 100644 --- a/src/libs/ifc/schema/pattern/v0.3.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -351,6 +351,7 @@
+ @@ -361,6 +362,7 @@
+ diff --git a/src/libs/vpatterndb/vpatterninfogeometry.cpp b/src/libs/vpatterndb/vpatterninfogeometry.cpp index cb0728454..11881bdbd 100644 --- a/src/libs/vpatterndb/vpatterninfogeometry.cpp +++ b/src/libs/vpatterndb/vpatterninfogeometry.cpp @@ -29,8 +29,9 @@ #include "vpatterninfogeometry.h" //--------------------------------------------------------------------------------------------------------------------- -VPatternInfoGeometry::VPatternInfoGeometry() : - m_ptPos(0, 0) +VPatternInfoGeometry::VPatternInfoGeometry() + :m_ptPos(0, 0), m_dLabelWidth(0), m_dLabelHeight(0), m_iFontSize(MIN_FONT_SIZE), + m_dRotation(0), m_bVisible(true) { m_iFontSize = MIN_FONT_SIZE; // 0 means unknown width @@ -106,3 +107,16 @@ void VPatternInfoGeometry::SetRotation(qreal dRot) m_dRotation = dRot; } +//--------------------------------------------------------------------------------------------------------------------- +bool VPatternInfoGeometry::IsVisible() const +{ + return m_bVisible; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternInfoGeometry::SetVisible(bool bVal) +{ + m_bVisible = bVal; +} + +//--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpatterninfogeometry.h b/src/libs/vpatterndb/vpatterninfogeometry.h index 36c8217c7..0f9ff5cfd 100644 --- a/src/libs/vpatterndb/vpatterninfogeometry.h +++ b/src/libs/vpatterndb/vpatterninfogeometry.h @@ -50,6 +50,8 @@ public: void SetFontSize(int iSize); qreal GetRotation() const; void SetRotation(qreal dRot); + bool IsVisible() const; + void SetVisible(bool bVal); private: QPointF m_ptPos; @@ -65,6 +67,10 @@ private: /** @brief Label rotation */ qreal m_dRotation; + /** @brief Visibility flag + */ + bool m_bVisible; + }; #endif // VPATTERNINFOGEOMETRY_H diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index 3ae853501..20b694bb0 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -36,7 +36,7 @@ MaterialCutPlacement::MaterialCutPlacement() //--------------------------------------------------------------------------------------------------------------------- VPatternPieceData::VPatternPieceData() :m_qsLetter(), m_conMCP(), m_ptPos(0, 0), m_dLabelWidth(0), m_dLabelHeight(0), - m_iFontSize(MIN_FONT_SIZE), m_dRotation(0) + m_iFontSize(MIN_FONT_SIZE), m_dRotation(0), m_bVisible(true) {} //--------------------------------------------------------------------------------------------------------------------- @@ -170,4 +170,16 @@ void VPatternPieceData::SetRotation(qreal dRot) } //--------------------------------------------------------------------------------------------------------------------- +bool VPatternPieceData::IsVisible() const +{ + return m_bVisible; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternPieceData::SetVisible(bool bVal) +{ + m_bVisible = bVal; +} + +//--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h index 4ce3c22be..833249f2d 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -95,6 +95,8 @@ public: void SetFontSize(int iSize); qreal GetRotation() const; void SetRotation(qreal dRot); + bool IsVisible() const; + void SetVisible(bool bVal); private: /** @brief Pattern piece letter (should be no more than 3 letters) @@ -118,6 +120,10 @@ private: /** @brief Label rotation */ qreal m_dRotation; + /** @brief Visibility flag + */ + bool m_bVisible; + }; #endif // VPATTERNPIECEDATA_H diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index a8ae201af..3f6da9a01 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -372,8 +372,12 @@ VDetail DialogDetail::CreateDetail() const detail.GetPatternPieceData().SetLabelHeight(m_oldData.GetLabelHeight()); detail.GetPatternPieceData().SetFontSize(m_oldData.GetFontSize()); detail.GetPatternPieceData().SetRotation(m_oldData.GetRotation()); + detail.GetPatternPieceData().SetVisible(ui.checkBoxDetail->isChecked()); + + qDebug() << "DD VISIBLE" << detail.GetPatternPieceData().IsVisible(); detail.GetPatternInfo() = m_oldGeom; + detail.GetPatternInfo().SetVisible(ui.checkBoxPattern->isChecked()); return detail; } @@ -433,6 +437,8 @@ void DialogDetail::setDetail(const VDetail &value) ui.toolButtonDelete->setEnabled(true); ui.lineEditLetter->setText(detail.GetPatternPieceData().GetLetter()); + ui.checkBoxDetail->setChecked(detail.GetPatternPieceData().IsVisible()); + ui.checkBoxPattern->setChecked(detail.GetPatternInfo().IsVisible()); m_conMCP.clear(); for (int i = 0; i < detail.GetPatternPieceData().GetMCPCount(); ++i) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index 3b220ca70..165a4b4b7 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -529,6 +529,32 @@ 3 + + + + 10 + 230 + 141 + 21 + + + + Detail label visible + + + + + + 10 + 260 + 141 + 21 + + + + Pattern label visible + + diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index cddf349c0..1929c3e3c 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -353,6 +353,7 @@ void VToolDetail::AddToFile() QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = detail.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? 1:0); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); @@ -374,6 +375,7 @@ void VToolDetail::AddToFile() domData = doc->createElement(VAbstractPattern::TagPatternInfo); const VPatternInfoGeometry& geom = detail.GetPatternInfo(); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true? 1:0); doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth()); @@ -409,6 +411,8 @@ void VToolDetail::RefreshDataInFile() QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = det.GetPatternPieceData(); + doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? 1:0); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); @@ -430,6 +434,7 @@ void VToolDetail::RefreshDataInFile() domData = doc->createElement(VAbstractPattern::TagPatternInfo); const VPatternInfoGeometry& geom = det.GetPatternInfo(); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true? 1:0); doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth()); @@ -669,9 +674,9 @@ void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) void VToolDetail::UpdateLabel() { const VDetail detail = VAbstractTool::data.GetDetail(id); - const VPatternPieceData& data = detail.GetPatternPieceData(); - if (data.GetLetter().isEmpty() == false || detail.getName().isEmpty() == false || data.GetMCPCount() > 0) + + if (data.IsVisible() == true) { //dataLabel->Reset(); @@ -736,62 +741,69 @@ void VToolDetail::UpdatePatternInfo() const VDetail detail = VAbstractTool::data.GetDetail(id); const VPatternInfoGeometry& geom = detail.GetPatternInfo(); - //patternInfo->Reset(); - QFont fnt = qApp->font(); - int iFS = geom.GetFontSize(); - if (iFS < MIN_FONT_SIZE) + if (geom.IsVisible() == true) { - iFS = MIN_FONT_SIZE; - } - fnt.setPixelSize(iFS); - patternInfo->SetFont(fnt); - patternInfo->SetSize(geom.GetLabelWidth(), geom.GetLabelHeight()); - patternInfo->Clear(); - TextLine tl; + QFont fnt = qApp->font(); + int iFS = geom.GetFontSize(); + if (iFS < MIN_FONT_SIZE) + { + iFS = MIN_FONT_SIZE; + } + fnt.setPixelSize(iFS); + patternInfo->SetFont(fnt); + patternInfo->SetSize(geom.GetLabelWidth(), geom.GetLabelHeight()); + patternInfo->Clear(); + TextLine tl; - // Company name - tl.m_qsText = doc->GetCompanyName(); - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::DemiBold; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 4; - patternInfo->AddLine(tl); + // Company name + tl.m_qsText = doc->GetCompanyName(); + tl.m_eAlign = Qt::AlignCenter; + tl.m_eFontWeight = QFont::DemiBold; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 4; + patternInfo->AddLine(tl); - // Pattern name - tl.m_qsText = doc->GetPatternName(); - tl.m_eFontWeight = QFont::Normal; - tl.m_iFontSize = 2; - patternInfo->AddLine(tl); + // Pattern name + tl.m_qsText = doc->GetPatternName(); + tl.m_eFontWeight = QFont::Normal; + tl.m_iFontSize = 2; + patternInfo->AddLine(tl); - // Pattern number - tl.m_qsText = doc->GetPatternNumber(); - tl.m_iFontSize = 0; - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - patternInfo->AddLine(tl); + // Pattern number + tl.m_qsText = doc->GetPatternNumber(); + tl.m_iFontSize = 0; + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + patternInfo->AddLine(tl); - // Customer name - tl.m_qsText = doc->GetCustomerName(); - tl.m_eStyle = QFont::StyleItalic; - patternInfo->AddLine(tl); + // Customer name + tl.m_qsText = doc->GetCustomerName(); + tl.m_eStyle = QFont::StyleItalic; + patternInfo->AddLine(tl); - // Creation date - QStringList qslDate = doc->GetCreationDate().toString(Qt::SystemLocaleLongDate).split(", "); - tl.m_qsText = qslDate.last(); - patternInfo->AddLine(tl); + // Creation date + QStringList qslDate = doc->GetCreationDate().toString(Qt::SystemLocaleLongDate).split(", "); + tl.m_qsText = qslDate.last(); + patternInfo->AddLine(tl); - // check if center is inside - QPointF pt; - if (boundingRect().contains(geom.GetPos() + QPointF(geom.GetLabelWidth()/2, geom.GetLabelHeight()/2)) == false) - { - pt = boundingRect().topLeft(); + // check if center is inside + QPointF pt; + if (boundingRect().contains(geom.GetPos() + QPointF(geom.GetLabelWidth()/2, geom.GetLabelHeight()/2)) == false) + { + pt = boundingRect().topLeft(); + } + else + { + pt = geom.GetPos(); + } + patternInfo->setPos(pt); + patternInfo->setRotation(geom.GetRotation()); + patternInfo->Update(); + patternInfo->show(); } else { - pt = geom.GetPos(); + patternInfo->hide(); } - patternInfo->setPos(pt); - patternInfo->setRotation(geom.GetRotation()); - patternInfo->Update(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index af6ec446b..85320bcd4 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -139,6 +139,7 @@ void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDet QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = det.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? 1:0); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth()); @@ -164,6 +165,7 @@ void SaveDetailOptions::SavePatternInfo(QDomElement &domElement, const VDetail & { QDomElement domData = doc->createElement(VAbstractPattern::TagPatternInfo); const VPatternInfoGeometry& data = det.GetPatternInfo(); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? 1:0); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth()); From 3a4092776426df4823566d24335dc1cdbc140bbe Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Wed, 6 Jul 2016 22:15:32 +0200 Subject: [PATCH 30/66] Fixed layout in detail dialog and painting of text item in rotate mode --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogdetail.ui | 122 ++++++++---------- src/libs/vtools/tools/vtextgraphicsitem.cpp | 3 +- 2 files changed, 56 insertions(+), 69 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index 165a4b4b7..418b88edf 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -390,32 +390,6 @@ - - - - 10 - 40 - 101 - 16 - - - - Name of detail: - - - - - - 110 - 40 - 151 - 23 - - - - 15 - - @@ -503,57 +477,71 @@ - + - 9 - 9 - 40 - 16 + 0 + 0 + 271 + 61 - - Letter: - + + + + + Letter: + + + + + + + 3 + + + + + + + Name of detail: + + + + + + + 15 + + + + - + - 110 - 10 - 151 - 23 - - - - 3 - - - - - - 10 + 0 230 - 141 - 21 + 261 + 80 - - Detail label visible - - - - - - 10 - 260 - 141 - 21 - - - - Pattern label visible - + + + + + Detail label visible + + + + + + + Pattern label visible + + + + diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 2e3c2fe68..5975462dd 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -122,8 +122,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->setPen(Qt::black); painter->setBrush(Qt::black); painter->drawEllipse( - m_rectBoundingBox.width()/2, - m_rectBoundingBox.height()/2, + QPointF(m_rectBoundingBox.width()/2, m_rectBoundingBox.height()/2), ROTATE_CIRCLE, ROTATE_CIRCLE ); From 6e1dce0cd7783b22bd3ba28ccb359847cbdca7c6 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 8 Jul 2016 00:46:33 +0200 Subject: [PATCH 31/66] Fixed moving labels and added warning icon to detail dialog when detail name is empty --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogdetail.cpp | 4 ++++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 3f6da9a01..f7eeebfc7 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -257,11 +257,15 @@ void DialogDetail::NameDetailChanged() { flagName = false; ChangeColor(labelEditNamePoint, Qt::red); + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui.tabWidget->setTabIcon(1, icon); } else { flagName = true; ChangeColor(labelEditNamePoint, okColor); + QIcon icon; + ui.tabWidget->setTabIcon(1, icon); } } CheckState(); diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 5975462dd..408a0d73d 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -242,11 +242,16 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) QPointF pt = m_ptStartPos + ptDiff; pt.setX(pt.x() + m_rectBoundingBox.width()/2); pt.setY(pt.y() + m_rectBoundingBox.height()/2); - if (parentItem()->boundingRect().contains(pt) == true) + QRectF rectBB = parentItem()->boundingRect(); + if (rectBB.contains(pt) == false) { - setPos(m_ptStartPos + ptDiff); - UpdateBox(); + pt.setX(qMin(rectBB.right(), qMax(pt.x(), rectBB.left()))); + pt.setY(qMin(rectBB.bottom(), qMax(pt.y(), rectBB.top()))); } + pt.setX(pt.x() - m_rectBoundingBox.width()/2); + pt.setY(pt.y() - m_rectBoundingBox.height()/2); + setPos(pt); + UpdateBox(); } else if (m_eMode == mResize) { From d76cc0bd3843790f1bf8e547e418e4d8bd2a5447 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 10 Jul 2016 11:20:53 +0200 Subject: [PATCH 32/66] Corrected the label placement when moved on the detail edge --HG-- branch : feature --- src/libs/vtools/tools/vtooldetail.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 83673a589..52ac44a2f 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -711,11 +711,15 @@ void VToolDetail::UpdateLabel() dataLabel->AddLine(tl); } - QPointF pt; + QPointF pt = data.GetPos() + QPointF(data.GetLabelWidth()/2, data.GetLabelHeight()/2); // check if center is inside - if (boundingRect().contains(data.GetPos() + QPointF(data.GetLabelWidth()/2, data.GetLabelHeight()/2)) == false) + if (boundingRect().contains(pt) == false) { - pt = boundingRect().topLeft(); + QRectF rect = boundingRect(); + pt.setX(qMin(rect.right(), qMax(pt.x(), rect.left()))); + pt.setY(qMin(rect.bottom(), qMax(pt.y(), rect.top()))); + pt.setX(pt.x() - data.GetLabelWidth()/2); + pt.setY(pt.y() - data.GetLabelHeight()/2); } else { @@ -786,10 +790,15 @@ void VToolDetail::UpdatePatternInfo() patternInfo->AddLine(tl); // check if center is inside - QPointF pt; - if (boundingRect().contains(geom.GetPos() + QPointF(geom.GetLabelWidth()/2, geom.GetLabelHeight()/2)) == false) + QPointF pt = geom.GetPos() + QPointF(geom.GetLabelWidth()/2, geom.GetLabelHeight()/2); + if (boundingRect().contains(pt) == false) { - pt = boundingRect().topLeft(); + QRectF rect = boundingRect(); + qDebug() << "FALSE" << rect << pt << pt.x() - rect.left(); + pt.setX(qMin(rect.right(), qMax(pt.x(), rect.left()))); + pt.setY(qMin(rect.bottom(), qMax(pt.y(), rect.top()))); + pt.setX(pt.x() - geom.GetLabelWidth()/2); + pt.setY(pt.y() - geom.GetLabelHeight()/2); } else { From a557b99409f1062fd8448171bbd4badc55c4a375 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 10 Jul 2016 11:32:37 +0200 Subject: [PATCH 33/66] Material/Cut/Placement is not displayed on label if cut number is 0 --HG-- branch : feature --- src/libs/vtools/tools/vtooldetail.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 52ac44a2f..6ad285e93 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -707,8 +707,11 @@ void VToolDetail::UpdateLabel() tl.m_iFontSize = 0; for (int i = 0; i < data.GetMCPCount(); ++i) { MaterialCutPlacement mcp = data.GetMCP(i); - tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]); - dataLabel->AddLine(tl); + if (mcp.m_iCutNumber > 0) + { + tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]); + dataLabel->AddLine(tl); + } } QPointF pt = data.GetPos() + QPointF(data.GetLabelWidth()/2, data.GetLabelHeight()/2); From e5f7c478289308556c6aa3cfa7b556bf504bce56 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 10 Jul 2016 12:39:50 +0200 Subject: [PATCH 34/66] Removed some compiler warnings and set the resize cursor when label is being resized --HG-- branch : feature --- src/libs/vmisc/def.cpp | 22 +++++++++++++++++++++ src/libs/vmisc/def.h | 2 ++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 20 ++++++++++++++----- src/libs/vtools/tools/vtooldetail.cpp | 1 - 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index 9e4276438..eba396865 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -439,6 +439,28 @@ void SetOverrideCursor(const QString &pixmapPath, int hotX, int hotY) #endif } +//--------------------------------------------------------------------------------------------------------------------- +void SetOverrideCursor(Qt::CursorShape shape) +{ +#ifndef QT_NO_CURSOR + QPixmap oldPixmap; + QCursor* pOldCursor = QGuiApplication::overrideCursor(); + if (pOldCursor != 0) + { + oldPixmap = pOldCursor->pixmap(); + } + QCursor cursor(shape); + QPixmap newPixmap = cursor.pixmap(); + if (oldPixmap.toImage() != newPixmap.toImage()) + { + QApplication::setOverrideCursor(cursor); + } + +#else + Q_UNUSED(shape); +#endif +} + //--------------------------------------------------------------------------------------------------------------------- void RestoreOverrideCursor(const QString &pixmapPath) { diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 60399132f..91f674346 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -595,8 +595,10 @@ extern const QString trueStr; extern const QString falseStr; void SetOverrideCursor(const QString & pixmapPath, int hotX = -1, int hotY = -1); +void SetOverrideCursor(Qt::CursorShape shape); void RestoreOverrideCursor(const QString & pixmapPath); + extern const qreal PrintDPI; double ToPixel(double val, const Unit &unit) Q_REQUIRED_RESULT; diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 408a0d73d..cf3653d95 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "../vmisc/def.h" @@ -95,7 +96,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); painter->setFont(fnt); - painter->drawText(0, iY, boundingRect().width(), iH, tl.m_eAlign, tl.m_qsText); + painter->drawText(0, iY, qRound(boundingRect().width()), iH, tl.m_eAlign, tl.m_qsText); iY += iH + SPACING; } @@ -113,8 +114,8 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem if (m_eMode == mResize) { - painter->drawLine(0, 0, m_rectBoundingBox.width(), m_rectBoundingBox.height()); - painter->drawLine(0, m_rectBoundingBox.height(), m_rectBoundingBox.width(), 0); + painter->drawLine(0, 0, qRound(m_rectBoundingBox.width()), qRound(m_rectBoundingBox.height())); + painter->drawLine(0, qRound(m_rectBoundingBox.height()), qRound(m_rectBoundingBox.width()), 0); } } else @@ -130,8 +131,8 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->setBrush(Qt::NoBrush); int iTop = ROTATE_RECT - ROTATE_ARC; int iLeft = ROTATE_RECT - ROTATE_ARC; - int iRight = m_rectBoundingBox.width() - ROTATE_RECT; - int iBottom = m_rectBoundingBox.height() - ROTATE_RECT; + int iRight = qRound(m_rectBoundingBox.width()) - ROTATE_RECT; + int iBottom = qRound(m_rectBoundingBox.height()) - ROTATE_RECT; painter->drawArc(iLeft, iTop, ROTATE_ARC, ROTATE_ARC, 180*16, -90*16); painter->drawArc(iRight, iTop, ROTATE_ARC, ROTATE_ARC, 90*16, -90*16); painter->drawArc(iLeft, iBottom, ROTATE_ARC, ROTATE_ARC, 270*16, -90*16); @@ -221,6 +222,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) if (m_rectResize.contains(pME->pos()) == true) { m_eMode = mResize; + SetOverrideCursor(Qt::SizeFDiagCursor); } else { @@ -236,6 +238,14 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { + if (m_rectResize.contains(pME->pos()) == true) + { + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + RestoreOverrideCursor(cursorArrowOpenHand); + } QPointF ptDiff = pME->scenePos() - m_ptStart; if (m_eMode == mMove) { diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 6ad285e93..a1d90652b 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -797,7 +797,6 @@ void VToolDetail::UpdatePatternInfo() if (boundingRect().contains(pt) == false) { QRectF rect = boundingRect(); - qDebug() << "FALSE" << rect << pt << pt.x() - rect.left(); pt.setX(qMin(rect.right(), qMax(pt.x(), rect.left()))); pt.setY(qMin(rect.bottom(), qMax(pt.y(), rect.top()))); pt.setX(pt.x() - geom.GetLabelWidth()/2); From 7c2f4e54ba63de4d6f292ca2c2077fd4c76dd4b3 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 12 Jul 2016 23:11:17 +0200 Subject: [PATCH 35/66] Fixed cursor handling on vtextgraphicsitem --HG-- branch : feature --- src/libs/vmisc/def.cpp | 22 +++++++++++++++++++++ src/libs/vmisc/def.h | 2 +- src/libs/vtools/tools/vtextgraphicsitem.cpp | 18 ++++++++--------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/libs/vmisc/def.cpp b/src/libs/vmisc/def.cpp index eba396865..02785f3d2 100644 --- a/src/libs/vmisc/def.cpp +++ b/src/libs/vmisc/def.cpp @@ -484,6 +484,28 @@ void RestoreOverrideCursor(const QString &pixmapPath) #endif } +//--------------------------------------------------------------------------------------------------------------------- +void RestoreOverrideCursor(Qt::CursorShape shape) +{ +#ifndef QT_NO_CURSOR + QPixmap oldPixmap; + QCursor* pOldCursor = QGuiApplication::overrideCursor(); + if (pOldCursor != 0) + { + oldPixmap = pOldCursor->pixmap(); + } + QCursor cursor(shape); + QPixmap newPixmap = cursor.pixmap(); + if (oldPixmap.toImage() == newPixmap.toImage()) + { + QApplication::restoreOverrideCursor(); + } + +#else + Q_UNUSED(shape); +#endif +} + const qreal PrintDPI = 96.0; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vmisc/def.h b/src/libs/vmisc/def.h index 91f674346..9e5be5209 100644 --- a/src/libs/vmisc/def.h +++ b/src/libs/vmisc/def.h @@ -597,7 +597,7 @@ extern const QString falseStr; void SetOverrideCursor(const QString & pixmapPath, int hotX = -1, int hotY = -1); void SetOverrideCursor(Qt::CursorShape shape); void RestoreOverrideCursor(const QString & pixmapPath); - +void RestoreOverrideCursor(Qt::CursorShape shape); extern const qreal PrintDPI; diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index cf3653d95..66c52ec84 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -238,14 +238,6 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { - if (m_rectResize.contains(pME->pos()) == true) - { - SetOverrideCursor(Qt::SizeFDiagCursor); - } - else - { - RestoreOverrideCursor(cursorArrowOpenHand); - } QPointF ptDiff = pME->scenePos() - m_ptStart; if (m_eMode == mMove) { @@ -293,7 +285,14 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (pME->button() == Qt::LeftButton) { - RestoreOverrideCursor(cursorArrowCloseHand); + if (m_eMode == mMove) + { + RestoreOverrideCursor(cursorArrowCloseHand); + } + else if (m_eMode == mResize) + { + RestoreOverrideCursor(Qt::SizeFDiagCursor); + } double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y()); bool bShort = (dDist < 2); @@ -323,7 +322,6 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) if (bShort == true) { m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); UpdateBox(); } else From 634d8773deb647a6056a73ad1004c04a0e2808cf Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 14 Jul 2016 02:10:27 +0200 Subject: [PATCH 36/66] Labels now cannot go outside the detail bounding box with any operation (move, resize or rotate) --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 127 +++++++++++++++++--- src/libs/vtools/tools/vtextgraphicsitem.h | 3 + src/libs/vtools/tools/vtooldetail.cpp | 46 ++++--- 3 files changed, 135 insertions(+), 41 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 66c52ec84..71725959b 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -194,6 +194,39 @@ void VTextGraphicsItem::Update() UpdateBox(); } +//--------------------------------------------------------------------------------------------------------------------- +bool VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal &dY) const +{ + QRectF rectParent = parentItem()->boundingRect(); + rectBB = GetBoundingRect(rectBB, dRot); + dX = 0; + dY = 0; + + if (rectParent.contains(rectBB) == false) + { + if (rectParent.left() - rectBB.left() > fabs(dX)) + { + dX = rectParent.left() - rectBB.left(); + } + else if (rectBB.right() - rectParent.right() > fabs(dX)) + { + dX = rectParent.right() - rectBB.right(); + } + + if (rectParent.top() - rectBB.top() > fabs(dY)) + { + dY = rectParent.top() - rectBB.top(); + } + else if (rectBB.bottom() - rectParent.bottom() > fabs(dY)) + { + dY = rectParent.bottom() - rectBB.bottom(); + } + + return false; + } + return true; +} + //--------------------------------------------------------------------------------------------------------------------- int VTextGraphicsItem::GetFontSize() const { @@ -238,33 +271,38 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { + qreal dX; + qreal dY; + QRectF rectBB; QPointF ptDiff = pME->scenePos() - m_ptStart; if (m_eMode == mMove) { QPointF pt = m_ptStartPos + ptDiff; - pt.setX(pt.x() + m_rectBoundingBox.width()/2); - pt.setY(pt.y() + m_rectBoundingBox.height()/2); - QRectF rectBB = parentItem()->boundingRect(); - if (rectBB.contains(pt) == false) + rectBB.setTopLeft(pt); + rectBB.setWidth(m_rectBoundingBox.width()); + rectBB.setHeight(m_rectBoundingBox.height()); + if (IsContained(rectBB, rotation(), dX, dY) == false) { - pt.setX(qMin(rectBB.right(), qMax(pt.x(), rectBB.left()))); - pt.setY(qMin(rectBB.bottom(), qMax(pt.y(), rectBB.top()))); + pt.setX(pt.x() + dX); + pt.setY(pt.y() + dY); } - pt.setX(pt.x() - m_rectBoundingBox.width()/2); - pt.setY(pt.y() - m_rectBoundingBox.height()/2); setPos(pt); UpdateBox(); } else if (m_eMode == mResize) { QPointF pt = m_ptStartPos; - pt.setX(pt.x() + (m_szStart.width() + ptDiff.x())/2); - pt.setY(pt.y() + (m_szStart.height() + ptDiff.y())/2); - if (parentItem()->boundingRect().contains(pt) == true) { - SetSize(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); - Update(); - emit SignalShrink(); + rectBB.setTopLeft(pt); + QSize sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); + rectBB.setSize(sz); + if (IsContained(rectBB, rotation(), dX, dY) == false) { + sz.setWidth(sz.width() + dX); + sz.setHeight(sz.height() + dY); } + + SetSize(sz.width(), sz.height()); + Update(); + emit SignalShrink(); } else if (m_eMode == mRotate) { @@ -274,9 +312,14 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) return; } double dAng = 180*(GetAngle(pME->scenePos()) - m_dAngle)/M_PI; - setRotation(m_dRotation + dAng); - //emit SignalRotated(rotation()); - Update(); + rectBB.setTopLeft(m_ptStartPos); + rectBB.setWidth(m_rectBoundingBox.width()); + rectBB.setHeight(m_rectBoundingBox.height()); + if (IsContained(rectBB, m_dRotation + dAng, dX, dY) == true) + { + setRotation(m_dRotation + dAng); + Update(); + } } } @@ -421,3 +464,53 @@ double VTextGraphicsItem::GetAngle(QPointF pt) const else return atan2(dY, dX); } + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VTextGraphicsItem::GetBoundingRect(QRectF rectBB, qreal dRot) const +{ + QPointF apt[4] = { rectBB.topLeft(), rectBB.topRight(), rectBB.bottomLeft(), rectBB.bottomRight() }; + QPointF ptCenter = rectBB.center(); + + qreal dX1 = 0; + qreal dX2 = 0; + qreal dY1 = 0; + qreal dY2 = 0; + + double dAng = M_PI*dRot/180; + for (int i = 0; i < 4; ++i) + { + QPointF pt = apt[i] - ptCenter; + qreal dX = pt.x()*cos(dAng) + pt.y()*sin(dAng); + qreal dY = -pt.x()*sin(dAng) + pt.y()*cos(dAng); + + if (i == 0) + { + dX1 = dX2 = dX; + dY1 = dY2 = dY; + } + else + { + if (dX < dX1) + { + dX1 = dX; + } + else if (dX > dX2) + { + dX2 = dX; + } + if (dY < dY1) + { + dY1 = dY; + } + else if (dY > dY2) + { + dY2 = dY; + } + } + } + QRectF rect; + rect.setTopLeft(ptCenter + QPointF(dX1, dY1)); + rect.setWidth(dX2 - dX1); + rect.setHeight(dY2 - dY1); + return rect; +} diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 703ba289f..647427f61 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -71,6 +71,7 @@ public: void Clear(); void SetSize(qreal fW, qreal fH); void Update(); + bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const; protected: void mousePressEvent(QGraphicsSceneMouseEvent* pME); @@ -104,6 +105,8 @@ private: QFont m_font; QList m_liLines; QList m_liOutput; + + QRectF GetBoundingRect(QRectF rectBB, qreal dRot) const; }; #endif // VTEXTGRAPHICSITEM_H diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index ec7ff0792..70622c56e 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -714,20 +714,19 @@ void VToolDetail::UpdateLabel() } } - QPointF pt = data.GetPos() + QPointF(data.GetLabelWidth()/2, data.GetLabelHeight()/2); - // check if center is inside - if (boundingRect().contains(pt) == false) + QPointF pt = data.GetPos(); + QRectF rectBB; + rectBB.setTopLeft(pt); + rectBB.setWidth(data.GetLabelWidth()); + rectBB.setHeight(data.GetLabelHeight()); + qreal dX; + qreal dY; + if (dataLabel->IsContained(rectBB, data.GetRotation(), dX, dY) == false) { - QRectF rect = boundingRect(); - pt.setX(qMin(rect.right(), qMax(pt.x(), rect.left()))); - pt.setY(qMin(rect.bottom(), qMax(pt.y(), rect.top()))); - pt.setX(pt.x() - data.GetLabelWidth()/2); - pt.setY(pt.y() - data.GetLabelHeight()/2); - } - else - { - pt = data.GetPos(); + pt.setX(pt.x() + dX); + pt.setY(pt.y() + dY); } + dataLabel->setPos(pt); dataLabel->setRotation(data.GetRotation()); dataLabel->Update(); @@ -792,20 +791,19 @@ void VToolDetail::UpdatePatternInfo() tl.m_qsText = qslDate.last(); patternInfo->AddLine(tl); - // check if center is inside - QPointF pt = geom.GetPos() + QPointF(geom.GetLabelWidth()/2, geom.GetLabelHeight()/2); - if (boundingRect().contains(pt) == false) + QPointF pt = geom.GetPos(); + QRectF rectBB; + rectBB.setTopLeft(pt); + rectBB.setWidth(geom.GetLabelWidth()); + rectBB.setHeight(geom.GetLabelHeight()); + qreal dX; + qreal dY; + if (patternInfo->IsContained(rectBB, geom.GetRotation(), dX, dY) == false) { - QRectF rect = boundingRect(); - pt.setX(qMin(rect.right(), qMax(pt.x(), rect.left()))); - pt.setY(qMin(rect.bottom(), qMax(pt.y(), rect.top()))); - pt.setX(pt.x() - geom.GetLabelWidth()/2); - pt.setY(pt.y() - geom.GetLabelHeight()/2); - } - else - { - pt = geom.GetPos(); + pt.setX(pt.x() + dX); + pt.setY(pt.y() + dY); } + patternInfo->setPos(pt); patternInfo->setRotation(geom.GetRotation()); patternInfo->Update(); From ea9cdd46b26b3becd6bf56d5983f8a6d26b1f033 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 14 Jul 2016 02:59:42 +0200 Subject: [PATCH 37/66] Fixed some code style errors and checking label position at resizing --HG-- branch : feature --- src/app/share/collection/TestDart.val | 2 +- src/libs/vpatterndb/vpatterninfogeometry.cpp | 4 ++++ src/libs/vpatterndb/vpatternpiecedata.cpp | 4 ++++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 24 ++++++++++++-------- src/libs/vtools/tools/vtextgraphicsitem.h | 2 +- src/libs/vtools/tools/vtooldetail.cpp | 6 ++--- src/libs/vtools/tools/vtooldetail.h | 4 ++-- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/app/share/collection/TestDart.val b/src/app/share/collection/TestDart.val index 1dd6bee39..bc3d1d8c4 100644 --- a/src/app/share/collection/TestDart.val +++ b/src/app/share/collection/TestDart.val @@ -1,7 +1,7 @@ - 0.3.2 + 0.2.4 cm diff --git a/src/libs/vpatterndb/vpatterninfogeometry.cpp b/src/libs/vpatterndb/vpatterninfogeometry.cpp index 11881bdbd..6de2bcc5d 100644 --- a/src/libs/vpatterndb/vpatterninfogeometry.cpp +++ b/src/libs/vpatterndb/vpatterninfogeometry.cpp @@ -90,9 +90,13 @@ int VPatternInfoGeometry::GetFontSize() const void VPatternInfoGeometry::SetFontSize(int iSize) { if (iSize >= MIN_FONT_SIZE) + { m_iFontSize = iSize; + } else + { m_iFontSize = MIN_FONT_SIZE; + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vpatternpiecedata.cpp b/src/libs/vpatterndb/vpatternpiecedata.cpp index 20b694bb0..08beb8e54 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.cpp +++ b/src/libs/vpatterndb/vpatternpiecedata.cpp @@ -152,9 +152,13 @@ int VPatternPieceData::GetFontSize() const void VPatternPieceData::SetFontSize(int iSize) { if (iSize >= MIN_FONT_SIZE) + { m_iFontSize = iSize; + } else + { m_iFontSize = MIN_FONT_SIZE; + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 71725959b..3b98e8f80 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -175,7 +175,9 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) { // don't allow resize under specific size if (fW < MIN_W || fH < m_iMinH) + { return; + } m_rectBoundingBox.setTopLeft(QPointF(0, 0)); m_rectBoundingBox.setWidth(fW); @@ -293,16 +295,14 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { QPointF pt = m_ptStartPos; rectBB.setTopLeft(pt); - QSize sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); + QSizeF sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); rectBB.setSize(sz); - if (IsContained(rectBB, rotation(), dX, dY) == false) { - sz.setWidth(sz.width() + dX); - sz.setHeight(sz.height() + dY); + if (IsContained(rectBB, rotation(), dX, dY) == true) + { + SetSize(sz.width(), sz.height()); + Update(); + emit SignalShrink(); } - - SetSize(sz.width(), sz.height()); - Update(); - emit SignalShrink(); } else if (m_eMode == mRotate) { @@ -429,7 +429,7 @@ bool VTextGraphicsItem::IsBigEnough(qreal fW, qreal fH, int iFontSize) //--------------------------------------------------------------------------------------------------------------------- QStringList VTextGraphicsItem::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm) { - QRegExp reg("\\s+"); + QRegularExpression reg("\\s+"); QStringList qslWords = qs.split(reg); QStringList qslLines; QString qsCurrent; @@ -437,7 +437,7 @@ QStringList VTextGraphicsItem::SplitString(const QString &qs, qreal fW, const QF { if (qsCurrent.length() > 0) { - qsCurrent += " "; + qsCurrent += QLatin1Literal(" "); } if (fm.width(qsCurrent + qslWords[i]) > fW) { @@ -460,9 +460,13 @@ double VTextGraphicsItem::GetAngle(QPointF pt) const double dY = pt.y() - m_ptRotCenter.y(); if (fabs(dX) < 1 && fabs(dY) < 1) + { return 0; + } else + { return atan2(dY, dX); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 647427f61..ba218355c 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -85,7 +85,7 @@ protected: double GetAngle(QPointF pt) const; signals: - void SignalMoved(QPointF ptPos); + void SignalMoved(const QPointF& ptPos); void SignalResized(qreal iTW, int iFontSize); void SignalRotated(qreal dAng); void SignalShrink(); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 70622c56e..446e41a28 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -134,12 +134,10 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(dataLabel, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMoveDetail); connect(dataLabel, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizeDetail); connect(dataLabel, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationDetail); - //connect(dataLabel, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); connect(patternInfo, &VTextGraphicsItem::SignalMoved, this, &VToolDetail::SaveMovePattern); connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern); connect(patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationPattern); - //connect(patternInfo, &VTextGraphicsItem::SignalShrink, this, &VToolDetail::UpdateAll); connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); @@ -820,7 +818,7 @@ void VToolDetail::UpdatePatternInfo() /** * @brief SaveMoveDetail saves the move detail operation to the undo stack */ -void VToolDetail::SaveMoveDetail(QPointF ptPos) +void VToolDetail::SaveMoveDetail(const QPointF& ptPos) { VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail newDet = oldDet; @@ -879,7 +877,7 @@ void VToolDetail::SaveRotationDetail(qreal dRot) /** * @brief SaveMovePattern saves the pattern label position */ -void VToolDetail::SaveMovePattern(QPointF ptPos) +void VToolDetail::SaveMovePattern(const QPointF &ptPos) { VDetail oldDet = VAbstractTool::data.GetDetail(id); VDetail newDet = oldDet; diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index d7086d5c2..a91526e05 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -111,10 +111,10 @@ protected: protected slots: virtual void UpdateLabel(); virtual void UpdatePatternInfo(); - virtual void SaveMoveDetail(QPointF ptPos); + virtual void SaveMoveDetail(const QPointF &ptPos); virtual void SaveResizeDetail(qreal dLabelW, int iFontSize); virtual void SaveRotationDetail(qreal dRot); - virtual void SaveMovePattern(QPointF ptPos); + virtual void SaveMovePattern(const QPointF& ptPos); virtual void SaveResizePattern(qreal dLabelW, int iFontSize); virtual void SaveRotationPattern(qreal dRot); From 25a58421cc39a7328877962bbfa8e325f33bd24d Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 16 Jul 2016 01:12:51 +0200 Subject: [PATCH 38/66] Added pattern size field and creation date visibility flag to pattern properties --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 4 + .../dialogs/dialogpatternproperties.ui | 27 ++++-- src/app/valentina/xml/vpattern.cpp | 8 +- src/libs/ifc/schema/pattern/v0.3.3.xsd | 2 + src/libs/ifc/xml/vabstractpattern.cpp | 45 +++++++++- src/libs/ifc/xml/vabstractpattern.h | 6 ++ src/libs/vpatterndb/vpatterndb.pri | 6 +- src/libs/vpatterndb/vpatterndb.pro | 7 -- src/libs/vtools/tools/vtextgraphicsitem.cpp | 5 +- src/libs/vtools/tools/vtooldetail.cpp | 82 +++++++++++++------ 10 files changed, 149 insertions(+), 43 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 85b96a291..7a54a0267 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -166,6 +166,8 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte ui->lineEditCompanyName->setText(doc->GetCompanyName()); ui->lineEditCustomerName->setText(doc->GetCustomerName()); ui->labelCreationDate->setText(doc->GetCreationDate().toString(Qt::SystemLocaleLongDate)); + ui->lineEditSize->setText(doc->GetPatternSize()); + ui->checkBoxShowDate->setChecked(doc->IsDateVisible()); connect(ui->lineEditPatternName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); @@ -552,6 +554,8 @@ void DialogPatternProperties::SaveGeneralInfo() doc->SetPatternNumber(ui->lineEditPatternNumber->text()); doc->SetCompanyName(ui->lineEditCompanyName->text()); doc->SetCustomerName(ui->lineEditCustomerName->text()); + doc->SetPatternSize(ui->lineEditSize->text()); + doc->SetDateVisible(ui->checkBoxShowDate->isChecked()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/dialogpatternproperties.ui b/src/app/valentina/dialogs/dialogpatternproperties.ui index 1d09d1a41..7521f8945 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.ui +++ b/src/app/valentina/dialogs/dialogpatternproperties.ui @@ -1053,7 +1053,7 @@ 10 10 401 - 171 + 221 @@ -1100,17 +1100,34 @@ - + + + + + + + + Created: - - + + - + Pattern size: + + + + + + + + + + Show date of creation diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index d83a82193..29f1fb9d3 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -139,7 +139,7 @@ void VPattern::Parse(const Document &parse) QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName - << TagCreationDate; + << TagCreationDate << TagSize << TagShowDate; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -214,6 +214,12 @@ void VPattern::Parse(const Document &parse) case 14: // TagCreationDate qCDebug(vXML, "Creation date."); break; + case 15: // TagSize + qCDebug(vXML, "Size"); + break; + case 16: + qCDebug(vXML, "Show creation date"); + break; default: qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); break; diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd index 9f622d42e..0f24bcc0c 100644 --- a/src/libs/ifc/schema/pattern/v0.3.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -23,6 +23,8 @@ + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index de5d12f41..ab85684cd 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -68,6 +68,9 @@ const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber" const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); +const QString VAbstractPattern::TagSize = QStringLiteral("size"); +const QString VAbstractPattern::TagShowDate = QStringLiteral("showDate"); + const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); @@ -1076,6 +1079,36 @@ QDate VAbstractPattern::GetCreationDate() const return QDate::currentDate(); } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractPattern::GetPatternSize() const +{ + return UniqueTagText(TagSize); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetPatternSize(QString qsSize) +{ + CheckTagExists(TagSize); + setTagText(TagSize, qsSize); + modified = true; + emit patternChanged(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractPattern::IsDateVisible() const +{ + return UniqueTagText(TagShowDate) != QStringLiteral("false"); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetDateVisible(bool bVisible) +{ + CheckTagExists(TagShowDate); + setTagText(TagShowDate, bVisible == true? QStringLiteral("true") : QStringLiteral("false")); + modified = true; + emit patternChanged(false); +} + //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPattern::GetImage() const { @@ -1178,7 +1211,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagCreationDate; + << TagCustomerName << TagCreationDate << TagSize << TagShowDate; switch (tags.indexOf(tag)) { case 0: //TagUnit @@ -1244,6 +1277,16 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) element = createElement(TagCreationDate); break; } + case 11: // TagSize + { + element = createElement(TagSize); + break; + } + case 12: // TagShowDate + { + element = createElement(TagShowDate); + break; + } default: { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 0ca26d050..c9e8d9380 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -117,6 +117,10 @@ public: QString GetCustomerName() const; void SetCustomerName(QString qsName); QDate GetCreationDate() const; + QString GetPatternSize() const; + void SetPatternSize(QString qsSize); + bool IsDateVisible() const; + void SetDateVisible(bool bVisible); QString GetImage() const; QString GetImageExtension() const; @@ -174,6 +178,8 @@ public: static const QString TagCompanyName; static const QString TagCustomerName; static const QString TagCreationDate; + static const QString TagSize; + static const QString TagShowDate; static const QString AttrName; static const QString AttrVisible; diff --git a/src/libs/vpatterndb/vpatterndb.pri b/src/libs/vpatterndb/vpatterndb.pri index b0507d074..b2e055a6e 100644 --- a/src/libs/vpatterndb/vpatterndb.pri +++ b/src/libs/vpatterndb/vpatterndb.pri @@ -18,7 +18,8 @@ SOURCES += \ $$PWD/variables/vmeasurement.cpp \ $$PWD/variables/vvariable.cpp \ $$PWD/vformula.cpp \ - $$PWD/vpatternpiecedata.cpp + $$PWD/vpatternpiecedata.cpp \ + $$PWD/vpatterninfogeometry.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -51,4 +52,5 @@ HEADERS += \ $$PWD/variables/vvariable.h \ $$PWD/variables/vvariable_p.h \ $$PWD/vformula.h \ - $$PWD/vpatternpiecedata.h + $$PWD/vpatternpiecedata.h \ + $$PWD/vpatterninfogeometry.h diff --git a/src/libs/vpatterndb/vpatterndb.pro b/src/libs/vpatterndb/vpatterndb.pro index bb5d3d0bc..28d254840 100644 --- a/src/libs/vpatterndb/vpatterndb.pro +++ b/src/libs/vpatterndb/vpatterndb.pro @@ -100,10 +100,3 @@ CONFIG(debug, debug|release){ } } } - -HEADERS += \ - vpatterninfogeometry.h - -SOURCES += \ - vpatterninfogeometry.cpp - diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 3b98e8f80..7380f65c9 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "../vmisc/def.h" @@ -311,7 +312,7 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) m_dAngle = GetAngle(pME->scenePos()); return; } - double dAng = 180*(GetAngle(pME->scenePos()) - m_dAngle)/M_PI; + double dAng = qRadiansToDegrees(GetAngle(pME->scenePos()) - m_dAngle); rectBB.setTopLeft(m_ptStartPos); rectBB.setWidth(m_rectBoundingBox.width()); rectBB.setHeight(m_rectBoundingBox.height()); @@ -480,7 +481,7 @@ QRectF VTextGraphicsItem::GetBoundingRect(QRectF rectBB, qreal dRot) const qreal dY1 = 0; qreal dY2 = 0; - double dAng = M_PI*dRot/180; + double dAng = qDegreesToRadians(dRot); for (int i = 0; i < 4; ++i) { QPointF pt = apt[i] - ptCenter; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 446e41a28..c89cc6970 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -689,16 +689,25 @@ void VToolDetail::UpdateLabel() TextLine tl; // letter tl.m_qsText = data.GetLetter(); - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::Bold; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 6; - dataLabel->AddLine(tl); + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eAlign = Qt::AlignCenter; + tl.m_eFontWeight = QFont::Bold; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 6; + dataLabel->AddLine(tl); + } + + // name tl.m_qsText = detail.getName(); - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::DemiBold; - tl.m_iFontSize = 2; - dataLabel->AddLine(tl); + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eAlign = Qt::AlignCenter; + tl.m_eFontWeight = QFont::DemiBold; + tl.m_iFontSize = 2; + dataLabel->AddLine(tl); + } + // MCP tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; tl.m_eFontWeight = QFont::Normal; @@ -761,33 +770,56 @@ void VToolDetail::UpdatePatternInfo() // Company name tl.m_qsText = doc->GetCompanyName(); - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::DemiBold; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 4; - patternInfo->AddLine(tl); + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eAlign = Qt::AlignCenter; + tl.m_eFontWeight = QFont::DemiBold; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 4; + patternInfo->AddLine(tl); + } // Pattern name tl.m_qsText = doc->GetPatternName(); - tl.m_eFontWeight = QFont::Normal; - tl.m_iFontSize = 2; - patternInfo->AddLine(tl); + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eFontWeight = QFont::Normal; + tl.m_iFontSize = 2; + patternInfo->AddLine(tl); + } // Pattern number tl.m_qsText = doc->GetPatternNumber(); - tl.m_iFontSize = 0; - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - patternInfo->AddLine(tl); + if (tl.m_qsText.isEmpty() == false) + { + tl.m_iFontSize = 0; + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + patternInfo->AddLine(tl); + } // Customer name tl.m_qsText = doc->GetCustomerName(); - tl.m_eStyle = QFont::StyleItalic; - patternInfo->AddLine(tl); + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eStyle = QFont::StyleItalic; + patternInfo->AddLine(tl); + } + + // Size + tl.m_qsText = doc->GetPatternSize(); + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eStyle = QFont::StyleNormal; + patternInfo->AddLine(tl); + } // Creation date - QStringList qslDate = doc->GetCreationDate().toString(Qt::SystemLocaleLongDate).split(", "); - tl.m_qsText = qslDate.last(); - patternInfo->AddLine(tl); + if (doc->IsDateVisible() == true) + { + QStringList qslDate = doc->GetCreationDate().toString(Qt::SystemLocaleLongDate).split(", "); + tl.m_qsText = qslDate.last(); + patternInfo->AddLine(tl); + } QPointF pt = geom.GetPos(); QRectF rectBB; From fed323fc25563794932664339bade25322a41357 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 17 Jul 2016 22:52:53 +0200 Subject: [PATCH 39/66] Labels are now shown on the layout, however I still need to figure out how to paste text into the labels --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 12 ++++ src/libs/vlayout/vlayoutdetail.cpp | 77 ++++++++++++++++++++++++++ src/libs/vlayout/vlayoutdetail.h | 8 +++ src/libs/vlayout/vlayoutdetail_p.h | 10 +++- 4 files changed, 105 insertions(+), 2 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index b3e6b9e72..b0471a14f 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -37,6 +37,8 @@ #include "dialogs/dialoglayoutprogress.h" #include "dialogs/dialogsavelayout.h" #include "../vlayout/vposter.h" +#include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vpatterninfogeometry.h" #include #include @@ -472,6 +474,16 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de det.SetCountourPoints(d.ContourPoints(pattern)); det.SetSeamAllowencePoints(d.SeamAllowancePoints(pattern), d.getSeamAllowance(), d.getClosed()); det.setName(d.getName()); + const VPatternPieceData& data = d.GetPatternPieceData(); + if (data.IsVisible() == true) + { + det.SetDetailLabelPoints(data.GetPos(), data.GetLabelWidth(), data.GetLabelHeight(), data.GetRotation()); + } + const VPatternInfoGeometry& geom = d.GetPatternInfo(); + if (geom.IsVisible() == true) + { + det.SetPatternInfoPoints(geom.GetPos(), geom.GetLabelWidth(), geom.GetLabelHeight(), geom.GetRotation()); + } det.setWidth(qApp->toPixel(d.getWidth())); listDetails.append(det); diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index 7cf91035a..a5fc4971b 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -112,6 +112,44 @@ QVector VLayoutDetail::GetLayoutAllowencePoints() const return Map(d->layoutAllowence); } +//--------------------------------------------------------------------------------------------------------------------- +QVector VLayoutDetail::GetDetailLabelPoints() const +{ + return d->detailLabel; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutDetail::SetDetailLabelPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot) +{ + qreal dAng = qDegreesToRadians(dRot); + QPointF ptCenter(ptPos.x() + dWidth/2, ptPos.y() + dHeight/2); + QVector v; + v << ptPos << QPointF(ptPos.x() + dWidth, ptPos.y()) << QPointF(ptPos.x() + dWidth, ptPos.y() + dHeight) + << QPointF(ptPos.x(), ptPos.y() + dHeight) << ptPos; + for (int i = 0; i < v.count(); ++i) + v[i] = RotatePoint(ptCenter, v[i], dAng); + d->detailLabel = RoundPoints(v); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVector VLayoutDetail::GetPatternInfoPoints() const +{ + return d->patternInfo; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutDetail::SetPatternInfoPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot) +{ + qreal dAng = qDegreesToRadians(dRot); + QPointF ptCenter(ptPos.x() + dWidth/2, ptPos.y() + dHeight/2); + QVector v; + v << ptPos << QPointF(ptPos.x() + dWidth, ptPos.y()) << QPointF(ptPos.x() + dWidth, ptPos.y() + dHeight) + << QPointF(ptPos.x(), ptPos.y() + dHeight) << ptPos; + for (int i = 0; i < v.count(); ++i) + v[i] = RotatePoint(ptCenter, v[i], dAng); + d->patternInfo = RoundPoints(v); +} + //--------------------------------------------------------------------------------------------------------------------- QTransform VLayoutDetail::GetMatrix() const { @@ -420,6 +458,34 @@ QPainterPath VLayoutDetail::ContourPath() const path.setFillRule(Qt::WindingFill); } + if (d->detailLabel.count() > 0) + { + points = Map(d->detailLabel); + + QPainterPath pathDet; + pathDet.moveTo(points.at(0)); + for (qint32 i = 1; i < points.count(); ++i) + { + pathDet.lineTo(points.at(i)); + } + + path.addPath(pathDet); + } + + if (d->patternInfo.count() > 0) + { + points = Map(d->patternInfo); + + QPainterPath pathDet; + pathDet.moveTo(points.at(0)); + for (qint32 i = 1; i < points.count(); ++i) + { + pathDet.lineTo(points.at(i)); + } + + path.addPath(pathDet); + } + return path; } @@ -459,3 +525,14 @@ void VLayoutDetail::SetMirror(bool value) { d->mirror = value; } + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) +{ + QPointF ptDest; + QPointF ptRel = pt - ptCenter; + ptDest.setX(cos(dAng)*ptRel.x() - sin(dAng)*ptRel.y()); + ptDest.setY(sin(dAng)*ptRel.x() + cos(dAng)*ptRel.y()); + + return ptDest + ptCenter; +} diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index 2e75159ad..8358dbbf4 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -54,6 +54,12 @@ public: QVector GetLayoutAllowencePoints() const; void SetLayoutAllowencePoints(); + QVector GetDetailLabelPoints() const; + void SetDetailLabelPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot); + + QVector GetPatternInfoPoints() const; + void SetPatternInfoPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot); + QTransform GetMatrix() const; void SetMatrix(const QTransform &matrix); @@ -86,6 +92,8 @@ private: QVector Map(const QVector &points) const; static QVector RoundPoints(const QVector &points); + + QPointF RotatePoint(const QPointF& ptCenter, const QPointF& pt, qreal dAng); }; Q_DECLARE_TYPEINFO(VLayoutDetail, Q_MOVABLE_TYPE); diff --git a/src/libs/vlayout/vlayoutdetail_p.h b/src/libs/vlayout/vlayoutdetail_p.h index 8a008ac80..1a2e00147 100644 --- a/src/libs/vlayout/vlayoutdetail_p.h +++ b/src/libs/vlayout/vlayoutdetail_p.h @@ -44,13 +44,14 @@ class VLayoutDetailData : public QSharedData public: VLayoutDetailData() :contour(QVector()), seamAllowence(QVector()), layoutAllowence(QVector()), - matrix(QMatrix()), layoutWidth(0), mirror(false) + matrix(QMatrix()), layoutWidth(0), mirror(false), detailLabel(QVector()), + patternInfo(QVector()) {} VLayoutDetailData(const VLayoutDetailData &detail) :QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence), layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), layoutWidth(detail.layoutWidth), - mirror(detail.mirror) + mirror(detail.mirror), detailLabel(detail.detailLabel), patternInfo(detail.patternInfo) {} ~VLayoutDetailData() {} @@ -72,6 +73,11 @@ public: bool mirror; + /** @brief detail label rectangle */ + QVector detailLabel; + /** @brief pattern info rectangle */ + QVector patternInfo; + private: VLayoutDetailData &operator=(const VLayoutDetailData &) Q_DECL_EQ_DELETE; }; From 0ea76c5914f698a71d680f3e0b28b278bd289c1f Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Mon, 18 Jul 2016 20:38:27 +0200 Subject: [PATCH 40/66] Few changes at vlayoutdetail class --HG-- branch : feature --- src/libs/vlayout/vlayoutdetail.cpp | 10 +++++++--- src/libs/vlayout/vlayoutdetail.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index a5fc4971b..69eee267b 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -31,6 +31,7 @@ #include #include +#include #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../vmisc/vmath.h" @@ -125,7 +126,7 @@ void VLayoutDetail::SetDetailLabelPoints(const QPointF& ptPos, qreal dWidth, qre QPointF ptCenter(ptPos.x() + dWidth/2, ptPos.y() + dHeight/2); QVector v; v << ptPos << QPointF(ptPos.x() + dWidth, ptPos.y()) << QPointF(ptPos.x() + dWidth, ptPos.y() + dHeight) - << QPointF(ptPos.x(), ptPos.y() + dHeight) << ptPos; + << QPointF(ptPos.x(), ptPos.y() + dHeight); for (int i = 0; i < v.count(); ++i) v[i] = RotatePoint(ptCenter, v[i], dAng); d->detailLabel = RoundPoints(v); @@ -144,7 +145,7 @@ void VLayoutDetail::SetPatternInfoPoints(const QPointF& ptPos, qreal dWidth, qre QPointF ptCenter(ptPos.x() + dWidth/2, ptPos.y() + dHeight/2); QVector v; v << ptPos << QPointF(ptPos.x() + dWidth, ptPos.y()) << QPointF(ptPos.x() + dWidth, ptPos.y() + dHeight) - << QPointF(ptPos.x(), ptPos.y() + dHeight) << ptPos; + << QPointF(ptPos.x(), ptPos.y() + dHeight); for (int i = 0; i < v.count(); ++i) v[i] = RotatePoint(ptCenter, v[i], dAng); d->patternInfo = RoundPoints(v); @@ -461,6 +462,7 @@ QPainterPath VLayoutDetail::ContourPath() const if (d->detailLabel.count() > 0) { points = Map(d->detailLabel); + points.push_back(points.at(0)); QPainterPath pathDet; pathDet.moveTo(points.at(0)); @@ -475,6 +477,7 @@ QPainterPath VLayoutDetail::ContourPath() const if (d->patternInfo.count() > 0) { points = Map(d->patternInfo); + points.push_back(points.at(0)); QPainterPath pathDet; pathDet.moveTo(points.at(0)); @@ -527,7 +530,7 @@ void VLayoutDetail::SetMirror(bool value) } //--------------------------------------------------------------------------------------------------------------------- -QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) +QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) const { QPointF ptDest; QPointF ptRel = pt - ptCenter; @@ -536,3 +539,4 @@ QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, q return ptDest + ptCenter; } + diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index 8358dbbf4..59b7fd53a 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -93,7 +93,7 @@ private: QVector Map(const QVector &points) const; static QVector RoundPoints(const QVector &points); - QPointF RotatePoint(const QPointF& ptCenter, const QPointF& pt, qreal dAng); + QPointF RotatePoint(const QPointF& ptCenter, const QPointF& pt, qreal dAng) const; }; Q_DECLARE_TYPEINFO(VLayoutDetail, Q_MOVABLE_TYPE); From 363714985cea94c25303980c65308bb8bd5d11f3 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Mon, 18 Jul 2016 21:02:02 +0200 Subject: [PATCH 41/66] Merging --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 3 --- src/app/valentina/dialogs/dialogpatternproperties.h | 4 ---- 2 files changed, 7 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 7e4020484..b4c0c7d3e 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -392,7 +392,6 @@ void DialogPatternProperties::DescEdited() } //--------------------------------------------------------------------------------------------------------------------- -<<<<<<< local void DialogPatternProperties::ToggleComboBox() { ui->comboBoxHeight->setEnabled(ui->radioButtonDefFromP->isChecked()); @@ -418,8 +417,6 @@ void DialogPatternProperties::GeneralInfoChanged() } //--------------------------------------------------------------------------------------------------------------------- -======= ->>>>>>> other void DialogPatternProperties::SetHeightsChecked(bool enabled) { ui->checkBoxH92->setChecked(enabled); diff --git a/src/app/valentina/dialogs/dialogpatternproperties.h b/src/app/valentina/dialogs/dialogpatternproperties.h index 92b8beb6c..0c26a8661 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.h +++ b/src/app/valentina/dialogs/dialogpatternproperties.h @@ -52,13 +52,10 @@ public: signals: void UpdateGradation(); private slots: -<<<<<<< local void ToggleComboBox(); void DefValueChanged(); void SecurityValueChanged(); void GeneralInfoChanged(); - void DeleteImage(); -======= void Apply(); void Ok(); void SelectAll(int state); @@ -66,7 +63,6 @@ private slots: void CheckStateSize(int state); void DescEdited(); void ChangeImage(); ->>>>>>> other void SaveImage(); private: Q_DISABLE_COPY(DialogPatternProperties) From c9ee648cb80ea0cb12ca46a8fe725d87a9844f4b Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Mon, 18 Jul 2016 22:30:14 +0200 Subject: [PATCH 42/66] Refactored the text managing in labels --HG-- branch : feature --- src/libs/vtools/tools/tools.pri | 6 +- src/libs/vtools/tools/vtextgraphicsitem.cpp | 95 ++++-------------- src/libs/vtools/tools/vtextgraphicsitem.h | 18 +--- src/libs/vtools/tools/vtextmanager.cpp | 106 ++++++++++++++++++++ src/libs/vtools/tools/vtextmanager.h | 47 +++++++++ 5 files changed, 176 insertions(+), 96 deletions(-) create mode 100644 src/libs/vtools/tools/vtextmanager.cpp create mode 100644 src/libs/vtools/tools/vtextmanager.h diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 0391ca475..f40f507c5 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -51,7 +51,8 @@ HEADERS += \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \ $$PWD/drawTools/operation/vtoolrotation.h \ - $$PWD/vtextgraphicsitem.h + $$PWD/vtextgraphicsitem.h \ + $$PWD/vtextmanager.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -100,4 +101,5 @@ SOURCES += \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \ $$PWD/drawTools/operation/vtoolrotation.cpp \ - $$PWD/vtextgraphicsitem.cpp + $$PWD/vtextgraphicsitem.cpp \ + $$PWD/vtextmanager.cpp diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 7380f65c9..eeee34aee 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -44,23 +44,13 @@ #define ROTATE_ARC 50 #define MIN_W 120 #define MIN_H 60 -#define MIN_FONT_SIZE 12 -#define MAX_FONT_SIZE 128 -#define SPACING 2 #define TOP_Z 2 -//--------------------------------------------------------------------------------------------------------------------- -TextLine::TextLine() - :m_qsText(), m_iFontSize(MIN_FONT_SIZE), m_eFontWeight(QFont::Normal), m_eStyle(QFont::StyleNormal), - m_eAlign(Qt::AlignCenter), m_iHeight(0) -{} - //--------------------------------------------------------------------------------------------------------------------- VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) :QGraphicsObject(pParent), m_eMode(VTextGraphicsItem::mNormal), m_bReleased(false), m_ptStartPos(), m_ptStart(), m_ptRotCenter(), m_szStart(), m_dRotation(0), m_dAngle(0), - m_rectResize(), m_iMinH(MIN_H), m_rectBoundingBox(), m_font(), m_liLines(), m_liOutput() - + m_rectResize(), m_iMinH(MIN_H), m_rectBoundingBox(), m_tm() { m_rectBoundingBox.setTopLeft(QPointF(0, 0)); SetSize(MIN_W, m_iMinH); @@ -74,7 +64,7 @@ VTextGraphicsItem::~VTextGraphicsItem() //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::SetFont(const QFont& fnt) { - m_font = fnt; + m_tm.SetFont(fnt); } //--------------------------------------------------------------------------------------------------------------------- @@ -88,17 +78,17 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem int iY = 0; int iH = 0; painter->setPen(Qt::black); - QFont fnt = m_font; - for (int i = 0; i < m_liOutput.count(); ++i) + QFont fnt = m_tm.GetFont(); + for (int i = 0; i < m_tm.GetCount(); ++i) { - const TextLine& tl = m_liOutput.at(i); + const TextLine& tl = m_tm.GetLine(i); iH = tl.m_iHeight; - fnt.setPixelSize(m_font.pixelSize() + tl.m_iFontSize); + fnt.setPixelSize(m_tm.GetFont().pixelSize() + tl.m_iFontSize); fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); painter->setFont(fnt); painter->drawText(0, iY, qRound(boundingRect().width()), iH, tl.m_eAlign, tl.m_qsText); - iY += iH + SPACING; + iY += iH + m_tm.GetSpacing(); } @@ -154,8 +144,8 @@ void VTextGraphicsItem::Reset() //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::AddLine(const TextLine& tl) { - m_liLines << tl; - while (IsBigEnough(MIN_W, m_iMinH, MIN_FONT_SIZE) == false) + m_tm.AddLine(tl); + while (m_tm.IsBigEnough(MIN_W, m_iMinH, MIN_FONT_SIZE) == false) { m_iMinH += 5; } @@ -168,7 +158,7 @@ void VTextGraphicsItem::AddLine(const TextLine& tl) //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::Clear() { - m_liLines.clear(); + m_tm.Clear(); } //--------------------------------------------------------------------------------------------------------------------- @@ -233,7 +223,7 @@ bool VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal //--------------------------------------------------------------------------------------------------------------------- int VTextGraphicsItem::GetFontSize() const { - return m_font.pixelSize(); + return m_tm.GetFont().pixelSize(); } //--------------------------------------------------------------------------------------------------------------------- @@ -357,7 +347,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } else { - emit SignalResized(m_rectBoundingBox.width(), m_font.pixelSize()); + emit SignalResized(m_rectBoundingBox.width(), m_tm.GetFont().pixelSize()); Update(); } } @@ -387,73 +377,22 @@ void VTextGraphicsItem::UpdateBox() //--------------------------------------------------------------------------------------------------------------------- void VTextGraphicsItem::UpdateFont() { - int iFS = m_font.pixelSize(); + int iFS = m_tm.GetFont().pixelSize(); // increase the font size until the bounding rect is not big enough - while (iFS < MAX_FONT_SIZE && IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS) == true) + while (iFS < MAX_FONT_SIZE && m_tm.IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS) == true) { ++iFS; } // decrease the font size until the bounding rect is big enough - while (iFS >= MIN_FONT_SIZE && IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS) == false) + while (iFS >= MIN_FONT_SIZE && m_tm.IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS) == false) { --iFS; } - m_font.setPixelSize(iFS); + m_tm.SetFontSize(iFS); UpdateBox(); } -//--------------------------------------------------------------------------------------------------------------------- -bool VTextGraphicsItem::IsBigEnough(qreal fW, qreal fH, int iFontSize) -{ - m_liOutput.clear(); - QFont fnt = m_font; - int iY = 0; - for (int i = 0; i < m_liLines.count(); ++i) - { - const TextLine& tl = m_liLines.at(i); - TextLine tlOut = tl; - fnt.setPixelSize(iFontSize + tl.m_iFontSize); - QFontMetrics fm(fnt); - tlOut.m_iHeight = fm.height(); - QStringList qslLines = SplitString(tlOut.m_qsText, fW, fm); - for (int iL = 0; iL < qslLines.count(); ++iL) - { - tlOut.m_qsText = qslLines[iL]; - m_liOutput << tlOut; - iY += tlOut.m_iHeight + SPACING; - } - } - return iY < fH; -} - -//--------------------------------------------------------------------------------------------------------------------- -QStringList VTextGraphicsItem::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm) -{ - QRegularExpression reg("\\s+"); - QStringList qslWords = qs.split(reg); - QStringList qslLines; - QString qsCurrent; - for (int i = 0; i < qslWords.count(); ++i) - { - if (qsCurrent.length() > 0) - { - qsCurrent += QLatin1Literal(" "); - } - if (fm.width(qsCurrent + qslWords[i]) > fW) - { - qslLines << qsCurrent; - qsCurrent = qslWords[i]; - } - else - { - qsCurrent += qslWords[i]; - } - } - qslLines << qsCurrent; - return qslLines; -} - //--------------------------------------------------------------------------------------------------------------------- double VTextGraphicsItem::GetAngle(QPointF pt) const { @@ -466,7 +405,7 @@ double VTextGraphicsItem::GetAngle(QPointF pt) const } else { - return atan2(dY, dX); + return qAtan2(dY, dX); } } diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index ba218355c..7ee41aabe 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -33,17 +33,7 @@ #include #include -struct TextLine -{ - QString m_qsText; - int m_iFontSize; // 0 means default - QFont::Weight m_eFontWeight; - QFont::Style m_eStyle; - Qt::Alignment m_eAlign; - int m_iHeight; - - TextLine(); -}; +#include "vtextmanager.h" class VTextGraphicsItem : public QGraphicsObject { @@ -79,8 +69,6 @@ protected: void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME); void UpdateBox(); void UpdateFont(); - bool IsBigEnough(qreal fW, qreal fH, int iFontSize); - QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); double GetAngle(QPointF pt) const; @@ -102,9 +90,7 @@ private: QRectF m_rectResize; int m_iMinH; QRectF m_rectBoundingBox; - QFont m_font; - QList m_liLines; - QList m_liOutput; + VTextManager m_tm; QRectF GetBoundingRect(QRectF rectBB, qreal dRot) const; }; diff --git a/src/libs/vtools/tools/vtextmanager.cpp b/src/libs/vtools/tools/vtextmanager.cpp new file mode 100644 index 000000000..4724f82f3 --- /dev/null +++ b/src/libs/vtools/tools/vtextmanager.cpp @@ -0,0 +1,106 @@ +#include +#include + +#include "vtextmanager.h" + +//--------------------------------------------------------------------------------------------------------------------- +TextLine::TextLine() + :m_qsText(), m_iFontSize(MIN_FONT_SIZE), m_eFontWeight(QFont::Normal), m_eStyle(QFont::StyleNormal), + m_eAlign(Qt::AlignCenter), m_iHeight(0) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VTextManager::VTextManager() + :m_liLines(), m_liOutput() +{} + +//--------------------------------------------------------------------------------------------------------------------- +VTextManager::~VTextManager() +{} + +//--------------------------------------------------------------------------------------------------------------------- +int VTextManager::GetSpacing() const +{ return 2; } + + +//--------------------------------------------------------------------------------------------------------------------- +void VTextManager::SetFont(const QFont& font) +{ m_font = font; } + +//--------------------------------------------------------------------------------------------------------------------- +const QFont& VTextManager::GetFont() const +{ return m_font; } + +//--------------------------------------------------------------------------------------------------------------------- +void VTextManager::SetFontSize(int iFS) +{ m_font.setPixelSize(iFS); } + +//--------------------------------------------------------------------------------------------------------------------- +void VTextManager::AddLine(const TextLine& tl) +{ m_liLines << tl; } + +//--------------------------------------------------------------------------------------------------------------------- +void VTextManager::Clear() +{ m_liLines.clear(); } + +//--------------------------------------------------------------------------------------------------------------------- +int VTextManager::GetCount() const +{ return m_liOutput.count(); } + +//--------------------------------------------------------------------------------------------------------------------- +const TextLine& VTextManager::GetLine(int i) const +{ return m_liOutput[i]; } + +//--------------------------------------------------------------------------------------------------------------------- +bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) +{ + m_liOutput.clear(); + QFont fnt = m_font; + int iY = 0; + for (int i = 0; i < m_liLines.count(); ++i) + { + const TextLine& tl = m_liLines.at(i); + TextLine tlOut = tl; + fnt.setPixelSize(iFontSize + tl.m_iFontSize); + QFontMetrics fm(fnt); + tlOut.m_iHeight = fm.height(); + QStringList qslLines = SplitString(tlOut.m_qsText, fW, fm); + for (int iL = 0; iL < qslLines.count(); ++iL) + { + tlOut.m_qsText = qslLines[iL]; + m_liOutput << tlOut; + iY += tlOut.m_iHeight + GetSpacing(); + } + } + return iY < fH; +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm) +{ + QRegularExpression reg("\\s+"); + QStringList qslWords = qs.split(reg); + QStringList qslLines; + QString qsCurrent; + for (int i = 0; i < qslWords.count(); ++i) + { + if (qsCurrent.length() > 0) + { + qsCurrent += QLatin1Literal(" "); + } + if (fm.width(qsCurrent + qslWords[i]) > fW) + { + qslLines << qsCurrent; + qsCurrent = qslWords[i]; + } + else + { + qsCurrent += qslWords[i]; + } + } + qslLines << qsCurrent; + return qslLines; +} + + + diff --git a/src/libs/vtools/tools/vtextmanager.h b/src/libs/vtools/tools/vtextmanager.h new file mode 100644 index 000000000..3ee8e8183 --- /dev/null +++ b/src/libs/vtools/tools/vtextmanager.h @@ -0,0 +1,47 @@ +#ifndef VTEXTMANAGER_H +#define VTEXTMANAGER_H + +#include +#include + +#define MIN_FONT_SIZE 12 +#define MAX_FONT_SIZE 128 + +struct TextLine +{ + QString m_qsText; + int m_iFontSize; // 0 means default + QFont::Weight m_eFontWeight; + QFont::Style m_eStyle; + Qt::Alignment m_eAlign; + int m_iHeight; + + TextLine(); +}; + +class VTextManager +{ +public: + VTextManager(); + ~VTextManager(); + + int GetSpacing() const; + void SetFont(const QFont& font); + const QFont& GetFont() const; + void SetFontSize(int iFS); + void AddLine(const TextLine& tl); + void Clear(); + int GetCount() const; + const TextLine& GetLine(int i) const; + bool IsBigEnough(qreal fW, qreal fH, int iFontSize); + +protected: + QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); + +private: + QFont m_font; + QList m_liLines; + QList m_liOutput; +}; + +#endif // VTEXTMANAGER_H From 9368978039c12337bdbbfacfd302f7892a9184e3 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 19 Jul 2016 02:26:50 +0200 Subject: [PATCH 43/66] Added detail texts to layout mode --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 2 +- src/libs/vlayout/vlayoutdetail.cpp | 136 ++++++++++++++++++++++--- src/libs/vlayout/vlayoutdetail.h | 10 +- src/libs/vlayout/vlayoutdetail_p.h | 9 +- src/libs/vtools/tools/vtextmanager.cpp | 39 +++++-- src/libs/vtools/tools/vtextmanager.h | 1 + src/libs/vtools/tools/vtooldetail.cpp | 3 +- 7 files changed, 169 insertions(+), 31 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index eb359d25a..d2cecb66d 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -477,7 +477,7 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de const VPatternPieceData& data = d.GetPatternPieceData(); if (data.IsVisible() == true) { - det.SetDetailLabelPoints(data.GetPos(), data.GetLabelWidth(), data.GetLabelHeight(), data.GetRotation()); + det.SetDetail(d.getName(), data); } const VPatternInfoGeometry& geom = d.GetPatternInfo(); if (geom.IsVisible() == true) diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index 69eee267b..251fd2269 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../vmisc/vmath.h" @@ -43,12 +45,12 @@ //--------------------------------------------------------------------------------------------------------------------- VLayoutDetail::VLayoutDetail() - :VAbstractDetail(), d(new VLayoutDetailData) + :VAbstractDetail(), d(new VLayoutDetailData), m_tmDetail() {} //--------------------------------------------------------------------------------------------------------------------- VLayoutDetail::VLayoutDetail(const VLayoutDetail &detail) - :VAbstractDetail(detail), d (detail.d) + :VAbstractDetail(detail), d(detail.d), m_tmDetail(detail.m_tmDetail) {} //--------------------------------------------------------------------------------------------------------------------- @@ -60,6 +62,7 @@ VLayoutDetail &VLayoutDetail::operator=(const VLayoutDetail &detail) } VAbstractDetail::operator=(detail); d = detail.d; + m_tmDetail = detail.m_tmDetail; return *this; } @@ -114,22 +117,63 @@ QVector VLayoutDetail::GetLayoutAllowencePoints() const } //--------------------------------------------------------------------------------------------------------------------- -QVector VLayoutDetail::GetDetailLabelPoints() const +void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& data) { - return d->detailLabel; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VLayoutDetail::SetDetailLabelPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot) -{ - qreal dAng = qDegreesToRadians(dRot); - QPointF ptCenter(ptPos.x() + dWidth/2, ptPos.y() + dHeight/2); + d->detailData = data; + qreal dAng = qDegreesToRadians(data.GetRotation()); + QPointF ptCenter(data.GetPos().x() + data.GetLabelWidth()/2, data.GetPos().y() + data.GetLabelHeight()/2); + QPointF ptPos = data.GetPos(); QVector v; - v << ptPos << QPointF(ptPos.x() + dWidth, ptPos.y()) << QPointF(ptPos.x() + dWidth, ptPos.y() + dHeight) - << QPointF(ptPos.x(), ptPos.y() + dHeight); + v << ptPos << QPointF(ptPos.x() + data.GetLabelWidth(), ptPos.y()) + << QPointF(ptPos.x() + data.GetLabelWidth(), ptPos.y() + data.GetLabelHeight()) + << QPointF(ptPos.x(), ptPos.y() + data.GetLabelHeight()); for (int i = 0; i < v.count(); ++i) v[i] = RotatePoint(ptCenter, v[i], dAng); d->detailLabel = RoundPoints(v); + + // generate text + QFont fnt = QApplication::font(); + m_tmDetail.SetFont(fnt); + m_tmDetail.SetFontSize(data.GetFontSize()); + m_tmDetail.Clear(); + TextLine tl; + // letter + tl.m_qsText = data.GetLetter(); + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eAlign = Qt::AlignCenter; + tl.m_eFontWeight = QFont::Bold; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 6; + m_tmDetail.AddLine(tl); + } + // name + if (qsName.isEmpty() == false) + { + tl.m_qsText = qsName; + tl.m_eFontWeight = QFont::DemiBold; + tl.m_iFontSize = 2; + m_tmDetail.AddLine(tl); + } + + // MCP + QString qsText = "Cut %1 of %2%3"; + QStringList qslPlace; + qslPlace << "" << " on Fold"; + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + tl.m_eFontWeight = QFont::Normal; + tl.m_iFontSize = 0; + for (int i = 0; i < data.GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = data.GetMCP(i); + if (mcp.m_iCutNumber > 0) + { + tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]); + m_tmDetail.AddLine(tl); + } + } + // will generate the lines of text + m_tmDetail.IsBigEnough(data.GetLabelWidth(), data.GetLabelHeight(), data.GetFontSize()); } //--------------------------------------------------------------------------------------------------------------------- @@ -461,7 +505,7 @@ QPainterPath VLayoutDetail::ContourPath() const if (d->detailLabel.count() > 0) { - points = Map(d->detailLabel); + points = Map(Mirror(d->detailLabel)); points.push_back(points.at(0)); QPainterPath pathDet; @@ -472,11 +516,46 @@ QPainterPath VLayoutDetail::ContourPath() const } path.addPath(pathDet); + + + qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x()); + qreal dW = GetDistance(points.at(0), points.at(1)); + qreal dY = 0; + qreal dX; + for (int i = 0; i < m_tmDetail.GetCount(); ++i) + { + const TextLine& tl = m_tmDetail.GetLine(i); + QFont fnt = m_tmDetail.GetFont(); + fnt.setPixelSize(m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize); + fnt.setWeight(tl.m_eFontWeight); + fnt.setStyle(tl.m_eStyle); + dY += tl.m_iHeight; + QMatrix mat; + mat.translate(points.at(0).x(), points.at(0).y()); + mat.rotate(qRadiansToDegrees(dAng)); + QFontMetrics fm(fnt); + if ((tl.m_eAlign & Qt::AlignLeft) > 0) + { + dX = 0; + } + else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) + { + dX = (dW - fm.width(tl.m_qsText))/2; + } + else + { + dX = dW - fm.width(tl.m_qsText); + } + QPainterPath pathText; + pathText.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, tl.m_qsText); + path.addPath(mat.map(pathText)); + dY += m_tmDetail.GetSpacing(); + } } if (d->patternInfo.count() > 0) { - points = Map(d->patternInfo); + points = Map(Mirror(d->patternInfo)); points.push_back(points.at(0)); QPainterPath pathDet; @@ -540,3 +619,30 @@ QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, q return ptDest + ptCenter; } +//--------------------------------------------------------------------------------------------------------------------- +QVector VLayoutDetail::Mirror(const QVector &points) const +{ + // should only call this method with rectangular shapes + Q_ASSERT(points.count() == 4); + if (d->mirror == false) + { + return points; + } + + QVector v; + v.resize(4); + v[0] = points.at(2); + v[1] = points.at(3); + v[2] = points.at(0); + v[3] = points.at(1); + return v; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VLayoutDetail::GetDistance(const QPointF &pt1, const QPointF &pt2) const +{ + qreal dX = pt1.x() - pt2.x(); + qreal dY = pt1.y() - pt2.y(); + + return qSqrt(dX*dX + dY*dY); +} diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index 59b7fd53a..b639420b9 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -30,6 +30,8 @@ #define VLAYOUTDETAIL_H #include "vabstractdetail.h" +#include "../vpatterndb/vpatternpiecedata.h" +#include "../vtools/tools/vtextmanager.h" #include #include @@ -54,8 +56,7 @@ public: QVector GetLayoutAllowencePoints() const; void SetLayoutAllowencePoints(); - QVector GetDetailLabelPoints() const; - void SetDetailLabelPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot); + void SetDetail(const QString &qsName, const VPatternPieceData& data); QVector GetPatternInfoPoints() const; void SetPatternInfoPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot); @@ -88,12 +89,15 @@ public: QGraphicsItem *GetItem() const Q_REQUIRED_RESULT; private: - QSharedDataPointer d; + QSharedDataPointer d; + VTextManager m_tmDetail; QVector Map(const QVector &points) const; static QVector RoundPoints(const QVector &points); QPointF RotatePoint(const QPointF& ptCenter, const QPointF& pt, qreal dAng) const; + QVector Mirror(const QVector& points) const; + qreal GetDistance(const QPointF& pt1, const QPointF& pt2) const; }; Q_DECLARE_TYPEINFO(VLayoutDetail, Q_MOVABLE_TYPE); diff --git a/src/libs/vlayout/vlayoutdetail_p.h b/src/libs/vlayout/vlayoutdetail_p.h index 1a2e00147..d7fe95d53 100644 --- a/src/libs/vlayout/vlayoutdetail_p.h +++ b/src/libs/vlayout/vlayoutdetail_p.h @@ -34,6 +34,8 @@ #include #include +#include "../vpatterndb/vpatternpiecedata.h" + #ifdef Q_CC_GNU #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Weffc++" @@ -45,13 +47,14 @@ public: VLayoutDetailData() :contour(QVector()), seamAllowence(QVector()), layoutAllowence(QVector()), matrix(QMatrix()), layoutWidth(0), mirror(false), detailLabel(QVector()), - patternInfo(QVector()) + patternInfo(QVector()), detailData() {} VLayoutDetailData(const VLayoutDetailData &detail) :QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence), layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), layoutWidth(detail.layoutWidth), - mirror(detail.mirror), detailLabel(detail.detailLabel), patternInfo(detail.patternInfo) + mirror(detail.mirror), detailLabel(detail.detailLabel), patternInfo(detail.patternInfo), + detailData(detail.detailData) {} ~VLayoutDetailData() {} @@ -77,6 +80,8 @@ public: QVector detailLabel; /** @brief pattern info rectangle */ QVector patternInfo; + /** @brief detail data */ + VPatternPieceData detailData; private: VLayoutDetailData &operator=(const VLayoutDetailData &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vtools/tools/vtextmanager.cpp b/src/libs/vtools/tools/vtextmanager.cpp index 4724f82f3..328457fcc 100644 --- a/src/libs/vtools/tools/vtextmanager.cpp +++ b/src/libs/vtools/tools/vtextmanager.cpp @@ -20,36 +20,57 @@ VTextManager::~VTextManager() //--------------------------------------------------------------------------------------------------------------------- int VTextManager::GetSpacing() const -{ return 2; } - +{ + return 2; +} //--------------------------------------------------------------------------------------------------------------------- void VTextManager::SetFont(const QFont& font) -{ m_font = font; } +{ + m_font = font; +} //--------------------------------------------------------------------------------------------------------------------- const QFont& VTextManager::GetFont() const -{ return m_font; } +{ + return m_font; +} //--------------------------------------------------------------------------------------------------------------------- void VTextManager::SetFontSize(int iFS) -{ m_font.setPixelSize(iFS); } +{ + m_font.setPixelSize(iFS); +} //--------------------------------------------------------------------------------------------------------------------- void VTextManager::AddLine(const TextLine& tl) -{ m_liLines << tl; } +{ + m_liLines << tl; +} //--------------------------------------------------------------------------------------------------------------------- void VTextManager::Clear() -{ m_liLines.clear(); } +{ + m_liLines.clear(); +} //--------------------------------------------------------------------------------------------------------------------- int VTextManager::GetCount() const -{ return m_liOutput.count(); } +{ + return m_liOutput.count(); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VTextManager::GetSourceLineCount() const +{ + return m_liLines.count(); +} //--------------------------------------------------------------------------------------------------------------------- const TextLine& VTextManager::GetLine(int i) const -{ return m_liOutput[i]; } +{ + return m_liOutput[i]; +} //--------------------------------------------------------------------------------------------------------------------- bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) diff --git a/src/libs/vtools/tools/vtextmanager.h b/src/libs/vtools/tools/vtextmanager.h index 3ee8e8183..da7b0a169 100644 --- a/src/libs/vtools/tools/vtextmanager.h +++ b/src/libs/vtools/tools/vtextmanager.h @@ -32,6 +32,7 @@ public: void AddLine(const TextLine& tl); void Clear(); int GetCount() const; + int GetSourceLineCount() const; const TextLine& GetLine(int i) const; bool IsBigEnough(qreal fW, qreal fH, int iFontSize); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index c89cc6970..cb16778f4 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -712,7 +712,8 @@ void VToolDetail::UpdateLabel() tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; tl.m_eFontWeight = QFont::Normal; tl.m_iFontSize = 0; - for (int i = 0; i < data.GetMCPCount(); ++i) { + for (int i = 0; i < data.GetMCPCount(); ++i) + { MaterialCutPlacement mcp = data.GetMCP(i); if (mcp.m_iCutNumber > 0) { From 6516fb32042cee26e59be849cb1438664999f9c8 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 19 Jul 2016 09:06:29 +0200 Subject: [PATCH 44/66] Made the labels text in Layout mode look better --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 1 + src/libs/vlayout/vlayoutdetail.cpp | 127 ++++++++++++++++++------- src/libs/vlayout/vlayoutdetail.h | 5 + src/libs/vlayout/vlayoutdetail_p.h | 6 +- src/libs/vlayout/vlayoutpaper.cpp | 4 + 5 files changed, 103 insertions(+), 40 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index d2cecb66d..c45273cfc 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -485,6 +485,7 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de det.SetPatternInfoPoints(geom.GetPos(), geom.GetLabelWidth(), geom.GetLabelHeight(), geom.GetRotation()); } det.setWidth(qApp->toPixel(d.getWidth())); + det.CreateTextItems(); listDetails.append(det); ++i; diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index 251fd2269..5209d179e 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../vmisc/vmath.h" @@ -45,12 +46,12 @@ //--------------------------------------------------------------------------------------------------------------------- VLayoutDetail::VLayoutDetail() - :VAbstractDetail(), d(new VLayoutDetailData), m_tmDetail() + :VAbstractDetail(), d(new VLayoutDetailData), m_tmDetail(), m_liPP() {} //--------------------------------------------------------------------------------------------------------------------- VLayoutDetail::VLayoutDetail(const VLayoutDetail &detail) - :VAbstractDetail(detail), d(detail.d), m_tmDetail(detail.m_tmDetail) + :VAbstractDetail(detail), d(detail.d), m_tmDetail(detail.m_tmDetail), m_liPP(detail.m_liPP) {} //--------------------------------------------------------------------------------------------------------------------- @@ -63,6 +64,7 @@ VLayoutDetail &VLayoutDetail::operator=(const VLayoutDetail &detail) VAbstractDetail::operator=(detail); d = detail.d; m_tmDetail = detail.m_tmDetail; + m_liPP = detail.m_liPP; return *this; } @@ -516,41 +518,6 @@ QPainterPath VLayoutDetail::ContourPath() const } path.addPath(pathDet); - - - qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x()); - qreal dW = GetDistance(points.at(0), points.at(1)); - qreal dY = 0; - qreal dX; - for (int i = 0; i < m_tmDetail.GetCount(); ++i) - { - const TextLine& tl = m_tmDetail.GetLine(i); - QFont fnt = m_tmDetail.GetFont(); - fnt.setPixelSize(m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize); - fnt.setWeight(tl.m_eFontWeight); - fnt.setStyle(tl.m_eStyle); - dY += tl.m_iHeight; - QMatrix mat; - mat.translate(points.at(0).x(), points.at(0).y()); - mat.rotate(qRadiansToDegrees(dAng)); - QFontMetrics fm(fnt); - if ((tl.m_eAlign & Qt::AlignLeft) > 0) - { - dX = 0; - } - else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) - { - dX = (dW - fm.width(tl.m_qsText))/2; - } - else - { - dX = dW - fm.width(tl.m_qsText); - } - QPainterPath pathText; - pathText.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, tl.m_qsText); - path.addPath(mat.map(pathText)); - dY += m_tmDetail.GetSpacing(); - } } if (d->patternInfo.count() > 0) @@ -571,6 +538,92 @@ QPainterPath VLayoutDetail::ContourPath() const return path; } +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutDetail::ClearTextItems() +{ + m_liPP.clear(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutDetail::CreateTextItems() +{ + ClearTextItems(); + if (d->detailLabel.count() > 0) + { + QVector points = Map(Mirror(d->detailLabel)); + points.push_back(points.at(0)); + qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x()); + qreal dW = GetDistance(points.at(0), points.at(1)); + qreal dY = 0; + qreal dX; + for (int i = 0; i < m_tmDetail.GetCount(); ++i) + { + const TextLine& tl = m_tmDetail.GetLine(i); + QFont fnt = m_tmDetail.GetFont(); + fnt.setPixelSize(m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize); + fnt.setWeight(tl.m_eFontWeight); + fnt.setStyle(tl.m_eStyle); + dY += tl.m_iHeight; + QMatrix mat; + mat.translate(points.at(0).x(), points.at(0).y()); + mat.rotate(qRadiansToDegrees(dAng)); + + QFontMetrics fm(fnt); + if ((tl.m_eAlign & Qt::AlignLeft) > 0) + { + dX = 0; + } + else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) + { + dX = (dW - fm.width(tl.m_qsText))/2; + } + else + { + dX = dW - fm.width(tl.m_qsText); + } + QPainterPath path; + path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, tl.m_qsText); + m_liPP << mat.map(path); + dY += m_tmDetail.GetSpacing(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int VLayoutDetail::GetTextItemsCount() const +{ + return m_liPP.count(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsItem* VLayoutDetail::GetTextItem(int i) const +{ + QGraphicsPathItem* item = new QGraphicsPathItem(); + QTransform transform = d->matrix; + + QPainterPath path = transform.map(m_liPP[i]); + + if (d->mirror == true) + { + QVector points = Map(Mirror(d->detailLabel)); + QPointF ptCenter = (points.at(1) + points.at(3))/2; + qreal dRot = qRadiansToDegrees(qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x())); + + // we need to move the center back to the origin, rotate it to align it with x axis, + // then mirror it to obtain the proper text direction, rotate it and translate it back to original position + QTransform t; + t.translate(ptCenter.x(), ptCenter.y()); + t.rotate(dRot); + t.scale(-1, 1); + t.rotate(-dRot); + t.translate(-ptCenter.x(), -ptCenter.y()); + path = t.map(path); + } + item->setPath(path); + item->setBrush(QBrush(Qt::black)); + return item; +} + //--------------------------------------------------------------------------------------------------------------------- QPainterPath VLayoutDetail::LayoutAllowencePath() const { diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index b639420b9..9c1da46e9 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -85,12 +85,17 @@ public: bool isNull() const; qint64 Square() const; QPainterPath ContourPath() const; + void ClearTextItems(); + void CreateTextItems(); + int GetTextItemsCount() const; + QGraphicsItem* GetTextItem(int i) const; QPainterPath LayoutAllowencePath() const; QGraphicsItem *GetItem() const Q_REQUIRED_RESULT; private: QSharedDataPointer d; VTextManager m_tmDetail; + QList m_liPP; QVector Map(const QVector &points) const; static QVector RoundPoints(const QVector &points); diff --git a/src/libs/vlayout/vlayoutdetail_p.h b/src/libs/vlayout/vlayoutdetail_p.h index d7fe95d53..46ed05d18 100644 --- a/src/libs/vlayout/vlayoutdetail_p.h +++ b/src/libs/vlayout/vlayoutdetail_p.h @@ -52,9 +52,9 @@ public: VLayoutDetailData(const VLayoutDetailData &detail) :QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence), - layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), layoutWidth(detail.layoutWidth), - mirror(detail.mirror), detailLabel(detail.detailLabel), patternInfo(detail.patternInfo), - detailData(detail.detailData) + layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), + layoutWidth(detail.layoutWidth), mirror(detail.mirror), detailLabel(detail.detailLabel), + patternInfo(detail.patternInfo), detailData(detail.detailData) {} ~VLayoutDetailData() {} diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 91a7213ba..21710bcc5 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -313,6 +313,10 @@ QList VLayoutPaper::GetItemDetails() const for (int i=0; i < d->details.count(); ++i) { list.append(d->details.at(i).GetItem()); + for (int iT = 0; iT < d->details.at(i).GetTextItemsCount(); ++iT) + { + list.append(d->details.at(i).GetTextItem(iT)); + } } return list; } From 1759d4314f7e929eb361dc4581545ff26ac39525 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 19 Jul 2016 13:47:21 +0200 Subject: [PATCH 45/66] Labels with pattern info are now displayed in the Layout mode as well. Maybe needs a little bit of refactoring (the label styles and texts are now set up in two different places (VToolDetail and VLayoutDetail), I think this should be unified --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 12 +- src/libs/vlayout/vlayoutdetail.cpp | 167 ++++++++++++++++++++++--- src/libs/vlayout/vlayoutdetail.h | 10 +- src/libs/vlayout/vlayoutdetail_p.h | 13 +- src/libs/vtools/tools/vtextmanager.cpp | 15 +++ src/libs/vtools/tools/vtextmanager.h | 1 + src/libs/vtools/tools/vtooldetail.cpp | 18 ++- 7 files changed, 206 insertions(+), 30 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index c45273cfc..71e77ccc3 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -477,12 +477,20 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de const VPatternPieceData& data = d.GetPatternPieceData(); if (data.IsVisible() == true) { - det.SetDetail(d.getName(), data); + det.SetDetail(d.getName(), data, qApp->font()); } const VPatternInfoGeometry& geom = d.GetPatternInfo(); if (geom.IsVisible() == true) { - det.SetPatternInfoPoints(geom.GetPos(), geom.GetLabelWidth(), geom.GetLabelHeight(), geom.GetRotation()); + VAbstractPattern* pDoc = qApp->getCurrentDocument(); + QDate date; + if (pDoc->IsDateVisible() == true) + { + date = pDoc->GetCreationDate(); + } + det.SetPatternInfo(pDoc->GetPatternName(), pDoc->GetPatternNumber(), pDoc->GetPatternSize(), + pDoc->GetCompanyName(), pDoc->GetCustomerName(), date, geom, qApp->font()); + qApp->getCurrentDocument(); } det.setWidth(qApp->toPixel(d.getWidth())); det.CreateTextItems(); diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index 5209d179e..d3b863960 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -33,8 +33,8 @@ #include #include #include -#include #include +#include #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../vmisc/vmath.h" @@ -46,12 +46,13 @@ //--------------------------------------------------------------------------------------------------------------------- VLayoutDetail::VLayoutDetail() - :VAbstractDetail(), d(new VLayoutDetailData), m_tmDetail(), m_liPP() + :VAbstractDetail(), d(new VLayoutDetailData), m_tmDetail(), m_tmPattern(), m_liPP() {} //--------------------------------------------------------------------------------------------------------------------- VLayoutDetail::VLayoutDetail(const VLayoutDetail &detail) - :VAbstractDetail(detail), d(detail.d), m_tmDetail(detail.m_tmDetail), m_liPP(detail.m_liPP) + :VAbstractDetail(detail), d(detail.d), m_tmDetail(detail.m_tmDetail), m_tmPattern(detail.m_tmPattern), + m_liPP(detail.m_liPP) {} //--------------------------------------------------------------------------------------------------------------------- @@ -64,6 +65,7 @@ VLayoutDetail &VLayoutDetail::operator=(const VLayoutDetail &detail) VAbstractDetail::operator=(detail); d = detail.d; m_tmDetail = detail.m_tmDetail; + m_tmPattern = detail.m_tmPattern; m_liPP = detail.m_liPP; return *this; } @@ -119,7 +121,7 @@ QVector VLayoutDetail::GetLayoutAllowencePoints() const } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& data) +void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& data, const QFont &font) { d->detailData = data; qreal dAng = qDegreesToRadians(data.GetRotation()); @@ -130,12 +132,13 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da << QPointF(ptPos.x() + data.GetLabelWidth(), ptPos.y() + data.GetLabelHeight()) << QPointF(ptPos.x(), ptPos.y() + data.GetLabelHeight()); for (int i = 0; i < v.count(); ++i) + { v[i] = RotatePoint(ptCenter, v[i], dAng); + } d->detailLabel = RoundPoints(v); // generate text - QFont fnt = QApplication::font(); - m_tmDetail.SetFont(fnt); + m_tmDetail.SetFont(font); m_tmDetail.SetFontSize(data.GetFontSize()); m_tmDetail.Clear(); TextLine tl; @@ -153,7 +156,9 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da if (qsName.isEmpty() == false) { tl.m_qsText = qsName; + tl.m_eAlign = Qt::AlignCenter; tl.m_eFontWeight = QFont::DemiBold; + tl.m_eStyle = QFont::StyleNormal; tl.m_iFontSize = 2; m_tmDetail.AddLine(tl); } @@ -164,6 +169,7 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da qslPlace << "" << " on Fold"; tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; tl.m_iFontSize = 0; for (int i = 0; i < data.GetMCPCount(); ++i) { @@ -175,26 +181,98 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da } } // will generate the lines of text - m_tmDetail.IsBigEnough(data.GetLabelWidth(), data.GetLabelHeight(), data.GetFontSize()); + m_tmDetail.SetFontSize(data.GetFontSize()); + m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight()); } //--------------------------------------------------------------------------------------------------------------------- -QVector VLayoutDetail::GetPatternInfoPoints() const +void VLayoutDetail::SetPatternInfo(const QString& qsPattern, const QString& qsNumber, const QString& qsSize, + const QString& qsCompany, const QString& qsCustomer, const QDate& date, + const VPatternInfoGeometry& geom, const QFont &font) { - return d->patternInfo; -} - -//--------------------------------------------------------------------------------------------------------------------- -void VLayoutDetail::SetPatternInfoPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot) -{ - qreal dAng = qDegreesToRadians(dRot); - QPointF ptCenter(ptPos.x() + dWidth/2, ptPos.y() + dHeight/2); + d->patternGeom = geom; + qreal dAng = qDegreesToRadians(geom.GetRotation()); + QPointF ptCenter(geom.GetPos().x() + geom.GetLabelWidth()/2, geom.GetPos().y() + geom.GetLabelHeight()/2); + QPointF ptPos = geom.GetPos(); QVector v; - v << ptPos << QPointF(ptPos.x() + dWidth, ptPos.y()) << QPointF(ptPos.x() + dWidth, ptPos.y() + dHeight) - << QPointF(ptPos.x(), ptPos.y() + dHeight); + v << ptPos << QPointF(ptPos.x() + geom.GetLabelWidth(), ptPos.y()) + << QPointF(ptPos.x() + geom.GetLabelWidth(), ptPos.y() + geom.GetLabelHeight()) + << QPointF(ptPos.x(), ptPos.y() + geom.GetLabelHeight()); for (int i = 0; i < v.count(); ++i) + { v[i] = RotatePoint(ptCenter, v[i], dAng); + } d->patternInfo = RoundPoints(v); + + // Generate text + m_tmPattern.SetFont(font); + m_tmPattern.SetFontSize(geom.GetFontSize()); + m_tmPattern.Clear(); + TextLine tl; + // Company name + tl.m_qsText = qsCompany; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eAlign = Qt::AlignCenter; + tl.m_eFontWeight = QFont::DemiBold; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 4; + m_tmPattern.AddLine(tl); + } + // Pattern name + tl.m_qsText = qsPattern; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eAlign = Qt::AlignCenter; + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 2; + m_tmPattern.AddLine(tl); + } + // Pattern number + tl.m_qsText = qsNumber; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 0; + m_tmPattern.AddLine(tl); + } + // Customer name + tl.m_qsText = qsCustomer; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleItalic; + tl.m_iFontSize = 0; + m_tmPattern.AddLine(tl); + } + // Size + tl.m_qsText = qsSize; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 0; + m_tmPattern.AddLine(tl); + } + // Creation date + if (date.isValid() == true) + { + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 0; + QStringList qslDate = date.toString(Qt::SystemLocaleLongDate).split(", "); + tl.m_qsText = qslDate.last(); + m_tmPattern.AddLine(tl); + } + // generate lines of text + m_tmPattern.SetFontSize(geom.GetFontSize()); + m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); } //--------------------------------------------------------------------------------------------------------------------- @@ -548,6 +626,7 @@ void VLayoutDetail::ClearTextItems() void VLayoutDetail::CreateTextItems() { ClearTextItems(); + // first add detail texts if (d->detailLabel.count() > 0) { QVector points = Map(Mirror(d->detailLabel)); @@ -587,6 +666,47 @@ void VLayoutDetail::CreateTextItems() dY += m_tmDetail.GetSpacing(); } } + // and then add pattern texts + if (d->patternInfo.count() > 0) + { + QVector points = Map(Mirror(d->patternInfo)); + points.push_back(points.at(0)); + qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x()); + qreal dW = GetDistance(points.at(0), points.at(1)); + qreal dY = 0; + qreal dX; + printf("Pattern lines %d %d\n", m_tmPattern.GetCount(), m_tmPattern.GetSourceLineCount()); + for (int i = 0; i < m_tmPattern.GetCount(); ++i) + { + const TextLine& tl = m_tmPattern.GetLine(i); + QFont fnt = m_tmPattern.GetFont(); + fnt.setPixelSize(m_tmPattern.GetFont().pixelSize() + tl.m_iFontSize); + fnt.setWeight(tl.m_eFontWeight); + fnt.setStyle(tl.m_eStyle); + dY += tl.m_iHeight; + QMatrix mat; + mat.translate(points.at(0).x(), points.at(0).y()); + mat.rotate(qRadiansToDegrees(dAng)); + + QFontMetrics fm(fnt); + if ((tl.m_eAlign & Qt::AlignLeft) > 0) + { + dX = 0; + } + else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) + { + dX = (dW - fm.width(tl.m_qsText))/2; + } + else + { + dX = dW - fm.width(tl.m_qsText); + } + QPainterPath path; + path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, tl.m_qsText); + m_liPP << mat.map(path); + dY += m_tmPattern.GetSpacing(); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -605,7 +725,15 @@ QGraphicsItem* VLayoutDetail::GetTextItem(int i) const if (d->mirror == true) { - QVector points = Map(Mirror(d->detailLabel)); + QVector points; + if (i < m_tmDetail.GetCount()) + { + points = Map(Mirror(d->detailLabel)); + } + else + { + points = Map(Mirror(d->patternInfo)); + } QPointF ptCenter = (points.at(1) + points.at(3))/2; qreal dRot = qRadiansToDegrees(qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x())); @@ -619,6 +747,7 @@ QGraphicsItem* VLayoutDetail::GetTextItem(int i) const t.translate(-ptCenter.x(), -ptCenter.y()); path = t.map(path); } + item->setPath(path); item->setBrush(QBrush(Qt::black)); return item; diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index 9c1da46e9..02f180cea 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -31,10 +31,12 @@ #include "vabstractdetail.h" #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vpatterninfogeometry.h" #include "../vtools/tools/vtextmanager.h" #include #include +#include class VLayoutDetailData; class QGraphicsItem; @@ -56,10 +58,11 @@ public: QVector GetLayoutAllowencePoints() const; void SetLayoutAllowencePoints(); - void SetDetail(const QString &qsName, const VPatternPieceData& data); + void SetDetail(const QString &qsName, const VPatternPieceData& data, const QFont& font); - QVector GetPatternInfoPoints() const; - void SetPatternInfoPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot); + void SetPatternInfo(const QString& qsPattern, const QString& qsNumber, const QString& qsSize, + const QString& qsCompany, const QString& qsCustomer, const QDate& date, + const VPatternInfoGeometry& geom, const QFont& font); QTransform GetMatrix() const; void SetMatrix(const QTransform &matrix); @@ -95,6 +98,7 @@ public: private: QSharedDataPointer d; VTextManager m_tmDetail; + VTextManager m_tmPattern; QList m_liPP; QVector Map(const QVector &points) const; diff --git a/src/libs/vlayout/vlayoutdetail_p.h b/src/libs/vlayout/vlayoutdetail_p.h index 46ed05d18..77afa5ca7 100644 --- a/src/libs/vlayout/vlayoutdetail_p.h +++ b/src/libs/vlayout/vlayoutdetail_p.h @@ -35,6 +35,7 @@ #include #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vpatterninfogeometry.h" #ifdef Q_CC_GNU #pragma GCC diagnostic push @@ -47,14 +48,14 @@ public: VLayoutDetailData() :contour(QVector()), seamAllowence(QVector()), layoutAllowence(QVector()), matrix(QMatrix()), layoutWidth(0), mirror(false), detailLabel(QVector()), - patternInfo(QVector()), detailData() + patternInfo(QVector()), detailData(), patternGeom() {} VLayoutDetailData(const VLayoutDetailData &detail) :QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence), layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), layoutWidth(detail.layoutWidth), mirror(detail.mirror), detailLabel(detail.detailLabel), - patternInfo(detail.patternInfo), detailData(detail.detailData) + patternInfo(detail.patternInfo), detailData(detail.detailData), patternGeom(detail.patternGeom) {} ~VLayoutDetailData() {} @@ -76,12 +77,14 @@ public: bool mirror; - /** @brief detail label rectangle */ + /** @brief detailLabel detail label rectangle */ QVector detailLabel; - /** @brief pattern info rectangle */ + /** @brief patternInfo pattern info rectangle */ QVector patternInfo; - /** @brief detail data */ + /** @brief detailData detail data */ VPatternPieceData detailData; + /** @brief patternGeom pattern geometry */ + VPatternInfoGeometry patternGeom; private: VLayoutDetailData &operator=(const VLayoutDetailData &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vtools/tools/vtextmanager.cpp b/src/libs/vtools/tools/vtextmanager.cpp index 328457fcc..115e2ec24 100644 --- a/src/libs/vtools/tools/vtextmanager.cpp +++ b/src/libs/vtools/tools/vtextmanager.cpp @@ -96,6 +96,21 @@ bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) return iY < fH; } +//--------------------------------------------------------------------------------------------------------------------- +void VTextManager::FitFontSize(qreal fW, qreal fH) +{ + int iFontSize = GetFont().pixelSize(); + while (IsBigEnough(fW, fH, iFontSize) == true && iFontSize <= MAX_FONT_SIZE) + { + ++iFontSize; + } + while (IsBigEnough(fW, fH, iFontSize) == false && iFontSize >= MIN_FONT_SIZE) + { + --iFontSize; + } + SetFontSize(iFontSize); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm) { diff --git a/src/libs/vtools/tools/vtextmanager.h b/src/libs/vtools/tools/vtextmanager.h index da7b0a169..659a07277 100644 --- a/src/libs/vtools/tools/vtextmanager.h +++ b/src/libs/vtools/tools/vtextmanager.h @@ -35,6 +35,7 @@ public: int GetSourceLineCount() const; const TextLine& GetLine(int i) const; bool IsBigEnough(qreal fW, qreal fH, int iFontSize); + void FitFontSize(qreal fW, qreal fH); protected: QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index cb16778f4..3b77db5a3 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -704,6 +704,7 @@ void VToolDetail::UpdateLabel() { tl.m_eAlign = Qt::AlignCenter; tl.m_eFontWeight = QFont::DemiBold; + tl.m_eStyle = QFont::StyleNormal; tl.m_iFontSize = 2; dataLabel->AddLine(tl); } @@ -711,6 +712,7 @@ void VToolDetail::UpdateLabel() // MCP tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; tl.m_iFontSize = 0; for (int i = 0; i < data.GetMCPCount(); ++i) { @@ -784,7 +786,9 @@ void VToolDetail::UpdatePatternInfo() tl.m_qsText = doc->GetPatternName(); if (tl.m_qsText.isEmpty() == false) { + tl.m_eAlign = Qt::AlignCenter; tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; tl.m_iFontSize = 2; patternInfo->AddLine(tl); } @@ -793,8 +797,10 @@ void VToolDetail::UpdatePatternInfo() tl.m_qsText = doc->GetPatternNumber(); if (tl.m_qsText.isEmpty() == false) { - tl.m_iFontSize = 0; tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 0; patternInfo->AddLine(tl); } @@ -802,7 +808,10 @@ void VToolDetail::UpdatePatternInfo() tl.m_qsText = doc->GetCustomerName(); if (tl.m_qsText.isEmpty() == false) { + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + tl.m_eFontWeight = QFont::Normal; tl.m_eStyle = QFont::StyleItalic; + tl.m_iFontSize = 0; patternInfo->AddLine(tl); } @@ -810,13 +819,20 @@ void VToolDetail::UpdatePatternInfo() tl.m_qsText = doc->GetPatternSize(); if (tl.m_qsText.isEmpty() == false) { + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + tl.m_eFontWeight = QFont::Normal; tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 0; patternInfo->AddLine(tl); } // Creation date if (doc->IsDateVisible() == true) { + tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 0; QStringList qslDate = doc->GetCreationDate().toString(Qt::SystemLocaleLongDate).split(", "); tl.m_qsText = qslDate.last(); patternInfo->AddLine(tl); From 04780b4323c9aef6a6fb2a6676d18fcb9f46818f Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 19 Jul 2016 14:23:20 +0200 Subject: [PATCH 46/66] Moved VTextManager class into the vlayout folder in order for tests to compile. It also belong to vlayout folder more than into vtools --HG-- branch : feature --- src/libs/vlayout/vlayout.pri | 2 ++ src/libs/vlayout/vlayoutdetail.h | 2 +- src/libs/{vtools/tools => vlayout}/vtextmanager.cpp | 0 src/libs/{vtools/tools => vlayout}/vtextmanager.h | 0 src/libs/vtools/tools/tools.pri | 6 ++---- src/libs/vtools/tools/vtextgraphicsitem.h | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename src/libs/{vtools/tools => vlayout}/vtextmanager.cpp (100%) rename src/libs/{vtools/tools => vlayout}/vtextmanager.h (100%) diff --git a/src/libs/vlayout/vlayout.pri b/src/libs/vlayout/vlayout.pri index 171d943cd..d1cc7645f 100644 --- a/src/libs/vlayout/vlayout.pri +++ b/src/libs/vlayout/vlayout.pri @@ -16,6 +16,7 @@ HEADERS += \ $$PWD/vcontour_p.h \ $$PWD/vbestsquare.h \ $$PWD/vposition.h \ + $$PWD/vtextmanager.h \ vposter.h SOURCES += \ @@ -27,6 +28,7 @@ SOURCES += \ $$PWD/vcontour.cpp \ $$PWD/vbestsquare.cpp \ $$PWD/vposition.cpp \ + $$PWD/vtextmanager.cpp \ vposter.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index 02f180cea..e813fe9e3 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -32,7 +32,7 @@ #include "vabstractdetail.h" #include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatterninfogeometry.h" -#include "../vtools/tools/vtextmanager.h" +#include "vtextmanager.h" #include #include diff --git a/src/libs/vtools/tools/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp similarity index 100% rename from src/libs/vtools/tools/vtextmanager.cpp rename to src/libs/vlayout/vtextmanager.cpp diff --git a/src/libs/vtools/tools/vtextmanager.h b/src/libs/vlayout/vtextmanager.h similarity index 100% rename from src/libs/vtools/tools/vtextmanager.h rename to src/libs/vlayout/vtextmanager.h diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index f40f507c5..0391ca475 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -51,8 +51,7 @@ HEADERS += \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \ $$PWD/drawTools/operation/vtoolrotation.h \ - $$PWD/vtextgraphicsitem.h \ - $$PWD/vtextmanager.h + $$PWD/vtextgraphicsitem.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -101,5 +100,4 @@ SOURCES += \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \ $$PWD/drawTools/operation/vtoolrotation.cpp \ - $$PWD/vtextgraphicsitem.cpp \ - $$PWD/vtextmanager.cpp + $$PWD/vtextgraphicsitem.cpp diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 7ee41aabe..6e5ddb92c 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -33,7 +33,7 @@ #include #include -#include "vtextmanager.h" +#include "../vlayout/vtextmanager.h" class VTextGraphicsItem : public QGraphicsObject { From 1cf04118da2128f539882a6b743aa6dbe64b2d7a Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 19 Jul 2016 17:25:04 +0200 Subject: [PATCH 47/66] Removed the rectangles around the labels in Layout mode --HG-- branch : feature --- src/libs/vlayout/vlayoutdetail.cpp | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index d3b863960..c438543c3 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -583,36 +583,6 @@ QPainterPath VLayoutDetail::ContourPath() const path.setFillRule(Qt::WindingFill); } - if (d->detailLabel.count() > 0) - { - points = Map(Mirror(d->detailLabel)); - points.push_back(points.at(0)); - - QPainterPath pathDet; - pathDet.moveTo(points.at(0)); - for (qint32 i = 1; i < points.count(); ++i) - { - pathDet.lineTo(points.at(i)); - } - - path.addPath(pathDet); - } - - if (d->patternInfo.count() > 0) - { - points = Map(Mirror(d->patternInfo)); - points.push_back(points.at(0)); - - QPainterPath pathDet; - pathDet.moveTo(points.at(0)); - for (qint32 i = 1; i < points.count(); ++i) - { - pathDet.lineTo(points.at(i)); - } - - path.addPath(pathDet); - } - return path; } From 02edbcc8d6dac854250d94e06549fe14695c2bf0 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 19 Jul 2016 19:02:20 +0200 Subject: [PATCH 48/66] Removed some compiler warnings --HG-- branch : feature --- src/libs/vlayout/vtextmanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 115e2ec24..4d2bc9c68 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -11,7 +11,7 @@ TextLine::TextLine() //--------------------------------------------------------------------------------------------------------------------- VTextManager::VTextManager() - :m_liLines(), m_liOutput() + :m_font(), m_liLines(), m_liOutput() {} //--------------------------------------------------------------------------------------------------------------------- From 948102e74ec2937089505540f862089b278af092 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 19 Jul 2016 22:59:14 +0200 Subject: [PATCH 49/66] Current date is always used to show the pattern creation date --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 2 +- src/app/valentina/mainwindowsnogui.cpp | 2 +- src/app/valentina/xml/vpattern.cpp | 14 ++------ src/libs/ifc/schema/pattern/v0.3.3.xsd | 1 - src/libs/ifc/xml/vabstractpattern.cpp | 35 ++----------------- src/libs/ifc/xml/vabstractpattern.h | 4 +-- src/libs/vtools/tools/vtooldetail.cpp | 2 +- 7 files changed, 10 insertions(+), 50 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index b4c0c7d3e..29abd4796 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -170,7 +170,7 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte ui->lineEditPatternNumber->setText(doc->GetPatternNumber()); ui->lineEditCompanyName->setText(doc->GetCompanyName()); ui->lineEditCustomerName->setText(doc->GetCustomerName()); - ui->labelCreationDate->setText(doc->GetCreationDate().toString(Qt::SystemLocaleLongDate)); + ui->labelCreationDate->setText(QDate::currentDate().toString(Qt::SystemLocaleLongDate)); ui->lineEditSize->setText(doc->GetPatternSize()); ui->checkBoxShowDate->setChecked(doc->IsDateVisible()); diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 71e77ccc3..a1b4d8e53 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -486,7 +486,7 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de QDate date; if (pDoc->IsDateVisible() == true) { - date = pDoc->GetCreationDate(); + date = QDate::currentDate(); } det.SetPatternInfo(pDoc->GetPatternName(), pDoc->GetPatternNumber(), pDoc->GetPatternSize(), pDoc->GetCompanyName(), pDoc->GetCustomerName(), date, geom, qApp->font()); diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 29f1fb9d3..901a8045a 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -83,11 +83,6 @@ void VPattern::CreateEmptyFile() version.appendChild(newNodeText); patternElement.appendChild(version); - QDomElement domCreated = createElement(TagCreationDate); - QDomText domCreatedText = createTextNode(QDate::currentDate().toString("d.M.yyyy")); - domCreated.appendChild(domCreatedText); - patternElement.appendChild(domCreated); - QDomElement unit = createElement(TagUnit); newNodeText = createTextNode(UnitsToStr(qApp->patternUnit())); unit.appendChild(newNodeText); @@ -139,7 +134,7 @@ void VPattern::Parse(const Document &parse) QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName - << TagCreationDate << TagSize << TagShowDate; + << TagSize << TagShowDate; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -211,13 +206,10 @@ void VPattern::Parse(const Document &parse) case 13: // TagCustomerName qCDebug(vXML, "Customer name."); break; - case 14: // TagCreationDate - qCDebug(vXML, "Creation date."); - break; - case 15: // TagSize + case 14: // TagSize qCDebug(vXML, "Size"); break; - case 16: + case 15: qCDebug(vXML, "Show creation date"); break; default: diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd index 0f24bcc0c..26f4b412f 100644 --- a/src/libs/ifc/schema/pattern/v0.3.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -22,7 +22,6 @@ - diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index ab85684cd..1dedb2bb1 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -67,7 +67,6 @@ const QString VAbstractPattern::TagPatternName = QStringLiteral("patternName"); const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber"); const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); -const QString VAbstractPattern::TagCreationDate = QStringLiteral("created"); const QString VAbstractPattern::TagSize = QStringLiteral("size"); const QString VAbstractPattern::TagShowDate = QStringLiteral("showDate"); @@ -1056,29 +1055,6 @@ void VAbstractPattern::SetCustomerName(QString qsName) emit patternChanged(false); } -//--------------------------------------------------------------------------------------------------------------------- -QDate VAbstractPattern::GetCreationDate() const -{ - QStringList qsl = UniqueTagText(TagCreationDate).split("."); - if (qsl.count() == 3) - { - bool bDay; - bool bMonth; - bool bYear; - int iDay = qsl[0].toInt(&bDay); - int iMonth = qsl[1].toInt(&bMonth); - int iYear = qsl[2].toInt(&bYear); - - if (bDay == true && bMonth == true && bYear == true) - { - QDate date; - date.setDate(iYear, iMonth, iDay); - return date; - } - } - return QDate::currentDate(); -} - //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPattern::GetPatternSize() const { @@ -1211,7 +1187,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagCreationDate << TagSize << TagShowDate; + << TagCustomerName << TagSize << TagShowDate; switch (tags.indexOf(tag)) { case 0: //TagUnit @@ -1272,17 +1248,12 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) element = createElement(TagCustomerName); break; } - case 10: // TagPatternName - { - element = createElement(TagCreationDate); - break; - } - case 11: // TagSize + case 10: // TagSize { element = createElement(TagSize); break; } - case 12: // TagShowDate + case 11: // TagShowDate { element = createElement(TagShowDate); break; diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index c9e8d9380..7c8cfad3f 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -116,7 +116,6 @@ public: void SetPatternNumber(QString qsNum); QString GetCustomerName() const; void SetCustomerName(QString qsName); - QDate GetCreationDate() const; QString GetPatternSize() const; void SetPatternSize(QString qsSize); bool IsDateVisible() const; @@ -177,8 +176,7 @@ public: static const QString TagPatternNum; static const QString TagCompanyName; static const QString TagCustomerName; - static const QString TagCreationDate; - static const QString TagSize; + static const QString TagSize; static const QString TagShowDate; static const QString AttrName; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 3b77db5a3..5d5429acf 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -833,7 +833,7 @@ void VToolDetail::UpdatePatternInfo() tl.m_eFontWeight = QFont::Normal; tl.m_eStyle = QFont::StyleNormal; tl.m_iFontSize = 0; - QStringList qslDate = doc->GetCreationDate().toString(Qt::SystemLocaleLongDate).split(", "); + QStringList qslDate = QDate::currentDate().toString(Qt::SystemLocaleLongDate).split(", "); tl.m_qsText = qslDate.last(); patternInfo->AddLine(tl); } From d6341b50e4018729d1bf606b16ebb9544947de2c Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 21 Jul 2016 08:38:10 +0200 Subject: [PATCH 50/66] Fixed alignment --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 29abd4796..1aafcf101 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -170,7 +170,7 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte ui->lineEditPatternNumber->setText(doc->GetPatternNumber()); ui->lineEditCompanyName->setText(doc->GetCompanyName()); ui->lineEditCustomerName->setText(doc->GetCustomerName()); - ui->labelCreationDate->setText(QDate::currentDate().toString(Qt::SystemLocaleLongDate)); + ui->labelCreationDate->setText(QDate::currentDate().toString(Qt::SystemLocaleLongDate)); ui->lineEditSize->setText(doc->GetPatternSize()); ui->checkBoxShowDate->setChecked(doc->IsDateVisible()); From 5ba40aad8cd9a13a1740fd705a74d43a2f4b6f57 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 21 Jul 2016 16:49:26 +0200 Subject: [PATCH 51/66] Fixed alignments --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 2 +- src/app/valentina/xml/vpattern.cpp | 6 +++--- src/libs/ifc/xml/vabstractpattern.cpp | 6 +++--- src/libs/ifc/xml/vabstractpattern.h | 2 +- src/libs/vtools/tools/vtooldetail.cpp | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 7ea4ffdd0..258d9ec94 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -489,7 +489,7 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de date = QDate::currentDate(); } det.SetPatternInfo(pDoc->GetPatternName(), pDoc->GetPatternNumber(), pDoc->GetPatternSize(), - pDoc->GetCompanyName(), pDoc->GetCustomerName(), date, geom, qApp->font()); + pDoc->GetCompanyName(), pDoc->GetCustomerName(), date, geom, qApp->font()); qApp->getCurrentDocument(); } det.setWidth(qApp->toPixel(d.getWidth())); diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 0fb139822..2d6133572 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -134,7 +134,7 @@ void VPattern::Parse(const Document &parse) QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName - << TagSize << TagShowDate; + << TagSize << TagShowDate; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -206,10 +206,10 @@ void VPattern::Parse(const Document &parse) case 13: // TagCustomerName qCDebug(vXML, "Customer name."); break; - case 14: // TagSize + case 14: // TagSize qCDebug(vXML, "Size"); break; - case 15: + case 15: qCDebug(vXML, "Show creation date"); break; default: diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 19d3f5d7e..c4991b689 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1199,7 +1199,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagSize << TagShowDate; + << TagCustomerName << TagSize << TagShowDate; switch (tags.indexOf(tag)) { case 0: //TagUnit @@ -1260,12 +1260,12 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) element = createElement(TagCustomerName); break; } - case 10: // TagSize + case 10: // TagSize { element = createElement(TagSize); break; } - case 11: // TagShowDate + case 11: // TagShowDate { element = createElement(TagShowDate); break; diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index abf36122c..f5f94ff5e 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -176,7 +176,7 @@ public: static const QString TagPatternNum; static const QString TagCompanyName; static const QString TagCustomerName; - static const QString TagSize; + static const QString TagSize; static const QString TagShowDate; static const QString AttrName; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index f91af956d..73afc8e47 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -833,7 +833,7 @@ void VToolDetail::UpdatePatternInfo() tl.m_eFontWeight = QFont::Normal; tl.m_eStyle = QFont::StyleNormal; tl.m_iFontSize = 0; - QStringList qslDate = QDate::currentDate().toString(Qt::SystemLocaleLongDate).split(", "); + QStringList qslDate = QDate::currentDate().toString(Qt::SystemLocaleLongDate).split(", "); tl.m_qsText = qslDate.last(); patternInfo->AddLine(tl); } From 312b8e458b1e0ea2999eb448885af663397332f1 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 21 Jul 2016 21:46:49 +0200 Subject: [PATCH 52/66] Centered the label texts and did some refactoring, so that the label content is generated in one place --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 4 +- src/libs/vlayout/vlayoutdetail.cpp | 108 +------------------ src/libs/vlayout/vtextmanager.cpp | 108 +++++++++++++++++++ src/libs/vlayout/vtextmanager.h | 13 +++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 13 +++ src/libs/vtools/tools/vtextgraphicsitem.h | 3 + src/libs/vtools/tools/vtooldetail.cpp | 109 +------------------- 7 files changed, 148 insertions(+), 210 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 258d9ec94..a54d26812 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -486,10 +486,10 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de QDate date; if (pDoc->IsDateVisible() == true) { - date = QDate::currentDate(); + date = QDate::currentDate(); } det.SetPatternInfo(pDoc->GetPatternName(), pDoc->GetPatternNumber(), pDoc->GetPatternSize(), - pDoc->GetCompanyName(), pDoc->GetCustomerName(), date, geom, qApp->font()); + pDoc->GetCompanyName(), pDoc->GetCustomerName(), date, geom, qApp->font()); qApp->getCurrentDocument(); } det.setWidth(qApp->toPixel(d.getWidth())); diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index c438543c3..2de021f92 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -140,47 +140,8 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da // generate text m_tmDetail.SetFont(font); m_tmDetail.SetFontSize(data.GetFontSize()); - m_tmDetail.Clear(); - TextLine tl; - // letter - tl.m_qsText = data.GetLetter(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::Bold; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 6; - m_tmDetail.AddLine(tl); - } - // name - if (qsName.isEmpty() == false) - { - tl.m_qsText = qsName; - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::DemiBold; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 2; - m_tmDetail.AddLine(tl); - } - - // MCP - QString qsText = "Cut %1 of %2%3"; - QStringList qslPlace; - qslPlace << "" << " on Fold"; - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - for (int i = 0; i < data.GetMCPCount(); ++i) - { - MaterialCutPlacement mcp = data.GetMCP(i); - if (mcp.m_iCutNumber > 0) - { - tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]); - m_tmDetail.AddLine(tl); - } - } - // will generate the lines of text + m_tmDetail.Update(qsName, data); + // this will generate the lines of text m_tmDetail.SetFontSize(data.GetFontSize()); m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight()); } @@ -207,69 +168,8 @@ void VLayoutDetail::SetPatternInfo(const QString& qsPattern, const QString& qsNu // Generate text m_tmPattern.SetFont(font); m_tmPattern.SetFontSize(geom.GetFontSize()); - m_tmPattern.Clear(); - TextLine tl; - // Company name - tl.m_qsText = qsCompany; - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::DemiBold; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 4; - m_tmPattern.AddLine(tl); - } - // Pattern name - tl.m_qsText = qsPattern; - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 2; - m_tmPattern.AddLine(tl); - } - // Pattern number - tl.m_qsText = qsNumber; - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - m_tmPattern.AddLine(tl); - } - // Customer name - tl.m_qsText = qsCustomer; - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleItalic; - tl.m_iFontSize = 0; - m_tmPattern.AddLine(tl); - } - // Size - tl.m_qsText = qsSize; - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - m_tmPattern.AddLine(tl); - } - // Creation date - if (date.isValid() == true) - { - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - QStringList qslDate = date.toString(Qt::SystemLocaleLongDate).split(", "); - tl.m_qsText = qslDate.last(); - m_tmPattern.AddLine(tl); - } + + m_tmPattern.Update(qsPattern, qsNumber, qsSize, qsCompany, qsCustomer, date); // generate lines of text m_tmPattern.SetFontSize(geom.GetFontSize()); m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 4d2bc9c68..5793c0c92 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -111,6 +111,114 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) SetFontSize(iFontSize); } +//--------------------------------------------------------------------------------------------------------------------- +void VTextManager::Update(const QString& qsName, const VPatternPieceData& data) +{ + Clear(); + TextLine tl; + // all text must be centered and normal style! + tl.m_eAlign = Qt::AlignCenter; + tl.m_eStyle = QFont::StyleNormal; + + // letter + tl.m_qsText = data.GetLetter(); + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eFontWeight = QFont::Bold; + tl.m_iFontSize = 6; + AddLine(tl); + } + // name + tl.m_qsText = qsName; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eFontWeight = QFont::DemiBold; + tl.m_iFontSize = 2; + AddLine(tl); + } + // MCP + QString qsText = "Cut %1 on %2%3"; + QStringList qslPlace; + qslPlace << "" << " on Fold"; + tl.m_eFontWeight = QFont::Normal; + tl.m_iFontSize = 0; + for (int i = 0; i < data.GetMCPCount(); ++i) + { + MaterialCutPlacement mcp = data.GetMCP(i); + if (mcp.m_iCutNumber > 0) + { + tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef). + arg(qslPlace[int(mcp.m_ePlacement)]); + AddLine(tl); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextManager::Update(const QString &qsPattern, const QString &qsNumber, const QString &qsSize, + const QString &qsCompany, const QString &qsCustomer, const QDate& date) +{ + Clear(); + TextLine tl; + // all information must be centered + tl.m_eAlign = Qt::AlignCenter; + + // Company name + tl.m_qsText = qsCompany; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eFontWeight = QFont::DemiBold; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 4; + AddLine(tl); + } + // Pattern name + tl.m_qsText = qsPattern; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 2; + AddLine(tl); + } + // Pattern number + tl.m_qsText = qsNumber; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 0; + AddLine(tl); + } + // Customer name + tl.m_qsText = qsCustomer; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleItalic; + tl.m_iFontSize = 0; + AddLine(tl); + } + // Size + tl.m_qsText = qsSize; + if (tl.m_qsText.isEmpty() == false) + { + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 0; + AddLine(tl); + } + // Date + if (date.isValid() == true) + { + tl.m_qsText = date.toString("dd MMMM yyyy"); + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 0; + AddLine(tl); + } +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm) { diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index 659a07277..167073f73 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -3,6 +3,9 @@ #include #include +#include + +#include "../vpatterndb/vpatternpiecedata.h" #define MIN_FONT_SIZE 12 #define MAX_FONT_SIZE 128 @@ -36,6 +39,16 @@ public: const TextLine& GetLine(int i) const; bool IsBigEnough(qreal fW, qreal fH, int iFontSize); void FitFontSize(qreal fW, qreal fH); + /** @brief Update(const QString& qsName, const VPatternPieceData& data) + * Updates the manager with detail name and detail data + */ + void Update(const QString& qsName, const VPatternPieceData& data); + /** @brief Updateconst QString& qsPattern, const QString& qsNumber, const QString& qsSize, + const QString& qsCompany, const QString& qsCustomer, const QDate& date) + Updates the manager with pattern data + */ + void Update(const QString& qsPattern, const QString& qsNumber, const QString& qsSize, + const QString& qsCompany, const QString& qsCustomer, const QDate& date); protected: QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index eeee34aee..f739c973e 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -220,6 +220,19 @@ bool VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal return true; } +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::UpdateData(const QString &qsName, const VPatternPieceData &data) +{ + m_tm.Update(qsName, data); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::UpdateData(const QString &qsPattern, const QString &qsNumber, const QString &qsSize, + const QString &qsCompany, const QString &qsCustomer, const QDate &date) +{ + m_tm.Update(qsPattern, qsNumber, qsSize, qsCompany, qsCustomer, date); +} + //--------------------------------------------------------------------------------------------------------------------- int VTextGraphicsItem::GetFontSize() const { diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 6e5ddb92c..29f9e39a9 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -62,6 +62,9 @@ public: void SetSize(qreal fW, qreal fH); void Update(); bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const; + void UpdateData(const QString& qsName, const VPatternPieceData& data); + void UpdateData(const QString& qsPattern, const QString& qsNumber, const QString& qsSize, + const QString& qsCompany, const QString& qsCustomer, const QDate& date); protected: void mousePressEvent(QGraphicsSceneMouseEvent* pME); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 73afc8e47..ec757abbd 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -685,45 +685,7 @@ void VToolDetail::UpdateLabel() fnt.setPixelSize(data.GetFontSize()); dataLabel->SetFont(fnt); dataLabel->SetSize(data.GetLabelWidth(), data.GetLabelHeight()); - dataLabel->Clear(); - TextLine tl; - // letter - tl.m_qsText = data.GetLetter(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::Bold; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 6; - dataLabel->AddLine(tl); - } - - // name - tl.m_qsText = detail.getName(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::DemiBold; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 2; - dataLabel->AddLine(tl); - } - - // MCP - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - for (int i = 0; i < data.GetMCPCount(); ++i) - { - MaterialCutPlacement mcp = data.GetMCP(i); - if (mcp.m_iCutNumber > 0) - { - tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]); - dataLabel->AddLine(tl); - } - } - + dataLabel->UpdateData(detail.getName(), data); QPointF pt = data.GetPos(); QRectF rectBB; rectBB.setTopLeft(pt); @@ -768,75 +730,14 @@ void VToolDetail::UpdatePatternInfo() fnt.setPixelSize(iFS); patternInfo->SetFont(fnt); patternInfo->SetSize(geom.GetLabelWidth(), geom.GetLabelHeight()); - patternInfo->Clear(); - TextLine tl; - // Company name - tl.m_qsText = doc->GetCompanyName(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::DemiBold; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 4; - patternInfo->AddLine(tl); - } - - // Pattern name - tl.m_qsText = doc->GetPatternName(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 2; - patternInfo->AddLine(tl); - } - - // Pattern number - tl.m_qsText = doc->GetPatternNumber(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - patternInfo->AddLine(tl); - } - - // Customer name - tl.m_qsText = doc->GetCustomerName(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleItalic; - tl.m_iFontSize = 0; - patternInfo->AddLine(tl); - } - - // Size - tl.m_qsText = doc->GetPatternSize(); - if (tl.m_qsText.isEmpty() == false) - { - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - patternInfo->AddLine(tl); - } - - // Creation date + QDate date; if (doc->IsDateVisible() == true) { - tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter; - tl.m_eFontWeight = QFont::Normal; - tl.m_eStyle = QFont::StyleNormal; - tl.m_iFontSize = 0; - QStringList qslDate = QDate::currentDate().toString(Qt::SystemLocaleLongDate).split(", "); - tl.m_qsText = qslDate.last(); - patternInfo->AddLine(tl); + date = QDate::currentDate(); } + patternInfo->UpdateData(doc->GetPatternName(), doc->GetPatternNumber(), doc->GetPatternSize(), + doc->GetCompanyName(), doc->GetCustomerName(), date); QPointF pt = geom.GetPos(); QRectF rectBB; From 28af32f027661177df38bc6475bc8d4b2fb320ff Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 22 Jul 2016 10:07:16 +0200 Subject: [PATCH 53/66] Removed unnecessary method call --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index a54d26812..6f487a7a8 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -490,7 +490,6 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de } det.SetPatternInfo(pDoc->GetPatternName(), pDoc->GetPatternNumber(), pDoc->GetPatternSize(), pDoc->GetCompanyName(), pDoc->GetCustomerName(), date, geom, qApp->font()); - qApp->getCurrentDocument(); } det.setWidth(qApp->toPixel(d.getWidth())); det.CreateTextItems(); From 0e7b369c2e8ed3cfe959d9f5221ab4b0e70a8d62 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 22 Jul 2016 11:56:45 +0200 Subject: [PATCH 54/66] Corrected all the issues reported by Roman till 10:11 AM --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 3 +- src/app/valentina/xml/vpattern.cpp | 41 ++++++++++++--------- src/libs/ifc/schema/pattern/v0.3.3.xsd | 35 +++++++++++++----- src/libs/ifc/xml/vabstractpattern.cpp | 10 ++--- src/libs/vlayout/vlayout.pro | 2 +- src/libs/vlayout/vlayoutdetail.cpp | 8 ++-- src/libs/vlayout/vlayoutdetail.h | 4 +- src/libs/vlayout/vtextmanager.cpp | 19 ++++++---- src/libs/vlayout/vtextmanager.h | 8 ++-- src/libs/vpatterndb/vpatternpiecedata.h | 16 +++++--- src/libs/vtools/tools/vtextgraphicsitem.cpp | 5 +-- src/libs/vtools/tools/vtextgraphicsitem.h | 3 +- src/libs/vtools/tools/vtooldetail.cpp | 9 +---- 13 files changed, 88 insertions(+), 75 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 6f487a7a8..6fe592e43 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -488,8 +488,7 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de { date = QDate::currentDate(); } - det.SetPatternInfo(pDoc->GetPatternName(), pDoc->GetPatternNumber(), pDoc->GetPatternSize(), - pDoc->GetCompanyName(), pDoc->GetCustomerName(), date, geom, qApp->font()); + det.SetPatternInfo(pDoc, geom, qApp->font()); } det.setWidth(qApp->toPixel(d.getWidth())); det.CreateTextItems(); diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 2d6133572..84aeea1d2 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -656,21 +656,27 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document } else if (element.tagName() == TagData) { - QString qsVisible = element.attribute(AttrVisible, "1"); - detail.GetPatternPieceData().SetVisible(qsVisible.toInt() != 0); - QString qsLetter = element.attribute(AttrLetter, ""); - detail.GetPatternPieceData().SetLetter(qsLetter); + bool bVisible = GetParametrBool(element, AttrVisible, trueStr); + detail.GetPatternPieceData().SetVisible(bVisible); + try + { + QString qsLetter = GetParametrString(element, AttrLetter, ""); + detail.GetPatternPieceData().SetLetter(qsLetter); + } catch(...) + { + detail.GetPatternPieceData().SetLetter(""); + } QPointF ptPos; - ptPos.setX(element.attribute(AttrMx, "0").toDouble()); - ptPos.setY(element.attribute(AttrMy, "0").toDouble()); + ptPos.setX(GetParametrDouble(element, AttrMx, "0")); + ptPos.setY(GetParametrDouble(element, AttrMy, "0")); detail.GetPatternPieceData().SetPos(ptPos); - qreal dLW = element.attribute(VToolDetail::AttrWidth, "0").toDouble(); + qreal dLW = GetParametrDouble(element, VToolDetail::AttrWidth, "0"); detail.GetPatternPieceData().SetLabelWidth(dLW); - qreal dLH = element.attribute(VToolDetail::AttrHeight, "0").toDouble(); + qreal dLH = GetParametrDouble(element, VToolDetail::AttrHeight, "0"); detail.GetPatternPieceData().SetLabelHeight(dLH); - int iFS = element.attribute(VToolDetail::AttrFont, "0").toInt(); + int iFS = GetParametrUInt(element, VToolDetail::AttrFont, "0"); detail.GetPatternPieceData().SetFontSize(iFS); - qreal dRot = element.attribute(VToolDetail::AttrRotation, "0").toDouble(); + qreal dRot = GetParametrDouble(element, VToolDetail::AttrRotation, "0"); detail.GetPatternPieceData().SetRotation(dRot); QDomNodeList nodeListMCP = element.childNodes(); @@ -687,24 +693,23 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document } else if (element.tagName() == TagPatternInfo) { - detail.GetPatternInfo().SetVisible(element.attribute(AttrVisible, "1").toInt() != 0); + detail.GetPatternInfo().SetVisible(GetParametrBool(element, AttrVisible, trueStr)); QPointF ptPos; - ptPos.setX(element.attribute(AttrMx, "0").toDouble()); - ptPos.setY(element.attribute(AttrMy, "0").toDouble()); + ptPos.setX(GetParametrDouble(element, AttrMx, "0")); + ptPos.setY(GetParametrDouble(element, AttrMy, "0")); detail.GetPatternInfo().SetPos(ptPos); - qreal dLW = element.attribute(VToolDetail::AttrWidth, "0").toDouble(); + qreal dLW = GetParametrDouble(element, VToolDetail::AttrWidth, "0"); detail.GetPatternInfo().SetLabelWidth(dLW); - qreal dLH = element.attribute(VToolDetail::AttrHeight, "0").toDouble(); + qreal dLH = GetParametrDouble(element, VToolDetail::AttrHeight, "0"); detail.GetPatternInfo().SetLabelHeight(dLH); - int iFS = element.attribute(VToolDetail::AttrFont, "0").toInt(); + int iFS = GetParametrUInt(element, VToolDetail::AttrFont, "0"); detail.GetPatternInfo().SetFontSize(iFS); - qreal dRot = element.attribute(VToolDetail::AttrRotation, "0").toDouble(); + qreal dRot = GetParametrDouble(element, VToolDetail::AttrRotation, "0"); detail.GetPatternInfo().SetRotation(dRot); } } } VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile); - SetVersion(); } catch (const VExceptionBadId &e) { diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd index 26f4b412f..2b7992a7d 100644 --- a/src/libs/ifc/schema/pattern/v0.3.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -18,12 +18,6 @@ - - - - - - @@ -79,6 +73,12 @@ + + + + + + @@ -346,13 +346,13 @@ - - + + - + @@ -363,7 +363,7 @@ - + @@ -552,4 +552,19 @@ + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index c4991b689..ddb870dd4 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1073,14 +1073,14 @@ void VAbstractPattern::SetPatternSize(QString qsSize) //--------------------------------------------------------------------------------------------------------------------- bool VAbstractPattern::IsDateVisible() const { - return UniqueTagText(TagShowDate) != QStringLiteral("false"); + return UniqueTagText(TagShowDate) != falseStr; } //--------------------------------------------------------------------------------------------------------------------- void VAbstractPattern::SetDateVisible(bool bVisible) { CheckTagExists(TagShowDate); - setTagText(TagShowDate, bVisible == true? QStringLiteral("true") : QStringLiteral("false")); + setTagText(TagShowDate, bVisible == true? trueStr : falseStr); modified = true; emit patternChanged(false); } @@ -1245,17 +1245,17 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) element = createElement(TagPatternName); break; } - case 7: // TagPatternName + case 7: // TagPatternNum { element = createElement(TagPatternNum); break; } - case 8: // TagPatternName + case 8: // TagCompanyName { element = createElement(TagCompanyName); break; } - case 9: // TagPatternName + case 9: // TagCustomerName { element = createElement(TagCustomerName); break; diff --git a/src/libs/vlayout/vlayout.pro b/src/libs/vlayout/vlayout.pro index 0a77c8638..de7ae8b22 100644 --- a/src/libs/vlayout/vlayout.pro +++ b/src/libs/vlayout/vlayout.pro @@ -7,7 +7,7 @@ # File with common stuff for whole project include(../../../common.pri) -QT += core gui widgets printsupport +QT += core gui widgets printsupport xml # Name of library TARGET = vlayout diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index 2de021f92..86e0e6f9e 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -133,7 +133,7 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da << QPointF(ptPos.x(), ptPos.y() + data.GetLabelHeight()); for (int i = 0; i < v.count(); ++i) { - v[i] = RotatePoint(ptCenter, v[i], dAng); + v[i] = RotatePoint(ptCenter, v.at(i), dAng); } d->detailLabel = RoundPoints(v); @@ -147,9 +147,7 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutDetail::SetPatternInfo(const QString& qsPattern, const QString& qsNumber, const QString& qsSize, - const QString& qsCompany, const QString& qsCustomer, const QDate& date, - const VPatternInfoGeometry& geom, const QFont &font) +void VLayoutDetail::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternInfoGeometry& geom, const QFont &font) { d->patternGeom = geom; qreal dAng = qDegreesToRadians(geom.GetRotation()); @@ -169,7 +167,7 @@ void VLayoutDetail::SetPatternInfo(const QString& qsPattern, const QString& qsNu m_tmPattern.SetFont(font); m_tmPattern.SetFontSize(geom.GetFontSize()); - m_tmPattern.Update(qsPattern, qsNumber, qsSize, qsCompany, qsCustomer, date); + m_tmPattern.Update(pDoc); // generate lines of text m_tmPattern.SetFontSize(geom.GetFontSize()); m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index e813fe9e3..4cd101a7a 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -60,9 +60,7 @@ public: void SetDetail(const QString &qsName, const VPatternPieceData& data, const QFont& font); - void SetPatternInfo(const QString& qsPattern, const QString& qsNumber, const QString& qsSize, - const QString& qsCompany, const QString& qsCustomer, const QDate& date, - const VPatternInfoGeometry& geom, const QFont& font); + void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternInfoGeometry& geom, const QFont& font); QTransform GetMatrix() const; void SetMatrix(const QTransform &matrix); diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 5793c0c92..0cadb02e4 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -155,8 +155,7 @@ void VTextManager::Update(const QString& qsName, const VPatternPieceData& data) } //--------------------------------------------------------------------------------------------------------------------- -void VTextManager::Update(const QString &qsPattern, const QString &qsNumber, const QString &qsSize, - const QString &qsCompany, const QString &qsCustomer, const QDate& date) +void VTextManager::Update(const VAbstractPattern *pDoc) { Clear(); TextLine tl; @@ -164,7 +163,7 @@ void VTextManager::Update(const QString &qsPattern, const QString &qsNumber, con tl.m_eAlign = Qt::AlignCenter; // Company name - tl.m_qsText = qsCompany; + tl.m_qsText = pDoc->GetCompanyName(); if (tl.m_qsText.isEmpty() == false) { tl.m_eFontWeight = QFont::DemiBold; @@ -173,7 +172,7 @@ void VTextManager::Update(const QString &qsPattern, const QString &qsNumber, con AddLine(tl); } // Pattern name - tl.m_qsText = qsPattern; + tl.m_qsText = pDoc->GetPatternName(); if (tl.m_qsText.isEmpty() == false) { tl.m_eFontWeight = QFont::Normal; @@ -182,7 +181,7 @@ void VTextManager::Update(const QString &qsPattern, const QString &qsNumber, con AddLine(tl); } // Pattern number - tl.m_qsText = qsNumber; + tl.m_qsText = pDoc->GetPatternNumber(); if (tl.m_qsText.isEmpty() == false) { tl.m_eFontWeight = QFont::Normal; @@ -191,7 +190,7 @@ void VTextManager::Update(const QString &qsPattern, const QString &qsNumber, con AddLine(tl); } // Customer name - tl.m_qsText = qsCustomer; + tl.m_qsText = pDoc->GetCustomerName(); if (tl.m_qsText.isEmpty() == false) { tl.m_eFontWeight = QFont::Normal; @@ -200,7 +199,7 @@ void VTextManager::Update(const QString &qsPattern, const QString &qsNumber, con AddLine(tl); } // Size - tl.m_qsText = qsSize; + tl.m_qsText = pDoc->GetPatternSize(); if (tl.m_qsText.isEmpty() == false) { tl.m_eFontWeight = QFont::Normal; @@ -209,6 +208,11 @@ void VTextManager::Update(const QString &qsPattern, const QString &qsNumber, con AddLine(tl); } // Date + QDate date; + if (pDoc->IsDateVisible() == true) + { + date = QDate::currentDate(); + } if (date.isValid() == true) { tl.m_qsText = date.toString("dd MMMM yyyy"); @@ -217,6 +221,7 @@ void VTextManager::Update(const QString &qsPattern, const QString &qsNumber, con tl.m_iFontSize = 0; AddLine(tl); } + } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index 167073f73..e3bc52f47 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -6,6 +6,7 @@ #include #include "../vpatterndb/vpatternpiecedata.h" +#include "../ifc/xml/vabstractpattern.h" #define MIN_FONT_SIZE 12 #define MAX_FONT_SIZE 128 @@ -43,12 +44,9 @@ public: * Updates the manager with detail name and detail data */ void Update(const QString& qsName, const VPatternPieceData& data); - /** @brief Updateconst QString& qsPattern, const QString& qsNumber, const QString& qsSize, - const QString& qsCompany, const QString& qsCustomer, const QDate& date) - Updates the manager with pattern data + /** @brief Update(const VAbstractPattern* pDoc) updates the manager with pattern data */ - void Update(const QString& qsPattern, const QString& qsNumber, const QString& qsSize, - const QString& qsCompany, const QString& qsCustomer, const QDate& date); + void Update(const VAbstractPattern* pDoc); protected: QStringList SplitString(const QString& qs, qreal fW, const QFontMetrics& fm); diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h index 833249f2d..65051a09d 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -37,14 +37,18 @@ enum class MaterialType : char { - mtFabric, - mtLining, - mtInterfacing, - mtInterlining, - mtUserDefined + mtFabric = 0, + mtLining = 1, + mtInterfacing = 2, + mtInterlining = 3, + mtUserDefined = 4 }; -enum class PlacementType : char { ptNone, ptCutOnFold }; +enum class PlacementType : char +{ + ptNone = 0, + ptCutOnFold = 1 +}; /** * @brief This structure holds a material, cut number and placement 3-tuple diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index f739c973e..06d7af6b6 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -227,10 +227,9 @@ void VTextGraphicsItem::UpdateData(const QString &qsName, const VPatternPieceDat } //--------------------------------------------------------------------------------------------------------------------- -void VTextGraphicsItem::UpdateData(const QString &qsPattern, const QString &qsNumber, const QString &qsSize, - const QString &qsCompany, const QString &qsCustomer, const QDate &date) +void VTextGraphicsItem::UpdateData(const VAbstractPattern* pDoc) { - m_tm.Update(qsPattern, qsNumber, qsSize, qsCompany, qsCustomer, date); + m_tm.Update(pDoc); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 29f9e39a9..14a585d9a 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -63,8 +63,7 @@ public: void Update(); bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const; void UpdateData(const QString& qsName, const VPatternPieceData& data); - void UpdateData(const QString& qsPattern, const QString& qsNumber, const QString& qsSize, - const QString& qsCompany, const QString& qsCustomer, const QDate& date); + void UpdateData(const VAbstractPattern* pDoc); protected: void mousePressEvent(QGraphicsSceneMouseEvent* pME); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index ec757abbd..c73425416 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -730,14 +730,7 @@ void VToolDetail::UpdatePatternInfo() fnt.setPixelSize(iFS); patternInfo->SetFont(fnt); patternInfo->SetSize(geom.GetLabelWidth(), geom.GetLabelHeight()); - - QDate date; - if (doc->IsDateVisible() == true) - { - date = QDate::currentDate(); - } - patternInfo->UpdateData(doc->GetPatternName(), doc->GetPatternNumber(), doc->GetPatternSize(), - doc->GetCompanyName(), doc->GetCustomerName(), date); + patternInfo->UpdateData(doc); QPointF pt = geom.GetPos(); QRectF rectBB; From 455befa4935c9476cd6c5af8506cef3ecc580cdc Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 22 Jul 2016 12:40:02 +0200 Subject: [PATCH 55/66] Removed printf commands, added Q_REQUIRED_RESULT macros, replaced v[i] with v.at(i) where needed, replaced 1,0 with true,false when creating boolean XML attributes --HG-- branch : feature --- src/libs/ifc/xml/vabstractpattern.cpp | 10 +++++----- src/libs/ifc/xml/vabstractpattern.h | 10 +++++----- src/libs/vlayout/vlayoutdetail.cpp | 4 +--- src/libs/vlayout/vlayoutdetail.h | 4 ++-- src/libs/vtools/undocommands/savedetailoptions.cpp | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index ddb870dd4..46b85959e 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -1002,7 +1002,7 @@ QString VAbstractPattern::GetPatternName() const } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetPatternName(QString qsName) +void VAbstractPattern::SetPatternName(const QString &qsName) { CheckTagExists(TagPatternName); setTagText(TagPatternName, qsName); @@ -1017,7 +1017,7 @@ QString VAbstractPattern::GetCompanyName() const } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetCompanyName(QString qsName) +void VAbstractPattern::SetCompanyName(const QString& qsName) { CheckTagExists(TagCompanyName); setTagText(TagCompanyName, qsName); @@ -1032,7 +1032,7 @@ QString VAbstractPattern::GetPatternNumber() const } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetPatternNumber(QString qsNum) +void VAbstractPattern::SetPatternNumber(const QString& qsNum) { CheckTagExists(TagPatternNum); setTagText(TagPatternNum, qsNum); @@ -1047,7 +1047,7 @@ QString VAbstractPattern::GetCustomerName() const } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetCustomerName(QString qsName) +void VAbstractPattern::SetCustomerName(const QString& qsName) { CheckTagExists(TagCustomerName); setTagText(TagCustomerName, qsName); @@ -1062,7 +1062,7 @@ QString VAbstractPattern::GetPatternSize() const } //--------------------------------------------------------------------------------------------------------------------- -void VAbstractPattern::SetPatternSize(QString qsSize) +void VAbstractPattern::SetPatternSize(const QString& qsSize) { CheckTagExists(TagSize); setTagText(TagSize, qsSize); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index f5f94ff5e..18c55c313 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -109,15 +109,15 @@ public: void SetNotes(const QString &text); QString GetPatternName() const; - void SetPatternName(QString qsName); + void SetPatternName(const QString& qsName); QString GetCompanyName() const; - void SetCompanyName(QString qsName); + void SetCompanyName(const QString& qsName); QString GetPatternNumber() const; - void SetPatternNumber(QString qsNum); + void SetPatternNumber(const QString &qsNum); QString GetCustomerName() const; - void SetCustomerName(QString qsName); + void SetCustomerName(const QString& qsName); QString GetPatternSize() const; - void SetPatternSize(QString qsSize); + void SetPatternSize(const QString &qsSize); bool IsDateVisible() const; void SetDateVisible(bool bVisible); diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index 86e0e6f9e..419a0089d 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) # include "../vmisc/vmath.h" @@ -159,7 +158,7 @@ void VLayoutDetail::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternI << QPointF(ptPos.x(), ptPos.y() + geom.GetLabelHeight()); for (int i = 0; i < v.count(); ++i) { - v[i] = RotatePoint(ptCenter, v[i], dAng); + v[i] = RotatePoint(ptCenter, v.at(i), dAng); } d->patternInfo = RoundPoints(v); @@ -543,7 +542,6 @@ void VLayoutDetail::CreateTextItems() qreal dW = GetDistance(points.at(0), points.at(1)); qreal dY = 0; qreal dX; - printf("Pattern lines %d %d\n", m_tmPattern.GetCount(), m_tmPattern.GetSourceLineCount()); for (int i = 0; i < m_tmPattern.GetCount(); ++i) { const TextLine& tl = m_tmPattern.GetLine(i); diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index 4cd101a7a..3672c8093 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -88,8 +88,8 @@ public: QPainterPath ContourPath() const; void ClearTextItems(); void CreateTextItems(); - int GetTextItemsCount() const; - QGraphicsItem* GetTextItem(int i) const; + int GetTextItemsCount() const Q_REQUIRED_RESULT; + QGraphicsItem* GetTextItem(int i) const Q_REQUIRED_RESULT; QPainterPath LayoutAllowencePath() const; QGraphicsItem *GetItem() const Q_REQUIRED_RESULT; diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 85320bcd4..1aadf15f6 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -139,7 +139,7 @@ void SaveDetailOptions::SavePatternPieceData(QDomElement &domElement, const VDet QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = det.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? 1:0); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? trueStr : falseStr); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth()); @@ -165,7 +165,7 @@ void SaveDetailOptions::SavePatternInfo(QDomElement &domElement, const VDetail & { QDomElement domData = doc->createElement(VAbstractPattern::TagPatternInfo); const VPatternInfoGeometry& data = det.GetPatternInfo(); - doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? 1:0); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? trueStr : falseStr); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, VToolDetail::AttrWidth, data.GetLabelWidth()); From 03482fb9a8191f14970b9affe5aeab4b0a0f99fa Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 22 Jul 2016 12:50:21 +0200 Subject: [PATCH 56/66] Moved m_tmDetail, m_tmPattern and m_liPP from VLayoutDetail into VLayoutDetailData class --HG-- branch : feature --- src/libs/vlayout/vlayoutdetail.cpp | 60 ++++++++++++++---------------- src/libs/vlayout/vlayoutdetail.h | 3 -- src/libs/vlayout/vlayoutdetail_p.h | 14 ++++++- 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index 419a0089d..bcd904037 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -45,13 +45,12 @@ //--------------------------------------------------------------------------------------------------------------------- VLayoutDetail::VLayoutDetail() - :VAbstractDetail(), d(new VLayoutDetailData), m_tmDetail(), m_tmPattern(), m_liPP() + :VAbstractDetail(), d(new VLayoutDetailData) {} //--------------------------------------------------------------------------------------------------------------------- VLayoutDetail::VLayoutDetail(const VLayoutDetail &detail) - :VAbstractDetail(detail), d(detail.d), m_tmDetail(detail.m_tmDetail), m_tmPattern(detail.m_tmPattern), - m_liPP(detail.m_liPP) + :VAbstractDetail(detail), d(detail.d) {} //--------------------------------------------------------------------------------------------------------------------- @@ -63,9 +62,6 @@ VLayoutDetail &VLayoutDetail::operator=(const VLayoutDetail &detail) } VAbstractDetail::operator=(detail); d = detail.d; - m_tmDetail = detail.m_tmDetail; - m_tmPattern = detail.m_tmPattern; - m_liPP = detail.m_liPP; return *this; } @@ -137,12 +133,12 @@ void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& da d->detailLabel = RoundPoints(v); // generate text - m_tmDetail.SetFont(font); - m_tmDetail.SetFontSize(data.GetFontSize()); - m_tmDetail.Update(qsName, data); + d->m_tmDetail.SetFont(font); + d->m_tmDetail.SetFontSize(data.GetFontSize()); + d->m_tmDetail.Update(qsName, data); // this will generate the lines of text - m_tmDetail.SetFontSize(data.GetFontSize()); - m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight()); + d->m_tmDetail.SetFontSize(data.GetFontSize()); + d->m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight()); } //--------------------------------------------------------------------------------------------------------------------- @@ -163,13 +159,13 @@ void VLayoutDetail::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternI d->patternInfo = RoundPoints(v); // Generate text - m_tmPattern.SetFont(font); - m_tmPattern.SetFontSize(geom.GetFontSize()); + d->m_tmPattern.SetFont(font); + d->m_tmPattern.SetFontSize(geom.GetFontSize()); - m_tmPattern.Update(pDoc); + d->m_tmPattern.Update(pDoc); // generate lines of text - m_tmPattern.SetFontSize(geom.GetFontSize()); - m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); + d->m_tmPattern.SetFontSize(geom.GetFontSize()); + d->m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); } //--------------------------------------------------------------------------------------------------------------------- @@ -486,7 +482,7 @@ QPainterPath VLayoutDetail::ContourPath() const //--------------------------------------------------------------------------------------------------------------------- void VLayoutDetail::ClearTextItems() { - m_liPP.clear(); + d->m_liPP.clear(); } //--------------------------------------------------------------------------------------------------------------------- @@ -502,11 +498,11 @@ void VLayoutDetail::CreateTextItems() qreal dW = GetDistance(points.at(0), points.at(1)); qreal dY = 0; qreal dX; - for (int i = 0; i < m_tmDetail.GetCount(); ++i) + for (int i = 0; i < d->m_tmDetail.GetCount(); ++i) { - const TextLine& tl = m_tmDetail.GetLine(i); - QFont fnt = m_tmDetail.GetFont(); - fnt.setPixelSize(m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize); + const TextLine& tl = d->m_tmDetail.GetLine(i); + QFont fnt = d->m_tmDetail.GetFont(); + fnt.setPixelSize(d->m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize); fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); dY += tl.m_iHeight; @@ -529,8 +525,8 @@ void VLayoutDetail::CreateTextItems() } QPainterPath path; path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, tl.m_qsText); - m_liPP << mat.map(path); - dY += m_tmDetail.GetSpacing(); + d->m_liPP << mat.map(path); + dY += d->m_tmDetail.GetSpacing(); } } // and then add pattern texts @@ -542,11 +538,11 @@ void VLayoutDetail::CreateTextItems() qreal dW = GetDistance(points.at(0), points.at(1)); qreal dY = 0; qreal dX; - for (int i = 0; i < m_tmPattern.GetCount(); ++i) + for (int i = 0; i < d->m_tmPattern.GetCount(); ++i) { - const TextLine& tl = m_tmPattern.GetLine(i); - QFont fnt = m_tmPattern.GetFont(); - fnt.setPixelSize(m_tmPattern.GetFont().pixelSize() + tl.m_iFontSize); + const TextLine& tl = d->m_tmPattern.GetLine(i); + QFont fnt = d->m_tmPattern.GetFont(); + fnt.setPixelSize(d->m_tmPattern.GetFont().pixelSize() + tl.m_iFontSize); fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); dY += tl.m_iHeight; @@ -569,8 +565,8 @@ void VLayoutDetail::CreateTextItems() } QPainterPath path; path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, tl.m_qsText); - m_liPP << mat.map(path); - dY += m_tmPattern.GetSpacing(); + d->m_liPP << mat.map(path); + dY += d->m_tmPattern.GetSpacing(); } } } @@ -578,7 +574,7 @@ void VLayoutDetail::CreateTextItems() //--------------------------------------------------------------------------------------------------------------------- int VLayoutDetail::GetTextItemsCount() const { - return m_liPP.count(); + return d->m_liPP.count(); } //--------------------------------------------------------------------------------------------------------------------- @@ -587,12 +583,12 @@ QGraphicsItem* VLayoutDetail::GetTextItem(int i) const QGraphicsPathItem* item = new QGraphicsPathItem(); QTransform transform = d->matrix; - QPainterPath path = transform.map(m_liPP[i]); + QPainterPath path = transform.map(d->m_liPP[i]); if (d->mirror == true) { QVector points; - if (i < m_tmDetail.GetCount()) + if (i < d->m_tmDetail.GetCount()) { points = Map(Mirror(d->detailLabel)); } diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index 3672c8093..e90e1b0c4 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -95,9 +95,6 @@ public: private: QSharedDataPointer d; - VTextManager m_tmDetail; - VTextManager m_tmPattern; - QList m_liPP; QVector Map(const QVector &points) const; static QVector RoundPoints(const QVector &points); diff --git a/src/libs/vlayout/vlayoutdetail_p.h b/src/libs/vlayout/vlayoutdetail_p.h index 77afa5ca7..01995de98 100644 --- a/src/libs/vlayout/vlayoutdetail_p.h +++ b/src/libs/vlayout/vlayoutdetail_p.h @@ -36,6 +36,8 @@ #include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatterninfogeometry.h" +#include "vtextmanager.h" + #ifdef Q_CC_GNU #pragma GCC diagnostic push @@ -48,14 +50,16 @@ public: VLayoutDetailData() :contour(QVector()), seamAllowence(QVector()), layoutAllowence(QVector()), matrix(QMatrix()), layoutWidth(0), mirror(false), detailLabel(QVector()), - patternInfo(QVector()), detailData(), patternGeom() + patternInfo(QVector()), detailData(), patternGeom(), m_tmDetail(), + m_tmPattern(), m_liPP(QList()) {} VLayoutDetailData(const VLayoutDetailData &detail) :QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence), layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), layoutWidth(detail.layoutWidth), mirror(detail.mirror), detailLabel(detail.detailLabel), - patternInfo(detail.patternInfo), detailData(detail.detailData), patternGeom(detail.patternGeom) + patternInfo(detail.patternInfo), detailData(detail.detailData), patternGeom(detail.patternGeom), + m_tmDetail(detail.m_tmDetail), m_tmPattern(detail.m_tmPattern), m_liPP(detail.m_liPP) {} ~VLayoutDetailData() {} @@ -85,6 +89,12 @@ public: VPatternPieceData detailData; /** @brief patternGeom pattern geometry */ VPatternInfoGeometry patternGeom; + /** @brief m_tmDetail text manager for laying out detail info */ + VTextManager m_tmDetail; + /** @brief m_tmPattern text manager for laying out pattern info */ + VTextManager m_tmPattern; + /** @bried m_liPP list of generated text painter paths */ + QList m_liPP; private: VLayoutDetailData &operator=(const VLayoutDetailData &) Q_DECL_EQ_DELETE; From a625c3561628e6f96db590c53765a1649c8778be Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 23 Jul 2016 15:26:15 +0200 Subject: [PATCH 57/66] Added comments to most important new classes --HG-- branch : feature --- src/libs/vlayout/vlayoutdetail.cpp | 54 ++++++-- src/libs/vlayout/vlayoutdetail.h | 3 +- src/libs/vlayout/vtextmanager.cpp | 79 ++++++++++++ src/libs/vlayout/vtextmanager.h | 14 ++- src/libs/vpatterndb/vpatterninfogeometry.h | 21 +++- src/libs/vpatterndb/vpatternpiecedata.h | 26 ++-- src/libs/vtools/tools/vtextgraphicsitem.cpp | 130 +++++++++++++++++++- src/libs/vtools/tools/vtextgraphicsitem.h | 5 + src/libs/vtools/tools/vtooldetail.cpp | 8 +- 9 files changed, 303 insertions(+), 37 deletions(-) diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index bcd904037..aae990633 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -492,12 +492,21 @@ void VLayoutDetail::CreateTextItems() // first add detail texts if (d->detailLabel.count() > 0) { + // get the mapped label vertices QVector points = Map(Mirror(d->detailLabel)); + // append the first point to obtain the closed rectangle points.push_back(points.at(0)); + // calculate the angle of rotation qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x()); + // calculate the label width qreal dW = GetDistance(points.at(0), points.at(1)); qreal dY = 0; qreal dX; + // set up the rotation around top-left corner matrix + QMatrix mat; + mat.translate(points.at(0).x(), points.at(0).y()); + mat.rotate(qRadiansToDegrees(dAng)); + for (int i = 0; i < d->m_tmDetail.GetCount(); ++i) { const TextLine& tl = d->m_tmDetail.GetLine(i); @@ -506,11 +515,9 @@ void VLayoutDetail::CreateTextItems() fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); dY += tl.m_iHeight; - QMatrix mat; - mat.translate(points.at(0).x(), points.at(0).y()); - mat.rotate(qRadiansToDegrees(dAng)); QFontMetrics fm(fnt); + // find the correct horizontal offset, depending on the alignment flag if ((tl.m_eAlign & Qt::AlignLeft) > 0) { dX = 0; @@ -523,6 +530,7 @@ void VLayoutDetail::CreateTextItems() { dX = dW - fm.width(tl.m_qsText); } + // create text path and add it to the list QPainterPath path; path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, tl.m_qsText); d->m_liPP << mat.map(path); @@ -532,12 +540,17 @@ void VLayoutDetail::CreateTextItems() // and then add pattern texts if (d->patternInfo.count() > 0) { + // similar approach like for the detail label QVector points = Map(Mirror(d->patternInfo)); points.push_back(points.at(0)); qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x()); qreal dW = GetDistance(points.at(0), points.at(1)); qreal dY = 0; qreal dX; + QMatrix mat; + mat.translate(points.at(0).x(), points.at(0).y()); + mat.rotate(qRadiansToDegrees(dAng)); + for (int i = 0; i < d->m_tmPattern.GetCount(); ++i) { const TextLine& tl = d->m_tmPattern.GetLine(i); @@ -546,9 +559,6 @@ void VLayoutDetail::CreateTextItems() fnt.setWeight(tl.m_eFontWeight); fnt.setStyle(tl.m_eStyle); dY += tl.m_iHeight; - QMatrix mat; - mat.translate(points.at(0).x(), points.at(0).y()); - mat.rotate(qRadiansToDegrees(dAng)); QFontMetrics fm(fnt); if ((tl.m_eAlign & Qt::AlignLeft) > 0) @@ -578,6 +588,11 @@ int VLayoutDetail::GetTextItemsCount() const } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VLayoutDetail::GetTextItem Creates and returns the i-th text item + * @param i index of the requested item + * @return pointer to the newly created item. The caller is responsible to delete it. + */ QGraphicsItem* VLayoutDetail::GetTextItem(int i) const { QGraphicsPathItem* item = new QGraphicsPathItem(); @@ -600,12 +615,18 @@ QGraphicsItem* VLayoutDetail::GetTextItem(int i) const qreal dRot = qRadiansToDegrees(qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x())); // we need to move the center back to the origin, rotate it to align it with x axis, - // then mirror it to obtain the proper text direction, rotate it and translate it back to original position + // then mirror it to obtain the proper text direction, rotate it and translate it back to original position. + // The operations must be added in reverse order QTransform t; + // move the label back to its original position t.translate(ptCenter.x(), ptCenter.y()); + // rotate the label back to original angle t.rotate(dRot); + // mirror the label horizontally t.scale(-1, 1); + // rotate the label to normal position t.rotate(-dRot); + // move the label center into origin t.translate(-ptCenter.x(), -ptCenter.y()); path = t.map(path); } @@ -653,6 +674,13 @@ void VLayoutDetail::SetMirror(bool value) } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VLayoutDetail::RotatePoint rotates a point around the center for given angle + * @param ptCenter center around which the point is rotated + * @param pt point, which is rotated around the center + * @param dAng angle of rotation + * @return position of point pt after rotating it around the center for dAng radians + */ QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) const { QPointF ptDest; @@ -664,6 +692,12 @@ QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, q } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VLayoutDetail::Mirror if the detail layout is rotated, this method will flip the + * label points over vertical axis, which goes through the center of the label + * @param list of 4 label vertices + * @return list of flipped points + */ QVector VLayoutDetail::Mirror(const QVector &points) const { // should only call this method with rectangular shapes @@ -683,6 +717,12 @@ QVector VLayoutDetail::Mirror(const QVector &points) const } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VLayoutDetail::GetDistance calculates the Euclidian distance between the points + * @param pt1 first point + * @param pt2 second point + * @return Euclidian distance between the two points + */ qreal VLayoutDetail::GetDistance(const QPointF &pt1, const QPointF &pt2) const { qreal dX = pt1.x() - pt2.x(); diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index e90e1b0c4..56cb5aff0 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -32,7 +32,8 @@ #include "vabstractdetail.h" #include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatterninfogeometry.h" -#include "vtextmanager.h" +#include "../ifc/xml/vabstractpattern.h" + #include #include diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 0cadb02e4..9a996b16c 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -4,75 +4,128 @@ #include "vtextmanager.h" //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief TextLine::TextLine default constructor + */ TextLine::TextLine() :m_qsText(), m_iFontSize(MIN_FONT_SIZE), m_eFontWeight(QFont::Normal), m_eStyle(QFont::StyleNormal), m_eAlign(Qt::AlignCenter), m_iHeight(0) {} //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::VTextManager constructor + */ VTextManager::VTextManager() :m_font(), m_liLines(), m_liOutput() {} //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::~VTextManager destructor + */ VTextManager::~VTextManager() {} //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::GetSpacing returns the vertical spacing between the lines + * @return + */ int VTextManager::GetSpacing() const { return 2; } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::SetFont set the text base font + * @param font text base font + */ void VTextManager::SetFont(const QFont& font) { m_font = font; } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::GetFont returns the text base font + * @return text base font + */ const QFont& VTextManager::GetFont() const { return m_font; } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::SetFontSize sets the font size + * @param iFS font size in pixels + */ void VTextManager::SetFontSize(int iFS) { m_font.setPixelSize(iFS); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::AddLine add new text line to the list + * @param tl text line object to be added + */ void VTextManager::AddLine(const TextLine& tl) { m_liLines << tl; } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::Clear deletes the list of texts + */ void VTextManager::Clear() { m_liLines.clear(); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::GetCount returns the number of output text lines + * @return number of output text lines + */ int VTextManager::GetCount() const { return m_liOutput.count(); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::GetSourceLineCount returns the number of input text lines + * @return number of text lines that were added to the list by calling AddLine + */ int VTextManager::GetSourceLineCount() const { return m_liLines.count(); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::GetLine returns the i-th output text line + * @param i index of the output text line + * @return i-th output text line + */ const TextLine& VTextManager::GetLine(int i) const { return m_liOutput[i]; } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::IsBigEnough Checks if rectangle of size (fW, fH) is big enough to hold the text with base font + * size iFontSize + * @param fW rectangle width + * @param fH rectangle height + * @param iFontSize base font size + * @return true, if rectangle of size (fW, fH) + */ bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) { m_liOutput.clear(); @@ -97,6 +150,12 @@ bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::FitFontSize sets the font size just big enough, so that the text fits into rectangle of + * size (fW, fH) + * @param fW rectangle width + * @param fH rectangle height + */ void VTextManager::FitFontSize(qreal fW, qreal fH) { int iFontSize = GetFont().pixelSize(); @@ -112,6 +171,11 @@ void VTextManager::FitFontSize(qreal fW, qreal fH) } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::Update updates the text lines with detail data + * @param qsName detail name + * @param data reference to the detail data + */ void VTextManager::Update(const QString& qsName, const VPatternPieceData& data) { Clear(); @@ -155,6 +219,10 @@ void VTextManager::Update(const QString& qsName, const VPatternPieceData& data) } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::Update updates the text lines with pattern info + * @param pDoc pointer to the abstract pattern object + */ void VTextManager::Update(const VAbstractPattern *pDoc) { Clear(); @@ -225,9 +293,17 @@ void VTextManager::Update(const VAbstractPattern *pDoc) } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextManager::SplitString splits the string into several lines, which all fit into width fW + * @param qs string to split + * @param fW required width of every output string + * @param fm font metrics of the font used + * @return list of strings, each of which is not wider than fW using the font metrics fm + */ QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMetrics &fm) { QRegularExpression reg("\\s+"); + // split the string into words QStringList qslWords = qs.split(reg); QStringList qslLines; QString qsCurrent; @@ -237,9 +313,12 @@ QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMe { qsCurrent += QLatin1Literal(" "); } + // check if another word can be added into current line if (fm.width(qsCurrent + qslWords[i]) > fW) { + // if not, add the current line into the list of text lines qslLines << qsCurrent; + // and set the current line to contain the current word qsCurrent = qslWords[i]; } else diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index e3bc52f47..1fa5a48de 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -11,6 +11,9 @@ #define MIN_FONT_SIZE 12 #define MAX_FONT_SIZE 128 +/** + * @brief The TextLine struct holds the information about one text line + */ struct TextLine { QString m_qsText; @@ -23,13 +26,17 @@ struct TextLine TextLine(); }; +/** + * @brief The VTextManager class this class is used to determine whether a collection of + * text lines can fit into specified bounding box and with what font size + */ class VTextManager { public: VTextManager(); ~VTextManager(); - int GetSpacing() const; + virtual int GetSpacing() const; void SetFont(const QFont& font); const QFont& GetFont() const; void SetFontSize(int iFS); @@ -40,12 +47,7 @@ public: const TextLine& GetLine(int i) const; bool IsBigEnough(qreal fW, qreal fH, int iFontSize); void FitFontSize(qreal fW, qreal fH); - /** @brief Update(const QString& qsName, const VPatternPieceData& data) - * Updates the manager with detail name and detail data - */ void Update(const QString& qsName, const VPatternPieceData& data); - /** @brief Update(const VAbstractPattern* pDoc) updates the manager with pattern data - */ void Update(const VAbstractPattern* pDoc); protected: diff --git a/src/libs/vpatterndb/vpatterninfogeometry.h b/src/libs/vpatterndb/vpatterninfogeometry.h index 0f9ff5cfd..6bb562fa1 100644 --- a/src/libs/vpatterndb/vpatterninfogeometry.h +++ b/src/libs/vpatterndb/vpatterninfogeometry.h @@ -33,6 +33,9 @@ #include +/** + * @brief The VPatternInfoGeometry class holds the information about pattern info label geometry + */ class VPatternInfoGeometry { public: @@ -54,20 +57,28 @@ public: void SetVisible(bool bVal); private: + /** + * @brief m_ptPos position of label's top left corner + */ QPointF m_ptPos; - /** @brief Label width + /** + * @brief m_dLabelWidth label width */ qreal m_dLabelWidth; - /** @brief Label height + /** + * @brief m_dLabelHeight label height */ qreal m_dLabelHeight; - /** @brief Label font size + /** + * @brief m_iFontSize label text base font size */ int m_iFontSize; - /** @brief Label rotation + /** + * @brief m_dRotation Label rotation */ qreal m_dRotation; - /** @brief Visibility flag + /** + * @brief m_bVisible visibility flag */ bool m_bVisible; diff --git a/src/libs/vpatterndb/vpatternpiecedata.h b/src/libs/vpatterndb/vpatternpiecedata.h index 65051a09d..0852b5724 100644 --- a/src/libs/vpatterndb/vpatternpiecedata.h +++ b/src/libs/vpatterndb/vpatternpiecedata.h @@ -51,7 +51,7 @@ enum class PlacementType : char }; /** - * @brief This structure holds a material, cut number and placement 3-tuple + * @brief The MaterialCutPlacement struct used to hold a material, cut number and placement 3-tuple */ struct MaterialCutPlacement { @@ -103,28 +103,36 @@ public: void SetVisible(bool bVal); private: - /** @brief Pattern piece letter (should be no more than 3 letters) + /** + * @brief m_qsLetter Detail letter (should be no more than 3 characters) */ QString m_qsLetter; - /** @brief List of material, cut number and placement 3-tuples + /** + * @brief m_conMCP List of material, cut, placement tuples */ MCPContainer m_conMCP; - /** @brief Location of the label + /** + * @brief m_ptPos position of label's top left corner */ QPointF m_ptPos; - /** @brief Label width + /** + * @brief m_dLabelWidth label width */ qreal m_dLabelWidth; - /** @brief Label height + /** + * @brief m_dLabelHeight label height */ qreal m_dLabelHeight; - /** @brief Label font size + /** + * @brief m_iFontSize label font size */ int m_iFontSize; - /** @brief Label rotation + /** + * @brief m_dRotation label rotation */ qreal m_dRotation; - /** @brief Visibility flag + /** + * @brief m_bVisible visibility flag */ bool m_bVisible; diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 06d7af6b6..06d1649fc 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -47,6 +47,10 @@ #define TOP_Z 2 //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::VTextGraphicsItem constructor + * @param pParent pointer to the parent item + */ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) :QGraphicsObject(pParent), m_eMode(VTextGraphicsItem::mNormal), m_bReleased(false), m_ptStartPos(), m_ptStart(), m_ptRotCenter(), m_szStart(), m_dRotation(0), m_dAngle(0), @@ -58,21 +62,34 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::~VTextGraphicsItem destructor + */ VTextGraphicsItem::~VTextGraphicsItem() {} //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::SetFont sets the item font + * @param fnt font to be used in item + */ void VTextGraphicsItem::SetFont(const QFont& fnt) { m_tm.SetFont(fnt); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::paint redraws the item content + * @param painter pointer to the QPainter in use + * @param option pointer to the object containing the actual label rectangle + * @param widget not used + */ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(widget); painter->fillRect(option->rect, QColor(251, 251, 175)); - painter->setRenderHints(QPainter::Antialiasing); + painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); // draw text lines int iY = 0; @@ -91,26 +108,30 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem iY += iH + m_tm.GetSpacing(); } - + // now draw the features specific to non-normal modes if (m_eMode != mNormal) { + // outline the rectangle painter->setPen(QPen(Qt::black, 2, Qt::DashLine)); painter->drawRect(boundingRect().adjusted(1, 1, -1, -1)); if (m_eMode != mRotate) { + // draw the resize square painter->setPen(Qt::black); painter->setBrush(Qt::black); painter->drawRect(m_rectResize); if (m_eMode == mResize) { + // draw the resize diagonal lines painter->drawLine(0, 0, qRound(m_rectBoundingBox.width()), qRound(m_rectBoundingBox.height())); painter->drawLine(0, qRound(m_rectBoundingBox.height()), qRound(m_rectBoundingBox.width()), 0); } } else { + // in rotate mode, draw the circle in the middle painter->setPen(Qt::black); painter->setBrush(Qt::black); painter->drawEllipse( @@ -120,6 +141,7 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem ); painter->setPen(QPen(Qt::black, 3)); painter->setBrush(Qt::NoBrush); + // and then draw the arc in each of the corners int iTop = ROTATE_RECT - ROTATE_ARC; int iLeft = ROTATE_RECT - ROTATE_ARC; int iRight = qRound(m_rectBoundingBox.width()) - ROTATE_RECT; @@ -133,6 +155,9 @@ void VTextGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::Reset resets the item, putting the mode and z coordinate to normal and redraws it + */ void VTextGraphicsItem::Reset() { m_eMode = mNormal; @@ -142,6 +167,11 @@ void VTextGraphicsItem::Reset() } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::AddLine adds a line of text to the label list. If necessary, it also resizes the + * label bounding box until it is big enough to contain all the text + * @param tl line of text to add + */ void VTextGraphicsItem::AddLine(const TextLine& tl) { m_tm.AddLine(tl); @@ -156,12 +186,21 @@ void VTextGraphicsItem::AddLine(const TextLine& tl) } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::Clear deletes all the label texts + */ void VTextGraphicsItem::Clear() { m_tm.Clear(); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::SetSize Tries to set the label size to (fW, fH). If any of those is too small, the label + * size does not change. + * @param fW label width + * @param fH label height + */ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) { // don't allow resize under specific size @@ -181,6 +220,9 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::Update sets the correct font size and redraws the label + */ void VTextGraphicsItem::Update() { UpdateFont(); @@ -188,6 +230,16 @@ void VTextGraphicsItem::Update() } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::IsContained checks if the bounding box around rotated rectBB is contained in + * the parent. If that is not the case, it calculates the amount of movement needed to put it inside the parent + * and write it into dX, dY + * @param rectBB bounding box in question + * @param dRot bounding box rotation in degrees + * @param dX horizontal translation needed to put the box inside parent item + * @param dY vertical translation needed to put the box inside parent item + * @return true, if rectBB is contained in parent item and false otherwise + */ bool VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal &dY) const { QRectF rectParent = parentItem()->boundingRect(); @@ -221,42 +273,68 @@ bool VTextGraphicsItem::IsContained(QRectF rectBB, qreal dRot, qreal &dX, qreal } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::UpdateData Updates the detail label + * @param qsName name of detail + * @param data reference to VPatternPieceData + */ void VTextGraphicsItem::UpdateData(const QString &qsName, const VPatternPieceData &data) { m_tm.Update(qsName, data); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::UpdateData Updates the pattern label + * @param pDoc pointer to the pattern object + */ void VTextGraphicsItem::UpdateData(const VAbstractPattern* pDoc) { m_tm.Update(pDoc); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::GetFontSize returns the currently used text base font size + * @return current text base font size + */ int VTextGraphicsItem::GetFontSize() const { return m_tm.GetFont().pixelSize(); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::boundingRect returns the label bounding box + * @return label bounding box + */ QRectF VTextGraphicsItem::boundingRect() const { return m_rectBoundingBox; } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::mousePressEvent handles left button mouse press events + * @param pME pointer to QGraphicsSceneMouseEvent object + */ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { if (pME->button() == Qt::LeftButton) { + // record the parameters of the mouse press. Specially record the position + // of the press as the origin for the following operations m_ptStartPos = pos(); m_ptStart = pME->scenePos(); m_szStart = m_rectBoundingBox.size(); m_ptRotCenter = mapToScene(m_rectBoundingBox.center()); m_dAngle = GetAngle(pME->scenePos()); m_dRotation = rotation(); + // in rotation mode, do not do any changes here, because user might want to + // rotate the label more. if (m_eMode != mRotate) { + // if user pressed the button inside the resize square, switch to resize mode if (m_rectResize.contains(pME->pos()) == true) { m_eMode = mResize; @@ -264,16 +342,22 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) } else { + // if user pressed the button outside the resize square, switch to move mode m_eMode = mMove; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } + // raise the label and redraw it setZValue(TOP_Z + 1); UpdateBox(); } } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::mouseMoveEvent handles mouse move events + * @param pME pointer to QGraphicsSceneMouseEvent object + */ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { qreal dX; @@ -282,10 +366,12 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) QPointF ptDiff = pME->scenePos() - m_ptStart; if (m_eMode == mMove) { + // in move mode move the label along the mouse move from the origin QPointF pt = m_ptStartPos + ptDiff; rectBB.setTopLeft(pt); rectBB.setWidth(m_rectBoundingBox.width()); rectBB.setHeight(m_rectBoundingBox.height()); + // before moving label to a new position, check if it will still be inside the parent item if (IsContained(rectBB, rotation(), dX, dY) == false) { pt.setX(pt.x() + dX); @@ -296,10 +382,12 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) } else if (m_eMode == mResize) { + // in resize mode, resize the label along the mouse move from the origin QPointF pt = m_ptStartPos; rectBB.setTopLeft(pt); QSizeF sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); rectBB.setSize(sz); + // before resizing the label to a new size, check if it will still be inside the parent item if (IsContained(rectBB, rotation(), dX, dY) == true) { SetSize(sz.width(), sz.height()); @@ -309,15 +397,19 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) } else if (m_eMode == mRotate) { + // if the angle from the original position is small (0.5 degrees), just remeber the new angle + // new angle will be the starting angle for rotation if (fabs(m_dAngle) < 0.01) { m_dAngle = GetAngle(pME->scenePos()); return; } - double dAng = qRadiansToDegrees(GetAngle(pME->scenePos()) - m_dAngle); + // calculate the angle difference from the starting angle + double dAng = qRadiansToDegrees(GetAngle(pME->scenePos()) - m_dAngle); rectBB.setTopLeft(m_ptStartPos); rectBB.setWidth(m_rectBoundingBox.width()); rectBB.setHeight(m_rectBoundingBox.height()); + // check if the rotated label will be inside the parent item and then rotate it if (IsContained(rectBB, m_dRotation + dAng, dX, dY) == true) { setRotation(m_dRotation + dAng); @@ -327,10 +419,15 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::mouseReleaseEvent handles left button mouse release events + * @param pME pointer to QGraphicsSceneMouseEvent object + */ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (pME->button() == Qt::LeftButton) { + // restore the cursor if (m_eMode == mMove) { RestoreOverrideCursor(cursorArrowCloseHand); @@ -340,10 +437,12 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) RestoreOverrideCursor(Qt::SizeFDiagCursor); } double dDist = fabs(pME->scenePos().x() - m_ptStart.x()) + fabs(pME->scenePos().y() - m_ptStart.y()); + // determine if this was just press/release (bShort == true) or user did some operation between press and release bool bShort = (dDist < 2); if (m_eMode == mMove || m_eMode == mResize) - { // when released in mMove or mResize mode + { // if user just pressed and released the button, we must switch the mode to rotate + // but if user did some operation (move/resize), emit the proper signal and update the label if (bShort == true) { if (m_bReleased == true) @@ -364,7 +463,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } } else - { // when released in mRotate mode + { // in rotate mode, if user did just press/release, switch to move mode if (bShort == true) { m_eMode = mMove; @@ -372,6 +471,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } else { + // if user rotated the item, emit proper signal and update the label emit SignalRotated(rotation()); UpdateBox(); } @@ -381,12 +481,19 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::UpdateBox redraws the label content + */ void VTextGraphicsItem::UpdateBox() { update(m_rectBoundingBox); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::UpdateFont sets the text font size, so that the entire text will + * just fit into the label bounding box + */ void VTextGraphicsItem::UpdateFont() { int iFS = m_tm.GetFont().pixelSize(); @@ -406,6 +513,12 @@ void VTextGraphicsItem::UpdateFont() } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::GetAngle calculates the angle between the line, which goes from + * rotation center to pt and x axis + * @param pt point of interest + * @return the angle between line from rotation center and point of interest and x axis + */ double VTextGraphicsItem::GetAngle(QPointF pt) const { double dX = pt.x() - m_ptRotCenter.x(); @@ -422,6 +535,13 @@ double VTextGraphicsItem::GetAngle(QPointF pt) const } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::GetBoundingRect calculates the bounding box + * around rectBB rectangle, rotated around its center by dRot degrees + * @param rectBB rectangle of interest + * @param dRot rectangle rotation + * @return bounding box around rectBB rotated by dRot + */ QRectF VTextGraphicsItem::GetBoundingRect(QRectF rectBB, qreal dRot) const { QPointF apt[4] = { rectBB.topLeft(), rectBB.topRight(), rectBB.bottomLeft(), rectBB.bottomRight() }; diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 14a585d9a..0b1275894 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -35,6 +35,11 @@ #include "../vlayout/vtextmanager.h" +/** + * @brief The VTextGraphicsItem class. This class implements text graphics item, + * which can be dragged around, resized and rotated within the parent item. The text font + * size will be automatically updated, so that the entire text will fit into the item. + */ class VTextGraphicsItem : public QGraphicsObject { Q_OBJECT diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index c73425416..bfbe238df 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -351,7 +351,7 @@ void VToolDetail::AddToFile() QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = detail.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? 1:0); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? trueStr : falseStr); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); @@ -373,7 +373,7 @@ void VToolDetail::AddToFile() domData = doc->createElement(VAbstractPattern::TagPatternInfo); const VPatternInfoGeometry& geom = detail.GetPatternInfo(); - doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true? 1:0); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true? trueStr : falseStr); doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth()); @@ -410,7 +410,7 @@ void VToolDetail::RefreshDataInFile() QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = det.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); - doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? 1:0); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, data.IsVisible() == true? trueStr : falseStr); doc->SetAttribute(domData, AttrMx, data.GetPos().x()); doc->SetAttribute(domData, AttrMy, data.GetPos().y()); doc->SetAttribute(domData, AttrWidth, data.GetLabelWidth()); @@ -432,7 +432,7 @@ void VToolDetail::RefreshDataInFile() domData = doc->createElement(VAbstractPattern::TagPatternInfo); const VPatternInfoGeometry& geom = det.GetPatternInfo(); - doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true? 1:0); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true? trueStr : falseStr); doc->SetAttribute(domData, AttrMx, geom.GetPos().x()); doc->SetAttribute(domData, AttrMy, geom.GetPos().y()); doc->SetAttribute(domData, AttrWidth, geom.GetLabelWidth()); From a6e38b54d01b8f826fe87ed717621d0b91b0e946 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 24 Jul 2016 12:30:10 +0200 Subject: [PATCH 58/66] Added the optional measurements line to the pattern info label --HG-- branch : feature --- .../dialogs/dialogpatternproperties.cpp | 2 + .../dialogs/dialogpatternproperties.ui | 41 +++- src/app/valentina/xml/vpattern.cpp | 5 +- src/libs/ifc/schema/pattern/v0.3.3.xsd | 1 + src/libs/ifc/xml/vabstractpattern.cpp | 196 ++++++++++-------- src/libs/ifc/xml/vabstractpattern.h | 3 + src/libs/vlayout/vtextmanager.cpp | 19 +- 7 files changed, 170 insertions(+), 97 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 1aafcf101..d56595dad 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -173,6 +173,7 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte ui->labelCreationDate->setText(QDate::currentDate().toString(Qt::SystemLocaleLongDate)); ui->lineEditSize->setText(doc->GetPatternSize()); ui->checkBoxShowDate->setChecked(doc->IsDateVisible()); + ui->checkBoxShowMeasurements->setChecked(doc->IsMeasurementsVisible()); connect(ui->lineEditPatternName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); @@ -561,6 +562,7 @@ void DialogPatternProperties::SaveGeneralInfo() doc->SetCustomerName(ui->lineEditCustomerName->text()); doc->SetPatternSize(ui->lineEditSize->text()); doc->SetDateVisible(ui->checkBoxShowDate->isChecked()); + doc->SetMesurementsVisible(ui->checkBoxShowMeasurements->isChecked()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/dialogpatternproperties.ui b/src/app/valentina/dialogs/dialogpatternproperties.ui index 7521f8945..69e597dfc 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.ui +++ b/src/app/valentina/dialogs/dialogpatternproperties.ui @@ -1053,7 +1053,7 @@ 10 10 401 - 221 + 241 @@ -1068,7 +1068,11 @@ - + + + 30 + + @@ -1078,7 +1082,11 @@ - + + + 30 + + @@ -1088,7 +1096,11 @@ - + + + 30 + + @@ -1098,7 +1110,11 @@ - + + + 30 + + @@ -1122,9 +1138,20 @@ - + + + 30 + + - + + + + Show measurements + + + + Show date of creation diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 84aeea1d2..08bcb6c66 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -134,7 +134,7 @@ void VPattern::Parse(const Document &parse) QStringList tags = QStringList() << TagDraw << TagIncrements << TagAuthor << TagDescription << TagNotes << TagMeasurements << TagVersion << TagGradation << TagImage << TagUnit << TagPatternName << TagPatternNum << TagCompanyName << TagCustomerName - << TagSize << TagShowDate; + << TagSize << TagShowDate << TagShowMeasurements; PrepareForParse(parse); QDomNode domNode = documentElement().firstChild(); while (domNode.isNull() == false) @@ -212,6 +212,9 @@ void VPattern::Parse(const Document &parse) case 15: qCDebug(vXML, "Show creation date"); break; + case 16: + qCDebug(vXML, "Show creation measurements"); + break; default: qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); break; diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd index 2b7992a7d..186f4cc6e 100644 --- a/src/libs/ifc/schema/pattern/v0.3.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -79,6 +79,7 @@ + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 46b85959e..5818b4aaa 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -34,98 +34,98 @@ #include "../exception/vexceptionobjecterror.h" #include "../vtools/tools/vdatatool.h" -const QString VAbstractPattern::TagPattern = QStringLiteral("pattern"); -const QString VAbstractPattern::TagCalculation = QStringLiteral("calculation"); -const QString VAbstractPattern::TagModeling = QStringLiteral("modeling"); -const QString VAbstractPattern::TagDetails = QStringLiteral("details"); -const QString VAbstractPattern::TagDetail = QStringLiteral("detail"); -const QString VAbstractPattern::TagAuthor = QStringLiteral("author"); -const QString VAbstractPattern::TagDescription = QStringLiteral("description"); -const QString VAbstractPattern::TagNotes = QStringLiteral("notes"); -const QString VAbstractPattern::TagImage = QStringLiteral("image"); -const QString VAbstractPattern::TagMeasurements = QStringLiteral("measurements"); -const QString VAbstractPattern::TagIncrements = QStringLiteral("increments"); -const QString VAbstractPattern::TagIncrement = QStringLiteral("increment"); -const QString VAbstractPattern::TagDraw = QStringLiteral("draw"); -const QString VAbstractPattern::TagGroups = QStringLiteral("groups"); -const QString VAbstractPattern::TagGroup = QStringLiteral("group"); -const QString VAbstractPattern::TagGroupItem = QStringLiteral("item"); -const QString VAbstractPattern::TagPoint = QStringLiteral("point"); -const QString VAbstractPattern::TagLine = QStringLiteral("line"); -const QString VAbstractPattern::TagSpline = QStringLiteral("spline"); -const QString VAbstractPattern::TagArc = QStringLiteral("arc"); -const QString VAbstractPattern::TagTools = QStringLiteral("tools"); -const QString VAbstractPattern::TagOperation = QStringLiteral("operation"); -const QString VAbstractPattern::TagGradation = QStringLiteral("gradation"); -const QString VAbstractPattern::TagHeights = QStringLiteral("heights"); -const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); -const QString VAbstractPattern::TagUnit = QStringLiteral("unit"); -const QString VAbstractPattern::TagData = QStringLiteral("data"); -const QString VAbstractPattern::TagPatternInfo = QStringLiteral("patternInfo"); -const QString VAbstractPattern::TagMCP = QStringLiteral("mcp"); -const QString VAbstractPattern::TagPatternName = QStringLiteral("patternName"); -const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber"); -const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); -const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); -const QString VAbstractPattern::TagSize = QStringLiteral("size"); -const QString VAbstractPattern::TagShowDate = QStringLiteral("showDate"); +const QString VAbstractPattern::TagPattern = QStringLiteral("pattern"); +const QString VAbstractPattern::TagCalculation = QStringLiteral("calculation"); +const QString VAbstractPattern::TagModeling = QStringLiteral("modeling"); +const QString VAbstractPattern::TagDetails = QStringLiteral("details"); +const QString VAbstractPattern::TagDetail = QStringLiteral("detail"); +const QString VAbstractPattern::TagAuthor = QStringLiteral("author"); +const QString VAbstractPattern::TagDescription = QStringLiteral("description"); +const QString VAbstractPattern::TagNotes = QStringLiteral("notes"); +const QString VAbstractPattern::TagImage = QStringLiteral("image"); +const QString VAbstractPattern::TagMeasurements = QStringLiteral("measurements"); +const QString VAbstractPattern::TagIncrements = QStringLiteral("increments"); +const QString VAbstractPattern::TagIncrement = QStringLiteral("increment"); +const QString VAbstractPattern::TagDraw = QStringLiteral("draw"); +const QString VAbstractPattern::TagGroups = QStringLiteral("groups"); +const QString VAbstractPattern::TagGroup = QStringLiteral("group"); +const QString VAbstractPattern::TagGroupItem = QStringLiteral("item"); +const QString VAbstractPattern::TagPoint = QStringLiteral("point"); +const QString VAbstractPattern::TagLine = QStringLiteral("line"); +const QString VAbstractPattern::TagSpline = QStringLiteral("spline"); +const QString VAbstractPattern::TagArc = QStringLiteral("arc"); +const QString VAbstractPattern::TagTools = QStringLiteral("tools"); +const QString VAbstractPattern::TagOperation = QStringLiteral("operation"); +const QString VAbstractPattern::TagGradation = QStringLiteral("gradation"); +const QString VAbstractPattern::TagHeights = QStringLiteral("heights"); +const QString VAbstractPattern::TagSizes = QStringLiteral("sizes"); +const QString VAbstractPattern::TagUnit = QStringLiteral("unit"); +const QString VAbstractPattern::TagData = QStringLiteral("data"); +const QString VAbstractPattern::TagPatternInfo = QStringLiteral("patternInfo"); +const QString VAbstractPattern::TagMCP = QStringLiteral("mcp"); +const QString VAbstractPattern::TagPatternName = QStringLiteral("patternName"); +const QString VAbstractPattern::TagPatternNum = QStringLiteral("patternNumber"); +const QString VAbstractPattern::TagCustomerName = QStringLiteral("customer"); +const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); +const QString VAbstractPattern::TagSize = QStringLiteral("size"); +const QString VAbstractPattern::TagShowDate = QStringLiteral("showDate"); +const QString VAbstractPattern::TagShowMeasurements = QStringLiteral("showMeasurements"); +const QString VAbstractPattern::AttrName = QStringLiteral("name"); +const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); +const QString VAbstractPattern::AttrObject = QStringLiteral("object"); +const QString VAbstractPattern::AttrTool = QStringLiteral("tool"); +const QString VAbstractPattern::AttrType = QStringLiteral("type"); +const QString VAbstractPattern::AttrLetter = QStringLiteral("letter"); +const QString VAbstractPattern::AttrMaterial = QStringLiteral("material"); +const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef"); +const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber"); +const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement"); -const QString VAbstractPattern::AttrName = QStringLiteral("name"); -const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); -const QString VAbstractPattern::AttrObject = QStringLiteral("object"); -const QString VAbstractPattern::AttrTool = QStringLiteral("tool"); -const QString VAbstractPattern::AttrType = QStringLiteral("type"); -const QString VAbstractPattern::AttrLetter = QStringLiteral("letter"); -const QString VAbstractPattern::AttrMaterial = QStringLiteral("material"); -const QString VAbstractPattern::AttrUserDefined = QStringLiteral("userDef"); -const QString VAbstractPattern::AttrCutNumber = QStringLiteral("cutNumber"); -const QString VAbstractPattern::AttrPlacement = QStringLiteral("placement"); +const QString VAbstractPattern::AttrAll = QStringLiteral("all"); -const QString VAbstractPattern::AttrAll = QStringLiteral("all"); +const QString VAbstractPattern::AttrH92 = QStringLiteral("h92"); +const QString VAbstractPattern::AttrH98 = QStringLiteral("h98"); +const QString VAbstractPattern::AttrH104 = QStringLiteral("h104"); +const QString VAbstractPattern::AttrH110 = QStringLiteral("h110"); +const QString VAbstractPattern::AttrH116 = QStringLiteral("h116"); +const QString VAbstractPattern::AttrH122 = QStringLiteral("h122"); +const QString VAbstractPattern::AttrH128 = QStringLiteral("h128"); +const QString VAbstractPattern::AttrH134 = QStringLiteral("h134"); +const QString VAbstractPattern::AttrH140 = QStringLiteral("h140"); +const QString VAbstractPattern::AttrH146 = QStringLiteral("h146"); +const QString VAbstractPattern::AttrH152 = QStringLiteral("h152"); +const QString VAbstractPattern::AttrH158 = QStringLiteral("h158"); +const QString VAbstractPattern::AttrH164 = QStringLiteral("h164"); +const QString VAbstractPattern::AttrH170 = QStringLiteral("h170"); +const QString VAbstractPattern::AttrH176 = QStringLiteral("h176"); +const QString VAbstractPattern::AttrH182 = QStringLiteral("h182"); +const QString VAbstractPattern::AttrH188 = QStringLiteral("h188"); +const QString VAbstractPattern::AttrH194 = QStringLiteral("h194"); -const QString VAbstractPattern::AttrH92 = QStringLiteral("h92"); -const QString VAbstractPattern::AttrH98 = QStringLiteral("h98"); -const QString VAbstractPattern::AttrH104 = QStringLiteral("h104"); -const QString VAbstractPattern::AttrH110 = QStringLiteral("h110"); -const QString VAbstractPattern::AttrH116 = QStringLiteral("h116"); -const QString VAbstractPattern::AttrH122 = QStringLiteral("h122"); -const QString VAbstractPattern::AttrH128 = QStringLiteral("h128"); -const QString VAbstractPattern::AttrH134 = QStringLiteral("h134"); -const QString VAbstractPattern::AttrH140 = QStringLiteral("h140"); -const QString VAbstractPattern::AttrH146 = QStringLiteral("h146"); -const QString VAbstractPattern::AttrH152 = QStringLiteral("h152"); -const QString VAbstractPattern::AttrH158 = QStringLiteral("h158"); -const QString VAbstractPattern::AttrH164 = QStringLiteral("h164"); -const QString VAbstractPattern::AttrH170 = QStringLiteral("h170"); -const QString VAbstractPattern::AttrH176 = QStringLiteral("h176"); -const QString VAbstractPattern::AttrH182 = QStringLiteral("h182"); -const QString VAbstractPattern::AttrH188 = QStringLiteral("h188"); -const QString VAbstractPattern::AttrH194 = QStringLiteral("h194"); +const QString VAbstractPattern::AttrS22 = QStringLiteral("s22"); +const QString VAbstractPattern::AttrS24 = QStringLiteral("s24"); +const QString VAbstractPattern::AttrS26 = QStringLiteral("s26"); +const QString VAbstractPattern::AttrS28 = QStringLiteral("s28"); +const QString VAbstractPattern::AttrS30 = QStringLiteral("s30"); +const QString VAbstractPattern::AttrS32 = QStringLiteral("s32"); +const QString VAbstractPattern::AttrS34 = QStringLiteral("s34"); +const QString VAbstractPattern::AttrS36 = QStringLiteral("s36"); +const QString VAbstractPattern::AttrS38 = QStringLiteral("s38"); +const QString VAbstractPattern::AttrS40 = QStringLiteral("s40"); +const QString VAbstractPattern::AttrS42 = QStringLiteral("s42"); +const QString VAbstractPattern::AttrS44 = QStringLiteral("s44"); +const QString VAbstractPattern::AttrS46 = QStringLiteral("s46"); +const QString VAbstractPattern::AttrS48 = QStringLiteral("s48"); +const QString VAbstractPattern::AttrS50 = QStringLiteral("s50"); +const QString VAbstractPattern::AttrS52 = QStringLiteral("s52"); +const QString VAbstractPattern::AttrS54 = QStringLiteral("s54"); +const QString VAbstractPattern::AttrS56 = QStringLiteral("s56"); -const QString VAbstractPattern::AttrS22 = QStringLiteral("s22"); -const QString VAbstractPattern::AttrS24 = QStringLiteral("s24"); -const QString VAbstractPattern::AttrS26 = QStringLiteral("s26"); -const QString VAbstractPattern::AttrS28 = QStringLiteral("s28"); -const QString VAbstractPattern::AttrS30 = QStringLiteral("s30"); -const QString VAbstractPattern::AttrS32 = QStringLiteral("s32"); -const QString VAbstractPattern::AttrS34 = QStringLiteral("s34"); -const QString VAbstractPattern::AttrS36 = QStringLiteral("s36"); -const QString VAbstractPattern::AttrS38 = QStringLiteral("s38"); -const QString VAbstractPattern::AttrS40 = QStringLiteral("s40"); -const QString VAbstractPattern::AttrS42 = QStringLiteral("s42"); -const QString VAbstractPattern::AttrS44 = QStringLiteral("s44"); -const QString VAbstractPattern::AttrS46 = QStringLiteral("s46"); -const QString VAbstractPattern::AttrS48 = QStringLiteral("s48"); -const QString VAbstractPattern::AttrS50 = QStringLiteral("s50"); -const QString VAbstractPattern::AttrS52 = QStringLiteral("s52"); -const QString VAbstractPattern::AttrS54 = QStringLiteral("s54"); -const QString VAbstractPattern::AttrS56 = QStringLiteral("s56"); - -const QString VAbstractPattern::AttrCustom = QStringLiteral("custom"); -const QString VAbstractPattern::AttrDefHeight = QStringLiteral("defHeight"); -const QString VAbstractPattern::AttrDefSize = QStringLiteral("defSize"); -const QString VAbstractPattern::AttrExtension = QStringLiteral("extension"); +const QString VAbstractPattern::AttrCustom = QStringLiteral("custom"); +const QString VAbstractPattern::AttrDefHeight = QStringLiteral("defHeight"); +const QString VAbstractPattern::AttrDefSize = QStringLiteral("defSize"); +const QString VAbstractPattern::AttrExtension = QStringLiteral("extension"); const QString VAbstractPattern::IncrementName = QStringLiteral("name"); const QString VAbstractPattern::IncrementFormula = QStringLiteral("formula"); @@ -1085,6 +1085,21 @@ void VAbstractPattern::SetDateVisible(bool bVisible) emit patternChanged(false); } +//--------------------------------------------------------------------------------------------------------------------- +bool VAbstractPattern::IsMeasurementsVisible() const +{ + return UniqueTagText(TagShowMeasurements) == trueStr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractPattern::SetMesurementsVisible(bool bVisible) +{ + CheckTagExists(TagShowMeasurements); + setTagText(TagShowMeasurements, bVisible == true? trueStr : falseStr); + modified = true; + emit patternChanged(false); +} + //--------------------------------------------------------------------------------------------------------------------- QString VAbstractPattern::GetImage() const { @@ -1199,7 +1214,7 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) { const QStringList tags = QStringList() << TagUnit << TagImage << TagAuthor << TagDescription << TagNotes << TagGradation << TagPatternName << TagPatternNum << TagCompanyName - << TagCustomerName << TagSize << TagShowDate; + << TagCustomerName << TagSize << TagShowDate << TagShowMeasurements; switch (tags.indexOf(tag)) { case 0: //TagUnit @@ -1270,6 +1285,11 @@ QDomElement VAbstractPattern::CheckTagExists(const QString &tag) element = createElement(TagShowDate); break; } + case 12: // TagShowMeasurements + { + element = createElement(TagShowMeasurements); + break; + } default: { diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 18c55c313..873b6d1b9 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -120,6 +120,8 @@ public: void SetPatternSize(const QString &qsSize); bool IsDateVisible() const; void SetDateVisible(bool bVisible); + bool IsMeasurementsVisible() const; + void SetMesurementsVisible(bool bVisible); QString GetImage() const; QString GetImageExtension() const; @@ -178,6 +180,7 @@ public: static const QString TagCustomerName; static const QString TagSize; static const QString TagShowDate; + static const QString TagShowMeasurements; static const QString AttrName; static const QString AttrVisible; diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 9a996b16c..02c2cf38b 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -141,6 +141,11 @@ bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) QStringList qslLines = SplitString(tlOut.m_qsText, fW, fm); for (int iL = 0; iL < qslLines.count(); ++iL) { + // check if every line fits within the label width + if (fm.width(qslLines[iL]) + 2*GetSpacing() > fW) + { + return false; + } tlOut.m_qsText = qslLines[iL]; m_liOutput << tlOut; iY += tlOut.m_iHeight + GetSpacing(); @@ -275,6 +280,15 @@ void VTextManager::Update(const VAbstractPattern *pDoc) tl.m_iFontSize = 0; AddLine(tl); } + // Measurements + tl.m_qsText = pDoc->MPath(); + if (tl.m_qsText.isEmpty() == false && pDoc->IsMeasurementsVisible() == true) + { + tl.m_eFontWeight = QFont::Normal; + tl.m_eStyle = QFont::StyleNormal; + tl.m_iFontSize = 0; + AddLine(tl); + } // Date QDate date; if (pDoc->IsDateVisible() == true) @@ -317,7 +331,10 @@ QStringList VTextManager::SplitString(const QString &qs, qreal fW, const QFontMe if (fm.width(qsCurrent + qslWords[i]) > fW) { // if not, add the current line into the list of text lines - qslLines << qsCurrent; + if (qsCurrent.isEmpty() == false) + { + qslLines << qsCurrent; + } // and set the current line to contain the current word qsCurrent = qslWords[i]; } From 85db8f84e69e1abb780ddaf60cd349e36bde0e27 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 24 Jul 2016 19:07:38 +0200 Subject: [PATCH 59/66] Added hiding Show measurement option and showing just a filename without path in detail and layout mode. Also fixed a wrong comment --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 11 ++++++++++- src/app/valentina/xml/vpattern.cpp | 2 +- src/libs/ifc/schema/pattern/v0.3.3.xsd | 2 +- src/libs/vlayout/vtextmanager.cpp | 3 ++- src/libs/vlayout/vtextmanager.h | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index d56595dad..659610086 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -173,7 +173,16 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte ui->labelCreationDate->setText(QDate::currentDate().toString(Qt::SystemLocaleLongDate)); ui->lineEditSize->setText(doc->GetPatternSize()); ui->checkBoxShowDate->setChecked(doc->IsDateVisible()); - ui->checkBoxShowMeasurements->setChecked(doc->IsMeasurementsVisible()); + if (doc->MPath().isEmpty() == true) + { + ui->checkBoxShowMeasurements->setChecked(false); + ui->checkBoxShowMeasurements->hide(); + } + else + { + ui->checkBoxShowMeasurements->setChecked(doc->IsMeasurementsVisible()); + } + connect(ui->lineEditPatternName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 08bcb6c66..d4b209223 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -213,7 +213,7 @@ void VPattern::Parse(const Document &parse) qCDebug(vXML, "Show creation date"); break; case 16: - qCDebug(vXML, "Show creation measurements"); + qCDebug(vXML, "Show measurements"); break; default: qCDebug(vXML, "Wrong tag name %s", qUtf8Printable(domElement.tagName())); diff --git a/src/libs/ifc/schema/pattern/v0.3.3.xsd b/src/libs/ifc/schema/pattern/v0.3.3.xsd index 186f4cc6e..5084f71c1 100644 --- a/src/libs/ifc/schema/pattern/v0.3.3.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.3.xsd @@ -390,7 +390,7 @@ - + diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 02c2cf38b..ad59cbc98 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "vtextmanager.h" @@ -281,7 +282,7 @@ void VTextManager::Update(const VAbstractPattern *pDoc) AddLine(tl); } // Measurements - tl.m_qsText = pDoc->MPath(); + tl.m_qsText = QDir::toNativeSeparators(pDoc->MPath()).split(QDir::separator()).last(); if (tl.m_qsText.isEmpty() == false && pDoc->IsMeasurementsVisible() == true) { tl.m_eFontWeight = QFont::Normal; diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index 1fa5a48de..aea6741ab 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -34,7 +34,7 @@ class VTextManager { public: VTextManager(); - ~VTextManager(); + virtual ~VTextManager(); virtual int GetSpacing() const; void SetFont(const QFont& font); From 1b5ca4e23dc5eb36edf368b6c16a2ebb34caa132 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 24 Jul 2016 19:48:31 +0200 Subject: [PATCH 60/66] Fixed the pattern converter --HG-- branch : feature --- src/libs/ifc/xml/vpatternconverter.cpp | 11 ++++++++++- src/libs/ifc/xml/vpatternconverter.h | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 819a98d47..34647259c 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -173,7 +173,9 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000302), fileName); V_FALLTHROUGH case (0x000302): - break; + ToV0_3_3(); + ValidateXML(XSDSchema(0x000303), fileName); + V_FALLTHROUGH default: break; } @@ -316,6 +318,13 @@ void VPatternConverter::ToV0_3_2() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_3_3() +{ + SetVersion(QStringLiteral("0.3.3")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index cbecfa5f0..76c0caa71 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -41,7 +41,7 @@ public: static const QString PatternMaxVerStr; static const QString CurrentSchema; static constexpr int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static constexpr int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 2); + static constexpr int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 3); protected: virtual int MinVer() const Q_DECL_OVERRIDE; @@ -73,6 +73,7 @@ private: void ToV0_3_0(); void ToV0_3_1(); void ToV0_3_2(); + void ToV0_3_3(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); From 88055db1708868a36c4d96118669ed1fefbd64b2 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Mon, 25 Jul 2016 19:10:13 +0200 Subject: [PATCH 61/66] Show measurements option is now disabled and not hidden, if there are no measurements associated with the current pattern. Finished pattern converter and refactored measurement file extraction in text manager class --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 2 +- src/libs/ifc/xml/vpatternconverter.cpp | 2 ++ src/libs/vlayout/vtextmanager.cpp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 659610086..82e4889f3 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -176,7 +176,7 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte if (doc->MPath().isEmpty() == true) { ui->checkBoxShowMeasurements->setChecked(false); - ui->checkBoxShowMeasurements->hide(); + ui->checkBoxShowMeasurements->setEnabled(false); } else { diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 34647259c..5723fadca 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -176,6 +176,8 @@ void VPatternConverter::ApplyPatches() ToV0_3_3(); ValidateXML(XSDSchema(0x000303), fileName); V_FALLTHROUGH + case (0x000303): + break; default: break; } diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index ad59cbc98..ee1a7cb04 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -282,7 +282,7 @@ void VTextManager::Update(const VAbstractPattern *pDoc) AddLine(tl); } // Measurements - tl.m_qsText = QDir::toNativeSeparators(pDoc->MPath()).split(QDir::separator()).last(); + tl.m_qsText = QFileInfo(pDoc->MPath()).fileName(); if (tl.m_qsText.isEmpty() == false && pDoc->IsMeasurementsVisible() == true) { tl.m_eFontWeight = QFont::Normal; From 06cfaea3b3920592877504325da4cf429e5cf64b Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Fri, 29 Jul 2016 21:59:48 +0200 Subject: [PATCH 62/66] Fixed maximal font size --HG-- branch : feature --- src/libs/vlayout/vtextmanager.cpp | 3 ++- src/libs/vlayout/vtextmanager.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index ee1a7cb04..62de75761 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -138,12 +138,13 @@ bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) TextLine tlOut = tl; fnt.setPixelSize(iFontSize + tl.m_iFontSize); QFontMetrics fm(fnt); + int iHorSp = fm.width(" "); tlOut.m_iHeight = fm.height(); QStringList qslLines = SplitString(tlOut.m_qsText, fW, fm); for (int iL = 0; iL < qslLines.count(); ++iL) { // check if every line fits within the label width - if (fm.width(qslLines[iL]) + 2*GetSpacing() > fW) + if (fm.width(qslLines[iL]) + iHorSp > fW) { return false; } diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index aea6741ab..e2f18e254 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -9,7 +9,7 @@ #include "../ifc/xml/vabstractpattern.h" #define MIN_FONT_SIZE 12 -#define MAX_FONT_SIZE 128 +#define MAX_FONT_SIZE 1024 /** * @brief The TextLine struct holds the information about one text line From a3f4c6da0d774ac57fc3dcc9a4bfa3056a8fa1b2 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 30 Jul 2016 12:48:18 +0200 Subject: [PATCH 63/66] Set maximal font size back to 128 --HG-- branch : feature --- src/libs/vlayout/vtextmanager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index e2f18e254..aea6741ab 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -9,7 +9,7 @@ #include "../ifc/xml/vabstractpattern.h" #define MIN_FONT_SIZE 12 -#define MAX_FONT_SIZE 1024 +#define MAX_FONT_SIZE 128 /** * @brief The TextLine struct holds the information about one text line From a1c905381b2c162f22af6c7a3bfc206c930ef4f4 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 30 Jul 2016 13:21:03 +0200 Subject: [PATCH 64/66] Fixed label update on clicking OK in pattern properties dialog and the label is hidden when there is no text on it --HG-- branch : feature --- src/app/valentina/dialogs/dialogpatternproperties.cpp | 3 +++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 10 ++++++++++ src/libs/vtools/tools/vtextgraphicsitem.h | 1 + src/libs/vtools/tools/vtooldetail.cpp | 9 ++++++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/app/valentina/dialogs/dialogpatternproperties.cpp b/src/app/valentina/dialogs/dialogpatternproperties.cpp index 82e4889f3..6792ab260 100644 --- a/src/app/valentina/dialogs/dialogpatternproperties.cpp +++ b/src/app/valentina/dialogs/dialogpatternproperties.cpp @@ -188,6 +188,9 @@ DialogPatternProperties::DialogPatternProperties(const QString &filePath, VPatte connect(ui->lineEditPatternNumber, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); connect(ui->lineEditCompanyName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); connect(ui->lineEditCustomerName, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); + connect(ui->lineEditSize, &QLineEdit::editingFinished, this, &DialogPatternProperties::GeneralInfoChanged); + connect(ui->checkBoxShowDate, &QCheckBox::stateChanged, this, &DialogPatternProperties::GeneralInfoChanged); + connect(ui->checkBoxShowMeasurements, &QCheckBox::stateChanged, this, &DialogPatternProperties::GeneralInfoChanged); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 06d1649fc..aa312ca32 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -293,6 +293,16 @@ void VTextGraphicsItem::UpdateData(const VAbstractPattern* pDoc) m_tm.Update(pDoc); } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::GetTextLines returns the number of lines of text to show + * @return number of lines of text + */ +int VTextGraphicsItem::GetTextLines() const +{ + return m_tm.GetCount(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VTextGraphicsItem::GetFontSize returns the currently used text base font size diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 0b1275894..c86b1a639 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -69,6 +69,7 @@ public: bool IsContained(QRectF rectBB, qreal dRot, qreal& dX, qreal& dY) const; void UpdateData(const QString& qsName, const VPatternPieceData& data); void UpdateData(const VAbstractPattern* pDoc); + int GetTextLines() const; protected: void mousePressEvent(QGraphicsSceneMouseEvent* pME); diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index bfbe238df..1d827e268 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -748,7 +748,14 @@ void VToolDetail::UpdatePatternInfo() patternInfo->setPos(pt); patternInfo->setRotation(geom.GetRotation()); patternInfo->Update(); - patternInfo->show(); + if (patternInfo->GetTextLines() > 0) + { + patternInfo->show(); + } + else + { + patternInfo->hide(); + } } else { From c48633a398e8ada7a36b372933224d1e4edff253 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 30 Jul 2016 14:09:51 +0200 Subject: [PATCH 65/66] Fixed ChangeLog.txt --HG-- branch : feature --- ChangeLog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index e660ee814..219eb4238 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,5 @@ # Version 0.5.0 +- [#24] User can now add labels with different information on the detail - [#505] New installer script based on Inno Setup 5. - Size of preferences dialog in both Valentina and Tape app is now preserved between sessions - [#479] Preferences dialog is now extendable and when it is opened again, it will be resized to its previous size. From 6da5cd6f928a2bd94f8b87eed2c160074cf6cdbe Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 30 Jul 2016 20:02:45 +0300 Subject: [PATCH 66/66] Close feature branch. --HG-- branch : feature