/************************************************************************ ** ** @file vtoollinepoint.cpp ** @author Roman Telezhynskyi ** @date November 15, 2013 ** ** @brief ** @copyright ** This source code is part of the Valentina project, a pattern making ** program, whose allow create and modeling patterns of clothing. ** Copyright (C) 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 "vtoollinepoint.h" #include #include #include #include #include #include #include #include #include "../../../../vabstracttool.h" #include "../../../vdrawtool.h" #include "../ifc/ifcdef.h" #include "../ifc/xml/vabstractpattern.h" #include "../ifc/xml/vdomdocument.h" #include "../vgeometry/vgobject.h" #include "../vgeometry/vpointf.h" #include "../vmisc/theme/vscenestylesheet.h" #include "../vpatterndb/vcontainer.h" #include "../vtoolsinglepoint.h" #include "../vwidgets/scalesceneitems.h" #if QT_VERSION < QT_VERSION_CHECK(6, 4, 0) #include "../vmisc/compatibility.h" #endif using namespace Qt::Literals::StringLiterals; template class QSharedPointer; //--------------------------------------------------------------------------------------------------------------------- /** * @brief VToolLinePoint constructor. * @param doc dom document container. * @param data container with variables. * @param id object id in container. * @param typeLine line type. * @param lineColor line color. * @param formula string with length formula. * @param basePointId id base line point. * @param angle line angle. * @param parent parent object. */ VToolLinePoint::VToolLinePoint(VAbstractPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, const QString &lineColor, const QString &formula, const quint32 &basePointId, const qreal &angle, const QString ¬es, QGraphicsItem *parent) : VToolSinglePoint(doc, data, id, notes, parent), formulaLength(formula), angle(angle), basePointId(basePointId), lineColor(lineColor) { this->m_lineType = typeLine; Q_ASSERT_X(basePointId != 0, Q_FUNC_INFO, "basePointId == 0"); //-V654 //-V712 auto const point1 = static_cast(*data->GeometricObject(basePointId)); auto const point2 = static_cast(*data->GeometricObject(id)); QLineF const line(point1 - point2, QPointF()); mainLine = new VScaledLine(line, VColorRole::CustomColor, this); mainLine->SetBoldLine(false); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); mainLine->setVisible(not line.isNull()); } //--------------------------------------------------------------------------------------------------------------------- VToolLinePoint::~VToolLinePoint() { delete mainLine; } //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QPen mPen = mainLine->pen(); mPen.setColor(VSceneStylesheet::CorrectToolColor(this, VSceneStylesheet::CorrectToolColorForDarkTheme(lineColor))); mPen.setStyle(LineStyleToPenStyle(m_lineType)); mainLine->setPen(mPen); VToolSinglePoint::paint(painter, option, widget); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. */ void VToolLinePoint::RefreshGeometry() { VToolSinglePoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(m_id)); auto const point = static_cast(*VDrawTool::data.GeometricObject(m_id)); auto const basePoint = static_cast(*VDrawTool::data.GeometricObject(basePointId)); QLineF const line(basePoint - point, QPointF()); mainLine->setLine(line); mainLine->setVisible(not line.isNull()); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. */ void VToolLinePoint::RemoveReferens() { const auto basePoint = VAbstractTool::data.GetGObject(basePointId); doc->DecrementReferens(basePoint->getIdTool()); } //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::SaveOptions(QDomElement &tag, QSharedPointer &obj) { VToolSinglePoint::SaveOptions(tag, obj); doc->SetAttribute(tag, AttrTypeLine, m_lineType); doc->SetAttribute(tag, AttrLineColor, lineColor); } //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { mainLine->SetBoldLine(true); VToolSinglePoint::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { mainLine->SetBoldLine(false); VToolSinglePoint::hoverLeaveEvent(event); } //--------------------------------------------------------------------------------------------------------------------- auto VToolLinePoint::MakeToolTip() const -> QString { const QSharedPointer first = VAbstractTool::data.GeometricObject(basePointId); const QSharedPointer second = VAbstractTool::data.GeometricObject(m_id); const QLineF line(static_cast(*first), static_cast(*second)); const QString toolTip = u"" u"" u"" u"" u"
%6: %7
%1: %2 %3
%4: %5°
"_s.arg(tr("Length")) .arg(VAbstractValApplication::VApp()->fromPixel(line.length())) .arg(UnitsToStr(VAbstractValApplication::VApp()->patternUnits(), true), tr("Angle")) .arg(line.angle()) .arg(tr("Label"), second->name()); return toolTip; } //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::Disable(bool disable, const QString &namePP) { VToolSinglePoint::Disable(disable, namePP); mainLine->setEnabled(isEnabled()); } //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. */ void VToolLinePoint::FullUpdateFromFile() { ReadAttributes(); RefreshGeometry(); SetVisualization(); } //--------------------------------------------------------------------------------------------------------------------- auto VToolLinePoint::GetAngle() const -> qreal { return angle; } //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::SetAngle(const qreal &value) { angle = value; QSharedPointer obj = VAbstractTool::data.GetGObject(m_id); SaveOption(obj); } //--------------------------------------------------------------------------------------------------------------------- auto VToolLinePoint::GetLineColor() const -> QString { return lineColor; } //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::SetLineColor(const QString &value) { lineColor = value; QSharedPointer obj = VAbstractTool::data.GetGObject(m_id); SaveOption(obj); } //--------------------------------------------------------------------------------------------------------------------- auto VToolLinePoint::GetFormulaLength() const -> VFormula { VFormula fLength(formulaLength, this->getData()); fLength.setToolId(m_id); fLength.setPostfix(UnitsToStr(VAbstractValApplication::VApp()->patternUnits())); fLength.Eval(); return fLength; } //--------------------------------------------------------------------------------------------------------------------- void VToolLinePoint::SetFormulaLength(const VFormula &value) { if (!value.error()) { formulaLength = value.GetFormula(FormulaType::FromUser); QSharedPointer obj = VAbstractTool::data.GetGObject(m_id); SaveOption(obj); } } //--------------------------------------------------------------------------------------------------------------------- auto VToolLinePoint::BasePointName() const -> QString { return VAbstractTool::data.GetGObject(basePointId)->name(); }