From 287f8fc41efa8929802700bec718e3265b0da4a1 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 6 Sep 2016 23:50:46 +0200 Subject: [PATCH 01/19] Added VGrainlineGeometry class to hold grainline parameters and methods to save, load and edit it --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 20 + src/libs/ifc/schema.qrc | 1 + src/libs/ifc/schema/pattern/v0.3.5.xsd | 581 ++++++++++++++++++ src/libs/ifc/xml/vabstractpattern.cpp | 1 + src/libs/ifc/xml/vabstractpattern.h | 1 + src/libs/ifc/xml/vpatternconverter.cpp | 16 +- src/libs/ifc/xml/vpatternconverter.h | 5 +- src/libs/vpatterndb/vdetail.cpp | 23 + src/libs/vpatterndb/vdetail.h | 3 + src/libs/vpatterndb/vdetail_p.h | 8 +- src/libs/vpatterndb/vgrainlinegeometry.cpp | 101 +++ src/libs/vpatterndb/vgrainlinegeometry.h | 76 +++ src/libs/vpatterndb/vpatterndb.pri | 6 +- src/libs/vpatterndb/vpatterndb.pro | 2 + .../vtools/dialogs/tools/dialogdetail.cpp | 22 +- src/libs/vtools/dialogs/tools/dialogdetail.h | 3 + src/libs/vtools/dialogs/tools/dialogdetail.ui | 66 +- src/libs/vtools/tools/vtooldetail.cpp | 24 + .../vtools/undocommands/savedetailoptions.cpp | 18 + .../vtools/undocommands/savedetailoptions.h | 1 + 20 files changed, 961 insertions(+), 17 deletions(-) create mode 100644 src/libs/ifc/schema/pattern/v0.3.5.xsd create mode 100644 src/libs/vpatterndb/vgrainlinegeometry.cpp create mode 100644 src/libs/vpatterndb/vgrainlinegeometry.h diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index faf18ed06..7a3d84f3f 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -51,6 +51,7 @@ #include "../vpatterndb/calculator.h" #include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatterninfogeometry.h" +#include "../vpatterndb/vgrainlinegeometry.h" #include #include @@ -716,6 +717,25 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document qreal dRot = GetParametrDouble(element, VToolDetail::AttrRotation, "0"); detail.GetPatternInfo().SetRotation(dRot); } + else if (element.tagName() == TagGrainline) + { + detail.GetGrainlineGeometry().SetVisible(GetParametrBool(element, AttrVisible, falseStr)); + QPointF ptPos; + ptPos.setX(GetParametrDouble(element, AttrMx, "0")); + ptPos.setY(GetParametrDouble(element, AttrMy, "0")); + detail.GetGrainlineGeometry().SetPos(ptPos); + qreal dLength = GetParametrDouble(element, AttrLength, "0"); + detail.GetGrainlineGeometry().SetLength(dLength); + if (detail.GetGrainlineGeometry().IsVisible() == true) + { + qreal dRot = GetParametrDouble(element, VToolDetail::AttrRotation, "0"); + detail.GetGrainlineGeometry().SetRotation(dRot); + } + else + { + detail.GetGrainlineGeometry().SetRotation(0); + } + } } } VToolDetail::Create(id, detail, sceneDetail, this, data, parse, Source::FromFile); diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index c55cd654e..6661ca5b6 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -27,5 +27,6 @@ schema/individual_measurements/v0.3.1.xsd schema/individual_measurements/v0.3.2.xsd schema/individual_measurements/v0.3.3.xsd + schema/pattern/v0.3.5.xsd diff --git a/src/libs/ifc/schema/pattern/v0.3.5.xsd b/src/libs/ifc/schema/pattern/v0.3.5.xsd new file mode 100644 index 000000000..db1b7232f --- /dev/null +++ b/src/libs/ifc/schema/pattern/v0.3.5.xsd @@ -0,0 +1,581 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 2d1cf5568..661387eb8 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -88,6 +88,7 @@ const QString VAbstractPattern::TagCompanyName = QStringLiteral("company"); const QString VAbstractPattern::TagSize = QStringLiteral("size"); const QString VAbstractPattern::TagShowDate = QStringLiteral("showDate"); const QString VAbstractPattern::TagShowMeasurements = QStringLiteral("showMeasurements"); +const QString VAbstractPattern::TagGrainline = QStringLiteral("grainline"); const QString VAbstractPattern::AttrName = QStringLiteral("name"); const QString VAbstractPattern::AttrVisible = QStringLiteral("visible"); diff --git a/src/libs/ifc/xml/vabstractpattern.h b/src/libs/ifc/xml/vabstractpattern.h index 467eb6da5..116a31769 100644 --- a/src/libs/ifc/xml/vabstractpattern.h +++ b/src/libs/ifc/xml/vabstractpattern.h @@ -192,6 +192,7 @@ public: static const QString TagSize; static const QString TagShowDate; static const QString TagShowMeasurements; + static const QString TagGrainline; static const QString AttrName; static const QString AttrVisible; diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 33b652163..606555335 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.3.4"); -const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.4.xsd"); +const QString VPatternConverter::PatternMaxVerStr = QStringLiteral("0.3.5"); +const QString VPatternConverter::CurrentSchema = QStringLiteral("://schema/pattern/v0.3.5.xsd"); //VPatternConverter::PatternMinVer; // <== DON'T FORGET TO UPDATE TOO!!!! //VPatternConverter::PatternMaxVer; // <== DON'T FORGET TO UPDATE TOO!!!! @@ -167,6 +167,8 @@ QString VPatternConverter::XSDSchema(int ver) const case (0x000303): return QStringLiteral("://schema/pattern/v0.3.3.xsd"); case (0x000304): + return QStringLiteral("://schema/pattern/v0.3.4.xsd"); + case (0x000305): return CurrentSchema; default: InvalidVersion(ver); @@ -250,6 +252,9 @@ void VPatternConverter::ApplyPatches() ValidateXML(XSDSchema(0x000304), fileName); V_FALLTHROUGH case (0x000304): + ToV0_3_5(); + ValidateXML(XSDSchema(0x000305), fileName); + case (0x000305): break; default: break; @@ -410,6 +415,13 @@ void VPatternConverter::ToV0_3_4() Save(); } +//--------------------------------------------------------------------------------------------------------------------- +void VPatternConverter::ToV0_3_5() +{ + SetVersion(QStringLiteral("0.3.5")); + Save(); +} + //--------------------------------------------------------------------------------------------------------------------- void VPatternConverter::TagUnitToV0_2_0() { diff --git a/src/libs/ifc/xml/vpatternconverter.h b/src/libs/ifc/xml/vpatternconverter.h index b4af935ac..cca5e3c2f 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, 3, 4); + static Q_DECL_CONSTEXPR int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 5); #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, 3, 4); + static Q_DECL_CONSTEXPR const int PatternMaxVer = CONVERTER_VERSION_CHECK(0, 3, 5); #endif protected: @@ -93,6 +93,7 @@ private: void ToV0_3_2(); void ToV0_3_3(); void ToV0_3_4(); + void ToV0_3_5(); void TagUnitToV0_2_0(); void TagIncrementToV0_2_0(); diff --git a/src/libs/vpatterndb/vdetail.cpp b/src/libs/vpatterndb/vdetail.cpp index 555f54a83..209265950 100644 --- a/src/libs/vpatterndb/vdetail.cpp +++ b/src/libs/vpatterndb/vdetail.cpp @@ -47,6 +47,7 @@ #include "vdetail_p.h" #include "vnodedetail.h" #include "vpatternpiecedata.h" +#include "vgrainlinegeometry.h" class QPointF; @@ -580,6 +581,28 @@ const VPatternInfoGeometry& VDetail::GetPatternInfo() const return d->m_piPatternInfo; } +//--------------------------------------------------------------------------------------------------------------------- + +/** + * @brief VDetail::GetGrainlineGeometry full access to the grainline geometry object + * @return reference to grainline geometry object + */ +VGrainlineGeometry& VDetail::GetGrainlineGeometry() +{ + return d->m_glGrainline; +} + +//--------------------------------------------------------------------------------------------------------------------- + +/** + * @brief VDetail::GetGrainlineGeometry returns the read-only reference to the grainline geometry object + * @return reference to grainline geometry object + */ +const VGrainlineGeometry& VDetail::GetGrainlineGeometry() const +{ + return d->m_glGrainline; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief indexOfNode return index in list node using id object. diff --git a/src/libs/vpatterndb/vdetail.h b/src/libs/vpatterndb/vdetail.h index 626fb4a0f..4f14115c7 100644 --- a/src/libs/vpatterndb/vdetail.h +++ b/src/libs/vpatterndb/vdetail.h @@ -47,6 +47,7 @@ class VDetailData; class VNodeDetail; class VPatternInfoGeometry; class VPatternPieceData; +class VGrainlineGeometry; /** * @brief The VDetail class for path of object (points, arcs, splines). @@ -101,6 +102,8 @@ public: const VPatternPieceData& GetPatternPieceData() const; VPatternInfoGeometry& GetPatternInfo(); const VPatternInfoGeometry& GetPatternInfo() const; + VGrainlineGeometry& GetGrainlineGeometry(); + const VGrainlineGeometry& GetGrainlineGeometry() const; private: QSharedDataPointer d; diff --git a/src/libs/vpatterndb/vdetail_p.h b/src/libs/vpatterndb/vdetail_p.h index 7e256b9e5..d3692ca24 100644 --- a/src/libs/vpatterndb/vdetail_p.h +++ b/src/libs/vpatterndb/vdetail_p.h @@ -33,6 +33,7 @@ #include "vnodedetail.h" #include "vpatternpiecedata.h" #include "vpatterninfogeometry.h" +#include "vgrainlinegeometry.h" #include "../ifc/ifcdef.h" #include "../vmisc/diagnostic.h" @@ -52,7 +53,8 @@ public: VDetailData(const VDetailData &detail) :QSharedData(detail), _id(NULL_ID), nodes(detail.nodes), mx(detail.mx), my(detail.my), - m_ppData(detail.m_ppData), m_piPatternInfo(detail.m_piPatternInfo), inLayout(detail.inLayout) + m_ppData(detail.m_ppData), m_piPatternInfo(detail.m_piPatternInfo), + m_glGrainline(detail.m_glGrainline), inLayout(detail.inLayout) {} ~VDetailData() {} @@ -73,6 +75,10 @@ public: VPatternPieceData m_ppData; /** @brief Pattern info coordinates */ VPatternInfoGeometry m_piPatternInfo; + /** + * @brief m_glGrainline grainline geometry object + */ + VGrainlineGeometry m_glGrainline; bool inLayout; diff --git a/src/libs/vpatterndb/vgrainlinegeometry.cpp b/src/libs/vpatterndb/vgrainlinegeometry.cpp new file mode 100644 index 000000000..4f64d6158 --- /dev/null +++ b/src/libs/vpatterndb/vgrainlinegeometry.cpp @@ -0,0 +1,101 @@ +/************************************************************************ + ** + ** @file vgrainlinegeometry.cpp + ** @author Bojan Kverh + ** @date September 06, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include + +#include "vgrainlinegeometry.h" + +//--------------------------------------------------------------------------------------------------------------------- + +VGrainlineGeometry::VGrainlineGeometry() + :m_ptPos(0, 0), m_dLength(0), m_dRotation(0), m_bVisible(true) +{} + +//--------------------------------------------------------------------------------------------------------------------- + +VGrainlineGeometry::~VGrainlineGeometry() +{} + +//--------------------------------------------------------------------------------------------------------------------- + +QPointF VGrainlineGeometry::GetPos() const +{ + return m_ptPos; +} + +//--------------------------------------------------------------------------------------------------------------------- + +void VGrainlineGeometry::SetPos(const QPointF &ptPos) +{ + m_ptPos = ptPos; +} + +//--------------------------------------------------------------------------------------------------------------------- + +qreal VGrainlineGeometry::GetLength() const +{ + return m_dLength; +} + +//--------------------------------------------------------------------------------------------------------------------- + +void VGrainlineGeometry::SetLength(qreal dLen) +{ + m_dLength = dLen; +} + +//--------------------------------------------------------------------------------------------------------------------- + +qreal VGrainlineGeometry::GetRotation() const +{ + return m_dRotation; +} + +//--------------------------------------------------------------------------------------------------------------------- + +void VGrainlineGeometry::SetRotation(qreal dRot) +{ + m_dRotation = dRot; +} + +//--------------------------------------------------------------------------------------------------------------------- + +bool VGrainlineGeometry::IsVisible() const +{ + return m_bVisible; +} + +//--------------------------------------------------------------------------------------------------------------------- + +void VGrainlineGeometry::SetVisible(bool bVisible) +{ + m_bVisible = bVisible; +} + +//--------------------------------------------------------------------------------------------------------------------- + diff --git a/src/libs/vpatterndb/vgrainlinegeometry.h b/src/libs/vpatterndb/vgrainlinegeometry.h new file mode 100644 index 000000000..ae7fad4b6 --- /dev/null +++ b/src/libs/vpatterndb/vgrainlinegeometry.h @@ -0,0 +1,76 @@ +/************************************************************************ + ** + ** @file vgrainlinegeometry.h + ** @author Bojan Kverh + ** @date September 06, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VGRAINLINEGEOMETRY_H +#define VGRAINLINEGEOMETRY_H + +#include + +class QPointF; + +/** + * @brief The VGrainlineGeometry class holds information about a grainline like + * position, size, rotation and visibility + */ +class VGrainlineGeometry +{ +public: + VGrainlineGeometry(); + ~VGrainlineGeometry(); + + // methods, which set and return values of different parameters + QPointF GetPos() const; + void SetPos(const QPointF& ptPos); + qreal GetLength() const; + void SetLength(qreal dLen); + qreal GetRotation() const; + void SetRotation(qreal dRot); + bool IsVisible() const; + void SetVisible(bool bVisible); + +private: + /** + * @brief m_ptPos position of grainline's center + */ + QPointF m_ptPos; + /** + * @brief m_dLength total length of grainline + */ + qreal m_dLength; + /** + * @brief m_dRotation rotation of grainline in [degrees] + */ + qreal m_dRotation; + /** + * @brief m_bVisible visibility flag + */ + bool m_bVisible; +}; + +#endif // VGRAINLINEGEOMETRY_H + diff --git a/src/libs/vpatterndb/vpatterndb.pri b/src/libs/vpatterndb/vpatterndb.pri index b2e055a6e..7ea6f076d 100644 --- a/src/libs/vpatterndb/vpatterndb.pri +++ b/src/libs/vpatterndb/vpatterndb.pri @@ -19,7 +19,8 @@ SOURCES += \ $$PWD/variables/vvariable.cpp \ $$PWD/vformula.cpp \ $$PWD/vpatternpiecedata.cpp \ - $$PWD/vpatterninfogeometry.cpp + $$PWD/vpatterninfogeometry.cpp \ + $$PWD/vgrainlinegeometry.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -53,4 +54,5 @@ HEADERS += \ $$PWD/variables/vvariable_p.h \ $$PWD/vformula.h \ $$PWD/vpatternpiecedata.h \ - $$PWD/vpatterninfogeometry.h + $$PWD/vpatterninfogeometry.h \ + $$PWD/vgrainlinegeometry.h diff --git a/src/libs/vpatterndb/vpatterndb.pro b/src/libs/vpatterndb/vpatterndb.pro index 10c0b507f..02883e19f 100644 --- a/src/libs/vpatterndb/vpatterndb.pro +++ b/src/libs/vpatterndb/vpatterndb.pro @@ -67,3 +67,5 @@ CONFIG(release, debug|release){ } include (../libs.pri) + +HEADERS += diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 6ee916db0..8334eae68 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -76,7 +76,7 @@ class QWidget; */ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(), detail(VDetail()), supplement(true), closed(true), flagWidth(true), - m_bAddMode(true), m_qslMaterials(), m_qslPlacements(), m_conMCP(), m_oldData(), m_oldGeom() + m_bAddMode(true), m_qslMaterials(), m_qslPlacements(), m_conMCP(), m_oldData(), m_oldGeom(), m_oldGrainline() { ui.setupUi(this); @@ -150,7 +150,9 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge connect(ui.pushButtonRemove, &QPushButton::clicked, this, &DialogDetail::Remove); connect(ui.listWidgetMCP, &QListWidget::itemClicked, this, &DialogDetail::SetEditMode); connect(ui.comboBoxMaterial, &QComboBox::currentTextChanged, this, &DialogDetail::MaterialChanged); + connect(ui.checkBoxGrainline, &QCheckBox::toggled, this, &DialogDetail::EnableGrainlineRotation); SetAddMode(); + EnableGrainlineRotation(); ui.tabWidget->setCurrentIndex(0); } @@ -463,6 +465,12 @@ VDetail DialogDetail::CreateDetail() const detail.GetPatternInfo() = m_oldGeom; detail.GetPatternInfo().SetVisible(ui.checkBoxPattern->isChecked()); + detail.GetGrainlineGeometry() = m_oldGrainline; + detail.GetGrainlineGeometry().SetVisible(ui.checkBoxGrainline->isChecked()); + if (ui.checkBoxGrainline->isChecked() == true) + { + detail.GetGrainlineGeometry().SetRotation(ui.spinBoxGrainlineRotation->value()); + } return detail; } @@ -532,10 +540,16 @@ void DialogDetail::setDetail(const VDetail &value) } UpdateList(); + + ui.checkBoxGrainline->setChecked(detail.GetGrainlineGeometry().IsVisible()); + ui.spinBoxGrainlineRotation->setValue(detail.GetGrainlineGeometry().GetRotation()); + m_oldData = detail.GetPatternPieceData(); m_oldGeom = detail.GetPatternInfo(); + m_oldGrainline = detail.GetGrainlineGeometry(); ValidObjects(DetailIsValid()); + EnableGrainlineRotation(); } //--------------------------------------------------------------------------------------------------------------------- @@ -847,3 +861,9 @@ void DialogDetail::SetEditMode() m_bAddMode = false; } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::EnableGrainlineRotation() +{ + ui.spinBoxGrainlineRotation->setEnabled(ui.checkBoxGrainline->isChecked()); +} diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index 26dbe48a0..d56787390 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -40,6 +40,7 @@ #include "../vpatterndb/vdetail.h" #include "../vpatterndb/vpatterninfogeometry.h" #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vgrainlinegeometry.h" #include "dialogtool.h" #include "ui_dialogdetail.h" @@ -107,6 +108,7 @@ private: MCPContainer m_conMCP; VPatternPieceData m_oldData; VPatternInfoGeometry m_oldGeom; + VGrainlineGeometry m_oldGrainline; bool DetailIsValid() const; @@ -126,6 +128,7 @@ private: private slots: void SetAddMode(); void SetEditMode(); + void EnableGrainlineRotation(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index be5300e33..ef40167f3 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -7,7 +7,7 @@ 0 0 581 - 468 + 478 @@ -24,7 +24,7 @@ - 0 + 2 @@ -318,7 +318,8 @@ - .. + + @@ -332,7 +333,8 @@ - .. + + @@ -526,6 +528,50 @@ + + + SizeVerCursor + + + Grainline + + + + + 10 + 10 + 291 + 62 + + + + + + + Rotation: + + + + + + + ° + + + 359 + + + + + + + Grainline visible + + + + + + @@ -539,11 +585,8 @@ - buttonBox - tabWidget - lineEditLetter lineEditName comboBoxMaterial spinBoxCutNumber @@ -551,8 +594,6 @@ pushButtonAdd pushButtonCancel pushButtonRemove - listWidgetMCP - buttonBox toolButtonUp listWidget checkBoxClosed @@ -563,6 +604,13 @@ checkBoxSeams doubleSpinBoxSeams toolButtonDown + tabWidget + checkBoxForbidFlipping + checkBoxDetail + checkBoxPattern + lineEditLetter + checkBoxGrainline + spinBoxGrainlineRotation diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index ed036006c..c8ad14fa8 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -435,6 +435,7 @@ void VToolDetail::AddToFile() doc->SetAttribute(domElement, AttrWidth, detail.getWidth()); doc->SetAttribute(domElement, AttrForbidFlipping, static_cast(detail.getForbidFlipping())); + // detail data QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = detail.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); @@ -461,6 +462,7 @@ void VToolDetail::AddToFile() } domElement.appendChild(domData); + // pattern info domData = doc->createElement(VAbstractPattern::TagPatternInfo); const VPatternInfoGeometry& geom = detail.GetPatternInfo(); doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true? trueStr : falseStr); @@ -471,6 +473,16 @@ void VToolDetail::AddToFile() doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); doc->SetAttribute(domData, AttrRotation, geom.GetRotation()); + // grainline + domData = doc->createElement(VAbstractPattern::TagGrainline); + const VGrainlineGeometry& glGeom = detail.GetGrainlineGeometry(); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, glGeom.IsVisible() == true? trueStr : falseStr); + doc->SetAttribute(domData, AttrMx, glGeom.GetPos().x()); + doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y()); + doc->SetAttribute(domData, AttrLength, glGeom.GetLength()); + doc->SetAttribute(domData, AttrRotation, glGeom.GetRotation()); + + // nodes for (int i = 0; i < detail.CountNode(); ++i) { AddNode(doc, domElement, detail.at(i)); @@ -497,6 +509,7 @@ void VToolDetail::RefreshDataInFile() doc->SetAttribute(domElement, AttrWidth, QString().setNum(det.getWidth())); doc->RemoveAllChildren(domElement); + // detail data QDomElement domData = doc->createElement(VAbstractPattern::TagData); const VPatternPieceData& data = det.GetPatternPieceData(); doc->SetAttribute(domData, VAbstractPattern::AttrLetter, data.GetLetter()); @@ -527,6 +540,7 @@ void VToolDetail::RefreshDataInFile() } domElement.appendChild(domData); + // pattern info domData = doc->createElement(VAbstractPattern::TagPatternInfo); const VPatternInfoGeometry& geom = det.GetPatternInfo(); doc->SetAttribute(domData, VAbstractPattern::AttrVisible, geom.IsVisible() == true? trueStr : falseStr); @@ -537,6 +551,16 @@ void VToolDetail::RefreshDataInFile() doc->SetAttribute(domData, AttrFont, geom.GetFontSize()); doc->SetAttribute(domData, AttrRotation, geom.GetRotation()); + // grainline + domData = doc->createElement(VAbstractPattern::TagGrainline); + const VGrainlineGeometry& glGeom = det.GetGrainlineGeometry(); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, glGeom.IsVisible() == true? trueStr : falseStr); + doc->SetAttribute(domData, AttrMx, glGeom.GetPos().x()); + doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y()); + doc->SetAttribute(domData, AttrLength, glGeom.GetLength()); + doc->SetAttribute(domData, AttrRotation, glGeom.GetRotation()); + + // nodes for (int i = 0; i < det.CountNode(); ++i) { AddNode(doc, domElement, det.at(i)); diff --git a/src/libs/vtools/undocommands/savedetailoptions.cpp b/src/libs/vtools/undocommands/savedetailoptions.cpp index 7da804348..11a418c52 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.cpp +++ b/src/libs/vtools/undocommands/savedetailoptions.cpp @@ -38,6 +38,7 @@ #include "../vmisc/def.h" #include "../vpatterndb/vpatterninfogeometry.h" #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vgrainlinegeometry.h" #include "../tools/vtooldetail.h" #include "vundocommand.h" @@ -69,6 +70,8 @@ void SaveDetailOptions::undo() doc->RemoveAllChildren(domElement); SavePatternPieceData(domElement, oldDet); SavePatternInfo(domElement, oldDet); + SaveGrainline(domElement, oldDet); + for (int i = 0; i < oldDet.CountNode(); ++i) { VToolDetail::AddNode(doc, domElement, oldDet.at(i)); @@ -95,6 +98,7 @@ void SaveDetailOptions::redo() doc->RemoveAllChildren(domElement); SavePatternPieceData(domElement, newDet); SavePatternInfo(domElement, newDet); + SaveGrainline(domElement, newDet); for (int i = 0; i < newDet.CountNode(); ++i) { @@ -194,3 +198,17 @@ void SaveDetailOptions::SavePatternInfo(QDomElement &domElement, const VDetail & domElement.appendChild(domData); } + +//--------------------------------------------------------------------------------------------------------------------- +void SaveDetailOptions::SaveGrainline(QDomElement &domElement, const VDetail &det) +{ + QDomElement domData = doc->createElement(VAbstractPattern::TagGrainline); + const VGrainlineGeometry& glGeom = det.GetGrainlineGeometry(); + doc->SetAttribute(domData, VAbstractPattern::AttrVisible, glGeom.IsVisible() == true? trueStr : falseStr); + doc->SetAttribute(domData, AttrMx, glGeom.GetPos().x()); + doc->SetAttribute(domData, AttrMy, glGeom.GetPos().y()); + doc->SetAttribute(domData, AttrLength, glGeom.GetLength()); + doc->SetAttribute(domData, VToolDetail::AttrRotation, glGeom.GetRotation()); + + domElement.appendChild(domData); +} diff --git a/src/libs/vtools/undocommands/savedetailoptions.h b/src/libs/vtools/undocommands/savedetailoptions.h index d1ff979d9..5b4cbc058 100644 --- a/src/libs/vtools/undocommands/savedetailoptions.h +++ b/src/libs/vtools/undocommands/savedetailoptions.h @@ -65,6 +65,7 @@ private: void SaveDet(QDomElement &domElement, const VDetail &det); void SavePatternPieceData(QDomElement &domElement, const VDetail &det); void SavePatternInfo(QDomElement &domElement, const VDetail &det); + void SaveGrainline(QDomElement &domElement, const VDetail &det); }; //--------------------------------------------------------------------------------------------------------------------- From 37e16b4626b80dfad80c8cfc07e262281f289929 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 6 Sep 2016 23:52:16 +0200 Subject: [PATCH 02/19] Removed the vpatterndb.pro changes --HG-- branch : feature --- src/libs/vpatterndb/vpatterndb.pro | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/vpatterndb/vpatterndb.pro b/src/libs/vpatterndb/vpatterndb.pro index 02883e19f..10c0b507f 100644 --- a/src/libs/vpatterndb/vpatterndb.pro +++ b/src/libs/vpatterndb/vpatterndb.pro @@ -67,5 +67,3 @@ CONFIG(release, debug|release){ } include (../libs.pri) - -HEADERS += From 2dc19732a056ad7488411d98518ca9e58dc5e72e Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 8 Sep 2016 22:35:32 +0200 Subject: [PATCH 03/19] Prepated detail dialog for formula editing in case of grainline length and rotation --HG-- branch : feature --- src/app/valentina/xml/vpattern.cpp | 15 +- src/libs/ifc/schema/pattern/v0.3.5.xsd | 4 +- src/libs/vpatterndb/vgrainlinegeometry.cpp | 18 +-- src/libs/vpatterndb/vgrainlinegeometry.h | 17 +- .../vtools/dialogs/tools/dialogdetail.cpp | 13 +- src/libs/vtools/dialogs/tools/dialogdetail.ui | 151 +++++++++++++++--- 6 files changed, 163 insertions(+), 55 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 7a3d84f3f..0899e0748 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -724,17 +724,10 @@ void VPattern::ParseDetailElement(const QDomElement &domElement, const Document ptPos.setX(GetParametrDouble(element, AttrMx, "0")); ptPos.setY(GetParametrDouble(element, AttrMy, "0")); detail.GetGrainlineGeometry().SetPos(ptPos); - qreal dLength = GetParametrDouble(element, AttrLength, "0"); - detail.GetGrainlineGeometry().SetLength(dLength); - if (detail.GetGrainlineGeometry().IsVisible() == true) - { - qreal dRot = GetParametrDouble(element, VToolDetail::AttrRotation, "0"); - detail.GetGrainlineGeometry().SetRotation(dRot); - } - else - { - detail.GetGrainlineGeometry().SetRotation(0); - } + QString qsLength = GetParametrString(element, AttrLength, "0"); + detail.GetGrainlineGeometry().SetLength(qsLength); + QString qsRot = GetParametrString(element, VToolDetail::AttrRotation, "0"); + detail.GetGrainlineGeometry().SetRotation(qsRot); } } } diff --git a/src/libs/ifc/schema/pattern/v0.3.5.xsd b/src/libs/ifc/schema/pattern/v0.3.5.xsd index db1b7232f..d872d7977 100644 --- a/src/libs/ifc/schema/pattern/v0.3.5.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.5.xsd @@ -378,8 +378,8 @@ - - + + diff --git a/src/libs/vpatterndb/vgrainlinegeometry.cpp b/src/libs/vpatterndb/vgrainlinegeometry.cpp index 4f64d6158..fb519bf84 100644 --- a/src/libs/vpatterndb/vgrainlinegeometry.cpp +++ b/src/libs/vpatterndb/vgrainlinegeometry.cpp @@ -33,7 +33,7 @@ //--------------------------------------------------------------------------------------------------------------------- VGrainlineGeometry::VGrainlineGeometry() - :m_ptPos(0, 0), m_dLength(0), m_dRotation(0), m_bVisible(true) + :m_ptPos(0, 0), m_qsLength(), m_qsRotation(), m_bVisible(true) {} //--------------------------------------------------------------------------------------------------------------------- @@ -57,30 +57,30 @@ void VGrainlineGeometry::SetPos(const QPointF &ptPos) //--------------------------------------------------------------------------------------------------------------------- -qreal VGrainlineGeometry::GetLength() const +QString VGrainlineGeometry::GetLength() const { - return m_dLength; + return m_qsLength; } //--------------------------------------------------------------------------------------------------------------------- -void VGrainlineGeometry::SetLength(qreal dLen) +void VGrainlineGeometry::SetLength(QString qsLen) { - m_dLength = dLen; + m_qsLength = qsLen; } //--------------------------------------------------------------------------------------------------------------------- -qreal VGrainlineGeometry::GetRotation() const +QString VGrainlineGeometry::GetRotation() const { - return m_dRotation; + return m_qsRotation; } //--------------------------------------------------------------------------------------------------------------------- -void VGrainlineGeometry::SetRotation(qreal dRot) +void VGrainlineGeometry::SetRotation(QString qsRot) { - m_dRotation = dRot; + m_qsRotation = qsRot; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vpatterndb/vgrainlinegeometry.h b/src/libs/vpatterndb/vgrainlinegeometry.h index ae7fad4b6..d4a2f8fff 100644 --- a/src/libs/vpatterndb/vgrainlinegeometry.h +++ b/src/libs/vpatterndb/vgrainlinegeometry.h @@ -30,6 +30,7 @@ #define VGRAINLINEGEOMETRY_H #include +#include class QPointF; @@ -46,10 +47,10 @@ public: // methods, which set and return values of different parameters QPointF GetPos() const; void SetPos(const QPointF& ptPos); - qreal GetLength() const; - void SetLength(qreal dLen); - qreal GetRotation() const; - void SetRotation(qreal dRot); + QString GetLength() const; + void SetLength(QString qsLen); + QString GetRotation() const; + void SetRotation(QString qsRot); bool IsVisible() const; void SetVisible(bool bVisible); @@ -59,13 +60,13 @@ private: */ QPointF m_ptPos; /** - * @brief m_dLength total length of grainline + * @brief m_dLength formula to calculate the length of grainline */ - qreal m_dLength; + QString m_qsLength; /** - * @brief m_dRotation rotation of grainline in [degrees] + * @brief m_dRotation formula to calculate the rotation of grainline in [degrees] */ - qreal m_dRotation; + QString m_qsRotation; /** * @brief m_bVisible visibility flag */ diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 8334eae68..f61898ee3 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -469,7 +469,8 @@ VDetail DialogDetail::CreateDetail() const detail.GetGrainlineGeometry().SetVisible(ui.checkBoxGrainline->isChecked()); if (ui.checkBoxGrainline->isChecked() == true) { - detail.GetGrainlineGeometry().SetRotation(ui.spinBoxGrainlineRotation->value()); + detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->text()); + detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->text()); } return detail; } @@ -542,7 +543,8 @@ void DialogDetail::setDetail(const VDetail &value) UpdateList(); ui.checkBoxGrainline->setChecked(detail.GetGrainlineGeometry().IsVisible()); - ui.spinBoxGrainlineRotation->setValue(detail.GetGrainlineGeometry().GetRotation()); + ui.lineEditRotFormula->setText(detail.GetGrainlineGeometry().GetRotation()); + ui.lineEditLenFormula->setText(detail.GetGrainlineGeometry().GetLength()); m_oldData = detail.GetPatternPieceData(); m_oldGeom = detail.GetPatternInfo(); @@ -865,5 +867,10 @@ void DialogDetail::SetEditMode() //--------------------------------------------------------------------------------------------------------------------- void DialogDetail::EnableGrainlineRotation() { - ui.spinBoxGrainlineRotation->setEnabled(ui.checkBoxGrainline->isChecked()); + ui.lineEditRotValue->setEnabled(ui.checkBoxGrainline->isChecked()); + ui.lineEditRotFormula->setEnabled(ui.checkBoxGrainline->isChecked()); + ui.lineEditLenValue->setEnabled(ui.checkBoxGrainline->isChecked()); + ui.lineEditLenFormula->setEnabled(ui.checkBoxGrainline->isChecked()); + ui.pushButtonRot->setEnabled(ui.checkBoxGrainline->isChecked()); + ui.pushButtonLen->setEnabled(ui.checkBoxGrainline->isChecked()); } diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index ef40167f3..6a5125508 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -540,28 +540,11 @@ 10 10 - 291 - 62 + 361 + 201 - - - - - Rotation: - - - - - - - ° - - - 359 - - - + @@ -569,6 +552,132 @@ + + + + + Liberation Sans + 10 + 75 + true + + + + Length + + + + + + + + + + + + + + Value + + + + + + + Value + + + + + + + + Liberation Sans + 10 + 75 + true + + + + Rotation + + + + + + + Formula + + + + + + + + + + + + + + Formula + + + + + + + + 0 + 0 + + + + f(x) + + + + + + + + 0 + 0 + + + + f(x) + + + + + + + true + + + + + + + true + + + + + + + true + + + + + + + true + + + @@ -604,13 +713,11 @@ checkBoxSeams doubleSpinBoxSeams toolButtonDown - tabWidget checkBoxForbidFlipping checkBoxDetail checkBoxPattern lineEditLetter checkBoxGrainline - spinBoxGrainlineRotation From 906dafebe80c79cfcbed25ed931393fd572a1e90 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 10 Sep 2016 15:17:55 +0200 Subject: [PATCH 04/19] Finished the grainline parameters editing in detail dialog --HG-- branch : feature --- .../vtools/dialogs/tools/dialogdetail.cpp | 108 ++++++++++++++++++ src/libs/vtools/dialogs/tools/dialogdetail.h | 4 + src/libs/vtools/dialogs/tools/dialogdetail.ui | 6 +- src/libs/vtools/dialogs/tools/dialogtool.cpp | 3 + 4 files changed, 118 insertions(+), 3 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index f61898ee3..efae6ce19 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -60,10 +60,12 @@ #include "../ifc/xml/vdomdocument.h" #include "../vpatterndb/vcontainer.h" +#include "../vpatterndb/calculator.h" #include "../vgeometry/vgobject.h" #include "../vmisc/vabstractapplication.h" #include "dialogtool.h" #include "vnodedetail.h" +#include "../support/dialogeditwrongformula.h" class QPointF; class QWidget; @@ -144,6 +146,8 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge 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, &DialogDetail::AddUpdate); connect(ui.pushButtonCancel, &QPushButton::clicked, this, &DialogDetail::Cancel); @@ -151,6 +155,11 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge connect(ui.listWidgetMCP, &QListWidget::itemClicked, this, &DialogDetail::SetEditMode); connect(ui.comboBoxMaterial, &QComboBox::currentTextChanged, this, &DialogDetail::MaterialChanged); connect(ui.checkBoxGrainline, &QCheckBox::toggled, this, &DialogDetail::EnableGrainlineRotation); + connect(ui.pushButtonRot, &QPushButton::clicked, this, &DialogDetail::EditFormula); + connect(ui.pushButtonLen, &QPushButton::clicked, this, &DialogDetail::EditFormula); + connect(ui.lineEditLenFormula, &QLineEdit::textChanged, this, &DialogDetail::UpdateValue); + connect(ui.lineEditRotFormula, &QLineEdit::textChanged, this, &DialogDetail::UpdateValue); + SetAddMode(); EnableGrainlineRotation(); @@ -817,6 +826,65 @@ void DialogDetail::ClearFields() ui.comboBoxPlacement->setCurrentIndex(0); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::SetValue(QObject *pobjSender) +{ + QLineEdit* pleSender = dynamic_cast(pobjSender); + SCASSERT(pleSender != 0); + + QString qsFormula = pleSender->text().simplified(); + Calculator cal; + QString qsVal; + try + { + qsFormula.replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + qreal dVal; + dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); + if (qIsInf(dVal) == true || qIsNaN(dVal) == true) + { + qsVal.clear(); + } + else + { + qsVal.setNum(dVal, 'f', 5); + } + } + catch (...) + { + qsVal.clear(); + } + + QLineEdit* pleVal; + QLabel* plbVal; + QString qsUnit; + if (pobjSender == ui.lineEditLenFormula) + { + pleVal = ui.lineEditLenValue; + plbVal = ui.labelLen; + qsUnit = " " + VDomDocument::UnitsToStr(qApp->patternUnit()); + } + else if (pobjSender == ui.lineEditRotFormula) + { + pleVal = ui.lineEditRotValue; + plbVal = ui.labelRot; + QChar ch(0x00b0); + qsUnit = ch; + } + else + { + // should not get here + return; + } + + if (qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } + pleVal->setText(qsVal); + plbVal->setText(qsVal); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogDetail::SetAddMode() { @@ -874,3 +942,43 @@ void DialogDetail::EnableGrainlineRotation() ui.pushButtonRot->setEnabled(ui.checkBoxGrainline->isChecked()); ui.pushButtonLen->setEnabled(ui.checkBoxGrainline->isChecked()); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::EditFormula() +{ + QLineEdit* pleFormula; + bool bCheckZero; + + if (sender() == ui.pushButtonLen) + { + pleFormula = ui.lineEditLenFormula; + bCheckZero = true; + } + else if (sender() == ui.pushButtonRot) + { + pleFormula = ui.lineEditRotFormula; + bCheckZero = false; + } + else + { + // should get here! + return; + } + + DialogEditWrongFormula dlg(data, NULL_ID, this); + dlg.SetFormula(pleFormula->text()); + dlg.setCheckZero(bCheckZero); + if (dlg.exec() == true) + { + QString qsFormula = dlg.GetFormula(); + qsFormula.replace("\n", " "); + pleFormula->setText(qsFormula); + SetValue(pleFormula); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::UpdateValue(const QString&) +{ + SetValue(sender()); +} diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index d56787390..7c7c634d2 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -125,10 +125,14 @@ private: quint32 RowId(int i) const; + void SetValue(QObject* pobjSender); + private slots: void SetAddMode(); void SetEditMode(); void EnableGrainlineRotation(); + void EditFormula(); + void UpdateValue(const QString &); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index 6a5125508..555100038 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -544,7 +544,7 @@ 201 - + @@ -633,7 +633,7 @@ - f(x) + @@ -646,7 +646,7 @@ - f(x) + diff --git a/src/libs/vtools/dialogs/tools/dialogtool.cpp b/src/libs/vtools/dialogs/tools/dialogtool.cpp index 48a492a0c..246b8a2ad 100644 --- a/src/libs/vtools/dialogs/tools/dialogtool.cpp +++ b/src/libs/vtools/dialogs/tools/dialogtool.cpp @@ -469,8 +469,11 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim */ qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QString& postfix, bool checkZero) { + qDebug() << "Eval started"; SCASSERT(label != nullptr); + qDebug() << "Label ok"; SCASSERT(labelEditFormula != nullptr); + qDebug() << "lef ok"; qreal result = INT_MIN;//Value can be 0, so use max imposible value From f341f51125ca34539e61946495ad2aef4f5da08a Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 10 Sep 2016 18:30:03 +0200 Subject: [PATCH 05/19] Grainline is visible on the detail now, rotation and length can be edited, but it cannot be moved yet --HG-- branch : feature --- .../vtools/dialogs/tools/dialogdetail.cpp | 5 +- src/libs/vtools/dialogs/tools/dialogdetail.h | 2 +- src/libs/vtools/tools/tools.pri | 6 +- src/libs/vtools/tools/vgrainlineitem.cpp | 125 ++++++++++++++++++ src/libs/vtools/tools/vgrainlineitem.h | 67 ++++++++++ src/libs/vtools/tools/vtextgraphicsitem.cpp | 2 +- src/libs/vtools/tools/vtooldetail.cpp | 44 +++++- src/libs/vtools/tools/vtooldetail.h | 3 + src/libs/vtools/vtools.pri | 1 + 9 files changed, 248 insertions(+), 7 deletions(-) create mode 100644 src/libs/vtools/tools/vgrainlineitem.cpp create mode 100644 src/libs/vtools/tools/vgrainlineitem.h diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index efae6ce19..c9879dcf8 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -961,7 +961,7 @@ void DialogDetail::EditFormula() } else { - // should get here! + // should not get here! return; } @@ -978,7 +978,8 @@ void DialogDetail::EditFormula() } //--------------------------------------------------------------------------------------------------------------------- -void DialogDetail::UpdateValue(const QString&) +void DialogDetail::UpdateValue(const QString& qsText) { + Q_UNUSED(qsText); SetValue(sender()); } diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index 7c7c634d2..bb2cfd813 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -132,7 +132,7 @@ private slots: void SetEditMode(); void EnableGrainlineRotation(); void EditFormula(); - void UpdateValue(const QString &); + void UpdateValue(const QString& qsText); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 0391ca475..9ca6a2cd2 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -51,7 +51,8 @@ HEADERS += \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \ $$PWD/drawTools/operation/vtoolrotation.h \ - $$PWD/vtextgraphicsitem.h + $$PWD/vtextgraphicsitem.h \ + $$PWD/vgrainlineitem.h SOURCES += \ $$PWD/vtooldetail.cpp \ @@ -100,4 +101,5 @@ SOURCES += \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.cpp \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \ $$PWD/drawTools/operation/vtoolrotation.cpp \ - $$PWD/vtextgraphicsitem.cpp + $$PWD/vtextgraphicsitem.cpp \ + $$PWD/vgrainlineitem.cpp diff --git a/src/libs/vtools/tools/vgrainlineitem.cpp b/src/libs/vtools/tools/vgrainlineitem.cpp new file mode 100644 index 000000000..e21fdffcb --- /dev/null +++ b/src/libs/vtools/tools/vgrainlineitem.cpp @@ -0,0 +1,125 @@ +/************************************************************************ + ** + ** @file vgrainlineitem.h + ** @author Bojan Kverh + ** @date September 10, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include + +#include +#include + +#include "vgrainlineitem.h" + +#define ARROW_ANGLE 0.5 +#define ARROW_LENGTH 0.05 +#define RECT_WIDTH 30 + +//--------------------------------------------------------------------------------------------------------------------- +VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) + :QGraphicsObject(pParent), m_eMode(mNormal), m_ptPos(QPointF(0, 0)), m_dRotation(0), m_dLength(0), + m_rectBoundingBox() +{ + m_rectBoundingBox.setTopLeft(QPointF(0, 0)); + m_rectBoundingBox.setSize(QSizeF(200, 200)); +} + +//--------------------------------------------------------------------------------------------------------------------- +VGrainlineItem::~VGrainlineItem() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget) +{ + Q_UNUSED(pOption); + Q_UNUSED(pWidget); + QColor clr = Qt::black; + pP->setPen(QPen(clr, 3)); + QPointF pt1 = m_ptPos; + QPointF pt2 = pt1; + + pP->setRenderHints(QPainter::Antialiasing); + pt2.setX(pt2.x() + m_dLength * cos(m_dRotation)); + pt2.setY(pt2.y() + m_dLength * sin(m_dRotation)); + pP->drawLine(pt1, pt2); + + QPolygonF poly; + poly << pt1; + QPointF ptA; + ptA.setX(pt1.x() + m_dLength*ARROW_LENGTH*cos(m_dRotation + ARROW_ANGLE)); + ptA.setY(pt1.y() + m_dLength*ARROW_LENGTH*sin(m_dRotation + ARROW_ANGLE)); + poly << ptA; + ptA.setX(pt1.x() + m_dLength*ARROW_LENGTH*cos(m_dRotation - ARROW_ANGLE)); + ptA.setY(pt1.y() + m_dLength*ARROW_LENGTH*sin(m_dRotation - ARROW_ANGLE)); + poly << ptA; + pP->setBrush(clr); + pP->drawPolygon(poly); + + poly.clear(); + poly << pt2; + ptA.setX(pt2.x() + m_dLength*ARROW_LENGTH*cos(M_PI + m_dRotation + ARROW_ANGLE)); + ptA.setY(pt2.y() + m_dLength*ARROW_LENGTH*sin(M_PI + m_dRotation + ARROW_ANGLE)); + poly << ptA; + ptA.setX(pt2.x() + m_dLength*ARROW_LENGTH*cos(M_PI + m_dRotation - ARROW_ANGLE)); + ptA.setY(pt2.y() + m_dLength*ARROW_LENGTH*sin(M_PI + m_dRotation - ARROW_ANGLE)); + poly << ptA; + pP->drawPolygon(poly); + + if (m_eMode != mNormal) + { + pP->setPen(QPen(clr, 2, Qt::DashLine)); + pP->setBrush(Qt::NoBrush); + poly.clear(); + ptA.setX(pt1.x() + RECT_WIDTH*cos(m_dRotation + M_PI/2)); + ptA.setY(pt1.y() + RECT_WIDTH*sin(m_dRotation + M_PI/2)); + poly << 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)); + poly << 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)); + poly << 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)); + poly << ptA; + pP->drawPolygon(poly); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength) +{ + m_ptPos = ptPos; + m_dRotation = qDegreesToRadians(dRotation); + m_dLength = dLength; + m_eMode = mMove; + update(m_rectBoundingBox); +} + +//--------------------------------------------------------------------------------------------------------------------- +QRectF VGrainlineItem::boundingRect() const +{ + return m_rectBoundingBox; +} diff --git a/src/libs/vtools/tools/vgrainlineitem.h b/src/libs/vtools/tools/vgrainlineitem.h new file mode 100644 index 000000000..0f090d2a1 --- /dev/null +++ b/src/libs/vtools/tools/vgrainlineitem.h @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @file vgrainlineitem.h + ** @author Bojan Kverh + ** @date September 10, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VGRAINLINEITEM_H +#define VGRAINLINEITEM_H + +#include + +#include "../vpatterndb/vgrainlinegeometry.h" + +class QGraphicsObject; +class QPainter; +class QStyleOptionGraphicsItem; +class QWidget; + +class VGrainlineItem : public QGraphicsObject +{ + Q_OBJECT + + enum Mode { + mNormal, + mMove + }; + +public: + explicit VGrainlineItem(QGraphicsItem* pParent = nullptr); + virtual ~VGrainlineItem(); + + void paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget); + void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength); + + QRectF boundingRect() const; + +private: + Mode m_eMode; + QPointF m_ptPos; + qreal m_dRotation; + qreal m_dLength; + QRectF m_rectBoundingBox; +}; + +#endif // VGRAINLINEITEM_H diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 7a491b4e6..01b2c8775 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vtextgraphicsitem.h + ** @file vtextgraphicsitem.cpp ** @author Bojan Kverh ** @date June 16, 2016 ** diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index c8ad14fa8..3f95a1ffc 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -89,6 +89,7 @@ #include "../vpatterndb/vdetail.h" #include "../vpatterndb/vpatterninfogeometry.h" #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/calculator.h" #include "../vmisc/def.h" #include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsview.h" @@ -146,7 +147,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem *parent) :VAbstractTool(doc, data, id), VNoBrushScalePathItem(parent), dialog(nullptr), sceneDetails(scene), drawName(drawName), seamAllowance(new VNoBrushScalePathItem(this)), dataLabel(new VTextGraphicsItem(this)), - patternInfo(new VTextGraphicsItem(this)) + patternInfo(new VTextGraphicsItem(this)), grainLine(new VGrainlineItem(this)) { VDetail detail = data->GetDetail(id); for (int i = 0; i< detail.CountNode(); ++i) @@ -206,6 +207,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdatePatternInfo); + connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateGrainline); connect(sceneDetails, &VMainGraphicsScene::DimensionsChanged, this, &VToolDetail::UpdateLabel); connect(sceneDetails, &VMainGraphicsScene::DimensionsChanged, this, &VToolDetail::UpdatePatternInfo); @@ -213,6 +215,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 UpdateLabel(); UpdatePatternInfo(); + UpdateGrainline(); } //--------------------------------------------------------------------------------------------------------------------- @@ -880,7 +883,46 @@ void VToolDetail::UpdatePatternInfo() } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VToolDetail::UpdateGrainline updates the grain line item + */ +void VToolDetail::UpdateGrainline() +{ + const VDetail detail = VAbstractTool::data.GetDetail(id); + const VGrainlineGeometry& geom = detail.GetGrainlineGeometry(); + if (geom.IsVisible() == true) + { + qreal dRotation; + qreal dLength; + try + { + QString qsFormula; + qsFormula = geom.GetRotation().replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + Calculator cal1; + dRotation = cal1.EvalFormula(VDataTool::data.PlainVariables(), qsFormula); + + qsFormula = geom.GetLength().replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + Calculator cal2; + dLength = cal2.EvalFormula(VDataTool::data.PlainVariables(), qsFormula); + } + catch(...) + { + grainLine->hide(); + return; + } + grainLine->UpdateGeometry(geom.GetPos(), dRotation, dLength); + grainLine->show(); + } + else + { + grainLine->hide(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveMoveDetail saves the move detail operation to the undo stack */ diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index b2b19e5ed..e189f1589 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -36,6 +36,7 @@ #include "../vwidgets/vnobrushscalepathitem.h" #include "vabstracttool.h" #include "vtextgraphicsitem.h" +#include "vgrainlineitem.h" class VMainGraphicsScene; class DialogTool; @@ -119,6 +120,7 @@ protected: protected slots: virtual void UpdateLabel(); virtual void UpdatePatternInfo(); + virtual void UpdateGrainline(); virtual void SaveMoveDetail(const QPointF &ptPos); virtual void SaveResizeDetail(qreal dLabelW, int iFontSize); virtual void SaveRotationDetail(qreal dRot); @@ -138,6 +140,7 @@ private: VNoBrushScalePathItem *seamAllowance; VTextGraphicsItem *dataLabel; VTextGraphicsItem *patternInfo; + VGrainlineItem *grainLine; VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 &id, const Source &typeCreation, VMainGraphicsScene *scene, const QString &drawName, QGraphicsItem * parent = nullptr); diff --git a/src/libs/vtools/vtools.pri b/src/libs/vtools/vtools.pri index acae2d114..ba301cfc1 100644 --- a/src/libs/vtools/vtools.pri +++ b/src/libs/vtools/vtools.pri @@ -10,3 +10,4 @@ HEADERS += \ $$PWD/stable.h win32-msvc*:SOURCES += $$PWD/stable.cpp + From 8e0dc15e25166490def902b0f18b437a57dab451 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 11 Sep 2016 12:18:09 +0200 Subject: [PATCH 06/19] Moving the grainline works now, but still has a few issues --HG-- branch : feature --- src/libs/vtools/tools/vgrainlineitem.cpp | 213 +++++++++++++++++--- src/libs/vtools/tools/vgrainlineitem.h | 17 +- src/libs/vtools/tools/vtextgraphicsitem.cpp | 9 +- src/libs/vtools/tools/vtooldetail.cpp | 21 ++ src/libs/vtools/tools/vtooldetail.h | 1 + 5 files changed, 231 insertions(+), 30 deletions(-) diff --git a/src/libs/vtools/tools/vgrainlineitem.cpp b/src/libs/vtools/tools/vgrainlineitem.cpp index e21fdffcb..8cc61c8d6 100644 --- a/src/libs/vtools/tools/vgrainlineitem.cpp +++ b/src/libs/vtools/tools/vgrainlineitem.cpp @@ -30,39 +30,59 @@ #include #include +#include +#include #include "vgrainlineitem.h" #define ARROW_ANGLE 0.5 #define ARROW_LENGTH 0.05 #define RECT_WIDTH 30 +#define ACTIVE_Z 10 +#define INACTIVE_Z 5 //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::VGrainlineItem constructor + * @param pParent pointer to the parent item + */ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) - :QGraphicsObject(pParent), m_eMode(mNormal), m_ptPos(QPointF(0, 0)), m_dRotation(0), m_dLength(0), - m_rectBoundingBox() + :QGraphicsObject(pParent), m_eMode(mNormal), m_dRotation(0), m_dLength(0), m_rectBoundingBox(), + m_polyBound(), m_ptStartPos(), m_ptStartMove() { - m_rectBoundingBox.setTopLeft(QPointF(0, 0)); - m_rectBoundingBox.setSize(QSizeF(200, 200)); + setAcceptHoverEvents(true); + Reset(); + UpdateRectangle(); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::~VGrainlineItem destructor + */ VGrainlineItem::~VGrainlineItem() {} //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::paint paints the item content + * @param pP pointer to the painter object + * @param pOption not used + * @param pWidget not used + */ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption, QWidget* pWidget) { Q_UNUSED(pOption); Q_UNUSED(pWidget); + pP->save(); QColor clr = Qt::black; pP->setPen(QPen(clr, 3)); - QPointF pt1 = m_ptPos; - QPointF pt2 = pt1; + QPointF pt1 = pos(); + QPointF pt2; + + pt2.setX(pt1.x() + m_dLength * cos(m_dRotation)); + pt2.setY(pt1.y() + m_dLength * sin(m_dRotation)); pP->setRenderHints(QPainter::Antialiasing); - pt2.setX(pt2.x() + m_dLength * cos(m_dRotation)); - pt2.setY(pt2.y() + m_dLength * sin(m_dRotation)); pP->drawLine(pt1, pt2); QPolygonF poly; @@ -91,35 +111,178 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption { pP->setPen(QPen(clr, 2, Qt::DashLine)); pP->setBrush(Qt::NoBrush); - poly.clear(); - ptA.setX(pt1.x() + RECT_WIDTH*cos(m_dRotation + M_PI/2)); - ptA.setY(pt1.y() + RECT_WIDTH*sin(m_dRotation + M_PI/2)); - poly << 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)); - poly << 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)); - poly << 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)); - poly << ptA; - pP->drawPolygon(poly); + pP->drawPolygon(m_polyBound); } + pP->restore(); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::UpdateGeometry updates the item with grainline parameters + * @param ptPos position of one grainline's end + * @param dRotation rotation of the grainline in [degrees] + * @param dLength length of the grainline in user's units + */ void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength) { - m_ptPos = ptPos; m_dRotation = qDegreesToRadians(dRotation); m_dLength = dLength; - m_eMode = mMove; - update(m_rectBoundingBox); + + setPos(ptPos); + UpdateRectangle(); + UpdateBox(); } //--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::boundingRect returns the bounding rect around the grainline + * @return bounding rect + */ QRectF VGrainlineItem::boundingRect() const { return m_rectBoundingBox; } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::Reset resets the item parameters. + */ +void VGrainlineItem::Reset() +{ + m_eMode = mNormal; + setZValue(INACTIVE_Z); + UpdateBox(); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::IsIdle returns the idle flag. + * @return true, if item mode is normal and false otherwise. + */ +bool VGrainlineItem::IsIdle() const +{ + return m_eMode == mNormal; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::IsContained checks, if both ends of the grainline, starting at pt, are contained in + * parent widget. + * @param pt starting point of the grainline. + * @return true, if both ends of the grainline, starting at pt, are contained in the parent widget and + * false otherwise. + */ +bool VGrainlineItem::IsContained(const QPointF& pt) const +{ + QRectF rectParent = parentItem()->boundingRect(); + if (rectParent.contains(pt) == false) + { + qDebug() << "First point out" << pt << rectParent; + return false; + } + QPointF ptA; + ptA.setX(pt.x() + m_dLength * cos(m_dRotation)); + ptA.setY(pt.y() + m_dLength * sin(m_dRotation)); + if (rectParent.contains(ptA) == false) + { + qDebug() << "Second point out" << ptA << rectParent; + } + return (rectParent.contains(ptA)); +} +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::mousePressEvent handles left button mouse press events + * @param pME pointer to QGraphicsSceneMouseEvent object + */ +void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) +{ + if (pME->button() == Qt::LeftButton) + { + m_eMode = mMove; + setZValue(ACTIVE_Z); + m_ptStartPos = pos(); + m_ptStartMove = pME->scenePos(); + UpdateBox(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::mouseMoveEvent handles mouse move events, making sure that the item is moved properly + * @param pME pointer to QGraphicsSceneMouseEvent object + */ +void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) +{ + if (m_eMode == mMove) + { + QPointF ptDiff = pME->scenePos() - m_ptStartMove; + QPointF pt = m_ptStartPos + ptDiff/2; + if (IsContained(pt) == true) + { + setPos(pt); + UpdateRectangle(); + UpdateBox(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::mouseReleaseEvent handles mouse release events and emits the proper signal if the item was + * moved + * @param pME pointer to QGraphicsSceneMouseEvent object + */ +void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) +{ + if (pME->button() == Qt::LeftButton) + { + if (m_eMode == mMove) + { + qreal dD = fabs(pME->scenePos().x() - m_ptStartMove.x()) + fabs(pME->scenePos().y() - m_ptStartMove.y()); + bool bShort = (dD < 2); + if (bShort == false) + { + emit SignalMoved(pos()); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::UpdateBox updates the item + */ +void VGrainlineItem::UpdateBox() +{ + update(m_rectBoundingBox); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::UpdateRectangle updates the polygon for the box around active item + * and the bounding rectangle + */ +void VGrainlineItem::UpdateRectangle() +{ + m_polyBound.clear(); + QPointF pt1 = pos(); + QPointF pt2; + + pt2.setX(pt1.x() + m_dLength * cos(m_dRotation)); + pt2.setY(pt1.y() + m_dLength * sin(m_dRotation)); + + 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_rectBoundingBox = m_polyBound.boundingRect(); +} diff --git a/src/libs/vtools/tools/vgrainlineitem.h b/src/libs/vtools/tools/vgrainlineitem.h index 0f090d2a1..0ffa0c653 100644 --- a/src/libs/vtools/tools/vgrainlineitem.h +++ b/src/libs/vtools/tools/vgrainlineitem.h @@ -55,13 +55,28 @@ public: void UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal dLength); QRectF boundingRect() const; + void Reset(); + bool IsIdle() const; + bool IsContained(const QPointF &pt) const; + +protected: + void mousePressEvent(QGraphicsSceneMouseEvent* pME); + void mouseMoveEvent(QGraphicsSceneMouseEvent* pME); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME); + void UpdateBox(); + void UpdateRectangle(); + +signals: + void SignalMoved(const QPointF& ptPos); private: Mode m_eMode; - QPointF m_ptPos; qreal m_dRotation; qreal m_dLength; QRectF m_rectBoundingBox; + QPolygonF m_polyBound; + QPointF m_ptStartPos; + QPointF m_ptStartMove; }; #endif // VGRAINLINEITEM_H diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 01b2c8775..bb73820c2 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -55,7 +55,8 @@ class VPatternPieceData; #define ROTATE_ARC 50 #define MIN_W 120 #define MIN_H 60 -#define TOP_Z 2 +#define INACTIVE_Z 2 +#define ACTIVE_Z 10 //--------------------------------------------------------------------------------------------------------------------- /** @@ -69,7 +70,7 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) { m_rectBoundingBox.setTopLeft(QPointF(0, 0)); SetSize(MIN_W, m_iMinH); - setZValue(TOP_Z); + setZValue(INACTIVE_Z); setAcceptHoverEvents(true); } @@ -173,7 +174,7 @@ void VTextGraphicsItem::Reset() m_eMode = mNormal; m_bReleased = false; Update(); - setZValue(TOP_Z); + setZValue(INACTIVE_Z); } //--------------------------------------------------------------------------------------------------------------------- @@ -399,7 +400,7 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) SetOverrideCursor(cursorArrowCloseHand, 1, 1); } // raise the label and redraw it - setZValue(TOP_Z + 1); + setZValue(ACTIVE_Z); UpdateBox(); } } diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 3f95a1ffc..8aae46e99 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -204,6 +204,8 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(patternInfo, &VTextGraphicsItem::SignalResized, this, &VToolDetail::SaveResizePattern); connect(patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationPattern); + connect(grainLine, &VGrainlineItem::SignalMoved, this, &VToolDetail::SaveMoveGrainline); + connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdatePatternInfo); @@ -1038,6 +1040,20 @@ void VToolDetail::SaveRotationPattern(qreal dRot) } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::SaveMoveGrainline(const QPointF& ptPos) +{ + VDetail oldDet = VAbstractTool::data.GetDetail(id); + VDetail newDet = oldDet; + newDet.GetGrainlineGeometry().SetPos(ptPos); + qDebug() << "******* new grainline pos" << ptPos; + + SaveDetailOptions* moveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); + moveCommand->setText(tr("move grainline")); + connect(moveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(moveCommand); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddNode add node to the file. @@ -1198,6 +1214,11 @@ void VToolDetail::ResetChildren(QGraphicsItem *pItem) { patternInfo->Reset(); } + VGrainlineItem* pGLI = dynamic_cast(pItem); + if (pGLI != grainLine) + { + grainLine->Reset(); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index e189f1589..0f2991406 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -127,6 +127,7 @@ protected slots: virtual void SaveMovePattern(const QPointF& ptPos); virtual void SaveResizePattern(qreal dLabelW, int iFontSize); virtual void SaveRotationPattern(qreal dRot); + virtual void SaveMoveGrainline(const QPointF& ptPos); private: Q_DISABLE_COPY(VToolDetail) From de799569ef1142552e2704e2d5f5979811b9dee2 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Wed, 14 Sep 2016 01:15:01 +0200 Subject: [PATCH 07/19] Fixed moving and scaling grainline and ensured that it stays in bounds --HG-- branch : feature --- src/libs/vtools/tools/vgrainlineitem.cpp | 138 +++++++++++++++++------ src/libs/vtools/tools/vgrainlineitem.h | 4 +- src/libs/vtools/tools/vtooldetail.cpp | 16 ++- 3 files changed, 121 insertions(+), 37 deletions(-) diff --git a/src/libs/vtools/tools/vgrainlineitem.cpp b/src/libs/vtools/tools/vgrainlineitem.cpp index 8cc61c8d6..684944a08 100644 --- a/src/libs/vtools/tools/vgrainlineitem.cpp +++ b/src/libs/vtools/tools/vgrainlineitem.cpp @@ -31,12 +31,15 @@ #include #include #include +#include #include +#include "../vmisc/def.h" + #include "vgrainlineitem.h" -#define ARROW_ANGLE 0.5 -#define ARROW_LENGTH 0.05 +#define ARROW_ANGLE 0.35 +#define ARROW_LENGTH 15 #define RECT_WIDTH 30 #define ACTIVE_Z 10 #define INACTIVE_Z 5 @@ -47,9 +50,10 @@ * @param pParent pointer to the parent item */ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) - :QGraphicsObject(pParent), m_eMode(mNormal), m_dRotation(0), m_dLength(0), m_rectBoundingBox(), - m_polyBound(), m_ptStartPos(), m_ptStartMove() + :QGraphicsObject(pParent), m_eMode(VGrainlineItem::mNormal), m_dRotation(0), m_dLength(0), m_rectBoundingBox(), + m_polyBound(), m_ptStartPos(), m_ptStartMove(), m_dScale(1) { + m_rectBoundingBox.setTopLeft(QPointF(0, 0)); setAcceptHoverEvents(true); Reset(); UpdateRectangle(); @@ -76,34 +80,37 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption pP->save(); QColor clr = Qt::black; pP->setPen(QPen(clr, 3)); - QPointF pt1 = pos(); + QPointF pt1(0, 0); QPointF pt2; pt2.setX(pt1.x() + m_dLength * cos(m_dRotation)); pt2.setY(pt1.y() + m_dLength * sin(m_dRotation)); pP->setRenderHints(QPainter::Antialiasing); + // line pP->drawLine(pt1, pt2); + // first arrow QPolygonF poly; poly << pt1; QPointF ptA; - ptA.setX(pt1.x() + m_dLength*ARROW_LENGTH*cos(m_dRotation + ARROW_ANGLE)); - ptA.setY(pt1.y() + m_dLength*ARROW_LENGTH*sin(m_dRotation + ARROW_ANGLE)); + qreal dArrLen = ARROW_LENGTH*m_dScale; + ptA.setX(pt1.x() + dArrLen*cos(m_dRotation + ARROW_ANGLE)); + ptA.setY(pt1.y() + dArrLen*sin(m_dRotation + ARROW_ANGLE)); poly << ptA; - ptA.setX(pt1.x() + m_dLength*ARROW_LENGTH*cos(m_dRotation - ARROW_ANGLE)); - ptA.setY(pt1.y() + m_dLength*ARROW_LENGTH*sin(m_dRotation - ARROW_ANGLE)); + ptA.setX(pt1.x() + dArrLen*cos(m_dRotation - ARROW_ANGLE)); + ptA.setY(pt1.y() + dArrLen*sin(m_dRotation - ARROW_ANGLE)); poly << ptA; pP->setBrush(clr); pP->drawPolygon(poly); - + // second arrow poly.clear(); poly << pt2; - ptA.setX(pt2.x() + m_dLength*ARROW_LENGTH*cos(M_PI + m_dRotation + ARROW_ANGLE)); - ptA.setY(pt2.y() + m_dLength*ARROW_LENGTH*sin(M_PI + m_dRotation + ARROW_ANGLE)); + ptA.setX(pt2.x() + dArrLen*cos(M_PI + m_dRotation + ARROW_ANGLE)); + ptA.setY(pt2.y() + dArrLen*sin(M_PI + m_dRotation + ARROW_ANGLE)); poly << ptA; - ptA.setX(pt2.x() + m_dLength*ARROW_LENGTH*cos(M_PI + m_dRotation - ARROW_ANGLE)); - ptA.setY(pt2.y() + m_dLength*ARROW_LENGTH*sin(M_PI + m_dRotation - ARROW_ANGLE)); + ptA.setX(pt2.x() + dArrLen*cos(M_PI + m_dRotation - ARROW_ANGLE)); + ptA.setY(pt2.y() + dArrLen*sin(M_PI + m_dRotation - ARROW_ANGLE)); poly << ptA; pP->drawPolygon(poly); @@ -111,6 +118,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption { pP->setPen(QPen(clr, 2, Qt::DashLine)); pP->setBrush(Qt::NoBrush); + // bounding polygon pP->drawPolygon(m_polyBound); } pP->restore(); @@ -128,7 +136,15 @@ void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal m_dRotation = qDegreesToRadians(dRotation); m_dLength = dLength; - setPos(ptPos); + qreal dX; + qreal dY; + QPointF pt = ptPos; + if (IsContained(pt, dX, dY) == false) + { + pt.setX(pt.x() + dX); + pt.setY(pt.y() + dY); + } + setPos(pt); UpdateRectangle(); UpdateBox(); } @@ -169,26 +185,74 @@ bool VGrainlineItem::IsIdle() const * @brief VGrainlineItem::IsContained checks, if both ends of the grainline, starting at pt, are contained in * parent widget. * @param pt starting point of the grainline. + * @param dX horizontal translation needed to put the arrow inside parent item + * @param dY vertical translation needed to put the arrow inside parent item * @return true, if both ends of the grainline, starting at pt, are contained in the parent widget and * false otherwise. */ -bool VGrainlineItem::IsContained(const QPointF& pt) const +bool VGrainlineItem::IsContained(const QPointF& pt, qreal &dX, qreal &dY) const { + dX = 0; + dY = 0; + QPointF apt[2]; + apt[0] = pt; + apt[1].setX(pt.x() + m_dLength * cos(m_dRotation)); + apt[1].setY(pt.y() + m_dLength * sin(m_dRotation)); + // single point differences + qreal dPtX; + qreal dPtY; + bool bInside = true; + QRectF rectParent = parentItem()->boundingRect(); - if (rectParent.contains(pt) == false) + for (int i = 0; i < 2; ++i) { - qDebug() << "First point out" << pt << rectParent; - return false; + dPtX = 0; + dPtY = 0; + if (rectParent.contains(apt[i]) == false) + { + if (apt[i].x() < rectParent.left()) + { + dPtX = rectParent.left() - apt[i].x(); + } + else if (apt[i].x() > rectParent.right()) + { + dPtX = rectParent.right() - apt[i].x(); + } + if (apt[i].y() < rectParent.top()) + { + dPtY = rectParent.top() - apt[i].y(); + } + else if (apt[i].y() > rectParent.bottom()) + { + dPtY = rectParent.bottom() - apt[i].y(); + } + + if (fabs(dPtX) > fabs(dX)) + { + dX = dPtX; + } + if (fabs(dPtY) > fabs(dY)) + { + dY = dPtY; + } + + bInside = false; + } } - QPointF ptA; - ptA.setX(pt.x() + m_dLength * cos(m_dRotation)); - ptA.setY(pt.y() + m_dLength * sin(m_dRotation)); - if (rectParent.contains(ptA) == false) - { - qDebug() << "Second point out" << ptA << rectParent; - } - return (rectParent.contains(ptA)); + return bInside; } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::SetScale sets the scale for keeping the arrows of constant size + * @param dScale scale factor + */ +void VGrainlineItem::SetScale(qreal dScale) +{ + m_dScale = dScale; + UpdateBox(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VGrainlineItem::mousePressEvent handles left button mouse press events @@ -203,6 +267,7 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) m_ptStartPos = pos(); m_ptStartMove = pME->scenePos(); UpdateBox(); + SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } @@ -216,13 +281,17 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) if (m_eMode == mMove) { QPointF ptDiff = pME->scenePos() - m_ptStartMove; - QPointF pt = m_ptStartPos + ptDiff/2; - if (IsContained(pt) == true) + QPointF pt = m_ptStartPos + ptDiff; + qreal dX; + qreal dY; + if (IsContained(pt, dX, dY) == false) { - setPos(pt); - UpdateRectangle(); - UpdateBox(); + pt.setX(pt.x() + dX); + pt.setY(pt.y() + dY); } + setPos(pt); + UpdateRectangle(); + UpdateBox(); } } @@ -245,6 +314,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) emit SignalMoved(pos()); } } + RestoreOverrideCursor(cursorArrowCloseHand); } } @@ -265,7 +335,7 @@ void VGrainlineItem::UpdateBox() void VGrainlineItem::UpdateRectangle() { m_polyBound.clear(); - QPointF pt1 = pos(); + QPointF pt1(0, 0); QPointF pt2; pt2.setX(pt1.x() + m_dLength * cos(m_dRotation)); @@ -285,4 +355,6 @@ void VGrainlineItem::UpdateRectangle() ptA.setY(pt2.y() + RECT_WIDTH*sin(m_dRotation + M_PI/2)); m_polyBound << ptA; m_rectBoundingBox = m_polyBound.boundingRect(); + setTransformOriginPoint(m_rectBoundingBox.center()); + prepareGeometryChange(); } diff --git a/src/libs/vtools/tools/vgrainlineitem.h b/src/libs/vtools/tools/vgrainlineitem.h index 0ffa0c653..9475a46c9 100644 --- a/src/libs/vtools/tools/vgrainlineitem.h +++ b/src/libs/vtools/tools/vgrainlineitem.h @@ -57,7 +57,8 @@ public: QRectF boundingRect() const; void Reset(); bool IsIdle() const; - bool IsContained(const QPointF &pt) const; + bool IsContained(const QPointF &pt, qreal &dX, qreal &dY) const; + void SetScale(qreal dScale); protected: void mousePressEvent(QGraphicsSceneMouseEvent* pME); @@ -77,6 +78,7 @@ private: QPolygonF m_polyBound; QPointF m_ptStartPos; QPointF m_ptStartMove; + qreal m_dScale; }; #endif // VGRAINLINEITEM_H diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 8aae46e99..58332c6e3 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -408,11 +408,20 @@ void VToolDetail::FullUpdateFromGuiOk(int result) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief VToolDetail::paint draws a bounding box around detail, if one of its text items is not idle. + * @brief VToolDetail::paint draws a bounding box around detail, if one of its text or grainline items is not idle. */ void VToolDetail::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if (dataLabel->IsIdle() == false || patternInfo->IsIdle() == false) + if (scene()->views().count() > 0) + { + QPoint pt0 = scene()->views().at(0)->mapFromScene(0, 0); + QPoint pt = scene()->views().at(0)->mapFromScene(0, 100); + qreal dScale = qSqrt(QPoint::dotProduct(pt - pt0, pt - pt0)); + grainLine->SetScale(100/dScale); + qDebug() << "SCALE" << dScale << 10/dScale; + } + + if (dataLabel->IsIdle() == false || patternInfo->IsIdle() == false || grainLine->IsIdle() == false) { painter->save(); painter->setPen(QPen(Qt::black, 3, Qt::DashLine)); @@ -915,7 +924,8 @@ void VToolDetail::UpdateGrainline() grainLine->hide(); return; } - grainLine->UpdateGeometry(geom.GetPos(), dRotation, dLength); + + grainLine->UpdateGeometry(geom.GetPos(), dRotation, ToPixel(dLength, *VDataTool::data.GetPatternUnit())); grainLine->show(); } else From f89b5a8a10f5db3f598d7218df69abf0bd9b05b0 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 20 Sep 2016 19:42:27 +0200 Subject: [PATCH 08/19] Fixed schema.qrc --HG-- branch : feature --- src/libs/ifc/schema.qrc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index c5e1855d9..85c0a825d 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -28,7 +28,6 @@ schema/individual_measurements/v0.3.1.xsd schema/individual_measurements/v0.3.2.xsd schema/individual_measurements/v0.3.3.xsd - schema/pattern/v0.3.5.xsd schema/pattern/v0.3.6.xsd From 85b8cb2bd7ed701106da81749386e9aa4643b805 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 27 Sep 2016 22:09:49 +0200 Subject: [PATCH 09/19] Fixes compilation error due to unrecognized qIsNaN --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogdetail.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index c9879dcf8..5c096c2cf 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -28,6 +28,7 @@ #include "dialogdetail.h" +#include #include #include #include From 083b2035afa9db1fca1211102a32284dcdc9fb49 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 29 Sep 2016 01:39:50 +0200 Subject: [PATCH 10/19] Hopefully this commit solves the #551 issue --HG-- branch : feature --- src/libs/vlayout/vtextmanager.cpp | 21 +++++++-- src/libs/vlayout/vtextmanager.h | 2 +- src/libs/vtools/tools/vtextgraphicsitem.cpp | 50 ++++++++++++++++----- src/libs/vtools/tools/vtextgraphicsitem.h | 2 +- src/libs/vtools/tools/vtooldetail.cpp | 2 +- 5 files changed, 60 insertions(+), 17 deletions(-) diff --git a/src/libs/vlayout/vtextmanager.cpp b/src/libs/vlayout/vtextmanager.cpp index 936a1a95e..b375e3c73 100644 --- a/src/libs/vlayout/vtextmanager.cpp +++ b/src/libs/vlayout/vtextmanager.cpp @@ -159,13 +159,18 @@ const TextLine& VTextManager::GetLine(int i) const * @param fW rectangle width * @param fH rectangle height * @param iFontSize base font size + * @param fMinW minimal required rectangle width to fit the text + * @param fMinH minimal required rectangle height to fit the text * @return true, if rectangle of size (fW, fH) */ -bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) +bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize, qreal& fMinW, qreal& fMinH) { m_liOutput.clear(); QFont fnt = m_font; int iY = 0; + fMinW = fW; + fMinH = fH; + for (int i = 0; i < m_liLines.count(); ++i) { const TextLine& tl = m_liLines.at(i); @@ -180,6 +185,7 @@ bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) // check if every line fits within the label width if (fm.width(qslLines[iL]) + iHorSp > fW) { + fMinW = fm.width(qslLines[iL]) + iHorSp; return false; } tlOut.m_qsText = qslLines[iL]; @@ -187,7 +193,11 @@ bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) iY += tlOut.m_iHeight + GetSpacing(); } } - return iY < fH; + if (iY > fH) + { + fMinH = iY; + } + return iY <= fH; } //--------------------------------------------------------------------------------------------------------------------- @@ -200,11 +210,14 @@ bool VTextManager::IsBigEnough(qreal fW, qreal fH, int iFontSize) void VTextManager::FitFontSize(qreal fW, qreal fH) { int iFontSize = GetFont().pixelSize(); - while (IsBigEnough(fW, fH, iFontSize) == true && iFontSize <= MAX_FONT_SIZE) + qreal fMinW; + qreal fMinH; + + while (IsBigEnough(fW, fH, iFontSize, fMinW, fMinH) == true && iFontSize <= MAX_FONT_SIZE) { ++iFontSize; } - while (IsBigEnough(fW, fH, iFontSize) == false && iFontSize >= MIN_FONT_SIZE) + while (IsBigEnough(fW, fH, iFontSize, fMinW, fMinH) == false && iFontSize >= MIN_FONT_SIZE) { --iFontSize; } diff --git a/src/libs/vlayout/vtextmanager.h b/src/libs/vlayout/vtextmanager.h index 1e3d2bf77..98d41aeb1 100644 --- a/src/libs/vlayout/vtextmanager.h +++ b/src/libs/vlayout/vtextmanager.h @@ -82,7 +82,7 @@ public: int GetCount() const; int GetSourceLineCount() const; const TextLine& GetLine(int i) const; - bool IsBigEnough(qreal fW, qreal fH, int iFontSize); + bool IsBigEnough(qreal fW, qreal fH, int iFontSize, qreal& fMinW, qreal& fMinH); void FitFontSize(qreal fW, qreal fH); void Update(const QString& qsName, const VPatternPieceData& data); void Update(const VAbstractPattern* pDoc, qreal dSize, qreal dHeight); diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index bb73820c2..4fb029650 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -196,13 +196,21 @@ bool VTextGraphicsItem::IsIdle() const void VTextGraphicsItem::AddLine(const TextLine& tl) { m_tm.AddLine(tl); - while (m_tm.IsBigEnough(MIN_W, m_iMinH, MIN_FONT_SIZE) == false) + qreal fW = MIN_W; + qreal fH = m_iMinH; + qreal fMinW; + qreal fMinH; + while (m_tm.IsBigEnough(fW, fH, MIN_FONT_SIZE, fMinW, fMinH) == false) { - m_iMinH += 5; + SetSize(fMinW, fMinH); + fW = m_rectBoundingBox.width(); + fH = m_rectBoundingBox.height(); } - if (m_rectBoundingBox.height() < m_iMinH) + qreal dX; + qreal dY; + if (IsContained(m_rectBoundingBox, rotation(), dX, dY) == false) { - SetSize(m_rectBoundingBox.width(), m_iMinH); + setPos(m_rectBoundingBox.left() + dX, m_rectBoundingBox.top() + dY); } } @@ -259,11 +267,11 @@ void VTextGraphicsItem::SetSize(qreal fW, qreal fH) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief VTextGraphicsItem::Update sets the correct font size and redraws the label + * @brief VTextGraphicsItem::Update sets the correct size and font size and redraws the label */ void VTextGraphicsItem::Update() { - UpdateFont(); + CorrectLabel(); UpdateBox(); } @@ -577,19 +585,41 @@ void VTextGraphicsItem::UpdateBox() * @brief VTextGraphicsItem::UpdateFont sets the text font size, so that the entire text will * just fit into the label bounding box */ -void VTextGraphicsItem::UpdateFont() +void VTextGraphicsItem::CorrectLabel() { int iFS = m_tm.GetFont().pixelSize(); + qreal fMinW; + qreal fMinH; // increase the font size until the bounding rect is not big enough - while (iFS < MAX_FONT_SIZE && m_tm.IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS) == true) + while ( + iFS < MAX_FONT_SIZE && + m_tm.IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS, fMinW, fMinH) == true + ) { ++iFS; } // decrease the font size until the bounding rect is big enough - while (iFS >= MIN_FONT_SIZE && m_tm.IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS) == false) + while (m_tm.IsBigEnough(m_rectBoundingBox.width(), m_rectBoundingBox.height(), iFS, fMinW, fMinH) == false) { - --iFS; + if (iFS > MIN_FONT_SIZE) + { + --iFS; + } + else + { + SetSize(fMinW, fMinH); + } + } + qreal dX; + qreal dY; + QRectF rectBB; + rectBB.setTopLeft(pos()); + rectBB.setSize(m_rectBoundingBox.size()); + if (IsContained(rectBB, rotation(), dX, dY) == false) + { + // put the label inside the pattern + setPos(pos().x() + dX, pos().y() + dY); } m_tm.SetFontSize(iFS); UpdateBox(); diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index fdd451820..88e0eb460 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -98,7 +98,7 @@ protected: void hoverMoveEvent(QGraphicsSceneHoverEvent* pHE); void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE); void UpdateBox(); - void UpdateFont(); + void CorrectLabel(); double GetAngle(QPointF pt) const; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 08290fdb0..8c0c03ac6 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -420,7 +420,7 @@ void VToolDetail::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio QPoint pt = scene()->views().at(0)->mapFromScene(0, 100); qreal dScale = qSqrt(QPoint::dotProduct(pt - pt0, pt - pt0)); grainLine->SetScale(100/dScale); - qDebug() << "SCALE" << dScale << 10/dScale; + //qDebug() << "SCALE" << dScale << 10/dScale; } if (dataLabel->IsIdle() == false || patternInfo->IsIdle() == false || grainLine->IsIdle() == false) From 60462bc303a4aacca518c7eef6c131173c037906 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 29 Sep 2016 02:13:18 +0200 Subject: [PATCH 11/19] Fixed some code style and replaced some code with more appropriate one according to general recommendations --HG-- branch : feature --- src/libs/ifc/schema.qrc | 2 +- src/libs/vpatterndb/vgrainlinegeometry.cpp | 4 ++-- src/libs/vpatterndb/vgrainlinegeometry.h | 4 ++-- src/libs/vtools/dialogs/tools/dialogdetail.cpp | 2 +- src/libs/vtools/tools/tools.pri | 12 ++++++------ src/libs/vtools/tools/vgrainlineitem.cpp | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/libs/ifc/schema.qrc b/src/libs/ifc/schema.qrc index 85c0a825d..6a0edbcae 100644 --- a/src/libs/ifc/schema.qrc +++ b/src/libs/ifc/schema.qrc @@ -19,6 +19,7 @@ schema/pattern/v0.3.3.xsd schema/pattern/v0.3.4.xsd schema/pattern/v0.3.5.xsd + schema/pattern/v0.3.6.xsd schema/standard_measurements/v0.3.0.xsd schema/standard_measurements/v0.4.0.xsd schema/standard_measurements/v0.4.1.xsd @@ -28,6 +29,5 @@ schema/individual_measurements/v0.3.1.xsd schema/individual_measurements/v0.3.2.xsd schema/individual_measurements/v0.3.3.xsd - schema/pattern/v0.3.6.xsd diff --git a/src/libs/vpatterndb/vgrainlinegeometry.cpp b/src/libs/vpatterndb/vgrainlinegeometry.cpp index fb519bf84..860ee5321 100644 --- a/src/libs/vpatterndb/vgrainlinegeometry.cpp +++ b/src/libs/vpatterndb/vgrainlinegeometry.cpp @@ -64,7 +64,7 @@ QString VGrainlineGeometry::GetLength() const //--------------------------------------------------------------------------------------------------------------------- -void VGrainlineGeometry::SetLength(QString qsLen) +void VGrainlineGeometry::SetLength(const QString& qsLen) { m_qsLength = qsLen; } @@ -78,7 +78,7 @@ QString VGrainlineGeometry::GetRotation() const //--------------------------------------------------------------------------------------------------------------------- -void VGrainlineGeometry::SetRotation(QString qsRot) +void VGrainlineGeometry::SetRotation(const QString& qsRot) { m_qsRotation = qsRot; } diff --git a/src/libs/vpatterndb/vgrainlinegeometry.h b/src/libs/vpatterndb/vgrainlinegeometry.h index d4a2f8fff..0b27c3adf 100644 --- a/src/libs/vpatterndb/vgrainlinegeometry.h +++ b/src/libs/vpatterndb/vgrainlinegeometry.h @@ -48,9 +48,9 @@ public: QPointF GetPos() const; void SetPos(const QPointF& ptPos); QString GetLength() const; - void SetLength(QString qsLen); + void SetLength(const QString& qsLen); QString GetRotation() const; - void SetRotation(QString qsRot); + void SetRotation(const QString& qsRot); bool IsVisible() const; void SetVisible(bool bVisible); diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 5c096c2cf..6240d5545 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -830,7 +830,7 @@ void DialogDetail::ClearFields() //--------------------------------------------------------------------------------------------------------------------- void DialogDetail::SetValue(QObject *pobjSender) { - QLineEdit* pleSender = dynamic_cast(pobjSender); + QLineEdit* pleSender = qobject_cast(pobjSender); SCASSERT(pleSender != 0); QString qsFormula = pleSender->text().simplified(); diff --git a/src/libs/vtools/tools/tools.pri b/src/libs/vtools/tools/tools.pri index 833e3d73d..57d4bb1a3 100644 --- a/src/libs/vtools/tools/tools.pri +++ b/src/libs/vtools/tools/tools.pri @@ -50,10 +50,10 @@ HEADERS += \ $$PWD/drawTools/toolpoint/toolsinglepoint/vtoolpointofintersectioncurves.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezier.h \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.h \ - $$PWD/drawTools/operation/vtoolrotation.h \ - $$PWD/vtextgraphicsitem.h \ - $$PWD/vgrainlineitem.h \ - $$PWD/drawTools/operation/flipping/vtoolflippingbyline.h \ + $$PWD/drawTools/operation/vtoolrotation.h \ + $$PWD/vtextgraphicsitem.h \ + $$PWD/vgrainlineitem.h \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyline.h \ $$PWD/drawTools/operation/vabstractoperation.h \ $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.h \ $$PWD/drawTools/operation/flipping/vabstractflipping.h @@ -106,8 +106,8 @@ SOURCES += \ $$PWD/drawTools/toolcurve/vtoolcubicbezierpath.cpp \ $$PWD/drawTools/operation/vtoolrotation.cpp \ $$PWD/vtextgraphicsitem.cpp \ - $$PWD/vgrainlineitem.cpp \ - $$PWD/drawTools/operation/flipping/vtoolflippingbyline.cpp \ + $$PWD/vgrainlineitem.cpp \ + $$PWD/drawTools/operation/flipping/vtoolflippingbyline.cpp \ $$PWD/drawTools/operation/vabstractoperation.cpp \ $$PWD/drawTools/operation/flipping/vtoolflippingbyaxis.cpp \ $$PWD/drawTools/operation/flipping/vabstractflipping.cpp diff --git a/src/libs/vtools/tools/vgrainlineitem.cpp b/src/libs/vtools/tools/vgrainlineitem.cpp index 684944a08..d0dbc0a83 100644 --- a/src/libs/vtools/tools/vgrainlineitem.cpp +++ b/src/libs/vtools/tools/vgrainlineitem.cpp @@ -29,12 +29,12 @@ #include #include -#include #include #include #include #include "../vmisc/def.h" +#include "../vmisc/vmath.h" #include "vgrainlineitem.h" From 3bc3c4bec3264b0a15030ef7172e754f3a49a4aa Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 4 Oct 2016 02:07:58 +0200 Subject: [PATCH 12/19] Fixed the grainline formulas editing --HG-- branch : feature --- src/libs/vpatterndb/vgrainlinegeometry.cpp | 2 +- .../vtools/dialogs/tools/dialogdetail.cpp | 56 ++-- src/libs/vtools/dialogs/tools/dialogdetail.h | 6 +- src/libs/vtools/dialogs/tools/dialogdetail.ui | 293 ++++++++++++------ 4 files changed, 237 insertions(+), 120 deletions(-) diff --git a/src/libs/vpatterndb/vgrainlinegeometry.cpp b/src/libs/vpatterndb/vgrainlinegeometry.cpp index 860ee5321..336d5da76 100644 --- a/src/libs/vpatterndb/vgrainlinegeometry.cpp +++ b/src/libs/vpatterndb/vgrainlinegeometry.cpp @@ -33,7 +33,7 @@ //--------------------------------------------------------------------------------------------------------------------- VGrainlineGeometry::VGrainlineGeometry() - :m_ptPos(0, 0), m_qsLength(), m_qsRotation(), m_bVisible(true) + :m_ptPos(0, 0), m_qsLength(), m_qsRotation(), m_bVisible(false) {} //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index 6240d5545..d6cc233ce 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -79,7 +79,8 @@ class QWidget; */ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(), detail(VDetail()), supplement(true), closed(true), flagWidth(true), - m_bAddMode(true), m_qslMaterials(), m_qslPlacements(), m_conMCP(), m_oldData(), m_oldGeom(), m_oldGrainline() + m_bAddMode(true), m_qslMaterials(), m_qslPlacements(), m_conMCP(), m_oldData(), m_oldGeom(), m_oldGrainline(), + m_iRotBaseHeight(0), m_iLenBaseHeight(0) { ui.setupUi(this); @@ -158,13 +159,19 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge connect(ui.checkBoxGrainline, &QCheckBox::toggled, this, &DialogDetail::EnableGrainlineRotation); connect(ui.pushButtonRot, &QPushButton::clicked, this, &DialogDetail::EditFormula); connect(ui.pushButtonLen, &QPushButton::clicked, this, &DialogDetail::EditFormula); - connect(ui.lineEditLenFormula, &QLineEdit::textChanged, this, &DialogDetail::UpdateValue); - connect(ui.lineEditRotFormula, &QLineEdit::textChanged, this, &DialogDetail::UpdateValue); + connect(ui.lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValue); + connect(ui.lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValue); + + connect(ui.pushButtonShowRot, &QPushButton::clicked, this, &DialogDetail::DeployRotation); + connect(ui.pushButtonShowLen, &QPushButton::clicked, this, &DialogDetail::DeployLength); SetAddMode(); EnableGrainlineRotation(); ui.tabWidget->setCurrentIndex(0); + + m_iRotBaseHeight = ui.lineEditRotFormula->height(); + m_iLenBaseHeight = ui.lineEditLenFormula->height(); } //--------------------------------------------------------------------------------------------------------------------- @@ -479,8 +486,8 @@ VDetail DialogDetail::CreateDetail() const detail.GetGrainlineGeometry().SetVisible(ui.checkBoxGrainline->isChecked()); if (ui.checkBoxGrainline->isChecked() == true) { - detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->text()); - detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->text()); + detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->toPlainText()); + detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->toPlainText()); } return detail; } @@ -553,8 +560,8 @@ void DialogDetail::setDetail(const VDetail &value) UpdateList(); ui.checkBoxGrainline->setChecked(detail.GetGrainlineGeometry().IsVisible()); - ui.lineEditRotFormula->setText(detail.GetGrainlineGeometry().GetRotation()); - ui.lineEditLenFormula->setText(detail.GetGrainlineGeometry().GetLength()); + ui.lineEditRotFormula->setPlainText(detail.GetGrainlineGeometry().GetRotation()); + ui.lineEditLenFormula->setPlainText(detail.GetGrainlineGeometry().GetLength()); m_oldData = detail.GetPatternPieceData(); m_oldGeom = detail.GetPatternInfo(); @@ -830,10 +837,10 @@ void DialogDetail::ClearFields() //--------------------------------------------------------------------------------------------------------------------- void DialogDetail::SetValue(QObject *pobjSender) { - QLineEdit* pleSender = qobject_cast(pobjSender); + QPlainTextEdit* pleSender = qobject_cast(pobjSender); SCASSERT(pleSender != 0); - QString qsFormula = pleSender->text().simplified(); + QString qsFormula = pleSender->toPlainText().simplified(); Calculator cal; QString qsVal; try @@ -856,18 +863,15 @@ void DialogDetail::SetValue(QObject *pobjSender) qsVal.clear(); } - QLineEdit* pleVal; QLabel* plbVal; QString qsUnit; if (pobjSender == ui.lineEditLenFormula) { - pleVal = ui.lineEditLenValue; plbVal = ui.labelLen; qsUnit = " " + VDomDocument::UnitsToStr(qApp->patternUnit()); } else if (pobjSender == ui.lineEditRotFormula) { - pleVal = ui.lineEditRotValue; plbVal = ui.labelRot; QChar ch(0x00b0); qsUnit = ch; @@ -882,7 +886,6 @@ void DialogDetail::SetValue(QObject *pobjSender) { qsVal += qsUnit; } - pleVal->setText(qsVal); plbVal->setText(qsVal); } @@ -936,18 +939,18 @@ void DialogDetail::SetEditMode() //--------------------------------------------------------------------------------------------------------------------- void DialogDetail::EnableGrainlineRotation() { - ui.lineEditRotValue->setEnabled(ui.checkBoxGrainline->isChecked()); ui.lineEditRotFormula->setEnabled(ui.checkBoxGrainline->isChecked()); - ui.lineEditLenValue->setEnabled(ui.checkBoxGrainline->isChecked()); ui.lineEditLenFormula->setEnabled(ui.checkBoxGrainline->isChecked()); ui.pushButtonRot->setEnabled(ui.checkBoxGrainline->isChecked()); ui.pushButtonLen->setEnabled(ui.checkBoxGrainline->isChecked()); + ui.pushButtonShowLen->setEnabled(ui.checkBoxGrainline->isChecked()); + ui.pushButtonShowRot->setEnabled(ui.checkBoxGrainline->isChecked()); } //--------------------------------------------------------------------------------------------------------------------- void DialogDetail::EditFormula() { - QLineEdit* pleFormula; + QPlainTextEdit* pleFormula; bool bCheckZero; if (sender() == ui.pushButtonLen) @@ -967,20 +970,33 @@ void DialogDetail::EditFormula() } DialogEditWrongFormula dlg(data, NULL_ID, this); - dlg.SetFormula(pleFormula->text()); + dlg.SetFormula(pleFormula->toPlainText()); dlg.setCheckZero(bCheckZero); if (dlg.exec() == true) { QString qsFormula = dlg.GetFormula(); qsFormula.replace("\n", " "); - pleFormula->setText(qsFormula); + pleFormula->setPlainText(qsFormula); SetValue(pleFormula); } } //--------------------------------------------------------------------------------------------------------------------- -void DialogDetail::UpdateValue(const QString& qsText) +void DialogDetail::UpdateValue() { - Q_UNUSED(qsText); SetValue(sender()); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::DeployRotation() +{ + DeployFormula(ui.lineEditRotFormula, ui.pushButtonShowRot, m_iRotBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogDetail::DeployLength() +{ + DeployFormula(ui.lineEditLenFormula, ui.pushButtonShowLen, m_iLenBaseHeight); +} + +//--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index bb2cfd813..b96263334 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -109,6 +109,8 @@ private: VPatternPieceData m_oldData; VPatternInfoGeometry m_oldGeom; VGrainlineGeometry m_oldGrainline; + int m_iRotBaseHeight; + int m_iLenBaseHeight; bool DetailIsValid() const; @@ -132,7 +134,9 @@ private slots: void SetEditMode(); void EnableGrainlineRotation(); void EditFormula(); - void UpdateValue(const QString& qsText); + void UpdateValue(); + void DeployRotation(); + void DeployLength(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index 555100038..ef696c8e6 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -535,65 +535,40 @@ Grainline - + - 10 - 10 - 361 - 201 + 20 + 20 + 351 + 41 - - + + Grainline visible - - - - - Liberation Sans - 10 - 75 - true - - - - Length - - - - - - - - - - - - - - Value - - - - - - - Value - - - - + + + + + + 20 + 70 + 351 + 41 + + + + - Liberation Sans - 10 + 11 75 true @@ -603,78 +578,201 @@ - - - - Formula + + + + Qt::Horizontal - - - - - - + + + 40 + 20 + - + - - - - Formula - - - - + - - - 0 - 0 - + + + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 87 + 0 + - + + + + + + 20 + 120 + 351 + 41 + + + + + + + + 16777215 + 28 + + + + + + + + + + + + + + + + + + + + 20 + 180 + 351 + 41 + + + + + + + + 11 + 75 + true + + + + Length + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - 0 - 0 - + + + + + + :/icon/24x24/fx.png:/icon/24x24/fx.png + + + + 24 + 24 + + + + + + + + + + + :/icon/24x24/equal.png + + + + + + + + 87 + 0 + - - - - true + + + + + + 20 + 230 + 351 + 41 + + + + + + + + 16777215 + 28 + - - - - true + + + + - - - - - - true - - - - - - - true + + + + @@ -717,7 +815,6 @@ checkBoxDetail checkBoxPattern lineEditLetter - checkBoxGrainline From 5562e467908a5e3b3f309ea3d8e3a28cf43bc9c5 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 6 Oct 2016 23:39:57 +0200 Subject: [PATCH 13/19] Fixed the Grainline tab in detail dialog and also length/rotation formulas checking --HG-- branch : feature --- .../vtools/dialogs/tools/dialogdetail.cpp | 126 ++++--- src/libs/vtools/dialogs/tools/dialogdetail.h | 4 +- src/libs/vtools/dialogs/tools/dialogdetail.ui | 308 ++++++++++++++---- 3 files changed, 324 insertions(+), 114 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.cpp b/src/libs/vtools/dialogs/tools/dialogdetail.cpp index d6cc233ce..e82f2e704 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.cpp +++ b/src/libs/vtools/dialogs/tools/dialogdetail.cpp @@ -159,8 +159,8 @@ DialogDetail::DialogDetail(const VContainer *data, const quint32 &toolId, QWidge connect(ui.checkBoxGrainline, &QCheckBox::toggled, this, &DialogDetail::EnableGrainlineRotation); connect(ui.pushButtonRot, &QPushButton::clicked, this, &DialogDetail::EditFormula); connect(ui.pushButtonLen, &QPushButton::clicked, this, &DialogDetail::EditFormula); - connect(ui.lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValue); - connect(ui.lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValue); + connect(ui.lineEditLenFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValues); + connect(ui.lineEditRotFormula, &QPlainTextEdit::textChanged, this, &DialogDetail::UpdateValues); connect(ui.pushButtonShowRot, &QPushButton::clicked, this, &DialogDetail::DeployRotation); connect(ui.pushButtonShowLen, &QPushButton::clicked, this, &DialogDetail::DeployLength); @@ -484,11 +484,8 @@ VDetail DialogDetail::CreateDetail() const detail.GetGrainlineGeometry() = m_oldGrainline; detail.GetGrainlineGeometry().SetVisible(ui.checkBoxGrainline->isChecked()); - if (ui.checkBoxGrainline->isChecked() == true) - { - detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->toPlainText()); - detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->toPlainText()); - } + detail.GetGrainlineGeometry().SetRotation(ui.lineEditRotFormula->toPlainText()); + detail.GetGrainlineGeometry().SetLength(ui.lineEditLenFormula->toPlainText()); return detail; } @@ -835,58 +832,80 @@ void DialogDetail::ClearFields() } //--------------------------------------------------------------------------------------------------------------------- -void DialogDetail::SetValue(QObject *pobjSender) +void DialogDetail::UpdateValues() { - QPlainTextEdit* pleSender = qobject_cast(pobjSender); - SCASSERT(pleSender != 0); + QPlainTextEdit* apleSender[2]; + apleSender[0] = ui.lineEditRotFormula; + apleSender[1] = ui.lineEditLenFormula; + bool bFormulasOK = true; - QString qsFormula = pleSender->toPlainText().simplified(); - Calculator cal; - QString qsVal; - try + for (int i = 0; i < 2; ++i) { - qsFormula.replace("\n", " "); - qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); - qreal dVal; - dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); - if (qIsInf(dVal) == true || qIsNaN(dVal) == true) + QLabel* plbVal; + QLabel* plbText; + QString qsUnit; + if (i == 0) { - qsVal.clear(); + plbVal = ui.labelRot; + plbText = ui.labelEditRot; + QChar ch(0x00b0); + qsUnit = ch; } else { - qsVal.setNum(dVal, 'f', 5); + plbVal = ui.labelLen; + plbText = ui.labelEditLen; + qsUnit = " " + VDomDocument::UnitsToStr(qApp->patternUnit()); } - } - catch (...) - { - qsVal.clear(); + + QString qsFormula = apleSender[i]->toPlainText().simplified(); + Calculator cal; + QString qsVal; + try + { + qsFormula.replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + qreal dVal; + dVal = cal.EvalFormula(data->PlainVariables(), qsFormula); + if (qIsInf(dVal) == true || qIsNaN(dVal) == true) + { + throw qmu::QmuParserError(tr("Infinite/undefined result")); + } + else if (i == 1 && dVal <= 0.0) + { + throw qmu::QmuParserError(tr("Length should be positive")); + } + else + { + qsVal.setNum(dVal, 'f', 2); + ChangeColor(plbText, okColor); + } + } + catch (...) + { + qsVal.clear(); + ChangeColor(plbText, Qt::red); + bFormulasOK = false; + } + + if (qsVal.isEmpty() == false) + { + qsVal += qsUnit; + } + plbVal->setText(qsVal); } - QLabel* plbVal; - QString qsUnit; - if (pobjSender == ui.lineEditLenFormula) + bOk->setEnabled(bFormulasOK); + if (bFormulasOK == false) { - plbVal = ui.labelLen; - qsUnit = " " + VDomDocument::UnitsToStr(qApp->patternUnit()); - } - else if (pobjSender == ui.lineEditRotFormula) - { - plbVal = ui.labelRot; - QChar ch(0x00b0); - qsUnit = ch; + QIcon icon(":/icons/win.icon.theme/16x16/status/dialog-warning.png"); + ui.tabWidget->setTabIcon(2, icon); } else { - // should not get here - return; + QIcon icon; + ui.tabWidget->setTabIcon(2, icon); } - - if (qsVal.isEmpty() == false) - { - qsVal += qsUnit; - } - plbVal->setText(qsVal); } //--------------------------------------------------------------------------------------------------------------------- @@ -945,6 +964,17 @@ void DialogDetail::EnableGrainlineRotation() ui.pushButtonLen->setEnabled(ui.checkBoxGrainline->isChecked()); ui.pushButtonShowLen->setEnabled(ui.checkBoxGrainline->isChecked()); ui.pushButtonShowRot->setEnabled(ui.checkBoxGrainline->isChecked()); + + if (ui.checkBoxGrainline->isChecked() == true) + { + UpdateValues(); + } + else + { + ChangeColor(ui.labelEditLen, okColor); + ChangeColor(ui.labelEditRot, okColor); + bOk->setEnabled(true); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -977,16 +1007,10 @@ void DialogDetail::EditFormula() QString qsFormula = dlg.GetFormula(); qsFormula.replace("\n", " "); pleFormula->setPlainText(qsFormula); - SetValue(pleFormula); + UpdateValues(); } } -//--------------------------------------------------------------------------------------------------------------------- -void DialogDetail::UpdateValue() -{ - SetValue(sender()); -} - //--------------------------------------------------------------------------------------------------------------------- void DialogDetail::DeployRotation() { diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.h b/src/libs/vtools/dialogs/tools/dialogdetail.h index b96263334..c40cb37a6 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.h +++ b/src/libs/vtools/dialogs/tools/dialogdetail.h @@ -127,14 +127,12 @@ private: quint32 RowId(int i) const; - void SetValue(QObject* pobjSender); - private slots: + void UpdateValues(); void SetAddMode(); void SetEditMode(); void EnableGrainlineRotation(); void EditFormula(); - void UpdateValue(); void DeployRotation(); void DeployLength(); }; diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index ef696c8e6..2e81a4f14 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -538,9 +538,9 @@ - 20 - 20 - 351 + 10 + 10 + 541 41 @@ -554,32 +554,68 @@ - + - 20 - 70 - 351 + 10 + 60 + 541 41 - - - - - - 11 - 75 - true - + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + - Rotation + Rotation: - + Qt::Horizontal @@ -591,10 +627,13 @@ - - + + + + Formula wizard + - + ... @@ -608,8 +647,8 @@ - - + + @@ -618,79 +657,171 @@ - + + + + 0 + 0 + + 87 0 + + + 0 + 0 + + + + Value + - + _ - + - 20 - 120 - 351 + 10 + 110 + 541 41 - + + + + 0 + 0 + + 16777215 28 + + Calculation + + + true + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + - + - + + + + + + + 16 + 16 + + + + true - + - 20 - 180 - 351 + 10 + 160 + 541 41 - - - - - - 11 - 75 - true - + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + - Length + Length: - + Qt::Horizontal @@ -702,10 +833,13 @@ - - + + + + Formula wizard + - + ... @@ -719,8 +853,8 @@ - - + + @@ -729,51 +863,105 @@ - + + + + 0 + 0 + + 87 0 + + + 0 + 0 + + + + Value + - + _ - + - 20 - 230 - 351 + 10 + 210 + 541 41 - + + + + 0 + 0 + + 16777215 28 + + Calculation + + + true + + + + + + + 18 + 18 + + + + + 0 + 0 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + - + + + + 16 + 16 + + + + true + From dc36337663b1c170aec0b3c300b9e8befcbd6f0b Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 11 Oct 2016 00:27:14 +0200 Subject: [PATCH 14/19] Implemented interactive resizing for grainline item --HG-- branch : feature --- src/libs/vtools/tools/vgrainlineitem.cpp | 100 ++++++++++++++++++++--- src/libs/vtools/tools/vgrainlineitem.h | 8 +- src/libs/vtools/tools/vtooldetail.cpp | 15 ++++ src/libs/vtools/tools/vtooldetail.h | 1 + 4 files changed, 111 insertions(+), 13 deletions(-) diff --git a/src/libs/vtools/tools/vgrainlineitem.cpp b/src/libs/vtools/tools/vgrainlineitem.cpp index d0dbc0a83..665017b74 100644 --- a/src/libs/vtools/tools/vgrainlineitem.cpp +++ b/src/libs/vtools/tools/vgrainlineitem.cpp @@ -41,6 +41,7 @@ #define ARROW_ANGLE 0.35 #define ARROW_LENGTH 15 #define RECT_WIDTH 30 +#define RESIZE_RECT_SIZE 10 #define ACTIVE_Z 10 #define INACTIVE_Z 5 @@ -51,7 +52,7 @@ */ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) :QGraphicsObject(pParent), m_eMode(VGrainlineItem::mNormal), m_dRotation(0), m_dLength(0), m_rectBoundingBox(), - m_polyBound(), m_ptStartPos(), m_ptStartMove(), m_dScale(1) + m_polyBound(), m_ptStartPos(), m_ptStartMove(), m_dScale(1), m_polyResize() { m_rectBoundingBox.setTopLeft(QPointF(0, 0)); setAcceptHoverEvents(true); @@ -120,6 +121,17 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption pP->setBrush(Qt::NoBrush); // bounding polygon pP->drawPolygon(m_polyBound); + + pP->setBrush(clr); + pP->drawPolygon(m_polyResize); + + pP->setBrush(Qt::NoBrush); + if (m_eMode == mResize) + { + pP->drawLine(m_polyBound.at(0), m_polyBound.at(2)); + pP->drawLine(m_polyBound.at(1), m_polyBound.at(3)); + } + } pP->restore(); } @@ -250,6 +262,7 @@ bool VGrainlineItem::IsContained(const QPointF& pt, qreal &dX, qreal &dY) const void VGrainlineItem::SetScale(qreal dScale) { m_dScale = dScale; + UpdateRectangle(); UpdateBox(); } @@ -262,13 +275,23 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) { if (pME->button() == Qt::LeftButton) { - m_eMode = mMove; - setZValue(ACTIVE_Z); m_ptStartPos = pos(); m_ptStartMove = pME->scenePos(); - UpdateBox(); - SetOverrideCursor(cursorArrowCloseHand, 1, 1); + m_dStartLength = m_dLength; + + if (m_polyResize.containsPoint(pME->pos(), Qt::OddEvenFill) == true) + { + m_eMode = mResize; + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + m_eMode = mMove; + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } } + setZValue(ACTIVE_Z); + UpdateBox(); } //--------------------------------------------------------------------------------------------------------------------- @@ -278,9 +301,9 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) */ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { + QPointF ptDiff = pME->scenePos() - m_ptStartMove; if (m_eMode == mMove) { - QPointF ptDiff = pME->scenePos() - m_ptStartMove; QPointF pt = m_ptStartPos + ptDiff; qreal dX; qreal dY; @@ -290,6 +313,22 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) pt.setY(pt.y() + dY); } setPos(pt); + UpdateBox(); + } + else if (m_eMode == mResize) + { + qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); + qreal dAng = qAtan2(ptDiff.y(), ptDiff.x()); + dLen = dLen*qCos(dAng - m_dRotation); + qreal dPrevLen = m_dLength; + // try with new length + m_dLength = m_dStartLength + dLen; + qreal dX; + qreal dY; + if (IsContained(m_ptStartPos, dX, dY) == false) + { + m_dLength = dPrevLen; + } UpdateRectangle(); UpdateBox(); } @@ -307,14 +346,35 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (m_eMode == mMove) { - qreal dD = fabs(pME->scenePos().x() - m_ptStartMove.x()) + fabs(pME->scenePos().y() - m_ptStartMove.y()); - bool bShort = (dD < 2); - if (bShort == false) + RestoreOverrideCursor(cursorArrowCloseHand); + } + else if (m_eMode == mResize) + { + RestoreOverrideCursor(Qt::SizeFDiagCursor); + } + + qreal dD = fabs(pME->scenePos().x() - m_ptStartMove.x()) + fabs(pME->scenePos().y() - m_ptStartMove.y()); + bool bShort = (dD < 2); + + if (m_eMode == mMove || m_eMode == mResize) + { + if (bShort == true) { - emit SignalMoved(pos()); + // TODO: switch to rotate mode + } + else + { + if (m_eMode == mMove) + { + emit SignalMoved(pos()); + } + else + { + emit SignalResized(m_dLength); + } + UpdateBox(); } } - RestoreOverrideCursor(cursorArrowCloseHand); } } @@ -356,5 +416,23 @@ void VGrainlineItem::UpdateRectangle() m_polyBound << ptA; 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; + prepareGeometryChange(); } diff --git a/src/libs/vtools/tools/vgrainlineitem.h b/src/libs/vtools/tools/vgrainlineitem.h index 9475a46c9..008fdb4a6 100644 --- a/src/libs/vtools/tools/vgrainlineitem.h +++ b/src/libs/vtools/tools/vgrainlineitem.h @@ -44,7 +44,8 @@ class VGrainlineItem : public QGraphicsObject enum Mode { mNormal, - mMove + mMove, + mResize }; public: @@ -69,16 +70,19 @@ protected: signals: void SignalMoved(const QPointF& ptPos); + void SignalResized(qreal dLength); private: Mode m_eMode; qreal m_dRotation; qreal m_dLength; QRectF m_rectBoundingBox; - QPolygonF m_polyBound; + QPolygonF m_polyBound; QPointF m_ptStartPos; QPointF m_ptStartMove; qreal m_dScale; + QPolygonF m_polyResize; + qreal m_dStartLength; }; #endif // VGRAINLINEITEM_H diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 8c0c03ac6..562bba867 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -205,6 +205,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(patternInfo, &VTextGraphicsItem::SignalRotated, this, &VToolDetail::SaveRotationPattern); connect(grainLine, &VGrainlineItem::SignalMoved, this, &VToolDetail::SaveMoveGrainline); + connect(grainLine, &VGrainlineItem::SignalResized, this, &VToolDetail::SaveResizeGrainline); connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); @@ -1067,6 +1068,20 @@ void VToolDetail::SaveMoveGrainline(const QPointF& ptPos) qApp->getUndoStack()->push(moveCommand); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::SaveResizeGrainline(qreal dLength) +{ + VDetail oldDet = VAbstractTool::data.GetDetail(id); + VDetail newDet = oldDet; + + dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit()); + newDet.GetGrainlineGeometry().SetLength(qApp->LocaleToString(dLength)); + SaveDetailOptions* moveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); + moveCommand->setText(tr("resize grainline")); + connect(moveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(moveCommand); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddNode add node to the file. diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 0f2991406..c6291235c 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -128,6 +128,7 @@ protected slots: virtual void SaveResizePattern(qreal dLabelW, int iFontSize); virtual void SaveRotationPattern(qreal dRot); virtual void SaveMoveGrainline(const QPointF& ptPos); + virtual void SaveResizeGrainline(qreal dLength); private: Q_DISABLE_COPY(VToolDetail) From fce28492086e6c61e958616c17661d2f3a9c91c9 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Wed, 12 Oct 2016 02:45:01 +0200 Subject: [PATCH 15/19] Worked on grainline rotation --HG-- branch : feature --- src/libs/vtools/tools/vgrainlineitem.cpp | 151 ++++++++++++++++++----- src/libs/vtools/tools/vgrainlineitem.h | 13 +- 2 files changed, 129 insertions(+), 35 deletions(-) diff --git a/src/libs/vtools/tools/vgrainlineitem.cpp b/src/libs/vtools/tools/vgrainlineitem.cpp index 665017b74..1b56f92b4 100644 --- a/src/libs/vtools/tools/vgrainlineitem.cpp +++ b/src/libs/vtools/tools/vgrainlineitem.cpp @@ -42,6 +42,7 @@ #define ARROW_LENGTH 15 #define RECT_WIDTH 30 #define RESIZE_RECT_SIZE 10 +#define ROTATE_CIRC_R 7 #define ACTIVE_Z 10 #define INACTIVE_Z 5 @@ -51,8 +52,9 @@ * @param pParent pointer to the parent item */ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) - :QGraphicsObject(pParent), m_eMode(VGrainlineItem::mNormal), m_dRotation(0), m_dLength(0), m_rectBoundingBox(), - m_polyBound(), m_ptStartPos(), m_ptStartMove(), m_dScale(1), m_polyResize() + :QGraphicsObject(pParent), m_eMode(VGrainlineItem::mNormal), m_bReleased(false), m_dRotation(0), m_dLength(0), + m_rectBoundingBox(), m_polyBound(), m_ptStartPos(), m_ptStartMove(), m_dScale(1), m_polyResize(), + m_ptStart(), m_ptFinish(), m_ptCenter(), m_dAngle(0) { m_rectBoundingBox.setTopLeft(QPointF(0, 0)); setAcceptHoverEvents(true); @@ -85,7 +87,7 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption QPointF pt2; pt2.setX(pt1.x() + m_dLength * cos(m_dRotation)); - pt2.setY(pt1.y() + m_dLength * sin(m_dRotation)); + pt2.setY(pt1.y() - m_dLength * sin(m_dRotation)); pP->setRenderHints(QPainter::Antialiasing); // line @@ -97,10 +99,10 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption QPointF ptA; qreal dArrLen = ARROW_LENGTH*m_dScale; ptA.setX(pt1.x() + dArrLen*cos(m_dRotation + ARROW_ANGLE)); - ptA.setY(pt1.y() + dArrLen*sin(m_dRotation + ARROW_ANGLE)); + ptA.setY(pt1.y() - dArrLen*sin(m_dRotation + ARROW_ANGLE)); poly << ptA; ptA.setX(pt1.x() + dArrLen*cos(m_dRotation - ARROW_ANGLE)); - ptA.setY(pt1.y() + dArrLen*sin(m_dRotation - ARROW_ANGLE)); + ptA.setY(pt1.y() - dArrLen*sin(m_dRotation - ARROW_ANGLE)); poly << ptA; pP->setBrush(clr); pP->drawPolygon(poly); @@ -108,10 +110,10 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption poly.clear(); poly << pt2; ptA.setX(pt2.x() + dArrLen*cos(M_PI + m_dRotation + ARROW_ANGLE)); - ptA.setY(pt2.y() + dArrLen*sin(M_PI + m_dRotation + ARROW_ANGLE)); + ptA.setY(pt2.y() - dArrLen*sin(M_PI + m_dRotation + ARROW_ANGLE)); poly << ptA; ptA.setX(pt2.x() + dArrLen*cos(M_PI + m_dRotation - ARROW_ANGLE)); - ptA.setY(pt2.y() + dArrLen*sin(M_PI + m_dRotation - ARROW_ANGLE)); + ptA.setY(pt2.y() - dArrLen*sin(M_PI + m_dRotation - ARROW_ANGLE)); poly << ptA; pP->drawPolygon(poly); @@ -121,17 +123,30 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption pP->setBrush(Qt::NoBrush); // bounding polygon pP->drawPolygon(m_polyBound); + pP->setPen(QPen(clr, 3)); - pP->setBrush(clr); - pP->drawPolygon(m_polyResize); + if (m_eMode != mRotate) + { + pP->setBrush(clr); + pP->drawPolygon(m_polyResize); + } pP->setBrush(Qt::NoBrush); if (m_eMode == mResize) { + pP->setPen(clr); pP->drawLine(m_polyBound.at(0), m_polyBound.at(2)); pP->drawLine(m_polyBound.at(1), m_polyBound.at(3)); } + if (m_eMode == mRotate) + { + QPointF ptC = (m_polyBound.at(0) + m_polyBound.at(2))/2; + qreal dRad = m_dScale * ROTATE_CIRC_R; + pP->setBrush(clr); + pP->drawEllipse(ptC, dRad, dRad); + } + } pP->restore(); } @@ -151,7 +166,7 @@ void VGrainlineItem::UpdateGeometry(const QPointF& ptPos, qreal dRotation, qreal qreal dX; qreal dY; QPointF pt = ptPos; - if (IsContained(pt, dX, dY) == false) + if (IsContained(pt, m_dRotation, dX, dY) == false) { pt.setX(pt.x() + dX); pt.setY(pt.y() + dY); @@ -177,6 +192,7 @@ QRectF VGrainlineItem::boundingRect() const */ void VGrainlineItem::Reset() { + m_bReleased = false; m_eMode = mNormal; setZValue(INACTIVE_Z); UpdateBox(); @@ -197,19 +213,20 @@ bool VGrainlineItem::IsIdle() const * @brief VGrainlineItem::IsContained checks, if both ends of the grainline, starting at pt, are contained in * parent widget. * @param pt starting point of the grainline. + * @param dRot rotation of the grainline in [rad] * @param dX horizontal translation needed to put the arrow inside parent item * @param dY vertical translation needed to put the arrow inside parent item * @return true, if both ends of the grainline, starting at pt, are contained in the parent widget and * false otherwise. */ -bool VGrainlineItem::IsContained(const QPointF& pt, qreal &dX, qreal &dY) const +bool VGrainlineItem::IsContained(const QPointF& pt, qreal dRot, qreal &dX, qreal &dY) const { dX = 0; dY = 0; QPointF apt[2]; apt[0] = pt; - apt[1].setX(pt.x() + m_dLength * cos(m_dRotation)); - apt[1].setY(pt.y() + m_dLength * sin(m_dRotation)); + apt[1].setX(pt.x() + m_dLength * cos(dRot)); + apt[1].setY(pt.y() - m_dLength * sin(dRot)); // single point differences qreal dPtX; qreal dPtY; @@ -278,20 +295,28 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) m_ptStartPos = pos(); m_ptStartMove = pME->scenePos(); m_dStartLength = m_dLength; + m_dAngle = GetAngle(mapToParent(pME->pos())); - if (m_polyResize.containsPoint(pME->pos(), Qt::OddEvenFill) == true) + if (m_eMode != mRotate) { - m_eMode = mResize; - SetOverrideCursor(Qt::SizeFDiagCursor); + if (m_polyResize.containsPoint(pME->pos(), Qt::OddEvenFill) == true) + { + m_eMode = mResize; + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + m_eMode = mMove; + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } } else { - m_eMode = mMove; SetOverrideCursor(cursorArrowCloseHand, 1, 1); } + setZValue(ACTIVE_Z); + UpdateBox(); } - setZValue(ACTIVE_Z); - UpdateBox(); } //--------------------------------------------------------------------------------------------------------------------- @@ -302,12 +327,12 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) { QPointF ptDiff = pME->scenePos() - m_ptStartMove; + qreal dX; + qreal dY; if (m_eMode == mMove) { QPointF pt = m_ptStartPos + ptDiff; - qreal dX; - qreal dY; - if (IsContained(pt, dX, dY) == false) + if (IsContained(pt, m_dRotation, dX, dY) == false) { pt.setX(pt.x() + dX); pt.setY(pt.y() + dY); @@ -325,13 +350,29 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) m_dLength = m_dStartLength + dLen; qreal dX; qreal dY; - if (IsContained(m_ptStartPos, dX, dY) == false) + if (IsContained(m_ptStartPos, m_dRotation, dX, dY) == false) { m_dLength = dPrevLen; } UpdateRectangle(); UpdateBox(); } + else if (m_eMode == mRotate) + { + if (fabs(m_dAngle) < 0.01) + { + m_dAngle = GetAngle(mapToParent(pME->pos())); + return; + } + + qreal dAng = GetAngle(mapToParent(pME->pos())) - m_dAngle; + if (IsContained(m_ptStartPos, m_dRotation + dAng, dX, dY) == true) + { + m_dRotation += dAng; + UpdateRectangle(); + UpdateBox(); + } + } } //--------------------------------------------------------------------------------------------------------------------- @@ -344,7 +385,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (pME->button() == Qt::LeftButton) { - if (m_eMode == mMove) + if (m_eMode == mMove || m_eMode == mRotate) { RestoreOverrideCursor(cursorArrowCloseHand); } @@ -360,7 +401,11 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) { if (bShort == true) { - // TODO: switch to rotate mode + if (m_bReleased == true) + { + m_eMode = mRotate; + UpdateBox(); + } } else { @@ -375,6 +420,19 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) UpdateBox(); } } + else + { + if (bShort == true) + { + m_eMode = mMove; + } + else + { + emit SignalRotated(m_dRotation); + } + UpdateBox(); + } + m_bReleased = true; } } @@ -399,20 +457,24 @@ void VGrainlineItem::UpdateRectangle() QPointF pt2; pt2.setX(pt1.x() + m_dLength * cos(m_dRotation)); - pt2.setY(pt1.y() + m_dLength * sin(m_dRotation)); + pt2.setY(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)); + 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)); + 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)); + 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)); + ptA.setY(pt2.y() - RECT_WIDTH*sin(m_dRotation + M_PI/2)); m_polyBound << ptA; m_rectBoundingBox = m_polyBound.boundingRect(); setTransformOriginPoint(m_rectBoundingBox.center()); @@ -423,16 +485,39 @@ void VGrainlineItem::UpdateRectangle() 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)); + 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)); + 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)); + ptA.setY(ptA.y() - dSize*sin(m_dRotation - M_PI/2)); m_polyResize << ptA; prepareGeometryChange(); } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::GetAngle calculates the angle between the line, which goes from + * rotation center to pt and x axis + * @param pt point of interest + * @return the angle between line from rotation center and point of interest and x axis + */ +double VGrainlineItem::GetAngle(QPointF pt) const +{ + double dX = pt.x() - m_ptCenter.x(); + double dY = pt.y() - m_ptCenter.y(); + + if (fabs(dX) < 1 && fabs(dY) < 1) + { + return 0; + } + else + { + return qAtan2(dY, dX); + } +} + diff --git a/src/libs/vtools/tools/vgrainlineitem.h b/src/libs/vtools/tools/vgrainlineitem.h index 008fdb4a6..fc3395b19 100644 --- a/src/libs/vtools/tools/vgrainlineitem.h +++ b/src/libs/vtools/tools/vgrainlineitem.h @@ -45,7 +45,8 @@ class VGrainlineItem : public QGraphicsObject enum Mode { mNormal, mMove, - mResize + mResize, + mRotate }; public: @@ -58,7 +59,7 @@ public: QRectF boundingRect() const; void Reset(); bool IsIdle() const; - bool IsContained(const QPointF &pt, qreal &dX, qreal &dY) const; + bool IsContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const; void SetScale(qreal dScale); protected: @@ -68,12 +69,16 @@ protected: void UpdateBox(); void UpdateRectangle(); + qreal GetAngle(QPointF pt) const; + signals: void SignalMoved(const QPointF& ptPos); void SignalResized(qreal dLength); + void SignalRotated(qreal dRot); private: Mode m_eMode; + bool m_bReleased; qreal m_dRotation; qreal m_dLength; QRectF m_rectBoundingBox; @@ -83,6 +88,10 @@ private: qreal m_dScale; QPolygonF m_polyResize; qreal m_dStartLength; + QPointF m_ptStart; + QPointF m_ptFinish; + QPointF m_ptCenter; + qreal m_dAngle; }; #endif // VGRAINLINEITEM_H From e192ff54ec06d1fa621d27759f9de1e0b23cf978 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Thu, 13 Oct 2016 23:33:32 +0200 Subject: [PATCH 16/19] Finished interactive rotation of the grainline and fixed cursor in the Grainline tab of detail dialog --HG-- branch : feature --- src/libs/vtools/dialogs/tools/dialogdetail.ui | 2 +- src/libs/vtools/tools/vgrainlineitem.cpp | 96 +++++++++++++++---- src/libs/vtools/tools/vgrainlineitem.h | 8 +- src/libs/vtools/tools/vtooldetail.cpp | 24 ++++- src/libs/vtools/tools/vtooldetail.h | 1 + 5 files changed, 107 insertions(+), 24 deletions(-) diff --git a/src/libs/vtools/dialogs/tools/dialogdetail.ui b/src/libs/vtools/dialogs/tools/dialogdetail.ui index 2e81a4f14..9adf0b18d 100644 --- a/src/libs/vtools/dialogs/tools/dialogdetail.ui +++ b/src/libs/vtools/dialogs/tools/dialogdetail.ui @@ -530,7 +530,7 @@ - SizeVerCursor + ArrowCursor Grainline diff --git a/src/libs/vtools/tools/vgrainlineitem.cpp b/src/libs/vtools/tools/vgrainlineitem.cpp index 1b56f92b4..37546c553 100644 --- a/src/libs/vtools/tools/vgrainlineitem.cpp +++ b/src/libs/vtools/tools/vgrainlineitem.cpp @@ -52,8 +52,8 @@ * @param pParent pointer to the parent item */ VGrainlineItem::VGrainlineItem(QGraphicsItem* pParent) - :QGraphicsObject(pParent), m_eMode(VGrainlineItem::mNormal), m_bReleased(false), m_dRotation(0), m_dLength(0), - m_rectBoundingBox(), m_polyBound(), m_ptStartPos(), m_ptStartMove(), m_dScale(1), m_polyResize(), + :QGraphicsObject(pParent), m_eMode(VGrainlineItem::mNormal), m_bReleased(false), m_dRotation(0), m_dStartRotation(0), + m_dLength(0), m_rectBoundingBox(), m_polyBound(), m_ptStartPos(), m_ptStartMove(), m_dScale(1), m_polyResize(), m_ptStart(), m_ptFinish(), m_ptCenter(), m_dAngle(0) { m_rectBoundingBox.setTopLeft(QPointF(0, 0)); @@ -145,6 +145,19 @@ void VGrainlineItem::paint(QPainter* pP, const QStyleOptionGraphicsItem* pOption qreal dRad = m_dScale * ROTATE_CIRC_R; pP->setBrush(clr); pP->drawEllipse(ptC, dRad, dRad); + + pP->setBrush(Qt::NoBrush); + pP->save(); + pP->translate(ptC); + pP->rotate(qRadiansToDegrees(-m_dRotation)); + int iX = int(qRound(m_dLength/2 - 0.5*dRad)); + int iY = int(qRound(RECT_WIDTH - 0.5*dRad)); + int iR = int(qRound(dRad*3)); + pP->drawArc(iX - iR, iY - iR, iR, iR, 0*16, -90*16); + pP->drawArc(-iX, iY - iR, iR, iR, 270*16, -90*16); + pP->drawArc(-iX, -iY, iR, iR, 180*16, -90*16); + pP->drawArc(iX - iR, -iY, iR, iR, 90*16, -90*16); + pP->restore(); } } @@ -295,7 +308,9 @@ void VGrainlineItem::mousePressEvent(QGraphicsSceneMouseEvent* pME) m_ptStartPos = pos(); m_ptStartMove = pME->scenePos(); m_dStartLength = m_dLength; + m_dStartRotation = m_dRotation; m_dAngle = GetAngle(mapToParent(pME->pos())); + m_ptRotCenter = m_ptCenter; if (m_eMode != mRotate) { @@ -343,7 +358,7 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) else if (m_eMode == mResize) { qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); - qreal dAng = qAtan2(ptDiff.y(), ptDiff.x()); + qreal dAng = qAtan2(-ptDiff.y(), ptDiff.x()); dLen = dLen*qCos(dAng - m_dRotation); qreal dPrevLen = m_dLength; // try with new length @@ -359,19 +374,28 @@ void VGrainlineItem::mouseMoveEvent(QGraphicsSceneMouseEvent* pME) } else if (m_eMode == mRotate) { + // prevent strange angle changes due to singularities + qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); + if (dLen < 2) + { + return; + } + if (fabs(m_dAngle) < 0.01) { m_dAngle = GetAngle(mapToParent(pME->pos())); return; } - qreal dAng = GetAngle(mapToParent(pME->pos())) - m_dAngle; - if (IsContained(m_ptStartPos, m_dRotation + dAng, dX, dY) == true) - { - m_dRotation += dAng; - UpdateRectangle(); - UpdateBox(); - } + qreal dAng = GetAngle(mapToParent(pME->pos())) - m_dAngle; + QPointF ptNewPos = Rotate(m_ptStartPos, m_ptRotCenter, dAng); + if (IsContained(ptNewPos, m_dStartRotation + dAng, dX, dY) == true) + { + setPos(ptNewPos); + m_dRotation = m_dStartRotation + dAng; + UpdateRectangle(); + UpdateBox(); + } } } @@ -394,8 +418,9 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) RestoreOverrideCursor(Qt::SizeFDiagCursor); } - qreal dD = fabs(pME->scenePos().x() - m_ptStartMove.x()) + fabs(pME->scenePos().y() - m_ptStartMove.y()); - bool bShort = (dD < 2); + QPointF ptDiff = pME->scenePos() - m_ptStartMove; + qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y()); + bool bShort = (dLen < 2); if (m_eMode == mMove || m_eMode == mResize) { @@ -428,7 +453,7 @@ void VGrainlineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } else { - emit SignalRotated(m_dRotation); + emit SignalRotated(m_dRotation, m_ptStart); } UpdateBox(); } @@ -506,10 +531,10 @@ void VGrainlineItem::UpdateRectangle() * @param pt point of interest * @return the angle between line from rotation center and point of interest and x axis */ -double VGrainlineItem::GetAngle(QPointF pt) const +qreal VGrainlineItem::GetAngle(const QPointF& pt) const { - double dX = pt.x() - m_ptCenter.x(); - double dY = pt.y() - m_ptCenter.y(); + double dX = pt.x() - m_ptRotCenter.x(); + double dY = pt.y() - m_ptRotCenter.y(); if (fabs(dX) < 1 && fabs(dY) < 1) { @@ -517,7 +542,44 @@ double VGrainlineItem::GetAngle(QPointF pt) const } else { - return qAtan2(dY, dX); + return qAtan2(-dY, dX); } } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::Rotate rotates point pt around ptCenter by angle dAng [rad] + * and returns the resulting point + * @param pt point to rotate + * @param ptCenter center of rotation + * @param dAng angle of rotation + * @return point, which is a result of rotating pt around ptCenter by angle dAng + */ +QPointF VGrainlineItem::Rotate(const QPointF& pt, const QPointF& ptCenter, qreal dAng) const +{ + QPointF ptRel = pt - ptCenter; + QPointF ptFinal; + ptFinal.setX(ptRel.x()*qCos(dAng) + ptRel.y()*qSin(dAng)); + ptFinal.setY(-ptRel.x()*qSin(dAng) + ptRel.y()*qCos(dAng)); + ptFinal += ptCenter; + return ptFinal; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VGrainlineItem::GetInsideCorner calculates a point inside the bounding polygon, + * dDist away of i-th point in each direction + * @param i index of corner + * @param dDist distance + * @return resulting point + */ +QPointF VGrainlineItem::GetInsideCorner(int i, qreal dDist) const +{ + QPointF pt1 = m_polyBound.at((i + 1) % m_polyBound.count()) - m_polyBound.at(i); + QPointF pt2 = m_polyBound.at((i + m_polyBound.count() - 1) % m_polyBound.count()) - m_polyBound.at(i); + + pt1 = dDist*pt1/qSqrt(pt1.x()*pt1.x() + pt1.y()*pt1.y()); + pt2 = dDist*pt2/qSqrt(pt2.x()*pt2.x() + pt2.y()*pt2.y()); + + return m_polyBound.at(i) + pt1 + pt2; +} diff --git a/src/libs/vtools/tools/vgrainlineitem.h b/src/libs/vtools/tools/vgrainlineitem.h index fc3395b19..30b4f36c6 100644 --- a/src/libs/vtools/tools/vgrainlineitem.h +++ b/src/libs/vtools/tools/vgrainlineitem.h @@ -69,17 +69,20 @@ protected: void UpdateBox(); void UpdateRectangle(); - qreal GetAngle(QPointF pt) const; + qreal GetAngle(const QPointF& pt) const; + QPointF Rotate(const QPointF& pt, const QPointF& ptCenter, qreal dAng) const; + QPointF GetInsideCorner(int i, qreal dDist) const; signals: void SignalMoved(const QPointF& ptPos); void SignalResized(qreal dLength); - void SignalRotated(qreal dRot); + void SignalRotated(qreal dRot, const QPointF& ptNewPos); private: Mode m_eMode; bool m_bReleased; qreal m_dRotation; + qreal m_dStartRotation; qreal m_dLength; QRectF m_rectBoundingBox; QPolygonF m_polyBound; @@ -91,6 +94,7 @@ private: QPointF m_ptStart; QPointF m_ptFinish; QPointF m_ptCenter; + QPointF m_ptRotCenter; qreal m_dAngle; }; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 9c4ffa0bc..bde71b25c 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -206,6 +206,7 @@ VToolDetail::VToolDetail(VAbstractPattern *doc, VContainer *data, const quint32 connect(grainLine, &VGrainlineItem::SignalMoved, this, &VToolDetail::SaveMoveGrainline); connect(grainLine, &VGrainlineItem::SignalResized, this, &VToolDetail::SaveResizeGrainline); + connect(grainLine, &VGrainlineItem::SignalRotated, this, &VToolDetail::SaveRotateGrainline); connect(doc, &VAbstractPattern::patternChanged, this, &VToolDetail::UpdatePatternInfo); connect(doc, &VAbstractPattern::CheckLayout, this, &VToolDetail::UpdateLabel); @@ -1077,10 +1078,25 @@ void VToolDetail::SaveResizeGrainline(qreal dLength) dLength = FromPixel(dLength, *VDataTool::data.GetPatternUnit()); newDet.GetGrainlineGeometry().SetLength(qApp->LocaleToString(dLength)); - SaveDetailOptions* moveCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); - moveCommand->setText(tr("resize grainline")); - connect(moveCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); - qApp->getUndoStack()->push(moveCommand); + SaveDetailOptions* resizeCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); + resizeCommand->setText(tr("resize grainline")); + connect(resizeCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(resizeCommand); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::SaveRotateGrainline(qreal dRot, const QPointF& ptPos) +{ + VDetail oldDet = VAbstractTool::data.GetDetail(id); + VDetail newDet = oldDet; + + dRot = qRadiansToDegrees(dRot); + newDet.GetGrainlineGeometry().SetRotation(qApp->LocaleToString(dRot)); + newDet.GetGrainlineGeometry().SetPos(ptPos); + SaveDetailOptions* rotateCommand = new SaveDetailOptions(oldDet, newDet, doc, id, this->scene()); + rotateCommand->setText(tr("rotate grainline")); + connect(rotateCommand, &SaveDetailOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree); + qApp->getUndoStack()->push(rotateCommand); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index 9252f0727..afefd8694 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -130,6 +130,7 @@ protected slots: virtual void SaveRotationPattern(qreal dRot); virtual void SaveMoveGrainline(const QPointF& ptPos); virtual void SaveResizeGrainline(qreal dLength); + virtual void SaveRotateGrainline(qreal dRot, const QPointF& ptPos); private: Q_DISABLE_COPY(VToolDetail) From 46eb6dfaa34a7961aef69afb22796162821e1876 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 16 Oct 2016 11:38:08 +0200 Subject: [PATCH 17/19] Added grainline to layout --HG-- branch : feature --- src/app/valentina/mainwindowsnogui.cpp | 6 +++ src/libs/vlayout/vlayoutdetail.cpp | 56 ++++++++++++++++++++++++++ src/libs/vlayout/vlayoutdetail.h | 5 +++ src/libs/vlayout/vlayoutdetail_p.h | 35 +++++++++------- src/libs/vlayout/vlayoutpaper.cpp | 6 +++ 5 files changed, 94 insertions(+), 14 deletions(-) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 8dd23ae17..141bf9f81 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -39,6 +39,7 @@ #include "../vlayout/vposter.h" #include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatterninfogeometry.h" +#include "../vpatterndb/vgrainlinegeometry.h" #include #include @@ -476,6 +477,11 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *de } det.SetPatternInfo(pDoc, geom, qApp->font(), pattern->size(), pattern->height()); } + const VGrainlineGeometry& grainlineGeom = d.GetGrainlineGeometry(); + if (grainlineGeom.IsVisible() == true) + { + det.SetGrainline(grainlineGeom, *pattern); + } det.setWidth(qApp->toPixel(d.getWidth())); det.CreateTextItems(); det.setForbidFlipping(d.getForbidFlipping()); diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index fc4de3307..16204c087 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -46,6 +46,8 @@ #include "../vpatterndb/vpatterninfogeometry.h" #include "../vpatterndb/vpatternpiecedata.h" #include "../vmisc/vmath.h" +#include "../vmisc/vabstractapplication.h" +#include "../vpatterndb/calculator.h" #include "vlayoutdef.h" #include "vlayoutdetail_p.h" #include "vtextmanager.h" @@ -180,6 +182,41 @@ void VLayoutDetail::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternI d->m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight()); } +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutDetail::SetGrainline(const VGrainlineGeometry& geom, const VContainer& rPattern) +{ + d->grainlineGeom = geom; + qreal dAng; + qreal dLen; + + try + { + QString qsFormula = geom.GetRotation().replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + Calculator cal1; + dAng = cal1.EvalFormula(rPattern.PlainVariables(), qsFormula); + dAng = qDegreesToRadians(dAng); + + qsFormula = geom.GetLength().replace("\n", " "); + qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator()); + Calculator cal2; + dLen = cal2.EvalFormula(rPattern.PlainVariables(), qsFormula); + dLen = ToPixel(dLen, *rPattern.GetPatternUnit()); + } + catch(...) + { + return; + } + + QPointF pt1 = geom.GetPos(); + QPointF pt2; + pt2.setX(pt1.x() + dLen * qCos(dAng)); + pt2.setY(pt1.y() - dLen * qSin(dAng)); + QVector v; + v << pt1 << pt2; + d->grainlinePoints = RoundPoints(v); +} + //--------------------------------------------------------------------------------------------------------------------- QTransform VLayoutDetail::GetMatrix() const { @@ -673,6 +710,25 @@ QGraphicsItem *VLayoutDetail::GetItem() const return item; } +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsItem* VLayoutDetail::GetGrainlineItem() const +{ + if (d->grainlinePoints.count() < 2) + { + return 0; + } + QGraphicsPathItem* item = new QGraphicsPathItem(); + QPainterPath path; + QVector v = Map(d->grainlinePoints); + path.moveTo(v.at(0)); + for (int i = 1; i < v.count(); ++i) + { + path.lineTo(v.at(i)); + } + item->setPath(path); + return item; +} + //--------------------------------------------------------------------------------------------------------------------- bool VLayoutDetail::IsMirror() const { diff --git a/src/libs/vlayout/vlayoutdetail.h b/src/libs/vlayout/vlayoutdetail.h index ef9cbd5cb..1c85855a9 100644 --- a/src/libs/vlayout/vlayoutdetail.h +++ b/src/libs/vlayout/vlayoutdetail.h @@ -44,6 +44,7 @@ #include "../ifc/xml/vabstractpattern.h" #include "../vpatterndb/vpatterninfogeometry.h" #include "../vpatterndb/vpatternpiecedata.h" +#include "../vpatterndb/vcontainer.h" #include "vabstractdetail.h" class QFont; @@ -57,6 +58,7 @@ class VAbstractPattern; class VLayoutDetailData; class VPatternInfoGeometry; class VPatternPieceData; +class VGrainlineGeometry; class VLayoutDetail :public VAbstractDetail { @@ -80,6 +82,8 @@ public: void SetPatternInfo(const VAbstractPattern* pDoc, const VPatternInfoGeometry& geom, const QFont& font, qreal dSize, qreal dHeight); + void SetGrainline(const VGrainlineGeometry& geom, const VContainer& rPattern); + QTransform GetMatrix() const; void SetMatrix(const QTransform &matrix); @@ -110,6 +114,7 @@ public: QGraphicsItem* GetTextItem(int i) const Q_REQUIRED_RESULT; QPainterPath LayoutAllowencePath() const; QGraphicsItem *GetItem() const Q_REQUIRED_RESULT; + QGraphicsItem* GetGrainlineItem() const Q_REQUIRED_RESULT; private: QSharedDataPointer d; diff --git a/src/libs/vlayout/vlayoutdetail_p.h b/src/libs/vlayout/vlayoutdetail_p.h index efbdf8ca6..289af3275 100644 --- a/src/libs/vlayout/vlayoutdetail_p.h +++ b/src/libs/vlayout/vlayoutdetail_p.h @@ -36,6 +36,8 @@ #include "../vpatterndb/vpatternpiecedata.h" #include "../vpatterndb/vpatterninfogeometry.h" +#include "../vpatterndb/vgrainlinegeometry.h" + #include "vtextmanager.h" QT_WARNING_PUSH @@ -47,45 +49,50 @@ public: VLayoutDetailData() :contour(QVector()), seamAllowence(QVector()), layoutAllowence(QVector()), matrix(QMatrix()), layoutWidth(0), mirror(false), detailLabel(QVector()), - patternInfo(QVector()), detailData(), patternGeom(), m_tmDetail(), - m_tmPattern(), m_liPP(QList()) + patternInfo(QVector()), grainlinePoints(QVector()), detailData(), patternGeom(), + grainlineGeom(), m_tmDetail(), m_tmPattern(), m_liPP(QList()) {} VLayoutDetailData(const VLayoutDetailData &detail) :QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence), layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), layoutWidth(detail.layoutWidth), mirror(detail.mirror), detailLabel(detail.detailLabel), - patternInfo(detail.patternInfo), detailData(detail.detailData), patternGeom(detail.patternGeom), - m_tmDetail(detail.m_tmDetail), m_tmPattern(detail.m_tmPattern), m_liPP(detail.m_liPP) + patternInfo(detail.patternInfo), grainlinePoints(detail.grainlinePoints), detailData(detail.detailData), + patternGeom(detail.patternGeom), grainlineGeom(detail.grainlineGeom), m_tmDetail(detail.m_tmDetail), + m_tmPattern(detail.m_tmPattern), m_liPP(detail.m_liPP) {} ~VLayoutDetailData() {} /** @brief contour list of contour points. */ - QVector contour; + QVector contour; /** @brief seamAllowence list of seam allowence points. */ - QVector seamAllowence; + QVector seamAllowence; /** @brief layoutAllowence list of layout allowence points. */ - QVector layoutAllowence; + QVector layoutAllowence; /** @brief matrix transformation matrix*/ - QTransform matrix; + QTransform matrix; /** @brief layoutWidth value layout allowence width in pixels. */ - qreal layoutWidth; + qreal layoutWidth; - bool mirror; + bool mirror; /** @brief detailLabel detail label rectangle */ - QVector detailLabel; + QVector detailLabel; /** @brief patternInfo pattern info rectangle */ - QVector patternInfo; + QVector patternInfo; + /** @brief grainlineInfo line */ + QVector grainlinePoints; /** @brief detailData detail data */ - VPatternPieceData detailData; + VPatternPieceData detailData; /** @brief patternGeom pattern geometry */ - VPatternInfoGeometry patternGeom; + VPatternInfoGeometry patternGeom; + /** @brief grainlineGeom grainline geometry */ + VGrainlineGeometry grainlineGeom; /** @brief m_tmDetail text manager for laying out detail info */ VTextManager m_tmDetail; /** @brief m_tmPattern text manager for laying out pattern info */ diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 638d43503..169c51457 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -348,6 +348,12 @@ QList VLayoutPaper::GetItemDetails() const { list.append(d->details.at(i).GetTextItem(iT)); } + + QGraphicsItem* pItem = d->details.at(i).GetGrainlineItem(); + if (pItem != 0) + { + list.append(pItem); + } } return list; } From 8ab094c40dd1f0dc6a30f520d1742bd9903f3319 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 16 Oct 2016 15:00:53 +0200 Subject: [PATCH 18/19] Grainline should now be visible in Layout mode --HG-- branch : feature --- src/libs/vlayout/vgraphicsfillitem.cpp | 52 ++++++++++++++++++++++ src/libs/vlayout/vgraphicsfillitem.h | 55 ++++++++++++++++++++++++ src/libs/vlayout/vlayout.pri | 6 ++- src/libs/vlayout/vlayoutdetail.cpp | 30 ++++++++++++- src/libs/vtools/tools/vgrainlineitem.cpp | 4 +- 5 files changed, 141 insertions(+), 6 deletions(-) create mode 100644 src/libs/vlayout/vgraphicsfillitem.cpp create mode 100644 src/libs/vlayout/vgraphicsfillitem.h diff --git a/src/libs/vlayout/vgraphicsfillitem.cpp b/src/libs/vlayout/vgraphicsfillitem.cpp new file mode 100644 index 000000000..4edcb17cb --- /dev/null +++ b/src/libs/vlayout/vgraphicsfillitem.cpp @@ -0,0 +1,52 @@ +/************************************************************************ + ** + ** @file vgraphicsfillitem.cpp + ** @author Bojan Kverh + ** @date October 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vgraphicsfillitem.h" + +//--------------------------------------------------------------------------------------------------------------------- +VGraphicsFillItem::VGraphicsFillItem() + :QGraphicsPathItem() +{} + +//--------------------------------------------------------------------------------------------------------------------- +VGraphicsFillItem::~VGraphicsFillItem() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VGraphicsFillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + painter->save(); + painter->setBrush(painter->pen().color()); + painter->drawPath(path()); + painter->restore(); +} + +//--------------------------------------------------------------------------------------------------------------------- + diff --git a/src/libs/vlayout/vgraphicsfillitem.h b/src/libs/vlayout/vgraphicsfillitem.h new file mode 100644 index 000000000..467d62e12 --- /dev/null +++ b/src/libs/vlayout/vgraphicsfillitem.h @@ -0,0 +1,55 @@ +/************************************************************************ + ** + ** @file vgraphicsfillitem.h + ** @author Bojan Kverh + ** @date October 16, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VGRAPHICSFILLITEM_H +#define VGRAPHICSFILLITEM_H + +#include +#include + +class VGraphicsFillItem : public QGraphicsPathItem +{ +public: + /** + * @brief VGraphicsFillItem Constructor + */ + VGraphicsFillItem(); + /** + * @brief ~VGraphicsFillItem Destructor + */ + ~VGraphicsFillItem(); + /** + * @brief paint Paints the item, filling the inside surface + * @param painter pointer to the painter object + * @param option unused + * @param widget unused + */ + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); +}; + +#endif // VGRAPHICSFILLITEM_H diff --git a/src/libs/vlayout/vlayout.pri b/src/libs/vlayout/vlayout.pri index d1cc7645f..6d82d469f 100644 --- a/src/libs/vlayout/vlayout.pri +++ b/src/libs/vlayout/vlayout.pri @@ -17,7 +17,8 @@ HEADERS += \ $$PWD/vbestsquare.h \ $$PWD/vposition.h \ $$PWD/vtextmanager.h \ - vposter.h + vposter.h \ + vgraphicsfillitem.h SOURCES += \ $$PWD/vlayoutgenerator.cpp \ @@ -29,6 +30,7 @@ SOURCES += \ $$PWD/vbestsquare.cpp \ $$PWD/vposition.cpp \ $$PWD/vtextmanager.cpp \ - vposter.cpp + vposter.cpp \ + vgraphicsfillitem.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp diff --git a/src/libs/vlayout/vlayoutdetail.cpp b/src/libs/vlayout/vlayoutdetail.cpp index 16204c087..dc666987f 100644 --- a/src/libs/vlayout/vlayoutdetail.cpp +++ b/src/libs/vlayout/vlayoutdetail.cpp @@ -51,6 +51,7 @@ #include "vlayoutdef.h" #include "vlayoutdetail_p.h" #include "vtextmanager.h" +#include "vgraphicsfillitem.h" class QGraphicsPathItem; class QLineF; @@ -213,7 +214,32 @@ void VLayoutDetail::SetGrainline(const VGrainlineGeometry& geom, const VContaine pt2.setX(pt1.x() + dLen * qCos(dAng)); pt2.setY(pt1.y() - dLen * qSin(dAng)); QVector v; + QPointF pt; + qreal dArrowLen = ToPixel(0.5, *rPattern.GetPatternUnit()); + qreal dArrowAng = M_PI/9; + + v << pt1; + + pt.setX(pt1.x() + dArrowLen * qCos(dAng + dArrowAng)); + pt.setY(pt1.y() - dArrowLen * qSin(dAng + dArrowAng)); + v << pt; + pt.setX(pt1.x() + dArrowLen * qCos(dAng - dArrowAng)); + pt.setY(pt1.y() - dArrowLen * qSin(dAng - dArrowAng)); + v << pt; + v << pt1 << pt2; + + dAng += M_PI; + + pt.setX(pt2.x() + dArrowLen * qCos(dAng + dArrowAng)); + pt.setY(pt2.y() - dArrowLen * qSin(dAng + dArrowAng)); + v << pt; + pt.setX(pt2.x() + dArrowLen * qCos(dAng - dArrowAng)); + pt.setY(pt2.y() - dArrowLen * qSin(dAng - dArrowAng)); + v << pt; + + v << pt2; + d->grainlinePoints = RoundPoints(v); } @@ -713,11 +739,11 @@ QGraphicsItem *VLayoutDetail::GetItem() const //--------------------------------------------------------------------------------------------------------------------- QGraphicsItem* VLayoutDetail::GetGrainlineItem() const { - if (d->grainlinePoints.count() < 2) + if (d->grainlinePoints.count() < 6) { return 0; } - QGraphicsPathItem* item = new QGraphicsPathItem(); + VGraphicsFillItem* item = new VGraphicsFillItem(); QPainterPath path; QVector v = Map(d->grainlinePoints); path.moveTo(v.at(0)); diff --git a/src/libs/vtools/tools/vgrainlineitem.cpp b/src/libs/vtools/tools/vgrainlineitem.cpp index 37546c553..ff4ae9bed 100644 --- a/src/libs/vtools/tools/vgrainlineitem.cpp +++ b/src/libs/vtools/tools/vgrainlineitem.cpp @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file vgrainlineitem.h + ** @file vgrainlineitem.cpp ** @author Bojan Kverh ** @date September 10, 2016 ** @@ -38,7 +38,7 @@ #include "vgrainlineitem.h" -#define ARROW_ANGLE 0.35 +#define ARROW_ANGLE M_PI/9 #define ARROW_LENGTH 15 #define RECT_WIDTH 30 #define RESIZE_RECT_SIZE 10 From 0ca37fdecb9c90769715bb32ba196b211a42e513 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sun, 23 Oct 2016 17:59:03 +0200 Subject: [PATCH 19/19] Merged grainline data into v0.3.7 schema --HG-- branch : feature --- src/libs/ifc/schema/pattern/v0.3.7.xsd | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libs/ifc/schema/pattern/v0.3.7.xsd b/src/libs/ifc/schema/pattern/v0.3.7.xsd index 7979e681b..d01677abf 100644 --- a/src/libs/ifc/schema/pattern/v0.3.7.xsd +++ b/src/libs/ifc/schema/pattern/v0.3.7.xsd @@ -377,6 +377,15 @@ + + + + + + + + +