diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index b38fe5a81..e4a95f52d 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -804,35 +804,26 @@ void VPattern::ParseDetailNodes(const QDomElement &domElement, VPiece &detail, q //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) const { - detail.GetPatternPieceData().SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); + VPieceLabelData &ppData = detail.GetPatternPieceData(); + ppData.SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); try { QString qsLetter = GetParametrString(domElement, AttrLetter, ""); - detail.GetPatternPieceData().SetLetter(qsLetter); + ppData.SetLetter(qsLetter); } catch(const VExceptionEmptyParameter &e) { Q_UNUSED(e) - detail.GetPatternPieceData().SetLetter(""); + ppData.SetLetter(""); } - QPointF ptPos; - ptPos.setX(GetParametrDouble(domElement, AttrMx, "0")); - ptPos.setY(GetParametrDouble(domElement, AttrMy, "0")); - detail.GetPatternPieceData().SetPos(ptPos); - qreal dLW = GetParametrDouble(domElement, AttrWidth, "0"); - detail.GetPatternPieceData().SetLabelWidth(dLW); - qreal dLH = GetParametrDouble(domElement, VToolSeamAllowance::AttrHeight, "0"); - detail.GetPatternPieceData().SetLabelHeight(dLH); - int iFS = static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0")); - detail.GetPatternPieceData().SetFontSize(iFS); - qreal dRot = GetParametrDouble(domElement, AttrRotation, "0"); - detail.GetPatternPieceData().SetRotation(dRot); - - const quint32 topLeftPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR); - detail.GetPatternPieceData().SetTopLeftPin(topLeftPin); - - const quint32 bottomRightPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR); - detail.GetPatternPieceData().SetBottomRightPin(bottomRightPin); + ppData.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, "0"), GetParametrDouble(domElement, AttrMy, "0"))); + ppData.SetLabelWidth(GetParametrString(domElement, AttrWidth, "1")); + ppData.SetLabelHeight(GetParametrString(domElement, VToolSeamAllowance::AttrHeight, "1")); + ppData.SetFontSize(static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0"))); + ppData.SetRotation(GetParametrString(domElement, AttrRotation, "0")); + ppData.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); + ppData.SetTopLeftPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR)); + ppData.SetBottomRightPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR)); QDomNodeList nodeListMCP = domElement.childNodes(); for (int iMCP = 0; iMCP < nodeListMCP.count(); ++iMCP) @@ -846,54 +837,37 @@ void VPattern::ParsePieceDataTag(const QDomElement &domElement, VPiece &detail) } mcp.m_iCutNumber = static_cast(GetParametrUInt(domMCP, AttrCutNumber, 0)); mcp.m_ePlacement = PlacementType(GetParametrUInt(domMCP, AttrPlacement, 0)); - detail.GetPatternPieceData().Append(mcp); + ppData.Append(mcp); } } //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParsePiecePatternInfo(const QDomElement &domElement, VPiece &detail) const { - detail.GetPatternInfo().SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); - QPointF ptPos; - ptPos.setX(GetParametrDouble(domElement, AttrMx, "0")); - ptPos.setY(GetParametrDouble(domElement, AttrMy, "0")); - detail.GetPatternInfo().SetPos(ptPos); - qreal dLW = GetParametrDouble(domElement, AttrWidth, "0"); - detail.GetPatternInfo().SetLabelWidth(dLW); - qreal dLH = GetParametrDouble(domElement, VToolSeamAllowance::AttrHeight, "0"); - detail.GetPatternInfo().SetLabelHeight(dLH); - int iFS = static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0")); - detail.GetPatternInfo().SetFontSize(iFS); - qreal dRot = GetParametrDouble(domElement, AttrRotation, "0"); - detail.GetPatternInfo().SetRotation(dRot); - - const quint32 topLeftPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR); - detail.GetPatternInfo().SetTopLeftPin(topLeftPin); - - const quint32 bottomRightPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR); - detail.GetPatternInfo().SetBottomRightPin(bottomRightPin); + VPatternLabelData &patternInfo = detail.GetPatternInfo(); + patternInfo.SetVisible(GetParametrBool(domElement, AttrVisible, trueStr)); + patternInfo.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, "0"), GetParametrDouble(domElement, AttrMy, "0"))); + patternInfo.SetLabelWidth(GetParametrString(domElement, AttrWidth, "1")); + patternInfo.SetLabelHeight(GetParametrString(domElement, VToolSeamAllowance::AttrHeight, "1")); + patternInfo.SetFontSize(static_cast(GetParametrUInt(domElement, VToolSeamAllowance::AttrFont, "0"))); + patternInfo.SetRotation(GetParametrString(domElement, AttrRotation, "0")); + patternInfo.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); + patternInfo.SetTopLeftPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopLeftPin, NULL_ID_STR)); + patternInfo.SetBottomRightPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomRightPin, NULL_ID_STR)); } //--------------------------------------------------------------------------------------------------------------------- void VPattern::ParsePieceGrainline(const QDomElement &domElement, VPiece &detail) const { - detail.GetGrainlineGeometry().SetVisible(GetParametrBool(domElement, AttrVisible, falseStr)); - QPointF ptPos; - ptPos.setX(GetParametrDouble(domElement, AttrMx, "0")); - ptPos.setY(GetParametrDouble(domElement, AttrMy, "0")); - detail.GetGrainlineGeometry().SetPos(ptPos); - QString qsLength = GetParametrString(domElement, AttrLength, "0"); - detail.GetGrainlineGeometry().SetLength(qsLength); - QString qsRot = GetParametrString(domElement, AttrRotation, "90"); - detail.GetGrainlineGeometry().SetRotation(qsRot); - ArrowType eAT = static_cast(GetParametrUInt(domElement, AttrArrows, "0")); - detail.GetGrainlineGeometry().SetArrowType(eAT); - - const quint32 topPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrTopPin, NULL_ID_STR); - detail.GetGrainlineGeometry().SetTopPin(topPin); - - const quint32 bottomPin = GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomPin, NULL_ID_STR); - detail.GetGrainlineGeometry().SetBottomPin(bottomPin); + VGrainlineData &gGeometry = detail.GetGrainlineGeometry(); + gGeometry.SetVisible(GetParametrBool(domElement, AttrVisible, falseStr)); + gGeometry.SetPos(QPointF(GetParametrDouble(domElement, AttrMx, "0"), GetParametrDouble(domElement, AttrMy, "0"))); + gGeometry.SetLength(GetParametrString(domElement, AttrLength, "1")); + gGeometry.SetRotation(GetParametrString(domElement, AttrRotation, "90")); + gGeometry.SetArrowType(static_cast(GetParametrUInt(domElement, AttrArrows, "0"))); + gGeometry.SetCenterPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrCenterPin, NULL_ID_STR)); + gGeometry.SetTopPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrTopPin, NULL_ID_STR)); + gGeometry.SetBottomPin(GetParametrUInt(domElement, VToolSeamAllowance::AttrBottomPin, NULL_ID_STR)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 12129b994..36ee8e5e6 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -27,6 +27,7 @@ schema/pattern/v0.4.1.xsd schema/pattern/v0.4.2.xsd schema/pattern/v0.4.3.xsd + schema/pattern/v0.4.4.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd diff --git a/src/libs/ifc/schema/pattern/v0.4.4.xsd b/src/libs/ifc/schema/pattern/v0.4.4.xsd new file mode 100644 index 000000000..a92a2a950 --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.4.4.xsd @@ -0,0 +1,874 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 64fc3c4e6..ff1c45e6d 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -58,8 +58,8 @@ class QDomElement; */ const QString VPatternConverter::PatternMinVerStr = QStringLiteral("0.1.0"); -const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.4.3"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.4.3.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.4.4"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.4.4.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -119,6 +119,7 @@ static const QString strDetail = QStringLiteral("detail"); static const QString strSupplement = QStringLiteral("supplement"); static const QString strClosed = QStringLiteral("closed"); static const QString strWidth = QStringLiteral("width"); +static const QString strHeight = QStringLiteral("height"); static const QString strNode = QStringLiteral("node"); static const QString strNodes = QStringLiteral("nodes"); static const QString strData = QStringLiteral("data"); @@ -204,6 +205,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000402): return QStringLiteral("://schema/pattern/v0.4.2.xsd"); case (0x000403): + return QStringLiteral("://schema/pattern/v0.4.3.xsd"); + case (0x000404): return CurrentSchema; default: InvalidVersion(ver); @@ -321,6 +324,10 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000403), m_convertedFileName); V_FALLTHROUGH case (0x000403): + ToV0_4_4(); + ValidateXML(XSDSchema(0x000404), m_convertedFileName); + V_FALLTHROUGH + case (0x000404): break; default: InvalidVersion(m_ver); @@ -339,7 +346,7 @@ void VPatternConverter::DowngradeToCurrentMaxVersion() bool VPatternConverter::IsReadOnly() const { // Check if attribute readOnly was not changed in file format - Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 4, 3), + Q_STATIC_ASSERT_X(VPatternConverter::PatternMaxVer == CONVERTER_VERSION_CHECK(0, 4, 4), "Check attribute readOnly."); // Possibly in future attribute readOnly will change position etc. @@ -655,6 +662,19 @@ void VPatternConverter::ToV0_4_3() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_4_4() +{ + // TODO. Delete if minimal supported version is 0.4.4 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 4), + "Time to refactor the code."); + + SetVersion(QStringLiteral("0.4.4")); + LabelTagToV0_4_4(strData); + LabelTagToV0_4_4(strPatternInfo); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { @@ -1927,6 +1947,58 @@ QDomElement VPatternConverter::GetUnionChildrenNodesV0_4_0(const QDomElement &de return tagNodes; } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::LabelTagToV0_4_4(const QString &tagName) +{ + // TODO. Delete if minimal supported version is 0.4.4 + Q_STATIC_ASSERT_X(VPatternConverter::PatternMinVer < CONVERTER_VERSION_CHECK(0, 4, 4), + "Time to refactor the code."); + + Unit unit = Unit::Cm; + const QStringList units = QStringList() << "mm" << "cm" << "inch"; + switch (units.indexOf(UniqueTagText(strUnit))) + { + case 0:// mm + unit = Unit::Mm; + break; + case 1:// cm + unit = Unit::Cm; + break; + case 2:// in + unit = Unit::Inch; + break; + default: + break; + } + + auto ConvertData = [unit](QDomElement &dom, const QString &attribute) + { + if (dom.hasAttribute(attribute)) + { + QString valStr = dom.attribute(attribute, "1"); + bool ok = false; + qreal val = valStr.toDouble(&ok); + if (not ok) + { + val = 1; + } + dom.setAttribute(attribute, QString().setNum(FromPixel(val, unit))); + } + }; + + const QDomNodeList list = elementsByTagName(tagName); + for (int i=0; i < list.size(); ++i) + { + QDomElement dom = list.at(i).toElement(); + + if (not dom.isNull()) + { + ConvertData(dom, strWidth); + ConvertData(dom, strHeight); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnionDetailsToV0_4_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index 73310c676..70df5445e 100644 --- a/src/libs/ifc/xml/vpatternconverter.h +++ b/src/libs/ifc/xml/vpatternconverter.h @@ -55,10 +55,10 @@ public: // GCC 4.6 doesn't allow constexpr and const together #if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) <= 406 static Q_DECL_CONSTEXPR int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 3); + static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 4); #else static Q_DECL_CONSTEXPR const int PatternMinVer = CONVERTER_VERSION_CHECK(0, 1, 0); - static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 3); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 4, 4); #endif protected: @@ -104,6 +104,7 @@ private: void ToV0_4_1(); void ToV0_4_2(); void ToV0_4_3(); + void ToV0_4_4(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); @@ -145,6 +146,8 @@ private: void TagUnionDetailsToV0_4_0(); QDomElement GetUnionDetailNodesV0_4_0(const QDomElement &detail); QDomElement GetUnionChildrenNodesV0_4_0(const QDomElement &detail); + + void LabelTagToV0_4_4(const QString &tagName); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index 93463eed8..7d9595a60 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -75,11 +75,22 @@ QVector ConvertInternalPaths(const VPiece &piece, const VConta } //--------------------------------------------------------------------------------------------------------------------- -void FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pattern, qreal &labelWidth, - qreal &labelHeight, QPointF &pos) +bool FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pattern, qreal &rotationAngle, + qreal &labelWidth, qreal &labelHeight, QPointF &pos) { SCASSERT(pattern != nullptr) + try + { + Calculator cal1; + rotationAngle = cal1.EvalFormula(pattern->PlainVariables(), labelData.GetRotation()); + } + catch(qmu::QmuParserError &e) + { + Q_UNUSED(e); + return false; + } + const quint32 topLeftPin = labelData.TopLeftPin(); const quint32 bottomRightPin = labelData.BottomRightPin(); @@ -96,7 +107,7 @@ void FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat pos = labelRect.topLeft(); - return; + return true; } catch(const VExceptionBadId &) { @@ -104,9 +115,43 @@ void FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pat } } - labelWidth = labelData.GetLabelWidth(); - labelHeight = labelData.GetLabelHeight(); - pos = labelData.GetPos(); + try + { + Calculator cal1; + labelWidth = cal1.EvalFormula(pattern->PlainVariables(), labelData.GetLabelWidth()); + + Calculator cal2; + labelHeight = cal2.EvalFormula(pattern->PlainVariables(), labelData.GetLabelHeight()); + } + catch(qmu::QmuParserError &e) + { + Q_UNUSED(e); + return false; + } + + const quint32 centerPin = labelData.CenterPin(); + if (centerPin != NULL_ID) + { + try + { + const auto centerPinPoint = pattern->GeometricObject(centerPin); + + const qreal lWidth = ToPixel(labelWidth, *pattern->GetPatternUnit()); + const qreal lHeight = ToPixel(labelHeight, *pattern->GetPatternUnit()); + + pos = *centerPinPoint - QRectF(0, 0, lWidth, lHeight).center(); + } + catch(const VExceptionBadId &) + { + pos = labelData.GetPos(); + } + } + else + { + pos = labelData.GetPos(); + } + + return true; } //--------------------------------------------------------------------------------------------------------------------- @@ -161,7 +206,32 @@ bool FindGrainlineGeometry(const VGrainlineData& geom, const VContainer *pattern return false; } - pos = geom.GetPos(); + const quint32 centerPin = geom.CenterPin(); + if (centerPin != NULL_ID) + { + try + { + const auto centerPinPoint = pattern->GeometricObject(centerPin); + + const qreal cLength = ToPixel(length, *pattern->GetPatternUnit()); + QLineF grainline(centerPinPoint->x(), centerPinPoint->y(), + centerPinPoint->x() + cLength / 2.0, centerPinPoint->y()); + + grainline.setAngle(rotationAngle); + grainline = QLineF(grainline.p2(), grainline.p1()); + grainline.setLength(cLength); + + pos = grainline.p2(); + } + catch(const VExceptionBadId &) + { + pos = geom.GetPos(); + } + } + else + { + pos = geom.GetPos(); + } return true; } @@ -401,7 +471,14 @@ void VLayoutPiece::SetDetail(const QString& qsName, const VPieceLabelData& data, QPointF ptPos; qreal labelWidth = 0; qreal labelHeight = 0; - FindLabelGeometry(data, pattern, labelWidth, labelHeight, ptPos); + qreal labelAngle = 0; + if (not FindLabelGeometry(data, pattern, labelAngle, labelWidth, labelHeight, ptPos)) + { + return; + } + + labelWidth = ToPixel(labelWidth, *pattern->GetPatternUnit()); + labelHeight = ToPixel(labelHeight, *pattern->GetPatternUnit()); QVector v; v << ptPos @@ -409,7 +486,7 @@ void VLayoutPiece::SetDetail(const QString& qsName, const VPieceLabelData& data, << QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight) << QPointF(ptPos.x(), ptPos.y() + labelHeight); - const qreal dAng = qDegreesToRadians(data.GetRotation()); + const qreal dAng = qDegreesToRadians(labelAngle); const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2); for (int i = 0; i < v.count(); ++i) { @@ -435,7 +512,14 @@ void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLa QPointF ptPos; qreal labelWidth = 0; qreal labelHeight = 0; - FindLabelGeometry(geom, pattern, labelWidth, labelHeight, ptPos); + qreal labelAngle = 0; + if (not FindLabelGeometry(geom, pattern, labelAngle, labelWidth, labelHeight, ptPos)) + { + return; + } + + labelWidth = ToPixel(labelWidth, *pattern->GetPatternUnit()); + labelHeight = ToPixel(labelHeight, *pattern->GetPatternUnit()); QVector v; v << ptPos @@ -443,7 +527,7 @@ void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLa << QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight) << QPointF(ptPos.x(), ptPos.y() + labelHeight); - const qreal dAng = qDegreesToRadians(geom.GetRotation()); + const qreal dAng = qDegreesToRadians(labelAngle); const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2); for (int i = 0; i < v.count(); ++i) { diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp b/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp index de189c075..a0ed3eecf 100644 --- a/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata.cpp @@ -95,6 +95,18 @@ void VGrainlineData::SetArrowType(ArrowType eAT) d->m_eArrowType = eAT; } +//--------------------------------------------------------------------------------------------------------------------- +quint32 VGrainlineData::CenterPin() const +{ + return d->m_centerPin; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineData::SetCenterPin(quint32 centerPin) +{ + d->m_centerPin = centerPin; +} + //--------------------------------------------------------------------------------------------------------------------- quint32 VGrainlineData::TopPin() const { diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata.h b/src/libs/vpatterndb/floatItemData/vgrainlinedata.h index dc259bf0e..97c247a37 100644 --- a/src/libs/vpatterndb/floatItemData/vgrainlinedata.h +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata.h @@ -59,6 +59,9 @@ public: ArrowType GetArrowType() const; void SetArrowType(ArrowType eAT); + quint32 CenterPin() const; + void SetCenterPin(quint32 centerPin); + quint32 TopPin() const; void SetTopPin(quint32 topPin); diff --git a/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h b/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h index cb85be652..5f336dfad 100644 --- a/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h +++ b/src/libs/vpatterndb/floatItemData/vgrainlinedata_p.h @@ -46,6 +46,7 @@ public: : m_qsLength(), m_dRotation(), m_eArrowType(ArrowType::atBoth), + m_centerPin(NULL_ID), m_topPin(NULL_ID), m_bottomPin(NULL_ID) {} @@ -55,6 +56,7 @@ public: m_qsLength(data.m_qsLength), m_dRotation(data.m_dRotation), m_eArrowType(data.m_eArrowType), + m_centerPin(data.m_centerPin), m_topPin(data.m_topPin), m_bottomPin(data.m_bottomPin) {} @@ -67,6 +69,8 @@ public: QString m_dRotation; /** @brief m_eArrowType type of arrow on the grainline */ ArrowType m_eArrowType; + /** @brief m_centerPin center pin id */ + quint32 m_centerPin; /** @brief m_topPin top pin id */ quint32 m_topPin; /** @brief m_bottomPin bottom pin id */ diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp index e87f06ddd..efe939c73 100644 --- a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.cpp @@ -59,25 +59,25 @@ VPatternLabelData::~VPatternLabelData() {} //--------------------------------------------------------------------------------------------------------------------- -qreal VPatternLabelData::GetLabelWidth() const +QString VPatternLabelData::GetLabelWidth() const { return d->m_dLabelWidth; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternLabelData::SetLabelWidth(qreal dLabelW) +void VPatternLabelData::SetLabelWidth(const QString &dLabelW) { d->m_dLabelWidth = dLabelW; } //--------------------------------------------------------------------------------------------------------------------- -qreal VPatternLabelData::GetLabelHeight() const +QString VPatternLabelData::GetLabelHeight() const { return d->m_dLabelHeight; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternLabelData::SetLabelHeight(qreal dLabelH) +void VPatternLabelData::SetLabelHeight(const QString &dLabelH) { d->m_dLabelHeight = dLabelH; } @@ -95,15 +95,27 @@ void VPatternLabelData::SetFontSize(int iSize) } //--------------------------------------------------------------------------------------------------------------------- -qreal VPatternLabelData::GetRotation() const +QString VPatternLabelData::GetRotation() const { - return d->m_dRotation; + return d->m_dLabelAngle; } //--------------------------------------------------------------------------------------------------------------------- -void VPatternLabelData::SetRotation(qreal dRot) +void VPatternLabelData::SetRotation(const QString &dRot) { - d->m_dRotation = dRot; + d->m_dLabelAngle = dRot; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VPatternLabelData::CenterPin() const +{ + return d->m_centerPin; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VPatternLabelData::SetCenterPin(const quint32 ¢erPin) +{ + d->m_centerPin = centerPin; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h index 29cdeffc3..aa9160dab 100644 --- a/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata.h @@ -47,17 +47,20 @@ public: virtual ~VPatternLabelData(); // methods, which set up label parameters - qreal GetLabelWidth() const; - void SetLabelWidth(qreal dLabelW); + QString GetLabelWidth() const; + void SetLabelWidth(const QString &dLabelW); - qreal GetLabelHeight() const; - void SetLabelHeight(qreal dLabelH); + QString GetLabelHeight() const; + void SetLabelHeight(const QString &dLabelH); int GetFontSize() const; void SetFontSize(int iSize); - qreal GetRotation() const; - void SetRotation(qreal dRot); + QString GetRotation() const; + void SetRotation(const QString &dRot); + + quint32 CenterPin() const; + void SetCenterPin(const quint32 ¢erPin); quint32 TopLeftPin() const; void SetTopLeftPin(const quint32 &topLeftPin); diff --git a/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h b/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h index 783addb83..17859d696 100644 --- a/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h +++ b/src/libs/vpatterndb/floatItemData/vpatternlabeldata_p.h @@ -42,10 +42,11 @@ class VPatternLabelDataPrivate : public QSharedData { public: VPatternLabelDataPrivate() - : m_dLabelWidth(0), - m_dLabelHeight(0), + : m_dLabelWidth(), + m_dLabelHeight(), + m_dLabelAngle(), m_iFontSize(0), - m_dRotation(0), + m_centerPin(NULL_ID), m_topLeftPin(NULL_ID), m_bottomRightPin(NULL_ID) {} @@ -54,22 +55,25 @@ public: : QSharedData(data), m_dLabelWidth(data.m_dLabelWidth), m_dLabelHeight(data.m_dLabelHeight), + m_dLabelAngle(data.m_dLabelAngle), m_iFontSize(data.m_iFontSize), - m_dRotation(data.m_dRotation), + m_centerPin(data.m_centerPin), m_topLeftPin(data.m_topLeftPin), m_bottomRightPin(data.m_bottomRightPin) {} ~VPatternLabelDataPrivate(); - /** @brief m_dLabelWidth label width */ - qreal m_dLabelWidth; - /** @brief m_dLabelHeight label height */ - qreal m_dLabelHeight; + /** @brief m_dLabelWidth formula to calculate the width of label */ + QString m_dLabelWidth; + /** @brief m_dLabelHeight formula to calculate the height of label */ + QString m_dLabelHeight; + /** @brief m_dLabelAngle formula to calculate the rotation angle of label */ + QString m_dLabelAngle; /** @brief m_iFontSize label text base font size */ int m_iFontSize; - /** @brief m_dRotation label rotation */ - qreal m_dRotation; + /** @brief m_centerPin center pin id */ + quint32 m_centerPin; /** @brief m_topLeftPin top left corner pin id */ quint32 m_topLeftPin; /** @brief m_bottomRightPin bottom right corner pin id */ diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp index 01924a406..5d1b63e6f 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.cpp @@ -73,7 +73,11 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & flagGPin(true), flagDPin(true), flagPPin(true), - flagGFormulas(false), + flagGFormulas(true), + flagDLAngle(true), + flagDLFormulas(true), + flagPLAngle(true), + flagPLFormulas(true), m_bAddMode(true), m_mx(0), m_my(0), @@ -87,6 +91,12 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & m_oldGrainline(), m_iRotBaseHeight(0), m_iLenBaseHeight(0), + m_DLWidthBaseHeight(0), + m_DLHeightBaseHeight(0), + m_DLAngleBaseHeight(0), + m_PLWidthBaseHeight(0), + m_PLHeightBaseHeight(0), + m_PLAngleBaseHeight(0), m_formulaBaseWidth(0), m_formulaBaseWidthBefore(0), m_formulaBaseWidthAfter(0), @@ -104,6 +114,7 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 & InitSeamAllowanceTab(); InitInternalPathsTab(); InitPatternPieceDataTab(); + InitLabelsTab(); InitGrainlineTab(); InitPinsTab(); @@ -137,7 +148,8 @@ void DialogSeamAllowance::EnableApply(bool enable) applyAllowed = enable; ui->tabSeamAllowance->setEnabled(applyAllowed); ui->tabInternalPaths->setEnabled(applyAllowed); - ui->tabPatternPieceData->setEnabled(applyAllowed); + ui->tabPieceLabelData->setEnabled(applyAllowed); + ui->tabLabels->setEnabled(applyAllowed); ui->tabGrainline->setEnabled(applyAllowed); ui->tabPins->setEnabled(applyAllowed); } @@ -201,8 +213,6 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) m_my = piece.GetMy(); ui->lineEditLetter->setText(piece.GetPatternPieceData().GetLetter()); - ui->groupBoxDetailLabel->setChecked(piece.GetPatternPieceData().IsVisible()); - ui->groupBoxPatternLabel->setChecked(piece.GetPatternInfo().IsVisible()); m_conMCP.clear(); for (int i = 0; i < piece.GetPatternPieceData().GetMCPCount(); ++i) @@ -212,25 +222,38 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece) UpdateList(); - ui->groupBoxGrainline->setChecked(piece.GetGrainlineGeometry().IsVisible()); - SetGrainlineAngle(piece.GetGrainlineGeometry()); - SetGrainlineLength(piece.GetGrainlineGeometry()); ui->comboBoxArrow->setCurrentIndex(int(piece.GetGrainlineGeometry().GetArrowType())); m_oldData = piece.GetPatternPieceData(); - ChangeCurrentData(ui->comboBoxDetailLabelTopLeftPin, m_oldData.TopLeftPin()); - ChangeCurrentData(ui->comboBoxDetailLabelBottomRightPin, m_oldData.BottomRightPin()); + ui->groupBoxDetailLabel->setChecked(m_oldData.IsVisible()); + ChangeCurrentData(ui->comboBoxDLCenterPin, m_oldData.CenterPin()); + ChangeCurrentData(ui->comboBoxDLTopLeftPin, m_oldData.TopLeftPin()); + ChangeCurrentData(ui->comboBoxDLBottomRightPin, m_oldData.BottomRightPin()); + SetDLWidth(m_oldData.GetLabelWidth()); + SetDLHeight(m_oldData.GetLabelHeight()); + SetDLAngle(m_oldData.GetRotation()); m_oldGeom = piece.GetPatternInfo(); - ChangeCurrentData(ui->comboBoxPatternLabelTopLeftPin, m_oldGeom.TopLeftPin()); - ChangeCurrentData(ui->comboBoxPatternLabelBottomRightPin, m_oldGeom.BottomRightPin()); + ui->groupBoxPatternLabel->setChecked(m_oldGeom.IsVisible()); + ChangeCurrentData(ui->comboBoxPLCenterPin, m_oldGeom.CenterPin()); + ChangeCurrentData(ui->comboBoxPLTopLeftPin, m_oldGeom.TopLeftPin()); + ChangeCurrentData(ui->comboBoxPLBottomRightPin, m_oldGeom.BottomRightPin()); + SetPLWidth(m_oldGeom.GetLabelWidth()); + SetPLHeight(m_oldGeom.GetLabelHeight()); + SetPLAngle(m_oldGeom.GetRotation()); m_oldGrainline = piece.GetGrainlineGeometry(); + ui->groupBoxGrainline->setChecked(m_oldGrainline.IsVisible()); + ChangeCurrentData(ui->comboBoxGrainlineCenterPin, m_oldGrainline.CenterPin()); ChangeCurrentData(ui->comboBoxGrainlineTopPin, m_oldGrainline.TopPin()); ChangeCurrentData(ui->comboBoxGrainlineBottomPin, m_oldGrainline.BottomPin()); + SetGrainlineAngle(m_oldGrainline.GetRotation()); + SetGrainlineLength(m_oldGrainline.GetLength()); ValidObjects(MainPathIsValid()); - EnableGrainlineRotation(); + EnabledGrainline(); + EnabledDetailLabel(); + EnabledPatternLabel(); ListChanged(); } @@ -346,7 +369,8 @@ void DialogSeamAllowance::SaveData() void DialogSeamAllowance::CheckState() { SCASSERT(bOk != nullptr); - bOk->setEnabled(flagName && flagError && flagFormula && flagDPin && flagPPin && (flagGFormulas || flagGPin)); + bOk->setEnabled(flagName && flagError && flagFormula && (flagGFormulas || flagGPin) + && flagDLAngle && (flagDLFormulas || flagDPin) && flagPLAngle && (flagPLFormulas || flagPPin)); // In case dialog hasn't apply button if ( bApply != nullptr && applyAllowed) { @@ -919,7 +943,7 @@ void DialogSeamAllowance::TabChanged(int index) { if (index == ui->tabWidget->indexOf(ui->tabPins) || index == ui->tabWidget->indexOf(ui->tabGrainline) - || index == ui->tabWidget->indexOf(ui->tabPatternPieceData)) + || index == ui->tabWidget->indexOf(ui->tabLabels)) { if (m_visPins.isNull()) { @@ -947,12 +971,10 @@ void DialogSeamAllowance::TabChanged(int index) } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::UpdateValues() +void DialogSeamAllowance::UpdateGrainlineValues() { - QPlainTextEdit* apleSender[2]; - apleSender[0] = ui->lineEditRotFormula; - apleSender[1] = ui->lineEditLenFormula; - bool bFormulasOK = true; + QPlainTextEdit* apleSender[2] = {ui->lineEditRotFormula, ui->lineEditLenFormula}; + bool bFormulasOK[2] = {true, true}; for (int i = 0; i < 2; ++i) { @@ -998,20 +1020,20 @@ void DialogSeamAllowance::UpdateValues() } catch (qmu::QmuParserError &e) { - qsVal.clear(); - ChangeColor(plbText, Qt::red); - bFormulasOK = false; + qsVal = tr("Error"); + not flagGPin ? ChangeColor(plbText, Qt::red) : ChangeColor(plbText, okColor); + bFormulasOK[i] = false; plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); } - if (qsVal.isEmpty() == false) + if (bFormulasOK[i] && qsVal.isEmpty() == false) { qsVal += qsUnit; } plbVal->setText(qsVal); } - flagGFormulas = bFormulasOK; + flagGFormulas = bFormulasOK[0] && bFormulasOK[1]; if (not flagGFormulas && not flagGPin) { QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); @@ -1019,7 +1041,175 @@ void DialogSeamAllowance::UpdateValues() } else { - ResetWarning(); + ResetGrainlineWarning(); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::UpdateDetailLabelValues() +{ + QPlainTextEdit* apleSender[3] = {ui->lineEditDLWidthFormula, ui->lineEditDLHeightFormula, + ui->lineEditDLAngleFormula}; + bool bFormulasOK[3] = {true, true, true}; + + for (int i = 0; i < 3; ++i) + { + QLabel* plbVal; + QLabel* plbText; + QString qsUnit; + if (i == 0) + { + plbVal = ui->labelDLWidth; + plbText = ui->labelEditDLWidth; + qsUnit = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit()); + } + else if (i == 1) + { + plbVal = ui->labelDLHeight; + plbText = ui->labelEditDLHeight; + qsUnit = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit()); + } + else + { + plbVal = ui->labelDLAngle; + plbText = ui->labelEditDLAngle; + qsUnit = degreeSymbol; + } + + plbVal->setToolTip(tr("Value")); + + QString qsFormula = apleSender[i]->toPlainText().simplified(); + QString qsVal; + try + { + qsFormula.replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + Calculator cal; + qreal dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); + if (qIsInf(dVal) == true || qIsNaN(dVal) == true) + { + throw qmu::QmuParserError(tr("Infinite/undefined result")); + } + else if ((i == 0 || i == 1) && dVal <= 0.0) + { + throw qmu::QmuParserError(tr("Length should be positive")); + } + else + { + qsVal.setNum(dVal, 'f', 2); + ChangeColor(plbText, okColor); + } + } + catch (qmu::QmuParserError &e) + { + qsVal = tr("Error"); + not flagDPin ? ChangeColor(plbText, Qt::red) : ChangeColor(plbText, okColor); + bFormulasOK[i] = false; + plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); + } + + if (bFormulasOK[i] && qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } + plbVal->setText(qsVal); + } + + flagDLAngle = bFormulasOK[2]; + flagDLFormulas = bFormulasOK[0] && bFormulasOK[1]; + if (not flagDLAngle || not (flagDLFormulas || flagDPin) || not flagPLAngle || not (flagPLFormulas || flagPPin)) + { + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); + } + else + { + ResetLabelsWarning(); + } + CheckState(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::UpdatePatternLabelValues() +{ + QPlainTextEdit* apleSender[3] = {ui->lineEditPLWidthFormula, ui->lineEditPLHeightFormula, + ui->lineEditPLAngleFormula}; + bool bFormulasOK[3] = {true, true, true}; + + for (int i = 0; i < 3; ++i) + { + QLabel* plbVal; + QLabel* plbText; + QString qsUnit; + if (i == 0) + { + plbVal = ui->labelPLWidth; + plbText = ui->labelEditPLWidth; + qsUnit = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit()); + } + else if (i == 1) + { + plbVal = ui->labelPLHeight; + plbText = ui->labelEditPLHeight; + qsUnit = QLatin1String(" ") + VDomDocument::UnitsToStr(qApp->patternUnit()); + } + else + { + plbVal = ui->labelPLAngle; + plbText = ui->labelEditPLAngle; + qsUnit = degreeSymbol; + } + + plbVal->setToolTip(tr("Value")); + + QString qsFormula = apleSender[i]->toPlainText().simplified(); + QString qsVal; + try + { + qsFormula.replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + Calculator cal; + qreal dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); + if (qIsInf(dVal) == true || qIsNaN(dVal) == true) + { + throw qmu::QmuParserError(tr("Infinite/undefined result")); + } + else if ((i == 0 || i == 1) && dVal <= 0.0) + { + throw qmu::QmuParserError(tr("Length should be positive")); + } + else + { + qsVal.setNum(dVal, 'f', 2); + ChangeColor(plbText, okColor); + } + } + catch (qmu::QmuParserError &e) + { + qsVal = tr("Error"); + not flagPPin ? ChangeColor(plbText, Qt::red) : ChangeColor(plbText, okColor); + bFormulasOK[i] = false; + plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); + } + + if (bFormulasOK[i] && qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } + plbVal->setText(qsVal); + } + + flagPLAngle = bFormulasOK[2]; + flagPLFormulas = bFormulasOK[0] && bFormulasOK[1]; + if (not flagDLAngle || not (flagDLFormulas || flagDPin) || not flagPLAngle || not (flagPLFormulas || flagPPin)) + { + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); + } + else + { + ResetLabelsWarning(); } CheckState(); } @@ -1072,35 +1262,73 @@ void DialogSeamAllowance::SetEditMode() } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::EnableGrainlineRotation() +void DialogSeamAllowance::EnabledGrainline() { if (ui->groupBoxGrainline->isChecked() == true) { - UpdateValues(); + UpdateGrainlineValues(); GrainlinePinPointChanged(); } else { flagGFormulas = true; - ResetWarning(); + ResetGrainlineWarning(); + CheckState(); } } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::EditFormula() +void DialogSeamAllowance::EnabledDetailLabel() +{ + if (ui->groupBoxDetailLabel->isChecked() == true) + { + UpdateDetailLabelValues(); + DetailPinPointChanged(); + } + else + { + flagDLAngle = true; + flagDLFormulas = true; + ResetLabelsWarning(); + CheckState(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EnabledPatternLabel() +{ + if (ui->groupBoxPatternLabel->isChecked() == true) + { + UpdatePatternLabelValues(); + PatternPinPointChanged(); + } + else + { + flagPLAngle = true; + flagPLFormulas = true; + ResetLabelsWarning(); + CheckState(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EditGrainlineFormula() { QPlainTextEdit* pleFormula; bool bCheckZero; + QString title; if (sender() == ui->pushButtonLen) { pleFormula = ui->lineEditLenFormula; bCheckZero = true; + title = tr("Edit length"); } else if (sender() == ui->pushButtonRot) { pleFormula = ui->lineEditRotFormula; bCheckZero = false; + title = tr("Edit angle"); } else { @@ -1109,31 +1337,201 @@ void DialogSeamAllowance::EditFormula() } DialogEditWrongFormula dlg(data, NULL_ID, this); - dlg.SetFormula(pleFormula->toPlainText()); + dlg.setWindowTitle(title); + dlg.SetFormula(qApp->TrVars()->TryFormulaFromUser(pleFormula->toPlainText(), qApp->Settings()->GetOsSeparator())); dlg.setCheckZero(bCheckZero); if (dlg.exec() == QDialog::Accepted) { QString qsFormula = dlg.GetFormula(); qsFormula.replace("\n", " "); - pleFormula->setPlainText(qsFormula); - UpdateValues(); + + if (sender() == ui->pushButtonLen) + { + SetGrainlineLength(qsFormula); + } + else if (sender() == ui->pushButtonRot) + { + SetGrainlineAngle(qsFormula); + } + else + { + // should not get here! + pleFormula->setPlainText(qsFormula); + } + UpdateGrainlineValues(); } } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::DeployRotation() +void DialogSeamAllowance::EditDLFormula() +{ + QPlainTextEdit* pleFormula; + bool bCheckZero; + QString title; + + if (sender() == ui->pushButtonDLHeight) + { + pleFormula = ui->lineEditDLHeightFormula; + bCheckZero = true; + title = tr("Edit height"); + } + else if (sender() == ui->pushButtonDLWidth) + { + pleFormula = ui->lineEditDLWidthFormula; + bCheckZero = true; + title = tr("Edit width"); + } + else if (sender() == ui->pushButtonDLAngle) + { + pleFormula = ui->lineEditDLAngleFormula; + bCheckZero = false; + title = tr("Edit angle"); + } + else + { + // should not get here! + return; + } + + DialogEditWrongFormula dlg(data, NULL_ID, this); + dlg.setWindowTitle(title); + dlg.SetFormula(qApp->TrVars()->TryFormulaFromUser(pleFormula->toPlainText(), qApp->Settings()->GetOsSeparator())); + dlg.setCheckZero(bCheckZero); + if (dlg.exec() == QDialog::Accepted) + { + QString qsFormula = dlg.GetFormula(); + qsFormula.replace("\n", " "); + if (sender() == ui->pushButtonDLHeight) + { + SetDLHeight(qsFormula); + } + else if (sender() == ui->pushButtonDLWidth) + { + SetDLWidth(qsFormula); + } + else if (sender() == ui->pushButtonDLAngle) + { + SetDLAngle(qsFormula); + } + else + { + // should not get here! + pleFormula->setPlainText(qsFormula); + } + UpdateDetailLabelValues(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::EditPLFormula() +{ + QPlainTextEdit* pleFormula; + bool bCheckZero; + QString title; + + if (sender() == ui->pushButtonPLHeight) + { + pleFormula = ui->lineEditPLHeightFormula; + bCheckZero = true; + title = tr("Edit height"); + } + else if (sender() == ui->pushButtonPLWidth) + { + pleFormula = ui->lineEditPLWidthFormula; + bCheckZero = true; + title = tr("Edit width"); + } + else if (sender() == ui->pushButtonPLAngle) + { + pleFormula = ui->lineEditPLAngleFormula; + bCheckZero = false; + title = tr("Edit angle"); + } + else + { + // should not get here! + return; + } + + DialogEditWrongFormula dlg(data, NULL_ID, this); + dlg.setWindowTitle(title); + dlg.SetFormula(qApp->TrVars()->TryFormulaFromUser(pleFormula->toPlainText(), qApp->Settings()->GetOsSeparator())); + dlg.setCheckZero(bCheckZero); + if (dlg.exec() == QDialog::Accepted) + { + QString qsFormula = dlg.GetFormula(); + qsFormula.replace("\n", " "); + if (sender() == ui->pushButtonPLHeight) + { + SetPLHeight(qsFormula); + } + else if (sender() == ui->pushButtonPLWidth) + { + SetPLWidth(qsFormula); + } + else if (sender() == ui->pushButtonPLAngle) + { + SetPLAngle(qsFormula); + } + else + { + // should not get here! + pleFormula->setPlainText(qsFormula); + } + UpdatePatternLabelValues(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployGrainlineRotation() { DeployFormula(ui->lineEditRotFormula, ui->pushButtonShowRot, m_iRotBaseHeight); } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::DeployLength() +void DialogSeamAllowance::DeployGrainlineLength() { DeployFormula(ui->lineEditLenFormula, ui->pushButtonShowLen, m_iLenBaseHeight); } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::ResetWarning() +void DialogSeamAllowance::DeployDLWidth() +{ + DeployFormula(ui->lineEditDLWidthFormula, ui->pushButtonShowDLWidth, m_DLWidthBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployDLHeight() +{ + DeployFormula(ui->lineEditDLHeightFormula, ui->pushButtonShowDLHeight, m_DLHeightBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployDLAngle() +{ + DeployFormula(ui->lineEditDLAngleFormula, ui->pushButtonShowDLAngle, m_DLAngleBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployPLWidth() +{ + DeployFormula(ui->lineEditPLWidthFormula, ui->pushButtonShowPLWidth, m_PLWidthBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployPLHeight() +{ + DeployFormula(ui->lineEditPLHeightFormula, ui->pushButtonShowPLHeight, m_PLHeightBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::DeployPLAngle() +{ + DeployFormula(ui->lineEditPLAngleFormula, ui->pushButtonShowPLAngle, m_PLAngleBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::ResetGrainlineWarning() { if (flagGFormulas || flagGPin) { @@ -1141,6 +1539,15 @@ void DialogSeamAllowance::ResetWarning() } } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::ResetLabelsWarning() +{ + if (flagDLAngle && (flagDLFormulas || flagDPin) && flagPLAngle && (flagPLFormulas || flagPPin)) + { + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), QIcon()); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::EvalWidth() { @@ -1292,12 +1699,12 @@ void DialogSeamAllowance::GrainlinePinPointChanged() flagGPin = true; color = okColor; - ResetWarning(); + ResetGrainlineWarning(); } else { flagGPin = false; - color = errorColor; + topPinId == NULL_ID && bottomPinId == NULL_ID ? color = okColor : color = errorColor; if (not flagGFormulas && not flagGPin) { @@ -1305,6 +1712,7 @@ void DialogSeamAllowance::GrainlinePinPointChanged() ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabGrainline), icon); } } + UpdateGrainlineValues(); ChangeColor(ui->labelGrainlineTopPin, color); ChangeColor(ui->labelGrainlineBottomPin, color); CheckState(); @@ -1314,29 +1722,29 @@ void DialogSeamAllowance::GrainlinePinPointChanged() void DialogSeamAllowance::DetailPinPointChanged() { QColor color = okColor; - const quint32 topPinId = getCurrentObjectId(ui->comboBoxDetailLabelTopLeftPin); - const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxDetailLabelBottomRightPin); - if ((topPinId == NULL_ID && bottomPinId == NULL_ID) - || (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)) + const quint32 topPinId = getCurrentObjectId(ui->comboBoxDLTopLeftPin); + const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxDLBottomRightPin); + if (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId) { flagDPin = true; color = okColor; if (flagPPin) { - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), QIcon()); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), QIcon()); } } else { flagDPin = false; - color = errorColor; + topPinId == NULL_ID && bottomPinId == NULL_ID ? color = okColor : color = errorColor; QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), icon); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); } - ChangeColor(ui->labelDetailLabelTopLeftPin, color); - ChangeColor(ui->labelDetailLabelBottomRightPin, color); + UpdateDetailLabelValues(); + ChangeColor(ui->labelDLTopLeftPin, color); + ChangeColor(ui->labelDLBottomRightPin, color); CheckState(); } @@ -1344,29 +1752,29 @@ void DialogSeamAllowance::DetailPinPointChanged() void DialogSeamAllowance::PatternPinPointChanged() { QColor color = okColor; - const quint32 topPinId = getCurrentObjectId(ui->comboBoxPatternLabelTopLeftPin); - const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxPatternLabelBottomRightPin); - if ((topPinId == NULL_ID && bottomPinId == NULL_ID) - || (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)) + const quint32 topPinId = getCurrentObjectId(ui->comboBoxPLTopLeftPin); + const quint32 bottomPinId = getCurrentObjectId(ui->comboBoxPLBottomRightPin); + if (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId) { flagPPin = true; color = okColor; if (flagDPin) { - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), QIcon()); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), QIcon()); } } else { flagPPin = false; - color = errorColor; + topPinId == NULL_ID && bottomPinId == NULL_ID ? color = okColor : color = errorColor; QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); - ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabPatternPieceData), icon); + ui->tabWidget->setTabIcon(ui->tabWidget->indexOf(ui->tabLabels), icon); } - ChangeColor(ui->labelPatternLabelTopLeftPin, color); - ChangeColor(ui->labelPatternLabelBottomRightPin, color); + UpdatePatternLabelValues(); + ChangeColor(ui->labelPLTopLeftPin, color); + ChangeColor(ui->labelPLBottomRightPin, color); CheckState(); } @@ -1392,24 +1800,30 @@ VPiece DialogSeamAllowance::CreatePiece() const } piece.GetPatternPieceData().SetPos(m_oldData.GetPos()); - piece.GetPatternPieceData().SetLabelWidth(m_oldData.GetLabelWidth()); - piece.GetPatternPieceData().SetLabelHeight(m_oldData.GetLabelHeight()); + piece.GetPatternPieceData().SetLabelWidth(GetFormulaFromUser(ui->lineEditDLWidthFormula)); + piece.GetPatternPieceData().SetLabelHeight(GetFormulaFromUser(ui->lineEditDLHeightFormula)); piece.GetPatternPieceData().SetFontSize(m_oldData.GetFontSize()); - piece.GetPatternPieceData().SetRotation(m_oldData.GetRotation()); + piece.GetPatternPieceData().SetRotation(GetFormulaFromUser(ui->lineEditDLAngleFormula)); piece.GetPatternPieceData().SetVisible(ui->groupBoxDetailLabel->isChecked()); - piece.GetPatternPieceData().SetTopLeftPin(getCurrentObjectId(ui->comboBoxDetailLabelTopLeftPin)); - piece.GetPatternPieceData().SetBottomRightPin(getCurrentObjectId(ui->comboBoxDetailLabelBottomRightPin)); + piece.GetPatternPieceData().SetCenterPin(getCurrentObjectId(ui->comboBoxDLCenterPin)); + piece.GetPatternPieceData().SetTopLeftPin(getCurrentObjectId(ui->comboBoxDLTopLeftPin)); + piece.GetPatternPieceData().SetBottomRightPin(getCurrentObjectId(ui->comboBoxDLBottomRightPin)); piece.GetPatternInfo() = m_oldGeom; piece.GetPatternInfo().SetVisible(ui->groupBoxPatternLabel->isChecked()); - piece.GetPatternInfo().SetTopLeftPin(getCurrentObjectId(ui->comboBoxPatternLabelTopLeftPin)); - piece.GetPatternInfo().SetBottomRightPin(getCurrentObjectId(ui->comboBoxPatternLabelBottomRightPin)); + piece.GetPatternInfo().SetCenterPin(getCurrentObjectId(ui->comboBoxPLCenterPin)); + piece.GetPatternInfo().SetTopLeftPin(getCurrentObjectId(ui->comboBoxPLTopLeftPin)); + piece.GetPatternInfo().SetBottomRightPin(getCurrentObjectId(ui->comboBoxPLBottomRightPin)); + piece.GetPatternInfo().SetLabelWidth(GetFormulaFromUser(ui->lineEditPLWidthFormula)); + piece.GetPatternInfo().SetLabelHeight(GetFormulaFromUser(ui->lineEditPLHeightFormula)); + piece.GetPatternInfo().SetRotation(GetFormulaFromUser(ui->lineEditPLAngleFormula)); piece.GetGrainlineGeometry() = m_oldGrainline; piece.GetGrainlineGeometry().SetVisible(ui->groupBoxGrainline->isChecked()); piece.GetGrainlineGeometry().SetRotation(GetFormulaFromUser(ui->lineEditRotFormula)); piece.GetGrainlineGeometry().SetLength(GetFormulaFromUser(ui->lineEditLenFormula)); piece.GetGrainlineGeometry().SetArrowType(static_cast(ui->comboBoxArrow->currentIndex())); + piece.GetGrainlineGeometry().SetCenterPin(getCurrentObjectId(ui->comboBoxGrainlineCenterPin)); piece.GetGrainlineGeometry().SetTopPin(getCurrentObjectId(ui->comboBoxGrainlineTopPin)); piece.GetGrainlineGeometry().SetBottomPin(getCurrentObjectId(ui->comboBoxGrainlineBottomPin)); @@ -1810,26 +2224,6 @@ void DialogSeamAllowance::InitPatternPieceDataTab() ui->lineEditLetter->setClearButtonEnabled(true); #endif - InitPinPoint(ui->comboBoxDetailLabelTopLeftPin); - InitPinPoint(ui->comboBoxDetailLabelBottomRightPin); - - connect(ui->comboBoxDetailLabelTopLeftPin, - static_cast(&QComboBox::currentIndexChanged), - this, &DialogSeamAllowance::DetailPinPointChanged); - connect(ui->comboBoxDetailLabelBottomRightPin, - static_cast(&QComboBox::currentIndexChanged), - this, &DialogSeamAllowance::DetailPinPointChanged); - - InitPinPoint(ui->comboBoxPatternLabelTopLeftPin); - InitPinPoint(ui->comboBoxPatternLabelBottomRightPin); - - connect(ui->comboBoxPatternLabelTopLeftPin, - static_cast(&QComboBox::currentIndexChanged), - this, &DialogSeamAllowance::PatternPinPointChanged); - connect(ui->comboBoxPatternLabelBottomRightPin, - static_cast(&QComboBox::currentIndexChanged), - this, &DialogSeamAllowance::PatternPinPointChanged); - connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSeamAllowance::NameDetailChanged); m_qslMaterials << QApplication::translate("Detail", "Fabric", 0) @@ -1850,30 +2244,99 @@ void DialogSeamAllowance::InitPatternPieceDataTab() m_qslPlacements << tr("None") << tr("Cut on fold"); ui->comboBoxPlacement->addItems(m_qslPlacements); - ui->pushButtonRot->setIcon(QIcon("://icon/16x16/fx.png")); - ui->pushButtonLen->setIcon(QIcon("://icon/16x16/fx.png")); connect(ui->pushButtonAdd, &QPushButton::clicked, this, &DialogSeamAllowance::AddUpdate); connect(ui->pushButtonCancel, &QPushButton::clicked, this, &DialogSeamAllowance::Cancel); connect(ui->pushButtonRemove, &QPushButton::clicked, this, &DialogSeamAllowance::Remove); connect(ui->listWidgetMCP, &QListWidget::itemClicked, this, &DialogSeamAllowance::SetEditMode); connect(ui->comboBoxMaterial, &QComboBox::currentTextChanged, this, &DialogSeamAllowance::MaterialChanged); + + SetAddMode(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::InitLabelsTab() +{ + m_DLWidthBaseHeight = ui->lineEditDLWidthFormula->height(); + m_DLHeightBaseHeight = ui->lineEditDLHeightFormula->height(); + m_DLAngleBaseHeight = ui->lineEditDLAngleFormula->height(); + + connect(ui->groupBoxDetailLabel, &QGroupBox::toggled, this, &DialogSeamAllowance::EnabledDetailLabel); + InitPinPoint(ui->comboBoxDLCenterPin); + InitPinPoint(ui->comboBoxDLTopLeftPin); + InitPinPoint(ui->comboBoxDLBottomRightPin); + + connect(ui->comboBoxDLTopLeftPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::DetailPinPointChanged); + connect(ui->comboBoxDLBottomRightPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::DetailPinPointChanged); + + connect(ui->pushButtonDLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::EditDLFormula); + connect(ui->pushButtonDLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::EditDLFormula); + connect(ui->pushButtonDLAngle, &QPushButton::clicked, this, &DialogSeamAllowance::EditDLFormula); + + connect(ui->lineEditDLWidthFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdateDetailLabelValues); + connect(ui->lineEditDLHeightFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdateDetailLabelValues); + connect(ui->lineEditDLAngleFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdateDetailLabelValues); + + connect(ui->pushButtonShowDLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::DeployDLWidth); + connect(ui->pushButtonShowDLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::DeployDLHeight); + connect(ui->pushButtonShowDLAngle, &QPushButton::clicked, this, &DialogSeamAllowance::DeployDLAngle); + + EnabledDetailLabel(); + + m_PLWidthBaseHeight = ui->lineEditPLWidthFormula->height(); + m_PLHeightBaseHeight = ui->lineEditPLHeightFormula->height(); + m_PLAngleBaseHeight = ui->lineEditPLAngleFormula->height(); + + connect(ui->groupBoxPatternLabel, &QGroupBox::toggled, this, &DialogSeamAllowance::EnabledPatternLabel); + InitPinPoint(ui->comboBoxPLCenterPin); + InitPinPoint(ui->comboBoxPLTopLeftPin); + InitPinPoint(ui->comboBoxPLBottomRightPin); + + connect(ui->comboBoxPLTopLeftPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::PatternPinPointChanged); + connect(ui->comboBoxPLBottomRightPin, + static_cast(&QComboBox::currentIndexChanged), + this, &DialogSeamAllowance::PatternPinPointChanged); + + connect(ui->pushButtonPLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::EditPLFormula); + connect(ui->pushButtonPLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::EditPLFormula); + connect(ui->pushButtonPLAngle, &QPushButton::clicked, this, &DialogSeamAllowance::EditPLFormula); + + connect(ui->lineEditPLWidthFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdatePatternLabelValues); + connect(ui->lineEditPLHeightFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdatePatternLabelValues); + connect(ui->lineEditPLAngleFormula, &QPlainTextEdit::textChanged, this, + &DialogSeamAllowance::UpdatePatternLabelValues); + + connect(ui->pushButtonShowPLWidth, &QPushButton::clicked, this, &DialogSeamAllowance::DeployPLWidth); + connect(ui->pushButtonShowPLHeight, &QPushButton::clicked, this, &DialogSeamAllowance::DeployPLHeight); + connect(ui->pushButtonShowPLAngle, &QPushButton::clicked, this, &DialogSeamAllowance::DeployPLAngle); + + EnabledPatternLabel(); } //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitGrainlineTab() { - connect(ui->groupBoxGrainline, &QGroupBox::toggled, this, &DialogSeamAllowance::EnableGrainlineRotation); - connect(ui->pushButtonRot, &QPushButton::clicked, this, &DialogSeamAllowance::EditFormula); - connect(ui->pushButtonLen, &QPushButton::clicked, this, &DialogSeamAllowance::EditFormula); - connect(ui->lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateValues); - connect(ui->lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateValues); + connect(ui->groupBoxGrainline, &QGroupBox::toggled, this, &DialogSeamAllowance::EnabledGrainline); + connect(ui->pushButtonRot, &QPushButton::clicked, this, &DialogSeamAllowance::EditGrainlineFormula); + connect(ui->pushButtonLen, &QPushButton::clicked, this, &DialogSeamAllowance::EditGrainlineFormula); + connect(ui->lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateGrainlineValues); + connect(ui->lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogSeamAllowance::UpdateGrainlineValues); - connect(ui->pushButtonShowRot, &QPushButton::clicked, this, &DialogSeamAllowance::DeployRotation); - connect(ui->pushButtonShowLen, &QPushButton::clicked, this, &DialogSeamAllowance::DeployLength); + connect(ui->pushButtonShowRot, &QPushButton::clicked, this, &DialogSeamAllowance::DeployGrainlineRotation); + connect(ui->pushButtonShowLen, &QPushButton::clicked, this, &DialogSeamAllowance::DeployGrainlineLength); - SetAddMode(); - EnableGrainlineRotation(); + EnabledGrainline(); ui->comboBoxArrow->addItem(tr("Both")); ui->comboBoxArrow->addItem(tr("Just front")); @@ -1882,6 +2345,7 @@ void DialogSeamAllowance::InitGrainlineTab() m_iRotBaseHeight = ui->lineEditRotFormula->height(); m_iLenBaseHeight = ui->lineEditLenFormula->height(); + InitPinPoint(ui->comboBoxGrainlineCenterPin); InitPinPoint(ui->comboBoxGrainlineTopPin); InitPinPoint(ui->comboBoxGrainlineBottomPin); @@ -1904,13 +2368,17 @@ void DialogSeamAllowance::InitPinsTab() //--------------------------------------------------------------------------------------------------------------------- void DialogSeamAllowance::InitAllPinComboboxes() { + InitPinPoint(ui->comboBoxGrainlineCenterPin); InitPinPoint(ui->comboBoxGrainlineTopPin); InitPinPoint(ui->comboBoxGrainlineBottomPin); - InitPinPoint(ui->comboBoxDetailLabelTopLeftPin); - InitPinPoint(ui->comboBoxDetailLabelBottomRightPin); - InitPinPoint(ui->comboBoxPatternLabelTopLeftPin); - InitPinPoint(ui->comboBoxPatternLabelBottomRightPin); + InitPinPoint(ui->comboBoxDLCenterPin); + InitPinPoint(ui->comboBoxDLTopLeftPin); + InitPinPoint(ui->comboBoxDLBottomRightPin); + + InitPinPoint(ui->comboBoxPLCenterPin); + InitPinPoint(ui->comboBoxPLTopLeftPin); + InitPinPoint(ui->comboBoxPLBottomRightPin); } //--------------------------------------------------------------------------------------------------------------------- @@ -1993,13 +2461,18 @@ QVector DialogSeamAllowance::GetPieceInternals(const QListWidget *list) const } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetGrainlineAngle(const VGrainlineData &data) +void DialogSeamAllowance::SetGrainlineAngle(QString angleFormula) { - const QString formula = qApp->TrVars()->FormulaToUser(data.GetRotation(), qApp->Settings()->GetOsSeparator()); + if (angleFormula.isEmpty()) + { + angleFormula = QString("0"); + } + + const QString formula = qApp->TrVars()->FormulaToUser(angleFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { - this->DeployRotation(); + this->DeployGrainlineRotation(); } ui->lineEditRotFormula->setPlainText(formula); @@ -2007,15 +2480,141 @@ void DialogSeamAllowance::SetGrainlineAngle(const VGrainlineData &data) } //--------------------------------------------------------------------------------------------------------------------- -void DialogSeamAllowance::SetGrainlineLength(const VGrainlineData &data) +void DialogSeamAllowance::SetGrainlineLength(QString lengthFormula) { - const QString formula = qApp->TrVars()->FormulaToUser(data.GetLength(), qApp->Settings()->GetOsSeparator()); + if (lengthFormula.isEmpty()) + { + lengthFormula = QString().setNum(UnitConvertor(1, Unit::Cm, *data->GetPatternUnit())); + } + + const QString formula = qApp->TrVars()->FormulaToUser(lengthFormula, qApp->Settings()->GetOsSeparator()); // increase height if needed. if (formula.length() > 80) { - this->DeployLength(); + this->DeployGrainlineLength(); } + ui->lineEditLenFormula->setPlainText(formula); MoveCursorToEnd(ui->lineEditLenFormula); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetDLWidth(QString widthFormula) +{ + if (widthFormula.isEmpty()) + { + widthFormula = QString().setNum(UnitConvertor(1, Unit::Cm, *data->GetPatternUnit())); + } + + const QString formula = qApp->TrVars()->FormulaToUser(widthFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployDLWidth(); + } + + ui->lineEditDLWidthFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditDLWidthFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetDLHeight(QString heightFormula) +{ + if (heightFormula.isEmpty()) + { + heightFormula = QString().setNum(UnitConvertor(1, Unit::Cm, *data->GetPatternUnit())); + } + + const QString formula = qApp->TrVars()->FormulaToUser(heightFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployDLHeight(); + } + + ui->lineEditDLHeightFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditDLHeightFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetDLAngle(QString angleFormula) +{ + if (angleFormula.isEmpty()) + { + angleFormula = QString("0"); + } + + const QString formula = qApp->TrVars()->FormulaToUser(angleFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployDLAngle(); + } + + ui->lineEditDLAngleFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditDLAngleFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetPLWidth(QString widthFormula) +{ + if (widthFormula.isEmpty()) + { + widthFormula = QString().setNum(UnitConvertor(1, Unit::Cm, *data->GetPatternUnit())); + } + + const QString formula = qApp->TrVars()->FormulaToUser(widthFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployPLWidth(); + } + + ui->lineEditPLWidthFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditPLWidthFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetPLHeight(QString heightFormula) +{ + if (heightFormula.isEmpty()) + { + heightFormula = QString().setNum(UnitConvertor(1, Unit::Cm, *data->GetPatternUnit())); + } + + const QString formula = qApp->TrVars()->FormulaToUser(heightFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployPLHeight(); + } + + ui->lineEditPLHeightFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditPLHeightFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSeamAllowance::SetPLAngle(QString angleFormula) +{ + if (angleFormula.isEmpty()) + { + angleFormula = QString("0"); + } + + const QString formula = qApp->TrVars()->FormulaToUser(angleFormula, qApp->Settings()->GetOsSeparator()); + // increase height if needed. + if (formula.length() > 80) + { + this->DeployPLAngle(); + } + + ui->lineEditPLAngleFormula->setPlainText(formula); + + MoveCursorToEnd(ui->lineEditPLAngleFormula); +} diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.h b/src/libs/vtools/dialogs/tools/dialogseamallowance.h index 0bcb47371..c3c2237d7 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.h +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.h @@ -94,14 +94,34 @@ private slots: void PathDialogClosed(int result); void TabChanged(int index); - void UpdateValues(); + void UpdateGrainlineValues(); + void UpdateDetailLabelValues(); + void UpdatePatternLabelValues(); + void SetAddMode(); void SetEditMode(); - void EnableGrainlineRotation(); - void EditFormula(); - void DeployRotation(); - void DeployLength(); - void ResetWarning(); + + void EditGrainlineFormula(); + void EditDLFormula(); + void EditPLFormula(); + + void DeployGrainlineRotation(); + void DeployGrainlineLength(); + + void DeployDLWidth(); + void DeployDLHeight(); + void DeployDLAngle(); + + void DeployPLWidth(); + void DeployPLHeight(); + void DeployPLAngle(); + + void ResetGrainlineWarning(); + void ResetLabelsWarning(); + + void EnabledGrainline(); + void EnabledDetailLabel(); + void EnabledPatternLabel(); void EvalWidth(); void EvalWidthBefore(); @@ -132,6 +152,10 @@ private: bool flagDPin; bool flagPPin; bool flagGFormulas; + bool flagDLAngle; + bool flagDLFormulas; + bool flagPLAngle; + bool flagPLFormulas; bool m_bAddMode; qreal m_mx; qreal m_my; @@ -149,6 +173,12 @@ private: VGrainlineData m_oldGrainline; int m_iRotBaseHeight; int m_iLenBaseHeight; + int m_DLWidthBaseHeight; + int m_DLHeightBaseHeight; + int m_DLAngleBaseHeight; + int m_PLWidthBaseHeight; + int m_PLHeightBaseHeight; + int m_PLAngleBaseHeight; int m_formulaBaseWidth; int m_formulaBaseWidthBefore; int m_formulaBaseWidthAfter; @@ -190,6 +220,7 @@ private: void InitSAIncludeType(); void InitInternalPathsTab(); void InitPatternPieceDataTab(); + void InitLabelsTab(); void InitGrainlineTab(); void InitPinsTab(); void InitAllPinComboboxes(); @@ -198,8 +229,17 @@ private: template QVector GetPieceInternals(const QListWidget *list) const; - void SetGrainlineAngle(const VGrainlineData &data); - void SetGrainlineLength(const VGrainlineData &data); + + void SetGrainlineAngle(QString angleFormula); + void SetGrainlineLength(QString lengthFormula); + + void SetDLWidth(QString widthFormula); + void SetDLHeight(QString heightFormula); + void SetDLAngle(QString angleFormula); + + void SetPLWidth(QString widthFormula); + void SetPLHeight(QString heightFormula); + void SetPLAngle(QString angleFormula); }; #endif // DIALOGSEAMALLOWANCE_H diff --git a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui index d9637e9e7..b59cf9ca6 100644 --- a/src/libs/vtools/dialogs/tools/dialogseamallowance.ui +++ b/src/libs/vtools/dialogs/tools/dialogseamallowance.ui @@ -6,7 +6,7 @@ 0 0 - 521 + 532 611 @@ -21,7 +21,7 @@ - 4 + 5 @@ -896,9 +896,9 @@ - + - Pattern piece data + Piece label data @@ -1027,87 +1027,17 @@ - - - - - Detail label visible - - - true - - - true - - - false - - - - QFormLayout::ExpandingFieldsGrow - - - - - Top left pin: - - - - - - - - - - Bottom right pin: - - - - - - - - - - - - - Pattern label visible - - - true - - - false - - - - QFormLayout::ExpandingFieldsGrow - - - - - Top left pin: - - - - - - - - - - Bottom right pin: - - - - - - - - - - + + + Qt::Vertical + + + + 20 + 40 + + + @@ -1126,6 +1056,1435 @@ + + + Labels + + + + + + Qt::Horizontal + + + + true + + + Detail label visible + + + true + + + true + + + false + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Width: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 1 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Height: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 1 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Center pin: + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Top left pin: + + + + + + + + + + Bottom right pin: + + + + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 0 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + true + + + Pattern label visible + + + true + + + false + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Width: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 1 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Height: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 1 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Center pin: + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Top left pin: + + + + + + + + + + Bottom right pin: + + + + + + + + + + + + Qt::Horizontal + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Formula wizard + + + ... + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + + 0 + 0 + + + + Value + + + _ + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 28 + + + + Calculation + + + true + + + 0 + + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + .. + + + + 16 + 16 + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Grainline @@ -1291,7 +2650,7 @@ true - + 1 @@ -1480,7 +2839,7 @@ true - + 90 @@ -1521,6 +2880,64 @@ + + + + QFormLayout::ExpandingFieldsGrow + + + + + Center pin: + + + + + + + + + + + + Qt::Horizontal + + + + + + + QFormLayout::ExpandingFieldsGrow + + + + + Top pin: + + + + + + + + + + Bottom pin: + + + + + + + + + + + + Qt::Horizontal + + + @@ -1542,26 +2959,6 @@ - - - - Top pin: - - - - - - - Bottom pin: - - - - - - - - - diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index f7576d5ab..4bce8e9e2 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -62,7 +62,7 @@ #include #include -// Current version of seam allowance tag nned for backward compatibility +// Current version of seam allowance tag need for backward compatibility const quint8 VToolSeamAllowance::pieceVersion = 2; const QString VToolSeamAllowance::TagCSA = QStringLiteral("csa"); @@ -78,6 +78,7 @@ const QString VToolSeamAllowance::AttrUnited = QStringLiteral("united"); const QString VToolSeamAllowance::AttrFont = QStringLiteral("fontSize"); const QString VToolSeamAllowance::AttrTopLeftPin = QStringLiteral("topLeftPin"); const QString VToolSeamAllowance::AttrBottomRightPin = QStringLiteral("bottomRightPin"); +const QString VToolSeamAllowance::AttrCenterPin = QStringLiteral("centerPin"); const QString VToolSeamAllowance::AttrTopPin = QStringLiteral("topPin"); const QString VToolSeamAllowance::AttrBottomPin = QStringLiteral("bottomPin"); @@ -257,6 +258,15 @@ void VToolSeamAllowance::AddPatternPieceData(VAbstractPattern *doc, QDomElement doc->SetAttribute(domData, AttrFont, data.GetFontSize()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, data.GetRotation()); + if (data.CenterPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrCenterPin, data.CenterPin()); + } + else + { + domData.removeAttribute(AttrCenterPin); + } + if (data.TopLeftPin() > NULL_ID) { doc->SetAttribute(domData, AttrTopLeftPin, data.TopLeftPin()); @@ -304,6 +314,15 @@ void VToolSeamAllowance::AddPatternInfo(VAbstractPattern *doc, QDomElement &domE doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); doc->SetAttribute(domData, VAbstractPattern::AttrRotation, geom.GetRotation()); + if (geom.CenterPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrCenterPin, geom.CenterPin()); + } + else + { + domData.removeAttribute(AttrCenterPin); + } + if (geom.TopLeftPin() > NULL_ID) { doc->SetAttribute(domData, AttrTopLeftPin, geom.TopLeftPin()); @@ -338,6 +357,15 @@ void VToolSeamAllowance::AddGrainline(VAbstractPattern *doc, QDomElement &domEle doc->SetAttribute(domData, VAbstractPattern::AttrRotation, glGeom.GetRotation()); doc->SetAttribute(domData, VAbstractPattern::AttrArrows, int(glGeom.GetArrowType())); + if (glGeom.CenterPin() > NULL_ID) + { + doc->SetAttribute(domData, AttrCenterPin, glGeom.CenterPin()); + } + else + { + domData.removeAttribute(AttrCenterPin); + } + if (glGeom.TopPin() > NULL_ID) { doc->SetAttribute(domData, AttrTopPin, glGeom.TopPin()); @@ -485,7 +513,14 @@ void VToolSeamAllowance::UpdateLabel() QPointF pos; qreal labelWidth = 0; qreal labelHeight = 0; - const VTextGraphicsItem::MoveType type = FindLabelGeometry(labelData, labelWidth, labelHeight, pos); + qreal labelAngle = 0; + const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelAngle, labelWidth, labelHeight, + pos); + if (type & VGrainlineItem::Error) + { + m_dataLabel->hide(); + return; + } m_dataLabel->SetMoveType(type); QFont fnt = qApp->font(); @@ -494,7 +529,8 @@ void VToolSeamAllowance::UpdateLabel() iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS); } m_dataLabel->SetFont(fnt); - m_dataLabel->SetSize(labelWidth, labelHeight); + m_dataLabel->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()), + ToPixel(labelHeight, *VDataTool::data.GetPatternUnit())); m_dataLabel->UpdateData(detail.GetName(), labelData); QRectF rectBB; @@ -503,14 +539,14 @@ void VToolSeamAllowance::UpdateLabel() rectBB.setHeight(m_dataLabel->boundingRect().height()); qreal dX; qreal dY; - if (m_dataLabel->IsContained(rectBB, labelData.GetRotation(), dX, dY) == false) + if (m_dataLabel->IsContained(rectBB, labelAngle, dX, dY) == false) { pos.setX(pos.x() + dX); pos.setY(pos.y() + dY); } m_dataLabel->setPos(pos); - m_dataLabel->setRotation(labelData.GetRotation()); + m_dataLabel->setRotation(-labelAngle); m_dataLabel->Update(); m_dataLabel->show(); } @@ -534,7 +570,13 @@ void VToolSeamAllowance::UpdatePatternInfo() QPointF pos; qreal labelWidth = 0; qreal labelHeight = 0; - const VTextGraphicsItem::MoveType type = FindLabelGeometry(geom, labelWidth, labelHeight, pos); + qreal labelAngle = 0; + const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(geom, labelAngle, labelWidth, labelHeight, pos); + if (type & VGrainlineItem::Error) + { + m_dataLabel->hide(); + return; + } m_patternInfo->SetMoveType(type); QFont fnt = qApp->font(); @@ -545,7 +587,8 @@ void VToolSeamAllowance::UpdatePatternInfo() } fnt.setPixelSize(iFS); m_patternInfo->SetFont(fnt); - m_patternInfo->SetSize(labelWidth, labelHeight); + m_patternInfo->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()), + ToPixel(labelHeight, *VDataTool::data.GetPatternUnit())); m_patternInfo->UpdateData(doc, getData()->size(), getData()->height()); QRectF rectBB; @@ -554,14 +597,14 @@ void VToolSeamAllowance::UpdatePatternInfo() rectBB.setHeight(m_patternInfo->boundingRect().height()); qreal dX; qreal dY; - if (m_patternInfo->IsContained(rectBB, geom.GetRotation(), dX, dY) == false) + if (m_patternInfo->IsContained(rectBB, labelAngle, dX, dY) == false) { pos.setX(pos.x() + dX); pos.setY(pos.y() + dY); } m_patternInfo->setPos(pos); - m_patternInfo->setRotation(geom.GetRotation()); + m_patternInfo->setRotation(labelAngle); m_patternInfo->Update(); m_patternInfo->GetTextLines() > 0 ? m_patternInfo->show() : m_patternInfo->hide(); } @@ -586,8 +629,8 @@ void VToolSeamAllowance::UpdateGrainline() qreal dRotation = 0; qreal dLength = 0; - const VGrainlineItem::MoveType type = FindGrainlineGeometry(geom, dLength, dRotation, pos); - if (type == VGrainlineItem::Error) + const VGrainlineItem::MoveTypes type = FindGrainlineGeometry(geom, dLength, dRotation, pos); + if (type & VGrainlineItem::Error) { m_grainLine->hide(); return; @@ -613,10 +656,6 @@ void VToolSeamAllowance::SaveMoveDetail(const QPointF& ptPos) VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; newDet.GetPatternPieceData().SetPos(ptPos); - newDet.GetPatternPieceData().SetLabelWidth(m_dataLabel->boundingRect().width()); - newDet.GetPatternPieceData().SetLabelHeight(m_dataLabel->boundingRect().height()); - newDet.GetPatternPieceData().SetFontSize(m_dataLabel->GetFontSize()); - newDet.GetPatternPieceData().SetRotation(m_dataLabel->rotation()); SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, id); moveCommand->setText(tr("move pattern piece label")); @@ -632,10 +671,13 @@ void VToolSeamAllowance::SaveResizeDetail(qreal dLabelW, int iFontSize) { VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; - newDet.GetPatternPieceData().SetLabelWidth(dLabelW); - newDet.GetPatternPieceData().SetLabelHeight(m_dataLabel->boundingRect().height()); + + dLabelW = FromPixel(dLabelW, *VDataTool::data.GetPatternUnit()); + newDet.GetPatternPieceData().SetLabelWidth(QString().setNum(dLabelW)); + const qreal height = FromPixel(m_dataLabel->boundingRect().height(), *VDataTool::data.GetPatternUnit()); + newDet.GetPatternPieceData().SetLabelHeight(QString().setNum(height)); newDet.GetPatternPieceData().SetFontSize(iFontSize); - newDet.GetPatternPieceData().SetRotation(m_dataLabel->rotation()); + SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id); resizeCommand->setText(tr("resize pattern piece label")); connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); @@ -651,10 +693,12 @@ void VToolSeamAllowance::SaveRotationDetail(qreal dRot) VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; newDet.GetPatternPieceData().SetPos(m_dataLabel->pos()); - newDet.GetPatternPieceData().SetLabelWidth(m_dataLabel->boundingRect().width()); - newDet.GetPatternPieceData().SetLabelHeight(m_dataLabel->boundingRect().height()); newDet.GetPatternPieceData().SetFontSize(m_dataLabel->GetFontSize()); - newDet.GetPatternPieceData().SetRotation(dRot); + + // Tranform angle to anticlockwise + QLineF line(0, 0, 100, 0); + line.setAngle(-dRot); + newDet.GetPatternPieceData().SetRotation(QString().setNum(line.angle())); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); rotateCommand->setText(tr("rotate pattern piece label")); @@ -672,10 +716,6 @@ void VToolSeamAllowance::SaveMovePattern(const QPointF &ptPos) VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; newDet.GetPatternInfo().SetPos(ptPos); - newDet.GetPatternInfo().SetLabelWidth(m_patternInfo->boundingRect().width()); - newDet.GetPatternInfo().SetLabelHeight(m_patternInfo->boundingRect().height()); - newDet.GetPatternInfo().SetFontSize(m_patternInfo->GetFontSize()); - newDet.GetPatternInfo().SetRotation(m_patternInfo->rotation()); SavePieceOptions* moveCommand = new SavePieceOptions(oldDet, newDet, doc, id); moveCommand->setText(tr("move pattern info label")); @@ -691,10 +731,13 @@ void VToolSeamAllowance::SaveResizePattern(qreal dLabelW, int iFontSize) { VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; - newDet.GetPatternInfo().SetLabelWidth(dLabelW); - newDet.GetPatternInfo().SetLabelHeight(m_patternInfo->boundingRect().height()); + + dLabelW = FromPixel(dLabelW, *VDataTool::data.GetPatternUnit()); + newDet.GetPatternInfo().SetLabelWidth(QString().setNum(dLabelW)); + qreal height = FromPixel(m_patternInfo->boundingRect().height(), *VDataTool::data.GetPatternUnit()); + newDet.GetPatternInfo().SetLabelHeight(QString().setNum(height)); newDet.GetPatternInfo().SetFontSize(iFontSize); - newDet.GetPatternInfo().SetRotation(m_patternInfo->rotation()); + SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id); resizeCommand->setText(tr("resize pattern info label")); connect(resizeCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); @@ -706,11 +749,14 @@ void VToolSeamAllowance::SaveRotationPattern(qreal dRot) { VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; + newDet.GetPatternInfo().SetPos(m_patternInfo->pos()); - newDet.GetPatternInfo().SetLabelWidth(m_patternInfo->boundingRect().width()); - newDet.GetPatternInfo().SetLabelHeight(m_patternInfo->boundingRect().height()); newDet.GetPatternInfo().SetFontSize(m_patternInfo->GetFontSize()); - newDet.GetPatternInfo().SetRotation(dRot); + + // Tranform angle to anticlockwise + QLineF line(0, 0, 100, 0); + line.setAngle(-dRot); + newDet.GetPatternInfo().SetRotation(QString().setNum(line.angle())); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); rotateCommand->setText(tr("rotate pattern info label")); @@ -740,6 +786,7 @@ void VToolSeamAllowance::SaveResizeGrainline(qreal dLength) VPiece newDet = oldDet; dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit()); + newDet.GetGrainlineGeometry().SetPos(m_grainLine->pos()); newDet.GetGrainlineGeometry().SetLength(QString().setNum(dLength)); SavePieceOptions* resizeCommand = new SavePieceOptions(oldDet, newDet, doc, id); resizeCommand->setText(tr("resize grainline")); @@ -753,8 +800,7 @@ void VToolSeamAllowance::SaveRotateGrainline(qreal dRot, const QPointF& ptPos) VPiece oldDet = VAbstractTool::data.GetPiece(id); VPiece newDet = oldDet; - dRot = qRadiansToDegrees(dRot); - newDet.GetGrainlineGeometry().SetRotation(QString().setNum(dRot)); + newDet.GetGrainlineGeometry().SetRotation(QString().setNum(qRadiansToDegrees(dRot))); newDet.GetGrainlineGeometry().SetPos(ptPos); SavePieceOptions* rotateCommand = new SavePieceOptions(oldDet, newDet, doc, id); rotateCommand->setText(tr("rotate grainline")); @@ -1157,9 +1203,27 @@ void VToolSeamAllowance::SaveDialogChange() } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &labelWidth, - qreal &labelHeight, QPointF &pos) +VPieceItem::MoveTypes VToolSeamAllowance::FindLabelGeometry(const VPatternLabelData& labelData, qreal &rotationAngle, + qreal &labelWidth, qreal &labelHeight, QPointF &pos) { + + VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications; + try + { + if (not qmu::QmuTokenParser::IsSingle(labelData.GetRotation())) + { + restrictions &= ~ VPieceItem::IsRotatable; + } + + Calculator cal1; + rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), labelData.GetRotation()); + } + catch(qmu::QmuParserError &e) + { + Q_UNUSED(e); + return VPieceItem::Error; + } + const quint32 topLeftPin = labelData.TopLeftPin(); const quint32 bottomRightPin = labelData.BottomRightPin(); @@ -1171,12 +1235,15 @@ VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelDa const auto bottomRightPinPoint = VAbstractTool::data.GeometricObject(bottomRightPin); const QRectF labelRect = QRectF(*topLeftPinPoint, *bottomRightPinPoint); - labelWidth = qAbs(labelRect.width()); - labelHeight = qAbs(labelRect.height()); + labelWidth = FromPixel(qAbs(labelRect.width()), *VDataTool::data.GetPatternUnit()); + labelHeight = FromPixel(qAbs(labelRect.height()), *VDataTool::data.GetPatternUnit()); pos = labelRect.topLeft(); - return VTextGraphicsItem::OnlyRotatable; + restrictions &= ~ VPieceItem::IsMovable; + restrictions &= ~ VPieceItem::IsResizable; + + return restrictions; } catch(const VExceptionBadId &) { @@ -1184,14 +1251,57 @@ VPieceItem::MoveType VToolSeamAllowance::FindLabelGeometry(const VPatternLabelDa } } - labelWidth = labelData.GetLabelWidth(); - labelHeight = labelData.GetLabelHeight(); - pos = labelData.GetPos(); - return VTextGraphicsItem::AllModifications; + try + { + const bool widthIsSingle = qmu::QmuTokenParser::IsSingle(labelData.GetLabelWidth()); + + Calculator cal1; + labelWidth = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), labelData.GetLabelWidth()); + + const bool heightIsSingle = qmu::QmuTokenParser::IsSingle(labelData.GetLabelHeight()); + + Calculator cal2; + labelHeight = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), labelData.GetLabelHeight()); + + if (not widthIsSingle || not heightIsSingle) + { + restrictions &= ~ VPieceItem::IsResizable; + } + } + catch(qmu::QmuParserError &e) + { + Q_UNUSED(e); + return VPieceItem::Error; + } + + const quint32 centerPin = labelData.CenterPin(); + if (centerPin != NULL_ID) + { + try + { + const auto centerPinPoint = VAbstractTool::data.GeometricObject(centerPin); + + const qreal lWidth = ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()); + const qreal lHeight = ToPixel(labelHeight, *VDataTool::data.GetPatternUnit()); + + pos = *centerPinPoint - QRectF(0, 0, lWidth, lHeight).center(); + restrictions &= ~ VPieceItem::IsMovable; + } + catch(const VExceptionBadId &) + { + pos = labelData.GetPos(); + } + } + else + { + pos = labelData.GetPos(); + } + + return restrictions; } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length, +VPieceItem::MoveTypes VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineData& geom, qreal &length, qreal &rotationAngle, QPointF &pos) { const quint32 topPin = geom.TopPin(); @@ -1223,16 +1333,21 @@ VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineD } } - bool isResizable = false; - bool isRotatable = false; + VPieceItem::MoveTypes restrictions = VPieceItem::AllModifications; try { - isRotatable = qmu::QmuTokenParser::IsSingle(geom.GetRotation()); + if (not qmu::QmuTokenParser::IsSingle(geom.GetRotation())) + { + restrictions &= ~ VPieceItem::IsRotatable; + } Calculator cal1; rotationAngle = cal1.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetRotation()); - isResizable = qmu::QmuTokenParser::IsSingle(geom.GetLength()); + if (not qmu::QmuTokenParser::IsSingle(geom.GetLength())) + { + restrictions &= ~ VPieceItem::IsResizable; + } Calculator cal2; length = cal2.EvalFormula(VAbstractTool::data.PlainVariables(), geom.GetLength()); @@ -1243,25 +1358,35 @@ VPieceItem::MoveType VToolSeamAllowance::FindGrainlineGeometry(const VGrainlineD return VPieceItem::Error; } - pos = geom.GetPos(); - - if (isResizable && isRotatable) + const quint32 centerPin = geom.CenterPin(); + if (centerPin != NULL_ID) { - return VPieceItem::AllModifications; + try + { + const auto centerPinPoint = VAbstractTool::data.GeometricObject(centerPin); + + const qreal cLength = ToPixel(length, *VDataTool::data.GetPatternUnit()); + QLineF grainline(centerPinPoint->x(), centerPinPoint->y(), + centerPinPoint->x() + cLength / 2.0, centerPinPoint->y()); + + grainline.setAngle(rotationAngle); + grainline = QLineF(grainline.p2(), grainline.p1()); + grainline.setLength(cLength); + + pos = grainline.p2(); + restrictions &= ~ VPieceItem::IsMovable; + } + catch(const VExceptionBadId &) + { + pos = geom.GetPos(); + } } else { - if (isResizable) - { - return VPieceItem::OnlyResizable; - } - - if (isRotatable) - { - return VPieceItem::OnlyRotatable; - } + pos = geom.GetPos(); } - return VPieceItem::OnlyMovable; + + return restrictions; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index f402721dc..08d70bf99 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -68,6 +68,7 @@ public: static const QString AttrFont; static const QString AttrTopLeftPin; static const QString AttrBottomRightPin; + static const QString AttrCenterPin; static const QString AttrTopPin; static const QString AttrBottomPin; @@ -151,10 +152,10 @@ private: void RefreshGeometry(); void SaveDialogChange(); - VPieceItem::MoveType FindLabelGeometry(const VPatternLabelData &labelData, qreal &labelWidth, qreal &labelHeight, - QPointF &pos); - VPieceItem::MoveType FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle, - QPointF &pos); + VPieceItem::MoveTypes FindLabelGeometry(const VPatternLabelData &labelData, qreal &rotationAngle, qreal &labelWidth, + qreal &labelHeight, QPointF &pos); + VPieceItem::MoveTypes FindGrainlineGeometry(const VGrainlineData &geom, qreal &length, qreal &rotationAngle, + QPointF &pos); void InitNodes(const VPiece &detail, VMainGraphicsScene *scene); void InitCSAPaths(const VPiece &detail); diff --git a/src/libs/vwidgets/vgrainlineitem.cpp b/src/libs/vwidgets/vgrainlineitem.cpp index 124093cd3..c272a7445 100644 --- a/src/libs/vwidgets/vgrainlineitem.cpp +++ b/src/libs/vwidgets/vgrainlineitem.cpp @@ -145,6 +145,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption if (m_eMode != mRotate) { pP->setBrush(clr); + UpdatePolyResize(); pP->drawPolygon(m_polyResize); } @@ -292,51 +293,66 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) m_dAngle = GetAngle(mapToParent(pME->pos())); m_ptRotCenter = m_ptCenter; - if (m_moveType == OnlyRotatable) + if ((m_moveType & AllModifications ) == AllModifications) { - if (m_eMode != mRotate) + AllUserModifications(pME->pos()); + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsRotatable) + { + if (m_moveType & IsResizable) + { + AllUserModifications(pME->pos()); + } + else if (m_moveType & IsMovable) + { + UserRotateAndMove(); + } + else + { + m_eMode = mRotate; + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsResizable) + { + if (m_moveType & IsRotatable) + { + AllUserModifications(pME->pos()); + } + else if (m_moveType & IsMovable) + { + UserMoveAndResize(pME->pos()); + } + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsMovable) + { + if (m_moveType & IsRotatable) + { + UserRotateAndMove(); + } + else if (m_moveType & IsResizable) + { + UserMoveAndResize(pME->pos()); + } + else { m_eMode = mMove; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } - else - { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } setZValue(ACTIVE_Z); Update(); } - else if (m_moveType == OnlyMovable) + else { - m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - - setZValue(ACTIVE_Z); - Update(); - } - else // All modifications - { - if (m_eMode != mRotate) - { - if (m_polyResize.containsPoint(pME->pos(), Qt::OddEvenFill) == true) - { - m_eMode = mResize; - SetOverrideCursor(Qt::SizeFDiagCursor); - } - else - { - m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } - } - else - { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } - - setZValue(ACTIVE_Z); - Update(); + pME->ignore(); + return; } } } @@ -351,7 +367,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) QPointF ptDiff = pME->scenePos() - m_ptStartMove; qreal dX; qreal dY; - if (m_eMode == mMove) + if (m_eMode == mMove && m_moveType & IsMovable) { QPointF pt = m_ptStartPos + ptDiff; if (IsContained(pt, m_dRotation, dX, dY) == false) @@ -362,24 +378,57 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) setPos(pt); Update(); } - else if (m_eMode == mResize) + else if (m_eMode == mResize && m_moveType & IsResizable) { qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); qreal dAng = qAtan2(-ptDiff.y(), ptDiff.x()); - dLen = dLen*qCos(dAng - m_dRotation); + dLen = -dLen*qCos(dAng - m_dRotation); qreal dPrevLen = m_dLength; // try with new length + if (not (m_moveType & IsMovable)) + { + dLen *= 2; + } m_dLength = m_dStartLength + dLen; + + QPointF pos; + + if (m_moveType & IsMovable) + { + QLineF grainline(this->pos().x(), this->pos().y(), + this->pos().x() + dPrevLen, this->pos().y()); + grainline.setAngle(qRadiansToDegrees(m_dRotation)); + grainline = QLineF(grainline.p2(), grainline.p1()); + grainline.setLength(m_dLength); + pos = grainline.p2(); + } + else + { + QLineF grainline(m_ptCenter.x(), m_ptCenter.y(), + m_ptCenter.x() + m_dLength / 2.0, m_ptCenter.y()); + + grainline.setAngle(qRadiansToDegrees(m_dRotation)); + grainline = QLineF(grainline.p2(), grainline.p1()); + grainline.setLength(m_dLength); + + pos = grainline.p2(); + } + qreal dX; qreal dY; - if (IsContained(m_ptStartPos, m_dRotation, dX, dY) == false) + if (IsContained(pos, m_dRotation, dX, dY) == false) { m_dLength = dPrevLen; } + else + { + setPos(pos); + } + UpdateRectangle(); Update(); } - else if (m_eMode == mRotate) + else if (m_eMode == mRotate && m_moveType & IsRotatable) { // prevent strange angle changes due to singularities qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); @@ -433,7 +482,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (bShort == true) { - if (m_bReleased == true && m_moveType != OnlyResizable && m_moveType != OnlyMovable) + if (m_bReleased == true && m_moveType & IsRotatable) { m_eMode = mRotate; Update(); @@ -441,11 +490,11 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } else { - if (m_eMode == mMove) + if (m_eMode == mMove && m_moveType & IsMovable) { emit SignalMoved(pos()); } - else + else if (m_moveType & IsResizable) { emit SignalResized(m_dLength); } @@ -458,7 +507,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { m_eMode = mMove; } - else + else if (m_moveType & IsRotatable) { emit SignalRotated(m_dRotation, m_ptStart); } @@ -498,50 +547,26 @@ void VGrainlineItem::Update() */ void VGrainlineItem::UpdateRectangle() { - m_polyBound.clear(); QPointF pt1(0, 0); - QPointF pt2; - - pt2.setX(pt1.x() + m_dLength * cos(m_dRotation)); - pt2.setY(pt1.y() - m_dLength * sin(m_dRotation)); + QPointF pt2(pt1.x() + m_dLength * cos(m_dRotation), pt1.y() - m_dLength * sin(m_dRotation)); m_ptStart = mapToParent(pt1); m_ptFinish = mapToParent(pt2); m_ptCenter = (m_ptStart + m_ptFinish)/2; - QPointF ptA; - ptA.setX(pt1.x() + RECT_WIDTH*cos(m_dRotation + M_PI/2)); - ptA.setY(pt1.y() - RECT_WIDTH*sin(m_dRotation + M_PI/2)); - m_polyBound << ptA; - ptA.setX(pt1.x() + RECT_WIDTH*cos(m_dRotation - M_PI/2)); - ptA.setY(pt1.y() - RECT_WIDTH*sin(m_dRotation - M_PI/2)); - m_polyBound << ptA; - ptA.setX(pt2.x() + RECT_WIDTH*cos(m_dRotation - M_PI/2)); - ptA.setY(pt2.y() - RECT_WIDTH*sin(m_dRotation - M_PI/2)); - m_polyBound << ptA; - ptA.setX(pt2.x() + RECT_WIDTH*cos(m_dRotation + M_PI/2)); - ptA.setY(pt2.y() - RECT_WIDTH*sin(m_dRotation + M_PI/2)); - m_polyBound << ptA; + m_polyBound.clear(); + m_polyBound << QPointF(pt1.x() + RECT_WIDTH*cos(m_dRotation + M_PI/2), + pt1.y() - RECT_WIDTH*sin(m_dRotation + M_PI/2)); + m_polyBound << QPointF(pt1.x() + RECT_WIDTH*cos(m_dRotation - M_PI/2), + pt1.y() - RECT_WIDTH*sin(m_dRotation - M_PI/2)); + m_polyBound << QPointF(pt2.x() + RECT_WIDTH*cos(m_dRotation - M_PI/2), + pt2.y() - RECT_WIDTH*sin(m_dRotation - M_PI/2)); + m_polyBound << QPointF(pt2.x() + RECT_WIDTH*cos(m_dRotation + M_PI/2), + pt2.y() - RECT_WIDTH*sin(m_dRotation + M_PI/2)); m_rectBoundingBox = m_polyBound.boundingRect(); setTransformOriginPoint(m_rectBoundingBox.center()); - m_polyResize.clear(); - ptA = m_polyBound.at(2); - m_polyResize << ptA; - double dSize = m_dScale * RESIZE_RECT_SIZE; - - ptA.setX(ptA.x() + dSize*cos(m_dRotation + M_PI/2)); - ptA.setY(ptA.y() - dSize*sin(m_dRotation + M_PI/2)); - m_polyResize << ptA; - - ptA.setX(ptA.x() - dSize*cos(m_dRotation)); - ptA.setY(ptA.y() + dSize*sin(m_dRotation)); - m_polyResize << ptA; - - ptA.setX(ptA.x() + dSize*cos(m_dRotation - M_PI/2)); - ptA.setY(ptA.y() - dSize*sin(m_dRotation - M_PI/2)); - m_polyResize << ptA; - + UpdatePolyResize(); prepareGeometryChange(); } @@ -628,19 +653,6 @@ QLineF VGrainlineItem::MainLine() const //--------------------------------------------------------------------------------------------------------------------- QPolygonF VGrainlineItem::FirstArrow(qreal dArrLen) const -{ - const QPointF pt1 = MainLine().p1(); - QPolygonF poly; - poly << pt1; - poly << QPointF(pt1.x() + dArrLen*cos(m_dRotation + ARROW_ANGLE), - pt1.y() - dArrLen*sin(m_dRotation + ARROW_ANGLE)); - poly << QPointF(pt1.x() + dArrLen*cos(m_dRotation - ARROW_ANGLE), - pt1.y() - dArrLen*sin(m_dRotation - ARROW_ANGLE)); - return poly; -} - -//--------------------------------------------------------------------------------------------------------------------- -QPolygonF VGrainlineItem::SecondArrow(qreal dArrLen) const { const QPointF pt2 = MainLine().p2(); QPolygonF poly; @@ -652,6 +664,19 @@ QPolygonF VGrainlineItem::SecondArrow(qreal dArrLen) const return poly; } +//--------------------------------------------------------------------------------------------------------------------- +QPolygonF VGrainlineItem::SecondArrow(qreal dArrLen) const +{ + const QPointF pt1 = MainLine().p1(); + QPolygonF poly; + poly << pt1; + poly << QPointF(pt1.x() + dArrLen*cos(m_dRotation + ARROW_ANGLE), + pt1.y() - dArrLen*sin(m_dRotation + ARROW_ANGLE)); + poly << QPointF(pt1.x() + dArrLen*cos(m_dRotation - ARROW_ANGLE), + pt1.y() - dArrLen*sin(m_dRotation - ARROW_ANGLE)); + return poly; +} + //--------------------------------------------------------------------------------------------------------------------- QPainterPath VGrainlineItem::MainShape() const { @@ -687,3 +712,62 @@ QPainterPath VGrainlineItem::MainShape() const } return path; } + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::AllUserModifications(const QPointF &pos) +{ + if (m_eMode != mRotate) + { + UserMoveAndResize(pos); + } + else + { + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::UserRotateAndMove() +{ + if (m_eMode != mRotate) + { + m_eMode = mMove; + } + SetOverrideCursor(cursorArrowCloseHand, 1, 1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::UserMoveAndResize(const QPointF &pos) +{ + if (m_polyResize.containsPoint(pos, Qt::OddEvenFill) == true) + { + m_eMode = mResize; + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + m_eMode = mMove; // block later if need + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::UpdatePolyResize() +{ + m_polyResize.clear(); + QPointF ptA = m_polyBound.at(1); + m_polyResize << ptA; + const double dSize = m_dScale * RESIZE_RECT_SIZE; + + ptA.setX(ptA.x() - dSize*cos(m_dRotation - M_PI/2)); + ptA.setY(ptA.y() + dSize*sin(m_dRotation - M_PI/2)); + m_polyResize << ptA; + + ptA.setX(ptA.x() + dSize*cos(m_dRotation)); + ptA.setY(ptA.y() - dSize*sin(m_dRotation)); + m_polyResize << ptA; + + ptA.setX(ptA.x() - dSize*cos(m_dRotation + M_PI/2)); + ptA.setY(ptA.y() + dSize*sin(m_dRotation + M_PI/2)); + m_polyResize << ptA; +} diff --git a/src/libs/vwidgets/vgrainlineitem.h b/src/libs/vwidgets/vgrainlineitem.h index e0fd31fe2..27ddbab53 100644 --- a/src/libs/vwidgets/vgrainlineitem.h +++ b/src/libs/vwidgets/vgrainlineitem.h @@ -89,6 +89,12 @@ private: QPolygonF SecondArrow(qreal dArrLen) const; QPainterPath MainShape() const; + + void AllUserModifications(const QPointF &pos); + void UserRotateAndMove(); + void UserMoveAndResize(const QPointF &pos); + + void UpdatePolyResize(); }; #endif // VGRAINLINEITEM_H diff --git a/src/libs/vwidgets/vpieceitem.cpp b/src/libs/vwidgets/vpieceitem.cpp index 5117b8c8c..375f5be9c 100644 --- a/src/libs/vwidgets/vpieceitem.cpp +++ b/src/libs/vwidgets/vpieceitem.cpp @@ -108,13 +108,13 @@ double VPieceItem::GetAngle(const QPointF &pt) const } //--------------------------------------------------------------------------------------------------------------------- -VPieceItem::MoveType VPieceItem::GetMoveType() const +VPieceItem::MoveTypes VPieceItem::GetMoveType() const { return m_moveType; } //--------------------------------------------------------------------------------------------------------------------- -void VPieceItem::SetMoveType(const MoveType &moveType) +void VPieceItem::SetMoveType(const VPieceItem::MoveTypes &moveType) { m_moveType = moveType; setAcceptHoverEvents(m_moveType != NotMovable); diff --git a/src/libs/vwidgets/vpieceitem.h b/src/libs/vwidgets/vpieceitem.h index b97a95fb3..103158d6e 100644 --- a/src/libs/vwidgets/vpieceitem.h +++ b/src/libs/vwidgets/vpieceitem.h @@ -36,7 +36,16 @@ class VPieceItem : public QGraphicsObject { Q_OBJECT public: - enum MoveType {AllModifications, OnlyResizable, OnlyRotatable, OnlyMovable, NotMovable, Error}; + enum MoveType + { + NotMovable = 0x0, + IsRotatable = 0x1, // 0001 + IsResizable = 0x2, // 0010 + IsMovable = 0x4, // 0100 + AllModifications = IsRotatable | IsResizable | IsMovable, + Error = 0x8 // 1000 + }; + Q_DECLARE_FLAGS(MoveTypes, MoveType) explicit VPieceItem(QGraphicsItem* pParent = nullptr); virtual ~VPieceItem(); @@ -48,8 +57,8 @@ public: void Reset(); bool IsIdle() const; - MoveType GetMoveType() const; - void SetMoveType(const MoveType &moveType); + VPieceItem::MoveTypes GetMoveType() const; + void SetMoveType(const VPieceItem::MoveTypes &moveType); signals: void SignalMoved(const QPointF &ptPos); @@ -62,11 +71,11 @@ protected: mResize, mRotate }; - QRectF m_rectBoundingBox; - Mode m_eMode; - bool m_bReleased; - QPointF m_ptRotCenter; - MoveType m_moveType; + QRectF m_rectBoundingBox; + Mode m_eMode; + bool m_bReleased; + QPointF m_ptRotCenter; + VPieceItem::MoveTypes m_moveType; qreal m_inactiveZ; @@ -76,4 +85,6 @@ private: Q_DISABLE_COPY(VPieceItem) }; +Q_DECLARE_OPERATORS_FOR_FLAGS(VPieceItem::MoveTypes) + #endif // VPIECEITEM_H diff --git a/src/libs/vwidgets/vtextgraphicsitem.cpp b/src/libs/vwidgets/vtextgraphicsitem.cpp index 150562ddf..014282088 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.cpp +++ b/src/libs/vwidgets/vtextgraphicsitem.cpp @@ -403,6 +403,12 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) { if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick) { + if (m_moveType == NotMovable) + { + pME->ignore(); + return; + } + // record the parameters of the mouse press. Specially record the position // of the press as the origin for the following operations m_ptStartPos = pos(); @@ -414,45 +420,66 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) // in rotation mode, do not do any changes here, because user might want to // rotate the label more. - if (m_moveType == OnlyRotatable) + if ((m_moveType & AllModifications ) == AllModifications) { - if (m_eMode != mRotate) + AllUserModifications(pME->pos()); + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsRotatable) + { + if (m_moveType & IsResizable) + { + AllUserModifications(pME->pos()); + } + else if (m_moveType & IsMovable) + { + UserRotateAndMove(); + } + else { m_eMode = mRotate; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsResizable) + { + if (m_moveType & IsRotatable) + { + AllUserModifications(pME->pos()); + } + else if (m_moveType & IsMovable) + { + UserMoveAndResize(pME->pos()); + } + setZValue(ACTIVE_Z); + Update(); + } + else if (m_moveType & IsMovable) + { + if (m_moveType & IsRotatable) + { + UserRotateAndMove(); + } + else if (m_moveType & IsResizable) + { + UserMoveAndResize(pME->pos()); + } else { + m_eMode = mMove; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } setZValue(ACTIVE_Z); Update(); } - else // All modifications + else { - 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; - SetOverrideCursor(Qt::SizeFDiagCursor); - } - else - { - // if user pressed the button outside the resize square, switch to move mode - m_eMode = mMove; - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } - } - else - { - SetOverrideCursor(cursorArrowCloseHand, 1, 1); - } - // raise the label and redraw it - setZValue(ACTIVE_Z); - UpdateBox(); + pME->ignore(); + return; } } } @@ -468,7 +495,7 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) qreal dY; QRectF rectBB; const QPointF ptDiff = pME->scenePos() - m_ptStart; - if (m_eMode == mMove) + if (m_eMode == mMove && m_moveType & IsMovable) { // in move mode move the label along the mouse move from the origin QPointF pt = m_ptStartPos + ptDiff; @@ -484,10 +511,21 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) setPos(pt); UpdateBox(); } - else if (m_eMode == mResize) + else if (m_eMode == mResize && m_moveType & IsResizable) { // in resize mode, resize the label along the mouse move from the origin - QPointF pt = m_ptStartPos; + QPointF pt; + + if (m_moveType & IsMovable) + { + pt = m_ptStartPos; + } + else + { + pt = m_ptRotCenter - QRectF(0, 0, m_szStart.width() + ptDiff.x(), + m_szStart.height() + ptDiff.y()).center(); + } + rectBB.setTopLeft(pt); QSizeF sz(m_szStart.width() + ptDiff.x(), m_szStart.height() + ptDiff.y()); rectBB.setSize(sz); @@ -496,12 +534,19 @@ void VTextGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { sz = QSizeF(sz.width()+dX, sz.height()+dY); } + else + { + if (not (m_moveType & IsMovable)) + { + setPos(pt); + } + } SetSize(sz.width(), sz.height()); Update(); emit SignalShrink(); } - else if (m_eMode == mRotate) + else if (m_eMode == mRotate && m_moveType & IsRotatable) { // 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 @@ -551,18 +596,18 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) // but if user did some operation (move/resize), emit the proper signal and update the label if (bShort == true) { - if (m_bReleased == true) + if (m_bReleased == true && m_moveType & IsRotatable) { m_eMode = mRotate; UpdateBox(); } } - else if (m_eMode == mMove) + else if (m_eMode == mMove && m_moveType & IsMovable) { emit SignalMoved(pos()); UpdateBox(); } - else + else if (m_moveType & IsResizable) { emit SignalResized(m_rectBoundingBox.width(), m_tm.GetFont().pixelSize()); Update(); @@ -570,20 +615,16 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } else { // in rotate mode, if user did just press/release, switch to move mode - if (bShort == true) + if (bShort == true && (m_moveType & IsMovable || m_moveType & IsResizable)) { - if (m_moveType != OnlyRotatable) - { - m_eMode = mMove; - } - UpdateBox(); + m_eMode = mMove; } - else + else if (m_moveType & IsRotatable) { // if user rotated the item, emit proper signal and update the label emit SignalRotated(rotation()); - UpdateBox(); } + UpdateBox(); } m_bReleased = true; } @@ -596,7 +637,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) */ void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) { - if (m_eMode == mMove || m_eMode == mResize) + if (m_eMode == mResize && m_moveType & IsResizable) { if (m_rectResize.contains(pHE->pos()) == true) { @@ -649,3 +690,41 @@ void VTextGraphicsItem::CorrectLabel() m_tm.FitFontSize(m_rectBoundingBox.width(), m_rectBoundingBox.height()); UpdateBox(); } + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::AllUserModifications(const QPointF &pos) +{ + if (m_eMode != mRotate) + { + UserMoveAndResize(pos); + } + else + { + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::UserRotateAndMove() +{ + if (m_eMode != mRotate) + { + m_eMode = mMove; + } + SetOverrideCursor(cursorArrowCloseHand, 1, 1); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTextGraphicsItem::UserMoveAndResize(const QPointF &pos) +{ + if (m_rectResize.contains(pos) == true) + { + m_eMode = mResize; + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + m_eMode = mMove; // block later if need + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } +} diff --git a/src/libs/vwidgets/vtextgraphicsitem.h b/src/libs/vwidgets/vtextgraphicsitem.h index 7c5d99bad..c453d520f 100644 --- a/src/libs/vwidgets/vtextgraphicsitem.h +++ b/src/libs/vwidgets/vtextgraphicsitem.h @@ -92,6 +92,10 @@ private: double m_dAngle; QRectF m_rectResize; VTextManager m_tm; + + void AllUserModifications(const QPointF &pos); + void UserRotateAndMove(); + void UserMoveAndResize(const QPointF &pos); }; #endif // VTEXTGRAPHICSITEM_H