From f341f51125ca34539e61946495ad2aef4f5da08a Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Sat, 10 Sep 2016 18:30:03 +0200 Subject: [PATCH] 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 +